From 0e47dc94f985d68fada52a207c39774310a37d9d Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Thu, 11 Jun 2020 17:19:10 +0800 Subject: [PATCH] =?UTF-8?q?aac=20config=E4=B8=8D=E5=86=8D=E9=99=90?= =?UTF-8?q?=E5=88=B6=E4=B8=A4=E4=B8=AA=E5=AD=97=E8=8A=82=EF=BC=9A#336?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Extension/AAC.h | 10 +++++++--- src/Extension/Factory.cpp | 17 ++++++----------- src/Record/MP4Muxer.cpp | 3 ++- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/Extension/AAC.h b/src/Extension/AAC.h index feb65bd7..d53b7f49 100644 --- a/src/Extension/AAC.h +++ b/src/Extension/AAC.h @@ -77,7 +77,7 @@ public: if(aac_cfg.size() < 2){ throw std::invalid_argument("adts配置必须最少2个字节"); } - _cfg = aac_cfg.substr(0,2); + _cfg = aac_cfg; onReady(); } @@ -185,8 +185,12 @@ public: _printer << "b=AS:" << bitrate << "\r\n"; _printer << "a=rtpmap:" << payload_type << " MPEG4-GENERIC/" << sample_rate << "/" << channels << "\r\n"; - char configStr[32] = {0}; - snprintf(configStr, sizeof(configStr), "%02X%02X", (uint8_t)aac_cfg[0], (uint8_t)aac_cfg[1]); + string configStr; + char buf[4] = {0}; + for(auto &ch : aac_cfg){ + snprintf(buf, sizeof(buf), "%02X", (uint8_t)ch); + configStr.append(buf); + } _printer << "a=fmtp:" << payload_type << " streamtype=5;profile-level-id=1;mode=AAC-hbr;" << "sizelength=13;indexlength=3;indexdeltalength=3;config=" << configStr << "\r\n"; _printer << "a=control:trackID=" << (int)TrackAudio << "\r\n"; diff --git a/src/Extension/Factory.cpp b/src/Extension/Factory.cpp index 276ce140..3a8fce31 100644 --- a/src/Extension/Factory.cpp +++ b/src/Extension/Factory.cpp @@ -33,17 +33,12 @@ Track::Ptr Factory::getTrackBySdp(const SdpTrack::Ptr &track) { return nullptr; } string aac_cfg; - - unsigned int cfg1; - sscanf(aac_cfg_str.substr(0, 2).data(), "%02X", &cfg1); - cfg1 &= 0x00FF; - aac_cfg.push_back(cfg1); - - unsigned int cfg2; - sscanf(aac_cfg_str.substr(2, 2).data(), "%02X", &cfg2); - cfg2 &= 0x00FF; - aac_cfg.push_back(cfg2); - + for(int i = 0 ; i < aac_cfg_str.size() / 2 ; ++i ){ + unsigned int cfg; + sscanf(aac_cfg_str.substr(i * 2, 2).data(), "%02X", &cfg); + cfg &= 0x00FF; + aac_cfg.push_back((char)cfg); + } return std::make_shared(aac_cfg); } diff --git a/src/Record/MP4Muxer.cpp b/src/Record/MP4Muxer.cpp index a543126a..c62c3dbb 100644 --- a/src/Record/MP4Muxer.cpp +++ b/src/Record/MP4Muxer.cpp @@ -202,7 +202,8 @@ void MP4Muxer::addTrack(const Track::Ptr &track) { audio_track->getAudioChannel(), audio_track->getAudioSampleBit() * audio_track->getAudioChannel(), audio_track->getAudioSampleRate(), - audio_track->getAacCfg().data(), 2); + audio_track->getAacCfg().data(), + audio_track->getAacCfg().size()); if(track_id < 0){ WarnL << "添加AAC Track失败:" << track_id; return;