| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #ifndef MEDIA_FILTERS_FFMPEG_VIDEO_DECODER_H_ | 5 #ifndef MEDIA_FILTERS_FFMPEG_VIDEO_DECODER_H_ |
| 6 #define MEDIA_FILTERS_FFMPEG_VIDEO_DECODER_H_ | 6 #define MEDIA_FILTERS_FFMPEG_VIDEO_DECODER_H_ |
| 7 | 7 |
| 8 #include <deque> |
| 9 |
| 8 #include "base/gtest_prod_util.h" | 10 #include "base/gtest_prod_util.h" |
| 9 #include "base/time.h" | 11 #include "base/time.h" |
| 10 #include "media/base/factory.h" | 12 #include "media/base/factory.h" |
| 11 #include "media/base/filters.h" | 13 #include "media/base/filters.h" |
| 12 #include "media/base/pts_heap.h" | 14 #include "media/base/pts_heap.h" |
| 13 #include "media/base/video_frame.h" | 15 #include "media/base/video_frame.h" |
| 14 #include "media/filters/decoder_base.h" | 16 #include "media/filters/decoder_base.h" |
| 15 #include "media/filters/video_decode_engine.h" | 17 #include "media/filters/video_decode_engine.h" |
| 16 | 18 |
| 17 // FFmpeg types. | 19 // FFmpeg types. |
| 18 struct AVRational; | 20 struct AVRational; |
| 19 | 21 |
| 20 namespace media { | 22 namespace media { |
| 21 | 23 |
| 22 class VideoDecodeEngine; | 24 class VideoDecodeEngine; |
| 23 | 25 |
| 24 class FFmpegVideoDecoder : public VideoDecoder, | 26 class FFmpegVideoDecoder : public VideoDecoder, |
| 25 public VideoDecodeEngine::EventHandler { | 27 public VideoDecodeEngine::EventHandler { |
| 26 public: | 28 public: |
| 27 explicit FFmpegVideoDecoder(VideoDecodeEngine* engine); | 29 explicit FFmpegVideoDecoder(VideoDecodeEngine* engine); |
| 28 virtual ~FFmpegVideoDecoder(); | 30 virtual ~FFmpegVideoDecoder(); |
| 29 | 31 |
| 30 static FilterFactory* CreateFactory(); | 32 static FilterFactory* CreateFactory(); |
| 31 static bool IsMediaFormatSupported(const MediaFormat& media_format); | 33 static bool IsMediaFormatSupported(const MediaFormat& media_format); |
| 32 | 34 |
| 33 // MediaFilter implementation. | 35 // MediaFilter implementation. |
| 34 virtual void Stop(FilterCallback* callback); | 36 virtual void Stop(FilterCallback* callback); |
| 35 virtual void Seek(base::TimeDelta time, FilterCallback* callback); | 37 virtual void Seek(base::TimeDelta time, FilterCallback* callback); |
| 38 virtual void Pause(FilterCallback* callback); |
| 36 virtual void Flush(FilterCallback* callback); | 39 virtual void Flush(FilterCallback* callback); |
| 37 | 40 |
| 38 // Decoder implementation. | 41 // Decoder implementation. |
| 39 virtual void Initialize(DemuxerStream* demuxer_stream, | 42 virtual void Initialize(DemuxerStream* demuxer_stream, |
| 40 FilterCallback* callback); | 43 FilterCallback* callback); |
| 41 virtual const MediaFormat& media_format() { return media_format_; } | 44 virtual const MediaFormat& media_format() { return media_format_; } |
| 42 virtual void FillThisBuffer(scoped_refptr<VideoFrame> video_frame); | 45 virtual void FillThisBuffer(scoped_refptr<VideoFrame> video_frame); |
| 43 virtual bool ProvidesBuffer(); | 46 virtual bool ProvidesBuffer(); |
| 44 | 47 |
| 45 private: | 48 private: |
| (...skipping 24 matching lines...) Expand all Loading... |
| 70 struct TimeTuple { | 73 struct TimeTuple { |
| 71 base::TimeDelta timestamp; | 74 base::TimeDelta timestamp; |
| 72 base::TimeDelta duration; | 75 base::TimeDelta duration; |
| 73 }; | 76 }; |
| 74 | 77 |
| 75 enum DecoderState { | 78 enum DecoderState { |
| 76 kUnInitialized, | 79 kUnInitialized, |
| 77 kNormal, | 80 kNormal, |
| 78 kFlushCodec, | 81 kFlushCodec, |
| 79 kDecodeFinished, | 82 kDecodeFinished, |
| 83 kPausing, |
| 84 kFlushing, |
| 80 kStopped | 85 kStopped |
| 81 }; | 86 }; |
| 82 | 87 |
| 83 void OnFlushComplete(FilterCallback* callback); | 88 void OnFlushComplete(FilterCallback* callback); |
| 84 void OnSeekComplete(FilterCallback* callback); | 89 void OnSeekComplete(FilterCallback* callback); |
| 85 void OnReadComplete(Buffer* buffer); | 90 void OnReadComplete(Buffer* buffer); |
| 86 | 91 |
| 87 // TODO(jiesun): until demuxer pass scoped_refptr<Buffer>: we could not merge | 92 // TODO(jiesun): until demuxer pass scoped_refptr<Buffer>: we could not merge |
| 88 // this with OnReadComplete | 93 // this with OnReadComplete |
| 89 void OnReadCompleteTask(scoped_refptr<Buffer> buffer); | 94 void OnReadCompleteTask(scoped_refptr<Buffer> buffer); |
| 90 | 95 |
| 96 // Flush the output buffers that we had held in Paused state. |
| 97 void FlushBuffers(); |
| 98 |
| 91 // Attempt to get the PTS and Duration for this frame by examining the time | 99 // Attempt to get the PTS and Duration for this frame by examining the time |
| 92 // info provided via packet stream (stored in |pts_heap|), or the info | 100 // info provided via packet stream (stored in |pts_heap|), or the info |
| 93 // written into the AVFrame itself. If no data is available in either, then | 101 // written into the AVFrame itself. If no data is available in either, then |
| 94 // attempt to generate a best guess of the pts based on the last known pts. | 102 // attempt to generate a best guess of the pts based on the last known pts. |
| 95 // | 103 // |
| 96 // Data inside the AVFrame (if provided) is trusted the most, followed | 104 // Data inside the AVFrame (if provided) is trusted the most, followed |
| 97 // by data from the packet stream. Estimation based on the |last_pts| is | 105 // by data from the packet stream. Estimation based on the |last_pts| is |
| 98 // reserved as a last-ditch effort. | 106 // reserved as a last-ditch effort. |
| 99 virtual TimeTuple FindPtsAndDuration(const AVRational& time_base, | 107 virtual TimeTuple FindPtsAndDuration(const AVRational& time_base, |
| 100 PtsHeap* pts_heap, | 108 PtsHeap* pts_heap, |
| 101 const TimeTuple& last_pts, | 109 const TimeTuple& last_pts, |
| 102 const VideoFrame* frame); | 110 const VideoFrame* frame); |
| 103 | 111 |
| 104 // Injection point for unittest to provide a mock engine. Takes ownership of | 112 // Injection point for unittest to provide a mock engine. Takes ownership of |
| 105 // the provided engine. | 113 // the provided engine. |
| 106 virtual void SetVideoDecodeEngineForTest(VideoDecodeEngine* engine); | 114 virtual void SetVideoDecodeEngineForTest(VideoDecodeEngine* engine); |
| 107 | 115 |
| 108 size_t width_; | 116 size_t width_; |
| 109 size_t height_; | 117 size_t height_; |
| 110 MediaFormat media_format_; | 118 MediaFormat media_format_; |
| 111 | 119 |
| 112 PtsHeap pts_heap_; // Heap of presentation timestamps. | 120 PtsHeap pts_heap_; // Heap of presentation timestamps. |
| 113 TimeTuple last_pts_; | 121 TimeTuple last_pts_; |
| 114 scoped_ptr<AVRational> time_base_; // Pointer to avoid needing full type. | 122 scoped_ptr<AVRational> time_base_; // Pointer to avoid needing full type. |
| 115 DecoderState state_; | 123 DecoderState state_; |
| 116 scoped_refptr<VideoDecodeEngine> decode_engine_; | 124 scoped_refptr<VideoDecodeEngine> decode_engine_; |
| 117 | 125 |
| 118 // Tracks the number of asynchronous reads issued to |demuxer_stream_|. | |
| 119 // Using size_t since it is always compared against deque::size(). | |
| 120 size_t pending_reads_; | |
| 121 // Tracks the number of asynchronous reads issued from renderer. | |
| 122 size_t pending_requests_; | |
| 123 | |
| 124 scoped_ptr<FilterCallback> initialize_callback_; | 126 scoped_ptr<FilterCallback> initialize_callback_; |
| 125 scoped_ptr<FilterCallback> uninitialize_callback_; | 127 scoped_ptr<FilterCallback> uninitialize_callback_; |
| 126 scoped_ptr<FilterCallback> flush_callback_; | 128 scoped_ptr<FilterCallback> flush_callback_; |
| 127 scoped_ptr<FilterCallback> seek_callback_; | 129 scoped_ptr<FilterCallback> seek_callback_; |
| 128 | 130 |
| 131 // Hold video frames when flush happens. |
| 132 std::deque<scoped_refptr<VideoFrame> > frame_queue_flushed_; |
| 133 |
| 129 VideoCodecInfo info_; | 134 VideoCodecInfo info_; |
| 130 | 135 |
| 131 // Pointer to the demuxer stream that will feed us compressed buffers. | 136 // Pointer to the demuxer stream that will feed us compressed buffers. |
| 132 scoped_refptr<DemuxerStream> demuxer_stream_; | 137 scoped_refptr<DemuxerStream> demuxer_stream_; |
| 133 | 138 |
| 134 DISALLOW_COPY_AND_ASSIGN(FFmpegVideoDecoder); | 139 DISALLOW_COPY_AND_ASSIGN(FFmpegVideoDecoder); |
| 135 }; | 140 }; |
| 136 | 141 |
| 137 } // namespace media | 142 } // namespace media |
| 138 | 143 |
| 139 #endif // MEDIA_FILTERS_FFMPEG_VIDEO_DECODER_H_ | 144 #endif // MEDIA_FILTERS_FFMPEG_VIDEO_DECODER_H_ |
| OLD | NEW |