| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef MEDIA_FILTERS_VIDEO_DECODER_IMPL_H_ | |
| 6 #define MEDIA_FILTERS_VIDEO_DECODER_IMPL_H_ | |
| 7 | |
| 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; | |
| 16 | |
| 17 namespace media { | |
| 18 | |
| 19 class VideoDecodeEngine; | |
| 20 | |
| 21 class VideoDecoderImpl : public DecoderBase<VideoDecoder, VideoFrame> { | |
| 22 protected: | |
| 23 VideoDecoderImpl(VideoDecodeEngine* engine); | |
| 24 | |
| 25 // Make this class abstract to document that this class cannot be used | |
| 26 // directly as a filter type because it does not implement the static methods | |
| 27 // CreateFactory() and IsMediaFormatSupported(). | |
| 28 // | |
| 29 // TODO(ajwong): When we clean up the filters to not required a static | |
| 30 // implementation of CreateFactory() and IsMediaFormatSupported(), this | |
| 31 // class doesn't probably need to be abstract. | |
| 32 virtual ~VideoDecoderImpl() = 0; | |
| 33 | |
| 34 virtual void DoInitialize(DemuxerStream* demuxer_stream, bool* success, | |
| 35 Task* done_cb); | |
| 36 virtual void DoSeek(base::TimeDelta time, Task* done_cb); | |
| 37 virtual void DoDecode(Buffer* input); | |
| 38 | |
| 39 protected: | |
| 40 virtual void OnEmptyBufferDone(scoped_refptr<Buffer> buffer); | |
| 41 | |
| 42 private: | |
| 43 friend class FilterFactoryImpl1<VideoDecoderImpl, VideoDecodeEngine*>; | |
| 44 friend class DecoderPrivateMock; | |
| 45 friend class VideoDecoderImplTest; | |
| 46 FRIEND_TEST(VideoDecoderImplTest, FindPtsAndDuration); | |
| 47 FRIEND_TEST(VideoDecoderImplTest, DoDecode_EnqueueVideoFrameError); | |
| 48 FRIEND_TEST(VideoDecoderImplTest, DoDecode_FinishEnqueuesEmptyFrames); | |
| 49 FRIEND_TEST(VideoDecoderImplTest, DoDecode_TestStateTransition); | |
| 50 FRIEND_TEST(VideoDecoderImplTest, DoSeek); | |
| 51 | |
| 52 // The TimeTuple struct is used to hold the needed timestamp data needed for | |
| 53 // enqueuing a video frame. | |
| 54 struct TimeTuple { | |
| 55 base::TimeDelta timestamp; | |
| 56 base::TimeDelta duration; | |
| 57 }; | |
| 58 | |
| 59 enum DecoderState { | |
| 60 kNormal, | |
| 61 kFlushCodec, | |
| 62 kDecodeFinished, | |
| 63 }; | |
| 64 | |
| 65 // Implement DecoderBase template methods. | |
| 66 virtual void EnqueueVideoFrame(const scoped_refptr<VideoFrame>& video_frame); | |
| 67 | |
| 68 // Create an empty video frame and queue it. | |
| 69 virtual void EnqueueEmptyFrame(); | |
| 70 | |
| 71 // Methods that pickup after the decode engine has finished its action. | |
| 72 virtual void OnInitializeComplete(bool* success /* Not owned */, | |
| 73 Task* done_cb); | |
| 74 | |
| 75 virtual void OnDecodeComplete(scoped_refptr<VideoFrame> video_frame); | |
| 76 | |
| 77 // Attempt to get the PTS and Duration for this frame by examining the time | |
| 78 // info provided via packet stream (stored in |pts_heap|), or the info | |
| 79 // writen into the AVFrame itself. If no data is available in either, then | |
| 80 // attempt to generate a best guess of the pts based on the last known pts. | |
| 81 // | |
| 82 // Data inside the AVFrame (if provided) is trusted the most, followed | |
| 83 // by data from the packet stream. Estimation based on the |last_pts| is | |
| 84 // reserved as a last-ditch effort. | |
| 85 virtual TimeTuple FindPtsAndDuration(const AVRational& time_base, | |
| 86 PtsHeap* pts_heap, | |
| 87 const TimeTuple& last_pts, | |
| 88 const VideoFrame* frame); | |
| 89 | |
| 90 // Signals the pipeline that a decode error occurs, and moves the decoder | |
| 91 // into the kDecodeFinished state. | |
| 92 virtual void SignalPipelineError(); | |
| 93 | |
| 94 // Injection point for unittest to provide a mock engine. Takes ownership of | |
| 95 // the provided engine. | |
| 96 virtual void SetVideoDecodeEngineForTest(VideoDecodeEngine* engine); | |
| 97 | |
| 98 size_t width_; | |
| 99 size_t height_; | |
| 100 | |
| 101 PtsHeap pts_heap_; // Heap of presentation timestamps. | |
| 102 TimeTuple last_pts_; | |
| 103 scoped_ptr<AVRational> time_base_; // Pointer to avoid needing full type. | |
| 104 DecoderState state_; | |
| 105 scoped_ptr<VideoDecodeEngine> decode_engine_; | |
| 106 | |
| 107 DISALLOW_COPY_AND_ASSIGN(VideoDecoderImpl); | |
| 108 }; | |
| 109 | |
| 110 } // namespace media | |
| 111 | |
| 112 #endif // MEDIA_FILTERS_VIDEO_DECODER_IMPL_H_ | |
| OLD | NEW |