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.
4
5#ifndef MEDIA_FORMATS_MP2T_ES_PARSER_TEST_BASE_H_
6#define MEDIA_FORMATS_MP2T_ES_PARSER_TEST_BASE_H_
7
8#include <sstream>
9#include <string>
10#include <vector>
11
12#include "base/macros.h"
13#include "base/memory/ref_counted.h"
14#include "base/time/time.h"
15
16namespace media {
17class AudioDecoderConfig;
18class StreamParserBuffer;
19class VideoDecoderConfig;
20
21namespace mp2t {
22class EsParser;
23
24class EsParserTestBase {
25 public:
26  struct Packet {
27    Packet();
28
29    // Offset in the stream.
30    size_t offset;
31
32    // Size of the packet.
33    size_t size;
34
35    // Timestamp of the packet.
36    base::TimeDelta pts;
37  };
38
39  EsParserTestBase();
40  virtual ~EsParserTestBase();
41
42 protected:
43  void LoadStream(const char* filename);
44
45  // ES parser callbacks.
46  void NewAudioConfig(const AudioDecoderConfig& config);
47  void NewVideoConfig(const VideoDecoderConfig& config);
48  void EmitBuffer(scoped_refptr<StreamParserBuffer> buffer);
49
50  // Process the PES packets using the given ES parser.
51  // When |force_timing| is true, even the invalid negative timestamps will be
52  // given to the ES parser.
53  // Return true if successful, false otherwise.
54  bool ProcessPesPackets(EsParser* es_parser,
55                         const std::vector<Packet>& pes_packets,
56                         bool force_timing);
57
58  // Assume the offsets are known, compute the size of each packet.
59  // The last packet is assumed to cover the end of the stream.
60  // Packets are assumed to be in stream order.
61  void ComputePacketSize(std::vector<Packet>* packets);
62
63  // Generate some fixed size PES packets of |stream_|.
64  std::vector<Packet> GenerateFixedSizePesPacket(size_t pes_size);
65
66  // ES stream.
67  std::vector<uint8> stream_;
68
69  // Number of decoder configs received from the ES parser.
70  size_t config_count_;
71
72  // Number of buffers generated while parsing the ES stream.
73  size_t buffer_count_;
74
75  // Timestamps of buffers generated while parsing the ES stream.
76  std::string buffer_timestamps_;
77
78 private:
79  // Timestamps of buffers generated while parsing the ES stream.
80  std::stringstream buffer_timestamps_stream_;
81
82  DISALLOW_COPY_AND_ASSIGN(EsParserTestBase);
83};
84
85}  // namespace mp2t
86}  // namespace media
87
88#endif  // MEDIA_FORMATS_MP2T_ES_PARSER_TEST_BASE_H_
89