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 // |
11 // FFmpegDemuxer sets the duration of pipeline during initialization by using | 11 // FFmpegDemuxer sets the duration of pipeline during initialization by using |
12 // the duration of the longest audio/video stream. | 12 // the duration of the longest audio/video stream. |
13 // | 13 // |
14 // NOTE: since FFmpegDemuxer reads packets sequentially without seeking, media | 14 // NOTE: since FFmpegDemuxer reads packets sequentially without seeking, media |
wolenetz
2017/05/08 20:55:33
this comment seems a bit incorrect now with this c
| |
15 // files with very large drift between audio/video streams may result in | 15 // files with very large drift between audio/video streams may result in |
16 // excessive memory consumption. | 16 // excessive memory consumption. |
17 // | 17 // |
18 // When stopped, FFmpegDemuxer and FFmpegDemuxerStream release all callbacks | 18 // When stopped, FFmpegDemuxer and FFmpegDemuxerStream release all callbacks |
19 // and buffered packets. Reads from a stopped FFmpegDemuxerStream will not be | 19 // and buffered packets. Reads from a stopped FFmpegDemuxerStream will not be |
20 // replied to. | 20 // replied to. |
21 | 21 |
22 #ifndef MEDIA_FILTERS_FFMPEG_DEMUXER_H_ | 22 #ifndef MEDIA_FILTERS_FFMPEG_DEMUXER_H_ |
23 #define MEDIA_FILTERS_FFMPEG_DEMUXER_H_ | 23 #define MEDIA_FILTERS_FFMPEG_DEMUXER_H_ |
24 | 24 |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
264 | 264 |
265 // FFmpeg callbacks during initialization. | 265 // FFmpeg callbacks during initialization. |
266 void OnOpenContextDone(const PipelineStatusCB& status_cb, bool result); | 266 void OnOpenContextDone(const PipelineStatusCB& status_cb, bool result); |
267 void OnFindStreamInfoDone(const PipelineStatusCB& status_cb, int result); | 267 void OnFindStreamInfoDone(const PipelineStatusCB& status_cb, int result); |
268 | 268 |
269 void LogMetadata(AVFormatContext* avctx, base::TimeDelta max_duration); | 269 void LogMetadata(AVFormatContext* avctx, base::TimeDelta max_duration); |
270 | 270 |
271 // FFmpeg callbacks during seeking. | 271 // FFmpeg callbacks during seeking. |
272 void OnSeekFrameDone(int result); | 272 void OnSeekFrameDone(int result); |
273 | 273 |
274 // Called when FFmpeg completes seek initiated in OnSelectedVideoTrackChanged | |
275 // in order to restart the |stream|. | |
276 void OnSeekDoneForRestartingStream(FFmpegDemuxerStream* stream, int result); | |
277 | |
274 // FFmpeg callbacks during reading + helper method to initiate reads. | 278 // FFmpeg callbacks during reading + helper method to initiate reads. |
275 void ReadFrameIfNeeded(); | 279 void ReadFrameIfNeeded(); |
276 void OnReadFrameDone(ScopedAVPacket packet, int result); | 280 void OnReadFrameDone(ScopedAVPacket packet, int result); |
277 | 281 |
278 // Returns true iff any stream has additional capacity. Note that streams can | 282 // Returns true iff any stream has additional capacity. Note that streams can |
279 // go over capacity depending on how the file is muxed. | 283 // go over capacity depending on how the file is muxed. |
280 bool StreamsHaveAvailableCapacity(); | 284 bool StreamsHaveAvailableCapacity(); |
281 | 285 |
282 // Returns true if the maximum allowed memory usage has been reached. | 286 // Returns true if the maximum allowed memory usage has been reached. |
283 bool IsMaxMemoryUsageReached() const; | 287 bool IsMaxMemoryUsageReached() const; |
284 | 288 |
285 // Signal all FFmpegDemuxerStreams that the stream has ended. | 289 // Signal all FFmpegDemuxerStreams that the stream has ended. |
286 void StreamHasEnded(); | 290 void StreamHasEnded(); |
287 | 291 |
288 // Called by |url_protocol_| whenever |data_source_| returns a read error. | 292 // Called by |url_protocol_| whenever |data_source_| returns a read error. |
289 void OnDataSourceError(); | 293 void OnDataSourceError(); |
290 | 294 |
291 // Returns the first stream from |streams_| that matches |type| as an | 295 // Returns the first stream from |streams_| that matches |type| as an |
292 // FFmpegDemuxerStream and is enabled. | 296 // FFmpegDemuxerStream and is enabled. |
293 FFmpegDemuxerStream* GetFirstEnabledFFmpegStream( | 297 FFmpegDemuxerStream* GetFirstEnabledFFmpegStream( |
294 DemuxerStream::Type type) const; | 298 DemuxerStream::Type type) const; |
295 | 299 |
296 // Called after the streams have been collected from the media, to allow | 300 // Called after the streams have been collected from the media, to allow |
297 // the text renderer to bind each text stream to the cue rendering engine. | 301 // the text renderer to bind each text stream to the cue rendering engine. |
298 void AddTextStreams(); | 302 void AddTextStreams(); |
299 | 303 |
300 void SetLiveness(DemuxerStream::Liveness liveness); | 304 void SetLiveness(DemuxerStream::Liveness liveness); |
301 | 305 |
306 // Do an FFmpeg seek such that the read position is adjusted to be able to | |
307 // restart playback from the |time| position. If the |preferred_stream| is not | |
308 // null then it is used for seeking, otherwise the preferred stream is | |
309 // selected by FindPreferredStreamForSeeking function. When the seek is | |
310 // completed the |ffmpeg_seek_done_cb| will be called with FFmpeg result. | |
311 using FFmpegSeekDoneCB = base::Callback<void(int ffmpeg_result)>; | |
312 void SeekInternal(base::TimeDelta time, | |
313 FFmpegDemuxerStream* preferred_stream, | |
314 const FFmpegSeekDoneCB& ffmpeg_seek_done_cb); | |
315 | |
302 DemuxerHost* host_; | 316 DemuxerHost* host_; |
303 | 317 |
304 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 318 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
305 | 319 |
306 // Task runner on which all blocking FFmpeg operations are executed; retrieved | 320 // Task runner on which all blocking FFmpeg operations are executed; retrieved |
307 // from base::TaskScheduler. | 321 // from base::TaskScheduler. |
308 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; | 322 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; |
309 | 323 |
310 // Indicates if Stop() has been called. | 324 // Indicates if Stop() has been called. |
311 bool stopped_; | 325 bool stopped_; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
372 // FFmpegURLProtocol implementation and corresponding glue bits. | 386 // FFmpegURLProtocol implementation and corresponding glue bits. |
373 std::unique_ptr<BlockingUrlProtocol> url_protocol_; | 387 std::unique_ptr<BlockingUrlProtocol> url_protocol_; |
374 std::unique_ptr<FFmpegGlue> glue_; | 388 std::unique_ptr<FFmpegGlue> glue_; |
375 | 389 |
376 const EncryptedMediaInitDataCB encrypted_media_init_data_cb_; | 390 const EncryptedMediaInitDataCB encrypted_media_init_data_cb_; |
377 | 391 |
378 const MediaTracksUpdatedCB media_tracks_updated_cb_; | 392 const MediaTracksUpdatedCB media_tracks_updated_cb_; |
379 | 393 |
380 std::map<MediaTrack::Id, FFmpegDemuxerStream*> track_id_to_demux_stream_map_; | 394 std::map<MediaTrack::Id, FFmpegDemuxerStream*> track_id_to_demux_stream_map_; |
381 | 395 |
396 int64_t last_packet_pos_; | |
397 FFmpegDemuxerStream* restarting_stream_; | |
398 | |
382 // NOTE: Weak pointers must be invalidated before all other member variables. | 399 // NOTE: Weak pointers must be invalidated before all other member variables. |
383 base::WeakPtr<FFmpegDemuxer> weak_this_; | 400 base::WeakPtr<FFmpegDemuxer> weak_this_; |
384 base::WeakPtrFactory<FFmpegDemuxer> cancel_pending_seek_factory_; | 401 base::WeakPtrFactory<FFmpegDemuxer> cancel_pending_seek_factory_; |
385 base::WeakPtrFactory<FFmpegDemuxer> weak_factory_; | 402 base::WeakPtrFactory<FFmpegDemuxer> weak_factory_; |
386 | 403 |
387 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxer); | 404 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxer); |
388 }; | 405 }; |
389 | 406 |
390 } // namespace media | 407 } // namespace media |
391 | 408 |
392 #endif // MEDIA_FILTERS_FFMPEG_DEMUXER_H_ | 409 #endif // MEDIA_FILTERS_FFMPEG_DEMUXER_H_ |
OLD | NEW |