Unified format selection.

This commit is contained in:
Armin Novak 2018-09-25 15:50:48 +02:00
parent 5e14bb1b11
commit db2a0dbdc0
3 changed files with 117 additions and 89 deletions

View File

@ -21,3 +21,113 @@
#include "config.h" #include "config.h"
#endif #endif
#include <winpr/wtypes.h>
#include <freerdp/codec/audio.h>
#include <freerdp/codec/dsp.h>
#include "server.h"
size_t server_audin_get_formats(AUDIO_FORMAT** dst_formats)
{
/* Default supported audio formats */
BYTE adpcm_data_7[] =
{
0xf4, 0x07, 0x07, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00,
0xff, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x40, 0x00, 0xf0, 0x00,
0x00, 0x00, 0xcc, 0x01, 0x30, 0xff, 0x88, 0x01, 0x18, 0xff
};
BYTE adpcm_data_3[] =
{
0xf4, 0x03, 0x07, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00,
0xff, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x40, 0x00, 0xf0, 0x00,
0x00, 0x00, 0xcc, 0x01, 0x30, 0xff, 0x88, 0x01, 0x18, 0xff
};
BYTE adpcm_data_1[] =
{
0xf4, 0x01, 0x07, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00,
0xff, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x40, 0x00, 0xf0, 0x00,
0x00, 0x00, 0xcc, 0x01, 0x30, 0xff, 0x88, 0x01, 0x18, 0xff
};
BYTE adpcm_dvi_data_7[] = { 0xf9, 0x07 };
BYTE adpcm_dvi_data_3[] = { 0xf9, 0x03 };
BYTE adpcm_dvi_data_1[] = { 0xf9, 0x01 };
BYTE gsm610_data[] = { 0x40, 0x01 };
const AUDIO_FORMAT default_supported_audio_formats[] =
{
/* Formats sent by windows 10 server */
{ WAVE_FORMAT_AAC_MS, 2, 44100, 24000, 4, 16, 0, NULL },
{ WAVE_FORMAT_AAC_MS, 2, 44100, 20000, 4, 16, 0, NULL },
{ WAVE_FORMAT_AAC_MS, 2, 44100, 16000, 4, 16, 0, NULL },
{ WAVE_FORMAT_AAC_MS, 2, 44100, 12000, 4, 16, 0, NULL },
{ WAVE_FORMAT_PCM, 2, 44100, 176400, 4, 16, 0, NULL },
{ WAVE_FORMAT_ADPCM, 2, 44100, 44359, 2048, 4, 32, adpcm_data_7 },
{ WAVE_FORMAT_DVI_ADPCM, 2, 44100, 44251, 2048, 4, 2, adpcm_dvi_data_7 },
{ WAVE_FORMAT_ALAW, 2, 22050, 44100, 2, 8, 0, NULL },
{ WAVE_FORMAT_ADPCM, 2, 22050, 22311, 1024, 4, 32, adpcm_data_3 },
{ WAVE_FORMAT_DVI_ADPCM, 2, 22050, 22201, 1024, 4, 2, adpcm_dvi_data_3 },
{ WAVE_FORMAT_ADPCM, 1, 44100, 22179, 1024, 4, 32, adpcm_data_7 },
{ WAVE_FORMAT_DVI_ADPCM, 1, 44100, 22125, 1024, 4, 2, adpcm_dvi_data_7 },
{ WAVE_FORMAT_ADPCM, 2, 11025, 11289, 512, 4, 32, adpcm_data_1 },
{ WAVE_FORMAT_DVI_ADPCM, 2, 11025, 11177, 512, 4, 2, adpcm_dvi_data_1 },
{ WAVE_FORMAT_ADPCM, 1, 22050, 11155, 512, 4, 32, adpcm_data_3 },
{ WAVE_FORMAT_DVI_ADPCM, 1, 22050, 11100, 512, 4, 2, adpcm_dvi_data_3 },
{ WAVE_FORMAT_GSM610, 1, 44100, 8957, 65, 0, 2, gsm610_data },
{ WAVE_FORMAT_ADPCM, 2, 8000, 8192, 512, 4, 32, adpcm_data_1 },
{ WAVE_FORMAT_DVI_ADPCM, 2, 8000, 8110, 512, 4, 2, adpcm_dvi_data_1 },
{ WAVE_FORMAT_ADPCM, 1, 11025, 5644, 256, 4, 32, adpcm_data_1 },
{ WAVE_FORMAT_DVI_ADPCM, 1, 11025, 5588, 256, 4, 2, adpcm_dvi_data_1 },
{ WAVE_FORMAT_GSM610, 1, 22050, 4478, 65, 0, 2, gsm610_data },
{ WAVE_FORMAT_ADPCM, 1, 8000, 4096, 256, 4, 32, adpcm_data_1 },
{ WAVE_FORMAT_DVI_ADPCM, 1, 8000, 4055, 256, 4, 2, adpcm_dvi_data_1 },
{ WAVE_FORMAT_GSM610, 1, 11025, 2239, 65, 0, 2, gsm610_data },
{ WAVE_FORMAT_GSM610, 1, 8000, 1625, 65, 0, 2, gsm610_data },
/* Formats added for others */
{ WAVE_FORMAT_MSG723, 2, 44100, 0, 4, 16, 0, NULL },
{ WAVE_FORMAT_MSG723, 2, 22050, 0, 4, 16, 0, NULL },
{ WAVE_FORMAT_MSG723, 1, 44100, 0, 4, 16, 0, NULL },
{ WAVE_FORMAT_MSG723, 1, 22050, 0, 4, 16, 0, NULL },
{ WAVE_FORMAT_PCM, 2, 44100, 176400, 4, 16, 0, NULL },
{ WAVE_FORMAT_PCM, 2, 22050, 88200, 4, 16, 0, NULL },
{ WAVE_FORMAT_PCM, 1, 44100, 88200, 4, 16, 0, NULL },
{ WAVE_FORMAT_PCM, 1, 22050, 44100, 4, 16, 0, NULL },
{ WAVE_FORMAT_MULAW, 2, 44100, 88200, 4, 16, 0, NULL },
{ WAVE_FORMAT_MULAW, 2, 22050, 44100, 4, 16, 0, NULL },
{ WAVE_FORMAT_MULAW, 1, 44100, 44100, 4, 16, 0, NULL },
{ WAVE_FORMAT_MULAW, 1, 22050, 22050, 4, 16, 0, NULL },
{ WAVE_FORMAT_ALAW, 2, 44100, 88200, 2, 8, 0, NULL },
{ WAVE_FORMAT_ALAW, 2, 22050, 44100, 2, 8, 0, NULL },
{ WAVE_FORMAT_ALAW, 1, 44100, 44100, 2, 8, 0, NULL },
{ WAVE_FORMAT_ALAW, 1, 22050, 22050, 2, 8, 0, NULL }
};
const size_t nrDefaultFormatsMax = ARRAYSIZE(default_supported_audio_formats);
size_t x, nr_formats = 0;
AUDIO_FORMAT* formats = audio_formats_new(nrDefaultFormatsMax);
if (!dst_formats)
goto fail;
*dst_formats = NULL;
if (!formats)
goto fail;
for (x = 0; x < nrDefaultFormatsMax; x++)
{
const AUDIO_FORMAT* format = &default_supported_audio_formats[x];
if (freerdp_dsp_supports_format(format, FALSE))
{
AUDIO_FORMAT* dst = &formats[nr_formats++];
if (!audio_format_copy(format, dst))
goto fail;
}
}
*dst_formats = formats;
return nr_formats;
fail:
audio_formats_free(formats, nrDefaultFormatsMax);
return 0;
}

