Blame channels/rdpsnd/client/proxy/rdpsnd_proxy.c

Packit Service fa4841
/**
Packit Service fa4841
 * FreeRDP: A Remote Desktop Protocol Implementation
Packit Service fa4841
 * FreeRDP rdpsnd proxy subsystem
Packit Service fa4841
 *
Packit Service fa4841
 * Copyright 2019 Kobi Mizrachi <kmizrachi18@gmail.com>
Packit Service fa4841
 *
Packit Service fa4841
 * Licensed under the Apache License, Version 2.0 (the "License");
Packit Service fa4841
 * you may not use this file except in compliance with the License.
Packit Service fa4841
 * You may obtain a copy of the License at
Packit Service fa4841
 *
Packit Service fa4841
 *     http://www.apache.org/licenses/LICENSE-2.0
Packit Service fa4841
 *
Packit Service fa4841
 * Unless required by applicable law or agreed to in writing, software
Packit Service fa4841
 * distributed under the License is distributed on an "AS IS" BASIS,
Packit Service fa4841
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Packit Service fa4841
 * See the License for the specific language governing permissions and
Packit Service fa4841
 * limitations under the License.
Packit Service fa4841
 */
Packit Service fa4841
Packit Service fa4841
#ifdef HAVE_CONFIG_H
Packit Service fa4841
#include "config.h"
Packit Service fa4841
#endif
Packit Service fa4841
Packit Service fa4841
#include <stdio.h>
Packit Service fa4841
#include <stdlib.h>
Packit Service fa4841
#include <string.h>
Packit Service fa4841
Packit Service fa4841
#include <winpr/crt.h>
Packit Service fa4841
#include <winpr/stream.h>
Packit Service fa4841
#include <winpr/cmdline.h>
Packit Service fa4841
#include <winpr/sysinfo.h>
Packit Service fa4841
#include <freerdp/types.h>
Packit Service fa4841
#include <freerdp/server/rdpsnd.h>
Packit Service fa4841
#include <freerdp/client/rdpsnd.h>
Packit Service fa4841
Packit Service fa4841
#include "rdpsnd_main.h"
Packit Service fa4841
#include "../../../../server/proxy/pf_context.h"
Packit Service fa4841
Packit Service fa4841
typedef struct rdpsnd_proxy_plugin rdpsndProxyPlugin;
Packit Service fa4841
Packit Service fa4841
struct rdpsnd_proxy_plugin
Packit Service fa4841
{
Packit Service fa4841
	rdpsndDevicePlugin device;
Packit Service fa4841
	RdpsndServerContext* rdpsnd_server;
Packit Service fa4841
};
Packit Service fa4841
Packit Service fa4841
static BOOL rdpsnd_proxy_open(rdpsndDevicePlugin* device, const AUDIO_FORMAT* format,
Packit Service fa4841
                              UINT32 latency)
