rtmp解复用支持无内存拷贝

hls生成支持输入无0x 00 00 01的H264/H265数据
This commit is contained in:
xiongziliang 2019-07-25 12:09:36 +08:00
parent d2a889b463
commit 6922d82c65
4 changed files with 31 additions and 6 deletions

@ -1 +1 @@
Subproject commit 0e726dd4e06ab4ed3723deaf3f73386e100bb10d Subproject commit e399b93802610dcf574ff64bcb7677572cd028c1

View File

@ -92,6 +92,11 @@ public:
}; };
/**
* H264类
* Frame类
* DevChannel中有使用
*/
class H264FrameNoCacheAble : public FrameNoCacheAble { class H264FrameNoCacheAble : public FrameNoCacheAble {
public: public:
typedef std::shared_ptr<H264FrameNoCacheAble> Ptr; typedef std::shared_ptr<H264FrameNoCacheAble> Ptr;
@ -117,17 +122,26 @@ public:
} }
}; };
/**
* H264Frame类中可以有多个帧 0x 00 00 01
* ZLMediaKit会先把这种复合帧split成单个帧然后再处理
* H264FrameSubFrame
*
*/
class H264FrameSubFrame : public H264FrameNoCacheAble{ class H264FrameSubFrame : public H264FrameNoCacheAble{
public: public:
typedef std::shared_ptr<H264FrameSubFrame> Ptr; typedef std::shared_ptr<H264FrameSubFrame> Ptr;
H264FrameSubFrame(const Frame::Ptr &strongRef, H264FrameSubFrame(const Frame::Ptr &parent_frame,
char *ptr, char *ptr,
uint32_t size, uint32_t size,
int prefixeSize) : H264FrameNoCacheAble(ptr,size,strongRef->dts(),strongRef->pts(),prefixeSize){ int prefixeSize) : H264FrameNoCacheAble(ptr,size,parent_frame->dts(),parent_frame->pts(),prefixeSize){
_strongRef = strongRef; _parent_frame = parent_frame;
}
bool cacheAble() const override {
return _parent_frame->cacheAble();
} }
private: private:
Frame::Ptr _strongRef; Frame::Ptr _parent_frame;
}; };
/** /**

View File

@ -108,6 +108,7 @@ inline void H264RtmpDecoder::onGetH264_l(const char* pcData, int iLen, uint32_t
} }
} }
inline void H264RtmpDecoder::onGetH264(const char* pcData, int iLen, uint32_t dts,uint32_t pts) { inline void H264RtmpDecoder::onGetH264(const char* pcData, int iLen, uint32_t dts,uint32_t pts) {
#if 0
_h264frame->type = H264_TYPE(pcData[0]); _h264frame->type = H264_TYPE(pcData[0]);
_h264frame->timeStamp = dts; _h264frame->timeStamp = dts;
_h264frame->ptsStamp = pts; _h264frame->ptsStamp = pts;
@ -117,6 +118,11 @@ inline void H264RtmpDecoder::onGetH264(const char* pcData, int iLen, uint32_t dt
//写入环形缓存 //写入环形缓存
RtmpCodec::inputFrame(_h264frame); RtmpCodec::inputFrame(_h264frame);
_h264frame = obtainFrame(); _h264frame = obtainFrame();
#else
//防止内存拷贝这样产生的264帧不会有0x00 00 01头
auto frame = std::make_shared<H264FrameNoCacheAble>((char *)pcData,iLen,dts,pts,0);
RtmpCodec::inputFrame(frame);
#endif
} }

View File

@ -70,7 +70,12 @@ void TsMuxer::inputFrame(const Frame::Ptr &frame) {
if(_frameCached.size() != 1){ if(_frameCached.size() != 1){
string merged; string merged;
_frameCached.for_each([&](const Frame::Ptr &frame){ _frameCached.for_each([&](const Frame::Ptr &frame){
merged.append(frame->data(),frame->size()); if(frame->prefixSize()){
merged.append(frame->data(),frame->size());
} else{
merged.append("\x00\x00\x00\x01",4);
merged.append(frame->data(),frame->size());
}
}); });
merged_frame = std::make_shared<BufferString>(std::move(merged)); merged_frame = std::make_shared<BufferString>(std::move(merged));
} }