From f66a9251424351ea6d631c54dd1feb64cc13d809 Mon Sep 17 00:00:00 2001 From: kwiberg Date: Thu, 24 Sep 2015 03:18:40 -0700 Subject: [PATCH] Don't link with audio codecs that we don't use We used to link with all audio codecs unconditionally (except Opus); this patch makes gyp and gn only link to the ones that are used. (This unfortunately fails to have a measurable impact on Chromium binary size, at least on x86_64 Linux; it turns out that iLBC and iSAC fix were already being excluded from Chromium by some other means (likely just the linker omitting compilation units with no incoming references).) BUG=webrtc:4557 Review URL: https://codereview.webrtc.org/1349393003 Cr-Commit-Position: refs/heads/master@{#10046} --- webrtc/build/common.gypi | 7 +-- webrtc/engine_configurations.h | 21 --------- webrtc/modules/audio_coding/BUILD.gn | 45 +++++++++++++++---- .../audio_coding/main/acm2/codec_owner.cc | 19 ++++---- .../main/audio_coding_module.gypi | 22 ++++++--- .../audio_coding/neteq/audio_decoder_impl.h | 4 -- .../neteq/audio_decoder_unittest.cc | 12 +++-- webrtc/modules/audio_coding/neteq/neteq.gypi | 30 +++++++++---- 8 files changed, 98 insertions(+), 62 deletions(-) diff --git a/webrtc/build/common.gypi b/webrtc/build/common.gypi index 5caa6cc10c..f9fa40c257 100644 --- a/webrtc/build/common.gypi +++ b/webrtc/build/common.gypi @@ -42,9 +42,13 @@ 'webrtc_vp9_dir%': '<(webrtc_root)/modules/video_coding/codecs/vp9', 'include_opus%': 1, 'opus_dir%': '<(DEPTH)/third_party/opus', + + # Enable to use the Mozilla internal settings. + 'build_with_mozilla%': 0, }, 'build_with_chromium%': '<(build_with_chromium)', 'build_with_libjingle%': '<(build_with_libjingle)', + 'build_with_mozilla%': '<(build_with_mozilla)', 'webrtc_root%': '<(webrtc_root)', 'apk_tests_path%': '<(apk_tests_path)', 'modules_java_gyp_path%': '<(modules_java_gyp_path)', @@ -98,9 +102,6 @@ # Disable by default 'have_dbus_glib%': 0, - # Enable to use the Mozilla internal settings. - 'build_with_mozilla%': 0, - # Make it possible to provide custom locations for some libraries. 'libvpx_dir%': '<(DEPTH)/third_party/libvpx', 'libyuv_dir%': '<(DEPTH)/third_party/libyuv', diff --git a/webrtc/engine_configurations.h b/webrtc/engine_configurations.h index f59fd3ec26..c832d9acb3 100644 --- a/webrtc/engine_configurations.h +++ b/webrtc/engine_configurations.h @@ -17,27 +17,6 @@ // Voice and Video // ============================================================================ -// ---------------------------------------------------------------------------- -// [Voice] Codec settings -// ---------------------------------------------------------------------------- - -// iSAC and G722 are not included in the Mozilla build, but in all other builds. -#ifndef WEBRTC_MOZILLA_BUILD -#ifdef WEBRTC_ARCH_ARM -#define WEBRTC_CODEC_ISACFX // Fix-point iSAC implementation. -#else -#define WEBRTC_CODEC_ISAC // Floating-point iSAC implementation (default). -#endif // WEBRTC_ARCH_ARM -#define WEBRTC_CODEC_G722 -#endif // !WEBRTC_MOZILLA_BUILD - -// iLBC and Redundancy coding are excluded from Chromium and Mozilla -// builds to reduce binary size. -#if !defined(WEBRTC_CHROMIUM_BUILD) && !defined(WEBRTC_MOZILLA_BUILD) -#define WEBRTC_CODEC_ILBC -#define WEBRTC_CODEC_RED -#endif // !WEBRTC_CHROMIUM_BUILD && !WEBRTC_MOZILLA_BUILD - // ---------------------------------------------------------------------------- // [Video] Codec settings // ---------------------------------------------------------------------------- diff --git a/webrtc/modules/audio_coding/BUILD.gn b/webrtc/modules/audio_coding/BUILD.gn index 5725ec03df..b1d8cebdec 100644 --- a/webrtc/modules/audio_coding/BUILD.gn +++ b/webrtc/modules/audio_coding/BUILD.gn @@ -67,13 +67,8 @@ source_set("audio_coding") { deps = [ ":cng", ":g711", - ":g722", - ":ilbc", - ":isac", - ":isac_fix", ":neteq", ":pcm16b", - ":red", "../..:rtc_event_log", "../..:webrtc_common", "../../common_audio", @@ -84,6 +79,27 @@ source_set("audio_coding") { defines += [ "WEBRTC_CODEC_OPUS" ] deps += [ ":webrtc_opus" ] } + if (!build_with_mozilla) { + if (current_cpu == "arm") { + defines += [ "WEBRTC_CODEC_ISACFX" ] + deps += [ ":isac_fix" ] + } else { + defines += [ "WEBRTC_CODEC_ISAC" ] + deps += [ ":isac" ] + } + defines += [ "WEBRTC_CODEC_G722" ] + deps += [ ":g722" ] + } + if (!build_with_mozilla && !build_with_chromium) { + defines += [ + "WEBRTC_CODEC_ILBC", + "WEBRTC_CODEC_RED", + ] + deps += [ + ":ilbc", + ":red", + ] + } } source_set("audio_decoder_interface") { @@ -788,10 +804,6 @@ source_set("neteq") { ":audio_decoder_interface", ":cng", ":g711", - ":g722", - ":ilbc", - ":isac", - ":isac_fix", ":pcm16b", "../..:webrtc_common", "../../common_audio", @@ -804,4 +816,19 @@ source_set("neteq") { defines += [ "WEBRTC_CODEC_OPUS" ] deps += [ ":webrtc_opus" ] } + if (!build_with_mozilla) { + if (current_cpu == "arm") { + defines += [ "WEBRTC_CODEC_ISACFX" ] + deps += [ ":isac_fix" ] + } else { + defines += [ "WEBRTC_CODEC_ISAC" ] + deps += [ ":isac" ] + } + defines += [ "WEBRTC_CODEC_G722" ] + deps += [ ":g722" ] + } + if (!build_with_mozilla && !build_with_chromium) { + defines += [ "WEBRTC_CODEC_ILBC" ] + deps += [ ":ilbc" ] + } } diff --git a/webrtc/modules/audio_coding/main/acm2/codec_owner.cc b/webrtc/modules/audio_coding/main/acm2/codec_owner.cc index 669eadb68e..66be85ff8e 100644 --- a/webrtc/modules/audio_coding/main/acm2/codec_owner.cc +++ b/webrtc/modules/audio_coding/main/acm2/codec_owner.cc @@ -131,15 +131,18 @@ rtc::scoped_ptr CreateSpeechEncoder( AudioEncoder* CreateRedEncoder(int red_payload_type, AudioEncoder* encoder, rtc::scoped_ptr* red_encoder) { - if (red_payload_type == -1) { - red_encoder->reset(); - return encoder; +#ifdef WEBRTC_CODEC_RED + if (red_payload_type != -1) { + AudioEncoderCopyRed::Config config; + config.payload_type = red_payload_type; + config.speech_encoder = encoder; + red_encoder->reset(new AudioEncoderCopyRed(config)); + return red_encoder->get(); } - AudioEncoderCopyRed::Config config; - config.payload_type = red_payload_type; - config.speech_encoder = encoder; - red_encoder->reset(new AudioEncoderCopyRed(config)); - return red_encoder->get(); +#endif + + red_encoder->reset(); + return encoder; } void CreateCngEncoder(int cng_payload_type, diff --git a/webrtc/modules/audio_coding/main/audio_coding_module.gypi b/webrtc/modules/audio_coding/main/audio_coding_module.gypi index ce86335c67..7370836e8b 100644 --- a/webrtc/modules/audio_coding/main/audio_coding_module.gypi +++ b/webrtc/modules/audio_coding/main/audio_coding_module.gypi @@ -11,12 +11,7 @@ 'audio_coding_dependencies': [ 'cng', 'g711', - 'g722', - 'ilbc', - 'isac', - 'isac_fix', 'pcm16b', - 'red', '<(webrtc_root)/common.gyp:webrtc_common', '<(webrtc_root)/common_audio/common_audio.gyp:common_audio', '<(webrtc_root)/system_wrappers/system_wrappers.gyp:system_wrappers', @@ -27,6 +22,23 @@ 'audio_coding_dependencies': ['webrtc_opus',], 'audio_coding_defines': ['WEBRTC_CODEC_OPUS',], }], + ['build_with_mozilla==0', { + 'conditions': [ + ['target_arch=="arm"', { + 'audio_coding_dependencies': ['isac_fix',], + 'audio_coding_defines': ['WEBRTC_CODEC_ISACFX',], + }, { + 'audio_coding_dependencies': ['isac',], + 'audio_coding_defines': ['WEBRTC_CODEC_ISAC',], + }], + ], + 'audio_coding_dependencies': ['g722',], + 'audio_coding_defines': ['WEBRTC_CODEC_G722',], + }], + ['build_with_mozilla==0 and build_with_chromium==0', { + 'audio_coding_dependencies': ['ilbc', 'red',], + 'audio_coding_defines': ['WEBRTC_CODEC_ILBC', 'WEBRTC_CODEC_RED',], + }], ], }, 'targets': [ diff --git a/webrtc/modules/audio_coding/neteq/audio_decoder_impl.h b/webrtc/modules/audio_coding/neteq/audio_decoder_impl.h index f7d50d1f66..48ef50259f 100644 --- a/webrtc/modules/audio_coding/neteq/audio_decoder_impl.h +++ b/webrtc/modules/audio_coding/neteq/audio_decoder_impl.h @@ -13,11 +13,7 @@ #include -#ifndef AUDIO_DECODER_UNITTEST -// If this is compiled as a part of the audio_deoder_unittest, the codec -// selection is made in the gypi file instead of in engine_configurations.h. #include "webrtc/engine_configurations.h" -#endif #include "webrtc/base/constructormagic.h" #include "webrtc/modules/audio_coding/codecs/audio_decoder.h" #include "webrtc/modules/audio_coding/codecs/cng/include/webrtc_cng.h" diff --git a/webrtc/modules/audio_coding/neteq/audio_decoder_unittest.cc b/webrtc/modules/audio_coding/neteq/audio_decoder_unittest.cc index 78ebf9f708..f7d14673f6 100644 --- a/webrtc/modules/audio_coding/neteq/audio_decoder_unittest.cc +++ b/webrtc/modules/audio_coding/neteq/audio_decoder_unittest.cc @@ -562,7 +562,6 @@ TEST_F(AudioDecoderIsacSwbTest, EncodeDecode) { int tolerance = 19757; double mse = 8.18e6; int delay = 160; // Delay from input to output. - EXPECT_TRUE(CodecSupported(kDecoderISACswb)); EncodeDecodeTest(0, tolerance, mse, delay); ReInitTest(); EXPECT_FALSE(decoder_->HasDecodePlc()); @@ -676,8 +675,10 @@ TEST(AudioDecoder, CodecSampleRateHz) { EXPECT_EQ(8000, CodecSampleRateHz(kDecoderPCMa_2ch)); EXPECT_EQ(8000, CodecSampleRateHz(kDecoderILBC)); EXPECT_EQ(16000, CodecSampleRateHz(kDecoderISAC)); +#ifndef WEBRTC_ARCH_ARM EXPECT_EQ(32000, CodecSampleRateHz(kDecoderISACswb)); EXPECT_EQ(32000, CodecSampleRateHz(kDecoderISACfb)); +#endif EXPECT_EQ(8000, CodecSampleRateHz(kDecoderPCM16B)); EXPECT_EQ(16000, CodecSampleRateHz(kDecoderPCM16Bwb)); EXPECT_EQ(32000, CodecSampleRateHz(kDecoderPCM16Bswb32kHz)); @@ -702,14 +703,19 @@ TEST(AudioDecoder, CodecSampleRateHz) { } TEST(AudioDecoder, CodecSupported) { +#ifdef WEBRTC_ARCH_ARM + static const bool has_isac_swb = false; +#else + static const bool has_isac_swb = true; +#endif EXPECT_TRUE(CodecSupported(kDecoderPCMu)); EXPECT_TRUE(CodecSupported(kDecoderPCMa)); EXPECT_TRUE(CodecSupported(kDecoderPCMu_2ch)); EXPECT_TRUE(CodecSupported(kDecoderPCMa_2ch)); EXPECT_TRUE(CodecSupported(kDecoderILBC)); EXPECT_TRUE(CodecSupported(kDecoderISAC)); - EXPECT_TRUE(CodecSupported(kDecoderISACswb)); - EXPECT_TRUE(CodecSupported(kDecoderISACfb)); + EXPECT_EQ(has_isac_swb, CodecSupported(kDecoderISACswb)); + EXPECT_EQ(has_isac_swb, CodecSupported(kDecoderISACfb)); EXPECT_TRUE(CodecSupported(kDecoderPCM16B)); EXPECT_TRUE(CodecSupported(kDecoderPCM16Bwb)); EXPECT_TRUE(CodecSupported(kDecoderPCM16Bswb32kHz)); diff --git a/webrtc/modules/audio_coding/neteq/neteq.gypi b/webrtc/modules/audio_coding/neteq/neteq.gypi index 6d0162286d..16cdeb3779 100644 --- a/webrtc/modules/audio_coding/neteq/neteq.gypi +++ b/webrtc/modules/audio_coding/neteq/neteq.gypi @@ -11,10 +11,6 @@ 'codecs': [ 'cng', 'g711', - 'g722', - 'ilbc', - 'isac', - 'isac_fix', 'pcm16b', ], 'neteq_defines': [], @@ -23,6 +19,23 @@ 'codecs': ['webrtc_opus',], 'neteq_defines': ['WEBRTC_CODEC_OPUS',], }], + ['build_with_mozilla==0', { + 'conditions': [ + ['target_arch=="arm"', { + 'codecs': ['isac_fix',], + 'neteq_defines': ['WEBRTC_CODEC_ISACFX',], + }, { + 'codecs': ['isac',], + 'neteq_defines': ['WEBRTC_CODEC_ISAC',], + }], + ], + 'codecs': ['g722',], + 'neteq_defines': ['WEBRTC_CODEC_G722',], + }], + ['build_with_mozilla==0 and build_with_chromium==0', { + 'codecs': ['ilbc',], + 'neteq_defines': ['WEBRTC_CODEC_ILBC',], + }], ], 'neteq_dependencies': [ '<@(codecs)', @@ -120,6 +133,10 @@ 'type': '<(gtest_target_type)', 'dependencies': [ '<@(codecs)', + 'g722', + 'ilbc', + 'isac', + 'isac_fix', 'audio_decoder_interface', 'neteq_unittest_tools', '<(DEPTH)/testing/gtest.gyp:gtest', @@ -127,11 +144,6 @@ '<(webrtc_root)/test/test.gyp:test_support_main', ], 'defines': [ - 'AUDIO_DECODER_UNITTEST', - 'WEBRTC_CODEC_G722', - 'WEBRTC_CODEC_ILBC', - 'WEBRTC_CODEC_ISACFX', - 'WEBRTC_CODEC_ISAC', '<@(neteq_defines)', ], 'sources': [