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
c353c626
Commit
c353c626
authored
Dec 16, 2019
by
xiongziliang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1、根据PS获取时间戳
2、修复rtp代理可能花屏的问题
parent
bfa9a3b6
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
53 行增加
和
17 行删除
+53
-17
src/Rtp/RtpProcess.cpp
+45
-6
src/Rtp/RtpProcess.h
+4
-2
src/Rtp/RtpSelector.cpp
+2
-2
src/Rtp/RtpSelector.h
+1
-1
tests/test_rtp.cpp
+1
-6
没有找到文件。
src/Rtp/RtpProcess.cpp
查看文件 @
c353c626
...
...
@@ -33,6 +33,35 @@
namespace
mediakit
{
/**
* 合并一些时间戳相同的frame
*/
class
FrameMerger
{
public
:
FrameMerger
()
=
default
;
virtual
~
FrameMerger
()
=
default
;
void
inputFrame
(
const
Frame
::
Ptr
&
frame
,
const
function
<
void
(
uint32_t
dts
,
uint32_t
pts
,
const
Buffer
::
Ptr
&
buffer
)
>
&
cb
){
if
(
!
_frameCached
.
empty
()
&&
_frameCached
.
back
()
->
dts
()
!=
frame
->
dts
())
{
Frame
::
Ptr
back
=
_frameCached
.
back
();
Buffer
::
Ptr
merged_frame
=
back
;
if
(
_frameCached
.
size
()
!=
1
){
string
merged
;
_frameCached
.
for_each
([
&
](
const
Frame
::
Ptr
&
frame
){
merged
.
append
(
frame
->
data
(),
frame
->
size
());
});
merged_frame
=
std
::
make_shared
<
BufferString
>
(
std
::
move
(
merged
));
}
cb
(
back
->
dts
(),
back
->
pts
(),
merged_frame
);
_frameCached
.
clear
();
}
_frameCached
.
emplace_back
(
Frame
::
getCacheAbleFrame
(
frame
));
}
private
:
List
<
Frame
::
Ptr
>
_frameCached
;
};
string
printSSRC
(
uint32_t
ui32Ssrc
)
{
char
tmp
[
9
]
=
{
0
};
ui32Ssrc
=
htonl
(
ui32Ssrc
);
...
...
@@ -90,6 +119,7 @@ RtpProcess::RtpProcess(uint32_t ssrc) {
});
}
}
_merger
=
std
::
make_shared
<
FrameMerger
>
();
}
RtpProcess
::~
RtpProcess
()
{
...
...
@@ -101,7 +131,7 @@ RtpProcess::~RtpProcess() {
}
}
bool
RtpProcess
::
inputRtp
(
const
char
*
data
,
int
data_len
,
const
struct
sockaddr
*
addr
)
{
bool
RtpProcess
::
inputRtp
(
const
char
*
data
,
int
data_len
,
const
struct
sockaddr
*
addr
,
uint32_t
*
dts_out
)
{
GET_CONFIG
(
bool
,
check_source
,
RtpProxy
::
kCheckSource
);
//检查源是否合法
if
(
!
_addr
){
...
...
@@ -116,7 +146,11 @@ bool RtpProcess::inputRtp(const char *data, int data_len,const struct sockaddr *
}
_last_rtp_time
.
resetTime
();
return
handleOneRtp
(
0
,
_track
,(
unsigned
char
*
)
data
,
data_len
);
bool
ret
=
handleOneRtp
(
0
,
_track
,(
unsigned
char
*
)
data
,
data_len
);
if
(
dts_out
){
*
dts_out
=
_dts
;
}
return
ret
;
}
void
RtpProcess
::
onRtpSorted
(
const
RtpPacket
::
Ptr
&
rtp
,
int
)
{
...
...
@@ -156,6 +190,7 @@ void RtpProcess::onPSDecode(int stream,
int
bytes
)
{
pts
/=
90
;
dts
/=
90
;
_dts
=
dts
;
_stamps
[
codecid
].
revise
(
dts
,
pts
,
dts
,
pts
,
false
);
switch
(
codecid
)
{
...
...
@@ -176,8 +211,10 @@ void RtpProcess::onPSDecode(int stream,
if
(
_save_file_video
){
fwrite
((
uint8_t
*
)
data
,
bytes
,
1
,
_save_file_video
.
get
());
}
auto
frame
=
std
::
make_shared
<
H264FrameNoCacheAble
>
((
char
*
)
data
,
bytes
,
dts
,
pts
,
4
);
_muxer
->
inputFrame
(
frame
);
auto
frame
=
std
::
make_shared
<
H264FrameNoCacheAble
>
((
char
*
)
data
,
bytes
,
dts
,
pts
,
0
);
_merger
->
inputFrame
(
frame
,[
this
](
uint32_t
dts
,
uint32_t
pts
,
const
Buffer
::
Ptr
&
buffer
)
{
_muxer
->
inputFrame
(
std
::
make_shared
<
H264FrameNoCacheAble
>
(
buffer
->
data
(),
buffer
->
size
(),
dts
,
pts
,
4
));
});
break
;
}
...
...
@@ -196,8 +233,10 @@ void RtpProcess::onPSDecode(int stream,
if
(
_save_file_video
){
fwrite
((
uint8_t
*
)
data
,
bytes
,
1
,
_save_file_video
.
get
());
}
auto
frame
=
std
::
make_shared
<
H265FrameNoCacheAble
>
((
char
*
)
data
,
bytes
,
dts
,
pts
,
4
);
_muxer
->
inputFrame
(
frame
);
auto
frame
=
std
::
make_shared
<
H265FrameNoCacheAble
>
((
char
*
)
data
,
bytes
,
dts
,
pts
,
0
);
_merger
->
inputFrame
(
frame
,[
this
](
uint32_t
dts
,
uint32_t
pts
,
const
Buffer
::
Ptr
&
buffer
)
{
_muxer
->
inputFrame
(
std
::
make_shared
<
H265FrameNoCacheAble
>
(
buffer
->
data
(),
buffer
->
size
(),
dts
,
pts
,
4
));
});
break
;
}
...
...
src/Rtp/RtpProcess.h
查看文件 @
c353c626
...
...
@@ -39,13 +39,13 @@ using namespace mediakit;
namespace
mediakit
{
string
printSSRC
(
uint32_t
ui32Ssrc
);
class
FrameMerger
;
class
RtpProcess
:
public
RtpReceiver
,
public
RtpDecoder
,
public
PSDecoder
{
public
:
typedef
std
::
shared_ptr
<
RtpProcess
>
Ptr
;
RtpProcess
(
uint32_t
ssrc
);
~
RtpProcess
();
bool
inputRtp
(
const
char
*
data
,
int
data_len
,
const
struct
sockaddr
*
addr
);
bool
inputRtp
(
const
char
*
data
,
int
data_len
,
const
struct
sockaddr
*
addr
,
uint32_t
*
dts_out
=
nullptr
);
bool
alive
();
string
get_peer_ip
();
uint16_t
get_peer_port
();
...
...
@@ -70,8 +70,10 @@ private:
int
_codecid_video
=
0
;
int
_codecid_audio
=
0
;
MultiMediaSourceMuxer
::
Ptr
_muxer
;
std
::
shared_ptr
<
FrameMerger
>
_merger
;
Ticker
_last_rtp_time
;
map
<
int
,
Stamp
>
_stamps
;
uint32_t
_dts
=
0
;
};
}
//namespace mediakit
...
...
src/Rtp/RtpSelector.cpp
查看文件 @
c353c626
...
...
@@ -31,7 +31,7 @@ namespace mediakit{
INSTANCE_IMP
(
RtpSelector
);
bool
RtpSelector
::
inputRtp
(
const
char
*
data
,
int
data_len
,
const
struct
sockaddr
*
addr
)
{
bool
RtpSelector
::
inputRtp
(
const
char
*
data
,
int
data_len
,
const
struct
sockaddr
*
addr
,
uint32_t
*
dts_out
)
{
if
(
_last_rtp_time
.
elapsedTime
()
>
3000
){
_last_rtp_time
.
resetTime
();
onManager
();
...
...
@@ -43,7 +43,7 @@ bool RtpSelector::inputRtp(const char *data, int data_len,const struct sockaddr
}
auto
process
=
getProcess
(
ssrc
,
true
);
if
(
process
){
return
process
->
inputRtp
(
data
,
data_len
,
addr
);
return
process
->
inputRtp
(
data
,
data_len
,
addr
,
dts_out
);
}
return
false
;
}
...
...
src/Rtp/RtpSelector.h
查看文件 @
c353c626
...
...
@@ -41,7 +41,7 @@ public:
~
RtpSelector
();
static
RtpSelector
&
Instance
();
bool
inputRtp
(
const
char
*
data
,
int
data_len
,
const
struct
sockaddr
*
addr
);
bool
inputRtp
(
const
char
*
data
,
int
data_len
,
const
struct
sockaddr
*
addr
,
uint32_t
*
dts_out
=
nullptr
);
static
uint32_t
getSSRC
(
const
char
*
data
,
int
data_len
);
RtpProcess
::
Ptr
getProcess
(
uint32_t
ssrc
,
bool
makeNew
);
void
delProcess
(
uint32_t
ssrc
,
const
RtpProcess
*
ptr
);
...
...
tests/test_rtp.cpp
查看文件 @
c353c626
...
...
@@ -71,19 +71,14 @@ static bool loadFile(const char *path){
}
uint32_t
timeStamp
;
memcpy
(
&
timeStamp
,
rtp
+
4
,
4
);
timeStamp
=
ntohl
(
timeStamp
);
timeStamp
/=
90
;
RtpSelector
::
Instance
().
inputRtp
(
rtp
,
len
,
&
addr
,
&
timeStamp
);
if
(
timeStamp_last
){
auto
diff
=
timeStamp
-
timeStamp_last
;
if
(
diff
>
0
){
usleep
(
diff
*
1000
);
}
}
timeStamp_last
=
timeStamp
;
RtpSelector
::
Instance
().
inputRtp
(
rtp
,
len
,
&
addr
);
}
fclose
(
fp
);
return
true
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论