Blame server/common/server.c

Packit 1fb8d4
/**
Packit 1fb8d4
 * FreeRDP: A Remote Desktop Protocol Implementation
Packit 1fb8d4
 * FreeRDP Server Common
Packit 1fb8d4
 *
Packit 1fb8d4
 * Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.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/wtypes.h>
Packit 1fb8d4
#include <freerdp/codec/audio.h>
Packit 1fb8d4
#include <freerdp/codec/dsp.h>
Packit 1fb8d4
Packit 1fb8d4
#include <freerdp/server/server-common.h>
Packit 1fb8d4
Packit 1fb8d4
size_t server_audin_get_formats(AUDIO_FORMAT** dst_formats)
Packit 1fb8d4
{
Packit 1fb8d4
	/* Default supported audio formats */
Packit Service 5a9772
	BYTE adpcm_data_7[] = { 0xf4, 0x07, 0x07, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00,
Packit Service 5a9772
		                    0xff, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x40, 0x00, 0xf0, 0x00,
Packit Service 5a9772
		                    0x00, 0x00, 0xcc, 0x01, 0x30, 0xff, 0x88, 0x01, 0x18, 0xff };
Packit Service 5a9772
	BYTE adpcm_data_3[] = { 0xf4, 0x03, 0x07, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00,
Packit Service 5a9772
		                    0xff, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x40, 0x00, 0xf0, 0x00,
Packit Service 5a9772
		                    0x00, 0x00, 0xcc, 0x01, 0x30, 0xff, 0x88, 0x01, 0x18, 0xff };
Packit Service 5a9772
	BYTE adpcm_data_1[] = { 0xf4, 0x01, 0x07, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00,
Packit Service 5a9772
		                    0xff, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x40, 0x00, 0xf0, 0x00,
Packit Service 5a9772
		                    0x00, 0x00, 0xcc, 0x01, 0x30, 0xff, 0x88, 0x01, 0x18, 0xff };
Packit 1fb8d4
	BYTE adpcm_dvi_data_7[] = { 0xf9, 0x07 };
Packit 1fb8d4
	BYTE adpcm_dvi_data_3[] = { 0xf9, 0x03 };
Packit 1fb8d4
	BYTE adpcm_dvi_data_1[] = { 0xf9, 0x01 };
Packit 1fb8d4
	BYTE gsm610_data[] = { 0x40, 0x01 };
