[vlc-commits] winstore: Handle audio device failures
Hugo Beauzée-Luyssen
git at videolan.org
Tue Sep 27 18:29:50 CEST 2016
vlc | branch: master | Hugo Beauzée-Luyssen <hugo at beauzee.fr> | Mon Sep 26 18:17:38 2016 +0200| [b6b011f5b1e89adecd4826a8ed65fc2d6694d6d9] | committer: Hugo Beauzée-Luyssen
winstore: Handle audio device failures
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=b6b011f5b1e89adecd4826a8ed65fc2d6694d6d9
---
modules/audio_output/winstore.c | 36 ++++++++++++++++++++++++++++++++----
1 file changed, 32 insertions(+), 4 deletions(-)
diff --git a/modules/audio_output/winstore.c b/modules/audio_output/winstore.c
index 6918b73..feb13d9 100644
--- a/modules/audio_output/winstore.c
+++ b/modules/audio_output/winstore.c
@@ -57,10 +57,23 @@ struct aout_sys_t
IAudioClient *client;
};
+static int vlc_FromHR(audio_output_t *aout, HRESULT hr)
+{
+ aout_sys_t* sys = aout->sys;
+ /* Select the default device (and restart) on unplug */
+ if (unlikely(hr == AUDCLNT_E_DEVICE_INVALIDATED ||
+ hr == AUDCLNT_E_RESOURCES_INVALIDATED))
+ {
+ sys->client = NULL;
+ }
+ return SUCCEEDED(hr) ? 0 : -1;
+}
static int VolumeSet(audio_output_t *aout, float vol)
{
aout_sys_t *sys = aout->sys;
+ if( unlikely( sys->client == NULL ) )
+ return VLC_EGENERIC;
HRESULT hr;
ISimpleAudioVolume *pc_AudioVolume = NULL;
float gain = 1.f;
@@ -98,6 +111,8 @@ done:
static int MuteSet(audio_output_t *aout, bool mute)
{
aout_sys_t *sys = aout->sys;
+ if( unlikely( sys->client == NULL ) )
+ return VLC_EGENERIC;
HRESULT hr;
ISimpleAudioVolume *pc_AudioVolume = NULL;
@@ -124,6 +139,8 @@ done:
static int TimeGet(audio_output_t *aout, mtime_t *restrict delay)
{
aout_sys_t *sys = aout->sys;
+ if( unlikely( sys->client == NULL ) )
+ return VLC_EGENERIC;
HRESULT hr;
EnterMTA();
@@ -136,30 +153,41 @@ static int TimeGet(audio_output_t *aout, mtime_t *restrict delay)
static void Play(audio_output_t *aout, block_t *block)
{
aout_sys_t *sys = aout->sys;
+ if( unlikely( sys->client == NULL ) )
+ return;
EnterMTA();
- aout_stream_Play(sys->stream, block);
+ HRESULT hr = aout_stream_Play(sys->stream, block);
LeaveMTA();
+
+ vlc_FromHR(aout, hr);
}
static void Pause(audio_output_t *aout, bool paused, mtime_t date)
{
aout_sys_t *sys = aout->sys;
+ if( unlikely( sys->client == NULL ) )
+ return;
EnterMTA();
- aout_stream_Pause(sys->stream, paused);
+ HRESULT hr = aout_stream_Pause(sys->stream, paused);
LeaveMTA();
(void) date;
+ vlc_FromHR(aout, hr);
}
static void Flush(audio_output_t *aout, bool wait)
{
aout_sys_t *sys = aout->sys;
+ if( unlikely( sys->client == NULL ) )
+ return;
EnterMTA();
- aout_stream_Flush(sys->stream, wait);
+ HRESULT hr = aout_stream_Flush(sys->stream, wait);
LeaveMTA();
+
+ vlc_FromHR(aout, hr);
}
static HRESULT ActivateDevice(void *opaque, REFIID iid, PROPVARIANT *actparms,
@@ -169,7 +197,7 @@ static HRESULT ActivateDevice(void *opaque, REFIID iid, PROPVARIANT *actparms,
if (!IsEqualIID(iid, &IID_IAudioClient))
return E_NOINTERFACE;
- if (actparms != NULL)
+ if (actparms != NULL || client == NULL )
return E_INVALIDARG;
IAudioClient_AddRef(client);
More information about the vlc-commits
mailing list