2011-09-21 09:28:02 +04:00
|
|
|
/**
|
2012-10-09 07:02:04 +04:00
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
2012-01-16 18:20:54 +04:00
|
|
|
* Audio Input Redirection Virtual Channel
|
2011-09-21 09:28:02 +04:00
|
|
|
*
|
|
|
|
* Copyright 2010-2011 Vic Lee
|
2015-06-02 10:50:38 +03:00
|
|
|
* Copyright 2015 Thincast Technologies GmbH
|
|
|
|
* Copyright 2015 DI (FH) Martin Haimberger <martin.haimberger@thincast.com>
|
2011-09-21 09:28:02 +04:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
|
2013-09-26 18:05:16 +04:00
|
|
|
#include <assert.h>
|
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>
|
|
|
|
|
2012-11-18 09:08:03 +04:00
|
|
|
#include <freerdp/addin.h>
|
|
|
|
|
2013-03-22 00:45:25 +04:00
|
|
|
#include <winpr/stream.h>
|
2015-07-15 10:50:35 +03:00
|
|
|
#include <freerdp/freerdp.h>
|
2011-09-21 09:28:02 +04:00
|
|
|
#include "audin_main.h"
|
|
|
|
|
|
|
|
#define MSG_SNDIN_VERSION 0x01
|
|
|
|
#define MSG_SNDIN_FORMATS 0x02
|
|
|
|
#define MSG_SNDIN_OPEN 0x03
|
|
|
|
#define MSG_SNDIN_OPEN_REPLY 0x04
|
|
|
|
#define MSG_SNDIN_DATA_INCOMING 0x05
|
|
|
|
#define MSG_SNDIN_DATA 0x06
|
|
|
|
#define MSG_SNDIN_FORMATCHANGE 0x07
|
|
|
|
|
|
|
|
typedef struct _AUDIN_LISTENER_CALLBACK AUDIN_LISTENER_CALLBACK;
|
|
|
|
struct _AUDIN_LISTENER_CALLBACK
|
|
|
|
{
|
|
|
|
IWTSListenerCallback iface;
|
|
|
|
|
|
|
|
IWTSPlugin* plugin;
|
|
|
|
IWTSVirtualChannelManager* channel_mgr;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct _AUDIN_CHANNEL_CALLBACK AUDIN_CHANNEL_CALLBACK;
|
|
|
|
struct _AUDIN_CHANNEL_CALLBACK
|
|
|
|
{
|
|
|
|
IWTSVirtualChannelCallback iface;
|
|
|
|
|
|
|
|
IWTSPlugin* plugin;
|
|
|
|
IWTSVirtualChannelManager* channel_mgr;
|
|
|
|
IWTSVirtualChannel* channel;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The supported format list sent back to the server, which needs to
|
|
|
|
* be stored as reference when the server sends the format index in
|
|
|
|
* Open PDU and Format Change PDU
|
|
|
|
*/
|
|
|
|
audinFormat* formats;
|
|
|
|
int formats_count;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct _AUDIN_PLUGIN AUDIN_PLUGIN;
|
|
|
|
struct _AUDIN_PLUGIN
|
|
|
|
{
|
|
|
|
IWTSPlugin iface;
|
|
|
|
|
|
|
|
AUDIN_LISTENER_CALLBACK* listener_callback;
|
|
|
|
|
|
|
|
/* Parsed plugin data */
|
2012-10-09 11:01:37 +04:00
|
|
|
UINT16 fixed_format;
|
|
|
|
UINT16 fixed_channel;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 fixed_rate;
|
2012-11-20 07:31:15 +04:00
|
|
|
char* subsystem;
|
|
|
|
char* device_name;
|
2011-09-21 09:28:02 +04:00
|
|
|
|
|
|
|
/* Device interface */
|
|
|
|
IAudinDevice* device;
|
2015-07-15 10:50:35 +03:00
|
|
|
|
|
|
|
rdpContext* rdpcontext;
|
2011-09-21 09:28:02 +04:00
|
|
|
};
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
static UINT audin_process_version(IWTSVirtualChannelCallback* pChannelCallback, wStream* s)
|
2011-09-21 09:28:02 +04:00
|
|
|
{
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT error;
|
2013-03-21 23:19:33 +04:00
|
|
|
wStream* out;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 Version;
|
2011-09-21 09:28:02 +04:00
|
|
|
AUDIN_CHANNEL_CALLBACK* callback = (AUDIN_CHANNEL_CALLBACK*) pChannelCallback;
|
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT32(s, Version);
|
2011-09-21 09:28:02 +04:00
|
|
|
|
2015-03-19 02:41:29 +03:00
|
|
|
DEBUG_DVC("Version=%d", Version);
|
2011-09-21 09:28:02 +04:00
|
|
|
|
2013-05-09 01:48:30 +04:00
|
|
|
out = Stream_New(NULL, 5);
|
2015-06-02 10:50:38 +03:00
|
|
|
|
|
|
|
if (!out)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Stream_New failed!");
|
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT8(out, MSG_SNDIN_VERSION);
|
|
|
|
Stream_Write_UINT32(out, Version);
|
2014-10-24 04:40:45 +04:00
|
|
|
error = callback->channel->Write(callback->channel, (UINT32) Stream_GetPosition(out), Stream_Buffer(out), NULL);
|
2013-05-09 01:48:30 +04:00
|
|
|
Stream_Free(out, TRUE);
|
2011-09-21 09:28:02 +04:00
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
static UINT audin_send_incoming_data_pdu(IWTSVirtualChannelCallback* pChannelCallback)
|
2011-09-21 09:28:02 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE out_data[1];
|
2011-09-21 09:28:02 +04:00
|
|
|
AUDIN_CHANNEL_CALLBACK* callback = (AUDIN_CHANNEL_CALLBACK*) pChannelCallback;
|
|
|
|
|
|
|
|
out_data[0] = MSG_SNDIN_DATA_INCOMING;
|
|
|
|
return callback->channel->Write(callback->channel, 1, out_data, NULL);
|
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
static UINT audin_process_formats(IWTSVirtualChannelCallback* pChannelCallback, wStream* s)
|
2011-09-21 09:28:02 +04:00
|
|
|
{
|
|
|
|
AUDIN_CHANNEL_CALLBACK* callback = (AUDIN_CHANNEL_CALLBACK*) pChannelCallback;
|
|
|
|
AUDIN_PLUGIN* audin = (AUDIN_PLUGIN*) callback->plugin;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 i;
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE* fm;
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT error;
|
2013-03-21 23:19:33 +04:00
|
|
|
wStream* out;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 NumFormats;
|
2011-09-21 09:28:02 +04:00
|
|
|
audinFormat format;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 cbSizeFormatsPacket;
|
2011-09-21 09:28:02 +04:00
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT32(s, NumFormats);
|
2015-03-19 02:41:29 +03:00
|
|
|
DEBUG_DVC("NumFormats %d", NumFormats);
|
2011-09-21 09:28:02 +04:00
|
|
|
if ((NumFormats < 1) || (NumFormats > 1000))
|
|
|
|
{
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_ERR(TAG, "bad NumFormats %d", NumFormats);
|
2015-06-02 10:50:38 +03:00
|
|
|
return ERROR_INVALID_DATA;
|
2011-09-21 09:28:02 +04:00
|
|
|
}
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_Seek_UINT32(s); /* cbSizeFormatsPacket */
|
2011-09-21 09:28:02 +04:00
|
|
|
|
2015-06-02 10:50:38 +03:00
|
|
|
callback->formats = (audinFormat*) calloc(1, NumFormats * sizeof(audinFormat));
|
|
|
|
if (!callback->formats)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "calloc failed!");
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2011-09-21 09:28:02 +04:00
|
|
|
|
2013-05-09 01:48:30 +04:00
|
|
|
out = Stream_New(NULL, 9);
|
2015-06-02 10:50:38 +03:00
|
|
|
|
|
|
|
if (!out)
|
|
|
|
{
|
|
|
|
error = CHANNEL_RC_NO_MEMORY;
|
|
|
|
WLog_ERR(TAG, "Stream_New failed!");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_Seek(out, 9);
|
2011-09-21 09:28:02 +04:00
|
|
|
|
|
|
|
/* SoundFormats (variable) */
|
|
|
|
for (i = 0; i < NumFormats; i++)
|
|
|
|
{
|
2013-05-09 00:27:21 +04:00
|
|
|
Stream_GetPointer(s, fm);
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT16(s, format.wFormatTag);
|
|
|
|
Stream_Read_UINT16(s, format.nChannels);
|
|
|
|
Stream_Read_UINT32(s, format.nSamplesPerSec);
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_Seek_UINT32(s); /* nAvgBytesPerSec */
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT16(s, format.nBlockAlign);
|
|
|
|
Stream_Read_UINT16(s, format.wBitsPerSample);
|
|
|
|
Stream_Read_UINT16(s, format.cbSize);
|
2013-04-30 06:35:15 +04:00
|
|
|
format.data = Stream_Pointer(s);
|
|
|
|
Stream_Seek(s, format.cbSize);
|
2011-09-21 09:28:02 +04:00
|
|
|
|
2015-03-19 02:41:29 +03:00
|
|
|
DEBUG_DVC("wFormatTag=%d nChannels=%d nSamplesPerSec=%d "
|
2011-09-21 09:28:02 +04:00
|
|
|
"nBlockAlign=%d wBitsPerSample=%d cbSize=%d",
|
|
|
|
format.wFormatTag, format.nChannels, format.nSamplesPerSec,
|
|
|
|
format.nBlockAlign, format.wBitsPerSample, format.cbSize);
|
|
|
|
|
|
|
|
if (audin->fixed_format > 0 && audin->fixed_format != format.wFormatTag)
|
|
|
|
continue;
|
|
|
|
if (audin->fixed_channel > 0 && audin->fixed_channel != format.nChannels)
|
|
|
|
continue;
|
|
|
|
if (audin->fixed_rate > 0 && audin->fixed_rate != format.nSamplesPerSec)
|
|
|
|
continue;
|
|
|
|
if (audin->device && audin->device->FormatSupported(audin->device, &format))
|
|
|
|
{
|
2015-03-19 02:41:29 +03:00
|
|
|
DEBUG_DVC("format ok");
|
2011-09-21 09:28:02 +04:00
|
|
|
|
|
|
|
/* Store the agreed format in the corresponding index */
|
|
|
|
callback->formats[callback->formats_count++] = format;
|
|
|
|
/* Put the format to output buffer */
|
2015-03-30 18:15:45 +03:00
|
|
|
if (!Stream_EnsureRemainingCapacity(out, 18 + format.cbSize))
|
2015-03-26 19:09:47 +03:00
|
|
|
{
|
2015-06-02 10:50:38 +03:00
|
|
|
error = CHANNEL_RC_NO_MEMORY;
|
|
|
|
WLog_ERR(TAG, "Stream_EnsureRemainingCapacity failed!");
|
|
|
|
goto out;
|
2015-03-26 19:09:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write(out, fm, 18 + format.cbSize);
|
2011-09-21 09:28:02 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-02 10:50:38 +03:00
|
|
|
if ((error = audin_send_incoming_data_pdu(pChannelCallback)))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "audin_send_incoming_data_pdu failed!");
|
|
|
|
goto out;
|
|
|
|
}
|
2011-09-21 09:28:02 +04:00
|
|
|
|
2014-02-10 10:06:11 +04:00
|
|
|
cbSizeFormatsPacket = (UINT32) Stream_GetPosition(out);
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_SetPosition(out, 0);
|
2011-09-21 09:28:02 +04:00
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT8(out, MSG_SNDIN_FORMATS); /* Header (1 byte) */
|
|
|
|
Stream_Write_UINT32(out, callback->formats_count); /* NumFormats (4 bytes) */
|
|
|
|
Stream_Write_UINT32(out, cbSizeFormatsPacket); /* cbSizeFormatsPacket (4 bytes) */
|
2011-09-21 09:28:02 +04:00
|
|
|
|
2013-05-09 00:27:21 +04:00
|
|
|
error = callback->channel->Write(callback->channel, cbSizeFormatsPacket, Stream_Buffer(out), NULL);
|
2015-06-02 10:50:38 +03:00
|
|
|
out:
|
|
|
|
if (error != CHANNEL_RC_OK)
|
|
|
|
{
|
|
|
|
free(callback->formats);
|
|
|
|
callback->formats = NULL;
|
|
|
|
}
|
2013-05-09 01:48:30 +04:00
|
|
|
Stream_Free(out, TRUE);
|
2011-09-21 09:28:02 +04:00
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
static UINT audin_send_format_change_pdu(IWTSVirtualChannelCallback* pChannelCallback, UINT32 NewFormat)
|
2011-09-21 09:28:02 +04:00
|
|
|
{
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT error;
|
2013-03-21 23:19:33 +04:00
|
|
|
wStream* out;
|
2011-09-21 09:28:02 +04:00
|
|
|
AUDIN_CHANNEL_CALLBACK* callback = (AUDIN_CHANNEL_CALLBACK*) pChannelCallback;
|
|
|
|
|
2013-05-09 01:48:30 +04:00
|
|
|
out = Stream_New(NULL, 5);
|
2015-06-02 10:50:38 +03:00
|
|
|
|
|
|
|
if (!out)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Stream_New failed!");
|
|
|
|
return CHANNEL_RC_OK;
|
|
|
|
}
|
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT8(out, MSG_SNDIN_FORMATCHANGE);
|
|
|
|
Stream_Write_UINT32(out, NewFormat);
|
2013-05-09 00:27:21 +04:00
|
|
|
error = callback->channel->Write(callback->channel, 5, Stream_Buffer(out), NULL);
|
2013-05-09 01:48:30 +04:00
|
|
|
Stream_Free(out, TRUE);
|
2011-09-21 09:28:02 +04:00
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
static UINT audin_send_open_reply_pdu(IWTSVirtualChannelCallback* pChannelCallback, UINT32 Result)
|
2011-09-21 09:28:02 +04:00
|
|
|
{
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT error;
|
2013-03-21 23:19:33 +04:00
|
|
|
wStream* out;
|
2011-09-21 09:28:02 +04:00
|
|
|
AUDIN_CHANNEL_CALLBACK* callback = (AUDIN_CHANNEL_CALLBACK*) pChannelCallback;
|
|
|
|
|
2013-05-09 01:48:30 +04:00
|
|
|
out = Stream_New(NULL, 5);
|
2015-06-02 10:50:38 +03:00
|
|
|
|
|
|
|
if (!out)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Stream_New failed!");
|
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
|
|
|
}
|
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT8(out, MSG_SNDIN_OPEN_REPLY);
|
|
|
|
Stream_Write_UINT32(out, Result);
|
2013-05-09 00:27:21 +04:00
|
|
|
error = callback->channel->Write(callback->channel, 5, Stream_Buffer(out), NULL);
|
2013-05-09 01:48:30 +04:00
|
|
|
Stream_Free(out, TRUE);
|
2011-09-21 09:28:02 +04:00
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
static UINT audin_receive_wave_data(BYTE* data, int size, void* user_data)
|
2011-09-21 09:28:02 +04:00
|
|
|
{
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT error;
|
2013-03-21 23:19:33 +04:00
|
|
|
wStream* out;
|
2011-09-21 09:28:02 +04:00
|
|
|
AUDIN_CHANNEL_CALLBACK* callback = (AUDIN_CHANNEL_CALLBACK*) user_data;
|
|
|
|
|
2015-06-02 10:50:38 +03:00
|
|
|
if ((error = audin_send_incoming_data_pdu((IWTSVirtualChannelCallback*) callback)))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "audin_send_incoming_data_pdu failed!");
|
|
|
|
return error;
|
|
|
|
}
|
2011-09-21 09:28:02 +04:00
|
|
|
|
2013-05-09 01:48:30 +04:00
|
|
|
out = Stream_New(NULL, size + 1);
|
2015-06-02 10:50:38 +03:00
|
|
|
|
|
|
|
if (!out)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Stream_New failed!");
|
|
|
|
return ERROR_NOT_ENOUGH_MEMORY;
|
|
|
|
}
|
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT8(out, MSG_SNDIN_DATA);
|
|
|
|
Stream_Write(out, data, size);
|
2014-02-10 10:06:11 +04:00
|
|
|
error = callback->channel->Write(callback->channel, (UINT32) Stream_GetPosition(out), Stream_Buffer(out), NULL);
|
2013-05-09 01:48:30 +04:00
|
|
|
Stream_Free(out, TRUE);
|
2011-09-21 09:28:02 +04:00
|
|
|
|
2015-06-02 10:50:38 +03:00
|
|
|
return error;
|
2011-09-21 09:28:02 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
static UINT audin_process_open(IWTSVirtualChannelCallback* pChannelCallback, wStream* s)
|
2011-09-21 09:28:02 +04:00
|
|
|
{
|
|
|
|
AUDIN_CHANNEL_CALLBACK* callback = (AUDIN_CHANNEL_CALLBACK*) pChannelCallback;
|
|
|
|
AUDIN_PLUGIN* audin = (AUDIN_PLUGIN*) callback->plugin;
|
|
|
|
audinFormat* format;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 initialFormat;
|
|
|
|
UINT32 FramesPerPacket;
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT error = CHANNEL_RC_OK;
|
2011-09-21 09:28:02 +04:00
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT32(s, FramesPerPacket);
|
|
|
|
Stream_Read_UINT32(s, initialFormat);
|
2011-09-21 09:28:02 +04:00
|
|
|
|
2015-03-19 02:41:29 +03:00
|
|
|
DEBUG_DVC("FramesPerPacket=%d initialFormat=%d",
|
2011-09-21 09:28:02 +04:00
|
|
|
FramesPerPacket, initialFormat);
|
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
if (initialFormat >= (UINT32) callback->formats_count)
|
2011-09-21 09:28:02 +04:00
|
|
|
{
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_ERR(TAG, "invalid format index %d (total %d)",
|
|
|
|
initialFormat, callback->formats_count);
|
2015-06-02 10:50:38 +03:00
|
|
|
return ERROR_INVALID_DATA;
|
2011-09-21 09:28:02 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
format = &callback->formats[initialFormat];
|
|
|
|
if (audin->device)
|
|
|
|
{
|
2015-06-02 10:50:38 +03:00
|
|
|
IFCALLRET(audin->device->SetFormat, error, audin->device, format, FramesPerPacket);
|
|
|
|
if (error != CHANNEL_RC_OK)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "SetFormat failed with errorcode %lu", error);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
IFCALLRET(audin->device->Open, error, audin->device, audin_receive_wave_data, callback);
|
|
|
|
if (error != CHANNEL_RC_OK)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Open failed with errorcode %lu", error);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((error = audin_send_format_change_pdu(pChannelCallback, initialFormat)))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "audin_send_format_change_pdu failed!");
|
|
|
|
return error;
|
2011-09-21 09:28:02 +04:00
|
|
|
}
|
|
|
|
|
2015-06-02 10:50:38 +03:00
|
|
|
if ((error = audin_send_open_reply_pdu(pChannelCallback, 0)))
|
|
|
|
WLog_ERR(TAG, "audin_send_open_reply_pdu failed!");
|
2011-09-21 09:28:02 +04:00
|
|
|
|
2015-06-02 10:50:38 +03:00
|
|
|
return error;
|
2011-09-21 09:28:02 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
static UINT audin_process_format_change(IWTSVirtualChannelCallback* pChannelCallback, wStream* s)
|
2011-09-21 09:28:02 +04:00
|
|
|
{
|
|
|
|
AUDIN_CHANNEL_CALLBACK* callback = (AUDIN_CHANNEL_CALLBACK*) pChannelCallback;
|
2012-02-10 04:48:52 +04:00
|
|
|
AUDIN_PLUGIN * audin = (AUDIN_PLUGIN*) callback->plugin;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 NewFormat;
|
2011-09-21 09:28:02 +04:00
|
|
|
audinFormat* format;
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT error = CHANNEL_RC_OK;
|
2011-09-21 09:28:02 +04:00
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT32(s, NewFormat);
|
2011-09-21 09:28:02 +04:00
|
|
|
|
2015-03-19 02:41:29 +03:00
|
|
|
DEBUG_DVC("NewFormat=%d", NewFormat);
|
2011-09-21 09:28:02 +04:00
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
if (NewFormat >= (UINT32) callback->formats_count)
|
2011-09-21 09:28:02 +04:00
|
|
|
{
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_ERR(TAG, "invalid format index %d (total %d)",
|
|
|
|
NewFormat, callback->formats_count);
|
2015-06-02 10:50:38 +03:00
|
|
|
return ERROR_INVALID_DATA;
|
2011-09-21 09:28:02 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
format = &callback->formats[NewFormat];
|
|
|
|
|
|
|
|
if (audin->device)
|
|
|
|
{
|
2015-06-02 10:50:38 +03:00
|
|
|
IFCALLRET(audin->device->Close, error, audin->device);
|
|
|
|
if (error != CHANNEL_RC_OK)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Close failed with errorcode %lu", error);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
IFCALLRET(audin->device->SetFormat, error, audin->device, format, 0);
|
|
|
|
if (error != CHANNEL_RC_OK)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "SetFormat failed with errorcode %lu", error);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
IFCALLRET(audin->device->Open, error, audin->device, audin_receive_wave_data, callback);
|
|
|
|
if (error != CHANNEL_RC_OK)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Open failed with errorcode %lu", error);
|
|
|
|
return error;
|
|
|
|
}
|
2011-09-21 09:28:02 +04:00
|
|
|
}
|
|
|
|
|
2015-06-02 10:50:38 +03:00
|
|
|
if ((error = audin_send_format_change_pdu(pChannelCallback, NewFormat)))
|
|
|
|
WLog_ERR(TAG, "audin_send_format_change_pdu failed!");
|
2011-09-21 09:28:02 +04:00
|
|
|
|
2015-06-02 10:50:38 +03:00
|
|
|
return error;
|
2011-09-21 09:28:02 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
static UINT audin_on_data_received(IWTSVirtualChannelCallback* pChannelCallback, wStream *data)
|
2011-09-21 09:28:02 +04:00
|
|
|
{
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT error;
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE MessageId;
|
2011-09-21 09:28:02 +04:00
|
|
|
|
2014-06-11 16:42:32 +04:00
|
|
|
Stream_Read_UINT8(data, MessageId);
|
2011-09-21 09:28:02 +04:00
|
|
|
|
2015-03-19 02:41:29 +03:00
|
|
|
DEBUG_DVC("MessageId=0x%x", MessageId);
|
2011-09-21 09:28:02 +04:00
|
|
|
|
|
|
|
switch (MessageId)
|
|
|
|
{
|
|
|
|
case MSG_SNDIN_VERSION:
|
2014-06-11 16:42:32 +04:00
|
|
|
error = audin_process_version(pChannelCallback, data);
|
2011-09-21 09:28:02 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MSG_SNDIN_FORMATS:
|
2014-06-11 16:42:32 +04:00
|
|
|
error = audin_process_formats(pChannelCallback, data);
|
2011-09-21 09:28:02 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MSG_SNDIN_OPEN:
|
2014-06-11 16:42:32 +04:00
|
|
|
error = audin_process_open(pChannelCallback, data);
|
2011-09-21 09:28:02 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MSG_SNDIN_FORMATCHANGE:
|
2014-06-11 16:42:32 +04:00
|
|
|
error = audin_process_format_change(pChannelCallback, data);
|
2011-09-21 09:28:02 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_ERR(TAG, "unknown MessageId=0x%x", MessageId);
|
2015-06-02 10:50:38 +03:00
|
|
|
error = ERROR_INVALID_DATA;
|
2011-09-21 09:28:02 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
static UINT audin_on_close(IWTSVirtualChannelCallback* pChannelCallback)
|
2011-09-21 09:28:02 +04:00
|
|
|
{
|
|
|
|
AUDIN_CHANNEL_CALLBACK* callback = (AUDIN_CHANNEL_CALLBACK*) pChannelCallback;
|
|
|
|
AUDIN_PLUGIN* audin = (AUDIN_PLUGIN*) callback->plugin;
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT error = CHANNEL_RC_OK;
|
2011-09-21 09:28:02 +04:00
|
|
|
|
2015-03-19 02:41:29 +03:00
|
|
|
DEBUG_DVC("...");
|
2011-09-21 09:28:02 +04:00
|
|
|
|
|
|
|
if (audin->device)
|
2015-06-02 10:50:38 +03:00
|
|
|
{
|
|
|
|
IFCALLRET(audin->device->Close, error, audin->device);
|
|
|
|
if (error != CHANNEL_RC_OK)
|
|
|
|
WLog_ERR(TAG, "Close failed with errorcode %lu", error);
|
|
|
|
}
|
2011-09-21 09:28:02 +04:00
|
|
|
|
2012-10-09 07:21:26 +04:00
|
|
|
free(callback->formats);
|
|
|
|
free(callback);
|
2011-09-21 09:28:02 +04:00
|
|
|
|
2015-06-02 10:50:38 +03:00
|
|
|
return error;
|
2011-09-21 09:28:02 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
static UINT audin_on_new_channel_connection(IWTSListenerCallback* pListenerCallback,
|
2012-10-09 11:01:37 +04:00
|
|
|
IWTSVirtualChannel* pChannel, BYTE* Data, int* pbAccept,
|
2011-09-21 09:28:02 +04:00
|
|
|
IWTSVirtualChannelCallback** ppCallback)
|
|
|
|
{
|
|
|
|
AUDIN_CHANNEL_CALLBACK* callback;
|
|
|
|
AUDIN_LISTENER_CALLBACK* listener_callback = (AUDIN_LISTENER_CALLBACK*) pListenerCallback;
|
|
|
|
|
2015-03-19 02:41:29 +03:00
|
|
|
DEBUG_DVC("...");
|
2011-09-21 09:28:02 +04:00
|
|
|
|
2015-06-02 10:50:38 +03:00
|
|
|
callback = (AUDIN_CHANNEL_CALLBACK*) calloc(1, sizeof(AUDIN_CHANNEL_CALLBACK));
|
|
|
|
if (!callback)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "calloc failed!");
|
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
|
|
|
}
|
2011-09-21 09:28:02 +04:00
|
|
|
|
|
|
|
callback->iface.OnDataReceived = audin_on_data_received;
|
|
|
|
callback->iface.OnClose = audin_on_close;
|
|
|
|
callback->plugin = listener_callback->plugin;
|
|
|
|
callback->channel_mgr = listener_callback->channel_mgr;
|
|
|
|
callback->channel = pChannel;
|
|
|
|
|
|
|
|
*ppCallback = (IWTSVirtualChannelCallback*) callback;
|
|
|
|
|
2015-06-02 10:50:38 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2011-09-21 09:28:02 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
static UINT audin_plugin_initialize(IWTSPlugin* pPlugin, IWTSVirtualChannelManager* pChannelMgr)
|
2011-09-21 09:28:02 +04:00
|
|
|
{
|
|
|
|
AUDIN_PLUGIN* audin = (AUDIN_PLUGIN*) pPlugin;
|
|
|
|
|
2015-03-19 02:41:29 +03:00
|
|
|
DEBUG_DVC("...");
|
2011-09-21 09:28:02 +04:00
|
|
|
|
2015-06-02 10:50:38 +03:00
|
|
|
audin->listener_callback = (AUDIN_LISTENER_CALLBACK*) calloc(1, sizeof(AUDIN_LISTENER_CALLBACK));
|
|
|
|
if (!audin->listener_callback)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "calloc failed!");
|
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
|
|
|
}
|
2011-09-21 09:28:02 +04:00
|
|
|
|
|
|
|
audin->listener_callback->iface.OnNewChannelConnection = audin_on_new_channel_connection;
|
|
|
|
audin->listener_callback->plugin = pPlugin;
|
|
|
|
audin->listener_callback->channel_mgr = pChannelMgr;
|
2012-02-10 04:48:52 +04:00
|
|
|
|
2011-09-21 09:28:02 +04:00
|
|
|
return pChannelMgr->CreateListener(pChannelMgr, "AUDIO_INPUT", 0,
|
|
|
|
(IWTSListenerCallback*) audin->listener_callback, NULL);
|
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
static UINT audin_plugin_terminated(IWTSPlugin* pPlugin)
|
2011-09-21 09:28:02 +04:00
|
|
|
{
|
|
|
|
AUDIN_PLUGIN* audin = (AUDIN_PLUGIN*) pPlugin;
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT error = CHANNEL_RC_OK;
|
2011-09-21 09:28:02 +04:00
|
|
|
|
2015-03-19 02:41:29 +03:00
|
|
|
DEBUG_DVC("...");
|
2011-09-21 09:28:02 +04:00
|
|
|
|
|
|
|
if (audin->device)
|
|
|
|
{
|
2015-06-02 10:50:38 +03:00
|
|
|
IFCALLRET(audin->device->Free, error, audin->device);
|
|
|
|
if (error != CHANNEL_RC_OK)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Free failed with errorcode %lu", error);
|
|
|
|
// dont stop on error
|
|
|
|
}
|
2011-09-21 09:28:02 +04:00
|
|
|
audin->device = NULL;
|
|
|
|
}
|
2012-02-10 04:48:52 +04:00
|
|
|
|
2014-12-27 21:50:50 +03:00
|
|
|
free(audin->subsystem);
|
|
|
|
audin->subsystem = NULL;
|
|
|
|
|
|
|
|
free(audin->device_name);
|
|
|
|
audin->device_name = NULL;
|
|
|
|
|
2012-10-09 07:21:26 +04:00
|
|
|
free(audin->listener_callback);
|
|
|
|
free(audin);
|
2011-09-21 09:28:02 +04:00
|
|
|
|
2015-06-02 10:50:38 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2011-09-21 09:28:02 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
static UINT audin_register_device_plugin(IWTSPlugin* pPlugin, IAudinDevice* device)
|
2011-09-21 09:28:02 +04:00
|
|
|
{
|
|
|
|
AUDIN_PLUGIN* audin = (AUDIN_PLUGIN*) pPlugin;
|
|
|
|
|
|
|
|
if (audin->device)
|
|
|
|
{
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_ERR(TAG, "existing device, abort.");
|
2015-06-02 10:50:38 +03:00
|
|
|
return ERROR_ALREADY_EXISTS;
|
2011-09-21 09:28:02 +04:00
|
|
|
}
|
|
|
|
|
2015-03-19 02:41:29 +03:00
|
|
|
DEBUG_DVC("device registered.");
|
2011-09-21 09:28:02 +04:00
|
|
|
|
|
|
|
audin->device = device;
|
2015-06-02 10:50:38 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2011-09-21 09:28:02 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
static UINT audin_load_device_plugin(IWTSPlugin* pPlugin, const char* name, ADDIN_ARGV* args)
|
2011-09-21 09:28:02 +04:00
|
|
|
{
|
|
|
|
PFREERDP_AUDIN_DEVICE_ENTRY entry;
|
|
|
|
FREERDP_AUDIN_DEVICE_ENTRY_POINTS entryPoints;
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT error;
|
2011-09-21 09:28:02 +04:00
|
|
|
|
2012-11-18 09:08:03 +04:00
|
|
|
entry = (PFREERDP_AUDIN_DEVICE_ENTRY) freerdp_load_channel_addin_entry("audin", (LPSTR) name, NULL, 0);
|
2012-02-10 04:48:52 +04:00
|
|
|
|
2011-09-21 09:28:02 +04:00
|
|
|
if (entry == NULL)
|
2015-06-02 10:50:38 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "freerdp_load_channel_addin_entry did not return any function pointers for %s ", name);
|
|
|
|
return ERROR_INVALID_FUNCTION;
|
|
|
|
}
|
2011-09-21 09:28:02 +04:00
|
|
|
|
|
|
|
entryPoints.plugin = pPlugin;
|
|
|
|
entryPoints.pRegisterAudinDevice = audin_register_device_plugin;
|
2012-11-20 07:31:15 +04:00
|
|
|
entryPoints.args = args;
|
2015-07-15 10:50:35 +03:00
|
|
|
entryPoints.rdpcontext = ((AUDIN_PLUGIN*)pPlugin)->rdpcontext;
|
2012-02-10 04:48:52 +04:00
|
|
|
|
2015-06-02 10:50:38 +03:00
|
|
|
if ((error = entry(&entryPoints)))
|
2011-09-21 09:28:02 +04:00
|
|
|
{
|
2015-06-02 10:50:38 +03:00
|
|
|
WLog_ERR(TAG, "%s entry returned error %lu.", name, error);
|
|
|
|
return error;
|
2011-09-21 09:28:02 +04:00
|
|
|
}
|
|
|
|
|
2015-06-02 10:50:38 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2011-09-21 09:28:02 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
UINT audin_set_subsystem(AUDIN_PLUGIN* audin, char* subsystem)
|
2012-11-20 07:31:15 +04:00
|
|
|
{
|
2015-05-11 10:07:39 +03:00
|
|
|
free(audin->subsystem);
|
2012-11-20 07:31:15 +04:00
|
|
|
audin->subsystem = _strdup(subsystem);
|
2015-06-02 10:50:38 +03:00
|
|
|
if (!audin->subsystem)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "_strdup failed!");
|
|
|
|
return ERROR_NOT_ENOUGH_MEMORY;
|
|
|
|
}
|
|
|
|
return CHANNEL_RC_OK;
|
2012-11-20 07:31:15 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
UINT audin_set_device_name(AUDIN_PLUGIN* audin, char* device_name)
|
2012-11-20 07:31:15 +04:00
|
|
|
{
|
2015-05-11 10:07:39 +03:00
|
|
|
free(audin->device_name);
|
2012-11-20 07:31:15 +04:00
|
|
|
audin->device_name = _strdup(device_name);
|
2015-06-02 10:50:38 +03:00
|
|
|
if (!audin->device_name)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "_strdup failed!");
|
|
|
|
return ERROR_NOT_ENOUGH_MEMORY;
|
|
|
|
}
|
|
|
|
return CHANNEL_RC_OK;
|
2012-11-20 07:31:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
COMMAND_LINE_ARGUMENT_A audin_args[] =
|
2011-09-21 09:28:02 +04:00
|
|
|
{
|
2012-11-20 07:31:15 +04:00
|
|
|
{ "sys", COMMAND_LINE_VALUE_REQUIRED, "<subsystem>", NULL, NULL, -1, NULL, "subsystem" },
|
|
|
|
{ "dev", COMMAND_LINE_VALUE_REQUIRED, "<device>", NULL, NULL, -1, NULL, "device" },
|
|
|
|
{ "format", COMMAND_LINE_VALUE_REQUIRED, "<format>", NULL, NULL, -1, NULL, "format" },
|
|
|
|
{ "rate", COMMAND_LINE_VALUE_REQUIRED, "<rate>", NULL, NULL, -1, NULL, "rate" },
|
|
|
|
{ "channel", COMMAND_LINE_VALUE_REQUIRED, "<channel>", NULL, NULL, -1, NULL, "channel" },
|
|
|
|
{ NULL, 0, NULL, NULL, NULL, -1, NULL, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
static BOOL audin_process_addin_args(IWTSPlugin* pPlugin, ADDIN_ARGV* args)
|
|
|
|
{
|
|
|
|
int status;
|
|
|
|
DWORD flags;
|
|
|
|
COMMAND_LINE_ARGUMENT_A* arg;
|
2011-09-21 09:28:02 +04:00
|
|
|
AUDIN_PLUGIN* audin = (AUDIN_PLUGIN*) pPlugin;
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT error;
|
2011-09-21 09:28:02 +04:00
|
|
|
|
2012-11-20 07:31:15 +04:00
|
|
|
flags = COMMAND_LINE_SIGIL_NONE | COMMAND_LINE_SEPARATOR_COLON;
|
|
|
|
|
|
|
|
status = CommandLineParseArgumentsA(args->argc, (const char**) args->argv,
|
|
|
|
audin_args, flags, audin, NULL, NULL);
|
|
|
|
|
|
|
|
arg = audin_args;
|
|
|
|
|
|
|
|
do
|
2011-09-21 09:28:02 +04:00
|
|
|
{
|
2012-11-20 07:31:15 +04:00
|
|
|
if (!(arg->Flags & COMMAND_LINE_VALUE_PRESENT))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
CommandLineSwitchStart(arg)
|
|
|
|
|
|
|
|
CommandLineSwitchCase(arg, "sys")
|
2011-09-21 09:28:02 +04:00
|
|
|
{
|
2015-06-02 10:50:38 +03:00
|
|
|
if ((error = audin_set_subsystem(audin, arg->Value)))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "audin_set_subsystem failed with error %lu!", error);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2011-09-21 09:28:02 +04:00
|
|
|
}
|
2012-11-20 07:31:15 +04:00
|
|
|
CommandLineSwitchCase(arg, "dev")
|
2011-09-21 09:28:02 +04:00
|
|
|
{
|
2015-06-02 10:50:38 +03:00
|
|
|
if ((error = audin_set_device_name(audin, arg->Value)))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "audin_set_device_name failed with error %lu!", error);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2011-09-21 09:28:02 +04:00
|
|
|
}
|
2012-11-20 07:31:15 +04:00
|
|
|
CommandLineSwitchCase(arg, "format")
|
2011-09-21 09:28:02 +04:00
|
|
|
{
|
2012-11-20 07:31:15 +04:00
|
|
|
audin->fixed_format = atoi(arg->Value);
|
2011-09-21 09:28:02 +04:00
|
|
|
}
|
2012-11-20 07:31:15 +04:00
|
|
|
CommandLineSwitchCase(arg, "rate")
|
2011-09-21 09:28:02 +04:00
|
|
|
{
|
2012-11-20 07:31:15 +04:00
|
|
|
audin->fixed_rate = atoi(arg->Value);
|
2011-09-21 09:28:02 +04:00
|
|
|
}
|
2012-11-20 07:31:15 +04:00
|
|
|
CommandLineSwitchCase(arg, "channel")
|
2011-09-21 09:28:02 +04:00
|
|
|
{
|
2012-11-20 07:31:15 +04:00
|
|
|
audin->fixed_channel = atoi(arg->Value);
|
2011-09-21 09:28:02 +04:00
|
|
|
}
|
2012-11-20 07:31:15 +04:00
|
|
|
CommandLineSwitchDefault(arg)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
CommandLineSwitchEnd(arg)
|
2011-09-21 09:28:02 +04:00
|
|
|
}
|
2012-11-20 07:31:15 +04:00
|
|
|
while ((arg = CommandLineFindNextArgumentA(arg)) != NULL);
|
2011-09-21 09:28:02 +04:00
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-09-21 09:28:02 +04:00
|
|
|
}
|
|
|
|
|
2012-10-14 10:38:58 +04:00
|
|
|
#ifdef STATIC_CHANNELS
|
|
|
|
#define DVCPluginEntry audin_DVCPluginEntry
|
|
|
|
#endif
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
UINT DVCPluginEntry(IDRDYNVC_ENTRY_POINTS* pEntryPoints)
|
2011-09-21 09:28:02 +04:00
|
|
|
{
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT error = CHANNEL_RC_OK;
|
2012-11-20 07:31:15 +04:00
|
|
|
ADDIN_ARGV* args;
|
2011-09-21 09:28:02 +04:00
|
|
|
AUDIN_PLUGIN* audin;
|
|
|
|
|
2013-09-26 18:05:16 +04:00
|
|
|
assert(pEntryPoints);
|
|
|
|
assert(pEntryPoints->GetPlugin);
|
2012-02-10 04:48:52 +04:00
|
|
|
|
2013-09-26 18:05:16 +04:00
|
|
|
audin = (AUDIN_PLUGIN*) pEntryPoints->GetPlugin(pEntryPoints, "audin");
|
2011-09-21 09:28:02 +04:00
|
|
|
if (audin == NULL)
|
|
|
|
{
|
2015-06-02 10:50:38 +03:00
|
|
|
audin = (AUDIN_PLUGIN*) calloc(1, sizeof(AUDIN_PLUGIN));
|
|
|
|
if (!audin)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "calloc failed!");
|
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
|
|
|
}
|
2011-09-21 09:28:02 +04:00
|
|
|
|
|
|
|
audin->iface.Initialize = audin_plugin_initialize;
|
|
|
|
audin->iface.Connected = NULL;
|
|
|
|
audin->iface.Disconnected = NULL;
|
|
|
|
audin->iface.Terminated = audin_plugin_terminated;
|
2012-11-20 07:31:15 +04:00
|
|
|
|
2011-09-21 09:28:02 +04:00
|
|
|
error = pEntryPoints->RegisterPlugin(pEntryPoints, "audin", (IWTSPlugin*) audin);
|
|
|
|
}
|
|
|
|
|
2012-11-20 07:31:15 +04:00
|
|
|
args = pEntryPoints->GetPluginData(pEntryPoints);
|
2015-07-15 10:50:35 +03:00
|
|
|
audin->rdpcontext = ((freerdp*)((rdpSettings*) pEntryPoints->GetRdpSettings(pEntryPoints))->instance)->context;
|
2012-11-20 07:31:15 +04:00
|
|
|
|
2015-06-02 10:50:38 +03:00
|
|
|
if (error == CHANNEL_RC_OK)
|
2012-11-20 07:31:15 +04:00
|
|
|
audin_process_addin_args((IWTSPlugin*) audin, args);
|
2015-06-02 10:50:38 +03:00
|
|
|
else
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "RegisterPlugin failed with error %lu!", error);
|
|
|
|
return error;
|
|
|
|
}
|
2012-11-20 07:31:15 +04:00
|
|
|
|
2015-06-02 10:50:38 +03:00
|
|
|
if (audin->subsystem && (error = audin_load_device_plugin((IWTSPlugin*) audin, audin->subsystem, args))) {
|
|
|
|
WLog_ERR(TAG, "audin_load_device_plugin failed!");
|
|
|
|
return error;
|
|
|
|
}
|
2012-11-20 07:31:15 +04:00
|
|
|
|
2013-09-26 18:05:16 +04:00
|
|
|
#if defined(WITH_PULSE)
|
2012-11-20 07:31:15 +04:00
|
|
|
if (!audin->device)
|
|
|
|
{
|
2015-06-02 10:50:38 +03:00
|
|
|
if ((error = audin_set_subsystem(audin, "pulse")))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "audin_set_subsystem for pulse failed with error %lu!", error);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
if ((error = audin_set_device_name(audin, "")))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "audin_set_device_name for pulse failed with error %lu!", error);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
if ((error = audin_load_device_plugin((IWTSPlugin*) audin, audin->subsystem, args)))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "audin_load_device_plugin for pulse failed with error %lu!", error);
|
|
|
|
return error;
|
|
|
|
}
|
2012-11-20 07:31:15 +04:00
|
|
|
}
|
2013-09-26 18:05:16 +04:00
|
|
|
#endif
|
2012-11-20 07:31:15 +04:00
|
|
|
|
2015-03-13 01:28:44 +03:00
|
|
|
#if defined(WITH_OSS)
|
|
|
|
if (!audin->device)
|
|
|
|
{
|
2015-06-02 10:50:38 +03:00
|
|
|
if ((error = audin_set_subsystem(audin, "oss")))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "audin_set_subsystem for oss failed with error %lu!", error);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
if ((error = audin_set_device_name(audin, "default")))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "audin_set_device_name for oss failed with error %lu!", error);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
if ((error = audin_load_device_plugin((IWTSPlugin*) audin, audin->subsystem, args)))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "audin_load_device_plugin oss pulse failed with error %lu!", error);
|
|
|
|
return error;
|
|
|
|
}
|
2015-03-13 01:28:44 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-09-26 18:05:16 +04:00
|
|
|
#if defined(WITH_ALSA)
|
2012-11-20 07:31:15 +04:00
|
|
|
if (!audin->device)
|
|
|
|
{
|
2015-06-02 10:50:38 +03:00
|
|
|
if ((error = audin_set_subsystem(audin, "alsa")))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "audin_set_subsystem for alsa failed with error %lu!", error);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
if ((error = audin_set_device_name(audin, "default")))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "audin_set_device_name for alsa failed with error %lu!", error);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
if ((error = audin_load_device_plugin((IWTSPlugin*) audin, audin->subsystem, args)))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "audin_load_device_plugin oss alsa failed with error %lu!", error);
|
|
|
|
return error;
|
|
|
|
}
|
2012-11-20 07:31:15 +04:00
|
|
|
}
|
2013-09-26 18:05:16 +04:00
|
|
|
#endif
|
2012-11-20 07:31:15 +04:00
|
|
|
|
2013-09-26 18:05:16 +04:00
|
|
|
#if defined(WITH_OPENSLES)
|
2013-09-20 13:47:10 +04:00
|
|
|
if (!audin->device)
|
|
|
|
{
|
2015-06-02 10:50:38 +03:00
|
|
|
if ((error = audin_set_subsystem(audin, "opensles")))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "audin_set_subsystem for opensles failed with error %lu!", error);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
if ((error = audin_set_device_name(audin, "default")))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "audin_set_device_name for opensles failed with error %lu!", error);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
if ((error = audin_load_device_plugin((IWTSPlugin*) audin, audin->subsystem, args)))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "audin_load_device_plugin oss opensles failed with error %lu!", error);
|
|
|
|
return error;
|
|
|
|
}
|
2013-09-20 13:47:10 +04:00
|
|
|
}
|
2013-09-26 18:05:16 +04:00
|
|
|
#endif
|
2013-09-20 13:47:10 +04:00
|
|
|
|
2014-02-11 13:30:57 +04:00
|
|
|
#if defined(WITH_WINMM)
|
|
|
|
if (!audin->device)
|
|
|
|
{
|
2015-06-02 10:50:38 +03:00
|
|
|
if ((error = audin_set_subsystem(audin, "winmm")))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "audin_set_subsystem for winmm failed with error %lu!", error);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
if ((error = audin_set_device_name(audin, "default")))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "audin_set_device_name for winmm failed with error %lu!", error);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
if ((error = audin_load_device_plugin((IWTSPlugin*) audin, audin->subsystem, args)))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "audin_load_device_plugin oss winmm failed with error %lu!", error);
|
|
|
|
return error;
|
|
|
|
}
|
2014-02-11 13:30:57 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-11-20 07:31:15 +04:00
|
|
|
if (audin->device == NULL)
|
|
|
|
{
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_ERR(TAG, "no sound device.");
|
2012-11-20 07:31:15 +04:00
|
|
|
}
|
2011-09-21 09:28:02 +04:00
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|