Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(98)

Side by Side Diff: content/common/gpu/media/vaapi_video_decode_accelerator.cc

Issue 170843004: Pass Client pointer in Initialize() for VDA/VEA (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 50e826de Rebase. Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 return; 50 return;
51 } 51 }
52 52
53 // Post Cleanup() as a task so we don't recursively acquire lock_. 53 // Post Cleanup() as a task so we don't recursively acquire lock_.
54 message_loop_->PostTask(FROM_HERE, base::Bind( 54 message_loop_->PostTask(FROM_HERE, base::Bind(
55 &VaapiVideoDecodeAccelerator::Cleanup, weak_this_)); 55 &VaapiVideoDecodeAccelerator::Cleanup, weak_this_));
56 56
57 DVLOG(1) << "Notifying of error " << error; 57 DVLOG(1) << "Notifying of error " << error;
58 if (client_) { 58 if (client_) {
59 client_->NotifyError(error); 59 client_->NotifyError(error);
60 client_ptr_factory_.InvalidateWeakPtrs(); 60 client_ptr_factory_.reset();
61 } 61 }
62 } 62 }
63 63
64 // TFPPicture allocates X Pixmaps and binds them to textures passed 64 // TFPPicture allocates X Pixmaps and binds them to textures passed
65 // in PictureBuffers from clients to them. TFPPictures are created as 65 // in PictureBuffers from clients to them. TFPPictures are created as
66 // a consequence of receiving a set of PictureBuffers from clients and released 66 // a consequence of receiving a set of PictureBuffers from clients and released
67 // at the end of decode (or when a new set of PictureBuffers is required). 67 // at the end of decode (or when a new set of PictureBuffers is required).
68 // 68 //
69 // TFPPictures are used for output, contents of VASurfaces passed from decoder 69 // TFPPictures are used for output, contents of VASurfaces passed from decoder
70 // are put into the associated pixmap memory and sent to client. 70 // are put into the associated pixmap memory and sent to client.
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 if (it == tfp_pictures_.end()) { 230 if (it == tfp_pictures_.end()) {
231 DVLOG(1) << "Picture id " << picture_buffer_id << " does not exist"; 231 DVLOG(1) << "Picture id " << picture_buffer_id << " does not exist";
232 return NULL; 232 return NULL;
233 } 233 }
234 234
235 return it->second.get(); 235 return it->second.get();
236 } 236 }
237 237
238 VaapiVideoDecodeAccelerator::VaapiVideoDecodeAccelerator( 238 VaapiVideoDecodeAccelerator::VaapiVideoDecodeAccelerator(
239 Display* x_display, 239 Display* x_display,
240 Client* client,
241 const base::Callback<bool(void)>& make_context_current) 240 const base::Callback<bool(void)>& make_context_current)
242 : x_display_(x_display), 241 : x_display_(x_display),
243 make_context_current_(make_context_current), 242 make_context_current_(make_context_current),
244 state_(kUninitialized), 243 state_(kUninitialized),
245 input_ready_(&lock_), 244 input_ready_(&lock_),
246 surfaces_available_(&lock_), 245 surfaces_available_(&lock_),
247 message_loop_(base::MessageLoop::current()), 246 message_loop_(base::MessageLoop::current()),
248 weak_this_(base::AsWeakPtr(this)), 247 weak_this_(base::AsWeakPtr(this)),
249 va_surface_release_cb_(media::BindToCurrentLoop(base::Bind( 248 va_surface_release_cb_(media::BindToCurrentLoop(base::Bind(
250 &VaapiVideoDecodeAccelerator::RecycleVASurfaceID, weak_this_))), 249 &VaapiVideoDecodeAccelerator::RecycleVASurfaceID, weak_this_))),
251 client_ptr_factory_(client),
252 client_(client_ptr_factory_.GetWeakPtr()),
253 decoder_thread_("VaapiDecoderThread"), 250 decoder_thread_("VaapiDecoderThread"),
254 num_frames_at_client_(0), 251 num_frames_at_client_(0),
255 num_stream_bufs_at_decoder_(0), 252 num_stream_bufs_at_decoder_(0),
256 finish_flush_pending_(false), 253 finish_flush_pending_(false),
257 awaiting_va_surfaces_recycle_(false), 254 awaiting_va_surfaces_recycle_(false),
258 requested_num_pics_(0) { 255 requested_num_pics_(0) {
259 DCHECK(client);
260 } 256 }
261 257
262 VaapiVideoDecodeAccelerator::~VaapiVideoDecodeAccelerator() { 258 VaapiVideoDecodeAccelerator::~VaapiVideoDecodeAccelerator() {
263 DCHECK_EQ(message_loop_, base::MessageLoop::current()); 259 DCHECK_EQ(message_loop_, base::MessageLoop::current());
264 } 260 }
265 261
266 class XFreeDeleter { 262 class XFreeDeleter {
267 public: 263 public:
268 void operator()(void* x) const { 264 void operator()(void* x) const {
269 ::XFree(x); 265 ::XFree(x);
(...skipping 15 matching lines...) Expand all
285 &num_fbconfigs)); 281 &num_fbconfigs));
286 if (!glx_fb_configs) 282 if (!glx_fb_configs)
287 return false; 283 return false;
288 if (!num_fbconfigs) 284 if (!num_fbconfigs)
289 return false; 285 return false;
290 286
291 fb_config_ = glx_fb_configs.get()[0]; 287 fb_config_ = glx_fb_configs.get()[0];
292 return true; 288 return true;
293 } 289 }
294 290
295 bool VaapiVideoDecodeAccelerator::Initialize( 291 bool VaapiVideoDecodeAccelerator::Initialize(media::VideoCodecProfile profile,
296 media::VideoCodecProfile profile) { 292 Client* client) {
297 DCHECK_EQ(message_loop_, base::MessageLoop::current()); 293 DCHECK_EQ(message_loop_, base::MessageLoop::current());
298 294
295 client_ptr_factory_.reset(new base::WeakPtrFactory<Client>(client));
296 client_ = client_ptr_factory_->GetWeakPtr();
297
299 base::AutoLock auto_lock(lock_); 298 base::AutoLock auto_lock(lock_);
300 DCHECK_EQ(state_, kUninitialized); 299 DCHECK_EQ(state_, kUninitialized);
301 DVLOG(2) << "Initializing VAVDA, profile: " << profile; 300 DVLOG(2) << "Initializing VAVDA, profile: " << profile;
302 301
303 if (!make_context_current_.Run()) 302 if (!make_context_current_.Run())
304 return false; 303 return false;
305 304
306 if (!InitializeFBConfig()) { 305 if (!InitializeFBConfig()) {
307 DVLOG(1) << "Could not get a usable FBConfig"; 306 DVLOG(1) << "Could not get a usable FBConfig";
308 return false; 307 return false;
(...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after
897 void VaapiVideoDecodeAccelerator::Cleanup() { 896 void VaapiVideoDecodeAccelerator::Cleanup() {
898 DCHECK_EQ(message_loop_, base::MessageLoop::current()); 897 DCHECK_EQ(message_loop_, base::MessageLoop::current());
899 898
900 if (state_ == kUninitialized || state_ == kDestroying) 899 if (state_ == kUninitialized || state_ == kDestroying)
901 return; 900 return;
902 901
903 DVLOG(1) << "Destroying VAVDA"; 902 DVLOG(1) << "Destroying VAVDA";
904 base::AutoLock auto_lock(lock_); 903 base::AutoLock auto_lock(lock_);
905 state_ = kDestroying; 904 state_ = kDestroying;
906 905
907 client_ptr_factory_.InvalidateWeakPtrs(); 906 client_ptr_factory_.reset();
908 907
909 { 908 {
910 base::AutoUnlock auto_unlock(lock_); 909 base::AutoUnlock auto_unlock(lock_);
911 // Post a dummy task to the decoder_thread_ to ensure it is drained. 910 // Post a dummy task to the decoder_thread_ to ensure it is drained.
912 base::WaitableEvent waiter(false, false); 911 base::WaitableEvent waiter(false, false);
913 decoder_thread_proxy_->PostTask(FROM_HERE, base::Bind( 912 decoder_thread_proxy_->PostTask(FROM_HERE, base::Bind(
914 &base::WaitableEvent::Signal, base::Unretained(&waiter))); 913 &base::WaitableEvent::Signal, base::Unretained(&waiter)));
915 input_ready_.Signal(); 914 input_ready_.Signal();
916 surfaces_available_.Signal(); 915 surfaces_available_.Signal();
917 waiter.Wait(); 916 waiter.Wait();
918 decoder_thread_.Stop(); 917 decoder_thread_.Stop();
919 } 918 }
920 919
921 state_ = kUninitialized; 920 state_ = kUninitialized;
922 } 921 }
923 922
924 void VaapiVideoDecodeAccelerator::Destroy() { 923 void VaapiVideoDecodeAccelerator::Destroy() {
925 DCHECK_EQ(message_loop_, base::MessageLoop::current()); 924 DCHECK_EQ(message_loop_, base::MessageLoop::current());
926 Cleanup(); 925 Cleanup();
927 delete this; 926 delete this;
928 } 927 }
929 928
930 } // namespace content 929 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698