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@7333 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
parent
1795c358fc
commit
38c121c484
1
resources/video_coding/pltype103_header_only.rtp.sha1
Normal file
1
resources/video_coding/pltype103_header_only.rtp.sha1
Normal file
@ -0,0 +1 @@
|
|||||||
|
2a77f0d030aa96f51f0a96e971b42c3b11fe006b
|
@ -16,6 +16,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "webrtc/base/checks.h"
|
||||||
#include "webrtc/modules/rtp_rtcp/source/rtp_utility.h"
|
#include "webrtc/modules/rtp_rtcp/source/rtp_utility.h"
|
||||||
#include "webrtc/system_wrappers/interface/scoped_ptr.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.
|
// Use 'len' here because a 'plen' of 0 specifies rtcp.
|
||||||
len -= kPacketHeaderSize;
|
len -= kPacketHeaderSize;
|
||||||
if (packet->length < len) {
|
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) {
|
if (fread(rtp_data, 1, len, file_) != len) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
packet->length = len;
|
packet->length = len;
|
||||||
|
packet->original_length = plen;
|
||||||
packet->time_ms = offset;
|
packet->time_ms = offset;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -290,6 +295,7 @@ class PcapReader : public RtpFileReaderImpl {
|
|||||||
if (NextPcap(packet->data, &length, &packet->time_ms) != kResultSuccess)
|
if (NextPcap(packet->data, &length, &packet->time_ms) != kResultSuccess)
|
||||||
return false;
|
return false;
|
||||||
packet->length = static_cast<size_t>(length);
|
packet->length = static_cast<size_t>(length);
|
||||||
|
packet->original_length = packet->length;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,9 +24,14 @@ class RtpFileReader {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct Packet {
|
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];
|
uint8_t data[kMaxPacketBufferSize];
|
||||||
size_t length;
|
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;
|
uint32_t time_ms;
|
||||||
};
|
};
|
||||||
|
@ -20,28 +20,40 @@ namespace webrtc {
|
|||||||
|
|
||||||
class TestRtpFileReader : public ::testing::Test {
|
class TestRtpFileReader : public ::testing::Test {
|
||||||
public:
|
public:
|
||||||
void Init(const std::string& filename) {
|
void Init(const std::string& filename, bool headers_only_file) {
|
||||||
std::string filepath =
|
std::string filepath =
|
||||||
test::ResourcePath("video_coding/" + filename, "rtp");
|
test::ResourcePath("video_coding/" + filename, "rtp");
|
||||||
rtp_packet_source_.reset(
|
rtp_packet_source_.reset(
|
||||||
test::RtpFileReader::Create(test::RtpFileReader::kRtpDump, filepath));
|
test::RtpFileReader::Create(test::RtpFileReader::kRtpDump, filepath));
|
||||||
ASSERT_TRUE(rtp_packet_source_.get() != NULL);
|
ASSERT_TRUE(rtp_packet_source_.get() != NULL);
|
||||||
|
headers_only_file_ = headers_only_file;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CountRtpPackets() {
|
int CountRtpPackets() {
|
||||||
test::RtpFileReader::Packet packet;
|
test::RtpFileReader::Packet packet;
|
||||||
int c = 0;
|
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++;
|
c++;
|
||||||
|
}
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
scoped_ptr<test::RtpFileReader> rtp_packet_source_;
|
scoped_ptr<test::RtpFileReader> rtp_packet_source_;
|
||||||
|
bool headers_only_file_;
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_F(TestRtpFileReader, Test60Packets) {
|
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());
|
EXPECT_EQ(60, CountRtpPackets());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,8 +72,10 @@ class TestPcapFileReader : public ::testing::Test {
|
|||||||
int CountRtpPackets() {
|
int CountRtpPackets() {
|
||||||
int c = 0;
|
int c = 0;
|
||||||
test::RtpFileReader::Packet packet;
|
test::RtpFileReader::Packet packet;
|
||||||
while (rtp_packet_source_->NextPacket(&packet))
|
while (rtp_packet_source_->NextPacket(&packet)) {
|
||||||
|
EXPECT_EQ(packet.length, packet.original_length);
|
||||||
c++;
|
c++;
|
||||||
|
}
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,6 +58,7 @@
|
|||||||
'dependencies': [
|
'dependencies': [
|
||||||
'<(DEPTH)/testing/gtest.gyp:gtest',
|
'<(DEPTH)/testing/gtest.gyp:gtest',
|
||||||
'<(DEPTH)/third_party/gflags/gflags.gyp:gflags',
|
'<(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:media_file',
|
||||||
'<(webrtc_root)/modules/modules.gyp:video_capture_module_impl',
|
'<(webrtc_root)/modules/modules.gyp:video_capture_module_impl',
|
||||||
'<(webrtc_root)/modules/modules.gyp:video_render_module_impl',
|
'<(webrtc_root)/modules/modules.gyp:video_render_module_impl',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user