DASH Media Packaging SDK
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator
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 MEDIA_FORMATS_MP2T_MP2T_MEDIA_PARSER_H_
6 #define MEDIA_FORMATS_MP2T_MP2T_MEDIA_PARSER_H_
7 
8 #include <deque>
9 #include <map>
10 #include <memory>
11 
12 #include "packager/media/base/byte_queue.h"
13 #include "packager/media/base/media_parser.h"
14 #include "packager/media/base/stream_info.h"
15 
16 namespace shaka {
17 namespace media {
18 
19 class MediaSample;
20 
21 namespace mp2t {
22 
23 class PidState;
24 class TsPacket;
25 class TsSection;
26 
27 typedef std::deque<std::shared_ptr<MediaSample>> SampleQueue;
28 
29 class Mp2tMediaParser : public MediaParser {
30  public:
32  ~Mp2tMediaParser() override;
33 
36  void Init(const InitCB& init_cb,
37  const NewSampleCB& new_sample_cb,
38  KeySource* decryption_key_source) override;
39  bool Flush() override WARN_UNUSED_RESULT;
40  bool Parse(const uint8_t* buf, int size) override WARN_UNUSED_RESULT;
42 
43  private:
44  typedef std::map<int, std::unique_ptr<PidState>> PidMap;
45 
46  // Callback invoked to register a Program Map Table.
47  // Note: Does nothing if the PID is already registered.
48  void RegisterPmt(int program_number, int pmt_pid);
49 
50  // Callback invoked to register a PES pid.
51  // Possible values for |media_type| are defined in:
52  // ISO-13818.1 / ITU H.222 Table 2.34 "Media type assignments".
53  // |pes_pid| is part of the Program Map Table refered by |pmt_pid|.
54  void RegisterPes(int pmt_pid, int pes_pid, int media_type);
55 
56  // Callback invoked each time the audio/video decoder configuration is
57  // changed.
58  void OnNewStreamInfo(const std::shared_ptr<StreamInfo>& new_stream_info);
59 
60  // Callback invoked by the ES media parser
61  // to emit a new audio/video access unit.
62  void OnEmitSample(uint32_t pes_pid,
63  const std::shared_ptr<MediaSample>& new_sample);
64 
65  // Invoke the initialization callback if needed.
66  bool FinishInitializationIfNeeded();
67 
68  bool EmitRemainingSamples();
69 
72  void set_sbr_in_mime_type(bool sbr_in_mimetype) {
73  sbr_in_mimetype_ = sbr_in_mimetype; }
74 
75  // List of callbacks.
76  InitCB init_cb_;
77  NewSampleCB new_sample_cb_;
78 
79  bool sbr_in_mimetype_;
80 
81  // Bytes of the TS media.
82  ByteQueue ts_byte_queue_;
83 
84  // List of PIDs and their states.
85  PidMap pids_;
86 
87  // Whether |init_cb_| has been invoked.
88  bool is_initialized_;
89 
90  DISALLOW_COPY_AND_ASSIGN(Mp2tMediaParser);
91 };
92 
93 } // namespace mp2t
94 } // namespace media
95 } // namespace shaka
96 
97 #endif
void Init(const InitCB &init_cb, const NewSampleCB &new_sample_cb, KeySource *decryption_key_source) override
base::Callback< void(const std::vector< std::shared_ptr< StreamInfo > > &stream_info)> InitCB
Definition: media_parser.h:34
bool Flush() override WARN_UNUSED_RESULT
base::Callback< bool(uint32_t track_id, const std::shared_ptr< MediaSample > &media_sample)> NewSampleCB
Definition: media_parser.h:43
KeySource is responsible for encryption key acquisition.
Definition: key_source.h:45
bool Parse(const uint8_t *buf, int size) override WARN_UNUSED_RESULT