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>
|
2015-11-12 18:04:31 +03:00
|
|
|
* Copyright 2015 Armin Novak <armin.novak@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
|
|
|
|
|
2017-11-14 18:10:52 +03:00
|
|
|
#include <errno.h>
|
2021-06-09 15:03:34 +03:00
|
|
|
#include <winpr/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>
|
2018-07-17 11:57:08 +03:00
|
|
|
#include <winpr/wlog.h>
|
2012-11-20 07:31:15 +04:00
|
|
|
|
2012-11-18 09:08:03 +04:00
|
|
|
#include <freerdp/addin.h>
|
2018-02-20 14:15:30 +03:00
|
|
|
|
|
|
|
#include <winpr/stream.h>
|
2015-07-15 10:50:35 +03:00
|
|
|
#include <freerdp/freerdp.h>
|
2018-02-20 14:15:30 +03:00
|
|
|
#include <freerdp/codec/dsp.h>
|
2020-08-10 16:36:31 +03:00
|
|
|
#include <freerdp/channels/audin.h>
|
2018-02-20 14:15:30 +03:00
|
|
|
|
2011-09-21 09:28:02 +04:00
|
|
|
#include "audin_main.h"
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
#define MSG_SNDIN_VERSION 0x01
|
|
|
|
#define MSG_SNDIN_FORMATS 0x02
|
|
|
|
#define MSG_SNDIN_OPEN 0x03
|
|
|
|
#define MSG_SNDIN_OPEN_REPLY 0x04
|
2011-09-21 09:28:02 +04:00
|
|
|
#define MSG_SNDIN_DATA_INCOMING 0x05
|
2019-11-06 17:24:51 +03:00
|
|
|
#define MSG_SNDIN_DATA 0x06
|
|
|
|
#define MSG_SNDIN_FORMATCHANGE 0x07
|
2011-09-21 09:28:02 +04:00
|
|
|
|
|
|
|
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
|
|
|
|
*/
|
2018-02-20 14:15:30 +03:00
|
|
|
AUDIO_FORMAT* formats;
|
2018-02-09 16:04:10 +03:00
|
|
|
UINT32 formats_count;
|
2011-09-21 09:28:02 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct _AUDIN_PLUGIN AUDIN_PLUGIN;
|
|
|
|
struct _AUDIN_PLUGIN
|
|
|
|
{
|
|
|
|
IWTSPlugin iface;
|
|
|
|
|
|
|
|
AUDIN_LISTENER_CALLBACK* listener_callback;
|
|
|
|
|
|
|
|
/* Parsed plugin data */
|
2018-09-25 15:34:14 +03:00
|
|
|
AUDIO_FORMAT* fixed_format;
|
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;
|
2016-12-19 19:07:01 +03:00
|
|
|
BOOL attached;
|
2018-02-20 14:15:30 +03:00
|
|
|
wStream* data;
|
|
|
|
AUDIO_FORMAT* format;
|
|
|
|
UINT32 FramesPerPacket;
|
|
|
|
|
|
|
|
FREERDP_DSP_CONTEXT* dsp_context;
|
2018-07-17 11:57:08 +03:00
|
|
|
wLog* log;
|
2020-05-12 15:26:45 +03:00
|
|
|
|
|
|
|
IWTSListener* listener;
|
2020-08-10 16:36:31 +03:00
|
|
|
|
|
|
|
BOOL initialized;
|
2011-09-21 09:28:02 +04:00
|
|
|
};
|
|
|
|
|
2020-11-18 09:51:45 +03:00
|
|
|
static BOOL audin_process_addin_args(AUDIN_PLUGIN* audin, const ADDIN_ARGV* args);
|
2016-02-28 21:56:57 +03:00
|
|
|
|
2018-02-20 14:15:30 +03:00
|
|
|
static UINT audin_channel_write_and_free(AUDIN_CHANNEL_CALLBACK* callback, wStream* out,
|
2019-11-06 17:24:51 +03:00
|
|
|
BOOL freeStream)
|
2018-02-09 15:49:58 +03:00
|
|
|
{
|
2018-02-20 14:15:30 +03:00
|
|
|
UINT error;
|
2018-02-09 15:49:58 +03:00
|
|
|
|
2018-02-20 14:15:30 +03:00
|
|
|
if (!callback || !out)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
if (!callback->channel || !callback->channel->Write)
|
|
|
|
return ERROR_INTERNAL_ERROR;
|
|
|
|
|
|
|
|
Stream_SealLength(out);
|
2021-06-16 13:58:44 +03:00
|
|
|
WINPR_ASSERT(Stream_Length(out) <= ULONG_MAX);
|
|
|
|
error = callback->channel->Write(callback->channel, (ULONG)Stream_Length(out),
|
|
|
|
Stream_Buffer(out), NULL);
|
2018-02-20 14:15:30 +03:00
|
|
|
|
|
|
|
if (freeStream)
|
|
|
|
Stream_Free(out, TRUE);
|
2018-02-09 15:49:58 +03:00
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
2018-02-20 14:15:30 +03:00
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2018-07-17 11:57:08 +03:00
|
|
|
static UINT audin_process_version(AUDIN_PLUGIN* audin, AUDIN_CHANNEL_CALLBACK* callback, wStream* s)
|
2011-09-21 09:28:02 +04:00
|
|
|
{
|
2013-03-21 23:19:33 +04:00
|
|
|
wStream* out;
|
2018-04-16 11:22:24 +03:00
|
|
|
const UINT32 ClientVersion = 0x01;
|
|
|
|
UINT32 ServerVersion;
|
2018-02-20 14:15:30 +03:00
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < 4)
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
|
2018-04-16 11:22:24 +03:00
|
|
|
Stream_Read_UINT32(s, ServerVersion);
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_Print(audin->log, WLOG_DEBUG, "ServerVersion=%" PRIu32 ", ClientVersion=%" PRIu32,
|
|
|
|
ServerVersion, ClientVersion);
|
2018-10-04 14:53:18 +03:00
|
|
|
|
|
|
|
/* Do not answer server packet, we do not support the channel version. */
|
|
|
|
if (ServerVersion != ClientVersion)
|
|
|
|
{
|
|
|
|
WLog_Print(audin->log, WLOG_WARN,
|
2019-11-06 17:24:51 +03:00
|
|
|
"Incompatible channel version server=%" PRIu32
|
|
|
|
", client supports version=%" PRIu32,
|
|
|
|
ServerVersion, ClientVersion);
|
2018-10-04 14:53:18 +03:00
|
|
|
return CHANNEL_RC_OK;
|
|
|
|
}
|
|
|
|
|
2013-05-09 01:48:30 +04:00
|
|
|
out = Stream_New(NULL, 5);
|
2015-06-02 10:50:38 +03:00
|
|
|
|
|
|
|
if (!out)
|
|
|
|
{
|
2018-07-17 11:57:08 +03:00
|
|
|
WLog_Print(audin->log, WLOG_ERROR, "Stream_New failed!");
|
2015-06-02 10:50:38 +03:00
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT8(out, MSG_SNDIN_VERSION);
|
2018-04-16 11:22:24 +03:00
|
|
|
Stream_Write_UINT32(out, ClientVersion);
|
2018-02-20 14:15:30 +03:00
|
|
|
return audin_channel_write_and_free(callback, out, TRUE);
|
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
|
|
|
|
*/
|
2018-07-17 11:57:08 +03:00
|
|
|
static UINT audin_send_incoming_data_pdu(AUDIN_CHANNEL_CALLBACK* callback)
|
2011-09-21 09:28:02 +04:00
|
|
|
{
|
2018-07-17 11:57:08 +03:00
|
|
|
BYTE out_data[1] = { MSG_SNDIN_DATA_INCOMING };
|
|
|
|
|
|
|
|
if (!callback || !callback->channel || !callback->channel->Write)
|
|
|
|
return ERROR_INTERNAL_ERROR;
|
|
|
|
|
2011-09-21 09:28:02 +04:00
|
|
|
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
|
|
|
|
*/
|
2018-07-17 11:57:08 +03:00
|
|
|
static UINT audin_process_formats(AUDIN_PLUGIN* audin, AUDIN_CHANNEL_CALLBACK* callback, wStream* s)
|
2011-09-21 09:28:02 +04:00
|
|
|
{
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 i;
|
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;
|
2018-02-20 14:15:30 +03:00
|
|
|
UINT32 cbSizeFormatsPacket;
|
2018-02-09 15:49:58 +03:00
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < 8)
|
2018-02-20 14:15:30 +03:00
|
|
|
return ERROR_INVALID_DATA;
|
2018-02-09 15:49:58 +03:00
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT32(s, NumFormats);
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_Print(audin->log, WLOG_DEBUG, "NumFormats %" PRIu32 "", NumFormats);
|
2016-12-19 19:07:01 +03:00
|
|
|
|
2011-09-21 09:28:02 +04:00
|
|
|
if ((NumFormats < 1) || (NumFormats > 1000))
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_Print(audin->log, WLOG_ERROR, "bad NumFormats %" PRIu32 "", NumFormats);
|
2015-06-02 10:50:38 +03:00
|
|
|
return ERROR_INVALID_DATA;
|
2011-09-21 09:28:02 +04:00
|
|
|
}
|
|
|
|
|
2016-12-19 19:07:01 +03:00
|
|
|
Stream_Seek_UINT32(s); /* cbSizeFormatsPacket */
|
2018-09-25 15:34:14 +03:00
|
|
|
callback->formats = audio_formats_new(NumFormats);
|
2016-12-19 19:07:01 +03:00
|
|
|
|
2015-06-02 10:50:38 +03:00
|
|
|
if (!callback->formats)
|
|
|
|
{
|
2018-07-17 11:57:08 +03:00
|
|
|
WLog_Print(audin->log, WLOG_ERROR, "calloc failed!");
|
2015-06-02 10:50:38 +03:00
|
|
|
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;
|
2018-07-17 11:57:08 +03:00
|
|
|
WLog_Print(audin->log, WLOG_ERROR, "Stream_New failed!");
|
2015-06-02 10:50:38 +03:00
|
|
|
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++)
|
|
|
|
{
|
2018-07-03 10:54:29 +03:00
|
|
|
AUDIO_FORMAT format = { 0 };
|
2018-02-20 14:15:30 +03:00
|
|
|
|
2018-09-25 13:04:10 +03:00
|
|
|
if (!audio_format_read(s, &format))
|
2018-08-17 13:30:33 +03:00
|
|
|
{
|
|
|
|
error = ERROR_INVALID_DATA;
|
|
|
|
goto out;
|
|
|
|
}
|
2018-02-09 15:49:58 +03:00
|
|
|
|
2018-09-25 15:34:14 +03:00
|
|
|
audio_format_print(audin->log, WLOG_DEBUG, &format);
|
2018-02-09 15:49:58 +03:00
|
|
|
|
2018-09-25 15:34:14 +03:00
|
|
|
if (!audio_format_compatible(audin->fixed_format, &format))
|
2018-08-17 13:30:33 +03:00
|
|
|
{
|
2018-09-25 15:34:14 +03:00
|
|
|
audio_format_free(&format);
|
2011-09-21 09:28:02 +04:00
|
|
|
continue;
|
2018-07-31 11:33:19 +03:00
|
|
|
}
|
2016-12-19 19:07:01 +03:00
|
|
|
|
2018-02-20 14:15:30 +03:00
|
|
|
if (freerdp_dsp_supports_format(&format, TRUE) ||
|
|
|
|
audin->device->FormatSupported(audin->device, &format))
|
2011-09-21 09:28:02 +04:00
|
|
|
{
|
|
|
|
/* Store the agreed format in the corresponding index */
|
|
|
|
callback->formats[callback->formats_count++] = format;
|
2016-12-19 19:07:01 +03:00
|
|
|
|
2018-09-25 13:04:10 +03:00
|
|
|
if (!audio_format_write(out, &format))
|
2015-03-26 19:09:47 +03:00
|
|
|
{
|
2015-06-02 10:50:38 +03:00
|
|
|
error = CHANNEL_RC_NO_MEMORY;
|
2018-07-17 11:57:08 +03:00
|
|
|
WLog_Print(audin->log, WLOG_ERROR, "Stream_EnsureRemainingCapacity failed!");
|
2015-06-02 10:50:38 +03:00
|
|
|
goto out;
|
2015-03-26 19:09:47 +03:00
|
|
|
}
|
2018-07-03 10:54:29 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-09-25 15:34:14 +03:00
|
|
|
audio_format_free(&format);
|
2011-09-21 09:28:02 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-17 11:57:08 +03:00
|
|
|
if ((error = audin_send_incoming_data_pdu(callback)))
|
2015-06-02 10:50:38 +03:00
|
|
|
{
|
2018-07-17 11:57:08 +03:00
|
|
|
WLog_Print(audin->log, WLOG_ERROR, "audin_send_incoming_data_pdu failed!");
|
2015-06-02 10:50:38 +03:00
|
|
|
goto out;
|
|
|
|
}
|
2011-09-21 09:28:02 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
cbSizeFormatsPacket = (UINT32)Stream_GetPosition(out);
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_SetPosition(out, 0);
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Write_UINT8(out, MSG_SNDIN_FORMATS); /* Header (1 byte) */
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT32(out, callback->formats_count); /* NumFormats (4 bytes) */
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Write_UINT32(out, cbSizeFormatsPacket); /* cbSizeFormatsPacket (4 bytes) */
|
2018-02-09 16:04:10 +03:00
|
|
|
Stream_SetPosition(out, cbSizeFormatsPacket);
|
2018-08-17 13:30:33 +03:00
|
|
|
error = audin_channel_write_and_free(callback, out, FALSE);
|
2015-06-02 10:50:38 +03:00
|
|
|
out:
|
2016-12-19 19:07:01 +03:00
|
|
|
|
2015-06-02 10:50:38 +03:00
|
|
|
if (error != CHANNEL_RC_OK)
|
|
|
|
{
|
2018-09-25 13:04:10 +03:00
|
|
|
audio_formats_free(callback->formats, NumFormats);
|
|
|
|
callback->formats = NULL;
|
2015-06-02 10:50:38 +03:00
|
|
|
}
|
2011-09-21 09:28:02 +04:00
|
|
|
|
2018-08-17 13:30:33 +03: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
|
|
|
|
*/
|
2018-07-17 11:57:08 +03:00
|
|
|
static UINT audin_send_format_change_pdu(AUDIN_PLUGIN* audin, AUDIN_CHANNEL_CALLBACK* callback,
|
2019-11-06 17:24:51 +03:00
|
|
|
UINT32 NewFormat)
|
2011-09-21 09:28:02 +04:00
|
|
|
{
|
2018-07-17 11:57:08 +03:00
|
|
|
wStream* out = Stream_New(NULL, 5);
|
2015-06-02 10:50:38 +03:00
|
|
|
|
|
|
|
if (!out)
|
|
|
|
{
|
2018-07-17 11:57:08 +03:00
|
|
|
WLog_Print(audin->log, WLOG_ERROR, "Stream_New failed!");
|
2015-06-02 10:50:38 +03:00
|
|
|
return CHANNEL_RC_OK;
|
|
|
|
}
|
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT8(out, MSG_SNDIN_FORMATCHANGE);
|
|
|
|
Stream_Write_UINT32(out, NewFormat);
|
2018-02-20 14:15:30 +03:00
|
|
|
return audin_channel_write_and_free(callback, out, TRUE);
|
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
|
|
|
|
*/
|
2018-07-17 11:57:08 +03:00
|
|
|
static UINT audin_send_open_reply_pdu(AUDIN_PLUGIN* audin, AUDIN_CHANNEL_CALLBACK* callback,
|
|
|
|
UINT32 Result)
|
2011-09-21 09:28:02 +04:00
|
|
|
{
|
2018-07-17 11:57:08 +03:00
|
|
|
wStream* out = Stream_New(NULL, 5);
|
2015-06-02 10:50:38 +03:00
|
|
|
|
|
|
|
if (!out)
|
|
|
|
{
|
2018-07-17 11:57:08 +03:00
|
|
|
WLog_Print(audin->log, WLOG_ERROR, "Stream_New failed!");
|
2015-06-02 10:50:38 +03:00
|
|
|
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);
|
2018-02-20 14:15:30 +03:00
|
|
|
return audin_channel_write_and_free(callback, out, TRUE);
|
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
|
|
|
|
*/
|
2019-11-06 17:24:51 +03:00
|
|
|
static UINT audin_receive_wave_data(const AUDIO_FORMAT* format, const BYTE* data, size_t size,
|
|
|
|
void* user_data)
|
2011-09-21 09:28:02 +04:00
|
|
|
{
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT error;
|
2018-11-13 13:00:39 +03:00
|
|
|
BOOL compatible;
|
2016-12-19 19:13:25 +03:00
|
|
|
AUDIN_PLUGIN* audin;
|
2019-11-06 17:24:51 +03:00
|
|
|
AUDIN_CHANNEL_CALLBACK* callback = (AUDIN_CHANNEL_CALLBACK*)user_data;
|
2011-09-21 09:28:02 +04:00
|
|
|
|
2016-12-19 19:13:25 +03:00
|
|
|
if (!callback)
|
|
|
|
return CHANNEL_RC_BAD_CHANNEL_HANDLE;
|
|
|
|
|
|
|
|
audin = (AUDIN_PLUGIN*)callback->plugin;
|
|
|
|
|
|
|
|
if (!audin)
|
|
|
|
return CHANNEL_RC_BAD_CHANNEL_HANDLE;
|
|
|
|
|
|
|
|
if (!audin->attached)
|
|
|
|
return CHANNEL_RC_OK;
|
|
|
|
|
2018-07-17 15:55:19 +03:00
|
|
|
Stream_SetPosition(audin->data, 0);
|
2018-02-20 14:15:30 +03:00
|
|
|
|
|
|
|
if (!Stream_EnsureRemainingCapacity(audin->data, 1))
|
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
|
|
|
|
|
|
|
Stream_Write_UINT8(audin->data, MSG_SNDIN_DATA);
|
|
|
|
|
2018-11-13 13:00:39 +03:00
|
|
|
compatible = audio_format_compatible(format, audin->format);
|
|
|
|
if (compatible && audin->device->FormatSupported(audin->device, audin->format))
|
2015-06-02 10:50:38 +03:00
|
|
|
{
|
2018-02-20 14:15:30 +03:00
|
|
|
if (!Stream_EnsureRemainingCapacity(audin->data, size))
|
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
|
|
|
|
|
|
|
Stream_Write(audin->data, data, size);
|
2015-06-02 10:50:38 +03:00
|
|
|
}
|
2018-07-18 13:14:37 +03:00
|
|
|
else
|
|
|
|
{
|
2018-07-19 16:17:54 +03:00
|
|
|
if (!freerdp_dsp_encode(audin->dsp_context, format, data, size, audin->data))
|
2018-07-18 13:14:37 +03:00
|
|
|
return ERROR_INTERNAL_ERROR;
|
|
|
|
}
|
2011-09-21 09:28:02 +04:00
|
|
|
|
2018-07-19 16:17:54 +03:00
|
|
|
/* Did not encode anything, skip this, the codec is not ready for output. */
|
2018-02-20 14:15:30 +03:00
|
|
|
if (Stream_GetPosition(audin->data) <= 1)
|
|
|
|
return CHANNEL_RC_OK;
|
2015-06-02 10:50:38 +03:00
|
|
|
|
2018-09-25 15:56:25 +03:00
|
|
|
audio_format_print(audin->log, WLOG_TRACE, audin->format);
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_Print(audin->log, WLOG_TRACE, "[%" PRIdz "/%" PRIdz "]", size,
|
2018-07-19 16:17:54 +03:00
|
|
|
Stream_GetPosition(audin->data) - 1);
|
|
|
|
|
2018-07-17 11:57:08 +03:00
|
|
|
if ((error = audin_send_incoming_data_pdu(callback)))
|
2015-06-02 10:50:38 +03:00
|
|
|
{
|
2018-07-17 11:57:08 +03:00
|
|
|
WLog_Print(audin->log, WLOG_ERROR, "audin_send_incoming_data_pdu failed!");
|
2018-02-20 14:15:30 +03:00
|
|
|
return error;
|
2015-06-02 10:50:38 +03:00
|
|
|
}
|
|
|
|
|
2018-02-20 14:15:30 +03:00
|
|
|
return audin_channel_write_and_free(callback, audin->data, FALSE);
|
2011-09-21 09:28:02 +04:00
|
|
|
}
|
|
|
|
|
2018-02-20 14:15:30 +03:00
|
|
|
static BOOL audin_open_device(AUDIN_PLUGIN* audin, AUDIN_CHANNEL_CALLBACK* callback)
|
|
|
|
{
|
|
|
|
UINT error = ERROR_INTERNAL_ERROR;
|
|
|
|
BOOL supported;
|
|
|
|
AUDIO_FORMAT format;
|
|
|
|
|
|
|
|
if (!audin || !audin->device)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
format = *audin->format;
|
|
|
|
supported = IFCALLRESULT(FALSE, audin->device->FormatSupported, audin->device, &format);
|
2018-07-17 11:57:08 +03:00
|
|
|
WLog_Print(audin->log, WLOG_DEBUG, "microphone uses %s codec",
|
2018-09-25 13:04:10 +03:00
|
|
|
audio_format_get_tag_string(format.wFormatTag));
|
2018-02-20 14:15:30 +03:00
|
|
|
|
|
|
|
if (!supported)
|
|
|
|
{
|
2018-11-13 13:00:39 +03:00
|
|
|
/* Default sample rates supported by most backends. */
|
2021-08-23 15:49:28 +03:00
|
|
|
const UINT32 samplerates[] = { format.nSamplesPerSec, 96000, 48000, 44100, 22050 };
|
2018-11-13 13:00:39 +03:00
|
|
|
BOOL test = FALSE;
|
2021-08-23 15:49:28 +03:00
|
|
|
size_t x;
|
2018-11-13 13:00:39 +03:00
|
|
|
|
2018-02-20 14:15:30 +03:00
|
|
|
format.wFormatTag = WAVE_FORMAT_PCM;
|
|
|
|
format.wBitsPerSample = 16;
|
2021-08-23 15:49:28 +03:00
|
|
|
format.cbSize = 0;
|
|
|
|
for (x = 0; x < ARRAYSIZE(samplerates); x++)
|
2018-11-13 13:00:39 +03:00
|
|
|
{
|
2021-09-29 11:31:45 +03:00
|
|
|
size_t y;
|
2021-08-23 15:49:28 +03:00
|
|
|
format.nSamplesPerSec = samplerates[x];
|
2021-09-29 11:31:45 +03:00
|
|
|
for (y = audin->format->nChannels; y > 0; y--)
|
|
|
|
{
|
|
|
|
format.nChannels = y;
|
|
|
|
format.nBlockAlign = 2 * format.nChannels;
|
|
|
|
test = IFCALLRESULT(FALSE, audin->device->FormatSupported, audin->device, &format);
|
|
|
|
if (test)
|
|
|
|
break;
|
|
|
|
}
|
2021-08-23 15:49:28 +03:00
|
|
|
if (test)
|
|
|
|
break;
|
2018-11-13 13:00:39 +03:00
|
|
|
}
|
|
|
|
if (!test)
|
|
|
|
return FALSE;
|
2018-02-20 14:15:30 +03:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
IFCALLRET(audin->device->SetFormat, error, audin->device, &format, audin->FramesPerPacket);
|
2018-02-20 14:15:30 +03:00
|
|
|
|
|
|
|
if (error != CHANNEL_RC_OK)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "SetFormat failed with errorcode %" PRIu32 "", error);
|
2018-02-20 14:15:30 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2018-07-18 13:14:37 +03:00
|
|
|
if (!supported)
|
2018-02-20 14:15:30 +03:00
|
|
|
{
|
2021-08-23 15:49:28 +03:00
|
|
|
if (!freerdp_dsp_context_reset(audin->dsp_context, audin->format, audin->FramesPerPacket))
|
2018-02-20 14:15:30 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
IFCALLRET(audin->device->Open, error, audin->device, audin_receive_wave_data, callback);
|
2018-02-20 14:15:30 +03:00
|
|
|
|
|
|
|
if (error != CHANNEL_RC_OK)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "Open failed with errorcode %" PRIu32 "", error);
|
2018-02-20 14:15:30 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2018-07-17 11:57:08 +03:00
|
|
|
static UINT audin_process_open(AUDIN_PLUGIN* audin, AUDIN_CHANNEL_CALLBACK* callback, wStream* s)
|
2011-09-21 09:28:02 +04:00
|
|
|
{
|
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;
|
2018-02-09 15:49:58 +03:00
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < 8)
|
2018-02-20 14:15:30 +03:00
|
|
|
return ERROR_INVALID_DATA;
|
2018-02-09 15:49:58 +03:00
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT32(s, FramesPerPacket);
|
|
|
|
Stream_Read_UINT32(s, initialFormat);
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_Print(audin->log, WLOG_DEBUG, "FramesPerPacket=%" PRIu32 " initialFormat=%" PRIu32 "",
|
2018-07-17 11:57:08 +03:00
|
|
|
FramesPerPacket, initialFormat);
|
2018-02-20 14:15:30 +03:00
|
|
|
audin->FramesPerPacket = FramesPerPacket;
|
2011-09-21 09:28:02 +04:00
|
|
|
|
2018-02-20 14:15:30 +03:00
|
|
|
if (initialFormat >= callback->formats_count)
|
2011-09-21 09:28:02 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_Print(audin->log, WLOG_ERROR, "invalid format index %" PRIu32 " (total %d)",
|
2018-07-17 11:57:08 +03:00
|
|
|
initialFormat, callback->formats_count);
|
2015-06-02 10:50:38 +03:00
|
|
|
return ERROR_INVALID_DATA;
|
2011-09-21 09:28:02 +04:00
|
|
|
}
|
|
|
|
|
2018-02-20 14:15:30 +03:00
|
|
|
audin->format = &callback->formats[initialFormat];
|
2016-12-19 19:07:01 +03:00
|
|
|
|
2018-02-20 14:15:30 +03:00
|
|
|
if (!audin_open_device(audin, callback))
|
|
|
|
return ERROR_INTERNAL_ERROR;
|
2015-06-02 10:50:38 +03:00
|
|
|
|
2018-07-17 11:57:08 +03:00
|
|
|
if ((error = audin_send_format_change_pdu(audin, callback, initialFormat)))
|
2015-06-02 10:50:38 +03:00
|
|
|
{
|
2018-07-17 11:57:08 +03:00
|
|
|
WLog_Print(audin->log, WLOG_ERROR, "audin_send_format_change_pdu failed!");
|
2015-06-02 10:50:38 +03:00
|
|
|
return error;
|
2011-09-21 09:28:02 +04:00
|
|
|
}
|
|
|
|
|
2018-07-17 11:57:08 +03:00
|
|
|
if ((error = audin_send_open_reply_pdu(audin, callback, 0)))
|
|
|
|
WLog_Print(audin->log, WLOG_ERROR, "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
|
|
|
|
*/
|
2018-07-17 11:57:08 +03:00
|
|
|
static UINT audin_process_format_change(AUDIN_PLUGIN* audin, AUDIN_CHANNEL_CALLBACK* callback,
|
|
|
|
wStream* s)
|
2011-09-21 09:28:02 +04:00
|
|
|
{
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 NewFormat;
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT error = CHANNEL_RC_OK;
|
2018-02-09 15:49:58 +03:00
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < 4)
|
2018-02-20 14:15:30 +03:00
|
|
|
return ERROR_INVALID_DATA;
|
2018-02-09 15:49:58 +03:00
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT32(s, NewFormat);
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_Print(audin->log, WLOG_DEBUG, "NewFormat=%" PRIu32 "", NewFormat);
|
2011-09-21 09:28:02 +04:00
|
|
|
|
2018-07-03 10:54:29 +03:00
|
|
|
if (NewFormat >= callback->formats_count)
|
2011-09-21 09:28:02 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_Print(audin->log, WLOG_ERROR, "invalid format index %" PRIu32 " (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
|
|
|
}
|
|
|
|
|
2018-02-20 14:15:30 +03:00
|
|
|
audin->format = &callback->formats[NewFormat];
|
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);
|
2016-12-19 19:07:01 +03:00
|
|
|
|
2015-06-02 10:50:38 +03:00
|
|
|
if (error != CHANNEL_RC_OK)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "Close failed with errorcode %" PRIu32 "", error);
|
2015-06-02 10:50:38 +03:00
|
|
|
return error;
|
|
|
|
}
|
2011-09-21 09:28:02 +04:00
|
|
|
}
|
|
|
|
|
2018-02-20 14:15:30 +03:00
|
|
|
if (!audin_open_device(audin, callback))
|
|
|
|
return ERROR_INTERNAL_ERROR;
|
|
|
|
|
2018-07-17 11:57:08 +03:00
|
|
|
if ((error = audin_send_format_change_pdu(audin, callback, NewFormat)))
|
2018-02-20 14:15:30 +03:00
|
|
|
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
|
|
|
|
*/
|
2016-12-19 19:07:01 +03:00
|
|
|
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;
|
2018-07-17 11:57:08 +03:00
|
|
|
AUDIN_PLUGIN* audin;
|
2019-11-06 17:24:51 +03:00
|
|
|
AUDIN_CHANNEL_CALLBACK* callback = (AUDIN_CHANNEL_CALLBACK*)pChannelCallback;
|
2018-02-09 15:49:58 +03:00
|
|
|
|
2018-07-17 11:57:08 +03:00
|
|
|
if (!callback || !data)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
audin = (AUDIN_PLUGIN*)callback->plugin;
|
2018-07-17 11:57:08 +03:00
|
|
|
|
|
|
|
if (!audin)
|
|
|
|
return ERROR_INTERNAL_ERROR;
|
|
|
|
|
|
|
|
if (Stream_GetRemainingCapacity(data) < 1)
|
|
|
|
return ERROR_NO_DATA;
|
2018-02-09 15:49:58 +03:00
|
|
|
|
2014-06-11 16:42:32 +04:00
|
|
|
Stream_Read_UINT8(data, MessageId);
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_Print(audin->log, WLOG_DEBUG, "MessageId=0x%02" PRIx8 "", MessageId);
|
2011-09-21 09:28:02 +04:00
|
|
|
|
|
|
|
switch (MessageId)
|
|
|
|
{
|
|
|
|
case MSG_SNDIN_VERSION:
|
2018-07-17 11:57:08 +03:00
|
|
|
error = audin_process_version(audin, callback, data);
|
2011-09-21 09:28:02 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MSG_SNDIN_FORMATS:
|
2018-07-17 11:57:08 +03:00
|
|
|
error = audin_process_formats(audin, callback, data);
|
2011-09-21 09:28:02 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MSG_SNDIN_OPEN:
|
2018-07-17 11:57:08 +03:00
|
|
|
error = audin_process_open(audin, callback, data);
|
2011-09-21 09:28:02 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MSG_SNDIN_FORMATCHANGE:
|
2018-07-17 11:57:08 +03:00
|
|
|
error = audin_process_format_change(audin, callback, data);
|
2011-09-21 09:28:02 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_Print(audin->log, WLOG_ERROR, "unknown MessageId=0x%02" PRIx8 "", 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
|
|
|
{
|
2019-11-06 17:24:51 +03: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;
|
2018-07-17 11:57:08 +03:00
|
|
|
WLog_Print(audin->log, WLOG_TRACE, "...");
|
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);
|
2016-12-19 19:07:01 +03:00
|
|
|
|
2015-06-02 10:50:38 +03:00
|
|
|
if (error != CHANNEL_RC_OK)
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_Print(audin->log, WLOG_ERROR, "Close failed with errorcode %" PRIu32 "", error);
|
2015-06-02 10:50:38 +03:00
|
|
|
}
|
2011-09-21 09:28:02 +04:00
|
|
|
|
2018-02-20 14:15:30 +03:00
|
|
|
audin->format = NULL;
|
2018-09-25 13:04:10 +03:00
|
|
|
audio_formats_free(callback->formats, callback->formats_count);
|
2012-10-09 07:21:26 +04:00
|
|
|
free(callback);
|
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,
|
2019-11-06 17:24:51 +03:00
|
|
|
IWTSVirtualChannel* pChannel, BYTE* Data,
|
|
|
|
BOOL* pbAccept, IWTSVirtualChannelCallback** ppCallback)
|
2011-09-21 09:28:02 +04:00
|
|
|
{
|
|
|
|
AUDIN_CHANNEL_CALLBACK* callback;
|
2018-07-17 11:57:08 +03:00
|
|
|
AUDIN_PLUGIN* audin;
|
2019-11-06 17:24:51 +03:00
|
|
|
AUDIN_LISTENER_CALLBACK* listener_callback = (AUDIN_LISTENER_CALLBACK*)pListenerCallback;
|
2018-07-17 11:57:08 +03:00
|
|
|
|
|
|
|
if (!listener_callback || !listener_callback->plugin)
|
|
|
|
return ERROR_INTERNAL_ERROR;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
audin = (AUDIN_PLUGIN*)listener_callback->plugin;
|
2018-07-17 11:57:08 +03:00
|
|
|
WLog_Print(audin->log, WLOG_TRACE, "...");
|
2019-11-06 17:24:51 +03:00
|
|
|
callback = (AUDIN_CHANNEL_CALLBACK*)calloc(1, sizeof(AUDIN_CHANNEL_CALLBACK));
|
2016-12-19 19:07:01 +03:00
|
|
|
|
2015-06-02 10:50:38 +03:00
|
|
|
if (!callback)
|
|
|
|
{
|
2018-07-17 11:57:08 +03:00
|
|
|
WLog_Print(audin->log, WLOG_ERROR, "calloc failed!");
|
2015-06-02 10:50:38 +03:00
|
|
|
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;
|
2019-11-06 17:24:51 +03:00
|
|
|
*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
|
|
|
{
|
2020-08-10 16:36:31 +03:00
|
|
|
UINT rc;
|
2019-11-06 17:24:51 +03:00
|
|
|
AUDIN_PLUGIN* audin = (AUDIN_PLUGIN*)pPlugin;
|
2018-07-30 12:22:11 +03:00
|
|
|
|
|
|
|
if (!audin)
|
|
|
|
return CHANNEL_RC_BAD_CHANNEL_HANDLE;
|
|
|
|
|
|
|
|
if (!pChannelMgr)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
2020-08-10 16:36:31 +03:00
|
|
|
if (audin->initialized)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "[%s] channel initialized twice, aborting", AUDIN_DVC_CHANNEL_NAME);
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
|
|
|
|
2018-07-17 11:57:08 +03:00
|
|
|
WLog_Print(audin->log, WLOG_TRACE, "...");
|
2019-11-06 17:24:51 +03:00
|
|
|
audin->listener_callback = (AUDIN_LISTENER_CALLBACK*)calloc(1, sizeof(AUDIN_LISTENER_CALLBACK));
|
2016-12-19 19:07:01 +03:00
|
|
|
|
2015-06-02 10:50:38 +03:00
|
|
|
if (!audin->listener_callback)
|
|
|
|
{
|
2018-07-17 11:57:08 +03:00
|
|
|
WLog_Print(audin->log, WLOG_ERROR, "calloc failed!");
|
2015-06-02 10:50:38 +03:00
|
|
|
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;
|
2020-08-10 16:36:31 +03:00
|
|
|
rc = pChannelMgr->CreateListener(pChannelMgr, AUDIN_DVC_CHANNEL_NAME, 0,
|
|
|
|
&audin->listener_callback->iface, &audin->listener);
|
|
|
|
|
|
|
|
audin->initialized = rc == CHANNEL_RC_OK;
|
|
|
|
return rc;
|
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_terminated(IWTSPlugin* pPlugin)
|
2011-09-21 09:28:02 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
AUDIN_PLUGIN* audin = (AUDIN_PLUGIN*)pPlugin;
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT error = CHANNEL_RC_OK;
|
2018-07-30 12:22:11 +03:00
|
|
|
|
|
|
|
if (!audin)
|
|
|
|
return CHANNEL_RC_BAD_CHANNEL_HANDLE;
|
|
|
|
|
2018-07-17 11:57:08 +03:00
|
|
|
WLog_Print(audin->log, WLOG_TRACE, "...");
|
2020-05-12 11:54:07 +03:00
|
|
|
|
|
|
|
if (audin->listener_callback)
|
|
|
|
{
|
|
|
|
IWTSVirtualChannelManager* mgr = audin->listener_callback->channel_mgr;
|
|
|
|
if (mgr)
|
2020-05-12 15:26:45 +03:00
|
|
|
IFCALL(mgr->DestroyListener, mgr, audin->listener);
|
2020-05-12 11:54:07 +03:00
|
|
|
}
|
2019-10-24 13:18:24 +03:00
|
|
|
audio_formats_free(audin->fixed_format, 1);
|
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);
|
2016-12-19 19:07:01 +03:00
|
|
|
|
2015-06-02 10:50:38 +03:00
|
|
|
if (error != CHANNEL_RC_OK)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_Print(audin->log, WLOG_ERROR, "Free failed with errorcode %" PRIu32 "", error);
|
2015-06-02 10:50:38 +03:00
|
|
|
// dont stop on error
|
|
|
|
}
|
2016-12-19 19:07:01 +03:00
|
|
|
|
2011-09-21 09:28:02 +04:00
|
|
|
audin->device = NULL;
|
|
|
|
}
|
2012-02-10 04:48:52 +04:00
|
|
|
|
2018-03-23 15:57:22 +03:00
|
|
|
freerdp_dsp_context_free(audin->dsp_context);
|
2018-02-20 14:15:30 +03:00
|
|
|
Stream_Free(audin->data, TRUE);
|
2014-12-27 21:50:50 +03:00
|
|
|
free(audin->subsystem);
|
|
|
|
free(audin->device_name);
|
2012-10-09 07:21:26 +04:00
|
|
|
free(audin->listener_callback);
|
|
|
|
free(audin);
|
2015-06-02 10:50:38 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2011-09-21 09:28:02 +04:00
|
|
|
}
|
|
|
|
|
2016-12-19 19:07:01 +03:00
|
|
|
static UINT audin_plugin_attached(IWTSPlugin* pPlugin)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
AUDIN_PLUGIN* audin = (AUDIN_PLUGIN*)pPlugin;
|
2016-12-19 19:07:01 +03:00
|
|
|
UINT error = CHANNEL_RC_OK;
|
|
|
|
|
|
|
|
if (!audin)
|
|
|
|
return CHANNEL_RC_BAD_CHANNEL_HANDLE;
|
|
|
|
|
|
|
|
audin->attached = TRUE;
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT audin_plugin_detached(IWTSPlugin* pPlugin)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
AUDIN_PLUGIN* audin = (AUDIN_PLUGIN*)pPlugin;
|
2016-12-19 19:07:01 +03:00
|
|
|
UINT error = CHANNEL_RC_OK;
|
|
|
|
|
|
|
|
if (!audin)
|
|
|
|
return CHANNEL_RC_BAD_CHANNEL_HANDLE;
|
|
|
|
|
|
|
|
audin->attached = FALSE;
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
AUDIN_PLUGIN* audin = (AUDIN_PLUGIN*)pPlugin;
|
2011-09-21 09:28:02 +04:00
|
|
|
|
|
|
|
if (audin->device)
|
|
|
|
{
|
2018-07-17 11:57:08 +03:00
|
|
|
WLog_Print(audin->log, WLOG_ERROR, "existing device, abort.");
|
2015-06-02 10:50:38 +03:00
|
|
|
return ERROR_ALREADY_EXISTS;
|
2011-09-21 09:28:02 +04:00
|
|
|
}
|
|
|
|
|
2018-07-17 11:57:08 +03:00
|
|
|
WLog_Print(audin->log, WLOG_DEBUG, "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
|
|
|
|
*/
|
2020-11-18 09:51:45 +03:00
|
|
|
static UINT audin_load_device_plugin(AUDIN_PLUGIN* audin, const char* name, const ADDIN_ARGV* args)
|
2011-09-21 09:28:02 +04:00
|
|
|
{
|
|
|
|
FREERDP_AUDIN_DEVICE_ENTRY_POINTS entryPoints;
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT error;
|
2021-08-02 13:13:34 +03:00
|
|
|
const PFREERDP_AUDIN_DEVICE_ENTRY entry =
|
|
|
|
(const PFREERDP_AUDIN_DEVICE_ENTRY)freerdp_load_channel_addin_entry("audin", 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
|
|
|
{
|
2018-07-17 11:57:08 +03:00
|
|
|
WLog_Print(audin->log, WLOG_ERROR,
|
|
|
|
"freerdp_load_channel_addin_entry did not return any function pointers for %s ",
|
|
|
|
name);
|
2015-06-02 10:50:38 +03:00
|
|
|
return ERROR_INVALID_FUNCTION;
|
|
|
|
}
|
2011-09-21 09:28:02 +04:00
|
|
|
|
2021-10-07 16:50:57 +03:00
|
|
|
entryPoints.plugin = &audin->iface;
|
2011-09-21 09:28:02 +04:00
|
|
|
entryPoints.pRegisterAudinDevice = audin_register_device_plugin;
|
2012-11-20 07:31:15 +04:00
|
|
|
entryPoints.args = args;
|
2018-07-17 11:57:08 +03:00
|
|
|
entryPoints.rdpcontext = audin->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
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_Print(audin->log, WLOG_ERROR, "%s entry returned error %" PRIu32 ".", name, error);
|
2015-06-02 10:50:38 +03:00
|
|
|
return error;
|
2011-09-21 09:28:02 +04:00
|
|
|
}
|
|
|
|
|
2018-07-17 11:57:08 +03:00
|
|
|
WLog_Print(audin->log, WLOG_INFO, "Loaded %s backend for audin", name);
|
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
|
|
|
|
*/
|
2018-02-09 16:04:10 +03:00
|
|
|
static UINT audin_set_subsystem(AUDIN_PLUGIN* audin, const 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);
|
2016-12-19 19:07:01 +03:00
|
|
|
|
2015-06-02 10:50:38 +03:00
|
|
|
if (!audin->subsystem)
|
|
|
|
{
|
2018-07-17 11:57:08 +03:00
|
|
|
WLog_Print(audin->log, WLOG_ERROR, "_strdup failed!");
|
2015-06-02 10:50:38 +03:00
|
|
|
return ERROR_NOT_ENOUGH_MEMORY;
|
|
|
|
}
|
2016-12-19 19:07:01 +03:00
|
|
|
|
2015-06-02 10:50:38 +03:00
|
|
|
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
|
|
|
|
*/
|
2018-10-04 14:53:18 +03:00
|
|
|
static UINT audin_set_device_name(AUDIN_PLUGIN* audin, const 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);
|
2016-12-19 19:07:01 +03:00
|
|
|
|
2015-06-02 10:50:38 +03:00
|
|
|
if (!audin->device_name)
|
|
|
|
{
|
2018-07-17 11:57:08 +03:00
|
|
|
WLog_Print(audin->log, WLOG_ERROR, "_strdup failed!");
|
2015-06-02 10:50:38 +03:00
|
|
|
return ERROR_NOT_ENOUGH_MEMORY;
|
|
|
|
}
|
2016-12-19 19:07:01 +03:00
|
|
|
|
2015-06-02 10:50:38 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2012-11-20 07:31:15 +04:00
|
|
|
}
|
|
|
|
|
2020-11-18 09:51:45 +03:00
|
|
|
BOOL audin_process_addin_args(AUDIN_PLUGIN* audin, const ADDIN_ARGV* args)
|
2012-11-20 07:31:15 +04:00
|
|
|
{
|
|
|
|
int status;
|
|
|
|
DWORD flags;
|
2021-09-07 09:31:07 +03:00
|
|
|
const COMMAND_LINE_ARGUMENT_A* arg;
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT error;
|
2019-11-06 17:24:51 +03:00
|
|
|
COMMAND_LINE_ARGUMENT_A audin_args[] = {
|
|
|
|
{ "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 }
|
|
|
|
};
|
2011-09-21 09:28:02 +04:00
|
|
|
|
2016-05-12 10:28:12 +03:00
|
|
|
if (!args || args->argc == 1)
|
2016-03-10 20:52:18 +03:00
|
|
|
return TRUE;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
flags =
|
|
|
|
COMMAND_LINE_SIGIL_NONE | COMMAND_LINE_SEPARATOR_COLON | COMMAND_LINE_IGN_UNKNOWN_KEYWORD;
|
|
|
|
status =
|
|
|
|
CommandLineParseArgumentsA(args->argc, args->argv, audin_args, flags, audin, NULL, NULL);
|
2016-12-19 19:07:01 +03:00
|
|
|
|
2016-02-28 21:56:57 +03:00
|
|
|
if (status != 0)
|
|
|
|
return FALSE;
|
2012-11-20 07:31:15 +04:00
|
|
|
|
|
|
|
arg = audin_args;
|
2017-11-14 18:10:52 +03:00
|
|
|
errno = 0;
|
2012-11-20 07:31:15 +04:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
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)))
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_Print(audin->log, WLOG_ERROR,
|
|
|
|
"audin_set_subsystem failed with error %" PRIu32 "!", error);
|
2015-06-02 10:50:38 +03:00
|
|
|
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)))
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_Print(audin->log, WLOG_ERROR,
|
|
|
|
"audin_set_device_name failed with error %" PRIu32 "!", error);
|
2015-06-02 10:50:38 +03:00
|
|
|
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
|
|
|
{
|
2017-11-14 18:10:52 +03:00
|
|
|
unsigned long val = strtoul(arg->Value, NULL, 0);
|
|
|
|
|
|
|
|
if ((errno != 0) || (val > UINT16_MAX))
|
|
|
|
return FALSE;
|
|
|
|
|
2018-09-25 15:34:14 +03:00
|
|
|
audin->fixed_format->wFormatTag = val;
|
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
|
|
|
{
|
2017-11-14 18:10:52 +03:00
|
|
|
long val = strtol(arg->Value, NULL, 0);
|
|
|
|
|
|
|
|
if ((errno != 0) || (val < INT32_MIN) || (val > INT32_MAX))
|
|
|
|
return FALSE;
|
|
|
|
|
2018-09-25 15:34:14 +03:00
|
|
|
audin->fixed_format->nSamplesPerSec = val;
|
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
|
|
|
{
|
2017-11-14 18:10:52 +03:00
|
|
|
unsigned long val = strtoul(arg->Value, NULL, 0);
|
|
|
|
|
2021-08-23 15:49:28 +03:00
|
|
|
if ((errno != 0) || (val < UINT16_MAX))
|
2018-09-25 15:34:14 +03:00
|
|
|
audin->fixed_format->nChannels = val;
|
2011-09-21 09:28:02 +04:00
|
|
|
}
|
2012-11-20 07:31:15 +04:00
|
|
|
CommandLineSwitchDefault(arg)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
CommandLineSwitchEnd(arg)
|
2019-11-06 17:24:51 +03: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
|
|
|
}
|
|
|
|
|
2016-06-15 14:36:27 +03:00
|
|
|
#ifdef BUILTIN_CHANNELS
|
2019-11-06 17:24:51 +03:00
|
|
|
#define DVCPluginEntry audin_DVCPluginEntry
|
2016-02-29 17:18:19 +03:00
|
|
|
#else
|
2019-11-06 17:24:51 +03:00
|
|
|
#define DVCPluginEntry FREERDP_API DVCPluginEntry
|
2012-10-14 10:38:58 +04:00
|
|
|
#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-11-12 18:04:31 +03:00
|
|
|
struct SubsystemEntry
|
|
|
|
{
|
2016-12-19 19:07:01 +03:00
|
|
|
char* subsystem;
|
|
|
|
char* device;
|
2015-11-12 18:04:31 +03:00
|
|
|
};
|
2016-02-28 21:56:57 +03:00
|
|
|
UINT error = CHANNEL_RC_INITIALIZATION_ERROR;
|
2020-11-18 09:51:45 +03:00
|
|
|
const ADDIN_ARGV* args;
|
2011-09-21 09:28:02 +04:00
|
|
|
AUDIN_PLUGIN* audin;
|
2015-11-12 18:04:31 +03:00
|
|
|
struct SubsystemEntry entries[] =
|
|
|
|
{
|
|
|
|
#if defined(WITH_PULSE)
|
2019-11-06 17:24:51 +03:00
|
|
|
{ "pulse", "" },
|
2015-11-12 18:04:31 +03:00
|
|
|
#endif
|
|
|
|
#if defined(WITH_OSS)
|
2019-11-06 17:24:51 +03:00
|
|
|
{ "oss", "default" },
|
2015-11-12 18:04:31 +03:00
|
|
|
#endif
|
|
|
|
#if defined(WITH_ALSA)
|
2019-11-06 17:24:51 +03:00
|
|
|
{ "alsa", "default" },
|
2015-11-12 18:04:31 +03:00
|
|
|
#endif
|
|
|
|
#if defined(WITH_OPENSLES)
|
2019-11-06 17:24:51 +03:00
|
|
|
{ "opensles", "default" },
|
2015-11-12 18:04:31 +03:00
|
|
|
#endif
|
|
|
|
#if defined(WITH_WINMM)
|
2019-11-06 17:24:51 +03:00
|
|
|
{ "winmm", "default" },
|
2015-11-12 18:04:31 +03:00
|
|
|
#endif
|
|
|
|
#if defined(WITH_MACAUDIO)
|
2019-11-06 17:24:51 +03:00
|
|
|
{ "mac", "default" },
|
2021-03-07 14:51:36 +03:00
|
|
|
#endif
|
|
|
|
#if defined(WITH_SNDIO)
|
|
|
|
{ "sndio", "default" },
|
2015-11-12 18:04:31 +03:00
|
|
|
#endif
|
2019-11-06 17:24:51 +03:00
|
|
|
{ NULL, NULL }
|
2015-11-12 18:04:31 +03:00
|
|
|
};
|
2016-12-19 19:07:01 +03:00
|
|
|
struct SubsystemEntry* entry = &entries[0];
|
2021-06-09 15:03:34 +03:00
|
|
|
WINPR_ASSERT(pEntryPoints);
|
|
|
|
WINPR_ASSERT(pEntryPoints->GetPlugin);
|
2019-11-06 17:24:51 +03:00
|
|
|
audin = (AUDIN_PLUGIN*)pEntryPoints->GetPlugin(pEntryPoints, "audin");
|
2016-12-19 19:07:01 +03:00
|
|
|
|
2016-03-07 14:54:49 +03:00
|
|
|
if (audin != NULL)
|
|
|
|
return CHANNEL_RC_ALREADY_INITIALIZED;
|
2012-11-20 07:31:15 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
audin = (AUDIN_PLUGIN*)calloc(1, sizeof(AUDIN_PLUGIN));
|
2016-12-19 19:07:01 +03:00
|
|
|
|
2016-03-07 14:54:49 +03:00
|
|
|
if (!audin)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "calloc failed!");
|
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
2011-09-21 09:28:02 +04:00
|
|
|
}
|
|
|
|
|
2018-07-17 11:57:08 +03:00
|
|
|
audin->log = WLog_Get(TAG);
|
2018-02-20 14:15:30 +03:00
|
|
|
audin->data = Stream_New(NULL, 4096);
|
2018-09-25 15:34:14 +03:00
|
|
|
audin->fixed_format = audio_format_new();
|
|
|
|
|
|
|
|
if (!audin->fixed_format)
|
|
|
|
goto out;
|
2018-02-20 14:15:30 +03:00
|
|
|
|
2018-07-19 17:21:03 +03:00
|
|
|
if (!audin->data)
|
2018-02-20 14:15:30 +03:00
|
|
|
goto out;
|
|
|
|
|
|
|
|
audin->dsp_context = freerdp_dsp_context_new(TRUE);
|
|
|
|
|
|
|
|
if (!audin->dsp_context)
|
|
|
|
goto out;
|
|
|
|
|
2016-12-19 19:07:01 +03:00
|
|
|
audin->attached = TRUE;
|
2016-03-07 14:54:49 +03:00
|
|
|
audin->iface.Initialize = audin_plugin_initialize;
|
|
|
|
audin->iface.Connected = NULL;
|
|
|
|
audin->iface.Disconnected = NULL;
|
|
|
|
audin->iface.Terminated = audin_plugin_terminated;
|
2016-12-19 19:07:01 +03:00
|
|
|
audin->iface.Attached = audin_plugin_attached;
|
|
|
|
audin->iface.Detached = audin_plugin_detached;
|
2012-11-20 07:31:15 +04:00
|
|
|
args = pEntryPoints->GetPluginData(pEntryPoints);
|
2019-11-06 17:24:51 +03:00
|
|
|
audin->rdpcontext =
|
|
|
|
((freerdp*)((rdpSettings*)pEntryPoints->GetRdpSettings(pEntryPoints))->instance)->context;
|
2012-11-20 07:31:15 +04:00
|
|
|
|
2016-02-28 21:56:57 +03:00
|
|
|
if (args)
|
2015-06-02 10:50:38 +03:00
|
|
|
{
|
2016-02-28 21:56:57 +03:00
|
|
|
if (!audin_process_addin_args(audin, args))
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (audin->subsystem)
|
|
|
|
{
|
2018-07-17 11:57:08 +03:00
|
|
|
if ((error = audin_load_device_plugin(audin, audin->subsystem, args)))
|
2015-06-02 10:50:38 +03:00
|
|
|
{
|
2020-01-08 15:31:20 +03:00
|
|
|
WLog_Print(
|
|
|
|
audin->log, WLOG_ERROR,
|
|
|
|
"Unable to load microphone redirection subsystem %s because of error %" PRIu32 "",
|
|
|
|
audin->subsystem, error);
|
2016-02-28 21:56:57 +03:00
|
|
|
goto out;
|
2015-06-02 10:50:38 +03:00
|
|
|
}
|
2016-02-28 21:56:57 +03:00
|
|
|
}
|
2016-02-29 14:34:53 +03:00
|
|
|
else
|
2016-02-28 21:56:57 +03:00
|
|
|
{
|
|
|
|
while (entry && entry->subsystem && !audin->device)
|
|
|
|
{
|
|
|
|
if ((error = audin_set_subsystem(audin, entry->subsystem)))
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_Print(audin->log, WLOG_ERROR,
|
|
|
|
"audin_set_subsystem for %s failed with error %" PRIu32 "!",
|
2018-07-17 11:57:08 +03:00
|
|
|
entry->subsystem, error);
|
2016-02-28 21:56:57 +03:00
|
|
|
}
|
|
|
|
else if ((error = audin_set_device_name(audin, entry->device)))
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_Print(audin->log, WLOG_ERROR,
|
|
|
|
"audin_set_device_name for %s failed with error %" PRIu32 "!",
|
2018-07-17 11:57:08 +03:00
|
|
|
entry->subsystem, error);
|
2016-02-28 21:56:57 +03:00
|
|
|
}
|
2018-07-17 11:57:08 +03:00
|
|
|
else if ((error = audin_load_device_plugin(audin, audin->subsystem, args)))
|
2016-02-28 21:56:57 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_Print(audin->log, WLOG_ERROR,
|
|
|
|
"audin_load_device_plugin %s failed with error %" PRIu32 "!",
|
2018-07-17 11:57:08 +03:00
|
|
|
entry->subsystem, error);
|
2016-02-28 21:56:57 +03:00
|
|
|
}
|
2012-11-20 07:31:15 +04:00
|
|
|
|
2016-02-28 21:56:57 +03:00
|
|
|
entry++;
|
|
|
|
}
|
2015-03-13 01:28:44 +03:00
|
|
|
}
|
2014-02-11 13:30:57 +04:00
|
|
|
|
2012-11-20 07:31:15 +04:00
|
|
|
if (audin->device == NULL)
|
2019-12-30 14:59:14 +03:00
|
|
|
{
|
|
|
|
/* If we have no audin device do not register plugin but still return OK or the client will
|
|
|
|
* just disconnect due to a missing microphone. */
|
2020-01-08 15:31:20 +03:00
|
|
|
WLog_Print(audin->log, WLOG_ERROR, "No microphone device could be found.");
|
2019-12-30 14:59:14 +03:00
|
|
|
error = CHANNEL_RC_OK;
|
|
|
|
goto out;
|
|
|
|
}
|
2016-02-28 21:56:57 +03:00
|
|
|
|
2021-10-07 16:50:57 +03:00
|
|
|
error = pEntryPoints->RegisterPlugin(pEntryPoints, "audin", &audin->iface);
|
2019-12-30 14:59:14 +03:00
|
|
|
if (error == CHANNEL_RC_OK)
|
|
|
|
return error;
|
2011-09-21 09:28:02 +04:00
|
|
|
|
2019-12-30 14:59:14 +03:00
|
|
|
out:
|
2021-10-07 16:50:57 +03:00
|
|
|
audin_plugin_terminated(&audin->iface);
|
2011-09-21 09:28:02 +04:00
|
|
|
return error;
|
|
|
|
}
|