修复过滤多余帧类型导致的bug

This commit is contained in:
xiongziliang 2019-12-13 15:42:58 +08:00
parent bd8a9a78e8
commit 6e59000265
2 changed files with 30 additions and 43 deletions

View File

@ -49,7 +49,6 @@ public:
NAL_SPS = 7, NAL_SPS = 7,
NAL_PPS = 8, NAL_PPS = 8,
NAL_IDR = 5, NAL_IDR = 5,
NAL_B_P = 1
} NalType; } NalType;
char *data() const override{ char *data() const override{
@ -315,18 +314,15 @@ private:
//I //I
insertConfigFrame(frame); insertConfigFrame(frame);
VideoTrack::inputFrame(frame); VideoTrack::inputFrame(frame);
_last_frame_is_idr = true;
} }
break; break;
case H264Frame::NAL_B_P:{ default:
//B or P
VideoTrack::inputFrame(frame); VideoTrack::inputFrame(frame);
_last_frame_is_idr = false;
}
break; break;
} }
_last_frame_is_idr = type == H264Frame::NAL_IDR;
if(_width == 0 && ready()){ if(_width == 0 && ready()){
onReady(); onReady();
} }

View File

@ -144,44 +144,35 @@ void H264RtmpEncoder::inputFrame(const Frame::Ptr &frame) {
} }
} }
switch (type){ if(_lastPacket && _lastPacket->timeStamp != frame->stamp()) {
case H264Frame::NAL_IDR: RtmpCodec::inputRtmp(_lastPacket, _lastPacket->isVideoKeyFrame());
case H264Frame::NAL_B_P:{ _lastPacket = nullptr;
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<RtmpPacket>::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) {
//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<RtmpPacket>::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();
} }