summaryrefslogtreecommitdiffstats
path: root/media/formats/mp2t/es_parser_mpeg1audio_unittest.cc
blob: 0571f058173208cb4c383b0433d90d520a3acbc7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <vector>

#include "base/bind.h"
#include "base/logging.h"
#include "base/time/time.h"
#include "media/base/buffers.h"
#include "media/base/media_log.h"
#include "media/base/stream_parser_buffer.h"
#include "media/formats/mp2t/es_parser_mpeg1audio.h"
#include "media/formats/mp2t/es_parser_test_base.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace media {
class AudioDecoderConfig;

namespace mp2t {

class EsParserMpeg1AudioTest : public EsParserTestBase,
                               public testing::Test {
 public:
  EsParserMpeg1AudioTest();
  virtual ~EsParserMpeg1AudioTest() {}

 protected:
  bool Process(const std::vector<Packet>& pes_packets, bool force_timing);

 private:
  DISALLOW_COPY_AND_ASSIGN(EsParserMpeg1AudioTest);
};

EsParserMpeg1AudioTest::EsParserMpeg1AudioTest() {
}

bool EsParserMpeg1AudioTest::Process(
    const std::vector<Packet>& pes_packets,
    bool force_timing) {
  EsParserMpeg1Audio es_parser(
      base::Bind(&EsParserMpeg1AudioTest::NewAudioConfig,
                 base::Unretained(this)),
      base::Bind(&EsParserMpeg1AudioTest::EmitBuffer,
                 base::Unretained(this)),
      LogCB());
  return ProcessPesPackets(&es_parser, pes_packets, force_timing);
}

TEST_F(EsParserMpeg1AudioTest, SinglePts) {
  LoadStream("sfx.mp3");

  std::vector<Packet> pes_packets = GenerateFixedSizePesPacket(512);
  pes_packets.front().pts = base::TimeDelta::FromSeconds(10);

  // Note: there is no parsing of metadata as part of Mpeg2 TS,
  // so the tag starting at 0x80d with 0x54 0x41 0x47 (ascii for "TAG")
  // is not a valid Mpeg1 audio frame header. This makes the previous frame
  // invalid since there is no start code following the previous frame.
  // So instead of the 13 Mpeg1 audio frames, only 12 are considered valid.
  // Offset of frames in the file:
  // {0x20,  0x1c1, 0x277, 0x2f9, 0x3fd, 0x47f, 0x501, 0x583,
  //  0x605, 0x687, 0x73d, 0x7a5, 0x80d}
  // TODO(damienv): find a file that would be more relevant for Mpeg1 audio
  // as part of Mpeg2 TS.
  EXPECT_TRUE(Process(pes_packets, false));
  EXPECT_EQ(1u, config_count_);
  EXPECT_EQ(12u, buffer_count_);
}

TEST_F(EsParserMpeg1AudioTest, NoTimingInfo) {
  LoadStream("sfx.mp3");
  std::vector<Packet> pes_packets = GenerateFixedSizePesPacket(512);

  // Process should succeed even without timing info, we should just skip the
  // audio frames without timing info, but still should be able to parse and
  // play the stream after that.
  EXPECT_TRUE(Process(pes_packets, false));
  EXPECT_EQ(1u, config_count_);
  EXPECT_EQ(0u, buffer_count_);
}

}  // namespace mp2t
}  // namespace media