精简代码

This commit is contained in:
xiongziliang 2019-07-03 16:42:20 +08:00
parent e36194aec3
commit 5dce8eccde
2 changed files with 35 additions and 50 deletions

View File

@ -308,27 +308,23 @@ private:
} }
if(!_sps.empty()){ if(!_sps.empty()){
if(!_spsFrame){ auto spsFrame = std::make_shared<H264Frame>();
_spsFrame = std::make_shared<H264Frame>(); spsFrame->type = H264Frame::NAL_SPS;
_spsFrame->type = H264Frame::NAL_SPS; spsFrame->iPrefixSize = 4;
_spsFrame->iPrefixSize = 4; spsFrame->buffer.assign("\x0\x0\x0\x1",4);
} spsFrame->buffer.append(_sps);
_spsFrame->buffer.assign("\x0\x0\x0\x1",4); spsFrame->timeStamp = frame->stamp();
_spsFrame->buffer.append(_sps); VideoTrack::inputFrame(spsFrame);
_spsFrame->timeStamp = frame->stamp();
VideoTrack::inputFrame(_spsFrame);
} }
if(!_pps.empty()){ if(!_pps.empty()){
if(!_ppsFrame) { auto ppsFrame = std::make_shared<H264Frame>();
_ppsFrame = std::make_shared<H264Frame>(); ppsFrame->type = H264Frame::NAL_PPS;
_ppsFrame->type = H264Frame::NAL_PPS; ppsFrame->iPrefixSize = 4;
_ppsFrame->iPrefixSize = 4; ppsFrame->buffer.assign("\x0\x0\x0\x1",4);
} ppsFrame->buffer.append(_pps);
_ppsFrame->buffer.assign("\x0\x0\x0\x1",4); ppsFrame->timeStamp = frame->stamp();
_ppsFrame->buffer.append(_pps); VideoTrack::inputFrame(ppsFrame);
_ppsFrame->timeStamp = frame->stamp();
VideoTrack::inputFrame(_ppsFrame);
} }
} }
private: private:
@ -338,8 +334,6 @@ private:
int _height = 0; int _height = 0;
float _fps = 0; float _fps = 0;
bool _last_frame_is_idr = false; bool _last_frame_is_idr = false;
H264Frame::Ptr _spsFrame;
H264Frame::Ptr _ppsFrame;
}; };

View File

@ -264,47 +264,38 @@ private:
return; return;
} }
if(!_vps.empty()){ if(!_vps.empty()){
if (!_vpsFrame) { auto vpsFrame = std::make_shared<H265Frame>();
_vpsFrame = std::make_shared<H265Frame>(); vpsFrame->type = H265Frame::NAL_VPS;
_vpsFrame->type = H265Frame::NAL_VPS; vpsFrame->iPrefixSize = 4;
_vpsFrame->iPrefixSize = 4; vpsFrame->buffer.assign("\x0\x0\x0\x1", 4);
} vpsFrame->buffer.append(_vps);
_vpsFrame->buffer.assign("\x0\x0\x0\x1", 4); vpsFrame->timeStamp = frame->stamp();
_vpsFrame->buffer.append(_vps); VideoTrack::inputFrame(vpsFrame);
_vpsFrame->timeStamp = frame->stamp();
VideoTrack::inputFrame(_vpsFrame);
} }
if (!_sps.empty()) { if (!_sps.empty()) {
if (!_spsFrame) { auto spsFrame = std::make_shared<H265Frame>();
_spsFrame = std::make_shared<H265Frame>(); spsFrame->type = H265Frame::NAL_SPS;
_spsFrame->type = H265Frame::NAL_SPS; spsFrame->iPrefixSize = 4;
_spsFrame->iPrefixSize = 4; spsFrame->buffer.assign("\x0\x0\x0\x1", 4);
} spsFrame->buffer.append(_sps);
_spsFrame->buffer.assign("\x0\x0\x0\x1", 4); spsFrame->timeStamp = frame->stamp();
_spsFrame->buffer.append(_sps); VideoTrack::inputFrame(spsFrame);
_spsFrame->timeStamp = frame->stamp();
VideoTrack::inputFrame(_spsFrame);
} }
if (!_pps.empty()) { if (!_pps.empty()) {
if (!_ppsFrame) { auto ppsFrame = std::make_shared<H265Frame>();
_ppsFrame = std::make_shared<H265Frame>(); ppsFrame->type = H265Frame::NAL_PPS;
_ppsFrame->type = H265Frame::NAL_PPS; ppsFrame->iPrefixSize = 4;
_ppsFrame->iPrefixSize = 4; ppsFrame->buffer.assign("\x0\x0\x0\x1", 4);
} ppsFrame->buffer.append(_pps);
_ppsFrame->buffer.assign("\x0\x0\x0\x1", 4); ppsFrame->timeStamp = frame->stamp();
_ppsFrame->buffer.append(_pps); VideoTrack::inputFrame(ppsFrame);
_ppsFrame->timeStamp = frame->stamp();
VideoTrack::inputFrame(_ppsFrame);
} }
} }
private: private:
string _vps; string _vps;
string _sps; string _sps;
string _pps; string _pps;
H265Frame::Ptr _vpsFrame;
H265Frame::Ptr _spsFrame;
H265Frame::Ptr _ppsFrame;
bool _last_frame_is_idr = false; bool _last_frame_is_idr = false;
}; };