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 |
11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
12 #include "webrtc/modules/audio_coding/codecs/ilbc/audio_decoder_ilbc.h" | 12 #include "webrtc/modules/audio_coding/codecs/ilbc/audio_decoder_ilbc.h" |
13 #include "webrtc/modules/audio_coding/codecs/ilbc/audio_encoder_ilbc.h" | 13 #include "webrtc/modules/audio_coding/codecs/ilbc/audio_encoder_ilbc.h" |
14 #include "webrtc/modules/audio_coding/codecs/legacy_encoded_audio_frame.h" | |
14 | 15 |
15 namespace webrtc { | 16 namespace webrtc { |
16 | 17 |
17 TEST(IlbcTest, BadPacket) { | 18 TEST(IlbcTest, BadPacket) { |
18 // Get a good packet. | 19 // Get a good packet. |
19 AudioEncoderIlbc::Config config; | 20 AudioEncoderIlbc::Config config; |
20 config.frame_size_ms = 20; // We need 20 ms rather than the default 30 ms; | 21 config.frame_size_ms = 20; // We need 20 ms rather than the default 30 ms; |
21 // otherwise, all possible values of cb_index[2] | 22 // otherwise, all possible values of cb_index[2] |
22 // are valid. | 23 // are valid. |
23 AudioEncoderIlbc encoder(config); | 24 AudioEncoderIlbc encoder(config); |
(...skipping 23 matching lines...) Expand all Loading... | |
47 decoded_samples.data(), &speech_type)); | 48 decoded_samples.data(), &speech_type)); |
48 | 49 |
49 // Decode the good packet. This should work, because the failed decoding | 50 // Decode the good packet. This should work, because the failed decoding |
50 // should not have left the decoder in a broken state. | 51 // should not have left the decoder in a broken state. |
51 EXPECT_EQ(static_cast<int>(decoded_samples.size()), | 52 EXPECT_EQ(static_cast<int>(decoded_samples.size()), |
52 decoder.Decode(packet.data(), packet.size(), encoder.SampleRateHz(), | 53 decoder.Decode(packet.data(), packet.size(), encoder.SampleRateHz(), |
53 sizeof(int16_t) * decoded_samples.size(), | 54 sizeof(int16_t) * decoded_samples.size(), |
54 decoded_samples.data(), &speech_type)); | 55 decoded_samples.data(), &speech_type)); |
55 } | 56 } |
56 | 57 |
58 class SplitIlbcTest : public ::testing::TestWithParam<std::pair<int, int> > { | |
59 protected: | |
60 virtual void SetUp() { | |
61 const std::pair<int, int> parameters = GetParam(); | |
62 num_frames_ = parameters.first; | |
63 frame_length_ms_ = parameters.second; | |
64 frame_length_bytes_ = (frame_length_ms_ == 20) ? 38 : 50; | |
65 } | |
66 size_t num_frames_; | |
67 int frame_length_ms_; | |
68 size_t frame_length_bytes_; | |
69 }; | |
70 | |
71 TEST_P(SplitIlbcTest, NumFrames) { | |
72 AudioDecoderIlbc decoder; | |
73 const size_t frame_length_samples = frame_length_ms_ * 8; | |
74 const size_t payload_length_bytes = frame_length_bytes_ * num_frames_; | |
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 results = decoder.ParsePayload(&payload, 0, true); | |
kwiberg-webrtc
2016/09/15 13:01:25
const
| |
82 EXPECT_EQ(num_frames_, results.size()); | |
83 | |
84 size_t frame_num = 0; | |
85 uint8_t payload_value = 0; | |
86 for (const auto& result : results) { | |
87 EXPECT_EQ(frame_length_samples * frame_num, result.timestamp); | |
88 const LegacyEncodedAudioFrame* frame = | |
89 static_cast<const LegacyEncodedAudioFrame*>(result.frame.get()); | |
90 const rtc::Buffer& payload = frame->payload(); | |
91 EXPECT_EQ(frame_length_bytes_, payload.size()); | |
92 for (size_t i = 0; i < payload.size(); ++i, ++payload_value) { | |
93 EXPECT_EQ(payload_value, payload[i]); | |
94 } | |
95 ++frame_num; | |
96 } | |
97 } | |
98 | |
99 // Test 1 through 5 frames of 20 and 30 ms size. | |
100 // Also test the maximum number of frames in one packet for 20 and 30 ms. | |
101 // The maximum is defined by the largest payload length that can be uniquely | |
102 // resolved to a frame size of either 38 bytes (20 ms) or 50 bytes (30 ms). | |
103 INSTANTIATE_TEST_CASE_P( | |
104 PayloadSplitter, SplitIlbcTest, | |
105 ::testing::Values(std::pair<int, int>(1, 20), // 1 frame, 20 ms. | |
106 std::pair<int, int>(2, 20), // 2 frames, 20 ms. | |
107 std::pair<int, int>(3, 20), // And so on. | |
108 std::pair<int, int>(4, 20), | |
109 std::pair<int, int>(5, 20), | |
110 std::pair<int, int>(24, 20), | |
111 std::pair<int, int>(1, 30), | |
112 std::pair<int, int>(2, 30), | |
113 std::pair<int, int>(3, 30), | |
114 std::pair<int, int>(4, 30), | |
115 std::pair<int, int>(5, 30), | |
116 std::pair<int, int>(18, 30))); | |
117 | |
118 // Test too large payload size. | |
119 TEST(IlbcPayloadSplitter, TooLargePayload) { | |
120 AudioDecoderIlbc decoder; | |
121 constexpr size_t kPayloadLengthBytes = 950; | |
122 rtc::Buffer payload(kPayloadLengthBytes); | |
123 const auto results = decoder.ParsePayload(&payload, 0, true); | |
124 EXPECT_TRUE(results.empty()); | |
125 } | |
126 | |
127 // Payload not an integer number of frames. | |
128 TEST(IlbcPayloadSplitter, UnevenPayload) { | |
129 AudioDecoderIlbc decoder; | |
130 constexpr size_t kPayloadLengthBytes = 39; // Not an even number of frames. | |
131 rtc::Buffer payload(kPayloadLengthBytes); | |
ossu
2016/09/13 14:25:55
Since it's now moved from by ParsePayload, it can'
hlundin-webrtc
2016/09/15 08:49:14
Acknowledged.
| |
132 const auto results = decoder.ParsePayload(&payload, 0, true); | |
133 EXPECT_TRUE(results.empty()); | |
134 } | |
135 | |
57 } // namespace webrtc | 136 } // namespace webrtc |
OLD | NEW |