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 | |
12 #include "testing/gtest/include/gtest/gtest.h" | |
13 #include "webrtc/modules/audio_coding/acm2/rent_a_codec.h" | |
14 #include "webrtc/modules/audio_coding/codecs/split_by_samples.h" | |
15 | |
16 namespace webrtc { | |
17 | |
18 using NetEqDecoder = acm2::RentACodec::NetEqDecoder; | |
19 | |
20 class SplitBySamplesTest : public ::testing::TestWithParam<NetEqDecoder> { | |
21 protected: | |
22 virtual void SetUp() { | |
23 decoder_type_ = GetParam(); | |
24 switch (decoder_type_) { | |
25 case NetEqDecoder::kDecoderPCMu: | |
26 case NetEqDecoder::kDecoderPCMa: | |
27 bytes_per_ms_ = 8; | |
28 samples_per_ms_ = 8; | |
29 break; | |
30 case NetEqDecoder::kDecoderPCMu_2ch: | |
31 case NetEqDecoder::kDecoderPCMa_2ch: | |
32 bytes_per_ms_ = 2 * 8; | |
33 samples_per_ms_ = 8; | |
34 break; | |
35 case NetEqDecoder::kDecoderG722: | |
36 bytes_per_ms_ = 8; | |
37 samples_per_ms_ = 16; | |
38 break; | |
39 case NetEqDecoder::kDecoderPCM16B: | |
40 bytes_per_ms_ = 16; | |
41 samples_per_ms_ = 8; | |
42 break; | |
43 case NetEqDecoder::kDecoderPCM16Bwb: | |
44 bytes_per_ms_ = 32; | |
45 samples_per_ms_ = 16; | |
46 break; | |
47 case NetEqDecoder::kDecoderPCM16Bswb32kHz: | |
48 bytes_per_ms_ = 64; | |
49 samples_per_ms_ = 32; | |
50 break; | |
51 case NetEqDecoder::kDecoderPCM16Bswb48kHz: | |
52 bytes_per_ms_ = 96; | |
53 samples_per_ms_ = 48; | |
54 break; | |
55 case NetEqDecoder::kDecoderPCM16B_2ch: | |
56 bytes_per_ms_ = 2 * 16; | |
57 samples_per_ms_ = 8; | |
58 break; | |
59 case NetEqDecoder::kDecoderPCM16Bwb_2ch: | |
60 bytes_per_ms_ = 2 * 32; | |
61 samples_per_ms_ = 16; | |
62 break; | |
63 case NetEqDecoder::kDecoderPCM16Bswb32kHz_2ch: | |
64 bytes_per_ms_ = 2 * 64; | |
65 samples_per_ms_ = 32; | |
66 break; | |
67 case NetEqDecoder::kDecoderPCM16Bswb48kHz_2ch: | |
68 bytes_per_ms_ = 2 * 96; | |
69 samples_per_ms_ = 48; | |
70 break; | |
71 case NetEqDecoder::kDecoderPCM16B_5ch: | |
72 bytes_per_ms_ = 5 * 16; | |
73 samples_per_ms_ = 8; | |
74 break; | |
75 default: | |
76 assert(false); | |
77 break; | |
78 } | |
79 } | |
80 size_t bytes_per_ms_; | |
81 int samples_per_ms_; | |
82 NetEqDecoder decoder_type_; | |
83 }; | |
kwiberg-webrtc
2016/09/12 02:11:02
Why use the NetEqDecoder enum, instead of feeding
ossu
2016/09/12 11:26:38
I took the test as much as possible as it was. My
| |
84 | |
85 // Test splitting sample-based payloads. | |
86 TEST_P(SplitBySamplesTest, PayloadSizes) { | |
87 struct ExpectedSplit { | |
88 size_t payload_size_ms; | |
89 size_t num_splits; | |
90 // For simplicity. We only expect up to two packets per split. | |
91 size_t split_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[] = { | |
kwiberg-webrtc
2016/09/12 02:11:02
constexpr
ossu
2016/09/12 11:26:38
Sure, but does it really matter? I mean, it's not
kwiberg-webrtc
2016/09/13 12:23:37
Documentation. The important step is making it con
| |
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 // int expected_size_ms[] = {10, 20, 30, 20, 20, 25, 25, 30, 30}; | |
110 // int expected_payload_value[] = {10, 20, 30, 40, 40, 50, 50, 60, 60}; | |
111 // int expected_timestamp_offset_ms[] = {0, 0, 0, 0, 20, 0, 25, 0, 30}; | |
112 // int expected_num_packets[] = {1, 1, 1, 2, 2, 2}; | |
kwiberg-webrtc
2016/09/12 02:11:02
Are these useful or not?
ossu
2016/09/12 11:26:38
Useful during review to make sure the values above
kwiberg-webrtc
2016/09/13 12:23:37
Acknowledged.
| |
113 | |
114 for (const auto& expected_split : expected_splits) { | |
115 // The payload values are set to be the same as the payload_size, so that | |
116 // one can distinguish from which packet the split payloads come from. | |
117 size_t payload_size_bytes = expected_split.payload_size_ms * bytes_per_ms_; | |
kwiberg-webrtc
2016/09/12 02:11:02
const
ossu
2016/09/12 11:26:38
Acknowledged.
| |
118 rtc::Buffer payload(payload_size_bytes); | |
kwiberg-webrtc
2016/09/12 02:11:02
const
ossu
2016/09/12 11:26:38
Acknowledged.
| |
119 auto splits = | |
kwiberg-webrtc
2016/09/12 02:11:02
const
ossu
2016/09/12 11:26:38
Acknowledged.
| |
120 internal::SplitBySamples(payload, bytes_per_ms_, samples_per_ms_); | |
121 EXPECT_EQ(expected_split.num_splits, splits.size()); | |
122 uint32_t expected_timestamp = 0; | |
123 uint32_t expected_byte_offset = 0; | |
124 for (size_t i = 0; i != expected_split.num_splits; ++i) { | |
125 const auto& split = splits[i]; | |
126 const size_t length_bytes = | |
127 expected_split.split_sizes[i] * bytes_per_ms_; | |
128 EXPECT_EQ(length_bytes, split.num_bytes); | |
129 EXPECT_EQ(expected_timestamp, split.timestamp_offset); | |
130 EXPECT_EQ(expected_byte_offset, split.byte_offset); | |
131 expected_timestamp += expected_split.split_sizes[i] * samples_per_ms_; | |
132 expected_byte_offset += length_bytes; | |
133 } | |
134 } | |
135 } | |
136 | |
137 INSTANTIATE_TEST_CASE_P( | |
138 AudioCodingUtils, | |
139 SplitBySamplesTest, | |
140 ::testing::Values(NetEqDecoder::kDecoderPCMu, | |
141 NetEqDecoder::kDecoderPCMa, | |
142 NetEqDecoder::kDecoderPCMu_2ch, | |
143 NetEqDecoder::kDecoderPCMa_2ch, | |
144 NetEqDecoder::kDecoderG722, | |
145 NetEqDecoder::kDecoderPCM16B, | |
146 NetEqDecoder::kDecoderPCM16Bwb, | |
147 NetEqDecoder::kDecoderPCM16Bswb32kHz, | |
148 NetEqDecoder::kDecoderPCM16Bswb48kHz, | |
149 NetEqDecoder::kDecoderPCM16B_2ch, | |
150 NetEqDecoder::kDecoderPCM16Bwb_2ch, | |
151 NetEqDecoder::kDecoderPCM16Bswb32kHz_2ch, | |
152 NetEqDecoder::kDecoderPCM16Bswb48kHz_2ch, | |
153 NetEqDecoder::kDecoderPCM16B_5ch)); | |
154 | |
155 } // namespace webrtc | |
OLD | NEW |