winealsa: Move stream mode and period/duration initialization logic into unixlib.

This commit is contained in:
Davide Beatrici 2023-05-24 11:29:54 +02:00 committed by Alexandre Julliard
parent b923aea734
commit b08d7efa5e
2 changed files with 34 additions and 32 deletions

View file

@ -85,6 +85,7 @@ struct alsa_stream
#define EXTRA_SAFE_RT 40000
static const REFERENCE_TIME def_period = 100000;
static const REFERENCE_TIME min_period = 50000;
static const WCHAR drv_keyW[] = {'S','o','f','t','w','a','r','e','\\',
'W','i','n','e','\\','D','r','i','v','e','r','s','\\',
@ -789,10 +790,42 @@ static NTSTATUS alsa_create_stream(void *args)
snd_pcm_sw_params_t *sw_params = NULL;
snd_pcm_format_t format;
unsigned int rate, alsa_period_us, i;
WAVEFORMATEXTENSIBLE *fmtex;
WAVEFORMATEXTENSIBLE *fmtex = (WAVEFORMATEXTENSIBLE *)params->fmt;
int err;
SIZE_T size;
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 {
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;
stream = calloc(1, sizeof(*stream));
if(!stream){
params->result = E_OUTOFMEMORY;

View file

@ -53,9 +53,6 @@ WINE_DEFAULT_DEBUG_CHANNEL(alsa);
#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 CRITICAL_SECTION g_sessions_lock;
static CRITICAL_SECTION_DEBUG g_sessions_lock_debug =
{
@ -607,34 +604,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){