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

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

Issue 1269473002: Extract IVF parser from VP8 parser unittest (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 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 | media/BUILD.gn » ('j') | media/filters/ivf_parser.h » ('J')
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 <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
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
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 memset(&header, 0, sizeof(header));
1291 header.signature[0] = 'D'; 1271 header.signature[0] = 'D';
1292 header.signature[1] = 'K'; 1272 header.signature[1] = 'K';
1293 header.signature[2] = 'I'; 1273 header.signature[2] = 'I';
1294 header.signature[3] = 'F'; 1274 header.signature[3] = 'F';
henryhsu 2015/08/05 10:45:13 memcpy(header.signature, media::kIvfHeaderSignatur
kcwu 2015/08/05 11:05:15 Done.
1295 header.version = 0; 1275 header.version = 0;
1296 header.header_size = base::ByteSwapToLE16(sizeof(header)); 1276 header.header_size = sizeof(header);
1297 header.fourcc = base::ByteSwapToLE32(0x30385056); // VP80 1277 header.fourcc = 0x30385056; // VP80
1298 header.width = base::ByteSwapToLE16( 1278 header.width =
1299 base::checked_cast<uint16_t>(test_stream_->visible_size.width())); 1279 base::checked_cast<uint16_t>(test_stream_->visible_size.width());
1300 header.height = base::ByteSwapToLE16( 1280 header.height =
1301 base::checked_cast<uint16_t>(test_stream_->visible_size.height())); 1281 base::checked_cast<uint16_t>(test_stream_->visible_size.height());
1302 header.framerate = base::ByteSwapToLE32(requested_framerate_); 1282 header.timebase_denum = requested_framerate_;
1303 header.timescale = base::ByteSwapToLE32(1); 1283 header.timebase_num = 1;
1304 header.num_frames = base::ByteSwapToLE32(num_frames_to_encode_); 1284 header.num_frames = num_frames_to_encode_;
1285 header.ByteSwap();
1305 1286
1306 EXPECT_TRUE(base::AppendToFile( 1287 EXPECT_TRUE(base::AppendToFile(
1307 base::FilePath::FromUTF8Unsafe(test_stream_->out_filename), 1288 base::FilePath::FromUTF8Unsafe(test_stream_->out_filename),
1308 reinterpret_cast<char*>(&header), sizeof(header))); 1289 reinterpret_cast<char*>(&header), sizeof(header)));
1309 } 1290 }
1310 1291
1311 void VEAClient::WriteIvfFrameHeader(int frame_index, size_t frame_size) { 1292 void VEAClient::WriteIvfFrameHeader(int frame_index, size_t frame_size) {
1312 IvfFrameHeader header; 1293 media::IvfFrameHeader header;
1313 1294
1314 memset(&header, 0, sizeof(header)); 1295 memset(&header, 0, sizeof(header));
1315 header.frame_size = base::ByteSwapToLE32(frame_size); 1296 header.frame_size = frame_size;
1316 header.timestamp = base::ByteSwapToLE64(frame_index); 1297 header.timestamp = frame_index;
1298 header.ByteSwap();
1317 EXPECT_TRUE(base::AppendToFile( 1299 EXPECT_TRUE(base::AppendToFile(
1318 base::FilePath::FromUTF8Unsafe(test_stream_->out_filename), 1300 base::FilePath::FromUTF8Unsafe(test_stream_->out_filename),
1319 reinterpret_cast<char*>(&header), sizeof(header))); 1301 reinterpret_cast<char*>(&header), sizeof(header)));
1320 } 1302 }
1321 1303
1322 // Test parameters: 1304 // Test parameters:
1323 // - Number of concurrent encoders. The value takes effect when there is only 1305 // - Number of concurrent encoders. The value takes effect when there is only
1324 // one input stream; otherwise, one encoder per input stream will be 1306 // one input stream; otherwise, one encoder per input stream will be
1325 // instantiated. 1307 // instantiated.
1326 // - If true, save output to file (provided an output filename was supplied). 1308 // - If true, save output to file (provided an output filename was supplied).
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
1518 1500
1519 content::g_env = 1501 content::g_env =
1520 reinterpret_cast<content::VideoEncodeAcceleratorTestEnvironment*>( 1502 reinterpret_cast<content::VideoEncodeAcceleratorTestEnvironment*>(
1521 testing::AddGlobalTestEnvironment( 1503 testing::AddGlobalTestEnvironment(
1522 new content::VideoEncodeAcceleratorTestEnvironment( 1504 new content::VideoEncodeAcceleratorTestEnvironment(
1523 test_stream_data.Pass(), log_path, run_at_fps, 1505 test_stream_data.Pass(), log_path, run_at_fps,
1524 needs_encode_latency))); 1506 needs_encode_latency)));
1525 1507
1526 return RUN_ALL_TESTS(); 1508 return RUN_ALL_TESTS();
1527 } 1509 }
OLDNEW
« no previous file with comments | « no previous file | media/BUILD.gn » ('j') | media/filters/ivf_parser.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698