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
02c4aa3f
Commit
02c4aa3f
authored
Oct 24, 2020
by
xiongziliang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化代码
parent
46ee7f36
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
24 行增加
和
48 行删除
+24
-48
src/Common/MediaSource.cpp
+3
-3
src/Common/MediaSource.h
+4
-12
src/FMP4/FMP4MediaSource.h
+4
-14
src/Rtmp/RtmpMediaSource.h
+2
-1
src/Rtsp/RtspMediaSource.h
+2
-1
src/Rtsp/RtspSession.h
+5
-3
src/TS/TSMediaSource.h
+4
-14
没有找到文件。
src/Common/MediaSource.cpp
查看文件 @
02c4aa3f
...
...
@@ -646,7 +646,7 @@ bool MediaSourceEventInterceptor::stopSendRtp(MediaSource &sender){
/////////////////////////////////////FlushPolicy//////////////////////////////////////
static
bool
isFlushAble_default
(
bool
is_video
,
uint
32_t
last_stamp
,
uint32
_t
new_stamp
,
int
cache_size
)
{
static
bool
isFlushAble_default
(
bool
is_video
,
uint
64_t
last_stamp
,
uint64
_t
new_stamp
,
int
cache_size
)
{
if
(
new_stamp
+
500
<
last_stamp
)
{
//时间戳回退比较大(可能seek中),由于rtp中时间戳是pts,是可能存在一定程度的回退的
return
true
;
...
...
@@ -656,7 +656,7 @@ static bool isFlushAble_default(bool is_video, uint32_t last_stamp, uint32_t new
return
last_stamp
!=
new_stamp
||
cache_size
>=
1024
;
}
static
bool
isFlushAble_merge
(
bool
is_video
,
uint
32_t
last_stamp
,
uint32
_t
new_stamp
,
int
cache_size
,
int
merge_ms
)
{
static
bool
isFlushAble_merge
(
bool
is_video
,
uint
64_t
last_stamp
,
uint64
_t
new_stamp
,
int
cache_size
,
int
merge_ms
)
{
if
(
new_stamp
+
500
<
last_stamp
)
{
//时间戳回退比较大(可能seek中),由于rtp中时间戳是pts,是可能存在一定程度的回退的
return
true
;
...
...
@@ -672,7 +672,7 @@ static bool isFlushAble_merge(bool is_video, uint32_t last_stamp, uint32_t new_s
return
cache_size
>=
1024
;
}
bool
FlushPolicy
::
isFlushAble
(
bool
is_video
,
bool
is_key
,
uint
32
_t
new_stamp
,
int
cache_size
)
{
bool
FlushPolicy
::
isFlushAble
(
bool
is_video
,
bool
is_key
,
uint
64
_t
new_stamp
,
int
cache_size
)
{
bool
flush_flag
=
false
;
if
(
is_key
&&
is_video
)
{
//遇到关键帧flush掉前面的数据,确保关键帧为该组数据的第一帧,确保GOP缓存有效
...
...
src/Common/MediaSource.h
查看文件 @
02c4aa3f
...
...
@@ -301,18 +301,10 @@ public:
FlushPolicy
()
=
default
;
~
FlushPolicy
()
=
default
;
uint32_t
getStamp
(
const
RtpPacket
::
Ptr
&
packet
)
{
return
packet
->
timeStamp
;
}
uint32_t
getStamp
(
const
RtmpPacket
::
Ptr
&
packet
)
{
return
packet
->
time_stamp
;
}
bool
isFlushAble
(
bool
is_video
,
bool
is_key
,
uint32_t
new_stamp
,
int
cache_size
);
bool
isFlushAble
(
bool
is_video
,
bool
is_key
,
uint64_t
new_stamp
,
int
cache_size
);
private
:
uint
32
_t
_last_stamp
[
2
]
=
{
0
,
0
};
uint
64
_t
_last_stamp
[
2
]
=
{
0
,
0
};
};
/// 合并写缓存模板
...
...
@@ -328,8 +320,8 @@ public:
virtual
~
PacketCache
()
=
default
;
void
inputPacket
(
bool
is_video
,
std
::
shared_ptr
<
packet
>
pkt
,
bool
key_pos
)
{
if
(
_policy
.
isFlushAble
(
is_video
,
key_pos
,
_policy
.
getStamp
(
pkt
)
,
_cache
->
size
()))
{
void
inputPacket
(
uint64_t
stamp
,
bool
is_video
,
std
::
shared_ptr
<
packet
>
pkt
,
bool
key_pos
)
{
if
(
_policy
.
isFlushAble
(
is_video
,
key_pos
,
stamp
,
_cache
->
size
()))
{
flushAll
();
}
...
...
src/FMP4/FMP4MediaSource.h
查看文件 @
02c4aa3f
...
...
@@ -30,19 +30,8 @@ public:
uint32_t
time_stamp
=
0
;
};
//FMP4直播合并写策略类
class
FMP4FlushPolicy
:
public
FlushPolicy
{
public
:
FMP4FlushPolicy
()
=
default
;
~
FMP4FlushPolicy
()
=
default
;
uint32_t
getStamp
(
const
FMP4Packet
::
Ptr
&
packet
)
{
return
packet
->
time_stamp
;
}
};
//FMP4直播源
class
FMP4MediaSource
:
public
MediaSource
,
public
RingDelegate
<
FMP4Packet
::
Ptr
>
,
public
PacketCache
<
FMP4Packet
,
FMP4FlushPolicy
>
{
class
FMP4MediaSource
:
public
MediaSource
,
public
RingDelegate
<
FMP4Packet
::
Ptr
>
,
public
PacketCache
<
FMP4Packet
>
{
public
:
using
Ptr
=
std
::
shared_ptr
<
FMP4MediaSource
>
;
using
RingDataType
=
std
::
shared_ptr
<
List
<
FMP4Packet
::
Ptr
>
>
;
...
...
@@ -100,14 +89,15 @@ public:
_have_video
=
true
;
}
_speed
+=
packet
->
size
();
PacketCache
<
FMP4Packet
,
FMP4FlushPolicy
>::
inputPacket
(
true
,
std
::
move
(
packet
),
key
);
auto
stamp
=
packet
->
time_stamp
;
PacketCache
<
FMP4Packet
>::
inputPacket
(
stamp
,
true
,
std
::
move
(
packet
),
key
);
}
/**
* 情况GOP缓存
*/
void
clearCache
()
override
{
PacketCache
<
FMP4Packet
,
FMP4FlushPolicy
>::
clearCache
();
PacketCache
<
FMP4Packet
>::
clearCache
();
_ring
->
clearCache
();
}
...
...
src/Rtmp/RtmpMediaSource.h
查看文件 @
02c4aa3f
...
...
@@ -154,7 +154,8 @@ public:
}
bool
key
=
pkt
->
isVideoKeyFrame
();
bool
is_video
=
pkt
->
type_id
==
MSG_VIDEO
;
PacketCache
<
RtmpPacket
>::
inputPacket
(
is_video
,
std
::
move
(
pkt
),
key
);
auto
stamp
=
pkt
->
time_stamp
;
PacketCache
<
RtmpPacket
>::
inputPacket
(
stamp
,
is_video
,
std
::
move
(
pkt
),
key
);
}
/**
...
...
src/Rtsp/RtspMediaSource.h
查看文件 @
02c4aa3f
...
...
@@ -183,7 +183,8 @@ public:
}
}
bool
is_video
=
rtp
->
type
==
TrackVideo
;
PacketCache
<
RtpPacket
>::
inputPacket
(
is_video
,
std
::
move
(
rtp
),
keyPos
);
auto
stamp
=
rtp
->
timeStamp
;
PacketCache
<
RtpPacket
>::
inputPacket
(
stamp
,
is_video
,
std
::
move
(
rtp
),
keyPos
);
}
void
clearCache
()
override
{
...
...
src/Rtsp/RtspSession.h
查看文件 @
02c4aa3f
...
...
@@ -37,17 +37,19 @@ class RtspSession;
class
BufferRtp
:
public
Buffer
{
public
:
typedef
std
::
shared_ptr
<
BufferRtp
>
Ptr
;
BufferRtp
(
const
RtpPacket
::
Ptr
&
pkt
,
uint32_t
offset
=
0
)
:
_rtp
(
pkt
),
_offset
(
offset
)
{}
virtual
~
BufferRtp
()
{}
BufferRtp
(
Buffer
::
Ptr
pkt
,
uint32_t
offset
=
0
)
:
_rtp
(
std
::
move
(
pkt
)),
_offset
(
offset
)
{}
~
BufferRtp
()
override
{}
char
*
data
()
const
override
{
return
(
char
*
)
_rtp
->
data
()
+
_offset
;
}
uint32_t
size
()
const
override
{
return
_rtp
->
size
()
-
_offset
;
}
private
:
RtpPacket
::
Ptr
_rtp
;
Buffer
::
Ptr
_rtp
;
uint32_t
_offset
;
};
...
...
src/TS/TSMediaSource.h
查看文件 @
02c4aa3f
...
...
@@ -30,19 +30,8 @@ public:
uint32_t
time_stamp
=
0
;
};
//TS直播合并写策略类
class
TSFlushPolicy
:
public
FlushPolicy
{
public
:
TSFlushPolicy
()
=
default
;
~
TSFlushPolicy
()
=
default
;
uint32_t
getStamp
(
const
TSPacket
::
Ptr
&
packet
)
{
return
packet
->
time_stamp
;
}
};
//TS直播源
class
TSMediaSource
:
public
MediaSource
,
public
RingDelegate
<
TSPacket
::
Ptr
>
,
public
PacketCache
<
TSPacket
,
TSFlushPolicy
>
{
class
TSMediaSource
:
public
MediaSource
,
public
RingDelegate
<
TSPacket
::
Ptr
>
,
public
PacketCache
<
TSPacket
>
{
public
:
using
PoolType
=
ResourcePool
<
TSPacket
>
;
using
Ptr
=
std
::
shared_ptr
<
TSMediaSource
>
;
...
...
@@ -83,14 +72,15 @@ public:
if
(
key
)
{
_have_video
=
true
;
}
PacketCache
<
TSPacket
,
TSFlushPolicy
>::
inputPacket
(
true
,
std
::
move
(
packet
),
key
);
auto
stamp
=
packet
->
time_stamp
;
PacketCache
<
TSPacket
>::
inputPacket
(
stamp
,
true
,
std
::
move
(
packet
),
key
);
}
/**
* 情况GOP缓存
*/
void
clearCache
()
override
{
PacketCache
<
TSPacket
,
TSFlushPolicy
>::
clearCache
();
PacketCache
<
TSPacket
>::
clearCache
();
_ring
->
clearCache
();
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论