Index: media/filters/audio_renderer_impl_unittest.cc |
diff --git a/media/filters/audio_renderer_impl_unittest.cc b/media/filters/audio_renderer_impl_unittest.cc |
index 288d27ccb6a662c4c23dc4d8a92e551afccdd1b1..4918d75d44390a52cd400f42f74de97f1f6a44e6 100644 |
--- a/media/filters/audio_renderer_impl_unittest.cc |
+++ b/media/filters/audio_renderer_impl_unittest.cc |
@@ -61,6 +61,8 @@ |
: hardware_config_(AudioParameters(), AudioParameters()), |
demuxer_stream_(DemuxerStream::AUDIO), |
decoder_(new MockAudioDecoder()), |
+ last_time_update_(kNoTimestamp()), |
+ last_max_time_(kNoTimestamp()), |
ended_(false) { |
AudioDecoderConfig audio_config(kCodec, |
kSampleFormat, |
@@ -114,11 +116,19 @@ |
MOCK_METHOD1(OnBufferingStateChange, void(BufferingState)); |
MOCK_METHOD1(OnError, void(PipelineStatus)); |
+ void OnAudioTimeCallback(TimeDelta current_time, TimeDelta max_time) { |
+ CHECK(current_time <= max_time); |
+ last_time_update_ = current_time; |
+ last_max_time_ = max_time; |
+ } |
+ |
void InitializeRenderer(const PipelineStatusCB& pipeline_status_cb) { |
renderer_->Initialize( |
&demuxer_stream_, |
pipeline_status_cb, |
base::Bind(&AudioRendererImplTest::OnStatistics, |
+ base::Unretained(this)), |
+ base::Bind(&AudioRendererImplTest::OnAudioTimeCallback, |
base::Unretained(this)), |
base::Bind(&AudioRendererImplTest::OnBufferingStateChange, |
base::Unretained(this)), |
@@ -323,9 +333,11 @@ |
return renderer_->splicer_->HasNextBuffer(); |
} |
- base::TimeDelta CurrentMediaTime() { |
- return renderer_->CurrentMediaTime(); |
- } |
+ base::TimeDelta last_time_update() const { |
+ return last_time_update_; |
+ } |
+ |
+ base::TimeDelta last_max_time() const { return last_max_time_; } |
bool ended() const { return ended_; } |
@@ -396,6 +408,8 @@ |
base::Closure wait_for_pending_decode_cb_; |
PipelineStatusCB init_decoder_cb_; |
+ base::TimeDelta last_time_update_; |
+ base::TimeDelta last_max_time_; |
bool ended_; |
DISALLOW_COPY_AND_ASSIGN(AudioRendererImplTest); |
@@ -619,27 +633,34 @@ |
StartTicking(); |
AudioTimestampHelper timestamp_helper(kOutputSamplesPerSecond); |
- timestamp_helper.SetBaseTimestamp(base::TimeDelta()); |
- |
- // Time should be the starting timestamp as nothing's been consumed yet. |
- EXPECT_EQ(timestamp_helper.GetTimestamp(), CurrentMediaTime()); |
- |
- // Consume some audio data. |
+ EXPECT_EQ(kNoTimestamp(), last_time_update()); |
+ EXPECT_EQ(kNoTimestamp(), last_max_time()); |
+ |
+ // Preroll() should be buffered some data, consume half of it now. |
OutputFrames frames_to_consume(frames_buffered().value / 2); |
EXPECT_TRUE(ConsumeBufferedData(frames_to_consume)); |
WaitForPendingRead(); |
- |
- // Time shouldn't change just yet because we've only sent the initial audio |
- // data to the hardware. |
- EXPECT_EQ(timestamp_helper.GetTimestamp(), CurrentMediaTime()); |
- |
- // Consume some more audio data. |
+ base::RunLoop().RunUntilIdle(); |
+ |
+ // ConsumeBufferedData() uses an audio delay of zero, so ensure we received |
+ // a time update that's equal to |kFramesToConsume| from above. |
+ timestamp_helper.SetBaseTimestamp(base::TimeDelta()); |
+ timestamp_helper.AddFrames(frames_to_consume.value); |
+ EXPECT_EQ(base::TimeDelta(), last_time_update()); |
+ EXPECT_EQ(timestamp_helper.GetTimestamp(), last_max_time()); |
+ |
+ // The next time update should match the remaining frames_buffered(), but only |
+ // after running the message loop. |
frames_to_consume = frames_buffered(); |
EXPECT_TRUE(ConsumeBufferedData(frames_to_consume)); |
- |
- // Now time should change now that the audio hardware has called back. |
+ EXPECT_EQ(base::TimeDelta(), last_time_update()); |
+ EXPECT_EQ(timestamp_helper.GetTimestamp(), last_max_time()); |
+ |
+ // Now the times should be updated. |
+ base::RunLoop().RunUntilIdle(); |
+ EXPECT_EQ(timestamp_helper.GetTimestamp(), last_time_update()); |
timestamp_helper.AddFrames(frames_to_consume.value); |
- EXPECT_EQ(timestamp_helper.GetTimestamp(), CurrentMediaTime()); |
+ EXPECT_EQ(timestamp_helper.GetTimestamp(), last_max_time()); |
} |
TEST_F(AudioRendererImplTest, ImmediateEndOfStream) { |