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