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

Side by Side Diff: media/renderers/audio_renderer_impl_unittest.cc

Issue 2089503002: Merge M52: "Freeze media time and audio rendering when the system suspends." (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2743
Patch Set: Created 4 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
« no previous file with comments | « media/renderers/audio_renderer_impl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 729 matching lines...) Expand 10 before | Expand all | Expand 10 after
740 EXPECT_EQ(frames_read, bus->frames()); 740 EXPECT_EQ(frames_read, bus->frames());
741 const int zero_frames = 741 const int zero_frames =
742 bus->frames() * (kBuffers - static_cast<int>(kBuffers)); 742 bus->frames() * (kBuffers - static_cast<int>(kBuffers));
743 743
744 for (int i = 0; i < zero_frames; ++i) 744 for (int i = 0; i < zero_frames; ++i)
745 ASSERT_FLOAT_EQ(0.0f, bus->channel(0)[i]); 745 ASSERT_FLOAT_EQ(0.0f, bus->channel(0)[i]);
746 for (int i = zero_frames; i < bus->frames(); ++i) 746 for (int i = zero_frames; i < bus->frames(); ++i)
747 ASSERT_NE(0.0f, bus->channel(0)[i]); 747 ASSERT_NE(0.0f, bus->channel(0)[i]);
748 } 748 }
749 749
750 TEST_F(AudioRendererImplTest, RenderingDelayedForSuspend) {
751 Initialize();
752 Preroll(base::TimeDelta(), base::TimeDelta(), PIPELINE_OK);
753 StartTicking();
754
755 // Verify the first buffer is real data.
756 int frames_read = 0;
757 std::unique_ptr<AudioBus> bus = AudioBus::Create(hardware_params_);
758 EXPECT_TRUE(sink_->Render(bus.get(), 0, &frames_read));
759 EXPECT_NE(0, frames_read);
760 for (int i = 0; i < bus->frames(); ++i)
761 ASSERT_NE(0.0f, bus->channel(0)[i]);
762
763 // Verify after suspend we get silence.
764 renderer_->OnSuspend();
765 EXPECT_TRUE(sink_->Render(bus.get(), 0, &frames_read));
766 EXPECT_EQ(0, frames_read);
767
768 // Verify after resume we get audio.
769 bus->Zero();
770 renderer_->OnResume();
771 EXPECT_TRUE(sink_->Render(bus.get(), 0, &frames_read));
772 EXPECT_NE(0, frames_read);
773 for (int i = 0; i < bus->frames(); ++i)
774 ASSERT_NE(0.0f, bus->channel(0)[i]);
775 }
776
750 TEST_F(AudioRendererImplTest, RenderingDelayDoesNotOverflow) { 777 TEST_F(AudioRendererImplTest, RenderingDelayDoesNotOverflow) {
751 Initialize(); 778 Initialize();
752 779
753 // Choose a first timestamp as far into the future as possible. Without care 780 // Choose a first timestamp as far into the future as possible. Without care
754 // this can cause an overflow in rendering arithmetic. 781 // this can cause an overflow in rendering arithmetic.
755 Preroll(base::TimeDelta(), base::TimeDelta::Max(), PIPELINE_OK); 782 Preroll(base::TimeDelta(), base::TimeDelta::Max(), PIPELINE_OK);
756 StartTicking(); 783 StartTicking();
757 EXPECT_TRUE(ConsumeBufferedData(OutputFrames(1))); 784 EXPECT_TRUE(ConsumeBufferedData(OutputFrames(1)));
758 } 785 }
759 786
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
851 OutputFrames frames_to_consume(frames_buffered().value / 2); 878 OutputFrames frames_to_consume(frames_buffered().value / 2);
852 EXPECT_TRUE(ConsumeBufferedData(frames_to_consume)); 879 EXPECT_TRUE(ConsumeBufferedData(frames_to_consume));
853 WaitForPendingRead(); 880 WaitForPendingRead();
854 881
855 // Time shouldn't change just yet because we've only sent the initial audio 882 // Time shouldn't change just yet because we've only sent the initial audio
856 // data to the hardware. 883 // data to the hardware.
857 EXPECT_EQ(tick_clock_->NowTicks(), 884 EXPECT_EQ(tick_clock_->NowTicks(),
858 ConvertMediaTime(base::TimeDelta(), &is_time_moving)); 885 ConvertMediaTime(base::TimeDelta(), &is_time_moving));
859 EXPECT_TRUE(is_time_moving); 886 EXPECT_TRUE(is_time_moving);
860 887
888 // A system suspend should freeze the time state and resume restart it.
889 renderer_->OnSuspend();
890 EXPECT_EQ(tick_clock_->NowTicks(),
891 ConvertMediaTime(base::TimeDelta(), &is_time_moving));
892 EXPECT_FALSE(is_time_moving);
893 renderer_->OnResume();
894 EXPECT_EQ(tick_clock_->NowTicks(),
895 ConvertMediaTime(base::TimeDelta(), &is_time_moving));
896 EXPECT_TRUE(is_time_moving);
897
861 // Consume some more audio data. 898 // Consume some more audio data.
862 frames_to_consume = frames_buffered(); 899 frames_to_consume = frames_buffered();
863 tick_clock_->Advance( 900 tick_clock_->Advance(
864 base::TimeDelta::FromSecondsD(1.0 / kOutputSamplesPerSecond)); 901 base::TimeDelta::FromSecondsD(1.0 / kOutputSamplesPerSecond));
865 EXPECT_TRUE(ConsumeBufferedData(frames_to_consume)); 902 EXPECT_TRUE(ConsumeBufferedData(frames_to_consume));
866 903
867 // Time should change now that the audio hardware has called back. 904 // Time should change now that the audio hardware has called back.
868 const base::TimeTicks wall_clock_time_zero = 905 const base::TimeTicks wall_clock_time_zero =
869 tick_clock_->NowTicks() - 906 tick_clock_->NowTicks() -
870 timestamp_helper.GetFrameDuration(frames_to_consume.value); 907 timestamp_helper.GetFrameDuration(frames_to_consume.value);
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
941 // Advance far enough that we shouldn't be clamped to current time (tested 978 // Advance far enough that we shouldn't be clamped to current time (tested
942 // already above). 979 // already above).
943 tick_clock_->Advance(kOneSecond); 980 tick_clock_->Advance(kOneSecond);
944 EXPECT_EQ( 981 EXPECT_EQ(
945 current_time + timestamp_helper.GetFrameDuration(frames_to_consume.value), 982 current_time + timestamp_helper.GetFrameDuration(frames_to_consume.value),
946 CurrentMediaWallClockTime(&is_time_moving)); 983 CurrentMediaWallClockTime(&is_time_moving));
947 EXPECT_TRUE(is_time_moving); 984 EXPECT_TRUE(is_time_moving);
948 } 985 }
949 986
950 } // namespace media 987 } // namespace media
OLDNEW
« no previous file with comments | « media/renderers/audio_renderer_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698