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 int max_parallel_decoding_requests
);
36 ~FakeVideoDecoder() override
;
38 // VideoDecoder implementation.
39 std::string
GetDisplayName() const override
;
40 void Initialize(const VideoDecoderConfig
& config
,
42 const PipelineStatusCB
& status_cb
,
43 const OutputCB
& output_cb
) override
;
44 void Decode(const scoped_refptr
<DecoderBuffer
>& buffer
,
45 const DecodeCB
& decode_cb
) override
;
46 void Reset(const base::Closure
& closure
) override
;
47 int GetMaxDecodeRequests() const override
;
49 // Holds the next init/decode/reset callback from firing.
54 // Satisfies the pending init/decode/reset callback, which must be ready to
55 // fire when these methods are called.
60 // Satisfies single decode request.
61 void SatisfySingleDecode();
65 int total_bytes_decoded() const { return total_bytes_decoded_
; }
75 // Callback for updating |total_bytes_decoded_|.
76 void OnFrameDecoded(int buffer_size
,
77 const DecodeCB
& decode_cb
,
80 // Runs |decode_cb| or puts it to |held_decode_callbacks_| depending on
81 // current value of |hold_decode_|.
82 void RunOrHoldDecode(const DecodeCB
& decode_cb
);
84 // Runs |decode_cb| with a frame from |decoded_frames_|.
85 void RunDecodeCallback(const DecodeCB
& decode_cb
);
89 base::ThreadChecker thread_checker_
;
91 const size_t decoding_delay_
;
92 const int max_parallel_decoding_requests_
;
96 CallbackHolder
<PipelineStatusCB
> init_cb_
;
97 CallbackHolder
<base::Closure
> reset_cb_
;
102 std::list
<DecodeCB
> held_decode_callbacks_
;
104 VideoDecoderConfig current_config_
;
106 std::list
<scoped_refptr
<VideoFrame
> > decoded_frames_
;
108 int total_bytes_decoded_
;
110 // NOTE: Weak pointers must be invalidated before all other member variables.
111 base::WeakPtrFactory
<FakeVideoDecoder
> weak_factory_
;
113 DISALLOW_COPY_AND_ASSIGN(FakeVideoDecoder
);
118 #endif // MEDIA_FILTERS_FAKE_VIDEO_DECODER_H_