Add new method AcmReceiver::last_packet_sample_rate_hz()

This change allows us to delete AcmReceiver::last_audio_codec_id().

BUG=webrtc:3520

Review URL: https://codereview.webrtc.org/1467183002

Cr-Commit-Position: refs/heads/master@{#10756}
This commit is contained in:
henrik.lundin
2015-11-23 08:19:52 -08:00
committed by Commit bot
parent 74e35f1d62
commit 057fb89f83
4 changed files with 26 additions and 24 deletions

View File

@ -156,6 +156,11 @@ int AcmReceiver::LeastRequiredDelayMs() const {
return neteq_->LeastRequiredDelayMs();
}
rtc::Optional<int> AcmReceiver::last_packet_sample_rate_hz() const {
CriticalSectionScoped lock(crit_sect_.get());
return last_packet_sample_rate_hz_;
}
int AcmReceiver::last_output_sample_rate_hz() const {
return neteq_->last_output_sample_rate_hz();
}
@ -190,6 +195,7 @@ int AcmReceiver::InsertPacket(const WebRtcRTPHeader& rtp_header,
decoder->acm_codec_id !=
*RentACodec::CodecIndexFromId(RentACodec::CodecId::kAVT)) {
last_audio_decoder_ = decoder;
last_packet_sample_rate_hz_ = rtc::Optional<int>(decoder->sample_rate_hz);
}
} // |crit_sect_| is released.
@ -392,6 +398,7 @@ int AcmReceiver::RemoveAllCodecs() {
// No codec is registered, invalidate last audio decoder.
last_audio_decoder_ = nullptr;
last_packet_sample_rate_hz_ = rtc::Optional<int>();
return ret_val;
}
@ -405,8 +412,10 @@ int AcmReceiver::RemoveCodec(uint8_t payload_type) {
LOG(LERROR) << "AcmReceiver::RemoveCodec" << static_cast<int>(payload_type);
return -1;
}
if (last_audio_decoder_ == &it->second)
if (last_audio_decoder_ == &it->second) {
last_audio_decoder_ = nullptr;
last_packet_sample_rate_hz_ = rtc::Optional<int>();
}
decoders_.erase(it);
return 0;
}
@ -420,11 +429,6 @@ bool AcmReceiver::GetPlayoutTimestamp(uint32_t* timestamp) {
return neteq_->GetPlayoutTimestamp(timestamp);
}
int AcmReceiver::last_audio_codec_id() const {
CriticalSectionScoped lock(crit_sect_.get());
return last_audio_decoder_ ? last_audio_decoder_->acm_codec_id : -1;
}
int AcmReceiver::LastAudioCodec(CodecInst* codec) const {
CriticalSectionScoped lock(crit_sect_.get());
if (!last_audio_decoder_) {

View File

@ -15,6 +15,7 @@
#include <vector>
#include "webrtc/base/array_view.h"
#include "webrtc/base/optional.h"
#include "webrtc/base/scoped_ptr.h"
#include "webrtc/base/thread_annotations.h"
#include "webrtc/common_audio/vad/include/webrtc_vad.h"
@ -154,6 +155,12 @@ class AcmReceiver {
//
void ResetInitialDelay();
// Returns the sample rate of the decoder associated with the last incoming
// packet. If no packet of a registered non-CNG codec has been received, the
// return value is empty. Also, if the decoder was unregistered since the last
// packet was inserted, the return value is empty.
rtc::Optional<int> last_packet_sample_rate_hz() const;
// Returns last_output_sample_rate_hz from the NetEq instance.
int last_output_sample_rate_hz() const;
@ -212,13 +219,6 @@ class AcmReceiver {
//
bool GetPlayoutTimestamp(uint32_t* timestamp);
//
// Return the index of the codec associated with the last non-CNG/non-DTMF
// received payload. If no non-CNG/non-DTMF payload is received -1 is
// returned.
//
int last_audio_codec_id() const; // TODO(turajs): can be inline.
//
// Get the audio codec associated with the last non-CNG/non-DTMF received
// payload. If no non-CNG/non-DTMF packet is received -1 is returned,
@ -295,6 +295,7 @@ class AcmReceiver {
bool vad_enabled_;
Clock* clock_; // TODO(henrik.lundin) Make const if possible.
bool resampled_last_output_frame_ GUARDED_BY(crit_sect_);
rtc::Optional<int> last_packet_sample_rate_hz_ GUARDED_BY(crit_sect_);
};
} // namespace acm2

View File

@ -330,7 +330,7 @@ TEST_F(AcmReceiverTestOldApi,
// Has received, only, DTX. Last Audio codec is undefined.
EXPECT_EQ(-1, receiver_->LastAudioCodec(&codec));
EXPECT_EQ(-1, receiver_->last_audio_codec_id());
EXPECT_FALSE(receiver_->last_packet_sample_rate_hz());
for (auto id : kCodecId) {
const CodecIdInst c(id);
@ -344,7 +344,8 @@ TEST_F(AcmReceiverTestOldApi,
// of type "speech."
ASSERT_TRUE(packet_sent_);
ASSERT_EQ(kAudioFrameSpeech, last_frame_type_);
EXPECT_EQ(c.id, receiver_->last_audio_codec_id());
EXPECT_EQ(rtc::Optional<int>(c.inst.plfreq),
receiver_->last_packet_sample_rate_hz());
// Set VAD on to send DTX. Then check if the "Last Audio codec" returns
// the expected codec.
@ -356,7 +357,8 @@ TEST_F(AcmReceiverTestOldApi,
InsertOnePacketOfSilence(c.id);
ASSERT_TRUE(packet_sent_);
}
EXPECT_EQ(c.id, receiver_->last_audio_codec_id());
EXPECT_EQ(rtc::Optional<int>(c.inst.plfreq),
receiver_->last_packet_sample_rate_hz());
EXPECT_EQ(0, receiver_->LastAudioCodec(&codec));
EXPECT_TRUE(CodecsEqual(c.inst, codec));
}

View File

@ -525,14 +525,9 @@ int AudioCodingModuleImpl::InitializeReceiverSafe() {
// Get current receive frequency.
int AudioCodingModuleImpl::ReceiveFrequency() const {
WEBRTC_TRACE(webrtc::kTraceStream, webrtc::kTraceAudioCoding, id_,
"ReceiveFrequency()");
CriticalSectionScoped lock(acm_crit_sect_.get());
auto codec_id = RentACodec::CodecIdFromIndex(receiver_.last_audio_codec_id());
return codec_id ? RentACodec::CodecInstById(*codec_id)->plfreq
: receiver_.last_output_sample_rate_hz();
const auto last_packet_sample_rate = receiver_.last_packet_sample_rate_hz();
return last_packet_sample_rate ? *last_packet_sample_rate
: receiver_.last_output_sample_rate_hz();
}
// Get current playout frequency.