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

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

Issue 760963003: Adds fake hardware video encoder. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updates according to comments Created 5 years, 11 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 | « no previous file | media/cast/cast_testing.gypi » ('j') | media/cast/sender/video_sender_unittest.cc » ('J')
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 "base/at_exit.h" 5 #include "base/at_exit.h"
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/files/memory_mapped_file.h" 9 #include "base/files/memory_mapped_file.h"
10 #include "base/memory/scoped_vector.h" 10 #include "base/memory/scoped_vector.h"
11 #include "base/numerics/safe_conversions.h" 11 #include "base/numerics/safe_conversions.h"
12 #include "base/process/process_handle.h" 12 #include "base/process/process_handle.h"
13 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
14 #include "base/strings/string_split.h" 14 #include "base/strings/string_split.h"
15 #include "base/sys_byteorder.h" 15 #include "base/sys_byteorder.h"
16 #include "base/time/time.h" 16 #include "base/time/time.h"
17 #include "base/timer/timer.h" 17 #include "base/timer/timer.h"
18 #include "content/common/gpu/media/video_accelerator_unittest_helpers.h" 18 #include "content/common/gpu/media/video_accelerator_unittest_helpers.h"
19 #include "media/base/bind_to_current_loop.h" 19 #include "media/base/bind_to_current_loop.h"
20 #include "media/base/bitstream_buffer.h" 20 #include "media/base/bitstream_buffer.h"
21 #include "media/base/test_data_util.h" 21 #include "media/base/test_data_util.h"
22 #include "media/filters/h264_parser.h" 22 #include "media/filters/h264_parser.h"
23 #include "media/video/fake_video_encode_accelerator.h"
23 #include "media/video/video_encode_accelerator.h" 24 #include "media/video/video_encode_accelerator.h"
24 #include "testing/gtest/include/gtest/gtest.h" 25 #include "testing/gtest/include/gtest/gtest.h"
25 26
26 #if defined(USE_OZONE) 27 #if defined(USE_OZONE)
27 #include "ui/ozone/public/ozone_platform.h" 28 #include "ui/ozone/public/ozone_platform.h"
28 #endif 29 #endif
29 30
30 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL) 31 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL)
31 #include "content/common/gpu/media/v4l2_video_encode_accelerator.h" 32 #include "content/common/gpu/media/v4l2_video_encode_accelerator.h"
32 #elif defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) 33 #elif defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY)
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 // parameters if a specific subsequent parameter is required): 92 // parameters if a specific subsequent parameter is required):
92 // - |requested_bitrate| requested bitrate in bits per second. 93 // - |requested_bitrate| requested bitrate in bits per second.
93 // - |requested_framerate| requested initial framerate. 94 // - |requested_framerate| requested initial framerate.
94 // - |requested_subsequent_bitrate| bitrate to switch to in the middle of the 95 // - |requested_subsequent_bitrate| bitrate to switch to in the middle of the
95 // stream. 96 // stream.
96 // - |requested_subsequent_framerate| framerate to switch to in the middle 97 // - |requested_subsequent_framerate| framerate to switch to in the middle
97 // of the stream. 98 // of the stream.
98 // Bitrate is only forced for tests that test bitrate. 99 // Bitrate is only forced for tests that test bitrate.
99 const char* g_default_in_filename = "bear_320x192_40frames.yuv"; 100 const char* g_default_in_filename = "bear_320x192_40frames.yuv";
100 const char* g_default_in_parameters = ":320:192:1:out.h264:200000"; 101 const char* g_default_in_parameters = ":320:192:1:out.h264:200000";
102
103 // Enabled by including a --fake_encoder flag to the command line invoking the
104 // test.
105 bool g_fake_encoder = false;
106
101 // Environment to store test stream data for all test cases. 107 // Environment to store test stream data for all test cases.
102 class VideoEncodeAcceleratorTestEnvironment; 108 class VideoEncodeAcceleratorTestEnvironment;
103 VideoEncodeAcceleratorTestEnvironment* g_env; 109 VideoEncodeAcceleratorTestEnvironment* g_env;
104 110
105 struct IvfFileHeader { 111 struct IvfFileHeader {
106 char signature[4]; // signature: 'DKIF' 112 char signature[4]; // signature: 'DKIF'
107 uint16_t version; // version (should be 0) 113 uint16_t version; // version (should be 0)
108 uint16_t header_size; // size of header in bytes 114 uint16_t header_size; // size of header in bytes
109 uint32_t fourcc; // codec FourCC (e.g., 'VP80') 115 uint32_t fourcc; // codec FourCC (e.g., 'VP80')
110 uint16_t width; // width in pixels 116 uint16_t width; // width in pixels
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 // no simple way to detect this. We'd need to parse the frames and go through 484 // no simple way to detect this. We'd need to parse the frames and go through
479 // partition numbers/sizes. For now assume one frame per buffer. 485 // partition numbers/sizes. For now assume one frame per buffer.
480 } 486 }
481 487
482 // static 488 // static
483 scoped_ptr<StreamValidator> StreamValidator::Create( 489 scoped_ptr<StreamValidator> StreamValidator::Create(
484 media::VideoCodecProfile profile, 490 media::VideoCodecProfile profile,
485 const FrameFoundCallback& frame_cb) { 491 const FrameFoundCallback& frame_cb) {
486 scoped_ptr<StreamValidator> validator; 492 scoped_ptr<StreamValidator> validator;
487 493
488 if (IsH264(profile)) { 494 if (g_fake_encoder) {
495 validator.reset(NULL);
496 } else if (IsH264(profile)) {
489 validator.reset(new H264Validator(frame_cb)); 497 validator.reset(new H264Validator(frame_cb));
490 } else if (IsVP8(profile)) { 498 } else if (IsVP8(profile)) {
491 validator.reset(new VP8Validator(frame_cb)); 499 validator.reset(new VP8Validator(frame_cb));
492 } else { 500 } else {
493 LOG(FATAL) << "Unsupported profile: " << profile; 501 LOG(FATAL) << "Unsupported profile: " << profile;
494 } 502 }
495 503
496 return validator.Pass(); 504 return validator.Pass();
497 } 505 }
498 506
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
703 requested_subsequent_bitrate_(0), 711 requested_subsequent_bitrate_(0),
704 requested_subsequent_framerate_(0), 712 requested_subsequent_framerate_(0),
705 run_at_fps_(run_at_fps) { 713 run_at_fps_(run_at_fps) {
706 if (keyframe_period_) 714 if (keyframe_period_)
707 CHECK_LT(kMaxKeyframeDelay, keyframe_period_); 715 CHECK_LT(kMaxKeyframeDelay, keyframe_period_);
708 716
709 validator_ = StreamValidator::Create( 717 validator_ = StreamValidator::Create(
710 test_stream_->requested_profile, 718 test_stream_->requested_profile,
711 base::Bind(&VEAClient::HandleEncodedFrame, base::Unretained(this))); 719 base::Bind(&VEAClient::HandleEncodedFrame, base::Unretained(this)));
712 720
713 CHECK(validator_.get()); 721
722 CHECK(g_fake_encoder || validator_.get());
714 723
715 if (save_to_file_) { 724 if (save_to_file_) {
716 CHECK(!test_stream_->out_filename.empty()); 725 CHECK(!test_stream_->out_filename.empty());
717 base::FilePath out_filename(test_stream_->out_filename); 726 base::FilePath out_filename(test_stream_->out_filename);
718 // This creates or truncates out_filename. 727 // This creates or truncates out_filename.
719 // Without it, AppendToFile() will not work. 728 // Without it, AppendToFile() will not work.
720 EXPECT_EQ(0, base::WriteFile(out_filename, NULL, 0)); 729 EXPECT_EQ(0, base::WriteFile(out_filename, NULL, 0));
721 } 730 }
722 731
723 // Initialize the parameters of the test streams. 732 // Initialize the parameters of the test streams.
724 UpdateTestStreamData(mid_stream_bitrate_switch, mid_stream_framerate_switch); 733 UpdateTestStreamData(mid_stream_bitrate_switch, mid_stream_framerate_switch);
725 734
726 thread_checker_.DetachFromThread(); 735 thread_checker_.DetachFromThread();
727 } 736 }
728 737
729 VEAClient::~VEAClient() { CHECK(!has_encoder()); } 738 VEAClient::~VEAClient() { CHECK(!has_encoder()); }
730 739
731 void VEAClient::CreateEncoder() { 740 void VEAClient::CreateEncoder() {
732 DCHECK(thread_checker_.CalledOnValidThread()); 741 DCHECK(thread_checker_.CalledOnValidThread());
733 CHECK(!has_encoder()); 742 CHECK(!has_encoder());
734 743
744
745 if (g_fake_encoder) {
746 encoder_.reset(
747 new media::FakeVideoEncodeAccelerator(
748 base::MessageLoopProxy::current()));
749 } else {
735 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL) 750 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL)
736 scoped_ptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kEncoder); 751 scoped_ptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kEncoder);
737 encoder_.reset(new V4L2VideoEncodeAccelerator(device.Pass())); 752 encoder_.reset(new V4L2VideoEncodeAccelerator(device.Pass()));
738 #elif defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) 753 #elif defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY)
739 encoder_.reset(new VaapiVideoEncodeAccelerator()); 754 encoder_.reset(new VaapiVideoEncodeAccelerator());
740 #endif 755 #endif
756 }
741 757
742 SetState(CS_ENCODER_SET); 758 SetState(CS_ENCODER_SET);
743 759
744 DVLOG(1) << "Profile: " << test_stream_->requested_profile 760 DVLOG(1) << "Profile: " << test_stream_->requested_profile
745 << ", initial bitrate: " << requested_bitrate_; 761 << ", initial bitrate: " << requested_bitrate_;
746 if (!encoder_->Initialize(kInputFormat, 762 if (!encoder_->Initialize(kInputFormat,
747 test_stream_->visible_size, 763 test_stream_->visible_size,
748 test_stream_->requested_profile, 764 test_stream_->requested_profile,
749 requested_bitrate_, 765 requested_bitrate_,
750 this)) { 766 this)) {
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
876 base::SharedMemory* shm = it->second; 892 base::SharedMemory* shm = it->second;
877 output_buffers_at_client_.erase(it); 893 output_buffers_at_client_.erase(it);
878 894
879 if (state_ == CS_FINISHED) 895 if (state_ == CS_FINISHED)
880 return; 896 return;
881 897
882 encoded_stream_size_since_last_check_ += payload_size; 898 encoded_stream_size_since_last_check_ += payload_size;
883 899
884 const uint8* stream_ptr = static_cast<const uint8*>(shm->memory()); 900 const uint8* stream_ptr = static_cast<const uint8*>(shm->memory());
885 if (payload_size > 0) { 901 if (payload_size > 0) {
886 validator_->ProcessStreamBuffer(stream_ptr, payload_size); 902 if (validator_) {
903 validator_->ProcessStreamBuffer(stream_ptr, payload_size);
904 } else {
905 HandleEncodedFrame(key_frame);
906 }
887 907
888 if (save_to_file_) { 908 if (save_to_file_) {
889 if (IsVP8(test_stream_->requested_profile)) 909 if (IsVP8(test_stream_->requested_profile))
890 WriteIvfFrameHeader(num_encoded_frames_ - 1, payload_size); 910 WriteIvfFrameHeader(num_encoded_frames_ - 1, payload_size);
891 911
892 EXPECT_TRUE(base::AppendToFile( 912 EXPECT_TRUE(base::AppendToFile(
893 base::FilePath::FromUTF8Unsafe(test_stream_->out_filename), 913 base::FilePath::FromUTF8Unsafe(test_stream_->out_filename),
894 static_cast<char*>(shm->memory()), 914 static_cast<char*>(shm->memory()),
895 base::checked_cast<int>(payload_size))); 915 base::checked_cast<int>(payload_size)));
896 } 916 }
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after
1315 for (base::CommandLine::SwitchMap::const_iterator it = switches.begin(); 1335 for (base::CommandLine::SwitchMap::const_iterator it = switches.begin();
1316 it != switches.end(); 1336 it != switches.end();
1317 ++it) { 1337 ++it) {
1318 if (it->first == "test_stream_data") { 1338 if (it->first == "test_stream_data") {
1319 test_stream_data->assign(it->second.c_str()); 1339 test_stream_data->assign(it->second.c_str());
1320 continue; 1340 continue;
1321 } 1341 }
1322 if (it->first == "num_frames_to_encode") { 1342 if (it->first == "num_frames_to_encode") {
1323 std::string input(it->second.begin(), it->second.end()); 1343 std::string input(it->second.begin(), it->second.end());
1324 CHECK(base::StringToInt(input, &content::g_num_frames_to_encode)); 1344 CHECK(base::StringToInt(input, &content::g_num_frames_to_encode));
1345 if (it->first == "fake_encoder") {
1346 content::g_fake_encoder = true;
1325 continue; 1347 continue;
1326 } 1348 }
1327 if (it->first == "run_at_fps") { 1349 if (it->first == "run_at_fps") {
1328 run_at_fps = true; 1350 run_at_fps = true;
1329 continue; 1351 continue;
1330 } 1352 }
1331 if (it->first == "v" || it->first == "vmodule") 1353 if (it->first == "v" || it->first == "vmodule")
1332 continue; 1354 continue;
1333 if (it->first == "ozone-platform" || it->first == "ozone-use-surfaceless") 1355 if (it->first == "ozone-platform" || it->first == "ozone-use-surfaceless")
1334 continue; 1356 continue;
1335 LOG(FATAL) << "Unexpected switch: " << it->first << ":" << it->second; 1357 LOG(FATAL) << "Unexpected switch: " << it->first << ":" << it->second;
1336 } 1358 }
1337 1359
1338 content::g_env = 1360 content::g_env =
1339 reinterpret_cast<content::VideoEncodeAcceleratorTestEnvironment*>( 1361 reinterpret_cast<content::VideoEncodeAcceleratorTestEnvironment*>(
1340 testing::AddGlobalTestEnvironment( 1362 testing::AddGlobalTestEnvironment(
1341 new content::VideoEncodeAcceleratorTestEnvironment( 1363 new content::VideoEncodeAcceleratorTestEnvironment(
1342 test_stream_data.Pass(), run_at_fps))); 1364 test_stream_data.Pass(), run_at_fps)));
1343 1365
1344 return RUN_ALL_TESTS(); 1366 return RUN_ALL_TESTS();
1345 } 1367 }
OLDNEW
« no previous file with comments | « no previous file | media/cast/cast_testing.gypi » ('j') | media/cast/sender/video_sender_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698