Commit 2e74d5c9 by xiongziliang

修复合并写相关bug: #282

parent 3cdc0dd9
...@@ -486,14 +486,22 @@ static bool isFlushAble_merge(bool is_audio, uint32_t last_stamp, uint32_t new_s ...@@ -486,14 +486,22 @@ static bool isFlushAble_merge(bool is_audio, uint32_t last_stamp, uint32_t new_s
return cache_size > 20; return cache_size > 20;
} }
bool FlushPolicy::isFlushAble(uint32_t last_stamp, uint32_t new_stamp, int cache_size) { bool FlushPolicy::isFlushAble(uint32_t new_stamp, int cache_size) {
GET_CONFIG(bool,ultraLowDelay, General::kUltraLowDelay); bool ret = false;
GET_CONFIG(int,mergeWriteMS, General::kMergeWriteMS); GET_CONFIG(bool, ultraLowDelay, General::kUltraLowDelay);
if(ultraLowDelay || mergeWriteMS <= 0){ GET_CONFIG(int, mergeWriteMS, General::kMergeWriteMS);
if (ultraLowDelay || mergeWriteMS <= 0) {
//关闭了合并写或者合并写阈值小于等于0 //关闭了合并写或者合并写阈值小于等于0
return isFlushAble_default(_is_audio, last_stamp, new_stamp, cache_size); ret = isFlushAble_default(_is_audio, _last_stamp, new_stamp, cache_size);
} else {
ret = isFlushAble_merge(_is_audio, _last_stamp, new_stamp, cache_size, mergeWriteMS);
}
if (ret) {
// DebugL << _is_audio << " " << _last_stamp << " " << new_stamp;
_last_stamp = new_stamp;
} }
return isFlushAble_merge(_is_audio, last_stamp, new_stamp, cache_size,mergeWriteMS); return ret;
} }
} /* namespace mediakit */ } /* namespace mediakit */
\ No newline at end of file
...@@ -173,9 +173,10 @@ public: ...@@ -173,9 +173,10 @@ public:
return packet->timeStamp; return packet->timeStamp;
} }
bool isFlushAble(uint32_t last_stamp, uint32_t new_stamp, int cache_size); bool isFlushAble(uint32_t new_stamp, int cache_size);
private: private:
bool _is_audio; bool _is_audio;
uint32_t _last_stamp= 0;
}; };
/// 视频合并写缓存模板 /// 视频合并写缓存模板
...@@ -192,14 +193,12 @@ public: ...@@ -192,14 +193,12 @@ public:
virtual ~VideoPacketCache() = default; virtual ~VideoPacketCache() = default;
void inputVideo(const std::shared_ptr<packet> &rtp, bool key_pos) { void inputVideo(const std::shared_ptr<packet> &rtp, bool key_pos) {
auto new_stamp = _policy.getStamp(rtp); if (_policy.isFlushAble(_policy.getStamp(rtp), _cache->size())) {
if (_policy.isFlushAble(_last_stamp, new_stamp, _cache->size())) {
flushAll(); flushAll();
} }
//追加数据到最后 //追加数据到最后
_cache->emplace_back(rtp); _cache->emplace_back(rtp);
_last_stamp = new_stamp;
if (key_pos) { if (key_pos) {
_key_pos = key_pos; _key_pos = key_pos;
} }
...@@ -220,7 +219,6 @@ private: ...@@ -220,7 +219,6 @@ private:
private: private:
policy _policy; policy _policy;
std::shared_ptr<packet_list> _cache; std::shared_ptr<packet_list> _cache;
uint32_t _last_stamp = 0;
bool _key_pos = false; bool _key_pos = false;
}; };
...@@ -238,13 +236,11 @@ public: ...@@ -238,13 +236,11 @@ public:
virtual ~AudioPacketCache() = default; virtual ~AudioPacketCache() = default;
void inputAudio(const std::shared_ptr<packet> &rtp) { void inputAudio(const std::shared_ptr<packet> &rtp) {
auto new_stamp = _policy.getStamp(rtp); if (_policy.isFlushAble(_policy.getStamp(rtp), _cache->size())) {
if (_policy.isFlushAble(_last_stamp, new_stamp, _cache->size())) {
flushAll(); flushAll();
} }
//追加数据到最后 //追加数据到最后
_cache->emplace_back(rtp); _cache->emplace_back(rtp);
_last_stamp = new_stamp;
} }
virtual void onFlushAudio(std::shared_ptr<packet_list> &) = 0; virtual void onFlushAudio(std::shared_ptr<packet_list> &) = 0;
...@@ -261,7 +257,6 @@ private: ...@@ -261,7 +257,6 @@ private:
private: private:
policy _policy; policy _policy;
std::shared_ptr<packet_list> _cache; std::shared_ptr<packet_list> _cache;
uint32_t _last_stamp = 0;
}; };
} /* namespace mediakit */ } /* namespace mediakit */
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论