Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/renderer/media/rtc_video_decoder.h" | 5 #include "content/renderer/media/rtc_video_decoder.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/message_loop/message_loop_proxy.h" | 10 #include "base/message_loop/message_loop_proxy.h" |
| (...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 401 { | 401 { |
| 402 base::AutoLock auto_lock(lock_); | 402 base::AutoLock auto_lock(lock_); |
| 403 DCHECK(decode_complete_callback_ != NULL); | 403 DCHECK(decode_complete_callback_ != NULL); |
| 404 if (IsBufferAfterReset(picture.bitstream_buffer_id(), | 404 if (IsBufferAfterReset(picture.bitstream_buffer_id(), |
| 405 reset_bitstream_buffer_id_)) { | 405 reset_bitstream_buffer_id_)) { |
| 406 decode_complete_callback_->Decoded(decoded_image); | 406 decode_complete_callback_->Decoded(decoded_image); |
| 407 } | 407 } |
| 408 } | 408 } |
| 409 } | 409 } |
| 410 | 410 |
| 411 static void ReadPixelsSyncInner( | |
| 412 const scoped_refptr<media::GpuVideoAcceleratorFactories>& factories, | |
| 413 uint32 texture_id, | |
| 414 const gfx::Rect& visible_rect, | |
| 415 const SkBitmap& pixels, | |
| 416 base::WaitableEvent* event) { | |
| 417 factories->ReadPixels(texture_id, visible_rect, pixels); | |
| 418 event->Signal(); | |
| 419 } | |
| 420 | |
| 421 static void ReadPixelsSync( | |
| 422 const scoped_refptr<media::GpuVideoAcceleratorFactories>& factories, | |
| 423 uint32 texture_id, | |
| 424 const gfx::Rect& visible_rect, | |
| 425 const SkBitmap& pixels) { | |
| 426 base::WaitableEvent event(true, false); | |
|
dshwang
2015/01/14 20:32:13
similar impl to GpuVideoDecoder.
| |
| 427 if (!factories->GetTaskRunner()->PostTask(FROM_HERE, | |
| 428 base::Bind(&ReadPixelsSyncInner, | |
| 429 factories, | |
| 430 texture_id, | |
| 431 visible_rect, | |
| 432 pixels, | |
| 433 &event))) | |
| 434 return; | |
| 435 event.Wait(); | |
| 436 } | |
| 437 | |
| 438 scoped_refptr<media::VideoFrame> RTCVideoDecoder::CreateVideoFrame( | 411 scoped_refptr<media::VideoFrame> RTCVideoDecoder::CreateVideoFrame( |
| 439 const media::Picture& picture, | 412 const media::Picture& picture, |
| 440 const media::PictureBuffer& pb, | 413 const media::PictureBuffer& pb, |
| 441 uint32_t timestamp) { | 414 uint32_t timestamp) { |
| 442 gfx::Rect visible_rect(picture.visible_rect()); | 415 gfx::Rect visible_rect(picture.visible_rect()); |
| 443 DCHECK(decoder_texture_target_); | 416 DCHECK(decoder_texture_target_); |
| 444 // Convert timestamp from 90KHz to ms. | 417 // Convert timestamp from 90KHz to ms. |
| 445 base::TimeDelta timestamp_ms = base::TimeDelta::FromInternalValue( | 418 base::TimeDelta timestamp_ms = base::TimeDelta::FromInternalValue( |
| 446 base::checked_cast<uint64_t>(timestamp) * 1000 / 90); | 419 base::checked_cast<uint64_t>(timestamp) * 1000 / 90); |
| 447 return media::VideoFrame::WrapNativeTexture( | 420 return media::VideoFrame::WrapNativeTexture( |
| 448 make_scoped_ptr(new gpu::MailboxHolder( | 421 make_scoped_ptr(new gpu::MailboxHolder(pb.texture_mailbox(), |
| 449 pb.texture_mailbox(), decoder_texture_target_, 0)), | 422 decoder_texture_target_, 0)), |
| 450 media::BindToCurrentLoop(base::Bind(&RTCVideoDecoder::ReleaseMailbox, | 423 media::BindToCurrentLoop(base::Bind( |
| 451 weak_factory_.GetWeakPtr(), | 424 &RTCVideoDecoder::ReleaseMailbox, weak_factory_.GetWeakPtr(), |
| 452 factories_, | 425 factories_, picture.picture_buffer_id(), pb.texture_id())), |
| 453 picture.picture_buffer_id(), | 426 pb.size(), visible_rect, visible_rect.size(), timestamp_ms); |
| 454 pb.texture_id())), | |
| 455 pb.size(), | |
| 456 visible_rect, | |
| 457 visible_rect.size(), | |
| 458 timestamp_ms, | |
| 459 base::Bind(&ReadPixelsSync, factories_, pb.texture_id(), visible_rect)); | |
| 460 } | 427 } |
| 461 | 428 |
| 462 void RTCVideoDecoder::NotifyEndOfBitstreamBuffer(int32 id) { | 429 void RTCVideoDecoder::NotifyEndOfBitstreamBuffer(int32 id) { |
| 463 DVLOG(3) << "NotifyEndOfBitstreamBuffer. id=" << id; | 430 DVLOG(3) << "NotifyEndOfBitstreamBuffer. id=" << id; |
| 464 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); | 431 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); |
| 465 | 432 |
| 466 std::map<int32, SHMBuffer*>::iterator it = | 433 std::map<int32, SHMBuffer*>::iterator it = |
| 467 bitstream_buffers_in_decoder_.find(id); | 434 bitstream_buffers_in_decoder_.find(id); |
| 468 if (it == bitstream_buffers_in_decoder_.end()) { | 435 if (it == bitstream_buffers_in_decoder_.end()) { |
| 469 NotifyError(media::VideoDecodeAccelerator::PLATFORM_FAILURE); | 436 NotifyError(media::VideoDecodeAccelerator::PLATFORM_FAILURE); |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 809 UMA_HISTOGRAM_BOOLEAN("Media.RTCVideoDecoderInitDecodeSuccess", sample); | 776 UMA_HISTOGRAM_BOOLEAN("Media.RTCVideoDecoderInitDecodeSuccess", sample); |
| 810 return status; | 777 return status; |
| 811 } | 778 } |
| 812 | 779 |
| 813 void RTCVideoDecoder::DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent() | 780 void RTCVideoDecoder::DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent() |
| 814 const { | 781 const { |
| 815 DCHECK(factories_->GetTaskRunner()->BelongsToCurrentThread()); | 782 DCHECK(factories_->GetTaskRunner()->BelongsToCurrentThread()); |
| 816 } | 783 } |
| 817 | 784 |
| 818 } // namespace content | 785 } // namespace content |
| OLD | NEW |