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 "media/formats/mp2t/es_parser_test_helper.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" |
| 20 |
| 21 namespace media { |
| 22 class AudioDecoderConfig; |
| 23 |
| 24 namespace mp2t { |
| 25 |
| 26 namespace { |
| 27 |
| 28 std::vector<Packet> GenerateFixedSizePesPacket( |
| 29 const std::vector<uint8>& stream, size_t pes_size) { |
| 30 std::vector<Packet> pes_packets; |
| 31 |
| 32 Packet cur_pes_packet; |
| 33 cur_pes_packet.offset = 0; |
| 34 cur_pes_packet.pts = kNoTimestamp(); |
| 35 while (cur_pes_packet.offset < stream.size()) { |
| 36 pes_packets.push_back(cur_pes_packet); |
| 37 cur_pes_packet.offset += pes_size; |
| 38 } |
| 39 ComputePacketSize(&pes_packets, stream.size()); |
| 40 |
| 41 return pes_packets; |
| 42 } |
| 43 |
| 44 } // namespace |
| 45 |
| 46 class EsParserAdtsTest : public testing::Test { |
| 47 public: |
| 48 EsParserAdtsTest(); |
| 49 virtual ~EsParserAdtsTest() {} |
| 50 |
| 51 protected: |
| 52 void LoadStream(const char* filename); |
| 53 bool Process(const std::vector<Packet>& pes_packets, bool force_timing); |
| 54 |
| 55 // ADTS stream. |
| 56 std::vector<uint8> stream_; |
| 57 |
| 58 // Number of different audio configs in the ADTS stream. |
| 59 size_t config_count_; |
| 60 |
| 61 // Number of buffers generated while parsing the ADTS stream. |
| 62 size_t buffer_count_; |
| 63 |
| 64 private: |
| 65 void NewAudioConfig(const AudioDecoderConfig& config); |
| 66 void EmitBuffer(scoped_refptr<StreamParserBuffer> buffer); |
| 67 |
| 68 DISALLOW_COPY_AND_ASSIGN(EsParserAdtsTest); |
| 69 }; |
| 70 |
| 71 EsParserAdtsTest::EsParserAdtsTest() |
| 72 : config_count_(0), |
| 73 buffer_count_(0) { |
| 74 } |
| 75 |
| 76 void EsParserAdtsTest::LoadStream(const char* filename) { |
| 77 base::FilePath file_path = GetTestDataFilePath(filename); |
| 78 |
| 79 base::MemoryMappedFile stream; |
| 80 ASSERT_TRUE(stream.Initialize(file_path)) |
| 81 << "Couldn't open stream file: " << file_path.MaybeAsASCII(); |
| 82 |
| 83 stream_.resize(stream.length()); |
| 84 memcpy(stream_.data(), stream.data(), stream_.size()); |
| 85 } |
| 86 |
| 87 bool EsParserAdtsTest::Process( |
| 88 const std::vector<Packet>& pes_packets, |
| 89 bool force_timing) { |
| 90 EsParserAdts es_parser( |
| 91 base::Bind(&EsParserAdtsTest::NewAudioConfig, base::Unretained(this)), |
| 92 base::Bind(&EsParserAdtsTest::EmitBuffer, base::Unretained(this)), |
| 93 false); |
| 94 |
| 95 return ProcessPesPackets(&es_parser, stream_, pes_packets, force_timing); |
| 96 } |
| 97 |
| 98 void EsParserAdtsTest::NewAudioConfig(const AudioDecoderConfig& config) { |
| 99 config_count_++; |
| 100 } |
| 101 |
| 102 void EsParserAdtsTest::EmitBuffer(scoped_refptr<StreamParserBuffer> buffer) { |
| 103 buffer_count_++; |
| 104 } |
| 105 |
| 106 TEST_F(EsParserAdtsTest, NoInitialPts) { |
| 107 LoadStream("bear.adts"); |
| 108 std::vector<Packet> pes_packets = GenerateFixedSizePesPacket(stream_, 512); |
| 109 EXPECT_FALSE(Process(pes_packets, false)); |
| 110 EXPECT_EQ(0u, buffer_count_); |
| 111 } |
| 112 |
| 113 TEST_F(EsParserAdtsTest, SinglePts) { |
| 114 LoadStream("bear.adts"); |
| 115 |
| 116 std::vector<Packet> pes_packets = GenerateFixedSizePesPacket(stream_, 512); |
| 117 pes_packets.front().pts = base::TimeDelta::FromSeconds(10); |
| 118 |
| 119 EXPECT_TRUE(Process(pes_packets, false)); |
| 120 EXPECT_EQ(1u, config_count_); |
| 121 EXPECT_EQ(45u, buffer_count_); |
| 122 } |
| 123 |
| 124 } // namespace mp2t |
| 125 } // namespace media |
| 126 |
OLD | NEW |