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 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
218 | 220 |
219 void GpuVideoDecodeAccelerator::NotifyError( | 221 void GpuVideoDecodeAccelerator::NotifyError( |
220 media::VideoDecodeAccelerator::Error error) { | 222 media::VideoDecodeAccelerator::Error error) { |
221 if (!Send(new AcceleratedVideoDecoderHostMsg_ErrorNotification( | 223 if (!Send(new AcceleratedVideoDecoderHostMsg_ErrorNotification( |
222 host_route_id_, error))) { | 224 host_route_id_, error))) { |
223 DLOG(ERROR) << "Send(AcceleratedVideoDecoderHostMsg_ErrorNotification) " | 225 DLOG(ERROR) << "Send(AcceleratedVideoDecoderHostMsg_ErrorNotification) " |
224 << "failed"; | 226 << "failed"; |
225 } | 227 } |
226 } | 228 } |
227 | 229 |
230 bool GpuVideoDecodeAccelerator::InitializeDecoder( | |
wuchengli
2014/12/26 09:26:25
Use the same order as the header file. Move this b
henryhsu
2014/12/26 09:52:11
Done.
| |
231 media::VideoCodecProfile profile) { | |
232 if (video_decode_accelerator_.get() && | |
233 video_decode_accelerator_->Initialize(profile, this)) { | |
234 if (video_decode_accelerator_->CanDecodeOnIOThread()) { | |
235 filter_ = new MessageFilter(this, host_route_id_); | |
236 stub_->channel()->AddFilter(filter_.get()); | |
237 } | |
238 return true; | |
239 } | |
240 return false; | |
241 } | |
242 | |
228 void GpuVideoDecodeAccelerator::Initialize( | 243 void GpuVideoDecodeAccelerator::Initialize( |
wuchengli
2014/12/26 09:26:25
This function is getting big. But I don't see a wa
| |
229 const media::VideoCodecProfile profile, | 244 const media::VideoCodecProfile profile, |
230 IPC::Message* init_done_msg) { | 245 IPC::Message* init_done_msg) { |
231 DCHECK(!video_decode_accelerator_.get()); | 246 DCHECK(!video_decode_accelerator_.get()); |
232 | 247 |
233 if (!stub_->channel()->AddRoute(host_route_id_, this)) { | 248 if (!stub_->channel()->AddRoute(host_route_id_, this)) { |
234 DLOG(ERROR) << "GpuVideoDecodeAccelerator::Initialize(): " | 249 DLOG(ERROR) << "GpuVideoDecodeAccelerator::Initialize(): " |
235 "failed to add route"; | 250 "failed to add route"; |
236 SendCreateDecoderReply(init_done_msg, false); | 251 SendCreateDecoderReply(init_done_msg, false); |
237 } | 252 } |
238 | 253 |
(...skipping 13 matching lines...) Expand all Loading... | |
252 return; | 267 return; |
253 } | 268 } |
254 DVLOG(0) << "Initializing DXVA HW decoder for windows."; | 269 DVLOG(0) << "Initializing DXVA HW decoder for windows."; |
255 video_decode_accelerator_.reset( | 270 video_decode_accelerator_.reset( |
256 new DXVAVideoDecodeAccelerator(make_context_current_)); | 271 new DXVAVideoDecodeAccelerator(make_context_current_)); |
257 #elif defined(OS_MACOSX) | 272 #elif defined(OS_MACOSX) |
258 video_decode_accelerator_.reset(new VTVideoDecodeAccelerator( | 273 video_decode_accelerator_.reset(new VTVideoDecodeAccelerator( |
259 static_cast<CGLContextObj>( | 274 static_cast<CGLContextObj>( |
260 stub_->decoder()->GetGLContext()->GetHandle()), | 275 stub_->decoder()->GetGLContext()->GetHandle()), |
261 make_context_current_)); | 276 make_context_current_)); |
262 #elif defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL) && defined(USE_X11) | 277 #elif defined(OS_CHROMEOS) && defined(USE_X11) |
wuchengli
2014/12/26 09:26:25
Are there others CPU other than ARCH_CPU_ARMEL and
henryhsu
2014/12/26 09:52:11
Done.
| |
263 scoped_ptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kDecoder); | 278 scoped_ptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kDecoder); |
264 if (!device.get()) { | 279 if (device.get()) { |
265 SendCreateDecoderReply(init_done_msg, false); | 280 video_decode_accelerator_.reset(new V4L2VideoDecodeAccelerator( |
266 return; | 281 gfx::GLSurfaceEGL::GetHardwareDisplay(), |
282 stub_->decoder()->GetGLContext()->GetHandle(), | |
283 weak_factory_for_io_.GetWeakPtr(), | |
284 make_context_current_, | |
285 device.Pass(), | |
286 io_message_loop_)); | |
267 } | 287 } |
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) | 288 #elif defined(USE_OZONE) |
287 media::MediaOzonePlatform* platform = | 289 media::MediaOzonePlatform* platform = |
288 media::MediaOzonePlatform::GetInstance(); | 290 media::MediaOzonePlatform::GetInstance(); |
289 video_decode_accelerator_.reset(platform->CreateVideoDecodeAccelerator( | 291 video_decode_accelerator_.reset(platform->CreateVideoDecodeAccelerator( |
290 make_context_current_)); | 292 make_context_current_)); |
291 if (!video_decode_accelerator_) { | 293 if (!video_decode_accelerator_) { |
292 SendCreateDecoderReply(init_done_msg, false); | 294 SendCreateDecoderReply(init_done_msg, false); |
293 return; | 295 return; |
294 } | 296 } |
295 #elif defined(OS_ANDROID) | 297 #elif defined(OS_ANDROID) |
296 video_decode_accelerator_.reset(new AndroidVideoDecodeAccelerator( | 298 video_decode_accelerator_.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 |
305 if (video_decode_accelerator_->CanDecodeOnIOThread()) { | 307 if (InitializeDecoder(profile)) { |
306 filter_ = new MessageFilter(this, host_route_id_); | 308 SendCreateDecoderReply(init_done_msg, true); |
307 stub_->channel()->AddFilter(filter_.get()); | 309 return; |
308 } | 310 } |
309 | 311 |
310 if (!video_decode_accelerator_->Initialize(profile, this)) { | 312 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) && defined(USE_X11) |
313 // X86 platforms try V4L2 device first. If V4L2 device initialization fails, | |
314 // try VAAPI device again. | |
315 if (gfx::GetGLImplementation() != gfx::kGLImplementationDesktopGL) { | |
316 VLOG(1) << "HW video decode acceleration not available without " | |
317 "DesktopGL (GLX)."; | |
311 SendCreateDecoderReply(init_done_msg, false); | 318 SendCreateDecoderReply(init_done_msg, false); |
312 return; | 319 return; |
313 } | 320 } |
321 gfx::GLContextGLX* glx_context = | |
322 static_cast<gfx::GLContextGLX*>(stub_->decoder()->GetGLContext()); | |
323 video_decode_accelerator_.reset(new VaapiVideoDecodeAccelerator( | |
324 glx_context->display(), make_context_current_)); | |
314 | 325 |
315 SendCreateDecoderReply(init_done_msg, true); | 326 if (InitializeDecoder(profile)) { |
327 SendCreateDecoderReply(init_done_msg, true); | |
328 return; | |
329 } | |
330 #endif | |
331 SendCreateDecoderReply(init_done_msg, false); | |
316 } | 332 } |
317 | 333 |
318 // Runs on IO thread if video_decode_accelerator_->CanDecodeOnIOThread() is | 334 // Runs on IO thread if video_decode_accelerator_->CanDecodeOnIOThread() is |
319 // true, otherwise on the main thread. | 335 // true, otherwise on the main thread. |
320 void GpuVideoDecodeAccelerator::OnDecode( | 336 void GpuVideoDecodeAccelerator::OnDecode( |
321 base::SharedMemoryHandle handle, int32 id, uint32 size) { | 337 base::SharedMemoryHandle handle, int32 id, uint32 size) { |
322 DCHECK(video_decode_accelerator_.get()); | 338 DCHECK(video_decode_accelerator_.get()); |
323 if (id < 0) { | 339 if (id < 0) { |
324 DLOG(ERROR) << "BitstreamBuffer id " << id << " out of range"; | 340 DLOG(ERROR) << "BitstreamBuffer id " << id << " out of range"; |
325 if (child_message_loop_->BelongsToCurrentThread()) { | 341 if (child_message_loop_->BelongsToCurrentThread()) { |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
514 return stub_->channel()->Send(message); | 530 return stub_->channel()->Send(message); |
515 } | 531 } |
516 | 532 |
517 void GpuVideoDecodeAccelerator::SendCreateDecoderReply(IPC::Message* message, | 533 void GpuVideoDecodeAccelerator::SendCreateDecoderReply(IPC::Message* message, |
518 bool succeeded) { | 534 bool succeeded) { |
519 GpuCommandBufferMsg_CreateVideoDecoder::WriteReplyParams(message, succeeded); | 535 GpuCommandBufferMsg_CreateVideoDecoder::WriteReplyParams(message, succeeded); |
520 Send(message); | 536 Send(message); |
521 } | 537 } |
522 | 538 |
523 } // namespace content | 539 } // namespace content |
OLD | NEW |