View File

@ -21,4 +21,9 @@
#ifndef FREERDP_SERVER_COMMON_SERVER_H #ifndef FREERDP_SERVER_COMMON_SERVER_H
#define FREERDP_SERVER_COMMON_SERVER_H #define FREERDP_SERVER_COMMON_SERVER_H
#include <winpr/wtypes.h>
#include <freerdp/codec/audio.h>
size_t server_audin_get_formats(AUDIO_FORMAT** dst_formats);
#endif /* FREERDP_SERVER_COMMON_SERVER_H */ #endif /* FREERDP_SERVER_COMMON_SERVER_H */

View File

@ -25,6 +25,7 @@
#include "shadow.h" #include "shadow.h"
#include "shadow_audin.h" #include "shadow_audin.h"
#include "../common/server.h"
#define TAG SERVER_TAG("shadow") #define TAG SERVER_TAG("shadow")
@ -119,95 +120,7 @@ BOOL shadow_client_audin_init(rdpShadowClient* client)
} }
else else
{ {
/* Default supported audio formats */ audin->num_server_formats = server_audin_get_formats(&audin->server_formats);
BYTE adpcm_data_7[] =
{
0xf4, 0x07, 0x07, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00,
0xff, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x40, 0x00, 0xf0, 0x00,
0x00, 0x00, 0xcc, 0x01, 0x30, 0xff, 0x88, 0x01, 0x18, 0xff
};
BYTE adpcm_data_3[] =
{
0xf4, 0x03, 0x07, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00,
0xff, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x40, 0x00, 0xf0, 0x00,
0x00, 0x00, 0xcc, 0x01, 0x30, 0xff, 0x88, 0x01, 0x18, 0xff
};
BYTE adpcm_data_1[] =
{
0xf4, 0x01, 0x07, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00,
0xff, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x40, 0x00, 0xf0, 0x00,
0x00, 0x00, 0xcc, 0x01, 0x30, 0xff, 0x88, 0x01, 0x18, 0xff
};
BYTE adpcm_dvi_data_7[] = { 0xf9, 0x07 };
BYTE adpcm_dvi_data_3[] = { 0xf9, 0x03 };
BYTE adpcm_dvi_data_1[] = { 0xf9, 0x01 };
BYTE gsm610_data[] = { 0x40, 0x01 };
const AUDIO_FORMAT default_supported_audio_formats[] =
{
/* Formats sent by windows 10 server */
{ WAVE_FORMAT_AAC_MS, 2, 44100, 24000, 4, 16, 0, NULL },
{ WAVE_FORMAT_AAC_MS, 2, 44100, 20000, 4, 16, 0, NULL },
{ WAVE_FORMAT_AAC_MS, 2, 44100, 16000, 4, 16, 0, NULL },
{ WAVE_FORMAT_AAC_MS, 2, 44100, 12000, 4, 16, 0, NULL },
{ WAVE_FORMAT_PCM, 2, 44100, 176400, 4, 16, 0, NULL },
{ WAVE_FORMAT_ADPCM, 2, 44100, 44359, 2048, 4, 32, adpcm_data_7 },
{ WAVE_FORMAT_DVI_ADPCM, 2, 44100, 44251, 2048, 4, 2, adpcm_dvi_data_7 },
{ WAVE_FORMAT_ALAW, 2, 22050, 44100, 2, 8, 0, NULL },
{ WAVE_FORMAT_ADPCM, 2, 22050, 22311, 1024, 4, 32, adpcm_data_3 },
{ WAVE_FORMAT_DVI_ADPCM, 2, 22050, 22201, 1024, 4, 2, adpcm_dvi_data_3 },
{ WAVE_FORMAT_ADPCM, 1, 44100, 22179, 1024, 4, 32, adpcm_data_7 },
{ WAVE_FORMAT_DVI_ADPCM, 1, 44100, 22125, 1024, 4, 2, adpcm_dvi_data_7 },
{ WAVE_FORMAT_ADPCM, 2, 11025, 11289, 512, 4, 32, adpcm_data_1 },
{ WAVE_FORMAT_DVI_ADPCM, 2, 11025, 11177, 512, 4, 2, adpcm_dvi_data_1 },
{ WAVE_FORMAT_ADPCM, 1, 22050, 11155, 512, 4, 32, adpcm_data_3 },
{ WAVE_FORMAT_DVI_ADPCM, 1, 22050, 11100, 512, 4, 2, adpcm_dvi_data_3 },
{ WAVE_FORMAT_GSM610, 1, 44100, 8957, 65, 0, 2, gsm610_data },
{ WAVE_FORMAT_ADPCM, 2, 8000, 8192, 512, 4, 32, adpcm_data_1 },
{ WAVE_FORMAT_DVI_ADPCM, 2, 8000, 8110, 512, 4, 2, adpcm_dvi_data_1 },
{ WAVE_FORMAT_ADPCM, 1, 11025, 5644, 256, 4, 32, adpcm_data_1 },
{ WAVE_FORMAT_DVI_ADPCM, 1, 11025, 5588, 256, 4, 2, adpcm_dvi_data_1 },
{ WAVE_FORMAT_GSM610, 1, 22050, 4478, 65, 0, 2, gsm610_data },
{ WAVE_FORMAT_ADPCM, 1, 8000, 4096, 256, 4, 32, adpcm_data_1 },
{ WAVE_FORMAT_DVI_ADPCM, 1, 8000, 4055, 256, 4, 2, adpcm_dvi_data_1 },
{ WAVE_FORMAT_GSM610, 1, 11025, 2239, 65, 0, 2, gsm610_data },
{ WAVE_FORMAT_GSM610, 1, 8000, 1625, 65, 0, 2, gsm610_data },
/* Formats added for others */
{ WAVE_FORMAT_MSG723, 2, 44100, 0, 4, 16, 0, NULL },
{ WAVE_FORMAT_MSG723, 2, 22050, 0, 4, 16, 0, NULL },
{ WAVE_FORMAT_MSG723, 1, 44100, 0, 4, 16, 0, NULL },
{ WAVE_FORMAT_MSG723, 1, 22050, 0, 4, 16, 0, NULL },
{ WAVE_FORMAT_PCM, 2, 44100, 176400, 4, 16, 0, NULL },
{ WAVE_FORMAT_PCM, 2, 22050, 88200, 4, 16, 0, NULL },
{ WAVE_FORMAT_PCM, 1, 44100, 88200, 4, 16, 0, NULL },
{ WAVE_FORMAT_PCM, 1, 22050, 44100, 4, 16, 0, NULL },
{ WAVE_FORMAT_MULAW, 2, 44100, 88200, 4, 16, 0, NULL },
{ WAVE_FORMAT_MULAW, 2, 22050, 44100, 4, 16, 0, NULL },
{ WAVE_FORMAT_MULAW, 1, 44100, 44100, 4, 16, 0, NULL },
{ WAVE_FORMAT_MULAW, 1, 22050, 22050, 4, 16, 0, NULL },
{ WAVE_FORMAT_ALAW, 2, 44100, 88200, 2, 8, 0, NULL },
{ WAVE_FORMAT_ALAW, 2, 22050, 44100, 2, 8, 0, NULL },
{ WAVE_FORMAT_ALAW, 1, 44100, 44100, 2, 8, 0, NULL },
{ WAVE_FORMAT_ALAW, 1, 22050, 22050, 2, 8, 0, NULL }
};
const size_t nrDefaultFormatsMax = ARRAYSIZE(default_supported_audio_formats);
size_t x;
audin->server_formats = audio_formats_new(nrDefaultFormatsMax);
if (!audin->server_formats)
goto fail;
/* Set default audio formats. */
for (x = 0; x < nrDefaultFormatsMax; x++)
{
const AUDIO_FORMAT* format = &default_supported_audio_formats[x];
if (freerdp_dsp_supports_format(format, FALSE))
{
AUDIO_FORMAT* dst = &audin->server_formats[audin->num_server_formats++];
audio_format_copy(format, dst);
}
}
} }
if (audin->num_server_formats < 1) if (audin->num_server_formats < 1)