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
feaacf39
Unverified
Commit
feaacf39
authored
Sep 02, 2022
by
夏楚
Committed by
GitHub
Sep 02, 2022
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1920 from custompal/cus_pr
增加获取媒体流播放器列表功能
parents
48d49a33
33e1e6b8
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
14 个修改的文件
包含
123 行增加
和
106 行删除
+123
-106
3rdpart/ZLToolKit
+1
-1
server/WebApi.cpp
+29
-0
src/Common/MediaSource.h
+7
-47
src/FMP4/FMP4MediaSource.h
+5
-0
src/Http/HttpSession.cpp
+20
-18
src/Rtmp/FlvMuxer.cpp
+15
-14
src/Rtmp/RtmpMediaSource.h
+5
-0
src/Rtmp/RtmpSession.cpp
+20
-19
src/Rtp/RtpSelector.h
+1
-1
src/Rtsp/RtspMediaSource.h
+5
-0
src/Rtsp/RtspSession.cpp
+0
-0
src/TS/TSMediaSource.h
+5
-0
srt/SrtTransportImp.cpp
+2
-0
webrtc/WebRtcPlayer.cpp
+8
-6
没有找到文件。
ZLToolKit
@
23575ba8
Subproject commit
658271fdf4fb497b0665c06544627789844a003a
Subproject commit
23575ba82d00641f8f33851b1d85391da310c378
server/WebApi.cpp
查看文件 @
feaacf39
...
...
@@ -741,6 +741,35 @@ void installWebApi() {
val
[
"online"
]
=
(
bool
)
(
MediaSource
::
find
(
allArgs
[
"schema"
],
allArgs
[
"vhost"
],
allArgs
[
"app"
],
allArgs
[
"stream"
]));
});
api_regist
(
"/index/api/getMediaPlayerList"
,[](
API_ARGS_MAP_ASYNC
){
CHECK_SECRET
();
CHECK_ARGS
(
"schema"
,
"vhost"
,
"app"
,
"stream"
);
auto
src
=
MediaSource
::
find
(
allArgs
[
"schema"
],
allArgs
[
"vhost"
],
allArgs
[
"app"
],
allArgs
[
"stream"
]);
if
(
!
src
)
{
throw
ApiRetException
(
"can not find the stream"
,
API
::
NotFound
);
}
src
->
getPlayerList
(
[
=
](
const
std
::
list
<
std
::
shared_ptr
<
void
>>
&
info_list
)
mutable
{
val
[
"code"
]
=
API
::
Success
;
auto
&
data
=
val
[
"data"
];
data
=
Value
(
arrayValue
);
for
(
auto
&
info
:
info_list
)
{
auto
obj
=
static_pointer_cast
<
Value
>
(
info
);
data
.
append
(
std
::
move
(
*
obj
));
}
invoker
(
200
,
headerOut
,
val
.
toStyledString
());
},
[](
std
::
shared_ptr
<
void
>
&&
info
)
->
std
::
shared_ptr
<
void
>
{
auto
obj
=
std
::
make_shared
<
Value
>
();
auto
session
=
static_pointer_cast
<
Session
>
(
info
);
(
*
obj
)[
"peer_ip"
]
=
session
->
get_peer_ip
();
(
*
obj
)[
"peer_port"
]
=
session
->
get_peer_port
();
(
*
obj
)[
"id"
]
=
session
->
getIdentifier
();
(
*
obj
)[
"typeid"
]
=
toolkit
::
demangle
(
typeid
(
*
session
).
name
());
return
obj
;
});
});
//测试url http://127.0.0.1/index/api/getMediaInfo?schema=rtsp&vhost=__defaultVhost__&app=live&stream=obs
api_regist
(
"/index/api/getMediaInfo"
,[](
API_ARGS_MAP_ASYNC
){
CHECK_SECRET
();
...
...
src/Common/MediaSource.h
查看文件 @
feaacf39
...
...
@@ -192,52 +192,6 @@ public:
std
::
string
_param_strs
;
};
class
BytesSpeed
{
public
:
BytesSpeed
()
=
default
;
~
BytesSpeed
()
=
default
;
/**
* 添加统计字节
*/
BytesSpeed
&
operator
+=
(
size_t
bytes
)
{
_bytes
+=
bytes
;
if
(
_bytes
>
1024
*
1024
)
{
//数据大于1MB就计算一次网速
computeSpeed
();
}
return
*
this
;
}
/**
* 获取速度,单位bytes/s
*/
int
getSpeed
()
{
if
(
_ticker
.
elapsedTime
()
<
1000
)
{
//获取频率小于1秒,那么返回上次计算结果
return
_speed
;
}
return
computeSpeed
();
}
private
:
int
computeSpeed
()
{
auto
elapsed
=
_ticker
.
elapsedTime
();
if
(
!
elapsed
)
{
return
_speed
;
}
_speed
=
(
int
)(
_bytes
*
1000
/
elapsed
);
_ticker
.
resetTime
();
_bytes
=
0
;
return
_speed
;
}
private
:
int
_speed
=
0
;
size_t
_bytes
=
0
;
toolkit
::
Ticker
_ticker
;
};
/**
* 媒体源,任何rtsp/rtmp的直播流都源自该对象
*/
...
...
@@ -293,6 +247,12 @@ public:
virtual
int
readerCount
()
=
0
;
// 观看者个数,包括(hls/rtsp/rtmp)
virtual
int
totalReaderCount
();
// 获取播放器列表
virtual
void
getPlayerList
(
const
std
::
function
<
void
(
const
std
::
list
<
std
::
shared_ptr
<
void
>>
&
info_list
)
>
&
cb
,
const
std
::
function
<
std
::
shared_ptr
<
void
>
(
std
::
shared_ptr
<
void
>
&&
info
)
>
&
on_change
)
{
assert
(
cb
);
cb
(
std
::
list
<
std
::
shared_ptr
<
void
>>
());
}
// 获取媒体源类型
MediaOriginType
getOriginType
()
const
;
...
...
@@ -350,7 +310,7 @@ private:
void
emitEvent
(
bool
regist
);
protected
:
BytesSpeed
_speed
[
TrackMax
];
toolkit
::
BytesSpeed
_speed
[
TrackMax
];
private
:
std
::
atomic_flag
_owned
{
false
};
...
...
src/FMP4/FMP4MediaSource.h
查看文件 @
feaacf39
...
...
@@ -51,6 +51,11 @@ public:
return
_ring
;
}
void
getPlayerList
(
const
std
::
function
<
void
(
const
std
::
list
<
std
::
shared_ptr
<
void
>>
&
info_list
)
>
&
cb
,
const
std
::
function
<
std
::
shared_ptr
<
void
>
(
std
::
shared_ptr
<
void
>
&&
info
)
>
&
on_change
)
override
{
_ring
->
getInfoList
(
cb
,
on_change
);
}
/**
* 获取fmp4 init segment
*/
...
...
src/Http/HttpSession.cpp
查看文件 @
feaacf39
...
...
@@ -245,8 +245,8 @@ bool HttpSession::checkLiveStream(const string &schema, const string &url_suffi
};
Broadcast
::
AuthInvoker
invoker
=
[
weak_self
,
onRes
](
const
string
&
err
)
{
if
(
auto
strong
S
elf
=
weak_self
.
lock
())
{
strong
S
elf
->
async
([
onRes
,
err
]()
{
onRes
(
err
);
});
if
(
auto
strong
_s
elf
=
weak_self
.
lock
())
{
strong
_s
elf
->
async
([
onRes
,
err
]()
{
onRes
(
err
);
});
}
};
...
...
@@ -277,6 +277,7 @@ bool HttpSession::checkLiveStreamFMP4(const function<void()> &cb){
weak_ptr
<
HttpSession
>
weak_self
=
dynamic_pointer_cast
<
HttpSession
>
(
shared_from_this
());
fmp4_src
->
pause
(
false
);
_fmp4_reader
=
fmp4_src
->
getRing
()
->
attach
(
getPoller
());
_fmp4_reader
->
setGetInfoCB
([
weak_self
]()
{
return
weak_self
.
lock
();
});
_fmp4_reader
->
setDetachCB
([
weak_self
]()
{
auto
strong_self
=
weak_self
.
lock
();
if
(
!
strong_self
)
{
...
...
@@ -318,6 +319,7 @@ bool HttpSession::checkLiveStreamTS(const function<void()> &cb){
weak_ptr
<
HttpSession
>
weak_self
=
dynamic_pointer_cast
<
HttpSession
>
(
shared_from_this
());
ts_src
->
pause
(
false
);
_ts_reader
=
ts_src
->
getRing
()
->
attach
(
getPoller
());
_ts_reader
->
setGetInfoCB
([
weak_self
]()
{
return
weak_self
.
lock
();
});
_ts_reader
->
setDetachCB
([
weak_self
](){
auto
strong_self
=
weak_self
.
lock
();
if
(
!
strong_self
)
{
...
...
@@ -412,19 +414,19 @@ void HttpSession::Handle_Req_GET_l(ssize_t &content_len, bool sendBody) {
}
bool
bClose
=
!
strcasecmp
(
_parser
[
"Connection"
].
data
(),
"close"
);
weak_ptr
<
HttpSession
>
weak
S
elf
=
dynamic_pointer_cast
<
HttpSession
>
(
shared_from_this
());
HttpFileManager
::
onAccessPath
(
*
this
,
_parser
,
[
weak
S
elf
,
bClose
](
int
code
,
const
string
&
content_type
,
weak_ptr
<
HttpSession
>
weak
_s
elf
=
dynamic_pointer_cast
<
HttpSession
>
(
shared_from_this
());
HttpFileManager
::
onAccessPath
(
*
this
,
_parser
,
[
weak
_s
elf
,
bClose
](
int
code
,
const
string
&
content_type
,
const
StrCaseMap
&
responseHeader
,
const
HttpBody
::
Ptr
&
body
)
{
auto
strong
Self
=
weakS
elf
.
lock
();
if
(
!
strong
S
elf
)
{
auto
strong
_self
=
weak_s
elf
.
lock
();
if
(
!
strong
_s
elf
)
{
return
;
}
strong
Self
->
async
([
weakS
elf
,
bClose
,
code
,
content_type
,
responseHeader
,
body
]()
{
auto
strong
Self
=
weakS
elf
.
lock
();
if
(
!
strong
S
elf
)
{
strong
_self
->
async
([
weak_s
elf
,
bClose
,
code
,
content_type
,
responseHeader
,
body
]()
{
auto
strong
_self
=
weak_s
elf
.
lock
();
if
(
!
strong
_s
elf
)
{
return
;
}
strong
S
elf
->
sendResponse
(
code
,
bClose
,
content_type
.
data
(),
responseHeader
,
body
);
strong
_s
elf
->
sendResponse
(
code
,
bClose
,
content_type
.
data
(),
responseHeader
,
body
);
});
});
}
...
...
@@ -645,19 +647,19 @@ void HttpSession::urlDecode(Parser &parser){
bool
HttpSession
::
emitHttpEvent
(
bool
doInvoke
){
bool
bClose
=
!
strcasecmp
(
_parser
[
"Connection"
].
data
(),
"close"
);
/////////////////////异步回复Invoker///////////////////////////////
weak_ptr
<
HttpSession
>
weak
S
elf
=
dynamic_pointer_cast
<
HttpSession
>
(
shared_from_this
());
HttpResponseInvoker
invoker
=
[
weak
S
elf
,
bClose
](
int
code
,
const
KeyValue
&
headerOut
,
const
HttpBody
::
Ptr
&
body
){
auto
strong
Self
=
weakS
elf
.
lock
();
if
(
!
strong
S
elf
)
{
weak_ptr
<
HttpSession
>
weak
_s
elf
=
dynamic_pointer_cast
<
HttpSession
>
(
shared_from_this
());
HttpResponseInvoker
invoker
=
[
weak
_s
elf
,
bClose
](
int
code
,
const
KeyValue
&
headerOut
,
const
HttpBody
::
Ptr
&
body
){
auto
strong
_self
=
weak_s
elf
.
lock
();
if
(
!
strong
_s
elf
)
{
return
;
}
strong
Self
->
async
([
weakS
elf
,
bClose
,
code
,
headerOut
,
body
]()
{
auto
strong
Self
=
weakS
elf
.
lock
();
if
(
!
strong
S
elf
)
{
strong
_self
->
async
([
weak_s
elf
,
bClose
,
code
,
headerOut
,
body
]()
{
auto
strong
_self
=
weak_s
elf
.
lock
();
if
(
!
strong
_s
elf
)
{
//本对象已经销毁
return
;
}
strong
S
elf
->
sendResponse
(
code
,
bClose
,
nullptr
,
headerOut
,
body
);
strong
_s
elf
->
sendResponse
(
code
,
bClose
,
nullptr
,
headerOut
,
body
);
});
};
///////////////////广播HTTP事件///////////////////////////
...
...
src/Rtmp/FlvMuxer.cpp
查看文件 @
feaacf39
...
...
@@ -28,12 +28,12 @@ void FlvMuxer::start(const EventPoller::Ptr &poller, const RtmpMediaSource::Ptr
throw
std
::
runtime_error
(
"RtmpMediaSource 无效"
);
}
if
(
!
poller
->
isCurrentThread
())
{
weak_ptr
<
FlvMuxer
>
weak
S
elf
=
getSharedPtr
();
weak_ptr
<
FlvMuxer
>
weak
_s
elf
=
getSharedPtr
();
//延时两秒启动录制,目的是为了等待config帧收集完毕
poller
->
doDelayTask
(
2000
,
[
weak
S
elf
,
poller
,
media
,
start_pts
]()
{
auto
strong
Self
=
weakS
elf
.
lock
();
if
(
strong
S
elf
)
{
strong
S
elf
->
start
(
poller
,
media
,
start_pts
);
poller
->
doDelayTask
(
2000
,
[
weak
_s
elf
,
poller
,
media
,
start_pts
]()
{
auto
strong
_self
=
weak_s
elf
.
lock
();
if
(
strong
_s
elf
)
{
strong
_s
elf
->
start
(
poller
,
media
,
start_pts
);
}
return
0
;
});
...
...
@@ -42,21 +42,22 @@ void FlvMuxer::start(const EventPoller::Ptr &poller, const RtmpMediaSource::Ptr
onWriteFlvHeader
(
media
);
std
::
weak_ptr
<
FlvMuxer
>
weak
S
elf
=
getSharedPtr
();
std
::
weak_ptr
<
FlvMuxer
>
weak
_s
elf
=
getSharedPtr
();
media
->
pause
(
false
);
_ring_reader
=
media
->
getRing
()
->
attach
(
poller
);
_ring_reader
->
setDetachCB
([
weakSelf
]()
{
auto
strongSelf
=
weakSelf
.
lock
();
if
(
!
strongSelf
)
{
_ring_reader
->
setGetInfoCB
([
weak_self
]()
{
return
weak_self
.
lock
();
});
_ring_reader
->
setDetachCB
([
weak_self
]()
{
auto
strong_self
=
weak_self
.
lock
();
if
(
!
strong_self
)
{
return
;
}
strong
S
elf
->
onDetach
();
strong
_s
elf
->
onDetach
();
});
bool
check
=
start_pts
>
0
;
_ring_reader
->
setReadCB
([
weak
S
elf
,
start_pts
,
check
](
const
RtmpMediaSource
::
RingDataType
&
pkt
)
mutable
{
auto
strong
Self
=
weakS
elf
.
lock
();
if
(
!
strong
S
elf
)
{
_ring_reader
->
setReadCB
([
weak
_s
elf
,
start_pts
,
check
](
const
RtmpMediaSource
::
RingDataType
&
pkt
)
mutable
{
auto
strong
_self
=
weak_s
elf
.
lock
();
if
(
!
strong
_s
elf
)
{
return
;
}
...
...
@@ -69,7 +70,7 @@ void FlvMuxer::start(const EventPoller::Ptr &poller, const RtmpMediaSource::Ptr
}
check
=
false
;
}
strong
S
elf
->
onWriteRtmp
(
rtmp
,
++
i
==
size
);
strong
_s
elf
->
onWriteRtmp
(
rtmp
,
++
i
==
size
);
});
});
}
...
...
src/Rtmp/RtmpMediaSource.h
查看文件 @
feaacf39
...
...
@@ -69,6 +69,11 @@ public:
return
_ring
;
}
void
getPlayerList
(
const
std
::
function
<
void
(
const
std
::
list
<
std
::
shared_ptr
<
void
>>
&
info_list
)
>
&
cb
,
const
std
::
function
<
std
::
shared_ptr
<
void
>
(
std
::
shared_ptr
<
void
>
&&
info
)
>
&
on_change
)
override
{
_ring
->
getInfoList
(
cb
,
on_change
);
}
/**
* 获取播放器个数
* @return
...
...
src/Rtmp/RtmpSession.cpp
查看文件 @
feaacf39
...
...
@@ -199,13 +199,13 @@ void RtmpSession::onCmd_publish(AMFDecoder &dec) {
}
Broadcast
::
PublishAuthInvoker
invoker
=
[
weak_self
,
on_res
,
pToken
](
const
string
&
err
,
const
ProtocolOption
&
option
)
{
auto
strong
S
elf
=
weak_self
.
lock
();
if
(
!
strong
S
elf
)
{
auto
strong
_s
elf
=
weak_self
.
lock
();
if
(
!
strong
_s
elf
)
{
return
;
}
strong
S
elf
->
async
([
weak_self
,
on_res
,
err
,
pToken
,
option
]()
{
auto
strong
S
elf
=
weak_self
.
lock
();
if
(
!
strong
S
elf
)
{
strong
_s
elf
->
async
([
weak_self
,
on_res
,
err
,
pToken
,
option
]()
{
auto
strong
_s
elf
=
weak_self
.
lock
();
if
(
!
strong
_s
elf
)
{
return
;
}
on_res
(
err
,
option
);
...
...
@@ -307,28 +307,29 @@ void RtmpSession::sendPlayResponse(const string &err, const RtmpMediaSource::Ptr
src
->
pause
(
false
);
_ring_reader
=
src
->
getRing
()
->
attach
(
getPoller
());
weak_ptr
<
RtmpSession
>
weakSelf
=
dynamic_pointer_cast
<
RtmpSession
>
(
shared_from_this
());
_ring_reader
->
setReadCB
([
weakSelf
](
const
RtmpMediaSource
::
RingDataType
&
pkt
)
{
auto
strongSelf
=
weakSelf
.
lock
();
if
(
!
strongSelf
)
{
weak_ptr
<
RtmpSession
>
weak_self
=
dynamic_pointer_cast
<
RtmpSession
>
(
shared_from_this
());
_ring_reader
->
setGetInfoCB
([
weak_self
]()
{
return
weak_self
.
lock
();
});
_ring_reader
->
setReadCB
([
weak_self
](
const
RtmpMediaSource
::
RingDataType
&
pkt
)
{
auto
strong_self
=
weak_self
.
lock
();
if
(
!
strong_self
)
{
return
;
}
size_t
i
=
0
;
auto
size
=
pkt
->
size
();
strong
S
elf
->
setSendFlushFlag
(
false
);
strong
_s
elf
->
setSendFlushFlag
(
false
);
pkt
->
for_each
([
&
](
const
RtmpPacket
::
Ptr
&
rtmp
){
if
(
++
i
==
size
){
strong
S
elf
->
setSendFlushFlag
(
true
);
strong
_s
elf
->
setSendFlushFlag
(
true
);
}
strong
S
elf
->
onSendMedia
(
rtmp
);
strong
_s
elf
->
onSendMedia
(
rtmp
);
});
});
_ring_reader
->
setDetachCB
([
weak
S
elf
]()
{
auto
strong
Self
=
weakS
elf
.
lock
();
if
(
!
strong
S
elf
)
{
_ring_reader
->
setDetachCB
([
weak
_s
elf
]()
{
auto
strong
_self
=
weak_s
elf
.
lock
();
if
(
!
strong
_s
elf
)
{
return
;
}
strong
S
elf
->
shutdown
(
SockException
(
Err_shutdown
,
"rtmp ring buffer detached"
));
strong
_s
elf
->
shutdown
(
SockException
(
Err_shutdown
,
"rtmp ring buffer detached"
));
});
src
->
pause
(
false
);
_play_src
=
src
;
...
...
@@ -360,9 +361,9 @@ void RtmpSession::doPlay(AMFDecoder &dec){
std
::
shared_ptr
<
Ticker
>
ticker
(
new
Ticker
);
weak_ptr
<
RtmpSession
>
weak_self
=
dynamic_pointer_cast
<
RtmpSession
>
(
shared_from_this
());
std
::
shared_ptr
<
onceToken
>
token
(
new
onceToken
(
nullptr
,
[
ticker
,
weak_self
](){
auto
strong
S
elf
=
weak_self
.
lock
();
if
(
strong
S
elf
)
{
DebugP
(
strong
S
elf
.
get
())
<<
"play 回复时间:"
<<
ticker
->
elapsedTime
()
<<
"ms"
;
auto
strong
_s
elf
=
weak_self
.
lock
();
if
(
strong
_s
elf
)
{
DebugP
(
strong
_s
elf
.
get
())
<<
"play 回复时间:"
<<
ticker
->
elapsedTime
()
<<
"ms"
;
}
}));
Broadcast
::
AuthInvoker
invoker
=
[
weak_self
,
token
](
const
string
&
err
){
...
...
src/Rtp/RtpSelector.h
查看文件 @
feaacf39
...
...
@@ -36,7 +36,7 @@ protected:
private
:
std
::
string
_stream_id
;
RtpProcess
::
Ptr
_process
;
std
::
weak_ptr
<
RtpSelector
>
_parent
;
std
::
weak_ptr
<
RtpSelector
>
_parent
;
};
class
RtpSelector
:
public
std
::
enable_shared_from_this
<
RtpSelector
>
{
...
...
src/Rtsp/RtspMediaSource.h
查看文件 @
feaacf39
...
...
@@ -65,6 +65,11 @@ public:
return
_ring
;
}
void
getPlayerList
(
const
std
::
function
<
void
(
const
std
::
list
<
std
::
shared_ptr
<
void
>>
&
info_list
)
>
&
cb
,
const
std
::
function
<
std
::
shared_ptr
<
void
>
(
std
::
shared_ptr
<
void
>
&&
info
)
>
&
on_change
)
override
{
_ring
->
getInfoList
(
cb
,
on_change
);
}
/**
* 获取播放器个数
*/
...
...
src/Rtsp/RtspSession.cpp
查看文件 @
feaacf39
差异被折叠。
点击展开。
src/TS/TSMediaSource.h
查看文件 @
feaacf39
...
...
@@ -51,6 +51,11 @@ public:
return
_ring
;
}
void
getPlayerList
(
const
std
::
function
<
void
(
const
std
::
list
<
std
::
shared_ptr
<
void
>>
&
info_list
)
>
&
cb
,
const
std
::
function
<
std
::
shared_ptr
<
void
>
(
std
::
shared_ptr
<
void
>
&&
info
)
>
&
on_change
)
override
{
_ring
->
getInfoList
(
cb
,
on_change
);
}
/**
* 获取播放器个数
*/
...
...
srt/SrtTransportImp.cpp
查看文件 @
feaacf39
...
...
@@ -226,6 +226,8 @@ void SrtTransportImp::doPlay() {
assert
(
ts_src
);
ts_src
->
pause
(
false
);
strong_self
->
_ts_reader
=
ts_src
->
getRing
()
->
attach
(
strong_self
->
getPoller
());
weak_ptr
<
Session
>
weak_session
=
strong_self
->
getSession
();
strong_self
->
_ts_reader
->
setGetInfoCB
([
weak_session
]()
{
return
weak_session
.
lock
();
});
strong_self
->
_ts_reader
->
setDetachCB
([
weak_self
]()
{
auto
strong_self
=
weak_self
.
lock
();
if
(
!
strong_self
)
{
...
...
webrtc/WebRtcPlayer.cpp
查看文件 @
feaacf39
...
...
@@ -39,23 +39,25 @@ void WebRtcPlayer::onStartWebRTC() {
_play_src
->
pause
(
false
);
_reader
=
_play_src
->
getRing
()
->
attach
(
getPoller
(),
true
);
weak_ptr
<
WebRtcPlayer
>
weak_self
=
static_pointer_cast
<
WebRtcPlayer
>
(
shared_from_this
());
weak_ptr
<
Session
>
weak_session
=
getSession
();
_reader
->
setGetInfoCB
([
weak_session
]()
{
return
weak_session
.
lock
();
});
_reader
->
setReadCB
([
weak_self
](
const
RtspMediaSource
::
RingDataType
&
pkt
)
{
auto
strong
S
elf
=
weak_self
.
lock
();
if
(
!
strong
S
elf
)
{
auto
strong
_s
elf
=
weak_self
.
lock
();
if
(
!
strong
_s
elf
)
{
return
;
}
size_t
i
=
0
;
pkt
->
for_each
([
&
](
const
RtpPacket
::
Ptr
&
rtp
)
{
//TraceL<<"send track type:"<<rtp->type<<" ts:"<<rtp->getStamp()<<" ntp:"<<rtp->ntp_stamp<<" size:"<<rtp->getPayloadSize()<<" i:"<<i;
strong
S
elf
->
onSendRtp
(
rtp
,
++
i
==
pkt
->
size
());
strong
_s
elf
->
onSendRtp
(
rtp
,
++
i
==
pkt
->
size
());
});
});
_reader
->
setDetachCB
([
weak_self
]()
{
auto
strong
S
elf
=
weak_self
.
lock
();
if
(
!
strong
S
elf
)
{
auto
strong
_s
elf
=
weak_self
.
lock
();
if
(
!
strong
_s
elf
)
{
return
;
}
strong
S
elf
->
onShutdown
(
SockException
(
Err_shutdown
,
"rtsp ring buffer detached"
));
strong
_s
elf
->
onShutdown
(
SockException
(
Err_shutdown
,
"rtsp ring buffer detached"
));
});
}
//使用完毕后,释放强引用,这样确保推流器断开后能及时注销媒体
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论