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

Unified Diff: webrtc/modules/audio_coding/acm2/acm_receiver.cc

Issue 2351183002: AcmReceiver: Eliminate AcmReceiver::decoders_ (Closed)
Patch Set: case-insensitive string comparison 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
« no previous file with comments | « webrtc/modules/audio_coding/acm2/acm_receiver.h ('k') | webrtc/modules/audio_coding/codecs/audio_format.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/modules/audio_coding/acm2/acm_receiver.cc
diff --git a/webrtc/modules/audio_coding/acm2/acm_receiver.cc b/webrtc/modules/audio_coding/acm2/acm_receiver.cc
index 9182bc1e0299c82253f644a3bd57fe83769165ed..36f2c36486e2b32ef5715c3871a4b49cf79c7dae 100644
--- a/webrtc/modules/audio_coding/acm2/acm_receiver.cc
+++ b/webrtc/modules/audio_coding/acm2/acm_receiver.cc
@@ -179,9 +179,12 @@ int AcmReceiver::GetAudio(int desired_freq_hz,
int32_t AcmReceiver::AddCodec(int acm_codec_id,
uint8_t payload_type,
size_t channels,
- int sample_rate_hz,
+ int /*sample_rate_hz*/,
AudioDecoder* audio_decoder,
const std::string& name) {
+ // TODO(kwiberg): This function has been ignoring the |sample_rate_hz|
+ // argument for a long time. Arguably, it should simply be removed.
+
const auto neteq_decoder = [acm_codec_id, channels]() -> NetEqDecoder {
if (acm_codec_id == -1)
return NetEqDecoder::kDecoderArbitrary; // External decoder.
@@ -193,29 +196,22 @@ int32_t AcmReceiver::AddCodec(int acm_codec_id,
RTC_DCHECK(ned) << "Invalid codec ID: " << static_cast<int>(*cid);
return *ned;
}();
+ const rtc::Optional<SdpAudioFormat> new_format =
+ RentACodec::NetEqDecoderToSdpAudioFormat(neteq_decoder);
rtc::CritScope lock(&crit_sect_);
- // The corresponding NetEq decoder ID.
- // If this codec has been registered before.
- auto it = decoders_.find(payload_type);
- if (it != decoders_.end()) {
- const Decoder& decoder = it->second;
- if (acm_codec_id != -1 && decoder.acm_codec_id == acm_codec_id &&
- decoder.channels == channels &&
- decoder.sample_rate_hz == sample_rate_hz) {
- // Re-registering the same codec. Do nothing and return.
- return 0;
- }
-
- // Changing codec. First unregister the old codec, then register the new
- // one.
- if (neteq_->RemovePayloadType(payload_type) != NetEq::kOK) {
- LOG(LERROR) << "Cannot remove payload " << static_cast<int>(payload_type);
- return -1;
- }
+ const SdpAudioFormat* const old_format =
+ neteq_->GetDecoderFormat(payload_type);
+ if (old_format && new_format && *old_format == *new_format) {
+ // Re-registering the same codec. Do nothing and return.
+ return 0;
+ }
- decoders_.erase(it);
+ if (neteq_->RemovePayloadType(payload_type) != NetEq::kOK &&
+ neteq_->LastError() != NetEq::kDecoderNotFound) {
+ LOG(LERROR) << "Cannot remove payload " << static_cast<int>(payload_type);
+ return -1;
}
int ret_val;
@@ -231,13 +227,6 @@ int32_t AcmReceiver::AddCodec(int acm_codec_id,
<< " channels: " << channels;
return -1;
}
-
- Decoder decoder;
- decoder.acm_codec_id = acm_codec_id;
- decoder.payload_type = payload_type;
- decoder.channels = channels;
- decoder.sample_rate_hz = sample_rate_hz;
- decoders_[payload_type] = decoder;
return 0;
}
@@ -248,18 +237,14 @@ void AcmReceiver::FlushBuffers() {
void AcmReceiver::RemoveAllCodecs() {
rtc::CritScope lock(&crit_sect_);
neteq_->RemoveAllPayloadTypes();
- decoders_.clear();
last_audio_decoder_ = rtc::Optional<CodecInst>();
last_packet_sample_rate_hz_ = rtc::Optional<int>();
}
int AcmReceiver::RemoveCodec(uint8_t payload_type) {
rtc::CritScope lock(&crit_sect_);
- auto it = decoders_.find(payload_type);
- if (it == decoders_.end()) { // Such a payload-type is not registered.
- return 0;
- }
- if (neteq_->RemovePayloadType(payload_type) != NetEq::kOK) {
+ if (neteq_->RemovePayloadType(payload_type) != NetEq::kOK &&
+ neteq_->LastError() != NetEq::kDecoderNotFound) {
LOG(LERROR) << "AcmReceiver::RemoveCodec" << static_cast<int>(payload_type);
return -1;
}
@@ -267,7 +252,6 @@ int AcmReceiver::RemoveCodec(uint8_t payload_type) {
last_audio_decoder_ = rtc::Optional<CodecInst>();
last_packet_sample_rate_hz_ = rtc::Optional<int>();
}
- decoders_.erase(it);
return 0;
}
« no previous file with comments | « webrtc/modules/audio_coding/acm2/acm_receiver.h ('k') | webrtc/modules/audio_coding/codecs/audio_format.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698