Packit Service fa4841
{
Packit Service fa4841
	rdpsndProxyPlugin* proxy = (rdpsndProxyPlugin*)device;
Packit Service fa4841
Packit Service fa4841
	/* update proxy's rdpsnd server latency */
Packit Service fa4841
	proxy->rdpsnd_server->latency = latency;
Packit Service fa4841
	return TRUE;
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
static void rdpsnd_proxy_close(rdpsndDevicePlugin* device)
Packit Service fa4841
{
Packit Service fa4841
	/* do nothing */
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
static BOOL rdpsnd_proxy_set_volume(rdpsndDevicePlugin* device, UINT32 value)
Packit Service fa4841
{
Packit Service fa4841
	rdpsndProxyPlugin* proxy = (rdpsndProxyPlugin*)device;
Packit Service fa4841
	proxy->rdpsnd_server->SetVolume(proxy->rdpsnd_server, value, value);
Packit Service fa4841
	return TRUE;
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
static void rdpsnd_proxy_free(rdpsndDevicePlugin* device)
Packit Service fa4841
{
Packit Service fa4841
	rdpsndProxyPlugin* proxy = (rdpsndProxyPlugin*)device;
Packit Service fa4841
Packit Service fa4841
	if (!proxy)
Packit Service fa4841
		return;
Packit Service fa4841
Packit Service fa4841
	free(proxy);
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
static BOOL rdpsnd_proxy_format_supported(rdpsndDevicePlugin* device, const AUDIO_FORMAT* format)
Packit Service fa4841
{
Packit Service fa4841
	rdpsndProxyPlugin* proxy = (rdpsndProxyPlugin*)device;
Packit Service fa4841
Packit Service fa4841
	/* use the same format that proxy's server used */
Packit Service fa4841
	if (proxy->rdpsnd_server->selected_client_format == format->wFormatTag)
Packit Service fa4841
		return TRUE;
Packit Service fa4841
Packit Service fa4841
	return FALSE;
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
static UINT rdpsnd_proxy_play(rdpsndDevicePlugin* device, const BYTE* data, size_t size)
Packit Service fa4841
{
Packit Service fa4841
	rdpsndProxyPlugin* proxy = (rdpsndProxyPlugin*)device;
Packit Service fa4841
	UINT64 start = GetTickCount();
Packit Service fa4841
	proxy->rdpsnd_server->SendSamples(proxy->rdpsnd_server, data, size / 4, start);
Packit Service fa4841
	return GetTickCount() - start;
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
Packit Service fa4841
/**
Packit Service fa4841
 * Function description
Packit Service fa4841
 *
Packit Service fa4841
 * @return 0 on success, otherwise a Win32 error code
Packit Service fa4841
 */
Packit Service fa4841
Packit Service fa4841
#ifdef BUILTIN_CHANNELS
Packit Service fa4841
#define freerdp_rdpsnd_client_subsystem_entry proxy_freerdp_rdpsnd_client_subsystem_entry
Packit Service fa4841
#else
Packit Service fa4841
#define freerdp_rdpsnd_client_subsystem_entry FREERDP_API freerdp_rdpsnd_client_subsystem_entry
Packit Service fa4841
#endif
Packit Service fa4841
Packit Service fa4841
/**
Packit Service fa4841
 * Function description
Packit Service fa4841
 *
Packit Service fa4841
 * @return 0 on success, otherwise a Win32 error code
Packit Service fa4841
 */
Packit Service fa4841
UINT freerdp_rdpsnd_client_subsystem_entry(PFREERDP_RDPSND_DEVICE_ENTRY_POINTS pEntryPoints)
Packit Service fa4841
{
Packit Service fa4841
	ADDIN_ARGV* args;
Packit Service fa4841
	rdpsndProxyPlugin* proxy;
Packit Service fa4841
	pClientContext* pc;
Packit Service fa4841
	proxy = (rdpsndProxyPlugin*)calloc(1, sizeof(rdpsndProxyPlugin));
Packit Service fa4841
Packit Service fa4841
	if (!proxy)
Packit Service fa4841
		return CHANNEL_RC_NO_MEMORY;
Packit Service fa4841
Packit Service fa4841
	proxy->device.Open = rdpsnd_proxy_open;
Packit Service fa4841
	proxy->device.FormatSupported = rdpsnd_proxy_format_supported;
Packit Service fa4841
	proxy->device.SetVolume = rdpsnd_proxy_set_volume;
Packit Service fa4841
	proxy->device.Play = rdpsnd_proxy_play;
Packit Service fa4841
	proxy->device.Close = rdpsnd_proxy_close;
Packit Service fa4841
	proxy->device.Free = rdpsnd_proxy_free;
Packit Service fa4841
	args = pEntryPoints->args;
Packit Service fa4841
Packit Service fa4841
	pEntryPoints->pRegisterRdpsndDevice(pEntryPoints->rdpsnd, &proxy->device);
Packit Service fa4841
	pc = (pClientContext*)freerdp_rdpsnd_get_context(pEntryPoints->rdpsnd);
Packit Service fa4841
	if (pc == NULL)
Packit Service fa4841
	{
Packit Service fa4841
		free(proxy);
Packit Service fa4841
		return ERROR_INTERNAL_ERROR;
Packit Service fa4841
	}
Packit Service fa4841
Packit Service fa4841
	proxy->rdpsnd_server = pc->pdata->ps->rdpsnd;
Packit Service fa4841
	return CHANNEL_RC_OK;
Packit Service fa4841
}