| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <algorithm> | 5 #include <algorithm> |
| 6 | 6 |
| 7 #include <CoreVideo/CoreVideo.h> | 7 #include <CoreVideo/CoreVideo.h> |
| 8 #include <OpenGL/CGLIOSurface.h> | 8 #include <OpenGL/CGLIOSurface.h> |
| 9 #include <OpenGL/gl.h> | 9 #include <OpenGL/gl.h> |
| 10 | 10 |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 return false; | 317 return false; |
| 318 | 318 |
| 319 // Count the session as successfully initialized. | 319 // Count the session as successfully initialized. |
| 320 UMA_HISTOGRAM_ENUMERATION("Media.VTVDA.SessionFailureReason", | 320 UMA_HISTOGRAM_ENUMERATION("Media.VTVDA.SessionFailureReason", |
| 321 SFT_SUCCESSFULLY_INITIALIZED, | 321 SFT_SUCCESSFULLY_INITIALIZED, |
| 322 SFT_MAX + 1); | 322 SFT_MAX + 1); |
| 323 return true; | 323 return true; |
| 324 } | 324 } |
| 325 | 325 |
| 326 bool VTVideoDecodeAccelerator::FinishDelayedFrames() { | 326 bool VTVideoDecodeAccelerator::FinishDelayedFrames() { |
| 327 DCHECK(decoder_thread_.task_runner()->BelongsToCurrentThread()); | 327 DCHECK(decoder_thread_.message_loop_proxy()->BelongsToCurrentThread()); |
| 328 if (session_) { | 328 if (session_) { |
| 329 OSStatus status = VTDecompressionSessionWaitForAsynchronousFrames(session_); | 329 OSStatus status = VTDecompressionSessionWaitForAsynchronousFrames(session_); |
| 330 if (status) { | 330 if (status) { |
| 331 NOTIFY_STATUS("VTDecompressionSessionWaitForAsynchronousFrames()", | 331 NOTIFY_STATUS("VTDecompressionSessionWaitForAsynchronousFrames()", |
| 332 status, SFT_PLATFORM_ERROR); | 332 status, SFT_PLATFORM_ERROR); |
| 333 return false; | 333 return false; |
| 334 } | 334 } |
| 335 } | 335 } |
| 336 return true; | 336 return true; |
| 337 } | 337 } |
| 338 | 338 |
| 339 bool VTVideoDecodeAccelerator::ConfigureDecoder() { | 339 bool VTVideoDecodeAccelerator::ConfigureDecoder() { |
| 340 DCHECK(decoder_thread_.task_runner()->BelongsToCurrentThread()); | 340 DCHECK(decoder_thread_.message_loop_proxy()->BelongsToCurrentThread()); |
| 341 DCHECK(!last_sps_.empty()); | 341 DCHECK(!last_sps_.empty()); |
| 342 DCHECK(!last_pps_.empty()); | 342 DCHECK(!last_pps_.empty()); |
| 343 | 343 |
| 344 // Build the configuration records. | 344 // Build the configuration records. |
| 345 std::vector<const uint8_t*> nalu_data_ptrs; | 345 std::vector<const uint8_t*> nalu_data_ptrs; |
| 346 std::vector<size_t> nalu_data_sizes; | 346 std::vector<size_t> nalu_data_sizes; |
| 347 nalu_data_ptrs.reserve(3); | 347 nalu_data_ptrs.reserve(3); |
| 348 nalu_data_sizes.reserve(3); | 348 nalu_data_sizes.reserve(3); |
| 349 nalu_data_ptrs.push_back(&last_sps_.front()); | 349 nalu_data_ptrs.push_back(&last_sps_.front()); |
| 350 nalu_data_sizes.push_back(last_sps_.size()); | 350 nalu_data_sizes.push_back(last_sps_.size()); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 using_hardware = CFBooleanGetValue(cf_using_hardware); | 440 using_hardware = CFBooleanGetValue(cf_using_hardware); |
| 441 } | 441 } |
| 442 UMA_HISTOGRAM_BOOLEAN("Media.VTVDA.HardwareAccelerated", using_hardware); | 442 UMA_HISTOGRAM_BOOLEAN("Media.VTVDA.HardwareAccelerated", using_hardware); |
| 443 | 443 |
| 444 return true; | 444 return true; |
| 445 } | 445 } |
| 446 | 446 |
| 447 void VTVideoDecodeAccelerator::DecodeTask( | 447 void VTVideoDecodeAccelerator::DecodeTask( |
| 448 const media::BitstreamBuffer& bitstream, | 448 const media::BitstreamBuffer& bitstream, |
| 449 Frame* frame) { | 449 Frame* frame) { |
| 450 DCHECK(decoder_thread_.task_runner()->BelongsToCurrentThread()); | 450 DCHECK(decoder_thread_.message_loop_proxy()->BelongsToCurrentThread()); |
| 451 | 451 |
| 452 // Map the bitstream buffer. | 452 // Map the bitstream buffer. |
| 453 base::SharedMemory memory(bitstream.handle(), true); | 453 base::SharedMemory memory(bitstream.handle(), true); |
| 454 size_t size = bitstream.size(); | 454 size_t size = bitstream.size(); |
| 455 if (!memory.Map(size)) { | 455 if (!memory.Map(size)) { |
| 456 DLOG(ERROR) << "Failed to map bitstream buffer"; | 456 DLOG(ERROR) << "Failed to map bitstream buffer"; |
| 457 NotifyError(PLATFORM_FAILURE, SFT_PLATFORM_ERROR); | 457 NotifyError(PLATFORM_FAILURE, SFT_PLATFORM_ERROR); |
| 458 return; | 458 return; |
| 459 } | 459 } |
| 460 const uint8_t* buf = static_cast<uint8_t*>(memory.memory()); | 460 const uint8_t* buf = static_cast<uint8_t*>(memory.memory()); |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 737 DCHECK(gpu_thread_checker_.CalledOnValidThread()); | 737 DCHECK(gpu_thread_checker_.CalledOnValidThread()); |
| 738 DCHECK_EQ(1u, pending_frames_.count(frame->bitstream_id)); | 738 DCHECK_EQ(1u, pending_frames_.count(frame->bitstream_id)); |
| 739 Task task(TASK_FRAME); | 739 Task task(TASK_FRAME); |
| 740 task.frame = pending_frames_[frame->bitstream_id]; | 740 task.frame = pending_frames_[frame->bitstream_id]; |
| 741 pending_frames_.erase(frame->bitstream_id); | 741 pending_frames_.erase(frame->bitstream_id); |
| 742 task_queue_.push(task); | 742 task_queue_.push(task); |
| 743 ProcessWorkQueues(); | 743 ProcessWorkQueues(); |
| 744 } | 744 } |
| 745 | 745 |
| 746 void VTVideoDecodeAccelerator::FlushTask(TaskType type) { | 746 void VTVideoDecodeAccelerator::FlushTask(TaskType type) { |
| 747 DCHECK(decoder_thread_.task_runner()->BelongsToCurrentThread()); | 747 DCHECK(decoder_thread_.message_loop_proxy()->BelongsToCurrentThread()); |
| 748 FinishDelayedFrames(); | 748 FinishDelayedFrames(); |
| 749 | 749 |
| 750 // Always queue a task, even if FinishDelayedFrames() fails, so that | 750 // Always queue a task, even if FinishDelayedFrames() fails, so that |
| 751 // destruction always completes. | 751 // destruction always completes. |
| 752 gpu_task_runner_->PostTask(FROM_HERE, base::Bind( | 752 gpu_task_runner_->PostTask(FROM_HERE, base::Bind( |
| 753 &VTVideoDecodeAccelerator::FlushDone, weak_this_, type)); | 753 &VTVideoDecodeAccelerator::FlushDone, weak_this_, type)); |
| 754 } | 754 } |
| 755 | 755 |
| 756 void VTVideoDecodeAccelerator::FlushDone(TaskType type) { | 756 void VTVideoDecodeAccelerator::FlushDone(TaskType type) { |
| 757 DCHECK(gpu_thread_checker_.CalledOnValidThread()); | 757 DCHECK(gpu_thread_checker_.CalledOnValidThread()); |
| 758 task_queue_.push(Task(type)); | 758 task_queue_.push(Task(type)); |
| 759 ProcessWorkQueues(); | 759 ProcessWorkQueues(); |
| 760 } | 760 } |
| 761 | 761 |
| 762 void VTVideoDecodeAccelerator::Decode(const media::BitstreamBuffer& bitstream) { | 762 void VTVideoDecodeAccelerator::Decode(const media::BitstreamBuffer& bitstream) { |
| 763 DCHECK(gpu_thread_checker_.CalledOnValidThread()); | 763 DCHECK(gpu_thread_checker_.CalledOnValidThread()); |
| 764 DCHECK_EQ(0u, assigned_bitstream_ids_.count(bitstream.id())); | 764 DCHECK_EQ(0u, assigned_bitstream_ids_.count(bitstream.id())); |
| 765 assigned_bitstream_ids_.insert(bitstream.id()); | 765 assigned_bitstream_ids_.insert(bitstream.id()); |
| 766 Frame* frame = new Frame(bitstream.id()); | 766 Frame* frame = new Frame(bitstream.id()); |
| 767 pending_frames_[frame->bitstream_id] = make_linked_ptr(frame); | 767 pending_frames_[frame->bitstream_id] = make_linked_ptr(frame); |
| 768 decoder_thread_.task_runner()->PostTask( | 768 decoder_thread_.message_loop_proxy()->PostTask(FROM_HERE, base::Bind( |
| 769 FROM_HERE, base::Bind(&VTVideoDecodeAccelerator::DecodeTask, | 769 &VTVideoDecodeAccelerator::DecodeTask, base::Unretained(this), |
| 770 base::Unretained(this), bitstream, frame)); | 770 bitstream, frame)); |
| 771 } | 771 } |
| 772 | 772 |
| 773 void VTVideoDecodeAccelerator::AssignPictureBuffers( | 773 void VTVideoDecodeAccelerator::AssignPictureBuffers( |
| 774 const std::vector<media::PictureBuffer>& pictures) { | 774 const std::vector<media::PictureBuffer>& pictures) { |
| 775 DCHECK(gpu_thread_checker_.CalledOnValidThread()); | 775 DCHECK(gpu_thread_checker_.CalledOnValidThread()); |
| 776 | 776 |
| 777 for (const media::PictureBuffer& picture : pictures) { | 777 for (const media::PictureBuffer& picture : pictures) { |
| 778 DCHECK(!texture_ids_.count(picture.id())); | 778 DCHECK(!texture_ids_.count(picture.id())); |
| 779 assigned_picture_ids_.insert(picture.id()); | 779 assigned_picture_ids_.insert(picture.id()); |
| 780 available_picture_ids_.push_back(picture.id()); | 780 available_picture_ids_.push_back(picture.id()); |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 997 UMA_HISTOGRAM_ENUMERATION("Media.VTVDA.SessionFailureReason", | 997 UMA_HISTOGRAM_ENUMERATION("Media.VTVDA.SessionFailureReason", |
| 998 session_failure_type, | 998 session_failure_type, |
| 999 SFT_MAX + 1); | 999 SFT_MAX + 1); |
| 1000 client_->NotifyError(vda_error_type); | 1000 client_->NotifyError(vda_error_type); |
| 1001 } | 1001 } |
| 1002 } | 1002 } |
| 1003 | 1003 |
| 1004 void VTVideoDecodeAccelerator::QueueFlush(TaskType type) { | 1004 void VTVideoDecodeAccelerator::QueueFlush(TaskType type) { |
| 1005 DCHECK(gpu_thread_checker_.CalledOnValidThread()); | 1005 DCHECK(gpu_thread_checker_.CalledOnValidThread()); |
| 1006 pending_flush_tasks_.push(type); | 1006 pending_flush_tasks_.push(type); |
| 1007 decoder_thread_.task_runner()->PostTask( | 1007 decoder_thread_.message_loop_proxy()->PostTask(FROM_HERE, base::Bind( |
| 1008 FROM_HERE, base::Bind(&VTVideoDecodeAccelerator::FlushTask, | 1008 &VTVideoDecodeAccelerator::FlushTask, base::Unretained(this), |
| 1009 base::Unretained(this), type)); | 1009 type)); |
| 1010 | 1010 |
| 1011 // If this is a new flush request, see if we can make progress. | 1011 // If this is a new flush request, see if we can make progress. |
| 1012 if (pending_flush_tasks_.size() == 1) | 1012 if (pending_flush_tasks_.size() == 1) |
| 1013 ProcessWorkQueues(); | 1013 ProcessWorkQueues(); |
| 1014 } | 1014 } |
| 1015 | 1015 |
| 1016 void VTVideoDecodeAccelerator::Flush() { | 1016 void VTVideoDecodeAccelerator::Flush() { |
| 1017 DCHECK(gpu_thread_checker_.CalledOnValidThread()); | 1017 DCHECK(gpu_thread_checker_.CalledOnValidThread()); |
| 1018 QueueFlush(TASK_FLUSH); | 1018 QueueFlush(TASK_FLUSH); |
| 1019 } | 1019 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1055 SupportedProfile profile; | 1055 SupportedProfile profile; |
| 1056 profile.profile = supported_profile; | 1056 profile.profile = supported_profile; |
| 1057 profile.min_resolution.SetSize(16, 16); | 1057 profile.min_resolution.SetSize(16, 16); |
| 1058 profile.max_resolution.SetSize(4096, 2160); | 1058 profile.max_resolution.SetSize(4096, 2160); |
| 1059 profiles.push_back(profile); | 1059 profiles.push_back(profile); |
| 1060 } | 1060 } |
| 1061 return profiles; | 1061 return profiles; |
| 1062 } | 1062 } |
| 1063 | 1063 |
| 1064 } // namespace content | 1064 } // namespace content |
| OLD | NEW |