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

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

Issue 516113002: Remove time getters from AudioBufferQueue and AudioRendererAlgorithm. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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/audio_buffer_queue.cc ('k') | media/filters/audio_renderer_algorithm.h » ('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 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 "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/logging.h" 6 #include "base/logging.h"
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/time/time.h" 8 #include "base/time/time.h"
9 #include "media/base/audio_buffer.h" 9 #include "media/base/audio_buffer.h"
10 #include "media/base/audio_buffer_queue.h" 10 #include "media/base/audio_buffer_queue.h"
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 bus1->Zero(); 337 bus1->Zero();
338 EXPECT_EQ(5, buffer.PeekFrames(5, 10, 0, bus1.get())); 338 EXPECT_EQ(5, buffer.PeekFrames(5, 10, 0, bus1.get()));
339 VerifyBus(bus1.get(), 0, 5, bus1->frames(), 40, 1); 339 VerifyBus(bus1.get(), 0, 5, bus1->frames(), 40, 1);
340 340
341 // Peek to the end of the buffer. 341 // Peek to the end of the buffer.
342 EXPECT_EQ(30, buffer.frames()); 342 EXPECT_EQ(30, buffer.frames());
343 EXPECT_EQ(30, buffer.PeekFrames(60, 0, 0, bus1.get())); 343 EXPECT_EQ(30, buffer.PeekFrames(60, 0, 0, bus1.get()));
344 EXPECT_EQ(30, buffer.PeekFrames(30, 0, 0, bus1.get())); 344 EXPECT_EQ(30, buffer.PeekFrames(30, 0, 0, bus1.get()));
345 } 345 }
346 346
347 TEST(AudioBufferQueueTest, Time) {
348 const ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO;
349 const int channels = ChannelLayoutToChannelCount(channel_layout);
350 const base::TimeDelta start_time1;
351 const base::TimeDelta start_time2 = base::TimeDelta::FromSeconds(30);
352 AudioBufferQueue buffer;
353 scoped_ptr<AudioBus> bus = AudioBus::Create(channels, 100);
354
355 scoped_refptr<AudioBuffer> audio_buffer =
356 MakeAudioBuffer<int16>(kSampleFormatS16,
357 channel_layout,
358 channels,
359 kSampleRate,
360 1,
361 1,
362 10,
363 start_time1);
364
365 // Add two buffers (second one added later):
366 // first: start=0s, duration=10s
367 // second: start=30s, duration=10s
368 buffer.Append(audio_buffer);
369 EXPECT_EQ(10, buffer.frames());
370
371 // Check starting time.
372 EXPECT_EQ(start_time1, buffer.current_time());
373
374 // Read 2 frames, should be 2s in (since duration is 1s per sample).
375 int frames_read = 2;
376 EXPECT_EQ(frames_read, buffer.ReadFrames(frames_read, 0, bus.get()));
377 EXPECT_EQ(
378 start_time1 +
379 frames_read * audio_buffer->duration() / audio_buffer->frame_count(),
380 buffer.current_time());
381
382 // Skip 2 frames.
383 buffer.SeekFrames(2);
384 frames_read += 2;
385 EXPECT_EQ(
386 start_time1 +
387 frames_read * audio_buffer->duration() / audio_buffer->frame_count(),
388 buffer.current_time());
389
390 // Add second buffer for more data.
391 buffer.Append(MakeAudioBuffer<int16>(kSampleFormatS16,
392 channel_layout,
393 channels,
394 kSampleRate,
395 1,
396 1,
397 10,
398 start_time2));
399 EXPECT_EQ(16, buffer.frames());
400
401 // Read until almost the end of buffer1.
402 frames_read += 5;
403 EXPECT_EQ(5, buffer.ReadFrames(5, 0, bus.get()));
404 EXPECT_EQ(
405 start_time1 +
406 frames_read * audio_buffer->duration() / audio_buffer->frame_count(),
407 buffer.current_time());
408
409 // Read 1 value, so time moved to buffer2.
410 EXPECT_EQ(1, buffer.ReadFrames(1, 0, bus.get()));
411 EXPECT_EQ(start_time2, buffer.current_time());
412
413 // Read all 10 frames in buffer2, timestamp should be last time from buffer2.
414 frames_read = 10;
415 EXPECT_EQ(10, buffer.ReadFrames(10, 0, bus.get()));
416 const base::TimeDelta expected_current_time =
417 start_time2 +
418 frames_read * audio_buffer->duration() / audio_buffer->frame_count();
419 EXPECT_EQ(expected_current_time, buffer.current_time());
420
421 // Try to read more frames (which don't exist), timestamp should remain.
422 EXPECT_EQ(0, buffer.ReadFrames(5, 0, bus.get()));
423 EXPECT_EQ(expected_current_time, buffer.current_time());
424 }
425
426 TEST(AudioBufferQueueTest, NoTime) {
427 const ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO;
428 const int channels = ChannelLayoutToChannelCount(channel_layout);
429 const base::TimeDelta kNoTime = kNoTimestamp();
430 AudioBufferQueue buffer;
431 scoped_ptr<AudioBus> bus = AudioBus::Create(channels, 100);
432
433 // Add two buffers with no timestamps. Time should always be unknown.
434 buffer.Append(
435 MakeTestBuffer<int16>(kSampleFormatS16, channel_layout, 1, 1, 10));
436 buffer.Append(
437 MakeTestBuffer<int16>(kSampleFormatS16, channel_layout, 1, 1, 10));
438 EXPECT_EQ(20, buffer.frames());
439
440 // Check starting time.
441 EXPECT_EQ(kNoTime, buffer.current_time());
442
443 // Read 2 frames.
444 EXPECT_EQ(2, buffer.ReadFrames(2, 0, bus.get()));
445 EXPECT_EQ(kNoTime, buffer.current_time());
446
447 // Skip 2 frames.
448 buffer.SeekFrames(2);
449 EXPECT_EQ(kNoTime, buffer.current_time());
450
451 // Read until almost the end of buffer1.
452 EXPECT_EQ(5, buffer.ReadFrames(5, 0, bus.get()));
453 EXPECT_EQ(kNoTime, buffer.current_time());
454
455 // Read 1 value, so time moved to buffer2.
456 EXPECT_EQ(1, buffer.ReadFrames(1, 0, bus.get()));
457 EXPECT_EQ(kNoTime, buffer.current_time());
458
459 // Read all 10 frames in buffer2.
460 EXPECT_EQ(10, buffer.ReadFrames(10, 0, bus.get()));
461 EXPECT_EQ(kNoTime, buffer.current_time());
462
463 // Try to read more frames (which don't exist), timestamp should remain.
464 EXPECT_EQ(0, buffer.ReadFrames(5, 0, bus.get()));
465 EXPECT_EQ(kNoTime, buffer.current_time());
466 }
467
468 } // namespace media 347 } // namespace media
OLDNEW
« no previous file with comments | « media/base/audio_buffer_queue.cc ('k') | media/filters/audio_renderer_algorithm.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698