Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(407)

Side by Side Diff: media/gpu/video_encode_accelerator_unittest.cc

Issue 2110063002: media: VEA unittest: make sure allocated memory is 64byte aligned (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: wuchengli's nits Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 bool g_fake_encoder = false; 140 bool g_fake_encoder = false;
140 141
141 // Environment to store test stream data for all test cases. 142 // Environment to store test stream data for all test cases.
142 class VideoEncodeAcceleratorTestEnvironment; 143 class VideoEncodeAcceleratorTestEnvironment;
143 VideoEncodeAcceleratorTestEnvironment* g_env; 144 VideoEncodeAcceleratorTestEnvironment* g_env;
144 145
145 // The number of frames to be encoded. This variable is set by the switch 146 // The number of frames to be encoded. This variable is set by the switch
146 // "--num_frames_to_encode". Ignored if 0. 147 // "--num_frames_to_encode". Ignored if 0.
147 int g_num_frames_to_encode = 0; 148 int g_num_frames_to_encode = 0;
148 149
150 // An aligned STL allocator.
151 template <typename T, size_t ByteAlignment>
152 class AlignedAllocator : public std::allocator<T> {
153 public:
154 typedef size_t size_type;
155 typedef T* pointer;
156
157 template <class T1>
158 struct rebind {
159 typedef AlignedAllocator<T1, ByteAlignment> other;
160 };
161
162 AlignedAllocator() {}
163 explicit AlignedAllocator(const AlignedAllocator&) {}
164 template <class T1>
165 explicit AlignedAllocator(const AlignedAllocator<T1, ByteAlignment>&) {}
166 ~AlignedAllocator() {}
167
168 pointer allocate(size_type n, const void* = 0) {
169 return static_cast<pointer>(base::AlignedAlloc(n, ByteAlignment));
170 }
171
172 void deallocate(pointer p, size_type n) {
173 base::AlignedFree(static_cast<void*>(p));
174 }
175
176 size_type max_size() const {
177 return std::numeric_limits<size_t>::max() / sizeof(T);
178 }
179 };
180
149 struct TestStream { 181 struct TestStream {
150 TestStream() 182 TestStream()
151 : num_frames(0), 183 : num_frames(0),
152 aligned_buffer_size(0), 184 aligned_buffer_size(0),
153 requested_bitrate(0), 185 requested_bitrate(0),
154 requested_framerate(0), 186 requested_framerate(0),
155 requested_subsequent_bitrate(0), 187 requested_subsequent_bitrate(0),
156 requested_subsequent_framerate(0) {} 188 requested_subsequent_framerate(0) {}
157 ~TestStream() {} 189 ~TestStream() {}
158 190
159 gfx::Size visible_size; 191 gfx::Size visible_size;
160 gfx::Size coded_size; 192 gfx::Size coded_size;
161 unsigned int num_frames; 193 unsigned int num_frames;
162 194
163 // Original unaligned input file name provided as an argument to the test. 195 // Original unaligned input file name provided as an argument to the test.
164 // And the file must be an I420 (YUV planar) raw stream. 196 // And the file must be an I420 (YUV planar) raw stream.
165 std::string in_filename; 197 std::string in_filename;
166 198
167 // A vector used to prepare aligned input buffers of |in_filename|. This 199 // A vector used to prepare aligned input buffers of |in_filename|. This
168 // makes sure starting address of YUV planes are 64 bytes-aligned. 200 // makes sure starting address of YUV planes are 64 bytes-aligned.
169 std::vector<char> aligned_in_file_data; 201 std::vector<char, AlignedAllocator<char, 64>> aligned_in_file_data;
170 202
171 // Byte size of a frame of |aligned_in_file_data|. 203 // Byte size of a frame of |aligned_in_file_data|.
172 size_t aligned_buffer_size; 204 size_t aligned_buffer_size;
173 205
174 // Byte size for each aligned plane of a frame. 206 // Byte size for each aligned plane of a frame.
175 std::vector<size_t> aligned_plane_size; 207 std::vector<size_t> aligned_plane_size;
176 208
177 std::string out_filename; 209 std::string out_filename;
178 VideoCodecProfile requested_profile; 210 VideoCodecProfile requested_profile;
179 unsigned int requested_bitrate; 211 unsigned int requested_bitrate;
180 unsigned int requested_framerate; 212 unsigned int requested_framerate;
181 unsigned int requested_subsequent_bitrate; 213 unsigned int requested_subsequent_bitrate;
182 unsigned int requested_subsequent_framerate; 214 unsigned int requested_subsequent_framerate;
183 }; 215 };
184 216
185 inline static size_t Align64Bytes(size_t value) { 217 inline static size_t Align64Bytes(size_t value) {
186 return (value + 63) & ~63; 218 return base::bits::Align(value, 64);
187 } 219 }
188 220
189 // Return the |percentile| from a sorted vector. 221 // Return the |percentile| from a sorted vector.
190 static base::TimeDelta Percentile( 222 static base::TimeDelta Percentile(
191 const std::vector<base::TimeDelta>& sorted_values, 223 const std::vector<base::TimeDelta>& sorted_values,
192 unsigned int percentile) { 224 unsigned int percentile) {
193 size_t size = sorted_values.size(); 225 size_t size = sorted_values.size();
194 LOG_ASSERT(size > 0UL); 226 LOG_ASSERT(size > 0UL);
195 LOG_ASSERT(percentile <= 100UL); 227 LOG_ASSERT(percentile <= 100UL);
196 // Use Nearest Rank method in http://en.wikipedia.org/wiki/Percentile. 228 // Use Nearest Rank method in http://en.wikipedia.org/wiki/Percentile.
(...skipping 1580 matching lines...) Expand 10 before | Expand all | Expand 10 after
1777 1809
1778 media::g_env = 1810 media::g_env =
1779 reinterpret_cast<media::VideoEncodeAcceleratorTestEnvironment*>( 1811 reinterpret_cast<media::VideoEncodeAcceleratorTestEnvironment*>(
1780 testing::AddGlobalTestEnvironment( 1812 testing::AddGlobalTestEnvironment(
1781 new media::VideoEncodeAcceleratorTestEnvironment( 1813 new media::VideoEncodeAcceleratorTestEnvironment(
1782 std::move(test_stream_data), log_path, run_at_fps, 1814 std::move(test_stream_data), log_path, run_at_fps,
1783 needs_encode_latency, verify_all_output))); 1815 needs_encode_latency, verify_all_output)));
1784 1816
1785 return RUN_ALL_TESTS(); 1817 return RUN_ALL_TESTS();
1786 } 1818 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698