Upstreaming browser/ui/uikit_ui_util from iOS.
[chromium-blink-merge.git] / media / formats / mp2t / es_parser_mpeg1audio_unittest.cc
blobfd95e6e055b1c2b5de190c6a4d53f2b614aaf200
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/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"
17 namespace media {
18 class AudioDecoderConfig;
20 namespace mp2t {
22 class EsParserMpeg1AudioTest : public EsParserTestBase,
23 public testing::Test {
24 public:
25 EsParserMpeg1AudioTest();
27 protected:
28 bool Process(const std::vector<Packet>& pes_packets, bool force_timing);
30 private:
31 DISALLOW_COPY_AND_ASSIGN(EsParserMpeg1AudioTest);
34 EsParserMpeg1AudioTest::EsParserMpeg1AudioTest() {
37 bool EsParserMpeg1AudioTest::Process(
38 const std::vector<Packet>& pes_packets,
39 bool force_timing) {
40 EsParserMpeg1Audio es_parser(
41 base::Bind(&EsParserMpeg1AudioTest::NewAudioConfig,
42 base::Unretained(this)),
43 base::Bind(&EsParserMpeg1AudioTest::EmitBuffer, base::Unretained(this)),
44 new MediaLog());
45 return ProcessPesPackets(&es_parser, pes_packets, force_timing);
48 TEST_F(EsParserMpeg1AudioTest, SinglePts) {
49 LoadStream("sfx.mp3");
51 std::vector<Packet> pes_packets = GenerateFixedSizePesPacket(512);
52 pes_packets.front().pts = base::TimeDelta::FromSeconds(10);
54 // Note: there is no parsing of metadata as part of Mpeg2 TS,
55 // so the tag starting at 0x80d with 0x54 0x41 0x47 (ascii for "TAG")
56 // is not a valid Mpeg1 audio frame header. This makes the previous frame
57 // invalid since there is no start code following the previous frame.
58 // So instead of the 13 Mpeg1 audio frames, only 12 are considered valid.
59 // Offset of frames in the file:
60 // {0x20, 0x1c1, 0x277, 0x2f9, 0x3fd, 0x47f, 0x501, 0x583,
61 // 0x605, 0x687, 0x73d, 0x7a5, 0x80d}
62 // TODO(damienv): find a file that would be more relevant for Mpeg1 audio
63 // as part of Mpeg2 TS.
64 EXPECT_TRUE(Process(pes_packets, false));
65 EXPECT_EQ(1u, config_count_);
66 EXPECT_EQ(12u, buffer_count_);
69 TEST_F(EsParserMpeg1AudioTest, NoTimingInfo) {
70 LoadStream("sfx.mp3");
71 std::vector<Packet> pes_packets = GenerateFixedSizePesPacket(512);
73 // Process should succeed even without timing info, we should just skip the
74 // audio frames without timing info, but still should be able to parse and
75 // play the stream after that.
76 EXPECT_TRUE(Process(pes_packets, false));
77 EXPECT_EQ(1u, config_count_);
78 EXPECT_EQ(0u, buffer_count_);
81 } // namespace mp2t
82 } // namespace media