Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(187)

Side by Side Diff: content/common/gpu/media/video_encode_accelerator_unittest.cc

Issue 1097793006: vea_unittest: Add --output_log option (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 } 346 }
346 347
347 if (fields.size() >= 9 && !fields[8].empty()) { 348 if (fields.size() >= 9 && !fields[8].empty()) {
348 CHECK(base::StringToUint(fields[8], 349 CHECK(base::StringToUint(fields[8],
349 &test_stream->requested_subsequent_framerate)); 350 &test_stream->requested_subsequent_framerate));
350 } 351 }
351 test_streams->push_back(test_stream); 352 test_streams->push_back(test_stream);
352 } 353 }
353 } 354 }
354 355
356 // Basic test environment shared across multiple test cases. We only need to
357 // setup it once for all test cases.
358 // It helps
359 // - maintain test stream data and other test settings.
360 // - clean up temporary aligned files.
361 // - output log to file.
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 : run_at_fps_(run_at_fps),
369 test_stream_data_(data.Pass()),
370 log_path_(log_path) {}
371
372 virtual void SetUp() {
373 if (!log_path_.empty()) {
374 log_file_.reset(new base::File(
375 log_path_, base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE));
376 CHECK(log_file_->IsValid());
377 }
378 ParseAndReadTestStreamData(*test_stream_data_, &test_streams_);
379 }
380
381 virtual void TearDown() {
382 for (size_t i = 0; i < test_streams_.size(); i++) {
383 base::DeleteFile(test_streams_[i]->aligned_in_file, false);
384 }
385 log_file_.reset();
386 }
387
388 // Log one entry of machine-readable data to file.
389 // The log has one data entry per line in the format of "<key>: <value>".
390 void LogToFile(const std::string& key, const std::string& value) {
391 if (log_file_) {
392 std::string s =
393 base::StringPrintf("%s: %s\n", key.c_str(), value.c_str());
394 log_file_->WriteAtCurrentPos(s.data(), s.length());
395 }
396 }
397
398 ScopedVector<TestStream> test_streams_;
399 bool run_at_fps_;
400
401 private:
402 scoped_ptr<base::FilePath::StringType> test_stream_data_;
403 base::FilePath log_path_;
404 scoped_ptr<base::File> log_file_;
405 };
406
355 enum ClientState { 407 enum ClientState {
356 CS_CREATED, 408 CS_CREATED,
357 CS_ENCODER_SET, 409 CS_ENCODER_SET,
358 CS_INITIALIZED, 410 CS_INITIALIZED,
359 CS_ENCODING, 411 CS_ENCODING,
360 CS_FINISHED, 412 CS_FINISHED,
361 CS_ERROR, 413 CS_ERROR,
362 }; 414 };
363 415
364 // Performs basic, codec-specific sanity checks on the stream buffers passed 416 // Performs basic, codec-specific sanity checks on the stream buffers passed
(...skipping 761 matching lines...) Expand 10 before | Expand all | Expand 10 after
1126 SetState(CS_FINISHED); 1178 SetState(CS_FINISHED);
1127 return false; 1179 return false;
1128 } 1180 }
1129 1181
1130 return true; 1182 return true;
1131 } 1183 }
1132 1184
1133 void VEAClient::VerifyPerf() { 1185 void VEAClient::VerifyPerf() {
1134 double measured_fps = frames_per_second(); 1186 double measured_fps = frames_per_second();
1135 LOG(INFO) << "Measured encoder FPS: " << measured_fps; 1187 LOG(INFO) << "Measured encoder FPS: " << measured_fps;
1188 g_env->LogToFile("Measured encoder FPS",
1189 base::StringPrintf("%.3f", measured_fps));
1136 if (test_perf_) 1190 if (test_perf_)
1137 EXPECT_GE(measured_fps, kMinPerfFPS); 1191 EXPECT_GE(measured_fps, kMinPerfFPS);
1138 } 1192 }
1139 1193
1140 void VEAClient::VerifyStreamProperties() { 1194 void VEAClient::VerifyStreamProperties() {
1141 CHECK_GT(num_frames_since_last_check_, 0UL); 1195 CHECK_GT(num_frames_since_last_check_, 0UL);
1142 CHECK_GT(encoded_stream_size_since_last_check_, 0UL); 1196 CHECK_GT(encoded_stream_size_since_last_check_, 0UL);
1143 unsigned int bitrate = encoded_stream_size_since_last_check_ * 8 * 1197 unsigned int bitrate = encoded_stream_size_since_last_check_ * 8 *
1144 current_framerate_ / num_frames_since_last_check_; 1198 current_framerate_ / num_frames_since_last_check_;
1145 DVLOG(1) << "Current chunk's bitrate: " << bitrate 1199 DVLOG(1) << "Current chunk's bitrate: " << bitrate
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1193 IvfFrameHeader header; 1247 IvfFrameHeader header;
1194 1248
1195 memset(&header, 0, sizeof(header)); 1249 memset(&header, 0, sizeof(header));
1196 header.frame_size = base::ByteSwapToLE32(frame_size); 1250 header.frame_size = base::ByteSwapToLE32(frame_size);
1197 header.timestamp = base::ByteSwapToLE64(frame_index); 1251 header.timestamp = base::ByteSwapToLE64(frame_index);
1198 EXPECT_TRUE(base::AppendToFile( 1252 EXPECT_TRUE(base::AppendToFile(
1199 base::FilePath::FromUTF8Unsafe(test_stream_->out_filename), 1253 base::FilePath::FromUTF8Unsafe(test_stream_->out_filename),
1200 reinterpret_cast<char*>(&header), sizeof(header))); 1254 reinterpret_cast<char*>(&header), sizeof(header)));
1201 } 1255 }
1202 1256
1203 // Setup test stream data and delete temporary aligned files at the beginning
1204 // and end of unittest. We only need to setup once for all test cases.
1205 class VideoEncodeAcceleratorTestEnvironment : public ::testing::Environment {
1206 public:
1207 VideoEncodeAcceleratorTestEnvironment(
1208 scoped_ptr<base::FilePath::StringType> data,
1209 bool run_at_fps) {
1210 test_stream_data_ = data.Pass();
1211 run_at_fps_ = run_at_fps;
1212 }
1213
1214 virtual void SetUp() {
1215 ParseAndReadTestStreamData(*test_stream_data_, &test_streams_);
1216 }
1217
1218 virtual void TearDown() {
1219 for (size_t i = 0; i < test_streams_.size(); i++) {
1220 base::DeleteFile(test_streams_[i]->aligned_in_file, false);
1221 }
1222 }
1223
1224 ScopedVector<TestStream> test_streams_;
1225 bool run_at_fps_;
1226
1227 private:
1228 scoped_ptr<base::FilePath::StringType> test_stream_data_;
1229 };
1230
1231 // Test parameters: 1257 // Test parameters:
1232 // - Number of concurrent encoders. The value takes effect when there is only 1258 // - Number of concurrent encoders. The value takes effect when there is only
1233 // one input stream; otherwise, one encoder per input stream will be 1259 // one input stream; otherwise, one encoder per input stream will be
1234 // instantiated. 1260 // instantiated.
1235 // - If true, save output to file (provided an output filename was supplied). 1261 // - If true, save output to file (provided an output filename was supplied).
1236 // - Force a keyframe every n frames. 1262 // - Force a keyframe every n frames.
1237 // - Force bitrate; the actual required value is provided as a property 1263 // - Force bitrate; the actual required value is provided as a property
1238 // of the input stream, because it depends on stream type/resolution/etc. 1264 // of the input stream, because it depends on stream type/resolution/etc.
1239 // - If true, measure performance. 1265 // - If true, measure performance.
1240 // - If true, switch bitrate mid-stream. 1266 // - If true, switch bitrate mid-stream.
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
1371 1397
1372 // Needed to enable DVLOG through --vmodule. 1398 // Needed to enable DVLOG through --vmodule.
1373 logging::LoggingSettings settings; 1399 logging::LoggingSettings settings;
1374 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; 1400 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
1375 CHECK(logging::InitLogging(settings)); 1401 CHECK(logging::InitLogging(settings));
1376 1402
1377 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); 1403 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess();
1378 DCHECK(cmd_line); 1404 DCHECK(cmd_line);
1379 1405
1380 bool run_at_fps = false; 1406 bool run_at_fps = false;
1407 base::FilePath log_path;
1408
1381 base::CommandLine::SwitchMap switches = cmd_line->GetSwitches(); 1409 base::CommandLine::SwitchMap switches = cmd_line->GetSwitches();
1382 for (base::CommandLine::SwitchMap::const_iterator it = switches.begin(); 1410 for (base::CommandLine::SwitchMap::const_iterator it = switches.begin();
1383 it != switches.end(); 1411 it != switches.end();
1384 ++it) { 1412 ++it) {
1385 if (it->first == "test_stream_data") { 1413 if (it->first == "test_stream_data") {
1386 test_stream_data->assign(it->second.c_str()); 1414 test_stream_data->assign(it->second.c_str());
1387 continue; 1415 continue;
1388 } 1416 }
1417 // Output machine-readable logs with fixed formats to a file.
1418 if (it->first == "output_log") {
1419 log_path = base::FilePath(
1420 base::FilePath::StringType(it->second.begin(), it->second.end()));
1421 continue;
1422 }
1389 if (it->first == "num_frames_to_encode") { 1423 if (it->first == "num_frames_to_encode") {
1390 std::string input(it->second.begin(), it->second.end()); 1424 std::string input(it->second.begin(), it->second.end());
1391 CHECK(base::StringToInt(input, &content::g_num_frames_to_encode)); 1425 CHECK(base::StringToInt(input, &content::g_num_frames_to_encode));
1392 continue; 1426 continue;
1393 } 1427 }
1394 if (it->first == "fake_encoder") { 1428 if (it->first == "fake_encoder") {
1395 content::g_fake_encoder = true; 1429 content::g_fake_encoder = true;
1396 continue; 1430 continue;
1397 } 1431 }
1398 if (it->first == "run_at_fps") { 1432 if (it->first == "run_at_fps") {
1399 run_at_fps = true; 1433 run_at_fps = true;
1400 continue; 1434 continue;
1401 } 1435 }
1402 if (it->first == "v" || it->first == "vmodule") 1436 if (it->first == "v" || it->first == "vmodule")
1403 continue; 1437 continue;
1404 if (it->first == "ozone-platform" || it->first == "ozone-use-surfaceless") 1438 if (it->first == "ozone-platform" || it->first == "ozone-use-surfaceless")
1405 continue; 1439 continue;
1406 LOG(FATAL) << "Unexpected switch: " << it->first << ":" << it->second; 1440 LOG(FATAL) << "Unexpected switch: " << it->first << ":" << it->second;
1407 } 1441 }
1408 1442
1409 content::g_env = 1443 content::g_env =
1410 reinterpret_cast<content::VideoEncodeAcceleratorTestEnvironment*>( 1444 reinterpret_cast<content::VideoEncodeAcceleratorTestEnvironment*>(
1411 testing::AddGlobalTestEnvironment( 1445 testing::AddGlobalTestEnvironment(
1412 new content::VideoEncodeAcceleratorTestEnvironment( 1446 new content::VideoEncodeAcceleratorTestEnvironment(
1413 test_stream_data.Pass(), run_at_fps))); 1447 test_stream_data.Pass(), log_path, run_at_fps)));
1414 1448
1415 return RUN_ALL_TESTS(); 1449 return RUN_ALL_TESTS();
1416 } 1450 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698