| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 // |lock_| for the life of the function so that means |read_callback| must | 77 // |lock_| for the life of the function so that means |read_callback| must |
| 78 // not make calls into FFmpegDemuxerStream directly or that may cause a | 78 // not make calls into FFmpegDemuxerStream directly or that may cause a |
| 79 // deadlock. |read_callback| should execute as quickly as possible because | 79 // deadlock. |read_callback| should execute as quickly as possible because |
| 80 // |lock_| is held throughout the life of the callback. | 80 // |lock_| is held throughout the life of the callback. |
| 81 virtual void Read(const ReadCallback& read_callback) OVERRIDE; | 81 virtual void Read(const ReadCallback& read_callback) OVERRIDE; |
| 82 virtual void EnableBitstreamConverter() OVERRIDE; | 82 virtual void EnableBitstreamConverter() OVERRIDE; |
| 83 virtual const AudioDecoderConfig& audio_decoder_config() OVERRIDE; | 83 virtual const AudioDecoderConfig& audio_decoder_config() OVERRIDE; |
| 84 virtual const VideoDecoderConfig& video_decoder_config() OVERRIDE; | 84 virtual const VideoDecoderConfig& video_decoder_config() OVERRIDE; |
| 85 | 85 |
| 86 private: | 86 private: |
| 87 friend class FFmpegDemuxerTest; |
| 87 virtual ~FFmpegDemuxerStream(); | 88 virtual ~FFmpegDemuxerStream(); |
| 88 | 89 |
| 89 // Carries out enqueuing a pending read on the demuxer thread. | 90 // Carries out enqueuing a pending read on the demuxer thread. |
| 90 void ReadTask(const ReadCallback& read_callback); | 91 void ReadTask(const ReadCallback& read_callback); |
| 91 | 92 |
| 92 // Attempts to fulfill a single pending read by dequeueing a buffer and read | 93 // Attempts to fulfill a single pending read by dequeueing a buffer and read |
| 93 // callback pair and executing the callback. The calling function must | 94 // callback pair and executing the callback. The calling function must |
| 94 // acquire |lock_| before calling this function. | 95 // acquire |lock_| before calling this function. |
| 95 void FulfillPendingRead(); | 96 void FulfillPendingRead(); |
| 96 | 97 |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 | 211 |
| 211 MessageLoop* message_loop_; | 212 MessageLoop* message_loop_; |
| 212 | 213 |
| 213 // True if the media is a local resource, false if the media require network | 214 // True if the media is a local resource, false if the media require network |
| 214 // access to be loaded. | 215 // access to be loaded. |
| 215 bool local_source_; | 216 bool local_source_; |
| 216 | 217 |
| 217 // FFmpeg context handle. | 218 // FFmpeg context handle. |
| 218 AVFormatContext* format_context_; | 219 AVFormatContext* format_context_; |
| 219 | 220 |
| 220 // Two vector of streams: | 221 // |streams_| mirrors the AVStream array in |format_context_|. It contains |
| 221 // - |streams_| is indexed by type for the Demuxer interface GetStream(), | 222 // FFmpegDemuxerStreams encapsluating AVStream objects at the same index. |
| 222 // and contains NULLs for types which aren't present. | |
| 223 // - |packet_streams_| is indexed to mirror AVFormatContext when dealing | |
| 224 // with AVPackets returned from av_read_frame() and contain NULL entries | |
| 225 // representing unsupported streams where we throw away the data. | |
| 226 // | 223 // |
| 227 // Ownership is handled via reference counting. | 224 // Since we only support a single audio and video stream, |streams_| will |
| 225 // contain NULL entries for additional audio/video streams as well as for |
| 226 // stream types that we do not currently support. |
| 228 // | 227 // |
| 229 // Once initialized, operations on FFmpegDemuxerStreams should be carried out | 228 // Once initialized, operations on FFmpegDemuxerStreams should be carried out |
| 230 // on the demuxer thread. | 229 // on the demuxer thread. |
| 231 typedef std::vector< scoped_refptr<FFmpegDemuxerStream> > StreamVector; | 230 typedef std::vector<scoped_refptr<FFmpegDemuxerStream> > StreamVector; |
| 232 StreamVector streams_; | 231 StreamVector streams_; |
| 233 StreamVector packet_streams_; | |
| 234 | 232 |
| 235 // Reference to the data source. Asynchronous read requests are submitted to | 233 // Reference to the data source. Asynchronous read requests are submitted to |
| 236 // this object. | 234 // this object. |
| 237 scoped_refptr<DataSource> data_source_; | 235 scoped_refptr<DataSource> data_source_; |
| 238 | 236 |
| 239 // This member is used to block on read method calls from FFmpeg and wait | 237 // This member is used to block on read method calls from FFmpeg and wait |
| 240 // until the asynchronous reads in the data source to complete. It is also | 238 // until the asynchronous reads in the data source to complete. It is also |
| 241 // signaled when the demuxer is being stopped. | 239 // signaled when the demuxer is being stopped. |
| 242 base::WaitableEvent read_event_; | 240 base::WaitableEvent read_event_; |
| 243 | 241 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 261 // starting clock value to match the timestamps in the media file. Default | 259 // starting clock value to match the timestamps in the media file. Default |
| 262 // is 0. | 260 // is 0. |
| 263 base::TimeDelta start_time_; | 261 base::TimeDelta start_time_; |
| 264 | 262 |
| 265 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxer); | 263 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxer); |
| 266 }; | 264 }; |
| 267 | 265 |
| 268 } // namespace media | 266 } // namespace media |
| 269 | 267 |
| 270 #endif // MEDIA_FILTERS_FFMPEG_DEMUXER_H_ | 268 #endif // MEDIA_FILTERS_FFMPEG_DEMUXER_H_ |
| OLD | NEW |