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

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

Issue 1410333015: Let Rent-A-Codec™ create and own speech encoders (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@rac5
Patch Set: comment fix Created 5 years, 1 month 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
« no previous file with comments | « webrtc/modules/audio_coding/main/acm2/rent_a_codec.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/rent_a_codec.h" 11 #include "webrtc/modules/audio_coding/main/acm2/rent_a_codec.h"
12 12
13 #include "webrtc/base/logging.h"
14 #include "webrtc/modules/audio_coding/codecs/g711/include/audio_encoder_pcm.h"
15 #ifdef WEBRTC_CODEC_G722
16 #include "webrtc/modules/audio_coding/codecs/g722/include/audio_encoder_g722.h"
17 #endif
18 #ifdef WEBRTC_CODEC_ILBC
19 #include "webrtc/modules/audio_coding/codecs/ilbc/include/audio_encoder_ilbc.h"
20 #endif
21 #ifdef WEBRTC_CODEC_ISACFX
22 #include "webrtc/modules/audio_coding/codecs/isac/fix/include/audio_decoder_isac fix.h"
23 #include "webrtc/modules/audio_coding/codecs/isac/fix/include/audio_encoder_isac fix.h"
24 #endif
25 #ifdef WEBRTC_CODEC_ISAC
26 #include "webrtc/modules/audio_coding/codecs/isac/main/include/audio_decoder_isa c.h"
27 #include "webrtc/modules/audio_coding/codecs/isac/main/include/audio_encoder_isa c.h"
28 #endif
29 #ifdef WEBRTC_CODEC_OPUS
30 #include "webrtc/modules/audio_coding/codecs/opus/include/audio_encoder_opus.h"
31 #endif
32 #include "webrtc/modules/audio_coding/codecs/pcm16b/include/audio_encoder_pcm16b .h"
13 #include "webrtc/modules/audio_coding/main/acm2/acm_codec_database.h" 33 #include "webrtc/modules/audio_coding/main/acm2/acm_codec_database.h"
14 #include "webrtc/modules/audio_coding/main/acm2/acm_common_defs.h" 34 #include "webrtc/modules/audio_coding/main/acm2/acm_common_defs.h"
15 35
16 namespace webrtc { 36 namespace webrtc {
17 namespace acm2 { 37 namespace acm2 {
18 38
19 rtc::Maybe<RentACodec::CodecId> RentACodec::CodecIdByParams( 39 rtc::Maybe<RentACodec::CodecId> RentACodec::CodecIdByParams(
20 const char* payload_name, 40 const char* payload_name,
21 int sampling_freq_hz, 41 int sampling_freq_hz,
22 int channels) { 42 int channels) {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 rtc::Maybe<int> i = CodecIndexFromId(codec_id); 93 rtc::Maybe<int> i = CodecIndexFromId(codec_id);
74 if (!i) 94 if (!i)
75 return rtc::Maybe<NetEqDecoder>(); 95 return rtc::Maybe<NetEqDecoder>();
76 const NetEqDecoder ned = ACMCodecDB::neteq_decoders_[*i]; 96 const NetEqDecoder ned = ACMCodecDB::neteq_decoders_[*i];
77 return rtc::Maybe<NetEqDecoder>( 97 return rtc::Maybe<NetEqDecoder>(
78 (ned == NetEqDecoder::kDecoderOpus && num_channels == 2) 98 (ned == NetEqDecoder::kDecoderOpus && num_channels == 2)
79 ? NetEqDecoder::kDecoderOpus_2ch 99 ? NetEqDecoder::kDecoderOpus_2ch
80 : ned); 100 : ned);
81 } 101 }
82 102
103 namespace {
104
105 // Returns a new speech encoder, or null on error.
106 // TODO(kwiberg): Don't handle errors here (bug 5033)
107 rtc::scoped_ptr<AudioEncoder> CreateEncoder(
108 const CodecInst& speech_inst,
109 LockedIsacBandwidthInfo* bwinfo) {
110 #if defined(WEBRTC_CODEC_ISACFX)
111 if (STR_CASE_CMP(speech_inst.plname, "isac") == 0)
112 return rtc_make_scoped_ptr(new AudioEncoderIsacFix(speech_inst, bwinfo));
113 #endif
114 #if defined(WEBRTC_CODEC_ISAC)
115 if (STR_CASE_CMP(speech_inst.plname, "isac") == 0)
116 return rtc_make_scoped_ptr(new AudioEncoderIsac(speech_inst, bwinfo));
117 #endif
118 #ifdef WEBRTC_CODEC_OPUS
119 if (STR_CASE_CMP(speech_inst.plname, "opus") == 0)
120 return rtc_make_scoped_ptr(new AudioEncoderOpus(speech_inst));
121 #endif
122 if (STR_CASE_CMP(speech_inst.plname, "pcmu") == 0)
123 return rtc_make_scoped_ptr(new AudioEncoderPcmU(speech_inst));
124 if (STR_CASE_CMP(speech_inst.plname, "pcma") == 0)
125 return rtc_make_scoped_ptr(new AudioEncoderPcmA(speech_inst));
126 if (STR_CASE_CMP(speech_inst.plname, "l16") == 0)
127 return rtc_make_scoped_ptr(new AudioEncoderPcm16B(speech_inst));
128 #ifdef WEBRTC_CODEC_ILBC
129 if (STR_CASE_CMP(speech_inst.plname, "ilbc") == 0)
130 return rtc_make_scoped_ptr(new AudioEncoderIlbc(speech_inst));
131 #endif
132 #ifdef WEBRTC_CODEC_G722
133 if (STR_CASE_CMP(speech_inst.plname, "g722") == 0)
134 return rtc_make_scoped_ptr(new AudioEncoderG722(speech_inst));
135 #endif
136 LOG_F(LS_ERROR) << "Could not create encoder of type " << speech_inst.plname;
137 return rtc::scoped_ptr<AudioEncoder>();
138 }
139
140 rtc::scoped_ptr<AudioDecoder> CreateIsacDecoder(
141 LockedIsacBandwidthInfo* bwinfo) {
142 #if defined(WEBRTC_CODEC_ISACFX)
143 return rtc_make_scoped_ptr(new AudioDecoderIsacFix(bwinfo));
144 #elif defined(WEBRTC_CODEC_ISAC)
145 return rtc_make_scoped_ptr(new AudioDecoderIsac(bwinfo));
146 #else
147 FATAL() << "iSAC is not supported.";
148 return rtc::scoped_ptr<AudioDecoder>();
149 #endif
150 }
151
152 } // namespace
153
154 RentACodec::RentACodec() = default;
155 RentACodec::~RentACodec() = default;
156
157 AudioEncoder* RentACodec::RentEncoder(const CodecInst& codec_inst) {
158 rtc::scoped_ptr<AudioEncoder> enc =
159 CreateEncoder(codec_inst, &isac_bandwidth_info_);
160 if (!enc)
161 return nullptr;
162 encoder_ = enc.Pass();
163 return encoder_.get();
164 }
165
166 AudioDecoder* RentACodec::RentIsacDecoder() {
167 if (!isac_decoder_)
168 isac_decoder_ = CreateIsacDecoder(&isac_bandwidth_info_);
169 return isac_decoder_.get();
170 }
171
83 } // namespace acm2 172 } // namespace acm2
84 } // namespace webrtc 173 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_coding/main/acm2/rent_a_codec.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698