DASH Media Packaging SDK
 All Classes Namespaces Functions Variables Typedefs
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/memory/ref_counted.h"
12 #include "packager/base/memory/scoped_ptr.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 edash_packager {
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  virtual ~Mp2tMediaParser();
34 
35  // MediaParser implementation overrides.
36  virtual void Init(const InitCB& init_cb,
37  const NewSampleCB& new_sample_cb,
38  KeySource* decryption_key_source) OVERRIDE;
39 
40  virtual void Flush() OVERRIDE;
41 
42  virtual bool Parse(const uint8_t* buf, int size) OVERRIDE;
43 
44  private:
45  typedef std::map<int, 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(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, scoped_refptr<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 edash_packager
96 
97 #endif
virtual void Init(const InitCB &init_cb, const NewSampleCB &new_sample_cb, KeySource *decryption_key_source) OVERRIDE
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:29
base::Callback< void(const std::vector< scoped_refptr< StreamInfo > > &stream_info)> InitCB
Definition: media_parser.h:34
virtual bool Parse(const uint8_t *buf, int size) OVERRIDE