| OLD | NEW |
| 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/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
| 9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
| 10 #include "media/base/audio_buffer.h" | 10 #include "media/base/audio_buffer.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 | 32 |
| 33 template <typename T> | 33 template <typename T> |
| 34 static scoped_refptr<AudioBuffer> MakeTestBuffer(SampleFormat format, | 34 static scoped_refptr<AudioBuffer> MakeTestBuffer(SampleFormat format, |
| 35 ChannelLayout channel_layout, | 35 ChannelLayout channel_layout, |
| 36 T start, | 36 T start, |
| 37 T end, | 37 T end, |
| 38 int frames) { | 38 int frames) { |
| 39 const base::TimeDelta kNoTime = kNoTimestamp(); | 39 const base::TimeDelta kNoTime = kNoTimestamp(); |
| 40 return MakeAudioBuffer<T>(format, | 40 return MakeAudioBuffer<T>(format, |
| 41 channel_layout, | 41 channel_layout, |
| 42 ChannelLayoutToChannelCount(channel_layout), |
| 42 kSampleRate, | 43 kSampleRate, |
| 43 start, | 44 start, |
| 44 end, | 45 end, |
| 45 frames, | 46 frames, |
| 46 kNoTime, | 47 kNoTime, |
| 47 kNoTime); | 48 kNoTime); |
| 48 } | 49 } |
| 49 | 50 |
| 50 TEST(AudioBufferQueueTest, AppendAndClear) { | 51 TEST(AudioBufferQueueTest, AppendAndClear) { |
| 51 const ChannelLayout channel_layout = CHANNEL_LAYOUT_MONO; | 52 const ChannelLayout channel_layout = CHANNEL_LAYOUT_MONO; |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 const base::TimeDelta start_time2 = base::TimeDelta::FromSeconds(30); | 382 const base::TimeDelta start_time2 = base::TimeDelta::FromSeconds(30); |
| 382 const base::TimeDelta duration = base::TimeDelta::FromSeconds(10); | 383 const base::TimeDelta duration = base::TimeDelta::FromSeconds(10); |
| 383 AudioBufferQueue buffer; | 384 AudioBufferQueue buffer; |
| 384 scoped_ptr<AudioBus> bus = AudioBus::Create(channels, 100); | 385 scoped_ptr<AudioBus> bus = AudioBus::Create(channels, 100); |
| 385 | 386 |
| 386 // Add two buffers (second one added later): | 387 // Add two buffers (second one added later): |
| 387 // first: start=0s, duration=10s | 388 // first: start=0s, duration=10s |
| 388 // second: start=30s, duration=10s | 389 // second: start=30s, duration=10s |
| 389 buffer.Append(MakeAudioBuffer<int16>(kSampleFormatS16, | 390 buffer.Append(MakeAudioBuffer<int16>(kSampleFormatS16, |
| 390 channel_layout, | 391 channel_layout, |
| 392 channels, |
| 391 kSampleRate, | 393 kSampleRate, |
| 392 1, | 394 1, |
| 393 1, | 395 1, |
| 394 10, | 396 10, |
| 395 start_time1, | 397 start_time1, |
| 396 duration)); | 398 duration)); |
| 397 EXPECT_EQ(10, buffer.frames()); | 399 EXPECT_EQ(10, buffer.frames()); |
| 398 | 400 |
| 399 // Check starting time. | 401 // Check starting time. |
| 400 EXPECT_EQ(start_time1, buffer.current_time()); | 402 EXPECT_EQ(start_time1, buffer.current_time()); |
| 401 | 403 |
| 402 // Read 2 frames, should be 2s in (since duration is 1s per sample). | 404 // Read 2 frames, should be 2s in (since duration is 1s per sample). |
| 403 EXPECT_EQ(2, buffer.ReadFrames(2, 0, bus.get())); | 405 EXPECT_EQ(2, buffer.ReadFrames(2, 0, bus.get())); |
| 404 EXPECT_EQ(start_time1 + base::TimeDelta::FromSeconds(2), | 406 EXPECT_EQ(start_time1 + base::TimeDelta::FromSeconds(2), |
| 405 buffer.current_time()); | 407 buffer.current_time()); |
| 406 | 408 |
| 407 // Skip 2 frames. | 409 // Skip 2 frames. |
| 408 buffer.SeekFrames(2); | 410 buffer.SeekFrames(2); |
| 409 EXPECT_EQ(start_time1 + base::TimeDelta::FromSeconds(4), | 411 EXPECT_EQ(start_time1 + base::TimeDelta::FromSeconds(4), |
| 410 buffer.current_time()); | 412 buffer.current_time()); |
| 411 | 413 |
| 412 // Add second buffer for more data. | 414 // Add second buffer for more data. |
| 413 buffer.Append(MakeAudioBuffer<int16>(kSampleFormatS16, | 415 buffer.Append(MakeAudioBuffer<int16>(kSampleFormatS16, |
| 414 channel_layout, | 416 channel_layout, |
| 417 channels, |
| 415 kSampleRate, | 418 kSampleRate, |
| 416 1, | 419 1, |
| 417 1, | 420 1, |
| 418 10, | 421 10, |
| 419 start_time2, | 422 start_time2, |
| 420 duration)); | 423 duration)); |
| 421 EXPECT_EQ(16, buffer.frames()); | 424 EXPECT_EQ(16, buffer.frames()); |
| 422 | 425 |
| 423 // Read until almost the end of buffer1. | 426 // Read until almost the end of buffer1. |
| 424 EXPECT_EQ(5, buffer.ReadFrames(5, 0, bus.get())); | 427 EXPECT_EQ(5, buffer.ReadFrames(5, 0, bus.get())); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 // Read all 10 frames in buffer2. | 479 // Read all 10 frames in buffer2. |
| 477 EXPECT_EQ(10, buffer.ReadFrames(10, 0, bus.get())); | 480 EXPECT_EQ(10, buffer.ReadFrames(10, 0, bus.get())); |
| 478 EXPECT_EQ(kNoTime, buffer.current_time()); | 481 EXPECT_EQ(kNoTime, buffer.current_time()); |
| 479 | 482 |
| 480 // Try to read more frames (which don't exist), timestamp should remain. | 483 // Try to read more frames (which don't exist), timestamp should remain. |
| 481 EXPECT_EQ(0, buffer.ReadFrames(5, 0, bus.get())); | 484 EXPECT_EQ(0, buffer.ReadFrames(5, 0, bus.get())); |
| 482 EXPECT_EQ(kNoTime, buffer.current_time()); | 485 EXPECT_EQ(kNoTime, buffer.current_time()); |
| 483 } | 486 } |
| 484 | 487 |
| 485 } // namespace media | 488 } // namespace media |
| OLD | NEW |