Shaka Packager SDK
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
ts_section_pes.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 MEDIA_FORMATS_MP2T_TS_SECTION_PES_H_
6 #define MEDIA_FORMATS_MP2T_TS_SECTION_PES_H_
7 
8 #include <stdint.h>
9 #include <memory>
10 #include "packager/base/compiler_specific.h"
11 #include "packager/media/base/byte_queue.h"
12 #include "packager/media/formats/mp2t/ts_section.h"
13 
14 namespace shaka {
15 namespace media {
16 namespace mp2t {
17 
18 class EsParser;
19 
20 class TsSectionPes : public TsSection {
21  public:
22  explicit TsSectionPes(std::unique_ptr<EsParser> es_parser);
23  ~TsSectionPes() override;
24 
25  // TsSection implementation.
26  bool Parse(bool payload_unit_start_indicator,
27  const uint8_t* buf,
28  int size) override;
29  void Flush() override;
30  void Reset() override;
31 
32  private:
33  // Emit a reassembled PES packet.
34  // Return true if successful.
35  // |emit_for_unknown_size| is used to force emission for PES packets
36  // whose size is unknown.
37  bool Emit(bool emit_for_unknown_size);
38 
39  // Parse a PES packet, return true if successful.
40  bool ParseInternal(const uint8_t* raw_pes, int raw_pes_size);
41 
42  void ResetPesState();
43 
44  // Bytes of the current PES.
45  ByteQueue pes_byte_queue_;
46 
47  // ES parser.
48  std::unique_ptr<EsParser> es_parser_;
49 
50  // Do not start parsing before getting a unit start indicator.
51  bool wait_for_pusi_;
52 
53  // Used to unroll PTS and DTS.
54  bool previous_pts_valid_;
55  int64_t previous_pts_;
56  bool previous_dts_valid_;
57  int64_t previous_dts_;
58 
59  DISALLOW_COPY_AND_ASSIGN(TsSectionPes);
60 };
61 
62 } // namespace mp2t
63 } // namespace media
64 } // namespace shaka
65 
66 #endif
67