Merge branch 'master' of github.com:FreeRDP/FreeRDP

This commit is contained in:
Marc-André Moreau 2014-05-08 16:11:42 -04:00
commit b0a9d7d690
26 changed files with 469 additions and 771 deletions

View File

@ -50,6 +50,7 @@ include(ConfigOptions)
include(ComplexLibrary)
include(FeatureSummary)
include(CheckCCompilerFlag)
include(CheckCXXCompilerFlag)
include(GNUInstallDirsWrapper)
include(CMakePackageConfigHelpers)
@ -116,15 +117,6 @@ if(MSVC)
endif()
endif()
CHECK_C_COMPILER_FLAG (-Wno-builtin-macro-redefined Wno-builtin-macro-redefined)
if(Wno-builtin-macro-redefined)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-builtin-macro-redefined")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-builtin-macro-redefined")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS} -D__FILE__='\"$(subst ${CMAKE_BINARY_DIR}/,,$(subst ${CMAKE_SOURCE_DIR}/,,$(abspath $<)))\"'")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -D__FILE__='\"$(subst ${CMAKE_BINARY_DIR}/,,$(subst ${CMAKE_SOURCE_DIR}/,,$(abspath $<)))\"'")
endif()
# Compiler-specific flags
if(CMAKE_COMPILER_IS_GNUCC)
if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64" OR CMAKE_SYSTEM_PROCESSOR MATCHES "i686")
@ -154,8 +146,12 @@ if(CMAKE_COMPILER_IS_GNUCC)
CHECK_C_COMPILER_FLAG(-Wno-deprecated-declarations Wno-deprecated-declarations)
if(Wno-deprecated-declarations)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-deprecated-declarations")
endif()
CHECK_CXX_COMPILER_FLAG(-Wno-deprecated-declarations Wno-deprecated-declarationsCXX)
if(Wno-deprecated-declarationsCXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations")
endif()
if(NOT EXPORT_ALL_SYMBOLS)
message(STATUS "GCC default symbol visibility: hidden")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden")
@ -167,8 +163,22 @@ if(CMAKE_COMPILER_IS_GNUCC)
endif()
endif()
if(CMAKE_BUILD_TYPE STREQUAL "Release")
set(CMAKE_C_FLAGS_RELEASE "-DNDEBUG")
set(CMAKE_C_FLAGS_RELEASE "-DNDEBUG")
set(CMAKE_CXX_FLAGS_RELEASE "-DNDEBUG")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2")
CHECK_C_COMPILER_FLAG (-Wno-builtin-macro-redefined Wno-builtin-macro-redefined)
if(Wno-builtin-macro-redefined)
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Wno-builtin-macro-redefined")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -D__FILE__='\"$(subst ${CMAKE_BINARY_DIR}/,,$(subst ${CMAKE_SOURCE_DIR}/,,$(abspath $<)))\"'")
endif()
CHECK_CXX_COMPILER_FLAG (-Wno-builtin-macro-redefined Wno-builtin-macro-redefinedCXX)
if(Wno-builtin-macro-redefinedCXX)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Wno-builtin-macro-redefined")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -D__FILE__='\"$(subst ${CMAKE_BINARY_DIR}/,,$(subst ${CMAKE_SOURCE_DIR}/,,$(abspath $<)))\"'")
endif()
else()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")
@ -188,6 +198,9 @@ if("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
CHECK_C_COMPILER_FLAG(-Wno-deprecated-declarations Wno-deprecated-declarations)
if(Wno-deprecated-declarations)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-deprecated-declarations")
endif()
CHECK_CXX_COMPILER_FLAG(-Wno-deprecated-declarations Wno-deprecated-declarationsCXX)
if(Wno-deprecated-declarationsCXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations")
endif()
endif()

View File

@ -280,7 +280,6 @@ static BOOL audin_server_recv_data(audin_server* audin, wStream* s, UINT32 lengt
static void* audin_server_thread_func(void* arg)
{
void* fd;
wStream* s;
void* buffer;
DWORD nCount;
@ -326,6 +325,8 @@ static void* audin_server_thread_func(void* arg)
}
s = Stream_New(NULL, 4096);
if (!s)
goto out;
if (ready)
{
@ -393,6 +394,8 @@ static void* audin_server_thread_func(void* arg)
}
Stream_Free(s, TRUE);
out:
WTSVirtualChannelClose(audin->audin_channel);
audin->audin_channel = NULL;
@ -463,7 +466,7 @@ audin_server_context* audin_server_context_new(HANDLE vcm)
{
audin_server* audin;
audin = (audin_server*) calloc(1, sizeof(audin_server));
audin = (audin_server *)calloc(1, sizeof(audin_server));
audin->context.vcm = vcm;
audin->context.selected_client_format = -1;

View File

@ -1,563 +0,0 @@
/**
* FreeRDP: A Remote Desktop Protocol Implementation
* Server Audio Virtual Channel
*
* Copyright 2012 Vic Lee
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <winpr/crt.h>
#include <winpr/print.h>
#include <winpr/synch.h>
#include <winpr/thread.h>
#include <winpr/stream.h>
#include <freerdp/codec/dsp.h>
#include <freerdp/channels/wtsvc.h>
#include <freerdp/server/rdpsnd.h>
typedef struct _rdpsnd_server
{
rdpsnd_server_context context;
HANDLE thread;
HANDLE StopEvent;
void* rdpsnd_channel;
wStream* rdpsnd_pdu;
FREERDP_DSP_CONTEXT* dsp_context;
BYTE* out_buffer;
int out_buffer_size;
int out_frames;
int out_pending_frames;
UINT32 src_bytes_per_sample;
UINT32 src_bytes_per_frame;
} rdpsnd_server;
static BOOL rdpsnd_server_send_formats(rdpsnd_server* rdpsnd, wStream* s)
{
int pos;
UINT16 i;
BOOL status;
Stream_Write_UINT8(s, SNDC_FORMATS);
Stream_Write_UINT8(s, 0);
Stream_Seek_UINT16(s);
Stream_Write_UINT32(s, 0); /* dwFlags */
Stream_Write_UINT32(s, 0); /* dwVolume */
Stream_Write_UINT32(s, 0); /* dwPitch */
Stream_Write_UINT16(s, 0); /* wDGramPort */
Stream_Write_UINT16(s, rdpsnd->context.num_server_formats); /* wNumberOfFormats */
Stream_Write_UINT8(s, rdpsnd->context.block_no); /* cLastBlockConfirmed */
Stream_Write_UINT16(s, 0x06); /* wVersion */
Stream_Write_UINT8(s, 0); /* bPad */
for (i = 0; i < rdpsnd->context.num_server_formats; i++)
{
Stream_Write_UINT16(s, rdpsnd->context.server_formats[i].wFormatTag); /* wFormatTag (WAVE_FORMAT_PCM) */
Stream_Write_UINT16(s, rdpsnd->context.server_formats[i].nChannels); /* nChannels */
Stream_Write_UINT32(s, rdpsnd->context.server_formats[i].nSamplesPerSec); /* nSamplesPerSec */
Stream_Write_UINT32(s, rdpsnd->context.server_formats[i].nSamplesPerSec *
rdpsnd->context.server_formats[i].nChannels *
rdpsnd->context.server_formats[i].wBitsPerSample / 8); /* nAvgBytesPerSec */
Stream_Write_UINT16(s, rdpsnd->context.server_formats[i].nBlockAlign); /* nBlockAlign */
Stream_Write_UINT16(s, rdpsnd->context.server_formats[i].wBitsPerSample); /* wBitsPerSample */
Stream_Write_UINT16(s, rdpsnd->context.server_formats[i].cbSize); /* cbSize */
if (rdpsnd->context.server_formats[i].cbSize > 0)
{
Stream_Write(s, rdpsnd->context.server_formats[i].data, rdpsnd->context.server_formats[i].cbSize);
}
}
pos = Stream_GetPosition(s);
Stream_SetPosition(s, 2);
Stream_Write_UINT16(s, pos - 4);
Stream_SetPosition(s, pos);
status = WTSVirtualChannelWrite(rdpsnd->rdpsnd_channel, Stream_Buffer(s), Stream_GetPosition(s), NULL);
Stream_SetPosition(s, 0);
return status;
}
static void rdpsnd_server_recv_waveconfirm(rdpsnd_server* rdpsnd, wStream* s)
{
//unhandled for now
UINT16 timestamp = 0;
BYTE confirmBlockNum = 0;
Stream_Read_UINT16(s, timestamp);
Stream_Read_UINT8(s, confirmBlockNum);
Stream_Seek_UINT8(s); // padding
}
static void rdpsnd_server_recv_quality_mode(rdpsnd_server* rdpsnd, wStream* s)
{
//unhandled for now
UINT16 quality;
Stream_Read_UINT16(s, quality);
Stream_Seek_UINT16(s); // reserved
fprintf(stderr, "Client requested sound quality: %#0X\n", quality);
}
static BOOL rdpsnd_server_recv_formats(rdpsnd_server* rdpsnd, wStream* s)
{
int i, num_known_format = 0;
UINT32 flags, vol, pitch;
UINT16 udpPort, version;
BYTE lastblock;
Stream_Read_UINT32(s, flags); /* dwFlags */
Stream_Read_UINT32(s, vol); /* dwVolume */
Stream_Read_UINT32(s, pitch); /* dwPitch */
Stream_Read_UINT16(s, udpPort); /* wDGramPort */
Stream_Read_UINT16(s, rdpsnd->context.num_client_formats); /* wNumberOfFormats */
Stream_Read_UINT8(s, lastblock); /* cLastBlockConfirmed */
Stream_Read_UINT16(s, version); /* wVersion */
Stream_Seek_UINT8(s); /* bPad */
if (rdpsnd->context.num_client_formats > 0)
{
rdpsnd->context.client_formats = (AUDIO_FORMAT*) malloc(rdpsnd->context.num_client_formats * sizeof(AUDIO_FORMAT));
ZeroMemory(rdpsnd->context.client_formats, sizeof(AUDIO_FORMAT));
for (i = 0; i < rdpsnd->context.num_client_formats; i++)
{
Stream_Read_UINT16(s, rdpsnd->context.client_formats[i].wFormatTag);
Stream_Read_UINT16(s, rdpsnd->context.client_formats[i].nChannels);
Stream_Read_UINT32(s, rdpsnd->context.client_formats[i].nSamplesPerSec);
Stream_Read_UINT32(s, rdpsnd->context.client_formats[i].nAvgBytesPerSec);
Stream_Read_UINT16(s, rdpsnd->context.client_formats[i].nBlockAlign);
Stream_Read_UINT16(s, rdpsnd->context.client_formats[i].wBitsPerSample);
Stream_Read_UINT16(s, rdpsnd->context.client_formats[i].cbSize);
if (rdpsnd->context.client_formats[i].cbSize > 0)
{
Stream_Seek(s, rdpsnd->context.client_formats[i].cbSize);
}
if (rdpsnd->context.client_formats[i].wFormatTag != 0)
{
//lets call this a known format
//TODO: actually look through our own list of known formats
num_known_format++;
}
}
}
if (num_known_format == 0)
{
fprintf(stderr, "Client doesnt support any known formats!\n");
return FALSE;
}
return TRUE;
}
static void* rdpsnd_server_thread_func(void* arg)
{
void* fd;
wStream* s;
void* buffer;
DWORD status;
BYTE msgType;
UINT16 BodySize;
HANDLE events[2];
UINT32 bytes_returned = 0;
rdpsnd_server* rdpsnd = (rdpsnd_server*) arg;
events[0] = rdpsnd->StopEvent;
if (WTSVirtualChannelQuery(rdpsnd->rdpsnd_channel, WTSVirtualFileHandle, &buffer, &bytes_returned) == TRUE)
{
fd = *((void**) buffer);
WTSFreeMemory(buffer);
events[1] = CreateWaitObjectEvent(NULL, TRUE, FALSE, fd);
}
s = Stream_New(NULL, 4096);
rdpsnd_server_send_formats(rdpsnd, s);
while (1)
{
status = WaitForMultipleObjects(2, events, FALSE, INFINITE);
if (WaitForSingleObject(rdpsnd->StopEvent, 0) == WAIT_OBJECT_0)
{
break;
}
Stream_SetPosition(s, 0);
if (WTSVirtualChannelRead(rdpsnd->rdpsnd_channel, 0, Stream_Buffer(s),
Stream_Capacity(s), &bytes_returned) == FALSE)
{
if (bytes_returned == 0)
break;
Stream_EnsureRemainingCapacity(s, (int) bytes_returned);
if (WTSVirtualChannelRead(rdpsnd->rdpsnd_channel, 0, Stream_Buffer(s),
Stream_Capacity(s), &bytes_returned) == FALSE)
break;
}
Stream_Read_UINT8(s, msgType);
Stream_Seek_UINT8(s); /* bPad */
Stream_Read_UINT16(s, BodySize);
switch (msgType)
{
case SNDC_WAVECONFIRM:
rdpsnd_server_recv_waveconfirm(rdpsnd, s);
break;
case SNDC_QUALITYMODE:
rdpsnd_server_recv_quality_mode(rdpsnd, s);
break;
case SNDC_FORMATS:
if (rdpsnd_server_recv_formats(rdpsnd, s))
{
IFCALL(rdpsnd->context.Activated, &rdpsnd->context);
}
break;
default:
fprintf(stderr, "UNKOWN MESSAGE TYPE!! (%#0X)\n\n", msgType);
break;
}
}
Stream_Free(s, TRUE);
return NULL;
}
static BOOL rdpsnd_server_initialize(rdpsnd_server_context* context)
{
rdpsnd_server* rdpsnd = (rdpsnd_server*) context;
rdpsnd->rdpsnd_channel = WTSVirtualChannelOpenEx(context->vcm, "rdpsnd", 0);
if (rdpsnd->rdpsnd_channel != NULL)
{
rdpsnd->rdpsnd_pdu = Stream_New(NULL, 4096);
rdpsnd->StopEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
rdpsnd->thread = CreateThread(NULL, 0,
(LPTHREAD_START_ROUTINE) rdpsnd_server_thread_func, (void*) rdpsnd, 0, NULL);
return TRUE;
}
else
{
return FALSE;
}
}
static void rdpsnd_server_select_format(rdpsnd_server_context* context, int client_format_index)
{
int bs;
int out_buffer_size;
AUDIO_FORMAT *format;
rdpsnd_server* rdpsnd = (rdpsnd_server*) context;
if (client_format_index < 0 || client_format_index >= context->num_client_formats)
{
fprintf(stderr, "rdpsnd_server_select_format: index %d is not correct.\n", client_format_index);
return;
}
rdpsnd->src_bytes_per_sample = context->src_format.wBitsPerSample / 8;
rdpsnd->src_bytes_per_frame = rdpsnd->src_bytes_per_sample * context->src_format.nChannels;
context->selected_client_format = client_format_index;
format = &context->client_formats[client_format_index];
if (format->nSamplesPerSec == 0)
{
fprintf(stderr, "Invalid Client Sound Format!!\n\n");
return;
}
if (format->wFormatTag == WAVE_FORMAT_DVI_ADPCM)
{
bs = (format->nBlockAlign - 4 * format->nChannels) * 4;
rdpsnd->out_frames = (format->nBlockAlign * 4 * format->nChannels * 2 / bs + 1) * bs / (format->nChannels * 2);
}
else if (format->wFormatTag == WAVE_FORMAT_ADPCM)
{
bs = (format->nBlockAlign - 7 * format->nChannels) * 2 / format->nChannels + 2;
rdpsnd->out_frames = bs * 4;
}
else
{
rdpsnd->out_frames = 0x4000 / rdpsnd->src_bytes_per_frame;
}
if (format->nSamplesPerSec != context->src_format.nSamplesPerSec)
{
rdpsnd->out_frames = (rdpsnd->out_frames * context->src_format.nSamplesPerSec + format->nSamplesPerSec - 100) / format->nSamplesPerSec;
}
rdpsnd->out_pending_frames = 0;
out_buffer_size = rdpsnd->out_frames * rdpsnd->src_bytes_per_frame;
if (rdpsnd->out_buffer_size < out_buffer_size)
{
rdpsnd->out_buffer = (BYTE*) realloc(rdpsnd->out_buffer, out_buffer_size);
rdpsnd->out_buffer_size = out_buffer_size;
}
freerdp_dsp_context_reset_adpcm(rdpsnd->dsp_context);
}
static BOOL rdpsnd_server_send_audio_pdu(rdpsnd_server* rdpsnd)
{
int size;
BYTE* src;
int frames;
int fill_size;
BOOL status;
AUDIO_FORMAT* format;
int tbytes_per_frame;
wStream* s = rdpsnd->rdpsnd_pdu;
format = &rdpsnd->context.client_formats[rdpsnd->context.selected_client_format];
tbytes_per_frame = format->nChannels * rdpsnd->src_bytes_per_sample;
if ((format->nSamplesPerSec == rdpsnd->context.src_format.nSamplesPerSec) &&
(format->nChannels == rdpsnd->context.src_format.nChannels))
{
src = rdpsnd->out_buffer;
frames = rdpsnd->out_pending_frames;
}
else
{
rdpsnd->dsp_context->resample(rdpsnd->dsp_context, rdpsnd->out_buffer, rdpsnd->src_bytes_per_sample,
rdpsnd->context.src_format.nChannels, rdpsnd->context.src_format.nSamplesPerSec, rdpsnd->out_pending_frames,
format->nChannels, format->nSamplesPerSec);
frames = rdpsnd->dsp_context->resampled_frames;
src = rdpsnd->dsp_context->resampled_buffer;
}
size = frames * tbytes_per_frame;
if (format->wFormatTag == WAVE_FORMAT_DVI_ADPCM)
{
rdpsnd->dsp_context->encode_ima_adpcm(rdpsnd->dsp_context,
src, size, format->nChannels, format->nBlockAlign);
src = rdpsnd->dsp_context->adpcm_buffer;
size = rdpsnd->dsp_context->adpcm_size;
}
else if (format->wFormatTag == WAVE_FORMAT_ADPCM)
{
rdpsnd->dsp_context->encode_ms_adpcm(rdpsnd->dsp_context,
src, size, format->nChannels, format->nBlockAlign);
src = rdpsnd->dsp_context->adpcm_buffer;
size = rdpsnd->dsp_context->adpcm_size;
}
rdpsnd->context.block_no = (rdpsnd->context.block_no + 1) % 256;
/* Fill to nBlockAlign for the last audio packet */
fill_size = 0;
if ((format->wFormatTag == WAVE_FORMAT_DVI_ADPCM || format->wFormatTag == WAVE_FORMAT_ADPCM) &&
(rdpsnd->out_pending_frames < rdpsnd->out_frames) && ((size % format->nBlockAlign) != 0))
{
fill_size = format->nBlockAlign - (size % format->nBlockAlign);
}
/* WaveInfo PDU */
Stream_SetPosition(s, 0);
Stream_Write_UINT8(s, SNDC_WAVE); /* msgType */
Stream_Write_UINT8(s, 0); /* bPad */
Stream_Write_UINT16(s, size + fill_size + 8); /* BodySize */
Stream_Write_UINT16(s, 0); /* wTimeStamp */
Stream_Write_UINT16(s, rdpsnd->context.selected_client_format); /* wFormatNo */
Stream_Write_UINT8(s, rdpsnd->context.block_no); /* cBlockNo */
Stream_Seek(s, 3); /* bPad */
Stream_Write(s, src, 4);
WTSVirtualChannelWrite(rdpsnd->rdpsnd_channel, Stream_Buffer(s), Stream_GetPosition(s), NULL);
Stream_SetPosition(s, 0);
/* Wave PDU */
Stream_EnsureRemainingCapacity(s, size + fill_size);
Stream_Write_UINT32(s, 0); /* bPad */
Stream_Write(s, src + 4, size - 4);
if (fill_size > 0)
Stream_Zero(s, fill_size);
status = WTSVirtualChannelWrite(rdpsnd->rdpsnd_channel, Stream_Buffer(s), Stream_GetPosition(s), NULL);
Stream_SetPosition(s, 0);
rdpsnd->out_pending_frames = 0;
return status;
}
static BOOL rdpsnd_server_send_samples(rdpsnd_server_context* context, const void* buf, int nframes)
{
int cframes;
int cframesize;
rdpsnd_server* rdpsnd = (rdpsnd_server*) context;
if (rdpsnd->context.selected_client_format < 0)
return FALSE;
while (nframes > 0)
{
cframes = MIN(nframes, rdpsnd->out_frames - rdpsnd->out_pending_frames);
cframesize = cframes * rdpsnd->src_bytes_per_frame;
CopyMemory(rdpsnd->out_buffer + (rdpsnd->out_pending_frames * rdpsnd->src_bytes_per_frame), buf, cframesize);
buf = (BYTE*) buf + cframesize;
nframes -= cframes;
rdpsnd->out_pending_frames += cframes;
if (rdpsnd->out_pending_frames >= rdpsnd->out_frames)
{
if (!rdpsnd_server_send_audio_pdu(rdpsnd))
return FALSE;
}
}
return TRUE;
}
static BOOL rdpsnd_server_set_volume(rdpsnd_server_context* context, int left, int right)
{
int pos;
BOOL status;
rdpsnd_server* rdpsnd = (rdpsnd_server*) context;
wStream* s = rdpsnd->rdpsnd_pdu;
Stream_Write_UINT8(s, SNDC_SETVOLUME);
Stream_Write_UINT8(s, 0);
Stream_Seek_UINT16(s);
Stream_Write_UINT16(s, left);
Stream_Write_UINT16(s, right);
pos = Stream_GetPosition(s);
Stream_SetPosition(s, 2);
Stream_Write_UINT16(s, pos - 4);
Stream_SetPosition(s, pos);
status = WTSVirtualChannelWrite(rdpsnd->rdpsnd_channel, Stream_Buffer(s), Stream_GetPosition(s), NULL);
Stream_SetPosition(s, 0);
return status;
}
static BOOL rdpsnd_server_close(rdpsnd_server_context* context)
{
int pos;
BOOL status;
rdpsnd_server* rdpsnd = (rdpsnd_server*) context;
wStream* s = rdpsnd->rdpsnd_pdu;
if (rdpsnd->context.selected_client_format < 0)
return FALSE;
if (rdpsnd->out_pending_frames > 0)
{
if (!rdpsnd_server_send_audio_pdu(rdpsnd))
return FALSE;
}
rdpsnd->context.selected_client_format = -1;
Stream_Write_UINT8(s, SNDC_CLOSE);
Stream_Write_UINT8(s, 0);
Stream_Seek_UINT16(s);
pos = Stream_GetPosition(s);
Stream_SetPosition(s, 2);
Stream_Write_UINT16(s, pos - 4);
Stream_SetPosition(s, pos);
status = WTSVirtualChannelWrite(rdpsnd->rdpsnd_channel, Stream_Buffer(s), Stream_GetPosition(s), NULL);
Stream_SetPosition(s, 0);
return status;
}
rdpsnd_server_context* rdpsnd_server_context_new(WTSVirtualChannelManager* vcm)
{
rdpsnd_server* rdpsnd;
rdpsnd = (rdpsnd_server*) malloc(sizeof(rdpsnd_server));
ZeroMemory(rdpsnd, sizeof(rdpsnd_server));
rdpsnd->context.vcm = vcm;
rdpsnd->context.selected_client_format = -1;
rdpsnd->context.Initialize = rdpsnd_server_initialize;
rdpsnd->context.SelectFormat = rdpsnd_server_select_format;
rdpsnd->context.SendSamples = rdpsnd_server_send_samples;
rdpsnd->context.SetVolume = rdpsnd_server_set_volume;
rdpsnd->context.Close = rdpsnd_server_close;
rdpsnd->dsp_context = freerdp_dsp_context_new();
return (rdpsnd_server_context*) rdpsnd;
}
void rdpsnd_server_context_free(rdpsnd_server_context* context)
{
rdpsnd_server* rdpsnd = (rdpsnd_server*) context;
SetEvent(rdpsnd->StopEvent);
WaitForSingleObject(rdpsnd->thread, INFINITE);
CloseHandle(rdpsnd->StopEvent);
CloseHandle(rdpsnd->thread);
if (rdpsnd->rdpsnd_channel)
WTSVirtualChannelClose(rdpsnd->rdpsnd_channel);
if (rdpsnd->rdpsnd_pdu)
Stream_Free(rdpsnd->rdpsnd_pdu, TRUE);
if (rdpsnd->out_buffer)
free(rdpsnd->out_buffer);
if (rdpsnd->dsp_context)
freerdp_dsp_context_free(rdpsnd->dsp_context);
if (rdpsnd->context.client_formats)
free(rdpsnd->context.client_formats);
free(rdpsnd);
}

View File

@ -80,23 +80,32 @@ static BOOL rdpsnd_server_send_formats(RdpsndServerContext* context, wStream* s)
return status;
}
static void rdpsnd_server_recv_waveconfirm(RdpsndServerContext* context, wStream* s)
static BOOL rdpsnd_server_recv_waveconfirm(RdpsndServerContext* context, wStream* s)
{
UINT16 timestamp = 0;
BYTE confirmBlockNum = 0;
if (Stream_GetRemainingLength(s) < 4)
return FALSE;
Stream_Read_UINT16(s, timestamp);
Stream_Read_UINT8(s, confirmBlockNum);
Stream_Seek_UINT8(s);
return TRUE;
}
static void rdpsnd_server_recv_quality_mode(RdpsndServerContext* context, wStream* s)
static BOOL rdpsnd_server_recv_quality_mode(RdpsndServerContext* context, wStream* s)
{
UINT16 quality;
if (Stream_GetRemainingLength(s) < 4)
return FALSE;
Stream_Read_UINT16(s, quality);
Stream_Seek_UINT16(s); // reserved
fprintf(stderr, "Client requested sound quality: %#0X\n", quality);
return TRUE;
}
static BOOL rdpsnd_server_recv_formats(RdpsndServerContext* context, wStream* s)
@ -106,6 +115,9 @@ static BOOL rdpsnd_server_recv_formats(RdpsndServerContext* context, wStream* s)
UINT16 udpPort, version;
BYTE lastblock;
if (Stream_GetRemainingLength(s) < 20)
return FALSE;
Stream_Read_UINT32(s, flags); /* dwFlags */
Stream_Read_UINT32(s, vol); /* dwVolume */
Stream_Read_UINT32(s, pitch); /* dwPitch */
@ -115,42 +127,58 @@ static BOOL rdpsnd_server_recv_formats(RdpsndServerContext* context, wStream* s)
Stream_Read_UINT16(s, version); /* wVersion */
Stream_Seek_UINT8(s); /* bPad */
if (context->num_client_formats > 0)
{
context->client_formats = (AUDIO_FORMAT*) malloc(context->num_client_formats * sizeof(AUDIO_FORMAT));
ZeroMemory(context->client_formats, sizeof(AUDIO_FORMAT));
/* this check is only a guess as cbSize can influence the size of a format record */
if (Stream_GetRemainingLength(s) < context->num_client_formats * 18)
return FALSE;
for (i = 0; i < context->num_client_formats; i++)
{
Stream_Read_UINT16(s, context->client_formats[i].wFormatTag);
Stream_Read_UINT16(s, context->client_formats[i].nChannels);
Stream_Read_UINT32(s, context->client_formats[i].nSamplesPerSec);
Stream_Read_UINT32(s, context->client_formats[i].nAvgBytesPerSec);
Stream_Read_UINT16(s, context->client_formats[i].nBlockAlign);
Stream_Read_UINT16(s, context->client_formats[i].wBitsPerSample);
Stream_Read_UINT16(s, context->client_formats[i].cbSize);
if (context->client_formats[i].cbSize > 0)
{
Stream_Seek(s, context->client_formats[i].cbSize);
}
if (context->client_formats[i].wFormatTag != 0)
{
//lets call this a known format
//TODO: actually look through our own list of known formats
num_known_format++;
}
}
}
if (num_known_format == 0)
if (!context->num_client_formats)
{
fprintf(stderr, "Client doesn't support any known formats!\n");
fprintf(stderr, "%s: client doesn't support any format!\n", __FUNCTION__);
return FALSE;
}
context->client_formats = (AUDIO_FORMAT *)calloc(context->num_client_formats, sizeof(AUDIO_FORMAT));
if (!context->client_formats)
return FALSE;
for (i = 0; i < context->num_client_formats; i++)
{
if (Stream_GetRemainingLength(s) < 18)
goto out_free;
Stream_Read_UINT16(s, context->client_formats[i].wFormatTag);
Stream_Read_UINT16(s, context->client_formats[i].nChannels);
Stream_Read_UINT32(s, context->client_formats[i].nSamplesPerSec);
Stream_Read_UINT32(s, context->client_formats[i].nAvgBytesPerSec);
Stream_Read_UINT16(s, context->client_formats[i].nBlockAlign);
Stream_Read_UINT16(s, context->client_formats[i].wBitsPerSample);
Stream_Read_UINT16(s, context->client_formats[i].cbSize);
if (context->client_formats[i].cbSize > 0)
{
if (!Stream_SafeSeek(s, context->client_formats[i].cbSize))
goto out_free;
}
if (context->client_formats[i].wFormatTag != 0)
{
//lets call this a known format
//TODO: actually look through our own list of known formats
num_known_format++;
}
}
if (!context->num_client_formats)
{
fprintf(stderr, "%s: client doesn't support any known format!\n", __FUNCTION__);
goto out_free;
}
return TRUE;
out_free:
free(context->client_formats);
return FALSE;
}
static void* rdpsnd_server_thread(void* arg)
@ -165,16 +193,19 @@ static void* rdpsnd_server_thread(void* arg)
HANDLE ChannelEvent;
DWORD BytesReturned;
RdpsndServerContext* context;
BOOL doRun;
context = (RdpsndServerContext*) arg;
context = (RdpsndServerContext *)arg;
buffer = NULL;
BytesReturned = 0;
ChannelEvent = NULL;
ChannelEvent = context->priv->ChannelHandle;
s = Stream_New(NULL, 4096);
if (!s)
return NULL;
if (WTSVirtualChannelQuery(context->priv->ChannelHandle, WTSVirtualEventHandle, &buffer, &BytesReturned) == TRUE)
if (WTSVirtualChannelQuery(ChannelEvent, WTSVirtualEventHandle, &buffer, &BytesReturned))
{
if (BytesReturned == sizeof(HANDLE))
CopyMemory(&ChannelEvent, buffer, sizeof(HANDLE));
@ -186,74 +217,77 @@ static void* rdpsnd_server_thread(void* arg)
events[nCount++] = ChannelEvent;
events[nCount++] = context->priv->StopEvent;
s = Stream_New(NULL, 4096);
rdpsnd_server_send_formats(context, s);
if (!rdpsnd_server_send_formats(context, s))
goto out;
while (1)
doRun = TRUE;
while (doRun)
{
status = WaitForMultipleObjects(nCount, events, FALSE, INFINITE);
if (WaitForSingleObject(context->priv->StopEvent, 0) == WAIT_OBJECT_0)
{
break;
}
Stream_SetPosition(s, 0);
if (WTSVirtualChannelRead(context->priv->ChannelHandle, 0,
(PCHAR) Stream_Buffer(s), Stream_Capacity(s), &BytesReturned) == FALSE)
if (!WTSVirtualChannelRead(ChannelEvent, 0, (PCHAR)Stream_Buffer(s),
Stream_Capacity(s), &BytesReturned))
{
if (!BytesReturned)
break;
Stream_EnsureRemainingCapacity(s, BytesReturned);
if (WTSVirtualChannelRead(context->priv->ChannelHandle, 0,
(PCHAR) Stream_Buffer(s), Stream_Capacity(s), &BytesReturned) == FALSE)
{
if (!WTSVirtualChannelRead(ChannelEvent, 0, (PCHAR)Stream_Buffer(s),
Stream_Capacity(s), &BytesReturned))
break;
}
}
if (Stream_GetRemainingLength(s) < 4)
break;
Stream_Read_UINT8(s, msgType);
Stream_Seek_UINT8(s); /* bPad */
Stream_Read_UINT16(s, BodySize);
if (Stream_GetRemainingLength(s) < BodySize)
break;
switch (msgType)
{
case SNDC_WAVECONFIRM:
rdpsnd_server_recv_waveconfirm(context, s);
doRun = rdpsnd_server_recv_waveconfirm(context, s);
break;
case SNDC_QUALITYMODE:
rdpsnd_server_recv_quality_mode(context, s);
doRun = rdpsnd_server_recv_quality_mode(context, s);
break;
case SNDC_FORMATS:
if (rdpsnd_server_recv_formats(context, s))
doRun = rdpsnd_server_recv_formats(context, s);
if (doRun)
{
IFCALL(context->Activated, context);
}
break;
default:
fprintf(stderr, "UNKOWN MESSAGE TYPE!! (%#0X)\n\n", msgType);
fprintf(stderr, "%s: UNKOWN MESSAGE TYPE!! (%#0X)\n\n", __FUNCTION__, msgType);
break;
}
}
out:
Stream_Free(s, TRUE);
return NULL;
}
static BOOL rdpsnd_server_initialize(RdpsndServerContext* context)
{
context->Start(context);
return TRUE;
return context->Start(context) >= 0;
}
static void rdpsnd_server_select_format(RdpsndServerContext* context, int client_format_index)
static BOOL rdpsnd_server_select_format(RdpsndServerContext* context, int client_format_index)
{
int bs;
int out_buffer_size;
@ -261,8 +295,8 @@ static void rdpsnd_server_select_format(RdpsndServerContext* context, int client
if (client_format_index < 0 || client_format_index >= context->num_client_formats)
{
fprintf(stderr, "rdpsnd_server_select_format: index %d is not correct.\n", client_format_index);
return;
fprintf(stderr, "%s: index %d is not correct.\n", __FUNCTION__, client_format_index);
return FALSE;
}
context->priv->src_bytes_per_sample = context->src_format.wBitsPerSample / 8;
@ -273,23 +307,24 @@ static void rdpsnd_server_select_format(RdpsndServerContext* context, int client
if (format->nSamplesPerSec == 0)
{
fprintf(stderr, "Invalid Client Sound Format!!\n\n");
return;
fprintf(stderr, "%s: invalid Client Sound Format!!\n", __FUNCTION__);
return FALSE;
}
if (format->wFormatTag == WAVE_FORMAT_DVI_ADPCM)
switch(format->wFormatTag)
{
bs = (format->nBlockAlign - 4 * format->nChannels) * 4;
context->priv->out_frames = (format->nBlockAlign * 4 * format->nChannels * 2 / bs + 1) * bs / (format->nChannels * 2);
}
else if (format->wFormatTag == WAVE_FORMAT_ADPCM)
{
bs = (format->nBlockAlign - 7 * format->nChannels) * 2 / format->nChannels + 2;
context->priv->out_frames = bs * 4;
}
else
{
context->priv->out_frames = 0x4000 / context->priv->src_bytes_per_frame;
case WAVE_FORMAT_DVI_ADPCM:
bs = (format->nBlockAlign - 4 * format->nChannels) * 4;
context->priv->out_frames = (format->nBlockAlign * 4 * format->nChannels * 2 / bs + 1) * bs / (format->nChannels * 2);
break;
case WAVE_FORMAT_ADPCM:
bs = (format->nBlockAlign - 7 * format->nChannels) * 2 / format->nChannels + 2;
context->priv->out_frames = bs * 4;
break;
default:
context->priv->out_frames = 0x4000 / context->priv->src_bytes_per_frame;
break;
}
if (format->nSamplesPerSec != context->src_format.nSamplesPerSec)
@ -302,11 +337,18 @@ static void rdpsnd_server_select_format(RdpsndServerContext* context, int client
if (context->priv->out_buffer_size < out_buffer_size)
{
context->priv->out_buffer = (BYTE*) realloc(context->priv->out_buffer, out_buffer_size);
BYTE *newBuffer;
newBuffer = (BYTE *)realloc(context->priv->out_buffer, out_buffer_size);
if (!newBuffer)
return FALSE;
context->priv->out_buffer = newBuffer;
context->priv->out_buffer_size = out_buffer_size;
}
freerdp_dsp_context_reset_adpcm(context->priv->dsp_context);
return TRUE;
}
static BOOL rdpsnd_server_send_audio_pdu(RdpsndServerContext* context)
@ -379,7 +421,9 @@ static BOOL rdpsnd_server_send_audio_pdu(RdpsndServerContext* context)
Stream_Seek(s, 3); /* bPad */
Stream_Write(s, src, 4);
WTSVirtualChannelWrite(context->priv->ChannelHandle, (PCHAR) Stream_Buffer(s), Stream_GetPosition(s), NULL);
status = WTSVirtualChannelWrite(context->priv->ChannelHandle, (PCHAR) Stream_Buffer(s), Stream_GetPosition(s), NULL);
if (!status)
goto out;
Stream_SetPosition(s, 0);
/* Wave PDU */
@ -391,10 +435,10 @@ static BOOL rdpsnd_server_send_audio_pdu(RdpsndServerContext* context)
Stream_Zero(s, fill_size);
status = WTSVirtualChannelWrite(context->priv->ChannelHandle, (PCHAR) Stream_Buffer(s), Stream_GetPosition(s), NULL);
out:
Stream_SetPosition(s, 0);
context->priv->out_pending_frames = 0;
return status;
}
@ -484,26 +528,45 @@ static BOOL rdpsnd_server_close(RdpsndServerContext* context)
static int rdpsnd_server_start(RdpsndServerContext* context)
{
context->priv->ChannelHandle = WTSVirtualChannelOpen(context->vcm, WTS_CURRENT_SESSION, "rdpsnd");
if (!context->priv->ChannelHandle)
return -1;
context->priv->rdpsnd_pdu = Stream_New(NULL, 4096);
if (!context->priv->rdpsnd_pdu)
goto out_close;
context->priv->StopEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
if (!context->priv->StopEvent)
goto out_pdu;
context->priv->Thread = CreateThread(NULL, 0,
(LPTHREAD_START_ROUTINE) rdpsnd_server_thread, (void*) context, 0, NULL);
if (!context->priv->Thread)
goto out_stopEvent;
return 0;
out_stopEvent:
CloseHandle(context->priv->StopEvent);
context->priv->StopEvent = NULL;
out_pdu:
Stream_Free(context->priv->rdpsnd_pdu, TRUE);
context->priv->rdpsnd_pdu = NULL;
out_close:
WTSVirtualChannelClose(context->priv->ChannelHandle);
context->priv->ChannelHandle = NULL;
return -1;
}
static int rdpsnd_server_stop(RdpsndServerContext* context)
{
SetEvent(context->priv->StopEvent);
if (context->priv->StopEvent)
{
SetEvent(context->priv->StopEvent);
WaitForSingleObject(context->priv->Thread, INFINITE);
CloseHandle(context->priv->Thread);
WaitForSingleObject(context->priv->Thread, INFINITE);
CloseHandle(context->priv->Thread);
}
return 0;
}
@ -512,41 +575,46 @@ RdpsndServerContext* rdpsnd_server_context_new(HANDLE vcm)
{
RdpsndServerContext* context;
context = (RdpsndServerContext*) malloc(sizeof(RdpsndServerContext));
context = (RdpsndServerContext*) calloc(1, sizeof(RdpsndServerContext));
if (!context)
return NULL;
if (context)
{
ZeroMemory(context, sizeof(RdpsndServerContext));
context->vcm = vcm;
context->vcm = vcm;
context->Start = rdpsnd_server_start;
context->Stop = rdpsnd_server_stop;
context->Start = rdpsnd_server_start;
context->Stop = rdpsnd_server_stop;
context->selected_client_format = -1;
context->Initialize = rdpsnd_server_initialize;
context->SelectFormat = rdpsnd_server_select_format;
context->SendSamples = rdpsnd_server_send_samples;
context->SetVolume = rdpsnd_server_set_volume;
context->Close = rdpsnd_server_close;
context->selected_client_format = -1;
context->Initialize = rdpsnd_server_initialize;
context->SelectFormat = rdpsnd_server_select_format;
context->SendSamples = rdpsnd_server_send_samples;
context->SetVolume = rdpsnd_server_set_volume;
context->Close = rdpsnd_server_close;
context->priv = (RdpsndServerPrivate*) calloc(1, sizeof(RdpsndServerPrivate));
if (!context->priv)
goto out_free;
context->priv = (RdpsndServerPrivate*) malloc(sizeof(RdpsndServerPrivate));
if (context->priv)
{
ZeroMemory(context->priv, sizeof(RdpsndServerPrivate));
context->priv->dsp_context = freerdp_dsp_context_new();
}
}
context->priv->dsp_context = freerdp_dsp_context_new();
if (!context->priv->dsp_context)
goto out_free_priv;
return context;
out_free_priv:
free(context->priv);
out_free:
free(context);
return NULL;
}
void rdpsnd_server_context_free(RdpsndServerContext* context)
{
SetEvent(context->priv->StopEvent);
WaitForSingleObject(context->priv->Thread, INFINITE);
if (!context->priv->StopEvent)
{
SetEvent(context->priv->StopEvent);
WaitForSingleObject(context->priv->Thread, INFINITE);
}
if (context->priv->ChannelHandle)
WTSVirtualChannelClose(context->priv->ChannelHandle);

View File

@ -1,12 +1,11 @@
set(OPTION_DEFAULT OFF)
set(OPTION_CLIENT_DEFAULT OFF)
set(OPTION_SERVER_DEFAULT OFF)
if(WITH_SAMPLE)
set(OPTION_CLIENT_DEFAULT ON)
set(OPTION_SERVER_DEFAULT OFF)
else()
set(OPTION_CLIENT_DEFAULT OFF)
endif()
set(OPTION_SERVER_DEFAULT OFF)
define_channel_options(NAME "sample" TYPE "static"
DESCRIPTION "Sample Virtual Channel Extension"
@ -15,4 +14,3 @@ define_channel_options(NAME "sample" TYPE "static"
define_channel_client_options(${OPTION_CLIENT_DEFAULT})
define_channel_server_options(${OPTION_SERVER_DEFAULT})

View File

@ -21,7 +21,7 @@ set(${MODULE_PREFIX}_SRCS
sample_main.c
sample_main.h)
add_channel_client_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} TRUE "VirtualChannelEntry")
add_channel_client_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} FALSE "VirtualChannelEntry")
set_target_properties(${MODULE_NAME} PROPERTIES PREFIX "")

View File

@ -54,9 +54,19 @@ extern "C" {
FREERDP_API void WTSVirtualChannelManagerGetFileDescriptor(HANDLE hServer, void** fds, int* fds_count);
FREERDP_API BOOL WTSVirtualChannelManagerCheckFileDescriptor(HANDLE hServer);
FREERDP_API HANDLE WTSVirtualChannelManagerGetEventHandle(HANDLE hServer);
FREERDP_API BOOL WTSVirtualChannelManagerIsChannelJoined(HANDLE hServer, const char* name);
/**
* Extended FreeRDP WTS functions for channel handling
*/
FREERDP_API UINT16 WTSChannelGetId(freerdp_peer *client, const char *channel_name);
FREERDP_API BOOL WTSIsChannelJoinedByName(freerdp_peer *client, const char *channel_name);
FREERDP_API BOOL WTSIsChannelJoinedById(freerdp_peer *client, const UINT16 channel_id);
FREERDP_API BOOL WTSChannelSetHandleByName(freerdp_peer *client, const char *channel_name, void *handle);
FREERDP_API BOOL WTSChannelSetHandleById(freerdp_peer *client, const UINT16 channel_id, void *handle);
FREERDP_API void *WTSChannelGetHandleByName(freerdp_peer *client, const char *channel_name);
FREERDP_API void *WTSChannelGetHandleById(freerdp_peer *client, const UINT16 channel_id);
#ifdef __cplusplus
}
#endif

View File

@ -54,19 +54,19 @@ struct _FREERDP_DSP_CONTEXT
ADPCM adpcm;
void (*resample)(FREERDP_DSP_CONTEXT* context,
BOOL (*resample)(FREERDP_DSP_CONTEXT* context,
const BYTE* src, int bytes_per_sample,
UINT32 schan, UINT32 srate, int sframes,
UINT32 rchan, UINT32 rrate);
void (*decode_ima_adpcm)(FREERDP_DSP_CONTEXT* context,
BOOL (*decode_ima_adpcm)(FREERDP_DSP_CONTEXT* context,
const BYTE* src, int size, int channels, int block_size);
void (*encode_ima_adpcm)(FREERDP_DSP_CONTEXT* context,
BOOL (*encode_ima_adpcm)(FREERDP_DSP_CONTEXT* context,
const BYTE* src, int size, int channels, int block_size);
void (*decode_ms_adpcm)(FREERDP_DSP_CONTEXT* context,
BOOL (*decode_ms_adpcm)(FREERDP_DSP_CONTEXT* context,
const BYTE* src, int size, int channels, int block_size);
void (*encode_ms_adpcm)(FREERDP_DSP_CONTEXT* context,
BOOL (*encode_ms_adpcm)(FREERDP_DSP_CONTEXT* context,
const BYTE* src, int size, int channels, int block_size);
};

View File

@ -31,7 +31,7 @@ typedef int (*psRdpsndStart)(RdpsndServerContext* context);
typedef int (*psRdpsndStop)(RdpsndServerContext* context);
typedef BOOL (*psRdpsndServerInitialize)(RdpsndServerContext* context);
typedef void (*psRdpsndServerSelectFormat)(RdpsndServerContext* context, int client_format_index);
typedef BOOL (*psRdpsndServerSelectFormat)(RdpsndServerContext* context, int client_format_index);
typedef BOOL (*psRdpsndServerSendSamples)(RdpsndServerContext* context, const void* buf, int nframes);
typedef BOOL (*psRdpsndServerSetVolume)(RdpsndServerContext* context, int left, int right);
typedef BOOL (*psRdpsndServerClose)(RdpsndServerContext* context);

View File

@ -960,7 +960,7 @@ struct rdp_settings
ALIGN64 UINT32 PreconnectionId; /* 1154 */
ALIGN64 char* PreconnectionBlob; /* 1155 */
ALIGN64 BOOL SendPreconnectionPdu; /* 1156 */
UINT64 padding1216[1216 - 1057]; /* 1157 */
UINT64 padding1216[1216 - 1157]; /* 1157 */
/* Server Redirection */
ALIGN64 UINT32 RedirectionFlags; /* 1216 */
@ -1029,7 +1029,7 @@ struct rdp_settings
ALIGN64 int XPan; /* 1552 */
ALIGN64 int YPan; /* 1553 */
ALIGN64 double ScalingFactor; /* 1554 */
UINT64 padding1600[1600 - 1555]; /* 1555 */
UINT64 padding1601[1601 - 1555]; /* 1555 */
/* Miscellaneous */
ALIGN64 BOOL SoftwareGdi; /* 1601 */
@ -1040,7 +1040,7 @@ struct rdp_settings
/* Names */
ALIGN64 char* ComputerName; /* 1664 */
UINT64 padding1728[1728 - 1605]; /* 1665 */
UINT64 padding1728[1728 - 1665]; /* 1665 */
/* Files */
ALIGN64 char* ConnectionFile; /* 1728 */
@ -1097,7 +1097,7 @@ struct rdp_settings
ALIGN64 UINT32 RemoteAppNumIconCacheEntries; /* 2123 */
ALIGN64 BOOL RemoteAppLanguageBarSupported; /* 2124 */
UINT64 padding2176[2176 - 2125]; /* 2125 */
UINT64 padding2240[2240 - 2124]; /* 2176 */
UINT64 padding2240[2240 - 2176]; /* 2176 */
/**
* Mandatory Capabilities
@ -1131,7 +1131,7 @@ struct rdp_settings
ALIGN64 BYTE* OrderSupport; /* 2432 */
ALIGN64 BOOL BitmapCacheV3Enabled; /* 2433 */
ALIGN64 BOOL AltSecFrameMarkerSupport; /* 2434 */
UINT64 padding2496[2496 - 2435]; /* 2435 */
UINT64 padding2497[2497 - 2435]; /* 2435 */
/* Bitmap Cache Capabilities */
ALIGN64 BOOL BitmapCacheEnabled; /* 2497 */
@ -1199,7 +1199,7 @@ struct rdp_settings
UINT64 padding3264[3264 - 3200]; /* 3200 */
/* Font Capabilities */
UINT64 padding3328[3328 - 3200]; /* 3264 */
UINT64 padding3328[3328 - 3264]; /* 3264 */
/* Multifragment Update Capabilities */
ALIGN64 UINT32 MultifragMaxRequestSize; /* 3328 */
@ -1244,7 +1244,7 @@ struct rdp_settings
ALIGN64 UINT32 JpegCodecId; /* 3777 */
ALIGN64 UINT32 JpegQuality; /* 3778 */
UINT64 padding3840[3840 - 3779]; /* 3779 */
UINT64 padding3904[3904 - 3779]; /* 3840 */
UINT64 padding3904[3904 - 3840]; /* 3840 */
/**
* Caches

View File

@ -36,7 +36,7 @@
* http://download.microsoft.com/download/9/8/6/9863C72A-A3AA-4DDB-B1BA-CA8D17EFD2D4/RIFFNEW.pdf
*/
static void freerdp_dsp_resample(FREERDP_DSP_CONTEXT* context,
static BOOL freerdp_dsp_resample(FREERDP_DSP_CONTEXT* context,
const BYTE* src, int bytes_per_sample,
UINT32 schan, UINT32 srate, int sframes,
UINT32 rchan, UINT32 rrate)
@ -56,8 +56,12 @@ static void freerdp_dsp_resample(FREERDP_DSP_CONTEXT* context,
if (rsize > (int) context->resampled_maxlength)
{
BYTE *newBuffer = (BYTE*) realloc(context->resampled_buffer, rsize + 1024);
if (!newBuffer)
return FALSE;
context->resampled_maxlength = rsize + 1024;
context->resampled_buffer = (BYTE*) realloc(context->resampled_buffer, context->resampled_maxlength);
context->resampled_buffer = newBuffer;
}
dst = context->resampled_buffer;
@ -83,6 +87,7 @@ static void freerdp_dsp_resample(FREERDP_DSP_CONTEXT* context,
context->resampled_frames = rframes;
context->resampled_size = rsize;
return TRUE;
}
/**
@ -149,7 +154,7 @@ static UINT16 dsp_decode_ima_adpcm_sample(ADPCM* adpcm,
return (UINT16) d;
}
static void freerdp_dsp_decode_ima_adpcm(FREERDP_DSP_CONTEXT* context,
static BOOL freerdp_dsp_decode_ima_adpcm(FREERDP_DSP_CONTEXT* context,
const BYTE* src, int size, int channels, int block_size)
{
BYTE* dst;
@ -163,8 +168,12 @@ static void freerdp_dsp_decode_ima_adpcm(FREERDP_DSP_CONTEXT* context,
if (out_size > context->adpcm_maxlength)
{
BYTE *newBuffer = realloc(context->adpcm_buffer, out_size + 1024);
if (!newBuffer)
return FALSE;
context->adpcm_maxlength = out_size + 1024;
context->adpcm_buffer = realloc(context->adpcm_buffer, context->adpcm_maxlength);
context->adpcm_buffer = newBuffer;
}
dst = context->adpcm_buffer;
@ -228,6 +237,7 @@ static void freerdp_dsp_decode_ima_adpcm(FREERDP_DSP_CONTEXT* context,
}
context->adpcm_size = dst - context->adpcm_buffer;
return TRUE;
}
/**
@ -326,7 +336,7 @@ static BYTE dsp_encode_ima_adpcm_sample(ADPCM* adpcm, int channel, INT16 sample)
return enc;
}
static void freerdp_dsp_encode_ima_adpcm(FREERDP_DSP_CONTEXT* context,
static BOOL freerdp_dsp_encode_ima_adpcm(FREERDP_DSP_CONTEXT* context,
const BYTE* src, int size, int channels, int block_size)
{
int i;
@ -339,8 +349,12 @@ static void freerdp_dsp_encode_ima_adpcm(FREERDP_DSP_CONTEXT* context,
if (out_size > context->adpcm_maxlength)
{
BYTE *newBuffer = realloc(context->adpcm_buffer, out_size + 1024);
if (!newBuffer)
return FALSE;
context->adpcm_maxlength = out_size + 1024;
context->adpcm_buffer = realloc(context->adpcm_buffer, context->adpcm_maxlength);
context->adpcm_buffer = newBuffer;
}
dst = context->adpcm_buffer;
@ -392,6 +406,7 @@ static void freerdp_dsp_encode_ima_adpcm(FREERDP_DSP_CONTEXT* context,
}
context->adpcm_size = dst - context->adpcm_buffer;
return TRUE;
}
/**
@ -443,7 +458,7 @@ static INLINE INT16 freerdp_dsp_decode_ms_adpcm_sample(ADPCM* adpcm, BYTE sample
return (INT16) presample;
}
static void freerdp_dsp_decode_ms_adpcm(FREERDP_DSP_CONTEXT* context,
static BOOL freerdp_dsp_decode_ms_adpcm(FREERDP_DSP_CONTEXT* context,
const BYTE* src, int size, int channels, int block_size)
{
BYTE* dst;
@ -454,8 +469,12 @@ static void freerdp_dsp_decode_ms_adpcm(FREERDP_DSP_CONTEXT* context,
if (out_size > context->adpcm_maxlength)
{
BYTE *newBuffer = realloc(context->adpcm_buffer, out_size + 1024);
if (!newBuffer)
return FALSE;
context->adpcm_maxlength = out_size + 1024;
context->adpcm_buffer = realloc(context->adpcm_buffer, context->adpcm_maxlength);
context->adpcm_buffer = newBuffer;
}
dst = context->adpcm_buffer;
@ -537,6 +556,7 @@ static void freerdp_dsp_decode_ms_adpcm(FREERDP_DSP_CONTEXT* context,
}
context->adpcm_size = dst - context->adpcm_buffer;
return TRUE;
}
static BYTE freerdp_dsp_encode_ms_adpcm_sample(ADPCM* adpcm, INT32 sample, int channel)
@ -573,7 +593,7 @@ static BYTE freerdp_dsp_encode_ms_adpcm_sample(ADPCM* adpcm, INT32 sample, int c
return ((BYTE) errordelta) & 0x0F;
}
static void freerdp_dsp_encode_ms_adpcm(FREERDP_DSP_CONTEXT* context,
static BOOL freerdp_dsp_encode_ms_adpcm(FREERDP_DSP_CONTEXT* context,
const BYTE* src, int size, int channels, int block_size)
{
BYTE* dst;
@ -584,8 +604,12 @@ static void freerdp_dsp_encode_ms_adpcm(FREERDP_DSP_CONTEXT* context,
if (out_size > context->adpcm_maxlength)
{
BYTE *newBuffer = realloc(context->adpcm_buffer, out_size + 1024);
if (!newBuffer)
return FALSE;
context->adpcm_maxlength = out_size + 1024;
context->adpcm_buffer = realloc(context->adpcm_buffer, context->adpcm_maxlength);
context->adpcm_buffer = newBuffer;
}
dst = context->adpcm_buffer;
@ -646,14 +670,16 @@ static void freerdp_dsp_encode_ms_adpcm(FREERDP_DSP_CONTEXT* context,
}
context->adpcm_size = dst - context->adpcm_buffer;
return TRUE;
}
FREERDP_DSP_CONTEXT* freerdp_dsp_context_new(void)
{
FREERDP_DSP_CONTEXT* context;
context = (FREERDP_DSP_CONTEXT*) malloc(sizeof(FREERDP_DSP_CONTEXT));
ZeroMemory(context, sizeof(FREERDP_DSP_CONTEXT));
context = (FREERDP_DSP_CONTEXT*) calloc(1, sizeof(FREERDP_DSP_CONTEXT));
if (!context)
return NULL;
context->resample = freerdp_dsp_resample;
context->decode_ima_adpcm = freerdp_dsp_decode_ima_adpcm;

View File

@ -619,7 +619,20 @@ static BOOL rfx_process_message_region(RFX_CONTEXT* context, RFX_MESSAGE* messag
if (message->numRects < 1)
{
DEBUG_WARN("no rects.");
/* Unfortunately, it isn't documented.
It seems that server asks to clip whole session when numRects = 0.
Issue: https://github.com/FreeRDP/FreeRDP/issues/1738 */
DEBUG_WARN("no rects. Clip whole session.");
message->numRects = 1;
message->rects = (RFX_RECT*) realloc(message->rects, message->numRects * sizeof(RFX_RECT));
if (!message->rects)
return FALSE;
message->rects->x = 0;
message->rects->y = 0;
message->rects->width = context->width;
message->rects->height = context->height;
return TRUE;
}

View File

@ -590,8 +590,8 @@ BOOL certificate_read_server_certificate(rdpCertificate* certificate, BYTE* serv
UINT32 dwVersion;
BOOL ret;
if (length < 4)
return FALSE;
if (length < 4) /* NULL certificate is not an error see #1795 */
return TRUE;
s = Stream_New(server_cert, length);

View File

@ -261,7 +261,7 @@ BOOL rts_connect(rdpRpc* rpc)
return TRUE;
}
#ifdef WITH_DEBUG_RTS
#if defined WITH_DEBUG_RTS && 0
static const char* const RTS_CMD_STRINGS[] =
{

View File

@ -203,6 +203,7 @@ static INLINE BOOL update_write_coord(wStream* s, INT32 coord)
return TRUE;
}
#if 0
static INLINE BOOL update_write_coord_delta(wStream* s, INT32 prevCoord, INT32 nextCoord)
{
INT8 lsi8;
@ -212,6 +213,7 @@ static INLINE BOOL update_write_coord_delta(wStream* s, INT32 prevCoord, INT32 n
return TRUE;
}
#endif
static INLINE BOOL update_read_color(wStream* s, UINT32* color)
{
@ -513,6 +515,7 @@ static INLINE BOOL update_read_delta(wStream* s, INT32* value)
return TRUE;
}
#if 0
static INLINE void update_read_glyph_delta(wStream* s, UINT16* value)
{
BYTE byte;
@ -534,6 +537,7 @@ static INLINE void update_seek_glyph_delta(wStream* s)
if (byte & 0x80)
Stream_Seek_UINT8(s);
}
#endif
static INLINE BOOL update_read_brush(wStream* s, rdpBrush* brush, BYTE fieldFlags)
{

View File

@ -300,7 +300,7 @@ static int wts_write_variable_uint(wStream* stream, UINT32 val)
}
else
{
cb = 3;
cb = 2;
Stream_Write_UINT32(stream, val);
}
@ -463,27 +463,132 @@ HANDLE WTSVirtualChannelManagerGetEventHandle(HANDLE hServer)
return MessageQueue_Event(vcm->queue);
}
BOOL WTSVirtualChannelManagerIsChannelJoined(HANDLE hServer, const char* name)
static rdpMcsChannel* wts_get_joined_channel_by_name(rdpMcs *mcs, const char *channel_name)
{
rdpMcs* mcs;
UINT32 index;
BOOL joined = FALSE;
WTSVirtualChannelManager* vcm = (WTSVirtualChannelManager*) hServer;
mcs = vcm->rdp->mcs;
if (!mcs || !channel_name || !strlen(channel_name))
return NULL;
for (index = 0; index < mcs->channelCount; index++)
{
if (mcs->channels[index].joined)
{
if (strncmp(mcs->channels[index].Name, name, strlen(name)) == 0)
{
joined = TRUE;
}
}
}
if (_strnicmp(mcs->channels[index].Name, channel_name, strlen(channel_name)) == 0)
return &mcs->channels[index];
}
}
return NULL;
}
return joined;
static rdpMcsChannel* wts_get_joined_channel_by_id(rdpMcs *mcs, const UINT16 channel_id)
{
UINT32 index;
if (!mcs || !channel_id)
return NULL;
for (index = 0; index < mcs->channelCount; index++)
{
if (mcs->channels[index].joined)
{
if (mcs->channels[index].ChannelId == channel_id)
return &mcs->channels[index];
}
}
return NULL;
}
BOOL WTSIsChannelJoinedByName(freerdp_peer *client, const char *channel_name)
{
if (!client || !client->context || !client->context->rdp)
return FALSE;
return wts_get_joined_channel_by_name(client->context->rdp->mcs, channel_name) == NULL ? FALSE : TRUE;
}
BOOL WTSIsChannelJoinedById(freerdp_peer *client, const UINT16 channel_id)
{
if (!client || !client->context || !client->context->rdp)
return FALSE;
return wts_get_joined_channel_by_id(client->context->rdp->mcs, channel_id) == NULL ? FALSE : TRUE;
}
BOOL WTSVirtualChannelManagerIsChannelJoined(HANDLE hServer, const char* name)
{
WTSVirtualChannelManager* vcm = (WTSVirtualChannelManager*) hServer;
if (!vcm || !vcm->rdp)
return FALSE;
return wts_get_joined_channel_by_name(vcm->rdp->mcs, name) == NULL ? FALSE : TRUE;
}
UINT16 WTSChannelGetId(freerdp_peer *client, const char *channel_name)
{
rdpMcsChannel *channel;
if (!client || !client->context || !client->context->rdp)
return 0;
channel = wts_get_joined_channel_by_name(client->context->rdp->mcs, channel_name);
if (!channel)
return 0;
return channel->ChannelId;
}
BOOL WTSChannelSetHandleByName(freerdp_peer *client, const char *channel_name, void *handle)
{
rdpMcsChannel *channel;
if (!client || !client->context || !client->context->rdp)
return FALSE;
channel = wts_get_joined_channel_by_name(client->context->rdp->mcs, channel_name);
if (!channel)
return FALSE;
channel->handle = handle;
return TRUE;
}
BOOL WTSChannelSetHandleById(freerdp_peer *client, const UINT16 channel_id, void *handle)
{
rdpMcsChannel *channel;
if (!client || !client->context || !client->context->rdp)
return FALSE;
channel = wts_get_joined_channel_by_id(client->context->rdp->mcs, channel_id);
if (!channel)
return FALSE;
channel->handle = handle;
return TRUE;
}
void *WTSChannelGetHandleByName(freerdp_peer *client, const char *channel_name)
{
rdpMcsChannel *channel;
if (!client || !client->context || !client->context->rdp)
return NULL;
channel = wts_get_joined_channel_by_name(client->context->rdp->mcs, channel_name);
if (!channel)
return NULL;
return channel->handle;
}
void *WTSChannelGetHandleById(freerdp_peer *client, const UINT16 channel_id)
{
rdpMcsChannel *channel;
if (!client || !client->context || !client->context->rdp)
return NULL;
channel = wts_get_joined_channel_by_id(client->context->rdp->mcs, channel_id);
if (!channel)
return NULL;
return channel->handle;
}
BOOL WINAPI FreeRDP_WTSStartRemoteControlSessionW(LPWSTR pTargetServerName, ULONG TargetLogonId, BYTE HotkeyVk, USHORT HotkeyModifiers)

View File

@ -431,20 +431,36 @@ int tls_read(rdpTls* tls, BYTE* data, int length)
break;
case SSL_ERROR_SYSCALL:
#ifdef _WIN32
if (WSAGetLastError() == WSAEWOULDBLOCK)
#else
if ((errno == EAGAIN) || (errno == 0))
#endif
{
status = 0;
}
else
{
tls_print_error("SSL_read", tls->ssl, status);
status = -1;
if (tls_print_error("SSL_read", tls->ssl, status))
{
status = -1;
}
else
{
status = 0;
}
}
break;
default:
tls_print_error("SSL_read", tls->ssl, status);
status = -1;
if (tls_print_error("SSL_read", tls->ssl, status))
{
status = -1;
}
else
{
status = 0;
}
break;
}
}
@ -568,7 +584,11 @@ BOOL tls_print_error(char* func, SSL* connection, int value)
return FALSE;
case SSL_ERROR_SYSCALL:
#ifdef _WIN32
fprintf(stderr, "%s: I/O error: %d\n", func, WSAGetLastError());
#else
fprintf(stderr, "%s: I/O error: %s (%d)\n", func, strerror(errno), errno);
#endif
tls_errors(func);
return TRUE;

View File

@ -49,7 +49,7 @@
#include "xf_update.h"
#include "xf_monitors.h"
#include "makecert.h"
#include <winpr/tools/makecert.h>
#include "xf_peer.h"

View File

@ -17,3 +17,4 @@
file(GLOB WINPR_HEADERS "winpr/*.h")
install(FILES ${WINPR_HEADERS} DESTINATION include/winpr COMPONENT headers)
install(DIRECTORY winpr/tools DESTINATION include/winpr COMPONENT headers FILES_MATCHING PATTERN "*.h")

View File

@ -297,7 +297,7 @@ WINPR_API BOOL DeleteTimerQueueTimer(HANDLE TimerQueue, HANDLE Timer, HANDLE Com
#endif
#if ((_WIN32) && (_WIN32_WINNT < 0x0403))
#if ((defined _WIN32) && (_WIN32_WINNT < 0x0403))
WINPR_API BOOL InitializeCriticalSectionEx(LPCRITICAL_SECTION lpCriticalSection, DWORD dwSpinCount, DWORD Flags);

View File

@ -862,7 +862,7 @@ int GetNamePipeFileDescriptor(HANDLE hNamedPipe)
pNamedPipe = (WINPR_NAMED_PIPE*) hNamedPipe;
if (!pNamedPipe)
if (!pNamedPipe || pNamedPipe->Type != HANDLE_TYPE_NAMED_PIPE)
return -1;
fd = (pNamedPipe->ServerMode) ? pNamedPipe->serverfd : pNamedPipe->clientfd;

View File

@ -397,37 +397,46 @@ BOOL WTSRegisterWtsApiFunctionTable(PWtsApiFunctionTable table)
return TRUE;
}
static BOOL LoadAndInitialize(char *library)
{
INIT_WTSAPI_FN pInitWtsApi;
g_WtsApiModule = LoadLibraryA(library);
if (!g_WtsApiModule)
return FALSE;
pInitWtsApi = (INIT_WTSAPI_FN) GetProcAddress(g_WtsApiModule, "InitWtsApi");
if (!pInitWtsApi)
{
return FALSE;
}
g_WtsApi = pInitWtsApi();
return TRUE;
}
void InitializeWtsApiStubs_Env()
{
DWORD nSize;
char* env = NULL;
INIT_WTSAPI_FN pInitWtsApi;
if (g_WtsApi)
return;
nSize = GetEnvironmentVariableA("WTSAPI_LIBRARY", NULL, 0);
if (nSize)
if (!nSize)
{
env = (LPSTR) malloc(nSize);
nSize = GetEnvironmentVariableA("WTSAPI_LIBRARY", env, nSize);
}
if (env)
g_WtsApiModule = LoadLibraryA(env);
if (!g_WtsApiModule)
return;
pInitWtsApi = (INIT_WTSAPI_FN) GetProcAddress(g_WtsApiModule, "InitWtsApi");
if (pInitWtsApi)
{
g_WtsApi = pInitWtsApi();
}
env = (LPSTR) malloc(nSize);
nSize = GetEnvironmentVariableA("WTSAPI_LIBRARY", env, nSize);
if (env)
LoadAndInitialize(env);
}
#define FREERDS_LIBRARY_NAME "libfreerds-fdsapi.so"
void InitializeWtsApiStubs_FreeRDS()
{
char* prefix;
@ -441,13 +450,16 @@ void InitializeWtsApiStubs_FreeRDS()
if (IniFile_Parse(ini, "/var/run/freerds.instance") < 0)
{
printf("failed to parse freerds.instance\n");
IniFile_Free(ini);
fprintf(stderr, "failed to parse freerds.instance\n");
LoadAndInitialize(FREERDS_LIBRARY_NAME);
return;
}
prefix = IniFile_GetKeyValueString(ini, "FreeRDS", "prefix");
libdir = IniFile_GetKeyValueString(ini, "FreeRDS", "libdir");
printf("FreeRDS: %s / %s\n", prefix, libdir);
fprintf(stderr, "FreeRDS (prefix / libdir): %s / %s\n", prefix, libdir);
if (prefix && libdir)
{
@ -455,23 +467,11 @@ void InitializeWtsApiStubs_FreeRDS()
char* wtsapi_library;
prefix_libdir = GetCombinedPath(prefix, libdir);
wtsapi_library = GetCombinedPath(prefix_libdir, "libfreerds-fdsapi.so");
wtsapi_library = GetCombinedPath(prefix_libdir, FREERDS_LIBRARY_NAME);
if (wtsapi_library)
{
INIT_WTSAPI_FN pInitWtsApi;
g_WtsApiModule = LoadLibraryA(wtsapi_library);
if (g_WtsApiModule)
{
pInitWtsApi = (INIT_WTSAPI_FN) GetProcAddress(g_WtsApiModule, "InitWtsApi");
if (pInitWtsApi)
{
g_WtsApi = pInitWtsApi();
}
}
LoadAndInitialize(wtsapi_library);
}
free(prefix_libdir);
@ -492,4 +492,6 @@ void InitializeWtsApiStubs(void)
if (!g_WtsApi)
InitializeWtsApiStubs_FreeRDS();
return;
}

View File

@ -18,9 +18,7 @@
set(MODULE_NAME "winpr-makecert-tool")
set(MODULE_PREFIX "WINPR_MAKECERT_TOOL")
set(${MODULE_PREFIX}_SRCS
makecert.c
makecert.h)
set(${MODULE_PREFIX}_SRCS makecert.c)
include_directories(${ZLIB_INCLUDE_DIRS})
include_directories(${OPENSSL_INCLUDE_DIR})

View File

@ -25,7 +25,7 @@
#include <winpr/cmdline.h>
#include <winpr/sysinfo.h>
#include "makecert.h"
#include <winpr/tools/makecert.h>
int main(int argc, char* argv[])
{

View File

@ -31,7 +31,7 @@
#include <openssl/conf.h>
#include <openssl/x509v3.h>
#include "makecert.h"
#include <winpr/tools/makecert.h>
struct _MAKECERT_CONTEXT
{