| 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 <inttypes.h> | 5 #include <inttypes.h> |
| 6 #include <stddef.h> | 6 #include <stddef.h> |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <queue> | 9 #include <queue> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 #if defined(OS_CHROMEOS) | 48 #if defined(OS_CHROMEOS) |
| 49 #if defined(ARCH_CPU_ARMEL) || (defined(USE_OZONE) && defined(USE_V4L2_CODEC)) | 49 #if defined(ARCH_CPU_ARMEL) || (defined(USE_OZONE) && defined(USE_V4L2_CODEC)) |
| 50 #include "content/common/gpu/media/v4l2_video_encode_accelerator.h" | 50 #include "content/common/gpu/media/v4l2_video_encode_accelerator.h" |
| 51 #endif | 51 #endif |
| 52 #if defined(ARCH_CPU_X86_FAMILY) | 52 #if defined(ARCH_CPU_X86_FAMILY) |
| 53 #include "content/common/gpu/media/vaapi_video_encode_accelerator.h" | 53 #include "content/common/gpu/media/vaapi_video_encode_accelerator.h" |
| 54 #include "content/common/gpu/media/vaapi_wrapper.h" | 54 #include "content/common/gpu/media/vaapi_wrapper.h" |
| 55 // Status has been defined as int in Xlib.h. | 55 // Status has been defined as int in Xlib.h. |
| 56 #undef Status | 56 #undef Status |
| 57 #endif // defined(ARCH_CPU_X86_FAMILY) | 57 #endif // defined(ARCH_CPU_X86_FAMILY) |
| 58 #elif defined(OS_MACOSX) |
| 59 #include "content/common/gpu/media/vt_video_encode_accelerator_mac.h" |
| 58 #else | 60 #else |
| 59 #error The VideoEncodeAcceleratorUnittest is not supported on this platform. | 61 #error The VideoEncodeAcceleratorUnittest is not supported on this platform. |
| 60 #endif | 62 #endif |
| 61 | 63 |
| 62 using media::VideoEncodeAccelerator; | 64 using media::VideoEncodeAccelerator; |
| 63 | 65 |
| 64 namespace content { | 66 namespace content { |
| 65 namespace { | 67 namespace { |
| 66 | 68 |
| 67 const media::VideoPixelFormat kInputFormat = media::PIXEL_FORMAT_I420; | 69 const media::VideoPixelFormat kInputFormat = media::PIXEL_FORMAT_I420; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 // Further parameters are optional (need to provide preceding positional | 121 // Further parameters are optional (need to provide preceding positional |
| 120 // parameters if a specific subsequent parameter is required): | 122 // parameters if a specific subsequent parameter is required): |
| 121 // - |requested_bitrate| requested bitrate in bits per second. | 123 // - |requested_bitrate| requested bitrate in bits per second. |
| 122 // - |requested_framerate| requested initial framerate. | 124 // - |requested_framerate| requested initial framerate. |
| 123 // - |requested_subsequent_bitrate| bitrate to switch to in the middle of the | 125 // - |requested_subsequent_bitrate| bitrate to switch to in the middle of the |
| 124 // stream. | 126 // stream. |
| 125 // - |requested_subsequent_framerate| framerate to switch to in the middle | 127 // - |requested_subsequent_framerate| framerate to switch to in the middle |
| 126 // of the stream. | 128 // of the stream. |
| 127 // Bitrate is only forced for tests that test bitrate. | 129 // Bitrate is only forced for tests that test bitrate. |
| 128 const char* g_default_in_filename = "bear_320x192_40frames.yuv"; | 130 const char* g_default_in_filename = "bear_320x192_40frames.yuv"; |
| 131 #if !defined(OS_MACOSX) |
| 129 const char* g_default_in_parameters = ":320:192:1:out.h264:200000"; | 132 const char* g_default_in_parameters = ":320:192:1:out.h264:200000"; |
| 133 #else |
| 134 const char* g_default_in_parameters = ":320:192:0:out.h264:200000"; |
| 135 #endif |
| 130 | 136 |
| 131 // Enabled by including a --fake_encoder flag to the command line invoking the | 137 // Enabled by including a --fake_encoder flag to the command line invoking the |
| 132 // test. | 138 // test. |
| 133 bool g_fake_encoder = false; | 139 bool g_fake_encoder = false; |
| 134 | 140 |
| 135 // Environment to store test stream data for all test cases. | 141 // Environment to store test stream data for all test cases. |
| 136 class VideoEncodeAcceleratorTestEnvironment; | 142 class VideoEncodeAcceleratorTestEnvironment; |
| 137 VideoEncodeAcceleratorTestEnvironment* g_env; | 143 VideoEncodeAcceleratorTestEnvironment* g_env; |
| 138 | 144 |
| 139 // The number of frames to be encoded. This variable is set by the switch | 145 // The number of frames to be encoded. This variable is set by the switch |
| (...skipping 665 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 805 | 811 |
| 806 private: | 812 private: |
| 807 bool has_encoder() { return encoder_.get(); } | 813 bool has_encoder() { return encoder_.get(); } |
| 808 | 814 |
| 809 // Return the number of encoded frames per second. | 815 // Return the number of encoded frames per second. |
| 810 double frames_per_second(); | 816 double frames_per_second(); |
| 811 | 817 |
| 812 scoped_ptr<media::VideoEncodeAccelerator> CreateFakeVEA(); | 818 scoped_ptr<media::VideoEncodeAccelerator> CreateFakeVEA(); |
| 813 scoped_ptr<media::VideoEncodeAccelerator> CreateV4L2VEA(); | 819 scoped_ptr<media::VideoEncodeAccelerator> CreateV4L2VEA(); |
| 814 scoped_ptr<media::VideoEncodeAccelerator> CreateVaapiVEA(); | 820 scoped_ptr<media::VideoEncodeAccelerator> CreateVaapiVEA(); |
| 821 scoped_ptr<media::VideoEncodeAccelerator> CreateVTVEA(); |
| 815 | 822 |
| 816 void SetState(ClientState new_state); | 823 void SetState(ClientState new_state); |
| 817 | 824 |
| 818 // Set current stream parameters to given |bitrate| at |framerate|. | 825 // Set current stream parameters to given |bitrate| at |framerate|. |
| 819 void SetStreamParameters(unsigned int bitrate, unsigned int framerate); | 826 void SetStreamParameters(unsigned int bitrate, unsigned int framerate); |
| 820 | 827 |
| 821 // Called when encoder is done with a VideoFrame. | 828 // Called when encoder is done with a VideoFrame. |
| 822 void InputNoLongerNeededCallback(int32_t input_id); | 829 void InputNoLongerNeededCallback(int32_t input_id); |
| 823 | 830 |
| 824 // Feed the encoder with one input frame. | 831 // Feed the encoder with one input frame. |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1066 } | 1073 } |
| 1067 | 1074 |
| 1068 scoped_ptr<media::VideoEncodeAccelerator> VEAClient::CreateVaapiVEA() { | 1075 scoped_ptr<media::VideoEncodeAccelerator> VEAClient::CreateVaapiVEA() { |
| 1069 scoped_ptr<media::VideoEncodeAccelerator> encoder; | 1076 scoped_ptr<media::VideoEncodeAccelerator> encoder; |
| 1070 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) | 1077 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) |
| 1071 encoder.reset(new VaapiVideoEncodeAccelerator()); | 1078 encoder.reset(new VaapiVideoEncodeAccelerator()); |
| 1072 #endif | 1079 #endif |
| 1073 return encoder; | 1080 return encoder; |
| 1074 } | 1081 } |
| 1075 | 1082 |
| 1083 scoped_ptr<media::VideoEncodeAccelerator> VEAClient::CreateVTVEA() { |
| 1084 scoped_ptr<media::VideoEncodeAccelerator> encoder; |
| 1085 #if defined(OS_MACOSX) |
| 1086 encoder.reset(new VTVideoEncodeAccelerator()); |
| 1087 #endif |
| 1088 return encoder; |
| 1089 } |
| 1090 |
| 1076 void VEAClient::CreateEncoder() { | 1091 void VEAClient::CreateEncoder() { |
| 1077 DCHECK(thread_checker_.CalledOnValidThread()); | 1092 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1078 LOG_ASSERT(!has_encoder()); | 1093 LOG_ASSERT(!has_encoder()); |
| 1079 | 1094 |
| 1080 scoped_ptr<media::VideoEncodeAccelerator> encoders[] = { | 1095 scoped_ptr<media::VideoEncodeAccelerator> encoders[] = { |
| 1081 CreateFakeVEA(), | 1096 CreateFakeVEA(), |
| 1082 CreateV4L2VEA(), | 1097 CreateV4L2VEA(), |
| 1083 CreateVaapiVEA() | 1098 CreateVaapiVEA(), |
| 1099 CreateVTVEA() |
| 1084 }; | 1100 }; |
| 1085 | 1101 |
| 1086 DVLOG(1) << "Profile: " << test_stream_->requested_profile | 1102 DVLOG(1) << "Profile: " << test_stream_->requested_profile |
| 1087 << ", initial bitrate: " << requested_bitrate_; | 1103 << ", initial bitrate: " << requested_bitrate_; |
| 1088 | 1104 |
| 1089 for (size_t i = 0; i < arraysize(encoders); ++i) { | 1105 for (size_t i = 0; i < arraysize(encoders); ++i) { |
| 1090 if (!encoders[i]) | 1106 if (!encoders[i]) |
| 1091 continue; | 1107 continue; |
| 1092 encoder_ = std::move(encoders[i]); | 1108 encoder_ = std::move(encoders[i]); |
| 1093 SetState(CS_ENCODER_SET); | 1109 SetState(CS_ENCODER_SET); |
| (...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1644 for (size_t i = 0; i < num_concurrent_encoders; ++i) { | 1660 for (size_t i = 0; i < num_concurrent_encoders; ++i) { |
| 1645 encoder_thread.message_loop()->PostTask( | 1661 encoder_thread.message_loop()->PostTask( |
| 1646 FROM_HERE, | 1662 FROM_HERE, |
| 1647 base::Bind(&VEAClient::DestroyEncoder, base::Unretained(clients[i]))); | 1663 base::Bind(&VEAClient::DestroyEncoder, base::Unretained(clients[i]))); |
| 1648 } | 1664 } |
| 1649 | 1665 |
| 1650 // This ensures all tasks have finished. | 1666 // This ensures all tasks have finished. |
| 1651 encoder_thread.Stop(); | 1667 encoder_thread.Stop(); |
| 1652 } | 1668 } |
| 1653 | 1669 |
| 1670 #if !defined(OS_MACOSX) |
| 1654 INSTANTIATE_TEST_CASE_P( | 1671 INSTANTIATE_TEST_CASE_P( |
| 1655 SimpleEncode, | 1672 SimpleEncode, |
| 1656 VideoEncodeAcceleratorTest, | 1673 VideoEncodeAcceleratorTest, |
| 1657 ::testing::Values( | 1674 ::testing::Values( |
| 1658 base::MakeTuple(1, true, 0, false, false, false, false, false), | 1675 base::MakeTuple(1, true, 0, false, false, false, false, false), |
| 1659 base::MakeTuple(1, true, 0, false, false, false, false, true))); | 1676 base::MakeTuple(1, true, 0, false, false, false, false, true))); |
| 1660 | 1677 |
| 1661 INSTANTIATE_TEST_CASE_P( | 1678 INSTANTIATE_TEST_CASE_P( |
| 1662 EncoderPerf, | 1679 EncoderPerf, |
| 1663 VideoEncodeAcceleratorTest, | 1680 VideoEncodeAcceleratorTest, |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1688 ::testing::Values( | 1705 ::testing::Values( |
| 1689 base::MakeTuple(1, false, 0, true, false, false, true, false))); | 1706 base::MakeTuple(1, false, 0, true, false, false, true, false))); |
| 1690 | 1707 |
| 1691 INSTANTIATE_TEST_CASE_P( | 1708 INSTANTIATE_TEST_CASE_P( |
| 1692 MultipleEncoders, | 1709 MultipleEncoders, |
| 1693 VideoEncodeAcceleratorTest, | 1710 VideoEncodeAcceleratorTest, |
| 1694 ::testing::Values( | 1711 ::testing::Values( |
| 1695 base::MakeTuple(3, false, 0, false, false, false, false, false), | 1712 base::MakeTuple(3, false, 0, false, false, false, false, false), |
| 1696 base::MakeTuple(3, false, 0, true, false, false, true, false), | 1713 base::MakeTuple(3, false, 0, true, false, false, true, false), |
| 1697 base::MakeTuple(3, false, 0, true, false, true, false, false))); | 1714 base::MakeTuple(3, false, 0, true, false, true, false, false))); |
| 1715 #else |
| 1716 INSTANTIATE_TEST_CASE_P( |
| 1717 SimpleEncode, |
| 1718 VideoEncodeAcceleratorTest, |
| 1719 ::testing::Values( |
| 1720 base::MakeTuple(1, true, 0, false, false, false, false, false), |
| 1721 base::MakeTuple(1, true, 0, false, false, false, false, true))); |
| 1722 |
| 1723 INSTANTIATE_TEST_CASE_P( |
| 1724 EncoderPerf, |
| 1725 VideoEncodeAcceleratorTest, |
| 1726 ::testing::Values( |
| 1727 base::MakeTuple(1, false, 0, false, true, false, false, false))); |
| 1728 |
| 1729 INSTANTIATE_TEST_CASE_P( |
| 1730 MultipleEncoders, |
| 1731 VideoEncodeAcceleratorTest, |
| 1732 ::testing::Values( |
| 1733 base::MakeTuple(3, false, 0, false, false, false, false, false))); |
| 1734 #endif |
| 1698 | 1735 |
| 1699 // TODO(posciak): more tests: | 1736 // TODO(posciak): more tests: |
| 1700 // - async FeedEncoderWithOutput | 1737 // - async FeedEncoderWithOutput |
| 1701 // - out-of-order return of outputs to encoder | 1738 // - out-of-order return of outputs to encoder |
| 1702 // - multiple encoders + decoders | 1739 // - multiple encoders + decoders |
| 1703 // - mid-stream encoder_->Destroy() | 1740 // - mid-stream encoder_->Destroy() |
| 1704 | 1741 |
| 1705 } // namespace | 1742 } // namespace |
| 1706 } // namespace content | 1743 } // namespace content |
| 1707 | 1744 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1785 | 1822 |
| 1786 content::g_env = | 1823 content::g_env = |
| 1787 reinterpret_cast<content::VideoEncodeAcceleratorTestEnvironment*>( | 1824 reinterpret_cast<content::VideoEncodeAcceleratorTestEnvironment*>( |
| 1788 testing::AddGlobalTestEnvironment( | 1825 testing::AddGlobalTestEnvironment( |
| 1789 new content::VideoEncodeAcceleratorTestEnvironment( | 1826 new content::VideoEncodeAcceleratorTestEnvironment( |
| 1790 std::move(test_stream_data), log_path, run_at_fps, | 1827 std::move(test_stream_data), log_path, run_at_fps, |
| 1791 needs_encode_latency, verify_all_output))); | 1828 needs_encode_latency, verify_all_output))); |
| 1792 | 1829 |
| 1793 return RUN_ALL_TESTS(); | 1830 return RUN_ALL_TESTS(); |
| 1794 } | 1831 } |
| OLD | NEW |