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

Unified Diff: webrtc/modules/audio_coding/codecs/ilbc/ilbc_unittest.cc

Issue 2326003002: Moved codec-specific audio packet splitting into decoders. (Closed)
Patch Set: Created 4 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: webrtc/modules/audio_coding/codecs/ilbc/ilbc_unittest.cc
diff --git a/webrtc/modules/audio_coding/codecs/ilbc/ilbc_unittest.cc b/webrtc/modules/audio_coding/codecs/ilbc/ilbc_unittest.cc
index c23cbc44e808a60185b30a6ad93d18778fdbe160..4a27f4cb98658d77dc55ba578b31473efdae37ea 100644
--- a/webrtc/modules/audio_coding/codecs/ilbc/ilbc_unittest.cc
+++ b/webrtc/modules/audio_coding/codecs/ilbc/ilbc_unittest.cc
@@ -54,4 +54,80 @@ TEST(IlbcTest, BadPacket) {
decoded_samples.data(), &speech_type));
}
+class SplitIlbcTest : public ::testing::TestWithParam<std::pair<int, int> > {
+ protected:
+ virtual void SetUp() {
+ const std::pair<int, int> parameters = GetParam();
+ num_frames_ = parameters.first;
+ frame_length_ms_ = parameters.second;
+ frame_length_bytes_ = (frame_length_ms_ == 20) ? 38 : 50;
+ }
+ size_t num_frames_;
+ int frame_length_ms_;
+ size_t frame_length_bytes_;
+};
+
+// 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
+TEST_P(SplitIlbcTest, NumFrames) {
+ AudioDecoderIlbc decoder;
+ const size_t frame_length_samples = frame_length_ms_ * 8;
+ 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.
+ rtc::Buffer payload(payload_length_bytes);
+ // Fill payload with increasing integers {0, 1, 2, ...}.
+ for (size_t i = 0; i < payload.size(); ++i) {
+ payload[i] = static_cast<uint8_t>(i);
+ }
+
+ auto splits = decoder.SplitPacket(payload);
+ EXPECT_EQ(num_frames_, splits.size());
+
+ size_t frame_num = 0;
+ uint8_t payload_value = 0;
+ for (const auto& split : splits) {
+ EXPECT_EQ(frame_length_samples * frame_num, split.timestamp_offset);
+ EXPECT_EQ(frame_length_bytes_, split.num_bytes);
+ for (size_t i = 0; i < split.num_bytes; ++i, ++payload_value) {
+ EXPECT_EQ(payload_value, payload[split.byte_offset + i]);
+ }
+ ++frame_num;
+ }
+}
+
+// Test 1 through 5 frames of 20 and 30 ms size.
+// Also test the maximum number of frames in one packet for 20 and 30 ms.
+// The maximum is defined by the largest payload length that can be uniquely
+// resolved to a frame size of either 38 bytes (20 ms) or 50 bytes (30 ms).
+INSTANTIATE_TEST_CASE_P(
+ PayloadSplitter, SplitIlbcTest,
+ ::testing::Values(std::pair<int, int>(1, 20), // 1 frame, 20 ms.
+ std::pair<int, int>(2, 20), // 2 frames, 20 ms.
+ std::pair<int, int>(3, 20), // And so on.
+ std::pair<int, int>(4, 20),
+ std::pair<int, int>(5, 20),
+ std::pair<int, int>(24, 20),
+ std::pair<int, int>(1, 30),
+ std::pair<int, int>(2, 30),
+ std::pair<int, int>(3, 30),
+ std::pair<int, int>(4, 30),
+ std::pair<int, int>(5, 30),
+ std::pair<int, int>(18, 30)));
+
+// Test too large payload size.
+TEST(IlbcPayloadSplitter, TooLargePayload) {
+ AudioDecoderIlbc decoder;
+ size_t kPayloadLengthBytes = 950;
kwiberg-webrtc 2016/09/12 02:11:01 constexpr
ossu 2016/09/12 11:26:37 Acknowledged.
+ rtc::Buffer payload(kPayloadLengthBytes);
kwiberg-webrtc 2016/09/12 02:11:01 const
ossu 2016/09/12 11:26:37 Acknowledged.
+ auto splits = decoder.SplitPacket(payload);
kwiberg-webrtc 2016/09/12 02:11:01 const
ossu 2016/09/12 11:26:37 Acknowledged.
+ EXPECT_TRUE(splits.empty());
+}
+
+// Payload not an integer number of frames.
+TEST(IlbcPayloadSplitter, UnevenPayload) {
+ AudioDecoderIlbc decoder;
+ size_t kPayloadLengthBytes = 39; // Not an even number of frames.
+ rtc::Buffer payload(kPayloadLengthBytes);
+ auto splits = decoder.SplitPacket(payload);
kwiberg-webrtc 2016/09/12 02:11:01 constexpr, const, const
ossu 2016/09/12 11:26:37 Acknowledged.
+ EXPECT_TRUE(splits.empty());
+}
+
} // namespace webrtc

Powered by Google App Engine
This is Rietveld 408576698