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