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

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

Issue 804353003: Revert of Refactor Vaapi video decoder/encoder in preparation of Freon support (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 12 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) 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"
12 #include "content/common/gpu/gpu_channel.h" 13 #include "content/common/gpu/gpu_channel.h"
13 #include "content/common/gpu/media/vaapi_picture.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" 17 #include "ui/gl/gl_bindings.h"
18 #include "ui/gl/scoped_binders.h"
18 19
19 static void ReportToUMA( 20 static void ReportToUMA(
20 content::VaapiH264Decoder::VAVDAH264DecoderFailure failure) { 21 content::VaapiH264Decoder::VAVDAH264DecoderFailure failure) {
21 UMA_HISTOGRAM_ENUMERATION( 22 UMA_HISTOGRAM_ENUMERATION(
22 "Media.VAVDAH264.DecoderFailure", 23 "Media.VAVDAH264.DecoderFailure",
23 failure, 24 failure,
24 content::VaapiH264Decoder::VAVDA_H264_DECODER_FAILURES_MAX); 25 content::VaapiH264Decoder::VAVDA_H264_DECODER_FAILURES_MAX);
25 } 26 }
26 27
27 namespace content { 28 namespace content {
(...skipping 25 matching lines...) Expand all
53 message_loop_->PostTask(FROM_HERE, base::Bind( 54 message_loop_->PostTask(FROM_HERE, base::Bind(
54 &VaapiVideoDecodeAccelerator::Cleanup, weak_this_)); 55 &VaapiVideoDecodeAccelerator::Cleanup, weak_this_));
55 56
56 LOG(ERROR) << "Notifying of error " << error; 57 LOG(ERROR) << "Notifying of error " << error;
57 if (client_) { 58 if (client_) {
58 client_->NotifyError(error); 59 client_->NotifyError(error);
59 client_ptr_factory_.reset(); 60 client_ptr_factory_.reset();
60 } 61 }
61 } 62 }
62 63
63 VaapiPicture* VaapiVideoDecodeAccelerator::PictureById( 64 // TFPPicture allocates X Pixmaps and binds them to textures passed
64 int32 picture_buffer_id) { 65 // in PictureBuffers from clients to them. TFPPictures are created as
65 Pictures::iterator it = pictures_.find(picture_buffer_id); 66 // a consequence of receiving a set of PictureBuffers from clients and released
66 if (it == pictures_.end()) { 67 // at the end of decode (or when a new set of PictureBuffers is required).
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 LOG(ERROR) << "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 LOG(ERROR) << "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()) {
67 LOG(ERROR) << "Picture id " << picture_buffer_id << " does not exist"; 222 LOG(ERROR) << "Picture id " << picture_buffer_id << " does not exist";
68 return NULL; 223 return NULL;
69 } 224 }
70 225
71 return it->second.get(); 226 return it->second.get();
72 } 227 }
73 228
74 VaapiVideoDecodeAccelerator::VaapiVideoDecodeAccelerator( 229 VaapiVideoDecodeAccelerator::VaapiVideoDecodeAccelerator(
230 Display* x_display,
75 const base::Callback<bool(void)>& make_context_current) 231 const base::Callback<bool(void)>& make_context_current)
76 : make_context_current_(make_context_current), 232 : x_display_(x_display),
233 make_context_current_(make_context_current),
77 state_(kUninitialized), 234 state_(kUninitialized),
78 input_ready_(&lock_), 235 input_ready_(&lock_),
79 surfaces_available_(&lock_), 236 surfaces_available_(&lock_),
80 message_loop_(base::MessageLoop::current()), 237 message_loop_(base::MessageLoop::current()),
81 decoder_thread_("VaapiDecoderThread"), 238 decoder_thread_("VaapiDecoderThread"),
82 num_frames_at_client_(0), 239 num_frames_at_client_(0),
83 num_stream_bufs_at_decoder_(0), 240 num_stream_bufs_at_decoder_(0),
84 finish_flush_pending_(false), 241 finish_flush_pending_(false),
85 awaiting_va_surfaces_recycle_(false), 242 awaiting_va_surfaces_recycle_(false),
86 requested_num_pics_(0), 243 requested_num_pics_(0),
87 weak_this_factory_(this) { 244 weak_this_factory_(this) {
88 weak_this_ = weak_this_factory_.GetWeakPtr(); 245 weak_this_ = weak_this_factory_.GetWeakPtr();
89 va_surface_release_cb_ = media::BindToCurrentLoop( 246 va_surface_release_cb_ = media::BindToCurrentLoop(
90 base::Bind(&VaapiVideoDecodeAccelerator::RecycleVASurfaceID, weak_this_)); 247 base::Bind(&VaapiVideoDecodeAccelerator::RecycleVASurfaceID, weak_this_));
91 } 248 }
92 249
93 VaapiVideoDecodeAccelerator::~VaapiVideoDecodeAccelerator() { 250 VaapiVideoDecodeAccelerator::~VaapiVideoDecodeAccelerator() {
94 DCHECK_EQ(message_loop_, base::MessageLoop::current()); 251 DCHECK_EQ(message_loop_, base::MessageLoop::current());
95 } 252 }
96 253
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
97 bool VaapiVideoDecodeAccelerator::Initialize(media::VideoCodecProfile profile, 283 bool VaapiVideoDecodeAccelerator::Initialize(media::VideoCodecProfile profile,
98 Client* client) { 284 Client* client) {
99 DCHECK_EQ(message_loop_, base::MessageLoop::current()); 285 DCHECK_EQ(message_loop_, base::MessageLoop::current());
100 286
101 client_ptr_factory_.reset(new base::WeakPtrFactory<Client>(client)); 287 client_ptr_factory_.reset(new base::WeakPtrFactory<Client>(client));
102 client_ = client_ptr_factory_->GetWeakPtr(); 288 client_ = client_ptr_factory_->GetWeakPtr();
103 289
104 base::AutoLock auto_lock(lock_); 290 base::AutoLock auto_lock(lock_);
105 DCHECK_EQ(state_, kUninitialized); 291 DCHECK_EQ(state_, kUninitialized);
106 DVLOG(2) << "Initializing VAVDA, profile: " << profile; 292 DVLOG(2) << "Initializing VAVDA, profile: " << profile;
107 293
108 #if defined(USE_X11) 294 if (!make_context_current_.Run())
109 if (gfx::GetGLImplementation() != gfx::kGLImplementationDesktopGL) { 295 return false;
110 DVLOG(1) << "HW video decode acceleration not available without " 296
111 "DesktopGL (GLX)."; 297 if (!InitializeFBConfig()) {
298 LOG(ERROR) << "Could not get a usable FBConfig";
112 return false; 299 return false;
113 } 300 }
114 #endif // USE_X11
115 301
116 vaapi_wrapper_ = VaapiWrapper::Create( 302 vaapi_wrapper_ = VaapiWrapper::Create(
117 VaapiWrapper::kDecode, 303 VaapiWrapper::kDecode,
118 profile, 304 profile,
305 x_display_,
119 base::Bind(&ReportToUMA, content::VaapiH264Decoder::VAAPI_ERROR)); 306 base::Bind(&ReportToUMA, content::VaapiH264Decoder::VAAPI_ERROR));
120 307
121 if (!vaapi_wrapper_.get()) { 308 if (!vaapi_wrapper_.get()) {
122 LOG(ERROR) << "Failed initializing VAAPI"; 309 LOG(ERROR) << "Failed initializing VAAPI";
123 return false; 310 return false;
124 } 311 }
125 312
126 decoder_.reset( 313 decoder_.reset(
127 new VaapiH264Decoder( 314 new VaapiH264Decoder(
128 vaapi_wrapper_.get(), 315 vaapi_wrapper_.get(),
(...skipping 21 matching lines...) Expand all
150 pending_output_cbs_.push( 337 pending_output_cbs_.push(
151 base::Bind(&VaapiVideoDecodeAccelerator::OutputPicture, 338 base::Bind(&VaapiVideoDecodeAccelerator::OutputPicture,
152 weak_this_, va_surface, input_id)); 339 weak_this_, va_surface, input_id));
153 340
154 TryOutputSurface(); 341 TryOutputSurface();
155 } 342 }
156 343
157 void VaapiVideoDecodeAccelerator::OutputPicture( 344 void VaapiVideoDecodeAccelerator::OutputPicture(
158 const scoped_refptr<VASurface>& va_surface, 345 const scoped_refptr<VASurface>& va_surface,
159 int32 input_id, 346 int32 input_id,
160 VaapiPicture* picture) { 347 TFPPicture* tfp_picture) {
161 DCHECK_EQ(message_loop_, base::MessageLoop::current()); 348 DCHECK_EQ(message_loop_, base::MessageLoop::current());
162 349
163 int32 output_id = picture->picture_buffer_id(); 350 int32 output_id = tfp_picture->picture_buffer_id();
164 351
165 TRACE_EVENT2("Video Decoder", "VAVDA::OutputSurface", 352 TRACE_EVENT2("Video Decoder", "VAVDA::OutputSurface",
166 "input_id", input_id, 353 "input_id", input_id,
167 "output_id", output_id); 354 "output_id", output_id);
168 355
169 DVLOG(3) << "Outputting VASurface " << va_surface->id() 356 DVLOG(3) << "Outputting VASurface " << va_surface->id()
170 << " into pixmap bound to picture buffer id " << output_id; 357 << " into pixmap bound to picture buffer id " << output_id;
171 358
172 RETURN_AND_NOTIFY_ON_FAILURE(picture->DownloadFromSurface(va_surface), 359 RETURN_AND_NOTIFY_ON_FAILURE(tfp_picture->Bind(),
173 "Failed putting surface into pixmap", 360 "Failed binding texture to pixmap",
174 PLATFORM_FAILURE, ); 361 PLATFORM_FAILURE, );
175 362
363 RETURN_AND_NOTIFY_ON_FAILURE(
364 vaapi_wrapper_->PutSurfaceIntoPixmap(va_surface->id(),
365 tfp_picture->x_pixmap(),
366 tfp_picture->size()),
367 "Failed putting surface into pixmap", PLATFORM_FAILURE, );
368
176 // Notify the client a picture is ready to be displayed. 369 // Notify the client a picture is ready to be displayed.
177 ++num_frames_at_client_; 370 ++num_frames_at_client_;
178 TRACE_COUNTER1("Video Decoder", "Textures at client", num_frames_at_client_); 371 TRACE_COUNTER1("Video Decoder", "Textures at client", num_frames_at_client_);
179 DVLOG(4) << "Notifying output picture id " << output_id 372 DVLOG(4) << "Notifying output picture id " << output_id
180 << " for input "<< input_id << " is ready"; 373 << " for input "<< input_id << " is ready";
181 // TODO(posciak): Use visible size from decoder here instead 374 // TODO(posciak): Use visible size from decoder here instead
182 // (crbug.com/402760). 375 // (crbug.com/402760).
183 if (client_) 376 if (client_)
184 client_->PictureReady( 377 client_->PictureReady(
185 media::Picture(output_id, input_id, gfx::Rect(picture->size()))); 378 media::Picture(output_id, input_id, gfx::Rect(tfp_picture->size())));
186 } 379 }
187 380
188 void VaapiVideoDecodeAccelerator::TryOutputSurface() { 381 void VaapiVideoDecodeAccelerator::TryOutputSurface() {
189 DCHECK_EQ(message_loop_, base::MessageLoop::current()); 382 DCHECK_EQ(message_loop_, base::MessageLoop::current());
190 383
191 // Handle Destroy() arriving while pictures are queued for output. 384 // Handle Destroy() arriving while pictures are queued for output.
192 if (!client_) 385 if (!client_)
193 return; 386 return;
194 387
195 if (pending_output_cbs_.empty() || output_buffers_.empty()) 388 if (pending_output_cbs_.empty() || output_buffers_.empty())
196 return; 389 return;
197 390
198 OutputCB output_cb = pending_output_cbs_.front(); 391 OutputCB output_cb = pending_output_cbs_.front();
199 pending_output_cbs_.pop(); 392 pending_output_cbs_.pop();
200 393
201 VaapiPicture* picture = PictureById(output_buffers_.front()); 394 TFPPicture* tfp_picture = TFPPictureById(output_buffers_.front());
202 DCHECK(picture); 395 DCHECK(tfp_picture);
203 output_buffers_.pop(); 396 output_buffers_.pop();
204 397
205 output_cb.Run(picture); 398 output_cb.Run(tfp_picture);
206 399
207 if (finish_flush_pending_ && pending_output_cbs_.empty()) 400 if (finish_flush_pending_ && pending_output_cbs_.empty())
208 FinishFlush(); 401 FinishFlush();
209 } 402 }
210 403
211 void VaapiVideoDecodeAccelerator::MapAndQueueNewInputBuffer( 404 void VaapiVideoDecodeAccelerator::MapAndQueueNewInputBuffer(
212 const media::BitstreamBuffer& bitstream_buffer) { 405 const media::BitstreamBuffer& bitstream_buffer) {
213 DCHECK_EQ(message_loop_, base::MessageLoop::current()); 406 DCHECK_EQ(message_loop_, base::MessageLoop::current());
214 TRACE_EVENT1("Video Decoder", "MapAndQueueNewInputBuffer", "input_id", 407 TRACE_EVENT1("Video Decoder", "MapAndQueueNewInputBuffer", "input_id",
215 bitstream_buffer.id()); 408 bitstream_buffer.id());
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 while (available_va_surfaces_.empty() && 499 while (available_va_surfaces_.empty() &&
307 (state_ == kDecoding || state_ == kFlushing || state_ == kIdle)) { 500 (state_ == kDecoding || state_ == kFlushing || state_ == kIdle)) {
308 surfaces_available_.Wait(); 501 surfaces_available_.Wait();
309 } 502 }
310 503
311 if (state_ != kDecoding && state_ != kFlushing && state_ != kIdle) 504 if (state_ != kDecoding && state_ != kFlushing && state_ != kIdle)
312 return false; 505 return false;
313 506
314 while (!available_va_surfaces_.empty()) { 507 while (!available_va_surfaces_.empty()) {
315 scoped_refptr<VASurface> va_surface( 508 scoped_refptr<VASurface> va_surface(
316 new VASurface(available_va_surfaces_.front(), requested_pic_size_, 509 new VASurface(available_va_surfaces_.front(), va_surface_release_cb_));
317 va_surface_release_cb_));
318 available_va_surfaces_.pop_front(); 510 available_va_surfaces_.pop_front();
319 decoder_->ReuseSurface(va_surface); 511 decoder_->ReuseSurface(va_surface);
320 } 512 }
321 513
322 return true; 514 return true;
323 } 515 }
324 516
325 void VaapiVideoDecodeAccelerator::DecodeTask() { 517 void VaapiVideoDecodeAccelerator::DecodeTask() {
326 DCHECK(decoder_thread_proxy_->BelongsToCurrentThread()); 518 DCHECK(decoder_thread_proxy_->BelongsToCurrentThread());
327 TRACE_EVENT0("Video Decoder", "VAVDA::DecodeTask"); 519 TRACE_EVENT0("Video Decoder", "VAVDA::DecodeTask");
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 TryFinishSurfaceSetChange(); 591 TryFinishSurfaceSetChange();
400 } 592 }
401 593
402 void VaapiVideoDecodeAccelerator::TryFinishSurfaceSetChange() { 594 void VaapiVideoDecodeAccelerator::TryFinishSurfaceSetChange() {
403 DCHECK_EQ(message_loop_, base::MessageLoop::current()); 595 DCHECK_EQ(message_loop_, base::MessageLoop::current());
404 596
405 if (!awaiting_va_surfaces_recycle_) 597 if (!awaiting_va_surfaces_recycle_)
406 return; 598 return;
407 599
408 if (!pending_output_cbs_.empty() || 600 if (!pending_output_cbs_.empty() ||
409 pictures_.size() != available_va_surfaces_.size()) { 601 tfp_pictures_.size() != available_va_surfaces_.size()) {
410 // Either: 602 // Either:
411 // 1. Not all pending pending output callbacks have been executed yet. 603 // 1. Not all pending pending output callbacks have been executed yet.
412 // Wait for the client to return enough pictures and retry later. 604 // Wait for the client to return enough pictures and retry later.
413 // 2. The above happened and all surface release callbacks have been posted 605 // 2. The above happened and all surface release callbacks have been posted
414 // as the result, but not all have executed yet. Post ourselves after them 606 // as the result, but not all have executed yet. Post ourselves after them
415 // to let them release surfaces. 607 // to let them release surfaces.
416 DVLOG(2) << "Awaiting pending output/surface release callbacks to finish"; 608 DVLOG(2) << "Awaiting pending output/surface release callbacks to finish";
417 message_loop_->PostTask(FROM_HERE, base::Bind( 609 message_loop_->PostTask(FROM_HERE, base::Bind(
418 &VaapiVideoDecodeAccelerator::TryFinishSurfaceSetChange, weak_this_)); 610 &VaapiVideoDecodeAccelerator::TryFinishSurfaceSetChange, weak_this_));
419 return; 611 return;
420 } 612 }
421 613
422 // All surfaces released, destroy them and dismiss all PictureBuffers. 614 // All surfaces released, destroy them and dismiss all PictureBuffers.
423 awaiting_va_surfaces_recycle_ = false; 615 awaiting_va_surfaces_recycle_ = false;
424 available_va_surfaces_.clear(); 616 available_va_surfaces_.clear();
425 vaapi_wrapper_->DestroySurfaces(); 617 vaapi_wrapper_->DestroySurfaces();
426 618
427 for (Pictures::iterator iter = pictures_.begin(); iter != pictures_.end(); 619 for (TFPPictures::iterator iter = tfp_pictures_.begin();
428 ++iter) { 620 iter != tfp_pictures_.end(); ++iter) {
429 DVLOG(2) << "Dismissing picture id: " << iter->first; 621 DVLOG(2) << "Dismissing picture id: " << iter->first;
430 if (client_) 622 if (client_)
431 client_->DismissPictureBuffer(iter->first); 623 client_->DismissPictureBuffer(iter->first);
432 } 624 }
433 pictures_.clear(); 625 tfp_pictures_.clear();
434 626
435 // And ask for a new set as requested. 627 // And ask for a new set as requested.
436 DVLOG(1) << "Requesting " << requested_num_pics_ << " pictures of size: " 628 DVLOG(1) << "Requesting " << requested_num_pics_ << " pictures of size: "
437 << requested_pic_size_.ToString(); 629 << requested_pic_size_.ToString();
438 630
439 message_loop_->PostTask( 631 message_loop_->PostTask(FROM_HERE, base::Bind(
440 FROM_HERE, 632 &Client::ProvidePictureBuffers, client_,
441 base::Bind(&Client::ProvidePictureBuffers, client_, requested_num_pics_, 633 requested_num_pics_, requested_pic_size_, GL_TEXTURE_2D));
442 requested_pic_size_, VaapiPicture::GetGLTextureTarget()));
443 } 634 }
444 635
445 void VaapiVideoDecodeAccelerator::Decode( 636 void VaapiVideoDecodeAccelerator::Decode(
446 const media::BitstreamBuffer& bitstream_buffer) { 637 const media::BitstreamBuffer& bitstream_buffer) {
447 DCHECK_EQ(message_loop_, base::MessageLoop::current()); 638 DCHECK_EQ(message_loop_, base::MessageLoop::current());
448 639
449 TRACE_EVENT1("Video Decoder", "VAVDA::Decode", "Buffer id", 640 TRACE_EVENT1("Video Decoder", "VAVDA::Decode", "Buffer id",
450 bitstream_buffer.id()); 641 bitstream_buffer.id());
451 642
452 // We got a new input buffer from the client, map it and queue for later use. 643 // We got a new input buffer from the client, map it and queue for later use.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 675
485 available_va_surfaces_.push_back(va_surface_id); 676 available_va_surfaces_.push_back(va_surface_id);
486 surfaces_available_.Signal(); 677 surfaces_available_.Signal();
487 } 678 }
488 679
489 void VaapiVideoDecodeAccelerator::AssignPictureBuffers( 680 void VaapiVideoDecodeAccelerator::AssignPictureBuffers(
490 const std::vector<media::PictureBuffer>& buffers) { 681 const std::vector<media::PictureBuffer>& buffers) {
491 DCHECK_EQ(message_loop_, base::MessageLoop::current()); 682 DCHECK_EQ(message_loop_, base::MessageLoop::current());
492 683
493 base::AutoLock auto_lock(lock_); 684 base::AutoLock auto_lock(lock_);
494 DCHECK(pictures_.empty()); 685 DCHECK(tfp_pictures_.empty());
495 686
496 while (!output_buffers_.empty()) 687 while (!output_buffers_.empty())
497 output_buffers_.pop(); 688 output_buffers_.pop();
498 689
499 RETURN_AND_NOTIFY_ON_FAILURE( 690 RETURN_AND_NOTIFY_ON_FAILURE(
500 buffers.size() == requested_num_pics_, 691 buffers.size() == requested_num_pics_,
501 "Got an invalid number of picture buffers. (Got " << buffers.size() 692 "Got an invalid number of picture buffers. (Got " << buffers.size()
502 << ", requested " << requested_num_pics_ << ")", INVALID_ARGUMENT, ); 693 << ", requested " << requested_num_pics_ << ")", INVALID_ARGUMENT, );
503 DCHECK(requested_pic_size_ == buffers[0].size()); 694 DCHECK(requested_pic_size_ == buffers[0].size());
504 695
505 std::vector<VASurfaceID> va_surface_ids; 696 std::vector<VASurfaceID> va_surface_ids;
506 RETURN_AND_NOTIFY_ON_FAILURE( 697 RETURN_AND_NOTIFY_ON_FAILURE(
507 vaapi_wrapper_->CreateSurfaces(requested_pic_size_, 698 vaapi_wrapper_->CreateSurfaces(requested_pic_size_,
508 buffers.size(), 699 buffers.size(),
509 &va_surface_ids), 700 &va_surface_ids),
510 "Failed creating VA Surfaces", PLATFORM_FAILURE, ); 701 "Failed creating VA Surfaces", PLATFORM_FAILURE, );
511 DCHECK_EQ(va_surface_ids.size(), buffers.size()); 702 DCHECK_EQ(va_surface_ids.size(), buffers.size());
512 703
513 for (size_t i = 0; i < buffers.size(); ++i) { 704 for (size_t i = 0; i < buffers.size(); ++i) {
514 DVLOG(2) << "Assigning picture id: " << buffers[i].id() 705 DVLOG(2) << "Assigning picture id: " << buffers[i].id()
515 << " to texture id: " << buffers[i].texture_id() 706 << " to texture id: " << buffers[i].texture_id()
516 << " VASurfaceID: " << va_surface_ids[i]; 707 << " VASurfaceID: " << va_surface_ids[i];
517 708
518 linked_ptr<VaapiPicture> picture(VaapiPicture::CreatePicture( 709 linked_ptr<TFPPicture> tfp_picture(
519 vaapi_wrapper_, make_context_current_, buffers[i].id(), 710 TFPPicture::Create(make_context_current_, fb_config_, x_display_,
520 buffers[i].texture_id(), requested_pic_size_)); 711 buffers[i].id(), buffers[i].texture_id(),
712 requested_pic_size_));
521 713
522 RETURN_AND_NOTIFY_ON_FAILURE( 714 RETURN_AND_NOTIFY_ON_FAILURE(
523 picture.get(), "Failed assigning picture buffer to a texture.", 715 tfp_picture.get(), "Failed assigning picture buffer to a texture.",
524 PLATFORM_FAILURE, ); 716 PLATFORM_FAILURE, );
525 717
526 bool inserted = 718 bool inserted = tfp_pictures_.insert(std::make_pair(
527 pictures_.insert(std::make_pair(buffers[i].id(), picture)).second; 719 buffers[i].id(), tfp_picture)).second;
528 DCHECK(inserted); 720 DCHECK(inserted);
529 721
530 output_buffers_.push(buffers[i].id()); 722 output_buffers_.push(buffers[i].id());
531 available_va_surfaces_.push_back(va_surface_ids[i]); 723 available_va_surfaces_.push_back(va_surface_ids[i]);
532 surfaces_available_.Signal(); 724 surfaces_available_.Signal();
533 } 725 }
534 726
535 state_ = kDecoding; 727 state_ = kDecoding;
536 decoder_thread_proxy_->PostTask(FROM_HERE, base::Bind( 728 decoder_thread_proxy_->PostTask(FROM_HERE, base::Bind(
537 &VaapiVideoDecodeAccelerator::DecodeTask, base::Unretained(this))); 729 &VaapiVideoDecodeAccelerator::DecodeTask, base::Unretained(this)));
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
725 DCHECK_EQ(message_loop_, base::MessageLoop::current()); 917 DCHECK_EQ(message_loop_, base::MessageLoop::current());
726 Cleanup(); 918 Cleanup();
727 delete this; 919 delete this;
728 } 920 }
729 921
730 bool VaapiVideoDecodeAccelerator::CanDecodeOnIOThread() { 922 bool VaapiVideoDecodeAccelerator::CanDecodeOnIOThread() {
731 return false; 923 return false;
732 } 924 }
733 925
734 } // namespace content 926 } // namespace content
OLDNEW
« no previous file with comments | « content/common/gpu/media/vaapi_video_decode_accelerator.h ('k') | content/common/gpu/media/vaapi_video_encode_accelerator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698