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" |
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" | |
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 |
28 namespace content { | 27 namespace content { |
(...skipping 25 matching lines...) Expand all Loading... | |
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 LOG(ERROR) << "Notifying of error " << error; | 56 LOG(ERROR) << "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 VaapiPicture* VaapiVideoDecodeAccelerator::PictureById( |
65 // in PictureBuffers from clients to them. TFPPictures are created as | 64 int32 picture_buffer_id) { |
66 // a consequence of receiving a set of PictureBuffers from clients and released | 65 Pictures::iterator it = pictures_.find(picture_buffer_id); |
67 // at the end of decode (or when a new set of PictureBuffers is required). | 66 if (it == pictures_.end()) { |
68 // | |
69 // TFPPictures are used for output, contents of VASurfaces passed from decoder | |
70 // are put into the associated pixmap memory and sent to client. | |
71 class VaapiVideoDecodeAccelerator::TFPPicture : public base::NonThreadSafe { | |
72 public: | |
73 ~TFPPicture(); | |
74 | |
75 static linked_ptr<TFPPicture> Create( | |
76 const base::Callback<bool(void)>& make_context_current, | |
77 const GLXFBConfig& fb_config, | |
78 Display* x_display, | |
79 int32 picture_buffer_id, | |
80 uint32 texture_id, | |
81 gfx::Size size); | |
82 | |
83 int32 picture_buffer_id() { | |
84 return picture_buffer_id_; | |
85 } | |
86 | |
87 gfx::Size size() { | |
88 return size_; | |
89 } | |
90 | |
91 int x_pixmap() { | |
92 return x_pixmap_; | |
93 } | |
94 | |
95 // Bind texture to pixmap. Needs to be called every frame. | |
96 bool Bind(); | |
97 | |
98 private: | |
99 TFPPicture(const base::Callback<bool(void)>& make_context_current, | |
100 Display* x_display, | |
101 int32 picture_buffer_id, | |
102 uint32 texture_id, | |
103 gfx::Size size); | |
104 | |
105 bool Initialize(const GLXFBConfig& fb_config); | |
106 | |
107 base::Callback<bool(void)> make_context_current_; | |
108 | |
109 Display* x_display_; | |
110 | |
111 // Output id for the client. | |
112 int32 picture_buffer_id_; | |
113 uint32 texture_id_; | |
114 | |
115 gfx::Size size_; | |
116 | |
117 // Pixmaps bound to this texture. | |
118 Pixmap x_pixmap_; | |
119 GLXPixmap glx_pixmap_; | |
120 | |
121 DISALLOW_COPY_AND_ASSIGN(TFPPicture); | |
122 }; | |
123 | |
124 VaapiVideoDecodeAccelerator::TFPPicture::TFPPicture( | |
125 const base::Callback<bool(void)>& make_context_current, | |
126 Display* x_display, | |
127 int32 picture_buffer_id, | |
128 uint32 texture_id, | |
129 gfx::Size size) | |
130 : make_context_current_(make_context_current), | |
131 x_display_(x_display), | |
132 picture_buffer_id_(picture_buffer_id), | |
133 texture_id_(texture_id), | |
134 size_(size), | |
135 x_pixmap_(0), | |
136 glx_pixmap_(0) { | |
137 DCHECK(!make_context_current_.is_null()); | |
138 }; | |
139 | |
140 linked_ptr<VaapiVideoDecodeAccelerator::TFPPicture> | |
141 VaapiVideoDecodeAccelerator::TFPPicture::Create( | |
142 const base::Callback<bool(void)>& make_context_current, | |
143 const GLXFBConfig& fb_config, | |
144 Display* x_display, | |
145 int32 picture_buffer_id, | |
146 uint32 texture_id, | |
147 gfx::Size size) { | |
148 | |
149 linked_ptr<TFPPicture> tfp_picture( | |
150 new TFPPicture(make_context_current, x_display, picture_buffer_id, | |
151 texture_id, size)); | |
152 | |
153 if (!tfp_picture->Initialize(fb_config)) | |
154 tfp_picture.reset(); | |
155 | |
156 return tfp_picture; | |
157 } | |
158 | |
159 bool VaapiVideoDecodeAccelerator::TFPPicture::Initialize( | |
160 const GLXFBConfig& fb_config) { | |
161 DCHECK(CalledOnValidThread()); | |
162 if (!make_context_current_.Run()) | |
163 return false; | |
164 | |
165 XWindowAttributes win_attr; | |
166 int screen = DefaultScreen(x_display_); | |
167 XGetWindowAttributes(x_display_, RootWindow(x_display_, screen), &win_attr); | |
168 //TODO(posciak): pass the depth required by libva, not the RootWindow's depth | |
169 x_pixmap_ = XCreatePixmap(x_display_, RootWindow(x_display_, screen), | |
170 size_.width(), size_.height(), win_attr.depth); | |
171 if (!x_pixmap_) { | |
172 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()) { | |
222 LOG(ERROR) << "Picture id " << picture_buffer_id << " does not exist"; | 67 LOG(ERROR) << "Picture id " << picture_buffer_id << " does not exist"; |
223 return NULL; | 68 return NULL; |
224 } | 69 } |
225 | 70 |
226 return it->second.get(); | 71 return it->second.get(); |
227 } | 72 } |
228 | 73 |
229 VaapiVideoDecodeAccelerator::VaapiVideoDecodeAccelerator( | 74 VaapiVideoDecodeAccelerator::VaapiVideoDecodeAccelerator( |
230 Display* x_display, | 75 gfx::GLContext* gl_context, |
231 const base::Callback<bool(void)>& make_context_current) | 76 const base::Callback<bool(void)>& make_context_current) |
232 : x_display_(x_display), | 77 : gl_context_(gl_context), |
233 make_context_current_(make_context_current), | 78 make_context_current_(make_context_current), |
234 state_(kUninitialized), | 79 state_(kUninitialized), |
235 input_ready_(&lock_), | 80 input_ready_(&lock_), |
236 surfaces_available_(&lock_), | 81 surfaces_available_(&lock_), |
237 message_loop_(base::MessageLoop::current()), | 82 message_loop_(base::MessageLoop::current()), |
238 decoder_thread_("VaapiDecoderThread"), | 83 decoder_thread_("VaapiDecoderThread"), |
239 num_frames_at_client_(0), | 84 num_frames_at_client_(0), |
240 num_stream_bufs_at_decoder_(0), | 85 num_stream_bufs_at_decoder_(0), |
241 finish_flush_pending_(false), | 86 finish_flush_pending_(false), |
242 awaiting_va_surfaces_recycle_(false), | 87 awaiting_va_surfaces_recycle_(false), |
243 requested_num_pics_(0), | 88 requested_num_pics_(0), |
244 weak_this_factory_(this) { | 89 weak_this_factory_(this) { |
245 weak_this_ = weak_this_factory_.GetWeakPtr(); | 90 weak_this_ = weak_this_factory_.GetWeakPtr(); |
246 va_surface_release_cb_ = media::BindToCurrentLoop( | 91 va_surface_release_cb_ = media::BindToCurrentLoop( |
247 base::Bind(&VaapiVideoDecodeAccelerator::RecycleVASurfaceID, weak_this_)); | 92 base::Bind(&VaapiVideoDecodeAccelerator::RecycleVASurfaceID, weak_this_)); |
248 } | 93 } |
249 | 94 |
250 VaapiVideoDecodeAccelerator::~VaapiVideoDecodeAccelerator() { | 95 VaapiVideoDecodeAccelerator::~VaapiVideoDecodeAccelerator() { |
251 DCHECK_EQ(message_loop_, base::MessageLoop::current()); | 96 DCHECK_EQ(message_loop_, base::MessageLoop::current()); |
252 } | |
253 | 97 |
254 class XFreeDeleter { | 98 // The dispose order matters on X11. When using vaPutSurface(), |
255 public: | 99 // LibVA keeps DRI2 references to the passed pixmaps |
256 void operator()(void* x) const { | 100 // (http://cgit.freedesktop.org/libva/tree/va/x11/va_dri2.c#n212). |
257 ::XFree(x); | 101 // These references are destroyed when we call vaTerminate(), this |
Pawel Osciak
2014/11/12 05:52:58
Could you identify the calls that destroy them? Co
llandwerlin-old
2014/11/12 18:04:43
LibVA maintains a hash table of X-Pixmap -> DRI2Dr
marcheu
2014/11/14 19:35:47
I don't think I agree. A DRIDrawable is basically
llandwerlin-old
2014/11/15 00:15:39
From what I can see in the DRI2 protocol, there ar
marcheu
2014/11/15 04:23:59
Ah I understand now, thanks for the explanation. S
| |
258 } | 102 // means we need to terminate LibVA before with calling |
259 }; | 103 // XFreePixmap() on the pixmaps passed to vaPutSurface(), otherwise |
260 | 104 // LibVA will generate BadDrawable errors. |
261 bool VaapiVideoDecodeAccelerator::InitializeFBConfig() { | 105 // |
262 const int fbconfig_attr[] = { | 106 // On the hand on DRM, output pictures need to destroy their |
263 GLX_DRAWABLE_TYPE, GLX_PIXMAP_BIT, | 107 // VASurface wrapper before we terminate LibVA. |
264 GLX_BIND_TO_TEXTURE_TARGETS_EXT, GLX_TEXTURE_2D_BIT_EXT, | 108 // |
265 GLX_BIND_TO_TEXTURE_RGB_EXT, GL_TRUE, | 109 // We have a 3 steps destruction sequence, first we ask pictures to |
266 GLX_Y_INVERTED_EXT, GL_TRUE, | 110 // release their references to LibVA objects, then we terminate |
267 GL_NONE, | 111 // LibVA by destroying the VaapiWrapper and finally we destroy the |
268 }; | 112 // pixmaps. |
269 | 113 for (Pictures::iterator iter = pictures_.begin(); iter != pictures_.end(); |
270 int num_fbconfigs; | 114 ++iter) |
271 scoped_ptr<GLXFBConfig, XFreeDeleter> glx_fb_configs( | 115 iter->second->DisposeVaapi(); |
272 glXChooseFBConfig(x_display_, DefaultScreen(x_display_), fbconfig_attr, | 116 vaapi_wrapper_.reset(); |
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 } | 117 } |
282 | 118 |
283 bool VaapiVideoDecodeAccelerator::Initialize(media::VideoCodecProfile profile, | 119 bool VaapiVideoDecodeAccelerator::Initialize(media::VideoCodecProfile profile, |
284 Client* client) { | 120 Client* client) { |
285 DCHECK_EQ(message_loop_, base::MessageLoop::current()); | 121 DCHECK_EQ(message_loop_, base::MessageLoop::current()); |
286 | 122 |
287 client_ptr_factory_.reset(new base::WeakPtrFactory<Client>(client)); | 123 client_ptr_factory_.reset(new base::WeakPtrFactory<Client>(client)); |
288 client_ = client_ptr_factory_->GetWeakPtr(); | 124 client_ = client_ptr_factory_->GetWeakPtr(); |
289 | 125 |
290 base::AutoLock auto_lock(lock_); | 126 base::AutoLock auto_lock(lock_); |
291 DCHECK_EQ(state_, kUninitialized); | 127 DCHECK_EQ(state_, kUninitialized); |
292 DVLOG(2) << "Initializing VAVDA, profile: " << profile; | 128 DVLOG(2) << "Initializing VAVDA, profile: " << profile; |
293 | 129 |
294 if (!make_context_current_.Run()) | 130 #if defined(USE_X11) |
295 return false; | 131 if (gfx::GetGLImplementation() != gfx::kGLImplementationDesktopGL) { |
296 | 132 DVLOG(1) << "HW video decode acceleration not available without " |
297 if (!InitializeFBConfig()) { | 133 "DesktopGL (GLX)."; |
298 LOG(ERROR) << "Could not get a usable FBConfig"; | |
299 return false; | 134 return false; |
300 } | 135 } |
136 #else | |
137 if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) { | |
138 DVLOG(1) << "HW video decode acceleration not available without " | |
139 "EGLGLES2."; | |
140 return false; | |
141 } | |
142 #endif // USE_X11 | |
301 | 143 |
302 vaapi_wrapper_ = VaapiWrapper::Create( | 144 vaapi_wrapper_ = VaapiWrapper::Create( |
303 VaapiWrapper::kDecode, | 145 VaapiWrapper::kDecode, |
304 profile, | 146 profile, |
305 x_display_, | |
306 base::Bind(&ReportToUMA, content::VaapiH264Decoder::VAAPI_ERROR)); | 147 base::Bind(&ReportToUMA, content::VaapiH264Decoder::VAAPI_ERROR)); |
307 | 148 |
308 if (!vaapi_wrapper_.get()) { | 149 if (!vaapi_wrapper_.get()) { |
309 LOG(ERROR) << "Failed initializing VAAPI"; | 150 LOG(ERROR) << "Failed initializing VAAPI"; |
310 return false; | 151 return false; |
311 } | 152 } |
312 | 153 |
313 decoder_.reset( | 154 decoder_.reset( |
314 new VaapiH264Decoder( | 155 new VaapiH264Decoder( |
315 vaapi_wrapper_.get(), | 156 vaapi_wrapper_.get(), |
(...skipping 21 matching lines...) Expand all Loading... | |
337 pending_output_cbs_.push( | 178 pending_output_cbs_.push( |
338 base::Bind(&VaapiVideoDecodeAccelerator::OutputPicture, | 179 base::Bind(&VaapiVideoDecodeAccelerator::OutputPicture, |
339 weak_this_, va_surface, input_id)); | 180 weak_this_, va_surface, input_id)); |
340 | 181 |
341 TryOutputSurface(); | 182 TryOutputSurface(); |
342 } | 183 } |
343 | 184 |
344 void VaapiVideoDecodeAccelerator::OutputPicture( | 185 void VaapiVideoDecodeAccelerator::OutputPicture( |
345 const scoped_refptr<VASurface>& va_surface, | 186 const scoped_refptr<VASurface>& va_surface, |
346 int32 input_id, | 187 int32 input_id, |
347 TFPPicture* tfp_picture) { | 188 VaapiPicture* picture) { |
348 DCHECK_EQ(message_loop_, base::MessageLoop::current()); | 189 DCHECK_EQ(message_loop_, base::MessageLoop::current()); |
349 | 190 |
350 int32 output_id = tfp_picture->picture_buffer_id(); | 191 int32 output_id = picture->picture_buffer_id(); |
351 | 192 |
352 TRACE_EVENT2("Video Decoder", "VAVDA::OutputSurface", | 193 TRACE_EVENT2("Video Decoder", "VAVDA::OutputSurface", |
353 "input_id", input_id, | 194 "input_id", input_id, |
354 "output_id", output_id); | 195 "output_id", output_id); |
355 | 196 |
356 DVLOG(3) << "Outputting VASurface " << va_surface->id() | 197 DVLOG(3) << "Outputting VASurface " << va_surface->id() |
357 << " into pixmap bound to picture buffer id " << output_id; | 198 << " into pixmap bound to picture buffer id " << output_id; |
358 | 199 |
359 RETURN_AND_NOTIFY_ON_FAILURE(tfp_picture->Bind(), | 200 RETURN_AND_NOTIFY_ON_FAILURE(picture->DownloadFromSurface(va_surface), |
360 "Failed binding texture to pixmap", | 201 "Failed putting surface into pixmap", |
361 PLATFORM_FAILURE, ); | 202 PLATFORM_FAILURE, ); |
362 | 203 |
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. | 204 // Notify the client a picture is ready to be displayed. |
370 ++num_frames_at_client_; | 205 ++num_frames_at_client_; |
371 TRACE_COUNTER1("Video Decoder", "Textures at client", num_frames_at_client_); | 206 TRACE_COUNTER1("Video Decoder", "Textures at client", num_frames_at_client_); |
372 DVLOG(4) << "Notifying output picture id " << output_id | 207 DVLOG(4) << "Notifying output picture id " << output_id |
373 << " for input "<< input_id << " is ready"; | 208 << " for input "<< input_id << " is ready"; |
374 // TODO(posciak): Use visible size from decoder here instead | 209 // TODO(posciak): Use visible size from decoder here instead |
375 // (crbug.com/402760). | 210 // (crbug.com/402760). |
376 if (client_) | 211 if (client_) |
377 client_->PictureReady( | 212 client_->PictureReady( |
378 media::Picture(output_id, input_id, gfx::Rect(tfp_picture->size()))); | 213 media::Picture(output_id, input_id, gfx::Rect(picture->size()))); |
379 } | 214 } |
380 | 215 |
381 void VaapiVideoDecodeAccelerator::TryOutputSurface() { | 216 void VaapiVideoDecodeAccelerator::TryOutputSurface() { |
382 DCHECK_EQ(message_loop_, base::MessageLoop::current()); | 217 DCHECK_EQ(message_loop_, base::MessageLoop::current()); |
383 | 218 |
384 // Handle Destroy() arriving while pictures are queued for output. | 219 // Handle Destroy() arriving while pictures are queued for output. |
385 if (!client_) | 220 if (!client_) |
386 return; | 221 return; |
387 | 222 |
388 if (pending_output_cbs_.empty() || output_buffers_.empty()) | 223 if (pending_output_cbs_.empty() || output_buffers_.empty()) |
389 return; | 224 return; |
390 | 225 |
391 OutputCB output_cb = pending_output_cbs_.front(); | 226 OutputCB output_cb = pending_output_cbs_.front(); |
392 pending_output_cbs_.pop(); | 227 pending_output_cbs_.pop(); |
393 | 228 |
394 TFPPicture* tfp_picture = TFPPictureById(output_buffers_.front()); | 229 VaapiPicture* picture = PictureById(output_buffers_.front()); |
395 DCHECK(tfp_picture); | 230 DCHECK(picture); |
396 output_buffers_.pop(); | 231 output_buffers_.pop(); |
397 | 232 |
398 output_cb.Run(tfp_picture); | 233 output_cb.Run(picture); |
399 | 234 |
400 if (finish_flush_pending_ && pending_output_cbs_.empty()) | 235 if (finish_flush_pending_ && pending_output_cbs_.empty()) |
401 FinishFlush(); | 236 FinishFlush(); |
402 } | 237 } |
403 | 238 |
404 void VaapiVideoDecodeAccelerator::MapAndQueueNewInputBuffer( | 239 void VaapiVideoDecodeAccelerator::MapAndQueueNewInputBuffer( |
405 const media::BitstreamBuffer& bitstream_buffer) { | 240 const media::BitstreamBuffer& bitstream_buffer) { |
406 DCHECK_EQ(message_loop_, base::MessageLoop::current()); | 241 DCHECK_EQ(message_loop_, base::MessageLoop::current()); |
407 TRACE_EVENT1("Video Decoder", "MapAndQueueNewInputBuffer", "input_id", | 242 TRACE_EVENT1("Video Decoder", "MapAndQueueNewInputBuffer", "input_id", |
408 bitstream_buffer.id()); | 243 bitstream_buffer.id()); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
499 while (available_va_surfaces_.empty() && | 334 while (available_va_surfaces_.empty() && |
500 (state_ == kDecoding || state_ == kFlushing || state_ == kIdle)) { | 335 (state_ == kDecoding || state_ == kFlushing || state_ == kIdle)) { |
501 surfaces_available_.Wait(); | 336 surfaces_available_.Wait(); |
502 } | 337 } |
503 | 338 |
504 if (state_ != kDecoding && state_ != kFlushing && state_ != kIdle) | 339 if (state_ != kDecoding && state_ != kFlushing && state_ != kIdle) |
505 return false; | 340 return false; |
506 | 341 |
507 while (!available_va_surfaces_.empty()) { | 342 while (!available_va_surfaces_.empty()) { |
508 scoped_refptr<VASurface> va_surface( | 343 scoped_refptr<VASurface> va_surface( |
509 new VASurface(available_va_surfaces_.front(), va_surface_release_cb_)); | 344 new VASurface(available_va_surfaces_.front(), |
345 requested_pic_size_, | |
346 va_surface_release_cb_)); | |
510 available_va_surfaces_.pop_front(); | 347 available_va_surfaces_.pop_front(); |
511 decoder_->ReuseSurface(va_surface); | 348 decoder_->ReuseSurface(va_surface); |
512 } | 349 } |
513 | 350 |
514 return true; | 351 return true; |
515 } | 352 } |
516 | 353 |
517 void VaapiVideoDecodeAccelerator::DecodeTask() { | 354 void VaapiVideoDecodeAccelerator::DecodeTask() { |
518 DCHECK(decoder_thread_proxy_->BelongsToCurrentThread()); | 355 DCHECK(decoder_thread_proxy_->BelongsToCurrentThread()); |
519 TRACE_EVENT0("Video Decoder", "VAVDA::DecodeTask"); | 356 TRACE_EVENT0("Video Decoder", "VAVDA::DecodeTask"); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
591 TryFinishSurfaceSetChange(); | 428 TryFinishSurfaceSetChange(); |
592 } | 429 } |
593 | 430 |
594 void VaapiVideoDecodeAccelerator::TryFinishSurfaceSetChange() { | 431 void VaapiVideoDecodeAccelerator::TryFinishSurfaceSetChange() { |
595 DCHECK_EQ(message_loop_, base::MessageLoop::current()); | 432 DCHECK_EQ(message_loop_, base::MessageLoop::current()); |
596 | 433 |
597 if (!awaiting_va_surfaces_recycle_) | 434 if (!awaiting_va_surfaces_recycle_) |
598 return; | 435 return; |
599 | 436 |
600 if (!pending_output_cbs_.empty() || | 437 if (!pending_output_cbs_.empty() || |
601 tfp_pictures_.size() != available_va_surfaces_.size()) { | 438 pictures_.size() != available_va_surfaces_.size()) { |
602 // Either: | 439 // Either: |
603 // 1. Not all pending pending output callbacks have been executed yet. | 440 // 1. Not all pending pending output callbacks have been executed yet. |
604 // Wait for the client to return enough pictures and retry later. | 441 // Wait for the client to return enough pictures and retry later. |
605 // 2. The above happened and all surface release callbacks have been posted | 442 // 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 | 443 // as the result, but not all have executed yet. Post ourselves after them |
607 // to let them release surfaces. | 444 // to let them release surfaces. |
608 DVLOG(2) << "Awaiting pending output/surface release callbacks to finish"; | 445 DVLOG(2) << "Awaiting pending output/surface release callbacks to finish"; |
609 message_loop_->PostTask(FROM_HERE, base::Bind( | 446 message_loop_->PostTask(FROM_HERE, base::Bind( |
610 &VaapiVideoDecodeAccelerator::TryFinishSurfaceSetChange, weak_this_)); | 447 &VaapiVideoDecodeAccelerator::TryFinishSurfaceSetChange, weak_this_)); |
611 return; | 448 return; |
612 } | 449 } |
613 | 450 |
614 // All surfaces released, destroy them and dismiss all PictureBuffers. | 451 // All surfaces released, destroy them and dismiss all PictureBuffers. |
615 awaiting_va_surfaces_recycle_ = false; | 452 awaiting_va_surfaces_recycle_ = false; |
616 available_va_surfaces_.clear(); | 453 available_va_surfaces_.clear(); |
617 vaapi_wrapper_->DestroySurfaces(); | 454 vaapi_wrapper_->DestroySurfaces(); |
618 | 455 |
619 for (TFPPictures::iterator iter = tfp_pictures_.begin(); | 456 for (Pictures::iterator iter = pictures_.begin(); iter != pictures_.end(); |
620 iter != tfp_pictures_.end(); ++iter) { | 457 ++iter) { |
621 DVLOG(2) << "Dismissing picture id: " << iter->first; | 458 DVLOG(2) << "Dismissing picture id: " << iter->first; |
622 if (client_) | 459 if (client_) |
623 client_->DismissPictureBuffer(iter->first); | 460 client_->DismissPictureBuffer(iter->first); |
624 } | 461 } |
625 tfp_pictures_.clear(); | 462 pictures_.clear(); |
626 | 463 |
627 // And ask for a new set as requested. | 464 // And ask for a new set as requested. |
628 DVLOG(1) << "Requesting " << requested_num_pics_ << " pictures of size: " | 465 DVLOG(1) << "Requesting " << requested_num_pics_ << " pictures of size: " |
629 << requested_pic_size_.ToString(); | 466 << requested_pic_size_.ToString(); |
630 | 467 |
631 message_loop_->PostTask(FROM_HERE, base::Bind( | 468 message_loop_->PostTask(FROM_HERE, base::Bind( |
632 &Client::ProvidePictureBuffers, client_, | 469 &Client::ProvidePictureBuffers, client_, |
633 requested_num_pics_, requested_pic_size_, GL_TEXTURE_2D)); | 470 requested_num_pics_, requested_pic_size_, |
471 VaapiPicture::GetGLTextureTarget())); | |
634 } | 472 } |
635 | 473 |
636 void VaapiVideoDecodeAccelerator::Decode( | 474 void VaapiVideoDecodeAccelerator::Decode( |
637 const media::BitstreamBuffer& bitstream_buffer) { | 475 const media::BitstreamBuffer& bitstream_buffer) { |
638 DCHECK_EQ(message_loop_, base::MessageLoop::current()); | 476 DCHECK_EQ(message_loop_, base::MessageLoop::current()); |
639 | 477 |
640 TRACE_EVENT1("Video Decoder", "VAVDA::Decode", "Buffer id", | 478 TRACE_EVENT1("Video Decoder", "VAVDA::Decode", "Buffer id", |
641 bitstream_buffer.id()); | 479 bitstream_buffer.id()); |
642 | 480 |
643 // We got a new input buffer from the client, map it and queue for later use. | 481 // 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 Loading... | |
675 | 513 |
676 available_va_surfaces_.push_back(va_surface_id); | 514 available_va_surfaces_.push_back(va_surface_id); |
677 surfaces_available_.Signal(); | 515 surfaces_available_.Signal(); |
678 } | 516 } |
679 | 517 |
680 void VaapiVideoDecodeAccelerator::AssignPictureBuffers( | 518 void VaapiVideoDecodeAccelerator::AssignPictureBuffers( |
681 const std::vector<media::PictureBuffer>& buffers) { | 519 const std::vector<media::PictureBuffer>& buffers) { |
682 DCHECK_EQ(message_loop_, base::MessageLoop::current()); | 520 DCHECK_EQ(message_loop_, base::MessageLoop::current()); |
683 | 521 |
684 base::AutoLock auto_lock(lock_); | 522 base::AutoLock auto_lock(lock_); |
685 DCHECK(tfp_pictures_.empty()); | 523 DCHECK(pictures_.empty()); |
686 | 524 |
687 while (!output_buffers_.empty()) | 525 while (!output_buffers_.empty()) |
688 output_buffers_.pop(); | 526 output_buffers_.pop(); |
689 | 527 |
690 RETURN_AND_NOTIFY_ON_FAILURE( | 528 RETURN_AND_NOTIFY_ON_FAILURE( |
691 buffers.size() == requested_num_pics_, | 529 buffers.size() == requested_num_pics_, |
692 "Got an invalid number of picture buffers. (Got " << buffers.size() | 530 "Got an invalid number of picture buffers. (Got " << buffers.size() |
693 << ", requested " << requested_num_pics_ << ")", INVALID_ARGUMENT, ); | 531 << ", requested " << requested_num_pics_ << ")", INVALID_ARGUMENT, ); |
694 DCHECK(requested_pic_size_ == buffers[0].size()); | 532 DCHECK(requested_pic_size_ == buffers[0].size()); |
695 | 533 |
696 std::vector<VASurfaceID> va_surface_ids; | 534 std::vector<VASurfaceID> va_surface_ids; |
697 RETURN_AND_NOTIFY_ON_FAILURE( | 535 RETURN_AND_NOTIFY_ON_FAILURE( |
698 vaapi_wrapper_->CreateSurfaces(requested_pic_size_, | 536 vaapi_wrapper_->CreateSurfaces(requested_pic_size_, |
699 buffers.size(), | 537 buffers.size(), |
700 &va_surface_ids), | 538 &va_surface_ids), |
701 "Failed creating VA Surfaces", PLATFORM_FAILURE, ); | 539 "Failed creating VA Surfaces", PLATFORM_FAILURE, ); |
702 DCHECK_EQ(va_surface_ids.size(), buffers.size()); | 540 DCHECK_EQ(va_surface_ids.size(), buffers.size()); |
703 | 541 |
704 for (size_t i = 0; i < buffers.size(); ++i) { | 542 for (size_t i = 0; i < buffers.size(); ++i) { |
705 DVLOG(2) << "Assigning picture id: " << buffers[i].id() | 543 DVLOG(2) << "Assigning picture id: " << buffers[i].id() |
706 << " to texture id: " << buffers[i].texture_id() | 544 << " to texture id: " << buffers[i].texture_id() |
707 << " VASurfaceID: " << va_surface_ids[i]; | 545 << " VASurfaceID: " << va_surface_ids[i]; |
708 | 546 |
709 linked_ptr<TFPPicture> tfp_picture( | 547 linked_ptr<VaapiPicture> picture( |
710 TFPPicture::Create(make_context_current_, fb_config_, x_display_, | 548 vaapi_wrapper_->CreatePicture(gl_context_, |
711 buffers[i].id(), buffers[i].texture_id(), | 549 make_context_current_, |
712 requested_pic_size_)); | 550 buffers[i].id(), |
551 buffers[i].texture_id(), | |
552 requested_pic_size_)); | |
713 | 553 |
714 RETURN_AND_NOTIFY_ON_FAILURE( | 554 RETURN_AND_NOTIFY_ON_FAILURE( |
715 tfp_picture.get(), "Failed assigning picture buffer to a texture.", | 555 picture.get(), |
556 "Failed assigning picture buffer to a texture.", | |
716 PLATFORM_FAILURE, ); | 557 PLATFORM_FAILURE, ); |
717 | 558 |
718 bool inserted = tfp_pictures_.insert(std::make_pair( | 559 bool inserted = |
719 buffers[i].id(), tfp_picture)).second; | 560 pictures_.insert(std::make_pair(buffers[i].id(), picture)).second; |
720 DCHECK(inserted); | 561 DCHECK(inserted); |
721 | 562 |
722 output_buffers_.push(buffers[i].id()); | 563 output_buffers_.push(buffers[i].id()); |
723 available_va_surfaces_.push_back(va_surface_ids[i]); | 564 available_va_surfaces_.push_back(va_surface_ids[i]); |
724 surfaces_available_.Signal(); | 565 surfaces_available_.Signal(); |
725 } | 566 } |
726 | 567 |
727 state_ = kDecoding; | 568 state_ = kDecoding; |
728 decoder_thread_proxy_->PostTask(FROM_HERE, base::Bind( | 569 decoder_thread_proxy_->PostTask(FROM_HERE, base::Bind( |
729 &VaapiVideoDecodeAccelerator::DecodeTask, base::Unretained(this))); | 570 &VaapiVideoDecodeAccelerator::DecodeTask, base::Unretained(this))); |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
917 DCHECK_EQ(message_loop_, base::MessageLoop::current()); | 758 DCHECK_EQ(message_loop_, base::MessageLoop::current()); |
918 Cleanup(); | 759 Cleanup(); |
919 delete this; | 760 delete this; |
920 } | 761 } |
921 | 762 |
922 bool VaapiVideoDecodeAccelerator::CanDecodeOnIOThread() { | 763 bool VaapiVideoDecodeAccelerator::CanDecodeOnIOThread() { |
923 return false; | 764 return false; |
924 } | 765 } |
925 | 766 |
926 } // namespace content | 767 } // namespace content |
OLD | NEW |