| OLD | NEW |
| 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 } |
| 49 RTC_DCHECK(audio_format_); |
| 45 if (!decoder_) { | 50 if (!decoder_) { |
| 46 decoder_.reset(CreateAudioDecoder(codec_type)); | 51 decoder_ = factory->MakeAudioDecoder(*audio_format_); |
| 47 } | 52 } |
| 48 RTC_DCHECK(decoder_); | 53 RTC_DCHECK(decoder_) << "Failed to create: " << *audio_format_; |
| 49 return decoder_.get(); | 54 return decoder_.get(); |
| 50 } | 55 } |
| 51 | 56 |
| 52 bool DecoderDatabase::Empty() const { return decoders_.empty(); } | 57 bool DecoderDatabase::Empty() const { return decoders_.empty(); } |
| 53 | 58 |
| 54 int DecoderDatabase::Size() const { return static_cast<int>(decoders_.size()); } | 59 int DecoderDatabase::Size() const { return static_cast<int>(decoders_.size()); } |
| 55 | 60 |
| 56 void DecoderDatabase::Reset() { | 61 void DecoderDatabase::Reset() { |
| 57 decoders_.clear(); | 62 decoders_.clear(); |
| 58 active_decoder_type_ = -1; | 63 active_decoder_type_ = -1; |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 IsComfortNoise(rtp_payload_type)) { | 153 IsComfortNoise(rtp_payload_type)) { |
| 149 // These are not real decoders. | 154 // These are not real decoders. |
| 150 return NULL; | 155 return NULL; |
| 151 } | 156 } |
| 152 DecoderMap::iterator it = decoders_.find(rtp_payload_type); | 157 DecoderMap::iterator it = decoders_.find(rtp_payload_type); |
| 153 if (it == decoders_.end()) { | 158 if (it == decoders_.end()) { |
| 154 // Decoder not found. | 159 // Decoder not found. |
| 155 return NULL; | 160 return NULL; |
| 156 } | 161 } |
| 157 DecoderInfo* info = &(*it).second; | 162 DecoderInfo* info = &(*it).second; |
| 158 return info->GetDecoder(); | 163 return info->GetDecoder(decoder_factory_.get()); |
| 159 } | 164 } |
| 160 | 165 |
| 161 bool DecoderDatabase::IsType(uint8_t rtp_payload_type, | 166 bool DecoderDatabase::IsType(uint8_t rtp_payload_type, |
| 162 NetEqDecoder codec_type) const { | 167 NetEqDecoder codec_type) const { |
| 163 DecoderMap::const_iterator it = decoders_.find(rtp_payload_type); | 168 DecoderMap::const_iterator it = decoders_.find(rtp_payload_type); |
| 164 if (it == decoders_.end()) { | 169 if (it == decoders_.end()) { |
| 165 // Decoder not found. | 170 // Decoder not found. |
| 166 return false; | 171 return false; |
| 167 } | 172 } |
| 168 return ((*it).second.codec_type == codec_type); | 173 return ((*it).second.codec_type == codec_type); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 LOG(LS_WARNING) << "CheckPayloadTypes: unknown RTP payload type " | 274 LOG(LS_WARNING) << "CheckPayloadTypes: unknown RTP payload type " |
| 270 << static_cast<int>((*it)->header.payloadType); | 275 << static_cast<int>((*it)->header.payloadType); |
| 271 return kDecoderNotFound; | 276 return kDecoderNotFound; |
| 272 } | 277 } |
| 273 } | 278 } |
| 274 return kOK; | 279 return kOK; |
| 275 } | 280 } |
| 276 | 281 |
| 277 | 282 |
| 278 } // namespace webrtc | 283 } // namespace webrtc |
| OLD | NEW |