From c949250be2012d7dac22e632f098405851ad18c9 Mon Sep 17 00:00:00 2001 From: Matthew Gregan Date: Fri, 28 Aug 2015 19:13:00 -0400 Subject: [PATCH] Bug 1199794 - Add NULL checks to avoid crashing during media playback if the audio device removed. r=padenot --- media/libcubeb/src/cubeb_wasapi.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/media/libcubeb/src/cubeb_wasapi.cpp b/media/libcubeb/src/cubeb_wasapi.cpp index 7dbf202a987..2ba8509bb72 100644 --- a/media/libcubeb/src/cubeb_wasapi.cpp +++ b/media/libcubeb/src/cubeb_wasapi.cpp @@ -701,6 +701,13 @@ current_stream_delay(cubeb_stream * stm) { stm->stream_reset_lock->assert_current_thread_owns(); + /* If the default audio endpoint went away during playback and we weren't + able to configure a new one, it's possible the caller may call this + before the error callback has propogated back. */ + if (!stm->audio_clock) { + return 0; + } + UINT64 freq; HRESULT hr = stm->audio_clock->GetFrequency(&freq); if (FAILED(hr)) { @@ -728,6 +735,10 @@ stream_set_volume(cubeb_stream * stm, float volume) { stm->stream_reset_lock->assert_current_thread_owns(); + if (!stm->audio_stream_volume) { + return CUBEB_ERROR; + } + uint32_t channels; HRESULT hr = stm->audio_stream_volume->GetChannelCount(&channels); if (hr != S_OK) { @@ -1289,6 +1300,10 @@ int wasapi_stream_start(cubeb_stream * stm) XASSERT(stm && !stm->thread && !stm->shutdown_event); + if (!stm->client) { + return CUBEB_ERROR; + } + HRESULT hr = stm->client->Start(); if (hr == AUDCLNT_E_DEVICE_INVALIDATED) { LOG("audioclient invalid device, reconfiguring\n", hr);