Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include <algorithm> | |
| 6 #include <vector> | |
| 7 | |
| 8 #include "base/bind.h" | |
| 9 #include "base/command_line.h" | |
| 10 #include "base/files/memory_mapped_file.h" | |
| 11 #include "base/logging.h" | |
| 12 #include "base/path_service.h" | |
| 13 #include "base/time/time.h" | |
| 14 #include "media/base/buffers.h" | |
| 15 #include "media/base/stream_parser_buffer.h" | |
| 16 #include "media/base/test_data_util.h" | |
| 17 #include "media/formats/mp2t/es_parser_adts.h" | |
| 18 #include "testing/gtest/include/gtest/gtest.h" | |
| 19 | |
| 20 namespace media { | |
| 21 class AudioDecoderConfig; | |
| 22 | |
| 23 namespace mp2t { | |
| 24 | |
| 25 namespace { | |
| 26 | |
| 27 struct Packet { | |
|
wolenetz
2014/07/15 21:59:57
Some of this (struct Packet, void ComputePacketSiz
damienv1
2014/07/15 22:22:40
Will start an es_parser_test_helper.*
| |
| 28 // Offset in the stream. | |
| 29 size_t offset; | |
| 30 | |
| 31 // Size of the packet. | |
| 32 size_t size; | |
| 33 | |
| 34 // Timestamp of the packet. | |
| 35 base::TimeDelta pts; | |
| 36 }; | |
| 37 | |
| 38 // Compute the size of each packet assuming packets are given in stream order | |
| 39 // and the last packet covers the end of the stream. | |
| 40 void ComputePacketSize(std::vector<Packet>& packets, size_t stream_size) { | |
|
wolenetz
2014/07/15 21:59:57
lint nit: Is this a non-const reference? If so, ma
damienv1
2014/07/15 22:22:40
I made it a reference since otherwise packets[k] d
wolenetz
2014/07/15 22:39:21
non-const ref violates http://google-styleguide.go
| |
| 41 for (size_t k = 0; k < packets.size() - 1; k++) { | |
| 42 DCHECK_GE(packets[k + 1].offset, packets[k].offset); | |
| 43 packets[k].size = packets[k + 1].offset - packets[k].offset; | |
| 44 } | |
| 45 packets[packets.size() - 1].size = | |
| 46 stream_size - packets[packets.size() - 1].offset; | |
| 47 } | |
| 48 | |
| 49 // Generate fixed size PES packets for t | |
| 50 std::vector<Packet> GenerateFixedSizePesPacket( | |
| 51 const std::vector<uint8>& stream, size_t pes_size) { | |
| 52 std::vector<Packet> pes_packets; | |
| 53 | |
| 54 Packet cur_pes_packet; | |
| 55 cur_pes_packet.offset = 0; | |
| 56 cur_pes_packet.pts = kNoTimestamp(); | |
| 57 while (cur_pes_packet.offset < stream.size()) { | |
| 58 pes_packets.push_back(cur_pes_packet); | |
| 59 cur_pes_packet.offset += pes_size; | |
| 60 } | |
| 61 ComputePacketSize(pes_packets, stream.size()); | |
| 62 | |
| 63 return pes_packets; | |
| 64 } | |
| 65 | |
| 66 } // namespace | |
| 67 | |
| 68 class EsParserAdtsTest : public testing::Test { | |
| 69 public: | |
| 70 EsParserAdtsTest(); | |
| 71 virtual ~EsParserAdtsTest() {} | |
| 72 | |
| 73 protected: | |
| 74 void LoadStream(const char* filename); | |
| 75 bool ProcessPesPackets(const std::vector<Packet>& pes_packets, | |
| 76 bool force_timing); | |
| 77 | |
| 78 // ADTS stream. | |
| 79 std::vector<uint8> stream_; | |
| 80 | |
| 81 // Number of different audio configs in the ADTS stream. | |
| 82 size_t config_count_; | |
| 83 | |
| 84 // Number of buffers generated while parsing the ADTS stream. | |
| 85 size_t buffer_count_; | |
| 86 | |
| 87 private: | |
| 88 void NewAudioConfig(const AudioDecoderConfig& config); | |
| 89 void EmitBuffer(scoped_refptr<StreamParserBuffer> buffer); | |
| 90 | |
| 91 DISALLOW_COPY_AND_ASSIGN(EsParserAdtsTest); | |
| 92 }; | |
| 93 | |
| 94 EsParserAdtsTest::EsParserAdtsTest() | |
| 95 : config_count_(0), | |
| 96 buffer_count_(0) { | |
| 97 } | |
| 98 | |
| 99 void EsParserAdtsTest::LoadStream(const char* filename) { | |
| 100 base::FilePath file_path = GetTestDataFilePath(filename); | |
| 101 | |
| 102 base::MemoryMappedFile stream; | |
| 103 ASSERT_TRUE(stream.Initialize(file_path)) | |
| 104 << "Couldn't open stream file: " << file_path.MaybeAsASCII(); | |
| 105 | |
| 106 stream_.resize(stream.length()); | |
| 107 memcpy(stream_.data(), stream.data(), stream_.size()); | |
| 108 } | |
| 109 | |
| 110 bool EsParserAdtsTest::ProcessPesPackets( | |
| 111 const std::vector<Packet>& pes_packets, | |
| 112 bool force_timing) { | |
| 113 EsParserAdts es_parser( | |
| 114 base::Bind(&EsParserAdtsTest::NewAudioConfig, base::Unretained(this)), | |
| 115 base::Bind(&EsParserAdtsTest::EmitBuffer, base::Unretained(this)), | |
| 116 false); | |
| 117 | |
| 118 for (size_t k = 0; k < pes_packets.size(); k++) { | |
| 119 size_t cur_pes_offset = pes_packets[k].offset; | |
| 120 size_t cur_pes_size = pes_packets[k].size; | |
| 121 | |
| 122 base::TimeDelta pts = kNoTimestamp(); | |
| 123 base::TimeDelta dts = kNoTimestamp(); | |
| 124 if (pes_packets[k].pts >= base::TimeDelta() || force_timing) | |
| 125 pts = pes_packets[k].pts; | |
| 126 | |
| 127 if (!es_parser.Parse(&stream_[cur_pes_offset], cur_pes_size, pts, dts)) | |
| 128 return false; | |
| 129 } | |
| 130 es_parser.Flush(); | |
| 131 return true; | |
| 132 } | |
| 133 | |
| 134 void EsParserAdtsTest::NewAudioConfig(const AudioDecoderConfig& config) { | |
| 135 config_count_++; | |
| 136 } | |
| 137 | |
| 138 void EsParserAdtsTest::EmitBuffer(scoped_refptr<StreamParserBuffer> buffer) { | |
| 139 buffer_count_++; | |
| 140 } | |
| 141 | |
| 142 TEST_F(EsParserAdtsTest, NoInitialPts) { | |
| 143 LoadStream("bear.adts"); | |
| 144 std::vector<Packet> pes_packets = GenerateFixedSizePesPacket(stream_, 512); | |
| 145 EXPECT_FALSE(ProcessPesPackets(pes_packets, false)); | |
|
wolenetz
2014/07/15 21:59:57
To verify the first condition added in this change
damienv1
2014/07/15 22:22:40
I'll check the buffers.
On the other side, whether
wolenetz
2014/07/15 22:39:21
Acknowledged.
| |
| 146 } | |
| 147 | |
|
wolenetz
2014/07/15 21:59:56
Is it possible to distinctly verify the second con
| |
| 148 TEST_F(EsParserAdtsTest, SinglePts) { | |
| 149 LoadStream("bear.adts"); | |
| 150 | |
| 151 std::vector<Packet> pes_packets = GenerateFixedSizePesPacket(stream_, 512); | |
| 152 pes_packets.front().pts = base::TimeDelta::FromSeconds(10); | |
| 153 | |
| 154 EXPECT_TRUE(ProcessPesPackets(pes_packets, false)); | |
| 155 EXPECT_EQ(config_count_, 1u); | |
|
wolenetz
2014/07/15 21:59:57
nit: here and elsewhere in this file, EXPECT_EQ(<e
damienv1
2014/07/15 22:22:40
Done.
| |
| 156 EXPECT_EQ(buffer_count_, 45u); | |
| 157 } | |
| 158 | |
| 159 } // namespace mp2t | |
| 160 } // namespace media | |
| 161 | |
| OLD | NEW |