| 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/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(const BufferQueueWithConfig& other); | 60 BufferQueueWithConfig(const BufferQueueWithConfig& other); |
| 56 ~BufferQueueWithConfig(); | 61 ~BufferQueueWithConfig(); |
| 57 | 62 |
| 58 bool is_config_sent; | 63 bool is_config_sent; |
| 59 AudioDecoderConfig audio_config; | 64 AudioDecoderConfig audio_config; |
| 60 StreamParser::BufferQueue audio_queue; | 65 StreamParser::BufferQueue audio_queue; |
| 61 VideoDecoderConfig video_config; | 66 VideoDecoderConfig video_config; |
| 62 StreamParser::BufferQueue video_queue; | 67 StreamParser::BufferQueue video_queue; |
| 63 }; | 68 }; |
| 64 | 69 |
| 65 // Callback invoked to register a Program Map Table. | 70 // Callback invoked to register a Program Map Table. |
| 66 // Note: Does nothing if the PID is already registered. | 71 // Note: Does nothing if the PID is already registered. |
| 67 void RegisterPmt(int program_number, int pmt_pid); | 72 void RegisterPmt(int program_number, int pmt_pid); |
| 68 | 73 |
| 69 // Callback invoked to register a PES pid. | 74 // Callback invoked to register a PES pid. |
| 70 // Possible values for |stream_type| are defined in: | 75 // Possible values for |stream_type| are defined in: |
| 71 // ISO-13818.1 / ITU H.222 Table 2.34 "Stream type assignments". | 76 // ISO-13818.1 / ITU H.222 Table 2.34 "Stream type assignments". |
| 72 // |pes_pid| is part of the Program Map Table refered by |pmt_pid|. | 77 // |pes_pid| is part of the Program Map Table refered by |pmt_pid|. |
| 73 void RegisterPes(int pmt_pid, int pes_pid, int stream_type); | 78 // Some stream types are qualified by additional |descriptors|. |
| 79 void RegisterPes(int pmt_pid, |
| 80 int pes_pid, |
| 81 int stream_type, |
| 82 const Descriptors& descriptors); |
| 74 | 83 |
| 75 // Since the StreamParser interface allows only one audio & video streams, | 84 // Since the StreamParser interface allows only one audio & video streams, |
| 76 // an automatic PID filtering should be applied to select the audio & video | 85 // an automatic PID filtering should be applied to select the audio & video |
| 77 // streams. | 86 // streams. |
| 78 void UpdatePidFilter(); | 87 void UpdatePidFilter(); |
| 79 | 88 |
| 80 // Callback invoked each time the audio/video decoder configuration is | 89 // Callback invoked each time the audio/video decoder configuration is |
| 81 // changed. | 90 // changed. |
| 82 void OnVideoConfigChanged(int pes_pid, | 91 void OnVideoConfigChanged(int pes_pid, |
| 83 const VideoDecoderConfig& video_decoder_config); | 92 const VideoDecoderConfig& video_decoder_config); |
| 84 void OnAudioConfigChanged(int pes_pid, | 93 void OnAudioConfigChanged(int pes_pid, |
| 85 const AudioDecoderConfig& audio_decoder_config); | 94 const AudioDecoderConfig& audio_decoder_config); |
| 86 | 95 |
| 87 // Invoke the initialization callback if needed. | 96 // Invoke the initialization callback if needed. |
| 88 bool FinishInitializationIfNeeded(); | 97 bool FinishInitializationIfNeeded(); |
| 89 | 98 |
| 90 // Callback invoked by the ES stream parser | 99 // Callback invoked by the ES stream parser |
| 91 // to emit a new audio/video access unit. | 100 // to emit a new audio/video access unit. |
| 92 void OnEmitAudioBuffer( | 101 void OnEmitAudioBuffer( |
| 93 int pes_pid, | 102 int pes_pid, |
| 94 scoped_refptr<StreamParserBuffer> stream_parser_buffer); | 103 scoped_refptr<StreamParserBuffer> stream_parser_buffer); |
| 95 void OnEmitVideoBuffer( | 104 void OnEmitVideoBuffer( |
| 96 int pes_pid, | 105 int pes_pid, |
| 97 scoped_refptr<StreamParserBuffer> stream_parser_buffer); | 106 scoped_refptr<StreamParserBuffer> stream_parser_buffer); |
| 98 bool EmitRemainingBuffers(); | 107 bool EmitRemainingBuffers(); |
| 99 | 108 |
| 109 #if BUILDFLAG(ENABLE_HLS_SAMPLE_AES) |
| 110 // Register the parser for CA Table. |
| 111 PidMap::iterator RegisterCat(); |
| 112 void UnregisterCat(); |
| 113 |
| 114 // Register the PIDs for the Cenc packets (CENC-ECM and CENC-PSSH). |
| 115 void RegisterCencPids(int ca_pid, int pssh_pid); |
| 116 void UnregisterCencPids(); |
| 117 |
| 118 // Register the DecryptConfig (parsed from CENC-ECM). |
| 119 void RegisterDecryptConfig(const DecryptConfig& config); |
| 120 |
| 121 // Register the PSSH (parsed from CENC-PSSH). |
| 122 void RegisterPsshBoxes(const std::vector<uint8_t>& init_data); |
| 123 |
| 124 const DecryptConfig* GetDecryptConfig() { return decrypt_config_.get(); } |
| 125 #endif |
| 126 |
| 100 // List of callbacks. | 127 // List of callbacks. |
| 101 InitCB init_cb_; | 128 InitCB init_cb_; |
| 102 NewConfigCB config_cb_; | 129 NewConfigCB config_cb_; |
| 103 NewBuffersCB new_buffers_cb_; | 130 NewBuffersCB new_buffers_cb_; |
| 104 EncryptedMediaInitDataCB encrypted_media_init_data_cb_; | 131 EncryptedMediaInitDataCB encrypted_media_init_data_cb_; |
| 105 NewMediaSegmentCB new_segment_cb_; | 132 NewMediaSegmentCB new_segment_cb_; |
| 106 EndMediaSegmentCB end_of_segment_cb_; | 133 EndMediaSegmentCB end_of_segment_cb_; |
| 107 scoped_refptr<MediaLog> media_log_; | 134 scoped_refptr<MediaLog> media_log_; |
| 108 | 135 |
| 109 // True when AAC SBR extension is signalled in the mimetype | 136 // True when AAC SBR extension is signalled in the mimetype |
| (...skipping 17 matching lines...) Expand all Loading... |
| 127 bool is_initialized_; | 154 bool is_initialized_; |
| 128 | 155 |
| 129 // Indicate whether a segment was started. | 156 // Indicate whether a segment was started. |
| 130 bool segment_started_; | 157 bool segment_started_; |
| 131 | 158 |
| 132 // Timestamp unroller. | 159 // Timestamp unroller. |
| 133 // Timestamps in PES packets must be unrolled using the same offset. | 160 // Timestamps in PES packets must be unrolled using the same offset. |
| 134 // So the unroller is global between PES pids. | 161 // So the unroller is global between PES pids. |
| 135 TimestampUnroller timestamp_unroller_; | 162 TimestampUnroller timestamp_unroller_; |
| 136 | 163 |
| 164 #if BUILDFLAG(ENABLE_HLS_SAMPLE_AES) |
| 165 std::unique_ptr<DecryptConfig> decrypt_config_; |
| 166 #endif |
| 167 |
| 137 DISALLOW_COPY_AND_ASSIGN(Mp2tStreamParser); | 168 DISALLOW_COPY_AND_ASSIGN(Mp2tStreamParser); |
| 138 }; | 169 }; |
| 139 | 170 |
| 140 } // namespace mp2t | 171 } // namespace mp2t |
| 141 } // namespace media | 172 } // namespace media |
| 142 | 173 |
| 143 #endif | 174 #endif |
| 144 | 175 |
| OLD | NEW |