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
...
@@ -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
();
auto
tuple
=
_ice_server
->
GetSelectedTuple
();
assert
(
tuple
);
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
){
string
getFingerprint
(
const
string
&
algorithm_str
,
const
std
::
shared_ptr
<
RTC
::
DtlsTransport
>
&
transport
){
...
@@ -85,7 +85,7 @@ void WebRtcTransport::setRemoteDtlsFingerprint(const RtcSession &remote){
...
@@ -85,7 +85,7 @@ void WebRtcTransport::setRemoteDtlsFingerprint(const RtcSession &remote){
_dtls_transport
->
SetRemoteFingerprint
(
remote_fingerprint
);
_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
)
{
for
(
auto
&
m
:
sdp
.
media
)
{
if
(
m
.
type
!=
TrackApplication
&&
!
m
.
rtcp_mux
)
{
if
(
m
.
type
!=
TrackApplication
&&
!
m
.
rtcp_mux
)
{
throw
std
::
invalid_argument
(
"只支持rtcp-mux模式"
);
throw
std
::
invalid_argument
(
"只支持rtcp-mux模式"
);
...
@@ -150,23 +150,27 @@ void WebRtcTransport::inputSockData(char *buf, size_t len, RTC::TransportTuple *
...
@@ -150,23 +150,27 @@ void WebRtcTransport::inputSockData(char *buf, size_t len, RTC::TransportTuple *
return
;
return
;
}
}
if
(
is_rtp
(
buf
))
{
if
(
is_rtp
(
buf
))
{
RtpHeader
*
header
=
(
RtpHeader
*
)
buf
;
if
(
_srtp_session_recv
->
DecryptSrtp
((
uint8_t
*
)
buf
,
&
len
))
{
onRtp
(
buf
,
len
);
}
return
;
return
;
}
}
if
(
is_rtcp
(
buf
))
{
if
(
is_rtcp
(
buf
))
{
RtcpHeader
*
header
=
(
RtcpHeader
*
)
buf
;
if
(
_srtp_session_recv
->
DecryptSrtcp
((
uint8_t
*
)
buf
,
&
len
))
{
onRtcp
(
buf
,
len
);
}
return
;
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
;
const
uint8_t
*
p
=
(
uint8_t
*
)
buf
;
bool
ret
=
false
;
bool
ret
=
false
;
if
(
_srtp_session_send
)
{
if
(
_srtp_session_send
)
{
ret
=
_srtp_session_send
->
EncryptRtp
(
&
p
,
&
len
);
ret
=
_srtp_session_send
->
EncryptRtp
(
&
p
,
&
len
);
}
}
if
(
ret
)
{
if
(
ret
)
{
onSendSockData
((
char
*
)
p
,
len
);
onSendSockData
((
char
*
)
p
,
len
,
flush
);
}
}
}
}
...
@@ -205,34 +209,38 @@ void WebRtcTransportImp::onStartWebRTC() {
...
@@ -205,34 +209,38 @@ void WebRtcTransportImp::onStartWebRTC() {
if
(
!
strongSelf
)
{
if
(
!
strongSelf
)
{
return
;
return
;
}
}
size_t
i
=
0
;
pkt
->
for_each
([
&
](
const
RtpPacket
::
Ptr
&
rtp
)
{
pkt
->
for_each
([
&
](
const
RtpPacket
::
Ptr
&
rtp
)
{
if
(
rtp
->
type
==
TrackVideo
)
{
strongSelf
->
onSendRtp
(
rtp
,
++
i
==
pkt
->
size
());
//目前只支持视频
strongSelf
->
sendRtpPacket
(
rtp
->
data
()
+
RtpPacket
::
kRtpTcpHeaderSize
,
rtp
->
size
()
-
RtpPacket
::
kRtpTcpHeaderSize
);
}
});
});
});
});
}
}
void
WebRtcTransportImp
::
onSendSockData
(
const
char
*
buf
,
size_t
len
,
struct
sockaddr_in
*
dst
)
{
void
WebRtcTransportImp
::
onSendRtp
(
const
RtpPacket
::
Ptr
&
rtp
,
bool
flush
){
auto
ptr
=
BufferRaw
::
create
();
InfoL
<<
flush
;
ptr
->
assign
(
buf
,
len
);
_socket
->
send
(
ptr
,
(
struct
sockaddr
*
)(
dst
),
sizeof
(
struct
sockaddr
));
}
}
uint32_t
WebRtcTransportImp
::
getSSRC
()
const
{
void
WebRtcTransportImp
::
onCheckSdp
(
SdpType
type
,
RtcSession
&
sdp
)
const
{
return
_src
->
getSsrc
(
TrackVideo
);
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
{
m
.
rtp_ssrc
.
cname
=
"zlmediakit rtc"
;
//todo udp端口号应该与外网映射端口相同
m
.
rtx_ssrc
.
cname
=
"zlmediakit rtc"
;
return
_socket
->
get_local_port
();
}
}
}
std
::
string
WebRtcTransportImp
::
getIP
()
const
{
void
WebRtcTransportImp
::
onSendSockData
(
const
char
*
buf
,
size_t
len
,
struct
sockaddr_in
*
dst
,
bool
flush
)
{
//todo 替换为外网ip
auto
ptr
=
BufferRaw
::
create
();
return
SockUtil
::
get_local_ip
();
ptr
->
assign
(
buf
,
len
);
_socket
->
send
(
ptr
,
(
struct
sockaddr
*
)(
dst
),
sizeof
(
struct
sockaddr
),
flush
);
}
}
SdpAttrCandidate
::
Ptr
WebRtcTransportImp
::
getIceCandidate
()
const
{
SdpAttrCandidate
::
Ptr
WebRtcTransportImp
::
getIceCandidate
()
const
{
...
@@ -241,12 +249,22 @@ SdpAttrCandidate::Ptr WebRtcTransportImp::getIceCandidate() const{
...
@@ -241,12 +249,22 @@ SdpAttrCandidate::Ptr WebRtcTransportImp::getIceCandidate() const{
candidate
->
component
=
1
;
candidate
->
component
=
1
;
candidate
->
transport
=
"udp"
;
candidate
->
transport
=
"udp"
;
candidate
->
priority
=
100
;
candidate
->
priority
=
100
;
candidate
->
address
=
getIP
();
candidate
->
address
=
SockUtil
::
get_local_ip
();
candidate
->
port
=
getP
ort
();
candidate
->
port
=
_socket
->
get_local_p
ort
();
candidate
->
type
=
"host"
;
candidate
->
type
=
"host"
;
return
candidate
;
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:
...
@@ -44,7 +44,7 @@ public:
* @param buf rtcp内容
* @param buf rtcp内容
* @param len rtcp长度
* @param len rtcp长度
*/
*/
void
sendRtpPacket
(
char
*
buf
,
size_t
len
);
void
sendRtpPacket
(
char
*
buf
,
size_t
len
,
bool
flush
);
protected
:
protected
:
//// dtls相关的回调 ////
//// dtls相关的回调 ////
...
@@ -71,19 +71,18 @@ protected:
...
@@ -71,19 +71,18 @@ protected:
void
OnIceServerDisconnected
(
const
RTC
::
IceServer
*
iceServer
)
override
;
void
OnIceServerDisconnected
(
const
RTC
::
IceServer
*
iceServer
)
override
;
protected
:
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
onStartWebRTC
()
=
0
;
virtual
void
onRtcConfigure
(
RtcConfigure
&
configure
)
const
{}
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
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
:
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
);
void
setRemoteDtlsFingerprint
(
const
RtcSession
&
remote
);
private
:
private
:
...
@@ -115,15 +114,17 @@ public:
...
@@ -115,15 +114,17 @@ public:
protected
:
protected
:
void
onStartWebRTC
()
override
;
void
onStartWebRTC
()
override
;
void
onSendSockData
(
const
char
*
buf
,
size_t
len
,
struct
sockaddr_in
*
dst
)
override
;
void
onSendSockData
(
const
char
*
buf
,
size_t
len
,
struct
sockaddr_in
*
dst
,
bool
flush
=
true
)
override
;
uint32_t
getSSRC
()
const
override
;
void
onCheckSdp
(
SdpType
type
,
RtcSession
&
sdp
)
const
override
;
uint16_t
getPort
()
const
override
;
std
::
string
getIP
()
const
override
;
SdpAttrCandidate
::
Ptr
getIceCandidate
()
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
:
private
:
WebRtcTransportImp
(
const
EventPoller
::
Ptr
&
poller
);
WebRtcTransportImp
(
const
EventPoller
::
Ptr
&
poller
);
void
onDestory
()
override
;
void
onDestory
()
override
;
void
onSendRtp
(
const
RtpPacket
::
Ptr
&
rtp
,
bool
flush
);
private
:
private
:
Socket
::
Ptr
_socket
;
Socket
::
Ptr
_socket
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论