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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 CHECK(!ended_); | 125 CHECK(!ended_); |
126 ended_ = true; | 126 ended_ = true; |
127 } | 127 } |
128 void OnStatisticsUpdate(const PipelineStatistics& stats) override { | 128 void OnStatisticsUpdate(const PipelineStatistics& stats) override { |
129 last_statistics_.audio_memory_usage += stats.audio_memory_usage; | 129 last_statistics_.audio_memory_usage += stats.audio_memory_usage; |
130 } | 130 } |
131 MOCK_METHOD1(OnBufferingStateChange, void(BufferingState)); | 131 MOCK_METHOD1(OnBufferingStateChange, void(BufferingState)); |
132 MOCK_METHOD0(OnWaitingForDecryptionKey, void(void)); | 132 MOCK_METHOD0(OnWaitingForDecryptionKey, void(void)); |
133 MOCK_METHOD1(OnVideoNaturalSizeChange, void(const gfx::Size&)); | 133 MOCK_METHOD1(OnVideoNaturalSizeChange, void(const gfx::Size&)); |
134 MOCK_METHOD1(OnVideoOpacityChange, void(bool)); | 134 MOCK_METHOD1(OnVideoOpacityChange, void(bool)); |
| 135 MOCK_METHOD3(OnTimeUpdate, |
| 136 void(base::TimeDelta, base::TimeDelta, base::TimeTicks)); |
135 | 137 |
136 void InitializeRenderer(const PipelineStatusCB& pipeline_status_cb) { | 138 void InitializeRenderer(const PipelineStatusCB& pipeline_status_cb) { |
137 EXPECT_CALL(*this, OnWaitingForDecryptionKey()).Times(0); | 139 EXPECT_CALL(*this, OnWaitingForDecryptionKey()).Times(0); |
138 EXPECT_CALL(*this, OnVideoNaturalSizeChange(_)).Times(0); | 140 EXPECT_CALL(*this, OnVideoNaturalSizeChange(_)).Times(0); |
139 EXPECT_CALL(*this, OnVideoOpacityChange(_)).Times(0); | 141 EXPECT_CALL(*this, OnVideoOpacityChange(_)).Times(0); |
140 renderer_->Initialize(&demuxer_stream_, nullptr, this, pipeline_status_cb); | 142 renderer_->Initialize(&demuxer_stream_, nullptr, this, pipeline_status_cb); |
141 } | 143 } |
142 | 144 |
143 void Initialize() { | 145 void Initialize() { |
144 EXPECT_CALL(*decoder_, Initialize(_, _, _, _)) | 146 EXPECT_CALL(*decoder_, Initialize(_, _, _, _)) |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 InputFrames converter_input_frames_left() const { | 354 InputFrames converter_input_frames_left() const { |
353 return InputFrames( | 355 return InputFrames( |
354 renderer_->buffer_converter_->input_frames_left_for_testing()); | 356 renderer_->buffer_converter_->input_frames_left_for_testing()); |
355 } | 357 } |
356 | 358 |
357 bool splicer_has_next_buffer() const { | 359 bool splicer_has_next_buffer() const { |
358 return renderer_->splicer_->HasNextBuffer(); | 360 return renderer_->splicer_->HasNextBuffer(); |
359 } | 361 } |
360 | 362 |
361 base::TimeDelta CurrentMediaTime() { | 363 base::TimeDelta CurrentMediaTime() { |
362 return renderer_->CurrentMediaTime(); | 364 return renderer_->CurrentMediaTime(nullptr); |
363 } | 365 } |
364 | 366 |
365 bool ended() const { return ended_; } | 367 bool ended() const { return ended_; } |
366 | 368 |
367 // Fixture members. | 369 // Fixture members. |
368 AudioParameters hardware_params_; | 370 AudioParameters hardware_params_; |
369 base::MessageLoop message_loop_; | 371 base::MessageLoop message_loop_; |
370 std::unique_ptr<AudioRendererImpl> renderer_; | 372 std::unique_ptr<AudioRendererImpl> renderer_; |
371 scoped_refptr<FakeAudioRendererSink> sink_; | 373 scoped_refptr<FakeAudioRendererSink> sink_; |
372 base::SimpleTestTickClock* tick_clock_; | 374 base::SimpleTestTickClock* tick_clock_; |
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
906 // Time should change now that the audio hardware has called back. | 908 // Time should change now that the audio hardware has called back. |
907 const base::TimeTicks wall_clock_time_zero = | 909 const base::TimeTicks wall_clock_time_zero = |
908 tick_clock_->NowTicks() - | 910 tick_clock_->NowTicks() - |
909 timestamp_helper.GetFrameDuration(frames_to_consume.value); | 911 timestamp_helper.GetFrameDuration(frames_to_consume.value); |
910 EXPECT_EQ(wall_clock_time_zero, | 912 EXPECT_EQ(wall_clock_time_zero, |
911 ConvertMediaTime(base::TimeDelta(), &is_time_moving)); | 913 ConvertMediaTime(base::TimeDelta(), &is_time_moving)); |
912 EXPECT_TRUE(is_time_moving); | 914 EXPECT_TRUE(is_time_moving); |
913 | 915 |
914 // Store current media time before advancing the tick clock since the call is | 916 // Store current media time before advancing the tick clock since the call is |
915 // compensated based on TimeTicks::Now(). | 917 // compensated based on TimeTicks::Now(). |
916 const base::TimeDelta current_media_time = renderer_->CurrentMediaTime(); | 918 const base::TimeDelta current_media_time = |
| 919 renderer_->CurrentMediaTime(nullptr); |
917 | 920 |
918 // The current wall clock time should change as our tick clock advances, up | 921 // The current wall clock time should change as our tick clock advances, up |
919 // until we've reached the end of played out frames. | 922 // until we've reached the end of played out frames. |
920 const int kSteps = 4; | 923 const int kSteps = 4; |
921 const base::TimeDelta kAdvanceDelta = | 924 const base::TimeDelta kAdvanceDelta = |
922 timestamp_helper.GetFrameDuration(frames_to_consume.value) / kSteps; | 925 timestamp_helper.GetFrameDuration(frames_to_consume.value) / kSteps; |
923 | 926 |
924 for (int i = 0; i < kSteps; ++i) { | 927 for (int i = 0; i < kSteps; ++i) { |
925 tick_clock_->Advance(kAdvanceDelta); | 928 tick_clock_->Advance(kAdvanceDelta); |
926 EXPECT_EQ(tick_clock_->NowTicks(), | 929 EXPECT_EQ(tick_clock_->NowTicks(), |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
958 base::TimeDelta delay_time = base::TimeDelta::FromMicroseconds( | 961 base::TimeDelta delay_time = base::TimeDelta::FromMicroseconds( |
959 std::round(delay_frames * kOutputMicrosPerFrame)); | 962 std::round(delay_frames * kOutputMicrosPerFrame)); |
960 | 963 |
961 frames_to_consume.value = frames_buffered().value / 16; | 964 frames_to_consume.value = frames_buffered().value / 16; |
962 EXPECT_TRUE(ConsumeBufferedData(frames_to_consume, delay_frames)); | 965 EXPECT_TRUE(ConsumeBufferedData(frames_to_consume, delay_frames)); |
963 | 966 |
964 // Verify time is adjusted for the current delay. | 967 // Verify time is adjusted for the current delay. |
965 current_time = tick_clock_->NowTicks() + delay_time; | 968 current_time = tick_clock_->NowTicks() + delay_time; |
966 EXPECT_EQ(current_time, CurrentMediaWallClockTime(&is_time_moving)); | 969 EXPECT_EQ(current_time, CurrentMediaWallClockTime(&is_time_moving)); |
967 EXPECT_TRUE(is_time_moving); | 970 EXPECT_TRUE(is_time_moving); |
968 EXPECT_EQ(current_time, | 971 EXPECT_EQ(current_time, ConvertMediaTime(renderer_->CurrentMediaTime(nullptr), |
969 ConvertMediaTime(renderer_->CurrentMediaTime(), &is_time_moving)); | 972 &is_time_moving)); |
970 EXPECT_TRUE(is_time_moving); | 973 EXPECT_TRUE(is_time_moving); |
971 | 974 |
972 tick_clock_->Advance(kOneSample); | 975 tick_clock_->Advance(kOneSample); |
973 renderer_->SetPlaybackRate(2); | 976 renderer_->SetPlaybackRate(2); |
974 EXPECT_EQ(current_time, CurrentMediaWallClockTime(&is_time_moving)); | 977 EXPECT_EQ(current_time, CurrentMediaWallClockTime(&is_time_moving)); |
975 EXPECT_TRUE(is_time_moving); | 978 EXPECT_TRUE(is_time_moving); |
976 EXPECT_EQ(current_time + kOneSample * 2, | 979 EXPECT_EQ( |
977 ConvertMediaTime(renderer_->CurrentMediaTime(), &is_time_moving)); | 980 current_time + kOneSample * 2, |
| 981 ConvertMediaTime(renderer_->CurrentMediaTime(nullptr), &is_time_moving)); |
978 EXPECT_TRUE(is_time_moving); | 982 EXPECT_TRUE(is_time_moving); |
979 | 983 |
980 // Advance far enough that we shouldn't be clamped to current time (tested | 984 // Advance far enough that we shouldn't be clamped to current time (tested |
981 // already above). | 985 // already above). |
982 tick_clock_->Advance(kOneSecond); | 986 tick_clock_->Advance(kOneSecond); |
983 EXPECT_EQ( | 987 EXPECT_EQ( |
984 current_time + timestamp_helper.GetFrameDuration(frames_to_consume.value), | 988 current_time + timestamp_helper.GetFrameDuration(frames_to_consume.value), |
985 CurrentMediaWallClockTime(&is_time_moving)); | 989 CurrentMediaWallClockTime(&is_time_moving)); |
986 EXPECT_TRUE(is_time_moving); | 990 EXPECT_TRUE(is_time_moving); |
987 } | 991 } |
988 | 992 |
989 } // namespace media | 993 } // namespace media |
OLD | NEW |