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
67d5ca02
Commit
67d5ca02
authored
Mar 24, 2023
by
xiongguangjie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rtsp push replace pre pusher
parent
ca7efd59
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
69 行增加
和
36 行删除
+69
-36
src/Rtsp/RtspSession.cpp
+67
-36
src/Rtsp/RtspSession.h
+2
-0
没有找到文件。
src/Rtsp/RtspSession.cpp
查看文件 @
67d5ca02
...
...
@@ -17,6 +17,7 @@
#include "Util/base64.h"
#include "RtpMultiCaster.h"
#include "Rtcp/RtcpContext.h"
#include "Network/Server.h"
using
namespace
std
;
using
namespace
toolkit
;
...
...
@@ -218,41 +219,7 @@ void RtspSession::handleReq_ANNOUNCE(const Parser &parser) {
throw
SockException
(
Err_shutdown
,
StrPrinter
<<
err
<<
":"
<<
full_url
);
}
auto
onRes
=
[
this
,
parser
,
full_url
](
const
string
&
err
,
const
ProtocolOption
&
option
)
{
if
(
!
err
.
empty
())
{
sendRtspResponse
(
"401 Unauthorized"
,
{
"Content-Type"
,
"text/plain"
},
err
);
shutdown
(
SockException
(
Err_shutdown
,
StrPrinter
<<
"401 Unauthorized:"
<<
err
));
return
;
}
assert
(
!
_push_src
);
auto
src
=
MediaSource
::
find
(
RTSP_SCHEMA
,
_media_info
.
_vhost
,
_media_info
.
_app
,
_media_info
.
_streamid
);
auto
push_failed
=
(
bool
)
src
;
while
(
src
)
{
//尝试断连后继续推流
auto
rtsp_src
=
dynamic_pointer_cast
<
RtspMediaSourceImp
>
(
src
);
if
(
!
rtsp_src
)
{
//源不是rtsp推流产生的
break
;
}
auto
ownership
=
rtsp_src
->
getOwnership
();
if
(
!
ownership
)
{
//获取推流源所有权失败
break
;
}
_push_src
=
std
::
move
(
rtsp_src
);
_push_src_ownership
=
std
::
move
(
ownership
);
push_failed
=
false
;
break
;
}
if
(
push_failed
)
{
sendRtspResponse
(
"406 Not Acceptable"
,
{
"Content-Type"
,
"text/plain"
},
"Already publishing."
);
string
err
=
StrPrinter
<<
"ANNOUNCE: Already publishing:"
<<
_media_info
.
shortUrl
()
<<
endl
;
throw
SockException
(
Err_shutdown
,
err
);
}
auto
onResPushSrc
=
[
this
,
parser
,
full_url
](
ProtocolOption
option
)
{
SdpParser
sdpParser
(
parser
.
Content
());
_sessionid
=
makeRandStr
(
12
);
_sdp_track
=
sdpParser
.
getAvailableTrack
();
...
...
@@ -270,7 +237,7 @@ void RtspSession::handleReq_ANNOUNCE(const Parser &parser) {
if
(
!
_push_src
)
{
_push_src
=
std
::
make_shared
<
RtspMediaSourceImp
>
(
_media_info
.
_vhost
,
_media_info
.
_app
,
_media_info
.
_streamid
);
//获取所有权
//
获取所有权
_push_src_ownership
=
_push_src
->
getOwnership
();
_push_src
->
setProtocolOption
(
option
);
_push_src
->
setSdp
(
parser
.
Content
());
...
...
@@ -281,6 +248,66 @@ void RtspSession::handleReq_ANNOUNCE(const Parser &parser) {
sendRtspResponse
(
"200 OK"
);
};
auto
onRes
=
[
this
,
parser
,
full_url
,
onResPushSrc
](
const
string
&
err
,
const
ProtocolOption
&
option
)
{
if
(
!
err
.
empty
())
{
sendRtspResponse
(
"401 Unauthorized"
,
{
"Content-Type"
,
"text/plain"
},
err
);
shutdown
(
SockException
(
Err_shutdown
,
StrPrinter
<<
"401 Unauthorized:"
<<
err
));
return
;
}
assert
(
!
_push_src
);
auto
src
=
MediaSource
::
find
(
RTSP_SCHEMA
,
_media_info
.
_vhost
,
_media_info
.
_app
,
_media_info
.
_streamid
);
auto
push_failed
=
(
bool
)
src
;
RtspMediaSource
::
Ptr
rtsp_src
;
RtspMediaSourceImp
::
Ptr
rtsp_src_imp
;
while
(
src
)
{
//尝试断连后继续推流
rtsp_src_imp
=
dynamic_pointer_cast
<
RtspMediaSourceImp
>
(
src
);
rtsp_src
=
dynamic_pointer_cast
<
RtspMediaSource
>
(
src
);
if
(
!
rtsp_src_imp
)
{
//源不是rtsp推流产生的
break
;
}
auto
ownership
=
rtsp_src_imp
->
getOwnership
();
if
(
!
ownership
)
{
//获取推流源所有权失败
break
;
}
_push_src
=
std
::
move
(
rtsp_src_imp
);
_push_src_ownership
=
std
::
move
(
ownership
);
push_failed
=
false
;
break
;
}
if
(
push_failed
&&
rtsp_src
)
{
auto
sock
=
rtsp_src
->
getOriginSock
();
if
(
sock
){
auto
session
=
SessionMap
::
Instance
().
get
(
sock
->
getIdentifier
());
auto
rtsp_session
=
dynamic_pointer_cast
<
RtspSession
>
(
session
);
if
(
session
&&
rtsp_session
){
rtsp_src_imp
=
rtsp_session
->
getPushSrc
();
session
->
getPoller
()
->
async_first
([
this
,
rtsp_src
,
option
,
rtsp_src_imp
,
onResPushSrc
,
session
](){
session
->
shutdown
(
SockException
(
Err_shutdown
,
"other pusher kick session"
));
_push_src_ownership
=
rtsp_src_imp
->
getOwnership
();
_push_src
=
std
::
move
(
rtsp_src_imp
);
this
->
getPoller
()
->
async_first
([
option
,
onResPushSrc
](){
onResPushSrc
(
option
);
});
});
return
;
}
}
sendRtspResponse
(
"406 Not Acceptable"
,
{
"Content-Type"
,
"text/plain"
},
"not reach this"
);
string
err
=
StrPrinter
<<
"ANNOUNCE: not reach this:"
<<
_media_info
.
shortUrl
()
<<
endl
;
throw
SockException
(
Err_shutdown
,
err
);
}
onResPushSrc
(
option
);
};
weak_ptr
<
RtspSession
>
weak_self
=
dynamic_pointer_cast
<
RtspSession
>
(
shared_from_this
());
Broadcast
::
PublishAuthInvoker
invoker
=
[
weak_self
,
onRes
](
const
string
&
err
,
const
ProtocolOption
&
option
)
{
auto
strong_self
=
weak_self
.
lock
();
...
...
@@ -1249,5 +1276,9 @@ void RtspSession::setSocketFlags(){
}
}
RtspMediaSourceImp
::
Ptr
RtspSession
::
getPushSrc
(){
return
_push_src
;
}
}
/* namespace mediakit */
src/Rtsp/RtspSession.h
查看文件 @
67d5ca02
...
...
@@ -40,6 +40,8 @@ public:
void
onError
(
const
toolkit
::
SockException
&
err
)
override
;
void
onManager
()
override
;
RtspMediaSourceImp
::
Ptr
getPushSrc
();
protected
:
/////RtspSplitter override/////
//收到完整的rtsp包回调,包括sdp等content数据
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论