| 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" |
| 11 #include "base/synchronization/waitable_event.h" | 11 #include "base/synchronization/waitable_event.h" |
| 12 #include "base/threading/non_thread_safe.h" | |
| 13 #include "content/common/gpu/gpu_channel.h" | 12 #include "content/common/gpu/gpu_channel.h" |
| 14 #include "content/common/gpu/media/vaapi_video_decode_accelerator.h" | 13 #include "content/common/gpu/media/vaapi_video_decode_accelerator.h" |
| 15 #include "media/base/bind_to_current_loop.h" | 14 #include "media/base/bind_to_current_loop.h" |
| 16 #include "media/video/picture.h" | 15 #include "media/video/picture.h" |
| 17 #include "ui/gl/gl_bindings.h" | 16 #include "ui/gl/gl_bindings.h" |
| 18 #include "ui/gl/scoped_binders.h" | |
| 19 | 17 |
| 20 static void ReportToUMA( | 18 static void ReportToUMA( |
| 21 content::VaapiH264Decoder::VAVDAH264DecoderFailure failure) { | 19 content::VaapiH264Decoder::VAVDAH264DecoderFailure failure) { |
| 22 UMA_HISTOGRAM_ENUMERATION( | 20 UMA_HISTOGRAM_ENUMERATION( |
| 23 "Media.VAVDAH264.DecoderFailure", | 21 "Media.VAVDAH264.DecoderFailure", |
| 24 failure, | 22 failure, |
| 25 content::VaapiH264Decoder::VAVDA_H264_DECODER_FAILURES_MAX); | 23 content::VaapiH264Decoder::VAVDA_H264_DECODER_FAILURES_MAX); |
| 26 } | 24 } |
| 27 | 25 |
| 28 namespace content { | 26 namespace content { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 54 message_loop_->PostTask(FROM_HERE, base::Bind( | 52 message_loop_->PostTask(FROM_HERE, base::Bind( |
| 55 &VaapiVideoDecodeAccelerator::Cleanup, weak_this_)); | 53 &VaapiVideoDecodeAccelerator::Cleanup, weak_this_)); |
| 56 | 54 |
| 57 DVLOG(1) << "Notifying of error " << error; | 55 DVLOG(1) << "Notifying of error " << error; |
| 58 if (client_) { | 56 if (client_) { |
| 59 client_->NotifyError(error); | 57 client_->NotifyError(error); |
| 60 client_ptr_factory_.reset(); | 58 client_ptr_factory_.reset(); |
| 61 } | 59 } |
| 62 } | 60 } |
| 63 | 61 |
| 64 // TFPPicture allocates X Pixmaps and binds them to textures passed | 62 VaapiWrapper::Picture* VaapiVideoDecodeAccelerator::PictureById( |
| 65 // in PictureBuffers from clients to them. TFPPictures are created as | 63 int32 picture_buffer_id) { |
| 66 // a consequence of receiving a set of PictureBuffers from clients and released | 64 Pictures::iterator it = pictures_.find(picture_buffer_id); |
| 67 // at the end of decode (or when a new set of PictureBuffers is required). | 65 if (it == pictures_.end()) { |
| 68 // | |
| 69 // TFPPictures are used for output, contents of VASurfaces passed from decoder | |
| 70 // are put into the associated pixmap memory and sent to client. | |
| 71 class VaapiVideoDecodeAccelerator::TFPPicture : public base::NonThreadSafe { | |
| 72 public: | |
| 73 ~TFPPicture(); | |
| 74 | |
| 75 static linked_ptr<TFPPicture> Create( | |
| 76 const base::Callback<bool(void)>& make_context_current, | |
| 77 const GLXFBConfig& fb_config, | |
| 78 Display* x_display, | |
| 79 int32 picture_buffer_id, | |
| 80 uint32 texture_id, | |
| 81 gfx::Size size); | |
| 82 | |
| 83 int32 picture_buffer_id() { | |
| 84 return picture_buffer_id_; | |
| 85 } | |
| 86 | |
| 87 gfx::Size size() { | |
| 88 return size_; | |
| 89 } | |
| 90 | |
| 91 int x_pixmap() { | |
| 92 return x_pixmap_; | |
| 93 } | |
| 94 | |
| 95 // Bind texture to pixmap. Needs to be called every frame. | |
| 96 bool Bind(); | |
| 97 | |
| 98 private: | |
| 99 TFPPicture(const base::Callback<bool(void)>& make_context_current, | |
| 100 Display* x_display, | |
| 101 int32 picture_buffer_id, | |
| 102 uint32 texture_id, | |
| 103 gfx::Size size); | |
| 104 | |
| 105 bool Initialize(const GLXFBConfig& fb_config); | |
| 106 | |
| 107 base::Callback<bool(void)> make_context_current_; | |
| 108 | |
| 109 Display* x_display_; | |
| 110 | |
| 111 // Output id for the client. | |
| 112 int32 picture_buffer_id_; | |
| 113 uint32 texture_id_; | |
| 114 | |
| 115 gfx::Size size_; | |
| 116 | |
| 117 // Pixmaps bound to this texture. | |
| 118 Pixmap x_pixmap_; | |
| 119 GLXPixmap glx_pixmap_; | |
| 120 | |
| 121 DISALLOW_COPY_AND_ASSIGN(TFPPicture); | |
| 122 }; | |
| 123 | |
| 124 VaapiVideoDecodeAccelerator::TFPPicture::TFPPicture( | |
| 125 const base::Callback<bool(void)>& make_context_current, | |
| 126 Display* x_display, | |
| 127 int32 picture_buffer_id, | |
| 128 uint32 texture_id, | |
| 129 gfx::Size size) | |
| 130 : make_context_current_(make_context_current), | |
| 131 x_display_(x_display), | |
| 132 picture_buffer_id_(picture_buffer_id), | |
| 133 texture_id_(texture_id), | |
| 134 size_(size), | |
| 135 x_pixmap_(0), | |
| 136 glx_pixmap_(0) { | |
| 137 DCHECK(!make_context_current_.is_null()); | |
| 138 }; | |
| 139 | |
| 140 linked_ptr<VaapiVideoDecodeAccelerator::TFPPicture> | |
| 141 VaapiVideoDecodeAccelerator::TFPPicture::Create( | |
| 142 const base::Callback<bool(void)>& make_context_current, | |
| 143 const GLXFBConfig& fb_config, | |
| 144 Display* x_display, | |
| 145 int32 picture_buffer_id, | |
| 146 uint32 texture_id, | |
| 147 gfx::Size size) { | |
| 148 | |
| 149 linked_ptr<TFPPicture> tfp_picture( | |
| 150 new TFPPicture(make_context_current, x_display, picture_buffer_id, | |
| 151 texture_id, size)); | |
| 152 | |
| 153 if (!tfp_picture->Initialize(fb_config)) | |
| 154 tfp_picture.reset(); | |
| 155 | |
| 156 return tfp_picture; | |
| 157 } | |
| 158 | |
| 159 bool VaapiVideoDecodeAccelerator::TFPPicture::Initialize( | |
| 160 const GLXFBConfig& fb_config) { | |
| 161 DCHECK(CalledOnValidThread()); | |
| 162 if (!make_context_current_.Run()) | |
| 163 return false; | |
| 164 | |
| 165 XWindowAttributes win_attr; | |
| 166 int screen = DefaultScreen(x_display_); | |
| 167 XGetWindowAttributes(x_display_, RootWindow(x_display_, screen), &win_attr); | |
| 168 //TODO(posciak): pass the depth required by libva, not the RootWindow's depth | |
| 169 x_pixmap_ = XCreatePixmap(x_display_, RootWindow(x_display_, screen), | |
| 170 size_.width(), size_.height(), win_attr.depth); | |
| 171 if (!x_pixmap_) { | |
| 172 DVLOG(1) << "Failed creating an X Pixmap for TFP"; | |
| 173 return false; | |
| 174 } | |
| 175 | |
| 176 static const int pixmap_attr[] = { | |
| 177 GLX_TEXTURE_TARGET_EXT, GLX_TEXTURE_2D_EXT, | |
| 178 GLX_TEXTURE_FORMAT_EXT, GLX_TEXTURE_FORMAT_RGB_EXT, | |
| 179 GL_NONE, | |
| 180 }; | |
| 181 | |
| 182 glx_pixmap_ = glXCreatePixmap(x_display_, fb_config, x_pixmap_, pixmap_attr); | |
| 183 if (!glx_pixmap_) { | |
| 184 // x_pixmap_ will be freed in the destructor. | |
| 185 DVLOG(1) << "Failed creating a GLX Pixmap for TFP"; | |
| 186 return false; | |
| 187 } | |
| 188 | |
| 189 return true; | |
| 190 } | |
| 191 | |
| 192 VaapiVideoDecodeAccelerator::TFPPicture::~TFPPicture() { | |
| 193 DCHECK(CalledOnValidThread()); | |
| 194 // Unbind surface from texture and deallocate resources. | |
| 195 if (glx_pixmap_ && make_context_current_.Run()) { | |
| 196 glXReleaseTexImageEXT(x_display_, glx_pixmap_, GLX_FRONT_LEFT_EXT); | |
| 197 glXDestroyPixmap(x_display_, glx_pixmap_); | |
| 198 } | |
| 199 | |
| 200 if (x_pixmap_) | |
| 201 XFreePixmap(x_display_, x_pixmap_); | |
| 202 XSync(x_display_, False); // Needed to work around buggy vdpau-driver. | |
| 203 } | |
| 204 | |
| 205 bool VaapiVideoDecodeAccelerator::TFPPicture::Bind() { | |
| 206 DCHECK(CalledOnValidThread()); | |
| 207 DCHECK(x_pixmap_); | |
| 208 DCHECK(glx_pixmap_); | |
| 209 if (!make_context_current_.Run()) | |
| 210 return false; | |
| 211 | |
| 212 gfx::ScopedTextureBinder texture_binder(GL_TEXTURE_2D, texture_id_); | |
| 213 glXBindTexImageEXT(x_display_, glx_pixmap_, GLX_FRONT_LEFT_EXT, NULL); | |
| 214 | |
| 215 return true; | |
| 216 } | |
| 217 | |
| 218 VaapiVideoDecodeAccelerator::TFPPicture* | |
| 219 VaapiVideoDecodeAccelerator::TFPPictureById(int32 picture_buffer_id) { | |
| 220 TFPPictures::iterator it = tfp_pictures_.find(picture_buffer_id); | |
| 221 if (it == tfp_pictures_.end()) { | |
| 222 DVLOG(1) << "Picture id " << picture_buffer_id << " does not exist"; | 66 DVLOG(1) << "Picture id " << picture_buffer_id << " does not exist"; |
| 223 return NULL; | 67 return NULL; |
| 224 } | 68 } |
| 225 | 69 |
| 226 return it->second.get(); | 70 return it->second.get(); |
| 227 } | 71 } |
| 228 | 72 |
| 229 VaapiVideoDecodeAccelerator::VaapiVideoDecodeAccelerator( | 73 VaapiVideoDecodeAccelerator::VaapiVideoDecodeAccelerator( |
| 230 Display* x_display, | 74 gfx::GLContext* gl_context, |
| 231 const base::Callback<bool(void)>& make_context_current) | 75 const base::Callback<bool(void)>& make_context_current) |
| 232 : x_display_(x_display), | 76 : gl_context_(gl_context), // x_display_(x_display), |
| 233 make_context_current_(make_context_current), | 77 make_context_current_(make_context_current), |
| 234 state_(kUninitialized), | 78 state_(kUninitialized), |
| 235 input_ready_(&lock_), | 79 input_ready_(&lock_), |
| 236 surfaces_available_(&lock_), | 80 surfaces_available_(&lock_), |
| 237 message_loop_(base::MessageLoop::current()), | 81 message_loop_(base::MessageLoop::current()), |
| 238 decoder_thread_("VaapiDecoderThread"), | 82 decoder_thread_("VaapiDecoderThread"), |
| 239 num_frames_at_client_(0), | 83 num_frames_at_client_(0), |
| 240 num_stream_bufs_at_decoder_(0), | 84 num_stream_bufs_at_decoder_(0), |
| 241 finish_flush_pending_(false), | 85 finish_flush_pending_(false), |
| 242 awaiting_va_surfaces_recycle_(false), | 86 awaiting_va_surfaces_recycle_(false), |
| 243 requested_num_pics_(0), | 87 requested_num_pics_(0), |
| 244 weak_this_factory_(this) { | 88 weak_this_factory_(this) { |
| 245 weak_this_ = weak_this_factory_.GetWeakPtr(); | 89 weak_this_ = weak_this_factory_.GetWeakPtr(); |
| 246 va_surface_release_cb_ = media::BindToCurrentLoop( | 90 va_surface_release_cb_ = media::BindToCurrentLoop( |
| 247 base::Bind(&VaapiVideoDecodeAccelerator::RecycleVASurfaceID, weak_this_)); | 91 base::Bind(&VaapiVideoDecodeAccelerator::RecycleVASurfaceID, weak_this_)); |
| 248 } | 92 } |
| 249 | 93 |
| 250 VaapiVideoDecodeAccelerator::~VaapiVideoDecodeAccelerator() { | 94 VaapiVideoDecodeAccelerator::~VaapiVideoDecodeAccelerator() { |
| 251 DCHECK_EQ(message_loop_, base::MessageLoop::current()); | 95 DCHECK_EQ(message_loop_, base::MessageLoop::current()); |
| 252 } | 96 } |
| 253 | 97 |
| 254 class XFreeDeleter { | |
| 255 public: | |
| 256 void operator()(void* x) const { | |
| 257 ::XFree(x); | |
| 258 } | |
| 259 }; | |
| 260 | |
| 261 bool VaapiVideoDecodeAccelerator::InitializeFBConfig() { | |
| 262 const int fbconfig_attr[] = { | |
| 263 GLX_DRAWABLE_TYPE, GLX_PIXMAP_BIT, | |
| 264 GLX_BIND_TO_TEXTURE_TARGETS_EXT, GLX_TEXTURE_2D_BIT_EXT, | |
| 265 GLX_BIND_TO_TEXTURE_RGB_EXT, GL_TRUE, | |
| 266 GLX_Y_INVERTED_EXT, GL_TRUE, | |
| 267 GL_NONE, | |
| 268 }; | |
| 269 | |
| 270 int num_fbconfigs; | |
| 271 scoped_ptr<GLXFBConfig, XFreeDeleter> glx_fb_configs( | |
| 272 glXChooseFBConfig(x_display_, DefaultScreen(x_display_), fbconfig_attr, | |
| 273 &num_fbconfigs)); | |
| 274 if (!glx_fb_configs) | |
| 275 return false; | |
| 276 if (!num_fbconfigs) | |
| 277 return false; | |
| 278 | |
| 279 fb_config_ = glx_fb_configs.get()[0]; | |
| 280 return true; | |
| 281 } | |
| 282 | |
| 283 bool VaapiVideoDecodeAccelerator::Initialize(media::VideoCodecProfile profile, | 98 bool VaapiVideoDecodeAccelerator::Initialize(media::VideoCodecProfile profile, |
| 284 Client* client) { | 99 Client* client) { |
| 285 DCHECK_EQ(message_loop_, base::MessageLoop::current()); | 100 DCHECK_EQ(message_loop_, base::MessageLoop::current()); |
| 286 | 101 |
| 287 client_ptr_factory_.reset(new base::WeakPtrFactory<Client>(client)); | 102 client_ptr_factory_.reset(new base::WeakPtrFactory<Client>(client)); |
| 288 client_ = client_ptr_factory_->GetWeakPtr(); | 103 client_ = client_ptr_factory_->GetWeakPtr(); |
| 289 | 104 |
| 290 base::AutoLock auto_lock(lock_); | 105 base::AutoLock auto_lock(lock_); |
| 291 DCHECK_EQ(state_, kUninitialized); | 106 DCHECK_EQ(state_, kUninitialized); |
| 292 DVLOG(2) << "Initializing VAVDA, profile: " << profile; | 107 DVLOG(2) << "Initializing VAVDA, profile: " << profile; |
| 293 | 108 |
| 294 if (!make_context_current_.Run()) | |
| 295 return false; | |
| 296 | |
| 297 if (!InitializeFBConfig()) { | |
| 298 DVLOG(1) << "Could not get a usable FBConfig"; | |
| 299 return false; | |
| 300 } | |
| 301 | |
| 302 vaapi_wrapper_ = VaapiWrapper::Create( | 109 vaapi_wrapper_ = VaapiWrapper::Create( |
| 303 VaapiWrapper::kDecode, | 110 VaapiWrapper::kDecode, |
| 304 profile, | 111 profile, |
| 305 x_display_, | 112 gl_context_, |
| 113 make_context_current_, |
| 306 base::Bind(&ReportToUMA, content::VaapiH264Decoder::VAAPI_ERROR)); | 114 base::Bind(&ReportToUMA, content::VaapiH264Decoder::VAAPI_ERROR)); |
| 307 | 115 |
| 308 if (!vaapi_wrapper_.get()) { | 116 if (!vaapi_wrapper_.get()) { |
| 309 DVLOG(1) << "Failed initializing VAAPI"; | 117 DVLOG(1) << "Failed initializing VAAPI"; |
| 310 return false; | 118 return false; |
| 311 } | 119 } |
| 312 | 120 |
| 313 decoder_.reset( | 121 decoder_.reset( |
| 314 new VaapiH264Decoder( | 122 new VaapiH264Decoder( |
| 315 vaapi_wrapper_.get(), | 123 vaapi_wrapper_.get(), |
| (...skipping 21 matching lines...) Expand all Loading... |
| 337 pending_output_cbs_.push( | 145 pending_output_cbs_.push( |
| 338 base::Bind(&VaapiVideoDecodeAccelerator::OutputPicture, | 146 base::Bind(&VaapiVideoDecodeAccelerator::OutputPicture, |
| 339 weak_this_, va_surface, input_id)); | 147 weak_this_, va_surface, input_id)); |
| 340 | 148 |
| 341 TryOutputSurface(); | 149 TryOutputSurface(); |
| 342 } | 150 } |
| 343 | 151 |
| 344 void VaapiVideoDecodeAccelerator::OutputPicture( | 152 void VaapiVideoDecodeAccelerator::OutputPicture( |
| 345 const scoped_refptr<VASurface>& va_surface, | 153 const scoped_refptr<VASurface>& va_surface, |
| 346 int32 input_id, | 154 int32 input_id, |
| 347 TFPPicture* tfp_picture) { | 155 VaapiWrapper::Picture* picture) { |
| 348 DCHECK_EQ(message_loop_, base::MessageLoop::current()); | 156 DCHECK_EQ(message_loop_, base::MessageLoop::current()); |
| 349 | 157 |
| 350 int32 output_id = tfp_picture->picture_buffer_id(); | 158 int32 output_id = picture->picture_buffer_id(); |
| 351 | 159 |
| 352 TRACE_EVENT2("Video Decoder", "VAVDA::OutputSurface", | 160 TRACE_EVENT2("Video Decoder", "VAVDA::OutputSurface", |
| 353 "input_id", input_id, | 161 "input_id", input_id, |
| 354 "output_id", output_id); | 162 "output_id", output_id); |
| 355 | 163 |
| 356 DVLOG(3) << "Outputting VASurface " << va_surface->id() | 164 DVLOG(3) << "Outputting VASurface " << va_surface->id() |
| 357 << " into pixmap bound to picture buffer id " << output_id; | 165 << " into pixmap bound to picture buffer id " << output_id; |
| 358 | 166 |
| 359 RETURN_AND_NOTIFY_ON_FAILURE(tfp_picture->Bind(), | 167 // RETURN_AND_NOTIFY_ON_FAILURE(picture->Bind(), |
| 360 "Failed binding texture to pixmap", | 168 // "Failed binding texture to pixmap", |
| 361 PLATFORM_FAILURE, ); | 169 // PLATFORM_FAILURE, ); |
| 362 | 170 |
| 363 RETURN_AND_NOTIFY_ON_FAILURE( | 171 RETURN_AND_NOTIFY_ON_FAILURE( |
| 364 vaapi_wrapper_->PutSurfaceIntoPixmap(va_surface->id(), | 172 vaapi_wrapper_->PutSurfaceIntoPicture(va_surface->id(), picture), |
| 365 tfp_picture->x_pixmap(), | 173 // tfp_picture->x_pixmap(), |
| 366 tfp_picture->size()), | 174 // tfp_picture->size()), |
| 367 "Failed putting surface into pixmap", PLATFORM_FAILURE, ); | 175 "Failed putting surface into pixmap", |
| 176 PLATFORM_FAILURE, ); |
| 368 | 177 |
| 369 // Notify the client a picture is ready to be displayed. | 178 // Notify the client a picture is ready to be displayed. |
| 370 ++num_frames_at_client_; | 179 ++num_frames_at_client_; |
| 371 TRACE_COUNTER1("Video Decoder", "Textures at client", num_frames_at_client_); | 180 TRACE_COUNTER1("Video Decoder", "Textures at client", num_frames_at_client_); |
| 372 DVLOG(4) << "Notifying output picture id " << output_id | 181 DVLOG(4) << "Notifying output picture id " << output_id |
| 373 << " for input "<< input_id << " is ready"; | 182 << " for input "<< input_id << " is ready"; |
| 374 if (client_) | 183 if (client_) |
| 375 client_->PictureReady(media::Picture(output_id, input_id)); | 184 client_->PictureReady(media::Picture(output_id, input_id)); |
| 376 } | 185 } |
| 377 | 186 |
| 378 void VaapiVideoDecodeAccelerator::TryOutputSurface() { | 187 void VaapiVideoDecodeAccelerator::TryOutputSurface() { |
| 379 DCHECK_EQ(message_loop_, base::MessageLoop::current()); | 188 DCHECK_EQ(message_loop_, base::MessageLoop::current()); |
| 380 | 189 |
| 381 // Handle Destroy() arriving while pictures are queued for output. | 190 // Handle Destroy() arriving while pictures are queued for output. |
| 382 if (!client_) | 191 if (!client_) |
| 383 return; | 192 return; |
| 384 | 193 |
| 385 if (pending_output_cbs_.empty() || output_buffers_.empty()) | 194 if (pending_output_cbs_.empty() || output_buffers_.empty()) |
| 386 return; | 195 return; |
| 387 | 196 |
| 388 OutputCB output_cb = pending_output_cbs_.front(); | 197 OutputCB output_cb = pending_output_cbs_.front(); |
| 389 pending_output_cbs_.pop(); | 198 pending_output_cbs_.pop(); |
| 390 | 199 |
| 391 TFPPicture* tfp_picture = TFPPictureById(output_buffers_.front()); | 200 VaapiWrapper::Picture* picture = PictureById(output_buffers_.front()); |
| 392 DCHECK(tfp_picture); | 201 DCHECK(picture); |
| 393 output_buffers_.pop(); | 202 output_buffers_.pop(); |
| 394 | 203 |
| 395 output_cb.Run(tfp_picture); | 204 output_cb.Run(picture); |
| 396 | 205 |
| 397 if (finish_flush_pending_ && pending_output_cbs_.empty()) | 206 if (finish_flush_pending_ && pending_output_cbs_.empty()) |
| 398 FinishFlush(); | 207 FinishFlush(); |
| 399 } | 208 } |
| 400 | 209 |
| 401 void VaapiVideoDecodeAccelerator::MapAndQueueNewInputBuffer( | 210 void VaapiVideoDecodeAccelerator::MapAndQueueNewInputBuffer( |
| 402 const media::BitstreamBuffer& bitstream_buffer) { | 211 const media::BitstreamBuffer& bitstream_buffer) { |
| 403 DCHECK_EQ(message_loop_, base::MessageLoop::current()); | 212 DCHECK_EQ(message_loop_, base::MessageLoop::current()); |
| 404 TRACE_EVENT1("Video Decoder", "MapAndQueueNewInputBuffer", "input_id", | 213 TRACE_EVENT1("Video Decoder", "MapAndQueueNewInputBuffer", "input_id", |
| 405 bitstream_buffer.id()); | 214 bitstream_buffer.id()); |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 588 TryFinishSurfaceSetChange(); | 397 TryFinishSurfaceSetChange(); |
| 589 } | 398 } |
| 590 | 399 |
| 591 void VaapiVideoDecodeAccelerator::TryFinishSurfaceSetChange() { | 400 void VaapiVideoDecodeAccelerator::TryFinishSurfaceSetChange() { |
| 592 DCHECK_EQ(message_loop_, base::MessageLoop::current()); | 401 DCHECK_EQ(message_loop_, base::MessageLoop::current()); |
| 593 | 402 |
| 594 if (!awaiting_va_surfaces_recycle_) | 403 if (!awaiting_va_surfaces_recycle_) |
| 595 return; | 404 return; |
| 596 | 405 |
| 597 if (!pending_output_cbs_.empty() || | 406 if (!pending_output_cbs_.empty() || |
| 598 tfp_pictures_.size() != available_va_surfaces_.size()) { | 407 pictures_.size() != available_va_surfaces_.size()) { |
| 599 // Either: | 408 // Either: |
| 600 // 1. Not all pending pending output callbacks have been executed yet. | 409 // 1. Not all pending pending output callbacks have been executed yet. |
| 601 // Wait for the client to return enough pictures and retry later. | 410 // Wait for the client to return enough pictures and retry later. |
| 602 // 2. The above happened and all surface release callbacks have been posted | 411 // 2. The above happened and all surface release callbacks have been posted |
| 603 // as the result, but not all have executed yet. Post ourselves after them | 412 // as the result, but not all have executed yet. Post ourselves after them |
| 604 // to let them release surfaces. | 413 // to let them release surfaces. |
| 605 DVLOG(2) << "Awaiting pending output/surface release callbacks to finish"; | 414 DVLOG(2) << "Awaiting pending output/surface release callbacks to finish"; |
| 606 message_loop_->PostTask(FROM_HERE, base::Bind( | 415 message_loop_->PostTask(FROM_HERE, base::Bind( |
| 607 &VaapiVideoDecodeAccelerator::TryFinishSurfaceSetChange, weak_this_)); | 416 &VaapiVideoDecodeAccelerator::TryFinishSurfaceSetChange, weak_this_)); |
| 608 return; | 417 return; |
| 609 } | 418 } |
| 610 | 419 |
| 611 // All surfaces released, destroy them and dismiss all PictureBuffers. | 420 // All surfaces released, destroy them and dismiss all PictureBuffers. |
| 612 awaiting_va_surfaces_recycle_ = false; | 421 awaiting_va_surfaces_recycle_ = false; |
| 613 available_va_surfaces_.clear(); | 422 available_va_surfaces_.clear(); |
| 614 vaapi_wrapper_->DestroySurfaces(); | 423 vaapi_wrapper_->DestroySurfaces(); |
| 615 | 424 |
| 616 for (TFPPictures::iterator iter = tfp_pictures_.begin(); | 425 for (Pictures::iterator iter = pictures_.begin(); iter != pictures_.end(); |
| 617 iter != tfp_pictures_.end(); ++iter) { | 426 ++iter) { |
| 618 DVLOG(2) << "Dismissing picture id: " << iter->first; | 427 DVLOG(2) << "Dismissing picture id: " << iter->first; |
| 619 if (client_) | 428 if (client_) |
| 620 client_->DismissPictureBuffer(iter->first); | 429 client_->DismissPictureBuffer(iter->first); |
| 621 } | 430 } |
| 622 tfp_pictures_.clear(); | 431 pictures_.clear(); |
| 623 | 432 |
| 624 // And ask for a new set as requested. | 433 // And ask for a new set as requested. |
| 625 DVLOG(1) << "Requesting " << requested_num_pics_ << " pictures of size: " | 434 DVLOG(1) << "Requesting " << requested_num_pics_ << " pictures of size: " |
| 626 << requested_pic_size_.ToString(); | 435 << requested_pic_size_.ToString(); |
| 627 | 436 |
| 628 message_loop_->PostTask(FROM_HERE, base::Bind( | 437 message_loop_->PostTask(FROM_HERE, base::Bind( |
| 629 &Client::ProvidePictureBuffers, client_, | 438 &Client::ProvidePictureBuffers, client_, |
| 630 requested_num_pics_, requested_pic_size_, GL_TEXTURE_2D)); | 439 requested_num_pics_, requested_pic_size_, GL_TEXTURE_2D)); |
| 631 } | 440 } |
| 632 | 441 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 672 | 481 |
| 673 available_va_surfaces_.push_back(va_surface_id); | 482 available_va_surfaces_.push_back(va_surface_id); |
| 674 surfaces_available_.Signal(); | 483 surfaces_available_.Signal(); |
| 675 } | 484 } |
| 676 | 485 |
| 677 void VaapiVideoDecodeAccelerator::AssignPictureBuffers( | 486 void VaapiVideoDecodeAccelerator::AssignPictureBuffers( |
| 678 const std::vector<media::PictureBuffer>& buffers) { | 487 const std::vector<media::PictureBuffer>& buffers) { |
| 679 DCHECK_EQ(message_loop_, base::MessageLoop::current()); | 488 DCHECK_EQ(message_loop_, base::MessageLoop::current()); |
| 680 | 489 |
| 681 base::AutoLock auto_lock(lock_); | 490 base::AutoLock auto_lock(lock_); |
| 682 DCHECK(tfp_pictures_.empty()); | 491 DCHECK(pictures_.empty()); |
| 683 | 492 |
| 684 while (!output_buffers_.empty()) | 493 while (!output_buffers_.empty()) |
| 685 output_buffers_.pop(); | 494 output_buffers_.pop(); |
| 686 | 495 |
| 687 RETURN_AND_NOTIFY_ON_FAILURE( | 496 RETURN_AND_NOTIFY_ON_FAILURE( |
| 688 buffers.size() == requested_num_pics_, | 497 buffers.size() == requested_num_pics_, |
| 689 "Got an invalid number of picture buffers. (Got " << buffers.size() | 498 "Got an invalid number of picture buffers. (Got " << buffers.size() |
| 690 << ", requested " << requested_num_pics_ << ")", INVALID_ARGUMENT, ); | 499 << ", requested " << requested_num_pics_ << ")", INVALID_ARGUMENT, ); |
| 691 DCHECK(requested_pic_size_ == buffers[0].size()); | 500 DCHECK(requested_pic_size_ == buffers[0].size()); |
| 692 | 501 |
| 693 std::vector<VASurfaceID> va_surface_ids; | 502 std::vector<VASurfaceID> va_surface_ids; |
| 694 RETURN_AND_NOTIFY_ON_FAILURE( | 503 RETURN_AND_NOTIFY_ON_FAILURE( |
| 695 vaapi_wrapper_->CreateSurfaces(requested_pic_size_, | 504 vaapi_wrapper_->CreateSurfaces(requested_pic_size_, |
| 696 buffers.size(), | 505 buffers.size(), |
| 697 &va_surface_ids), | 506 &va_surface_ids), |
| 698 "Failed creating VA Surfaces", PLATFORM_FAILURE, ); | 507 "Failed creating VA Surfaces", PLATFORM_FAILURE, ); |
| 699 DCHECK_EQ(va_surface_ids.size(), buffers.size()); | 508 DCHECK_EQ(va_surface_ids.size(), buffers.size()); |
| 700 | 509 |
| 701 for (size_t i = 0; i < buffers.size(); ++i) { | 510 for (size_t i = 0; i < buffers.size(); ++i) { |
| 702 DVLOG(2) << "Assigning picture id: " << buffers[i].id() | 511 DVLOG(2) << "Assigning picture id: " << buffers[i].id() |
| 703 << " to texture id: " << buffers[i].texture_id() | 512 << " to texture id: " << buffers[i].texture_id() |
| 704 << " VASurfaceID: " << va_surface_ids[i]; | 513 << " VASurfaceID: " << va_surface_ids[i]; |
| 705 | 514 |
| 706 linked_ptr<TFPPicture> tfp_picture( | 515 linked_ptr<VaapiWrapper::Picture> picture(vaapi_wrapper_->CreatePicture( |
| 707 TFPPicture::Create(make_context_current_, fb_config_, x_display_, | 516 buffers[i].id(), buffers[i].texture_id(), requested_pic_size_)); |
| 708 buffers[i].id(), buffers[i].texture_id(), | |
| 709 requested_pic_size_)); | |
| 710 | 517 |
| 711 RETURN_AND_NOTIFY_ON_FAILURE( | 518 RETURN_AND_NOTIFY_ON_FAILURE( |
| 712 tfp_picture.get(), "Failed assigning picture buffer to a texture.", | 519 picture.get(), |
| 520 "Failed assigning picture buffer to a texture.", |
| 713 PLATFORM_FAILURE, ); | 521 PLATFORM_FAILURE, ); |
| 714 | 522 |
| 715 bool inserted = tfp_pictures_.insert(std::make_pair( | 523 bool inserted = |
| 716 buffers[i].id(), tfp_picture)).second; | 524 pictures_.insert(std::make_pair(buffers[i].id(), picture)).second; |
| 717 DCHECK(inserted); | 525 DCHECK(inserted); |
| 718 | 526 |
| 719 output_buffers_.push(buffers[i].id()); | 527 output_buffers_.push(buffers[i].id()); |
| 720 available_va_surfaces_.push_back(va_surface_ids[i]); | 528 available_va_surfaces_.push_back(va_surface_ids[i]); |
| 721 surfaces_available_.Signal(); | 529 surfaces_available_.Signal(); |
| 722 } | 530 } |
| 723 | 531 |
| 724 state_ = kDecoding; | 532 state_ = kDecoding; |
| 725 decoder_thread_proxy_->PostTask(FROM_HERE, base::Bind( | 533 decoder_thread_proxy_->PostTask(FROM_HERE, base::Bind( |
| 726 &VaapiVideoDecodeAccelerator::DecodeTask, base::Unretained(this))); | 534 &VaapiVideoDecodeAccelerator::DecodeTask, base::Unretained(this))); |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 914 DCHECK_EQ(message_loop_, base::MessageLoop::current()); | 722 DCHECK_EQ(message_loop_, base::MessageLoop::current()); |
| 915 Cleanup(); | 723 Cleanup(); |
| 916 delete this; | 724 delete this; |
| 917 } | 725 } |
| 918 | 726 |
| 919 bool VaapiVideoDecodeAccelerator::CanDecodeOnIOThread() { | 727 bool VaapiVideoDecodeAccelerator::CanDecodeOnIOThread() { |
| 920 return false; | 728 return false; |
| 921 } | 729 } |
| 922 | 730 |
| 923 } // namespace content | 731 } // namespace content |
| OLD | NEW |