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

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

Issue 2058413003: H264 HW encode using MediaFoundation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: wuchengli@ and ananta@ comments. Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <inttypes.h> 5 #include <inttypes.h>
6 #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
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
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
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
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 = src_file_size / visible_buffer_size;
303 330
(...skipping 17 matching lines...) Expand all
321 visible_bpl[i]); 348 visible_bpl[i]);
322 src_ptr += visible_bpl[i]; 349 src_ptr += visible_bpl[i];
323 dest_offset += coded_bpl[i]; 350 dest_offset += coded_bpl[i];
324 } 351 }
325 dest_offset += padding_sizes[i]; 352 dest_offset += padding_sizes[i];
326 } 353 }
327 src_offset += visible_buffer_size; 354 src_offset += visible_buffer_size;
328 } 355 }
329 src.Close(); 356 src.Close();
330 357
358 #if defined(OS_POSIX)
331 // Assert that memory mapped of file starts at 64 byte boundary. So each 359 // Assert that memory mapped of file starts at 64 byte boundary. So each
332 // plane of frames also start at 64 byte boundary. 360 // plane of frames also start at 64 byte boundary.
333 ASSERT_EQ(reinterpret_cast<off_t>(&test_stream->aligned_in_file_data[0]) & 63, 361 ASSERT_EQ(reinterpret_cast<off_t>(&test_stream->aligned_in_file_data[0]) & 63,
334 0) 362 0)
335 << "File should be mapped at a 64 byte boundary"; 363 << "File should be mapped at a 64 byte boundary";
364 #endif // defined(OS_POSIX)
336 365
337 LOG_ASSERT(test_stream->num_frames > 0UL); 366 LOG_ASSERT(test_stream->num_frames > 0UL);
338 } 367 }
339 368
340 // Parse |data| into its constituent parts, set the various output fields 369 // Parse |data| into its constituent parts, set the various output fields
341 // accordingly, read in video stream, and store them to |test_streams|. 370 // accordingly, read in video stream, and store them to |test_streams|.
342 static void ParseAndReadTestStreamData(const base::FilePath::StringType& data, 371 static void ParseAndReadTestStreamData(const base::FilePath::StringType& data,
343 ScopedVector<TestStream>* test_streams) { 372 ScopedVector<TestStream>* test_streams) {
344 // Split the string to individual test stream data. 373 // Split the string to individual test stream data.
345 std::vector<base::FilePath::StringType> test_streams_data = 374 std::vector<base::FilePath::StringType> test_streams_data =
346 base::SplitString(data, base::FilePath::StringType(1, ';'), 375 base::SplitString(data, base::FilePath::StringType(1, ';'),
347 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); 376 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
348 LOG_ASSERT(test_streams_data.size() >= 1U) << data; 377 LOG_ASSERT(test_streams_data.size() >= 1U) << data;
349 378
350 // Parse each test stream data and read the input file. 379 // Parse each test stream data and read the input file.
351 for (size_t index = 0; index < test_streams_data.size(); ++index) { 380 for (size_t index = 0; index < test_streams_data.size(); ++index) {
352 std::vector<base::FilePath::StringType> fields = base::SplitString( 381 std::vector<base::FilePath::StringType> fields = base::SplitString(
353 test_streams_data[index], base::FilePath::StringType(1, ':'), 382 test_streams_data[index], base::FilePath::StringType(1, ','),
354 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); 383 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
384 // Try using ":" as the seperator if "," isn't used.
385 if (fields.size() == 1U) {
386 fields = base::SplitString(test_streams_data[index],
387 base::FilePath::StringType(1, ':'),
388 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
389 }
355 LOG_ASSERT(fields.size() >= 4U) << data; 390 LOG_ASSERT(fields.size() >= 4U) << data;
356 LOG_ASSERT(fields.size() <= 9U) << data; 391 LOG_ASSERT(fields.size() <= 9U) << data;
357 TestStream* test_stream = new TestStream(); 392 TestStream* test_stream = new TestStream();
358 393
359 test_stream->in_filename = fields[0]; 394 test_stream->in_filename = FilePathStringTypeToString(fields[0]);
360 int width, height; 395 int width, height;
361 bool result = base::StringToInt(fields[1], &width); 396 bool result = base::StringToInt(fields[1], &width);
362 LOG_ASSERT(result); 397 LOG_ASSERT(result);
363 result = base::StringToInt(fields[2], &height); 398 result = base::StringToInt(fields[2], &height);
364 LOG_ASSERT(result); 399 LOG_ASSERT(result);
365 test_stream->visible_size = gfx::Size(width, height); 400 test_stream->visible_size = gfx::Size(width, height);
366 LOG_ASSERT(!test_stream->visible_size.IsEmpty()); 401 LOG_ASSERT(!test_stream->visible_size.IsEmpty());
367 int profile; 402 int profile;
368 result = base::StringToInt(fields[3], &profile); 403 result = base::StringToInt(fields[3], &profile);
369 LOG_ASSERT(result); 404 LOG_ASSERT(result);
370 LOG_ASSERT(profile > VIDEO_CODEC_PROFILE_UNKNOWN); 405 LOG_ASSERT(profile > VIDEO_CODEC_PROFILE_UNKNOWN);
371 LOG_ASSERT(profile <= VIDEO_CODEC_PROFILE_MAX); 406 LOG_ASSERT(profile <= VIDEO_CODEC_PROFILE_MAX);
372 test_stream->requested_profile = static_cast<VideoCodecProfile>(profile); 407 test_stream->requested_profile = static_cast<VideoCodecProfile>(profile);
373 408
374 if (fields.size() >= 5 && !fields[4].empty()) 409 if (fields.size() >= 5 && !fields[4].empty())
375 test_stream->out_filename = fields[4]; 410 test_stream->out_filename = FilePathStringTypeToString(fields[4]);
376 411
377 if (fields.size() >= 6 && !fields[5].empty()) 412 if (fields.size() >= 6 && !fields[5].empty())
378 LOG_ASSERT( 413 LOG_ASSERT(
379 base::StringToUint(fields[5], &test_stream->requested_bitrate)); 414 base::StringToUint(fields[5], &test_stream->requested_bitrate));
380 415
381 if (fields.size() >= 7 && !fields[6].empty()) 416 if (fields.size() >= 7 && !fields[6].empty())
382 LOG_ASSERT( 417 LOG_ASSERT(
383 base::StringToUint(fields[6], &test_stream->requested_framerate)); 418 base::StringToUint(fields[6], &test_stream->requested_framerate));
384 419
385 if (fields.size() >= 8 && !fields[7].empty()) { 420 if (fields.size() >= 8 && !fields[7].empty()) {
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
628 // Flush the decoder. 663 // Flush the decoder.
629 void Flush(); 664 void Flush();
630 665
631 private: 666 private:
632 void InitializeCB(bool success); 667 void InitializeCB(bool success);
633 void DecodeDone(DecodeStatus status); 668 void DecodeDone(DecodeStatus status);
634 void FlushDone(DecodeStatus status); 669 void FlushDone(DecodeStatus status);
635 void VerifyOutputFrame(const scoped_refptr<VideoFrame>& output_frame); 670 void VerifyOutputFrame(const scoped_refptr<VideoFrame>& output_frame);
636 void Decode(); 671 void Decode();
637 672
638 enum State { UNINITIALIZED, INITIALIZED, DECODING, ERROR }; 673 enum State { UNINITIALIZED, INITIALIZED, DECODING, DECODER_ERROR };
639 674
640 const VideoCodecProfile profile_; 675 const VideoCodecProfile profile_;
641 std::unique_ptr<FFmpegVideoDecoder> decoder_; 676 std::unique_ptr<FFmpegVideoDecoder> decoder_;
642 VideoDecoder::DecodeCB decode_cb_; 677 VideoDecoder::DecodeCB decode_cb_;
643 // Decode callback of an EOS buffer. 678 // Decode callback of an EOS buffer.
644 VideoDecoder::DecodeCB eos_decode_cb_; 679 VideoDecoder::DecodeCB eos_decode_cb_;
645 // Callback of Flush(). Called after all frames are decoded. 680 // Callback of Flush(). Called after all frames are decoded.
646 const base::Closure flush_complete_cb_; 681 const base::Closure flush_complete_cb_;
647 const base::Closure decode_error_cb_; 682 const base::Closure decode_error_cb_;
648 State decoder_state_; 683 State decoder_state_;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
691 base::Unretained(this)), 726 base::Unretained(this)),
692 base::Bind(&VideoFrameQualityValidator::VerifyOutputFrame, 727 base::Bind(&VideoFrameQualityValidator::VerifyOutputFrame,
693 base::Unretained(this))); 728 base::Unretained(this)));
694 } 729 }
695 730
696 void VideoFrameQualityValidator::InitializeCB(bool success) { 731 void VideoFrameQualityValidator::InitializeCB(bool success) {
697 if (success) { 732 if (success) {
698 decoder_state_ = INITIALIZED; 733 decoder_state_ = INITIALIZED;
699 Decode(); 734 Decode();
700 } else { 735 } else {
701 decoder_state_ = ERROR; 736 decoder_state_ = DECODER_ERROR;
702 if (IsH264(profile_)) 737 if (IsH264(profile_))
703 LOG(ERROR) << "Chromium does not support H264 decode. Try Chrome."; 738 LOG(ERROR) << "Chromium does not support H264 decode. Try Chrome.";
704 FAIL() << "Decoder initialization error"; 739 FAIL() << "Decoder initialization error";
705 decode_error_cb_.Run(); 740 decode_error_cb_.Run();
706 } 741 }
707 } 742 }
708 743
709 void VideoFrameQualityValidator::AddOriginalFrame( 744 void VideoFrameQualityValidator::AddOriginalFrame(
710 scoped_refptr<VideoFrame> frame) { 745 scoped_refptr<VideoFrame> frame) {
711 original_frames_.push(frame); 746 original_frames_.push(frame);
712 } 747 }
713 748
714 void VideoFrameQualityValidator::DecodeDone(DecodeStatus status) { 749 void VideoFrameQualityValidator::DecodeDone(DecodeStatus status) {
715 if (status == DecodeStatus::OK) { 750 if (status == DecodeStatus::OK) {
716 decoder_state_ = INITIALIZED; 751 decoder_state_ = INITIALIZED;
717 Decode(); 752 Decode();
718 } else { 753 } else {
719 decoder_state_ = ERROR; 754 decoder_state_ = DECODER_ERROR;
720 FAIL() << "Unexpected decode status = " << status << ". Stop decoding."; 755 FAIL() << "Unexpected decode status = " << status << ". Stop decoding.";
721 decode_error_cb_.Run(); 756 decode_error_cb_.Run();
722 } 757 }
723 } 758 }
724 759
725 void VideoFrameQualityValidator::FlushDone(DecodeStatus status) { 760 void VideoFrameQualityValidator::FlushDone(DecodeStatus status) {
726 flush_complete_cb_.Run(); 761 flush_complete_cb_.Run();
727 } 762 }
728 763
729 void VideoFrameQualityValidator::Flush() { 764 void VideoFrameQualityValidator::Flush() {
730 if (decoder_state_ != ERROR) { 765 if (decoder_state_ != DECODER_ERROR) {
731 decode_buffers_.push(DecoderBuffer::CreateEOSBuffer()); 766 decode_buffers_.push(DecoderBuffer::CreateEOSBuffer());
732 Decode(); 767 Decode();
733 } 768 }
734 } 769 }
735 770
736 void VideoFrameQualityValidator::AddDecodeBuffer( 771 void VideoFrameQualityValidator::AddDecodeBuffer(
737 const scoped_refptr<DecoderBuffer>& buffer) { 772 const scoped_refptr<DecoderBuffer>& buffer) {
738 if (decoder_state_ != ERROR) { 773 if (decoder_state_ != DECODER_ERROR) {
739 decode_buffers_.push(buffer); 774 decode_buffers_.push(buffer);
740 Decode(); 775 Decode();
741 } 776 }
742 } 777 }
743 778
744 void VideoFrameQualityValidator::Decode() { 779 void VideoFrameQualityValidator::Decode() {
745 if (decoder_state_ == INITIALIZED && !decode_buffers_.empty()) { 780 if (decoder_state_ == INITIALIZED && !decode_buffers_.empty()) {
746 scoped_refptr<DecoderBuffer> next_buffer = decode_buffers_.front(); 781 scoped_refptr<DecoderBuffer> next_buffer = decode_buffers_.front();
747 decode_buffers_.pop(); 782 decode_buffers_.pop();
748 decoder_state_ = DECODING; 783 decoder_state_ = DECODING;
(...skipping 15 matching lines...) Expand all
764 double difference = 0; 799 double difference = 0;
765 for (int plane : planes) { 800 for (int plane : planes) {
766 uint8_t* original_plane = original_frame->data(plane); 801 uint8_t* original_plane = original_frame->data(plane);
767 uint8_t* output_plane = output_frame->data(plane); 802 uint8_t* output_plane = output_frame->data(plane);
768 803
769 size_t rows = VideoFrame::Rows(plane, kInputFormat, visible_size.height()); 804 size_t rows = VideoFrame::Rows(plane, kInputFormat, visible_size.height());
770 size_t columns = 805 size_t columns =
771 VideoFrame::Columns(plane, kInputFormat, visible_size.width()); 806 VideoFrame::Columns(plane, kInputFormat, visible_size.width());
772 size_t stride = original_frame->stride(plane); 807 size_t stride = original_frame->stride(plane);
773 808
774 for (size_t i = 0; i < rows; i++) 809 for (size_t i = 0; i < rows; i++) {
775 for (size_t j = 0; j < columns; j++) 810 for (size_t j = 0; j < columns; j++) {
776 difference += std::abs(original_plane[stride * i + j] - 811 difference += std::abs(original_plane[stride * i + j] -
777 output_plane[stride * i + j]); 812 output_plane[stride * i + j]);
813 }
814 }
778 } 815 }
816
779 // Divide the difference by the size of frame. 817 // Divide the difference by the size of frame.
780 difference /= VideoFrame::AllocationSize(kInputFormat, visible_size); 818 difference /= VideoFrame::AllocationSize(kInputFormat, visible_size);
781 EXPECT_TRUE(difference <= kDecodeSimilarityThreshold) 819 EXPECT_TRUE(difference <= kDecodeSimilarityThreshold)
782 << "differrence = " << difference << " > decode similarity threshold"; 820 << "difference = " << difference << " > decode similarity threshold";
783 } 821 }
784 822
785 class VEAClient : public VideoEncodeAccelerator::Client { 823 class VEAClient : public VideoEncodeAccelerator::Client {
786 public: 824 public:
787 VEAClient(TestStream* test_stream, 825 VEAClient(TestStream* test_stream,
788 ClientStateNotification<ClientState>* note, 826 ClientStateNotification<ClientState>* note,
789 bool save_to_file, 827 bool save_to_file,
790 unsigned int keyframe_period, 828 unsigned int keyframe_period,
791 bool force_bitrate, 829 bool force_bitrate,
792 bool test_perf, 830 bool test_perf,
(...skipping 18 matching lines...) Expand all
811 private: 849 private:
812 bool has_encoder() { return encoder_.get(); } 850 bool has_encoder() { return encoder_.get(); }
813 851
814 // Return the number of encoded frames per second. 852 // Return the number of encoded frames per second.
815 double frames_per_second(); 853 double frames_per_second();
816 854
817 std::unique_ptr<VideoEncodeAccelerator> CreateFakeVEA(); 855 std::unique_ptr<VideoEncodeAccelerator> CreateFakeVEA();
818 std::unique_ptr<VideoEncodeAccelerator> CreateV4L2VEA(); 856 std::unique_ptr<VideoEncodeAccelerator> CreateV4L2VEA();
819 std::unique_ptr<VideoEncodeAccelerator> CreateVaapiVEA(); 857 std::unique_ptr<VideoEncodeAccelerator> CreateVaapiVEA();
820 std::unique_ptr<VideoEncodeAccelerator> CreateVTVEA(); 858 std::unique_ptr<VideoEncodeAccelerator> CreateVTVEA();
859 std::unique_ptr<VideoEncodeAccelerator> CreateMFVEA();
821 860
822 void SetState(ClientState new_state); 861 void SetState(ClientState new_state);
823 862
824 // Set current stream parameters to given |bitrate| at |framerate|. 863 // Set current stream parameters to given |bitrate| at |framerate|.
825 void SetStreamParameters(unsigned int bitrate, unsigned int framerate); 864 void SetStreamParameters(unsigned int bitrate, unsigned int framerate);
826 865
827 // Called when encoder is done with a VideoFrame. 866 // Called when encoder is done with a VideoFrame.
828 void InputNoLongerNeededCallback(int32_t input_id); 867 void InputNoLongerNeededCallback(int32_t input_id);
829 868
830 // Feed the encoder with one input frame. 869 // Feed the encoder with one input frame.
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
1043 // Fake encoder produces an invalid stream, so skip validating it. 1082 // Fake encoder produces an invalid stream, so skip validating it.
1044 if (!g_fake_encoder) { 1083 if (!g_fake_encoder) {
1045 stream_validator_ = StreamValidator::Create( 1084 stream_validator_ = StreamValidator::Create(
1046 test_stream_->requested_profile, 1085 test_stream_->requested_profile,
1047 base::Bind(&VEAClient::HandleEncodedFrame, base::Unretained(this))); 1086 base::Bind(&VEAClient::HandleEncodedFrame, base::Unretained(this)));
1048 CHECK(stream_validator_); 1087 CHECK(stream_validator_);
1049 } 1088 }
1050 1089
1051 if (save_to_file_) { 1090 if (save_to_file_) {
1052 LOG_ASSERT(!test_stream_->out_filename.empty()); 1091 LOG_ASSERT(!test_stream_->out_filename.empty());
1092 #if defined(OS_POSIX)
1053 base::FilePath out_filename(test_stream_->out_filename); 1093 base::FilePath out_filename(test_stream_->out_filename);
1094 #elif defined(OS_WIN)
1095 base::FilePath out_filename(base::UTF8ToWide(test_stream_->out_filename));
1096 #endif
1054 // This creates or truncates out_filename. 1097 // This creates or truncates out_filename.
1055 // Without it, AppendToFile() will not work. 1098 // Without it, AppendToFile() will not work.
1056 EXPECT_EQ(0, base::WriteFile(out_filename, NULL, 0)); 1099 EXPECT_EQ(0, base::WriteFile(out_filename, NULL, 0));
1057 } 1100 }
1058 1101
1059 // Initialize the parameters of the test streams. 1102 // Initialize the parameters of the test streams.
1060 UpdateTestStreamData(mid_stream_bitrate_switch, mid_stream_framerate_switch); 1103 UpdateTestStreamData(mid_stream_bitrate_switch, mid_stream_framerate_switch);
1061 1104
1062 thread_checker_.DetachFromThread(); 1105 thread_checker_.DetachFromThread();
1063 } 1106 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1096 } 1139 }
1097 1140
1098 std::unique_ptr<VideoEncodeAccelerator> VEAClient::CreateVTVEA() { 1141 std::unique_ptr<VideoEncodeAccelerator> VEAClient::CreateVTVEA() {
1099 std::unique_ptr<VideoEncodeAccelerator> encoder; 1142 std::unique_ptr<VideoEncodeAccelerator> encoder;
1100 #if defined(OS_MACOSX) 1143 #if defined(OS_MACOSX)
1101 encoder.reset(new VTVideoEncodeAccelerator()); 1144 encoder.reset(new VTVideoEncodeAccelerator());
1102 #endif 1145 #endif
1103 return encoder; 1146 return encoder;
1104 } 1147 }
1105 1148
1149 std::unique_ptr<VideoEncodeAccelerator> VEAClient::CreateMFVEA() {
1150 std::unique_ptr<VideoEncodeAccelerator> encoder;
1151 #if defined(OS_WIN)
1152 MediaFoundationVideoEncodeAccelerator::PreSandboxInitialization();
1153 encoder.reset(new MediaFoundationVideoEncodeAccelerator());
1154 #endif
1155 return encoder;
1156 }
1157
1106 void VEAClient::CreateEncoder() { 1158 void VEAClient::CreateEncoder() {
1107 DCHECK(thread_checker_.CalledOnValidThread()); 1159 DCHECK(thread_checker_.CalledOnValidThread());
1108 LOG_ASSERT(!has_encoder()); 1160 LOG_ASSERT(!has_encoder());
1109 1161
1110 std::unique_ptr<VideoEncodeAccelerator> encoders[] = { 1162 std::unique_ptr<VideoEncodeAccelerator> encoders[] = {
1111 CreateFakeVEA(), CreateV4L2VEA(), CreateVaapiVEA(), CreateVTVEA()}; 1163 CreateFakeVEA(), CreateV4L2VEA(), CreateVaapiVEA(), CreateVTVEA(),
1164 CreateMFVEA()};
1112 1165
1113 DVLOG(1) << "Profile: " << test_stream_->requested_profile 1166 DVLOG(1) << "Profile: " << test_stream_->requested_profile
1114 << ", initial bitrate: " << requested_bitrate_; 1167 << ", initial bitrate: " << requested_bitrate_;
1115 1168
1116 for (size_t i = 0; i < arraysize(encoders); ++i) { 1169 for (size_t i = 0; i < arraysize(encoders); ++i) {
1117 if (!encoders[i]) 1170 if (!encoders[i])
1118 continue; 1171 continue;
1119 encoder_ = std::move(encoders[i]); 1172 encoder_ = std::move(encoders[i]);
1120 SetState(CS_ENCODER_SET); 1173 SetState(CS_ENCODER_SET);
1121 if (encoder_->Initialize(kInputFormat, test_stream_->visible_size, 1174 if (encoder_->Initialize(kInputFormat, test_stream_->visible_size,
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after
1691 for (size_t i = 0; i < num_concurrent_encoders; ++i) { 1744 for (size_t i = 0; i < num_concurrent_encoders; ++i) {
1692 encoder_thread.task_runner()->PostTask( 1745 encoder_thread.task_runner()->PostTask(
1693 FROM_HERE, 1746 FROM_HERE,
1694 base::Bind(&VEAClient::DestroyEncoder, base::Unretained(clients[i]))); 1747 base::Bind(&VEAClient::DestroyEncoder, base::Unretained(clients[i])));
1695 } 1748 }
1696 1749
1697 // This ensures all tasks have finished. 1750 // This ensures all tasks have finished.
1698 encoder_thread.Stop(); 1751 encoder_thread.Stop();
1699 } 1752 }
1700 1753
1701 #if !defined(OS_MACOSX) 1754 #if defined(OS_CHROMEOS)
1702 INSTANTIATE_TEST_CASE_P( 1755 INSTANTIATE_TEST_CASE_P(
1703 SimpleEncode, 1756 SimpleEncode,
1704 VideoEncodeAcceleratorTest, 1757 VideoEncodeAcceleratorTest,
1705 ::testing::Values( 1758 ::testing::Values(
1706 std::make_tuple(1, true, 0, false, false, false, false, false, false), 1759 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))); 1760 std::make_tuple(1, true, 0, false, false, false, false, true, false)));
1708 1761
1709 INSTANTIATE_TEST_CASE_P( 1762 INSTANTIATE_TEST_CASE_P(
1710 EncoderPerf, 1763 EncoderPerf,
1711 VideoEncodeAcceleratorTest, 1764 VideoEncodeAcceleratorTest,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1749 std::make_tuple(3, false, 0, false, false, false, false, false, false), 1802 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), 1803 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))); 1804 std::make_tuple(3, false, 0, true, false, true, false, false, false)));
1752 1805
1753 INSTANTIATE_TEST_CASE_P( 1806 INSTANTIATE_TEST_CASE_P(
1754 VerifyTimestamp, 1807 VerifyTimestamp,
1755 VideoEncodeAcceleratorTest, 1808 VideoEncodeAcceleratorTest,
1756 ::testing::Values( 1809 ::testing::Values(
1757 std::make_tuple(1, false, 0, false, false, false, false, false, true))); 1810 std::make_tuple(1, false, 0, false, false, false, false, false, true)));
1758 1811
1759 #else 1812 #elif defined(OS_MACOSX) || defined(OS_WIN)
1760 INSTANTIATE_TEST_CASE_P( 1813 INSTANTIATE_TEST_CASE_P(
1761 SimpleEncode, 1814 SimpleEncode,
1762 VideoEncodeAcceleratorTest, 1815 VideoEncodeAcceleratorTest,
1763 ::testing::Values( 1816 ::testing::Values(
1764 std::make_tuple(1, true, 0, false, false, false, false, false, false), 1817 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))); 1818 std::make_tuple(1, true, 0, false, false, false, false, true, false)));
1766 1819
1767 INSTANTIATE_TEST_CASE_P( 1820 INSTANTIATE_TEST_CASE_P(
1768 EncoderPerf, 1821 EncoderPerf,
1769 VideoEncodeAcceleratorTest, 1822 VideoEncodeAcceleratorTest,
1770 ::testing::Values( 1823 ::testing::Values(
1771 std::make_tuple(1, false, 0, false, true, false, false, false, false))); 1824 std::make_tuple(1, false, 0, false, true, false, false, false, false)));
1772 1825
1773 INSTANTIATE_TEST_CASE_P(MultipleEncoders, 1826 INSTANTIATE_TEST_CASE_P(MultipleEncoders,
1774 VideoEncodeAcceleratorTest, 1827 VideoEncodeAcceleratorTest,
1775 ::testing::Values(std::make_tuple(3, 1828 ::testing::Values(std::make_tuple(3,
1776 false, 1829 false,
1777 0, 1830 0,
1778 false, 1831 false,
1779 false, 1832 false,
1780 false, 1833 false,
1781 false, 1834 false,
1782 false, 1835 false,
1783 false))); 1836 false)));
1784 #endif 1837 #if defined(OS_WIN)
1838 INSTANTIATE_TEST_CASE_P(
1839 ForceBitrate,
1840 VideoEncodeAcceleratorTest,
1841 ::testing::Values(
1842 std::make_tuple(1, false, 0, true, false, false, false, false, false)));
1843 #endif // defined(OS_WIN)
1844
1845 #endif // defined(OS_CHROMEOS)
1785 1846
1786 // TODO(posciak): more tests: 1847 // TODO(posciak): more tests:
1787 // - async FeedEncoderWithOutput 1848 // - async FeedEncoderWithOutput
1788 // - out-of-order return of outputs to encoder 1849 // - out-of-order return of outputs to encoder
1789 // - multiple encoders + decoders 1850 // - multiple encoders + decoders
1790 // - mid-stream encoder_->Destroy() 1851 // - mid-stream encoder_->Destroy()
1791 1852
1792 } // namespace 1853 } // namespace
1793 } // namespace media 1854 } // namespace media
1794 1855
1795 int main(int argc, char** argv) { 1856 int main(int argc, char** argv) {
1796 testing::InitGoogleTest(&argc, argv); // Removes gtest-specific args. 1857 testing::InitGoogleTest(&argc, argv); // Removes gtest-specific args.
1797 base::CommandLine::Init(argc, argv); 1858 base::CommandLine::Init(argc, argv);
1798 1859
1799 base::ShadowingAtExitManager at_exit_manager; 1860 base::ShadowingAtExitManager at_exit_manager;
1800 base::MessageLoop main_loop; 1861 base::MessageLoop main_loop;
1801 1862
1802 std::unique_ptr<base::FilePath::StringType> test_stream_data( 1863 std::unique_ptr<base::FilePath::StringType> test_stream_data(
1803 new base::FilePath::StringType( 1864 new base::FilePath::StringType(
1804 media::GetTestDataFilePath(media::g_default_in_filename).value() + 1865 media::GetTestDataFilePath(media::g_default_in_filename).value()));
1805 media::g_default_in_parameters)); 1866 test_stream_data->append(media::g_default_in_parameters);
1806 1867
1807 // Needed to enable DVLOG through --vmodule. 1868 // Needed to enable DVLOG through --vmodule.
1808 logging::LoggingSettings settings; 1869 logging::LoggingSettings settings;
1809 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; 1870 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
1810 LOG_ASSERT(logging::InitLogging(settings)); 1871 LOG_ASSERT(logging::InitLogging(settings));
1811 1872
1812 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); 1873 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess();
1813 DCHECK(cmd_line); 1874 DCHECK(cmd_line);
1814 1875
1815 bool run_at_fps = false; 1876 bool run_at_fps = false;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1871 1932
1872 media::g_env = 1933 media::g_env =
1873 reinterpret_cast<media::VideoEncodeAcceleratorTestEnvironment*>( 1934 reinterpret_cast<media::VideoEncodeAcceleratorTestEnvironment*>(
1874 testing::AddGlobalTestEnvironment( 1935 testing::AddGlobalTestEnvironment(
1875 new media::VideoEncodeAcceleratorTestEnvironment( 1936 new media::VideoEncodeAcceleratorTestEnvironment(
1876 std::move(test_stream_data), log_path, run_at_fps, 1937 std::move(test_stream_data), log_path, run_at_fps,
1877 needs_encode_latency, verify_all_output))); 1938 needs_encode_latency, verify_all_output)));
1878 1939
1879 return RUN_ALL_TESTS(); 1940 return RUN_ALL_TESTS();
1880 } 1941 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698