NetEq: Add new method last_output_sample_rate_hz
This change moves the logics for keeping track of the last ouput sample rate from AcmReceiver to NetEq, where it fits better. The getter function AcmReceiver::current_sample_rate_hz() is renamed to last_output_sample_rate_hz(). BUG=webrtc:3520 Review URL: https://codereview.webrtc.org/1467163002 Cr-Commit-Position: refs/heads/master@{#10754}
This commit is contained in:
committed by
Commit bot
parent
dfafd12418
commit
d89814bfd7
@ -251,6 +251,11 @@ class NetEq {
|
||||
// Returns true if the RTP timestamp is valid, otherwise false.
|
||||
virtual bool GetPlayoutTimestamp(uint32_t* timestamp) = 0;
|
||||
|
||||
// Returns the sample rate in Hz of the audio produced in the last GetAudio
|
||||
// call. If GetAudio has not been called yet, the configured sample rate
|
||||
// (Config::sample_rate_hz) is returned.
|
||||
virtual int last_output_sample_rate_hz() const = 0;
|
||||
|
||||
// Not implemented.
|
||||
virtual int SetTargetNumberOfChannels() = 0;
|
||||
|
||||
|
||||
@ -106,6 +106,7 @@ NetEqImpl::NetEqImpl(const NetEq::Config& config,
|
||||
}
|
||||
fs_hz_ = fs;
|
||||
fs_mult_ = fs / 8000;
|
||||
last_output_sample_rate_hz_ = fs;
|
||||
output_size_samples_ = static_cast<size_t>(kOutputSizeMs * 8 * fs_mult_);
|
||||
decoder_frame_length_ = 3 * output_size_samples_;
|
||||
WebRtcSpl_Init();
|
||||
@ -160,6 +161,13 @@ int NetEqImpl::GetAudio(size_t max_length, int16_t* output_audio,
|
||||
if (type) {
|
||||
*type = LastOutputType();
|
||||
}
|
||||
last_output_sample_rate_hz_ =
|
||||
rtc::checked_cast<int>(*samples_per_channel * 100);
|
||||
RTC_DCHECK(last_output_sample_rate_hz_ == 8000 ||
|
||||
last_output_sample_rate_hz_ == 16000 ||
|
||||
last_output_sample_rate_hz_ == 32000 ||
|
||||
last_output_sample_rate_hz_ == 48000)
|
||||
<< "Unexpected sample rate " << last_output_sample_rate_hz_;
|
||||
return kOK;
|
||||
}
|
||||
|
||||
@ -359,6 +367,11 @@ bool NetEqImpl::GetPlayoutTimestamp(uint32_t* timestamp) {
|
||||
return true;
|
||||
}
|
||||
|
||||
int NetEqImpl::last_output_sample_rate_hz() const {
|
||||
CriticalSectionScoped lock(crit_sect_.get());
|
||||
return last_output_sample_rate_hz_;
|
||||
}
|
||||
|
||||
int NetEqImpl::SetTargetNumberOfChannels() {
|
||||
return kNotImplemented;
|
||||
}
|
||||
|
||||
@ -168,6 +168,8 @@ class NetEqImpl : public webrtc::NetEq {
|
||||
|
||||
bool GetPlayoutTimestamp(uint32_t* timestamp) override;
|
||||
|
||||
int last_output_sample_rate_hz() const override;
|
||||
|
||||
int SetTargetNumberOfChannels() override;
|
||||
|
||||
int SetTargetSampleRate() override;
|
||||
@ -375,6 +377,7 @@ class NetEqImpl : public webrtc::NetEq {
|
||||
StatisticsCalculator stats_ GUARDED_BY(crit_sect_);
|
||||
int fs_hz_ GUARDED_BY(crit_sect_);
|
||||
int fs_mult_ GUARDED_BY(crit_sect_);
|
||||
int last_output_sample_rate_hz_ GUARDED_BY(crit_sect_);
|
||||
size_t output_size_samples_ GUARDED_BY(crit_sect_);
|
||||
size_t decoder_frame_length_ GUARDED_BY(crit_sect_);
|
||||
Modes last_mode_ GUARDED_BY(crit_sect_);
|
||||
|
||||
@ -1230,4 +1230,13 @@ TEST_F(NetEqImplTest, DecodingErrorDuringInternalCng) {
|
||||
EXPECT_CALL(mock_decoder, Die());
|
||||
}
|
||||
|
||||
// Tests that the return value from last_output_sample_rate_hz() is equal to the
|
||||
// configured inital sample rate.
|
||||
TEST_F(NetEqImplTest, InitialLastOutputSampleRate) {
|
||||
UseNoMocks();
|
||||
config_.sample_rate_hz = 48000;
|
||||
CreateInstance();
|
||||
EXPECT_EQ(48000, neteq_->last_output_sample_rate_hz());
|
||||
}
|
||||
|
||||
}// namespace webrtc
|
||||
|
||||
@ -362,6 +362,7 @@ void NetEqDecodingTest::Process(size_t* out_len) {
|
||||
(*out_len == kBlockSize16kHz) ||
|
||||
(*out_len == kBlockSize32kHz));
|
||||
output_sample_rate_ = static_cast<int>(*out_len / 10 * 1000);
|
||||
EXPECT_EQ(output_sample_rate_, neteq_->last_output_sample_rate_hz());
|
||||
|
||||
// Increase time.
|
||||
sim_clock_ += kTimeStepMs;
|
||||
@ -895,6 +896,8 @@ TEST_F(NetEqDecodingTest, GetAudioBeforeInsertPacket) {
|
||||
SCOPED_TRACE(ss.str()); // Print out the parameter values on failure.
|
||||
EXPECT_EQ(0, out_data_[i]);
|
||||
}
|
||||
// Verify that the sample rate did not change from the initial configuration.
|
||||
EXPECT_EQ(config_.sample_rate_hz, neteq_->last_output_sample_rate_hz());
|
||||
}
|
||||
|
||||
class NetEqBgnTest : public NetEqDecodingTest {
|
||||
|
||||
@ -56,6 +56,7 @@ size_t NetEqExternalDecoderTest::GetOutputAudio(size_t max_length,
|
||||
EXPECT_EQ(channels_, num_channels);
|
||||
EXPECT_EQ(static_cast<size_t>(kOutputLengthMs * sample_rate_hz_ / 1000),
|
||||
samples_per_channel);
|
||||
EXPECT_EQ(sample_rate_hz_, neteq_->last_output_sample_rate_hz());
|
||||
return samples_per_channel;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user