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 rdpsnd_server_context_lock(context);
39 for (
size_t i = 0; i < context->num_client_formats; i++)
41 for (
size_t j = 0; j < context->num_server_formats; j++)
43 if (audio_format_compatible(&context->server_formats[j], &context->client_formats[i]))
45 const UINT rc = context->SelectFormat(context, WINPR_ASSERTING_INT_CAST(UINT16, i));
46 rdpsnd_server_context_unlock(context);
47 if (rc != CHANNEL_RC_OK)
48 WLog_WARN(TAG,
"SelectFormat failed with %" PRIu32, rc);
53 rdpsnd_server_context_unlock(context);
55 WLog_ERR(TAG,
"Could not agree on a audio format with the server\n");
58int shadow_client_rdpsnd_init(rdpShadowClient* client)
61 RdpsndServerContext* rdpsnd = client->rdpsnd = rdpsnd_server_context_new(client->vcm);
68 rdpsnd->data = client;
70 if (client->subsystem->rdpsndFormats)
74 const size_t count = client->subsystem->nRdpsndFormats;
75 rdpsnd->server_formats = audio_formats_new(count);
76 if (!rdpsnd->server_formats)
79 for (
size_t x = 0; x < count; x++)
81 if (!audio_format_copy(&client->subsystem->rdpsndFormats[x],
82 &rdpsnd->server_formats[x]))
85 rdpsnd->num_server_formats = count;
89 rdpsnd->num_server_formats = server_rdpsnd_get_formats(&rdpsnd->server_formats);
92 if (rdpsnd->num_server_formats > 0)
93 rdpsnd->src_format = &rdpsnd->server_formats[0];
95 rdpsnd->Activated = rdpsnd_activated;
97 const UINT error = rdpsnd->Initialize(rdpsnd, TRUE);
98 if (error != CHANNEL_RC_OK)
103void shadow_client_rdpsnd_uninit(rdpShadowClient* client)
105 WINPR_ASSERT(client);
108 client->rdpsnd->Stop(client->rdpsnd);
109 rdpsnd_server_context_free(client->rdpsnd);
110 client->rdpsnd =
nullptr;