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

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

Issue 2172703002: Revert of H264 HW encode using MediaFoundation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
« no previous file with comments | « media/gpu/media_foundation_video_encode_accelerator_win.cc ('k') | media/media.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <inttypes.h> 5 #include <inttypes.h>
6 #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"
31 #include "base/threading/thread.h" 30 #include "base/threading/thread.h"
32 #include "base/threading/thread_checker.h" 31 #include "base/threading/thread_checker.h"
33 #include "base/time/time.h" 32 #include "base/time/time.h"
34 #include "base/timer/timer.h" 33 #include "base/timer/timer.h"
35 #include "build/build_config.h" 34 #include "build/build_config.h"
36 #include "media/base/bind_to_current_loop.h" 35 #include "media/base/bind_to_current_loop.h"
37 #include "media/base/bitstream_buffer.h" 36 #include "media/base/bitstream_buffer.h"
38 #include "media/base/cdm_context.h" 37 #include "media/base/cdm_context.h"
39 #include "media/base/decoder_buffer.h" 38 #include "media/base/decoder_buffer.h"
40 #include "media/base/media_util.h" 39 #include "media/base/media_util.h"
(...skipping 14 matching lines...) Expand all
55 #include "media/gpu/v4l2_video_encode_accelerator.h" 54 #include "media/gpu/v4l2_video_encode_accelerator.h"
56 #endif 55 #endif
57 #if defined(ARCH_CPU_X86_FAMILY) 56 #if defined(ARCH_CPU_X86_FAMILY)
58 #include "media/gpu/vaapi_video_encode_accelerator.h" 57 #include "media/gpu/vaapi_video_encode_accelerator.h"
59 #include "media/gpu/vaapi_wrapper.h" 58 #include "media/gpu/vaapi_wrapper.h"
60 // Status has been defined as int in Xlib.h. 59 // Status has been defined as int in Xlib.h.
61 #undef Status 60 #undef Status
62 #endif // defined(ARCH_CPU_X86_FAMILY) 61 #endif // defined(ARCH_CPU_X86_FAMILY)
63 #elif defined(OS_MACOSX) 62 #elif defined(OS_MACOSX)
64 #include "media/gpu/vt_video_encode_accelerator_mac.h" 63 #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"
67 #else 64 #else
68 #error The VideoEncodeAcceleratorUnittest is not supported on this platform. 65 #error The VideoEncodeAcceleratorUnittest is not supported on this platform.
69 #endif 66 #endif
70 67
71 namespace media { 68 namespace media {
72 namespace { 69 namespace {
73 70
74 const VideoPixelFormat kInputFormat = PIXEL_FORMAT_I420; 71 const VideoPixelFormat kInputFormat = PIXEL_FORMAT_I420;
75 72
76 // The absolute differences between original frame and decoded frame usually 73 // The absolute differences between original frame and decoded frame usually
(...skipping 29 matching lines...) Expand all
106 const unsigned int kMinFramesForBitrateTests = 300; 103 const unsigned int kMinFramesForBitrateTests = 300;
107 // The percentiles to measure for encode latency. 104 // The percentiles to measure for encode latency.
108 const unsigned int kLoggedLatencyPercentiles[] = {50, 75, 95}; 105 const unsigned int kLoggedLatencyPercentiles[] = {50, 75, 95};
109 106
110 // The syntax of multiple test streams is: 107 // The syntax of multiple test streams is:
111 // test-stream1;test-stream2;test-stream3 108 // test-stream1;test-stream2;test-stream3
112 // The syntax of each test stream is: 109 // The syntax of each test stream is:
113 // "in_filename:width:height:profile:out_filename:requested_bitrate 110 // "in_filename:width:height:profile:out_filename:requested_bitrate
114 // :requested_framerate:requested_subsequent_bitrate 111 // :requested_framerate:requested_subsequent_bitrate
115 // :requested_subsequent_framerate" 112 // :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.
118 // - |in_filename| must be an I420 (YUV planar) raw stream 113 // - |in_filename| must be an I420 (YUV planar) raw stream
119 // (see http://www.fourcc.org/yuv.php#IYUV). 114 // (see http://www.fourcc.org/yuv.php#IYUV).
120 // - |width| and |height| are in pixels. 115 // - |width| and |height| are in pixels.
121 // - |profile| to encode into (values of VideoCodecProfile). 116 // - |profile| to encode into (values of VideoCodecProfile).
122 // - |out_filename| filename to save the encoded stream to (optional). The 117 // - |out_filename| filename to save the encoded stream to (optional). The
123 // format for H264 is Annex-B byte stream. The format for VP8 is IVF. Output 118 // format for H264 is Annex-B byte stream. The format for VP8 is IVF. Output
124 // stream is saved for the simple encode test only. H264 raw stream and IVF 119 // stream is saved for the simple encode test only. H264 raw stream and IVF
125 // can be used as input of VDA unittest. H264 raw stream can be played by 120 // can be used as input of VDA unittest. H264 raw stream can be played by
126 // "mplayer -fps 25 out.h264" and IVF can be played by mplayer directly. 121 // "mplayer -fps 25 out.h264" and IVF can be played by mplayer directly.
127 // Helpful description: http://wiki.multimedia.cx/index.php?title=IVF 122 // Helpful description: http://wiki.multimedia.cx/index.php?title=IVF
128 // Further parameters are optional (need to provide preceding positional 123 // Further parameters are optional (need to provide preceding positional
129 // parameters if a specific subsequent parameter is required): 124 // parameters if a specific subsequent parameter is required):
130 // - |requested_bitrate| requested bitrate in bits per second. 125 // - |requested_bitrate| requested bitrate in bits per second.
131 // - |requested_framerate| requested initial framerate. 126 // - |requested_framerate| requested initial framerate.
132 // - |requested_subsequent_bitrate| bitrate to switch to in the middle of the 127 // - |requested_subsequent_bitrate| bitrate to switch to in the middle of the
133 // stream. 128 // stream.
134 // - |requested_subsequent_framerate| framerate to switch to in the middle 129 // - |requested_subsequent_framerate| framerate to switch to in the middle
135 // of the stream. 130 // of the stream.
136 // Bitrate is only forced for tests that test bitrate. 131 // Bitrate is only forced for tests that test bitrate.
137 const char* g_default_in_filename = "bear_320x192_40frames.yuv"; 132 const char* g_default_in_filename = "bear_320x192_40frames.yuv";
138 133 #if !defined(OS_MACOSX)
139 #if defined(OS_CHROMEOS) 134 const char* g_default_in_parameters = ":320:192:1:out.h264:200000";
140 const base::FilePath::CharType* g_default_in_parameters = 135 #else
141 FILE_PATH_LITERAL(":320:192:1:out.h264:200000"); 136 const char* g_default_in_parameters = ":320:192:0:out.h264:200000";
142 #elif defined(OS_MACOSX) || defined(OS_WIN) 137 #endif
143 const base::FilePath::CharType* g_default_in_parameters =
144 FILE_PATH_LITERAL(",320,192,0,out.h264,200000");
145 #endif // defined(OS_CHROMEOS)
146 138
147 // Enabled by including a --fake_encoder flag to the command line invoking the 139 // Enabled by including a --fake_encoder flag to the command line invoking the
148 // test. 140 // test.
149 bool g_fake_encoder = false; 141 bool g_fake_encoder = false;
150 142
151 // Environment to store test stream data for all test cases. 143 // Environment to store test stream data for all test cases.
152 class VideoEncodeAcceleratorTestEnvironment; 144 class VideoEncodeAcceleratorTestEnvironment;
153 VideoEncodeAcceleratorTestEnvironment* g_env; 145 VideoEncodeAcceleratorTestEnvironment* g_env;
154 146
155 // The number of frames to be encoded. This variable is set by the switch 147 // 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
241 } 233 }
242 234
243 static bool IsH264(VideoCodecProfile profile) { 235 static bool IsH264(VideoCodecProfile profile) {
244 return profile >= H264PROFILE_MIN && profile <= H264PROFILE_MAX; 236 return profile >= H264PROFILE_MIN && profile <= H264PROFILE_MAX;
245 } 237 }
246 238
247 static bool IsVP8(VideoCodecProfile profile) { 239 static bool IsVP8(VideoCodecProfile profile) {
248 return profile >= VP8PROFILE_MIN && profile <= VP8PROFILE_MAX; 240 return profile >= VP8PROFILE_MIN && profile <= VP8PROFILE_MAX;
249 } 241 }
250 242
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
270 // ARM performs CPU cache management with CPU cache line granularity. We thus 243 // ARM performs CPU cache management with CPU cache line granularity. We thus
271 // need to ensure our buffers are CPU cache line-aligned (64 byte-aligned). 244 // need to ensure our buffers are CPU cache line-aligned (64 byte-aligned).
272 // Otherwise newer kernels will refuse to accept them, and on older kernels 245 // Otherwise newer kernels will refuse to accept them, and on older kernels
273 // we'll be treating ourselves to random corruption. 246 // we'll be treating ourselves to random corruption.
274 // Since we are just mapping and passing chunks of the input file directly to 247 // Since we are just mapping and passing chunks of the input file directly to
275 // the VEA as input frames to avoid copying large chunks of raw data on each 248 // the VEA as input frames to avoid copying large chunks of raw data on each
276 // frame and thus affecting performance measurements, we have to prepare a 249 // frame and thus affecting performance measurements, we have to prepare a
277 // temporary file with all planes aligned to 64-byte boundaries beforehand. 250 // temporary file with all planes aligned to 64-byte boundaries beforehand.
278 static void CreateAlignedInputStreamFile(const gfx::Size& coded_size, 251 static void CreateAlignedInputStreamFile(const gfx::Size& coded_size,
279 TestStream* test_stream) { 252 TestStream* test_stream) {
(...skipping 30 matching lines...) Expand all
310 visible_bpl[i] = VideoFrame::RowBytes(i, kInputFormat, 283 visible_bpl[i] = VideoFrame::RowBytes(i, kInputFormat,
311 test_stream->visible_size.width()); 284 test_stream->visible_size.width());
312 visible_plane_rows[i] = 285 visible_plane_rows[i] =
313 VideoFrame::Rows(i, kInputFormat, test_stream->visible_size.height()); 286 VideoFrame::Rows(i, kInputFormat, test_stream->visible_size.height());
314 const size_t padding_rows = 287 const size_t padding_rows =
315 VideoFrame::Rows(i, kInputFormat, coded_size.height()) - 288 VideoFrame::Rows(i, kInputFormat, coded_size.height()) -
316 visible_plane_rows[i]; 289 visible_plane_rows[i];
317 padding_sizes[i] = padding_rows * coded_bpl[i] + Align64Bytes(size) - size; 290 padding_sizes[i] = padding_rows * coded_bpl[i] + Align64Bytes(size) - size;
318 } 291 }
319 292
320 base::FilePath src_file(StringToFilePathStringType(test_stream->in_filename)); 293 base::FilePath src_file(test_stream->in_filename);
321 int64_t src_file_size = 0; 294 int64_t src_file_size = 0;
322 LOG_ASSERT(base::GetFileSize(src_file, &src_file_size)); 295 LOG_ASSERT(base::GetFileSize(src_file, &src_file_size));
323 296
324 size_t visible_buffer_size = 297 size_t visible_buffer_size =
325 VideoFrame::AllocationSize(kInputFormat, test_stream->visible_size); 298 VideoFrame::AllocationSize(kInputFormat, test_stream->visible_size);
326 LOG_ASSERT(src_file_size % visible_buffer_size == 0U) 299 LOG_ASSERT(src_file_size % visible_buffer_size == 0U)
327 << "Stream byte size is not a product of calculated frame byte size"; 300 << "Stream byte size is not a product of calculated frame byte size";
328 301
329 test_stream->num_frames = src_file_size / visible_buffer_size; 302 test_stream->num_frames = src_file_size / visible_buffer_size;
330 303
(...skipping 17 matching lines...) Expand all
348 visible_bpl[i]); 321 visible_bpl[i]);
349 src_ptr += visible_bpl[i]; 322 src_ptr += visible_bpl[i];
350 dest_offset += coded_bpl[i]; 323 dest_offset += coded_bpl[i];
351 } 324 }
352 dest_offset += padding_sizes[i]; 325 dest_offset += padding_sizes[i];
353 } 326 }
354 src_offset += visible_buffer_size; 327 src_offset += visible_buffer_size;
355 } 328 }
356 src.Close(); 329 src.Close();
357 330
358 #if defined(OS_POSIX)
359 // Assert that memory mapped of file starts at 64 byte boundary. So each 331 // Assert that memory mapped of file starts at 64 byte boundary. So each
360 // plane of frames also start at 64 byte boundary. 332 // plane of frames also start at 64 byte boundary.
361 ASSERT_EQ(reinterpret_cast<off_t>(&test_stream->aligned_in_file_data[0]) & 63, 333 ASSERT_EQ(reinterpret_cast<off_t>(&test_stream->aligned_in_file_data[0]) & 63,
362 0) 334 0)
363 << "File should be mapped at a 64 byte boundary"; 335 << "File should be mapped at a 64 byte boundary";
364 #endif // defined(OS_POSIX)
365 336
366 LOG_ASSERT(test_stream->num_frames > 0UL); 337 LOG_ASSERT(test_stream->num_frames > 0UL);
367 } 338 }
368 339
369 // Parse |data| into its constituent parts, set the various output fields 340 // Parse |data| into its constituent parts, set the various output fields
370 // accordingly, read in video stream, and store them to |test_streams|. 341 // accordingly, read in video stream, and store them to |test_streams|.
371 static void ParseAndReadTestStreamData(const base::FilePath::StringType& data, 342 static void ParseAndReadTestStreamData(const base::FilePath::StringType& data,
372 ScopedVector<TestStream>* test_streams) { 343 ScopedVector<TestStream>* test_streams) {
373 // Split the string to individual test stream data. 344 // Split the string to individual test stream data.
374 std::vector<base::FilePath::StringType> test_streams_data = 345 std::vector<base::FilePath::StringType> test_streams_data =
375 base::SplitString(data, base::FilePath::StringType(1, ';'), 346 base::SplitString(data, base::FilePath::StringType(1, ';'),
376 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); 347 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
377 LOG_ASSERT(test_streams_data.size() >= 1U) << data; 348 LOG_ASSERT(test_streams_data.size() >= 1U) << data;
378 349
379 // Parse each test stream data and read the input file. 350 // Parse each test stream data and read the input file.
380 for (size_t index = 0; index < test_streams_data.size(); ++index) { 351 for (size_t index = 0; index < test_streams_data.size(); ++index) {
381 std::vector<base::FilePath::StringType> fields = base::SplitString( 352 std::vector<base::FilePath::StringType> fields = base::SplitString(
382 test_streams_data[index], base::FilePath::StringType(1, ','), 353 test_streams_data[index], base::FilePath::StringType(1, ':'),
383 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); 354 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 }
390 LOG_ASSERT(fields.size() >= 4U) << data; 355 LOG_ASSERT(fields.size() >= 4U) << data;
391 LOG_ASSERT(fields.size() <= 9U) << data; 356 LOG_ASSERT(fields.size() <= 9U) << data;
392 TestStream* test_stream = new TestStream(); 357 TestStream* test_stream = new TestStream();
393 358
394 test_stream->in_filename = FilePathStringTypeToString(fields[0]); 359 test_stream->in_filename = fields[0];
395 int width, height; 360 int width, height;
396 bool result = base::StringToInt(fields[1], &width); 361 bool result = base::StringToInt(fields[1], &width);
397 LOG_ASSERT(result); 362 LOG_ASSERT(result);
398 result = base::StringToInt(fields[2], &height); 363 result = base::StringToInt(fields[2], &height);
399 LOG_ASSERT(result); 364 LOG_ASSERT(result);
400 test_stream->visible_size = gfx::Size(width, height); 365 test_stream->visible_size = gfx::Size(width, height);
401 LOG_ASSERT(!test_stream->visible_size.IsEmpty()); 366 LOG_ASSERT(!test_stream->visible_size.IsEmpty());
402 int profile; 367 int profile;
403 result = base::StringToInt(fields[3], &profile); 368 result = base::StringToInt(fields[3], &profile);
404 LOG_ASSERT(result); 369 LOG_ASSERT(result);
405 LOG_ASSERT(profile > VIDEO_CODEC_PROFILE_UNKNOWN); 370 LOG_ASSERT(profile > VIDEO_CODEC_PROFILE_UNKNOWN);
406 LOG_ASSERT(profile <= VIDEO_CODEC_PROFILE_MAX); 371 LOG_ASSERT(profile <= VIDEO_CODEC_PROFILE_MAX);
407 test_stream->requested_profile = static_cast<VideoCodecProfile>(profile); 372 test_stream->requested_profile = static_cast<VideoCodecProfile>(profile);
408 373
409 if (fields.size() >= 5 && !fields[4].empty()) 374 if (fields.size() >= 5 && !fields[4].empty())
410 test_stream->out_filename = FilePathStringTypeToString(fields[4]); 375 test_stream->out_filename = fields[4];
411 376
412 if (fields.size() >= 6 && !fields[5].empty()) 377 if (fields.size() >= 6 && !fields[5].empty())
413 LOG_ASSERT( 378 LOG_ASSERT(
414 base::StringToUint(fields[5], &test_stream->requested_bitrate)); 379 base::StringToUint(fields[5], &test_stream->requested_bitrate));
415 380
416 if (fields.size() >= 7 && !fields[6].empty()) 381 if (fields.size() >= 7 && !fields[6].empty())
417 LOG_ASSERT( 382 LOG_ASSERT(
418 base::StringToUint(fields[6], &test_stream->requested_framerate)); 383 base::StringToUint(fields[6], &test_stream->requested_framerate));
419 384
420 if (fields.size() >= 8 && !fields[7].empty()) { 385 if (fields.size() >= 8 && !fields[7].empty()) {
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
663 // Flush the decoder. 628 // Flush the decoder.
664 void Flush(); 629 void Flush();
665 630
666 private: 631 private:
667 void InitializeCB(bool success); 632 void InitializeCB(bool success);
668 void DecodeDone(DecodeStatus status); 633 void DecodeDone(DecodeStatus status);
669 void FlushDone(DecodeStatus status); 634 void FlushDone(DecodeStatus status);
670 void VerifyOutputFrame(const scoped_refptr<VideoFrame>& output_frame); 635 void VerifyOutputFrame(const scoped_refptr<VideoFrame>& output_frame);
671 void Decode(); 636 void Decode();
672 637
673 enum State { UNINITIALIZED, INITIALIZED, DECODING, DECODER_ERROR }; 638 enum State { UNINITIALIZED, INITIALIZED, DECODING, ERROR };
674 639
675 const VideoCodecProfile profile_; 640 const VideoCodecProfile profile_;
676 std::unique_ptr<FFmpegVideoDecoder> decoder_; 641 std::unique_ptr<FFmpegVideoDecoder> decoder_;
677 VideoDecoder::DecodeCB decode_cb_; 642 VideoDecoder::DecodeCB decode_cb_;
678 // Decode callback of an EOS buffer. 643 // Decode callback of an EOS buffer.
679 VideoDecoder::DecodeCB eos_decode_cb_; 644 VideoDecoder::DecodeCB eos_decode_cb_;
680 // Callback of Flush(). Called after all frames are decoded. 645 // Callback of Flush(). Called after all frames are decoded.
681 const base::Closure flush_complete_cb_; 646 const base::Closure flush_complete_cb_;
682 const base::Closure decode_error_cb_; 647 const base::Closure decode_error_cb_;
683 State decoder_state_; 648 State decoder_state_;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
726 base::Unretained(this)), 691 base::Unretained(this)),
727 base::Bind(&VideoFrameQualityValidator::VerifyOutputFrame, 692 base::Bind(&VideoFrameQualityValidator::VerifyOutputFrame,
728 base::Unretained(this))); 693 base::Unretained(this)));
729 } 694 }
730 695
731 void VideoFrameQualityValidator::InitializeCB(bool success) { 696 void VideoFrameQualityValidator::InitializeCB(bool success) {
732 if (success) { 697 if (success) {
733 decoder_state_ = INITIALIZED; 698 decoder_state_ = INITIALIZED;
734 Decode(); 699 Decode();
735 } else { 700 } else {
736 decoder_state_ = DECODER_ERROR; 701 decoder_state_ = ERROR;
737 if (IsH264(profile_)) 702 if (IsH264(profile_))
738 LOG(ERROR) << "Chromium does not support H264 decode. Try Chrome."; 703 LOG(ERROR) << "Chromium does not support H264 decode. Try Chrome.";
739 FAIL() << "Decoder initialization error"; 704 FAIL() << "Decoder initialization error";
740 decode_error_cb_.Run(); 705 decode_error_cb_.Run();
741 } 706 }
742 } 707 }
743 708
744 void VideoFrameQualityValidator::AddOriginalFrame( 709 void VideoFrameQualityValidator::AddOriginalFrame(
745 scoped_refptr<VideoFrame> frame) { 710 scoped_refptr<VideoFrame> frame) {
746 original_frames_.push(frame); 711 original_frames_.push(frame);
747 } 712 }
748 713
749 void VideoFrameQualityValidator::DecodeDone(DecodeStatus status) { 714 void VideoFrameQualityValidator::DecodeDone(DecodeStatus status) {
750 if (status == DecodeStatus::OK) { 715 if (status == DecodeStatus::OK) {
751 decoder_state_ = INITIALIZED; 716 decoder_state_ = INITIALIZED;
752 Decode(); 717 Decode();
753 } else { 718 } else {
754 decoder_state_ = DECODER_ERROR; 719 decoder_state_ = ERROR;
755 FAIL() << "Unexpected decode status = " << status << ". Stop decoding."; 720 FAIL() << "Unexpected decode status = " << status << ". Stop decoding.";
756 decode_error_cb_.Run(); 721 decode_error_cb_.Run();
757 } 722 }
758 } 723 }
759 724
760 void VideoFrameQualityValidator::FlushDone(DecodeStatus status) { 725 void VideoFrameQualityValidator::FlushDone(DecodeStatus status) {
761 flush_complete_cb_.Run(); 726 flush_complete_cb_.Run();
762 } 727 }
763 728
764 void VideoFrameQualityValidator::Flush() { 729 void VideoFrameQualityValidator::Flush() {
765 if (decoder_state_ != DECODER_ERROR) { 730 if (decoder_state_ != ERROR) {
766 decode_buffers_.push(DecoderBuffer::CreateEOSBuffer()); 731 decode_buffers_.push(DecoderBuffer::CreateEOSBuffer());
767 Decode(); 732 Decode();
768 } 733 }
769 } 734 }
770 735
771 void VideoFrameQualityValidator::AddDecodeBuffer( 736 void VideoFrameQualityValidator::AddDecodeBuffer(
772 const scoped_refptr<DecoderBuffer>& buffer) { 737 const scoped_refptr<DecoderBuffer>& buffer) {
773 if (decoder_state_ != DECODER_ERROR) { 738 if (decoder_state_ != ERROR) {
774 decode_buffers_.push(buffer); 739 decode_buffers_.push(buffer);
775 Decode(); 740 Decode();
776 } 741 }
777 } 742 }
778 743
779 void VideoFrameQualityValidator::Decode() { 744 void VideoFrameQualityValidator::Decode() {
780 if (decoder_state_ == INITIALIZED && !decode_buffers_.empty()) { 745 if (decoder_state_ == INITIALIZED && !decode_buffers_.empty()) {
781 scoped_refptr<DecoderBuffer> next_buffer = decode_buffers_.front(); 746 scoped_refptr<DecoderBuffer> next_buffer = decode_buffers_.front();
782 decode_buffers_.pop(); 747 decode_buffers_.pop();
783 decoder_state_ = DECODING; 748 decoder_state_ = DECODING;
(...skipping 15 matching lines...) Expand all
799 double difference = 0; 764 double difference = 0;
800 for (int plane : planes) { 765 for (int plane : planes) {
801 uint8_t* original_plane = original_frame->data(plane); 766 uint8_t* original_plane = original_frame->data(plane);
802 uint8_t* output_plane = output_frame->data(plane); 767 uint8_t* output_plane = output_frame->data(plane);
803 768
804 size_t rows = VideoFrame::Rows(plane, kInputFormat, visible_size.height()); 769 size_t rows = VideoFrame::Rows(plane, kInputFormat, visible_size.height());
805 size_t columns = 770 size_t columns =
806 VideoFrame::Columns(plane, kInputFormat, visible_size.width()); 771 VideoFrame::Columns(plane, kInputFormat, visible_size.width());
807 size_t stride = original_frame->stride(plane); 772 size_t stride = original_frame->stride(plane);
808 773
809 for (size_t i = 0; i < rows; i++) { 774 for (size_t i = 0; i < rows; i++)
810 for (size_t j = 0; j < columns; j++) { 775 for (size_t j = 0; j < columns; j++)
811 difference += std::abs(original_plane[stride * i + j] - 776 difference += std::abs(original_plane[stride * i + j] -
812 output_plane[stride * i + j]); 777 output_plane[stride * i + j]);
813 }
814 }
815 } 778 }
816
817 // Divide the difference by the size of frame. 779 // Divide the difference by the size of frame.
818 difference /= VideoFrame::AllocationSize(kInputFormat, visible_size); 780 difference /= VideoFrame::AllocationSize(kInputFormat, visible_size);
819 EXPECT_TRUE(difference <= kDecodeSimilarityThreshold) 781 EXPECT_TRUE(difference <= kDecodeSimilarityThreshold)
820 << "difference = " << difference << " > decode similarity threshold"; 782 << "differrence = " << difference << " > decode similarity threshold";
821 } 783 }
822 784
823 class VEAClient : public VideoEncodeAccelerator::Client { 785 class VEAClient : public VideoEncodeAccelerator::Client {
824 public: 786 public:
825 VEAClient(TestStream* test_stream, 787 VEAClient(TestStream* test_stream,
826 ClientStateNotification<ClientState>* note, 788 ClientStateNotification<ClientState>* note,
827 bool save_to_file, 789 bool save_to_file,
828 unsigned int keyframe_period, 790 unsigned int keyframe_period,
829 bool force_bitrate, 791 bool force_bitrate,
830 bool test_perf, 792 bool test_perf,
(...skipping 18 matching lines...) Expand all
849 private: 811 private:
850 bool has_encoder() { return encoder_.get(); } 812 bool has_encoder() { return encoder_.get(); }
851 813
852 // Return the number of encoded frames per second. 814 // Return the number of encoded frames per second.
853 double frames_per_second(); 815 double frames_per_second();
854 816
855 std::unique_ptr<VideoEncodeAccelerator> CreateFakeVEA(); 817 std::unique_ptr<VideoEncodeAccelerator> CreateFakeVEA();
856 std::unique_ptr<VideoEncodeAccelerator> CreateV4L2VEA(); 818 std::unique_ptr<VideoEncodeAccelerator> CreateV4L2VEA();
857 std::unique_ptr<VideoEncodeAccelerator> CreateVaapiVEA(); 819 std::unique_ptr<VideoEncodeAccelerator> CreateVaapiVEA();
858 std::unique_ptr<VideoEncodeAccelerator> CreateVTVEA(); 820 std::unique_ptr<VideoEncodeAccelerator> CreateVTVEA();
859 std::unique_ptr<VideoEncodeAccelerator> CreateMFVEA();
860 821
861 void SetState(ClientState new_state); 822 void SetState(ClientState new_state);
862 823
863 // Set current stream parameters to given |bitrate| at |framerate|. 824 // Set current stream parameters to given |bitrate| at |framerate|.
864 void SetStreamParameters(unsigned int bitrate, unsigned int framerate); 825 void SetStreamParameters(unsigned int bitrate, unsigned int framerate);
865 826
866 // Called when encoder is done with a VideoFrame. 827 // Called when encoder is done with a VideoFrame.
867 void InputNoLongerNeededCallback(int32_t input_id); 828 void InputNoLongerNeededCallback(int32_t input_id);
868 829
869 // Feed the encoder with one input frame. 830 // Feed the encoder with one input frame.
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
1082 // Fake encoder produces an invalid stream, so skip validating it. 1043 // Fake encoder produces an invalid stream, so skip validating it.
1083 if (!g_fake_encoder) { 1044 if (!g_fake_encoder) {
1084 stream_validator_ = StreamValidator::Create( 1045 stream_validator_ = StreamValidator::Create(
1085 test_stream_->requested_profile, 1046 test_stream_->requested_profile,
1086 base::Bind(&VEAClient::HandleEncodedFrame, base::Unretained(this))); 1047 base::Bind(&VEAClient::HandleEncodedFrame, base::Unretained(this)));
1087 CHECK(stream_validator_); 1048 CHECK(stream_validator_);
1088 } 1049 }
1089 1050
1090 if (save_to_file_) { 1051 if (save_to_file_) {
1091 LOG_ASSERT(!test_stream_->out_filename.empty()); 1052 LOG_ASSERT(!test_stream_->out_filename.empty());
1092 #if defined(OS_POSIX)
1093 base::FilePath out_filename(test_stream_->out_filename); 1053 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
1097 // This creates or truncates out_filename. 1054 // This creates or truncates out_filename.
1098 // Without it, AppendToFile() will not work. 1055 // Without it, AppendToFile() will not work.
1099 EXPECT_EQ(0, base::WriteFile(out_filename, NULL, 0)); 1056 EXPECT_EQ(0, base::WriteFile(out_filename, NULL, 0));
1100 } 1057 }
1101 1058
1102 // Initialize the parameters of the test streams. 1059 // Initialize the parameters of the test streams.
1103 UpdateTestStreamData(mid_stream_bitrate_switch, mid_stream_framerate_switch); 1060 UpdateTestStreamData(mid_stream_bitrate_switch, mid_stream_framerate_switch);
1104 1061
1105 thread_checker_.DetachFromThread(); 1062 thread_checker_.DetachFromThread();
1106 } 1063 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1139 } 1096 }
1140 1097
1141 std::unique_ptr<VideoEncodeAccelerator> VEAClient::CreateVTVEA() { 1098 std::unique_ptr<VideoEncodeAccelerator> VEAClient::CreateVTVEA() {
1142 std::unique_ptr<VideoEncodeAccelerator> encoder; 1099 std::unique_ptr<VideoEncodeAccelerator> encoder;
1143 #if defined(OS_MACOSX) 1100 #if defined(OS_MACOSX)
1144 encoder.reset(new VTVideoEncodeAccelerator()); 1101 encoder.reset(new VTVideoEncodeAccelerator());
1145 #endif 1102 #endif
1146 return encoder; 1103 return encoder;
1147 } 1104 }
1148 1105
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
1158 void VEAClient::CreateEncoder() { 1106 void VEAClient::CreateEncoder() {
1159 DCHECK(thread_checker_.CalledOnValidThread()); 1107 DCHECK(thread_checker_.CalledOnValidThread());
1160 LOG_ASSERT(!has_encoder()); 1108 LOG_ASSERT(!has_encoder());
1161 1109
1162 std::unique_ptr<VideoEncodeAccelerator> encoders[] = { 1110 std::unique_ptr<VideoEncodeAccelerator> encoders[] = {
1163 CreateFakeVEA(), CreateV4L2VEA(), CreateVaapiVEA(), CreateVTVEA(), 1111 CreateFakeVEA(), CreateV4L2VEA(), CreateVaapiVEA(), CreateVTVEA()};
1164 CreateMFVEA()};
1165 1112
1166 DVLOG(1) << "Profile: " << test_stream_->requested_profile 1113 DVLOG(1) << "Profile: " << test_stream_->requested_profile
1167 << ", initial bitrate: " << requested_bitrate_; 1114 << ", initial bitrate: " << requested_bitrate_;
1168 1115
1169 for (size_t i = 0; i < arraysize(encoders); ++i) { 1116 for (size_t i = 0; i < arraysize(encoders); ++i) {
1170 if (!encoders[i]) 1117 if (!encoders[i])
1171 continue; 1118 continue;
1172 encoder_ = std::move(encoders[i]); 1119 encoder_ = std::move(encoders[i]);
1173 SetState(CS_ENCODER_SET); 1120 SetState(CS_ENCODER_SET);
1174 if (encoder_->Initialize(kInputFormat, test_stream_->visible_size, 1121 if (encoder_->Initialize(kInputFormat, test_stream_->visible_size,
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after
1744 for (size_t i = 0; i < num_concurrent_encoders; ++i) { 1691 for (size_t i = 0; i < num_concurrent_encoders; ++i) {
1745 encoder_thread.task_runner()->PostTask( 1692 encoder_thread.task_runner()->PostTask(
1746 FROM_HERE, 1693 FROM_HERE,
1747 base::Bind(&VEAClient::DestroyEncoder, base::Unretained(clients[i]))); 1694 base::Bind(&VEAClient::DestroyEncoder, base::Unretained(clients[i])));
1748 } 1695 }
1749 1696
1750 // This ensures all tasks have finished. 1697 // This ensures all tasks have finished.
1751 encoder_thread.Stop(); 1698 encoder_thread.Stop();
1752 } 1699 }
1753 1700
1754 #if defined(OS_CHROMEOS) 1701 #if !defined(OS_MACOSX)
1755 INSTANTIATE_TEST_CASE_P( 1702 INSTANTIATE_TEST_CASE_P(
1756 SimpleEncode, 1703 SimpleEncode,
1757 VideoEncodeAcceleratorTest, 1704 VideoEncodeAcceleratorTest,
1758 ::testing::Values( 1705 ::testing::Values(
1759 std::make_tuple(1, true, 0, false, false, false, false, false, false), 1706 std::make_tuple(1, true, 0, false, false, false, false, false, false),
1760 std::make_tuple(1, true, 0, false, false, false, false, true, false))); 1707 std::make_tuple(1, true, 0, false, false, false, false, true, false)));
1761 1708
1762 INSTANTIATE_TEST_CASE_P( 1709 INSTANTIATE_TEST_CASE_P(
1763 EncoderPerf, 1710 EncoderPerf,
1764 VideoEncodeAcceleratorTest, 1711 VideoEncodeAcceleratorTest,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1802 std::make_tuple(3, false, 0, false, false, false, false, false, false), 1749 std::make_tuple(3, false, 0, false, false, false, false, false, false),
1803 std::make_tuple(3, false, 0, true, false, false, true, false, false), 1750 std::make_tuple(3, false, 0, true, false, false, true, false, false),
1804 std::make_tuple(3, false, 0, true, false, true, false, false, false))); 1751 std::make_tuple(3, false, 0, true, false, true, false, false, false)));
1805 1752
1806 INSTANTIATE_TEST_CASE_P( 1753 INSTANTIATE_TEST_CASE_P(
1807 VerifyTimestamp, 1754 VerifyTimestamp,
1808 VideoEncodeAcceleratorTest, 1755 VideoEncodeAcceleratorTest,
1809 ::testing::Values( 1756 ::testing::Values(
1810 std::make_tuple(1, false, 0, false, false, false, false, false, true))); 1757 std::make_tuple(1, false, 0, false, false, false, false, false, true)));
1811 1758
1812 #elif defined(OS_MACOSX) || defined(OS_WIN) 1759 #else
1813 INSTANTIATE_TEST_CASE_P( 1760 INSTANTIATE_TEST_CASE_P(
1814 SimpleEncode, 1761 SimpleEncode,
1815 VideoEncodeAcceleratorTest, 1762 VideoEncodeAcceleratorTest,
1816 ::testing::Values( 1763 ::testing::Values(
1817 std::make_tuple(1, true, 0, false, false, false, false, false, false), 1764 std::make_tuple(1, true, 0, false, false, false, false, false, false),
1818 std::make_tuple(1, true, 0, false, false, false, false, true, false))); 1765 std::make_tuple(1, true, 0, false, false, false, false, true, false)));
1819 1766
1820 INSTANTIATE_TEST_CASE_P( 1767 INSTANTIATE_TEST_CASE_P(
1821 EncoderPerf, 1768 EncoderPerf,
1822 VideoEncodeAcceleratorTest, 1769 VideoEncodeAcceleratorTest,
1823 ::testing::Values( 1770 ::testing::Values(
1824 std::make_tuple(1, false, 0, false, true, false, false, false, false))); 1771 std::make_tuple(1, false, 0, false, true, false, false, false, false)));
1825 1772
1826 INSTANTIATE_TEST_CASE_P(MultipleEncoders, 1773 INSTANTIATE_TEST_CASE_P(MultipleEncoders,
1827 VideoEncodeAcceleratorTest, 1774 VideoEncodeAcceleratorTest,
1828 ::testing::Values(std::make_tuple(3, 1775 ::testing::Values(std::make_tuple(3,
1829 false, 1776 false,
1830 0, 1777 0,
1831 false, 1778 false,
1832 false, 1779 false,
1833 false, 1780 false,
1834 false, 1781 false,
1835 false, 1782 false,
1836 false))); 1783 false)));
1837 #if defined(OS_WIN) 1784 #endif
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)
1846 1785
1847 // TODO(posciak): more tests: 1786 // TODO(posciak): more tests:
1848 // - async FeedEncoderWithOutput 1787 // - async FeedEncoderWithOutput
1849 // - out-of-order return of outputs to encoder 1788 // - out-of-order return of outputs to encoder
1850 // - multiple encoders + decoders 1789 // - multiple encoders + decoders
1851 // - mid-stream encoder_->Destroy() 1790 // - mid-stream encoder_->Destroy()
1852 1791
1853 } // namespace 1792 } // namespace
1854 } // namespace media 1793 } // namespace media
1855 1794
1856 int main(int argc, char** argv) { 1795 int main(int argc, char** argv) {
1857 testing::InitGoogleTest(&argc, argv); // Removes gtest-specific args. 1796 testing::InitGoogleTest(&argc, argv); // Removes gtest-specific args.
1858 base::CommandLine::Init(argc, argv); 1797 base::CommandLine::Init(argc, argv);
1859 1798
1860 base::ShadowingAtExitManager at_exit_manager; 1799 base::ShadowingAtExitManager at_exit_manager;
1861 base::MessageLoop main_loop; 1800 base::MessageLoop main_loop;
1862 1801
1863 std::unique_ptr<base::FilePath::StringType> test_stream_data( 1802 std::unique_ptr<base::FilePath::StringType> test_stream_data(
1864 new base::FilePath::StringType( 1803 new base::FilePath::StringType(
1865 media::GetTestDataFilePath(media::g_default_in_filename).value())); 1804 media::GetTestDataFilePath(media::g_default_in_filename).value() +
1866 test_stream_data->append(media::g_default_in_parameters); 1805 media::g_default_in_parameters));
1867 1806
1868 // Needed to enable DVLOG through --vmodule. 1807 // Needed to enable DVLOG through --vmodule.
1869 logging::LoggingSettings settings; 1808 logging::LoggingSettings settings;
1870 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; 1809 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
1871 LOG_ASSERT(logging::InitLogging(settings)); 1810 LOG_ASSERT(logging::InitLogging(settings));
1872 1811
1873 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); 1812 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess();
1874 DCHECK(cmd_line); 1813 DCHECK(cmd_line);
1875 1814
1876 bool run_at_fps = false; 1815 bool run_at_fps = false;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1932 1871
1933 media::g_env = 1872 media::g_env =
1934 reinterpret_cast<media::VideoEncodeAcceleratorTestEnvironment*>( 1873 reinterpret_cast<media::VideoEncodeAcceleratorTestEnvironment*>(
1935 testing::AddGlobalTestEnvironment( 1874 testing::AddGlobalTestEnvironment(
1936 new media::VideoEncodeAcceleratorTestEnvironment( 1875 new media::VideoEncodeAcceleratorTestEnvironment(
1937 std::move(test_stream_data), log_path, run_at_fps, 1876 std::move(test_stream_data), log_path, run_at_fps,
1938 needs_encode_latency, verify_all_output))); 1877 needs_encode_latency, verify_all_output)));
1939 1878
1940 return RUN_ALL_TESTS(); 1879 return RUN_ALL_TESTS();
1941 } 1880 }
OLDNEW
« no previous file with comments | « media/gpu/media_foundation_video_encode_accelerator_win.cc ('k') | media/media.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698