From 6e59000265055a39bb1a40387ef24acc418071e7 Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Fri, 13 Dec 2019 15:42:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=BF=87=E6=BB=A4=E5=A4=9A?= =?UTF-8?q?=E4=BD=99=E5=B8=A7=E7=B1=BB=E5=9E=8B=E5=AF=BC=E8=87=B4=E7=9A=84?= =?UTF-8?q?bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Extension/H264.h | 8 ++--- src/Extension/H264Rtmp.cpp | 65 ++++++++++++++++---------------------- 2 files changed, 30 insertions(+), 43 deletions(-) diff --git a/src/Extension/H264.h b/src/Extension/H264.h index 394752ec..4bb8ea1c 100644 --- a/src/Extension/H264.h +++ b/src/Extension/H264.h @@ -49,7 +49,6 @@ public: NAL_SPS = 7, NAL_PPS = 8, NAL_IDR = 5, - NAL_B_P = 1 } NalType; char *data() const override{ @@ -315,18 +314,15 @@ private: //I insertConfigFrame(frame); VideoTrack::inputFrame(frame); - _last_frame_is_idr = true; } break; - case H264Frame::NAL_B_P:{ - //B or P + default: VideoTrack::inputFrame(frame); - _last_frame_is_idr = false; - } break; } + _last_frame_is_idr = type == H264Frame::NAL_IDR; if(_width == 0 && ready()){ onReady(); } diff --git a/src/Extension/H264Rtmp.cpp b/src/Extension/H264Rtmp.cpp index 2f56b9e6..5bea72de 100644 --- a/src/Extension/H264Rtmp.cpp +++ b/src/Extension/H264Rtmp.cpp @@ -144,44 +144,35 @@ void H264RtmpEncoder::inputFrame(const Frame::Ptr &frame) { } } - switch (type){ - case H264Frame::NAL_IDR: - case H264Frame::NAL_B_P:{ - if(_lastPacket && _lastPacket->timeStamp != frame->stamp()) { - RtmpCodec::inputRtmp(_lastPacket, _lastPacket->isVideoKeyFrame()); - _lastPacket = nullptr; - } - - if(!_lastPacket) { - //I or P or B frame - int8_t flags = 7; //h.264 - bool is_config = false; - flags |= ((frame->keyFrame() ? FLV_KEY_FRAME : FLV_INTER_FRAME) << 4); - - _lastPacket = ResourcePoolHelper::obtainObj(); - _lastPacket->strBuf.clear(); - _lastPacket->strBuf.push_back(flags); - _lastPacket->strBuf.push_back(!is_config); - auto cts = frame->pts() - frame->dts(); - cts = htonl(cts); - _lastPacket->strBuf.append((char *)&cts + 1, 3); - - _lastPacket->chunkId = CHUNK_VIDEO; - _lastPacket->streamId = STREAM_MEDIA; - _lastPacket->timeStamp = frame->stamp(); - _lastPacket->typeId = MSG_VIDEO; - - } - auto size = htonl(iLen); - _lastPacket->strBuf.append((char *) &size, 4); - _lastPacket->strBuf.append(pcData, iLen); - _lastPacket->bodySize = _lastPacket->strBuf.size(); - } - break; - - default: - break; + if(_lastPacket && _lastPacket->timeStamp != frame->stamp()) { + RtmpCodec::inputRtmp(_lastPacket, _lastPacket->isVideoKeyFrame()); + _lastPacket = nullptr; } + + if(!_lastPacket) { + //I or P or B frame + int8_t flags = 7; //h.264 + bool is_config = false; + flags |= ((frame->keyFrame() ? FLV_KEY_FRAME : FLV_INTER_FRAME) << 4); + + _lastPacket = ResourcePoolHelper::obtainObj(); + _lastPacket->strBuf.clear(); + _lastPacket->strBuf.push_back(flags); + _lastPacket->strBuf.push_back(!is_config); + auto cts = frame->pts() - frame->dts(); + cts = htonl(cts); + _lastPacket->strBuf.append((char *)&cts + 1, 3); + + _lastPacket->chunkId = CHUNK_VIDEO; + _lastPacket->streamId = STREAM_MEDIA; + _lastPacket->timeStamp = frame->stamp(); + _lastPacket->typeId = MSG_VIDEO; + + } + auto size = htonl(iLen); + _lastPacket->strBuf.append((char *) &size, 4); + _lastPacket->strBuf.append(pcData, iLen); + _lastPacket->bodySize = _lastPacket->strBuf.size(); }