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

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

Issue 2021063002: NetEq decoder database: Don't keep track of sample rate for builtin decoders (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@decoder-samp-rate
Patch Set: explicit capture Created 4 years, 6 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
(...skipping 10 matching lines...) Expand all
21 21
22 DecoderDatabase::DecoderDatabase( 22 DecoderDatabase::DecoderDatabase(
23 const rtc::scoped_refptr<AudioDecoderFactory>& decoder_factory) 23 const rtc::scoped_refptr<AudioDecoderFactory>& decoder_factory)
24 : active_decoder_type_(-1), 24 : active_decoder_type_(-1),
25 active_cng_decoder_type_(-1), 25 active_cng_decoder_type_(-1),
26 decoder_factory_(decoder_factory) {} 26 decoder_factory_(decoder_factory) {}
27 27
28 DecoderDatabase::~DecoderDatabase() = default; 28 DecoderDatabase::~DecoderDatabase() = default;
29 29
30 DecoderDatabase::DecoderInfo::DecoderInfo(NetEqDecoder ct, 30 DecoderDatabase::DecoderInfo::DecoderInfo(NetEqDecoder ct,
31 const std::string& nm)
32 : codec_type(ct),
33 name(nm),
34 audio_format_(acm2::RentACodec::NetEqDecoderToSdpAudioFormat(ct)),
35 cng_decoder_(CngDecoder::Create(ct)) {}
36
37 DecoderDatabase::DecoderInfo::DecoderInfo(NetEqDecoder ct,
31 const std::string& nm, 38 const std::string& nm,
32 int fs, 39 int sample_rate_hz,
33 AudioDecoder* ext_dec) 40 AudioDecoder* ext_dec)
34 : codec_type(ct), 41 : codec_type(ct),
35 name(nm), 42 name(nm),
36 fs_hz(fs), 43 audio_format_(acm2::RentACodec::NetEqDecoderToSdpAudioFormat(ct)),
37 external_decoder(ext_dec), 44 external_decoder({sample_rate_hz, ext_dec}) {
38 audio_format_(acm2::RentACodec::NetEqDecoderToSdpAudioFormat(ct)) {} 45 RTC_CHECK(ext_dec);
46 }
39 47
40 DecoderDatabase::DecoderInfo::DecoderInfo(DecoderInfo&&) = default; 48 DecoderDatabase::DecoderInfo::DecoderInfo(DecoderInfo&&) = default;
41 DecoderDatabase::DecoderInfo::~DecoderInfo() = default; 49 DecoderDatabase::DecoderInfo::~DecoderInfo() = default;
42 50
43 AudioDecoder* DecoderDatabase::DecoderInfo::GetDecoder( 51 AudioDecoder* DecoderDatabase::DecoderInfo::GetDecoder(
44 AudioDecoderFactory* factory) { 52 AudioDecoderFactory* factory) {
45 if (external_decoder) { 53 if (external_decoder) {
46 RTC_DCHECK(!decoder_); 54 RTC_DCHECK(!decoder_);
47 return external_decoder; 55 RTC_DCHECK(external_decoder->decoder);
56 return external_decoder->decoder;
48 } 57 }
49 RTC_DCHECK(audio_format_); 58 RTC_DCHECK(audio_format_);
50 if (!decoder_) { 59 if (!decoder_) {
51 decoder_ = factory->MakeAudioDecoder(*audio_format_); 60 decoder_ = factory->MakeAudioDecoder(*audio_format_);
52 } 61 }
53 RTC_DCHECK(decoder_) << "Failed to create: " << *audio_format_; 62 RTC_DCHECK(decoder_) << "Failed to create: " << *audio_format_;
54 return decoder_.get(); 63 return decoder_.get();
55 } 64 }
56 65
66 rtc::Optional<DecoderDatabase::DecoderInfo::CngDecoder>
67 DecoderDatabase::DecoderInfo::CngDecoder::Create(NetEqDecoder ct) {
68 const auto cng = [](int sample_rate_hz) {
69 return rtc::Optional<DecoderDatabase::DecoderInfo::CngDecoder>(
70 {sample_rate_hz});
71 };
72 switch (ct) {
73 case NetEqDecoder::kDecoderCNGnb:
74 return cng(8000);
75 case NetEqDecoder::kDecoderCNGwb:
76 return cng(16000);
77 case NetEqDecoder::kDecoderCNGswb32kHz:
78 return cng(32000);
79 case NetEqDecoder::kDecoderCNGswb48kHz:
80 return cng(48000);
81 default:
82 return rtc::Optional<DecoderDatabase::DecoderInfo::CngDecoder>();
83 }
84 }
85
57 bool DecoderDatabase::Empty() const { return decoders_.empty(); } 86 bool DecoderDatabase::Empty() const { return decoders_.empty(); }
58 87
59 int DecoderDatabase::Size() const { return static_cast<int>(decoders_.size()); } 88 int DecoderDatabase::Size() const { return static_cast<int>(decoders_.size()); }
60 89
61 void DecoderDatabase::Reset() { 90 void DecoderDatabase::Reset() {
62 decoders_.clear(); 91 decoders_.clear();
63 active_decoder_type_ = -1; 92 active_decoder_type_ = -1;
64 active_cng_decoder_type_ = -1; 93 active_cng_decoder_type_ = -1;
65 } 94 }
66 95
67 int DecoderDatabase::RegisterPayload(uint8_t rtp_payload_type, 96 int DecoderDatabase::RegisterPayload(uint8_t rtp_payload_type,
68 NetEqDecoder codec_type, 97 NetEqDecoder codec_type,
69 const std::string& name) { 98 const std::string& name) {
70 if (rtp_payload_type > 0x7F) { 99 if (rtp_payload_type > 0x7F) {
71 return kInvalidRtpPayloadType; 100 return kInvalidRtpPayloadType;
72 } 101 }
73 if (!CodecSupported(codec_type)) { 102 if (!CodecSupported(codec_type)) {
74 return kCodecNotSupported; 103 return kCodecNotSupported;
75 } 104 }
76 const int fs_hz = CodecSampleRateHz(codec_type); 105 DecoderInfo info(codec_type, name);
77 DecoderInfo info(codec_type, name, fs_hz, nullptr);
78 auto ret = 106 auto ret =
79 decoders_.insert(std::make_pair(rtp_payload_type, std::move(info))); 107 decoders_.insert(std::make_pair(rtp_payload_type, std::move(info)));
80 if (ret.second == false) { 108 if (ret.second == false) {
81 // Database already contains a decoder with type |rtp_payload_type|. 109 // Database already contains a decoder with type |rtp_payload_type|.
82 return kDecoderExists; 110 return kDecoderExists;
83 } 111 }
84 return kOK; 112 return kOK;
85 } 113 }
86 114
87 int DecoderDatabase::InsertExternal(uint8_t rtp_payload_type, 115 int DecoderDatabase::InsertExternal(uint8_t rtp_payload_type,
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 } 268 }
241 if (active_cng_decoder_type_ >= 0 && 269 if (active_cng_decoder_type_ >= 0 &&
242 active_cng_decoder_type_ != rtp_payload_type) { 270 active_cng_decoder_type_ != rtp_payload_type) {
243 // Moving from one active CNG decoder to another. Delete the first one. 271 // Moving from one active CNG decoder to another. Delete the first one.
244 DecoderMap::iterator it = decoders_.find(active_cng_decoder_type_); 272 DecoderMap::iterator it = decoders_.find(active_cng_decoder_type_);
245 if (it == decoders_.end()) { 273 if (it == decoders_.end()) {
246 // Decoder not found. This should not be possible. 274 // Decoder not found. This should not be possible.
247 assert(false); 275 assert(false);
248 return kDecoderNotFound; 276 return kDecoderNotFound;
249 } 277 }
250 // The CNG decoder should never be provided externally.
251 RTC_CHECK(!it->second.external_decoder);
252 active_cng_decoder_.reset(); 278 active_cng_decoder_.reset();
253 } 279 }
254 active_cng_decoder_type_ = rtp_payload_type; 280 active_cng_decoder_type_ = rtp_payload_type;
255 return kOK; 281 return kOK;
256 } 282 }
257 283
258 ComfortNoiseDecoder* DecoderDatabase::GetActiveCngDecoder() { 284 ComfortNoiseDecoder* DecoderDatabase::GetActiveCngDecoder() {
259 if (active_cng_decoder_type_ < 0) { 285 if (active_cng_decoder_type_ < 0) {
260 // No active CNG decoder. 286 // No active CNG decoder.
261 return NULL; 287 return NULL;
(...skipping 12 matching lines...) Expand all
274 LOG(LS_WARNING) << "CheckPayloadTypes: unknown RTP payload type " 300 LOG(LS_WARNING) << "CheckPayloadTypes: unknown RTP payload type "
275 << static_cast<int>((*it)->header.payloadType); 301 << static_cast<int>((*it)->header.payloadType);
276 return kDecoderNotFound; 302 return kDecoderNotFound;
277 } 303 }
278 } 304 }
279 return kOK; 305 return kOK;
280 } 306 }
281 307
282 308
283 } // namespace webrtc 309 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_coding/neteq/decoder_database.h ('k') | webrtc/modules/audio_coding/neteq/decoder_database_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698