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
c77f82f0
Commit
c77f82f0
authored
Mar 04, 2020
by
xiongziliang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
尝试添加rtp类型自动判断逻辑
parent
f384f5e0
隐藏空白字符变更
内嵌
并排
正在显示
8 个修改的文件
包含
37 行增加
和
15 行删除
+37
-15
conf/config.ini
+0
-2
src/Common/config.cpp
+0
-3
src/Common/config.h
+0
-2
src/Rtp/RtpDecoder.cpp
+11
-3
src/Rtp/RtpDecoder.h
+2
-1
src/Rtp/RtpProcess.cpp
+19
-2
src/Rtp/RtpProcess.h
+5
-0
tests/test_rtp.cpp
+0
-2
没有找到文件。
conf/config.ini
查看文件 @
c77f82f0
...
@@ -168,8 +168,6 @@ checkSource=1
...
@@ -168,8 +168,6 @@ checkSource=1
dumpDir
=
dumpDir
=
#udp和tcp代理服务器,支持rtp(必须是ts或ps类型)代理
#udp和tcp代理服务器,支持rtp(必须是ts或ps类型)代理
port
=
10000
port
=
10000
#rtp如果是ts/ps类型则选择MP2P,还可以设置为MP4V-ES
rtp_type
=
MP2P
#rtp超时时间,单位秒
#rtp超时时间,单位秒
timeoutSec
=
15
timeoutSec
=
15
...
...
src/Common/config.cpp
查看文件 @
c77f82f0
...
@@ -282,15 +282,12 @@ namespace RtpProxy {
...
@@ -282,15 +282,12 @@ namespace RtpProxy {
const
string
kDumpDir
=
RTP_PROXY_FIELD
"dumpDir"
;
const
string
kDumpDir
=
RTP_PROXY_FIELD
"dumpDir"
;
//是否限制udp数据来源ip和端口
//是否限制udp数据来源ip和端口
const
string
kCheckSource
=
RTP_PROXY_FIELD
"checkSource"
;
const
string
kCheckSource
=
RTP_PROXY_FIELD
"checkSource"
;
//rtp类型,支持MP2P/MP4V-ES
const
string
kRtpType
=
RTP_PROXY_FIELD
"rtp_type"
;
//rtp接收超时时间
//rtp接收超时时间
const
string
kTimeoutSec
=
RTP_PROXY_FIELD
"timeoutSec"
;
const
string
kTimeoutSec
=
RTP_PROXY_FIELD
"timeoutSec"
;
onceToken
token
([](){
onceToken
token
([](){
mINI
::
Instance
()[
kDumpDir
]
=
""
;
mINI
::
Instance
()[
kDumpDir
]
=
""
;
mINI
::
Instance
()[
kCheckSource
]
=
1
;
mINI
::
Instance
()[
kCheckSource
]
=
1
;
mINI
::
Instance
()[
kRtpType
]
=
"MP2P"
;
mINI
::
Instance
()[
kTimeoutSec
]
=
15
;
mINI
::
Instance
()[
kTimeoutSec
]
=
15
;
},
nullptr
);
},
nullptr
);
}
//namespace RtpProxy
}
//namespace RtpProxy
...
...
src/Common/config.h
查看文件 @
c77f82f0
...
@@ -306,8 +306,6 @@ namespace RtpProxy {
...
@@ -306,8 +306,6 @@ namespace RtpProxy {
extern
const
string
kDumpDir
;
extern
const
string
kDumpDir
;
//是否限制udp数据来源ip和端口
//是否限制udp数据来源ip和端口
extern
const
string
kCheckSource
;
extern
const
string
kCheckSource
;
//rtp类型,支持MP2P/MP4V-ES
extern
const
string
kRtpType
;
//rtp接收超时时间
//rtp接收超时时间
extern
const
string
kTimeoutSec
;
extern
const
string
kTimeoutSec
;
}
//namespace RtpProxy
}
//namespace RtpProxy
...
...
src/Rtp/RtpDecoder.cpp
查看文件 @
c77f82f0
...
@@ -29,7 +29,6 @@
...
@@ -29,7 +29,6 @@
#include "Util/logger.h"
#include "Util/logger.h"
#include "RtpDecoder.h"
#include "RtpDecoder.h"
#include "rtp-payload.h"
#include "rtp-payload.h"
using
namespace
toolkit
;
using
namespace
toolkit
;
namespace
mediakit
{
namespace
mediakit
{
...
@@ -45,7 +44,13 @@ RtpDecoder::~RtpDecoder() {
...
@@ -45,7 +44,13 @@ RtpDecoder::~RtpDecoder() {
}
}
}
}
void
RtpDecoder
::
decodeRtp
(
const
void
*
data
,
int
bytes
,
const
char
*
type_name
)
{
void
RtpDecoder
::
decodeRtp
(
const
void
*
data
,
int
bytes
,
const
string
&
type_name
)
{
if
(
_rtp_type
!=
type_name
&&
_rtp_decoder
){
//rtp类型发生变化,切换之
rtp_payload_decode_destroy
(
_rtp_decoder
);
_rtp_decoder
=
nullptr
;
}
if
(
!
_rtp_decoder
){
if
(
!
_rtp_decoder
){
static
rtp_payload_t
s_func
=
{
static
rtp_payload_t
s_func
=
{
[](
void
*
param
,
int
bytes
){
[](
void
*
param
,
int
bytes
){
...
@@ -64,11 +69,14 @@ void RtpDecoder::decodeRtp(const void *data, int bytes,const char *type_name) {
...
@@ -64,11 +69,14 @@ void RtpDecoder::decodeRtp(const void *data, int bytes,const char *type_name) {
uint8_t
rtp_type
=
0x7F
&
((
uint8_t
*
)
data
)[
1
];
uint8_t
rtp_type
=
0x7F
&
((
uint8_t
*
)
data
)[
1
];
InfoL
<<
"rtp type:"
<<
(
int
)
rtp_type
;
InfoL
<<
"rtp type:"
<<
(
int
)
rtp_type
;
_rtp_decoder
=
rtp_payload_decode_create
(
rtp_type
,
type_name
,
&
s_func
,
this
);
_rtp_decoder
=
rtp_payload_decode_create
(
rtp_type
,
type_name
.
data
()
,
&
s_func
,
this
);
if
(
!
_rtp_decoder
)
{
if
(
!
_rtp_decoder
)
{
WarnL
<<
"unsupported rtp type:"
<<
(
int
)
rtp_type
<<
",size:"
<<
bytes
<<
",hexdump"
<<
hexdump
(
data
,
bytes
>
16
?
16
:
bytes
);
WarnL
<<
"unsupported rtp type:"
<<
(
int
)
rtp_type
<<
",size:"
<<
bytes
<<
",hexdump"
<<
hexdump
(
data
,
bytes
>
16
?
16
:
bytes
);
}
else
{
_rtp_type
=
type_name
;
}
}
}
}
if
(
_rtp_decoder
){
if
(
_rtp_decoder
){
rtp_payload_decode_input
(
_rtp_decoder
,
data
,
bytes
);
rtp_payload_decode_input
(
_rtp_decoder
,
data
,
bytes
);
}
}
...
...
src/Rtp/RtpDecoder.h
查看文件 @
c77f82f0
...
@@ -38,11 +38,12 @@ public:
...
@@ -38,11 +38,12 @@ public:
RtpDecoder
();
RtpDecoder
();
virtual
~
RtpDecoder
();
virtual
~
RtpDecoder
();
protected
:
protected
:
void
decodeRtp
(
const
void
*
data
,
int
bytes
,
const
char
*
type_name
);
void
decodeRtp
(
const
void
*
data
,
int
bytes
,
const
string
&
type_name
);
virtual
void
onRtpDecode
(
const
void
*
packet
,
int
bytes
,
uint32_t
timestamp
,
int
flags
)
=
0
;
virtual
void
onRtpDecode
(
const
void
*
packet
,
int
bytes
,
uint32_t
timestamp
,
int
flags
)
=
0
;
private
:
private
:
void
*
_rtp_decoder
=
nullptr
;
void
*
_rtp_decoder
=
nullptr
;
BufferRaw
::
Ptr
_buffer
;
BufferRaw
::
Ptr
_buffer
;
string
_rtp_type
;
};
};
}
//namespace mediakit
}
//namespace mediakit
...
...
src/Rtp/RtpProcess.cpp
查看文件 @
c77f82f0
...
@@ -33,6 +33,7 @@
...
@@ -33,6 +33,7 @@
namespace
mediakit
{
namespace
mediakit
{
static
const
vector
<
string
>
kRtpTypes
=
{
"MP2P"
,
"MP4V-ES"
};
/**
/**
* 合并一些时间戳相同的frame
* 合并一些时间戳相同的frame
...
@@ -84,6 +85,7 @@ RtpProcess::RtpProcess(uint32_t ssrc) {
...
@@ -84,6 +85,7 @@ RtpProcess::RtpProcess(uint32_t ssrc) {
_track
->
_samplerate
=
90000
;
_track
->
_samplerate
=
90000
;
_track
->
_type
=
TrackVideo
;
_track
->
_type
=
TrackVideo
;
_track
->
_ssrc
=
_ssrc
;
_track
->
_ssrc
=
_ssrc
;
getNextRtpType
();
DebugL
<<
printSSRC
(
_ssrc
);
DebugL
<<
printSSRC
(
_ssrc
);
GET_CONFIG
(
bool
,
toRtxp
,
General
::
kPublishToRtxp
);
GET_CONFIG
(
bool
,
toRtxp
,
General
::
kPublishToRtxp
);
...
@@ -153,6 +155,14 @@ bool RtpProcess::inputRtp(const char *data, int data_len,const struct sockaddr *
...
@@ -153,6 +155,14 @@ bool RtpProcess::inputRtp(const char *data, int data_len,const struct sockaddr *
return
ret
;
return
ret
;
}
}
void
RtpProcess
::
getNextRtpType
(){
_rtp_type
=
kRtpTypes
[
_rtp_type_idx
++
];
_rtp_dec_failed_cnt
=
0
;
if
(
_rtp_type_idx
==
kRtpTypes
.
size
()){
_rtp_type_idx
=
0
;
}
}
void
RtpProcess
::
onRtpSorted
(
const
RtpPacket
::
Ptr
&
rtp
,
int
)
{
void
RtpProcess
::
onRtpSorted
(
const
RtpPacket
::
Ptr
&
rtp
,
int
)
{
if
(
rtp
->
sequence
!=
_sequence
+
1
){
if
(
rtp
->
sequence
!=
_sequence
+
1
){
WarnL
<<
rtp
->
sequence
<<
" != "
<<
_sequence
<<
"+1"
;
WarnL
<<
rtp
->
sequence
<<
" != "
<<
_sequence
<<
"+1"
;
...
@@ -166,8 +176,7 @@ void RtpProcess::onRtpSorted(const RtpPacket::Ptr &rtp, int) {
...
@@ -166,8 +176,7 @@ void RtpProcess::onRtpSorted(const RtpPacket::Ptr &rtp, int) {
fwrite
((
uint8_t
*
)
rtp
->
data
()
+
4
,
rtp
->
size
()
-
4
,
1
,
_save_file_rtp
.
get
());
fwrite
((
uint8_t
*
)
rtp
->
data
()
+
4
,
rtp
->
size
()
-
4
,
1
,
_save_file_rtp
.
get
());
}
}
GET_CONFIG
(
string
,
rtp_type
,
::
RtpProxy
::
kRtpType
);
decodeRtp
(
rtp
->
data
()
+
4
,
rtp
->
size
()
-
4
,
_rtp_type
);
decodeRtp
(
rtp
->
data
()
+
4
,
rtp
->
size
()
-
4
,
rtp_type
.
data
());
}
}
void
RtpProcess
::
onRtpDecode
(
const
void
*
packet
,
int
bytes
,
uint32_t
,
int
flags
)
{
void
RtpProcess
::
onRtpDecode
(
const
void
*
packet
,
int
bytes
,
uint32_t
,
int
flags
)
{
...
@@ -178,6 +187,12 @@ void RtpProcess::onRtpDecode(const void *packet, int bytes, uint32_t, int flags)
...
@@ -178,6 +187,12 @@ void RtpProcess::onRtpDecode(const void *packet, int bytes, uint32_t, int flags)
auto
ret
=
decodePS
((
uint8_t
*
)
packet
,
bytes
);
auto
ret
=
decodePS
((
uint8_t
*
)
packet
,
bytes
);
if
(
ret
!=
bytes
){
if
(
ret
!=
bytes
){
WarnL
<<
ret
<<
" != "
<<
bytes
<<
" "
<<
flags
;
WarnL
<<
ret
<<
" != "
<<
bytes
<<
" "
<<
flags
;
if
(
++
_rtp_dec_failed_cnt
==
10
){
getNextRtpType
();
InfoL
<<
"rtp of ssrc "
<<
printSSRC
(
_ssrc
)
<<
" change to type: "
<<
_rtp_type
;
}
}
else
{
_rtp_dec_failed_cnt
=
0
;
}
}
}
}
...
@@ -307,5 +322,6 @@ void RtpProcess::setListener(const std::weak_ptr<MediaSourceEvent> &listener){
...
@@ -307,5 +322,6 @@ void RtpProcess::setListener(const std::weak_ptr<MediaSourceEvent> &listener){
_muxer
->
setListener
(
listener
);
_muxer
->
setListener
(
listener
);
}
}
}
//namespace mediakit
}
//namespace mediakit
#endif//defined(ENABLE_RTPPROXY)
#endif//defined(ENABLE_RTPPROXY)
\ No newline at end of file
src/Rtp/RtpProcess.h
查看文件 @
c77f82f0
...
@@ -63,6 +63,8 @@ protected:
...
@@ -63,6 +63,8 @@ protected:
const
void
*
data
,
const
void
*
data
,
int
bytes
)
override
;
int
bytes
)
override
;
private
:
private
:
void
getNextRtpType
();
private
:
std
::
shared_ptr
<
FILE
>
_save_file_rtp
;
std
::
shared_ptr
<
FILE
>
_save_file_rtp
;
std
::
shared_ptr
<
FILE
>
_save_file_ps
;
std
::
shared_ptr
<
FILE
>
_save_file_ps
;
std
::
shared_ptr
<
FILE
>
_save_file_video
;
std
::
shared_ptr
<
FILE
>
_save_file_video
;
...
@@ -77,6 +79,9 @@ private:
...
@@ -77,6 +79,9 @@ private:
Ticker
_last_rtp_time
;
Ticker
_last_rtp_time
;
map
<
int
,
Stamp
>
_stamps
;
map
<
int
,
Stamp
>
_stamps
;
uint32_t
_dts
=
0
;
uint32_t
_dts
=
0
;
int
_rtp_type_idx
=
0
;
string
_rtp_type
;
int
_rtp_dec_failed_cnt
=
0
;
};
};
}
//namespace mediakit
}
//namespace mediakit
...
...
tests/test_rtp.cpp
查看文件 @
c77f82f0
...
@@ -98,8 +98,6 @@ int main(int argc,char *argv[]) {
...
@@ -98,8 +98,6 @@ int main(int argc,char *argv[]) {
rtspSrv
->
start
<
RtspSession
>
(
554
);
//默认554
rtspSrv
->
start
<
RtspSession
>
(
554
);
//默认554
rtmpSrv
->
start
<
RtmpSession
>
(
1935
);
//默认1935
rtmpSrv
->
start
<
RtmpSession
>
(
1935
);
//默认1935
httpSrv
->
start
<
HttpSession
>
(
80
);
//默认80
httpSrv
->
start
<
HttpSession
>
(
80
);
//默认80
//此处可以选择MP4V-ES或MP2P
mINI
::
Instance
()[
RtpProxy
::
kRtpType
]
=
"MP4V-ES"
;
//此处选择是否导出调试文件
//此处选择是否导出调试文件
// mINI::Instance()[RtpProxy::kDumpDir] = "/Users/xzl/Desktop/";
// mINI::Instance()[RtpProxy::kDumpDir] = "/Users/xzl/Desktop/";
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论