19#include <freerdp/config.h>
22#include <winpr/assert.h>
23#include <winpr/cast.h>
25#include <freerdp/log.h>
26#include <freerdp/codec/dsp.h>
27#include <freerdp/server/server-common.h>
31#include "shadow_rdpsnd.h"
33#define TAG SERVER_TAG("shadow")
35static void rdpsnd_activated(RdpsndServerContext* context)
37 WINPR_ASSERT(context);
38 for (
size_t i = 0; i < context->num_client_formats; i++)
40 for (
size_t j = 0; j < context->num_server_formats; j++)
42 if (audio_format_compatible(&context->server_formats[j], &context->client_formats[i]))
44 const UINT rc = context->SelectFormat(context, WINPR_ASSERTING_INT_CAST(UINT16, i));
45 if (rc != CHANNEL_RC_OK)
46 WLog_WARN(TAG,
"SelectFormat failed with %" PRIu32, rc);
52 WLog_ERR(TAG,
"Could not agree on a audio format with the server\n");
55int shadow_client_rdpsnd_init(rdpShadowClient* client)
58 RdpsndServerContext* rdpsnd = client->rdpsnd = rdpsnd_server_context_new(client->vcm);
65 rdpsnd->data = client;
67 if (client->subsystem->rdpsndFormats)
71 const size_t count = client->subsystem->nRdpsndFormats;
72 rdpsnd->server_formats = audio_formats_new(count);
73 if (!rdpsnd->server_formats)
76 for (
size_t x = 0; x < count; x++)
78 if (!audio_format_copy(&client->subsystem->rdpsndFormats[x],
79 &rdpsnd->server_formats[x]))
82 rdpsnd->num_server_formats = count;
86 rdpsnd->num_server_formats = server_rdpsnd_get_formats(&rdpsnd->server_formats);
89 if (rdpsnd->num_server_formats > 0)
90 rdpsnd->src_format = &rdpsnd->server_formats[0];
92 rdpsnd->Activated = rdpsnd_activated;
94 const UINT error = rdpsnd->Initialize(rdpsnd, TRUE);
95 if (error != CHANNEL_RC_OK)
100void shadow_client_rdpsnd_uninit(rdpShadowClient* client)
102 WINPR_ASSERT(client);
105 client->rdpsnd->Stop(client->rdpsnd);
106 rdpsnd_server_context_free(client->rdpsnd);
107 client->rdpsnd =
nullptr;