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 26 matching lines...) Expand all Loading... | |
100 // an encoder to be able to converge to the requested bitrate over. | 103 // an encoder to be able to converge to the requested bitrate over. |
101 // The input stream will be looped as many times as needed in bitrate tests | 104 // The input stream will be looped as many times as needed in bitrate tests |
102 // to reach at least this number of frames before calculating final bitrate. | 105 // to reach at least this number of frames before calculating final bitrate. |
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 |
wuchengli
2016/07/20 09:22:18
Pawel, Kuang-che and I discussed.
- Can we use ","
emircan
2016/07/20 19:01:19
Done.
Thanks for the suggestion. I took the seco
| |
111 // :requested_framerate:requested_subsequent_bitrate | 114 // &requested_framerate&requested_subsequent_bitrate |
112 // :requested_subsequent_framerate" | 115 // &requested_subsequent_framerate" |
113 // - |in_filename| must be an I420 (YUV planar) raw stream | 116 // - |in_filename| must be an I420 (YUV planar) raw stream |
114 // (see http://www.fourcc.org/yuv.php#IYUV). | 117 // (see http://www.fourcc.org/yuv.php#IYUV). |
115 // - |width| and |height| are in pixels. | 118 // - |width| and |height| are in pixels. |
116 // - |profile| to encode into (values of VideoCodecProfile). | 119 // - |profile| to encode into (values of VideoCodecProfile). |
117 // - |out_filename| filename to save the encoded stream to (optional). The | 120 // - |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 | 121 // 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 | 122 // 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 | 123 // 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. | 124 // "mplayer -fps 25 out.h264" and IVF can be played by mplayer directly. |
122 // Helpful description: http://wiki.multimedia.cx/index.php?title=IVF | 125 // Helpful description: http://wiki.multimedia.cx/index.php?title=IVF |
123 // Further parameters are optional (need to provide preceding positional | 126 // Further parameters are optional (need to provide preceding positional |
124 // parameters if a specific subsequent parameter is required): | 127 // parameters if a specific subsequent parameter is required): |
125 // - |requested_bitrate| requested bitrate in bits per second. | 128 // - |requested_bitrate| requested bitrate in bits per second. |
126 // - |requested_framerate| requested initial framerate. | 129 // - |requested_framerate| requested initial framerate. |
127 // - |requested_subsequent_bitrate| bitrate to switch to in the middle of the | 130 // - |requested_subsequent_bitrate| bitrate to switch to in the middle of the |
128 // stream. | 131 // stream. |
129 // - |requested_subsequent_framerate| framerate to switch to in the middle | 132 // - |requested_subsequent_framerate| framerate to switch to in the middle |
130 // of the stream. | 133 // of the stream. |
131 // Bitrate is only forced for tests that test bitrate. | 134 // Bitrate is only forced for tests that test bitrate. |
132 const char* g_default_in_filename = "bear_320x192_40frames.yuv"; | 135 const char* g_default_in_filename = "bear_320x192_40frames.yuv"; |
133 #if !defined(OS_MACOSX) | 136 |
134 const char* g_default_in_parameters = ":320:192:1:out.h264:200000"; | 137 #if defined(OS_CHROMEOS) |
135 #else | 138 const base::FilePath::CharType* g_default_in_parameters = |
136 const char* g_default_in_parameters = ":320:192:0:out.h264:200000"; | 139 FILE_PATH_LITERAL("&320&192&1&out.h264&200000"); |
137 #endif | 140 #elif defined(OS_MACOSX) || defined(OS_WIN) |
141 const base::FilePath::CharType* g_default_in_parameters = | |
142 FILE_PATH_LITERAL("&320&192&0&out.h264&200000"); | |
143 #endif // defined(OS_CHROMEOS) | |
138 | 144 |
139 // Enabled by including a --fake_encoder flag to the command line invoking the | 145 // Enabled by including a --fake_encoder flag to the command line invoking the |
140 // test. | 146 // test. |
141 bool g_fake_encoder = false; | 147 bool g_fake_encoder = false; |
142 | 148 |
143 // Environment to store test stream data for all test cases. | 149 // Environment to store test stream data for all test cases. |
144 class VideoEncodeAcceleratorTestEnvironment; | 150 class VideoEncodeAcceleratorTestEnvironment; |
145 VideoEncodeAcceleratorTestEnvironment* g_env; | 151 VideoEncodeAcceleratorTestEnvironment* g_env; |
146 | 152 |
147 // The number of frames to be encoded. This variable is set by the switch | 153 // 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 } | 239 } |
234 | 240 |
235 static bool IsH264(VideoCodecProfile profile) { | 241 static bool IsH264(VideoCodecProfile profile) { |
236 return profile >= H264PROFILE_MIN && profile <= H264PROFILE_MAX; | 242 return profile >= H264PROFILE_MIN && profile <= H264PROFILE_MAX; |
237 } | 243 } |
238 | 244 |
239 static bool IsVP8(VideoCodecProfile profile) { | 245 static bool IsVP8(VideoCodecProfile profile) { |
240 return profile >= VP8PROFILE_MIN && profile <= VP8PROFILE_MAX; | 246 return profile >= VP8PROFILE_MIN && profile <= VP8PROFILE_MAX; |
241 } | 247 } |
242 | 248 |
249 // Helper functions to do string conversions. | |
250 static base::FilePath::StringType StringToFilePathStringType( | |
251 const std::string& str) { | |
252 #if defined(OS_WIN) | |
253 return base::UTF8ToWide(str); | |
254 #else | |
255 return str; | |
256 #endif // defined(OS_WIN) | |
257 } | |
258 | |
259 static std::string FilePathStringTypeToString( | |
260 const base::FilePath::StringType& str) { | |
261 #if defined(OS_WIN) | |
262 return base::WideToUTF8(str); | |
263 #else | |
264 return str; | |
265 #endif // defined(OS_WIN) | |
266 } | |
267 | |
243 // ARM performs CPU cache management with CPU cache line granularity. We thus | 268 // 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). | 269 // 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 | 270 // Otherwise newer kernels will refuse to accept them, and on older kernels |
246 // we'll be treating ourselves to random corruption. | 271 // we'll be treating ourselves to random corruption. |
247 // Since we are just mapping and passing chunks of the input file directly to | 272 // 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 | 273 // 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 | 274 // frame and thus affecting performance measurements, we have to prepare a |
250 // temporary file with all planes aligned to 64-byte boundaries beforehand. | 275 // temporary file with all planes aligned to 64-byte boundaries beforehand. |
251 static void CreateAlignedInputStreamFile(const gfx::Size& coded_size, | 276 static void CreateAlignedInputStreamFile(const gfx::Size& coded_size, |
252 TestStream* test_stream) { | 277 TestStream* test_stream) { |
(...skipping 30 matching lines...) Expand all Loading... | |
283 visible_bpl[i] = VideoFrame::RowBytes(i, kInputFormat, | 308 visible_bpl[i] = VideoFrame::RowBytes(i, kInputFormat, |
284 test_stream->visible_size.width()); | 309 test_stream->visible_size.width()); |
285 visible_plane_rows[i] = | 310 visible_plane_rows[i] = |
286 VideoFrame::Rows(i, kInputFormat, test_stream->visible_size.height()); | 311 VideoFrame::Rows(i, kInputFormat, test_stream->visible_size.height()); |
287 const size_t padding_rows = | 312 const size_t padding_rows = |
288 VideoFrame::Rows(i, kInputFormat, coded_size.height()) - | 313 VideoFrame::Rows(i, kInputFormat, coded_size.height()) - |
289 visible_plane_rows[i]; | 314 visible_plane_rows[i]; |
290 padding_sizes[i] = padding_rows * coded_bpl[i] + Align64Bytes(size) - size; | 315 padding_sizes[i] = padding_rows * coded_bpl[i] + Align64Bytes(size) - size; |
291 } | 316 } |
292 | 317 |
293 base::FilePath src_file(test_stream->in_filename); | 318 base::FilePath src_file(StringToFilePathStringType(test_stream->in_filename)); |
294 int64_t src_file_size = 0; | 319 int64_t src_file_size = 0; |
295 LOG_ASSERT(base::GetFileSize(src_file, &src_file_size)); | 320 LOG_ASSERT(base::GetFileSize(src_file, &src_file_size)); |
296 | 321 |
297 size_t visible_buffer_size = | 322 size_t visible_buffer_size = |
298 VideoFrame::AllocationSize(kInputFormat, test_stream->visible_size); | 323 VideoFrame::AllocationSize(kInputFormat, test_stream->visible_size); |
299 LOG_ASSERT(src_file_size % visible_buffer_size == 0U) | 324 LOG_ASSERT(src_file_size % visible_buffer_size == 0U) |
300 << "Stream byte size is not a product of calculated frame byte size"; | 325 << "Stream byte size is not a product of calculated frame byte size"; |
301 | 326 |
302 test_stream->num_frames = src_file_size / visible_buffer_size; | 327 test_stream->num_frames = src_file_size / visible_buffer_size; |
303 | 328 |
(...skipping 17 matching lines...) Expand all Loading... | |
321 visible_bpl[i]); | 346 visible_bpl[i]); |
322 src_ptr += visible_bpl[i]; | 347 src_ptr += visible_bpl[i]; |
323 dest_offset += coded_bpl[i]; | 348 dest_offset += coded_bpl[i]; |
324 } | 349 } |
325 dest_offset += padding_sizes[i]; | 350 dest_offset += padding_sizes[i]; |
326 } | 351 } |
327 src_offset += visible_buffer_size; | 352 src_offset += visible_buffer_size; |
328 } | 353 } |
329 src.Close(); | 354 src.Close(); |
330 | 355 |
356 #if defined(OS_POSIX) | |
331 // Assert that memory mapped of file starts at 64 byte boundary. So each | 357 // Assert that memory mapped of file starts at 64 byte boundary. So each |
332 // plane of frames also start at 64 byte boundary. | 358 // plane of frames also start at 64 byte boundary. |
333 ASSERT_EQ(reinterpret_cast<off_t>(&test_stream->aligned_in_file_data[0]) & 63, | 359 ASSERT_EQ(reinterpret_cast<off_t>(&test_stream->aligned_in_file_data[0]) & 63, |
334 0) | 360 0) |
335 << "File should be mapped at a 64 byte boundary"; | 361 << "File should be mapped at a 64 byte boundary"; |
362 #endif // defined(OS_POSIX) | |
336 | 363 |
337 LOG_ASSERT(test_stream->num_frames > 0UL); | 364 LOG_ASSERT(test_stream->num_frames > 0UL); |
338 } | 365 } |
339 | 366 |
340 // Parse |data| into its constituent parts, set the various output fields | 367 // Parse |data| into its constituent parts, set the various output fields |
341 // accordingly, read in video stream, and store them to |test_streams|. | 368 // accordingly, read in video stream, and store them to |test_streams|. |
342 static void ParseAndReadTestStreamData(const base::FilePath::StringType& data, | 369 static void ParseAndReadTestStreamData(const base::FilePath::StringType& data, |
343 ScopedVector<TestStream>* test_streams) { | 370 ScopedVector<TestStream>* test_streams) { |
344 // Split the string to individual test stream data. | 371 // Split the string to individual test stream data. |
345 std::vector<base::FilePath::StringType> test_streams_data = | 372 std::vector<base::FilePath::StringType> test_streams_data = |
346 base::SplitString(data, base::FilePath::StringType(1, ';'), | 373 base::SplitString(data, base::FilePath::StringType(1, ';'), |
347 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 374 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
348 LOG_ASSERT(test_streams_data.size() >= 1U) << data; | 375 LOG_ASSERT(test_streams_data.size() >= 1U) << data; |
349 | 376 |
350 // Parse each test stream data and read the input file. | 377 // Parse each test stream data and read the input file. |
351 for (size_t index = 0; index < test_streams_data.size(); ++index) { | 378 for (size_t index = 0; index < test_streams_data.size(); ++index) { |
352 std::vector<base::FilePath::StringType> fields = base::SplitString( | 379 std::vector<base::FilePath::StringType> fields = base::SplitString( |
353 test_streams_data[index], base::FilePath::StringType(1, ':'), | 380 test_streams_data[index], base::FilePath::StringType(1, '&'), |
354 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 381 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
355 LOG_ASSERT(fields.size() >= 4U) << data; | 382 LOG_ASSERT(fields.size() >= 4U) << data; |
356 LOG_ASSERT(fields.size() <= 9U) << data; | 383 LOG_ASSERT(fields.size() <= 9U) << data; |
357 TestStream* test_stream = new TestStream(); | 384 TestStream* test_stream = new TestStream(); |
358 | 385 |
359 test_stream->in_filename = fields[0]; | 386 test_stream->in_filename = FilePathStringTypeToString(fields[0]); |
360 int width, height; | 387 int width, height; |
361 bool result = base::StringToInt(fields[1], &width); | 388 bool result = base::StringToInt(fields[1], &width); |
362 LOG_ASSERT(result); | 389 LOG_ASSERT(result); |
363 result = base::StringToInt(fields[2], &height); | 390 result = base::StringToInt(fields[2], &height); |
364 LOG_ASSERT(result); | 391 LOG_ASSERT(result); |
365 test_stream->visible_size = gfx::Size(width, height); | 392 test_stream->visible_size = gfx::Size(width, height); |
366 LOG_ASSERT(!test_stream->visible_size.IsEmpty()); | 393 LOG_ASSERT(!test_stream->visible_size.IsEmpty()); |
367 int profile; | 394 int profile; |
368 result = base::StringToInt(fields[3], &profile); | 395 result = base::StringToInt(fields[3], &profile); |
369 LOG_ASSERT(result); | 396 LOG_ASSERT(result); |
370 LOG_ASSERT(profile > VIDEO_CODEC_PROFILE_UNKNOWN); | 397 LOG_ASSERT(profile > VIDEO_CODEC_PROFILE_UNKNOWN); |
371 LOG_ASSERT(profile <= VIDEO_CODEC_PROFILE_MAX); | 398 LOG_ASSERT(profile <= VIDEO_CODEC_PROFILE_MAX); |
372 test_stream->requested_profile = static_cast<VideoCodecProfile>(profile); | 399 test_stream->requested_profile = static_cast<VideoCodecProfile>(profile); |
373 | 400 |
374 if (fields.size() >= 5 && !fields[4].empty()) | 401 if (fields.size() >= 5 && !fields[4].empty()) |
375 test_stream->out_filename = fields[4]; | 402 test_stream->out_filename = FilePathStringTypeToString(fields[4]); |
376 | 403 |
377 if (fields.size() >= 6 && !fields[5].empty()) | 404 if (fields.size() >= 6 && !fields[5].empty()) |
378 LOG_ASSERT( | 405 LOG_ASSERT( |
379 base::StringToUint(fields[5], &test_stream->requested_bitrate)); | 406 base::StringToUint(fields[5], &test_stream->requested_bitrate)); |
380 | 407 |
381 if (fields.size() >= 7 && !fields[6].empty()) | 408 if (fields.size() >= 7 && !fields[6].empty()) |
382 LOG_ASSERT( | 409 LOG_ASSERT( |
383 base::StringToUint(fields[6], &test_stream->requested_framerate)); | 410 base::StringToUint(fields[6], &test_stream->requested_framerate)); |
384 | 411 |
385 if (fields.size() >= 8 && !fields[7].empty()) { | 412 if (fields.size() >= 8 && !fields[7].empty()) { |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
628 // Flush the decoder. | 655 // Flush the decoder. |
629 void Flush(); | 656 void Flush(); |
630 | 657 |
631 private: | 658 private: |
632 void InitializeCB(bool success); | 659 void InitializeCB(bool success); |
633 void DecodeDone(DecodeStatus status); | 660 void DecodeDone(DecodeStatus status); |
634 void FlushDone(DecodeStatus status); | 661 void FlushDone(DecodeStatus status); |
635 void VerifyOutputFrame(const scoped_refptr<VideoFrame>& output_frame); | 662 void VerifyOutputFrame(const scoped_refptr<VideoFrame>& output_frame); |
636 void Decode(); | 663 void Decode(); |
637 | 664 |
638 enum State { UNINITIALIZED, INITIALIZED, DECODING, ERROR }; | 665 enum State { UNINITIALIZED, INITIALIZED, DECODING, DECODER_ERROR }; |
639 | 666 |
640 const VideoCodecProfile profile_; | 667 const VideoCodecProfile profile_; |
641 std::unique_ptr<FFmpegVideoDecoder> decoder_; | 668 std::unique_ptr<FFmpegVideoDecoder> decoder_; |
642 VideoDecoder::DecodeCB decode_cb_; | 669 VideoDecoder::DecodeCB decode_cb_; |
643 // Decode callback of an EOS buffer. | 670 // Decode callback of an EOS buffer. |
644 VideoDecoder::DecodeCB eos_decode_cb_; | 671 VideoDecoder::DecodeCB eos_decode_cb_; |
645 // Callback of Flush(). Called after all frames are decoded. | 672 // Callback of Flush(). Called after all frames are decoded. |
646 const base::Closure flush_complete_cb_; | 673 const base::Closure flush_complete_cb_; |
647 const base::Closure decode_error_cb_; | 674 const base::Closure decode_error_cb_; |
648 State decoder_state_; | 675 State decoder_state_; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
691 base::Unretained(this)), | 718 base::Unretained(this)), |
692 base::Bind(&VideoFrameQualityValidator::VerifyOutputFrame, | 719 base::Bind(&VideoFrameQualityValidator::VerifyOutputFrame, |
693 base::Unretained(this))); | 720 base::Unretained(this))); |
694 } | 721 } |
695 | 722 |
696 void VideoFrameQualityValidator::InitializeCB(bool success) { | 723 void VideoFrameQualityValidator::InitializeCB(bool success) { |
697 if (success) { | 724 if (success) { |
698 decoder_state_ = INITIALIZED; | 725 decoder_state_ = INITIALIZED; |
699 Decode(); | 726 Decode(); |
700 } else { | 727 } else { |
701 decoder_state_ = ERROR; | 728 decoder_state_ = DECODER_ERROR; |
702 if (IsH264(profile_)) | 729 if (IsH264(profile_)) |
703 LOG(ERROR) << "Chromium does not support H264 decode. Try Chrome."; | 730 LOG(ERROR) << "Chromium does not support H264 decode. Try Chrome."; |
704 FAIL() << "Decoder initialization error"; | 731 FAIL() << "Decoder initialization error"; |
705 decode_error_cb_.Run(); | 732 decode_error_cb_.Run(); |
706 } | 733 } |
707 } | 734 } |
708 | 735 |
709 void VideoFrameQualityValidator::AddOriginalFrame( | 736 void VideoFrameQualityValidator::AddOriginalFrame( |
710 scoped_refptr<VideoFrame> frame) { | 737 scoped_refptr<VideoFrame> frame) { |
711 original_frames_.push(frame); | 738 original_frames_.push(frame); |
712 } | 739 } |
713 | 740 |
714 void VideoFrameQualityValidator::DecodeDone(DecodeStatus status) { | 741 void VideoFrameQualityValidator::DecodeDone(DecodeStatus status) { |
715 if (status == DecodeStatus::OK) { | 742 if (status == DecodeStatus::OK) { |
716 decoder_state_ = INITIALIZED; | 743 decoder_state_ = INITIALIZED; |
717 Decode(); | 744 Decode(); |
718 } else { | 745 } else { |
719 decoder_state_ = ERROR; | 746 decoder_state_ = DECODER_ERROR; |
720 FAIL() << "Unexpected decode status = " << status << ". Stop decoding."; | 747 FAIL() << "Unexpected decode status = " << status << ". Stop decoding."; |
721 decode_error_cb_.Run(); | 748 decode_error_cb_.Run(); |
722 } | 749 } |
723 } | 750 } |
724 | 751 |
725 void VideoFrameQualityValidator::FlushDone(DecodeStatus status) { | 752 void VideoFrameQualityValidator::FlushDone(DecodeStatus status) { |
726 flush_complete_cb_.Run(); | 753 flush_complete_cb_.Run(); |
727 } | 754 } |
728 | 755 |
729 void VideoFrameQualityValidator::Flush() { | 756 void VideoFrameQualityValidator::Flush() { |
730 if (decoder_state_ != ERROR) { | 757 if (decoder_state_ != DECODER_ERROR) { |
731 decode_buffers_.push(DecoderBuffer::CreateEOSBuffer()); | 758 decode_buffers_.push(DecoderBuffer::CreateEOSBuffer()); |
732 Decode(); | 759 Decode(); |
733 } | 760 } |
734 } | 761 } |
735 | 762 |
736 void VideoFrameQualityValidator::AddDecodeBuffer( | 763 void VideoFrameQualityValidator::AddDecodeBuffer( |
737 const scoped_refptr<DecoderBuffer>& buffer) { | 764 const scoped_refptr<DecoderBuffer>& buffer) { |
738 if (decoder_state_ != ERROR) { | 765 if (decoder_state_ != DECODER_ERROR) { |
739 decode_buffers_.push(buffer); | 766 decode_buffers_.push(buffer); |
740 Decode(); | 767 Decode(); |
741 } | 768 } |
742 } | 769 } |
743 | 770 |
744 void VideoFrameQualityValidator::Decode() { | 771 void VideoFrameQualityValidator::Decode() { |
745 if (decoder_state_ == INITIALIZED && !decode_buffers_.empty()) { | 772 if (decoder_state_ == INITIALIZED && !decode_buffers_.empty()) { |
746 scoped_refptr<DecoderBuffer> next_buffer = decode_buffers_.front(); | 773 scoped_refptr<DecoderBuffer> next_buffer = decode_buffers_.front(); |
747 decode_buffers_.pop(); | 774 decode_buffers_.pop(); |
748 decoder_state_ = DECODING; | 775 decoder_state_ = DECODING; |
(...skipping 15 matching lines...) Expand all Loading... | |
764 double difference = 0; | 791 double difference = 0; |
765 for (int plane : planes) { | 792 for (int plane : planes) { |
766 uint8_t* original_plane = original_frame->data(plane); | 793 uint8_t* original_plane = original_frame->data(plane); |
767 uint8_t* output_plane = output_frame->data(plane); | 794 uint8_t* output_plane = output_frame->data(plane); |
768 | 795 |
769 size_t rows = VideoFrame::Rows(plane, kInputFormat, visible_size.height()); | 796 size_t rows = VideoFrame::Rows(plane, kInputFormat, visible_size.height()); |
770 size_t columns = | 797 size_t columns = |
771 VideoFrame::Columns(plane, kInputFormat, visible_size.width()); | 798 VideoFrame::Columns(plane, kInputFormat, visible_size.width()); |
772 size_t stride = original_frame->stride(plane); | 799 size_t stride = original_frame->stride(plane); |
773 | 800 |
774 for (size_t i = 0; i < rows; i++) | 801 for (size_t i = 0; i < rows; i++) { |
775 for (size_t j = 0; j < columns; j++) | 802 for (size_t j = 0; j < columns; j++) { |
776 difference += std::abs(original_plane[stride * i + j] - | 803 difference += std::abs(original_plane[stride * i + j] - |
777 output_plane[stride * i + j]); | 804 output_plane[stride * i + j]); |
805 } | |
806 } | |
778 } | 807 } |
808 | |
779 // Divide the difference by the size of frame. | 809 // Divide the difference by the size of frame. |
780 difference /= VideoFrame::AllocationSize(kInputFormat, visible_size); | 810 difference /= VideoFrame::AllocationSize(kInputFormat, visible_size); |
781 EXPECT_TRUE(difference <= kDecodeSimilarityThreshold) | 811 EXPECT_TRUE(difference <= kDecodeSimilarityThreshold) |
782 << "differrence = " << difference << " > decode similarity threshold"; | 812 << "difference = " << difference << " > decode similarity threshold"; |
783 } | 813 } |
784 | 814 |
785 class VEAClient : public VideoEncodeAccelerator::Client { | 815 class VEAClient : public VideoEncodeAccelerator::Client { |
786 public: | 816 public: |
787 VEAClient(TestStream* test_stream, | 817 VEAClient(TestStream* test_stream, |
788 ClientStateNotification<ClientState>* note, | 818 ClientStateNotification<ClientState>* note, |
789 bool save_to_file, | 819 bool save_to_file, |
790 unsigned int keyframe_period, | 820 unsigned int keyframe_period, |
791 bool force_bitrate, | 821 bool force_bitrate, |
792 bool test_perf, | 822 bool test_perf, |
(...skipping 18 matching lines...) Expand all Loading... | |
811 private: | 841 private: |
812 bool has_encoder() { return encoder_.get(); } | 842 bool has_encoder() { return encoder_.get(); } |
813 | 843 |
814 // Return the number of encoded frames per second. | 844 // Return the number of encoded frames per second. |
815 double frames_per_second(); | 845 double frames_per_second(); |
816 | 846 |
817 std::unique_ptr<VideoEncodeAccelerator> CreateFakeVEA(); | 847 std::unique_ptr<VideoEncodeAccelerator> CreateFakeVEA(); |
818 std::unique_ptr<VideoEncodeAccelerator> CreateV4L2VEA(); | 848 std::unique_ptr<VideoEncodeAccelerator> CreateV4L2VEA(); |
819 std::unique_ptr<VideoEncodeAccelerator> CreateVaapiVEA(); | 849 std::unique_ptr<VideoEncodeAccelerator> CreateVaapiVEA(); |
820 std::unique_ptr<VideoEncodeAccelerator> CreateVTVEA(); | 850 std::unique_ptr<VideoEncodeAccelerator> CreateVTVEA(); |
851 std::unique_ptr<VideoEncodeAccelerator> CreateMFVEA(); | |
821 | 852 |
822 void SetState(ClientState new_state); | 853 void SetState(ClientState new_state); |
823 | 854 |
824 // Set current stream parameters to given |bitrate| at |framerate|. | 855 // Set current stream parameters to given |bitrate| at |framerate|. |
825 void SetStreamParameters(unsigned int bitrate, unsigned int framerate); | 856 void SetStreamParameters(unsigned int bitrate, unsigned int framerate); |
826 | 857 |
827 // Called when encoder is done with a VideoFrame. | 858 // Called when encoder is done with a VideoFrame. |
828 void InputNoLongerNeededCallback(int32_t input_id); | 859 void InputNoLongerNeededCallback(int32_t input_id); |
829 | 860 |
830 // Feed the encoder with one input frame. | 861 // 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. | 1074 // Fake encoder produces an invalid stream, so skip validating it. |
1044 if (!g_fake_encoder) { | 1075 if (!g_fake_encoder) { |
1045 stream_validator_ = StreamValidator::Create( | 1076 stream_validator_ = StreamValidator::Create( |
1046 test_stream_->requested_profile, | 1077 test_stream_->requested_profile, |
1047 base::Bind(&VEAClient::HandleEncodedFrame, base::Unretained(this))); | 1078 base::Bind(&VEAClient::HandleEncodedFrame, base::Unretained(this))); |
1048 CHECK(stream_validator_); | 1079 CHECK(stream_validator_); |
1049 } | 1080 } |
1050 | 1081 |
1051 if (save_to_file_) { | 1082 if (save_to_file_) { |
1052 LOG_ASSERT(!test_stream_->out_filename.empty()); | 1083 LOG_ASSERT(!test_stream_->out_filename.empty()); |
1084 #if defined(OS_POSIX) | |
1053 base::FilePath out_filename(test_stream_->out_filename); | 1085 base::FilePath out_filename(test_stream_->out_filename); |
1086 #elif defined(OS_WIN) | |
1087 base::FilePath out_filename(base::UTF8ToWide(test_stream_->out_filename)); | |
1088 #endif | |
1054 // This creates or truncates out_filename. | 1089 // This creates or truncates out_filename. |
1055 // Without it, AppendToFile() will not work. | 1090 // Without it, AppendToFile() will not work. |
1056 EXPECT_EQ(0, base::WriteFile(out_filename, NULL, 0)); | 1091 EXPECT_EQ(0, base::WriteFile(out_filename, NULL, 0)); |
1057 } | 1092 } |
1058 | 1093 |
1059 // Initialize the parameters of the test streams. | 1094 // Initialize the parameters of the test streams. |
1060 UpdateTestStreamData(mid_stream_bitrate_switch, mid_stream_framerate_switch); | 1095 UpdateTestStreamData(mid_stream_bitrate_switch, mid_stream_framerate_switch); |
1061 | 1096 |
1062 thread_checker_.DetachFromThread(); | 1097 thread_checker_.DetachFromThread(); |
1063 } | 1098 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1096 } | 1131 } |
1097 | 1132 |
1098 std::unique_ptr<VideoEncodeAccelerator> VEAClient::CreateVTVEA() { | 1133 std::unique_ptr<VideoEncodeAccelerator> VEAClient::CreateVTVEA() { |
1099 std::unique_ptr<VideoEncodeAccelerator> encoder; | 1134 std::unique_ptr<VideoEncodeAccelerator> encoder; |
1100 #if defined(OS_MACOSX) | 1135 #if defined(OS_MACOSX) |
1101 encoder.reset(new VTVideoEncodeAccelerator()); | 1136 encoder.reset(new VTVideoEncodeAccelerator()); |
1102 #endif | 1137 #endif |
1103 return encoder; | 1138 return encoder; |
1104 } | 1139 } |
1105 | 1140 |
1141 std::unique_ptr<VideoEncodeAccelerator> VEAClient::CreateMFVEA() { | |
1142 std::unique_ptr<VideoEncodeAccelerator> encoder; | |
1143 #if defined(OS_WIN) | |
1144 MediaFoundationVideoEncodeAccelerator::PreSandboxInitialization(); | |
1145 encoder.reset(new MediaFoundationVideoEncodeAccelerator()); | |
1146 #endif | |
1147 return encoder; | |
1148 } | |
1149 | |
1106 void VEAClient::CreateEncoder() { | 1150 void VEAClient::CreateEncoder() { |
1107 DCHECK(thread_checker_.CalledOnValidThread()); | 1151 DCHECK(thread_checker_.CalledOnValidThread()); |
1108 LOG_ASSERT(!has_encoder()); | 1152 LOG_ASSERT(!has_encoder()); |
1109 | 1153 |
1110 std::unique_ptr<VideoEncodeAccelerator> encoders[] = { | 1154 std::unique_ptr<VideoEncodeAccelerator> encoders[] = { |
1111 CreateFakeVEA(), CreateV4L2VEA(), CreateVaapiVEA(), CreateVTVEA()}; | 1155 CreateFakeVEA(), CreateV4L2VEA(), CreateVaapiVEA(), CreateVTVEA(), |
1156 CreateMFVEA()}; | |
1112 | 1157 |
1113 DVLOG(1) << "Profile: " << test_stream_->requested_profile | 1158 DVLOG(1) << "Profile: " << test_stream_->requested_profile |
1114 << ", initial bitrate: " << requested_bitrate_; | 1159 << ", initial bitrate: " << requested_bitrate_; |
1115 | 1160 |
1116 for (size_t i = 0; i < arraysize(encoders); ++i) { | 1161 for (size_t i = 0; i < arraysize(encoders); ++i) { |
1117 if (!encoders[i]) | 1162 if (!encoders[i]) |
1118 continue; | 1163 continue; |
1119 encoder_ = std::move(encoders[i]); | 1164 encoder_ = std::move(encoders[i]); |
1120 SetState(CS_ENCODER_SET); | 1165 SetState(CS_ENCODER_SET); |
1121 if (encoder_->Initialize(kInputFormat, test_stream_->visible_size, | 1166 if (encoder_->Initialize(kInputFormat, test_stream_->visible_size, |
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1691 for (size_t i = 0; i < num_concurrent_encoders; ++i) { | 1736 for (size_t i = 0; i < num_concurrent_encoders; ++i) { |
1692 encoder_thread.task_runner()->PostTask( | 1737 encoder_thread.task_runner()->PostTask( |
1693 FROM_HERE, | 1738 FROM_HERE, |
1694 base::Bind(&VEAClient::DestroyEncoder, base::Unretained(clients[i]))); | 1739 base::Bind(&VEAClient::DestroyEncoder, base::Unretained(clients[i]))); |
1695 } | 1740 } |
1696 | 1741 |
1697 // This ensures all tasks have finished. | 1742 // This ensures all tasks have finished. |
1698 encoder_thread.Stop(); | 1743 encoder_thread.Stop(); |
1699 } | 1744 } |
1700 | 1745 |
1701 #if !defined(OS_MACOSX) | 1746 #if defined(OS_CHROMEOS) |
1702 INSTANTIATE_TEST_CASE_P( | 1747 INSTANTIATE_TEST_CASE_P( |
1703 SimpleEncode, | 1748 SimpleEncode, |
1704 VideoEncodeAcceleratorTest, | 1749 VideoEncodeAcceleratorTest, |
1705 ::testing::Values( | 1750 ::testing::Values( |
1706 std::make_tuple(1, true, 0, false, false, false, false, false, false), | 1751 std::make_tuple(1, true, 0, false, false, false, false, false, false), |
1707 std::make_tuple(1, true, 0, false, false, false, false, true, false))); | 1752 std::make_tuple(1, true, 0, false, false, false, false, true, false))); |
1708 | 1753 |
1709 INSTANTIATE_TEST_CASE_P( | 1754 INSTANTIATE_TEST_CASE_P( |
1710 EncoderPerf, | 1755 EncoderPerf, |
1711 VideoEncodeAcceleratorTest, | 1756 VideoEncodeAcceleratorTest, |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1749 std::make_tuple(3, false, 0, false, false, false, false, false, false), | 1794 std::make_tuple(3, false, 0, false, false, false, false, false, false), |
1750 std::make_tuple(3, false, 0, true, false, false, true, false, false), | 1795 std::make_tuple(3, false, 0, true, false, false, true, false, false), |
1751 std::make_tuple(3, false, 0, true, false, true, false, false, false))); | 1796 std::make_tuple(3, false, 0, true, false, true, false, false, false))); |
1752 | 1797 |
1753 INSTANTIATE_TEST_CASE_P( | 1798 INSTANTIATE_TEST_CASE_P( |
1754 VerifyTimestamp, | 1799 VerifyTimestamp, |
1755 VideoEncodeAcceleratorTest, | 1800 VideoEncodeAcceleratorTest, |
1756 ::testing::Values( | 1801 ::testing::Values( |
1757 std::make_tuple(1, false, 0, false, false, false, false, false, true))); | 1802 std::make_tuple(1, false, 0, false, false, false, false, false, true))); |
1758 | 1803 |
1759 #else | 1804 #elif defined(OS_MACOSX) || defined(OS_WIN) |
1760 INSTANTIATE_TEST_CASE_P( | 1805 INSTANTIATE_TEST_CASE_P( |
1761 SimpleEncode, | 1806 SimpleEncode, |
1762 VideoEncodeAcceleratorTest, | 1807 VideoEncodeAcceleratorTest, |
1763 ::testing::Values( | 1808 ::testing::Values( |
1764 std::make_tuple(1, true, 0, false, false, false, false, false, false), | 1809 std::make_tuple(1, true, 0, false, false, false, false, false, false), |
1765 std::make_tuple(1, true, 0, false, false, false, false, true, false))); | 1810 std::make_tuple(1, true, 0, false, false, false, false, true, false))); |
1766 | 1811 |
1767 INSTANTIATE_TEST_CASE_P( | 1812 INSTANTIATE_TEST_CASE_P( |
1768 EncoderPerf, | 1813 EncoderPerf, |
1769 VideoEncodeAcceleratorTest, | 1814 VideoEncodeAcceleratorTest, |
1770 ::testing::Values( | 1815 ::testing::Values( |
1771 std::make_tuple(1, false, 0, false, true, false, false, false, false))); | 1816 std::make_tuple(1, false, 0, false, true, false, false, false, false))); |
1772 | 1817 |
1773 INSTANTIATE_TEST_CASE_P(MultipleEncoders, | 1818 INSTANTIATE_TEST_CASE_P(MultipleEncoders, |
1774 VideoEncodeAcceleratorTest, | 1819 VideoEncodeAcceleratorTest, |
1775 ::testing::Values(std::make_tuple(3, | 1820 ::testing::Values(std::make_tuple(3, |
1776 false, | 1821 false, |
1777 0, | 1822 0, |
1778 false, | 1823 false, |
1779 false, | 1824 false, |
1780 false, | 1825 false, |
1781 false, | 1826 false, |
1782 false, | 1827 false, |
1783 false))); | 1828 false))); |
1784 #endif | 1829 #if defined(OS_WIN) |
1830 INSTANTIATE_TEST_CASE_P( | |
1831 ForceBitrate, | |
1832 VideoEncodeAcceleratorTest, | |
1833 ::testing::Values( | |
1834 std::make_tuple(1, false, 0, true, false, false, false, false, false))); | |
1835 #endif // defined(OS_WIN) | |
1836 | |
1837 #endif // defined(OS_CHROMEOS) | |
1785 | 1838 |
1786 // TODO(posciak): more tests: | 1839 // TODO(posciak): more tests: |
1787 // - async FeedEncoderWithOutput | 1840 // - async FeedEncoderWithOutput |
1788 // - out-of-order return of outputs to encoder | 1841 // - out-of-order return of outputs to encoder |
1789 // - multiple encoders + decoders | 1842 // - multiple encoders + decoders |
1790 // - mid-stream encoder_->Destroy() | 1843 // - mid-stream encoder_->Destroy() |
1791 | 1844 |
1792 } // namespace | 1845 } // namespace |
1793 } // namespace media | 1846 } // namespace media |
1794 | 1847 |
1795 int main(int argc, char** argv) { | 1848 int main(int argc, char** argv) { |
1796 testing::InitGoogleTest(&argc, argv); // Removes gtest-specific args. | 1849 testing::InitGoogleTest(&argc, argv); // Removes gtest-specific args. |
1797 base::CommandLine::Init(argc, argv); | 1850 base::CommandLine::Init(argc, argv); |
1798 | 1851 |
1799 base::ShadowingAtExitManager at_exit_manager; | 1852 base::ShadowingAtExitManager at_exit_manager; |
1800 base::MessageLoop main_loop; | 1853 base::MessageLoop main_loop; |
1801 | 1854 |
1802 std::unique_ptr<base::FilePath::StringType> test_stream_data( | 1855 std::unique_ptr<base::FilePath::StringType> test_stream_data( |
1803 new base::FilePath::StringType( | 1856 new base::FilePath::StringType( |
1804 media::GetTestDataFilePath(media::g_default_in_filename).value() + | 1857 media::GetTestDataFilePath(media::g_default_in_filename).value())); |
1805 media::g_default_in_parameters)); | 1858 test_stream_data->append(media::g_default_in_parameters); |
1806 | 1859 |
1807 // Needed to enable DVLOG through --vmodule. | 1860 // Needed to enable DVLOG through --vmodule. |
1808 logging::LoggingSettings settings; | 1861 logging::LoggingSettings settings; |
1809 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; | 1862 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; |
1810 LOG_ASSERT(logging::InitLogging(settings)); | 1863 LOG_ASSERT(logging::InitLogging(settings)); |
1811 | 1864 |
1812 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); | 1865 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); |
1813 DCHECK(cmd_line); | 1866 DCHECK(cmd_line); |
1814 | 1867 |
1815 bool run_at_fps = false; | 1868 bool run_at_fps = false; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1871 | 1924 |
1872 media::g_env = | 1925 media::g_env = |
1873 reinterpret_cast<media::VideoEncodeAcceleratorTestEnvironment*>( | 1926 reinterpret_cast<media::VideoEncodeAcceleratorTestEnvironment*>( |
1874 testing::AddGlobalTestEnvironment( | 1927 testing::AddGlobalTestEnvironment( |
1875 new media::VideoEncodeAcceleratorTestEnvironment( | 1928 new media::VideoEncodeAcceleratorTestEnvironment( |
1876 std::move(test_stream_data), log_path, run_at_fps, | 1929 std::move(test_stream_data), log_path, run_at_fps, |
1877 needs_encode_latency, verify_all_output))); | 1930 needs_encode_latency, verify_all_output))); |
1878 | 1931 |
1879 return RUN_ALL_TESTS(); | 1932 return RUN_ALL_TESTS(); |
1880 } | 1933 } |
OLD | NEW |