From 97567ec36dc06b3b2e53e3bd1c6483e3412297f2 Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Wed, 24 Oct 2018 14:44:36 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90Rtmp=20AAC=E6=89=93=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/RtmpCodec/AACRtmpCodec.cpp | 21 +++++++++++++++++++-- src/RtmpCodec/AACRtmpCodec.h | 1 + 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/RtmpCodec/AACRtmpCodec.cpp b/src/RtmpCodec/AACRtmpCodec.cpp index 84da145c..54ffecd0 100644 --- a/src/RtmpCodec/AACRtmpCodec.cpp +++ b/src/RtmpCodec/AACRtmpCodec.cpp @@ -62,6 +62,23 @@ void AACRtmpEncoder::inputFrame(const Frame::Ptr &frame) { _aac_cfg = makeAdtsConfig(reinterpret_cast(frame->data())); makeAudioConfigPkt(); } + + if(!_aac_cfg.empty()){ + RtmpPacket::Ptr rtmpPkt = ResourcePoolHelper::obtainObj(); + //////////header + uint8_t is_config = false; + rtmpPkt->strBuf.push_back(m_ui8AudioFlags); + rtmpPkt->strBuf.push_back(!is_config); + rtmpPkt->strBuf.append(frame->data() + frame->prefixSize(), frame->size() - frame->prefixSize()); + + rtmpPkt->bodySize = rtmpPkt->strBuf.size(); + rtmpPkt->chunkId = CHUNK_AUDIO; + rtmpPkt->streamId = STREAM_MEDIA; + rtmpPkt->timeStamp = frame->stamp(); + rtmpPkt->typeId = MSG_AUDIO; + inputRtmp(rtmpPkt, false); + } + } void AACRtmpEncoder::makeAudioConfigPkt() { @@ -91,7 +108,7 @@ void AACRtmpEncoder::makeAudioConfigPkt() { uint8_t flvSampleBit = iSampleBit == 16; uint8_t flvAudioType = 10; //aac - uint8_t m_ui8AudioFlags = (flvAudioType << 4) | (flvSampleRate << 2) | (flvSampleBit << 1) | flvStereoOrMono; + m_ui8AudioFlags = (flvAudioType << 4) | (flvSampleRate << 2) | (flvSampleBit << 1) | flvStereoOrMono; RtmpPacket::Ptr rtmpPkt = ResourcePoolHelper::obtainObj(); //////////header @@ -105,7 +122,7 @@ void AACRtmpEncoder::makeAudioConfigPkt() { rtmpPkt->streamId = STREAM_MEDIA; rtmpPkt->timeStamp = 0; rtmpPkt->typeId = MSG_AUDIO; - inputRtmp(rtmpPkt, true); + inputRtmp(rtmpPkt, false); } diff --git a/src/RtmpCodec/AACRtmpCodec.h b/src/RtmpCodec/AACRtmpCodec.h index c326835a..9aff6e76 100644 --- a/src/RtmpCodec/AACRtmpCodec.h +++ b/src/RtmpCodec/AACRtmpCodec.h @@ -61,6 +61,7 @@ public: private: void makeAudioConfigPkt(); + uint8_t m_ui8AudioFlags; }; }//namespace Rtmp