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 #endif |
| 34 #if defined(ARCH_CPU_X86_FAMILY) |
33 #include "content/common/gpu/media/vaapi_video_encode_accelerator.h" | 35 #include "content/common/gpu/media/vaapi_video_encode_accelerator.h" |
| 36 #endif // defined(ARCH_CPU_X86_FAMILY) |
34 #else | 37 #else |
35 #error The VideoEncodeAcceleratorUnittest is not supported on this platform. | 38 #error The VideoEncodeAcceleratorUnittest is not supported on this platform. |
36 #endif | 39 #endif |
37 | 40 |
38 using media::VideoEncodeAccelerator; | 41 using media::VideoEncodeAccelerator; |
39 | 42 |
40 namespace content { | 43 namespace content { |
41 namespace { | 44 namespace { |
42 | 45 |
43 const media::VideoFrame::Format kInputFormat = media::VideoFrame::I420; | 46 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, | 522 const gfx::Size& input_coded_size, |
520 size_t output_buffer_size) override; | 523 size_t output_buffer_size) override; |
521 virtual void BitstreamBufferReady(int32 bitstream_buffer_id, | 524 virtual void BitstreamBufferReady(int32 bitstream_buffer_id, |
522 size_t payload_size, | 525 size_t payload_size, |
523 bool key_frame) override; | 526 bool key_frame) override; |
524 virtual void NotifyError(VideoEncodeAccelerator::Error error) override; | 527 virtual void NotifyError(VideoEncodeAccelerator::Error error) override; |
525 | 528 |
526 private: | 529 private: |
527 bool has_encoder() { return encoder_.get(); } | 530 bool has_encoder() { return encoder_.get(); } |
528 | 531 |
| 532 scoped_ptr<media::VideoEncodeAccelerator> CreateV4L2VEA(); |
| 533 scoped_ptr<media::VideoEncodeAccelerator> CreateVaapiVEA(); |
| 534 |
529 void SetState(ClientState new_state); | 535 void SetState(ClientState new_state); |
530 | 536 |
531 // Set current stream parameters to given |bitrate| at |framerate|. | 537 // Set current stream parameters to given |bitrate| at |framerate|. |
532 void SetStreamParameters(unsigned int bitrate, unsigned int framerate); | 538 void SetStreamParameters(unsigned int bitrate, unsigned int framerate); |
533 | 539 |
534 // Called when encoder is done with a VideoFrame. | 540 // Called when encoder is done with a VideoFrame. |
535 void InputNoLongerNeededCallback(int32 input_id); | 541 void InputNoLongerNeededCallback(int32 input_id); |
536 | 542 |
537 // Feed the encoder with one input frame. | 543 // Feed the encoder with one input frame. |
538 void FeedEncoderWithOneInput(); | 544 void FeedEncoderWithOneInput(); |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
721 } | 727 } |
722 | 728 |
723 // Initialize the parameters of the test streams. | 729 // Initialize the parameters of the test streams. |
724 UpdateTestStreamData(mid_stream_bitrate_switch, mid_stream_framerate_switch); | 730 UpdateTestStreamData(mid_stream_bitrate_switch, mid_stream_framerate_switch); |
725 | 731 |
726 thread_checker_.DetachFromThread(); | 732 thread_checker_.DetachFromThread(); |
727 } | 733 } |
728 | 734 |
729 VEAClient::~VEAClient() { CHECK(!has_encoder()); } | 735 VEAClient::~VEAClient() { CHECK(!has_encoder()); } |
730 | 736 |
| 737 scoped_ptr<media::VideoEncodeAccelerator> VEAClient::CreateV4L2VEA() { |
| 738 scoped_ptr<media::VideoEncodeAccelerator> encoder; |
| 739 #if defined(OS_CHROMEOS) && (defined(ARCH_CPU_ARMEL) || \ |
| 740 (defined(USE_OZONE) && defined(USE_V4L2_CODEC))) |
| 741 scoped_ptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kEncoder); |
| 742 if (device) |
| 743 encoder.reset(new V4L2VideoEncodeAccelerator(device.Pass())); |
| 744 #endif |
| 745 return encoder.Pass(); |
| 746 } |
| 747 |
| 748 scoped_ptr<media::VideoEncodeAccelerator> VEAClient::CreateVaapiVEA() { |
| 749 scoped_ptr<media::VideoEncodeAccelerator> encoder; |
| 750 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) |
| 751 encoder.reset(new VaapiVideoEncodeAccelerator()); |
| 752 #endif |
| 753 return encoder.Pass(); |
| 754 } |
| 755 |
731 void VEAClient::CreateEncoder() { | 756 void VEAClient::CreateEncoder() { |
732 DCHECK(thread_checker_.CalledOnValidThread()); | 757 DCHECK(thread_checker_.CalledOnValidThread()); |
733 CHECK(!has_encoder()); | 758 CHECK(!has_encoder()); |
734 | 759 |
735 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL) | 760 scoped_ptr<media::VideoEncodeAccelerator> encoders[] = { |
736 scoped_ptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kEncoder); | 761 CreateV4L2VEA(), |
737 encoder_.reset(new V4L2VideoEncodeAccelerator(device.Pass())); | 762 CreateVaapiVEA() |
738 #elif defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) | 763 }; |
739 encoder_.reset(new VaapiVideoEncodeAccelerator()); | |
740 #endif | |
741 | |
742 SetState(CS_ENCODER_SET); | |
743 | 764 |
744 DVLOG(1) << "Profile: " << test_stream_->requested_profile | 765 DVLOG(1) << "Profile: " << test_stream_->requested_profile |
745 << ", initial bitrate: " << requested_bitrate_; | 766 << ", initial bitrate: " << requested_bitrate_; |
746 if (!encoder_->Initialize(kInputFormat, | 767 |
747 test_stream_->visible_size, | 768 for (size_t i = 0; i < arraysize(encoders); ++i) { |
748 test_stream_->requested_profile, | 769 if (!encoders[i]) |
749 requested_bitrate_, | 770 continue; |
750 this)) { | 771 encoder_ = encoders[i].Pass(); |
751 LOG(ERROR) << "VideoEncodeAccelerator::Initialize() failed"; | 772 SetState(CS_ENCODER_SET); |
752 SetState(CS_ERROR); | 773 if (encoder_->Initialize(kInputFormat, |
753 return; | 774 test_stream_->visible_size, |
| 775 test_stream_->requested_profile, |
| 776 requested_bitrate_, |
| 777 this)) { |
| 778 SetStreamParameters(requested_bitrate_, requested_framerate_); |
| 779 SetState(CS_INITIALIZED); |
| 780 return; |
| 781 } |
754 } | 782 } |
755 | 783 encoder_.reset(); |
756 SetStreamParameters(requested_bitrate_, requested_framerate_); | 784 LOG(ERROR) << "VideoEncodeAccelerator::Initialize() failed"; |
757 SetState(CS_INITIALIZED); | 785 SetState(CS_ERROR); |
758 } | 786 } |
759 | 787 |
760 void VEAClient::DestroyEncoder() { | 788 void VEAClient::DestroyEncoder() { |
761 DCHECK(thread_checker_.CalledOnValidThread()); | 789 DCHECK(thread_checker_.CalledOnValidThread()); |
762 if (!has_encoder()) | 790 if (!has_encoder()) |
763 return; | 791 return; |
764 encoder_.reset(); | 792 encoder_.reset(); |
765 input_timer_.reset(); | 793 input_timer_.reset(); |
766 } | 794 } |
767 | 795 |
(...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1336 } | 1364 } |
1337 | 1365 |
1338 content::g_env = | 1366 content::g_env = |
1339 reinterpret_cast<content::VideoEncodeAcceleratorTestEnvironment*>( | 1367 reinterpret_cast<content::VideoEncodeAcceleratorTestEnvironment*>( |
1340 testing::AddGlobalTestEnvironment( | 1368 testing::AddGlobalTestEnvironment( |
1341 new content::VideoEncodeAcceleratorTestEnvironment( | 1369 new content::VideoEncodeAcceleratorTestEnvironment( |
1342 test_stream_data.Pass(), run_at_fps))); | 1370 test_stream_data.Pass(), run_at_fps))); |
1343 | 1371 |
1344 return RUN_ALL_TESTS(); | 1372 return RUN_ALL_TESTS(); |
1345 } | 1373 } |
OLD | NEW |