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 #include <memory> | 12 #include <memory> |
13 | 13 |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.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/decrypt_config.h" |
| 19 #include "media/base/encryption_scheme.h" |
19 #include "media/base/media_export.h" | 20 #include "media/base/media_export.h" |
20 #include "media/base/stream_parser.h" | 21 #include "media/base/stream_parser.h" |
21 #include "media/base/video_decoder_config.h" | 22 #include "media/base/video_decoder_config.h" |
22 #include "media/formats/mp2t/timestamp_unroller.h" | 23 #include "media/formats/mp2t/timestamp_unroller.h" |
23 #include "media/media_features.h" | 24 #include "media/media_features.h" |
24 | 25 |
25 namespace media { | 26 namespace media { |
26 | 27 |
27 class DecryptConfig; | 28 class DecryptConfig; |
28 class StreamParserBuffer; | 29 class StreamParserBuffer; |
29 | 30 |
30 namespace mp2t { | 31 namespace mp2t { |
31 | 32 |
32 class Descriptors; | 33 class Descriptors; |
| 34 class EsParser; |
33 class PidState; | 35 class PidState; |
34 | 36 |
35 class MEDIA_EXPORT Mp2tStreamParser : public StreamParser { | 37 class MEDIA_EXPORT Mp2tStreamParser : public StreamParser { |
36 public: | 38 public: |
37 explicit Mp2tStreamParser(bool sbr_in_mimetype); | 39 explicit Mp2tStreamParser(bool sbr_in_mimetype); |
38 ~Mp2tStreamParser() override; | 40 ~Mp2tStreamParser() override; |
39 | 41 |
40 // StreamParser implementation. | 42 // StreamParser implementation. |
41 void Init(const InitCB& init_cb, | 43 void Init(const InitCB& init_cb, |
42 const NewConfigCB& config_cb, | 44 const NewConfigCB& config_cb, |
(...skipping 21 matching lines...) Expand all Loading... |
64 StreamParser::BufferQueue video_queue; | 66 StreamParser::BufferQueue video_queue; |
65 }; | 67 }; |
66 | 68 |
67 // Callback invoked to register a Program Map Table. | 69 // Callback invoked to register a Program Map Table. |
68 // Note: Does nothing if the PID is already registered. | 70 // Note: Does nothing if the PID is already registered. |
69 void RegisterPmt(int program_number, int pmt_pid); | 71 void RegisterPmt(int program_number, int pmt_pid); |
70 | 72 |
71 // Callback invoked to register a PES pid. | 73 // Callback invoked to register a PES pid. |
72 // Possible values for |stream_type| are defined in: | 74 // Possible values for |stream_type| are defined in: |
73 // 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". |
74 // |pes_pid| is part of the Program Map Table refered by |pmt_pid|. | 76 // |pes_pid| is part of the Program Map Table. |
75 // Some stream types are qualified by additional |descriptors|. | 77 // Some stream types are qualified by additional |descriptors|. |
76 void RegisterPes(int pmt_pid, | 78 void RegisterPes(int pes_pid, |
77 int pes_pid, | |
78 int stream_type, | 79 int stream_type, |
79 const Descriptors& descriptors); | 80 const Descriptors& descriptors); |
80 | 81 |
81 // Since the StreamParser interface allows only one audio & video streams, | 82 // Since the StreamParser interface allows only one audio & video streams, |
82 // an automatic PID filtering should be applied to select the audio & video | 83 // an automatic PID filtering should be applied to select the audio & video |
83 // streams. | 84 // streams. |
84 void UpdatePidFilter(); | 85 void UpdatePidFilter(); |
85 | 86 |
86 // Callback invoked each time the audio/video decoder configuration is | 87 // Callback invoked each time the audio/video decoder configuration is |
87 // changed. | 88 // changed. |
88 void OnVideoConfigChanged(int pes_pid, | 89 void OnVideoConfigChanged(int pes_pid, |
89 const VideoDecoderConfig& video_decoder_config); | 90 const VideoDecoderConfig& video_decoder_config); |
90 void OnAudioConfigChanged(int pes_pid, | 91 void OnAudioConfigChanged(int pes_pid, |
91 const AudioDecoderConfig& audio_decoder_config); | 92 const AudioDecoderConfig& audio_decoder_config); |
92 | 93 |
93 // Invoke the initialization callback if needed. | 94 // Invoke the initialization callback if needed. |
94 bool FinishInitializationIfNeeded(); | 95 bool FinishInitializationIfNeeded(); |
95 | 96 |
96 // Callback invoked by the ES stream parser | 97 // Callback invoked by the ES stream parser |
97 // to emit a new audio/video access unit. | 98 // to emit a new audio/video access unit. |
98 void OnEmitAudioBuffer( | 99 void OnEmitAudioBuffer( |
99 int pes_pid, | 100 int pes_pid, |
100 scoped_refptr<StreamParserBuffer> stream_parser_buffer); | 101 scoped_refptr<StreamParserBuffer> stream_parser_buffer); |
101 void OnEmitVideoBuffer( | 102 void OnEmitVideoBuffer( |
102 int pes_pid, | 103 int pes_pid, |
103 scoped_refptr<StreamParserBuffer> stream_parser_buffer); | 104 scoped_refptr<StreamParserBuffer> stream_parser_buffer); |
104 bool EmitRemainingBuffers(); | 105 bool EmitRemainingBuffers(); |
105 | 106 |
| 107 std::unique_ptr<EsParser> CreateH264Parser(int pes_pid); |
| 108 std::unique_ptr<EsParser> CreateAacParser(int pes_pid); |
| 109 std::unique_ptr<EsParser> CreateMpeg1AudioParser(int pes_pid); |
| 110 |
106 #if BUILDFLAG(ENABLE_HLS_SAMPLE_AES) | 111 #if BUILDFLAG(ENABLE_HLS_SAMPLE_AES) |
| 112 bool ShouldForceEncryptedParser(); |
| 113 std::unique_ptr<EsParser> CreateEncryptedH264Parser(int pes_pid); |
| 114 std::unique_ptr<EsParser> CreateEncryptedAacParser(int pes_pid); |
| 115 |
107 std::unique_ptr<PidState> MakeCatPidState(); | 116 std::unique_ptr<PidState> MakeCatPidState(); |
108 void UnregisterCat(); | 117 void UnregisterCat(); |
109 | 118 |
110 // Register the PIDs for the Cenc packets (CENC-ECM and CENC-PSSH). | 119 // Register the PIDs for the Cenc packets (CENC-ECM and CENC-PSSH). |
111 void RegisterCencPids(int ca_pid, int pssh_pid); | 120 void RegisterCencPids(int ca_pid, int pssh_pid); |
112 void UnregisterCencPids(); | 121 void UnregisterCencPids(); |
113 | 122 |
| 123 // Register a default encryption scheme to be used for decoder configs. This |
| 124 // value is only used in the absence of explicit encryption metadata, as might |
| 125 // be the case during an unencrypted portion of a live stream. |
| 126 void RegisterEncryptionScheme(const EncryptionScheme& scheme); |
| 127 |
114 // Register the DecryptConfig (parsed from CENC-ECM). | 128 // Register the DecryptConfig (parsed from CENC-ECM). |
115 void RegisterDecryptConfig(const DecryptConfig& config); | 129 void RegisterDecryptConfig(const DecryptConfig& config); |
116 | 130 |
117 // Register the PSSH (parsed from CENC-PSSH). | 131 // Register the PSSH (parsed from CENC-PSSH). |
118 void RegisterPsshBoxes(const std::vector<uint8_t>& init_data); | 132 void RegisterPsshBoxes(const std::vector<uint8_t>& init_data); |
119 | 133 |
120 const DecryptConfig* GetDecryptConfig() { return decrypt_config_.get(); } | 134 const DecryptConfig* GetDecryptConfig() { return decrypt_config_.get(); } |
121 #endif | 135 #endif |
122 | 136 |
123 // List of callbacks. | 137 // List of callbacks. |
(...skipping 27 matching lines...) Expand all Loading... |
151 | 165 |
152 // Indicate whether a segment was started. | 166 // Indicate whether a segment was started. |
153 bool segment_started_; | 167 bool segment_started_; |
154 | 168 |
155 // Timestamp unroller. | 169 // Timestamp unroller. |
156 // Timestamps in PES packets must be unrolled using the same offset. | 170 // Timestamps in PES packets must be unrolled using the same offset. |
157 // So the unroller is global between PES pids. | 171 // So the unroller is global between PES pids. |
158 TimestampUnroller timestamp_unroller_; | 172 TimestampUnroller timestamp_unroller_; |
159 | 173 |
160 #if BUILDFLAG(ENABLE_HLS_SAMPLE_AES) | 174 #if BUILDFLAG(ENABLE_HLS_SAMPLE_AES) |
| 175 EncryptionScheme initial_scheme_; |
161 std::unique_ptr<DecryptConfig> decrypt_config_; | 176 std::unique_ptr<DecryptConfig> decrypt_config_; |
162 #endif | 177 #endif |
163 | 178 |
164 DISALLOW_COPY_AND_ASSIGN(Mp2tStreamParser); | 179 DISALLOW_COPY_AND_ASSIGN(Mp2tStreamParser); |
165 }; | 180 }; |
166 | 181 |
167 } // namespace mp2t | 182 } // namespace mp2t |
168 } // namespace media | 183 } // namespace media |
169 | 184 |
170 #endif // MEDIA_FORMATS_MP2T_MP2T_STREAM_PARSER_H_ | 185 #endif // MEDIA_FORMATS_MP2T_MP2T_STREAM_PARSER_H_ |
OLD | NEW |