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 // The bulk of this file is support code; sorry about that. Here's an overview | 5 // The bulk of this file is support code; sorry about that. Here's an overview |
6 // to hopefully help readers of this code: | 6 // to hopefully help readers of this code: |
7 // - RenderingHelper is charged with interacting with X11/{EGL/GLES2,GLX/GL} or | 7 // - RenderingHelper is charged with interacting with X11/{EGL/GLES2,GLX/GL} or |
8 // Win/EGL. | 8 // Win/EGL. |
9 // - ClientState is an enum for the state of the decode client used by the test. | 9 // - ClientState is an enum for the state of the decode client used by the test. |
10 // - ClientStateNotification is a barrier abstraction that allows the test code | 10 // - ClientStateNotification is a barrier abstraction that allows the test code |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
48 #include "base/synchronization/waitable_event.h" | 48 #include "base/synchronization/waitable_event.h" |
49 #include "base/threading/thread.h" | 49 #include "base/threading/thread.h" |
50 #include "content/common/gpu/media/rendering_helper.h" | 50 #include "content/common/gpu/media/rendering_helper.h" |
51 #include "content/common/gpu/media/video_accelerator_unittest_helpers.h" | 51 #include "content/common/gpu/media/video_accelerator_unittest_helpers.h" |
52 #include "content/public/common/content_switches.h" | 52 #include "content/public/common/content_switches.h" |
53 #include "media/filters/h264_parser.h" | 53 #include "media/filters/h264_parser.h" |
54 #include "ui/gfx/codec/png_codec.h" | 54 #include "ui/gfx/codec/png_codec.h" |
55 | 55 |
56 #if defined(OS_WIN) | 56 #if defined(OS_WIN) |
57 #include "content/common/gpu/media/dxva_video_decode_accelerator.h" | 57 #include "content/common/gpu/media/dxva_video_decode_accelerator.h" |
58 #elif defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL) | 58 #elif defined(OS_CHROMEOS) |
59 #if defined(ARCH_CPU_ARMEL) || (defined(USE_OZONE) && defined(USE_V4L2_CODEC)) | |
59 #include "content/common/gpu/media/v4l2_video_decode_accelerator.h" | 60 #include "content/common/gpu/media/v4l2_video_decode_accelerator.h" |
60 #include "content/common/gpu/media/v4l2_video_device.h" | 61 #include "content/common/gpu/media/v4l2_video_device.h" |
61 #elif defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) | 62 // defined(ARCH_CPU_ARMEL) || (defined(USE_OZONE) && defined(USE_V4L2_CODEC)) |
Pawel Osciak
2015/01/09 13:09:11
Maybe just remove this please, it's actually confu
henryhsu
2015/01/09 14:29:23
Done.
| |
63 #endif | |
64 #if defined(ARCH_CPU_X86_FAMILY) | |
62 #include "content/common/gpu/media/vaapi_video_decode_accelerator.h" | 65 #include "content/common/gpu/media/vaapi_video_decode_accelerator.h" |
63 #include "content/common/gpu/media/vaapi_wrapper.h" | 66 #include "content/common/gpu/media/vaapi_wrapper.h" |
67 #endif // defined(ARCH_CPU_X86_FAMILY) | |
64 #else | 68 #else |
65 #error The VideoAccelerator tests are not supported on this platform. | 69 #error The VideoAccelerator tests are not supported on this platform. |
66 #endif // OS_WIN | 70 #endif // OS_WIN |
67 | 71 |
68 using media::VideoDecodeAccelerator; | 72 using media::VideoDecodeAccelerator; |
69 | 73 |
70 namespace content { | 74 namespace content { |
71 namespace { | 75 namespace { |
72 | 76 |
73 // Values optionally filled in from flags; see main() below. | 77 // Values optionally filled in from flags; see main() below. |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
275 int num_queued_fragments() { return num_queued_fragments_; } | 279 int num_queued_fragments() { return num_queued_fragments_; } |
276 int num_decoded_frames() { return num_decoded_frames_; } | 280 int num_decoded_frames() { return num_decoded_frames_; } |
277 double frames_per_second(); | 281 double frames_per_second(); |
278 // Return the median of the decode time of all decoded frames. | 282 // Return the median of the decode time of all decoded frames. |
279 base::TimeDelta decode_time_median(); | 283 base::TimeDelta decode_time_median(); |
280 bool decoder_deleted() { return !decoder_.get(); } | 284 bool decoder_deleted() { return !decoder_.get(); } |
281 | 285 |
282 private: | 286 private: |
283 typedef std::map<int32, scoped_refptr<TextureRef>> TextureRefMap; | 287 typedef std::map<int32, scoped_refptr<TextureRef>> TextureRefMap; |
284 | 288 |
289 scoped_ptr<media::VideoDecodeAccelerator> CreateDXVAVDA(); | |
Pawel Osciak
2015/01/09 13:09:11
Could these be static and maybe even outside of th
henryhsu
2015/01/09 14:29:23
I think no. First, we have multiple instances of G
| |
290 scoped_ptr<media::VideoDecodeAccelerator> CreateV4L2VDA(); | |
291 scoped_ptr<media::VideoDecodeAccelerator> CreateVaapiVDA(); | |
292 | |
285 void SetState(ClientState new_state); | 293 void SetState(ClientState new_state); |
286 void FinishInitialization(); | 294 void FinishInitialization(); |
287 void ReturnPicture(int32 picture_buffer_id); | 295 void ReturnPicture(int32 picture_buffer_id); |
288 | 296 |
289 // Delete the associated decoder helper. | 297 // Delete the associated decoder helper. |
290 void DeleteDecoder(); | 298 void DeleteDecoder(); |
291 | 299 |
292 // Compute & return the first encoded bytes (including a start frame) to send | 300 // Compute & return the first encoded bytes (including a start frame) to send |
293 // to the decoder, starting at |start_pos| and returning one fragment. Skips | 301 // to the decoder, starting at |start_pos| and returning one fragment. Skips |
294 // to the first decodable position. | 302 // to the first decodable position. |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
404 } | 412 } |
405 | 413 |
406 GLRenderingVDAClient::~GLRenderingVDAClient() { | 414 GLRenderingVDAClient::~GLRenderingVDAClient() { |
407 DeleteDecoder(); // Clean up in case of expected error. | 415 DeleteDecoder(); // Clean up in case of expected error. |
408 CHECK(decoder_deleted()); | 416 CHECK(decoder_deleted()); |
409 SetState(CS_DESTROYED); | 417 SetState(CS_DESTROYED); |
410 } | 418 } |
411 | 419 |
412 static bool DoNothingReturnTrue() { return true; } | 420 static bool DoNothingReturnTrue() { return true; } |
413 | 421 |
422 scoped_ptr<media::VideoDecodeAccelerator> | |
423 GLRenderingVDAClient::CreateDXVAVDA() { | |
424 scoped_ptr<media::VideoDecodeAccelerator> decoder; | |
425 #if defined(OS_WIN) | |
426 if (base::win::GetVersion() >= base::win::VERSION_WIN7) | |
427 decoder.reset( | |
428 new DXVAVideoDecodeAccelerator(base::Bind(&DoNothingReturnTrue))); | |
429 #endif | |
430 return decoder.Pass(); | |
431 } | |
432 | |
433 scoped_ptr<media::VideoDecodeAccelerator> | |
434 GLRenderingVDAClient::CreateV4L2VDA() { | |
435 scoped_ptr<media::VideoDecodeAccelerator> decoder; | |
436 #if defined(OS_CHROMEOS) && (defined(ARCH_CPU_ARMEL) || \ | |
437 (defined(USE_OZONE) && defined(USE_V4L2_CODEC))) | |
438 scoped_ptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kDecoder); | |
439 if (device.get()) { | |
440 base::WeakPtr<VideoDecodeAccelerator::Client> weak_client = AsWeakPtr(); | |
441 decoder.reset(new V4L2VideoDecodeAccelerator( | |
442 static_cast<EGLDisplay>(rendering_helper_->GetGLDisplay()), | |
443 static_cast<EGLContext>(rendering_helper_->GetGLContextHandle()), | |
444 weak_client, | |
445 base::Bind(&DoNothingReturnTrue), | |
446 device.Pass(), | |
447 base::MessageLoopProxy::current())); | |
448 } | |
449 #endif | |
450 return decoder.Pass(); | |
451 } | |
452 | |
453 scoped_ptr<media::VideoDecodeAccelerator> | |
454 GLRenderingVDAClient::CreateVaapiVDA() { | |
455 scoped_ptr<media::VideoDecodeAccelerator> decoder; | |
456 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) | |
457 decoder.reset( | |
458 new VaapiVideoDecodeAccelerator(base::Bind(&DoNothingReturnTrue))); | |
459 #endif | |
460 return decoder.Pass(); | |
461 } | |
462 | |
414 void GLRenderingVDAClient::CreateAndStartDecoder() { | 463 void GLRenderingVDAClient::CreateAndStartDecoder() { |
415 CHECK(decoder_deleted()); | 464 CHECK(decoder_deleted()); |
416 CHECK(!decoder_.get()); | 465 CHECK(!decoder_.get()); |
417 | 466 |
418 VideoDecodeAccelerator::Client* client = this; | 467 VideoDecodeAccelerator::Client* client = this; |
419 base::WeakPtr<VideoDecodeAccelerator::Client> weak_client = AsWeakPtr(); | |
420 #if defined(OS_WIN) | |
421 decoder_.reset( | |
422 new DXVAVideoDecodeAccelerator(base::Bind(&DoNothingReturnTrue))); | |
423 #elif defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL) | |
424 | 468 |
425 scoped_ptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kDecoder); | 469 scoped_ptr<media::VideoDecodeAccelerator> decoders[] = { |
426 if (!device.get()) { | 470 CreateDXVAVDA(), |
427 NotifyError(media::VideoDecodeAccelerator::PLATFORM_FAILURE); | 471 CreateV4L2VDA(), |
428 return; | 472 CreateVaapiVDA() |
473 }; | |
474 size_t num_decoders = sizeof(decoders) / | |
Pawel Osciak
2015/01/09 13:09:11
Please use arraysize() and move to the for loop.
henryhsu
2015/01/09 14:29:23
Done.
| |
475 sizeof(scoped_ptr<media::VideoDecodeAccelerator>); | |
476 | |
477 for (size_t i = 0; i < num_decoders; ++i) { | |
478 if (!decoders[i]) continue; | |
Pawel Osciak
2015/01/09 13:09:11
New line please.
henryhsu
2015/01/09 14:29:23
Done.
| |
479 decoder_ = decoders[i].Pass(); | |
480 weak_decoder_factory_.reset( | |
481 new base::WeakPtrFactory<VideoDecodeAccelerator>(decoder_.get())); | |
482 SetState(CS_DECODER_SET); | |
483 if (decoder_->Initialize(profile_, client)) { | |
484 FinishInitialization(); | |
485 return; | |
486 } | |
429 } | 487 } |
430 decoder_.reset(new V4L2VideoDecodeAccelerator( | |
431 static_cast<EGLDisplay>(rendering_helper_->GetGLDisplay()), | |
432 static_cast<EGLContext>(rendering_helper_->GetGLContextHandle()), | |
433 weak_client, base::Bind(&DoNothingReturnTrue), device.Pass(), | |
434 base::MessageLoopProxy::current())); | |
435 #elif defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) | |
436 decoder_.reset( | |
437 new VaapiVideoDecodeAccelerator(base::Bind(&DoNothingReturnTrue))); | |
438 #endif // OS_WIN | |
439 CHECK(decoder_.get()); | 488 CHECK(decoder_.get()); |
Pawel Osciak
2015/01/09 13:09:11
Perhaps have decoder_.reset() at the end of each i
henryhsu
2015/01/09 14:29:23
We don't have to reset decoder_ at the end of each
| |
440 weak_decoder_factory_.reset( | 489 // Decoders are all initialize failed. |
441 new base::WeakPtrFactory<VideoDecodeAccelerator>(decoder_.get())); | 490 CHECK(false); |
442 SetState(CS_DECODER_SET); | |
443 if (decoder_deleted()) | |
444 return; | |
445 | |
446 CHECK(decoder_->Initialize(profile_, client)); | |
447 FinishInitialization(); | |
448 } | 491 } |
449 | 492 |
450 void GLRenderingVDAClient::ProvidePictureBuffers( | 493 void GLRenderingVDAClient::ProvidePictureBuffers( |
451 uint32 requested_num_of_buffers, | 494 uint32 requested_num_of_buffers, |
452 const gfx::Size& dimensions, | 495 const gfx::Size& dimensions, |
453 uint32 texture_target) { | 496 uint32 texture_target) { |
454 if (decoder_deleted()) | 497 if (decoder_deleted()) |
455 return; | 498 return; |
456 std::vector<media::PictureBuffer> buffers; | 499 std::vector<media::PictureBuffer> buffers; |
457 | 500 |
(...skipping 1014 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1472 if (it->first == "ozone-platform" || it->first == "ozone-use-surfaceless") | 1515 if (it->first == "ozone-platform" || it->first == "ozone-use-surfaceless") |
1473 continue; | 1516 continue; |
1474 LOG(FATAL) << "Unexpected switch: " << it->first << ":" << it->second; | 1517 LOG(FATAL) << "Unexpected switch: " << it->first << ":" << it->second; |
1475 } | 1518 } |
1476 | 1519 |
1477 base::ShadowingAtExitManager at_exit_manager; | 1520 base::ShadowingAtExitManager at_exit_manager; |
1478 content::RenderingHelper::InitializeOneOff(); | 1521 content::RenderingHelper::InitializeOneOff(); |
1479 | 1522 |
1480 return RUN_ALL_TESTS(); | 1523 return RUN_ALL_TESTS(); |
1481 } | 1524 } |
OLD | NEW |