| 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 | 6 | 
| 7 #include <algorithm> | 7 #include <algorithm> | 
| 8 | 8 | 
| 9 #include "base/at_exit.h" | 9 #include "base/at_exit.h" | 
| 10 #include "base/bind.h" | 10 #include "base/bind.h" | 
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" | 
| 12 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" | 
| 13 #include "base/files/memory_mapped_file.h" | 13 #include "base/files/memory_mapped_file.h" | 
| 14 #include "base/memory/scoped_vector.h" | 14 #include "base/memory/scoped_vector.h" | 
| 15 #include "base/numerics/safe_conversions.h" | 15 #include "base/numerics/safe_conversions.h" | 
| 16 #include "base/process/process_handle.h" | 16 #include "base/process/process_handle.h" | 
| 17 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" | 
| 18 #include "base/strings/string_split.h" | 18 #include "base/strings/string_split.h" | 
| 19 #include "base/strings/stringprintf.h" | 19 #include "base/strings/stringprintf.h" | 
| 20 #include "base/sys_byteorder.h" |  | 
| 21 #include "base/threading/thread.h" | 20 #include "base/threading/thread.h" | 
| 22 #include "base/threading/thread_checker.h" | 21 #include "base/threading/thread_checker.h" | 
| 23 #include "base/time/time.h" | 22 #include "base/time/time.h" | 
| 24 #include "base/timer/timer.h" | 23 #include "base/timer/timer.h" | 
| 25 #include "content/common/gpu/media/video_accelerator_unittest_helpers.h" | 24 #include "content/common/gpu/media/video_accelerator_unittest_helpers.h" | 
| 26 #include "media/base/bind_to_current_loop.h" | 25 #include "media/base/bind_to_current_loop.h" | 
| 27 #include "media/base/bitstream_buffer.h" | 26 #include "media/base/bitstream_buffer.h" | 
| 28 #include "media/base/test_data_util.h" | 27 #include "media/base/test_data_util.h" | 
| 29 #include "media/filters/h264_parser.h" | 28 #include "media/filters/h264_parser.h" | 
|  | 29 #include "media/filters/ivf_parser.h" | 
| 30 #include "media/video/fake_video_encode_accelerator.h" | 30 #include "media/video/fake_video_encode_accelerator.h" | 
| 31 #include "media/video/video_encode_accelerator.h" | 31 #include "media/video/video_encode_accelerator.h" | 
| 32 #include "testing/gtest/include/gtest/gtest.h" | 32 #include "testing/gtest/include/gtest/gtest.h" | 
| 33 | 33 | 
| 34 #if defined(OS_CHROMEOS) | 34 #if defined(OS_CHROMEOS) | 
| 35 #if defined(ARCH_CPU_ARMEL) || (defined(USE_OZONE) && defined(USE_V4L2_CODEC)) | 35 #if defined(ARCH_CPU_ARMEL) || (defined(USE_OZONE) && defined(USE_V4L2_CODEC)) | 
| 36 #include "content/common/gpu/media/v4l2_video_encode_accelerator.h" | 36 #include "content/common/gpu/media/v4l2_video_encode_accelerator.h" | 
| 37 #endif | 37 #endif | 
| 38 #if defined(ARCH_CPU_X86_FAMILY) | 38 #if defined(ARCH_CPU_X86_FAMILY) | 
| 39 #include "content/common/gpu/media/vaapi_video_encode_accelerator.h" | 39 #include "content/common/gpu/media/vaapi_video_encode_accelerator.h" | 
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 107 const char* g_default_in_parameters = ":320:192:1:out.h264:200000"; | 107 const char* g_default_in_parameters = ":320:192:1:out.h264:200000"; | 
| 108 | 108 | 
| 109 // Enabled by including a --fake_encoder flag to the command line invoking the | 109 // Enabled by including a --fake_encoder flag to the command line invoking the | 
| 110 // test. | 110 // test. | 
| 111 bool g_fake_encoder = false; | 111 bool g_fake_encoder = false; | 
| 112 | 112 | 
| 113 // Environment to store test stream data for all test cases. | 113 // Environment to store test stream data for all test cases. | 
| 114 class VideoEncodeAcceleratorTestEnvironment; | 114 class VideoEncodeAcceleratorTestEnvironment; | 
| 115 VideoEncodeAcceleratorTestEnvironment* g_env; | 115 VideoEncodeAcceleratorTestEnvironment* g_env; | 
| 116 | 116 | 
| 117 struct IvfFileHeader { |  | 
| 118   char signature[4];     // signature: 'DKIF' |  | 
| 119   uint16_t version;      // version (should be 0) |  | 
| 120   uint16_t header_size;  // size of header in bytes |  | 
| 121   uint32_t fourcc;       // codec FourCC (e.g., 'VP80') |  | 
| 122   uint16_t width;        // width in pixels |  | 
| 123   uint16_t height;       // height in pixels |  | 
| 124   uint32_t framerate;    // frame rate per seconds |  | 
| 125   uint32_t timescale;    // time scale. For example, if framerate is 30 and |  | 
| 126                          // timescale is 2, the unit of IvfFrameHeader.timestamp |  | 
| 127                          // is 2/30 seconds. |  | 
| 128   uint32_t num_frames;   // number of frames in file |  | 
| 129   uint32_t unused;       // unused |  | 
| 130 } __attribute__((packed)); |  | 
| 131 |  | 
| 132 struct IvfFrameHeader { |  | 
| 133   uint32_t frame_size;  // Size of frame in bytes (not including the header) |  | 
| 134   uint64_t timestamp;   // 64-bit presentation timestamp |  | 
| 135 } __attribute__((packed)); |  | 
| 136 |  | 
| 137 // The number of frames to be encoded. This variable is set by the switch | 117 // The number of frames to be encoded. This variable is set by the switch | 
| 138 // "--num_frames_to_encode". Ignored if 0. | 118 // "--num_frames_to_encode". Ignored if 0. | 
| 139 int g_num_frames_to_encode = 0; | 119 int g_num_frames_to_encode = 0; | 
| 140 | 120 | 
| 141 struct TestStream { | 121 struct TestStream { | 
| 142   TestStream() | 122   TestStream() | 
| 143       : num_frames(0), | 123       : num_frames(0), | 
| 144         aligned_buffer_size(0), | 124         aligned_buffer_size(0), | 
| 145         requested_bitrate(0), | 125         requested_bitrate(0), | 
| 146         requested_framerate(0), | 126         requested_framerate(0), | 
| (...skipping 1131 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1278   // All requested keyframes should've been provided. Allow the last requested | 1258   // All requested keyframes should've been provided. Allow the last requested | 
| 1279   // frame to remain undelivered if we haven't reached the maximum frame number | 1259   // frame to remain undelivered if we haven't reached the maximum frame number | 
| 1280   // by which it should have arrived. | 1260   // by which it should have arrived. | 
| 1281   if (num_encoded_frames_ < next_keyframe_at_  + kMaxKeyframeDelay) | 1261   if (num_encoded_frames_ < next_keyframe_at_  + kMaxKeyframeDelay) | 
| 1282     EXPECT_LE(num_keyframes_requested_, 1UL); | 1262     EXPECT_LE(num_keyframes_requested_, 1UL); | 
| 1283   else | 1263   else | 
| 1284     EXPECT_EQ(num_keyframes_requested_, 0UL); | 1264     EXPECT_EQ(num_keyframes_requested_, 0UL); | 
| 1285 } | 1265 } | 
| 1286 | 1266 | 
| 1287 void VEAClient::WriteIvfFileHeader() { | 1267 void VEAClient::WriteIvfFileHeader() { | 
| 1288   IvfFileHeader header; | 1268   media::IvfFileHeader header = {}; | 
| 1289 | 1269 | 
| 1290   memset(&header, 0, sizeof(header)); | 1270   memcpy(header.signature, media::kIvfHeaderSignature, | 
| 1291   header.signature[0] = 'D'; | 1271          sizeof(header.signature)); | 
| 1292   header.signature[1] = 'K'; |  | 
| 1293   header.signature[2] = 'I'; |  | 
| 1294   header.signature[3] = 'F'; |  | 
| 1295   header.version = 0; | 1272   header.version = 0; | 
| 1296   header.header_size = base::ByteSwapToLE16(sizeof(header)); | 1273   header.header_size = sizeof(header); | 
| 1297   header.fourcc = base::ByteSwapToLE32(0x30385056);  // VP80 | 1274   header.fourcc = 0x30385056;  // VP80 | 
| 1298   header.width = base::ByteSwapToLE16( | 1275   header.width = | 
| 1299       base::checked_cast<uint16_t>(test_stream_->visible_size.width())); | 1276       base::checked_cast<uint16_t>(test_stream_->visible_size.width()); | 
| 1300   header.height = base::ByteSwapToLE16( | 1277   header.height = | 
| 1301       base::checked_cast<uint16_t>(test_stream_->visible_size.height())); | 1278       base::checked_cast<uint16_t>(test_stream_->visible_size.height()); | 
| 1302   header.framerate = base::ByteSwapToLE32(requested_framerate_); | 1279   header.timebase_denum = requested_framerate_; | 
| 1303   header.timescale = base::ByteSwapToLE32(1); | 1280   header.timebase_num = 1; | 
| 1304   header.num_frames = base::ByteSwapToLE32(num_frames_to_encode_); | 1281   header.num_frames = num_frames_to_encode_; | 
|  | 1282   header.ByteSwap(); | 
| 1305 | 1283 | 
| 1306   EXPECT_TRUE(base::AppendToFile( | 1284   EXPECT_TRUE(base::AppendToFile( | 
| 1307       base::FilePath::FromUTF8Unsafe(test_stream_->out_filename), | 1285       base::FilePath::FromUTF8Unsafe(test_stream_->out_filename), | 
| 1308       reinterpret_cast<char*>(&header), sizeof(header))); | 1286       reinterpret_cast<char*>(&header), sizeof(header))); | 
| 1309 } | 1287 } | 
| 1310 | 1288 | 
| 1311 void VEAClient::WriteIvfFrameHeader(int frame_index, size_t frame_size) { | 1289 void VEAClient::WriteIvfFrameHeader(int frame_index, size_t frame_size) { | 
| 1312   IvfFrameHeader header; | 1290   media::IvfFrameHeader header = {}; | 
| 1313 | 1291 | 
| 1314   memset(&header, 0, sizeof(header)); | 1292   header.frame_size = frame_size; | 
| 1315   header.frame_size = base::ByteSwapToLE32(frame_size); | 1293   header.timestamp = frame_index; | 
| 1316   header.timestamp = base::ByteSwapToLE64(frame_index); | 1294   header.ByteSwap(); | 
| 1317   EXPECT_TRUE(base::AppendToFile( | 1295   EXPECT_TRUE(base::AppendToFile( | 
| 1318       base::FilePath::FromUTF8Unsafe(test_stream_->out_filename), | 1296       base::FilePath::FromUTF8Unsafe(test_stream_->out_filename), | 
| 1319       reinterpret_cast<char*>(&header), sizeof(header))); | 1297       reinterpret_cast<char*>(&header), sizeof(header))); | 
| 1320 } | 1298 } | 
| 1321 | 1299 | 
| 1322 // Test parameters: | 1300 // Test parameters: | 
| 1323 // - Number of concurrent encoders. The value takes effect when there is only | 1301 // - Number of concurrent encoders. The value takes effect when there is only | 
| 1324 //   one input stream; otherwise, one encoder per input stream will be | 1302 //   one input stream; otherwise, one encoder per input stream will be | 
| 1325 //   instantiated. | 1303 //   instantiated. | 
| 1326 // - If true, save output to file (provided an output filename was supplied). | 1304 // - If true, save output to file (provided an output filename was supplied). | 
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1518 | 1496 | 
| 1519   content::g_env = | 1497   content::g_env = | 
| 1520       reinterpret_cast<content::VideoEncodeAcceleratorTestEnvironment*>( | 1498       reinterpret_cast<content::VideoEncodeAcceleratorTestEnvironment*>( | 
| 1521           testing::AddGlobalTestEnvironment( | 1499           testing::AddGlobalTestEnvironment( | 
| 1522               new content::VideoEncodeAcceleratorTestEnvironment( | 1500               new content::VideoEncodeAcceleratorTestEnvironment( | 
| 1523                   test_stream_data.Pass(), log_path, run_at_fps, | 1501                   test_stream_data.Pass(), log_path, run_at_fps, | 
| 1524                   needs_encode_latency))); | 1502                   needs_encode_latency))); | 
| 1525 | 1503 | 
| 1526   return RUN_ALL_TESTS(); | 1504   return RUN_ALL_TESTS(); | 
| 1527 } | 1505 } | 
| OLD | NEW | 
|---|