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 <vector> |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/logging.h" |
| 9 #include "base/time/time.h" |
| 10 #include "media/base/buffers.h" |
| 11 #include "media/base/stream_parser_buffer.h" |
| 12 #include "media/formats/mp2t/es_parser_adts.h" |
| 13 #include "media/formats/mp2t/es_parser_test_base.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 |
| 16 namespace media { |
| 17 class AudioDecoderConfig; |
| 18 |
| 19 namespace mp2t { |
| 20 |
| 21 class EsParserAdtsTest : public EsParserTestBase, |
| 22 public testing::Test { |
| 23 public: |
| 24 EsParserAdtsTest(); |
| 25 virtual ~EsParserAdtsTest() {} |
| 26 |
| 27 protected: |
| 28 bool Process(const std::vector<Packet>& pes_packets, bool force_timing); |
| 29 |
| 30 std::vector<Packet> GenerateFixedSizePesPacket(size_t pes_size); |
| 31 |
| 32 private: |
| 33 DISALLOW_COPY_AND_ASSIGN(EsParserAdtsTest); |
| 34 }; |
| 35 |
| 36 EsParserAdtsTest::EsParserAdtsTest() { |
| 37 } |
| 38 |
| 39 bool EsParserAdtsTest::Process( |
| 40 const std::vector<Packet>& pes_packets, |
| 41 bool force_timing) { |
| 42 EsParserAdts es_parser( |
| 43 base::Bind(&EsParserAdtsTest::NewAudioConfig, base::Unretained(this)), |
| 44 base::Bind(&EsParserAdtsTest::EmitBuffer, base::Unretained(this)), |
| 45 false); |
| 46 return ProcessPesPackets(&es_parser, pes_packets, force_timing); |
| 47 } |
| 48 |
| 49 std::vector<EsParserTestBase::Packet> |
| 50 EsParserAdtsTest::GenerateFixedSizePesPacket(size_t pes_size) { |
| 51 DCHECK_GT(stream_.size(), 0u); |
| 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); |
| 62 |
| 63 return pes_packets; |
| 64 } |
| 65 |
| 66 TEST_F(EsParserAdtsTest, NoInitialPts) { |
| 67 LoadStream("bear.adts"); |
| 68 std::vector<Packet> pes_packets = GenerateFixedSizePesPacket(512); |
| 69 EXPECT_FALSE(Process(pes_packets, false)); |
| 70 EXPECT_EQ(0u, buffer_count_); |
| 71 } |
| 72 |
| 73 TEST_F(EsParserAdtsTest, SinglePts) { |
| 74 LoadStream("bear.adts"); |
| 75 |
| 76 std::vector<Packet> pes_packets = GenerateFixedSizePesPacket(512); |
| 77 pes_packets.front().pts = base::TimeDelta::FromSeconds(10); |
| 78 |
| 79 EXPECT_TRUE(Process(pes_packets, false)); |
| 80 EXPECT_EQ(1u, config_count_); |
| 81 EXPECT_EQ(45u, buffer_count_); |
| 82 } |
| 83 |
| 84 } // namespace mp2t |
| 85 } // namespace media |
| 86 |
OLD | NEW |