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
109fab2c
Commit
109fab2c
authored
Feb 28, 2020
by
xiongziliang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
RTP代理支持完整的事件
parent
5acdf1f7
显示空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
117 行增加
和
8 行删除
+117
-8
src/Rtp/RtpProcess.cpp
+9
-0
src/Rtp/RtpProcess.h
+3
-0
src/Rtp/RtpSelector.cpp
+49
-5
src/Rtp/RtpSelector.h
+23
-1
src/Rtp/RtpSession.cpp
+25
-0
src/Rtp/RtpSession.h
+8
-2
没有找到文件。
src/Rtp/RtpProcess.cpp
查看文件 @
109fab2c
...
...
@@ -299,5 +299,13 @@ uint16_t RtpProcess::get_peer_port() {
return
ntohs
(((
struct
sockaddr_in
*
)
_addr
)
->
sin_port
);
}
int
RtpProcess
::
totalReaderCount
(){
return
_muxer
->
totalReaderCount
();
}
void
RtpProcess
::
setListener
(
const
std
::
weak_ptr
<
MediaSourceEvent
>
&
listener
){
_muxer
->
setListener
(
listener
);
}
}
//namespace mediakit
#endif//defined(ENABLE_RTPPROXY)
\ No newline at end of file
src/Rtp/RtpProcess.h
查看文件 @
109fab2c
...
...
@@ -49,6 +49,9 @@ public:
bool
alive
();
string
get_peer_ip
();
uint16_t
get_peer_port
();
int
totalReaderCount
();
void
setListener
(
const
std
::
weak_ptr
<
MediaSourceEvent
>
&
listener
);
protected
:
void
onRtpSorted
(
const
RtpPacket
::
Ptr
&
rtp
,
int
track_index
)
override
;
void
onRtpDecode
(
const
void
*
packet
,
int
bytes
,
uint32_t
timestamp
,
int
flags
)
override
;
...
...
src/Rtp/RtpSelector.cpp
查看文件 @
109fab2c
...
...
@@ -63,11 +63,12 @@ RtpProcess::Ptr RtpSelector::getProcess(uint32_t ssrc,bool makeNew) {
if
(
it
==
_map_rtp_process
.
end
()
&&
!
makeNew
){
return
nullptr
;
}
RtpProcess
::
Ptr
&
ref
=
_map_rtp_process
[
ssrc
];
RtpProcess
Helper
::
Ptr
&
ref
=
_map_rtp_process
[
ssrc
];
if
(
!
ref
){
ref
=
std
::
make_shared
<
RtpProcess
>
(
ssrc
);
ref
=
std
::
make_shared
<
RtpProcessHelper
>
(
ssrc
,
shared_from_this
());
ref
->
attachEvent
();
}
return
ref
;
return
ref
->
getProcess
()
;
}
void
RtpSelector
::
delProcess
(
uint32_t
ssrc
,
const
RtpProcess
*
ptr
)
{
...
...
@@ -77,7 +78,7 @@ void RtpSelector::delProcess(uint32_t ssrc,const RtpProcess *ptr) {
return
;
}
if
(
it
->
second
.
get
()
!=
ptr
){
if
(
it
->
second
->
getProcess
()
.
get
()
!=
ptr
){
return
;
}
...
...
@@ -87,7 +88,7 @@ void RtpSelector::delProcess(uint32_t ssrc,const RtpProcess *ptr) {
void
RtpSelector
::
onManager
()
{
lock_guard
<
decltype
(
_mtx_map
)
>
lck
(
_mtx_map
);
for
(
auto
it
=
_map_rtp_process
.
begin
();
it
!=
_map_rtp_process
.
end
();)
{
if
(
it
->
second
->
alive
())
{
if
(
it
->
second
->
getProcess
()
->
alive
())
{
++
it
;
continue
;
}
...
...
@@ -102,5 +103,47 @@ RtpSelector::RtpSelector() {
RtpSelector
::~
RtpSelector
()
{
}
RtpProcessHelper
::
RtpProcessHelper
(
uint32_t
ssrc
,
const
weak_ptr
<
RtpSelector
>
&
parent
)
{
_ssrc
=
ssrc
;
_parent
=
parent
;
_process
=
std
::
make_shared
<
RtpProcess
>
(
_ssrc
);
}
RtpProcessHelper
::~
RtpProcessHelper
()
{
}
void
RtpProcessHelper
::
attachEvent
()
{
_process
->
setListener
(
shared_from_this
());
}
bool
RtpProcessHelper
::
close
(
MediaSource
&
sender
,
bool
force
)
{
//此回调在其他线程触发
if
(
!
_process
||
(
!
force
&&
_process
->
totalReaderCount
())){
return
false
;
}
auto
parent
=
_parent
.
lock
();
if
(
!
parent
){
return
false
;
}
parent
->
delProcess
(
_ssrc
,
_process
.
get
());
string
err
=
StrPrinter
<<
"close media:"
<<
sender
.
getSchema
()
<<
"/"
<<
sender
.
getVhost
()
<<
"/"
<<
sender
.
getApp
()
<<
"/"
<<
sender
.
getId
()
<<
" "
<<
force
;
return
true
;
}
void
RtpProcessHelper
::
onNoneReader
(
MediaSource
&
sender
)
{
if
(
!
_process
||
_process
->
totalReaderCount
()){
return
;
}
MediaSourceEvent
::
onNoneReader
(
sender
);
}
int
RtpProcessHelper
::
totalReaderCount
(
MediaSource
&
sender
)
{
return
_process
?
_process
->
totalReaderCount
()
:
sender
.
totalReaderCount
();
}
RtpProcess
::
Ptr
&
RtpProcessHelper
::
getProcess
()
{
return
_process
;
}
}
//namespace mediakit
#endif//defined(ENABLE_RTPPROXY)
\ No newline at end of file
src/Rtp/RtpSelector.h
查看文件 @
109fab2c
...
...
@@ -32,9 +32,31 @@
#include <mutex>
#include <unordered_map>
#include "RtpProcess.h"
#include "Common/MediaSource.h"
namespace
mediakit
{
class
RtpSelector
;
class
RtpProcessHelper
:
public
MediaSourceEvent
,
public
std
::
enable_shared_from_this
<
RtpProcessHelper
>
{
public
:
typedef
std
::
shared_ptr
<
RtpProcessHelper
>
Ptr
;
RtpProcessHelper
(
uint32_t
ssrc
,
const
weak_ptr
<
RtpSelector
>
&
parent
);
~
RtpProcessHelper
();
void
attachEvent
();
RtpProcess
::
Ptr
&
getProcess
();
protected
:
// 通知其停止推流
bool
close
(
MediaSource
&
sender
,
bool
force
)
override
;
// 通知无人观看
void
onNoneReader
(
MediaSource
&
sender
)
override
;
// 观看总人数
int
totalReaderCount
(
MediaSource
&
sender
)
override
;
private
:
weak_ptr
<
RtpSelector
>
_parent
;
RtpProcess
::
Ptr
_process
;
uint32_t
_ssrc
=
0
;
};
class
RtpSelector
:
public
std
::
enable_shared_from_this
<
RtpSelector
>
{
public
:
RtpSelector
();
...
...
@@ -48,7 +70,7 @@ public:
private
:
void
onManager
();
private
:
unordered_map
<
uint32_t
,
RtpProcess
::
Ptr
>
_map_rtp_process
;
unordered_map
<
uint32_t
,
RtpProcess
Helper
::
Ptr
>
_map_rtp_process
;
recursive_mutex
_mtx_map
;
Ticker
_last_rtp_time
;
};
...
...
src/Rtp/RtpSession.cpp
查看文件 @
109fab2c
...
...
@@ -71,10 +71,34 @@ void RtpSession::onRtpPacket(const char *data, uint64_t len) {
return
;
}
_process
=
RtpSelector
::
Instance
().
getProcess
(
_ssrc
,
true
);
_process
->
setListener
(
dynamic_pointer_cast
<
RtpSession
>
(
shared_from_this
()));
}
_process
->
inputRtp
(
data
+
2
,
len
-
2
,
&
addr
);
_ticker
.
resetTime
();
}
bool
RtpSession
::
close
(
MediaSource
&
sender
,
bool
force
)
{
//此回调在其他线程触发
if
(
!
_process
||
(
!
force
&&
_process
->
totalReaderCount
())){
return
false
;
}
string
err
=
StrPrinter
<<
"close media:"
<<
sender
.
getSchema
()
<<
"/"
<<
sender
.
getVhost
()
<<
"/"
<<
sender
.
getApp
()
<<
"/"
<<
sender
.
getId
()
<<
" "
<<
force
;
safeShutdown
(
SockException
(
Err_shutdown
,
err
));
return
true
;
}
void
RtpSession
::
onNoneReader
(
MediaSource
&
sender
)
{
//此回调在其他线程触发
if
(
!
_process
||
_process
->
totalReaderCount
()){
return
;
}
MediaSourceEvent
::
onNoneReader
(
sender
);
}
int
RtpSession
::
totalReaderCount
(
MediaSource
&
sender
)
{
//此回调在其他线程触发
return
_process
?
_process
->
totalReaderCount
()
:
sender
.
totalReaderCount
();
}
}
//namespace mediakit
#endif//defined(ENABLE_RTPPROXY)
\ No newline at end of file
src/Rtp/RtpSession.h
查看文件 @
109fab2c
...
...
@@ -36,14 +36,20 @@ using namespace toolkit;
namespace
mediakit
{
class
RtpSession
:
public
TcpSession
,
public
RtpSplitter
{
class
RtpSession
:
public
TcpSession
,
public
RtpSplitter
,
public
MediaSourceEvent
{
public
:
RtpSession
(
const
Socket
::
Ptr
&
sock
);
~
RtpSession
()
override
;
void
onRecv
(
const
Buffer
::
Ptr
&
)
override
;
void
onError
(
const
SockException
&
err
)
override
;
void
onManager
()
override
;
private
:
protected
:
// 通知其停止推流
bool
close
(
MediaSource
&
sender
,
bool
force
)
override
;
// 通知无人观看
void
onNoneReader
(
MediaSource
&
sender
)
override
;
// 观看总人数
int
totalReaderCount
(
MediaSource
&
sender
)
override
;
void
onRtpPacket
(
const
char
*
data
,
uint64_t
len
)
override
;
private
:
uint32_t
_ssrc
=
0
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论