Packit Service 5a9772
	const AUDIO_FORMAT default_supported_audio_formats[] = {
Packit 1fb8d4
		/* Formats sent by windows 10 server */
Packit Service 5a9772
		{ WAVE_FORMAT_AAC_MS, 2, 44100, 24000, 4, 16, 0, NULL },
Packit Service 5a9772
		{ WAVE_FORMAT_AAC_MS, 2, 44100, 20000, 4, 16, 0, NULL },
Packit Service 5a9772
		{ WAVE_FORMAT_AAC_MS, 2, 44100, 16000, 4, 16, 0, NULL },
Packit Service 5a9772
		{ WAVE_FORMAT_AAC_MS, 2, 44100, 12000, 4, 16, 0, NULL },
Packit Service 5a9772
		{ WAVE_FORMAT_PCM, 2, 44100, 176400, 4, 16, 0, NULL },
Packit Service 5a9772
		{ WAVE_FORMAT_ADPCM, 2, 44100, 44359, 2048, 4, 32, adpcm_data_7 },
Packit Service 5a9772
		{ WAVE_FORMAT_DVI_ADPCM, 2, 44100, 44251, 2048, 4, 2, adpcm_dvi_data_7 },
Packit Service 5a9772
		{ WAVE_FORMAT_ALAW, 2, 22050, 44100, 2, 8, 0, NULL },
Packit Service 5a9772
		{ WAVE_FORMAT_ADPCM, 2, 22050, 22311, 1024, 4, 32, adpcm_data_3 },
Packit Service 5a9772
		{ WAVE_FORMAT_DVI_ADPCM, 2, 22050, 22201, 1024, 4, 2, adpcm_dvi_data_3 },
Packit Service 5a9772
		{ WAVE_FORMAT_ADPCM, 1, 44100, 22179, 1024, 4, 32, adpcm_data_7 },
Packit Service 5a9772
		{ WAVE_FORMAT_DVI_ADPCM, 1, 44100, 22125, 1024, 4, 2, adpcm_dvi_data_7 },
Packit Service 5a9772
		{ WAVE_FORMAT_ADPCM, 2, 11025, 11289, 512, 4, 32, adpcm_data_1 },
Packit Service 5a9772
		{ WAVE_FORMAT_DVI_ADPCM, 2, 11025, 11177, 512, 4, 2, adpcm_dvi_data_1 },
Packit Service 5a9772
		{ WAVE_FORMAT_ADPCM, 1, 22050, 11155, 512, 4, 32, adpcm_data_3 },
Packit Service 5a9772
		{ WAVE_FORMAT_DVI_ADPCM, 1, 22050, 11100, 512, 4, 2, adpcm_dvi_data_3 },
Packit Service 5a9772
		{ WAVE_FORMAT_GSM610, 1, 44100, 8957, 65, 0, 2, gsm610_data },
Packit Service 5a9772
		{ WAVE_FORMAT_ADPCM, 2, 8000, 8192, 512, 4, 32, adpcm_data_1 },
Packit Service 5a9772
		{ WAVE_FORMAT_DVI_ADPCM, 2, 8000, 8110, 512, 4, 2, adpcm_dvi_data_1 },
Packit Service 5a9772
		{ WAVE_FORMAT_ADPCM, 1, 11025, 5644, 256, 4, 32, adpcm_data_1 },
Packit Service 5a9772
		{ WAVE_FORMAT_DVI_ADPCM, 1, 11025, 5588, 256, 4, 2, adpcm_dvi_data_1 },
Packit Service 5a9772
		{ WAVE_FORMAT_GSM610, 1, 22050, 4478, 65, 0, 2, gsm610_data },
Packit Service 5a9772
		{ WAVE_FORMAT_ADPCM, 1, 8000, 4096, 256, 4, 32, adpcm_data_1 },
Packit Service 5a9772
		{ WAVE_FORMAT_DVI_ADPCM, 1, 8000, 4055, 256, 4, 2, adpcm_dvi_data_1 },
Packit Service 5a9772
		{ WAVE_FORMAT_GSM610, 1, 11025, 2239, 65, 0, 2, gsm610_data },
Packit Service 5a9772
		{ WAVE_FORMAT_GSM610, 1, 8000, 1625, 65, 0, 2, gsm610_data },
Packit 1fb8d4
		/* Formats added for others */
Packit 1fb8d4
Packit 1fb8d4
		{ WAVE_FORMAT_MSG723, 2, 44100, 0, 4, 16, 0, NULL },
Packit 1fb8d4
		{ WAVE_FORMAT_MSG723, 2, 22050, 0, 4, 16, 0, NULL },
Packit 1fb8d4
		{ WAVE_FORMAT_MSG723, 1, 44100, 0, 4, 16, 0, NULL },
Packit 1fb8d4
		{ WAVE_FORMAT_MSG723, 1, 22050, 0, 4, 16, 0, NULL },
Packit 1fb8d4
		{ WAVE_FORMAT_PCM, 2, 44100, 176400, 4, 16, 0, NULL },
Packit 1fb8d4
		{ WAVE_FORMAT_PCM, 2, 22050, 88200, 4, 16, 0, NULL },
Packit 1fb8d4
		{ WAVE_FORMAT_PCM, 1, 44100, 88200, 4, 16, 0, NULL },
Packit 1fb8d4
		{ WAVE_FORMAT_PCM, 1, 22050, 44100, 4, 16, 0, NULL },
Packit 1fb8d4
		{ WAVE_FORMAT_MULAW, 2, 44100, 88200, 4, 16, 0, NULL },
Packit 1fb8d4
		{ WAVE_FORMAT_MULAW, 2, 22050, 44100, 4, 16, 0, NULL },
Packit 1fb8d4
		{ WAVE_FORMAT_MULAW, 1, 44100, 44100, 4, 16, 0, NULL },
Packit 1fb8d4
		{ WAVE_FORMAT_MULAW, 1, 22050, 22050, 4, 16, 0, NULL },
Packit 1fb8d4
		{ WAVE_FORMAT_ALAW, 2, 44100, 88200, 2, 8, 0, NULL },
Packit 1fb8d4
		{ WAVE_FORMAT_ALAW, 2, 22050, 44100, 2, 8, 0, NULL },
Packit 1fb8d4
		{ WAVE_FORMAT_ALAW, 1, 44100, 44100, 2, 8, 0, NULL },
Packit 1fb8d4
		{ WAVE_FORMAT_ALAW, 1, 22050, 22050, 2, 8, 0, NULL }
Packit 1fb8d4
	};
