mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-27 05:38:31 +08:00
修复h264/h265 prefixSize计算错误的bug
This commit is contained in:
parent
7d8dbb2a4b
commit
7b90daab24
@ -78,14 +78,6 @@ void DevChannel::inputH264(const char *data, int len, uint32_t dts, uint32_t pts
|
|||||||
if(pts == 0){
|
if(pts == 0){
|
||||||
pts = dts;
|
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需要缓存时间戳相同的帧,
|
//由于rtmp/hls/mp4需要缓存时间戳相同的帧,
|
||||||
//所以使用FrameNoCacheAble类型的帧反而会在转换成FrameCacheAble时多次内存拷贝
|
//所以使用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<H264Frame>();
|
H264Frame::Ptr frame = std::make_shared<H264Frame>();
|
||||||
frame->_dts = dts;
|
frame->_dts = dts;
|
||||||
frame->_pts = pts;
|
frame->_pts = pts;
|
||||||
frame->_buffer.assign("\x00\x00\x00\x01",4);
|
frame->_buffer.assign(data, len);
|
||||||
frame->_buffer.append(data + prefixeSize, len - prefixeSize);
|
frame->_prefix_size = prefixSize(data,len);
|
||||||
frame->_prefix_size = 4;
|
|
||||||
inputFrame(frame);
|
inputFrame(frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,14 +97,6 @@ void DevChannel::inputH265(const char *data, int len, uint32_t dts, uint32_t pts
|
|||||||
if(pts == 0){
|
if(pts == 0){
|
||||||
pts = dts;
|
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需要缓存时间戳相同的帧,
|
//由于rtmp/hls/mp4需要缓存时间戳相同的帧,
|
||||||
//所以使用FrameNoCacheAble类型的帧反而会在转换成FrameCacheAble时多次内存拷贝
|
//所以使用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<H265Frame>();
|
H265Frame::Ptr frame = std::make_shared<H265Frame>();
|
||||||
frame->_dts = dts;
|
frame->_dts = dts;
|
||||||
frame->_pts = pts;
|
frame->_pts = pts;
|
||||||
frame->_buffer.assign("\x00\x00\x00\x01",4);
|
frame->_buffer.assign(data, len);
|
||||||
frame->_buffer.append(data + prefixeSize, len - prefixeSize);
|
frame->_prefix_size = prefixSize(data,len);
|
||||||
frame->_prefix_size = 4;
|
|
||||||
inputFrame(frame);
|
inputFrame(frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,6 +74,21 @@ void splitH264(const char *ptr, int len, int prefix, const std::function<void(co
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int prefixSize(const char *ptr, int len){
|
||||||
|
if (len < 4) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (memcmp("\x00\x00\x01", ptr, 3) == 0) {
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (memcmp("\x00\x00\x00\x01", ptr, 4) == 0) {
|
||||||
|
return 4;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
//splitH264函数测试程序
|
//splitH264函数测试程序
|
||||||
static onceToken s_token([](){
|
static onceToken s_token([](){
|
||||||
|
@ -21,7 +21,7 @@ namespace mediakit{
|
|||||||
|
|
||||||
bool getAVCInfo(const string &strSps,int &iVideoWidth, int &iVideoHeight, float &iVideoFps);
|
bool getAVCInfo(const string &strSps,int &iVideoWidth, int &iVideoHeight, float &iVideoFps);
|
||||||
void splitH264(const char *ptr, int len, int prefix, const std::function<void(const char *, int, int)> &cb);
|
void splitH264(const char *ptr, int len, int prefix, const std::function<void(const char *, int, int)> &cb);
|
||||||
|
int prefixSize(const char *ptr, int len);
|
||||||
/**
|
/**
|
||||||
* 264帧类
|
* 264帧类
|
||||||
*/
|
*/
|
||||||
|
@ -129,7 +129,7 @@ void DecoderImp::onDecode(int stream,int codecid,int flags,int64_t pts,int64_t d
|
|||||||
|
|
||||||
auto frame = std::make_shared<H264FrameNoCacheAble>((char *) data, bytes, dts, pts,0);
|
auto frame = std::make_shared<H264FrameNoCacheAble>((char *) data, bytes, dts, pts,0);
|
||||||
_merger.inputFrame(frame,[this](uint32_t dts, uint32_t pts, const Buffer::Ptr &buffer) {
|
_merger.inputFrame(frame,[this](uint32_t dts, uint32_t pts, const Buffer::Ptr &buffer) {
|
||||||
onFrame(std::make_shared<H264FrameNoCacheAble>(buffer->data(), buffer->size(), dts, pts,4));
|
onFrame(std::make_shared<H264FrameNoCacheAble>(buffer->data(), buffer->size(), dts, pts, prefixSize(buffer->data(), buffer->size())));
|
||||||
});
|
});
|
||||||
break;
|
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<H265FrameNoCacheAble>((char *) data, bytes, dts, pts, 0);
|
auto frame = std::make_shared<H265FrameNoCacheAble>((char *) data, bytes, dts, pts, 0);
|
||||||
_merger.inputFrame(frame,[this](uint32_t dts, uint32_t pts, const Buffer::Ptr &buffer) {
|
_merger.inputFrame(frame,[this](uint32_t dts, uint32_t pts, const Buffer::Ptr &buffer) {
|
||||||
onFrame(std::make_shared<H265FrameNoCacheAble>(buffer->data(), buffer->size(), dts, pts, 4));
|
onFrame(std::make_shared<H265FrameNoCacheAble>(buffer->data(), buffer->size(), dts, pts, prefixSize(buffer->data(), buffer->size())));
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user