From 4407edc314411f701cb888c1aed17d4f5639bf97 Mon Sep 17 00:00:00 2001 From: "henrik.lundin@webrtc.org" Date: Wed, 18 Jan 2012 10:01:03 +0000 Subject: [PATCH] Bugfix in VP8 packetizer Handle the case with no small partitions in Vp8PartitionAggregator. Also added a new unit test for the packetizer to verify that the bug is fixed. TEST=RtpFormatVp8Test.TestAggregateModeTwoLargePartitions TBR=stefan@webrtc.org Review URL: https://webrtc-codereview.appspot.com/348011 git-svn-id: http://webrtc.googlecode.com/svn/trunk@1451 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../source/rtp_format_vp8_unittest.cc | 30 +++++++++++++++++++ .../source/vp8_partition_aggregator.cc | 6 ++++ 2 files changed, 36 insertions(+) diff --git a/src/modules/rtp_rtcp/source/rtp_format_vp8_unittest.cc b/src/modules/rtp_rtcp/source/rtp_format_vp8_unittest.cc index 9497bfa5f9..09f12acd66 100644 --- a/src/modules/rtp_rtcp/source/rtp_format_vp8_unittest.cc +++ b/src/modules/rtp_rtcp/source/rtp_format_vp8_unittest.cc @@ -170,6 +170,36 @@ TEST_F(RtpFormatVp8Test, TestAggregateModeManyPartitions2) { kExpectedFragStart, kExpectedNum); } +TEST_F(RtpFormatVp8Test, TestAggregateModeTwoLargePartitions) { + const int kSizeVector[] = {1654, 2268}; + const int kNumPartitions = sizeof(kSizeVector) / sizeof(kSizeVector[0]); + ASSERT_TRUE(Init(kSizeVector, kNumPartitions)); + + hdr_info_.pictureId = 20; // <= 0x7F should produce 1-byte PictureID. + const int kMaxSize = 1460; + RtpFormatVp8 packetizer(helper_->payload_data(), + helper_->payload_size(), + hdr_info_, + kMaxSize, + *(helper_->fragmentation()), + kAggregate); + + // The expected sizes are obtained by running a verified good implementation. + const int kExpectedSizes[] = {830, 830, 1137, 1137}; + const int kExpectedPart[] = {0, 0, 1, 1}; + const bool kExpectedFragStart[] = {true, false, true, false}; + const int kExpectedNum = sizeof(kExpectedSizes) / sizeof(kExpectedSizes[0]); + COMPILE_ASSERT(kExpectedNum == + sizeof(kExpectedPart) / sizeof(kExpectedPart[0]), + kExpectedPart_wrong_size); + COMPILE_ASSERT(kExpectedNum == + sizeof(kExpectedFragStart) / sizeof(kExpectedFragStart[0]), + kExpectedFragStart_wrong_size); + + helper_->GetAllPacketsAndCheck(&packetizer, kExpectedSizes, kExpectedPart, + kExpectedFragStart, kExpectedNum); +} + TEST_F(RtpFormatVp8Test, TestSloppyMode) { const int kSizeVector[] = {10, 10, 10}; const int kNumPartitions = sizeof(kSizeVector) / sizeof(kSizeVector[0]); diff --git a/src/modules/rtp_rtcp/source/vp8_partition_aggregator.cc b/src/modules/rtp_rtcp/source/vp8_partition_aggregator.cc index 9fcadad5db..22d24d8d44 100644 --- a/src/modules/rtp_rtcp/source/vp8_partition_aggregator.cc +++ b/src/modules/rtp_rtcp/source/vp8_partition_aggregator.cc @@ -229,9 +229,15 @@ int Vp8PartitionAggregator::CalcNumberOfFragments(int large_partition_size, int max_size) { assert(max_size <= max_payload_size); assert(min_size <= max_size); + assert(max_payload_size > 0); // Divisions with rounding up. const int min_number_of_fragments = (large_partition_size + max_payload_size - 1) / max_payload_size; + if (min_size < 0 || max_size < 0) { + // No aggregates produced, so we do not have any size boundaries. + // Simply split in as few partitions as possible. + return min_number_of_fragments; + } const int max_number_of_fragments = (large_partition_size + min_size - 1) / min_size; int num_fragments = -1;