Chromium Code Reviews| 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 <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 730 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 741 EXPECT_EQ(frames_read, bus->frames()); | 741 EXPECT_EQ(frames_read, bus->frames()); |
| 742 const int zero_frames = | 742 const int zero_frames = |
| 743 bus->frames() * (kBuffers - static_cast<int>(kBuffers)); | 743 bus->frames() * (kBuffers - static_cast<int>(kBuffers)); |
| 744 | 744 |
| 745 for (int i = 0; i < zero_frames; ++i) | 745 for (int i = 0; i < zero_frames; ++i) |
| 746 ASSERT_FLOAT_EQ(0.0f, bus->channel(0)[i]); | 746 ASSERT_FLOAT_EQ(0.0f, bus->channel(0)[i]); |
| 747 for (int i = zero_frames; i < bus->frames(); ++i) | 747 for (int i = zero_frames; i < bus->frames(); ++i) |
| 748 ASSERT_NE(0.0f, bus->channel(0)[i]); | 748 ASSERT_NE(0.0f, bus->channel(0)[i]); |
| 749 } | 749 } |
| 750 | 750 |
| 751 TEST_F(AudioRendererImplTest, RenderingDelayedForSuspend) { | |
| 752 Initialize(); | |
| 753 Preroll(base::TimeDelta(), base::TimeDelta(), PIPELINE_OK); | |
| 754 StartTicking(); | |
| 755 | |
| 756 // Verify the first buffer is real data. | |
| 757 int frames_read = 0; | |
| 758 std::unique_ptr<AudioBus> bus = AudioBus::Create(hardware_params_); | |
| 759 EXPECT_TRUE(sink_->Render(bus.get(), 0, &frames_read)); | |
| 760 EXPECT_NE(0, frames_read); | |
| 761 for (int i = 0; i < bus->frames(); ++i) | |
| 762 ASSERT_NE(0.0f, bus->channel(0)[i]); | |
| 763 | |
| 764 // Verify after suspend we get silence. | |
| 765 renderer_->OnSuspend(); | |
|
xhwang
2016/06/17 07:12:52
Can you actually use TestPowerMonitorSource so we
| |
| 766 EXPECT_TRUE(sink_->Render(bus.get(), 0, &frames_read)); | |
| 767 EXPECT_EQ(0, frames_read); | |
| 768 | |
| 769 // Verify after resume we get audio. | |
| 770 bus->Zero(); | |
| 771 renderer_->OnResume(); | |
| 772 EXPECT_TRUE(sink_->Render(bus.get(), 0, &frames_read)); | |
| 773 EXPECT_NE(0, frames_read); | |
| 774 for (int i = 0; i < bus->frames(); ++i) | |
| 775 ASSERT_NE(0.0f, bus->channel(0)[i]); | |
| 776 } | |
| 777 | |
| 751 TEST_F(AudioRendererImplTest, RenderingDelayDoesNotOverflow) { | 778 TEST_F(AudioRendererImplTest, RenderingDelayDoesNotOverflow) { |
| 752 Initialize(); | 779 Initialize(); |
| 753 | 780 |
| 754 // Choose a first timestamp as far into the future as possible. Without care | 781 // Choose a first timestamp as far into the future as possible. Without care |
| 755 // this can cause an overflow in rendering arithmetic. | 782 // this can cause an overflow in rendering arithmetic. |
| 756 Preroll(base::TimeDelta(), base::TimeDelta::Max(), PIPELINE_OK); | 783 Preroll(base::TimeDelta(), base::TimeDelta::Max(), PIPELINE_OK); |
| 757 StartTicking(); | 784 StartTicking(); |
| 758 EXPECT_TRUE(ConsumeBufferedData(OutputFrames(1))); | 785 EXPECT_TRUE(ConsumeBufferedData(OutputFrames(1))); |
| 759 } | 786 } |
| 760 | 787 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 852 OutputFrames frames_to_consume(frames_buffered().value / 2); | 879 OutputFrames frames_to_consume(frames_buffered().value / 2); |
| 853 EXPECT_TRUE(ConsumeBufferedData(frames_to_consume)); | 880 EXPECT_TRUE(ConsumeBufferedData(frames_to_consume)); |
| 854 WaitForPendingRead(); | 881 WaitForPendingRead(); |
| 855 | 882 |
| 856 // Time shouldn't change just yet because we've only sent the initial audio | 883 // Time shouldn't change just yet because we've only sent the initial audio |
| 857 // data to the hardware. | 884 // data to the hardware. |
| 858 EXPECT_EQ(tick_clock_->NowTicks(), | 885 EXPECT_EQ(tick_clock_->NowTicks(), |
| 859 ConvertMediaTime(base::TimeDelta(), &is_time_moving)); | 886 ConvertMediaTime(base::TimeDelta(), &is_time_moving)); |
| 860 EXPECT_TRUE(is_time_moving); | 887 EXPECT_TRUE(is_time_moving); |
| 861 | 888 |
| 889 // A system suspend should freeze the time state and resume restart it. | |
| 890 renderer_->OnSuspend(); | |
| 891 EXPECT_EQ(tick_clock_->NowTicks(), | |
| 892 ConvertMediaTime(base::TimeDelta(), &is_time_moving)); | |
| 893 EXPECT_FALSE(is_time_moving); | |
| 894 renderer_->OnResume(); | |
| 895 EXPECT_EQ(tick_clock_->NowTicks(), | |
| 896 ConvertMediaTime(base::TimeDelta(), &is_time_moving)); | |
| 897 EXPECT_TRUE(is_time_moving); | |
| 898 | |
| 862 // Consume some more audio data. | 899 // Consume some more audio data. |
| 863 frames_to_consume = frames_buffered(); | 900 frames_to_consume = frames_buffered(); |
| 864 tick_clock_->Advance( | 901 tick_clock_->Advance( |
| 865 base::TimeDelta::FromSecondsD(1.0 / kOutputSamplesPerSecond)); | 902 base::TimeDelta::FromSecondsD(1.0 / kOutputSamplesPerSecond)); |
| 866 EXPECT_TRUE(ConsumeBufferedData(frames_to_consume)); | 903 EXPECT_TRUE(ConsumeBufferedData(frames_to_consume)); |
| 867 | 904 |
| 868 // Time should change now that the audio hardware has called back. | 905 // Time should change now that the audio hardware has called back. |
| 869 const base::TimeTicks wall_clock_time_zero = | 906 const base::TimeTicks wall_clock_time_zero = |
| 870 tick_clock_->NowTicks() - | 907 tick_clock_->NowTicks() - |
| 871 timestamp_helper.GetFrameDuration(frames_to_consume.value); | 908 timestamp_helper.GetFrameDuration(frames_to_consume.value); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 942 // Advance far enough that we shouldn't be clamped to current time (tested | 979 // Advance far enough that we shouldn't be clamped to current time (tested |
| 943 // already above). | 980 // already above). |
| 944 tick_clock_->Advance(kOneSecond); | 981 tick_clock_->Advance(kOneSecond); |
| 945 EXPECT_EQ( | 982 EXPECT_EQ( |
| 946 current_time + timestamp_helper.GetFrameDuration(frames_to_consume.value), | 983 current_time + timestamp_helper.GetFrameDuration(frames_to_consume.value), |
| 947 CurrentMediaWallClockTime(&is_time_moving)); | 984 CurrentMediaWallClockTime(&is_time_moving)); |
| 948 EXPECT_TRUE(is_time_moving); | 985 EXPECT_TRUE(is_time_moving); |
| 949 } | 986 } |
| 950 | 987 |
| 951 } // namespace media | 988 } // namespace media |
| OLD | NEW |