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