Blame server/shadow/shadow_audin.c

Packit Service fa4841
/**
Packit Service fa4841
 * FreeRDP: A Remote Desktop Protocol Implementation
Packit Service fa4841
 *
Packit Service fa4841
 * Copyright 2015 Jiang Zihao <zihao.jiang@yahoo.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 <freerdp/log.h>
Packit Service fa4841
#include <freerdp/codec/dsp.h>
Packit Service fa4841
#include "shadow.h"
Packit Service fa4841
Packit Service fa4841
#include "shadow_audin.h"
Packit Service fa4841
#include <freerdp/server/server-common.h>
Packit Service fa4841
Packit Service fa4841
#define TAG SERVER_TAG("shadow")
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 AudinServerOpening(audin_server_context* context)
Packit Service fa4841
{
Packit Service fa4841
	AUDIO_FORMAT* agreed_format = NULL;
Packit Service fa4841
	size_t i = 0, j = 0;
Packit Service fa4841
Packit Service fa4841
	for (i = 0; i < context->num_client_formats; i++)
Packit Service fa4841
	{
Packit Service fa4841
		for (j = 0; j < context->num_server_formats; j++)
Packit Service fa4841
		{
Packit Service fa4841
			if (audio_format_compatible(&context->server_formats[j], &context->client_formats[i]))
Packit Service fa4841
			{
Packit Service fa4841
				agreed_format = &context->server_formats[j];
Packit Service fa4841
				break;
Packit Service fa4841
			}
Packit Service fa4841
		}
Packit Service fa4841
Packit Service fa4841
		if (agreed_format != NULL)
Packit Service fa4841
			break;
Packit Service fa4841
	}
Packit Service fa4841
Packit Service fa4841
	if (agreed_format == NULL)
Packit Service fa4841
	{
Packit Service fa4841
		WLog_ERR(TAG, "Could not agree on a audio format with the server\n");
Packit Service fa4841
		return CHANNEL_RC_OK;
Packit Service fa4841
	}
Packit Service fa4841
Packit Service fa4841
	return IFCALLRESULT(ERROR_CALL_NOT_IMPLEMENTED, context->SelectFormat, context, i);
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 AudinServerOpenResult(audin_server_context* context, UINT32 result)
Packit Service fa4841
{
Packit Service fa4841
	/* TODO: Implement */
Packit Service fa4841
	WLog_WARN(TAG, "%s not implemented", __FUNCTION__);
Packit Service fa4841
	WLog_INFO(TAG, "AUDIN open result %" PRIu32 ".\n", result);
Packit Service fa4841
	return CHANNEL_RC_OK;
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 AudinServerReceiveSamples(audin_server_context* context, const AUDIO_FORMAT* format,
Packit Service fa4841
                                      wStream* buf, size_t nframes)
Packit Service fa4841
{
Packit Service fa4841
	rdpShadowClient* client = (rdpShadowClient*)context->data;
Packit Service fa4841
	rdpShadowSubsystem* subsystem = client->server->subsystem;
Packit Service fa4841
Packit Service fa4841
	if (!client->mayInteract)
Packit Service fa4841
		return CHANNEL_RC_OK;
Packit Service fa4841
Packit Service fa4841
	if (!IFCALLRESULT(TRUE, subsystem->AudinServerReceiveSamples, subsystem, client, format, buf,
Packit Service fa4841
	                  nframes))
Packit Service fa4841
		return ERROR_INTERNAL_ERROR;
Packit Service fa4841
Packit Service fa4841
	return CHANNEL_RC_OK;
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
BOOL shadow_client_audin_init(rdpShadowClient* client)
Packit Service fa4841
{
Packit Service fa4841
	audin_server_context* audin;
Packit Service fa4841
	audin = client->audin = audin_server_context_new(client->vcm);
Packit Service fa4841
Packit Service fa4841
	if (!audin)
Packit Service fa4841
		return FALSE;
Packit Service fa4841
Packit Service fa4841
	audin->data = client;
Packit Service fa4841
Packit Service fa4841
	if (client->subsystem->audinFormats)
Packit Service fa4841
	{
Packit Service fa4841
		size_t x;
Packit Service fa4841
		audin->server_formats = audio_formats_new(client->subsystem->nAudinFormats);
Packit Service fa4841
Packit Service fa4841
		if (!audin->server_formats)
Packit Service fa4841
			goto fail;
Packit Service fa4841
Packit Service fa4841
		for (x = 0; x < client->subsystem->nAudinFormats; x++)
Packit Service fa4841
		{
Packit Service fa4841
			if (!audio_format_copy(&client->subsystem->audinFormats[x], &audin->server_formats[x]))
Packit Service fa4841
				goto fail;
Packit Service fa4841
		}
Packit Service fa4841
Packit Service fa4841
		audin->num_server_formats = client->subsystem->nAudinFormats;
Packit Service fa4841
	}
Packit Service fa4841
	else
Packit Service fa4841
	{
Packit Service fa4841
		audin->num_server_formats = server_audin_get_formats(&audin->server_formats);
Packit Service fa4841
	}
Packit Service fa4841
Packit Service fa4841
	if (audin->num_server_formats < 1)
Packit Service fa4841
		goto fail;
Packit Service fa4841
Packit Service fa4841
	audin->dst_format = &audin->server_formats[0];
Packit Service fa4841
	audin->Opening = AudinServerOpening;
Packit Service fa4841
	audin->OpenResult = AudinServerOpenResult;
Packit Service fa4841
	audin->ReceiveSamples = AudinServerReceiveSamples;
Packit Service fa4841
	return TRUE;
Packit Service fa4841
fail:
Packit Service fa4841
	audin_server_context_free(audin);
Packit Service fa4841
	client->audin = NULL;
Packit Service fa4841
	return FALSE;
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
void shadow_client_audin_uninit(rdpShadowClient* client)
Packit Service fa4841
{
Packit Service fa4841
	if (client->audin)
Packit Service fa4841
	{
Packit Service fa4841
		audin_server_context_free(client->audin);
Packit Service fa4841
		client->audin = NULL;
Packit Service fa4841
	}
Packit Service fa4841
}