mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-26 12:37:09 +08:00
解决多pps问题
解决某些流因为多pps而导致不能播放的问题.
This commit is contained in:
parent
08de795220
commit
f128b35b18
@ -1,4 +1,4 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
||||||
*
|
*
|
||||||
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
||||||
@ -48,7 +48,8 @@ static const char *memfind(const char *buf, ssize_t len, const char *subbuf, ssi
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void splitH264(const char *ptr, size_t len, size_t prefix, const std::function<void(const char *, size_t , size_t)> &cb) {
|
void splitH264(
|
||||||
|
const char *ptr, size_t len, size_t prefix, const std::function<void(const char *, size_t, size_t)> &cb) {
|
||||||
auto start = ptr + prefix;
|
auto start = ptr + prefix;
|
||||||
auto end = ptr + len;
|
auto end = ptr + len;
|
||||||
size_t next_prefix;
|
size_t next_prefix;
|
||||||
@ -180,22 +181,28 @@ bool H264Track::inputFrame_l(const Frame::Ptr &frame){
|
|||||||
switch (type) {
|
switch (type) {
|
||||||
case H264Frame::NAL_SPS: {
|
case H264Frame::NAL_SPS: {
|
||||||
_sps = string(frame->data() + frame->prefixSize(), frame->size() - frame->prefixSize());
|
_sps = string(frame->data() + frame->prefixSize(), frame->size() - frame->prefixSize());
|
||||||
|
_latest_is_config_frame = true;
|
||||||
|
ret = VideoTrack::inputFrame(frame);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case H264Frame::NAL_PPS: {
|
case H264Frame::NAL_PPS: {
|
||||||
_pps = string(frame->data() + frame->prefixSize(), frame->size() - frame->prefixSize());
|
_pps = string(frame->data() + frame->prefixSize(), frame->size() - frame->prefixSize());
|
||||||
_insert_config_frame = true;
|
_latest_is_config_frame = true;
|
||||||
|
ret = VideoTrack::inputFrame(frame);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if (_insert_config_frame && !frame->dropAble()) {
|
// 避免识别不出关键帧
|
||||||
|
if (_latest_is_config_frame && !frame->dropAble()) {
|
||||||
if (!frame->keyFrame()) {
|
if (!frame->keyFrame()) {
|
||||||
const_cast<Frame::Ptr &>(frame) = std::make_shared<FrameCacheAble>(frame, true);
|
const_cast<Frame::Ptr &>(frame) = std::make_shared<FrameCacheAble>(frame, true);
|
||||||
}
|
}
|
||||||
insertConfigFrame(frame);
|
|
||||||
_insert_config_frame = false;
|
|
||||||
}
|
}
|
||||||
|
// 判断是否是I帧, 并且如果是,那判断前面是否插入过config帧, 如果插入过就不插入了
|
||||||
|
if (frame->keyFrame() && !_latest_is_config_frame) {
|
||||||
|
insertConfigFrame(frame);
|
||||||
|
}
|
||||||
|
_latest_is_config_frame = false;
|
||||||
ret = VideoTrack::inputFrame(frame);
|
ret = VideoTrack::inputFrame(frame);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -258,13 +265,9 @@ public:
|
|||||||
_printer << "a=control:trackID=" << (int)TrackVideo << "\r\n";
|
_printer << "a=control:trackID=" << (int)TrackVideo << "\r\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
string getSdp() const {
|
string getSdp() const { return _printer; }
|
||||||
return _printer;
|
|
||||||
}
|
|
||||||
|
|
||||||
CodecId getCodecId() const {
|
CodecId getCodecId() const { return CodecH264; }
|
||||||
return CodecH264;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
_StrPrinter _printer;
|
_StrPrinter _printer;
|
||||||
@ -279,5 +282,3 @@ Sdp::Ptr H264Track::getSdp() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
} // namespace mediakit
|
} // namespace mediakit
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user