Cache the subtype of each DecoderInfo to make the Is* checks quicker.
Addresses a regression in the NetEq performance test. # Added NOTRY due to android_arm64_rel being swamped. NOTRY=True BUG=chromium:651426 Review-Url: https://codereview.webrtc.org/2383723002 Cr-Commit-Position: refs/heads/master@{#14495}
This commit is contained in:
@ -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);
|
||||
}
|
||||
|
||||
@ -52,7 +55,7 @@ DecoderDatabase::DecoderInfo::DecoderInfo(DecoderInfo&&) = default;
|
||||
DecoderDatabase::DecoderInfo::~DecoderInfo() = default;
|
||||
|
||||
AudioDecoder* DecoderDatabase::DecoderInfo::GetDecoder() const {
|
||||
if (IsDtmf() || IsRed() || IsComfortNoise()) {
|
||||
if (subtype_ != Subtype::kNormal) {
|
||||
// These are handled internally, so they have no AudioDecoder objects.
|
||||
return nullptr;
|
||||
}
|
||||
@ -71,19 +74,6 @@ AudioDecoder* DecoderDatabase::DecoderInfo::GetDecoder() const {
|
||||
return decoder_.get();
|
||||
}
|
||||
|
||||
bool DecoderDatabase::DecoderInfo::IsComfortNoise() const {
|
||||
RTC_DCHECK_EQ(!!cng_decoder_, IsType("CN"));
|
||||
return !!cng_decoder_;
|
||||
}
|
||||
|
||||
bool DecoderDatabase::DecoderInfo::IsDtmf() const {
|
||||
return IsType("telephone-event");
|
||||
}
|
||||
|
||||
bool DecoderDatabase::DecoderInfo::IsRed() const {
|
||||
return IsType("red");
|
||||
}
|
||||
|
||||
bool DecoderDatabase::DecoderInfo::IsType(const char* name) const {
|
||||
return STR_CASE_CMP(audio_format_.name.c_str(), name) == 0;
|
||||
}
|
||||
@ -101,6 +91,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()); }
|
||||
|
||||
@ -65,13 +65,20 @@ class DecoderDatabase {
|
||||
const SdpAudioFormat& GetFormat() const { return audio_format_; }
|
||||
|
||||
// Returns true if the decoder's format is comfort noise.
|
||||
bool IsComfortNoise() const;
|
||||
bool IsComfortNoise() const {
|
||||
RTC_DCHECK_EQ(!!cng_decoder_, subtype_ == Subtype::kComfortNoise);
|
||||
return subtype_ == Subtype::kComfortNoise;
|
||||
}
|
||||
|
||||
// Returns true if the decoder's format is DTMF.
|
||||
bool IsDtmf() const;
|
||||
bool IsDtmf() const {
|
||||
return subtype_ == Subtype::kDtmf;
|
||||
}
|
||||
|
||||
// Returns true if the decoder's format is RED.
|
||||
bool IsRed() const;
|
||||
bool IsRed() const {
|
||||
return subtype_ == Subtype::kRed;
|
||||
}
|
||||
|
||||
// Returns true if the decoder's format is named |name|.
|
||||
bool IsType(const char* name) const;
|
||||
@ -97,6 +104,17 @@ class DecoderDatabase {
|
||||
int sample_rate_hz;
|
||||
};
|
||||
const rtc::Optional<CngDecoder> cng_decoder_;
|
||||
|
||||
enum class Subtype : int8_t {
|
||||
kNormal,
|
||||
kComfortNoise,
|
||||
kDtmf,
|
||||
kRed
|
||||
};
|
||||
|
||||
static Subtype SubtypeFromFormat(const SdpAudioFormat& format);
|
||||
|
||||
const Subtype subtype_;
|
||||
};
|
||||
|
||||
// Maximum value for 8 bits, and an invalid RTP payload type (since it is
|
||||
|
||||
Reference in New Issue
Block a user