OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "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 "content/common/gpu/media/video_accelerator_unittest_helpers.h" | 17 #include "content/common/gpu/media/video_accelerator_unittest_helpers.h" |
18 #include "media/base/bind_to_current_loop.h" | 18 #include "media/base/bind_to_current_loop.h" |
19 #include "media/base/bitstream_buffer.h" | 19 #include "media/base/bitstream_buffer.h" |
20 #include "media/base/test_data_util.h" | 20 #include "media/base/test_data_util.h" |
21 #include "media/filters/h264_parser.h" | 21 #include "media/filters/h264_parser.h" |
| 22 #include "media/video/fake_video_encode_accelerator.h" |
22 #include "media/video/video_encode_accelerator.h" | 23 #include "media/video/video_encode_accelerator.h" |
23 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
24 | 25 |
25 #if defined(USE_X11) | 26 #if defined(USE_X11) |
26 #include "ui/gfx/x/x11_types.h" | 27 #include "ui/gfx/x/x11_types.h" |
27 #endif | 28 #endif |
28 | 29 |
29 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL) | 30 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL) |
30 #include "content/common/gpu/media/v4l2_video_encode_accelerator.h" | 31 #include "content/common/gpu/media/v4l2_video_encode_accelerator.h" |
31 #elif defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) && defined(USE_X11) | 32 #elif defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) && defined(USE_X11) |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 // parameters if a specific subsequent parameter is required): | 91 // parameters if a specific subsequent parameter is required): |
91 // - |requested_bitrate| requested bitrate in bits per second. | 92 // - |requested_bitrate| requested bitrate in bits per second. |
92 // - |requested_framerate| requested initial framerate. | 93 // - |requested_framerate| requested initial framerate. |
93 // - |requested_subsequent_bitrate| bitrate to switch to in the middle of the | 94 // - |requested_subsequent_bitrate| bitrate to switch to in the middle of the |
94 // stream. | 95 // stream. |
95 // - |requested_subsequent_framerate| framerate to switch to in the middle | 96 // - |requested_subsequent_framerate| framerate to switch to in the middle |
96 // of the stream. | 97 // of the stream. |
97 // Bitrate is only forced for tests that test bitrate. | 98 // Bitrate is only forced for tests that test bitrate. |
98 const char* g_default_in_filename = "bear_320x192_40frames.yuv"; | 99 const char* g_default_in_filename = "bear_320x192_40frames.yuv"; |
99 const char* g_default_in_parameters = ":320:192:1:out.h264:200000"; | 100 const char* g_default_in_parameters = ":320:192:1:out.h264:200000"; |
| 101 |
| 102 // Enabled by including a --fake_encoder flag to the command line invoking the |
| 103 // test. |
| 104 bool g_fake_encoder = false; |
| 105 |
100 // Environment to store test stream data for all test cases. | 106 // Environment to store test stream data for all test cases. |
101 class VideoEncodeAcceleratorTestEnvironment; | 107 class VideoEncodeAcceleratorTestEnvironment; |
102 VideoEncodeAcceleratorTestEnvironment* g_env; | 108 VideoEncodeAcceleratorTestEnvironment* g_env; |
103 | 109 |
104 struct IvfFileHeader { | 110 struct IvfFileHeader { |
105 char signature[4]; // signature: 'DKIF' | 111 char signature[4]; // signature: 'DKIF' |
106 uint16_t version; // version (should be 0) | 112 uint16_t version; // version (should be 0) |
107 uint16_t header_size; // size of header in bytes | 113 uint16_t header_size; // size of header in bytes |
108 uint32_t fourcc; // codec FourCC (e.g., 'VP80') | 114 uint32_t fourcc; // codec FourCC (e.g., 'VP80') |
109 uint16_t width; // width in pixels | 115 uint16_t width; // width in pixels |
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
473 // no simple way to detect this. We'd need to parse the frames and go through | 479 // no simple way to detect this. We'd need to parse the frames and go through |
474 // partition numbers/sizes. For now assume one frame per buffer. | 480 // partition numbers/sizes. For now assume one frame per buffer. |
475 } | 481 } |
476 | 482 |
477 // static | 483 // static |
478 scoped_ptr<StreamValidator> StreamValidator::Create( | 484 scoped_ptr<StreamValidator> StreamValidator::Create( |
479 media::VideoCodecProfile profile, | 485 media::VideoCodecProfile profile, |
480 const FrameFoundCallback& frame_cb) { | 486 const FrameFoundCallback& frame_cb) { |
481 scoped_ptr<StreamValidator> validator; | 487 scoped_ptr<StreamValidator> validator; |
482 | 488 |
483 if (IsH264(profile)) { | 489 if (g_fake_encoder) { |
| 490 validator.reset(NULL); |
| 491 } else if (IsH264(profile)) { |
484 validator.reset(new H264Validator(frame_cb)); | 492 validator.reset(new H264Validator(frame_cb)); |
485 } else if (IsVP8(profile)) { | 493 } else if (IsVP8(profile)) { |
486 validator.reset(new VP8Validator(frame_cb)); | 494 validator.reset(new VP8Validator(frame_cb)); |
487 } else { | 495 } else { |
488 LOG(FATAL) << "Unsupported profile: " << profile; | 496 LOG(FATAL) << "Unsupported profile: " << profile; |
489 } | 497 } |
490 | 498 |
491 return validator.Pass(); | 499 return validator.Pass(); |
492 } | 500 } |
493 | 501 |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
684 requested_framerate_(0), | 692 requested_framerate_(0), |
685 requested_subsequent_bitrate_(0), | 693 requested_subsequent_bitrate_(0), |
686 requested_subsequent_framerate_(0) { | 694 requested_subsequent_framerate_(0) { |
687 if (keyframe_period_) | 695 if (keyframe_period_) |
688 CHECK_LT(kMaxKeyframeDelay, keyframe_period_); | 696 CHECK_LT(kMaxKeyframeDelay, keyframe_period_); |
689 | 697 |
690 validator_ = StreamValidator::Create( | 698 validator_ = StreamValidator::Create( |
691 test_stream_->requested_profile, | 699 test_stream_->requested_profile, |
692 base::Bind(&VEAClient::HandleEncodedFrame, base::Unretained(this))); | 700 base::Bind(&VEAClient::HandleEncodedFrame, base::Unretained(this))); |
693 | 701 |
694 CHECK(validator_.get()); | 702 |
| 703 CHECK(g_fake_encoder || validator_.get()); |
695 | 704 |
696 if (save_to_file_) { | 705 if (save_to_file_) { |
697 CHECK(!test_stream_->out_filename.empty()); | 706 CHECK(!test_stream_->out_filename.empty()); |
698 base::FilePath out_filename(test_stream_->out_filename); | 707 base::FilePath out_filename(test_stream_->out_filename); |
699 // This creates or truncates out_filename. | 708 // This creates or truncates out_filename. |
700 // Without it, AppendToFile() will not work. | 709 // Without it, AppendToFile() will not work. |
701 EXPECT_EQ(0, base::WriteFile(out_filename, NULL, 0)); | 710 EXPECT_EQ(0, base::WriteFile(out_filename, NULL, 0)); |
702 } | 711 } |
703 | 712 |
704 // Initialize the parameters of the test streams. | 713 // Initialize the parameters of the test streams. |
705 UpdateTestStreamData(mid_stream_bitrate_switch, mid_stream_framerate_switch); | 714 UpdateTestStreamData(mid_stream_bitrate_switch, mid_stream_framerate_switch); |
706 | 715 |
707 thread_checker_.DetachFromThread(); | 716 thread_checker_.DetachFromThread(); |
708 } | 717 } |
709 | 718 |
710 VEAClient::~VEAClient() { CHECK(!has_encoder()); } | 719 VEAClient::~VEAClient() { CHECK(!has_encoder()); } |
711 | 720 |
712 void VEAClient::CreateEncoder() { | 721 void VEAClient::CreateEncoder() { |
713 DCHECK(thread_checker_.CalledOnValidThread()); | 722 DCHECK(thread_checker_.CalledOnValidThread()); |
714 CHECK(!has_encoder()); | 723 CHECK(!has_encoder()); |
715 | 724 |
| 725 |
| 726 if (g_fake_encoder) { |
| 727 encoder_.reset( |
| 728 new media::FakeVideoEncodeAccelerator( |
| 729 base::MessageLoopProxy::current())); |
| 730 } else { |
716 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL) | 731 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL) |
717 scoped_ptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kEncoder); | 732 scoped_ptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kEncoder); |
718 encoder_.reset(new V4L2VideoEncodeAccelerator(device.Pass())); | 733 encoder_.reset(new V4L2VideoEncodeAccelerator(device.Pass())); |
719 #elif defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) && defined(USE_X11) | 734 #elif defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) && defined(USE_X11) |
720 encoder_.reset(new VaapiVideoEncodeAccelerator(gfx::GetXDisplay())); | 735 encoder_.reset(new VaapiVideoEncodeAccelerator(gfx::GetXDisplay())); |
721 #endif | 736 #endif |
| 737 } |
722 | 738 |
723 SetState(CS_ENCODER_SET); | 739 SetState(CS_ENCODER_SET); |
724 | 740 |
725 DVLOG(1) << "Profile: " << test_stream_->requested_profile | 741 DVLOG(1) << "Profile: " << test_stream_->requested_profile |
726 << ", initial bitrate: " << requested_bitrate_; | 742 << ", initial bitrate: " << requested_bitrate_; |
727 if (!encoder_->Initialize(kInputFormat, | 743 if (!encoder_->Initialize(kInputFormat, |
728 test_stream_->visible_size, | 744 test_stream_->visible_size, |
729 test_stream_->requested_profile, | 745 test_stream_->requested_profile, |
730 requested_bitrate_, | 746 requested_bitrate_, |
731 this)) { | 747 this)) { |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
845 base::SharedMemory* shm = it->second; | 861 base::SharedMemory* shm = it->second; |
846 output_buffers_at_client_.erase(it); | 862 output_buffers_at_client_.erase(it); |
847 | 863 |
848 if (state_ == CS_FINISHED) | 864 if (state_ == CS_FINISHED) |
849 return; | 865 return; |
850 | 866 |
851 encoded_stream_size_since_last_check_ += payload_size; | 867 encoded_stream_size_since_last_check_ += payload_size; |
852 | 868 |
853 const uint8* stream_ptr = static_cast<const uint8*>(shm->memory()); | 869 const uint8* stream_ptr = static_cast<const uint8*>(shm->memory()); |
854 if (payload_size > 0) { | 870 if (payload_size > 0) { |
855 validator_->ProcessStreamBuffer(stream_ptr, payload_size); | 871 if (validator_) { |
| 872 validator_->ProcessStreamBuffer(stream_ptr, payload_size); |
| 873 } else { |
| 874 HandleEncodedFrame(key_frame); |
| 875 } |
856 | 876 |
857 if (save_to_file_) { | 877 if (save_to_file_) { |
858 if (IsVP8(test_stream_->requested_profile)) | 878 if (IsVP8(test_stream_->requested_profile)) |
859 WriteIvfFrameHeader(num_encoded_frames_ - 1, payload_size); | 879 WriteIvfFrameHeader(num_encoded_frames_ - 1, payload_size); |
860 | 880 |
861 EXPECT_TRUE(base::AppendToFile( | 881 EXPECT_TRUE(base::AppendToFile( |
862 base::FilePath::FromUTF8Unsafe(test_stream_->out_filename), | 882 base::FilePath::FromUTF8Unsafe(test_stream_->out_filename), |
863 static_cast<char*>(shm->memory()), | 883 static_cast<char*>(shm->memory()), |
864 base::checked_cast<int>(payload_size))); | 884 base::checked_cast<int>(payload_size))); |
865 } | 885 } |
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1262 DCHECK(cmd_line); | 1282 DCHECK(cmd_line); |
1263 | 1283 |
1264 base::CommandLine::SwitchMap switches = cmd_line->GetSwitches(); | 1284 base::CommandLine::SwitchMap switches = cmd_line->GetSwitches(); |
1265 for (base::CommandLine::SwitchMap::const_iterator it = switches.begin(); | 1285 for (base::CommandLine::SwitchMap::const_iterator it = switches.begin(); |
1266 it != switches.end(); | 1286 it != switches.end(); |
1267 ++it) { | 1287 ++it) { |
1268 if (it->first == "test_stream_data") { | 1288 if (it->first == "test_stream_data") { |
1269 test_stream_data->assign(it->second.c_str()); | 1289 test_stream_data->assign(it->second.c_str()); |
1270 continue; | 1290 continue; |
1271 } | 1291 } |
| 1292 if (it->first == "fake_encoder") { |
| 1293 content::g_fake_encoder = true; |
| 1294 continue; |
| 1295 } |
1272 if (it->first == "v" || it->first == "vmodule") | 1296 if (it->first == "v" || it->first == "vmodule") |
1273 continue; | 1297 continue; |
1274 LOG(FATAL) << "Unexpected switch: " << it->first << ":" << it->second; | 1298 LOG(FATAL) << "Unexpected switch: " << it->first << ":" << it->second; |
1275 } | 1299 } |
1276 | 1300 |
1277 content::g_env = | 1301 content::g_env = |
1278 reinterpret_cast<content::VideoEncodeAcceleratorTestEnvironment*>( | 1302 reinterpret_cast<content::VideoEncodeAcceleratorTestEnvironment*>( |
1279 testing::AddGlobalTestEnvironment( | 1303 testing::AddGlobalTestEnvironment( |
1280 new content::VideoEncodeAcceleratorTestEnvironment( | 1304 new content::VideoEncodeAcceleratorTestEnvironment( |
1281 test_stream_data.Pass()))); | 1305 test_stream_data.Pass()))); |
1282 | 1306 |
1283 return RUN_ALL_TESTS(); | 1307 return RUN_ALL_TESTS(); |
1284 } | 1308 } |
OLD | NEW |