From 43608585a1df415856550d840f144c78a3ace958 Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Tue, 27 Aug 2019 11:34:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=97=B6=E9=97=B4=E6=88=B3?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Rtmp/FlvMuxer.cpp | 19 +++---------------- src/Rtmp/FlvMuxer.h | 4 +++- 2 files changed, 6 insertions(+), 17 deletions(-) diff --git a/src/Rtmp/FlvMuxer.cpp b/src/Rtmp/FlvMuxer.cpp index 6354b40a..e47ba1d3 100644 --- a/src/Rtmp/FlvMuxer.cpp +++ b/src/Rtmp/FlvMuxer.cpp @@ -76,8 +76,6 @@ void FlvMuxer::start(const EventPoller::Ptr &poller,const RtmpMediaSource::Ptr & } void FlvMuxer::onWriteFlvHeader(const RtmpMediaSource::Ptr &mediaSrc) { - CLEAR_ARR(_aui32FirstStamp); - //发送flv文件头 char flv_file_header[] = "FLV\x1\x5\x0\x0\x0\x9"; // have audio and have video bool is_have_audio = false,is_have_video = false; @@ -158,20 +156,9 @@ void FlvMuxer::onWriteFlvTag(uint8_t ui8Type, const Buffer::Ptr &buffer, uint32_ } void FlvMuxer::onWriteRtmp(const RtmpPacket::Ptr &pkt) { - auto modifiedStamp = pkt->timeStamp; - auto &firstStamp = _aui32FirstStamp[pkt->typeId % 2]; - if(!firstStamp){ - firstStamp = modifiedStamp; - } - if(modifiedStamp >= firstStamp){ - //计算时间戳增量 - modifiedStamp -= firstStamp; - }else{ - //发生回环,重新计算时间戳增量 - CLEAR_ARR(_aui32FirstStamp); - modifiedStamp = 0; - } - onWriteFlvTag(pkt, modifiedStamp); + int64_t dts_out; + _stamp[pkt->typeId % 2].revise(pkt->timeStamp, 0, dts_out, dts_out); + onWriteFlvTag(pkt, dts_out); } void FlvMuxer::stop() { diff --git a/src/Rtmp/FlvMuxer.h b/src/Rtmp/FlvMuxer.h index 99be3275..7f48d3fd 100644 --- a/src/Rtmp/FlvMuxer.h +++ b/src/Rtmp/FlvMuxer.h @@ -30,6 +30,7 @@ #include "Rtmp/Rtmp.h" #include "Rtmp/RtmpMediaSource.h" #include "Network/Socket.h" +#include "MediaFile/Stamp.h" using namespace toolkit; namespace mediakit { @@ -52,7 +53,8 @@ private: void onWriteFlvTag(uint8_t ui8Type, const Buffer::Ptr &buffer, uint32_t ui32TimeStamp); private: RtmpMediaSource::RingType::RingReader::Ptr _ring_reader; - uint32_t _aui32FirstStamp[2] = {0}; + //时间戳修整器 + Stamp _stamp[2]; };