From e5eb7247ffaefade251d9c8b4cc1df1530564482 Mon Sep 17 00:00:00 2001 From: kwiberg Date: Fri, 25 Aug 2017 03:10:50 -0700 Subject: [PATCH] Reimplement the builtin audio codec factories using the new stuff in api/ The whole point of all the audio codec stuff we've recently published in api/ is to function as lego bricks so that building stuff like our builtin audio codec factories will be easy. (This has landed once before, but got reverted because of Chromium test failures---apparently, someone isn't ignoring the case of the codec names like they're supposed to. The quick fix was to preserve the same case used by the old implementation.) BUG=webrtc:7821, webrtc:7822 Review-Url: https://codereview.webrtc.org/2998263002 Cr-Commit-Position: refs/heads/master@{#19512} --- webrtc/api/audio_codecs/BUILD.gn | 78 +++++- .../builtin_audio_decoder_factory.cc | 62 ++++- .../builtin_audio_encoder_factory.cc | 66 ++++- .../audio_codecs/g722/audio_decoder_g722.cc | 4 +- .../audio_codecs/g722/audio_encoder_g722.cc | 2 +- .../audio_codecs/ilbc/audio_decoder_ilbc.cc | 2 +- webrtc/api/audio_codecs/opus/BUILD.gn | 5 +- webrtc/api/audio_codecs/test/BUILD.gn | 1 - ...audio_decoder_factory_template_unittest.cc | 12 +- ...audio_encoder_factory_template_unittest.cc | 6 +- webrtc/modules/audio_coding/BUILD.gn | 30 +- .../builtin_audio_decoder_factory_internal.cc | 257 ------------------ .../builtin_audio_decoder_factory_internal.h | 24 -- .../builtin_audio_encoder_factory_internal.cc | 144 ---------- .../builtin_audio_encoder_factory_internal.h | 26 -- 15 files changed, 218 insertions(+), 501 deletions(-) delete mode 100644 webrtc/modules/audio_coding/codecs/builtin_audio_decoder_factory_internal.cc delete mode 100644 webrtc/modules/audio_coding/codecs/builtin_audio_decoder_factory_internal.h delete mode 100644 webrtc/modules/audio_coding/codecs/builtin_audio_encoder_factory_internal.cc delete mode 100644 webrtc/modules/audio_coding/codecs/builtin_audio_encoder_factory_internal.h diff --git a/webrtc/api/audio_codecs/BUILD.gn b/webrtc/api/audio_codecs/BUILD.gn index 2174fb1063..3ed63965b2 100644 --- a/webrtc/api/audio_codecs/BUILD.gn +++ b/webrtc/api/audio_codecs/BUILD.gn @@ -38,9 +38,46 @@ rtc_static_library("builtin_audio_decoder_factory") { ] deps = [ ":audio_codecs_api", - "../../modules/audio_coding:builtin_audio_decoder_factory_internal", "../../rtc_base:rtc_base_approved", + "L16:audio_decoder_L16", + "g711:audio_decoder_g711", ] + defines = [] + if (rtc_include_ilbc) { + deps += [ "ilbc:audio_decoder_ilbc" ] + defines += [ "WEBRTC_USE_BUILTIN_ILBC=1" ] + } else { + defines += [ "WEBRTC_USE_BUILTIN_ILBC=0" ] + } + if (rtc_include_opus) { + deps += [ "opus:audio_decoder_opus" ] + defines += [ "WEBRTC_USE_BUILTIN_OPUS=1" ] + } else { + defines += [ "WEBRTC_USE_BUILTIN_OPUS=0" ] + } + if (build_with_mozilla) { + defines += [ + "WEBRTC_USE_BUILTIN_G722=0", + "WEBRTC_USE_BUILTIN_ISAC_FIX=0", + "WEBRTC_USE_BUILTIN_ISAC_FLOAT=0", + ] + } else { + if (current_cpu == "arm") { + deps += [ "isac:audio_decoder_isac_fix" ] + defines += [ + "WEBRTC_USE_BUILTIN_ISAC_FIX=1", + "WEBRTC_USE_BUILTIN_ISAC_FLOAT=0", + ] + } else { + deps += [ "isac:audio_decoder_isac_float" ] + defines += [ + "WEBRTC_USE_BUILTIN_ISAC_FIX=0", + "WEBRTC_USE_BUILTIN_ISAC_FLOAT=1", + ] + } + deps += [ "g722:audio_decoder_g722" ] + defines += [ "WEBRTC_USE_BUILTIN_G722=1" ] + } } rtc_static_library("builtin_audio_encoder_factory") { @@ -50,7 +87,44 @@ rtc_static_library("builtin_audio_encoder_factory") { ] deps = [ ":audio_codecs_api", - "../../modules/audio_coding:builtin_audio_encoder_factory_internal", "../../rtc_base:rtc_base_approved", + "L16:audio_encoder_L16", + "g711:audio_encoder_g711", ] + defines = [] + if (rtc_include_ilbc) { + deps += [ "ilbc:audio_encoder_ilbc" ] + defines += [ "WEBRTC_USE_BUILTIN_ILBC=1" ] + } else { + defines += [ "WEBRTC_USE_BUILTIN_ILBC=0" ] + } + if (rtc_include_opus) { + deps += [ "opus:audio_encoder_opus" ] + defines += [ "WEBRTC_USE_BUILTIN_OPUS=1" ] + } else { + defines += [ "WEBRTC_USE_BUILTIN_OPUS=0" ] + } + if (build_with_mozilla) { + defines += [ + "WEBRTC_USE_BUILTIN_G722=0", + "WEBRTC_USE_BUILTIN_ISAC_FIX=0", + "WEBRTC_USE_BUILTIN_ISAC_FLOAT=0", + ] + } else { + if (current_cpu == "arm") { + deps += [ "isac:audio_encoder_isac_fix" ] + defines += [ + "WEBRTC_USE_BUILTIN_ISAC_FIX=1", + "WEBRTC_USE_BUILTIN_ISAC_FLOAT=0", + ] + } else { + deps += [ "isac:audio_encoder_isac_float" ] + defines += [ + "WEBRTC_USE_BUILTIN_ISAC_FIX=0", + "WEBRTC_USE_BUILTIN_ISAC_FLOAT=1", + ] + } + deps += [ "g722:audio_encoder_g722" ] + defines += [ "WEBRTC_USE_BUILTIN_G722=1" ] + } } diff --git a/webrtc/api/audio_codecs/builtin_audio_decoder_factory.cc b/webrtc/api/audio_codecs/builtin_audio_decoder_factory.cc index 9bd049b0e6..69a3e7c533 100644 --- a/webrtc/api/audio_codecs/builtin_audio_decoder_factory.cc +++ b/webrtc/api/audio_codecs/builtin_audio_decoder_factory.cc @@ -10,12 +10,70 @@ #include "webrtc/api/audio_codecs/builtin_audio_decoder_factory.h" -#include "webrtc/modules/audio_coding/codecs/builtin_audio_decoder_factory_internal.h" +#include +#include + +#include "webrtc/api/audio_codecs/L16/audio_decoder_L16.h" +#include "webrtc/api/audio_codecs/audio_decoder_factory_template.h" +#include "webrtc/api/audio_codecs/g711/audio_decoder_g711.h" +#if WEBRTC_USE_BUILTIN_G722 +#include "webrtc/api/audio_codecs/g722/audio_decoder_g722.h" // nogncheck +#endif +#if WEBRTC_USE_BUILTIN_ILBC +#include "webrtc/api/audio_codecs/ilbc/audio_decoder_ilbc.h" // nogncheck +#endif +#if WEBRTC_USE_BUILTIN_ISAC_FIX +#include "webrtc/api/audio_codecs/isac/audio_decoder_isac_fix.h" // nogncheck +#elif WEBRTC_USE_BUILTIN_ISAC_FLOAT +#include "webrtc/api/audio_codecs/isac/audio_decoder_isac_float.h" // nogncheck +#endif +#if WEBRTC_USE_BUILTIN_OPUS +#include "webrtc/api/audio_codecs/opus/audio_decoder_opus.h" // nogncheck +#endif namespace webrtc { +namespace { + +// Modify an audio decoder to not advertise support for anything. +template +struct NotAdvertised { + using Config = typename T::Config; + static rtc::Optional SdpToConfig(const SdpAudioFormat& audio_format) { + return T::SdpToConfig(audio_format); + } + static void AppendSupportedDecoders(std::vector* specs) { + // Don't advertise support for anything. + } + static std::unique_ptr MakeAudioDecoder(const Config& config) { + return T::MakeAudioDecoder(config); + } +}; + +} // namespace + rtc::scoped_refptr CreateBuiltinAudioDecoderFactory() { - return CreateBuiltinAudioDecoderFactoryInternal(); + return CreateAudioDecoderFactory< + +#if WEBRTC_USE_BUILTIN_OPUS + AudioDecoderOpus, +#endif + +#if WEBRTC_USE_BUILTIN_ISAC_FIX + AudioDecoderIsacFix, +#elif WEBRTC_USE_BUILTIN_ISAC_FLOAT + AudioDecoderIsacFloat, +#endif + +#if WEBRTC_USE_BUILTIN_G722 + AudioDecoderG722, +#endif + +#if WEBRTC_USE_BUILTIN_ILBC + AudioDecoderIlbc, +#endif + + AudioDecoderG711, NotAdvertised>(); } } // namespace webrtc diff --git a/webrtc/api/audio_codecs/builtin_audio_encoder_factory.cc b/webrtc/api/audio_codecs/builtin_audio_encoder_factory.cc index bb57a5f48a..ae1bf4b306 100644 --- a/webrtc/api/audio_codecs/builtin_audio_encoder_factory.cc +++ b/webrtc/api/audio_codecs/builtin_audio_encoder_factory.cc @@ -10,12 +10,74 @@ #include "webrtc/api/audio_codecs/builtin_audio_encoder_factory.h" -#include "webrtc/modules/audio_coding/codecs/builtin_audio_encoder_factory_internal.h" +#include +#include + +#include "webrtc/api/audio_codecs/L16/audio_encoder_L16.h" +#include "webrtc/api/audio_codecs/audio_encoder_factory_template.h" +#include "webrtc/api/audio_codecs/g711/audio_encoder_g711.h" +#if WEBRTC_USE_BUILTIN_G722 +#include "webrtc/api/audio_codecs/g722/audio_encoder_g722.h" // nogncheck +#endif +#if WEBRTC_USE_BUILTIN_ILBC +#include "webrtc/api/audio_codecs/ilbc/audio_encoder_ilbc.h" // nogncheck +#endif +#if WEBRTC_USE_BUILTIN_ISAC_FIX +#include "webrtc/api/audio_codecs/isac/audio_encoder_isac_fix.h" // nogncheck +#elif WEBRTC_USE_BUILTIN_ISAC_FLOAT +#include "webrtc/api/audio_codecs/isac/audio_encoder_isac_float.h" // nogncheck +#endif +#if WEBRTC_USE_BUILTIN_OPUS +#include "webrtc/api/audio_codecs/opus/audio_encoder_opus.h" // nogncheck +#endif namespace webrtc { +namespace { + +// Modify an audio encoder to not advertise support for anything. +template +struct NotAdvertised { + using Config = typename T::Config; + static rtc::Optional SdpToConfig(const SdpAudioFormat& audio_format) { + return T::SdpToConfig(audio_format); + } + static void AppendSupportedEncoders(std::vector* specs) { + // Don't advertise support for anything. + } + static AudioCodecInfo QueryAudioEncoder(const Config& config) { + return T::QueryAudioEncoder(config); + } + static std::unique_ptr MakeAudioEncoder(const Config& config, + int payload_type) { + return T::MakeAudioEncoder(config, payload_type); + } +}; + +} // namespace + rtc::scoped_refptr CreateBuiltinAudioEncoderFactory() { - return CreateBuiltinAudioEncoderFactoryInternal(); + return CreateAudioEncoderFactory< + +#if WEBRTC_USE_BUILTIN_OPUS + AudioEncoderOpus, +#endif + +#if WEBRTC_USE_BUILTIN_ISAC_FIX + AudioEncoderIsacFix, +#elif WEBRTC_USE_BUILTIN_ISAC_FLOAT + AudioEncoderIsacFloat, +#endif + +#if WEBRTC_USE_BUILTIN_G722 + AudioEncoderG722, +#endif + +#if WEBRTC_USE_BUILTIN_ILBC + AudioEncoderIlbc, +#endif + + AudioEncoderG711, NotAdvertised>(); } } // namespace webrtc diff --git a/webrtc/api/audio_codecs/g722/audio_decoder_g722.cc b/webrtc/api/audio_codecs/g722/audio_decoder_g722.cc index 9c4bff71c5..6f3ce97de9 100644 --- a/webrtc/api/audio_codecs/g722/audio_decoder_g722.cc +++ b/webrtc/api/audio_codecs/g722/audio_decoder_g722.cc @@ -22,7 +22,7 @@ namespace webrtc { rtc::Optional AudioDecoderG722::SdpToConfig( const SdpAudioFormat& format) { - return STR_CASE_CMP(format.name.c_str(), "g722") == 0 && + return STR_CASE_CMP(format.name.c_str(), "G722") == 0 && format.clockrate_hz == 8000 && (format.num_channels == 1 || format.num_channels == 2) ? rtc::Optional( @@ -32,7 +32,7 @@ rtc::Optional AudioDecoderG722::SdpToConfig( void AudioDecoderG722::AppendSupportedDecoders( std::vector* specs) { - specs->push_back({{"g722", 8000, 1}, {16000, 1, 64000}}); + specs->push_back({{"G722", 8000, 1}, {16000, 1, 64000}}); } std::unique_ptr AudioDecoderG722::MakeAudioDecoder( diff --git a/webrtc/api/audio_codecs/g722/audio_encoder_g722.cc b/webrtc/api/audio_codecs/g722/audio_encoder_g722.cc index b3e406304d..09b3faf745 100644 --- a/webrtc/api/audio_codecs/g722/audio_encoder_g722.cc +++ b/webrtc/api/audio_codecs/g722/audio_encoder_g722.cc @@ -26,7 +26,7 @@ rtc::Optional AudioEncoderG722::SdpToConfig( void AudioEncoderG722::AppendSupportedEncoders( std::vector* specs) { - const SdpAudioFormat fmt = {"g722", 8000, 1}; + const SdpAudioFormat fmt = {"G722", 8000, 1}; const AudioCodecInfo info = QueryAudioEncoder(*SdpToConfig(fmt)); specs->push_back({fmt, info}); } diff --git a/webrtc/api/audio_codecs/ilbc/audio_decoder_ilbc.cc b/webrtc/api/audio_codecs/ilbc/audio_decoder_ilbc.cc index b3053ef471..dc1775189e 100644 --- a/webrtc/api/audio_codecs/ilbc/audio_decoder_ilbc.cc +++ b/webrtc/api/audio_codecs/ilbc/audio_decoder_ilbc.cc @@ -21,7 +21,7 @@ namespace webrtc { rtc::Optional AudioDecoderIlbc::SdpToConfig( const SdpAudioFormat& format) { - return STR_CASE_CMP(format.name.c_str(), "ilbc") == 0 && + return STR_CASE_CMP(format.name.c_str(), "ILBC") == 0 && format.clockrate_hz == 8000 && format.num_channels == 1 ? rtc::Optional(Config()) : rtc::Optional(); diff --git a/webrtc/api/audio_codecs/opus/BUILD.gn b/webrtc/api/audio_codecs/opus/BUILD.gn index 29a68ff74e..658d151a1d 100644 --- a/webrtc/api/audio_codecs/opus/BUILD.gn +++ b/webrtc/api/audio_codecs/opus/BUILD.gn @@ -36,9 +36,12 @@ rtc_source_set("audio_encoder_opus") { ":audio_encoder_opus_config", "..:audio_codecs_api", "../../../modules/audio_coding:webrtc_opus", - "../../../rtc_base:protobuf_utils", # TODO(kwiberg): Why is this needed? "../../../rtc_base:rtc_base_approved", ] + public_deps = [ + # TODO(kwiberg): Remove this public_dep when bug 7847 has been fixed. + "../../../rtc_base:protobuf_utils", + ] } rtc_static_library("audio_decoder_opus") { diff --git a/webrtc/api/audio_codecs/test/BUILD.gn b/webrtc/api/audio_codecs/test/BUILD.gn index 16fdeb9698..0f742f57cc 100644 --- a/webrtc/api/audio_codecs/test/BUILD.gn +++ b/webrtc/api/audio_codecs/test/BUILD.gn @@ -21,7 +21,6 @@ if (rtc_include_tests) { ] deps = [ "..:audio_codecs_api", - "../../../rtc_base:protobuf_utils", # TODO(kwiberg): Why is this needed? "../../../rtc_base:rtc_base_approved", "../../../test:audio_codec_mocks", "../../../test:test_support", diff --git a/webrtc/api/audio_codecs/test/audio_decoder_factory_template_unittest.cc b/webrtc/api/audio_codecs/test/audio_decoder_factory_template_unittest.cc index 8d65a659a9..0b1135cf2b 100644 --- a/webrtc/api/audio_codecs/test/audio_decoder_factory_template_unittest.cc +++ b/webrtc/api/audio_codecs/test/audio_decoder_factory_template_unittest.cc @@ -123,7 +123,7 @@ TEST(AudioDecoderFactoryTemplateTest, G711) { testing::ElementsAre( AudioCodecSpec{{"PCMU", 8000, 1}, {8000, 1, 64000}}, AudioCodecSpec{{"PCMA", 8000, 1}, {8000, 1, 64000}})); - EXPECT_FALSE(factory->IsSupportedDecoder({"g711", 8000, 1})); + EXPECT_FALSE(factory->IsSupportedDecoder({"G711", 8000, 1})); EXPECT_TRUE(factory->IsSupportedDecoder({"PCMU", 8000, 1})); EXPECT_TRUE(factory->IsSupportedDecoder({"pcma", 8000, 1})); EXPECT_EQ(nullptr, factory->MakeAudioDecoder({"pcmu", 16000, 1})); @@ -139,19 +139,19 @@ TEST(AudioDecoderFactoryTemplateTest, G722) { auto factory = CreateAudioDecoderFactory(); EXPECT_THAT(factory->GetSupportedDecoders(), testing::ElementsAre( - AudioCodecSpec{{"g722", 8000, 1}, {16000, 1, 64000}})); + AudioCodecSpec{{"G722", 8000, 1}, {16000, 1, 64000}})); EXPECT_FALSE(factory->IsSupportedDecoder({"foo", 8000, 1})); - EXPECT_TRUE(factory->IsSupportedDecoder({"g722", 8000, 1})); + EXPECT_TRUE(factory->IsSupportedDecoder({"G722", 8000, 1})); EXPECT_EQ(nullptr, factory->MakeAudioDecoder({"bar", 16000, 1})); - auto dec1 = factory->MakeAudioDecoder({"g722", 8000, 1}); + auto dec1 = factory->MakeAudioDecoder({"G722", 8000, 1}); ASSERT_NE(nullptr, dec1); EXPECT_EQ(16000, dec1->SampleRateHz()); EXPECT_EQ(1u, dec1->Channels()); - auto dec2 = factory->MakeAudioDecoder({"g722", 8000, 2}); + auto dec2 = factory->MakeAudioDecoder({"G722", 8000, 2}); ASSERT_NE(nullptr, dec2); EXPECT_EQ(16000, dec2->SampleRateHz()); EXPECT_EQ(2u, dec2->Channels()); - auto dec3 = factory->MakeAudioDecoder({"g722", 8000, 3}); + auto dec3 = factory->MakeAudioDecoder({"G722", 8000, 3}); ASSERT_EQ(nullptr, dec3); } diff --git a/webrtc/api/audio_codecs/test/audio_encoder_factory_template_unittest.cc b/webrtc/api/audio_codecs/test/audio_encoder_factory_template_unittest.cc index 7d8f3a8f95..891821a803 100644 --- a/webrtc/api/audio_codecs/test/audio_encoder_factory_template_unittest.cc +++ b/webrtc/api/audio_codecs/test/audio_encoder_factory_template_unittest.cc @@ -147,13 +147,13 @@ TEST(AudioEncoderFactoryTemplateTest, G722) { auto factory = CreateAudioEncoderFactory(); EXPECT_THAT(factory->GetSupportedEncoders(), testing::ElementsAre( - AudioCodecSpec{{"g722", 8000, 1}, {16000, 1, 64000}})); + AudioCodecSpec{{"G722", 8000, 1}, {16000, 1, 64000}})); EXPECT_EQ(rtc::Optional(), factory->QueryAudioEncoder({"foo", 8000, 1})); EXPECT_EQ(rtc::Optional({16000, 1, 64000}), - factory->QueryAudioEncoder({"g722", 8000, 1})); + factory->QueryAudioEncoder({"G722", 8000, 1})); EXPECT_EQ(nullptr, factory->MakeAudioEncoder(17, {"bar", 16000, 1})); - auto enc = factory->MakeAudioEncoder(17, {"g722", 8000, 1}); + auto enc = factory->MakeAudioEncoder(17, {"G722", 8000, 1}); ASSERT_NE(nullptr, enc); EXPECT_EQ(16000, enc->SampleRateHz()); } diff --git a/webrtc/modules/audio_coding/BUILD.gn b/webrtc/modules/audio_coding/BUILD.gn index 3e6a183486..a3964c9080 100644 --- a/webrtc/modules/audio_coding/BUILD.gn +++ b/webrtc/modules/audio_coding/BUILD.gn @@ -51,34 +51,6 @@ rtc_static_library("audio_format_conversion") { ] } -rtc_static_library("builtin_audio_decoder_factory_internal") { - sources = [ - "codecs/builtin_audio_decoder_factory_internal.cc", - "codecs/builtin_audio_decoder_factory_internal.h", - ] - deps = [ - "../..:webrtc_common", - "../../rtc_base:protobuf_utils", - "../../rtc_base:rtc_base_approved", - "../../api/audio_codecs:audio_codecs_api", - ] + audio_codec_deps - defines = audio_codec_defines -} - -rtc_static_library("builtin_audio_encoder_factory_internal") { - sources = [ - "codecs/builtin_audio_encoder_factory_internal.cc", - "codecs/builtin_audio_encoder_factory_internal.h", - ] - deps = [ - "../..:webrtc_common", - "../../rtc_base:protobuf_utils", - "../../rtc_base:rtc_base_approved", - "../../api/audio_codecs:audio_codecs_api", - ] + audio_codec_deps - defines = audio_codec_defines -} - rtc_static_library("rent_a_codec") { sources = [ "acm2/acm_codec_database.cc", @@ -840,13 +812,13 @@ rtc_static_library("webrtc_opus") { "../../api/audio_codecs:audio_codecs_api", "../../api/audio_codecs/opus:audio_encoder_opus_config", "../../common_audio", - "../../rtc_base:protobuf_utils", "../../rtc_base:rtc_base_approved", "../../rtc_base:rtc_numerics", "../../system_wrappers", ] public_deps = [ ":webrtc_opus_c", + "../../rtc_base:protobuf_utils", ] defines = audio_codec_defines diff --git a/webrtc/modules/audio_coding/codecs/builtin_audio_decoder_factory_internal.cc b/webrtc/modules/audio_coding/codecs/builtin_audio_decoder_factory_internal.cc deleted file mode 100644 index f853cbda31..0000000000 --- a/webrtc/modules/audio_coding/codecs/builtin_audio_decoder_factory_internal.cc +++ /dev/null @@ -1,257 +0,0 @@ -/* - * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#include "webrtc/modules/audio_coding/codecs/builtin_audio_decoder_factory_internal.h" - -#include -#include - -#include "webrtc/common_types.h" -#include "webrtc/modules/audio_coding/codecs/cng/webrtc_cng.h" -#include "webrtc/modules/audio_coding/codecs/g711/audio_decoder_pcm.h" -#include "webrtc/rtc_base/checks.h" -#include "webrtc/rtc_base/optional.h" -#ifdef WEBRTC_CODEC_G722 -#include "webrtc/modules/audio_coding/codecs/g722/audio_decoder_g722.h" -#endif -#ifdef WEBRTC_CODEC_ILBC -#include "webrtc/modules/audio_coding/codecs/ilbc/audio_decoder_ilbc.h" -#endif -#ifdef WEBRTC_CODEC_ISACFX -#include "webrtc/modules/audio_coding/codecs/isac/fix/include/audio_decoder_isacfix.h" // nogncheck -#endif -#ifdef WEBRTC_CODEC_ISAC -#include "webrtc/modules/audio_coding/codecs/isac/main/include/audio_decoder_isac.h" // nogncheck -#endif -#ifdef WEBRTC_CODEC_OPUS -#include "webrtc/modules/audio_coding/codecs/opus/audio_decoder_opus.h" -#endif -#include "webrtc/modules/audio_coding/codecs/pcm16b/audio_decoder_pcm16b.h" - -namespace webrtc { - -namespace { - -struct NamedDecoderConstructor { - const char* name; - - // If |format| is good, return true and (if |out| isn't null) reset |*out| to - // a new decoder object. If the |format| is not good, return false. - bool (*constructor)(const SdpAudioFormat& format, - std::unique_ptr* out); -}; - -// TODO(kwiberg): These factory functions should probably be moved to each -// decoder. -NamedDecoderConstructor decoder_constructors[] = { - {"pcmu", - [](const SdpAudioFormat& format, std::unique_ptr* out) { - if (format.clockrate_hz == 8000 && format.num_channels >= 1) { - if (out) { - out->reset(new AudioDecoderPcmU(format.num_channels)); - } - return true; - } else { - return false; - } - }}, - {"pcma", - [](const SdpAudioFormat& format, std::unique_ptr* out) { - if (format.clockrate_hz == 8000 && format.num_channels >= 1) { - if (out) { - out->reset(new AudioDecoderPcmA(format.num_channels)); - } - return true; - } else { - return false; - } - }}, -#ifdef WEBRTC_CODEC_ILBC - {"ilbc", - [](const SdpAudioFormat& format, std::unique_ptr* out) { - if (format.clockrate_hz == 8000 && format.num_channels == 1) { - if (out) { - out->reset(new AudioDecoderIlbcImpl); - } - return true; - } else { - return false; - } - }}, -#endif -#if defined(WEBRTC_CODEC_ISACFX) - {"isac", - [](const SdpAudioFormat& format, std::unique_ptr* out) { - if (format.clockrate_hz == 16000 && format.num_channels == 1) { - if (out) { - out->reset(new AudioDecoderIsacFixImpl(format.clockrate_hz)); - } - return true; - } else { - return false; - } - }}, -#elif defined(WEBRTC_CODEC_ISAC) - {"isac", - [](const SdpAudioFormat& format, std::unique_ptr* out) { - if ((format.clockrate_hz == 16000 || format.clockrate_hz == 32000) && - format.num_channels == 1) { - if (out) { - out->reset(new AudioDecoderIsacFloatImpl(format.clockrate_hz)); - } - return true; - } else { - return false; - } - }}, -#endif - {"l16", - [](const SdpAudioFormat& format, std::unique_ptr* out) { - if (format.num_channels >= 1) { - if (out) { - out->reset(new AudioDecoderPcm16B(format.clockrate_hz, - format.num_channels)); - } - return true; - } else { - return false; - } - }}, -#ifdef WEBRTC_CODEC_G722 - {"g722", - [](const SdpAudioFormat& format, std::unique_ptr* out) { - if (format.clockrate_hz == 8000) { - if (format.num_channels == 1) { - if (out) { - out->reset(new AudioDecoderG722Impl); - } - return true; - } else if (format.num_channels == 2) { - if (out) { - out->reset(new AudioDecoderG722StereoImpl); - } - return true; - } - } - return false; - }}, -#endif -#ifdef WEBRTC_CODEC_OPUS - {"opus", - [](const SdpAudioFormat& format, std::unique_ptr* out) { - const rtc::Optional num_channels = [&] { - auto stereo = format.parameters.find("stereo"); - if (stereo != format.parameters.end()) { - if (stereo->second == "0") { - return rtc::Optional(1); - } else if (stereo->second == "1") { - return rtc::Optional(2); - } else { - return rtc::Optional(); // Bad stereo parameter. - } - } - return rtc::Optional(1); // Default to mono. - }(); - if (format.clockrate_hz == 48000 && format.num_channels == 2 && - num_channels) { - if (out) { - out->reset(new AudioDecoderOpusImpl(*num_channels)); - } - return true; - } else { - return false; - } - }}, -#endif -}; - -class BuiltinAudioDecoderFactory : public AudioDecoderFactory { - public: - std::vector GetSupportedDecoders() override { - // Although this looks a bit strange, it means specs need only be - // initialized once, and that that initialization is thread-safe. - static std::vector specs = [] { - std::vector specs; -#ifdef WEBRTC_CODEC_OPUS - AudioCodecInfo opus_info{48000, 1, 64000, 6000, 510000}; - opus_info.allow_comfort_noise = false; - opus_info.supports_network_adaption = true; - // clang-format off - SdpAudioFormat opus_format({"opus", 48000, 2, { - {"minptime", "10"}, - {"useinbandfec", "1"} - }}); - // clang-format on - specs.push_back({std::move(opus_format), opus_info}); -#endif -#if (defined(WEBRTC_CODEC_ISAC) || defined(WEBRTC_CODEC_ISACFX)) - specs.push_back(AudioCodecSpec{{"ISAC", 16000, 1}, - {16000, 1, 32000, 10000, 56000}}); -#endif -#if (defined(WEBRTC_CODEC_ISAC)) - specs.push_back(AudioCodecSpec{{"ISAC", 32000, 1}, - {32000, 1, 56000, 10000, 56000}}); -#endif -#ifdef WEBRTC_CODEC_G722 - specs.push_back(AudioCodecSpec{{"G722", 8000, 1}, - {16000, 1, 64000}}); -#endif -#ifdef WEBRTC_CODEC_ILBC - specs.push_back(AudioCodecSpec{{"ILBC", 8000, 1}, - {8000, 1, 13300}}); -#endif - specs.push_back(AudioCodecSpec{{"PCMU", 8000, 1}, - {8000, 1, 64000}}); - specs.push_back(AudioCodecSpec{{"PCMA", 8000, 1}, - {8000, 1, 64000}}); - return specs; - }(); - return specs; - } - - bool IsSupportedDecoder(const SdpAudioFormat& format) override { - for (const auto& dc : decoder_constructors) { - if (STR_CASE_CMP(format.name.c_str(), dc.name) == 0) { - return dc.constructor(format, nullptr); - } - } - return false; - } - - std::unique_ptr MakeAudioDecoder( - const SdpAudioFormat& format) override { - for (const auto& dc : decoder_constructors) { - if (STR_CASE_CMP(format.name.c_str(), dc.name) == 0) { - std::unique_ptr decoder; - bool ok = dc.constructor(format, &decoder); - RTC_DCHECK_EQ(ok, decoder != nullptr); - if (decoder) { - const int expected_sample_rate_hz = - STR_CASE_CMP(format.name.c_str(), "g722") == 0 - ? 2 * format.clockrate_hz - : format.clockrate_hz; - RTC_CHECK_EQ(expected_sample_rate_hz, decoder->SampleRateHz()); - } - return decoder; - } - } - return nullptr; - } -}; - -} // namespace - -rtc::scoped_refptr -CreateBuiltinAudioDecoderFactoryInternal() { - return rtc::scoped_refptr( - new rtc::RefCountedObject); -} - -} // namespace webrtc diff --git a/webrtc/modules/audio_coding/codecs/builtin_audio_decoder_factory_internal.h b/webrtc/modules/audio_coding/codecs/builtin_audio_decoder_factory_internal.h deleted file mode 100644 index c856954512..0000000000 --- a/webrtc/modules/audio_coding/codecs/builtin_audio_decoder_factory_internal.h +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#ifndef WEBRTC_MODULES_AUDIO_CODING_CODECS_BUILTIN_AUDIO_DECODER_FACTORY_INTERNAL_H_ -#define WEBRTC_MODULES_AUDIO_CODING_CODECS_BUILTIN_AUDIO_DECODER_FACTORY_INTERNAL_H_ - -#include "webrtc/api/audio_codecs/audio_decoder_factory.h" -#include "webrtc/rtc_base/scoped_ref_ptr.h" - -namespace webrtc { - -rtc::scoped_refptr -CreateBuiltinAudioDecoderFactoryInternal(); - -} // namespace webrtc - -#endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_BUILTIN_AUDIO_DECODER_FACTORY_INTERNAL_H_ diff --git a/webrtc/modules/audio_coding/codecs/builtin_audio_encoder_factory_internal.cc b/webrtc/modules/audio_coding/codecs/builtin_audio_encoder_factory_internal.cc deleted file mode 100644 index b44268ab07..0000000000 --- a/webrtc/modules/audio_coding/codecs/builtin_audio_encoder_factory_internal.cc +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#include "webrtc/modules/audio_coding/codecs/builtin_audio_encoder_factory_internal.h" - -#include -#include - -#include "webrtc/common_types.h" -#include "webrtc/modules/audio_coding/codecs/g711/audio_encoder_pcm.h" -#include "webrtc/rtc_base/checks.h" -#include "webrtc/rtc_base/logging.h" -#include "webrtc/rtc_base/optional.h" -#ifdef WEBRTC_CODEC_G722 -#include "webrtc/modules/audio_coding/codecs/g722/audio_encoder_g722.h" -#endif -#ifdef WEBRTC_CODEC_ILBC -#include "webrtc/modules/audio_coding/codecs/ilbc/audio_encoder_ilbc.h" -#endif -#ifdef WEBRTC_CODEC_ISACFX -#include "webrtc/modules/audio_coding/codecs/isac/fix/include/audio_encoder_isacfix.h" // nogncheck -#endif -#ifdef WEBRTC_CODEC_ISAC -#include "webrtc/modules/audio_coding/codecs/isac/main/include/audio_encoder_isac.h" // nogncheck -#endif -#ifdef WEBRTC_CODEC_OPUS -#include "webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.h" -#endif -#include "webrtc/modules/audio_coding/codecs/pcm16b/audio_encoder_pcm16b.h" - -namespace webrtc { - -namespace { - -struct NamedEncoderFactory { - const char* name; - rtc::Optional (*QueryAudioEncoder)( - const SdpAudioFormat& format); - std::unique_ptr ( - *MakeAudioEncoder)(int payload_type, const SdpAudioFormat& format); - - template - static NamedEncoderFactory ForEncoder() { - auto constructor = [](int payload_type, const SdpAudioFormat& format) { - auto opt_info = T::QueryAudioEncoder(format); - if (opt_info) { - return std::unique_ptr(new T(payload_type, format)); - } - return std::unique_ptr(); - }; - - return {T::GetPayloadName(), T::QueryAudioEncoder, constructor}; - } -}; - -NamedEncoderFactory encoder_factories[] = { -#ifdef WEBRTC_CODEC_G722 - NamedEncoderFactory::ForEncoder(), -#endif -#ifdef WEBRTC_CODEC_ILBC - NamedEncoderFactory::ForEncoder(), -#endif -#if defined(WEBRTC_CODEC_ISACFX) - NamedEncoderFactory::ForEncoder(), -#elif defined(WEBRTC_CODEC_ISAC) - NamedEncoderFactory::ForEncoder(), -#endif - -#ifdef WEBRTC_CODEC_OPUS - NamedEncoderFactory::ForEncoder(), -#endif - NamedEncoderFactory::ForEncoder(), - NamedEncoderFactory::ForEncoder(), - NamedEncoderFactory::ForEncoder(), -}; -} // namespace - -class BuiltinAudioEncoderFactory : public AudioEncoderFactory { - public: - std::vector GetSupportedEncoders() override { - static const SdpAudioFormat desired_encoders[] = { - {"opus", 48000, 2, {{"minptime", "10"}, {"useinbandfec", "1"}}}, - {"ISAC", 16000, 1}, - {"ISAC", 32000, 1}, - {"G722", 8000, 1}, - {"ILBC", 8000, 1}, - {"PCMU", 8000, 1}, - {"PCMA", 8000, 1}, - }; - - // Initialize thread-safely, once, on first use. - static const std::vector specs = [] { - std::vector specs; - for (const auto& format : desired_encoders) { - for (const auto& ef : encoder_factories) { - if (STR_CASE_CMP(format.name.c_str(), ef.name) == 0) { - auto opt_info = ef.QueryAudioEncoder(format); - if (opt_info) { - specs.push_back({format, *opt_info}); - } - } - } - } - return specs; - }(); - return specs; - } - - rtc::Optional QueryAudioEncoder( - const SdpAudioFormat& format) override { - for (const auto& ef : encoder_factories) { - if (STR_CASE_CMP(format.name.c_str(), ef.name) == 0) { - return ef.QueryAudioEncoder(format); - } - } - return rtc::Optional(); - } - - std::unique_ptr MakeAudioEncoder( - int payload_type, - const SdpAudioFormat& format) override { - for (const auto& ef : encoder_factories) { - if (STR_CASE_CMP(format.name.c_str(), ef.name) == 0) { - return ef.MakeAudioEncoder(payload_type, format); - } - } - return nullptr; - } -}; - -rtc::scoped_refptr -CreateBuiltinAudioEncoderFactoryInternal() { - return rtc::scoped_refptr( - new rtc::RefCountedObject()); -} - -} // namespace webrtc diff --git a/webrtc/modules/audio_coding/codecs/builtin_audio_encoder_factory_internal.h b/webrtc/modules/audio_coding/codecs/builtin_audio_encoder_factory_internal.h deleted file mode 100644 index 327e6ca4e5..0000000000 --- a/webrtc/modules/audio_coding/codecs/builtin_audio_encoder_factory_internal.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#ifndef WEBRTC_MODULES_AUDIO_CODING_CODECS_BUILTIN_AUDIO_ENCODER_FACTORY_INTERNAL_H_ -#define WEBRTC_MODULES_AUDIO_CODING_CODECS_BUILTIN_AUDIO_ENCODER_FACTORY_INTERNAL_H_ - -#include "webrtc/api/audio_codecs/audio_encoder_factory.h" -#include "webrtc/rtc_base/scoped_ref_ptr.h" - -namespace webrtc { - -// Creates a new factory that can create the built-in types of audio encoders. -// NOTE: This function is still under development and may change without notice. -rtc::scoped_refptr -CreateBuiltinAudioEncoderFactoryInternal(); - -} // namespace webrtc - -#endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_BUILTIN_AUDIO_ENCODER_FACTORY_INTERNAL_H_