Commit 5516e83f authored by Huw Davies's avatar Huw Davies Committed by Alexandre Julliard

winealsa: Move get_latency to the unixlib.

parent 413b3c59
......@@ -1250,6 +1250,27 @@ static NTSTATUS get_buffer_size(void *args)
return alsa_unlock_result(stream, &params->result, S_OK);
}
static NTSTATUS get_latency(void *args)
{
struct get_latency_params *params = args;
struct alsa_stream *stream = params->stream;
alsa_lock(stream);
/* Hide some frames in the ALSA buffer. Allows us to return GetCurrentPadding=0
* yet have enough data left to play (as if it were in native's mixer). Add:
* + mmdevapi_period such that at the end of it, ALSA still has data;
* + EXTRA_SAFE (~4ms) to allow for late callback invocation / fluctuation;
* + alsa_period such that ALSA always has at least one period to play. */
if(stream->flow == eRender)
*params->latency = muldiv(stream->hidden_frames, 10000000, stream->fmt->nSamplesPerSec);
else
*params->latency = muldiv(stream->alsa_period_frames, 10000000, stream->fmt->nSamplesPerSec)
+ stream->mmdev_period_rt;
return alsa_unlock_result(stream, &params->result, S_OK);
}
unixlib_entry_t __wine_unix_call_funcs[] =
{
get_endpoint_ids,
......@@ -1258,4 +1279,5 @@ unixlib_entry_t __wine_unix_call_funcs[] =
is_format_supported,
get_mix_format,
get_buffer_size,
get_latency,
};
......@@ -849,7 +849,7 @@ static HRESULT WINAPI AudioClient_GetStreamLatency(IAudioClient3 *iface,
REFERENCE_TIME *latency)
{
ACImpl *This = impl_from_IAudioClient3(iface);
struct alsa_stream *stream = This->stream;
struct get_latency_params params;
TRACE("(%p)->(%p)\n", This, latency);
......@@ -859,22 +859,12 @@ static HRESULT WINAPI AudioClient_GetStreamLatency(IAudioClient3 *iface,
if(!This->stream)
return AUDCLNT_E_NOT_INITIALIZED;
alsa_lock(stream);
/* Hide some frames in the ALSA buffer. Allows us to return GetCurrentPadding=0
* yet have enough data left to play (as if it were in native's mixer). Add:
* + mmdevapi_period such that at the end of it, ALSA still has data;
* + EXTRA_SAFE (~4ms) to allow for late callback invocation / fluctuation;
* + alsa_period such that ALSA always has at least one period to play. */
if(stream->flow == eRender)
*latency = MulDiv(stream->hidden_frames, 10000000, stream->fmt->nSamplesPerSec);
else
*latency = MulDiv(stream->alsa_period_frames, 10000000, stream->fmt->nSamplesPerSec)
+ stream->mmdev_period_rt;
params.stream = This->stream;
params.latency = latency;
alsa_unlock(stream);
ALSA_CALL(get_latency, &params);
return S_OK;
return params.result;
}
static HRESULT WINAPI AudioClient_GetCurrentPadding(IAudioClient3 *iface,
......
......@@ -115,6 +115,13 @@ struct get_buffer_size_params
UINT32 *size;
};
struct get_latency_params
{
struct alsa_stream *stream;
HRESULT result;
REFERENCE_TIME *latency;
};
enum alsa_funcs
{
alsa_get_endpoint_ids,
......@@ -123,6 +130,7 @@ enum alsa_funcs
alsa_is_format_supported,
alsa_get_mix_format,
alsa_get_buffer_size,
alsa_get_latency,
};
extern unixlib_handle_t alsa_handle;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment