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

Side by Side Diff: media/filters/ffmpeg_demuxer.h

Issue 10829470: Support for parsing encrypted WebM streams by src. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase code. Add support for audio. Created 7 years, 9 months 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // Implements the Demuxer interface using FFmpeg's libavformat. At this time 5 // Implements the Demuxer interface using FFmpeg's libavformat. At this time
6 // will support demuxing any audio/video format thrown at it. The streams 6 // will support demuxing any audio/video format thrown at it. The streams
7 // output mime types audio/x-ffmpeg and video/x-ffmpeg and include an integer 7 // output mime types audio/x-ffmpeg and video/x-ffmpeg and include an integer
8 // key FFmpegCodecID which contains the CodecID enumeration value. The CodecIDs 8 // key FFmpegCodecID which contains the CodecID enumeration value. The CodecIDs
9 // can be used to create and initialize the corresponding FFmpeg decoder. 9 // can be used to create and initialize the corresponding FFmpeg decoder.
10 // 10 //
11 // FFmpegDemuxer sets the duration of pipeline during initialization by using 11 // FFmpegDemuxer sets the duration of pipeline during initialization by using
12 // the duration of the longest audio/video stream. 12 // the duration of the longest audio/video stream.
13 // 13 //
14 // NOTE: since FFmpegDemuxer reads packets sequentially without seeking, media 14 // NOTE: since FFmpegDemuxer reads packets sequentially without seeking, media
15 // files with very large drift between audio/video streams may result in 15 // files with very large drift between audio/video streams may result in
16 // excessive memory consumption. 16 // excessive memory consumption.
17 // 17 //
18 // When stopped, FFmpegDemuxer and FFmpegDemuxerStream release all callbacks 18 // When stopped, FFmpegDemuxer and FFmpegDemuxerStream release all callbacks
19 // and buffered packets. Reads from a stopped FFmpegDemuxerStream will not be 19 // and buffered packets. Reads from a stopped FFmpegDemuxerStream will not be
20 // replied to. 20 // replied to.
21 21
22 #ifndef MEDIA_FILTERS_FFMPEG_DEMUXER_H_ 22 #ifndef MEDIA_FILTERS_FFMPEG_DEMUXER_H_
23 #define MEDIA_FILTERS_FFMPEG_DEMUXER_H_ 23 #define MEDIA_FILTERS_FFMPEG_DEMUXER_H_
24 24
25 #include <string>
25 #include <vector> 26 #include <vector>
26 27
27 #include "base/callback.h" 28 #include "base/callback.h"
28 #include "base/gtest_prod_util.h" 29 #include "base/gtest_prod_util.h"
29 #include "base/threading/thread.h" 30 #include "base/threading/thread.h"
30 #include "media/base/audio_decoder_config.h" 31 #include "media/base/audio_decoder_config.h"
31 #include "media/base/decoder_buffer.h" 32 #include "media/base/decoder_buffer.h"
32 #include "media/base/decoder_buffer_queue.h" 33 #include "media/base/decoder_buffer_queue.h"
33 #include "media/base/demuxer.h" 34 #include "media/base/demuxer.h"
34 #include "media/base/pipeline.h" 35 #include "media/base/pipeline.h"
35 #include "media/base/video_decoder_config.h" 36 #include "media/base/video_decoder_config.h"
36 #include "media/filters/blocking_url_protocol.h" 37 #include "media/filters/blocking_url_protocol.h"
37 38
38 // FFmpeg forward declarations. 39 // FFmpeg forward declarations.
39 struct AVPacket; 40 struct AVPacket;
40 struct AVRational; 41 struct AVRational;
41 struct AVStream; 42 struct AVStream;
42 43
43 namespace media { 44 namespace media {
44 45
46 // A new potentially encrypted stream has been parsed.
47 // First parameter - The type of encryption.
ddorwin 2013/03/10 21:29:39 s/encryption/initialization data/
fgalligan1 2013/03/12 00:42:42 Done.
48 // Second parameter - The initialization data associated with the stream.
49 // Third parameter - Number of bytes of the initialization data.
50 typedef base::Callback<void(const std::string& type,
51 scoped_array<uint8> init_data,
52 int init_data_size)> FFmpegNeedKeyCB;
53
45 class FFmpegDemuxer; 54 class FFmpegDemuxer;
46 class FFmpegGlue; 55 class FFmpegGlue;
47 class FFmpegH264ToAnnexBBitstreamConverter; 56 class FFmpegH264ToAnnexBBitstreamConverter;
48 class ScopedPtrAVFreePacket; 57 class ScopedPtrAVFreePacket;
49 58
50 typedef scoped_ptr_malloc<AVPacket, ScopedPtrAVFreePacket> ScopedAVPacket; 59 typedef scoped_ptr_malloc<AVPacket, ScopedPtrAVFreePacket> ScopedAVPacket;
51 60
52 class FFmpegDemuxerStream : public DemuxerStream { 61 class FFmpegDemuxerStream : public DemuxerStream {
53 public: 62 public:
54 // Keeps a copy of |demuxer| and initializes itself using information 63 // Keeps a copy of |demuxer| and initializes itself using information
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 bool end_of_stream_; 123 bool end_of_stream_;
115 base::TimeDelta last_packet_timestamp_; 124 base::TimeDelta last_packet_timestamp_;
116 Ranges<base::TimeDelta> buffered_ranges_; 125 Ranges<base::TimeDelta> buffered_ranges_;
117 126
118 DecoderBufferQueue buffer_queue_; 127 DecoderBufferQueue buffer_queue_;
119 ReadCB read_cb_; 128 ReadCB read_cb_;
120 129
121 scoped_ptr<FFmpegH264ToAnnexBBitstreamConverter> bitstream_converter_; 130 scoped_ptr<FFmpegH264ToAnnexBBitstreamConverter> bitstream_converter_;
122 bool bitstream_converter_enabled_; 131 bool bitstream_converter_enabled_;
123 132
133 std::string audio_encryption_key_id_;
ddorwin 2013/03/10 21:29:39 A demuxer stream only supports audio or video, rig
fgalligan1 2013/03/12 00:42:42 Done.
134 std::string video_encryption_key_id_;
135
124 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxerStream); 136 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxerStream);
125 }; 137 };
126 138
127 class MEDIA_EXPORT FFmpegDemuxer : public Demuxer { 139 class MEDIA_EXPORT FFmpegDemuxer : public Demuxer {
128 public: 140 public:
129 FFmpegDemuxer(const scoped_refptr<base::MessageLoopProxy>& message_loop, 141 FFmpegDemuxer(const scoped_refptr<base::MessageLoopProxy>& message_loop,
130 const scoped_refptr<DataSource>& data_source); 142 const scoped_refptr<DataSource>& data_source,
143 const FFmpegNeedKeyCB& need_key_cb);
131 144
132 // Demuxer implementation. 145 // Demuxer implementation.
133 virtual void Initialize(DemuxerHost* host, 146 virtual void Initialize(DemuxerHost* host,
134 const PipelineStatusCB& status_cb) OVERRIDE; 147 const PipelineStatusCB& status_cb) OVERRIDE;
135 virtual void Stop(const base::Closure& callback) OVERRIDE; 148 virtual void Stop(const base::Closure& callback) OVERRIDE;
136 virtual void Seek(base::TimeDelta time, const PipelineStatusCB& cb) OVERRIDE; 149 virtual void Seek(base::TimeDelta time, const PipelineStatusCB& cb) OVERRIDE;
137 virtual void OnAudioRendererDisabled() OVERRIDE; 150 virtual void OnAudioRendererDisabled() OVERRIDE;
138 virtual void SetPlaybackRate(float playback_rate) OVERRIDE; 151 virtual void SetPlaybackRate(float playback_rate) OVERRIDE;
139 virtual scoped_refptr<DemuxerStream> GetStream( 152 virtual scoped_refptr<DemuxerStream> GetStream(
140 DemuxerStream::Type type) OVERRIDE; 153 DemuxerStream::Type type) OVERRIDE;
141 virtual base::TimeDelta GetStartTime() const OVERRIDE; 154 virtual base::TimeDelta GetStartTime() const OVERRIDE;
142 155
156 // Calls |need_key_cb_| with the encryption key id of the decryption key
ddorwin 2013/03/10 21:29:39 // Calls |need_key_cb_| with the initialization da
fgalligan1 2013/03/12 00:42:42 Done. I agree.
157 // that is needed.
158 void FireNeedKey(const std::string& init_data_type,
159 const std::string& encryption_key_id);
160
143 // Allow FFmpegDemuxerStream to notify us when there is updated information 161 // Allow FFmpegDemuxerStream to notify us when there is updated information
144 // about capacity and what buffered data is available. 162 // about capacity and what buffered data is available.
145 void NotifyCapacityAvailable(); 163 void NotifyCapacityAvailable();
146 void NotifyBufferingChanged(); 164 void NotifyBufferingChanged();
147 165
148 private: 166 private:
149 // To allow tests access to privates. 167 // To allow tests access to privates.
150 friend class FFmpegDemuxerTest; 168 friend class FFmpegDemuxerTest;
151 169
152 virtual ~FFmpegDemuxer(); 170 virtual ~FFmpegDemuxer();
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 bool audio_disabled_; 244 bool audio_disabled_;
227 245
228 // Set if we know duration of the audio stream. Used when processing end of 246 // Set if we know duration of the audio stream. Used when processing end of
229 // stream -- at this moment we definitely know duration. 247 // stream -- at this moment we definitely know duration.
230 bool duration_known_; 248 bool duration_known_;
231 249
232 // FFmpegURLProtocol implementation and corresponding glue bits. 250 // FFmpegURLProtocol implementation and corresponding glue bits.
233 BlockingUrlProtocol url_protocol_; 251 BlockingUrlProtocol url_protocol_;
234 scoped_ptr<FFmpegGlue> glue_; 252 scoped_ptr<FFmpegGlue> glue_;
235 253
254 const FFmpegNeedKeyCB need_key_cb_;
255
236 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxer); 256 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxer);
237 }; 257 };
238 258
239 } // namespace media 259 } // namespace media
240 260
241 #endif // MEDIA_FILTERS_FFMPEG_DEMUXER_H_ 261 #endif // MEDIA_FILTERS_FFMPEG_DEMUXER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698