Merge branch 'master' of github.com:ZLMediaKit/ZLMediaKit

This commit is contained in:
xiongziliang 2022-04-09 10:23:33 +08:00
commit 6073175e75
4 changed files with 68 additions and 85 deletions

View File

@ -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
_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;
} }

View File

@ -444,6 +444,67 @@ protected:
CodecId _codec_id = CodecInvalid; 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对象 * Buffer对象转换成可缓存的Frame对象
*/ */

View File

@ -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){
} }
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;

View File

@ -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;