Index: media/formats/mp2t/es_parser_h264_unittest.cc |
diff --git a/media/formats/mp2t/es_parser_h264_unittest.cc b/media/formats/mp2t/es_parser_h264_unittest.cc |
index 2c13df0d853fb72b12efe2640000ebd63ca95e97..284f6f2f1fc9dd137999735f3b3405666405710c 100644 |
--- a/media/formats/mp2t/es_parser_h264_unittest.cc |
+++ b/media/formats/mp2t/es_parser_h264_unittest.cc |
@@ -15,6 +15,7 @@ |
#include "media/base/test_data_util.h" |
#include "media/filters/h264_parser.h" |
#include "media/formats/mp2t/es_parser_h264.h" |
+#include "media/formats/mp2t/es_parser_test_helper.h" |
#include "testing/gtest/include/gtest/gtest.h" |
namespace media { |
@@ -24,28 +25,6 @@ namespace mp2t { |
namespace { |
-struct Packet { |
- // Offset in the stream. |
- size_t offset; |
- |
- // Size of the packet. |
- size_t size; |
- |
- // Timestamp of the packet. |
- base::TimeDelta pts; |
-}; |
- |
-// Compute the size of each packet assuming packets are given in stream order |
-// and the last packet covers the end of the stream. |
-void ComputePacketSize(std::vector<Packet>& packets, size_t stream_size) { |
- for (size_t k = 0; k < packets.size() - 1; k++) { |
- DCHECK_GE(packets[k + 1].offset, packets[k].offset); |
- packets[k].size = packets[k + 1].offset - packets[k].offset; |
- } |
- packets[packets.size() - 1].size = |
- stream_size - packets[packets.size() - 1].offset; |
-} |
- |
// Get the offset of the start of each access unit. |
// This function assumes there is only one slice per access unit. |
// This is a very simplified access unit segmenter that is good |
@@ -87,7 +66,7 @@ std::vector<Packet> GetAccessUnits(const uint8* stream, size_t stream_size) { |
} |
} |
- ComputePacketSize(access_units, stream_size); |
+ ComputePacketSize(&access_units, stream_size); |
return access_units; |
} |
@@ -127,8 +106,7 @@ class EsParserH264Test : public testing::Test { |
protected: |
void LoadStream(const char* filename); |
void GetPesTimestamps(std::vector<Packet>& pes_packets); |
- void ProcessPesPackets(const std::vector<Packet>& pes_packets, |
- bool force_timing); |
+ bool Process(const std::vector<Packet>& pes_packets, bool force_timing); |
// Stream with AUD NALUs. |
std::vector<uint8> stream_; |
@@ -194,26 +172,14 @@ void EsParserH264Test::GetPesTimestamps(std::vector<Packet>& pes_packets) { |
} |
} |
-void EsParserH264Test::ProcessPesPackets( |
+bool EsParserH264Test::Process( |
const std::vector<Packet>& pes_packets, |
bool force_timing) { |
EsParserH264 es_parser( |
base::Bind(&EsParserH264Test::NewVideoConfig, base::Unretained(this)), |
base::Bind(&EsParserH264Test::EmitBuffer, base::Unretained(this))); |
- for (size_t k = 0; k < pes_packets.size(); k++) { |
- size_t cur_pes_offset = pes_packets[k].offset; |
- size_t cur_pes_size = pes_packets[k].size; |
- |
- base::TimeDelta pts = kNoTimestamp(); |
- base::TimeDelta dts = kNoTimestamp(); |
- if (pes_packets[k].pts >= base::TimeDelta() || force_timing) |
- pts = pes_packets[k].pts; |
- |
- ASSERT_TRUE( |
- es_parser.Parse(&stream_[cur_pes_offset], cur_pes_size, pts, dts)); |
- } |
- es_parser.Flush(); |
+ return ProcessPesPackets(&es_parser, stream_, pes_packets, force_timing); |
} |
void EsParserH264Test::EmitBuffer(scoped_refptr<StreamParserBuffer> buffer) { |
@@ -230,7 +196,7 @@ TEST_F(EsParserH264Test, OneAccessUnitPerPes) { |
GetPesTimestamps(pes_packets); |
// Process each PES packet. |
- ProcessPesPackets(pes_packets, false); |
+ EXPECT_TRUE(Process(pes_packets, false)); |
EXPECT_EQ(buffer_count_, access_units_.size()); |
} |
@@ -251,11 +217,11 @@ TEST_F(EsParserH264Test, NonAlignedPesPacket) { |
cur_pes_packet.offset = access_units_[k].offset + |
std::min<size_t>(487u, access_units_[k].size); |
} |
- ComputePacketSize(pes_packets, stream_.size()); |
+ ComputePacketSize(&pes_packets, stream_.size()); |
GetPesTimestamps(pes_packets); |
// Process each PES packet. |
- ProcessPesPackets(pes_packets, false); |
+ EXPECT_TRUE(Process(pes_packets, false)); |
EXPECT_EQ(buffer_count_, access_units_.size()); |
} |
@@ -282,16 +248,16 @@ TEST_F(EsParserH264Test, SeveralPesPerAccessUnit) { |
pes_packets.push_back(cur_pes_packet); |
cur_pes_packet.offset += pes_size; |
} |
- ComputePacketSize(pes_packets, stream_.size()); |
+ ComputePacketSize(&pes_packets, stream_.size()); |
GetPesTimestamps(pes_packets); |
// Process each PES packet. |
- ProcessPesPackets(pes_packets, false); |
+ EXPECT_TRUE(Process(pes_packets, false)); |
EXPECT_EQ(buffer_count_, access_units_.size()); |
// Process PES packets forcing timings for each PES packet. |
buffer_count_ = 0; |
- ProcessPesPackets(pes_packets, true); |
+ EXPECT_TRUE(Process(pes_packets, true)); |
EXPECT_EQ(buffer_count_, access_units_.size()); |
} |