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"; |
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) { | 288 const std::vector<gfx::Size>& sizes) { |
piman
2013/09/24 22:14:07
Is it fair to say we don't care about sizes any mo
sheu
2013/09/24 22:22:23
I do a check against texture_dimensions_ at l.307
piman
2013/09/24 23:01:31
Oh, yeah, missed that somehow.
| |
290 DCHECK(stub_); | 289 DCHECK(stub_); |
291 if (buffer_ids.size() != texture_ids.size() || | 290 if (buffer_ids.size() != texture_ids.size() || |
292 buffer_ids.size() != sizes.size()) { | 291 buffer_ids.size() != sizes.size()) { |
293 NotifyError(media::VideoDecodeAccelerator::INVALID_ARGUMENT); | 292 NotifyError(media::VideoDecodeAccelerator::INVALID_ARGUMENT); |
294 return; | 293 return; |
295 } | 294 } |
296 | 295 |
297 gpu::gles2::GLES2Decoder* command_decoder = stub_->decoder(); | 296 gpu::gles2::GLES2Decoder* command_decoder = stub_->decoder(); |
298 gpu::gles2::TextureManager* texture_manager = | 297 gpu::gles2::TextureManager* texture_manager = |
299 command_decoder->GetContextGroup()->texture_manager(); | 298 command_decoder->GetContextGroup()->texture_manager(); |
300 | 299 |
301 std::vector<media::PictureBuffer> buffers; | 300 std::vector<media::PictureBuffer> buffers; |
302 for (uint32 i = 0; i < buffer_ids.size(); ++i) { | 301 for (uint32 i = 0; i < buffer_ids.size(); ++i) { |
303 if (buffer_ids[i] < 0) { | 302 if (buffer_ids[i] < 0) { |
304 DLOG(FATAL) << "Buffer id " << buffer_ids[i] << " out of range"; | 303 DLOG(ERROR) << "Buffer id " << buffer_ids[i] << " out of range"; |
304 NotifyError(media::VideoDecodeAccelerator::INVALID_ARGUMENT); | |
305 return; | |
306 } | |
307 if (sizes[i] != texture_dimensions_) { | |
308 DLOG(ERROR) << "Invalid buffer size " << sizes[i].ToString(); | |
305 NotifyError(media::VideoDecodeAccelerator::INVALID_ARGUMENT); | 309 NotifyError(media::VideoDecodeAccelerator::INVALID_ARGUMENT); |
306 return; | 310 return; |
307 } | 311 } |
308 gpu::gles2::TextureRef* texture_ref = texture_manager->GetTexture( | 312 gpu::gles2::TextureRef* texture_ref = texture_manager->GetTexture( |
309 texture_ids[i]); | 313 texture_ids[i]); |
310 if (!texture_ref) { | 314 if (!texture_ref) { |
311 DLOG(FATAL) << "Failed to find texture id " << texture_ids[i]; | 315 DLOG(ERROR) << "Failed to find texture id " << texture_ids[i]; |
312 NotifyError(media::VideoDecodeAccelerator::INVALID_ARGUMENT); | 316 NotifyError(media::VideoDecodeAccelerator::INVALID_ARGUMENT); |
313 return; | 317 return; |
314 } | 318 } |
315 gpu::gles2::Texture* info = texture_ref->texture(); | 319 gpu::gles2::Texture* info = texture_ref->texture(); |
316 if (info->target() != texture_target_) { | 320 if (info->target() != texture_target_) { |
317 DLOG(FATAL) << "Texture target mismatch for texture id " | 321 DLOG(ERROR) << "Texture target mismatch for texture id " |
318 << texture_ids[i]; | 322 << texture_ids[i]; |
319 NotifyError(media::VideoDecodeAccelerator::INVALID_ARGUMENT); | 323 NotifyError(media::VideoDecodeAccelerator::INVALID_ARGUMENT); |
320 return; | 324 return; |
321 } | 325 } |
322 // GL_TEXTURE_EXTERNAL_OES textures have their dimensions defined by the | 326 if (texture_target_ == GL_TEXTURE_EXTERNAL_OES) { |
323 // underlying EGLImage. | 327 // GL_TEXTURE_EXTERNAL_OES textures have their dimensions defined by the |
324 if (texture_target_ != GL_TEXTURE_EXTERNAL_OES) { | 328 // underlying EGLImage. Use |texture_dimensions_| for this size. |
329 texture_manager->SetLevelInfo(texture_ref, | |
330 GL_TEXTURE_EXTERNAL_OES, | |
331 0, | |
332 0, | |
333 texture_dimensions_.width(), | |
334 texture_dimensions_.height(), | |
335 1, | |
336 0, | |
337 0, | |
338 0, | |
339 false); | |
340 } else { | |
341 // For other targets, texture dimensions should already be defined. | |
325 GLsizei width = 0, height = 0; | 342 GLsizei width = 0, height = 0; |
326 info->GetLevelSize(texture_target_, 0, &width, &height); | 343 info->GetLevelSize(texture_target_, 0, &width, &height); |
327 if (width != sizes[i].width() || height != sizes[i].height()) { | 344 if (width != texture_dimensions_.width() || |
328 DLOG(FATAL) << "Size mismatch for texture id " << texture_ids[i]; | 345 height != texture_dimensions_.height()) { |
346 DLOG(ERROR) << "Size mismatch for texture id " << texture_ids[i]; | |
329 NotifyError(media::VideoDecodeAccelerator::INVALID_ARGUMENT); | 347 NotifyError(media::VideoDecodeAccelerator::INVALID_ARGUMENT); |
330 return; | 348 return; |
331 } | 349 } |
332 } | 350 } |
333 if (!texture_manager->ClearRenderableLevels(command_decoder, texture_ref)) { | 351 if (!texture_manager->ClearRenderableLevels(command_decoder, texture_ref)) { |
334 DLOG(FATAL) << "Failed to Clear texture id " << texture_ids[i]; | 352 DLOG(ERROR) << "Failed to Clear texture id " << texture_ids[i]; |
335 NotifyError(media::VideoDecodeAccelerator::PLATFORM_FAILURE); | 353 NotifyError(media::VideoDecodeAccelerator::PLATFORM_FAILURE); |
336 return; | 354 return; |
337 } | 355 } |
338 uint32 service_texture_id; | 356 uint32 service_texture_id; |
339 if (!command_decoder->GetServiceTextureId( | 357 if (!command_decoder->GetServiceTextureId( |
340 texture_ids[i], &service_texture_id)) { | 358 texture_ids[i], &service_texture_id)) { |
341 DLOG(FATAL) << "Failed to translate texture!"; | 359 DLOG(ERROR) << "Failed to translate texture!"; |
342 NotifyError(media::VideoDecodeAccelerator::PLATFORM_FAILURE); | 360 NotifyError(media::VideoDecodeAccelerator::PLATFORM_FAILURE); |
343 return; | 361 return; |
344 } | 362 } |
345 buffers.push_back(media::PictureBuffer( | 363 buffers.push_back(media::PictureBuffer( |
346 buffer_ids[i], sizes[i], service_texture_id)); | 364 buffer_ids[i], texture_dimensions_, service_texture_id)); |
347 } | 365 } |
348 video_decode_accelerator_->AssignPictureBuffers(buffers); | 366 video_decode_accelerator_->AssignPictureBuffers(buffers); |
349 } | 367 } |
350 | 368 |
351 void GpuVideoDecodeAccelerator::OnReusePictureBuffer( | 369 void GpuVideoDecodeAccelerator::OnReusePictureBuffer( |
352 int32 picture_buffer_id) { | 370 int32 picture_buffer_id) { |
353 DCHECK(video_decode_accelerator_.get()); | 371 DCHECK(video_decode_accelerator_.get()); |
354 video_decode_accelerator_->ReusePictureBuffer(picture_buffer_id); | 372 video_decode_accelerator_->ReusePictureBuffer(picture_buffer_id); |
355 } | 373 } |
356 | 374 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
416 | 434 |
417 bool GpuVideoDecodeAccelerator::Send(IPC::Message* message) { | 435 bool GpuVideoDecodeAccelerator::Send(IPC::Message* message) { |
418 DCHECK(stub_); | 436 DCHECK(stub_); |
419 if (filter_.get() && io_message_loop_->BelongsToCurrentThread()) | 437 if (filter_.get() && io_message_loop_->BelongsToCurrentThread()) |
420 return filter_->SendOnIOThread(message); | 438 return filter_->SendOnIOThread(message); |
421 DCHECK(child_message_loop_->BelongsToCurrentThread()); | 439 DCHECK(child_message_loop_->BelongsToCurrentThread()); |
422 return stub_->channel()->Send(message); | 440 return stub_->channel()->Send(message); |
423 } | 441 } |
424 | 442 |
425 } // namespace content | 443 } // namespace content |
OLD | NEW |