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

Side by Side Diff: media/base/seekable_audio_buffer_unittest.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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/basictypes.h"
6 #include "base/logging.h"
7 #include "base/memory/scoped_ptr.h"
8 #include "base/strings/stringprintf.h"
9 #include "base/time.h"
10 #include "media/base/audio_buffer.h"
11 #include "media/base/audio_bus.h"
12 #include "media/base/buffers.h"
13 #include "media/base/seekable_audio_buffer.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15
16 namespace media {
17
18 template <class T>
19 static scoped_refptr<AudioBuffer> MakeInterleavedBuffer(
scherkus (not reviewing) 2013/06/19 23:38:06 are these duplicated from audio_buffer_unittest.cc
jrummell 2013/06/20 21:47:01 Done.
20 SampleFormat format,
21 int channels,
22 T start,
23 T increment,
24 int frames,
25 const base::TimeDelta start_time) {
26 DCHECK(format == kSampleFormatU8 || format == kSampleFormatS16 ||
27 format == kSampleFormatS32 || format == kSampleFormatF32);
28
29 // Create a block of memory with values:
30 // start
31 // start + increment
32 // start + 2 * increment, ...
33 // Since this is interleaved data, channel 0 data will be:
34 // start
35 // start + channels * increment
36 // start + 2 * channels * increment, ...
37 int buffer_size = frames * channels * sizeof(T);
38 scoped_ptr<uint8[]> memory(new uint8[buffer_size]);
39 uint8* data[] = { memory.get() };
40 T* buffer = reinterpret_cast<T*>(memory.get());
41 for (int i = 0; i < frames * channels; ++i) {
42 buffer[i] = start;
43 start += increment;
44 }
45 // Duration is 1 second per frame (for simplicity).
46 base::TimeDelta duration = base::TimeDelta::FromSeconds(frames);
47 return AudioBuffer::CopyFrom(
48 format, channels, frames, data, start_time, duration);
49 }
50
51 template <class T>
52 static scoped_refptr<AudioBuffer> MakePlanarBuffer(
53 SampleFormat format,
54 int channels,
55 T start,
56 T increment,
57 int frames,
58 const base::TimeDelta start_time) {
59 DCHECK(format == kSampleFormatPlanarF32 || format == kSampleFormatPlanarS16);
60
61 // Create multiple blocks of data, one for each channel.
62 // Values in channel 0 will be:
63 // start
64 // start + increment
65 // start + 2 * increment, ...
66 // Values in channel 1 will be:
67 // start + frames * increment
68 // start + (frames + 1) * increment
69 // start + (frames + 2) * increment, ...
70 int buffer_size = frames * sizeof(T);
71 scoped_ptr<uint8*[]> data(new uint8*[channels]);
72 scoped_ptr<uint8[]> memory(new uint8[channels * buffer_size]);
73 for (int i = 0; i < channels; ++i) {
74 data.get()[i] = memory.get() + i * buffer_size;
75 T* buffer = reinterpret_cast<T*>(data.get()[i]);
76 for (int j = 0; j < frames; ++j) {
77 buffer[j] = start;
78 start += increment;
79 }
80 }
81 // Duration is 1 second per frame (for simplicity).
82 base::TimeDelta duration = base::TimeDelta::FromSeconds(frames);
83 return AudioBuffer::CopyFrom(
84 format, channels, frames, data.get(), start_time, duration);
85 }
86
87 static void VerifyResult(float* channel_data,
88 int frames,
89 float start,
90 float increment) {
91 for (int i = 0; i < frames; ++i) {
92 SCOPED_TRACE(base::StringPrintf(
93 "i=%d/%d start=%f, increment=%f", i, frames, start, increment));
94 ASSERT_EQ(channel_data[i], start);
95 start += increment;
96 }
97 }
98
99 TEST(SeekableAudioBufferTest, AppendAndClear) {
100 const int channels = 1;
101 const base::TimeDelta start_time;
102 SeekableAudioBuffer buffer(1000);
103 EXPECT_EQ(buffer.forward_capacity(), 1000);
104 EXPECT_EQ(buffer.forward_frames(), 0);
105 buffer.set_forward_capacity(2000);
106 EXPECT_EQ(buffer.forward_capacity(), 2000);
107 EXPECT_EQ(buffer.forward_frames(), 0);
108 EXPECT_TRUE(buffer.Append(MakeInterleavedBuffer<uint8>(
109 kSampleFormatU8, channels, 10, 1, 8, start_time)));
110 EXPECT_GT(buffer.forward_frames(), 0);
111 buffer.Clear();
112 EXPECT_EQ(buffer.forward_capacity(), 2000);
113 EXPECT_EQ(buffer.forward_frames(), 0);
114 EXPECT_TRUE(buffer.Append(MakeInterleavedBuffer<uint8>(
115 kSampleFormatU8, channels, 20, 1, 8, start_time)));
116 EXPECT_EQ(buffer.forward_frames(), 8);
117 }
118
119 TEST(SeekableAudioBufferTest, MultipleAppend) {
120 const int channels = 1;
121 const base::TimeDelta start_time;
122 SeekableAudioBuffer buffer(1000);
123
124 // Append 40 frames in 5 buffers.
125 EXPECT_TRUE(buffer.Append(MakeInterleavedBuffer<uint8>(
126 kSampleFormatU8, channels, 10, 1, 8, start_time)));
127 EXPECT_EQ(buffer.forward_frames(), 8);
128 EXPECT_TRUE(buffer.Append(MakeInterleavedBuffer<uint8>(
129 kSampleFormatU8, channels, 10, 1, 8, start_time)));
130 EXPECT_EQ(buffer.forward_frames(), 16);
131 EXPECT_TRUE(buffer.Append(MakeInterleavedBuffer<uint8>(
132 kSampleFormatU8, channels, 10, 1, 8, start_time)));
133 EXPECT_EQ(buffer.forward_frames(), 24);
134 EXPECT_TRUE(buffer.Append(MakeInterleavedBuffer<uint8>(
135 kSampleFormatU8, channels, 10, 1, 8, start_time)));
136 EXPECT_EQ(buffer.forward_frames(), 32);
137 EXPECT_TRUE(buffer.Append(MakeInterleavedBuffer<uint8>(
138 kSampleFormatU8, channels, 10, 1, 8, start_time)));
139 EXPECT_EQ(buffer.forward_frames(), 40);
140 }
141
142 TEST(SeekableAudioBufferTest, Seek) {
143 const int channels = 2;
144 const base::TimeDelta start_time;
145 SeekableAudioBuffer buffer(1000);
146
147 // Add 6 frames of data.
148 EXPECT_TRUE(buffer.Append(MakeInterleavedBuffer<float>(
149 kSampleFormatF32, channels, 1.0f, 1.0f, 6, start_time)));
150 EXPECT_EQ(buffer.forward_frames(), 6);
151
152 // Seek past 2 frames.
153 EXPECT_TRUE(buffer.SeekFrames(2));
154 EXPECT_EQ(buffer.forward_frames(), 4);
155
156 // Try to seek more frames than exist.
157 EXPECT_FALSE(buffer.SeekFrames(20));
158 EXPECT_EQ(buffer.forward_frames(), 4);
159
160 // Seek to end of data.
161 EXPECT_TRUE(buffer.SeekFrames(4));
162 EXPECT_EQ(buffer.forward_frames(), 0);
163
164 // At end, seek now fails unless 0 specified.
165 EXPECT_FALSE(buffer.SeekFrames(1));
166 EXPECT_FALSE(buffer.SeekFrames(100));
167 EXPECT_TRUE(buffer.SeekFrames(0));
168 }
169
170 TEST(SeekableAudioBufferTest, BufferFull) {
171 const int channels = 1;
172 const base::TimeDelta start_time;
173 SeekableAudioBuffer buffer(10); // hold up to 10 frames.
174
175 // Add 24 frames of data, much more than the limit of 10.
176 EXPECT_TRUE(buffer.Append(MakeInterleavedBuffer<uint8>(
177 kSampleFormatU8, channels, 10, 1, 8, start_time)));
178 EXPECT_EQ(buffer.forward_frames(), 8);
179 EXPECT_FALSE(buffer.Append(MakeInterleavedBuffer<uint8>(
180 kSampleFormatU8, channels, 10, 1, 8, start_time)));
181 EXPECT_EQ(buffer.forward_frames(), 16);
182 EXPECT_FALSE(buffer.Append(MakeInterleavedBuffer<uint8>(
183 kSampleFormatU8, channels, 10, 1, 8, start_time)));
184 EXPECT_EQ(buffer.forward_frames(), 24);
185 }
186
187 TEST(SeekableAudioBufferTest, ReadF32) {
188 const int channels = 2;
189 const base::TimeDelta start_time;
190 SeekableAudioBuffer buffer(1000);
191
192 // Add 76 frames of data.
193 EXPECT_TRUE(buffer.Append(MakeInterleavedBuffer<float>(
194 kSampleFormatF32, channels, 1.0f, 1.0f, 6, start_time)));
195 EXPECT_TRUE(buffer.Append(MakeInterleavedBuffer<float>(
196 kSampleFormatF32, channels, 13.0f, 1.0f, 10, start_time)));
197 EXPECT_TRUE(buffer.Append(MakeInterleavedBuffer<float>(
198 kSampleFormatF32, channels, 33.0f, 1.0f, 60, start_time)));
199 EXPECT_EQ(buffer.forward_frames(), 76);
200
201 // Read 3 frames from the buffer. F32 is interleaved, so ch[0] should be
202 // 1, 3, 5, and ch[1] should be 2, 4, 6.
203 scoped_ptr<AudioBus> bus = AudioBus::Create(channels, 100);
204 EXPECT_EQ(buffer.ReadFrames(3, bus.get()), 3);
205 EXPECT_EQ(buffer.forward_frames(), 73);
206 VerifyResult(bus->channel(0), 3, 1.0f, 2.0f);
207 VerifyResult(bus->channel(1), 3, 2.0f, 2.0f);
208
209 // Now read 5 frames, which will span buffers.
210 EXPECT_EQ(buffer.ReadFrames(5, bus.get()), 5);
211 EXPECT_EQ(buffer.forward_frames(), 68);
212 VerifyResult(bus->channel(0), 5, 7.0f, 2.0f);
213 VerifyResult(bus->channel(1), 5, 8.0f, 2.0f);
214
215 // Now skip into the third buffer.
216 EXPECT_TRUE(buffer.SeekFrames(20));
217 EXPECT_EQ(buffer.forward_frames(), 48);
218
219 // Now read 2 frames, which are in the third buffer.
220 EXPECT_EQ(buffer.ReadFrames(2, bus.get()), 2);
221 VerifyResult(bus->channel(0), 2, 57.0f, 2.0f);
222 VerifyResult(bus->channel(1), 2, 58.0f, 2.0f);
223 }
224
225 TEST(SeekableAudioBufferTest, ReadU8) {
226 const int channels = 4;
227 const base::TimeDelta start_time;
228 SeekableAudioBuffer buffer(1000);
229
230 // Add 4 frames of data.
231 EXPECT_TRUE(buffer.Append(MakeInterleavedBuffer<uint8>(
232 kSampleFormatU8, channels, 128, 1, 4, start_time)));
233
234 // Read all 4 frames from the buffer. Data is interleaved, so ch[0] should be
235 // 128, 132, 136, 140, other channels similar. However, values are converted
236 // from [0, 255] to [-1.0, 1.0] with a bias of 128. Thus the first buffer
237 // value should be 0.0, then 1/127, 2/127, etc.
238 scoped_ptr<AudioBus> bus = AudioBus::Create(channels, 100);
239 EXPECT_EQ(buffer.ReadFrames(4, bus.get()), 4);
240 EXPECT_EQ(buffer.forward_frames(), 0);
241 VerifyResult(bus->channel(0), 4, 0.0f, 4.0f / 127.0f);
242 VerifyResult(bus->channel(1), 4, 1.0f / 127.0f, 4.0f / 127.0f);
243 VerifyResult(bus->channel(2), 4, 2.0f / 127.0f, 4.0f / 127.0f);
244 VerifyResult(bus->channel(3), 4, 3.0f / 127.0f, 4.0f / 127.0f);
245 }
246
247 TEST(SeekableAudioBufferTest, ReadS16) {
248 const int channels = 2;
249 const base::TimeDelta start_time;
250 SeekableAudioBuffer buffer(1000);
251
252 // Add 24 frames of data.
253 EXPECT_TRUE(buffer.Append(MakeInterleavedBuffer<int16>(
254 kSampleFormatS16, channels, 1, 1, 4, start_time)));
255 EXPECT_TRUE(buffer.Append(MakeInterleavedBuffer<int16>(
256 kSampleFormatS16, channels, 9, 1, 20, start_time)));
257 EXPECT_EQ(buffer.forward_frames(), 24);
258
259 // Read 6 frames from the buffer. Data is interleaved, so ch[0] should be
260 // 1, 3, 5, 7, 9, 11, and ch[1] should be 2, 4, 6, 8, 10, 12.
261 // Data is converted to float from -1.0 to 1.0 based on int16 range.
262 scoped_ptr<AudioBus> bus = AudioBus::Create(channels, 100);
263 EXPECT_EQ(buffer.ReadFrames(6, bus.get()), 6);
264 EXPECT_EQ(buffer.forward_frames(), 18);
265 VerifyResult(bus->channel(0), 6, 1.0f / kint16max, 2.0f / kint16max);
266 VerifyResult(bus->channel(1), 6, 2.0f / kint16max, 2.0f / kint16max);
267 }
268
269 TEST(SeekableAudioBufferTest, ReadS32) {
270 const int channels = 2;
271 const base::TimeDelta start_time;
272 SeekableAudioBuffer buffer(1000);
273
274 // Add 24 frames of data.
275 EXPECT_TRUE(buffer.Append(MakeInterleavedBuffer<int32>(
276 kSampleFormatS32, channels, 1, 1, 4, start_time)));
277 EXPECT_TRUE(buffer.Append(MakeInterleavedBuffer<int32>(
278 kSampleFormatS32, channels, 9, 1, 20, start_time)));
279 EXPECT_EQ(buffer.forward_frames(), 24);
280
281 // Read 6 frames from the buffer. Data is interleaved, so ch[0] should be
282 // 1, 3, 5, 7, 100, 106, and ch[1] should be 2, 4, 6, 8, 103, 109.
283 // Data is converted to float from -1.0 to 1.0 based on int32 range.
284 scoped_ptr<AudioBus> bus = AudioBus::Create(channels, 100);
285 EXPECT_EQ(buffer.ReadFrames(6, bus.get()), 6);
286 EXPECT_EQ(buffer.forward_frames(), 18);
287 VerifyResult(bus->channel(0), 6, 1.0f / kint32max, 2.0f / kint32max);
288 VerifyResult(bus->channel(1), 6, 2.0f / kint32max, 2.0f / kint32max);
289
290 // Read the next 2 frames.
291 EXPECT_EQ(buffer.ReadFrames(2, bus.get()), 2);
292 EXPECT_EQ(buffer.forward_frames(), 16);
293 VerifyResult(bus->channel(0), 2, 13.0f / kint32max, 2.0f / kint32max);
294 VerifyResult(bus->channel(1), 2, 14.0f / kint32max, 2.0f / kint32max);
295 }
296
297 TEST(SeekableAudioBufferTest, ReadF32Planar) {
298 const int channels = 2;
299 const base::TimeDelta start_time;
300 SeekableAudioBuffer buffer(1000);
301
302 // Add 14 frames of data.
303 EXPECT_TRUE(buffer.Append(MakePlanarBuffer<float>(
304 kSampleFormatPlanarF32, channels, 1.0f, 1.0f, 4, start_time)));
305 EXPECT_TRUE(buffer.Append(MakePlanarBuffer<float>(
306 kSampleFormatPlanarF32, channels, 50.0f, 1.0f, 10, start_time)));
307 EXPECT_EQ(buffer.forward_frames(), 14);
308
309 // Read 6 frames from the buffer. F32 is planar, so ch[0] should be
310 // 1, 2, 3, 4, 50, 51, and ch[1] should be 5, 6, 7, 8, 60, 61.
311 scoped_ptr<AudioBus> bus = AudioBus::Create(channels, 100);
312 EXPECT_EQ(buffer.ReadFrames(6, bus.get()), 6);
313 EXPECT_EQ(buffer.forward_frames(), 8);
314 VerifyResult(bus->channel(0), 4, 1.0f, 1.0f);
315 VerifyResult(bus->channel(0) + 4, 2, 50.0f, 1.0f);
316 VerifyResult(bus->channel(1), 4, 5.0f, 1.0f);
317 VerifyResult(bus->channel(1) + 4, 2, 60.0f, 1.0f);
318 }
319
320 TEST(SeekableAudioBufferTest, ReadS16Planar) {
321 const int channels = 2;
322 const base::TimeDelta start_time;
323 SeekableAudioBuffer buffer(1000);
324
325 // Add 24 frames of data.
326 EXPECT_TRUE(buffer.Append(MakePlanarBuffer<int16>(
327 kSampleFormatPlanarS16, channels, 1, 1, 4, start_time)));
328 EXPECT_TRUE(buffer.Append(MakePlanarBuffer<int16>(
329 kSampleFormatPlanarS16, channels, 100, 5, 20, start_time)));
330 EXPECT_EQ(buffer.forward_frames(), 24);
331
332 // Read 6 frames from the buffer. Data is planar, so ch[0] should be
333 // 1, 2, 3, 4, 100, 105, and ch[1] should be 5, 6, 7, 8, 200, 205.
334 // Data is converted to float from -1.0 to 1.0 based on int16 range.
335 scoped_ptr<AudioBus> bus = AudioBus::Create(channels, 100);
336 EXPECT_EQ(buffer.ReadFrames(6, bus.get()), 6);
337 EXPECT_EQ(buffer.forward_frames(), 18);
338 VerifyResult(bus->channel(0), 4, 1.0f / kint16max, 1.0f / kint16max);
339 VerifyResult(bus->channel(0) + 4, 2, 100.0f / kint16max, 5.0f / kint16max);
340 VerifyResult(bus->channel(1), 4, 5.0f / kint16max, 1.0f / kint16max);
341 VerifyResult(bus->channel(1) + 4, 2, 200.0f / kint16max, 5.0f / kint16max);
342 }
343
344 TEST(SeekableAudioBufferTest, ReadManyChannels) {
345 const int channels = 16;
346 const base::TimeDelta start_time;
347 SeekableAudioBuffer buffer(1000);
348
349 // Add 76 frames of data.
350 EXPECT_TRUE(buffer.Append(MakeInterleavedBuffer<float>(
351 kSampleFormatF32, channels, 0.0f, 1.0f, 6, start_time)));
352 EXPECT_TRUE(buffer.Append(MakeInterleavedBuffer<float>(
353 kSampleFormatF32, channels, 6.0f * channels, 1.0f, 10, start_time)));
354 EXPECT_TRUE(buffer.Append(MakeInterleavedBuffer<float>(
355 kSampleFormatF32, channels, 16.0f * channels, 1.0f, 60, start_time)));
356 EXPECT_EQ(buffer.forward_frames(), 76);
357
358 // Read 3 frames from the buffer. F32 is interleaved, so ch[0] should be
359 // 1, 17, 33, and ch[1] should be 2, 18, 34. Just check a few channels.
360 scoped_ptr<AudioBus> bus = AudioBus::Create(channels, 100);
361 EXPECT_EQ(buffer.ReadFrames(30, bus.get()), 30);
362 EXPECT_EQ(buffer.forward_frames(), 46);
363 for (int i = 0; i < channels; ++i) {
364 VerifyResult(bus->channel(i), 30, static_cast<float>(i), 16.0f);
365 }
366 }
367
368 TEST(SeekableAudioBufferTest, Peek) {
369 const int channels = 4;
370 const base::TimeDelta start_time;
371 SeekableAudioBuffer buffer(1000);
372
373 // Add 60 frames of data.
374 EXPECT_TRUE(buffer.Append(MakeInterleavedBuffer<float>(
375 kSampleFormatF32, channels, 0.0f, 1.0f, 60, start_time)));
376 EXPECT_EQ(buffer.forward_frames(), 60);
377
378 // Peek at the first 30 frames.
379 scoped_ptr<AudioBus> bus1 = AudioBus::Create(channels, 100);
380 EXPECT_EQ(buffer.forward_frames(), 60);
381 EXPECT_EQ(buffer.PeekFrames(100, bus1.get()), 60); // only 60 in buffer.
382 EXPECT_EQ(buffer.PeekFrames(30, bus1.get()), 30); // should get first 30.
383 EXPECT_EQ(buffer.forward_frames(), 60);
384
385 // Now read the next 30 frames (which should be the same as those peeked at).
386 scoped_ptr<AudioBus> bus2 = AudioBus::Create(channels, 100);
387 EXPECT_EQ(buffer.ReadFrames(30, bus2.get()), 30);
388 for (int i = 0; i < channels; ++i) {
389 VerifyResult(bus1->channel(i),
390 30,
391 static_cast<float>(i),
392 static_cast<float>(channels));
393 VerifyResult(bus2->channel(i),
394 30,
395 static_cast<float>(i),
396 static_cast<float>(channels));
397 }
398
399 // Peek 10 frames forward
400 EXPECT_EQ(buffer.PeekFrames(5, 10, bus1.get()), 5);
401 for (int i = 0; i < channels; ++i) {
402 VerifyResult(bus1->channel(i),
403 5,
404 static_cast<float>(i + 40 * channels),
405 static_cast<float>(channels));
406 }
407
408 // Peek to the end of the buffer.
409 EXPECT_EQ(buffer.forward_frames(), 30);
410 EXPECT_EQ(buffer.PeekFrames(100, bus1.get()), 30);
411 EXPECT_EQ(buffer.PeekFrames(30, bus1.get()), 30);
412 }
413
414 TEST(SeekableAudioBufferTest, Time) {
415 const int channels = 2;
416 const base::TimeDelta start_time1;
417 const base::TimeDelta start_time2 = base::TimeDelta::FromSeconds(30);
418 SeekableAudioBuffer buffer(1000);
419 scoped_ptr<AudioBus> bus = AudioBus::Create(channels, 100);
420
421 // Add two buffers:
422 // first: start=0s, duration=10s
423 // second: start=30s, duration=10s
424 EXPECT_TRUE(buffer.Append(MakeInterleavedBuffer<int16>(
425 kSampleFormatS16, channels, 1, 1, 10, start_time1)));
426 EXPECT_TRUE(buffer.Append(MakeInterleavedBuffer<int16>(
427 kSampleFormatS16, channels, 1, 1, 10, start_time2)));
428 EXPECT_EQ(buffer.forward_frames(), 20);
429
430 // Check starting time.
431 EXPECT_EQ(buffer.current_time(), start_time1);
432
433 // Read 2 frames, should be 2s in (since duration is 1s per sample).
434 EXPECT_EQ(buffer.ReadFrames(2, bus.get()), 2);
435 EXPECT_EQ(buffer.current_time(),
436 start_time1 + base::TimeDelta::FromSeconds(2));
437
438 // Skip 2 frames.
439 EXPECT_TRUE(buffer.SeekFrames(2));
440 EXPECT_EQ(buffer.current_time(),
441 start_time1 + base::TimeDelta::FromSeconds(4));
442
443 // Read until almost the end of buffer1.
444 EXPECT_EQ(buffer.ReadFrames(5, bus.get()), 5);
445 EXPECT_EQ(buffer.current_time(),
446 start_time1 + base::TimeDelta::FromSeconds(9));
447
448 // Read 1 value, so time moved to buffer2.
449 EXPECT_EQ(buffer.ReadFrames(1, bus.get()), 1);
450 EXPECT_EQ(buffer.current_time(), start_time2);
451
452 // Read all 10 frames in buffer2, timestamp should be last time from buffer2.
453 EXPECT_EQ(buffer.ReadFrames(10, bus.get()), 10);
454 EXPECT_EQ(buffer.current_time(),
455 start_time2 + base::TimeDelta::FromSeconds(10));
456
457 // Try to read more frames (which don't exist), timestamp should remain.
458 EXPECT_EQ(buffer.ReadFrames(5, bus.get()), 0);
459 EXPECT_EQ(buffer.current_time(),
460 start_time2 + base::TimeDelta::FromSeconds(10));
461 }
462
463 TEST(SeekableAudioBufferTest, NoTime) {
464 const int channels = 2;
465 SeekableAudioBuffer buffer(1000);
466 scoped_ptr<AudioBus> bus = AudioBus::Create(channels, 100);
467
468 // Add two buffers with no timestamps. Time should always be unknown.
469 EXPECT_TRUE(buffer.Append(MakeInterleavedBuffer<int16>(
470 kSampleFormatS16, channels, 1, 1, 10, kNoTimestamp())));
471 EXPECT_TRUE(buffer.Append(MakeInterleavedBuffer<int16>(
472 kSampleFormatS16, channels, 1, 1, 10, kNoTimestamp())));
473 EXPECT_EQ(buffer.forward_frames(), 20);
474
475 // Check starting time.
476 EXPECT_EQ(buffer.current_time(), kNoTimestamp());
477
478 // Read 2 frames.
479 EXPECT_EQ(buffer.ReadFrames(2, bus.get()), 2);
480 EXPECT_EQ(buffer.current_time(), kNoTimestamp());
481
482 // Skip 2 frames.
483 EXPECT_TRUE(buffer.SeekFrames(2));
484 EXPECT_EQ(buffer.current_time(), kNoTimestamp());
485
486 // Read until almost the end of buffer1.
487 EXPECT_EQ(buffer.ReadFrames(5, bus.get()), 5);
488 EXPECT_EQ(buffer.current_time(), kNoTimestamp());
489
490 // Read 1 value, so time moved to buffer2.
491 EXPECT_EQ(buffer.ReadFrames(1, bus.get()), 1);
492 EXPECT_EQ(buffer.current_time(), kNoTimestamp());
493
494 // Read all 10 frames in buffer2.
495 EXPECT_EQ(buffer.ReadFrames(10, bus.get()), 10);
496 EXPECT_EQ(buffer.current_time(), kNoTimestamp());
497
498 // Try to read more frames (which don't exist), timestamp should remain.
499 EXPECT_EQ(buffer.ReadFrames(5, bus.get()), 0);
500 EXPECT_EQ(buffer.current_time(), kNoTimestamp());
501 }
502
503 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698