Commit 78d32702 by alexliyu7352 Committed by GitHub

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

2.修复由于丢弃sei帧导致ffplay不能正常播放
parent 75b17b3a
...@@ -22,67 +22,6 @@ namespace toolkit { ...@@ -22,67 +22,6 @@ namespace toolkit {
namespace mediakit{ 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){ Frame::Ptr Frame::getCacheAbleFrame(const Frame::Ptr &frame){
if(frame->cacheAble()){ if(frame->cacheAble()){
return frame; return frame;
...@@ -241,18 +180,6 @@ bool FrameMerger::inputFrame(const Frame::Ptr &frame, const onOutput &cb, Buffer ...@@ -241,18 +180,6 @@ bool FrameMerger::inputFrame(const Frame::Ptr &frame, const onOutput &cb, Buffer
_have_decode_able_frame = false; _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()) { if (frame->decodeAble()) {
_have_decode_able_frame = true; _have_decode_able_frame = true;
} }
......
...@@ -445,6 +445,67 @@ protected: ...@@ -445,6 +445,67 @@ protected:
}; };
/** /**
* 该对象的功能是把一个不可缓存的帧转换成可缓存的帧
*/
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对象 * 该对象可以把Buffer对象转换成可缓存的Frame对象
*/ */
template <typename Parent> template <typename Parent>
......
...@@ -184,23 +184,22 @@ bool H264Track::inputFrame_l(const Frame::Ptr &frame){ ...@@ -184,23 +184,22 @@ bool H264Track::inputFrame_l(const Frame::Ptr &frame){
} }
case H264Frame::NAL_PPS: { case H264Frame::NAL_PPS: {
_pps = string(frame->data() + frame->prefixSize(), frame->size() - frame->prefixSize()); _pps = string(frame->data() + frame->prefixSize(), frame->size() - frame->prefixSize());
break; _insert_config_frame = true;
}
case H264Frame::NAL_AUD: {
//忽略AUD帧;
ret = false;
break; break;
} }
default: 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); insertConfigFrame(frame);
_insert_config_frame = false;
} }
ret = VideoTrack::inputFrame(frame); ret = VideoTrack::inputFrame(frame);
break; break;
} }
_is_idr = type == H264Frame::NAL_IDR;
if (_width == 0 && ready()) { if (_width == 0 && ready()) {
onReady(); onReady();
} }
...@@ -208,10 +207,6 @@ bool H264Track::inputFrame_l(const Frame::Ptr &frame){ ...@@ -208,10 +207,6 @@ bool H264Track::inputFrame_l(const Frame::Ptr &frame){
} }
void H264Track::insertConfigFrame(const Frame::Ptr &frame){ void H264Track::insertConfigFrame(const Frame::Ptr &frame){
if(_is_idr){
return;
}
if(!_sps.empty()){ if(!_sps.empty()){
auto spsFrame = FrameImp::create<H264Frame>(); auto spsFrame = FrameImp::create<H264Frame>();
spsFrame->_prefix_size = 4; spsFrame->_prefix_size = 4;
......
...@@ -138,7 +138,7 @@ private: ...@@ -138,7 +138,7 @@ private:
void insertConfigFrame(const Frame::Ptr &frame); void insertConfigFrame(const Frame::Ptr &frame);
private: private:
bool _is_idr = false; bool _insert_config_frame = false;
int _width = 0; int _width = 0;
int _height = 0; int _height = 0;
float _fps = 0; float _fps = 0;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论