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
dc26bbf1
Commit
dc26bbf1
authored
Dec 30, 2022
by
Alexandr
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
protected virtual bool sendRtspResponse(...)
parent
eed5f023
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
27 行增加
和
19 行删除
+27
-19
src/Rtsp/RtpMultiCaster.cpp
+8
-8
src/Rtsp/RtpMultiCaster.h
+2
-2
src/Rtsp/RtspSession.cpp
+1
-1
src/Rtsp/RtspSession.h
+16
-8
没有找到文件。
src/Rtsp/RtpMultiCaster.cpp
查看文件 @
dc26bbf1
...
...
@@ -99,13 +99,13 @@ RtpMultiCaster::~RtpMultiCaster() {
DebugL
;
}
RtpMultiCaster
::
RtpMultiCaster
(
SocketHelper
&
helper
,
const
string
&
local_ip
,
const
string
&
vhost
,
const
string
&
app
,
const
string
&
stream
)
{
RtpMultiCaster
::
RtpMultiCaster
(
SocketHelper
&
helper
,
const
string
&
local_ip
,
const
string
&
vhost
,
const
string
&
app
,
const
string
&
stream
,
uint32_t
multicast_ip
,
uint16_t
video_port
,
uint16_t
audio_port
)
{
auto
src
=
dynamic_pointer_cast
<
RtspMediaSource
>
(
MediaSource
::
find
(
RTSP_SCHEMA
,
vhost
,
app
,
stream
));
if
(
!
src
)
{
auto
err
=
StrPrinter
<<
"未找到媒体源:"
<<
vhost
<<
" "
<<
app
<<
" "
<<
stream
<<
endl
;
throw
std
::
runtime_error
(
err
);
}
_multicast_ip
=
MultiCastAddressMaker
::
Instance
().
obtain
();
_multicast_ip
=
(
multicast_ip
)
?
make_shared
<
uint32_t
>
(
multicast_ip
)
:
MultiCastAddressMaker
::
Instance
().
obtain
();
if
(
!
_multicast_ip
)
{
throw
std
::
runtime_error
(
"获取组播地址失败"
);
}
...
...
@@ -113,7 +113,7 @@ RtpMultiCaster::RtpMultiCaster(SocketHelper &helper, const string &local_ip, con
for
(
auto
i
=
0
;
i
<
2
;
++
i
)
{
//创建udp socket, 数组下标为TrackType
_udp_sock
[
i
]
=
helper
.
createSocket
();
if
(
!
_udp_sock
[
i
]
->
bindUdpSock
(
0
,
local_ip
.
data
()))
{
if
(
!
_udp_sock
[
i
]
->
bindUdpSock
(
(
i
==
TrackVideo
)
?
video_port
:
audio_port
,
local_ip
.
data
()))
{
auto
err
=
StrPrinter
<<
"绑定UDP端口失败:"
<<
local_ip
<<
endl
;
throw
std
::
runtime_error
(
err
);
}
...
...
@@ -171,11 +171,11 @@ string RtpMultiCaster::getMultiCasterIP() {
return
SockUtil
::
inet_ntoa
(
addr
);
}
RtpMultiCaster
::
Ptr
RtpMultiCaster
::
get
(
SocketHelper
&
helper
,
const
string
&
local_ip
,
const
string
&
vhost
,
const
string
&
app
,
const
string
&
stream
)
{
static
auto
on_create
=
[](
SocketHelper
&
helper
,
const
string
&
local_ip
,
const
string
&
vhost
,
const
string
&
app
,
const
string
&
stream
){
RtpMultiCaster
::
Ptr
RtpMultiCaster
::
get
(
SocketHelper
&
helper
,
const
string
&
local_ip
,
const
string
&
vhost
,
const
string
&
app
,
const
string
&
stream
,
uint32_t
multicast_ip
,
uint16_t
video_port
,
uint16_t
audio_port
)
{
static
auto
on_create
=
[](
SocketHelper
&
helper
,
const
string
&
local_ip
,
const
string
&
vhost
,
const
string
&
app
,
const
string
&
stream
,
uint32_t
multicast_ip
,
uint16_t
video_port
,
uint16_t
audio_port
){
try
{
auto
poller
=
helper
.
getPoller
();
auto
ret
=
RtpMultiCaster
::
Ptr
(
new
RtpMultiCaster
(
helper
,
local_ip
,
vhost
,
app
,
stream
),
[
poller
](
RtpMultiCaster
*
ptr
)
{
auto
ret
=
RtpMultiCaster
::
Ptr
(
new
RtpMultiCaster
(
helper
,
local_ip
,
vhost
,
app
,
stream
,
multicast_ip
,
video_port
,
audio_port
),
[
poller
](
RtpMultiCaster
*
ptr
)
{
poller
->
async
([
ptr
]()
{
delete
ptr
;
});
...
...
@@ -194,12 +194,12 @@ RtpMultiCaster::Ptr RtpMultiCaster::get(SocketHelper &helper, const string &loca
lock_guard
<
recursive_mutex
>
lck
(
g_mtx
);
auto
it
=
g_multi_caster_map
.
find
(
strKey
);
if
(
it
==
g_multi_caster_map
.
end
())
{
return
on_create
(
helper
,
local_ip
,
vhost
,
app
,
stream
);
return
on_create
(
helper
,
local_ip
,
vhost
,
app
,
stream
,
multicast_ip
,
video_port
,
audio_port
);
}
auto
ret
=
it
->
second
.
lock
();
if
(
!
ret
)
{
g_multi_caster_map
.
erase
(
it
);
return
on_create
(
helper
,
local_ip
,
vhost
,
app
,
stream
);
return
on_create
(
helper
,
local_ip
,
vhost
,
app
,
stream
,
multicast_ip
,
video_port
,
audio_port
);
}
return
ret
;
}
...
...
src/Rtsp/RtpMultiCaster.h
查看文件 @
dc26bbf1
...
...
@@ -46,14 +46,14 @@ public:
~
RtpMultiCaster
();
static
Ptr
get
(
toolkit
::
SocketHelper
&
helper
,
const
std
::
string
&
local_ip
,
const
std
::
string
&
vhost
,
const
std
::
string
&
app
,
const
std
::
string
&
stream
);
static
Ptr
get
(
toolkit
::
SocketHelper
&
helper
,
const
std
::
string
&
local_ip
,
const
std
::
string
&
vhost
,
const
std
::
string
&
app
,
const
std
::
string
&
stream
,
uint32_t
multicast_ip
=
0
,
uint16_t
video_port
=
0
,
uint16_t
audio_port
=
0
);
void
setDetachCB
(
void
*
listener
,
const
onDetach
&
cb
);
std
::
string
getMultiCasterIP
();
uint16_t
getMultiCasterPort
(
TrackType
trackType
);
private
:
RtpMultiCaster
(
toolkit
::
SocketHelper
&
helper
,
const
std
::
string
&
local_ip
,
const
std
::
string
&
vhost
,
const
std
::
string
&
app
,
const
std
::
string
&
stream
);
RtpMultiCaster
(
toolkit
::
SocketHelper
&
helper
,
const
std
::
string
&
local_ip
,
const
std
::
string
&
vhost
,
const
std
::
string
&
app
,
const
std
::
string
&
stream
,
uint32_t
multicast_ip
,
uint16_t
video_port
,
uint16_t
audio_port
);
private
:
std
::
recursive_mutex
_mtx
;
...
...
src/Rtsp/RtspSession.cpp
查看文件 @
dc26bbf1
...
...
@@ -721,7 +721,7 @@ void RtspSession::handleReq_Setup(const Parser &parser) {
break
;
case
Rtsp
:
:
RTP_MULTICAST
:
{
if
(
!
_multicaster
){
_multicaster
=
RtpMultiCaster
::
get
(
*
this
,
get_local_ip
(),
_media_info
.
_vhost
,
_media_info
.
_app
,
_media_info
.
_streamid
);
_multicaster
=
RtpMultiCaster
::
get
(
*
this
,
get_local_ip
(),
_media_info
.
_vhost
,
_media_info
.
_app
,
_media_info
.
_streamid
,
_multicast_ip
,
_multicast_video_port
,
_multicast_audio_port
);
if
(
!
_multicaster
)
{
send_NotAcceptable
();
throw
SockException
(
Err_shutdown
,
"can not get a available udp multicast socket"
);
...
...
src/Rtsp/RtspSession.h
查看文件 @
dc26bbf1
...
...
@@ -72,6 +72,22 @@ protected:
//收到RTCP包回调
virtual
void
onRtcpPacket
(
int
track_idx
,
SdpTrack
::
Ptr
&
track
,
const
char
*
data
,
size_t
len
);
//回复客户端
virtual
bool
sendRtspResponse
(
const
std
::
string
&
res_code
,
const
StrCaseMap
&
header
=
StrCaseMap
(),
const
std
::
string
&
sdp
=
""
,
const
char
*
protocol
=
"RTSP/1.0"
);
//url解析后保存的相关信息
MediaInfo
_media_info
;
////////RTP over udp_multicast////////
//共享的rtp组播对象
RtpMultiCaster
::
Ptr
_multicaster
;
//Session号
std
::
string
_sessionid
;
uint32_t
_multicast_ip
=
0
;
uint16_t
_multicast_video_port
=
0
;
uint16_t
_multicast_audio_port
=
0
;
private
:
//处理options方法,获取服务器能力
void
handleReq_Options
(
const
Parser
&
parser
);
...
...
@@ -130,7 +146,6 @@ private:
void
updateRtcpContext
(
const
RtpPacket
::
Ptr
&
rtp
);
//回复客户端
bool
sendRtspResponse
(
const
std
::
string
&
res_code
,
const
std
::
initializer_list
<
std
::
string
>
&
header
,
const
std
::
string
&
sdp
=
""
,
const
char
*
protocol
=
"RTSP/1.0"
);
bool
sendRtspResponse
(
const
std
::
string
&
res_code
,
const
StrCaseMap
&
header
=
StrCaseMap
(),
const
std
::
string
&
sdp
=
""
,
const
char
*
protocol
=
"RTSP/1.0"
);
//设置socket标志
void
setSocketFlags
();
...
...
@@ -149,8 +164,6 @@ private:
uint64_t
_bytes_usage
=
0
;
//ContentBase
std
::
string
_content_base
;
//Session号
std
::
string
_sessionid
;
//记录是否需要rtsp专属鉴权,防止重复触发事件
std
::
string
_rtsp_realm
;
//登录认证
...
...
@@ -158,8 +171,6 @@ private:
//用于判断客户端是否超时
toolkit
::
Ticker
_alive_ticker
;
//url解析后保存的相关信息
MediaInfo
_media_info
;
//rtsp推流相关绑定的源
RtspMediaSourceImp
::
Ptr
_push_src
;
//推流器所有权
...
...
@@ -180,9 +191,6 @@ private:
toolkit
::
Socket
::
Ptr
_rtcp_socks
[
2
];
//标记是否收到播放的udp打洞包,收到播放的udp打洞包后才能知道其外网udp端口号
std
::
unordered_set
<
int
>
_udp_connected_flags
;
////////RTP over udp_multicast////////
//共享的rtp组播对象
RtpMultiCaster
::
Ptr
_multicaster
;
////////RTSP over HTTP ////////
//quicktime 请求rtsp会产生两次tcp连接,
//一次发送 get 一次发送post,需要通过x-sessioncookie关联起来
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论