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