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_
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"
19 class SingleThreadTaskRunner
;
25 class MEDIA_EXPORT FakeVideoEncodeAccelerator
: public VideoEncodeAccelerator
{
27 explicit FakeVideoEncodeAccelerator(
28 const scoped_refptr
<base::SingleThreadTaskRunner
>& task_runner
);
29 ~FakeVideoEncodeAccelerator() override
;
31 std::vector
<VideoEncodeAccelerator::SupportedProfile
> GetSupportedProfiles()
33 bool Initialize(VideoFrame::Format input_format
,
34 const gfx::Size
& input_visible_size
,
35 VideoCodecProfile output_profile
,
36 uint32 initial_bitrate
,
37 Client
* client
) override
;
38 void Encode(const scoped_refptr
<VideoFrame
>& frame
,
39 bool force_keyframe
) override
;
40 void UseOutputBitstreamBuffer(const BitstreamBuffer
& buffer
) override
;
41 void RequestEncodingParametersChange(uint32 bitrate
,
42 uint32 framerate
) override
;
43 void Destroy() override
;
45 const std::vector
<uint32
>& stored_bitrates() const {
46 return stored_bitrates_
;
48 void SendDummyFrameForTesting(bool key_frame
);
49 void SetWillInitializationSucceed(bool will_initialization_succeed
);
52 void DoRequireBitstreamBuffers(unsigned int input_count
,
53 const gfx::Size
& input_coded_size
,
54 size_t output_buffer_size
) const;
56 void DoBitstreamBufferReady(int32 bitstream_buffer_id
,
58 bool key_frame
) const;
60 // Our original (constructor) calling message loop used for all tasks.
61 const scoped_refptr
<base::SingleThreadTaskRunner
> task_runner_
;
62 std::vector
<uint32
> stored_bitrates_
;
63 bool will_initialization_succeed_
;
65 VideoEncodeAccelerator::Client
* client_
;
67 // Keeps track of if the current frame is the first encoded frame. This
68 // is used to force a fake key frame for the first encoded frame.
69 bool next_frame_is_first_frame_
;
71 // A queue containing the necessary data for incoming frames. The boolean
72 // represent whether the queued frame should force a key frame.
73 std::queue
<bool> queued_frames_
;
75 // A list of buffers available for putting fake encoded frames in.
76 std::list
<BitstreamBuffer
> available_buffers_
;
78 base::WeakPtrFactory
<FakeVideoEncodeAccelerator
> weak_this_factory_
;
80 DISALLOW_COPY_AND_ASSIGN(FakeVideoEncodeAccelerator
);
85 #endif // MEDIA_VIDEO_FAKE_VIDEO_ENCODE_ACCELERATOR_H_