| 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 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 } | 196 } |
| 197 | 197 |
| 198 void deallocate(pointer p, size_type n) { | 198 void deallocate(pointer p, size_type n) { |
| 199 base::AlignedFree(static_cast<void*>(p)); | 199 base::AlignedFree(static_cast<void*>(p)); |
| 200 } | 200 } |
| 201 | 201 |
| 202 size_type max_size() const { | 202 size_type max_size() const { |
| 203 return std::numeric_limits<size_t>::max() / sizeof(T); | 203 return std::numeric_limits<size_t>::max() / sizeof(T); |
| 204 } | 204 } |
| 205 }; | 205 }; |
| 206 typedef std::vector<char, AlignedAllocator<char, kPlatformBufferAlignment>> | |
| 207 AlignedCharVector; | |
| 208 | 206 |
| 209 struct TestStream { | 207 struct TestStream { |
| 210 TestStream() | 208 TestStream() |
| 211 : num_frames(0), | 209 : num_frames(0), |
| 212 aligned_buffer_size(0), | 210 aligned_buffer_size(0), |
| 213 requested_bitrate(0), | 211 requested_bitrate(0), |
| 214 requested_framerate(0), | 212 requested_framerate(0), |
| 215 requested_subsequent_bitrate(0), | 213 requested_subsequent_bitrate(0), |
| 216 requested_subsequent_framerate(0) {} | 214 requested_subsequent_framerate(0) {} |
| 217 ~TestStream() {} | 215 ~TestStream() {} |
| 218 | 216 |
| 219 gfx::Size visible_size; | 217 gfx::Size visible_size; |
| 220 gfx::Size coded_size; | 218 gfx::Size coded_size; |
| 221 unsigned int num_frames; | 219 unsigned int num_frames; |
| 222 | 220 |
| 223 // Original unaligned input file name provided as an argument to the test. | 221 // Original unaligned input file name provided as an argument to the test. |
| 224 // And the file must be an I420 (YUV planar) raw stream. | 222 // And the file must be an I420 (YUV planar) raw stream. |
| 225 std::string in_filename; | 223 std::string in_filename; |
| 226 | 224 |
| 227 // A vector used to prepare aligned input buffers of |in_filename|. This | 225 // A vector used to prepare aligned input buffers of |in_filename|. This |
| 228 // makes sure starting addresses of YUV planes are aligned to | 226 // makes sure starting addresses of YUV planes are aligned to |
| 229 // kPlatformBufferAlignment bytes. | 227 // kPlatformBufferAlignment bytes. |
| 230 AlignedCharVector aligned_in_file_data; | 228 std::vector<char, AlignedAllocator<char, kPlatformBufferAlignment>> |
| 229 aligned_in_file_data; |
| 231 | 230 |
| 232 // Byte size of a frame of |aligned_in_file_data|. | 231 // Byte size of a frame of |aligned_in_file_data|. |
| 233 size_t aligned_buffer_size; | 232 size_t aligned_buffer_size; |
| 234 | 233 |
| 235 // Byte size for each aligned plane of a frame. | 234 // Byte size for each aligned plane of a frame. |
| 236 std::vector<size_t> aligned_plane_size; | 235 std::vector<size_t> aligned_plane_size; |
| 237 | 236 |
| 238 std::string out_filename; | 237 std::string out_filename; |
| 239 VideoCodecProfile requested_profile; | 238 VideoCodecProfile requested_profile; |
| 240 unsigned int requested_bitrate; | 239 unsigned int requested_bitrate; |
| (...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 868 } | 867 } |
| 869 } | 868 } |
| 870 } | 869 } |
| 871 | 870 |
| 872 // Divide the difference by the size of frame. | 871 // Divide the difference by the size of frame. |
| 873 difference /= VideoFrame::AllocationSize(kInputFormat, visible_size); | 872 difference /= VideoFrame::AllocationSize(kInputFormat, visible_size); |
| 874 EXPECT_TRUE(difference <= kDecodeSimilarityThreshold) | 873 EXPECT_TRUE(difference <= kDecodeSimilarityThreshold) |
| 875 << "difference = " << difference << " > decode similarity threshold"; | 874 << "difference = " << difference << " > decode similarity threshold"; |
| 876 } | 875 } |
| 877 | 876 |
| 878 // Base class for all VEA Clients in this file | 877 class VEAClient : public VideoEncodeAccelerator::Client { |
| 879 class VEAClientBase : public VideoEncodeAccelerator::Client { | |
| 880 public: | |
| 881 ~VEAClientBase() override { LOG_ASSERT(!has_encoder()); } | |
| 882 void NotifyError(VideoEncodeAccelerator::Error error) override { | |
| 883 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 884 SetState(CS_ERROR); | |
| 885 } | |
| 886 | |
| 887 protected: | |
| 888 VEAClientBase(ClientStateNotification<ClientState>* note) | |
| 889 : note_(note), next_output_buffer_id_(0) {} | |
| 890 | |
| 891 bool has_encoder() { return encoder_.get(); } | |
| 892 | |
| 893 virtual void SetState(ClientState new_state) = 0; | |
| 894 | |
| 895 std::unique_ptr<VideoEncodeAccelerator> encoder_; | |
| 896 | |
| 897 // Used to notify another thread about the state. VEAClientBase does not own | |
| 898 // this. | |
| 899 ClientStateNotification<ClientState>* note_; | |
| 900 | |
| 901 // All methods of this class should be run on the same thread. | |
| 902 base::ThreadChecker thread_checker_; | |
| 903 | |
| 904 ScopedVector<base::SharedMemory> output_shms_; | |
| 905 int32_t next_output_buffer_id_; | |
| 906 }; | |
| 907 | |
| 908 class VEAClient : public VEAClientBase { | |
| 909 public: | 878 public: |
| 910 VEAClient(TestStream* test_stream, | 879 VEAClient(TestStream* test_stream, |
| 911 ClientStateNotification<ClientState>* note, | 880 ClientStateNotification<ClientState>* note, |
| 912 bool save_to_file, | 881 bool save_to_file, |
| 913 unsigned int keyframe_period, | 882 unsigned int keyframe_period, |
| 914 bool force_bitrate, | 883 bool force_bitrate, |
| 915 bool test_perf, | 884 bool test_perf, |
| 916 bool mid_stream_bitrate_switch, | 885 bool mid_stream_bitrate_switch, |
| 917 bool mid_stream_framerate_switch, | 886 bool mid_stream_framerate_switch, |
| 918 bool verify_output, | 887 bool verify_output, |
| 919 bool verify_output_timestamp); | 888 bool verify_output_timestamp); |
| 889 ~VEAClient() override; |
| 920 void CreateEncoder(); | 890 void CreateEncoder(); |
| 921 void DestroyEncoder(); | 891 void DestroyEncoder(); |
| 922 | 892 |
| 923 void TryToSetupEncodeOnSeperateThread(); | 893 void TryToSetupEncodeOnSeperateThread(); |
| 924 void DestroyEncodeOnSeperateThread(); | 894 void DestroyEncodeOnSeperateThread(); |
| 925 | 895 |
| 926 // VideoDecodeAccelerator::Client implementation. | 896 // VideoDecodeAccelerator::Client implementation. |
| 927 void RequireBitstreamBuffers(unsigned int input_count, | 897 void RequireBitstreamBuffers(unsigned int input_count, |
| 928 const gfx::Size& input_coded_size, | 898 const gfx::Size& input_coded_size, |
| 929 size_t output_buffer_size) override; | 899 size_t output_buffer_size) override; |
| 930 void BitstreamBufferReady(int32_t bitstream_buffer_id, | 900 void BitstreamBufferReady(int32_t bitstream_buffer_id, |
| 931 size_t payload_size, | 901 size_t payload_size, |
| 932 bool key_frame, | 902 bool key_frame, |
| 933 base::TimeDelta timestamp) override; | 903 base::TimeDelta timestamp) override; |
| 904 void NotifyError(VideoEncodeAccelerator::Error error) override; |
| 934 | 905 |
| 935 private: | 906 private: |
| 936 void BitstreamBufferReadyOnMainThread(int32_t bitstream_buffer_id, | 907 void BitstreamBufferReadyOnMainThread(int32_t bitstream_buffer_id, |
| 937 size_t payload_size, | 908 size_t payload_size, |
| 938 bool key_frame, | 909 bool key_frame, |
| 939 base::TimeDelta timestamp); | 910 base::TimeDelta timestamp); |
| 911 bool has_encoder() { return encoder_.get(); } |
| 940 | 912 |
| 941 // Return the number of encoded frames per second. | 913 // Return the number of encoded frames per second. |
| 942 double frames_per_second(); | 914 double frames_per_second(); |
| 943 | 915 |
| 944 void SetState(ClientState new_state) override; | 916 void SetState(ClientState new_state); |
| 945 | 917 |
| 946 // Set current stream parameters to given |bitrate| at |framerate|. | 918 // Set current stream parameters to given |bitrate| at |framerate|. |
| 947 void SetStreamParameters(unsigned int bitrate, unsigned int framerate); | 919 void SetStreamParameters(unsigned int bitrate, unsigned int framerate); |
| 948 | 920 |
| 949 // Called when encoder is done with a VideoFrame. | 921 // Called when encoder is done with a VideoFrame. |
| 950 void InputNoLongerNeededCallback(int32_t input_id); | 922 void InputNoLongerNeededCallback(int32_t input_id); |
| 951 | 923 |
| 952 // Feed the encoder with one input frame. | 924 // Feed the encoder with one input frame. |
| 953 void FeedEncoderWithOneInput(); | 925 void FeedEncoderWithOneInput(); |
| 954 | 926 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 999 // Called when the quality validator has decoded all the frames. | 971 // Called when the quality validator has decoded all the frames. |
| 1000 void DecodeCompleted(); | 972 void DecodeCompleted(); |
| 1001 | 973 |
| 1002 // Called when the quality validator fails to decode a frame. | 974 // Called when the quality validator fails to decode a frame. |
| 1003 void DecodeFailed(); | 975 void DecodeFailed(); |
| 1004 | 976 |
| 1005 // Verify that the output timestamp matches input timestamp. | 977 // Verify that the output timestamp matches input timestamp. |
| 1006 void VerifyOutputTimestamp(base::TimeDelta timestamp); | 978 void VerifyOutputTimestamp(base::TimeDelta timestamp); |
| 1007 | 979 |
| 1008 ClientState state_; | 980 ClientState state_; |
| 981 std::unique_ptr<VideoEncodeAccelerator> encoder_; |
| 1009 | 982 |
| 1010 TestStream* test_stream_; | 983 TestStream* test_stream_; |
| 1011 | 984 |
| 985 // Used to notify another thread about the state. VEAClient does not own this. |
| 986 ClientStateNotification<ClientState>* note_; |
| 987 |
| 1012 // Ids assigned to VideoFrames. | 988 // Ids assigned to VideoFrames. |
| 1013 std::set<int32_t> inputs_at_client_; | 989 std::set<int32_t> inputs_at_client_; |
| 1014 int32_t next_input_id_; | 990 int32_t next_input_id_; |
| 1015 | 991 |
| 1016 // Encode start time of all encoded frames. The position in the vector is the | 992 // Encode start time of all encoded frames. The position in the vector is the |
| 1017 // frame input id. | 993 // frame input id. |
| 1018 std::vector<base::TimeTicks> encode_start_time_; | 994 std::vector<base::TimeTicks> encode_start_time_; |
| 1019 // The encode latencies of all encoded frames. We define encode latency as the | 995 // The encode latencies of all encoded frames. We define encode latency as the |
| 1020 // time delay from input of each VideoFrame (VEA::Encode()) to output of the | 996 // time delay from input of each VideoFrame (VEA::Encode()) to output of the |
| 1021 // corresponding BitstreamBuffer (VEA::Client::BitstreamBufferReady()). | 997 // corresponding BitstreamBuffer (VEA::Client::BitstreamBufferReady()). |
| 1022 std::vector<base::TimeDelta> encode_latencies_; | 998 std::vector<base::TimeDelta> encode_latencies_; |
| 1023 | 999 |
| 1024 // Ids for output BitstreamBuffers. | 1000 // Ids for output BitstreamBuffers. |
| 1025 typedef std::map<int32_t, base::SharedMemory*> IdToSHM; | 1001 typedef std::map<int32_t, base::SharedMemory*> IdToSHM; |
| 1002 ScopedVector<base::SharedMemory> output_shms_; |
| 1026 IdToSHM output_buffers_at_client_; | 1003 IdToSHM output_buffers_at_client_; |
| 1004 int32_t next_output_buffer_id_; |
| 1027 | 1005 |
| 1028 // Current offset into input stream. | 1006 // Current offset into input stream. |
| 1029 off_t pos_in_input_stream_; | 1007 off_t pos_in_input_stream_; |
| 1030 gfx::Size input_coded_size_; | 1008 gfx::Size input_coded_size_; |
| 1031 // Requested by encoder. | 1009 // Requested by encoder. |
| 1032 unsigned int num_required_input_buffers_; | 1010 unsigned int num_required_input_buffers_; |
| 1033 size_t output_buffer_size_; | 1011 size_t output_buffer_size_; |
| 1034 | 1012 |
| 1035 // Number of frames to encode. This may differ from the number of frames in | 1013 // Number of frames to encode. This may differ from the number of frames in |
| 1036 // stream if we need more frames for bitrate tests. | 1014 // stream if we need more frames for bitrate tests. |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1084 | 1062 |
| 1085 // Used to validate the encoded frame quality. | 1063 // Used to validate the encoded frame quality. |
| 1086 std::unique_ptr<VideoFrameQualityValidator> quality_validator_; | 1064 std::unique_ptr<VideoFrameQualityValidator> quality_validator_; |
| 1087 | 1065 |
| 1088 // The time when the first frame is submitted for encode. | 1066 // The time when the first frame is submitted for encode. |
| 1089 base::TimeTicks first_frame_start_time_; | 1067 base::TimeTicks first_frame_start_time_; |
| 1090 | 1068 |
| 1091 // The time when the last encoded frame is ready. | 1069 // The time when the last encoded frame is ready. |
| 1092 base::TimeTicks last_frame_ready_time_; | 1070 base::TimeTicks last_frame_ready_time_; |
| 1093 | 1071 |
| 1072 // All methods of this class should be run on the same thread. |
| 1073 base::ThreadChecker thread_checker_; |
| 1074 |
| 1094 // Requested bitrate in bits per second. | 1075 // Requested bitrate in bits per second. |
| 1095 unsigned int requested_bitrate_; | 1076 unsigned int requested_bitrate_; |
| 1096 | 1077 |
| 1097 // Requested initial framerate. | 1078 // Requested initial framerate. |
| 1098 unsigned int requested_framerate_; | 1079 unsigned int requested_framerate_; |
| 1099 | 1080 |
| 1100 // Bitrate to switch to in the middle of the stream. | 1081 // Bitrate to switch to in the middle of the stream. |
| 1101 unsigned int requested_subsequent_bitrate_; | 1082 unsigned int requested_subsequent_bitrate_; |
| 1102 | 1083 |
| 1103 // Framerate to switch to in the middle of the stream. | 1084 // Framerate to switch to in the middle of the stream. |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1134 VEAClient::VEAClient(TestStream* test_stream, | 1115 VEAClient::VEAClient(TestStream* test_stream, |
| 1135 ClientStateNotification<ClientState>* note, | 1116 ClientStateNotification<ClientState>* note, |
| 1136 bool save_to_file, | 1117 bool save_to_file, |
| 1137 unsigned int keyframe_period, | 1118 unsigned int keyframe_period, |
| 1138 bool force_bitrate, | 1119 bool force_bitrate, |
| 1139 bool test_perf, | 1120 bool test_perf, |
| 1140 bool mid_stream_bitrate_switch, | 1121 bool mid_stream_bitrate_switch, |
| 1141 bool mid_stream_framerate_switch, | 1122 bool mid_stream_framerate_switch, |
| 1142 bool verify_output, | 1123 bool verify_output, |
| 1143 bool verify_output_timestamp) | 1124 bool verify_output_timestamp) |
| 1144 : VEAClientBase(note), | 1125 : state_(CS_CREATED), |
| 1145 state_(CS_CREATED), | |
| 1146 test_stream_(test_stream), | 1126 test_stream_(test_stream), |
| 1127 note_(note), |
| 1147 next_input_id_(0), | 1128 next_input_id_(0), |
| 1129 next_output_buffer_id_(0), |
| 1148 pos_in_input_stream_(0), | 1130 pos_in_input_stream_(0), |
| 1149 num_required_input_buffers_(0), | 1131 num_required_input_buffers_(0), |
| 1150 output_buffer_size_(0), | 1132 output_buffer_size_(0), |
| 1151 num_frames_to_encode_(0), | 1133 num_frames_to_encode_(0), |
| 1152 num_encoded_frames_(0), | 1134 num_encoded_frames_(0), |
| 1153 num_frames_since_last_check_(0), | 1135 num_frames_since_last_check_(0), |
| 1154 seen_keyframe_in_this_buffer_(false), | 1136 seen_keyframe_in_this_buffer_(false), |
| 1155 save_to_file_(save_to_file), | 1137 save_to_file_(save_to_file), |
| 1156 keyframe_period_(keyframe_period), | 1138 keyframe_period_(keyframe_period), |
| 1157 num_keyframes_requested_(0), | 1139 num_keyframes_requested_(0), |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1191 // Without it, AppendToFile() will not work. | 1173 // Without it, AppendToFile() will not work. |
| 1192 EXPECT_EQ(0, base::WriteFile(out_filename, NULL, 0)); | 1174 EXPECT_EQ(0, base::WriteFile(out_filename, NULL, 0)); |
| 1193 } | 1175 } |
| 1194 | 1176 |
| 1195 // Initialize the parameters of the test streams. | 1177 // Initialize the parameters of the test streams. |
| 1196 UpdateTestStreamData(mid_stream_bitrate_switch, mid_stream_framerate_switch); | 1178 UpdateTestStreamData(mid_stream_bitrate_switch, mid_stream_framerate_switch); |
| 1197 | 1179 |
| 1198 thread_checker_.DetachFromThread(); | 1180 thread_checker_.DetachFromThread(); |
| 1199 } | 1181 } |
| 1200 | 1182 |
| 1183 VEAClient::~VEAClient() { |
| 1184 LOG_ASSERT(!has_encoder()); |
| 1185 } |
| 1186 |
| 1201 void VEAClient::CreateEncoder() { | 1187 void VEAClient::CreateEncoder() { |
| 1202 DCHECK(thread_checker_.CalledOnValidThread()); | 1188 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1203 LOG_ASSERT(!has_encoder()); | 1189 LOG_ASSERT(!has_encoder()); |
| 1204 | 1190 |
| 1205 main_thread_task_runner_ = base::ThreadTaskRunnerHandle::Get(); | 1191 main_thread_task_runner_ = base::ThreadTaskRunnerHandle::Get(); |
| 1206 encode_task_runner_ = main_thread_task_runner_; | 1192 encode_task_runner_ = main_thread_task_runner_; |
| 1207 | 1193 |
| 1208 std::unique_ptr<VideoEncodeAccelerator> encoders[] = { | 1194 std::unique_ptr<VideoEncodeAccelerator> encoders[] = { |
| 1209 CreateFakeVEA(), CreateV4L2VEA(), CreateVaapiVEA(), CreateVTVEA(), | 1195 CreateFakeVEA(), CreateV4L2VEA(), CreateVaapiVEA(), CreateVTVEA(), |
| 1210 CreateMFVEA()}; | 1196 CreateMFVEA()}; |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1411 size_t payload_size, | 1397 size_t payload_size, |
| 1412 bool key_frame, | 1398 bool key_frame, |
| 1413 base::TimeDelta timestamp) { | 1399 base::TimeDelta timestamp) { |
| 1414 ASSERT_TRUE(encode_task_runner_->BelongsToCurrentThread()); | 1400 ASSERT_TRUE(encode_task_runner_->BelongsToCurrentThread()); |
| 1415 main_thread_task_runner_->PostTask( | 1401 main_thread_task_runner_->PostTask( |
| 1416 FROM_HERE, base::Bind(&VEAClient::BitstreamBufferReadyOnMainThread, | 1402 FROM_HERE, base::Bind(&VEAClient::BitstreamBufferReadyOnMainThread, |
| 1417 base::Unretained(this), bitstream_buffer_id, | 1403 base::Unretained(this), bitstream_buffer_id, |
| 1418 payload_size, key_frame, timestamp)); | 1404 payload_size, key_frame, timestamp)); |
| 1419 } | 1405 } |
| 1420 | 1406 |
| 1407 void VEAClient::NotifyError(VideoEncodeAccelerator::Error error) { |
| 1408 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1409 SetState(CS_ERROR); |
| 1410 } |
| 1411 |
| 1421 void VEAClient::BitstreamBufferReadyOnMainThread(int32_t bitstream_buffer_id, | 1412 void VEAClient::BitstreamBufferReadyOnMainThread(int32_t bitstream_buffer_id, |
| 1422 size_t payload_size, | 1413 size_t payload_size, |
| 1423 bool key_frame, | 1414 bool key_frame, |
| 1424 base::TimeDelta timestamp) { | 1415 base::TimeDelta timestamp) { |
| 1425 DCHECK(thread_checker_.CalledOnValidThread()); | 1416 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1426 | 1417 |
| 1427 ASSERT_LE(payload_size, output_buffer_size_); | 1418 ASSERT_LE(payload_size, output_buffer_size_); |
| 1428 | 1419 |
| 1429 IdToSHM::iterator it = output_buffers_at_client_.find(bitstream_buffer_id); | 1420 IdToSHM::iterator it = output_buffers_at_client_.find(bitstream_buffer_id); |
| 1430 ASSERT_NE(it, output_buffers_at_client_.end()); | 1421 ASSERT_NE(it, output_buffers_at_client_.end()); |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1761 IvfFrameHeader header = {}; | 1752 IvfFrameHeader header = {}; |
| 1762 | 1753 |
| 1763 header.frame_size = static_cast<uint32_t>(frame_size); | 1754 header.frame_size = static_cast<uint32_t>(frame_size); |
| 1764 header.timestamp = frame_index; | 1755 header.timestamp = frame_index; |
| 1765 header.ByteSwap(); | 1756 header.ByteSwap(); |
| 1766 EXPECT_TRUE(base::AppendToFile( | 1757 EXPECT_TRUE(base::AppendToFile( |
| 1767 base::FilePath::FromUTF8Unsafe(test_stream_->out_filename), | 1758 base::FilePath::FromUTF8Unsafe(test_stream_->out_filename), |
| 1768 reinterpret_cast<char*>(&header), sizeof(header))); | 1759 reinterpret_cast<char*>(&header), sizeof(header))); |
| 1769 } | 1760 } |
| 1770 | 1761 |
| 1771 // Base class for simple VEA Clients | 1762 // This client is only used to make sure the encoder does not return an encoded |
| 1772 class SimpleVEAClientBase : public VEAClientBase { | 1763 // frame before getting any input. |
| 1764 class VEANoInputClient : public VideoEncodeAccelerator::Client { |
| 1773 public: | 1765 public: |
| 1766 explicit VEANoInputClient(ClientStateNotification<ClientState>* note); |
| 1767 ~VEANoInputClient() override; |
| 1774 void CreateEncoder(); | 1768 void CreateEncoder(); |
| 1775 void DestroyEncoder(); | 1769 void DestroyEncoder(); |
| 1776 | 1770 |
| 1777 // VideoDecodeAccelerator::Client implementation. | 1771 // VideoDecodeAccelerator::Client implementation. |
| 1778 void RequireBitstreamBuffers(unsigned int input_count, | |
| 1779 const gfx::Size& input_coded_size, | |
| 1780 size_t output_buffer_size) override; | |
| 1781 | |
| 1782 protected: | |
| 1783 SimpleVEAClientBase(ClientStateNotification<ClientState>* note, | |
| 1784 const int width, | |
| 1785 const int height); | |
| 1786 | |
| 1787 void SetState(ClientState new_state) override; | |
| 1788 | |
| 1789 // Provide the encoder with a new output buffer. | |
| 1790 void FeedEncoderWithOutput(base::SharedMemory* shm, size_t output_size); | |
| 1791 | |
| 1792 const int width_; | |
| 1793 const int height_; | |
| 1794 const int bitrate_; | |
| 1795 const int fps_; | |
| 1796 }; | |
| 1797 | |
| 1798 SimpleVEAClientBase::SimpleVEAClientBase( | |
| 1799 ClientStateNotification<ClientState>* note, | |
| 1800 const int width, | |
| 1801 const int height) | |
| 1802 : VEAClientBase(note), | |
| 1803 width_(width), | |
| 1804 height_(height), | |
| 1805 bitrate_(200000), | |
| 1806 fps_(30) { | |
| 1807 thread_checker_.DetachFromThread(); | |
| 1808 } | |
| 1809 | |
| 1810 void SimpleVEAClientBase::CreateEncoder() { | |
| 1811 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 1812 LOG_ASSERT(!has_encoder()); | |
| 1813 LOG_ASSERT(g_env->test_streams_.size()); | |
| 1814 | |
| 1815 std::unique_ptr<VideoEncodeAccelerator> encoders[] = { | |
| 1816 CreateFakeVEA(), CreateV4L2VEA(), CreateVaapiVEA(), CreateVTVEA(), | |
| 1817 CreateMFVEA()}; | |
| 1818 | |
| 1819 gfx::Size visible_size(width_, height_); | |
| 1820 for (auto& encoder : encoders) { | |
| 1821 if (!encoder) | |
| 1822 continue; | |
| 1823 encoder_ = std::move(encoder); | |
| 1824 if (encoder_->Initialize(kInputFormat, visible_size, | |
| 1825 g_env->test_streams_[0]->requested_profile, | |
| 1826 bitrate_, this)) { | |
| 1827 encoder_->RequestEncodingParametersChange(bitrate_, fps_); | |
| 1828 SetState(CS_INITIALIZED); | |
| 1829 return; | |
| 1830 } | |
| 1831 } | |
| 1832 encoder_.reset(); | |
| 1833 LOG(ERROR) << "VideoEncodeAccelerator::Initialize() failed"; | |
| 1834 SetState(CS_ERROR); | |
| 1835 } | |
| 1836 | |
| 1837 void SimpleVEAClientBase::DestroyEncoder() { | |
| 1838 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 1839 if (!has_encoder()) | |
| 1840 return; | |
| 1841 // Clear the objects that should be destroyed on the same thread as creation. | |
| 1842 encoder_.reset(); | |
| 1843 } | |
| 1844 | |
| 1845 void SimpleVEAClientBase::SetState(ClientState new_state) { | |
| 1846 DVLOG(4) << "Changing state to " << new_state; | |
| 1847 note_->Notify(new_state); | |
| 1848 } | |
| 1849 | |
| 1850 void SimpleVEAClientBase::RequireBitstreamBuffers( | |
| 1851 unsigned int input_count, | |
| 1852 const gfx::Size& input_coded_size, | |
| 1853 size_t output_size) { | |
| 1854 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 1855 SetState(CS_ENCODING); | |
| 1856 ASSERT_GT(output_size, 0UL); | |
| 1857 | |
| 1858 for (unsigned int i = 0; i < kNumOutputBuffers; ++i) { | |
| 1859 base::SharedMemory* shm = new base::SharedMemory(); | |
| 1860 LOG_ASSERT(shm->CreateAndMapAnonymous(output_size)); | |
| 1861 output_shms_.push_back(shm); | |
| 1862 FeedEncoderWithOutput(shm, output_size); | |
| 1863 } | |
| 1864 } | |
| 1865 | |
| 1866 void SimpleVEAClientBase::FeedEncoderWithOutput(base::SharedMemory* shm, | |
| 1867 size_t output_size) { | |
| 1868 if (!has_encoder()) | |
| 1869 return; | |
| 1870 | |
| 1871 base::SharedMemoryHandle dup_handle; | |
| 1872 LOG_ASSERT(shm->ShareToProcess(base::GetCurrentProcessHandle(), &dup_handle)); | |
| 1873 | |
| 1874 BitstreamBuffer bitstream_buffer(next_output_buffer_id_++, dup_handle, | |
| 1875 output_size); | |
| 1876 encoder_->UseOutputBitstreamBuffer(bitstream_buffer); | |
| 1877 } | |
| 1878 | |
| 1879 // This client is only used to make sure the encoder does not return an encoded | |
| 1880 // frame before getting any input. | |
| 1881 class VEANoInputClient : public SimpleVEAClientBase { | |
| 1882 public: | |
| 1883 explicit VEANoInputClient(ClientStateNotification<ClientState>* note); | |
| 1884 void DestroyEncoder(); | |
| 1885 | |
| 1886 // VideoDecodeAccelerator::Client implementation. | |
| 1887 void RequireBitstreamBuffers(unsigned int input_count, | 1772 void RequireBitstreamBuffers(unsigned int input_count, |
| 1888 const gfx::Size& input_coded_size, | 1773 const gfx::Size& input_coded_size, |
| 1889 size_t output_buffer_size) override; | 1774 size_t output_buffer_size) override; |
| 1890 void BitstreamBufferReady(int32_t bitstream_buffer_id, | 1775 void BitstreamBufferReady(int32_t bitstream_buffer_id, |
| 1891 size_t payload_size, | 1776 size_t payload_size, |
| 1892 bool key_frame, | 1777 bool key_frame, |
| 1893 base::TimeDelta timestamp) override; | 1778 base::TimeDelta timestamp) override; |
| 1779 void NotifyError(VideoEncodeAccelerator::Error error) override; |
| 1894 | 1780 |
| 1895 private: | 1781 private: |
| 1782 bool has_encoder() { return encoder_.get(); } |
| 1783 |
| 1784 void SetState(ClientState new_state); |
| 1785 |
| 1786 // Provide the encoder with a new output buffer. |
| 1787 void FeedEncoderWithOutput(base::SharedMemory* shm, size_t output_size); |
| 1788 |
| 1789 std::unique_ptr<VideoEncodeAccelerator> encoder_; |
| 1790 |
| 1791 // Used to notify another thread about the state. VEAClient does not own this. |
| 1792 ClientStateNotification<ClientState>* note_; |
| 1793 |
| 1794 // All methods of this class should be run on the same thread. |
| 1795 base::ThreadChecker thread_checker_; |
| 1796 |
| 1797 // Ids for output BitstreamBuffers. |
| 1798 ScopedVector<base::SharedMemory> output_shms_; |
| 1799 int32_t next_output_buffer_id_; |
| 1800 |
| 1896 // The timer used to monitor the encoder doesn't return an output buffer in | 1801 // The timer used to monitor the encoder doesn't return an output buffer in |
| 1897 // a period of time. | 1802 // a period of time. |
| 1898 std::unique_ptr<base::Timer> timer_; | 1803 std::unique_ptr<base::Timer> timer_; |
| 1899 }; | 1804 }; |
| 1900 | 1805 |
| 1901 VEANoInputClient::VEANoInputClient(ClientStateNotification<ClientState>* note) | 1806 VEANoInputClient::VEANoInputClient(ClientStateNotification<ClientState>* note) |
| 1902 : SimpleVEAClientBase(note, 320, 240) {} | 1807 : note_(note), next_output_buffer_id_(0) { |
| 1808 thread_checker_.DetachFromThread(); |
| 1809 } |
| 1810 |
| 1811 VEANoInputClient::~VEANoInputClient() { |
| 1812 LOG_ASSERT(!has_encoder()); |
| 1813 } |
| 1814 |
| 1815 void VEANoInputClient::CreateEncoder() { |
| 1816 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1817 LOG_ASSERT(!has_encoder()); |
| 1818 LOG_ASSERT(g_env->test_streams_.size()); |
| 1819 |
| 1820 const int kDefaultWidth = 320; |
| 1821 const int kDefaultHeight = 240; |
| 1822 const int kDefaultBitrate = 200000; |
| 1823 const int kDefaultFps = 30; |
| 1824 |
| 1825 std::unique_ptr<VideoEncodeAccelerator> encoders[] = { |
| 1826 CreateFakeVEA(), CreateV4L2VEA(), CreateVaapiVEA(), CreateVTVEA(), |
| 1827 CreateMFVEA()}; |
| 1828 |
| 1829 // The test case is no input. Use default visible size, bitrate, and fps. |
| 1830 gfx::Size visible_size(kDefaultWidth, kDefaultHeight); |
| 1831 for (auto& encoder : encoders) { |
| 1832 if (!encoder) |
| 1833 continue; |
| 1834 encoder_ = std::move(encoder); |
| 1835 if (encoder_->Initialize(kInputFormat, visible_size, |
| 1836 g_env->test_streams_[0]->requested_profile, |
| 1837 kDefaultBitrate, this)) { |
| 1838 encoder_->RequestEncodingParametersChange(kDefaultBitrate, kDefaultFps); |
| 1839 SetState(CS_INITIALIZED); |
| 1840 return; |
| 1841 } |
| 1842 } |
| 1843 encoder_.reset(); |
| 1844 LOG(ERROR) << "VideoEncodeAccelerator::Initialize() failed"; |
| 1845 SetState(CS_ERROR); |
| 1846 } |
| 1903 | 1847 |
| 1904 void VEANoInputClient::DestroyEncoder() { | 1848 void VEANoInputClient::DestroyEncoder() { |
| 1905 SimpleVEAClientBase::DestroyEncoder(); | 1849 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1850 if (!has_encoder()) |
| 1851 return; |
| 1906 // Clear the objects that should be destroyed on the same thread as creation. | 1852 // Clear the objects that should be destroyed on the same thread as creation. |
| 1853 encoder_.reset(); |
| 1907 timer_.reset(); | 1854 timer_.reset(); |
| 1908 } | 1855 } |
| 1909 | 1856 |
| 1910 void VEANoInputClient::RequireBitstreamBuffers( | 1857 void VEANoInputClient::RequireBitstreamBuffers( |
| 1911 unsigned int input_count, | 1858 unsigned int input_count, |
| 1912 const gfx::Size& input_coded_size, | 1859 const gfx::Size& input_coded_size, |
| 1913 size_t output_size) { | 1860 size_t output_size) { |
| 1914 SimpleVEAClientBase::RequireBitstreamBuffers(input_count, input_coded_size, | 1861 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1915 output_size); | 1862 SetState(CS_ENCODING); |
| 1863 ASSERT_GT(output_size, 0UL); |
| 1916 | 1864 |
| 1865 for (unsigned int i = 0; i < kNumOutputBuffers; ++i) { |
| 1866 base::SharedMemory* shm = new base::SharedMemory(); |
| 1867 LOG_ASSERT(shm->CreateAndMapAnonymous(output_size)); |
| 1868 output_shms_.push_back(shm); |
| 1869 FeedEncoderWithOutput(shm, output_size); |
| 1870 } |
| 1917 // Timer is used to make sure there is no output frame in 100ms. | 1871 // Timer is used to make sure there is no output frame in 100ms. |
| 1918 timer_.reset(new base::Timer(FROM_HERE, | 1872 timer_.reset(new base::Timer(FROM_HERE, |
| 1919 base::TimeDelta::FromMilliseconds(100), | 1873 base::TimeDelta::FromMilliseconds(100), |
| 1920 base::Bind(&VEANoInputClient::SetState, | 1874 base::Bind(&VEANoInputClient::SetState, |
| 1921 base::Unretained(this), CS_FINISHED), | 1875 base::Unretained(this), CS_FINISHED), |
| 1922 false)); | 1876 false)); |
| 1923 timer_->Reset(); | 1877 timer_->Reset(); |
| 1924 } | 1878 } |
| 1925 | 1879 |
| 1926 void VEANoInputClient::BitstreamBufferReady(int32_t bitstream_buffer_id, | 1880 void VEANoInputClient::BitstreamBufferReady(int32_t bitstream_buffer_id, |
| 1927 size_t payload_size, | 1881 size_t payload_size, |
| 1928 bool key_frame, | 1882 bool key_frame, |
| 1929 base::TimeDelta timestamp) { | 1883 base::TimeDelta timestamp) { |
| 1930 DCHECK(thread_checker_.CalledOnValidThread()); | 1884 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1931 SetState(CS_ERROR); | 1885 SetState(CS_ERROR); |
| 1932 } | 1886 } |
| 1933 | 1887 |
| 1934 // This client is only used to test input frame with the size of U and V planes | 1888 void VEANoInputClient::NotifyError(VideoEncodeAccelerator::Error error) { |
| 1935 // unaligned to cache line. | 1889 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1936 // To have both width and height divisible by 16 but not 32 will make the size | 1890 SetState(CS_ERROR); |
| 1937 // of U/V plane (width * height / 4) unaligned to 128-byte cache line. | |
| 1938 class VEACacheLineUnalignedInputClient : public SimpleVEAClientBase { | |
| 1939 public: | |
| 1940 explicit VEACacheLineUnalignedInputClient( | |
| 1941 ClientStateNotification<ClientState>* note); | |
| 1942 | |
| 1943 // VideoDecodeAccelerator::Client implementation. | |
| 1944 void RequireBitstreamBuffers(unsigned int input_count, | |
| 1945 const gfx::Size& input_coded_size, | |
| 1946 size_t output_buffer_size) override; | |
| 1947 void BitstreamBufferReady(int32_t bitstream_buffer_id, | |
| 1948 size_t payload_size, | |
| 1949 bool key_frame, | |
| 1950 base::TimeDelta timestamp) override; | |
| 1951 | |
| 1952 private: | |
| 1953 // Feed the encoder with one input frame. | |
| 1954 void FeedEncoderWithOneInput(const gfx::Size& input_coded_size); | |
| 1955 }; | |
| 1956 | |
| 1957 VEACacheLineUnalignedInputClient::VEACacheLineUnalignedInputClient( | |
| 1958 ClientStateNotification<ClientState>* note) | |
| 1959 : SimpleVEAClientBase(note, 368, 368) { | |
| 1960 } // 368 is divisible by 16 but not 32 | |
| 1961 | |
| 1962 void VEACacheLineUnalignedInputClient::RequireBitstreamBuffers( | |
| 1963 unsigned int input_count, | |
| 1964 const gfx::Size& input_coded_size, | |
| 1965 size_t output_size) { | |
| 1966 SimpleVEAClientBase::RequireBitstreamBuffers(input_count, input_coded_size, | |
| 1967 output_size); | |
| 1968 | |
| 1969 FeedEncoderWithOneInput(input_coded_size); | |
| 1970 } | 1891 } |
| 1971 | 1892 |
| 1972 void VEACacheLineUnalignedInputClient::BitstreamBufferReady( | 1893 void VEANoInputClient::SetState(ClientState new_state) { |
| 1973 int32_t bitstream_buffer_id, | 1894 DVLOG(4) << "Changing state to " << new_state; |
| 1974 size_t payload_size, | 1895 note_->Notify(new_state); |
| 1975 bool key_frame, | |
| 1976 base::TimeDelta timestamp) { | |
| 1977 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 1978 // It's enough to encode just one frame. If plane size is not aligned, | |
| 1979 // VideoEncodeAccelerator::Encode will fail. | |
| 1980 SetState(CS_FINISHED); | |
| 1981 } | 1896 } |
| 1982 | 1897 |
| 1983 void VEACacheLineUnalignedInputClient::FeedEncoderWithOneInput( | 1898 void VEANoInputClient::FeedEncoderWithOutput(base::SharedMemory* shm, |
| 1984 const gfx::Size& input_coded_size) { | 1899 size_t output_size) { |
| 1985 if (!has_encoder()) | 1900 if (!has_encoder()) |
| 1986 return; | 1901 return; |
| 1987 | 1902 |
| 1988 AlignedCharVector aligned_plane[] = { | 1903 base::SharedMemoryHandle dup_handle; |
| 1989 AlignedCharVector( | 1904 LOG_ASSERT(shm->ShareToProcess(base::GetCurrentProcessHandle(), &dup_handle)); |
| 1990 VideoFrame::PlaneSize(kInputFormat, 0, input_coded_size).GetArea()), | |
| 1991 AlignedCharVector( | |
| 1992 VideoFrame::PlaneSize(kInputFormat, 1, input_coded_size).GetArea()), | |
| 1993 AlignedCharVector( | |
| 1994 VideoFrame::PlaneSize(kInputFormat, 2, input_coded_size).GetArea())}; | |
| 1995 uint8_t* frame_data_y = reinterpret_cast<uint8_t*>(&aligned_plane[0][0]); | |
| 1996 uint8_t* frame_data_u = reinterpret_cast<uint8_t*>(&aligned_plane[1][0]); | |
| 1997 uint8_t* frame_data_v = reinterpret_cast<uint8_t*>(&aligned_plane[2][0]); | |
| 1998 | 1905 |
| 1999 scoped_refptr<VideoFrame> video_frame = VideoFrame::WrapExternalYuvData( | 1906 BitstreamBuffer bitstream_buffer(next_output_buffer_id_++, dup_handle, |
| 2000 kInputFormat, input_coded_size, gfx::Rect(input_coded_size), | 1907 output_size); |
| 2001 input_coded_size, input_coded_size.width(), input_coded_size.width() / 2, | 1908 encoder_->UseOutputBitstreamBuffer(bitstream_buffer); |
| 2002 input_coded_size.width() / 2, frame_data_y, frame_data_u, frame_data_v, | |
| 2003 base::TimeDelta().FromMilliseconds(base::Time::kMillisecondsPerSecond / | |
| 2004 fps_)); | |
| 2005 | |
| 2006 encoder_->Encode(video_frame, false); | |
| 2007 } | 1909 } |
| 2008 | 1910 |
| 2009 // Test parameters: | 1911 // Test parameters: |
| 2010 // - Number of concurrent encoders. The value takes effect when there is only | 1912 // - Number of concurrent encoders. The value takes effect when there is only |
| 2011 // one input stream; otherwise, one encoder per input stream will be | 1913 // one input stream; otherwise, one encoder per input stream will be |
| 2012 // instantiated. | 1914 // instantiated. |
| 2013 // - If true, save output to file (provided an output filename was supplied). | 1915 // - If true, save output to file (provided an output filename was supplied). |
| 2014 // - Force a keyframe every n frames. | 1916 // - Force a keyframe every n frames. |
| 2015 // - Force bitrate; the actual required value is provided as a property | 1917 // - Force bitrate; the actual required value is provided as a property |
| 2016 // of the input stream, because it depends on stream type/resolution/etc. | 1918 // of the input stream, because it depends on stream type/resolution/etc. |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2082 for (size_t i = 0; i < num_concurrent_encoders; ++i) { | 1984 for (size_t i = 0; i < num_concurrent_encoders; ++i) { |
| 2083 encoder_thread.task_runner()->PostTask( | 1985 encoder_thread.task_runner()->PostTask( |
| 2084 FROM_HERE, | 1986 FROM_HERE, |
| 2085 base::Bind(&VEAClient::DestroyEncoder, base::Unretained(clients[i]))); | 1987 base::Bind(&VEAClient::DestroyEncoder, base::Unretained(clients[i]))); |
| 2086 } | 1988 } |
| 2087 | 1989 |
| 2088 // This ensures all tasks have finished. | 1990 // This ensures all tasks have finished. |
| 2089 encoder_thread.Stop(); | 1991 encoder_thread.Stop(); |
| 2090 } | 1992 } |
| 2091 | 1993 |
| 2092 // Test parameters: | |
| 2093 // - Test type | |
| 2094 // 0: No input test | |
| 2095 // 1: Cache line-unaligned test | |
| 2096 class VideoEncodeAcceleratorSimpleTest : public ::testing::TestWithParam<int> { | |
| 2097 }; | |
| 2098 | |
| 2099 template <class TestClient> | |
| 2100 void SimpleTestFunc() { | |
| 2101 std::unique_ptr<ClientStateNotification<ClientState>> note( | |
| 2102 new ClientStateNotification<ClientState>()); | |
| 2103 std::unique_ptr<TestClient> client(new TestClient(note.get())); | |
| 2104 base::Thread encoder_thread("EncoderThread"); | |
| 2105 ASSERT_TRUE(encoder_thread.Start()); | |
| 2106 | |
| 2107 encoder_thread.task_runner()->PostTask( | |
| 2108 FROM_HERE, | |
| 2109 base::Bind(&TestClient::CreateEncoder, base::Unretained(client.get()))); | |
| 2110 | |
| 2111 // Encoder must pass through states in this order. | |
| 2112 enum ClientState state_transitions[] = {CS_INITIALIZED, CS_ENCODING, | |
| 2113 CS_FINISHED}; | |
| 2114 | |
| 2115 for (const auto& state : state_transitions) { | |
| 2116 EXPECT_EQ(state, note->Wait()); | |
| 2117 } | |
| 2118 | |
| 2119 encoder_thread.task_runner()->PostTask( | |
| 2120 FROM_HERE, | |
| 2121 base::Bind(&TestClient::DestroyEncoder, base::Unretained(client.get()))); | |
| 2122 | |
| 2123 // This ensures all tasks have finished. | |
| 2124 encoder_thread.Stop(); | |
| 2125 } | |
| 2126 | |
| 2127 TEST_P(VideoEncodeAcceleratorSimpleTest, TestSimpleEncode) { | |
| 2128 const int test_type = GetParam(); | |
| 2129 ASSERT_LT(test_type, 2) << "Invalid test type=" << test_type; | |
| 2130 | |
| 2131 if (test_type == 0) | |
| 2132 SimpleTestFunc<VEANoInputClient>(); | |
| 2133 else if (test_type == 1) | |
| 2134 SimpleTestFunc<VEACacheLineUnalignedInputClient>(); | |
| 2135 } | |
| 2136 | |
| 2137 #if defined(OS_CHROMEOS) | 1994 #if defined(OS_CHROMEOS) |
| 2138 INSTANTIATE_TEST_CASE_P( | 1995 INSTANTIATE_TEST_CASE_P( |
| 2139 SimpleEncode, | 1996 SimpleEncode, |
| 2140 VideoEncodeAcceleratorTest, | 1997 VideoEncodeAcceleratorTest, |
| 2141 ::testing::Values( | 1998 ::testing::Values( |
| 2142 std::make_tuple(1, true, 0, false, false, false, false, false, false), | 1999 std::make_tuple(1, true, 0, false, false, false, false, false, false), |
| 2143 std::make_tuple(1, true, 0, false, false, false, false, true, false))); | 2000 std::make_tuple(1, true, 0, false, false, false, false, true, false))); |
| 2144 | 2001 |
| 2145 INSTANTIATE_TEST_CASE_P( | 2002 INSTANTIATE_TEST_CASE_P( |
| 2146 EncoderPerf, | 2003 EncoderPerf, |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2185 std::make_tuple(3, false, 0, false, false, false, false, false, false), | 2042 std::make_tuple(3, false, 0, false, false, false, false, false, false), |
| 2186 std::make_tuple(3, false, 0, true, false, false, true, false, false), | 2043 std::make_tuple(3, false, 0, true, false, false, true, false, false), |
| 2187 std::make_tuple(3, false, 0, true, false, true, false, false, false))); | 2044 std::make_tuple(3, false, 0, true, false, true, false, false, false))); |
| 2188 | 2045 |
| 2189 INSTANTIATE_TEST_CASE_P( | 2046 INSTANTIATE_TEST_CASE_P( |
| 2190 VerifyTimestamp, | 2047 VerifyTimestamp, |
| 2191 VideoEncodeAcceleratorTest, | 2048 VideoEncodeAcceleratorTest, |
| 2192 ::testing::Values( | 2049 ::testing::Values( |
| 2193 std::make_tuple(1, false, 0, false, false, false, false, false, true))); | 2050 std::make_tuple(1, false, 0, false, false, false, false, false, true))); |
| 2194 | 2051 |
| 2195 INSTANTIATE_TEST_CASE_P(NoInputTest, | 2052 TEST(VEANoInputTest, CheckOutput) { |
| 2196 VideoEncodeAcceleratorSimpleTest, | 2053 std::unique_ptr<ClientStateNotification<ClientState>> note( |
| 2197 ::testing::Values(0)); | 2054 new ClientStateNotification<ClientState>()); |
| 2055 std::unique_ptr<VEANoInputClient> client(new VEANoInputClient(note.get())); |
| 2056 base::Thread encoder_thread("EncoderThread"); |
| 2057 ASSERT_TRUE(encoder_thread.Start()); |
| 2198 | 2058 |
| 2199 INSTANTIATE_TEST_CASE_P(CacheLineUnalignedInputTest, | 2059 encoder_thread.task_runner()->PostTask( |
| 2200 VideoEncodeAcceleratorSimpleTest, | 2060 FROM_HERE, base::Bind(&VEANoInputClient::CreateEncoder, |
| 2201 ::testing::Values(1)); | 2061 base::Unretained(client.get()))); |
| 2062 |
| 2063 // Encoder must pass through states in this order. |
| 2064 enum ClientState state_transitions[] = {CS_INITIALIZED, CS_ENCODING, |
| 2065 CS_FINISHED}; |
| 2066 |
| 2067 for (const auto& state : state_transitions) { |
| 2068 ASSERT_EQ(state, note->Wait()); |
| 2069 } |
| 2070 |
| 2071 encoder_thread.task_runner()->PostTask( |
| 2072 FROM_HERE, base::Bind(&VEANoInputClient::DestroyEncoder, |
| 2073 base::Unretained(client.get()))); |
| 2074 |
| 2075 // This ensures all tasks have finished. |
| 2076 encoder_thread.Stop(); |
| 2077 } |
| 2202 | 2078 |
| 2203 #elif defined(OS_MACOSX) || defined(OS_WIN) | 2079 #elif defined(OS_MACOSX) || defined(OS_WIN) |
| 2204 INSTANTIATE_TEST_CASE_P( | 2080 INSTANTIATE_TEST_CASE_P( |
| 2205 SimpleEncode, | 2081 SimpleEncode, |
| 2206 VideoEncodeAcceleratorTest, | 2082 VideoEncodeAcceleratorTest, |
| 2207 ::testing::Values( | 2083 ::testing::Values( |
| 2208 std::make_tuple(1, true, 0, false, false, false, false, false, false), | 2084 std::make_tuple(1, true, 0, false, false, false, false, false, false), |
| 2209 std::make_tuple(1, true, 0, false, false, false, false, true, false))); | 2085 std::make_tuple(1, true, 0, false, false, false, false, true, false))); |
| 2210 | 2086 |
| 2211 INSTANTIATE_TEST_CASE_P( | 2087 INSTANTIATE_TEST_CASE_P( |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2323 | 2199 |
| 2324 media::g_env = | 2200 media::g_env = |
| 2325 reinterpret_cast<media::VideoEncodeAcceleratorTestEnvironment*>( | 2201 reinterpret_cast<media::VideoEncodeAcceleratorTestEnvironment*>( |
| 2326 testing::AddGlobalTestEnvironment( | 2202 testing::AddGlobalTestEnvironment( |
| 2327 new media::VideoEncodeAcceleratorTestEnvironment( | 2203 new media::VideoEncodeAcceleratorTestEnvironment( |
| 2328 std::move(test_stream_data), log_path, run_at_fps, | 2204 std::move(test_stream_data), log_path, run_at_fps, |
| 2329 needs_encode_latency, verify_all_output))); | 2205 needs_encode_latency, verify_all_output))); |
| 2330 | 2206 |
| 2331 return RUN_ALL_TESTS(); | 2207 return RUN_ALL_TESTS(); |
| 2332 } | 2208 } |
| OLD | NEW |