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
ee072191
Commit
ee072191
authored
Apr 02, 2021
by
ziyue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
开始对接rtsp源
parent
7110dc75
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
58 行增加
和
39 行删除
+58
-39
webrtc/WebRtcTransport.cpp
+45
-27
webrtc/WebRtcTransport.h
+13
-12
没有找到文件。
webrtc/WebRtcTransport.cpp
查看文件 @
ee072191
...
...
@@ -61,10 +61,10 @@ void WebRtcTransport::OnDtlsTransportSendData(const RTC::DtlsTransport *dtlsTran
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void
WebRtcTransport
::
onSendSockData
(
const
char
*
buf
,
size_t
len
){
void
WebRtcTransport
::
onSendSockData
(
const
char
*
buf
,
size_t
len
,
bool
flush
){
auto
tuple
=
_ice_server
->
GetSelectedTuple
();
assert
(
tuple
);
onSendSockData
(
buf
,
len
,
(
struct
sockaddr_in
*
)
tuple
);
onSendSockData
(
buf
,
len
,
(
struct
sockaddr_in
*
)
tuple
,
flush
);
}
string
getFingerprint
(
const
string
&
algorithm_str
,
const
std
::
shared_ptr
<
RTC
::
DtlsTransport
>
&
transport
){
...
...
@@ -85,7 +85,7 @@ void WebRtcTransport::setRemoteDtlsFingerprint(const RtcSession &remote){
_dtls_transport
->
SetRemoteFingerprint
(
remote_fingerprint
);
}
void
WebRtcTransport
::
onCheckSdp
(
SdpType
type
,
const
RtcSession
&
sdp
)
const
{
void
WebRtcTransport
::
onCheckSdp
(
SdpType
type
,
RtcSession
&
sdp
)
const
{
for
(
auto
&
m
:
sdp
.
media
)
{
if
(
m
.
type
!=
TrackApplication
&&
!
m
.
rtcp_mux
)
{
throw
std
::
invalid_argument
(
"只支持rtcp-mux模式"
);
...
...
@@ -150,23 +150,27 @@ void WebRtcTransport::inputSockData(char *buf, size_t len, RTC::TransportTuple *
return
;
}
if
(
is_rtp
(
buf
))
{
RtpHeader
*
header
=
(
RtpHeader
*
)
buf
;
if
(
_srtp_session_recv
->
DecryptSrtp
((
uint8_t
*
)
buf
,
&
len
))
{
onRtp
(
buf
,
len
);
}
return
;
}
if
(
is_rtcp
(
buf
))
{
RtcpHeader
*
header
=
(
RtcpHeader
*
)
buf
;
if
(
_srtp_session_recv
->
DecryptSrtcp
((
uint8_t
*
)
buf
,
&
len
))
{
onRtcp
(
buf
,
len
);
}
return
;
}
}
void
WebRtcTransport
::
sendRtpPacket
(
char
*
buf
,
size_t
len
)
{
void
WebRtcTransport
::
sendRtpPacket
(
char
*
buf
,
size_t
len
,
bool
flush
)
{
const
uint8_t
*
p
=
(
uint8_t
*
)
buf
;
bool
ret
=
false
;
if
(
_srtp_session_send
)
{
ret
=
_srtp_session_send
->
EncryptRtp
(
&
p
,
&
len
);
}
if
(
ret
)
{
onSendSockData
((
char
*
)
p
,
len
);
onSendSockData
((
char
*
)
p
,
len
,
flush
);
}
}
...
...
@@ -205,34 +209,38 @@ void WebRtcTransportImp::onStartWebRTC() {
if
(
!
strongSelf
)
{
return
;
}
size_t
i
=
0
;
pkt
->
for_each
([
&
](
const
RtpPacket
::
Ptr
&
rtp
)
{
if
(
rtp
->
type
==
TrackVideo
)
{
//目前只支持视频
strongSelf
->
sendRtpPacket
(
rtp
->
data
()
+
RtpPacket
::
kRtpTcpHeaderSize
,
rtp
->
size
()
-
RtpPacket
::
kRtpTcpHeaderSize
);
}
strongSelf
->
onSendRtp
(
rtp
,
++
i
==
pkt
->
size
());
});
});
}
void
WebRtcTransportImp
::
onSendSockData
(
const
char
*
buf
,
size_t
len
,
struct
sockaddr_in
*
dst
)
{
auto
ptr
=
BufferRaw
::
create
();
ptr
->
assign
(
buf
,
len
);
_socket
->
send
(
ptr
,
(
struct
sockaddr
*
)(
dst
),
sizeof
(
struct
sockaddr
));
void
WebRtcTransportImp
::
onSendRtp
(
const
RtpPacket
::
Ptr
&
rtp
,
bool
flush
){
InfoL
<<
flush
;
}
uint32_t
WebRtcTransportImp
::
getSSRC
()
const
{
return
_src
->
getSsrc
(
TrackVideo
);
}
void
WebRtcTransportImp
::
onCheckSdp
(
SdpType
type
,
RtcSession
&
sdp
)
const
{
WebRtcTransport
::
onCheckSdp
(
type
,
sdp
);
if
(
type
!=
SdpType
::
answer
)
{
return
;
}
for
(
auto
&
m
:
sdp
.
media
)
{
if
(
m
.
type
==
TrackApplication
)
{
continue
;
}
m
.
rtp_ssrc
.
ssrc
=
_src
->
getSsrc
(
m
.
type
);
m
.
rtx_ssrc
.
ssrc
=
2
+
m
.
rtp_ssrc
.
ssrc
;
uint16_t
WebRtcTransportImp
::
getPort
()
const
{
//todo udp端口号应该与外网映射端口相同
return
_socket
->
get_local_port
();
m
.
rtp_ssrc
.
cname
=
"zlmediakit rtc"
;
m
.
rtx_ssrc
.
cname
=
"zlmediakit rtc"
;
}
}
std
::
string
WebRtcTransportImp
::
getIP
()
const
{
//todo 替换为外网ip
return
SockUtil
::
get_local_ip
();
void
WebRtcTransportImp
::
onSendSockData
(
const
char
*
buf
,
size_t
len
,
struct
sockaddr_in
*
dst
,
bool
flush
)
{
auto
ptr
=
BufferRaw
::
create
();
ptr
->
assign
(
buf
,
len
);
_socket
->
send
(
ptr
,
(
struct
sockaddr
*
)(
dst
),
sizeof
(
struct
sockaddr
),
flush
);
}
SdpAttrCandidate
::
Ptr
WebRtcTransportImp
::
getIceCandidate
()
const
{
...
...
@@ -241,12 +249,22 @@ SdpAttrCandidate::Ptr WebRtcTransportImp::getIceCandidate() const{
candidate
->
component
=
1
;
candidate
->
transport
=
"udp"
;
candidate
->
priority
=
100
;
candidate
->
address
=
getIP
();
candidate
->
port
=
getP
ort
();
candidate
->
address
=
SockUtil
::
get_local_ip
();
candidate
->
port
=
_socket
->
get_local_p
ort
();
candidate
->
type
=
"host"
;
return
candidate
;
}
void
WebRtcTransportImp
::
onRtp
(
const
char
*
buf
,
size_t
len
)
{
RtpHeader
*
rtp
=
(
RtpHeader
*
)
buf
;
// TraceL << (int)rtp->ssrc;
}
void
WebRtcTransportImp
::
onRtcp
(
const
char
*
buf
,
size_t
len
)
{
RtcpHeader
*
rtcp
=
(
RtcpHeader
*
)
buf
;
// TraceL << rtcpTypeToStr((RtcpType)rtcp->pt);
}
///////////////////////////////////////////////////////////////////
...
...
webrtc/WebRtcTransport.h
查看文件 @
ee072191
...
...
@@ -44,7 +44,7 @@ public:
* @param buf rtcp内容
* @param len rtcp长度
*/
void
sendRtpPacket
(
char
*
buf
,
size_t
len
);
void
sendRtpPacket
(
char
*
buf
,
size_t
len
,
bool
flush
);
protected
:
//// dtls相关的回调 ////
...
...
@@ -71,19 +71,18 @@ protected:
void
OnIceServerDisconnected
(
const
RTC
::
IceServer
*
iceServer
)
override
;
protected
:
virtual
uint32_t
getSSRC
()
const
=
0
;
virtual
uint16_t
getPort
()
const
=
0
;
virtual
std
::
string
getIP
()
const
=
0
;
virtual
void
onStartWebRTC
()
=
0
;
virtual
void
onRtcConfigure
(
RtcConfigure
&
configure
)
const
{}
virtual
void
onCheckSdp
(
SdpType
type
,
const
RtcSession
&
sdp
)
const
;
virtual
void
onCheckSdp
(
SdpType
type
,
RtcSession
&
sdp
)
const
;
virtual
SdpAttrCandidate
::
Ptr
getIceCandidate
()
const
=
0
;
virtual
void
onSendSockData
(
const
char
*
buf
,
size_t
len
,
struct
sockaddr_in
*
dst
)
=
0
;
virtual
void
onSendSockData
(
const
char
*
buf
,
size_t
len
,
struct
sockaddr_in
*
dst
,
bool
flush
=
true
)
=
0
;
virtual
void
onRtp
(
const
char
*
buf
,
size_t
len
)
=
0
;
virtual
void
onRtcp
(
const
char
*
buf
,
size_t
len
)
=
0
;
private
:
void
onSendSockData
(
const
char
*
buf
,
size_t
len
);
void
onSendSockData
(
const
char
*
buf
,
size_t
len
,
bool
flush
=
true
);
void
setRemoteDtlsFingerprint
(
const
RtcSession
&
remote
);
private
:
...
...
@@ -115,15 +114,17 @@ public:
protected
:
void
onStartWebRTC
()
override
;
void
onSendSockData
(
const
char
*
buf
,
size_t
len
,
struct
sockaddr_in
*
dst
)
override
;
uint32_t
getSSRC
()
const
override
;
uint16_t
getPort
()
const
override
;
std
::
string
getIP
()
const
override
;
void
onSendSockData
(
const
char
*
buf
,
size_t
len
,
struct
sockaddr_in
*
dst
,
bool
flush
=
true
)
override
;
void
onCheckSdp
(
SdpType
type
,
RtcSession
&
sdp
)
const
override
;
SdpAttrCandidate
::
Ptr
getIceCandidate
()
const
override
;
void
onRtp
(
const
char
*
buf
,
size_t
len
)
override
;
void
onRtcp
(
const
char
*
buf
,
size_t
len
)
override
;
private
:
WebRtcTransportImp
(
const
EventPoller
::
Ptr
&
poller
);
void
onDestory
()
override
;
void
onSendRtp
(
const
RtpPacket
::
Ptr
&
rtp
,
bool
flush
);
private
:
Socket
::
Ptr
_socket
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论