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 #include <stddef.h> | 6 #include <stddef.h> |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <memory> | 10 #include <memory> |
11 #include <queue> | 11 #include <queue> |
12 #include <string> | 12 #include <string> |
13 #include <utility> | 13 #include <utility> |
14 | 14 |
15 #include "base/at_exit.h" | 15 #include "base/at_exit.h" |
16 #include "base/bind.h" | 16 #include "base/bind.h" |
17 #include "base/bits.h" | 17 #include "base/bits.h" |
18 #include "base/command_line.h" | 18 #include "base/command_line.h" |
19 #include "base/files/file_util.h" | 19 #include "base/files/file_util.h" |
20 #include "base/macros.h" | 20 #include "base/macros.h" |
21 #include "base/memory/aligned_memory.h" | 21 #include "base/memory/aligned_memory.h" |
22 #include "base/memory/scoped_vector.h" | 22 #include "base/memory/scoped_vector.h" |
23 #include "base/message_loop/message_loop.h" | 23 #include "base/message_loop/message_loop.h" |
24 #include "base/numerics/safe_conversions.h" | 24 #include "base/numerics/safe_conversions.h" |
25 #include "base/process/process_handle.h" | 25 #include "base/process/process_handle.h" |
26 #include "base/single_thread_task_runner.h" | 26 #include "base/single_thread_task_runner.h" |
27 #include "base/strings/string_number_conversions.h" | 27 #include "base/strings/string_number_conversions.h" |
28 #include "base/strings/string_split.h" | 28 #include "base/strings/string_split.h" |
29 #include "base/strings/stringprintf.h" | 29 #include "base/strings/stringprintf.h" |
| 30 #include "base/strings/utf_string_conversions.h" |
30 #include "base/threading/thread.h" | 31 #include "base/threading/thread.h" |
31 #include "base/threading/thread_checker.h" | 32 #include "base/threading/thread_checker.h" |
32 #include "base/time/time.h" | 33 #include "base/time/time.h" |
33 #include "base/timer/timer.h" | 34 #include "base/timer/timer.h" |
34 #include "build/build_config.h" | 35 #include "build/build_config.h" |
35 #include "media/base/bind_to_current_loop.h" | 36 #include "media/base/bind_to_current_loop.h" |
36 #include "media/base/bitstream_buffer.h" | 37 #include "media/base/bitstream_buffer.h" |
37 #include "media/base/cdm_context.h" | 38 #include "media/base/cdm_context.h" |
38 #include "media/base/decoder_buffer.h" | 39 #include "media/base/decoder_buffer.h" |
39 #include "media/base/media_util.h" | 40 #include "media/base/media_util.h" |
(...skipping 14 matching lines...) Expand all Loading... |
54 #include "media/gpu/v4l2_video_encode_accelerator.h" | 55 #include "media/gpu/v4l2_video_encode_accelerator.h" |
55 #endif | 56 #endif |
56 #if defined(ARCH_CPU_X86_FAMILY) | 57 #if defined(ARCH_CPU_X86_FAMILY) |
57 #include "media/gpu/vaapi_video_encode_accelerator.h" | 58 #include "media/gpu/vaapi_video_encode_accelerator.h" |
58 #include "media/gpu/vaapi_wrapper.h" | 59 #include "media/gpu/vaapi_wrapper.h" |
59 // Status has been defined as int in Xlib.h. | 60 // Status has been defined as int in Xlib.h. |
60 #undef Status | 61 #undef Status |
61 #endif // defined(ARCH_CPU_X86_FAMILY) | 62 #endif // defined(ARCH_CPU_X86_FAMILY) |
62 #elif defined(OS_MACOSX) | 63 #elif defined(OS_MACOSX) |
63 #include "media/gpu/vt_video_encode_accelerator_mac.h" | 64 #include "media/gpu/vt_video_encode_accelerator_mac.h" |
| 65 #elif defined(OS_WIN) |
| 66 #include "media/gpu/media_foundation_video_encode_accelerator_win.h" |
64 #else | 67 #else |
65 #error The VideoEncodeAcceleratorUnittest is not supported on this platform. | 68 #error The VideoEncodeAcceleratorUnittest is not supported on this platform. |
66 #endif | 69 #endif |
67 | 70 |
68 namespace media { | 71 namespace media { |
69 namespace { | 72 namespace { |
70 | 73 |
71 const VideoPixelFormat kInputFormat = PIXEL_FORMAT_I420; | 74 const VideoPixelFormat kInputFormat = PIXEL_FORMAT_I420; |
72 | 75 |
73 // The absolute differences between original frame and decoded frame usually | 76 // The absolute differences between original frame and decoded frame usually |
(...skipping 29 matching lines...) Expand all Loading... |
103 const unsigned int kMinFramesForBitrateTests = 300; | 106 const unsigned int kMinFramesForBitrateTests = 300; |
104 // The percentiles to measure for encode latency. | 107 // The percentiles to measure for encode latency. |
105 const unsigned int kLoggedLatencyPercentiles[] = {50, 75, 95}; | 108 const unsigned int kLoggedLatencyPercentiles[] = {50, 75, 95}; |
106 | 109 |
107 // The syntax of multiple test streams is: | 110 // The syntax of multiple test streams is: |
108 // test-stream1;test-stream2;test-stream3 | 111 // test-stream1;test-stream2;test-stream3 |
109 // The syntax of each test stream is: | 112 // The syntax of each test stream is: |
110 // "in_filename:width:height:profile:out_filename:requested_bitrate | 113 // "in_filename:width:height:profile:out_filename:requested_bitrate |
111 // :requested_framerate:requested_subsequent_bitrate | 114 // :requested_framerate:requested_subsequent_bitrate |
112 // :requested_subsequent_framerate" | 115 // :requested_subsequent_framerate" |
| 116 // Instead of ":", "," can be used as a seperator as well. Note that ":" does |
| 117 // not work on Windows as it interferes with file paths. |
113 // - |in_filename| must be an I420 (YUV planar) raw stream | 118 // - |in_filename| must be an I420 (YUV planar) raw stream |
114 // (see http://www.fourcc.org/yuv.php#IYUV). | 119 // (see http://www.fourcc.org/yuv.php#IYUV). |
115 // - |width| and |height| are in pixels. | 120 // - |width| and |height| are in pixels. |
116 // - |profile| to encode into (values of VideoCodecProfile). | 121 // - |profile| to encode into (values of VideoCodecProfile). |
117 // - |out_filename| filename to save the encoded stream to (optional). The | 122 // - |out_filename| filename to save the encoded stream to (optional). The |
118 // format for H264 is Annex-B byte stream. The format for VP8 is IVF. Output | 123 // format for H264 is Annex-B byte stream. The format for VP8 is IVF. Output |
119 // stream is saved for the simple encode test only. H264 raw stream and IVF | 124 // stream is saved for the simple encode test only. H264 raw stream and IVF |
120 // can be used as input of VDA unittest. H264 raw stream can be played by | 125 // can be used as input of VDA unittest. H264 raw stream can be played by |
121 // "mplayer -fps 25 out.h264" and IVF can be played by mplayer directly. | 126 // "mplayer -fps 25 out.h264" and IVF can be played by mplayer directly. |
122 // Helpful description: http://wiki.multimedia.cx/index.php?title=IVF | 127 // Helpful description: http://wiki.multimedia.cx/index.php?title=IVF |
123 // Further parameters are optional (need to provide preceding positional | 128 // Further parameters are optional (need to provide preceding positional |
124 // parameters if a specific subsequent parameter is required): | 129 // parameters if a specific subsequent parameter is required): |
125 // - |requested_bitrate| requested bitrate in bits per second. | 130 // - |requested_bitrate| requested bitrate in bits per second. |
126 // - |requested_framerate| requested initial framerate. | 131 // - |requested_framerate| requested initial framerate. |
127 // - |requested_subsequent_bitrate| bitrate to switch to in the middle of the | 132 // - |requested_subsequent_bitrate| bitrate to switch to in the middle of the |
128 // stream. | 133 // stream. |
129 // - |requested_subsequent_framerate| framerate to switch to in the middle | 134 // - |requested_subsequent_framerate| framerate to switch to in the middle |
130 // of the stream. | 135 // of the stream. |
131 // Bitrate is only forced for tests that test bitrate. | 136 // Bitrate is only forced for tests that test bitrate. |
132 const char* g_default_in_filename = "bear_320x192_40frames.yuv"; | 137 const char* g_default_in_filename = "bear_320x192_40frames.yuv"; |
133 #if !defined(OS_MACOSX) | 138 |
134 const char* g_default_in_parameters = ":320:192:1:out.h264:200000"; | 139 #if defined(OS_CHROMEOS) |
135 #else | 140 const base::FilePath::CharType* g_default_in_parameters = |
136 const char* g_default_in_parameters = ":320:192:0:out.h264:200000"; | 141 FILE_PATH_LITERAL(":320:192:1:out.h264:200000"); |
137 #endif | 142 #elif defined(OS_MACOSX) || defined(OS_WIN) |
| 143 const base::FilePath::CharType* g_default_in_parameters = |
| 144 FILE_PATH_LITERAL(",320,192,0,out.h264,200000"); |
| 145 #endif // defined(OS_CHROMEOS) |
138 | 146 |
139 // Enabled by including a --fake_encoder flag to the command line invoking the | 147 // Enabled by including a --fake_encoder flag to the command line invoking the |
140 // test. | 148 // test. |
141 bool g_fake_encoder = false; | 149 bool g_fake_encoder = false; |
142 | 150 |
143 // Environment to store test stream data for all test cases. | 151 // Environment to store test stream data for all test cases. |
144 class VideoEncodeAcceleratorTestEnvironment; | 152 class VideoEncodeAcceleratorTestEnvironment; |
145 VideoEncodeAcceleratorTestEnvironment* g_env; | 153 VideoEncodeAcceleratorTestEnvironment* g_env; |
146 | 154 |
147 // The number of frames to be encoded. This variable is set by the switch | 155 // The number of frames to be encoded. This variable is set by the switch |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 } | 241 } |
234 | 242 |
235 static bool IsH264(VideoCodecProfile profile) { | 243 static bool IsH264(VideoCodecProfile profile) { |
236 return profile >= H264PROFILE_MIN && profile <= H264PROFILE_MAX; | 244 return profile >= H264PROFILE_MIN && profile <= H264PROFILE_MAX; |
237 } | 245 } |
238 | 246 |
239 static bool IsVP8(VideoCodecProfile profile) { | 247 static bool IsVP8(VideoCodecProfile profile) { |
240 return profile >= VP8PROFILE_MIN && profile <= VP8PROFILE_MAX; | 248 return profile >= VP8PROFILE_MIN && profile <= VP8PROFILE_MAX; |
241 } | 249 } |
242 | 250 |
| 251 // Helper functions to do string conversions. |
| 252 static base::FilePath::StringType StringToFilePathStringType( |
| 253 const std::string& str) { |
| 254 #if defined(OS_WIN) |
| 255 return base::UTF8ToWide(str); |
| 256 #else |
| 257 return str; |
| 258 #endif // defined(OS_WIN) |
| 259 } |
| 260 |
| 261 static std::string FilePathStringTypeToString( |
| 262 const base::FilePath::StringType& str) { |
| 263 #if defined(OS_WIN) |
| 264 return base::WideToUTF8(str); |
| 265 #else |
| 266 return str; |
| 267 #endif // defined(OS_WIN) |
| 268 } |
| 269 |
243 // ARM performs CPU cache management with CPU cache line granularity. We thus | 270 // ARM performs CPU cache management with CPU cache line granularity. We thus |
244 // need to ensure our buffers are CPU cache line-aligned (64 byte-aligned). | 271 // need to ensure our buffers are CPU cache line-aligned (64 byte-aligned). |
245 // Otherwise newer kernels will refuse to accept them, and on older kernels | 272 // Otherwise newer kernels will refuse to accept them, and on older kernels |
246 // we'll be treating ourselves to random corruption. | 273 // we'll be treating ourselves to random corruption. |
247 // Since we are just mapping and passing chunks of the input file directly to | 274 // Since we are just mapping and passing chunks of the input file directly to |
248 // the VEA as input frames to avoid copying large chunks of raw data on each | 275 // the VEA as input frames to avoid copying large chunks of raw data on each |
249 // frame and thus affecting performance measurements, we have to prepare a | 276 // frame and thus affecting performance measurements, we have to prepare a |
250 // temporary file with all planes aligned to 64-byte boundaries beforehand. | 277 // temporary file with all planes aligned to 64-byte boundaries beforehand. |
251 static void CreateAlignedInputStreamFile(const gfx::Size& coded_size, | 278 static void CreateAlignedInputStreamFile(const gfx::Size& coded_size, |
252 TestStream* test_stream) { | 279 TestStream* test_stream) { |
(...skipping 30 matching lines...) Expand all Loading... |
283 visible_bpl[i] = VideoFrame::RowBytes(i, kInputFormat, | 310 visible_bpl[i] = VideoFrame::RowBytes(i, kInputFormat, |
284 test_stream->visible_size.width()); | 311 test_stream->visible_size.width()); |
285 visible_plane_rows[i] = | 312 visible_plane_rows[i] = |
286 VideoFrame::Rows(i, kInputFormat, test_stream->visible_size.height()); | 313 VideoFrame::Rows(i, kInputFormat, test_stream->visible_size.height()); |
287 const size_t padding_rows = | 314 const size_t padding_rows = |
288 VideoFrame::Rows(i, kInputFormat, coded_size.height()) - | 315 VideoFrame::Rows(i, kInputFormat, coded_size.height()) - |
289 visible_plane_rows[i]; | 316 visible_plane_rows[i]; |
290 padding_sizes[i] = padding_rows * coded_bpl[i] + Align64Bytes(size) - size; | 317 padding_sizes[i] = padding_rows * coded_bpl[i] + Align64Bytes(size) - size; |
291 } | 318 } |
292 | 319 |
293 base::FilePath src_file(test_stream->in_filename); | 320 base::FilePath src_file(StringToFilePathStringType(test_stream->in_filename)); |
294 int64_t src_file_size = 0; | 321 int64_t src_file_size = 0; |
295 LOG_ASSERT(base::GetFileSize(src_file, &src_file_size)); | 322 LOG_ASSERT(base::GetFileSize(src_file, &src_file_size)); |
296 | 323 |
297 size_t visible_buffer_size = | 324 size_t visible_buffer_size = |
298 VideoFrame::AllocationSize(kInputFormat, test_stream->visible_size); | 325 VideoFrame::AllocationSize(kInputFormat, test_stream->visible_size); |
299 LOG_ASSERT(src_file_size % visible_buffer_size == 0U) | 326 LOG_ASSERT(src_file_size % visible_buffer_size == 0U) |
300 << "Stream byte size is not a product of calculated frame byte size"; | 327 << "Stream byte size is not a product of calculated frame byte size"; |
301 | 328 |
302 test_stream->num_frames = src_file_size / visible_buffer_size; | 329 test_stream->num_frames = |
| 330 static_cast<unsigned int>(src_file_size / visible_buffer_size); |
303 | 331 |
304 LOG_ASSERT(test_stream->aligned_buffer_size > 0UL); | 332 LOG_ASSERT(test_stream->aligned_buffer_size > 0UL); |
305 test_stream->aligned_in_file_data.resize(test_stream->aligned_buffer_size * | 333 test_stream->aligned_in_file_data.resize(test_stream->aligned_buffer_size * |
306 test_stream->num_frames); | 334 test_stream->num_frames); |
307 | 335 |
308 base::File src(src_file, base::File::FLAG_OPEN | base::File::FLAG_READ); | 336 base::File src(src_file, base::File::FLAG_OPEN | base::File::FLAG_READ); |
309 std::vector<char> src_data(visible_buffer_size); | 337 std::vector<char> src_data(visible_buffer_size); |
310 off_t src_offset = 0, dest_offset = 0; | 338 off_t src_offset = 0, dest_offset = 0; |
311 for (size_t frame = 0; frame < test_stream->num_frames; frame++) { | 339 for (size_t frame = 0; frame < test_stream->num_frames; frame++) { |
312 LOG_ASSERT(src.Read(src_offset, &src_data[0], visible_buffer_size) == | 340 LOG_ASSERT(src.Read(src_offset, &src_data[0], |
| 341 static_cast<int>(visible_buffer_size)) == |
313 static_cast<int>(visible_buffer_size)); | 342 static_cast<int>(visible_buffer_size)); |
314 const char* src_ptr = &src_data[0]; | 343 const char* src_ptr = &src_data[0]; |
315 for (size_t i = 0; i < num_planes; i++) { | 344 for (size_t i = 0; i < num_planes; i++) { |
316 // Assert that each plane of frame starts at 64 byte boundary. | 345 // Assert that each plane of frame starts at 64 byte boundary. |
317 ASSERT_EQ(dest_offset & 63, 0) | 346 ASSERT_EQ(dest_offset & 63, 0) |
318 << "Planes of frame should be mapped at a 64 byte boundary"; | 347 << "Planes of frame should be mapped at a 64 byte boundary"; |
319 for (size_t j = 0; j < visible_plane_rows[i]; j++) { | 348 for (size_t j = 0; j < visible_plane_rows[i]; j++) { |
320 memcpy(&test_stream->aligned_in_file_data[dest_offset], src_ptr, | 349 memcpy(&test_stream->aligned_in_file_data[dest_offset], src_ptr, |
321 visible_bpl[i]); | 350 visible_bpl[i]); |
322 src_ptr += visible_bpl[i]; | 351 src_ptr += visible_bpl[i]; |
323 dest_offset += coded_bpl[i]; | 352 dest_offset += static_cast<off_t>(coded_bpl[i]); |
324 } | 353 } |
325 dest_offset += padding_sizes[i]; | 354 dest_offset += static_cast<off_t>(padding_sizes[i]); |
326 } | 355 } |
327 src_offset += visible_buffer_size; | 356 src_offset += static_cast<off_t>(visible_buffer_size); |
328 } | 357 } |
329 src.Close(); | 358 src.Close(); |
330 | 359 |
| 360 #if defined(OS_POSIX) |
331 // Assert that memory mapped of file starts at 64 byte boundary. So each | 361 // Assert that memory mapped of file starts at 64 byte boundary. So each |
332 // plane of frames also start at 64 byte boundary. | 362 // plane of frames also start at 64 byte boundary. |
333 ASSERT_EQ(reinterpret_cast<off_t>(&test_stream->aligned_in_file_data[0]) & 63, | 363 ASSERT_EQ(reinterpret_cast<off_t>(&test_stream->aligned_in_file_data[0]) & 63, |
334 0) | 364 0) |
335 << "File should be mapped at a 64 byte boundary"; | 365 << "File should be mapped at a 64 byte boundary"; |
| 366 #endif // defined(OS_POSIX) |
336 | 367 |
337 LOG_ASSERT(test_stream->num_frames > 0UL); | 368 LOG_ASSERT(test_stream->num_frames > 0UL); |
338 } | 369 } |
339 | 370 |
340 // Parse |data| into its constituent parts, set the various output fields | 371 // Parse |data| into its constituent parts, set the various output fields |
341 // accordingly, read in video stream, and store them to |test_streams|. | 372 // accordingly, read in video stream, and store them to |test_streams|. |
342 static void ParseAndReadTestStreamData(const base::FilePath::StringType& data, | 373 static void ParseAndReadTestStreamData(const base::FilePath::StringType& data, |
343 ScopedVector<TestStream>* test_streams) { | 374 ScopedVector<TestStream>* test_streams) { |
344 // Split the string to individual test stream data. | 375 // Split the string to individual test stream data. |
345 std::vector<base::FilePath::StringType> test_streams_data = | 376 std::vector<base::FilePath::StringType> test_streams_data = |
346 base::SplitString(data, base::FilePath::StringType(1, ';'), | 377 base::SplitString(data, base::FilePath::StringType(1, ';'), |
347 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 378 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
348 LOG_ASSERT(test_streams_data.size() >= 1U) << data; | 379 LOG_ASSERT(test_streams_data.size() >= 1U) << data; |
349 | 380 |
350 // Parse each test stream data and read the input file. | 381 // Parse each test stream data and read the input file. |
351 for (size_t index = 0; index < test_streams_data.size(); ++index) { | 382 for (size_t index = 0; index < test_streams_data.size(); ++index) { |
352 std::vector<base::FilePath::StringType> fields = base::SplitString( | 383 std::vector<base::FilePath::StringType> fields = base::SplitString( |
353 test_streams_data[index], base::FilePath::StringType(1, ':'), | 384 test_streams_data[index], base::FilePath::StringType(1, ','), |
354 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 385 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
| 386 // Try using ":" as the seperator if "," isn't used. |
| 387 if (fields.size() == 1U) { |
| 388 fields = base::SplitString(test_streams_data[index], |
| 389 base::FilePath::StringType(1, ':'), |
| 390 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
| 391 } |
355 LOG_ASSERT(fields.size() >= 4U) << data; | 392 LOG_ASSERT(fields.size() >= 4U) << data; |
356 LOG_ASSERT(fields.size() <= 9U) << data; | 393 LOG_ASSERT(fields.size() <= 9U) << data; |
357 TestStream* test_stream = new TestStream(); | 394 TestStream* test_stream = new TestStream(); |
358 | 395 |
359 test_stream->in_filename = fields[0]; | 396 test_stream->in_filename = FilePathStringTypeToString(fields[0]); |
360 int width, height; | 397 int width, height; |
361 bool result = base::StringToInt(fields[1], &width); | 398 bool result = base::StringToInt(fields[1], &width); |
362 LOG_ASSERT(result); | 399 LOG_ASSERT(result); |
363 result = base::StringToInt(fields[2], &height); | 400 result = base::StringToInt(fields[2], &height); |
364 LOG_ASSERT(result); | 401 LOG_ASSERT(result); |
365 test_stream->visible_size = gfx::Size(width, height); | 402 test_stream->visible_size = gfx::Size(width, height); |
366 LOG_ASSERT(!test_stream->visible_size.IsEmpty()); | 403 LOG_ASSERT(!test_stream->visible_size.IsEmpty()); |
367 int profile; | 404 int profile; |
368 result = base::StringToInt(fields[3], &profile); | 405 result = base::StringToInt(fields[3], &profile); |
369 LOG_ASSERT(result); | 406 LOG_ASSERT(result); |
370 LOG_ASSERT(profile > VIDEO_CODEC_PROFILE_UNKNOWN); | 407 LOG_ASSERT(profile > VIDEO_CODEC_PROFILE_UNKNOWN); |
371 LOG_ASSERT(profile <= VIDEO_CODEC_PROFILE_MAX); | 408 LOG_ASSERT(profile <= VIDEO_CODEC_PROFILE_MAX); |
372 test_stream->requested_profile = static_cast<VideoCodecProfile>(profile); | 409 test_stream->requested_profile = static_cast<VideoCodecProfile>(profile); |
373 | 410 |
374 if (fields.size() >= 5 && !fields[4].empty()) | 411 if (fields.size() >= 5 && !fields[4].empty()) |
375 test_stream->out_filename = fields[4]; | 412 test_stream->out_filename = FilePathStringTypeToString(fields[4]); |
376 | 413 |
377 if (fields.size() >= 6 && !fields[5].empty()) | 414 if (fields.size() >= 6 && !fields[5].empty()) |
378 LOG_ASSERT( | 415 LOG_ASSERT( |
379 base::StringToUint(fields[5], &test_stream->requested_bitrate)); | 416 base::StringToUint(fields[5], &test_stream->requested_bitrate)); |
380 | 417 |
381 if (fields.size() >= 7 && !fields[6].empty()) | 418 if (fields.size() >= 7 && !fields[6].empty()) |
382 LOG_ASSERT( | 419 LOG_ASSERT( |
383 base::StringToUint(fields[6], &test_stream->requested_framerate)); | 420 base::StringToUint(fields[6], &test_stream->requested_framerate)); |
384 | 421 |
385 if (fields.size() >= 8 && !fields[7].empty()) { | 422 if (fields.size() >= 8 && !fields[7].empty()) { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
429 } | 466 } |
430 | 467 |
431 // Log one entry of machine-readable data to file and LOG(INFO). | 468 // Log one entry of machine-readable data to file and LOG(INFO). |
432 // The log has one data entry per line in the format of "<key>: <value>". | 469 // The log has one data entry per line in the format of "<key>: <value>". |
433 // Note that Chrome OS video_VEAPerf autotest parses the output key and value | 470 // Note that Chrome OS video_VEAPerf autotest parses the output key and value |
434 // pairs. Be sure to keep the autotest in sync. | 471 // pairs. Be sure to keep the autotest in sync. |
435 void LogToFile(const std::string& key, const std::string& value) { | 472 void LogToFile(const std::string& key, const std::string& value) { |
436 std::string s = base::StringPrintf("%s: %s\n", key.c_str(), value.c_str()); | 473 std::string s = base::StringPrintf("%s: %s\n", key.c_str(), value.c_str()); |
437 LOG(INFO) << s; | 474 LOG(INFO) << s; |
438 if (log_file_) { | 475 if (log_file_) { |
439 log_file_->WriteAtCurrentPos(s.data(), s.length()); | 476 log_file_->WriteAtCurrentPos(s.data(), static_cast<int>(s.length())); |
440 } | 477 } |
441 } | 478 } |
442 | 479 |
443 // Feed the encoder with the input buffers at the requested framerate. If | 480 // Feed the encoder with the input buffers at the requested framerate. If |
444 // false, feed as fast as possible. This is set by the command line switch | 481 // false, feed as fast as possible. This is set by the command line switch |
445 // "--run_at_fps". | 482 // "--run_at_fps". |
446 bool run_at_fps() const { return run_at_fps_; } | 483 bool run_at_fps() const { return run_at_fps_; } |
447 | 484 |
448 // Whether to measure encode latency. This is set by the command line switch | 485 // Whether to measure encode latency. This is set by the command line switch |
449 // "--measure_latency". | 486 // "--measure_latency". |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
518 private: | 555 private: |
519 // Set to true when encoder provides us with the corresponding NALU type. | 556 // Set to true when encoder provides us with the corresponding NALU type. |
520 bool seen_sps_; | 557 bool seen_sps_; |
521 bool seen_pps_; | 558 bool seen_pps_; |
522 bool seen_idr_; | 559 bool seen_idr_; |
523 | 560 |
524 H264Parser h264_parser_; | 561 H264Parser h264_parser_; |
525 }; | 562 }; |
526 | 563 |
527 void H264Validator::ProcessStreamBuffer(const uint8_t* stream, size_t size) { | 564 void H264Validator::ProcessStreamBuffer(const uint8_t* stream, size_t size) { |
528 h264_parser_.SetStream(stream, size); | 565 h264_parser_.SetStream(stream, static_cast<off_t>(size)); |
529 | 566 |
530 while (1) { | 567 while (1) { |
531 H264NALU nalu; | 568 H264NALU nalu; |
532 H264Parser::Result result; | 569 H264Parser::Result result; |
533 | 570 |
534 result = h264_parser_.AdvanceToNextNALU(&nalu); | 571 result = h264_parser_.AdvanceToNextNALU(&nalu); |
535 if (result == H264Parser::kEOStream) | 572 if (result == H264Parser::kEOStream) |
536 break; | 573 break; |
537 | 574 |
538 ASSERT_EQ(H264Parser::kOk, result); | 575 ASSERT_EQ(H264Parser::kOk, result); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
628 // Flush the decoder. | 665 // Flush the decoder. |
629 void Flush(); | 666 void Flush(); |
630 | 667 |
631 private: | 668 private: |
632 void InitializeCB(bool success); | 669 void InitializeCB(bool success); |
633 void DecodeDone(DecodeStatus status); | 670 void DecodeDone(DecodeStatus status); |
634 void FlushDone(DecodeStatus status); | 671 void FlushDone(DecodeStatus status); |
635 void VerifyOutputFrame(const scoped_refptr<VideoFrame>& output_frame); | 672 void VerifyOutputFrame(const scoped_refptr<VideoFrame>& output_frame); |
636 void Decode(); | 673 void Decode(); |
637 | 674 |
638 enum State { UNINITIALIZED, INITIALIZED, DECODING, ERROR }; | 675 enum State { UNINITIALIZED, INITIALIZED, DECODING, DECODER_ERROR }; |
639 | 676 |
640 const VideoCodecProfile profile_; | 677 const VideoCodecProfile profile_; |
641 std::unique_ptr<FFmpegVideoDecoder> decoder_; | 678 std::unique_ptr<FFmpegVideoDecoder> decoder_; |
642 VideoDecoder::DecodeCB decode_cb_; | 679 VideoDecoder::DecodeCB decode_cb_; |
643 // Decode callback of an EOS buffer. | 680 // Decode callback of an EOS buffer. |
644 VideoDecoder::DecodeCB eos_decode_cb_; | 681 VideoDecoder::DecodeCB eos_decode_cb_; |
645 // Callback of Flush(). Called after all frames are decoded. | 682 // Callback of Flush(). Called after all frames are decoded. |
646 const base::Closure flush_complete_cb_; | 683 const base::Closure flush_complete_cb_; |
647 const base::Closure decode_error_cb_; | 684 const base::Closure decode_error_cb_; |
648 State decoder_state_; | 685 State decoder_state_; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
691 base::Unretained(this)), | 728 base::Unretained(this)), |
692 base::Bind(&VideoFrameQualityValidator::VerifyOutputFrame, | 729 base::Bind(&VideoFrameQualityValidator::VerifyOutputFrame, |
693 base::Unretained(this))); | 730 base::Unretained(this))); |
694 } | 731 } |
695 | 732 |
696 void VideoFrameQualityValidator::InitializeCB(bool success) { | 733 void VideoFrameQualityValidator::InitializeCB(bool success) { |
697 if (success) { | 734 if (success) { |
698 decoder_state_ = INITIALIZED; | 735 decoder_state_ = INITIALIZED; |
699 Decode(); | 736 Decode(); |
700 } else { | 737 } else { |
701 decoder_state_ = ERROR; | 738 decoder_state_ = DECODER_ERROR; |
702 if (IsH264(profile_)) | 739 if (IsH264(profile_)) |
703 LOG(ERROR) << "Chromium does not support H264 decode. Try Chrome."; | 740 LOG(ERROR) << "Chromium does not support H264 decode. Try Chrome."; |
| 741 decode_error_cb_.Run(); |
704 FAIL() << "Decoder initialization error"; | 742 FAIL() << "Decoder initialization error"; |
705 decode_error_cb_.Run(); | |
706 } | 743 } |
707 } | 744 } |
708 | 745 |
709 void VideoFrameQualityValidator::AddOriginalFrame( | 746 void VideoFrameQualityValidator::AddOriginalFrame( |
710 scoped_refptr<VideoFrame> frame) { | 747 scoped_refptr<VideoFrame> frame) { |
711 original_frames_.push(frame); | 748 original_frames_.push(frame); |
712 } | 749 } |
713 | 750 |
714 void VideoFrameQualityValidator::DecodeDone(DecodeStatus status) { | 751 void VideoFrameQualityValidator::DecodeDone(DecodeStatus status) { |
715 if (status == DecodeStatus::OK) { | 752 if (status == DecodeStatus::OK) { |
716 decoder_state_ = INITIALIZED; | 753 decoder_state_ = INITIALIZED; |
717 Decode(); | 754 Decode(); |
718 } else { | 755 } else { |
719 decoder_state_ = ERROR; | 756 decoder_state_ = DECODER_ERROR; |
| 757 decode_error_cb_.Run(); |
720 FAIL() << "Unexpected decode status = " << status << ". Stop decoding."; | 758 FAIL() << "Unexpected decode status = " << status << ". Stop decoding."; |
721 decode_error_cb_.Run(); | |
722 } | 759 } |
723 } | 760 } |
724 | 761 |
725 void VideoFrameQualityValidator::FlushDone(DecodeStatus status) { | 762 void VideoFrameQualityValidator::FlushDone(DecodeStatus status) { |
726 flush_complete_cb_.Run(); | 763 flush_complete_cb_.Run(); |
727 } | 764 } |
728 | 765 |
729 void VideoFrameQualityValidator::Flush() { | 766 void VideoFrameQualityValidator::Flush() { |
730 if (decoder_state_ != ERROR) { | 767 if (decoder_state_ != DECODER_ERROR) { |
731 decode_buffers_.push(DecoderBuffer::CreateEOSBuffer()); | 768 decode_buffers_.push(DecoderBuffer::CreateEOSBuffer()); |
732 Decode(); | 769 Decode(); |
733 } | 770 } |
734 } | 771 } |
735 | 772 |
736 void VideoFrameQualityValidator::AddDecodeBuffer( | 773 void VideoFrameQualityValidator::AddDecodeBuffer( |
737 const scoped_refptr<DecoderBuffer>& buffer) { | 774 const scoped_refptr<DecoderBuffer>& buffer) { |
738 if (decoder_state_ != ERROR) { | 775 if (decoder_state_ != DECODER_ERROR) { |
739 decode_buffers_.push(buffer); | 776 decode_buffers_.push(buffer); |
740 Decode(); | 777 Decode(); |
741 } | 778 } |
742 } | 779 } |
743 | 780 |
744 void VideoFrameQualityValidator::Decode() { | 781 void VideoFrameQualityValidator::Decode() { |
745 if (decoder_state_ == INITIALIZED && !decode_buffers_.empty()) { | 782 if (decoder_state_ == INITIALIZED && !decode_buffers_.empty()) { |
746 scoped_refptr<DecoderBuffer> next_buffer = decode_buffers_.front(); | 783 scoped_refptr<DecoderBuffer> next_buffer = decode_buffers_.front(); |
747 decode_buffers_.pop(); | 784 decode_buffers_.pop(); |
748 decoder_state_ = DECODING; | 785 decoder_state_ = DECODING; |
(...skipping 15 matching lines...) Expand all Loading... |
764 double difference = 0; | 801 double difference = 0; |
765 for (int plane : planes) { | 802 for (int plane : planes) { |
766 uint8_t* original_plane = original_frame->data(plane); | 803 uint8_t* original_plane = original_frame->data(plane); |
767 uint8_t* output_plane = output_frame->data(plane); | 804 uint8_t* output_plane = output_frame->data(plane); |
768 | 805 |
769 size_t rows = VideoFrame::Rows(plane, kInputFormat, visible_size.height()); | 806 size_t rows = VideoFrame::Rows(plane, kInputFormat, visible_size.height()); |
770 size_t columns = | 807 size_t columns = |
771 VideoFrame::Columns(plane, kInputFormat, visible_size.width()); | 808 VideoFrame::Columns(plane, kInputFormat, visible_size.width()); |
772 size_t stride = original_frame->stride(plane); | 809 size_t stride = original_frame->stride(plane); |
773 | 810 |
774 for (size_t i = 0; i < rows; i++) | 811 for (size_t i = 0; i < rows; i++) { |
775 for (size_t j = 0; j < columns; j++) | 812 for (size_t j = 0; j < columns; j++) { |
776 difference += std::abs(original_plane[stride * i + j] - | 813 difference += std::abs(original_plane[stride * i + j] - |
777 output_plane[stride * i + j]); | 814 output_plane[stride * i + j]); |
| 815 } |
| 816 } |
778 } | 817 } |
| 818 |
779 // Divide the difference by the size of frame. | 819 // Divide the difference by the size of frame. |
780 difference /= VideoFrame::AllocationSize(kInputFormat, visible_size); | 820 difference /= VideoFrame::AllocationSize(kInputFormat, visible_size); |
781 EXPECT_TRUE(difference <= kDecodeSimilarityThreshold) | 821 EXPECT_TRUE(difference <= kDecodeSimilarityThreshold) |
782 << "differrence = " << difference << " > decode similarity threshold"; | 822 << "difference = " << difference << " > decode similarity threshold"; |
783 } | 823 } |
784 | 824 |
785 class VEAClient : public VideoEncodeAccelerator::Client { | 825 class VEAClient : public VideoEncodeAccelerator::Client { |
786 public: | 826 public: |
787 VEAClient(TestStream* test_stream, | 827 VEAClient(TestStream* test_stream, |
788 ClientStateNotification<ClientState>* note, | 828 ClientStateNotification<ClientState>* note, |
789 bool save_to_file, | 829 bool save_to_file, |
790 unsigned int keyframe_period, | 830 unsigned int keyframe_period, |
791 bool force_bitrate, | 831 bool force_bitrate, |
792 bool test_perf, | 832 bool test_perf, |
(...skipping 18 matching lines...) Expand all Loading... |
811 private: | 851 private: |
812 bool has_encoder() { return encoder_.get(); } | 852 bool has_encoder() { return encoder_.get(); } |
813 | 853 |
814 // Return the number of encoded frames per second. | 854 // Return the number of encoded frames per second. |
815 double frames_per_second(); | 855 double frames_per_second(); |
816 | 856 |
817 std::unique_ptr<VideoEncodeAccelerator> CreateFakeVEA(); | 857 std::unique_ptr<VideoEncodeAccelerator> CreateFakeVEA(); |
818 std::unique_ptr<VideoEncodeAccelerator> CreateV4L2VEA(); | 858 std::unique_ptr<VideoEncodeAccelerator> CreateV4L2VEA(); |
819 std::unique_ptr<VideoEncodeAccelerator> CreateVaapiVEA(); | 859 std::unique_ptr<VideoEncodeAccelerator> CreateVaapiVEA(); |
820 std::unique_ptr<VideoEncodeAccelerator> CreateVTVEA(); | 860 std::unique_ptr<VideoEncodeAccelerator> CreateVTVEA(); |
| 861 std::unique_ptr<VideoEncodeAccelerator> CreateMFVEA(); |
821 | 862 |
822 void SetState(ClientState new_state); | 863 void SetState(ClientState new_state); |
823 | 864 |
824 // Set current stream parameters to given |bitrate| at |framerate|. | 865 // Set current stream parameters to given |bitrate| at |framerate|. |
825 void SetStreamParameters(unsigned int bitrate, unsigned int framerate); | 866 void SetStreamParameters(unsigned int bitrate, unsigned int framerate); |
826 | 867 |
827 // Called when encoder is done with a VideoFrame. | 868 // Called when encoder is done with a VideoFrame. |
828 void InputNoLongerNeededCallback(int32_t input_id); | 869 void InputNoLongerNeededCallback(int32_t input_id); |
829 | 870 |
830 // Feed the encoder with one input frame. | 871 // Feed the encoder with one input frame. |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1043 // Fake encoder produces an invalid stream, so skip validating it. | 1084 // Fake encoder produces an invalid stream, so skip validating it. |
1044 if (!g_fake_encoder) { | 1085 if (!g_fake_encoder) { |
1045 stream_validator_ = StreamValidator::Create( | 1086 stream_validator_ = StreamValidator::Create( |
1046 test_stream_->requested_profile, | 1087 test_stream_->requested_profile, |
1047 base::Bind(&VEAClient::HandleEncodedFrame, base::Unretained(this))); | 1088 base::Bind(&VEAClient::HandleEncodedFrame, base::Unretained(this))); |
1048 CHECK(stream_validator_); | 1089 CHECK(stream_validator_); |
1049 } | 1090 } |
1050 | 1091 |
1051 if (save_to_file_) { | 1092 if (save_to_file_) { |
1052 LOG_ASSERT(!test_stream_->out_filename.empty()); | 1093 LOG_ASSERT(!test_stream_->out_filename.empty()); |
| 1094 #if defined(OS_POSIX) |
1053 base::FilePath out_filename(test_stream_->out_filename); | 1095 base::FilePath out_filename(test_stream_->out_filename); |
| 1096 #elif defined(OS_WIN) |
| 1097 base::FilePath out_filename(base::UTF8ToWide(test_stream_->out_filename)); |
| 1098 #endif |
1054 // This creates or truncates out_filename. | 1099 // This creates or truncates out_filename. |
1055 // Without it, AppendToFile() will not work. | 1100 // Without it, AppendToFile() will not work. |
1056 EXPECT_EQ(0, base::WriteFile(out_filename, NULL, 0)); | 1101 EXPECT_EQ(0, base::WriteFile(out_filename, NULL, 0)); |
1057 } | 1102 } |
1058 | 1103 |
1059 // Initialize the parameters of the test streams. | 1104 // Initialize the parameters of the test streams. |
1060 UpdateTestStreamData(mid_stream_bitrate_switch, mid_stream_framerate_switch); | 1105 UpdateTestStreamData(mid_stream_bitrate_switch, mid_stream_framerate_switch); |
1061 | 1106 |
1062 thread_checker_.DetachFromThread(); | 1107 thread_checker_.DetachFromThread(); |
1063 } | 1108 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1095 } | 1140 } |
1096 | 1141 |
1097 std::unique_ptr<VideoEncodeAccelerator> VEAClient::CreateVTVEA() { | 1142 std::unique_ptr<VideoEncodeAccelerator> VEAClient::CreateVTVEA() { |
1098 std::unique_ptr<VideoEncodeAccelerator> encoder; | 1143 std::unique_ptr<VideoEncodeAccelerator> encoder; |
1099 #if defined(OS_MACOSX) | 1144 #if defined(OS_MACOSX) |
1100 encoder.reset(new VTVideoEncodeAccelerator()); | 1145 encoder.reset(new VTVideoEncodeAccelerator()); |
1101 #endif | 1146 #endif |
1102 return encoder; | 1147 return encoder; |
1103 } | 1148 } |
1104 | 1149 |
| 1150 std::unique_ptr<VideoEncodeAccelerator> VEAClient::CreateMFVEA() { |
| 1151 std::unique_ptr<VideoEncodeAccelerator> encoder; |
| 1152 #if defined(OS_WIN) |
| 1153 MediaFoundationVideoEncodeAccelerator::PreSandboxInitialization(); |
| 1154 encoder.reset(new MediaFoundationVideoEncodeAccelerator()); |
| 1155 #endif |
| 1156 return encoder; |
| 1157 } |
| 1158 |
1105 void VEAClient::CreateEncoder() { | 1159 void VEAClient::CreateEncoder() { |
1106 DCHECK(thread_checker_.CalledOnValidThread()); | 1160 DCHECK(thread_checker_.CalledOnValidThread()); |
1107 LOG_ASSERT(!has_encoder()); | 1161 LOG_ASSERT(!has_encoder()); |
1108 | 1162 |
1109 std::unique_ptr<VideoEncodeAccelerator> encoders[] = { | 1163 std::unique_ptr<VideoEncodeAccelerator> encoders[] = { |
1110 CreateFakeVEA(), CreateV4L2VEA(), CreateVaapiVEA(), CreateVTVEA()}; | 1164 CreateFakeVEA(), CreateV4L2VEA(), CreateVaapiVEA(), CreateVTVEA(), |
| 1165 CreateMFVEA()}; |
1111 | 1166 |
1112 DVLOG(1) << "Profile: " << test_stream_->requested_profile | 1167 DVLOG(1) << "Profile: " << test_stream_->requested_profile |
1113 << ", initial bitrate: " << requested_bitrate_; | 1168 << ", initial bitrate: " << requested_bitrate_; |
1114 | 1169 |
1115 for (size_t i = 0; i < arraysize(encoders); ++i) { | 1170 for (size_t i = 0; i < arraysize(encoders); ++i) { |
1116 if (!encoders[i]) | 1171 if (!encoders[i]) |
1117 continue; | 1172 continue; |
1118 encoder_ = std::move(encoders[i]); | 1173 encoder_ = std::move(encoders[i]); |
1119 SetState(CS_ENCODER_SET); | 1174 SetState(CS_ENCODER_SET); |
1120 if (encoder_->Initialize(kInputFormat, test_stream_->visible_size, | 1175 if (encoder_->Initialize(kInputFormat, test_stream_->visible_size, |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1420 pos_in_input_stream_ = 0; | 1475 pos_in_input_stream_ = 0; |
1421 } | 1476 } |
1422 | 1477 |
1423 if (quality_validator_) | 1478 if (quality_validator_) |
1424 quality_validator_->AddOriginalFrame(CreateFrame(pos_in_input_stream_)); | 1479 quality_validator_->AddOriginalFrame(CreateFrame(pos_in_input_stream_)); |
1425 | 1480 |
1426 int32_t input_id; | 1481 int32_t input_id; |
1427 scoped_refptr<VideoFrame> video_frame = | 1482 scoped_refptr<VideoFrame> video_frame = |
1428 PrepareInputFrame(pos_in_input_stream_, &input_id); | 1483 PrepareInputFrame(pos_in_input_stream_, &input_id); |
1429 frame_timestamps_.push(video_frame->timestamp()); | 1484 frame_timestamps_.push(video_frame->timestamp()); |
1430 pos_in_input_stream_ += test_stream_->aligned_buffer_size; | 1485 pos_in_input_stream_ += static_cast<off_t>(test_stream_->aligned_buffer_size); |
1431 | 1486 |
1432 bool force_keyframe = false; | 1487 bool force_keyframe = false; |
1433 if (keyframe_period_ && input_id % keyframe_period_ == 0) { | 1488 if (keyframe_period_ && input_id % keyframe_period_ == 0) { |
1434 force_keyframe = true; | 1489 force_keyframe = true; |
1435 ++num_keyframes_requested_; | 1490 ++num_keyframes_requested_; |
1436 } | 1491 } |
1437 | 1492 |
1438 if (input_id == 0) { | 1493 if (input_id == 0) { |
1439 first_frame_start_time_ = base::TimeTicks::Now(); | 1494 first_frame_start_time_ = base::TimeTicks::Now(); |
1440 } | 1495 } |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1550 } | 1605 } |
1551 | 1606 |
1552 void VEAClient::VerifyMinFPS() { | 1607 void VEAClient::VerifyMinFPS() { |
1553 if (test_perf_) | 1608 if (test_perf_) |
1554 EXPECT_GE(frames_per_second(), kMinPerfFPS); | 1609 EXPECT_GE(frames_per_second(), kMinPerfFPS); |
1555 } | 1610 } |
1556 | 1611 |
1557 void VEAClient::VerifyStreamProperties() { | 1612 void VEAClient::VerifyStreamProperties() { |
1558 LOG_ASSERT(num_frames_since_last_check_ > 0UL); | 1613 LOG_ASSERT(num_frames_since_last_check_ > 0UL); |
1559 LOG_ASSERT(encoded_stream_size_since_last_check_ > 0UL); | 1614 LOG_ASSERT(encoded_stream_size_since_last_check_ > 0UL); |
1560 unsigned int bitrate = encoded_stream_size_since_last_check_ * 8 * | 1615 unsigned int bitrate = static_cast<unsigned int>( |
1561 current_framerate_ / num_frames_since_last_check_; | 1616 encoded_stream_size_since_last_check_ * 8 * current_framerate_ / |
| 1617 num_frames_since_last_check_); |
1562 DVLOG(1) << "Current chunk's bitrate: " << bitrate | 1618 DVLOG(1) << "Current chunk's bitrate: " << bitrate |
1563 << " (expected: " << current_requested_bitrate_ | 1619 << " (expected: " << current_requested_bitrate_ << " @ " |
1564 << " @ " << current_framerate_ << " FPS," | 1620 << current_framerate_ << " FPS," |
1565 << " num frames in chunk: " << num_frames_since_last_check_; | 1621 << " num frames in chunk: " << num_frames_since_last_check_; |
1566 | 1622 |
1567 num_frames_since_last_check_ = 0; | 1623 num_frames_since_last_check_ = 0; |
1568 encoded_stream_size_since_last_check_ = 0; | 1624 encoded_stream_size_since_last_check_ = 0; |
1569 | 1625 |
1570 if (force_bitrate_) { | 1626 if (force_bitrate_) { |
1571 EXPECT_NEAR(bitrate, current_requested_bitrate_, | 1627 EXPECT_NEAR(bitrate, current_requested_bitrate_, |
1572 kBitrateTolerance * current_requested_bitrate_); | 1628 kBitrateTolerance * current_requested_bitrate_); |
1573 } | 1629 } |
1574 | 1630 |
(...skipping 23 matching lines...) Expand all Loading... |
1598 header.ByteSwap(); | 1654 header.ByteSwap(); |
1599 | 1655 |
1600 EXPECT_TRUE(base::AppendToFile( | 1656 EXPECT_TRUE(base::AppendToFile( |
1601 base::FilePath::FromUTF8Unsafe(test_stream_->out_filename), | 1657 base::FilePath::FromUTF8Unsafe(test_stream_->out_filename), |
1602 reinterpret_cast<char*>(&header), sizeof(header))); | 1658 reinterpret_cast<char*>(&header), sizeof(header))); |
1603 } | 1659 } |
1604 | 1660 |
1605 void VEAClient::WriteIvfFrameHeader(int frame_index, size_t frame_size) { | 1661 void VEAClient::WriteIvfFrameHeader(int frame_index, size_t frame_size) { |
1606 IvfFrameHeader header = {}; | 1662 IvfFrameHeader header = {}; |
1607 | 1663 |
1608 header.frame_size = frame_size; | 1664 header.frame_size = static_cast<uint32_t>(frame_size); |
1609 header.timestamp = frame_index; | 1665 header.timestamp = frame_index; |
1610 header.ByteSwap(); | 1666 header.ByteSwap(); |
1611 EXPECT_TRUE(base::AppendToFile( | 1667 EXPECT_TRUE(base::AppendToFile( |
1612 base::FilePath::FromUTF8Unsafe(test_stream_->out_filename), | 1668 base::FilePath::FromUTF8Unsafe(test_stream_->out_filename), |
1613 reinterpret_cast<char*>(&header), sizeof(header))); | 1669 reinterpret_cast<char*>(&header), sizeof(header))); |
1614 } | 1670 } |
1615 | 1671 |
1616 // Test parameters: | 1672 // Test parameters: |
1617 // - Number of concurrent encoders. The value takes effect when there is only | 1673 // - Number of concurrent encoders. The value takes effect when there is only |
1618 // one input stream; otherwise, one encoder per input stream will be | 1674 // one input stream; otherwise, one encoder per input stream will be |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1690 for (size_t i = 0; i < num_concurrent_encoders; ++i) { | 1746 for (size_t i = 0; i < num_concurrent_encoders; ++i) { |
1691 encoder_thread.task_runner()->PostTask( | 1747 encoder_thread.task_runner()->PostTask( |
1692 FROM_HERE, | 1748 FROM_HERE, |
1693 base::Bind(&VEAClient::DestroyEncoder, base::Unretained(clients[i]))); | 1749 base::Bind(&VEAClient::DestroyEncoder, base::Unretained(clients[i]))); |
1694 } | 1750 } |
1695 | 1751 |
1696 // This ensures all tasks have finished. | 1752 // This ensures all tasks have finished. |
1697 encoder_thread.Stop(); | 1753 encoder_thread.Stop(); |
1698 } | 1754 } |
1699 | 1755 |
1700 #if !defined(OS_MACOSX) | 1756 #if defined(OS_CHROMEOS) |
1701 INSTANTIATE_TEST_CASE_P( | 1757 INSTANTIATE_TEST_CASE_P( |
1702 SimpleEncode, | 1758 SimpleEncode, |
1703 VideoEncodeAcceleratorTest, | 1759 VideoEncodeAcceleratorTest, |
1704 ::testing::Values( | 1760 ::testing::Values( |
1705 std::make_tuple(1, true, 0, false, false, false, false, false, false), | 1761 std::make_tuple(1, true, 0, false, false, false, false, false, false), |
1706 std::make_tuple(1, true, 0, false, false, false, false, true, false))); | 1762 std::make_tuple(1, true, 0, false, false, false, false, true, false))); |
1707 | 1763 |
1708 INSTANTIATE_TEST_CASE_P( | 1764 INSTANTIATE_TEST_CASE_P( |
1709 EncoderPerf, | 1765 EncoderPerf, |
1710 VideoEncodeAcceleratorTest, | 1766 VideoEncodeAcceleratorTest, |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1748 std::make_tuple(3, false, 0, false, false, false, false, false, false), | 1804 std::make_tuple(3, false, 0, false, false, false, false, false, false), |
1749 std::make_tuple(3, false, 0, true, false, false, true, false, false), | 1805 std::make_tuple(3, false, 0, true, false, false, true, false, false), |
1750 std::make_tuple(3, false, 0, true, false, true, false, false, false))); | 1806 std::make_tuple(3, false, 0, true, false, true, false, false, false))); |
1751 | 1807 |
1752 INSTANTIATE_TEST_CASE_P( | 1808 INSTANTIATE_TEST_CASE_P( |
1753 VerifyTimestamp, | 1809 VerifyTimestamp, |
1754 VideoEncodeAcceleratorTest, | 1810 VideoEncodeAcceleratorTest, |
1755 ::testing::Values( | 1811 ::testing::Values( |
1756 std::make_tuple(1, false, 0, false, false, false, false, false, true))); | 1812 std::make_tuple(1, false, 0, false, false, false, false, false, true))); |
1757 | 1813 |
1758 #else | 1814 #elif defined(OS_MACOSX) || defined(OS_WIN) |
1759 INSTANTIATE_TEST_CASE_P( | 1815 INSTANTIATE_TEST_CASE_P( |
1760 SimpleEncode, | 1816 SimpleEncode, |
1761 VideoEncodeAcceleratorTest, | 1817 VideoEncodeAcceleratorTest, |
1762 ::testing::Values( | 1818 ::testing::Values( |
1763 std::make_tuple(1, true, 0, false, false, false, false, false, false), | 1819 std::make_tuple(1, true, 0, false, false, false, false, false, false), |
1764 std::make_tuple(1, true, 0, false, false, false, false, true, false))); | 1820 std::make_tuple(1, true, 0, false, false, false, false, true, false))); |
1765 | 1821 |
1766 INSTANTIATE_TEST_CASE_P( | 1822 INSTANTIATE_TEST_CASE_P( |
1767 EncoderPerf, | 1823 EncoderPerf, |
1768 VideoEncodeAcceleratorTest, | 1824 VideoEncodeAcceleratorTest, |
1769 ::testing::Values( | 1825 ::testing::Values( |
1770 std::make_tuple(1, false, 0, false, true, false, false, false, false))); | 1826 std::make_tuple(1, false, 0, false, true, false, false, false, false))); |
1771 | 1827 |
1772 INSTANTIATE_TEST_CASE_P(MultipleEncoders, | 1828 INSTANTIATE_TEST_CASE_P(MultipleEncoders, |
1773 VideoEncodeAcceleratorTest, | 1829 VideoEncodeAcceleratorTest, |
1774 ::testing::Values(std::make_tuple(3, | 1830 ::testing::Values(std::make_tuple(3, |
1775 false, | 1831 false, |
1776 0, | 1832 0, |
1777 false, | 1833 false, |
1778 false, | 1834 false, |
1779 false, | 1835 false, |
1780 false, | 1836 false, |
1781 false, | 1837 false, |
1782 false))); | 1838 false))); |
1783 #endif | 1839 #if defined(OS_WIN) |
| 1840 INSTANTIATE_TEST_CASE_P( |
| 1841 ForceBitrate, |
| 1842 VideoEncodeAcceleratorTest, |
| 1843 ::testing::Values( |
| 1844 std::make_tuple(1, false, 0, true, false, false, false, false, false))); |
| 1845 #endif // defined(OS_WIN) |
| 1846 |
| 1847 #endif // defined(OS_CHROMEOS) |
1784 | 1848 |
1785 // TODO(posciak): more tests: | 1849 // TODO(posciak): more tests: |
1786 // - async FeedEncoderWithOutput | 1850 // - async FeedEncoderWithOutput |
1787 // - out-of-order return of outputs to encoder | 1851 // - out-of-order return of outputs to encoder |
1788 // - multiple encoders + decoders | 1852 // - multiple encoders + decoders |
1789 // - mid-stream encoder_->Destroy() | 1853 // - mid-stream encoder_->Destroy() |
1790 | 1854 |
1791 } // namespace | 1855 } // namespace |
1792 } // namespace media | 1856 } // namespace media |
1793 | 1857 |
1794 int main(int argc, char** argv) { | 1858 int main(int argc, char** argv) { |
1795 testing::InitGoogleTest(&argc, argv); // Removes gtest-specific args. | 1859 testing::InitGoogleTest(&argc, argv); // Removes gtest-specific args. |
1796 base::CommandLine::Init(argc, argv); | 1860 base::CommandLine::Init(argc, argv); |
1797 | 1861 |
1798 base::ShadowingAtExitManager at_exit_manager; | 1862 base::ShadowingAtExitManager at_exit_manager; |
1799 base::MessageLoop main_loop; | 1863 base::MessageLoop main_loop; |
1800 | 1864 |
1801 std::unique_ptr<base::FilePath::StringType> test_stream_data( | 1865 std::unique_ptr<base::FilePath::StringType> test_stream_data( |
1802 new base::FilePath::StringType( | 1866 new base::FilePath::StringType( |
1803 media::GetTestDataFilePath(media::g_default_in_filename).value() + | 1867 media::GetTestDataFilePath(media::g_default_in_filename).value())); |
1804 media::g_default_in_parameters)); | 1868 test_stream_data->append(media::g_default_in_parameters); |
1805 | 1869 |
1806 // Needed to enable DVLOG through --vmodule. | 1870 // Needed to enable DVLOG through --vmodule. |
1807 logging::LoggingSettings settings; | 1871 logging::LoggingSettings settings; |
1808 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; | 1872 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; |
1809 LOG_ASSERT(logging::InitLogging(settings)); | 1873 LOG_ASSERT(logging::InitLogging(settings)); |
1810 | 1874 |
1811 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); | 1875 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); |
1812 DCHECK(cmd_line); | 1876 DCHECK(cmd_line); |
1813 | 1877 |
1814 bool run_at_fps = false; | 1878 bool run_at_fps = false; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1870 | 1934 |
1871 media::g_env = | 1935 media::g_env = |
1872 reinterpret_cast<media::VideoEncodeAcceleratorTestEnvironment*>( | 1936 reinterpret_cast<media::VideoEncodeAcceleratorTestEnvironment*>( |
1873 testing::AddGlobalTestEnvironment( | 1937 testing::AddGlobalTestEnvironment( |
1874 new media::VideoEncodeAcceleratorTestEnvironment( | 1938 new media::VideoEncodeAcceleratorTestEnvironment( |
1875 std::move(test_stream_data), log_path, run_at_fps, | 1939 std::move(test_stream_data), log_path, run_at_fps, |
1876 needs_encode_latency, verify_all_output))); | 1940 needs_encode_latency, verify_all_output))); |
1877 | 1941 |
1878 return RUN_ALL_TESTS(); | 1942 return RUN_ALL_TESTS(); |
1879 } | 1943 } |
OLD | NEW |