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 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 | 237 |
238 VaapiVideoDecodeAccelerator::VaapiVideoDecodeAccelerator( | 238 VaapiVideoDecodeAccelerator::VaapiVideoDecodeAccelerator( |
239 Display* x_display, | 239 Display* x_display, |
240 const base::Callback<bool(void)>& make_context_current) | 240 const base::Callback<bool(void)>& make_context_current) |
241 : x_display_(x_display), | 241 : x_display_(x_display), |
242 make_context_current_(make_context_current), | 242 make_context_current_(make_context_current), |
243 state_(kUninitialized), | 243 state_(kUninitialized), |
244 input_ready_(&lock_), | 244 input_ready_(&lock_), |
245 surfaces_available_(&lock_), | 245 surfaces_available_(&lock_), |
246 message_loop_(base::MessageLoop::current()), | 246 message_loop_(base::MessageLoop::current()), |
247 weak_this_(base::AsWeakPtr(this)), | |
248 va_surface_release_cb_(media::BindToCurrentLoop(base::Bind( | |
249 &VaapiVideoDecodeAccelerator::RecycleVASurfaceID, weak_this_))), | |
250 decoder_thread_("VaapiDecoderThread"), | 247 decoder_thread_("VaapiDecoderThread"), |
251 num_frames_at_client_(0), | 248 num_frames_at_client_(0), |
252 num_stream_bufs_at_decoder_(0), | 249 num_stream_bufs_at_decoder_(0), |
253 finish_flush_pending_(false), | 250 finish_flush_pending_(false), |
254 awaiting_va_surfaces_recycle_(false), | 251 awaiting_va_surfaces_recycle_(false), |
255 requested_num_pics_(0) { | 252 requested_num_pics_(0), |
| 253 weak_this_factory_(this) { |
| 254 weak_this_ = weak_this_factory_.GetWeakPtr(); |
| 255 va_surface_release_cb_ = media::BindToCurrentLoop( |
| 256 base::Bind(&VaapiVideoDecodeAccelerator::RecycleVASurfaceID, weak_this_)); |
256 } | 257 } |
257 | 258 |
258 VaapiVideoDecodeAccelerator::~VaapiVideoDecodeAccelerator() { | 259 VaapiVideoDecodeAccelerator::~VaapiVideoDecodeAccelerator() { |
259 DCHECK_EQ(message_loop_, base::MessageLoop::current()); | 260 DCHECK_EQ(message_loop_, base::MessageLoop::current()); |
260 } | 261 } |
261 | 262 |
262 class XFreeDeleter { | 263 class XFreeDeleter { |
263 public: | 264 public: |
264 void operator()(void* x) const { | 265 void operator()(void* x) const { |
265 ::XFree(x); | 266 ::XFree(x); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 new VaapiH264Decoder( | 321 new VaapiH264Decoder( |
321 vaapi_wrapper_.get(), | 322 vaapi_wrapper_.get(), |
322 media::BindToCurrentLoop(base::Bind( | 323 media::BindToCurrentLoop(base::Bind( |
323 &VaapiVideoDecodeAccelerator::SurfaceReady, weak_this_)), | 324 &VaapiVideoDecodeAccelerator::SurfaceReady, weak_this_)), |
324 base::Bind(&ReportToUMA))); | 325 base::Bind(&ReportToUMA))); |
325 | 326 |
326 CHECK(decoder_thread_.Start()); | 327 CHECK(decoder_thread_.Start()); |
327 decoder_thread_proxy_ = decoder_thread_.message_loop_proxy(); | 328 decoder_thread_proxy_ = decoder_thread_.message_loop_proxy(); |
328 | 329 |
329 state_ = kIdle; | 330 state_ = kIdle; |
330 | |
331 message_loop_->PostTask(FROM_HERE, base::Bind( | |
332 &Client::NotifyInitializeDone, client_)); | |
333 return true; | 331 return true; |
334 } | 332 } |
335 | 333 |
336 void VaapiVideoDecodeAccelerator::SurfaceReady( | 334 void VaapiVideoDecodeAccelerator::SurfaceReady( |
337 int32 input_id, | 335 int32 input_id, |
338 const scoped_refptr<VASurface>& va_surface) { | 336 const scoped_refptr<VASurface>& va_surface) { |
339 DCHECK_EQ(message_loop_, base::MessageLoop::current()); | 337 DCHECK_EQ(message_loop_, base::MessageLoop::current()); |
340 DCHECK(!awaiting_va_surfaces_recycle_); | 338 DCHECK(!awaiting_va_surfaces_recycle_); |
341 | 339 |
342 // Drop any requests to output if we are resetting or being destroyed. | 340 // 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... |
897 DCHECK_EQ(message_loop_, base::MessageLoop::current()); | 895 DCHECK_EQ(message_loop_, base::MessageLoop::current()); |
898 | 896 |
899 if (state_ == kUninitialized || state_ == kDestroying) | 897 if (state_ == kUninitialized || state_ == kDestroying) |
900 return; | 898 return; |
901 | 899 |
902 DVLOG(1) << "Destroying VAVDA"; | 900 DVLOG(1) << "Destroying VAVDA"; |
903 base::AutoLock auto_lock(lock_); | 901 base::AutoLock auto_lock(lock_); |
904 state_ = kDestroying; | 902 state_ = kDestroying; |
905 | 903 |
906 client_ptr_factory_.reset(); | 904 client_ptr_factory_.reset(); |
| 905 weak_this_factory_.InvalidateWeakPtrs(); |
907 | 906 |
908 { | 907 { |
909 base::AutoUnlock auto_unlock(lock_); | 908 base::AutoUnlock auto_unlock(lock_); |
910 // Post a dummy task to the decoder_thread_ to ensure it is drained. | 909 // Post a dummy task to the decoder_thread_ to ensure it is drained. |
911 base::WaitableEvent waiter(false, false); | 910 base::WaitableEvent waiter(false, false); |
912 decoder_thread_proxy_->PostTask(FROM_HERE, base::Bind( | 911 decoder_thread_proxy_->PostTask(FROM_HERE, base::Bind( |
913 &base::WaitableEvent::Signal, base::Unretained(&waiter))); | 912 &base::WaitableEvent::Signal, base::Unretained(&waiter))); |
914 input_ready_.Signal(); | 913 input_ready_.Signal(); |
915 surfaces_available_.Signal(); | 914 surfaces_available_.Signal(); |
916 waiter.Wait(); | 915 waiter.Wait(); |
917 decoder_thread_.Stop(); | 916 decoder_thread_.Stop(); |
918 } | 917 } |
919 | 918 |
920 state_ = kUninitialized; | 919 state_ = kUninitialized; |
921 } | 920 } |
922 | 921 |
923 void VaapiVideoDecodeAccelerator::Destroy() { | 922 void VaapiVideoDecodeAccelerator::Destroy() { |
924 DCHECK_EQ(message_loop_, base::MessageLoop::current()); | 923 DCHECK_EQ(message_loop_, base::MessageLoop::current()); |
925 Cleanup(); | 924 Cleanup(); |
926 delete this; | 925 delete this; |
927 } | 926 } |
928 | 927 |
929 } // namespace content | 928 } // namespace content |
OLD | NEW |