1 // Copyright 2013 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.
5 #ifndef MEDIA_FILTERS_FAKE_VIDEO_DECODER_H_
6 #define MEDIA_FILTERS_FAKE_VIDEO_DECODER_H_
10 #include "base/bind.h"
11 #include "base/callback.h"
12 #include "base/callback_helpers.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/threading/thread_checker.h"
15 #include "media/base/callback_holder.h"
16 #include "media/base/decoder_buffer.h"
17 #include "media/base/pipeline_status.h"
18 #include "media/base/video_decoder.h"
19 #include "media/base/video_decoder_config.h"
20 #include "media/base/video_frame.h"
21 #include "ui/gfx/size.h"
23 using base::ResetAndReturn;
26 class SingleThreadTaskRunner;
31 class FakeVideoDecoder : public VideoDecoder {
33 // Constructs an object with a decoding delay of |decoding_delay| frames.
34 FakeVideoDecoder(int decoding_delay,
35 bool supports_get_decode_output,
36 int max_parallel_decoding_requests);
37 virtual ~FakeVideoDecoder();
39 // VideoDecoder implementation.
40 virtual void Initialize(const VideoDecoderConfig& config,
42 const PipelineStatusCB& status_cb) OVERRIDE;
43 virtual void Decode(const scoped_refptr<DecoderBuffer>& buffer,
44 const DecodeCB& decode_cb) OVERRIDE;
45 virtual void Reset(const base::Closure& closure) OVERRIDE;
46 virtual void Stop() OVERRIDE;
47 virtual scoped_refptr<VideoFrame> GetDecodeOutput() OVERRIDE;
48 virtual int GetMaxDecodeRequests() const OVERRIDE;
50 // Holds the next init/decode/reset callback from firing.
55 // Satisfies the pending init/decode/reset callback, which must be ready to
56 // fire when these methods are called.
61 // Satisfies single decode request.
62 void SatisfySingleDecode();
66 int total_bytes_decoded() const { return total_bytes_decoded_; }
76 // Callback for updating |total_bytes_decoded_|.
77 void OnFrameDecoded(int buffer_size,
78 const DecodeCB& decode_cb,
80 const scoped_refptr<VideoFrame>& video_frame);
82 // Runs |decode_cb| or puts it to |held_decode_callbacks_| depending on
83 // current value of |hold_decode_|.
84 void RunOrHoldDecode(const DecodeCB& decode_cb);
86 // Runs |decode_cb| with a frame from |decoded_frames_|.
87 void RunDecodeCallback(const DecodeCB& decode_cb);
91 base::ThreadChecker thread_checker_;
93 const size_t decoding_delay_;
94 const bool supports_get_decode_output_;
95 const int max_parallel_decoding_requests_;
99 CallbackHolder<PipelineStatusCB> init_cb_;
100 CallbackHolder<base::Closure> reset_cb_;
103 std::list<DecodeCB> held_decode_callbacks_;
105 VideoDecoderConfig current_config_;
107 std::list<scoped_refptr<VideoFrame> > decoded_frames_;
109 int total_bytes_decoded_;
111 // NOTE: Weak pointers must be invalidated before all other member variables.
112 base::WeakPtrFactory<FakeVideoDecoder> weak_factory_;
114 DISALLOW_COPY_AND_ASSIGN(FakeVideoDecoder);
119 #endif // MEDIA_FILTERS_FAKE_VIDEO_DECODER_H_