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