FreeRDP
Loading...
Searching...
No Matches
shadow_rdpsnd.c
1
18
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 rdpsnd_server_context_lock(context);
39 for (size_t i = 0; i < context->num_client_formats; i++)
40 {
41 for (size_t j = 0; j < context->num_server_formats; j++)
42 {
43 if (audio_format_compatible(&context->server_formats[j], &context->client_formats[i]))
44 {
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);
49 return;
50 }
51 }
52 }
53 rdpsnd_server_context_unlock(context);
54
55 WLog_ERR(TAG, "Could not agree on a audio format with the server\n");
56}
57
58int shadow_client_rdpsnd_init(rdpShadowClient* client)
59{
60 WINPR_ASSERT(client);
61 RdpsndServerContext* rdpsnd = client->rdpsnd = rdpsnd_server_context_new(client->vcm);
62
63 if (!rdpsnd)
64 {
65 return 0;
66 }
67
68 rdpsnd->data = client;
69
70 if (client->subsystem->rdpsndFormats)
71 {
72 /* rdpsnd_server_context_free() frees the list: each client gets its own
73 * copy (shadow_client_rdpsnd_uninit() cleans up after a failure here) */
74 const size_t count = client->subsystem->nRdpsndFormats;
75 rdpsnd->server_formats = audio_formats_new(count);
76 if (!rdpsnd->server_formats)
77 return -1;
78
79 for (size_t x = 0; x < count; x++)
80 {
81 if (!audio_format_copy(&client->subsystem->rdpsndFormats[x],
82 &rdpsnd->server_formats[x]))
83 return -1;
84 }
85 rdpsnd->num_server_formats = count;
86 }
87 else
88 {
89 rdpsnd->num_server_formats = server_rdpsnd_get_formats(&rdpsnd->server_formats);
90 }
91
92 if (rdpsnd->num_server_formats > 0)
93 rdpsnd->src_format = &rdpsnd->server_formats[0];
94
95 rdpsnd->Activated = rdpsnd_activated;
96
97 const UINT error = rdpsnd->Initialize(rdpsnd, TRUE);
98 if (error != CHANNEL_RC_OK)
99 return -1;
100 return 1;
101}
102
103void shadow_client_rdpsnd_uninit(rdpShadowClient* client)
104{
105 WINPR_ASSERT(client);
106 if (client->rdpsnd)
107 {
108 client->rdpsnd->Stop(client->rdpsnd);
109 rdpsnd_server_context_free(client->rdpsnd);
110 client->rdpsnd = nullptr;
111 }
112}