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