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