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

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

Issue 240113009: Enable HW VAVDA by libva-wayland backend. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 8 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2014 and intel copyright. All rights reserved.
Ami GONE FROM CHROMIUM 2014/04/18 22:40:25 Copyright rests with The Chromium Authors, not wit
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" 12 #include "base/threading/non_thread_safe.h"
13 #include "content/common/gpu/gpu_channel.h" 13 #include "content/common/gpu/gpu_channel.h"
14 #include "content/common/gpu/media/vaapi_video_decode_accelerator.h" 14 #include "content/common/gpu/media/vaapi_video_decode_accelerator.h"
15 #include "media/base/bind_to_current_loop.h" 15 #include "media/base/bind_to_current_loop.h"
16 #include "media/video/picture.h" 16 #include "media/video/picture.h"
17 #include "ui/gl/gl_bindings.h"
18 #include "ui/gl/scoped_binders.h" 17 #include "ui/gl/scoped_binders.h"
19 18
20 static void ReportToUMA( 19 static void ReportToUMA(
21 content::VaapiH264Decoder::VAVDAH264DecoderFailure failure) { 20 content::VaapiH264Decoder::VAVDAH264DecoderFailure failure) {
22 UMA_HISTOGRAM_ENUMERATION( 21 UMA_HISTOGRAM_ENUMERATION(
23 "Media.VAVDAH264.DecoderFailure", 22 "Media.VAVDAH264.DecoderFailure",
24 failure, 23 failure,
25 content::VaapiH264Decoder::VAVDA_H264_DECODER_FAILURES_MAX); 24 content::VaapiH264Decoder::VAVDA_H264_DECODER_FAILURES_MAX);
26 } 25 }
27 26
(...skipping 26 matching lines...) Expand all
54 message_loop_->PostTask(FROM_HERE, base::Bind( 53 message_loop_->PostTask(FROM_HERE, base::Bind(
55 &VaapiVideoDecodeAccelerator::Cleanup, weak_this_)); 54 &VaapiVideoDecodeAccelerator::Cleanup, weak_this_));
56 55
57 DVLOG(1) << "Notifying of error " << error; 56 DVLOG(1) << "Notifying of error " << error;
58 if (client_) { 57 if (client_) {
59 client_->NotifyError(error); 58 client_->NotifyError(error);
60 client_ptr_factory_.reset(); 59 client_ptr_factory_.reset();
61 } 60 }
62 } 61 }
63 62
64 // TFPPicture allocates X Pixmaps and binds them to textures passed 63 // TFPPicture allocates VAImage and binds them to textures passed
65 // in PictureBuffers from clients to them. TFPPictures are created as 64 // in PictureBuffers from clients to them. TFPPictures are created as
66 // a consequence of receiving a set of PictureBuffers from clients and released 65 // 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). 66 // at the end of decode (or when a new set of PictureBuffers is required).
68 // 67 //
69 // TFPPictures are used for output, contents of VASurfaces passed from decoder 68 // TFPPictures are used for output, contents of VASurfaces passed from decoder
70 // are put into the associated pixmap memory and sent to client. 69 // are put into the associated vaimage memory and upload to client.
71 class VaapiVideoDecodeAccelerator::TFPPicture : public base::NonThreadSafe { 70 class VaapiVideoDecodeAccelerator::TFPPicture : public base::NonThreadSafe {
72 public: 71 public:
73 ~TFPPicture(); 72 ~TFPPicture();
74 73
75 static linked_ptr<TFPPicture> Create( 74 static linked_ptr<TFPPicture> Create(
76 const base::Callback<bool(void)>& make_context_current, 75 const base::Callback<bool(void)>& make_context_current, //NOLINT
77 const GLXFBConfig& fb_config, 76 wl_display* wl_display,
78 Display* x_display, 77 VaapiWrapper* va_wrapper,
79 int32 picture_buffer_id, 78 int32 picture_buffer_id,
80 uint32 texture_id, 79 uint32 texture_id,
81 gfx::Size size); 80 gfx::Size size);
82 81
83 int32 picture_buffer_id() { 82 int32 picture_buffer_id() {
84 return picture_buffer_id_; 83 return picture_buffer_id_;
85 } 84 }
86 85
87 gfx::Size size() { 86 gfx::Size size() {
88 return size_; 87 return size_;
89 } 88 }
90 89
91 int x_pixmap() { 90 // Upload vaimage data to texture. Needs to be called every frame.
92 return x_pixmap_; 91 bool Upload(VASurfaceID id);
93 }
94
95 // Bind texture to pixmap. Needs to be called every frame.
96 bool Bind();
97 92
98 private: 93 private:
99 TFPPicture(const base::Callback<bool(void)>& make_context_current, 94 TFPPicture(const base::Callback<bool(void)>& make_context_current, //NOLINT
100 Display* x_display, 95 wl_display* wl_display,
96 VaapiWrapper* va_wrapper,
101 int32 picture_buffer_id, 97 int32 picture_buffer_id,
102 uint32 texture_id, 98 uint32 texture_id,
103 gfx::Size size); 99 gfx::Size size);
104 100
105 bool Initialize(const GLXFBConfig& fb_config); 101 bool Initialize();
106 102
107 base::Callback<bool(void)> make_context_current_; 103 base::Callback<bool(void)> make_context_current_; //NOLINT
108 104
109 Display* x_display_; 105 wl_display* wl_display_;
106 VaapiWrapper* va_wrapper_;
110 107
111 // Output id for the client. 108 // Output id for the client.
112 int32 picture_buffer_id_; 109 int32 picture_buffer_id_;
113 uint32 texture_id_; 110 uint32 texture_id_;
114 111
115 gfx::Size size_; 112 gfx::Size size_;
116 113 VAImage va_image_;
117 // Pixmaps bound to this texture.
118 Pixmap x_pixmap_;
119 GLXPixmap glx_pixmap_;
120 114
121 DISALLOW_COPY_AND_ASSIGN(TFPPicture); 115 DISALLOW_COPY_AND_ASSIGN(TFPPicture);
122 }; 116 };
123 117
124 VaapiVideoDecodeAccelerator::TFPPicture::TFPPicture( 118 VaapiVideoDecodeAccelerator::TFPPicture::TFPPicture(
125 const base::Callback<bool(void)>& make_context_current, 119 const base::Callback<bool(void)>& make_context_current, //NOLINT
126 Display* x_display, 120 wl_display* wl_display,
121 VaapiWrapper* va_wrapper,
127 int32 picture_buffer_id, 122 int32 picture_buffer_id,
128 uint32 texture_id, 123 uint32 texture_id,
129 gfx::Size size) 124 gfx::Size size)
130 : make_context_current_(make_context_current), 125 : make_context_current_(make_context_current),
131 x_display_(x_display), 126 wl_display_(wl_display),
127 va_wrapper_(va_wrapper),
132 picture_buffer_id_(picture_buffer_id), 128 picture_buffer_id_(picture_buffer_id),
133 texture_id_(texture_id), 129 texture_id_(texture_id),
134 size_(size), 130 size_(size) {
135 x_pixmap_(0),
136 glx_pixmap_(0) {
137 DCHECK(!make_context_current_.is_null()); 131 DCHECK(!make_context_current_.is_null());
138 }; 132 };
139 133
140 linked_ptr<VaapiVideoDecodeAccelerator::TFPPicture> 134 linked_ptr<VaapiVideoDecodeAccelerator::TFPPicture>
141 VaapiVideoDecodeAccelerator::TFPPicture::Create( 135 VaapiVideoDecodeAccelerator::TFPPicture::Create(
142 const base::Callback<bool(void)>& make_context_current, 136 const base::Callback<bool(void)>& make_context_current, //NOLINT
143 const GLXFBConfig& fb_config, 137 wl_display* wl_display,
144 Display* x_display, 138 VaapiWrapper* va_wrapper,
145 int32 picture_buffer_id, 139 int32 picture_buffer_id,
146 uint32 texture_id, 140 uint32 texture_id,
147 gfx::Size size) { 141 gfx::Size size) {
142 linked_ptr<TFPPicture> tfp_picture(
143 new TFPPicture(make_context_current, wl_display, va_wrapper,
144 picture_buffer_id, texture_id, size));
148 145
149 linked_ptr<TFPPicture> tfp_picture( 146 if (!tfp_picture->Initialize())
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(); 147 tfp_picture.reset();
155 148
156 return tfp_picture; 149 return tfp_picture;
157 } 150 }
158 151
159 bool VaapiVideoDecodeAccelerator::TFPPicture::Initialize( 152 bool VaapiVideoDecodeAccelerator::TFPPicture::Initialize() {
160 const GLXFBConfig& fb_config) {
161 DCHECK(CalledOnValidThread()); 153 DCHECK(CalledOnValidThread());
162 if (!make_context_current_.Run()) 154 if (!make_context_current_.Run())
163 return false; 155 return false;
164 156
165 XWindowAttributes win_attr; 157 if (!va_wrapper_->CreateRGBImage(size_, &va_image_)) {
166 int screen = DefaultScreen(x_display_); 158 DVLOG(1) << "Failed to create VAImage";
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; 159 return false;
174 } 160 }
175 161
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; 162 return true;
190 } 163 }
191 164
192 VaapiVideoDecodeAccelerator::TFPPicture::~TFPPicture() { 165 VaapiVideoDecodeAccelerator::TFPPicture::~TFPPicture() {
193 DCHECK(CalledOnValidThread()); 166 DCHECK(CalledOnValidThread());
194 // Unbind surface from texture and deallocate resources. 167
195 if (glx_pixmap_ && make_context_current_.Run()) { 168 if (va_wrapper_) {
196 glXReleaseTexImageEXT(x_display_, glx_pixmap_, GLX_FRONT_LEFT_EXT); 169 va_wrapper_->DestroyImage(&va_image_);
197 glXDestroyPixmap(x_display_, glx_pixmap_);
198 } 170 }
199
200 if (x_pixmap_)
201 XFreePixmap(x_display_, x_pixmap_);
202 XSync(x_display_, False); // Needed to work around buggy vdpau-driver.
203 } 171 }
204 172
205 bool VaapiVideoDecodeAccelerator::TFPPicture::Bind() { 173 bool VaapiVideoDecodeAccelerator::TFPPicture::Upload(VASurfaceID surface) {
206 DCHECK(CalledOnValidThread()); 174 DCHECK(CalledOnValidThread());
207 DCHECK(x_pixmap_); 175
208 DCHECK(glx_pixmap_);
209 if (!make_context_current_.Run()) 176 if (!make_context_current_.Run())
210 return false; 177 return false;
211 178
179 if (!va_wrapper_->PutSurfaceIntoImage(surface, &va_image_)) {
180 DVLOG(1) << "Failed to put va surface to image";
181 return false;
182 }
183
184 void* buffer = NULL;
185 if (!va_wrapper_->MapImage(&va_image_, &buffer)) {
186 DVLOG(1) << "Failed to map VAImage";
187 return false;
188 }
189
212 gfx::ScopedTextureBinder texture_binder(GL_TEXTURE_2D, texture_id_); 190 gfx::ScopedTextureBinder texture_binder(GL_TEXTURE_2D, texture_id_);
213 glXBindTexImageEXT(x_display_, glx_pixmap_, GLX_FRONT_LEFT_EXT, NULL); 191 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
192 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
193 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, size_.width(), size_.height(),
194 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
195
196 va_wrapper_->UnmapImage(&va_image_);
214 197
215 return true; 198 return true;
216 } 199 }
217 200
218 VaapiVideoDecodeAccelerator::TFPPicture* 201 VaapiVideoDecodeAccelerator::TFPPicture*
219 VaapiVideoDecodeAccelerator::TFPPictureById(int32 picture_buffer_id) { 202 VaapiVideoDecodeAccelerator::TFPPictureById(int32 picture_buffer_id) {
220 TFPPictures::iterator it = tfp_pictures_.find(picture_buffer_id); 203 TFPPictures::iterator it = tfp_pictures_.find(picture_buffer_id);
221 if (it == tfp_pictures_.end()) { 204 if (it == tfp_pictures_.end()) {
222 DVLOG(1) << "Picture id " << picture_buffer_id << " does not exist"; 205 DVLOG(1) << "Picture id " << picture_buffer_id << " does not exist";
223 return NULL; 206 return NULL;
224 } 207 }
225 208
226 return it->second.get(); 209 return it->second.get();
227 } 210 }
228 211
229 VaapiVideoDecodeAccelerator::VaapiVideoDecodeAccelerator( 212 VaapiVideoDecodeAccelerator::VaapiVideoDecodeAccelerator(
230 Display* x_display, 213 const base::Callback<bool(void)>& make_context_current) //NOLINT
231 const base::Callback<bool(void)>& make_context_current) 214 : wl_display_(NULL),
232 : x_display_(x_display),
233 make_context_current_(make_context_current), 215 make_context_current_(make_context_current),
234 state_(kUninitialized), 216 state_(kUninitialized),
235 input_ready_(&lock_), 217 input_ready_(&lock_),
236 surfaces_available_(&lock_), 218 surfaces_available_(&lock_),
237 message_loop_(base::MessageLoop::current()), 219 message_loop_(base::MessageLoop::current()),
220 weak_this_(base::AsWeakPtr(this)),
221 va_surface_release_cb_(media::BindToCurrentLoop(base::Bind(
222 &VaapiVideoDecodeAccelerator::RecycleVASurfaceID, weak_this_))),
238 decoder_thread_("VaapiDecoderThread"), 223 decoder_thread_("VaapiDecoderThread"),
239 num_frames_at_client_(0), 224 num_frames_at_client_(0),
240 num_stream_bufs_at_decoder_(0), 225 num_stream_bufs_at_decoder_(0),
241 finish_flush_pending_(false), 226 finish_flush_pending_(false),
242 awaiting_va_surfaces_recycle_(false), 227 awaiting_va_surfaces_recycle_(false),
243 requested_num_pics_(0), 228 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_));
248 } 229 }
249 230
250 VaapiVideoDecodeAccelerator::~VaapiVideoDecodeAccelerator() { 231 VaapiVideoDecodeAccelerator::~VaapiVideoDecodeAccelerator() {
251 DCHECK_EQ(message_loop_, base::MessageLoop::current()); 232 DCHECK_EQ(message_loop_, base::MessageLoop::current());
233 if (wl_display_) {
234 wl_display_flush(wl_display_);
235 wl_display_disconnect(wl_display_);
236 wl_display_ = NULL;
237 }
252 } 238 }
253 239
254 class XFreeDeleter { 240 typedef struct wayland_display {
255 public: 241 wl_display* display;
256 void operator()(void* x) const { 242 wl_compositor* compositor;
257 ::XFree(x); 243 wl_shell* shell;
244 wl_registry* registry;
245 int event_fd;
246 } wayland_display;
247
248 static void registry_handle_global(
249 void* data,
250 wl_registry* registry,
251 uint32_t id,
252 const char* interface,
253 uint32_t version) {
254 wayland_display* display_handle =
255 reinterpret_cast<wayland_display *>(data);
256
257 if (strcmp(interface, "wl_compositor") == 0) {
258 display_handle->compositor =
259 reinterpret_cast<wl_compositor *>(wl_registry_bind(
260 registry, id, &wl_compositor_interface, 1));
261 } else if (strcmp(interface, "wl_shell") == 0) {
262 display_handle->shell =
263 reinterpret_cast<wl_shell *>(wl_registry_bind(
264 registry, id, &wl_shell_interface, 1));
258 } 265 }
266 }
267
268 static const struct wl_registry_listener registry_listener = {
269 registry_handle_global,
270 NULL,
259 }; 271 };
260 272
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, 273 bool VaapiVideoDecodeAccelerator::Initialize(media::VideoCodecProfile profile,
284 Client* client) { 274 Client* client) {
285 DCHECK_EQ(message_loop_, base::MessageLoop::current()); 275 DCHECK_EQ(message_loop_, base::MessageLoop::current());
286 276
287 client_ptr_factory_.reset(new base::WeakPtrFactory<Client>(client)); 277 client_ptr_factory_.reset(new base::WeakPtrFactory<Client>(client));
288 client_ = client_ptr_factory_->GetWeakPtr(); 278 client_ = client_ptr_factory_->GetWeakPtr();
289 279
290 base::AutoLock auto_lock(lock_); 280 base::AutoLock auto_lock(lock_);
291 DCHECK_EQ(state_, kUninitialized); 281 DCHECK_EQ(state_, kUninitialized);
292 DVLOG(2) << "Initializing VAVDA, profile: " << profile; 282 DVLOG(2) << "Initializing VAVDA, profile: " << profile;
293 283
294 if (!make_context_current_.Run()) 284 if (!make_context_current_.Run())
295 return false; 285 return false;
296 286
297 if (!InitializeFBConfig()) { 287 wayland_display d;
298 DVLOG(1) << "Could not get a usable FBConfig"; 288
289 d.display = wl_display_connect(NULL);
290 if (!d.display)
299 return false; 291 return false;
300 } 292 wl_display_set_user_data(d.display, &d);
293 d.registry = wl_display_get_registry(d.display);
294 wl_registry_add_listener(d.registry, &registry_listener, &d);
295 wl_display_dispatch(d.display);
296 wl_display_ = d.display;
301 297
302 vaapi_wrapper_ = VaapiWrapper::Create( 298 vaapi_wrapper_ = VaapiWrapper::Create(
303 profile, x_display_, 299 profile, wl_display_,
304 base::Bind(&ReportToUMA, content::VaapiH264Decoder::VAAPI_ERROR)); 300 base::Bind(&ReportToUMA, content::VaapiH264Decoder::VAAPI_ERROR));
305 301
306 if (!vaapi_wrapper_.get()) { 302 if (!vaapi_wrapper_.get()) {
307 DVLOG(1) << "Failed initializing VAAPI"; 303 DVLOG(1) << "Failed initializing VAAPI";
308 return false; 304 return false;
309 } 305 }
310 306
311 decoder_.reset( 307 decoder_.reset(
312 new VaapiH264Decoder( 308 new VaapiH264Decoder(
313 vaapi_wrapper_.get(), 309 vaapi_wrapper_.get(),
314 media::BindToCurrentLoop(base::Bind( 310 media::BindToCurrentLoop(base::Bind(
315 &VaapiVideoDecodeAccelerator::SurfaceReady, weak_this_)), 311 &VaapiVideoDecodeAccelerator::SurfaceReady, weak_this_)),
316 base::Bind(&ReportToUMA))); 312 base::Bind(&ReportToUMA)));
317 313
318 CHECK(decoder_thread_.Start()); 314 CHECK(decoder_thread_.Start());
319 decoder_thread_proxy_ = decoder_thread_.message_loop_proxy(); 315 decoder_thread_proxy_ = decoder_thread_.message_loop_proxy();
320 316
321 state_ = kIdle; 317 state_ = kIdle;
318
319 message_loop_->PostTask(FROM_HERE, base::Bind(
320 &Client::NotifyInitializeDone, client_));
321
322 return true; 322 return true;
323 } 323 }
324 324
325 void VaapiVideoDecodeAccelerator::SurfaceReady( 325 void VaapiVideoDecodeAccelerator::SurfaceReady(
326 int32 input_id, 326 int32 input_id,
327 const scoped_refptr<VASurface>& va_surface) { 327 const scoped_refptr<VASurface>& va_surface) {
328 DCHECK_EQ(message_loop_, base::MessageLoop::current()); 328 DCHECK_EQ(message_loop_, base::MessageLoop::current());
329 DCHECK(!awaiting_va_surfaces_recycle_); 329 DCHECK(!awaiting_va_surfaces_recycle_);
330 330
331 // 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 15 matching lines...) Expand all
347 347
348 int32 output_id = tfp_picture->picture_buffer_id(); 348 int32 output_id = tfp_picture->picture_buffer_id();
349 349
350 TRACE_EVENT2("Video Decoder", "VAVDA::OutputSurface", 350 TRACE_EVENT2("Video Decoder", "VAVDA::OutputSurface",
351 "input_id", input_id, 351 "input_id", input_id,
352 "output_id", output_id); 352 "output_id", output_id);
353 353
354 DVLOG(3) << "Outputting VASurface " << va_surface->id() 354 DVLOG(3) << "Outputting VASurface " << va_surface->id()
355 << " into pixmap bound to picture buffer id " << output_id; 355 << " into pixmap bound to picture buffer id " << output_id;
356 356
357 RETURN_AND_NOTIFY_ON_FAILURE(tfp_picture->Bind(), 357 RETURN_AND_NOTIFY_ON_FAILURE(tfp_picture->Upload(va_surface->id()),
358 "Failed binding texture to pixmap", 358 "Failed to upload VASurface to texture",
359 PLATFORM_FAILURE, ); 359 PLATFORM_FAILURE, ); //NOLINT
360
361 RETURN_AND_NOTIFY_ON_FAILURE(
362 vaapi_wrapper_->PutSurfaceIntoPixmap(va_surface->id(),
363 tfp_picture->x_pixmap(),
364 tfp_picture->size()),
365 "Failed putting surface into pixmap", PLATFORM_FAILURE, );
366 360
367 // Notify the client a picture is ready to be displayed. 361 // Notify the client a picture is ready to be displayed.
368 ++num_frames_at_client_; 362 ++num_frames_at_client_;
369 TRACE_COUNTER1("Video Decoder", "Textures at client", num_frames_at_client_); 363 TRACE_COUNTER1("Video Decoder", "Textures at client", num_frames_at_client_);
370 DVLOG(4) << "Notifying output picture id " << output_id 364 DVLOG(4) << "Notifying output picture id " << output_id
371 << " for input "<< input_id << " is ready"; 365 << " for input "<< input_id << " is ready";
372 if (client_) 366 if (client_)
373 client_->PictureReady(media::Picture(output_id, input_id)); 367 client_->PictureReady(media::Picture(output_id, input_id));
374 } 368 }
375 369
(...skipping 20 matching lines...) Expand all
396 FinishFlush(); 390 FinishFlush();
397 } 391 }
398 392
399 void VaapiVideoDecodeAccelerator::MapAndQueueNewInputBuffer( 393 void VaapiVideoDecodeAccelerator::MapAndQueueNewInputBuffer(
400 const media::BitstreamBuffer& bitstream_buffer) { 394 const media::BitstreamBuffer& bitstream_buffer) {
401 DCHECK_EQ(message_loop_, base::MessageLoop::current()); 395 DCHECK_EQ(message_loop_, base::MessageLoop::current());
402 TRACE_EVENT1("Video Decoder", "MapAndQueueNewInputBuffer", "input_id", 396 TRACE_EVENT1("Video Decoder", "MapAndQueueNewInputBuffer", "input_id",
403 bitstream_buffer.id()); 397 bitstream_buffer.id());
404 398
405 DVLOG(4) << "Mapping new input buffer id: " << bitstream_buffer.id() 399 DVLOG(4) << "Mapping new input buffer id: " << bitstream_buffer.id()
406 << " size: " << (int)bitstream_buffer.size(); 400 << " size: " << static_cast<int>(bitstream_buffer.size());
407 401
408 scoped_ptr<base::SharedMemory> shm( 402 scoped_ptr<base::SharedMemory> shm(
409 new base::SharedMemory(bitstream_buffer.handle(), true)); 403 new base::SharedMemory(bitstream_buffer.handle(), true));
410 RETURN_AND_NOTIFY_ON_FAILURE(shm->Map(bitstream_buffer.size()), 404 RETURN_AND_NOTIFY_ON_FAILURE(shm->Map(bitstream_buffer.size()),
411 "Failed to map input buffer", UNREADABLE_INPUT,); 405 "Failed to map input buffer", UNREADABLE_INPUT,); //NOLINT
412 406
413 base::AutoLock auto_lock(lock_); 407 base::AutoLock auto_lock(lock_);
414 408
415 // Set up a new input buffer and queue it for later. 409 // Set up a new input buffer and queue it for later.
416 linked_ptr<InputBuffer> input_buffer(new InputBuffer()); 410 linked_ptr<InputBuffer> input_buffer(new InputBuffer());
417 input_buffer->shm.reset(shm.release()); 411 input_buffer->shm.reset(shm.release());
418 input_buffer->id = bitstream_buffer.id(); 412 input_buffer->id = bitstream_buffer.id();
419 input_buffer->size = bitstream_buffer.size(); 413 input_buffer->size = bitstream_buffer.size();
420 414
421 ++num_stream_bufs_at_decoder_; 415 ++num_stream_bufs_at_decoder_;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 --num_stream_bufs_at_decoder_; 479 --num_stream_bufs_at_decoder_;
486 TRACE_COUNTER1("Video Decoder", "Stream buffers at decoder", 480 TRACE_COUNTER1("Video Decoder", "Stream buffers at decoder",
487 num_stream_bufs_at_decoder_); 481 num_stream_bufs_at_decoder_);
488 } 482 }
489 483
490 bool VaapiVideoDecodeAccelerator::FeedDecoderWithOutputSurfaces_Locked() { 484 bool VaapiVideoDecodeAccelerator::FeedDecoderWithOutputSurfaces_Locked() {
491 lock_.AssertAcquired(); 485 lock_.AssertAcquired();
492 DCHECK(decoder_thread_proxy_->BelongsToCurrentThread()); 486 DCHECK(decoder_thread_proxy_->BelongsToCurrentThread());
493 487
494 while (available_va_surfaces_.empty() && 488 while (available_va_surfaces_.empty() &&
495 (state_ == kDecoding || state_ == kFlushing || state_ == kIdle)) { 489 (state_ == kDecoding || state_ == kFlushing || state_ == kIdle)) {
496 surfaces_available_.Wait(); 490 surfaces_available_.Wait();
497 } 491 }
498 492
499 if (state_ != kDecoding && state_ != kFlushing && state_ != kIdle) 493 if (state_ != kDecoding && state_ != kFlushing && state_ != kIdle)
500 return false; 494 return false;
501 495
502 while (!available_va_surfaces_.empty()) { 496 while (!available_va_surfaces_.empty()) {
503 scoped_refptr<VASurface> va_surface( 497 scoped_refptr<VASurface> va_surface(
504 new VASurface(available_va_surfaces_.front(), va_surface_release_cb_)); 498 new VASurface(available_va_surfaces_.front(), va_surface_release_cb_));
505 available_va_surfaces_.pop_front(); 499 available_va_surfaces_.pop_front();
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 case VaapiH264Decoder::kRanOutOfSurfaces: 547 case VaapiH264Decoder::kRanOutOfSurfaces:
554 // No more output buffers in the decoder, try getting more or go to 548 // No more output buffers in the decoder, try getting more or go to
555 // sleep waiting for them. 549 // sleep waiting for them.
556 if (!FeedDecoderWithOutputSurfaces_Locked()) 550 if (!FeedDecoderWithOutputSurfaces_Locked())
557 return; 551 return;
558 552
559 break; 553 break;
560 554
561 case VaapiH264Decoder::kDecodeError: 555 case VaapiH264Decoder::kDecodeError:
562 RETURN_AND_NOTIFY_ON_FAILURE(false, "Error decoding stream", 556 RETURN_AND_NOTIFY_ON_FAILURE(false, "Error decoding stream",
563 PLATFORM_FAILURE, ); 557 PLATFORM_FAILURE,); //NOLINT
564 return; 558 return;
565 } 559 }
566 } 560 }
567 } 561 }
568 562
569 void VaapiVideoDecodeAccelerator::InitiateSurfaceSetChange(size_t num_pics, 563 void VaapiVideoDecodeAccelerator::InitiateSurfaceSetChange(size_t num_pics,
570 gfx::Size size) { 564 gfx::Size size) {
571 DCHECK_EQ(message_loop_, base::MessageLoop::current()); 565 DCHECK_EQ(message_loop_, base::MessageLoop::current());
572 DCHECK(!awaiting_va_surfaces_recycle_); 566 DCHECK(!awaiting_va_surfaces_recycle_);
573 567
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
651 // Decoder already running, fallthrough. 645 // Decoder already running, fallthrough.
652 case kResetting: 646 case kResetting:
653 // When resetting, allow accumulating bitstream buffers, so that 647 // When resetting, allow accumulating bitstream buffers, so that
654 // the client can queue after-seek-buffers while we are finishing with 648 // the client can queue after-seek-buffers while we are finishing with
655 // the before-seek one. 649 // the before-seek one.
656 break; 650 break;
657 651
658 default: 652 default:
659 RETURN_AND_NOTIFY_ON_FAILURE(false, 653 RETURN_AND_NOTIFY_ON_FAILURE(false,
660 "Decode request from client in invalid state: " << state_, 654 "Decode request from client in invalid state: " << state_,
661 PLATFORM_FAILURE, ); 655 PLATFORM_FAILURE,); //NOLINT
662 break; 656 break;
663 } 657 }
664 } 658 }
665 659
666 void VaapiVideoDecodeAccelerator::RecycleVASurfaceID( 660 void VaapiVideoDecodeAccelerator::RecycleVASurfaceID(
667 VASurfaceID va_surface_id) { 661 VASurfaceID va_surface_id) {
668 DCHECK_EQ(message_loop_, base::MessageLoop::current()); 662 DCHECK_EQ(message_loop_, base::MessageLoop::current());
669 base::AutoLock auto_lock(lock_); 663 base::AutoLock auto_lock(lock_);
670 664
671 available_va_surfaces_.push_back(va_surface_id); 665 available_va_surfaces_.push_back(va_surface_id);
672 surfaces_available_.Signal(); 666 surfaces_available_.Signal();
673 } 667 }
674 668
675 void VaapiVideoDecodeAccelerator::AssignPictureBuffers( 669 void VaapiVideoDecodeAccelerator::AssignPictureBuffers(
676 const std::vector<media::PictureBuffer>& buffers) { 670 const std::vector<media::PictureBuffer>& buffers) {
677 DCHECK_EQ(message_loop_, base::MessageLoop::current()); 671 DCHECK_EQ(message_loop_, base::MessageLoop::current());
678 672
679 base::AutoLock auto_lock(lock_); 673 base::AutoLock auto_lock(lock_);
680 DCHECK(tfp_pictures_.empty()); 674 DCHECK(tfp_pictures_.empty());
681 675
682 while (!output_buffers_.empty()) 676 while (!output_buffers_.empty())
683 output_buffers_.pop(); 677 output_buffers_.pop();
684 678
685 RETURN_AND_NOTIFY_ON_FAILURE( 679 RETURN_AND_NOTIFY_ON_FAILURE(
686 buffers.size() == requested_num_pics_, 680 buffers.size() == requested_num_pics_,
687 "Got an invalid number of picture buffers. (Got " << buffers.size() 681 "Got an invalid buffers. (Got " << buffers.size() << ", requested "
688 << ", requested " << requested_num_pics_ << ")", INVALID_ARGUMENT, ); 682 << requested_num_pics_ << ")", INVALID_ARGUMENT,); //NOLINT
689 DCHECK(requested_pic_size_ == buffers[0].size()); 683 DCHECK(requested_pic_size_ == buffers[0].size());
690 684
691 std::vector<VASurfaceID> va_surface_ids; 685 std::vector<VASurfaceID> va_surface_ids;
692 RETURN_AND_NOTIFY_ON_FAILURE( 686 RETURN_AND_NOTIFY_ON_FAILURE(
693 vaapi_wrapper_->CreateSurfaces(requested_pic_size_, 687 vaapi_wrapper_->CreateSurfaces(requested_pic_size_,
694 buffers.size(), 688 buffers.size(),
695 &va_surface_ids), 689 &va_surface_ids),
696 "Failed creating VA Surfaces", PLATFORM_FAILURE, ); 690 "Failed creating VA Surfaces", PLATFORM_FAILURE,); //NOLINT
697 DCHECK_EQ(va_surface_ids.size(), buffers.size()); 691 DCHECK_EQ(va_surface_ids.size(), buffers.size());
698 692
699 for (size_t i = 0; i < buffers.size(); ++i) { 693 for (size_t i = 0; i < buffers.size(); ++i) {
700 DVLOG(2) << "Assigning picture id: " << buffers[i].id() 694 DVLOG(2) << "Assigning picture id: " << buffers[i].id()
701 << " to texture id: " << buffers[i].texture_id() 695 << " to texture id: " << buffers[i].texture_id()
702 << " VASurfaceID: " << va_surface_ids[i]; 696 << " VASurfaceID: " << va_surface_ids[i];
703 697
704 linked_ptr<TFPPicture> tfp_picture( 698 linked_ptr<TFPPicture> tfp_picture(
705 TFPPicture::Create(make_context_current_, fb_config_, x_display_, 699 TFPPicture::Create(make_context_current_, wl_display_,
706 buffers[i].id(), buffers[i].texture_id(), 700 vaapi_wrapper_.get(), buffers[i].id(),
707 requested_pic_size_)); 701 buffers[i].texture_id(), requested_pic_size_));
708 702
709 RETURN_AND_NOTIFY_ON_FAILURE( 703 RETURN_AND_NOTIFY_ON_FAILURE(
710 tfp_picture.get(), "Failed assigning picture buffer to a texture.", 704 tfp_picture.get(), "Failed assigning picture buffer to a texture.",
711 PLATFORM_FAILURE, ); 705 PLATFORM_FAILURE,); //NOLINT
712 706
713 bool inserted = tfp_pictures_.insert(std::make_pair( 707 bool inserted = tfp_pictures_.insert(std::make_pair(
714 buffers[i].id(), tfp_picture)).second; 708 buffers[i].id(), tfp_picture)).second;
715 DCHECK(inserted); 709 DCHECK(inserted);
716 710
717 output_buffers_.push(buffers[i].id()); 711 output_buffers_.push(buffers[i].id());
718 available_va_surfaces_.push_back(va_surface_ids[i]); 712 available_va_surfaces_.push_back(va_surface_ids[i]);
719 surfaces_available_.Signal(); 713 surfaces_available_.Signal();
720 } 714 }
721 715
(...skipping 15 matching lines...) Expand all
737 } 731 }
738 732
739 void VaapiVideoDecodeAccelerator::FlushTask() { 733 void VaapiVideoDecodeAccelerator::FlushTask() {
740 DCHECK(decoder_thread_proxy_->BelongsToCurrentThread()); 734 DCHECK(decoder_thread_proxy_->BelongsToCurrentThread());
741 DVLOG(1) << "Flush task"; 735 DVLOG(1) << "Flush task";
742 736
743 // First flush all the pictures that haven't been outputted, notifying the 737 // First flush all the pictures that haven't been outputted, notifying the
744 // client to output them. 738 // client to output them.
745 bool res = decoder_->Flush(); 739 bool res = decoder_->Flush();
746 RETURN_AND_NOTIFY_ON_FAILURE(res, "Failed flushing the decoder.", 740 RETURN_AND_NOTIFY_ON_FAILURE(res, "Failed flushing the decoder.",
747 PLATFORM_FAILURE, ); 741 PLATFORM_FAILURE,); //NOLINT
748 742
749 // Put the decoder in idle state, ready to resume. 743 // Put the decoder in idle state, ready to resume.
750 decoder_->Reset(); 744 decoder_->Reset();
751 745
752 message_loop_->PostTask(FROM_HERE, base::Bind( 746 message_loop_->PostTask(FROM_HERE, base::Bind(
753 &VaapiVideoDecodeAccelerator::FinishFlush, weak_this_)); 747 &VaapiVideoDecodeAccelerator::FinishFlush, weak_this_));
754 } 748 }
755 749
756 void VaapiVideoDecodeAccelerator::Flush() { 750 void VaapiVideoDecodeAccelerator::Flush() {
757 DCHECK_EQ(message_loop_, base::MessageLoop::current()); 751 DCHECK_EQ(message_loop_, base::MessageLoop::current());
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
886 DCHECK_EQ(message_loop_, base::MessageLoop::current()); 880 DCHECK_EQ(message_loop_, base::MessageLoop::current());
887 881
888 if (state_ == kUninitialized || state_ == kDestroying) 882 if (state_ == kUninitialized || state_ == kDestroying)
889 return; 883 return;
890 884
891 DVLOG(1) << "Destroying VAVDA"; 885 DVLOG(1) << "Destroying VAVDA";
892 base::AutoLock auto_lock(lock_); 886 base::AutoLock auto_lock(lock_);
893 state_ = kDestroying; 887 state_ = kDestroying;
894 888
895 client_ptr_factory_.reset(); 889 client_ptr_factory_.reset();
896 weak_this_factory_.InvalidateWeakPtrs();
897 890
898 { 891 {
899 base::AutoUnlock auto_unlock(lock_); 892 base::AutoUnlock auto_unlock(lock_);
900 // Post a dummy task to the decoder_thread_ to ensure it is drained. 893 // Post a dummy task to the decoder_thread_ to ensure it is drained.
901 base::WaitableEvent waiter(false, false); 894 base::WaitableEvent waiter(false, false);
902 decoder_thread_proxy_->PostTask(FROM_HERE, base::Bind( 895 decoder_thread_proxy_->PostTask(FROM_HERE, base::Bind(
903 &base::WaitableEvent::Signal, base::Unretained(&waiter))); 896 &base::WaitableEvent::Signal, base::Unretained(&waiter)));
904 input_ready_.Signal(); 897 input_ready_.Signal();
905 surfaces_available_.Signal(); 898 surfaces_available_.Signal();
906 waiter.Wait(); 899 waiter.Wait();
907 decoder_thread_.Stop(); 900 decoder_thread_.Stop();
908 } 901 }
909 902
910 state_ = kUninitialized; 903 state_ = kUninitialized;
911 } 904 }
912 905
913 void VaapiVideoDecodeAccelerator::Destroy() { 906 void VaapiVideoDecodeAccelerator::Destroy() {
914 DCHECK_EQ(message_loop_, base::MessageLoop::current()); 907 DCHECK_EQ(message_loop_, base::MessageLoop::current());
915 Cleanup(); 908 Cleanup();
916 delete this; 909 delete this;
917 } 910 }
918 911
919 } // namespace content 912 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698