blob: bd5d7197a9618a1f9c73b6f776f411c59fd6402b [file] [log] [blame]
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +00001/*
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 Bonadei92ea95e2017-09-15 06:47:31 +020011#include "modules/audio_coding/neteq/decoder_database.h"
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000012
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000013#include <utility> // pair
14
Niels Möller2edab4c2018-10-22 09:48:08 +020015#include "absl/strings/match.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020016#include "api/audio_codecs/audio_decoder.h"
17#include "rtc_base/checks.h"
18#include "rtc_base/logging.h"
Jonas Olssonabbe8412018-04-03 13:40:05 +020019#include "rtc_base/strings/audio_format_to_string.h"
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000020
21namespace webrtc {
22
kwiberg5178ee82016-05-03 01:39:01 -070023DecoderDatabase::DecoderDatabase(
Karl Wiberg08126342018-03-20 19:18:55 +010024 const rtc::scoped_refptr<AudioDecoderFactory>& decoder_factory,
Danil Chapovalovb6021232018-06-19 13:26:36 +020025 absl::optional<AudioCodecPairId> codec_pair_id)
kwiberg5178ee82016-05-03 01:39:01 -070026 : active_decoder_type_(-1),
27 active_cng_decoder_type_(-1),
Karl Wiberg08126342018-03-20 19:18:55 +010028 decoder_factory_(decoder_factory),
29 codec_pair_id_(codec_pair_id) {}
pbos@webrtc.org2d1a55c2013-07-31 15:54:00 +000030
ossu97ba30e2016-04-25 07:55:58 -070031DecoderDatabase::~DecoderDatabase() = default;
pbos@webrtc.org2d1a55c2013-07-31 15:54:00 +000032
Karl Wiberg08126342018-03-20 19:18:55 +010033DecoderDatabase::DecoderInfo::DecoderInfo(
34 const SdpAudioFormat& audio_format,
Danil Chapovalovb6021232018-06-19 13:26:36 +020035 absl::optional<AudioCodecPairId> codec_pair_id,
Karl Wiberg08126342018-03-20 19:18:55 +010036 AudioDecoderFactory* factory,
37 const std::string& codec_name)
kwiberge9413062016-11-03 05:29:05 -070038 : name_(codec_name),
39 audio_format_(audio_format),
Karl Wiberg08126342018-03-20 19:18:55 +010040 codec_pair_id_(codec_pair_id),
ossu84bc9852016-08-26 05:41:23 -070041 factory_(factory),
kwiberg342f7402016-06-16 03:18:00 -070042 external_decoder_(nullptr),
ossu9f38c212016-10-04 05:23:32 -070043 cng_decoder_(CngDecoder::Create(audio_format)),
44 subtype_(SubtypeFromFormat(audio_format)) {}
kwibergc0f2dcf2016-05-31 06:28:03 -070045
Karl Wiberg08126342018-03-20 19:18:55 +010046DecoderDatabase::DecoderInfo::DecoderInfo(
47 const SdpAudioFormat& audio_format,
Danil Chapovalovb6021232018-06-19 13:26:36 +020048 absl::optional<AudioCodecPairId> codec_pair_id,
Karl Wiberg08126342018-03-20 19:18:55 +010049 AudioDecoderFactory* factory)
50 : DecoderInfo(audio_format, codec_pair_id, factory, audio_format.name) {}
kwiberge9413062016-11-03 05:29:05 -070051
Karl Wiberg08126342018-03-20 19:18:55 +010052DecoderDatabase::DecoderInfo::DecoderInfo(
53 NetEqDecoder ct,
Danil Chapovalovb6021232018-06-19 13:26:36 +020054 absl::optional<AudioCodecPairId> codec_pair_id,
Karl Wiberg08126342018-03-20 19:18:55 +010055 AudioDecoderFactory* factory)
56 : DecoderInfo(*NetEqDecoderToSdpAudioFormat(ct), codec_pair_id, factory) {}
ossuf1b08da2016-09-23 02:19:43 -070057
58DecoderDatabase::DecoderInfo::DecoderInfo(const SdpAudioFormat& audio_format,
kwiberge9413062016-11-03 05:29:05 -070059 AudioDecoder* ext_dec,
60 const std::string& codec_name)
61 : name_(codec_name),
62 audio_format_(audio_format),
Danil Chapovalovb6021232018-06-19 13:26:36 +020063 codec_pair_id_(absl::nullopt),
ossuf1b08da2016-09-23 02:19:43 -070064 factory_(nullptr),
ossu9f38c212016-10-04 05:23:32 -070065 external_decoder_(ext_dec),
66 subtype_(Subtype::kNormal) {
kwibergc0f2dcf2016-05-31 06:28:03 -070067 RTC_CHECK(ext_dec);
68}
kwiberg0fa0a972016-04-19 05:03:45 -070069
70DecoderDatabase::DecoderInfo::DecoderInfo(DecoderInfo&&) = default;
71DecoderDatabase::DecoderInfo::~DecoderInfo() = default;
72
Karl Wiberg31fbb542017-10-16 12:42:38 +020073bool DecoderDatabase::DecoderInfo::CanGetDecoder() const {
74 if (subtype_ == Subtype::kNormal && !external_decoder_ && !decoder_) {
75 // TODO(ossu): Keep a check here for now, since a number of tests create
76 // DecoderInfos without factories.
77 RTC_DCHECK(factory_);
78 return factory_->IsSupportedDecoder(audio_format_);
79 } else {
80 return true;
81 }
82}
83
ossu84bc9852016-08-26 05:41:23 -070084AudioDecoder* DecoderDatabase::DecoderInfo::GetDecoder() const {
ossu9f38c212016-10-04 05:23:32 -070085 if (subtype_ != Subtype::kNormal) {
ossuf1b08da2016-09-23 02:19:43 -070086 // These are handled internally, so they have no AudioDecoder objects.
87 return nullptr;
88 }
kwiberg342f7402016-06-16 03:18:00 -070089 if (external_decoder_) {
kwiberg0fa0a972016-04-19 05:03:45 -070090 RTC_DCHECK(!decoder_);
kwiberg342f7402016-06-16 03:18:00 -070091 RTC_DCHECK(!cng_decoder_);
92 return external_decoder_;
kwiberg0fa0a972016-04-19 05:03:45 -070093 }
94 if (!decoder_) {
ossuf1b08da2016-09-23 02:19:43 -070095 // TODO(ossu): Keep a check here for now, since a number of tests create
96 // DecoderInfos without factories.
ossu84bc9852016-08-26 05:41:23 -070097 RTC_DCHECK(factory_);
Karl Wiberg08126342018-03-20 19:18:55 +010098 decoder_ = factory_->MakeAudioDecoder(audio_format_, codec_pair_id_);
kwiberg0fa0a972016-04-19 05:03:45 -070099 }
Jonas Olssonabbe8412018-04-03 13:40:05 +0200100 RTC_DCHECK(decoder_) << "Failed to create: " << rtc::ToString(audio_format_);
kwiberg0fa0a972016-04-19 05:03:45 -0700101 return decoder_.get();
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +0000102}
103
ossuf1b08da2016-09-23 02:19:43 -0700104bool DecoderDatabase::DecoderInfo::IsType(const char* name) const {
Niels Möller2edab4c2018-10-22 09:48:08 +0200105 return absl::EqualsIgnoreCase(audio_format_.name, name);
ossuf1b08da2016-09-23 02:19:43 -0700106}
107
108bool DecoderDatabase::DecoderInfo::IsType(const std::string& name) const {
109 return IsType(name.c_str());
ossu84bc9852016-08-26 05:41:23 -0700110}
111
Danil Chapovalovb6021232018-06-19 13:26:36 +0200112absl::optional<DecoderDatabase::DecoderInfo::CngDecoder>
ossuf1b08da2016-09-23 02:19:43 -0700113DecoderDatabase::DecoderInfo::CngDecoder::Create(const SdpAudioFormat& format) {
Niels Möller2edab4c2018-10-22 09:48:08 +0200114 if (absl::EqualsIgnoreCase(format.name, "CN")) {
kwiberg5adaf732016-10-04 09:33:27 -0700115 // CN has a 1:1 RTP clock rate to sample rate ratio.
116 const int sample_rate_hz = format.clockrate_hz;
117 RTC_DCHECK(sample_rate_hz == 8000 || sample_rate_hz == 16000 ||
118 sample_rate_hz == 32000 || sample_rate_hz == 48000);
Oskar Sundbom12ab00b2017-11-16 15:31:38 +0100119 return DecoderDatabase::DecoderInfo::CngDecoder{sample_rate_hz};
ossuf1b08da2016-09-23 02:19:43 -0700120 } else {
Danil Chapovalovb6021232018-06-19 13:26:36 +0200121 return absl::nullopt;
kwibergc0f2dcf2016-05-31 06:28:03 -0700122 }
123}
124
ossu9f38c212016-10-04 05:23:32 -0700125DecoderDatabase::DecoderInfo::Subtype
126DecoderDatabase::DecoderInfo::SubtypeFromFormat(const SdpAudioFormat& format) {
Niels Möller2edab4c2018-10-22 09:48:08 +0200127 if (absl::EqualsIgnoreCase(format.name, "CN")) {
ossu9f38c212016-10-04 05:23:32 -0700128 return Subtype::kComfortNoise;
Niels Möller2edab4c2018-10-22 09:48:08 +0200129 } else if (absl::EqualsIgnoreCase(format.name, "telephone-event")) {
ossu9f38c212016-10-04 05:23:32 -0700130 return Subtype::kDtmf;
Niels Möller2edab4c2018-10-22 09:48:08 +0200131 } else if (absl::EqualsIgnoreCase(format.name, "red")) {
ossu9f38c212016-10-04 05:23:32 -0700132 return Subtype::kRed;
133 }
134
135 return Subtype::kNormal;
136}
137
Yves Gerey665174f2018-06-19 15:03:05 +0200138bool DecoderDatabase::Empty() const {
139 return decoders_.empty();
140}
pbos@webrtc.org2d1a55c2013-07-31 15:54:00 +0000141
Yves Gerey665174f2018-06-19 15:03:05 +0200142int DecoderDatabase::Size() const {
143 return static_cast<int>(decoders_.size());
144}
pbos@webrtc.org2d1a55c2013-07-31 15:54:00 +0000145
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +0000146void DecoderDatabase::Reset() {
147 decoders_.clear();
ossu97ba30e2016-04-25 07:55:58 -0700148 active_decoder_type_ = -1;
149 active_cng_decoder_type_ = -1;
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +0000150}
151
kwiberg1c07c702017-03-27 07:15:49 -0700152std::vector<int> DecoderDatabase::SetCodecs(
153 const std::map<int, SdpAudioFormat>& codecs) {
154 // First collect all payload types that we'll remove or reassign, then remove
155 // them from the database.
156 std::vector<int> changed_payload_types;
157 for (const std::pair<uint8_t, const DecoderInfo&> kv : decoders_) {
158 auto i = codecs.find(kv.first);
159 if (i == codecs.end() || i->second != kv.second.GetFormat()) {
160 changed_payload_types.push_back(kv.first);
161 }
162 }
163 for (int pl_type : changed_payload_types) {
164 Remove(pl_type);
165 }
166
167 // Enter the new and changed payload type mappings into the database.
168 for (const auto& kv : codecs) {
169 const int& rtp_payload_type = kv.first;
170 const SdpAudioFormat& audio_format = kv.second;
171 RTC_DCHECK_GE(rtp_payload_type, 0);
172 RTC_DCHECK_LE(rtp_payload_type, 0x7f);
173 if (decoders_.count(rtp_payload_type) == 0) {
174 decoders_.insert(std::make_pair(
Karl Wiberg08126342018-03-20 19:18:55 +0100175 rtp_payload_type,
176 DecoderInfo(audio_format, codec_pair_id_, decoder_factory_.get())));
kwiberg1c07c702017-03-27 07:15:49 -0700177 } else {
178 // The mapping for this payload type hasn't changed.
179 }
180 }
181
182 return changed_payload_types;
183}
184
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +0000185int DecoderDatabase::RegisterPayload(uint8_t rtp_payload_type,
henrik.lundin4cf61dd2015-12-09 06:20:58 -0800186 NetEqDecoder codec_type,
187 const std::string& name) {
pkasting@chromium.orgd3245462015-02-23 21:28:22 +0000188 if (rtp_payload_type > 0x7F) {
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +0000189 return kInvalidRtpPayloadType;
190 }
Karl Wiberg31fbb542017-10-16 12:42:38 +0200191 if (codec_type == NetEqDecoder::kDecoderArbitrary) {
192 return kCodecNotSupported; // Only supported through InsertExternal.
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +0000193 }
kwiberg65cb70d2017-03-03 06:16:28 -0800194 const auto opt_format = NetEqDecoderToSdpAudioFormat(codec_type);
ossuf1b08da2016-09-23 02:19:43 -0700195 if (!opt_format) {
196 return kCodecNotSupported;
197 }
Karl Wiberg08126342018-03-20 19:18:55 +0100198 DecoderInfo info(*opt_format, codec_pair_id_, decoder_factory_, name);
Karl Wiberg31fbb542017-10-16 12:42:38 +0200199 if (!info.CanGetDecoder()) {
200 return kCodecNotSupported;
201 }
kwiberg0fa0a972016-04-19 05:03:45 -0700202 auto ret =
203 decoders_.insert(std::make_pair(rtp_payload_type, std::move(info)));
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +0000204 if (ret.second == false) {
205 // Database already contains a decoder with type |rtp_payload_type|.
206 return kDecoderExists;
207 }
208 return kOK;
209}
210
kwiberg5adaf732016-10-04 09:33:27 -0700211int DecoderDatabase::RegisterPayload(int rtp_payload_type,
212 const SdpAudioFormat& audio_format) {
213 if (rtp_payload_type < 0 || rtp_payload_type > 0x7f) {
214 return kInvalidRtpPayloadType;
215 }
216 const auto ret = decoders_.insert(std::make_pair(
Karl Wiberg08126342018-03-20 19:18:55 +0100217 rtp_payload_type,
218 DecoderInfo(audio_format, codec_pair_id_, decoder_factory_.get())));
kwiberg5adaf732016-10-04 09:33:27 -0700219 if (ret.second == false) {
220 // Database already contains a decoder with type |rtp_payload_type|.
221 return kDecoderExists;
222 }
223 return kOK;
224}
225
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +0000226int DecoderDatabase::InsertExternal(uint8_t rtp_payload_type,
227 NetEqDecoder codec_type,
henrik.lundin4cf61dd2015-12-09 06:20:58 -0800228 const std::string& codec_name,
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +0000229 AudioDecoder* decoder) {
230 if (rtp_payload_type > 0x7F) {
231 return kInvalidRtpPayloadType;
232 }
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +0000233 if (!decoder) {
234 return kInvalidPointer;
235 }
ossuf1b08da2016-09-23 02:19:43 -0700236
kwiberg65cb70d2017-03-03 06:16:28 -0800237 const auto opt_db_format = NetEqDecoderToSdpAudioFormat(codec_type);
Danil Chapovalov8aba6b42018-04-17 10:10:57 +0200238 const SdpAudioFormat format =
239 opt_db_format.value_or(SdpAudioFormat("arbitrary", 0, 0));
ossuf1b08da2016-09-23 02:19:43 -0700240
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +0000241 std::pair<DecoderMap::iterator, bool> ret;
kwiberge9413062016-11-03 05:29:05 -0700242 DecoderInfo info(format, decoder, codec_name);
kwiberg0fa0a972016-04-19 05:03:45 -0700243 ret = decoders_.insert(std::make_pair(rtp_payload_type, std::move(info)));
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +0000244 if (ret.second == false) {
245 // Database already contains a decoder with type |rtp_payload_type|.
246 return kDecoderExists;
247 }
248 return kOK;
249}
250
251int DecoderDatabase::Remove(uint8_t rtp_payload_type) {
252 if (decoders_.erase(rtp_payload_type) == 0) {
253 // No decoder with that |rtp_payload_type|.
254 return kDecoderNotFound;
255 }
ossu97ba30e2016-04-25 07:55:58 -0700256 if (active_decoder_type_ == rtp_payload_type) {
257 active_decoder_type_ = -1; // No active decoder.
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +0000258 }
ossu97ba30e2016-04-25 07:55:58 -0700259 if (active_cng_decoder_type_ == rtp_payload_type) {
260 active_cng_decoder_type_ = -1; // No active CNG decoder.
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +0000261 }
262 return kOK;
263}
264
kwiberg6b19b562016-09-20 04:02:25 -0700265void DecoderDatabase::RemoveAll() {
266 decoders_.clear();
267 active_decoder_type_ = -1; // No active decoder.
268 active_cng_decoder_type_ = -1; // No active CNG decoder.
269}
270
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +0000271const DecoderDatabase::DecoderInfo* DecoderDatabase::GetDecoderInfo(
272 uint8_t rtp_payload_type) const {
273 DecoderMap::const_iterator it = decoders_.find(rtp_payload_type);
274 if (it == decoders_.end()) {
275 // Decoder not found.
276 return NULL;
277 }
ossuf1b08da2016-09-23 02:19:43 -0700278 return &it->second;
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +0000279}
280
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +0000281int DecoderDatabase::SetActiveDecoder(uint8_t rtp_payload_type,
282 bool* new_decoder) {
283 // Check that |rtp_payload_type| exists in the database.
Yves Gerey665174f2018-06-19 15:03:05 +0200284 const DecoderInfo* info = GetDecoderInfo(rtp_payload_type);
ossu84bc9852016-08-26 05:41:23 -0700285 if (!info) {
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +0000286 // Decoder not found.
287 return kDecoderNotFound;
288 }
ossu84bc9852016-08-26 05:41:23 -0700289 RTC_CHECK(!info->IsComfortNoise());
290 RTC_DCHECK(new_decoder);
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +0000291 *new_decoder = false;
ossu97ba30e2016-04-25 07:55:58 -0700292 if (active_decoder_type_ < 0) {
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +0000293 // This is the first active decoder.
294 *new_decoder = true;
ossu97ba30e2016-04-25 07:55:58 -0700295 } else if (active_decoder_type_ != rtp_payload_type) {
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +0000296 // Moving from one active decoder to another. Delete the first one.
Yves Gerey665174f2018-06-19 15:03:05 +0200297 const DecoderInfo* old_info = GetDecoderInfo(active_decoder_type_);
ossu84bc9852016-08-26 05:41:23 -0700298 RTC_DCHECK(old_info);
299 old_info->DropDecoder();
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +0000300 *new_decoder = true;
301 }
ossu97ba30e2016-04-25 07:55:58 -0700302 active_decoder_type_ = rtp_payload_type;
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +0000303 return kOK;
304}
305
ossu84bc9852016-08-26 05:41:23 -0700306AudioDecoder* DecoderDatabase::GetActiveDecoder() const {
ossu97ba30e2016-04-25 07:55:58 -0700307 if (active_decoder_type_ < 0) {
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +0000308 // No active decoder.
309 return NULL;
310 }
ossu97ba30e2016-04-25 07:55:58 -0700311 return GetDecoder(active_decoder_type_);
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +0000312}
313
314int DecoderDatabase::SetActiveCngDecoder(uint8_t rtp_payload_type) {
315 // Check that |rtp_payload_type| exists in the database.
Yves Gerey665174f2018-06-19 15:03:05 +0200316 const DecoderInfo* info = GetDecoderInfo(rtp_payload_type);
ossu84bc9852016-08-26 05:41:23 -0700317 if (!info) {
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +0000318 // Decoder not found.
319 return kDecoderNotFound;
320 }
ossu97ba30e2016-04-25 07:55:58 -0700321 if (active_cng_decoder_type_ >= 0 &&
322 active_cng_decoder_type_ != rtp_payload_type) {
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +0000323 // Moving from one active CNG decoder to another. Delete the first one.
ossu84bc9852016-08-26 05:41:23 -0700324 RTC_DCHECK(active_cng_decoder_);
ossu97ba30e2016-04-25 07:55:58 -0700325 active_cng_decoder_.reset();
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +0000326 }
ossu97ba30e2016-04-25 07:55:58 -0700327 active_cng_decoder_type_ = rtp_payload_type;
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +0000328 return kOK;
329}
330
ossu84bc9852016-08-26 05:41:23 -0700331ComfortNoiseDecoder* DecoderDatabase::GetActiveCngDecoder() const {
ossu97ba30e2016-04-25 07:55:58 -0700332 if (active_cng_decoder_type_ < 0) {
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +0000333 // No active CNG decoder.
334 return NULL;
335 }
ossu97ba30e2016-04-25 07:55:58 -0700336 if (!active_cng_decoder_) {
337 active_cng_decoder_.reset(new ComfortNoiseDecoder);
338 }
339 return active_cng_decoder_.get();
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +0000340}
341
ossu84bc9852016-08-26 05:41:23 -0700342AudioDecoder* DecoderDatabase::GetDecoder(uint8_t rtp_payload_type) const {
Yves Gerey665174f2018-06-19 15:03:05 +0200343 const DecoderInfo* info = GetDecoderInfo(rtp_payload_type);
ossu84bc9852016-08-26 05:41:23 -0700344 return info ? info->GetDecoder() : nullptr;
345}
346
ossuf1b08da2016-09-23 02:19:43 -0700347bool DecoderDatabase::IsType(uint8_t rtp_payload_type, const char* name) const {
348 const DecoderInfo* info = GetDecoderInfo(rtp_payload_type);
349 return info && info->IsType(name);
350}
351
ossu84bc9852016-08-26 05:41:23 -0700352bool DecoderDatabase::IsType(uint8_t rtp_payload_type,
ossuf1b08da2016-09-23 02:19:43 -0700353 const std::string& name) const {
354 return IsType(rtp_payload_type, name.c_str());
ossu84bc9852016-08-26 05:41:23 -0700355}
356
357bool DecoderDatabase::IsComfortNoise(uint8_t rtp_payload_type) const {
Yves Gerey665174f2018-06-19 15:03:05 +0200358 const DecoderInfo* info = GetDecoderInfo(rtp_payload_type);
ossu84bc9852016-08-26 05:41:23 -0700359 return info && info->IsComfortNoise();
360}
361
362bool DecoderDatabase::IsDtmf(uint8_t rtp_payload_type) const {
Yves Gerey665174f2018-06-19 15:03:05 +0200363 const DecoderInfo* info = GetDecoderInfo(rtp_payload_type);
ossu84bc9852016-08-26 05:41:23 -0700364 return info && info->IsDtmf();
365}
366
367bool DecoderDatabase::IsRed(uint8_t rtp_payload_type) const {
Yves Gerey665174f2018-06-19 15:03:05 +0200368 const DecoderInfo* info = GetDecoderInfo(rtp_payload_type);
ossu84bc9852016-08-26 05:41:23 -0700369 return info && info->IsRed();
370}
371
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +0000372int DecoderDatabase::CheckPayloadTypes(const PacketList& packet_list) const {
373 PacketList::const_iterator it;
374 for (it = packet_list.begin(); it != packet_list.end(); ++it) {
ossua73f6c92016-10-24 08:25:28 -0700375 if (!GetDecoderInfo(it->payload_type)) {
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +0000376 // Payload type is not found.
Mirko Bonadei675513b2017-11-09 11:09:25 +0100377 RTC_LOG(LS_WARNING) << "CheckPayloadTypes: unknown RTP payload type "
378 << static_cast<int>(it->payload_type);
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +0000379 return kDecoderNotFound;
380 }
381 }
382 return kOK;
383}
384
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +0000385} // namespace webrtc