OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "base/at_exit.h" | 5 #include "base/at_exit.h" |
6 #include "base/bind.h" | 6 #include "base/bind.h" |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/files/memory_mapped_file.h" | 9 #include "base/files/memory_mapped_file.h" |
10 #include "base/memory/scoped_vector.h" | 10 #include "base/memory/scoped_vector.h" |
11 #include "base/numerics/safe_conversions.h" | 11 #include "base/numerics/safe_conversions.h" |
12 #include "base/process/process_handle.h" | 12 #include "base/process/process_handle.h" |
13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
14 #include "base/strings/string_split.h" | 14 #include "base/strings/string_split.h" |
15 #include "base/sys_byteorder.h" | 15 #include "base/sys_byteorder.h" |
16 #include "base/time/time.h" | 16 #include "base/time/time.h" |
17 #include "base/timer/timer.h" | 17 #include "base/timer/timer.h" |
18 #include "content/common/gpu/media/video_accelerator_unittest_helpers.h" | 18 #include "content/common/gpu/media/video_accelerator_unittest_helpers.h" |
19 #include "media/base/bind_to_current_loop.h" | 19 #include "media/base/bind_to_current_loop.h" |
20 #include "media/base/bitstream_buffer.h" | 20 #include "media/base/bitstream_buffer.h" |
21 #include "media/base/test_data_util.h" | 21 #include "media/base/test_data_util.h" |
22 #include "media/filters/h264_parser.h" | 22 #include "media/filters/h264_parser.h" |
23 #include "media/video/video_encode_accelerator.h" | 23 #include "media/video/video_encode_accelerator.h" |
24 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
25 | 25 |
26 #if defined(USE_OZONE) | 26 #if defined(USE_OZONE) |
27 #include "ui/ozone/public/ozone_platform.h" | 27 #include "ui/ozone/public/ozone_platform.h" |
28 #endif | 28 #endif |
29 | 29 |
30 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL) | 30 #if defined(OS_CHROMEOS) |
| 31 #if defined(ARCH_CPU_ARMEL) || (defined(USE_OZONE) && defined(USE_V4L2_CODEC)) |
31 #include "content/common/gpu/media/v4l2_video_encode_accelerator.h" | 32 #include "content/common/gpu/media/v4l2_video_encode_accelerator.h" |
32 #elif defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) | 33 // defined(ARCH_CPU_ARMEL) || (defined(USE_OZONE) && defined(USE_V4L2_CODEC)) |
| 34 #endif |
| 35 #if defined(ARCH_CPU_X86_FAMILY) |
33 #include "content/common/gpu/media/vaapi_video_encode_accelerator.h" | 36 #include "content/common/gpu/media/vaapi_video_encode_accelerator.h" |
| 37 #endif // defined(ARCH_CPU_X86_FAMILY) |
34 #else | 38 #else |
35 #error The VideoEncodeAcceleratorUnittest is not supported on this platform. | 39 #error The VideoEncodeAcceleratorUnittest is not supported on this platform. |
36 #endif | 40 #endif |
37 | 41 |
38 using media::VideoEncodeAccelerator; | 42 using media::VideoEncodeAccelerator; |
39 | 43 |
40 namespace content { | 44 namespace content { |
41 namespace { | 45 namespace { |
42 | 46 |
43 const media::VideoFrame::Format kInputFormat = media::VideoFrame::I420; | 47 const media::VideoFrame::Format kInputFormat = media::VideoFrame::I420; |
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
519 const gfx::Size& input_coded_size, | 523 const gfx::Size& input_coded_size, |
520 size_t output_buffer_size) override; | 524 size_t output_buffer_size) override; |
521 virtual void BitstreamBufferReady(int32 bitstream_buffer_id, | 525 virtual void BitstreamBufferReady(int32 bitstream_buffer_id, |
522 size_t payload_size, | 526 size_t payload_size, |
523 bool key_frame) override; | 527 bool key_frame) override; |
524 virtual void NotifyError(VideoEncodeAccelerator::Error error) override; | 528 virtual void NotifyError(VideoEncodeAccelerator::Error error) override; |
525 | 529 |
526 private: | 530 private: |
527 bool has_encoder() { return encoder_.get(); } | 531 bool has_encoder() { return encoder_.get(); } |
528 | 532 |
| 533 scoped_ptr<media::VideoEncodeAccelerator> CreateV4L2VEA(); |
| 534 scoped_ptr<media::VideoEncodeAccelerator> CreateVaapiVEA(); |
| 535 |
529 void SetState(ClientState new_state); | 536 void SetState(ClientState new_state); |
530 | 537 |
531 // Set current stream parameters to given |bitrate| at |framerate|. | 538 // Set current stream parameters to given |bitrate| at |framerate|. |
532 void SetStreamParameters(unsigned int bitrate, unsigned int framerate); | 539 void SetStreamParameters(unsigned int bitrate, unsigned int framerate); |
533 | 540 |
534 // Called when encoder is done with a VideoFrame. | 541 // Called when encoder is done with a VideoFrame. |
535 void InputNoLongerNeededCallback(int32 input_id); | 542 void InputNoLongerNeededCallback(int32 input_id); |
536 | 543 |
537 // Feed the encoder with one input frame. | 544 // Feed the encoder with one input frame. |
538 void FeedEncoderWithOneInput(); | 545 void FeedEncoderWithOneInput(); |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
721 } | 728 } |
722 | 729 |
723 // Initialize the parameters of the test streams. | 730 // Initialize the parameters of the test streams. |
724 UpdateTestStreamData(mid_stream_bitrate_switch, mid_stream_framerate_switch); | 731 UpdateTestStreamData(mid_stream_bitrate_switch, mid_stream_framerate_switch); |
725 | 732 |
726 thread_checker_.DetachFromThread(); | 733 thread_checker_.DetachFromThread(); |
727 } | 734 } |
728 | 735 |
729 VEAClient::~VEAClient() { CHECK(!has_encoder()); } | 736 VEAClient::~VEAClient() { CHECK(!has_encoder()); } |
730 | 737 |
| 738 scoped_ptr<media::VideoEncodeAccelerator> VEAClient::CreateV4L2VEA() { |
| 739 scoped_ptr<media::VideoEncodeAccelerator> encoder; |
| 740 #if defined(OS_CHROMEOS) && (defined(ARCH_CPU_ARMEL) || \ |
| 741 (defined(USE_OZONE) && defined(USE_V4L2_CODEC))) |
| 742 scoped_ptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kEncoder); |
| 743 if (device) |
| 744 encoder.reset(new V4L2VideoEncodeAccelerator(device.Pass())); |
| 745 #endif |
| 746 return encoder.Pass(); |
| 747 } |
| 748 |
| 749 scoped_ptr<media::VideoEncodeAccelerator> VEAClient::CreateVaapiVEA() { |
| 750 scoped_ptr<media::VideoEncodeAccelerator> encoder; |
| 751 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) |
| 752 encoder.reset(new VaapiVideoEncodeAccelerator()); |
| 753 #endif |
| 754 return encoder.Pass(); |
| 755 } |
| 756 |
731 void VEAClient::CreateEncoder() { | 757 void VEAClient::CreateEncoder() { |
732 DCHECK(thread_checker_.CalledOnValidThread()); | 758 DCHECK(thread_checker_.CalledOnValidThread()); |
733 CHECK(!has_encoder()); | 759 CHECK(!has_encoder()); |
734 | 760 |
735 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL) | 761 scoped_ptr<media::VideoEncodeAccelerator> encoders[] = { |
736 scoped_ptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kEncoder); | 762 CreateV4L2VEA(), |
737 encoder_.reset(new V4L2VideoEncodeAccelerator(device.Pass())); | 763 CreateVaapiVEA() |
738 #elif defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) | 764 }; |
739 encoder_.reset(new VaapiVideoEncodeAccelerator()); | 765 size_t num_encoders = sizeof(encoders) / |
740 #endif | 766 sizeof(scoped_ptr<media::VideoEncodeAccelerator>); |
741 | |
742 SetState(CS_ENCODER_SET); | |
743 | 767 |
744 DVLOG(1) << "Profile: " << test_stream_->requested_profile | 768 DVLOG(1) << "Profile: " << test_stream_->requested_profile |
745 << ", initial bitrate: " << requested_bitrate_; | 769 << ", initial bitrate: " << requested_bitrate_; |
746 if (!encoder_->Initialize(kInputFormat, | 770 |
747 test_stream_->visible_size, | 771 for (size_t i = 0; i < num_encoders; ++i) { |
748 test_stream_->requested_profile, | 772 if (!encoders[i]) |
749 requested_bitrate_, | 773 continue; |
750 this)) { | 774 encoder_ = encoders[i].Pass(); |
751 LOG(ERROR) << "VideoEncodeAccelerator::Initialize() failed"; | 775 SetState(CS_ENCODER_SET); |
752 SetState(CS_ERROR); | 776 if (encoder_->Initialize(kInputFormat, |
753 return; | 777 test_stream_->visible_size, |
| 778 test_stream_->requested_profile, |
| 779 requested_bitrate_, |
| 780 this)) { |
| 781 SetStreamParameters(requested_bitrate_, requested_framerate_); |
| 782 SetState(CS_INITIALIZED); |
| 783 return; |
| 784 } |
754 } | 785 } |
755 | 786 |
756 SetStreamParameters(requested_bitrate_, requested_framerate_); | 787 LOG(ERROR) << "VideoEncodeAccelerator::Initialize() failed"; |
757 SetState(CS_INITIALIZED); | 788 SetState(CS_ERROR); |
758 } | 789 } |
759 | 790 |
760 void VEAClient::DestroyEncoder() { | 791 void VEAClient::DestroyEncoder() { |
761 DCHECK(thread_checker_.CalledOnValidThread()); | 792 DCHECK(thread_checker_.CalledOnValidThread()); |
762 if (!has_encoder()) | 793 if (!has_encoder()) |
763 return; | 794 return; |
764 encoder_.reset(); | 795 encoder_.reset(); |
765 input_timer_.reset(); | 796 input_timer_.reset(); |
766 } | 797 } |
767 | 798 |
(...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1336 } | 1367 } |
1337 | 1368 |
1338 content::g_env = | 1369 content::g_env = |
1339 reinterpret_cast<content::VideoEncodeAcceleratorTestEnvironment*>( | 1370 reinterpret_cast<content::VideoEncodeAcceleratorTestEnvironment*>( |
1340 testing::AddGlobalTestEnvironment( | 1371 testing::AddGlobalTestEnvironment( |
1341 new content::VideoEncodeAcceleratorTestEnvironment( | 1372 new content::VideoEncodeAcceleratorTestEnvironment( |
1342 test_stream_data.Pass(), run_at_fps))); | 1373 test_stream_data.Pass(), run_at_fps))); |
1343 | 1374 |
1344 return RUN_ALL_TESTS(); | 1375 return RUN_ALL_TESTS(); |
1345 } | 1376 } |
OLD | NEW |