[vlc-devel] [PATCH 1/2] aout: wasapi: refactor the code
Steve Lhomme
robux4 at ycbcr.xyz
Tue Jun 9 16:48:47 CEST 2020
No functional changes.
---
modules/audio_output/wasapi.c | 36 +++++++++++++++++++++++------------
1 file changed, 24 insertions(+), 12 deletions(-)
diff --git a/modules/audio_output/wasapi.c b/modules/audio_output/wasapi.c
index 5180e93f8e89..ecfcc99ae1dd 100644
--- a/modules/audio_output/wasapi.c
+++ b/modules/audio_output/wasapi.c
@@ -160,7 +160,7 @@ static HRESULT TimeGet(aout_stream_t *s, vlc_tick_t *restrict delay)
return hr;
}
-static void CALLBACK StartDeferredCallback(void *val, BOOLEAN timeout)
+static void DoStartDeferred(void *val)
{
aout_stream_t *s = val;
aout_stream_sys_t *sys = s->sys;
@@ -168,7 +168,27 @@ static void CALLBACK StartDeferredCallback(void *val, BOOLEAN timeout)
HRESULT hr = IAudioClient_Start(sys->client);
atomic_store(&sys->started_state,
SUCCEEDED(hr) ? STARTED_STATE_OK : STARTED_STATE_ERROR);
- (void) timeout;
+}
+static void CALLBACK StartDeferredCallback(void *val, BOOLEAN timeout)
+{
+ DoStartDeferred(val);
+ (void)timeout;
+}
+
+static bool StartTimer(aout_stream_t *s, vlc_tick_t start_delay)
+{
+ aout_stream_sys_t *sys = s->sys;
+ bool timer_updated = false;
+ DWORD start_delay_ms = MS_FROM_VLC_TICK(start_delay);
+ if (sys->hTimer == NULL)
+ timer_updated =
+ CreateTimerQueueTimer(&sys->hTimer, NULL, StartDeferredCallback,
+ s, start_delay_ms, 0,
+ WT_EXECUTEDEFAULT | WT_EXECUTEONLYONCE);
+ else
+ timer_updated =
+ ChangeTimerQueueTimer(NULL, sys->hTimer, start_delay_ms, 0);
+ return timer_updated;
}
static HRESULT StartDeferred(aout_stream_t *s, vlc_tick_t date)
@@ -176,20 +196,12 @@ static HRESULT StartDeferred(aout_stream_t *s, vlc_tick_t date)
aout_stream_sys_t *sys = s->sys;
vlc_tick_t written = vlc_tick_from_frac(sys->written, sys->rate);
vlc_tick_t start_delay = date - vlc_tick_now() - written;
- DWORD start_delay_ms = start_delay > 0 ? MS_FROM_VLC_TICK(start_delay) : 0;
BOOL timer_updated = false;
/* Create or update the current timer */
- if (start_delay_ms > 0)
+ if (start_delay > 0)
{
- if (sys->hTimer == NULL)
- timer_updated =
- CreateTimerQueueTimer(&sys->hTimer, NULL, StartDeferredCallback,
- s, start_delay_ms, 0,
- WT_EXECUTEDEFAULT | WT_EXECUTEONLYONCE);
- else
- timer_updated =
- ChangeTimerQueueTimer(NULL, sys->hTimer, start_delay_ms, 0);
+ timer_updated = StartTimer(s, start_delay);
if (!timer_updated)
msg_Warn(s, "timer update failed, starting now");
}
--
2.26.2
More information about the vlc-devel
mailing list