Chromium Code Reviews| 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); | |
|
dshwang
2015/01/14 20:32:13
it's executed in media thread.
| |
| 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); | |
|
dshwang
2015/01/14 20:32:13
wait Blink thread until the job getting done in me
| |
| 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 18 matching lines...) Expand all Loading... | |
| 443 // use config information instead. | 415 // use config information instead. |
| 444 gfx::Rect visible_rect; | 416 gfx::Rect visible_rect; |
| 445 gfx::Size natural_size; | 417 gfx::Size natural_size; |
| 446 GetBufferData(picture.bitstream_buffer_id(), ×tamp, &visible_rect, | 418 GetBufferData(picture.bitstream_buffer_id(), ×tamp, &visible_rect, |
| 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(&GpuVideoDecoder::ReleaseMailbox, | 425 BindToCurrentLoop(base::Bind( |
| 454 weak_factory_.GetWeakPtr(), | 426 &GpuVideoDecoder::ReleaseMailbox, weak_factory_.GetWeakPtr(), |
| 455 factories_, | 427 factories_, picture.picture_buffer_id(), pb.texture_id())), |
| 456 picture.picture_buffer_id(), | 428 pb.size(), visible_rect, natural_size, timestamp)); |
| 457 pb.texture_id())), | |
| 458 pb.size(), | |
| 459 visible_rect, | |
| 460 natural_size, | |
| 461 timestamp, | |
| 462 base::Bind(&ReadPixelsSync, factories_, pb.texture_id(), visible_rect))); | |
| 463 CHECK_GT(available_pictures_, 0); | 429 CHECK_GT(available_pictures_, 0); |
| 464 --available_pictures_; | 430 --available_pictures_; |
| 465 bool inserted = | 431 bool inserted = |
| 466 picture_buffers_at_display_.insert(std::make_pair( | 432 picture_buffers_at_display_.insert(std::make_pair( |
| 467 picture.picture_buffer_id(), | 433 picture.picture_buffer_id(), |
| 468 pb.texture_id())).second; | 434 pb.texture_id())).second; |
| 469 DCHECK(inserted); | 435 DCHECK(inserted); |
| 470 | 436 |
| 471 DeliverFrame(frame); | 437 DeliverFrame(frame); |
| 472 } | 438 } |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 622 DLOG(ERROR) << "VDA Error: " << error; | 588 DLOG(ERROR) << "VDA Error: " << error; |
| 623 DestroyVDA(); | 589 DestroyVDA(); |
| 624 } | 590 } |
| 625 | 591 |
| 626 void GpuVideoDecoder::DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent() | 592 void GpuVideoDecoder::DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent() |
| 627 const { | 593 const { |
| 628 DCHECK(factories_->GetTaskRunner()->BelongsToCurrentThread()); | 594 DCHECK(factories_->GetTaskRunner()->BelongsToCurrentThread()); |
| 629 } | 595 } |
| 630 | 596 |
| 631 } // namespace media | 597 } // namespace media |
| OLD | NEW |