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
50ca789c
Commit
50ca789c
authored
Apr 05, 2021
by
xiongziliang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
预留同时推流拉流的接口
parent
606f2513
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
33 行增加
和
21 行删除
+33
-21
server/WebApi.cpp
+2
-2
webrtc/WebRtcTransport.cpp
+24
-16
webrtc/WebRtcTransport.h
+7
-3
没有找到文件。
server/WebApi.cpp
查看文件 @
50ca789c
...
...
@@ -1105,7 +1105,7 @@ void installWebApi() {
throw
runtime_error
(
StrPrinter
<<
"播放鉴权失败:"
<<
err
);
}
auto
rtc
=
WebRtcTransportImp
::
create
(
EventPollerPool
::
Instance
().
getPoller
());
rtc
->
attach
(
src
);
rtc
->
attach
(
src
,
true
);
val
[
"sdp"
]
=
rtc
->
getAnswerSdp
(
offer_sdp
);
val
[
"type"
]
=
"answer"
;
rtcs
.
emplace_back
(
rtc
);
...
...
@@ -1139,7 +1139,7 @@ void installWebApi() {
auto
push_src
=
std
::
make_shared
<
RtspMediaSourceImp
>
(
info
.
_vhost
,
info
.
_app
,
info
.
_streamid
);
push_src
->
setProtocolTranslation
(
enableHls
,
enableMP4
);
auto
rtc
=
WebRtcTransportImp
::
create
(
EventPollerPool
::
Instance
().
getPoller
());
rtc
->
attach
(
push_src
);
rtc
->
attach
(
push_src
,
false
);
val
[
"sdp"
]
=
rtc
->
getAnswerSdp
(
offer_sdp
);
val
[
"type"
]
=
"answer"
;
rtcs
.
emplace_back
(
rtc
);
...
...
webrtc/WebRtcTransport.cpp
查看文件 @
50ca789c
...
...
@@ -224,9 +224,13 @@ void WebRtcTransportImp::onDestory() {
WebRtcTransport
::
onDestory
();
}
void
WebRtcTransportImp
::
attach
(
const
RtspMediaSource
::
Ptr
&
src
)
{
void
WebRtcTransportImp
::
attach
(
const
RtspMediaSource
::
Ptr
&
src
,
bool
is_play
)
{
assert
(
src
);
_src
=
src
;
if
(
is_play
)
{
_play_src
=
src
;
}
else
{
_push_src
=
src
;
}
}
void
WebRtcTransportImp
::
onSendSockData
(
const
char
*
buf
,
size_t
len
,
struct
sockaddr_in
*
dst
,
bool
flush
)
{
...
...
@@ -239,12 +243,12 @@ void WebRtcTransportImp::onSendSockData(const char *buf, size_t len, struct sock
bool
WebRtcTransportImp
::
canSendRtp
()
const
{
auto
&
sdp
=
getSdp
(
SdpType
::
answer
);
return
sdp
.
media
[
0
].
direction
==
RtpDirection
::
sendrecv
||
sdp
.
media
[
0
].
direction
==
RtpDirection
::
sendonly
;
return
_play_src
&&
(
sdp
.
media
[
0
].
direction
==
RtpDirection
::
sendrecv
||
sdp
.
media
[
0
].
direction
==
RtpDirection
::
sendonly
)
;
}
bool
WebRtcTransportImp
::
canRecvRtp
()
const
{
auto
&
sdp
=
getSdp
(
SdpType
::
answer
);
return
sdp
.
media
[
0
].
direction
==
RtpDirection
::
sendrecv
||
sdp
.
media
[
0
].
direction
==
RtpDirection
::
recvonly
;
return
_push_src
&&
(
sdp
.
media
[
0
].
direction
==
RtpDirection
::
sendrecv
||
sdp
.
media
[
0
].
direction
==
RtpDirection
::
recvonly
)
;
}
void
WebRtcTransportImp
::
onStartWebRTC
()
{
...
...
@@ -274,10 +278,10 @@ void WebRtcTransportImp::onStartWebRTC() {
}
if
(
canRecvRtp
())
{
_src
->
setSdp
(
getSdp
(
SdpType
::
answer
).
toRtspSdp
());
_
push_
src
->
setSdp
(
getSdp
(
SdpType
::
answer
).
toRtspSdp
());
}
if
(
canSendRtp
())
{
_reader
=
_src
->
getRing
()
->
attach
(
_socket
->
getPoller
(),
true
);
_reader
=
_
play_
src
->
getRing
()
->
attach
(
_socket
->
getPoller
(),
true
);
weak_ptr
<
WebRtcTransportImp
>
weak_self
=
shared_from_this
();
_reader
->
setReadCB
([
weak_self
](
const
RtspMediaSource
::
RingDataType
&
pkt
)
{
auto
strongSelf
=
weak_self
.
lock
();
...
...
@@ -299,14 +303,14 @@ void WebRtcTransportImp::onCheckSdp(SdpType type, RtcSession &sdp){
}
RtcSession
rtsp_send_sdp
;
rtsp_send_sdp
.
loadFrom
(
_src
->
getSdp
(),
false
);
rtsp_send_sdp
.
loadFrom
(
_
play_
src
->
getSdp
(),
false
);
for
(
auto
&
m
:
sdp
.
media
)
{
if
(
m
.
type
==
TrackApplication
)
{
continue
;
}
//添加answer sdp的ssrc信息
m
.
rtp_ssrc
.
ssrc
=
_src
->
getSsrc
(
m
.
type
);
m
.
rtp_ssrc
.
ssrc
=
_
play_
src
->
getSsrc
(
m
.
type
);
m
.
rtp_ssrc
.
cname
=
RTP_CNAME
;
//todo 先屏蔽rtx,因为chrome报错
if
(
false
&&
m
.
getRelatedRtxPlan
(
m
.
plan
[
0
].
pt
))
{
...
...
@@ -324,15 +328,17 @@ void WebRtcTransportImp::onCheckSdp(SdpType type, RtcSession &sdp){
void
WebRtcTransportImp
::
onRtcConfigure
(
RtcConfigure
&
configure
)
const
{
WebRtcTransport
::
onRtcConfigure
(
configure
);
if
(
!
_src
->
getSdp
().
empty
()
)
{
//这是播放
configure
.
video
.
direction
=
RtpDirection
::
sendonly
;
configure
.
audio
.
direction
=
RtpDirection
::
sendonly
;
configure
.
setPlayRtspInfo
(
_src
->
getSdp
());
}
else
{
//这是推流
if
(
_play_src
)
{
//这是播放
,同时也可能有推流
configure
.
video
.
direction
=
_push_src
?
RtpDirection
::
sendrecv
:
RtpDirection
::
sendonly
;
configure
.
audio
.
direction
=
configure
.
video
.
direction
;
configure
.
setPlayRtspInfo
(
_
play_
src
->
getSdp
());
}
else
if
(
_push_src
)
{
//这
只
是推流
configure
.
video
.
direction
=
RtpDirection
::
recvonly
;
configure
.
audio
.
direction
=
RtpDirection
::
recvonly
;
}
else
{
throw
std
::
invalid_argument
(
"未设置播放或推流的媒体源"
);
}
//添加接收端口candidate信息
...
...
@@ -455,7 +461,9 @@ void WebRtcTransportImp::onSortedRtp(const RtpPayloadInfo &info, RtpPacket::Ptr
sendRtcpPacket
((
char
*
)
pli
.
get
(),
sizeof
(
RtcpPli
),
true
);
InfoL
<<
"send pli"
;
}
_src
->
onWrite
(
std
::
move
(
rtp
),
false
);
if
(
_push_src
)
{
_push_src
->
onWrite
(
std
::
move
(
rtp
),
false
);
}
}
void
WebRtcTransportImp
::
onBeforeSortedRtp
(
const
RtpPayloadInfo
&
info
,
const
RtpPacket
::
Ptr
&
rtp
)
{
...
...
webrtc/WebRtcTransport.h
查看文件 @
50ca789c
...
...
@@ -119,8 +119,9 @@ public:
/**
* 绑定rtsp媒体源
* @param src 媒体源
* @param is_play 是播放还是推流
*/
void
attach
(
const
RtspMediaSource
::
Ptr
&
src
);
void
attach
(
const
RtspMediaSource
::
Ptr
&
src
,
bool
is_play
=
true
);
protected
:
void
onStartWebRTC
()
override
;
...
...
@@ -161,8 +162,11 @@ private:
uint8_t
_send_rtp_pt
[
2
]
=
{
0
,
0
};
//复合udp端口,接收一切rtp与rtcp
Socket
::
Ptr
_socket
;
//推流或播放的rtsp源
RtspMediaSource
::
Ptr
_src
;
//推流的rtsp源
RtspMediaSource
::
Ptr
_push_src
;
//播放的rtsp源
RtspMediaSource
::
Ptr
_play_src
;
//播放rtsp源的reader对象
RtspMediaSource
::
RingType
::
RingReader
::
Ptr
_reader
;
//根据rtp的pt获取相关信息
unordered_map
<
uint8_t
,
RtpPayloadInfo
>
_rtp_info_pt
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论