OLD | NEW |
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/renderers/audio_renderer_impl.h" | 5 #include "media/renderers/audio_renderer_impl.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 // Constants to specify the type of audio data used. | 49 // Constants to specify the type of audio data used. |
50 static AudioCodec kCodec = kCodecVorbis; | 50 static AudioCodec kCodec = kCodecVorbis; |
51 static SampleFormat kSampleFormat = kSampleFormatPlanarF32; | 51 static SampleFormat kSampleFormat = kSampleFormatPlanarF32; |
52 static ChannelLayout kChannelLayout = CHANNEL_LAYOUT_STEREO; | 52 static ChannelLayout kChannelLayout = CHANNEL_LAYOUT_STEREO; |
53 static int kChannelCount = 2; | 53 static int kChannelCount = 2; |
54 static int kChannels = ChannelLayoutToChannelCount(kChannelLayout); | 54 static int kChannels = ChannelLayoutToChannelCount(kChannelLayout); |
55 | 55 |
56 // Use a different output sample rate so the AudioBufferConverter is invoked. | 56 // Use a different output sample rate so the AudioBufferConverter is invoked. |
57 static int kInputSamplesPerSecond = 5000; | 57 static int kInputSamplesPerSecond = 5000; |
58 static int kOutputSamplesPerSecond = 10000; | 58 static int kOutputSamplesPerSecond = 10000; |
| 59 static double kOutputMicrosPerFrame = |
| 60 static_cast<double>(base::Time::kMicrosecondsPerSecond) / |
| 61 kOutputSamplesPerSecond; |
59 | 62 |
60 ACTION_P(EnterPendingDecoderInitStateAction, test) { | 63 ACTION_P(EnterPendingDecoderInitStateAction, test) { |
61 test->EnterPendingDecoderInitState(arg2); | 64 test->EnterPendingDecoderInitState(arg2); |
62 } | 65 } |
63 | 66 |
64 class AudioRendererImplTest : public ::testing::Test { | 67 class AudioRendererImplTest : public ::testing::Test { |
65 public: | 68 public: |
66 // Give the decoder some non-garbage media properties. | 69 // Give the decoder some non-garbage media properties. |
67 AudioRendererImplTest() | 70 AudioRendererImplTest() |
68 : hardware_config_(AudioParameters(), AudioParameters()), | 71 : hardware_config_(AudioParameters(), AudioParameters()), |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 void DeliverRemainingAudio() { | 294 void DeliverRemainingAudio() { |
292 while (frames_remaining_in_buffer().value > 0) { | 295 while (frames_remaining_in_buffer().value > 0) { |
293 SatisfyPendingRead(InputFrames(256)); | 296 SatisfyPendingRead(InputFrames(256)); |
294 } | 297 } |
295 } | 298 } |
296 | 299 |
297 // Attempts to consume |requested_frames| frames from |renderer_|'s internal | 300 // Attempts to consume |requested_frames| frames from |renderer_|'s internal |
298 // buffer. Returns true if and only if all of |requested_frames| were able | 301 // buffer. Returns true if and only if all of |requested_frames| were able |
299 // to be consumed. | 302 // to be consumed. |
300 bool ConsumeBufferedData(OutputFrames requested_frames, | 303 bool ConsumeBufferedData(OutputFrames requested_frames, |
301 base::TimeDelta delay) { | 304 uint32_t delay_frames) { |
302 scoped_ptr<AudioBus> bus = | 305 scoped_ptr<AudioBus> bus = |
303 AudioBus::Create(kChannels, requested_frames.value); | 306 AudioBus::Create(kChannels, requested_frames.value); |
304 int frames_read = 0; | 307 int frames_read = 0; |
305 EXPECT_TRUE(sink_->Render(bus.get(), delay.InMilliseconds(), &frames_read)); | 308 EXPECT_TRUE(sink_->Render(bus.get(), delay_frames, &frames_read)); |
306 return frames_read == requested_frames.value; | 309 return frames_read == requested_frames.value; |
307 } | 310 } |
308 | 311 |
309 bool ConsumeBufferedData(OutputFrames requested_frames) { | 312 bool ConsumeBufferedData(OutputFrames requested_frames) { |
310 return ConsumeBufferedData(requested_frames, base::TimeDelta()); | 313 return ConsumeBufferedData(requested_frames, 0); |
311 } | 314 } |
312 | 315 |
313 base::TimeTicks ConvertMediaTime(base::TimeDelta timestamp, | 316 base::TimeTicks ConvertMediaTime(base::TimeDelta timestamp, |
314 bool* is_time_moving) { | 317 bool* is_time_moving) { |
315 std::vector<base::TimeTicks> wall_clock_times; | 318 std::vector<base::TimeTicks> wall_clock_times; |
316 *is_time_moving = renderer_->GetWallClockTimes( | 319 *is_time_moving = renderer_->GetWallClockTimes( |
317 std::vector<base::TimeDelta>(1, timestamp), &wall_clock_times); | 320 std::vector<base::TimeDelta>(1, timestamp), &wall_clock_times); |
318 return wall_clock_times[0]; | 321 return wall_clock_times[0]; |
319 } | 322 } |
320 | 323 |
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
863 // Elapse a lot of time between StopTicking() and the next Render() call. | 866 // Elapse a lot of time between StopTicking() and the next Render() call. |
864 const base::TimeDelta kOneSecond = base::TimeDelta::FromSeconds(1); | 867 const base::TimeDelta kOneSecond = base::TimeDelta::FromSeconds(1); |
865 tick_clock_->Advance(kOneSecond); | 868 tick_clock_->Advance(kOneSecond); |
866 StartTicking(); | 869 StartTicking(); |
867 | 870 |
868 // Time should be stopped until the next render call. | 871 // Time should be stopped until the next render call. |
869 EXPECT_EQ(current_time, CurrentMediaWallClockTime(&is_time_moving)); | 872 EXPECT_EQ(current_time, CurrentMediaWallClockTime(&is_time_moving)); |
870 EXPECT_FALSE(is_time_moving); | 873 EXPECT_FALSE(is_time_moving); |
871 | 874 |
872 // Consume some buffered data with a small delay. | 875 // Consume some buffered data with a small delay. |
873 base::TimeDelta delay_time = base::TimeDelta::FromMilliseconds(50); | 876 uint32_t delay_frames = 500; |
| 877 base::TimeDelta delay_time = base::TimeDelta::FromMicroseconds( |
| 878 std::round(delay_frames * kOutputMicrosPerFrame)); |
| 879 |
874 frames_to_consume.value = frames_buffered().value / 16; | 880 frames_to_consume.value = frames_buffered().value / 16; |
875 EXPECT_TRUE(ConsumeBufferedData(frames_to_consume, delay_time)); | 881 EXPECT_TRUE(ConsumeBufferedData(frames_to_consume, delay_frames)); |
876 | 882 |
877 // Verify time is adjusted for the current delay. | 883 // Verify time is adjusted for the current delay. |
878 current_time = tick_clock_->NowTicks() + delay_time; | 884 current_time = tick_clock_->NowTicks() + delay_time; |
879 EXPECT_EQ(current_time, CurrentMediaWallClockTime(&is_time_moving)); | 885 EXPECT_EQ(current_time, CurrentMediaWallClockTime(&is_time_moving)); |
880 EXPECT_TRUE(is_time_moving); | 886 EXPECT_TRUE(is_time_moving); |
881 EXPECT_EQ(current_time, | 887 EXPECT_EQ(current_time, |
882 ConvertMediaTime(renderer_->CurrentMediaTime(), &is_time_moving)); | 888 ConvertMediaTime(renderer_->CurrentMediaTime(), &is_time_moving)); |
883 EXPECT_TRUE(is_time_moving); | 889 EXPECT_TRUE(is_time_moving); |
884 | 890 |
885 // Advance far enough that we shouldn't be clamped to current time (tested | 891 // Advance far enough that we shouldn't be clamped to current time (tested |
886 // already above). | 892 // already above). |
887 tick_clock_->Advance(kOneSecond); | 893 tick_clock_->Advance(kOneSecond); |
888 EXPECT_EQ( | 894 EXPECT_EQ( |
889 current_time + timestamp_helper.GetFrameDuration(frames_to_consume.value), | 895 current_time + timestamp_helper.GetFrameDuration(frames_to_consume.value), |
890 CurrentMediaWallClockTime(&is_time_moving)); | 896 CurrentMediaWallClockTime(&is_time_moving)); |
891 EXPECT_TRUE(is_time_moving); | 897 EXPECT_TRUE(is_time_moving); |
892 } | 898 } |
893 | 899 |
894 } // namespace media | 900 } // namespace media |
OLD | NEW |