Packit 1fb8d4
	const size_t nrDefaultFormatsMax = ARRAYSIZE(default_supported_audio_formats);
Packit 1fb8d4
	size_t x, nr_formats = 0;
Packit 1fb8d4
	AUDIO_FORMAT* formats = audio_formats_new(nrDefaultFormatsMax);
Packit 1fb8d4
Packit 1fb8d4
	if (!dst_formats)
Packit 1fb8d4
		goto fail;
Packit 1fb8d4
Packit 1fb8d4
	*dst_formats = NULL;
Packit 1fb8d4
Packit 1fb8d4
	if (!formats)
Packit 1fb8d4
		goto fail;
Packit 1fb8d4
Packit 1fb8d4
	for (x = 0; x < nrDefaultFormatsMax; x++)
Packit 1fb8d4
	{
Packit 1fb8d4
		const AUDIO_FORMAT* format = &default_supported_audio_formats[x];
Packit 1fb8d4
Packit 1fb8d4
		if (freerdp_dsp_supports_format(format, FALSE))
Packit 1fb8d4
		{
Packit 1fb8d4
			AUDIO_FORMAT* dst = &formats[nr_formats++];
Packit 1fb8d4
Packit 1fb8d4
			if (!audio_format_copy(format, dst))
Packit 1fb8d4
				goto fail;
Packit 1fb8d4
		}
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	*dst_formats = formats;
Packit 1fb8d4
	return nr_formats;
Packit 1fb8d4
fail:
Packit 1fb8d4
	audio_formats_free(formats, nrDefaultFormatsMax);
Packit 1fb8d4
	return 0;
Packit 1fb8d4
}
Packit 1fb8d4
Packit 1fb8d4
size_t server_rdpsnd_get_formats(AUDIO_FORMAT** dst_formats)
Packit 1fb8d4
{
Packit 1fb8d4
	size_t x, y = 0;
Packit 1fb8d4
	/* Default supported audio formats */
Packit Service 5a9772
	static const AUDIO_FORMAT default_supported_audio_formats[] = {
Packit 1fb8d4
		{ WAVE_FORMAT_AAC_MS, 2, 44100, 176400, 4, 16, 0, NULL },
Packit 1fb8d4
		{ WAVE_FORMAT_MPEGLAYER3, 2, 44100, 176400, 4, 16, 0, NULL },
Packit 1fb8d4
		{ WAVE_FORMAT_MSG723, 2, 44100, 176400, 4, 16, 0, NULL },
Packit 1fb8d4
		{ WAVE_FORMAT_GSM610, 2, 44100, 176400, 4, 16, 0, NULL },
Packit 1fb8d4
		{ WAVE_FORMAT_ADPCM, 2, 44100, 176400, 4, 16, 0, NULL },
Packit 1fb8d4
		{ WAVE_FORMAT_PCM, 2, 44100, 176400, 4, 16, 0, NULL },
Packit 1fb8d4
		{ WAVE_FORMAT_ALAW, 2, 22050, 44100, 2, 8, 0, NULL },
Packit 1fb8d4
		{ WAVE_FORMAT_MULAW, 2, 22050, 44100, 2, 8, 0, NULL },
Packit 1fb8d4
	};
Packit Service 5a9772
	AUDIO_FORMAT* supported_audio_formats =
Packit Service 5a9772
	    audio_formats_new(ARRAYSIZE(default_supported_audio_formats));
Packit 1fb8d4
Packit 1fb8d4
	if (!supported_audio_formats)
Packit 1fb8d4
		goto fail;
Packit 1fb8d4
Packit 1fb8d4
	for (x = 0; x < ARRAYSIZE(default_supported_audio_formats); x++)
Packit 1fb8d4
	{
Packit 1fb8d4
		const AUDIO_FORMAT* format = &default_supported_audio_formats[x];
Packit 1fb8d4
Packit 1fb8d4
		if (freerdp_dsp_supports_format(format, TRUE))
Packit 1fb8d4
			supported_audio_formats[y++] = *format;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	/* Set default audio formats. */
Packit 1fb8d4
	*dst_formats = supported_audio_formats;
Packit 1fb8d4
	return y;
Packit 1fb8d4
fail:
Packit 1fb8d4
	audio_formats_free(supported_audio_formats, ARRAYSIZE(default_supported_audio_formats));
Packit 1fb8d4
Packit 1fb8d4
	if (dst_formats)
Packit 1fb8d4
		*dst_formats = NULL;
Packit 1fb8d4
Packit 1fb8d4
	return 0;
Packit 1fb8d4
}