From 396acb0ec3b2aa1707ca7f0e3bdfd1bd090be444 Mon Sep 17 00:00:00 2001 From: Davide Beatrici Date: Wed, 24 May 2023 11:31:51 +0200 Subject: [PATCH] winecoreaudio: Move stream mode and period/duration initialization logic into unixlib. --- dlls/winecoreaudio.drv/coreaudio.c | 37 +++++++++++++++++++++++++++++++++++-- dlls/winecoreaudio.drv/mmdevdrv.c | 31 ------------------------------- 2 files changed, 35 insertions(+), 33 deletions(-) diff --git a/dlls/winecoreaudio.drv/coreaudio.c b/dlls/winecoreaudio.drv/coreaudio.c index 89265558a1d..d031b82583e 100644 --- a/dlls/winecoreaudio.drv/coreaudio.c +++ b/dlls/winecoreaudio.drv/coreaudio.c @@ -649,12 +649,45 @@ static AudioDeviceID dev_id_from_device(const char *device) static NTSTATUS unix_create_stream(void *args) { struct create_stream_params *params = args; - struct coreaudio_stream *stream = calloc(1, sizeof(*stream)); + struct coreaudio_stream *stream; AURenderCallbackStruct input; OSStatus sc; SIZE_T size; - if(!stream){ + params->result = S_OK; + + if (params->share == AUDCLNT_SHAREMODE_SHARED) { + params->period = def_period; + if (params->duration < 3 * params->period) + params->duration = 3 * params->period; + } else { + const WAVEFORMATEXTENSIBLE *fmtex = (WAVEFORMATEXTENSIBLE *)params->fmt; + if (fmtex->Format.wFormatTag == WAVE_FORMAT_EXTENSIBLE && + (fmtex->dwChannelMask == 0 || fmtex->dwChannelMask & SPEAKER_RESERVED)) + params->result = AUDCLNT_E_UNSUPPORTED_FORMAT; + else { + if (!params->period) + params->period = def_period; + if (params->period < min_period || params->period > 5000000) + params->result = AUDCLNT_E_INVALID_DEVICE_PERIOD; + else if (params->duration > 20000000) /* The smaller the period, the lower this limit. */ + params->result = AUDCLNT_E_BUFFER_SIZE_ERROR; + else if (params->flags & AUDCLNT_STREAMFLAGS_EVENTCALLBACK) { + if (params->duration != params->period) + params->result = AUDCLNT_E_BUFDURATION_PERIOD_NOT_EQUAL; + + FIXME("EXCLUSIVE mode with EVENTCALLBACK\n"); + + params->result = AUDCLNT_E_DEVICE_IN_USE; + } else if (params->duration < 8 * params->period) + params->duration = 8 * params->period; /* May grow above 2s. */ + } + } + + if (FAILED(params->result)) + return STATUS_SUCCESS; + + if (!(stream = calloc(1, sizeof(*stream)))) { params->result = E_OUTOFMEMORY; return STATUS_SUCCESS; } diff --git a/dlls/winecoreaudio.drv/mmdevdrv.c b/dlls/winecoreaudio.drv/mmdevdrv.c index d8a2e9e5d21..0372e320680 100644 --- a/dlls/winecoreaudio.drv/mmdevdrv.c +++ b/dlls/winecoreaudio.drv/mmdevdrv.c @@ -48,9 +48,6 @@ WINE_DEFAULT_DEBUG_CHANNEL(coreaudio); #define NULL_PTR_ERR MAKE_HRESULT(SEVERITY_ERROR, FACILITY_WIN32, RPC_X_NULL_REF_POINTER) -static const REFERENCE_TIME DefaultPeriod = 100000; -static const REFERENCE_TIME MinimumPeriod = 50000; - static const IAudioClient3Vtbl AudioClient3_Vtbl; extern const IAudioRenderClientVtbl AudioRenderClient_Vtbl; extern const IAudioCaptureClientVtbl AudioCaptureClient_Vtbl; @@ -582,34 +579,6 @@ static HRESULT WINAPI AudioClient_Initialize(IAudioClient3 *iface, return E_INVALIDARG; } - if(mode == AUDCLNT_SHAREMODE_SHARED){ - period = DefaultPeriod; - if( duration < 3 * period) - duration = 3 * period; - }else{ - if(fmt->wFormatTag == WAVE_FORMAT_EXTENSIBLE){ - if(((WAVEFORMATEXTENSIBLE*)fmt)->dwChannelMask == 0 || - ((WAVEFORMATEXTENSIBLE*)fmt)->dwChannelMask & SPEAKER_RESERVED) - return AUDCLNT_E_UNSUPPORTED_FORMAT; - } - - if(!period) - period = DefaultPeriod; /* not minimum */ - if(period < MinimumPeriod || period > 5000000) - return AUDCLNT_E_INVALID_DEVICE_PERIOD; - if(duration > 20000000) /* the smaller the period, the lower this limit */ - return AUDCLNT_E_BUFFER_SIZE_ERROR; - if(flags & AUDCLNT_STREAMFLAGS_EVENTCALLBACK){ - if(duration != period) - return AUDCLNT_E_BUFDURATION_PERIOD_NOT_EQUAL; - FIXME("EXCLUSIVE mode with EVENTCALLBACK\n"); - return AUDCLNT_E_DEVICE_IN_USE; - }else{ - if( duration < 8 * period) - duration = 8 * period; /* may grow above 2s */ - } - } - sessions_lock(); if(This->stream){ -- 2.11.4.GIT