Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / media / video / fake_video_encode_accelerator.h
blob91b6f1d4f77b0f52a6610e2a97a6a8321bf2e3d3
1 // Copyright 2014 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_VIDEO_FAKE_VIDEO_ENCODE_ACCELERATOR_H_
6 #define MEDIA_VIDEO_FAKE_VIDEO_ENCODE_ACCELERATOR_H_
8 #include <list>
9 #include <queue>
10 #include <vector>
12 #include "base/memory/weak_ptr.h"
13 #include "media/base/bitstream_buffer.h"
14 #include "media/base/media_export.h"
15 #include "media/video/video_encode_accelerator.h"
17 namespace base {
19 class SingleThreadTaskRunner;
21 } // namespace base
23 namespace media {
25 class MEDIA_EXPORT FakeVideoEncodeAccelerator : public VideoEncodeAccelerator {
26 public:
27 explicit FakeVideoEncodeAccelerator(
28 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner);
29 ~FakeVideoEncodeAccelerator() override;
31 VideoEncodeAccelerator::SupportedProfiles GetSupportedProfiles() override;
32 bool Initialize(VideoPixelFormat input_format,
33 const gfx::Size& input_visible_size,
34 VideoCodecProfile output_profile,
35 uint32 initial_bitrate,
36 Client* client) override;
37 void Encode(const scoped_refptr<VideoFrame>& frame,
38 bool force_keyframe) override;
39 void UseOutputBitstreamBuffer(const BitstreamBuffer& buffer) override;
40 void RequestEncodingParametersChange(uint32 bitrate,
41 uint32 framerate) override;
42 void Destroy() override;
44 const std::vector<uint32>& stored_bitrates() const {
45 return stored_bitrates_;
47 void SendDummyFrameForTesting(bool key_frame);
48 void SetWillInitializationSucceed(bool will_initialization_succeed);
50 private:
51 void DoRequireBitstreamBuffers(unsigned int input_count,
52 const gfx::Size& input_coded_size,
53 size_t output_buffer_size) const;
54 void EncodeTask();
55 void DoBitstreamBufferReady(int32 bitstream_buffer_id,
56 size_t payload_size,
57 bool key_frame) const;
59 // Our original (constructor) calling message loop used for all tasks.
60 const scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
61 std::vector<uint32> stored_bitrates_;
62 bool will_initialization_succeed_;
64 VideoEncodeAccelerator::Client* client_;
66 // Keeps track of if the current frame is the first encoded frame. This
67 // is used to force a fake key frame for the first encoded frame.
68 bool next_frame_is_first_frame_;
70 // A queue containing the necessary data for incoming frames. The boolean
71 // represent whether the queued frame should force a key frame.
72 std::queue<bool> queued_frames_;
74 // A list of buffers available for putting fake encoded frames in.
75 std::list<BitstreamBuffer> available_buffers_;
77 base::WeakPtrFactory<FakeVideoEncodeAccelerator> weak_this_factory_;
79 DISALLOW_COPY_AND_ASSIGN(FakeVideoEncodeAccelerator);
82 } // namespace media
84 #endif // MEDIA_VIDEO_FAKE_VIDEO_ENCODE_ACCELERATOR_H_