OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/gpu_video_decode_accelerator.h" | 5 #include "content/common/gpu/media/gpu_video_decode_accelerator.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 18 matching lines...) Expand all Loading... | |
29 #elif defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) && defined(USE_X11) | 29 #elif defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) && defined(USE_X11) |
30 #include "ui/gl/gl_context_glx.h" | 30 #include "ui/gl/gl_context_glx.h" |
31 #include "content/common/gpu/media/vaapi_video_decode_accelerator.h" | 31 #include "content/common/gpu/media/vaapi_video_decode_accelerator.h" |
32 #elif defined(OS_ANDROID) | 32 #elif defined(OS_ANDROID) |
33 #include "content/common/gpu/media/android_video_decode_accelerator.h" | 33 #include "content/common/gpu/media/android_video_decode_accelerator.h" |
34 #endif | 34 #endif |
35 | 35 |
36 #include "gpu/command_buffer/service/texture_manager.h" | 36 #include "gpu/command_buffer/service/texture_manager.h" |
37 #include "ui/gfx/size.h" | 37 #include "ui/gfx/size.h" |
38 | 38 |
39 using gpu::gles2::TextureManager; | |
40 | |
41 namespace content { | 39 namespace content { |
42 | 40 |
43 static bool MakeDecoderContextCurrent( | 41 static bool MakeDecoderContextCurrent( |
44 const base::WeakPtr<GpuCommandBufferStub> stub) { | 42 const base::WeakPtr<GpuCommandBufferStub> stub) { |
45 if (!stub.get()) { | 43 if (!stub.get()) { |
46 DLOG(ERROR) << "Stub is gone; won't MakeCurrent()."; | 44 DLOG(ERROR) << "Stub is gone; won't MakeCurrent()."; |
47 return false; | 45 return false; |
48 } | 46 } |
49 | 47 |
50 if (!stub->decoder()->MakeCurrent()) { | 48 if (!stub->decoder()->MakeCurrent()) { |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
150 void GpuVideoDecodeAccelerator::ProvidePictureBuffers( | 148 void GpuVideoDecodeAccelerator::ProvidePictureBuffers( |
151 uint32 requested_num_of_buffers, | 149 uint32 requested_num_of_buffers, |
152 const gfx::Size& dimensions, | 150 const gfx::Size& dimensions, |
153 uint32 texture_target) { | 151 uint32 texture_target) { |
154 if (!Send(new AcceleratedVideoDecoderHostMsg_ProvidePictureBuffers( | 152 if (!Send(new AcceleratedVideoDecoderHostMsg_ProvidePictureBuffers( |
155 host_route_id_, requested_num_of_buffers, dimensions, | 153 host_route_id_, requested_num_of_buffers, dimensions, |
156 texture_target))) { | 154 texture_target))) { |
157 DLOG(ERROR) << "Send(AcceleratedVideoDecoderHostMsg_ProvidePictureBuffers) " | 155 DLOG(ERROR) << "Send(AcceleratedVideoDecoderHostMsg_ProvidePictureBuffers) " |
158 << "failed"; | 156 << "failed"; |
159 } | 157 } |
158 texture_dimensions_ = dimensions; | |
160 texture_target_ = texture_target; | 159 texture_target_ = texture_target; |
161 } | 160 } |
162 | 161 |
163 void GpuVideoDecodeAccelerator::DismissPictureBuffer( | 162 void GpuVideoDecodeAccelerator::DismissPictureBuffer( |
164 int32 picture_buffer_id) { | 163 int32 picture_buffer_id) { |
165 // Notify client that picture buffer is now unused. | 164 // Notify client that picture buffer is now unused. |
166 if (!Send(new AcceleratedVideoDecoderHostMsg_DismissPictureBuffer( | 165 if (!Send(new AcceleratedVideoDecoderHostMsg_DismissPictureBuffer( |
167 host_route_id_, picture_buffer_id))) { | 166 host_route_id_, picture_buffer_id))) { |
168 DLOG(ERROR) << "Send(AcceleratedVideoDecoderHostMsg_DismissPictureBuffer) " | 167 DLOG(ERROR) << "Send(AcceleratedVideoDecoderHostMsg_DismissPictureBuffer) " |
169 << "failed"; | 168 << "failed"; |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
261 if (!video_decode_accelerator_->Initialize(profile)) | 260 if (!video_decode_accelerator_->Initialize(profile)) |
262 NotifyError(media::VideoDecodeAccelerator::PLATFORM_FAILURE); | 261 NotifyError(media::VideoDecodeAccelerator::PLATFORM_FAILURE); |
263 } | 262 } |
264 | 263 |
265 // Runs on IO thread if video_decode_accelerator_->CanDecodeOnIOThread() is | 264 // Runs on IO thread if video_decode_accelerator_->CanDecodeOnIOThread() is |
266 // true, otherwise on the main thread. | 265 // true, otherwise on the main thread. |
267 void GpuVideoDecodeAccelerator::OnDecode( | 266 void GpuVideoDecodeAccelerator::OnDecode( |
268 base::SharedMemoryHandle handle, int32 id, uint32 size) { | 267 base::SharedMemoryHandle handle, int32 id, uint32 size) { |
269 DCHECK(video_decode_accelerator_.get()); | 268 DCHECK(video_decode_accelerator_.get()); |
270 if (id < 0) { | 269 if (id < 0) { |
271 DLOG(FATAL) << "BitstreamBuffer id " << id << " out of range"; | 270 DLOG(ERROR) << "BitstreamBuffer id " << id << " out of range"; |
Ami GONE FROM CHROMIUM
2013/09/25 01:09:30
Why this change, here and elsewhere? These are ef
piman
2013/09/25 01:12:10
This is untrusted data though, coming from the ren
Ami GONE FROM CHROMIUM
2013/09/25 01:15:46
For debug builds I am more concerned about asserti
| |
272 if (child_message_loop_->BelongsToCurrentThread()) { | 271 if (child_message_loop_->BelongsToCurrentThread()) { |
273 NotifyError(media::VideoDecodeAccelerator::INVALID_ARGUMENT); | 272 NotifyError(media::VideoDecodeAccelerator::INVALID_ARGUMENT); |
274 } else { | 273 } else { |
275 child_message_loop_->PostTask( | 274 child_message_loop_->PostTask( |
276 FROM_HERE, | 275 FROM_HERE, |
277 base::Bind(&GpuVideoDecodeAccelerator::NotifyError, | 276 base::Bind(&GpuVideoDecodeAccelerator::NotifyError, |
278 base::Unretained(this), | 277 base::Unretained(this), |
279 media::VideoDecodeAccelerator::INVALID_ARGUMENT)); | 278 media::VideoDecodeAccelerator::INVALID_ARGUMENT)); |
280 } | 279 } |
281 return; | 280 return; |
282 } | 281 } |
283 video_decode_accelerator_->Decode(media::BitstreamBuffer(id, handle, size)); | 282 video_decode_accelerator_->Decode(media::BitstreamBuffer(id, handle, size)); |
284 } | 283 } |
285 | 284 |
286 void GpuVideoDecodeAccelerator::OnAssignPictureBuffers( | 285 void GpuVideoDecodeAccelerator::OnAssignPictureBuffers( |
287 const std::vector<int32>& buffer_ids, | 286 const std::vector<int32>& buffer_ids, |
288 const std::vector<uint32>& texture_ids, | 287 const std::vector<uint32>& texture_ids) { |
289 const std::vector<gfx::Size>& sizes) { | |
290 DCHECK(stub_); | 288 DCHECK(stub_); |
291 if (buffer_ids.size() != texture_ids.size() || | 289 if (buffer_ids.size() != texture_ids.size()) { |
292 buffer_ids.size() != sizes.size()) { | |
293 NotifyError(media::VideoDecodeAccelerator::INVALID_ARGUMENT); | 290 NotifyError(media::VideoDecodeAccelerator::INVALID_ARGUMENT); |
294 return; | 291 return; |
295 } | 292 } |
296 | 293 |
297 gpu::gles2::GLES2Decoder* command_decoder = stub_->decoder(); | 294 gpu::gles2::GLES2Decoder* command_decoder = stub_->decoder(); |
298 gpu::gles2::TextureManager* texture_manager = | 295 gpu::gles2::TextureManager* texture_manager = |
299 command_decoder->GetContextGroup()->texture_manager(); | 296 command_decoder->GetContextGroup()->texture_manager(); |
300 | 297 |
301 std::vector<media::PictureBuffer> buffers; | 298 std::vector<media::PictureBuffer> buffers; |
302 for (uint32 i = 0; i < buffer_ids.size(); ++i) { | 299 for (uint32 i = 0; i < buffer_ids.size(); ++i) { |
303 if (buffer_ids[i] < 0) { | 300 if (buffer_ids[i] < 0) { |
304 DLOG(FATAL) << "Buffer id " << buffer_ids[i] << " out of range"; | 301 DLOG(ERROR) << "Buffer id " << buffer_ids[i] << " out of range"; |
305 NotifyError(media::VideoDecodeAccelerator::INVALID_ARGUMENT); | 302 NotifyError(media::VideoDecodeAccelerator::INVALID_ARGUMENT); |
306 return; | 303 return; |
307 } | 304 } |
308 gpu::gles2::TextureRef* texture_ref = texture_manager->GetTexture( | 305 gpu::gles2::TextureRef* texture_ref = texture_manager->GetTexture( |
309 texture_ids[i]); | 306 texture_ids[i]); |
310 if (!texture_ref) { | 307 if (!texture_ref) { |
311 DLOG(FATAL) << "Failed to find texture id " << texture_ids[i]; | 308 DLOG(ERROR) << "Failed to find texture id " << texture_ids[i]; |
312 NotifyError(media::VideoDecodeAccelerator::INVALID_ARGUMENT); | 309 NotifyError(media::VideoDecodeAccelerator::INVALID_ARGUMENT); |
313 return; | 310 return; |
314 } | 311 } |
315 gpu::gles2::Texture* info = texture_ref->texture(); | 312 gpu::gles2::Texture* info = texture_ref->texture(); |
316 if (info->target() != texture_target_) { | 313 if (info->target() != texture_target_) { |
317 DLOG(FATAL) << "Texture target mismatch for texture id " | 314 DLOG(ERROR) << "Texture target mismatch for texture id " |
318 << texture_ids[i]; | 315 << texture_ids[i]; |
319 NotifyError(media::VideoDecodeAccelerator::INVALID_ARGUMENT); | 316 NotifyError(media::VideoDecodeAccelerator::INVALID_ARGUMENT); |
320 return; | 317 return; |
321 } | 318 } |
322 // GL_TEXTURE_EXTERNAL_OES textures have their dimensions defined by the | 319 if (texture_target_ == GL_TEXTURE_EXTERNAL_OES) { |
323 // underlying EGLImage. | 320 // GL_TEXTURE_EXTERNAL_OES textures have their dimensions defined by the |
324 if (texture_target_ != GL_TEXTURE_EXTERNAL_OES) { | 321 // underlying EGLImage. Use |texture_dimensions_| for this size. The |
322 // textures cannot be rendered to or cleared, so we set |cleared| true to | |
323 // skip clearing. | |
324 texture_manager->SetLevelInfo(texture_ref, | |
325 GL_TEXTURE_EXTERNAL_OES, | |
326 0, | |
327 0, | |
328 texture_dimensions_.width(), | |
329 texture_dimensions_.height(), | |
330 1, | |
331 0, | |
332 0, | |
333 0, | |
334 true); | |
335 } else { | |
336 // For other targets, texture dimensions should already be defined. | |
325 GLsizei width = 0, height = 0; | 337 GLsizei width = 0, height = 0; |
326 info->GetLevelSize(texture_target_, 0, &width, &height); | 338 info->GetLevelSize(texture_target_, 0, &width, &height); |
327 if (width != sizes[i].width() || height != sizes[i].height()) { | 339 if (width != texture_dimensions_.width() || |
328 DLOG(FATAL) << "Size mismatch for texture id " << texture_ids[i]; | 340 height != texture_dimensions_.height()) { |
341 DLOG(ERROR) << "Size mismatch for texture id " << texture_ids[i]; | |
329 NotifyError(media::VideoDecodeAccelerator::INVALID_ARGUMENT); | 342 NotifyError(media::VideoDecodeAccelerator::INVALID_ARGUMENT); |
330 return; | 343 return; |
331 } | 344 } |
332 } | 345 } |
333 if (!texture_manager->ClearRenderableLevels(command_decoder, texture_ref)) { | 346 if (!texture_manager->ClearRenderableLevels(command_decoder, texture_ref)) { |
334 DLOG(FATAL) << "Failed to Clear texture id " << texture_ids[i]; | 347 DLOG(ERROR) << "Failed to Clear texture id " << texture_ids[i]; |
335 NotifyError(media::VideoDecodeAccelerator::PLATFORM_FAILURE); | 348 NotifyError(media::VideoDecodeAccelerator::PLATFORM_FAILURE); |
336 return; | 349 return; |
337 } | 350 } |
338 uint32 service_texture_id; | 351 uint32 service_texture_id; |
339 if (!command_decoder->GetServiceTextureId( | 352 if (!command_decoder->GetServiceTextureId( |
340 texture_ids[i], &service_texture_id)) { | 353 texture_ids[i], &service_texture_id)) { |
341 DLOG(FATAL) << "Failed to translate texture!"; | 354 DLOG(ERROR) << "Failed to translate texture!"; |
342 NotifyError(media::VideoDecodeAccelerator::PLATFORM_FAILURE); | 355 NotifyError(media::VideoDecodeAccelerator::PLATFORM_FAILURE); |
343 return; | 356 return; |
344 } | 357 } |
345 buffers.push_back(media::PictureBuffer( | 358 buffers.push_back(media::PictureBuffer( |
346 buffer_ids[i], sizes[i], service_texture_id)); | 359 buffer_ids[i], texture_dimensions_, service_texture_id)); |
347 } | 360 } |
348 video_decode_accelerator_->AssignPictureBuffers(buffers); | 361 video_decode_accelerator_->AssignPictureBuffers(buffers); |
349 } | 362 } |
350 | 363 |
351 void GpuVideoDecodeAccelerator::OnReusePictureBuffer( | 364 void GpuVideoDecodeAccelerator::OnReusePictureBuffer( |
352 int32 picture_buffer_id) { | 365 int32 picture_buffer_id) { |
353 DCHECK(video_decode_accelerator_.get()); | 366 DCHECK(video_decode_accelerator_.get()); |
354 video_decode_accelerator_->ReusePictureBuffer(picture_buffer_id); | 367 video_decode_accelerator_->ReusePictureBuffer(picture_buffer_id); |
355 } | 368 } |
356 | 369 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
416 | 429 |
417 bool GpuVideoDecodeAccelerator::Send(IPC::Message* message) { | 430 bool GpuVideoDecodeAccelerator::Send(IPC::Message* message) { |
418 DCHECK(stub_); | 431 DCHECK(stub_); |
419 if (filter_.get() && io_message_loop_->BelongsToCurrentThread()) | 432 if (filter_.get() && io_message_loop_->BelongsToCurrentThread()) |
420 return filter_->SendOnIOThread(message); | 433 return filter_->SendOnIOThread(message); |
421 DCHECK(child_message_loop_->BelongsToCurrentThread()); | 434 DCHECK(child_message_loop_->BelongsToCurrentThread()); |
422 return stub_->channel()->Send(message); | 435 return stub_->channel()->Send(message); |
423 } | 436 } |
424 | 437 |
425 } // namespace content | 438 } // namespace content |
OLD | NEW |