| 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 14 matching lines...) Expand all Loading... |
| 25 #include <stddef.h> | 25 #include <stddef.h> |
| 26 #include <stdint.h> | 26 #include <stdint.h> |
| 27 | 27 |
| 28 #include <memory> | 28 #include <memory> |
| 29 #include <string> | 29 #include <string> |
| 30 #include <utility> | 30 #include <utility> |
| 31 #include <vector> | 31 #include <vector> |
| 32 | 32 |
| 33 #include "base/callback.h" | 33 #include "base/callback.h" |
| 34 #include "base/macros.h" | 34 #include "base/macros.h" |
| 35 #include "base/memory/scoped_vector.h" | |
| 36 #include "base/threading/thread.h" | 35 #include "base/threading/thread.h" |
| 37 #include "media/base/audio_decoder_config.h" | 36 #include "media/base/audio_decoder_config.h" |
| 38 #include "media/base/decoder_buffer.h" | 37 #include "media/base/decoder_buffer.h" |
| 39 #include "media/base/decoder_buffer_queue.h" | 38 #include "media/base/decoder_buffer_queue.h" |
| 40 #include "media/base/demuxer.h" | 39 #include "media/base/demuxer.h" |
| 41 #include "media/base/pipeline_status.h" | 40 #include "media/base/pipeline_status.h" |
| 42 #include "media/base/text_track_config.h" | 41 #include "media/base/text_track_config.h" |
| 43 #include "media/base/video_decoder_config.h" | 42 #include "media/base/video_decoder_config.h" |
| 44 #include "media/ffmpeg/ffmpeg_deleters.h" | 43 #include "media/ffmpeg/ffmpeg_deleters.h" |
| 45 #include "media/filters/blocking_url_protocol.h" | 44 #include "media/filters/blocking_url_protocol.h" |
| 46 | 45 |
| 47 // FFmpeg forward declarations. | 46 // FFmpeg forward declarations. |
| 47 struct AVFormatContext; |
| 48 struct AVPacket; | 48 struct AVPacket; |
| 49 struct AVRational; | 49 struct AVRational; |
| 50 struct AVStream; | 50 struct AVStream; |
| 51 | 51 |
| 52 namespace media { | 52 namespace media { |
| 53 | 53 |
| 54 class MediaLog; | 54 class MediaLog; |
| 55 class FFmpegBitstreamConverter; | 55 class FFmpegBitstreamConverter; |
| 56 class FFmpegDemuxer; | 56 class FFmpegDemuxer; |
| 57 class FFmpegGlue; | 57 class FFmpegGlue; |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 base::TimeDelta start_time() const { return start_time_; } | 246 base::TimeDelta start_time() const { return start_time_; } |
| 247 | 247 |
| 248 private: | 248 private: |
| 249 // To allow tests access to privates. | 249 // To allow tests access to privates. |
| 250 friend class FFmpegDemuxerTest; | 250 friend class FFmpegDemuxerTest; |
| 251 | 251 |
| 252 // FFmpeg callbacks during initialization. | 252 // FFmpeg callbacks during initialization. |
| 253 void OnOpenContextDone(const PipelineStatusCB& status_cb, bool result); | 253 void OnOpenContextDone(const PipelineStatusCB& status_cb, bool result); |
| 254 void OnFindStreamInfoDone(const PipelineStatusCB& status_cb, int result); | 254 void OnFindStreamInfoDone(const PipelineStatusCB& status_cb, int result); |
| 255 | 255 |
| 256 void LogMetadata(AVFormatContext* avctx, base::TimeDelta max_duration); |
| 257 |
| 256 // FFmpeg callbacks during seeking. | 258 // FFmpeg callbacks during seeking. |
| 257 void OnSeekFrameDone(int result); | 259 void OnSeekFrameDone(int result); |
| 258 | 260 |
| 259 // FFmpeg callbacks during reading + helper method to initiate reads. | 261 // FFmpeg callbacks during reading + helper method to initiate reads. |
| 260 void ReadFrameIfNeeded(); | 262 void ReadFrameIfNeeded(); |
| 261 void OnReadFrameDone(ScopedAVPacket packet, int result); | 263 void OnReadFrameDone(ScopedAVPacket packet, int result); |
| 262 | 264 |
| 263 // Returns true iff any stream has additional capacity. Note that streams can | 265 // Returns true iff any stream has additional capacity. Note that streams can |
| 264 // go over capacity depending on how the file is muxed. | 266 // go over capacity depending on how the file is muxed. |
| 265 bool StreamsHaveAvailableCapacity(); | 267 bool StreamsHaveAvailableCapacity(); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 | 304 |
| 303 // |streams_| mirrors the AVStream array in AVFormatContext. It contains | 305 // |streams_| mirrors the AVStream array in AVFormatContext. It contains |
| 304 // FFmpegDemuxerStreams encapsluating AVStream objects at the same index. | 306 // FFmpegDemuxerStreams encapsluating AVStream objects at the same index. |
| 305 // | 307 // |
| 306 // Since we only support a single audio and video stream, |streams_| will | 308 // Since we only support a single audio and video stream, |streams_| will |
| 307 // contain NULL entries for additional audio/video streams as well as for | 309 // contain NULL entries for additional audio/video streams as well as for |
| 308 // stream types that we do not currently support. | 310 // stream types that we do not currently support. |
| 309 // | 311 // |
| 310 // Once initialized, operations on FFmpegDemuxerStreams should be carried out | 312 // Once initialized, operations on FFmpegDemuxerStreams should be carried out |
| 311 // on the demuxer thread. | 313 // on the demuxer thread. |
| 312 typedef ScopedVector<FFmpegDemuxerStream> StreamVector; | 314 using StreamVector = std::vector<std::unique_ptr<FFmpegDemuxerStream>>; |
| 313 StreamVector streams_; | 315 StreamVector streams_; |
| 314 | 316 |
| 315 // Provides asynchronous IO to this demuxer. Consumed by |url_protocol_| to | 317 // Provides asynchronous IO to this demuxer. Consumed by |url_protocol_| to |
| 316 // integrate with libavformat. | 318 // integrate with libavformat. |
| 317 DataSource* data_source_; | 319 DataSource* data_source_; |
| 318 | 320 |
| 319 scoped_refptr<MediaLog> media_log_; | 321 scoped_refptr<MediaLog> media_log_; |
| 320 | 322 |
| 321 // Derived bitrate after initialization has completed. | 323 // Derived bitrate after initialization has completed. |
| 322 int bitrate_; | 324 int bitrate_; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 344 bool duration_known_; | 346 bool duration_known_; |
| 345 | 347 |
| 346 // FFmpegURLProtocol implementation and corresponding glue bits. | 348 // FFmpegURLProtocol implementation and corresponding glue bits. |
| 347 std::unique_ptr<BlockingUrlProtocol> url_protocol_; | 349 std::unique_ptr<BlockingUrlProtocol> url_protocol_; |
| 348 std::unique_ptr<FFmpegGlue> glue_; | 350 std::unique_ptr<FFmpegGlue> glue_; |
| 349 | 351 |
| 350 const EncryptedMediaInitDataCB encrypted_media_init_data_cb_; | 352 const EncryptedMediaInitDataCB encrypted_media_init_data_cb_; |
| 351 | 353 |
| 352 const MediaTracksUpdatedCB media_tracks_updated_cb_; | 354 const MediaTracksUpdatedCB media_tracks_updated_cb_; |
| 353 | 355 |
| 354 std::map<MediaTrack::Id, const DemuxerStream*> track_id_to_demux_stream_map_; | 356 std::map<MediaTrack::Id, DemuxerStream*> track_id_to_demux_stream_map_; |
| 355 | 357 |
| 356 // NOTE: Weak pointers must be invalidated before all other member variables. | 358 // NOTE: Weak pointers must be invalidated before all other member variables. |
| 357 base::WeakPtrFactory<FFmpegDemuxer> weak_factory_; | 359 base::WeakPtrFactory<FFmpegDemuxer> weak_factory_; |
| 358 | 360 |
| 359 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxer); | 361 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxer); |
| 360 }; | 362 }; |
| 361 | 363 |
| 362 } // namespace media | 364 } // namespace media |
| 363 | 365 |
| 364 #endif // MEDIA_FILTERS_FFMPEG_DEMUXER_H_ | 366 #endif // MEDIA_FILTERS_FFMPEG_DEMUXER_H_ |
| OLD | NEW |