Disable FileSystemProviderApiTest.BigFile
[chromium-blink-merge.git] / media / video / fake_video_encode_accelerator.cc
blob4ca7a236ca1e1a10b8e9b8a4fb57e86f569fd4ce
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/video/fake_video_encode_accelerator.h"
7 #include "base/bind.h"
8 #include "base/location.h"
9 #include "base/logging.h"
10 #include "base/single_thread_task_runner.h"
12 namespace media {
14 static const unsigned int kMinimumInputCount = 1;
15 static const size_t kMinimumOutputBufferSize = 123456;
17 FakeVideoEncodeAccelerator::FakeVideoEncodeAccelerator(
18 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner)
19 : task_runner_(task_runner),
20 will_initialization_succeed_(true),
21 client_(NULL),
22 next_frame_is_first_frame_(true),
23 weak_this_factory_(this) {}
25 FakeVideoEncodeAccelerator::~FakeVideoEncodeAccelerator() {
26 weak_this_factory_.InvalidateWeakPtrs();
29 std::vector<VideoEncodeAccelerator::SupportedProfile>
30 FakeVideoEncodeAccelerator::GetSupportedProfiles() {
31 std::vector<VideoEncodeAccelerator::SupportedProfile> profiles;
32 SupportedProfile profile;
33 profile.max_resolution.SetSize(1920, 1088);
34 profile.max_framerate_numerator = 30;
35 profile.max_framerate_denominator = 1;
37 profile.profile = media::H264PROFILE_MAIN;
38 profiles.push_back(profile);
39 profile.profile = media::VP8PROFILE_ANY;
40 profiles.push_back(profile);
41 return profiles;
44 bool FakeVideoEncodeAccelerator::Initialize(
45 VideoFrame::Format input_format,
46 const gfx::Size& input_visible_size,
47 VideoCodecProfile output_profile,
48 uint32 initial_bitrate,
49 Client* client) {
50 if (!will_initialization_succeed_) {
51 return false;
53 if (output_profile == VIDEO_CODEC_PROFILE_UNKNOWN ||
54 output_profile > VIDEO_CODEC_PROFILE_MAX) {
55 return false;
57 client_ = client;
58 task_runner_->PostTask(
59 FROM_HERE,
60 base::Bind(&FakeVideoEncodeAccelerator::DoRequireBitstreamBuffers,
61 weak_this_factory_.GetWeakPtr(),
62 kMinimumInputCount,
63 input_visible_size,
64 kMinimumOutputBufferSize));
65 return true;
68 void FakeVideoEncodeAccelerator::Encode(
69 const scoped_refptr<VideoFrame>& frame,
70 bool force_keyframe) {
71 DCHECK(client_);
72 queued_frames_.push(force_keyframe);
73 EncodeTask();
76 void FakeVideoEncodeAccelerator::UseOutputBitstreamBuffer(
77 const BitstreamBuffer& buffer) {
78 available_buffers_.push_back(buffer);
79 EncodeTask();
82 void FakeVideoEncodeAccelerator::RequestEncodingParametersChange(
83 uint32 bitrate,
84 uint32 framerate) {
85 stored_bitrates_.push_back(bitrate);
88 void FakeVideoEncodeAccelerator::Destroy() { delete this; }
90 void FakeVideoEncodeAccelerator::SendDummyFrameForTesting(bool key_frame) {
91 task_runner_->PostTask(
92 FROM_HERE,
93 base::Bind(&FakeVideoEncodeAccelerator::DoBitstreamBufferReady,
94 weak_this_factory_.GetWeakPtr(),
96 23,
97 key_frame));
100 void FakeVideoEncodeAccelerator::SetWillInitializationSucceed(
101 bool will_initialization_succeed) {
102 will_initialization_succeed_ = will_initialization_succeed;
105 void FakeVideoEncodeAccelerator::DoRequireBitstreamBuffers(
106 unsigned int input_count,
107 const gfx::Size& input_coded_size,
108 size_t output_buffer_size) const {
109 client_->RequireBitstreamBuffers(
110 input_count, input_coded_size, output_buffer_size);
113 void FakeVideoEncodeAccelerator::EncodeTask() {
114 while (!queued_frames_.empty() && !available_buffers_.empty()) {
115 bool force_key_frame = queued_frames_.front();
116 queued_frames_.pop();
117 int32 bitstream_buffer_id = available_buffers_.front().id();
118 available_buffers_.pop_front();
119 bool key_frame = next_frame_is_first_frame_ || force_key_frame;
120 next_frame_is_first_frame_ = false;
121 task_runner_->PostTask(
122 FROM_HERE,
123 base::Bind(&FakeVideoEncodeAccelerator::DoBitstreamBufferReady,
124 weak_this_factory_.GetWeakPtr(),
125 bitstream_buffer_id,
126 kMinimumOutputBufferSize,
127 key_frame));
131 void FakeVideoEncodeAccelerator::DoBitstreamBufferReady(
132 int32 bitstream_buffer_id,
133 size_t payload_size,
134 bool key_frame) const {
135 client_->BitstreamBufferReady(bitstream_buffer_id,
136 payload_size,
137 key_frame);
140 } // namespace media