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 - ALSA 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>
|
2013-03-21 04:44:31 +04:00
|
|
|
#include <winpr/synch.h>
|
|
|
|
#include <winpr/thread.h>
|
2012-11-20 07:31:15 +04:00
|
|
|
#include <winpr/cmdline.h>
|
|
|
|
|
2011-09-21 09:28:02 +04:00
|
|
|
#include <alsa/asoundlib.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>
|
2013-02-21 06:34:47 +04:00
|
|
|
#include <freerdp/channels/rdpsnd.h>
|
2011-09-21 09:28:02 +04:00
|
|
|
|
|
|
|
#include "audin_main.h"
|
|
|
|
|
|
|
|
typedef struct _AudinALSADevice
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
UINT32 target_rate;
|
|
|
|
UINT32 actual_rate;
|
2011-09-21 09:28:02 +04:00
|
|
|
snd_pcm_format_t format;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 target_channels;
|
|
|
|
UINT32 actual_channels;
|
2011-09-21 09:28:02 +04:00
|
|
|
int bytes_per_channel;
|
|
|
|
int wformat;
|
|
|
|
int block_size;
|
2012-05-09 12:15:23 +04:00
|
|
|
|
|
|
|
FREERDP_DSP_CONTEXT* dsp_context;
|
2011-09-21 09:28:02 +04:00
|
|
|
|
2013-03-21 04:44:31 +04:00
|
|
|
HANDLE thread;
|
|
|
|
HANDLE stopEvent;
|
2011-09-21 09:28:02 +04:00
|
|
|
|
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;
|
|
|
|
} AudinALSADevice;
|
|
|
|
|
2012-10-09 10:38:39 +04:00
|
|
|
static BOOL audin_alsa_set_params(AudinALSADevice* alsa, snd_pcm_t* capture_handle)
|
2011-09-21 09:28:02 +04:00
|
|
|
{
|
|
|
|
int error;
|
|
|
|
snd_pcm_hw_params_t* hw_params;
|
|
|
|
|
|
|
|
if ((error = snd_pcm_hw_params_malloc(&hw_params)) < 0)
|
|
|
|
{
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_ERR(TAG, "snd_pcm_hw_params_malloc (%s)",
|
|
|
|
snd_strerror(error));
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-09-21 09:28:02 +04:00
|
|
|
}
|
2013-02-21 06:34:47 +04:00
|
|
|
|
2011-09-21 09:28:02 +04:00
|
|
|
snd_pcm_hw_params_any(capture_handle, hw_params);
|
2013-02-21 06:34:47 +04:00
|
|
|
snd_pcm_hw_params_set_access(capture_handle, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED);
|
|
|
|
snd_pcm_hw_params_set_format(capture_handle, hw_params, alsa->format);
|
|
|
|
snd_pcm_hw_params_set_rate_near(capture_handle, hw_params, &alsa->actual_rate, NULL);
|
|
|
|
snd_pcm_hw_params_set_channels_near(capture_handle, hw_params, &alsa->actual_channels);
|
2011-09-21 09:28:02 +04:00
|
|
|
snd_pcm_hw_params(capture_handle, hw_params);
|
|
|
|
snd_pcm_hw_params_free(hw_params);
|
|
|
|
snd_pcm_prepare(capture_handle);
|
|
|
|
|
|
|
|
if ((alsa->actual_rate != alsa->target_rate) ||
|
|
|
|
(alsa->actual_channels != alsa->target_channels))
|
|
|
|
{
|
|
|
|
DEBUG_DVC("actual rate %d / channel %d is "
|
|
|
|
"different from target rate %d / channel %d, resampling required.",
|
|
|
|
alsa->actual_rate, alsa->actual_channels,
|
|
|
|
alsa->target_rate, alsa->target_channels);
|
|
|
|
}
|
2013-02-21 06:34:47 +04:00
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-09-21 09:28:02 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
static BOOL audin_alsa_thread_receive(AudinALSADevice* alsa, BYTE* src, int size)
|
2011-09-21 09:28:02 +04:00
|
|
|
{
|
|
|
|
int frames;
|
|
|
|
int cframes;
|
|
|
|
int ret = 0;
|
|
|
|
int encoded_size;
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE* encoded_data;
|
2011-09-21 09:28:02 +04:00
|
|
|
int rbytes_per_frame;
|
|
|
|
int tbytes_per_frame;
|
|
|
|
|
|
|
|
rbytes_per_frame = alsa->actual_channels * alsa->bytes_per_channel;
|
|
|
|
tbytes_per_frame = alsa->target_channels * alsa->bytes_per_channel;
|
|
|
|
|
|
|
|
if ((alsa->target_rate == alsa->actual_rate) &&
|
|
|
|
(alsa->target_channels == alsa->actual_channels))
|
|
|
|
{
|
|
|
|
frames = size / rbytes_per_frame;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-05-09 12:15:23 +04:00
|
|
|
alsa->dsp_context->resample(alsa->dsp_context, src, alsa->bytes_per_channel,
|
2011-09-21 09:28:02 +04:00
|
|
|
alsa->actual_channels, alsa->actual_rate, size / rbytes_per_frame,
|
2012-05-09 12:15:23 +04:00
|
|
|
alsa->target_channels, alsa->target_rate);
|
|
|
|
frames = alsa->dsp_context->resampled_frames;
|
2011-09-21 09:28:02 +04:00
|
|
|
DEBUG_DVC("resampled %d frames at %d to %d frames at %d",
|
|
|
|
size / rbytes_per_frame, alsa->actual_rate, frames, alsa->target_rate);
|
|
|
|
size = frames * tbytes_per_frame;
|
2012-05-09 12:15:23 +04:00
|
|
|
src = alsa->dsp_context->resampled_buffer;
|
2011-09-21 09:28:02 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
while (frames > 0)
|
|
|
|
{
|
2013-03-21 04:44:31 +04:00
|
|
|
if (WaitForSingleObject(alsa->stopEvent, 0) == WAIT_OBJECT_0)
|
2011-10-19 18:55:54 +04:00
|
|
|
break;
|
|
|
|
|
2011-09-21 09:28:02 +04:00
|
|
|
cframes = alsa->frames_per_packet - alsa->buffer_frames;
|
2013-02-21 06:34:47 +04:00
|
|
|
|
2011-09-21 09:28:02 +04:00
|
|
|
if (cframes > frames)
|
|
|
|
cframes = frames;
|
2013-02-21 06:34:47 +04:00
|
|
|
|
|
|
|
CopyMemory(alsa->buffer + alsa->buffer_frames * tbytes_per_frame, src, cframes * tbytes_per_frame);
|
|
|
|
|
2011-09-21 09:28:02 +04:00
|
|
|
alsa->buffer_frames += cframes;
|
2013-02-21 06:34:47 +04:00
|
|
|
|
2011-09-21 09:28:02 +04:00
|
|
|
if (alsa->buffer_frames >= alsa->frames_per_packet)
|
|
|
|
{
|
2013-02-21 06:34:47 +04:00
|
|
|
if (alsa->wformat == WAVE_FORMAT_DVI_ADPCM)
|
2011-09-21 09:28:02 +04:00
|
|
|
{
|
2012-05-09 12:15:23 +04:00
|
|
|
alsa->dsp_context->encode_ima_adpcm(alsa->dsp_context,
|
2011-09-21 09:28:02 +04:00
|
|
|
alsa->buffer, alsa->buffer_frames * tbytes_per_frame,
|
2012-05-09 12:15:23 +04:00
|
|
|
alsa->target_channels, alsa->block_size);
|
2013-02-21 06:34:47 +04:00
|
|
|
|
2012-05-09 12:15:23 +04:00
|
|
|
encoded_data = alsa->dsp_context->adpcm_buffer;
|
|
|
|
encoded_size = alsa->dsp_context->adpcm_size;
|
2013-02-21 06:34:47 +04:00
|
|
|
|
2011-09-21 09:28:02 +04:00
|
|
|
DEBUG_DVC("encoded %d to %d",
|
|
|
|
alsa->buffer_frames * tbytes_per_frame, encoded_size);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
encoded_data = alsa->buffer;
|
|
|
|
encoded_size = alsa->buffer_frames * tbytes_per_frame;
|
|
|
|
}
|
|
|
|
|
2013-03-21 04:44:31 +04:00
|
|
|
if (WaitForSingleObject(alsa->stopEvent, 0) == WAIT_OBJECT_0)
|
2013-09-05 11:33:12 +04:00
|
|
|
break;
|
2011-10-19 18:55:54 +04:00
|
|
|
else
|
2013-09-27 13:39:04 +04:00
|
|
|
{
|
|
|
|
DEBUG_DVC("encoded %d [%d] to %d [%X]", alsa->buffer_frames,
|
|
|
|
tbytes_per_frame, encoded_size,
|
|
|
|
alsa->wformat);
|
2011-10-19 18:55:54 +04:00
|
|
|
ret = alsa->receive(encoded_data, encoded_size, alsa->user_data);
|
2013-09-27 13:39:04 +04:00
|
|
|
}
|
2013-02-21 06:34:47 +04:00
|
|
|
|
2011-09-21 09:28:02 +04:00
|
|
|
alsa->buffer_frames = 0;
|
2013-02-21 06:34:47 +04:00
|
|
|
|
2011-09-21 09:28:02 +04:00
|
|
|
if (!ret)
|
|
|
|
break;
|
|
|
|
}
|
2013-02-21 06:34:47 +04:00
|
|
|
|
2011-09-21 09:28:02 +04:00
|
|
|
src += cframes * tbytes_per_frame;
|
|
|
|
frames -= cframes;
|
|
|
|
}
|
|
|
|
|
2013-09-05 11:33:12 +04:00
|
|
|
return (ret) ? TRUE : FALSE;
|
2011-09-21 09:28:02 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void* audin_alsa_thread_func(void* arg)
|
|
|
|
{
|
|
|
|
int error;
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE* buffer;
|
2011-09-21 09:28:02 +04:00
|
|
|
int rbytes_per_frame;
|
|
|
|
int tbytes_per_frame;
|
|
|
|
snd_pcm_t* capture_handle = NULL;
|
|
|
|
AudinALSADevice* alsa = (AudinALSADevice*) arg;
|
|
|
|
|
|
|
|
DEBUG_DVC("in");
|
|
|
|
|
|
|
|
rbytes_per_frame = alsa->actual_channels * alsa->bytes_per_channel;
|
|
|
|
tbytes_per_frame = alsa->target_channels * alsa->bytes_per_channel;
|
2012-11-20 08:49:08 +04:00
|
|
|
buffer = (BYTE*) malloc(rbytes_per_frame * alsa->frames_per_packet);
|
|
|
|
ZeroMemory(buffer, rbytes_per_frame * alsa->frames_per_packet);
|
2012-05-09 12:15:23 +04:00
|
|
|
freerdp_dsp_context_reset_adpcm(alsa->dsp_context);
|
2012-11-20 08:49:08 +04:00
|
|
|
|
2011-09-21 09:28:02 +04:00
|
|
|
do
|
|
|
|
{
|
|
|
|
if ((error = snd_pcm_open(&capture_handle, alsa->device_name, SND_PCM_STREAM_CAPTURE, 0)) < 0)
|
|
|
|
{
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_ERR(TAG, "snd_pcm_open (%s)", snd_strerror(error));
|
2011-09-21 09:28:02 +04:00
|
|
|
break;
|
|
|
|
}
|
2013-03-21 04:44:31 +04:00
|
|
|
|
2011-09-21 09:28:02 +04:00
|
|
|
if (!audin_alsa_set_params(alsa, capture_handle))
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-03-21 04:44:31 +04:00
|
|
|
while (!(WaitForSingleObject(alsa->stopEvent, 0) == WAIT_OBJECT_0))
|
2011-09-21 09:28:02 +04:00
|
|
|
{
|
|
|
|
error = snd_pcm_readi(capture_handle, buffer, alsa->frames_per_packet);
|
2013-03-21 04:44:31 +04:00
|
|
|
|
2011-09-21 09:28:02 +04:00
|
|
|
if (error == -EPIPE)
|
|
|
|
{
|
|
|
|
snd_pcm_recover(capture_handle, error, 0);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if (error < 0)
|
|
|
|
{
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_ERR(TAG, "snd_pcm_readi (%s)", snd_strerror(error));
|
2011-09-21 09:28:02 +04:00
|
|
|
break;
|
|
|
|
}
|
2013-03-21 04:44:31 +04:00
|
|
|
|
2011-09-21 09:28:02 +04:00
|
|
|
if (!audin_alsa_thread_receive(alsa, buffer, error * rbytes_per_frame))
|
|
|
|
break;
|
|
|
|
}
|
2013-03-21 04:44:31 +04:00
|
|
|
}
|
|
|
|
while (0);
|
2011-09-21 09:28:02 +04:00
|
|
|
|
2012-10-09 07:21:26 +04:00
|
|
|
free(buffer);
|
2013-02-21 06:34:47 +04:00
|
|
|
|
2011-09-21 09:28:02 +04:00
|
|
|
if (capture_handle)
|
|
|
|
snd_pcm_close(capture_handle);
|
|
|
|
|
|
|
|
DEBUG_DVC("out");
|
2013-09-05 11:33:12 +04:00
|
|
|
ExitThread(0);
|
2011-09-21 09:28:02 +04:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void audin_alsa_free(IAudinDevice* device)
|
|
|
|
{
|
|
|
|
AudinALSADevice* alsa = (AudinALSADevice*) device;
|
|
|
|
|
2012-05-09 12:15:23 +04:00
|
|
|
freerdp_dsp_context_free(alsa->dsp_context);
|
2012-11-20 07:31:15 +04:00
|
|
|
|
|
|
|
free(alsa->device_name);
|
|
|
|
|
2012-10-09 07:21:26 +04:00
|
|
|
free(alsa);
|
2011-09-21 09:28:02 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 10:38:39 +04:00
|
|
|
static BOOL audin_alsa_format_supported(IAudinDevice* device, audinFormat* format)
|
2011-09-21 09:28:02 +04:00
|
|
|
{
|
|
|
|
switch (format->wFormatTag)
|
|
|
|
{
|
2013-02-21 06:34:47 +04:00
|
|
|
case WAVE_FORMAT_PCM:
|
2011-09-21 09:28:02 +04:00
|
|
|
if (format->cbSize == 0 &&
|
|
|
|
(format->nSamplesPerSec <= 48000) &&
|
|
|
|
(format->wBitsPerSample == 8 || format->wBitsPerSample == 16) &&
|
|
|
|
(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;
|
|
|
|
|
2013-02-21 06:34:47 +04:00
|
|
|
case WAVE_FORMAT_DVI_ADPCM:
|
2011-09-21 09:28:02 +04:00
|
|
|
if ((format->nSamplesPerSec <= 48000) &&
|
|
|
|
(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;
|
|
|
|
}
|
2013-02-21 06:34:47 +04:00
|
|
|
|
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_alsa_set_format(IAudinDevice* device, audinFormat* format, UINT32 FramesPerPacket)
|
2011-09-21 09:28:02 +04:00
|
|
|
{
|
|
|
|
int bs;
|
|
|
|
AudinALSADevice* alsa = (AudinALSADevice*) device;
|
|
|
|
|
|
|
|
alsa->target_rate = format->nSamplesPerSec;
|
|
|
|
alsa->actual_rate = format->nSamplesPerSec;
|
|
|
|
alsa->target_channels = format->nChannels;
|
|
|
|
alsa->actual_channels = format->nChannels;
|
2013-02-21 06:34:47 +04:00
|
|
|
|
2011-09-21 09:28:02 +04:00
|
|
|
switch (format->wFormatTag)
|
|
|
|
{
|
2013-02-21 06:34:47 +04:00
|
|
|
case WAVE_FORMAT_PCM:
|
2011-09-21 09:28:02 +04:00
|
|
|
switch (format->wBitsPerSample)
|
|
|
|
{
|
|
|
|
case 8:
|
|
|
|
alsa->format = SND_PCM_FORMAT_S8;
|
|
|
|
alsa->bytes_per_channel = 1;
|
|
|
|
break;
|
|
|
|
case 16:
|
|
|
|
alsa->format = SND_PCM_FORMAT_S16_LE;
|
|
|
|
alsa->bytes_per_channel = 2;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2013-02-21 06:34:47 +04:00
|
|
|
case WAVE_FORMAT_DVI_ADPCM:
|
2011-09-21 09:28:02 +04:00
|
|
|
alsa->format = SND_PCM_FORMAT_S16_LE;
|
|
|
|
alsa->bytes_per_channel = 2;
|
|
|
|
bs = (format->nBlockAlign - 4 * format->nChannels) * 4;
|
|
|
|
alsa->frames_per_packet = (alsa->frames_per_packet * format->nChannels * 2 /
|
|
|
|
bs + 1) * bs / (format->nChannels * 2);
|
|
|
|
DEBUG_DVC("aligned FramesPerPacket=%d",
|
|
|
|
alsa->frames_per_packet);
|
|
|
|
break;
|
|
|
|
}
|
2013-02-21 06:34:47 +04:00
|
|
|
|
2011-09-21 09:28:02 +04:00
|
|
|
alsa->wformat = format->wFormatTag;
|
|
|
|
alsa->block_size = format->nBlockAlign;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void audin_alsa_open(IAudinDevice* device, AudinReceive receive, void* user_data)
|
|
|
|
{
|
2013-09-05 11:33:12 +04:00
|
|
|
int rbytes_per_frame;
|
|
|
|
int tbytes_per_frame;
|
2011-09-21 09:28:02 +04:00
|
|
|
AudinALSADevice* alsa = (AudinALSADevice*) device;
|
|
|
|
|
|
|
|
DEBUG_DVC("");
|
|
|
|
|
|
|
|
alsa->receive = receive;
|
|
|
|
alsa->user_data = user_data;
|
|
|
|
|
2013-09-05 11:33:12 +04:00
|
|
|
rbytes_per_frame = alsa->actual_channels * alsa->bytes_per_channel;
|
|
|
|
tbytes_per_frame = alsa->target_channels * alsa->bytes_per_channel;
|
|
|
|
alsa->buffer = (BYTE*) malloc(tbytes_per_frame * alsa->frames_per_packet);
|
|
|
|
ZeroMemory(alsa->buffer, tbytes_per_frame * alsa->frames_per_packet);
|
|
|
|
alsa->buffer_frames = 0;
|
2013-09-05 15:41:32 +04:00
|
|
|
|
|
|
|
alsa->stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
|
|
|
|
alsa->thread = CreateThread(NULL, 0,
|
|
|
|
(LPTHREAD_START_ROUTINE) audin_alsa_thread_func, alsa, 0, NULL);
|
2011-09-21 09:28:02 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void audin_alsa_close(IAudinDevice* device)
|
|
|
|
{
|
|
|
|
AudinALSADevice* alsa = (AudinALSADevice*) device;
|
|
|
|
|
|
|
|
DEBUG_DVC("");
|
|
|
|
|
2014-12-27 21:50:50 +03:00
|
|
|
if (alsa->stopEvent)
|
|
|
|
{
|
|
|
|
SetEvent(alsa->stopEvent);
|
|
|
|
WaitForSingleObject(alsa->thread, INFINITE);
|
|
|
|
|
|
|
|
CloseHandle(alsa->stopEvent);
|
|
|
|
alsa->stopEvent = NULL;
|
|
|
|
|
|
|
|
CloseHandle(alsa->thread);
|
|
|
|
alsa->thread = NULL;
|
|
|
|
}
|
2013-09-05 11:33:12 +04:00
|
|
|
|
|
|
|
if (alsa->buffer)
|
|
|
|
free(alsa->buffer);
|
|
|
|
alsa->buffer = NULL;
|
2011-09-21 09:28:02 +04:00
|
|
|
|
|
|
|
alsa->receive = NULL;
|
|
|
|
alsa->user_data = NULL;
|
|
|
|
}
|
|
|
|
|
2012-11-20 07:31:15 +04:00
|
|
|
COMMAND_LINE_ARGUMENT_A audin_alsa_args[] =
|
|
|
|
{
|
2015-03-13 01:28:44 +03:00
|
|
|
{ "dev", COMMAND_LINE_VALUE_REQUIRED, "<device>", NULL, NULL, -1, NULL, "audio device name" },
|
2012-11-20 07:31:15 +04:00
|
|
|
{ NULL, 0, NULL, NULL, NULL, -1, NULL, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
static void audin_alsa_parse_addin_args(AudinALSADevice* device, ADDIN_ARGV* args)
|
|
|
|
{
|
|
|
|
int status;
|
|
|
|
DWORD flags;
|
|
|
|
COMMAND_LINE_ARGUMENT_A* arg;
|
|
|
|
AudinALSADevice* alsa = (AudinALSADevice*) device;
|
|
|
|
|
2015-03-13 01:28:44 +03:00
|
|
|
flags = COMMAND_LINE_SIGIL_NONE | COMMAND_LINE_SEPARATOR_COLON | COMMAND_LINE_IGN_UNKNOWN_KEYWORD;
|
2012-11-20 07:31:15 +04:00
|
|
|
|
|
|
|
status = CommandLineParseArgumentsA(args->argc, (const char**) args->argv, audin_alsa_args, flags, alsa, NULL, NULL);
|
|
|
|
|
|
|
|
arg = audin_alsa_args;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (!(arg->Flags & COMMAND_LINE_VALUE_PRESENT))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
CommandLineSwitchStart(arg)
|
|
|
|
|
2015-03-13 01:28:44 +03:00
|
|
|
CommandLineSwitchCase(arg, "dev")
|
2012-11-20 07:31:15 +04:00
|
|
|
{
|
|
|
|
alsa->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 alsa_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
|
|
|
AudinALSADevice* alsa;
|
|
|
|
|
2012-11-20 07:31:15 +04:00
|
|
|
alsa = (AudinALSADevice*) malloc(sizeof(AudinALSADevice));
|
|
|
|
ZeroMemory(alsa, sizeof(AudinALSADevice));
|
2011-09-21 09:28:02 +04:00
|
|
|
|
|
|
|
alsa->iface.Open = audin_alsa_open;
|
|
|
|
alsa->iface.FormatSupported = audin_alsa_format_supported;
|
|
|
|
alsa->iface.SetFormat = audin_alsa_set_format;
|
|
|
|
alsa->iface.Close = audin_alsa_close;
|
|
|
|
alsa->iface.Free = audin_alsa_free;
|
|
|
|
|
2012-11-20 07:31:15 +04:00
|
|
|
args = pEntryPoints->args;
|
2012-04-18 21:16:50 +04:00
|
|
|
|
2012-11-20 07:31:15 +04:00
|
|
|
audin_alsa_parse_addin_args(alsa, args);
|
|
|
|
|
|
|
|
if (!alsa->device_name)
|
|
|
|
alsa->device_name = _strdup("default");
|
2011-09-21 09:28:02 +04:00
|
|
|
|
|
|
|
alsa->frames_per_packet = 128;
|
|
|
|
alsa->target_rate = 22050;
|
|
|
|
alsa->actual_rate = 22050;
|
|
|
|
alsa->format = SND_PCM_FORMAT_S16_LE;
|
|
|
|
alsa->target_channels = 2;
|
|
|
|
alsa->actual_channels = 2;
|
|
|
|
alsa->bytes_per_channel = 2;
|
|
|
|
|
2012-05-09 12:15:23 +04:00
|
|
|
alsa->dsp_context = freerdp_dsp_context_new();
|
|
|
|
|
2011-09-21 09:28:02 +04:00
|
|
|
pEntryPoints->pRegisterAudinDevice(pEntryPoints->plugin, (IAudinDevice*) alsa);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|