FreeRDP
Loading...
Searching...
No Matches
shadow_rdpsnd.c
1
19#include <freerdp/config.h>
20
21#include <winpr/crt.h>
22#include <winpr/assert.h>
23#include <winpr/cast.h>
24
25#include <freerdp/log.h>
26#include <freerdp/codec/dsp.h>
27#include <freerdp/server/server-common.h>
28
29#include "shadow.h"
30
31#include "shadow_rdpsnd.h"
32
33#define TAG SERVER_TAG("shadow")
34
35static void rdpsnd_activated(RdpsndServerContext* context)
36{
37 WINPR_ASSERT(context);
38 for (size_t i = 0; i < context->num_client_formats; i++)
39 {
40 for (size_t j = 0; j < context->num_server_formats; j++)
41 {
42 if (audio_format_compatible(&context->server_formats[j], &context->client_formats[i]))
43 {
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);
47 return;
48 }
49 }
50 }
51
52 WLog_ERR(TAG, "Could not agree on a audio format with the server\n");
53}
54
55int shadow_client_rdpsnd_init(rdpShadowClient* client)
56{
57 WINPR_ASSERT(client);
58 RdpsndServerContext* rdpsnd = client->rdpsnd = rdpsnd_server_context_new(client->vcm);
59
60 if (!rdpsnd)
61 {
62 return 0;
63 }
64
65 rdpsnd->data = client;
66
67 if (client->subsystem->rdpsndFormats)
68 {
69 rdpsnd->server_formats = client->subsystem->rdpsndFormats;
70 rdpsnd->num_server_formats = client->subsystem->nRdpsndFormats;
71 }
72 else
73 {
74 rdpsnd->num_server_formats = server_rdpsnd_get_formats(&rdpsnd->server_formats);
75 }
76
77 if (rdpsnd->num_server_formats > 0)
78 rdpsnd->src_format = &rdpsnd->server_formats[0];
79
80 rdpsnd->Activated = rdpsnd_activated;
81
82 const UINT error = rdpsnd->Initialize(rdpsnd, TRUE);
83 if (error != CHANNEL_RC_OK)
84 return -1;
85 return 1;
86}
87
88void shadow_client_rdpsnd_uninit(rdpShadowClient* client)
89{
90 WINPR_ASSERT(client);
91 if (client->rdpsnd)
92 {
93 client->rdpsnd->Stop(client->rdpsnd);
94 rdpsnd_server_context_free(client->rdpsnd);
95 client->rdpsnd = nullptr;
96 }
97}