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

Side by Side Diff: webrtc/modules/audio_coding/neteq/decoder_database.cc

Issue 1928293002: NetEq: Use a BuiltinAudioDecoderFactory to create decoders (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 7 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) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 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/neteq/decoder_database.h" 11 #include "webrtc/modules/audio_coding/neteq/decoder_database.h"
12 12
13 #include <assert.h> 13 #include <assert.h>
14 #include <utility> // pair 14 #include <utility> // pair
15 15
16 #include "webrtc/base/checks.h" 16 #include "webrtc/base/checks.h"
17 #include "webrtc/base/logging.h" 17 #include "webrtc/base/logging.h"
18 #include "webrtc/modules/audio_coding/codecs/audio_decoder.h" 18 #include "webrtc/modules/audio_coding/codecs/audio_decoder.h"
19 19
20 namespace webrtc { 20 namespace webrtc {
21 21
22 DecoderDatabase::DecoderDatabase() 22 DecoderDatabase::DecoderDatabase(
23 : active_decoder_type_(-1), active_cng_decoder_type_(-1) { 23 std::unique_ptr<AudioDecoderFactory> decoder_factory)
24 } 24 : active_decoder_type_(-1),
25 active_cng_decoder_type_(-1),
26 decoder_factory_(std::move(decoder_factory)) {}
25 27
26 DecoderDatabase::~DecoderDatabase() = default; 28 DecoderDatabase::~DecoderDatabase() = default;
27 29
28 DecoderDatabase::DecoderInfo::DecoderInfo(NetEqDecoder ct, 30 DecoderDatabase::DecoderInfo::DecoderInfo(NetEqDecoder ct,
29 const std::string& nm, 31 const std::string& nm,
30 int fs, 32 int fs,
31 AudioDecoder* ext_dec) 33 AudioDecoder* ext_dec)
32 : codec_type(ct), 34 : codec_type(ct),
33 name(nm), 35 name(nm),
34 fs_hz(fs), 36 fs_hz(fs),
35 external_decoder(ext_dec) {} 37 external_decoder(ext_dec),
38 audio_format_(acm2::RentACodec::NetEqDecoderToSdpAudioFormat(ct)) {}
36 39
37 DecoderDatabase::DecoderInfo::DecoderInfo(DecoderInfo&&) = default; 40 DecoderDatabase::DecoderInfo::DecoderInfo(DecoderInfo&&) = default;
38 DecoderDatabase::DecoderInfo::~DecoderInfo() = default; 41 DecoderDatabase::DecoderInfo::~DecoderInfo() = default;
39 42
40 AudioDecoder* DecoderDatabase::DecoderInfo::GetDecoder() { 43 AudioDecoder* DecoderDatabase::DecoderInfo::GetDecoder(
44 AudioDecoderFactory* factory) {
41 if (external_decoder) { 45 if (external_decoder) {
42 RTC_DCHECK(!decoder_); 46 RTC_DCHECK(!decoder_);
43 return external_decoder; 47 return external_decoder;
44 } 48 }
45 if (!decoder_) { 49 if (!decoder_ && audio_format_) {
46 decoder_.reset(CreateAudioDecoder(codec_type)); 50 decoder_ = factory->MakeAudioDecoder(*audio_format_);
51 RTC_DCHECK(decoder_) << "Failed to create: " << *audio_format_;
47 } 52 }
48 RTC_DCHECK(decoder_);
49 return decoder_.get(); 53 return decoder_.get();
hlundin-webrtc 2016/04/29 11:52:56 So now we can end up returning no decoder without
kwiberg-webrtc 2016/04/29 23:10:13 I... ummm... oh, look over there! A pink elephant!
hlundin-webrtc 2016/05/02 07:54:42 Where? What!?
50 } 54 }
51 55
52 bool DecoderDatabase::Empty() const { return decoders_.empty(); } 56 bool DecoderDatabase::Empty() const { return decoders_.empty(); }
53 57
54 int DecoderDatabase::Size() const { return static_cast<int>(decoders_.size()); } 58 int DecoderDatabase::Size() const { return static_cast<int>(decoders_.size()); }
55 59
56 void DecoderDatabase::Reset() { 60 void DecoderDatabase::Reset() {
57 decoders_.clear(); 61 decoders_.clear();
58 active_decoder_type_ = -1; 62 active_decoder_type_ = -1;
59 active_cng_decoder_type_ = -1; 63 active_cng_decoder_type_ = -1;
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 IsComfortNoise(rtp_payload_type)) { 152 IsComfortNoise(rtp_payload_type)) {
149 // These are not real decoders. 153 // These are not real decoders.
150 return NULL; 154 return NULL;
151 } 155 }
152 DecoderMap::iterator it = decoders_.find(rtp_payload_type); 156 DecoderMap::iterator it = decoders_.find(rtp_payload_type);
153 if (it == decoders_.end()) { 157 if (it == decoders_.end()) {
154 // Decoder not found. 158 // Decoder not found.
155 return NULL; 159 return NULL;
156 } 160 }
157 DecoderInfo* info = &(*it).second; 161 DecoderInfo* info = &(*it).second;
158 return info->GetDecoder(); 162 return info->GetDecoder(decoder_factory_.get());
159 } 163 }
160 164
161 bool DecoderDatabase::IsType(uint8_t rtp_payload_type, 165 bool DecoderDatabase::IsType(uint8_t rtp_payload_type,
162 NetEqDecoder codec_type) const { 166 NetEqDecoder codec_type) const {
163 DecoderMap::const_iterator it = decoders_.find(rtp_payload_type); 167 DecoderMap::const_iterator it = decoders_.find(rtp_payload_type);
164 if (it == decoders_.end()) { 168 if (it == decoders_.end()) {
165 // Decoder not found. 169 // Decoder not found.
166 return false; 170 return false;
167 } 171 }
168 return ((*it).second.codec_type == codec_type); 172 return ((*it).second.codec_type == codec_type);
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 LOG(LS_WARNING) << "CheckPayloadTypes: unknown RTP payload type " 273 LOG(LS_WARNING) << "CheckPayloadTypes: unknown RTP payload type "
270 << static_cast<int>((*it)->header.payloadType); 274 << static_cast<int>((*it)->header.payloadType);
271 return kDecoderNotFound; 275 return kDecoderNotFound;
272 } 276 }
273 } 277 }
274 return kOK; 278 return kOK;
275 } 279 }
276 280
277 281
278 } // namespace webrtc 282 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698