优化SEI/AUD帧处理逻辑

This commit is contained in:
xia-chu
2025-06-29 18:00:47 +08:00
parent 9a7cca1ad9
commit a35444f27e
3 changed files with 20 additions and 2 deletions

View File

@@ -153,7 +153,11 @@ bool H264Track::ready() const {
bool H264Track::inputFrame(const Frame::Ptr &frame) {
using H264FrameInternal = FrameInternal<H264FrameNoCacheAble>;
int type = H264_TYPE(frame->data()[frame->prefixSize()]);
if (type == H264Frame::NAL_AUD) {
// AUD帧丢弃
return false;
}
if ((type == H264Frame::NAL_B_P || type == H264Frame::NAL_IDR) && ready()) {
return inputFrame_l(frame);
}

View File

@@ -205,7 +205,11 @@ bool FrameMerger::willFlush(const Frame::Ptr &frame) const{
case mp4_nal_size:
case h264_prefix: {
if (!_have_decode_able_frame) {
if (frame->dropAble() && !_have_config_frame) {
// 遇到SEI帧且未缓存配置帧flush之前的帧
return true;
}
if (!_have_decode_able_frame && !_have_drop_able_frame) {
// 缓存中没有有效的能解码的帧所以这次不flush [AUTO-TRANSLATED:5d860722]
// There are no valid frames that can be decoded in the cache, so no flush this time.
return _frame_cache.size() > kMaxFrameCacheSize;
@@ -290,6 +294,8 @@ bool FrameMerger::inputFrame(const Frame::Ptr &frame, onOutput cb, BufferLikeStr
cb(back->dts(), back->pts(), merged_frame, have_key_frame);
_frame_cache.clear();
_have_decode_able_frame = false;
_have_drop_able_frame = false;
_have_config_frame = false;
}
if (!frame) {
@@ -299,6 +305,12 @@ bool FrameMerger::inputFrame(const Frame::Ptr &frame, onOutput cb, BufferLikeStr
if (frame->decodeAble()) {
_have_decode_able_frame = true;
}
if (frame->dropAble()) {
_have_drop_able_frame = true;
}
if (frame->configFrame()) {
_have_config_frame = true;
}
_cb = std::move(cb);
_frame_cache.emplace_back(Frame::getCacheAbleFrame(frame));
return true;

View File

@@ -660,6 +660,8 @@ private:
private:
int _type;
bool _have_decode_able_frame = false;
bool _have_drop_able_frame = false;
bool _have_config_frame = false;
onOutput _cb;
toolkit::List<Frame::Ptr> _frame_cache;
};