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
c6a0e3ad
Commit
c6a0e3ad
authored
Aug 20, 2022
by
xiongziliang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rtp发送启停支持触发观看人数统计事件
parent
9f0c15a4
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
19 行增加
和
16 行删除
+19
-16
api/source/mk_media.cpp
+3
-2
src/Common/MediaSource.cpp
+6
-4
src/Common/MediaSource.h
+1
-1
src/Common/MultiMediaSourceMuxer.cpp
+9
-9
没有找到文件。
api/source/mk_media.cpp
查看文件 @
c6a0e3ad
...
@@ -266,7 +266,7 @@ API_EXPORT void API_CALL mk_media_start_send_rtp(mk_media ctx, const char *dst_u
...
@@ -266,7 +266,7 @@ API_EXPORT void API_CALL mk_media_start_send_rtp(mk_media ctx, const char *dst_u
args
.
is_udp
=
is_udp
;
args
.
is_udp
=
is_udp
;
//sender参数无用
//sender参数无用
(
*
obj
)
->
getChannel
()
->
startSendRtp
(
*
MediaSource
::
NullMediaSource
,
args
,
[
cb
,
user_data
](
uint16_t
local_port
,
const
SockException
&
ex
){
(
*
obj
)
->
getChannel
()
->
startSendRtp
(
MediaSource
::
NullMediaSource
,
args
,
[
cb
,
user_data
](
uint16_t
local_port
,
const
SockException
&
ex
){
if
(
cb
)
{
if
(
cb
)
{
cb
(
user_data
,
local_port
,
ex
.
getErrCode
(),
ex
.
what
());
cb
(
user_data
,
local_port
,
ex
.
getErrCode
(),
ex
.
what
());
}
}
...
@@ -277,5 +277,5 @@ API_EXPORT int API_CALL mk_media_stop_send_rtp(mk_media ctx, const char *ssrc){
...
@@ -277,5 +277,5 @@ API_EXPORT int API_CALL mk_media_stop_send_rtp(mk_media ctx, const char *ssrc){
assert
(
ctx
);
assert
(
ctx
);
MediaHelper
::
Ptr
*
obj
=
(
MediaHelper
::
Ptr
*
)
ctx
;
MediaHelper
::
Ptr
*
obj
=
(
MediaHelper
::
Ptr
*
)
ctx
;
//sender参数无用
//sender参数无用
return
(
*
obj
)
->
getChannel
()
->
stopSendRtp
(
*
MediaSource
::
NullMediaSource
,
ssrc
?
ssrc
:
""
);
return
(
*
obj
)
->
getChannel
()
->
stopSendRtp
(
MediaSource
::
NullMediaSource
,
ssrc
?
ssrc
:
""
);
}
}
\ No newline at end of file
src/Common/MediaSource.cpp
查看文件 @
c6a0e3ad
...
@@ -44,15 +44,17 @@ string getOriginTypeString(MediaOriginType type){
...
@@ -44,15 +44,17 @@ string getOriginTypeString(MediaOriginType type){
}
}
static
string
getOriginUrl_l
(
const
MediaSource
*
thiz
)
{
static
string
getOriginUrl_l
(
const
MediaSource
*
thiz
)
{
if
(
thiz
==
MediaSource
::
NullMediaSource
)
{
return
""
;
}
return
thiz
->
getSchema
()
+
"://"
+
thiz
->
getVhost
()
+
"/"
+
thiz
->
getApp
()
+
"/"
+
thiz
->
getId
();
return
thiz
->
getSchema
()
+
"://"
+
thiz
->
getVhost
()
+
"/"
+
thiz
->
getApp
()
+
"/"
+
thiz
->
getId
();
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
struct
MediaSourceNull
:
public
MediaSource
{
MediaSourceNull
()
:
MediaSource
(
"schema"
,
"vhost"
,
"app"
,
"stream"
)
{};
int
readerCount
()
override
{
return
0
;
}
};
MediaSource
*
const
MediaSource
::
NullMediaSource
=
nullptr
;
static
std
::
shared_ptr
<
MediaSource
>
s_null
=
std
::
make_shared
<
MediaSourceNull
>
();
MediaSource
&
MediaSource
::
NullMediaSource
=
*
s_null
;
MediaSource
::
MediaSource
(
const
string
&
schema
,
const
string
&
vhost
,
const
string
&
app
,
const
string
&
stream_id
){
MediaSource
::
MediaSource
(
const
string
&
schema
,
const
string
&
vhost
,
const
string
&
app
,
const
string
&
stream_id
){
GET_CONFIG
(
bool
,
enableVhost
,
General
::
kEnableVhost
);
GET_CONFIG
(
bool
,
enableVhost
,
General
::
kEnableVhost
);
...
...
src/Common/MediaSource.h
查看文件 @
c6a0e3ad
...
@@ -235,7 +235,7 @@ private:
...
@@ -235,7 +235,7 @@ private:
*/
*/
class
MediaSource
:
public
TrackSource
,
public
std
::
enable_shared_from_this
<
MediaSource
>
{
class
MediaSource
:
public
TrackSource
,
public
std
::
enable_shared_from_this
<
MediaSource
>
{
public
:
public
:
static
MediaSource
*
const
NullMediaSource
;
static
MediaSource
&
NullMediaSource
;
using
Ptr
=
std
::
shared_ptr
<
MediaSource
>
;
using
Ptr
=
std
::
shared_ptr
<
MediaSource
>
;
using
StreamMap
=
std
::
unordered_map
<
std
::
string
/*stream_id*/
,
std
::
weak_ptr
<
MediaSource
>
>
;
using
StreamMap
=
std
::
unordered_map
<
std
::
string
/*stream_id*/
,
std
::
weak_ptr
<
MediaSource
>
>
;
using
AppStreamMap
=
std
::
unordered_map
<
std
::
string
/*app*/
,
StreamMap
>
;
using
AppStreamMap
=
std
::
unordered_map
<
std
::
string
/*app*/
,
StreamMap
>
;
...
...
src/Common/MultiMediaSourceMuxer.cpp
查看文件 @
c6a0e3ad
...
@@ -78,7 +78,7 @@ static string getTrackInfoStr(const TrackSource *track_src){
...
@@ -78,7 +78,7 @@ static string getTrackInfoStr(const TrackSource *track_src){
MultiMediaSourceMuxer
::
MultiMediaSourceMuxer
(
const
string
&
vhost
,
const
string
&
app
,
const
string
&
stream
,
float
dur_sec
,
const
ProtocolOption
&
option
)
{
MultiMediaSourceMuxer
::
MultiMediaSourceMuxer
(
const
string
&
vhost
,
const
string
&
app
,
const
string
&
stream
,
float
dur_sec
,
const
ProtocolOption
&
option
)
{
_option
=
option
;
_option
=
option
;
_get_origin_url
=
[
this
,
vhost
,
app
,
stream
]()
{
_get_origin_url
=
[
this
,
vhost
,
app
,
stream
]()
{
auto
ret
=
getOriginUrl
(
*
MediaSource
::
NullMediaSource
);
auto
ret
=
getOriginUrl
(
MediaSource
::
NullMediaSource
);
if
(
!
ret
.
empty
())
{
if
(
!
ret
.
empty
())
{
return
ret
;
return
ret
;
}
}
...
@@ -237,11 +237,14 @@ void MultiMediaSourceMuxer::startSendRtp(MediaSource &, const MediaSourceEvent::
...
@@ -237,11 +237,14 @@ void MultiMediaSourceMuxer::startSendRtp(MediaSource &, const MediaSourceEvent::
auto
ssrc
=
args
.
ssrc
;
auto
ssrc
=
args
.
ssrc
;
rtp_sender
->
setOnClose
([
weak_self
,
ssrc
]()
{
rtp_sender
->
setOnClose
([
weak_self
,
ssrc
]()
{
if
(
auto
strong_self
=
weak_self
.
lock
())
{
if
(
auto
strong_self
=
weak_self
.
lock
())
{
strong_self
->
_rtp_sender
.
erase
(
ssrc
);
WarnL
<<
"stream:"
<<
strong_self
->
_get_origin_url
()
<<
" stop send rtp:"
<<
ssrc
;
WarnL
<<
"stream:"
<<
strong_self
->
_get_origin_url
()
<<
" stop send rtp:"
<<
ssrc
;
strong_self
->
_rtp_sender
.
erase
(
ssrc
);
//触发观看人数统计
strong_self
->
onReaderChanged
(
MediaSource
::
NullMediaSource
,
strong_self
->
totalReaderCount
());
}
}
});
});
strong_self
->
_rtp_sender
[
args
.
ssrc
]
=
std
::
move
(
rtp_sender
);
strong_self
->
_rtp_sender
[
args
.
ssrc
]
=
std
::
move
(
rtp_sender
);
strong_self
->
onReaderChanged
(
MediaSource
::
NullMediaSource
,
strong_self
->
totalReaderCount
());
});
});
#else
#else
cb
(
0
,
SockException
(
Err_other
,
"该功能未启用,编译时请打开ENABLE_RTPPROXY宏"
));
cb
(
0
,
SockException
(
Err_other
,
"该功能未启用,编译时请打开ENABLE_RTPPROXY宏"
));
...
@@ -250,13 +253,10 @@ void MultiMediaSourceMuxer::startSendRtp(MediaSource &, const MediaSourceEvent::
...
@@ -250,13 +253,10 @@ void MultiMediaSourceMuxer::startSendRtp(MediaSource &, const MediaSourceEvent::
bool
MultiMediaSourceMuxer
::
stopSendRtp
(
MediaSource
&
sender
,
const
string
&
ssrc
)
{
bool
MultiMediaSourceMuxer
::
stopSendRtp
(
MediaSource
&
sender
,
const
string
&
ssrc
)
{
#if defined(ENABLE_RTPPROXY)
#if defined(ENABLE_RTPPROXY)
std
::
unique_ptr
<
onceToken
>
token
;
onceToken
token
(
nullptr
,
[
&
]()
{
if
(
&
sender
!=
MediaSource
::
NullMediaSource
)
{
//关闭rtp推流,可能触发无人观看事件
token
.
reset
(
new
onceToken
(
nullptr
,
[
&
]()
{
onReaderChanged
(
sender
,
totalReaderCount
());
//关闭rtp推流,可能触发无人观看事件
});
MediaSourceEventInterceptor
::
onReaderChanged
(
sender
,
totalReaderCount
());
}));
}
if
(
ssrc
.
empty
())
{
if
(
ssrc
.
empty
())
{
//关闭全部
//关闭全部
auto
size
=
_rtp_sender
.
size
();
auto
size
=
_rtp_sender
.
size
();
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论