Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / media / formats / mp2t / es_parser_mpeg1audio_unittest.cc
blobcb78950f271b5b5f4f226d7a1f0680e7fe157c1a
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.
5 #include <vector>
7 #include "base/bind.h"
8 #include "base/logging.h"
9 #include "base/time/time.h"
10 #include "media/base/media_log.h"
11 #include "media/base/stream_parser_buffer.h"
12 #include "media/formats/mp2t/es_parser_mpeg1audio.h"
13 #include "media/formats/mp2t/es_parser_test_base.h"
14 #include "testing/gtest/include/gtest/gtest.h"
16 namespace media {
17 class AudioDecoderConfig;
19 namespace mp2t {
21 class EsParserMpeg1AudioTest : public EsParserTestBase,
22 public testing::Test {
23 public:
24 EsParserMpeg1AudioTest();
26 protected:
27 bool Process(const std::vector<Packet>& pes_packets, bool force_timing);
29 private:
30 DISALLOW_COPY_AND_ASSIGN(EsParserMpeg1AudioTest);
33 EsParserMpeg1AudioTest::EsParserMpeg1AudioTest() {
36 bool EsParserMpeg1AudioTest::Process(
37 const std::vector<Packet>& pes_packets,
38 bool force_timing) {
39 EsParserMpeg1Audio es_parser(
40 base::Bind(&EsParserMpeg1AudioTest::NewAudioConfig,
41 base::Unretained(this)),
42 base::Bind(&EsParserMpeg1AudioTest::EmitBuffer, base::Unretained(this)),
43 new MediaLog());
44 return ProcessPesPackets(&es_parser, pes_packets, force_timing);
47 TEST_F(EsParserMpeg1AudioTest, SinglePts) {
48 LoadStream("sfx.mp3");
50 std::vector<Packet> pes_packets = GenerateFixedSizePesPacket(512);
51 pes_packets.front().pts = base::TimeDelta::FromSeconds(10);
53 // Note: there is no parsing of metadata as part of Mpeg2 TS,
54 // so the tag starting at 0x80d with 0x54 0x41 0x47 (ascii for "TAG")
55 // is not a valid Mpeg1 audio frame header. This makes the previous frame
56 // invalid since there is no start code following the previous frame.
57 // So instead of the 13 Mpeg1 audio frames, only 12 are considered valid.
58 // Offset of frames in the file:
59 // {0x20, 0x1c1, 0x277, 0x2f9, 0x3fd, 0x47f, 0x501, 0x583,
60 // 0x605, 0x687, 0x73d, 0x7a5, 0x80d}
61 // TODO(damienv): find a file that would be more relevant for Mpeg1 audio
62 // as part of Mpeg2 TS.
63 EXPECT_TRUE(Process(pes_packets, false));
64 EXPECT_EQ(1u, config_count_);
65 EXPECT_EQ(12u, buffer_count_);
68 TEST_F(EsParserMpeg1AudioTest, NoTimingInfo) {
69 LoadStream("sfx.mp3");
70 std::vector<Packet> pes_packets = GenerateFixedSizePesPacket(512);
72 // Process should succeed even without timing info, we should just skip the
73 // audio frames without timing info, but still should be able to parse and
74 // play the stream after that.
75 EXPECT_TRUE(Process(pes_packets, false));
76 EXPECT_EQ(1u, config_count_);
77 EXPECT_EQ(0u, buffer_count_);
80 } // namespace mp2t
81 } // namespace media