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