| 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 12 matching lines...) Expand all Loading... |
| 23 "Media.VAVDAH264.DecoderFailure", | 23 "Media.VAVDAH264.DecoderFailure", |
| 24 failure, | 24 failure, |
| 25 content::VaapiH264Decoder::VAVDA_H264_DECODER_FAILURES_MAX); | 25 content::VaapiH264Decoder::VAVDA_H264_DECODER_FAILURES_MAX); |
| 26 } | 26 } |
| 27 | 27 |
| 28 namespace content { | 28 namespace content { |
| 29 | 29 |
| 30 #define RETURN_AND_NOTIFY_ON_FAILURE(result, log, error_code, ret) \ | 30 #define RETURN_AND_NOTIFY_ON_FAILURE(result, log, error_code, ret) \ |
| 31 do { \ | 31 do { \ |
| 32 if (!(result)) { \ | 32 if (!(result)) { \ |
| 33 DVLOG(1) << log; \ | 33 LOG(ERROR) << log; \ |
| 34 NotifyError(error_code); \ | 34 NotifyError(error_code); \ |
| 35 return ret; \ | 35 return ret; \ |
| 36 } \ | 36 } \ |
| 37 } while (0) | 37 } while (0) |
| 38 | 38 |
| 39 VaapiVideoDecodeAccelerator::InputBuffer::InputBuffer() : id(0), size(0) { | 39 VaapiVideoDecodeAccelerator::InputBuffer::InputBuffer() : id(0), size(0) { |
| 40 } | 40 } |
| 41 | 41 |
| 42 VaapiVideoDecodeAccelerator::InputBuffer::~InputBuffer() { | 42 VaapiVideoDecodeAccelerator::InputBuffer::~InputBuffer() { |
| 43 } | 43 } |
| 44 | 44 |
| 45 void VaapiVideoDecodeAccelerator::NotifyError(Error error) { | 45 void VaapiVideoDecodeAccelerator::NotifyError(Error error) { |
| 46 if (message_loop_ != base::MessageLoop::current()) { | 46 if (message_loop_ != base::MessageLoop::current()) { |
| 47 DCHECK(decoder_thread_proxy_->BelongsToCurrentThread()); | 47 DCHECK(decoder_thread_proxy_->BelongsToCurrentThread()); |
| 48 message_loop_->PostTask(FROM_HERE, base::Bind( | 48 message_loop_->PostTask(FROM_HERE, base::Bind( |
| 49 &VaapiVideoDecodeAccelerator::NotifyError, weak_this_, error)); | 49 &VaapiVideoDecodeAccelerator::NotifyError, weak_this_, error)); |
| 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 LOG(ERROR) << "Notifying of error " << error; |
| 58 if (client_) { | 58 if (client_) { |
| 59 client_->NotifyError(error); | 59 client_->NotifyError(error); |
| 60 client_ptr_factory_.reset(); | 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). |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 if (!make_context_current_.Run()) | 162 if (!make_context_current_.Run()) |
| 163 return false; | 163 return false; |
| 164 | 164 |
| 165 XWindowAttributes win_attr; | 165 XWindowAttributes win_attr; |
| 166 int screen = DefaultScreen(x_display_); | 166 int screen = DefaultScreen(x_display_); |
| 167 XGetWindowAttributes(x_display_, RootWindow(x_display_, screen), &win_attr); | 167 XGetWindowAttributes(x_display_, RootWindow(x_display_, screen), &win_attr); |
| 168 //TODO(posciak): pass the depth required by libva, not the RootWindow's depth | 168 //TODO(posciak): pass the depth required by libva, not the RootWindow's depth |
| 169 x_pixmap_ = XCreatePixmap(x_display_, RootWindow(x_display_, screen), | 169 x_pixmap_ = XCreatePixmap(x_display_, RootWindow(x_display_, screen), |
| 170 size_.width(), size_.height(), win_attr.depth); | 170 size_.width(), size_.height(), win_attr.depth); |
| 171 if (!x_pixmap_) { | 171 if (!x_pixmap_) { |
| 172 DVLOG(1) << "Failed creating an X Pixmap for TFP"; | 172 LOG(ERROR) << "Failed creating an X Pixmap for TFP"; |
| 173 return false; | 173 return false; |
| 174 } | 174 } |
| 175 | 175 |
| 176 static const int pixmap_attr[] = { | 176 static const int pixmap_attr[] = { |
| 177 GLX_TEXTURE_TARGET_EXT, GLX_TEXTURE_2D_EXT, | 177 GLX_TEXTURE_TARGET_EXT, GLX_TEXTURE_2D_EXT, |
| 178 GLX_TEXTURE_FORMAT_EXT, GLX_TEXTURE_FORMAT_RGB_EXT, | 178 GLX_TEXTURE_FORMAT_EXT, GLX_TEXTURE_FORMAT_RGB_EXT, |
| 179 GL_NONE, | 179 GL_NONE, |
| 180 }; | 180 }; |
| 181 | 181 |
| 182 glx_pixmap_ = glXCreatePixmap(x_display_, fb_config, x_pixmap_, pixmap_attr); | 182 glx_pixmap_ = glXCreatePixmap(x_display_, fb_config, x_pixmap_, pixmap_attr); |
| 183 if (!glx_pixmap_) { | 183 if (!glx_pixmap_) { |
| 184 // x_pixmap_ will be freed in the destructor. | 184 // x_pixmap_ will be freed in the destructor. |
| 185 DVLOG(1) << "Failed creating a GLX Pixmap for TFP"; | 185 LOG(ERROR) << "Failed creating a GLX Pixmap for TFP"; |
| 186 return false; | 186 return false; |
| 187 } | 187 } |
| 188 | 188 |
| 189 return true; | 189 return true; |
| 190 } | 190 } |
| 191 | 191 |
| 192 VaapiVideoDecodeAccelerator::TFPPicture::~TFPPicture() { | 192 VaapiVideoDecodeAccelerator::TFPPicture::~TFPPicture() { |
| 193 DCHECK(CalledOnValidThread()); | 193 DCHECK(CalledOnValidThread()); |
| 194 // Unbind surface from texture and deallocate resources. | 194 // Unbind surface from texture and deallocate resources. |
| 195 if (glx_pixmap_ && make_context_current_.Run()) { | 195 if (glx_pixmap_ && make_context_current_.Run()) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 212 gfx::ScopedTextureBinder texture_binder(GL_TEXTURE_2D, texture_id_); | 212 gfx::ScopedTextureBinder texture_binder(GL_TEXTURE_2D, texture_id_); |
| 213 glXBindTexImageEXT(x_display_, glx_pixmap_, GLX_FRONT_LEFT_EXT, NULL); | 213 glXBindTexImageEXT(x_display_, glx_pixmap_, GLX_FRONT_LEFT_EXT, NULL); |
| 214 | 214 |
| 215 return true; | 215 return true; |
| 216 } | 216 } |
| 217 | 217 |
| 218 VaapiVideoDecodeAccelerator::TFPPicture* | 218 VaapiVideoDecodeAccelerator::TFPPicture* |
| 219 VaapiVideoDecodeAccelerator::TFPPictureById(int32 picture_buffer_id) { | 219 VaapiVideoDecodeAccelerator::TFPPictureById(int32 picture_buffer_id) { |
| 220 TFPPictures::iterator it = tfp_pictures_.find(picture_buffer_id); | 220 TFPPictures::iterator it = tfp_pictures_.find(picture_buffer_id); |
| 221 if (it == tfp_pictures_.end()) { | 221 if (it == tfp_pictures_.end()) { |
| 222 DVLOG(1) << "Picture id " << picture_buffer_id << " does not exist"; | 222 LOG(ERROR) << "Picture id " << picture_buffer_id << " does not exist"; |
| 223 return NULL; | 223 return NULL; |
| 224 } | 224 } |
| 225 | 225 |
| 226 return it->second.get(); | 226 return it->second.get(); |
| 227 } | 227 } |
| 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), |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 client_ = client_ptr_factory_->GetWeakPtr(); | 288 client_ = client_ptr_factory_->GetWeakPtr(); |
| 289 | 289 |
| 290 base::AutoLock auto_lock(lock_); | 290 base::AutoLock auto_lock(lock_); |
| 291 DCHECK_EQ(state_, kUninitialized); | 291 DCHECK_EQ(state_, kUninitialized); |
| 292 DVLOG(2) << "Initializing VAVDA, profile: " << profile; | 292 DVLOG(2) << "Initializing VAVDA, profile: " << profile; |
| 293 | 293 |
| 294 if (!make_context_current_.Run()) | 294 if (!make_context_current_.Run()) |
| 295 return false; | 295 return false; |
| 296 | 296 |
| 297 if (!InitializeFBConfig()) { | 297 if (!InitializeFBConfig()) { |
| 298 DVLOG(1) << "Could not get a usable FBConfig"; | 298 LOG(ERROR) << "Could not get a usable FBConfig"; |
| 299 return false; | 299 return false; |
| 300 } | 300 } |
| 301 | 301 |
| 302 vaapi_wrapper_ = VaapiWrapper::Create( | 302 vaapi_wrapper_ = VaapiWrapper::Create( |
| 303 VaapiWrapper::kDecode, | 303 VaapiWrapper::kDecode, |
| 304 profile, | 304 profile, |
| 305 x_display_, | 305 x_display_, |
| 306 base::Bind(&ReportToUMA, content::VaapiH264Decoder::VAAPI_ERROR)); | 306 base::Bind(&ReportToUMA, content::VaapiH264Decoder::VAAPI_ERROR)); |
| 307 | 307 |
| 308 if (!vaapi_wrapper_.get()) { | 308 if (!vaapi_wrapper_.get()) { |
| 309 DVLOG(1) << "Failed initializing VAAPI"; | 309 LOG(ERROR) << "Failed initializing VAAPI"; |
| 310 return false; | 310 return false; |
| 311 } | 311 } |
| 312 | 312 |
| 313 decoder_.reset( | 313 decoder_.reset( |
| 314 new VaapiH264Decoder( | 314 new VaapiH264Decoder( |
| 315 vaapi_wrapper_.get(), | 315 vaapi_wrapper_.get(), |
| 316 media::BindToCurrentLoop(base::Bind( | 316 media::BindToCurrentLoop(base::Bind( |
| 317 &VaapiVideoDecodeAccelerator::SurfaceReady, weak_this_)), | 317 &VaapiVideoDecodeAccelerator::SurfaceReady, weak_this_)), |
| 318 base::Bind(&ReportToUMA))); | 318 base::Bind(&ReportToUMA))); |
| 319 | 319 |
| (...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 917 DCHECK_EQ(message_loop_, base::MessageLoop::current()); | 917 DCHECK_EQ(message_loop_, base::MessageLoop::current()); |
| 918 Cleanup(); | 918 Cleanup(); |
| 919 delete this; | 919 delete this; |
| 920 } | 920 } |
| 921 | 921 |
| 922 bool VaapiVideoDecodeAccelerator::CanDecodeOnIOThread() { | 922 bool VaapiVideoDecodeAccelerator::CanDecodeOnIOThread() { |
| 923 return false; | 923 return false; |
| 924 } | 924 } |
| 925 | 925 |
| 926 } // namespace content | 926 } // namespace content |
| OLD | NEW |