OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/at_exit.h" | 5 #include "base/at_exit.h" |
6 #include "base/bind.h" | 6 #include "base/bind.h" |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/files/memory_mapped_file.h" | 9 #include "base/files/memory_mapped_file.h" |
10 #include "base/memory/scoped_vector.h" | 10 #include "base/memory/scoped_vector.h" |
11 #include "base/numerics/safe_conversions.h" | 11 #include "base/numerics/safe_conversions.h" |
12 #include "base/process/process_handle.h" | 12 #include "base/process/process_handle.h" |
13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
14 #include "base/strings/string_split.h" | 14 #include "base/strings/string_split.h" |
15 #include "base/strings/stringprintf.h" | |
15 #include "base/sys_byteorder.h" | 16 #include "base/sys_byteorder.h" |
16 #include "base/time/time.h" | 17 #include "base/time/time.h" |
17 #include "base/timer/timer.h" | 18 #include "base/timer/timer.h" |
18 #include "content/common/gpu/media/video_accelerator_unittest_helpers.h" | 19 #include "content/common/gpu/media/video_accelerator_unittest_helpers.h" |
19 #include "media/base/bind_to_current_loop.h" | 20 #include "media/base/bind_to_current_loop.h" |
20 #include "media/base/bitstream_buffer.h" | 21 #include "media/base/bitstream_buffer.h" |
21 #include "media/base/test_data_util.h" | 22 #include "media/base/test_data_util.h" |
22 #include "media/filters/h264_parser.h" | 23 #include "media/filters/h264_parser.h" |
23 #include "media/video/fake_video_encode_accelerator.h" | 24 #include "media/video/fake_video_encode_accelerator.h" |
24 #include "media/video/video_encode_accelerator.h" | 25 #include "media/video/video_encode_accelerator.h" |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
349 } | 350 } |
350 | 351 |
351 if (fields.size() >= 9 && !fields[8].empty()) { | 352 if (fields.size() >= 9 && !fields[8].empty()) { |
352 CHECK(base::StringToUint(fields[8], | 353 CHECK(base::StringToUint(fields[8], |
353 &test_stream->requested_subsequent_framerate)); | 354 &test_stream->requested_subsequent_framerate)); |
354 } | 355 } |
355 test_streams->push_back(test_stream); | 356 test_streams->push_back(test_stream); |
356 } | 357 } |
357 } | 358 } |
358 | 359 |
360 // Basic test environment shared across multiple test cases. We only need to | |
361 // setup it once for all test cases. | |
362 // It helps | |
363 // - maintain test stream data and other test settings. | |
364 // - clean up temporary aligned files. | |
365 // - output log to file. | |
366 class VideoEncodeAcceleratorTestEnvironment : public ::testing::Environment { | |
367 public: | |
368 VideoEncodeAcceleratorTestEnvironment( | |
369 scoped_ptr<base::FilePath::StringType> data, | |
370 const base::FilePath& log_path, | |
371 bool run_at_fps) | |
372 : run_at_fps_(run_at_fps), | |
373 test_stream_data_(data.Pass()), | |
374 log_path_(log_path) {} | |
375 | |
376 virtual void SetUp() { | |
377 if (!log_path_.empty()) { | |
378 log_file_.reset(new base::File( | |
379 log_path_, base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE)); | |
380 CHECK(log_file_->IsValid()); | |
381 } | |
382 ParseAndReadTestStreamData(*test_stream_data_, &test_streams_); | |
383 } | |
384 | |
385 virtual void TearDown() { | |
386 for (size_t i = 0; i < test_streams_.size(); i++) { | |
387 base::DeleteFile(test_streams_[i]->aligned_in_file, false); | |
388 } | |
389 log_file_.reset(); | |
390 } | |
391 | |
392 void LogToFile(const std::string& s) { | |
393 if (log_file_) | |
394 log_file_->WriteAtCurrentPos(s.data(), s.length()); | |
395 } | |
396 | |
397 ScopedVector<TestStream> test_streams_; | |
398 bool run_at_fps_; | |
399 | |
400 private: | |
401 scoped_ptr<base::FilePath::StringType> test_stream_data_; | |
402 base::FilePath log_path_; | |
403 scoped_ptr<base::File> log_file_; | |
Pawel Osciak
2015/04/27 02:08:56
Please document the log format somewhere.
Justin Chuang
2015/04/27 07:42:05
Done.
| |
404 }; | |
405 | |
359 enum ClientState { | 406 enum ClientState { |
360 CS_CREATED, | 407 CS_CREATED, |
361 CS_ENCODER_SET, | 408 CS_ENCODER_SET, |
362 CS_INITIALIZED, | 409 CS_INITIALIZED, |
363 CS_ENCODING, | 410 CS_ENCODING, |
364 CS_FINISHED, | 411 CS_FINISHED, |
365 CS_ERROR, | 412 CS_ERROR, |
366 }; | 413 }; |
367 | 414 |
368 // Performs basic, codec-specific sanity checks on the stream buffers passed | 415 // Performs basic, codec-specific sanity checks on the stream buffers passed |
(...skipping 758 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1127 SetState(CS_FINISHED); | 1174 SetState(CS_FINISHED); |
1128 return false; | 1175 return false; |
1129 } | 1176 } |
1130 | 1177 |
1131 return true; | 1178 return true; |
1132 } | 1179 } |
1133 | 1180 |
1134 void VEAClient::VerifyPerf() { | 1181 void VEAClient::VerifyPerf() { |
1135 double measured_fps = frames_per_second(); | 1182 double measured_fps = frames_per_second(); |
1136 LOG(INFO) << "Measured encoder FPS: " << measured_fps; | 1183 LOG(INFO) << "Measured encoder FPS: " << measured_fps; |
1184 g_env->LogToFile( | |
1185 base::StringPrintf("Measured encoder FPS: %.3f", measured_fps)); | |
1137 if (test_perf_) | 1186 if (test_perf_) |
1138 EXPECT_GE(measured_fps, kMinPerfFPS); | 1187 EXPECT_GE(measured_fps, kMinPerfFPS); |
1139 } | 1188 } |
1140 | 1189 |
1141 void VEAClient::VerifyStreamProperties() { | 1190 void VEAClient::VerifyStreamProperties() { |
1142 CHECK_GT(num_frames_since_last_check_, 0UL); | 1191 CHECK_GT(num_frames_since_last_check_, 0UL); |
1143 CHECK_GT(encoded_stream_size_since_last_check_, 0UL); | 1192 CHECK_GT(encoded_stream_size_since_last_check_, 0UL); |
1144 unsigned int bitrate = encoded_stream_size_since_last_check_ * 8 * | 1193 unsigned int bitrate = encoded_stream_size_since_last_check_ * 8 * |
1145 current_framerate_ / num_frames_since_last_check_; | 1194 current_framerate_ / num_frames_since_last_check_; |
1146 DVLOG(1) << "Current chunk's bitrate: " << bitrate | 1195 DVLOG(1) << "Current chunk's bitrate: " << bitrate |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1194 IvfFrameHeader header; | 1243 IvfFrameHeader header; |
1195 | 1244 |
1196 memset(&header, 0, sizeof(header)); | 1245 memset(&header, 0, sizeof(header)); |
1197 header.frame_size = base::ByteSwapToLE32(frame_size); | 1246 header.frame_size = base::ByteSwapToLE32(frame_size); |
1198 header.timestamp = base::ByteSwapToLE64(frame_index); | 1247 header.timestamp = base::ByteSwapToLE64(frame_index); |
1199 EXPECT_TRUE(base::AppendToFile( | 1248 EXPECT_TRUE(base::AppendToFile( |
1200 base::FilePath::FromUTF8Unsafe(test_stream_->out_filename), | 1249 base::FilePath::FromUTF8Unsafe(test_stream_->out_filename), |
1201 reinterpret_cast<char*>(&header), sizeof(header))); | 1250 reinterpret_cast<char*>(&header), sizeof(header))); |
1202 } | 1251 } |
1203 | 1252 |
1204 // Setup test stream data and delete temporary aligned files at the beginning | |
1205 // and end of unittest. We only need to setup once for all test cases. | |
1206 class VideoEncodeAcceleratorTestEnvironment : public ::testing::Environment { | |
1207 public: | |
1208 VideoEncodeAcceleratorTestEnvironment( | |
1209 scoped_ptr<base::FilePath::StringType> data, | |
1210 bool run_at_fps) { | |
1211 test_stream_data_ = data.Pass(); | |
1212 run_at_fps_ = run_at_fps; | |
1213 } | |
1214 | |
1215 virtual void SetUp() { | |
1216 ParseAndReadTestStreamData(*test_stream_data_, &test_streams_); | |
1217 } | |
1218 | |
1219 virtual void TearDown() { | |
1220 for (size_t i = 0; i < test_streams_.size(); i++) { | |
1221 base::DeleteFile(test_streams_[i]->aligned_in_file, false); | |
1222 } | |
1223 } | |
1224 | |
1225 ScopedVector<TestStream> test_streams_; | |
1226 bool run_at_fps_; | |
1227 | |
1228 private: | |
1229 scoped_ptr<base::FilePath::StringType> test_stream_data_; | |
1230 }; | |
1231 | |
1232 // Test parameters: | 1253 // Test parameters: |
1233 // - Number of concurrent encoders. The value takes effect when there is only | 1254 // - Number of concurrent encoders. The value takes effect when there is only |
1234 // one input stream; otherwise, one encoder per input stream will be | 1255 // one input stream; otherwise, one encoder per input stream will be |
1235 // instantiated. | 1256 // instantiated. |
1236 // - If true, save output to file (provided an output filename was supplied). | 1257 // - If true, save output to file (provided an output filename was supplied). |
1237 // - Force a keyframe every n frames. | 1258 // - Force a keyframe every n frames. |
1238 // - Force bitrate; the actual required value is provided as a property | 1259 // - Force bitrate; the actual required value is provided as a property |
1239 // of the input stream, because it depends on stream type/resolution/etc. | 1260 // of the input stream, because it depends on stream type/resolution/etc. |
1240 // - If true, measure performance. | 1261 // - If true, measure performance. |
1241 // - If true, switch bitrate mid-stream. | 1262 // - If true, switch bitrate mid-stream. |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1372 | 1393 |
1373 // Needed to enable DVLOG through --vmodule. | 1394 // Needed to enable DVLOG through --vmodule. |
1374 logging::LoggingSettings settings; | 1395 logging::LoggingSettings settings; |
1375 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; | 1396 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; |
1376 CHECK(logging::InitLogging(settings)); | 1397 CHECK(logging::InitLogging(settings)); |
1377 | 1398 |
1378 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); | 1399 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); |
1379 DCHECK(cmd_line); | 1400 DCHECK(cmd_line); |
1380 | 1401 |
1381 bool run_at_fps = false; | 1402 bool run_at_fps = false; |
1403 base::FilePath log_path; | |
1404 | |
1382 base::CommandLine::SwitchMap switches = cmd_line->GetSwitches(); | 1405 base::CommandLine::SwitchMap switches = cmd_line->GetSwitches(); |
1383 for (base::CommandLine::SwitchMap::const_iterator it = switches.begin(); | 1406 for (base::CommandLine::SwitchMap::const_iterator it = switches.begin(); |
1384 it != switches.end(); | 1407 it != switches.end(); |
1385 ++it) { | 1408 ++it) { |
1386 if (it->first == "test_stream_data") { | 1409 if (it->first == "test_stream_data") { |
1387 test_stream_data->assign(it->second.c_str()); | 1410 test_stream_data->assign(it->second.c_str()); |
1388 continue; | 1411 continue; |
1389 } | 1412 } |
1413 // Output machine-readable logs with fixed formats to a file. | |
1414 if (it->first == "output_log") { | |
1415 log_path = base::FilePath( | |
1416 base::FilePath::StringType(it->second.begin(), it->second.end())); | |
Pawel Osciak
2015/04/27 02:08:56
Would
log_path = base::FilePath(it->second)
work
Justin Chuang
2015/04/27 07:42:05
it->second is base:string16 on OS_WIN, which is ws
| |
1417 continue; | |
1418 } | |
1390 if (it->first == "num_frames_to_encode") { | 1419 if (it->first == "num_frames_to_encode") { |
1391 std::string input(it->second.begin(), it->second.end()); | 1420 std::string input(it->second.begin(), it->second.end()); |
1392 CHECK(base::StringToInt(input, &content::g_num_frames_to_encode)); | 1421 CHECK(base::StringToInt(input, &content::g_num_frames_to_encode)); |
1393 continue; | 1422 continue; |
1394 } | 1423 } |
1395 if (it->first == "fake_encoder") { | 1424 if (it->first == "fake_encoder") { |
1396 content::g_fake_encoder = true; | 1425 content::g_fake_encoder = true; |
1397 continue; | 1426 continue; |
1398 } | 1427 } |
1399 if (it->first == "run_at_fps") { | 1428 if (it->first == "run_at_fps") { |
1400 run_at_fps = true; | 1429 run_at_fps = true; |
1401 continue; | 1430 continue; |
1402 } | 1431 } |
1403 if (it->first == "v" || it->first == "vmodule") | 1432 if (it->first == "v" || it->first == "vmodule") |
1404 continue; | 1433 continue; |
1405 if (it->first == "ozone-platform" || it->first == "ozone-use-surfaceless") | 1434 if (it->first == "ozone-platform" || it->first == "ozone-use-surfaceless") |
1406 continue; | 1435 continue; |
1407 LOG(FATAL) << "Unexpected switch: " << it->first << ":" << it->second; | 1436 LOG(FATAL) << "Unexpected switch: " << it->first << ":" << it->second; |
1408 } | 1437 } |
1409 | 1438 |
1410 content::g_env = | 1439 content::g_env = |
1411 reinterpret_cast<content::VideoEncodeAcceleratorTestEnvironment*>( | 1440 reinterpret_cast<content::VideoEncodeAcceleratorTestEnvironment*>( |
1412 testing::AddGlobalTestEnvironment( | 1441 testing::AddGlobalTestEnvironment( |
1413 new content::VideoEncodeAcceleratorTestEnvironment( | 1442 new content::VideoEncodeAcceleratorTestEnvironment( |
1414 test_stream_data.Pass(), run_at_fps))); | 1443 test_stream_data.Pass(), log_path, run_at_fps))); |
1415 | 1444 |
1416 return RUN_ALL_TESTS(); | 1445 return RUN_ALL_TESTS(); |
1417 } | 1446 } |
OLD | NEW |