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

Unified Diff: webrtc/modules/audio_coding/neteq/decoder_database.cc

Issue 2383723002: Cache the subtype of each DecoderInfo to make the Is* checks quicker. (Closed)
Patch Set: Created 4 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: webrtc/modules/audio_coding/neteq/decoder_database.cc
diff --git a/webrtc/modules/audio_coding/neteq/decoder_database.cc b/webrtc/modules/audio_coding/neteq/decoder_database.cc
index 27bc6d56970c9835300fc1cb398c387a6f03b220..9526c47a83b3206e439891171e14c21c6d1bb2db 100644
--- a/webrtc/modules/audio_coding/neteq/decoder_database.cc
+++ b/webrtc/modules/audio_coding/neteq/decoder_database.cc
@@ -31,20 +31,23 @@ DecoderDatabase::DecoderInfo::DecoderInfo(const SdpAudioFormat& audio_format,
: audio_format_(audio_format),
factory_(factory),
external_decoder_(nullptr),
- cng_decoder_(CngDecoder::Create(audio_format)) {}
+ cng_decoder_(CngDecoder::Create(audio_format)),
+ subtype_(SubtypeFromFormat(audio_format)) {}
DecoderDatabase::DecoderInfo::DecoderInfo(NetEqDecoder ct,
AudioDecoderFactory* factory)
: audio_format_(*acm2::RentACodec::NetEqDecoderToSdpAudioFormat(ct)),
factory_(factory),
external_decoder_(nullptr),
- cng_decoder_(CngDecoder::Create(audio_format_)) {}
+ cng_decoder_(CngDecoder::Create(audio_format_)),
+ subtype_(SubtypeFromFormat(audio_format_)) {}
DecoderDatabase::DecoderInfo::DecoderInfo(const SdpAudioFormat& audio_format,
AudioDecoder* ext_dec)
: audio_format_(audio_format),
factory_(nullptr),
- external_decoder_(ext_dec) {
+ external_decoder_(ext_dec),
+ subtype_(Subtype::kNormal) {
RTC_CHECK(ext_dec);
}
@@ -72,16 +75,16 @@ AudioDecoder* DecoderDatabase::DecoderInfo::GetDecoder() const {
}
bool DecoderDatabase::DecoderInfo::IsComfortNoise() const {
- RTC_DCHECK_EQ(!!cng_decoder_, IsType("CN"));
- return !!cng_decoder_;
+ RTC_DCHECK_EQ(!!cng_decoder_, subtype_ == Subtype::kComfortNoise);
+ return subtype_ == Subtype::kComfortNoise;
}
bool DecoderDatabase::DecoderInfo::IsDtmf() const {
- return IsType("telephone-event");
+ return subtype_ == Subtype::kDtmf;
}
bool DecoderDatabase::DecoderInfo::IsRed() const {
- return IsType("red");
+ return subtype_ == Subtype::kRed;
}
bool DecoderDatabase::DecoderInfo::IsType(const char* name) const {
@@ -101,6 +104,19 @@ DecoderDatabase::DecoderInfo::CngDecoder::Create(const SdpAudioFormat& format) {
}
}
+DecoderDatabase::DecoderInfo::Subtype
+DecoderDatabase::DecoderInfo::SubtypeFromFormat(const SdpAudioFormat& format) {
+ if (STR_CASE_CMP(format.name.c_str(), "CN") == 0) {
+ return Subtype::kComfortNoise;
+ } else if (STR_CASE_CMP(format.name.c_str(), "telephone-event") == 0) {
+ return Subtype::kDtmf;
+ } else if (STR_CASE_CMP(format.name.c_str(), "red") == 0) {
+ return Subtype::kRed;
+ }
+
+ return Subtype::kNormal;
+}
+
bool DecoderDatabase::Empty() const { return decoders_.empty(); }
int DecoderDatabase::Size() const { return static_cast<int>(decoders_.size()); }

Powered by Google App Engine
This is Rietveld 408576698