mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2026-06-30 23:02:24 +08:00
优化代码
This commit is contained in:
@@ -646,7 +646,7 @@ bool MediaSourceEventInterceptor::stopSendRtp(MediaSource &sender){
|
||||
|
||||
/////////////////////////////////////FlushPolicy//////////////////////////////////////
|
||||
|
||||
static bool isFlushAble_default(bool is_video, uint32_t last_stamp, uint32_t new_stamp, int cache_size) {
|
||||
static bool isFlushAble_default(bool is_video, uint64_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, uint32_t last_stamp, uint32_t new_stamp, int cache_size, int merge_ms) {
|
||||
static bool isFlushAble_merge(bool is_video, uint64_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, uint32_t new_stamp, int cache_size) {
|
||||
bool FlushPolicy::isFlushAble(bool is_video, bool is_key, uint64_t new_stamp, int cache_size) {
|
||||
bool flush_flag = false;
|
||||
if (is_key && is_video) {
|
||||
//遇到关键帧flush掉前面的数据,确保关键帧为该组数据的第一帧,确保GOP缓存有效
|
||||
|
||||
@@ -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:
|
||||
uint32_t _last_stamp[2] = {0, 0};
|
||||
uint64_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();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user