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 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 const media::VideoCodecProfile profile, | 231 const media::VideoCodecProfile profile, |
230 IPC::Message* init_done_msg) { | 232 IPC::Message* init_done_msg) { |
231 DCHECK(!video_decode_accelerator_.get()); | 233 DCHECK(!video_decode_accelerator_.get()); |
232 | 234 |
233 if (!stub_->channel()->AddRoute(host_route_id_, this)) { | 235 if (!stub_->channel()->AddRoute(host_route_id_, this)) { |
234 DLOG(ERROR) << "GpuVideoDecodeAccelerator::Initialize(): " | 236 DLOG(ERROR) << "GpuVideoDecodeAccelerator::Initialize(): " |
235 "failed to add route"; | 237 "failed to add route"; |
236 SendCreateDecoderReply(init_done_msg, false); | 238 SendCreateDecoderReply(init_done_msg, false); |
237 } | 239 } |
238 | 240 |
| 241 scoped_ptr<media::VideoDecodeAccelerator> decoders[2]; |
| 242 size_t n_decoders = 0; |
| 243 |
239 #if !defined(OS_WIN) | 244 #if !defined(OS_WIN) |
240 // Ensure we will be able to get a GL context at all before initializing | 245 // Ensure we will be able to get a GL context at all before initializing |
241 // non-Windows VDAs. | 246 // non-Windows VDAs. |
242 if (!make_context_current_.Run()) { | 247 if (!make_context_current_.Run()) { |
243 SendCreateDecoderReply(init_done_msg, false); | 248 SendCreateDecoderReply(init_done_msg, false); |
244 return; | 249 return; |
245 } | 250 } |
246 #endif | 251 #endif |
247 | 252 |
248 #if defined(OS_WIN) | 253 #if defined(OS_WIN) |
249 if (base::win::GetVersion() < base::win::VERSION_WIN7) { | 254 if (base::win::GetVersion() < base::win::VERSION_WIN7) { |
250 NOTIMPLEMENTED() << "HW video decode acceleration not available."; | 255 NOTIMPLEMENTED() << "HW video decode acceleration not available."; |
251 SendCreateDecoderReply(init_done_msg, false); | 256 SendCreateDecoderReply(init_done_msg, false); |
252 return; | 257 return; |
253 } | 258 } |
254 DVLOG(0) << "Initializing DXVA HW decoder for windows."; | 259 DVLOG(0) << "Initializing DXVA HW decoder for windows."; |
255 video_decode_accelerator_.reset( | 260 decoders[n_decoders++].reset( |
256 new DXVAVideoDecodeAccelerator(make_context_current_)); | 261 new DXVAVideoDecodeAccelerator(make_context_current_)); |
257 #elif defined(OS_MACOSX) | 262 #elif defined(OS_MACOSX) |
258 video_decode_accelerator_.reset(new VTVideoDecodeAccelerator( | 263 decoders[n_decoders++].reset(new VTVideoDecodeAccelerator( |
259 static_cast<CGLContextObj>( | 264 static_cast<CGLContextObj>( |
260 stub_->decoder()->GetGLContext()->GetHandle()), | 265 stub_->decoder()->GetGLContext()->GetHandle()), |
261 make_context_current_)); | 266 make_context_current_)); |
262 #elif defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL) && defined(USE_X11) | 267 #elif defined(OS_CHROMEOS) && defined(USE_X11) && \ |
| 268 (defined(ARCH_CPU_X86_FAMILY) || defined(ARCH_CPU_ARMEL)) |
263 scoped_ptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kDecoder); | 269 scoped_ptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kDecoder); |
264 if (!device.get()) { | 270 if (device.get()) { |
265 SendCreateDecoderReply(init_done_msg, false); | 271 decoders[n_decoders++].reset(new V4L2VideoDecodeAccelerator( |
266 return; | 272 gfx::GLSurfaceEGL::GetHardwareDisplay(), |
| 273 stub_->decoder()->GetGLContext()->GetHandle(), |
| 274 weak_factory_for_io_.GetWeakPtr(), |
| 275 make_context_current_, |
| 276 device.Pass(), |
| 277 io_message_loop_)); |
267 } | 278 } |
268 video_decode_accelerator_.reset(new V4L2VideoDecodeAccelerator( | 279 #if defined(ARCH_CPU_X86_FAMILY) |
269 gfx::GLSurfaceEGL::GetHardwareDisplay(), | 280 // x86 CrOS platforms may have multiple decoders. |
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) { | 281 if (gfx::GetGLImplementation() != gfx::kGLImplementationDesktopGL) { |
277 VLOG(1) << "HW video decode acceleration not available without " | 282 VLOG(1) << "HW video decode acceleration not available without " |
278 "DesktopGL (GLX)."; | 283 "DesktopGL (GLX)."; |
279 SendCreateDecoderReply(init_done_msg, false); | 284 SendCreateDecoderReply(init_done_msg, false); |
280 return; | 285 return; |
281 } | 286 } |
282 gfx::GLContextGLX* glx_context = | 287 gfx::GLContextGLX* glx_context = |
283 static_cast<gfx::GLContextGLX*>(stub_->decoder()->GetGLContext()); | 288 static_cast<gfx::GLContextGLX*>(stub_->decoder()->GetGLContext()); |
284 video_decode_accelerator_.reset(new VaapiVideoDecodeAccelerator( | 289 decoders[n_decoders++].reset(new VaapiVideoDecodeAccelerator( |
285 glx_context->display(), make_context_current_)); | 290 glx_context->display(), make_context_current_)); |
| 291 #endif |
286 #elif defined(USE_OZONE) | 292 #elif defined(USE_OZONE) |
287 media::MediaOzonePlatform* platform = | 293 media::MediaOzonePlatform* platform = |
288 media::MediaOzonePlatform::GetInstance(); | 294 media::MediaOzonePlatform::GetInstance(); |
289 video_decode_accelerator_.reset(platform->CreateVideoDecodeAccelerator( | 295 decoders[n_decoders++].reset(platform->CreateVideoDecodeAccelerator( |
290 make_context_current_)); | 296 make_context_current_)); |
291 if (!video_decode_accelerator_) { | |
292 SendCreateDecoderReply(init_done_msg, false); | |
293 return; | |
294 } | |
295 #elif defined(OS_ANDROID) | 297 #elif defined(OS_ANDROID) |
296 video_decode_accelerator_.reset(new AndroidVideoDecodeAccelerator( | 298 decoders[n_decoders++].reset(new AndroidVideoDecodeAccelerator( |
297 stub_->decoder()->AsWeakPtr(), | 299 stub_->decoder()->AsWeakPtr(), |
298 make_context_current_)); | 300 make_context_current_)); |
299 #else | 301 #else |
300 NOTIMPLEMENTED() << "HW video decode acceleration not available."; | 302 NOTIMPLEMENTED() << "HW video decode acceleration not available."; |
301 SendCreateDecoderReply(init_done_msg, false); | 303 SendCreateDecoderReply(init_done_msg, false); |
302 return; | 304 return; |
303 #endif | 305 #endif |
304 | 306 |
| 307 for (size_t i = 0; i < n_decoders; ++i) { |
| 308 if (!decoders[i]) |
| 309 continue; |
| 310 video_decode_accelerator_ = decoders[i].Pass(); |
| 311 if (InitializeDecoder(profile)) { |
| 312 SendCreateDecoderReply(init_done_msg, true); |
| 313 return; |
| 314 } |
| 315 } |
| 316 |
| 317 SendCreateDecoderReply(init_done_msg, false); |
| 318 } |
| 319 |
| 320 bool GpuVideoDecodeAccelerator::InitializeDecoder( |
| 321 media::VideoCodecProfile profile) { |
| 322 if (!video_decode_accelerator_.get() || |
| 323 !video_decode_accelerator_->Initialize(profile, this)) |
| 324 return false; |
| 325 |
305 if (video_decode_accelerator_->CanDecodeOnIOThread()) { | 326 if (video_decode_accelerator_->CanDecodeOnIOThread()) { |
306 filter_ = new MessageFilter(this, host_route_id_); | 327 filter_ = new MessageFilter(this, host_route_id_); |
307 stub_->channel()->AddFilter(filter_.get()); | 328 stub_->channel()->AddFilter(filter_.get()); |
308 } | 329 } |
309 | 330 return true; |
310 if (!video_decode_accelerator_->Initialize(profile, this)) { | |
311 SendCreateDecoderReply(init_done_msg, false); | |
312 return; | |
313 } | |
314 | |
315 SendCreateDecoderReply(init_done_msg, true); | |
316 } | 331 } |
317 | 332 |
318 // Runs on IO thread if video_decode_accelerator_->CanDecodeOnIOThread() is | 333 // Runs on IO thread if video_decode_accelerator_->CanDecodeOnIOThread() is |
319 // true, otherwise on the main thread. | 334 // true, otherwise on the main thread. |
320 void GpuVideoDecodeAccelerator::OnDecode( | 335 void GpuVideoDecodeAccelerator::OnDecode( |
321 base::SharedMemoryHandle handle, int32 id, uint32 size) { | 336 base::SharedMemoryHandle handle, int32 id, uint32 size) { |
322 DCHECK(video_decode_accelerator_.get()); | 337 DCHECK(video_decode_accelerator_.get()); |
323 if (id < 0) { | 338 if (id < 0) { |
324 DLOG(ERROR) << "BitstreamBuffer id " << id << " out of range"; | 339 DLOG(ERROR) << "BitstreamBuffer id " << id << " out of range"; |
325 if (child_message_loop_->BelongsToCurrentThread()) { | 340 if (child_message_loop_->BelongsToCurrentThread()) { |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
514 return stub_->channel()->Send(message); | 529 return stub_->channel()->Send(message); |
515 } | 530 } |
516 | 531 |
517 void GpuVideoDecodeAccelerator::SendCreateDecoderReply(IPC::Message* message, | 532 void GpuVideoDecodeAccelerator::SendCreateDecoderReply(IPC::Message* message, |
518 bool succeeded) { | 533 bool succeeded) { |
519 GpuCommandBufferMsg_CreateVideoDecoder::WriteReplyParams(message, succeeded); | 534 GpuCommandBufferMsg_CreateVideoDecoder::WriteReplyParams(message, succeeded); |
520 Send(message); | 535 Send(message); |
521 } | 536 } |
522 | 537 |
523 } // namespace content | 538 } // namespace content |
OLD | NEW |