winepulse: Move pulse_reset to unix lib.

Signed-off-by: Jacek Caban <jacek@codeweavers.com>
Signed-off-by: Andrew Eikum <aeikum@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Jacek Caban 2021-05-18 16:58:48 +02:00 committed by Alexandre Julliard
parent 638455136b
commit 505d4b8b14
3 changed files with 65 additions and 55 deletions

View File

@ -243,12 +243,6 @@ static void silence_buffer(pa_sample_format_t format, BYTE *buffer, UINT32 bytes
memset(buffer, format == PA_SAMPLE_U8 ? 0x80 : 0, bytes);
}
static void pulse_op_cb(pa_stream *s, int success, void *user) {
TRACE("Success: %i\n", success);
*(int*)user = success;
pulse->broadcast();
}
static DWORD WINAPI pulse_timer_cb(void *user)
{
ACImpl *This = user;
@ -941,56 +935,13 @@ static HRESULT WINAPI AudioClient_Stop(IAudioClient3 *iface)
static HRESULT WINAPI AudioClient_Reset(IAudioClient3 *iface)
{
ACImpl *This = impl_from_IAudioClient3(iface);
HRESULT hr = S_OK;
TRACE("(%p)\n", This);
pulse->lock();
hr = pulse_stream_valid(This);
if (FAILED(hr)) {
pulse->unlock();
return hr;
}
if (!This->pulse_stream)
return AUDCLNT_E_NOT_INITIALIZED;
if (This->pulse_stream->started) {
pulse->unlock();
return AUDCLNT_E_NOT_STOPPED;
}
if (This->pulse_stream->locked) {
pulse->unlock();
return AUDCLNT_E_BUFFER_OPERATION_PENDING;
}
if (This->dataflow == eRender) {
/* If there is still data in the render buffer it needs to be removed from the server */
int success = 0;
if (This->pulse_stream->held_bytes) {
pa_operation *o = pa_stream_flush(This->pulse_stream->stream, pulse_op_cb, &success);
if (o) {
while(pa_operation_get_state(o) == PA_OPERATION_RUNNING)
pulse->cond_wait();
pa_operation_unref(o);
}
}
if (success || !This->pulse_stream->held_bytes){
This->pulse_stream->clock_lastpos = This->pulse_stream->clock_written = 0;
This->pulse_stream->pa_offs_bytes = This->pulse_stream->lcl_offs_bytes = This->pulse_stream->held_bytes = This->pulse_stream->pa_held_bytes = 0;
}
} else {
ACPacket *p;
This->pulse_stream->clock_written += This->pulse_stream->held_bytes;
This->pulse_stream->held_bytes = 0;
if ((p = This->pulse_stream->locked_ptr)) {
This->pulse_stream->locked_ptr = NULL;
list_add_tail(&This->pulse_stream->packet_free_head, &p->entry);
}
list_move_tail(&This->pulse_stream->packet_free_head, &This->pulse_stream->packet_filled_head);
}
pulse->unlock();
return hr;
return pulse->reset(This->pulse_stream);
}
static HRESULT WINAPI AudioClient_SetEventHandle(IAudioClient3 *iface,

View File

@ -76,7 +76,7 @@ static int WINAPI pulse_cond_wait(void)
return pthread_cond_wait(&pulse_cond, &pulse_mutex);
}
static void WINAPI pulse_broadcast(void)
static void pulse_broadcast(void)
{
pthread_cond_broadcast(&pulse_cond);
}
@ -1347,6 +1347,65 @@ static HRESULT WINAPI pulse_stop(struct pulse_stream *stream)
return hr;
}
static HRESULT WINAPI pulse_reset(struct pulse_stream *stream)
{
pulse_lock();
if (!pulse_stream_valid(stream))
{
pulse_unlock();
return AUDCLNT_E_DEVICE_INVALIDATED;
}
if (stream->started)
{
pulse_unlock();
return AUDCLNT_E_NOT_STOPPED;
}
if (stream->locked)
{
pulse_unlock();
return AUDCLNT_E_BUFFER_OPERATION_PENDING;
}
if (stream->dataflow == eRender)
{
/* If there is still data in the render buffer it needs to be removed from the server */
int success = 0;
if (stream->held_bytes)
{
pa_operation *o = pa_stream_flush(stream->stream, pulse_op_cb, &success);
if (o)
{
while (pa_operation_get_state(o) == PA_OPERATION_RUNNING)
pulse_cond_wait();
pa_operation_unref(o);
}
}
if (success || !stream->held_bytes)
{
stream->clock_lastpos = stream->clock_written = 0;
stream->pa_offs_bytes = stream->lcl_offs_bytes = 0;
stream->held_bytes = stream->pa_held_bytes = 0;
}
}
else
{
ACPacket *p;
stream->clock_written += stream->held_bytes;
stream->held_bytes = 0;
if ((p = stream->locked_ptr))
{
stream->locked_ptr = NULL;
list_add_tail(&stream->packet_free_head, &p->entry);
}
list_move_tail(&stream->packet_free_head, &stream->packet_filled_head);
}
pulse_unlock();
return S_OK;
}
static void WINAPI pulse_set_volumes(struct pulse_stream *stream, float master_volume,
const float *volumes, const float *session_volumes)
{
@ -1361,12 +1420,12 @@ static const struct unix_funcs unix_funcs =
pulse_lock,
pulse_unlock,
pulse_cond_wait,
pulse_broadcast,
pulse_main_loop,
pulse_create_stream,
pulse_release_stream,
pulse_start,
pulse_stop,
pulse_reset,
pulse_timer_loop,
pulse_set_volumes,
pulse_test_connect,

View File

@ -71,7 +71,6 @@ struct unix_funcs
void (WINAPI *lock)(void);
void (WINAPI *unlock)(void);
int (WINAPI *cond_wait)(void);
void (WINAPI *broadcast)(void);
void (WINAPI *main_loop)(void);
HRESULT (WINAPI *create_stream)(const char *name, EDataFlow dataflow, AUDCLNT_SHAREMODE mode,
DWORD flags, REFERENCE_TIME duration, REFERENCE_TIME period,
@ -80,6 +79,7 @@ struct unix_funcs
void (WINAPI *release_stream)(struct pulse_stream *stream, HANDLE timer);
HRESULT (WINAPI *start)(struct pulse_stream *stream);
HRESULT (WINAPI *stop)(struct pulse_stream *stream);
HRESULT (WINAPI *reset)(struct pulse_stream *stream);
void (WINAPI *timer_loop)(struct pulse_stream *stream);
void (WINAPI *set_volumes)(struct pulse_stream *stream, float master_volume,
const float *volumes, const float *session_volumes);