2011-09-21 09:28:02 +04:00
|
|
|
/**
|
2012-10-09 07:02:04 +04:00
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
2011-09-21 09:28:02 +04:00
|
|
|
* Audio Input Redirection Virtual Channel - PulseAudio implementation
|
|
|
|
*
|
|
|
|
* 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-21 09:28:02 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2012-08-15 01:09:01 +04:00
|
|
|
|
2012-11-20 07:31:15 +04:00
|
|
|
#include <winpr/crt.h>
|
|
|
|
#include <winpr/cmdline.h>
|
|
|
|
|
2011-09-21 09:28:02 +04:00
|
|
|
#include <pulse/pulseaudio.h>
|
2012-11-20 07:31:15 +04:00
|
|
|
|
2011-09-21 09:28:02 +04:00
|
|
|
#include <freerdp/types.h>
|
2012-11-20 07:31:15 +04:00
|
|
|
#include <freerdp/addin.h>
|
2013-02-20 02:47:55 +04:00
|
|
|
#include <freerdp/codec/dsp.h>
|
2011-09-21 09:28:02 +04:00
|
|
|
|
|
|
|
#include "audin_main.h"
|
|
|
|
|
|
|
|
typedef struct _AudinPulseDevice
|
|
|
|
{
|
|
|
|
IAudinDevice iface;
|
|
|
|
|
2012-11-20 07:31:15 +04:00
|
|
|
char* device_name;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 frames_per_packet;
|
2011-09-21 09:28:02 +04:00
|
|
|
pa_threaded_mainloop* mainloop;
|
|
|
|
pa_context* context;
|
|
|
|
pa_sample_spec sample_spec;
|
|
|
|
pa_stream* stream;
|
|
|
|
int format;
|
|
|
|
int block_size;
|
2012-05-09 12:15:23 +04:00
|
|
|
|
|
|
|
FREERDP_DSP_CONTEXT* dsp_context;
|
2011-09-21 09:28:02 +04:00
|
|
|
|
|
|
|
int bytes_per_frame;
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE* buffer;
|
2011-09-21 09:28:02 +04:00
|
|
|
int buffer_frames;
|
|
|
|
|
|
|
|
AudinReceive receive;
|
|
|
|
void* user_data;
|
|
|
|
} AudinPulseDevice;
|
|
|
|
|
|
|
|
static void audin_pulse_context_state_callback(pa_context* context, void* userdata)
|
|
|
|
{
|
|
|
|
pa_context_state_t state;
|
|
|
|
AudinPulseDevice* pulse = (AudinPulseDevice*) userdata;
|
|
|
|
|
|
|
|
state = pa_context_get_state(context);
|
|
|
|
switch (state)
|
|
|
|
{
|
|
|
|
case PA_CONTEXT_READY:
|
|
|
|
DEBUG_DVC("PA_CONTEXT_READY");
|
|
|
|
pa_threaded_mainloop_signal (pulse->mainloop, 0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PA_CONTEXT_FAILED:
|
|
|
|
case PA_CONTEXT_TERMINATED:
|
|
|
|
DEBUG_DVC("state %d", (int)state);
|
|
|
|
pa_threaded_mainloop_signal (pulse->mainloop, 0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
DEBUG_DVC("state %d", (int)state);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-09 10:38:39 +04:00
|
|
|
static BOOL audin_pulse_connect(IAudinDevice* device)
|
2011-09-21 09:28:02 +04:00
|
|
|
{
|
|
|
|
pa_context_state_t state;
|
|
|
|
AudinPulseDevice* pulse = (AudinPulseDevice*) device;
|
|
|
|
|
|
|
|
if (!pulse->context)
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-09-21 09:28:02 +04:00
|
|
|
|
|
|
|
if (pa_context_connect(pulse->context, NULL, 0, NULL))
|
|
|
|
{
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_ERR(TAG, "pa_context_connect failed (%d)",
|
|
|
|
pa_context_errno(pulse->context));
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-09-21 09:28:02 +04:00
|
|
|
}
|
|
|
|
pa_threaded_mainloop_lock(pulse->mainloop);
|
|
|
|
if (pa_threaded_mainloop_start(pulse->mainloop) < 0)
|
|
|
|
{
|
|
|
|
pa_threaded_mainloop_unlock(pulse->mainloop);
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_ERR(TAG, "pa_threaded_mainloop_start failed (%d)",
|
|
|
|
pa_context_errno(pulse->context));
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-09-21 09:28:02 +04:00
|
|
|
}
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
state = pa_context_get_state(pulse->context);
|
|
|
|
if (state == PA_CONTEXT_READY)
|
|
|
|
break;
|
|
|
|
if (!PA_CONTEXT_IS_GOOD(state))
|
|
|
|
{
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_ERR(TAG, "bad context state (%d)",
|
|
|
|
pa_context_errno(pulse->context));
|
2011-09-21 09:28:02 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
pa_threaded_mainloop_wait(pulse->mainloop);
|
|
|
|
}
|
|
|
|
pa_threaded_mainloop_unlock(pulse->mainloop);
|
|
|
|
if (state == PA_CONTEXT_READY)
|
|
|
|
{
|
|
|
|
DEBUG_DVC("connected");
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-09-21 09:28:02 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pa_context_disconnect(pulse->context);
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-09-21 09:28:02 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void audin_pulse_free(IAudinDevice* device)
|
|
|
|
{
|
|
|
|
AudinPulseDevice* pulse = (AudinPulseDevice*) device;
|
|
|
|
|
|
|
|
DEBUG_DVC("");
|
|
|
|
|
|
|
|
if (!pulse)
|
|
|
|
return;
|
|
|
|
if (pulse->mainloop)
|
|
|
|
{
|
|
|
|
pa_threaded_mainloop_stop(pulse->mainloop);
|
|
|
|
}
|
|
|
|
if (pulse->context)
|
|
|
|
{
|
|
|
|
pa_context_disconnect(pulse->context);
|
|
|
|
pa_context_unref(pulse->context);
|
|
|
|
pulse->context = NULL;
|
|
|
|
}
|
|
|
|
if (pulse->mainloop)
|
|
|
|
{
|
|
|
|
pa_threaded_mainloop_free(pulse->mainloop);
|
|
|
|
pulse->mainloop = NULL;
|
|
|
|
}
|
2012-05-09 12:15:23 +04:00
|
|
|
freerdp_dsp_context_free(pulse->dsp_context);
|
2012-10-09 07:21:26 +04:00
|
|
|
free(pulse);
|
2011-09-21 09:28:02 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 10:38:39 +04:00
|
|
|
static BOOL audin_pulse_format_supported(IAudinDevice* device, audinFormat* format)
|
2011-09-21 09:28:02 +04:00
|
|
|
{
|
|
|
|
AudinPulseDevice* pulse = (AudinPulseDevice*) device;
|
|
|
|
|
|
|
|
if (!pulse->context)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
switch (format->wFormatTag)
|
|
|
|
{
|
|
|
|
case 1: /* PCM */
|
|
|
|
if (format->cbSize == 0 &&
|
|
|
|
(format->nSamplesPerSec <= PA_RATE_MAX) &&
|
|
|
|
(format->wBitsPerSample == 8 || format->wBitsPerSample == 16) &&
|
|
|
|
(format->nChannels >= 1 && format->nChannels <= PA_CHANNELS_MAX))
|
|
|
|
{
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-09-21 09:28:02 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 6: /* A-LAW */
|
|
|
|
case 7: /* U-LAW */
|
|
|
|
if (format->cbSize == 0 &&
|
|
|
|
(format->nSamplesPerSec <= PA_RATE_MAX) &&
|
|
|
|
(format->wBitsPerSample == 8) &&
|
|
|
|
(format->nChannels >= 1 && format->nChannels <= PA_CHANNELS_MAX))
|
|
|
|
{
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-09-21 09:28:02 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x11: /* IMA ADPCM */
|
|
|
|
if ((format->nSamplesPerSec <= PA_RATE_MAX) &&
|
|
|
|
(format->wBitsPerSample == 4) &&
|
|
|
|
(format->nChannels == 1 || format->nChannels == 2))
|
|
|
|
{
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-09-21 09:28:02 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-09-21 09:28:02 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
static void audin_pulse_set_format(IAudinDevice* device, audinFormat* format, UINT32 FramesPerPacket)
|
2011-09-21 09:28:02 +04:00
|
|
|
{
|
|
|
|
int bs;
|
|
|
|
pa_sample_spec sample_spec = { 0 };
|
|
|
|
AudinPulseDevice* pulse = (AudinPulseDevice*) device;
|
|
|
|
|
|
|
|
if (!pulse->context)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (FramesPerPacket > 0)
|
|
|
|
{
|
|
|
|
pulse->frames_per_packet = FramesPerPacket;
|
|
|
|
}
|
|
|
|
|
|
|
|
sample_spec.rate = format->nSamplesPerSec;
|
|
|
|
sample_spec.channels = format->nChannels;
|
|
|
|
switch (format->wFormatTag)
|
|
|
|
{
|
|
|
|
case 1: /* PCM */
|
|
|
|
switch (format->wBitsPerSample)
|
|
|
|
{
|
|
|
|
case 8:
|
|
|
|
sample_spec.format = PA_SAMPLE_U8;
|
|
|
|
break;
|
|
|
|
case 16:
|
|
|
|
sample_spec.format = PA_SAMPLE_S16LE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 6: /* A-LAW */
|
|
|
|
sample_spec.format = PA_SAMPLE_ALAW;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 7: /* U-LAW */
|
|
|
|
sample_spec.format = PA_SAMPLE_ULAW;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x11: /* IMA ADPCM */
|
|
|
|
sample_spec.format = PA_SAMPLE_S16LE;
|
|
|
|
bs = (format->nBlockAlign - 4 * format->nChannels) * 4;
|
|
|
|
pulse->frames_per_packet = (pulse->frames_per_packet * format->nChannels * 2 /
|
|
|
|
bs + 1) * bs / (format->nChannels * 2);
|
|
|
|
DEBUG_DVC("aligned FramesPerPacket=%d",
|
|
|
|
pulse->frames_per_packet);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
pulse->sample_spec = sample_spec;
|
|
|
|
pulse->format = format->wFormatTag;
|
|
|
|
pulse->block_size = format->nBlockAlign;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void audin_pulse_stream_state_callback(pa_stream* stream, void* userdata)
|
|
|
|
{
|
|
|
|
pa_stream_state_t state;
|
|
|
|
AudinPulseDevice* pulse = (AudinPulseDevice*) userdata;
|
|
|
|
|
|
|
|
state = pa_stream_get_state(stream);
|
|
|
|
switch (state)
|
|
|
|
{
|
|
|
|
case PA_STREAM_READY:
|
|
|
|
DEBUG_DVC("PA_STREAM_READY");
|
|
|
|
pa_threaded_mainloop_signal(pulse->mainloop, 0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PA_STREAM_FAILED:
|
|
|
|
case PA_STREAM_TERMINATED:
|
|
|
|
DEBUG_DVC("state %d", (int)state);
|
|
|
|
pa_threaded_mainloop_signal(pulse->mainloop, 0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
DEBUG_DVC("state %d", (int)state);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void audin_pulse_stream_request_callback(pa_stream* stream, size_t length, void* userdata)
|
|
|
|
{
|
|
|
|
int frames;
|
|
|
|
int cframes;
|
2012-10-09 10:38:39 +04:00
|
|
|
BOOL ret;
|
2011-09-21 09:28:02 +04:00
|
|
|
const void* data;
|
2012-10-09 11:01:37 +04:00
|
|
|
const BYTE* src;
|
2011-09-21 09:28:02 +04:00
|
|
|
int encoded_size;
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE* encoded_data;
|
2011-09-21 09:28:02 +04:00
|
|
|
AudinPulseDevice* pulse = (AudinPulseDevice*) userdata;
|
|
|
|
|
2013-07-26 23:54:20 +04:00
|
|
|
/* There is a race condition here where we may receive this callback
|
|
|
|
* before the buffer has been set up in the main code. It's probably
|
|
|
|
* possible to fix with additional locking, but it's easier just to
|
|
|
|
* ignore input until the buffer is ready.
|
|
|
|
*/
|
|
|
|
if (pulse->buffer == NULL)
|
|
|
|
{
|
2014-09-12 18:19:32 +04:00
|
|
|
/* WLog_ERR(TAG, "%s: ignoring input, pulse buffer not ready.\n", __func__); */
|
2013-07-26 23:54:20 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-09-21 09:28:02 +04:00
|
|
|
pa_stream_peek(stream, &data, &length);
|
|
|
|
frames = length / pulse->bytes_per_frame;
|
|
|
|
|
|
|
|
DEBUG_DVC("length %d frames %d", (int) length, frames);
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
src = (const BYTE*) data;
|
2011-09-21 09:28:02 +04:00
|
|
|
while (frames > 0)
|
|
|
|
{
|
|
|
|
cframes = pulse->frames_per_packet - pulse->buffer_frames;
|
|
|
|
if (cframes > frames)
|
|
|
|
cframes = frames;
|
|
|
|
memcpy(pulse->buffer + pulse->buffer_frames * pulse->bytes_per_frame,
|
|
|
|
src, cframes * pulse->bytes_per_frame);
|
|
|
|
pulse->buffer_frames += cframes;
|
|
|
|
if (pulse->buffer_frames >= pulse->frames_per_packet)
|
|
|
|
{
|
|
|
|
if (pulse->format == 0x11)
|
|
|
|
{
|
2012-05-09 12:15:23 +04:00
|
|
|
pulse->dsp_context->encode_ima_adpcm(pulse->dsp_context,
|
2011-09-21 09:28:02 +04:00
|
|
|
pulse->buffer, pulse->buffer_frames * pulse->bytes_per_frame,
|
2012-05-09 12:15:23 +04:00
|
|
|
pulse->sample_spec.channels, pulse->block_size);
|
|
|
|
encoded_data = pulse->dsp_context->adpcm_buffer;
|
|
|
|
encoded_size = pulse->dsp_context->adpcm_size;
|
2011-09-21 09:28:02 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
encoded_data = pulse->buffer;
|
|
|
|
encoded_size = pulse->buffer_frames * pulse->bytes_per_frame;
|
|
|
|
}
|
|
|
|
|
2013-09-27 13:39:04 +04:00
|
|
|
DEBUG_DVC("encoded %d [%d] to %d [%X]",
|
|
|
|
pulse->buffer_frames, pulse->bytes_per_frame, encoded_size,
|
|
|
|
pulse->format);
|
2011-09-21 09:28:02 +04:00
|
|
|
ret = pulse->receive(encoded_data, encoded_size, pulse->user_data);
|
|
|
|
pulse->buffer_frames = 0;
|
|
|
|
if (!ret)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
src += cframes * pulse->bytes_per_frame;
|
|
|
|
frames -= cframes;
|
|
|
|
}
|
|
|
|
|
|
|
|
pa_stream_drop(stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void audin_pulse_close(IAudinDevice* device)
|
|
|
|
{
|
|
|
|
AudinPulseDevice* pulse = (AudinPulseDevice*) device;
|
|
|
|
|
|
|
|
if (!pulse->context || !pulse->stream)
|
|
|
|
return;
|
|
|
|
|
|
|
|
DEBUG_DVC("");
|
|
|
|
|
|
|
|
pa_threaded_mainloop_lock(pulse->mainloop);
|
|
|
|
pa_stream_disconnect(pulse->stream);
|
|
|
|
pa_stream_unref(pulse->stream);
|
|
|
|
pulse->stream = NULL;
|
|
|
|
pa_threaded_mainloop_unlock(pulse->mainloop);
|
|
|
|
|
|
|
|
pulse->receive = NULL;
|
|
|
|
pulse->user_data = NULL;
|
|
|
|
if (pulse->buffer)
|
|
|
|
{
|
2012-10-09 07:21:26 +04:00
|
|
|
free(pulse->buffer);
|
2011-09-21 09:28:02 +04:00
|
|
|
pulse->buffer = NULL;
|
|
|
|
pulse->buffer_frames = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void audin_pulse_open(IAudinDevice* device, AudinReceive receive, void* user_data)
|
|
|
|
{
|
|
|
|
pa_stream_state_t state;
|
|
|
|
pa_buffer_attr buffer_attr = { 0 };
|
|
|
|
AudinPulseDevice* pulse = (AudinPulseDevice*) device;
|
|
|
|
|
|
|
|
if (!pulse->context)
|
|
|
|
return;
|
|
|
|
if (!pulse->sample_spec.rate || pulse->stream)
|
|
|
|
return;
|
|
|
|
|
|
|
|
DEBUG_DVC("");
|
|
|
|
|
2013-07-26 23:54:20 +04:00
|
|
|
pulse->buffer = NULL;
|
2011-09-21 09:28:02 +04:00
|
|
|
pulse->receive = receive;
|
|
|
|
pulse->user_data = user_data;
|
|
|
|
|
|
|
|
pa_threaded_mainloop_lock(pulse->mainloop);
|
|
|
|
pulse->stream = pa_stream_new(pulse->context, "freerdp_audin",
|
|
|
|
&pulse->sample_spec, NULL);
|
|
|
|
if (!pulse->stream)
|
|
|
|
{
|
|
|
|
pa_threaded_mainloop_unlock(pulse->mainloop);
|
|
|
|
DEBUG_DVC("pa_stream_new failed (%d)",
|
|
|
|
pa_context_errno(pulse->context));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
pulse->bytes_per_frame = pa_frame_size(&pulse->sample_spec);
|
|
|
|
pa_stream_set_state_callback(pulse->stream,
|
|
|
|
audin_pulse_stream_state_callback, pulse);
|
|
|
|
pa_stream_set_read_callback(pulse->stream,
|
|
|
|
audin_pulse_stream_request_callback, pulse);
|
2012-10-09 22:00:28 +04:00
|
|
|
buffer_attr.maxlength = (UINT32) -1;
|
|
|
|
buffer_attr.tlength = (UINT32) -1;
|
|
|
|
buffer_attr.prebuf = (UINT32) -1;
|
|
|
|
buffer_attr.minreq = (UINT32) -1;
|
2011-09-21 09:28:02 +04:00
|
|
|
/* 500ms latency */
|
|
|
|
buffer_attr.fragsize = pa_usec_to_bytes(500000, &pulse->sample_spec);
|
|
|
|
if (pa_stream_connect_record(pulse->stream,
|
2013-09-26 18:05:16 +04:00
|
|
|
pulse->device_name,
|
2011-09-21 09:28:02 +04:00
|
|
|
&buffer_attr, PA_STREAM_ADJUST_LATENCY) < 0)
|
|
|
|
{
|
|
|
|
pa_threaded_mainloop_unlock(pulse->mainloop);
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_ERR(TAG, "pa_stream_connect_playback failed (%d)",
|
|
|
|
pa_context_errno(pulse->context));
|
2011-09-21 09:28:02 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
state = pa_stream_get_state(pulse->stream);
|
|
|
|
if (state == PA_STREAM_READY)
|
|
|
|
break;
|
|
|
|
if (!PA_STREAM_IS_GOOD(state))
|
|
|
|
{
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_ERR(TAG, "bad stream state (%d)",
|
|
|
|
pa_context_errno(pulse->context));
|
2011-09-21 09:28:02 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
pa_threaded_mainloop_wait(pulse->mainloop);
|
|
|
|
}
|
|
|
|
pa_threaded_mainloop_unlock(pulse->mainloop);
|
|
|
|
if (state == PA_STREAM_READY)
|
|
|
|
{
|
2012-05-09 12:15:23 +04:00
|
|
|
freerdp_dsp_context_reset_adpcm(pulse->dsp_context);
|
2012-11-20 08:49:08 +04:00
|
|
|
pulse->buffer = malloc(pulse->bytes_per_frame * pulse->frames_per_packet);
|
|
|
|
ZeroMemory(pulse->buffer, pulse->bytes_per_frame * pulse->frames_per_packet);
|
2011-09-21 09:28:02 +04:00
|
|
|
pulse->buffer_frames = 0;
|
|
|
|
DEBUG_DVC("connected");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
audin_pulse_close(device);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-26 18:05:16 +04:00
|
|
|
static COMMAND_LINE_ARGUMENT_A audin_pulse_args[] =
|
2012-11-20 07:31:15 +04:00
|
|
|
{
|
|
|
|
{ "audio-dev", COMMAND_LINE_VALUE_REQUIRED, "<device>", NULL, NULL, -1, NULL, "audio device name" },
|
|
|
|
{ NULL, 0, NULL, NULL, NULL, -1, NULL, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
static void audin_pulse_parse_addin_args(AudinPulseDevice* device, ADDIN_ARGV* args)
|
|
|
|
{
|
|
|
|
int status;
|
|
|
|
DWORD flags;
|
|
|
|
COMMAND_LINE_ARGUMENT_A* arg;
|
|
|
|
AudinPulseDevice* pulse = (AudinPulseDevice*) device;
|
|
|
|
|
|
|
|
flags = COMMAND_LINE_SIGIL_NONE | COMMAND_LINE_SEPARATOR_COLON;
|
|
|
|
|
|
|
|
status = CommandLineParseArgumentsA(args->argc, (const char**) args->argv, audin_pulse_args, flags, pulse, NULL, NULL);
|
|
|
|
|
|
|
|
arg = audin_pulse_args;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (!(arg->Flags & COMMAND_LINE_VALUE_PRESENT))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
CommandLineSwitchStart(arg)
|
|
|
|
|
|
|
|
CommandLineSwitchCase(arg, "audio-dev")
|
|
|
|
{
|
|
|
|
pulse->device_name = _strdup(arg->Value);
|
|
|
|
}
|
|
|
|
|
|
|
|
CommandLineSwitchEnd(arg)
|
|
|
|
}
|
|
|
|
while ((arg = CommandLineFindNextArgumentA(arg)) != NULL);
|
|
|
|
}
|
|
|
|
|
2012-11-06 04:55:15 +04:00
|
|
|
#ifdef STATIC_CHANNELS
|
|
|
|
#define freerdp_audin_client_subsystem_entry pulse_freerdp_audin_client_subsystem_entry
|
|
|
|
#endif
|
|
|
|
|
|
|
|
int freerdp_audin_client_subsystem_entry(PFREERDP_AUDIN_DEVICE_ENTRY_POINTS pEntryPoints)
|
2011-09-21 09:28:02 +04:00
|
|
|
{
|
2012-11-20 07:31:15 +04:00
|
|
|
ADDIN_ARGV* args;
|
2011-09-21 09:28:02 +04:00
|
|
|
AudinPulseDevice* pulse;
|
|
|
|
|
2012-11-20 07:31:15 +04:00
|
|
|
pulse = (AudinPulseDevice*) malloc(sizeof(AudinPulseDevice));
|
|
|
|
ZeroMemory(pulse, sizeof(AudinPulseDevice));
|
2011-09-21 09:28:02 +04:00
|
|
|
|
|
|
|
pulse->iface.Open = audin_pulse_open;
|
|
|
|
pulse->iface.FormatSupported = audin_pulse_format_supported;
|
|
|
|
pulse->iface.SetFormat = audin_pulse_set_format;
|
|
|
|
pulse->iface.Close = audin_pulse_close;
|
|
|
|
pulse->iface.Free = audin_pulse_free;
|
|
|
|
|
2012-11-20 07:31:15 +04:00
|
|
|
args = pEntryPoints->args;
|
|
|
|
|
|
|
|
audin_pulse_parse_addin_args(pulse, args);
|
|
|
|
|
2012-05-09 12:15:23 +04:00
|
|
|
pulse->dsp_context = freerdp_dsp_context_new();
|
|
|
|
|
2011-09-21 09:28:02 +04:00
|
|
|
pulse->mainloop = pa_threaded_mainloop_new();
|
2012-11-20 07:31:15 +04:00
|
|
|
|
2011-09-21 09:28:02 +04:00
|
|
|
if (!pulse->mainloop)
|
|
|
|
{
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_ERR(TAG, "pa_threaded_mainloop_new failed");
|
2011-09-21 09:28:02 +04:00
|
|
|
audin_pulse_free((IAudinDevice*) pulse);
|
|
|
|
return 1;
|
|
|
|
}
|
2012-11-20 07:31:15 +04:00
|
|
|
|
2011-09-21 09:28:02 +04:00
|
|
|
pulse->context = pa_context_new(pa_threaded_mainloop_get_api(pulse->mainloop), "freerdp");
|
2012-11-20 07:31:15 +04:00
|
|
|
|
2011-09-21 09:28:02 +04:00
|
|
|
if (!pulse->context)
|
|
|
|
{
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_ERR(TAG, "pa_context_new failed");
|
2011-09-21 09:28:02 +04:00
|
|
|
audin_pulse_free((IAudinDevice*) pulse);
|
|
|
|
return 1;
|
|
|
|
}
|
2012-11-20 07:31:15 +04:00
|
|
|
|
2011-09-21 09:28:02 +04:00
|
|
|
pa_context_set_state_callback(pulse->context, audin_pulse_context_state_callback, pulse);
|
2012-11-20 07:31:15 +04:00
|
|
|
|
2011-09-21 09:28:02 +04:00
|
|
|
if (!audin_pulse_connect((IAudinDevice*) pulse))
|
|
|
|
{
|
|
|
|
audin_pulse_free((IAudinDevice*) pulse);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
pEntryPoints->pRegisterAudinDevice(pEntryPoints->plugin, (IAudinDevice*) pulse);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2013-09-04 18:24:27 +04:00
|
|
|
|