| 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 // |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 | 27 |
| 28 #include "base/callback.h" | 28 #include "base/callback.h" |
| 29 #include "base/gtest_prod_util.h" | 29 #include "base/gtest_prod_util.h" |
| 30 #include "base/memory/scoped_vector.h" | 30 #include "base/memory/scoped_vector.h" |
| 31 #include "base/threading/thread.h" | 31 #include "base/threading/thread.h" |
| 32 #include "media/base/audio_decoder_config.h" | 32 #include "media/base/audio_decoder_config.h" |
| 33 #include "media/base/decoder_buffer.h" | 33 #include "media/base/decoder_buffer.h" |
| 34 #include "media/base/decoder_buffer_queue.h" | 34 #include "media/base/decoder_buffer_queue.h" |
| 35 #include "media/base/demuxer.h" | 35 #include "media/base/demuxer.h" |
| 36 #include "media/base/pipeline.h" | 36 #include "media/base/pipeline.h" |
| 37 #include "media/base/text_track_config.h" |
| 37 #include "media/base/video_decoder_config.h" | 38 #include "media/base/video_decoder_config.h" |
| 38 #include "media/filters/blocking_url_protocol.h" | 39 #include "media/filters/blocking_url_protocol.h" |
| 39 | 40 |
| 40 // FFmpeg forward declarations. | 41 // FFmpeg forward declarations. |
| 41 struct AVPacket; | 42 struct AVPacket; |
| 42 struct AVRational; | 43 struct AVRational; |
| 43 struct AVStream; | 44 struct AVStream; |
| 44 | 45 |
| 45 namespace media { | 46 namespace media { |
| 46 | 47 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 // Returns the range of buffered data in this stream. | 87 // Returns the range of buffered data in this stream. |
| 87 Ranges<base::TimeDelta> GetBufferedRanges() const; | 88 Ranges<base::TimeDelta> GetBufferedRanges() const; |
| 88 | 89 |
| 89 // Returns elapsed time based on the already queued packets. | 90 // Returns elapsed time based on the already queued packets. |
| 90 // Used to determine stream duration when it's not known ahead of time. | 91 // Used to determine stream duration when it's not known ahead of time. |
| 91 base::TimeDelta GetElapsedTime() const; | 92 base::TimeDelta GetElapsedTime() const; |
| 92 | 93 |
| 93 // Returns true if this stream has capacity for additional data. | 94 // Returns true if this stream has capacity for additional data. |
| 94 bool HasAvailableCapacity(); | 95 bool HasAvailableCapacity(); |
| 95 | 96 |
| 97 TextKind GetTextKind() const; |
| 98 |
| 99 // Returns the value associated with |key| in the metadata for the avstream. |
| 100 // Returns an empty string if the key is not present. |
| 101 std::string GetMetadata(const char* key) const; |
| 102 |
| 96 private: | 103 private: |
| 97 friend class FFmpegDemuxerTest; | 104 friend class FFmpegDemuxerTest; |
| 98 | 105 |
| 99 // Runs |read_cb_| if present with the front of |buffer_queue_|, calling | 106 // Runs |read_cb_| if present with the front of |buffer_queue_|, calling |
| 100 // NotifyCapacityAvailable() if capacity is still available. | 107 // NotifyCapacityAvailable() if capacity is still available. |
| 101 void SatisfyPendingRead(); | 108 void SatisfyPendingRead(); |
| 102 | 109 |
| 103 // Converts an FFmpeg stream timestamp into a base::TimeDelta. | 110 // Converts an FFmpeg stream timestamp into a base::TimeDelta. |
| 104 static base::TimeDelta ConvertStreamTimestamp(const AVRational& time_base, | 111 static base::TimeDelta ConvertStreamTimestamp(const AVRational& time_base, |
| 105 int64 timestamp); | 112 int64 timestamp); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 129 class MEDIA_EXPORT FFmpegDemuxer : public Demuxer { | 136 class MEDIA_EXPORT FFmpegDemuxer : public Demuxer { |
| 130 public: | 137 public: |
| 131 FFmpegDemuxer(const scoped_refptr<base::MessageLoopProxy>& message_loop, | 138 FFmpegDemuxer(const scoped_refptr<base::MessageLoopProxy>& message_loop, |
| 132 DataSource* data_source, | 139 DataSource* data_source, |
| 133 const NeedKeyCB& need_key_cb, | 140 const NeedKeyCB& need_key_cb, |
| 134 const scoped_refptr<MediaLog>& media_log); | 141 const scoped_refptr<MediaLog>& media_log); |
| 135 virtual ~FFmpegDemuxer(); | 142 virtual ~FFmpegDemuxer(); |
| 136 | 143 |
| 137 // Demuxer implementation. | 144 // Demuxer implementation. |
| 138 virtual void Initialize(DemuxerHost* host, | 145 virtual void Initialize(DemuxerHost* host, |
| 139 const PipelineStatusCB& status_cb) OVERRIDE; | 146 const PipelineStatusCB& status_cb, |
| 147 bool enable_text_tracks) OVERRIDE; |
| 140 virtual void Stop(const base::Closure& callback) OVERRIDE; | 148 virtual void Stop(const base::Closure& callback) OVERRIDE; |
| 141 virtual void Seek(base::TimeDelta time, const PipelineStatusCB& cb) OVERRIDE; | 149 virtual void Seek(base::TimeDelta time, const PipelineStatusCB& cb) OVERRIDE; |
| 142 virtual void OnAudioRendererDisabled() OVERRIDE; | 150 virtual void OnAudioRendererDisabled() OVERRIDE; |
| 143 virtual DemuxerStream* GetStream(DemuxerStream::Type type) OVERRIDE; | 151 virtual DemuxerStream* GetStream(DemuxerStream::Type type) OVERRIDE; |
| 144 virtual base::TimeDelta GetStartTime() const OVERRIDE; | 152 virtual base::TimeDelta GetStartTime() const OVERRIDE; |
| 145 | 153 |
| 146 // Calls |need_key_cb_| with the initialization data encountered in the file. | 154 // Calls |need_key_cb_| with the initialization data encountered in the file. |
| 147 void FireNeedKey(const std::string& init_data_type, | 155 void FireNeedKey(const std::string& init_data_type, |
| 148 const std::string& encryption_key_id); | 156 const std::string& encryption_key_id); |
| 149 | 157 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 177 // Signal all FFmpegDemuxerStreams that the stream has ended. | 185 // Signal all FFmpegDemuxerStreams that the stream has ended. |
| 178 void StreamHasEnded(); | 186 void StreamHasEnded(); |
| 179 | 187 |
| 180 // Called by |url_protocol_| whenever |data_source_| returns a read error. | 188 // Called by |url_protocol_| whenever |data_source_| returns a read error. |
| 181 void OnDataSourceError(); | 189 void OnDataSourceError(); |
| 182 | 190 |
| 183 // Returns the stream from |streams_| that matches |type| as an | 191 // Returns the stream from |streams_| that matches |type| as an |
| 184 // FFmpegDemuxerStream. | 192 // FFmpegDemuxerStream. |
| 185 FFmpegDemuxerStream* GetFFmpegStream(DemuxerStream::Type type) const; | 193 FFmpegDemuxerStream* GetFFmpegStream(DemuxerStream::Type type) const; |
| 186 | 194 |
| 195 // Called after the streams have been collected from the media, to allow |
| 196 // the text renderer to bind each text stream to the cue rendering engine. |
| 197 void AddTextStreams(); |
| 198 |
| 187 DemuxerHost* host_; | 199 DemuxerHost* host_; |
| 188 | 200 |
| 189 scoped_refptr<base::MessageLoopProxy> message_loop_; | 201 scoped_refptr<base::MessageLoopProxy> message_loop_; |
| 190 base::WeakPtrFactory<FFmpegDemuxer> weak_factory_; | 202 base::WeakPtrFactory<FFmpegDemuxer> weak_factory_; |
| 191 base::WeakPtr<FFmpegDemuxer> weak_this_; | 203 base::WeakPtr<FFmpegDemuxer> weak_this_; |
| 192 | 204 |
| 193 // Thread on which all blocking FFmpeg operations are executed. | 205 // Thread on which all blocking FFmpeg operations are executed. |
| 194 base::Thread blocking_thread_; | 206 base::Thread blocking_thread_; |
| 195 | 207 |
| 196 // Tracks if there's an outstanding av_read_frame() operation. | 208 // Tracks if there's an outstanding av_read_frame() operation. |
| (...skipping 29 matching lines...) Expand all Loading... |
| 226 | 238 |
| 227 // The first timestamp of the opened media file. This is used to set the | 239 // The first timestamp of the opened media file. This is used to set the |
| 228 // starting clock value to match the timestamps in the media file. Default | 240 // starting clock value to match the timestamps in the media file. Default |
| 229 // is 0. | 241 // is 0. |
| 230 base::TimeDelta start_time_; | 242 base::TimeDelta start_time_; |
| 231 | 243 |
| 232 // Whether audio has been disabled for this demuxer (in which case this class | 244 // Whether audio has been disabled for this demuxer (in which case this class |
| 233 // drops packets destined for AUDIO demuxer streams on the floor). | 245 // drops packets destined for AUDIO demuxer streams on the floor). |
| 234 bool audio_disabled_; | 246 bool audio_disabled_; |
| 235 | 247 |
| 248 // Whether text streams have been enabled for this demuxer. |
| 249 bool text_enabled_; |
| 250 |
| 236 // Set if we know duration of the audio stream. Used when processing end of | 251 // Set if we know duration of the audio stream. Used when processing end of |
| 237 // stream -- at this moment we definitely know duration. | 252 // stream -- at this moment we definitely know duration. |
| 238 bool duration_known_; | 253 bool duration_known_; |
| 239 | 254 |
| 240 // FFmpegURLProtocol implementation and corresponding glue bits. | 255 // FFmpegURLProtocol implementation and corresponding glue bits. |
| 241 BlockingUrlProtocol url_protocol_; | 256 BlockingUrlProtocol url_protocol_; |
| 242 scoped_ptr<FFmpegGlue> glue_; | 257 scoped_ptr<FFmpegGlue> glue_; |
| 243 | 258 |
| 244 const NeedKeyCB need_key_cb_; | 259 const NeedKeyCB need_key_cb_; |
| 245 | 260 |
| 246 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxer); | 261 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxer); |
| 247 }; | 262 }; |
| 248 | 263 |
| 249 } // namespace media | 264 } // namespace media |
| 250 | 265 |
| 251 #endif // MEDIA_FILTERS_FFMPEG_DEMUXER_H_ | 266 #endif // MEDIA_FILTERS_FFMPEG_DEMUXER_H_ |
| OLD | NEW |