修复由于识别不出关键帧而导致hls不能切片. (#1551)

2.修复由于丢弃sei帧导致ffplay不能正常播放
This commit is contained in:
alexliyu7352 2022-04-09 10:22:41 +08:00 committed by GitHub
parent 75b17b3a6a
commit 78d32702e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 68 additions and 85 deletions

View File

@ -22,67 +22,6 @@ namespace toolkit {
namespace mediakit{
/**
*
*/
class FrameCacheAble : public FrameFromPtr {
public:
typedef std::shared_ptr<FrameCacheAble> Ptr;
FrameCacheAble(const Frame::Ptr &frame){
if (frame->cacheAble()) {
_frame = frame;
_ptr = frame->data();
} else {
_buffer = FrameImp::create();
_buffer->_buffer.assign(frame->data(), frame->size());
_ptr = _buffer->data();
}
_size = frame->size();
_dts = frame->dts();
_pts = frame->pts();
_prefix_size = frame->prefixSize();
_codec_id = frame->getCodecId();
_key = frame->keyFrame();
_config = frame->configFrame();
_drop_able = frame->dropAble();
_decode_able = frame->decodeAble();
}
~FrameCacheAble() override = default;
/**
*
*/
bool cacheAble() const override {
return true;
}
bool keyFrame() const override{
return _key;
}
bool configFrame() const override{
return _config;
}
bool dropAble() const override {
return _drop_able;
}
bool decodeAble() const override {
return _decode_able;
}
private:
bool _key;
bool _config;
bool _drop_able;
bool _decode_able;
Frame::Ptr _frame;
FrameImp::Ptr _buffer;
};
Frame::Ptr Frame::getCacheAbleFrame(const Frame::Ptr &frame){
if(frame->cacheAble()){
return frame;
@ -241,18 +180,6 @@ bool FrameMerger::inputFrame(const Frame::Ptr &frame, const onOutput &cb, Buffer
_have_decode_able_frame = false;
}
switch (_type) {
case h264_prefix:
case mp4_nal_size: {
if (frame->dropAble()) {
//h264头和mp4头模式过滤无效的帧
return false;
}
break;
}
default: break;
}
if (frame->decodeAble()) {
_have_decode_able_frame = true;
}

View File

@ -444,6 +444,67 @@ protected:
CodecId _codec_id = CodecInvalid;
};
/**
*
*/
class FrameCacheAble : public FrameFromPtr {
public:
typedef std::shared_ptr<FrameCacheAble> Ptr;
FrameCacheAble(const Frame::Ptr &frame, bool force_key_frame = false) {
if (frame->cacheAble()) {
_frame = frame;
_ptr = frame->data();
} else {
_buffer = FrameImp::create();
_buffer->_buffer.assign(frame->data(), frame->size());
_ptr = _buffer->data();
}
_size = frame->size();
_dts = frame->dts();
_pts = frame->pts();
_prefix_size = frame->prefixSize();
_codec_id = frame->getCodecId();
_key = force_key_frame ? true : frame->keyFrame();
_config = frame->configFrame();
_drop_able = frame->dropAble();
_decode_able = frame->decodeAble();
}
~FrameCacheAble() override = default;
/**
*
*/
bool cacheAble() const override {
return true;
}
bool keyFrame() const override{
return _key;
}
bool configFrame() const override{
return _config;
}
bool dropAble() const override {
return _drop_able;
}
bool decodeAble() const override {
return _decode_able;
}
private:
bool _key;
bool _config;
bool _drop_able;
bool _decode_able;
Frame::Ptr _frame;
FrameImp::Ptr _buffer;
};
/**
* Buffer对象转换成可缓存的Frame对象
*/

View File

@ -184,23 +184,22 @@ bool H264Track::inputFrame_l(const Frame::Ptr &frame){
}
case H264Frame::NAL_PPS: {
_pps = string(frame->data() + frame->prefixSize(), frame->size() - frame->prefixSize());
break;
}
case H264Frame::NAL_AUD: {
//忽略AUD帧;
ret = false;
_insert_config_frame = true;
break;
}
default:
if (frame->keyFrame()) {
if (_insert_config_frame && !frame->dropAble()) {
if (!frame->keyFrame()) {
const_cast<Frame::Ptr &>(frame) = std::make_shared<FrameCacheAble>(frame, true);
}
insertConfigFrame(frame);
_insert_config_frame = false;
}
ret = VideoTrack::inputFrame(frame);
break;
}
_is_idr = type == H264Frame::NAL_IDR;
if (_width == 0 && ready()) {
onReady();
}
@ -208,10 +207,6 @@ bool H264Track::inputFrame_l(const Frame::Ptr &frame){
}
void H264Track::insertConfigFrame(const Frame::Ptr &frame){
if(_is_idr){
return;
}
if(!_sps.empty()){
auto spsFrame = FrameImp::create<H264Frame>();
spsFrame->_prefix_size = 4;

View File

@ -138,7 +138,7 @@ private:
void insertConfigFrame(const Frame::Ptr &frame);
private:
bool _is_idr = false;
bool _insert_config_frame = false;
int _width = 0;
int _height = 0;
float _fps = 0;