Commit 573182f0 authored by Ken MacKay's avatar Ken MacKay Committed by Commit Bot

[Chromecast] Fix pending push tracking in CmaAudioOutputStream

Bug: internal b/140603369
Change-Id: I188c969198078afb251c488fb0574a628dc8a2be
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1866973
Commit-Queue: Kenneth MacKay <kmackay@chromium.org>
Reviewed-by: default avatarYuchen Liu <yucliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#707016}
parent 472addf6
...@@ -519,11 +519,8 @@ TEST_F(CastAudioOutputStreamTest, StartStopStart) { ...@@ -519,11 +519,8 @@ TEST_F(CastAudioOutputStreamTest, StartStopStart) {
ASSERT_TRUE(stream->Open()); ASSERT_TRUE(stream->Open());
RunThreadsUntilIdle(); RunThreadsUntilIdle();
// Set to busy, so that the OnPushBufferComplete callback is not called after
// the backend is stopped.
FakeAudioDecoder* audio_decoder = GetAudioDecoder(); FakeAudioDecoder* audio_decoder = GetAudioDecoder();
ASSERT_TRUE(audio_decoder); ASSERT_TRUE(audio_decoder);
audio_decoder->set_pipeline_status(FakeAudioDecoder::PIPELINE_STATUS_BUSY);
::media::MockAudioSourceCallback source_callback; ::media::MockAudioSourceCallback source_callback;
EXPECT_CALL(source_callback, OnMoreData(_, _, _, _)) EXPECT_CALL(source_callback, OnMoreData(_, _, _, _))
...@@ -531,8 +528,13 @@ TEST_F(CastAudioOutputStreamTest, StartStopStart) { ...@@ -531,8 +528,13 @@ TEST_F(CastAudioOutputStreamTest, StartStopStart) {
stream->Start(&source_callback); stream->Start(&source_callback);
RunThreadsUntilIdle(); RunThreadsUntilIdle();
stream->Stop(); stream->Stop();
EXPECT_CALL(source_callback, OnMoreData(_, _, _, _)).Times(0);
RunThreadsUntilIdle();
testing::Mock::VerifyAndClearExpectations(&source_callback);
// Ensure we fetch new data when restarting. // Ensure we fetch new data when restarting.
EXPECT_CALL(source_callback, OnMoreData(_, _, _, _))
.WillRepeatedly(Invoke(OnMoreData));
int last_on_more_data_call_count = on_more_data_call_count_; int last_on_more_data_call_count = on_more_data_call_count_;
stream->Start(&source_callback); stream->Start(&source_callback);
RunThreadsUntilIdle(); RunThreadsUntilIdle();
...@@ -551,8 +553,6 @@ TEST_F(CastAudioOutputStreamTest, StopPreventsCallbacks) { ...@@ -551,8 +553,6 @@ TEST_F(CastAudioOutputStreamTest, StopPreventsCallbacks) {
ASSERT_TRUE(stream->Open()); ASSERT_TRUE(stream->Open());
RunThreadsUntilIdle(); RunThreadsUntilIdle();
// Set to busy, so that the OnPushBufferComplete callback is not called after
// the backend is stopped.
FakeAudioDecoder* audio_decoder = GetAudioDecoder(); FakeAudioDecoder* audio_decoder = GetAudioDecoder();
ASSERT_TRUE(audio_decoder); ASSERT_TRUE(audio_decoder);
......
...@@ -146,7 +146,6 @@ void CmaAudioOutputStream::Start( ...@@ -146,7 +146,6 @@ void CmaAudioOutputStream::Start(
} }
if (!push_in_progress_) { if (!push_in_progress_) {
push_in_progress_ = true;
PushBuffer(); PushBuffer();
} }
} }
...@@ -161,7 +160,6 @@ void CmaAudioOutputStream::Stop(base::WaitableEvent* finished) { ...@@ -161,7 +160,6 @@ void CmaAudioOutputStream::Stop(base::WaitableEvent* finished) {
cma_backend_->Pause(); cma_backend_->Pause();
cma_backend_state_ = CmaBackendState::kPaused; cma_backend_state_ = CmaBackendState::kPaused;
} }
push_in_progress_ = false;
source_callback_ = nullptr; source_callback_ = nullptr;
finished->Signal(); finished->Signal();
} }
...@@ -218,6 +216,7 @@ void CmaAudioOutputStream::PushBuffer() { ...@@ -218,6 +216,7 @@ void CmaAudioOutputStream::PushBuffer() {
// prevent the source callback from closing the output stream // prevent the source callback from closing the output stream
// mid-push. // mid-push.
base::AutoLock lock(running_lock_); base::AutoLock lock(running_lock_);
DCHECK(!push_in_progress_);
// Do not fill more buffers if we have stopped running. // Do not fill more buffers if we have stopped running.
if (!running_) if (!running_)
...@@ -227,10 +226,8 @@ void CmaAudioOutputStream::PushBuffer() { ...@@ -227,10 +226,8 @@ void CmaAudioOutputStream::PushBuffer() {
// Return quickly if so. // Return quickly if so.
if (!source_callback_ || encountered_error_ || if (!source_callback_ || encountered_error_ ||
cma_backend_state_ != CmaBackendState::kStarted) { cma_backend_state_ != CmaBackendState::kStarted) {
push_in_progress_ = false;
return; return;
} }
DCHECK(push_in_progress_);
CmaBackend::AudioDecoder::RenderingDelay rendering_delay = CmaBackend::AudioDecoder::RenderingDelay rendering_delay =
audio_decoder_->GetRenderingDelay(); audio_decoder_->GetRenderingDelay();
...@@ -271,6 +268,7 @@ void CmaAudioOutputStream::PushBuffer() { ...@@ -271,6 +268,7 @@ void CmaAudioOutputStream::PushBuffer() {
decoder_buffer->set_timestamp(timestamp_helper_.GetTimestamp()); decoder_buffer->set_timestamp(timestamp_helper_.GetTimestamp());
timestamp_helper_.AddFrames(frame_count); timestamp_helper_.AddFrames(frame_count);
push_in_progress_ = true;
BufferStatus status = audio_decoder_->PushBuffer(std::move(decoder_buffer)); BufferStatus status = audio_decoder_->PushBuffer(std::move(decoder_buffer));
if (status != CmaBackend::BufferStatus::kBufferPending) if (status != CmaBackend::BufferStatus::kBufferPending)
OnPushBufferComplete(status); OnPushBufferComplete(status);
...@@ -316,7 +314,6 @@ void CmaAudioOutputStream::OnPushBufferComplete(BufferStatus status) { ...@@ -316,7 +314,6 @@ void CmaAudioOutputStream::OnPushBufferComplete(BufferStatus status) {
<< " delay=" << delay << " buffer_duration_=" << buffer_duration_; << " delay=" << delay << " buffer_duration_=" << buffer_duration_;
push_timer_.Start(FROM_HERE, delay, this, &CmaAudioOutputStream::PushBuffer); push_timer_.Start(FROM_HERE, delay, this, &CmaAudioOutputStream::PushBuffer);
push_in_progress_ = true;
} }
void CmaAudioOutputStream::OnDecoderError() { void CmaAudioOutputStream::OnDecoderError() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment