| 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 "media/filters/gpu_video_decoder.h" | 5 #include "media/filters/gpu_video_decoder.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/cpu.h" | 12 #include "base/cpu.h" |
| 13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 14 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
| 15 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
| 16 #include "base/synchronization/waitable_event.h" | |
| 17 #include "base/task_runner_util.h" | 16 #include "base/task_runner_util.h" |
| 18 #include "gpu/command_buffer/common/mailbox_holder.h" | 17 #include "gpu/command_buffer/common/mailbox_holder.h" |
| 19 #include "media/base/bind_to_current_loop.h" | 18 #include "media/base/bind_to_current_loop.h" |
| 20 #include "media/base/decoder_buffer.h" | 19 #include "media/base/decoder_buffer.h" |
| 21 #include "media/base/media_switches.h" | 20 #include "media/base/media_switches.h" |
| 22 #include "media/base/pipeline.h" | 21 #include "media/base/pipeline.h" |
| 23 #include "media/base/pipeline_status.h" | 22 #include "media/base/pipeline_status.h" |
| 24 #include "media/base/video_decoder_config.h" | 23 #include "media/base/video_decoder_config.h" |
| 25 #include "media/filters/gpu_video_accelerator_factories.h" | 24 #include "media/filters/gpu_video_accelerator_factories.h" |
| 26 #include "third_party/skia/include/core/SkBitmap.h" | 25 #include "third_party/skia/include/core/SkBitmap.h" |
| (...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 if (!picture_buffers_at_display_.count(id)) { | 377 if (!picture_buffers_at_display_.count(id)) { |
| 379 // We can delete the texture immediately as it's not being displayed. | 378 // We can delete the texture immediately as it's not being displayed. |
| 380 factories_->DeleteTexture(buffer_to_dismiss.texture_id()); | 379 factories_->DeleteTexture(buffer_to_dismiss.texture_id()); |
| 381 CHECK_GT(available_pictures_, 0); | 380 CHECK_GT(available_pictures_, 0); |
| 382 --available_pictures_; | 381 --available_pictures_; |
| 383 } | 382 } |
| 384 // Not destroying a texture in display in |picture_buffers_at_display_|. | 383 // Not destroying a texture in display in |picture_buffers_at_display_|. |
| 385 // Postpone deletion until after it's returned to us. | 384 // Postpone deletion until after it's returned to us. |
| 386 } | 385 } |
| 387 | 386 |
| 388 static void ReadPixelsSyncInner( | |
| 389 const scoped_refptr<media::GpuVideoAcceleratorFactories>& factories, | |
| 390 uint32 texture_id, | |
| 391 const gfx::Rect& visible_rect, | |
| 392 const SkBitmap& pixels, | |
| 393 base::WaitableEvent* event) { | |
| 394 factories->ReadPixels(texture_id, visible_rect, pixels); | |
| 395 event->Signal(); | |
| 396 } | |
| 397 | |
| 398 static void ReadPixelsSync( | |
| 399 const scoped_refptr<media::GpuVideoAcceleratorFactories>& factories, | |
| 400 uint32 texture_id, | |
| 401 const gfx::Rect& visible_rect, | |
| 402 const SkBitmap& pixels) { | |
| 403 base::WaitableEvent event(true, false); | |
| 404 if (!factories->GetTaskRunner()->PostTask(FROM_HERE, | |
| 405 base::Bind(&ReadPixelsSyncInner, | |
| 406 factories, | |
| 407 texture_id, | |
| 408 visible_rect, | |
| 409 pixels, | |
| 410 &event))) | |
| 411 return; | |
| 412 event.Wait(); | |
| 413 } | |
| 414 | |
| 415 void GpuVideoDecoder::PictureReady(const media::Picture& picture) { | 387 void GpuVideoDecoder::PictureReady(const media::Picture& picture) { |
| 416 DVLOG(3) << "PictureReady()"; | 388 DVLOG(3) << "PictureReady()"; |
| 417 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); | 389 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); |
| 418 | 390 |
| 419 PictureBufferMap::iterator it = | 391 PictureBufferMap::iterator it = |
| 420 assigned_picture_buffers_.find(picture.picture_buffer_id()); | 392 assigned_picture_buffers_.find(picture.picture_buffer_id()); |
| 421 if (it == assigned_picture_buffers_.end()) { | 393 if (it == assigned_picture_buffers_.end()) { |
| 422 NOTREACHED() << "Missing picture buffer: " << picture.picture_buffer_id(); | 394 NOTREACHED() << "Missing picture buffer: " << picture.picture_buffer_id(); |
| 423 NotifyError(VideoDecodeAccelerator::PLATFORM_FAILURE); | 395 NotifyError(VideoDecodeAccelerator::PLATFORM_FAILURE); |
| 424 return; | 396 return; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 447 &natural_size); | 419 &natural_size); |
| 448 DCHECK(decoder_texture_target_); | 420 DCHECK(decoder_texture_target_); |
| 449 | 421 |
| 450 scoped_refptr<VideoFrame> frame(VideoFrame::WrapNativeTexture( | 422 scoped_refptr<VideoFrame> frame(VideoFrame::WrapNativeTexture( |
| 451 make_scoped_ptr(new gpu::MailboxHolder( | 423 make_scoped_ptr(new gpu::MailboxHolder( |
| 452 pb.texture_mailbox(), decoder_texture_target_, 0 /* sync_point */)), | 424 pb.texture_mailbox(), decoder_texture_target_, 0 /* sync_point */)), |
| 453 BindToCurrentLoop(base::Bind( | 425 BindToCurrentLoop(base::Bind( |
| 454 &GpuVideoDecoder::ReleaseMailbox, weak_factory_.GetWeakPtr(), | 426 &GpuVideoDecoder::ReleaseMailbox, weak_factory_.GetWeakPtr(), |
| 455 factories_, picture.picture_buffer_id(), pb.texture_id())), | 427 factories_, picture.picture_buffer_id(), pb.texture_id())), |
| 456 pb.size(), visible_rect, natural_size, timestamp, | 428 pb.size(), visible_rect, natural_size, timestamp, |
| 457 base::Bind(&ReadPixelsSync, factories_, pb.texture_id(), visible_rect), | |
| 458 picture.allow_overlay())); | 429 picture.allow_overlay())); |
| 459 CHECK_GT(available_pictures_, 0); | 430 CHECK_GT(available_pictures_, 0); |
| 460 --available_pictures_; | 431 --available_pictures_; |
| 461 bool inserted = | 432 bool inserted = |
| 462 picture_buffers_at_display_.insert(std::make_pair( | 433 picture_buffers_at_display_.insert(std::make_pair( |
| 463 picture.picture_buffer_id(), | 434 picture.picture_buffer_id(), |
| 464 pb.texture_id())).second; | 435 pb.texture_id())).second; |
| 465 DCHECK(inserted); | 436 DCHECK(inserted); |
| 466 | 437 |
| 467 DeliverFrame(frame); | 438 DeliverFrame(frame); |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 618 DLOG(ERROR) << "VDA Error: " << error; | 589 DLOG(ERROR) << "VDA Error: " << error; |
| 619 DestroyVDA(); | 590 DestroyVDA(); |
| 620 } | 591 } |
| 621 | 592 |
| 622 void GpuVideoDecoder::DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent() | 593 void GpuVideoDecoder::DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent() |
| 623 const { | 594 const { |
| 624 DCHECK(factories_->GetTaskRunner()->BelongsToCurrentThread()); | 595 DCHECK(factories_->GetTaskRunner()->BelongsToCurrentThread()); |
| 625 } | 596 } |
| 626 | 597 |
| 627 } // namespace media | 598 } // namespace media |
| OLD | NEW |