mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-26 04:31:37 +08:00
parent
75b17b3a6a
commit
78d32702e2
@ -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;
|
||||
}
|
||||
|
@ -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对象
|
||||
*/
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user