2011-09-20 10:27:10 +04:00
|
|
|
/**
|
2012-10-09 07:02:04 +04:00
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
2011-09-20 10:27:10 +04:00
|
|
|
* Video Redirection Virtual Channel - PulseAudio Device
|
|
|
|
*
|
|
|
|
* Copyright 2010-2011 Vic Lee
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2012-08-15 01:09:01 +04:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2011-09-20 10:27:10 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
2012-08-15 01:09:01 +04:00
|
|
|
|
2012-11-20 07:31:15 +04:00
|
|
|
#include <winpr/crt.h>
|
|
|
|
|
2011-09-20 10:27:10 +04:00
|
|
|
#include <pulse/pulseaudio.h>
|
2012-11-20 07:31:15 +04:00
|
|
|
|
2011-09-20 10:27:10 +04:00
|
|
|
#include "tsmf_audio.h"
|
|
|
|
|
|
|
|
typedef struct _TSMFPulseAudioDevice
|
|
|
|
{
|
|
|
|
ITSMFAudioDevice iface;
|
|
|
|
|
|
|
|
char device[32];
|
2014-05-23 15:12:34 +04:00
|
|
|
pa_threaded_mainloop *mainloop;
|
|
|
|
pa_context *context;
|
2011-09-20 10:27:10 +04:00
|
|
|
pa_sample_spec sample_spec;
|
2014-05-23 15:12:34 +04:00
|
|
|
pa_stream *stream;
|
2011-09-20 10:27:10 +04:00
|
|
|
} TSMFPulseAudioDevice;
|
|
|
|
|
2014-05-23 15:12:34 +04:00
|
|
|
static void tsmf_pulse_context_state_callback(pa_context *context, void *userdata)
|
2011-09-20 10:27:10 +04:00
|
|
|
{
|
2014-05-23 15:12:34 +04:00
|
|
|
TSMFPulseAudioDevice *pulse = (TSMFPulseAudioDevice *) userdata;
|
2011-09-20 10:27:10 +04:00
|
|
|
pa_context_state_t state;
|
|
|
|
state = pa_context_get_state(context);
|
2014-05-23 15:12:34 +04:00
|
|
|
switch(state)
|
2011-09-20 10:27:10 +04:00
|
|
|
{
|
|
|
|
case PA_CONTEXT_READY:
|
2014-05-23 15:12:34 +04:00
|
|
|
DEBUG_TSMF("PA_CONTEXT_READY");
|
2011-09-20 10:27:10 +04:00
|
|
|
pa_threaded_mainloop_signal(pulse->mainloop, 0);
|
|
|
|
break;
|
|
|
|
case PA_CONTEXT_FAILED:
|
|
|
|
case PA_CONTEXT_TERMINATED:
|
2014-05-23 15:12:34 +04:00
|
|
|
DEBUG_TSMF("state %d", (int)state);
|
2011-09-20 10:27:10 +04:00
|
|
|
pa_threaded_mainloop_signal(pulse->mainloop, 0);
|
|
|
|
break;
|
|
|
|
default:
|
2014-05-23 15:12:34 +04:00
|
|
|
DEBUG_TSMF("state %d", (int)state);
|
2011-09-20 10:27:10 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-23 15:12:34 +04:00
|
|
|
static BOOL tsmf_pulse_connect(TSMFPulseAudioDevice *pulse)
|
2011-09-20 10:27:10 +04:00
|
|
|
{
|
|
|
|
pa_context_state_t state;
|
2014-05-23 15:12:34 +04:00
|
|
|
if(!pulse->context)
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2014-05-23 15:12:34 +04:00
|
|
|
if(pa_context_connect(pulse->context, NULL, 0, NULL))
|
2011-09-20 10:27:10 +04:00
|
|
|
{
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_ERR(TAG, "pa_context_connect failed (%d)",
|
2014-05-23 15:12:34 +04:00
|
|
|
pa_context_errno(pulse->context));
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-09-20 10:27:10 +04:00
|
|
|
}
|
|
|
|
pa_threaded_mainloop_lock(pulse->mainloop);
|
2014-05-23 15:12:34 +04:00
|
|
|
if(pa_threaded_mainloop_start(pulse->mainloop) < 0)
|
2011-09-20 10:27:10 +04:00
|
|
|
{
|
|
|
|
pa_threaded_mainloop_unlock(pulse->mainloop);
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_ERR(TAG, "pa_threaded_mainloop_start failed (%d)",
|
2014-05-23 15:12:34 +04:00
|
|
|
pa_context_errno(pulse->context));
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-09-20 10:27:10 +04:00
|
|
|
}
|
2014-05-23 15:12:34 +04:00
|
|
|
for(;;)
|
2011-09-20 10:27:10 +04:00
|
|
|
{
|
|
|
|
state = pa_context_get_state(pulse->context);
|
2014-05-23 15:12:34 +04:00
|
|
|
if(state == PA_CONTEXT_READY)
|
2011-09-20 10:27:10 +04:00
|
|
|
break;
|
2014-05-23 15:12:34 +04:00
|
|
|
if(!PA_CONTEXT_IS_GOOD(state))
|
2011-09-20 10:27:10 +04:00
|
|
|
{
|
2014-05-23 15:12:34 +04:00
|
|
|
DEBUG_TSMF("bad context state (%d)",
|
|
|
|
pa_context_errno(pulse->context));
|
2011-09-20 10:27:10 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
pa_threaded_mainloop_wait(pulse->mainloop);
|
|
|
|
}
|
|
|
|
pa_threaded_mainloop_unlock(pulse->mainloop);
|
2014-05-23 15:12:34 +04:00
|
|
|
if(state == PA_CONTEXT_READY)
|
2011-09-20 10:27:10 +04:00
|
|
|
{
|
2014-05-23 15:12:34 +04:00
|
|
|
DEBUG_TSMF("connected");
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-09-20 10:27:10 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pa_context_disconnect(pulse->context);
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-09-20 10:27:10 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-23 15:12:34 +04:00
|
|
|
static BOOL tsmf_pulse_open(ITSMFAudioDevice *audio, const char *device)
|
2011-09-20 10:27:10 +04:00
|
|
|
{
|
2014-05-23 15:12:34 +04:00
|
|
|
TSMFPulseAudioDevice *pulse = (TSMFPulseAudioDevice *) audio;
|
|
|
|
if(device)
|
2011-09-20 10:27:10 +04:00
|
|
|
{
|
|
|
|
strcpy(pulse->device, device);
|
|
|
|
}
|
|
|
|
pulse->mainloop = pa_threaded_mainloop_new();
|
2014-05-23 15:12:34 +04:00
|
|
|
if(!pulse->mainloop)
|
2011-09-20 10:27:10 +04:00
|
|
|
{
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_ERR(TAG, "pa_threaded_mainloop_new failed");
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-09-20 10:27:10 +04:00
|
|
|
}
|
|
|
|
pulse->context = pa_context_new(pa_threaded_mainloop_get_api(pulse->mainloop), "freerdp");
|
2014-05-23 15:12:34 +04:00
|
|
|
if(!pulse->context)
|
2011-09-20 10:27:10 +04:00
|
|
|
{
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_ERR(TAG, "pa_context_new failed");
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-09-20 10:27:10 +04:00
|
|
|
}
|
|
|
|
pa_context_set_state_callback(pulse->context, tsmf_pulse_context_state_callback, pulse);
|
2014-05-23 15:12:34 +04:00
|
|
|
if(tsmf_pulse_connect(pulse))
|
2011-09-20 10:27:10 +04:00
|
|
|
{
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_ERR(TAG, "tsmf_pulse_connect failed");
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-09-20 10:27:10 +04:00
|
|
|
}
|
2014-05-23 15:12:34 +04:00
|
|
|
DEBUG_TSMF("open device %s", pulse->device);
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-09-20 10:27:10 +04:00
|
|
|
}
|
|
|
|
|
2014-05-23 15:12:34 +04:00
|
|
|
static void tsmf_pulse_stream_success_callback(pa_stream *stream, int success, void *userdata)
|
2011-09-20 10:27:10 +04:00
|
|
|
{
|
2014-05-23 15:12:34 +04:00
|
|
|
TSMFPulseAudioDevice *pulse = (TSMFPulseAudioDevice *) userdata;
|
2011-09-20 10:27:10 +04:00
|
|
|
pa_threaded_mainloop_signal(pulse->mainloop, 0);
|
|
|
|
}
|
|
|
|
|
2014-05-23 15:12:34 +04:00
|
|
|
static void tsmf_pulse_wait_for_operation(TSMFPulseAudioDevice *pulse, pa_operation *operation)
|
2011-09-20 10:27:10 +04:00
|
|
|
{
|
2014-05-23 15:12:34 +04:00
|
|
|
if(operation == NULL)
|
2011-09-20 10:27:10 +04:00
|
|
|
return;
|
2014-05-23 15:12:34 +04:00
|
|
|
while(pa_operation_get_state(operation) == PA_OPERATION_RUNNING)
|
2011-09-20 10:27:10 +04:00
|
|
|
{
|
|
|
|
pa_threaded_mainloop_wait(pulse->mainloop);
|
|
|
|
}
|
|
|
|
pa_operation_unref(operation);
|
|
|
|
}
|
|
|
|
|
2014-05-23 15:12:34 +04:00
|
|
|
static void tsmf_pulse_stream_state_callback(pa_stream *stream, void *userdata)
|
2011-09-20 10:27:10 +04:00
|
|
|
{
|
2014-05-23 15:12:34 +04:00
|
|
|
TSMFPulseAudioDevice *pulse = (TSMFPulseAudioDevice *) userdata;
|
2011-09-20 10:27:10 +04:00
|
|
|
pa_stream_state_t state;
|
|
|
|
state = pa_stream_get_state(stream);
|
2014-05-23 15:12:34 +04:00
|
|
|
switch(state)
|
2011-09-20 10:27:10 +04:00
|
|
|
{
|
|
|
|
case PA_STREAM_READY:
|
2014-05-23 15:12:34 +04:00
|
|
|
DEBUG_TSMF("PA_STREAM_READY");
|
|
|
|
pa_threaded_mainloop_signal(pulse->mainloop, 0);
|
2011-09-20 10:27:10 +04:00
|
|
|
break;
|
|
|
|
case PA_STREAM_FAILED:
|
|
|
|
case PA_STREAM_TERMINATED:
|
2014-05-23 15:12:34 +04:00
|
|
|
DEBUG_TSMF("state %d", (int)state);
|
|
|
|
pa_threaded_mainloop_signal(pulse->mainloop, 0);
|
2011-09-20 10:27:10 +04:00
|
|
|
break;
|
|
|
|
default:
|
2014-05-23 15:12:34 +04:00
|
|
|
DEBUG_TSMF("state %d", (int)state);
|
2011-09-20 10:27:10 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-23 15:12:34 +04:00
|
|
|
static void tsmf_pulse_stream_request_callback(pa_stream *stream, size_t length, void *userdata)
|
2011-09-20 10:27:10 +04:00
|
|
|
{
|
2014-05-23 15:12:34 +04:00
|
|
|
TSMFPulseAudioDevice *pulse = (TSMFPulseAudioDevice *) userdata;
|
|
|
|
DEBUG_TSMF("%d", (int) length);
|
2011-09-20 10:27:10 +04:00
|
|
|
pa_threaded_mainloop_signal(pulse->mainloop, 0);
|
|
|
|
}
|
|
|
|
|
2014-05-23 15:12:34 +04:00
|
|
|
static BOOL tsmf_pulse_close_stream(TSMFPulseAudioDevice *pulse)
|
2011-09-20 10:27:10 +04:00
|
|
|
{
|
2014-05-23 15:12:34 +04:00
|
|
|
if(!pulse->context || !pulse->stream)
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2014-05-23 15:12:34 +04:00
|
|
|
DEBUG_TSMF("");
|
2011-09-20 10:27:10 +04:00
|
|
|
pa_threaded_mainloop_lock(pulse->mainloop);
|
|
|
|
pa_stream_set_write_callback(pulse->stream, NULL, NULL);
|
|
|
|
tsmf_pulse_wait_for_operation(pulse,
|
2014-05-23 15:12:34 +04:00
|
|
|
pa_stream_drain(pulse->stream, tsmf_pulse_stream_success_callback, pulse));
|
2011-09-20 10:27:10 +04:00
|
|
|
pa_stream_disconnect(pulse->stream);
|
|
|
|
pa_stream_unref(pulse->stream);
|
|
|
|
pulse->stream = NULL;
|
|
|
|
pa_threaded_mainloop_unlock(pulse->mainloop);
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-09-20 10:27:10 +04:00
|
|
|
}
|
|
|
|
|
2014-05-23 15:12:34 +04:00
|
|
|
static BOOL tsmf_pulse_open_stream(TSMFPulseAudioDevice *pulse)
|
2011-09-20 10:27:10 +04:00
|
|
|
{
|
|
|
|
pa_stream_state_t state;
|
|
|
|
pa_buffer_attr buffer_attr = { 0 };
|
2014-05-23 15:12:34 +04:00
|
|
|
if(!pulse->context)
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2014-05-23 15:12:34 +04:00
|
|
|
DEBUG_TSMF("");
|
2011-09-20 10:27:10 +04:00
|
|
|
pa_threaded_mainloop_lock(pulse->mainloop);
|
|
|
|
pulse->stream = pa_stream_new(pulse->context, "freerdp",
|
2014-05-23 15:12:34 +04:00
|
|
|
&pulse->sample_spec, NULL);
|
|
|
|
if(!pulse->stream)
|
2011-09-20 10:27:10 +04:00
|
|
|
{
|
|
|
|
pa_threaded_mainloop_unlock(pulse->mainloop);
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_ERR(TAG, "pa_stream_new failed (%d)",
|
2014-05-23 15:12:34 +04:00
|
|
|
pa_context_errno(pulse->context));
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-09-20 10:27:10 +04:00
|
|
|
}
|
|
|
|
pa_stream_set_state_callback(pulse->stream,
|
2014-05-23 15:12:34 +04:00
|
|
|
tsmf_pulse_stream_state_callback, pulse);
|
2011-09-20 10:27:10 +04:00
|
|
|
pa_stream_set_write_callback(pulse->stream,
|
2014-05-23 15:12:34 +04:00
|
|
|
tsmf_pulse_stream_request_callback, pulse);
|
2011-09-20 10:27:10 +04:00
|
|
|
buffer_attr.maxlength = pa_usec_to_bytes(500000, &pulse->sample_spec);
|
|
|
|
buffer_attr.tlength = pa_usec_to_bytes(250000, &pulse->sample_spec);
|
2012-10-09 22:00:28 +04:00
|
|
|
buffer_attr.prebuf = (UINT32) -1;
|
|
|
|
buffer_attr.minreq = (UINT32) -1;
|
|
|
|
buffer_attr.fragsize = (UINT32) -1;
|
2014-05-23 15:12:34 +04:00
|
|
|
if(pa_stream_connect_playback(pulse->stream,
|
|
|
|
pulse->device[0] ? pulse->device : NULL, &buffer_attr,
|
|
|
|
PA_STREAM_ADJUST_LATENCY | PA_STREAM_INTERPOLATE_TIMING | PA_STREAM_AUTO_TIMING_UPDATE,
|
|
|
|
NULL, NULL) < 0)
|
2011-09-20 10:27:10 +04:00
|
|
|
{
|
|
|
|
pa_threaded_mainloop_unlock(pulse->mainloop);
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_ERR(TAG, "pa_stream_connect_playback failed (%d)",
|
2014-05-23 15:12:34 +04:00
|
|
|
pa_context_errno(pulse->context));
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-09-20 10:27:10 +04:00
|
|
|
}
|
2014-05-23 15:12:34 +04:00
|
|
|
for(;;)
|
2011-09-20 10:27:10 +04:00
|
|
|
{
|
|
|
|
state = pa_stream_get_state(pulse->stream);
|
2014-05-23 15:12:34 +04:00
|
|
|
if(state == PA_STREAM_READY)
|
2011-09-20 10:27:10 +04:00
|
|
|
break;
|
2014-05-23 15:12:34 +04:00
|
|
|
if(!PA_STREAM_IS_GOOD(state))
|
2011-09-20 10:27:10 +04:00
|
|
|
{
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_ERR(TAG, "bad stream state (%d)",
|
2014-05-23 15:12:34 +04:00
|
|
|
pa_context_errno(pulse->context));
|
2011-09-20 10:27:10 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
pa_threaded_mainloop_wait(pulse->mainloop);
|
|
|
|
}
|
|
|
|
pa_threaded_mainloop_unlock(pulse->mainloop);
|
2014-05-23 15:12:34 +04:00
|
|
|
if(state == PA_STREAM_READY)
|
2011-09-20 10:27:10 +04:00
|
|
|
{
|
2014-05-23 15:12:34 +04:00
|
|
|
DEBUG_TSMF("connected");
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-09-20 10:27:10 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tsmf_pulse_close_stream(pulse);
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-09-20 10:27:10 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-23 15:12:34 +04:00
|
|
|
static BOOL tsmf_pulse_set_format(ITSMFAudioDevice *audio,
|
|
|
|
UINT32 sample_rate, UINT32 channels, UINT32 bits_per_sample)
|
2011-09-20 10:27:10 +04:00
|
|
|
{
|
2014-05-23 15:12:34 +04:00
|
|
|
TSMFPulseAudioDevice *pulse = (TSMFPulseAudioDevice *) audio;
|
|
|
|
DEBUG_TSMF("sample_rate %d channels %d bits_per_sample %d",
|
|
|
|
sample_rate, channels, bits_per_sample);
|
2011-09-20 10:27:10 +04:00
|
|
|
pulse->sample_spec.rate = sample_rate;
|
|
|
|
pulse->sample_spec.channels = channels;
|
|
|
|
pulse->sample_spec.format = PA_SAMPLE_S16LE;
|
|
|
|
return tsmf_pulse_open_stream(pulse);
|
|
|
|
}
|
|
|
|
|
2014-05-23 15:12:34 +04:00
|
|
|
static BOOL tsmf_pulse_play(ITSMFAudioDevice *audio, BYTE *data, UINT32 data_size)
|
2011-09-20 10:27:10 +04:00
|
|
|
{
|
2014-05-23 15:12:34 +04:00
|
|
|
TSMFPulseAudioDevice *pulse = (TSMFPulseAudioDevice *) audio;
|
|
|
|
BYTE *src;
|
2011-09-20 10:27:10 +04:00
|
|
|
int len;
|
|
|
|
int ret;
|
2014-05-23 15:12:34 +04:00
|
|
|
DEBUG_TSMF("data_size %d", data_size);
|
|
|
|
if(pulse->stream)
|
2011-09-20 10:27:10 +04:00
|
|
|
{
|
|
|
|
pa_threaded_mainloop_lock(pulse->mainloop);
|
|
|
|
src = data;
|
2014-05-23 15:12:34 +04:00
|
|
|
while(data_size > 0)
|
2011-09-20 10:27:10 +04:00
|
|
|
{
|
2014-05-23 15:12:34 +04:00
|
|
|
while((len = pa_stream_writable_size(pulse->stream)) == 0)
|
2011-09-20 10:27:10 +04:00
|
|
|
{
|
2014-05-23 15:12:34 +04:00
|
|
|
DEBUG_TSMF("waiting");
|
2011-09-20 10:27:10 +04:00
|
|
|
pa_threaded_mainloop_wait(pulse->mainloop);
|
|
|
|
}
|
2014-05-23 15:12:34 +04:00
|
|
|
if(len < 0)
|
2011-09-20 10:27:10 +04:00
|
|
|
break;
|
2014-05-23 15:12:34 +04:00
|
|
|
if(len > data_size)
|
2011-09-20 10:27:10 +04:00
|
|
|
len = data_size;
|
|
|
|
ret = pa_stream_write(pulse->stream, src, len, NULL, 0LL, PA_SEEK_RELATIVE);
|
2014-05-23 15:12:34 +04:00
|
|
|
if(ret < 0)
|
2011-09-20 10:27:10 +04:00
|
|
|
{
|
2014-05-23 15:12:34 +04:00
|
|
|
DEBUG_TSMF("pa_stream_write failed (%d)",
|
|
|
|
pa_context_errno(pulse->context));
|
2011-09-20 10:27:10 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
src += len;
|
|
|
|
data_size -= len;
|
|
|
|
}
|
|
|
|
pa_threaded_mainloop_unlock(pulse->mainloop);
|
|
|
|
}
|
2012-10-09 07:21:26 +04:00
|
|
|
free(data);
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-09-20 10:27:10 +04:00
|
|
|
}
|
|
|
|
|
2014-05-23 15:12:34 +04:00
|
|
|
static UINT64 tsmf_pulse_get_latency(ITSMFAudioDevice *audio)
|
2011-09-20 10:27:10 +04:00
|
|
|
{
|
|
|
|
pa_usec_t usec;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT64 latency = 0;
|
2014-05-23 15:12:34 +04:00
|
|
|
TSMFPulseAudioDevice *pulse = (TSMFPulseAudioDevice *) audio;
|
|
|
|
if(pulse->stream && pa_stream_get_latency(pulse->stream, &usec, NULL) == 0)
|
2011-09-20 10:27:10 +04:00
|
|
|
{
|
2012-10-09 11:26:39 +04:00
|
|
|
latency = ((UINT64)usec) * 10LL;
|
2011-09-20 10:27:10 +04:00
|
|
|
}
|
|
|
|
return latency;
|
|
|
|
}
|
|
|
|
|
2015-06-29 16:21:53 +03:00
|
|
|
static BOOL tsmf_pulse_flush(ITSMFAudioDevice *audio)
|
2011-09-20 10:27:10 +04:00
|
|
|
{
|
2014-05-23 15:12:34 +04:00
|
|
|
TSMFPulseAudioDevice *pulse = (TSMFPulseAudioDevice *) audio;
|
2011-09-20 10:27:10 +04:00
|
|
|
pa_threaded_mainloop_lock(pulse->mainloop);
|
|
|
|
tsmf_pulse_wait_for_operation(pulse,
|
2014-05-23 15:12:34 +04:00
|
|
|
pa_stream_flush(pulse->stream, tsmf_pulse_stream_success_callback, pulse));
|
2011-09-20 10:27:10 +04:00
|
|
|
pa_threaded_mainloop_unlock(pulse->mainloop);
|
2015-06-29 16:21:53 +03:00
|
|
|
return TRUE;
|
2011-09-20 10:27:10 +04:00
|
|
|
}
|
|
|
|
|
2014-05-23 15:12:34 +04:00
|
|
|
static void tsmf_pulse_free(ITSMFAudioDevice *audio)
|
2011-09-20 10:27:10 +04:00
|
|
|
{
|
2014-05-23 15:12:34 +04:00
|
|
|
TSMFPulseAudioDevice *pulse = (TSMFPulseAudioDevice *) audio;
|
|
|
|
DEBUG_TSMF("");
|
2011-09-20 10:27:10 +04:00
|
|
|
tsmf_pulse_close_stream(pulse);
|
2014-05-23 15:12:34 +04:00
|
|
|
if(pulse->mainloop)
|
2011-09-20 10:27:10 +04:00
|
|
|
{
|
|
|
|
pa_threaded_mainloop_stop(pulse->mainloop);
|
|
|
|
}
|
2014-05-23 15:12:34 +04:00
|
|
|
if(pulse->context)
|
2011-09-20 10:27:10 +04:00
|
|
|
{
|
|
|
|
pa_context_disconnect(pulse->context);
|
|
|
|
pa_context_unref(pulse->context);
|
|
|
|
pulse->context = NULL;
|
|
|
|
}
|
2014-05-23 15:12:34 +04:00
|
|
|
if(pulse->mainloop)
|
2011-09-20 10:27:10 +04:00
|
|
|
{
|
|
|
|
pa_threaded_mainloop_free(pulse->mainloop);
|
|
|
|
pulse->mainloop = NULL;
|
|
|
|
}
|
2012-10-09 07:21:26 +04:00
|
|
|
free(pulse);
|
2011-09-20 10:27:10 +04:00
|
|
|
}
|
|
|
|
|
2012-11-20 07:31:15 +04:00
|
|
|
#ifdef STATIC_CHANNELS
|
|
|
|
#define freerdp_tsmf_client_audio_subsystem_entry pulse_freerdp_tsmf_client_audio_subsystem_entry
|
|
|
|
#endif
|
|
|
|
|
2014-05-23 15:12:34 +04:00
|
|
|
ITSMFAudioDevice *freerdp_tsmf_client_audio_subsystem_entry(void)
|
2011-09-20 10:27:10 +04:00
|
|
|
{
|
2014-05-23 15:12:34 +04:00
|
|
|
TSMFPulseAudioDevice *pulse;
|
2015-06-29 16:21:53 +03:00
|
|
|
|
|
|
|
pulse = (TSMFPulseAudioDevice *) calloc(1, sizeof(TSMFPulseAudioDevice));
|
|
|
|
if (!pulse)
|
|
|
|
return NULL;
|
2011-09-20 10:27:10 +04:00
|
|
|
pulse->iface.Open = tsmf_pulse_open;
|
|
|
|
pulse->iface.SetFormat = tsmf_pulse_set_format;
|
|
|
|
pulse->iface.Play = tsmf_pulse_play;
|
|
|
|
pulse->iface.GetLatency = tsmf_pulse_get_latency;
|
|
|
|
pulse->iface.Flush = tsmf_pulse_flush;
|
|
|
|
pulse->iface.Free = tsmf_pulse_free;
|
2014-05-23 15:12:34 +04:00
|
|
|
return (ITSMFAudioDevice *) pulse;
|
2011-09-20 10:27:10 +04:00
|
|
|
}
|
|
|
|
|