| 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 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 active_cng_decoder_type_(-1), | 24 active_cng_decoder_type_(-1), |
| 25 decoder_factory_(decoder_factory) {} | 25 decoder_factory_(decoder_factory) {} |
| 26 | 26 |
| 27 DecoderDatabase::~DecoderDatabase() = default; | 27 DecoderDatabase::~DecoderDatabase() = default; |
| 28 | 28 |
| 29 DecoderDatabase::DecoderInfo::DecoderInfo(const SdpAudioFormat& audio_format, | 29 DecoderDatabase::DecoderInfo::DecoderInfo(const SdpAudioFormat& audio_format, |
| 30 AudioDecoderFactory* factory) | 30 AudioDecoderFactory* factory) |
| 31 : audio_format_(audio_format), | 31 : audio_format_(audio_format), |
| 32 factory_(factory), | 32 factory_(factory), |
| 33 external_decoder_(nullptr), | 33 external_decoder_(nullptr), |
| 34 cng_decoder_(CngDecoder::Create(audio_format)) {} | 34 cng_decoder_(CngDecoder::Create(audio_format)), |
| 35 subtype_(SubtypeFromFormat(audio_format)) {} |
| 35 | 36 |
| 36 DecoderDatabase::DecoderInfo::DecoderInfo(NetEqDecoder ct, | 37 DecoderDatabase::DecoderInfo::DecoderInfo(NetEqDecoder ct, |
| 37 AudioDecoderFactory* factory) | 38 AudioDecoderFactory* factory) |
| 38 : audio_format_(*acm2::RentACodec::NetEqDecoderToSdpAudioFormat(ct)), | 39 : audio_format_(*acm2::RentACodec::NetEqDecoderToSdpAudioFormat(ct)), |
| 39 factory_(factory), | 40 factory_(factory), |
| 40 external_decoder_(nullptr), | 41 external_decoder_(nullptr), |
| 41 cng_decoder_(CngDecoder::Create(audio_format_)) {} | 42 cng_decoder_(CngDecoder::Create(audio_format_)), |
| 43 subtype_(SubtypeFromFormat(audio_format_)) {} |
| 42 | 44 |
| 43 DecoderDatabase::DecoderInfo::DecoderInfo(const SdpAudioFormat& audio_format, | 45 DecoderDatabase::DecoderInfo::DecoderInfo(const SdpAudioFormat& audio_format, |
| 44 AudioDecoder* ext_dec) | 46 AudioDecoder* ext_dec) |
| 45 : audio_format_(audio_format), | 47 : audio_format_(audio_format), |
| 46 factory_(nullptr), | 48 factory_(nullptr), |
| 47 external_decoder_(ext_dec) { | 49 external_decoder_(ext_dec), |
| 50 subtype_(Subtype::kNormal) { |
| 48 RTC_CHECK(ext_dec); | 51 RTC_CHECK(ext_dec); |
| 49 } | 52 } |
| 50 | 53 |
| 51 DecoderDatabase::DecoderInfo::DecoderInfo(DecoderInfo&&) = default; | 54 DecoderDatabase::DecoderInfo::DecoderInfo(DecoderInfo&&) = default; |
| 52 DecoderDatabase::DecoderInfo::~DecoderInfo() = default; | 55 DecoderDatabase::DecoderInfo::~DecoderInfo() = default; |
| 53 | 56 |
| 54 AudioDecoder* DecoderDatabase::DecoderInfo::GetDecoder() const { | 57 AudioDecoder* DecoderDatabase::DecoderInfo::GetDecoder() const { |
| 55 if (IsDtmf() || IsRed() || IsComfortNoise()) { | 58 if (subtype_ != Subtype::kNormal) { |
| 56 // These are handled internally, so they have no AudioDecoder objects. | 59 // These are handled internally, so they have no AudioDecoder objects. |
| 57 return nullptr; | 60 return nullptr; |
| 58 } | 61 } |
| 59 if (external_decoder_) { | 62 if (external_decoder_) { |
| 60 RTC_DCHECK(!decoder_); | 63 RTC_DCHECK(!decoder_); |
| 61 RTC_DCHECK(!cng_decoder_); | 64 RTC_DCHECK(!cng_decoder_); |
| 62 return external_decoder_; | 65 return external_decoder_; |
| 63 } | 66 } |
| 64 if (!decoder_) { | 67 if (!decoder_) { |
| 65 // TODO(ossu): Keep a check here for now, since a number of tests create | 68 // TODO(ossu): Keep a check here for now, since a number of tests create |
| 66 // DecoderInfos without factories. | 69 // DecoderInfos without factories. |
| 67 RTC_DCHECK(factory_); | 70 RTC_DCHECK(factory_); |
| 68 decoder_ = factory_->MakeAudioDecoder(audio_format_); | 71 decoder_ = factory_->MakeAudioDecoder(audio_format_); |
| 69 } | 72 } |
| 70 RTC_DCHECK(decoder_) << "Failed to create: " << audio_format_; | 73 RTC_DCHECK(decoder_) << "Failed to create: " << audio_format_; |
| 71 return decoder_.get(); | 74 return decoder_.get(); |
| 72 } | 75 } |
| 73 | 76 |
| 74 bool DecoderDatabase::DecoderInfo::IsComfortNoise() const { | |
| 75 RTC_DCHECK_EQ(!!cng_decoder_, IsType("CN")); | |
| 76 return !!cng_decoder_; | |
| 77 } | |
| 78 | |
| 79 bool DecoderDatabase::DecoderInfo::IsDtmf() const { | |
| 80 return IsType("telephone-event"); | |
| 81 } | |
| 82 | |
| 83 bool DecoderDatabase::DecoderInfo::IsRed() const { | |
| 84 return IsType("red"); | |
| 85 } | |
| 86 | |
| 87 bool DecoderDatabase::DecoderInfo::IsType(const char* name) const { | 77 bool DecoderDatabase::DecoderInfo::IsType(const char* name) const { |
| 88 return STR_CASE_CMP(audio_format_.name.c_str(), name) == 0; | 78 return STR_CASE_CMP(audio_format_.name.c_str(), name) == 0; |
| 89 } | 79 } |
| 90 | 80 |
| 91 bool DecoderDatabase::DecoderInfo::IsType(const std::string& name) const { | 81 bool DecoderDatabase::DecoderInfo::IsType(const std::string& name) const { |
| 92 return IsType(name.c_str()); | 82 return IsType(name.c_str()); |
| 93 } | 83 } |
| 94 | 84 |
| 95 rtc::Optional<DecoderDatabase::DecoderInfo::CngDecoder> | 85 rtc::Optional<DecoderDatabase::DecoderInfo::CngDecoder> |
| 96 DecoderDatabase::DecoderInfo::CngDecoder::Create(const SdpAudioFormat& format) { | 86 DecoderDatabase::DecoderInfo::CngDecoder::Create(const SdpAudioFormat& format) { |
| 97 if (STR_CASE_CMP(format.name.c_str(), "CN") == 0) { | 87 if (STR_CASE_CMP(format.name.c_str(), "CN") == 0) { |
| 98 return rtc::Optional<CngDecoder>({format.clockrate_hz}); | 88 return rtc::Optional<CngDecoder>({format.clockrate_hz}); |
| 99 } else { | 89 } else { |
| 100 return rtc::Optional<CngDecoder>(); | 90 return rtc::Optional<CngDecoder>(); |
| 101 } | 91 } |
| 102 } | 92 } |
| 103 | 93 |
| 94 DecoderDatabase::DecoderInfo::Subtype |
| 95 DecoderDatabase::DecoderInfo::SubtypeFromFormat(const SdpAudioFormat& format) { |
| 96 if (STR_CASE_CMP(format.name.c_str(), "CN") == 0) { |
| 97 return Subtype::kComfortNoise; |
| 98 } else if (STR_CASE_CMP(format.name.c_str(), "telephone-event") == 0) { |
| 99 return Subtype::kDtmf; |
| 100 } else if (STR_CASE_CMP(format.name.c_str(), "red") == 0) { |
| 101 return Subtype::kRed; |
| 102 } |
| 103 |
| 104 return Subtype::kNormal; |
| 105 } |
| 106 |
| 104 bool DecoderDatabase::Empty() const { return decoders_.empty(); } | 107 bool DecoderDatabase::Empty() const { return decoders_.empty(); } |
| 105 | 108 |
| 106 int DecoderDatabase::Size() const { return static_cast<int>(decoders_.size()); } | 109 int DecoderDatabase::Size() const { return static_cast<int>(decoders_.size()); } |
| 107 | 110 |
| 108 void DecoderDatabase::Reset() { | 111 void DecoderDatabase::Reset() { |
| 109 decoders_.clear(); | 112 decoders_.clear(); |
| 110 active_decoder_type_ = -1; | 113 active_decoder_type_ = -1; |
| 111 active_cng_decoder_type_ = -1; | 114 active_cng_decoder_type_ = -1; |
| 112 } | 115 } |
| 113 | 116 |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 // Payload type is not found. | 295 // Payload type is not found. |
| 293 LOG(LS_WARNING) << "CheckPayloadTypes: unknown RTP payload type " | 296 LOG(LS_WARNING) << "CheckPayloadTypes: unknown RTP payload type " |
| 294 << static_cast<int>((*it)->header.payloadType); | 297 << static_cast<int>((*it)->header.payloadType); |
| 295 return kDecoderNotFound; | 298 return kDecoderNotFound; |
| 296 } | 299 } |
| 297 } | 300 } |
| 298 return kOK; | 301 return kOK; |
| 299 } | 302 } |
| 300 | 303 |
| 301 } // namespace webrtc | 304 } // namespace webrtc |
| OLD | NEW |