OLD | NEW |
---|---|
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 <deque> | 25 #include <deque> |
26 #include <string> | |
26 #include <vector> | 27 #include <vector> |
27 | 28 |
28 #include "base/callback.h" | 29 #include "base/callback.h" |
29 #include "base/gtest_prod_util.h" | 30 #include "base/gtest_prod_util.h" |
30 #include "base/synchronization/waitable_event.h" | 31 #include "base/synchronization/waitable_event.h" |
31 #include "media/base/audio_decoder_config.h" | 32 #include "media/base/audio_decoder_config.h" |
32 #include "media/base/decoder_buffer.h" | 33 #include "media/base/decoder_buffer.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/ffmpeg_glue.h" | 37 #include "media/filters/ffmpeg_glue.h" |
37 | 38 |
38 // FFmpeg forward declarations. | 39 // FFmpeg forward declarations. |
39 struct AVFormatContext; | 40 struct AVFormatContext; |
40 struct AVPacket; | 41 struct AVPacket; |
41 struct AVRational; | 42 struct AVRational; |
42 struct AVStream; | 43 struct AVStream; |
43 | 44 |
44 namespace media { | 45 namespace media { |
45 | 46 |
47 // A new potentially encrypted stream has been parsed. | |
48 // First parameter - The initialization data associated with the stream. | |
49 // Second parameter - Number of bytes of the initialization data. | |
50 typedef base::Callback<void(scoped_array<uint8>, int)> FFmpegNeedKeyCB; | |
xhwang
2012/08/29 05:08:14
Move this typedef into FFmpegDemuxer and rename it
ddorwin
2012/09/01 16:46:41
We're going to eliminate this and replace it with
fgalligan1
2013/03/09 01:10:59
What should I do with this at this point?
| |
51 | |
46 class FFmpegDemuxer; | 52 class FFmpegDemuxer; |
47 class FFmpegH264ToAnnexBBitstreamConverter; | 53 class FFmpegH264ToAnnexBBitstreamConverter; |
48 class ScopedPtrAVFreePacket; | 54 class ScopedPtrAVFreePacket; |
49 | 55 |
50 class FFmpegDemuxerStream : public DemuxerStream { | 56 class FFmpegDemuxerStream : public DemuxerStream { |
51 public: | 57 public: |
52 // Keeps a copy of |demuxer| and initializes itself using information | 58 // Keeps a copy of |demuxer| and initializes itself using information |
53 // inside |stream|. Both parameters must outlive |this|. | 59 // inside |stream|. Both parameters must outlive |this|. |
54 FFmpegDemuxerStream(FFmpegDemuxer* demuxer, AVStream* stream); | 60 FFmpegDemuxerStream(FFmpegDemuxer* demuxer, AVStream* stream); |
55 | 61 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
121 Ranges<base::TimeDelta> buffered_ranges_; | 127 Ranges<base::TimeDelta> buffered_ranges_; |
122 | 128 |
123 typedef std::deque<scoped_refptr<DecoderBuffer> > BufferQueue; | 129 typedef std::deque<scoped_refptr<DecoderBuffer> > BufferQueue; |
124 BufferQueue buffer_queue_; | 130 BufferQueue buffer_queue_; |
125 | 131 |
126 typedef std::deque<ReadCB> ReadQueue; | 132 typedef std::deque<ReadCB> ReadQueue; |
127 ReadQueue read_queue_; | 133 ReadQueue read_queue_; |
128 | 134 |
129 scoped_ptr<FFmpegH264ToAnnexBBitstreamConverter> bitstream_converter_; | 135 scoped_ptr<FFmpegH264ToAnnexBBitstreamConverter> bitstream_converter_; |
130 | 136 |
137 std::string current_key_id_; | |
138 | |
131 // Used to synchronize access to |buffer_queue_|, |read_queue_|, and | 139 // Used to synchronize access to |buffer_queue_|, |read_queue_|, and |
132 // |stopped_|. This is so other threads can get access to buffers that have | 140 // |stopped_|. This is so other threads can get access to buffers that have |
133 // already been demuxed without having the demuxer thread sending the | 141 // already been demuxed without having the demuxer thread sending the |
134 // buffers. |lock_| must be acquired before any access to |buffer_queue_|, | 142 // buffers. |lock_| must be acquired before any access to |buffer_queue_|, |
135 // |read_queue_|, or |stopped_|. | 143 // |read_queue_|, or |stopped_|. |
136 mutable base::Lock lock_; | 144 mutable base::Lock lock_; |
137 | 145 |
138 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxerStream); | 146 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxerStream); |
139 }; | 147 }; |
140 | 148 |
141 class MEDIA_EXPORT FFmpegDemuxer : public Demuxer, public FFmpegURLProtocol { | 149 class MEDIA_EXPORT FFmpegDemuxer : public Demuxer, public FFmpegURLProtocol { |
142 public: | 150 public: |
143 FFmpegDemuxer(const scoped_refptr<base::MessageLoopProxy>& message_loop, | 151 FFmpegDemuxer(const scoped_refptr<base::MessageLoopProxy>& message_loop, |
144 const scoped_refptr<DataSource>& data_source); | 152 const scoped_refptr<DataSource>& data_source, |
153 const FFmpegNeedKeyCB& need_key_cb); | |
145 | 154 |
146 // Posts a task to perform additional demuxing. | 155 // Posts a task to perform additional demuxing. |
147 virtual void PostDemuxTask(); | 156 virtual void PostDemuxTask(); |
148 | 157 |
149 // Demuxer implementation. | 158 // Demuxer implementation. |
150 virtual void Initialize(DemuxerHost* host, | 159 virtual void Initialize(DemuxerHost* host, |
151 const PipelineStatusCB& status_cb) OVERRIDE; | 160 const PipelineStatusCB& status_cb) OVERRIDE; |
152 virtual void Stop(const base::Closure& callback) OVERRIDE; | 161 virtual void Stop(const base::Closure& callback) OVERRIDE; |
153 virtual void Seek(base::TimeDelta time, const PipelineStatusCB& cb) OVERRIDE; | 162 virtual void Seek(base::TimeDelta time, const PipelineStatusCB& cb) OVERRIDE; |
154 virtual void OnAudioRendererDisabled() OVERRIDE; | 163 virtual void OnAudioRendererDisabled() OVERRIDE; |
155 virtual void SetPlaybackRate(float playback_rate) OVERRIDE; | 164 virtual void SetPlaybackRate(float playback_rate) OVERRIDE; |
156 virtual scoped_refptr<DemuxerStream> GetStream( | 165 virtual scoped_refptr<DemuxerStream> GetStream( |
157 DemuxerStream::Type type) OVERRIDE; | 166 DemuxerStream::Type type) OVERRIDE; |
158 virtual base::TimeDelta GetStartTime() const OVERRIDE; | 167 virtual base::TimeDelta GetStartTime() const OVERRIDE; |
159 | 168 |
160 // FFmpegURLProtocol implementation. | 169 // FFmpegURLProtocol implementation. |
161 virtual size_t Read(size_t size, uint8* data) OVERRIDE; | 170 virtual size_t Read(size_t size, uint8* data) OVERRIDE; |
162 virtual bool GetPosition(int64* position_out) OVERRIDE; | 171 virtual bool GetPosition(int64* position_out) OVERRIDE; |
163 virtual bool SetPosition(int64 position) OVERRIDE; | 172 virtual bool SetPosition(int64 position) OVERRIDE; |
164 virtual bool GetSize(int64* size_out) OVERRIDE; | 173 virtual bool GetSize(int64* size_out) OVERRIDE; |
165 virtual bool IsStreaming() OVERRIDE; | 174 virtual bool IsStreaming() OVERRIDE; |
166 | 175 |
167 // Provide access to FFmpegDemuxerStream. | 176 // Provide access to FFmpegDemuxerStream. |
168 scoped_refptr<base::MessageLoopProxy> message_loop(); | 177 scoped_refptr<base::MessageLoopProxy> message_loop(); |
169 | 178 |
179 void NeedKey(const std::string& key_id); | |
180 | |
170 // Allow FFmpegDemuxerStream to notify us when there is updated information | 181 // Allow FFmpegDemuxerStream to notify us when there is updated information |
171 // about what buffered data is available. | 182 // about what buffered data is available. |
172 void NotifyBufferingChanged(); | 183 void NotifyBufferingChanged(); |
173 | 184 |
174 private: | 185 private: |
175 // To allow tests access to privates. | 186 // To allow tests access to privates. |
176 friend class FFmpegDemuxerTest; | 187 friend class FFmpegDemuxerTest; |
177 | 188 |
178 virtual ~FFmpegDemuxer(); | 189 virtual ~FFmpegDemuxer(); |
179 | 190 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
260 base::TimeDelta start_time_; | 271 base::TimeDelta start_time_; |
261 | 272 |
262 // Whether audio has been disabled for this demuxer (in which case this class | 273 // Whether audio has been disabled for this demuxer (in which case this class |
263 // drops packets destined for AUDIO demuxer streams on the floor). | 274 // drops packets destined for AUDIO demuxer streams on the floor). |
264 bool audio_disabled_; | 275 bool audio_disabled_; |
265 | 276 |
266 // Set if we know duration of the audio stream. Used when processing end of | 277 // Set if we know duration of the audio stream. Used when processing end of |
267 // stream -- at this moment we definitely know duration. | 278 // stream -- at this moment we definitely know duration. |
268 bool duration_known_; | 279 bool duration_known_; |
269 | 280 |
281 const FFmpegNeedKeyCB need_key_cb_; | |
282 | |
270 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxer); | 283 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxer); |
271 }; | 284 }; |
272 | 285 |
273 } // namespace media | 286 } // namespace media |
274 | 287 |
275 #endif // MEDIA_FILTERS_FFMPEG_DEMUXER_H_ | 288 #endif // MEDIA_FILTERS_FFMPEG_DEMUXER_H_ |
OLD | NEW |