Shaka Packager SDK
ts_packet.h
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 PACKAGER_MEDIA_FORMATS_MP2T_TS_PACKET_H_
6 #define PACKAGER_MEDIA_FORMATS_MP2T_TS_PACKET_H_
7 
8 #include <stdint.h>
9 
10 #include "packager/base/macros.h"
11 
12 namespace shaka {
13 namespace media {
14 
15 class BitReader;
16 
17 namespace mp2t {
18 
19 class TsPacket {
20  public:
21  static const int kPacketSize = 188;
22 
23  // Return the number of bytes to discard
24  // to be synchronized on a TS syncword.
25  static int Sync(const uint8_t* buf, int size);
26 
27  // Parse a TS packet.
28  // Return a TsPacket only when parsing was successful.
29  // Return NULL otherwise.
30  static TsPacket* Parse(const uint8_t* buf, int size);
31 
32  ~TsPacket();
33 
34  // TS header accessors.
35  bool payload_unit_start_indicator() const {
36  return payload_unit_start_indicator_;
37  }
38  int pid() const { return pid_; }
39  int continuity_counter() const { return continuity_counter_; }
40  bool discontinuity_indicator() const { return discontinuity_indicator_; }
41  bool random_access_indicator() const { return random_access_indicator_; }
42 
43  // Return the offset and the size of the payload.
44  const uint8_t* payload() const { return payload_; }
45  int payload_size() const { return payload_size_; }
46 
47  private:
48  TsPacket();
49 
50  // Parse an Mpeg2 TS header.
51  // The buffer size should be at least |kPacketSize|
52  bool ParseHeader(const uint8_t* buf);
53  bool ParseAdaptationField(BitReader* bit_reader,
54  int adaptation_field_length);
55 
56  // Size of the payload.
57  const uint8_t* payload_;
58  int payload_size_;
59 
60  // TS header.
61  bool payload_unit_start_indicator_;
62  int pid_;
63  int continuity_counter_;
64 
65  // Params from the adaptation field.
66  bool discontinuity_indicator_;
67  bool random_access_indicator_;
68 
69  DISALLOW_COPY_AND_ASSIGN(TsPacket);
70 };
71 
72 } // namespace mp2t
73 } // namespace media
74 } // namespace shaka
75 
76 #endif
77 
shaka
All the methods that are virtual are virtual for mocking.
Definition: gflags_hex_bytes.cc:11
shaka::media::BitReader
A class to read bit streams.
Definition: bit_reader.h:17
shaka::media::mp2t::TsPacket
Definition: ts_packet.h:19