Unit test for AudioFrame output from AcmReceiver::GetAudio

This new unit test verifies the parameter fields (not the audio data
itself) written to the AudioFrame output by AcmReceiver::GetAudio.

Also corrected a few comments reflecting recent changes in the code.

BUG=webrtc:5669

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

Cr-Commit-Position: refs/heads/master@{#12253}
This commit is contained in:
henrik.lundin
2016-04-06 01:03:02 -07:00
committed by Commit bot
parent 6172401972
commit 7dc68897d3
3 changed files with 83 additions and 4 deletions

View File

@ -14,6 +14,8 @@
#include <memory>
#include "testing/gtest/include/gtest/gtest.h"
#include "webrtc/base/checks.h"
#include "webrtc/base/safe_conversions.h"
#include "webrtc/modules/audio_coding/include/audio_coding_module.h"
#include "webrtc/modules/audio_coding/acm2/audio_coding_module_impl.h"
#include "webrtc/modules/audio_coding/neteq/tools/rtp_generator.h"
@ -289,6 +291,84 @@ TEST_F(AcmReceiverTestOldApi, MAYBE_SampleRate) {
}
}
class AcmReceiverTestFaxModeOldApi : public AcmReceiverTestOldApi {
protected:
AcmReceiverTestFaxModeOldApi() {
config_.neteq_config.playout_mode = kPlayoutFax;
}
void RunVerifyAudioFrame(RentACodec::CodecId codec_id) {
// Make sure "fax mode" is enabled. This will avoid delay changes unless the
// packet-loss concealment is made. We do this in order to make the
// timestamp increments predictable; in normal mode, NetEq may decide to do
// accelerate or pre-emptive expand operations after some time, offsetting
// the timestamp.
EXPECT_EQ(kPlayoutFax, config_.neteq_config.playout_mode);
const RentACodec::CodecId kCodecId[] = {codec_id};
AddSetOfCodecs(kCodecId);
const CodecIdInst codec(codec_id);
const int output_sample_rate_hz = codec.inst.plfreq;
const size_t output_channels = codec.inst.channels;
const size_t samples_per_ms = rtc::checked_cast<size_t>(
rtc::CheckedDivExact(output_sample_rate_hz, 1000));
const int num_10ms_frames = rtc::CheckedDivExact(
codec.inst.pacsize, rtc::checked_cast<int>(10 * samples_per_ms));
const AudioFrame::VADActivity expected_vad_activity =
output_sample_rate_hz > 16000 ? AudioFrame::kVadActive
: AudioFrame::kVadPassive;
// Expect the first output timestamp to be 5*fs/8000 samples before the
// first inserted timestamp (because of NetEq's look-ahead). (This value is
// defined in Expand::overlap_length_.)
uint32_t expected_output_ts = last_packet_send_timestamp_ -
rtc::CheckedDivExact(5 * output_sample_rate_hz, 8000);
AudioFrame frame;
for (int i = 0; i < 5; ++i) {
InsertOnePacketOfSilence(codec.id);
for (int k = 0; k < num_10ms_frames; ++k) {
EXPECT_EQ(0, receiver_->GetAudio(output_sample_rate_hz, &frame));
EXPECT_EQ(expected_output_ts, frame.timestamp_);
expected_output_ts += 10 * samples_per_ms;
EXPECT_EQ(10 * samples_per_ms, frame.samples_per_channel_);
EXPECT_EQ(output_sample_rate_hz, frame.sample_rate_hz_);
EXPECT_EQ(output_channels, frame.num_channels_);
EXPECT_EQ(AudioFrame::kNormalSpeech, frame.speech_type_);
EXPECT_EQ(expected_vad_activity, frame.vad_activity_);
}
}
}
};
#if defined(WEBRTC_ANDROID)
#define MAYBE_VerifyAudioFramePCMU DISABLED_VerifyAudioFramePCMU
#else
#define MAYBE_VerifyAudioFramePCMU VerifyAudioFramePCMU
#endif
TEST_F(AcmReceiverTestFaxModeOldApi, MAYBE_VerifyAudioFramePCMU) {
RunVerifyAudioFrame(RentACodec::CodecId::kPCMU);
}
#if defined(WEBRTC_ANDROID)
#define MAYBE_VerifyAudioFrameISAC DISABLED_VerifyAudioFrameISAC
#else
#define MAYBE_VerifyAudioFrameISAC VerifyAudioFrameISAC
#endif
TEST_F(AcmReceiverTestFaxModeOldApi, MAYBE_VerifyAudioFrameISAC) {
RunVerifyAudioFrame(RentACodec::CodecId::kISAC);
}
#if defined(WEBRTC_ANDROID)
#define MAYBE_VerifyAudioFrameOpus DISABLED_VerifyAudioFrameOpus
#else
#define MAYBE_VerifyAudioFrameOpus VerifyAudioFrameOpus
#endif
TEST_F(AcmReceiverTestFaxModeOldApi, MAYBE_VerifyAudioFrameOpus) {
RunVerifyAudioFrame(RentACodec::CodecId::kOpus);
}
#if defined(WEBRTC_ANDROID)
#define MAYBE_PostdecodingVad DISABLED_PostdecodingVad
#else

View File

@ -156,8 +156,8 @@ class NetEq {
uint32_t receive_timestamp) = 0;
// Instructs NetEq to deliver 10 ms of audio data. The data is written to
// |audio_frame|. All data in |audio_frame| is wiped; |data_|, |interleaved_|,
// |num_channels_|, |samples_per_channel_|, |speech_type_|, and
// |audio_frame|. All data in |audio_frame| is wiped; |data_|, |speech_type_|,
// |num_channels_|, |sample_rate_hz_|, |samples_per_channel_|, and
// |vad_activity_| are updated upon success. If an error is returned, some
// fields may not have been updated.
// Returns kOK on success, or kFail in case of an error.

View File

@ -67,8 +67,7 @@ class SyncBuffer : public AudioMultiVector {
// Reads |requested_len| samples from each channel and writes them interleaved
// into |output|. The |next_index_| is updated to point to the sample to read
// next time. The AudioFrame |output| is first reset, and the |data_|,
// |interleaved_|, |num_channels_|, and |samples_per_channel_| fields are
// updated.
// |num_channels_|, and |samples_per_channel_| fields are updated.
void GetNextAudioInterleaved(size_t requested_len, AudioFrame* output);
// Adds |increment| to |end_timestamp_|.