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

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
« no previous file with comments | « media/base/test_helpers.h ('k') | media/media.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 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 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
221 #define DEFINE_INTERLEAVED_INSTANCE(type) \
222 template scoped_refptr<AudioBuffer> MakeInterleavedAudioBuffer<type>( \
223 SampleFormat format, \
224 int channels, \
225 type start, \
226 type increment, \
227 int frames, \
228 base::TimeDelta start_time)
229 DEFINE_INTERLEAVED_INSTANCE(uint8);
230 DEFINE_INTERLEAVED_INSTANCE(int16);
231 DEFINE_INTERLEAVED_INSTANCE(int32);
232 DEFINE_INTERLEAVED_INSTANCE(float);
233
234 #define DEFINE_PLANAR_INSTANCE(type) \
235 template scoped_refptr<AudioBuffer> MakePlanarAudioBuffer<type>( \
236 SampleFormat format, \
237 int channels, \
238 type start, \
239 type increment, \
240 int frames, \
241 base::TimeDelta start_time);
242 DEFINE_PLANAR_INSTANCE(int16);
243 DEFINE_PLANAR_INSTANCE(float);
244
146 } // namespace media 245 } // namespace media
OLDNEW
« no previous file with comments | « media/base/test_helpers.h ('k') | media/media.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698