Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Z
ZLMediaKit
概览
Overview
Details
Activity
Cycle Analytics
版本库
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
问题
0
Issues
0
列表
Board
标记
里程碑
合并请求
0
Merge Requests
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
Snippets
成员
Collapse sidebar
Close sidebar
活动
图像
聊天
创建新问题
作业
提交
Issue Boards
Open sidebar
张翔宇
ZLMediaKit
Commits
272ab706
Commit
272ab706
authored
Mar 27, 2021
by
ziyue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
确保安全释放资源
parent
cc960a32
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
25 行增加
和
13 行删除
+25
-13
server/WebApi.cpp
+2
-6
webrtc/WebRtcTransport.cpp
+15
-4
webrtc/WebRtcTransport.h
+8
-3
没有找到文件。
server/WebApi.cpp
查看文件 @
272ab706
...
@@ -1062,15 +1062,11 @@ void installWebApi() {
...
@@ -1062,15 +1062,11 @@ void installWebApi() {
}
}
headerOut
[
"Content-Type"
]
=
"text/plain"
;
headerOut
[
"Content-Type"
]
=
"text/plain"
;
headerOut
[
"Access-Control-Allow-Origin"
]
=
"*"
;
headerOut
[
"Access-Control-Allow-Origin"
]
=
"*"
;
auto
poller
=
EventPollerPool
::
Instance
().
getFirstPoller
();
auto
rtc
=
WebRtcTransportImp
::
create
(
EventPollerPool
::
Instance
().
getPoller
());
auto
rtc
=
std
::
make_shared
<
WebRtcTransportImp
>
(
poller
);
poller
->
async
([
invoker
,
rtc
,
headerOut
,
src
]()
{
rtc
->
attach
(
src
);
rtc
->
attach
(
src
);
auto
sdp
=
rtc
->
GetLocalSdp
();
invoker
(
200
,
headerOut
,
rtc
->
GetLocalSdp
());
invoker
(
200
,
headerOut
,
sdp
);
rtcs
.
emplace_back
(
rtc
);
rtcs
.
emplace_back
(
rtc
);
});
});
});
#endif
#endif
////////////以下是注册的Hook API////////////
////////////以下是注册的Hook API////////////
...
...
webrtc/WebRtcTransport.cpp
查看文件 @
272ab706
...
@@ -2,12 +2,12 @@
...
@@ -2,12 +2,12 @@
#include <iostream>
#include <iostream>
#include "Rtcp/Rtcp.h"
#include "Rtcp/Rtcp.h"
WebRtcTransport
::
WebRtcTransport
()
{
WebRtcTransport
::
WebRtcTransport
(
const
EventPoller
::
Ptr
&
poller
)
{
dtls_transport_
=
std
::
make_shared
<
RTC
::
DtlsTransport
>
(
EventPollerPool
::
Instance
().
getFirstPoller
()
,
this
);
dtls_transport_
=
std
::
make_shared
<
RTC
::
DtlsTransport
>
(
poller
,
this
);
ice_server_
=
std
::
make_shared
<
RTC
::
IceServer
>
(
this
,
makeRandStr
(
4
),
makeRandStr
(
24
));
ice_server_
=
std
::
make_shared
<
RTC
::
IceServer
>
(
this
,
makeRandStr
(
4
),
makeRandStr
(
24
));
}
}
WebRtcTransport
::~
WebRtcTransport
()
{
void
WebRtcTransport
::
onDestory
()
{
dtls_transport_
=
nullptr
;
dtls_transport_
=
nullptr
;
ice_server_
=
nullptr
;
ice_server_
=
nullptr
;
}
}
...
@@ -163,8 +163,15 @@ void WebRtcTransport::WritRtpPacket(char *buf, size_t len) {
...
@@ -163,8 +163,15 @@ void WebRtcTransport::WritRtpPacket(char *buf, size_t len) {
}
}
///////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
WebRtcTransportImp
::
Ptr
WebRtcTransportImp
::
create
(
const
EventPoller
::
Ptr
&
poller
){
WebRtcTransportImp
::
Ptr
ret
(
new
WebRtcTransportImp
(
poller
),
[](
WebRtcTransportImp
*
ptr
){
ptr
->
onDestory
();
delete
ptr
;
});
return
ret
;
}
WebRtcTransportImp
::
WebRtcTransportImp
(
const
EventPoller
::
Ptr
&
poller
)
{
WebRtcTransportImp
::
WebRtcTransportImp
(
const
EventPoller
::
Ptr
&
poller
)
:
WebRtcTransport
(
poller
)
{
_socket
=
Socket
::
createSocket
(
poller
,
false
);
_socket
=
Socket
::
createSocket
(
poller
,
false
);
//随机端口,绑定全部网卡
//随机端口,绑定全部网卡
_socket
->
bindUdpSock
(
0
);
_socket
->
bindUdpSock
(
0
);
...
@@ -173,6 +180,10 @@ WebRtcTransportImp::WebRtcTransportImp(const EventPoller::Ptr &poller) {
...
@@ -173,6 +180,10 @@ WebRtcTransportImp::WebRtcTransportImp(const EventPoller::Ptr &poller) {
});
});
}
}
void
WebRtcTransportImp
::
onDestory
()
{
WebRtcTransport
::
onDestory
();
}
void
WebRtcTransportImp
::
attach
(
const
RtspMediaSource
::
Ptr
&
src
)
{
void
WebRtcTransportImp
::
attach
(
const
RtspMediaSource
::
Ptr
&
src
)
{
assert
(
src
);
assert
(
src
);
_src
=
src
;
_src
=
src
;
...
...
webrtc/WebRtcTransport.h
查看文件 @
272ab706
...
@@ -11,8 +11,11 @@
...
@@ -11,8 +11,11 @@
class
WebRtcTransport
:
public
RTC
::
DtlsTransport
::
Listener
,
public
RTC
::
IceServer
::
Listener
{
class
WebRtcTransport
:
public
RTC
::
DtlsTransport
::
Listener
,
public
RTC
::
IceServer
::
Listener
{
public
:
public
:
using
Ptr
=
std
::
shared_ptr
<
WebRtcTransport
>
;
using
Ptr
=
std
::
shared_ptr
<
WebRtcTransport
>
;
WebRtcTransport
();
WebRtcTransport
(
const
EventPoller
::
Ptr
&
poller
);
virtual
~
WebRtcTransport
();
~
WebRtcTransport
()
override
=
default
;
/// 销毁对象
virtual
void
onDestory
();
/// 获取本地sdp
/// 获取本地sdp
/// \return
/// \return
...
@@ -85,7 +88,7 @@ class WebRtcTransportImp : public WebRtcTransport, public std::enable_shared_fro
...
@@ -85,7 +88,7 @@ class WebRtcTransportImp : public WebRtcTransport, public std::enable_shared_fro
public
:
public
:
using
Ptr
=
std
::
shared_ptr
<
WebRtcTransportImp
>
;
using
Ptr
=
std
::
shared_ptr
<
WebRtcTransportImp
>
;
WebRtcTransportImp
(
const
EventPoller
::
Ptr
&
poller
);
static
Ptr
create
(
const
EventPoller
::
Ptr
&
poller
);
~
WebRtcTransportImp
()
override
=
default
;
~
WebRtcTransportImp
()
override
=
default
;
void
attach
(
const
RtspMediaSource
::
Ptr
&
src
);
void
attach
(
const
RtspMediaSource
::
Ptr
&
src
);
...
@@ -97,6 +100,8 @@ protected:
...
@@ -97,6 +100,8 @@ protected:
uint16_t
getPort
()
const
override
;
uint16_t
getPort
()
const
override
;
std
::
string
getIP
()
const
override
;
std
::
string
getIP
()
const
override
;
void
onDtlsConnected
()
override
;
void
onDtlsConnected
()
override
;
WebRtcTransportImp
(
const
EventPoller
::
Ptr
&
poller
);
void
onDestory
()
override
;
private
:
private
:
Socket
::
Ptr
_socket
;
Socket
::
Ptr
_socket
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论