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

Side by Side Diff: content/common/gpu/media/fake_video_decode_accelerator.cc

Issue 1839193003: Reland: Introduce GpuVideoDecodeAcceleratorFactory. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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
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 "content/common/gpu/media/fake_video_decode_accelerator.h" 5 #include "content/common/gpu/media/fake_video_decode_accelerator.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <string.h> 8 #include <string.h>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 11 matching lines...) Expand all
22 22
23 static const uint32_t kDefaultTextureTarget = GL_TEXTURE_2D; 23 static const uint32_t kDefaultTextureTarget = GL_TEXTURE_2D;
24 // Must be at least 2 since the rendering helper will switch between textures 24 // Must be at least 2 since the rendering helper will switch between textures
25 // and if there is only one, it will wait for the next one that will never come. 25 // and if there is only one, it will wait for the next one that will never come.
26 // Must also be an even number as otherwise there won't be the same amount of 26 // Must also be an even number as otherwise there won't be the same amount of
27 // white and black frames. 27 // white and black frames.
28 static const unsigned int kNumBuffers = media::limits::kMaxVideoFrames + 28 static const unsigned int kNumBuffers = media::limits::kMaxVideoFrames +
29 (media::limits::kMaxVideoFrames & 1u); 29 (media::limits::kMaxVideoFrames & 1u);
30 30
31 FakeVideoDecodeAccelerator::FakeVideoDecodeAccelerator( 31 FakeVideoDecodeAccelerator::FakeVideoDecodeAccelerator(
32 gfx::GLContext* gl, 32 const gfx::Size& size,
33 gfx::Size size, 33 const MakeGLContextCurrentCallback& make_context_current_cb)
34 const base::Callback<bool(void)>& make_context_current)
35 : child_task_runner_(base::ThreadTaskRunnerHandle::Get()), 34 : child_task_runner_(base::ThreadTaskRunnerHandle::Get()),
36 client_(NULL), 35 client_(NULL),
37 make_context_current_(make_context_current), 36 make_context_current_cb_(make_context_current_cb),
38 gl_(gl),
39 frame_buffer_size_(size), 37 frame_buffer_size_(size),
40 flushing_(false), 38 flushing_(false),
41 weak_this_factory_(this) { 39 weak_this_factory_(this) {}
42 }
43 40
44 FakeVideoDecodeAccelerator::~FakeVideoDecodeAccelerator() { 41 FakeVideoDecodeAccelerator::~FakeVideoDecodeAccelerator() {
45 } 42 }
46 43
47 bool FakeVideoDecodeAccelerator::Initialize(const Config& config, 44 bool FakeVideoDecodeAccelerator::Initialize(const Config& config,
48 Client* client) { 45 Client* client) {
49 DCHECK(child_task_runner_->BelongsToCurrentThread()); 46 DCHECK(child_task_runner_->BelongsToCurrentThread());
50 if (config.profile == media::VIDEO_CODEC_PROFILE_UNKNOWN) { 47 if (config.profile == media::VIDEO_CODEC_PROFILE_UNKNOWN) {
51 LOG(ERROR) << "unknown codec profile"; 48 LOG(ERROR) << "unknown codec profile";
52 return false; 49 return false;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 4]); 92 4]);
96 memset(white_data.get(), 93 memset(white_data.get(),
97 UINT8_MAX, 94 UINT8_MAX,
98 frame_buffer_size_.width() * frame_buffer_size_.height() * 4); 95 frame_buffer_size_.width() * frame_buffer_size_.height() * 4);
99 scoped_ptr<uint8_t[]> black_data( 96 scoped_ptr<uint8_t[]> black_data(
100 new uint8_t[frame_buffer_size_.width() * frame_buffer_size_.height() * 97 new uint8_t[frame_buffer_size_.width() * frame_buffer_size_.height() *
101 4]); 98 4]);
102 memset(black_data.get(), 99 memset(black_data.get(),
103 0, 100 0,
104 frame_buffer_size_.width() * frame_buffer_size_.height() * 4); 101 frame_buffer_size_.width() * frame_buffer_size_.height() * 4);
105 if (!make_context_current_.Run()) { 102 if (!make_context_current_cb_.Run()) {
106 LOG(ERROR) << "ReusePictureBuffer(): could not make context current"; 103 LOG(ERROR) << "ReusePictureBuffer(): could not make context current";
107 return; 104 return;
108 } 105 }
109 for (size_t index = 0; index < buffers.size(); ++index) { 106 for (size_t index = 0; index < buffers.size(); ++index) {
110 DCHECK_LE(1u, buffers[index].texture_ids().size()); 107 DCHECK_LE(1u, buffers[index].texture_ids().size());
111 glBindTexture(GL_TEXTURE_2D, buffers[index].texture_ids()[0]); 108 glBindTexture(GL_TEXTURE_2D, buffers[index].texture_ids()[0]);
112 // Every other frame white and the rest black. 109 // Every other frame white and the rest black.
113 uint8_t* data = index % 2 ? white_data.get() : black_data.get(); 110 uint8_t* data = index % 2 ? white_data.get() : black_data.get();
114 glTexImage2D(GL_TEXTURE_2D, 111 glTexImage2D(GL_TEXTURE_2D,
115 0, 112 0,
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 } 152 }
156 153
157 void FakeVideoDecodeAccelerator::Destroy() { 154 void FakeVideoDecodeAccelerator::Destroy() {
158 while (!queued_bitstream_ids_.empty()) { 155 while (!queued_bitstream_ids_.empty()) {
159 client_->NotifyEndOfBitstreamBuffer(queued_bitstream_ids_.front()); 156 client_->NotifyEndOfBitstreamBuffer(queued_bitstream_ids_.front());
160 queued_bitstream_ids_.pop(); 157 queued_bitstream_ids_.pop();
161 } 158 }
162 delete this; 159 delete this;
163 } 160 }
164 161
165 bool FakeVideoDecodeAccelerator::CanDecodeOnIOThread() { 162 bool FakeVideoDecodeAccelerator::TryToSetupDecodeOnSeparateThread(
166 return true; 163 const base::WeakPtr<Client>& decode_client,
164 const scoped_refptr<base::SingleThreadTaskRunner>& decode_task_runner) {
165 return false;
167 } 166 }
168 167
169 void FakeVideoDecodeAccelerator::DoPictureReady() { 168 void FakeVideoDecodeAccelerator::DoPictureReady() {
170 if (flushing_ && queued_bitstream_ids_.empty()) { 169 if (flushing_ && queued_bitstream_ids_.empty()) {
171 flushing_ = false; 170 flushing_ = false;
172 client_->NotifyFlushDone(); 171 client_->NotifyFlushDone();
173 } 172 }
174 while (!free_output_buffers_.empty() && !queued_bitstream_ids_.empty()) { 173 while (!free_output_buffers_.empty() && !queued_bitstream_ids_.empty()) {
175 int bitstream_id = queued_bitstream_ids_.front(); 174 int bitstream_id = queued_bitstream_ids_.front();
176 queued_bitstream_ids_.pop(); 175 queued_bitstream_ids_.pop();
177 int buffer_id = free_output_buffers_.front(); 176 int buffer_id = free_output_buffers_.front();
178 free_output_buffers_.pop(); 177 free_output_buffers_.pop();
179 178
180 const media::Picture picture = 179 const media::Picture picture =
181 media::Picture(buffer_id, 180 media::Picture(buffer_id,
182 bitstream_id, 181 bitstream_id,
183 gfx::Rect(frame_buffer_size_), 182 gfx::Rect(frame_buffer_size_),
184 false); 183 false);
185 client_->PictureReady(picture); 184 client_->PictureReady(picture);
186 // Bitstream no longer needed. 185 // Bitstream no longer needed.
187 client_->NotifyEndOfBitstreamBuffer(bitstream_id); 186 client_->NotifyEndOfBitstreamBuffer(bitstream_id);
188 if (flushing_ && queued_bitstream_ids_.empty()) { 187 if (flushing_ && queued_bitstream_ids_.empty()) {
189 flushing_ = false; 188 flushing_ = false;
190 client_->NotifyFlushDone(); 189 client_->NotifyFlushDone();
191 } 190 }
192 } 191 }
193 } 192 }
194 193
195 } // namespace content 194 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698