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

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

Issue 335273002: Fix seeking when the start time is non-zero. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixes. Created 6 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 58 // Keeps a copy of |demuxer| and initializes itself using information inside
59 // inside |stream|. Both parameters must outlive |this|. 59 // |stream|. Both parameters must outlive |this|.
60 FFmpegDemuxerStream(FFmpegDemuxer* demuxer, AVStream* stream); 60 // |discard_negative_timestamps| tells the DemuxerStream that all packets with
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);
61 virtual ~FFmpegDemuxerStream(); 66 virtual ~FFmpegDemuxerStream();
62 67
63 // Enqueues the given AVPacket. It is invalid to queue a |packet| after 68 // Enqueues the given AVPacket. It is invalid to queue a |packet| after
64 // SetEndOfStream() has been called. 69 // SetEndOfStream() has been called.
65 void EnqueuePacket(ScopedAVPacket packet); 70 void EnqueuePacket(ScopedAVPacket packet);
66 71
67 // Enters the end of stream state. After delivering remaining queued buffers 72 // Enters the end of stream state. After delivering remaining queued buffers
68 // only end of stream buffers will be delivered. 73 // only end of stream buffers will be delivered.
69 void SetEndOfStream(); 74 void SetEndOfStream();
70 75
71 // Drops queued buffers and clears end of stream state. 76 // Drops queued buffers and clears end of stream state.
72 void FlushBuffers(); 77 void FlushBuffers();
73 78
74 // Empties the queues and ignores any additional calls to Read(). 79 // Empties the queues and ignores any additional calls to Read().
75 void Stop(); 80 void Stop();
76 81
77 // Returns the duration of this stream. 82 base::TimeDelta duration() const { return duration_; }
78 base::TimeDelta duration();
79 83
80 // DemuxerStream implementation. 84 // DemuxerStream implementation.
81 virtual Type type() OVERRIDE; 85 virtual Type type() OVERRIDE;
82 virtual void Read(const ReadCB& read_cb) OVERRIDE; 86 virtual void Read(const ReadCB& read_cb) OVERRIDE;
83 virtual void EnableBitstreamConverter() OVERRIDE; 87 virtual void EnableBitstreamConverter() OVERRIDE;
84 virtual bool SupportsConfigChanges() OVERRIDE; 88 virtual bool SupportsConfigChanges() OVERRIDE;
85 virtual AudioDecoderConfig audio_decoder_config() OVERRIDE; 89 virtual AudioDecoderConfig audio_decoder_config() OVERRIDE;
86 virtual VideoDecoderConfig video_decoder_config() OVERRIDE; 90 virtual VideoDecoderConfig video_decoder_config() OVERRIDE;
87 91
88 // Returns the range of buffered data in this stream. 92 // Returns the range of buffered data in this stream.
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 DecoderBufferQueue buffer_queue_; 133 DecoderBufferQueue buffer_queue_;
130 ReadCB read_cb_; 134 ReadCB read_cb_;
131 135
132 #if defined(USE_PROPRIETARY_CODECS) 136 #if defined(USE_PROPRIETARY_CODECS)
133 scoped_ptr<FFmpegH264ToAnnexBBitstreamConverter> bitstream_converter_; 137 scoped_ptr<FFmpegH264ToAnnexBBitstreamConverter> bitstream_converter_;
134 #endif 138 #endif
135 139
136 bool bitstream_converter_enabled_; 140 bool bitstream_converter_enabled_;
137 141
138 std::string encryption_key_id_; 142 std::string encryption_key_id_;
143 const bool discard_negative_timestamps_;
139 144
140 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxerStream); 145 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxerStream);
141 }; 146 };
142 147
143 class MEDIA_EXPORT FFmpegDemuxer : public Demuxer { 148 class MEDIA_EXPORT FFmpegDemuxer : public Demuxer {
144 public: 149 public:
145 FFmpegDemuxer(const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, 150 FFmpegDemuxer(const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
146 DataSource* data_source, 151 DataSource* data_source,
147 const NeedKeyCB& need_key_cb, 152 const NeedKeyCB& need_key_cb,
148 const scoped_refptr<MediaLog>& media_log); 153 const scoped_refptr<MediaLog>& media_log);
149 virtual ~FFmpegDemuxer(); 154 virtual ~FFmpegDemuxer();
150 155
151 // Demuxer implementation. 156 // Demuxer implementation.
152 virtual void Initialize(DemuxerHost* host, 157 virtual void Initialize(DemuxerHost* host,
153 const PipelineStatusCB& status_cb, 158 const PipelineStatusCB& status_cb,
154 bool enable_text_tracks) OVERRIDE; 159 bool enable_text_tracks) OVERRIDE;
155 virtual void Stop(const base::Closure& callback) OVERRIDE; 160 virtual void Stop(const base::Closure& callback) OVERRIDE;
156 virtual void Seek(base::TimeDelta time, const PipelineStatusCB& cb) OVERRIDE; 161 virtual void Seek(base::TimeDelta time, const PipelineStatusCB& cb) OVERRIDE;
157 virtual DemuxerStream* GetStream(DemuxerStream::Type type) OVERRIDE; 162 virtual DemuxerStream* GetStream(DemuxerStream::Type type) OVERRIDE;
158 virtual base::TimeDelta GetStartTime() const OVERRIDE;
159 virtual base::Time GetTimelineOffset() const OVERRIDE; 163 virtual base::Time GetTimelineOffset() const OVERRIDE;
160 virtual Liveness GetLiveness() const OVERRIDE; 164 virtual Liveness GetLiveness() const OVERRIDE;
161 165
162 // Calls |need_key_cb_| with the initialization data encountered in the file. 166 // Calls |need_key_cb_| with the initialization data encountered in the file.
163 void FireNeedKey(const std::string& init_data_type, 167 void FireNeedKey(const std::string& init_data_type,
164 const std::string& encryption_key_id); 168 const std::string& encryption_key_id);
165 169
166 // Allow FFmpegDemuxerStream to notify us when there is updated information 170 // Allow FFmpegDemuxerStream to notify us when there is updated information
167 // about capacity and what buffered data is available. 171 // about capacity and what buffered data is available.
168 void NotifyCapacityAvailable(); 172 void NotifyCapacityAvailable();
169 void NotifyBufferingChanged(); 173 void NotifyBufferingChanged();
170 174
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
171 private: 179 private:
172 // To allow tests access to privates. 180 // To allow tests access to privates.
173 friend class FFmpegDemuxerTest; 181 friend class FFmpegDemuxerTest;
174 182
175 // FFmpeg callbacks during initialization. 183 // FFmpeg callbacks during initialization.
176 void OnOpenContextDone(const PipelineStatusCB& status_cb, bool result); 184 void OnOpenContextDone(const PipelineStatusCB& status_cb, bool result);
177 void OnFindStreamInfoDone(const PipelineStatusCB& status_cb, int result); 185 void OnFindStreamInfoDone(const PipelineStatusCB& status_cb, int result);
178 186
179 // FFmpeg callbacks during seeking. 187 // FFmpeg callbacks during seeking.
180 void OnSeekFrameDone(const PipelineStatusCB& cb, int result); 188 void OnSeekFrameDone(const PipelineStatusCB& cb, int result);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 // Tracks if there's an outstanding av_read_frame() operation. 225 // Tracks if there's an outstanding av_read_frame() operation.
218 // 226 //
219 // TODO(scherkus): Allow more than one read in flight for higher read 227 // TODO(scherkus): Allow more than one read in flight for higher read
220 // throughput using demuxer_bench to verify improvements. 228 // throughput using demuxer_bench to verify improvements.
221 bool pending_read_; 229 bool pending_read_;
222 230
223 // Tracks if there's an outstanding av_seek_frame() operation. Used to discard 231 // Tracks if there's an outstanding av_seek_frame() operation. Used to discard
224 // results of pre-seek av_read_frame() operations. 232 // results of pre-seek av_read_frame() operations.
225 bool pending_seek_; 233 bool pending_seek_;
226 234
227 // |streams_| mirrors the AVStream array in |format_context_|. It contains 235 // |streams_| mirrors the AVStream array in AVFormatContext. It contains
228 // FFmpegDemuxerStreams encapsluating AVStream objects at the same index. 236 // FFmpegDemuxerStreams encapsluating AVStream objects at the same index.
229 // 237 //
230 // Since we only support a single audio and video stream, |streams_| will 238 // Since we only support a single audio and video stream, |streams_| will
231 // contain NULL entries for additional audio/video streams as well as for 239 // contain NULL entries for additional audio/video streams as well as for
232 // stream types that we do not currently support. 240 // stream types that we do not currently support.
233 // 241 //
234 // Once initialized, operations on FFmpegDemuxerStreams should be carried out 242 // Once initialized, operations on FFmpegDemuxerStreams should be carried out
235 // on the demuxer thread. 243 // on the demuxer thread.
236 typedef ScopedVector<FFmpegDemuxerStream> StreamVector; 244 typedef ScopedVector<FFmpegDemuxerStream> StreamVector;
237 StreamVector streams_; 245 StreamVector streams_;
238 246
239 // Provides asynchronous IO to this demuxer. Consumed by |url_protocol_| to 247 // Provides asynchronous IO to this demuxer. Consumed by |url_protocol_| to
240 // integrate with libavformat. 248 // integrate with libavformat.
241 DataSource* data_source_; 249 DataSource* data_source_;
242 250
243 scoped_refptr<MediaLog> media_log_; 251 scoped_refptr<MediaLog> media_log_;
244 252
245 // Derived bitrate after initialization has completed. 253 // Derived bitrate after initialization has completed.
246 int bitrate_; 254 int bitrate_;
247 255
248 // The first timestamp of the opened media file. This is used to set the 256 // The first timestamp of the audio or video stream, whichever is lower. This
249 // starting clock value to match the timestamps in the media file. Default 257 // is used to adjust timestamps so that external consumers always see a zero
250 // is 0. 258 // based timeline.
251 base::TimeDelta start_time_; 259 base::TimeDelta start_time_;
252 260
261 // The starting timestamp of each stream. It contains an entry for every
262 // AVStream in the AVFormatContext. Used to determine which stream should be
263 // used for seeking.
264 std::vector<base::TimeDelta> stream_start_times_;
acolwell GONE FROM CHROMIUM 2014/06/17 17:41:22 as discussed offline, I don't think you need the v
DaleCurtis 2014/06/17 20:52:30 Done. Though I'm not sure it's clearer.
265
253 // The Time associated with timestamp 0. Set to a null 266 // The Time associated with timestamp 0. Set to a null
254 // time if the file doesn't have an association to Time. 267 // time if the file doesn't have an association to Time.
255 base::Time timeline_offset_; 268 base::Time timeline_offset_;
256 269
257 // Liveness of the stream. 270 // Liveness of the stream.
258 Liveness liveness_; 271 Liveness liveness_;
259 272
260 // Whether text streams have been enabled for this demuxer. 273 // Whether text streams have been enabled for this demuxer.
261 bool text_enabled_; 274 bool text_enabled_;
262 275
263 // Set if we know duration of the audio stream. Used when processing end of 276 // Set if we know duration of the audio stream. Used when processing end of
264 // stream -- at this moment we definitely know duration. 277 // stream -- at this moment we definitely know duration.
265 bool duration_known_; 278 bool duration_known_;
266 279
267 // FFmpegURLProtocol implementation and corresponding glue bits. 280 // FFmpegURLProtocol implementation and corresponding glue bits.
268 scoped_ptr<BlockingUrlProtocol> url_protocol_; 281 scoped_ptr<BlockingUrlProtocol> url_protocol_;
269 scoped_ptr<FFmpegGlue> glue_; 282 scoped_ptr<FFmpegGlue> glue_;
270 283
271 const NeedKeyCB need_key_cb_; 284 const NeedKeyCB need_key_cb_;
272 285
273 // NOTE: Weak pointers must be invalidated before all other member variables. 286 // NOTE: Weak pointers must be invalidated before all other member variables.
274 base::WeakPtrFactory<FFmpegDemuxer> weak_factory_; 287 base::WeakPtrFactory<FFmpegDemuxer> weak_factory_;
275 288
276 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxer); 289 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxer);
277 }; 290 };
278 291
279 } // namespace media 292 } // namespace media
280 293
281 #endif // MEDIA_FILTERS_FFMPEG_DEMUXER_H_ 294 #endif // MEDIA_FILTERS_FFMPEG_DEMUXER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698