OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <vector> | 5 #include <vector> |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
10 #include "media/base/buffers.h" | 10 #include "media/base/buffers.h" |
11 #include "media/base/stream_parser_buffer.h" | 11 #include "media/base/stream_parser_buffer.h" |
12 #include "media/formats/mp2t/es_parser_adts.h" | 12 #include "media/formats/mp2t/es_parser_mpeg1audio.h" |
13 #include "media/formats/mp2t/es_parser_test_base.h" | 13 #include "media/formats/mp2t/es_parser_test_base.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
15 | 15 |
16 namespace media { | 16 namespace media { |
17 class AudioDecoderConfig; | 17 class AudioDecoderConfig; |
18 | 18 |
19 namespace mp2t { | 19 namespace mp2t { |
20 | 20 |
21 class EsParserAdtsTest : public EsParserTestBase, | 21 class EsParserMpeg1AudioTest : public EsParserTestBase, |
22 public testing::Test { | 22 public testing::Test { |
23 public: | 23 public: |
24 EsParserAdtsTest(); | 24 EsParserMpeg1AudioTest(); |
25 virtual ~EsParserAdtsTest() {} | 25 virtual ~EsParserMpeg1AudioTest() {} |
26 | 26 |
27 protected: | 27 protected: |
28 bool Process(const std::vector<Packet>& pes_packets, bool force_timing); | 28 bool Process(const std::vector<Packet>& pes_packets, bool force_timing); |
29 | 29 |
30 std::vector<Packet> GenerateFixedSizePesPacket(size_t pes_size); | 30 std::vector<Packet> GenerateFixedSizePesPacket(size_t pes_size); |
31 | 31 |
32 private: | 32 private: |
33 DISALLOW_COPY_AND_ASSIGN(EsParserAdtsTest); | 33 DISALLOW_COPY_AND_ASSIGN(EsParserMpeg1AudioTest); |
34 }; | 34 }; |
35 | 35 |
36 EsParserAdtsTest::EsParserAdtsTest() { | 36 EsParserMpeg1AudioTest::EsParserMpeg1AudioTest() { |
37 } | 37 } |
38 | 38 |
39 bool EsParserAdtsTest::Process( | 39 bool EsParserMpeg1AudioTest::Process( |
40 const std::vector<Packet>& pes_packets, | 40 const std::vector<Packet>& pes_packets, |
41 bool force_timing) { | 41 bool force_timing) { |
42 EsParserAdts es_parser( | 42 EsParserMpeg1Audio es_parser( |
43 base::Bind(&EsParserAdtsTest::NewAudioConfig, base::Unretained(this)), | 43 base::Bind(&EsParserMpeg1AudioTest::NewAudioConfig, |
44 base::Bind(&EsParserAdtsTest::EmitBuffer, base::Unretained(this)), | 44 base::Unretained(this)), |
45 false); | 45 base::Bind(&EsParserMpeg1AudioTest::EmitBuffer, |
46 base::Unretained(this))); | |
46 return ProcessPesPackets(&es_parser, pes_packets, force_timing); | 47 return ProcessPesPackets(&es_parser, pes_packets, force_timing); |
47 } | 48 } |
48 | 49 |
49 std::vector<EsParserTestBase::Packet> | 50 std::vector<EsParserTestBase::Packet> |
50 EsParserAdtsTest::GenerateFixedSizePesPacket(size_t pes_size) { | 51 EsParserMpeg1AudioTest::GenerateFixedSizePesPacket(size_t pes_size) { |
51 DCHECK_GT(stream_.size(), 0u); | 52 DCHECK_GT(stream_.size(), 0u); |
wolenetz
2014/09/13 00:06:38
nit: candidate for relocation into EsParserTestBas
damienv1
2014/09/13 01:27:47
Done.
| |
52 std::vector<Packet> pes_packets; | 53 std::vector<Packet> pes_packets; |
53 | 54 |
54 Packet cur_pes_packet; | 55 Packet cur_pes_packet; |
55 cur_pes_packet.offset = 0; | 56 cur_pes_packet.offset = 0; |
56 cur_pes_packet.pts = kNoTimestamp(); | 57 cur_pes_packet.pts = kNoTimestamp(); |
57 while (cur_pes_packet.offset < stream_.size()) { | 58 while (cur_pes_packet.offset < stream_.size()) { |
58 pes_packets.push_back(cur_pes_packet); | 59 pes_packets.push_back(cur_pes_packet); |
59 cur_pes_packet.offset += pes_size; | 60 cur_pes_packet.offset += pes_size; |
60 } | 61 } |
61 ComputePacketSize(&pes_packets); | 62 ComputePacketSize(&pes_packets); |
62 | 63 |
63 return pes_packets; | 64 return pes_packets; |
64 } | 65 } |
65 | 66 |
66 TEST_F(EsParserAdtsTest, NoInitialPts) { | 67 TEST_F(EsParserMpeg1AudioTest, SinglePts) { |
67 LoadStream("bear.adts"); | 68 LoadStream("sfx.mp3"); |
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 | 69 |
76 std::vector<Packet> pes_packets = GenerateFixedSizePesPacket(512); | 70 std::vector<Packet> pes_packets = GenerateFixedSizePesPacket(512); |
77 pes_packets.front().pts = base::TimeDelta::FromSeconds(10); | 71 pes_packets.front().pts = base::TimeDelta::FromSeconds(10); |
78 | 72 |
73 // Note: there is no parsing of metadata as part of Mpeg2 TS, | |
74 // so the tag starting at 0x80d with 0x54 0x41 0x47 (ascii for "TAG") | |
75 // is not a valid Mpeg1 audio frame header. This makes the previous frame | |
76 // invalid since there is no start code following the previous frame. | |
77 // So instead of the 13 Mpeg1 audio frames, only 12 are considered valid. | |
78 // Offset of frames in the file: | |
79 // {0x20, 0x1c1, 0x277, 0x2f9, 0x3fd, 0x47f, 0x501, 0x583, | |
80 // 0x605, 0x687, 0x73d, 0x7a5, 0x80d} | |
81 // TODO(damienv): find a file that would be more relevant for Mpeg1 audio | |
82 // as part of Mpeg2 TS. | |
79 EXPECT_TRUE(Process(pes_packets, false)); | 83 EXPECT_TRUE(Process(pes_packets, false)); |
80 EXPECT_EQ(1u, config_count_); | 84 EXPECT_EQ(1u, config_count_); |
81 EXPECT_EQ(45u, buffer_count_); | 85 EXPECT_EQ(12u, buffer_count_); |
82 } | 86 } |
83 | 87 |
84 } // namespace mp2t | 88 } // namespace mp2t |
85 } // namespace media | 89 } // namespace media |
86 | |
OLD | NEW |