Blame channels/rdpsnd/client/fake/rdpsnd_fake.c

Packit Service fa4841
/**
Packit Service fa4841
 * FreeRDP: A Remote Desktop Protocol Implementation
Packit Service fa4841
 * Audio Output Virtual Channel
Packit Service fa4841
 *
Packit Service fa4841
 * Copyright 2019 Armin Novak <armin.novak@thincast.com>
Packit Service fa4841
 * Copyright 2019 Thincast Technologies GmbH
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
Packit Service fa4841
#include <freerdp/types.h>
Packit Service fa4841
Packit Service fa4841
#include "rdpsnd_main.h"
Packit Service fa4841
Packit Service fa4841
typedef struct rdpsnd_fake_plugin rdpsndFakePlugin;
Packit Service fa4841
Packit Service fa4841
struct rdpsnd_fake_plugin
Packit Service fa4841
{
Packit Service fa4841
	rdpsndDevicePlugin device;
Packit Service fa4841
};
Packit Service fa4841
Packit Service fa4841
static BOOL rdpsnd_fake_open(rdpsndDevicePlugin* device, const AUDIO_FORMAT* format, UINT32 latency)
Packit Service fa4841
{
Packit Service fa4841
	return TRUE;
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
static void rdpsnd_fake_close(rdpsndDevicePlugin* device)
Packit Service fa4841
{
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
static BOOL rdpsnd_fake_set_volume(rdpsndDevicePlugin* device, UINT32 value)
Packit Service fa4841
{
Packit Service fa4841
	return TRUE;
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
static void rdpsnd_fake_free(rdpsndDevicePlugin* device)
Packit Service fa4841
{
Packit Service fa4841
	rdpsndFakePlugin* fake = (rdpsndFakePlugin*)device;
Packit Service fa4841
Packit Service fa4841
	if (!fake)
Packit Service fa4841
		return;
Packit Service fa4841
Packit Service fa4841
	free(fake);
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
static BOOL rdpsnd_fake_format_supported(rdpsndDevicePlugin* device, const AUDIO_FORMAT* format)
Packit Service fa4841
{
Packit Service fa4841
	return TRUE;
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
static UINT rdpsnd_fake_play(rdpsndDevicePlugin* device, const BYTE* data, size_t size)
Packit Service fa4841
{
Packit Service fa4841
	return CHANNEL_RC_OK;
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
static UINT rdpsnd_fake_parse_addin_args(rdpsndFakePlugin* fake, ADDIN_ARGV* args)
Packit Service fa4841
{
Packit Service fa4841
	int status;
Packit Service fa4841
	DWORD flags;
Packit Service fa4841
	COMMAND_LINE_ARGUMENT_A* arg;
Packit Service fa4841
	COMMAND_LINE_ARGUMENT_A rdpsnd_fake_args[] = { { NULL, 0, NULL, NULL, NULL, -1, NULL, NULL } };
Packit Service fa4841
	flags =
Packit Service fa4841
	    COMMAND_LINE_SIGIL_NONE | COMMAND_LINE_SEPARATOR_COLON | COMMAND_LINE_IGN_UNKNOWN_KEYWORD;
Packit Service fa4841
	status = CommandLineParseArgumentsA(args->argc, args->argv, rdpsnd_fake_args, flags, fake, NULL,
Packit Service fa4841
	                                    NULL);
Packit Service fa4841
Packit Service fa4841
	if (status < 0)
Packit Service fa4841
		return ERROR_INVALID_DATA;
Packit Service fa4841
Packit Service fa4841
	arg = rdpsnd_fake_args;
Packit Service fa4841
Packit Service fa4841
	do
Packit Service fa4841
	{
Packit Service fa4841
		if (!(arg->Flags & COMMAND_LINE_VALUE_PRESENT))
Packit Service fa4841
			continue;
Packit Service fa4841
Packit Service fa4841
		CommandLineSwitchStart(arg) CommandLineSwitchEnd(arg)
Packit Service fa4841
	} while ((arg = CommandLineFindNextArgumentA(arg)) != NULL);
Packit Service fa4841
Packit Service fa4841
	return CHANNEL_RC_OK;
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
#ifdef BUILTIN_CHANNELS
Packit Service fa4841
#define freerdp_rdpsnd_client_subsystem_entry fake_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
	rdpsndFakePlugin* fake;
Packit Service fa4841
	UINT ret = CHANNEL_RC_OK;
Packit Service fa4841
	fake = (rdpsndFakePlugin*)calloc(1, sizeof(rdpsndFakePlugin));
Packit Service fa4841
Packit Service fa4841
	if (!fake)
Packit Service fa4841
		return CHANNEL_RC_NO_MEMORY;
Packit Service fa4841
Packit Service fa4841
	fake->device.Open = rdpsnd_fake_open;
Packit Service fa4841
	fake->device.FormatSupported = rdpsnd_fake_format_supported;
Packit Service fa4841
	fake->device.SetVolume = rdpsnd_fake_set_volume;
Packit Service fa4841
	fake->device.Play = rdpsnd_fake_play;
Packit Service fa4841
	fake->device.Close = rdpsnd_fake_close;
Packit Service fa4841
	fake->device.Free = rdpsnd_fake_free;
Packit Service fa4841
	args = pEntryPoints->args;
Packit Service fa4841
Packit Service fa4841
	if (args->argc > 1)
Packit Service fa4841
	{
Packit Service fa4841
		ret = rdpsnd_fake_parse_addin_args(fake, args);
Packit Service fa4841
Packit Service fa4841
		if (ret != CHANNEL_RC_OK)
Packit Service fa4841
		{
Packit Service fa4841
			WLog_ERR(TAG, "error parsing arguments");
Packit Service fa4841
			goto error;
Packit Service fa4841
		}
Packit Service fa4841
	}
Packit Service fa4841
Packit Service fa4841
	pEntryPoints->pRegisterRdpsndDevice(pEntryPoints->rdpsnd, &fake->device);
Packit Service fa4841
	return ret;
Packit Service fa4841
error:
Packit Service fa4841
	rdpsnd_fake_free(&fake->device);
Packit Service fa4841
	return ret;
Packit Service fa4841
}