Blame server/proxy/pf_rdpsnd.c

Packit Service 5a9772
/**
Packit Service 5a9772
 * FreeRDP: A Remote Desktop Protocol Implementation
Packit Service 5a9772
 * FreeRDP Proxy Server
Packit Service 5a9772
 *
Packit Service 5a9772
 * Copyright 2019 Kobi Mizrachi <kmizrachi18@gmail.com>
Packit Service 5a9772
 *
Packit Service 5a9772
 * Licensed under the Apache License, Version 2.0 (the "License");
Packit Service 5a9772
 * you may not use this file except in compliance with the License.
Packit Service 5a9772
 * You may obtain a copy of the License at
Packit Service 5a9772
 *
Packit Service 5a9772
 *     http://www.apache.org/licenses/LICENSE-2.0
Packit Service 5a9772
 *
Packit Service 5a9772
 * Unless required by applicable law or agreed to in writing, software
Packit Service 5a9772
 * distributed under the License is distributed on an "AS IS" BASIS,
Packit Service 5a9772
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Packit Service 5a9772
 * See the License for the specific language governing permissions and
Packit Service 5a9772
 * limitations under the License.
Packit Service 5a9772
 */
Packit Service 5a9772
Packit Service 5a9772
#include <winpr/crt.h>
Packit Service 5a9772
#include <freerdp/log.h>
Packit Service 5a9772
#include <freerdp/codec/dsp.h>
Packit Service 5a9772
#include <freerdp/server/rdpsnd.h>
Packit Service 5a9772
#include <freerdp/server/server-common.h>
Packit Service 5a9772
Packit Service 5a9772
#include "pf_rdpsnd.h"
Packit Service 5a9772
#include "pf_log.h"
Packit Service 5a9772
Packit Service 5a9772
#define TAG PROXY_TAG("rdpsnd")
Packit Service 5a9772
Packit Service 5a9772
static void rdpsnd_activated(RdpsndServerContext* context)
Packit Service 5a9772
{
Packit Service 5a9772
	const AUDIO_FORMAT* agreed_format = NULL;
Packit Service 5a9772
	UINT16 i = 0, j = 0;
Packit Service 5a9772
Packit Service 5a9772
	for (i = 0; i < context->num_client_formats; i++)
Packit Service 5a9772
	{
Packit Service 5a9772
		for (j = 0; j < context->num_server_formats; j++)
Packit Service 5a9772
		{
Packit Service 5a9772
			if (audio_format_compatible(&context->server_formats[j], &context->client_formats[i]))
Packit Service 5a9772
			{
Packit Service 5a9772
				agreed_format = &context->server_formats[j];
Packit Service 5a9772
				break;
Packit Service 5a9772
			}
Packit Service 5a9772
		}
Packit Service 5a9772
Packit Service 5a9772
		if (agreed_format != NULL)
Packit Service 5a9772
			break;
Packit Service 5a9772
	}
Packit Service 5a9772
Packit Service 5a9772
	if (agreed_format == NULL)
Packit Service 5a9772
	{
Packit Service 5a9772
		WLog_ERR(TAG, "rdpsnd_activated(): Could not agree on a audio format with the server");
Packit Service 5a9772
		return;
Packit Service 5a9772
	}
Packit Service 5a9772
Packit Service 5a9772
	context->SelectFormat(context, i);
Packit Service 5a9772
}
Packit Service 5a9772
Packit Service 5a9772
BOOL pf_server_rdpsnd_init(pServerContext* ps)
Packit Service 5a9772
{
Packit Service 5a9772
	RdpsndServerContext* rdpsnd;
Packit Service 5a9772
	rdpsnd = ps->rdpsnd = rdpsnd_server_context_new(ps->vcm);
Packit Service 5a9772
Packit Service 5a9772
	if (!rdpsnd)
Packit Service 5a9772
	{
Packit Service 5a9772
		return FALSE;
Packit Service 5a9772
	}
Packit Service 5a9772
Packit Service 5a9772
	rdpsnd->rdpcontext = (rdpContext*)ps;
Packit Service 5a9772
	rdpsnd->data = (rdpContext*)ps;
Packit Service 5a9772
Packit Service 5a9772
	rdpsnd->num_server_formats = server_rdpsnd_get_formats(&rdpsnd->server_formats);
Packit Service 5a9772
Packit Service 5a9772
	if (rdpsnd->num_server_formats > 0)
Packit Service 5a9772
		rdpsnd->src_format = &rdpsnd->server_formats[0];
Packit Service 5a9772
Packit Service 5a9772
	rdpsnd->Activated = rdpsnd_activated;
Packit Service 5a9772
	return TRUE;
Packit Service 5a9772
}