Shaka Packager SDK
mp2t_media_parser.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_MP2T_MEDIA_PARSER_H_
6 #define PACKAGER_MEDIA_FORMATS_MP2T_MP2T_MEDIA_PARSER_H_
7 
8 #include <bitset>
9 #include <deque>
10 #include <map>
11 #include <memory>
12 
13 #include "packager/media/base/byte_queue.h"
14 #include "packager/media/base/media_parser.h"
15 #include "packager/media/base/stream_info.h"
16 #include "packager/media/formats/mp2t/ts_stream_type.h"
17 
18 namespace shaka {
19 namespace media {
20 
21 class MediaSample;
22 
23 namespace mp2t {
24 
25 class PidState;
26 class TsPacket;
27 class TsSection;
28 
29 class Mp2tMediaParser : public MediaParser {
30  public:
32  ~Mp2tMediaParser() override;
33 
36  void Init(const InitCB& init_cb,
37  const NewMediaSampleCB& new_media_sample_cb,
38  const NewTextSampleCB& new_text_sample_cb,
39  KeySource* decryption_key_source) override;
40  bool Flush() override WARN_UNUSED_RESULT;
41  bool Parse(const uint8_t* buf, int size) override WARN_UNUSED_RESULT;
43 
44  private:
45  // Callback invoked to register a Program Map Table.
46  // Note: Does nothing if the PID is already registered.
47  void RegisterPmt(int program_number, int pmt_pid);
48 
49  // Callback invoked to register a PES pid.
50  // Possible values for |media_type| are defined in:
51  // ISO-13818.1 / ITU H.222 Table 2.34 "Media type assignments".
52  // |pes_pid| is part of the Program Map Table refered by |pmt_pid|.
53  void RegisterPes(int pmt_pid,
54  int pes_pid,
55  TsStreamType media_type,
56  const uint8_t* descriptor,
57  size_t descriptor_length);
58 
59  // Callback invoked each time the audio/video decoder configuration is
60  // changed.
61  void OnNewStreamInfo(uint32_t pes_pid,
62  std::shared_ptr<StreamInfo> new_stream_info);
63 
64  // Callback invoked by the ES media parser
65  // to emit a new audio/video access unit.
66  void OnEmitMediaSample(uint32_t pes_pid,
67  std::shared_ptr<MediaSample> new_sample);
68  void OnEmitTextSample(uint32_t pes_pid,
69  std::shared_ptr<TextSample> new_sample);
70 
71  // Invoke the initialization callback if needed.
72  bool FinishInitializationIfNeeded();
73 
74  bool EmitRemainingSamples();
75 
78  void set_sbr_in_mime_type(bool sbr_in_mimetype) {
79  sbr_in_mimetype_ = sbr_in_mimetype;
80  }
81 
82  // List of callbacks.
83  InitCB init_cb_;
84  NewMediaSampleCB new_media_sample_cb_;
85  NewTextSampleCB new_text_sample_cb_;
86 
87  bool sbr_in_mimetype_;
88 
89  // Bytes of the TS media.
90  ByteQueue ts_byte_queue_;
91 
92  // Map of PIDs and their states. Use an ordered map so manifest generation
93  // has a deterministic order.
94  std::map<int, std::unique_ptr<PidState>> pids_;
95 
96  // Whether |init_cb_| has been invoked.
97  bool is_initialized_;
98 
99  // A map used to track unsupported stream types and make sure the error is
100  // only logged once.
101  std::bitset<256> stream_type_logged_once_;
102 
103  DISALLOW_COPY_AND_ASSIGN(Mp2tMediaParser);
104 };
105 
106 } // namespace mp2t
107 } // namespace media
108 } // namespace shaka
109 
110 #endif
KeySource is responsible for encryption key acquisition.
Definition: key_source.h:51
base::Callback< bool(uint32_t track_id, std::shared_ptr< TextSample > text_sample)> NewTextSampleCB
Definition: media_parser.h:53
base::Callback< bool(uint32_t track_id, std::shared_ptr< MediaSample > media_sample)> NewMediaSampleCB
Definition: media_parser.h:44
base::Callback< void(const std::vector< std::shared_ptr< StreamInfo > > &stream_info)> InitCB
Definition: media_parser.h:35
void Init(const InitCB &init_cb, const NewMediaSampleCB &new_media_sample_cb, const NewTextSampleCB &new_text_sample_cb, KeySource *decryption_key_source) override
bool Parse(const uint8_t *buf, int size) override WARN_UNUSED_RESULT
bool Flush() override WARN_UNUSED_RESULT
All the methods that are virtual are virtual for mocking.