2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
11 #include "webrtc/modules/audio_coding/main/acm2/acm_receive_test.h"
16 #include "testing/gtest/include/gtest/gtest.h"
17 #include "webrtc/modules/audio_coding/main/interface/audio_coding_module.h"
18 #include "webrtc/modules/audio_coding/neteq/tools/audio_sink.h"
19 #include "webrtc/modules/audio_coding/neteq/tools/packet.h"
20 #include "webrtc/modules/audio_coding/neteq/tools/packet_source.h"
25 AcmReceiveTest::AcmReceiveTest(PacketSource* packet_source,
26 AudioSink* audio_sink,
28 NumOutputChannels exptected_output_channels)
30 packet_source_(packet_source),
31 audio_sink_(audio_sink),
32 output_freq_hz_(output_freq_hz),
33 exptected_output_channels_(exptected_output_channels) {
34 webrtc::AudioCoding::Config config;
35 config.clock = &clock_;
36 config.playout_frequency_hz = output_freq_hz_;
37 acm_.reset(webrtc::AudioCoding::Create(config));
40 void AcmReceiveTest::RegisterDefaultCodecs() {
41 ASSERT_TRUE(acm_->RegisterReceiveCodec(acm2::ACMCodecDB::kOpus, 120));
42 ASSERT_TRUE(acm_->RegisterReceiveCodec(acm2::ACMCodecDB::kISAC, 103));
43 #ifndef WEBRTC_ANDROID
44 ASSERT_TRUE(acm_->RegisterReceiveCodec(acm2::ACMCodecDB::kISACSWB, 104));
45 ASSERT_TRUE(acm_->RegisterReceiveCodec(acm2::ACMCodecDB::kISACFB, 105));
47 ASSERT_TRUE(acm_->RegisterReceiveCodec(acm2::ACMCodecDB::kPCM16B, 107));
48 ASSERT_TRUE(acm_->RegisterReceiveCodec(acm2::ACMCodecDB::kPCM16Bwb, 108));
50 acm_->RegisterReceiveCodec(acm2::ACMCodecDB::kPCM16Bswb32kHz, 109));
51 ASSERT_TRUE(acm_->RegisterReceiveCodec(acm2::ACMCodecDB::kPCM16B_2ch, 111));
52 ASSERT_TRUE(acm_->RegisterReceiveCodec(acm2::ACMCodecDB::kPCM16Bwb_2ch, 112));
54 acm_->RegisterReceiveCodec(acm2::ACMCodecDB::kPCM16Bswb32kHz_2ch, 113));
55 ASSERT_TRUE(acm_->RegisterReceiveCodec(acm2::ACMCodecDB::kPCMU, 0));
56 ASSERT_TRUE(acm_->RegisterReceiveCodec(acm2::ACMCodecDB::kPCMA, 8));
57 ASSERT_TRUE(acm_->RegisterReceiveCodec(acm2::ACMCodecDB::kPCMU_2ch, 110));
58 ASSERT_TRUE(acm_->RegisterReceiveCodec(acm2::ACMCodecDB::kPCMA_2ch, 118));
59 ASSERT_TRUE(acm_->RegisterReceiveCodec(acm2::ACMCodecDB::kILBC, 102));
60 ASSERT_TRUE(acm_->RegisterReceiveCodec(acm2::ACMCodecDB::kG722, 9));
61 ASSERT_TRUE(acm_->RegisterReceiveCodec(acm2::ACMCodecDB::kG722_2ch, 119));
62 ASSERT_TRUE(acm_->RegisterReceiveCodec(acm2::ACMCodecDB::kCNNB, 13));
63 ASSERT_TRUE(acm_->RegisterReceiveCodec(acm2::ACMCodecDB::kCNWB, 98));
64 ASSERT_TRUE(acm_->RegisterReceiveCodec(acm2::ACMCodecDB::kCNSWB, 99));
65 ASSERT_TRUE(acm_->RegisterReceiveCodec(acm2::ACMCodecDB::kRED, 127));
68 void AcmReceiveTest::RegisterNetEqTestCodecs() {
69 ASSERT_TRUE(acm_->RegisterReceiveCodec(acm2::ACMCodecDB::kISAC, 103));
70 #ifndef WEBRTC_ANDROID
71 ASSERT_TRUE(acm_->RegisterReceiveCodec(acm2::ACMCodecDB::kISACSWB, 104));
72 ASSERT_TRUE(acm_->RegisterReceiveCodec(acm2::ACMCodecDB::kISACFB, 124));
74 ASSERT_TRUE(acm_->RegisterReceiveCodec(acm2::ACMCodecDB::kPCM16B, 93));
75 ASSERT_TRUE(acm_->RegisterReceiveCodec(acm2::ACMCodecDB::kPCM16Bwb, 94));
77 acm_->RegisterReceiveCodec(acm2::ACMCodecDB::kPCM16Bswb32kHz, 95));
78 ASSERT_TRUE(acm_->RegisterReceiveCodec(acm2::ACMCodecDB::kPCMU, 0));
79 ASSERT_TRUE(acm_->RegisterReceiveCodec(acm2::ACMCodecDB::kPCMA, 8));
80 ASSERT_TRUE(acm_->RegisterReceiveCodec(acm2::ACMCodecDB::kILBC, 102));
81 ASSERT_TRUE(acm_->RegisterReceiveCodec(acm2::ACMCodecDB::kG722, 9));
82 ASSERT_TRUE(acm_->RegisterReceiveCodec(acm2::ACMCodecDB::kCNNB, 13));
83 ASSERT_TRUE(acm_->RegisterReceiveCodec(acm2::ACMCodecDB::kCNWB, 98));
84 ASSERT_TRUE(acm_->RegisterReceiveCodec(acm2::ACMCodecDB::kCNSWB, 99));
85 ASSERT_TRUE(acm_->RegisterReceiveCodec(acm2::ACMCodecDB::kRED, 117));
88 void AcmReceiveTest::Run() {
89 for (scoped_ptr<Packet> packet(packet_source_->NextPacket()); packet;
90 packet.reset(packet_source_->NextPacket())) {
91 // Pull audio until time to insert packet.
92 while (clock_.TimeInMilliseconds() < packet->time_ms()) {
93 AudioFrame output_frame;
94 EXPECT_TRUE(acm_->Get10MsAudio(&output_frame));
95 EXPECT_EQ(output_freq_hz_, output_frame.sample_rate_hz_);
96 const int samples_per_block = output_freq_hz_ * 10 / 1000;
97 EXPECT_EQ(samples_per_block, output_frame.samples_per_channel_);
98 if (exptected_output_channels_ != kArbitraryChannels) {
99 if (output_frame.speech_type_ == webrtc::AudioFrame::kPLC) {
100 // Don't check number of channels for PLC output, since each test run
101 // usually starts with a short period of mono PLC before decoding the
104 EXPECT_EQ(exptected_output_channels_, output_frame.num_channels_);
107 ASSERT_TRUE(audio_sink_->WriteAudioFrame(output_frame));
108 clock_.AdvanceTimeMilliseconds(10);
111 // Insert packet after converting from RTPHeader to WebRtcRTPHeader.
112 WebRtcRTPHeader header;
113 header.header = packet->header();
114 header.frameType = kAudioFrameSpeech;
115 memset(&header.type.Audio, 0, sizeof(RTPAudioHeader));
117 acm_->InsertPacket(packet->payload(),
118 static_cast<int32_t>(packet->payload_length_bytes()),
120 << "Failure when inserting packet:" << std::endl
121 << " PT = " << static_cast<int>(header.header.payloadType) << std::endl
122 << " TS = " << header.header.timestamp << std::endl
123 << " SN = " << header.header.sequenceNumber;
128 } // namespace webrtc