OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef MEDIA_FORMATS_MP2T_MP2T_STREAM_PARSER_H_ | 5 #ifndef MEDIA_FORMATS_MP2T_MP2T_STREAM_PARSER_H_ |
6 #define MEDIA_FORMATS_MP2T_MP2T_STREAM_PARSER_H_ | 6 #define MEDIA_FORMATS_MP2T_MP2T_STREAM_PARSER_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <list> | 10 #include <list> |
11 #include <map> | 11 #include <map> |
12 | 12 |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
16 #include "media/base/audio_decoder_config.h" | 16 #include "media/base/audio_decoder_config.h" |
17 #include "media/base/byte_queue.h" | 17 #include "media/base/byte_queue.h" |
| 18 #include "media/base/decrypt_config.h" |
18 #include "media/base/media_export.h" | 19 #include "media/base/media_export.h" |
19 #include "media/base/stream_parser.h" | 20 #include "media/base/stream_parser.h" |
20 #include "media/base/video_decoder_config.h" | 21 #include "media/base/video_decoder_config.h" |
21 #include "media/formats/mp2t/timestamp_unroller.h" | 22 #include "media/formats/mp2t/timestamp_unroller.h" |
| 23 #include "media/media_features.h" |
22 | 24 |
23 namespace media { | 25 namespace media { |
24 | 26 |
| 27 class DecryptConfig; |
25 class StreamParserBuffer; | 28 class StreamParserBuffer; |
26 | 29 |
27 namespace mp2t { | 30 namespace mp2t { |
28 | 31 |
| 32 class Descriptors; |
29 class PidState; | 33 class PidState; |
30 | 34 |
31 class MEDIA_EXPORT Mp2tStreamParser : public StreamParser { | 35 class MEDIA_EXPORT Mp2tStreamParser : public StreamParser { |
32 public: | 36 public: |
33 explicit Mp2tStreamParser(bool sbr_in_mimetype); | 37 explicit Mp2tStreamParser(bool sbr_in_mimetype); |
34 ~Mp2tStreamParser() override; | 38 ~Mp2tStreamParser() override; |
35 | 39 |
36 // StreamParser implementation. | 40 // StreamParser implementation. |
37 void Init(const InitCB& init_cb, | 41 void Init(const InitCB& init_cb, |
38 const NewConfigCB& config_cb, | 42 const NewConfigCB& config_cb, |
39 const NewBuffersCB& new_buffers_cb, | 43 const NewBuffersCB& new_buffers_cb, |
40 bool ignore_text_tracks, | 44 bool ignore_text_tracks, |
41 const EncryptedMediaInitDataCB& encrypted_media_init_data_cb, | 45 const EncryptedMediaInitDataCB& encrypted_media_init_data_cb, |
42 const NewMediaSegmentCB& new_segment_cb, | 46 const NewMediaSegmentCB& new_segment_cb, |
43 const EndMediaSegmentCB& end_of_segment_cb, | 47 const EndMediaSegmentCB& end_of_segment_cb, |
44 const scoped_refptr<MediaLog>& media_log) override; | 48 const scoped_refptr<MediaLog>& media_log) override; |
45 void Flush() override; | 49 void Flush() override; |
46 bool Parse(const uint8_t* buf, int size) override; | 50 bool Parse(const uint8_t* buf, int size) override; |
47 | 51 |
48 private: | 52 private: |
49 typedef std::map<int, PidState*> PidMap; | 53 using PidMap = std::map<int, PidState*>; |
| 54 using PidMapElement = std::pair<int, PidState*>; |
50 | 55 |
51 struct BufferQueueWithConfig { | 56 struct BufferQueueWithConfig { |
52 BufferQueueWithConfig(bool is_cfg_sent, | 57 BufferQueueWithConfig(bool is_cfg_sent, |
53 const AudioDecoderConfig& audio_cfg, | 58 const AudioDecoderConfig& audio_cfg, |
54 const VideoDecoderConfig& video_cfg); | 59 const VideoDecoderConfig& video_cfg); |
55 ~BufferQueueWithConfig(); | 60 ~BufferQueueWithConfig(); |
56 | 61 |
57 bool is_config_sent; | 62 bool is_config_sent; |
58 AudioDecoderConfig audio_config; | 63 AudioDecoderConfig audio_config; |
59 StreamParser::BufferQueue audio_queue; | 64 StreamParser::BufferQueue audio_queue; |
60 VideoDecoderConfig video_config; | 65 VideoDecoderConfig video_config; |
61 StreamParser::BufferQueue video_queue; | 66 StreamParser::BufferQueue video_queue; |
62 }; | 67 }; |
63 | 68 |
64 // Callback invoked to register a Program Map Table. | 69 // Callback invoked to register a Program Map Table. |
65 // Note: Does nothing if the PID is already registered. | 70 // Note: Does nothing if the PID is already registered. |
66 void RegisterPmt(int program_number, int pmt_pid); | 71 void RegisterPmt(int program_number, int pmt_pid); |
67 | 72 |
68 // Callback invoked to register a PES pid. | 73 // Callback invoked to register a PES pid. |
69 // Possible values for |stream_type| are defined in: | 74 // Possible values for |stream_type| are defined in: |
70 // ISO-13818.1 / ITU H.222 Table 2.34 "Stream type assignments". | 75 // ISO-13818.1 / ITU H.222 Table 2.34 "Stream type assignments". |
71 // |pes_pid| is part of the Program Map Table refered by |pmt_pid|. | 76 // |pes_pid| is part of the Program Map Table refered by |pmt_pid|. |
72 void RegisterPes(int pmt_pid, int pes_pid, int stream_type); | 77 // Some stream types are qualified by additional |descriptors|. |
| 78 void RegisterPes(int pmt_pid, |
| 79 int pes_pid, |
| 80 int stream_type, |
| 81 const Descriptors& descriptors); |
73 | 82 |
74 // Since the StreamParser interface allows only one audio & video streams, | 83 // Since the StreamParser interface allows only one audio & video streams, |
75 // an automatic PID filtering should be applied to select the audio & video | 84 // an automatic PID filtering should be applied to select the audio & video |
76 // streams. | 85 // streams. |
77 void UpdatePidFilter(); | 86 void UpdatePidFilter(); |
78 | 87 |
79 // Callback invoked each time the audio/video decoder configuration is | 88 // Callback invoked each time the audio/video decoder configuration is |
80 // changed. | 89 // changed. |
81 void OnVideoConfigChanged(int pes_pid, | 90 void OnVideoConfigChanged(int pes_pid, |
82 const VideoDecoderConfig& video_decoder_config); | 91 const VideoDecoderConfig& video_decoder_config); |
83 void OnAudioConfigChanged(int pes_pid, | 92 void OnAudioConfigChanged(int pes_pid, |
84 const AudioDecoderConfig& audio_decoder_config); | 93 const AudioDecoderConfig& audio_decoder_config); |
85 | 94 |
86 // Invoke the initialization callback if needed. | 95 // Invoke the initialization callback if needed. |
87 bool FinishInitializationIfNeeded(); | 96 bool FinishInitializationIfNeeded(); |
88 | 97 |
89 // Callback invoked by the ES stream parser | 98 // Callback invoked by the ES stream parser |
90 // to emit a new audio/video access unit. | 99 // to emit a new audio/video access unit. |
91 void OnEmitAudioBuffer( | 100 void OnEmitAudioBuffer( |
92 int pes_pid, | 101 int pes_pid, |
93 scoped_refptr<StreamParserBuffer> stream_parser_buffer); | 102 scoped_refptr<StreamParserBuffer> stream_parser_buffer); |
94 void OnEmitVideoBuffer( | 103 void OnEmitVideoBuffer( |
95 int pes_pid, | 104 int pes_pid, |
96 scoped_refptr<StreamParserBuffer> stream_parser_buffer); | 105 scoped_refptr<StreamParserBuffer> stream_parser_buffer); |
97 bool EmitRemainingBuffers(); | 106 bool EmitRemainingBuffers(); |
98 | 107 |
| 108 #if BUILDFLAG(ENABLE_HLS_SAMPLE_AES) |
| 109 // Register the parser for CA Table. |
| 110 PidMap::iterator RegisterCat(); |
| 111 void UnregisterCat(); |
| 112 |
| 113 // Register the PIDs for the Cenc packets (CENC-ECM and CENC-PSSH). |
| 114 void RegisterCencPids(int ca_pid, int pssh_pid); |
| 115 void UnregisterCencPids(); |
| 116 |
| 117 // Register the DecryptConfig (parsed from CENC-ECM). |
| 118 void RegisterDecryptConfig(const DecryptConfig& config); |
| 119 |
| 120 // Register the PSSH (parsed from CENC-PSSH). |
| 121 void RegisterPsshBoxes(const std::vector<uint8_t>& init_data); |
| 122 |
| 123 const DecryptConfig* GetDecryptConfig() { return decrypt_config_.get(); } |
| 124 #endif |
| 125 |
99 // List of callbacks. | 126 // List of callbacks. |
100 InitCB init_cb_; | 127 InitCB init_cb_; |
101 NewConfigCB config_cb_; | 128 NewConfigCB config_cb_; |
102 NewBuffersCB new_buffers_cb_; | 129 NewBuffersCB new_buffers_cb_; |
103 EncryptedMediaInitDataCB encrypted_media_init_data_cb_; | 130 EncryptedMediaInitDataCB encrypted_media_init_data_cb_; |
104 NewMediaSegmentCB new_segment_cb_; | 131 NewMediaSegmentCB new_segment_cb_; |
105 EndMediaSegmentCB end_of_segment_cb_; | 132 EndMediaSegmentCB end_of_segment_cb_; |
106 scoped_refptr<MediaLog> media_log_; | 133 scoped_refptr<MediaLog> media_log_; |
107 | 134 |
108 // True when AAC SBR extension is signalled in the mimetype | 135 // True when AAC SBR extension is signalled in the mimetype |
(...skipping 17 matching lines...) Expand all Loading... |
126 bool is_initialized_; | 153 bool is_initialized_; |
127 | 154 |
128 // Indicate whether a segment was started. | 155 // Indicate whether a segment was started. |
129 bool segment_started_; | 156 bool segment_started_; |
130 | 157 |
131 // Timestamp unroller. | 158 // Timestamp unroller. |
132 // Timestamps in PES packets must be unrolled using the same offset. | 159 // Timestamps in PES packets must be unrolled using the same offset. |
133 // So the unroller is global between PES pids. | 160 // So the unroller is global between PES pids. |
134 TimestampUnroller timestamp_unroller_; | 161 TimestampUnroller timestamp_unroller_; |
135 | 162 |
| 163 #if BUILDFLAG(ENABLE_HLS_SAMPLE_AES) |
| 164 scoped_ptr<DecryptConfig> decrypt_config_; |
| 165 #endif |
| 166 |
136 DISALLOW_COPY_AND_ASSIGN(Mp2tStreamParser); | 167 DISALLOW_COPY_AND_ASSIGN(Mp2tStreamParser); |
137 }; | 168 }; |
138 | 169 |
139 } // namespace mp2t | 170 } // namespace mp2t |
140 } // namespace media | 171 } // namespace media |
141 | 172 |
142 #endif | 173 #endif |
143 | 174 |
OLD | NEW |