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