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 "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 // Setup test stream data and delete temporary aligned files at the beginning | |
| 361 // and end of unittest. We only need to setup once for all test cases. | |
|
Owen Lin
2015/04/24 05:10:32
I only see the temporary aligned file getting dele
Justin Chuang
2015/04/24 14:34:00
Done. PTAL again
| |
| 362 class VideoEncodeAcceleratorTestEnvironment : public ::testing::Environment { | |
| 363 public: | |
| 364 VideoEncodeAcceleratorTestEnvironment( | |
| 365 scoped_ptr<base::FilePath::StringType> data, | |
| 366 const base::FilePath& log_path, | |
| 367 bool run_at_fps) | |
| 368 : log_path_(log_path) { | |
| 369 test_stream_data_ = data.Pass(); | |
|
Owen Lin
2015/04/24 05:10:32
Move these two lines into the initializer list.
Justin Chuang
2015/04/24 14:34:00
Done.
| |
| 370 run_at_fps_ = run_at_fps; | |
| 371 } | |
| 372 | |
| 373 virtual void SetUp() { | |
| 374 if (!log_path_.empty()) { | |
| 375 log_file_.reset(new base::File( | |
| 376 log_path_, base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE)); | |
| 377 CHECK(log_file_->IsValid()); | |
| 378 } | |
| 379 ParseAndReadTestStreamData(*test_stream_data_, &test_streams_); | |
| 380 } | |
| 381 | |
| 382 virtual void TearDown() { | |
| 383 for (size_t i = 0; i < test_streams_.size(); i++) { | |
| 384 base::DeleteFile(test_streams_[i]->aligned_in_file, false); | |
| 385 } | |
| 386 if (log_file_.get()) | |
|
Owen Lin
2015/04/24 05:10:32
log_file_.reset() should works.
https://code.goog
Justin Chuang
2015/04/24 14:34:00
Cool. Thanks
| |
| 387 log_file_->Close(); | |
| 388 } | |
| 389 | |
| 390 void LogToFile(const std::string& s) { | |
| 391 if (log_file_.get()) | |
|
Owen Lin
2015/04/24 05:10:32
if (log_file_)
Justin Chuang
2015/04/24 14:34:00
Done.
| |
| 392 log_file_->WriteAtCurrentPos(s.data(), s.length()); | |
| 393 } | |
| 394 | |
| 395 ScopedVector<TestStream> test_streams_; | |
| 396 bool run_at_fps_; | |
| 397 | |
| 398 private: | |
| 399 scoped_ptr<base::FilePath::StringType> test_stream_data_; | |
| 400 base::FilePath log_path_; | |
| 401 scoped_ptr<base::File> log_file_; | |
| 402 }; | |
| 403 | |
| 359 enum ClientState { | 404 enum ClientState { |
| 360 CS_CREATED, | 405 CS_CREATED, |
| 361 CS_ENCODER_SET, | 406 CS_ENCODER_SET, |
| 362 CS_INITIALIZED, | 407 CS_INITIALIZED, |
| 363 CS_ENCODING, | 408 CS_ENCODING, |
| 364 CS_FINISHED, | 409 CS_FINISHED, |
| 365 CS_ERROR, | 410 CS_ERROR, |
| 366 }; | 411 }; |
| 367 | 412 |
| 368 // Performs basic, codec-specific sanity checks on the stream buffers passed | 413 // 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); | 1172 SetState(CS_FINISHED); |
| 1128 return false; | 1173 return false; |
| 1129 } | 1174 } |
| 1130 | 1175 |
| 1131 return true; | 1176 return true; |
| 1132 } | 1177 } |
| 1133 | 1178 |
| 1134 void VEAClient::VerifyPerf() { | 1179 void VEAClient::VerifyPerf() { |
| 1135 double measured_fps = frames_per_second(); | 1180 double measured_fps = frames_per_second(); |
| 1136 LOG(INFO) << "Measured encoder FPS: " << measured_fps; | 1181 LOG(INFO) << "Measured encoder FPS: " << measured_fps; |
| 1182 g_env->LogToFile( | |
| 1183 base::StringPrintf("Measured encoder FPS: %.3f", measured_fps)); | |
| 1137 if (test_perf_) | 1184 if (test_perf_) |
| 1138 EXPECT_GE(measured_fps, kMinPerfFPS); | 1185 EXPECT_GE(measured_fps, kMinPerfFPS); |
| 1139 } | 1186 } |
| 1140 | 1187 |
| 1141 void VEAClient::VerifyStreamProperties() { | 1188 void VEAClient::VerifyStreamProperties() { |
| 1142 CHECK_GT(num_frames_since_last_check_, 0UL); | 1189 CHECK_GT(num_frames_since_last_check_, 0UL); |
| 1143 CHECK_GT(encoded_stream_size_since_last_check_, 0UL); | 1190 CHECK_GT(encoded_stream_size_since_last_check_, 0UL); |
| 1144 unsigned int bitrate = encoded_stream_size_since_last_check_ * 8 * | 1191 unsigned int bitrate = encoded_stream_size_since_last_check_ * 8 * |
| 1145 current_framerate_ / num_frames_since_last_check_; | 1192 current_framerate_ / num_frames_since_last_check_; |
| 1146 DVLOG(1) << "Current chunk's bitrate: " << bitrate | 1193 DVLOG(1) << "Current chunk's bitrate: " << bitrate |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1194 IvfFrameHeader header; | 1241 IvfFrameHeader header; |
| 1195 | 1242 |
| 1196 memset(&header, 0, sizeof(header)); | 1243 memset(&header, 0, sizeof(header)); |
| 1197 header.frame_size = base::ByteSwapToLE32(frame_size); | 1244 header.frame_size = base::ByteSwapToLE32(frame_size); |
| 1198 header.timestamp = base::ByteSwapToLE64(frame_index); | 1245 header.timestamp = base::ByteSwapToLE64(frame_index); |
| 1199 EXPECT_TRUE(base::AppendToFile( | 1246 EXPECT_TRUE(base::AppendToFile( |
| 1200 base::FilePath::FromUTF8Unsafe(test_stream_->out_filename), | 1247 base::FilePath::FromUTF8Unsafe(test_stream_->out_filename), |
| 1201 reinterpret_cast<char*>(&header), sizeof(header))); | 1248 reinterpret_cast<char*>(&header), sizeof(header))); |
| 1202 } | 1249 } |
| 1203 | 1250 |
| 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: | 1251 // Test parameters: |
| 1233 // - Number of concurrent encoders. The value takes effect when there is only | 1252 // - Number of concurrent encoders. The value takes effect when there is only |
| 1234 // one input stream; otherwise, one encoder per input stream will be | 1253 // one input stream; otherwise, one encoder per input stream will be |
| 1235 // instantiated. | 1254 // instantiated. |
| 1236 // - If true, save output to file (provided an output filename was supplied). | 1255 // - If true, save output to file (provided an output filename was supplied). |
| 1237 // - Force a keyframe every n frames. | 1256 // - Force a keyframe every n frames. |
| 1238 // - Force bitrate; the actual required value is provided as a property | 1257 // - Force bitrate; the actual required value is provided as a property |
| 1239 // of the input stream, because it depends on stream type/resolution/etc. | 1258 // of the input stream, because it depends on stream type/resolution/etc. |
| 1240 // - If true, measure performance. | 1259 // - If true, measure performance. |
| 1241 // - If true, switch bitrate mid-stream. | 1260 // - If true, switch bitrate mid-stream. |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1372 | 1391 |
| 1373 // Needed to enable DVLOG through --vmodule. | 1392 // Needed to enable DVLOG through --vmodule. |
| 1374 logging::LoggingSettings settings; | 1393 logging::LoggingSettings settings; |
| 1375 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; | 1394 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; |
| 1376 CHECK(logging::InitLogging(settings)); | 1395 CHECK(logging::InitLogging(settings)); |
| 1377 | 1396 |
| 1378 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); | 1397 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); |
| 1379 DCHECK(cmd_line); | 1398 DCHECK(cmd_line); |
| 1380 | 1399 |
| 1381 bool run_at_fps = false; | 1400 bool run_at_fps = false; |
| 1401 base::FilePath log_path; | |
| 1402 | |
| 1382 base::CommandLine::SwitchMap switches = cmd_line->GetSwitches(); | 1403 base::CommandLine::SwitchMap switches = cmd_line->GetSwitches(); |
| 1383 for (base::CommandLine::SwitchMap::const_iterator it = switches.begin(); | 1404 for (base::CommandLine::SwitchMap::const_iterator it = switches.begin(); |
| 1384 it != switches.end(); | 1405 it != switches.end(); |
| 1385 ++it) { | 1406 ++it) { |
| 1386 if (it->first == "test_stream_data") { | 1407 if (it->first == "test_stream_data") { |
| 1387 test_stream_data->assign(it->second.c_str()); | 1408 test_stream_data->assign(it->second.c_str()); |
| 1388 continue; | 1409 continue; |
| 1389 } | 1410 } |
| 1411 // Output machine-readable logs with fixed formats to a file. | |
| 1412 if (it->first == "output_log") { | |
| 1413 log_path = base::FilePath( | |
| 1414 base::FilePath::StringType(it->second.begin(), it->second.end())); | |
| 1415 continue; | |
| 1416 } | |
| 1390 if (it->first == "num_frames_to_encode") { | 1417 if (it->first == "num_frames_to_encode") { |
| 1391 std::string input(it->second.begin(), it->second.end()); | 1418 std::string input(it->second.begin(), it->second.end()); |
| 1392 CHECK(base::StringToInt(input, &content::g_num_frames_to_encode)); | 1419 CHECK(base::StringToInt(input, &content::g_num_frames_to_encode)); |
| 1393 continue; | 1420 continue; |
| 1394 } | 1421 } |
| 1395 if (it->first == "fake_encoder") { | 1422 if (it->first == "fake_encoder") { |
| 1396 content::g_fake_encoder = true; | 1423 content::g_fake_encoder = true; |
| 1397 continue; | 1424 continue; |
| 1398 } | 1425 } |
| 1399 if (it->first == "run_at_fps") { | 1426 if (it->first == "run_at_fps") { |
| 1400 run_at_fps = true; | 1427 run_at_fps = true; |
| 1401 continue; | 1428 continue; |
| 1402 } | 1429 } |
| 1403 if (it->first == "v" || it->first == "vmodule") | 1430 if (it->first == "v" || it->first == "vmodule") |
| 1404 continue; | 1431 continue; |
| 1405 if (it->first == "ozone-platform" || it->first == "ozone-use-surfaceless") | 1432 if (it->first == "ozone-platform" || it->first == "ozone-use-surfaceless") |
| 1406 continue; | 1433 continue; |
| 1407 LOG(FATAL) << "Unexpected switch: " << it->first << ":" << it->second; | 1434 LOG(FATAL) << "Unexpected switch: " << it->first << ":" << it->second; |
| 1408 } | 1435 } |
| 1409 | 1436 |
| 1410 content::g_env = | 1437 content::g_env = |
| 1411 reinterpret_cast<content::VideoEncodeAcceleratorTestEnvironment*>( | 1438 reinterpret_cast<content::VideoEncodeAcceleratorTestEnvironment*>( |
| 1412 testing::AddGlobalTestEnvironment( | 1439 testing::AddGlobalTestEnvironment( |
| 1413 new content::VideoEncodeAcceleratorTestEnvironment( | 1440 new content::VideoEncodeAcceleratorTestEnvironment( |
| 1414 test_stream_data.Pass(), run_at_fps))); | 1441 test_stream_data.Pass(), log_path, run_at_fps))); |
| 1415 | 1442 |
| 1416 return RUN_ALL_TESTS(); | 1443 return RUN_ALL_TESTS(); |
| 1417 } | 1444 } |
| OLD | NEW |