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

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: updates according to comments Created 6 years 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
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/message_loop/message_loop_proxy.h"
10 #include "base/single_thread_task_runner.h" 11 #include "base/single_thread_task_runner.h"
11 12
12 namespace media { 13 namespace media {
13 namespace cast {
14 namespace test {
15 14
16 static const unsigned int kMinimumInputCount = 1; 15 static const unsigned int kMinimumInputCount = 1;
17 static const size_t kMinimumOutputBufferSize = 123456; 16 static const size_t kMinimumOutputBufferSize = 123456;
18 17
19 FakeVideoEncodeAccelerator::FakeVideoEncodeAccelerator( 18 FakeVideoEncodeAccelerator::FakeVideoEncodeAccelerator(
20 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, 19 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner)
21 std::vector<uint32>* stored_bitrates)
22 : task_runner_(task_runner), 20 : task_runner_(task_runner),
23 stored_bitrates_(stored_bitrates), 21 will_initialization_succeed_(true),
24 client_(NULL), 22 client_(NULL),
25 first_(true), 23 first_(true),
26 will_initialization_succeed_(true), 24 weak_this_factory_(this) {}
27 weak_this_factory_(this) {
28 DCHECK(stored_bitrates_);
29 }
30 25
31 FakeVideoEncodeAccelerator::~FakeVideoEncodeAccelerator() { 26 FakeVideoEncodeAccelerator::~FakeVideoEncodeAccelerator() {
32 weak_this_factory_.InvalidateWeakPtrs(); 27 weak_this_factory_.InvalidateWeakPtrs();
33 } 28 }
34 29
35 std::vector<VideoEncodeAccelerator::SupportedProfile> 30 std::vector<VideoEncodeAccelerator::SupportedProfile>
36 FakeVideoEncodeAccelerator::GetSupportedProfiles() { 31 FakeVideoEncodeAccelerator::GetSupportedProfiles() {
37 return std::vector<VideoEncodeAccelerator::SupportedProfile>(); 32 return std::vector<VideoEncodeAccelerator::SupportedProfile>();
38 } 33 }
39 34
40 bool FakeVideoEncodeAccelerator::Initialize( 35 bool FakeVideoEncodeAccelerator::Initialize(
41 media::VideoFrame::Format input_format, 36 VideoFrame::Format input_format,
42 const gfx::Size& input_visible_size, 37 const gfx::Size& input_visible_size,
43 VideoCodecProfile output_profile, 38 VideoCodecProfile output_profile,
44 uint32 initial_bitrate, 39 uint32 initial_bitrate,
45 Client* client) { 40 Client* client) {
46 if (!will_initialization_succeed_) 41 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; 42 return false;
52 } 43 }
44 if (output_profile == VIDEO_CODEC_PROFILE_UNKNOWN ||
45 output_profile > VIDEO_CODEC_PROFILE_MAX) {
46 return false;
47 }
48 client_ = client;
53 task_runner_->PostTask( 49 task_runner_->PostTask(
54 FROM_HERE, 50 FROM_HERE,
55 base::Bind(&FakeVideoEncodeAccelerator::DoRequireBitstreamBuffers, 51 base::Bind(&FakeVideoEncodeAccelerator::DoRequireBitstreamBuffers,
56 weak_this_factory_.GetWeakPtr(), 52 weak_this_factory_.GetWeakPtr(),
57 kMinimumInputCount, 53 kMinimumInputCount,
58 input_visible_size, 54 input_visible_size,
59 kMinimumOutputBufferSize)); 55 kMinimumOutputBufferSize));
60 return true; 56 return true;
61 } 57 }
62 58
63 void FakeVideoEncodeAccelerator::Encode(const scoped_refptr<VideoFrame>& frame, 59 void FakeVideoEncodeAccelerator::Encode(
64 bool force_keyframe) { 60 const scoped_refptr<VideoFrame>& frame,
61 bool force_keyframe) {
65 DCHECK(client_); 62 DCHECK(client_);
66 DCHECK(!available_buffer_ids_.empty()); 63 queued_frames_.push(force_keyframe);
67 64 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 } 65 }
86 66
87 void FakeVideoEncodeAccelerator::UseOutputBitstreamBuffer( 67 void FakeVideoEncodeAccelerator::UseOutputBitstreamBuffer(
88 const BitstreamBuffer& buffer) { 68 const BitstreamBuffer& buffer) {
89 available_buffer_ids_.push_back(buffer.id()); 69 available_buffers_.push_back(buffer);
70 EncodeTask();
90 } 71 }
91 72
92 void FakeVideoEncodeAccelerator::RequestEncodingParametersChange( 73 void FakeVideoEncodeAccelerator::RequestEncodingParametersChange(
93 uint32 bitrate, 74 uint32 bitrate,
94 uint32 framerate) { 75 uint32 framerate) {
95 stored_bitrates_->push_back(bitrate); 76 stored_bitrates_.push_back(bitrate);
96 } 77 }
97 78
98 void FakeVideoEncodeAccelerator::Destroy() { delete this; } 79 void FakeVideoEncodeAccelerator::Destroy() { delete this; }
99 80
100 void FakeVideoEncodeAccelerator::SendDummyFrameForTesting(bool key_frame) { 81 void FakeVideoEncodeAccelerator::SendDummyFrameForTesting(bool key_frame) {
101 DoBitstreamBufferReady(0, 23, key_frame); 82 queued_frames_.push(key_frame);
83 EncodeTask();
wuchengli 2014/12/16 02:21:48 This should call DoBitstreamBufferReady to have th
hellner1 2014/12/16 20:14:08 What should I use for |bitstream_buffer_id| if the
wuchengli 2014/12/17 03:21:22 You are right. The original FakeVideoEncodeAcceler
84 }
85
86 void FakeVideoEncodeAccelerator::SetWillInitializationSucceed(
87 bool will_initialization_succeed) {
88 will_initialization_succeed_ = will_initialization_succeed;
102 } 89 }
103 90
104 void FakeVideoEncodeAccelerator::DoRequireBitstreamBuffers( 91 void FakeVideoEncodeAccelerator::DoRequireBitstreamBuffers(
105 unsigned int input_count, 92 unsigned int input_count,
106 const gfx::Size& input_coded_size, 93 const gfx::Size& input_coded_size,
107 size_t output_buffer_size) const { 94 size_t output_buffer_size) const {
108 client_->RequireBitstreamBuffers( 95 client_->RequireBitstreamBuffers(
109 input_count, input_coded_size, output_buffer_size); 96 input_count, input_coded_size, output_buffer_size);
110 } 97 }
111 98
99 void FakeVideoEncodeAccelerator::EncodeTask() {
100 while (!queued_frames_.empty() && !available_buffers_.empty()) {
101 bool force_key_frame = queued_frames_.front();
102 queued_frames_.pop();
103 int32 bitstream_buffer_id = available_buffers_.front().id();
104 available_buffers_.pop_front();
105 bool key_frame = first_ || force_key_frame;
106 first_ = false;
107 task_runner_->PostTask(
108 FROM_HERE,
109 base::Bind(&FakeVideoEncodeAccelerator::DoBitstreamBufferReady,
110 weak_this_factory_.GetWeakPtr(),
111 bitstream_buffer_id,
112 kMinimumOutputBufferSize,
113 key_frame));
114 }
115 }
116
112 void FakeVideoEncodeAccelerator::DoBitstreamBufferReady( 117 void FakeVideoEncodeAccelerator::DoBitstreamBufferReady(
113 int32 bitstream_buffer_id, 118 int32 bitstream_buffer_id,
114 size_t payload_size, 119 size_t kMinimumOutputBufferSize,
wuchengli 2014/12/16 02:21:48 s/kMinimumOutputBufferSize/payload_size/
hellner1 2014/12/16 20:14:08 Done. Thanks!
115 bool key_frame) const { 120 bool key_frame) {
116 client_->BitstreamBufferReady(bitstream_buffer_id, payload_size, key_frame); 121 client_->BitstreamBufferReady(bitstream_buffer_id,
122 kMinimumOutputBufferSize,
wuchengli 2014/12/16 02:21:48 s/kMinimumOutputBufferSize/payload_size/
hellner1 2014/12/16 20:14:08 Done.
123 key_frame);
117 } 124 }
118 125
119 } // namespace test
120 } // namespace cast
121 } // namespace media 126 } // namespace media
OLDNEW
« media/video/fake_video_encode_accelerator.h ('K') | « 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