From c0fde6248021410a487021283f561dfd4bf97a12 Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Fri, 24 Jul 2020 20:10:47 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84aac=20rtp=E8=A7=A3=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Extension/AACRtp.cpp | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/Extension/AACRtp.cpp b/src/Extension/AACRtp.cpp index 9214d97b..0140e277 100644 --- a/src/Extension/AACRtp.cpp +++ b/src/Extension/AACRtp.cpp @@ -98,10 +98,15 @@ bool AACRtpDecoder::inputRtp(const RtpPacket::Ptr &rtppack, bool key_pos) { return false; } + if (!_last_dts) { + //记录第一个时间戳 + _last_dts = rtppack->timeStamp; + } + //每个audio unit时间戳增量 auto dts_inc = (rtppack->timeStamp - _last_dts) / au_header_count; - if(dts_inc < 0 && dts_inc > 100){ - //时间戳增量异常 + if (dts_inc < 0 && dts_inc > 100) { + //时间戳增量异常,忽略 dts_inc = 0; } @@ -112,13 +117,16 @@ bool AACRtpDecoder::inputRtp(const RtpPacket::Ptr &rtppack, bool key_pos) { //数据不够 break; } - //设置aac数据 - _frame->_buffer.assign((char *) ptr, size); - //设置当前audio unit时间戳 - _frame->_dts = _last_dts + i * dts_inc; - ptr += size; - au_header_ptr += 2; - flushData(); + + if (size) { + //设置aac数据 + _frame->_buffer.assign((char *) ptr, size); + //设置当前audio unit时间戳 + _frame->_dts = _last_dts + i * dts_inc; + ptr += size; + au_header_ptr += 2; + flushData(); + } } //记录上次时间戳 _last_dts = rtppack->timeStamp; @@ -126,11 +134,6 @@ bool AACRtpDecoder::inputRtp(const RtpPacket::Ptr &rtppack, bool key_pos) { } void AACRtpDecoder::flushData() { - if (_frame->_buffer.empty()) { - //没有有效数据 - return; - } - //插入adts头 char adts_header[32] = {0}; auto size = dumpAacConfig(_aac_cfg, _frame->_buffer.size(), (uint8_t *) adts_header, sizeof(adts_header));