Blame server/shadow/shadow_rdpsnd.c

Packit 1fb8d4
/**
Packit 1fb8d4
 * FreeRDP: A Remote Desktop Protocol Implementation
Packit 1fb8d4
 *
Packit 1fb8d4
 * Copyright 2015 Jiang Zihao <zihao.jiang@yahoo.com>
Packit 1fb8d4
 *
Packit 1fb8d4
 * Licensed under the Apache License, Version 2.0 (the "License");
Packit 1fb8d4
 * you may not use this file except in compliance with the License.
Packit 1fb8d4
 * You may obtain a copy of the License at
Packit 1fb8d4
 *
Packit 1fb8d4
 *     http://www.apache.org/licenses/LICENSE-2.0
Packit 1fb8d4
 *
Packit 1fb8d4
 * Unless required by applicable law or agreed to in writing, software
Packit 1fb8d4
 * distributed under the License is distributed on an "AS IS" BASIS,
Packit 1fb8d4
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Packit 1fb8d4
 * See the License for the specific language governing permissions and
Packit 1fb8d4
 * limitations under the License.
Packit 1fb8d4
 */
Packit 1fb8d4
Packit 1fb8d4
#ifdef HAVE_CONFIG_H
Packit 1fb8d4
#include "config.h"
Packit 1fb8d4
#endif
Packit 1fb8d4
Packit 1fb8d4
#include <winpr/crt.h>
Packit 1fb8d4
#include <freerdp/log.h>
Packit 1fb8d4
#include <freerdp/codec/dsp.h>
Packit 1fb8d4
#include <freerdp/server/server-common.h>
Packit 1fb8d4
Packit 1fb8d4
#include "shadow.h"
Packit 1fb8d4
Packit 1fb8d4
#include "shadow_rdpsnd.h"
Packit 1fb8d4
Packit 1fb8d4
#define TAG SERVER_TAG("shadow")
Packit 1fb8d4
Packit 1fb8d4
static void rdpsnd_activated(RdpsndServerContext* context)
Packit 1fb8d4
{
Packit 1fb8d4
	const AUDIO_FORMAT* agreed_format = NULL;
Packit 1fb8d4
	UINT16 i = 0, j = 0;
Packit 1fb8d4
Packit 1fb8d4
	for (i = 0; i < context->num_client_formats; i++)
Packit 1fb8d4
	{
Packit 1fb8d4
		for (j = 0; j < context->num_server_formats; j++)
Packit 1fb8d4
		{
Packit 1fb8d4
			if (audio_format_compatible(&context->server_formats[j], &context->client_formats[i]))
Packit 1fb8d4
			{
Packit 1fb8d4
				agreed_format = &context->server_formats[j];
Packit 1fb8d4
				break;
Packit 1fb8d4
			}
Packit 1fb8d4
		}
Packit 1fb8d4
Packit 1fb8d4
		if (agreed_format != NULL)
Packit 1fb8d4
			break;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	if (agreed_format == NULL)
Packit 1fb8d4
	{
Packit 1fb8d4
		WLog_ERR(TAG, "Could not agree on a audio format with the server\n");
Packit 1fb8d4
		return;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	context->SelectFormat(context, i);
Packit 1fb8d4
}
Packit 1fb8d4
Packit 1fb8d4
int shadow_client_rdpsnd_init(rdpShadowClient* client)
Packit 1fb8d4
{
Packit 1fb8d4
	RdpsndServerContext* rdpsnd;
Packit 1fb8d4
	rdpsnd = client->rdpsnd = rdpsnd_server_context_new(client->vcm);
Packit 1fb8d4
Packit 1fb8d4
	if (!rdpsnd)
Packit 1fb8d4
	{
Packit 1fb8d4
		return 0;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	rdpsnd->data = client;
Packit 1fb8d4
Packit 1fb8d4
	if (client->subsystem->rdpsndFormats)
Packit 1fb8d4
	{
Packit 1fb8d4
		rdpsnd->server_formats = client->subsystem->rdpsndFormats;
Packit 1fb8d4
		rdpsnd->num_server_formats = client->subsystem->nRdpsndFormats;
Packit 1fb8d4
	}
Packit 1fb8d4
	else
Packit 1fb8d4
	{
Packit 1fb8d4
		rdpsnd->num_server_formats = server_rdpsnd_get_formats(&rdpsnd->server_formats);
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	if (rdpsnd->num_server_formats > 0)
Packit 1fb8d4
		rdpsnd->src_format = &rdpsnd->server_formats[0];
Packit 1fb8d4
Packit 1fb8d4
	rdpsnd->Activated = rdpsnd_activated;
Packit 1fb8d4
	rdpsnd->Initialize(rdpsnd, TRUE);
Packit 1fb8d4
	return 1;
Packit 1fb8d4
}
Packit 1fb8d4
Packit 1fb8d4
void shadow_client_rdpsnd_uninit(rdpShadowClient* client)
Packit 1fb8d4
{
Packit 1fb8d4
	if (client->rdpsnd)
Packit 1fb8d4
	{
Packit 1fb8d4
		client->rdpsnd->Stop(client->rdpsnd);
Packit 1fb8d4
		rdpsnd_server_context_free(client->rdpsnd);
Packit 1fb8d4
		client->rdpsnd = NULL;
Packit 1fb8d4
	}
Packit 1fb8d4
}