Skip to content

Commit

Permalink
Handle SwitchOutputDevice() when a WebRtcAudioRenderer is stopped.
Browse files Browse the repository at this point in the history
It is possible that the audio renderer is stopped before a
SwitchOutputDevice() call.

Drive-by: Add thread check to WebMediaPlayerMS::ActiveStateChanged().

Bug: 846904
Change-Id: I8bb097ae2dcaff11c0607ffa1f5237d726347f49
Reviewed-on: https://chromium-review.googlesource.com/1075271
Reviewed-by: Max Morin <[email protected]>
Commit-Queue: Guido Urdaneta <[email protected]>
Cr-Original-Commit-Position: refs/heads/master@{#562284}(cherry picked from commit 86992ee)
Reviewed-on: https://chromium-review.googlesource.com/1080188
Reviewed-by: Guido Urdaneta <[email protected]>
Cr-Commit-Position: refs/branch-heads/3440@{#57}
Cr-Branched-From: 010ddcf-refs/heads/master@{#561733}
  • Loading branch information
Guido Urdaneta committed May 31, 2018
1 parent 4f1ab6e commit d4014a1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions content/renderer/media/stream/webmediaplayer_ms.cc
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ void WebMediaPlayerMS::TrackRemoved(const blink::WebMediaStreamTrack& track) {
}

void WebMediaPlayerMS::ActiveStateChanged(bool is_active) {
DCHECK(thread_checker_.CalledOnValidThread());
// The case when the stream becomes active is handled by TrackAdded().
if (is_active)
return;
Expand Down
6 changes: 5 additions & 1 deletion content/renderer/media/webrtc/webrtc_audio_renderer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -374,10 +374,14 @@ void WebRtcAudioRenderer::SwitchOutputDevice(
const media::OutputDeviceStatusCB& callback) {
DVLOG(1) << "WebRtcAudioRenderer::SwitchOutputDevice()";
DCHECK(thread_checker_.CalledOnValidThread());
if (!source_) {
callback.Run(media::OUTPUT_DEVICE_STATUS_ERROR_INTERNAL);
return;
}

DCHECK_GE(session_id_, 0);
{
base::AutoLock auto_lock(lock_);
DCHECK(source_);
DCHECK_NE(state_, UNINITIALIZED);
}

Expand Down
18 changes: 18 additions & 0 deletions content/renderer/media/webrtc/webrtc_audio_renderer_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -297,4 +297,22 @@ TEST_F(WebRtcAudioRendererTest, InitializeWithInvalidDevice) {
mock_sink_->GetOutputDeviceInfo().device_id());
}

TEST_F(WebRtcAudioRendererTest, SwitchOutputDeviceStoppedSource) {
SetupRenderer(kDefaultOutputDeviceId);
auto original_sink = mock_sink_;
renderer_proxy_->Start();

EXPECT_CALL(*original_sink.get(), Stop());
EXPECT_CALL(*source_.get(), RemoveAudioRenderer(renderer_.get()));
EXPECT_CALL(*this, MockSwitchDeviceCallback(
media::OUTPUT_DEVICE_STATUS_ERROR_INTERNAL));
base::RunLoop loop;
renderer_proxy_->Stop();
renderer_proxy_->SwitchOutputDevice(
kInvalidOutputDeviceId,
base::BindRepeating(&WebRtcAudioRendererTest::SwitchDeviceCallback,
base::Unretained(this), &loop));
loop.Run();
}

} // namespace content

0 comments on commit d4014a1

Please sign in to comment.