Chromium Code Reviews| 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/files/memory_mapped_file.h" |
|
wuchengli
2016/07/01 06:25:30
This can be removed.
llandwerlin-old
2016/07/01 08:11:39
Done.
| |
| 20 #include "base/macros.h" | 21 #include "base/macros.h" |
| 22 #include "base/memory/aligned_memory.h" | |
| 21 #include "base/memory/scoped_vector.h" | 23 #include "base/memory/scoped_vector.h" |
| 22 #include "base/message_loop/message_loop.h" | 24 #include "base/message_loop/message_loop.h" |
| 23 #include "base/numerics/safe_conversions.h" | 25 #include "base/numerics/safe_conversions.h" |
| 24 #include "base/process/process_handle.h" | 26 #include "base/process/process_handle.h" |
| 25 #include "base/strings/string_number_conversions.h" | 27 #include "base/strings/string_number_conversions.h" |
| 26 #include "base/strings/string_split.h" | 28 #include "base/strings/string_split.h" |
| 27 #include "base/strings/stringprintf.h" | 29 #include "base/strings/stringprintf.h" |
| 28 #include "base/threading/thread.h" | 30 #include "base/threading/thread.h" |
| 29 #include "base/threading/thread_checker.h" | 31 #include "base/threading/thread_checker.h" |
| 30 #include "base/time/time.h" | 32 #include "base/time/time.h" |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 139 bool g_fake_encoder = false; | 141 bool g_fake_encoder = false; |
| 140 | 142 |
| 141 // Environment to store test stream data for all test cases. | 143 // Environment to store test stream data for all test cases. |
| 142 class VideoEncodeAcceleratorTestEnvironment; | 144 class VideoEncodeAcceleratorTestEnvironment; |
| 143 VideoEncodeAcceleratorTestEnvironment* g_env; | 145 VideoEncodeAcceleratorTestEnvironment* g_env; |
| 144 | 146 |
| 145 // 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 |
| 146 // "--num_frames_to_encode". Ignored if 0. | 148 // "--num_frames_to_encode". Ignored if 0. |
| 147 int g_num_frames_to_encode = 0; | 149 int g_num_frames_to_encode = 0; |
| 148 | 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 AlignedAllocator(const AlignedAllocator<T1, ByteAlignment>&) {} | |
|
wuchengli
2016/07/01 06:25:30
add explict?
llandwerlin-old
2016/07/01 08:11:39
Done.
| |
| 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 | |
| 149 struct TestStream { | 182 struct TestStream { |
| 150 TestStream() | 183 TestStream() |
| 151 : num_frames(0), | 184 : num_frames(0), |
| 152 aligned_buffer_size(0), | 185 aligned_buffer_size(0), |
| 153 requested_bitrate(0), | 186 requested_bitrate(0), |
| 154 requested_framerate(0), | 187 requested_framerate(0), |
| 155 requested_subsequent_bitrate(0), | 188 requested_subsequent_bitrate(0), |
| 156 requested_subsequent_framerate(0) {} | 189 requested_subsequent_framerate(0) {} |
| 157 ~TestStream() {} | 190 ~TestStream() {} |
| 158 | 191 |
| 159 gfx::Size visible_size; | 192 gfx::Size visible_size; |
| 160 gfx::Size coded_size; | 193 gfx::Size coded_size; |
| 161 unsigned int num_frames; | 194 unsigned int num_frames; |
| 162 | 195 |
| 163 // 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. |
| 164 // And the file must be an I420 (YUV planar) raw stream. | 197 // And the file must be an I420 (YUV planar) raw stream. |
| 165 std::string in_filename; | 198 std::string in_filename; |
| 166 | 199 |
| 167 // 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 |
| 168 // makes sure starting address of YUV planes are 64 bytes-aligned. | 201 // makes sure starting address of YUV planes are 64 bytes-aligned. |
| 169 std::vector<char> aligned_in_file_data; | 202 std::vector<char, AlignedAllocator<char, 64>> aligned_in_file_data; |
| 170 | 203 |
| 171 // Byte size of a frame of |aligned_in_file_data|. | 204 // Byte size of a frame of |aligned_in_file_data|. |
| 172 size_t aligned_buffer_size; | 205 size_t aligned_buffer_size; |
| 173 | 206 |
| 174 // Byte size for each aligned plane of a frame. | 207 // Byte size for each aligned plane of a frame. |
| 175 std::vector<size_t> aligned_plane_size; | 208 std::vector<size_t> aligned_plane_size; |
| 176 | 209 |
| 177 std::string out_filename; | 210 std::string out_filename; |
| 178 VideoCodecProfile requested_profile; | 211 VideoCodecProfile requested_profile; |
| 179 unsigned int requested_bitrate; | 212 unsigned int requested_bitrate; |
| 180 unsigned int requested_framerate; | 213 unsigned int requested_framerate; |
| 181 unsigned int requested_subsequent_bitrate; | 214 unsigned int requested_subsequent_bitrate; |
| 182 unsigned int requested_subsequent_framerate; | 215 unsigned int requested_subsequent_framerate; |
| 183 }; | 216 }; |
| 184 | 217 |
| 185 inline static size_t Align64Bytes(size_t value) { | 218 inline static size_t Align64Bytes(size_t value) { |
| 186 return (value + 63) & ~63; | 219 return base::bits::Align(value, 64); |
| 187 } | 220 } |
| 188 | 221 |
| 189 // Return the |percentile| from a sorted vector. | 222 // Return the |percentile| from a sorted vector. |
| 190 static base::TimeDelta Percentile( | 223 static base::TimeDelta Percentile( |
| 191 const std::vector<base::TimeDelta>& sorted_values, | 224 const std::vector<base::TimeDelta>& sorted_values, |
| 192 unsigned int percentile) { | 225 unsigned int percentile) { |
| 193 size_t size = sorted_values.size(); | 226 size_t size = sorted_values.size(); |
| 194 LOG_ASSERT(size > 0UL); | 227 LOG_ASSERT(size > 0UL); |
| 195 LOG_ASSERT(percentile <= 100UL); | 228 LOG_ASSERT(percentile <= 100UL); |
| 196 // 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... | |
| 1777 | 1810 |
| 1778 media::g_env = | 1811 media::g_env = |
| 1779 reinterpret_cast<media::VideoEncodeAcceleratorTestEnvironment*>( | 1812 reinterpret_cast<media::VideoEncodeAcceleratorTestEnvironment*>( |
| 1780 testing::AddGlobalTestEnvironment( | 1813 testing::AddGlobalTestEnvironment( |
| 1781 new media::VideoEncodeAcceleratorTestEnvironment( | 1814 new media::VideoEncodeAcceleratorTestEnvironment( |
| 1782 std::move(test_stream_data), log_path, run_at_fps, | 1815 std::move(test_stream_data), log_path, run_at_fps, |
| 1783 needs_encode_latency, verify_all_output))); | 1816 needs_encode_latency, verify_all_output))); |
| 1784 | 1817 |
| 1785 return RUN_ALL_TESTS(); | 1818 return RUN_ALL_TESTS(); |
| 1786 } | 1819 } |
| OLD | NEW |