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 VaapiPictureProvider::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 VaapiPictureProvider::Picture* picture = pictures_.get(picture_buffer_id); |
67 // at the end of decode (or when a new set of PictureBuffers is required). | 65 return picture; |
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"; | |
223 return NULL; | |
224 } | |
225 | |
226 return it->second.get(); | |
227 } | 66 } |
228 | 67 |
229 VaapiVideoDecodeAccelerator::VaapiVideoDecodeAccelerator( | 68 VaapiVideoDecodeAccelerator::VaapiVideoDecodeAccelerator( |
230 Display* x_display, | 69 gfx::GLContext* gl_context, |
231 const base::Callback<bool(void)>& make_context_current) | 70 const base::Callback<bool(void)>& make_context_current) |
232 : x_display_(x_display), | 71 : gl_context_(gl_context), |
233 make_context_current_(make_context_current), | 72 make_context_current_(make_context_current), |
234 state_(kUninitialized), | 73 state_(kUninitialized), |
235 input_ready_(&lock_), | 74 input_ready_(&lock_), |
236 surfaces_available_(&lock_), | 75 surfaces_available_(&lock_), |
237 message_loop_(base::MessageLoop::current()), | 76 message_loop_(base::MessageLoop::current()), |
238 decoder_thread_("VaapiDecoderThread"), | 77 decoder_thread_("VaapiDecoderThread"), |
239 num_frames_at_client_(0), | 78 num_frames_at_client_(0), |
240 num_stream_bufs_at_decoder_(0), | 79 num_stream_bufs_at_decoder_(0), |
241 finish_flush_pending_(false), | 80 finish_flush_pending_(false), |
242 awaiting_va_surfaces_recycle_(false), | 81 awaiting_va_surfaces_recycle_(false), |
243 requested_num_pics_(0), | 82 requested_num_pics_(0), |
244 weak_this_factory_(this) { | 83 weak_this_factory_(this) { |
245 weak_this_ = weak_this_factory_.GetWeakPtr(); | 84 weak_this_ = weak_this_factory_.GetWeakPtr(); |
246 va_surface_release_cb_ = media::BindToCurrentLoop( | 85 va_surface_release_cb_ = media::BindToCurrentLoop( |
247 base::Bind(&VaapiVideoDecodeAccelerator::RecycleVASurfaceID, weak_this_)); | 86 base::Bind(&VaapiVideoDecodeAccelerator::RecycleVASurfaceID, weak_this_)); |
248 } | 87 } |
249 | 88 |
250 VaapiVideoDecodeAccelerator::~VaapiVideoDecodeAccelerator() { | 89 VaapiVideoDecodeAccelerator::~VaapiVideoDecodeAccelerator() { |
251 DCHECK_EQ(message_loop_, base::MessageLoop::current()); | 90 DCHECK_EQ(message_loop_, base::MessageLoop::current()); |
252 } | 91 // Make sure pictures are destroyed before VaapiWrapper is, so the |
Pawel Osciak
2014/10/08 08:17:22
If we keep a refcount to the wrapper in provider,
llandwerlin-old
2014/10/08 09:31:18
We can either use refcounting or move the pictures
Pawel Osciak
2014/10/26 13:06:46
Refcounting of course; now we have a ref to wrappe
llandwerlin-old
2014/10/29 13:52:47
Acknowledged.
| |
253 | 92 // VADisplay they contain is still valid. |
254 class XFreeDeleter { | 93 pictures_.clear(); |
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 } | 94 } |
282 | 95 |
283 bool VaapiVideoDecodeAccelerator::Initialize(media::VideoCodecProfile profile, | 96 bool VaapiVideoDecodeAccelerator::Initialize(media::VideoCodecProfile profile, |
284 Client* client) { | 97 Client* client) { |
285 DCHECK_EQ(message_loop_, base::MessageLoop::current()); | 98 DCHECK_EQ(message_loop_, base::MessageLoop::current()); |
286 | 99 |
287 client_ptr_factory_.reset(new base::WeakPtrFactory<Client>(client)); | 100 client_ptr_factory_.reset(new base::WeakPtrFactory<Client>(client)); |
288 client_ = client_ptr_factory_->GetWeakPtr(); | 101 client_ = client_ptr_factory_->GetWeakPtr(); |
289 | 102 |
290 base::AutoLock auto_lock(lock_); | 103 base::AutoLock auto_lock(lock_); |
291 DCHECK_EQ(state_, kUninitialized); | 104 DCHECK_EQ(state_, kUninitialized); |
292 DVLOG(2) << "Initializing VAVDA, profile: " << profile; | 105 DVLOG(2) << "Initializing VAVDA, profile: " << profile; |
293 | 106 |
294 if (!make_context_current_.Run()) | 107 #if defined(USE_X11) |
295 return false; | 108 if (gfx::GetGLImplementation() != gfx::kGLImplementationDesktopGL) { |
296 | 109 DVLOG(1) << "HW video decode acceleration not available without " |
297 if (!InitializeFBConfig()) { | 110 "DesktopGL (GLX)."; |
298 DVLOG(1) << "Could not get a usable FBConfig"; | |
299 return false; | 111 return false; |
300 } | 112 } |
113 #else | |
114 if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) { | |
115 DVLOG(1) << "HW video decode acceleration not available without " | |
116 "EGLGLES2."; | |
117 return false; | |
118 } | |
119 #endif // USE_X11 | |
301 | 120 |
302 vaapi_wrapper_ = VaapiWrapper::Create( | 121 vaapi_wrapper_ = VaapiWrapper::Create( |
303 VaapiWrapper::kDecode, | 122 VaapiWrapper::kDecode, |
304 profile, | 123 profile, |
305 x_display_, | |
306 base::Bind(&ReportToUMA, content::VaapiH264Decoder::VAAPI_ERROR)); | 124 base::Bind(&ReportToUMA, content::VaapiH264Decoder::VAAPI_ERROR)); |
307 | 125 |
308 if (!vaapi_wrapper_.get()) { | 126 if (!vaapi_wrapper_.get()) { |
309 DVLOG(1) << "Failed initializing VAAPI"; | 127 DVLOG(1) << "Failed initializing VAAPI"; |
310 return false; | 128 return false; |
311 } | 129 } |
312 | 130 |
131 vaapi_picture_provider_ = VaapiPictureProvider::Create( | |
132 vaapi_wrapper_->GetDisplay(), gl_context_, make_context_current_); | |
133 | |
134 if (!vaapi_picture_provider_.get()) { | |
135 DVLOG(1) << "Failed initializing VAAPI Picture Provider"; | |
136 return false; | |
137 } | |
138 | |
313 decoder_.reset( | 139 decoder_.reset( |
314 new VaapiH264Decoder( | 140 new VaapiH264Decoder( |
315 vaapi_wrapper_.get(), | 141 vaapi_wrapper_.get(), |
316 media::BindToCurrentLoop(base::Bind( | 142 media::BindToCurrentLoop(base::Bind( |
317 &VaapiVideoDecodeAccelerator::SurfaceReady, weak_this_)), | 143 &VaapiVideoDecodeAccelerator::SurfaceReady, weak_this_)), |
318 base::Bind(&ReportToUMA))); | 144 base::Bind(&ReportToUMA))); |
319 | 145 |
320 CHECK(decoder_thread_.Start()); | 146 CHECK(decoder_thread_.Start()); |
321 decoder_thread_proxy_ = decoder_thread_.message_loop_proxy(); | 147 decoder_thread_proxy_ = decoder_thread_.message_loop_proxy(); |
322 | 148 |
(...skipping 14 matching lines...) Expand all Loading... | |
337 pending_output_cbs_.push( | 163 pending_output_cbs_.push( |
338 base::Bind(&VaapiVideoDecodeAccelerator::OutputPicture, | 164 base::Bind(&VaapiVideoDecodeAccelerator::OutputPicture, |
339 weak_this_, va_surface, input_id)); | 165 weak_this_, va_surface, input_id)); |
340 | 166 |
341 TryOutputSurface(); | 167 TryOutputSurface(); |
342 } | 168 } |
343 | 169 |
344 void VaapiVideoDecodeAccelerator::OutputPicture( | 170 void VaapiVideoDecodeAccelerator::OutputPicture( |
345 const scoped_refptr<VASurface>& va_surface, | 171 const scoped_refptr<VASurface>& va_surface, |
346 int32 input_id, | 172 int32 input_id, |
347 TFPPicture* tfp_picture) { | 173 VaapiPictureProvider::Picture* picture) { |
348 DCHECK_EQ(message_loop_, base::MessageLoop::current()); | 174 DCHECK_EQ(message_loop_, base::MessageLoop::current()); |
349 | 175 |
350 int32 output_id = tfp_picture->picture_buffer_id(); | 176 int32 output_id = picture->picture_buffer_id(); |
351 | 177 |
352 TRACE_EVENT2("Video Decoder", "VAVDA::OutputSurface", | 178 TRACE_EVENT2("Video Decoder", "VAVDA::OutputSurface", |
353 "input_id", input_id, | 179 "input_id", input_id, |
354 "output_id", output_id); | 180 "output_id", output_id); |
355 | 181 |
356 DVLOG(3) << "Outputting VASurface " << va_surface->id() | 182 DVLOG(3) << "Outputting VASurface " << va_surface->id() |
357 << " into pixmap bound to picture buffer id " << output_id; | 183 << " into pixmap bound to picture buffer id " << output_id; |
358 | 184 |
359 RETURN_AND_NOTIFY_ON_FAILURE(tfp_picture->Bind(), | 185 RETURN_AND_NOTIFY_ON_FAILURE(picture->PutSurface(va_surface->id()), |
360 "Failed binding texture to pixmap", | 186 "Failed putting surface into pixmap", |
361 PLATFORM_FAILURE, ); | 187 PLATFORM_FAILURE, ); |
362 | 188 |
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 | |
369 // Notify the client a picture is ready to be displayed. | 189 // Notify the client a picture is ready to be displayed. |
370 ++num_frames_at_client_; | 190 ++num_frames_at_client_; |
371 TRACE_COUNTER1("Video Decoder", "Textures at client", num_frames_at_client_); | 191 TRACE_COUNTER1("Video Decoder", "Textures at client", num_frames_at_client_); |
372 DVLOG(4) << "Notifying output picture id " << output_id | 192 DVLOG(4) << "Notifying output picture id " << output_id |
373 << " for input "<< input_id << " is ready"; | 193 << " for input "<< input_id << " is ready"; |
374 // TODO(posciak): Use visible size from decoder here instead | 194 // TODO(posciak): Use visible size from decoder here instead |
375 // (crbug.com/402760). | 195 // (crbug.com/402760). |
376 if (client_) | 196 if (client_) |
377 client_->PictureReady( | 197 client_->PictureReady( |
378 media::Picture(output_id, input_id, gfx::Rect(tfp_picture->size()))); | 198 media::Picture(output_id, input_id, gfx::Rect(picture->size()))); |
379 } | 199 } |
380 | 200 |
381 void VaapiVideoDecodeAccelerator::TryOutputSurface() { | 201 void VaapiVideoDecodeAccelerator::TryOutputSurface() { |
382 DCHECK_EQ(message_loop_, base::MessageLoop::current()); | 202 DCHECK_EQ(message_loop_, base::MessageLoop::current()); |
383 | 203 |
384 // Handle Destroy() arriving while pictures are queued for output. | 204 // Handle Destroy() arriving while pictures are queued for output. |
385 if (!client_) | 205 if (!client_) |
386 return; | 206 return; |
387 | 207 |
388 if (pending_output_cbs_.empty() || output_buffers_.empty()) | 208 if (pending_output_cbs_.empty() || output_buffers_.empty()) |
389 return; | 209 return; |
390 | 210 |
391 OutputCB output_cb = pending_output_cbs_.front(); | 211 OutputCB output_cb = pending_output_cbs_.front(); |
392 pending_output_cbs_.pop(); | 212 pending_output_cbs_.pop(); |
393 | 213 |
394 TFPPicture* tfp_picture = TFPPictureById(output_buffers_.front()); | 214 VaapiPictureProvider::Picture* picture = PictureById(output_buffers_.front()); |
395 DCHECK(tfp_picture); | 215 DCHECK(picture); |
396 output_buffers_.pop(); | 216 output_buffers_.pop(); |
397 | 217 |
398 output_cb.Run(tfp_picture); | 218 output_cb.Run(picture); |
399 | 219 |
400 if (finish_flush_pending_ && pending_output_cbs_.empty()) | 220 if (finish_flush_pending_ && pending_output_cbs_.empty()) |
401 FinishFlush(); | 221 FinishFlush(); |
402 } | 222 } |
403 | 223 |
404 void VaapiVideoDecodeAccelerator::MapAndQueueNewInputBuffer( | 224 void VaapiVideoDecodeAccelerator::MapAndQueueNewInputBuffer( |
405 const media::BitstreamBuffer& bitstream_buffer) { | 225 const media::BitstreamBuffer& bitstream_buffer) { |
406 DCHECK_EQ(message_loop_, base::MessageLoop::current()); | 226 DCHECK_EQ(message_loop_, base::MessageLoop::current()); |
407 TRACE_EVENT1("Video Decoder", "MapAndQueueNewInputBuffer", "input_id", | 227 TRACE_EVENT1("Video Decoder", "MapAndQueueNewInputBuffer", "input_id", |
408 bitstream_buffer.id()); | 228 bitstream_buffer.id()); |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
591 TryFinishSurfaceSetChange(); | 411 TryFinishSurfaceSetChange(); |
592 } | 412 } |
593 | 413 |
594 void VaapiVideoDecodeAccelerator::TryFinishSurfaceSetChange() { | 414 void VaapiVideoDecodeAccelerator::TryFinishSurfaceSetChange() { |
595 DCHECK_EQ(message_loop_, base::MessageLoop::current()); | 415 DCHECK_EQ(message_loop_, base::MessageLoop::current()); |
596 | 416 |
597 if (!awaiting_va_surfaces_recycle_) | 417 if (!awaiting_va_surfaces_recycle_) |
598 return; | 418 return; |
599 | 419 |
600 if (!pending_output_cbs_.empty() || | 420 if (!pending_output_cbs_.empty() || |
601 tfp_pictures_.size() != available_va_surfaces_.size()) { | 421 pictures_.size() != available_va_surfaces_.size()) { |
602 // Either: | 422 // Either: |
603 // 1. Not all pending pending output callbacks have been executed yet. | 423 // 1. Not all pending pending output callbacks have been executed yet. |
604 // Wait for the client to return enough pictures and retry later. | 424 // Wait for the client to return enough pictures and retry later. |
605 // 2. The above happened and all surface release callbacks have been posted | 425 // 2. The above happened and all surface release callbacks have been posted |
606 // as the result, but not all have executed yet. Post ourselves after them | 426 // as the result, but not all have executed yet. Post ourselves after them |
607 // to let them release surfaces. | 427 // to let them release surfaces. |
608 DVLOG(2) << "Awaiting pending output/surface release callbacks to finish"; | 428 DVLOG(2) << "Awaiting pending output/surface release callbacks to finish"; |
609 message_loop_->PostTask(FROM_HERE, base::Bind( | 429 message_loop_->PostTask(FROM_HERE, base::Bind( |
610 &VaapiVideoDecodeAccelerator::TryFinishSurfaceSetChange, weak_this_)); | 430 &VaapiVideoDecodeAccelerator::TryFinishSurfaceSetChange, weak_this_)); |
611 return; | 431 return; |
612 } | 432 } |
613 | 433 |
614 // All surfaces released, destroy them and dismiss all PictureBuffers. | 434 // All surfaces released, destroy them and dismiss all PictureBuffers. |
615 awaiting_va_surfaces_recycle_ = false; | 435 awaiting_va_surfaces_recycle_ = false; |
616 available_va_surfaces_.clear(); | 436 available_va_surfaces_.clear(); |
617 vaapi_wrapper_->DestroySurfaces(); | 437 vaapi_wrapper_->DestroySurfaces(); |
618 | 438 |
619 for (TFPPictures::iterator iter = tfp_pictures_.begin(); | 439 for (Pictures::iterator iter = pictures_.begin(); iter != pictures_.end(); |
620 iter != tfp_pictures_.end(); ++iter) { | 440 ++iter) { |
621 DVLOG(2) << "Dismissing picture id: " << iter->first; | 441 DVLOG(2) << "Dismissing picture id: " << iter->first; |
622 if (client_) | 442 if (client_) |
623 client_->DismissPictureBuffer(iter->first); | 443 client_->DismissPictureBuffer(iter->first); |
624 } | 444 } |
625 tfp_pictures_.clear(); | 445 pictures_.clear(); |
626 | 446 |
627 // And ask for a new set as requested. | 447 // And ask for a new set as requested. |
628 DVLOG(1) << "Requesting " << requested_num_pics_ << " pictures of size: " | 448 DVLOG(1) << "Requesting " << requested_num_pics_ << " pictures of size: " |
629 << requested_pic_size_.ToString(); | 449 << requested_pic_size_.ToString(); |
630 | 450 |
631 message_loop_->PostTask(FROM_HERE, base::Bind( | 451 message_loop_->PostTask(FROM_HERE, base::Bind( |
632 &Client::ProvidePictureBuffers, client_, | 452 &Client::ProvidePictureBuffers, client_, |
633 requested_num_pics_, requested_pic_size_, GL_TEXTURE_2D)); | 453 requested_num_pics_, requested_pic_size_, GL_TEXTURE_2D)); |
634 } | 454 } |
635 | 455 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
675 | 495 |
676 available_va_surfaces_.push_back(va_surface_id); | 496 available_va_surfaces_.push_back(va_surface_id); |
677 surfaces_available_.Signal(); | 497 surfaces_available_.Signal(); |
678 } | 498 } |
679 | 499 |
680 void VaapiVideoDecodeAccelerator::AssignPictureBuffers( | 500 void VaapiVideoDecodeAccelerator::AssignPictureBuffers( |
681 const std::vector<media::PictureBuffer>& buffers) { | 501 const std::vector<media::PictureBuffer>& buffers) { |
682 DCHECK_EQ(message_loop_, base::MessageLoop::current()); | 502 DCHECK_EQ(message_loop_, base::MessageLoop::current()); |
683 | 503 |
684 base::AutoLock auto_lock(lock_); | 504 base::AutoLock auto_lock(lock_); |
685 DCHECK(tfp_pictures_.empty()); | 505 DCHECK(pictures_.empty()); |
686 | 506 |
687 while (!output_buffers_.empty()) | 507 while (!output_buffers_.empty()) |
688 output_buffers_.pop(); | 508 output_buffers_.pop(); |
689 | 509 |
690 RETURN_AND_NOTIFY_ON_FAILURE( | 510 RETURN_AND_NOTIFY_ON_FAILURE( |
691 buffers.size() == requested_num_pics_, | 511 buffers.size() == requested_num_pics_, |
692 "Got an invalid number of picture buffers. (Got " << buffers.size() | 512 "Got an invalid number of picture buffers. (Got " << buffers.size() |
693 << ", requested " << requested_num_pics_ << ")", INVALID_ARGUMENT, ); | 513 << ", requested " << requested_num_pics_ << ")", INVALID_ARGUMENT, ); |
694 DCHECK(requested_pic_size_ == buffers[0].size()); | 514 DCHECK(requested_pic_size_ == buffers[0].size()); |
695 | 515 |
696 std::vector<VASurfaceID> va_surface_ids; | 516 std::vector<VASurfaceID> va_surface_ids; |
697 RETURN_AND_NOTIFY_ON_FAILURE( | 517 RETURN_AND_NOTIFY_ON_FAILURE( |
698 vaapi_wrapper_->CreateSurfaces(requested_pic_size_, | 518 vaapi_wrapper_->CreateSurfaces(requested_pic_size_, |
699 buffers.size(), | 519 buffers.size(), |
700 &va_surface_ids), | 520 &va_surface_ids), |
701 "Failed creating VA Surfaces", PLATFORM_FAILURE, ); | 521 "Failed creating VA Surfaces", PLATFORM_FAILURE, ); |
702 DCHECK_EQ(va_surface_ids.size(), buffers.size()); | 522 DCHECK_EQ(va_surface_ids.size(), buffers.size()); |
703 | 523 |
524 RETURN_AND_NOTIFY_ON_FAILURE( | |
525 vaapi_picture_provider_->SetCodedSurfacesSize(requested_pic_size_), | |
526 "Failed to update VA picture provider surface size", | |
527 PLATFORM_FAILURE, ); | |
528 | |
704 for (size_t i = 0; i < buffers.size(); ++i) { | 529 for (size_t i = 0; i < buffers.size(); ++i) { |
705 DVLOG(2) << "Assigning picture id: " << buffers[i].id() | 530 DVLOG(2) << "Assigning picture id: " << buffers[i].id() |
706 << " to texture id: " << buffers[i].texture_id() | 531 << " to texture id: " << buffers[i].texture_id() |
707 << " VASurfaceID: " << va_surface_ids[i]; | 532 << " VASurfaceID: " << va_surface_ids[i]; |
708 | 533 |
709 linked_ptr<TFPPicture> tfp_picture( | 534 scoped_ptr<VaapiPictureProvider::Picture> picture( |
710 TFPPicture::Create(make_context_current_, fb_config_, x_display_, | 535 vaapi_picture_provider_->CreatePicture( |
711 buffers[i].id(), buffers[i].texture_id(), | 536 buffers[i].id(), buffers[i].texture_id(), requested_pic_size_)); |
712 requested_pic_size_)); | |
713 | 537 |
714 RETURN_AND_NOTIFY_ON_FAILURE( | 538 RETURN_AND_NOTIFY_ON_FAILURE( |
715 tfp_picture.get(), "Failed assigning picture buffer to a texture.", | 539 picture.get(), |
540 "Failed assigning picture buffer to a texture.", | |
716 PLATFORM_FAILURE, ); | 541 PLATFORM_FAILURE, ); |
717 | 542 |
718 bool inserted = tfp_pictures_.insert(std::make_pair( | 543 DCHECK(!pictures_.contains(buffers[i].id())); |
719 buffers[i].id(), tfp_picture)).second; | 544 pictures_.set(buffers[i].id(), picture.Pass()); |
720 DCHECK(inserted); | |
721 | 545 |
722 output_buffers_.push(buffers[i].id()); | 546 output_buffers_.push(buffers[i].id()); |
723 available_va_surfaces_.push_back(va_surface_ids[i]); | 547 available_va_surfaces_.push_back(va_surface_ids[i]); |
724 surfaces_available_.Signal(); | 548 surfaces_available_.Signal(); |
725 } | 549 } |
726 | 550 |
727 state_ = kDecoding; | 551 state_ = kDecoding; |
728 decoder_thread_proxy_->PostTask(FROM_HERE, base::Bind( | 552 decoder_thread_proxy_->PostTask(FROM_HERE, base::Bind( |
729 &VaapiVideoDecodeAccelerator::DecodeTask, base::Unretained(this))); | 553 &VaapiVideoDecodeAccelerator::DecodeTask, base::Unretained(this))); |
730 } | 554 } |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
917 DCHECK_EQ(message_loop_, base::MessageLoop::current()); | 741 DCHECK_EQ(message_loop_, base::MessageLoop::current()); |
918 Cleanup(); | 742 Cleanup(); |
919 delete this; | 743 delete this; |
920 } | 744 } |
921 | 745 |
922 bool VaapiVideoDecodeAccelerator::CanDecodeOnIOThread() { | 746 bool VaapiVideoDecodeAccelerator::CanDecodeOnIOThread() { |
923 return false; | 747 return false; |
924 } | 748 } |
925 | 749 |
926 } // namespace content | 750 } // namespace content |
OLD | NEW |