Roll src/breakpad/src 3ea146d:57c3d7c (svn 1405:1407)
[chromium-blink-merge.git] / media / filters / fake_video_decoder.h
blobd7150b695308d074e1de740aedd4b3bfc376528f
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/size.h"
23 using base::ResetAndReturn;
25 namespace base {
26 class SingleThreadTaskRunner;
29 namespace media {
31 class FakeVideoDecoder : public VideoDecoder {
32 public:
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,
41 bool low_delay,
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.
50 void HoldNextInit();
51 void HoldDecode();
52 void HoldNextReset();
54 // Satisfies the pending init/decode/reset callback, which must be ready to
55 // fire when these methods are called.
56 void SatisfyInit();
57 void SatisfyDecode();
58 void SatisfyReset();
60 // Satisfies single decode request.
61 void SatisfySingleDecode();
63 void SimulateError();
65 int total_bytes_decoded() const { return total_bytes_decoded_; }
67 private:
68 enum State {
69 STATE_UNINITIALIZED,
70 STATE_NORMAL,
71 STATE_END_OF_STREAM,
72 STATE_ERROR,
75 // Callback for updating |total_bytes_decoded_|.
76 void OnFrameDecoded(int buffer_size,
77 const DecodeCB& decode_cb,
78 Status status);
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);
87 void DoReset();
89 base::ThreadChecker thread_checker_;
91 const size_t decoding_delay_;
92 const int max_parallel_decoding_requests_;
94 State state_;
96 CallbackHolder<PipelineStatusCB> init_cb_;
97 CallbackHolder<base::Closure> reset_cb_;
99 OutputCB output_cb_;
101 bool hold_decode_;
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);
116 } // namespace media
118 #endif // MEDIA_FILTERS_FAKE_VIDEO_DECODER_H_