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}
This commit is contained in:
kwiberg
2015-09-24 03:18:40 -07:00
committed by Commit bot
parent 61e933eac7
commit f66a925142
8 changed files with 98 additions and 62 deletions

View File

@ -42,9 +42,13 @@
'webrtc_vp9_dir%': '<(webrtc_root)/modules/video_coding/codecs/vp9', 'webrtc_vp9_dir%': '<(webrtc_root)/modules/video_coding/codecs/vp9',
'include_opus%': 1, 'include_opus%': 1,
'opus_dir%': '<(DEPTH)/third_party/opus', '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_chromium%': '<(build_with_chromium)',
'build_with_libjingle%': '<(build_with_libjingle)', 'build_with_libjingle%': '<(build_with_libjingle)',
'build_with_mozilla%': '<(build_with_mozilla)',
'webrtc_root%': '<(webrtc_root)', 'webrtc_root%': '<(webrtc_root)',
'apk_tests_path%': '<(apk_tests_path)', 'apk_tests_path%': '<(apk_tests_path)',
'modules_java_gyp_path%': '<(modules_java_gyp_path)', 'modules_java_gyp_path%': '<(modules_java_gyp_path)',
@ -98,9 +102,6 @@
# Disable by default # Disable by default
'have_dbus_glib%': 0, '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. # Make it possible to provide custom locations for some libraries.
'libvpx_dir%': '<(DEPTH)/third_party/libvpx', 'libvpx_dir%': '<(DEPTH)/third_party/libvpx',
'libyuv_dir%': '<(DEPTH)/third_party/libyuv', 'libyuv_dir%': '<(DEPTH)/third_party/libyuv',

View File

