| 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/vpx_video_decoder.h" | 5 #include "media/filters/vpx_video_decoder.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 // destroyed. | 223 // destroyed. |
| 224 void OnVideoFrameDestroyed(VP9FrameBuffer* frame_buffer); | 224 void OnVideoFrameDestroyed(VP9FrameBuffer* frame_buffer); |
| 225 | 225 |
| 226 // Frame buffers to be used by libvpx for VP9 Decoding. | 226 // Frame buffers to be used by libvpx for VP9 Decoding. |
| 227 std::vector<std::unique_ptr<VP9FrameBuffer>> frame_buffers_; | 227 std::vector<std::unique_ptr<VP9FrameBuffer>> frame_buffers_; |
| 228 | 228 |
| 229 DISALLOW_COPY_AND_ASSIGN(MemoryPool); | 229 DISALLOW_COPY_AND_ASSIGN(MemoryPool); |
| 230 }; | 230 }; |
| 231 | 231 |
| 232 VpxVideoDecoder::MemoryPool::MemoryPool() { | 232 VpxVideoDecoder::MemoryPool::MemoryPool() { |
| 233 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( | |
| 234 this, "VpxVideoDecoder", base::ThreadTaskRunnerHandle::Get()); | |
| 235 } | 233 } |
| 236 | 234 |
| 237 VpxVideoDecoder::MemoryPool::~MemoryPool() { | 235 VpxVideoDecoder::MemoryPool::~MemoryPool() { |
| 238 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( | |
| 239 this); | |
| 240 } | 236 } |
| 241 | 237 |
| 242 VpxVideoDecoder::MemoryPool::VP9FrameBuffer* | 238 VpxVideoDecoder::MemoryPool::VP9FrameBuffer* |
| 243 VpxVideoDecoder::MemoryPool::GetFreeFrameBuffer(size_t min_size) { | 239 VpxVideoDecoder::MemoryPool::GetFreeFrameBuffer(size_t min_size) { |
| 244 // Check if a free frame buffer exists. | 240 // Check if a free frame buffer exists. |
| 245 size_t i = 0; | 241 size_t i = 0; |
| 246 for (; i < frame_buffers_.size(); ++i) { | 242 for (; i < frame_buffers_.size(); ++i) { |
| 247 if (frame_buffers_[i]->ref_cnt == 0) | 243 if (frame_buffers_[i]->ref_cnt == 0) |
| 248 break; | 244 break; |
| 249 } | 245 } |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 475 DCHECK(vpx_codec_get_caps(vpx_codec_->iface) & | 471 DCHECK(vpx_codec_get_caps(vpx_codec_->iface) & |
| 476 VPX_CODEC_CAP_EXTERNAL_FRAME_BUFFER); | 472 VPX_CODEC_CAP_EXTERNAL_FRAME_BUFFER); |
| 477 | 473 |
| 478 // Move high resolution vp9 decodes off of the main media thread (otherwise | 474 // Move high resolution vp9 decodes off of the main media thread (otherwise |
| 479 // decode may block audio decoding, demuxing, and other control activities). | 475 // decode may block audio decoding, demuxing, and other control activities). |
| 480 if (config.coded_size().width() >= 1024) { | 476 if (config.coded_size().width() >= 1024) { |
| 481 offload_task_runner_ = | 477 offload_task_runner_ = |
| 482 g_vpx_offload_thread.Pointer()->RequestOffloadThread(); | 478 g_vpx_offload_thread.Pointer()->RequestOffloadThread(); |
| 483 } | 479 } |
| 484 | 480 |
| 481 DCHECK(!memory_pool_); |
| 485 memory_pool_ = new MemoryPool(); | 482 memory_pool_ = new MemoryPool(); |
| 483 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( |
| 484 memory_pool_.get(), "VpxVideoDecoder", |
| 485 base::ThreadTaskRunnerHandle::Get()); |
| 486 |
| 486 if (vpx_codec_set_frame_buffer_functions(vpx_codec_, | 487 if (vpx_codec_set_frame_buffer_functions(vpx_codec_, |
| 487 &MemoryPool::GetVP9FrameBuffer, | 488 &MemoryPool::GetVP9FrameBuffer, |
| 488 &MemoryPool::ReleaseVP9FrameBuffer, | 489 &MemoryPool::ReleaseVP9FrameBuffer, |
| 489 memory_pool_.get())) { | 490 memory_pool_.get())) { |
| 490 DLOG(ERROR) << "Failed to configure external buffers. " | 491 DLOG(ERROR) << "Failed to configure external buffers. " |
| 491 << vpx_codec_error(vpx_codec_); | 492 << vpx_codec_error(vpx_codec_); |
| 492 return false; | 493 return false; |
| 493 } | 494 } |
| 494 } | 495 } |
| 495 | 496 |
| 496 if (config.format() != PIXEL_FORMAT_YV12A) | 497 if (config.format() != PIXEL_FORMAT_YV12A) |
| 497 return true; | 498 return true; |
| 498 | 499 |
| 499 vpx_codec_alpha_ = InitializeVpxContext(vpx_codec_alpha_, config); | 500 vpx_codec_alpha_ = InitializeVpxContext(vpx_codec_alpha_, config); |
| 500 return !!vpx_codec_alpha_; | 501 return !!vpx_codec_alpha_; |
| 501 } | 502 } |
| 502 | 503 |
| 503 void VpxVideoDecoder::CloseDecoder() { | 504 void VpxVideoDecoder::CloseDecoder() { |
| 504 if (offload_task_runner_) { | 505 if (offload_task_runner_) { |
| 505 g_vpx_offload_thread.Pointer() | 506 g_vpx_offload_thread.Pointer() |
| 506 ->WaitForOutstandingTasksAndReleaseOffloadThread(); | 507 ->WaitForOutstandingTasksAndReleaseOffloadThread(); |
| 507 offload_task_runner_ = nullptr; | 508 offload_task_runner_ = nullptr; |
| 508 } | 509 } |
| 509 | 510 |
| 510 if (vpx_codec_) { | 511 if (vpx_codec_) { |
| 511 vpx_codec_destroy(vpx_codec_); | 512 vpx_codec_destroy(vpx_codec_); |
| 512 delete vpx_codec_; | 513 delete vpx_codec_; |
| 513 vpx_codec_ = nullptr; | 514 vpx_codec_ = nullptr; |
| 515 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( |
| 516 memory_pool_.get()); |
| 514 memory_pool_ = nullptr; | 517 memory_pool_ = nullptr; |
| 515 } | 518 } |
| 516 if (vpx_codec_alpha_) { | 519 if (vpx_codec_alpha_) { |
| 517 vpx_codec_destroy(vpx_codec_alpha_); | 520 vpx_codec_destroy(vpx_codec_alpha_); |
| 518 delete vpx_codec_alpha_; | 521 delete vpx_codec_alpha_; |
| 519 vpx_codec_alpha_ = nullptr; | 522 vpx_codec_alpha_ = nullptr; |
| 520 } | 523 } |
| 521 } | 524 } |
| 522 | 525 |
| 523 bool VpxVideoDecoder::VpxDecode(const scoped_refptr<DecoderBuffer>& buffer, | 526 bool VpxVideoDecoder::VpxDecode(const scoped_refptr<DecoderBuffer>& buffer, |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 826 (*video_frame)->visible_data(VideoFrame::kUPlane), | 829 (*video_frame)->visible_data(VideoFrame::kUPlane), |
| 827 (*video_frame)->stride(VideoFrame::kUPlane), | 830 (*video_frame)->stride(VideoFrame::kUPlane), |
| 828 (*video_frame)->visible_data(VideoFrame::kVPlane), | 831 (*video_frame)->visible_data(VideoFrame::kVPlane), |
| 829 (*video_frame)->stride(VideoFrame::kVPlane), coded_size.width(), | 832 (*video_frame)->stride(VideoFrame::kVPlane), coded_size.width(), |
| 830 coded_size.height()); | 833 coded_size.height()); |
| 831 | 834 |
| 832 return true; | 835 return true; |
| 833 } | 836 } |
| 834 | 837 |
| 835 } // namespace media | 838 } // namespace media |
| OLD | NEW |