Roll ANGLE e754fb8..6ffeb74
[chromium-blink-merge.git] / media / formats / mp2t / mp2t_stream_parser.h
blobea91d84183477c1b578d7b79317f9e635303d13d
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.
5 #ifndef MEDIA_FORMATS_MP2T_MP2T_STREAM_PARSER_H_
6 #define MEDIA_FORMATS_MP2T_MP2T_STREAM_PARSER_H_
8 #include <list>
9 #include <map>
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "media/base/audio_decoder_config.h"
14 #include "media/base/byte_queue.h"
15 #include "media/base/media_export.h"
16 #include "media/base/stream_parser.h"
17 #include "media/base/video_decoder_config.h"
18 #include "media/formats/mp2t/timestamp_unroller.h"
20 namespace media {
22 class StreamParserBuffer;
24 namespace mp2t {
26 class PidState;
28 class MEDIA_EXPORT Mp2tStreamParser : public StreamParser {
29 public:
30 explicit Mp2tStreamParser(bool sbr_in_mimetype);
31 ~Mp2tStreamParser() override;
33 // StreamParser implementation.
34 void Init(
35 const InitCB& init_cb,
36 const NewConfigCB& config_cb,
37 const NewBuffersCB& new_buffers_cb,
38 bool ignore_text_tracks,
39 const EncryptedMediaInitDataCB& encrypted_media_init_data_cb,
40 const NewMediaSegmentCB& new_segment_cb,
41 const base::Closure& end_of_segment_cb,
42 const LogCB& log_cb) override;
43 void Flush() override;
44 bool Parse(const uint8* buf, int size) override;
46 private:
47 typedef std::map<int, PidState*> PidMap;
49 struct BufferQueueWithConfig {
50 BufferQueueWithConfig(bool is_cfg_sent,
51 const AudioDecoderConfig& audio_cfg,
52 const VideoDecoderConfig& video_cfg);
53 ~BufferQueueWithConfig();
55 bool is_config_sent;
56 AudioDecoderConfig audio_config;
57 StreamParser::BufferQueue audio_queue;
58 VideoDecoderConfig video_config;
59 StreamParser::BufferQueue video_queue;
62 // Callback invoked to register a Program Map Table.
63 // Note: Does nothing if the PID is already registered.
64 void RegisterPmt(int program_number, int pmt_pid);
66 // Callback invoked to register a PES pid.
67 // Possible values for |stream_type| are defined in:
68 // ISO-13818.1 / ITU H.222 Table 2.34 "Stream type assignments".
69 // |pes_pid| is part of the Program Map Table refered by |pmt_pid|.
70 void RegisterPes(int pmt_pid, int pes_pid, int stream_type);
72 // Since the StreamParser interface allows only one audio & video streams,
73 // an automatic PID filtering should be applied to select the audio & video
74 // streams.
75 void UpdatePidFilter();
77 // Callback invoked each time the audio/video decoder configuration is
78 // changed.
79 void OnVideoConfigChanged(int pes_pid,
80 const VideoDecoderConfig& video_decoder_config);
81 void OnAudioConfigChanged(int pes_pid,
82 const AudioDecoderConfig& audio_decoder_config);
84 // Invoke the initialization callback if needed.
85 bool FinishInitializationIfNeeded();
87 // Callback invoked by the ES stream parser
88 // to emit a new audio/video access unit.
89 void OnEmitAudioBuffer(
90 int pes_pid,
91 scoped_refptr<StreamParserBuffer> stream_parser_buffer);
92 void OnEmitVideoBuffer(
93 int pes_pid,
94 scoped_refptr<StreamParserBuffer> stream_parser_buffer);
95 bool EmitRemainingBuffers();
97 // List of callbacks.
98 InitCB init_cb_;
99 NewConfigCB config_cb_;
100 NewBuffersCB new_buffers_cb_;
101 EncryptedMediaInitDataCB encrypted_media_init_data_cb_;
102 NewMediaSegmentCB new_segment_cb_;
103 base::Closure end_of_segment_cb_;
104 LogCB log_cb_;
106 // True when AAC SBR extension is signalled in the mimetype
107 // (mp4a.40.5 in the codecs parameter).
108 bool sbr_in_mimetype_;
110 // Bytes of the TS stream.
111 ByteQueue ts_byte_queue_;
113 // List of PIDs and their state.
114 PidMap pids_;
116 // Selected audio and video PIDs.
117 int selected_audio_pid_;
118 int selected_video_pid_;
120 // Pending audio & video buffers.
121 std::list<BufferQueueWithConfig> buffer_queue_chain_;
123 // Whether |init_cb_| has been invoked.
124 bool is_initialized_;
126 // Indicate whether a segment was started.
127 bool segment_started_;
129 // Timestamp unroller.
130 // Timestamps in PES packets must be unrolled using the same offset.
131 // So the unroller is global between PES pids.
132 TimestampUnroller timestamp_unroller_;
134 DISALLOW_COPY_AND_ASSIGN(Mp2tStreamParser);
137 } // namespace mp2t
138 } // namespace media
140 #endif