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

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

Powered by Google App Engine
This is Rietveld 408576698