Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(91)

Side by Side Diff: media/video/fake_video_encode_accelerator.cc

Issue 760963003: Adds fake hardware video encoder. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed broken unittest Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/video/fake_video_encode_accelerator.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/cast/test/fake_video_encode_accelerator.h" 5 #include "media/video/fake_video_encode_accelerator.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/single_thread_task_runner.h" 10 #include "base/single_thread_task_runner.h"
11 11
12 namespace media { 12 namespace media {
13 namespace cast {
14 namespace test {
15 13
16 static const unsigned int kMinimumInputCount = 1; 14 static const unsigned int kMinimumInputCount = 1;
17 static const size_t kMinimumOutputBufferSize = 123456; 15 static const size_t kMinimumOutputBufferSize = 123456;
18 16
19 FakeVideoEncodeAccelerator::FakeVideoEncodeAccelerator( 17 FakeVideoEncodeAccelerator::FakeVideoEncodeAccelerator(
20 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, 18 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner)
21 std::vector<uint32>* stored_bitrates)
22 : task_runner_(task_runner), 19 : task_runner_(task_runner),
23 stored_bitrates_(stored_bitrates), 20 will_initialization_succeed_(true),
24 client_(NULL), 21 client_(NULL),
25 first_(true), 22 next_frame_is_first_frame_(true),
26 will_initialization_succeed_(true), 23 weak_this_factory_(this) {}
27 weak_this_factory_(this) {
28 DCHECK(stored_bitrates_);
29 }
30 24
31 FakeVideoEncodeAccelerator::~FakeVideoEncodeAccelerator() { 25 FakeVideoEncodeAccelerator::~FakeVideoEncodeAccelerator() {
32 weak_this_factory_.InvalidateWeakPtrs(); 26 weak_this_factory_.InvalidateWeakPtrs();
33 } 27 }
34 28
35 std::vector<VideoEncodeAccelerator::SupportedProfile> 29 std::vector<VideoEncodeAccelerator::SupportedProfile>
36 FakeVideoEncodeAccelerator::GetSupportedProfiles() { 30 FakeVideoEncodeAccelerator::GetSupportedProfiles() {
37 return std::vector<VideoEncodeAccelerator::SupportedProfile>(); 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;
36
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;
38 } 42 }
39 43
40 bool FakeVideoEncodeAccelerator::Initialize( 44 bool FakeVideoEncodeAccelerator::Initialize(
41 media::VideoFrame::Format input_format, 45 VideoFrame::Format input_format,
42 const gfx::Size& input_visible_size, 46 const gfx::Size& input_visible_size,
43 VideoCodecProfile output_profile, 47 VideoCodecProfile output_profile,
44 uint32 initial_bitrate, 48 uint32 initial_bitrate,
45 Client* client) { 49 Client* client) {
46 if (!will_initialization_succeed_) 50 if (!will_initialization_succeed_) {
47 return false;
48 client_ = client;
49 if (output_profile != media::VP8PROFILE_ANY &&
50 output_profile != media::H264PROFILE_MAIN) {
51 return false; 51 return false;
52 } 52 }
53 if (output_profile == VIDEO_CODEC_PROFILE_UNKNOWN ||
54 output_profile > VIDEO_CODEC_PROFILE_MAX) {
55 return false;
56 }
57 client_ = client;
53 task_runner_->PostTask( 58 task_runner_->PostTask(
54 FROM_HERE, 59 FROM_HERE,
55 base::Bind(&FakeVideoEncodeAccelerator::DoRequireBitstreamBuffers, 60 base::Bind(&FakeVideoEncodeAccelerator::DoRequireBitstreamBuffers,
56 weak_this_factory_.GetWeakPtr(), 61 weak_this_factory_.GetWeakPtr(),
57 kMinimumInputCount, 62 kMinimumInputCount,
58 input_visible_size, 63 input_visible_size,
59 kMinimumOutputBufferSize)); 64 kMinimumOutputBufferSize));
60 return true; 65 return true;
61 } 66 }
62 67
63 void FakeVideoEncodeAccelerator::Encode(const scoped_refptr<VideoFrame>& frame, 68 void FakeVideoEncodeAccelerator::Encode(
64 bool force_keyframe) { 69 const scoped_refptr<VideoFrame>& frame,
70 bool force_keyframe) {
65 DCHECK(client_); 71 DCHECK(client_);
66 DCHECK(!available_buffer_ids_.empty()); 72 queued_frames_.push(force_keyframe);
67 73 EncodeTask();
68 // Fake that we have encoded the frame; resulting in using the full output
69 // buffer.
70 int32 id = available_buffer_ids_.front();
71 available_buffer_ids_.pop_front();
72
73 bool is_key_fame = force_keyframe;
74 if (first_) {
75 is_key_fame = true;
76 first_ = false;
77 }
78 task_runner_->PostTask(
79 FROM_HERE,
80 base::Bind(&FakeVideoEncodeAccelerator::DoBitstreamBufferReady,
81 weak_this_factory_.GetWeakPtr(),
82 id,
83 kMinimumOutputBufferSize,
84 is_key_fame));
85 } 74 }
86 75
87 void FakeVideoEncodeAccelerator::UseOutputBitstreamBuffer( 76 void FakeVideoEncodeAccelerator::UseOutputBitstreamBuffer(
88 const BitstreamBuffer& buffer) { 77 const BitstreamBuffer& buffer) {
89 available_buffer_ids_.push_back(buffer.id()); 78 available_buffers_.push_back(buffer);
79 EncodeTask();
90 } 80 }
91 81
92 void FakeVideoEncodeAccelerator::RequestEncodingParametersChange( 82 void FakeVideoEncodeAccelerator::RequestEncodingParametersChange(
93 uint32 bitrate, 83 uint32 bitrate,
94 uint32 framerate) { 84 uint32 framerate) {
95 stored_bitrates_->push_back(bitrate); 85 stored_bitrates_.push_back(bitrate);
96 } 86 }
97 87
98 void FakeVideoEncodeAccelerator::Destroy() { delete this; } 88 void FakeVideoEncodeAccelerator::Destroy() { delete this; }
99 89
100 void FakeVideoEncodeAccelerator::SendDummyFrameForTesting(bool key_frame) { 90 void FakeVideoEncodeAccelerator::SendDummyFrameForTesting(bool key_frame) {
101 DoBitstreamBufferReady(0, 23, key_frame); 91 task_runner_->PostTask(
92 FROM_HERE,
93 base::Bind(&FakeVideoEncodeAccelerator::DoBitstreamBufferReady,
94 weak_this_factory_.GetWeakPtr(),
95 0,
96 23,
97 key_frame));
98 }
99
100 void FakeVideoEncodeAccelerator::SetWillInitializationSucceed(
101 bool will_initialization_succeed) {
102 will_initialization_succeed_ = will_initialization_succeed;
102 } 103 }
103 104
104 void FakeVideoEncodeAccelerator::DoRequireBitstreamBuffers( 105 void FakeVideoEncodeAccelerator::DoRequireBitstreamBuffers(
105 unsigned int input_count, 106 unsigned int input_count,
106 const gfx::Size& input_coded_size, 107 const gfx::Size& input_coded_size,
107 size_t output_buffer_size) const { 108 size_t output_buffer_size) const {
108 client_->RequireBitstreamBuffers( 109 client_->RequireBitstreamBuffers(
109 input_count, input_coded_size, output_buffer_size); 110 input_count, input_coded_size, output_buffer_size);
110 } 111 }
111 112
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));
128 }
129 }
130
112 void FakeVideoEncodeAccelerator::DoBitstreamBufferReady( 131 void FakeVideoEncodeAccelerator::DoBitstreamBufferReady(
113 int32 bitstream_buffer_id, 132 int32 bitstream_buffer_id,
114 size_t payload_size, 133 size_t payload_size,
115 bool key_frame) const { 134 bool key_frame) const {
116 client_->BitstreamBufferReady(bitstream_buffer_id, payload_size, key_frame); 135 client_->BitstreamBufferReady(bitstream_buffer_id,
136 payload_size,
137 key_frame);
117 } 138 }
118 139
119 } // namespace test
120 } // namespace cast
121 } // namespace media 140 } // namespace media
OLDNEW
« no previous file with comments | « media/video/fake_video_encode_accelerator.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698