diff --git a/webrtc/modules/audio_coding/acm2/acm_receiver_unittest_oldapi.cc b/webrtc/modules/audio_coding/acm2/acm_receiver_unittest_oldapi.cc index a26b2e217f..969ff40bc2 100644 --- a/webrtc/modules/audio_coding/acm2/acm_receiver_unittest_oldapi.cc +++ b/webrtc/modules/audio_coding/acm2/acm_receiver_unittest_oldapi.cc @@ -14,6 +14,8 @@ #include #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( + rtc::CheckedDivExact(output_sample_rate_hz, 1000)); + const int num_10ms_frames = rtc::CheckedDivExact( + codec.inst.pacsize, rtc::checked_cast(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 diff --git a/webrtc/modules/audio_coding/neteq/include/neteq.h b/webrtc/modules/audio_coding/neteq/include/neteq.h index d53551f897..5e06d484e5 100644 --- a/webrtc/modules/audio_coding/neteq/include/neteq.h +++ b/webrtc/modules/audio_coding/neteq/include/neteq.h @@ -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. diff --git a/webrtc/modules/audio_coding/neteq/sync_buffer.h b/webrtc/modules/audio_coding/neteq/sync_buffer.h index c3bb4a9069..5eae4bfc46 100644 --- a/webrtc/modules/audio_coding/neteq/sync_buffer.h +++ b/webrtc/modules/audio_coding/neteq/sync_buffer.h @@ -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_|.