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

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: Rebase 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 = 1234;
wuchengli 2014/12/09 14:29:25 Why this has been changed?
hellner1 2014/12/10 22:38:59 It happened during debugging. I put the old value
17
18 struct FakeVideoEncodeAccelerator::BitstreamBufferRef {
19 BitstreamBufferRef(int id, scoped_ptr<base::SharedMemory> shm, size_t size)
20 : id(id), shm(shm.Pass()), size(size) {}
21 const int id;
22 const scoped_ptr<base::SharedMemory> shm;
23 const size_t size;
24 };
18 25
19 FakeVideoEncodeAccelerator::FakeVideoEncodeAccelerator( 26 FakeVideoEncodeAccelerator::FakeVideoEncodeAccelerator(
20 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, 27 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
21 std::vector<uint32>* stored_bitrates) 28 const std::vector<uint32>& stored_bitrates)
22 : task_runner_(task_runner), 29 : child_message_loop_proxy_(task_runner),
wuchengli 2014/12/09 14:29:25 I assume you don't force FakeVEA to run on the chi
hellner1 2014/12/10 22:38:59 Done.
23 stored_bitrates_(stored_bitrates), 30 stored_bitrates_(stored_bitrates),
24 client_(NULL), 31 client_(NULL),
25 first_(true), 32 first_(true),
26 will_initialization_succeed_(true), 33 weak_this_factory_(this) {}
27 weak_this_factory_(this) {
28 DCHECK(stored_bitrates_);
29 }
30 34
31 FakeVideoEncodeAccelerator::~FakeVideoEncodeAccelerator() { 35 FakeVideoEncodeAccelerator::~FakeVideoEncodeAccelerator() {
32 weak_this_factory_.InvalidateWeakPtrs(); 36 weak_this_factory_.InvalidateWeakPtrs();
33 } 37 }
34 38
35 std::vector<VideoEncodeAccelerator::SupportedProfile> 39 std::vector<VideoEncodeAccelerator::SupportedProfile>
36 FakeVideoEncodeAccelerator::GetSupportedProfiles() { 40 FakeVideoEncodeAccelerator::GetSupportedProfiles() {
37 return std::vector<VideoEncodeAccelerator::SupportedProfile>(); 41 return std::vector<VideoEncodeAccelerator::SupportedProfile>();
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 (output_profile == VIDEO_CODEC_PROFILE_UNKNOWN) {
wuchengli 2014/12/09 14:29:25 Return false for profile > VIDEO_CODEC_PROFILE_MAX
hellner1 2014/12/10 22:38:59 Done.
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;
wuchengli 2014/12/09 14:29:25 Why will_initialization_succeed_ is removed?
hellner1 2014/12/10 22:38:59 Done.
52 } 52 }
53 task_runner_->PostTask( 53 client_ = client;
54 child_message_loop_proxy_->PostTask(
54 FROM_HERE, 55 FROM_HERE,
55 base::Bind(&FakeVideoEncodeAccelerator::DoRequireBitstreamBuffers, 56 base::Bind(&FakeVideoEncodeAccelerator::DoRequireBitstreamBuffers,
56 weak_this_factory_.GetWeakPtr(), 57 weak_this_factory_.GetWeakPtr(),
57 kMinimumInputCount, 58 kMinimumInputCount,
58 input_visible_size, 59 input_visible_size,
59 kMinimumOutputBufferSize)); 60 kMinimumOutputBufferSize));
60 return true; 61 return true;
61 } 62 }
62 63
63 void FakeVideoEncodeAccelerator::Encode(const scoped_refptr<VideoFrame>& frame, 64 void FakeVideoEncodeAccelerator::Encode(
64 bool force_keyframe) { 65 const scoped_refptr<VideoFrame>& frame,
66 bool force_keyframe) {
65 DCHECK(client_); 67 DCHECK(client_);
66 DCHECK(!available_buffer_ids_.empty()); 68 DCHECK(!available_buffers_.empty());
67 69
68 // Fake that we have encoded the frame; resulting in using the full output 70 // Create fake encoded frame by just signaling that the buffer contains
69 // buffer. 71 // data. Note that the only thing written to the buffer is whether it is
70 int32 id = available_buffer_ids_.front(); 72 // a key frame or not.
71 available_buffer_ids_.pop_front(); 73 BitstreamBufferRef* buffer = available_buffers_.front().get();
74 int32 id = buffer->id;
75 bool is_key_frame = first_ || force_keyframe;
76 first_ = false;
72 77
73 bool is_key_fame = force_keyframe; 78 uint8* stream = static_cast<uint8*>(buffer->shm->memory());
74 if (first_) { 79 stream[0] = is_key_frame ? 0x00 : 0x01; // Key frame scheme = VP8
75 is_key_fame = true; 80 DoBitstreamBufferReady(id,
wuchengli 2014/12/09 14:29:25 Remove DoBitstreamBufferReady and just call client
hellner1 2014/12/10 22:38:59 I have to post here because calling client_->Bitst
wuchengli 2014/12/11 02:14:31 So you'll change this back to PostTask? The latest
hellner1 2014/12/11 19:34:19 Sorry, my bad here. Calling without posting does n
76 first_ = false; 81 kMinimumOutputBufferSize,
77 } 82 is_key_frame);
78 task_runner_->PostTask( 83 available_buffers_.pop_front();
79 FROM_HERE,
80 base::Bind(&FakeVideoEncodeAccelerator::DoBitstreamBufferReady,
81 weak_this_factory_.GetWeakPtr(),
82 id,
83 kMinimumOutputBufferSize,
84 is_key_fame));
85 } 84 }
86 85
87 void FakeVideoEncodeAccelerator::UseOutputBitstreamBuffer( 86 void FakeVideoEncodeAccelerator::UseOutputBitstreamBuffer(
88 const BitstreamBuffer& buffer) { 87 const BitstreamBuffer& buffer) {
89 available_buffer_ids_.push_back(buffer.id()); 88 scoped_ptr<base::SharedMemory> shm(
89 new base::SharedMemory(buffer.handle(), false));
90 if (!shm->Map(buffer.size())) {
91 LOG(ERROR) << "Shared memory failure";
92 return;
93 }
94 available_buffers_.push_back(
wuchengli 2014/12/09 14:29:25 Can we store BitstreamBuffer in |available_buffers
hellner1 2014/12/10 22:38:59 FYI: this behavior is taken from here: https://cod
wuchengli 2014/12/11 02:14:31 I guess v4l2VEA needs to map the memory in UseOutp
hellner1 2014/12/11 19:34:19 Done.
95 scoped_ptr<BitstreamBufferRef>(
96 new BitstreamBufferRef(buffer.id(), shm.Pass(), buffer.size())));
90 } 97 }
91 98
92 void FakeVideoEncodeAccelerator::RequestEncodingParametersChange( 99 void FakeVideoEncodeAccelerator::RequestEncodingParametersChange(
93 uint32 bitrate, 100 uint32 bitrate,
94 uint32 framerate) { 101 uint32 framerate) {
95 stored_bitrates_->push_back(bitrate); 102 stored_bitrates_.push_back(bitrate);
96 } 103 }
97 104
98 void FakeVideoEncodeAccelerator::Destroy() { delete this; } 105 void FakeVideoEncodeAccelerator::Destroy() { delete this; }
99 106
100 void FakeVideoEncodeAccelerator::SendDummyFrameForTesting(bool key_frame) { 107 void FakeVideoEncodeAccelerator::SendDummyFrameForTesting(bool key_frame) {
101 DoBitstreamBufferReady(0, 23, key_frame); 108 DoBitstreamBufferReady(0, 23, key_frame);
102 } 109 }
103 110
111 void FakeVideoEncodeAccelerator::SetWillInitializationSucceed(
112 bool will_initialization_succeed) {
113 will_initialization_succeed_ = will_initialization_succeed;
114 }
115
104 void FakeVideoEncodeAccelerator::DoRequireBitstreamBuffers( 116 void FakeVideoEncodeAccelerator::DoRequireBitstreamBuffers(
105 unsigned int input_count, 117 unsigned int input_count,
106 const gfx::Size& input_coded_size, 118 const gfx::Size& input_coded_size,
107 size_t output_buffer_size) const { 119 size_t output_buffer_size) const {
108 client_->RequireBitstreamBuffers( 120 client_->RequireBitstreamBuffers(
109 input_count, input_coded_size, output_buffer_size); 121 input_count, input_coded_size, output_buffer_size);
110 } 122 }
111 123
112 void FakeVideoEncodeAccelerator::DoBitstreamBufferReady( 124 void FakeVideoEncodeAccelerator::DoBitstreamBufferReady(
113 int32 bitstream_buffer_id, 125 int32 bitstream_buffer_id,
114 size_t payload_size, 126 size_t payload_size,
115 bool key_frame) const { 127 bool key_frame) const {
116 client_->BitstreamBufferReady(bitstream_buffer_id, payload_size, key_frame); 128 client_->BitstreamBufferReady(bitstream_buffer_id, payload_size, key_frame);
117 } 129 }
118 130
119 } // namespace test
120 } // namespace cast
121 } // namespace media 131 } // 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