| 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/debug/trace_event.h" | 6 #include "base/debug/trace_event.h" |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 | 228 |
| 229 VaapiVideoDecodeAccelerator::VaapiVideoDecodeAccelerator( | 229 VaapiVideoDecodeAccelerator::VaapiVideoDecodeAccelerator( |
| 230 Display* x_display, | 230 Display* x_display, |
| 231 const base::Callback<bool(void)>& make_context_current) | 231 const base::Callback<bool(void)>& make_context_current) |
| 232 : x_display_(x_display), | 232 : x_display_(x_display), |
| 233 make_context_current_(make_context_current), | 233 make_context_current_(make_context_current), |
| 234 state_(kUninitialized), | 234 state_(kUninitialized), |
| 235 input_ready_(&lock_), | 235 input_ready_(&lock_), |
| 236 surfaces_available_(&lock_), | 236 surfaces_available_(&lock_), |
| 237 message_loop_(base::MessageLoop::current()), | 237 message_loop_(base::MessageLoop::current()), |
| 238 weak_this_(base::AsWeakPtr(this)), | |
| 239 va_surface_release_cb_(media::BindToCurrentLoop(base::Bind( | |
| 240 &VaapiVideoDecodeAccelerator::RecycleVASurfaceID, weak_this_))), | |
| 241 decoder_thread_("VaapiDecoderThread"), | 238 decoder_thread_("VaapiDecoderThread"), |
| 242 num_frames_at_client_(0), | 239 num_frames_at_client_(0), |
| 243 num_stream_bufs_at_decoder_(0), | 240 num_stream_bufs_at_decoder_(0), |
| 244 finish_flush_pending_(false), | 241 finish_flush_pending_(false), |
| 245 awaiting_va_surfaces_recycle_(false), | 242 awaiting_va_surfaces_recycle_(false), |
| 246 requested_num_pics_(0) { | 243 requested_num_pics_(0), |
| 244 weak_this_factory_(this) { |
| 245 weak_this_ = weak_this_factory_.GetWeakPtr(); |
| 246 va_surface_release_cb_ = media::BindToCurrentLoop( |
| 247 base::Bind(&VaapiVideoDecodeAccelerator::RecycleVASurfaceID, weak_this_)); |
| 247 } | 248 } |
| 248 | 249 |
| 249 VaapiVideoDecodeAccelerator::~VaapiVideoDecodeAccelerator() { | 250 VaapiVideoDecodeAccelerator::~VaapiVideoDecodeAccelerator() { |
| 250 DCHECK_EQ(message_loop_, base::MessageLoop::current()); | 251 DCHECK_EQ(message_loop_, base::MessageLoop::current()); |
| 251 } | 252 } |
| 252 | 253 |
| 253 class XFreeDeleter { | 254 class XFreeDeleter { |
| 254 public: | 255 public: |
| 255 void operator()(void* x) const { | 256 void operator()(void* x) const { |
| 256 ::XFree(x); | 257 ::XFree(x); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 new VaapiH264Decoder( | 312 new VaapiH264Decoder( |
| 312 vaapi_wrapper_.get(), | 313 vaapi_wrapper_.get(), |
| 313 media::BindToCurrentLoop(base::Bind( | 314 media::BindToCurrentLoop(base::Bind( |
| 314 &VaapiVideoDecodeAccelerator::SurfaceReady, weak_this_)), | 315 &VaapiVideoDecodeAccelerator::SurfaceReady, weak_this_)), |
| 315 base::Bind(&ReportToUMA))); | 316 base::Bind(&ReportToUMA))); |
| 316 | 317 |
| 317 CHECK(decoder_thread_.Start()); | 318 CHECK(decoder_thread_.Start()); |
| 318 decoder_thread_proxy_ = decoder_thread_.message_loop_proxy(); | 319 decoder_thread_proxy_ = decoder_thread_.message_loop_proxy(); |
| 319 | 320 |
| 320 state_ = kIdle; | 321 state_ = kIdle; |
| 321 | |
| 322 message_loop_->PostTask(FROM_HERE, base::Bind( | |
| 323 &Client::NotifyInitializeDone, client_)); | |
| 324 return true; | 322 return true; |
| 325 } | 323 } |
| 326 | 324 |
| 327 void VaapiVideoDecodeAccelerator::SurfaceReady( | 325 void VaapiVideoDecodeAccelerator::SurfaceReady( |
| 328 int32 input_id, | 326 int32 input_id, |
| 329 const scoped_refptr<VASurface>& va_surface) { | 327 const scoped_refptr<VASurface>& va_surface) { |
| 330 DCHECK_EQ(message_loop_, base::MessageLoop::current()); | 328 DCHECK_EQ(message_loop_, base::MessageLoop::current()); |
| 331 DCHECK(!awaiting_va_surfaces_recycle_); | 329 DCHECK(!awaiting_va_surfaces_recycle_); |
| 332 | 330 |
| 333 // Drop any requests to output if we are resetting or being destroyed. | 331 // Drop any requests to output if we are resetting or being destroyed. |
| (...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 888 DCHECK_EQ(message_loop_, base::MessageLoop::current()); | 886 DCHECK_EQ(message_loop_, base::MessageLoop::current()); |
| 889 | 887 |
| 890 if (state_ == kUninitialized || state_ == kDestroying) | 888 if (state_ == kUninitialized || state_ == kDestroying) |
| 891 return; | 889 return; |
| 892 | 890 |
| 893 DVLOG(1) << "Destroying VAVDA"; | 891 DVLOG(1) << "Destroying VAVDA"; |
| 894 base::AutoLock auto_lock(lock_); | 892 base::AutoLock auto_lock(lock_); |
| 895 state_ = kDestroying; | 893 state_ = kDestroying; |
| 896 | 894 |
| 897 client_ptr_factory_.reset(); | 895 client_ptr_factory_.reset(); |
| 896 weak_this_factory_.InvalidateWeakPtrs(); |
| 898 | 897 |
| 899 { | 898 { |
| 900 base::AutoUnlock auto_unlock(lock_); | 899 base::AutoUnlock auto_unlock(lock_); |
| 901 // Post a dummy task to the decoder_thread_ to ensure it is drained. | 900 // Post a dummy task to the decoder_thread_ to ensure it is drained. |
| 902 base::WaitableEvent waiter(false, false); | 901 base::WaitableEvent waiter(false, false); |
| 903 decoder_thread_proxy_->PostTask(FROM_HERE, base::Bind( | 902 decoder_thread_proxy_->PostTask(FROM_HERE, base::Bind( |
| 904 &base::WaitableEvent::Signal, base::Unretained(&waiter))); | 903 &base::WaitableEvent::Signal, base::Unretained(&waiter))); |
| 905 input_ready_.Signal(); | 904 input_ready_.Signal(); |
| 906 surfaces_available_.Signal(); | 905 surfaces_available_.Signal(); |
| 907 waiter.Wait(); | 906 waiter.Wait(); |
| 908 decoder_thread_.Stop(); | 907 decoder_thread_.Stop(); |
| 909 } | 908 } |
| 910 | 909 |
| 911 state_ = kUninitialized; | 910 state_ = kUninitialized; |
| 912 } | 911 } |
| 913 | 912 |
| 914 void VaapiVideoDecodeAccelerator::Destroy() { | 913 void VaapiVideoDecodeAccelerator::Destroy() { |
| 915 DCHECK_EQ(message_loop_, base::MessageLoop::current()); | 914 DCHECK_EQ(message_loop_, base::MessageLoop::current()); |
| 916 Cleanup(); | 915 Cleanup(); |
| 917 delete this; | 916 delete this; |
| 918 } | 917 } |
| 919 | 918 |
| 920 } // namespace content | 919 } // namespace content |
| OLD | NEW |