Fix Mac GN build
[chromium-blink-merge.git] / media / filters / fake_video_decoder.h
blobbf407b995d0c02c5db69d2fca13191ac030e005c
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_
8 #include <list>
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/geometry/size.h"
23 using base::ResetAndReturn;
25 namespace base {
26 class SingleThreadTaskRunner;
29 namespace media {
31 typedef base::Callback<void(int)> BytesDecodedCB;
33 class FakeVideoDecoder : public VideoDecoder {
34 public:
35 // Constructs an object with a decoding delay of |decoding_delay| frames.
36 // |bytes_decoded_cb| is called after each decode. The sum of the byte
37 // count over all calls will be equal to total_bytes_decoded().
38 FakeVideoDecoder(int decoding_delay,
39 int max_parallel_decoding_requests,
40 const BytesDecodedCB& bytes_decoded_cb);
41 ~FakeVideoDecoder() override;
43 // VideoDecoder implementation.
44 std::string GetDisplayName() const override;
45 void Initialize(const VideoDecoderConfig& config,
46 bool low_delay,
47 const PipelineStatusCB& status_cb,
48 const OutputCB& output_cb) override;
49 void Decode(const scoped_refptr<DecoderBuffer>& buffer,
50 const DecodeCB& decode_cb) override;
51 void Reset(const base::Closure& closure) override;
52 int GetMaxDecodeRequests() const override;
54 // Holds the next init/decode/reset callback from firing.
55 void HoldNextInit();
56 void HoldDecode();
57 void HoldNextReset();
59 // Satisfies the pending init/decode/reset callback, which must be ready to
60 // fire when these methods are called.
61 void SatisfyInit();
62 void SatisfyDecode();
63 void SatisfyReset();
65 // Satisfies single decode request.
66 void SatisfySingleDecode();
68 void SimulateError();
69 // Fail with status DECODER_ERROR_NOT_SUPPORTED when Initialize() is called.
70 void SimulateFailureToInit();
72 int total_bytes_decoded() const { return total_bytes_decoded_; }
74 private:
75 enum State {
76 STATE_UNINITIALIZED,
77 STATE_NORMAL,
78 STATE_END_OF_STREAM,
79 STATE_ERROR,
82 // Callback for updating |total_bytes_decoded_|.
83 void OnFrameDecoded(int buffer_size,
84 const DecodeCB& decode_cb,
85 Status status);
87 // Runs |decode_cb| or puts it to |held_decode_callbacks_| depending on
88 // current value of |hold_decode_|.
89 void RunOrHoldDecode(const DecodeCB& decode_cb);
91 // Runs |decode_cb| with a frame from |decoded_frames_|.
92 void RunDecodeCallback(const DecodeCB& decode_cb);
94 void DoReset();
96 base::ThreadChecker thread_checker_;
98 const size_t decoding_delay_;
99 const int max_parallel_decoding_requests_;
100 BytesDecodedCB bytes_decoded_cb_;
102 State state_;
104 CallbackHolder<PipelineStatusCB> init_cb_;
105 CallbackHolder<base::Closure> reset_cb_;
107 OutputCB output_cb_;
109 bool hold_decode_;
110 std::list<DecodeCB> held_decode_callbacks_;
112 VideoDecoderConfig current_config_;
114 std::list<scoped_refptr<VideoFrame> > decoded_frames_;
116 int total_bytes_decoded_;
118 bool fail_to_initialize_;
120 // NOTE: Weak pointers must be invalidated before all other member variables.
121 base::WeakPtrFactory<FakeVideoDecoder> weak_factory_;
123 DISALLOW_COPY_AND_ASSIGN(FakeVideoDecoder);
126 } // namespace media
128 #endif // MEDIA_FILTERS_FAKE_VIDEO_DECODER_H_