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 #include "media/cast/test/fake_video_encode_accelerator.h"
8 #include "base/location.h"
9 #include "base/logging.h"
10 #include "base/single_thread_task_runner.h"
16 static const unsigned int kMinimumInputCount
= 1;
17 static const size_t kMinimumOutputBufferSize
= 123456;
19 FakeVideoEncodeAccelerator::FakeVideoEncodeAccelerator(
20 const scoped_refptr
<base::SingleThreadTaskRunner
>& task_runner
)
21 : task_runner_(task_runner
),
24 weak_this_factory_(this) {}
26 FakeVideoEncodeAccelerator::~FakeVideoEncodeAccelerator() {
27 weak_this_factory_
.InvalidateWeakPtrs();
30 bool FakeVideoEncodeAccelerator::Initialize(
31 media::VideoFrame::Format input_format
,
32 const gfx::Size
& input_visible_size
,
33 VideoCodecProfile output_profile
,
34 uint32 initial_bitrate
,
37 if (output_profile
!= media::VP8PROFILE_MAIN
&&
38 output_profile
!= media::H264PROFILE_MAIN
) {
41 task_runner_
->PostTask(
43 base::Bind(&FakeVideoEncodeAccelerator::DoRequireBitstreamBuffers
,
44 weak_this_factory_
.GetWeakPtr(),
47 kMinimumOutputBufferSize
));
51 void FakeVideoEncodeAccelerator::Encode(const scoped_refptr
<VideoFrame
>& frame
,
52 bool force_keyframe
) {
54 DCHECK(!available_buffer_ids_
.empty());
56 // Fake that we have encoded the frame; resulting in using the full output
58 int32 id
= available_buffer_ids_
.front();
59 available_buffer_ids_
.pop_front();
61 bool is_key_fame
= force_keyframe
;
66 task_runner_
->PostTask(
68 base::Bind(&FakeVideoEncodeAccelerator::DoBitstreamBufferReady
,
69 weak_this_factory_
.GetWeakPtr(),
71 kMinimumOutputBufferSize
,
75 void FakeVideoEncodeAccelerator::UseOutputBitstreamBuffer(
76 const BitstreamBuffer
& buffer
) {
77 available_buffer_ids_
.push_back(buffer
.id());
80 void FakeVideoEncodeAccelerator::RequestEncodingParametersChange(
86 void FakeVideoEncodeAccelerator::Destroy() { delete this; }
88 void FakeVideoEncodeAccelerator::SendDummyFrameForTesting(bool key_frame
) {
89 DoBitstreamBufferReady(0, 23, key_frame
);
92 void FakeVideoEncodeAccelerator::DoRequireBitstreamBuffers(
93 unsigned int input_count
,
94 const gfx::Size
& input_coded_size
,
95 size_t output_buffer_size
) const {
96 client_
->RequireBitstreamBuffers(
97 input_count
, input_coded_size
, output_buffer_size
);
100 void FakeVideoEncodeAccelerator::DoBitstreamBufferReady(
101 int32 bitstream_buffer_id
,
103 bool key_frame
) const {
104 client_
->BitstreamBufferReady(bitstream_buffer_id
, payload_size
, key_frame
);