OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright (c) 2016 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 "testing/gtest/include/gtest/gtest.h" | |
12 #include "webrtc/modules/audio_coding/acm2/rent_a_codec.h" | |
13 #include "webrtc/modules/audio_coding/codecs/legacy_encoded_audio_frame.h" | |
14 | |
15 namespace webrtc { | |
16 | |
17 using NetEqDecoder = acm2::RentACodec::NetEqDecoder; | |
18 | |
19 class SplitBySamplesTest : public ::testing::TestWithParam<NetEqDecoder> { | |
20 protected: | |
21 virtual void SetUp() { | |
22 decoder_type_ = GetParam(); | |
23 switch (decoder_type_) { | |
24 case NetEqDecoder::kDecoderPCMu: | |
25 case NetEqDecoder::kDecoderPCMa: | |
26 bytes_per_ms_ = 8; | |
27 samples_per_ms_ = 8; | |
28 break; | |
29 case NetEqDecoder::kDecoderPCMu_2ch: | |
30 case NetEqDecoder::kDecoderPCMa_2ch: | |
31 bytes_per_ms_ = 2 * 8; | |
32 samples_per_ms_ = 8; | |
33 break; | |
34 case NetEqDecoder::kDecoderG722: | |
35 bytes_per_ms_ = 8; | |
36 samples_per_ms_ = 16; | |
37 break; | |
38 case NetEqDecoder::kDecoderPCM16B: | |
39 bytes_per_ms_ = 16; | |
40 samples_per_ms_ = 8; | |
41 break; | |
42 case NetEqDecoder::kDecoderPCM16Bwb: | |
43 bytes_per_ms_ = 32; | |
44 samples_per_ms_ = 16; | |
45 break; | |
46 case NetEqDecoder::kDecoderPCM16Bswb32kHz: | |
47 bytes_per_ms_ = 64; | |
48 samples_per_ms_ = 32; | |
49 break; | |
50 case NetEqDecoder::kDecoderPCM16Bswb48kHz: | |
51 bytes_per_ms_ = 96; | |
52 samples_per_ms_ = 48; | |
53 break; | |
54 case NetEqDecoder::kDecoderPCM16B_2ch: | |
55 bytes_per_ms_ = 2 * 16; | |
56 samples_per_ms_ = 8; | |
57 break; | |
58 case NetEqDecoder::kDecoderPCM16Bwb_2ch: | |
59 bytes_per_ms_ = 2 * 32; | |
60 samples_per_ms_ = 16; | |
61 break; | |
62 case NetEqDecoder::kDecoderPCM16Bswb32kHz_2ch: | |
63 bytes_per_ms_ = 2 * 64; | |
64 samples_per_ms_ = 32; | |
65 break; | |
66 case NetEqDecoder::kDecoderPCM16Bswb48kHz_2ch: | |
67 bytes_per_ms_ = 2 * 96; | |
68 samples_per_ms_ = 48; | |
69 break; | |
70 case NetEqDecoder::kDecoderPCM16B_5ch: | |
71 bytes_per_ms_ = 5 * 16; | |
72 samples_per_ms_ = 8; | |
73 break; | |
74 default: | |
75 assert(false); | |
76 break; | |
77 } | |
78 } | |
79 size_t bytes_per_ms_; | |
80 int samples_per_ms_; | |
81 NetEqDecoder decoder_type_; | |
82 }; | |
83 | |
84 // Test splitting sample-based payloads. | |
85 TEST_P(SplitBySamplesTest, PayloadSizes) { | |
86 constexpr uint32_t kBaseTimestamp = 0x12345678; | |
87 struct ExpectedSplit { | |
88 size_t payload_size_ms; | |
89 size_t num_frames; | |
90 // For simplicity. We only expect up to two packets per split. | |
91 size_t frame_sizes[2]; | |
92 }; | |
93 // The payloads are expected to be split as follows: | |
94 // 10 ms -> 10 ms | |
95 // 20 ms -> 20 ms | |
96 // 30 ms -> 30 ms | |
97 // 40 ms -> 20 + 20 ms | |
98 // 50 ms -> 25 + 25 ms | |
99 // 60 ms -> 30 + 30 ms | |
100 ExpectedSplit expected_splits[] = { | |
101 {10, 1, {10}}, | |
102 {20, 1, {20}}, | |
103 {30, 1, {30}}, | |
104 {40, 2, {20, 20}}, | |
105 {50, 2, {25, 25}}, | |
106 {60, 2, {30, 30}} | |
107 }; | |
108 | |
109 for (const auto& expected_split : expected_splits) { | |
110 // The payload values are set to steadily increase (modulo 256), so that the | |
111 // resulting frames can be checked and we can be reasonably certain no | |
112 // sample was missed or repeated. | |
113 rtc::Buffer payload(expected_split.payload_size_ms * bytes_per_ms_); | |
114 uint8_t value = 0; | |
115 // Allow wrap-around of value in counter below. | |
116 for (size_t i = 0; i != payload.size(); ++i, ++value) { | |
117 payload[i] = value; | |
118 } | |
119 | |
120 auto results = LegacyEncodedAudioFrame::SplitBySamples( | |
121 nullptr, &payload, kBaseTimestamp, true, bytes_per_ms_, | |
122 samples_per_ms_); | |
123 | |
124 EXPECT_EQ(expected_split.num_frames, results.size()); | |
125 uint32_t expected_timestamp = kBaseTimestamp; | |
126 uint32_t expected_byte_offset = 0; | |
127 value = 0; | |
kwiberg-webrtc
2016/09/15 13:01:25
It's easier to read if you don't reuse variables.
ossu
2016/09/15 14:41:06
It's easier to write if I do. ;)
Just kidding. Wit
kwiberg-webrtc
2016/09/16 00:48:08
Nice!
| |
128 for (size_t i = 0; i != expected_split.num_frames; ++i) { | |
129 const auto& result = results[i]; | |
130 const LegacyEncodedAudioFrame* frame = | |
131 static_cast<const LegacyEncodedAudioFrame*>(result.frame.get()); | |
132 const size_t length_bytes = expected_split.frame_sizes[i] * bytes_per_ms_; | |
133 EXPECT_EQ(length_bytes, frame->payload().size()); | |
134 EXPECT_EQ(expected_timestamp, result.timestamp); | |
135 const rtc::Buffer& payload = frame->payload(); | |
136 // Allow wrap-around of value in counter below. | |
137 for (size_t i = 0; i != payload.size(); ++i, ++value) { | |
138 ASSERT_EQ(value, payload[i]); | |
139 } | |
140 | |
141 expected_timestamp += expected_split.frame_sizes[i] * samples_per_ms_; | |
142 expected_byte_offset += length_bytes; | |
143 } | |
144 } | |
145 } | |
146 | |
147 INSTANTIATE_TEST_CASE_P( | |
148 AudioCodingUtils, | |
149 SplitBySamplesTest, | |
150 ::testing::Values(NetEqDecoder::kDecoderPCMu, | |
151 NetEqDecoder::kDecoderPCMa, | |
152 NetEqDecoder::kDecoderPCMu_2ch, | |
153 NetEqDecoder::kDecoderPCMa_2ch, | |
154 NetEqDecoder::kDecoderG722, | |
155 NetEqDecoder::kDecoderPCM16B, | |
156 NetEqDecoder::kDecoderPCM16Bwb, | |
157 NetEqDecoder::kDecoderPCM16Bswb32kHz, | |
158 NetEqDecoder::kDecoderPCM16Bswb48kHz, | |
159 NetEqDecoder::kDecoderPCM16B_2ch, | |
160 NetEqDecoder::kDecoderPCM16Bwb_2ch, | |
161 NetEqDecoder::kDecoderPCM16Bswb32kHz_2ch, | |
162 NetEqDecoder::kDecoderPCM16Bswb48kHz_2ch, | |
163 NetEqDecoder::kDecoderPCM16B_5ch)); | |
164 | |
165 } // namespace webrtc | |
OLD | NEW |