Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(304)

Side by Side Diff: media/filters/ffmpeg_demuxer.h

Issue 10581050: Ensure media's buffered ranges always have a range that includes currentTime. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 29 matching lines...) Expand all
40 struct AVPacket; 40 struct AVPacket;
41 struct AVRational; 41 struct AVRational;
42 struct AVStream; 42 struct AVStream;
43 43
44 namespace media { 44 namespace media {
45 45
46 class BitstreamConverter; 46 class BitstreamConverter;
47 class FFmpegDemuxer; 47 class FFmpegDemuxer;
48 class ScopedPtrAVFreePacket; 48 class ScopedPtrAVFreePacket;
49 49
50 typedef base::Callback<void(base::TimeDelta, base::TimeDelta)> NotifyBufferedCB;
51
50 class FFmpegDemuxerStream : public DemuxerStream { 52 class FFmpegDemuxerStream : public DemuxerStream {
51 public: 53 public:
52 // Keeps a copy of |demuxer| and initializes itself using information 54 // Keeps a copy of |demuxer| and initializes itself using information
53 // inside |stream|. Both parameters must outlive |this|. 55 // inside |stream|. Both parameters must outlive |this|.
54 FFmpegDemuxerStream(FFmpegDemuxer* demuxer, AVStream* stream); 56 FFmpegDemuxerStream(const NotifyBufferedCB& notify_buffered_cb_,
57 FFmpegDemuxer* demuxer, AVStream* stream);
55 58
56 // Returns true is this stream has pending reads, false otherwise. 59 // Returns true is this stream has pending reads, false otherwise.
57 // 60 //
58 // Safe to call on any thread. 61 // Safe to call on any thread.
59 bool HasPendingReads(); 62 bool HasPendingReads();
60 63
61 // Enqueues the given AVPacket. If |packet| is NULL an end of stream packet 64 // Enqueues the given AVPacket. If |packet| is NULL an end of stream packet
62 // is enqueued. 65 // is enqueued.
63 void EnqueuePacket(scoped_ptr_malloc<AVPacket, ScopedPtrAVFreePacket> packet); 66 void EnqueuePacket(scoped_ptr_malloc<AVPacket, ScopedPtrAVFreePacket> packet);
64 67
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 103
101 // Attempts to fulfill a single pending read by dequeueing a buffer and read 104 // Attempts to fulfill a single pending read by dequeueing a buffer and read
102 // callback pair and executing the callback. The calling function must 105 // callback pair and executing the callback. The calling function must
103 // acquire |lock_| before calling this function. 106 // acquire |lock_| before calling this function.
104 void FulfillPendingRead(); 107 void FulfillPendingRead();
105 108
106 // Converts an FFmpeg stream timestamp into a base::TimeDelta. 109 // Converts an FFmpeg stream timestamp into a base::TimeDelta.
107 static base::TimeDelta ConvertStreamTimestamp(const AVRational& time_base, 110 static base::TimeDelta ConvertStreamTimestamp(const AVRational& time_base,
108 int64 timestamp); 111 int64 timestamp);
109 112
113 NotifyBufferedCB notify_buffered_cb_;
110 FFmpegDemuxer* demuxer_; 114 FFmpegDemuxer* demuxer_;
111 AVStream* stream_; 115 AVStream* stream_;
112 AudioDecoderConfig audio_config_; 116 AudioDecoderConfig audio_config_;
113 VideoDecoderConfig video_config_; 117 VideoDecoderConfig video_config_;
114 Type type_; 118 Type type_;
115 base::TimeDelta duration_; 119 base::TimeDelta duration_;
116 bool discontinuous_; 120 bool discontinuous_;
117 bool stopped_; 121 bool stopped_;
122 base::TimeDelta last_packet_timestamp_;
118 123
119 typedef std::deque<scoped_refptr<DecoderBuffer> > BufferQueue; 124 typedef std::deque<scoped_refptr<DecoderBuffer> > BufferQueue;
120 BufferQueue buffer_queue_; 125 BufferQueue buffer_queue_;
121 126
122 typedef std::deque<ReadCB> ReadQueue; 127 typedef std::deque<ReadCB> ReadQueue;
123 ReadQueue read_queue_; 128 ReadQueue read_queue_;
124 129
125 // Used to translate bitstream formats. 130 // Used to translate bitstream formats.
126 scoped_ptr<BitstreamConverter> bitstream_converter_; 131 scoped_ptr<BitstreamConverter> bitstream_converter_;
127 132
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 // Must be called on the demuxer thread. 203 // Must be called on the demuxer thread.
199 void StreamHasEnded(); 204 void StreamHasEnded();
200 205
201 // Wait for asynchronous read to complete and return number of bytes read. 206 // Wait for asynchronous read to complete and return number of bytes read.
202 virtual int WaitForRead(); 207 virtual int WaitForRead();
203 208
204 // Signal the blocked thread that the read has completed, with |size| bytes 209 // Signal the blocked thread that the read has completed, with |size| bytes
205 // read or kReadError in case of error. 210 // read or kReadError in case of error.
206 virtual void SignalReadCompleted(int size); 211 virtual void SignalReadCompleted(int size);
207 212
213 // Callback for DemuxerStreams to notify us they've buffered a time range,
214 // which we then percolate upwards.
215 void NotifyBufferedRange(
216 int stream_id, base::TimeDelta start, base::TimeDelta end);
217
208 DemuxerHost* host_; 218 DemuxerHost* host_;
209 219
210 MessageLoop* message_loop_; 220 MessageLoop* message_loop_;
211 221
212 // FFmpeg context handle. 222 // FFmpeg context handle.
213 AVFormatContext* format_context_; 223 AVFormatContext* format_context_;
214 224
215 // |streams_| mirrors the AVStream array in |format_context_|. It contains 225 // |streams_| mirrors the AVStream array in |format_context_|. It contains
216 // FFmpegDemuxerStreams encapsluating AVStream objects at the same index. 226 // FFmpegDemuxerStreams encapsluating AVStream objects at the same index.
217 // 227 //
218 // Since we only support a single audio and video stream, |streams_| will 228 // Since we only support a single audio and video stream, |streams_| will
219 // contain NULL entries for additional audio/video streams as well as for 229 // contain NULL entries for additional audio/video streams as well as for
220 // stream types that we do not currently support. 230 // stream types that we do not currently support.
221 // 231 //
222 // Once initialized, operations on FFmpegDemuxerStreams should be carried out 232 // Once initialized, operations on FFmpegDemuxerStreams should be carried out
223 // on the demuxer thread. 233 // on the demuxer thread.
224 typedef std::vector<scoped_refptr<FFmpegDemuxerStream> > StreamVector; 234 typedef std::vector<scoped_refptr<FFmpegDemuxerStream> > StreamVector;
225 StreamVector streams_; 235 StreamVector streams_;
226 236
237 // The times buffered by each stream.
238 std::vector<Ranges<base::TimeDelta> > buffered_times_;
239
227 // Reference to the data source. Asynchronous read requests are submitted to 240 // Reference to the data source. Asynchronous read requests are submitted to
228 // this object. 241 // this object.
229 scoped_refptr<DataSource> data_source_; 242 scoped_refptr<DataSource> data_source_;
230 243
231 // This member is used to block on read method calls from FFmpeg and wait 244 // This member is used to block on read method calls from FFmpeg and wait
232 // until the asynchronous reads in the data source to complete. It is also 245 // until the asynchronous reads in the data source to complete. It is also
233 // signaled when the demuxer is being stopped. 246 // signaled when the demuxer is being stopped.
234 base::WaitableEvent read_event_; 247 base::WaitableEvent read_event_;
235 248
236 // Flag to indicate if read has ever failed. Once set to true, it will 249 // Flag to indicate if read has ever failed. Once set to true, it will
(...skipping 18 matching lines...) Expand all
255 // Set if we know duration of the audio stream. Used when processing end of 268 // Set if we know duration of the audio stream. Used when processing end of
256 // stream -- at this moment we definitely know duration. 269 // stream -- at this moment we definitely know duration.
257 bool duration_known_; 270 bool duration_known_;
258 271
259 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxer); 272 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxer);
260 }; 273 };
261 274
262 } // namespace media 275 } // namespace media
263 276
264 #endif // MEDIA_FILTERS_FFMPEG_DEMUXER_H_ 277 #endif // MEDIA_FILTERS_FFMPEG_DEMUXER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698