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 10 matching lines...) Expand all Loading... |
21 #include "ipc/message_filter.h" | 21 #include "ipc/message_filter.h" |
22 #include "media/base/limits.h" | 22 #include "media/base/limits.h" |
23 #include "ui/gl/gl_context.h" | 23 #include "ui/gl/gl_context.h" |
24 #include "ui/gl/gl_surface_egl.h" | 24 #include "ui/gl/gl_surface_egl.h" |
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) |
| 32 #if defined(USE_OZONE) || defined(ARCH_CPU_ARMEL) |
32 #include "content/common/gpu/media/v4l2_video_decode_accelerator.h" | 33 #include "content/common/gpu/media/v4l2_video_decode_accelerator.h" |
33 #include "content/common/gpu/media/v4l2_video_device.h" | 34 #include "content/common/gpu/media/v4l2_video_device.h" |
34 #elif defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) | 35 #endif // defined(USE_OZONE) || defined(ARCH_CPU_ARMEL) |
| 36 #if defined(ARCH_CPU_X86_FAMILY) |
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_implementation.h" | 38 #include "ui/gl/gl_implementation.h" |
| 39 #endif // defined(ARCH_CPU_X86_FAMILY) |
37 #elif defined(USE_OZONE) | 40 #elif defined(USE_OZONE) |
38 #include "media/ozone/media_ozone_platform.h" | 41 #include "media/ozone/media_ozone_platform.h" |
39 #elif defined(OS_ANDROID) | 42 #elif defined(OS_ANDROID) |
40 #include "content/common/gpu/media/android_video_decode_accelerator.h" | 43 #include "content/common/gpu/media/android_video_decode_accelerator.h" |
41 #endif | 44 #endif |
42 | 45 |
43 #include "ui/gfx/size.h" | 46 #include "ui/gfx/size.h" |
44 | 47 |
45 namespace content { | 48 namespace content { |
46 | 49 |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 | 240 |
238 #if !defined(OS_WIN) | 241 #if !defined(OS_WIN) |
239 // 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 |
240 // non-Windows VDAs. | 243 // non-Windows VDAs. |
241 if (!make_context_current_.Run()) { | 244 if (!make_context_current_.Run()) { |
242 SendCreateDecoderReply(init_done_msg, false); | 245 SendCreateDecoderReply(init_done_msg, false); |
243 return; | 246 return; |
244 } | 247 } |
245 #endif | 248 #endif |
246 | 249 |
247 #if defined(OS_WIN) | 250 std::vector<GpuVideoDecodeAccelerator::CreateVDAFp> |
248 if (base::win::GetVersion() < base::win::VERSION_WIN7) { | 251 create_vda_fps = CreateVDAFps(); |
249 NOTIMPLEMENTED() << "HW video decode acceleration not available."; | 252 |
250 SendCreateDecoderReply(init_done_msg, false); | 253 for (size_t i = 0; i < create_vda_fps.size(); ++i) { |
| 254 video_decode_accelerator_ = (this->*create_vda_fps[i])(); |
| 255 if (!video_decode_accelerator_ || |
| 256 !video_decode_accelerator_->Initialize(profile, this)) |
| 257 continue; |
| 258 |
| 259 if (video_decode_accelerator_->CanDecodeOnIOThread()) { |
| 260 filter_ = new MessageFilter(this, host_route_id_); |
| 261 stub_->channel()->AddFilter(filter_.get()); |
| 262 } |
| 263 SendCreateDecoderReply(init_done_msg, true); |
251 return; | 264 return; |
252 } | 265 } |
253 DVLOG(0) << "Initializing DXVA HW decoder for windows."; | 266 video_decode_accelerator_.reset(); |
254 video_decode_accelerator_.reset( | 267 NOTIMPLEMENTED() << "HW video decode acceleration not available."; |
255 new DXVAVideoDecodeAccelerator(make_context_current_)); | 268 SendCreateDecoderReply(init_done_msg, false); |
256 #elif defined(OS_MACOSX) | 269 } |
257 video_decode_accelerator_.reset(new VTVideoDecodeAccelerator( | 270 |
258 static_cast<CGLContextObj>( | 271 std::vector<GpuVideoDecodeAccelerator::CreateVDAFp> |
259 stub_->decoder()->GetGLContext()->GetHandle()), | 272 GpuVideoDecodeAccelerator::CreateVDAFps() { |
| 273 std::vector<GpuVideoDecodeAccelerator::CreateVDAFp> create_vda_fps; |
| 274 create_vda_fps.push_back(&GpuVideoDecodeAccelerator::CreateDXVAVDA); |
| 275 create_vda_fps.push_back(&GpuVideoDecodeAccelerator::CreateV4L2VDA); |
| 276 create_vda_fps.push_back(&GpuVideoDecodeAccelerator::CreateVaapiVDA); |
| 277 create_vda_fps.push_back(&GpuVideoDecodeAccelerator::CreateVTVDA); |
| 278 create_vda_fps.push_back(&GpuVideoDecodeAccelerator::CreateOzoneVDA); |
| 279 create_vda_fps.push_back(&GpuVideoDecodeAccelerator::CreateAndroidVDA); |
| 280 return create_vda_fps; |
| 281 } |
| 282 |
| 283 scoped_ptr<media::VideoDecodeAccelerator> |
| 284 GpuVideoDecodeAccelerator::CreateDXVAVDA() { |
| 285 scoped_ptr<media::VideoDecodeAccelerator> decoder; |
| 286 #if defined(OS_WIN) |
| 287 if (base::win::GetVersion() >= base::win::VERSION_WIN7) { |
| 288 DVLOG(0) << "Initializing DXVA HW decoder for windows."; |
| 289 decoder.reset(new DXVAVideoDecodeAccelerator(make_context_current_)); |
| 290 } else { |
| 291 NOTIMPLEMENTED() << "HW video decode acceleration not available."; |
| 292 } |
| 293 #endif |
| 294 return decoder.Pass(); |
| 295 } |
| 296 |
| 297 scoped_ptr<media::VideoDecodeAccelerator> |
| 298 GpuVideoDecodeAccelerator::CreateV4L2VDA() { |
| 299 scoped_ptr<media::VideoDecodeAccelerator> decoder; |
| 300 #if defined(OS_CHROMEOS) && (defined(USE_OZONE) || defined(ARCH_CPU_ARMEL)) |
| 301 scoped_ptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kDecoder); |
| 302 if (device.get()) { |
| 303 decoder.reset(new V4L2VideoDecodeAccelerator( |
| 304 gfx::GLSurfaceEGL::GetHardwareDisplay(), |
| 305 stub_->decoder()->GetGLContext()->GetHandle(), |
| 306 weak_factory_for_io_.GetWeakPtr(), |
| 307 make_context_current_, |
| 308 device.Pass(), |
| 309 io_message_loop_)); |
| 310 } |
| 311 #endif |
| 312 return decoder.Pass(); |
| 313 } |
| 314 |
| 315 scoped_ptr<media::VideoDecodeAccelerator> |
| 316 GpuVideoDecodeAccelerator::CreateVaapiVDA() { |
| 317 scoped_ptr<media::VideoDecodeAccelerator> decoder; |
| 318 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) |
| 319 decoder.reset(new VaapiVideoDecodeAccelerator(make_context_current_)); |
| 320 #endif |
| 321 return decoder.Pass(); |
| 322 } |
| 323 |
| 324 scoped_ptr<media::VideoDecodeAccelerator> |
| 325 GpuVideoDecodeAccelerator::CreateVTVDA() { |
| 326 scoped_ptr<media::VideoDecodeAccelerator> decoder; |
| 327 #if defined(OS_MACOSX) |
| 328 decoder.reset(new VTVideoDecodeAccelerator( |
| 329 static_cast<CGLContextObj>(stub_->decoder()->GetGLContext()->GetHandle()), |
260 make_context_current_)); | 330 make_context_current_)); |
261 #elif defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL) && defined(USE_X11) | 331 #endif |
262 scoped_ptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kDecoder); | 332 return decoder.Pass(); |
263 if (!device.get()) { | 333 } |
264 SendCreateDecoderReply(init_done_msg, false); | 334 |
265 return; | 335 scoped_ptr<media::VideoDecodeAccelerator> |
266 } | 336 GpuVideoDecodeAccelerator::CreateOzoneVDA() { |
267 video_decode_accelerator_.reset(new V4L2VideoDecodeAccelerator( | 337 scoped_ptr<media::VideoDecodeAccelerator> decoder; |
268 gfx::GLSurfaceEGL::GetHardwareDisplay(), | 338 #if !defined(OS_CHROMEOS) && defined(USE_OZONE) |
269 stub_->decoder()->GetGLContext()->GetHandle(), | |
270 weak_factory_for_io_.GetWeakPtr(), | |
271 make_context_current_, | |
272 device.Pass(), | |
273 io_message_loop_)); | |
274 #elif defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) | |
275 video_decode_accelerator_.reset( | |
276 new VaapiVideoDecodeAccelerator(make_context_current_)); | |
277 #elif defined(USE_OZONE) | |
278 media::MediaOzonePlatform* platform = | 339 media::MediaOzonePlatform* platform = |
279 media::MediaOzonePlatform::GetInstance(); | 340 media::MediaOzonePlatform::GetInstance(); |
280 video_decode_accelerator_.reset(platform->CreateVideoDecodeAccelerator( | 341 decoder.reset(platform->CreateVideoDecodeAccelerator(make_context_current_)); |
281 make_context_current_)); | 342 #endif |
282 if (!video_decode_accelerator_) { | 343 return decoder.Pass(); |
283 SendCreateDecoderReply(init_done_msg, false); | 344 } |
284 return; | 345 |
285 } | 346 scoped_ptr<media::VideoDecodeAccelerator> |
286 #elif defined(OS_ANDROID) | 347 GpuVideoDecodeAccelerator::CreateAndroidVDA() { |
287 video_decode_accelerator_.reset(new AndroidVideoDecodeAccelerator( | 348 scoped_ptr<media::VideoDecodeAccelerator> decoder; |
| 349 #if defined(OS_ANDROID) |
| 350 decoder.reset(new AndroidVideoDecodeAccelerator( |
288 stub_->decoder()->AsWeakPtr(), | 351 stub_->decoder()->AsWeakPtr(), |
289 make_context_current_)); | 352 make_context_current_)); |
290 #else | |
291 NOTIMPLEMENTED() << "HW video decode acceleration not available."; | |
292 SendCreateDecoderReply(init_done_msg, false); | |
293 return; | |
294 #endif | 353 #endif |
295 | 354 return decoder.Pass(); |
296 if (video_decode_accelerator_->CanDecodeOnIOThread()) { | |
297 filter_ = new MessageFilter(this, host_route_id_); | |
298 stub_->channel()->AddFilter(filter_.get()); | |
299 } | |
300 | |
301 if (!video_decode_accelerator_->Initialize(profile, this)) { | |
302 SendCreateDecoderReply(init_done_msg, false); | |
303 return; | |
304 } | |
305 | |
306 SendCreateDecoderReply(init_done_msg, true); | |
307 } | 355 } |
308 | 356 |
309 // Runs on IO thread if video_decode_accelerator_->CanDecodeOnIOThread() is | 357 // Runs on IO thread if video_decode_accelerator_->CanDecodeOnIOThread() is |
310 // true, otherwise on the main thread. | 358 // true, otherwise on the main thread. |
311 void GpuVideoDecodeAccelerator::OnDecode( | 359 void GpuVideoDecodeAccelerator::OnDecode( |
312 base::SharedMemoryHandle handle, int32 id, uint32 size) { | 360 base::SharedMemoryHandle handle, int32 id, uint32 size) { |
313 DCHECK(video_decode_accelerator_.get()); | 361 DCHECK(video_decode_accelerator_.get()); |
314 if (id < 0) { | 362 if (id < 0) { |
315 DLOG(ERROR) << "BitstreamBuffer id " << id << " out of range"; | 363 DLOG(ERROR) << "BitstreamBuffer id " << id << " out of range"; |
316 if (child_message_loop_->BelongsToCurrentThread()) { | 364 if (child_message_loop_->BelongsToCurrentThread()) { |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
505 return stub_->channel()->Send(message); | 553 return stub_->channel()->Send(message); |
506 } | 554 } |
507 | 555 |
508 void GpuVideoDecodeAccelerator::SendCreateDecoderReply(IPC::Message* message, | 556 void GpuVideoDecodeAccelerator::SendCreateDecoderReply(IPC::Message* message, |
509 bool succeeded) { | 557 bool succeeded) { |
510 GpuCommandBufferMsg_CreateVideoDecoder::WriteReplyParams(message, succeeded); | 558 GpuCommandBufferMsg_CreateVideoDecoder::WriteReplyParams(message, succeeded); |
511 Send(message); | 559 Send(message); |
512 } | 560 } |
513 | 561 |
514 } // namespace content | 562 } // namespace content |
OLD | NEW |