From b33c227cf4aa1bb0074c5435676c9399cef70832 Mon Sep 17 00:00:00 2001 From: cqm Date: Wed, 1 Jun 2022 11:35:52 +0800 Subject: [PATCH] =?UTF-8?q?AacTracker=20=E5=A2=9E=E5=8A=A0=E6=9E=84?= =?UTF-8?q?=E9=80=A0=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Extension/AAC.cpp | 18 +++++++++++++++++- src/Extension/AAC.h | 1 + src/Extension/G711.h | 2 +- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/Extension/AAC.cpp b/src/Extension/AAC.cpp index 1047a8b3..4bf7733a 100644 --- a/src/Extension/AAC.cpp +++ b/src/Extension/AAC.cpp @@ -18,8 +18,8 @@ using namespace toolkit; namespace mediakit{ -#ifndef ENABLE_MP4 unsigned const samplingFrequencyTable[16] = { 96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050, 16000, 12000, 11025, 8000, 7350, 0, 0, 0 }; +#ifndef ENABLE_MP4 class AdtsHeader{ public: @@ -246,6 +246,22 @@ AACTrack::AACTrack(const string &aac_cfg) { onReady(); } +AACTrack::AACTrack(int samplerate, int channel, int profile) : _channel(channel), _sampleRate(samplerate) { + uint8_t audioSpecificConfig[2] = { 0 }; + uint8_t audioObjectType = profile+1; + int samplingFrequencyIndex = 0; + for (size_t i = 0; i < sizeof(samplingFrequencyTable) / sizeof(samplingFrequencyTable[0]); i++) { + if (samplingFrequencyTable[i] == (unsigned)samplerate) { + samplingFrequencyIndex = i; + break; + } + } + _cfg.resize(2); + _cfg[0] = (audioObjectType << 3) | (samplingFrequencyIndex >> 1); + _cfg[1] = (samplingFrequencyIndex << 7) | (channel << 3); + // onReady(); +} + const string &AACTrack::getConfig() const { return _cfg; } diff --git a/src/Extension/AAC.h b/src/Extension/AAC.h index b95fc6f2..bba5ea00 100644 --- a/src/Extension/AAC.h +++ b/src/Extension/AAC.h @@ -40,6 +40,7 @@ public: * @param aac_cfg aac配置信息 */ AACTrack(const std::string &aac_cfg); + AACTrack(int samplerate, int channel, int profile=1); /** * 获取aac 配置信息 diff --git a/src/Extension/G711.h b/src/Extension/G711.h index 550acbc4..e2e01746 100644 --- a/src/Extension/G711.h +++ b/src/Extension/G711.h @@ -22,7 +22,7 @@ namespace mediakit{ class G711Track : public AudioTrackImp{ public: using Ptr = std::shared_ptr; - G711Track(CodecId codecId, int sample_rate, int channels, int sample_bit) : AudioTrackImp(codecId, 8000, 1, 16) {} + G711Track(CodecId codecId, int sample_rate = 8000, int channels = 1, int sample_bit = 16) : AudioTrackImp(codecId, sample_rate, channels, sample_bit) {} private: Sdp::Ptr getSdp() override;