| 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 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <memory> | 10 #include <memory> |
| 11 #include <queue> | 11 #include <queue> |
| 12 #include <string> | 12 #include <string> |
| 13 #include <utility> | 13 #include <utility> |
| 14 | 14 |
| 15 #include "base/at_exit.h" | 15 #include "base/at_exit.h" |
| 16 #include "base/bind.h" | 16 #include "base/bind.h" |
| 17 #include "base/bits.h" |
| 17 #include "base/command_line.h" | 18 #include "base/command_line.h" |
| 18 #include "base/files/file_util.h" | 19 #include "base/files/file_util.h" |
| 19 #include "base/files/memory_mapped_file.h" | |
| 20 #include "base/macros.h" | 20 #include "base/macros.h" |
| 21 #include "base/memory/aligned_memory.h" |
| 21 #include "base/memory/scoped_vector.h" | 22 #include "base/memory/scoped_vector.h" |
| 22 #include "base/message_loop/message_loop.h" | 23 #include "base/message_loop/message_loop.h" |
| 23 #include "base/numerics/safe_conversions.h" | 24 #include "base/numerics/safe_conversions.h" |
| 24 #include "base/process/process_handle.h" | 25 #include "base/process/process_handle.h" |
| 25 #include "base/single_thread_task_runner.h" | 26 #include "base/single_thread_task_runner.h" |
| 26 #include "base/strings/string_number_conversions.h" | 27 #include "base/strings/string_number_conversions.h" |
| 27 #include "base/strings/string_split.h" | 28 #include "base/strings/string_split.h" |
| 28 #include "base/strings/stringprintf.h" | 29 #include "base/strings/stringprintf.h" |
| 29 #include "base/threading/thread.h" | 30 #include "base/threading/thread.h" |
| 30 #include "base/threading/thread_checker.h" | 31 #include "base/threading/thread_checker.h" |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 bool g_fake_encoder = false; | 141 bool g_fake_encoder = false; |
| 141 | 142 |
| 142 // Environment to store test stream data for all test cases. | 143 // Environment to store test stream data for all test cases. |
| 143 class VideoEncodeAcceleratorTestEnvironment; | 144 class VideoEncodeAcceleratorTestEnvironment; |
| 144 VideoEncodeAcceleratorTestEnvironment* g_env; | 145 VideoEncodeAcceleratorTestEnvironment* g_env; |
| 145 | 146 |
| 146 // The number of frames to be encoded. This variable is set by the switch | 147 // The number of frames to be encoded. This variable is set by the switch |
| 147 // "--num_frames_to_encode". Ignored if 0. | 148 // "--num_frames_to_encode". Ignored if 0. |
| 148 int g_num_frames_to_encode = 0; | 149 int g_num_frames_to_encode = 0; |
| 149 | 150 |
| 151 // An aligned STL allocator. |
| 152 template <typename T, size_t ByteAlignment> |
| 153 class AlignedAllocator : public std::allocator<T> { |
| 154 public: |
| 155 typedef size_t size_type; |
| 156 typedef T* pointer; |
| 157 |
| 158 template <class T1> |
| 159 struct rebind { |
| 160 typedef AlignedAllocator<T1, ByteAlignment> other; |
| 161 }; |
| 162 |
| 163 AlignedAllocator() {} |
| 164 explicit AlignedAllocator(const AlignedAllocator&) {} |
| 165 template <class T1> |
| 166 explicit AlignedAllocator(const AlignedAllocator<T1, ByteAlignment>&) {} |
| 167 ~AlignedAllocator() {} |
| 168 |
| 169 pointer allocate(size_type n, const void* = 0) { |
| 170 return static_cast<pointer>(base::AlignedAlloc(n, ByteAlignment)); |
| 171 } |
| 172 |
| 173 void deallocate(pointer p, size_type n) { |
| 174 base::AlignedFree(static_cast<void*>(p)); |
| 175 } |
| 176 |
| 177 size_type max_size() const { |
| 178 return std::numeric_limits<size_t>::max() / sizeof(T); |
| 179 } |
| 180 }; |
| 181 |
| 150 struct TestStream { | 182 struct TestStream { |
| 151 TestStream() | 183 TestStream() |
| 152 : num_frames(0), | 184 : num_frames(0), |
| 153 aligned_buffer_size(0), | 185 aligned_buffer_size(0), |
| 154 requested_bitrate(0), | 186 requested_bitrate(0), |
| 155 requested_framerate(0), | 187 requested_framerate(0), |
| 156 requested_subsequent_bitrate(0), | 188 requested_subsequent_bitrate(0), |
| 157 requested_subsequent_framerate(0) {} | 189 requested_subsequent_framerate(0) {} |
| 158 ~TestStream() {} | 190 ~TestStream() {} |
| 159 | 191 |
| 160 gfx::Size visible_size; | 192 gfx::Size visible_size; |
| 161 gfx::Size coded_size; | 193 gfx::Size coded_size; |
| 162 unsigned int num_frames; | 194 unsigned int num_frames; |
| 163 | 195 |
| 164 // Original unaligned input file name provided as an argument to the test. | 196 // Original unaligned input file name provided as an argument to the test. |
| 165 // And the file must be an I420 (YUV planar) raw stream. | 197 // And the file must be an I420 (YUV planar) raw stream. |
| 166 std::string in_filename; | 198 std::string in_filename; |
| 167 | 199 |
| 168 // A vector used to prepare aligned input buffers of |in_filename|. This | 200 // A vector used to prepare aligned input buffers of |in_filename|. This |
| 169 // makes sure starting address of YUV planes are 64 bytes-aligned. | 201 // makes sure starting address of YUV planes are 64 bytes-aligned. |
| 170 std::vector<char> aligned_in_file_data; | 202 std::vector<char, AlignedAllocator<char, 64>> aligned_in_file_data; |
| 171 | 203 |
| 172 // Byte size of a frame of |aligned_in_file_data|. | 204 // Byte size of a frame of |aligned_in_file_data|. |
| 173 size_t aligned_buffer_size; | 205 size_t aligned_buffer_size; |
| 174 | 206 |
| 175 // Byte size for each aligned plane of a frame. | 207 // Byte size for each aligned plane of a frame. |
| 176 std::vector<size_t> aligned_plane_size; | 208 std::vector<size_t> aligned_plane_size; |
| 177 | 209 |
| 178 std::string out_filename; | 210 std::string out_filename; |
| 179 VideoCodecProfile requested_profile; | 211 VideoCodecProfile requested_profile; |
| 180 unsigned int requested_bitrate; | 212 unsigned int requested_bitrate; |
| 181 unsigned int requested_framerate; | 213 unsigned int requested_framerate; |
| 182 unsigned int requested_subsequent_bitrate; | 214 unsigned int requested_subsequent_bitrate; |
| 183 unsigned int requested_subsequent_framerate; | 215 unsigned int requested_subsequent_framerate; |
| 184 }; | 216 }; |
| 185 | 217 |
| 186 inline static size_t Align64Bytes(size_t value) { | 218 inline static size_t Align64Bytes(size_t value) { |
| 187 return (value + 63) & ~63; | 219 return base::bits::Align(value, 64); |
| 188 } | 220 } |
| 189 | 221 |
| 190 // Return the |percentile| from a sorted vector. | 222 // Return the |percentile| from a sorted vector. |
| 191 static base::TimeDelta Percentile( | 223 static base::TimeDelta Percentile( |
| 192 const std::vector<base::TimeDelta>& sorted_values, | 224 const std::vector<base::TimeDelta>& sorted_values, |
| 193 unsigned int percentile) { | 225 unsigned int percentile) { |
| 194 size_t size = sorted_values.size(); | 226 size_t size = sorted_values.size(); |
| 195 LOG_ASSERT(size > 0UL); | 227 LOG_ASSERT(size > 0UL); |
| 196 LOG_ASSERT(percentile <= 100UL); | 228 LOG_ASSERT(percentile <= 100UL); |
| 197 // Use Nearest Rank method in http://en.wikipedia.org/wiki/Percentile. | 229 // Use Nearest Rank method in http://en.wikipedia.org/wiki/Percentile. |
| (...skipping 1580 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1778 | 1810 |
| 1779 media::g_env = | 1811 media::g_env = |
| 1780 reinterpret_cast<media::VideoEncodeAcceleratorTestEnvironment*>( | 1812 reinterpret_cast<media::VideoEncodeAcceleratorTestEnvironment*>( |
| 1781 testing::AddGlobalTestEnvironment( | 1813 testing::AddGlobalTestEnvironment( |
| 1782 new media::VideoEncodeAcceleratorTestEnvironment( | 1814 new media::VideoEncodeAcceleratorTestEnvironment( |
| 1783 std::move(test_stream_data), log_path, run_at_fps, | 1815 std::move(test_stream_data), log_path, run_at_fps, |
| 1784 needs_encode_latency, verify_all_output))); | 1816 needs_encode_latency, verify_all_output))); |
| 1785 | 1817 |
| 1786 return RUN_ALL_TESTS(); | 1818 return RUN_ALL_TESTS(); |
| 1787 } | 1819 } |
| OLD | NEW |