Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: webrtc/modules/audio_coding/main/acm2/acm_receive_test.cc

Issue 1415163002: Removing AudioCoding class, a.k.a the new ACM API (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
3 *
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.
9 */
10
11 #include "webrtc/modules/audio_coding/main/acm2/acm_receive_test.h"
12
13 #include <assert.h>
14 #include <stdio.h>
15
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"
21
22 namespace webrtc {
23 namespace test {
24
25 AcmReceiveTest::AcmReceiveTest(PacketSource* packet_source,
26 AudioSink* audio_sink,
27 int output_freq_hz,
28 NumOutputChannels expected_output_channels)
29 : clock_(0),
30 packet_source_(packet_source),
31 audio_sink_(audio_sink),
32 output_freq_hz_(output_freq_hz),
33 expected_output_channels_(expected_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));
38 }
39
40 void AcmReceiveTest::RegisterDefaultCodecs() {
41 #ifdef WEBRTC_CODEC_OPUS
42 ASSERT_TRUE(acm_->RegisterReceiveCodec(acm2::ACMCodecDB::kOpus, 120));
43 #endif
44 #if defined(WEBRTC_CODEC_ISAC) || defined(WEBRTC_CODEC_ISACFX)
45 ASSERT_TRUE(acm_->RegisterReceiveCodec(acm2::ACMCodecDB::kISAC, 103));
46 #endif
47 #ifdef WEBRTC_CODEC_ISAC
48 ASSERT_TRUE(acm_->RegisterReceiveCodec(acm2::ACMCodecDB::kISACSWB, 104));
49 #endif
50 ASSERT_TRUE(acm_->RegisterReceiveCodec(acm2::ACMCodecDB::kPCM16B, 107));
51 ASSERT_TRUE(acm_->RegisterReceiveCodec(acm2::ACMCodecDB::kPCM16Bwb, 108));
52 ASSERT_TRUE(
53 acm_->RegisterReceiveCodec(acm2::ACMCodecDB::kPCM16Bswb32kHz, 109));
54 ASSERT_TRUE(acm_->RegisterReceiveCodec(acm2::ACMCodecDB::kPCM16B_2ch, 111));
55 ASSERT_TRUE(acm_->RegisterReceiveCodec(acm2::ACMCodecDB::kPCM16Bwb_2ch, 112));
56 ASSERT_TRUE(
57 acm_->RegisterReceiveCodec(acm2::ACMCodecDB::kPCM16Bswb32kHz_2ch, 113));
58 ASSERT_TRUE(acm_->RegisterReceiveCodec(acm2::ACMCodecDB::kPCMU, 0));
59 ASSERT_TRUE(acm_->RegisterReceiveCodec(acm2::ACMCodecDB::kPCMA, 8));
60 ASSERT_TRUE(acm_->RegisterReceiveCodec(acm2::ACMCodecDB::kPCMU_2ch, 110));
61 ASSERT_TRUE(acm_->RegisterReceiveCodec(acm2::ACMCodecDB::kPCMA_2ch, 118));
62 #ifdef WEBRTC_CODEC_ILBC
63 ASSERT_TRUE(acm_->RegisterReceiveCodec(acm2::ACMCodecDB::kILBC, 102));
64 #endif
65 #ifdef WEBRTC_CODEC_G722
66 ASSERT_TRUE(acm_->RegisterReceiveCodec(acm2::ACMCodecDB::kG722, 9));
67 ASSERT_TRUE(acm_->RegisterReceiveCodec(acm2::ACMCodecDB::kG722_2ch, 119));
68 #endif
69 ASSERT_TRUE(acm_->RegisterReceiveCodec(acm2::ACMCodecDB::kCNNB, 13));
70 ASSERT_TRUE(acm_->RegisterReceiveCodec(acm2::ACMCodecDB::kCNWB, 98));
71 ASSERT_TRUE(acm_->RegisterReceiveCodec(acm2::ACMCodecDB::kCNSWB, 99));
72 #ifdef WEBRTC_CODEC_RED
73 ASSERT_TRUE(acm_->RegisterReceiveCodec(acm2::ACMCodecDB::kRED, 127));
74 #endif
75 }
76
77 void AcmReceiveTest::RegisterNetEqTestCodecs() {
78 ASSERT_TRUE(acm_->RegisterReceiveCodec(acm2::ACMCodecDB::kISAC, 103));
79 #ifndef WEBRTC_ANDROID
80 ASSERT_TRUE(acm_->RegisterReceiveCodec(acm2::ACMCodecDB::kISACSWB, 104));
81 #endif
82 ASSERT_TRUE(acm_->RegisterReceiveCodec(acm2::ACMCodecDB::kPCM16B, 93));
83 ASSERT_TRUE(acm_->RegisterReceiveCodec(acm2::ACMCodecDB::kPCM16Bwb, 94));
84 ASSERT_TRUE(
85 acm_->RegisterReceiveCodec(acm2::ACMCodecDB::kPCM16Bswb32kHz, 95));
86 ASSERT_TRUE(acm_->RegisterReceiveCodec(acm2::ACMCodecDB::kPCMU, 0));
87 ASSERT_TRUE(acm_->RegisterReceiveCodec(acm2::ACMCodecDB::kPCMA, 8));
88 ASSERT_TRUE(acm_->RegisterReceiveCodec(acm2::ACMCodecDB::kILBC, 102));
89 ASSERT_TRUE(acm_->RegisterReceiveCodec(acm2::ACMCodecDB::kG722, 9));
90 ASSERT_TRUE(acm_->RegisterReceiveCodec(acm2::ACMCodecDB::kCNNB, 13));
91 ASSERT_TRUE(acm_->RegisterReceiveCodec(acm2::ACMCodecDB::kCNWB, 98));
92 ASSERT_TRUE(acm_->RegisterReceiveCodec(acm2::ACMCodecDB::kCNSWB, 99));
93 ASSERT_TRUE(acm_->RegisterReceiveCodec(acm2::ACMCodecDB::kRED, 117));
94 }
95
96 void AcmReceiveTest::Run() {
97 for (rtc::scoped_ptr<Packet> packet(packet_source_->NextPacket()); packet;
98 packet.reset(packet_source_->NextPacket())) {
99 // Pull audio until time to insert packet.
100 while (clock_.TimeInMilliseconds() < packet->time_ms()) {
101 AudioFrame output_frame;
102 EXPECT_TRUE(acm_->Get10MsAudio(&output_frame));
103 EXPECT_EQ(output_freq_hz_, output_frame.sample_rate_hz_);
104 const size_t samples_per_block =
105 static_cast<size_t>(output_freq_hz_ * 10 / 1000);
106 EXPECT_EQ(samples_per_block, output_frame.samples_per_channel_);
107 if (expected_output_channels_ != kArbitraryChannels) {
108 if (output_frame.speech_type_ == webrtc::AudioFrame::kPLC) {
109 // Don't check number of channels for PLC output, since each test run
110 // usually starts with a short period of mono PLC before decoding the
111 // first packet.
112 } else {
113 EXPECT_EQ(expected_output_channels_, output_frame.num_channels_);
114 }
115 }
116 ASSERT_TRUE(audio_sink_->WriteAudioFrame(output_frame));
117 clock_.AdvanceTimeMilliseconds(10);
118 }
119
120 // Insert packet after converting from RTPHeader to WebRtcRTPHeader.
121 WebRtcRTPHeader header;
122 header.header = packet->header();
123 header.frameType = kAudioFrameSpeech;
124 memset(&header.type.Audio, 0, sizeof(RTPAudioHeader));
125 EXPECT_TRUE(acm_->InsertPacket(packet->payload(),
126 packet->payload_length_bytes(),
127 header))
128 << "Failure when inserting packet:" << std::endl
129 << " PT = " << static_cast<int>(header.header.payloadType) << std::endl
130 << " TS = " << header.header.timestamp << std::endl
131 << " SN = " << header.header.sequenceNumber;
132 }
133 }
134
135 } // namespace test
136 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698