henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 11 | #include "modules/audio_coding/neteq/decoder_database.h" |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 | [diff] [blame] | 12 | |
Yves Gerey | 988cc08 | 2018-10-23 10:03:01 | [diff] [blame] | 13 | #include <stddef.h> |
Jonas Olsson | a4d8737 | 2019-07-05 17:08:33 | [diff] [blame] | 14 | |
Yves Gerey | 988cc08 | 2018-10-23 10:03:01 | [diff] [blame] | 15 | #include <cstdint> |
| 16 | #include <list> |
| 17 | #include <type_traits> |
| 18 | #include <utility> |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 | [diff] [blame] | 19 | |
Niels Möller | 2edab4c | 2018-10-22 07:48:08 | [diff] [blame] | 20 | #include "absl/strings/match.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 21 | #include "api/audio_codecs/audio_decoder.h" |
| 22 | #include "rtc_base/checks.h" |
| 23 | #include "rtc_base/logging.h" |
Jonas Olsson | abbe841 | 2018-04-03 11:40:05 | [diff] [blame] | 24 | #include "rtc_base/strings/audio_format_to_string.h" |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 | [diff] [blame] | 25 | |
| 26 | namespace webrtc { |
| 27 | |
kwiberg | 5178ee8 | 2016-05-03 08:39:01 | [diff] [blame] | 28 | DecoderDatabase::DecoderDatabase( |
Karl Wiberg | 0812634 | 2018-03-20 18:18:55 | [diff] [blame] | 29 | const rtc::scoped_refptr<AudioDecoderFactory>& decoder_factory, |
Danil Chapovalov | b602123 | 2018-06-19 11:26:36 | [diff] [blame] | 30 | absl::optional<AudioCodecPairId> codec_pair_id) |
kwiberg | 5178ee8 | 2016-05-03 08:39:01 | [diff] [blame] | 31 | : active_decoder_type_(-1), |
| 32 | active_cng_decoder_type_(-1), |
Karl Wiberg | 0812634 | 2018-03-20 18:18:55 | [diff] [blame] | 33 | decoder_factory_(decoder_factory), |
| 34 | codec_pair_id_(codec_pair_id) {} |
pbos@webrtc.org | 2d1a55c | 2013-07-31 15:54:00 | [diff] [blame] | 35 | |
ossu | 97ba30e | 2016-04-25 14:55:58 | [diff] [blame] | 36 | DecoderDatabase::~DecoderDatabase() = default; |
pbos@webrtc.org | 2d1a55c | 2013-07-31 15:54:00 | [diff] [blame] | 37 | |
Karl Wiberg | 0812634 | 2018-03-20 18:18:55 | [diff] [blame] | 38 | DecoderDatabase::DecoderInfo::DecoderInfo( |
| 39 | const SdpAudioFormat& audio_format, |
Danil Chapovalov | b602123 | 2018-06-19 11:26:36 | [diff] [blame] | 40 | absl::optional<AudioCodecPairId> codec_pair_id, |
Karl Wiberg | 0812634 | 2018-03-20 18:18:55 | [diff] [blame] | 41 | AudioDecoderFactory* factory, |
| 42 | const std::string& codec_name) |
kwiberg | e941306 | 2016-11-03 12:29:05 | [diff] [blame] | 43 | : name_(codec_name), |
| 44 | audio_format_(audio_format), |
Karl Wiberg | 0812634 | 2018-03-20 18:18:55 | [diff] [blame] | 45 | codec_pair_id_(codec_pair_id), |
ossu | 84bc985 | 2016-08-26 12:41:23 | [diff] [blame] | 46 | factory_(factory), |
ossu | 9f38c21 | 2016-10-04 12:23:32 | [diff] [blame] | 47 | cng_decoder_(CngDecoder::Create(audio_format)), |
| 48 | subtype_(SubtypeFromFormat(audio_format)) {} |
kwiberg | c0f2dcf | 2016-05-31 13:28:03 | [diff] [blame] | 49 | |
Karl Wiberg | 0812634 | 2018-03-20 18:18:55 | [diff] [blame] | 50 | DecoderDatabase::DecoderInfo::DecoderInfo( |
| 51 | const SdpAudioFormat& audio_format, |
Danil Chapovalov | b602123 | 2018-06-19 11:26:36 | [diff] [blame] | 52 | absl::optional<AudioCodecPairId> codec_pair_id, |
Karl Wiberg | 0812634 | 2018-03-20 18:18:55 | [diff] [blame] | 53 | AudioDecoderFactory* factory) |
| 54 | : DecoderInfo(audio_format, codec_pair_id, factory, audio_format.name) {} |
kwiberg | e941306 | 2016-11-03 12:29:05 | [diff] [blame] | 55 | |
kwiberg | 0fa0a97 | 2016-04-19 12:03:45 | [diff] [blame] | 56 | DecoderDatabase::DecoderInfo::DecoderInfo(DecoderInfo&&) = default; |
| 57 | DecoderDatabase::DecoderInfo::~DecoderInfo() = default; |
| 58 | |
ossu | 84bc985 | 2016-08-26 12:41:23 | [diff] [blame] | 59 | AudioDecoder* DecoderDatabase::DecoderInfo::GetDecoder() const { |
ossu | 9f38c21 | 2016-10-04 12:23:32 | [diff] [blame] | 60 | if (subtype_ != Subtype::kNormal) { |
ossu | f1b08da | 2016-09-23 09:19:43 | [diff] [blame] | 61 | // These are handled internally, so they have no AudioDecoder objects. |
| 62 | return nullptr; |
| 63 | } |
kwiberg | 0fa0a97 | 2016-04-19 12:03:45 | [diff] [blame] | 64 | if (!decoder_) { |
ossu | f1b08da | 2016-09-23 09:19:43 | [diff] [blame] | 65 | // TODO(ossu): Keep a check here for now, since a number of tests create |
| 66 | // DecoderInfos without factories. |
ossu | 84bc985 | 2016-08-26 12:41:23 | [diff] [blame] | 67 | RTC_DCHECK(factory_); |
Karl Wiberg | 0812634 | 2018-03-20 18:18:55 | [diff] [blame] | 68 | decoder_ = factory_->MakeAudioDecoder(audio_format_, codec_pair_id_); |
kwiberg | 0fa0a97 | 2016-04-19 12:03:45 | [diff] [blame] | 69 | } |
Jonas Olsson | abbe841 | 2018-04-03 11:40:05 | [diff] [blame] | 70 | RTC_DCHECK(decoder_) << "Failed to create: " << rtc::ToString(audio_format_); |
kwiberg | 0fa0a97 | 2016-04-19 12:03:45 | [diff] [blame] | 71 | return decoder_.get(); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 | [diff] [blame] | 72 | } |
| 73 | |
ossu | f1b08da | 2016-09-23 09:19:43 | [diff] [blame] | 74 | bool DecoderDatabase::DecoderInfo::IsType(const char* name) const { |
Niels Möller | 2edab4c | 2018-10-22 07:48:08 | [diff] [blame] | 75 | return absl::EqualsIgnoreCase(audio_format_.name, name); |
ossu | f1b08da | 2016-09-23 09:19:43 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | bool DecoderDatabase::DecoderInfo::IsType(const std::string& name) const { |
| 79 | return IsType(name.c_str()); |
ossu | 84bc985 | 2016-08-26 12:41:23 | [diff] [blame] | 80 | } |
| 81 | |
Danil Chapovalov | b602123 | 2018-06-19 11:26:36 | [diff] [blame] | 82 | absl::optional<DecoderDatabase::DecoderInfo::CngDecoder> |
ossu | f1b08da | 2016-09-23 09:19:43 | [diff] [blame] | 83 | DecoderDatabase::DecoderInfo::CngDecoder::Create(const SdpAudioFormat& format) { |
Niels Möller | 2edab4c | 2018-10-22 07:48:08 | [diff] [blame] | 84 | if (absl::EqualsIgnoreCase(format.name, "CN")) { |
kwiberg | 5adaf73 | 2016-10-04 16:33:27 | [diff] [blame] | 85 | // CN has a 1:1 RTP clock rate to sample rate ratio. |
| 86 | const int sample_rate_hz = format.clockrate_hz; |
| 87 | RTC_DCHECK(sample_rate_hz == 8000 || sample_rate_hz == 16000 || |
| 88 | sample_rate_hz == 32000 || sample_rate_hz == 48000); |
Oskar Sundbom | 12ab00b | 2017-11-16 14:31:38 | [diff] [blame] | 89 | return DecoderDatabase::DecoderInfo::CngDecoder{sample_rate_hz}; |
ossu | f1b08da | 2016-09-23 09:19:43 | [diff] [blame] | 90 | } else { |
Danil Chapovalov | b602123 | 2018-06-19 11:26:36 | [diff] [blame] | 91 | return absl::nullopt; |
kwiberg | c0f2dcf | 2016-05-31 13:28:03 | [diff] [blame] | 92 | } |
| 93 | } |
| 94 | |
ossu | 9f38c21 | 2016-10-04 12:23:32 | [diff] [blame] | 95 | DecoderDatabase::DecoderInfo::Subtype |
| 96 | DecoderDatabase::DecoderInfo::SubtypeFromFormat(const SdpAudioFormat& format) { |
Niels Möller | 2edab4c | 2018-10-22 07:48:08 | [diff] [blame] | 97 | if (absl::EqualsIgnoreCase(format.name, "CN")) { |
ossu | 9f38c21 | 2016-10-04 12:23:32 | [diff] [blame] | 98 | return Subtype::kComfortNoise; |
Niels Möller | 2edab4c | 2018-10-22 07:48:08 | [diff] [blame] | 99 | } else if (absl::EqualsIgnoreCase(format.name, "telephone-event")) { |
ossu | 9f38c21 | 2016-10-04 12:23:32 | [diff] [blame] | 100 | return Subtype::kDtmf; |
Niels Möller | 2edab4c | 2018-10-22 07:48:08 | [diff] [blame] | 101 | } else if (absl::EqualsIgnoreCase(format.name, "red")) { |
ossu | 9f38c21 | 2016-10-04 12:23:32 | [diff] [blame] | 102 | return Subtype::kRed; |
| 103 | } |
| 104 | |
| 105 | return Subtype::kNormal; |
| 106 | } |
| 107 | |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 108 | bool DecoderDatabase::Empty() const { |
| 109 | return decoders_.empty(); |
| 110 | } |
pbos@webrtc.org | 2d1a55c | 2013-07-31 15:54:00 | [diff] [blame] | 111 | |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 112 | int DecoderDatabase::Size() const { |
| 113 | return static_cast<int>(decoders_.size()); |
| 114 | } |
pbos@webrtc.org | 2d1a55c | 2013-07-31 15:54:00 | [diff] [blame] | 115 | |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 | [diff] [blame] | 116 | void DecoderDatabase::Reset() { |
| 117 | decoders_.clear(); |
ossu | 97ba30e | 2016-04-25 14:55:58 | [diff] [blame] | 118 | active_decoder_type_ = -1; |
| 119 | active_cng_decoder_type_ = -1; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 | [diff] [blame] | 120 | } |
| 121 | |
kwiberg | 1c07c70 | 2017-03-27 14:15:49 | [diff] [blame] | 122 | std::vector<int> DecoderDatabase::SetCodecs( |
| 123 | const std::map<int, SdpAudioFormat>& codecs) { |
| 124 | // First collect all payload types that we'll remove or reassign, then remove |
| 125 | // them from the database. |
| 126 | std::vector<int> changed_payload_types; |
| 127 | for (const std::pair<uint8_t, const DecoderInfo&> kv : decoders_) { |
| 128 | auto i = codecs.find(kv.first); |
| 129 | if (i == codecs.end() || i->second != kv.second.GetFormat()) { |
| 130 | changed_payload_types.push_back(kv.first); |
| 131 | } |
| 132 | } |
| 133 | for (int pl_type : changed_payload_types) { |
| 134 | Remove(pl_type); |
| 135 | } |
| 136 | |
| 137 | // Enter the new and changed payload type mappings into the database. |
| 138 | for (const auto& kv : codecs) { |
| 139 | const int& rtp_payload_type = kv.first; |
| 140 | const SdpAudioFormat& audio_format = kv.second; |
| 141 | RTC_DCHECK_GE(rtp_payload_type, 0); |
| 142 | RTC_DCHECK_LE(rtp_payload_type, 0x7f); |
| 143 | if (decoders_.count(rtp_payload_type) == 0) { |
| 144 | decoders_.insert(std::make_pair( |
Karl Wiberg | 0812634 | 2018-03-20 18:18:55 | [diff] [blame] | 145 | rtp_payload_type, |
| 146 | DecoderInfo(audio_format, codec_pair_id_, decoder_factory_.get()))); |
kwiberg | 1c07c70 | 2017-03-27 14:15:49 | [diff] [blame] | 147 | } else { |
| 148 | // The mapping for this payload type hasn't changed. |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | return changed_payload_types; |
| 153 | } |
| 154 | |
kwiberg | 5adaf73 | 2016-10-04 16:33:27 | [diff] [blame] | 155 | int DecoderDatabase::RegisterPayload(int rtp_payload_type, |
| 156 | const SdpAudioFormat& audio_format) { |
| 157 | if (rtp_payload_type < 0 || rtp_payload_type > 0x7f) { |
| 158 | return kInvalidRtpPayloadType; |
| 159 | } |
| 160 | const auto ret = decoders_.insert(std::make_pair( |
Karl Wiberg | 0812634 | 2018-03-20 18:18:55 | [diff] [blame] | 161 | rtp_payload_type, |
| 162 | DecoderInfo(audio_format, codec_pair_id_, decoder_factory_.get()))); |
kwiberg | 5adaf73 | 2016-10-04 16:33:27 | [diff] [blame] | 163 | if (ret.second == false) { |
| 164 | // Database already contains a decoder with type |rtp_payload_type|. |
| 165 | return kDecoderExists; |
| 166 | } |
| 167 | return kOK; |
| 168 | } |
| 169 | |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 | [diff] [blame] | 170 | int DecoderDatabase::Remove(uint8_t rtp_payload_type) { |
| 171 | if (decoders_.erase(rtp_payload_type) == 0) { |
| 172 | // No decoder with that |rtp_payload_type|. |
| 173 | return kDecoderNotFound; |
| 174 | } |
ossu | 97ba30e | 2016-04-25 14:55:58 | [diff] [blame] | 175 | if (active_decoder_type_ == rtp_payload_type) { |
| 176 | active_decoder_type_ = -1; // No active decoder. |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 | [diff] [blame] | 177 | } |
ossu | 97ba30e | 2016-04-25 14:55:58 | [diff] [blame] | 178 | if (active_cng_decoder_type_ == rtp_payload_type) { |
| 179 | active_cng_decoder_type_ = -1; // No active CNG decoder. |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 | [diff] [blame] | 180 | } |
| 181 | return kOK; |
| 182 | } |
| 183 | |
kwiberg | 6b19b56 | 2016-09-20 11:02:25 | [diff] [blame] | 184 | void DecoderDatabase::RemoveAll() { |
| 185 | decoders_.clear(); |
| 186 | active_decoder_type_ = -1; // No active decoder. |
| 187 | active_cng_decoder_type_ = -1; // No active CNG decoder. |
| 188 | } |
| 189 | |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 | [diff] [blame] | 190 | const DecoderDatabase::DecoderInfo* DecoderDatabase::GetDecoderInfo( |
| 191 | uint8_t rtp_payload_type) const { |
| 192 | DecoderMap::const_iterator it = decoders_.find(rtp_payload_type); |
| 193 | if (it == decoders_.end()) { |
| 194 | // Decoder not found. |
| 195 | return NULL; |
| 196 | } |
ossu | f1b08da | 2016-09-23 09:19:43 | [diff] [blame] | 197 | return &it->second; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 | [diff] [blame] | 198 | } |
| 199 | |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 | [diff] [blame] | 200 | int DecoderDatabase::SetActiveDecoder(uint8_t rtp_payload_type, |
| 201 | bool* new_decoder) { |
| 202 | // Check that |rtp_payload_type| exists in the database. |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 203 | const DecoderInfo* info = GetDecoderInfo(rtp_payload_type); |
ossu | 84bc985 | 2016-08-26 12:41:23 | [diff] [blame] | 204 | if (!info) { |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 | [diff] [blame] | 205 | // Decoder not found. |
| 206 | return kDecoderNotFound; |
| 207 | } |
ossu | 84bc985 | 2016-08-26 12:41:23 | [diff] [blame] | 208 | RTC_CHECK(!info->IsComfortNoise()); |
| 209 | RTC_DCHECK(new_decoder); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 | [diff] [blame] | 210 | *new_decoder = false; |
ossu | 97ba30e | 2016-04-25 14:55:58 | [diff] [blame] | 211 | if (active_decoder_type_ < 0) { |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 | [diff] [blame] | 212 | // This is the first active decoder. |
| 213 | *new_decoder = true; |
ossu | 97ba30e | 2016-04-25 14:55:58 | [diff] [blame] | 214 | } else if (active_decoder_type_ != rtp_payload_type) { |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 | [diff] [blame] | 215 | // Moving from one active decoder to another. Delete the first one. |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 216 | const DecoderInfo* old_info = GetDecoderInfo(active_decoder_type_); |
ossu | 84bc985 | 2016-08-26 12:41:23 | [diff] [blame] | 217 | RTC_DCHECK(old_info); |
| 218 | old_info->DropDecoder(); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 | [diff] [blame] | 219 | *new_decoder = true; |
| 220 | } |
ossu | 97ba30e | 2016-04-25 14:55:58 | [diff] [blame] | 221 | active_decoder_type_ = rtp_payload_type; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 | [diff] [blame] | 222 | return kOK; |
| 223 | } |
| 224 | |
ossu | 84bc985 | 2016-08-26 12:41:23 | [diff] [blame] | 225 | AudioDecoder* DecoderDatabase::GetActiveDecoder() const { |
ossu | 97ba30e | 2016-04-25 14:55:58 | [diff] [blame] | 226 | if (active_decoder_type_ < 0) { |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 | [diff] [blame] | 227 | // No active decoder. |
| 228 | return NULL; |
| 229 | } |
ossu | 97ba30e | 2016-04-25 14:55:58 | [diff] [blame] | 230 | return GetDecoder(active_decoder_type_); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | int DecoderDatabase::SetActiveCngDecoder(uint8_t rtp_payload_type) { |
| 234 | // Check that |rtp_payload_type| exists in the database. |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 235 | const DecoderInfo* info = GetDecoderInfo(rtp_payload_type); |
ossu | 84bc985 | 2016-08-26 12:41:23 | [diff] [blame] | 236 | if (!info) { |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 | [diff] [blame] | 237 | // Decoder not found. |
| 238 | return kDecoderNotFound; |
| 239 | } |
ossu | 97ba30e | 2016-04-25 14:55:58 | [diff] [blame] | 240 | if (active_cng_decoder_type_ >= 0 && |
| 241 | active_cng_decoder_type_ != rtp_payload_type) { |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 | [diff] [blame] | 242 | // Moving from one active CNG decoder to another. Delete the first one. |
ossu | 84bc985 | 2016-08-26 12:41:23 | [diff] [blame] | 243 | RTC_DCHECK(active_cng_decoder_); |
ossu | 97ba30e | 2016-04-25 14:55:58 | [diff] [blame] | 244 | active_cng_decoder_.reset(); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 | [diff] [blame] | 245 | } |
ossu | 97ba30e | 2016-04-25 14:55:58 | [diff] [blame] | 246 | active_cng_decoder_type_ = rtp_payload_type; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 | [diff] [blame] | 247 | return kOK; |
| 248 | } |
| 249 | |
ossu | 84bc985 | 2016-08-26 12:41:23 | [diff] [blame] | 250 | ComfortNoiseDecoder* DecoderDatabase::GetActiveCngDecoder() const { |
ossu | 97ba30e | 2016-04-25 14:55:58 | [diff] [blame] | 251 | if (active_cng_decoder_type_ < 0) { |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 | [diff] [blame] | 252 | // No active CNG decoder. |
| 253 | return NULL; |
| 254 | } |
ossu | 97ba30e | 2016-04-25 14:55:58 | [diff] [blame] | 255 | if (!active_cng_decoder_) { |
| 256 | active_cng_decoder_.reset(new ComfortNoiseDecoder); |
| 257 | } |
| 258 | return active_cng_decoder_.get(); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 | [diff] [blame] | 259 | } |
| 260 | |
ossu | 84bc985 | 2016-08-26 12:41:23 | [diff] [blame] | 261 | AudioDecoder* DecoderDatabase::GetDecoder(uint8_t rtp_payload_type) const { |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 262 | const DecoderInfo* info = GetDecoderInfo(rtp_payload_type); |
ossu | 84bc985 | 2016-08-26 12:41:23 | [diff] [blame] | 263 | return info ? info->GetDecoder() : nullptr; |
| 264 | } |
| 265 | |
ossu | f1b08da | 2016-09-23 09:19:43 | [diff] [blame] | 266 | bool DecoderDatabase::IsType(uint8_t rtp_payload_type, const char* name) const { |
| 267 | const DecoderInfo* info = GetDecoderInfo(rtp_payload_type); |
| 268 | return info && info->IsType(name); |
| 269 | } |
| 270 | |
ossu | 84bc985 | 2016-08-26 12:41:23 | [diff] [blame] | 271 | bool DecoderDatabase::IsType(uint8_t rtp_payload_type, |
ossu | f1b08da | 2016-09-23 09:19:43 | [diff] [blame] | 272 | const std::string& name) const { |
| 273 | return IsType(rtp_payload_type, name.c_str()); |
ossu | 84bc985 | 2016-08-26 12:41:23 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | bool DecoderDatabase::IsComfortNoise(uint8_t rtp_payload_type) const { |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 277 | const DecoderInfo* info = GetDecoderInfo(rtp_payload_type); |
ossu | 84bc985 | 2016-08-26 12:41:23 | [diff] [blame] | 278 | return info && info->IsComfortNoise(); |
| 279 | } |
| 280 | |
| 281 | bool DecoderDatabase::IsDtmf(uint8_t rtp_payload_type) const { |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 282 | const DecoderInfo* info = GetDecoderInfo(rtp_payload_type); |
ossu | 84bc985 | 2016-08-26 12:41:23 | [diff] [blame] | 283 | return info && info->IsDtmf(); |
| 284 | } |
| 285 | |
| 286 | bool DecoderDatabase::IsRed(uint8_t rtp_payload_type) const { |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 287 | const DecoderInfo* info = GetDecoderInfo(rtp_payload_type); |
ossu | 84bc985 | 2016-08-26 12:41:23 | [diff] [blame] | 288 | return info && info->IsRed(); |
| 289 | } |
| 290 | |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 | [diff] [blame] | 291 | int DecoderDatabase::CheckPayloadTypes(const PacketList& packet_list) const { |
| 292 | PacketList::const_iterator it; |
| 293 | for (it = packet_list.begin(); it != packet_list.end(); ++it) { |
ossu | a73f6c9 | 2016-10-24 15:25:28 | [diff] [blame] | 294 | if (!GetDecoderInfo(it->payload_type)) { |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 | [diff] [blame] | 295 | // Payload type is not found. |
Mirko Bonadei | 675513b | 2017-11-09 10:09:25 | [diff] [blame] | 296 | RTC_LOG(LS_WARNING) << "CheckPayloadTypes: unknown RTP payload type " |
| 297 | << static_cast<int>(it->payload_type); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 | [diff] [blame] | 298 | return kDecoderNotFound; |
| 299 | } |
| 300 | } |
| 301 | return kOK; |
| 302 | } |
| 303 | |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 | [diff] [blame] | 304 | } // namespace webrtc |