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
10884340
Commit
10884340
authored
Mar 08, 2020
by
xiongziliang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化rtp推流相关代码
parent
ae45c24f
显示空白字符变更
内嵌
并排
正在显示
10 个修改的文件
包含
31 行增加
和
41 行删除
+31
-41
3rdpart/media-server
+1
-1
src/Common/MediaSink.cpp
+1
-0
src/Extension/Factory.cpp
+2
-2
src/Extension/Frame.cpp
+11
-0
src/Extension/Frame.h
+6
-0
src/Record/MP4Muxer.cpp
+1
-1
src/Rtp/RtpDecoder.cpp
+2
-11
src/Rtp/RtpDecoder.h
+1
-2
src/Rtp/RtpProcess.cpp
+6
-20
src/Rtp/RtpProcess.h
+0
-4
没有找到文件。
media-server
@
1603194d
Subproject commit
8d40dad3dbdce171756691d4511aca49fcf2a23
1
Subproject commit
1603194dafdcecda9036e5741ec8d3e8c9ab1e0
1
src/Common/MediaSink.cpp
查看文件 @
10884340
...
...
@@ -137,6 +137,7 @@ void MediaSink::emitAllTrackReady() {
//移除未准备好的Track
for
(
auto
it
=
_track_map
.
begin
();
it
!=
_track_map
.
end
();)
{
if
(
!
it
->
second
->
ready
())
{
WarnL
<<
"该track长时间未被初始化,已忽略:"
<<
it
->
second
->
getCodecName
();
it
=
_track_map
.
erase
(
it
);
continue
;
}
...
...
src/Extension/Factory.cpp
查看文件 @
10884340
...
...
@@ -155,7 +155,7 @@ RtpCodec::Ptr Factory::getRtpDecoderByTrack(const Track::Ptr &track) {
case
CodecAAC
:
return
std
::
make_shared
<
AACRtpDecoder
>
(
track
->
clone
());
default
:
WarnL
<<
"暂不支持该CodecId:"
<<
track
->
getCodec
Id
();
WarnL
<<
"暂不支持该CodecId:"
<<
track
->
getCodec
Name
();
return
nullptr
;
}
}
...
...
@@ -212,7 +212,7 @@ RtmpCodec::Ptr Factory::getRtmpCodecByTrack(const Track::Ptr &track) {
case
CodecAAC
:
return
std
::
make_shared
<
AACRtmpEncoder
>
(
track
);
default
:
WarnL
<<
"暂不支持该CodecId:"
<<
track
->
getCodec
Id
();
WarnL
<<
"暂不支持该CodecId:"
<<
track
->
getCodec
Name
();
return
nullptr
;
}
}
...
...
src/Extension/Frame.cpp
查看文件 @
10884340
...
...
@@ -38,5 +38,16 @@ Frame::Ptr Frame::getCacheAbleFrame(const Frame::Ptr &frame){
return
std
::
make_shared
<
FrameCacheAble
>
(
frame
);
}
#define SWITCH_CASE(codec_id) case codec_id : return #codec_id
char
*
CodecInfo
::
getCodecName
()
{
switch
(
getCodecId
())
{
SWITCH_CASE
(
CodecH264
);
SWITCH_CASE
(
CodecH265
);
SWITCH_CASE
(
CodecAAC
);
default
:
return
"unknown codec"
;
}
}
}
//namespace mediakit
src/Extension/Frame.h
查看文件 @
10884340
...
...
@@ -72,6 +72,12 @@ public:
* 获取编解码器类型
*/
virtual
CodecId
getCodecId
()
const
=
0
;
/**
* 获取编码器名称
* @return 编码器名称
*/
char
*
getCodecName
();
};
/**
...
...
src/Record/MP4Muxer.cpp
查看文件 @
10884340
...
...
@@ -258,7 +258,7 @@ void MP4Muxer::addTrack(const Track::Ptr &track) {
}
break
;
default
:
WarnL
<<
"MP4录制不支持该编码格式:"
<<
track
->
getCodec
Id
();
WarnL
<<
"MP4录制不支持该编码格式:"
<<
track
->
getCodec
Name
();
break
;
}
}
...
...
src/Rtp/RtpDecoder.cpp
查看文件 @
10884340
...
...
@@ -25,7 +25,6 @@
*/
#if defined(ENABLE_RTPPROXY)
#include <assert.h>
#include "Util/logger.h"
#include "RtpDecoder.h"
#include "rtp-payload.h"
...
...
@@ -44,13 +43,7 @@ RtpDecoder::~RtpDecoder() {
}
}
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
;
}
void
RtpDecoder
::
decodeRtp
(
const
void
*
data
,
int
bytes
)
{
if
(
!
_rtp_decoder
){
static
rtp_payload_t
s_func
=
{
[](
void
*
param
,
int
bytes
){
...
...
@@ -69,11 +62,9 @@ void RtpDecoder::decodeRtp(const void *data, int bytes,const string &type_name)
uint8_t
rtp_type
=
0x7F
&
((
uint8_t
*
)
data
)[
1
];
InfoL
<<
"rtp type:"
<<
(
int
)
rtp_type
;
_rtp_decoder
=
rtp_payload_decode_create
(
rtp_type
,
type_name
.
data
()
,
&
s_func
,
this
);
_rtp_decoder
=
rtp_payload_decode_create
(
rtp_type
,
"MP4V-ES"
,
&
s_func
,
this
);
if
(
!
_rtp_decoder
)
{
WarnL
<<
"unsupported rtp type:"
<<
(
int
)
rtp_type
<<
",size:"
<<
bytes
<<
",hexdump"
<<
hexdump
(
data
,
bytes
>
16
?
16
:
bytes
);
}
else
{
_rtp_type
=
type_name
;
}
}
...
...
src/Rtp/RtpDecoder.h
查看文件 @
10884340
...
...
@@ -38,12 +38,11 @@ public:
RtpDecoder
();
virtual
~
RtpDecoder
();
protected
:
void
decodeRtp
(
const
void
*
data
,
int
bytes
,
const
string
&
type_name
);
void
decodeRtp
(
const
void
*
data
,
int
bytes
);
virtual
void
onRtpDecode
(
const
uint8_t
*
packet
,
int
bytes
,
uint32_t
timestamp
,
int
flags
)
=
0
;
private
:
void
*
_rtp_decoder
=
nullptr
;
BufferRaw
::
Ptr
_buffer
;
string
_rtp_type
;
};
}
//namespace mediakit
...
...
src/Rtp/RtpProcess.cpp
查看文件 @
10884340
...
...
@@ -33,8 +33,6 @@
namespace
mediakit
{
static
const
vector
<
string
>
kRtpTypes
=
{
"MP2P"
,
"MP4V-ES"
};
/**
* 合并一些时间戳相同的frame
*/
...
...
@@ -85,7 +83,6 @@ RtpProcess::RtpProcess(uint32_t ssrc) {
_track
->
_samplerate
=
90000
;
_track
->
_type
=
TrackVideo
;
_track
->
_ssrc
=
_ssrc
;
getNextRtpType
();
DebugL
<<
printSSRC
(
_ssrc
);
GET_CONFIG
(
bool
,
toRtxp
,
General
::
kPublishToRtxp
);
...
...
@@ -155,12 +152,9 @@ bool RtpProcess::inputRtp(const char *data, int data_len,const struct sockaddr *
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
;
}
//判断是否为ts负载
static
inline
bool
checkTS
(
const
uint8_t
*
packet
,
int
bytes
){
return
bytes
%
188
==
0
&&
packet
[
0
]
==
0x47
;
}
void
RtpProcess
::
onRtpSorted
(
const
RtpPacket
::
Ptr
&
rtp
,
int
)
{
...
...
@@ -168,25 +162,23 @@ void RtpProcess::onRtpSorted(const RtpPacket::Ptr &rtp, int) {
WarnL
<<
rtp
->
sequence
<<
" != "
<<
_sequence
<<
"+1"
;
}
_sequence
=
rtp
->
sequence
;
if
(
_save_file_rtp
){
uint16_t
size
=
rtp
->
size
()
-
4
;
size
=
htons
(
size
);
fwrite
((
uint8_t
*
)
&
size
,
2
,
1
,
_save_file_rtp
.
get
());
fwrite
((
uint8_t
*
)
rtp
->
data
()
+
4
,
rtp
->
size
()
-
4
,
1
,
_save_file_rtp
.
get
());
}
decodeRtp
(
rtp
->
data
()
+
4
,
rtp
->
size
()
-
4
,
_rtp_type
);
decodeRtp
(
rtp
->
data
()
+
4
,
rtp
->
size
()
-
4
);
}
void
RtpProcess
::
onRtpDecode
(
const
uint8_t
*
packet
,
int
bytes
,
uint32_t
,
int
flags
)
{
void
RtpProcess
::
onRtpDecode
(
const
uint8_t
*
packet
,
int
bytes
,
uint32_t
timestamp
,
int
flags
)
{
if
(
_save_file_ps
){
fwrite
((
uint8_t
*
)
packet
,
bytes
,
1
,
_save_file_ps
.
get
());
}
if
(
!
_decoder
){
//创建解码器
if
(
bytes
%
188
==
0
&&
packet
[
0
]
==
0x47
){
if
(
checkTS
(
packet
,
bytes
)
){
//猜测是ts负载
_decoder
=
Decoder
::
createDecoder
(
Decoder
::
decoder_ts
);
}
else
{
...
...
@@ -201,12 +193,6 @@ void RtpProcess::onRtpDecode(const uint8_t *packet, int bytes, uint32_t, int fla
auto
ret
=
_decoder
->
input
((
uint8_t
*
)
packet
,
bytes
);
if
(
ret
!=
bytes
){
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
;
}
}
...
...
src/Rtp/RtpProcess.h
查看文件 @
10884340
...
...
@@ -49,7 +49,6 @@ public:
bool
alive
();
string
get_peer_ip
();
uint16_t
get_peer_port
();
int
totalReaderCount
();
void
setListener
(
const
std
::
weak_ptr
<
MediaSourceEvent
>
&
listener
);
protected
:
...
...
@@ -73,9 +72,6 @@ private:
Ticker
_last_rtp_time
;
map
<
int
,
Stamp
>
_stamps
;
uint32_t
_dts
=
0
;
int
_rtp_type_idx
=
0
;
string
_rtp_type
;
int
_rtp_dec_failed_cnt
=
0
;
Decoder
::
Ptr
_decoder
;
};
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论