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

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

Issue 2027993002: NetEq: Ask AudioDecoder for sample rate instead of passing it as an argument (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@samprate1
Patch Set: rebase 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 14 matching lines...) Expand all
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) 31 const std::string& nm)
32 : codec_type(ct), 32 : codec_type(ct),
33 name(nm), 33 name(nm),
34 audio_format_(acm2::RentACodec::NetEqDecoderToSdpAudioFormat(ct)), 34 audio_format_(acm2::RentACodec::NetEqDecoderToSdpAudioFormat(ct)),
35 external_decoder_(nullptr),
35 cng_decoder_(CngDecoder::Create(ct)) {} 36 cng_decoder_(CngDecoder::Create(ct)) {}
36 37
37 DecoderDatabase::DecoderInfo::DecoderInfo(NetEqDecoder ct, 38 DecoderDatabase::DecoderInfo::DecoderInfo(NetEqDecoder ct,
38 const std::string& nm, 39 const std::string& nm,
39 int sample_rate_hz,
40 AudioDecoder* ext_dec) 40 AudioDecoder* ext_dec)
41 : codec_type(ct), 41 : codec_type(ct),
42 name(nm), 42 name(nm),
43 audio_format_(acm2::RentACodec::NetEqDecoderToSdpAudioFormat(ct)), 43 audio_format_(acm2::RentACodec::NetEqDecoderToSdpAudioFormat(ct)),
44 external_decoder({sample_rate_hz, ext_dec}) { 44 external_decoder_(ext_dec) {
45 RTC_CHECK(ext_dec); 45 RTC_CHECK(ext_dec);
46 } 46 }
47 47
48 DecoderDatabase::DecoderInfo::DecoderInfo(DecoderInfo&&) = default; 48 DecoderDatabase::DecoderInfo::DecoderInfo(DecoderInfo&&) = default;
49 DecoderDatabase::DecoderInfo::~DecoderInfo() = default; 49 DecoderDatabase::DecoderInfo::~DecoderInfo() = default;
50 50
51 AudioDecoder* DecoderDatabase::DecoderInfo::GetDecoder( 51 AudioDecoder* DecoderDatabase::DecoderInfo::GetDecoder(
52 AudioDecoderFactory* factory) { 52 AudioDecoderFactory* factory) {
53 if (external_decoder) { 53 if (external_decoder_) {
54 RTC_DCHECK(!decoder_); 54 RTC_DCHECK(!decoder_);
55 RTC_DCHECK(external_decoder->decoder); 55 RTC_DCHECK(!cng_decoder_);
56 return external_decoder->decoder; 56 return external_decoder_;
57 } 57 }
58 RTC_DCHECK(audio_format_); 58 RTC_DCHECK(audio_format_);
59 if (!decoder_) { 59 if (!decoder_) {
60 decoder_ = factory->MakeAudioDecoder(*audio_format_); 60 decoder_ = factory->MakeAudioDecoder(*audio_format_);
61 } 61 }
62 RTC_DCHECK(decoder_) << "Failed to create: " << *audio_format_; 62 RTC_DCHECK(decoder_) << "Failed to create: " << *audio_format_;
63 return decoder_.get(); 63 return decoder_.get();
64 } 64 }
65 65
66 rtc::Optional<DecoderDatabase::DecoderInfo::CngDecoder> 66 rtc::Optional<DecoderDatabase::DecoderInfo::CngDecoder>
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 if (ret.second == false) { 108 if (ret.second == false) {
109 // Database already contains a decoder with type |rtp_payload_type|. 109 // Database already contains a decoder with type |rtp_payload_type|.
110 return kDecoderExists; 110 return kDecoderExists;
111 } 111 }
112 return kOK; 112 return kOK;
113 } 113 }
114 114
115 int DecoderDatabase::InsertExternal(uint8_t rtp_payload_type, 115 int DecoderDatabase::InsertExternal(uint8_t rtp_payload_type,
116 NetEqDecoder codec_type, 116 NetEqDecoder codec_type,
117 const std::string& codec_name, 117 const std::string& codec_name,
118 int fs_hz,
119 AudioDecoder* decoder) { 118 AudioDecoder* decoder) {
120 if (rtp_payload_type > 0x7F) { 119 if (rtp_payload_type > 0x7F) {
121 return kInvalidRtpPayloadType; 120 return kInvalidRtpPayloadType;
122 } 121 }
123 if (!CodecSupported(codec_type)) { 122 if (!CodecSupported(codec_type)) {
124 return kCodecNotSupported; 123 return kCodecNotSupported;
125 } 124 }
126 if (fs_hz != 8000 && fs_hz != 16000 && fs_hz != 32000 && fs_hz != 48000) {
127 return kInvalidSampleRate;
128 }
129 if (!decoder) { 125 if (!decoder) {
130 return kInvalidPointer; 126 return kInvalidPointer;
131 } 127 }
132 std::pair<DecoderMap::iterator, bool> ret; 128 std::pair<DecoderMap::iterator, bool> ret;
133 DecoderInfo info(codec_type, codec_name, fs_hz, decoder); 129 DecoderInfo info(codec_type, codec_name, decoder);
134 ret = decoders_.insert(std::make_pair(rtp_payload_type, std::move(info))); 130 ret = decoders_.insert(std::make_pair(rtp_payload_type, std::move(info)));
135 if (ret.second == false) { 131 if (ret.second == false) {
136 // Database already contains a decoder with type |rtp_payload_type|. 132 // Database already contains a decoder with type |rtp_payload_type|.
137 return kDecoderExists; 133 return kDecoderExists;
138 } 134 }
139 return kOK; 135 return kOK;
140 } 136 }
141 137
142 int DecoderDatabase::Remove(uint8_t rtp_payload_type) { 138 int DecoderDatabase::Remove(uint8_t rtp_payload_type) {
143 if (decoders_.erase(rtp_payload_type) == 0) { 139 if (decoders_.erase(rtp_payload_type) == 0) {
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 LOG(LS_WARNING) << "CheckPayloadTypes: unknown RTP payload type " 296 LOG(LS_WARNING) << "CheckPayloadTypes: unknown RTP payload type "
301 << static_cast<int>((*it)->header.payloadType); 297 << static_cast<int>((*it)->header.payloadType);
302 return kDecoderNotFound; 298 return kDecoderNotFound;
303 } 299 }
304 } 300 }
305 return kOK; 301 return kOK;
306 } 302 }
307 303
308 304
309 } // namespace webrtc 305 } // 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