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.
8 #include "base/logging.h"
9 #include "base/time/time.h"
10 #include "media/base/buffers.h"
11 #include "media/base/media_log.h"
12 #include "media/base/stream_parser_buffer.h"
13 #include "media/formats/mp2t/es_parser_mpeg1audio.h"
14 #include "media/formats/mp2t/es_parser_test_base.h"
15 #include "testing/gtest/include/gtest/gtest.h"
18 class AudioDecoderConfig
;
22 class EsParserMpeg1AudioTest
: public EsParserTestBase
,
23 public testing::Test
{
25 EsParserMpeg1AudioTest();
28 bool Process(const std::vector
<Packet
>& pes_packets
, bool force_timing
);
31 DISALLOW_COPY_AND_ASSIGN(EsParserMpeg1AudioTest
);
34 EsParserMpeg1AudioTest::EsParserMpeg1AudioTest() {
37 bool EsParserMpeg1AudioTest::Process(
38 const std::vector
<Packet
>& pes_packets
,
40 EsParserMpeg1Audio
es_parser(
41 base::Bind(&EsParserMpeg1AudioTest::NewAudioConfig
,
42 base::Unretained(this)),
43 base::Bind(&EsParserMpeg1AudioTest::EmitBuffer
,
44 base::Unretained(this)),
46 return ProcessPesPackets(&es_parser
, pes_packets
, force_timing
);
49 TEST_F(EsParserMpeg1AudioTest
, SinglePts
) {
50 LoadStream("sfx.mp3");
52 std::vector
<Packet
> pes_packets
= GenerateFixedSizePesPacket(512);
53 pes_packets
.front().pts
= base::TimeDelta::FromSeconds(10);
55 // Note: there is no parsing of metadata as part of Mpeg2 TS,
56 // so the tag starting at 0x80d with 0x54 0x41 0x47 (ascii for "TAG")
57 // is not a valid Mpeg1 audio frame header. This makes the previous frame
58 // invalid since there is no start code following the previous frame.
59 // So instead of the 13 Mpeg1 audio frames, only 12 are considered valid.
60 // Offset of frames in the file:
61 // {0x20, 0x1c1, 0x277, 0x2f9, 0x3fd, 0x47f, 0x501, 0x583,
62 // 0x605, 0x687, 0x73d, 0x7a5, 0x80d}
63 // TODO(damienv): find a file that would be more relevant for Mpeg1 audio
64 // as part of Mpeg2 TS.
65 EXPECT_TRUE(Process(pes_packets
, false));
66 EXPECT_EQ(1u, config_count_
);
67 EXPECT_EQ(12u, buffer_count_
);
70 TEST_F(EsParserMpeg1AudioTest
, NoTimingInfo
) {
71 LoadStream("sfx.mp3");
72 std::vector
<Packet
> pes_packets
= GenerateFixedSizePesPacket(512);
74 // Process should succeed even without timing info, we should just skip the
75 // audio frames without timing info, but still should be able to parse and
76 // play the stream after that.
77 EXPECT_TRUE(Process(pes_packets
, false));
78 EXPECT_EQ(1u, config_count_
);
79 EXPECT_EQ(0u, buffer_count_
);