Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(159)

Side by Side Diff: media/formats/mp2t/mp2t_stream_parser.h

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

Powered by Google App Engine
This is Rietveld 408576698