2012-06-26 10:49:39 +04:00
|
|
|
/**
|
2012-10-09 07:02:04 +04:00
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
2012-06-26 10:49:39 +04:00
|
|
|
* Server Audio Input Virtual Channel
|
|
|
|
*
|
|
|
|
* Copyright 2012 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>
|
2012-06-26 10:49:39 +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.
|
|
|
|
*/
|
|
|
|
|
2022-02-16 13:20:38 +03:00
|
|
|
#include <freerdp/config.h>
|
2012-08-15 01:20:53 +04:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2012-11-20 08:49:08 +04:00
|
|
|
#include <winpr/crt.h>
|
2021-06-16 13:58:44 +03:00
|
|
|
#include <winpr/assert.h>
|
2013-03-22 01:28:55 +04:00
|
|
|
#include <winpr/synch.h>
|
|
|
|
#include <winpr/thread.h>
|
|
|
|
#include <winpr/stream.h>
|
2012-11-20 08:49:08 +04:00
|
|
|
|
2013-02-20 02:47:55 +04:00
|
|
|
#include <freerdp/codec/dsp.h>
|
2013-03-22 01:28:55 +04:00
|
|
|
#include <freerdp/codec/audio.h>
|
2012-06-26 10:49:39 +04:00
|
|
|
#include <freerdp/channels/wtsvc.h>
|
2020-08-10 16:36:31 +03:00
|
|
|
#include <freerdp/channels/audin.h>
|
2012-06-26 10:49:39 +04:00
|
|
|
#include <freerdp/server/audin.h>
|
2014-08-11 11:12:01 +04:00
|
|
|
#include <freerdp/channels/log.h>
|
2012-06-26 10:49:39 +04:00
|
|
|
|
2014-09-12 18:19:32 +04:00
|
|
|
#define TAG CHANNELS_TAG("audin.server")
|
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
|
|
|
|
#define MSG_SNDIN_DATA_INCOMING 0x05
|
|
|
|
#define MSG_SNDIN_DATA 0x06
|
|
|
|
#define MSG_SNDIN_FORMATCHANGE 0x07
|
2012-06-26 10:49:39 +04:00
|
|
|
|
2022-02-14 16:59:22 +03:00
|
|
|
typedef struct
|
2012-06-26 10:49:39 +04:00
|
|
|
{
|
|
|
|
audin_server_context context;
|
|
|
|
|
2013-03-22 01:28:55 +04:00
|
|
|
BOOL opened;
|
|
|
|
|
|
|
|
HANDLE stopEvent;
|
|
|
|
|
|
|
|
HANDLE thread;
|
2012-06-26 10:49:39 +04:00
|
|
|
void* audin_channel;
|
|
|
|
|
2014-02-17 08:00:58 +04:00
|
|
|
DWORD SessionId;
|
|
|
|
|
2012-06-26 10:49:39 +04:00
|
|
|
FREERDP_DSP_CONTEXT* dsp_context;
|
|
|
|
|
|
|
|
} audin_server;
|
|
|
|
|
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_server_select_format(audin_server_context* context, size_t client_format_index)
|
2012-06-26 10:49:39 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
audin_server* audin = (audin_server*)context;
|
2012-06-26 10:49:39 +04:00
|
|
|
|
2021-06-16 13:58:44 +03:00
|
|
|
WINPR_ASSERT(audin);
|
|
|
|
|
2012-06-26 10:49:39 +04:00
|
|
|
if (client_format_index >= context->num_client_formats)
|
2015-06-02 10:50:38 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "error in protocol: client_format_index >= context->num_client_formats!");
|
2015-06-02 10:50:38 +03:00
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2013-03-22 01:28:55 +04:00
|
|
|
|
2018-09-25 17:32:37 +03:00
|
|
|
context->selected_client_format = (SSIZE_T)client_format_index;
|
2018-09-25 12:13:32 +03:00
|
|
|
|
2018-07-19 16:54:40 +03:00
|
|
|
if (!freerdp_dsp_context_reset(audin->dsp_context,
|
2021-08-23 15:49:28 +03:00
|
|
|
&audin->context.client_formats[client_format_index], 0u))
|
2018-07-19 16:54:40 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Failed to reset dsp context format!");
|
|
|
|
return ERROR_INTERNAL_ERROR;
|
|
|
|
}
|
2013-03-22 01:28:55 +04:00
|
|
|
|
2012-06-26 10:49:39 +04:00
|
|
|
if (audin->opened)
|
|
|
|
{
|
|
|
|
/* TODO: send MSG_SNDIN_FORMATCHANGE */
|
|
|
|
}
|
2016-09-26 13:12:37 +03:00
|
|
|
|
2015-06-02 10:50:38 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2012-06-26 10:49:39 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
static UINT audin_server_send_version(audin_server* audin, wStream* s)
|
2012-06-26 10:49:39 +04:00
|
|
|
{
|
2014-05-28 19:04:24 +04:00
|
|
|
ULONG written;
|
2021-06-16 13:58:44 +03:00
|
|
|
WINPR_ASSERT(audin);
|
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT8(s, MSG_SNDIN_VERSION);
|
|
|
|
Stream_Write_UINT32(s, 1); /* Version (4 bytes) */
|
2016-09-26 13:12:37 +03:00
|
|
|
|
2021-06-16 13:58:44 +03:00
|
|
|
WINPR_ASSERT(Stream_GetPosition(s) <= ULONG_MAX);
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!WTSVirtualChannelWrite(audin->audin_channel, (PCHAR)Stream_Buffer(s),
|
2021-06-16 13:58:44 +03:00
|
|
|
(ULONG)Stream_GetPosition(s), &written))
|
2015-06-02 10:50:38 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "WTSVirtualChannelWrite failed!");
|
|
|
|
return ERROR_INTERNAL_ERROR;
|
|
|
|
}
|
2016-09-26 13:12:37 +03:00
|
|
|
|
2015-06-02 10:50:38 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2012-06-26 10:49:39 +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_server_recv_version(audin_server* audin, wStream* s, UINT32 length)
|
2012-06-26 10:49:39 +04:00
|
|
|
{
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 Version;
|
2012-06-26 10:49:39 +04:00
|
|
|
|
2021-06-16 13:58:44 +03:00
|
|
|
WINPR_ASSERT(audin);
|
2012-06-26 10:49:39 +04:00
|
|
|
if (length < 4)
|
2015-06-02 10:50:38 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "error parsing version info: expected at least 4 bytes, got %" PRIu32 "",
|
2016-09-26 13:12:37 +03:00
|
|
|
length);
|
2015-06-02 10:50:38 +03:00
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2013-03-22 01:28:55 +04:00
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT32(s, Version);
|
2013-03-22 01:28:55 +04:00
|
|
|
|
2012-06-26 10:49:39 +04:00
|
|
|
if (Version < 1)
|
2015-06-02 10:50:38 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "expected Version > 0 but got %" PRIu32 "", Version);
|
2015-06-02 10:50:38 +03:00
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2012-06-26 10:49:39 +04:00
|
|
|
|
2015-06-02 10:50:38 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2012-06-26 10:49:39 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
static UINT audin_server_send_formats(audin_server* audin, wStream* s)
|
2012-06-26 10:49:39 +04:00
|
|
|
{
|
2018-09-25 13:04:10 +03:00
|
|
|
size_t i;
|
2014-05-28 19:04:24 +04:00
|
|
|
ULONG written;
|
2021-06-16 13:58:44 +03:00
|
|
|
WINPR_ASSERT(audin);
|
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_SetPosition(s, 0);
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT8(s, MSG_SNDIN_FORMATS);
|
2021-06-16 13:58:44 +03:00
|
|
|
WINPR_ASSERT(audin->context.num_server_formats <= UINT32_MAX);
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Write_UINT32(s, audin->context.num_server_formats); /* NumFormats (4 bytes) */
|
|
|
|
Stream_Write_UINT32(s, 0); /* cbSizeFormatsPacket (4 bytes), client-to-server only */
|
2012-06-26 10:49:39 +04:00
|
|
|
|
|
|
|
for (i = 0; i < audin->context.num_server_formats; i++)
|
|
|
|
{
|
2018-09-25 13:04:10 +03:00
|
|
|
AUDIO_FORMAT format = audin->context.server_formats[i];
|
|
|
|
// TODO: Eliminate this
|
2019-11-06 17:24:51 +03:00
|
|
|
format.nAvgBytesPerSec =
|
|
|
|
format.nSamplesPerSec * format.nChannels * format.wBitsPerSample / 8;
|
2013-05-02 02:15:55 +04:00
|
|
|
|
2018-09-25 13:04:10 +03:00
|
|
|
if (!audio_format_write(s, &format))
|
2015-06-02 10:50:38 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Stream_EnsureRemainingCapacity failed!");
|
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
|
|
|
}
|
2012-06-26 10:49:39 +04:00
|
|
|
}
|
|
|
|
|
2021-06-16 13:58:44 +03:00
|
|
|
WINPR_ASSERT(Stream_GetPosition(s) <= ULONG_MAX);
|
2019-11-06 17:24:51 +03:00
|
|
|
return WTSVirtualChannelWrite(audin->audin_channel, (PCHAR)Stream_Buffer(s),
|
2021-06-16 13:58:44 +03:00
|
|
|
(ULONG)Stream_GetPosition(s), &written)
|
2019-11-06 17:24:51 +03:00
|
|
|
? CHANNEL_RC_OK
|
|
|
|
: ERROR_INTERNAL_ERROR;
|
2012-06-26 10:49:39 +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_server_recv_formats(audin_server* audin, wStream* s, UINT32 length)
|
2012-06-26 10:49:39 +04:00
|
|
|
{
|
2018-09-25 15:34:14 +03:00
|
|
|
size_t i;
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT success = CHANNEL_RC_OK;
|
2012-06-26 10:49:39 +04:00
|
|
|
|
2021-06-16 13:58:44 +03:00
|
|
|
WINPR_ASSERT(audin);
|
2012-06-26 10:49:39 +04:00
|
|
|
if (length < 8)
|
2015-06-02 10:50:38 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "error parsing rec formats: expected at least 8 bytes, got %" PRIu32 "",
|
2016-09-26 13:12:37 +03:00
|
|
|
length);
|
2015-06-02 10:50:38 +03:00
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2012-06-26 10:49:39 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Read_UINT32(s, audin->context.num_client_formats); /* NumFormats (4 bytes) */
|
|
|
|
Stream_Seek_UINT32(s); /* cbSizeFormatsPacket (4 bytes) */
|
2012-06-26 10:49:39 +04:00
|
|
|
length -= 8;
|
|
|
|
|
|
|
|
if (audin->context.num_client_formats <= 0)
|
2015-06-02 10:50:38 +03:00
|
|
|
{
|
2016-09-26 13:12:37 +03:00
|
|
|
WLog_ERR(TAG, "num_client_formats expected > 0 but got %d",
|
|
|
|
audin->context.num_client_formats);
|
2015-06-02 10:50:38 +03:00
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2012-06-26 10:49:39 +04:00
|
|
|
|
2018-09-25 15:34:14 +03:00
|
|
|
audin->context.client_formats = audio_formats_new(audin->context.num_client_formats);
|
2016-10-04 11:31:04 +03:00
|
|
|
|
|
|
|
if (!audin->context.client_formats)
|
|
|
|
return ERROR_NOT_ENOUGH_MEMORY;
|
2012-11-20 08:49:08 +04:00
|
|
|
|
2012-06-26 10:49:39 +04:00
|
|
|
for (i = 0; i < audin->context.num_client_formats; i++)
|
|
|
|
{
|
2018-09-25 13:04:10 +03:00
|
|
|
AUDIO_FORMAT* format = &audin->context.client_formats[i];
|
|
|
|
|
|
|
|
if (!audio_format_read(s, format))
|
2012-06-26 10:49:39 +04:00
|
|
|
{
|
2018-09-25 13:04:10 +03:00
|
|
|
audio_formats_free(audin->context.client_formats, i);
|
2012-06-26 10:49:39 +04:00
|
|
|
audin->context.client_formats = NULL;
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "expected length at least 18, but got %" PRIu32 "", length);
|
2015-06-02 10:50:38 +03:00
|
|
|
return ERROR_INVALID_DATA;
|
2012-06-26 10:49:39 +04:00
|
|
|
}
|
2018-09-25 15:34:14 +03:00
|
|
|
|
|
|
|
audio_format_print(WLog_Get(TAG), WLOG_DEBUG, format);
|
2012-06-26 10:49:39 +04:00
|
|
|
}
|
|
|
|
|
2015-06-02 10:50:38 +03:00
|
|
|
IFCALLRET(audin->context.Opening, success, &audin->context);
|
2016-09-26 13:12:37 +03:00
|
|
|
|
|
|
|
if (success)
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "context.Opening failed with error %" PRIu32 "", success);
|
2016-09-26 13:12:37 +03:00
|
|
|
|
2015-06-02 10:50:38 +03:00
|
|
|
return success;
|
2012-06-26 10:49:39 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
static UINT audin_server_send_open(audin_server* audin, wStream* s)
|
2012-06-26 10:49:39 +04:00
|
|
|
{
|
2014-05-28 19:04:24 +04:00
|
|
|
ULONG written;
|
|
|
|
|
2021-06-16 13:58:44 +03:00
|
|
|
WINPR_ASSERT(audin);
|
2012-06-26 10:49:39 +04:00
|
|
|
if (audin->context.selected_client_format < 0)
|
2015-06-02 10:50:38 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "audin->context.selected_client_format = %d",
|
2016-09-26 13:12:37 +03:00
|
|
|
audin->context.selected_client_format);
|
2015-06-02 10:50:38 +03:00
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2012-06-26 10:49:39 +04:00
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
audin->opened = TRUE;
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_SetPosition(s, 0);
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT8(s, MSG_SNDIN_OPEN);
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Write_UINT32(s, audin->context.frames_per_packet); /* FramesPerPacket (4 bytes) */
|
2021-06-16 13:58:44 +03:00
|
|
|
WINPR_ASSERT(audin->context.selected_client_format >= 0);
|
|
|
|
WINPR_ASSERT(audin->context.selected_client_format <= UINT32_MAX);
|
|
|
|
Stream_Write_UINT32(
|
|
|
|
s, (UINT32)audin->context.selected_client_format); /* initialFormat (4 bytes) */
|
2012-06-26 10:49:39 +04:00
|
|
|
/*
|
|
|
|
* [MS-RDPEAI] 3.2.5.1.6
|
|
|
|
* The second format specify the format that SHOULD be used to capture data from
|
|
|
|
* the actual audio input device.
|
|
|
|
*/
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Write_UINT16(s, 1); /* wFormatTag = PCM */
|
|
|
|
Stream_Write_UINT16(s, 2); /* nChannels */
|
|
|
|
Stream_Write_UINT32(s, 44100); /* nSamplesPerSec */
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT32(s, 44100 * 2 * 2); /* nAvgBytesPerSec */
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Write_UINT16(s, 4); /* nBlockAlign */
|
|
|
|
Stream_Write_UINT16(s, 16); /* wBitsPerSample */
|
|
|
|
Stream_Write_UINT16(s, 0); /* cbSize */
|
2021-06-16 13:58:44 +03:00
|
|
|
WINPR_ASSERT(Stream_GetPosition(s) <= ULONG_MAX);
|
2019-11-06 17:24:51 +03:00
|
|
|
return WTSVirtualChannelWrite(audin->audin_channel, (PCHAR)Stream_Buffer(s),
|
2021-06-16 13:58:44 +03:00
|
|
|
(ULONG)Stream_GetPosition(s), &written)
|
2019-11-06 17:24:51 +03:00
|
|
|
? CHANNEL_RC_OK
|
|
|
|
: ERROR_INTERNAL_ERROR;
|
2012-06-26 10:49:39 +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_server_recv_open_reply(audin_server* audin, wStream* s, UINT32 length)
|
2012-06-26 10:49:39 +04:00
|
|
|
{
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 Result;
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT success = CHANNEL_RC_OK;
|
2012-06-26 10:49:39 +04:00
|
|
|
|
2021-06-16 13:58:44 +03:00
|
|
|
WINPR_ASSERT(audin);
|
2012-06-26 10:49:39 +04:00
|
|
|
if (length < 4)
|
2015-06-02 10:50:38 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "error parsing version info: expected at least 4 bytes, got %" PRIu32 "",
|
2016-09-26 13:12:37 +03:00
|
|
|
length);
|
2015-06-02 10:50:38 +03:00
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2013-03-22 01:28:55 +04:00
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT32(s, Result);
|
2015-06-02 10:50:38 +03:00
|
|
|
IFCALLRET(audin->context.OpenResult, success, &audin->context, Result);
|
2012-06-26 10:49:39 +04:00
|
|
|
|
2016-09-26 13:12:37 +03:00
|
|
|
if (success)
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "context.OpenResult failed with error %" PRIu32 "", success);
|
2015-07-30 16:49:21 +03:00
|
|
|
|
2015-06-02 10:50:38 +03:00
|
|
|
return success;
|
2012-06-26 10:49:39 +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_server_recv_data(audin_server* audin, wStream* s, UINT32 length)
|
2012-06-26 10:49:39 +04:00
|
|
|
{
|
2013-02-26 06:46:48 +04:00
|
|
|
AUDIO_FORMAT* format;
|
2021-06-16 13:58:44 +03:00
|
|
|
size_t sbytes_per_sample;
|
|
|
|
size_t sbytes_per_frame;
|
|
|
|
size_t frames;
|
2018-02-20 14:15:30 +03:00
|
|
|
wStream* out;
|
|
|
|
UINT success = ERROR_INTERNAL_ERROR;
|
2012-06-26 10:49:39 +04:00
|
|
|
|
2021-06-16 13:58:44 +03:00
|
|
|
WINPR_ASSERT(audin);
|
2012-06-28 09:16:03 +04:00
|
|
|
if (audin->context.selected_client_format < 0)
|
2015-06-02 10:50:38 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "audin->context.selected_client_format = %d",
|
2016-09-26 13:12:37 +03:00
|
|
|
audin->context.selected_client_format);
|
2015-06-02 10:50:38 +03:00
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2012-06-28 09:16:03 +04:00
|
|
|
|
2018-02-20 14:15:30 +03:00
|
|
|
out = Stream_New(NULL, 4096);
|
|
|
|
|
|
|
|
if (!out)
|
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
|
2012-06-26 10:49:39 +04:00
|
|
|
format = &audin->context.client_formats[audin->context.selected_client_format];
|
|
|
|
|
2018-02-20 14:15:30 +03:00
|
|
|
if (freerdp_dsp_decode(audin->dsp_context, format, Stream_Pointer(s), length, out))
|
2012-06-26 10:49:39 +04:00
|
|
|
{
|
2018-09-25 17:25:35 +03:00
|
|
|
AUDIO_FORMAT dformat = *format;
|
|
|
|
dformat.wFormatTag = WAVE_FORMAT_PCM;
|
|
|
|
dformat.wBitsPerSample = 16;
|
2018-02-20 14:15:30 +03:00
|
|
|
Stream_SealLength(out);
|
2018-09-25 17:25:35 +03:00
|
|
|
Stream_SetPosition(out, 0);
|
2021-06-16 13:58:44 +03:00
|
|
|
sbytes_per_sample = format->wBitsPerSample / 8UL;
|
2012-06-28 09:16:03 +04:00
|
|
|
sbytes_per_frame = format->nChannels * sbytes_per_sample;
|
2018-02-20 14:15:30 +03:00
|
|
|
frames = Stream_Length(out) / sbytes_per_frame;
|
2018-09-25 17:25:35 +03:00
|
|
|
IFCALLRET(audin->context.ReceiveSamples, success, &audin->context, &dformat, out, frames);
|
2012-06-26 10:49:39 +04:00
|
|
|
|
2018-02-20 14:15:30 +03:00
|
|
|
if (success)
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "context.ReceiveSamples failed with error %" PRIu32 "", success);
|
2012-06-26 10:49:39 +04:00
|
|
|
}
|
2018-07-19 16:54:40 +03:00
|
|
|
else
|
|
|
|
WLog_ERR(TAG, "freerdp_dsp_decode failed!");
|
2012-06-26 10:49:39 +04:00
|
|
|
|
2018-02-20 14:15:30 +03:00
|
|
|
Stream_Free(out, TRUE);
|
2016-09-26 13:12:37 +03:00
|
|
|
return success;
|
2012-06-26 10:49:39 +04:00
|
|
|
}
|
|
|
|
|
2018-03-07 14:03:10 +03:00
|
|
|
static DWORD WINAPI audin_server_thread_func(LPVOID arg)
|
2012-06-26 10:49:39 +04:00
|
|
|
{
|
2013-03-21 23:19:33 +04:00
|
|
|
wStream* s;
|
2012-06-26 10:49:39 +04:00
|
|
|
void* buffer;
|
2014-04-22 15:02:23 +04:00
|
|
|
DWORD nCount;
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE MessageId;
|
2014-04-22 15:02:23 +04:00
|
|
|
HANDLE events[8];
|
2012-10-09 10:38:39 +04:00
|
|
|
BOOL ready = FALSE;
|
2014-04-22 15:02:23 +04:00
|
|
|
HANDLE ChannelEvent;
|
2013-08-21 02:06:19 +04:00
|
|
|
DWORD BytesReturned = 0;
|
2019-11-06 17:24:51 +03:00
|
|
|
audin_server* audin = (audin_server*)arg;
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT error = CHANNEL_RC_OK;
|
2015-07-30 16:49:21 +03:00
|
|
|
DWORD status;
|
2014-04-22 15:02:23 +04:00
|
|
|
buffer = NULL;
|
|
|
|
BytesReturned = 0;
|
|
|
|
ChannelEvent = NULL;
|
2016-09-26 13:12:37 +03:00
|
|
|
|
2021-06-16 13:58:44 +03:00
|
|
|
WINPR_ASSERT(audin);
|
|
|
|
|
2016-09-26 13:12:37 +03:00
|
|
|
if (WTSVirtualChannelQuery(audin->audin_channel, WTSVirtualEventHandle, &buffer,
|
|
|
|
&BytesReturned) == TRUE)
|
2012-06-26 10:49:39 +04:00
|
|
|
{
|
2014-04-22 15:02:23 +04:00
|
|
|
if (BytesReturned == sizeof(HANDLE))
|
|
|
|
CopyMemory(&ChannelEvent, buffer, sizeof(HANDLE));
|
2012-11-27 05:15:48 +04:00
|
|
|
|
2014-04-22 15:02:23 +04:00
|
|
|
WTSFreeMemory(buffer);
|
2012-06-26 10:49:39 +04:00
|
|
|
}
|
2015-06-02 10:50:38 +03:00
|
|
|
else
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "WTSVirtualChannelQuery failed");
|
|
|
|
error = ERROR_INTERNAL_ERROR;
|
|
|
|
goto out;
|
|
|
|
}
|
2012-06-26 10:49:39 +04:00
|
|
|
|
2014-04-22 15:02:23 +04:00
|
|
|
nCount = 0;
|
|
|
|
events[nCount++] = audin->stopEvent;
|
|
|
|
events[nCount++] = ChannelEvent;
|
|
|
|
|
2012-06-26 10:49:39 +04:00
|
|
|
/* Wait for the client to confirm that the Audio Input dynamic channel is ready */
|
2013-03-22 01:28:55 +04:00
|
|
|
|
2012-06-26 10:49:39 +04:00
|
|
|
while (1)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
if ((status = WaitForMultipleObjects(nCount, events, FALSE, 100)) == WAIT_OBJECT_0)
|
2015-06-02 10:50:38 +03:00
|
|
|
goto out;
|
2012-06-26 10:49:39 +04:00
|
|
|
|
2015-07-30 16:49:21 +03:00
|
|
|
if (status == WAIT_FAILED)
|
|
|
|
{
|
2016-09-26 13:12:37 +03:00
|
|
|
error = GetLastError();
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "WaitForMultipleObjects failed with error %" PRIu32 "", error);
|
2015-07-30 16:49:21 +03:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (WTSVirtualChannelQuery(audin->audin_channel, WTSVirtualChannelReady, &buffer,
|
|
|
|
&BytesReturned) == FALSE)
|
2015-06-02 10:50:38 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "WTSVirtualChannelQuery failed");
|
|
|
|
error = ERROR_INTERNAL_ERROR;
|
|
|
|
goto out;
|
|
|
|
}
|
2012-11-27 05:15:48 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
ready = *((BOOL*)buffer);
|
2012-06-26 10:49:39 +04:00
|
|
|
WTSFreeMemory(buffer);
|
2012-11-27 05:15:48 +04:00
|
|
|
|
2012-06-26 10:49:39 +04:00
|
|
|
if (ready)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-05-09 01:48:30 +04:00
|
|
|
s = Stream_New(NULL, 4096);
|
2016-09-26 13:12:37 +03:00
|
|
|
|
2014-04-29 12:32:16 +04:00
|
|
|
if (!s)
|
2015-06-02 10:50:38 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Stream_New failed!");
|
|
|
|
error = CHANNEL_RC_NO_MEMORY;
|
2014-04-29 12:32:16 +04:00
|
|
|
goto out;
|
2015-06-02 10:50:38 +03:00
|
|
|
}
|
|
|
|
|
2012-06-26 10:49:39 +04:00
|
|
|
if (ready)
|
|
|
|
{
|
2015-06-02 10:50:38 +03:00
|
|
|
if ((error = audin_server_send_version(audin, s)))
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "audin_server_send_version failed with error %" PRIu32 "!", error);
|
2015-06-02 10:50:38 +03:00
|
|
|
goto out_capacity;
|
|
|
|
}
|
2012-06-26 10:49:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
while (ready)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
if ((status = WaitForMultipleObjects(nCount, events, FALSE, INFINITE)) == WAIT_OBJECT_0)
|
2012-06-26 10:49:39 +04:00
|
|
|
break;
|
|
|
|
|
2015-07-30 16:49:21 +03:00
|
|
|
if (status == WAIT_FAILED)
|
|
|
|
{
|
2016-09-26 13:12:37 +03:00
|
|
|
error = GetLastError();
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "WaitForMultipleObjects failed with error %" PRIu32 "", error);
|
2016-09-26 13:12:37 +03:00
|
|
|
goto out;
|
2015-07-30 16:49:21 +03:00
|
|
|
}
|
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_SetPosition(s, 0);
|
2012-08-15 02:39:07 +04:00
|
|
|
|
2015-06-02 10:50:38 +03:00
|
|
|
if (!WTSVirtualChannelRead(audin->audin_channel, 0, NULL, 0, &BytesReturned))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "WTSVirtualChannelRead failed!");
|
|
|
|
error = ERROR_INTERNAL_ERROR;
|
|
|
|
break;
|
|
|
|
}
|
2016-09-26 13:12:37 +03:00
|
|
|
|
2014-07-14 16:00:38 +04:00
|
|
|
if (BytesReturned < 1)
|
|
|
|
continue;
|
2016-09-26 13:12:37 +03:00
|
|
|
|
2015-03-26 19:09:47 +03:00
|
|
|
if (!Stream_EnsureRemainingCapacity(s, BytesReturned))
|
2015-06-02 10:50:38 +03:00
|
|
|
break;
|
2016-09-26 13:12:37 +03:00
|
|
|
|
2021-06-16 13:58:44 +03:00
|
|
|
WINPR_ASSERT(Stream_Capacity(s) <= ULONG_MAX);
|
2019-11-06 17:24:51 +03:00
|
|
|
if (WTSVirtualChannelRead(audin->audin_channel, 0, (PCHAR)Stream_Buffer(s),
|
2021-06-16 13:58:44 +03:00
|
|
|
(ULONG)Stream_Capacity(s), &BytesReturned) == FALSE)
|
2012-06-26 10:49:39 +04:00
|
|
|
{
|
2015-06-02 10:50:38 +03:00
|
|
|
WLog_ERR(TAG, "WTSVirtualChannelRead failed!");
|
|
|
|
error = ERROR_INTERNAL_ERROR;
|
2014-07-14 16:00:38 +04:00
|
|
|
break;
|
2012-06-26 10:49:39 +04:00
|
|
|
}
|
2013-03-22 01:28:55 +04:00
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT8(s, MessageId);
|
2013-08-21 02:06:19 +04:00
|
|
|
BytesReturned--;
|
2013-03-22 01:28:55 +04:00
|
|
|
|
2012-06-26 10:49:39 +04:00
|
|
|
switch (MessageId)
|
|
|
|
{
|
|
|
|
case MSG_SNDIN_VERSION:
|
2015-06-02 10:50:38 +03:00
|
|
|
if ((error = audin_server_recv_version(audin, s, BytesReturned)))
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "audin_server_recv_version failed with error %" PRIu32 "!",
|
|
|
|
error);
|
2016-09-26 13:12:37 +03:00
|
|
|
goto out_capacity;
|
|
|
|
}
|
|
|
|
|
2015-06-02 10:50:38 +03:00
|
|
|
if ((error = audin_server_send_formats(audin, s)))
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "audin_server_send_formats failed with error %" PRIu32 "!",
|
|
|
|
error);
|
2015-06-02 10:50:38 +03:00
|
|
|
goto out_capacity;
|
|
|
|
}
|
2016-09-26 13:12:37 +03:00
|
|
|
|
2012-06-26 10:49:39 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MSG_SNDIN_FORMATS:
|
2015-06-02 10:50:38 +03:00
|
|
|
if ((error = audin_server_recv_formats(audin, s, BytesReturned)))
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "audin_server_recv_formats failed with error %" PRIu32 "!",
|
|
|
|
error);
|
2015-07-22 12:36:24 +03:00
|
|
|
goto out_capacity;
|
|
|
|
}
|
2016-09-26 13:12:37 +03:00
|
|
|
|
2015-06-02 10:50:38 +03:00
|
|
|
if ((error = audin_server_send_open(audin, s)))
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "audin_server_send_open failed with error %" PRIu32 "!", error);
|
2015-06-02 10:50:38 +03:00
|
|
|
goto out_capacity;
|
|
|
|
}
|
2016-09-26 13:12:37 +03:00
|
|
|
|
2012-06-26 10:49:39 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MSG_SNDIN_OPEN_REPLY:
|
2015-06-02 10:50:38 +03:00
|
|
|
if ((error = audin_server_recv_open_reply(audin, s, BytesReturned)))
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "audin_server_recv_open_reply failed with error %" PRIu32 "!",
|
|
|
|
error);
|
2015-06-02 10:50:38 +03:00
|
|
|
goto out_capacity;
|
|
|
|
}
|
2016-09-26 13:12:37 +03:00
|
|
|
|
2012-06-26 10:49:39 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MSG_SNDIN_DATA_INCOMING:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MSG_SNDIN_DATA:
|
2015-06-02 10:50:38 +03:00
|
|
|
if ((error = audin_server_recv_data(audin, s, BytesReturned)))
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "audin_server_recv_data failed with error %" PRIu32 "!", error);
|
2015-06-02 10:50:38 +03:00
|
|
|
goto out_capacity;
|
2021-06-18 11:00:01 +03:00
|
|
|
}
|
2016-09-26 13:12:37 +03:00
|
|
|
|
2012-06-26 10:49:39 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MSG_SNDIN_FORMATCHANGE:
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "audin_server_thread_func: unknown MessageId %" PRIu8 "", MessageId);
|
2012-06-26 10:49:39 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-26 19:09:47 +03:00
|
|
|
out_capacity:
|
2013-05-09 01:48:30 +04:00
|
|
|
Stream_Free(s, TRUE);
|
2014-04-29 12:32:16 +04:00
|
|
|
out:
|
2012-06-26 10:49:39 +04:00
|
|
|
WTSVirtualChannelClose(audin->audin_channel);
|
|
|
|
audin->audin_channel = NULL;
|
2016-09-26 13:12:37 +03:00
|
|
|
|
2015-07-15 10:50:35 +03:00
|
|
|
if (error && audin->context.rdpcontext)
|
2016-09-26 13:12:37 +03:00
|
|
|
setChannelError(audin->context.rdpcontext, error,
|
|
|
|
"audin_server_thread_func reported an error");
|
2015-07-15 10:50:35 +03:00
|
|
|
|
2018-03-07 14:03:10 +03:00
|
|
|
ExitThread(error);
|
|
|
|
return error;
|
2012-06-26 10:49:39 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 10:38:39 +04:00
|
|
|
static BOOL audin_server_open(audin_server_context* context)
|
2012-06-26 10:49:39 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
audin_server* audin = (audin_server*)context;
|
2012-06-26 10:49:39 +04:00
|
|
|
|
2021-06-16 13:58:44 +03:00
|
|
|
WINPR_ASSERT(audin);
|
2013-03-22 01:28:55 +04:00
|
|
|
if (!audin->thread)
|
2012-06-26 10:49:39 +04:00
|
|
|
{
|
2014-02-17 08:00:58 +04:00
|
|
|
PULONG pSessionId = NULL;
|
|
|
|
DWORD BytesReturned = 0;
|
|
|
|
audin->SessionId = WTS_CURRENT_SESSION;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (WTSQuerySessionInformationA(context->vcm, WTS_CURRENT_SESSION, WTSSessionId,
|
|
|
|
(LPSTR*)&pSessionId, &BytesReturned))
|
2014-02-17 08:00:58 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
audin->SessionId = (DWORD)*pSessionId;
|
2014-02-17 08:00:58 +04:00
|
|
|
WTSFreeMemory(pSessionId);
|
|
|
|
}
|
|
|
|
|
2020-08-10 16:36:31 +03:00
|
|
|
audin->audin_channel = WTSVirtualChannelOpenEx(audin->SessionId, AUDIN_DVC_CHANNEL_NAME,
|
|
|
|
WTS_CHANNEL_OPTION_DYNAMIC);
|
2012-10-09 00:29:40 +04:00
|
|
|
|
2013-03-22 01:28:55 +04:00
|
|
|
if (!audin->audin_channel)
|
2015-06-02 10:50:38 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "WTSVirtualChannelOpenEx failed!");
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2015-06-02 10:50:38 +03:00
|
|
|
}
|
2012-06-26 10:49:39 +04:00
|
|
|
|
2015-06-02 10:50:38 +03:00
|
|
|
if (!(audin->stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL)))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "CreateEvent failed!");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2013-03-22 01:28:55 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!(audin->thread =
|
|
|
|
CreateThread(NULL, 0, audin_server_thread_func, (void*)audin, 0, NULL)))
|
2015-06-02 10:50:38 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "CreateThread failed!");
|
|
|
|
CloseHandle(audin->stopEvent);
|
|
|
|
audin->stopEvent = NULL;
|
|
|
|
return FALSE;
|
|
|
|
}
|
2012-06-26 10:49:39 +04:00
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2012-06-26 10:49:39 +04:00
|
|
|
}
|
2016-09-26 13:12:37 +03:00
|
|
|
|
2015-06-02 10:50:38 +03:00
|
|
|
WLog_ERR(TAG, "thread already running!");
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2012-06-26 10:49:39 +04:00
|
|
|
}
|
|
|
|
|
2018-09-25 12:13:32 +03:00
|
|
|
static BOOL audin_server_is_open(audin_server_context* context)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
audin_server* audin = (audin_server*)context;
|
2018-09-25 12:13:32 +03:00
|
|
|
|
2021-06-16 13:58:44 +03:00
|
|
|
WINPR_ASSERT(audin);
|
2018-09-25 12:13:32 +03:00
|
|
|
return audin->thread != NULL;
|
|
|
|
}
|
|
|
|
|
2012-10-09 10:38:39 +04:00
|
|
|
static BOOL audin_server_close(audin_server_context* context)
|
2012-06-26 10:49:39 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
audin_server* audin = (audin_server*)context;
|
2021-06-16 13:58:44 +03:00
|
|
|
WINPR_ASSERT(audin);
|
2012-06-26 10:49:39 +04:00
|
|
|
|
2013-03-22 01:28:55 +04:00
|
|
|
if (audin->thread)
|
2012-06-26 10:49:39 +04:00
|
|
|
{
|
2013-03-22 01:28:55 +04:00
|
|
|
SetEvent(audin->stopEvent);
|
2016-09-26 13:12:37 +03:00
|
|
|
|
2015-07-30 16:49:21 +03:00
|
|
|
if (WaitForSingleObject(audin->thread, INFINITE) == WAIT_FAILED)
|
2016-09-26 13:12:37 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "WaitForSingleObject failed with error %" PRIu32 "", GetLastError());
|
2016-09-26 13:12:37 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
2015-07-30 16:49:21 +03:00
|
|
|
|
2013-03-22 01:40:04 +04:00
|
|
|
CloseHandle(audin->thread);
|
2013-09-05 15:38:35 +04:00
|
|
|
CloseHandle(audin->stopEvent);
|
2013-03-22 01:28:55 +04:00
|
|
|
audin->thread = NULL;
|
2013-09-05 15:38:35 +04:00
|
|
|
audin->stopEvent = NULL;
|
2012-06-26 10:49:39 +04:00
|
|
|
}
|
2013-03-22 01:28:55 +04:00
|
|
|
|
2012-06-26 10:49:39 +04:00
|
|
|
if (audin->audin_channel)
|
|
|
|
{
|
|
|
|
WTSVirtualChannelClose(audin->audin_channel);
|
|
|
|
audin->audin_channel = NULL;
|
|
|
|
}
|
2013-03-22 01:28:55 +04:00
|
|
|
|
2012-06-26 10:49:39 +04:00
|
|
|
audin->context.selected_client_format = -1;
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2012-06-26 10:49:39 +04:00
|
|
|
}
|
|
|
|
|
2014-02-27 22:30:04 +04:00
|
|
|
audin_server_context* audin_server_context_new(HANDLE vcm)
|
2012-06-26 10:49:39 +04:00
|
|
|
{
|
|
|
|
audin_server* audin;
|
2016-09-26 13:12:37 +03:00
|
|
|
audin = (audin_server*)calloc(1, sizeof(audin_server));
|
2012-06-26 10:49:39 +04:00
|
|
|
|
2015-06-02 10:50:38 +03:00
|
|
|
if (!audin)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "calloc failed!");
|
|
|
|
return NULL;
|
|
|
|
}
|
2012-11-20 08:49:08 +04:00
|
|
|
|
2012-06-26 10:49:39 +04:00
|
|
|
audin->context.vcm = vcm;
|
|
|
|
audin->context.selected_client_format = -1;
|
|
|
|
audin->context.frames_per_packet = 4096;
|
|
|
|
audin->context.SelectFormat = audin_server_select_format;
|
|
|
|
audin->context.Open = audin_server_open;
|
2018-09-25 12:13:32 +03:00
|
|
|
audin->context.IsOpen = audin_server_is_open;
|
2012-06-26 10:49:39 +04:00
|
|
|
audin->context.Close = audin_server_close;
|
2018-02-20 14:15:30 +03:00
|
|
|
audin->dsp_context = freerdp_dsp_context_new(FALSE);
|
2012-06-26 10:49:39 +04:00
|
|
|
|
2015-06-02 10:50:38 +03:00
|
|
|
if (!audin->dsp_context)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "freerdp_dsp_context_new failed!");
|
|
|
|
free(audin);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
return (audin_server_context*)audin;
|
2012-06-26 10:49:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void audin_server_context_free(audin_server_context* context)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
audin_server* audin = (audin_server*)context;
|
2012-11-20 08:49:08 +04:00
|
|
|
|
2018-09-25 13:04:10 +03:00
|
|
|
if (!audin)
|
|
|
|
return;
|
2012-11-20 08:49:08 +04:00
|
|
|
|
2018-09-25 13:04:10 +03:00
|
|
|
audin_server_close(context);
|
|
|
|
freerdp_dsp_context_free(audin->dsp_context);
|
|
|
|
audio_formats_free(audin->context.client_formats, audin->context.num_client_formats);
|
|
|
|
audio_formats_free(audin->context.server_formats, audin->context.num_server_formats);
|
2012-10-09 07:21:26 +04:00
|
|
|
free(audin);
|
2012-06-26 10:49:39 +04:00
|
|
|
}
|