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

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

Issue 1364193002: CodecOwner::SetEncoders: Return error code when given bad arguments (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Add unittest 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/engine_configurations.h" 15 #include "webrtc/engine_configurations.h"
15 #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"
16 #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"
17 #include "webrtc/modules/audio_coding/codecs/g722/include/audio_encoder_g722.h" 18 #include "webrtc/modules/audio_coding/codecs/g722/include/audio_encoder_g722.h"
18 #include "webrtc/modules/audio_coding/codecs/ilbc/interface/audio_encoder_ilbc.h " 19 #include "webrtc/modules/audio_coding/codecs/ilbc/interface/audio_encoder_ilbc.h "
19 #include "webrtc/modules/audio_coding/codecs/isac/fix/interface/audio_decoder_is acfix.h" 20 #include "webrtc/modules/audio_coding/codecs/isac/fix/interface/audio_decoder_is acfix.h"
20 #include "webrtc/modules/audio_coding/codecs/isac/fix/interface/audio_encoder_is acfix.h" 21 #include "webrtc/modules/audio_coding/codecs/isac/fix/interface/audio_encoder_is acfix.h"
21 #include "webrtc/modules/audio_coding/codecs/isac/main/interface/audio_decoder_i sac.h" 22 #include "webrtc/modules/audio_coding/codecs/isac/main/interface/audio_decoder_i sac.h"
22 #include "webrtc/modules/audio_coding/codecs/isac/main/interface/audio_encoder_i sac.h" 23 #include "webrtc/modules/audio_coding/codecs/isac/main/interface/audio_encoder_i sac.h"
23 #include "webrtc/modules/audio_coding/codecs/opus/interface/audio_encoder_opus.h " 24 #include "webrtc/modules/audio_coding/codecs/opus/interface/audio_encoder_opus.h "
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 #if defined(WEBRTC_CODEC_ISACFX) 99 #if defined(WEBRTC_CODEC_ISACFX)
99 return rtc_make_scoped_ptr(new AudioEncoderIsacFix(speech_inst, bwinfo)); 100 return rtc_make_scoped_ptr(new AudioEncoderIsacFix(speech_inst, bwinfo));
100 #elif defined(WEBRTC_CODEC_ISAC) 101 #elif defined(WEBRTC_CODEC_ISAC)
101 return rtc_make_scoped_ptr(new AudioEncoderIsac(speech_inst, bwinfo)); 102 return rtc_make_scoped_ptr(new AudioEncoderIsac(speech_inst, bwinfo));
102 #else 103 #else
103 FATAL() << "iSAC is not supported."; 104 FATAL() << "iSAC is not supported.";
104 return rtc::scoped_ptr<AudioEncoderMutable>(); 105 return rtc::scoped_ptr<AudioEncoderMutable>();
105 #endif 106 #endif
106 } 107 }
107 108
109 // Returns a new speech encoder, or null on error.
110 // TODO(kwiberg): Don't handle errors here (bug 5033)
108 rtc::scoped_ptr<AudioEncoder> CreateSpeechEncoder( 111 rtc::scoped_ptr<AudioEncoder> CreateSpeechEncoder(
109 const CodecInst& speech_inst, 112 const CodecInst& speech_inst,
110 LockedIsacBandwidthInfo* bwinfo) { 113 LockedIsacBandwidthInfo* bwinfo) {
111 if (IsIsac(speech_inst)) { 114 if (IsIsac(speech_inst)) {
112 return CreateIsacEncoder(speech_inst, bwinfo); 115 return CreateIsacEncoder(speech_inst, bwinfo);
113 } else if (IsOpus(speech_inst)) { 116 } else if (IsOpus(speech_inst)) {
114 return rtc_make_scoped_ptr(new AudioEncoderOpus(speech_inst)); 117 return rtc_make_scoped_ptr(new AudioEncoderOpus(speech_inst));
115 } else if (IsPcmU(speech_inst)) { 118 } else if (IsPcmU(speech_inst)) {
116 return rtc_make_scoped_ptr(new AudioEncoderPcmU(speech_inst)); 119 return rtc_make_scoped_ptr(new AudioEncoderPcmU(speech_inst));
117 } else if (IsPcmA(speech_inst)) { 120 } else if (IsPcmA(speech_inst)) {
118 return rtc_make_scoped_ptr(new AudioEncoderPcmA(speech_inst)); 121 return rtc_make_scoped_ptr(new AudioEncoderPcmA(speech_inst));
119 } else if (IsPcm16B(speech_inst)) { 122 } else if (IsPcm16B(speech_inst)) {
120 return rtc_make_scoped_ptr(new AudioEncoderPcm16B(speech_inst)); 123 return rtc_make_scoped_ptr(new AudioEncoderPcm16B(speech_inst));
121 } else if (IsIlbc(speech_inst)) { 124 } else if (IsIlbc(speech_inst)) {
122 return rtc_make_scoped_ptr(new AudioEncoderIlbc(speech_inst)); 125 return rtc_make_scoped_ptr(new AudioEncoderIlbc(speech_inst));
123 } else if (IsG722(speech_inst)) { 126 } else if (IsG722(speech_inst)) {
124 return rtc_make_scoped_ptr(new AudioEncoderG722(speech_inst)); 127 return rtc_make_scoped_ptr(new AudioEncoderG722(speech_inst));
125 } else { 128 } else {
126 FATAL() << "Could not create encoder of type " << speech_inst.plname; 129 LOG_F(LS_ERROR) << "Could not create encoder of type "
130 << speech_inst.plname;
127 return rtc::scoped_ptr<AudioEncoder>(); 131 return rtc::scoped_ptr<AudioEncoder>();
128 } 132 }
129 } 133 }
130 134
131 AudioEncoder* CreateRedEncoder(int red_payload_type, 135 AudioEncoder* CreateRedEncoder(int red_payload_type,
132 AudioEncoder* encoder, 136 AudioEncoder* encoder,
133 rtc::scoped_ptr<AudioEncoder>* red_encoder) { 137 rtc::scoped_ptr<AudioEncoder>* red_encoder) {
134 if (red_payload_type == -1) { 138 if (red_payload_type == -1) {
135 red_encoder->reset(); 139 red_encoder->reset();
136 return encoder; 140 return encoder;
(...skipping 30 matching lines...) Expand all
167 case VADVeryAggr: 171 case VADVeryAggr:
168 config.vad_mode = Vad::kVadVeryAggressive; 172 config.vad_mode = Vad::kVadVeryAggressive;
169 break; 173 break;
170 default: 174 default:
171 FATAL(); 175 FATAL();
172 } 176 }
173 cng_encoder->reset(new AudioEncoderCng(config)); 177 cng_encoder->reset(new AudioEncoderCng(config));
174 } 178 }
175 } // namespace 179 } // namespace
176 180
177 void CodecOwner::SetEncoders(const CodecInst& speech_inst, 181 bool CodecOwner::SetEncoders(const CodecInst& speech_inst,
178 int cng_payload_type, 182 int cng_payload_type,
179 ACMVADMode vad_mode, 183 ACMVADMode vad_mode,
180 int red_payload_type) { 184 int red_payload_type) {
181 speech_encoder_ = CreateSpeechEncoder(speech_inst, &isac_bandwidth_info_); 185 speech_encoder_ = CreateSpeechEncoder(speech_inst, &isac_bandwidth_info_);
186 if (!speech_encoder_)
187 return false;
182 external_speech_encoder_ = nullptr; 188 external_speech_encoder_ = nullptr;
183 ChangeCngAndRed(cng_payload_type, vad_mode, red_payload_type); 189 ChangeCngAndRed(cng_payload_type, vad_mode, red_payload_type);
190 return true;
184 } 191 }
185 192
186 void CodecOwner::SetEncoders(AudioEncoder* external_speech_encoder, 193 void CodecOwner::SetEncoders(AudioEncoder* external_speech_encoder,
187 int cng_payload_type, 194 int cng_payload_type,
188 ACMVADMode vad_mode, 195 ACMVADMode vad_mode,
189 int red_payload_type) { 196 int red_payload_type) {
190 external_speech_encoder_ = external_speech_encoder; 197 external_speech_encoder_ = external_speech_encoder;
191 speech_encoder_.reset(); 198 speech_encoder_.reset();
192 ChangeCngAndRed(cng_payload_type, vad_mode, red_payload_type); 199 ChangeCngAndRed(cng_payload_type, vad_mode, red_payload_type);
193 } 200 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 } 239 }
233 240
234 const AudioEncoder* CodecOwner::SpeechEncoder() const { 241 const AudioEncoder* CodecOwner::SpeechEncoder() const {
235 RTC_DCHECK(!speech_encoder_ || !external_speech_encoder_); 242 RTC_DCHECK(!speech_encoder_ || !external_speech_encoder_);
236 return external_speech_encoder_ ? external_speech_encoder_ 243 return external_speech_encoder_ ? external_speech_encoder_
237 : speech_encoder_.get(); 244 : speech_encoder_.get();
238 } 245 }
239 246
240 } // namespace acm2 247 } // namespace acm2
241 } // namespace webrtc 248 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698