| 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 <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 initialization data. |
| 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 Loading... |
| 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 encryption_key_id_; |
| 134 |
| 124 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxerStream); | 135 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxerStream); |
| 125 }; | 136 }; |
| 126 | 137 |
| 127 class MEDIA_EXPORT FFmpegDemuxer : public Demuxer { | 138 class MEDIA_EXPORT FFmpegDemuxer : public Demuxer { |
| 128 public: | 139 public: |
| 129 FFmpegDemuxer(const scoped_refptr<base::MessageLoopProxy>& message_loop, | 140 FFmpegDemuxer(const scoped_refptr<base::MessageLoopProxy>& message_loop, |
| 130 const scoped_refptr<DataSource>& data_source); | 141 const scoped_refptr<DataSource>& data_source, |
| 142 const FFmpegNeedKeyCB& need_key_cb); |
| 131 | 143 |
| 132 // Demuxer implementation. | 144 // Demuxer implementation. |
| 133 virtual void Initialize(DemuxerHost* host, | 145 virtual void Initialize(DemuxerHost* host, |
| 134 const PipelineStatusCB& status_cb) OVERRIDE; | 146 const PipelineStatusCB& status_cb) OVERRIDE; |
| 135 virtual void Stop(const base::Closure& callback) OVERRIDE; | 147 virtual void Stop(const base::Closure& callback) OVERRIDE; |
| 136 virtual void Seek(base::TimeDelta time, const PipelineStatusCB& cb) OVERRIDE; | 148 virtual void Seek(base::TimeDelta time, const PipelineStatusCB& cb) OVERRIDE; |
| 137 virtual void OnAudioRendererDisabled() OVERRIDE; | 149 virtual void OnAudioRendererDisabled() OVERRIDE; |
| 138 virtual void SetPlaybackRate(float playback_rate) OVERRIDE; | 150 virtual void SetPlaybackRate(float playback_rate) OVERRIDE; |
| 139 virtual scoped_refptr<DemuxerStream> GetStream( | 151 virtual scoped_refptr<DemuxerStream> GetStream( |
| 140 DemuxerStream::Type type) OVERRIDE; | 152 DemuxerStream::Type type) OVERRIDE; |
| 141 virtual base::TimeDelta GetStartTime() const OVERRIDE; | 153 virtual base::TimeDelta GetStartTime() const OVERRIDE; |
| 142 | 154 |
| 155 // Calls |need_key_cb_| with the initialization data encountered in the file. |
| 156 void FireNeedKey(const std::string& init_data_type, |
| 157 const std::string& encryption_key_id); |
| 158 |
| 143 // Allow FFmpegDemuxerStream to notify us when there is updated information | 159 // Allow FFmpegDemuxerStream to notify us when there is updated information |
| 144 // about capacity and what buffered data is available. | 160 // about capacity and what buffered data is available. |
| 145 void NotifyCapacityAvailable(); | 161 void NotifyCapacityAvailable(); |
| 146 void NotifyBufferingChanged(); | 162 void NotifyBufferingChanged(); |
| 147 | 163 |
| 148 private: | 164 private: |
| 149 // To allow tests access to privates. | 165 // To allow tests access to privates. |
| 150 friend class FFmpegDemuxerTest; | 166 friend class FFmpegDemuxerTest; |
| 151 | 167 |
| 152 virtual ~FFmpegDemuxer(); | 168 virtual ~FFmpegDemuxer(); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 bool audio_disabled_; | 242 bool audio_disabled_; |
| 227 | 243 |
| 228 // Set if we know duration of the audio stream. Used when processing end of | 244 // Set if we know duration of the audio stream. Used when processing end of |
| 229 // stream -- at this moment we definitely know duration. | 245 // stream -- at this moment we definitely know duration. |
| 230 bool duration_known_; | 246 bool duration_known_; |
| 231 | 247 |
| 232 // FFmpegURLProtocol implementation and corresponding glue bits. | 248 // FFmpegURLProtocol implementation and corresponding glue bits. |
| 233 BlockingUrlProtocol url_protocol_; | 249 BlockingUrlProtocol url_protocol_; |
| 234 scoped_ptr<FFmpegGlue> glue_; | 250 scoped_ptr<FFmpegGlue> glue_; |
| 235 | 251 |
| 252 const FFmpegNeedKeyCB need_key_cb_; |
| 253 |
| 236 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxer); | 254 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxer); |
| 237 }; | 255 }; |
| 238 | 256 |
| 239 } // namespace media | 257 } // namespace media |
| 240 | 258 |
| 241 #endif // MEDIA_FILTERS_FFMPEG_DEMUXER_H_ | 259 #endif // MEDIA_FILTERS_FFMPEG_DEMUXER_H_ |
| OLD | NEW |