Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / media / formats / mp2t / es_parser_adts_unittest.cc
blobe7ccb5cb4ef592c3078f895d60af169bdd7a7842
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/stream_parser_buffer.h"
11 #include "media/formats/mp2t/es_parser_adts.h"
12 #include "media/formats/mp2t/es_parser_test_base.h"
13 #include "testing/gtest/include/gtest/gtest.h"
15 namespace media {
16 class AudioDecoderConfig;
18 namespace mp2t {
20 class EsParserAdtsTest : public EsParserTestBase,
21 public testing::Test {
22 public:
23 EsParserAdtsTest();
25 protected:
26 bool Process(const std::vector<Packet>& pes_packets, bool force_timing);
28 private:
29 DISALLOW_COPY_AND_ASSIGN(EsParserAdtsTest);
32 EsParserAdtsTest::EsParserAdtsTest() {
35 bool EsParserAdtsTest::Process(
36 const std::vector<Packet>& pes_packets,
37 bool force_timing) {
38 EsParserAdts es_parser(
39 base::Bind(&EsParserAdtsTest::NewAudioConfig, base::Unretained(this)),
40 base::Bind(&EsParserAdtsTest::EmitBuffer, base::Unretained(this)),
41 false);
42 return ProcessPesPackets(&es_parser, pes_packets, force_timing);
45 TEST_F(EsParserAdtsTest, NoInitialPts) {
46 LoadStream("bear.adts");
47 std::vector<Packet> pes_packets = GenerateFixedSizePesPacket(512);
48 // Process should succeed even without timing info, we should just skip the
49 // audio frames without timing info, but still should be able to parse and
50 // play the stream after that.
51 EXPECT_TRUE(Process(pes_packets, false));
52 EXPECT_EQ(1u, config_count_);
53 EXPECT_EQ(0u, buffer_count_);
56 TEST_F(EsParserAdtsTest, SinglePts) {
57 LoadStream("bear.adts");
59 std::vector<Packet> pes_packets = GenerateFixedSizePesPacket(512);
60 pes_packets.front().pts = base::TimeDelta::FromSeconds(10);
62 EXPECT_TRUE(Process(pes_packets, false));
63 EXPECT_EQ(1u, config_count_);
64 EXPECT_EQ(45u, buffer_count_);
67 TEST_F(EsParserAdtsTest, AacLcAdts) {
68 LoadStream("sfx.adts");
69 std::vector<Packet> pes_packets = GenerateFixedSizePesPacket(512);
70 pes_packets.front().pts = base::TimeDelta::FromSeconds(1);
71 EXPECT_TRUE(Process(pes_packets, false));
72 EXPECT_EQ(1u, config_count_);
73 EXPECT_EQ(14u, buffer_count_);
75 } // namespace mp2t
76 } // namespace media