Bug 1199794 - Add NULL checks to avoid crashing during media playback if the audio device removed. r=padenot

This commit is contained in:
Matthew Gregan 2015-08-28 19:13:00 -04:00
parent 40122c5ef1
commit c949250be2

View File

@ -701,6 +701,13 @@ current_stream_delay(cubeb_stream * stm)
{ {
stm->stream_reset_lock->assert_current_thread_owns(); 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; UINT64 freq;
HRESULT hr = stm->audio_clock->GetFrequency(&freq); HRESULT hr = stm->audio_clock->GetFrequency(&freq);
if (FAILED(hr)) { if (FAILED(hr)) {
@ -728,6 +735,10 @@ stream_set_volume(cubeb_stream * stm, float volume)
{ {
stm->stream_reset_lock->assert_current_thread_owns(); stm->stream_reset_lock->assert_current_thread_owns();
if (!stm->audio_stream_volume) {
return CUBEB_ERROR;
}
uint32_t channels; uint32_t channels;
HRESULT hr = stm->audio_stream_volume->GetChannelCount(&channels); HRESULT hr = stm->audio_stream_volume->GetChannelCount(&channels);
if (hr != S_OK) { if (hr != S_OK) {
@ -1289,6 +1300,10 @@ int wasapi_stream_start(cubeb_stream * stm)
XASSERT(stm && !stm->thread && !stm->shutdown_event); XASSERT(stm && !stm->thread && !stm->shutdown_event);
if (!stm->client) {
return CUBEB_ERROR;
}
HRESULT hr = stm->client->Start(); HRESULT hr = stm->client->Start();
if (hr == AUDCLNT_E_DEVICE_INVALIDATED) { if (hr == AUDCLNT_E_DEVICE_INVALIDATED) {
LOG("audioclient invalid device, reconfiguring\n", hr); LOG("audioclient invalid device, reconfiguring\n", hr);