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
0d6509ce
Commit
0d6509ce
authored
Aug 30, 2022
by
custompal
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
统一部分变量名和代码样式风格
parent
04aa3ef4
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
156 行增加
和
164 行删除
+156
-164
src/Http/HttpSession.cpp
+20
-24
src/Rtmp/FlvMuxer.cpp
+15
-17
src/Rtmp/RtmpSession.cpp
+20
-20
src/Rtp/RtpSelector.h
+1
-1
src/Rtsp/RtspSession.cpp
+92
-94
srt/SrtTransportImp.cpp
+2
-2
webrtc/WebRtcPlayer.cpp
+6
-6
没有找到文件。
src/Http/HttpSession.cpp
查看文件 @
0d6509ce
...
...
@@ -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
)
{
...
...
@@ -285,9 +286,6 @@ bool HttpSession::checkLiveStreamFMP4(const function<void()> &cb){
}
strong_self
->
shutdown
(
SockException
(
Err_shutdown
,
"fmp4 ring buffer detached"
));
});
_fmp4_reader
->
setGetInfoCB
([
weak_self
]()
{
return
weak_self
.
lock
();
});
_fmp4_reader
->
setReadCB
([
weak_self
](
const
FMP4MediaSource
::
RingDataType
&
fmp4_list
)
{
auto
strong_self
=
weak_self
.
lock
();
if
(
!
strong_self
)
{
...
...
@@ -321,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
)
{
...
...
@@ -329,9 +328,6 @@ bool HttpSession::checkLiveStreamTS(const function<void()> &cb){
}
strong_self
->
shutdown
(
SockException
(
Err_shutdown
,
"ts ring buffer detached"
));
});
_ts_reader
->
setGetInfoCB
([
weak_self
]()
{
return
weak_self
.
lock
();
});
_ts_reader
->
setReadCB
([
weak_self
](
const
TSMediaSource
::
RingDataType
&
ts_list
)
{
auto
strong_self
=
weak_self
.
lock
();
if
(
!
strong_self
)
{
...
...
@@ -418,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
);
});
});
}
...
...
@@ -651,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
查看文件 @
0d6509ce
...
...
@@ -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,24 +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
->
setGetInfoCB
([
weakSelf
]()
{
return
weakSelf
.
lock
();
});
_ring_reader
->
setReadCB
([
weakSelf
,
start_pts
,
check
](
const
RtmpMediaSource
::
RingDataType
&
pkt
)
mutable
{
auto
strongSelf
=
weakSelf
.
lock
();
if
(
!
strongSelf
)
{
_ring_reader
->
setReadCB
([
weak_self
,
start_pts
,
check
](
const
RtmpMediaSource
::
RingDataType
&
pkt
)
mutable
{
auto
strong_self
=
weak_self
.
lock
();
if
(
!
strong_self
)
{
return
;
}
...
...
@@ -72,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/RtmpSession.cpp
查看文件 @
0d6509ce
...
...
@@ -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,29 +307,29 @@ void RtmpSession::sendPlayResponse(const string &err, const RtmpMediaSource::Ptr
src
->
pause
(
false
);
_ring_reader
=
src
->
getRing
()
->
attach
(
getPoller
());
weak_ptr
<
RtmpSession
>
weak
S
elf
=
dynamic_pointer_cast
<
RtmpSession
>
(
shared_from_this
());
_ring_reader
->
setGetInfoCB
([
weak
Self
]()
{
return
weakS
elf
.
lock
();
});
_ring_reader
->
setReadCB
([
weak
S
elf
](
const
RtmpMediaSource
::
RingDataType
&
pkt
)
{
auto
strong
Self
=
weakS
elf
.
lock
();
if
(
!
strong
S
elf
)
{
weak_ptr
<
RtmpSession
>
weak
_s
elf
=
dynamic_pointer_cast
<
RtmpSession
>
(
shared_from_this
());
_ring_reader
->
setGetInfoCB
([
weak
_self
]()
{
return
weak_s
elf
.
lock
();
});
_ring_reader
->
setReadCB
([
weak
_s
elf
](
const
RtmpMediaSource
::
RingDataType
&
pkt
)
{
auto
strong
_self
=
weak_s
elf
.
lock
();
if
(
!
strong
_s
elf
)
{
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
;
...
...
@@ -361,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
查看文件 @
0d6509ce
...
...
@@ -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/RtspSession.cpp
查看文件 @
0d6509ce
...
...
@@ -283,15 +283,15 @@ void RtspSession::handleReq_ANNOUNCE(const Parser &parser) {
sendRtspResponse
(
"200 OK"
);
};
weak_ptr
<
RtspSession
>
weak
S
elf
=
dynamic_pointer_cast
<
RtspSession
>
(
shared_from_this
());
Broadcast
::
PublishAuthInvoker
invoker
=
[
weak
S
elf
,
onRes
](
const
string
&
err
,
const
ProtocolOption
&
option
)
{
auto
strong
Self
=
weakS
elf
.
lock
();
if
(
!
strong
S
elf
)
{
weak_ptr
<
RtspSession
>
weak
_s
elf
=
dynamic_pointer_cast
<
RtspSession
>
(
shared_from_this
());
Broadcast
::
PublishAuthInvoker
invoker
=
[
weak
_s
elf
,
onRes
](
const
string
&
err
,
const
ProtocolOption
&
option
)
{
auto
strong
_self
=
weak_s
elf
.
lock
();
if
(
!
strong
_s
elf
)
{
return
;
}
strong
Self
->
async
([
weakS
elf
,
onRes
,
err
,
option
]()
{
auto
strong
Self
=
weakS
elf
.
lock
();
if
(
!
strong
S
elf
)
{
strong
_self
->
async
([
weak_s
elf
,
onRes
,
err
,
option
]()
{
auto
strong
_self
=
weak_s
elf
.
lock
();
if
(
!
strong
_s
elf
)
{
return
;
}
onRes
(
err
,
option
);
...
...
@@ -330,28 +330,28 @@ void RtspSession::handleReq_RECORD(const Parser &parser){
}
void
RtspSession
::
emitOnPlay
(){
weak_ptr
<
RtspSession
>
weak
S
elf
=
dynamic_pointer_cast
<
RtspSession
>
(
shared_from_this
());
weak_ptr
<
RtspSession
>
weak
_s
elf
=
dynamic_pointer_cast
<
RtspSession
>
(
shared_from_this
());
//url鉴权回调
auto
onRes
=
[
weak
S
elf
](
const
string
&
err
)
{
auto
strong
Self
=
weakS
elf
.
lock
();
if
(
!
strong
S
elf
)
{
auto
onRes
=
[
weak
_s
elf
](
const
string
&
err
)
{
auto
strong
_self
=
weak_s
elf
.
lock
();
if
(
!
strong
_s
elf
)
{
return
;
}
if
(
!
err
.
empty
())
{
//播放url鉴权失败
strong
S
elf
->
sendRtspResponse
(
"401 Unauthorized"
,
{
"Content-Type"
,
"text/plain"
},
err
);
strong
S
elf
->
shutdown
(
SockException
(
Err_shutdown
,
StrPrinter
<<
"401 Unauthorized:"
<<
err
));
strong
_s
elf
->
sendRtspResponse
(
"401 Unauthorized"
,
{
"Content-Type"
,
"text/plain"
},
err
);
strong
_s
elf
->
shutdown
(
SockException
(
Err_shutdown
,
StrPrinter
<<
"401 Unauthorized:"
<<
err
));
return
;
}
strong
S
elf
->
onAuthSuccess
();
strong
_s
elf
->
onAuthSuccess
();
};
Broadcast
::
AuthInvoker
invoker
=
[
weak
S
elf
,
onRes
](
const
string
&
err
)
{
auto
strong
Self
=
weakS
elf
.
lock
();
if
(
!
strong
S
elf
)
{
Broadcast
::
AuthInvoker
invoker
=
[
weak
_s
elf
,
onRes
](
const
string
&
err
)
{
auto
strong
_self
=
weak_s
elf
.
lock
();
if
(
!
strong
_s
elf
)
{
return
;
}
strong
Self
->
async
([
onRes
,
err
,
weakS
elf
]()
{
strong
_self
->
async
([
onRes
,
err
,
weak_s
elf
]()
{
onRes
(
err
);
});
};
...
...
@@ -369,29 +369,29 @@ void RtspSession::emitOnPlay(){
void
RtspSession
::
handleReq_Describe
(
const
Parser
&
parser
)
{
//该请求中的认证信息
auto
authorization
=
parser
[
"Authorization"
];
weak_ptr
<
RtspSession
>
weak
S
elf
=
dynamic_pointer_cast
<
RtspSession
>
(
shared_from_this
());
weak_ptr
<
RtspSession
>
weak
_s
elf
=
dynamic_pointer_cast
<
RtspSession
>
(
shared_from_this
());
//rtsp专属鉴权是否开启事件回调
onGetRealm
invoker
=
[
weak
S
elf
,
authorization
](
const
string
&
realm
)
{
auto
strong
Self
=
weakS
elf
.
lock
();
if
(
!
strong
S
elf
)
{
onGetRealm
invoker
=
[
weak
_s
elf
,
authorization
](
const
string
&
realm
)
{
auto
strong
_self
=
weak_s
elf
.
lock
();
if
(
!
strong
_s
elf
)
{
//本对象已经销毁
return
;
}
//切换到自己的线程然后执行
strong
Self
->
async
([
weakS
elf
,
realm
,
authorization
]()
{
auto
strong
Self
=
weakS
elf
.
lock
();
if
(
!
strong
S
elf
)
{
strong
_self
->
async
([
weak_s
elf
,
realm
,
authorization
]()
{
auto
strong
_self
=
weak_s
elf
.
lock
();
if
(
!
strong
_s
elf
)
{
//本对象已经销毁
return
;
}
if
(
realm
.
empty
())
{
//无需rtsp专属认证, 那么继续url通用鉴权认证(on_play)
strong
S
elf
->
emitOnPlay
();
strong
_s
elf
->
emitOnPlay
();
return
;
}
//该流需要rtsp专属认证,开启rtsp专属认证后,将不再触发url通用鉴权认证(on_play)
strong
S
elf
->
_rtsp_realm
=
realm
;
strong
S
elf
->
onAuthUser
(
realm
,
authorization
);
strong
_s
elf
->
_rtsp_realm
=
realm
;
strong
_s
elf
->
onAuthUser
(
realm
,
authorization
);
});
};
...
...
@@ -408,43 +408,43 @@ void RtspSession::handleReq_Describe(const Parser &parser) {
void
RtspSession
::
onAuthSuccess
()
{
TraceP
(
this
);
weak_ptr
<
RtspSession
>
weak
S
elf
=
dynamic_pointer_cast
<
RtspSession
>
(
shared_from_this
());
MediaSource
::
findAsync
(
_media_info
,
weak
Self
.
lock
(),
[
weakS
elf
](
const
MediaSource
::
Ptr
&
src
){
auto
strong
Self
=
weakS
elf
.
lock
();
if
(
!
strong
S
elf
){
weak_ptr
<
RtspSession
>
weak
_s
elf
=
dynamic_pointer_cast
<
RtspSession
>
(
shared_from_this
());
MediaSource
::
findAsync
(
_media_info
,
weak
_self
.
lock
(),
[
weak_s
elf
](
const
MediaSource
::
Ptr
&
src
){
auto
strong
_self
=
weak_s
elf
.
lock
();
if
(
!
strong
_s
elf
){
return
;
}
auto
rtsp_src
=
dynamic_pointer_cast
<
RtspMediaSource
>
(
src
);
if
(
!
rtsp_src
)
{
//未找到相应的MediaSource
string
err
=
StrPrinter
<<
"no such stream:"
<<
strong
Self
->
_media_info
.
_vhost
<<
" "
<<
strongSelf
->
_media_info
.
_app
<<
" "
<<
strongS
elf
->
_media_info
.
_streamid
;
strong
S
elf
->
send_StreamNotFound
();
strong
S
elf
->
shutdown
(
SockException
(
Err_shutdown
,
err
));
string
err
=
StrPrinter
<<
"no such stream:"
<<
strong
_self
->
_media_info
.
_vhost
<<
" "
<<
strong_self
->
_media_info
.
_app
<<
" "
<<
strong_s
elf
->
_media_info
.
_streamid
;
strong
_s
elf
->
send_StreamNotFound
();
strong
_s
elf
->
shutdown
(
SockException
(
Err_shutdown
,
err
));
return
;
}
//找到了相应的rtsp流
strong
S
elf
->
_sdp_track
=
SdpParser
(
rtsp_src
->
getSdp
()).
getAvailableTrack
();
if
(
strong
S
elf
->
_sdp_track
.
empty
())
{
strong
_s
elf
->
_sdp_track
=
SdpParser
(
rtsp_src
->
getSdp
()).
getAvailableTrack
();
if
(
strong
_s
elf
->
_sdp_track
.
empty
())
{
//该流无效
WarnL
<<
"sdp中无有效track,该流无效:"
<<
rtsp_src
->
getSdp
();
strong
S
elf
->
send_StreamNotFound
();
strong
S
elf
->
shutdown
(
SockException
(
Err_shutdown
,
"can not find any available track in sdp"
));
strong
_s
elf
->
send_StreamNotFound
();
strong
_s
elf
->
shutdown
(
SockException
(
Err_shutdown
,
"can not find any available track in sdp"
));
return
;
}
strong
S
elf
->
_rtcp_context
.
clear
();
for
(
auto
&
track
:
strong
S
elf
->
_sdp_track
)
{
strong
S
elf
->
_rtcp_context
.
emplace_back
(
std
::
make_shared
<
RtcpContextForSend
>
());
strong
_s
elf
->
_rtcp_context
.
clear
();
for
(
auto
&
track
:
strong
_s
elf
->
_sdp_track
)
{
strong
_s
elf
->
_rtcp_context
.
emplace_back
(
std
::
make_shared
<
RtcpContextForSend
>
());
}
strong
S
elf
->
_sessionid
=
makeRandStr
(
12
);
strong
S
elf
->
_play_src
=
rtsp_src
;
for
(
auto
&
track
:
strong
S
elf
->
_sdp_track
){
strong
_s
elf
->
_sessionid
=
makeRandStr
(
12
);
strong
_s
elf
->
_play_src
=
rtsp_src
;
for
(
auto
&
track
:
strong
_s
elf
->
_sdp_track
){
track
->
_ssrc
=
rtsp_src
->
getSsrc
(
track
->
_type
);
track
->
_seq
=
rtsp_src
->
getSeqence
(
track
->
_type
);
track
->
_time_stamp
=
rtsp_src
->
getTimeStamp
(
track
->
_type
);
}
strong
S
elf
->
sendRtspResponse
(
"200 OK"
,
{
"Content-Base"
,
strong
S
elf
->
_content_base
+
"/"
,
strong
_s
elf
->
sendRtspResponse
(
"200 OK"
,
{
"Content-Base"
,
strong
_s
elf
->
_content_base
+
"/"
,
"x-Accept-Retransmit"
,
"our-retransmit"
,
"x-Accept-Dynamic-Rate"
,
"1"
},
rtsp_src
->
getSdp
());
...
...
@@ -482,28 +482,28 @@ void RtspSession::onAuthBasic(const string &realm,const string &auth_base64){
}
auto
user
=
user_pwd_vec
[
0
];
auto
pwd
=
user_pwd_vec
[
1
];
weak_ptr
<
RtspSession
>
weak
S
elf
=
dynamic_pointer_cast
<
RtspSession
>
(
shared_from_this
());
onAuth
invoker
=
[
pwd
,
realm
,
weak
S
elf
](
bool
encrypted
,
const
string
&
good_pwd
)
{
auto
strong
Self
=
weakS
elf
.
lock
();
if
(
!
strong
S
elf
)
{
weak_ptr
<
RtspSession
>
weak
_s
elf
=
dynamic_pointer_cast
<
RtspSession
>
(
shared_from_this
());
onAuth
invoker
=
[
pwd
,
realm
,
weak
_s
elf
](
bool
encrypted
,
const
string
&
good_pwd
)
{
auto
strong
_self
=
weak_s
elf
.
lock
();
if
(
!
strong
_s
elf
)
{
//本对象已经销毁
return
;
}
//切换到自己的线程执行
strong
Self
->
async
([
weakS
elf
,
good_pwd
,
pwd
,
realm
]()
{
auto
strong
Self
=
weakS
elf
.
lock
();
if
(
!
strong
S
elf
)
{
strong
_self
->
async
([
weak_s
elf
,
good_pwd
,
pwd
,
realm
]()
{
auto
strong
_self
=
weak_s
elf
.
lock
();
if
(
!
strong
_s
elf
)
{
//本对象已经销毁
return
;
}
//base64忽略encrypted参数,上层必须传入明文密码
if
(
pwd
==
good_pwd
)
{
//提供的密码且匹配正确
strong
S
elf
->
onAuthSuccess
();
strong
_s
elf
->
onAuthSuccess
();
return
;
}
//密码错误
strong
S
elf
->
onAuthFailed
(
realm
,
StrPrinter
<<
"password mismatch when base64 auth:"
<<
pwd
<<
" != "
<<
good_pwd
);
strong
_s
elf
->
onAuthFailed
(
realm
,
StrPrinter
<<
"password mismatch when base64 auth:"
<<
pwd
<<
" != "
<<
good_pwd
);
});
};
...
...
@@ -575,16 +575,16 @@ void RtspSession::onAuthDigest(const string &realm,const string &auth_md5){
}
};
weak_ptr
<
RtspSession
>
weak
S
elf
=
dynamic_pointer_cast
<
RtspSession
>
(
shared_from_this
());
onAuth
invoker
=
[
realInvoker
,
weak
S
elf
](
bool
encrypted
,
const
string
&
good_pwd
){
auto
strong
Self
=
weakS
elf
.
lock
();
if
(
!
strong
S
elf
){
weak_ptr
<
RtspSession
>
weak
_s
elf
=
dynamic_pointer_cast
<
RtspSession
>
(
shared_from_this
());
onAuth
invoker
=
[
realInvoker
,
weak
_s
elf
](
bool
encrypted
,
const
string
&
good_pwd
){
auto
strong
_self
=
weak_s
elf
.
lock
();
if
(
!
strong
_s
elf
){
return
;
}
//切换到自己的线程确保realInvoker执行时,this指针有效
strong
Self
->
async
([
realInvoker
,
weakS
elf
,
encrypted
,
good_pwd
](){
auto
strong
Self
=
weakS
elf
.
lock
();
if
(
!
strong
S
elf
){
strong
_self
->
async
([
realInvoker
,
weak_s
elf
,
encrypted
,
good_pwd
](){
auto
strong
_self
=
weak_s
elf
.
lock
();
if
(
!
strong
_s
elf
){
return
;
}
realInvoker
(
false
,
encrypted
,
good_pwd
);
...
...
@@ -733,13 +733,13 @@ void RtspSession::handleReq_Setup(const Parser &parser) {
send_NotAcceptable
();
throw
SockException
(
Err_shutdown
,
"can not get a available udp multicast socket"
);
}
weak_ptr
<
RtspSession
>
weak
S
elf
=
dynamic_pointer_cast
<
RtspSession
>
(
shared_from_this
());
_multicaster
->
setDetachCB
(
this
,
[
weak
S
elf
]()
{
auto
strong
Self
=
weakS
elf
.
lock
();
if
(
!
strong
S
elf
)
{
weak_ptr
<
RtspSession
>
weak
_s
elf
=
dynamic_pointer_cast
<
RtspSession
>
(
shared_from_this
());
_multicaster
->
setDetachCB
(
this
,
[
weak
_s
elf
]()
{
auto
strong
_self
=
weak_s
elf
.
lock
();
if
(
!
strong
_s
elf
)
{
return
;
}
strong
S
elf
->
safeShutdown
(
SockException
(
Err_shutdown
,
"ring buffer detached"
));
strong
_s
elf
->
safeShutdown
(
SockException
(
Err_shutdown
,
"ring buffer detached"
));
});
}
int
iSrvPort
=
_multicaster
->
getMultiCasterPort
(
trackRef
->
_type
);
...
...
@@ -781,7 +781,7 @@ void RtspSession::handleReq_Play(const Parser &parser) {
return
;
}
bool
use
GOP
=
true
;
bool
use
_gop
=
true
;
auto
&
strScale
=
parser
[
"Scale"
];
auto
&
strRange
=
parser
[
"Range"
];
StrCaseMap
res_header
;
...
...
@@ -801,7 +801,7 @@ void RtspSession::handleReq_Play(const Parser &parser) {
strStart
=
"0"
;
}
auto
iStartTime
=
1000
*
(
float
)
atof
(
strStart
.
data
());
use
GOP
=
!
play_src
->
seekTo
((
uint32_t
)
iStartTime
);
use
_gop
=
!
play_src
->
seekTo
((
uint32_t
)
iStartTime
);
InfoP
(
this
)
<<
"rtsp seekTo(ms):"
<<
iStartTime
;
}
...
...
@@ -834,24 +834,22 @@ void RtspSession::handleReq_Play(const Parser &parser) {
setSocketFlags
();
if
(
!
_play_reader
&&
_rtp_type
!=
Rtsp
::
RTP_MULTICAST
)
{
weak_ptr
<
RtspSession
>
weakSelf
=
dynamic_pointer_cast
<
RtspSession
>
(
shared_from_this
());
_play_reader
=
play_src
->
getRing
()
->
attach
(
getPoller
(),
useGOP
);
_play_reader
->
setGetInfoCB
([
weakSelf
]()
{
return
weakSelf
.
lock
();
});
_play_reader
->
setDetachCB
([
weakSelf
]()
{
auto
strongSelf
=
weakSelf
.
lock
();
if
(
!
strongSelf
)
{
weak_ptr
<
RtspSession
>
weak_self
=
dynamic_pointer_cast
<
RtspSession
>
(
shared_from_this
());
_play_reader
=
play_src
->
getRing
()
->
attach
(
getPoller
(),
use_gop
);
_play_reader
->
setGetInfoCB
([
weak_self
]()
{
return
weak_self
.
lock
();
});
_play_reader
->
setDetachCB
([
weak_self
]()
{
auto
strong_self
=
weak_self
.
lock
();
if
(
!
strong_self
)
{
return
;
}
strong
S
elf
->
shutdown
(
SockException
(
Err_shutdown
,
"rtsp ring buffer detached"
));
strong
_s
elf
->
shutdown
(
SockException
(
Err_shutdown
,
"rtsp ring buffer detached"
));
});
_play_reader
->
setReadCB
([
weak
S
elf
](
const
RtspMediaSource
::
RingDataType
&
pack
)
{
auto
strong
Self
=
weakS
elf
.
lock
();
if
(
!
strong
S
elf
)
{
_play_reader
->
setReadCB
([
weak
_s
elf
](
const
RtspMediaSource
::
RingDataType
&
pack
)
{
auto
strong
_self
=
weak_s
elf
.
lock
();
if
(
!
strong
_s
elf
)
{
return
;
}
strong
S
elf
->
sendRtpPacket
(
pack
);
strong
_s
elf
->
sendRtpPacket
(
pack
);
});
}
}
...
...
@@ -975,32 +973,32 @@ void RtspSession::onRcvPeerUdpData(int interleaved, const Buffer::Ptr &buf, cons
}
void
RtspSession
::
startListenPeerUdpData
(
int
track_idx
)
{
weak_ptr
<
RtspSession
>
weak
S
elf
=
dynamic_pointer_cast
<
RtspSession
>
(
shared_from_this
());
weak_ptr
<
RtspSession
>
weak
_s
elf
=
dynamic_pointer_cast
<
RtspSession
>
(
shared_from_this
());
auto
peer_ip
=
get_peer_ip
();
auto
onUdpData
=
[
weak
S
elf
,
peer_ip
](
const
Buffer
::
Ptr
&
buf
,
struct
sockaddr
*
peer_addr
,
int
interleaved
){
auto
strong
Self
=
weakS
elf
.
lock
();
if
(
!
strong
S
elf
)
{
auto
onUdpData
=
[
weak
_s
elf
,
peer_ip
](
const
Buffer
::
Ptr
&
buf
,
struct
sockaddr
*
peer_addr
,
int
interleaved
){
auto
strong
_self
=
weak_s
elf
.
lock
();
if
(
!
strong
_s
elf
)
{
return
false
;
}
if
(
SockUtil
::
inet_ntoa
(
peer_addr
)
!=
peer_ip
)
{
WarnP
(
strong
S
elf
.
get
())
<<
((
interleaved
%
2
==
0
)
?
"收到其他地址的rtp数据:"
:
"收到其他地址的rtcp数据:"
)
WarnP
(
strong
_s
elf
.
get
())
<<
((
interleaved
%
2
==
0
)
?
"收到其他地址的rtp数据:"
:
"收到其他地址的rtcp数据:"
)
<<
SockUtil
::
inet_ntoa
(
peer_addr
);
return
true
;
}
struct
sockaddr_storage
addr
=
*
((
struct
sockaddr_storage
*
)
peer_addr
);
strong
Self
->
async
([
weakS
elf
,
buf
,
addr
,
interleaved
]()
{
auto
strong
Self
=
weakS
elf
.
lock
();
if
(
!
strong
S
elf
)
{
strong
_self
->
async
([
weak_s
elf
,
buf
,
addr
,
interleaved
]()
{
auto
strong
_self
=
weak_s
elf
.
lock
();
if
(
!
strong
_s
elf
)
{
return
;
}
try
{
strong
S
elf
->
onRcvPeerUdpData
(
interleaved
,
buf
,
addr
);
strong
_s
elf
->
onRcvPeerUdpData
(
interleaved
,
buf
,
addr
);
}
catch
(
SockException
&
ex
)
{
strong
S
elf
->
shutdown
(
ex
);
strong
_s
elf
->
shutdown
(
ex
);
}
catch
(
std
::
exception
&
ex
)
{
strong
S
elf
->
shutdown
(
SockException
(
Err_other
,
ex
.
what
()));
strong
_s
elf
->
shutdown
(
SockException
(
Err_other
,
ex
.
what
()));
}
});
return
true
;
...
...
srt/SrtTransportImp.cpp
查看文件 @
0d6509ce
...
...
@@ -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
)
{
...
...
@@ -234,8 +236,6 @@ void SrtTransportImp::doPlay() {
}
strong_self
->
onShutdown
(
SockException
(
Err_shutdown
));
});
weak_ptr
<
Session
>
weak_session
=
strong_self
->
getSession
();
strong_self
->
_ts_reader
->
setGetInfoCB
([
weak_session
]()
{
return
weak_session
.
lock
();
});
strong_self
->
_ts_reader
->
setReadCB
([
weak_self
](
const
TSMediaSource
::
RingDataType
&
ts_list
)
{
auto
strong_self
=
weak_self
.
lock
();
if
(
!
strong_self
)
{
...
...
webrtc/WebRtcPlayer.cpp
查看文件 @
0d6509ce
...
...
@@ -42,22 +42,22 @@ void WebRtcPlayer::onStartWebRTC() {
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
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论