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 bool g_fake_encoder = false; | |
wuchengli
2014/12/11 02:14:31
Please document this.
hellner1
2014/12/11 19:34:19
Done.
| |
103 | |
100 // Environment to store test stream data for all test cases. | 104 // Environment to store test stream data for all test cases. |
101 class VideoEncodeAcceleratorTestEnvironment; | 105 class VideoEncodeAcceleratorTestEnvironment; |
102 VideoEncodeAcceleratorTestEnvironment* g_env; | 106 VideoEncodeAcceleratorTestEnvironment* g_env; |
103 | 107 |
104 struct IvfFileHeader { | 108 struct IvfFileHeader { |
105 char signature[4]; // signature: 'DKIF' | 109 char signature[4]; // signature: 'DKIF' |
106 uint16_t version; // version (should be 0) | 110 uint16_t version; // version (should be 0) |
107 uint16_t header_size; // size of header in bytes | 111 uint16_t header_size; // size of header in bytes |
108 uint32_t fourcc; // codec FourCC (e.g., 'VP80') | 112 uint32_t fourcc; // codec FourCC (e.g., 'VP80') |
109 uint16_t width; // width in pixels | 113 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 | 477 // 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. | 478 // partition numbers/sizes. For now assume one frame per buffer. |
475 } | 479 } |
476 | 480 |
477 // static | 481 // static |
478 scoped_ptr<StreamValidator> StreamValidator::Create( | 482 scoped_ptr<StreamValidator> StreamValidator::Create( |
479 media::VideoCodecProfile profile, | 483 media::VideoCodecProfile profile, |
480 const FrameFoundCallback& frame_cb) { | 484 const FrameFoundCallback& frame_cb) { |
481 scoped_ptr<StreamValidator> validator; | 485 scoped_ptr<StreamValidator> validator; |
482 | 486 |
483 if (IsH264(profile)) { | 487 if (g_fake_encoder) { |
488 validator.reset(NULL); | |
489 } else if (IsH264(profile)) { | |
484 validator.reset(new H264Validator(frame_cb)); | 490 validator.reset(new H264Validator(frame_cb)); |
485 } else if (IsVP8(profile)) { | 491 } else if (IsVP8(profile)) { |
486 validator.reset(new VP8Validator(frame_cb)); | 492 validator.reset(new VP8Validator(frame_cb)); |
487 } else { | 493 } else { |
488 LOG(FATAL) << "Unsupported profile: " << profile; | 494 LOG(FATAL) << "Unsupported profile: " << profile; |
489 } | 495 } |
490 | 496 |
491 return validator.Pass(); | 497 return validator.Pass(); |
492 } | 498 } |
493 | 499 |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
684 requested_framerate_(0), | 690 requested_framerate_(0), |
685 requested_subsequent_bitrate_(0), | 691 requested_subsequent_bitrate_(0), |
686 requested_subsequent_framerate_(0) { | 692 requested_subsequent_framerate_(0) { |
687 if (keyframe_period_) | 693 if (keyframe_period_) |
688 CHECK_LT(kMaxKeyframeDelay, keyframe_period_); | 694 CHECK_LT(kMaxKeyframeDelay, keyframe_period_); |
689 | 695 |
690 validator_ = StreamValidator::Create( | 696 validator_ = StreamValidator::Create( |
691 test_stream_->requested_profile, | 697 test_stream_->requested_profile, |
692 base::Bind(&VEAClient::HandleEncodedFrame, base::Unretained(this))); | 698 base::Bind(&VEAClient::HandleEncodedFrame, base::Unretained(this))); |
693 | 699 |
694 CHECK(validator_.get()); | 700 |
701 CHECK(g_fake_encoder || validator_.get()); | |
695 | 702 |
696 if (save_to_file_) { | 703 if (save_to_file_) { |
697 CHECK(!test_stream_->out_filename.empty()); | 704 CHECK(!test_stream_->out_filename.empty()); |
698 base::FilePath out_filename(test_stream_->out_filename); | 705 base::FilePath out_filename(test_stream_->out_filename); |
699 // This creates or truncates out_filename. | 706 // This creates or truncates out_filename. |
700 // Without it, AppendToFile() will not work. | 707 // Without it, AppendToFile() will not work. |
701 EXPECT_EQ(0, base::WriteFile(out_filename, NULL, 0)); | 708 EXPECT_EQ(0, base::WriteFile(out_filename, NULL, 0)); |
702 } | 709 } |
703 | 710 |
704 // Initialize the parameters of the test streams. | 711 // Initialize the parameters of the test streams. |
705 UpdateTestStreamData(mid_stream_bitrate_switch, mid_stream_framerate_switch); | 712 UpdateTestStreamData(mid_stream_bitrate_switch, mid_stream_framerate_switch); |
706 | 713 |
707 thread_checker_.DetachFromThread(); | 714 thread_checker_.DetachFromThread(); |
708 } | 715 } |
709 | 716 |
710 VEAClient::~VEAClient() { CHECK(!has_encoder()); } | 717 VEAClient::~VEAClient() { CHECK(!has_encoder()); } |
711 | 718 |
712 void VEAClient::CreateEncoder() { | 719 void VEAClient::CreateEncoder() { |
713 DCHECK(thread_checker_.CalledOnValidThread()); | 720 DCHECK(thread_checker_.CalledOnValidThread()); |
714 CHECK(!has_encoder()); | 721 CHECK(!has_encoder()); |
715 | 722 |
723 | |
724 if (g_fake_encoder) { | |
725 encoder_.reset( | |
726 new media::FakeVideoEncodeAccelerator( | |
727 scoped_refptr<base::SingleThreadTaskRunner>( | |
728 base::MessageLoopProxy::current()))); | |
729 } else { | |
716 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL) | 730 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL) |
717 scoped_ptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kEncoder); | 731 scoped_ptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kEncoder); |
718 encoder_.reset(new V4L2VideoEncodeAccelerator(device.Pass())); | 732 encoder_.reset(new V4L2VideoEncodeAccelerator(device.Pass())); |
719 #elif defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) && defined(USE_X11) | 733 #elif defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) && defined(USE_X11) |
720 encoder_.reset(new VaapiVideoEncodeAccelerator(gfx::GetXDisplay())); | 734 encoder_.reset(new VaapiVideoEncodeAccelerator(gfx::GetXDisplay())); |
721 #endif | 735 #endif |
736 } | |
722 | 737 |
723 SetState(CS_ENCODER_SET); | 738 SetState(CS_ENCODER_SET); |
724 | 739 |
725 DVLOG(1) << "Profile: " << test_stream_->requested_profile | 740 DVLOG(1) << "Profile: " << test_stream_->requested_profile |
726 << ", initial bitrate: " << requested_bitrate_; | 741 << ", initial bitrate: " << requested_bitrate_; |
727 if (!encoder_->Initialize(kInputFormat, | 742 if (!encoder_->Initialize(kInputFormat, |
728 test_stream_->visible_size, | 743 test_stream_->visible_size, |
729 test_stream_->requested_profile, | 744 test_stream_->requested_profile, |
730 requested_bitrate_, | 745 requested_bitrate_, |
731 this)) { | 746 this)) { |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
845 base::SharedMemory* shm = it->second; | 860 base::SharedMemory* shm = it->second; |
846 output_buffers_at_client_.erase(it); | 861 output_buffers_at_client_.erase(it); |
847 | 862 |
848 if (state_ == CS_FINISHED) | 863 if (state_ == CS_FINISHED) |
849 return; | 864 return; |
850 | 865 |
851 encoded_stream_size_since_last_check_ += payload_size; | 866 encoded_stream_size_since_last_check_ += payload_size; |
852 | 867 |
853 const uint8* stream_ptr = static_cast<const uint8*>(shm->memory()); | 868 const uint8* stream_ptr = static_cast<const uint8*>(shm->memory()); |
854 if (payload_size > 0) { | 869 if (payload_size > 0) { |
855 validator_->ProcessStreamBuffer(stream_ptr, payload_size); | 870 if (validator_) { |
871 validator_->ProcessStreamBuffer(stream_ptr, payload_size); | |
872 } else { | |
873 HandleEncodedFrame(key_frame); | |
874 } | |
856 | 875 |
857 if (save_to_file_) { | 876 if (save_to_file_) { |
858 if (IsVP8(test_stream_->requested_profile)) | 877 if (IsVP8(test_stream_->requested_profile)) |
859 WriteIvfFrameHeader(num_encoded_frames_ - 1, payload_size); | 878 WriteIvfFrameHeader(num_encoded_frames_ - 1, payload_size); |
860 | 879 |
861 EXPECT_TRUE(base::AppendToFile( | 880 EXPECT_TRUE(base::AppendToFile( |
862 base::FilePath::FromUTF8Unsafe(test_stream_->out_filename), | 881 base::FilePath::FromUTF8Unsafe(test_stream_->out_filename), |
863 static_cast<char*>(shm->memory()), | 882 static_cast<char*>(shm->memory()), |
864 base::checked_cast<int>(payload_size))); | 883 base::checked_cast<int>(payload_size))); |
865 } | 884 } |
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1262 DCHECK(cmd_line); | 1281 DCHECK(cmd_line); |
1263 | 1282 |
1264 base::CommandLine::SwitchMap switches = cmd_line->GetSwitches(); | 1283 base::CommandLine::SwitchMap switches = cmd_line->GetSwitches(); |
1265 for (base::CommandLine::SwitchMap::const_iterator it = switches.begin(); | 1284 for (base::CommandLine::SwitchMap::const_iterator it = switches.begin(); |
1266 it != switches.end(); | 1285 it != switches.end(); |
1267 ++it) { | 1286 ++it) { |
1268 if (it->first == "test_stream_data") { | 1287 if (it->first == "test_stream_data") { |
1269 test_stream_data->assign(it->second.c_str()); | 1288 test_stream_data->assign(it->second.c_str()); |
1270 continue; | 1289 continue; |
1271 } | 1290 } |
1291 if (it->first == "fake_encoder") { | |
1292 content::g_fake_encoder = true; | |
1293 continue; | |
1294 } | |
1272 if (it->first == "v" || it->first == "vmodule") | 1295 if (it->first == "v" || it->first == "vmodule") |
1273 continue; | 1296 continue; |
1274 LOG(FATAL) << "Unexpected switch: " << it->first << ":" << it->second; | 1297 LOG(FATAL) << "Unexpected switch: " << it->first << ":" << it->second; |
1275 } | 1298 } |
1276 | 1299 |
1277 content::g_env = | 1300 content::g_env = |
1278 reinterpret_cast<content::VideoEncodeAcceleratorTestEnvironment*>( | 1301 reinterpret_cast<content::VideoEncodeAcceleratorTestEnvironment*>( |
1279 testing::AddGlobalTestEnvironment( | 1302 testing::AddGlobalTestEnvironment( |
1280 new content::VideoEncodeAcceleratorTestEnvironment( | 1303 new content::VideoEncodeAcceleratorTestEnvironment( |
1281 test_stream_data.Pass()))); | 1304 test_stream_data.Pass()))); |
1282 | 1305 |
1283 return RUN_ALL_TESTS(); | 1306 return RUN_ALL_TESTS(); |
1284 } | 1307 } |
OLD | NEW |