| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // source code is governed by a BSD-style license that can be found in the | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // 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 "media/filters/video_decoder_impl.h" | 8 #include "base/time.h" |
| 9 #include "media/base/pts_heap.h" |
| 10 #include "media/base/video_frame.h" |
| 11 #include "media/filters/decoder_base.h" |
| 12 #include "testing/gtest/include/gtest/gtest_prod.h" |
| 13 |
| 14 // FFmpeg types. |
| 15 struct AVRational; |
| 9 | 16 |
| 10 namespace media { | 17 namespace media { |
| 11 | 18 |
| 12 class FFmpegVideoDecodeEngine; | 19 class VideoDecodeEngine; |
| 13 class FilterFactory; | |
| 14 class MediaFormat; | |
| 15 | 20 |
| 16 class FFmpegVideoDecoder : public VideoDecoderImpl { | 21 class FFmpegVideoDecoder : public DecoderBase<VideoDecoder, VideoFrame> { |
| 17 public: | 22 public: |
| 23 explicit FFmpegVideoDecoder(VideoDecodeEngine* engine); |
| 24 virtual ~FFmpegVideoDecoder(); |
| 25 |
| 18 static FilterFactory* CreateFactory(); | 26 static FilterFactory* CreateFactory(); |
| 19 static bool IsMediaFormatSupported(const MediaFormat& media_format); | 27 static bool IsMediaFormatSupported(const MediaFormat& media_format); |
| 20 | 28 |
| 21 FFmpegVideoDecoder(FFmpegVideoDecodeEngine* engine); | 29 protected: |
| 22 virtual ~FFmpegVideoDecoder(); | 30 virtual void DoInitialize(DemuxerStream* demuxer_stream, bool* success, |
| 31 Task* done_cb); |
| 32 virtual void DoSeek(base::TimeDelta time, Task* done_cb); |
| 33 virtual void DoDecode(Buffer* input); |
| 34 |
| 35 protected: |
| 36 virtual void OnEmptyBufferDone(scoped_refptr<Buffer> buffer); |
| 37 |
| 38 private: |
| 39 friend class FilterFactoryImpl1<FFmpegVideoDecoder, VideoDecodeEngine*>; |
| 40 friend class DecoderPrivateMock; |
| 41 friend class FFmpegVideoDecoderTest; |
| 42 FRIEND_TEST(FFmpegVideoDecoderTest, FindPtsAndDuration); |
| 43 FRIEND_TEST(FFmpegVideoDecoderTest, DoDecode_EnqueueVideoFrameError); |
| 44 FRIEND_TEST(FFmpegVideoDecoderTest, DoDecode_FinishEnqueuesEmptyFrames); |
| 45 FRIEND_TEST(FFmpegVideoDecoderTest, DoDecode_TestStateTransition); |
| 46 FRIEND_TEST(FFmpegVideoDecoderTest, DoSeek); |
| 47 |
| 48 // The TimeTuple struct is used to hold the needed timestamp data needed for |
| 49 // enqueuing a video frame. |
| 50 struct TimeTuple { |
| 51 base::TimeDelta timestamp; |
| 52 base::TimeDelta duration; |
| 53 }; |
| 54 |
| 55 enum DecoderState { |
| 56 kNormal, |
| 57 kFlushCodec, |
| 58 kDecodeFinished, |
| 59 }; |
| 60 |
| 61 // Implement DecoderBase template methods. |
| 62 virtual void EnqueueVideoFrame(const scoped_refptr<VideoFrame>& video_frame); |
| 63 |
| 64 // Create an empty video frame and queue it. |
| 65 virtual void EnqueueEmptyFrame(); |
| 66 |
| 67 // Methods that pickup after the decode engine has finished its action. |
| 68 virtual void OnInitializeComplete(bool* success /* Not owned */, |
| 69 Task* done_cb); |
| 70 |
| 71 virtual void OnDecodeComplete(scoped_refptr<VideoFrame> video_frame); |
| 72 |
| 73 // Attempt to get the PTS and Duration for this frame by examining the time |
| 74 // info provided via packet stream (stored in |pts_heap|), or the info |
| 75 // writen into the AVFrame itself. If no data is available in either, then |
| 76 // attempt to generate a best guess of the pts based on the last known pts. |
| 77 // |
| 78 // Data inside the AVFrame (if provided) is trusted the most, followed |
| 79 // by data from the packet stream. Estimation based on the |last_pts| is |
| 80 // reserved as a last-ditch effort. |
| 81 virtual TimeTuple FindPtsAndDuration(const AVRational& time_base, |
| 82 PtsHeap* pts_heap, |
| 83 const TimeTuple& last_pts, |
| 84 const VideoFrame* frame); |
| 85 |
| 86 // Signals the pipeline that a decode error occurs, and moves the decoder |
| 87 // into the kDecodeFinished state. |
| 88 virtual void SignalPipelineError(); |
| 89 |
| 90 // Injection point for unittest to provide a mock engine. Takes ownership of |
| 91 // the provided engine. |
| 92 virtual void SetVideoDecodeEngineForTest(VideoDecodeEngine* engine); |
| 93 |
| 94 size_t width_; |
| 95 size_t height_; |
| 96 |
| 97 PtsHeap pts_heap_; // Heap of presentation timestamps. |
| 98 TimeTuple last_pts_; |
| 99 scoped_ptr<AVRational> time_base_; // Pointer to avoid needing full type. |
| 100 DecoderState state_; |
| 101 scoped_ptr<VideoDecodeEngine> decode_engine_; |
| 102 |
| 103 DISALLOW_COPY_AND_ASSIGN(FFmpegVideoDecoder); |
| 23 }; | 104 }; |
| 24 | 105 |
| 25 } // namespace media | 106 } // namespace media |
| 26 | 107 |
| 27 #endif // MEDIA_FILTERS_FFMPEG_VIDEO_DECODER_H_ | 108 #endif // MEDIA_FILTERS_FFMPEG_VIDEO_DECODER_H_ |
| OLD | NEW |