FreeRDP
Loading...
Searching...
No Matches
TestFreeRDPCodecAudio.c
1#include <stdio.h>
2
3#include <winpr/crt.h>
4
5#include <freerdp/codec/audio.h>
6
7/* The filters rdpsnd and audin build from /sound:format: and /microphone:format:, all zero
8 * without the option, and the one the resampler builds without a tag. */
9static BOOL test_format_compatible(void)
10{
11 const AUDIO_FORMAT pcm = { .wFormatTag = WAVE_FORMAT_PCM,
12 .nChannels = 2,
13 .nSamplesPerSec = 44100,
14 .nAvgBytesPerSec = 176400,
15 .nBlockAlign = 4,
16 .wBitsPerSample = 16 };
17 AUDIO_FORMAT alaw = pcm;
18 alaw.wFormatTag = WAVE_FORMAT_ALAW;
19 AUDIO_FORMAT broken = pcm;
20 broken.nSamplesPerSec = 0;
21
22 const AUDIO_FORMAT any = WINPR_C_ARRAY_INIT;
23 const AUDIO_FORMAT onlyPcm = { .wFormatTag = WAVE_FORMAT_PCM };
24 const AUDIO_FORMAT only48k = { .nSamplesPerSec = 48000 };
25 AUDIO_FORMAT noTag = pcm;
26 noTag.wFormatTag = WAVE_FORMAT_UNKNOWN;
27 noTag.wBitsPerSample = 0;
28
29 BOOL rc = TRUE;
30 const struct
31 {
32 const char* what;
33 const AUDIO_FORMAT* with;
34 const AUDIO_FORMAT* format;
35 BOOL expected;
36 } cases[] = {
37 { "no filter, PCM", &any, &pcm, TRUE },
38 { "no filter, A-law", &any, &alaw, TRUE },
39 { "PCM filter, PCM", &onlyPcm, &pcm, TRUE },
40 { "PCM filter, A-law", &onlyPcm, &alaw, FALSE },
41 { "48 kHz filter, 44.1 kHz", &only48k, &pcm, FALSE },
42 { "no tag, same rate", &noTag, &alaw, TRUE },
43 { "same format", &pcm, &pcm, TRUE },
44 { "no filter, no sample rate", &any, &broken, FALSE },
45 };
46 for (size_t i = 0; i < ARRAYSIZE(cases); i++)
47 {
48 const BOOL got = audio_format_compatible(cases[i].with, cases[i].format);
49 if (got != cases[i].expected)
50 {
51 (void)fprintf(stderr, "[%s] %s: got %d, expected %d\n", __func__, cases[i].what, got,
52 cases[i].expected);
53 rc = FALSE;
54 }
55 }
56 return rc;
57}
58
59int TestFreeRDPCodecAudio(WINPR_ATTR_UNUSED int argc, WINPR_ATTR_UNUSED char* argv[])
60{
61 if (!test_format_compatible())
62 return -1;
63 return 0;
64}