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 "content/common/gpu/media/gpu_video_decode_accelerator.h" | 5 #include "content/common/gpu/media/gpu_video_decode_accelerator.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 14 matching lines...) Expand all Loading... | |
25 | 25 |
26 #if defined(OS_WIN) | 26 #if defined(OS_WIN) |
27 #include "base/win/windows_version.h" | 27 #include "base/win/windows_version.h" |
28 #include "content/common/gpu/media/dxva_video_decode_accelerator.h" | 28 #include "content/common/gpu/media/dxva_video_decode_accelerator.h" |
29 #elif defined(OS_MACOSX) | 29 #elif defined(OS_MACOSX) |
30 #include "content/common/gpu/media/vt_video_decode_accelerator.h" | 30 #include "content/common/gpu/media/vt_video_decode_accelerator.h" |
31 #elif defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL) && defined(USE_X11) | 31 #elif defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL) && defined(USE_X11) |
32 #include "content/common/gpu/media/v4l2_video_decode_accelerator.h" | 32 #include "content/common/gpu/media/v4l2_video_decode_accelerator.h" |
33 #include "content/common/gpu/media/v4l2_video_device.h" | 33 #include "content/common/gpu/media/v4l2_video_device.h" |
34 #elif defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) && defined(USE_X11) | 34 #elif defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) && defined(USE_X11) |
35 #include "content/common/gpu/media/v4l2_video_decode_accelerator.h" | |
36 #include "content/common/gpu/media/v4l2_video_device.h" | |
35 #include "content/common/gpu/media/vaapi_video_decode_accelerator.h" | 37 #include "content/common/gpu/media/vaapi_video_decode_accelerator.h" |
36 #include "ui/gl/gl_context_glx.h" | 38 #include "ui/gl/gl_context_glx.h" |
37 #include "ui/gl/gl_implementation.h" | 39 #include "ui/gl/gl_implementation.h" |
38 #elif defined(USE_OZONE) | 40 #elif defined(USE_OZONE) |
39 #include "media/ozone/media_ozone_platform.h" | 41 #include "media/ozone/media_ozone_platform.h" |
40 #elif defined(OS_ANDROID) | 42 #elif defined(OS_ANDROID) |
41 #include "content/common/gpu/media/android_video_decode_accelerator.h" | 43 #include "content/common/gpu/media/android_video_decode_accelerator.h" |
42 #endif | 44 #endif |
43 | 45 |
44 #include "ui/gfx/size.h" | 46 #include "ui/gfx/size.h" |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
238 | 240 |
239 #if !defined(OS_WIN) | 241 #if !defined(OS_WIN) |
240 // Ensure we will be able to get a GL context at all before initializing | 242 // Ensure we will be able to get a GL context at all before initializing |
241 // non-Windows VDAs. | 243 // non-Windows VDAs. |
242 if (!make_context_current_.Run()) { | 244 if (!make_context_current_.Run()) { |
243 SendCreateDecoderReply(init_done_msg, false); | 245 SendCreateDecoderReply(init_done_msg, false); |
244 return; | 246 return; |
245 } | 247 } |
246 #endif | 248 #endif |
247 | 249 |
248 #if defined(OS_WIN) | 250 std::vector<GpuVideoDecodeAccelerator::CreateVDACb> |
249 if (base::win::GetVersion() < base::win::VERSION_WIN7) { | 251 create_vda_cbs = CreateDecoderCbs(); |
250 NOTIMPLEMENTED() << "HW video decode acceleration not available."; | |
251 SendCreateDecoderReply(init_done_msg, false); | |
252 return; | |
253 } | |
254 DVLOG(0) << "Initializing DXVA HW decoder for windows."; | |
255 video_decode_accelerator_.reset( | |
256 new DXVAVideoDecodeAccelerator(make_context_current_)); | |
257 #elif defined(OS_MACOSX) | |
258 video_decode_accelerator_.reset(new VTVideoDecodeAccelerator( | |
259 static_cast<CGLContextObj>( | |
260 stub_->decoder()->GetGLContext()->GetHandle()), | |
261 make_context_current_)); | |
262 #elif defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL) && defined(USE_X11) | |
263 scoped_ptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kDecoder); | |
264 if (!device.get()) { | |
265 SendCreateDecoderReply(init_done_msg, false); | |
266 return; | |
267 } | |
268 video_decode_accelerator_.reset(new V4L2VideoDecodeAccelerator( | |
269 gfx::GLSurfaceEGL::GetHardwareDisplay(), | |
270 stub_->decoder()->GetGLContext()->GetHandle(), | |
271 weak_factory_for_io_.GetWeakPtr(), | |
272 make_context_current_, | |
273 device.Pass(), | |
274 io_message_loop_)); | |
275 #elif defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) && defined(USE_X11) | |
276 if (gfx::GetGLImplementation() != gfx::kGLImplementationDesktopGL) { | |
277 VLOG(1) << "HW video decode acceleration not available without " | |
278 "DesktopGL (GLX)."; | |
279 SendCreateDecoderReply(init_done_msg, false); | |
280 return; | |
281 } | |
282 gfx::GLContextGLX* glx_context = | |
283 static_cast<gfx::GLContextGLX*>(stub_->decoder()->GetGLContext()); | |
284 video_decode_accelerator_.reset(new VaapiVideoDecodeAccelerator( | |
285 glx_context->display(), make_context_current_)); | |
286 #elif defined(USE_OZONE) | |
287 media::MediaOzonePlatform* platform = | |
288 media::MediaOzonePlatform::GetInstance(); | |
289 video_decode_accelerator_.reset(platform->CreateVideoDecodeAccelerator( | |
290 make_context_current_)); | |
291 if (!video_decode_accelerator_) { | |
292 SendCreateDecoderReply(init_done_msg, false); | |
293 return; | |
294 } | |
295 #elif defined(OS_ANDROID) | |
296 video_decode_accelerator_.reset(new AndroidVideoDecodeAccelerator( | |
297 stub_->decoder()->AsWeakPtr(), | |
298 make_context_current_)); | |
299 #else | |
300 NOTIMPLEMENTED() << "HW video decode acceleration not available."; | |
301 SendCreateDecoderReply(init_done_msg, false); | |
302 return; | |
303 #endif | |
304 | 252 |
305 if (video_decode_accelerator_->CanDecodeOnIOThread()) { | 253 if (create_vda_cbs.empty()) { |
Pawel Osciak
2014/12/31 07:55:59
I think not needed, since the for loop will not do
henryhsu
2014/12/31 08:47:53
Done.
| |
306 filter_ = new MessageFilter(this, host_route_id_); | |
307 stub_->channel()->AddFilter(filter_.get()); | |
308 } | |
309 | |
310 if (!video_decode_accelerator_->Initialize(profile, this)) { | |
311 SendCreateDecoderReply(init_done_msg, false); | 254 SendCreateDecoderReply(init_done_msg, false); |
312 return; | 255 return; |
313 } | 256 } |
314 | 257 |
315 SendCreateDecoderReply(init_done_msg, true); | 258 for (size_t i = 0; i < create_vda_cbs.size(); ++i) { |
259 video_decode_accelerator_ = create_vda_cbs[i].Run(); | |
260 if (!video_decode_accelerator_.get() || | |
Pawel Osciak
2014/12/31 07:55:59
IIRC, we don't need get()s on scoped_ptr?
henryhsu
2014/12/31 08:47:53
yes. We don't need. This references other codes in
Pawel Osciak
2015/01/02 01:49:14
Not sure if we need this kind of consistency ;)
Bu
| |
261 !video_decode_accelerator_->Initialize(profile, this)) | |
262 continue; | |
263 | |
264 if (video_decode_accelerator_->CanDecodeOnIOThread()) { | |
265 filter_ = new MessageFilter(this, host_route_id_); | |
266 stub_->channel()->AddFilter(filter_.get()); | |
267 } | |
268 SendCreateDecoderReply(init_done_msg, true); | |
269 return; | |
270 } | |
271 video_decode_accelerator_.reset(); | |
272 SendCreateDecoderReply(init_done_msg, false); | |
273 } | |
274 | |
275 std::vector<GpuVideoDecodeAccelerator::CreateVDACb> | |
276 GpuVideoDecodeAccelerator::CreateDecoderCbs() { | |
277 std::vector<GpuVideoDecodeAccelerator::CreateVDACb> create_vda_cbs; | |
278 #if defined(OS_WIN) | |
Pawel Osciak
2014/12/31 07:55:59
Technically, we don't need all the #ifs here. The
henryhsu
2014/12/31 08:47:53
Sure. Then we will have many callback functions wi
| |
279 create_vda_cbs.push_back(base::Bind( | |
280 &GpuVideoDecodeAccelerator::CreateDXVADecoder, base::Unretained(this))); | |
281 #elif defined(OS_CHROMEOS) && defined(USE_X11) && \ | |
282 (defined(ARCH_CPU_X86_FAMILY) || defined(ARCH_CPU_ARMEL)) | |
283 create_vda_cbs.push_back(base::Bind( | |
284 &GpuVideoDecodeAccelerator::CreateV4L2Decoder, base::Unretained(this))); | |
285 #if defined(ARCH_CPU_X86_FAMILY) | |
286 create_vda_cbs.push_back(base::Bind( | |
287 &GpuVideoDecodeAccelerator::CreateVaapiDecoder, base::Unretained(this))); | |
288 #endif | |
289 #elif defined(OS_MACOSX) | |
290 create_vda_cbs.push_back(base::Bind( | |
291 &GpuVideoDecodeAccelerator::CreateVTDecoder, base::Unretained(this))); | |
292 #elif defined(OS_ANDROID) | |
293 create_vda_cbs.push_back(base::Bind( | |
294 &GpuVideoDecodeAccelerator::CreateAndroidDecoder, | |
295 base::Unretained(this))); | |
296 #elif defined(USE_OZONE) | |
297 create_vda_cbs.push_back(base::Bind( | |
298 &GpuVideoDecodeAccelerator::CreateOzoneDecoder, base::Unretained(this))); | |
299 #else | |
300 NOTIMPLEMENTED() << "HW video decode acceleration not available."; | |
301 #endif | |
302 return create_vda_cbs; | |
303 } | |
304 | |
305 scoped_ptr<media::VideoDecodeAccelerator> | |
306 GpuVideoDecodeAccelerator::CreateDXVADecoder() { | |
307 scoped_ptr<media::VideoDecodeAccelerator> decoder; | |
308 #if defined(OS_WIN) | |
309 if (base::win::GetVersion() >= base::win::VERSION_WIN7) { | |
310 DVLOG(0) << "Initializing DXVA HW decoder for windows."; | |
311 decoder.reset(new DXVAVideoDecodeAccelerator(make_context_current_)); | |
312 } else | |
Pawel Osciak
2014/12/31 07:55:59
Per coding style both branches need a brace if one
henryhsu
2014/12/31 08:47:53
Done.
| |
313 NOTIMPLEMENTED() << "HW video decode acceleration not available."; | |
314 #endif | |
315 return decoder.Pass(); | |
316 } | |
317 | |
318 scoped_ptr<media::VideoDecodeAccelerator> | |
319 GpuVideoDecodeAccelerator::CreateV4L2Decoder() { | |
320 scoped_ptr<media::VideoDecodeAccelerator> decoder; | |
321 #if defined(OS_CHROMEOS) && defined(USE_X11) && \ | |
322 (defined(ARCH_CPU_X86_FAMILY) || defined(ARCH_CPU_ARMEL)) | |
323 scoped_ptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kDecoder); | |
324 if (device.get()) { | |
325 decoder.reset(new V4L2VideoDecodeAccelerator( | |
326 gfx::GLSurfaceEGL::GetHardwareDisplay(), | |
327 stub_->decoder()->GetGLContext()->GetHandle(), | |
328 weak_factory_for_io_.GetWeakPtr(), | |
329 make_context_current_, | |
330 device.Pass(), | |
331 io_message_loop_)); | |
332 } | |
333 #endif | |
334 return decoder.Pass(); | |
335 } | |
336 | |
337 scoped_ptr<media::VideoDecodeAccelerator> | |
338 GpuVideoDecodeAccelerator::CreateVaapiDecoder() { | |
339 scoped_ptr<media::VideoDecodeAccelerator> decoder; | |
340 #if defined(OS_CHROMEOS) && defined(USE_X11) && defined(ARCH_CPU_X86_FAMILY) | |
341 if (gfx::GetGLImplementation() != gfx::kGLImplementationDesktopGL) { | |
342 VLOG(1) << "HW video decode acceleration not available without " | |
343 "DesktopGL (GLX)."; | |
344 return decoder.Pass(); | |
345 } | |
346 gfx::GLContextGLX* glx_context = | |
347 static_cast<gfx::GLContextGLX*>(stub_->decoder()->GetGLContext()); | |
348 decoder.reset(new VaapiVideoDecodeAccelerator( | |
349 glx_context->display(), make_context_current_)); | |
350 #endif | |
351 return decoder.Pass(); | |
352 } | |
353 | |
354 scoped_ptr<media::VideoDecodeAccelerator> | |
355 GpuVideoDecodeAccelerator::CreateVTDecoder() { | |
356 scoped_ptr<media::VideoDecodeAccelerator> decoder; | |
357 #if defined(OS_MACOSX) | |
358 decoder.reset(new VTVideoDecodeAccelerator( | |
359 static_cast<CGLContextObj>(stub_->decoder()->GetGLContext()->GetHandle()), | |
360 make_context_current_)); | |
361 #endif | |
362 return decoder.Pass(); | |
363 } | |
364 | |
365 scoped_ptr<media::VideoDecodeAccelerator> | |
366 GpuVideoDecodeAccelerator::CreateAndroidDecoder() { | |
367 scoped_ptr<media::VideoDecodeAccelerator> decoder; | |
368 #if defined(OS_ANDROID) | |
369 decoder.reset(new AndroidVideoDecodeAccelerator( | |
370 stub_->decoder()->AsWeakPtr(), | |
371 make_context_current_)); | |
372 #endif | |
373 return decoder.Pass(); | |
374 } | |
375 | |
376 scoped_ptr<media::VideoDecodeAccelerator> | |
377 GpuVideoDecodeAccelerator::CreateOzoneDecoder() { | |
378 scoped_ptr<media::VideoDecodeAccelerator> decoder; | |
379 #if defined(USE_OZONE) | |
380 media::MediaOzonePlatform* platform = | |
381 media::MediaOzonePlatform::GetInstance(); | |
382 decoder.reset(platform->CreateVideoDecodeAccelerator(make_context_current_)); | |
383 #endif | |
384 return decoder.Pass(); | |
316 } | 385 } |
317 | 386 |
318 // Runs on IO thread if video_decode_accelerator_->CanDecodeOnIOThread() is | 387 // Runs on IO thread if video_decode_accelerator_->CanDecodeOnIOThread() is |
319 // true, otherwise on the main thread. | 388 // true, otherwise on the main thread. |
320 void GpuVideoDecodeAccelerator::OnDecode( | 389 void GpuVideoDecodeAccelerator::OnDecode( |
321 base::SharedMemoryHandle handle, int32 id, uint32 size) { | 390 base::SharedMemoryHandle handle, int32 id, uint32 size) { |
322 DCHECK(video_decode_accelerator_.get()); | 391 DCHECK(video_decode_accelerator_.get()); |
323 if (id < 0) { | 392 if (id < 0) { |
324 DLOG(ERROR) << "BitstreamBuffer id " << id << " out of range"; | 393 DLOG(ERROR) << "BitstreamBuffer id " << id << " out of range"; |
325 if (child_message_loop_->BelongsToCurrentThread()) { | 394 if (child_message_loop_->BelongsToCurrentThread()) { |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
514 return stub_->channel()->Send(message); | 583 return stub_->channel()->Send(message); |
515 } | 584 } |
516 | 585 |
517 void GpuVideoDecodeAccelerator::SendCreateDecoderReply(IPC::Message* message, | 586 void GpuVideoDecodeAccelerator::SendCreateDecoderReply(IPC::Message* message, |
518 bool succeeded) { | 587 bool succeeded) { |
519 GpuCommandBufferMsg_CreateVideoDecoder::WriteReplyParams(message, succeeded); | 588 GpuCommandBufferMsg_CreateVideoDecoder::WriteReplyParams(message, succeeded); |
520 Send(message); | 589 Send(message); |
521 } | 590 } |
522 | 591 |
523 } // namespace content | 592 } // namespace content |
OLD | NEW |