Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(801)

Side by Side Diff: webrtc/modules/audio_coding/main/acm2/codec_owner.cc

Issue 1368843003: Don't link with audio codecs that we don't use (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Add comment Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include "webrtc/modules/audio_coding/main/acm2/codec_owner.h" 11 #include "webrtc/modules/audio_coding/main/acm2/codec_owner.h"
12 12
13 #include "webrtc/base/checks.h" 13 #include "webrtc/base/checks.h"
14 #include "webrtc/base/logging.h" 14 #include "webrtc/base/logging.h"
15 #include "webrtc/engine_configurations.h" 15 #include "webrtc/engine_configurations.h"
16 #include "webrtc/modules/audio_coding/codecs/cng/include/audio_encoder_cng.h" 16 #include "webrtc/modules/audio_coding/codecs/cng/include/audio_encoder_cng.h"
17 #include "webrtc/modules/audio_coding/codecs/g711/include/audio_encoder_pcm.h" 17 #include "webrtc/modules/audio_coding/codecs/g711/include/audio_encoder_pcm.h"
18 #ifdef WEBRTC_CODEC_G722
18 #include "webrtc/modules/audio_coding/codecs/g722/include/audio_encoder_g722.h" 19 #include "webrtc/modules/audio_coding/codecs/g722/include/audio_encoder_g722.h"
20 #endif
21 #ifdef WEBRTC_CODEC_ILBC
19 #include "webrtc/modules/audio_coding/codecs/ilbc/interface/audio_encoder_ilbc.h " 22 #include "webrtc/modules/audio_coding/codecs/ilbc/interface/audio_encoder_ilbc.h "
23 #endif
24 #ifdef WEBRTC_CODEC_ISACFX
20 #include "webrtc/modules/audio_coding/codecs/isac/fix/interface/audio_decoder_is acfix.h" 25 #include "webrtc/modules/audio_coding/codecs/isac/fix/interface/audio_decoder_is acfix.h"
21 #include "webrtc/modules/audio_coding/codecs/isac/fix/interface/audio_encoder_is acfix.h" 26 #include "webrtc/modules/audio_coding/codecs/isac/fix/interface/audio_encoder_is acfix.h"
27 #endif
28 #ifdef WEBRTC_CODEC_ISAC
22 #include "webrtc/modules/audio_coding/codecs/isac/main/interface/audio_decoder_i sac.h" 29 #include "webrtc/modules/audio_coding/codecs/isac/main/interface/audio_decoder_i sac.h"
23 #include "webrtc/modules/audio_coding/codecs/isac/main/interface/audio_encoder_i sac.h" 30 #include "webrtc/modules/audio_coding/codecs/isac/main/interface/audio_encoder_i sac.h"
31 #endif
32 #ifdef WEBRTC_CODEC_OPUS
24 #include "webrtc/modules/audio_coding/codecs/opus/interface/audio_encoder_opus.h " 33 #include "webrtc/modules/audio_coding/codecs/opus/interface/audio_encoder_opus.h "
34 #endif
25 #include "webrtc/modules/audio_coding/codecs/pcm16b/include/audio_encoder_pcm16b .h" 35 #include "webrtc/modules/audio_coding/codecs/pcm16b/include/audio_encoder_pcm16b .h"
36 #ifdef WEBRTC_CODEC_RED
26 #include "webrtc/modules/audio_coding/codecs/red/audio_encoder_copy_red.h" 37 #include "webrtc/modules/audio_coding/codecs/red/audio_encoder_copy_red.h"
38 #endif
27 39
28 namespace webrtc { 40 namespace webrtc {
29 namespace acm2 { 41 namespace acm2 {
30 42
31 namespace {
32 bool IsIsac(const CodecInst& codec) {
33 return
34 #if (defined(WEBRTC_CODEC_ISAC) || defined(WEBRTC_CODEC_ISACFX))
35 !STR_CASE_CMP(codec.plname, "isac") ||
36 #endif
37 false;
38 }
39
40 bool IsOpus(const CodecInst& codec) {
41 return
42 #ifdef WEBRTC_CODEC_OPUS
43 !STR_CASE_CMP(codec.plname, "opus") ||
44 #endif
45 false;
46 }
47
48 bool IsPcmU(const CodecInst& codec) {
49 return !STR_CASE_CMP(codec.plname, "pcmu");
50 }
51
52 bool IsPcmA(const CodecInst& codec) {
53 return !STR_CASE_CMP(codec.plname, "pcma");
54 }
55
56 bool IsPcm16B(const CodecInst& codec) {
57 return !STR_CASE_CMP(codec.plname, "l16");
58 }
59
60 bool IsIlbc(const CodecInst& codec) {
61 return
62 #ifdef WEBRTC_CODEC_ILBC
63 !STR_CASE_CMP(codec.plname, "ilbc") ||
64 #endif
65 false;
66 }
67
68 bool IsG722(const CodecInst& codec) {
69 return
70 #ifdef WEBRTC_CODEC_G722
71 !STR_CASE_CMP(codec.plname, "g722") ||
72 #endif
73 false;
74 }
75 } // namespace
76
77 CodecOwner::CodecOwner() : external_speech_encoder_(nullptr) { 43 CodecOwner::CodecOwner() : external_speech_encoder_(nullptr) {
78 } 44 }
79 45
80 CodecOwner::~CodecOwner() = default; 46 CodecOwner::~CodecOwner() = default;
81 47
82 namespace { 48 namespace {
83 49
84 rtc::scoped_ptr<AudioDecoder> CreateIsacDecoder( 50 rtc::scoped_ptr<AudioDecoder> CreateIsacDecoder(
85 LockedIsacBandwidthInfo* bwinfo) { 51 LockedIsacBandwidthInfo* bwinfo) {
86 #if defined(WEBRTC_CODEC_ISACFX) 52 #if defined(WEBRTC_CODEC_ISACFX)
87 return rtc_make_scoped_ptr(new AudioDecoderIsacFix(bwinfo)); 53 return rtc_make_scoped_ptr(new AudioDecoderIsacFix(bwinfo));
88 #elif defined(WEBRTC_CODEC_ISAC) 54 #elif defined(WEBRTC_CODEC_ISAC)
89 return rtc_make_scoped_ptr(new AudioDecoderIsac(bwinfo)); 55 return rtc_make_scoped_ptr(new AudioDecoderIsac(bwinfo));
90 #else 56 #else
91 FATAL() << "iSAC is not supported."; 57 FATAL() << "iSAC is not supported.";
92 return rtc::scoped_ptr<AudioDecoder>(); 58 return rtc::scoped_ptr<AudioDecoder>();
93 #endif 59 #endif
94 } 60 }
95 61
96 rtc::scoped_ptr<AudioEncoder> CreateIsacEncoder(
97 const CodecInst& speech_inst,
98 LockedIsacBandwidthInfo* bwinfo) {
99 #if defined(WEBRTC_CODEC_ISACFX)
100 return rtc_make_scoped_ptr(new AudioEncoderIsacFix(speech_inst, bwinfo));
101 #elif defined(WEBRTC_CODEC_ISAC)
102 return rtc_make_scoped_ptr(new AudioEncoderIsac(speech_inst, bwinfo));
103 #else
104 FATAL() << "iSAC is not supported.";
105 return rtc::scoped_ptr<AudioEncoderMutable>();
106 #endif
107 }
108
109 // Returns a new speech encoder, or null on error. 62 // Returns a new speech encoder, or null on error.
110 // TODO(kwiberg): Don't handle errors here (bug 5033) 63 // TODO(kwiberg): Don't handle errors here (bug 5033)
111 rtc::scoped_ptr<AudioEncoder> CreateSpeechEncoder( 64 rtc::scoped_ptr<AudioEncoder> CreateSpeechEncoder(
112 const CodecInst& speech_inst, 65 const CodecInst& speech_inst,
113 LockedIsacBandwidthInfo* bwinfo) { 66 LockedIsacBandwidthInfo* bwinfo) {
114 if (IsIsac(speech_inst)) { 67 #if defined(WEBRTC_CODEC_ISACFX)
115 return CreateIsacEncoder(speech_inst, bwinfo); 68 if (STR_CASE_CMP(speech_inst.plname, "isac") == 0)
116 } else if (IsOpus(speech_inst)) { 69 return rtc_make_scoped_ptr(new AudioEncoderIsacFix(speech_inst, bwinfo));
70 #endif
71 #if defined(WEBRTC_CODEC_ISAC)
72 if (STR_CASE_CMP(speech_inst.plname, "isac") == 0)
73 return rtc_make_scoped_ptr(new AudioEncoderIsac(speech_inst, bwinfo));
74 #endif
75 #ifdef WEBRTC_CODEC_OPUS
76 if (STR_CASE_CMP(speech_inst.plname, "opus") == 0)
117 return rtc_make_scoped_ptr(new AudioEncoderOpus(speech_inst)); 77 return rtc_make_scoped_ptr(new AudioEncoderOpus(speech_inst));
118 } else if (IsPcmU(speech_inst)) { 78 #endif
79 if (STR_CASE_CMP(speech_inst.plname, "pcmu") == 0)
119 return rtc_make_scoped_ptr(new AudioEncoderPcmU(speech_inst)); 80 return rtc_make_scoped_ptr(new AudioEncoderPcmU(speech_inst));
120 } else if (IsPcmA(speech_inst)) { 81 if (STR_CASE_CMP(speech_inst.plname, "pcma") == 0)
121 return rtc_make_scoped_ptr(new AudioEncoderPcmA(speech_inst)); 82 return rtc_make_scoped_ptr(new AudioEncoderPcmA(speech_inst));
122 } else if (IsPcm16B(speech_inst)) { 83 if (STR_CASE_CMP(speech_inst.plname, "l16") == 0)
123 return rtc_make_scoped_ptr(new AudioEncoderPcm16B(speech_inst)); 84 return rtc_make_scoped_ptr(new AudioEncoderPcm16B(speech_inst));
124 } else if (IsIlbc(speech_inst)) { 85 #ifdef WEBRTC_CODEC_ILBC
86 if (STR_CASE_CMP(speech_inst.plname, "ilbc") == 0)
125 return rtc_make_scoped_ptr(new AudioEncoderIlbc(speech_inst)); 87 return rtc_make_scoped_ptr(new AudioEncoderIlbc(speech_inst));
126 } else if (IsG722(speech_inst)) { 88 #endif
89 #ifdef WEBRTC_CODEC_G722
90 if (STR_CASE_CMP(speech_inst.plname, "g722") == 0)
127 return rtc_make_scoped_ptr(new AudioEncoderG722(speech_inst)); 91 return rtc_make_scoped_ptr(new AudioEncoderG722(speech_inst));
128 } else { 92 #endif
129 LOG_F(LS_ERROR) << "Could not create encoder of type " 93 LOG_F(LS_ERROR) << "Could not create encoder of type " << speech_inst.plname;
130 << speech_inst.plname; 94 return rtc::scoped_ptr<AudioEncoder>();
131 return rtc::scoped_ptr<AudioEncoder>();
132 }
133 } 95 }
134 96
135 AudioEncoder* CreateRedEncoder(int red_payload_type, 97 AudioEncoder* CreateRedEncoder(int red_payload_type,
136 AudioEncoder* encoder, 98 AudioEncoder* encoder,
137 rtc::scoped_ptr<AudioEncoder>* red_encoder) { 99 rtc::scoped_ptr<AudioEncoder>* red_encoder) {
138 if (red_payload_type == -1) { 100 #ifdef WEBRTC_CODEC_RED
139 red_encoder->reset(); 101 if (red_payload_type != -1) {
140 return encoder; 102 AudioEncoderCopyRed::Config config;
103 config.payload_type = red_payload_type;
104 config.speech_encoder = encoder;
105 red_encoder->reset(new AudioEncoderCopyRed(config));
106 return red_encoder->get();
141 } 107 }
142 AudioEncoderCopyRed::Config config; 108 #endif
143 config.payload_type = red_payload_type; 109
144 config.speech_encoder = encoder; 110 red_encoder->reset();
145 red_encoder->reset(new AudioEncoderCopyRed(config)); 111 return encoder;
146 return red_encoder->get();
147 } 112 }
148 113
149 void CreateCngEncoder(int cng_payload_type, 114 void CreateCngEncoder(int cng_payload_type,
150 ACMVADMode vad_mode, 115 ACMVADMode vad_mode,
151 AudioEncoder* encoder, 116 AudioEncoder* encoder,
152 rtc::scoped_ptr<AudioEncoder>* cng_encoder) { 117 rtc::scoped_ptr<AudioEncoder>* cng_encoder) {
153 if (cng_payload_type == -1) { 118 if (cng_payload_type == -1) {
154 cng_encoder->reset(); 119 cng_encoder->reset();
155 return; 120 return;
156 } 121 }
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 } 204 }
240 205
241 const AudioEncoder* CodecOwner::SpeechEncoder() const { 206 const AudioEncoder* CodecOwner::SpeechEncoder() const {
242 RTC_DCHECK(!speech_encoder_ || !external_speech_encoder_); 207 RTC_DCHECK(!speech_encoder_ || !external_speech_encoder_);
243 return external_speech_encoder_ ? external_speech_encoder_ 208 return external_speech_encoder_ ? external_speech_encoder_
244 : speech_encoder_.get(); 209 : speech_encoder_.get();
245 } 210 }
246 211
247 } // namespace acm2 212 } // namespace acm2
248 } // namespace webrtc 213 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_coding/main/acm2/codec_owner.h ('k') | webrtc/modules/audio_coding/main/audio_coding_module.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698