From e1e0d673ac55cded129753340c977bd4ef672124 Mon Sep 17 00:00:00 2001 From: "henrik.lundin@webrtc.org" Date: Tue, 30 Sep 2014 11:08:44 +0000 Subject: Minor modifications to test::RtpFileReader Adding original_length to the Packet struct. This is populated with the plen value from the RTP dump file. In the case of reading a pcap file, original_length will be equal to length. Also increasing the maximum packet size to 3500 bytes. This is to accomodate some test files that contain PCM16b audio encoding. R=pbos@webrtc.org Review URL: https://webrtc-codereview.appspot.com/28609004 git-svn-id: http://webrtc.googlecode.com/svn/trunk/webrtc@7333 4adac7df-926f-26a2-2b94-8c16560cd09d --- test/rtp_file_reader.cc | 8 +++++++- test/rtp_file_reader.h | 7 ++++++- test/rtp_file_reader_unittest.cc | 22 ++++++++++++++++++---- test/webrtc_test_common.gyp | 1 + 4 files changed, 32 insertions(+), 6 deletions(-) diff --git a/test/rtp_file_reader.cc b/test/rtp_file_reader.cc index be8dc2bc..fd3116eb 100644 --- a/test/rtp_file_reader.cc +++ b/test/rtp_file_reader.cc @@ -16,6 +16,7 @@ #include #include +#include "webrtc/base/checks.h" #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h" #include "webrtc/system_wrappers/interface/scoped_ptr.h" @@ -113,13 +114,17 @@ class RtpDumpReader : public RtpFileReaderImpl { // Use 'len' here because a 'plen' of 0 specifies rtcp. len -= kPacketHeaderSize; if (packet->length < len) { - return false; + FATAL() << "Packet is too large to fit: " << len << " bytes vs " + << packet->length + << " bytes allocated. Consider increasing the buffer " + "size"; } if (fread(rtp_data, 1, len, file_) != len) { return false; } packet->length = len; + packet->original_length = plen; packet->time_ms = offset; return true; } @@ -290,6 +295,7 @@ class PcapReader : public RtpFileReaderImpl { if (NextPcap(packet->data, &length, &packet->time_ms) != kResultSuccess) return false; packet->length = static_cast(length); + packet->original_length = packet->length; return true; } diff --git a/test/rtp_file_reader.h b/test/rtp_file_reader.h index 379bf2d7..095ce767 100644 --- a/test/rtp_file_reader.h +++ b/test/rtp_file_reader.h @@ -24,9 +24,14 @@ class RtpFileReader { }; struct Packet { - static const size_t kMaxPacketBufferSize = 1500; + // Accommodate for 50 ms packets of 32 kHz PCM16 samples (3200 bytes) plus + // some overhead. + static const size_t kMaxPacketBufferSize = 3500; uint8_t data[kMaxPacketBufferSize]; size_t length; + // The length the packet had on wire. Will be different from |length| when + // reading a header-only RTP dump. + size_t original_length; uint32_t time_ms; }; diff --git a/test/rtp_file_reader_unittest.cc b/test/rtp_file_reader_unittest.cc index b5fa260c..54fb874b 100644 --- a/test/rtp_file_reader_unittest.cc +++ b/test/rtp_file_reader_unittest.cc @@ -20,28 +20,40 @@ namespace webrtc { class TestRtpFileReader : public ::testing::Test { public: - void Init(const std::string& filename) { + void Init(const std::string& filename, bool headers_only_file) { std::string filepath = test::ResourcePath("video_coding/" + filename, "rtp"); rtp_packet_source_.reset( test::RtpFileReader::Create(test::RtpFileReader::kRtpDump, filepath)); ASSERT_TRUE(rtp_packet_source_.get() != NULL); + headers_only_file_ = headers_only_file; } int CountRtpPackets() { test::RtpFileReader::Packet packet; int c = 0; - while (rtp_packet_source_->NextPacket(&packet)) + while (rtp_packet_source_->NextPacket(&packet)) { + if (headers_only_file_) + EXPECT_LT(packet.length, packet.original_length); + else + EXPECT_EQ(packet.length, packet.original_length); c++; + } return c; } private: scoped_ptr rtp_packet_source_; + bool headers_only_file_; }; TEST_F(TestRtpFileReader, Test60Packets) { - Init("pltype103"); + Init("pltype103", false); + EXPECT_EQ(60, CountRtpPackets()); +} + +TEST_F(TestRtpFileReader, Test60PacketsHeaderOnly) { + Init("pltype103_header_only", true); EXPECT_EQ(60, CountRtpPackets()); } @@ -60,8 +72,10 @@ class TestPcapFileReader : public ::testing::Test { int CountRtpPackets() { int c = 0; test::RtpFileReader::Packet packet; - while (rtp_packet_source_->NextPacket(&packet)) + while (rtp_packet_source_->NextPacket(&packet)) { + EXPECT_EQ(packet.length, packet.original_length); c++; + } return c; } diff --git a/test/webrtc_test_common.gyp b/test/webrtc_test_common.gyp index d422a4b0..477ec0fc 100644 --- a/test/webrtc_test_common.gyp +++ b/test/webrtc_test_common.gyp @@ -58,6 +58,7 @@ 'dependencies': [ '<(DEPTH)/testing/gtest.gyp:gtest', '<(DEPTH)/third_party/gflags/gflags.gyp:gflags', + '<(webrtc_root)/base/base.gyp:rtc_base', '<(webrtc_root)/modules/modules.gyp:media_file', '<(webrtc_root)/modules/modules.gyp:video_capture_module_impl', '<(webrtc_root)/modules/modules.gyp:video_render_module_impl', -- cgit v1.2.3