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 "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) | 31 #if defined(OS_CHROMEOS) |
31 #if defined(ARCH_CPU_ARMEL) || (defined(USE_OZONE) && defined(USE_V4L2_CODEC)) | 32 #if defined(ARCH_CPU_ARMEL) || (defined(USE_OZONE) && defined(USE_V4L2_CODEC)) |
32 #include "content/common/gpu/media/v4l2_video_encode_accelerator.h" | 33 #include "content/common/gpu/media/v4l2_video_encode_accelerator.h" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 // parameters if a specific subsequent parameter is required): | 95 // parameters if a specific subsequent parameter is required): |
95 // - |requested_bitrate| requested bitrate in bits per second. | 96 // - |requested_bitrate| requested bitrate in bits per second. |
96 // - |requested_framerate| requested initial framerate. | 97 // - |requested_framerate| requested initial framerate. |
97 // - |requested_subsequent_bitrate| bitrate to switch to in the middle of the | 98 // - |requested_subsequent_bitrate| bitrate to switch to in the middle of the |
98 // stream. | 99 // stream. |
99 // - |requested_subsequent_framerate| framerate to switch to in the middle | 100 // - |requested_subsequent_framerate| framerate to switch to in the middle |
100 // of the stream. | 101 // of the stream. |
101 // Bitrate is only forced for tests that test bitrate. | 102 // Bitrate is only forced for tests that test bitrate. |
102 const char* g_default_in_filename = "bear_320x192_40frames.yuv"; | 103 const char* g_default_in_filename = "bear_320x192_40frames.yuv"; |
103 const char* g_default_in_parameters = ":320:192:1:out.h264:200000"; | 104 const char* g_default_in_parameters = ":320:192:1:out.h264:200000"; |
| 105 |
| 106 // Enabled by including a --fake_encoder flag to the command line invoking the |
| 107 // test. |
| 108 bool g_fake_encoder = false; |
| 109 |
104 // Environment to store test stream data for all test cases. | 110 // Environment to store test stream data for all test cases. |
105 class VideoEncodeAcceleratorTestEnvironment; | 111 class VideoEncodeAcceleratorTestEnvironment; |
106 VideoEncodeAcceleratorTestEnvironment* g_env; | 112 VideoEncodeAcceleratorTestEnvironment* g_env; |
107 | 113 |
108 struct IvfFileHeader { | 114 struct IvfFileHeader { |
109 char signature[4]; // signature: 'DKIF' | 115 char signature[4]; // signature: 'DKIF' |
110 uint16_t version; // version (should be 0) | 116 uint16_t version; // version (should be 0) |
111 uint16_t header_size; // size of header in bytes | 117 uint16_t header_size; // size of header in bytes |
112 uint32_t fourcc; // codec FourCC (e.g., 'VP80') | 118 uint32_t fourcc; // codec FourCC (e.g., 'VP80') |
113 uint16_t width; // width in pixels | 119 uint16_t width; // width in pixels |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
481 // no simple way to detect this. We'd need to parse the frames and go through | 487 // no simple way to detect this. We'd need to parse the frames and go through |
482 // partition numbers/sizes. For now assume one frame per buffer. | 488 // partition numbers/sizes. For now assume one frame per buffer. |
483 } | 489 } |
484 | 490 |
485 // static | 491 // static |
486 scoped_ptr<StreamValidator> StreamValidator::Create( | 492 scoped_ptr<StreamValidator> StreamValidator::Create( |
487 media::VideoCodecProfile profile, | 493 media::VideoCodecProfile profile, |
488 const FrameFoundCallback& frame_cb) { | 494 const FrameFoundCallback& frame_cb) { |
489 scoped_ptr<StreamValidator> validator; | 495 scoped_ptr<StreamValidator> validator; |
490 | 496 |
491 if (IsH264(profile)) { | 497 if (g_fake_encoder) { |
| 498 validator.reset(NULL); |
| 499 } else if (IsH264(profile)) { |
492 validator.reset(new H264Validator(frame_cb)); | 500 validator.reset(new H264Validator(frame_cb)); |
493 } else if (IsVP8(profile)) { | 501 } else if (IsVP8(profile)) { |
494 validator.reset(new VP8Validator(frame_cb)); | 502 validator.reset(new VP8Validator(frame_cb)); |
495 } else { | 503 } else { |
496 LOG(FATAL) << "Unsupported profile: " << profile; | 504 LOG(FATAL) << "Unsupported profile: " << profile; |
497 } | 505 } |
498 | 506 |
499 return validator.Pass(); | 507 return validator.Pass(); |
500 } | 508 } |
501 | 509 |
(...skipping 20 matching lines...) Expand all Loading... |
522 const gfx::Size& input_coded_size, | 530 const gfx::Size& input_coded_size, |
523 size_t output_buffer_size) override; | 531 size_t output_buffer_size) override; |
524 virtual void BitstreamBufferReady(int32 bitstream_buffer_id, | 532 virtual void BitstreamBufferReady(int32 bitstream_buffer_id, |
525 size_t payload_size, | 533 size_t payload_size, |
526 bool key_frame) override; | 534 bool key_frame) override; |
527 virtual void NotifyError(VideoEncodeAccelerator::Error error) override; | 535 virtual void NotifyError(VideoEncodeAccelerator::Error error) override; |
528 | 536 |
529 private: | 537 private: |
530 bool has_encoder() { return encoder_.get(); } | 538 bool has_encoder() { return encoder_.get(); } |
531 | 539 |
| 540 scoped_ptr<media::VideoEncodeAccelerator> CreateFakeVEA(); |
532 scoped_ptr<media::VideoEncodeAccelerator> CreateV4L2VEA(); | 541 scoped_ptr<media::VideoEncodeAccelerator> CreateV4L2VEA(); |
533 scoped_ptr<media::VideoEncodeAccelerator> CreateVaapiVEA(); | 542 scoped_ptr<media::VideoEncodeAccelerator> CreateVaapiVEA(); |
534 | 543 |
535 void SetState(ClientState new_state); | 544 void SetState(ClientState new_state); |
536 | 545 |
537 // Set current stream parameters to given |bitrate| at |framerate|. | 546 // Set current stream parameters to given |bitrate| at |framerate|. |
538 void SetStreamParameters(unsigned int bitrate, unsigned int framerate); | 547 void SetStreamParameters(unsigned int bitrate, unsigned int framerate); |
539 | 548 |
540 // Called when encoder is done with a VideoFrame. | 549 // Called when encoder is done with a VideoFrame. |
541 void InputNoLongerNeededCallback(int32 input_id); | 550 void InputNoLongerNeededCallback(int32 input_id); |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
709 requested_subsequent_bitrate_(0), | 718 requested_subsequent_bitrate_(0), |
710 requested_subsequent_framerate_(0), | 719 requested_subsequent_framerate_(0), |
711 run_at_fps_(run_at_fps) { | 720 run_at_fps_(run_at_fps) { |
712 if (keyframe_period_) | 721 if (keyframe_period_) |
713 CHECK_LT(kMaxKeyframeDelay, keyframe_period_); | 722 CHECK_LT(kMaxKeyframeDelay, keyframe_period_); |
714 | 723 |
715 validator_ = StreamValidator::Create( | 724 validator_ = StreamValidator::Create( |
716 test_stream_->requested_profile, | 725 test_stream_->requested_profile, |
717 base::Bind(&VEAClient::HandleEncodedFrame, base::Unretained(this))); | 726 base::Bind(&VEAClient::HandleEncodedFrame, base::Unretained(this))); |
718 | 727 |
719 CHECK(validator_.get()); | 728 |
| 729 CHECK(g_fake_encoder || validator_.get()); |
720 | 730 |
721 if (save_to_file_) { | 731 if (save_to_file_) { |
722 CHECK(!test_stream_->out_filename.empty()); | 732 CHECK(!test_stream_->out_filename.empty()); |
723 base::FilePath out_filename(test_stream_->out_filename); | 733 base::FilePath out_filename(test_stream_->out_filename); |
724 // This creates or truncates out_filename. | 734 // This creates or truncates out_filename. |
725 // Without it, AppendToFile() will not work. | 735 // Without it, AppendToFile() will not work. |
726 EXPECT_EQ(0, base::WriteFile(out_filename, NULL, 0)); | 736 EXPECT_EQ(0, base::WriteFile(out_filename, NULL, 0)); |
727 } | 737 } |
728 | 738 |
729 // Initialize the parameters of the test streams. | 739 // Initialize the parameters of the test streams. |
730 UpdateTestStreamData(mid_stream_bitrate_switch, mid_stream_framerate_switch); | 740 UpdateTestStreamData(mid_stream_bitrate_switch, mid_stream_framerate_switch); |
731 | 741 |
732 thread_checker_.DetachFromThread(); | 742 thread_checker_.DetachFromThread(); |
733 } | 743 } |
734 | 744 |
735 VEAClient::~VEAClient() { CHECK(!has_encoder()); } | 745 VEAClient::~VEAClient() { CHECK(!has_encoder()); } |
736 | 746 |
| 747 scoped_ptr<media::VideoEncodeAccelerator> VEAClient::CreateFakeVEA() { |
| 748 scoped_ptr<media::VideoEncodeAccelerator> encoder; |
| 749 if (g_fake_encoder) { |
| 750 encoder.reset( |
| 751 new media::FakeVideoEncodeAccelerator( |
| 752 scoped_refptr<base::SingleThreadTaskRunner>( |
| 753 base::MessageLoopProxy::current()))); |
| 754 } |
| 755 return encoder.Pass(); |
| 756 } |
| 757 |
737 scoped_ptr<media::VideoEncodeAccelerator> VEAClient::CreateV4L2VEA() { | 758 scoped_ptr<media::VideoEncodeAccelerator> VEAClient::CreateV4L2VEA() { |
738 scoped_ptr<media::VideoEncodeAccelerator> encoder; | 759 scoped_ptr<media::VideoEncodeAccelerator> encoder; |
739 #if defined(OS_CHROMEOS) && (defined(ARCH_CPU_ARMEL) || \ | 760 #if defined(OS_CHROMEOS) && (defined(ARCH_CPU_ARMEL) || \ |
740 (defined(USE_OZONE) && defined(USE_V4L2_CODEC))) | 761 (defined(USE_OZONE) && defined(USE_V4L2_CODEC))) |
741 scoped_refptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kEncoder); | 762 scoped_refptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kEncoder); |
742 if (device) | 763 if (device) |
743 encoder.reset(new V4L2VideoEncodeAccelerator(device)); | 764 encoder.reset(new V4L2VideoEncodeAccelerator(device)); |
744 #endif | 765 #endif |
745 return encoder.Pass(); | 766 return encoder.Pass(); |
746 } | 767 } |
747 | 768 |
748 scoped_ptr<media::VideoEncodeAccelerator> VEAClient::CreateVaapiVEA() { | 769 scoped_ptr<media::VideoEncodeAccelerator> VEAClient::CreateVaapiVEA() { |
749 scoped_ptr<media::VideoEncodeAccelerator> encoder; | 770 scoped_ptr<media::VideoEncodeAccelerator> encoder; |
750 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) | 771 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) |
751 encoder.reset(new VaapiVideoEncodeAccelerator()); | 772 encoder.reset(new VaapiVideoEncodeAccelerator()); |
752 #endif | 773 #endif |
753 return encoder.Pass(); | 774 return encoder.Pass(); |
754 } | 775 } |
755 | 776 |
756 void VEAClient::CreateEncoder() { | 777 void VEAClient::CreateEncoder() { |
757 DCHECK(thread_checker_.CalledOnValidThread()); | 778 DCHECK(thread_checker_.CalledOnValidThread()); |
758 CHECK(!has_encoder()); | 779 CHECK(!has_encoder()); |
759 | 780 |
760 scoped_ptr<media::VideoEncodeAccelerator> encoders[] = { | 781 scoped_ptr<media::VideoEncodeAccelerator> encoders[] = { |
| 782 CreateFakeVEA(), |
761 CreateV4L2VEA(), | 783 CreateV4L2VEA(), |
762 CreateVaapiVEA() | 784 CreateVaapiVEA() |
763 }; | 785 }; |
764 | 786 |
765 DVLOG(1) << "Profile: " << test_stream_->requested_profile | 787 DVLOG(1) << "Profile: " << test_stream_->requested_profile |
766 << ", initial bitrate: " << requested_bitrate_; | 788 << ", initial bitrate: " << requested_bitrate_; |
767 | 789 |
768 for (size_t i = 0; i < arraysize(encoders); ++i) { | 790 for (size_t i = 0; i < arraysize(encoders); ++i) { |
769 if (!encoders[i]) | 791 if (!encoders[i]) |
770 continue; | 792 continue; |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
904 base::SharedMemory* shm = it->second; | 926 base::SharedMemory* shm = it->second; |
905 output_buffers_at_client_.erase(it); | 927 output_buffers_at_client_.erase(it); |
906 | 928 |
907 if (state_ == CS_FINISHED) | 929 if (state_ == CS_FINISHED) |
908 return; | 930 return; |
909 | 931 |
910 encoded_stream_size_since_last_check_ += payload_size; | 932 encoded_stream_size_since_last_check_ += payload_size; |
911 | 933 |
912 const uint8* stream_ptr = static_cast<const uint8*>(shm->memory()); | 934 const uint8* stream_ptr = static_cast<const uint8*>(shm->memory()); |
913 if (payload_size > 0) { | 935 if (payload_size > 0) { |
914 validator_->ProcessStreamBuffer(stream_ptr, payload_size); | 936 if (validator_) { |
| 937 validator_->ProcessStreamBuffer(stream_ptr, payload_size); |
| 938 } else { |
| 939 HandleEncodedFrame(key_frame); |
| 940 } |
915 | 941 |
916 if (save_to_file_) { | 942 if (save_to_file_) { |
917 if (IsVP8(test_stream_->requested_profile)) | 943 if (IsVP8(test_stream_->requested_profile)) |
918 WriteIvfFrameHeader(num_encoded_frames_ - 1, payload_size); | 944 WriteIvfFrameHeader(num_encoded_frames_ - 1, payload_size); |
919 | 945 |
920 EXPECT_TRUE(base::AppendToFile( | 946 EXPECT_TRUE(base::AppendToFile( |
921 base::FilePath::FromUTF8Unsafe(test_stream_->out_filename), | 947 base::FilePath::FromUTF8Unsafe(test_stream_->out_filename), |
922 static_cast<char*>(shm->memory()), | 948 static_cast<char*>(shm->memory()), |
923 base::checked_cast<int>(payload_size))); | 949 base::checked_cast<int>(payload_size))); |
924 } | 950 } |
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1345 for (base::CommandLine::SwitchMap::const_iterator it = switches.begin(); | 1371 for (base::CommandLine::SwitchMap::const_iterator it = switches.begin(); |
1346 it != switches.end(); | 1372 it != switches.end(); |
1347 ++it) { | 1373 ++it) { |
1348 if (it->first == "test_stream_data") { | 1374 if (it->first == "test_stream_data") { |
1349 test_stream_data->assign(it->second.c_str()); | 1375 test_stream_data->assign(it->second.c_str()); |
1350 continue; | 1376 continue; |
1351 } | 1377 } |
1352 if (it->first == "num_frames_to_encode") { | 1378 if (it->first == "num_frames_to_encode") { |
1353 std::string input(it->second.begin(), it->second.end()); | 1379 std::string input(it->second.begin(), it->second.end()); |
1354 CHECK(base::StringToInt(input, &content::g_num_frames_to_encode)); | 1380 CHECK(base::StringToInt(input, &content::g_num_frames_to_encode)); |
| 1381 } |
| 1382 if (it->first == "fake_encoder") { |
| 1383 content::g_fake_encoder = true; |
1355 continue; | 1384 continue; |
1356 } | 1385 } |
1357 if (it->first == "run_at_fps") { | 1386 if (it->first == "run_at_fps") { |
1358 run_at_fps = true; | 1387 run_at_fps = true; |
1359 continue; | 1388 continue; |
1360 } | 1389 } |
1361 if (it->first == "v" || it->first == "vmodule") | 1390 if (it->first == "v" || it->first == "vmodule") |
1362 continue; | 1391 continue; |
1363 if (it->first == "ozone-platform" || it->first == "ozone-use-surfaceless") | 1392 if (it->first == "ozone-platform" || it->first == "ozone-use-surfaceless") |
1364 continue; | 1393 continue; |
1365 LOG(FATAL) << "Unexpected switch: " << it->first << ":" << it->second; | 1394 LOG(FATAL) << "Unexpected switch: " << it->first << ":" << it->second; |
1366 } | 1395 } |
1367 | 1396 |
1368 content::g_env = | 1397 content::g_env = |
1369 reinterpret_cast<content::VideoEncodeAcceleratorTestEnvironment*>( | 1398 reinterpret_cast<content::VideoEncodeAcceleratorTestEnvironment*>( |
1370 testing::AddGlobalTestEnvironment( | 1399 testing::AddGlobalTestEnvironment( |
1371 new content::VideoEncodeAcceleratorTestEnvironment( | 1400 new content::VideoEncodeAcceleratorTestEnvironment( |
1372 test_stream_data.Pass(), run_at_fps))); | 1401 test_stream_data.Pass(), run_at_fps))); |
1373 | 1402 |
1374 return RUN_ALL_TESTS(); | 1403 return RUN_ALL_TESTS(); |
1375 } | 1404 } |
OLD | NEW |