diff --git a/src/Common/Device.cpp b/src/Common/Device.cpp index 71f42b39..37a0056b 100644 --- a/src/Common/Device.cpp +++ b/src/Common/Device.cpp @@ -78,14 +78,6 @@ void DevChannel::inputH264(const char *data, int len, uint32_t dts, uint32_t pts if(pts == 0){ pts = dts; } - int prefixeSize; - if (memcmp("\x00\x00\x00\x01", data, 4) == 0) { - prefixeSize = 4; - } else if (memcmp("\x00\x00\x01", data, 3) == 0) { - prefixeSize = 3; - } else { - prefixeSize = 0; - } //由于rtmp/hls/mp4需要缓存时间戳相同的帧, //所以使用FrameNoCacheAble类型的帧反而会在转换成FrameCacheAble时多次内存拷贝 @@ -93,9 +85,8 @@ void DevChannel::inputH264(const char *data, int len, uint32_t dts, uint32_t pts H264Frame::Ptr frame = std::make_shared(); frame->_dts = dts; frame->_pts = pts; - frame->_buffer.assign("\x00\x00\x00\x01",4); - frame->_buffer.append(data + prefixeSize, len - prefixeSize); - frame->_prefix_size = 4; + frame->_buffer.assign(data, len); + frame->_prefix_size = prefixSize(data,len); inputFrame(frame); } @@ -106,14 +97,6 @@ void DevChannel::inputH265(const char *data, int len, uint32_t dts, uint32_t pts if(pts == 0){ pts = dts; } - int prefixeSize; - if (memcmp("\x00\x00\x00\x01", data, 4) == 0) { - prefixeSize = 4; - } else if (memcmp("\x00\x00\x01", data, 3) == 0) { - prefixeSize = 3; - } else { - prefixeSize = 0; - } //由于rtmp/hls/mp4需要缓存时间戳相同的帧, //所以使用FrameNoCacheAble类型的帧反而会在转换成FrameCacheAble时多次内存拷贝 @@ -121,9 +104,8 @@ void DevChannel::inputH265(const char *data, int len, uint32_t dts, uint32_t pts H265Frame::Ptr frame = std::make_shared(); frame->_dts = dts; frame->_pts = pts; - frame->_buffer.assign("\x00\x00\x00\x01",4); - frame->_buffer.append(data + prefixeSize, len - prefixeSize); - frame->_prefix_size = 4; + frame->_buffer.assign(data, len); + frame->_prefix_size = prefixSize(data,len); inputFrame(frame); } diff --git a/src/Extension/H264.cpp b/src/Extension/H264.cpp index 0a5314ae..0d591ea4 100644 --- a/src/Extension/H264.cpp +++ b/src/Extension/H264.cpp @@ -74,6 +74,21 @@ void splitH264(const char *ptr, int len, int prefix, const std::function &cb); - +int prefixSize(const char *ptr, int len); /** * 264帧类 */ diff --git a/src/Rtp/Decoder.cpp b/src/Rtp/Decoder.cpp index 5c8a7662..e177ed8e 100644 --- a/src/Rtp/Decoder.cpp +++ b/src/Rtp/Decoder.cpp @@ -129,7 +129,7 @@ void DecoderImp::onDecode(int stream,int codecid,int flags,int64_t pts,int64_t d auto frame = std::make_shared((char *) data, bytes, dts, pts,0); _merger.inputFrame(frame,[this](uint32_t dts, uint32_t pts, const Buffer::Ptr &buffer) { - onFrame(std::make_shared(buffer->data(), buffer->size(), dts, pts,4)); + onFrame(std::make_shared(buffer->data(), buffer->size(), dts, pts, prefixSize(buffer->data(), buffer->size()))); }); break; } @@ -148,7 +148,7 @@ void DecoderImp::onDecode(int stream,int codecid,int flags,int64_t pts,int64_t d } auto frame = std::make_shared((char *) data, bytes, dts, pts, 0); _merger.inputFrame(frame,[this](uint32_t dts, uint32_t pts, const Buffer::Ptr &buffer) { - onFrame(std::make_shared(buffer->data(), buffer->size(), dts, pts, 4)); + onFrame(std::make_shared(buffer->data(), buffer->size(), dts, pts, prefixSize(buffer->data(), buffer->size()))); }); break; }