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 "content/common/gpu/media/vaapi_video_decode_accelerator.h" | 5 #include "content/common/gpu/media/vaapi_video_decode_accelerator.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 Pictures::iterator it = pictures_.find(picture_buffer_id); | 285 Pictures::iterator it = pictures_.find(picture_buffer_id); |
286 if (it == pictures_.end()) { | 286 if (it == pictures_.end()) { |
287 LOG(ERROR) << "Picture id " << picture_buffer_id << " does not exist"; | 287 LOG(ERROR) << "Picture id " << picture_buffer_id << " does not exist"; |
288 return NULL; | 288 return NULL; |
289 } | 289 } |
290 | 290 |
291 return it->second.get(); | 291 return it->second.get(); |
292 } | 292 } |
293 | 293 |
294 VaapiVideoDecodeAccelerator::VaapiVideoDecodeAccelerator( | 294 VaapiVideoDecodeAccelerator::VaapiVideoDecodeAccelerator( |
295 const MakeContextCurrentCallback& make_context_current, | 295 const MakeGLContextCurrentCallback& make_context_current_cb, |
296 const BindImageCallback& bind_image) | 296 const BindGLImageCallback& bind_image_cb) |
297 : make_context_current_(make_context_current), | 297 : state_(kUninitialized), |
298 state_(kUninitialized), | |
299 input_ready_(&lock_), | 298 input_ready_(&lock_), |
300 surfaces_available_(&lock_), | 299 surfaces_available_(&lock_), |
301 message_loop_(base::MessageLoop::current()), | 300 message_loop_(base::MessageLoop::current()), |
302 decoder_thread_("VaapiDecoderThread"), | 301 decoder_thread_("VaapiDecoderThread"), |
303 num_frames_at_client_(0), | 302 num_frames_at_client_(0), |
304 num_stream_bufs_at_decoder_(0), | 303 num_stream_bufs_at_decoder_(0), |
305 finish_flush_pending_(false), | 304 finish_flush_pending_(false), |
306 awaiting_va_surfaces_recycle_(false), | 305 awaiting_va_surfaces_recycle_(false), |
307 requested_num_pics_(0), | 306 requested_num_pics_(0), |
308 bind_image_(bind_image), | 307 make_context_current_cb_(make_context_current_cb), |
| 308 bind_image_cb_(bind_image_cb), |
309 weak_this_factory_(this) { | 309 weak_this_factory_(this) { |
310 weak_this_ = weak_this_factory_.GetWeakPtr(); | 310 weak_this_ = weak_this_factory_.GetWeakPtr(); |
311 va_surface_release_cb_ = media::BindToCurrentLoop( | 311 va_surface_release_cb_ = media::BindToCurrentLoop( |
312 base::Bind(&VaapiVideoDecodeAccelerator::RecycleVASurfaceID, weak_this_)); | 312 base::Bind(&VaapiVideoDecodeAccelerator::RecycleVASurfaceID, weak_this_)); |
313 } | 313 } |
314 | 314 |
315 VaapiVideoDecodeAccelerator::~VaapiVideoDecodeAccelerator() { | 315 VaapiVideoDecodeAccelerator::~VaapiVideoDecodeAccelerator() { |
316 DCHECK_EQ(message_loop_, base::MessageLoop::current()); | 316 DCHECK_EQ(message_loop_, base::MessageLoop::current()); |
317 } | 317 } |
318 | 318 |
319 bool VaapiVideoDecodeAccelerator::Initialize(const Config& config, | 319 bool VaapiVideoDecodeAccelerator::Initialize(const Config& config, |
320 Client* client) { | 320 Client* client) { |
321 DCHECK_EQ(message_loop_, base::MessageLoop::current()); | 321 DCHECK_EQ(message_loop_, base::MessageLoop::current()); |
322 | 322 |
| 323 if (make_context_current_cb_.is_null() || bind_image_cb_.is_null()) { |
| 324 NOTREACHED() << "GL callbacks are required for this VDA"; |
| 325 return false; |
| 326 } |
| 327 |
323 if (config.is_encrypted) { | 328 if (config.is_encrypted) { |
324 NOTREACHED() << "Encrypted streams are not supported for this VDA"; | 329 NOTREACHED() << "Encrypted streams are not supported for this VDA"; |
325 return false; | 330 return false; |
326 } | 331 } |
327 | 332 |
328 client_ptr_factory_.reset(new base::WeakPtrFactory<Client>(client)); | 333 client_ptr_factory_.reset(new base::WeakPtrFactory<Client>(client)); |
329 client_ = client_ptr_factory_->GetWeakPtr(); | 334 client_ = client_ptr_factory_->GetWeakPtr(); |
330 | 335 |
331 media::VideoCodecProfile profile = config.profile; | 336 media::VideoCodecProfile profile = config.profile; |
332 | 337 |
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
734 buffers.size(), &va_surface_ids), | 739 buffers.size(), &va_surface_ids), |
735 "Failed creating VA Surfaces", PLATFORM_FAILURE, ); | 740 "Failed creating VA Surfaces", PLATFORM_FAILURE, ); |
736 DCHECK_EQ(va_surface_ids.size(), buffers.size()); | 741 DCHECK_EQ(va_surface_ids.size(), buffers.size()); |
737 | 742 |
738 for (size_t i = 0; i < buffers.size(); ++i) { | 743 for (size_t i = 0; i < buffers.size(); ++i) { |
739 DVLOG(2) << "Assigning picture id: " << buffers[i].id() | 744 DVLOG(2) << "Assigning picture id: " << buffers[i].id() |
740 << " to texture id: " << buffers[i].texture_id() | 745 << " to texture id: " << buffers[i].texture_id() |
741 << " VASurfaceID: " << va_surface_ids[i]; | 746 << " VASurfaceID: " << va_surface_ids[i]; |
742 | 747 |
743 linked_ptr<VaapiPicture> picture(VaapiPicture::CreatePicture( | 748 linked_ptr<VaapiPicture> picture(VaapiPicture::CreatePicture( |
744 vaapi_wrapper_, make_context_current_, buffers[i].id(), | 749 vaapi_wrapper_, make_context_current_cb_, buffers[i].id(), |
745 buffers[i].texture_id(), requested_pic_size_)); | 750 buffers[i].texture_id(), requested_pic_size_)); |
746 | 751 |
747 scoped_refptr<gl::GLImage> image = picture->GetImageToBind(); | 752 scoped_refptr<gl::GLImage> image = picture->GetImageToBind(); |
748 if (image) { | 753 if (image) { |
749 bind_image_.Run(buffers[i].internal_texture_id(), | 754 RETURN_AND_NOTIFY_ON_FAILURE( |
750 VaapiPicture::GetGLTextureTarget(), image, true); | 755 bind_image_cb_.Run(buffers[i].internal_texture_id(), |
| 756 VaapiPicture::GetGLTextureTarget(), image, true), |
| 757 "Failed to bind image", PLATFORM_FAILURE, ); |
751 } | 758 } |
752 | 759 |
753 RETURN_AND_NOTIFY_ON_FAILURE( | 760 RETURN_AND_NOTIFY_ON_FAILURE( |
754 picture.get(), "Failed assigning picture buffer to a texture.", | 761 picture.get(), "Failed assigning picture buffer to a texture.", |
755 PLATFORM_FAILURE, ); | 762 PLATFORM_FAILURE, ); |
756 | 763 |
757 bool inserted = | 764 bool inserted = |
758 pictures_.insert(std::make_pair(buffers[i].id(), picture)).second; | 765 pictures_.insert(std::make_pair(buffers[i].id(), picture)).second; |
759 DCHECK(inserted); | 766 DCHECK(inserted); |
760 | 767 |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
955 | 962 |
956 state_ = kUninitialized; | 963 state_ = kUninitialized; |
957 } | 964 } |
958 | 965 |
959 void VaapiVideoDecodeAccelerator::Destroy() { | 966 void VaapiVideoDecodeAccelerator::Destroy() { |
960 DCHECK_EQ(message_loop_, base::MessageLoop::current()); | 967 DCHECK_EQ(message_loop_, base::MessageLoop::current()); |
961 Cleanup(); | 968 Cleanup(); |
962 delete this; | 969 delete this; |
963 } | 970 } |
964 | 971 |
965 bool VaapiVideoDecodeAccelerator::CanDecodeOnIOThread() { | 972 bool VaapiVideoDecodeAccelerator::TryToSetupDecodeOnSeparateThread( |
| 973 const base::WeakPtr<Client>& decode_client, |
| 974 const scoped_refptr<base::SingleThreadTaskRunner>& decode_task_runner) { |
966 return false; | 975 return false; |
967 } | 976 } |
968 | 977 |
969 bool VaapiVideoDecodeAccelerator::DecodeSurface( | 978 bool VaapiVideoDecodeAccelerator::DecodeSurface( |
970 const scoped_refptr<VaapiDecodeSurface>& dec_surface) { | 979 const scoped_refptr<VaapiDecodeSurface>& dec_surface) { |
971 if (!vaapi_wrapper_->ExecuteAndDestroyPendingBuffers( | 980 if (!vaapi_wrapper_->ExecuteAndDestroyPendingBuffers( |
972 dec_surface->va_surface()->id())) { | 981 dec_surface->va_surface()->id())) { |
973 DVLOG(1) << "Failed decoding picture"; | 982 DVLOG(1) << "Failed decoding picture"; |
974 return false; | 983 return false; |
975 } | 984 } |
(...skipping 768 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1744 return vaapi_pic->dec_surface(); | 1753 return vaapi_pic->dec_surface(); |
1745 } | 1754 } |
1746 | 1755 |
1747 // static | 1756 // static |
1748 media::VideoDecodeAccelerator::SupportedProfiles | 1757 media::VideoDecodeAccelerator::SupportedProfiles |
1749 VaapiVideoDecodeAccelerator::GetSupportedProfiles() { | 1758 VaapiVideoDecodeAccelerator::GetSupportedProfiles() { |
1750 return VaapiWrapper::GetSupportedDecodeProfiles(); | 1759 return VaapiWrapper::GetSupportedDecodeProfiles(); |
1751 } | 1760 } |
1752 | 1761 |
1753 } // namespace content | 1762 } // namespace content |
OLD | NEW |