OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
47 decoded_samples.data(), &speech_type)); | 47 decoded_samples.data(), &speech_type)); |
48 | 48 |
49 // Decode the good packet. This should work, because the failed decoding | 49 // Decode the good packet. This should work, because the failed decoding |
50 // should not have left the decoder in a broken state. | 50 // should not have left the decoder in a broken state. |
51 EXPECT_EQ(static_cast<int>(decoded_samples.size()), | 51 EXPECT_EQ(static_cast<int>(decoded_samples.size()), |
52 decoder.Decode(packet.data(), packet.size(), encoder.SampleRateHz(), | 52 decoder.Decode(packet.data(), packet.size(), encoder.SampleRateHz(), |
53 sizeof(int16_t) * decoded_samples.size(), | 53 sizeof(int16_t) * decoded_samples.size(), |
54 decoded_samples.data(), &speech_type)); | 54 decoded_samples.data(), &speech_type)); |
55 } | 55 } |
56 | 56 |
57 class SplitIlbcTest : public ::testing::TestWithParam<std::pair<int, int> > { | |
58 protected: | |
59 virtual void SetUp() { | |
60 const std::pair<int, int> parameters = GetParam(); | |
61 num_frames_ = parameters.first; | |
62 frame_length_ms_ = parameters.second; | |
63 frame_length_bytes_ = (frame_length_ms_ == 20) ? 38 : 50; | |
64 } | |
65 size_t num_frames_; | |
66 int frame_length_ms_; | |
67 size_t frame_length_bytes_; | |
68 }; | |
69 | |
70 // Test splitting sample-based payloads. | |
hlundin-webrtc
2016/09/09 12:52:52
iLBC does not split sample-based.
ossu
2016/09/12 11:26:37
Nope! The comment is an old one but it's still wro
| |
71 TEST_P(SplitIlbcTest, NumFrames) { | |
72 AudioDecoderIlbc decoder; | |
73 const size_t frame_length_samples = frame_length_ms_ * 8; | |
74 size_t payload_length_bytes = frame_length_bytes_ * num_frames_; | |
kwiberg-webrtc
2016/09/12 02:11:01
const?
ossu
2016/09/12 11:26:37
Acknowledged.
| |
75 rtc::Buffer payload(payload_length_bytes); | |
76 // Fill payload with increasing integers {0, 1, 2, ...}. | |
77 for (size_t i = 0; i < payload.size(); ++i) { | |
78 payload[i] = static_cast<uint8_t>(i); | |
79 } | |
80 | |
81 auto splits = decoder.SplitPacket(payload); | |
82 EXPECT_EQ(num_frames_, splits.size()); | |
83 | |
84 size_t frame_num = 0; | |
85 uint8_t payload_value = 0; | |
86 for (const auto& split : splits) { | |
87 EXPECT_EQ(frame_length_samples * frame_num, split.timestamp_offset); | |
88 EXPECT_EQ(frame_length_bytes_, split.num_bytes); | |
89 for (size_t i = 0; i < split.num_bytes; ++i, ++payload_value) { | |
90 EXPECT_EQ(payload_value, payload[split.byte_offset + i]); | |
91 } | |
92 ++frame_num; | |
93 } | |
94 } | |
95 | |
96 // Test 1 through 5 frames of 20 and 30 ms size. | |
97 // Also test the maximum number of frames in one packet for 20 and 30 ms. | |
98 // The maximum is defined by the largest payload length that can be uniquely | |
99 // resolved to a frame size of either 38 bytes (20 ms) or 50 bytes (30 ms). | |
100 INSTANTIATE_TEST_CASE_P( | |
101 PayloadSplitter, SplitIlbcTest, | |
102 ::testing::Values(std::pair<int, int>(1, 20), // 1 frame, 20 ms. | |
103 std::pair<int, int>(2, 20), // 2 frames, 20 ms. | |
104 std::pair<int, int>(3, 20), // And so on. | |
105 std::pair<int, int>(4, 20), | |
106 std::pair<int, int>(5, 20), | |
107 std::pair<int, int>(24, 20), | |
108 std::pair<int, int>(1, 30), | |
109 std::pair<int, int>(2, 30), | |
110 std::pair<int, int>(3, 30), | |
111 std::pair<int, int>(4, 30), | |
112 std::pair<int, int>(5, 30), | |
113 std::pair<int, int>(18, 30))); | |
114 | |
115 // Test too large payload size. | |
116 TEST(IlbcPayloadSplitter, TooLargePayload) { | |
117 AudioDecoderIlbc decoder; | |
118 size_t kPayloadLengthBytes = 950; | |
kwiberg-webrtc
2016/09/12 02:11:01
constexpr
ossu
2016/09/12 11:26:37
Acknowledged.
| |
119 rtc::Buffer payload(kPayloadLengthBytes); | |
kwiberg-webrtc
2016/09/12 02:11:01
const
ossu
2016/09/12 11:26:37
Acknowledged.
| |
120 auto splits = decoder.SplitPacket(payload); | |
kwiberg-webrtc
2016/09/12 02:11:01
const
ossu
2016/09/12 11:26:37
Acknowledged.
| |
121 EXPECT_TRUE(splits.empty()); | |
122 } | |
123 | |
124 // Payload not an integer number of frames. | |
125 TEST(IlbcPayloadSplitter, UnevenPayload) { | |
126 AudioDecoderIlbc decoder; | |
127 size_t kPayloadLengthBytes = 39; // Not an even number of frames. | |
128 rtc::Buffer payload(kPayloadLengthBytes); | |
129 auto splits = decoder.SplitPacket(payload); | |
kwiberg-webrtc
2016/09/12 02:11:01
constexpr, const, const
ossu
2016/09/12 11:26:37
Acknowledged.
| |
130 EXPECT_TRUE(splits.empty()); | |
131 } | |
132 | |
57 } // namespace webrtc | 133 } // namespace webrtc |
OLD | NEW |