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

Side by Side Diff: media/base/test_helpers.cc

Issue 17112016: Add new class AudioBufferQueue. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 6 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "media/base/test_helpers.h" 5 #include "media/base/test_helpers.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h"
8 #include "base/message_loop.h" 9 #include "base/message_loop.h"
9 #include "base/test/test_timeouts.h" 10 #include "base/test/test_timeouts.h"
11 #include "base/time.h"
10 #include "base/timer.h" 12 #include "base/timer.h"
13 #include "media/base/audio_buffer.h"
11 #include "media/base/bind_to_loop.h" 14 #include "media/base/bind_to_loop.h"
12 #include "ui/gfx/rect.h" 15 #include "ui/gfx/rect.h"
13 16
14 using ::testing::_; 17 using ::testing::_;
15 using ::testing::StrictMock; 18 using ::testing::StrictMock;
16 19
17 namespace media { 20 namespace media {
18 21
19 // Utility mock for testing methods expecting Closures and PipelineStatusCBs. 22 // Utility mock for testing methods expecting Closures and PipelineStatusCBs.
20 class MockCallback : public base::RefCountedThreadSafe<MockCallback> { 23 class MockCallback : public base::RefCountedThreadSafe<MockCallback> {
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 } 139 }
137 140
138 gfx::Size TestVideoConfig::NormalCodedSize() { 141 gfx::Size TestVideoConfig::NormalCodedSize() {
139 return kNormalSize; 142 return kNormalSize;
140 } 143 }
141 144
142 gfx::Size TestVideoConfig::LargeCodedSize() { 145 gfx::Size TestVideoConfig::LargeCodedSize() {
143 return kLargeSize; 146 return kLargeSize;
144 } 147 }
145 148
149 template <class T>
150 scoped_refptr<AudioBuffer> MakeInterleavedAudioBuffer(
151 SampleFormat format,
152 int channels,
153 T start,
154 T increment,
155 int frames,
156 const base::TimeDelta start_time) {
157 DCHECK(format == kSampleFormatU8 || format == kSampleFormatS16 ||
158 format == kSampleFormatS32 || format == kSampleFormatF32);
159
160 // Create a block of memory with values:
161 // start
162 // start + increment
163 // start + 2 * increment, ...
164 // Since this is interleaved data, channel 0 data will be:
165 // start
166 // start + channels * increment
167 // start + 2 * channels * increment, ...
168 int buffer_size = frames * channels * sizeof(T);
169 scoped_ptr<uint8[]> memory(new uint8[buffer_size]);
170 uint8* data[] = { memory.get() };
171 T* buffer = reinterpret_cast<T*>(memory.get());
172 for (int i = 0; i < frames * channels; ++i) {
173 buffer[i] = start;
174 start += increment;
175 }
176 // Duration is 1 second per frame (for simplicity).
177 base::TimeDelta duration = base::TimeDelta::FromSeconds(frames);
178 return AudioBuffer::CopyFrom(
179 format, channels, frames, data, start_time, duration);
180 }
181
182 template <class T>
183 scoped_refptr<AudioBuffer> MakePlanarAudioBuffer(
184 SampleFormat format,
185 int channels,
186 T start,
187 T increment,
188 int frames,
189 const base::TimeDelta start_time) {
190 DCHECK(format == kSampleFormatPlanarF32 || format == kSampleFormatPlanarS16);
191
192 // Create multiple blocks of data, one for each channel.
193 // Values in channel 0 will be:
194 // start
195 // start + increment
196 // start + 2 * increment, ...
197 // Values in channel 1 will be:
198 // start + frames * increment
199 // start + (frames + 1) * increment
200 // start + (frames + 2) * increment, ...
201 int buffer_size = frames * sizeof(T);
202 scoped_ptr<uint8*[]> data(new uint8*[channels]);
203 scoped_ptr<uint8[]> memory(new uint8[channels * buffer_size]);
204 for (int i = 0; i < channels; ++i) {
205 data.get()[i] = memory.get() + i * buffer_size;
206 T* buffer = reinterpret_cast<T*>(data.get()[i]);
207 for (int j = 0; j < frames; ++j) {
208 buffer[j] = start;
209 start += increment;
210 }
211 }
212 // Duration is 1 second per frame (for simplicity).
213 base::TimeDelta duration = base::TimeDelta::FromSeconds(frames);
214 return AudioBuffer::CopyFrom(
215 format, channels, frames, data.get(), start_time, duration);
216 }
217
218 // Instantiate all the types of MakeInterleavedAudioBuffer() and
219 // MakePlanarAudioBuffer() needed.
220 template scoped_refptr<AudioBuffer> MakeInterleavedAudioBuffer<uint8>(
scherkus (not reviewing) 2013/06/20 23:36:24 if you want you can create a macro to cut down on
jrummell 2013/06/21 01:17:22 Done.
221 SampleFormat format,
222 int channels,
223 uint8 start,
224 uint8 increment,
225 int frames,
226 const base::TimeDelta start_time);
227
228 template scoped_refptr<AudioBuffer> MakeInterleavedAudioBuffer<int16>(
229 SampleFormat format,
230 int channels,
231 int16 start,
232 int16 increment,
233 int frames,
234 const base::TimeDelta start_time);
235
236 template scoped_refptr<AudioBuffer> MakeInterleavedAudioBuffer<int32>(
237 SampleFormat format,
238 int channels,
239 int32 start,
240 int32 increment,
241 int frames,
242 const base::TimeDelta start_time);
243
244 template scoped_refptr<AudioBuffer> MakeInterleavedAudioBuffer<float>(
245 SampleFormat format,
246 int channels,
247 float start,
248 float increment,
249 int frames,
250 const base::TimeDelta start_time);
251
252 template scoped_refptr<AudioBuffer> MakePlanarAudioBuffer<int16>(
253 SampleFormat format,
254 int channels,
255 int16 start,
256 int16 increment,
257 int frames,
258 const base::TimeDelta start_time);
259
260 template scoped_refptr<AudioBuffer> MakePlanarAudioBuffer<float>(
261 SampleFormat format,
262 int channels,
263 float start,
264 float increment,
265 int frames,
266 const base::TimeDelta start_time);
267
146 } // namespace media 268 } // namespace media
OLDNEW
« media/base/test_helpers.h ('K') | « media/base/test_helpers.h ('k') | media/media.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698