Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .gitattributes +3 -0
- local-test-freerdp-delta-01/afc-freerdp/channels/ainput/CMakeLists.txt +27 -0
- local-test-freerdp-delta-01/afc-freerdp/channels/ainput/ChannelOptions.cmake +20 -0
- local-test-freerdp-delta-01/afc-freerdp/channels/ainput/client/CMakeLists.txt +27 -0
- local-test-freerdp-delta-01/afc-freerdp/channels/ainput/client/ainput_main.c +183 -0
- local-test-freerdp-delta-01/afc-freerdp/channels/ainput/client/ainput_main.h +40 -0
- local-test-freerdp-delta-01/afc-freerdp/channels/ainput/common/ainput_common.h +59 -0
- local-test-freerdp-delta-01/afc-freerdp/channels/ainput/server/CMakeLists.txt +24 -0
- local-test-freerdp-delta-01/afc-freerdp/channels/ainput/server/ainput_main.c +597 -0
- local-test-freerdp-delta-01/afc-freerdp/channels/audin/CMakeLists.txt +26 -0
- local-test-freerdp-delta-01/afc-freerdp/channels/audin/ChannelOptions.cmake +24 -0
- local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/CMakeLists.txt +58 -0
- local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/alsa/CMakeLists.txt +29 -0
- local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/alsa/audin_alsa.c +463 -0
- local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/audin_main.c +1110 -0
- local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/audin_main.h +33 -0
- local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/ios/CMakeLists.txt +31 -0
- local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/ios/audin_ios.m +335 -0
- local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/mac/CMakeLists.txt +32 -0
- local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/mac/audin_mac.m +463 -0
- local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/opensles/CMakeLists.txt +29 -0
- local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/opensles/audin_opensl_es.c +336 -0
- local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/opensles/opensl_io.c +388 -0
- local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/opensles/opensl_io.h +65 -0
- local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/oss/CMakeLists.txt +31 -0
- local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/oss/audin_oss.c +486 -0
- local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/pulse/CMakeLists.txt +29 -0
- local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/pulse/audin_pulse.c +561 -0
- local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/sndio/CMakeLists.txt +30 -0
- local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/sndio/audin_sndio.c +352 -0
- local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/winmm/CMakeLists.txt +26 -0
- local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/winmm/audin_winmm.c +566 -0
- local-test-freerdp-delta-01/afc-freerdp/channels/audin/server/CMakeLists.txt +23 -0
- local-test-freerdp-delta-01/afc-freerdp/channels/audin/server/audin.c +913 -0
- local-test-freerdp-delta-01/afc-freerdp/channels/client/CMakeLists.txt +165 -0
- local-test-freerdp-delta-01/afc-freerdp/channels/client/addin.c +761 -0
- local-test-freerdp-delta-01/afc-freerdp/channels/client/addin.h +28 -0
- local-test-freerdp-delta-01/afc-freerdp/channels/client/generic_dynvc.c +214 -0
- local-test-freerdp-delta-01/afc-freerdp/channels/client/tables.c.in +33 -0
- local-test-freerdp-delta-01/afc-freerdp/channels/client/tables.h +105 -0
- local-test-freerdp-delta-01/afc-freerdp/channels/cliprdr/CMakeLists.txt +26 -0
- local-test-freerdp-delta-01/afc-freerdp/channels/cliprdr/ChannelOptions.cmake +20 -0
- local-test-freerdp-delta-01/afc-freerdp/channels/cliprdr/client/CMakeLists.txt +25 -0
- local-test-freerdp-delta-01/afc-freerdp/channels/cliprdr/client/cliprdr_format.c +244 -0
- local-test-freerdp-delta-01/afc-freerdp/channels/cliprdr/client/cliprdr_format.h +37 -0
- local-test-freerdp-delta-01/afc-freerdp/channels/cliprdr/client/cliprdr_main.c +1174 -0
- local-test-freerdp-delta-01/afc-freerdp/channels/cliprdr/client/cliprdr_main.h +61 -0
- local-test-freerdp-delta-01/afc-freerdp/channels/cliprdr/cliprdr_common.c +558 -0
- local-test-freerdp-delta-01/afc-freerdp/channels/cliprdr/cliprdr_common.h +64 -0
- local-test-freerdp-delta-01/afc-freerdp/channels/cliprdr/server/CMakeLists.txt +23 -0
.gitattributes
CHANGED
|
@@ -59,3 +59,6 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 59 |
*.webm filter=lfs diff=lfs merge=lfs -text
|
| 60 |
fuzz-tooling/infra/cifuzz/test_data/timeout_fuzzer filter=lfs diff=lfs merge=lfs -text
|
| 61 |
fuzz-tooling/projects/curl/pkgs/curl_fuzzer/corpora/curl_fuzzer_rtsp/oss-fuzz-issue-6937 filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
*.webm filter=lfs diff=lfs merge=lfs -text
|
| 60 |
fuzz-tooling/infra/cifuzz/test_data/timeout_fuzzer filter=lfs diff=lfs merge=lfs -text
|
| 61 |
fuzz-tooling/projects/curl/pkgs/curl_fuzzer/corpora/curl_fuzzer_rtsp/oss-fuzz-issue-6937 filter=lfs diff=lfs merge=lfs -text
|
| 62 |
+
local-test-freerdp-full-01/afc-freerdp/resources/font/OpenSans-VariableFont_wdth,wght.ttf filter=lfs diff=lfs merge=lfs -text
|
| 63 |
+
local-test-freerdp-full-01/afc-freerdp/resources/font/OpenSans-Italic-VariableFont_wdth,wght.ttf filter=lfs diff=lfs merge=lfs -text
|
| 64 |
+
local-test-freerdp-full-01/afc-freerdp/server/Sample/rfx_test.pcap filter=lfs diff=lfs merge=lfs -text
|
local-test-freerdp-delta-01/afc-freerdp/channels/ainput/CMakeLists.txt
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# FreeRDP: A Remote Desktop Protocol Implementation
|
| 2 |
+
# FreeRDP cmake build script
|
| 3 |
+
#
|
| 4 |
+
# Copyright 2022 Armin Novak <anovak@thincast.com>
|
| 5 |
+
# Copyright 2022 Thincast Technologies GmbH
|
| 6 |
+
#
|
| 7 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 8 |
+
# you may not use this file except in compliance with the License.
|
| 9 |
+
# You may obtain a copy of the License at
|
| 10 |
+
#
|
| 11 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
+
#
|
| 13 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 14 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 15 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 16 |
+
# See the License for the specific language governing permissions and
|
| 17 |
+
# limitations under the License.
|
| 18 |
+
|
| 19 |
+
define_channel("ainput")
|
| 20 |
+
|
| 21 |
+
if(WITH_CLIENT_CHANNELS)
|
| 22 |
+
add_channel_client(${MODULE_PREFIX} ${CHANNEL_NAME})
|
| 23 |
+
endif()
|
| 24 |
+
|
| 25 |
+
if(WITH_SERVER_CHANNELS)
|
| 26 |
+
add_channel_server(${MODULE_PREFIX} ${CHANNEL_NAME})
|
| 27 |
+
endif()
|
local-test-freerdp-delta-01/afc-freerdp/channels/ainput/ChannelOptions.cmake
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
set(OPTION_DEFAULT ON)
|
| 2 |
+
set(OPTION_CLIENT_DEFAULT ON)
|
| 3 |
+
set(OPTION_SERVER_DEFAULT ON)
|
| 4 |
+
|
| 5 |
+
define_channel_options(
|
| 6 |
+
NAME
|
| 7 |
+
"ainput"
|
| 8 |
+
TYPE
|
| 9 |
+
"dynamic"
|
| 10 |
+
DESCRIPTION
|
| 11 |
+
"Advanced Input Virtual Channel Extension"
|
| 12 |
+
SPECIFICATIONS
|
| 13 |
+
"[XXXXX]"
|
| 14 |
+
DEFAULT
|
| 15 |
+
${OPTION_DEFAULT}
|
| 16 |
+
CLIENT_DEFAULT
|
| 17 |
+
${OPTION_CLIENT_DEFAULT}
|
| 18 |
+
SERVER_DEFAULT
|
| 19 |
+
${OPTION_SERVER_DEFAULT}
|
| 20 |
+
)
|
local-test-freerdp-delta-01/afc-freerdp/channels/ainput/client/CMakeLists.txt
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# FreeRDP: A Remote Desktop Protocol Implementation
|
| 2 |
+
# FreeRDP cmake build script
|
| 3 |
+
#
|
| 4 |
+
# Copyright 2022 Armin Novak <anovak@thincast.com>
|
| 5 |
+
# Copyright 2022 Thincast Technologies GmbH
|
| 6 |
+
#
|
| 7 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 8 |
+
# you may not use this file except in compliance with the License.
|
| 9 |
+
# You may obtain a copy of the License at
|
| 10 |
+
#
|
| 11 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
+
#
|
| 13 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 14 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 15 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 16 |
+
# See the License for the specific language governing permissions and
|
| 17 |
+
# limitations under the License.
|
| 18 |
+
|
| 19 |
+
define_channel_client("ainput")
|
| 20 |
+
|
| 21 |
+
set(${MODULE_PREFIX}_SRCS ainput_main.c ainput_main.h)
|
| 22 |
+
|
| 23 |
+
set(${MODULE_PREFIX}_LIBS winpr)
|
| 24 |
+
|
| 25 |
+
include_directories(..)
|
| 26 |
+
|
| 27 |
+
add_channel_client_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} TRUE "DVCPluginEntry")
|
local-test-freerdp-delta-01/afc-freerdp/channels/ainput/client/ainput_main.c
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* FreeRDP: A Remote Desktop Protocol Implementation
|
| 3 |
+
* Advanced Input Virtual Channel Extension
|
| 4 |
+
*
|
| 5 |
+
* Copyright 2022 Armin Novak <anovak@thincast.com>
|
| 6 |
+
* Copyright 2022 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 |
+
|
| 26 |
+
#include <winpr/crt.h>
|
| 27 |
+
#include <winpr/assert.h>
|
| 28 |
+
#include <winpr/stream.h>
|
| 29 |
+
#include <winpr/sysinfo.h>
|
| 30 |
+
|
| 31 |
+
#include "ainput_main.h"
|
| 32 |
+
#include <freerdp/channels/log.h>
|
| 33 |
+
#include <freerdp/client/channels.h>
|
| 34 |
+
#include <freerdp/client/ainput.h>
|
| 35 |
+
#include <freerdp/channels/ainput.h>
|
| 36 |
+
|
| 37 |
+
#include "../common/ainput_common.h"
|
| 38 |
+
|
| 39 |
+
#define TAG CHANNELS_TAG("ainput.client")
|
| 40 |
+
|
| 41 |
+
typedef struct AINPUT_PLUGIN_ AINPUT_PLUGIN;
|
| 42 |
+
struct AINPUT_PLUGIN_
|
| 43 |
+
{
|
| 44 |
+
GENERIC_DYNVC_PLUGIN base;
|
| 45 |
+
AInputClientContext* context;
|
| 46 |
+
UINT32 MajorVersion;
|
| 47 |
+
UINT32 MinorVersion;
|
| 48 |
+
};
|
| 49 |
+
|
| 50 |
+
/**
|
| 51 |
+
* Function description
|
| 52 |
+
*
|
| 53 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 54 |
+
*/
|
| 55 |
+
static UINT ainput_on_data_received(IWTSVirtualChannelCallback* pChannelCallback, wStream* data)
|
| 56 |
+
{
|
| 57 |
+
UINT16 type = 0;
|
| 58 |
+
AINPUT_PLUGIN* ainput = NULL;
|
| 59 |
+
GENERIC_CHANNEL_CALLBACK* callback = (GENERIC_CHANNEL_CALLBACK*)pChannelCallback;
|
| 60 |
+
|
| 61 |
+
WINPR_ASSERT(callback);
|
| 62 |
+
WINPR_ASSERT(data);
|
| 63 |
+
|
| 64 |
+
ainput = (AINPUT_PLUGIN*)callback->plugin;
|
| 65 |
+
WINPR_ASSERT(ainput);
|
| 66 |
+
|
| 67 |
+
if (!Stream_CheckAndLogRequiredLength(TAG, data, 2))
|
| 68 |
+
return ERROR_NO_DATA;
|
| 69 |
+
Stream_Read_UINT16(data, type);
|
| 70 |
+
switch (type)
|
| 71 |
+
{
|
| 72 |
+
case MSG_AINPUT_VERSION:
|
| 73 |
+
if (!Stream_CheckAndLogRequiredLength(TAG, data, 8))
|
| 74 |
+
return ERROR_NO_DATA;
|
| 75 |
+
Stream_Read_UINT32(data, ainput->MajorVersion);
|
| 76 |
+
Stream_Read_UINT32(data, ainput->MinorVersion);
|
| 77 |
+
break;
|
| 78 |
+
default:
|
| 79 |
+
WLog_WARN(TAG, "Received unsupported message type 0x%04" PRIx16, type);
|
| 80 |
+
break;
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
return CHANNEL_RC_OK;
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
static UINT ainput_send_input_event(AInputClientContext* context, UINT64 flags, INT32 x, INT32 y)
|
| 87 |
+
{
|
| 88 |
+
AINPUT_PLUGIN* ainput = NULL;
|
| 89 |
+
GENERIC_CHANNEL_CALLBACK* callback = NULL;
|
| 90 |
+
BYTE buffer[32] = { 0 };
|
| 91 |
+
UINT64 time = 0;
|
| 92 |
+
wStream sbuffer = { 0 };
|
| 93 |
+
wStream* s = Stream_StaticInit(&sbuffer, buffer, sizeof(buffer));
|
| 94 |
+
|
| 95 |
+
WINPR_ASSERT(s);
|
| 96 |
+
WINPR_ASSERT(context);
|
| 97 |
+
|
| 98 |
+
time = GetTickCount64();
|
| 99 |
+
ainput = (AINPUT_PLUGIN*)context->handle;
|
| 100 |
+
WINPR_ASSERT(ainput);
|
| 101 |
+
|
| 102 |
+
if (ainput->MajorVersion != AINPUT_VERSION_MAJOR)
|
| 103 |
+
{
|
| 104 |
+
WLog_WARN(TAG, "Unsupported channel version %" PRIu32 ".%" PRIu32 ", aborting.",
|
| 105 |
+
ainput->MajorVersion, ainput->MinorVersion);
|
| 106 |
+
return CHANNEL_RC_UNSUPPORTED_VERSION;
|
| 107 |
+
}
|
| 108 |
+
callback = ainput->base.listener_callback->channel_callback;
|
| 109 |
+
WINPR_ASSERT(callback);
|
| 110 |
+
|
| 111 |
+
{
|
| 112 |
+
char ebuffer[128] = { 0 };
|
| 113 |
+
WLog_VRB(TAG, "sending timestamp=0x%08" PRIx64 ", flags=%s, %" PRId32 "x%" PRId32, time,
|
| 114 |
+
ainput_flags_to_string(flags, ebuffer, sizeof(ebuffer)), x, y);
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
/* Message type */
|
| 118 |
+
Stream_Write_UINT16(s, MSG_AINPUT_MOUSE);
|
| 119 |
+
|
| 120 |
+
/* Event data */
|
| 121 |
+
Stream_Write_UINT64(s, time);
|
| 122 |
+
Stream_Write_UINT64(s, flags);
|
| 123 |
+
Stream_Write_INT32(s, x);
|
| 124 |
+
Stream_Write_INT32(s, y);
|
| 125 |
+
Stream_SealLength(s);
|
| 126 |
+
|
| 127 |
+
/* ainput back what we have received. AINPUT does not have any message IDs. */
|
| 128 |
+
WINPR_ASSERT(callback->channel);
|
| 129 |
+
WINPR_ASSERT(callback->channel->Write);
|
| 130 |
+
return callback->channel->Write(callback->channel, (ULONG)Stream_Length(s), Stream_Buffer(s),
|
| 131 |
+
NULL);
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
/**
|
| 135 |
+
* Function description
|
| 136 |
+
*
|
| 137 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 138 |
+
*/
|
| 139 |
+
static UINT ainput_on_close(IWTSVirtualChannelCallback* pChannelCallback)
|
| 140 |
+
{
|
| 141 |
+
GENERIC_CHANNEL_CALLBACK* callback = (GENERIC_CHANNEL_CALLBACK*)pChannelCallback;
|
| 142 |
+
|
| 143 |
+
free(callback);
|
| 144 |
+
|
| 145 |
+
return CHANNEL_RC_OK;
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
static UINT init_plugin_cb(GENERIC_DYNVC_PLUGIN* base, rdpContext* rcontext, rdpSettings* settings)
|
| 149 |
+
{
|
| 150 |
+
AINPUT_PLUGIN* ainput = (AINPUT_PLUGIN*)base;
|
| 151 |
+
AInputClientContext* context = (AInputClientContext*)calloc(1, sizeof(AInputClientContext));
|
| 152 |
+
if (!context)
|
| 153 |
+
return CHANNEL_RC_NO_MEMORY;
|
| 154 |
+
|
| 155 |
+
context->handle = (void*)base;
|
| 156 |
+
context->AInputSendInputEvent = ainput_send_input_event;
|
| 157 |
+
|
| 158 |
+
ainput->context = context;
|
| 159 |
+
ainput->base.iface.pInterface = context;
|
| 160 |
+
return CHANNEL_RC_OK;
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
static void terminate_plugin_cb(GENERIC_DYNVC_PLUGIN* base)
|
| 164 |
+
{
|
| 165 |
+
AINPUT_PLUGIN* ainput = (AINPUT_PLUGIN*)base;
|
| 166 |
+
free(ainput->context);
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
static const IWTSVirtualChannelCallback ainput_functions = { ainput_on_data_received,
|
| 170 |
+
NULL, /* Open */
|
| 171 |
+
ainput_on_close, NULL };
|
| 172 |
+
|
| 173 |
+
/**
|
| 174 |
+
* Function description
|
| 175 |
+
*
|
| 176 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 177 |
+
*/
|
| 178 |
+
FREERDP_ENTRY_POINT(UINT VCAPITYPE ainput_DVCPluginEntry(IDRDYNVC_ENTRY_POINTS* pEntryPoints))
|
| 179 |
+
{
|
| 180 |
+
return freerdp_generic_DVCPluginEntry(pEntryPoints, TAG, AINPUT_DVC_CHANNEL_NAME,
|
| 181 |
+
sizeof(AINPUT_PLUGIN), sizeof(GENERIC_CHANNEL_CALLBACK),
|
| 182 |
+
&ainput_functions, init_plugin_cb, terminate_plugin_cb);
|
| 183 |
+
}
|
local-test-freerdp-delta-01/afc-freerdp/channels/ainput/client/ainput_main.h
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* FreeRDP: A Remote Desktop Protocol Implementation
|
| 3 |
+
* Advanced Input Virtual Channel Extension
|
| 4 |
+
*
|
| 5 |
+
* Copyright 2022 Armin Novak <anovak@thincast.com>
|
| 6 |
+
* Copyright 2022 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 |
+
#ifndef FREERDP_CHANNEL_AINPUT_CLIENT_MAIN_H
|
| 22 |
+
#define FREERDP_CHANNEL_AINPUT_CLIENT_MAIN_H
|
| 23 |
+
|
| 24 |
+
#include <freerdp/config.h>
|
| 25 |
+
#include <freerdp/dvc.h>
|
| 26 |
+
#include <freerdp/types.h>
|
| 27 |
+
#include <freerdp/addin.h>
|
| 28 |
+
#include <freerdp/channels/log.h>
|
| 29 |
+
|
| 30 |
+
#define DVC_TAG CHANNELS_TAG("ainput.client")
|
| 31 |
+
#ifdef WITH_DEBUG_DVC
|
| 32 |
+
#define DEBUG_DVC(...) WLog_DBG(DVC_TAG, __VA_ARGS__)
|
| 33 |
+
#else
|
| 34 |
+
#define DEBUG_DVC(...) \
|
| 35 |
+
do \
|
| 36 |
+
{ \
|
| 37 |
+
} while (0)
|
| 38 |
+
#endif
|
| 39 |
+
|
| 40 |
+
#endif /* FREERDP_CHANNEL_AINPUT_CLIENT_MAIN_H */
|
local-test-freerdp-delta-01/afc-freerdp/channels/ainput/common/ainput_common.h
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* FreeRDP: A Remote Desktop Protocol Implementation
|
| 3 |
+
* Audio Input Redirection Virtual Channel
|
| 4 |
+
*
|
| 5 |
+
* Copyright 2022 Armin Novak <anovak@thincast.com>
|
| 6 |
+
* Copyright 2022 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 |
+
#ifndef FREERDP_INT_AINPUT_COMMON_H
|
| 22 |
+
#define FREERDP_INT_AINPUT_COMMON_H
|
| 23 |
+
|
| 24 |
+
#include <winpr/string.h>
|
| 25 |
+
|
| 26 |
+
#include <freerdp/channels/ainput.h>
|
| 27 |
+
|
| 28 |
+
static INLINE const char* ainput_flags_to_string(UINT64 flags, char* buffer, size_t size)
|
| 29 |
+
{
|
| 30 |
+
char number[32] = { 0 };
|
| 31 |
+
|
| 32 |
+
if (flags & AINPUT_FLAGS_HAVE_REL)
|
| 33 |
+
winpr_str_append("AINPUT_FLAGS_HAVE_REL", buffer, size, "|");
|
| 34 |
+
if (flags & AINPUT_FLAGS_WHEEL)
|
| 35 |
+
winpr_str_append("AINPUT_FLAGS_WHEEL", buffer, size, "|");
|
| 36 |
+
if (flags & AINPUT_FLAGS_MOVE)
|
| 37 |
+
winpr_str_append("AINPUT_FLAGS_MOVE", buffer, size, "|");
|
| 38 |
+
if (flags & AINPUT_FLAGS_DOWN)
|
| 39 |
+
winpr_str_append("AINPUT_FLAGS_DOWN", buffer, size, "|");
|
| 40 |
+
if (flags & AINPUT_FLAGS_REL)
|
| 41 |
+
winpr_str_append("AINPUT_FLAGS_REL", buffer, size, "|");
|
| 42 |
+
if (flags & AINPUT_FLAGS_BUTTON1)
|
| 43 |
+
winpr_str_append("AINPUT_FLAGS_BUTTON1", buffer, size, "|");
|
| 44 |
+
if (flags & AINPUT_FLAGS_BUTTON2)
|
| 45 |
+
winpr_str_append("AINPUT_FLAGS_BUTTON2", buffer, size, "|");
|
| 46 |
+
if (flags & AINPUT_FLAGS_BUTTON3)
|
| 47 |
+
winpr_str_append("AINPUT_FLAGS_BUTTON3", buffer, size, "|");
|
| 48 |
+
if (flags & AINPUT_XFLAGS_BUTTON1)
|
| 49 |
+
winpr_str_append("AINPUT_XFLAGS_BUTTON1", buffer, size, "|");
|
| 50 |
+
if (flags & AINPUT_XFLAGS_BUTTON2)
|
| 51 |
+
winpr_str_append("AINPUT_XFLAGS_BUTTON2", buffer, size, "|");
|
| 52 |
+
|
| 53 |
+
_snprintf(number, sizeof(number), "[0x%08" PRIx64 "]", flags);
|
| 54 |
+
winpr_str_append(number, buffer, size, " ");
|
| 55 |
+
|
| 56 |
+
return buffer;
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
#endif /* FREERDP_INT_AINPUT_COMMON_H */
|
local-test-freerdp-delta-01/afc-freerdp/channels/ainput/server/CMakeLists.txt
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# FreeRDP: A Remote Desktop Protocol Implementation
|
| 2 |
+
# FreeRDP cmake build script
|
| 3 |
+
#
|
| 4 |
+
# Copyright 2022 Armin Novak <anovak@thincast.com>
|
| 5 |
+
# Copyright 2022 Thincast Technologies GmbH
|
| 6 |
+
#
|
| 7 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 8 |
+
# you may not use this file except in compliance with the License.
|
| 9 |
+
# You may obtain a copy of the License at
|
| 10 |
+
#
|
| 11 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
+
#
|
| 13 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 14 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 15 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 16 |
+
# See the License for the specific language governing permissions and
|
| 17 |
+
# limitations under the License.
|
| 18 |
+
|
| 19 |
+
define_channel_server("ainput")
|
| 20 |
+
|
| 21 |
+
set(${MODULE_PREFIX}_SRCS ainput_main.c)
|
| 22 |
+
|
| 23 |
+
set(${MODULE_PREFIX}_L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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* FreeRDP: A Remote Desktop Protocol Implementation
|
| 3 |
+
* Advanced Input Virtual Channel Extension
|
| 4 |
+
*
|
| 5 |
+
* Copyright 2022 Armin Novak <anovak@thincast.com>
|
| 6 |
+
* Copyright 2022 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/assert.h>
|
| 29 |
+
#include <winpr/synch.h>
|
| 30 |
+
#include <winpr/thread.h>
|
| 31 |
+
#include <winpr/stream.h>
|
| 32 |
+
#include <winpr/sysinfo.h>
|
| 33 |
+
|
| 34 |
+
#include <freerdp/freerdp.h>
|
| 35 |
+
#include <freerdp/channels/ainput.h>
|
| 36 |
+
#include <freerdp/server/ainput.h>
|
| 37 |
+
#include <freerdp/channels/log.h>
|
| 38 |
+
|
| 39 |
+
#include "../common/ainput_common.h"
|
| 40 |
+
|
| 41 |
+
#define TAG CHANNELS_TAG("ainput.server")
|
| 42 |
+
|
| 43 |
+
typedef enum
|
| 44 |
+
{
|
| 45 |
+
AINPUT_INITIAL,
|
| 46 |
+
AINPUT_OPENED,
|
| 47 |
+
AINPUT_VERSION_SENT,
|
| 48 |
+
} eAInputChannelState;
|
| 49 |
+
|
| 50 |
+
typedef struct
|
| 51 |
+
{
|
| 52 |
+
ainput_server_context context;
|
| 53 |
+
|
| 54 |
+
BOOL opened;
|
| 55 |
+
|
| 56 |
+
HANDLE stopEvent;
|
| 57 |
+
|
| 58 |
+
HANDLE thread;
|
| 59 |
+
void* ainput_channel;
|
| 60 |
+
|
| 61 |
+
DWORD SessionId;
|
| 62 |
+
|
| 63 |
+
BOOL isOpened;
|
| 64 |
+
BOOL externalThread;
|
| 65 |
+
|
| 66 |
+
/* Channel state */
|
| 67 |
+
eAInputChannelState state;
|
| 68 |
+
|
| 69 |
+
wStream* buffer;
|
| 70 |
+
} ainput_server;
|
| 71 |
+
|
| 72 |
+
static UINT ainput_server_context_poll(ainput_server_context* context);
|
| 73 |
+
static BOOL ainput_server_context_handle(ainput_server_context* context, HANDLE* handle);
|
| 74 |
+
static UINT ainput_server_context_poll_int(ainput_server_context* context);
|
| 75 |
+
|
| 76 |
+
static BOOL ainput_server_is_open(ainput_server_context* context)
|
| 77 |
+
{
|
| 78 |
+
ainput_server* ainput = (ainput_server*)context;
|
| 79 |
+
|
| 80 |
+
WINPR_ASSERT(ainput);
|
| 81 |
+
return ainput->isOpened;
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
/**
|
| 85 |
+
* Function description
|
| 86 |
+
*
|
| 87 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 88 |
+
*/
|
| 89 |
+
static UINT ainput_server_open_channel(ainput_server* ainput)
|
| 90 |
+
{
|
| 91 |
+
DWORD Error = 0;
|
| 92 |
+
HANDLE hEvent = NULL;
|
| 93 |
+
DWORD StartTick = 0;
|
| 94 |
+
DWORD BytesReturned = 0;
|
| 95 |
+
PULONG pSessionId = NULL;
|
| 96 |
+
|
| 97 |
+
WINPR_ASSERT(ainput);
|
| 98 |
+
|
| 99 |
+
if (WTSQuerySessionInformationA(ainput->context.vcm, WTS_CURRENT_SESSION, WTSSessionId,
|
| 100 |
+
(LPSTR*)&pSessionId, &BytesReturned) == FALSE)
|
| 101 |
+
{
|
| 102 |
+
WLog_ERR(TAG, "WTSQuerySessionInformationA failed!");
|
| 103 |
+
return ERROR_INTERNAL_ERROR;
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
ainput->SessionId = (DWORD)*pSessionId;
|
| 107 |
+
WTSFreeMemory(pSessionId);
|
| 108 |
+
hEvent = WTSVirtualChannelManagerGetEventHandle(ainput->context.vcm);
|
| 109 |
+
StartTick = GetTickCount();
|
| 110 |
+
|
| 111 |
+
while (ainput->ainput_channel == NULL)
|
| 112 |
+
{
|
| 113 |
+
if (WaitForSingleObject(hEvent, 1000) == WAIT_FAILED)
|
| 114 |
+
{
|
| 115 |
+
Error = GetLastError();
|
| 116 |
+
WLog_ERR(TAG, "WaitForSingleObject failed with error %" PRIu32 "!", Error);
|
| 117 |
+
return Error;
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
ainput->ainput_channel = WTSVirtualChannelOpenEx(ainput->SessionId, AINPUT_DVC_CHANNEL_NAME,
|
| 121 |
+
WTS_CHANNEL_OPTION_DYNAMIC);
|
| 122 |
+
|
| 123 |
+
Error = GetLastError();
|
| 124 |
+
|
| 125 |
+
if (Error == ERROR_NOT_FOUND)
|
| 126 |
+
{
|
| 127 |
+
WLog_DBG(TAG, "Channel %s not found", AINPUT_DVC_CHANNEL_NAME);
|
| 128 |
+
break;
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
if (ainput->ainput_channel)
|
| 132 |
+
{
|
| 133 |
+
UINT32 channelId = 0;
|
| 134 |
+
BOOL status = TRUE;
|
| 135 |
+
|
| 136 |
+
channelId = WTSChannelGetIdByHandle(ainput->ainput_channel);
|
| 137 |
+
|
| 138 |
+
IFCALLRET(ainput->context.ChannelIdAssigned, status, &ainput->context, channelId);
|
| 139 |
+
if (!status)
|
| 140 |
+
{
|
| 141 |
+
WLog_ERR(TAG, "context->ChannelIdAssigned failed!");
|
| 142 |
+
return ERROR_INTERNAL_ERROR;
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
break;
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
if (GetTickCount() - StartTick > 5000)
|
| 149 |
+
{
|
| 150 |
+
WLog_WARN(TAG, "Timeout opening channel %s", AINPUT_DVC_CHANNEL_NAME);
|
| 151 |
+
break;
|
| 152 |
+
}
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
return ainput->ainput_channel ? CHANNEL_RC_OK : ERROR_INTERNAL_ERROR;
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
static UINT ainput_server_send_version(ainput_server* ainput)
|
| 159 |
+
{
|
| 160 |
+
ULONG written = 0;
|
| 161 |
+
wStream* s = NULL;
|
| 162 |
+
|
| 163 |
+
WINPR_ASSERT(ainput);
|
| 164 |
+
|
| 165 |
+
s = ainput->buffer;
|
| 166 |
+
WINPR_ASSERT(s);
|
| 167 |
+
|
| 168 |
+
Stream_SetPosition(s, 0);
|
| 169 |
+
if (!Stream_EnsureCapacity(s, 10))
|
| 170 |
+
{
|
| 171 |
+
WLog_WARN(TAG, "[%s] out of memory", AINPUT_DVC_CHANNEL_NAME);
|
| 172 |
+
return ERROR_OUTOFMEMORY;
|
| 173 |
+
}
|
| 174 |
+
|
| 175 |
+
Stream_Write_UINT16(s, MSG_AINPUT_VERSION);
|
| 176 |
+
Stream_Write_UINT32(s, AINPUT_VERSION_MAJOR); /* Version (4 bytes) */
|
| 177 |
+
Stream_Write_UINT32(s, AINPUT_VERSION_MINOR); /* Version (4 bytes) */
|
| 178 |
+
|
| 179 |
+
WINPR_ASSERT(Stream_GetPosition(s) <= UINT32_MAX);
|
| 180 |
+
if (!WTSVirtualChannelWrite(ainput->ainput_channel, Stream_BufferAs(s, char),
|
| 181 |
+
(ULONG)Stream_GetPosition(s), &written))
|
| 182 |
+
{
|
| 183 |
+
WLog_ERR(TAG, "WTSVirtualChannelWrite failed!");
|
| 184 |
+
return ERROR_INTERNAL_ERROR;
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
return CHANNEL_RC_OK;
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
static UINT ainput_server_recv_mouse_event(ainput_server* ainput, wStream* s)
|
| 191 |
+
{
|
| 192 |
+
UINT error = CHANNEL_RC_OK;
|
| 193 |
+
UINT64 flags = 0;
|
| 194 |
+
UINT64 time = 0;
|
| 195 |
+
INT32 x = 0;
|
| 196 |
+
INT32 y = 0;
|
| 197 |
+
char buffer[128] = { 0 };
|
| 198 |
+
|
| 199 |
+
WINPR_ASSERT(ainput);
|
| 200 |
+
WINPR_ASSERT(s);
|
| 201 |
+
|
| 202 |
+
if (!Stream_CheckAndLogRequiredLength(TAG, s, 24))
|
| 203 |
+
return ERROR_NO_DATA;
|
| 204 |
+
|
| 205 |
+
Stream_Read_UINT64(s, time);
|
| 206 |
+
Stream_Read_UINT64(s, flags);
|
| 207 |
+
Stream_Read_INT32(s, x);
|
| 208 |
+
Stream_Read_INT32(s, y);
|
| 209 |
+
|
| 210 |
+
WLog_VRB(TAG, "received: time=0x%08" PRIx64 ", flags=%s, %" PRId32 "x%" PRId32, time,
|
| 211 |
+
ainput_flags_to_string(flags, buffer, sizeof(buffer)), x, y);
|
| 212 |
+
IFCALLRET(ainput->context.MouseEvent, error, &ainput->context, time, flags, x, y);
|
| 213 |
+
|
| 214 |
+
return error;
|
| 215 |
+
}
|
| 216 |
+
|
| 217 |
+
static HANDLE ainput_server_get_channel_handle(ainput_server* ainput)
|
| 218 |
+
{
|
| 219 |
+
void* buffer = NULL;
|
| 220 |
+
DWORD BytesReturned = 0;
|
| 221 |
+
HANDLE ChannelEvent = NULL;
|
| 222 |
+
|
| 223 |
+
WINPR_ASSERT(ainput);
|
| 224 |
+
|
| 225 |
+
if (WTSVirtualChannelQuery(ainput->ainput_channel, WTSVirtualEventHandle, &buffer,
|
| 226 |
+
&BytesReturned) == TRUE)
|
| 227 |
+
{
|
| 228 |
+
if (BytesReturned == sizeof(HANDLE))
|
| 229 |
+
ChannelEvent = *(HANDLE*)buffer;
|
| 230 |
+
|
| 231 |
+
WTSFreeMemory(buffer);
|
| 232 |
+
}
|
| 233 |
+
|
| 234 |
+
return ChannelEvent;
|
| 235 |
+
}
|
| 236 |
+
|
| 237 |
+
static DWORD WINAPI ainput_server_thread_func(LPVOID arg)
|
| 238 |
+
{
|
| 239 |
+
DWORD nCount = 0;
|
| 240 |
+
HANDLE events[2] = { 0 };
|
| 241 |
+
ainput_server* ainput = (ainput_server*)arg;
|
| 242 |
+
UINT error = CHANNEL_RC_OK;
|
| 243 |
+
DWORD status = 0;
|
| 244 |
+
|
| 245 |
+
WINPR_ASSERT(ainput);
|
| 246 |
+
|
| 247 |
+
nCount = 0;
|
| 248 |
+
events[nCount++] = ainput->stopEvent;
|
| 249 |
+
|
| 250 |
+
while ((error == CHANNEL_RC_OK) && (WaitForSingleObject(events[0], 0) != WAIT_OBJECT_0))
|
| 251 |
+
{
|
| 252 |
+
switch (ainput->state)
|
| 253 |
+
{
|
| 254 |
+
case AINPUT_OPENED:
|
| 255 |
+
events[1] = ainput_server_get_channel_handle(ainput);
|
| 256 |
+
nCount = 2;
|
| 257 |
+
status = WaitForMultipleObjects(nCount, events, FALSE, 100);
|
| 258 |
+
switch (status)
|
| 259 |
+
{
|
| 260 |
+
case WAIT_TIMEOUT:
|
| 261 |
+
case WAIT_OBJECT_0 + 1:
|
| 262 |
+
case WAIT_OBJECT_0:
|
| 263 |
+
error = ainput_server_context_poll_int(&ainput->context);
|
| 264 |
+
break;
|
| 265 |
+
case WAIT_FAILED:
|
| 266 |
+
default:
|
| 267 |
+
WLog_WARN(TAG, "[%s] Wait for open failed", AINPUT_DVC_CHANNEL_NAME);
|
| 268 |
+
error = ERROR_INTERNAL_ERROR;
|
| 269 |
+
break;
|
| 270 |
+
}
|
| 271 |
+
break;
|
| 272 |
+
case AINPUT_VERSION_SENT:
|
| 273 |
+
status = WaitForMultipleObjects(nCount, events, FALSE, INFINITE);
|
| 274 |
+
switch (status)
|
| 275 |
+
{
|
| 276 |
+
case WAIT_TIMEOUT:
|
| 277 |
+
case WAIT_OBJECT_0 + 1:
|
| 278 |
+
case WAIT_OBJECT_0:
|
| 279 |
+
error = ainput_server_context_poll_int(&ainput->context);
|
| 280 |
+
break;
|
| 281 |
+
|
| 282 |
+
case WAIT_FAILED:
|
| 283 |
+
default:
|
| 284 |
+
WLog_WARN(TAG, "[%s] Wait for version failed", AINPUT_DVC_CHANNEL_NAME);
|
| 285 |
+
error = ERROR_INTERNAL_ERROR;
|
| 286 |
+
break;
|
| 287 |
+
}
|
| 288 |
+
break;
|
| 289 |
+
default:
|
| 290 |
+
error = ainput_server_context_poll_int(&ainput->context);
|
| 291 |
+
break;
|
| 292 |
+
}
|
| 293 |
+
}
|
| 294 |
+
|
| 295 |
+
(void)WTSVirtualChannelClose(ainput->ainput_channel);
|
| 296 |
+
ainput->ainput_channel = NULL;
|
| 297 |
+
|
| 298 |
+
if (error && ainput->context.rdpcontext)
|
| 299 |
+
setChannelError(ainput->context.rdpcontext, error,
|
| 300 |
+
"ainput_server_thread_func reported an error");
|
| 301 |
+
|
| 302 |
+
ExitThread(error);
|
| 303 |
+
return error;
|
| 304 |
+
}
|
| 305 |
+
|
| 306 |
+
/**
|
| 307 |
+
* Function description
|
| 308 |
+
*
|
| 309 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 310 |
+
*/
|
| 311 |
+
static UINT ainput_server_open(ainput_server_context* context)
|
| 312 |
+
{
|
| 313 |
+
ainput_server* ainput = (ainput_server*)context;
|
| 314 |
+
|
| 315 |
+
WINPR_ASSERT(ainput);
|
| 316 |
+
|
| 317 |
+
if (!ainput->externalThread && (ainput->thread == NULL))
|
| 318 |
+
{
|
| 319 |
+
ainput->stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
|
| 320 |
+
if (!ainput->stopEvent)
|
| 321 |
+
{
|
| 322 |
+
WLog_ERR(TAG, "CreateEvent failed!");
|
| 323 |
+
return ERROR_INTERNAL_ERROR;
|
| 324 |
+
}
|
| 325 |
+
|
| 326 |
+
ainput->thread = CreateThread(NULL, 0, ainput_server_thread_func, ainput, 0, NULL);
|
| 327 |
+
if (!ainput->thread)
|
| 328 |
+
{
|
| 329 |
+
WLog_ERR(TAG, "CreateEvent failed!");
|
| 330 |
+
(void)CloseHandle(ainput->stopEvent);
|
| 331 |
+
ainput->stopEvent = NULL;
|
| 332 |
+
return ERROR_INTERNAL_ERROR;
|
| 333 |
+
}
|
| 334 |
+
}
|
| 335 |
+
ainput->isOpened = TRUE;
|
| 336 |
+
|
| 337 |
+
return CHANNEL_RC_OK;
|
| 338 |
+
}
|
| 339 |
+
|
| 340 |
+
/**
|
| 341 |
+
* Function description
|
| 342 |
+
*
|
| 343 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 344 |
+
*/
|
| 345 |
+
static UINT ainput_server_close(ainput_server_context* context)
|
| 346 |
+
{
|
| 347 |
+
UINT error = CHANNEL_RC_OK;
|
| 348 |
+
ainput_server* ainput = (ainput_server*)context;
|
| 349 |
+
|
| 350 |
+
WINPR_ASSERT(ainput);
|
| 351 |
+
|
| 352 |
+
if (!ainput->externalThread && ainput->thread)
|
| 353 |
+
{
|
| 354 |
+
(void)SetEvent(ainput->stopEvent);
|
| 355 |
+
|
| 356 |
+
if (WaitForSingleObject(ainput->thread, INFINITE) == WAIT_FAILED)
|
| 357 |
+
{
|
| 358 |
+
error = GetLastError();
|
| 359 |
+
WLog_ERR(TAG, "WaitForSingleObject failed with error %" PRIu32 "", error);
|
| 360 |
+
return error;
|
| 361 |
+
}
|
| 362 |
+
|
| 363 |
+
(void)CloseHandle(ainput->thread);
|
| 364 |
+
(void)CloseHandle(ainput->stopEvent);
|
| 365 |
+
ainput->thread = NULL;
|
| 366 |
+
ainput->stopEvent = NULL;
|
| 367 |
+
}
|
| 368 |
+
if (ainput->externalThread)
|
| 369 |
+
{
|
| 370 |
+
if (ainput->state != AINPUT_INITIAL)
|
| 371 |
+
{
|
| 372 |
+
(void)WTSVirtualChannelClose(ainput->ainput_channel);
|
| 373 |
+
ainput->ainput_channel = NULL;
|
| 374 |
+
ainput->state = AINPUT_INITIAL;
|
| 375 |
+
}
|
| 376 |
+
}
|
| 377 |
+
ainput->isOpened = FALSE;
|
| 378 |
+
|
| 379 |
+
return error;
|
| 380 |
+
}
|
| 381 |
+
|
| 382 |
+
static UINT ainput_server_initialize(ainput_server_context* context, BOOL externalThread)
|
| 383 |
+
{
|
| 384 |
+
UINT error = CHANNEL_RC_OK;
|
| 385 |
+
ainput_server* ainput = (ainput_server*)context;
|
| 386 |
+
|
| 387 |
+
WINPR_ASSERT(ainput);
|
| 388 |
+
|
| 389 |
+
if (ainput->isOpened)
|
| 390 |
+
{
|
| 391 |
+
WLog_WARN(TAG, "Application error: AINPUT channel already initialized, calling in this "
|
| 392 |
+
"state is not possible!");
|
| 393 |
+
return ERROR_INVALID_STATE;
|
| 394 |
+
}
|
| 395 |
+
ainput->externalThread = externalThread;
|
| 396 |
+
return error;
|
| 397 |
+
}
|
| 398 |
+
|
| 399 |
+
ainput_server_context* ainput_server_context_new(HANDLE vcm)
|
| 400 |
+
{
|
| 401 |
+
ainput_server* ainput = (ainput_server*)calloc(1, sizeof(ainput_server));
|
| 402 |
+
|
| 403 |
+
if (!ainput)
|
| 404 |
+
return NULL;
|
| 405 |
+
|
| 406 |
+
ainput->context.vcm = vcm;
|
| 407 |
+
ainput->context.Open = ainput_server_open;
|
| 408 |
+
ainput->context.IsOpen = ainput_server_is_open;
|
| 409 |
+
ainput->context.Close = ainput_server_close;
|
| 410 |
+
ainput->context.Initialize = ainput_server_initialize;
|
| 411 |
+
ainput->context.Poll = ainput_server_context_poll;
|
| 412 |
+
ainput->context.ChannelHandle = ainput_server_context_handle;
|
| 413 |
+
|
| 414 |
+
ainput->buffer = Stream_New(NULL, 4096);
|
| 415 |
+
if (!ainput->buffer)
|
| 416 |
+
goto fail;
|
| 417 |
+
return &ainput->context;
|
| 418 |
+
fail:
|
| 419 |
+
WINPR_PRAGMA_DIAG_PUSH
|
| 420 |
+
WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
|
| 421 |
+
ainput_server_context_free(&ainput->context);
|
| 422 |
+
WINPR_PRAGMA_DIAG_POP
|
| 423 |
+
return NULL;
|
| 424 |
+
}
|
| 425 |
+
|
| 426 |
+
void ainput_server_context_free(ainput_server_context* context)
|
| 427 |
+
{
|
| 428 |
+
ainput_server* ainput = (ainput_server*)context;
|
| 429 |
+
if (ainput)
|
| 430 |
+
{
|
| 431 |
+
ainput_server_close(context);
|
| 432 |
+
Stream_Free(ainput->buffer, TRUE);
|
| 433 |
+
}
|
| 434 |
+
free(ainput);
|
| 435 |
+
}
|
| 436 |
+
|
| 437 |
+
static UINT ainput_process_message(ainput_server* ainput)
|
| 438 |
+
{
|
| 439 |
+
BOOL rc = 0;
|
| 440 |
+
UINT error = ERROR_INTERNAL_ERROR;
|
| 441 |
+
ULONG BytesReturned = 0;
|
| 442 |
+
ULONG ActualBytesReturned = 0;
|
| 443 |
+
UINT16 MessageId = 0;
|
| 444 |
+
wStream* s = NULL;
|
| 445 |
+
|
| 446 |
+
WINPR_ASSERT(ainput);
|
| 447 |
+
WINPR_ASSERT(ainput->ainput_channel);
|
| 448 |
+
|
| 449 |
+
s = ainput->buffer;
|
| 450 |
+
WINPR_ASSERT(s);
|
| 451 |
+
|
| 452 |
+
Stream_SetPosition(s, 0);
|
| 453 |
+
rc = WTSVirtualChannelRead(ainput->ainput_channel, 0, NULL, 0, &BytesReturned);
|
| 454 |
+
if (!rc)
|
| 455 |
+
goto out;
|
| 456 |
+
|
| 457 |
+
if (BytesReturned < 2)
|
| 458 |
+
{
|
| 459 |
+
error = CHANNEL_RC_OK;
|
| 460 |
+
goto out;
|
| 461 |
+
}
|
| 462 |
+
|
| 463 |
+
if (!Stream_EnsureRemainingCapacity(s, BytesReturned))
|
| 464 |
+
{
|
| 465 |
+
WLog_ERR(TAG, "Stream_EnsureRemainingCapacity failed!");
|
| 466 |
+
error = CHANNEL_RC_NO_MEMORY;
|
| 467 |
+
goto out;
|
| 468 |
+
}
|
| 469 |
+
|
| 470 |
+
if (WTSVirtualChannelRead(ainput->ainput_channel, 0, Stream_BufferAs(s, char),
|
| 471 |
+
(ULONG)Stream_Capacity(s), &ActualBytesReturned) == FALSE)
|
| 472 |
+
{
|
| 473 |
+
WLog_ERR(TAG, "WTSVirtualChannelRead failed!");
|
| 474 |
+
goto out;
|
| 475 |
+
}
|
| 476 |
+
|
| 477 |
+
if (BytesReturned != ActualBytesReturned)
|
| 478 |
+
{
|
| 479 |
+
WLog_ERR(TAG, "WTSVirtualChannelRead size mismatch %" PRId32 ", expected %" PRId32,
|
| 480 |
+
ActualBytesReturned, BytesReturned);
|
| 481 |
+
goto out;
|
| 482 |
+
}
|
| 483 |
+
|
| 484 |
+
Stream_SetLength(s, ActualBytesReturned);
|
| 485 |
+
Stream_Read_UINT16(s, MessageId);
|
| 486 |
+
|
| 487 |
+
switch (MessageId)
|
| 488 |
+
{
|
| 489 |
+
case MSG_AINPUT_MOUSE:
|
| 490 |
+
error = ainput_server_recv_mouse_event(ainput, s);
|
| 491 |
+
break;
|
| 492 |
+
|
| 493 |
+
default:
|
| 494 |
+
WLog_ERR(TAG, "audin_server_thread_func: unknown MessageId %" PRIu8 "", MessageId);
|
| 495 |
+
break;
|
| 496 |
+
}
|
| 497 |
+
|
| 498 |
+
out:
|
| 499 |
+
if (error)
|
| 500 |
+
WLog_ERR(TAG, "Response failed with error %" PRIu32 "!", error);
|
| 501 |
+
|
| 502 |
+
return error;
|
| 503 |
+
}
|
| 504 |
+
|
| 505 |
+
BOOL ainput_server_context_handle(ainput_server_context* context, HANDLE* handle)
|
| 506 |
+
{
|
| 507 |
+
ainput_server* ainput = (ainput_server*)context;
|
| 508 |
+
WINPR_ASSERT(ainput);
|
| 509 |
+
WINPR_ASSERT(handle);
|
| 510 |
+
|
| 511 |
+
if (!ainput->externalThread)
|
| 512 |
+
{
|
| 513 |
+
WLog_WARN(TAG, "[%s] externalThread fail!", AINPUT_DVC_CHANNEL_NAME);
|
| 514 |
+
return FALSE;
|
| 515 |
+
}
|
| 516 |
+
if (ainput->state == AINPUT_INITIAL)
|
| 517 |
+
{
|
| 518 |
+
WLog_WARN(TAG, "[%s] state fail!", AINPUT_DVC_CHANNEL_NAME);
|
| 519 |
+
return FALSE;
|
| 520 |
+
}
|
| 521 |
+
*handle = ainput_server_get_channel_handle(ainput);
|
| 522 |
+
return TRUE;
|
| 523 |
+
}
|
| 524 |
+
|
| 525 |
+
UINT ainput_server_context_poll_int(ainput_server_context* context)
|
| 526 |
+
{
|
| 527 |
+
ainput_server* ainput = (ainput_server*)context;
|
| 528 |
+
UINT error = ERROR_INTERNAL_ERROR;
|
| 529 |
+
|
| 530 |
+
WINPR_ASSERT(ainput);
|
| 531 |
+
|
| 532 |
+
switch (ainput->state)
|
| 533 |
+
{
|
| 534 |
+
case AINPUT_INITIAL:
|
| 535 |
+
error = ainput_server_open_channel(ainput);
|
| 536 |
+
if (error)
|
| 537 |
+
WLog_ERR(TAG, "ainput_server_open_channel failed with error %" PRIu32 "!", error);
|
| 538 |
+
else
|
| 539 |
+
ainput->state = AINPUT_OPENED;
|
| 540 |
+
break;
|
| 541 |
+
case AINPUT_OPENED:
|
| 542 |
+
{
|
| 543 |
+
union
|
| 544 |
+
{
|
| 545 |
+
BYTE* pb;
|
| 546 |
+
void* pv;
|
| 547 |
+
} buffer;
|
| 548 |
+
DWORD BytesReturned = 0;
|
| 549 |
+
|
| 550 |
+
buffer.pv = NULL;
|
| 551 |
+
|
| 552 |
+
if (WTSVirtualChannelQuery(ainput->ainput_channel, WTSVirtualChannelReady, &buffer.pv,
|
| 553 |
+
&BytesReturned) != TRUE)
|
| 554 |
+
{
|
| 555 |
+
WLog_ERR(TAG, "WTSVirtualChannelReady failed,");
|
| 556 |
+
}
|
| 557 |
+
else
|
| 558 |
+
{
|
| 559 |
+
if (*buffer.pb != 0)
|
| 560 |
+
{
|
| 561 |
+
error = ainput_server_send_version(ainput);
|
| 562 |
+
if (error)
|
| 563 |
+
WLog_ERR(TAG, "audin_server_send_version failed with error %" PRIu32 "!",
|
| 564 |
+
error);
|
| 565 |
+
else
|
| 566 |
+
ainput->state = AINPUT_VERSION_SENT;
|
| 567 |
+
}
|
| 568 |
+
else
|
| 569 |
+
error = CHANNEL_RC_OK;
|
| 570 |
+
}
|
| 571 |
+
WTSFreeMemory(buffer.pv);
|
| 572 |
+
}
|
| 573 |
+
break;
|
| 574 |
+
case AINPUT_VERSION_SENT:
|
| 575 |
+
error = ainput_process_message(ainput);
|
| 576 |
+
break;
|
| 577 |
+
|
| 578 |
+
default:
|
| 579 |
+
WLog_ERR(TAG, "AINPUT channel is in invalid state %d", ainput->state);
|
| 580 |
+
break;
|
| 581 |
+
}
|
| 582 |
+
|
| 583 |
+
return error;
|
| 584 |
+
}
|
| 585 |
+
|
| 586 |
+
UINT ainput_server_context_poll(ainput_server_context* context)
|
| 587 |
+
{
|
| 588 |
+
ainput_server* ainput = (ainput_server*)context;
|
| 589 |
+
|
| 590 |
+
WINPR_ASSERT(ainput);
|
| 591 |
+
if (!ainput->externalThread)
|
| 592 |
+
{
|
| 593 |
+
WLog_WARN(TAG, "[%s] externalThread fail!", AINPUT_DVC_CHANNEL_NAME);
|
| 594 |
+
return ERROR_INTERNAL_ERROR;
|
| 595 |
+
}
|
| 596 |
+
return ainput_server_context_poll_int(context);
|
| 597 |
+
}
|
local-test-freerdp-delta-01/afc-freerdp/channels/audin/CMakeLists.txt
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# FreeRDP: A Remote Desktop Protocol Implementation
|
| 2 |
+
# FreeRDP cmake build script
|
| 3 |
+
#
|
| 4 |
+
# Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
| 5 |
+
#
|
| 6 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 7 |
+
# you may not use this file except in compliance with the License.
|
| 8 |
+
# You may obtain a copy of the License at
|
| 9 |
+
#
|
| 10 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 11 |
+
#
|
| 12 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 13 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 14 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 15 |
+
# See the License for the specific language governing permissions and
|
| 16 |
+
# limitations under the License.
|
| 17 |
+
|
| 18 |
+
define_channel("audin")
|
| 19 |
+
|
| 20 |
+
if(WITH_CLIENT_CHANNELS)
|
| 21 |
+
add_channel_client(${MODULE_PREFIX} ${CHANNEL_NAME})
|
| 22 |
+
endif()
|
| 23 |
+
|
| 24 |
+
if(WITH_SERVER_CHANNELS)
|
| 25 |
+
add_channel_server(${MODULE_PREFIX} ${CHANNEL_NAME})
|
| 26 |
+
endif()
|
local-test-freerdp-delta-01/afc-freerdp/channels/audin/ChannelOptions.cmake
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
set(OPTION_DEFAULT ON)
|
| 2 |
+
set(OPTION_CLIENT_DEFAULT ON)
|
| 3 |
+
set(OPTION_SERVER_DEFAULT ON)
|
| 4 |
+
|
| 5 |
+
if(ANDROID)
|
| 6 |
+
set(OPTION_SERVER_DEFAULT OFF)
|
| 7 |
+
endif()
|
| 8 |
+
|
| 9 |
+
define_channel_options(
|
| 10 |
+
NAME
|
| 11 |
+
"audin"
|
| 12 |
+
TYPE
|
| 13 |
+
"dynamic"
|
| 14 |
+
DESCRIPTION
|
| 15 |
+
"Audio Input Redirection Virtual Channel Extension"
|
| 16 |
+
SPECIFICATIONS
|
| 17 |
+
"[MS-RDPEAI]"
|
| 18 |
+
DEFAULT
|
| 19 |
+
${OPTION_DEFAULT}
|
| 20 |
+
CLIENT_DEFAULT
|
| 21 |
+
${OPTION_CLIENT_DEFAULT}
|
| 22 |
+
SERVER_DEFAULT
|
| 23 |
+
${OPTION_SERVER_DEFAULT}
|
| 24 |
+
)
|
local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/CMakeLists.txt
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# FreeRDP: A Remote Desktop Protocol Implementation
|
| 2 |
+
# FreeRDP cmake build script
|
| 3 |
+
#
|
| 4 |
+
# Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
| 5 |
+
#
|
| 6 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 7 |
+
# you may not use this file except in compliance with the License.
|
| 8 |
+
# You may obtain a copy of the License at
|
| 9 |
+
#
|
| 10 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 11 |
+
#
|
| 12 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 13 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 14 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 15 |
+
# See the License for the specific language governing permissions and
|
| 16 |
+
# limitations under the License.
|
| 17 |
+
|
| 18 |
+
define_channel_client("audin")
|
| 19 |
+
|
| 20 |
+
set(${MODULE_PREFIX}_SRCS audin_main.c audin_main.h)
|
| 21 |
+
|
| 22 |
+
set(${MODULE_PREFIX}_LIBS freerdp winpr)
|
| 23 |
+
|
| 24 |
+
include_directories(..)
|
| 25 |
+
|
| 26 |
+
add_channel_client_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} TRUE "DVCPluginEntry")
|
| 27 |
+
|
| 28 |
+
if(WITH_OSS)
|
| 29 |
+
add_channel_client_subsystem(${MODULE_PREFIX} ${CHANNEL_NAME} "oss" "")
|
| 30 |
+
endif()
|
| 31 |
+
|
| 32 |
+
if(WITH_ALSA)
|
| 33 |
+
add_channel_client_subsystem(${MODULE_PREFIX} ${CHANNEL_NAME} "alsa" "")
|
| 34 |
+
endif()
|
| 35 |
+
|
| 36 |
+
if(WITH_PULSE)
|
| 37 |
+
add_channel_client_subsystem(${MODULE_PREFIX} ${CHANNEL_NAME} "pulse" "")
|
| 38 |
+
endif()
|
| 39 |
+
|
| 40 |
+
if(WITH_OPENSLES)
|
| 41 |
+
add_channel_client_subsystem(${MODULE_PREFIX} ${CHANNEL_NAME} "opensles" "")
|
| 42 |
+
endif()
|
| 43 |
+
|
| 44 |
+
if(WITH_WINMM)
|
| 45 |
+
add_channel_client_subsystem(${MODULE_PREFIX} ${CHANNEL_NAME} "winmm" "")
|
| 46 |
+
endif()
|
| 47 |
+
|
| 48 |
+
if(WITH_MACAUDIO)
|
| 49 |
+
add_channel_client_subsystem(${MODULE_PREFIX} ${CHANNEL_NAME} "mac" "")
|
| 50 |
+
endif()
|
| 51 |
+
|
| 52 |
+
if(WITH_SNDIO)
|
| 53 |
+
add_channel_client_subsystem(${MODULE_PREFIX} ${CHANNEL_NAME} "sndio" "")
|
| 54 |
+
endif()
|
| 55 |
+
|
| 56 |
+
if(WITH_IOSAUDIO)
|
| 57 |
+
add_channel_client_subsystem(${MODULE_PREFIX} ${CHANNEL_NAME} "ios" "")
|
| 58 |
+
endif()
|
local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/alsa/CMakeLists.txt
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# FreeRDP: A Remote Desktop Protocol Implementation
|
| 2 |
+
# FreeRDP cmake build script
|
| 3 |
+
#
|
| 4 |
+
# Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
| 5 |
+
#
|
| 6 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 7 |
+
# you may not use this file except in compliance with the License.
|
| 8 |
+
# You may obtain a copy of the License at
|
| 9 |
+
#
|
| 10 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 11 |
+
#
|
| 12 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 13 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 14 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 15 |
+
# See the License for the specific language governing permissions and
|
| 16 |
+
# limitations under the License.
|
| 17 |
+
|
| 18 |
+
define_channel_client_subsystem("audin" "alsa" "")
|
| 19 |
+
|
| 20 |
+
find_package(ALSA REQUIRED)
|
| 21 |
+
|
| 22 |
+
set(${MODULE_PREFIX}_SRCS audin_alsa.c)
|
| 23 |
+
|
| 24 |
+
set(${MODULE_PREFIX}_LIBS winpr freerdp ${ALSA_LIBRARIES})
|
| 25 |
+
|
| 26 |
+
include_directories(..)
|
| 27 |
+
include_directories(SYSTEM ${ALSA_INCLUDE_DIRS})
|
| 28 |
+
|
| 29 |
+
add_channel_client_subsystem_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} "" TRUE "")
|
local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/alsa/audin_alsa.c
ADDED
|
@@ -0,0 +1,463 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* FreeRDP: A Remote Desktop Protocol Implementation
|
| 3 |
+
* Audio Input Redirection Virtual Channel - ALSA implementation
|
| 4 |
+
*
|
| 5 |
+
* Copyright 2010-2011 Vic Lee
|
| 6 |
+
* Copyright 2015 Thincast Technologies GmbH
|
| 7 |
+
* Copyright 2015 DI (FH) Martin Haimberger <martin.haimberger@thincast.com>
|
| 8 |
+
*
|
| 9 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 10 |
+
* you may not use this file except in compliance with the License.
|
| 11 |
+
* You may obtain a copy of the License at
|
| 12 |
+
*
|
| 13 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 14 |
+
*
|
| 15 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 16 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 17 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 18 |
+
* See the License for the specific language governing permissions and
|
| 19 |
+
* limitations under the License.
|
| 20 |
+
*/
|
| 21 |
+
|
| 22 |
+
#include <freerdp/config.h>
|
| 23 |
+
|
| 24 |
+
#include <stdio.h>
|
| 25 |
+
#include <stdlib.h>
|
| 26 |
+
#include <string.h>
|
| 27 |
+
|
| 28 |
+
#include <winpr/crt.h>
|
| 29 |
+
#include <winpr/synch.h>
|
| 30 |
+
#include <winpr/thread.h>
|
| 31 |
+
#include <winpr/cmdline.h>
|
| 32 |
+
#include <winpr/wlog.h>
|
| 33 |
+
|
| 34 |
+
#include <alsa/asoundlib.h>
|
| 35 |
+
|
| 36 |
+
#include <freerdp/freerdp.h>
|
| 37 |
+
#include <freerdp/addin.h>
|
| 38 |
+
#include <freerdp/channels/rdpsnd.h>
|
| 39 |
+
|
| 40 |
+
#include "audin_main.h"
|
| 41 |
+
|
| 42 |
+
typedef struct
|
| 43 |
+
{
|
| 44 |
+
IAudinDevice iface;
|
| 45 |
+
|
| 46 |
+
char* device_name;
|
| 47 |
+
UINT32 frames_per_packet;
|
| 48 |
+
AUDIO_FORMAT aformat;
|
| 49 |
+
|
| 50 |
+
HANDLE thread;
|
| 51 |
+
HANDLE stopEvent;
|
| 52 |
+
|
| 53 |
+
AudinReceive receive;
|
| 54 |
+
void* user_data;
|
| 55 |
+
|
| 56 |
+
rdpContext* rdpcontext;
|
| 57 |
+
wLog* log;
|
| 58 |
+
size_t bytes_per_frame;
|
| 59 |
+
} AudinALSADevice;
|
| 60 |
+
|
| 61 |
+
static snd_pcm_format_t audin_alsa_format(UINT32 wFormatTag, UINT32 bitPerChannel)
|
| 62 |
+
{
|
| 63 |
+
switch (wFormatTag)
|
| 64 |
+
{
|
| 65 |
+
case WAVE_FORMAT_PCM:
|
| 66 |
+
switch (bitPerChannel)
|
| 67 |
+
{
|
| 68 |
+
case 16:
|
| 69 |
+
return SND_PCM_FORMAT_S16_LE;
|
| 70 |
+
|
| 71 |
+
case 8:
|
| 72 |
+
return SND_PCM_FORMAT_S8;
|
| 73 |
+
|
| 74 |
+
default:
|
| 75 |
+
return SND_PCM_FORMAT_UNKNOWN;
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
default:
|
| 79 |
+
return SND_PCM_FORMAT_UNKNOWN;
|
| 80 |
+
}
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
static BOOL audin_alsa_set_params(AudinALSADevice* alsa, snd_pcm_t* capture_handle)
|
| 84 |
+
{
|
| 85 |
+
int error = 0;
|
| 86 |
+
SSIZE_T s = 0;
|
| 87 |
+
UINT32 channels = alsa->aformat.nChannels;
|
| 88 |
+
snd_pcm_hw_params_t* hw_params = NULL;
|
| 89 |
+
snd_pcm_format_t format =
|
| 90 |
+
audin_alsa_format(alsa->aformat.wFormatTag, alsa->aformat.wBitsPerSample);
|
| 91 |
+
|
| 92 |
+
if ((error = snd_pcm_hw_params_malloc(&hw_params)) < 0)
|
| 93 |
+
{
|
| 94 |
+
WLog_Print(alsa->log, WLOG_ERROR, "snd_pcm_hw_params_malloc (%s)", snd_strerror(error));
|
| 95 |
+
return FALSE;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
snd_pcm_hw_params_any(capture_handle, hw_params);
|
| 99 |
+
snd_pcm_hw_params_set_access(capture_handle, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED);
|
| 100 |
+
snd_pcm_hw_params_set_format(capture_handle, hw_params, format);
|
| 101 |
+
snd_pcm_hw_params_set_rate_near(capture_handle, hw_params, &alsa->aformat.nSamplesPerSec, NULL);
|
| 102 |
+
snd_pcm_hw_params_set_channels_near(capture_handle, hw_params, &channels);
|
| 103 |
+
snd_pcm_hw_params(capture_handle, hw_params);
|
| 104 |
+
snd_pcm_hw_params_free(hw_params);
|
| 105 |
+
snd_pcm_prepare(capture_handle);
|
| 106 |
+
if (channels > UINT16_MAX)
|
| 107 |
+
return FALSE;
|
| 108 |
+
s = snd_pcm_format_size(format, 1);
|
| 109 |
+
if ((s < 0) || (s > UINT16_MAX))
|
| 110 |
+
return FALSE;
|
| 111 |
+
alsa->aformat.nChannels = (UINT16)channels;
|
| 112 |
+
alsa->bytes_per_frame = (size_t)s * channels;
|
| 113 |
+
return TRUE;
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
static DWORD WINAPI audin_alsa_thread_func(LPVOID arg)
|
| 117 |
+
{
|
| 118 |
+
DWORD error = CHANNEL_RC_OK;
|
| 119 |
+
BYTE* buffer = NULL;
|
| 120 |
+
AudinALSADevice* alsa = (AudinALSADevice*)arg;
|
| 121 |
+
|
| 122 |
+
WINPR_ASSERT(alsa);
|
| 123 |
+
|
| 124 |
+
WLog_Print(alsa->log, WLOG_DEBUG, "in");
|
| 125 |
+
|
| 126 |
+
snd_pcm_t* capture_handle = NULL;
|
| 127 |
+
const int rc = snd_pcm_open(&capture_handle, alsa->device_name, SND_PCM_STREAM_CAPTURE, 0);
|
| 128 |
+
if (rc < 0)
|
| 129 |
+
{
|
| 130 |
+
WLog_Print(alsa->log, WLOG_ERROR, "snd_pcm_open (%s)", snd_strerror(rc));
|
| 131 |
+
error = CHANNEL_RC_INITIALIZATION_ERROR;
|
| 132 |
+
goto out;
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
if (!audin_alsa_set_params(alsa, capture_handle))
|
| 136 |
+
{
|
| 137 |
+
WLog_Print(alsa->log, WLOG_ERROR, "audin_alsa_set_params failed");
|
| 138 |
+
goto out;
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
buffer =
|
| 142 |
+
(BYTE*)calloc(alsa->frames_per_packet + alsa->aformat.nBlockAlign, alsa->bytes_per_frame);
|
| 143 |
+
|
| 144 |
+
if (!buffer)
|
| 145 |
+
{
|
| 146 |
+
WLog_Print(alsa->log, WLOG_ERROR, "calloc failed!");
|
| 147 |
+
error = CHANNEL_RC_NO_MEMORY;
|
| 148 |
+
goto out;
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
while (1)
|
| 152 |
+
{
|
| 153 |
+
size_t frames = alsa->frames_per_packet;
|
| 154 |
+
const DWORD status = WaitForSingleObject(alsa->stopEvent, 0);
|
| 155 |
+
|
| 156 |
+
if (status == WAIT_FAILED)
|
| 157 |
+
{
|
| 158 |
+
error = GetLastError();
|
| 159 |
+
WLog_Print(alsa->log, WLOG_ERROR, "WaitForSingleObject failed with error %" PRIu32 "!",
|
| 160 |
+
error);
|
| 161 |
+
break;
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
if (status == WAIT_OBJECT_0)
|
| 165 |
+
{
|
| 166 |
+
WLog_Print(alsa->log, WLOG_DEBUG, "alsa->stopEvent requests termination");
|
| 167 |
+
break;
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
snd_pcm_sframes_t framesRead = snd_pcm_readi(capture_handle, buffer, frames);
|
| 171 |
+
|
| 172 |
+
if (framesRead == 0)
|
| 173 |
+
continue;
|
| 174 |
+
|
| 175 |
+
if (framesRead == -EPIPE)
|
| 176 |
+
{
|
| 177 |
+
const int res = snd_pcm_recover(capture_handle, (int)framesRead, 0);
|
| 178 |
+
if (res < 0)
|
| 179 |
+
WLog_Print(alsa->log, WLOG_WARN, "snd_pcm_recover (%s)", snd_strerror(res));
|
| 180 |
+
|
| 181 |
+
continue;
|
| 182 |
+
}
|
| 183 |
+
else if (framesRead < 0)
|
| 184 |
+
{
|
| 185 |
+
WLog_Print(alsa->log, WLOG_ERROR, "snd_pcm_readi (%s)", snd_strerror((int)framesRead));
|
| 186 |
+
error = ERROR_INTERNAL_ERROR;
|
| 187 |
+
break;
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
error = alsa->receive(&alsa->aformat, buffer,
|
| 191 |
+
WINPR_ASSERTING_INT_CAST(size_t, framesRead) * alsa->bytes_per_frame,
|
| 192 |
+
alsa->user_data);
|
| 193 |
+
|
| 194 |
+
if (error)
|
| 195 |
+
{
|
| 196 |
+
WLog_Print(alsa->log, WLOG_ERROR, "audin_alsa_thread_receive failed with error %ld",
|
| 197 |
+
error);
|
| 198 |
+
break;
|
| 199 |
+
}
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
free(buffer);
|
| 203 |
+
|
| 204 |
+
if (capture_handle)
|
| 205 |
+
{
|
| 206 |
+
const int res = snd_pcm_close(capture_handle);
|
| 207 |
+
if (res < 0)
|
| 208 |
+
WLog_Print(alsa->log, WLOG_WARN, "snd_pcm_close (%s)", snd_strerror(res));
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
out:
|
| 212 |
+
WLog_Print(alsa->log, WLOG_DEBUG, "out");
|
| 213 |
+
|
| 214 |
+
if (error && alsa->rdpcontext)
|
| 215 |
+
setChannelError(alsa->rdpcontext, error, "audin_alsa_thread_func reported an error");
|
| 216 |
+
|
| 217 |
+
ExitThread(error);
|
| 218 |
+
return error;
|
| 219 |
+
}
|
| 220 |
+
|
| 221 |
+
/**
|
| 222 |
+
* Function description
|
| 223 |
+
*
|
| 224 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 225 |
+
*/
|
| 226 |
+
static UINT audin_alsa_free(IAudinDevice* device)
|
| 227 |
+
{
|
| 228 |
+
AudinALSADevice* alsa = (AudinALSADevice*)device;
|
| 229 |
+
|
| 230 |
+
if (alsa)
|
| 231 |
+
free(alsa->device_name);
|
| 232 |
+
|
| 233 |
+
free(alsa);
|
| 234 |
+
return CHANNEL_RC_OK;
|
| 235 |
+
}
|
| 236 |
+
|
| 237 |
+
static BOOL audin_alsa_format_supported(IAudinDevice* device, const AUDIO_FORMAT* format)
|
| 238 |
+
{
|
| 239 |
+
if (!device || !format)
|
| 240 |
+
return FALSE;
|
| 241 |
+
|
| 242 |
+
switch (format->wFormatTag)
|
| 243 |
+
{
|
| 244 |
+
case WAVE_FORMAT_PCM:
|
| 245 |
+
if (format->cbSize == 0 && (format->nSamplesPerSec <= 48000) &&
|
| 246 |
+
(format->wBitsPerSample == 8 || format->wBitsPerSample == 16) &&
|
| 247 |
+
(format->nChannels == 1 || format->nChannels == 2))
|
| 248 |
+
{
|
| 249 |
+
return TRUE;
|
| 250 |
+
}
|
| 251 |
+
|
| 252 |
+
break;
|
| 253 |
+
|
| 254 |
+
default:
|
| 255 |
+
return FALSE;
|
| 256 |
+
}
|
| 257 |
+
|
| 258 |
+
return FALSE;
|
| 259 |
+
}
|
| 260 |
+
|
| 261 |
+
/**
|
| 262 |
+
* Function description
|
| 263 |
+
*
|
| 264 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 265 |
+
*/
|
| 266 |
+
static UINT audin_alsa_set_format(IAudinDevice* device, const AUDIO_FORMAT* format,
|
| 267 |
+
UINT32 FramesPerPacket)
|
| 268 |
+
{
|
| 269 |
+
AudinALSADevice* alsa = (AudinALSADevice*)device;
|
| 270 |
+
|
| 271 |
+
if (!alsa || !format)
|
| 272 |
+
return ERROR_INVALID_PARAMETER;
|
| 273 |
+
|
| 274 |
+
alsa->aformat = *format;
|
| 275 |
+
alsa->frames_per_packet = FramesPerPacket;
|
| 276 |
+
|
| 277 |
+
if (audin_alsa_format(format->wFormatTag, format->wBitsPerSample) == SND_PCM_FORMAT_UNKNOWN)
|
| 278 |
+
return ERROR_INTERNAL_ERROR;
|
| 279 |
+
|
| 280 |
+
return CHANNEL_RC_OK;
|
| 281 |
+
}
|
| 282 |
+
|
| 283 |
+
/**
|
| 284 |
+
* Function description
|
| 285 |
+
*
|
| 286 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 287 |
+
*/
|
| 288 |
+
static UINT audin_alsa_open(IAudinDevice* device, AudinReceive receive, void* user_data)
|
| 289 |
+
{
|
| 290 |
+
AudinALSADevice* alsa = (AudinALSADevice*)device;
|
| 291 |
+
|
| 292 |
+
if (!device || !receive || !user_data)
|
| 293 |
+
return ERROR_INVALID_PARAMETER;
|
| 294 |
+
|
| 295 |
+
alsa->receive = receive;
|
| 296 |
+
alsa->user_data = user_data;
|
| 297 |
+
|
| 298 |
+
if (!(alsa->stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL)))
|
| 299 |
+
{
|
| 300 |
+
WLog_Print(alsa->log, WLOG_ERROR, "CreateEvent failed!");
|
| 301 |
+
goto error_out;
|
| 302 |
+
}
|
| 303 |
+
|
| 304 |
+
if (!(alsa->thread = CreateThread(NULL, 0, audin_alsa_thread_func, alsa, 0, NULL)))
|
| 305 |
+
{
|
| 306 |
+
WLog_Print(alsa->log, WLOG_ERROR, "CreateThread failed!");
|
| 307 |
+
goto error_out;
|
| 308 |
+
}
|
| 309 |
+
|
| 310 |
+
return CHANNEL_RC_OK;
|
| 311 |
+
error_out:
|
| 312 |
+
(void)CloseHandle(alsa->stopEvent);
|
| 313 |
+
alsa->stopEvent = NULL;
|
| 314 |
+
return ERROR_INTERNAL_ERROR;
|
| 315 |
+
}
|
| 316 |
+
|
| 317 |
+
/**
|
| 318 |
+
* Function description
|
| 319 |
+
*
|
| 320 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 321 |
+
*/
|
| 322 |
+
static UINT audin_alsa_close(IAudinDevice* device)
|
| 323 |
+
{
|
| 324 |
+
UINT error = CHANNEL_RC_OK;
|
| 325 |
+
AudinALSADevice* alsa = (AudinALSADevice*)device;
|
| 326 |
+
|
| 327 |
+
if (!alsa)
|
| 328 |
+
return ERROR_INVALID_PARAMETER;
|
| 329 |
+
|
| 330 |
+
if (alsa->stopEvent)
|
| 331 |
+
{
|
| 332 |
+
(void)SetEvent(alsa->stopEvent);
|
| 333 |
+
|
| 334 |
+
if (WaitForSingleObject(alsa->thread, INFINITE) == WAIT_FAILED)
|
| 335 |
+
{
|
| 336 |
+
error = GetLastError();
|
| 337 |
+
WLog_Print(alsa->log, WLOG_ERROR, "WaitForSingleObject failed with error %" PRIu32 "",
|
| 338 |
+
error);
|
| 339 |
+
return error;
|
| 340 |
+
}
|
| 341 |
+
|
| 342 |
+
(void)CloseHandle(alsa->stopEvent);
|
| 343 |
+
alsa->stopEvent = NULL;
|
| 344 |
+
(void)CloseHandle(alsa->thread);
|
| 345 |
+
alsa->thread = NULL;
|
| 346 |
+
}
|
| 347 |
+
|
| 348 |
+
alsa->receive = NULL;
|
| 349 |
+
alsa->user_data = NULL;
|
| 350 |
+
return error;
|
| 351 |
+
}
|
| 352 |
+
|
| 353 |
+
/**
|
| 354 |
+
* Function description
|
| 355 |
+
*
|
| 356 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 357 |
+
*/
|
| 358 |
+
static UINT audin_alsa_parse_addin_args(AudinALSADevice* device, const ADDIN_ARGV* args)
|
| 359 |
+
{
|
| 360 |
+
int status = 0;
|
| 361 |
+
DWORD flags = 0;
|
| 362 |
+
const COMMAND_LINE_ARGUMENT_A* arg = NULL;
|
| 363 |
+
AudinALSADevice* alsa = device;
|
| 364 |
+
COMMAND_LINE_ARGUMENT_A audin_alsa_args[] = { { "dev", COMMAND_LINE_VALUE_REQUIRED, "<device>",
|
| 365 |
+
NULL, NULL, -1, NULL, "audio device name" },
|
| 366 |
+
{ NULL, 0, NULL, NULL, NULL, -1, NULL, NULL } };
|
| 367 |
+
flags =
|
| 368 |
+
COMMAND_LINE_SIGIL_NONE | COMMAND_LINE_SEPARATOR_COLON | COMMAND_LINE_IGN_UNKNOWN_KEYWORD;
|
| 369 |
+
status = CommandLineParseArgumentsA(args->argc, args->argv, audin_alsa_args, flags, alsa, NULL,
|
| 370 |
+
NULL);
|
| 371 |
+
|
| 372 |
+
if (status < 0)
|
| 373 |
+
return ERROR_INVALID_PARAMETER;
|
| 374 |
+
|
| 375 |
+
arg = audin_alsa_args;
|
| 376 |
+
|
| 377 |
+
do
|
| 378 |
+
{
|
| 379 |
+
if (!(arg->Flags & COMMAND_LINE_VALUE_PRESENT))
|
| 380 |
+
continue;
|
| 381 |
+
|
| 382 |
+
CommandLineSwitchStart(arg) CommandLineSwitchCase(arg, "dev")
|
| 383 |
+
{
|
| 384 |
+
alsa->device_name = _strdup(arg->Value);
|
| 385 |
+
|
| 386 |
+
if (!alsa->device_name)
|
| 387 |
+
{
|
| 388 |
+
WLog_Print(alsa->log, WLOG_ERROR, "_strdup failed!");
|
| 389 |
+
return CHANNEL_RC_NO_MEMORY;
|
| 390 |
+
}
|
| 391 |
+
}
|
| 392 |
+
CommandLineSwitchEnd(arg)
|
| 393 |
+
} while ((arg = CommandLineFindNextArgumentA(arg)) != NULL);
|
| 394 |
+
|
| 395 |
+
return CHANNEL_RC_OK;
|
| 396 |
+
}
|
| 397 |
+
|
| 398 |
+
/**
|
| 399 |
+
* Function description
|
| 400 |
+
*
|
| 401 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 402 |
+
*/
|
| 403 |
+
FREERDP_ENTRY_POINT(UINT VCAPITYPE alsa_freerdp_audin_client_subsystem_entry(
|
| 404 |
+
PFREERDP_AUDIN_DEVICE_ENTRY_POINTS pEntryPoints))
|
| 405 |
+
{
|
| 406 |
+
const ADDIN_ARGV* args = NULL;
|
| 407 |
+
AudinALSADevice* alsa = NULL;
|
| 408 |
+
UINT error = 0;
|
| 409 |
+
alsa = (AudinALSADevice*)calloc(1, sizeof(AudinALSADevice));
|
| 410 |
+
|
| 411 |
+
if (!alsa)
|
| 412 |
+
{
|
| 413 |
+
WLog_ERR(TAG, "calloc failed!");
|
| 414 |
+
return CHANNEL_RC_NO_MEMORY;
|
| 415 |
+
}
|
| 416 |
+
|
| 417 |
+
alsa->log = WLog_Get(TAG);
|
| 418 |
+
alsa->iface.Open = audin_alsa_open;
|
| 419 |
+
alsa->iface.FormatSupported = audin_alsa_format_supported;
|
| 420 |
+
alsa->iface.SetFormat = audin_alsa_set_format;
|
| 421 |
+
alsa->iface.Close = audin_alsa_close;
|
| 422 |
+
alsa->iface.Free = audin_alsa_free;
|
| 423 |
+
alsa->rdpcontext = pEntryPoints->rdpcontext;
|
| 424 |
+
args = pEntryPoints->args;
|
| 425 |
+
|
| 426 |
+
if ((error = audin_alsa_parse_addin_args(alsa, args)))
|
| 427 |
+
{
|
| 428 |
+
WLog_Print(alsa->log, WLOG_ERROR,
|
| 429 |
+
"audin_alsa_parse_addin_args failed with errorcode %" PRIu32 "!", error);
|
| 430 |
+
goto error_out;
|
| 431 |
+
}
|
| 432 |
+
|
| 433 |
+
if (!alsa->device_name)
|
| 434 |
+
{
|
| 435 |
+
alsa->device_name = _strdup("default");
|
| 436 |
+
|
| 437 |
+
if (!alsa->device_name)
|
| 438 |
+
{
|
| 439 |
+
WLog_Print(alsa->log, WLOG_ERROR, "_strdup failed!");
|
| 440 |
+
error = CHANNEL_RC_NO_MEMORY;
|
| 441 |
+
goto error_out;
|
| 442 |
+
}
|
| 443 |
+
}
|
| 444 |
+
|
| 445 |
+
alsa->frames_per_packet = 128;
|
| 446 |
+
alsa->aformat.nChannels = 2;
|
| 447 |
+
alsa->aformat.wBitsPerSample = 16;
|
| 448 |
+
alsa->aformat.wFormatTag = WAVE_FORMAT_PCM;
|
| 449 |
+
alsa->aformat.nSamplesPerSec = 44100;
|
| 450 |
+
|
| 451 |
+
if ((error = pEntryPoints->pRegisterAudinDevice(pEntryPoints->plugin, (IAudinDevice*)alsa)))
|
| 452 |
+
{
|
| 453 |
+
WLog_Print(alsa->log, WLOG_ERROR, "RegisterAudinDevice failed with error %" PRIu32 "!",
|
| 454 |
+
error);
|
| 455 |
+
goto error_out;
|
| 456 |
+
}
|
| 457 |
+
|
| 458 |
+
return CHANNEL_RC_OK;
|
| 459 |
+
error_out:
|
| 460 |
+
free(alsa->device_name);
|
| 461 |
+
free(alsa);
|
| 462 |
+
return error;
|
| 463 |
+
}
|
local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/audin_main.c
ADDED
|
@@ -0,0 +1,1110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* FreeRDP: A Remote Desktop Protocol Implementation
|
| 3 |
+
* Audio Input Redirection Virtual Channel
|
| 4 |
+
*
|
| 5 |
+
* Copyright 2010-2011 Vic Lee
|
| 6 |
+
* Copyright 2015 Thincast Technologies GmbH
|
| 7 |
+
* Copyright 2015 DI (FH) Martin Haimberger <martin.haimberger@thincast.com>
|
| 8 |
+
* Copyright 2015 Armin Novak <armin.novak@thincast.com>
|
| 9 |
+
*
|
| 10 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 11 |
+
* you may not use this file except in compliance with the License.
|
| 12 |
+
* You may obtain a copy of the License at
|
| 13 |
+
*
|
| 14 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 15 |
+
*
|
| 16 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 17 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 18 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 19 |
+
* See the License for the specific language governing permissions and
|
| 20 |
+
* limitations under the License.
|
| 21 |
+
*/
|
| 22 |
+
|
| 23 |
+
#include <freerdp/config.h>
|
| 24 |
+
|
| 25 |
+
#include <errno.h>
|
| 26 |
+
#include <winpr/assert.h>
|
| 27 |
+
#include <stdio.h>
|
| 28 |
+
#include <stdlib.h>
|
| 29 |
+
#include <string.h>
|
| 30 |
+
|
| 31 |
+
#include <winpr/crt.h>
|
| 32 |
+
#include <winpr/cmdline.h>
|
| 33 |
+
#include <winpr/wlog.h>
|
| 34 |
+
|
| 35 |
+
#include <freerdp/addin.h>
|
| 36 |
+
|
| 37 |
+
#include <winpr/stream.h>
|
| 38 |
+
#include <freerdp/freerdp.h>
|
| 39 |
+
#include <freerdp/codec/dsp.h>
|
| 40 |
+
#include <freerdp/client/channels.h>
|
| 41 |
+
#include <freerdp/channels/audin.h>
|
| 42 |
+
|
| 43 |
+
#include "audin_main.h"
|
| 44 |
+
|
| 45 |
+
#define SNDIN_VERSION 0x02
|
| 46 |
+
|
| 47 |
+
typedef enum
|
| 48 |
+
{
|
| 49 |
+
MSG_SNDIN_VERSION = 0x01,
|
| 50 |
+
MSG_SNDIN_FORMATS = 0x02,
|
| 51 |
+
MSG_SNDIN_OPEN = 0x03,
|
| 52 |
+
MSG_SNDIN_OPEN_REPLY = 0x04,
|
| 53 |
+
MSG_SNDIN_DATA_INCOMING = 0x05,
|
| 54 |
+
MSG_SNDIN_DATA = 0x06,
|
| 55 |
+
MSG_SNDIN_FORMATCHANGE = 0x07,
|
| 56 |
+
} MSG_SNDIN;
|
| 57 |
+
|
| 58 |
+
typedef struct
|
| 59 |
+
{
|
| 60 |
+
IWTSVirtualChannelCallback iface;
|
| 61 |
+
|
| 62 |
+
IWTSPlugin* plugin;
|
| 63 |
+
IWTSVirtualChannelManager* channel_mgr;
|
| 64 |
+
IWTSVirtualChannel* channel;
|
| 65 |
+
|
| 66 |
+
/**
|
| 67 |
+
* The supported format list sent back to the server, which needs to
|
| 68 |
+
* be stored as reference when the server sends the format index in
|
| 69 |
+
* Open PDU and Format Change PDU
|
| 70 |
+
*/
|
| 71 |
+
AUDIO_FORMAT* formats;
|
| 72 |
+
UINT32 formats_count;
|
| 73 |
+
} AUDIN_CHANNEL_CALLBACK;
|
| 74 |
+
|
| 75 |
+
typedef struct
|
| 76 |
+
{
|
| 77 |
+
IWTSPlugin iface;
|
| 78 |
+
|
| 79 |
+
GENERIC_LISTENER_CALLBACK* listener_callback;
|
| 80 |
+
|
| 81 |
+
/* Parsed plugin data */
|
| 82 |
+
AUDIO_FORMAT* fixed_format;
|
| 83 |
+
char* subsystem;
|
| 84 |
+
char* device_name;
|
| 85 |
+
|
| 86 |
+
/* Device interface */
|
| 87 |
+
IAudinDevice* device;
|
| 88 |
+
|
| 89 |
+
rdpContext* rdpcontext;
|
| 90 |
+
BOOL attached;
|
| 91 |
+
wStream* data;
|
| 92 |
+
AUDIO_FORMAT* format;
|
| 93 |
+
UINT32 FramesPerPacket;
|
| 94 |
+
|
| 95 |
+
FREERDP_DSP_CONTEXT* dsp_context;
|
| 96 |
+
wLog* log;
|
| 97 |
+
|
| 98 |
+
IWTSListener* listener;
|
| 99 |
+
|
| 100 |
+
BOOL initialized;
|
| 101 |
+
UINT32 version;
|
| 102 |
+
} AUDIN_PLUGIN;
|
| 103 |
+
|
| 104 |
+
static BOOL audin_process_addin_args(AUDIN_PLUGIN* audin, const ADDIN_ARGV* args);
|
| 105 |
+
|
| 106 |
+
static UINT audin_channel_write_and_free(AUDIN_CHANNEL_CALLBACK* callback, wStream* out,
|
| 107 |
+
BOOL freeStream)
|
| 108 |
+
{
|
| 109 |
+
if (!callback || !out)
|
| 110 |
+
return ERROR_INVALID_PARAMETER;
|
| 111 |
+
|
| 112 |
+
if (!callback->channel || !callback->channel->Write)
|
| 113 |
+
return ERROR_INTERNAL_ERROR;
|
| 114 |
+
|
| 115 |
+
Stream_SealLength(out);
|
| 116 |
+
WINPR_ASSERT(Stream_Length(out) <= UINT32_MAX);
|
| 117 |
+
const UINT error = callback->channel->Write(callback->channel, (ULONG)Stream_Length(out),
|
| 118 |
+
Stream_Buffer(out), NULL);
|
| 119 |
+
|
| 120 |
+
if (freeStream)
|
| 121 |
+
Stream_Free(out, TRUE);
|
| 122 |
+
|
| 123 |
+
return error;
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
/**
|
| 127 |
+
* Function description
|
| 128 |
+
*
|
| 129 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 130 |
+
*/
|
| 131 |
+
static UINT audin_process_version(AUDIN_PLUGIN* audin, AUDIN_CHANNEL_CALLBACK* callback, wStream* s)
|
| 132 |
+
{
|
| 133 |
+
const UINT32 ClientVersion = SNDIN_VERSION;
|
| 134 |
+
UINT32 ServerVersion = 0;
|
| 135 |
+
|
| 136 |
+
if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
|
| 137 |
+
return ERROR_INVALID_DATA;
|
| 138 |
+
|
| 139 |
+
Stream_Read_UINT32(s, ServerVersion);
|
| 140 |
+
WLog_Print(audin->log, WLOG_DEBUG, "ServerVersion=%" PRIu32 ", ClientVersion=%" PRIu32,
|
| 141 |
+
ServerVersion, ClientVersion);
|
| 142 |
+
|
| 143 |
+
/* Do not answer server packet, we do not support the channel version. */
|
| 144 |
+
if (ServerVersion > ClientVersion)
|
| 145 |
+
{
|
| 146 |
+
WLog_Print(audin->log, WLOG_WARN,
|
| 147 |
+
"Incompatible channel version server=%" PRIu32
|
| 148 |
+
", client supports version=%" PRIu32,
|
| 149 |
+
ServerVersion, ClientVersion);
|
| 150 |
+
return CHANNEL_RC_OK;
|
| 151 |
+
}
|
| 152 |
+
audin->version = ServerVersion;
|
| 153 |
+
|
| 154 |
+
wStream* out = Stream_New(NULL, 5);
|
| 155 |
+
|
| 156 |
+
if (!out)
|
| 157 |
+
{
|
| 158 |
+
WLog_Print(audin->log, WLOG_ERROR, "Stream_New failed!");
|
| 159 |
+
return ERROR_OUTOFMEMORY;
|
| 160 |
+
}
|
| 161 |
+
|
| 162 |
+
Stream_Write_UINT8(out, MSG_SNDIN_VERSION);
|
| 163 |
+
Stream_Write_UINT32(out, ClientVersion);
|
| 164 |
+
return audin_channel_write_and_free(callback, out, TRUE);
|
| 165 |
+
}
|
| 166 |
+
|
| 167 |
+
/**
|
| 168 |
+
* Function description
|
| 169 |
+
*
|
| 170 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 171 |
+
*/
|
| 172 |
+
static UINT audin_send_incoming_data_pdu(AUDIN_CHANNEL_CALLBACK* callback)
|
| 173 |
+
{
|
| 174 |
+
BYTE out_data[1] = { MSG_SNDIN_DATA_INCOMING };
|
| 175 |
+
|
| 176 |
+
if (!callback || !callback->channel || !callback->channel->Write)
|
| 177 |
+
return ERROR_INTERNAL_ERROR;
|
| 178 |
+
|
| 179 |
+
return callback->channel->Write(callback->channel, 1, out_data, NULL);
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
/**
|
| 183 |
+
* Function description
|
| 184 |
+
*
|
| 185 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 186 |
+
*/
|
| 187 |
+
static UINT audin_process_formats(AUDIN_PLUGIN* audin, AUDIN_CHANNEL_CALLBACK* callback, wStream* s)
|
| 188 |
+
{
|
| 189 |
+
UINT error = ERROR_INTERNAL_ERROR;
|
| 190 |
+
UINT32 NumFormats = 0;
|
| 191 |
+
UINT32 cbSizeFormatsPacket = 0;
|
| 192 |
+
|
| 193 |
+
WINPR_ASSERT(audin);
|
| 194 |
+
WINPR_ASSERT(callback);
|
| 195 |
+
|
| 196 |
+
if (!Stream_CheckAndLogRequiredLength(TAG, s, 8))
|
| 197 |
+
return ERROR_INVALID_DATA;
|
| 198 |
+
|
| 199 |
+
Stream_Read_UINT32(s, NumFormats);
|
| 200 |
+
WLog_Print(audin->log, WLOG_DEBUG, "NumFormats %" PRIu32 "", NumFormats);
|
| 201 |
+
|
| 202 |
+
if ((NumFormats < 1) || (NumFormats > 1000))
|
| 203 |
+
{
|
| 204 |
+
WLog_Print(audin->log, WLOG_ERROR, "bad NumFormats %" PRIu32 "", NumFormats);
|
| 205 |
+
return ERROR_INVALID_DATA;
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
Stream_Seek_UINT32(s); /* cbSizeFormatsPacket */
|
| 209 |
+
callback->formats = audio_formats_new(NumFormats);
|
| 210 |
+
|
| 211 |
+
if (!callback->formats)
|
| 212 |
+
{
|
| 213 |
+
WLog_Print(audin->log, WLOG_ERROR, "calloc failed!");
|
| 214 |
+
return ERROR_INVALID_DATA;
|
| 215 |
+
}
|
| 216 |
+
|
| 217 |
+
wStream* out = Stream_New(NULL, 9);
|
| 218 |
+
|
| 219 |
+
if (!out)
|
| 220 |
+
{
|
| 221 |
+
error = CHANNEL_RC_NO_MEMORY;
|
| 222 |
+
WLog_Print(audin->log, WLOG_ERROR, "Stream_New failed!");
|
| 223 |
+
goto out;
|
| 224 |
+
}
|
| 225 |
+
|
| 226 |
+
Stream_Seek(out, 9);
|
| 227 |
+
|
| 228 |
+
/* SoundFormats (variable) */
|
| 229 |
+
for (UINT32 i = 0; i < NumFormats; i++)
|
| 230 |
+
{
|
| 231 |
+
AUDIO_FORMAT format = { 0 };
|
| 232 |
+
|
| 233 |
+
if (!audio_format_read(s, &format))
|
| 234 |
+
{
|
| 235 |
+
error = ERROR_INVALID_DATA;
|
| 236 |
+
goto out;
|
| 237 |
+
}
|
| 238 |
+
|
| 239 |
+
audio_format_print(audin->log, WLOG_DEBUG, &format);
|
| 240 |
+
|
| 241 |
+
if (!audio_format_compatible(audin->fixed_format, &format))
|
| 242 |
+
{
|
| 243 |
+
audio_format_free(&format);
|
| 244 |
+
continue;
|
| 245 |
+
}
|
| 246 |
+
|
| 247 |
+
if (freerdp_dsp_supports_format(&format, TRUE) ||
|
| 248 |
+
audin->device->FormatSupported(audin->device, &format))
|
| 249 |
+
{
|
| 250 |
+
/* Store the agreed format in the corresponding index */
|
| 251 |
+
callback->formats[callback->formats_count++] = format;
|
| 252 |
+
|
| 253 |
+
if (!audio_format_write(out, &format))
|
| 254 |
+
{
|
| 255 |
+
error = CHANNEL_RC_NO_MEMORY;
|
| 256 |
+
WLog_Print(audin->log, WLOG_ERROR, "Stream_EnsureRemainingCapacity failed!");
|
| 257 |
+
goto out;
|
| 258 |
+
}
|
| 259 |
+
}
|
| 260 |
+
else
|
| 261 |
+
{
|
| 262 |
+
audio_format_free(&format);
|
| 263 |
+
}
|
| 264 |
+
}
|
| 265 |
+
|
| 266 |
+
if ((error = audin_send_incoming_data_pdu(callback)))
|
| 267 |
+
{
|
| 268 |
+
WLog_Print(audin->log, WLOG_ERROR, "audin_send_incoming_data_pdu failed!");
|
| 269 |
+
goto out;
|
| 270 |
+
}
|
| 271 |
+
|
| 272 |
+
cbSizeFormatsPacket = (UINT32)Stream_GetPosition(out);
|
| 273 |
+
Stream_SetPosition(out, 0);
|
| 274 |
+
Stream_Write_UINT8(out, MSG_SNDIN_FORMATS); /* Header (1 byte) */
|
| 275 |
+
Stream_Write_UINT32(out, callback->formats_count); /* NumFormats (4 bytes) */
|
| 276 |
+
Stream_Write_UINT32(out, cbSizeFormatsPacket); /* cbSizeFormatsPacket (4 bytes) */
|
| 277 |
+
Stream_SetPosition(out, cbSizeFormatsPacket);
|
| 278 |
+
error = audin_channel_write_and_free(callback, out, FALSE);
|
| 279 |
+
out:
|
| 280 |
+
|
| 281 |
+
if (error != CHANNEL_RC_OK)
|
| 282 |
+
{
|
| 283 |
+
audio_formats_free(callback->formats, NumFormats);
|
| 284 |
+
callback->formats = NULL;
|
| 285 |
+
}
|
| 286 |
+
|
| 287 |
+
Stream_Free(out, TRUE);
|
| 288 |
+
return error;
|
| 289 |
+
}
|
| 290 |
+
|
| 291 |
+
/**
|
| 292 |
+
* Function description
|
| 293 |
+
*
|
| 294 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 295 |
+
*/
|
| 296 |
+
static UINT audin_send_format_change_pdu(AUDIN_PLUGIN* audin, AUDIN_CHANNEL_CALLBACK* callback,
|
| 297 |
+
UINT32 NewFormat)
|
| 298 |
+
{
|
| 299 |
+
WINPR_ASSERT(audin);
|
| 300 |
+
WINPR_ASSERT(callback);
|
| 301 |
+
|
| 302 |
+
wStream* out = Stream_New(NULL, 5);
|
| 303 |
+
|
| 304 |
+
if (!out)
|
| 305 |
+
{
|
| 306 |
+
WLog_Print(audin->log, WLOG_ERROR, "Stream_New failed!");
|
| 307 |
+
return CHANNEL_RC_OK;
|
| 308 |
+
}
|
| 309 |
+
|
| 310 |
+
Stream_Write_UINT8(out, MSG_SNDIN_FORMATCHANGE);
|
| 311 |
+
Stream_Write_UINT32(out, NewFormat);
|
| 312 |
+
return audin_channel_write_and_free(callback, out, TRUE);
|
| 313 |
+
}
|
| 314 |
+
|
| 315 |
+
/**
|
| 316 |
+
* Function description
|
| 317 |
+
*
|
| 318 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 319 |
+
*/
|
| 320 |
+
static UINT audin_send_open_reply_pdu(AUDIN_PLUGIN* audin, AUDIN_CHANNEL_CALLBACK* callback,
|
| 321 |
+
UINT32 Result)
|
| 322 |
+
{
|
| 323 |
+
WINPR_ASSERT(audin);
|
| 324 |
+
WINPR_ASSERT(callback);
|
| 325 |
+
|
| 326 |
+
wStream* out = Stream_New(NULL, 5);
|
| 327 |
+
|
| 328 |
+
if (!out)
|
| 329 |
+
{
|
| 330 |
+
WLog_Print(audin->log, WLOG_ERROR, "Stream_New failed!");
|
| 331 |
+
return CHANNEL_RC_NO_MEMORY;
|
| 332 |
+
}
|
| 333 |
+
|
| 334 |
+
Stream_Write_UINT8(out, MSG_SNDIN_OPEN_REPLY);
|
| 335 |
+
Stream_Write_UINT32(out, Result);
|
| 336 |
+
return audin_channel_write_and_free(callback, out, TRUE);
|
| 337 |
+
}
|
| 338 |
+
|
| 339 |
+
/**
|
| 340 |
+
* Function description
|
| 341 |
+
*
|
| 342 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 343 |
+
*/
|
| 344 |
+
static UINT audin_receive_wave_data(const AUDIO_FORMAT* format, const BYTE* data, size_t size,
|
| 345 |
+
void* user_data)
|
| 346 |
+
{
|
| 347 |
+
WINPR_ASSERT(format);
|
| 348 |
+
|
| 349 |
+
UINT error = ERROR_INTERNAL_ERROR;
|
| 350 |
+
AUDIN_CHANNEL_CALLBACK* callback = (AUDIN_CHANNEL_CALLBACK*)user_data;
|
| 351 |
+
|
| 352 |
+
if (!callback)
|
| 353 |
+
return CHANNEL_RC_BAD_CHANNEL_HANDLE;
|
| 354 |
+
|
| 355 |
+
AUDIN_PLUGIN* audin = (AUDIN_PLUGIN*)callback->plugin;
|
| 356 |
+
|
| 357 |
+
if (!audin)
|
| 358 |
+
return CHANNEL_RC_BAD_CHANNEL_HANDLE;
|
| 359 |
+
|
| 360 |
+
if (!audin->attached)
|
| 361 |
+
return CHANNEL_RC_OK;
|
| 362 |
+
|
| 363 |
+
Stream_SetPosition(audin->data, 0);
|
| 364 |
+
|
| 365 |
+
if (!Stream_EnsureRemainingCapacity(audin->data, 1))
|
| 366 |
+
return CHANNEL_RC_NO_MEMORY;
|
| 367 |
+
|
| 368 |
+
Stream_Write_UINT8(audin->data, MSG_SNDIN_DATA);
|
| 369 |
+
|
| 370 |
+
const BOOL compatible = audio_format_compatible(format, audin->format);
|
| 371 |
+
if (compatible && audin->device->FormatSupported(audin->device, audin->format))
|
| 372 |
+
{
|
| 373 |
+
if (!Stream_EnsureRemainingCapacity(audin->data, size))
|
| 374 |
+
return CHANNEL_RC_NO_MEMORY;
|
| 375 |
+
|
| 376 |
+
Stream_Write(audin->data, data, size);
|
| 377 |
+
}
|
| 378 |
+
else
|
| 379 |
+
{
|
| 380 |
+
if (!freerdp_dsp_encode(audin->dsp_context, format, data, size, audin->data))
|
| 381 |
+
return ERROR_INTERNAL_ERROR;
|
| 382 |
+
}
|
| 383 |
+
|
| 384 |
+
/* Did not encode anything, skip this, the codec is not ready for output. */
|
| 385 |
+
if (Stream_GetPosition(audin->data) <= 1)
|
| 386 |
+
return CHANNEL_RC_OK;
|
| 387 |
+
|
| 388 |
+
audio_format_print(audin->log, WLOG_TRACE, audin->format);
|
| 389 |
+
WLog_Print(audin->log, WLOG_TRACE, "[%" PRIdz "/%" PRIdz "]", size,
|
| 390 |
+
Stream_GetPosition(audin->data) - 1);
|
| 391 |
+
|
| 392 |
+
if ((error = audin_send_incoming_data_pdu(callback)))
|
| 393 |
+
{
|
| 394 |
+
WLog_Print(audin->log, WLOG_ERROR, "audin_send_incoming_data_pdu failed!");
|
| 395 |
+
return error;
|
| 396 |
+
}
|
| 397 |
+
|
| 398 |
+
return audin_channel_write_and_free(callback, audin->data, FALSE);
|
| 399 |
+
}
|
| 400 |
+
|
| 401 |
+
static BOOL audin_open_device(AUDIN_PLUGIN* audin, AUDIN_CHANNEL_CALLBACK* callback)
|
| 402 |
+
{
|
| 403 |
+
UINT error = ERROR_INTERNAL_ERROR;
|
| 404 |
+
AUDIO_FORMAT format = { 0 };
|
| 405 |
+
|
| 406 |
+
if (!audin || !audin->device)
|
| 407 |
+
return FALSE;
|
| 408 |
+
|
| 409 |
+
format = *audin->format;
|
| 410 |
+
const BOOL supported =
|
| 411 |
+
IFCALLRESULT(FALSE, audin->device->FormatSupported, audin->device, &format);
|
| 412 |
+
WLog_Print(audin->log, WLOG_DEBUG, "microphone uses %s codec",
|
| 413 |
+
audio_format_get_tag_string(format.wFormatTag));
|
| 414 |
+
|
| 415 |
+
if (!supported)
|
| 416 |
+
{
|
| 417 |
+
/* Default sample rates supported by most backends. */
|
| 418 |
+
const UINT32 samplerates[] = { format.nSamplesPerSec, 96000, 48000, 44100, 22050 };
|
| 419 |
+
BOOL test = FALSE;
|
| 420 |
+
|
| 421 |
+
format.wFormatTag = WAVE_FORMAT_PCM;
|
| 422 |
+
format.wBitsPerSample = 16;
|
| 423 |
+
format.cbSize = 0;
|
| 424 |
+
for (size_t x = 0; x < ARRAYSIZE(samplerates); x++)
|
| 425 |
+
{
|
| 426 |
+
format.nSamplesPerSec = samplerates[x];
|
| 427 |
+
for (UINT16 y = audin->format->nChannels; y > 0; y--)
|
| 428 |
+
{
|
| 429 |
+
format.nChannels = y;
|
| 430 |
+
format.nBlockAlign = 2 * format.nChannels;
|
| 431 |
+
test = IFCALLRESULT(FALSE, audin->device->FormatSupported, audin->device, &format);
|
| 432 |
+
if (test)
|
| 433 |
+
break;
|
| 434 |
+
}
|
| 435 |
+
if (test)
|
| 436 |
+
break;
|
| 437 |
+
}
|
| 438 |
+
if (!test)
|
| 439 |
+
return FALSE;
|
| 440 |
+
}
|
| 441 |
+
|
| 442 |
+
IFCALLRET(audin->device->SetFormat, error, audin->device, &format, audin->FramesPerPacket);
|
| 443 |
+
|
| 444 |
+
if (error != CHANNEL_RC_OK)
|
| 445 |
+
{
|
| 446 |
+
WLog_ERR(TAG, "SetFormat failed with errorcode %" PRIu32 "", error);
|
| 447 |
+
return FALSE;
|
| 448 |
+
}
|
| 449 |
+
|
| 450 |
+
if (!freerdp_dsp_context_reset(audin->dsp_context, audin->format, audin->FramesPerPacket))
|
| 451 |
+
return FALSE;
|
| 452 |
+
|
| 453 |
+
IFCALLRET(audin->device->Open, error, audin->device, audin_receive_wave_data, callback);
|
| 454 |
+
|
| 455 |
+
if (error != CHANNEL_RC_OK)
|
| 456 |
+
{
|
| 457 |
+
WLog_ERR(TAG, "Open failed with errorcode %" PRIu32 "", error);
|
| 458 |
+
return FALSE;
|
| 459 |
+
}
|
| 460 |
+
|
| 461 |
+
return TRUE;
|
| 462 |
+
}
|
| 463 |
+
|
| 464 |
+
/**
|
| 465 |
+
* Function description
|
| 466 |
+
*
|
| 467 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 468 |
+
*/
|
| 469 |
+
static UINT audin_process_open(AUDIN_PLUGIN* audin, AUDIN_CHANNEL_CALLBACK* callback, wStream* s)
|
| 470 |
+
{
|
| 471 |
+
UINT32 initialFormat = 0;
|
| 472 |
+
UINT32 FramesPerPacket = 0;
|
| 473 |
+
UINT error = CHANNEL_RC_OK;
|
| 474 |
+
|
| 475 |
+
if (!Stream_CheckAndLogRequiredLength(TAG, s, 8))
|
| 476 |
+
return ERROR_INVALID_DATA;
|
| 477 |
+
|
| 478 |
+
Stream_Read_UINT32(s, FramesPerPacket);
|
| 479 |
+
Stream_Read_UINT32(s, initialFormat);
|
| 480 |
+
WLog_Print(audin->log, WLOG_DEBUG, "FramesPerPacket=%" PRIu32 " initialFormat=%" PRIu32 "",
|
| 481 |
+
FramesPerPacket, initialFormat);
|
| 482 |
+
audin->FramesPerPacket = FramesPerPacket;
|
| 483 |
+
|
| 484 |
+
if (initialFormat >= callback->formats_count)
|
| 485 |
+
{
|
| 486 |
+
WLog_Print(audin->log, WLOG_ERROR, "invalid format index %" PRIu32 " (total %" PRIu32 ")",
|
| 487 |
+
initialFormat, callback->formats_count);
|
| 488 |
+
return ERROR_INVALID_DATA;
|
| 489 |
+
}
|
| 490 |
+
|
| 491 |
+
audin->format = &callback->formats[initialFormat];
|
| 492 |
+
|
| 493 |
+
if (!audin_open_device(audin, callback))
|
| 494 |
+
return ERROR_INTERNAL_ERROR;
|
| 495 |
+
|
| 496 |
+
if ((error = audin_send_format_change_pdu(audin, callback, initialFormat)))
|
| 497 |
+
{
|
| 498 |
+
WLog_Print(audin->log, WLOG_ERROR, "audin_send_format_change_pdu failed!");
|
| 499 |
+
return error;
|
| 500 |
+
}
|
| 501 |
+
|
| 502 |
+
if ((error = audin_send_open_reply_pdu(audin, callback, 0)))
|
| 503 |
+
WLog_Print(audin->log, WLOG_ERROR, "audin_send_open_reply_pdu failed!");
|
| 504 |
+
|
| 505 |
+
return error;
|
| 506 |
+
}
|
| 507 |
+
|
| 508 |
+
/**
|
| 509 |
+
* Function description
|
| 510 |
+
*
|
| 511 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 512 |
+
*/
|
| 513 |
+
static UINT audin_process_format_change(AUDIN_PLUGIN* audin, AUDIN_CHANNEL_CALLBACK* callback,
|
| 514 |
+
wStream* s)
|
| 515 |
+
{
|
| 516 |
+
UINT32 NewFormat = 0;
|
| 517 |
+
UINT error = CHANNEL_RC_OK;
|
| 518 |
+
|
| 519 |
+
if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
|
| 520 |
+
return ERROR_INVALID_DATA;
|
| 521 |
+
|
| 522 |
+
Stream_Read_UINT32(s, NewFormat);
|
| 523 |
+
WLog_Print(audin->log, WLOG_DEBUG, "NewFormat=%" PRIu32 "", NewFormat);
|
| 524 |
+
|
| 525 |
+
if (NewFormat >= callback->formats_count)
|
| 526 |
+
{
|
| 527 |
+
WLog_Print(audin->log, WLOG_ERROR, "invalid format index %" PRIu32 " (total %" PRIu32 ")",
|
| 528 |
+
NewFormat, callback->formats_count);
|
| 529 |
+
return ERROR_INVALID_DATA;
|
| 530 |
+
}
|
| 531 |
+
|
| 532 |
+
audin->format = &callback->formats[NewFormat];
|
| 533 |
+
|
| 534 |
+
if (audin->device)
|
| 535 |
+
{
|
| 536 |
+
IFCALLRET(audin->device->Close, error, audin->device);
|
| 537 |
+
|
| 538 |
+
if (error != CHANNEL_RC_OK)
|
| 539 |
+
{
|
| 540 |
+
WLog_ERR(TAG, "Close failed with errorcode %" PRIu32 "", error);
|
| 541 |
+
return error;
|
| 542 |
+
}
|
| 543 |
+
}
|
| 544 |
+
|
| 545 |
+
if (!audin_open_device(audin, callback))
|
| 546 |
+
return ERROR_INTERNAL_ERROR;
|
| 547 |
+
|
| 548 |
+
if ((error = audin_send_format_change_pdu(audin, callback, NewFormat)))
|
| 549 |
+
WLog_ERR(TAG, "audin_send_format_change_pdu failed!");
|
| 550 |
+
|
| 551 |
+
return error;
|
| 552 |
+
}
|
| 553 |
+
|
| 554 |
+
/**
|
| 555 |
+
* Function description
|
| 556 |
+
*
|
| 557 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 558 |
+
*/
|
| 559 |
+
static UINT audin_on_data_received(IWTSVirtualChannelCallback* pChannelCallback, wStream* data)
|
| 560 |
+
{
|
| 561 |
+
UINT error = 0;
|
| 562 |
+
BYTE MessageId = 0;
|
| 563 |
+
AUDIN_CHANNEL_CALLBACK* callback = (AUDIN_CHANNEL_CALLBACK*)pChannelCallback;
|
| 564 |
+
|
| 565 |
+
if (!callback || !data)
|
| 566 |
+
return ERROR_INVALID_PARAMETER;
|
| 567 |
+
|
| 568 |
+
AUDIN_PLUGIN* audin = (AUDIN_PLUGIN*)callback->plugin;
|
| 569 |
+
|
| 570 |
+
if (!audin)
|
| 571 |
+
return ERROR_INTERNAL_ERROR;
|
| 572 |
+
|
| 573 |
+
if (!Stream_CheckAndLogRequiredCapacity(TAG, data, 1))
|
| 574 |
+
return ERROR_NO_DATA;
|
| 575 |
+
|
| 576 |
+
Stream_Read_UINT8(data, MessageId);
|
| 577 |
+
WLog_Print(audin->log, WLOG_DEBUG, "MessageId=0x%02" PRIx8 "", MessageId);
|
| 578 |
+
|
| 579 |
+
switch (MessageId)
|
| 580 |
+
{
|
| 581 |
+
case MSG_SNDIN_VERSION:
|
| 582 |
+
error = audin_process_version(audin, callback, data);
|
| 583 |
+
break;
|
| 584 |
+
|
| 585 |
+
case MSG_SNDIN_FORMATS:
|
| 586 |
+
error = audin_process_formats(audin, callback, data);
|
| 587 |
+
break;
|
| 588 |
+
|
| 589 |
+
case MSG_SNDIN_OPEN:
|
| 590 |
+
error = audin_process_open(audin, callback, data);
|
| 591 |
+
break;
|
| 592 |
+
|
| 593 |
+
case MSG_SNDIN_FORMATCHANGE:
|
| 594 |
+
error = audin_process_format_change(audin, callback, data);
|
| 595 |
+
break;
|
| 596 |
+
|
| 597 |
+
default:
|
| 598 |
+
WLog_Print(audin->log, WLOG_ERROR, "unknown MessageId=0x%02" PRIx8 "", MessageId);
|
| 599 |
+
error = ERROR_INVALID_DATA;
|
| 600 |
+
break;
|
| 601 |
+
}
|
| 602 |
+
|
| 603 |
+
return error;
|
| 604 |
+
}
|
| 605 |
+
|
| 606 |
+
/**
|
| 607 |
+
* Function description
|
| 608 |
+
*
|
| 609 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 610 |
+
*/
|
| 611 |
+
static UINT audin_on_close(IWTSVirtualChannelCallback* pChannelCallback)
|
| 612 |
+
{
|
| 613 |
+
AUDIN_CHANNEL_CALLBACK* callback = (AUDIN_CHANNEL_CALLBACK*)pChannelCallback;
|
| 614 |
+
WINPR_ASSERT(callback);
|
| 615 |
+
|
| 616 |
+
AUDIN_PLUGIN* audin = (AUDIN_PLUGIN*)callback->plugin;
|
| 617 |
+
WINPR_ASSERT(audin);
|
| 618 |
+
|
| 619 |
+
UINT error = CHANNEL_RC_OK;
|
| 620 |
+
WLog_Print(audin->log, WLOG_TRACE, "...");
|
| 621 |
+
|
| 622 |
+
if (audin->device)
|
| 623 |
+
{
|
| 624 |
+
IFCALLRET(audin->device->Close, error, audin->device);
|
| 625 |
+
|
| 626 |
+
if (error != CHANNEL_RC_OK)
|
| 627 |
+
WLog_Print(audin->log, WLOG_ERROR, "Close failed with errorcode %" PRIu32 "", error);
|
| 628 |
+
}
|
| 629 |
+
|
| 630 |
+
audin->format = NULL;
|
| 631 |
+
audio_formats_free(callback->formats, callback->formats_count);
|
| 632 |
+
free(callback);
|
| 633 |
+
return error;
|
| 634 |
+
}
|
| 635 |
+
|
| 636 |
+
/**
|
| 637 |
+
* Function description
|
| 638 |
+
*
|
| 639 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 640 |
+
*/
|
| 641 |
+
static UINT audin_on_new_channel_connection(IWTSListenerCallback* pListenerCallback,
|
| 642 |
+
IWTSVirtualChannel* pChannel, BYTE* Data,
|
| 643 |
+
BOOL* pbAccept, IWTSVirtualChannelCallback** ppCallback)
|
| 644 |
+
{
|
| 645 |
+
GENERIC_LISTENER_CALLBACK* listener_callback = (GENERIC_LISTENER_CALLBACK*)pListenerCallback;
|
| 646 |
+
|
| 647 |
+
if (!listener_callback || !listener_callback->plugin)
|
| 648 |
+
return ERROR_INTERNAL_ERROR;
|
| 649 |
+
|
| 650 |
+
AUDIN_PLUGIN* audin = (AUDIN_PLUGIN*)listener_callback->plugin;
|
| 651 |
+
WLog_Print(audin->log, WLOG_TRACE, "...");
|
| 652 |
+
AUDIN_CHANNEL_CALLBACK* callback =
|
| 653 |
+
(AUDIN_CHANNEL_CALLBACK*)calloc(1, sizeof(AUDIN_CHANNEL_CALLBACK));
|
| 654 |
+
|
| 655 |
+
if (!callback)
|
| 656 |
+
{
|
| 657 |
+
WLog_Print(audin->log, WLOG_ERROR, "calloc failed!");
|
| 658 |
+
return CHANNEL_RC_NO_MEMORY;
|
| 659 |
+
}
|
| 660 |
+
|
| 661 |
+
callback->iface.OnDataReceived = audin_on_data_received;
|
| 662 |
+
callback->iface.OnClose = audin_on_close;
|
| 663 |
+
callback->plugin = listener_callback->plugin;
|
| 664 |
+
callback->channel_mgr = listener_callback->channel_mgr;
|
| 665 |
+
callback->channel = pChannel;
|
| 666 |
+
*ppCallback = (IWTSVirtualChannelCallback*)callback;
|
| 667 |
+
return CHANNEL_RC_OK;
|
| 668 |
+
}
|
| 669 |
+
|
| 670 |
+
/**
|
| 671 |
+
* Function description
|
| 672 |
+
*
|
| 673 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 674 |
+
*/
|
| 675 |
+
static UINT audin_plugin_initialize(IWTSPlugin* pPlugin, IWTSVirtualChannelManager* pChannelMgr)
|
| 676 |
+
{
|
| 677 |
+
AUDIN_PLUGIN* audin = (AUDIN_PLUGIN*)pPlugin;
|
| 678 |
+
|
| 679 |
+
if (!audin)
|
| 680 |
+
return CHANNEL_RC_BAD_CHANNEL_HANDLE;
|
| 681 |
+
|
| 682 |
+
if (!pChannelMgr)
|
| 683 |
+
return ERROR_INVALID_PARAMETER;
|
| 684 |
+
|
| 685 |
+
if (audin->initialized)
|
| 686 |
+
{
|
| 687 |
+
WLog_ERR(TAG, "[%s] channel initialized twice, aborting", AUDIN_DVC_CHANNEL_NAME);
|
| 688 |
+
return ERROR_INVALID_DATA;
|
| 689 |
+
}
|
| 690 |
+
|
| 691 |
+
WLog_Print(audin->log, WLOG_TRACE, "...");
|
| 692 |
+
audin->listener_callback =
|
| 693 |
+
(GENERIC_LISTENER_CALLBACK*)calloc(1, sizeof(GENERIC_LISTENER_CALLBACK));
|
| 694 |
+
|
| 695 |
+
if (!audin->listener_callback)
|
| 696 |
+
{
|
| 697 |
+
WLog_Print(audin->log, WLOG_ERROR, "calloc failed!");
|
| 698 |
+
return CHANNEL_RC_NO_MEMORY;
|
| 699 |
+
}
|
| 700 |
+
|
| 701 |
+
audin->listener_callback->iface.OnNewChannelConnection = audin_on_new_channel_connection;
|
| 702 |
+
audin->listener_callback->plugin = pPlugin;
|
| 703 |
+
audin->listener_callback->channel_mgr = pChannelMgr;
|
| 704 |
+
const UINT rc = pChannelMgr->CreateListener(pChannelMgr, AUDIN_DVC_CHANNEL_NAME, 0,
|
| 705 |
+
&audin->listener_callback->iface, &audin->listener);
|
| 706 |
+
|
| 707 |
+
audin->initialized = rc == CHANNEL_RC_OK;
|
| 708 |
+
return rc;
|
| 709 |
+
}
|
| 710 |
+
|
| 711 |
+
/**
|
| 712 |
+
* Function description
|
| 713 |
+
*
|
| 714 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 715 |
+
*/
|
| 716 |
+
static UINT audin_plugin_terminated(IWTSPlugin* pPlugin)
|
| 717 |
+
{
|
| 718 |
+
AUDIN_PLUGIN* audin = (AUDIN_PLUGIN*)pPlugin;
|
| 719 |
+
UINT error = CHANNEL_RC_OK;
|
| 720 |
+
|
| 721 |
+
if (!audin)
|
| 722 |
+
return CHANNEL_RC_BAD_CHANNEL_HANDLE;
|
| 723 |
+
|
| 724 |
+
WLog_Print(audin->log, WLOG_TRACE, "...");
|
| 725 |
+
|
| 726 |
+
if (audin->listener_callback)
|
| 727 |
+
{
|
| 728 |
+
IWTSVirtualChannelManager* mgr = audin->listener_callback->channel_mgr;
|
| 729 |
+
if (mgr)
|
| 730 |
+
IFCALL(mgr->DestroyListener, mgr, audin->listener);
|
| 731 |
+
}
|
| 732 |
+
audio_formats_free(audin->fixed_format, 1);
|
| 733 |
+
|
| 734 |
+
if (audin->device)
|
| 735 |
+
{
|
| 736 |
+
IFCALLRET(audin->device->Free, error, audin->device);
|
| 737 |
+
|
| 738 |
+
if (error != CHANNEL_RC_OK)
|
| 739 |
+
{
|
| 740 |
+
WLog_Print(audin->log, WLOG_ERROR, "Free failed with errorcode %" PRIu32 "", error);
|
| 741 |
+
// dont stop on error
|
| 742 |
+
}
|
| 743 |
+
|
| 744 |
+
audin->device = NULL;
|
| 745 |
+
}
|
| 746 |
+
|
| 747 |
+
freerdp_dsp_context_free(audin->dsp_context);
|
| 748 |
+
Stream_Free(audin->data, TRUE);
|
| 749 |
+
free(audin->subsystem);
|
| 750 |
+
free(audin->device_name);
|
| 751 |
+
free(audin->listener_callback);
|
| 752 |
+
free(audin);
|
| 753 |
+
return CHANNEL_RC_OK;
|
| 754 |
+
}
|
| 755 |
+
|
| 756 |
+
static UINT audin_plugin_attached(IWTSPlugin* pPlugin)
|
| 757 |
+
{
|
| 758 |
+
AUDIN_PLUGIN* audin = (AUDIN_PLUGIN*)pPlugin;
|
| 759 |
+
UINT error = CHANNEL_RC_OK;
|
| 760 |
+
|
| 761 |
+
if (!audin)
|
| 762 |
+
return CHANNEL_RC_BAD_CHANNEL_HANDLE;
|
| 763 |
+
|
| 764 |
+
audin->attached = TRUE;
|
| 765 |
+
return error;
|
| 766 |
+
}
|
| 767 |
+
|
| 768 |
+
static UINT audin_plugin_detached(IWTSPlugin* pPlugin)
|
| 769 |
+
{
|
| 770 |
+
AUDIN_PLUGIN* audin = (AUDIN_PLUGIN*)pPlugin;
|
| 771 |
+
UINT error = CHANNEL_RC_OK;
|
| 772 |
+
|
| 773 |
+
if (!audin)
|
| 774 |
+
return CHANNEL_RC_BAD_CHANNEL_HANDLE;
|
| 775 |
+
|
| 776 |
+
audin->attached = FALSE;
|
| 777 |
+
return error;
|
| 778 |
+
}
|
| 779 |
+
|
| 780 |
+
/**
|
| 781 |
+
* Function description
|
| 782 |
+
*
|
| 783 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 784 |
+
*/
|
| 785 |
+
static UINT audin_register_device_plugin(IWTSPlugin* pPlugin, IAudinDevice* device)
|
| 786 |
+
{
|
| 787 |
+
AUDIN_PLUGIN* audin = (AUDIN_PLUGIN*)pPlugin;
|
| 788 |
+
|
| 789 |
+
WINPR_ASSERT(audin);
|
| 790 |
+
|
| 791 |
+
if (audin->device)
|
| 792 |
+
{
|
| 793 |
+
WLog_Print(audin->log, WLOG_ERROR, "existing device, abort.");
|
| 794 |
+
return ERROR_ALREADY_EXISTS;
|
| 795 |
+
}
|
| 796 |
+
|
| 797 |
+
WLog_Print(audin->log, WLOG_DEBUG, "device registered.");
|
| 798 |
+
audin->device = device;
|
| 799 |
+
return CHANNEL_RC_OK;
|
| 800 |
+
}
|
| 801 |
+
|
| 802 |
+
/**
|
| 803 |
+
* Function description
|
| 804 |
+
*
|
| 805 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 806 |
+
*/
|
| 807 |
+
static UINT audin_load_device_plugin(AUDIN_PLUGIN* audin, const char* name, const ADDIN_ARGV* args)
|
| 808 |
+
{
|
| 809 |
+
WINPR_ASSERT(audin);
|
| 810 |
+
|
| 811 |
+
FREERDP_AUDIN_DEVICE_ENTRY_POINTS entryPoints = { 0 };
|
| 812 |
+
UINT error = ERROR_INTERNAL_ERROR;
|
| 813 |
+
|
| 814 |
+
PVIRTUALCHANNELENTRY pvce = freerdp_load_channel_addin_entry(AUDIN_CHANNEL_NAME, name, NULL, 0);
|
| 815 |
+
PFREERDP_AUDIN_DEVICE_ENTRY entry = WINPR_FUNC_PTR_CAST(pvce, PFREERDP_AUDIN_DEVICE_ENTRY);
|
| 816 |
+
|
| 817 |
+
if (entry == NULL)
|
| 818 |
+
{
|
| 819 |
+
WLog_Print(audin->log, WLOG_ERROR,
|
| 820 |
+
"freerdp_load_channel_addin_entry did not return any function pointers for %s ",
|
| 821 |
+
name);
|
| 822 |
+
return ERROR_INVALID_FUNCTION;
|
| 823 |
+
}
|
| 824 |
+
|
| 825 |
+
entryPoints.plugin = &audin->iface;
|
| 826 |
+
entryPoints.pRegisterAudinDevice = audin_register_device_plugin;
|
| 827 |
+
entryPoints.args = args;
|
| 828 |
+
entryPoints.rdpcontext = audin->rdpcontext;
|
| 829 |
+
|
| 830 |
+
error = entry(&entryPoints);
|
| 831 |
+
if (error)
|
| 832 |
+
{
|
| 833 |
+
WLog_Print(audin->log, WLOG_ERROR, "%s entry returned error %" PRIu32 ".", name, error);
|
| 834 |
+
return error;
|
| 835 |
+
}
|
| 836 |
+
|
| 837 |
+
WLog_Print(audin->log, WLOG_INFO, "Loaded %s backend for audin", name);
|
| 838 |
+
return CHANNEL_RC_OK;
|
| 839 |
+
}
|
| 840 |
+
|
| 841 |
+
/**
|
| 842 |
+
* Function description
|
| 843 |
+
*
|
| 844 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 845 |
+
*/
|
| 846 |
+
static UINT audin_set_subsystem(AUDIN_PLUGIN* audin, const char* subsystem)
|
| 847 |
+
{
|
| 848 |
+
WINPR_ASSERT(audin);
|
| 849 |
+
|
| 850 |
+
free(audin->subsystem);
|
| 851 |
+
audin->subsystem = _strdup(subsystem);
|
| 852 |
+
|
| 853 |
+
if (!audin->subsystem)
|
| 854 |
+
{
|
| 855 |
+
WLog_Print(audin->log, WLOG_ERROR, "_strdup failed!");
|
| 856 |
+
return ERROR_NOT_ENOUGH_MEMORY;
|
| 857 |
+
}
|
| 858 |
+
|
| 859 |
+
return CHANNEL_RC_OK;
|
| 860 |
+
}
|
| 861 |
+
|
| 862 |
+
/**
|
| 863 |
+
* Function description
|
| 864 |
+
*
|
| 865 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 866 |
+
*/
|
| 867 |
+
static UINT audin_set_device_name(AUDIN_PLUGIN* audin, const char* device_name)
|
| 868 |
+
{
|
| 869 |
+
WINPR_ASSERT(audin);
|
| 870 |
+
|
| 871 |
+
free(audin->device_name);
|
| 872 |
+
audin->device_name = _strdup(device_name);
|
| 873 |
+
|
| 874 |
+
if (!audin->device_name)
|
| 875 |
+
{
|
| 876 |
+
WLog_Print(audin->log, WLOG_ERROR, "_strdup failed!");
|
| 877 |
+
return ERROR_NOT_ENOUGH_MEMORY;
|
| 878 |
+
}
|
| 879 |
+
|
| 880 |
+
return CHANNEL_RC_OK;
|
| 881 |
+
}
|
| 882 |
+
|
| 883 |
+
BOOL audin_process_addin_args(AUDIN_PLUGIN* audin, const ADDIN_ARGV* args)
|
| 884 |
+
{
|
| 885 |
+
COMMAND_LINE_ARGUMENT_A audin_args[] = {
|
| 886 |
+
{ "sys", COMMAND_LINE_VALUE_REQUIRED, "<subsystem>", NULL, NULL, -1, NULL, "subsystem" },
|
| 887 |
+
{ "dev", COMMAND_LINE_VALUE_REQUIRED, "<device>", NULL, NULL, -1, NULL, "device" },
|
| 888 |
+
{ "format", COMMAND_LINE_VALUE_REQUIRED, "<format>", NULL, NULL, -1, NULL, "format" },
|
| 889 |
+
{ "rate", COMMAND_LINE_VALUE_REQUIRED, "<rate>", NULL, NULL, -1, NULL, "rate" },
|
| 890 |
+
{ "channel", COMMAND_LINE_VALUE_REQUIRED, "<channel>", NULL, NULL, -1, NULL, "channel" },
|
| 891 |
+
{ NULL, 0, NULL, NULL, NULL, -1, NULL, NULL }
|
| 892 |
+
};
|
| 893 |
+
|
| 894 |
+
if (!args || args->argc == 1)
|
| 895 |
+
return TRUE;
|
| 896 |
+
|
| 897 |
+
const DWORD flags =
|
| 898 |
+
COMMAND_LINE_SIGIL_NONE | COMMAND_LINE_SEPARATOR_COLON | COMMAND_LINE_IGN_UNKNOWN_KEYWORD;
|
| 899 |
+
const int status =
|
| 900 |
+
CommandLineParseArgumentsA(args->argc, args->argv, audin_args, flags, audin, NULL, NULL);
|
| 901 |
+
|
| 902 |
+
if (status != 0)
|
| 903 |
+
return FALSE;
|
| 904 |
+
|
| 905 |
+
const COMMAND_LINE_ARGUMENT_A* arg = audin_args;
|
| 906 |
+
errno = 0;
|
| 907 |
+
|
| 908 |
+
do
|
| 909 |
+
{
|
| 910 |
+
if (!(arg->Flags & COMMAND_LINE_VALUE_PRESENT))
|
| 911 |
+
continue;
|
| 912 |
+
|
| 913 |
+
CommandLineSwitchStart(arg) CommandLineSwitchCase(arg, "sys")
|
| 914 |
+
{
|
| 915 |
+
const UINT error = audin_set_subsystem(audin, arg->Value);
|
| 916 |
+
if (error != CHANNEL_RC_OK)
|
| 917 |
+
{
|
| 918 |
+
WLog_Print(audin->log, WLOG_ERROR,
|
| 919 |
+
"audin_set_subsystem failed with error %" PRIu32 "!", error);
|
| 920 |
+
return FALSE;
|
| 921 |
+
}
|
| 922 |
+
}
|
| 923 |
+
CommandLineSwitchCase(arg, "dev")
|
| 924 |
+
{
|
| 925 |
+
const UINT error = audin_set_device_name(audin, arg->Value);
|
| 926 |
+
if (error != CHANNEL_RC_OK)
|
| 927 |
+
{
|
| 928 |
+
WLog_Print(audin->log, WLOG_ERROR,
|
| 929 |
+
"audin_set_device_name failed with error %" PRIu32 "!", error);
|
| 930 |
+
return FALSE;
|
| 931 |
+
}
|
| 932 |
+
}
|
| 933 |
+
CommandLineSwitchCase(arg, "format")
|
| 934 |
+
{
|
| 935 |
+
unsigned long val = strtoul(arg->Value, NULL, 0);
|
| 936 |
+
|
| 937 |
+
if ((errno != 0) || (val > UINT16_MAX))
|
| 938 |
+
return FALSE;
|
| 939 |
+
|
| 940 |
+
audin->fixed_format->wFormatTag = (UINT16)val;
|
| 941 |
+
}
|
| 942 |
+
CommandLineSwitchCase(arg, "rate")
|
| 943 |
+
{
|
| 944 |
+
unsigned long val = strtoul(arg->Value, NULL, 0);
|
| 945 |
+
|
| 946 |
+
if ((errno != 0) || (val == 0) || (val > UINT32_MAX))
|
| 947 |
+
return FALSE;
|
| 948 |
+
|
| 949 |
+
audin->fixed_format->nSamplesPerSec = (UINT32)val;
|
| 950 |
+
}
|
| 951 |
+
CommandLineSwitchCase(arg, "channel")
|
| 952 |
+
{
|
| 953 |
+
unsigned long val = strtoul(arg->Value, NULL, 0);
|
| 954 |
+
|
| 955 |
+
if ((errno != 0) || (val <= UINT16_MAX))
|
| 956 |
+
audin->fixed_format->nChannels = (UINT16)val;
|
| 957 |
+
}
|
| 958 |
+
CommandLineSwitchDefault(arg)
|
| 959 |
+
{
|
| 960 |
+
}
|
| 961 |
+
CommandLineSwitchEnd(arg)
|
| 962 |
+
} while ((arg = CommandLineFindNextArgumentA(arg)) != NULL);
|
| 963 |
+
|
| 964 |
+
return TRUE;
|
| 965 |
+
}
|
| 966 |
+
|
| 967 |
+
/**
|
| 968 |
+
* Function description
|
| 969 |
+
*
|
| 970 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 971 |
+
*/
|
| 972 |
+
FREERDP_ENTRY_POINT(UINT VCAPITYPE audin_DVCPluginEntry(IDRDYNVC_ENTRY_POINTS* pEntryPoints))
|
| 973 |
+
{
|
| 974 |
+
struct SubsystemEntry
|
| 975 |
+
{
|
| 976 |
+
char* subsystem;
|
| 977 |
+
char* device;
|
| 978 |
+
};
|
| 979 |
+
UINT error = CHANNEL_RC_INITIALIZATION_ERROR;
|
| 980 |
+
struct SubsystemEntry entries[] =
|
| 981 |
+
{
|
| 982 |
+
#if defined(WITH_PULSE)
|
| 983 |
+
{ "pulse", "" },
|
| 984 |
+
#endif
|
| 985 |
+
#if defined(WITH_OSS)
|
| 986 |
+
{ "oss", "default" },
|
| 987 |
+
#endif
|
| 988 |
+
#if defined(WITH_ALSA)
|
| 989 |
+
{ "alsa", "default" },
|
| 990 |
+
#endif
|
| 991 |
+
#if defined(WITH_OPENSLES)
|
| 992 |
+
{ "opensles", "default" },
|
| 993 |
+
#endif
|
| 994 |
+
#if defined(WITH_WINMM)
|
| 995 |
+
{ "winmm", "default" },
|
| 996 |
+
#endif
|
| 997 |
+
#if defined(WITH_MACAUDIO)
|
| 998 |
+
{ "mac", "default" },
|
| 999 |
+
#endif
|
| 1000 |
+
#if defined(WITH_IOSAUDIO)
|
| 1001 |
+
{ "ios", "default" },
|
| 1002 |
+
#endif
|
| 1003 |
+
#if defined(WITH_SNDIO)
|
| 1004 |
+
{ "sndio", "default" },
|
| 1005 |
+
#endif
|
| 1006 |
+
{ NULL, NULL }
|
| 1007 |
+
};
|
| 1008 |
+
struct SubsystemEntry* entry = &entries[0];
|
| 1009 |
+
WINPR_ASSERT(pEntryPoints);
|
| 1010 |
+
WINPR_ASSERT(pEntryPoints->GetPlugin);
|
| 1011 |
+
AUDIN_PLUGIN* audin = (AUDIN_PLUGIN*)pEntryPoints->GetPlugin(pEntryPoints, AUDIN_CHANNEL_NAME);
|
| 1012 |
+
|
| 1013 |
+
if (audin != NULL)
|
| 1014 |
+
return CHANNEL_RC_ALREADY_INITIALIZED;
|
| 1015 |
+
|
| 1016 |
+
audin = (AUDIN_PLUGIN*)calloc(1, sizeof(AUDIN_PLUGIN));
|
| 1017 |
+
|
| 1018 |
+
if (!audin)
|
| 1019 |
+
{
|
| 1020 |
+
WLog_ERR(TAG, "calloc failed!");
|
| 1021 |
+
return CHANNEL_RC_NO_MEMORY;
|
| 1022 |
+
}
|
| 1023 |
+
|
| 1024 |
+
audin->log = WLog_Get(TAG);
|
| 1025 |
+
audin->data = Stream_New(NULL, 4096);
|
| 1026 |
+
audin->fixed_format = audio_format_new();
|
| 1027 |
+
|
| 1028 |
+
if (!audin->fixed_format)
|
| 1029 |
+
goto out;
|
| 1030 |
+
|
| 1031 |
+
if (!audin->data)
|
| 1032 |
+
goto out;
|
| 1033 |
+
|
| 1034 |
+
audin->dsp_context = freerdp_dsp_context_new(TRUE);
|
| 1035 |
+
|
| 1036 |
+
if (!audin->dsp_context)
|
| 1037 |
+
goto out;
|
| 1038 |
+
|
| 1039 |
+
audin->attached = TRUE;
|
| 1040 |
+
audin->iface.Initialize = audin_plugin_initialize;
|
| 1041 |
+
audin->iface.Connected = NULL;
|
| 1042 |
+
audin->iface.Disconnected = NULL;
|
| 1043 |
+
audin->iface.Terminated = audin_plugin_terminated;
|
| 1044 |
+
audin->iface.Attached = audin_plugin_attached;
|
| 1045 |
+
audin->iface.Detached = audin_plugin_detached;
|
| 1046 |
+
|
| 1047 |
+
const ADDIN_ARGV* args = pEntryPoints->GetPluginData(pEntryPoints);
|
| 1048 |
+
audin->rdpcontext = pEntryPoints->GetRdpContext(pEntryPoints);
|
| 1049 |
+
|
| 1050 |
+
if (args)
|
| 1051 |
+
{
|
| 1052 |
+
if (!audin_process_addin_args(audin, args))
|
| 1053 |
+
goto out;
|
| 1054 |
+
}
|
| 1055 |
+
|
| 1056 |
+
if (audin->subsystem)
|
| 1057 |
+
{
|
| 1058 |
+
if ((error = audin_load_device_plugin(audin, audin->subsystem, args)))
|
| 1059 |
+
{
|
| 1060 |
+
WLog_Print(
|
| 1061 |
+
audin->log, WLOG_ERROR,
|
| 1062 |
+
"Unable to load microphone redirection subsystem %s because of error %" PRIu32 "",
|
| 1063 |
+
audin->subsystem, error);
|
| 1064 |
+
goto out;
|
| 1065 |
+
}
|
| 1066 |
+
}
|
| 1067 |
+
else
|
| 1068 |
+
{
|
| 1069 |
+
while (entry && entry->subsystem && !audin->device)
|
| 1070 |
+
{
|
| 1071 |
+
if ((error = audin_set_subsystem(audin, entry->subsystem)))
|
| 1072 |
+
{
|
| 1073 |
+
WLog_Print(audin->log, WLOG_ERROR,
|
| 1074 |
+
"audin_set_subsystem for %s failed with error %" PRIu32 "!",
|
| 1075 |
+
entry->subsystem, error);
|
| 1076 |
+
}
|
| 1077 |
+
else if ((error = audin_set_device_name(audin, entry->device)))
|
| 1078 |
+
{
|
| 1079 |
+
WLog_Print(audin->log, WLOG_ERROR,
|
| 1080 |
+
"audin_set_device_name for %s failed with error %" PRIu32 "!",
|
| 1081 |
+
entry->subsystem, error);
|
| 1082 |
+
}
|
| 1083 |
+
else if ((error = audin_load_device_plugin(audin, audin->subsystem, args)))
|
| 1084 |
+
{
|
| 1085 |
+
WLog_Print(audin->log, WLOG_ERROR,
|
| 1086 |
+
"audin_load_device_plugin %s failed with error %" PRIu32 "!",
|
| 1087 |
+
entry->subsystem, error);
|
| 1088 |
+
}
|
| 1089 |
+
|
| 1090 |
+
entry++;
|
| 1091 |
+
}
|
| 1092 |
+
}
|
| 1093 |
+
|
| 1094 |
+
if (audin->device == NULL)
|
| 1095 |
+
{
|
| 1096 |
+
/* If we have no audin device do not register plugin but still return OK or the client will
|
| 1097 |
+
* just disconnect due to a missing microphone. */
|
| 1098 |
+
WLog_Print(audin->log, WLOG_ERROR, "No microphone device could be found.");
|
| 1099 |
+
error = CHANNEL_RC_OK;
|
| 1100 |
+
goto out;
|
| 1101 |
+
}
|
| 1102 |
+
|
| 1103 |
+
error = pEntryPoints->RegisterPlugin(pEntryPoints, AUDIN_CHANNEL_NAME, &audin->iface);
|
| 1104 |
+
if (error == CHANNEL_RC_OK)
|
| 1105 |
+
return error;
|
| 1106 |
+
|
| 1107 |
+
out:
|
| 1108 |
+
audin_plugin_terminated(&audin->iface);
|
| 1109 |
+
return error;
|
| 1110 |
+
}
|
local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/audin_main.h
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* FreeRDP: A Remote Desktop Protocol Implementation
|
| 3 |
+
* Audio Input Redirection Virtual Channel
|
| 4 |
+
*
|
| 5 |
+
* Copyright 2010-2011 Vic Lee
|
| 6 |
+
*
|
| 7 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 8 |
+
* you may not use this file except in compliance with the License.
|
| 9 |
+
* You may obtain a copy of the License at
|
| 10 |
+
*
|
| 11 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
+
*
|
| 13 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 14 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 15 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 16 |
+
* See the License for the specific language governing permissions and
|
| 17 |
+
* limitations under the License.
|
| 18 |
+
*/
|
| 19 |
+
|
| 20 |
+
#ifndef FREERDP_CHANNEL_AUDIN_CLIENT_MAIN_H
|
| 21 |
+
#define FREERDP_CHANNEL_AUDIN_CLIENT_MAIN_H
|
| 22 |
+
|
| 23 |
+
#include <freerdp/config.h>
|
| 24 |
+
|
| 25 |
+
#include <freerdp/dvc.h>
|
| 26 |
+
#include <freerdp/types.h>
|
| 27 |
+
#include <freerdp/addin.h>
|
| 28 |
+
#include <freerdp/channels/log.h>
|
| 29 |
+
#include <freerdp/client/audin.h>
|
| 30 |
+
|
| 31 |
+
#define TAG CHANNELS_TAG("audin.client")
|
| 32 |
+
|
| 33 |
+
#endif /* FREERDP_CHANNEL_AUDIN_CLIENT_MAIN_H */
|
local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/ios/CMakeLists.txt
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# FreeRDP: A Remote Desktop Protocol Implementation
|
| 2 |
+
# FreeRDP cmake build script
|
| 3 |
+
#
|
| 4 |
+
# Copyright (c) 2015 Armin Novak <armin.novak@thincast.com>
|
| 5 |
+
# Copyright (c) 2015 Thincast Technologies GmbH
|
| 6 |
+
#
|
| 7 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 8 |
+
# you may not use this file except in compliance with the License.
|
| 9 |
+
# You may obtain a copy of the License at
|
| 10 |
+
#
|
| 11 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
+
#
|
| 13 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 14 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 15 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 16 |
+
# See the License for the specific language governing permissions and
|
| 17 |
+
# limitations under the License.
|
| 18 |
+
|
| 19 |
+
define_channel_client_subsystem("audin" "ios" "")
|
| 20 |
+
find_library(CORE_AUDIO CoreAudio)
|
| 21 |
+
find_library(AVFOUNDATION AVFoundation)
|
| 22 |
+
find_library(AUDIO_TOOL AudioToolbox)
|
| 23 |
+
|
| 24 |
+
set(${MODULE_PREFIX}_SRCS audin_ios.m)
|
| 25 |
+
|
| 26 |
+
set(${MODULE_PREFIX}_LIBS winpr freerdp ${AVFOUNDATION} ${CORE_AUDIO} ${AUDIO_TOOL})
|
| 27 |
+
|
| 28 |
+
include_directories(..)
|
| 29 |
+
include_directories(SYSTEM ${MAC_INCLUDE_DIRS})
|
| 30 |
+
|
| 31 |
+
add_channel_client_subsystem_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} "" TRUE "")
|
local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/ios/audin_ios.m
ADDED
|
@@ -0,0 +1,335 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* FreeRDP: A Remote Desktop Protocol Implementation
|
| 3 |
+
* Audio Input Redirection Virtual Channel - iOS implementation
|
| 4 |
+
*
|
| 5 |
+
* Copyright (c) 2015 Armin Novak <armin.novak@thincast.com>
|
| 6 |
+
* Copyright 2015 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/synch.h>
|
| 29 |
+
#include <winpr/string.h>
|
| 30 |
+
#include <winpr/thread.h>
|
| 31 |
+
#include <winpr/debug.h>
|
| 32 |
+
#include <winpr/cmdline.h>
|
| 33 |
+
|
| 34 |
+
#import <AVFoundation/AVFoundation.h>
|
| 35 |
+
|
| 36 |
+
#define __COREFOUNDATION_CFPLUGINCOM__ 1
|
| 37 |
+
#define IUNKNOWN_C_GUTS \
|
| 38 |
+
void *_reserved; \
|
| 39 |
+
void *QueryInterface; \
|
| 40 |
+
void *AddRef; \
|
| 41 |
+
void *Release
|
| 42 |
+
|
| 43 |
+
#include <CoreAudio/CoreAudioTypes.h>
|
| 44 |
+
#include <AudioToolbox/AudioToolbox.h>
|
| 45 |
+
#include <AudioToolbox/AudioQueue.h>
|
| 46 |
+
|
| 47 |
+
#include <freerdp/addin.h>
|
| 48 |
+
#include <freerdp/channels/rdpsnd.h>
|
| 49 |
+
|
| 50 |
+
#include "audin_main.h"
|
| 51 |
+
|
| 52 |
+
#define IOS_AUDIO_QUEUE_NUM_BUFFERS 100
|
| 53 |
+
|
| 54 |
+
typedef struct
|
| 55 |
+
{
|
| 56 |
+
IAudinDevice iface;
|
| 57 |
+
|
| 58 |
+
AUDIO_FORMAT format;
|
| 59 |
+
UINT32 FramesPerPacket;
|
| 60 |
+
int dev_unit;
|
| 61 |
+
|
| 62 |
+
AudinReceive receive;
|
| 63 |
+
void *user_data;
|
| 64 |
+
|
| 65 |
+
rdpContext *rdpcontext;
|
| 66 |
+
|
| 67 |
+
bool isOpen;
|
| 68 |
+
AudioQueueRef audioQueue;
|
| 69 |
+
AudioStreamBasicDescription audioFormat;
|
| 70 |
+
AudioQueueBufferRef audioBuffers[IOS_AUDIO_QUEUE_NUM_BUFFERS];
|
| 71 |
+
} AudinIosDevice;
|
| 72 |
+
|
| 73 |
+
static AudioFormatID audin_ios_get_format(const AUDIO_FORMAT *format)
|
| 74 |
+
{
|
| 75 |
+
switch (format->wFormatTag)
|
| 76 |
+
{
|
| 77 |
+
case WAVE_FORMAT_PCM:
|
| 78 |
+
return kAudioFormatLinearPCM;
|
| 79 |
+
|
| 80 |
+
default:
|
| 81 |
+
return 0;
|
| 82 |
+
}
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
static AudioFormatFlags audin_ios_get_flags_for_format(const AUDIO_FORMAT *format)
|
| 86 |
+
{
|
| 87 |
+
switch (format->wFormatTag)
|
| 88 |
+
{
|
| 89 |
+
case WAVE_FORMAT_PCM:
|
| 90 |
+
return kAudioFormatFlagIsSignedInteger;
|
| 91 |
+
|
| 92 |
+
default:
|
| 93 |
+
return 0;
|
| 94 |
+
}
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
static BOOL audin_ios_format_supported(IAudinDevice *device, const AUDIO_FORMAT *format)
|
| 98 |
+
{
|
| 99 |
+
AudinIosDevice *ios = (AudinIosDevice *)device;
|
| 100 |
+
AudioFormatID req_fmt = 0;
|
| 101 |
+
|
| 102 |
+
if (device == NULL || format == NULL)
|
| 103 |
+
return FALSE;
|
| 104 |
+
|
| 105 |
+
req_fmt = audin_ios_get_format(format);
|
| 106 |
+
|
| 107 |
+
if (req_fmt == 0)
|
| 108 |
+
return FALSE;
|
| 109 |
+
|
| 110 |
+
return TRUE;
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
/**
|
| 114 |
+
* Function description
|
| 115 |
+
*
|
| 116 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 117 |
+
*/
|
| 118 |
+
static UINT audin_ios_set_format(IAudinDevice *device, const AUDIO_FORMAT *format,
|
| 119 |
+
UINT32 FramesPerPacket)
|
| 120 |
+
{
|
| 121 |
+
AudinIosDevice *ios = (AudinIosDevice *)device;
|
| 122 |
+
|
| 123 |
+
if (device == NULL || format == NULL)
|
| 124 |
+
return ERROR_INVALID_PARAMETER;
|
| 125 |
+
|
| 126 |
+
ios->FramesPerPacket = FramesPerPacket;
|
| 127 |
+
ios->format = *format;
|
| 128 |
+
WLog_INFO(TAG, "Audio Format %s [channels=%d, samples=%d, bits=%d]",
|
| 129 |
+
audio_format_get_tag_string(format->wFormatTag), format->nChannels,
|
| 130 |
+
format->nSamplesPerSec, format->wBitsPerSample);
|
| 131 |
+
ios->audioFormat.mBitsPerChannel = format->wBitsPerSample;
|
| 132 |
+
|
| 133 |
+
if (format->wBitsPerSample == 0)
|
| 134 |
+
ios->audioFormat.mBitsPerChannel = 16;
|
| 135 |
+
|
| 136 |
+
ios->audioFormat.mChannelsPerFrame = ios->format.nChannels;
|
| 137 |
+
ios->audioFormat.mFramesPerPacket = 1;
|
| 138 |
+
|
| 139 |
+
ios->audioFormat.mBytesPerFrame =
|
| 140 |
+
ios->audioFormat.mChannelsPerFrame * (ios->audioFormat.mBitsPerChannel / 8);
|
| 141 |
+
ios->audioFormat.mBytesPerPacket =
|
| 142 |
+
ios->audioFormat.mBytesPerFrame * ios->audioFormat.mFramesPerPacket;
|
| 143 |
+
|
| 144 |
+
ios->audioFormat.mFormatFlags = audin_ios_get_flags_for_format(format);
|
| 145 |
+
ios->audioFormat.mFormatID = audin_ios_get_format(format);
|
| 146 |
+
ios->audioFormat.mReserved = 0;
|
| 147 |
+
ios->audioFormat.mSampleRate = ios->format.nSamplesPerSec;
|
| 148 |
+
return CHANNEL_RC_OK;
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
static void ios_audio_queue_input_cb(void *aqData, AudioQueueRef inAQ, AudioQueueBufferRef inBuffer,
|
| 152 |
+
const AudioTimeStamp *inStartTime, UInt32 inNumPackets,
|
| 153 |
+
const AudioStreamPacketDescription *inPacketDesc)
|
| 154 |
+
{
|
| 155 |
+
AudinIosDevice *ios = (AudinIosDevice *)aqData;
|
| 156 |
+
UINT error = CHANNEL_RC_OK;
|
| 157 |
+
const BYTE *buffer = inBuffer->mAudioData;
|
| 158 |
+
int buffer_size = inBuffer->mAudioDataByteSize;
|
| 159 |
+
(void)inAQ;
|
| 160 |
+
(void)inStartTime;
|
| 161 |
+
(void)inNumPackets;
|
| 162 |
+
(void)inPacketDesc;
|
| 163 |
+
|
| 164 |
+
if (buffer_size > 0)
|
| 165 |
+
error = ios->receive(&ios->format, buffer, buffer_size, ios->user_data);
|
| 166 |
+
|
| 167 |
+
AudioQueueEnqueueBuffer(inAQ, inBuffer, 0, NULL);
|
| 168 |
+
|
| 169 |
+
if (error)
|
| 170 |
+
{
|
| 171 |
+
WLog_ERR(TAG, "ios->receive failed with error %" PRIu32 "", error);
|
| 172 |
+
SetLastError(ERROR_INTERNAL_ERROR);
|
| 173 |
+
}
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
static UINT audin_ios_close(IAudinDevice *device)
|
| 177 |
+
{
|
| 178 |
+
UINT errCode = CHANNEL_RC_OK;
|
| 179 |
+
char errString[1024];
|
| 180 |
+
OSStatus devStat;
|
| 181 |
+
AudinIosDevice *ios = (AudinIosDevice *)device;
|
| 182 |
+
|
| 183 |
+
if (device == NULL)
|
| 184 |
+
return ERROR_INVALID_PARAMETER;
|
| 185 |
+
|
| 186 |
+
if (ios->isOpen)
|
| 187 |
+
{
|
| 188 |
+
devStat = AudioQueueStop(ios->audioQueue, true);
|
| 189 |
+
|
| 190 |
+
if (devStat != 0)
|
| 191 |
+
{
|
| 192 |
+
errCode = GetLastError();
|
| 193 |
+
WLog_ERR(TAG, "AudioQueueStop failed with %s [%" PRIu32 "]",
|
| 194 |
+
winpr_strerror(errCode, errString, sizeof(errString)), errCode);
|
| 195 |
+
}
|
| 196 |
+
|
| 197 |
+
ios->isOpen = false;
|
| 198 |
+
}
|
| 199 |
+
|
| 200 |
+
if (ios->audioQueue)
|
| 201 |
+
{
|
| 202 |
+
devStat = AudioQueueDispose(ios->audioQueue, true);
|
| 203 |
+
|
| 204 |
+
if (devStat != 0)
|
| 205 |
+
{
|
| 206 |
+
errCode = GetLastError();
|
| 207 |
+
WLog_ERR(TAG, "AudioQueueDispose failed with %s [%" PRIu32 "]",
|
| 208 |
+
winpr_strerror(errCode, errString, sizeof(errString)), errCode);
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
ios->audioQueue = NULL;
|
| 212 |
+
}
|
| 213 |
+
|
| 214 |
+
ios->receive = NULL;
|
| 215 |
+
ios->user_data = NULL;
|
| 216 |
+
return errCode;
|
| 217 |
+
}
|
| 218 |
+
|
| 219 |
+
static UINT audin_ios_open(IAudinDevice *device, AudinReceive receive, void *user_data)
|
| 220 |
+
{
|
| 221 |
+
AudinIosDevice *ios = (AudinIosDevice *)device;
|
| 222 |
+
DWORD errCode;
|
| 223 |
+
char errString[1024];
|
| 224 |
+
OSStatus devStat;
|
| 225 |
+
|
| 226 |
+
ios->receive = receive;
|
| 227 |
+
ios->user_data = user_data;
|
| 228 |
+
devStat = AudioQueueNewInput(&(ios->audioFormat), ios_audio_queue_input_cb, ios, NULL,
|
| 229 |
+
kCFRunLoopCommonModes, 0, &(ios->audioQueue));
|
| 230 |
+
|
| 231 |
+
if (devStat != 0)
|
| 232 |
+
{
|
| 233 |
+
errCode = GetLastError();
|
| 234 |
+
WLog_ERR(TAG, "AudioQueueNewInput failed with %s [%" PRIu32 "]",
|
| 235 |
+
winpr_strerror(errCode, errString, sizeof(errString)), errCode);
|
| 236 |
+
goto err_out;
|
| 237 |
+
}
|
| 238 |
+
|
| 239 |
+
for (size_t index = 0; index < IOS_AUDIO_QUEUE_NUM_BUFFERS; index++)
|
| 240 |
+
{
|
| 241 |
+
devStat = AudioQueueAllocateBuffer(ios->audioQueue,
|
| 242 |
+
ios->FramesPerPacket * 2 * ios->format.nChannels,
|
| 243 |
+
&ios->audioBuffers[index]);
|
| 244 |
+
|
| 245 |
+
if (devStat != 0)
|
| 246 |
+
{
|
| 247 |
+
errCode = GetLastError();
|
| 248 |
+
WLog_ERR(TAG, "AudioQueueAllocateBuffer failed with %s [%" PRIu32 "]",
|
| 249 |
+
winpr_strerror(errCode, errString, sizeof(errString)), errCode);
|
| 250 |
+
goto err_out;
|
| 251 |
+
}
|
| 252 |
+
|
| 253 |
+
devStat = AudioQueueEnqueueBuffer(ios->audioQueue, ios->audioBuffers[index], 0, NULL);
|
| 254 |
+
|
| 255 |
+
if (devStat != 0)
|
| 256 |
+
{
|
| 257 |
+
errCode = GetLastError();
|
| 258 |
+
WLog_ERR(TAG, "AudioQueueEnqueueBuffer failed with %s [%" PRIu32 "]",
|
| 259 |
+
winpr_strerror(errCode, errString, sizeof(errString)), errCode);
|
| 260 |
+
goto err_out;
|
| 261 |
+
}
|
| 262 |
+
}
|
| 263 |
+
|
| 264 |
+
devStat = AudioQueueStart(ios->audioQueue, NULL);
|
| 265 |
+
|
| 266 |
+
if (devStat != 0)
|
| 267 |
+
{
|
| 268 |
+
errCode = GetLastError();
|
| 269 |
+
WLog_ERR(TAG, "AudioQueueStart failed with %s [%" PRIu32 "]",
|
| 270 |
+
winpr_strerror(errCode, errString, sizeof(errString)), errCode);
|
| 271 |
+
goto err_out;
|
| 272 |
+
}
|
| 273 |
+
|
| 274 |
+
ios->isOpen = true;
|
| 275 |
+
return CHANNEL_RC_OK;
|
| 276 |
+
err_out:
|
| 277 |
+
audin_ios_close(device);
|
| 278 |
+
return CHANNEL_RC_INITIALIZATION_ERROR;
|
| 279 |
+
}
|
| 280 |
+
|
| 281 |
+
static UINT audin_ios_free(IAudinDevice *device)
|
| 282 |
+
{
|
| 283 |
+
AudinIosDevice *ios = (AudinIosDevice *)device;
|
| 284 |
+
int error;
|
| 285 |
+
|
| 286 |
+
if (device == NULL)
|
| 287 |
+
return ERROR_INVALID_PARAMETER;
|
| 288 |
+
|
| 289 |
+
if ((error = audin_ios_close(device)))
|
| 290 |
+
{
|
| 291 |
+
WLog_ERR(TAG, "audin_oss_close failed with error code %d!", error);
|
| 292 |
+
}
|
| 293 |
+
|
| 294 |
+
free(ios);
|
| 295 |
+
return CHANNEL_RC_OK;
|
| 296 |
+
}
|
| 297 |
+
|
| 298 |
+
FREERDP_ENTRY_POINT(UINT VCAPITYPE ios_freerdp_audin_client_subsystem_entry(
|
| 299 |
+
PFREERDP_AUDIN_DEVICE_ENTRY_POINTS pEntryPoints))
|
| 300 |
+
{
|
| 301 |
+
DWORD errCode;
|
| 302 |
+
char errString[1024];
|
| 303 |
+
const ADDIN_ARGV *args;
|
| 304 |
+
AudinIosDevice *ios;
|
| 305 |
+
UINT error;
|
| 306 |
+
ios = (AudinIosDevice *)calloc(1, sizeof(AudinIosDevice));
|
| 307 |
+
|
| 308 |
+
if (!ios)
|
| 309 |
+
{
|
| 310 |
+
errCode = GetLastError();
|
| 311 |
+
WLog_ERR(TAG, "calloc failed with %s [%" PRIu32 "]",
|
| 312 |
+
winpr_strerror(errCode, errString, sizeof(errString)), errCode);
|
| 313 |
+
return CHANNEL_RC_NO_MEMORY;
|
| 314 |
+
}
|
| 315 |
+
|
| 316 |
+
ios->iface.Open = audin_ios_open;
|
| 317 |
+
ios->iface.FormatSupported = audin_ios_format_supported;
|
| 318 |
+
ios->iface.SetFormat = audin_ios_set_format;
|
| 319 |
+
ios->iface.Close = audin_ios_close;
|
| 320 |
+
ios->iface.Free = audin_ios_free;
|
| 321 |
+
ios->rdpcontext = pEntryPoints->rdpcontext;
|
| 322 |
+
ios->dev_unit = -1;
|
| 323 |
+
args = pEntryPoints->args;
|
| 324 |
+
|
| 325 |
+
if ((error = pEntryPoints->pRegisterAudinDevice(pEntryPoints->plugin, (IAudinDevice *)ios)))
|
| 326 |
+
{
|
| 327 |
+
WLog_ERR(TAG, "RegisterAudinDevice failed with error %" PRIu32 "!", error);
|
| 328 |
+
goto error_out;
|
| 329 |
+
}
|
| 330 |
+
|
| 331 |
+
return CHANNEL_RC_OK;
|
| 332 |
+
error_out:
|
| 333 |
+
free(ios);
|
| 334 |
+
return error;
|
| 335 |
+
}
|
local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/mac/CMakeLists.txt
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# FreeRDP: A Remote Desktop Protocol Implementation
|
| 2 |
+
# FreeRDP cmake build script
|
| 3 |
+
#
|
| 4 |
+
# Copyright (c) 2015 Armin Novak <armin.novak@thincast.com>
|
| 5 |
+
# Copyright (c) 2015 Thincast Technologies GmbH
|
| 6 |
+
#
|
| 7 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 8 |
+
# you may not use this file except in compliance with the License.
|
| 9 |
+
# You may obtain a copy of the License at
|
| 10 |
+
#
|
| 11 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
+
#
|
| 13 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 14 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 15 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 16 |
+
# See the License for the specific language governing permissions and
|
| 17 |
+
# limitations under the License.
|
| 18 |
+
|
| 19 |
+
define_channel_client_subsystem("audin" "mac" "")
|
| 20 |
+
find_library(CORE_AUDIO CoreAudio)
|
| 21 |
+
find_library(AVFOUNDATION AVFoundation)
|
| 22 |
+
find_library(AUDIO_TOOL AudioToolbox)
|
| 23 |
+
find_library(APP_SERVICES ApplicationServices)
|
| 24 |
+
|
| 25 |
+
set(${MODULE_PREFIX}_SRCS audin_mac.m)
|
| 26 |
+
|
| 27 |
+
set(${MODULE_PREFIX}_LIBS winpr freerdp ${AVFOUNDATION} ${CORE_AUDIO} ${AUDIO_TOOL} ${APP_SERVICES})
|
| 28 |
+
|
| 29 |
+
include_directories(..)
|
| 30 |
+
include_directories(SYSTEM ${MAC_INCLUDE_DIRS})
|
| 31 |
+
|
| 32 |
+
add_channel_client_subsystem_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} "" TRUE "")
|
local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/mac/audin_mac.m
ADDED
|
@@ -0,0 +1,463 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
| 1 |
+
/**
|
| 2 |
+
* FreeRDP: A Remote Desktop Protocol Implementation
|
| 3 |
+
* Audio Input Redirection Virtual Channel - Mac OS X implementation
|
| 4 |
+
*
|
| 5 |
+
* Copyright (c) 2015 Armin Novak <armin.novak@thincast.com>
|
| 6 |
+
* Copyright 2015 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/synch.h>
|
| 29 |
+
#include <winpr/string.h>
|
| 30 |
+
#include <winpr/thread.h>
|
| 31 |
+
#include <winpr/debug.h>
|
| 32 |
+
#include <winpr/cmdline.h>
|
| 33 |
+
|
| 34 |
+
#import <AVFoundation/AVFoundation.h>
|
| 35 |
+
|
| 36 |
+
#define __COREFOUNDATION_CFPLUGINCOM__ 1
|
| 37 |
+
#define IUNKNOWN_C_GUTS \
|
| 38 |
+
void *_reserved; \
|
| 39 |
+
void *QueryInterface; \
|
| 40 |
+
void *AddRef; \
|
| 41 |
+
void *Release
|
| 42 |
+
|
| 43 |
+
#include <CoreAudio/CoreAudioTypes.h>
|
| 44 |
+
#include <CoreAudio/CoreAudio.h>
|
| 45 |
+
#include <AudioToolbox/AudioToolbox.h>
|
| 46 |
+
#include <AudioToolbox/AudioQueue.h>
|
| 47 |
+
|
| 48 |
+
#include <freerdp/addin.h>
|
| 49 |
+
#include <freerdp/channels/rdpsnd.h>
|
| 50 |
+
|
| 51 |
+
#include "audin_main.h"
|
| 52 |
+
|
| 53 |
+
#define MAC_AUDIO_QUEUE_NUM_BUFFERS 100
|
| 54 |
+
|
| 55 |
+
/* Fix for #4462: Provide type alias if not declared (Mac OS < 10.10)
|
| 56 |
+
* https://developer.apple.com/documentation/coreaudio/audioformatid
|
| 57 |
+
*/
|
| 58 |
+
#ifndef AudioFormatID
|
| 59 |
+
typedef UInt32 AudioFormatID;
|
| 60 |
+
#endif
|
| 61 |
+
|
| 62 |
+
#ifndef AudioFormatFlags
|
| 63 |
+
typedef UInt32 AudioFormatFlags;
|
| 64 |
+
#endif
|
| 65 |
+
|
| 66 |
+
typedef struct
|
| 67 |
+
{
|
| 68 |
+
IAudinDevice iface;
|
| 69 |
+
|
| 70 |
+
AUDIO_FORMAT format;
|
| 71 |
+
UINT32 FramesPerPacket;
|
| 72 |
+
int dev_unit;
|
| 73 |
+
|
| 74 |
+
AudinReceive receive;
|
| 75 |
+
void *user_data;
|
| 76 |
+
|
| 77 |
+
rdpContext *rdpcontext;
|
| 78 |
+
|
| 79 |
+
bool isAuthorized;
|
| 80 |
+
bool isOpen;
|
| 81 |
+
AudioQueueRef audioQueue;
|
| 82 |
+
AudioStreamBasicDescription audioFormat;
|
| 83 |
+
AudioQueueBufferRef audioBuffers[MAC_AUDIO_QUEUE_NUM_BUFFERS];
|
| 84 |
+
} AudinMacDevice;
|
| 85 |
+
|
| 86 |
+
static AudioFormatID audin_mac_get_format(const AUDIO_FORMAT *format)
|
| 87 |
+
{
|
| 88 |
+
switch (format->wFormatTag)
|
| 89 |
+
{
|
| 90 |
+
case WAVE_FORMAT_PCM:
|
| 91 |
+
return kAudioFormatLinearPCM;
|
| 92 |
+
|
| 93 |
+
default:
|
| 94 |
+
return 0;
|
| 95 |
+
}
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
static AudioFormatFlags audin_mac_get_flags_for_format(const AUDIO_FORMAT *format)
|
| 99 |
+
{
|
| 100 |
+
switch (format->wFormatTag)
|
| 101 |
+
{
|
| 102 |
+
case WAVE_FORMAT_PCM:
|
| 103 |
+
return kAudioFormatFlagIsSignedInteger;
|
| 104 |
+
|
| 105 |
+
default:
|
| 106 |
+
return 0;
|
| 107 |
+
}
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
static BOOL audin_mac_format_supported(IAudinDevice *device, const AUDIO_FORMAT *format)
|
| 111 |
+
{
|
| 112 |
+
AudinMacDevice *mac = (AudinMacDevice *)device;
|
| 113 |
+
AudioFormatID req_fmt = 0;
|
| 114 |
+
|
| 115 |
+
if (!mac->isAuthorized)
|
| 116 |
+
return FALSE;
|
| 117 |
+
|
| 118 |
+
if (device == NULL || format == NULL)
|
| 119 |
+
return FALSE;
|
| 120 |
+
|
| 121 |
+
if (format->nChannels != 2)
|
| 122 |
+
return FALSE;
|
| 123 |
+
|
| 124 |
+
req_fmt = audin_mac_get_format(format);
|
| 125 |
+
|
| 126 |
+
if (req_fmt == 0)
|
| 127 |
+
return FALSE;
|
| 128 |
+
|
| 129 |
+
return TRUE;
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
/**
|
| 133 |
+
* Function description
|
| 134 |
+
*
|
| 135 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 136 |
+
*/
|
| 137 |
+
static UINT audin_mac_set_format(IAudinDevice *device, const AUDIO_FORMAT *format,
|
| 138 |
+
UINT32 FramesPerPacket)
|
| 139 |
+
{
|
| 140 |
+
AudinMacDevice *mac = (AudinMacDevice *)device;
|
| 141 |
+
|
| 142 |
+
if (!mac->isAuthorized)
|
| 143 |
+
return ERROR_INTERNAL_ERROR;
|
| 144 |
+
|
| 145 |
+
if (device == NULL || format == NULL)
|
| 146 |
+
return ERROR_INVALID_PARAMETER;
|
| 147 |
+
|
| 148 |
+
mac->FramesPerPacket = FramesPerPacket;
|
| 149 |
+
mac->format = *format;
|
| 150 |
+
WLog_INFO(TAG, "Audio Format %s [channels=%d, samples=%d, bits=%d]",
|
| 151 |
+
audio_format_get_tag_string(format->wFormatTag), format->nChannels,
|
| 152 |
+
format->nSamplesPerSec, format->wBitsPerSample);
|
| 153 |
+
mac->audioFormat.mBitsPerChannel = format->wBitsPerSample;
|
| 154 |
+
|
| 155 |
+
if (format->wBitsPerSample == 0)
|
| 156 |
+
mac->audioFormat.mBitsPerChannel = 16;
|
| 157 |
+
|
| 158 |
+
mac->audioFormat.mChannelsPerFrame = mac->format.nChannels;
|
| 159 |
+
mac->audioFormat.mFramesPerPacket = 1;
|
| 160 |
+
|
| 161 |
+
mac->audioFormat.mBytesPerFrame =
|
| 162 |
+
mac->audioFormat.mChannelsPerFrame * (mac->audioFormat.mBitsPerChannel / 8);
|
| 163 |
+
mac->audioFormat.mBytesPerPacket =
|
| 164 |
+
mac->audioFormat.mBytesPerFrame * mac->audioFormat.mFramesPerPacket;
|
| 165 |
+
|
| 166 |
+
mac->audioFormat.mFormatFlags = audin_mac_get_flags_for_format(format);
|
| 167 |
+
mac->audioFormat.mFormatID = audin_mac_get_format(format);
|
| 168 |
+
mac->audioFormat.mReserved = 0;
|
| 169 |
+
mac->audioFormat.mSampleRate = mac->format.nSamplesPerSec;
|
| 170 |
+
return CHANNEL_RC_OK;
|
| 171 |
+
}
|
| 172 |
+
|
| 173 |
+
static void mac_audio_queue_input_cb(void *aqData, AudioQueueRef inAQ, AudioQueueBufferRef inBuffer,
|
| 174 |
+
const AudioTimeStamp *inStartTime, UInt32 inNumPackets,
|
| 175 |
+
const AudioStreamPacketDescription *inPacketDesc)
|
| 176 |
+
{
|
| 177 |
+
AudinMacDevice *mac = (AudinMacDevice *)aqData;
|
| 178 |
+
UINT error = CHANNEL_RC_OK;
|
| 179 |
+
const BYTE *buffer = inBuffer->mAudioData;
|
| 180 |
+
int buffer_size = inBuffer->mAudioDataByteSize;
|
| 181 |
+
(void)inAQ;
|
| 182 |
+
(void)inStartTime;
|
| 183 |
+
(void)inNumPackets;
|
| 184 |
+
(void)inPacketDesc;
|
| 185 |
+
|
| 186 |
+
if (buffer_size > 0)
|
| 187 |
+
error = mac->receive(&mac->format, buffer, buffer_size, mac->user_data);
|
| 188 |
+
|
| 189 |
+
AudioQueueEnqueueBuffer(inAQ, inBuffer, 0, NULL);
|
| 190 |
+
|
| 191 |
+
if (error)
|
| 192 |
+
{
|
| 193 |
+
WLog_ERR(TAG, "mac->receive failed with error %" PRIu32 "", error);
|
| 194 |
+
SetLastError(ERROR_INTERNAL_ERROR);
|
| 195 |
+
}
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
static UINT audin_mac_close(IAudinDevice *device)
|
| 199 |
+
{
|
| 200 |
+
UINT errCode = CHANNEL_RC_OK;
|
| 201 |
+
char errString[1024];
|
| 202 |
+
OSStatus devStat;
|
| 203 |
+
AudinMacDevice *mac = (AudinMacDevice *)device;
|
| 204 |
+
|
| 205 |
+
if (!mac->isAuthorized)
|
| 206 |
+
return ERROR_INTERNAL_ERROR;
|
| 207 |
+
|
| 208 |
+
if (device == NULL)
|
| 209 |
+
return ERROR_INVALID_PARAMETER;
|
| 210 |
+
|
| 211 |
+
if (mac->isOpen)
|
| 212 |
+
{
|
| 213 |
+
devStat = AudioQueueStop(mac->audioQueue, true);
|
| 214 |
+
|
| 215 |
+
if (devStat != 0)
|
| 216 |
+
{
|
| 217 |
+
errCode = GetLastError();
|
| 218 |
+
WLog_ERR(TAG, "AudioQueueStop failed with %s [%" PRIu32 "]",
|
| 219 |
+
winpr_strerror(errCode, errString, sizeof(errString)), errCode);
|
| 220 |
+
}
|
| 221 |
+
|
| 222 |
+
mac->isOpen = false;
|
| 223 |
+
}
|
| 224 |
+
|
| 225 |
+
if (mac->audioQueue)
|
| 226 |
+
{
|
| 227 |
+
devStat = AudioQueueDispose(mac->audioQueue, true);
|
| 228 |
+
|
| 229 |
+
if (devStat != 0)
|
| 230 |
+
{
|
| 231 |
+
errCode = GetLastError();
|
| 232 |
+
WLog_ERR(TAG, "AudioQueueDispose failed with %s [%" PRIu32 "]",
|
| 233 |
+
winpr_strerror(errCode, errString, sizeof(errString)), errCode);
|
| 234 |
+
}
|
| 235 |
+
|
| 236 |
+
mac->audioQueue = NULL;
|
| 237 |
+
}
|
| 238 |
+
|
| 239 |
+
mac->receive = NULL;
|
| 240 |
+
mac->user_data = NULL;
|
| 241 |
+
return errCode;
|
| 242 |
+
}
|
| 243 |
+
|
| 244 |
+
static UINT audin_mac_open(IAudinDevice *device, AudinReceive receive, void *user_data)
|
| 245 |
+
{
|
| 246 |
+
AudinMacDevice *mac = (AudinMacDevice *)device;
|
| 247 |
+
DWORD errCode;
|
| 248 |
+
char errString[1024];
|
| 249 |
+
OSStatus devStat;
|
| 250 |
+
|
| 251 |
+
if (!mac->isAuthorized)
|
| 252 |
+
return ERROR_INTERNAL_ERROR;
|
| 253 |
+
|
| 254 |
+
mac->receive = receive;
|
| 255 |
+
mac->user_data = user_data;
|
| 256 |
+
devStat = AudioQueueNewInput(&(mac->audioFormat), mac_audio_queue_input_cb, mac, NULL,
|
| 257 |
+
kCFRunLoopCommonModes, 0, &(mac->audioQueue));
|
| 258 |
+
|
| 259 |
+
if (devStat != 0)
|
| 260 |
+
{
|
| 261 |
+
errCode = GetLastError();
|
| 262 |
+
WLog_ERR(TAG, "AudioQueueNewInput failed with %s [%" PRIu32 "]",
|
| 263 |
+
winpr_strerror(errCode, errString, sizeof(errString)), errCode);
|
| 264 |
+
goto err_out;
|
| 265 |
+
}
|
| 266 |
+
|
| 267 |
+
for (size_t index = 0; index < MAC_AUDIO_QUEUE_NUM_BUFFERS; index++)
|
| 268 |
+
{
|
| 269 |
+
devStat = AudioQueueAllocateBuffer(mac->audioQueue,
|
| 270 |
+
mac->FramesPerPacket * 2 * mac->format.nChannels,
|
| 271 |
+
&mac->audioBuffers[index]);
|
| 272 |
+
|
| 273 |
+
if (devStat != 0)
|
| 274 |
+
{
|
| 275 |
+
errCode = GetLastError();
|
| 276 |
+
WLog_ERR(TAG, "AudioQueueAllocateBuffer failed with %s [%" PRIu32 "]",
|
| 277 |
+
winpr_strerror(errCode, errString, sizeof(errString)), errCode);
|
| 278 |
+
goto err_out;
|
| 279 |
+
}
|
| 280 |
+
|
| 281 |
+
devStat = AudioQueueEnqueueBuffer(mac->audioQueue, mac->audioBuffers[index], 0, NULL);
|
| 282 |
+
|
| 283 |
+
if (devStat != 0)
|
| 284 |
+
{
|
| 285 |
+
errCode = GetLastError();
|
| 286 |
+
WLog_ERR(TAG, "AudioQueueEnqueueBuffer failed with %s [%" PRIu32 "]",
|
| 287 |
+
winpr_strerror(errCode, errString, sizeof(errString)), errCode);
|
| 288 |
+
goto err_out;
|
| 289 |
+
}
|
| 290 |
+
}
|
| 291 |
+
|
| 292 |
+
devStat = AudioQueueStart(mac->audioQueue, NULL);
|
| 293 |
+
|
| 294 |
+
if (devStat != 0)
|
| 295 |
+
{
|
| 296 |
+
errCode = GetLastError();
|
| 297 |
+
WLog_ERR(TAG, "AudioQueueStart failed with %s [%" PRIu32 "]",
|
| 298 |
+
winpr_strerror(errCode, errString, sizeof(errString)), errCode);
|
| 299 |
+
goto err_out;
|
| 300 |
+
}
|
| 301 |
+
|
| 302 |
+
mac->isOpen = true;
|
| 303 |
+
return CHANNEL_RC_OK;
|
| 304 |
+
err_out:
|
| 305 |
+
audin_mac_close(device);
|
| 306 |
+
return CHANNEL_RC_INITIALIZATION_ERROR;
|
| 307 |
+
}
|
| 308 |
+
|
| 309 |
+
static UINT audin_mac_free(IAudinDevice *device)
|
| 310 |
+
{
|
| 311 |
+
AudinMacDevice *mac = (AudinMacDevice *)device;
|
| 312 |
+
int error;
|
| 313 |
+
|
| 314 |
+
if (device == NULL)
|
| 315 |
+
return ERROR_INVALID_PARAMETER;
|
| 316 |
+
|
| 317 |
+
if ((error = audin_mac_close(device)))
|
| 318 |
+
{
|
| 319 |
+
WLog_ERR(TAG, "audin_oss_close failed with error code %d!", error);
|
| 320 |
+
}
|
| 321 |
+
|
| 322 |
+
free(mac);
|
| 323 |
+
return CHANNEL_RC_OK;
|
| 324 |
+
}
|
| 325 |
+
|
| 326 |
+
static UINT audin_mac_parse_addin_args(AudinMacDevice *device, const ADDIN_ARGV *args)
|
| 327 |
+
{
|
| 328 |
+
DWORD errCode;
|
| 329 |
+
char errString[1024];
|
| 330 |
+
int status;
|
| 331 |
+
char *str_num, *eptr;
|
| 332 |
+
DWORD flags;
|
| 333 |
+
const COMMAND_LINE_ARGUMENT_A *arg;
|
| 334 |
+
COMMAND_LINE_ARGUMENT_A audin_mac_args[] = { { "dev", COMMAND_LINE_VALUE_REQUIRED, "<device>",
|
| 335 |
+
NULL, NULL, -1, NULL, "audio device name" },
|
| 336 |
+
{ NULL, 0, NULL, NULL, NULL, -1, NULL, NULL } };
|
| 337 |
+
|
| 338 |
+
AudinMacDevice *mac = (AudinMacDevice *)device;
|
| 339 |
+
|
| 340 |
+
if (args->argc == 1)
|
| 341 |
+
return CHANNEL_RC_OK;
|
| 342 |
+
|
| 343 |
+
flags =
|
| 344 |
+
COMMAND_LINE_SIGIL_NONE | COMMAND_LINE_SEPARATOR_COLON | COMMAND_LINE_IGN_UNKNOWN_KEYWORD;
|
| 345 |
+
status =
|
| 346 |
+
CommandLineParseArgumentsA(args->argc, args->argv, audin_mac_args, flags, mac, NULL, NULL);
|
| 347 |
+
|
| 348 |
+
if (status < 0)
|
| 349 |
+
return ERROR_INVALID_PARAMETER;
|
| 350 |
+
|
| 351 |
+
arg = audin_mac_args;
|
| 352 |
+
|
| 353 |
+
do
|
| 354 |
+
{
|
| 355 |
+
if (!(arg->Flags & COMMAND_LINE_VALUE_PRESENT))
|
| 356 |
+
continue;
|
| 357 |
+
|
| 358 |
+
CommandLineSwitchStart(arg) CommandLineSwitchCase(arg, "dev")
|
| 359 |
+
{
|
| 360 |
+
str_num = _strdup(arg->Value);
|
| 361 |
+
|
| 362 |
+
if (!str_num)
|
| 363 |
+
{
|
| 364 |
+
errCode = GetLastError();
|
| 365 |
+
WLog_ERR(TAG, "_strdup failed with %s [%d]",
|
| 366 |
+
winpr_strerror(errCode, errString, sizeof(errString)), errCode);
|
| 367 |
+
return CHANNEL_RC_NO_MEMORY;
|
| 368 |
+
}
|
| 369 |
+
|
| 370 |
+
mac->dev_unit = strtol(str_num, &eptr, 10);
|
| 371 |
+
|
| 372 |
+
if (mac->dev_unit < 0 || *eptr != '\0')
|
| 373 |
+
mac->dev_unit = -1;
|
| 374 |
+
|
| 375 |
+
free(str_num);
|
| 376 |
+
}
|
| 377 |
+
CommandLineSwitchEnd(arg)
|
| 378 |
+
} while ((arg = CommandLineFindNextArgumentA(arg)) != NULL);
|
| 379 |
+
|
| 380 |
+
return CHANNEL_RC_OK;
|
| 381 |
+
}
|
| 382 |
+
|
| 383 |
+
FREERDP_ENTRY_POINT(UINT VCAPITYPE mac_freerdp_audin_client_subsystem_entry(
|
| 384 |
+
PFREERDP_AUDIN_DEVICE_ENTRY_POINTS pEntryPoints))
|
| 385 |
+
{
|
| 386 |
+
DWORD errCode;
|
| 387 |
+
char errString[1024];
|
| 388 |
+
const ADDIN_ARGV *args;
|
| 389 |
+
AudinMacDevice *mac;
|
| 390 |
+
UINT error;
|
| 391 |
+
mac = (AudinMacDevice *)calloc(1, sizeof(AudinMacDevice));
|
| 392 |
+
|
| 393 |
+
if (!mac)
|
| 394 |
+
{
|
| 395 |
+
errCode = GetLastError();
|
| 396 |
+
WLog_ERR(TAG, "calloc failed with %s [%" PRIu32 "]",
|
| 397 |
+
winpr_strerror(errCode, errString, sizeof(errString)), errCode);
|
| 398 |
+
return CHANNEL_RC_NO_MEMORY;
|
| 399 |
+
}
|
| 400 |
+
|
| 401 |
+
mac->iface.Open = audin_mac_open;
|
| 402 |
+
mac->iface.FormatSupported = audin_mac_format_supported;
|
| 403 |
+
mac->iface.SetFormat = audin_mac_set_format;
|
| 404 |
+
mac->iface.Close = audin_mac_close;
|
| 405 |
+
mac->iface.Free = audin_mac_free;
|
| 406 |
+
mac->rdpcontext = pEntryPoints->rdpcontext;
|
| 407 |
+
mac->dev_unit = -1;
|
| 408 |
+
args = pEntryPoints->args;
|
| 409 |
+
|
| 410 |
+
if ((error = audin_mac_parse_addin_args(mac, args)))
|
| 411 |
+
{
|
| 412 |
+
WLog_ERR(TAG, "audin_mac_parse_addin_args failed with %" PRIu32 "!", error);
|
| 413 |
+
goto error_out;
|
| 414 |
+
}
|
| 415 |
+
|
| 416 |
+
if ((error = pEntryPoints->pRegisterAudinDevice(pEntryPoints->plugin, (IAudinDevice *)mac)))
|
| 417 |
+
{
|
| 418 |
+
WLog_ERR(TAG, "RegisterAudinDevice failed with error %" PRIu32 "!", error);
|
| 419 |
+
goto error_out;
|
| 420 |
+
}
|
| 421 |
+
|
| 422 |
+
#if defined(MAC_OS_X_VERSION_10_14)
|
| 423 |
+
if (@available(macOS 10.14, *))
|
| 424 |
+
{
|
| 425 |
+
@autoreleasepool
|
| 426 |
+
{
|
| 427 |
+
AVAuthorizationStatus status =
|
| 428 |
+
[AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeAudio];
|
| 429 |
+
switch (status)
|
| 430 |
+
{
|
| 431 |
+
case AVAuthorizationStatusAuthorized:
|
| 432 |
+
mac->isAuthorized = TRUE;
|
| 433 |
+
break;
|
| 434 |
+
case AVAuthorizationStatusNotDetermined:
|
| 435 |
+
[AVCaptureDevice
|
| 436 |
+
requestAccessForMediaType:AVMediaTypeAudio
|
| 437 |
+
completionHandler:^(BOOL granted) {
|
| 438 |
+
if (granted == YES)
|
| 439 |
+
{
|
| 440 |
+
mac->isAuthorized = TRUE;
|
| 441 |
+
}
|
| 442 |
+
else
|
| 443 |
+
WLog_WARN(TAG, "Microphone access denied by user");
|
| 444 |
+
}];
|
| 445 |
+
break;
|
| 446 |
+
case AVAuthorizationStatusRestricted:
|
| 447 |
+
WLog_WARN(TAG, "Microphone access restricted by policy");
|
| 448 |
+
break;
|
| 449 |
+
case AVAuthorizationStatusDenied:
|
| 450 |
+
WLog_WARN(TAG, "Microphone access denied by policy");
|
| 451 |
+
break;
|
| 452 |
+
default:
|
| 453 |
+
break;
|
| 454 |
+
}
|
| 455 |
+
}
|
| 456 |
+
}
|
| 457 |
+
#endif
|
| 458 |
+
|
| 459 |
+
return CHANNEL_RC_OK;
|
| 460 |
+
error_out:
|
| 461 |
+
free(mac);
|
| 462 |
+
return error;
|
| 463 |
+
}
|
local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/opensles/CMakeLists.txt
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# FreeRDP: A Remote Desktop Protocol Implementation
|
| 2 |
+
# FreeRDP cmake build script
|
| 3 |
+
#
|
| 4 |
+
# Copyright 2013 Armin Novak <armin.novak@gmail.com>
|
| 5 |
+
#
|
| 6 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 7 |
+
# you may not use this file except in compliance with the License.
|
| 8 |
+
# You may obtain a copy of the License at
|
| 9 |
+
#
|
| 10 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 11 |
+
#
|
| 12 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 13 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 14 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 15 |
+
# See the License for the specific language governing permissions and
|
| 16 |
+
# limitations under the License.
|
| 17 |
+
|
| 18 |
+
define_channel_client_subsystem("audin" "opensles" "")
|
| 19 |
+
|
| 20 |
+
find_package(OpenSLES REQUIRED)
|
| 21 |
+
|
| 22 |
+
set(${MODULE_PREFIX}_SRCS opensl_io.c audin_opensl_es.c)
|
| 23 |
+
|
| 24 |
+
set(${MODULE_PREFIX}_LIBS winpr freerdp ${OpenSLES_LIBRARIES})
|
| 25 |
+
|
| 26 |
+
include_directories(..)
|
| 27 |
+
include_directories(SYSTEM ${OpenSLES_INCLUDE_DIRS})
|
| 28 |
+
|
| 29 |
+
add_channel_client_subsystem_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} "" TRUE "")
|
local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/opensles/audin_opensl_es.c
ADDED
|
@@ -0,0 +1,336 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* FreeRDP: A Remote Desktop Protocol Implementation
|
| 3 |
+
* Audio Input Redirection Virtual Channel - OpenSL ES implementation
|
| 4 |
+
*
|
| 5 |
+
* Copyright 2013 Armin Novak <armin.novak@gmail.com>
|
| 6 |
+
* Copyright 2015 Thincast Technologies GmbH
|
| 7 |
+
* Copyright 2015 DI (FH) Martin Haimberger <martin.haimberger@thincast.com>
|
| 8 |
+
*
|
| 9 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 10 |
+
* you may not use this file except in compliance with the License.
|
| 11 |
+
* You may obtain a copy of the License at
|
| 12 |
+
*
|
| 13 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 14 |
+
*
|
| 15 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 16 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 17 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 18 |
+
* See the License for the specific language governing permissions and
|
| 19 |
+
* limitations under the License.
|
| 20 |
+
*/
|
| 21 |
+
|
| 22 |
+
#include <freerdp/config.h>
|
| 23 |
+
|
| 24 |
+
#include <winpr/assert.h>
|
| 25 |
+
#include <stdio.h>
|
| 26 |
+
#include <stdlib.h>
|
| 27 |
+
#include <string.h>
|
| 28 |
+
|
| 29 |
+
#include <winpr/crt.h>
|
| 30 |
+
#include <winpr/cmdline.h>
|
| 31 |
+
|
| 32 |
+
#include <freerdp/freerdp.h>
|
| 33 |
+
#include <freerdp/addin.h>
|
| 34 |
+
#include <freerdp/channels/rdpsnd.h>
|
| 35 |
+
|
| 36 |
+
#include <SLES/OpenSLES.h>
|
| 37 |
+
#include <freerdp/client/audin.h>
|
| 38 |
+
|
| 39 |
+
#include "audin_main.h"
|
| 40 |
+
#include "opensl_io.h"
|
| 41 |
+
|
| 42 |
+
typedef struct
|
| 43 |
+
{
|
| 44 |
+
IAudinDevice iface;
|
| 45 |
+
|
| 46 |
+
char* device_name;
|
| 47 |
+
OPENSL_STREAM* stream;
|
| 48 |
+
|
| 49 |
+
AUDIO_FORMAT format;
|
| 50 |
+
UINT32 frames_per_packet;
|
| 51 |
+
|
| 52 |
+
UINT32 bytes_per_channel;
|
| 53 |
+
|
| 54 |
+
AudinReceive receive;
|
| 55 |
+
|
| 56 |
+
void* user_data;
|
| 57 |
+
|
| 58 |
+
rdpContext* rdpcontext;
|
| 59 |
+
wLog* log;
|
| 60 |
+
} AudinOpenSLESDevice;
|
| 61 |
+
|
| 62 |
+
static UINT audin_opensles_close(IAudinDevice* device);
|
| 63 |
+
|
| 64 |
+
static void audin_receive(void* context, const void* data, size_t size)
|
| 65 |
+
{
|
| 66 |
+
UINT error;
|
| 67 |
+
AudinOpenSLESDevice* opensles = (AudinOpenSLESDevice*)context;
|
| 68 |
+
|
| 69 |
+
if (!opensles || !data)
|
| 70 |
+
{
|
| 71 |
+
WLog_ERR(TAG, "Invalid arguments context=%p, data=%p", opensles, data);
|
| 72 |
+
return;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
error = opensles->receive(&opensles->format, data, size, opensles->user_data);
|
| 76 |
+
|
| 77 |
+
if (error && opensles->rdpcontext)
|
| 78 |
+
setChannelError(opensles->rdpcontext, error, "audin_receive reported an error");
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
/**
|
| 82 |
+
* Function description
|
| 83 |
+
*
|
| 84 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 85 |
+
*/
|
| 86 |
+
static UINT audin_opensles_free(IAudinDevice* device)
|
| 87 |
+
{
|
| 88 |
+
AudinOpenSLESDevice* opensles = (AudinOpenSLESDevice*)device;
|
| 89 |
+
|
| 90 |
+
if (!opensles)
|
| 91 |
+
return ERROR_INVALID_PARAMETER;
|
| 92 |
+
|
| 93 |
+
WLog_Print(opensles->log, WLOG_DEBUG, "device=%p", (void*)device);
|
| 94 |
+
|
| 95 |
+
free(opensles->device_name);
|
| 96 |
+
free(opensles);
|
| 97 |
+
return CHANNEL_RC_OK;
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
static BOOL audin_opensles_format_supported(IAudinDevice* device, const AUDIO_FORMAT* format)
|
| 101 |
+
{
|
| 102 |
+
AudinOpenSLESDevice* opensles = (AudinOpenSLESDevice*)device;
|
| 103 |
+
|
| 104 |
+
if (!opensles || !format)
|
| 105 |
+
return FALSE;
|
| 106 |
+
|
| 107 |
+
WLog_Print(opensles->log, WLOG_DEBUG, "device=%p, format=%p", (void*)opensles, (void*)format);
|
| 108 |
+
WINPR_ASSERT(format);
|
| 109 |
+
|
| 110 |
+
switch (format->wFormatTag)
|
| 111 |
+
{
|
| 112 |
+
case WAVE_FORMAT_PCM: /* PCM */
|
| 113 |
+
if (format->cbSize == 0 && (format->nSamplesPerSec <= 48000) &&
|
| 114 |
+
(format->wBitsPerSample == 8 || format->wBitsPerSample == 16) &&
|
| 115 |
+
(format->nChannels >= 1 && format->nChannels <= 2))
|
| 116 |
+
{
|
| 117 |
+
return TRUE;
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
break;
|
| 121 |
+
|
| 122 |
+
default:
|
| 123 |
+
WLog_Print(opensles->log, WLOG_DEBUG, "Encoding '%s' [0x%04" PRIX16 "] not supported",
|
| 124 |
+
audio_format_get_tag_string(format->wFormatTag), format->wFormatTag);
|
| 125 |
+
break;
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
return FALSE;
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
/**
|
| 132 |
+
* Function description
|
| 133 |
+
*
|
| 134 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 135 |
+
*/
|
| 136 |
+
static UINT audin_opensles_set_format(IAudinDevice* device, const AUDIO_FORMAT* format,
|
| 137 |
+
UINT32 FramesPerPacket)
|
| 138 |
+
{
|
| 139 |
+
AudinOpenSLESDevice* opensles = (AudinOpenSLESDevice*)device;
|
| 140 |
+
|
| 141 |
+
if (!opensles || !format)
|
| 142 |
+
return ERROR_INVALID_PARAMETER;
|
| 143 |
+
|
| 144 |
+
WLog_Print(opensles->log, WLOG_DEBUG, "device=%p, format=%p, FramesPerPacket=%" PRIu32 "",
|
| 145 |
+
(void*)device, (void*)format, FramesPerPacket);
|
| 146 |
+
WINPR_ASSERT(format);
|
| 147 |
+
|
| 148 |
+
opensles->format = *format;
|
| 149 |
+
|
| 150 |
+
switch (format->wFormatTag)
|
| 151 |
+
{
|
| 152 |
+
case WAVE_FORMAT_PCM:
|
| 153 |
+
opensles->frames_per_packet = FramesPerPacket;
|
| 154 |
+
|
| 155 |
+
switch (format->wBitsPerSample)
|
| 156 |
+
{
|
| 157 |
+
case 4:
|
| 158 |
+
opensles->bytes_per_channel = 1;
|
| 159 |
+
break;
|
| 160 |
+
|
| 161 |
+
case 8:
|
| 162 |
+
opensles->bytes_per_channel = 1;
|
| 163 |
+
break;
|
| 164 |
+
|
| 165 |
+
case 16:
|
| 166 |
+
opensles->bytes_per_channel = 2;
|
| 167 |
+
break;
|
| 168 |
+
|
| 169 |
+
default:
|
| 170 |
+
return ERROR_UNSUPPORTED_TYPE;
|
| 171 |
+
}
|
| 172 |
+
|
| 173 |
+
break;
|
| 174 |
+
|
| 175 |
+
default:
|
| 176 |
+
WLog_Print(opensles->log, WLOG_ERROR,
|
| 177 |
+
"Encoding '%" PRIu16 "' [%04" PRIX16 "] not supported", format->wFormatTag,
|
| 178 |
+
format->wFormatTag);
|
| 179 |
+
return ERROR_UNSUPPORTED_TYPE;
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
WLog_Print(opensles->log, WLOG_DEBUG, "frames_per_packet=%" PRIu32,
|
| 183 |
+
opensles->frames_per_packet);
|
| 184 |
+
return CHANNEL_RC_OK;
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
/**
|
| 188 |
+
* Function description
|
| 189 |
+
*
|
| 190 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 191 |
+
*/
|
| 192 |
+
static UINT audin_opensles_open(IAudinDevice* device, AudinReceive receive, void* user_data)
|
| 193 |
+
{
|
| 194 |
+
AudinOpenSLESDevice* opensles = (AudinOpenSLESDevice*)device;
|
| 195 |
+
|
| 196 |
+
if (!opensles || !receive || !user_data)
|
| 197 |
+
return ERROR_INVALID_PARAMETER;
|
| 198 |
+
|
| 199 |
+
WLog_Print(opensles->log, WLOG_DEBUG, "device=%p, receive=%p, user_data=%p", (void*)device,
|
| 200 |
+
(void*)receive, (void*)user_data);
|
| 201 |
+
|
| 202 |
+
if (opensles->stream)
|
| 203 |
+
goto error_out;
|
| 204 |
+
|
| 205 |
+
if (!(opensles->stream = android_OpenRecDevice(
|
| 206 |
+
opensles, audin_receive, opensles->format.nSamplesPerSec, opensles->format.nChannels,
|
| 207 |
+
opensles->frames_per_packet, opensles->format.wBitsPerSample)))
|
| 208 |
+
{
|
| 209 |
+
WLog_Print(opensles->log, WLOG_ERROR, "android_OpenRecDevice failed!");
|
| 210 |
+
goto error_out;
|
| 211 |
+
}
|
| 212 |
+
|
| 213 |
+
opensles->receive = receive;
|
| 214 |
+
opensles->user_data = user_data;
|
| 215 |
+
return CHANNEL_RC_OK;
|
| 216 |
+
error_out:
|
| 217 |
+
audin_opensles_close(device);
|
| 218 |
+
return ERROR_INTERNAL_ERROR;
|
| 219 |
+
}
|
| 220 |
+
|
| 221 |
+
/**
|
| 222 |
+
* Function description
|
| 223 |
+
*
|
| 224 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 225 |
+
*/
|
| 226 |
+
UINT audin_opensles_close(IAudinDevice* device)
|
| 227 |
+
{
|
| 228 |
+
AudinOpenSLESDevice* opensles = (AudinOpenSLESDevice*)device;
|
| 229 |
+
|
| 230 |
+
if (!opensles)
|
| 231 |
+
return ERROR_INVALID_PARAMETER;
|
| 232 |
+
|
| 233 |
+
WLog_Print(opensles->log, WLOG_DEBUG, "device=%p", (void*)device);
|
| 234 |
+
android_CloseRecDevice(opensles->stream);
|
| 235 |
+
opensles->receive = NULL;
|
| 236 |
+
opensles->user_data = NULL;
|
| 237 |
+
opensles->stream = NULL;
|
| 238 |
+
return CHANNEL_RC_OK;
|
| 239 |
+
}
|
| 240 |
+
|
| 241 |
+
/**
|
| 242 |
+
* Function description
|
| 243 |
+
*
|
| 244 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 245 |
+
*/
|
| 246 |
+
static UINT audin_opensles_parse_addin_args(AudinOpenSLESDevice* device, const ADDIN_ARGV* args)
|
| 247 |
+
{
|
| 248 |
+
UINT status;
|
| 249 |
+
DWORD flags;
|
| 250 |
+
const COMMAND_LINE_ARGUMENT_A* arg;
|
| 251 |
+
AudinOpenSLESDevice* opensles = (AudinOpenSLESDevice*)device;
|
| 252 |
+
COMMAND_LINE_ARGUMENT_A audin_opensles_args[] = {
|
| 253 |
+
{ "dev", COMMAND_LINE_VALUE_REQUIRED, "<device>", NULL, NULL, -1, NULL,
|
| 254 |
+
"audio device name" },
|
| 255 |
+
{ NULL, 0, NULL, NULL, NULL, -1, NULL, NULL }
|
| 256 |
+
};
|
| 257 |
+
|
| 258 |
+
WLog_Print(opensles->log, WLOG_DEBUG, "device=%p, args=%p", (void*)device, (void*)args);
|
| 259 |
+
flags =
|
| 260 |
+
COMMAND_LINE_SIGIL_NONE | COMMAND_LINE_SEPARATOR_COLON | COMMAND_LINE_IGN_UNKNOWN_KEYWORD;
|
| 261 |
+
status = CommandLineParseArgumentsA(args->argc, args->argv, audin_opensles_args, flags,
|
| 262 |
+
opensles, NULL, NULL);
|
| 263 |
+
|
| 264 |
+
if (status < 0)
|
| 265 |
+
return status;
|
| 266 |
+
|
| 267 |
+
arg = audin_opensles_args;
|
| 268 |
+
|
| 269 |
+
do
|
| 270 |
+
{
|
| 271 |
+
if (!(arg->Flags & COMMAND_LINE_VALUE_PRESENT))
|
| 272 |
+
continue;
|
| 273 |
+
|
| 274 |
+
CommandLineSwitchStart(arg) CommandLineSwitchCase(arg, "dev")
|
| 275 |
+
{
|
| 276 |
+
opensles->device_name = _strdup(arg->Value);
|
| 277 |
+
|
| 278 |
+
if (!opensles->device_name)
|
| 279 |
+
{
|
| 280 |
+
WLog_Print(opensles->log, WLOG_ERROR, "_strdup failed!");
|
| 281 |
+
return CHANNEL_RC_NO_MEMORY;
|
| 282 |
+
}
|
| 283 |
+
}
|
| 284 |
+
CommandLineSwitchEnd(arg)
|
| 285 |
+
} while ((arg = CommandLineFindNextArgumentA(arg)) != NULL);
|
| 286 |
+
|
| 287 |
+
return CHANNEL_RC_OK;
|
| 288 |
+
}
|
| 289 |
+
|
| 290 |
+
/**
|
| 291 |
+
* Function description
|
| 292 |
+
*
|
| 293 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 294 |
+
*/
|
| 295 |
+
FREERDP_ENTRY_POINT(UINT VCAPITYPE opensles_freerdp_audin_client_subsystem_entry(
|
| 296 |
+
PFREERDP_AUDIN_DEVICE_ENTRY_POINTS pEntryPoints))
|
| 297 |
+
{
|
| 298 |
+
const ADDIN_ARGV* args;
|
| 299 |
+
AudinOpenSLESDevice* opensles;
|
| 300 |
+
UINT error;
|
| 301 |
+
opensles = (AudinOpenSLESDevice*)calloc(1, sizeof(AudinOpenSLESDevice));
|
| 302 |
+
|
| 303 |
+
if (!opensles)
|
| 304 |
+
{
|
| 305 |
+
WLog_ERR(TAG, "calloc failed!");
|
| 306 |
+
return CHANNEL_RC_NO_MEMORY;
|
| 307 |
+
}
|
| 308 |
+
|
| 309 |
+
opensles->log = WLog_Get(TAG);
|
| 310 |
+
opensles->iface.Open = audin_opensles_open;
|
| 311 |
+
opensles->iface.FormatSupported = audin_opensles_format_supported;
|
| 312 |
+
opensles->iface.SetFormat = audin_opensles_set_format;
|
| 313 |
+
opensles->iface.Close = audin_opensles_close;
|
| 314 |
+
opensles->iface.Free = audin_opensles_free;
|
| 315 |
+
opensles->rdpcontext = pEntryPoints->rdpcontext;
|
| 316 |
+
args = pEntryPoints->args;
|
| 317 |
+
|
| 318 |
+
if ((error = audin_opensles_parse_addin_args(opensles, args)))
|
| 319 |
+
{
|
| 320 |
+
WLog_Print(opensles->log, WLOG_ERROR,
|
| 321 |
+
"audin_opensles_parse_addin_args failed with errorcode %" PRIu32 "!", error);
|
| 322 |
+
goto error_out;
|
| 323 |
+
}
|
| 324 |
+
|
| 325 |
+
if ((error = pEntryPoints->pRegisterAudinDevice(pEntryPoints->plugin, (IAudinDevice*)opensles)))
|
| 326 |
+
{
|
| 327 |
+
WLog_Print(opensles->log, WLOG_ERROR, "RegisterAudinDevice failed with error %" PRIu32 "!",
|
| 328 |
+
error);
|
| 329 |
+
goto error_out;
|
| 330 |
+
}
|
| 331 |
+
|
| 332 |
+
return CHANNEL_RC_OK;
|
| 333 |
+
error_out:
|
| 334 |
+
free(opensles);
|
| 335 |
+
return error;
|
| 336 |
+
}
|
local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/opensles/opensl_io.c
ADDED
|
@@ -0,0 +1,388 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
opensl_io.c:
|
| 3 |
+
Android OpenSL input/output module
|
| 4 |
+
Copyright (c) 2012, Victor Lazzarini
|
| 5 |
+
All rights reserved.
|
| 6 |
+
|
| 7 |
+
Redistribution and use in source and binary forms, with or without
|
| 8 |
+
modification, are permitted provided that the following conditions are met:
|
| 9 |
+
* Redistributions of source code must retain the above copyright
|
| 10 |
+
notice, this list of conditions and the following disclaimer.
|
| 11 |
+
* Redistributions in binary form must reproduce the above copyright
|
| 12 |
+
notice, this list of conditions and the following disclaimer in the
|
| 13 |
+
documentation and/or other materials provided with the distribution.
|
| 14 |
+
* Neither the name of the <organization> nor the
|
| 15 |
+
names of its contributors may be used to endorse or promote products
|
| 16 |
+
derived from this software without specific prior written permission.
|
| 17 |
+
|
| 18 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
| 19 |
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
| 20 |
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
| 21 |
+
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
| 22 |
+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
| 23 |
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
| 24 |
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
| 25 |
+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 26 |
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
| 27 |
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 28 |
+
*/
|
| 29 |
+
|
| 30 |
+
#include <winpr/assert.h>
|
| 31 |
+
|
| 32 |
+
#include "audin_main.h"
|
| 33 |
+
#include "opensl_io.h"
|
| 34 |
+
#define CONV16BIT 32768
|
| 35 |
+
#define CONVMYFLT (1. / 32768.)
|
| 36 |
+
|
| 37 |
+
typedef struct
|
| 38 |
+
{
|
| 39 |
+
size_t size;
|
| 40 |
+
void* data;
|
| 41 |
+
} queue_element;
|
| 42 |
+
|
| 43 |
+
struct opensl_stream
|
| 44 |
+
{
|
| 45 |
+
// engine interfaces
|
| 46 |
+
SLObjectItf engineObject;
|
| 47 |
+
SLEngineItf engineEngine;
|
| 48 |
+
|
| 49 |
+
// device interfaces
|
| 50 |
+
SLDeviceVolumeItf deviceVolume;
|
| 51 |
+
|
| 52 |
+
// recorder interfaces
|
| 53 |
+
SLObjectItf recorderObject;
|
| 54 |
+
SLRecordItf recorderRecord;
|
| 55 |
+
SLAndroidSimpleBufferQueueItf recorderBufferQueue;
|
| 56 |
+
|
| 57 |
+
unsigned int inchannels;
|
| 58 |
+
unsigned int sr;
|
| 59 |
+
unsigned int buffersize;
|
| 60 |
+
unsigned int bits_per_sample;
|
| 61 |
+
|
| 62 |
+
queue_element* prep;
|
| 63 |
+
queue_element* next;
|
| 64 |
+
|
| 65 |
+
void* context;
|
| 66 |
+
opensl_receive_t receive;
|
| 67 |
+
};
|
| 68 |
+
|
| 69 |
+
static void bqRecorderCallback(SLAndroidSimpleBufferQueueItf bq, void* context);
|
| 70 |
+
|
| 71 |
+
// creates the OpenSL ES audio engine
|
| 72 |
+
static SLresult openSLCreateEngine(OPENSL_STREAM* p)
|
| 73 |
+
{
|
| 74 |
+
SLresult result;
|
| 75 |
+
// create engine
|
| 76 |
+
result = slCreateEngine(&(p->engineObject), 0, NULL, 0, NULL, NULL);
|
| 77 |
+
|
| 78 |
+
if (result != SL_RESULT_SUCCESS)
|
| 79 |
+
goto engine_end;
|
| 80 |
+
|
| 81 |
+
// realize the engine
|
| 82 |
+
result = (*p->engineObject)->Realize(p->engineObject, SL_BOOLEAN_FALSE);
|
| 83 |
+
|
| 84 |
+
if (result != SL_RESULT_SUCCESS)
|
| 85 |
+
goto engine_end;
|
| 86 |
+
|
| 87 |
+
// get the engine interface, which is needed in order to create other objects
|
| 88 |
+
result = (*p->engineObject)->GetInterface(p->engineObject, SL_IID_ENGINE, &(p->engineEngine));
|
| 89 |
+
|
| 90 |
+
if (result != SL_RESULT_SUCCESS)
|
| 91 |
+
goto engine_end;
|
| 92 |
+
|
| 93 |
+
// get the volume interface - important, this is optional!
|
| 94 |
+
result =
|
| 95 |
+
(*p->engineObject)->GetInterface(p->engineObject, SL_IID_DEVICEVOLUME, &(p->deviceVolume));
|
| 96 |
+
|
| 97 |
+
if (result != SL_RESULT_SUCCESS)
|
| 98 |
+
{
|
| 99 |
+
p->deviceVolume = NULL;
|
| 100 |
+
result = SL_RESULT_SUCCESS;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
engine_end:
|
| 104 |
+
WINPR_ASSERT(SL_RESULT_SUCCESS == result);
|
| 105 |
+
return result;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
// Open the OpenSL ES device for input
|
| 109 |
+
static SLresult openSLRecOpen(OPENSL_STREAM* p)
|
| 110 |
+
{
|
| 111 |
+
SLresult result;
|
| 112 |
+
SLuint32 sr = p->sr;
|
| 113 |
+
SLuint32 channels = p->inchannels;
|
| 114 |
+
WINPR_ASSERT(!p->recorderObject);
|
| 115 |
+
|
| 116 |
+
if (channels)
|
| 117 |
+
{
|
| 118 |
+
switch (sr)
|
| 119 |
+
{
|
| 120 |
+
case 8000:
|
| 121 |
+
sr = SL_SAMPLINGRATE_8;
|
| 122 |
+
break;
|
| 123 |
+
|
| 124 |
+
case 11025:
|
| 125 |
+
sr = SL_SAMPLINGRATE_11_025;
|
| 126 |
+
break;
|
| 127 |
+
|
| 128 |
+
case 16000:
|
| 129 |
+
sr = SL_SAMPLINGRATE_16;
|
| 130 |
+
break;
|
| 131 |
+
|
| 132 |
+
case 22050:
|
| 133 |
+
sr = SL_SAMPLINGRATE_22_05;
|
| 134 |
+
break;
|
| 135 |
+
|
| 136 |
+
case 24000:
|
| 137 |
+
sr = SL_SAMPLINGRATE_24;
|
| 138 |
+
break;
|
| 139 |
+
|
| 140 |
+
case 32000:
|
| 141 |
+
sr = SL_SAMPLINGRATE_32;
|
| 142 |
+
break;
|
| 143 |
+
|
| 144 |
+
case 44100:
|
| 145 |
+
sr = SL_SAMPLINGRATE_44_1;
|
| 146 |
+
break;
|
| 147 |
+
|
| 148 |
+
case 48000:
|
| 149 |
+
sr = SL_SAMPLINGRATE_48;
|
| 150 |
+
break;
|
| 151 |
+
|
| 152 |
+
case 64000:
|
| 153 |
+
sr = SL_SAMPLINGRATE_64;
|
| 154 |
+
break;
|
| 155 |
+
|
| 156 |
+
case 88200:
|
| 157 |
+
sr = SL_SAMPLINGRATE_88_2;
|
| 158 |
+
break;
|
| 159 |
+
|
| 160 |
+
case 96000:
|
| 161 |
+
sr = SL_SAMPLINGRATE_96;
|
| 162 |
+
break;
|
| 163 |
+
|
| 164 |
+
case 192000:
|
| 165 |
+
sr = SL_SAMPLINGRATE_192;
|
| 166 |
+
break;
|
| 167 |
+
|
| 168 |
+
default:
|
| 169 |
+
return -1;
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
// configure audio source
|
| 173 |
+
SLDataLocator_IODevice loc_dev = { SL_DATALOCATOR_IODEVICE, SL_IODEVICE_AUDIOINPUT,
|
| 174 |
+
SL_DEFAULTDEVICEID_AUDIOINPUT, NULL };
|
| 175 |
+
SLDataSource audioSrc = { &loc_dev, NULL };
|
| 176 |
+
// configure audio sink
|
| 177 |
+
int speakers;
|
| 178 |
+
|
| 179 |
+
if (channels > 1)
|
| 180 |
+
speakers = SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT;
|
| 181 |
+
else
|
| 182 |
+
speakers = SL_SPEAKER_FRONT_CENTER;
|
| 183 |
+
|
| 184 |
+
SLDataLocator_AndroidSimpleBufferQueue loc_bq = { SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE,
|
| 185 |
+
2 };
|
| 186 |
+
SLDataFormat_PCM format_pcm;
|
| 187 |
+
format_pcm.formatType = SL_DATAFORMAT_PCM;
|
| 188 |
+
format_pcm.numChannels = channels;
|
| 189 |
+
format_pcm.samplesPerSec = sr;
|
| 190 |
+
format_pcm.channelMask = speakers;
|
| 191 |
+
format_pcm.endianness = SL_BYTEORDER_LITTLEENDIAN;
|
| 192 |
+
|
| 193 |
+
if (16 == p->bits_per_sample)
|
| 194 |
+
{
|
| 195 |
+
format_pcm.bitsPerSample = SL_PCMSAMPLEFORMAT_FIXED_16;
|
| 196 |
+
format_pcm.containerSize = 16;
|
| 197 |
+
}
|
| 198 |
+
else if (8 == p->bits_per_sample)
|
| 199 |
+
{
|
| 200 |
+
format_pcm.bitsPerSample = SL_PCMSAMPLEFORMAT_FIXED_8;
|
| 201 |
+
format_pcm.containerSize = 8;
|
| 202 |
+
}
|
| 203 |
+
else
|
| 204 |
+
WINPR_ASSERT(0);
|
| 205 |
+
|
| 206 |
+
SLDataSink audioSnk = { &loc_bq, &format_pcm };
|
| 207 |
+
// create audio recorder
|
| 208 |
+
// (requires the RECORD_AUDIO permission)
|
| 209 |
+
const SLInterfaceID id[] = { SL_IID_ANDROIDSIMPLEBUFFERQUEUE };
|
| 210 |
+
const SLboolean req[] = { SL_BOOLEAN_TRUE };
|
| 211 |
+
result = (*p->engineEngine)
|
| 212 |
+
->CreateAudioRecorder(p->engineEngine, &(p->recorderObject), &audioSrc,
|
| 213 |
+
&audioSnk, 1, id, req);
|
| 214 |
+
WINPR_ASSERT(!result);
|
| 215 |
+
|
| 216 |
+
if (SL_RESULT_SUCCESS != result)
|
| 217 |
+
goto end_recopen;
|
| 218 |
+
|
| 219 |
+
// realize the audio recorder
|
| 220 |
+
result = (*p->recorderObject)->Realize(p->recorderObject, SL_BOOLEAN_FALSE);
|
| 221 |
+
WINPR_ASSERT(!result);
|
| 222 |
+
|
| 223 |
+
if (SL_RESULT_SUCCESS != result)
|
| 224 |
+
goto end_recopen;
|
| 225 |
+
|
| 226 |
+
// get the record interface
|
| 227 |
+
result = (*p->recorderObject)
|
| 228 |
+
->GetInterface(p->recorderObject, SL_IID_RECORD, &(p->recorderRecord));
|
| 229 |
+
WINPR_ASSERT(!result);
|
| 230 |
+
|
| 231 |
+
if (SL_RESULT_SUCCESS != result)
|
| 232 |
+
goto end_recopen;
|
| 233 |
+
|
| 234 |
+
// get the buffer queue interface
|
| 235 |
+
result = (*p->recorderObject)
|
| 236 |
+
->GetInterface(p->recorderObject, SL_IID_ANDROIDSIMPLEBUFFERQUEUE,
|
| 237 |
+
&(p->recorderBufferQueue));
|
| 238 |
+
WINPR_ASSERT(!result);
|
| 239 |
+
|
| 240 |
+
if (SL_RESULT_SUCCESS != result)
|
| 241 |
+
goto end_recopen;
|
| 242 |
+
|
| 243 |
+
// register callback on the buffer queue
|
| 244 |
+
result = (*p->recorderBufferQueue)
|
| 245 |
+
->RegisterCallback(p->recorderBufferQueue, bqRecorderCallback, p);
|
| 246 |
+
WINPR_ASSERT(!result);
|
| 247 |
+
|
| 248 |
+
if (SL_RESULT_SUCCESS != result)
|
| 249 |
+
goto end_recopen;
|
| 250 |
+
|
| 251 |
+
end_recopen:
|
| 252 |
+
return result;
|
| 253 |
+
}
|
| 254 |
+
else
|
| 255 |
+
return SL_RESULT_SUCCESS;
|
| 256 |
+
}
|
| 257 |
+
|
| 258 |
+
// close the OpenSL IO and destroy the audio engine
|
| 259 |
+
static void openSLDestroyEngine(OPENSL_STREAM* p)
|
| 260 |
+
{
|
| 261 |
+
// destroy audio recorder object, and invalidate all associated interfaces
|
| 262 |
+
if (p->recorderObject != NULL)
|
| 263 |
+
{
|
| 264 |
+
(*p->recorderObject)->Destroy(p->recorderObject);
|
| 265 |
+
p->recorderObject = NULL;
|
| 266 |
+
p->recorderRecord = NULL;
|
| 267 |
+
p->recorderBufferQueue = NULL;
|
| 268 |
+
}
|
| 269 |
+
|
| 270 |
+
// destroy engine object, and invalidate all associated interfaces
|
| 271 |
+
if (p->engineObject != NULL)
|
| 272 |
+
{
|
| 273 |
+
(*p->engineObject)->Destroy(p->engineObject);
|
| 274 |
+
p->engineObject = NULL;
|
| 275 |
+
p->engineEngine = NULL;
|
| 276 |
+
}
|
| 277 |
+
}
|
| 278 |
+
|
| 279 |
+
static queue_element* opensles_queue_element_new(size_t size)
|
| 280 |
+
{
|
| 281 |
+
queue_element* q = calloc(1, sizeof(queue_element));
|
| 282 |
+
|
| 283 |
+
if (!q)
|
| 284 |
+
goto fail;
|
| 285 |
+
|
| 286 |
+
q->size = size;
|
| 287 |
+
q->data = malloc(size);
|
| 288 |
+
|
| 289 |
+
if (!q->data)
|
| 290 |
+
goto fail;
|
| 291 |
+
|
| 292 |
+
return q;
|
| 293 |
+
fail:
|
| 294 |
+
free(q);
|
| 295 |
+
return NULL;
|
| 296 |
+
}
|
| 297 |
+
|
| 298 |
+
static void opensles_queue_element_free(void* obj)
|
| 299 |
+
{
|
| 300 |
+
queue_element* e = (queue_element*)obj;
|
| 301 |
+
|
| 302 |
+
if (e)
|
| 303 |
+
free(e->data);
|
| 304 |
+
|
| 305 |
+
free(e);
|
| 306 |
+
}
|
| 307 |
+
|
| 308 |
+
// open the android audio device for input
|
| 309 |
+
OPENSL_STREAM* android_OpenRecDevice(void* context, opensl_receive_t receive, int sr,
|
| 310 |
+
int inchannels, int bufferframes, int bits_per_sample)
|
| 311 |
+
{
|
| 312 |
+
OPENSL_STREAM* p;
|
| 313 |
+
|
| 314 |
+
if (!context || !receive)
|
| 315 |
+
return NULL;
|
| 316 |
+
|
| 317 |
+
p = (OPENSL_STREAM*)calloc(1, sizeof(OPENSL_STREAM));
|
| 318 |
+
|
| 319 |
+
if (!p)
|
| 320 |
+
return NULL;
|
| 321 |
+
|
| 322 |
+
p->context = context;
|
| 323 |
+
p->receive = receive;
|
| 324 |
+
p->inchannels = inchannels;
|
| 325 |
+
p->sr = sr;
|
| 326 |
+
p->buffersize = bufferframes;
|
| 327 |
+
p->bits_per_sample = bits_per_sample;
|
| 328 |
+
|
| 329 |
+
if ((p->bits_per_sample != 8) && (p->bits_per_sample != 16))
|
| 330 |
+
goto fail;
|
| 331 |
+
|
| 332 |
+
if (openSLCreateEngine(p) != SL_RESULT_SUCCESS)
|
| 333 |
+
goto fail;
|
| 334 |
+
|
| 335 |
+
if (openSLRecOpen(p) != SL_RESULT_SUCCESS)
|
| 336 |
+
goto fail;
|
| 337 |
+
|
| 338 |
+
/* Create receive buffers, prepare them and start recording */
|
| 339 |
+
p->prep = opensles_queue_element_new(p->buffersize * p->bits_per_sample / 8);
|
| 340 |
+
p->next = opensles_queue_element_new(p->buffersize * p->bits_per_sample / 8);
|
| 341 |
+
|
| 342 |
+
if (!p->prep || !p->next)
|
| 343 |
+
goto fail;
|
| 344 |
+
|
| 345 |
+
(*p->recorderBufferQueue)->Enqueue(p->recorderBufferQueue, p->next->data, p->next->size);
|
| 346 |
+
(*p->recorderBufferQueue)->Enqueue(p->recorderBufferQueue, p->prep->data, p->prep->size);
|
| 347 |
+
(*p->recorderRecord)->SetRecordState(p->recorderRecord, SL_RECORDSTATE_RECORDING);
|
| 348 |
+
return p;
|
| 349 |
+
fail:
|
| 350 |
+
android_CloseRecDevice(p);
|
| 351 |
+
return NULL;
|
| 352 |
+
}
|
| 353 |
+
|
| 354 |
+
// close the android audio device
|
| 355 |
+
void android_CloseRecDevice(OPENSL_STREAM* p)
|
| 356 |
+
{
|
| 357 |
+
if (p == NULL)
|
| 358 |
+
return;
|
| 359 |
+
|
| 360 |
+
opensles_queue_element_free(p->next);
|
| 361 |
+
opensles_queue_element_free(p->prep);
|
| 362 |
+
openSLDestroyEngine(p);
|
| 363 |
+
free(p);
|
| 364 |
+
}
|
| 365 |
+
|
| 366 |
+
// this callback handler is called every time a buffer finishes recording
|
| 367 |
+
static void bqRecorderCallback(SLAndroidSimpleBufferQueueItf bq, void* context)
|
| 368 |
+
{
|
| 369 |
+
OPENSL_STREAM* p = (OPENSL_STREAM*)context;
|
| 370 |
+
queue_element* e;
|
| 371 |
+
|
| 372 |
+
if (!p)
|
| 373 |
+
return;
|
| 374 |
+
|
| 375 |
+
e = p->next;
|
| 376 |
+
|
| 377 |
+
if (!e)
|
| 378 |
+
return;
|
| 379 |
+
|
| 380 |
+
if (!p->context || !p->receive)
|
| 381 |
+
WLog_WARN(TAG, "Missing receive callback=%p, context=%p", p->receive, p->context);
|
| 382 |
+
else
|
| 383 |
+
p->receive(p->context, e->data, e->size);
|
| 384 |
+
|
| 385 |
+
p->next = p->prep;
|
| 386 |
+
p->prep = e;
|
| 387 |
+
(*p->recorderBufferQueue)->Enqueue(p->recorderBufferQueue, e->data, e->size);
|
| 388 |
+
}
|
local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/opensles/opensl_io.h
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
opensl_io.c:
|
| 3 |
+
Android OpenSL input/output module header
|
| 4 |
+
Copyright (c) 2012, Victor Lazzarini
|
| 5 |
+
All rights reserved.
|
| 6 |
+
|
| 7 |
+
Redistribution and use in source and binary forms, with or without
|
| 8 |
+
modification, are permitted provided that the following conditions are met:
|
| 9 |
+
* Redistributions of source code must retain the above copyright
|
| 10 |
+
notice, this list of conditions and the following disclaimer.
|
| 11 |
+
* Redistributions in binary form must reproduce the above copyright
|
| 12 |
+
notice, this list of conditions and the following disclaimer in the
|
| 13 |
+
documentation and/or other materials provided with the distribution.
|
| 14 |
+
* Neither the name of the <organization> nor the
|
| 15 |
+
names of its contributors may be used to endorse or promote products
|
| 16 |
+
derived from this software without specific prior written permission.
|
| 17 |
+
|
| 18 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
| 19 |
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
| 20 |
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
| 21 |
+
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
| 22 |
+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
| 23 |
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
| 24 |
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
| 25 |
+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 26 |
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
| 27 |
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 28 |
+
*/
|
| 29 |
+
|
| 30 |
+
#ifndef FREERDP_CHANNEL_AUDIN_CLIENT_OPENSL_IO_H
|
| 31 |
+
#define FREERDP_CHANNEL_AUDIN_CLIENT_OPENSL_IO_H
|
| 32 |
+
|
| 33 |
+
#include <SLES/OpenSLES.h>
|
| 34 |
+
#include <SLES/OpenSLES_Android.h>
|
| 35 |
+
|
| 36 |
+
#include <freerdp/api.h>
|
| 37 |
+
|
| 38 |
+
#include <stdlib.h>
|
| 39 |
+
|
| 40 |
+
#ifdef __cplusplus
|
| 41 |
+
extern "C"
|
| 42 |
+
{
|
| 43 |
+
#endif
|
| 44 |
+
|
| 45 |
+
typedef struct opensl_stream OPENSL_STREAM;
|
| 46 |
+
|
| 47 |
+
typedef void (*opensl_receive_t)(void* context, const void* data, size_t size);
|
| 48 |
+
|
| 49 |
+
/*
|
| 50 |
+
Open the audio device with a given sampling rate (sr), input and output channels and IO buffer
|
| 51 |
+
size in frames. Returns a handle to the OpenSL stream
|
| 52 |
+
*/
|
| 53 |
+
FREERDP_LOCAL OPENSL_STREAM* android_OpenRecDevice(void* context, opensl_receive_t receive,
|
| 54 |
+
int sr, int inchannels, int bufferframes,
|
| 55 |
+
int bits_per_sample);
|
| 56 |
+
/*
|
| 57 |
+
Close the audio device
|
| 58 |
+
*/
|
| 59 |
+
FREERDP_LOCAL void android_CloseRecDevice(OPENSL_STREAM* p);
|
| 60 |
+
|
| 61 |
+
#ifdef __cplusplus
|
| 62 |
+
};
|
| 63 |
+
#endif
|
| 64 |
+
|
| 65 |
+
#endif /* FREERDP_CHANNEL_AUDIN_CLIENT_OPENSL_IO_H */
|
local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/oss/CMakeLists.txt
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# FreeRDP: A Remote Desktop Protocol Implementation
|
| 2 |
+
# FreeRDP cmake build script
|
| 3 |
+
#
|
| 4 |
+
# Copyright (c) 2015 Rozhuk Ivan <rozhuk.im@gmail.com>
|
| 5 |
+
#
|
| 6 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 7 |
+
# you may not use this file except in compliance with the License.
|
| 8 |
+
# You may obtain a copy of the License at
|
| 9 |
+
#
|
| 10 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 11 |
+
#
|
| 12 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 13 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 14 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 15 |
+
# See the License for the specific language governing permissions and
|
| 16 |
+
# limitations under the License.
|
| 17 |
+
|
| 18 |
+
define_channel_client_subsystem("audin" "oss" "")
|
| 19 |
+
|
| 20 |
+
find_package(OSS REQUIRED)
|
| 21 |
+
|
| 22 |
+
set(${MODULE_PREFIX}_SRCS audin_oss.c)
|
| 23 |
+
|
| 24 |
+
set(${MODULE_PREFIX}_LIBS winpr freerdp ${OSS_LIBRARIES})
|
| 25 |
+
|
| 26 |
+
include_directories(..)
|
| 27 |
+
include_directories(${CMAKE_CURRENT_BINARY_DIR})
|
| 28 |
+
include_directories(SYSTEM ${OSS_INCLUDE_DIRS})
|
| 29 |
+
cleaning_configure_file(${CMAKE_SOURCE_DIR}/cmake/oss-includes.h.in ${CMAKE_CURRENT_BINARY_DIR}/oss-includes.h @ONLY)
|
| 30 |
+
|
| 31 |
+
add_channel_client_subsystem_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} "" TRUE "")
|
local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/oss/audin_oss.c
ADDED
|
@@ -0,0 +1,486 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* FreeRDP: A Remote Desktop Protocol Implementation
|
| 3 |
+
* Audio Input Redirection Virtual Channel - OSS implementation
|
| 4 |
+
*
|
| 5 |
+
* Copyright (c) 2015 Rozhuk Ivan <rozhuk.im@gmail.com>
|
| 6 |
+
* Copyright 2015 Thincast Technologies GmbH
|
| 7 |
+
* Copyright 2015 DI (FH) Martin Haimberger <martin.haimberger@thincast.com>
|
| 8 |
+
*
|
| 9 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 10 |
+
* you may not use this file except in compliance with the License.
|
| 11 |
+
* You may obtain a copy of the License at
|
| 12 |
+
*
|
| 13 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 14 |
+
*
|
| 15 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 16 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 17 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 18 |
+
* See the License for the specific language governing permissions and
|
| 19 |
+
* limitations under the License.
|
| 20 |
+
*/
|
| 21 |
+
|
| 22 |
+
#include <freerdp/config.h>
|
| 23 |
+
|
| 24 |
+
#include <stdio.h>
|
| 25 |
+
#include <stdlib.h>
|
| 26 |
+
#include <string.h>
|
| 27 |
+
|
| 28 |
+
#include <winpr/crt.h>
|
| 29 |
+
#include <winpr/synch.h>
|
| 30 |
+
#include <winpr/string.h>
|
| 31 |
+
#include <winpr/thread.h>
|
| 32 |
+
#include <winpr/cmdline.h>
|
| 33 |
+
|
| 34 |
+
#include <err.h>
|
| 35 |
+
#include <errno.h>
|
| 36 |
+
#include <fcntl.h>
|
| 37 |
+
#include <libgen.h>
|
| 38 |
+
#include <limits.h>
|
| 39 |
+
#include <unistd.h>
|
| 40 |
+
#include <oss-includes.h>
|
| 41 |
+
#include <sys/ioctl.h>
|
| 42 |
+
|
| 43 |
+
#include <freerdp/freerdp.h>
|
| 44 |
+
#include <freerdp/addin.h>
|
| 45 |
+
#include <freerdp/channels/rdpsnd.h>
|
| 46 |
+
|
| 47 |
+
#include "audin_main.h"
|
| 48 |
+
|
| 49 |
+
typedef struct
|
| 50 |
+
{
|
| 51 |
+
IAudinDevice iface;
|
| 52 |
+
|
| 53 |
+
HANDLE thread;
|
| 54 |
+
HANDLE stopEvent;
|
| 55 |
+
|
| 56 |
+
AUDIO_FORMAT format;
|
| 57 |
+
UINT32 FramesPerPacket;
|
| 58 |
+
int dev_unit;
|
| 59 |
+
|
| 60 |
+
AudinReceive receive;
|
| 61 |
+
void* user_data;
|
| 62 |
+
|
| 63 |
+
rdpContext* rdpcontext;
|
| 64 |
+
} AudinOSSDevice;
|
| 65 |
+
|
| 66 |
+
static void OSS_LOG_ERR(const char* _text, int _error)
|
| 67 |
+
{
|
| 68 |
+
if ((_error) != 0)
|
| 69 |
+
{
|
| 70 |
+
char buffer[256] = { 0 };
|
| 71 |
+
WLog_ERR(TAG, "%s: %i - %s\n", (_text), (_error),
|
| 72 |
+
winpr_strerror((_error), buffer, sizeof(buffer)));
|
| 73 |
+
}
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
static UINT32 audin_oss_get_format(const AUDIO_FORMAT* format)
|
| 77 |
+
{
|
| 78 |
+
switch (format->wFormatTag)
|
| 79 |
+
{
|
| 80 |
+
case WAVE_FORMAT_PCM:
|
| 81 |
+
switch (format->wBitsPerSample)
|
| 82 |
+
{
|
| 83 |
+
case 8:
|
| 84 |
+
return AFMT_S8;
|
| 85 |
+
|
| 86 |
+
case 16:
|
| 87 |
+
return AFMT_S16_LE;
|
| 88 |
+
|
| 89 |
+
default:
|
| 90 |
+
break;
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
break;
|
| 94 |
+
default:
|
| 95 |
+
break;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
return 0;
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
static BOOL audin_oss_format_supported(IAudinDevice* device, const AUDIO_FORMAT* format)
|
| 102 |
+
{
|
| 103 |
+
if (device == NULL || format == NULL)
|
| 104 |
+
return FALSE;
|
| 105 |
+
|
| 106 |
+
switch (format->wFormatTag)
|
| 107 |
+
{
|
| 108 |
+
case WAVE_FORMAT_PCM:
|
| 109 |
+
if (format->cbSize != 0 || format->nSamplesPerSec > 48000 ||
|
| 110 |
+
(format->wBitsPerSample != 8 && format->wBitsPerSample != 16) ||
|
| 111 |
+
(format->nChannels != 1 && format->nChannels != 2))
|
| 112 |
+
return FALSE;
|
| 113 |
+
|
| 114 |
+
break;
|
| 115 |
+
|
| 116 |
+
default:
|
| 117 |
+
return FALSE;
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
return TRUE;
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
/**
|
| 124 |
+
* Function description
|
| 125 |
+
*
|
| 126 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 127 |
+
*/
|
| 128 |
+
static UINT audin_oss_set_format(IAudinDevice* device, const AUDIO_FORMAT* format,
|
| 129 |
+
UINT32 FramesPerPacket)
|
| 130 |
+
{
|
| 131 |
+
AudinOSSDevice* oss = (AudinOSSDevice*)device;
|
| 132 |
+
|
| 133 |
+
if (device == NULL || format == NULL)
|
| 134 |
+
return ERROR_INVALID_PARAMETER;
|
| 135 |
+
|
| 136 |
+
oss->FramesPerPacket = FramesPerPacket;
|
| 137 |
+
oss->format = *format;
|
| 138 |
+
return CHANNEL_RC_OK;
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
static DWORD WINAPI audin_oss_thread_func(LPVOID arg)
|
| 142 |
+
{
|
| 143 |
+
char dev_name[PATH_MAX] = "/dev/dsp";
|
| 144 |
+
char mixer_name[PATH_MAX] = "/dev/mixer";
|
| 145 |
+
int pcm_handle = -1;
|
| 146 |
+
int mixer_handle = 0;
|
| 147 |
+
BYTE* buffer = NULL;
|
| 148 |
+
unsigned long tmp = 0;
|
| 149 |
+
size_t buffer_size = 0;
|
| 150 |
+
AudinOSSDevice* oss = (AudinOSSDevice*)arg;
|
| 151 |
+
UINT error = 0;
|
| 152 |
+
DWORD status = 0;
|
| 153 |
+
|
| 154 |
+
if (oss == NULL)
|
| 155 |
+
{
|
| 156 |
+
error = ERROR_INVALID_PARAMETER;
|
| 157 |
+
goto err_out;
|
| 158 |
+
}
|
| 159 |
+
|
| 160 |
+
if (oss->dev_unit != -1)
|
| 161 |
+
{
|
| 162 |
+
(void)sprintf_s(dev_name, (PATH_MAX - 1), "/dev/dsp%i", oss->dev_unit);
|
| 163 |
+
(void)sprintf_s(mixer_name, PATH_MAX - 1, "/dev/mixer%i", oss->dev_unit);
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
WLog_INFO(TAG, "open: %s", dev_name);
|
| 167 |
+
|
| 168 |
+
if ((pcm_handle = open(dev_name, O_RDONLY)) < 0)
|
| 169 |
+
{
|
| 170 |
+
OSS_LOG_ERR("sound dev open failed", errno);
|
| 171 |
+
error = ERROR_INTERNAL_ERROR;
|
| 172 |
+
goto err_out;
|
| 173 |
+
}
|
| 174 |
+
|
| 175 |
+
/* Set rec volume to 100%. */
|
| 176 |
+
if ((mixer_handle = open(mixer_name, O_RDWR)) < 0)
|
| 177 |
+
{
|
| 178 |
+
OSS_LOG_ERR("mixer open failed, not critical", errno);
|
| 179 |
+
}
|
| 180 |
+
else
|
| 181 |
+
{
|
| 182 |
+
tmp = (100 | (100 << 8));
|
| 183 |
+
|
| 184 |
+
if (ioctl(mixer_handle, MIXER_WRITE(SOUND_MIXER_MIC), &tmp) == -1)
|
| 185 |
+
OSS_LOG_ERR("WRITE_MIXER - SOUND_MIXER_MIC, not critical", errno);
|
| 186 |
+
|
| 187 |
+
tmp = (100 | (100 << 8));
|
| 188 |
+
|
| 189 |
+
if (ioctl(mixer_handle, MIXER_WRITE(SOUND_MIXER_RECLEV), &tmp) == -1)
|
| 190 |
+
OSS_LOG_ERR("WRITE_MIXER - SOUND_MIXER_RECLEV, not critical", errno);
|
| 191 |
+
|
| 192 |
+
close(mixer_handle);
|
| 193 |
+
}
|
| 194 |
+
|
| 195 |
+
#if 0 /* FreeBSD OSS implementation at this moment (2015.03) does not set PCM_CAP_INPUT flag. */
|
| 196 |
+
tmp = 0;
|
| 197 |
+
|
| 198 |
+
if (ioctl(pcm_handle, SNDCTL_DSP_GETCAPS, &tmp) == -1)
|
| 199 |
+
{
|
| 200 |
+
OSS_LOG_ERR("SNDCTL_DSP_GETCAPS failed, try ignored", errno);
|
| 201 |
+
}
|
| 202 |
+
else if ((tmp & PCM_CAP_INPUT) == 0)
|
| 203 |
+
{
|
| 204 |
+
OSS_LOG_ERR("Device does not supports playback", EOPNOTSUPP);
|
| 205 |
+
goto err_out;
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
#endif
|
| 209 |
+
/* Set format. */
|
| 210 |
+
tmp = audin_oss_get_format(&oss->format);
|
| 211 |
+
|
| 212 |
+
if (ioctl(pcm_handle, SNDCTL_DSP_SETFMT, &tmp) == -1)
|
| 213 |
+
OSS_LOG_ERR("SNDCTL_DSP_SETFMT failed", errno);
|
| 214 |
+
|
| 215 |
+
tmp = oss->format.nChannels;
|
| 216 |
+
|
| 217 |
+
if (ioctl(pcm_handle, SNDCTL_DSP_CHANNELS, &tmp) == -1)
|
| 218 |
+
OSS_LOG_ERR("SNDCTL_DSP_CHANNELS failed", errno);
|
| 219 |
+
|
| 220 |
+
tmp = oss->format.nSamplesPerSec;
|
| 221 |
+
|
| 222 |
+
if (ioctl(pcm_handle, SNDCTL_DSP_SPEED, &tmp) == -1)
|
| 223 |
+
OSS_LOG_ERR("SNDCTL_DSP_SPEED failed", errno);
|
| 224 |
+
|
| 225 |
+
tmp = oss->format.nBlockAlign;
|
| 226 |
+
|
| 227 |
+
if (ioctl(pcm_handle, SNDCTL_DSP_SETFRAGMENT, &tmp) == -1)
|
| 228 |
+
OSS_LOG_ERR("SNDCTL_DSP_SETFRAGMENT failed", errno);
|
| 229 |
+
|
| 230 |
+
buffer_size =
|
| 231 |
+
(1ull * oss->FramesPerPacket * oss->format.nChannels * (oss->format.wBitsPerSample / 8ull));
|
| 232 |
+
buffer = (BYTE*)calloc((buffer_size + sizeof(void*)), sizeof(BYTE));
|
| 233 |
+
|
| 234 |
+
if (NULL == buffer)
|
| 235 |
+
{
|
| 236 |
+
OSS_LOG_ERR("malloc() fail", errno);
|
| 237 |
+
error = ERROR_NOT_ENOUGH_MEMORY;
|
| 238 |
+
goto err_out;
|
| 239 |
+
}
|
| 240 |
+
|
| 241 |
+
while (1)
|
| 242 |
+
{
|
| 243 |
+
SSIZE_T stmp = -1;
|
| 244 |
+
status = WaitForSingleObject(oss->stopEvent, 0);
|
| 245 |
+
|
| 246 |
+
if (status == WAIT_FAILED)
|
| 247 |
+
{
|
| 248 |
+
error = GetLastError();
|
| 249 |
+
WLog_ERR(TAG, "WaitForSingleObject failed with error %" PRIu32 "", error);
|
| 250 |
+
goto err_out;
|
| 251 |
+
}
|
| 252 |
+
|
| 253 |
+
if (status == WAIT_OBJECT_0)
|
| 254 |
+
break;
|
| 255 |
+
|
| 256 |
+
stmp = read(pcm_handle, buffer, buffer_size);
|
| 257 |
+
|
| 258 |
+
/* Error happen. */
|
| 259 |
+
if (stmp < 0)
|
| 260 |
+
{
|
| 261 |
+
OSS_LOG_ERR("read() error", errno);
|
| 262 |
+
continue;
|
| 263 |
+
}
|
| 264 |
+
|
| 265 |
+
if ((size_t)stmp < buffer_size) /* Not enough data. */
|
| 266 |
+
continue;
|
| 267 |
+
|
| 268 |
+
if ((error = oss->receive(&oss->format, buffer, buffer_size, oss->user_data)))
|
| 269 |
+
{
|
| 270 |
+
WLog_ERR(TAG, "oss->receive failed with error %" PRIu32 "", error);
|
| 271 |
+
break;
|
| 272 |
+
}
|
| 273 |
+
}
|
| 274 |
+
|
| 275 |
+
err_out:
|
| 276 |
+
|
| 277 |
+
if (error && oss && oss->rdpcontext)
|
| 278 |
+
setChannelError(oss->rdpcontext, error, "audin_oss_thread_func reported an error");
|
| 279 |
+
|
| 280 |
+
if (pcm_handle != -1)
|
| 281 |
+
{
|
| 282 |
+
WLog_INFO(TAG, "close: %s", dev_name);
|
| 283 |
+
close(pcm_handle);
|
| 284 |
+
}
|
| 285 |
+
|
| 286 |
+
free(buffer);
|
| 287 |
+
ExitThread(error);
|
| 288 |
+
return error;
|
| 289 |
+
}
|
| 290 |
+
|
| 291 |
+
/**
|
| 292 |
+
* Function description
|
| 293 |
+
*
|
| 294 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 295 |
+
*/
|
| 296 |
+
static UINT audin_oss_open(IAudinDevice* device, AudinReceive receive, void* user_data)
|
| 297 |
+
{
|
| 298 |
+
AudinOSSDevice* oss = (AudinOSSDevice*)device;
|
| 299 |
+
oss->receive = receive;
|
| 300 |
+
oss->user_data = user_data;
|
| 301 |
+
|
| 302 |
+
if (!(oss->stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL)))
|
| 303 |
+
{
|
| 304 |
+
WLog_ERR(TAG, "CreateEvent failed!");
|
| 305 |
+
return ERROR_INTERNAL_ERROR;
|
| 306 |
+
}
|
| 307 |
+
|
| 308 |
+
if (!(oss->thread = CreateThread(NULL, 0, audin_oss_thread_func, oss, 0, NULL)))
|
| 309 |
+
{
|
| 310 |
+
WLog_ERR(TAG, "CreateThread failed!");
|
| 311 |
+
(void)CloseHandle(oss->stopEvent);
|
| 312 |
+
oss->stopEvent = NULL;
|
| 313 |
+
return ERROR_INTERNAL_ERROR;
|
| 314 |
+
}
|
| 315 |
+
|
| 316 |
+
return CHANNEL_RC_OK;
|
| 317 |
+
}
|
| 318 |
+
|
| 319 |
+
/**
|
| 320 |
+
* Function description
|
| 321 |
+
*
|
| 322 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 323 |
+
*/
|
| 324 |
+
static UINT audin_oss_close(IAudinDevice* device)
|
| 325 |
+
{
|
| 326 |
+
UINT error = 0;
|
| 327 |
+
AudinOSSDevice* oss = (AudinOSSDevice*)device;
|
| 328 |
+
|
| 329 |
+
if (device == NULL)
|
| 330 |
+
return ERROR_INVALID_PARAMETER;
|
| 331 |
+
|
| 332 |
+
if (oss->stopEvent != NULL)
|
| 333 |
+
{
|
| 334 |
+
(void)SetEvent(oss->stopEvent);
|
| 335 |
+
|
| 336 |
+
if (WaitForSingleObject(oss->thread, INFINITE) == WAIT_FAILED)
|
| 337 |
+
{
|
| 338 |
+
error = GetLastError();
|
| 339 |
+
WLog_ERR(TAG, "WaitForSingleObject failed with error %" PRIu32 "", error);
|
| 340 |
+
return error;
|
| 341 |
+
}
|
| 342 |
+
|
| 343 |
+
(void)CloseHandle(oss->stopEvent);
|
| 344 |
+
oss->stopEvent = NULL;
|
| 345 |
+
(void)CloseHandle(oss->thread);
|
| 346 |
+
oss->thread = NULL;
|
| 347 |
+
}
|
| 348 |
+
|
| 349 |
+
oss->receive = NULL;
|
| 350 |
+
oss->user_data = NULL;
|
| 351 |
+
return CHANNEL_RC_OK;
|
| 352 |
+
}
|
| 353 |
+
|
| 354 |
+
/**
|
| 355 |
+
* Function description
|
| 356 |
+
*
|
| 357 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 358 |
+
*/
|
| 359 |
+
static UINT audin_oss_free(IAudinDevice* device)
|
| 360 |
+
{
|
| 361 |
+
AudinOSSDevice* oss = (AudinOSSDevice*)device;
|
| 362 |
+
UINT error = 0;
|
| 363 |
+
|
| 364 |
+
if (device == NULL)
|
| 365 |
+
return ERROR_INVALID_PARAMETER;
|
| 366 |
+
|
| 367 |
+
if ((error = audin_oss_close(device)))
|
| 368 |
+
{
|
| 369 |
+
WLog_ERR(TAG, "audin_oss_close failed with error code %" PRIu32 "!", error);
|
| 370 |
+
}
|
| 371 |
+
|
| 372 |
+
free(oss);
|
| 373 |
+
return CHANNEL_RC_OK;
|
| 374 |
+
}
|
| 375 |
+
|
| 376 |
+
/**
|
| 377 |
+
* Function description
|
| 378 |
+
*
|
| 379 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 380 |
+
*/
|
| 381 |
+
static UINT audin_oss_parse_addin_args(AudinOSSDevice* device, const ADDIN_ARGV* args)
|
| 382 |
+
{
|
| 383 |
+
int status = 0;
|
| 384 |
+
char* str_num = NULL;
|
| 385 |
+
char* eptr = NULL;
|
| 386 |
+
DWORD flags = 0;
|
| 387 |
+
const COMMAND_LINE_ARGUMENT_A* arg = NULL;
|
| 388 |
+
AudinOSSDevice* oss = device;
|
| 389 |
+
COMMAND_LINE_ARGUMENT_A audin_oss_args[] = { { "dev", COMMAND_LINE_VALUE_REQUIRED, "<device>",
|
| 390 |
+
NULL, NULL, -1, NULL, "audio device name" },
|
| 391 |
+
{ NULL, 0, NULL, NULL, NULL, -1, NULL, NULL } };
|
| 392 |
+
|
| 393 |
+
flags =
|
| 394 |
+
COMMAND_LINE_SIGIL_NONE | COMMAND_LINE_SEPARATOR_COLON | COMMAND_LINE_IGN_UNKNOWN_KEYWORD;
|
| 395 |
+
status =
|
| 396 |
+
CommandLineParseArgumentsA(args->argc, args->argv, audin_oss_args, flags, oss, NULL, NULL);
|
| 397 |
+
|
| 398 |
+
if (status < 0)
|
| 399 |
+
return ERROR_INVALID_PARAMETER;
|
| 400 |
+
|
| 401 |
+
arg = audin_oss_args;
|
| 402 |
+
errno = 0;
|
| 403 |
+
|
| 404 |
+
do
|
| 405 |
+
{
|
| 406 |
+
if (!(arg->Flags & COMMAND_LINE_VALUE_PRESENT))
|
| 407 |
+
continue;
|
| 408 |
+
|
| 409 |
+
CommandLineSwitchStart(arg) CommandLineSwitchCase(arg, "dev")
|
| 410 |
+
{
|
| 411 |
+
str_num = _strdup(arg->Value);
|
| 412 |
+
|
| 413 |
+
if (!str_num)
|
| 414 |
+
{
|
| 415 |
+
WLog_ERR(TAG, "_strdup failed!");
|
| 416 |
+
return CHANNEL_RC_NO_MEMORY;
|
| 417 |
+
}
|
| 418 |
+
|
| 419 |
+
{
|
| 420 |
+
long val = strtol(str_num, &eptr, 10);
|
| 421 |
+
|
| 422 |
+
if ((errno != 0) || (val < INT32_MIN) || (val > INT32_MAX))
|
| 423 |
+
{
|
| 424 |
+
free(str_num);
|
| 425 |
+
return CHANNEL_RC_NULL_DATA;
|
| 426 |
+
}
|
| 427 |
+
|
| 428 |
+
oss->dev_unit = (INT32)val;
|
| 429 |
+
}
|
| 430 |
+
|
| 431 |
+
if (oss->dev_unit < 0 || *eptr != '\0')
|
| 432 |
+
oss->dev_unit = -1;
|
| 433 |
+
|
| 434 |
+
free(str_num);
|
| 435 |
+
}
|
| 436 |
+
CommandLineSwitchEnd(arg)
|
| 437 |
+
} while ((arg = CommandLineFindNextArgumentA(arg)) != NULL);
|
| 438 |
+
|
| 439 |
+
return CHANNEL_RC_OK;
|
| 440 |
+
}
|
| 441 |
+
|
| 442 |
+
/**
|
| 443 |
+
* Function description
|
| 444 |
+
*
|
| 445 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 446 |
+
*/
|
| 447 |
+
FREERDP_ENTRY_POINT(UINT VCAPITYPE oss_freerdp_audin_client_subsystem_entry(
|
| 448 |
+
PFREERDP_AUDIN_DEVICE_ENTRY_POINTS pEntryPoints))
|
| 449 |
+
{
|
| 450 |
+
const ADDIN_ARGV* args = NULL;
|
| 451 |
+
AudinOSSDevice* oss = NULL;
|
| 452 |
+
UINT error = 0;
|
| 453 |
+
oss = (AudinOSSDevice*)calloc(1, sizeof(AudinOSSDevice));
|
| 454 |
+
|
| 455 |
+
if (!oss)
|
| 456 |
+
{
|
| 457 |
+
WLog_ERR(TAG, "calloc failed!");
|
| 458 |
+
return CHANNEL_RC_NO_MEMORY;
|
| 459 |
+
}
|
| 460 |
+
|
| 461 |
+
oss->iface.Open = audin_oss_open;
|
| 462 |
+
oss->iface.FormatSupported = audin_oss_format_supported;
|
| 463 |
+
oss->iface.SetFormat = audin_oss_set_format;
|
| 464 |
+
oss->iface.Close = audin_oss_close;
|
| 465 |
+
oss->iface.Free = audin_oss_free;
|
| 466 |
+
oss->rdpcontext = pEntryPoints->rdpcontext;
|
| 467 |
+
oss->dev_unit = -1;
|
| 468 |
+
args = pEntryPoints->args;
|
| 469 |
+
|
| 470 |
+
if ((error = audin_oss_parse_addin_args(oss, args)))
|
| 471 |
+
{
|
| 472 |
+
WLog_ERR(TAG, "audin_oss_parse_addin_args failed with errorcode %" PRIu32 "!", error);
|
| 473 |
+
goto error_out;
|
| 474 |
+
}
|
| 475 |
+
|
| 476 |
+
if ((error = pEntryPoints->pRegisterAudinDevice(pEntryPoints->plugin, (IAudinDevice*)oss)))
|
| 477 |
+
{
|
| 478 |
+
WLog_ERR(TAG, "RegisterAudinDevice failed with error %" PRIu32 "!", error);
|
| 479 |
+
goto error_out;
|
| 480 |
+
}
|
| 481 |
+
|
| 482 |
+
return CHANNEL_RC_OK;
|
| 483 |
+
error_out:
|
| 484 |
+
free(oss);
|
| 485 |
+
return error;
|
| 486 |
+
}
|
local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/pulse/CMakeLists.txt
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# FreeRDP: A Remote Desktop Protocol Implementation
|
| 2 |
+
# FreeRDP cmake build script
|
| 3 |
+
#
|
| 4 |
+
# Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
| 5 |
+
#
|
| 6 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 7 |
+
# you may not use this file except in compliance with the License.
|
| 8 |
+
# You may obtain a copy of the License at
|
| 9 |
+
#
|
| 10 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 11 |
+
#
|
| 12 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 13 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 14 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 15 |
+
# See the License for the specific language governing permissions and
|
| 16 |
+
# limitations under the License.
|
| 17 |
+
|
| 18 |
+
define_channel_client_subsystem("audin" "pulse" "")
|
| 19 |
+
|
| 20 |
+
find_package(PulseAudio REQUIRED)
|
| 21 |
+
|
| 22 |
+
set(${MODULE_PREFIX}_SRCS audin_pulse.c)
|
| 23 |
+
|
| 24 |
+
set(${MODULE_PREFIX}_LIBS winpr freerdp ${PULSEAUDIO_LIBRARY} ${PULSEAUDIO_MAINLOOP_LIBRARY})
|
| 25 |
+
|
| 26 |
+
include_directories(..)
|
| 27 |
+
include_directories(SYSTEM ${PULSEAUDIO_INCLUDE_DIR})
|
| 28 |
+
|
| 29 |
+
add_channel_client_subsystem_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} "" TRUE "")
|
local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/pulse/audin_pulse.c
ADDED
|
@@ -0,0 +1,561 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* FreeRDP: A Remote Desktop Protocol Implementation
|
| 3 |
+
* Audio Input Redirection Virtual Channel - PulseAudio implementation
|
| 4 |
+
*
|
| 5 |
+
* Copyright 2010-2011 Vic Lee
|
| 6 |
+
* Copyright 2015 Thincast Technologies GmbH
|
| 7 |
+
* Copyright 2015 DI (FH) Martin Haimberger <martin.haimberger@thincast.com>
|
| 8 |
+
*
|
| 9 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 10 |
+
* you may not use this file except in compliance with the License.
|
| 11 |
+
* You may obtain a copy of the License at
|
| 12 |
+
*
|
| 13 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 14 |
+
*
|
| 15 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 16 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 17 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 18 |
+
* See the License for the specific language governing permissions and
|
| 19 |
+
* limitations under the License.
|
| 20 |
+
*/
|
| 21 |
+
|
| 22 |
+
#include <freerdp/config.h>
|
| 23 |
+
|
| 24 |
+
#include <stdio.h>
|
| 25 |
+
#include <stdlib.h>
|
| 26 |
+
#include <string.h>
|
| 27 |
+
|
| 28 |
+
#include <winpr/crt.h>
|
| 29 |
+
#include <winpr/cmdline.h>
|
| 30 |
+
#include <winpr/wlog.h>
|
| 31 |
+
#include <winpr/cast.h>
|
| 32 |
+
|
| 33 |
+
#include <pulse/pulseaudio.h>
|
| 34 |
+
|
| 35 |
+
#include <freerdp/types.h>
|
| 36 |
+
#include <freerdp/addin.h>
|
| 37 |
+
#include <freerdp/freerdp.h>
|
| 38 |
+
#include <freerdp/codec/audio.h>
|
| 39 |
+
#include <freerdp/client/audin.h>
|
| 40 |
+
|
| 41 |
+
#include "audin_main.h"
|
| 42 |
+
|
| 43 |
+
typedef struct
|
| 44 |
+
{
|
| 45 |
+
IAudinDevice iface;
|
| 46 |
+
|
| 47 |
+
char* device_name;
|
| 48 |
+
UINT32 frames_per_packet;
|
| 49 |
+
pa_threaded_mainloop* mainloop;
|
| 50 |
+
pa_context* context;
|
| 51 |
+
pa_sample_spec sample_spec;
|
| 52 |
+
pa_stream* stream;
|
| 53 |
+
AUDIO_FORMAT format;
|
| 54 |
+
|
| 55 |
+
size_t bytes_per_frame;
|
| 56 |
+
size_t buffer_frames;
|
| 57 |
+
|
| 58 |
+
AudinReceive receive;
|
| 59 |
+
void* user_data;
|
| 60 |
+
|
| 61 |
+
rdpContext* rdpcontext;
|
| 62 |
+
wLog* log;
|
| 63 |
+
} AudinPulseDevice;
|
| 64 |
+
|
| 65 |
+
static const char* pulse_context_state_string(pa_context_state_t state)
|
| 66 |
+
{
|
| 67 |
+
switch (state)
|
| 68 |
+
{
|
| 69 |
+
case PA_CONTEXT_UNCONNECTED:
|
| 70 |
+
return "PA_CONTEXT_UNCONNECTED";
|
| 71 |
+
case PA_CONTEXT_CONNECTING:
|
| 72 |
+
return "PA_CONTEXT_CONNECTING";
|
| 73 |
+
case PA_CONTEXT_AUTHORIZING:
|
| 74 |
+
return "PA_CONTEXT_AUTHORIZING";
|
| 75 |
+
case PA_CONTEXT_SETTING_NAME:
|
| 76 |
+
return "PA_CONTEXT_SETTING_NAME";
|
| 77 |
+
case PA_CONTEXT_READY:
|
| 78 |
+
return "PA_CONTEXT_READY";
|
| 79 |
+
case PA_CONTEXT_FAILED:
|
| 80 |
+
return "PA_CONTEXT_FAILED";
|
| 81 |
+
case PA_CONTEXT_TERMINATED:
|
| 82 |
+
return "PA_CONTEXT_TERMINATED";
|
| 83 |
+
default:
|
| 84 |
+
return "UNKNOWN";
|
| 85 |
+
}
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
static const char* pulse_stream_state_string(pa_stream_state_t state)
|
| 89 |
+
{
|
| 90 |
+
switch (state)
|
| 91 |
+
{
|
| 92 |
+
case PA_STREAM_UNCONNECTED:
|
| 93 |
+
return "PA_STREAM_UNCONNECTED";
|
| 94 |
+
case PA_STREAM_CREATING:
|
| 95 |
+
return "PA_STREAM_CREATING";
|
| 96 |
+
case PA_STREAM_READY:
|
| 97 |
+
return "PA_STREAM_READY";
|
| 98 |
+
case PA_STREAM_FAILED:
|
| 99 |
+
return "PA_STREAM_FAILED";
|
| 100 |
+
case PA_STREAM_TERMINATED:
|
| 101 |
+
return "PA_STREAM_TERMINATED";
|
| 102 |
+
default:
|
| 103 |
+
return "UNKNOWN";
|
| 104 |
+
}
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
static void audin_pulse_context_state_callback(pa_context* context, void* userdata)
|
| 108 |
+
{
|
| 109 |
+
AudinPulseDevice* pulse = (AudinPulseDevice*)userdata;
|
| 110 |
+
pa_context_state_t state = pa_context_get_state(context);
|
| 111 |
+
|
| 112 |
+
WLog_Print(pulse->log, WLOG_DEBUG, "context state %s", pulse_context_state_string(state));
|
| 113 |
+
switch (state)
|
| 114 |
+
{
|
| 115 |
+
case PA_CONTEXT_READY:
|
| 116 |
+
case PA_CONTEXT_FAILED:
|
| 117 |
+
case PA_CONTEXT_TERMINATED:
|
| 118 |
+
pa_threaded_mainloop_signal(pulse->mainloop, 0);
|
| 119 |
+
break;
|
| 120 |
+
|
| 121 |
+
default:
|
| 122 |
+
break;
|
| 123 |
+
}
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
/**
|
| 127 |
+
* Function description
|
| 128 |
+
*
|
| 129 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 130 |
+
*/
|
| 131 |
+
static UINT audin_pulse_connect(IAudinDevice* device)
|
| 132 |
+
{
|
| 133 |
+
pa_context_state_t state = PA_CONTEXT_FAILED;
|
| 134 |
+
AudinPulseDevice* pulse = (AudinPulseDevice*)device;
|
| 135 |
+
|
| 136 |
+
if (!pulse->context)
|
| 137 |
+
return ERROR_INVALID_PARAMETER;
|
| 138 |
+
|
| 139 |
+
if (pa_context_connect(pulse->context, NULL, 0, NULL))
|
| 140 |
+
{
|
| 141 |
+
WLog_Print(pulse->log, WLOG_ERROR, "pa_context_connect failed (%d)",
|
| 142 |
+
pa_context_errno(pulse->context));
|
| 143 |
+
return ERROR_INTERNAL_ERROR;
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
pa_threaded_mainloop_lock(pulse->mainloop);
|
| 147 |
+
|
| 148 |
+
if (pa_threaded_mainloop_start(pulse->mainloop) < 0)
|
| 149 |
+
{
|
| 150 |
+
pa_threaded_mainloop_unlock(pulse->mainloop);
|
| 151 |
+
WLog_Print(pulse->log, WLOG_ERROR, "pa_threaded_mainloop_start failed (%d)",
|
| 152 |
+
pa_context_errno(pulse->context));
|
| 153 |
+
return ERROR_INTERNAL_ERROR;
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
for (;;)
|
| 157 |
+
{
|
| 158 |
+
state = pa_context_get_state(pulse->context);
|
| 159 |
+
|
| 160 |
+
if (state == PA_CONTEXT_READY)
|
| 161 |
+
break;
|
| 162 |
+
|
| 163 |
+
if (!PA_CONTEXT_IS_GOOD(state))
|
| 164 |
+
{
|
| 165 |
+
WLog_Print(pulse->log, WLOG_ERROR, "bad context state (%s: %d)",
|
| 166 |
+
pulse_context_state_string(state), pa_context_errno(pulse->context));
|
| 167 |
+
pa_context_disconnect(pulse->context);
|
| 168 |
+
return ERROR_INVALID_STATE;
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
pa_threaded_mainloop_wait(pulse->mainloop);
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
pa_threaded_mainloop_unlock(pulse->mainloop);
|
| 175 |
+
WLog_Print(pulse->log, WLOG_DEBUG, "connected");
|
| 176 |
+
return CHANNEL_RC_OK;
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
/**
|
| 180 |
+
* Function description
|
| 181 |
+
*
|
| 182 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 183 |
+
*/
|
| 184 |
+
static UINT audin_pulse_free(IAudinDevice* device)
|
| 185 |
+
{
|
| 186 |
+
AudinPulseDevice* pulse = (AudinPulseDevice*)device;
|
| 187 |
+
|
| 188 |
+
if (!pulse)
|
| 189 |
+
return ERROR_INVALID_PARAMETER;
|
| 190 |
+
|
| 191 |
+
if (pulse->mainloop)
|
| 192 |
+
{
|
| 193 |
+
pa_threaded_mainloop_stop(pulse->mainloop);
|
| 194 |
+
}
|
| 195 |
+
|
| 196 |
+
if (pulse->context)
|
| 197 |
+
{
|
| 198 |
+
pa_context_disconnect(pulse->context);
|
| 199 |
+
pa_context_unref(pulse->context);
|
| 200 |
+
pulse->context = NULL;
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
if (pulse->mainloop)
|
| 204 |
+
{
|
| 205 |
+
pa_threaded_mainloop_free(pulse->mainloop);
|
| 206 |
+
pulse->mainloop = NULL;
|
| 207 |
+
}
|
| 208 |
+
|
| 209 |
+
free(pulse);
|
| 210 |
+
return CHANNEL_RC_OK;
|
| 211 |
+
}
|
| 212 |
+
|
| 213 |
+
static BOOL audin_pulse_format_supported(IAudinDevice* device, const AUDIO_FORMAT* format)
|
| 214 |
+
{
|
| 215 |
+
AudinPulseDevice* pulse = (AudinPulseDevice*)device;
|
| 216 |
+
|
| 217 |
+
if (!pulse || !format)
|
| 218 |
+
return FALSE;
|
| 219 |
+
|
| 220 |
+
if (!pulse->context)
|
| 221 |
+
return 0;
|
| 222 |
+
|
| 223 |
+
switch (format->wFormatTag)
|
| 224 |
+
{
|
| 225 |
+
case WAVE_FORMAT_PCM:
|
| 226 |
+
if (format->cbSize == 0 && (format->nSamplesPerSec <= PA_RATE_MAX) &&
|
| 227 |
+
(format->wBitsPerSample == 8 || format->wBitsPerSample == 16) &&
|
| 228 |
+
(format->nChannels >= 1 && format->nChannels <= PA_CHANNELS_MAX))
|
| 229 |
+
{
|
| 230 |
+
return TRUE;
|
| 231 |
+
}
|
| 232 |
+
|
| 233 |
+
break;
|
| 234 |
+
|
| 235 |
+
default:
|
| 236 |
+
return FALSE;
|
| 237 |
+
}
|
| 238 |
+
|
| 239 |
+
return FALSE;
|
| 240 |
+
}
|
| 241 |
+
|
| 242 |
+
/**
|
| 243 |
+
* Function description
|
| 244 |
+
*
|
| 245 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 246 |
+
*/
|
| 247 |
+
static UINT audin_pulse_set_format(IAudinDevice* device, const AUDIO_FORMAT* format,
|
| 248 |
+
UINT32 FramesPerPacket)
|
| 249 |
+
{
|
| 250 |
+
pa_sample_spec sample_spec = { 0 };
|
| 251 |
+
AudinPulseDevice* pulse = (AudinPulseDevice*)device;
|
| 252 |
+
|
| 253 |
+
if (!pulse || !format)
|
| 254 |
+
return ERROR_INVALID_PARAMETER;
|
| 255 |
+
|
| 256 |
+
if (!pulse->context)
|
| 257 |
+
return ERROR_INVALID_PARAMETER;
|
| 258 |
+
|
| 259 |
+
if (FramesPerPacket > 0)
|
| 260 |
+
pulse->frames_per_packet = FramesPerPacket;
|
| 261 |
+
|
| 262 |
+
sample_spec.rate = format->nSamplesPerSec;
|
| 263 |
+
|
| 264 |
+
sample_spec.channels = WINPR_ASSERTING_INT_CAST(uint8_t, format->nChannels);
|
| 265 |
+
|
| 266 |
+
switch (format->wFormatTag)
|
| 267 |
+
{
|
| 268 |
+
case WAVE_FORMAT_PCM: /* PCM */
|
| 269 |
+
switch (format->wBitsPerSample)
|
| 270 |
+
{
|
| 271 |
+
case 8:
|
| 272 |
+
sample_spec.format = PA_SAMPLE_U8;
|
| 273 |
+
break;
|
| 274 |
+
|
| 275 |
+
case 16:
|
| 276 |
+
sample_spec.format = PA_SAMPLE_S16LE;
|
| 277 |
+
break;
|
| 278 |
+
|
| 279 |
+
default:
|
| 280 |
+
return ERROR_INTERNAL_ERROR;
|
| 281 |
+
}
|
| 282 |
+
|
| 283 |
+
break;
|
| 284 |
+
|
| 285 |
+
default:
|
| 286 |
+
return ERROR_INTERNAL_ERROR;
|
| 287 |
+
}
|
| 288 |
+
|
| 289 |
+
pulse->sample_spec = sample_spec;
|
| 290 |
+
pulse->format = *format;
|
| 291 |
+
return CHANNEL_RC_OK;
|
| 292 |
+
}
|
| 293 |
+
|
| 294 |
+
static void audin_pulse_stream_state_callback(pa_stream* stream, void* userdata)
|
| 295 |
+
{
|
| 296 |
+
AudinPulseDevice* pulse = (AudinPulseDevice*)userdata;
|
| 297 |
+
WINPR_ASSERT(pulse);
|
| 298 |
+
|
| 299 |
+
pa_stream_state_t state = pa_stream_get_state(stream);
|
| 300 |
+
|
| 301 |
+
WLog_Print(pulse->log, WLOG_DEBUG, "stream state %s", pulse_stream_state_string(state));
|
| 302 |
+
switch (state)
|
| 303 |
+
{
|
| 304 |
+
case PA_STREAM_READY:
|
| 305 |
+
case PA_STREAM_FAILED:
|
| 306 |
+
case PA_STREAM_TERMINATED:
|
| 307 |
+
pa_threaded_mainloop_signal(pulse->mainloop, 0);
|
| 308 |
+
break;
|
| 309 |
+
|
| 310 |
+
case PA_STREAM_UNCONNECTED:
|
| 311 |
+
case PA_STREAM_CREATING:
|
| 312 |
+
default:
|
| 313 |
+
break;
|
| 314 |
+
}
|
| 315 |
+
}
|
| 316 |
+
|
| 317 |
+
static void audin_pulse_stream_request_callback(pa_stream* stream, size_t length, void* userdata)
|
| 318 |
+
{
|
| 319 |
+
const void* data = NULL;
|
| 320 |
+
AudinPulseDevice* pulse = (AudinPulseDevice*)userdata;
|
| 321 |
+
UINT error = CHANNEL_RC_OK;
|
| 322 |
+
pa_stream_peek(stream, &data, &length);
|
| 323 |
+
error =
|
| 324 |
+
IFCALLRESULT(CHANNEL_RC_OK, pulse->receive, &pulse->format, data, length, pulse->user_data);
|
| 325 |
+
pa_stream_drop(stream);
|
| 326 |
+
|
| 327 |
+
if (error && pulse->rdpcontext)
|
| 328 |
+
setChannelError(pulse->rdpcontext, error, "audin_pulse_thread_func reported an error");
|
| 329 |
+
}
|
| 330 |
+
|
| 331 |
+
/**
|
| 332 |
+
* Function description
|
| 333 |
+
*
|
| 334 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 335 |
+
*/
|
| 336 |
+
static UINT audin_pulse_close(IAudinDevice* device)
|
| 337 |
+
{
|
| 338 |
+
AudinPulseDevice* pulse = (AudinPulseDevice*)device;
|
| 339 |
+
|
| 340 |
+
if (!pulse)
|
| 341 |
+
return ERROR_INVALID_PARAMETER;
|
| 342 |
+
|
| 343 |
+
if (pulse->stream)
|
| 344 |
+
{
|
| 345 |
+
pa_threaded_mainloop_lock(pulse->mainloop);
|
| 346 |
+
pa_stream_disconnect(pulse->stream);
|
| 347 |
+
pa_stream_unref(pulse->stream);
|
| 348 |
+
pulse->stream = NULL;
|
| 349 |
+
pa_threaded_mainloop_unlock(pulse->mainloop);
|
| 350 |
+
}
|
| 351 |
+
|
| 352 |
+
pulse->receive = NULL;
|
| 353 |
+
pulse->user_data = NULL;
|
| 354 |
+
return CHANNEL_RC_OK;
|
| 355 |
+
}
|
| 356 |
+
|
| 357 |
+
/**
|
| 358 |
+
* Function description
|
| 359 |
+
*
|
| 360 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 361 |
+
*/
|
| 362 |
+
static UINT audin_pulse_open(IAudinDevice* device, AudinReceive receive, void* user_data)
|
| 363 |
+
{
|
| 364 |
+
pa_stream_state_t state = PA_STREAM_FAILED;
|
| 365 |
+
pa_buffer_attr buffer_attr = { 0 };
|
| 366 |
+
AudinPulseDevice* pulse = (AudinPulseDevice*)device;
|
| 367 |
+
|
| 368 |
+
if (!pulse || !receive || !user_data)
|
| 369 |
+
return ERROR_INVALID_PARAMETER;
|
| 370 |
+
|
| 371 |
+
if (!pulse->context)
|
| 372 |
+
return ERROR_INVALID_PARAMETER;
|
| 373 |
+
|
| 374 |
+
if (!pulse->sample_spec.rate || pulse->stream)
|
| 375 |
+
return ERROR_INVALID_PARAMETER;
|
| 376 |
+
|
| 377 |
+
pulse->receive = receive;
|
| 378 |
+
pulse->user_data = user_data;
|
| 379 |
+
pa_threaded_mainloop_lock(pulse->mainloop);
|
| 380 |
+
pulse->stream = pa_stream_new(pulse->context, "freerdp_audin", &pulse->sample_spec, NULL);
|
| 381 |
+
|
| 382 |
+
if (!pulse->stream)
|
| 383 |
+
{
|
| 384 |
+
pa_threaded_mainloop_unlock(pulse->mainloop);
|
| 385 |
+
WLog_Print(pulse->log, WLOG_DEBUG, "pa_stream_new failed (%d)",
|
| 386 |
+
pa_context_errno(pulse->context));
|
| 387 |
+
const int rc = pa_context_errno(pulse->context);
|
| 388 |
+
return (UINT)rc;
|
| 389 |
+
}
|
| 390 |
+
|
| 391 |
+
pulse->bytes_per_frame = pa_frame_size(&pulse->sample_spec);
|
| 392 |
+
pa_stream_set_state_callback(pulse->stream, audin_pulse_stream_state_callback, pulse);
|
| 393 |
+
pa_stream_set_read_callback(pulse->stream, audin_pulse_stream_request_callback, pulse);
|
| 394 |
+
buffer_attr.maxlength = (UINT32)-1;
|
| 395 |
+
buffer_attr.tlength = (UINT32)-1;
|
| 396 |
+
buffer_attr.prebuf = (UINT32)-1;
|
| 397 |
+
buffer_attr.minreq = (UINT32)-1;
|
| 398 |
+
/* 500ms latency */
|
| 399 |
+
const size_t frag = pulse->bytes_per_frame * pulse->frames_per_packet;
|
| 400 |
+
WINPR_ASSERT(frag <= UINT32_MAX);
|
| 401 |
+
buffer_attr.fragsize = (uint32_t)frag;
|
| 402 |
+
|
| 403 |
+
if (buffer_attr.fragsize % pulse->format.nBlockAlign)
|
| 404 |
+
buffer_attr.fragsize +=
|
| 405 |
+
pulse->format.nBlockAlign - buffer_attr.fragsize % pulse->format.nBlockAlign;
|
| 406 |
+
|
| 407 |
+
if (pa_stream_connect_record(pulse->stream, pulse->device_name, &buffer_attr,
|
| 408 |
+
PA_STREAM_ADJUST_LATENCY) < 0)
|
| 409 |
+
{
|
| 410 |
+
pa_threaded_mainloop_unlock(pulse->mainloop);
|
| 411 |
+
WLog_Print(pulse->log, WLOG_ERROR, "pa_stream_connect_playback failed (%d)",
|
| 412 |
+
pa_context_errno(pulse->context));
|
| 413 |
+
const int rc = pa_context_errno(pulse->context);
|
| 414 |
+
return (UINT)rc;
|
| 415 |
+
}
|
| 416 |
+
|
| 417 |
+
while (pulse->stream)
|
| 418 |
+
{
|
| 419 |
+
state = pa_stream_get_state(pulse->stream);
|
| 420 |
+
|
| 421 |
+
if (state == PA_STREAM_READY)
|
| 422 |
+
break;
|
| 423 |
+
|
| 424 |
+
if (!PA_STREAM_IS_GOOD(state))
|
| 425 |
+
{
|
| 426 |
+
audin_pulse_close(device);
|
| 427 |
+
WLog_Print(pulse->log, WLOG_ERROR, "bad stream state (%s: %d)",
|
| 428 |
+
pulse_stream_state_string(state), pa_context_errno(pulse->context));
|
| 429 |
+
pa_threaded_mainloop_unlock(pulse->mainloop);
|
| 430 |
+
const int rc = pa_context_errno(pulse->context);
|
| 431 |
+
return (UINT)rc;
|
| 432 |
+
}
|
| 433 |
+
|
| 434 |
+
pa_threaded_mainloop_wait(pulse->mainloop);
|
| 435 |
+
}
|
| 436 |
+
|
| 437 |
+
pa_threaded_mainloop_unlock(pulse->mainloop);
|
| 438 |
+
pulse->buffer_frames = 0;
|
| 439 |
+
WLog_Print(pulse->log, WLOG_DEBUG, "connected");
|
| 440 |
+
return CHANNEL_RC_OK;
|
| 441 |
+
}
|
| 442 |
+
|
| 443 |
+
/**
|
| 444 |
+
* Function description
|
| 445 |
+
*
|
| 446 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 447 |
+
*/
|
| 448 |
+
static UINT audin_pulse_parse_addin_args(AudinPulseDevice* device, const ADDIN_ARGV* args)
|
| 449 |
+
{
|
| 450 |
+
int status = 0;
|
| 451 |
+
DWORD flags = 0;
|
| 452 |
+
const COMMAND_LINE_ARGUMENT_A* arg = NULL;
|
| 453 |
+
AudinPulseDevice* pulse = device;
|
| 454 |
+
COMMAND_LINE_ARGUMENT_A audin_pulse_args[] = { { "dev", COMMAND_LINE_VALUE_REQUIRED, "<device>",
|
| 455 |
+
NULL, NULL, -1, NULL, "audio device name" },
|
| 456 |
+
{ NULL, 0, NULL, NULL, NULL, -1, NULL, NULL } };
|
| 457 |
+
|
| 458 |
+
flags =
|
| 459 |
+
COMMAND_LINE_SIGIL_NONE | COMMAND_LINE_SEPARATOR_COLON | COMMAND_LINE_IGN_UNKNOWN_KEYWORD;
|
| 460 |
+
status = CommandLineParseArgumentsA(args->argc, args->argv, audin_pulse_args, flags, pulse,
|
| 461 |
+
NULL, NULL);
|
| 462 |
+
|
| 463 |
+
if (status < 0)
|
| 464 |
+
return ERROR_INVALID_PARAMETER;
|
| 465 |
+
|
| 466 |
+
arg = audin_pulse_args;
|
| 467 |
+
|
| 468 |
+
do
|
| 469 |
+
{
|
| 470 |
+
if (!(arg->Flags & COMMAND_LINE_VALUE_PRESENT))
|
| 471 |
+
continue;
|
| 472 |
+
|
| 473 |
+
CommandLineSwitchStart(arg) CommandLineSwitchCase(arg, "dev")
|
| 474 |
+
{
|
| 475 |
+
pulse->device_name = _strdup(arg->Value);
|
| 476 |
+
|
| 477 |
+
if (!pulse->device_name)
|
| 478 |
+
{
|
| 479 |
+
WLog_Print(pulse->log, WLOG_ERROR, "_strdup failed!");
|
| 480 |
+
return CHANNEL_RC_NO_MEMORY;
|
| 481 |
+
}
|
| 482 |
+
}
|
| 483 |
+
CommandLineSwitchEnd(arg)
|
| 484 |
+
} while ((arg = CommandLineFindNextArgumentA(arg)) != NULL);
|
| 485 |
+
|
| 486 |
+
return CHANNEL_RC_OK;
|
| 487 |
+
}
|
| 488 |
+
|
| 489 |
+
/**
|
| 490 |
+
* Function description
|
| 491 |
+
*
|
| 492 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 493 |
+
*/
|
| 494 |
+
FREERDP_ENTRY_POINT(UINT VCAPITYPE pulse_freerdp_audin_client_subsystem_entry(
|
| 495 |
+
PFREERDP_AUDIN_DEVICE_ENTRY_POINTS pEntryPoints))
|
| 496 |
+
{
|
| 497 |
+
const ADDIN_ARGV* args = NULL;
|
| 498 |
+
AudinPulseDevice* pulse = NULL;
|
| 499 |
+
UINT error = 0;
|
| 500 |
+
pulse = (AudinPulseDevice*)calloc(1, sizeof(AudinPulseDevice));
|
| 501 |
+
|
| 502 |
+
if (!pulse)
|
| 503 |
+
{
|
| 504 |
+
WLog_ERR(TAG, "calloc failed!");
|
| 505 |
+
return CHANNEL_RC_NO_MEMORY;
|
| 506 |
+
}
|
| 507 |
+
|
| 508 |
+
pulse->log = WLog_Get(TAG);
|
| 509 |
+
pulse->iface.Open = audin_pulse_open;
|
| 510 |
+
pulse->iface.FormatSupported = audin_pulse_format_supported;
|
| 511 |
+
pulse->iface.SetFormat = audin_pulse_set_format;
|
| 512 |
+
pulse->iface.Close = audin_pulse_close;
|
| 513 |
+
pulse->iface.Free = audin_pulse_free;
|
| 514 |
+
pulse->rdpcontext = pEntryPoints->rdpcontext;
|
| 515 |
+
args = pEntryPoints->args;
|
| 516 |
+
|
| 517 |
+
if ((error = audin_pulse_parse_addin_args(pulse, args)))
|
| 518 |
+
{
|
| 519 |
+
WLog_Print(pulse->log, WLOG_ERROR,
|
| 520 |
+
"audin_pulse_parse_addin_args failed with error %" PRIu32 "!", error);
|
| 521 |
+
goto error_out;
|
| 522 |
+
}
|
| 523 |
+
|
| 524 |
+
pulse->mainloop = pa_threaded_mainloop_new();
|
| 525 |
+
|
| 526 |
+
if (!pulse->mainloop)
|
| 527 |
+
{
|
| 528 |
+
WLog_Print(pulse->log, WLOG_ERROR, "pa_threaded_mainloop_new failed");
|
| 529 |
+
error = CHANNEL_RC_NO_MEMORY;
|
| 530 |
+
goto error_out;
|
| 531 |
+
}
|
| 532 |
+
|
| 533 |
+
pulse->context = pa_context_new(pa_threaded_mainloop_get_api(pulse->mainloop), "freerdp");
|
| 534 |
+
|
| 535 |
+
if (!pulse->context)
|
| 536 |
+
{
|
| 537 |
+
WLog_Print(pulse->log, WLOG_ERROR, "pa_context_new failed");
|
| 538 |
+
error = CHANNEL_RC_NO_MEMORY;
|
| 539 |
+
goto error_out;
|
| 540 |
+
}
|
| 541 |
+
|
| 542 |
+
pa_context_set_state_callback(pulse->context, audin_pulse_context_state_callback, pulse);
|
| 543 |
+
|
| 544 |
+
if ((error = audin_pulse_connect(&pulse->iface)))
|
| 545 |
+
{
|
| 546 |
+
WLog_Print(pulse->log, WLOG_ERROR, "audin_pulse_connect failed");
|
| 547 |
+
goto error_out;
|
| 548 |
+
}
|
| 549 |
+
|
| 550 |
+
if ((error = pEntryPoints->pRegisterAudinDevice(pEntryPoints->plugin, &pulse->iface)))
|
| 551 |
+
{
|
| 552 |
+
WLog_Print(pulse->log, WLOG_ERROR, "RegisterAudinDevice failed with error %" PRIu32 "!",
|
| 553 |
+
error);
|
| 554 |
+
goto error_out;
|
| 555 |
+
}
|
| 556 |
+
|
| 557 |
+
return CHANNEL_RC_OK;
|
| 558 |
+
error_out:
|
| 559 |
+
audin_pulse_free(&pulse->iface);
|
| 560 |
+
return error;
|
| 561 |
+
}
|
local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/sndio/CMakeLists.txt
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# FreeRDP: A Remote Desktop Protocol Implementation
|
| 2 |
+
# FreeRDP cmake build script
|
| 3 |
+
#
|
| 4 |
+
# Copyright (c) 2015 Rozhuk Ivan <rozhuk.im@gmail.com>
|
| 5 |
+
# Copyright (c) 2020 Ingo Feinerer <feinerer@logic.at>
|
| 6 |
+
#
|
| 7 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 8 |
+
# you may not use this file except in compliance with the License.
|
| 9 |
+
# You may obtain a copy of the License at
|
| 10 |
+
#
|
| 11 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
+
#
|
| 13 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 14 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 15 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 16 |
+
# See the License for the specific language governing permissions and
|
| 17 |
+
# limitations under the License.
|
| 18 |
+
|
| 19 |
+
define_channel_client_subsystem("audin" "sndio" "")
|
| 20 |
+
|
| 21 |
+
find_package(SNDIO REQUIRED)
|
| 22 |
+
|
| 23 |
+
set(${MODULE_PREFIX}_SRCS audin_sndio.c)
|
| 24 |
+
|
| 25 |
+
set(${MODULE_PREFIX}_LIBS winpr freerdp ${SNDIO_LIBRARIES})
|
| 26 |
+
|
| 27 |
+
include_directories(..)
|
| 28 |
+
include_directories(SYSTEM ${SNDIO_INCLUDE_DIRS})
|
| 29 |
+
|
| 30 |
+
add_channel_client_subsystem_library(${MODULE_PREFIX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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* FreeRDP: A Remote Desktop Protocol Implementation
|
| 3 |
+
* Audio Input Redirection Virtual Channel - sndio implementation
|
| 4 |
+
*
|
| 5 |
+
* Copyright (c) 2015 Rozhuk Ivan <rozhuk.im@gmail.com>
|
| 6 |
+
* Copyright 2015 Thincast Technologies GmbH
|
| 7 |
+
* Copyright 2015 DI (FH) Martin Haimberger <martin.haimberger@thincast.com>
|
| 8 |
+
* Copyright 2020 Ingo Feinerer <feinerer@logic.at>
|
| 9 |
+
*
|
| 10 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 11 |
+
* you may not use this file except in compliance with the License.
|
| 12 |
+
* You may obtain a copy of the License at
|
| 13 |
+
*
|
| 14 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 15 |
+
*
|
| 16 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 17 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 18 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 19 |
+
* See the License for the specific language governing permissions and
|
| 20 |
+
* limitations under the License.
|
| 21 |
+
*/
|
| 22 |
+
|
| 23 |
+
#include <freerdp/config.h>
|
| 24 |
+
|
| 25 |
+
#include <sndio.h>
|
| 26 |
+
|
| 27 |
+
#include <winpr/cmdline.h>
|
| 28 |
+
|
| 29 |
+
#include <freerdp/freerdp.h>
|
| 30 |
+
#include <freerdp/channels/rdpsnd.h>
|
| 31 |
+
|
| 32 |
+
#include "audin_main.h"
|
| 33 |
+
|
| 34 |
+
typedef struct
|
| 35 |
+
{
|
| 36 |
+
IAudinDevice device;
|
| 37 |
+
|
| 38 |
+
HANDLE thread;
|
| 39 |
+
HANDLE stopEvent;
|
| 40 |
+
|
| 41 |
+
AUDIO_FORMAT format;
|
| 42 |
+
UINT32 FramesPerPacket;
|
| 43 |
+
|
| 44 |
+
AudinReceive receive;
|
| 45 |
+
void* user_data;
|
| 46 |
+
|
| 47 |
+
rdpContext* rdpcontext;
|
| 48 |
+
} AudinSndioDevice;
|
| 49 |
+
|
| 50 |
+
static BOOL audin_sndio_format_supported(IAudinDevice* device, const AUDIO_FORMAT* format)
|
| 51 |
+
{
|
| 52 |
+
if (device == NULL || format == NULL)
|
| 53 |
+
return FALSE;
|
| 54 |
+
|
| 55 |
+
return (format->wFormatTag == WAVE_FORMAT_PCM);
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
/**
|
| 59 |
+
* Function description
|
| 60 |
+
*
|
| 61 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 62 |
+
*/
|
| 63 |
+
static UINT audin_sndio_set_format(IAudinDevice* device, AUDIO_FORMAT* format,
|
| 64 |
+
UINT32 FramesPerPacket)
|
| 65 |
+
{
|
| 66 |
+
AudinSndioDevice* sndio = (AudinSndioDevice*)device;
|
| 67 |
+
|
| 68 |
+
if (device == NULL || format == NULL)
|
| 69 |
+
return ERROR_INVALID_PARAMETER;
|
| 70 |
+
|
| 71 |
+
if (format->wFormatTag != WAVE_FORMAT_PCM)
|
| 72 |
+
return ERROR_INTERNAL_ERROR;
|
| 73 |
+
|
| 74 |
+
sndio->format = *format;
|
| 75 |
+
sndio->FramesPerPacket = FramesPerPacket;
|
| 76 |
+
|
| 77 |
+
return CHANNEL_RC_OK;
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
static void* audin_sndio_thread_func(void* arg)
|
| 81 |
+
{
|
| 82 |
+
struct sio_hdl* hdl;
|
| 83 |
+
struct sio_par par;
|
| 84 |
+
BYTE* buffer = NULL;
|
| 85 |
+
size_t n, nbytes;
|
| 86 |
+
AudinSndioDevice* sndio = (AudinSndioDevice*)arg;
|
| 87 |
+
UINT error = 0;
|
| 88 |
+
DWORD status;
|
| 89 |
+
|
| 90 |
+
if (arg == NULL)
|
| 91 |
+
{
|
| 92 |
+
error = ERROR_INVALID_PARAMETER;
|
| 93 |
+
goto err_out;
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
hdl = sio_open(SIO_DEVANY, SIO_REC, 0);
|
| 97 |
+
if (hdl == NULL)
|
| 98 |
+
{
|
| 99 |
+
WLog_ERR(TAG, "could not open audio device");
|
| 100 |
+
error = ERROR_INTERNAL_ERROR;
|
| 101 |
+
goto err_out;
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
sio_initpar(&par);
|
| 105 |
+
par.bits = sndio->format.wBitsPerSample;
|
| 106 |
+
par.rchan = sndio->format.nChannels;
|
| 107 |
+
par.rate = sndio->format.nSamplesPerSec;
|
| 108 |
+
if (!sio_setpar(hdl, &par))
|
| 109 |
+
{
|
| 110 |
+
WLog_ERR(TAG, "could not set audio parameters");
|
| 111 |
+
error = ERROR_INTERNAL_ERROR;
|
| 112 |
+
goto err_out;
|
| 113 |
+
}
|
| 114 |
+
if (!sio_getpar(hdl, &par))
|
| 115 |
+
{
|
| 116 |
+
WLog_ERR(TAG, "could not get audio parameters");
|
| 117 |
+
error = ERROR_INTERNAL_ERROR;
|
| 118 |
+
goto err_out;
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
if (!sio_start(hdl))
|
| 122 |
+
{
|
| 123 |
+
WLog_ERR(TAG, "could not start audio device");
|
| 124 |
+
error = ERROR_INTERNAL_ERROR;
|
| 125 |
+
goto err_out;
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
nbytes =
|
| 129 |
+
(sndio->FramesPerPacket * sndio->format.nChannels * (sndio->format.wBitsPerSample / 8));
|
| 130 |
+
buffer = (BYTE*)calloc((nbytes + sizeof(void*)), sizeof(BYTE));
|
| 131 |
+
|
| 132 |
+
if (buffer == NULL)
|
| 133 |
+
{
|
| 134 |
+
error = ERROR_NOT_ENOUGH_MEMORY;
|
| 135 |
+
goto err_out;
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
while (1)
|
| 139 |
+
{
|
| 140 |
+
status = WaitForSingleObject(sndio->stopEvent, 0);
|
| 141 |
+
|
| 142 |
+
if (status == WAIT_FAILED)
|
| 143 |
+
{
|
| 144 |
+
error = GetLastError();
|
| 145 |
+
WLog_ERR(TAG, "WaitForSingleObject failed with error %" PRIu32 "", error);
|
| 146 |
+
goto err_out;
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
if (status == WAIT_OBJECT_0)
|
| 150 |
+
break;
|
| 151 |
+
|
| 152 |
+
n = sio_read(hdl, buffer, nbytes);
|
| 153 |
+
|
| 154 |
+
if (n == 0)
|
| 155 |
+
{
|
| 156 |
+
WLog_ERR(TAG, "could not read");
|
| 157 |
+
continue;
|
| 158 |
+
}
|
| 159 |
+
|
| 160 |
+
if (n < nbytes)
|
| 161 |
+
continue;
|
| 162 |
+
|
| 163 |
+
if ((error = sndio->receive(&sndio->format, buffer, nbytes, sndio->user_data)))
|
| 164 |
+
{
|
| 165 |
+
WLog_ERR(TAG, "sndio->receive failed with error %" PRIu32 "", error);
|
| 166 |
+
break;
|
| 167 |
+
}
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
err_out:
|
| 171 |
+
if (error && sndio->rdpcontext)
|
| 172 |
+
setChannelError(sndio->rdpcontext, error, "audin_sndio_thread_func reported an error");
|
| 173 |
+
|
| 174 |
+
if (hdl != NULL)
|
| 175 |
+
{
|
| 176 |
+
WLog_INFO(TAG, "sio_close");
|
| 177 |
+
sio_stop(hdl);
|
| 178 |
+
sio_close(hdl);
|
| 179 |
+
}
|
| 180 |
+
|
| 181 |
+
free(buffer);
|
| 182 |
+
ExitThread(0);
|
| 183 |
+
return NULL;
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
+
/**
|
| 187 |
+
* Function description
|
| 188 |
+
*
|
| 189 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 190 |
+
*/
|
| 191 |
+
static UINT audin_sndio_open(IAudinDevice* device, AudinReceive receive, void* user_data)
|
| 192 |
+
{
|
| 193 |
+
AudinSndioDevice* sndio = (AudinSndioDevice*)device;
|
| 194 |
+
sndio->receive = receive;
|
| 195 |
+
sndio->user_data = user_data;
|
| 196 |
+
|
| 197 |
+
if (!(sndio->stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL)))
|
| 198 |
+
{
|
| 199 |
+
WLog_ERR(TAG, "CreateEvent failed");
|
| 200 |
+
return ERROR_INTERNAL_ERROR;
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
if (!(sndio->thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)audin_sndio_thread_func,
|
| 204 |
+
sndio, 0, NULL)))
|
| 205 |
+
{
|
| 206 |
+
WLog_ERR(TAG, "CreateThread failed");
|
| 207 |
+
(void)CloseHandle(sndio->stopEvent);
|
| 208 |
+
sndio->stopEvent = NULL;
|
| 209 |
+
return ERROR_INTERNAL_ERROR;
|
| 210 |
+
}
|
| 211 |
+
|
| 212 |
+
return CHANNEL_RC_OK;
|
| 213 |
+
}
|
| 214 |
+
|
| 215 |
+
/**
|
| 216 |
+
* Function description
|
| 217 |
+
*
|
| 218 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 219 |
+
*/
|
| 220 |
+
static UINT audin_sndio_close(IAudinDevice* device)
|
| 221 |
+
{
|
| 222 |
+
UINT error;
|
| 223 |
+
AudinSndioDevice* sndio = (AudinSndioDevice*)device;
|
| 224 |
+
|
| 225 |
+
if (device == NULL)
|
| 226 |
+
return ERROR_INVALID_PARAMETER;
|
| 227 |
+
|
| 228 |
+
if (sndio->stopEvent != NULL)
|
| 229 |
+
{
|
| 230 |
+
(void)SetEvent(sndio->stopEvent);
|
| 231 |
+
|
| 232 |
+
if (WaitForSingleObject(sndio->thread, INFINITE) == WAIT_FAILED)
|
| 233 |
+
{
|
| 234 |
+
error = GetLastError();
|
| 235 |
+
WLog_ERR(TAG, "WaitForSingleObject failed with error %" PRIu32 "", error);
|
| 236 |
+
return error;
|
| 237 |
+
}
|
| 238 |
+
|
| 239 |
+
(void)CloseHandle(sndio->stopEvent);
|
| 240 |
+
sndio->stopEvent = NULL;
|
| 241 |
+
(void)CloseHandle(sndio->thread);
|
| 242 |
+
sndio->thread = NULL;
|
| 243 |
+
}
|
| 244 |
+
|
| 245 |
+
sndio->receive = NULL;
|
| 246 |
+
sndio->user_data = NULL;
|
| 247 |
+
|
| 248 |
+
return CHANNEL_RC_OK;
|
| 249 |
+
}
|
| 250 |
+
|
| 251 |
+
/**
|
| 252 |
+
* Function description
|
| 253 |
+
*
|
| 254 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 255 |
+
*/
|
| 256 |
+
static UINT audin_sndio_free(IAudinDevice* device)
|
| 257 |
+
{
|
| 258 |
+
AudinSndioDevice* sndio = (AudinSndioDevice*)device;
|
| 259 |
+
int error;
|
| 260 |
+
|
| 261 |
+
if (device == NULL)
|
| 262 |
+
return ERROR_INVALID_PARAMETER;
|
| 263 |
+
|
| 264 |
+
if ((error = audin_sndio_close(device)))
|
| 265 |
+
{
|
| 266 |
+
WLog_ERR(TAG, "audin_sndio_close failed with error code %d", error);
|
| 267 |
+
}
|
| 268 |
+
|
| 269 |
+
free(sndio);
|
| 270 |
+
|
| 271 |
+
return CHANNEL_RC_OK;
|
| 272 |
+
}
|
| 273 |
+
|
| 274 |
+
/**
|
| 275 |
+
* Function description
|
| 276 |
+
*
|
| 277 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 278 |
+
*/
|
| 279 |
+
static UINT audin_sndio_parse_addin_args(AudinSndioDevice* device, ADDIN_ARGV* args)
|
| 280 |
+
{
|
| 281 |
+
int status;
|
| 282 |
+
DWORD flags;
|
| 283 |
+
COMMAND_LINE_ARGUMENT_A* arg;
|
| 284 |
+
AudinSndioDevice* sndio = (AudinSndioDevice*)device;
|
| 285 |
+
COMMAND_LINE_ARGUMENT_A audin_sndio_args[] = { { NULL, 0, NULL, NULL, NULL, -1, NULL, NULL } };
|
| 286 |
+
flags =
|
| 287 |
+
COMMAND_LINE_SIGIL_NONE | COMMAND_LINE_SEPARATOR_COLON | COMMAND_LINE_IGN_UNKNOWN_KEYWORD;
|
| 288 |
+
status = CommandLineParseArgumentsA(args->argc, (const char**)args->argv, audin_sndio_args,
|
| 289 |
+
flags, sndio, NULL, NULL);
|
| 290 |
+
|
| 291 |
+
if (status < 0)
|
| 292 |
+
return ERROR_INVALID_PARAMETER;
|
| 293 |
+
|
| 294 |
+
arg = audin_sndio_args;
|
| 295 |
+
|
| 296 |
+
do
|
| 297 |
+
{
|
| 298 |
+
if (!(arg->Flags & COMMAND_LINE_VALUE_PRESENT))
|
| 299 |
+
continue;
|
| 300 |
+
|
| 301 |
+
CommandLineSwitchStart(arg) CommandLineSwitchEnd(arg)
|
| 302 |
+
} while ((arg = CommandLineFindNextArgumentA(arg)) != NULL);
|
| 303 |
+
|
| 304 |
+
return CHANNEL_RC_OK;
|
| 305 |
+
}
|
| 306 |
+
|
| 307 |
+
/**
|
| 308 |
+
* Function description
|
| 309 |
+
*
|
| 310 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 311 |
+
*/
|
| 312 |
+
FREERDP_ENTRY_POINT(UINT VCAPITYPE sndio_freerdp_audin_client_subsystem_entry(
|
| 313 |
+
PFREERDP_AUDIN_DEVICE_ENTRY_POINTS pEntryPoints))
|
| 314 |
+
{
|
| 315 |
+
ADDIN_ARGV* args;
|
| 316 |
+
AudinSndioDevice* sndio;
|
| 317 |
+
UINT ret = CHANNEL_RC_OK;
|
| 318 |
+
sndio = (AudinSndioDevice*)calloc(1, sizeof(AudinSndioDevice));
|
| 319 |
+
|
| 320 |
+
if (sndio == NULL)
|
| 321 |
+
return CHANNEL_RC_NO_MEMORY;
|
| 322 |
+
|
| 323 |
+
sndio->device.Open = audin_sndio_open;
|
| 324 |
+
sndio->device.FormatSupported = audin_sndio_format_supported;
|
| 325 |
+
sndio->device.SetFormat = audin_sndio_set_format;
|
| 326 |
+
sndio->device.Close = audin_sndio_close;
|
| 327 |
+
sndio->device.Free = audin_sndio_free;
|
| 328 |
+
sndio->rdpcontext = pEntryPoints->rdpcontext;
|
| 329 |
+
args = pEntryPoints->args;
|
| 330 |
+
|
| 331 |
+
if (args->argc > 1)
|
| 332 |
+
{
|
| 333 |
+
ret = audin_sndio_parse_addin_args(sndio, args);
|
| 334 |
+
|
| 335 |
+
if (ret != CHANNEL_RC_OK)
|
| 336 |
+
{
|
| 337 |
+
WLog_ERR(TAG, "error parsing arguments");
|
| 338 |
+
goto error;
|
| 339 |
+
}
|
| 340 |
+
}
|
| 341 |
+
|
| 342 |
+
if ((ret = pEntryPoints->pRegisterAudinDevice(pEntryPoints->plugin, (IAudinDevice*)sndio)))
|
| 343 |
+
{
|
| 344 |
+
WLog_ERR(TAG, "RegisterAudinDevice failed with error %" PRIu32 "", ret);
|
| 345 |
+
goto error;
|
| 346 |
+
}
|
| 347 |
+
|
| 348 |
+
return ret;
|
| 349 |
+
error:
|
| 350 |
+
audin_sndio_free(&sndio->device);
|
| 351 |
+
return ret;
|
| 352 |
+
}
|
local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/winmm/CMakeLists.txt
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# FreeRDP: A Remote Desktop Protocol Implementation
|
| 2 |
+
# FreeRDP cmake build script
|
| 3 |
+
#
|
| 4 |
+
# Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
| 5 |
+
#
|
| 6 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 7 |
+
# you may not use this file except in compliance with the License.
|
| 8 |
+
# You may obtain a copy of the License at
|
| 9 |
+
#
|
| 10 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 11 |
+
#
|
| 12 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 13 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 14 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 15 |
+
# See the License for the specific language governing permissions and
|
| 16 |
+
# limitations under the License.
|
| 17 |
+
|
| 18 |
+
define_channel_client_subsystem("audin" "winmm" "")
|
| 19 |
+
|
| 20 |
+
set(${MODULE_PREFIX}_SRCS audin_winmm.c)
|
| 21 |
+
|
| 22 |
+
set(${MODULE_PREFIX}_LIBS winpr freerdp winmm.lib)
|
| 23 |
+
|
| 24 |
+
include_directories(..)
|
| 25 |
+
|
| 26 |
+
add_channel_client_subsystem_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} "" TRUE "")
|
local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/winmm/audin_winmm.c
ADDED
|
@@ -0,0 +1,566 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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l2013@126.com>
|
| 6 |
+
* Copyright 2015 Thincast Technologies GmbH
|
| 7 |
+
* Copyright 2015 DI (FH) Martin Haimberger <martin.haimberger@thincast.com>
|
| 8 |
+
*
|
| 9 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 10 |
+
* you may not use this file except in compliance with the License.
|
| 11 |
+
* You may obtain a copy of the License at
|
| 12 |
+
*
|
| 13 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 14 |
+
*
|
| 15 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 16 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 17 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 18 |
+
* See the License for the specific language governing permissions and
|
| 19 |
+
* limitations under the License.
|
| 20 |
+
*/
|
| 21 |
+
|
| 22 |
+
#include <freerdp/config.h>
|
| 23 |
+
|
| 24 |
+
#include <stdio.h>
|
| 25 |
+
#include <stdlib.h>
|
| 26 |
+
#include <string.h>
|
| 27 |
+
|
| 28 |
+
#include <windows.h>
|
| 29 |
+
#include <mmsystem.h>
|
| 30 |
+
|
| 31 |
+
#include <winpr/crt.h>
|
| 32 |
+
#include <winpr/wtsapi.h>
|
| 33 |
+
#include <winpr/cmdline.h>
|
| 34 |
+
#include <freerdp/freerdp.h>
|
| 35 |
+
#include <freerdp/addin.h>
|
| 36 |
+
#include <freerdp/client/audin.h>
|
| 37 |
+
|
| 38 |
+
#include "audin_main.h"
|
| 39 |
+
|
| 40 |
+
/* fix missing definitions in mingw */
|
| 41 |
+
#ifndef WAVE_MAPPED_DEFAULT_COMMUNICATION_DEVICE
|
| 42 |
+
#define WAVE_MAPPED_DEFAULT_COMMUNICATION_DEVICE 0x0010
|
| 43 |
+
#endif
|
| 44 |
+
|
| 45 |
+
typedef struct
|
| 46 |
+
{
|
| 47 |
+
IAudinDevice iface;
|
| 48 |
+
|
| 49 |
+
char* device_name;
|
| 50 |
+
AudinReceive receive;
|
| 51 |
+
void* user_data;
|
| 52 |
+
HANDLE thread;
|
| 53 |
+
HANDLE stopEvent;
|
| 54 |
+
HWAVEIN hWaveIn;
|
| 55 |
+
PWAVEFORMATEX* ppwfx;
|
| 56 |
+
PWAVEFORMATEX pwfx_cur;
|
| 57 |
+
UINT32 ppwfx_size;
|
| 58 |
+
UINT32 cFormats;
|
| 59 |
+
UINT32 frames_per_packet;
|
| 60 |
+
rdpContext* rdpcontext;
|
| 61 |
+
wLog* log;
|
| 62 |
+
} AudinWinmmDevice;
|
| 63 |
+
|
| 64 |
+
static void CALLBACK waveInProc(HWAVEIN hWaveIn, UINT uMsg, DWORD_PTR dwInstance,
|
| 65 |
+
DWORD_PTR dwParam1, DWORD_PTR dwParam2)
|
| 66 |
+
{
|
| 67 |
+
AudinWinmmDevice* winmm = (AudinWinmmDevice*)dwInstance;
|
| 68 |
+
PWAVEHDR pWaveHdr;
|
| 69 |
+
UINT error = CHANNEL_RC_OK;
|
| 70 |
+
MMRESULT mmResult;
|
| 71 |
+
|
| 72 |
+
switch (uMsg)
|
| 73 |
+
{
|
| 74 |
+
case WIM_CLOSE:
|
| 75 |
+
break;
|
| 76 |
+
|
| 77 |
+
case WIM_DATA:
|
| 78 |
+
pWaveHdr = (WAVEHDR*)dwParam1;
|
| 79 |
+
|
| 80 |
+
if (WHDR_DONE == (WHDR_DONE & pWaveHdr->dwFlags))
|
| 81 |
+
{
|
| 82 |
+
if (pWaveHdr->dwBytesRecorded &&
|
| 83 |
+
!(WaitForSingleObject(winmm->stopEvent, 0) == WAIT_OBJECT_0))
|
| 84 |
+
{
|
| 85 |
+
AUDIO_FORMAT format;
|
| 86 |
+
format.cbSize = winmm->pwfx_cur->cbSize;
|
| 87 |
+
format.nBlockAlign = winmm->pwfx_cur->nBlockAlign;
|
| 88 |
+
format.nAvgBytesPerSec = winmm->pwfx_cur->nAvgBytesPerSec;
|
| 89 |
+
format.nChannels = winmm->pwfx_cur->nChannels;
|
| 90 |
+
format.nSamplesPerSec = winmm->pwfx_cur->nSamplesPerSec;
|
| 91 |
+
format.wBitsPerSample = winmm->pwfx_cur->wBitsPerSample;
|
| 92 |
+
format.wFormatTag = winmm->pwfx_cur->wFormatTag;
|
| 93 |
+
|
| 94 |
+
if ((error = winmm->receive(&format, pWaveHdr->lpData,
|
| 95 |
+
pWaveHdr->dwBytesRecorded, winmm->user_data)))
|
| 96 |
+
break;
|
| 97 |
+
|
| 98 |
+
mmResult = waveInAddBuffer(hWaveIn, pWaveHdr, sizeof(WAVEHDR));
|
| 99 |
+
|
| 100 |
+
if (mmResult != MMSYSERR_NOERROR)
|
| 101 |
+
error = ERROR_INTERNAL_ERROR;
|
| 102 |
+
}
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
break;
|
| 106 |
+
|
| 107 |
+
case WIM_OPEN:
|
| 108 |
+
break;
|
| 109 |
+
|
| 110 |
+
default:
|
| 111 |
+
break;
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
if (error && winmm->rdpcontext)
|
| 115 |
+
setChannelError(winmm->rdpcontext, error, "waveInProc reported an error");
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
static BOOL log_mmresult(AudinWinmmDevice* winmm, const char* what, MMRESULT result)
|
| 119 |
+
{
|
| 120 |
+
if (result != MMSYSERR_NOERROR)
|
| 121 |
+
{
|
| 122 |
+
CHAR buffer[8192] = { 0 };
|
| 123 |
+
CHAR msg[8192] = { 0 };
|
| 124 |
+
CHAR cmsg[8192] = { 0 };
|
| 125 |
+
waveInGetErrorTextA(result, buffer, sizeof(buffer));
|
| 126 |
+
|
| 127 |
+
_snprintf(msg, sizeof(msg) - 1, "%s failed. %" PRIu32 " [%s]", what, result, buffer);
|
| 128 |
+
_snprintf(cmsg, sizeof(cmsg) - 1, "audin_winmm_thread_func reported an error '%s'", msg);
|
| 129 |
+
WLog_Print(winmm->log, WLOG_DEBUG, "%s", msg);
|
| 130 |
+
if (winmm->rdpcontext)
|
| 131 |
+
setChannelError(winmm->rdpcontext, ERROR_INTERNAL_ERROR, cmsg);
|
| 132 |
+
return FALSE;
|
| 133 |
+
}
|
| 134 |
+
return TRUE;
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
static BOOL test_format_supported(const PWAVEFORMATEX pwfx)
|
| 138 |
+
{
|
| 139 |
+
MMRESULT rc;
|
| 140 |
+
WAVEINCAPSA caps = { 0 };
|
| 141 |
+
|
| 142 |
+
rc = waveInGetDevCapsA(WAVE_MAPPER, &caps, sizeof(caps));
|
| 143 |
+
if (rc != MMSYSERR_NOERROR)
|
| 144 |
+
return FALSE;
|
| 145 |
+
|
| 146 |
+
switch (pwfx->nChannels)
|
| 147 |
+
{
|
| 148 |
+
case 1:
|
| 149 |
+
if ((caps.dwFormats &
|
| 150 |
+
(WAVE_FORMAT_1M08 | WAVE_FORMAT_2M08 | WAVE_FORMAT_4M08 | WAVE_FORMAT_96M08 |
|
| 151 |
+
WAVE_FORMAT_1M16 | WAVE_FORMAT_2M16 | WAVE_FORMAT_4M16 | WAVE_FORMAT_96M16)) == 0)
|
| 152 |
+
return FALSE;
|
| 153 |
+
break;
|
| 154 |
+
case 2:
|
| 155 |
+
if ((caps.dwFormats &
|
| 156 |
+
(WAVE_FORMAT_1S08 | WAVE_FORMAT_2S08 | WAVE_FORMAT_4S08 | WAVE_FORMAT_96S08 |
|
| 157 |
+
WAVE_FORMAT_1S16 | WAVE_FORMAT_2S16 | WAVE_FORMAT_4S16 | WAVE_FORMAT_96S16)) == 0)
|
| 158 |
+
return FALSE;
|
| 159 |
+
break;
|
| 160 |
+
default:
|
| 161 |
+
return FALSE;
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
rc = waveInOpen(NULL, WAVE_MAPPER, pwfx, 0, 0,
|
| 165 |
+
WAVE_FORMAT_QUERY | WAVE_MAPPED_DEFAULT_COMMUNICATION_DEVICE);
|
| 166 |
+
return (rc == MMSYSERR_NOERROR);
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
static DWORD WINAPI audin_winmm_thread_func(LPVOID arg)
|
| 170 |
+
{
|
| 171 |
+
AudinWinmmDevice* winmm = (AudinWinmmDevice*)arg;
|
| 172 |
+
char* buffer = NULL;
|
| 173 |
+
int size = 0;
|
| 174 |
+
WAVEHDR waveHdr[4] = { 0 };
|
| 175 |
+
DWORD status = 0;
|
| 176 |
+
MMRESULT rc = 0;
|
| 177 |
+
|
| 178 |
+
if (!winmm->hWaveIn)
|
| 179 |
+
{
|
| 180 |
+
rc = waveInOpen(&winmm->hWaveIn, WAVE_MAPPER, winmm->pwfx_cur, (DWORD_PTR)waveInProc,
|
| 181 |
+
(DWORD_PTR)winmm,
|
| 182 |
+
CALLBACK_FUNCTION | WAVE_MAPPED_DEFAULT_COMMUNICATION_DEVICE);
|
| 183 |
+
if (!log_mmresult(winmm, "waveInOpen", rc))
|
| 184 |
+
return ERROR_INTERNAL_ERROR;
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
size =
|
| 188 |
+
(winmm->pwfx_cur->wBitsPerSample * winmm->pwfx_cur->nChannels * winmm->frames_per_packet +
|
| 189 |
+
7) /
|
| 190 |
+
8;
|
| 191 |
+
|
| 192 |
+
for (int i = 0; i < 4; i++)
|
| 193 |
+
{
|
| 194 |
+
buffer = (char*)malloc(size);
|
| 195 |
+
|
| 196 |
+
if (!buffer)
|
| 197 |
+
return CHANNEL_RC_NO_MEMORY;
|
| 198 |
+
|
| 199 |
+
waveHdr[i].dwBufferLength = size;
|
| 200 |
+
waveHdr[i].dwFlags = 0;
|
| 201 |
+
waveHdr[i].lpData = buffer;
|
| 202 |
+
rc = waveInPrepareHeader(winmm->hWaveIn, &waveHdr[i], sizeof(waveHdr[i]));
|
| 203 |
+
|
| 204 |
+
if (!log_mmresult(winmm, "waveInPrepareHeader", rc))
|
| 205 |
+
{
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
rc = waveInAddBuffer(winmm->hWaveIn, &waveHdr[i], sizeof(waveHdr[i]));
|
| 209 |
+
|
| 210 |
+
if (!log_mmresult(winmm, "waveInAddBuffer", rc))
|
| 211 |
+
{
|
| 212 |
+
}
|
| 213 |
+
}
|
| 214 |
+
|
| 215 |
+
rc = waveInStart(winmm->hWaveIn);
|
| 216 |
+
|
| 217 |
+
if (!log_mmresult(winmm, "waveInStart", rc))
|
| 218 |
+
{
|
| 219 |
+
}
|
| 220 |
+
|
| 221 |
+
status = WaitForSingleObject(winmm->stopEvent, INFINITE);
|
| 222 |
+
|
| 223 |
+
if (status == WAIT_FAILED)
|
| 224 |
+
{
|
| 225 |
+
WLog_Print(winmm->log, WLOG_DEBUG, "WaitForSingleObject failed.");
|
| 226 |
+
|
| 227 |
+
if (winmm->rdpcontext)
|
| 228 |
+
setChannelError(winmm->rdpcontext, ERROR_INTERNAL_ERROR,
|
| 229 |
+
"audin_winmm_thread_func reported an error");
|
| 230 |
+
}
|
| 231 |
+
|
| 232 |
+
rc = waveInReset(winmm->hWaveIn);
|
| 233 |
+
|
| 234 |
+
if (!log_mmresult(winmm, "waveInReset", rc))
|
| 235 |
+
{
|
| 236 |
+
}
|
| 237 |
+
|
| 238 |
+
for (int i = 0; i < 4; i++)
|
| 239 |
+
{
|
| 240 |
+
rc = waveInUnprepareHeader(winmm->hWaveIn, &waveHdr[i], sizeof(waveHdr[i]));
|
| 241 |
+
|
| 242 |
+
if (!log_mmresult(winmm, "waveInUnprepareHeader", rc))
|
| 243 |
+
{
|
| 244 |
+
}
|
| 245 |
+
|
| 246 |
+
free(waveHdr[i].lpData);
|
| 247 |
+
}
|
| 248 |
+
|
| 249 |
+
rc = waveInClose(winmm->hWaveIn);
|
| 250 |
+
|
| 251 |
+
if (!log_mmresult(winmm, "waveInClose", rc))
|
| 252 |
+
{
|
| 253 |
+
}
|
| 254 |
+
|
| 255 |
+
winmm->hWaveIn = NULL;
|
| 256 |
+
return 0;
|
| 257 |
+
}
|
| 258 |
+
|
| 259 |
+
/**
|
| 260 |
+
* Function description
|
| 261 |
+
*
|
| 262 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 263 |
+
*/
|
| 264 |
+
static UINT audin_winmm_free(IAudinDevice* device)
|
| 265 |
+
{
|
| 266 |
+
AudinWinmmDevice* winmm = (AudinWinmmDevice*)device;
|
| 267 |
+
|
| 268 |
+
if (!winmm)
|
| 269 |
+
return ERROR_INVALID_PARAMETER;
|
| 270 |
+
|
| 271 |
+
for (UINT32 i = 0; i < winmm->cFormats; i++)
|
| 272 |
+
{
|
| 273 |
+
free(winmm->ppwfx[i]);
|
| 274 |
+
}
|
| 275 |
+
|
| 276 |
+
free(winmm->ppwfx);
|
| 277 |
+
free(winmm->device_name);
|
| 278 |
+
free(winmm);
|
| 279 |
+
return CHANNEL_RC_OK;
|
| 280 |
+
}
|
| 281 |
+
|
| 282 |
+
/**
|
| 283 |
+
* Function description
|
| 284 |
+
*
|
| 285 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 286 |
+
*/
|
| 287 |
+
static UINT audin_winmm_close(IAudinDevice* device)
|
| 288 |
+
{
|
| 289 |
+
DWORD status;
|
| 290 |
+
UINT error = CHANNEL_RC_OK;
|
| 291 |
+
AudinWinmmDevice* winmm = (AudinWinmmDevice*)device;
|
| 292 |
+
|
| 293 |
+
if (!winmm)
|
| 294 |
+
return ERROR_INVALID_PARAMETER;
|
| 295 |
+
|
| 296 |
+
(void)SetEvent(winmm->stopEvent);
|
| 297 |
+
status = WaitForSingleObject(winmm->thread, INFINITE);
|
| 298 |
+
|
| 299 |
+
if (status == WAIT_FAILED)
|
| 300 |
+
{
|
| 301 |
+
error = GetLastError();
|
| 302 |
+
WLog_Print(winmm->log, WLOG_ERROR, "WaitForSingleObject failed with error %" PRIu32 "!",
|
| 303 |
+
error);
|
| 304 |
+
return error;
|
| 305 |
+
}
|
| 306 |
+
|
| 307 |
+
(void)CloseHandle(winmm->thread);
|
| 308 |
+
(void)CloseHandle(winmm->stopEvent);
|
| 309 |
+
winmm->thread = NULL;
|
| 310 |
+
winmm->stopEvent = NULL;
|
| 311 |
+
winmm->receive = NULL;
|
| 312 |
+
winmm->user_data = NULL;
|
| 313 |
+
return error;
|
| 314 |
+
}
|
| 315 |
+
|
| 316 |
+
/**
|
| 317 |
+
* Function description
|
| 318 |
+
*
|
| 319 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 320 |
+
*/
|
| 321 |
+
static UINT audin_winmm_set_format(IAudinDevice* device, const AUDIO_FORMAT* format,
|
| 322 |
+
UINT32 FramesPerPacket)
|
| 323 |
+
{
|
| 324 |
+
AudinWinmmDevice* winmm = (AudinWinmmDevice*)device;
|
| 325 |
+
|
| 326 |
+
if (!winmm || !format)
|
| 327 |
+
return ERROR_INVALID_PARAMETER;
|
| 328 |
+
|
| 329 |
+
winmm->frames_per_packet = FramesPerPacket;
|
| 330 |
+
|
| 331 |
+
for (UINT32 i = 0; i < winmm->cFormats; i++)
|
| 332 |
+
{
|
| 333 |
+
const PWAVEFORMATEX ppwfx = winmm->ppwfx[i];
|
| 334 |
+
if ((ppwfx->wFormatTag == format->wFormatTag) && (ppwfx->nChannels == format->nChannels) &&
|
| 335 |
+
(ppwfx->wBitsPerSample == format->wBitsPerSample) &&
|
| 336 |
+
(ppwfx->nSamplesPerSec == format->nSamplesPerSec))
|
| 337 |
+
{
|
| 338 |
+
/* BUG: Many devices report to support stereo recording but fail here.
|
| 339 |
+
* Ensure we always use mono. */
|
| 340 |
+
if (ppwfx->nChannels > 1)
|
| 341 |
+
{
|
| 342 |
+
ppwfx->nChannels = 1;
|
| 343 |
+
}
|
| 344 |
+
|
| 345 |
+
if (ppwfx->nBlockAlign != 2)
|
| 346 |
+
{
|
| 347 |
+
ppwfx->nBlockAlign = 2;
|
| 348 |
+
ppwfx->nAvgBytesPerSec = ppwfx->nSamplesPerSec * ppwfx->nBlockAlign;
|
| 349 |
+
}
|
| 350 |
+
|
| 351 |
+
if (!test_format_supported(ppwfx))
|
| 352 |
+
return ERROR_INVALID_PARAMETER;
|
| 353 |
+
winmm->pwfx_cur = ppwfx;
|
| 354 |
+
return CHANNEL_RC_OK;
|
| 355 |
+
}
|
| 356 |
+
}
|
| 357 |
+
|
| 358 |
+
return ERROR_INVALID_PARAMETER;
|
| 359 |
+
}
|
| 360 |
+
|
| 361 |
+
static BOOL audin_winmm_format_supported(IAudinDevice* device, const AUDIO_FORMAT* format)
|
| 362 |
+
{
|
| 363 |
+
AudinWinmmDevice* winmm = (AudinWinmmDevice*)device;
|
| 364 |
+
PWAVEFORMATEX pwfx;
|
| 365 |
+
BYTE* data;
|
| 366 |
+
|
| 367 |
+
if (!winmm || !format)
|
| 368 |
+
return FALSE;
|
| 369 |
+
|
| 370 |
+
if (format->wFormatTag != WAVE_FORMAT_PCM)
|
| 371 |
+
return FALSE;
|
| 372 |
+
|
| 373 |
+
if (format->nChannels != 1)
|
| 374 |
+
return FALSE;
|
| 375 |
+
|
| 376 |
+
pwfx = (PWAVEFORMATEX)malloc(sizeof(WAVEFORMATEX) + format->cbSize);
|
| 377 |
+
|
| 378 |
+
if (!pwfx)
|
| 379 |
+
return FALSE;
|
| 380 |
+
|
| 381 |
+
pwfx->cbSize = format->cbSize;
|
| 382 |
+
pwfx->wFormatTag = format->wFormatTag;
|
| 383 |
+
pwfx->nChannels = format->nChannels;
|
| 384 |
+
pwfx->nSamplesPerSec = format->nSamplesPerSec;
|
| 385 |
+
pwfx->nBlockAlign = format->nBlockAlign;
|
| 386 |
+
pwfx->wBitsPerSample = format->wBitsPerSample;
|
| 387 |
+
data = (BYTE*)pwfx + sizeof(WAVEFORMATEX);
|
| 388 |
+
memcpy(data, format->data, format->cbSize);
|
| 389 |
+
|
| 390 |
+
pwfx->nAvgBytesPerSec = pwfx->nSamplesPerSec * pwfx->nBlockAlign;
|
| 391 |
+
|
| 392 |
+
if (!test_format_supported(pwfx))
|
| 393 |
+
goto fail;
|
| 394 |
+
|
| 395 |
+
if (winmm->cFormats >= winmm->ppwfx_size)
|
| 396 |
+
{
|
| 397 |
+
PWAVEFORMATEX* tmp_ppwfx;
|
| 398 |
+
tmp_ppwfx = realloc(winmm->ppwfx, sizeof(PWAVEFORMATEX) * winmm->ppwfx_size * 2);
|
| 399 |
+
|
| 400 |
+
if (!tmp_ppwfx)
|
| 401 |
+
goto fail;
|
| 402 |
+
|
| 403 |
+
winmm->ppwfx_size *= 2;
|
| 404 |
+
winmm->ppwfx = tmp_ppwfx;
|
| 405 |
+
}
|
| 406 |
+
|
| 407 |
+
winmm->ppwfx[winmm->cFormats++] = pwfx;
|
| 408 |
+
return TRUE;
|
| 409 |
+
|
| 410 |
+
fail:
|
| 411 |
+
free(pwfx);
|
| 412 |
+
return FALSE;
|
| 413 |
+
}
|
| 414 |
+
|
| 415 |
+
/**
|
| 416 |
+
* Function description
|
| 417 |
+
*
|
| 418 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 419 |
+
*/
|
| 420 |
+
static UINT audin_winmm_open(IAudinDevice* device, AudinReceive receive, void* user_data)
|
| 421 |
+
{
|
| 422 |
+
AudinWinmmDevice* winmm = (AudinWinmmDevice*)device;
|
| 423 |
+
|
| 424 |
+
if (!winmm || !receive || !user_data)
|
| 425 |
+
return ERROR_INVALID_PARAMETER;
|
| 426 |
+
|
| 427 |
+
winmm->receive = receive;
|
| 428 |
+
winmm->user_data = user_data;
|
| 429 |
+
|
| 430 |
+
if (!(winmm->stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL)))
|
| 431 |
+
{
|
| 432 |
+
WLog_Print(winmm->log, WLOG_ERROR, "CreateEvent failed!");
|
| 433 |
+
return ERROR_INTERNAL_ERROR;
|
| 434 |
+
}
|
| 435 |
+
|
| 436 |
+
if (!(winmm->thread = CreateThread(NULL, 0, audin_winmm_thread_func, winmm, 0, NULL)))
|
| 437 |
+
{
|
| 438 |
+
WLog_Print(winmm->log, WLOG_ERROR, "CreateThread failed!");
|
| 439 |
+
(void)CloseHandle(winmm->stopEvent);
|
| 440 |
+
winmm->stopEvent = NULL;
|
| 441 |
+
return ERROR_INTERNAL_ERROR;
|
| 442 |
+
}
|
| 443 |
+
|
| 444 |
+
return CHANNEL_RC_OK;
|
| 445 |
+
}
|
| 446 |
+
|
| 447 |
+
/**
|
| 448 |
+
* Function description
|
| 449 |
+
*
|
| 450 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 451 |
+
*/
|
| 452 |
+
static UINT audin_winmm_parse_addin_args(AudinWinmmDevice* device, const ADDIN_ARGV* args)
|
| 453 |
+
{
|
| 454 |
+
int status;
|
| 455 |
+
DWORD flags;
|
| 456 |
+
const COMMAND_LINE_ARGUMENT_A* arg;
|
| 457 |
+
AudinWinmmDevice* winmm = (AudinWinmmDevice*)device;
|
| 458 |
+
COMMAND_LINE_ARGUMENT_A audin_winmm_args[] = { { "dev", COMMAND_LINE_VALUE_REQUIRED, "<device>",
|
| 459 |
+
NULL, NULL, -1, NULL, "audio device name" },
|
| 460 |
+
{ NULL, 0, NULL, NULL, NULL, -1, NULL, NULL } };
|
| 461 |
+
|
| 462 |
+
flags =
|
| 463 |
+
COMMAND_LINE_SIGIL_NONE | COMMAND_LINE_SEPARATOR_COLON | COMMAND_LINE_IGN_UNKNOWN_KEYWORD;
|
| 464 |
+
status = CommandLineParseArgumentsA(args->argc, args->argv, audin_winmm_args, flags, winmm,
|
| 465 |
+
NULL, NULL);
|
| 466 |
+
arg = audin_winmm_args;
|
| 467 |
+
|
| 468 |
+
do
|
| 469 |
+
{
|
| 470 |
+
if (!(arg->Flags & COMMAND_LINE_VALUE_PRESENT))
|
| 471 |
+
continue;
|
| 472 |
+
|
| 473 |
+
CommandLineSwitchStart(arg) CommandLineSwitchCase(arg, "dev")
|
| 474 |
+
{
|
| 475 |
+
winmm->device_name = _strdup(arg->Value);
|
| 476 |
+
|
| 477 |
+
if (!winmm->device_name)
|
| 478 |
+
{
|
| 479 |
+
WLog_Print(winmm->log, WLOG_ERROR, "_strdup failed!");
|
| 480 |
+
return CHANNEL_RC_NO_MEMORY;
|
| 481 |
+
}
|
| 482 |
+
}
|
| 483 |
+
CommandLineSwitchEnd(arg)
|
| 484 |
+
} while ((arg = CommandLineFindNextArgumentA(arg)) != NULL);
|
| 485 |
+
|
| 486 |
+
return CHANNEL_RC_OK;
|
| 487 |
+
}
|
| 488 |
+
|
| 489 |
+
/**
|
| 490 |
+
* Function description
|
| 491 |
+
*
|
| 492 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 493 |
+
*/
|
| 494 |
+
FREERDP_ENTRY_POINT(UINT VCAPITYPE winmm_freerdp_audin_client_subsystem_entry(
|
| 495 |
+
PFREERDP_AUDIN_DEVICE_ENTRY_POINTS pEntryPoints))
|
| 496 |
+
{
|
| 497 |
+
const ADDIN_ARGV* args;
|
| 498 |
+
AudinWinmmDevice* winmm;
|
| 499 |
+
UINT error;
|
| 500 |
+
|
| 501 |
+
if (waveInGetNumDevs() == 0)
|
| 502 |
+
{
|
| 503 |
+
WLog_Print(WLog_Get(TAG), WLOG_ERROR, "No microphone available!");
|
| 504 |
+
return ERROR_DEVICE_NOT_AVAILABLE;
|
| 505 |
+
}
|
| 506 |
+
|
| 507 |
+
winmm = (AudinWinmmDevice*)calloc(1, sizeof(AudinWinmmDevice));
|
| 508 |
+
|
| 509 |
+
if (!winmm)
|
| 510 |
+
{
|
| 511 |
+
WLog_ERR(TAG, "calloc failed!");
|
| 512 |
+
return CHANNEL_RC_NO_MEMORY;
|
| 513 |
+
}
|
| 514 |
+
|
| 515 |
+
winmm->log = WLog_Get(TAG);
|
| 516 |
+
winmm->iface.Open = audin_winmm_open;
|
| 517 |
+
winmm->iface.FormatSupported = audin_winmm_format_supported;
|
| 518 |
+
winmm->iface.SetFormat = audin_winmm_set_format;
|
| 519 |
+
winmm->iface.Close = audin_winmm_close;
|
| 520 |
+
winmm->iface.Free = audin_winmm_free;
|
| 521 |
+
winmm->rdpcontext = pEntryPoints->rdpcontext;
|
| 522 |
+
args = pEntryPoints->args;
|
| 523 |
+
|
| 524 |
+
if ((error = audin_winmm_parse_addin_args(winmm, args)))
|
| 525 |
+
{
|
| 526 |
+
WLog_Print(winmm->log, WLOG_ERROR,
|
| 527 |
+
"audin_winmm_parse_addin_args failed with error %" PRIu32 "!", error);
|
| 528 |
+
goto error_out;
|
| 529 |
+
}
|
| 530 |
+
|
| 531 |
+
if (!winmm->device_name)
|
| 532 |
+
{
|
| 533 |
+
winmm->device_name = _strdup("default");
|
| 534 |
+
|
| 535 |
+
if (!winmm->device_name)
|
| 536 |
+
{
|
| 537 |
+
WLog_Print(winmm->log, WLOG_ERROR, "_strdup failed!");
|
| 538 |
+
error = CHANNEL_RC_NO_MEMORY;
|
| 539 |
+
goto error_out;
|
| 540 |
+
}
|
| 541 |
+
}
|
| 542 |
+
|
| 543 |
+
winmm->ppwfx_size = 10;
|
| 544 |
+
winmm->ppwfx = calloc(winmm->ppwfx_size, sizeof(PWAVEFORMATEX));
|
| 545 |
+
|
| 546 |
+
if (!winmm->ppwfx)
|
| 547 |
+
{
|
| 548 |
+
WLog_Print(winmm->log, WLOG_ERROR, "malloc failed!");
|
| 549 |
+
error = CHANNEL_RC_NO_MEMORY;
|
| 550 |
+
goto error_out;
|
| 551 |
+
}
|
| 552 |
+
|
| 553 |
+
if ((error = pEntryPoints->pRegisterAudinDevice(pEntryPoints->plugin, &winmm->iface)))
|
| 554 |
+
{
|
| 555 |
+
WLog_Print(winmm->log, WLOG_ERROR, "RegisterAudinDevice failed with error %" PRIu32 "!",
|
| 556 |
+
error);
|
| 557 |
+
goto error_out;
|
| 558 |
+
}
|
| 559 |
+
|
| 560 |
+
return CHANNEL_RC_OK;
|
| 561 |
+
error_out:
|
| 562 |
+
free(winmm->ppwfx);
|
| 563 |
+
free(winmm->device_name);
|
| 564 |
+
free(winmm);
|
| 565 |
+
return error;
|
| 566 |
+
}
|
local-test-freerdp-delta-01/afc-freerdp/channels/audin/server/CMakeLists.txt
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# FreeRDP: A Remote Desktop Protocol Implementation
|
| 2 |
+
# FreeRDP cmake build script
|
| 3 |
+
#
|
| 4 |
+
# Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
| 5 |
+
#
|
| 6 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 7 |
+
# you may not use this file except in compliance with the License.
|
| 8 |
+
# You may obtain a copy of the License at
|
| 9 |
+
#
|
| 10 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 11 |
+
#
|
| 12 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 13 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 14 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 15 |
+
# See the License for the specific language governing permissions and
|
| 16 |
+
# limitations under the License.
|
| 17 |
+
|
| 18 |
+
define_channel_server("audin")
|
| 19 |
+
|
| 20 |
+
set(${MODULE_PREFIX}_SRCS audin.c)
|
| 21 |
+
|
| 22 |
+
set(${MODULE_PREFIX}_LIBS freerdp)
|
| 23 |
+
add_channel_server_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} FALSE "DVCPluginEntry")
|
local-test-freerdp-delta-01/afc-freerdp/channels/audin/server/audin.c
ADDED
|
@@ -0,0 +1,913 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* FreeRDP: A Remote Desktop Protocol Implementation
|
| 3 |
+
* Server Audio Input Virtual Channel
|
| 4 |
+
*
|
| 5 |
+
* Copyright 2012 Vic Lee
|
| 6 |
+
* Copyright 2015 Thincast Technologies GmbH
|
| 7 |
+
* Copyright 2015 DI (FH) Martin Haimberger <martin.haimberger@thincast.com>
|
| 8 |
+
* Copyright 2022 Pascal Nowack <Pascal.Nowack@gmx.de>
|
| 9 |
+
*
|
| 10 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 11 |
+
* you may not use this file except in compliance with the License.
|
| 12 |
+
* You may obtain a copy of the License at
|
| 13 |
+
*
|
| 14 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 15 |
+
*
|
| 16 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 17 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 18 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 19 |
+
* See the License for the specific language governing permissions and
|
| 20 |
+
* limitations under the License.
|
| 21 |
+
*/
|
| 22 |
+
|
| 23 |
+
#include <freerdp/config.h>
|
| 24 |
+
|
| 25 |
+
#include <winpr/crt.h>
|
| 26 |
+
#include <winpr/assert.h>
|
| 27 |
+
#include <winpr/synch.h>
|
| 28 |
+
#include <winpr/thread.h>
|
| 29 |
+
#include <winpr/stream.h>
|
| 30 |
+
|
| 31 |
+
#include <freerdp/freerdp.h>
|
| 32 |
+
#include <freerdp/server/server-common.h>
|
| 33 |
+
#include <freerdp/server/audin.h>
|
| 34 |
+
#include <freerdp/channels/log.h>
|
| 35 |
+
|
| 36 |
+
#define AUDIN_TAG CHANNELS_TAG("audin.server")
|
| 37 |
+
|
| 38 |
+
#define SNDIN_HEADER_SIZE 1
|
| 39 |
+
|
| 40 |
+
typedef enum
|
| 41 |
+
{
|
| 42 |
+
MSG_SNDIN_VERSION = 0x01,
|
| 43 |
+
MSG_SNDIN_FORMATS = 0x02,
|
| 44 |
+
MSG_SNDIN_OPEN = 0x03,
|
| 45 |
+
MSG_SNDIN_OPEN_REPLY = 0x04,
|
| 46 |
+
MSG_SNDIN_DATA_INCOMING = 0x05,
|
| 47 |
+
MSG_SNDIN_DATA = 0x06,
|
| 48 |
+
MSG_SNDIN_FORMATCHANGE = 0x07,
|
| 49 |
+
} MSG_SNDIN;
|
| 50 |
+
|
| 51 |
+
typedef struct
|
| 52 |
+
{
|
| 53 |
+
audin_server_context context;
|
| 54 |
+
|
| 55 |
+
HANDLE stopEvent;
|
| 56 |
+
|
| 57 |
+
HANDLE thread;
|
| 58 |
+
void* audin_channel;
|
| 59 |
+
|
| 60 |
+
DWORD SessionId;
|
| 61 |
+
|
| 62 |
+
AUDIO_FORMAT* audin_server_formats;
|
| 63 |
+
UINT32 audin_n_server_formats;
|
| 64 |
+
AUDIO_FORMAT* audin_negotiated_format;
|
| 65 |
+
UINT32 audin_client_format_idx;
|
| 66 |
+
wLog* log;
|
| 67 |
+
} audin_server;
|
| 68 |
+
|
| 69 |
+
static UINT audin_server_recv_version(audin_server_context* context, wStream* s,
|
| 70 |
+
const SNDIN_PDU* header)
|
| 71 |
+
{
|
| 72 |
+
audin_server* audin = (audin_server*)context;
|
| 73 |
+
SNDIN_VERSION pdu = { 0 };
|
| 74 |
+
UINT error = CHANNEL_RC_OK;
|
| 75 |
+
|
| 76 |
+
WINPR_ASSERT(context);
|
| 77 |
+
WINPR_ASSERT(header);
|
| 78 |
+
|
| 79 |
+
pdu.Header = *header;
|
| 80 |
+
|
| 81 |
+
if (!Stream_CheckAndLogRequiredLengthWLog(audin->log, s, 4))
|
| 82 |
+
return ERROR_NO_DATA;
|
| 83 |
+
|
| 84 |
+
Stream_Read_UINT32(s, pdu.Version);
|
| 85 |
+
|
| 86 |
+
IFCALLRET(context->ReceiveVersion, error, context, &pdu);
|
| 87 |
+
if (error)
|
| 88 |
+
WLog_Print(audin->log, WLOG_ERROR, "context->ReceiveVersion failed with error %" PRIu32 "",
|
| 89 |
+
error);
|
| 90 |
+
|
| 91 |
+
return error;
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
static UINT audin_server_recv_formats(audin_server_context* context, wStream* s,
|
| 95 |
+
const SNDIN_PDU* header)
|
| 96 |
+
{
|
| 97 |
+
audin_server* audin = (audin_server*)context;
|
| 98 |
+
SNDIN_FORMATS pdu = { 0 };
|
| 99 |
+
UINT error = CHANNEL_RC_OK;
|
| 100 |
+
|
| 101 |
+
WINPR_ASSERT(context);
|
| 102 |
+
WINPR_ASSERT(header);
|
| 103 |
+
|
| 104 |
+
pdu.Header = *header;
|
| 105 |
+
|
| 106 |
+
/* Implementations MUST, at a minimum, support WAVE_FORMAT_PCM (0x0001) */
|
| 107 |
+
if (!Stream_CheckAndLogRequiredLengthWLog(audin->log, s, 4 + 4 + 18))
|
| 108 |
+
return ERROR_NO_DATA;
|
| 109 |
+
|
| 110 |
+
Stream_Read_UINT32(s, pdu.NumFormats);
|
| 111 |
+
Stream_Read_UINT32(s, pdu.cbSizeFormatsPacket);
|
| 112 |
+
|
| 113 |
+
if (pdu.NumFormats == 0)
|
| 114 |
+
{
|
| 115 |
+
WLog_Print(audin->log, WLOG_ERROR, "Sound Formats PDU contains no formats");
|
| 116 |
+
return ERROR_INVALID_DATA;
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
pdu.SoundFormats = audio_formats_new(pdu.NumFormats);
|
| 120 |
+
if (!pdu.SoundFormats)
|
| 121 |
+
{
|
| 122 |
+
WLog_Print(audin->log, WLOG_ERROR, "Failed to allocate %u SoundFormats", pdu.NumFormats);
|
| 123 |
+
return ERROR_NOT_ENOUGH_MEMORY;
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
for (UINT32 i = 0; i < pdu.NumFormats; ++i)
|
| 127 |
+
{
|
| 128 |
+
AUDIO_FORMAT* format = &pdu.SoundFormats[i];
|
| 129 |
+
|
| 130 |
+
if (!audio_format_read(s, format))
|
| 131 |
+
{
|
| 132 |
+
WLog_Print(audin->log, WLOG_ERROR, "Failed to read audio format");
|
| 133 |
+
audio_formats_free(pdu.SoundFormats, i + i);
|
| 134 |
+
return ERROR_INVALID_DATA;
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
audio_format_print(audin->log, WLOG_DEBUG, format);
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
if (pdu.cbSizeFormatsPacket != Stream_GetPosition(s))
|
| 141 |
+
{
|
| 142 |
+
WLog_Print(audin->log, WLOG_WARN,
|
| 143 |
+
"cbSizeFormatsPacket is invalid! Expected: %u Got: %zu. Fixing size",
|
| 144 |
+
pdu.cbSizeFormatsPacket, Stream_GetPosition(s));
|
| 145 |
+
const size_t pos = Stream_GetPosition(s);
|
| 146 |
+
if (pos > UINT32_MAX)
|
| 147 |
+
{
|
| 148 |
+
WLog_Print(audin->log, WLOG_ERROR, "Stream too long, %" PRIuz " exceeds UINT32_MAX",
|
| 149 |
+
pos);
|
| 150 |
+
error = ERROR_INVALID_PARAMETER;
|
| 151 |
+
goto fail;
|
| 152 |
+
}
|
| 153 |
+
pdu.cbSizeFormatsPacket = (UINT32)pos;
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
pdu.ExtraDataSize = Stream_GetRemainingLength(s);
|
| 157 |
+
|
| 158 |
+
IFCALLRET(context->ReceiveFormats, error, context, &pdu);
|
| 159 |
+
if (error)
|
| 160 |
+
WLog_Print(audin->log, WLOG_ERROR, "context->ReceiveFormats failed with error %" PRIu32 "",
|
| 161 |
+
error);
|
| 162 |
+
|
| 163 |
+
fail:
|
| 164 |
+
audio_formats_free(pdu.SoundFormats, pdu.NumFormats);
|
| 165 |
+
|
| 166 |
+
return error;
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
static UINT audin_server_recv_open_reply(audin_server_context* context, wStream* s,
|
| 170 |
+
const SNDIN_PDU* header)
|
| 171 |
+
{
|
| 172 |
+
audin_server* audin = (audin_server*)context;
|
| 173 |
+
SNDIN_OPEN_REPLY pdu = { 0 };
|
| 174 |
+
UINT error = CHANNEL_RC_OK;
|
| 175 |
+
|
| 176 |
+
WINPR_ASSERT(context);
|
| 177 |
+
WINPR_ASSERT(header);
|
| 178 |
+
|
| 179 |
+
pdu.Header = *header;
|
| 180 |
+
|
| 181 |
+
if (!Stream_CheckAndLogRequiredLengthWLog(audin->log, s, 4))
|
| 182 |
+
return ERROR_NO_DATA;
|
| 183 |
+
|
| 184 |
+
Stream_Read_UINT32(s, pdu.Result);
|
| 185 |
+
|
| 186 |
+
IFCALLRET(context->OpenReply, error, context, &pdu);
|
| 187 |
+
if (error)
|
| 188 |
+
WLog_Print(audin->log, WLOG_ERROR, "context->OpenReply failed with error %" PRIu32 "",
|
| 189 |
+
error);
|
| 190 |
+
|
| 191 |
+
return error;
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
static UINT audin_server_recv_data_incoming(audin_server_context* context, wStream* s,
|
| 195 |
+
const SNDIN_PDU* header)
|
| 196 |
+
{
|
| 197 |
+
audin_server* audin = (audin_server*)context;
|
| 198 |
+
SNDIN_DATA_INCOMING pdu = { 0 };
|
| 199 |
+
UINT error = CHANNEL_RC_OK;
|
| 200 |
+
|
| 201 |
+
WINPR_ASSERT(context);
|
| 202 |
+
WINPR_ASSERT(header);
|
| 203 |
+
|
| 204 |
+
pdu.Header = *header;
|
| 205 |
+
|
| 206 |
+
IFCALLRET(context->IncomingData, error, context, &pdu);
|
| 207 |
+
if (error)
|
| 208 |
+
WLog_Print(audin->log, WLOG_ERROR, "context->IncomingData failed with error %" PRIu32 "",
|
| 209 |
+
error);
|
| 210 |
+
|
| 211 |
+
return error;
|
| 212 |
+
}
|
| 213 |
+
|
| 214 |
+
static UINT audin_server_recv_data(audin_server_context* context, wStream* s,
|
| 215 |
+
const SNDIN_PDU* header)
|
| 216 |
+
{
|
| 217 |
+
audin_server* audin = (audin_server*)context;
|
| 218 |
+
SNDIN_DATA pdu = { 0 };
|
| 219 |
+
wStream dataBuffer = { 0 };
|
| 220 |
+
UINT error = CHANNEL_RC_OK;
|
| 221 |
+
|
| 222 |
+
WINPR_ASSERT(context);
|
| 223 |
+
WINPR_ASSERT(header);
|
| 224 |
+
|
| 225 |
+
pdu.Header = *header;
|
| 226 |
+
|
| 227 |
+
pdu.Data = Stream_StaticInit(&dataBuffer, Stream_Pointer(s), Stream_GetRemainingLength(s));
|
| 228 |
+
|
| 229 |
+
IFCALLRET(context->Data, error, context, &pdu);
|
| 230 |
+
if (error)
|
| 231 |
+
WLog_Print(audin->log, WLOG_ERROR, "context->Data failed with error %" PRIu32 "", error);
|
| 232 |
+
|
| 233 |
+
return error;
|
| 234 |
+
}
|
| 235 |
+
|
| 236 |
+
static UINT audin_server_recv_format_change(audin_server_context* context, wStream* s,
|
| 237 |
+
const SNDIN_PDU* header)
|
| 238 |
+
{
|
| 239 |
+
audin_server* audin = (audin_server*)context;
|
| 240 |
+
SNDIN_FORMATCHANGE pdu = { 0 };
|
| 241 |
+
UINT error = CHANNEL_RC_OK;
|
| 242 |
+
|
| 243 |
+
WINPR_ASSERT(context);
|
| 244 |
+
WINPR_ASSERT(header);
|
| 245 |
+
|
| 246 |
+
pdu.Header = *header;
|
| 247 |
+
|
| 248 |
+
if (!Stream_CheckAndLogRequiredLengthWLog(audin->log, s, 4))
|
| 249 |
+
return ERROR_NO_DATA;
|
| 250 |
+
|
| 251 |
+
Stream_Read_UINT32(s, pdu.NewFormat);
|
| 252 |
+
|
| 253 |
+
IFCALLRET(context->ReceiveFormatChange, error, context, &pdu);
|
| 254 |
+
if (error)
|
| 255 |
+
WLog_Print(audin->log, WLOG_ERROR,
|
| 256 |
+
"context->ReceiveFormatChange failed with error %" PRIu32 "", error);
|
| 257 |
+
|
| 258 |
+
return error;
|
| 259 |
+
}
|
| 260 |
+
|
| 261 |
+
static DWORD WINAPI audin_server_thread_func(LPVOID arg)
|
| 262 |
+
{
|
| 263 |
+
wStream* s = NULL;
|
| 264 |
+
void* buffer = NULL;
|
| 265 |
+
DWORD nCount = 0;
|
| 266 |
+
HANDLE events[8] = { 0 };
|
| 267 |
+
BOOL ready = FALSE;
|
| 268 |
+
HANDLE ChannelEvent = NULL;
|
| 269 |
+
DWORD BytesReturned = 0;
|
| 270 |
+
audin_server* audin = (audin_server*)arg;
|
| 271 |
+
UINT error = CHANNEL_RC_OK;
|
| 272 |
+
DWORD status = ERROR_INTERNAL_ERROR;
|
| 273 |
+
|
| 274 |
+
WINPR_ASSERT(audin);
|
| 275 |
+
|
| 276 |
+
if (WTSVirtualChannelQuery(audin->audin_channel, WTSVirtualEventHandle, &buffer,
|
| 277 |
+
&BytesReturned) == TRUE)
|
| 278 |
+
{
|
| 279 |
+
if (BytesReturned == sizeof(HANDLE))
|
| 280 |
+
ChannelEvent = *(HANDLE*)buffer;
|
| 281 |
+
|
| 282 |
+
WTSFreeMemory(buffer);
|
| 283 |
+
}
|
| 284 |
+
else
|
| 285 |
+
{
|
| 286 |
+
WLog_Print(audin->log, WLOG_ERROR, "WTSVirtualChannelQuery failed");
|
| 287 |
+
error = ERROR_INTERNAL_ERROR;
|
| 288 |
+
goto out;
|
| 289 |
+
}
|
| 290 |
+
|
| 291 |
+
nCount = 0;
|
| 292 |
+
events[nCount++] = audin->stopEvent;
|
| 293 |
+
events[nCount++] = ChannelEvent;
|
| 294 |
+
|
| 295 |
+
/* Wait for the client to confirm that the Audio Input dynamic channel is ready */
|
| 296 |
+
|
| 297 |
+
while (1)
|
| 298 |
+
{
|
| 299 |
+
if ((status = WaitForMultipleObjects(nCount, events, FALSE, 100)) == WAIT_OBJECT_0)
|
| 300 |
+
goto out;
|
| 301 |
+
|
| 302 |
+
if (status == WAIT_FAILED)
|
| 303 |
+
{
|
| 304 |
+
error = GetLastError();
|
| 305 |
+
WLog_Print(audin->log, WLOG_ERROR,
|
| 306 |
+
"WaitForMultipleObjects failed with error %" PRIu32 "", error);
|
| 307 |
+
goto out;
|
| 308 |
+
}
|
| 309 |
+
if (status == WAIT_OBJECT_0)
|
| 310 |
+
goto out;
|
| 311 |
+
|
| 312 |
+
if (WTSVirtualChannelQuery(audin->audin_channel, WTSVirtualChannelReady, &buffer,
|
| 313 |
+
&BytesReturned) == FALSE)
|
| 314 |
+
{
|
| 315 |
+
WLog_Print(audin->log, WLOG_ERROR, "WTSVirtualChannelQuery failed");
|
| 316 |
+
error = ERROR_INTERNAL_ERROR;
|
| 317 |
+
goto out;
|
| 318 |
+
}
|
| 319 |
+
|
| 320 |
+
ready = *((BOOL*)buffer);
|
| 321 |
+
WTSFreeMemory(buffer);
|
| 322 |
+
|
| 323 |
+
if (ready)
|
| 324 |
+
break;
|
| 325 |
+
}
|
| 326 |
+
|
| 327 |
+
s = Stream_New(NULL, 4096);
|
| 328 |
+
|
| 329 |
+
if (!s)
|
| 330 |
+
{
|
| 331 |
+
WLog_Print(audin->log, WLOG_ERROR, "Stream_New failed!");
|
| 332 |
+
error = CHANNEL_RC_NO_MEMORY;
|
| 333 |
+
goto out;
|
| 334 |
+
}
|
| 335 |
+
|
| 336 |
+
if (ready)
|
| 337 |
+
{
|
| 338 |
+
SNDIN_VERSION version = { 0 };
|
| 339 |
+
|
| 340 |
+
version.Version = audin->context.serverVersion;
|
| 341 |
+
|
| 342 |
+
if ((error = audin->context.SendVersion(&audin->context, &version)))
|
| 343 |
+
{
|
| 344 |
+
WLog_Print(audin->log, WLOG_ERROR, "SendVersion failed with error %" PRIu32 "!", error);
|
| 345 |
+
goto out_capacity;
|
| 346 |
+
}
|
| 347 |
+
}
|
| 348 |
+
|
| 349 |
+
while (ready)
|
| 350 |
+
{
|
| 351 |
+
SNDIN_PDU header = { 0 };
|
| 352 |
+
|
| 353 |
+
if ((status = WaitForMultipleObjects(nCount, events, FALSE, INFINITE)) == WAIT_OBJECT_0)
|
| 354 |
+
break;
|
| 355 |
+
|
| 356 |
+
if (status == WAIT_FAILED)
|
| 357 |
+
{
|
| 358 |
+
error = GetLastError();
|
| 359 |
+
WLog_Print(audin->log, WLOG_ERROR,
|
| 360 |
+
"WaitForMultipleObjects failed with error %" PRIu32 "", error);
|
| 361 |
+
break;
|
| 362 |
+
}
|
| 363 |
+
if (status == WAIT_OBJECT_0)
|
| 364 |
+
break;
|
| 365 |
+
|
| 366 |
+
Stream_SetPosition(s, 0);
|
| 367 |
+
|
| 368 |
+
if (!WTSVirtualChannelRead(audin->audin_channel, 0, NULL, 0, &BytesReturned))
|
| 369 |
+
{
|
| 370 |
+
WLog_Print(audin->log, WLOG_ERROR, "WTSVirtualChannelRead failed!");
|
| 371 |
+
error = ERROR_INTERNAL_ERROR;
|
| 372 |
+
break;
|
| 373 |
+
}
|
| 374 |
+
|
| 375 |
+
if (BytesReturned < 1)
|
| 376 |
+
continue;
|
| 377 |
+
|
| 378 |
+
if (!Stream_EnsureRemainingCapacity(s, BytesReturned))
|
| 379 |
+
break;
|
| 380 |
+
|
| 381 |
+
WINPR_ASSERT(Stream_Capacity(s) <= UINT32_MAX);
|
| 382 |
+
if (WTSVirtualChannelRead(audin->audin_channel, 0, Stream_BufferAs(s, char),
|
| 383 |
+
(ULONG)Stream_Capacity(s), &BytesReturned) == FALSE)
|
| 384 |
+
{
|
| 385 |
+
WLog_Print(audin->log, WLOG_ERROR, "WTSVirtualChannelRead failed!");
|
| 386 |
+
error = ERROR_INTERNAL_ERROR;
|
| 387 |
+
break;
|
| 388 |
+
}
|
| 389 |
+
|
| 390 |
+
Stream_SetLength(s, BytesReturned);
|
| 391 |
+
if (!Stream_CheckAndLogRequiredLengthWLog(audin->log, s, SNDIN_HEADER_SIZE))
|
| 392 |
+
{
|
| 393 |
+
error = ERROR_INTERNAL_ERROR;
|
| 394 |
+
break;
|
| 395 |
+
}
|
| 396 |
+
|
| 397 |
+
Stream_Read_UINT8(s, header.MessageId);
|
| 398 |
+
|
| 399 |
+
switch (header.MessageId)
|
| 400 |
+
{
|
| 401 |
+
case MSG_SNDIN_VERSION:
|
| 402 |
+
error = audin_server_recv_version(&audin->context, s, &header);
|
| 403 |
+
break;
|
| 404 |
+
case MSG_SNDIN_FORMATS:
|
| 405 |
+
error = audin_server_recv_formats(&audin->context, s, &header);
|
| 406 |
+
break;
|
| 407 |
+
case MSG_SNDIN_OPEN_REPLY:
|
| 408 |
+
error = audin_server_recv_open_reply(&audin->context, s, &header);
|
| 409 |
+
break;
|
| 410 |
+
case MSG_SNDIN_DATA_INCOMING:
|
| 411 |
+
error = audin_server_recv_data_incoming(&audin->context, s, &header);
|
| 412 |
+
break;
|
| 413 |
+
case MSG_SNDIN_DATA:
|
| 414 |
+
error = audin_server_recv_data(&audin->context, s, &header);
|
| 415 |
+
break;
|
| 416 |
+
case MSG_SNDIN_FORMATCHANGE:
|
| 417 |
+
error = audin_server_recv_format_change(&audin->context, s, &header);
|
| 418 |
+
break;
|
| 419 |
+
default:
|
| 420 |
+
WLog_Print(audin->log, WLOG_ERROR,
|
| 421 |
+
"audin_server_thread_func: unknown or invalid MessageId %" PRIu8 "",
|
| 422 |
+
header.MessageId);
|
| 423 |
+
error = ERROR_INVALID_DATA;
|
| 424 |
+
break;
|
| 425 |
+
}
|
| 426 |
+
if (error)
|
| 427 |
+
break;
|
| 428 |
+
}
|
| 429 |
+
|
| 430 |
+
out_capacity:
|
| 431 |
+
Stream_Free(s, TRUE);
|
| 432 |
+
out:
|
| 433 |
+
(void)WTSVirtualChannelClose(audin->audin_channel);
|
| 434 |
+
audin->audin_channel = NULL;
|
| 435 |
+
|
| 436 |
+
if (error && audin->context.rdpcontext)
|
| 437 |
+
setChannelError(audin->context.rdpcontext, error,
|
| 438 |
+
"audin_server_thread_func reported an error");
|
| 439 |
+
|
| 440 |
+
ExitThread(error);
|
| 441 |
+
return error;
|
| 442 |
+
}
|
| 443 |
+
|
| 444 |
+
static BOOL audin_server_open(audin_server_context* context)
|
| 445 |
+
{
|
| 446 |
+
audin_server* audin = (audin_server*)context;
|
| 447 |
+
|
| 448 |
+
WINPR_ASSERT(audin);
|
| 449 |
+
if (!audin->thread)
|
| 450 |
+
{
|
| 451 |
+
PULONG pSessionId = NULL;
|
| 452 |
+
DWORD BytesReturned = 0;
|
| 453 |
+
audin->SessionId = WTS_CURRENT_SESSION;
|
| 454 |
+
UINT32 channelId = 0;
|
| 455 |
+
BOOL status = TRUE;
|
| 456 |
+
|
| 457 |
+
if (WTSQuerySessionInformationA(context->vcm, WTS_CURRENT_SESSION, WTSSessionId,
|
| 458 |
+
(LPSTR*)&pSessionId, &BytesReturned))
|
| 459 |
+
{
|
| 460 |
+
audin->SessionId = (DWORD)*pSessionId;
|
| 461 |
+
WTSFreeMemory(pSessionId);
|
| 462 |
+
}
|
| 463 |
+
|
| 464 |
+
audin->audin_channel = WTSVirtualChannelOpenEx(audin->SessionId, AUDIN_DVC_CHANNEL_NAME,
|
| 465 |
+
WTS_CHANNEL_OPTION_DYNAMIC);
|
| 466 |
+
|
| 467 |
+
if (!audin->audin_channel)
|
| 468 |
+
{
|
| 469 |
+
WLog_Print(audin->log, WLOG_ERROR, "WTSVirtualChannelOpenEx failed!");
|
| 470 |
+
return FALSE;
|
| 471 |
+
}
|
| 472 |
+
|
| 473 |
+
channelId = WTSChannelGetIdByHandle(audin->audin_channel);
|
| 474 |
+
|
| 475 |
+
IFCALLRET(context->ChannelIdAssigned, status, context, channelId);
|
| 476 |
+
if (!status)
|
| 477 |
+
{
|
| 478 |
+
WLog_Print(audin->log, WLOG_ERROR, "context->ChannelIdAssigned failed!");
|
| 479 |
+
return FALSE;
|
| 480 |
+
}
|
| 481 |
+
|
| 482 |
+
if (!(audin->stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL)))
|
| 483 |
+
{
|
| 484 |
+
WLog_Print(audin->log, WLOG_ERROR, "CreateEvent failed!");
|
| 485 |
+
return FALSE;
|
| 486 |
+
}
|
| 487 |
+
|
| 488 |
+
if (!(audin->thread =
|
| 489 |
+
CreateThread(NULL, 0, audin_server_thread_func, (void*)audin, 0, NULL)))
|
| 490 |
+
{
|
| 491 |
+
WLog_Print(audin->log, WLOG_ERROR, "CreateThread failed!");
|
| 492 |
+
(void)CloseHandle(audin->stopEvent);
|
| 493 |
+
audin->stopEvent = NULL;
|
| 494 |
+
return FALSE;
|
| 495 |
+
}
|
| 496 |
+
|
| 497 |
+
return TRUE;
|
| 498 |
+
}
|
| 499 |
+
|
| 500 |
+
WLog_Print(audin->log, WLOG_ERROR, "thread already running!");
|
| 501 |
+
return FALSE;
|
| 502 |
+
}
|
| 503 |
+
|
| 504 |
+
static BOOL audin_server_is_open(audin_server_context* context)
|
| 505 |
+
{
|
| 506 |
+
audin_server* audin = (audin_server*)context;
|
| 507 |
+
|
| 508 |
+
WINPR_ASSERT(audin);
|
| 509 |
+
return audin->thread != NULL;
|
| 510 |
+
}
|
| 511 |
+
|
| 512 |
+
static BOOL audin_server_close(audin_server_context* context)
|
| 513 |
+
{
|
| 514 |
+
audin_server* audin = (audin_server*)context;
|
| 515 |
+
WINPR_ASSERT(audin);
|
| 516 |
+
|
| 517 |
+
if (audin->thread)
|
| 518 |
+
{
|
| 519 |
+
(void)SetEvent(audin->stopEvent);
|
| 520 |
+
|
| 521 |
+
if (WaitForSingleObject(audin->thread, INFINITE) == WAIT_FAILED)
|
| 522 |
+
{
|
| 523 |
+
WLog_Print(audin->log, WLOG_ERROR, "WaitForSingleObject failed with error %" PRIu32 "",
|
| 524 |
+
GetLastError());
|
| 525 |
+
return FALSE;
|
| 526 |
+
}
|
| 527 |
+
|
| 528 |
+
(void)CloseHandle(audin->thread);
|
| 529 |
+
(void)CloseHandle(audin->stopEvent);
|
| 530 |
+
audin->thread = NULL;
|
| 531 |
+
audin->stopEvent = NULL;
|
| 532 |
+
}
|
| 533 |
+
|
| 534 |
+
if (audin->audin_channel)
|
| 535 |
+
{
|
| 536 |
+
(void)WTSVirtualChannelClose(audin->audin_channel);
|
| 537 |
+
audin->audin_channel = NULL;
|
| 538 |
+
}
|
| 539 |
+
|
| 540 |
+
audin->audin_negotiated_format = NULL;
|
| 541 |
+
|
| 542 |
+
return TRUE;
|
| 543 |
+
}
|
| 544 |
+
|
| 545 |
+
static wStream* audin_server_packet_new(wLog* log, size_t size, BYTE MessageId)
|
| 546 |
+
{
|
| 547 |
+
WINPR_ASSERT(log);
|
| 548 |
+
|
| 549 |
+
/* Allocate what we need plus header bytes */
|
| 550 |
+
wStream* s = Stream_New(NULL, size + SNDIN_HEADER_SIZE);
|
| 551 |
+
if (!s)
|
| 552 |
+
{
|
| 553 |
+
WLog_Print(log, WLOG_ERROR, "Stream_New failed!");
|
| 554 |
+
return NULL;
|
| 555 |
+
}
|
| 556 |
+
|
| 557 |
+
Stream_Write_UINT8(s, MessageId);
|
| 558 |
+
|
| 559 |
+
return s;
|
| 560 |
+
}
|
| 561 |
+
|
| 562 |
+
static UINT audin_server_packet_send(audin_server_context* context, wStream* s)
|
| 563 |
+
{
|
| 564 |
+
audin_server* audin = (audin_server*)context;
|
| 565 |
+
UINT error = CHANNEL_RC_OK;
|
| 566 |
+
ULONG written = 0;
|
| 567 |
+
|
| 568 |
+
WINPR_ASSERT(context);
|
| 569 |
+
WINPR_ASSERT(s);
|
| 570 |
+
|
| 571 |
+
const size_t pos = Stream_GetPosition(s);
|
| 572 |
+
WINPR_ASSERT(pos <= UINT32_MAX);
|
| 573 |
+
if (!WTSVirtualChannelWrite(audin->audin_channel, Stream_BufferAs(s, char), (UINT32)pos,
|
| 574 |
+
&written))
|
| 575 |
+
{
|
| 576 |
+
WLog_Print(audin->log, WLOG_ERROR, "WTSVirtualChannelWrite failed!");
|
| 577 |
+
error = ERROR_INTERNAL_ERROR;
|
| 578 |
+
goto out;
|
| 579 |
+
}
|
| 580 |
+
|
| 581 |
+
if (written < Stream_GetPosition(s))
|
| 582 |
+
{
|
| 583 |
+
WLog_Print(audin->log, WLOG_WARN, "Unexpected bytes written: %" PRIu32 "/%" PRIuz "",
|
| 584 |
+
written, Stream_GetPosition(s));
|
| 585 |
+
}
|
| 586 |
+
|
| 587 |
+
out:
|
| 588 |
+
Stream_Free(s, TRUE);
|
| 589 |
+
return error;
|
| 590 |
+
}
|
| 591 |
+
|
| 592 |
+
static UINT audin_server_send_version(audin_server_context* context, const SNDIN_VERSION* version)
|
| 593 |
+
{
|
| 594 |
+
audin_server* audin = (audin_server*)context;
|
| 595 |
+
|
| 596 |
+
WINPR_ASSERT(context);
|
| 597 |
+
WINPR_ASSERT(version);
|
| 598 |
+
|
| 599 |
+
wStream* s = audin_server_packet_new(audin->log, 4, MSG_SNDIN_VERSION);
|
| 600 |
+
if (!s)
|
| 601 |
+
return ERROR_NOT_ENOUGH_MEMORY;
|
| 602 |
+
|
| 603 |
+
Stream_Write_UINT32(s, version->Version);
|
| 604 |
+
|
| 605 |
+
return audin_server_packet_send(context, s);
|
| 606 |
+
}
|
| 607 |
+
|
| 608 |
+
static UINT audin_server_send_formats(audin_server_context* context, const SNDIN_FORMATS* formats)
|
| 609 |
+
{
|
| 610 |
+
audin_server* audin = (audin_server*)context;
|
| 611 |
+
|
| 612 |
+
WINPR_ASSERT(audin);
|
| 613 |
+
WINPR_ASSERT(formats);
|
| 614 |
+
|
| 615 |
+
wStream* s = audin_server_packet_new(audin->log, 4 + 4 + 18, MSG_SNDIN_FORMATS);
|
| 616 |
+
if (!s)
|
| 617 |
+
return ERROR_NOT_ENOUGH_MEMORY;
|
| 618 |
+
|
| 619 |
+
Stream_Write_UINT32(s, formats->NumFormats);
|
| 620 |
+
Stream_Write_UINT32(s, formats->cbSizeFormatsPacket);
|
| 621 |
+
|
| 622 |
+
for (UINT32 i = 0; i < formats->NumFormats; ++i)
|
| 623 |
+
{
|
| 624 |
+
AUDIO_FORMAT* format = &formats->SoundFormats[i];
|
| 625 |
+
|
| 626 |
+
if (!audio_format_write(s, format))
|
| 627 |
+
{
|
| 628 |
+
WLog_Print(audin->log, WLOG_ERROR, "Failed to write audio format");
|
| 629 |
+
Stream_Free(s, TRUE);
|
| 630 |
+
return CHANNEL_RC_NO_MEMORY;
|
| 631 |
+
}
|
| 632 |
+
}
|
| 633 |
+
|
| 634 |
+
return audin_server_packet_send(context, s);
|
| 635 |
+
}
|
| 636 |
+
|
| 637 |
+
static UINT audin_server_send_open(audin_server_context* context, const SNDIN_OPEN* open)
|
| 638 |
+
{
|
| 639 |
+
audin_server* audin = (audin_server*)context;
|
| 640 |
+
WINPR_ASSERT(audin);
|
| 641 |
+
WINPR_ASSERT(open);
|
| 642 |
+
|
| 643 |
+
wStream* s = audin_server_packet_new(audin->log, 4 + 4 + 18 + 22, MSG_SNDIN_OPEN);
|
| 644 |
+
if (!s)
|
| 645 |
+
return ERROR_NOT_ENOUGH_MEMORY;
|
| 646 |
+
|
| 647 |
+
Stream_Write_UINT32(s, open->FramesPerPacket);
|
| 648 |
+
Stream_Write_UINT32(s, open->initialFormat);
|
| 649 |
+
|
| 650 |
+
Stream_Write_UINT16(s, open->captureFormat.wFormatTag);
|
| 651 |
+
Stream_Write_UINT16(s, open->captureFormat.nChannels);
|
| 652 |
+
Stream_Write_UINT32(s, open->captureFormat.nSamplesPerSec);
|
| 653 |
+
Stream_Write_UINT32(s, open->captureFormat.nAvgBytesPerSec);
|
| 654 |
+
Stream_Write_UINT16(s, open->captureFormat.nBlockAlign);
|
| 655 |
+
Stream_Write_UINT16(s, open->captureFormat.wBitsPerSample);
|
| 656 |
+
|
| 657 |
+
if (open->ExtraFormatData)
|
| 658 |
+
{
|
| 659 |
+
Stream_Write_UINT16(s, 22); /* cbSize */
|
| 660 |
+
|
| 661 |
+
Stream_Write_UINT16(s, open->ExtraFormatData->Samples.wReserved);
|
| 662 |
+
Stream_Write_UINT32(s, open->ExtraFormatData->dwChannelMask);
|
| 663 |
+
|
| 664 |
+
Stream_Write_UINT32(s, open->ExtraFormatData->SubFormat.Data1);
|
| 665 |
+
Stream_Write_UINT16(s, open->ExtraFormatData->SubFormat.Data2);
|
| 666 |
+
Stream_Write_UINT16(s, open->ExtraFormatData->SubFormat.Data3);
|
| 667 |
+
Stream_Write_UINT8(s, open->ExtraFormatData->SubFormat.Data4[0]);
|
| 668 |
+
Stream_Write_UINT8(s, open->ExtraFormatData->SubFormat.Data4[1]);
|
| 669 |
+
Stream_Write_UINT8(s, open->ExtraFormatData->SubFormat.Data4[2]);
|
| 670 |
+
Stream_Write_UINT8(s, open->ExtraFormatData->SubFormat.Data4[3]);
|
| 671 |
+
Stream_Write_UINT8(s, open->ExtraFormatData->SubFormat.Data4[4]);
|
| 672 |
+
Stream_Write_UINT8(s, open->ExtraFormatData->SubFormat.Data4[5]);
|
| 673 |
+
Stream_Write_UINT8(s, open->ExtraFormatData->SubFormat.Data4[6]);
|
| 674 |
+
Stream_Write_UINT8(s, open->ExtraFormatData->SubFormat.Data4[7]);
|
| 675 |
+
}
|
| 676 |
+
else
|
| 677 |
+
{
|
| 678 |
+
WINPR_ASSERT(open->captureFormat.wFormatTag != WAVE_FORMAT_EXTENSIBLE);
|
| 679 |
+
|
| 680 |
+
Stream_Write_UINT16(s, 0); /* cbSize */
|
| 681 |
+
}
|
| 682 |
+
|
| 683 |
+
return audin_server_packet_send(context, s);
|
| 684 |
+
}
|
| 685 |
+
|
| 686 |
+
static UINT audin_server_send_format_change(audin_server_context* context,
|
| 687 |
+
const SNDIN_FORMATCHANGE* format_change)
|
| 688 |
+
{
|
| 689 |
+
audin_server* audin = (audin_server*)context;
|
| 690 |
+
|
| 691 |
+
WINPR_ASSERT(context);
|
| 692 |
+
WINPR_ASSERT(format_change);
|
| 693 |
+
|
| 694 |
+
wStream* s = audin_server_packet_new(audin->log, 4, MSG_SNDIN_FORMATCHANGE);
|
| 695 |
+
if (!s)
|
| 696 |
+
return ERROR_NOT_ENOUGH_MEMORY;
|
| 697 |
+
|
| 698 |
+
Stream_Write_UINT32(s, format_change->NewFormat);
|
| 699 |
+
|
| 700 |
+
return audin_server_packet_send(context, s);
|
| 701 |
+
}
|
| 702 |
+
|
| 703 |
+
static UINT audin_server_receive_version_default(audin_server_context* audin_ctx,
|
| 704 |
+
const SNDIN_VERSION* version)
|
| 705 |
+
{
|
| 706 |
+
audin_server* audin = (audin_server*)audin_ctx;
|
| 707 |
+
SNDIN_FORMATS formats = { 0 };
|
| 708 |
+
|
| 709 |
+
WINPR_ASSERT(audin);
|
| 710 |
+
WINPR_ASSERT(version);
|
| 711 |
+
|
| 712 |
+
if (version->Version == 0)
|
| 713 |
+
{
|
| 714 |
+
WLog_Print(audin->log, WLOG_ERROR, "Received invalid AUDIO_INPUT version from client");
|
| 715 |
+
return ERROR_INVALID_DATA;
|
| 716 |
+
}
|
| 717 |
+
|
| 718 |
+
WLog_Print(audin->log, WLOG_DEBUG, "AUDIO_INPUT version of client: %u", version->Version);
|
| 719 |
+
|
| 720 |
+
formats.NumFormats = audin->audin_n_server_formats;
|
| 721 |
+
formats.SoundFormats = audin->audin_server_formats;
|
| 722 |
+
|
| 723 |
+
return audin->context.SendFormats(&audin->context, &formats);
|
| 724 |
+
}
|
| 725 |
+
|
| 726 |
+
static UINT send_open(audin_server* audin)
|
| 727 |
+
{
|
| 728 |
+
SNDIN_OPEN open = { 0 };
|
| 729 |
+
|
| 730 |
+
WINPR_ASSERT(audin);
|
| 731 |
+
|
| 732 |
+
open.FramesPerPacket = 441;
|
| 733 |
+
open.initialFormat = audin->audin_client_format_idx;
|
| 734 |
+
open.captureFormat.wFormatTag = WAVE_FORMAT_PCM;
|
| 735 |
+
open.captureFormat.nChannels = 2;
|
| 736 |
+
open.captureFormat.nSamplesPerSec = 44100;
|
| 737 |
+
open.captureFormat.nAvgBytesPerSec = 44100 * 2 * 2;
|
| 738 |
+
open.captureFormat.nBlockAlign = 4;
|
| 739 |
+
open.captureFormat.wBitsPerSample = 16;
|
| 740 |
+
|
| 741 |
+
WINPR_ASSERT(audin->context.SendOpen);
|
| 742 |
+
return audin->context.SendOpen(&audin->context, &open);
|
| 743 |
+
}
|
| 744 |
+
|
| 745 |
+
static UINT audin_server_receive_formats_default(audin_server_context* context,
|
| 746 |
+
const SNDIN_FORMATS* formats)
|
| 747 |
+
{
|
| 748 |
+
audin_server* audin = (audin_server*)context;
|
| 749 |
+
WINPR_ASSERT(audin);
|
| 750 |
+
WINPR_ASSERT(formats);
|
| 751 |
+
|
| 752 |
+
if (audin->audin_negotiated_format)
|
| 753 |
+
{
|
| 754 |
+
WLog_Print(audin->log, WLOG_ERROR,
|
| 755 |
+
"Received client formats, but negotiation was already done");
|
| 756 |
+
return ERROR_INVALID_DATA;
|
| 757 |
+
}
|
| 758 |
+
|
| 759 |
+
for (UINT32 i = 0; i < audin->audin_n_server_formats; ++i)
|
| 760 |
+
{
|
| 761 |
+
for (UINT32 j = 0; j < formats->NumFormats; ++j)
|
| 762 |
+
{
|
| 763 |
+
if (audio_format_compatible(&audin->audin_server_formats[i], &formats->SoundFormats[j]))
|
| 764 |
+
{
|
| 765 |
+
audin->audin_negotiated_format = &audin->audin_server_formats[i];
|
| 766 |
+
audin->audin_client_format_idx = i;
|
| 767 |
+
return send_open(audin);
|
| 768 |
+
}
|
| 769 |
+
}
|
| 770 |
+
}
|
| 771 |
+
|
| 772 |
+
WLog_Print(audin->log, WLOG_ERROR, "Could not agree on a audio format with the server");
|
| 773 |
+
|
| 774 |
+
return ERROR_INVALID_DATA;
|
| 775 |
+
}
|
| 776 |
+
|
| 777 |
+
static UINT audin_server_receive_format_change_default(audin_server_context* context,
|
| 778 |
+
const SNDIN_FORMATCHANGE* format_change)
|
| 779 |
+
{
|
| 780 |
+
audin_server* audin = (audin_server*)context;
|
| 781 |
+
|
| 782 |
+
WINPR_ASSERT(audin);
|
| 783 |
+
WINPR_ASSERT(format_change);
|
| 784 |
+
|
| 785 |
+
if (format_change->NewFormat != audin->audin_client_format_idx)
|
| 786 |
+
{
|
| 787 |
+
WLog_Print(audin->log, WLOG_ERROR,
|
| 788 |
+
"NewFormat in FormatChange differs from requested format");
|
| 789 |
+
return ERROR_INVALID_DATA;
|
| 790 |
+
}
|
| 791 |
+
|
| 792 |
+
WLog_Print(audin->log, WLOG_DEBUG, "Received Format Change PDU: %u", format_change->NewFormat);
|
| 793 |
+
|
| 794 |
+
return CHANNEL_RC_OK;
|
| 795 |
+
}
|
| 796 |
+
|
| 797 |
+
static UINT audin_server_incoming_data_default(audin_server_context* context,
|
| 798 |
+
const SNDIN_DATA_INCOMING* data_incoming)
|
| 799 |
+
{
|
| 800 |
+
audin_server* audin = (audin_server*)context;
|
| 801 |
+
WINPR_ASSERT(audin);
|
| 802 |
+
WINPR_ASSERT(data_incoming);
|
| 803 |
+
|
| 804 |
+
/* TODO: Implement bandwidth measure of clients uplink */
|
| 805 |
+
WLog_Print(audin->log, WLOG_DEBUG, "Received Incoming Data PDU");
|
| 806 |
+
return CHANNEL_RC_OK;
|
| 807 |
+
}
|
| 808 |
+
|
| 809 |
+
static UINT audin_server_open_reply_default(audin_server_context* context,
|
| 810 |
+
const SNDIN_OPEN_REPLY* open_reply)
|
| 811 |
+
{
|
| 812 |
+
audin_server* audin = (audin_server*)context;
|
| 813 |
+
WINPR_ASSERT(audin);
|
| 814 |
+
WINPR_ASSERT(open_reply);
|
| 815 |
+
|
| 816 |
+
/* TODO: Implement failure handling */
|
| 817 |
+
WLog_Print(audin->log, WLOG_DEBUG, "Open Reply PDU: Result: %i", open_reply->Result);
|
| 818 |
+
return CHANNEL_RC_OK;
|
| 819 |
+
}
|
| 820 |
+
|
| 821 |
+
audin_server_context* audin_server_context_new(HANDLE vcm)
|
| 822 |
+
{
|
| 823 |
+
audin_server* audin = (audin_server*)calloc(1, sizeof(audin_server));
|
| 824 |
+
|
| 825 |
+
if (!audin)
|
| 826 |
+
{
|
| 827 |
+
WLog_ERR(AUDIN_TAG, "calloc failed!");
|
| 828 |
+
return NULL;
|
| 829 |
+
}
|
| 830 |
+
audin->log = WLog_Get(AUDIN_TAG);
|
| 831 |
+
audin->context.vcm = vcm;
|
| 832 |
+
audin->context.Open = audin_server_open;
|
| 833 |
+
audin->context.IsOpen = audin_server_is_open;
|
| 834 |
+
audin->context.Close = audin_server_close;
|
| 835 |
+
|
| 836 |
+
audin->context.SendVersion = audin_server_send_version;
|
| 837 |
+
audin->context.SendFormats = audin_server_send_formats;
|
| 838 |
+
audin->context.SendOpen = audin_server_send_open;
|
| 839 |
+
audin->context.SendFormatChange = audin_server_send_format_change;
|
| 840 |
+
|
| 841 |
+
/* Default values */
|
| 842 |
+
audin->context.serverVersion = SNDIN_VERSION_Version_2;
|
| 843 |
+
audin->context.ReceiveVersion = audin_server_receive_version_default;
|
| 844 |
+
audin->context.ReceiveFormats = audin_server_receive_formats_default;
|
| 845 |
+
audin->context.ReceiveFormatChange = audin_server_receive_format_change_default;
|
| 846 |
+
audin->context.IncomingData = audin_server_incoming_data_default;
|
| 847 |
+
audin->context.OpenReply = audin_server_open_reply_default;
|
| 848 |
+
|
| 849 |
+
return &audin->context;
|
| 850 |
+
}
|
| 851 |
+
|
| 852 |
+
void audin_server_context_free(audin_server_context* context)
|
| 853 |
+
{
|
| 854 |
+
audin_server* audin = (audin_server*)context;
|
| 855 |
+
|
| 856 |
+
if (!audin)
|
| 857 |
+
return;
|
| 858 |
+
|
| 859 |
+
audin_server_close(context);
|
| 860 |
+
audio_formats_free(audin->audin_server_formats, audin->audin_n_server_formats);
|
| 861 |
+
audin->audin_server_formats = NULL;
|
| 862 |
+
free(audin);
|
| 863 |
+
}
|
| 864 |
+
|
| 865 |
+
BOOL audin_server_set_formats(audin_server_context* context, SSIZE_T count,
|
| 866 |
+
const AUDIO_FORMAT* formats)
|
| 867 |
+
{
|
| 868 |
+
audin_server* audin = (audin_server*)context;
|
| 869 |
+
WINPR_ASSERT(audin);
|
| 870 |
+
|
| 871 |
+
audio_formats_free(audin->audin_server_formats, audin->audin_n_server_formats);
|
| 872 |
+
audin->audin_n_server_formats = 0;
|
| 873 |
+
audin->audin_server_formats = NULL;
|
| 874 |
+
audin->audin_negotiated_format = NULL;
|
| 875 |
+
|
| 876 |
+
if (count < 0)
|
| 877 |
+
{
|
| 878 |
+
const size_t audin_n_server_formats =
|
| 879 |
+
server_audin_get_formats(&audin->audin_server_formats);
|
| 880 |
+
WINPR_ASSERT(audin_n_server_formats <= UINT32_MAX);
|
| 881 |
+
|
| 882 |
+
audin->audin_n_server_formats = (UINT32)audin_n_server_formats;
|
| 883 |
+
}
|
| 884 |
+
else
|
| 885 |
+
{
|
| 886 |
+
const size_t scount = (size_t)count;
|
| 887 |
+
AUDIO_FORMAT* audin_server_formats = audio_formats_new(scount);
|
| 888 |
+
if (!audin_server_formats)
|
| 889 |
+
return count == 0;
|
| 890 |
+
|
| 891 |
+
for (SSIZE_T x = 0; x < count; x++)
|
| 892 |
+
{
|
| 893 |
+
if (!audio_format_copy(&formats[x], &audin_server_formats[x]))
|
| 894 |
+
{
|
| 895 |
+
audio_formats_free(audin_server_formats, scount);
|
| 896 |
+
return FALSE;
|
| 897 |
+
}
|
| 898 |
+
}
|
| 899 |
+
|
| 900 |
+
WINPR_ASSERT(count <= UINT32_MAX);
|
| 901 |
+
audin->audin_server_formats = audin_server_formats;
|
| 902 |
+
audin->audin_n_server_formats = (UINT32)count;
|
| 903 |
+
}
|
| 904 |
+
return audin->audin_n_server_formats > 0;
|
| 905 |
+
}
|
| 906 |
+
|
| 907 |
+
const AUDIO_FORMAT* audin_server_get_negotiated_format(const audin_server_context* context)
|
| 908 |
+
{
|
| 909 |
+
const audin_server* audin = (const audin_server*)context;
|
| 910 |
+
WINPR_ASSERT(audin);
|
| 911 |
+
|
| 912 |
+
return audin->audin_negotiated_format;
|
| 913 |
+
}
|
local-test-freerdp-delta-01/afc-freerdp/channels/client/CMakeLists.txt
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# FreeRDP: A Remote Desktop Protocol Implementation
|
| 2 |
+
# FreeRDP cmake build script
|
| 3 |
+
#
|
| 4 |
+
# Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
| 5 |
+
# Copyright 2024 Armin Novak <anovak@thincast.com>
|
| 6 |
+
# Copyright 2024 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 |
+
set(MODULE_NAME "freerdp-channels-client")
|
| 21 |
+
set(MODULE_PREFIX "FREERDP_CHANNELS_CLIENT")
|
| 22 |
+
|
| 23 |
+
set(${MODULE_PREFIX}_SRCS
|
| 24 |
+
${CMAKE_CURRENT_BINARY_DIR}/tables.c ${CMAKE_CURRENT_SOURCE_DIR}/tables.h ${CMAKE_CURRENT_SOURCE_DIR}/addin.c
|
| 25 |
+
${CMAKE_CURRENT_SOURCE_DIR}/addin.h ${CMAKE_CURRENT_SOURCE_DIR}/generic_dynvc.c
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
if(CHANNEL_STATIC_CLIENT_ENTRIES)
|
| 29 |
+
list(REMOVE_DUPLICATES CHANNEL_STATIC_CLIENT_ENTRIES)
|
| 30 |
+
endif()
|
| 31 |
+
|
| 32 |
+
foreach(STATIC_ENTRY ${CHANNEL_STATIC_CLIENT_ENTRIES})
|
| 33 |
+
foreach(STATIC_MODULE ${CHANNEL_STATIC_CLIENT_MODULES})
|
| 34 |
+
foreach(ENTRY ${${STATIC_MODULE}_CLIENT_ENTRY})
|
| 35 |
+
if(${ENTRY} STREQUAL ${STATIC_ENTRY})
|
| 36 |
+
set(STATIC_MODULE_NAME ${${STATIC_MODULE}_CLIENT_NAME})
|
| 37 |
+
set(STATIC_MODULE_CHANNEL ${${STATIC_MODULE}_CLIENT_CHANNEL})
|
| 38 |
+
list(APPEND ${MODULE_PREFIX}_LIBS ${STATIC_MODULE_NAME})
|
| 39 |
+
|
| 40 |
+
set(ENTRY_POINT_NAME "${STATIC_MODULE_CHANNEL}_${ENTRY}")
|
| 41 |
+
if(${ENTRY} STREQUAL "VirtualChannelEntry")
|
| 42 |
+
set(ENTRY_POINT_IMPORT "extern BOOL VCAPITYPE ${ENTRY_POINT_NAME}(PCHANNEL_ENTRY_POINTS);")
|
| 43 |
+
elseif(${ENTRY} STREQUAL "VirtualChannelEntryEx")
|
| 44 |
+
set(ENTRY_POINT_IMPORT "extern BOOL VCAPITYPE ${ENTRY_POINT_NAME}(PCHANNEL_ENTRY_POINTS,PVOID);")
|
| 45 |
+
elseif(${ENTRY} MATCHES "DVCPluginEntry$")
|
| 46 |
+
set(ENTRY_POINT_IMPORT "extern UINT VCAPITYPE ${ENTRY_POINT_NAME}(IDRDYNVC_ENTRY_POINTS* pEntryPoints);")
|
| 47 |
+
elseif(${ENTRY} MATCHES "DeviceServiceEntry$")
|
| 48 |
+
set(ENTRY_POINT_IMPORT
|
| 49 |
+
"extern UINT VCAPITYPE ${ENTRY_POINT_NAME}(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints);"
|
| 50 |
+
)
|
| 51 |
+
else()
|
| 52 |
+
set(ENTRY_POINT_IMPORT "extern UINT VCAPITYPE ${ENTRY_POINT_NAME}(void);")
|
| 53 |
+
endif()
|
| 54 |
+
|
| 55 |
+
string(APPEND ${STATIC_ENTRY}_IMPORTS "\n${ENTRY_POINT_IMPORT}")
|
| 56 |
+
string(APPEND ${STATIC_ENTRY}_TABLE "\n\t{ \"${STATIC_MODULE_CHANNEL}\", ${ENTRY_POINT_NAME} },")
|
| 57 |
+
endif()
|
| 58 |
+
endforeach()
|
| 59 |
+
endforeach()
|
| 60 |
+
endforeach()
|
| 61 |
+
|
| 62 |
+
string(APPEND CLIENT_STATIC_ENTRY_TABLES_LIST "\nextern const STATIC_ENTRY_TABLE CLIENT_STATIC_ENTRY_TABLES[];\n")
|
| 63 |
+
string(APPEND CLIENT_STATIC_ENTRY_TABLES_LIST "const STATIC_ENTRY_TABLE CLIENT_STATIC_ENTRY_TABLES[] =\n{")
|
| 64 |
+
|
| 65 |
+
foreach(STATIC_ENTRY ${CHANNEL_STATIC_CLIENT_ENTRIES})
|
| 66 |
+
set(CLIENT_STATIC_ENTRY_IMPORTS "${CLIENT_STATIC_ENTRY_IMPORTS}\n${${STATIC_ENTRY}_IMPORTS}")
|
| 67 |
+
if(${STATIC_ENTRY} STREQUAL "VirtualChannelEntry")
|
| 68 |
+
set(CLIENT_STATIC_ENTRY_TYPE "STATIC_ENTRY_VC")
|
| 69 |
+
set(CLIENT_STATIC_ENTRY_INITIALIZER ".csevc")
|
| 70 |
+
elseif(${STATIC_ENTRY} STREQUAL "VirtualChannelEntryEx")
|
| 71 |
+
set(CLIENT_STATIC_ENTRY_TYPE "STATIC_ENTRY_VCEX")
|
| 72 |
+
set(CLIENT_STATIC_ENTRY_INITIALIZER ".csevcex")
|
| 73 |
+
elseif(${STATIC_ENTRY} MATCHES "DVCPluginEntry$")
|
| 74 |
+
set(CLIENT_STATIC_ENTRY_TYPE "STATIC_ENTRY_DVC")
|
| 75 |
+
set(CLIENT_STATIC_ENTRY_INITIALIZER ".csedvc")
|
| 76 |
+
elseif(${STATIC_ENTRY} MATCHES "DeviceServiceEntry$")
|
| 77 |
+
set(CLIENT_STATIC_ENTRY_TYPE "STATIC_ENTRY_DSE")
|
| 78 |
+
set(CLIENT_STATIC_ENTRY_INITIALIZER ".csedse")
|
| 79 |
+
else()
|
| 80 |
+
set(CLIENT_STATIC_ENTRY_TYPE "STATIC_ENTRY")
|
| 81 |
+
set(CLIENT_STATIC_ENTRY_INITIALIZER ".cse")
|
| 82 |
+
endif()
|
| 83 |
+
|
| 84 |
+
string(APPEND CLIENT_STATIC_ENTRY_TABLES
|
| 85 |
+
"\nextern const ${CLIENT_STATIC_ENTRY_TYPE} CLIENT_${STATIC_ENTRY}_TABLE[];\n"
|
| 86 |
+
)
|
| 87 |
+
string(APPEND CLIENT_STATIC_ENTRY_TABLES "const ${CLIENT_STATIC_ENTRY_TYPE} CLIENT_${STATIC_ENTRY}_TABLE[] =\n{")
|
| 88 |
+
string(APPEND CLIENT_STATIC_ENTRY_TABLES "\n${${STATIC_ENTRY}_TABLE}")
|
| 89 |
+
string(APPEND CLIENT_STATIC_ENTRY_TABLES "\n\t{ NULL, NULL }\n};")
|
| 90 |
+
string(APPEND CLIENT_STATIC_ENTRY_TABLES_LIST
|
| 91 |
+
"\n\t{ \"${STATIC_ENTRY}\", { ${CLIENT_STATIC_ENTRY_INITIALIZER} = CLIENT_${STATIC_ENTRY}_TABLE } },"
|
| 92 |
+
)
|
| 93 |
+
endforeach()
|
| 94 |
+
|
| 95 |
+
string(APPEND CLIENT_STATIC_ENTRY_TABLES_LIST "\n\t{ NULL, { .cse = NULL } }\n};")
|
| 96 |
+
|
| 97 |
+
set(CLIENT_STATIC_ADDIN_TABLE "extern const STATIC_ADDIN_TABLE CLIENT_STATIC_ADDIN_TABLE[];\n")
|
| 98 |
+
string(APPEND CLIENT_STATIC_ADDIN_TABLE "const STATIC_ADDIN_TABLE CLIENT_STATIC_ADDIN_TABLE[] =\n{")
|
| 99 |
+
|
| 100 |
+
foreach(STATIC_MODULE ${CHANNEL_STATIC_CLIENT_MODULES})
|
| 101 |
+
set(STATIC_MODULE_NAME ${${STATIC_MODULE}_CLIENT_NAME})
|
| 102 |
+
set(STATIC_MODULE_CHANNEL ${${STATIC_MODULE}_CLIENT_CHANNEL})
|
| 103 |
+
string(TOUPPER "CLIENT_${STATIC_MODULE_CHANNEL}_SUBSYSTEM_TABLE" SUBSYSTEM_TABLE_NAME)
|
| 104 |
+
set(SUBSYSTEM_TABLE
|
| 105 |
+
"extern const STATIC_SUBSYSTEM_ENTRY ${SUBSYSTEM_TABLE_NAME}[];\nconst STATIC_SUBSYSTEM_ENTRY ${SUBSYSTEM_TABLE_NAME}[] =\n{"
|
| 106 |
+
)
|
| 107 |
+
get_target_property(CHANNEL_SUBSYSTEMS ${STATIC_MODULE_NAME} SUBSYSTEMS)
|
| 108 |
+
if(CHANNEL_SUBSYSTEMS MATCHES "NOTFOUND")
|
| 109 |
+
set(CHANNEL_SUBSYSTEMS "")
|
| 110 |
+
endif()
|
| 111 |
+
foreach(STATIC_SUBSYSTEM ${CHANNEL_SUBSYSTEMS})
|
| 112 |
+
if(${STATIC_SUBSYSTEM} MATCHES "^([^-]*)-(.*)")
|
| 113 |
+
string(REGEX REPLACE "^([^-]*)-(.*)" "\\1" STATIC_SUBSYSTEM_NAME ${STATIC_SUBSYSTEM})
|
| 114 |
+
string(REGEX REPLACE "^([^-]*)-(.*)" "\\2" STATIC_SUBSYSTEM_TYPE ${STATIC_SUBSYSTEM})
|
| 115 |
+
else()
|
| 116 |
+
set(STATIC_SUBSYSTEM_NAME "${STATIC_SUBSYSTEM}")
|
| 117 |
+
set(STATIC_SUBSYSTEM_TYPE "")
|
| 118 |
+
endif()
|
| 119 |
+
string(LENGTH "${STATIC_SUBSYSTEM_TYPE}" _type_length)
|
| 120 |
+
set(SUBSYSTEM_MODULE_NAME "${STATIC_MODULE_NAME}-${STATIC_SUBSYSTEM}")
|
| 121 |
+
list(APPEND ${MODULE_PREFIX}_LIBS ${SUBSYSTEM_MODULE_NAME})
|
| 122 |
+
if(_type_length GREATER 0)
|
| 123 |
+
set(STATIC_SUBSYSTEM_ENTRY
|
| 124 |
+
"${STATIC_SUBSYSTEM_NAME}_freerdp_${STATIC_MODULE_CHANNEL}_client_${STATIC_SUBSYSTEM_TYPE}_subsystem_entry"
|
| 125 |
+
)
|
| 126 |
+
else()
|
| 127 |
+
set(STATIC_SUBSYSTEM_ENTRY "${STATIC_SUBSYSTEM_NAME}_freerdp_${STATIC_MODULE_CHANNEL}_client_subsystem_entry")
|
| 128 |
+
endif()
|
| 129 |
+
string(APPEND SUBSYSTEM_TABLE
|
| 130 |
+
"\n\t{ \"${STATIC_SUBSYSTEM_NAME}\", \"${STATIC_SUBSYSTEM_TYPE}\", ${STATIC_SUBSYSTEM_ENTRY} },"
|
| 131 |
+
)
|
| 132 |
+
set(SUBSYSTEM_IMPORT "extern UINT VCAPITYPE ${STATIC_SUBSYSTEM_ENTRY}(void*);")
|
| 133 |
+
string(APPEND CLIENT_STATIC_SUBSYSTEM_IMPORTS "\n${SUBSYSTEM_IMPORT}")
|
| 134 |
+
endforeach()
|
| 135 |
+
string(APPEND SUBSYSTEM_TABLE "\n\t{ NULL, NULL, NULL }\n};")
|
| 136 |
+
string(APPEND CLIENT_STATIC_SUBSYSTEM_TABLES "\n${SUBSYSTEM_TABLE}")
|
| 137 |
+
|
| 138 |
+
foreach(ENTRY ${${STATIC_MODULE}_CLIENT_ENTRY})
|
| 139 |
+
set(ENTRY_POINT_NAME ${STATIC_MODULE_CHANNEL}_${ENTRY})
|
| 140 |
+
if(${ENTRY} STREQUAL "VirtualChannelEntry")
|
| 141 |
+
set(ENTRY_INITIALIZER ".csevc")
|
| 142 |
+
elseif(${ENTRY} STREQUAL "VirtualChannelEntryEx")
|
| 143 |
+
set(ENTRY_INITIALIZER ".csevcex")
|
| 144 |
+
elseif(${ENTRY} MATCHES "DVCPluginEntry$")
|
| 145 |
+
set(ENTRY_INITIALIZER ".csedvc")
|
| 146 |
+
elseif(${ENTRY} MATCHES "DeviceServiceEntry$")
|
| 147 |
+
set(ENTRY_INITIALIZER ".csedse")
|
| 148 |
+
else()
|
| 149 |
+
set(ENTRY_INITIALIZER ".cse")
|
| 150 |
+
endif()
|
| 151 |
+
string(
|
| 152 |
+
APPEND
|
| 153 |
+
CLIENT_STATIC_ADDIN_TABLE
|
| 154 |
+
"\n\t{ \"${STATIC_MODULE_CHANNEL}\", \"${ENTRY}\", { ${ENTRY_INITIALIZER} = ${ENTRY_POINT_NAME} }, ${SUBSYSTEM_TABLE_NAME} },"
|
| 155 |
+
)
|
| 156 |
+
endforeach()
|
| 157 |
+
endforeach()
|
| 158 |
+
string(APPEND CLIENT_STATIC_ADDIN_TABLE "\n\t{ NULL, NULL, { .cse = NULL }, NULL }\n};")
|
| 159 |
+
|
| 160 |
+
cleaning_configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tables.c.in ${CMAKE_CURRENT_BINARY_DIR}/tables.c)
|
| 161 |
+
|
| 162 |
+
set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} freerdp winpr)
|
| 163 |
+
|
| 164 |
+
set(${MODULE_PREFIX}_SRCS ${${MODULE_PREFIX}_SRCS} PARENT_SCOPE)
|
| 165 |
+
set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} PARENT_SCOPE)
|
local-test-freerdp-delta-01/afc-freerdp/channels/client/addin.c
ADDED
|
@@ -0,0 +1,761 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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* Copyright 2015 DI (FH) Martin Haimberger <martin.haimberger@thincast.com>
|
| 8 |
+
*
|
| 9 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 10 |
+
* you may not use this file except in compliance with the License.
|
| 11 |
+
* You may obtain a copy of the License at
|
| 12 |
+
*
|
| 13 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 14 |
+
*
|
| 15 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 16 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 17 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 18 |
+
* See the License for the specific language governing permissions and
|
| 19 |
+
* limitations under the License.
|
| 20 |
+
*/
|
| 21 |
+
|
| 22 |
+
#include <freerdp/config.h>
|
| 23 |
+
|
| 24 |
+
#include <winpr/crt.h>
|
| 25 |
+
#include <winpr/assert.h>
|
| 26 |
+
#include <winpr/path.h>
|
| 27 |
+
#include <winpr/string.h>
|
| 28 |
+
#include <winpr/file.h>
|
| 29 |
+
#include <winpr/synch.h>
|
| 30 |
+
#include <winpr/library.h>
|
| 31 |
+
#include <winpr/collections.h>
|
| 32 |
+
|
| 33 |
+
#include <freerdp/freerdp.h>
|
| 34 |
+
#include <freerdp/addin.h>
|
| 35 |
+
#include <freerdp/build-config.h>
|
| 36 |
+
#include <freerdp/client/channels.h>
|
| 37 |
+
|
| 38 |
+
#include "tables.h"
|
| 39 |
+
|
| 40 |
+
#include "addin.h"
|
| 41 |
+
|
| 42 |
+
#include <freerdp/channels/log.h>
|
| 43 |
+
#define TAG CHANNELS_TAG("addin")
|
| 44 |
+
|
| 45 |
+
extern const STATIC_ENTRY_TABLE CLIENT_STATIC_ENTRY_TABLES[];
|
| 46 |
+
|
| 47 |
+
static void* freerdp_channels_find_static_entry_in_table(const STATIC_ENTRY_TABLE* table,
|
| 48 |
+
const char* identifier)
|
| 49 |
+
{
|
| 50 |
+
size_t index = 0;
|
| 51 |
+
const STATIC_ENTRY* pEntry = &table->table.cse[index++];
|
| 52 |
+
|
| 53 |
+
while (pEntry->entry != NULL)
|
| 54 |
+
{
|
| 55 |
+
static_entry_fn_t fkt = pEntry->entry;
|
| 56 |
+
if (strcmp(pEntry->name, identifier) == 0)
|
| 57 |
+
return WINPR_FUNC_PTR_CAST(fkt, void*);
|
| 58 |
+
|
| 59 |
+
pEntry = &table->table.cse[index++];
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
return NULL;
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
void* freerdp_channels_client_find_static_entry(const char* name, const char* identifier)
|
| 66 |
+
{
|
| 67 |
+
size_t index = 0;
|
| 68 |
+
const STATIC_ENTRY_TABLE* pEntry = &CLIENT_STATIC_ENTRY_TABLES[index++];
|
| 69 |
+
|
| 70 |
+
while (pEntry->table.cse != NULL)
|
| 71 |
+
{
|
| 72 |
+
if (strcmp(pEntry->name, name) == 0)
|
| 73 |
+
{
|
| 74 |
+
return freerdp_channels_find_static_entry_in_table(pEntry, identifier);
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
pEntry = &CLIENT_STATIC_ENTRY_TABLES[index++];
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
return NULL;
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
extern const STATIC_ADDIN_TABLE CLIENT_STATIC_ADDIN_TABLE[];
|
| 84 |
+
|
| 85 |
+
static FREERDP_ADDIN** freerdp_channels_list_client_static_addins(LPCSTR pszName,
|
| 86 |
+
LPCSTR pszSubsystem,
|
| 87 |
+
LPCSTR pszType, DWORD dwFlags)
|
| 88 |
+
{
|
| 89 |
+
DWORD nAddins = 0;
|
| 90 |
+
FREERDP_ADDIN** ppAddins = NULL;
|
| 91 |
+
const STATIC_SUBSYSTEM_ENTRY* subsystems = NULL;
|
| 92 |
+
nAddins = 0;
|
| 93 |
+
ppAddins = (FREERDP_ADDIN**)calloc(128, sizeof(FREERDP_ADDIN*));
|
| 94 |
+
|
| 95 |
+
if (!ppAddins)
|
| 96 |
+
{
|
| 97 |
+
WLog_ERR(TAG, "calloc failed!");
|
| 98 |
+
return NULL;
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
ppAddins[nAddins] = NULL;
|
| 102 |
+
|
| 103 |
+
for (size_t i = 0; CLIENT_STATIC_ADDIN_TABLE[i].name != NULL; i++)
|
| 104 |
+
{
|
| 105 |
+
FREERDP_ADDIN* pAddin = (FREERDP_ADDIN*)calloc(1, sizeof(FREERDP_ADDIN));
|
| 106 |
+
const STATIC_ADDIN_TABLE* table = &CLIENT_STATIC_ADDIN_TABLE[i];
|
| 107 |
+
if (!pAddin)
|
| 108 |
+
{
|
| 109 |
+
WLog_ERR(TAG, "calloc failed!");
|
| 110 |
+
goto error_out;
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
(void)sprintf_s(pAddin->cName, ARRAYSIZE(pAddin->cName), "%s", table->name);
|
| 114 |
+
pAddin->dwFlags = FREERDP_ADDIN_CLIENT;
|
| 115 |
+
pAddin->dwFlags |= FREERDP_ADDIN_STATIC;
|
| 116 |
+
pAddin->dwFlags |= FREERDP_ADDIN_NAME;
|
| 117 |
+
ppAddins[nAddins++] = pAddin;
|
| 118 |
+
subsystems = table->table;
|
| 119 |
+
|
| 120 |
+
for (size_t j = 0; subsystems[j].name != NULL; j++)
|
| 121 |
+
{
|
| 122 |
+
pAddin = (FREERDP_ADDIN*)calloc(1, sizeof(FREERDP_ADDIN));
|
| 123 |
+
|
| 124 |
+
if (!pAddin)
|
| 125 |
+
{
|
| 126 |
+
WLog_ERR(TAG, "calloc failed!");
|
| 127 |
+
goto error_out;
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
(void)sprintf_s(pAddin->cName, ARRAYSIZE(pAddin->cName), "%s", table->name);
|
| 131 |
+
(void)sprintf_s(pAddin->cSubsystem, ARRAYSIZE(pAddin->cSubsystem), "%s",
|
| 132 |
+
subsystems[j].name);
|
| 133 |
+
pAddin->dwFlags = FREERDP_ADDIN_CLIENT;
|
| 134 |
+
pAddin->dwFlags |= FREERDP_ADDIN_STATIC;
|
| 135 |
+
pAddin->dwFlags |= FREERDP_ADDIN_NAME;
|
| 136 |
+
pAddin->dwFlags |= FREERDP_ADDIN_SUBSYSTEM;
|
| 137 |
+
ppAddins[nAddins++] = pAddin;
|
| 138 |
+
}
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
return ppAddins;
|
| 142 |
+
error_out:
|
| 143 |
+
freerdp_channels_addin_list_free(ppAddins);
|
| 144 |
+
return NULL;
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
static HANDLE FindFirstFileUTF8(LPCSTR pszSearchPath, WIN32_FIND_DATAW* FindData)
|
| 148 |
+
{
|
| 149 |
+
HANDLE hdl = INVALID_HANDLE_VALUE;
|
| 150 |
+
if (!pszSearchPath)
|
| 151 |
+
return hdl;
|
| 152 |
+
WCHAR* wpath = ConvertUtf8ToWCharAlloc(pszSearchPath, NULL);
|
| 153 |
+
if (!wpath)
|
| 154 |
+
return hdl;
|
| 155 |
+
|
| 156 |
+
hdl = FindFirstFileW(wpath, FindData);
|
| 157 |
+
free(wpath);
|
| 158 |
+
|
| 159 |
+
return hdl;
|
| 160 |
+
}
|
| 161 |
+
|
| 162 |
+
static FREERDP_ADDIN** freerdp_channels_list_dynamic_addins(LPCSTR pszName, LPCSTR pszSubsystem,
|
| 163 |
+
LPCSTR pszType, DWORD dwFlags)
|
| 164 |
+
{
|
| 165 |
+
int nDashes = 0;
|
| 166 |
+
HANDLE hFind = NULL;
|
| 167 |
+
DWORD nAddins = 0;
|
| 168 |
+
LPSTR pszPattern = NULL;
|
| 169 |
+
size_t cchPattern = 0;
|
| 170 |
+
LPCSTR pszAddinPath = FREERDP_ADDIN_PATH;
|
| 171 |
+
LPCSTR pszInstallPrefix = FREERDP_INSTALL_PREFIX;
|
| 172 |
+
LPCSTR pszExtension = NULL;
|
| 173 |
+
LPSTR pszSearchPath = NULL;
|
| 174 |
+
size_t cchSearchPath = 0;
|
| 175 |
+
size_t cchAddinPath = 0;
|
| 176 |
+
size_t cchInstallPrefix = 0;
|
| 177 |
+
FREERDP_ADDIN** ppAddins = NULL;
|
| 178 |
+
WIN32_FIND_DATAW FindData = { 0 };
|
| 179 |
+
cchAddinPath = strnlen(pszAddinPath, sizeof(FREERDP_ADDIN_PATH));
|
| 180 |
+
cchInstallPrefix = strnlen(pszInstallPrefix, sizeof(FREERDP_INSTALL_PREFIX));
|
| 181 |
+
pszExtension = PathGetSharedLibraryExtensionA(0);
|
| 182 |
+
cchPattern = 128 + strnlen(pszExtension, MAX_PATH) + 2;
|
| 183 |
+
pszPattern = (LPSTR)malloc(cchPattern + 1);
|
| 184 |
+
|
| 185 |
+
if (!pszPattern)
|
| 186 |
+
{
|
| 187 |
+
WLog_ERR(TAG, "malloc failed!");
|
| 188 |
+
return NULL;
|
| 189 |
+
}
|
| 190 |
+
|
| 191 |
+
if (pszName && pszSubsystem && pszType)
|
| 192 |
+
{
|
| 193 |
+
(void)sprintf_s(pszPattern, cchPattern, FREERDP_SHARED_LIBRARY_PREFIX "%s-client-%s-%s.%s",
|
| 194 |
+
pszName, pszSubsystem, pszType, pszExtension);
|
| 195 |
+
}
|
| 196 |
+
else if (pszName && pszType)
|
| 197 |
+
{
|
| 198 |
+
(void)sprintf_s(pszPattern, cchPattern, FREERDP_SHARED_LIBRARY_PREFIX "%s-client-?-%s.%s",
|
| 199 |
+
pszName, pszType, pszExtension);
|
| 200 |
+
}
|
| 201 |
+
else if (pszName)
|
| 202 |
+
{
|
| 203 |
+
(void)sprintf_s(pszPattern, cchPattern, FREERDP_SHARED_LIBRARY_PREFIX "%s-client*.%s",
|
| 204 |
+
pszName, pszExtension);
|
| 205 |
+
}
|
| 206 |
+
else
|
| 207 |
+
{
|
| 208 |
+
(void)sprintf_s(pszPattern, cchPattern, FREERDP_SHARED_LIBRARY_PREFIX "?-client*.%s",
|
| 209 |
+
pszExtension);
|
| 210 |
+
}
|
| 211 |
+
|
| 212 |
+
cchPattern = strnlen(pszPattern, cchPattern);
|
| 213 |
+
cchSearchPath = cchInstallPrefix + cchAddinPath + cchPattern + 3;
|
| 214 |
+
pszSearchPath = (LPSTR)calloc(cchSearchPath + 1, sizeof(char));
|
| 215 |
+
|
| 216 |
+
if (!pszSearchPath)
|
| 217 |
+
{
|
| 218 |
+
WLog_ERR(TAG, "malloc failed!");
|
| 219 |
+
free(pszPattern);
|
| 220 |
+
return NULL;
|
| 221 |
+
}
|
| 222 |
+
|
| 223 |
+
CopyMemory(pszSearchPath, pszInstallPrefix, cchInstallPrefix);
|
| 224 |
+
pszSearchPath[cchInstallPrefix] = '\0';
|
| 225 |
+
const HRESULT hr1 = NativePathCchAppendA(pszSearchPath, cchSearchPath + 1, pszAddinPath);
|
| 226 |
+
const HRESULT hr2 = NativePathCchAppendA(pszSearchPath, cchSearchPath + 1, pszPattern);
|
| 227 |
+
free(pszPattern);
|
| 228 |
+
|
| 229 |
+
if (FAILED(hr1) || FAILED(hr2))
|
| 230 |
+
{
|
| 231 |
+
free(pszSearchPath);
|
| 232 |
+
return NULL;
|
| 233 |
+
}
|
| 234 |
+
|
| 235 |
+
hFind = FindFirstFileUTF8(pszSearchPath, &FindData);
|
| 236 |
+
|
| 237 |
+
free(pszSearchPath);
|
| 238 |
+
nAddins = 0;
|
| 239 |
+
ppAddins = (FREERDP_ADDIN**)calloc(128, sizeof(FREERDP_ADDIN*));
|
| 240 |
+
|
| 241 |
+
if (!ppAddins)
|
| 242 |
+
{
|
| 243 |
+
FindClose(hFind);
|
| 244 |
+
WLog_ERR(TAG, "calloc failed!");
|
| 245 |
+
return NULL;
|
| 246 |
+
}
|
| 247 |
+
|
| 248 |
+
if (hFind == INVALID_HANDLE_VALUE)
|
| 249 |
+
return ppAddins;
|
| 250 |
+
|
| 251 |
+
do
|
| 252 |
+
{
|
| 253 |
+
char* cFileName = NULL;
|
| 254 |
+
BOOL used = FALSE;
|
| 255 |
+
FREERDP_ADDIN* pAddin = (FREERDP_ADDIN*)calloc(1, sizeof(FREERDP_ADDIN));
|
| 256 |
+
|
| 257 |
+
if (!pAddin)
|
| 258 |
+
{
|
| 259 |
+
WLog_ERR(TAG, "calloc failed!");
|
| 260 |
+
goto error_out;
|
| 261 |
+
}
|
| 262 |
+
|
| 263 |
+
cFileName =
|
| 264 |
+
ConvertWCharNToUtf8Alloc(FindData.cFileName, ARRAYSIZE(FindData.cFileName), NULL);
|
| 265 |
+
if (!cFileName)
|
| 266 |
+
goto skip;
|
| 267 |
+
|
| 268 |
+
nDashes = 0;
|
| 269 |
+
for (size_t index = 0; cFileName[index]; index++)
|
| 270 |
+
nDashes += (cFileName[index] == '-') ? 1 : 0;
|
| 271 |
+
|
| 272 |
+
if (nDashes == 1)
|
| 273 |
+
{
|
| 274 |
+
size_t len = 0;
|
| 275 |
+
char* p[2] = { 0 };
|
| 276 |
+
/* <name>-client.<extension> */
|
| 277 |
+
p[0] = cFileName;
|
| 278 |
+
p[1] = strchr(p[0], '-');
|
| 279 |
+
if (!p[1])
|
| 280 |
+
goto skip;
|
| 281 |
+
p[1] += 1;
|
| 282 |
+
|
| 283 |
+
len = (size_t)(p[1] - p[0]);
|
| 284 |
+
if (len < 1)
|
| 285 |
+
{
|
| 286 |
+
WLog_WARN(TAG, "Skipping file '%s', invalid format", cFileName);
|
| 287 |
+
goto skip;
|
| 288 |
+
}
|
| 289 |
+
strncpy(pAddin->cName, p[0], MIN(ARRAYSIZE(pAddin->cName), len - 1));
|
| 290 |
+
|
| 291 |
+
pAddin->dwFlags = FREERDP_ADDIN_CLIENT;
|
| 292 |
+
pAddin->dwFlags |= FREERDP_ADDIN_DYNAMIC;
|
| 293 |
+
pAddin->dwFlags |= FREERDP_ADDIN_NAME;
|
| 294 |
+
ppAddins[nAddins++] = pAddin;
|
| 295 |
+
|
| 296 |
+
used = TRUE;
|
| 297 |
+
}
|
| 298 |
+
else if (nDashes == 2)
|
| 299 |
+
{
|
| 300 |
+
size_t len = 0;
|
| 301 |
+
char* p[4] = { 0 };
|
| 302 |
+
/* <name>-client-<subsystem>.<extension> */
|
| 303 |
+
p[0] = cFileName;
|
| 304 |
+
p[1] = strchr(p[0], '-');
|
| 305 |
+
if (!p[1])
|
| 306 |
+
goto skip;
|
| 307 |
+
p[1] += 1;
|
| 308 |
+
p[2] = strchr(p[1], '-');
|
| 309 |
+
if (!p[2])
|
| 310 |
+
goto skip;
|
| 311 |
+
p[2] += 1;
|
| 312 |
+
p[3] = strchr(p[2], '.');
|
| 313 |
+
if (!p[3])
|
| 314 |
+
goto skip;
|
| 315 |
+
p[3] += 1;
|
| 316 |
+
|
| 317 |
+
len = (size_t)(p[1] - p[0]);
|
| 318 |
+
if (len < 1)
|
| 319 |
+
{
|
| 320 |
+
WLog_WARN(TAG, "Skipping file '%s', invalid format", cFileName);
|
| 321 |
+
goto skip;
|
| 322 |
+
}
|
| 323 |
+
strncpy(pAddin->cName, p[0], MIN(ARRAYSIZE(pAddin->cName), len - 1));
|
| 324 |
+
|
| 325 |
+
len = (size_t)(p[3] - p[2]);
|
| 326 |
+
if (len < 1)
|
| 327 |
+
{
|
| 328 |
+
WLog_WARN(TAG, "Skipping file '%s', invalid format", cFileName);
|
| 329 |
+
goto skip;
|
| 330 |
+
}
|
| 331 |
+
strncpy(pAddin->cSubsystem, p[2], MIN(ARRAYSIZE(pAddin->cSubsystem), len - 1));
|
| 332 |
+
|
| 333 |
+
pAddin->dwFlags = FREERDP_ADDIN_CLIENT;
|
| 334 |
+
pAddin->dwFlags |= FREERDP_ADDIN_DYNAMIC;
|
| 335 |
+
pAddin->dwFlags |= FREERDP_ADDIN_NAME;
|
| 336 |
+
pAddin->dwFlags |= FREERDP_ADDIN_SUBSYSTEM;
|
| 337 |
+
ppAddins[nAddins++] = pAddin;
|
| 338 |
+
|
| 339 |
+
used = TRUE;
|
| 340 |
+
}
|
| 341 |
+
else if (nDashes == 3)
|
| 342 |
+
{
|
| 343 |
+
size_t len = 0;
|
| 344 |
+
char* p[5] = { 0 };
|
| 345 |
+
/* <name>-client-<subsystem>-<type>.<extension> */
|
| 346 |
+
p[0] = cFileName;
|
| 347 |
+
p[1] = strchr(p[0], '-');
|
| 348 |
+
if (!p[1])
|
| 349 |
+
goto skip;
|
| 350 |
+
p[1] += 1;
|
| 351 |
+
p[2] = strchr(p[1], '-');
|
| 352 |
+
if (!p[2])
|
| 353 |
+
goto skip;
|
| 354 |
+
p[2] += 1;
|
| 355 |
+
p[3] = strchr(p[2], '-');
|
| 356 |
+
if (!p[3])
|
| 357 |
+
goto skip;
|
| 358 |
+
p[3] += 1;
|
| 359 |
+
p[4] = strchr(p[3], '.');
|
| 360 |
+
if (!p[4])
|
| 361 |
+
goto skip;
|
| 362 |
+
p[4] += 1;
|
| 363 |
+
|
| 364 |
+
len = (size_t)(p[1] - p[0]);
|
| 365 |
+
if (len < 1)
|
| 366 |
+
{
|
| 367 |
+
WLog_WARN(TAG, "Skipping file '%s', invalid format", cFileName);
|
| 368 |
+
goto skip;
|
| 369 |
+
}
|
| 370 |
+
strncpy(pAddin->cName, p[0], MIN(ARRAYSIZE(pAddin->cName), len - 1));
|
| 371 |
+
|
| 372 |
+
len = (size_t)(p[3] - p[2]);
|
| 373 |
+
if (len < 1)
|
| 374 |
+
{
|
| 375 |
+
WLog_WARN(TAG, "Skipping file '%s', invalid format", cFileName);
|
| 376 |
+
goto skip;
|
| 377 |
+
}
|
| 378 |
+
strncpy(pAddin->cSubsystem, p[2], MIN(ARRAYSIZE(pAddin->cSubsystem), len - 1));
|
| 379 |
+
|
| 380 |
+
len = (size_t)(p[4] - p[3]);
|
| 381 |
+
if (len < 1)
|
| 382 |
+
{
|
| 383 |
+
WLog_WARN(TAG, "Skipping file '%s', invalid format", cFileName);
|
| 384 |
+
goto skip;
|
| 385 |
+
}
|
| 386 |
+
strncpy(pAddin->cType, p[3], MIN(ARRAYSIZE(pAddin->cType), len - 1));
|
| 387 |
+
|
| 388 |
+
pAddin->dwFlags = FREERDP_ADDIN_CLIENT;
|
| 389 |
+
pAddin->dwFlags |= FREERDP_ADDIN_DYNAMIC;
|
| 390 |
+
pAddin->dwFlags |= FREERDP_ADDIN_NAME;
|
| 391 |
+
pAddin->dwFlags |= FREERDP_ADDIN_SUBSYSTEM;
|
| 392 |
+
pAddin->dwFlags |= FREERDP_ADDIN_TYPE;
|
| 393 |
+
ppAddins[nAddins++] = pAddin;
|
| 394 |
+
|
| 395 |
+
used = TRUE;
|
| 396 |
+
}
|
| 397 |
+
|
| 398 |
+
skip:
|
| 399 |
+
free(cFileName);
|
| 400 |
+
if (!used)
|
| 401 |
+
free(pAddin);
|
| 402 |
+
|
| 403 |
+
} while (FindNextFileW(hFind, &FindData));
|
| 404 |
+
|
| 405 |
+
FindClose(hFind);
|
| 406 |
+
ppAddins[nAddins] = NULL;
|
| 407 |
+
return ppAddins;
|
| 408 |
+
error_out:
|
| 409 |
+
FindClose(hFind);
|
| 410 |
+
freerdp_channels_addin_list_free(ppAddins);
|
| 411 |
+
return NULL;
|
| 412 |
+
}
|
| 413 |
+
|
| 414 |
+
FREERDP_ADDIN** freerdp_channels_list_addins(LPCSTR pszName, LPCSTR pszSubsystem, LPCSTR pszType,
|
| 415 |
+
DWORD dwFlags)
|
| 416 |
+
{
|
| 417 |
+
if (dwFlags & FREERDP_ADDIN_STATIC)
|
| 418 |
+
return freerdp_channels_list_client_static_addins(pszName, pszSubsystem, pszType, dwFlags);
|
| 419 |
+
else if (dwFlags & FREERDP_ADDIN_DYNAMIC)
|
| 420 |
+
return freerdp_channels_list_dynamic_addins(pszName, pszSubsystem, pszType, dwFlags);
|
| 421 |
+
|
| 422 |
+
return NULL;
|
| 423 |
+
}
|
| 424 |
+
|
| 425 |
+
void freerdp_channels_addin_list_free(FREERDP_ADDIN** ppAddins)
|
| 426 |
+
{
|
| 427 |
+
if (!ppAddins)
|
| 428 |
+
return;
|
| 429 |
+
|
| 430 |
+
for (size_t index = 0; ppAddins[index] != NULL; index++)
|
| 431 |
+
free(ppAddins[index]);
|
| 432 |
+
|
| 433 |
+
free((void*)ppAddins);
|
| 434 |
+
}
|
| 435 |
+
|
| 436 |
+
extern const STATIC_ENTRY CLIENT_VirtualChannelEntryEx_TABLE[];
|
| 437 |
+
|
| 438 |
+
static BOOL freerdp_channels_is_virtual_channel_entry_ex(LPCSTR pszName)
|
| 439 |
+
{
|
| 440 |
+
for (size_t i = 0; CLIENT_VirtualChannelEntryEx_TABLE[i].name != NULL; i++)
|
| 441 |
+
{
|
| 442 |
+
const STATIC_ENTRY* entry = &CLIENT_VirtualChannelEntryEx_TABLE[i];
|
| 443 |
+
|
| 444 |
+
if (!strncmp(entry->name, pszName, MAX_PATH))
|
| 445 |
+
return TRUE;
|
| 446 |
+
}
|
| 447 |
+
|
| 448 |
+
return FALSE;
|
| 449 |
+
}
|
| 450 |
+
|
| 451 |
+
PVIRTUALCHANNELENTRY freerdp_channels_load_static_addin_entry(LPCSTR pszName, LPCSTR pszSubsystem,
|
| 452 |
+
LPCSTR pszType, DWORD dwFlags)
|
| 453 |
+
{
|
| 454 |
+
const STATIC_ADDIN_TABLE* table = CLIENT_STATIC_ADDIN_TABLE;
|
| 455 |
+
const char* type = NULL;
|
| 456 |
+
|
| 457 |
+
if (!pszName)
|
| 458 |
+
return NULL;
|
| 459 |
+
|
| 460 |
+
if (dwFlags & FREERDP_ADDIN_CHANNEL_DYNAMIC)
|
| 461 |
+
type = "DVCPluginEntry";
|
| 462 |
+
else if (dwFlags & FREERDP_ADDIN_CHANNEL_DEVICE)
|
| 463 |
+
type = "DeviceServiceEntry";
|
| 464 |
+
else if (dwFlags & FREERDP_ADDIN_CHANNEL_STATIC)
|
| 465 |
+
{
|
| 466 |
+
if (dwFlags & FREERDP_ADDIN_CHANNEL_ENTRYEX)
|
| 467 |
+
type = "VirtualChannelEntryEx";
|
| 468 |
+
else
|
| 469 |
+
type = "VirtualChannelEntry";
|
| 470 |
+
}
|
| 471 |
+
|
| 472 |
+
for (; table->name != NULL; table++)
|
| 473 |
+
{
|
| 474 |
+
if (strncmp(table->name, pszName, MAX_PATH) == 0)
|
| 475 |
+
{
|
| 476 |
+
if (type && (strncmp(table->type, type, MAX_PATH) != 0))
|
| 477 |
+
continue;
|
| 478 |
+
|
| 479 |
+
if (pszSubsystem != NULL)
|
| 480 |
+
{
|
| 481 |
+
const STATIC_SUBSYSTEM_ENTRY* subsystems = table->table;
|
| 482 |
+
|
| 483 |
+
for (; subsystems->name != NULL; subsystems++)
|
| 484 |
+
{
|
| 485 |
+
/* If the pszSubsystem is an empty string use the default backend. */
|
| 486 |
+
if ((strnlen(pszSubsystem, 1) ==
|
| 487 |
+
0) || /* we only want to know if strnlen is > 0 */
|
| 488 |
+
(strncmp(subsystems->name, pszSubsystem, MAX_PATH) == 0))
|
| 489 |
+
{
|
| 490 |
+
static_subsystem_entry_fn_t fkt = subsystems->entry;
|
| 491 |
+
|
| 492 |
+
if (pszType)
|
| 493 |
+
{
|
| 494 |
+
if (strncmp(subsystems->type, pszType, MAX_PATH) == 0)
|
| 495 |
+
return WINPR_FUNC_PTR_CAST(fkt, PVIRTUALCHANNELENTRY);
|
| 496 |
+
}
|
| 497 |
+
else
|
| 498 |
+
return WINPR_FUNC_PTR_CAST(fkt, PVIRTUALCHANNELENTRY);
|
| 499 |
+
}
|
| 500 |
+
}
|
| 501 |
+
}
|
| 502 |
+
else
|
| 503 |
+
{
|
| 504 |
+
if (dwFlags & FREERDP_ADDIN_CHANNEL_ENTRYEX)
|
| 505 |
+
{
|
| 506 |
+
if (!freerdp_channels_is_virtual_channel_entry_ex(pszName))
|
| 507 |
+
return NULL;
|
| 508 |
+
}
|
| 509 |
+
|
| 510 |
+
return table->entry.csevc;
|
| 511 |
+
}
|
| 512 |
+
}
|
| 513 |
+
}
|
| 514 |
+
|
| 515 |
+
return NULL;
|
| 516 |
+
}
|
| 517 |
+
|
| 518 |
+
typedef struct
|
| 519 |
+
{
|
| 520 |
+
wMessageQueue* queue;
|
| 521 |
+
wStream* data_in;
|
| 522 |
+
HANDLE thread;
|
| 523 |
+
char* channel_name;
|
| 524 |
+
rdpContext* ctx;
|
| 525 |
+
LPVOID userdata;
|
| 526 |
+
MsgHandler msg_handler;
|
| 527 |
+
} msg_proc_internals;
|
| 528 |
+
|
| 529 |
+
static DWORD WINAPI channel_client_thread_proc(LPVOID userdata)
|
| 530 |
+
{
|
| 531 |
+
UINT error = CHANNEL_RC_OK;
|
| 532 |
+
wStream* data = NULL;
|
| 533 |
+
wMessage message = { 0 };
|
| 534 |
+
msg_proc_internals* internals = userdata;
|
| 535 |
+
|
| 536 |
+
WINPR_ASSERT(internals);
|
| 537 |
+
|
| 538 |
+
while (1)
|
| 539 |
+
{
|
| 540 |
+
if (!MessageQueue_Wait(internals->queue))
|
| 541 |
+
{
|
| 542 |
+
WLog_ERR(TAG, "MessageQueue_Wait failed!");
|
| 543 |
+
error = ERROR_INTERNAL_ERROR;
|
| 544 |
+
break;
|
| 545 |
+
}
|
| 546 |
+
if (!MessageQueue_Peek(internals->queue, &message, TRUE))
|
| 547 |
+
{
|
| 548 |
+
WLog_ERR(TAG, "MessageQueue_Peek failed!");
|
| 549 |
+
error = ERROR_INTERNAL_ERROR;
|
| 550 |
+
break;
|
| 551 |
+
}
|
| 552 |
+
|
| 553 |
+
if (message.id == WMQ_QUIT)
|
| 554 |
+
break;
|
| 555 |
+
|
| 556 |
+
if (message.id == 0)
|
| 557 |
+
{
|
| 558 |
+
data = (wStream*)message.wParam;
|
| 559 |
+
|
| 560 |
+
if ((error = internals->msg_handler(internals->userdata, data)))
|
| 561 |
+
{
|
| 562 |
+
WLog_ERR(TAG, "msg_handler failed with error %" PRIu32 "!", error);
|
| 563 |
+
break;
|
| 564 |
+
}
|
| 565 |
+
}
|
| 566 |
+
}
|
| 567 |
+
if (error && internals->ctx)
|
| 568 |
+
{
|
| 569 |
+
char msg[128];
|
| 570 |
+
(void)_snprintf(msg, 127,
|
| 571 |
+
"%s_virtual_channel_client_thread reported an"
|
| 572 |
+
" error",
|
| 573 |
+
internals->channel_name);
|
| 574 |
+
setChannelError(internals->ctx, error, msg);
|
| 575 |
+
}
|
| 576 |
+
ExitThread(error);
|
| 577 |
+
return error;
|
| 578 |
+
}
|
| 579 |
+
|
| 580 |
+
static void free_msg(void* obj)
|
| 581 |
+
{
|
| 582 |
+
wMessage* msg = (wMessage*)obj;
|
| 583 |
+
|
| 584 |
+
if (msg && (msg->id == 0))
|
| 585 |
+
{
|
| 586 |
+
wStream* s = (wStream*)msg->wParam;
|
| 587 |
+
Stream_Free(s, TRUE);
|
| 588 |
+
}
|
| 589 |
+
}
|
| 590 |
+
|
| 591 |
+
static void channel_client_handler_free(msg_proc_internals* internals)
|
| 592 |
+
{
|
| 593 |
+
if (!internals)
|
| 594 |
+
return;
|
| 595 |
+
|
| 596 |
+
if (internals->thread)
|
| 597 |
+
(void)CloseHandle(internals->thread);
|
| 598 |
+
MessageQueue_Free(internals->queue);
|
| 599 |
+
Stream_Free(internals->data_in, TRUE);
|
| 600 |
+
free(internals->channel_name);
|
| 601 |
+
free(internals);
|
| 602 |
+
}
|
| 603 |
+
|
| 604 |
+
/* Create message queue and thread or not, depending on settings */
|
| 605 |
+
void* channel_client_create_handler(rdpContext* ctx, LPVOID userdata, MsgHandler msg_handler,
|
| 606 |
+
const char* channel_name)
|
| 607 |
+
{
|
| 608 |
+
msg_proc_internals* internals = calloc(1, sizeof(msg_proc_internals));
|
| 609 |
+
if (!internals)
|
| 610 |
+
{
|
| 611 |
+
WLog_ERR(TAG, "calloc failed!");
|
| 612 |
+
return NULL;
|
| 613 |
+
}
|
| 614 |
+
internals->msg_handler = msg_handler;
|
| 615 |
+
internals->userdata = userdata;
|
| 616 |
+
if (channel_name)
|
| 617 |
+
{
|
| 618 |
+
internals->channel_name = _strdup(channel_name);
|
| 619 |
+
if (!internals->channel_name)
|
| 620 |
+
goto fail;
|
| 621 |
+
}
|
| 622 |
+
WINPR_ASSERT(ctx);
|
| 623 |
+
WINPR_ASSERT(ctx->settings);
|
| 624 |
+
internals->ctx = ctx;
|
| 625 |
+
if ((freerdp_settings_get_uint32(ctx->settings, FreeRDP_ThreadingFlags) &
|
| 626 |
+
THREADING_FLAGS_DISABLE_THREADS) == 0)
|
| 627 |
+
{
|
| 628 |
+
wObject obj = { 0 };
|
| 629 |
+
obj.fnObjectFree = free_msg;
|
| 630 |
+
internals->queue = MessageQueue_New(&obj);
|
| 631 |
+
if (!internals->queue)
|
| 632 |
+
{
|
| 633 |
+
WLog_ERR(TAG, "MessageQueue_New failed!");
|
| 634 |
+
goto fail;
|
| 635 |
+
}
|
| 636 |
+
|
| 637 |
+
if (!(internals->thread =
|
| 638 |
+
CreateThread(NULL, 0, channel_client_thread_proc, (void*)internals, 0, NULL)))
|
| 639 |
+
{
|
| 640 |
+
WLog_ERR(TAG, "CreateThread failed!");
|
| 641 |
+
goto fail;
|
| 642 |
+
}
|
| 643 |
+
}
|
| 644 |
+
return internals;
|
| 645 |
+
|
| 646 |
+
fail:
|
| 647 |
+
channel_client_handler_free(internals);
|
| 648 |
+
return NULL;
|
| 649 |
+
}
|
| 650 |
+
/* post a message in the queue or directly call the processing handler */
|
| 651 |
+
UINT channel_client_post_message(void* MsgsHandle, LPVOID pData, UINT32 dataLength,
|
| 652 |
+
UINT32 totalLength, UINT32 dataFlags)
|
| 653 |
+
{
|
| 654 |
+
msg_proc_internals* internals = MsgsHandle;
|
| 655 |
+
wStream* data_in = NULL;
|
| 656 |
+
|
| 657 |
+
if (!internals)
|
| 658 |
+
{
|
| 659 |
+
/* TODO: return some error here */
|
| 660 |
+
return CHANNEL_RC_OK;
|
| 661 |
+
}
|
| 662 |
+
|
| 663 |
+
if ((dataFlags & CHANNEL_FLAG_SUSPEND) || (dataFlags & CHANNEL_FLAG_RESUME))
|
| 664 |
+
{
|
| 665 |
+
return CHANNEL_RC_OK;
|
| 666 |
+
}
|
| 667 |
+
|
| 668 |
+
if (dataFlags & CHANNEL_FLAG_FIRST)
|
| 669 |
+
{
|
| 670 |
+
if (internals->data_in)
|
| 671 |
+
{
|
| 672 |
+
if (!Stream_EnsureCapacity(internals->data_in, totalLength))
|
| 673 |
+
return CHANNEL_RC_NO_MEMORY;
|
| 674 |
+
}
|
| 675 |
+
else
|
| 676 |
+
internals->data_in = Stream_New(NULL, totalLength);
|
| 677 |
+
}
|
| 678 |
+
|
| 679 |
+
if (!(data_in = internals->data_in))
|
| 680 |
+
{
|
| 681 |
+
WLog_ERR(TAG, "Stream_New failed!");
|
| 682 |
+
return CHANNEL_RC_NO_MEMORY;
|
| 683 |
+
}
|
| 684 |
+
|
| 685 |
+
if (!Stream_EnsureRemainingCapacity(data_in, dataLength))
|
| 686 |
+
{
|
| 687 |
+
Stream_Free(internals->data_in, TRUE);
|
| 688 |
+
internals->data_in = NULL;
|
| 689 |
+
return CHANNEL_RC_NO_MEMORY;
|
| 690 |
+
}
|
| 691 |
+
|
| 692 |
+
Stream_Write(data_in, pData, dataLength);
|
| 693 |
+
|
| 694 |
+
if (dataFlags & CHANNEL_FLAG_LAST)
|
| 695 |
+
{
|
| 696 |
+
if (Stream_Capacity(data_in) != Stream_GetPosition(data_in))
|
| 697 |
+
{
|
| 698 |
+
char msg[128];
|
| 699 |
+
(void)_snprintf(msg, 127, "%s_plugin_process_received: read error",
|
| 700 |
+
internals->channel_name);
|
| 701 |
+
WLog_ERR(TAG, msg);
|
| 702 |
+
return ERROR_INTERNAL_ERROR;
|
| 703 |
+
}
|
| 704 |
+
|
| 705 |
+
internals->data_in = NULL;
|
| 706 |
+
Stream_SealLength(data_in);
|
| 707 |
+
Stream_SetPosition(data_in, 0);
|
| 708 |
+
|
| 709 |
+
if ((freerdp_settings_get_uint32(internals->ctx->settings, FreeRDP_ThreadingFlags) &
|
| 710 |
+
THREADING_FLAGS_DISABLE_THREADS) != 0)
|
| 711 |
+
{
|
| 712 |
+
UINT error = CHANNEL_RC_OK;
|
| 713 |
+
if ((error = internals->msg_handler(internals->userdata, data_in)))
|
| 714 |
+
{
|
| 715 |
+
WLog_ERR(TAG,
|
| 716 |
+
"msg_handler failed with error"
|
| 717 |
+
" %" PRIu32 "!",
|
| 718 |
+
error);
|
| 719 |
+
return ERROR_INTERNAL_ERROR;
|
| 720 |
+
}
|
| 721 |
+
}
|
| 722 |
+
else if (!MessageQueue_Post(internals->queue, NULL, 0, (void*)data_in, NULL))
|
| 723 |
+
{
|
| 724 |
+
WLog_ERR(TAG, "MessageQueue_Post failed!");
|
| 725 |
+
return ERROR_INTERNAL_ERROR;
|
| 726 |
+
}
|
| 727 |
+
}
|
| 728 |
+
return CHANNEL_RC_OK;
|
| 729 |
+
}
|
| 730 |
+
/* Tear down queue and thread */
|
| 731 |
+
UINT channel_client_quit_handler(void* MsgsHandle)
|
| 732 |
+
{
|
| 733 |
+
msg_proc_internals* internals = MsgsHandle;
|
| 734 |
+
UINT rc = 0;
|
| 735 |
+
if (!internals)
|
| 736 |
+
{
|
| 737 |
+
/* TODO: return some error here */
|
| 738 |
+
return CHANNEL_RC_OK;
|
| 739 |
+
}
|
| 740 |
+
|
| 741 |
+
WINPR_ASSERT(internals->ctx);
|
| 742 |
+
WINPR_ASSERT(internals->ctx->settings);
|
| 743 |
+
|
| 744 |
+
if ((freerdp_settings_get_uint32(internals->ctx->settings, FreeRDP_ThreadingFlags) &
|
| 745 |
+
THREADING_FLAGS_DISABLE_THREADS) == 0)
|
| 746 |
+
{
|
| 747 |
+
if (internals->queue && internals->thread)
|
| 748 |
+
{
|
| 749 |
+
if (MessageQueue_PostQuit(internals->queue, 0) &&
|
| 750 |
+
(WaitForSingleObject(internals->thread, INFINITE) == WAIT_FAILED))
|
| 751 |
+
{
|
| 752 |
+
rc = GetLastError();
|
| 753 |
+
WLog_ERR(TAG, "WaitForSingleObject failed with error %" PRIu32 "", rc);
|
| 754 |
+
return rc;
|
| 755 |
+
}
|
| 756 |
+
}
|
| 757 |
+
}
|
| 758 |
+
|
| 759 |
+
channel_client_handler_free(internals);
|
| 760 |
+
return CHANNEL_RC_OK;
|
| 761 |
+
}
|
local-test-freerdp-delta-01/afc-freerdp/channels/client/addin.h
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* FreeRDP: A Remote Desktop Protocol Implementation
|
| 3 |
+
* Channel Addins
|
| 4 |
+
*
|
| 5 |
+
* Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
| 6 |
+
*
|
| 7 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 8 |
+
* you may not use this file except in compliance with the License.
|
| 9 |
+
* You may obtain a copy of the License at
|
| 10 |
+
*
|
| 11 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
+
*
|
| 13 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 14 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 15 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 16 |
+
* See the License for the specific language governing permissions and
|
| 17 |
+
* limitations under the License.
|
| 18 |
+
*/
|
| 19 |
+
|
| 20 |
+
typedef UINT (*MsgHandler)(LPVOID userdata, wStream* data);
|
| 21 |
+
|
| 22 |
+
FREERDP_API void* channel_client_create_handler(rdpContext* ctx, LPVOID userdata,
|
| 23 |
+
MsgHandler handler, const char* channel_name);
|
| 24 |
+
|
| 25 |
+
UINT channel_client_post_message(void* MsgsHandle, LPVOID pData, UINT32 dataLength,
|
| 26 |
+
UINT32 totalLength, UINT32 dataFlags);
|
| 27 |
+
|
| 28 |
+
UINT channel_client_quit_handler(void* MsgsHandle);
|
local-test-freerdp-delta-01/afc-freerdp/channels/client/generic_dynvc.c
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* FreeRDP: A Remote Desktop Protocol Implementation
|
| 3 |
+
* Dynamic channel
|
| 4 |
+
*
|
| 5 |
+
* Copyright 2022 David Fort <contact@hardening-consulting.com>
|
| 6 |
+
*
|
| 7 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 8 |
+
* you may not use this file except in compliance with the License.
|
| 9 |
+
* You may obtain a copy of the License at
|
| 10 |
+
*
|
| 11 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
+
*
|
| 13 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 14 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 15 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 16 |
+
* See the License for the specific language governing permissions and
|
| 17 |
+
* limitations under the License.
|
| 18 |
+
*/
|
| 19 |
+
|
| 20 |
+
#include <freerdp/config.h>
|
| 21 |
+
#include <freerdp/log.h>
|
| 22 |
+
#include <freerdp/client/channels.h>
|
| 23 |
+
|
| 24 |
+
#define TAG FREERDP_TAG("genericdynvc")
|
| 25 |
+
|
| 26 |
+
static UINT generic_on_new_channel_connection(IWTSListenerCallback* pListenerCallback,
|
| 27 |
+
IWTSVirtualChannel* pChannel, BYTE* Data,
|
| 28 |
+
BOOL* pbAccept,
|
| 29 |
+
IWTSVirtualChannelCallback** ppCallback)
|
| 30 |
+
{
|
| 31 |
+
GENERIC_CHANNEL_CALLBACK* callback = NULL;
|
| 32 |
+
GENERIC_DYNVC_PLUGIN* plugin = NULL;
|
| 33 |
+
GENERIC_LISTENER_CALLBACK* listener_callback = (GENERIC_LISTENER_CALLBACK*)pListenerCallback;
|
| 34 |
+
|
| 35 |
+
if (!listener_callback || !listener_callback->plugin)
|
| 36 |
+
return ERROR_INTERNAL_ERROR;
|
| 37 |
+
|
| 38 |
+
plugin = (GENERIC_DYNVC_PLUGIN*)listener_callback->plugin;
|
| 39 |
+
WLog_Print(plugin->log, WLOG_TRACE, "...");
|
| 40 |
+
|
| 41 |
+
callback = (GENERIC_CHANNEL_CALLBACK*)calloc(1, plugin->channelCallbackSize);
|
| 42 |
+
if (!callback)
|
| 43 |
+
{
|
| 44 |
+
WLog_Print(plugin->log, WLOG_ERROR, "calloc failed!");
|
| 45 |
+
return CHANNEL_RC_NO_MEMORY;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
/* implant configured channel callbacks */
|
| 49 |
+
callback->iface = *plugin->channel_callbacks;
|
| 50 |
+
|
| 51 |
+
callback->plugin = listener_callback->plugin;
|
| 52 |
+
callback->channel_mgr = listener_callback->channel_mgr;
|
| 53 |
+
callback->channel = pChannel;
|
| 54 |
+
|
| 55 |
+
listener_callback->channel_callback = callback;
|
| 56 |
+
listener_callback->channel = pChannel;
|
| 57 |
+
|
| 58 |
+
*ppCallback = (IWTSVirtualChannelCallback*)callback;
|
| 59 |
+
return CHANNEL_RC_OK;
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
static UINT generic_dynvc_plugin_initialize(IWTSPlugin* pPlugin,
|
| 63 |
+
IWTSVirtualChannelManager* pChannelMgr)
|
| 64 |
+
{
|
| 65 |
+
UINT rc = 0;
|
| 66 |
+
GENERIC_LISTENER_CALLBACK* listener_callback = NULL;
|
| 67 |
+
GENERIC_DYNVC_PLUGIN* plugin = (GENERIC_DYNVC_PLUGIN*)pPlugin;
|
| 68 |
+
|
| 69 |
+
if (!plugin)
|
| 70 |
+
return CHANNEL_RC_BAD_CHANNEL_HANDLE;
|
| 71 |
+
|
| 72 |
+
if (!pChannelMgr)
|
| 73 |
+
return ERROR_INVALID_PARAMETER;
|
| 74 |
+
|
| 75 |
+
if (plugin->initialized)
|
| 76 |
+
{
|
| 77 |
+
WLog_ERR(TAG, "[%s] channel initialized twice, aborting", plugin->dynvc_name);
|
| 78 |
+
return ERROR_INVALID_DATA;
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
WLog_Print(plugin->log, WLOG_TRACE, "...");
|
| 82 |
+
listener_callback = (GENERIC_LISTENER_CALLBACK*)calloc(1, sizeof(GENERIC_LISTENER_CALLBACK));
|
| 83 |
+
if (!listener_callback)
|
| 84 |
+
{
|
| 85 |
+
WLog_Print(plugin->log, WLOG_ERROR, "calloc failed!");
|
| 86 |
+
return CHANNEL_RC_NO_MEMORY;
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
plugin->listener_callback = listener_callback;
|
| 90 |
+
listener_callback->iface.OnNewChannelConnection = generic_on_new_channel_connection;
|
| 91 |
+
listener_callback->plugin = pPlugin;
|
| 92 |
+
listener_callback->channel_mgr = pChannelMgr;
|
| 93 |
+
rc = pChannelMgr->CreateListener(pChannelMgr, plugin->dynvc_name, 0, &listener_callback->iface,
|
| 94 |
+
&plugin->listener);
|
| 95 |
+
|
| 96 |
+
plugin->listener->pInterface = plugin->iface.pInterface;
|
| 97 |
+
plugin->initialized = (rc == CHANNEL_RC_OK);
|
| 98 |
+
return rc;
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
static UINT generic_plugin_terminated(IWTSPlugin* pPlugin)
|
| 102 |
+
{
|
| 103 |
+
GENERIC_DYNVC_PLUGIN* plugin = (GENERIC_DYNVC_PLUGIN*)pPlugin;
|
| 104 |
+
UINT error = CHANNEL_RC_OK;
|
| 105 |
+
|
| 106 |
+
if (!plugin)
|
| 107 |
+
return CHANNEL_RC_BAD_CHANNEL_HANDLE;
|
| 108 |
+
|
| 109 |
+
WLog_Print(plugin->log, WLOG_TRACE, "...");
|
| 110 |
+
|
| 111 |
+
/* some channels (namely rdpei), look at initialized to see if they should continue to run */
|
| 112 |
+
plugin->initialized = FALSE;
|
| 113 |
+
|
| 114 |
+
if (plugin->terminatePluginFn)
|
| 115 |
+
plugin->terminatePluginFn(plugin);
|
| 116 |
+
|
| 117 |
+
if (plugin->listener_callback)
|
| 118 |
+
{
|
| 119 |
+
IWTSVirtualChannelManager* mgr = plugin->listener_callback->channel_mgr;
|
| 120 |
+
if (mgr)
|
| 121 |
+
IFCALL(mgr->DestroyListener, mgr, plugin->listener);
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
free(plugin->listener_callback);
|
| 125 |
+
free(plugin->dynvc_name);
|
| 126 |
+
free(plugin);
|
| 127 |
+
return error;
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
static UINT generic_dynvc_plugin_attached(IWTSPlugin* pPlugin)
|
| 131 |
+
{
|
| 132 |
+
GENERIC_DYNVC_PLUGIN* pluginn = (GENERIC_DYNVC_PLUGIN*)pPlugin;
|
| 133 |
+
UINT error = CHANNEL_RC_OK;
|
| 134 |
+
|
| 135 |
+
if (!pluginn)
|
| 136 |
+
return CHANNEL_RC_BAD_CHANNEL_HANDLE;
|
| 137 |
+
|
| 138 |
+
pluginn->attached = TRUE;
|
| 139 |
+
return error;
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
static UINT generic_dynvc_plugin_detached(IWTSPlugin* pPlugin)
|
| 143 |
+
{
|
| 144 |
+
GENERIC_DYNVC_PLUGIN* plugin = (GENERIC_DYNVC_PLUGIN*)pPlugin;
|
| 145 |
+
UINT error = CHANNEL_RC_OK;
|
| 146 |
+
|
| 147 |
+
if (!plugin)
|
| 148 |
+
return CHANNEL_RC_BAD_CHANNEL_HANDLE;
|
| 149 |
+
|
| 150 |
+
plugin->attached = FALSE;
|
| 151 |
+
return error;
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
UINT freerdp_generic_DVCPluginEntry(IDRDYNVC_ENTRY_POINTS* pEntryPoints, const char* logTag,
|
| 155 |
+
const char* name, size_t pluginSize, size_t channelCallbackSize,
|
| 156 |
+
const IWTSVirtualChannelCallback* channel_callbacks,
|
| 157 |
+
DYNVC_PLUGIN_INIT_FN initPluginFn,
|
| 158 |
+
DYNVC_PLUGIN_TERMINATE_FN terminatePluginFn)
|
| 159 |
+
{
|
| 160 |
+
GENERIC_DYNVC_PLUGIN* plugin = NULL;
|
| 161 |
+
UINT error = CHANNEL_RC_INITIALIZATION_ERROR;
|
| 162 |
+
|
| 163 |
+
WINPR_ASSERT(pEntryPoints);
|
| 164 |
+
WINPR_ASSERT(pEntryPoints->GetPlugin);
|
| 165 |
+
WINPR_ASSERT(logTag);
|
| 166 |
+
WINPR_ASSERT(name);
|
| 167 |
+
WINPR_ASSERT(pluginSize >= sizeof(*plugin));
|
| 168 |
+
WINPR_ASSERT(channelCallbackSize >= sizeof(GENERIC_CHANNEL_CALLBACK));
|
| 169 |
+
|
| 170 |
+
plugin = (GENERIC_DYNVC_PLUGIN*)pEntryPoints->GetPlugin(pEntryPoints, name);
|
| 171 |
+
if (plugin != NULL)
|
| 172 |
+
return CHANNEL_RC_ALREADY_INITIALIZED;
|
| 173 |
+
|
| 174 |
+
plugin = (GENERIC_DYNVC_PLUGIN*)calloc(1, pluginSize);
|
| 175 |
+
if (!plugin)
|
| 176 |
+
{
|
| 177 |
+
WLog_ERR(TAG, "calloc failed!");
|
| 178 |
+
return CHANNEL_RC_NO_MEMORY;
|
| 179 |
+
}
|
| 180 |
+
|
| 181 |
+
plugin->log = WLog_Get(logTag);
|
| 182 |
+
plugin->attached = TRUE;
|
| 183 |
+
plugin->channel_callbacks = channel_callbacks;
|
| 184 |
+
plugin->channelCallbackSize = channelCallbackSize;
|
| 185 |
+
plugin->iface.Initialize = generic_dynvc_plugin_initialize;
|
| 186 |
+
plugin->iface.Connected = NULL;
|
| 187 |
+
plugin->iface.Disconnected = NULL;
|
| 188 |
+
plugin->iface.Terminated = generic_plugin_terminated;
|
| 189 |
+
plugin->iface.Attached = generic_dynvc_plugin_attached;
|
| 190 |
+
plugin->iface.Detached = generic_dynvc_plugin_detached;
|
| 191 |
+
plugin->terminatePluginFn = terminatePluginFn;
|
| 192 |
+
|
| 193 |
+
if (initPluginFn)
|
| 194 |
+
{
|
| 195 |
+
rdpSettings* settings = pEntryPoints->GetRdpSettings(pEntryPoints);
|
| 196 |
+
rdpContext* context = pEntryPoints->GetRdpContext(pEntryPoints);
|
| 197 |
+
|
| 198 |
+
error = initPluginFn(plugin, context, settings);
|
| 199 |
+
if (error != CHANNEL_RC_OK)
|
| 200 |
+
goto error;
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
plugin->dynvc_name = _strdup(name);
|
| 204 |
+
if (!plugin->dynvc_name)
|
| 205 |
+
goto error;
|
| 206 |
+
|
| 207 |
+
error = pEntryPoints->RegisterPlugin(pEntryPoints, name, &plugin->iface);
|
| 208 |
+
if (error == CHANNEL_RC_OK)
|
| 209 |
+
return error;
|
| 210 |
+
|
| 211 |
+
error:
|
| 212 |
+
generic_plugin_terminated(&plugin->iface);
|
| 213 |
+
return error;
|
| 214 |
+
}
|
local-test-freerdp-delta-01/afc-freerdp/channels/client/tables.c.in
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* FreeRDP: A Remote Desktop Protocol Implementation
|
| 3 |
+
* Static Entry Point Tables
|
| 4 |
+
*
|
| 5 |
+
* Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
| 6 |
+
* Copyright 2015 Thincast Technologies GmbH
|
| 7 |
+
* Copyright 2015 DI (FH) Martin Haimberger <martin.haimberger@thincast.com>
|
| 8 |
+
*
|
| 9 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 10 |
+
* you may not use this file except in compliance with the License.
|
| 11 |
+
* You may obtain a copy of the License at
|
| 12 |
+
*
|
| 13 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 14 |
+
*
|
| 15 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 16 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 17 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 18 |
+
* See the License for the specific language governing permissions and
|
| 19 |
+
* limitations under the License.
|
| 20 |
+
*/
|
| 21 |
+
|
| 22 |
+
#include <freerdp/dvc.h>
|
| 23 |
+
#include <freerdp/channels/rdpdr.h>
|
| 24 |
+
#include "tables.h"
|
| 25 |
+
|
| 26 |
+
${CLIENT_STATIC_TYPEDEFS}
|
| 27 |
+
${CLIENT_STATIC_ENTRY_IMPORTS}
|
| 28 |
+
${CLIENT_STATIC_SUBSYSTEM_IMPORTS}
|
| 29 |
+
${CLIENT_STATIC_ENTRY_TABLES}
|
| 30 |
+
${CLIENT_STATIC_ENTRY_TABLES_LIST}
|
| 31 |
+
${CLIENT_STATIC_SUBSYSTEM_TABLES}
|
| 32 |
+
${CLIENT_STATIC_ADDIN_TABLE}
|
| 33 |
+
|
local-test-freerdp-delta-01/afc-freerdp/channels/client/tables.h
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* FreeRDP: A Remote Desktop Protocol Implementation
|
| 3 |
+
* Static Entry Point Tables
|
| 4 |
+
*
|
| 5 |
+
* Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
| 6 |
+
*
|
| 7 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 8 |
+
* you may not use this file except in compliance with the License.
|
| 9 |
+
* You may obtain a copy of the License at
|
| 10 |
+
*
|
| 11 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
+
*
|
| 13 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 14 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 15 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 16 |
+
* See the License for the specific language governing permissions and
|
| 17 |
+
* limitations under the License.
|
| 18 |
+
*/
|
| 19 |
+
|
| 20 |
+
#include <winpr/platform.h>
|
| 21 |
+
#include <winpr/wtsapi.h>
|
| 22 |
+
#include <freerdp/svc.h>
|
| 23 |
+
#include <freerdp/dvc.h>
|
| 24 |
+
#include <freerdp/channels/rdpdr.h>
|
| 25 |
+
|
| 26 |
+
/* The 'entry' function pointers have variable arguments. */
|
| 27 |
+
WINPR_PRAGMA_DIAG_PUSH
|
| 28 |
+
WINPR_PRAGMA_DIAG_IGNORED_STRICT_PROTOTYPES
|
| 29 |
+
|
| 30 |
+
typedef UINT(VCAPITYPE* static_entry_fn_t)();
|
| 31 |
+
typedef struct
|
| 32 |
+
{
|
| 33 |
+
const char* name;
|
| 34 |
+
static_entry_fn_t entry;
|
| 35 |
+
} STATIC_ENTRY;
|
| 36 |
+
|
| 37 |
+
typedef BOOL(VCAPITYPE* static_entry_vc_fn_t)(PCHANNEL_ENTRY_POINTS);
|
| 38 |
+
typedef struct
|
| 39 |
+
{
|
| 40 |
+
const char* name;
|
| 41 |
+
static_entry_vc_fn_t entry;
|
| 42 |
+
} STATIC_ENTRY_VC;
|
| 43 |
+
|
| 44 |
+
typedef BOOL(VCAPITYPE* static_entry_vcex_fn_t)(PCHANNEL_ENTRY_POINTS, PVOID);
|
| 45 |
+
typedef struct
|
| 46 |
+
{
|
| 47 |
+
const char* name;
|
| 48 |
+
static_entry_vcex_fn_t entry;
|
| 49 |
+
} STATIC_ENTRY_VCEX;
|
| 50 |
+
|
| 51 |
+
typedef UINT(VCAPITYPE* static_entry_dvc_fn_t)(IDRDYNVC_ENTRY_POINTS*);
|
| 52 |
+
typedef struct
|
| 53 |
+
{
|
| 54 |
+
const char* name;
|
| 55 |
+
static_entry_dvc_fn_t entry;
|
| 56 |
+
} STATIC_ENTRY_DVC;
|
| 57 |
+
|
| 58 |
+
typedef UINT(VCAPITYPE* static_entry_dse_fn_t)(PDEVICE_SERVICE_ENTRY_POINTS);
|
| 59 |
+
typedef struct
|
| 60 |
+
{
|
| 61 |
+
const char* name;
|
| 62 |
+
static_entry_dse_fn_t entry;
|
| 63 |
+
} STATIC_ENTRY_DSE;
|
| 64 |
+
|
| 65 |
+
typedef union
|
| 66 |
+
{
|
| 67 |
+
const STATIC_ENTRY* cse;
|
| 68 |
+
const STATIC_ENTRY_VC* csevc;
|
| 69 |
+
const STATIC_ENTRY_VCEX* csevcex;
|
| 70 |
+
const STATIC_ENTRY_DVC* csedvc;
|
| 71 |
+
const STATIC_ENTRY_DSE* csedse;
|
| 72 |
+
} static_entry_u;
|
| 73 |
+
|
| 74 |
+
typedef union
|
| 75 |
+
{
|
| 76 |
+
static_entry_fn_t cse;
|
| 77 |
+
static_entry_vc_fn_t csevc;
|
| 78 |
+
static_entry_vcex_fn_t csevcex;
|
| 79 |
+
static_entry_dvc_fn_t csedvc;
|
| 80 |
+
static_entry_dse_fn_t csedse;
|
| 81 |
+
} static_entry_fn_u;
|
| 82 |
+
|
| 83 |
+
typedef struct
|
| 84 |
+
{
|
| 85 |
+
const char* name;
|
| 86 |
+
static_entry_u table;
|
| 87 |
+
} STATIC_ENTRY_TABLE;
|
| 88 |
+
|
| 89 |
+
typedef UINT(VCAPITYPE* static_subsystem_entry_fn_t)(void*);
|
| 90 |
+
typedef struct
|
| 91 |
+
{
|
| 92 |
+
const char* name;
|
| 93 |
+
const char* type;
|
| 94 |
+
static_subsystem_entry_fn_t entry;
|
| 95 |
+
} STATIC_SUBSYSTEM_ENTRY;
|
| 96 |
+
|
| 97 |
+
typedef struct
|
| 98 |
+
{
|
| 99 |
+
const char* name;
|
| 100 |
+
const char* type;
|
| 101 |
+
static_entry_fn_u entry;
|
| 102 |
+
const STATIC_SUBSYSTEM_ENTRY* table;
|
| 103 |
+
} STATIC_ADDIN_TABLE;
|
| 104 |
+
|
| 105 |
+
WINPR_PRAGMA_DIAG_POP
|
local-test-freerdp-delta-01/afc-freerdp/channels/cliprdr/CMakeLists.txt
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# FreeRDP: A Remote Desktop Protocol Implementation
|
| 2 |
+
# FreeRDP cmake build script
|
| 3 |
+
#
|
| 4 |
+
# Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
| 5 |
+
#
|
| 6 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 7 |
+
# you may not use this file except in compliance with the License.
|
| 8 |
+
# You may obtain a copy of the License at
|
| 9 |
+
#
|
| 10 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 11 |
+
#
|
| 12 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 13 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 14 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 15 |
+
# See the License for the specific language governing permissions and
|
| 16 |
+
# limitations under the License.
|
| 17 |
+
|
| 18 |
+
define_channel("cliprdr")
|
| 19 |
+
|
| 20 |
+
if(WITH_CLIENT_CHANNELS)
|
| 21 |
+
add_channel_client(${MODULE_PREFIX} ${CHANNEL_NAME})
|
| 22 |
+
endif()
|
| 23 |
+
|
| 24 |
+
if(WITH_SERVER_CHANNELS)
|
| 25 |
+
add_channel_server(${MODULE_PREFIX} ${CHANNEL_NAME})
|
| 26 |
+
endif()
|
local-test-freerdp-delta-01/afc-freerdp/channels/cliprdr/ChannelOptions.cmake
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
set(OPTION_DEFAULT ON)
|
| 2 |
+
set(OPTION_CLIENT_DEFAULT ON)
|
| 3 |
+
set(OPTION_SERVER_DEFAULT ON)
|
| 4 |
+
|
| 5 |
+
define_channel_options(
|
| 6 |
+
NAME
|
| 7 |
+
"cliprdr"
|
| 8 |
+
TYPE
|
| 9 |
+
"static"
|
| 10 |
+
DESCRIPTION
|
| 11 |
+
"Clipboard Virtual Channel Extension"
|
| 12 |
+
SPECIFICATIONS
|
| 13 |
+
"[MS-RDPECLIP]"
|
| 14 |
+
DEFAULT
|
| 15 |
+
${OPTION_DEFAULT}
|
| 16 |
+
CLIENT_DEFAULT
|
| 17 |
+
${OPTION_CLIENT_DEFAULT}
|
| 18 |
+
SERVER_DEFAULT
|
| 19 |
+
${OPTION_SERVER_DEFAULT}
|
| 20 |
+
)
|
local-test-freerdp-delta-01/afc-freerdp/channels/cliprdr/client/CMakeLists.txt
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# FreeRDP: A Remote Desktop Protocol Implementation
|
| 2 |
+
# FreeRDP cmake build script
|
| 3 |
+
#
|
| 4 |
+
# Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
| 5 |
+
#
|
| 6 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 7 |
+
# you may not use this file except in compliance with the License.
|
| 8 |
+
# You may obtain a copy of the License at
|
| 9 |
+
#
|
| 10 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 11 |
+
#
|
| 12 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 13 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 14 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 15 |
+
# See the License for the specific language governing permissions and
|
| 16 |
+
# limitations under the License.
|
| 17 |
+
|
| 18 |
+
define_channel_client("cliprdr")
|
| 19 |
+
|
| 20 |
+
set(${MODULE_PREFIX}_SRCS cliprdr_format.c cliprdr_format.h cliprdr_main.c cliprdr_main.h ../cliprdr_common.h
|
| 21 |
+
../cliprdr_common.c
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* FreeRDP: A Remote Desktop Protocol Implementation
|
| 3 |
+
* Clipboard Virtual Channel
|
| 4 |
+
*
|
| 5 |
+
* Copyright 2009-2011 Jay Sorg
|
| 6 |
+
* Copyright 2010-2011 Vic Lee
|
| 7 |
+
* Copyright 2015 Thincast Technologies GmbH
|
| 8 |
+
* Copyright 2015 DI (FH) Martin Haimberger <martin.haimberger@thincast.com>
|
| 9 |
+
*
|
| 10 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 11 |
+
* you may not use this file except in compliance with the License.
|
| 12 |
+
* You may obtain a copy of the License at
|
| 13 |
+
*
|
| 14 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 15 |
+
*
|
| 16 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 17 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 18 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 19 |
+
* See the License for the specific language governing permissions and
|
| 20 |
+
* limitations under the License.
|
| 21 |
+
*/
|
| 22 |
+
|
| 23 |
+
#include <freerdp/config.h>
|
| 24 |
+
|
| 25 |
+
#include <winpr/crt.h>
|
| 26 |
+
#include <winpr/print.h>
|
| 27 |
+
|
| 28 |
+
#include <freerdp/types.h>
|
| 29 |
+
#include <freerdp/freerdp.h>
|
| 30 |
+
#include <freerdp/settings.h>
|
| 31 |
+
#include <freerdp/constants.h>
|
| 32 |
+
#include <freerdp/client/cliprdr.h>
|
| 33 |
+
|
| 34 |
+
#include "cliprdr_main.h"
|
| 35 |
+
#include "cliprdr_format.h"
|
| 36 |
+
#include "../cliprdr_common.h"
|
| 37 |
+
|
| 38 |
+
CLIPRDR_FORMAT_LIST cliprdr_filter_format_list(const CLIPRDR_FORMAT_LIST* list, const UINT32 mask,
|
| 39 |
+
const UINT32 checkMask)
|
| 40 |
+
{
|
| 41 |
+
const UINT32 maskData =
|
| 42 |
+
checkMask & (CLIPRDR_FLAG_LOCAL_TO_REMOTE | CLIPRDR_FLAG_REMOTE_TO_LOCAL);
|
| 43 |
+
const UINT32 maskFiles =
|
| 44 |
+
checkMask & (CLIPRDR_FLAG_LOCAL_TO_REMOTE_FILES | CLIPRDR_FLAG_REMOTE_TO_LOCAL_FILES);
|
| 45 |
+
WINPR_ASSERT(list);
|
| 46 |
+
|
| 47 |
+
CLIPRDR_FORMAT_LIST filtered = { 0 };
|
| 48 |
+
filtered.common.msgType = CB_FORMAT_LIST;
|
| 49 |
+
filtered.numFormats = list->numFormats;
|
| 50 |
+
filtered.formats = calloc(filtered.numFormats, sizeof(CLIPRDR_FORMAT));
|
| 51 |
+
|
| 52 |
+
size_t wpos = 0;
|
| 53 |
+
if ((mask & checkMask) == checkMask)
|
| 54 |
+
{
|
| 55 |
+
for (size_t x = 0; x < list->numFormats; x++)
|
| 56 |
+
{
|
| 57 |
+
const CLIPRDR_FORMAT* format = &list->formats[x];
|
| 58 |
+
CLIPRDR_FORMAT* cur = &filtered.formats[x];
|
| 59 |
+
cur->formatId = format->formatId;
|
| 60 |
+
if (format->formatName)
|
| 61 |
+
cur->formatName = _strdup(format->formatName);
|
| 62 |
+
wpos++;
|
| 63 |
+
}
|
| 64 |
+
}
|
| 65 |
+
else if ((mask & maskFiles) != 0)
|
| 66 |
+
{
|
| 67 |
+
for (size_t x = 0; x < list->numFormats; x++)
|
| 68 |
+
{
|
| 69 |
+
const CLIPRDR_FORMAT* format = &list->formats[x];
|
| 70 |
+
CLIPRDR_FORMAT* cur = &filtered.formats[wpos];
|
| 71 |
+
|
| 72 |
+
if (!format->formatName)
|
| 73 |
+
continue;
|
| 74 |
+
if (strcmp(format->formatName, type_FileGroupDescriptorW) == 0 ||
|
| 75 |
+
strcmp(format->formatName, type_FileContents) == 0)
|
| 76 |
+
{
|
| 77 |
+
cur->formatId = format->formatId;
|
| 78 |
+
cur->formatName = _strdup(format->formatName);
|
| 79 |
+
wpos++;
|
| 80 |
+
}
|
| 81 |
+
}
|
| 82 |
+
}
|
| 83 |
+
else if ((mask & maskData) != 0)
|
| 84 |
+
{
|
| 85 |
+
for (size_t x = 0; x < list->numFormats; x++)
|
| 86 |
+
{
|
| 87 |
+
const CLIPRDR_FORMAT* format = &list->formats[x];
|
| 88 |
+
CLIPRDR_FORMAT* cur = &filtered.formats[wpos];
|
| 89 |
+
|
| 90 |
+
if (!format->formatName ||
|
| 91 |
+
(strcmp(format->formatName, type_FileGroupDescriptorW) != 0 &&
|
| 92 |
+
strcmp(format->formatName, type_FileContents) != 0))
|
| 93 |
+
{
|
| 94 |
+
cur->formatId = format->formatId;
|
| 95 |
+
if (format->formatName)
|
| 96 |
+
cur->formatName = _strdup(format->formatName);
|
| 97 |
+
wpos++;
|
| 98 |
+
}
|
| 99 |
+
}
|
| 100 |
+
}
|
| 101 |
+
WINPR_ASSERT(wpos <= UINT32_MAX);
|
| 102 |
+
filtered.numFormats = (UINT32)wpos;
|
| 103 |
+
return filtered;
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
/**
|
| 107 |
+
* Function description
|
| 108 |
+
*
|
| 109 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 110 |
+
*/
|
| 111 |
+
UINT cliprdr_process_format_list(cliprdrPlugin* cliprdr, wStream* s, UINT32 dataLen,
|
| 112 |
+
UINT16 msgFlags)
|
| 113 |
+
{
|
| 114 |
+
CLIPRDR_FORMAT_LIST formatList = { 0 };
|
| 115 |
+
CLIPRDR_FORMAT_LIST filteredFormatList = { 0 };
|
| 116 |
+
CliprdrClientContext* context = cliprdr_get_client_interface(cliprdr);
|
| 117 |
+
UINT error = CHANNEL_RC_OK;
|
| 118 |
+
|
| 119 |
+
formatList.common.msgType = CB_FORMAT_LIST;
|
| 120 |
+
formatList.common.msgFlags = msgFlags;
|
| 121 |
+
formatList.common.dataLen = dataLen;
|
| 122 |
+
|
| 123 |
+
if ((error = cliprdr_read_format_list(s, &formatList, cliprdr->useLongFormatNames)))
|
| 124 |
+
goto error_out;
|
| 125 |
+
|
| 126 |
+
const UINT32 mask =
|
| 127 |
+
freerdp_settings_get_uint32(context->rdpcontext->settings, FreeRDP_ClipboardFeatureMask);
|
| 128 |
+
filteredFormatList = cliprdr_filter_format_list(
|
| 129 |
+
&formatList, mask, CLIPRDR_FLAG_REMOTE_TO_LOCAL | CLIPRDR_FLAG_REMOTE_TO_LOCAL_FILES);
|
| 130 |
+
if (filteredFormatList.numFormats == 0)
|
| 131 |
+
goto error_out;
|
| 132 |
+
|
| 133 |
+
WLog_Print(cliprdr->log, WLOG_DEBUG, "ServerFormatList: numFormats: %" PRIu32 "",
|
| 134 |
+
filteredFormatList.numFormats);
|
| 135 |
+
|
| 136 |
+
if (context->ServerFormatList)
|
| 137 |
+
{
|
| 138 |
+
if ((error = context->ServerFormatList(context, &filteredFormatList)))
|
| 139 |
+
WLog_ERR(TAG, "ServerFormatList failed with error %" PRIu32 "", error);
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
error_out:
|
| 143 |
+
cliprdr_free_format_list(&filteredFormatList);
|
| 144 |
+
cliprdr_free_format_list(&formatList);
|
| 145 |
+
return error;
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
/**
|
| 149 |
+
* Function description
|
| 150 |
+
*
|
| 151 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 152 |
+
*/
|
| 153 |
+
UINT cliprdr_process_format_list_response(cliprdrPlugin* cliprdr, wStream* s, UINT32 dataLen,
|
| 154 |
+
UINT16 msgFlags)
|
| 155 |
+
{
|
| 156 |
+
CLIPRDR_FORMAT_LIST_RESPONSE formatListResponse = { 0 };
|
| 157 |
+
CliprdrClientContext* context = cliprdr_get_client_interface(cliprdr);
|
| 158 |
+
UINT error = CHANNEL_RC_OK;
|
| 159 |
+
|
| 160 |
+
WLog_Print(cliprdr->log, WLOG_DEBUG, "ServerFormatListResponse");
|
| 161 |
+
|
| 162 |
+
formatListResponse.common.msgType = CB_FORMAT_LIST_RESPONSE;
|
| 163 |
+
formatListResponse.common.msgFlags = msgFlags;
|
| 164 |
+
formatListResponse.common.dataLen = dataLen;
|
| 165 |
+
|
| 166 |
+
IFCALLRET(context->ServerFormatListResponse, error, context, &formatListResponse);
|
| 167 |
+
if (error)
|
| 168 |
+
WLog_ERR(TAG, "ServerFormatListResponse failed with error %" PRIu32 "!", error);
|
| 169 |
+
|
| 170 |
+
return error;
|
| 171 |
+
}
|
| 172 |
+
|
| 173 |
+
/**
|
| 174 |
+
* Function description
|
| 175 |
+
*
|
| 176 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 177 |
+
*/
|
| 178 |
+
UINT cliprdr_process_format_data_request(cliprdrPlugin* cliprdr, wStream* s, UINT32 dataLen,
|
| 179 |
+
UINT16 msgFlags)
|
| 180 |
+
{
|
| 181 |
+
CLIPRDR_FORMAT_DATA_REQUEST formatDataRequest = { 0 };
|
| 182 |
+
CliprdrClientContext* context = cliprdr_get_client_interface(cliprdr);
|
| 183 |
+
UINT error = CHANNEL_RC_OK;
|
| 184 |
+
|
| 185 |
+
WLog_Print(cliprdr->log, WLOG_DEBUG, "ServerFormatDataRequest");
|
| 186 |
+
|
| 187 |
+
formatDataRequest.common.msgType = CB_FORMAT_DATA_REQUEST;
|
| 188 |
+
formatDataRequest.common.msgFlags = msgFlags;
|
| 189 |
+
formatDataRequest.common.dataLen = dataLen;
|
| 190 |
+
|
| 191 |
+
if ((error = cliprdr_read_format_data_request(s, &formatDataRequest)))
|
| 192 |
+
return error;
|
| 193 |
+
|
| 194 |
+
const UINT32 mask =
|
| 195 |
+
freerdp_settings_get_uint32(context->rdpcontext->settings, FreeRDP_ClipboardFeatureMask);
|
| 196 |
+
if ((mask & (CLIPRDR_FLAG_LOCAL_TO_REMOTE | CLIPRDR_FLAG_LOCAL_TO_REMOTE_FILES)) == 0)
|
| 197 |
+
{
|
| 198 |
+
return cliprdr_send_error_response(cliprdr, CB_FORMAT_DATA_RESPONSE);
|
| 199 |
+
}
|
| 200 |
+
|
| 201 |
+
context->lastRequestedFormatId = formatDataRequest.requestedFormatId;
|
| 202 |
+
IFCALLRET(context->ServerFormatDataRequest, error, context, &formatDataRequest);
|
| 203 |
+
if (error)
|
| 204 |
+
WLog_ERR(TAG, "ServerFormatDataRequest failed with error %" PRIu32 "!", error);
|
| 205 |
+
|
| 206 |
+
return error;
|
| 207 |
+
}
|
| 208 |
+
|
| 209 |
+
/**
|
| 210 |
+
* Function description
|
| 211 |
+
*
|
| 212 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 213 |
+
*/
|
| 214 |
+
UINT cliprdr_process_format_data_response(cliprdrPlugin* cliprdr, wStream* s, UINT32 dataLen,
|
| 215 |
+
UINT16 msgFlags)
|
| 216 |
+
{
|
| 217 |
+
CLIPRDR_FORMAT_DATA_RESPONSE formatDataResponse = { 0 };
|
| 218 |
+
CliprdrClientContext* context = cliprdr_get_client_interface(cliprdr);
|
| 219 |
+
UINT error = CHANNEL_RC_OK;
|
| 220 |
+
|
| 221 |
+
WLog_Print(cliprdr->log, WLOG_DEBUG, "ServerFormatDataResponse");
|
| 222 |
+
|
| 223 |
+
formatDataResponse.common.msgType = CB_FORMAT_DATA_RESPONSE;
|
| 224 |
+
formatDataResponse.common.msgFlags = msgFlags;
|
| 225 |
+
formatDataResponse.common.dataLen = dataLen;
|
| 226 |
+
|
| 227 |
+
if ((error = cliprdr_read_format_data_response(s, &formatDataResponse)))
|
| 228 |
+
return error;
|
| 229 |
+
|
| 230 |
+
const UINT32 mask =
|
| 231 |
+
freerdp_settings_get_uint32(context->rdpcontext->settings, FreeRDP_ClipboardFeatureMask);
|
| 232 |
+
if ((mask & (CLIPRDR_FLAG_REMOTE_TO_LOCAL | CLIPRDR_FLAG_REMOTE_TO_LOCAL_FILES)) == 0)
|
| 233 |
+
{
|
| 234 |
+
WLog_WARN(TAG,
|
| 235 |
+
"Received ServerFormatDataResponse but remote -> local clipboard is disabled");
|
| 236 |
+
return CHANNEL_RC_OK;
|
| 237 |
+
}
|
| 238 |
+
|
| 239 |
+
IFCALLRET(context->ServerFormatDataResponse, error, context, &formatDataResponse);
|
| 240 |
+
if (error)
|
| 241 |
+
WLog_ERR(TAG, "ServerFormatDataResponse failed with error %" PRIu32 "!", error);
|
| 242 |
+
|
| 243 |
+
return error;
|
| 244 |
+
}
|
local-test-freerdp-delta-01/afc-freerdp/channels/cliprdr/client/cliprdr_format.h
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* FreeRDP: A Remote Desktop Protocol Implementation
|
| 3 |
+
* Clipboard Virtual Channel
|
| 4 |
+
*
|
| 5 |
+
* Copyright 2009-2011 Jay Sorg
|
| 6 |
+
* Copyright 2010-2011 Vic Lee
|
| 7 |
+
* Copyright 2015 Thincast Technologies GmbH
|
| 8 |
+
* Copyright 2015 DI (FH) Martin Haimberger <martin.haimberger@thincast.com>
|
| 9 |
+
*
|
| 10 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 11 |
+
* you may not use this file except in compliance with the License.
|
| 12 |
+
* You may obtain a copy of the License at
|
| 13 |
+
*
|
| 14 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 15 |
+
*
|
| 16 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 17 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 18 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 19 |
+
* See the License for the specific language governing permissions and
|
| 20 |
+
* limitations under the License.
|
| 21 |
+
*/
|
| 22 |
+
|
| 23 |
+
#ifndef FREERDP_CHANNEL_CLIPRDR_CLIENT_FORMAT_H
|
| 24 |
+
#define FREERDP_CHANNEL_CLIPRDR_CLIENT_FORMAT_H
|
| 25 |
+
|
| 26 |
+
UINT cliprdr_process_format_list(cliprdrPlugin* cliprdr, wStream* s, UINT32 dataLen,
|
| 27 |
+
UINT16 msgFlags);
|
| 28 |
+
UINT cliprdr_process_format_list_response(cliprdrPlugin* cliprdr, wStream* s, UINT32 dataLen,
|
| 29 |
+
UINT16 msgFlags);
|
| 30 |
+
UINT cliprdr_process_format_data_request(cliprdrPlugin* cliprdr, wStream* s, UINT32 dataLen,
|
| 31 |
+
UINT16 msgFlags);
|
| 32 |
+
UINT cliprdr_process_format_data_response(cliprdrPlugin* cliprdr, wStream* s, UINT32 dataLen,
|
| 33 |
+
UINT16 msgFlags);
|
| 34 |
+
CLIPRDR_FORMAT_LIST cliprdr_filter_format_list(const CLIPRDR_FORMAT_LIST* list, const UINT32 mask,
|
| 35 |
+
const UINT32 checkMask);
|
| 36 |
+
|
| 37 |
+
#endif /* FREERDP_CHANNEL_CLIPRDR_CLIENT_FORMAT_H */
|
local-test-freerdp-delta-01/afc-freerdp/channels/cliprdr/client/cliprdr_main.c
ADDED
|
@@ -0,0 +1,1174 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* FreeRDP: A Remote Desktop Protocol Implementation
|
| 3 |
+
* Clipboard Virtual Channel
|
| 4 |
+
*
|
| 5 |
+
* Copyright 2009-2011 Jay Sorg
|
| 6 |
+
* Copyright 2010-2011 Vic Lee
|
| 7 |
+
* Copyright 2015 Thincast Technologies GmbH
|
| 8 |
+
* Copyright 2015 DI (FH) Martin Haimberger <martin.haimberger@thincast.com>
|
| 9 |
+
*
|
| 10 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 11 |
+
* you may not use this file except in compliance with the License.
|
| 12 |
+
* You may obtain a copy of the License at
|
| 13 |
+
*
|
| 14 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 15 |
+
*
|
| 16 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 17 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 18 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 19 |
+
* See the License for the specific language governing permissions and
|
| 20 |
+
* limitations under the License.
|
| 21 |
+
*/
|
| 22 |
+
|
| 23 |
+
#include <freerdp/config.h>
|
| 24 |
+
|
| 25 |
+
#include <winpr/wtypes.h>
|
| 26 |
+
#include <winpr/assert.h>
|
| 27 |
+
#include <winpr/crt.h>
|
| 28 |
+
#include <winpr/print.h>
|
| 29 |
+
|
| 30 |
+
#include <freerdp/types.h>
|
| 31 |
+
#include <freerdp/constants.h>
|
| 32 |
+
#include <freerdp/freerdp.h>
|
| 33 |
+
#include <freerdp/client/cliprdr.h>
|
| 34 |
+
|
| 35 |
+
#include "../../../channels/client/addin.h"
|
| 36 |
+
|
| 37 |
+
#include "cliprdr_main.h"
|
| 38 |
+
#include "cliprdr_format.h"
|
| 39 |
+
#include "../cliprdr_common.h"
|
| 40 |
+
|
| 41 |
+
const char type_FileGroupDescriptorW[] = "FileGroupDescriptorW";
|
| 42 |
+
const char type_FileContents[] = "FileContents";
|
| 43 |
+
|
| 44 |
+
CliprdrClientContext* cliprdr_get_client_interface(cliprdrPlugin* cliprdr)
|
| 45 |
+
{
|
| 46 |
+
CliprdrClientContext* pInterface = NULL;
|
| 47 |
+
|
| 48 |
+
if (!cliprdr)
|
| 49 |
+
return NULL;
|
| 50 |
+
|
| 51 |
+
pInterface = (CliprdrClientContext*)cliprdr->channelEntryPoints.pInterface;
|
| 52 |
+
return pInterface;
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
/**
|
| 56 |
+
* Function description
|
| 57 |
+
*
|
| 58 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 59 |
+
*/
|
| 60 |
+
static UINT cliprdr_packet_send(cliprdrPlugin* cliprdr, wStream* s)
|
| 61 |
+
{
|
| 62 |
+
UINT status = CHANNEL_RC_OK;
|
| 63 |
+
|
| 64 |
+
WINPR_ASSERT(cliprdr);
|
| 65 |
+
WINPR_ASSERT(s);
|
| 66 |
+
|
| 67 |
+
const size_t pos = Stream_GetPosition(s);
|
| 68 |
+
const size_t dataLen = pos - 8;
|
| 69 |
+
WINPR_ASSERT(dataLen <= UINT32_MAX);
|
| 70 |
+
|
| 71 |
+
Stream_SetPosition(s, 4);
|
| 72 |
+
Stream_Write_UINT32(s, (UINT32)dataLen);
|
| 73 |
+
Stream_SetPosition(s, pos);
|
| 74 |
+
|
| 75 |
+
WLog_DBG(TAG, "Cliprdr Sending (%" PRIu32 " bytes)", dataLen + 8);
|
| 76 |
+
|
| 77 |
+
if (!cliprdr)
|
| 78 |
+
{
|
| 79 |
+
status = CHANNEL_RC_BAD_INIT_HANDLE;
|
| 80 |
+
}
|
| 81 |
+
else
|
| 82 |
+
{
|
| 83 |
+
WINPR_ASSERT(cliprdr->channelEntryPoints.pVirtualChannelWriteEx);
|
| 84 |
+
status = cliprdr->channelEntryPoints.pVirtualChannelWriteEx(
|
| 85 |
+
cliprdr->InitHandle, cliprdr->OpenHandle, Stream_Buffer(s),
|
| 86 |
+
(UINT32)Stream_GetPosition(s), s);
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
if (status != CHANNEL_RC_OK)
|
| 90 |
+
{
|
| 91 |
+
Stream_Free(s, TRUE);
|
| 92 |
+
WLog_ERR(TAG, "VirtualChannelWrite failed with %s [%08" PRIX32 "]",
|
| 93 |
+
WTSErrorToString(status), status);
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
return status;
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
UINT cliprdr_send_error_response(cliprdrPlugin* cliprdr, UINT16 type)
|
| 100 |
+
{
|
| 101 |
+
wStream* s = cliprdr_packet_new(type, CB_RESPONSE_FAIL, 0);
|
| 102 |
+
if (!s)
|
| 103 |
+
{
|
| 104 |
+
WLog_ERR(TAG, "cliprdr_packet_new failed!");
|
| 105 |
+
return ERROR_OUTOFMEMORY;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
return cliprdr_packet_send(cliprdr, s);
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
static void cliprdr_print_general_capability_flags(UINT32 flags)
|
| 112 |
+
{
|
| 113 |
+
WLog_DBG(TAG, "generalFlags (0x%08" PRIX32 ") {", flags);
|
| 114 |
+
|
| 115 |
+
if (flags & CB_USE_LONG_FORMAT_NAMES)
|
| 116 |
+
WLog_DBG(TAG, "\tCB_USE_LONG_FORMAT_NAMES");
|
| 117 |
+
|
| 118 |
+
if (flags & CB_STREAM_FILECLIP_ENABLED)
|
| 119 |
+
WLog_DBG(TAG, "\tCB_STREAM_FILECLIP_ENABLED");
|
| 120 |
+
|
| 121 |
+
if (flags & CB_FILECLIP_NO_FILE_PATHS)
|
| 122 |
+
WLog_DBG(TAG, "\tCB_FILECLIP_NO_FILE_PATHS");
|
| 123 |
+
|
| 124 |
+
if (flags & CB_CAN_LOCK_CLIPDATA)
|
| 125 |
+
WLog_DBG(TAG, "\tCB_CAN_LOCK_CLIPDATA");
|
| 126 |
+
|
| 127 |
+
if (flags & CB_HUGE_FILE_SUPPORT_ENABLED)
|
| 128 |
+
WLog_DBG(TAG, "\tCB_HUGE_FILE_SUPPORT_ENABLED");
|
| 129 |
+
|
| 130 |
+
WLog_DBG(TAG, "}");
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
/**
|
| 134 |
+
* Function description
|
| 135 |
+
*
|
| 136 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 137 |
+
*/
|
| 138 |
+
static UINT cliprdr_process_general_capability(cliprdrPlugin* cliprdr, wStream* s)
|
| 139 |
+
{
|
| 140 |
+
UINT32 version = 0;
|
| 141 |
+
UINT32 generalFlags = 0;
|
| 142 |
+
CLIPRDR_CAPABILITIES capabilities = { 0 };
|
| 143 |
+
CLIPRDR_GENERAL_CAPABILITY_SET generalCapabilitySet = { 0 };
|
| 144 |
+
CliprdrClientContext* context = cliprdr_get_client_interface(cliprdr);
|
| 145 |
+
UINT error = CHANNEL_RC_OK;
|
| 146 |
+
|
| 147 |
+
WINPR_ASSERT(cliprdr);
|
| 148 |
+
WINPR_ASSERT(s);
|
| 149 |
+
|
| 150 |
+
if (!context)
|
| 151 |
+
{
|
| 152 |
+
WLog_ERR(TAG, "cliprdr_get_client_interface failed!");
|
| 153 |
+
return ERROR_INTERNAL_ERROR;
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
if (!Stream_CheckAndLogRequiredLength(TAG, s, 8))
|
| 157 |
+
return ERROR_INVALID_DATA;
|
| 158 |
+
|
| 159 |
+
Stream_Read_UINT32(s, version); /* version (4 bytes) */
|
| 160 |
+
Stream_Read_UINT32(s, generalFlags); /* generalFlags (4 bytes) */
|
| 161 |
+
WLog_DBG(TAG, "Version: %" PRIu32 "", version);
|
| 162 |
+
|
| 163 |
+
cliprdr_print_general_capability_flags(generalFlags);
|
| 164 |
+
|
| 165 |
+
cliprdr->useLongFormatNames = (generalFlags & CB_USE_LONG_FORMAT_NAMES) ? TRUE : FALSE;
|
| 166 |
+
cliprdr->streamFileClipEnabled = (generalFlags & CB_STREAM_FILECLIP_ENABLED) ? TRUE : FALSE;
|
| 167 |
+
cliprdr->fileClipNoFilePaths = (generalFlags & CB_FILECLIP_NO_FILE_PATHS) ? TRUE : FALSE;
|
| 168 |
+
cliprdr->canLockClipData = (generalFlags & CB_CAN_LOCK_CLIPDATA) ? TRUE : FALSE;
|
| 169 |
+
cliprdr->hasHugeFileSupport = (generalFlags & CB_HUGE_FILE_SUPPORT_ENABLED) ? TRUE : FALSE;
|
| 170 |
+
cliprdr->capabilitiesReceived = TRUE;
|
| 171 |
+
|
| 172 |
+
capabilities.common.msgType = CB_CLIP_CAPS;
|
| 173 |
+
capabilities.cCapabilitiesSets = 1;
|
| 174 |
+
capabilities.capabilitySets = (CLIPRDR_CAPABILITY_SET*)&(generalCapabilitySet);
|
| 175 |
+
generalCapabilitySet.capabilitySetType = CB_CAPSTYPE_GENERAL;
|
| 176 |
+
generalCapabilitySet.capabilitySetLength = 12;
|
| 177 |
+
generalCapabilitySet.version = version;
|
| 178 |
+
generalCapabilitySet.generalFlags = generalFlags;
|
| 179 |
+
IFCALLRET(context->ServerCapabilities, error, context, &capabilities);
|
| 180 |
+
|
| 181 |
+
if (error)
|
| 182 |
+
WLog_ERR(TAG, "ServerCapabilities failed with error %" PRIu32 "!", error);
|
| 183 |
+
|
| 184 |
+
return error;
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
/**
|
| 188 |
+
* Function description
|
| 189 |
+
*
|
| 190 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 191 |
+
*/
|
| 192 |
+
static UINT cliprdr_process_clip_caps(cliprdrPlugin* cliprdr, wStream* s, UINT32 length,
|
| 193 |
+
UINT16 flags)
|
| 194 |
+
{
|
| 195 |
+
UINT16 lengthCapability = 0;
|
| 196 |
+
UINT16 cCapabilitiesSets = 0;
|
| 197 |
+
UINT16 capabilitySetType = 0;
|
| 198 |
+
UINT error = CHANNEL_RC_OK;
|
| 199 |
+
|
| 200 |
+
WINPR_ASSERT(cliprdr);
|
| 201 |
+
WINPR_ASSERT(s);
|
| 202 |
+
|
| 203 |
+
if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
|
| 204 |
+
return ERROR_INVALID_DATA;
|
| 205 |
+
|
| 206 |
+
Stream_Read_UINT16(s, cCapabilitiesSets); /* cCapabilitiesSets (2 bytes) */
|
| 207 |
+
Stream_Seek_UINT16(s); /* pad1 (2 bytes) */
|
| 208 |
+
WLog_Print(cliprdr->log, WLOG_DEBUG, "ServerCapabilities");
|
| 209 |
+
|
| 210 |
+
for (UINT16 index = 0; index < cCapabilitiesSets; index++)
|
| 211 |
+
{
|
| 212 |
+
if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
|
| 213 |
+
return ERROR_INVALID_DATA;
|
| 214 |
+
|
| 215 |
+
Stream_Read_UINT16(s, capabilitySetType); /* capabilitySetType (2 bytes) */
|
| 216 |
+
Stream_Read_UINT16(s, lengthCapability); /* lengthCapability (2 bytes) */
|
| 217 |
+
|
| 218 |
+
if ((lengthCapability < 4) ||
|
| 219 |
+
(!Stream_CheckAndLogRequiredLength(TAG, s, lengthCapability - 4U)))
|
| 220 |
+
return ERROR_INVALID_DATA;
|
| 221 |
+
|
| 222 |
+
switch (capabilitySetType)
|
| 223 |
+
{
|
| 224 |
+
case CB_CAPSTYPE_GENERAL:
|
| 225 |
+
if ((error = cliprdr_process_general_capability(cliprdr, s)))
|
| 226 |
+
{
|
| 227 |
+
WLog_ERR(TAG,
|
| 228 |
+
"cliprdr_process_general_capability failed with error %" PRIu32 "!",
|
| 229 |
+
error);
|
| 230 |
+
return error;
|
| 231 |
+
}
|
| 232 |
+
|
| 233 |
+
break;
|
| 234 |
+
|
| 235 |
+
default:
|
| 236 |
+
WLog_ERR(TAG, "unknown cliprdr capability set: %" PRIu16 "", capabilitySetType);
|
| 237 |
+
return CHANNEL_RC_BAD_PROC;
|
| 238 |
+
}
|
| 239 |
+
}
|
| 240 |
+
|
| 241 |
+
return error;
|
| 242 |
+
}
|
| 243 |
+
|
| 244 |
+
/**
|
| 245 |
+
* Function description
|
| 246 |
+
*
|
| 247 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 248 |
+
*/
|
| 249 |
+
static UINT cliprdr_process_monitor_ready(cliprdrPlugin* cliprdr, wStream* s, UINT32 length,
|
| 250 |
+
UINT16 flags)
|
| 251 |
+
{
|
| 252 |
+
CLIPRDR_MONITOR_READY monitorReady = { 0 };
|
| 253 |
+
CliprdrClientContext* context = cliprdr_get_client_interface(cliprdr);
|
| 254 |
+
UINT error = CHANNEL_RC_OK;
|
| 255 |
+
|
| 256 |
+
WINPR_ASSERT(cliprdr);
|
| 257 |
+
WINPR_ASSERT(s);
|
| 258 |
+
|
| 259 |
+
WLog_Print(cliprdr->log, WLOG_DEBUG, "MonitorReady");
|
| 260 |
+
|
| 261 |
+
if (!cliprdr->capabilitiesReceived)
|
| 262 |
+
{
|
| 263 |
+
/**
|
| 264 |
+
* The clipboard capabilities pdu from server to client is optional,
|
| 265 |
+
* but a server using it must send it before sending the monitor ready pdu.
|
| 266 |
+
* When the server capabilities pdu is not used, default capabilities
|
| 267 |
+
* corresponding to a generalFlags field set to zero are assumed.
|
| 268 |
+
*/
|
| 269 |
+
cliprdr->useLongFormatNames = FALSE;
|
| 270 |
+
cliprdr->streamFileClipEnabled = FALSE;
|
| 271 |
+
cliprdr->fileClipNoFilePaths = TRUE;
|
| 272 |
+
cliprdr->canLockClipData = FALSE;
|
| 273 |
+
}
|
| 274 |
+
|
| 275 |
+
monitorReady.common.msgType = CB_MONITOR_READY;
|
| 276 |
+
monitorReady.common.msgFlags = flags;
|
| 277 |
+
monitorReady.common.dataLen = length;
|
| 278 |
+
IFCALLRET(context->MonitorReady, error, context, &monitorReady);
|
| 279 |
+
|
| 280 |
+
if (error)
|
| 281 |
+
WLog_ERR(TAG, "MonitorReady failed with error %" PRIu32 "!", error);
|
| 282 |
+
|
| 283 |
+
return error;
|
| 284 |
+
}
|
| 285 |
+
|
| 286 |
+
/**
|
| 287 |
+
* Function description
|
| 288 |
+
*
|
| 289 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 290 |
+
*/
|
| 291 |
+
static UINT cliprdr_process_filecontents_request(cliprdrPlugin* cliprdr, wStream* s, UINT32 length,
|
| 292 |
+
UINT16 flags)
|
| 293 |
+
{
|
| 294 |
+
CLIPRDR_FILE_CONTENTS_REQUEST request = { 0 };
|
| 295 |
+
CliprdrClientContext* context = cliprdr_get_client_interface(cliprdr);
|
| 296 |
+
UINT error = CHANNEL_RC_OK;
|
| 297 |
+
|
| 298 |
+
WINPR_ASSERT(cliprdr);
|
| 299 |
+
WINPR_ASSERT(s);
|
| 300 |
+
|
| 301 |
+
WLog_Print(cliprdr->log, WLOG_DEBUG, "FileContentsRequest");
|
| 302 |
+
|
| 303 |
+
request.common.msgType = CB_FILECONTENTS_REQUEST;
|
| 304 |
+
request.common.msgFlags = flags;
|
| 305 |
+
request.common.dataLen = length;
|
| 306 |
+
|
| 307 |
+
if ((error = cliprdr_read_file_contents_request(s, &request)))
|
| 308 |
+
return error;
|
| 309 |
+
|
| 310 |
+
const UINT32 mask =
|
| 311 |
+
freerdp_settings_get_uint32(context->rdpcontext->settings, FreeRDP_ClipboardFeatureMask);
|
| 312 |
+
if ((mask & (CLIPRDR_FLAG_LOCAL_TO_REMOTE_FILES)) == 0)
|
| 313 |
+
{
|
| 314 |
+
WLog_WARN(TAG, "local -> remote file copy disabled, ignoring request");
|
| 315 |
+
return cliprdr_send_error_response(cliprdr, CB_FILECONTENTS_RESPONSE);
|
| 316 |
+
}
|
| 317 |
+
IFCALLRET(context->ServerFileContentsRequest, error, context, &request);
|
| 318 |
+
|
| 319 |
+
if (error)
|
| 320 |
+
WLog_ERR(TAG, "ServerFileContentsRequest failed with error %" PRIu32 "!", error);
|
| 321 |
+
|
| 322 |
+
return error;
|
| 323 |
+
}
|
| 324 |
+
|
| 325 |
+
/**
|
| 326 |
+
* Function description
|
| 327 |
+
*
|
| 328 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 329 |
+
*/
|
| 330 |
+
static UINT cliprdr_process_filecontents_response(cliprdrPlugin* cliprdr, wStream* s, UINT32 length,
|
| 331 |
+
UINT16 flags)
|
| 332 |
+
{
|
| 333 |
+
CLIPRDR_FILE_CONTENTS_RESPONSE response = { 0 };
|
| 334 |
+
CliprdrClientContext* context = cliprdr_get_client_interface(cliprdr);
|
| 335 |
+
UINT error = CHANNEL_RC_OK;
|
| 336 |
+
|
| 337 |
+
WINPR_ASSERT(cliprdr);
|
| 338 |
+
WINPR_ASSERT(s);
|
| 339 |
+
|
| 340 |
+
WLog_Print(cliprdr->log, WLOG_DEBUG, "FileContentsResponse");
|
| 341 |
+
|
| 342 |
+
response.common.msgType = CB_FILECONTENTS_RESPONSE;
|
| 343 |
+
response.common.msgFlags = flags;
|
| 344 |
+
response.common.dataLen = length;
|
| 345 |
+
|
| 346 |
+
if ((error = cliprdr_read_file_contents_response(s, &response)))
|
| 347 |
+
return error;
|
| 348 |
+
|
| 349 |
+
IFCALLRET(context->ServerFileContentsResponse, error, context, &response);
|
| 350 |
+
|
| 351 |
+
if (error)
|
| 352 |
+
WLog_ERR(TAG, "ServerFileContentsResponse failed with error %" PRIu32 "!", error);
|
| 353 |
+
|
| 354 |
+
return error;
|
| 355 |
+
}
|
| 356 |
+
|
| 357 |
+
/**
|
| 358 |
+
* Function description
|
| 359 |
+
*
|
| 360 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 361 |
+
*/
|
| 362 |
+
static UINT cliprdr_process_lock_clipdata(cliprdrPlugin* cliprdr, wStream* s, UINT32 length,
|
| 363 |
+
UINT16 flags)
|
| 364 |
+
{
|
| 365 |
+
CLIPRDR_LOCK_CLIPBOARD_DATA lockClipboardData = { 0 };
|
| 366 |
+
CliprdrClientContext* context = cliprdr_get_client_interface(cliprdr);
|
| 367 |
+
UINT error = CHANNEL_RC_OK;
|
| 368 |
+
|
| 369 |
+
WINPR_ASSERT(cliprdr);
|
| 370 |
+
WINPR_ASSERT(s);
|
| 371 |
+
|
| 372 |
+
WLog_Print(cliprdr->log, WLOG_DEBUG, "LockClipData");
|
| 373 |
+
|
| 374 |
+
if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
|
| 375 |
+
return ERROR_INVALID_DATA;
|
| 376 |
+
|
| 377 |
+
lockClipboardData.common.msgType = CB_LOCK_CLIPDATA;
|
| 378 |
+
lockClipboardData.common.msgFlags = flags;
|
| 379 |
+
lockClipboardData.common.dataLen = length;
|
| 380 |
+
Stream_Read_UINT32(s, lockClipboardData.clipDataId); /* clipDataId (4 bytes) */
|
| 381 |
+
IFCALLRET(context->ServerLockClipboardData, error, context, &lockClipboardData);
|
| 382 |
+
|
| 383 |
+
if (error)
|
| 384 |
+
WLog_ERR(TAG, "ServerLockClipboardData failed with error %" PRIu32 "!", error);
|
| 385 |
+
|
| 386 |
+
return error;
|
| 387 |
+
}
|
| 388 |
+
|
| 389 |
+
/**
|
| 390 |
+
* Function description
|
| 391 |
+
*
|
| 392 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 393 |
+
*/
|
| 394 |
+
static UINT cliprdr_process_unlock_clipdata(cliprdrPlugin* cliprdr, wStream* s, UINT32 length,
|
| 395 |
+
UINT16 flags)
|
| 396 |
+
{
|
| 397 |
+
CLIPRDR_UNLOCK_CLIPBOARD_DATA unlockClipboardData = { 0 };
|
| 398 |
+
CliprdrClientContext* context = cliprdr_get_client_interface(cliprdr);
|
| 399 |
+
UINT error = CHANNEL_RC_OK;
|
| 400 |
+
|
| 401 |
+
WINPR_ASSERT(cliprdr);
|
| 402 |
+
WINPR_ASSERT(s);
|
| 403 |
+
|
| 404 |
+
WLog_Print(cliprdr->log, WLOG_DEBUG, "UnlockClipData");
|
| 405 |
+
|
| 406 |
+
if ((error = cliprdr_read_unlock_clipdata(s, &unlockClipboardData)))
|
| 407 |
+
return error;
|
| 408 |
+
|
| 409 |
+
unlockClipboardData.common.msgType = CB_UNLOCK_CLIPDATA;
|
| 410 |
+
unlockClipboardData.common.msgFlags = flags;
|
| 411 |
+
unlockClipboardData.common.dataLen = length;
|
| 412 |
+
|
| 413 |
+
IFCALLRET(context->ServerUnlockClipboardData, error, context, &unlockClipboardData);
|
| 414 |
+
|
| 415 |
+
if (error)
|
| 416 |
+
WLog_ERR(TAG, "ServerUnlockClipboardData failed with error %" PRIu32 "!", error);
|
| 417 |
+
|
| 418 |
+
return error;
|
| 419 |
+
}
|
| 420 |
+
|
| 421 |
+
/**
|
| 422 |
+
* Function description
|
| 423 |
+
*
|
| 424 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 425 |
+
*/
|
| 426 |
+
static UINT cliprdr_order_recv(LPVOID userdata, wStream* s)
|
| 427 |
+
{
|
| 428 |
+
cliprdrPlugin* cliprdr = userdata;
|
| 429 |
+
UINT16 msgType = 0;
|
| 430 |
+
UINT16 msgFlags = 0;
|
| 431 |
+
UINT32 dataLen = 0;
|
| 432 |
+
UINT error = 0;
|
| 433 |
+
|
| 434 |
+
WINPR_ASSERT(cliprdr);
|
| 435 |
+
WINPR_ASSERT(s);
|
| 436 |
+
|
| 437 |
+
if (!Stream_CheckAndLogRequiredLength(TAG, s, 8))
|
| 438 |
+
return ERROR_INVALID_DATA;
|
| 439 |
+
|
| 440 |
+
Stream_Read_UINT16(s, msgType); /* msgType (2 bytes) */
|
| 441 |
+
Stream_Read_UINT16(s, msgFlags); /* msgFlags (2 bytes) */
|
| 442 |
+
Stream_Read_UINT32(s, dataLen); /* dataLen (4 bytes) */
|
| 443 |
+
|
| 444 |
+
if (!Stream_CheckAndLogRequiredLength(TAG, s, dataLen))
|
| 445 |
+
return ERROR_INVALID_DATA;
|
| 446 |
+
|
| 447 |
+
char buffer1[64] = { 0 };
|
| 448 |
+
char buffer2[64] = { 0 };
|
| 449 |
+
WLog_DBG(TAG, "msgType: %s (%" PRIu16 "), msgFlags: %s dataLen: %" PRIu32 "",
|
| 450 |
+
CB_MSG_TYPE_STRING(msgType, buffer1, sizeof(buffer1)), msgType,
|
| 451 |
+
CB_MSG_FLAGS_STRING(msgFlags, buffer2, sizeof(buffer2)), dataLen);
|
| 452 |
+
|
| 453 |
+
switch (msgType)
|
| 454 |
+
{
|
| 455 |
+
case CB_CLIP_CAPS:
|
| 456 |
+
if ((error = cliprdr_process_clip_caps(cliprdr, s, dataLen, msgFlags)))
|
| 457 |
+
WLog_ERR(TAG, "cliprdr_process_clip_caps failed with error %" PRIu32 "!", error);
|
| 458 |
+
|
| 459 |
+
break;
|
| 460 |
+
|
| 461 |
+
case CB_MONITOR_READY:
|
| 462 |
+
if ((error = cliprdr_process_monitor_ready(cliprdr, s, dataLen, msgFlags)))
|
| 463 |
+
WLog_ERR(TAG, "cliprdr_process_monitor_ready failed with error %" PRIu32 "!",
|
| 464 |
+
error);
|
| 465 |
+
|
| 466 |
+
break;
|
| 467 |
+
|
| 468 |
+
case CB_FORMAT_LIST:
|
| 469 |
+
if ((error = cliprdr_process_format_list(cliprdr, s, dataLen, msgFlags)))
|
| 470 |
+
WLog_ERR(TAG, "cliprdr_process_format_list failed with error %" PRIu32 "!", error);
|
| 471 |
+
|
| 472 |
+
break;
|
| 473 |
+
|
| 474 |
+
case CB_FORMAT_LIST_RESPONSE:
|
| 475 |
+
if ((error = cliprdr_process_format_list_response(cliprdr, s, dataLen, msgFlags)))
|
| 476 |
+
WLog_ERR(TAG, "cliprdr_process_format_list_response failed with error %" PRIu32 "!",
|
| 477 |
+
error);
|
| 478 |
+
|
| 479 |
+
break;
|
| 480 |
+
|
| 481 |
+
case CB_FORMAT_DATA_REQUEST:
|
| 482 |
+
if ((error = cliprdr_process_format_data_request(cliprdr, s, dataLen, msgFlags)))
|
| 483 |
+
WLog_ERR(TAG, "cliprdr_process_format_data_request failed with error %" PRIu32 "!",
|
| 484 |
+
error);
|
| 485 |
+
|
| 486 |
+
break;
|
| 487 |
+
|
| 488 |
+
case CB_FORMAT_DATA_RESPONSE:
|
| 489 |
+
if ((error = cliprdr_process_format_data_response(cliprdr, s, dataLen, msgFlags)))
|
| 490 |
+
WLog_ERR(TAG, "cliprdr_process_format_data_response failed with error %" PRIu32 "!",
|
| 491 |
+
error);
|
| 492 |
+
|
| 493 |
+
break;
|
| 494 |
+
|
| 495 |
+
case CB_FILECONTENTS_REQUEST:
|
| 496 |
+
if ((error = cliprdr_process_filecontents_request(cliprdr, s, dataLen, msgFlags)))
|
| 497 |
+
WLog_ERR(TAG, "cliprdr_process_filecontents_request failed with error %" PRIu32 "!",
|
| 498 |
+
error);
|
| 499 |
+
|
| 500 |
+
break;
|
| 501 |
+
|
| 502 |
+
case CB_FILECONTENTS_RESPONSE:
|
| 503 |
+
if ((error = cliprdr_process_filecontents_response(cliprdr, s, dataLen, msgFlags)))
|
| 504 |
+
WLog_ERR(TAG,
|
| 505 |
+
"cliprdr_process_filecontents_response failed with error %" PRIu32 "!",
|
| 506 |
+
error);
|
| 507 |
+
|
| 508 |
+
break;
|
| 509 |
+
|
| 510 |
+
case CB_LOCK_CLIPDATA:
|
| 511 |
+
if ((error = cliprdr_process_lock_clipdata(cliprdr, s, dataLen, msgFlags)))
|
| 512 |
+
WLog_ERR(TAG, "cliprdr_process_lock_clipdata failed with error %" PRIu32 "!",
|
| 513 |
+
error);
|
| 514 |
+
|
| 515 |
+
break;
|
| 516 |
+
|
| 517 |
+
case CB_UNLOCK_CLIPDATA:
|
| 518 |
+
if ((error = cliprdr_process_unlock_clipdata(cliprdr, s, dataLen, msgFlags)))
|
| 519 |
+
WLog_ERR(TAG, "cliprdr_process_unlock_clipdata failed with error %" PRIu32 "!",
|
| 520 |
+
error);
|
| 521 |
+
|
| 522 |
+
break;
|
| 523 |
+
|
| 524 |
+
default:
|
| 525 |
+
error = CHANNEL_RC_BAD_PROC;
|
| 526 |
+
WLog_ERR(TAG, "unknown msgType %" PRIu16 "", msgType);
|
| 527 |
+
break;
|
| 528 |
+
}
|
| 529 |
+
|
| 530 |
+
Stream_Free(s, TRUE);
|
| 531 |
+
return error;
|
| 532 |
+
}
|
| 533 |
+
|
| 534 |
+
/**
|
| 535 |
+
* Callback Interface
|
| 536 |
+
*/
|
| 537 |
+
|
| 538 |
+
/**
|
| 539 |
+
* Function description
|
| 540 |
+
*
|
| 541 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 542 |
+
*/
|
| 543 |
+
static UINT cliprdr_client_capabilities(CliprdrClientContext* context,
|
| 544 |
+
const CLIPRDR_CAPABILITIES* capabilities)
|
| 545 |
+
{
|
| 546 |
+
wStream* s = NULL;
|
| 547 |
+
UINT32 flags = 0;
|
| 548 |
+
const CLIPRDR_GENERAL_CAPABILITY_SET* generalCapabilitySet = NULL;
|
| 549 |
+
cliprdrPlugin* cliprdr = NULL;
|
| 550 |
+
|
| 551 |
+
WINPR_ASSERT(context);
|
| 552 |
+
|
| 553 |
+
cliprdr = (cliprdrPlugin*)context->handle;
|
| 554 |
+
WINPR_ASSERT(cliprdr);
|
| 555 |
+
|
| 556 |
+
s = cliprdr_packet_new(CB_CLIP_CAPS, 0, 4 + CB_CAPSTYPE_GENERAL_LEN);
|
| 557 |
+
|
| 558 |
+
if (!s)
|
| 559 |
+
{
|
| 560 |
+
WLog_ERR(TAG, "cliprdr_packet_new failed!");
|
| 561 |
+
return ERROR_INTERNAL_ERROR;
|
| 562 |
+
}
|
| 563 |
+
|
| 564 |
+
Stream_Write_UINT16(s, 1); /* cCapabilitiesSets */
|
| 565 |
+
Stream_Write_UINT16(s, 0); /* pad1 */
|
| 566 |
+
generalCapabilitySet = (const CLIPRDR_GENERAL_CAPABILITY_SET*)capabilities->capabilitySets;
|
| 567 |
+
Stream_Write_UINT16(s, generalCapabilitySet->capabilitySetType); /* capabilitySetType */
|
| 568 |
+
Stream_Write_UINT16(s, generalCapabilitySet->capabilitySetLength); /* lengthCapability */
|
| 569 |
+
Stream_Write_UINT32(s, generalCapabilitySet->version); /* version */
|
| 570 |
+
flags = generalCapabilitySet->generalFlags;
|
| 571 |
+
|
| 572 |
+
/* Client capabilities are sent in response to server capabilities.
|
| 573 |
+
* -> Do not request features the server does not support.
|
| 574 |
+
* -> Update clipboard context feature state to what was agreed upon.
|
| 575 |
+
*/
|
| 576 |
+
if (!cliprdr->useLongFormatNames)
|
| 577 |
+
flags &= (uint32_t)~CB_USE_LONG_FORMAT_NAMES;
|
| 578 |
+
if (!cliprdr->streamFileClipEnabled)
|
| 579 |
+
flags &= (uint32_t)~CB_STREAM_FILECLIP_ENABLED;
|
| 580 |
+
if (!cliprdr->fileClipNoFilePaths)
|
| 581 |
+
flags &= (uint32_t)~CB_FILECLIP_NO_FILE_PATHS;
|
| 582 |
+
if (!cliprdr->canLockClipData)
|
| 583 |
+
flags &= (uint32_t)~CB_CAN_LOCK_CLIPDATA;
|
| 584 |
+
if (!cliprdr->hasHugeFileSupport)
|
| 585 |
+
flags &= (uint32_t)~CB_HUGE_FILE_SUPPORT_ENABLED;
|
| 586 |
+
|
| 587 |
+
cliprdr->useLongFormatNames = (flags & CB_USE_LONG_FORMAT_NAMES) ? TRUE : FALSE;
|
| 588 |
+
cliprdr->streamFileClipEnabled = (flags & CB_STREAM_FILECLIP_ENABLED) ? TRUE : FALSE;
|
| 589 |
+
cliprdr->fileClipNoFilePaths = (flags & CB_FILECLIP_NO_FILE_PATHS) ? TRUE : FALSE;
|
| 590 |
+
cliprdr->canLockClipData = (flags & CB_CAN_LOCK_CLIPDATA) ? TRUE : FALSE;
|
| 591 |
+
cliprdr->hasHugeFileSupport = (flags & CB_HUGE_FILE_SUPPORT_ENABLED) ? TRUE : FALSE;
|
| 592 |
+
|
| 593 |
+
Stream_Write_UINT32(s, flags); /* generalFlags */
|
| 594 |
+
WLog_Print(cliprdr->log, WLOG_DEBUG, "ClientCapabilities");
|
| 595 |
+
|
| 596 |
+
cliprdr->initialFormatListSent = FALSE;
|
| 597 |
+
|
| 598 |
+
return cliprdr_packet_send(cliprdr, s);
|
| 599 |
+
}
|
| 600 |
+
|
| 601 |
+
/**
|
| 602 |
+
* Function description
|
| 603 |
+
*
|
| 604 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 605 |
+
*/
|
| 606 |
+
static UINT cliprdr_temp_directory(CliprdrClientContext* context,
|
| 607 |
+
const CLIPRDR_TEMP_DIRECTORY* tempDirectory)
|
| 608 |
+
{
|
| 609 |
+
wStream* s = NULL;
|
| 610 |
+
cliprdrPlugin* cliprdr = NULL;
|
| 611 |
+
|
| 612 |
+
WINPR_ASSERT(context);
|
| 613 |
+
WINPR_ASSERT(tempDirectory);
|
| 614 |
+
|
| 615 |
+
cliprdr = (cliprdrPlugin*)context->handle;
|
| 616 |
+
WINPR_ASSERT(cliprdr);
|
| 617 |
+
|
| 618 |
+
const size_t tmpDirCharLen = sizeof(tempDirectory->szTempDir) / sizeof(WCHAR);
|
| 619 |
+
s = cliprdr_packet_new(CB_TEMP_DIRECTORY, 0, tmpDirCharLen * sizeof(WCHAR));
|
| 620 |
+
|
| 621 |
+
if (!s)
|
| 622 |
+
{
|
| 623 |
+
WLog_ERR(TAG, "cliprdr_packet_new failed!");
|
| 624 |
+
return ERROR_INTERNAL_ERROR;
|
| 625 |
+
}
|
| 626 |
+
|
| 627 |
+
if (Stream_Write_UTF16_String_From_UTF8(s, tmpDirCharLen - 1, tempDirectory->szTempDir,
|
| 628 |
+
ARRAYSIZE(tempDirectory->szTempDir), TRUE) < 0)
|
| 629 |
+
{
|
| 630 |
+
Stream_Free(s, TRUE);
|
| 631 |
+
return ERROR_INTERNAL_ERROR;
|
| 632 |
+
}
|
| 633 |
+
/* Path must be 260 UTF16 characters with '\0' termination.
|
| 634 |
+
* ensure this here */
|
| 635 |
+
Stream_Write_UINT16(s, 0);
|
| 636 |
+
|
| 637 |
+
WLog_Print(cliprdr->log, WLOG_DEBUG, "TempDirectory: %s", tempDirectory->szTempDir);
|
| 638 |
+
return cliprdr_packet_send(cliprdr, s);
|
| 639 |
+
}
|
| 640 |
+
|
| 641 |
+
/**
|
| 642 |
+
* Function description
|
| 643 |
+
*
|
| 644 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 645 |
+
*/
|
| 646 |
+
static UINT cliprdr_client_format_list(CliprdrClientContext* context,
|
| 647 |
+
const CLIPRDR_FORMAT_LIST* formatList)
|
| 648 |
+
{
|
| 649 |
+
wStream* s = NULL;
|
| 650 |
+
cliprdrPlugin* cliprdr = NULL;
|
| 651 |
+
|
| 652 |
+
WINPR_ASSERT(context);
|
| 653 |
+
WINPR_ASSERT(formatList);
|
| 654 |
+
|
| 655 |
+
cliprdr = (cliprdrPlugin*)context->handle;
|
| 656 |
+
WINPR_ASSERT(cliprdr);
|
| 657 |
+
|
| 658 |
+
{
|
| 659 |
+
const UINT32 mask = CB_RESPONSE_OK | CB_RESPONSE_FAIL;
|
| 660 |
+
if ((formatList->common.msgFlags & mask) != 0)
|
| 661 |
+
WLog_WARN(TAG,
|
| 662 |
+
"Sending clipboard request with invalid flags msgFlags = 0x%08" PRIx32
|
| 663 |
+
". Correct in your client!",
|
| 664 |
+
formatList->common.msgFlags & mask);
|
| 665 |
+
}
|
| 666 |
+
|
| 667 |
+
const UINT32 mask =
|
| 668 |
+
freerdp_settings_get_uint32(context->rdpcontext->settings, FreeRDP_ClipboardFeatureMask);
|
| 669 |
+
CLIPRDR_FORMAT_LIST filterList = cliprdr_filter_format_list(
|
| 670 |
+
formatList, mask, CLIPRDR_FLAG_LOCAL_TO_REMOTE | CLIPRDR_FLAG_LOCAL_TO_REMOTE_FILES);
|
| 671 |
+
|
| 672 |
+
/* Allow initial format list from monitor ready, but ignore later attempts */
|
| 673 |
+
if ((filterList.numFormats == 0) && cliprdr->initialFormatListSent)
|
| 674 |
+
{
|
| 675 |
+
cliprdr_free_format_list(&filterList);
|
| 676 |
+
return CHANNEL_RC_OK;
|
| 677 |
+
}
|
| 678 |
+
cliprdr->initialFormatListSent = TRUE;
|
| 679 |
+
|
| 680 |
+
s = cliprdr_packet_format_list_new(&filterList, cliprdr->useLongFormatNames, FALSE);
|
| 681 |
+
cliprdr_free_format_list(&filterList);
|
| 682 |
+
|
| 683 |
+
if (!s)
|
| 684 |
+
{
|
| 685 |
+
WLog_ERR(TAG, "cliprdr_packet_format_list_new failed!");
|
| 686 |
+
return ERROR_INTERNAL_ERROR;
|
| 687 |
+
}
|
| 688 |
+
|
| 689 |
+
WLog_Print(cliprdr->log, WLOG_DEBUG, "ClientFormatList: numFormats: %" PRIu32 "",
|
| 690 |
+
formatList->numFormats);
|
| 691 |
+
return cliprdr_packet_send(cliprdr, s);
|
| 692 |
+
}
|
| 693 |
+
|
| 694 |
+
/**
|
| 695 |
+
* Function description
|
| 696 |
+
*
|
| 697 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 698 |
+
*/
|
| 699 |
+
static UINT
|
| 700 |
+
cliprdr_client_format_list_response(CliprdrClientContext* context,
|
| 701 |
+
const CLIPRDR_FORMAT_LIST_RESPONSE* formatListResponse)
|
| 702 |
+
{
|
| 703 |
+
wStream* s = NULL;
|
| 704 |
+
cliprdrPlugin* cliprdr = NULL;
|
| 705 |
+
|
| 706 |
+
WINPR_ASSERT(context);
|
| 707 |
+
WINPR_ASSERT(formatListResponse);
|
| 708 |
+
|
| 709 |
+
cliprdr = (cliprdrPlugin*)context->handle;
|
| 710 |
+
WINPR_ASSERT(cliprdr);
|
| 711 |
+
|
| 712 |
+
s = cliprdr_packet_new(CB_FORMAT_LIST_RESPONSE, formatListResponse->common.msgFlags, 0);
|
| 713 |
+
|
| 714 |
+
if (!s)
|
| 715 |
+
{
|
| 716 |
+
WLog_ERR(TAG, "cliprdr_packet_new failed!");
|
| 717 |
+
return ERROR_INTERNAL_ERROR;
|
| 718 |
+
}
|
| 719 |
+
|
| 720 |
+
WLog_Print(cliprdr->log, WLOG_DEBUG, "ClientFormatListResponse");
|
| 721 |
+
return cliprdr_packet_send(cliprdr, s);
|
| 722 |
+
}
|
| 723 |
+
|
| 724 |
+
/**
|
| 725 |
+
* Function description
|
| 726 |
+
*
|
| 727 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 728 |
+
*/
|
| 729 |
+
static UINT cliprdr_client_lock_clipboard_data(CliprdrClientContext* context,
|
| 730 |
+
const CLIPRDR_LOCK_CLIPBOARD_DATA* lockClipboardData)
|
| 731 |
+
{
|
| 732 |
+
wStream* s = NULL;
|
| 733 |
+
cliprdrPlugin* cliprdr = NULL;
|
| 734 |
+
|
| 735 |
+
WINPR_ASSERT(context);
|
| 736 |
+
WINPR_ASSERT(lockClipboardData);
|
| 737 |
+
|
| 738 |
+
cliprdr = (cliprdrPlugin*)context->handle;
|
| 739 |
+
WINPR_ASSERT(cliprdr);
|
| 740 |
+
|
| 741 |
+
s = cliprdr_packet_lock_clipdata_new(lockClipboardData);
|
| 742 |
+
|
| 743 |
+
if (!s)
|
| 744 |
+
{
|
| 745 |
+
WLog_ERR(TAG, "cliprdr_packet_lock_clipdata_new failed!");
|
| 746 |
+
return ERROR_INTERNAL_ERROR;
|
| 747 |
+
}
|
| 748 |
+
|
| 749 |
+
WLog_Print(cliprdr->log, WLOG_DEBUG, "ClientLockClipboardData: clipDataId: 0x%08" PRIX32 "",
|
| 750 |
+
lockClipboardData->clipDataId);
|
| 751 |
+
return cliprdr_packet_send(cliprdr, s);
|
| 752 |
+
}
|
| 753 |
+
|
| 754 |
+
/**
|
| 755 |
+
* Function description
|
| 756 |
+
*
|
| 757 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 758 |
+
*/
|
| 759 |
+
static UINT
|
| 760 |
+
cliprdr_client_unlock_clipboard_data(CliprdrClientContext* context,
|
| 761 |
+
const CLIPRDR_UNLOCK_CLIPBOARD_DATA* unlockClipboardData)
|
| 762 |
+
{
|
| 763 |
+
wStream* s = NULL;
|
| 764 |
+
cliprdrPlugin* cliprdr = NULL;
|
| 765 |
+
|
| 766 |
+
WINPR_ASSERT(context);
|
| 767 |
+
WINPR_ASSERT(unlockClipboardData);
|
| 768 |
+
|
| 769 |
+
cliprdr = (cliprdrPlugin*)context->handle;
|
| 770 |
+
WINPR_ASSERT(cliprdr);
|
| 771 |
+
|
| 772 |
+
s = cliprdr_packet_unlock_clipdata_new(unlockClipboardData);
|
| 773 |
+
|
| 774 |
+
if (!s)
|
| 775 |
+
{
|
| 776 |
+
WLog_ERR(TAG, "cliprdr_packet_unlock_clipdata_new failed!");
|
| 777 |
+
return ERROR_INTERNAL_ERROR;
|
| 778 |
+
}
|
| 779 |
+
|
| 780 |
+
WLog_Print(cliprdr->log, WLOG_DEBUG, "ClientUnlockClipboardData: clipDataId: 0x%08" PRIX32 "",
|
| 781 |
+
unlockClipboardData->clipDataId);
|
| 782 |
+
return cliprdr_packet_send(cliprdr, s);
|
| 783 |
+
}
|
| 784 |
+
|
| 785 |
+
/**
|
| 786 |
+
* Function description
|
| 787 |
+
*
|
| 788 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 789 |
+
*/
|
| 790 |
+
static UINT cliprdr_client_format_data_request(CliprdrClientContext* context,
|
| 791 |
+
const CLIPRDR_FORMAT_DATA_REQUEST* formatDataRequest)
|
| 792 |
+
{
|
| 793 |
+
WINPR_ASSERT(context);
|
| 794 |
+
WINPR_ASSERT(formatDataRequest);
|
| 795 |
+
|
| 796 |
+
cliprdrPlugin* cliprdr = (cliprdrPlugin*)context->handle;
|
| 797 |
+
WINPR_ASSERT(cliprdr);
|
| 798 |
+
|
| 799 |
+
const UINT32 mask =
|
| 800 |
+
freerdp_settings_get_uint32(context->rdpcontext->settings, FreeRDP_ClipboardFeatureMask);
|
| 801 |
+
if ((mask & (CLIPRDR_FLAG_REMOTE_TO_LOCAL | CLIPRDR_FLAG_REMOTE_TO_LOCAL_FILES)) == 0)
|
| 802 |
+
{
|
| 803 |
+
WLog_WARN(TAG, "remote -> local copy disabled, ignoring request");
|
| 804 |
+
return CHANNEL_RC_OK;
|
| 805 |
+
}
|
| 806 |
+
|
| 807 |
+
wStream* s = cliprdr_packet_new(CB_FORMAT_DATA_REQUEST, 0, 4);
|
| 808 |
+
if (!s)
|
| 809 |
+
{
|
| 810 |
+
WLog_ERR(TAG, "cliprdr_packet_new failed!");
|
| 811 |
+
return ERROR_INTERNAL_ERROR;
|
| 812 |
+
}
|
| 813 |
+
|
| 814 |
+
Stream_Write_UINT32(s, formatDataRequest->requestedFormatId); /* requestedFormatId (4 bytes) */
|
| 815 |
+
WLog_Print(cliprdr->log, WLOG_DEBUG, "ClientFormatDataRequest(0x%08" PRIx32 ")",
|
| 816 |
+
formatDataRequest->requestedFormatId);
|
| 817 |
+
return cliprdr_packet_send(cliprdr, s);
|
| 818 |
+
}
|
| 819 |
+
|
| 820 |
+
/**
|
| 821 |
+
* Function description
|
| 822 |
+
*
|
| 823 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 824 |
+
*/
|
| 825 |
+
static UINT
|
| 826 |
+
cliprdr_client_format_data_response(CliprdrClientContext* context,
|
| 827 |
+
const CLIPRDR_FORMAT_DATA_RESPONSE* formatDataResponse)
|
| 828 |
+
{
|
| 829 |
+
WINPR_ASSERT(context);
|
| 830 |
+
WINPR_ASSERT(formatDataResponse);
|
| 831 |
+
|
| 832 |
+
cliprdrPlugin* cliprdr = (cliprdrPlugin*)context->handle;
|
| 833 |
+
WINPR_ASSERT(cliprdr);
|
| 834 |
+
|
| 835 |
+
WINPR_ASSERT(
|
| 836 |
+
(freerdp_settings_get_uint32(context->rdpcontext->settings, FreeRDP_ClipboardFeatureMask) &
|
| 837 |
+
(CLIPRDR_FLAG_LOCAL_TO_REMOTE | CLIPRDR_FLAG_LOCAL_TO_REMOTE_FILES)) != 0);
|
| 838 |
+
|
| 839 |
+
wStream* s = cliprdr_packet_new(CB_FORMAT_DATA_RESPONSE, formatDataResponse->common.msgFlags,
|
| 840 |
+
formatDataResponse->common.dataLen);
|
| 841 |
+
|
| 842 |
+
if (!s)
|
| 843 |
+
{
|
| 844 |
+
WLog_ERR(TAG, "cliprdr_packet_new failed!");
|
| 845 |
+
return ERROR_INTERNAL_ERROR;
|
| 846 |
+
}
|
| 847 |
+
|
| 848 |
+
Stream_Write(s, formatDataResponse->requestedFormatData, formatDataResponse->common.dataLen);
|
| 849 |
+
WLog_Print(cliprdr->log, WLOG_DEBUG, "ClientFormatDataResponse");
|
| 850 |
+
return cliprdr_packet_send(cliprdr, s);
|
| 851 |
+
}
|
| 852 |
+
|
| 853 |
+
/**
|
| 854 |
+
* Function description
|
| 855 |
+
*
|
| 856 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 857 |
+
*/
|
| 858 |
+
static UINT
|
| 859 |
+
cliprdr_client_file_contents_request(CliprdrClientContext* context,
|
| 860 |
+
const CLIPRDR_FILE_CONTENTS_REQUEST* fileContentsRequest)
|
| 861 |
+
{
|
| 862 |
+
wStream* s = NULL;
|
| 863 |
+
cliprdrPlugin* cliprdr = NULL;
|
| 864 |
+
|
| 865 |
+
WINPR_ASSERT(context);
|
| 866 |
+
WINPR_ASSERT(fileContentsRequest);
|
| 867 |
+
|
| 868 |
+
const UINT32 mask =
|
| 869 |
+
freerdp_settings_get_uint32(context->rdpcontext->settings, FreeRDP_ClipboardFeatureMask);
|
| 870 |
+
if ((mask & CLIPRDR_FLAG_REMOTE_TO_LOCAL_FILES) == 0)
|
| 871 |
+
{
|
| 872 |
+
WLog_WARN(TAG, "remote -> local file copy disabled, ignoring request");
|
| 873 |
+
return CHANNEL_RC_OK;
|
| 874 |
+
}
|
| 875 |
+
|
| 876 |
+
cliprdr = (cliprdrPlugin*)context->handle;
|
| 877 |
+
if (!cliprdr)
|
| 878 |
+
return ERROR_INTERNAL_ERROR;
|
| 879 |
+
|
| 880 |
+
if (!cliprdr->hasHugeFileSupport)
|
| 881 |
+
{
|
| 882 |
+
if (((UINT64)fileContentsRequest->cbRequested + fileContentsRequest->nPositionLow) >
|
| 883 |
+
UINT32_MAX)
|
| 884 |
+
return ERROR_INVALID_PARAMETER;
|
| 885 |
+
if (fileContentsRequest->nPositionHigh != 0)
|
| 886 |
+
return ERROR_INVALID_PARAMETER;
|
| 887 |
+
}
|
| 888 |
+
|
| 889 |
+
s = cliprdr_packet_file_contents_request_new(fileContentsRequest);
|
| 890 |
+
|
| 891 |
+
if (!s)
|
| 892 |
+
{
|
| 893 |
+
WLog_ERR(TAG, "cliprdr_packet_file_contents_request_new failed!");
|
| 894 |
+
return ERROR_INTERNAL_ERROR;
|
| 895 |
+
}
|
| 896 |
+
|
| 897 |
+
WLog_Print(cliprdr->log, WLOG_DEBUG, "ClientFileContentsRequest: streamId: 0x%08" PRIX32 "",
|
| 898 |
+
fileContentsRequest->streamId);
|
| 899 |
+
return cliprdr_packet_send(cliprdr, s);
|
| 900 |
+
}
|
| 901 |
+
|
| 902 |
+
/**
|
| 903 |
+
* Function description
|
| 904 |
+
*
|
| 905 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 906 |
+
*/
|
| 907 |
+
static UINT
|
| 908 |
+
cliprdr_client_file_contents_response(CliprdrClientContext* context,
|
| 909 |
+
const CLIPRDR_FILE_CONTENTS_RESPONSE* fileContentsResponse)
|
| 910 |
+
{
|
| 911 |
+
wStream* s = NULL;
|
| 912 |
+
cliprdrPlugin* cliprdr = NULL;
|
| 913 |
+
|
| 914 |
+
WINPR_ASSERT(context);
|
| 915 |
+
WINPR_ASSERT(fileContentsResponse);
|
| 916 |
+
|
| 917 |
+
cliprdr = (cliprdrPlugin*)context->handle;
|
| 918 |
+
WINPR_ASSERT(cliprdr);
|
| 919 |
+
|
| 920 |
+
const UINT32 mask =
|
| 921 |
+
freerdp_settings_get_uint32(context->rdpcontext->settings, FreeRDP_ClipboardFeatureMask);
|
| 922 |
+
if ((mask & CLIPRDR_FLAG_LOCAL_TO_REMOTE_FILES) == 0)
|
| 923 |
+
return cliprdr_send_error_response(cliprdr, CB_FILECONTENTS_RESPONSE);
|
| 924 |
+
|
| 925 |
+
s = cliprdr_packet_file_contents_response_new(fileContentsResponse);
|
| 926 |
+
|
| 927 |
+
if (!s)
|
| 928 |
+
{
|
| 929 |
+
WLog_ERR(TAG, "cliprdr_packet_file_contents_response_new failed!");
|
| 930 |
+
return ERROR_INTERNAL_ERROR;
|
| 931 |
+
}
|
| 932 |
+
|
| 933 |
+
WLog_Print(cliprdr->log, WLOG_DEBUG, "ClientFileContentsResponse: streamId: 0x%08" PRIX32 "",
|
| 934 |
+
fileContentsResponse->streamId);
|
| 935 |
+
return cliprdr_packet_send(cliprdr, s);
|
| 936 |
+
}
|
| 937 |
+
|
| 938 |
+
static VOID VCAPITYPE cliprdr_virtual_channel_open_event_ex(LPVOID lpUserParam, DWORD openHandle,
|
| 939 |
+
UINT event, LPVOID pData,
|
| 940 |
+
UINT32 dataLength, UINT32 totalLength,
|
| 941 |
+
UINT32 dataFlags)
|
| 942 |
+
{
|
| 943 |
+
UINT error = CHANNEL_RC_OK;
|
| 944 |
+
cliprdrPlugin* cliprdr = (cliprdrPlugin*)lpUserParam;
|
| 945 |
+
|
| 946 |
+
switch (event)
|
| 947 |
+
{
|
| 948 |
+
case CHANNEL_EVENT_DATA_RECEIVED:
|
| 949 |
+
if (!cliprdr || (cliprdr->OpenHandle != openHandle))
|
| 950 |
+
{
|
| 951 |
+
WLog_ERR(TAG, "error no match");
|
| 952 |
+
return;
|
| 953 |
+
}
|
| 954 |
+
if ((error = channel_client_post_message(cliprdr->MsgsHandle, pData, dataLength,
|
| 955 |
+
totalLength, dataFlags)))
|
| 956 |
+
WLog_ERR(TAG, "failed with error %" PRIu32 "", error);
|
| 957 |
+
|
| 958 |
+
break;
|
| 959 |
+
|
| 960 |
+
case CHANNEL_EVENT_WRITE_CANCELLED:
|
| 961 |
+
case CHANNEL_EVENT_WRITE_COMPLETE:
|
| 962 |
+
{
|
| 963 |
+
wStream* s = (wStream*)pData;
|
| 964 |
+
Stream_Free(s, TRUE);
|
| 965 |
+
}
|
| 966 |
+
break;
|
| 967 |
+
|
| 968 |
+
case CHANNEL_EVENT_USER:
|
| 969 |
+
break;
|
| 970 |
+
default:
|
| 971 |
+
break;
|
| 972 |
+
}
|
| 973 |
+
|
| 974 |
+
if (error && cliprdr && cliprdr->context->rdpcontext)
|
| 975 |
+
setChannelError(cliprdr->context->rdpcontext, error,
|
| 976 |
+
"cliprdr_virtual_channel_open_event_ex reported an error");
|
| 977 |
+
}
|
| 978 |
+
|
| 979 |
+
/**
|
| 980 |
+
* Function description
|
| 981 |
+
*
|
| 982 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 983 |
+
*/
|
| 984 |
+
static UINT cliprdr_virtual_channel_event_connected(cliprdrPlugin* cliprdr, LPVOID pData,
|
| 985 |
+
UINT32 dataLength)
|
| 986 |
+
{
|
| 987 |
+
DWORD status = 0;
|
| 988 |
+
WINPR_ASSERT(cliprdr);
|
| 989 |
+
WINPR_ASSERT(cliprdr->context);
|
| 990 |
+
|
| 991 |
+
WINPR_ASSERT(cliprdr->channelEntryPoints.pVirtualChannelOpenEx);
|
| 992 |
+
status = cliprdr->channelEntryPoints.pVirtualChannelOpenEx(
|
| 993 |
+
cliprdr->InitHandle, &cliprdr->OpenHandle, cliprdr->channelDef.name,
|
| 994 |
+
cliprdr_virtual_channel_open_event_ex);
|
| 995 |
+
if (status != CHANNEL_RC_OK)
|
| 996 |
+
return status;
|
| 997 |
+
|
| 998 |
+
cliprdr->MsgsHandle = channel_client_create_handler(
|
| 999 |
+
cliprdr->context->rdpcontext, cliprdr, cliprdr_order_recv, CLIPRDR_SVC_CHANNEL_NAME);
|
| 1000 |
+
if (!cliprdr->MsgsHandle)
|
| 1001 |
+
return ERROR_INTERNAL_ERROR;
|
| 1002 |
+
|
| 1003 |
+
return status;
|
| 1004 |
+
}
|
| 1005 |
+
|
| 1006 |
+
/**
|
| 1007 |
+
* Function description
|
| 1008 |
+
*
|
| 1009 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 1010 |
+
*/
|
| 1011 |
+
static UINT cliprdr_virtual_channel_event_disconnected(cliprdrPlugin* cliprdr)
|
| 1012 |
+
{
|
| 1013 |
+
UINT rc = 0;
|
| 1014 |
+
|
| 1015 |
+
WINPR_ASSERT(cliprdr);
|
| 1016 |
+
|
| 1017 |
+
channel_client_quit_handler(cliprdr->MsgsHandle);
|
| 1018 |
+
cliprdr->MsgsHandle = NULL;
|
| 1019 |
+
|
| 1020 |
+
if (cliprdr->OpenHandle == 0)
|
| 1021 |
+
return CHANNEL_RC_OK;
|
| 1022 |
+
|
| 1023 |
+
WINPR_ASSERT(cliprdr->channelEntryPoints.pVirtualChannelCloseEx);
|
| 1024 |
+
rc = cliprdr->channelEntryPoints.pVirtualChannelCloseEx(cliprdr->InitHandle,
|
| 1025 |
+
cliprdr->OpenHandle);
|
| 1026 |
+
|
| 1027 |
+
if (CHANNEL_RC_OK != rc)
|
| 1028 |
+
{
|
| 1029 |
+
WLog_ERR(TAG, "pVirtualChannelClose failed with %s [%08" PRIX32 "]", WTSErrorToString(rc),
|
| 1030 |
+
rc);
|
| 1031 |
+
return rc;
|
| 1032 |
+
}
|
| 1033 |
+
|
| 1034 |
+
cliprdr->OpenHandle = 0;
|
| 1035 |
+
|
| 1036 |
+
return CHANNEL_RC_OK;
|
| 1037 |
+
}
|
| 1038 |
+
|
| 1039 |
+
/**
|
| 1040 |
+
* Function description
|
| 1041 |
+
*
|
| 1042 |
+
* @return 0 on success, otherwise a Win32 error code
|
| 1043 |
+
*/
|
| 1044 |
+
static UINT cliprdr_virtual_channel_event_terminated(cliprdrPlugin* cliprdr)
|
| 1045 |
+
{
|
| 1046 |
+
WINPR_ASSERT(cliprdr);
|
| 1047 |
+
|
| 1048 |
+
cliprdr->InitHandle = 0;
|
| 1049 |
+
free(cliprdr->context);
|
| 1050 |
+
free(cliprdr);
|
| 1051 |
+
return CHANNEL_RC_OK;
|
| 1052 |
+
}
|
| 1053 |
+
|
| 1054 |
+
static VOID VCAPITYPE cliprdr_virtual_channel_init_event_ex(LPVOID lpUserParam, LPVOID pInitHandle,
|
| 1055 |
+
UINT event, LPVOID pData,
|
| 1056 |
+
UINT dataLength)
|
| 1057 |
+
{
|
| 1058 |
+
UINT error = CHANNEL_RC_OK;
|
| 1059 |
+
cliprdrPlugin* cliprdr = (cliprdrPlugin*)lpUserParam;
|
| 1060 |
+
|
| 1061 |
+
if (!cliprdr || (cliprdr->InitHandle != pInitHandle))
|
| 1062 |
+
{
|
| 1063 |
+
WLog_ERR(TAG, "error no match");
|
| 1064 |
+
return;
|
| 1065 |
+
}
|
| 1066 |
+
|
| 1067 |
+
switch (event)
|
| 1068 |
+
{
|
| 1069 |
+
case CHANNEL_EVENT_CONNECTED:
|
| 1070 |
+
if ((error = cliprdr_virtual_channel_event_connected(cliprdr, pData, dataLength)))
|
| 1071 |
+
WLog_ERR(TAG,
|
| 1072 |
+
"cliprdr_virtual_channel_event_connected failed with error %" PRIu32 "!",
|
| 1073 |
+
error);
|
| 1074 |
+
|
| 1075 |
+
break;
|
| 1076 |
+
|
| 1077 |
+
case CHANNEL_EVENT_DISCONNECTED:
|
| 1078 |
+
if ((error = cliprdr_virtual_channel_event_disconnected(cliprdr)))
|
| 1079 |
+
WLog_ERR(TAG,
|
| 1080 |
+
"cliprdr_virtual_channel_event_disconnected failed with error %" PRIu32
|
| 1081 |
+
"!",
|
| 1082 |
+
error);
|
| 1083 |
+
|
| 1084 |
+
break;
|
| 1085 |
+
|
| 1086 |
+
case CHANNEL_EVENT_TERMINATED:
|
| 1087 |
+
if ((error = cliprdr_virtual_channel_event_terminated(cliprdr)))
|
| 1088 |
+
WLog_ERR(TAG,
|
| 1089 |
+
"cliprdr_virtual_channel_event_terminated failed with error %" PRIu32 "!",
|
| 1090 |
+
error);
|
| 1091 |
+
break;
|
| 1092 |
+
default:
|
| 1093 |
+
break;
|
| 1094 |
+
}
|
| 1095 |
+
|
| 1096 |
+
if (error && cliprdr->context->rdpcontext)
|
| 1097 |
+
setChannelError(cliprdr->context->rdpcontext, error,
|
| 1098 |
+
"cliprdr_virtual_channel_init_event reported an error");
|
| 1099 |
+
}
|
| 1100 |
+
|
| 1101 |
+
/* cliprdr is always built-in */
|
| 1102 |
+
#define VirtualChannelEntryEx cliprdr_VirtualChannelEntryEx
|
| 1103 |
+
|
| 1104 |
+
FREERDP_ENTRY_POINT(BOOL VCAPITYPE VirtualChannelEntryEx(PCHANNEL_ENTRY_POINTS pEntryPoints,
|
| 1105 |
+
PVOID pInitHandle))
|
| 1106 |
+
{
|
| 1107 |
+
UINT rc = 0;
|
| 1108 |
+
cliprdrPlugin* cliprdr = NULL;
|
| 1109 |
+
CliprdrClientContext* context = NULL;
|
| 1110 |
+
CHANNEL_ENTRY_POINTS_FREERDP_EX* pEntryPointsEx = NULL;
|
| 1111 |
+
cliprdr = (cliprdrPlugin*)calloc(1, sizeof(cliprdrPlugin));
|
| 1112 |
+
|
| 1113 |
+
if (!cliprdr)
|
| 1114 |
+
{
|
| 1115 |
+
WLog_ERR(TAG, "calloc failed!");
|
| 1116 |
+
return FALSE;
|
| 1117 |
+
}
|
| 1118 |
+
|
| 1119 |
+
cliprdr->channelDef.options = CHANNEL_OPTION_INITIALIZED | CHANNEL_OPTION_ENCRYPT_RDP |
|
| 1120 |
+
CHANNEL_OPTION_COMPRESS_RDP | CHANNEL_OPTION_SHOW_PROTOCOL;
|
| 1121 |
+
(void)sprintf_s(cliprdr->channelDef.name, ARRAYSIZE(cliprdr->channelDef.name),
|
| 1122 |
+
CLIPRDR_SVC_CHANNEL_NAME);
|
| 1123 |
+
pEntryPointsEx = (CHANNEL_ENTRY_POINTS_FREERDP_EX*)pEntryPoints;
|
| 1124 |
+
WINPR_ASSERT(pEntryPointsEx);
|
| 1125 |
+
|
| 1126 |
+
if ((pEntryPointsEx->cbSize >= sizeof(CHANNEL_ENTRY_POINTS_FREERDP_EX)) &&
|
| 1127 |
+
(pEntryPointsEx->MagicNumber == FREERDP_CHANNEL_MAGIC_NUMBER))
|
| 1128 |
+
{
|
| 1129 |
+
context = (CliprdrClientContext*)calloc(1, sizeof(CliprdrClientContext));
|
| 1130 |
+
|
| 1131 |
+
if (!context)
|
| 1132 |
+
{
|
| 1133 |
+
free(cliprdr);
|
| 1134 |
+
WLog_ERR(TAG, "calloc failed!");
|
| 1135 |
+
return FALSE;
|
| 1136 |
+
}
|
| 1137 |
+
|
| 1138 |
+
context->handle = (void*)cliprdr;
|
| 1139 |
+
context->custom = NULL;
|
| 1140 |
+
context->ClientCapabilities = cliprdr_client_capabilities;
|
| 1141 |
+
context->TempDirectory = cliprdr_temp_directory;
|
| 1142 |
+
context->ClientFormatList = cliprdr_client_format_list;
|
| 1143 |
+
context->ClientFormatListResponse = cliprdr_client_format_list_response;
|
| 1144 |
+
context->ClientLockClipboardData = cliprdr_client_lock_clipboard_data;
|
| 1145 |
+
context->ClientUnlockClipboardData = cliprdr_client_unlock_clipboard_data;
|
| 1146 |
+
context->ClientFormatDataRequest = cliprdr_client_format_data_request;
|
| 1147 |
+
context->ClientFormatDataResponse = cliprdr_client_format_data_response;
|
| 1148 |
+
context->ClientFileContentsRequest = cliprdr_client_file_contents_request;
|
| 1149 |
+
context->ClientFileContentsResponse = cliprdr_client_file_contents_response;
|
| 1150 |
+
cliprdr->context = context;
|
| 1151 |
+
context->rdpcontext = pEntryPointsEx->context;
|
| 1152 |
+
}
|
| 1153 |
+
|
| 1154 |
+
cliprdr->log = WLog_Get(CHANNELS_TAG("channels.cliprdr.client"));
|
| 1155 |
+
WLog_Print(cliprdr->log, WLOG_DEBUG, "VirtualChannelEntryEx");
|
| 1156 |
+
CopyMemory(&(cliprdr->channelEntryPoints), pEntryPoints,
|
| 1157 |
+
sizeof(CHANNEL_ENTRY_POINTS_FREERDP_EX));
|
| 1158 |
+
cliprdr->InitHandle = pInitHandle;
|
| 1159 |
+
rc = cliprdr->channelEntryPoints.pVirtualChannelInitEx(
|
| 1160 |
+
cliprdr, context, pInitHandle, &cliprdr->channelDef, 1, VIRTUAL_CHANNEL_VERSION_WIN2000,
|
| 1161 |
+
cliprdr_virtual_channel_init_event_ex);
|
| 1162 |
+
|
| 1163 |
+
if (CHANNEL_RC_OK != rc)
|
| 1164 |
+
{
|
| 1165 |
+
WLog_ERR(TAG, "pVirtualChannelInit failed with %s [%08" PRIX32 "]", WTSErrorToString(rc),
|
| 1166 |
+
rc);
|
| 1167 |
+
free(cliprdr->context);
|
| 1168 |
+
free(cliprdr);
|
| 1169 |
+
return FALSE;
|
| 1170 |
+
}
|
| 1171 |
+
|
| 1172 |
+
cliprdr->channelEntryPoints.pInterface = context;
|
| 1173 |
+
return TRUE;
|
| 1174 |
+
}
|
local-test-freerdp-delta-01/afc-freerdp/channels/cliprdr/client/cliprdr_main.h
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* FreeRDP: A Remote Desktop Protocol Implementation
|
| 3 |
+
* Clipboard Virtual Channel
|
| 4 |
+
*
|
| 5 |
+
* Copyright 2009-2011 Jay Sorg
|
| 6 |
+
* Copyright 2010-2011 Vic Lee
|
| 7 |
+
* Copyright 2015 DI (FH) Martin Haimberger <martin.haimberger@thincast.com>
|
| 8 |
+
*
|
| 9 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 10 |
+
* you may not use this file except in compliance with the License.
|
| 11 |
+
* You may obtain a copy of the License at
|
| 12 |
+
*
|
| 13 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 14 |
+
*
|
| 15 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 16 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 17 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 18 |
+
* See the License for the specific language governing permissions and
|
| 19 |
+
* limitations under the License.
|
| 20 |
+
*/
|
| 21 |
+
|
| 22 |
+
#ifndef FREERDP_CHANNEL_CLIPRDR_CLIENT_MAIN_H
|
| 23 |
+
#define FREERDP_CHANNEL_CLIPRDR_CLIENT_MAIN_H
|
| 24 |
+
|
| 25 |
+
#include <winpr/stream.h>
|
| 26 |
+
|
| 27 |
+
#include <freerdp/svc.h>
|
| 28 |
+
#include <freerdp/addin.h>
|
| 29 |
+
#include <freerdp/channels/log.h>
|
| 30 |
+
#include <freerdp/client/cliprdr.h>
|
| 31 |
+
|
| 32 |
+
#define TAG CHANNELS_TAG("cliprdr.client")
|
| 33 |
+
|
| 34 |
+
typedef struct
|
| 35 |
+
{
|
| 36 |
+
CHANNEL_DEF channelDef;
|
| 37 |
+
CHANNEL_ENTRY_POINTS_FREERDP_EX channelEntryPoints;
|
| 38 |
+
|
| 39 |
+
CliprdrClientContext* context;
|
| 40 |
+
|
| 41 |
+
wLog* log;
|
| 42 |
+
void* InitHandle;
|
| 43 |
+
DWORD OpenHandle;
|
| 44 |
+
void* MsgsHandle;
|
| 45 |
+
|
| 46 |
+
BOOL capabilitiesReceived;
|
| 47 |
+
BOOL useLongFormatNames;
|
| 48 |
+
BOOL streamFileClipEnabled;
|
| 49 |
+
BOOL fileClipNoFilePaths;
|
| 50 |
+
BOOL canLockClipData;
|
| 51 |
+
BOOL hasHugeFileSupport;
|
| 52 |
+
BOOL initialFormatListSent;
|
| 53 |
+
} cliprdrPlugin;
|
| 54 |
+
|
| 55 |
+
CliprdrClientContext* cliprdr_get_client_interface(cliprdrPlugin* cliprdr);
|
| 56 |
+
UINT cliprdr_send_error_response(cliprdrPlugin* cliprdr, UINT16 type);
|
| 57 |
+
|
| 58 |
+
extern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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* FreeRDP: A Remote Desktop Protocol Implementation
|
| 3 |
+
* Cliprdr common
|
| 4 |
+
*
|
| 5 |
+
* Copyright 2013 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
| 6 |
+
* Copyright 2015 Thincast Technologies GmbH
|
| 7 |
+
* Copyright 2015 DI (FH) Martin Haimberger <martin.haimberger@thincast.com>
|
| 8 |
+
* Copyright 2019 Kobi Mizrachi <kmizrachi18@gmail.com>
|
| 9 |
+
*
|
| 10 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 11 |
+
* you may not use this file except in compliance with the License.
|
| 12 |
+
* You may obtain a copy of the License at
|
| 13 |
+
*
|
| 14 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 15 |
+
*
|
| 16 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 17 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 18 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 19 |
+
* See the License for the specific language governing permissions and
|
| 20 |
+
* limitations under the License.
|
| 21 |
+
*/
|
| 22 |
+
|
| 23 |
+
#include <winpr/crt.h>
|
| 24 |
+
#include <winpr/stream.h>
|
| 25 |
+
#include <freerdp/channels/log.h>
|
| 26 |
+
|
| 27 |
+
#define TAG CHANNELS_TAG("cliprdr.common")
|
| 28 |
+
|
| 29 |
+
#include "cliprdr_common.h"
|
| 30 |
+
|
| 31 |
+
static const char* CB_MSG_TYPE_STR(UINT32 type)
|
| 32 |
+
{
|
| 33 |
+
switch (type)
|
| 34 |
+
{
|
| 35 |
+
case CB_TYPE_NONE:
|
| 36 |
+
return "CB_TYPE_NONE";
|
| 37 |
+
case CB_MONITOR_READY:
|
| 38 |
+
return "CB_MONITOR_READY";
|
| 39 |
+
case CB_FORMAT_LIST:
|
| 40 |
+
return "CB_FORMAT_LIST";
|
| 41 |
+
case CB_FORMAT_LIST_RESPONSE:
|
| 42 |
+
return "CB_FORMAT_LIST_RESPONSE";
|
| 43 |
+
case CB_FORMAT_DATA_REQUEST:
|
| 44 |
+
return "CB_FORMAT_DATA_REQUEST";
|
| 45 |
+
case CB_FORMAT_DATA_RESPONSE:
|
| 46 |
+
return "CB_FORMAT_DATA_RESPONSE";
|
| 47 |
+
case CB_TEMP_DIRECTORY:
|
| 48 |
+
return "CB_TEMP_DIRECTORY";
|
| 49 |
+
case CB_CLIP_CAPS:
|
| 50 |
+
return "CB_CLIP_CAPS";
|
| 51 |
+
case CB_FILECONTENTS_REQUEST:
|
| 52 |
+
return "CB_FILECONTENTS_REQUEST";
|
| 53 |
+
case CB_FILECONTENTS_RESPONSE:
|
| 54 |
+
return "CB_FILECONTENTS_RESPONSE";
|
| 55 |
+
case CB_LOCK_CLIPDATA:
|
| 56 |
+
return "CB_LOCK_CLIPDATA";
|
| 57 |
+
case CB_UNLOCK_CLIPDATA:
|
| 58 |
+
return "CB_UNLOCK_CLIPDATA";
|
| 59 |
+
default:
|
| 60 |
+
return "UNKNOWN";
|
| 61 |
+
}
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
const char* CB_MSG_TYPE_STRING(UINT16 type, char* buffer, size_t size)
|
| 65 |
+
{
|
| 66 |
+
(void)_snprintf(buffer, size, "%s [0x%04" PRIx16 "]", CB_MSG_TYPE_STR(type), type);
|
| 67 |
+
return buffer;
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
const char* CB_MSG_FLAGS_STRING(UINT16 msgFlags, char* buffer, size_t size)
|
| 71 |
+
{
|
| 72 |
+
if ((msgFlags & CB_RESPONSE_OK) != 0)
|
| 73 |
+
winpr_str_append("CB_RESPONSE_OK", buffer, size, "|");
|
| 74 |
+
if ((msgFlags & CB_RESPONSE_FAIL) != 0)
|
| 75 |
+
winpr_str_append("CB_RESPONSE_FAIL", buffer, size, "|");
|
| 76 |
+
if ((msgFlags & CB_ASCII_NAMES) != 0)
|
| 77 |
+
winpr_str_append("CB_ASCII_NAMES", buffer, size, "|");
|
| 78 |
+
|
| 79 |
+
const size_t len = strnlen(buffer, size);
|
| 80 |
+
if (!len)
|
| 81 |
+
winpr_str_append("NONE", buffer, size, "");
|
| 82 |
+
|
| 83 |
+
char val[32] = { 0 };
|
| 84 |
+
(void)_snprintf(val, sizeof(val), "[0x%04" PRIx16 "]", msgFlags);
|
| 85 |
+
winpr_str_append(val, buffer, size, "|");
|
| 86 |
+
return buffer;
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
static BOOL cliprdr_validate_file_contents_request(const CLIPRDR_FILE_CONTENTS_REQUEST* request)
|
| 90 |
+
{
|
| 91 |
+
/*
|
| 92 |
+
* [MS-RDPECLIP] 2.2.5.3 File Contents Request PDU (CLIPRDR_FILECONTENTS_REQUEST).
|
| 93 |
+
*
|
| 94 |
+
* A request for the size of the file identified by the lindex field. The size MUST be
|
| 95 |
+
* returned as a 64-bit, unsigned integer. The cbRequested field MUST be set to
|
| 96 |
+
* 0x00000008 and both the nPositionLow and nPositionHigh fields MUST be
|
| 97 |
+
* set to 0x00000000.
|
| 98 |
+
*/
|
| 99 |
+
|
| 100 |
+
if (request->dwFlags & FILECONTENTS_SIZE)
|
| 101 |
+
{
|
| 102 |
+
if (request->cbRequested != sizeof(UINT64))
|
| 103 |
+
{
|
| 104 |
+
WLog_ERR(TAG, "cbRequested must be %" PRIu32 ", got %" PRIu32 "", sizeof(UINT64),
|
| 105 |
+
request->cbRequested);
|
| 106 |
+
return FALSE;
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
if (request->nPositionHigh != 0 || request->nPositionLow != 0)
|
| 110 |
+
{
|
| 111 |
+
WLog_ERR(TAG, "nPositionHigh and nPositionLow must be set to 0");
|
| 112 |
+
return FALSE;
|
| 113 |
+
}
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
return TRUE;
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
wStream* cliprdr_packet_new(UINT16 msgType, UINT16 msgFlags, UINT32 dataLen)
|
| 120 |
+
{
|
| 121 |
+
wStream* s = NULL;
|
| 122 |
+
s = Stream_New(NULL, dataLen + 8);
|
| 123 |
+
|
| 124 |
+
if (!s)
|
| 125 |
+
{
|
| 126 |
+
WLog_ERR(TAG, "Stream_New failed!");
|
| 127 |
+
return NULL;
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
Stream_Write_UINT16(s, msgType);
|
| 131 |
+
Stream_Write_UINT16(s, msgFlags);
|
| 132 |
+
/* Write actual length after the entire packet has been constructed. */
|
| 133 |
+
Stream_Write_UINT32(s, 0);
|
| 134 |
+
return s;
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
static void cliprdr_write_file_contents_request(wStream* s,
|
| 138 |
+
const CLIPRDR_FILE_CONTENTS_REQUEST* request)
|
| 139 |
+
{
|
| 140 |
+
Stream_Write_UINT32(s, request->streamId); /* streamId (4 bytes) */
|
| 141 |
+
Stream_Write_UINT32(s, request->listIndex); /* listIndex (4 bytes) */
|
| 142 |
+
Stream_Write_UINT32(s, request->dwFlags); /* dwFlags (4 bytes) */
|
| 143 |
+
Stream_Write_UINT32(s, request->nPositionLow); /* nPositionLow (4 bytes) */
|
| 144 |
+
Stream_Write_UINT32(s, request->nPositionHigh); /* nPositionHigh (4 bytes) */
|
| 145 |
+
Stream_Write_UINT32(s, request->cbRequested); /* cbRequested (4 bytes) */
|
| 146 |
+
|
| 147 |
+
if (request->haveClipDataId)
|
| 148 |
+
Stream_Write_UINT32(s, request->clipDataId); /* clipDataId (4 bytes) */
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
static INLINE void cliprdr_write_lock_unlock_clipdata(wStream* s, UINT32 clipDataId)
|
| 152 |
+
{
|
| 153 |
+
Stream_Write_UINT32(s, clipDataId);
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
static void cliprdr_write_lock_clipdata(wStream* s,
|
| 157 |
+
const CLIPRDR_LOCK_CLIPBOARD_DATA* lockClipboardData)
|
| 158 |
+
{
|
| 159 |
+
cliprdr_write_lock_unlock_clipdata(s, lockClipboardData->clipDataId);
|
| 160 |
+
}
|
| 161 |
+
|
| 162 |
+
static void cliprdr_write_unlock_clipdata(wStream* s,
|
| 163 |
+
const CLIPRDR_UNLOCK_CLIPBOARD_DATA* unlockClipboardData)
|
| 164 |
+
{
|
| 165 |
+
cliprdr_write_lock_unlock_clipdata(s, unlockClipboardData->clipDataId);
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
static void cliprdr_write_file_contents_response(wStream* s,
|
| 169 |
+
const CLIPRDR_FILE_CONTENTS_RESPONSE* response)
|
| 170 |
+
{
|
| 171 |
+
Stream_Write_UINT32(s, response->streamId); /* streamId (4 bytes) */
|
| 172 |
+
Stream_Write(s, response->requestedData, response->cbRequested);
|
| 173 |
+
}
|
| 174 |
+
|
| 175 |
+
wStream* cliprdr_packet_lock_clipdata_new(const CLIPRDR_LOCK_CLIPBOARD_DATA* lockClipboardData)
|
| 176 |
+
{
|
| 177 |
+
wStream* s = NULL;
|
| 178 |
+
|
| 179 |
+
if (!lockClipboardData)
|
| 180 |
+
return NULL;
|
| 181 |
+
|
| 182 |
+
s = cliprdr_packet_new(CB_LOCK_CLIPDATA, 0, 4);
|
| 183 |
+
|
| 184 |
+
if (!s)
|
| 185 |
+
return NULL;
|
| 186 |
+
|
| 187 |
+
cliprdr_write_lock_clipdata(s, lockClipboardData);
|
| 188 |
+
return s;
|
| 189 |
+
}
|
| 190 |
+
|
| 191 |
+
wStream*
|
| 192 |
+
cliprdr_packet_unlock_clipdata_new(const CLIPRDR_UNLOCK_CLIPBOARD_DATA* unlockClipboardData)
|
| 193 |
+
{
|
| 194 |
+
wStream* s = NULL;
|
| 195 |
+
|
| 196 |
+
if (!unlockClipboardData)
|
| 197 |
+
return NULL;
|
| 198 |
+
|
| 199 |
+
s = cliprdr_packet_new(CB_UNLOCK_CLIPDATA, 0, 4);
|
| 200 |
+
|
| 201 |
+
if (!s)
|
| 202 |
+
return NULL;
|
| 203 |
+
|
| 204 |
+
cliprdr_write_unlock_clipdata(s, unlockClipboardData);
|
| 205 |
+
return s;
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
wStream* cliprdr_packet_file_contents_request_new(const CLIPRDR_FILE_CONTENTS_REQUEST* request)
|
| 209 |
+
{
|
| 210 |
+
wStream* s = NULL;
|
| 211 |
+
|
| 212 |
+
if (!request)
|
| 213 |
+
return NULL;
|
| 214 |
+
|
| 215 |
+
s = cliprdr_packet_new(CB_FILECONTENTS_REQUEST, 0, 28);
|
| 216 |
+
|
| 217 |
+
if (!s)
|
| 218 |
+
return NULL;
|
| 219 |
+
|
| 220 |
+
cliprdr_write_file_contents_request(s, request);
|
| 221 |
+
return s;
|
| 222 |
+
}
|
| 223 |
+
|
| 224 |
+
wStream* cliprdr_packet_file_contents_response_new(const CLIPRDR_FILE_CONTENTS_RESPONSE* response)
|
| 225 |
+
{
|
| 226 |
+
wStream* s = NULL;
|
| 227 |
+
|
| 228 |
+
if (!response)
|
| 229 |
+
return NULL;
|
| 230 |
+
|
| 231 |
+
s = cliprdr_packet_new(CB_FILECONTENTS_RESPONSE, response->common.msgFlags,
|
| 232 |
+
4 + response->cbRequested);
|
| 233 |
+
|
| 234 |
+
if (!s)
|
| 235 |
+
return NULL;
|
| 236 |
+
|
| 237 |
+
cliprdr_write_file_contents_response(s, response);
|
| 238 |
+
return s;
|
| 239 |
+
}
|
| 240 |
+
|
| 241 |
+
wStream* cliprdr_packet_format_list_new(const CLIPRDR_FORMAT_LIST* formatList,
|
| 242 |
+
BOOL useLongFormatNames, BOOL useAsciiNames)
|
| 243 |
+
{
|
| 244 |
+
WINPR_ASSERT(formatList);
|
| 245 |
+
|
| 246 |
+
if (formatList->common.msgType != CB_FORMAT_LIST)
|
| 247 |
+
WLog_WARN(TAG, "called with invalid type %08" PRIx32, formatList->common.msgType);
|
| 248 |
+
|
| 249 |
+
if (useLongFormatNames && useAsciiNames)
|
| 250 |
+
WLog_WARN(TAG, "called with invalid arguments useLongFormatNames=true && "
|
| 251 |
+
"useAsciiNames=true. useAsciiNames requires "
|
| 252 |
+
"useLongFormatNames=false, ignoring argument.");
|
| 253 |
+
|
| 254 |
+
const UINT32 length = formatList->numFormats * 36;
|
| 255 |
+
const size_t formatNameCharSize =
|
| 256 |
+
(useLongFormatNames || !useAsciiNames) ? sizeof(WCHAR) : sizeof(CHAR);
|
| 257 |
+
|
| 258 |
+
wStream* s = cliprdr_packet_new(CB_FORMAT_LIST, 0, length);
|
| 259 |
+
if (!s)
|
| 260 |
+
{
|
| 261 |
+
WLog_ERR(TAG, "cliprdr_packet_new failed!");
|
| 262 |
+
return NULL;
|
| 263 |
+
}
|
| 264 |
+
|
| 265 |
+
for (UINT32 index = 0; index < formatList->numFormats; index++)
|
| 266 |
+
{
|
| 267 |
+
const CLIPRDR_FORMAT* format = &(formatList->formats[index]);
|
| 268 |
+
|
| 269 |
+
const char* szFormatName = format->formatName;
|
| 270 |
+
size_t formatNameLength = 0;
|
| 271 |
+
if (szFormatName)
|
| 272 |
+
formatNameLength = strlen(szFormatName);
|
| 273 |
+
|
| 274 |
+
size_t formatNameMaxLength = formatNameLength + 1; /* Ensure '\0' termination in output */
|
| 275 |
+
if (!Stream_EnsureRemainingCapacity(s,
|
| 276 |
+
4 + MAX(32, formatNameMaxLength * formatNameCharSize)))
|
| 277 |
+
goto fail;
|
| 278 |
+
|
| 279 |
+
Stream_Write_UINT32(s, format->formatId); /* formatId (4 bytes) */
|
| 280 |
+
|
| 281 |
+
if (!useLongFormatNames)
|
| 282 |
+
{
|
| 283 |
+
formatNameMaxLength = useAsciiNames ? 32 : 16;
|
| 284 |
+
formatNameLength = MIN(formatNameMaxLength - 1, formatNameLength);
|
| 285 |
+
}
|
| 286 |
+
|
| 287 |
+
if (szFormatName && (formatNameLength > 0))
|
| 288 |
+
{
|
| 289 |
+
if (useAsciiNames)
|
| 290 |
+
{
|
| 291 |
+
Stream_Write(s, szFormatName, formatNameLength);
|
| 292 |
+
Stream_Zero(s, formatNameMaxLength - formatNameLength);
|
| 293 |
+
}
|
| 294 |
+
else
|
| 295 |
+
{
|
| 296 |
+
if (Stream_Write_UTF16_String_From_UTF8(s, formatNameMaxLength, szFormatName,
|
| 297 |
+
formatNameLength, TRUE) < 0)
|
| 298 |
+
goto fail;
|
| 299 |
+
}
|
| 300 |
+
}
|
| 301 |
+
else
|
| 302 |
+
Stream_Zero(s, formatNameMaxLength * formatNameCharSize);
|
| 303 |
+
}
|
| 304 |
+
|
| 305 |
+
return s;
|
| 306 |
+
|
| 307 |
+
fail:
|
| 308 |
+
Stream_Free(s, TRUE);
|
| 309 |
+
return NULL;
|
| 310 |
+
}
|
| 311 |
+
|
| 312 |
+
UINT cliprdr_read_unlock_clipdata(wStream* s, CLIPRDR_UNLOCK_CLIPBOARD_DATA* unlockClipboardData)
|
| 313 |
+
{
|
| 314 |
+
if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
|
| 315 |
+
return ERROR_INVALID_DATA;
|
| 316 |
+
|
| 317 |
+
Stream_Read_UINT32(s, unlockClipboardData->clipDataId); /* clipDataId (4 bytes) */
|
| 318 |
+
return CHANNEL_RC_OK;
|
| 319 |
+
}
|
| 320 |
+
|
| 321 |
+
UINT cliprdr_read_format_data_request(wStream* s, CLIPRDR_FORMAT_DATA_REQUEST* request)
|
| 322 |
+
{
|
| 323 |
+
if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
|
| 324 |
+
return ERROR_INVALID_DATA;
|
| 325 |
+
|
| 326 |
+
Stream_Read_UINT32(s, request->requestedFormatId); /* requestedFormatId (4 bytes) */
|
| 327 |
+
return CHANNEL_RC_OK;
|
| 328 |
+
}
|
| 329 |
+
|
| 330 |
+
UINT cliprdr_read_format_data_response(wStream* s, CLIPRDR_FORMAT_DATA_RESPONSE* response)
|
| 331 |
+
{
|
| 332 |
+
response->requestedFormatData = NULL;
|
| 333 |
+
|
| 334 |
+
if (!Stream_CheckAndLogRequiredLength(TAG, s, response->common.dataLen))
|
| 335 |
+
return ERROR_INVALID_DATA;
|
| 336 |
+
|
| 337 |
+
if (response->common.dataLen)
|
| 338 |
+
response->requestedFormatData = Stream_ConstPointer(s);
|
| 339 |
+
|
| 340 |
+
return CHANNEL_RC_OK;
|
| 341 |
+
}
|
| 342 |
+
|
| 343 |
+
UINT cliprdr_read_file_contents_request(wStream* s, CLIPRDR_FILE_CONTENTS_REQUEST* request)
|
| 344 |
+
{
|
| 345 |
+
if (!Stream_CheckAndLogRequiredLength(TAG, s, 24))
|
| 346 |
+
return ERROR_INVALID_DATA;
|
| 347 |
+
|
| 348 |
+
request->haveClipDataId = FALSE;
|
| 349 |
+
Stream_Read_UINT32(s, request->streamId); /* streamId (4 bytes) */
|
| 350 |
+
Stream_Read_UINT32(s, request->listIndex); /* listIndex (4 bytes) */
|
| 351 |
+
Stream_Read_UINT32(s, request->dwFlags); /* dwFlags (4 bytes) */
|
| 352 |
+
Stream_Read_UINT32(s, request->nPositionLow); /* nPositionLow (4 bytes) */
|
| 353 |
+
Stream_Read_UINT32(s, request->nPositionHigh); /* nPositionHigh (4 bytes) */
|
| 354 |
+
Stream_Read_UINT32(s, request->cbRequested); /* cbRequested (4 bytes) */
|
| 355 |
+
|
| 356 |
+
if (Stream_GetRemainingLength(s) >= 4)
|
| 357 |
+
{
|
| 358 |
+
Stream_Read_UINT32(s, request->clipDataId); /* clipDataId (4 bytes) */
|
| 359 |
+
request->haveClipDataId = TRUE;
|
| 360 |
+
}
|
| 361 |
+
|
| 362 |
+
if (!cliprdr_validate_file_contents_request(request))
|
| 363 |
+
return ERROR_BAD_ARGUMENTS;
|
| 364 |
+
|
| 365 |
+
return CHANNEL_RC_OK;
|
| 366 |
+
}
|
| 367 |
+
|
| 368 |
+
UINT cliprdr_read_file_contents_response(wStream* s, CLIPRDR_FILE_CONTENTS_RESPONSE* response)
|
| 369 |
+
{
|
| 370 |
+
if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
|
| 371 |
+
return ERROR_INVALID_DATA;
|
| 372 |
+
|
| 373 |
+
Stream_Read_UINT32(s, response->streamId); /* streamId (4 bytes) */
|
| 374 |
+
response->requestedData = Stream_ConstPointer(s); /* requestedFileContentsData */
|
| 375 |
+
|
| 376 |
+
WINPR_ASSERT(response->common.dataLen >= 4);
|
| 377 |
+
response->cbRequested = response->common.dataLen - 4;
|
| 378 |
+
return CHANNEL_RC_OK;
|
| 379 |
+
}
|
| 380 |
+
|
| 381 |
+
UINT cliprdr_read_format_list(wStream* s, CLIPRDR_FORMAT_LIST* formatList, BOOL useLongFormatNames)
|
| 382 |
+
{
|
| 383 |
+
UINT32 index = 0;
|
| 384 |
+
size_t formatNameLength = 0;
|
| 385 |
+
const char* szFormatName = NULL;
|
| 386 |
+
const WCHAR* wszFormatName = NULL;
|
| 387 |
+
wStream sub1buffer = { 0 };
|
| 388 |
+
CLIPRDR_FORMAT* formats = NULL;
|
| 389 |
+
UINT error = ERROR_INTERNAL_ERROR;
|
| 390 |
+
|
| 391 |
+
const BOOL asciiNames = (formatList->common.msgFlags & CB_ASCII_NAMES) ? TRUE : FALSE;
|
| 392 |
+
|
| 393 |
+
index = 0;
|
| 394 |
+
/* empty format list */
|
| 395 |
+
formatList->formats = NULL;
|
| 396 |
+
formatList->numFormats = 0;
|
| 397 |
+
|
| 398 |
+
wStream* sub1 =
|
| 399 |
+
Stream_StaticConstInit(&sub1buffer, Stream_ConstPointer(s), formatList->common.dataLen);
|
| 400 |
+
if (!Stream_SafeSeek(s, formatList->common.dataLen))
|
| 401 |
+
return ERROR_INVALID_DATA;
|
| 402 |
+
|
| 403 |
+
if (!formatList->common.dataLen)
|
| 404 |
+
{
|
| 405 |
+
}
|
| 406 |
+
else if (!useLongFormatNames)
|
| 407 |
+
{
|
| 408 |
+
const size_t cap = Stream_Capacity(sub1) / 36ULL;
|
| 409 |
+
if (cap > UINT32_MAX)
|
| 410 |
+
{
|
| 411 |
+
WLog_ERR(TAG, "Invalid short format list length: %" PRIuz "", cap);
|
| 412 |
+
return ERROR_INTERNAL_ERROR;
|
| 413 |
+
}
|
| 414 |
+
formatList->numFormats = (UINT32)cap;
|
| 415 |
+
|
| 416 |
+
if (formatList->numFormats)
|
| 417 |
+
formats = (CLIPRDR_FORMAT*)calloc(formatList->numFormats, sizeof(CLIPRDR_FORMAT));
|
| 418 |
+
|
| 419 |
+
if (!formats)
|
| 420 |
+
{
|
| 421 |
+
WLog_ERR(TAG, "calloc failed!");
|
| 422 |
+
return CHANNEL_RC_NO_MEMORY;
|
| 423 |
+
}
|
| 424 |
+
|
| 425 |
+
formatList->formats = formats;
|
| 426 |
+
|
| 427 |
+
while (Stream_GetRemainingLength(sub1) >= 4)
|
| 428 |
+
{
|
| 429 |
+
CLIPRDR_FORMAT* format = &formats[index];
|
| 430 |
+
|
| 431 |
+
Stream_Read_UINT32(sub1, format->formatId); /* formatId (4 bytes) */
|
| 432 |
+
|
| 433 |
+
/* According to MS-RDPECLIP 2.2.3.1.1.1 formatName is "a 32-byte block containing
|
| 434 |
+
* the *null-terminated* name assigned to the Clipboard Format: (32 ASCII 8 characters
|
| 435 |
+
* or 16 Unicode characters)"
|
| 436 |
+
* However, both Windows RDSH and mstsc violate this specs as seen in the following
|
| 437 |
+
* example of a transferred short format name string: [R.i.c.h. .T.e.x.t. .F.o.r.m.a.t.]
|
| 438 |
+
* These are 16 unicode characters - *without* terminating null !
|
| 439 |
+
*/
|
| 440 |
+
|
| 441 |
+
szFormatName = Stream_ConstPointer(sub1);
|
| 442 |
+
wszFormatName = Stream_ConstPointer(sub1);
|
| 443 |
+
if (!Stream_SafeSeek(sub1, 32))
|
| 444 |
+
goto error_out;
|
| 445 |
+
|
| 446 |
+
free(format->formatName);
|
| 447 |
+
format->formatName = NULL;
|
| 448 |
+
|
| 449 |
+
if (asciiNames)
|
| 450 |
+
{
|
| 451 |
+
if (szFormatName[0])
|
| 452 |
+
{
|
| 453 |
+
/* ensure null termination */
|
| 454 |
+
format->formatName = strndup(szFormatName, 31);
|
| 455 |
+
if (!format->formatName)
|
| 456 |
+
{
|
| 457 |
+
WLog_ERR(TAG, "malloc failed!");
|
| 458 |
+
error = CHANNEL_RC_NO_MEMORY;
|
| 459 |
+
goto error_out;
|
| 460 |
+
}
|
| 461 |
+
}
|
| 462 |
+
}
|
| 463 |
+
else
|
| 464 |
+
{
|
| 465 |
+
if (wszFormatName[0])
|
| 466 |
+
{
|
| 467 |
+
format->formatName = ConvertWCharNToUtf8Alloc(wszFormatName, 16, NULL);
|
| 468 |
+
if (!format->formatName)
|
| 469 |
+
goto error_out;
|
| 470 |
+
}
|
| 471 |
+
}
|
| 472 |
+
|
| 473 |
+
index++;
|
| 474 |
+
}
|
| 475 |
+
}
|
| 476 |
+
else
|
| 477 |
+
{
|
| 478 |
+
wStream sub2buffer = sub1buffer;
|
| 479 |
+
wStream* sub2 = &sub2buffer;
|
| 480 |
+
|
| 481 |
+
while (Stream_GetRemainingLength(sub1) > 0)
|
| 482 |
+
{
|
| 483 |
+
size_t rest = 0;
|
| 484 |
+
if (!Stream_SafeSeek(sub1, 4)) /* formatId (4 bytes) */
|
| 485 |
+
goto error_out;
|
| 486 |
+
|
| 487 |
+
wszFormatName = Stream_ConstPointer(sub1);
|
| 488 |
+
rest = Stream_GetRemainingLength(sub1);
|
| 489 |
+
formatNameLength = _wcsnlen(wszFormatName, rest / sizeof(WCHAR));
|
| 490 |
+
|
| 491 |
+
if (!Stream_SafeSeek(sub1, (formatNameLength + 1) * sizeof(WCHAR)))
|
| 492 |
+
goto error_out;
|
| 493 |
+
formatList->numFormats++;
|
| 494 |
+
}
|
| 495 |
+
|
| 496 |
+
if (formatList->numFormats)
|
| 497 |
+
formats = (CLIPRDR_FORMAT*)calloc(formatList->numFormats, sizeof(CLIPRDR_FORMAT));
|
| 498 |
+
|
| 499 |
+
if (!formats)
|
| 500 |
+
{
|
| 501 |
+
WLog_ERR(TAG, "calloc failed!");
|
| 502 |
+
return CHANNEL_RC_NO_MEMORY;
|
| 503 |
+
}
|
| 504 |
+
|
| 505 |
+
formatList->formats = formats;
|
| 506 |
+
|
| 507 |
+
while (Stream_GetRemainingLength(sub2) >= 4)
|
| 508 |
+
{
|
| 509 |
+
size_t rest = 0;
|
| 510 |
+
CLIPRDR_FORMAT* format = &formats[index];
|
| 511 |
+
|
| 512 |
+
Stream_Read_UINT32(sub2, format->formatId); /* formatId (4 bytes) */
|
| 513 |
+
|
| 514 |
+
free(format->formatName);
|
| 515 |
+
format->formatName = NULL;
|
| 516 |
+
|
| 517 |
+
wszFormatName = Stream_ConstPointer(sub2);
|
| 518 |
+
rest = Stream_GetRemainingLength(sub2);
|
| 519 |
+
formatNameLength = _wcsnlen(wszFormatName, rest / sizeof(WCHAR));
|
| 520 |
+
if (!Stream_SafeSeek(sub2, (formatNameLength + 1) * sizeof(WCHAR)))
|
| 521 |
+
goto error_out;
|
| 522 |
+
|
| 523 |
+
if (formatNameLength)
|
| 524 |
+
{
|
| 525 |
+
format->formatName =
|
| 526 |
+
ConvertWCharNToUtf8Alloc(wszFormatName, formatNameLength, NULL);
|
| 527 |
+
if (!format->formatName)
|
| 528 |
+
goto error_out;
|
| 529 |
+
}
|
| 530 |
+
|
| 531 |
+
index++;
|
| 532 |
+
}
|
| 533 |
+
}
|
| 534 |
+
|
| 535 |
+
return CHANNEL_RC_OK;
|
| 536 |
+
|
| 537 |
+
error_out:
|
| 538 |
+
cliprdr_free_format_list(formatList);
|
| 539 |
+
return error;
|
| 540 |
+
}
|
| 541 |
+
|
| 542 |
+
void cliprdr_free_format_list(CLIPRDR_FORMAT_LIST* formatList)
|
| 543 |
+
{
|
| 544 |
+
if (formatList == NULL)
|
| 545 |
+
return;
|
| 546 |
+
|
| 547 |
+
if (formatList->formats)
|
| 548 |
+
{
|
| 549 |
+
for (UINT32 index = 0; index < formatList->numFormats; index++)
|
| 550 |
+
{
|
| 551 |
+
free(formatList->formats[index].formatName);
|
| 552 |
+
}
|
| 553 |
+
|
| 554 |
+
free(formatList->formats);
|
| 555 |
+
formatList->formats = NULL;
|
| 556 |
+
formatList->numFormats = 0;
|
| 557 |
+
}
|
| 558 |
+
}
|
local-test-freerdp-delta-01/afc-freerdp/channels/cliprdr/cliprdr_common.h
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* FreeRDP: A Remote Desktop Protocol Implementation
|
| 3 |
+
* Cliprdr common
|
| 4 |
+
*
|
| 5 |
+
* Copyright 2013 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
| 6 |
+
* Copyright 2015 Thincast Technologies GmbH
|
| 7 |
+
* Copyright 2015 DI (FH) Martin Haimberger <martin.haimberger@thincast.com>
|
| 8 |
+
* Copyright 2019 Kobi Mizrachi <kmizrachi18@gmail.com>
|
| 9 |
+
*
|
| 10 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 11 |
+
* you may not use this file except in compliance with the License.
|
| 12 |
+
* You may obtain a copy of the License at
|
| 13 |
+
*
|
| 14 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 15 |
+
*
|
| 16 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 17 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 18 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 19 |
+
* See the License for the specific language governing permissions and
|
| 20 |
+
* limitations under the License.
|
| 21 |
+
*/
|
| 22 |
+
|
| 23 |
+
#ifndef FREERDP_CHANNEL_RDPECLIP_COMMON_H
|
| 24 |
+
#define FREERDP_CHANNEL_RDPECLIP_COMMON_H
|
| 25 |
+
|
| 26 |
+
#include <winpr/crt.h>
|
| 27 |
+
#include <winpr/stream.h>
|
| 28 |
+
|
| 29 |
+
#include <freerdp/channels/cliprdr.h>
|
| 30 |
+
#include <freerdp/api.h>
|
| 31 |
+
|
| 32 |
+
FREERDP_LOCAL const char* CB_MSG_TYPE_STRING(UINT16 type, char* buffer, size_t size);
|
| 33 |
+
FREERDP_LOCAL const char* CB_MSG_FLAGS_STRING(UINT16 msgFlags, char* buffer, size_t size);
|
| 34 |
+
|
| 35 |
+
FREERDP_LOCAL wStream* cliprdr_packet_new(UINT16 msgType, UINT16 msgFlags, UINT32 dataLen);
|
| 36 |
+
FREERDP_LOCAL wStream*
|
| 37 |
+
cliprdr_packet_lock_clipdata_new(const CLIPRDR_LOCK_CLIPBOARD_DATA* lockClipboardData);
|
| 38 |
+
FREERDP_LOCAL wStream*
|
| 39 |
+
cliprdr_packet_unlock_clipdata_new(const CLIPRDR_UNLOCK_CLIPBOARD_DATA* unlockClipboardData);
|
| 40 |
+
FREERDP_LOCAL wStream*
|
| 41 |
+
cliprdr_packet_file_contents_request_new(const CLIPRDR_FILE_CONTENTS_REQUEST* request);
|
| 42 |
+
FREERDP_LOCAL wStream*
|
| 43 |
+
cliprdr_packet_file_contents_response_new(const CLIPRDR_FILE_CONTENTS_RESPONSE* response);
|
| 44 |
+
FREERDP_LOCAL wStream* cliprdr_packet_format_list_new(const CLIPRDR_FORMAT_LIST* formatList,
|
| 45 |
+
BOOL useLongFormatNames, BOOL useAsciiNames);
|
| 46 |
+
|
| 47 |
+
FREERDP_LOCAL UINT cliprdr_read_lock_clipdata(wStream* s,
|
| 48 |
+
CLIPRDR_LOCK_CLIPBOARD_DATA* lockClipboardData);
|
| 49 |
+
FREERDP_LOCAL UINT cliprdr_read_unlock_clipdata(wStream* s,
|
| 50 |
+
CLIPRDR_UNLOCK_CLIPBOARD_DATA* unlockClipboardData);
|
| 51 |
+
FREERDP_LOCAL UINT cliprdr_read_format_data_request(wStream* s,
|
| 52 |
+
CLIPRDR_FORMAT_DATA_REQUEST* formatDataRequest);
|
| 53 |
+
FREERDP_LOCAL UINT cliprdr_read_format_data_response(wStream* s,
|
| 54 |
+
CLIPRDR_FORMAT_DATA_RESPONSE* response);
|
| 55 |
+
FREERDP_LOCAL UINT
|
| 56 |
+
cliprdr_read_file_contents_request(wStream* s, CLIPRDR_FILE_CONTENTS_REQUEST* fileContentsRequest);
|
| 57 |
+
FREERDP_LOCAL UINT cliprdr_read_file_contents_response(wStream* s,
|
| 58 |
+
CLIPRDR_FILE_CONTENTS_RESPONSE* response);
|
| 59 |
+
FREERDP_LOCAL UINT cliprdr_read_format_list(wStream* s, CLIPRDR_FORMAT_LIST* formatList,
|
| 60 |
+
BOOL useLongFormatNames);
|
| 61 |
+
|
| 62 |
+
FREERDP_LOCAL void cliprdr_free_format_list(CLIPRDR_FORMAT_LIST* formatList);
|
| 63 |
+
|
| 64 |
+
#endif /* FREERDP_CHANNEL_RDPECLIP_COMMON_H */
|
local-test-freerdp-delta-01/afc-freerdp/channels/cliprdr/server/CMakeLists.txt
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# FreeRDP: A Remote Desktop Protocol Implementation
|
| 2 |
+
# FreeRDP cmake build script
|
| 3 |
+
#
|
| 4 |
+
# Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
| 5 |
+
#
|
| 6 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 7 |
+
# you may not use this file except in compliance with the License.
|
| 8 |
+
# You may obtain a copy of the License at
|
| 9 |
+
#
|
| 10 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 11 |
+
#
|
| 12 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 13 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 14 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 15 |
+
# See the License for the specific language governing permissions and
|
| 16 |
+
# limitations under the License.
|
| 17 |
+
|
| 18 |
+
define_channel_server("cliprdr")
|
| 19 |
+
|
| 20 |
+
set(${MODULE_PREFIX}_SRCS cliprdr_main.c cliprdr_main.h ../cliprdr_common.h ../cliprdr_common.c)
|
| 21 |
+
|
| 22 |
+
set(${MODULE_PREFIX}_LIBS freerdp)
|
| 23 |
+
add_channel_server_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} FALSE "VirtualChannelEntry")
|