/src/FreeRDP/channels/rdpsnd/client/fake/rdpsnd_fake.c
Line  | Count  | Source (jump to first uncovered line)  | 
1  |  | /**  | 
2  |  |  * FreeRDP: A Remote Desktop Protocol Implementation  | 
3  |  |  * Audio Output Virtual Channel  | 
4  |  |  *  | 
5  |  |  * Copyright 2019 Armin Novak <armin.novak@thincast.com>  | 
6  |  |  * Copyright 2019 Thincast Technologies GmbH  | 
7  |  |  *  | 
8  |  |  * Licensed under the Apache License, Version 2.0 (the "License");  | 
9  |  |  * you may not use this file except in compliance with the License.  | 
10  |  |  * You may obtain a copy of the License at  | 
11  |  |  *  | 
12  |  |  *     http://www.apache.org/licenses/LICENSE-2.0  | 
13  |  |  *  | 
14  |  |  * Unless required by applicable law or agreed to in writing, software  | 
15  |  |  * distributed under the License is distributed on an "AS IS" BASIS,  | 
16  |  |  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  | 
17  |  |  * See the License for the specific language governing permissions and  | 
18  |  |  * limitations under the License.  | 
19  |  |  */  | 
20  |  |  | 
21  |  | #include <freerdp/config.h>  | 
22  |  |  | 
23  |  | #include <stdio.h>  | 
24  |  | #include <stdlib.h>  | 
25  |  | #include <string.h>  | 
26  |  |  | 
27  |  | #include <winpr/crt.h>  | 
28  |  | #include <winpr/stream.h>  | 
29  |  | #include <winpr/cmdline.h>  | 
30  |  |  | 
31  |  | #include <freerdp/types.h>  | 
32  |  | #include <freerdp/settings.h>  | 
33  |  |  | 
34  |  | #include "rdpsnd_main.h"  | 
35  |  |  | 
36  |  | typedef struct  | 
37  |  | { | 
38  |  |   rdpsndDevicePlugin device;  | 
39  |  | } rdpsndFakePlugin;  | 
40  |  |  | 
41  |  | static BOOL rdpsnd_fake_open(rdpsndDevicePlugin* device, const AUDIO_FORMAT* format, UINT32 latency)  | 
42  | 0  | { | 
43  | 0  |   return TRUE;  | 
44  | 0  | }  | 
45  |  |  | 
46  |  | static void rdpsnd_fake_close(rdpsndDevicePlugin* device)  | 
47  | 0  | { | 
48  | 0  | }  | 
49  |  |  | 
50  |  | static BOOL rdpsnd_fake_set_volume(rdpsndDevicePlugin* device, UINT32 value)  | 
51  | 0  | { | 
52  | 0  |   return TRUE;  | 
53  | 0  | }  | 
54  |  |  | 
55  |  | static void rdpsnd_fake_free(rdpsndDevicePlugin* device)  | 
56  | 0  | { | 
57  | 0  |   rdpsndFakePlugin* fake = (rdpsndFakePlugin*)device;  | 
58  |  | 
  | 
59  | 0  |   if (!fake)  | 
60  | 0  |     return;  | 
61  |  |  | 
62  | 0  |   free(fake);  | 
63  | 0  | }  | 
64  |  |  | 
65  |  | static BOOL rdpsnd_fake_format_supported(rdpsndDevicePlugin* device, const AUDIO_FORMAT* format)  | 
66  | 0  | { | 
67  | 0  |   return TRUE;  | 
68  | 0  | }  | 
69  |  |  | 
70  |  | static UINT rdpsnd_fake_play(rdpsndDevicePlugin* device, const BYTE* data, size_t size)  | 
71  | 0  | { | 
72  | 0  |   return CHANNEL_RC_OK;  | 
73  | 0  | }  | 
74  |  |  | 
75  |  | /**  | 
76  |  |  * Function description  | 
77  |  |  *  | 
78  |  |  * @return 0 on success, otherwise a Win32 error code  | 
79  |  |  */  | 
80  |  | static UINT rdpsnd_fake_parse_addin_args(rdpsndFakePlugin* fake, const ADDIN_ARGV* args)  | 
81  | 0  | { | 
82  | 0  |   int status = 0;  | 
83  | 0  |   DWORD flags = 0;  | 
84  | 0  |   const COMMAND_LINE_ARGUMENT_A* arg = NULL;  | 
85  | 0  |   COMMAND_LINE_ARGUMENT_A rdpsnd_fake_args[] = { { NULL, 0, NULL, NULL, NULL, -1, NULL, NULL } }; | 
86  | 0  |   flags =  | 
87  | 0  |       COMMAND_LINE_SIGIL_NONE | COMMAND_LINE_SEPARATOR_COLON | COMMAND_LINE_IGN_UNKNOWN_KEYWORD;  | 
88  | 0  |   status = CommandLineParseArgumentsA(args->argc, args->argv, rdpsnd_fake_args, flags, fake, NULL,  | 
89  | 0  |                                       NULL);  | 
90  |  | 
  | 
91  | 0  |   if (status < 0)  | 
92  | 0  |     return ERROR_INVALID_DATA;  | 
93  |  |  | 
94  | 0  |   arg = rdpsnd_fake_args;  | 
95  |  | 
  | 
96  | 0  |   do  | 
97  | 0  |   { | 
98  | 0  |     if (!(arg->Flags & COMMAND_LINE_VALUE_PRESENT))  | 
99  | 0  |       continue;  | 
100  |  |  | 
101  | 0  |     CommandLineSwitchStart(arg) CommandLineSwitchEnd(arg)  | 
102  | 0  |   } while ((arg = CommandLineFindNextArgumentA(arg)) != NULL);  | 
103  |  |  | 
104  | 0  |   return CHANNEL_RC_OK;  | 
105  | 0  | }  | 
106  |  |  | 
107  |  | /**  | 
108  |  |  * Function description  | 
109  |  |  *  | 
110  |  |  * @return 0 on success, otherwise a Win32 error code  | 
111  |  |  */  | 
112  |  | FREERDP_ENTRY_POINT(UINT VCAPITYPE fake_freerdp_rdpsnd_client_subsystem_entry(  | 
113  |  |     PFREERDP_RDPSND_DEVICE_ENTRY_POINTS pEntryPoints))  | 
114  | 0  | { | 
115  | 0  |   const ADDIN_ARGV* args = NULL;  | 
116  | 0  |   rdpsndFakePlugin* fake = NULL;  | 
117  | 0  |   UINT ret = CHANNEL_RC_OK;  | 
118  | 0  |   fake = (rdpsndFakePlugin*)calloc(1, sizeof(rdpsndFakePlugin));  | 
119  |  | 
  | 
120  | 0  |   if (!fake)  | 
121  | 0  |     return CHANNEL_RC_NO_MEMORY;  | 
122  |  |  | 
123  | 0  |   fake->device.Open = rdpsnd_fake_open;  | 
124  | 0  |   fake->device.FormatSupported = rdpsnd_fake_format_supported;  | 
125  | 0  |   fake->device.SetVolume = rdpsnd_fake_set_volume;  | 
126  | 0  |   fake->device.Play = rdpsnd_fake_play;  | 
127  | 0  |   fake->device.Close = rdpsnd_fake_close;  | 
128  | 0  |   fake->device.Free = rdpsnd_fake_free;  | 
129  | 0  |   args = pEntryPoints->args;  | 
130  |  | 
  | 
131  | 0  |   if (args->argc > 1)  | 
132  | 0  |   { | 
133  | 0  |     ret = rdpsnd_fake_parse_addin_args(fake, args);  | 
134  |  | 
  | 
135  | 0  |     if (ret != CHANNEL_RC_OK)  | 
136  | 0  |     { | 
137  | 0  |       WLog_ERR(TAG, "error parsing arguments");  | 
138  | 0  |       goto error;  | 
139  | 0  |     }  | 
140  | 0  |   }  | 
141  |  |  | 
142  | 0  |   pEntryPoints->pRegisterRdpsndDevice(pEntryPoints->rdpsnd, &fake->device);  | 
143  | 0  |   return ret;  | 
144  | 0  | error:  | 
145  | 0  |   rdpsnd_fake_free(&fake->device);  | 
146  | 0  |   return ret;  | 
147  | 0  | }  |