| 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 <inttypes.h> | 5 #include <inttypes.h> |
| 6 #include <stddef.h> | 6 #include <stddef.h> |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | |
| 9 #include <algorithm> | 8 #include <algorithm> |
| 10 #include <queue> | 9 #include <queue> |
| 11 #include <string> | 10 #include <string> |
| 11 #include <utility> |
| 12 | 12 |
| 13 #include "base/at_exit.h" | 13 #include "base/at_exit.h" |
| 14 #include "base/bind.h" | 14 #include "base/bind.h" |
| 15 #include "base/command_line.h" | 15 #include "base/command_line.h" |
| 16 #include "base/files/file_util.h" | 16 #include "base/files/file_util.h" |
| 17 #include "base/files/memory_mapped_file.h" | 17 #include "base/files/memory_mapped_file.h" |
| 18 #include "base/macros.h" | 18 #include "base/macros.h" |
| 19 #include "base/memory/scoped_vector.h" | 19 #include "base/memory/scoped_vector.h" |
| 20 #include "base/message_loop/message_loop.h" | 20 #include "base/message_loop/message_loop.h" |
| 21 #include "base/numerics/safe_conversions.h" | 21 #include "base/numerics/safe_conversions.h" |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 src += visible_bpl[i]; | 303 src += visible_bpl[i]; |
| 304 dest_offset += coded_bpl[i]; | 304 dest_offset += coded_bpl[i]; |
| 305 } | 305 } |
| 306 if (!padding[i].empty()) { | 306 if (!padding[i].empty()) { |
| 307 LOG_ASSERT(WriteFile(&dest_file, dest_offset, &padding[i][0], | 307 LOG_ASSERT(WriteFile(&dest_file, dest_offset, &padding[i][0], |
| 308 padding[i].size())); | 308 padding[i].size())); |
| 309 dest_offset += padding[i].size(); | 309 dest_offset += padding[i].size(); |
| 310 } | 310 } |
| 311 } | 311 } |
| 312 } | 312 } |
| 313 LOG_ASSERT(test_stream->mapped_aligned_in_file.Initialize(dest_file.Pass())); | 313 LOG_ASSERT( |
| 314 test_stream->mapped_aligned_in_file.Initialize(std::move(dest_file))); |
| 314 // Assert that memory mapped of file starts at 64 byte boundary. So each | 315 // Assert that memory mapped of file starts at 64 byte boundary. So each |
| 315 // plane of frames also start at 64 byte boundary. | 316 // plane of frames also start at 64 byte boundary. |
| 316 | 317 |
| 317 ASSERT_EQ( | 318 ASSERT_EQ( |
| 318 reinterpret_cast<off_t>(test_stream->mapped_aligned_in_file.data()) & 63, | 319 reinterpret_cast<off_t>(test_stream->mapped_aligned_in_file.data()) & 63, |
| 319 0) | 320 0) |
| 320 << "File should be mapped at a 64 byte boundary"; | 321 << "File should be mapped at a 64 byte boundary"; |
| 321 | 322 |
| 322 LOG_ASSERT(test_stream->mapped_aligned_in_file.length() % | 323 LOG_ASSERT(test_stream->mapped_aligned_in_file.length() % |
| 323 test_stream->aligned_buffer_size == 0U) | 324 test_stream->aligned_buffer_size == 0U) |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 // - clean up temporary aligned files. | 392 // - clean up temporary aligned files. |
| 392 // - output log to file. | 393 // - output log to file. |
| 393 class VideoEncodeAcceleratorTestEnvironment : public ::testing::Environment { | 394 class VideoEncodeAcceleratorTestEnvironment : public ::testing::Environment { |
| 394 public: | 395 public: |
| 395 VideoEncodeAcceleratorTestEnvironment( | 396 VideoEncodeAcceleratorTestEnvironment( |
| 396 scoped_ptr<base::FilePath::StringType> data, | 397 scoped_ptr<base::FilePath::StringType> data, |
| 397 const base::FilePath& log_path, | 398 const base::FilePath& log_path, |
| 398 bool run_at_fps, | 399 bool run_at_fps, |
| 399 bool needs_encode_latency, | 400 bool needs_encode_latency, |
| 400 bool verify_all_output) | 401 bool verify_all_output) |
| 401 : test_stream_data_(data.Pass()), | 402 : test_stream_data_(std::move(data)), |
| 402 log_path_(log_path), | 403 log_path_(log_path), |
| 403 run_at_fps_(run_at_fps), | 404 run_at_fps_(run_at_fps), |
| 404 needs_encode_latency_(needs_encode_latency), | 405 needs_encode_latency_(needs_encode_latency), |
| 405 verify_all_output_(verify_all_output) {} | 406 verify_all_output_(verify_all_output) {} |
| 406 | 407 |
| 407 virtual void SetUp() { | 408 virtual void SetUp() { |
| 408 if (!log_path_.empty()) { | 409 if (!log_path_.empty()) { |
| 409 log_file_.reset(new base::File( | 410 log_file_.reset(new base::File( |
| 410 log_path_, base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE)); | 411 log_path_, base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE)); |
| 411 LOG_ASSERT(log_file_->IsValid()); | 412 LOG_ASSERT(log_file_->IsValid()); |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 598 scoped_ptr<StreamValidator> validator; | 599 scoped_ptr<StreamValidator> validator; |
| 599 | 600 |
| 600 if (IsH264(profile)) { | 601 if (IsH264(profile)) { |
| 601 validator.reset(new H264Validator(frame_cb)); | 602 validator.reset(new H264Validator(frame_cb)); |
| 602 } else if (IsVP8(profile)) { | 603 } else if (IsVP8(profile)) { |
| 603 validator.reset(new VP8Validator(frame_cb)); | 604 validator.reset(new VP8Validator(frame_cb)); |
| 604 } else { | 605 } else { |
| 605 LOG(FATAL) << "Unsupported profile: " << profile; | 606 LOG(FATAL) << "Unsupported profile: " << profile; |
| 606 } | 607 } |
| 607 | 608 |
| 608 return validator.Pass(); | 609 return validator; |
| 609 } | 610 } |
| 610 | 611 |
| 611 class VideoFrameQualityValidator { | 612 class VideoFrameQualityValidator { |
| 612 public: | 613 public: |
| 613 VideoFrameQualityValidator(const media::VideoCodecProfile profile, | 614 VideoFrameQualityValidator(const media::VideoCodecProfile profile, |
| 614 const base::Closure& flush_complete_cb, | 615 const base::Closure& flush_complete_cb, |
| 615 const base::Closure& decode_error_cb); | 616 const base::Closure& decode_error_cb); |
| 616 void Initialize(const gfx::Size& coded_size, const gfx::Rect& visible_size); | 617 void Initialize(const gfx::Size& coded_size, const gfx::Rect& visible_size); |
| 617 // Save original YUV frame to compare it with the decoded frame later. | 618 // Save original YUV frame to compare it with the decoded frame later. |
| 618 void AddOriginalFrame(scoped_refptr<media::VideoFrame> frame); | 619 void AddOriginalFrame(scoped_refptr<media::VideoFrame> frame); |
| (...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1041 | 1042 |
| 1042 VEAClient::~VEAClient() { LOG_ASSERT(!has_encoder()); } | 1043 VEAClient::~VEAClient() { LOG_ASSERT(!has_encoder()); } |
| 1043 | 1044 |
| 1044 scoped_ptr<media::VideoEncodeAccelerator> VEAClient::CreateFakeVEA() { | 1045 scoped_ptr<media::VideoEncodeAccelerator> VEAClient::CreateFakeVEA() { |
| 1045 scoped_ptr<media::VideoEncodeAccelerator> encoder; | 1046 scoped_ptr<media::VideoEncodeAccelerator> encoder; |
| 1046 if (g_fake_encoder) { | 1047 if (g_fake_encoder) { |
| 1047 encoder.reset(new media::FakeVideoEncodeAccelerator( | 1048 encoder.reset(new media::FakeVideoEncodeAccelerator( |
| 1048 scoped_refptr<base::SingleThreadTaskRunner>( | 1049 scoped_refptr<base::SingleThreadTaskRunner>( |
| 1049 base::ThreadTaskRunnerHandle::Get()))); | 1050 base::ThreadTaskRunnerHandle::Get()))); |
| 1050 } | 1051 } |
| 1051 return encoder.Pass(); | 1052 return encoder; |
| 1052 } | 1053 } |
| 1053 | 1054 |
| 1054 scoped_ptr<media::VideoEncodeAccelerator> VEAClient::CreateV4L2VEA() { | 1055 scoped_ptr<media::VideoEncodeAccelerator> VEAClient::CreateV4L2VEA() { |
| 1055 scoped_ptr<media::VideoEncodeAccelerator> encoder; | 1056 scoped_ptr<media::VideoEncodeAccelerator> encoder; |
| 1056 #if defined(OS_CHROMEOS) && (defined(ARCH_CPU_ARMEL) || \ | 1057 #if defined(OS_CHROMEOS) && (defined(ARCH_CPU_ARMEL) || \ |
| 1057 (defined(USE_OZONE) && defined(USE_V4L2_CODEC))) | 1058 (defined(USE_OZONE) && defined(USE_V4L2_CODEC))) |
| 1058 scoped_refptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kEncoder); | 1059 scoped_refptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kEncoder); |
| 1059 if (device) | 1060 if (device) |
| 1060 encoder.reset(new V4L2VideoEncodeAccelerator(device)); | 1061 encoder.reset(new V4L2VideoEncodeAccelerator(device)); |
| 1061 #endif | 1062 #endif |
| 1062 return encoder.Pass(); | 1063 return encoder; |
| 1063 } | 1064 } |
| 1064 | 1065 |
| 1065 scoped_ptr<media::VideoEncodeAccelerator> VEAClient::CreateVaapiVEA() { | 1066 scoped_ptr<media::VideoEncodeAccelerator> VEAClient::CreateVaapiVEA() { |
| 1066 scoped_ptr<media::VideoEncodeAccelerator> encoder; | 1067 scoped_ptr<media::VideoEncodeAccelerator> encoder; |
| 1067 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) | 1068 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) |
| 1068 encoder.reset(new VaapiVideoEncodeAccelerator()); | 1069 encoder.reset(new VaapiVideoEncodeAccelerator()); |
| 1069 #endif | 1070 #endif |
| 1070 return encoder.Pass(); | 1071 return encoder; |
| 1071 } | 1072 } |
| 1072 | 1073 |
| 1073 void VEAClient::CreateEncoder() { | 1074 void VEAClient::CreateEncoder() { |
| 1074 DCHECK(thread_checker_.CalledOnValidThread()); | 1075 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1075 LOG_ASSERT(!has_encoder()); | 1076 LOG_ASSERT(!has_encoder()); |
| 1076 | 1077 |
| 1077 scoped_ptr<media::VideoEncodeAccelerator> encoders[] = { | 1078 scoped_ptr<media::VideoEncodeAccelerator> encoders[] = { |
| 1078 CreateFakeVEA(), | 1079 CreateFakeVEA(), |
| 1079 CreateV4L2VEA(), | 1080 CreateV4L2VEA(), |
| 1080 CreateVaapiVEA() | 1081 CreateVaapiVEA() |
| 1081 }; | 1082 }; |
| 1082 | 1083 |
| 1083 DVLOG(1) << "Profile: " << test_stream_->requested_profile | 1084 DVLOG(1) << "Profile: " << test_stream_->requested_profile |
| 1084 << ", initial bitrate: " << requested_bitrate_; | 1085 << ", initial bitrate: " << requested_bitrate_; |
| 1085 | 1086 |
| 1086 for (size_t i = 0; i < arraysize(encoders); ++i) { | 1087 for (size_t i = 0; i < arraysize(encoders); ++i) { |
| 1087 if (!encoders[i]) | 1088 if (!encoders[i]) |
| 1088 continue; | 1089 continue; |
| 1089 encoder_ = encoders[i].Pass(); | 1090 encoder_ = std::move(encoders[i]); |
| 1090 SetState(CS_ENCODER_SET); | 1091 SetState(CS_ENCODER_SET); |
| 1091 if (encoder_->Initialize(kInputFormat, | 1092 if (encoder_->Initialize(kInputFormat, |
| 1092 test_stream_->visible_size, | 1093 test_stream_->visible_size, |
| 1093 test_stream_->requested_profile, | 1094 test_stream_->requested_profile, |
| 1094 requested_bitrate_, | 1095 requested_bitrate_, |
| 1095 this)) { | 1096 this)) { |
| 1096 SetStreamParameters(requested_bitrate_, requested_framerate_); | 1097 SetStreamParameters(requested_bitrate_, requested_framerate_); |
| 1097 SetState(CS_INITIALIZED); | 1098 SetState(CS_INITIALIZED); |
| 1098 | 1099 |
| 1099 if (verify_output_ && !g_fake_encoder) | 1100 if (verify_output_ && !g_fake_encoder) |
| (...skipping 672 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1772 } | 1773 } |
| 1773 | 1774 |
| 1774 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) | 1775 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) |
| 1775 content::VaapiWrapper::PreSandboxInitialization(); | 1776 content::VaapiWrapper::PreSandboxInitialization(); |
| 1776 #endif | 1777 #endif |
| 1777 | 1778 |
| 1778 content::g_env = | 1779 content::g_env = |
| 1779 reinterpret_cast<content::VideoEncodeAcceleratorTestEnvironment*>( | 1780 reinterpret_cast<content::VideoEncodeAcceleratorTestEnvironment*>( |
| 1780 testing::AddGlobalTestEnvironment( | 1781 testing::AddGlobalTestEnvironment( |
| 1781 new content::VideoEncodeAcceleratorTestEnvironment( | 1782 new content::VideoEncodeAcceleratorTestEnvironment( |
| 1782 test_stream_data.Pass(), log_path, run_at_fps, | 1783 std::move(test_stream_data), log_path, run_at_fps, |
| 1783 needs_encode_latency, verify_all_output))); | 1784 needs_encode_latency, verify_all_output))); |
| 1784 | 1785 |
| 1785 return RUN_ALL_TESTS(); | 1786 return RUN_ALL_TESTS(); |
| 1786 } | 1787 } |
| OLD | NEW |