| 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 | 48 |
| 49 class MediaLog; | 49 class MediaLog; |
| 50 class FFmpegDemuxer; | 50 class FFmpegDemuxer; |
| 51 class FFmpegGlue; | 51 class FFmpegGlue; |
| 52 class FFmpegH264ToAnnexBBitstreamConverter; | 52 class FFmpegH264ToAnnexBBitstreamConverter; |
| 53 | 53 |
| 54 typedef scoped_ptr<AVPacket, ScopedPtrAVFreePacket> ScopedAVPacket; | 54 typedef scoped_ptr<AVPacket, ScopedPtrAVFreePacket> ScopedAVPacket; |
| 55 | 55 |
| 56 class FFmpegDemuxerStream : public DemuxerStream { | 56 class FFmpegDemuxerStream : public DemuxerStream { |
| 57 public: | 57 public: |
| 58 // Keeps a copy of |demuxer| and initializes itself using information inside | 58 // Keeps a copy of |demuxer| and initializes itself using information |
| 59 // |stream|. Both parameters must outlive |this|. | 59 // inside |stream|. Both parameters must outlive |this|. |
| 60 // |discard_negative_timestamps| tells the DemuxerStream that all packets with | 60 FFmpegDemuxerStream(FFmpegDemuxer* demuxer, AVStream* stream); |
| 61 // negative timestamps should be marked for post-decode discard. All decoded | |
| 62 // data before time zero will be discarded. | |
| 63 FFmpegDemuxerStream(FFmpegDemuxer* demuxer, | |
| 64 AVStream* stream, | |
| 65 bool discard_negative_timestamps); | |
| 66 virtual ~FFmpegDemuxerStream(); | 61 virtual ~FFmpegDemuxerStream(); |
| 67 | 62 |
| 68 // Enqueues the given AVPacket. It is invalid to queue a |packet| after | 63 // Enqueues the given AVPacket. It is invalid to queue a |packet| after |
| 69 // SetEndOfStream() has been called. | 64 // SetEndOfStream() has been called. |
| 70 void EnqueuePacket(ScopedAVPacket packet); | 65 void EnqueuePacket(ScopedAVPacket packet); |
| 71 | 66 |
| 72 // Enters the end of stream state. After delivering remaining queued buffers | 67 // Enters the end of stream state. After delivering remaining queued buffers |
| 73 // only end of stream buffers will be delivered. | 68 // only end of stream buffers will be delivered. |
| 74 void SetEndOfStream(); | 69 void SetEndOfStream(); |
| 75 | 70 |
| 76 // Drops queued buffers and clears end of stream state. | 71 // Drops queued buffers and clears end of stream state. |
| 77 void FlushBuffers(); | 72 void FlushBuffers(); |
| 78 | 73 |
| 79 // Empties the queues and ignores any additional calls to Read(). | 74 // Empties the queues and ignores any additional calls to Read(). |
| 80 void Stop(); | 75 void Stop(); |
| 81 | 76 |
| 82 base::TimeDelta duration() const { return duration_; } | 77 // Returns the duration of this stream. |
| 78 base::TimeDelta duration(); |
| 83 | 79 |
| 84 // DemuxerStream implementation. | 80 // DemuxerStream implementation. |
| 85 virtual Type type() OVERRIDE; | 81 virtual Type type() OVERRIDE; |
| 86 virtual void Read(const ReadCB& read_cb) OVERRIDE; | 82 virtual void Read(const ReadCB& read_cb) OVERRIDE; |
| 87 virtual void EnableBitstreamConverter() OVERRIDE; | 83 virtual void EnableBitstreamConverter() OVERRIDE; |
| 88 virtual bool SupportsConfigChanges() OVERRIDE; | 84 virtual bool SupportsConfigChanges() OVERRIDE; |
| 89 virtual AudioDecoderConfig audio_decoder_config() OVERRIDE; | 85 virtual AudioDecoderConfig audio_decoder_config() OVERRIDE; |
| 90 virtual VideoDecoderConfig video_decoder_config() OVERRIDE; | 86 virtual VideoDecoderConfig video_decoder_config() OVERRIDE; |
| 91 | 87 |
| 92 // Returns the range of buffered data in this stream. | 88 // Returns the range of buffered data in this stream. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 DecoderBufferQueue buffer_queue_; | 129 DecoderBufferQueue buffer_queue_; |
| 134 ReadCB read_cb_; | 130 ReadCB read_cb_; |
| 135 | 131 |
| 136 #if defined(USE_PROPRIETARY_CODECS) | 132 #if defined(USE_PROPRIETARY_CODECS) |
| 137 scoped_ptr<FFmpegH264ToAnnexBBitstreamConverter> bitstream_converter_; | 133 scoped_ptr<FFmpegH264ToAnnexBBitstreamConverter> bitstream_converter_; |
| 138 #endif | 134 #endif |
| 139 | 135 |
| 140 bool bitstream_converter_enabled_; | 136 bool bitstream_converter_enabled_; |
| 141 | 137 |
| 142 std::string encryption_key_id_; | 138 std::string encryption_key_id_; |
| 143 const bool discard_negative_timestamps_; | |
| 144 | 139 |
| 145 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxerStream); | 140 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxerStream); |
| 146 }; | 141 }; |
| 147 | 142 |
| 148 class MEDIA_EXPORT FFmpegDemuxer : public Demuxer { | 143 class MEDIA_EXPORT FFmpegDemuxer : public Demuxer { |
| 149 public: | 144 public: |
| 150 FFmpegDemuxer(const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 145 FFmpegDemuxer(const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
| 151 DataSource* data_source, | 146 DataSource* data_source, |
| 152 const NeedKeyCB& need_key_cb, | 147 const NeedKeyCB& need_key_cb, |
| 153 const scoped_refptr<MediaLog>& media_log); | 148 const scoped_refptr<MediaLog>& media_log); |
| 154 virtual ~FFmpegDemuxer(); | 149 virtual ~FFmpegDemuxer(); |
| 155 | 150 |
| 156 // Demuxer implementation. | 151 // Demuxer implementation. |
| 157 virtual void Initialize(DemuxerHost* host, | 152 virtual void Initialize(DemuxerHost* host, |
| 158 const PipelineStatusCB& status_cb, | 153 const PipelineStatusCB& status_cb, |
| 159 bool enable_text_tracks) OVERRIDE; | 154 bool enable_text_tracks) OVERRIDE; |
| 160 virtual void Stop(const base::Closure& callback) OVERRIDE; | 155 virtual void Stop(const base::Closure& callback) OVERRIDE; |
| 161 virtual void Seek(base::TimeDelta time, const PipelineStatusCB& cb) OVERRIDE; | 156 virtual void Seek(base::TimeDelta time, const PipelineStatusCB& cb) OVERRIDE; |
| 162 virtual DemuxerStream* GetStream(DemuxerStream::Type type) OVERRIDE; | 157 virtual DemuxerStream* GetStream(DemuxerStream::Type type) OVERRIDE; |
| 158 virtual base::TimeDelta GetStartTime() const OVERRIDE; |
| 163 virtual base::Time GetTimelineOffset() const OVERRIDE; | 159 virtual base::Time GetTimelineOffset() const OVERRIDE; |
| 164 virtual Liveness GetLiveness() const OVERRIDE; | 160 virtual Liveness GetLiveness() const OVERRIDE; |
| 165 | 161 |
| 166 // Calls |need_key_cb_| with the initialization data encountered in the file. | 162 // Calls |need_key_cb_| with the initialization data encountered in the file. |
| 167 void FireNeedKey(const std::string& init_data_type, | 163 void FireNeedKey(const std::string& init_data_type, |
| 168 const std::string& encryption_key_id); | 164 const std::string& encryption_key_id); |
| 169 | 165 |
| 170 // Allow FFmpegDemuxerStream to notify us when there is updated information | 166 // Allow FFmpegDemuxerStream to notify us when there is updated information |
| 171 // about capacity and what buffered data is available. | 167 // about capacity and what buffered data is available. |
| 172 void NotifyCapacityAvailable(); | 168 void NotifyCapacityAvailable(); |
| 173 void NotifyBufferingChanged(); | 169 void NotifyBufferingChanged(); |
| 174 | 170 |
| 175 // The lowest demuxed timestamp. DemuxerStream's must use this to adjust | |
| 176 // packet timestamps such that external clients see a zero-based timeline. | |
| 177 base::TimeDelta start_time() const { return start_time_; } | |
| 178 | |
| 179 private: | 171 private: |
| 180 // To allow tests access to privates. | 172 // To allow tests access to privates. |
| 181 friend class FFmpegDemuxerTest; | 173 friend class FFmpegDemuxerTest; |
| 182 | 174 |
| 183 // FFmpeg callbacks during initialization. | 175 // FFmpeg callbacks during initialization. |
| 184 void OnOpenContextDone(const PipelineStatusCB& status_cb, bool result); | 176 void OnOpenContextDone(const PipelineStatusCB& status_cb, bool result); |
| 185 void OnFindStreamInfoDone(const PipelineStatusCB& status_cb, int result); | 177 void OnFindStreamInfoDone(const PipelineStatusCB& status_cb, int result); |
| 186 | 178 |
| 187 // FFmpeg callbacks during seeking. | 179 // FFmpeg callbacks during seeking. |
| 188 void OnSeekFrameDone(const PipelineStatusCB& cb, int result); | 180 void OnSeekFrameDone(const PipelineStatusCB& cb, int result); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 | 238 |
| 247 // Provides asynchronous IO to this demuxer. Consumed by |url_protocol_| to | 239 // Provides asynchronous IO to this demuxer. Consumed by |url_protocol_| to |
| 248 // integrate with libavformat. | 240 // integrate with libavformat. |
| 249 DataSource* data_source_; | 241 DataSource* data_source_; |
| 250 | 242 |
| 251 scoped_refptr<MediaLog> media_log_; | 243 scoped_refptr<MediaLog> media_log_; |
| 252 | 244 |
| 253 // Derived bitrate after initialization has completed. | 245 // Derived bitrate after initialization has completed. |
| 254 int bitrate_; | 246 int bitrate_; |
| 255 | 247 |
| 256 // The first timestamp of the audio or video stream, whichever is lower. This | 248 // The first timestamp of the opened media file. This is used to set the |
| 257 // is used to adjust timestamps so that external consumers always see a zero | 249 // starting clock value to match the timestamps in the media file. Default |
| 258 // based timeline. | 250 // is 0. |
| 259 base::TimeDelta start_time_; | 251 base::TimeDelta start_time_; |
| 260 | 252 |
| 261 // The Time associated with timestamp 0. Set to a null | 253 // The Time associated with timestamp 0. Set to a null |
| 262 // time if the file doesn't have an association to Time. | 254 // time if the file doesn't have an association to Time. |
| 263 base::Time timeline_offset_; | 255 base::Time timeline_offset_; |
| 264 | 256 |
| 265 // Liveness of the stream. | 257 // Liveness of the stream. |
| 266 Liveness liveness_; | 258 Liveness liveness_; |
| 267 | 259 |
| 268 // Whether text streams have been enabled for this demuxer. | 260 // Whether text streams have been enabled for this demuxer. |
| 269 bool text_enabled_; | 261 bool text_enabled_; |
| 270 | 262 |
| 271 // Set if we know duration of the audio stream. Used when processing end of | 263 // Set if we know duration of the audio stream. Used when processing end of |
| 272 // stream -- at this moment we definitely know duration. | 264 // stream -- at this moment we definitely know duration. |
| 273 bool duration_known_; | 265 bool duration_known_; |
| 274 | 266 |
| 275 // FFmpegURLProtocol implementation and corresponding glue bits. | 267 // FFmpegURLProtocol implementation and corresponding glue bits. |
| 276 scoped_ptr<BlockingUrlProtocol> url_protocol_; | 268 scoped_ptr<BlockingUrlProtocol> url_protocol_; |
| 277 scoped_ptr<FFmpegGlue> glue_; | 269 scoped_ptr<FFmpegGlue> glue_; |
| 278 | 270 |
| 279 const NeedKeyCB need_key_cb_; | 271 const NeedKeyCB need_key_cb_; |
| 280 | 272 |
| 281 // The index of the stream in |streams_| to use for seeking. Chosen by the | |
| 282 // stream with the lowest starting timestamp. | |
| 283 int stream_index_for_seeking_; | |
| 284 | |
| 285 // NOTE: Weak pointers must be invalidated before all other member variables. | 273 // NOTE: Weak pointers must be invalidated before all other member variables. |
| 286 base::WeakPtrFactory<FFmpegDemuxer> weak_factory_; | 274 base::WeakPtrFactory<FFmpegDemuxer> weak_factory_; |
| 287 | 275 |
| 288 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxer); | 276 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxer); |
| 289 }; | 277 }; |
| 290 | 278 |
| 291 } // namespace media | 279 } // namespace media |
| 292 | 280 |
| 293 #endif // MEDIA_FILTERS_FFMPEG_DEMUXER_H_ | 281 #endif // MEDIA_FILTERS_FFMPEG_DEMUXER_H_ |
| OLD | NEW |