@ -17,27 +17,6 @@
// Voice and Video // 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 // [Video] Codec settings
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@ -67,13 +67,8 @@ source_set("audio_coding") {
deps = [ deps = [
":cng", ":cng",
":g711", ":g711",
":g722",
":ilbc",
":isac",
":isac_fix",
":neteq", ":neteq",
":pcm16b", ":pcm16b",
":red",
"../..:rtc_event_log", "../..:rtc_event_log",
"../..:webrtc_common", "../..:webrtc_common",
"../../common_audio", "../../common_audio",
@ -84,6 +79,27 @@ source_set("audio_coding") {
defines += [ "WEBRTC_CODEC_OPUS" ] defines += [ "WEBRTC_CODEC_OPUS" ]
deps += [ ":webrtc_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") { source_set("audio_decoder_interface") {
@ -788,10 +804,6 @@ source_set("neteq") {
":audio_decoder_interface", ":audio_decoder_interface",
":cng", ":cng",
":g711", ":g711",
":g722",
":ilbc",
":isac",
":isac_fix",
":pcm16b", ":pcm16b",
"../..:webrtc_common", "../..:webrtc_common",
"../../common_audio", "../../common_audio",
@ -804,4 +816,19 @@ source_set("neteq") {
defines += [ "WEBRTC_CODEC_OPUS" ] defines += [ "WEBRTC_CODEC_OPUS" ]
deps += [ ":webrtc_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" ]
}
} }

View File

@ -131,15 +131,18 @@ rtc::scoped_ptr<AudioEncoder> CreateSpeechEncoder(
AudioEncoder* CreateRedEncoder(int red_payload_type, AudioEncoder* CreateRedEncoder(int red_payload_type,
AudioEncoder* encoder, AudioEncoder* encoder,
rtc::scoped_ptr<AudioEncoder>* red_encoder) { rtc::scoped_ptr<AudioEncoder>* red_encoder) {
if (red_payload_type == -1) { #ifdef WEBRTC_CODEC_RED
red_encoder->reset(); if (red_payload_type != -1) {
return encoder; 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; #endif
config.payload_type = red_payload_type;
config.speech_encoder = encoder; red_encoder->reset();
red_encoder->reset(new AudioEncoderCopyRed(config)); return encoder;
return red_encoder->get();
} }
void CreateCngEncoder(int cng_payload_type, void CreateCngEncoder(int cng_payload_type,

View File

@ -11,12 +11,7 @@
'audio_coding_dependencies': [ 'audio_coding_dependencies': [
'cng', 'cng',
'g711', 'g711',
'g722',
'ilbc',
'isac',
'isac_fix',
'pcm16b', 'pcm16b',
'red',
'<(webrtc_root)/common.gyp:webrtc_common', '<(webrtc_root)/common.gyp:webrtc_common',
'<(webrtc_root)/common_audio/common_audio.gyp:common_audio', '<(webrtc_root)/common_audio/common_audio.gyp:common_audio',
'<(webrtc_root)/system_wrappers/system_wrappers.gyp:system_wrappers', '<(webrtc_root)/system_wrappers/system_wrappers.gyp:system_wrappers',
@ -27,6 +22,23 @@
'audio_coding_dependencies': ['webrtc_opus',], 'audio_coding_dependencies': ['webrtc_opus',],
'audio_coding_defines': ['WEBRTC_CODEC_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': [ 'targets': [

View File

@ -13,11 +13,7 @@
#include <assert.h> #include <assert.h>
#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" #include "webrtc/engine_configurations.h"
#endif
#include "webrtc/base/constructormagic.h" #include "webrtc/base/constructormagic.h"
#include "webrtc/modules/audio_coding/codecs/audio_decoder.h" #include "webrtc/modules/audio_coding/codecs/audio_decoder.h"
#include "webrtc/modules/audio_coding/codecs/cng/include/webrtc_cng.h" #include "webrtc/modules/audio_coding/codecs/cng/include/webrtc_cng.h"

View File

@ -562,7 +562,6 @@ TEST_F(AudioDecoderIsacSwbTest, EncodeDecode) {
int tolerance = 19757; int tolerance = 19757;
double mse = 8.18e6; double mse = 8.18e6;
int delay = 160; // Delay from input to output. int delay = 160; // Delay from input to output.
EXPECT_TRUE(CodecSupported(kDecoderISACswb));
EncodeDecodeTest(0, tolerance, mse, delay); EncodeDecodeTest(0, tolerance, mse, delay);
ReInitTest(); ReInitTest();
EXPECT_FALSE(decoder_->HasDecodePlc()); EXPECT_FALSE(decoder_->HasDecodePlc());
@ -676,8 +675,10 @@ TEST(AudioDecoder, CodecSampleRateHz) {
EXPECT_EQ(8000, CodecSampleRateHz(kDecoderPCMa_2ch)); EXPECT_EQ(8000, CodecSampleRateHz(kDecoderPCMa_2ch));
EXPECT_EQ(8000, CodecSampleRateHz(kDecoderILBC)); EXPECT_EQ(8000, CodecSampleRateHz(kDecoderILBC));
EXPECT_EQ(16000, CodecSampleRateHz(kDecoderISAC)); EXPECT_EQ(16000, CodecSampleRateHz(kDecoderISAC));
#ifndef WEBRTC_ARCH_ARM
EXPECT_EQ(32000, CodecSampleRateHz(kDecoderISACswb)); EXPECT_EQ(32000, CodecSampleRateHz(kDecoderISACswb));
EXPECT_EQ(32000, CodecSampleRateHz(kDecoderISACfb)); EXPECT_EQ(32000, CodecSampleRateHz(kDecoderISACfb));
#endif
EXPECT_EQ(8000, CodecSampleRateHz(kDecoderPCM16B)); EXPECT_EQ(8000, CodecSampleRateHz(kDecoderPCM16B));
EXPECT_EQ(16000, CodecSampleRateHz(kDecoderPCM16Bwb)); EXPECT_EQ(16000, CodecSampleRateHz(kDecoderPCM16Bwb));
EXPECT_EQ(32000, CodecSampleRateHz(kDecoderPCM16Bswb32kHz)); EXPECT_EQ(32000, CodecSampleRateHz(kDecoderPCM16Bswb32kHz));
@ -702,14 +703,19 @@ TEST(AudioDecoder, CodecSampleRateHz) {
} }
TEST(AudioDecoder, CodecSupported) { 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(kDecoderPCMu));
EXPECT_TRUE(CodecSupported(kDecoderPCMa)); EXPECT_TRUE(CodecSupported(kDecoderPCMa));
EXPECT_TRUE(CodecSupported(kDecoderPCMu_2ch)); EXPECT_TRUE(CodecSupported(kDecoderPCMu_2ch));
EXPECT_TRUE(CodecSupported(kDecoderPCMa_2ch)); EXPECT_TRUE(CodecSupported(kDecoderPCMa_2ch));
EXPECT_TRUE(CodecSupported(kDecoderILBC)); EXPECT_TRUE(CodecSupported(kDecoderILBC));
EXPECT_TRUE(CodecSupported(kDecoderISAC)); EXPECT_TRUE(CodecSupported(kDecoderISAC));
EXPECT_TRUE(CodecSupported(kDecoderISACswb)); EXPECT_EQ(has_isac_swb, CodecSupported(kDecoderISACswb));
EXPECT_TRUE(CodecSupported(kDecoderISACfb)); EXPECT_EQ(has_isac_swb, CodecSupported(kDecoderISACfb));
EXPECT_TRUE(CodecSupported(kDecoderPCM16B)); EXPECT_TRUE(CodecSupported(kDecoderPCM16B));
EXPECT_TRUE(CodecSupported(kDecoderPCM16Bwb)); EXPECT_TRUE(CodecSupported(kDecoderPCM16Bwb));
EXPECT_TRUE(CodecSupported(kDecoderPCM16Bswb32kHz)); EXPECT_TRUE(CodecSupported(kDecoderPCM16Bswb32kHz));

View File

@ -11,10 +11,6 @@
'codecs': [ 'codecs': [
'cng', 'cng',
'g711', 'g711',
'g722',
'ilbc',
'isac',
'isac_fix',
'pcm16b', 'pcm16b',
], ],
'neteq_defines': [], 'neteq_defines': [],
@ -23,6 +19,23 @@
'codecs': ['webrtc_opus',], 'codecs': ['webrtc_opus',],
'neteq_defines': ['WEBRTC_CODEC_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': [ 'neteq_dependencies': [
'<@(codecs)', '<@(codecs)',
@ -120,6 +133,10 @@
'type': '<(gtest_target_type)', 'type': '<(gtest_target_type)',
'dependencies': [ 'dependencies': [
'<@(codecs)', '<@(codecs)',
'g722',
'ilbc',
'isac',
'isac_fix',
'audio_decoder_interface', 'audio_decoder_interface',
'neteq_unittest_tools', 'neteq_unittest_tools',
'<(DEPTH)/testing/gtest.gyp:gtest', '<(DEPTH)/testing/gtest.gyp:gtest',
@ -127,11 +144,6 @@
'<(webrtc_root)/test/test.gyp:test_support_main', '<(webrtc_root)/test/test.gyp:test_support_main',
], ],
'defines': [ 'defines': [
'AUDIO_DECODER_UNITTEST',
'WEBRTC_CODEC_G722',
'WEBRTC_CODEC_ILBC',
'WEBRTC_CODEC_ISACFX',
'WEBRTC_CODEC_ISAC',
'<@(neteq_defines)', '<@(neteq_defines)',
], ],
'sources': [ 'sources': [