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) {
ASSERT_TRUE(stream->Open());
RunThreadsUntilIdle();
// Set to busy, so that the OnPushBufferComplete callback is not called after
// the backend is stopped.
FakeAudioDecoder* audio_decoder = GetAudioDecoder();
ASSERT_TRUE(audio_decoder);
audio_decoder->set_pipeline_status(FakeAudioDecoder::PIPELINE_STATUS_BUSY);
::media::MockAudioSourceCallback source_callback;
EXPECT_CALL(source_callback, OnMoreData(_, _, _, _))
......@@ -531,8 +528,13 @@ TEST_F(CastAudioOutputStreamTest, StartStopStart) {
stream->Start(&source_callback);
RunThreadsUntilIdle();
stream->Stop();
EXPECT_CALL(source_callback, OnMoreData(_, _, _, _)).Times(0);
RunThreadsUntilIdle();
testing::Mock::VerifyAndClearExpectations(&source_callback);
// 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_;
stream->Start(&source_callback);
RunThreadsUntilIdle();
......@@ -551,8 +553,6 @@ TEST_F(CastAudioOutputStreamTest, StopPreventsCallbacks) {
ASSERT_TRUE(stream->Open());
RunThreadsUntilIdle();
// Set to busy, so that the OnPushBufferComplete callback is not called after
// the backend is stopped.
FakeAudioDecoder* audio_decoder = GetAudioDecoder();
ASSERT_TRUE(audio_decoder);
......
......@@ -146,7 +146,6 @@ void CmaAudioOutputStream::Start(
}
if (!push_in_progress_) {
push_in_progress_ = true;
PushBuffer();
}
}
......@@ -161,7 +160,6 @@ void CmaAudioOutputStream::Stop(base::WaitableEvent* finished) {
cma_backend_->Pause();
cma_backend_state_ = CmaBackendState::kPaused;
}
push_in_progress_ = false;
source_callback_ = nullptr;
finished->Signal();
}
......@@ -218,6 +216,7 @@ void CmaAudioOutputStream::PushBuffer() {
// prevent the source callback from closing the output stream
// mid-push.
base::AutoLock lock(running_lock_);
DCHECK(!push_in_progress_);
// Do not fill more buffers if we have stopped running.
if (!running_)
......@@ -227,10 +226,8 @@ void CmaAudioOutputStream::PushBuffer() {
// Return quickly if so.
if (!source_callback_ || encountered_error_ ||
cma_backend_state_ != CmaBackendState::kStarted) {
push_in_progress_ = false;
return;
}
DCHECK(push_in_progress_);
CmaBackend::AudioDecoder::RenderingDelay rendering_delay =
audio_decoder_->GetRenderingDelay();
......@@ -271,6 +268,7 @@ void CmaAudioOutputStream::PushBuffer() {
decoder_buffer->set_timestamp(timestamp_helper_.GetTimestamp());
timestamp_helper_.AddFrames(frame_count);
push_in_progress_ = true;
BufferStatus status = audio_decoder_->PushBuffer(std::move(decoder_buffer));
if (status != CmaBackend::BufferStatus::kBufferPending)
OnPushBufferComplete(status);
......@@ -316,7 +314,6 @@ void CmaAudioOutputStream::OnPushBufferComplete(BufferStatus status) {
<< " delay=" << delay << " buffer_duration_=" << buffer_duration_;
push_timer_.Start(FROM_HERE, delay, this, &CmaAudioOutputStream::PushBuffer);
push_in_progress_ = true;
}
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