Merge pull request #5213 from akallabeth/wayland_and_warning_fixes

Wayland and warning fixes
This commit is contained in:
David Fort 2019-01-25 11:42:38 +01:00 committed by GitHub
commit 343bc8c6e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 237 additions and 162 deletions

View File

@ -54,8 +54,7 @@
static void drive_file_fix_path(WCHAR* path)
{
size_t i;
size_t length;
length = (int) _wcslen(path);
size_t length = _wcslen(path);
for (i = 0; i < length; i++)
{
@ -80,10 +79,10 @@ static void drive_file_fix_path(WCHAR* path)
}
static WCHAR* drive_file_combine_fullpath(const WCHAR* base_path, const WCHAR* path,
UINT32 PathLength)
size_t PathLength)
{
WCHAR* fullpath;
UINT32 base_path_length;
size_t base_path_length;
if (!base_path || !path)
return NULL;
@ -107,11 +106,10 @@ static BOOL drive_file_remove_dir(const WCHAR* path)
{
WIN32_FIND_DATAW findFileData;
BOOL ret = TRUE;
INT len;
HANDLE dir;
WCHAR* fullpath;
WCHAR* path_slash;
UINT32 base_path_length;
size_t base_path_length;
if (!path)
return FALSE;
@ -140,7 +138,7 @@ static BOOL drive_file_remove_dir(const WCHAR* path)
do
{
len = _wcslen(findFileData.cFileName);
size_t len = _wcslen(findFileData.cFileName);
if ((len == 1 && findFileData.cFileName[0] == L'.') || (len == 2 &&
findFileData.cFileName[0] == L'.' && findFileData.cFileName[1] == L'.'))
@ -335,7 +333,7 @@ DRIVE_FILE* drive_file_new(const WCHAR* base_path, const WCHAR* path, UINT32 Pat
file->file_handle = INVALID_HANDLE_VALUE;
file->find_handle = INVALID_HANDLE_VALUE;
file->id = id;
file->basepath = (WCHAR*) base_path;
file->basepath = base_path;
file->FileAttributes = FileAttributes;
file->DesiredAccess = DesiredAccess;
file->CreateDisposition = CreateDisposition;
@ -397,7 +395,10 @@ BOOL drive_file_seek(DRIVE_FILE* file, UINT64 Offset)
if (!file)
return FALSE;
loffset.QuadPart = Offset;
if (Offset > INT64_MAX)
return FALSE;
loffset.QuadPart = (LONGLONG)Offset;
return SetFilePointerEx(file->file_handle, loffset, NULL, FILE_BEGIN);
}
@ -757,7 +758,10 @@ BOOL drive_file_query_directory(DRIVE_FILE* file, UINT32 FsInformationClass, BYT
if (!Stream_EnsureRemainingCapacity(output, 4 + 64 + length))
goto out_fail;
Stream_Write_UINT32(output, 64 + length); /* Length */
if (length > UINT32_MAX - 64)
goto out_fail;
Stream_Write_UINT32(output, (UINT32)(64 + length)); /* Length */
Stream_Write_UINT32(output, 0); /* NextEntryOffset */
Stream_Write_UINT32(output, 0); /* FileIndex */
Stream_Write_UINT32(output, file->find_data.ftCreationTime.dwLowDateTime); /* CreationTime */
@ -773,7 +777,7 @@ BOOL drive_file_query_directory(DRIVE_FILE* file, UINT32 FsInformationClass, BYT
Stream_Write_UINT32(output, file->find_data.nFileSizeLow); /* AllocationSize */
Stream_Write_UINT32(output, file->find_data.nFileSizeHigh); /* AllocationSize */
Stream_Write_UINT32(output, file->find_data.dwFileAttributes); /* FileAttributes */
Stream_Write_UINT32(output, length); /* FileNameLength */
Stream_Write_UINT32(output, (UINT32)length); /* FileNameLength */
Stream_Write(output, file->find_data.cFileName, length);
break;
@ -783,7 +787,10 @@ BOOL drive_file_query_directory(DRIVE_FILE* file, UINT32 FsInformationClass, BYT
if (!Stream_EnsureRemainingCapacity(output, 4 + 68 + length))
goto out_fail;
Stream_Write_UINT32(output, 68 + length); /* Length */
if (length > UINT32_MAX - 68)
goto out_fail;
Stream_Write_UINT32(output, (UINT32)(68 + length)); /* Length */
Stream_Write_UINT32(output, 0); /* NextEntryOffset */
Stream_Write_UINT32(output, 0); /* FileIndex */
Stream_Write_UINT32(output, file->find_data.ftCreationTime.dwLowDateTime); /* CreationTime */
@ -799,7 +806,7 @@ BOOL drive_file_query_directory(DRIVE_FILE* file, UINT32 FsInformationClass, BYT
Stream_Write_UINT32(output, file->find_data.nFileSizeLow); /* AllocationSize */
Stream_Write_UINT32(output, file->find_data.nFileSizeHigh); /* AllocationSize */
Stream_Write_UINT32(output, file->find_data.dwFileAttributes); /* FileAttributes */
Stream_Write_UINT32(output, length); /* FileNameLength */
Stream_Write_UINT32(output, (UINT32)length); /* FileNameLength */
Stream_Write_UINT32(output, 0); /* EaSize */
Stream_Write(output, file->find_data.cFileName, length);
break;
@ -810,7 +817,10 @@ BOOL drive_file_query_directory(DRIVE_FILE* file, UINT32 FsInformationClass, BYT
if (!Stream_EnsureRemainingCapacity(output, 4 + 93 + length))
goto out_fail;
Stream_Write_UINT32(output, 93 + length); /* Length */
if (length > UINT32_MAX - 93)
goto out_fail;
Stream_Write_UINT32(output, (UINT32)(93 + length)); /* Length */
Stream_Write_UINT32(output, 0); /* NextEntryOffset */
Stream_Write_UINT32(output, 0); /* FileIndex */
Stream_Write_UINT32(output, file->find_data.ftCreationTime.dwLowDateTime); /* CreationTime */
@ -826,7 +836,7 @@ BOOL drive_file_query_directory(DRIVE_FILE* file, UINT32 FsInformationClass, BYT
Stream_Write_UINT32(output, file->find_data.nFileSizeLow); /* AllocationSize */
Stream_Write_UINT32(output, file->find_data.nFileSizeHigh); /* AllocationSize */
Stream_Write_UINT32(output, file->find_data.dwFileAttributes); /* FileAttributes */
Stream_Write_UINT32(output, length); /* FileNameLength */
Stream_Write_UINT32(output, (UINT32)length); /* FileNameLength */
Stream_Write_UINT32(output, 0); /* EaSize */
Stream_Write_UINT8(output, 0); /* ShortNameLength */
/* Reserved(1), MUST NOT be added! */
@ -840,10 +850,13 @@ BOOL drive_file_query_directory(DRIVE_FILE* file, UINT32 FsInformationClass, BYT
if (!Stream_EnsureRemainingCapacity(output, 4 + 12 + length))
goto out_fail;
Stream_Write_UINT32(output, 12 + length); /* Length */
if (length > UINT32_MAX - 12)
goto out_fail;
Stream_Write_UINT32(output, (UINT32)(12 + length)); /* Length */
Stream_Write_UINT32(output, 0); /* NextEntryOffset */
Stream_Write_UINT32(output, 0); /* FileIndex */
Stream_Write_UINT32(output, length); /* FileNameLength */
Stream_Write_UINT32(output, (UINT32)length); /* FileNameLength */
Stream_Write(output, file->find_data.cFileName, length);
break;

View File

@ -40,7 +40,7 @@ struct _DRIVE_FILE
HANDLE file_handle;
HANDLE find_handle;
WIN32_FIND_DATAW find_data;
WCHAR* basepath;
const WCHAR* basepath;
WCHAR* fullpath;
WCHAR* filename;
BOOL delete_pending;

View File

@ -267,8 +267,11 @@ static UINT wlf_cliprdr_send_data_response(wfClipboard* clipboard, const BYTE* d
size_t size)
{
CLIPRDR_FORMAT_DATA_RESPONSE response = { 0 };
if (size > UINT32_MAX)
return ERROR_INVALID_PARAMETER;
response.msgFlags = (data) ? CB_RESPONSE_OK : CB_RESPONSE_FAIL;
response.dataLen = size;
response.dataLen = (UINT32)size;
response.requestedFormatData = data;
return clipboard->context->ClientFormatDataResponse(clipboard->context,
&response);
@ -355,6 +358,7 @@ static UINT wlf_cliprdr_monitor_ready(CliprdrClientContext* context,
wfClipboard* clipboard = (wfClipboard*) context->custom;
UINT ret;
WINPR_UNUSED(monitorReady);
if ((ret = wlf_cliprdr_send_client_capabilities(clipboard)) != CHANNEL_RC_OK)
return ret;
@ -592,8 +596,9 @@ static UINT wlf_cliprdr_server_format_list_response(CliprdrClientContext*
static UINT wlf_cliprdr_server_format_data_request(CliprdrClientContext* context,
const CLIPRDR_FORMAT_DATA_REQUEST* formatDataRequest)
{
int cnv;
UINT rc;
char* data;
BYTE* data;
LPWSTR cdata;
size_t size;
const char* mime;
@ -632,10 +637,22 @@ static UINT wlf_cliprdr_server_format_data_request(CliprdrClientContext* context
switch (formatId)
{
case CF_UNICODETEXT:
size = ConvertToUnicode(CP_UTF8, 0, data, size, &cdata, 0);
free(data);
data = cdata;
size *= sizeof(WCHAR);
if (size > INT_MAX)
rc = ERROR_INTERNAL_ERROR;
else
{
cnv = ConvertToUnicode(CP_UTF8, 0, (LPCSTR)data, (int)size, &cdata, 0);
free(data);
if (cnv < 0)
rc = ERROR_INTERNAL_ERROR;
else
{
size = (size_t)cnv;
data = (BYTE*)cdata;
size *= sizeof(WCHAR);
}
}
break;
default:
@ -656,18 +673,25 @@ static UINT wlf_cliprdr_server_format_data_request(CliprdrClientContext* context
static UINT wlf_cliprdr_server_format_data_response(CliprdrClientContext*
context, const CLIPRDR_FORMAT_DATA_RESPONSE* formatDataResponse)
{
int cnv;
UINT rc = ERROR_INTERNAL_ERROR;
BOOL freedata = FALSE;
UINT32 size = formatDataResponse->dataLen;
LPSTR data = formatDataResponse->requestedFormatData;
const WCHAR* wdata = (WCHAR*)formatDataResponse->requestedFormatData;
LPSTR cdata = NULL;
LPCSTR data = (LPCSTR)formatDataResponse->requestedFormatData;
const WCHAR* wdata = (const WCHAR*)formatDataResponse->requestedFormatData;
wfClipboard* clipboard = (wfClipboard*) context->custom;
if (size > INT_MAX * sizeof(WCHAR))
return ERROR_INTERNAL_ERROR;
switch (clipboard->responseFormat)
{
case CF_UNICODETEXT:
size = ConvertFromUnicode(CP_UTF8, 0, wdata, size / sizeof(WCHAR), &data, 0, NULL, NULL);
freedata = TRUE;
cnv = ConvertFromUnicode(CP_UTF8, 0, wdata, (int)(size / sizeof(WCHAR)), &cdata, 0, NULL, NULL);
if (cnv < 0)
return ERROR_INTERNAL_ERROR;
size = (size_t)cnv;
data = cdata;
break;
default:
@ -678,10 +702,7 @@ static UINT wlf_cliprdr_server_format_data_response(CliprdrClientContext*
fwrite(data, 1, size, clipboard->responseFile);
fclose(clipboard->responseFile);
rc = CHANNEL_RC_OK;
fail:
if (freedata)
free(data);
free(cdata);
return rc;
}
@ -775,6 +796,8 @@ static UINT wlf_cliprdr_clipboard_file_size_failure(wClipboardDelegate* delegate
{
CLIPRDR_FILE_CONTENTS_RESPONSE response = { 0 };
wfClipboard* clipboard = delegate->custom;
WINPR_UNUSED(errorCode);
response.msgFlags = CB_RESPONSE_FAIL;
response.streamId = request->streamId;
response.dwFlags = FILECONTENTS_SIZE;
@ -790,7 +813,7 @@ static UINT wlf_cliprdr_clipboard_file_range_success(wClipboardDelegate* delegat
response.streamId = request->streamId;
response.dwFlags = FILECONTENTS_RANGE;
response.cbRequested = size;
response.requestedData = (BYTE*) data;
response.requestedData = (const BYTE*) data;
return clipboard->context->ClientFileContentsResponse(clipboard->context, &response);
}
@ -799,6 +822,8 @@ static UINT wlf_cliprdr_clipboard_file_range_failure(wClipboardDelegate* delegat
{
CLIPRDR_FILE_CONTENTS_RESPONSE response = { 0 };
wfClipboard* clipboard = delegate->custom;
WINPR_UNUSED(errorCode);
response.msgFlags = CB_RESPONSE_FAIL;
response.streamId = request->streamId;
response.dwFlags = FILECONTENTS_RANGE;
@ -825,9 +850,6 @@ wfClipboard* wlf_clipboard_new(wlfContext* wfc)
clipboard->delegate->ClipboardFileRangeSuccess = wlf_cliprdr_clipboard_file_range_success;
clipboard->delegate->ClipboardFileRangeFailure = wlf_cliprdr_clipboard_file_range_failure;
return clipboard;
error:
wlf_clipboard_free(clipboard);
return NULL;
}
void wlf_clipboard_free(wfClipboard* clipboard)

View File

@ -40,21 +40,6 @@
#include "wlf_disp.h"
#include "wlf_channels.h"
static BOOL wl_update_content(wlfContext* context_w)
{
if (!context_w)
return FALSE;
if (!context_w->waitingFrameDone && context_w->haveDamage)
{
UwacWindowSubmitBuffer(context_w->window, true);
context_w->waitingFrameDone = TRUE;
context_w->haveDamage = FALSE;
}
return TRUE;
}
static BOOL wl_begin_paint(rdpContext* context)
{
rdpGdi* gdi;
@ -71,18 +56,31 @@ static BOOL wl_begin_paint(rdpContext* context)
return TRUE;
}
static BOOL wl_update_buffer(wlfContext* context_w, UINT32 x, UINT32 y, UINT32 w, UINT32 h)
static BOOL wl_update_buffer(wlfContext* context_w, INT32 ix, INT32 iy, INT32 iw, INT32 ih)
{
rdpGdi* gdi;
char* data;
UINT32 i;
size_t baseSrcOffset;
size_t baseDstOffset;
UINT32 i, x, y, w, h;
UwacSize geometry;
size_t stride;
UwacReturnCode rc;
if (!context_w)
return FALSE;
if ((ix < 0) || (iy < 0) || (iw < 0) || (ih < 0))
return FALSE;
x = (UINT32)ix;
y = (UINT32)iy;
w = (UINT32)iw;
h = (UINT32)ih;
rc = UwacWindowGetDrawingBufferGeometry(context_w->window, &geometry, &stride);
data = UwacWindowGetDrawingBuffer(context_w->window);
if (!data)
if (!data || (rc != UWAC_SUCCESS))
return FALSE;
gdi = context_w->context.gdi;
@ -90,20 +88,28 @@ static BOOL wl_update_buffer(wlfContext* context_w, UINT32 x, UINT32 y, UINT32 w
if (!gdi)
return FALSE;
for (i = 0; i < h; i++)
/* Ignore output if the surface size does not match. */
if ((x > geometry.width) || (y > geometry.height))
return TRUE;
baseSrcOffset = y * gdi->stride + x * GetBytesPerPixel(gdi->dstFormat);
baseDstOffset = y * stride + x * 4;
for (i = 0; i < MIN(h, geometry.height - y); i++)
{
memcpy(data + ((i + y) * (gdi->width * GetBytesPerPixel(
gdi->dstFormat))) + x * GetBytesPerPixel(gdi->dstFormat),
gdi->primary_buffer + ((i + y) * (gdi->width * GetBytesPerPixel(
gdi->dstFormat))) + x * GetBytesPerPixel(gdi->dstFormat),
w * GetBytesPerPixel(gdi->dstFormat));
const size_t srcOffset = i * gdi->stride + baseSrcOffset;
const size_t dstOffset = i * stride + baseDstOffset;
memcpy(data + dstOffset, gdi->primary_buffer + srcOffset,
MIN(w, geometry.width - x) * GetBytesPerPixel(gdi->dstFormat));
}
if (UwacWindowAddDamage(context_w->window, x, y, w, h) != UWAC_SUCCESS)
return FALSE;
context_w->haveDamage = TRUE;
return wl_update_content(context_w);
if (UwacWindowSubmitBuffer(context_w->window, true) != UWAC_SUCCESS)
return FALSE;
return TRUE;
}
static BOOL wl_end_paint(rdpContext* context)
@ -111,7 +117,7 @@ static BOOL wl_end_paint(rdpContext* context)
rdpGdi* gdi;
wlfContext* context_w;
INT32 x, y;
UINT32 w, h;
INT32 w, h;
if (!context || !context->gdi || !context->gdi->primary)
return FALSE;
@ -203,6 +209,7 @@ static BOOL wl_post_connect(freerdp* instance)
rdpGdi* gdi;
UwacWindow* window;
wlfContext* context;
UINT32 w, h;
if (!instance || !instance->context)
return FALSE;
@ -212,19 +219,20 @@ static BOOL wl_post_connect(freerdp* instance)
gdi = instance->context->gdi;
if (!gdi)
if (!gdi || (gdi->width < 0) || (gdi->height < 0))
return FALSE;
w = (UINT32)gdi->width;
h = (UINT32)gdi->height;
context = (wlfContext*) instance->context;
context->window = window = UwacCreateWindowShm(context->display, gdi->width,
gdi->height, WL_SHM_FORMAT_XRGB8888);
context->window = window = UwacCreateWindowShm(context->display, w, h, WL_SHM_FORMAT_XRGB8888);
if (!window)
return FALSE;
UwacWindowSetFullscreenState(window, NULL, instance->context->settings->Fullscreen);
UwacWindowSetTitle(window, "FreeRDP");
UwacWindowSetOpaqueRegion(context->window, 0, 0, gdi->width, gdi->height);
UwacWindowSetOpaqueRegion(context->window, 0, 0, w, h);
instance->update->BeginPaint = wl_begin_paint;
instance->update->EndPaint = wl_end_paint;
instance->update->DesktopResize = wl_resize_display;
@ -238,7 +246,7 @@ static BOOL wl_post_connect(freerdp* instance)
if (!context->clipboard)
return FALSE;
return wl_update_buffer(context, 0, 0, gdi->width, gdi->height);
return wl_refresh_display(context);
}
static void wl_post_disconnect(freerdp* instance)
@ -279,14 +287,6 @@ static BOOL handle_uwac_events(freerdp* instance, UwacDisplay* display)
switch (event.type)
{
case UWAC_EVENT_FRAME_DONE:
if (!instance)
continue;
context->waitingFrameDone = FALSE;
if (context->haveDamage && !wl_update_content(context))
return FALSE;
break;
case UWAC_EVENT_POINTER_ENTER:
@ -487,11 +487,13 @@ static void wlf_client_free(freerdp* instance, rdpContext* context)
static int wfl_client_start(rdpContext* context)
{
WINPR_UNUSED(context);
return 0;
}
static int wfl_client_stop(rdpContext* context)
{
WINPR_UNUSED(context);
return 0;
}
@ -513,7 +515,7 @@ static int RdpClientEntry(RDP_CLIENT_ENTRY_POINTS* pEntryPoints)
int main(int argc, char* argv[])
{
int rc = -1;
DWORD status;
int status;
RDP_CLIENT_ENTRY_POINTS clientEntryPoints;
rdpContext* context;
RdpClientEntry(&clientEntryPoints);

View File

@ -42,8 +42,6 @@ struct wlf_context
HANDLE displayHandle;
UwacWindow* window;
BOOL waitingFrameDone;
BOOL haveDamage;
BOOL fullscreen;
/* Channels */

View File

@ -203,7 +203,7 @@ struct _CLIPRDR_FORMAT_DATA_RESPONSE
{
DEFINE_CLIPRDR_HEADER_COMMON();
BYTE* requestedFormatData;
const BYTE* requestedFormatData;
};
typedef struct _CLIPRDR_FORMAT_DATA_RESPONSE CLIPRDR_FORMAT_DATA_RESPONSE;
@ -229,7 +229,7 @@ struct _CLIPRDR_FILE_CONTENTS_RESPONSE
UINT32 streamId;
UINT32 dwFlags;
UINT32 cbRequested;
BYTE* requestedData;
const BYTE* requestedData;
};
typedef struct _CLIPRDR_FILE_CONTENTS_RESPONSE CLIPRDR_FILE_CONTENTS_RESPONSE;

View File

@ -111,6 +111,17 @@ struct _FREERDP_DSP_CONTEXT
#endif
};
static INT16 read_int16(const BYTE* src)
{
return (INT16) (src[0] | (src[1] << 8));
}
static void write_int16(BYTE* dst, INT32 val)
{
dst[1] = (val >> 8) & 0xFF;
dst[0] = val & 0xFF;
}
static BOOL freerdp_dsp_channel_mix(FREERDP_DSP_CONTEXT* context,
const BYTE* src, size_t size,
const AUDIO_FORMAT* srcFormat,
@ -208,11 +219,11 @@ static BOOL freerdp_dsp_resample(FREERDP_DSP_CONTEXT* context,
#if defined(WITH_SOXR)
soxr_error_t error;
size_t idone, odone;
#endif
size_t sframes, rframes;
size_t rsize;
size_t j;
size_t sbytes, rbytes;
#endif
size_t srcBytesPerFrame, dstBytesPerFrame;
size_t srcChannels, dstChannels;
AUDIO_FORMAT format;
@ -256,6 +267,10 @@ static BOOL freerdp_dsp_resample(FREERDP_DSP_CONTEXT* context,
*length = Stream_Length(context->resample);
return (error == 0) ? TRUE : FALSE;
#else
WINPR_UNUSED(src);
WINPR_UNUSED(size);
WINPR_UNUSED(data);
WINPR_UNUSED(length);
WLog_ERR(TAG, "Missing resample support, recompile -DWITH_SOXR=ON or -DWITH_DSP_FFMPEG=ON");
return FALSE;
#endif
@ -331,11 +346,11 @@ static BOOL freerdp_dsp_decode_ima_adpcm(FREERDP_DSP_CONTEXT* context,
BYTE* dst;
BYTE sample;
UINT16 decoded;
UINT32 out_size = size * 4;
size_t out_size = size * 4;
UINT32 channel;
const UINT32 block_size = context->format.nBlockAlign;
const UINT32 channels = context->format.nChannels;
int i;
size_t i;
if (!Stream_EnsureCapacity(out, out_size))
return FALSE;
@ -410,7 +425,7 @@ static BOOL freerdp_dsp_decode_gsm610(FREERDP_DSP_CONTEXT* context,
{
int rc;
gsm_signal gsmBlockBuffer[160] = { 0 };
rc = gsm_decode(context->gsm, (gsm_byte*) &src[offset], gsmBlockBuffer);
rc = gsm_decode(context->gsm, (gsm_byte*) /* API does not modify */ &src[offset], gsmBlockBuffer);
if (rc < 0)
return FALSE;
@ -436,12 +451,12 @@ static BOOL freerdp_dsp_encode_gsm610(FREERDP_DSP_CONTEXT* context,
while (offset < size)
{
gsm_signal* signal = (gsm_signal*)&src[offset];
const gsm_signal* signal = (const gsm_signal*)&src[offset];
if (!Stream_EnsureRemainingCapacity(out, sizeof(gsm_frame)))
return FALSE;
gsm_encode(context->gsm, signal, Stream_Pointer(out));
gsm_encode(context->gsm, (gsm_signal*) /* API does not modify */ signal, Stream_Pointer(out));
if ((offset % 65) == 0)
Stream_Seek(out, 33);
@ -480,13 +495,13 @@ static BOOL freerdp_dsp_decode_mp3(FREERDP_DSP_CONTEXT* context,
if (rc <= 0)
return FALSE;
if (!Stream_EnsureRemainingCapacity(out, rc * context->format.nChannels * 2))
if (!Stream_EnsureRemainingCapacity(out, (size_t)rc * context->format.nChannels * 2))
return FALSE;
for (x = 0; x < rc; x++)
{
Stream_Write_UINT16(out, pcm_l[x]);
Stream_Write_UINT16(out, pcm_r[x]);
Stream_Write_UINT16(out, (UINT16)pcm_l[x]);
Stream_Write_UINT16(out, (UINT16)pcm_r[x]);
}
return TRUE;
@ -504,7 +519,7 @@ static BOOL freerdp_dsp_encode_mp3(FREERDP_DSP_CONTEXT* context,
samples_per_channel = size / context->format.nChannels / context->format.wBitsPerSample / 8;
/* Ensure worst case buffer size for mp3 stream taken from LAME header */
if (!Stream_EnsureRemainingCapacity(out, 1.25 * samples_per_channel + 7200))
if (!Stream_EnsureRemainingCapacity(out, 5 / 4 * samples_per_channel + 7200))
return FALSE;
samples_per_channel = size / 2 /* size of a sample */ / context->format.nChannels;
@ -514,7 +529,7 @@ static BOOL freerdp_dsp_encode_mp3(FREERDP_DSP_CONTEXT* context,
if (rc < 0)
return FALSE;
Stream_Seek(out, rc);
Stream_Seek(out, (size_t)rc);
return TRUE;
}
#endif
@ -523,10 +538,10 @@ static BOOL freerdp_dsp_encode_mp3(FREERDP_DSP_CONTEXT* context,
static BOOL freerdp_dsp_encode_faac(FREERDP_DSP_CONTEXT* context,
const BYTE* src, size_t size, wStream* out)
{
int16_t* inSamples = (int16_t*)src;
const int16_t* inSamples = (const int16_t*)src;
int32_t* outSamples;
unsigned int bpp;
unsigned int nrSamples, x;
size_t nrSamples, x;
int rc;
if (!context || !src || !out)
@ -553,7 +568,7 @@ static BOOL freerdp_dsp_encode_faac(FREERDP_DSP_CONTEXT* context,
if (rc < 0)
return FALSE;
else if (rc > 0)
Stream_Seek(out, rc);
Stream_Seek(out, (size_t)rc);
return TRUE;
}
@ -574,7 +589,7 @@ static BOOL freerdp_dsp_decode_faad(FREERDP_DSP_CONTEXT* context,
{
unsigned long samplerate;
unsigned char channels;
char err = NeAACDecInit(context->faad, /* API is not modifying content */(unsigned char*)src,
long err = NeAACDecInit(context->faad, /* API is not modifying content */(unsigned char*)src,
size, &samplerate, &channels);
if (err != 0)
@ -721,7 +736,7 @@ static BOOL freerdp_dsp_encode_ima_adpcm(FREERDP_DSP_CONTEXT* context,
BYTE* start;
INT16 sample;
BYTE encoded;
UINT32 out_size;
size_t out_size;
size_t align;
out_size = size / 2;
@ -807,7 +822,7 @@ static INLINE INT16 freerdp_dsp_decode_ms_adpcm_sample(ADPCM* adpcm, BYTE sample
{
INT8 nibble;
INT32 presample;
nibble = (sample & 0x08 ? (INT8) sample - 16 : sample);
nibble = (sample & 0x08 ? (INT8) sample - 16 : (INT8)sample);
presample = ((adpcm->ms.sample1[channel] * ms_adpcm_coeffs1[adpcm->ms.predictor[channel]]) +
(adpcm->ms.sample2[channel] * ms_adpcm_coeffs2[adpcm->ms.predictor[channel]])) / 256;
presample += nibble * adpcm->ms.delta[channel];
@ -832,7 +847,7 @@ static BOOL freerdp_dsp_decode_ms_adpcm(FREERDP_DSP_CONTEXT* context,
{
BYTE* dst;
BYTE sample;
const UINT32 out_size = size * 4;
const size_t out_size = size * 4;
const UINT32 channels = context->format.nChannels;
const UINT32 block_size = context->format.nBlockAlign;
@ -849,41 +864,41 @@ static BOOL freerdp_dsp_decode_ms_adpcm(FREERDP_DSP_CONTEXT* context,
{
context->adpcm.ms.predictor[0] = *src++;
context->adpcm.ms.predictor[1] = *src++;
context->adpcm.ms.delta[0] = *((INT16*) src);
context->adpcm.ms.delta[0] = read_int16(src);
src += 2;
context->adpcm.ms.delta[1] = *((INT16*) src);
context->adpcm.ms.delta[1] = read_int16(src);
src += 2;
context->adpcm.ms.sample1[0] = *((INT16*) src);
context->adpcm.ms.sample1[0] = read_int16(src);
src += 2;
context->adpcm.ms.sample1[1] = *((INT16*) src);
context->adpcm.ms.sample1[1] = read_int16(src);
src += 2;
context->adpcm.ms.sample2[0] = *((INT16*) src);
context->adpcm.ms.sample2[0] = read_int16(src);
src += 2;
context->adpcm.ms.sample2[1] = *((INT16*) src);
context->adpcm.ms.sample2[1] = read_int16(src);
src += 2;
size -= 14;
*((INT16*) dst) = context->adpcm.ms.sample2[0];
write_int16(dst, context->adpcm.ms.sample2[0]);
dst += 2;
*((INT16*) dst) = context->adpcm.ms.sample2[1];
write_int16(dst, context->adpcm.ms.sample2[1]);
dst += 2;
*((INT16*) dst) = context->adpcm.ms.sample1[0];
write_int16(dst, context->adpcm.ms.sample1[0]);
dst += 2;
*((INT16*) dst) = context->adpcm.ms.sample1[1];
write_int16(dst, context->adpcm.ms.sample1[1]);
dst += 2;
}
else
{
context->adpcm.ms.predictor[0] = *src++;
context->adpcm.ms.delta[0] = *((INT16*) src);
context->adpcm.ms.delta[0] = read_int16(src);
src += 2;
context->adpcm.ms.sample1[0] = *((INT16*) src);
context->adpcm.ms.sample1[0] = read_int16(src);
src += 2;
context->adpcm.ms.sample2[0] = *((INT16*) src);
context->adpcm.ms.sample2[0] = read_int16(src);
src += 2;
size -= 7;
*((INT16*) dst) = context->adpcm.ms.sample2[0];
write_int16(dst, context->adpcm.ms.sample2[0]);
dst += 2;
*((INT16*) dst) = context->adpcm.ms.sample1[0];
write_int16(dst, context->adpcm.ms.sample1[0]);
dst += 2;
}
}
@ -892,24 +907,24 @@ static BOOL freerdp_dsp_decode_ms_adpcm(FREERDP_DSP_CONTEXT* context,
{
sample = *src++;
size--;
*((INT16*) dst) = freerdp_dsp_decode_ms_adpcm_sample(&context->adpcm, sample >> 4, 0);
write_int16(dst, freerdp_dsp_decode_ms_adpcm_sample(&context->adpcm, sample >> 4, 0));
dst += 2;
*((INT16*) dst) = freerdp_dsp_decode_ms_adpcm_sample(&context->adpcm, sample & 0x0F, 1);
write_int16(dst, freerdp_dsp_decode_ms_adpcm_sample(&context->adpcm, sample & 0x0F, 1));
dst += 2;
sample = *src++;
size--;
*((INT16*) dst) = freerdp_dsp_decode_ms_adpcm_sample(&context->adpcm, sample >> 4, 0);
write_int16(dst, freerdp_dsp_decode_ms_adpcm_sample(&context->adpcm, sample >> 4, 0));
dst += 2;
*((INT16*) dst) = freerdp_dsp_decode_ms_adpcm_sample(&context->adpcm, sample & 0x0F, 1);
write_int16(dst, freerdp_dsp_decode_ms_adpcm_sample(&context->adpcm, sample & 0x0F, 1));
dst += 2;
}
else
{
sample = *src++;
size--;
*((INT16*) dst) = freerdp_dsp_decode_ms_adpcm_sample(&context->adpcm, sample >> 4, 0);
write_int16(dst, freerdp_dsp_decode_ms_adpcm_sample(&context->adpcm, sample >> 4, 0));
dst += 2;
*((INT16*) dst) = freerdp_dsp_decode_ms_adpcm_sample(&context->adpcm, sample & 0x0F, 0);
write_int16(dst, freerdp_dsp_decode_ms_adpcm_sample(&context->adpcm, sample & 0x0F, 0));
dst += 2;
}
}
@ -958,7 +973,7 @@ static BOOL freerdp_dsp_encode_ms_adpcm(FREERDP_DSP_CONTEXT* context, const BYTE
BYTE* dst;
BYTE* start;
INT32 sample;
UINT32 out_size;
size_t out_size;
const size_t step = 8 + ((context->format.nChannels > 1) ? 4 : 0);
out_size = size / 2;
@ -985,14 +1000,14 @@ static BOOL freerdp_dsp_encode_ms_adpcm(FREERDP_DSP_CONTEXT* context, const BYTE
*dst++ = (BYTE)((context->adpcm.ms.delta[0] >> 8) & 0xFF);
*dst++ = (BYTE)(context->adpcm.ms.delta[1] & 0xFF);
*dst++ = (BYTE)((context->adpcm.ms.delta[1] >> 8) & 0xFF);
context->adpcm.ms.sample1[0] = *((INT16*)(src + 4));
context->adpcm.ms.sample1[1] = *((INT16*)(src + 6));
context->adpcm.ms.sample2[0] = *((INT16*)(src + 0));
context->adpcm.ms.sample2[1] = *((INT16*)(src + 2));
*((INT16*)(dst + 0)) = (INT16) context->adpcm.ms.sample1[0];
*((INT16*)(dst + 2)) = (INT16) context->adpcm.ms.sample1[1];
*((INT16*)(dst + 4)) = (INT16) context->adpcm.ms.sample2[0];
*((INT16*)(dst + 6)) = (INT16) context->adpcm.ms.sample2[1];
context->adpcm.ms.sample1[0] = read_int16(src + 4);
context->adpcm.ms.sample1[1] = read_int16(src + 6);
context->adpcm.ms.sample2[0] = read_int16(src + 0);
context->adpcm.ms.sample2[1] = read_int16(src + 2);
write_int16(dst + 0, context->adpcm.ms.sample1[0]);
write_int16(dst + 2, context->adpcm.ms.sample1[1]);
write_int16(dst + 4, context->adpcm.ms.sample2[0]);
write_int16(dst + 6, context->adpcm.ms.sample2[1]);
dst += 8;
src += 8;
size -= 8;
@ -1002,20 +1017,20 @@ static BOOL freerdp_dsp_encode_ms_adpcm(FREERDP_DSP_CONTEXT* context, const BYTE
*dst++ = context->adpcm.ms.predictor[0];
*dst++ = (BYTE)(context->adpcm.ms.delta[0] & 0xFF);
*dst++ = (BYTE)((context->adpcm.ms.delta[0] >> 8) & 0xFF);
context->adpcm.ms.sample1[0] = *((INT16*)(src + 2));
context->adpcm.ms.sample2[0] = *((INT16*)(src + 0));
*((INT16*)(dst + 0)) = (INT16) context->adpcm.ms.sample1[0];
*((INT16*)(dst + 2)) = (INT16) context->adpcm.ms.sample2[0];
context->adpcm.ms.sample1[0] = read_int16(src + 2);
context->adpcm.ms.sample2[0] = read_int16(src + 0);
write_int16(dst + 0, context->adpcm.ms.sample1[0]);
write_int16(dst + 2, context->adpcm.ms.sample2[0]);
dst += 4;
src += 4;
size -= 4;
}
}
sample = *((INT16*) src);
sample = read_int16(src);
src += 2;
*dst = freerdp_dsp_encode_ms_adpcm_sample(&context->adpcm, sample, 0) << 4;
sample = *((INT16*) src);
*dst = (freerdp_dsp_encode_ms_adpcm_sample(&context->adpcm, sample, 0) << 4) & 0xFF;
sample = read_int16(src);
src += 2;
*dst += freerdp_dsp_encode_ms_adpcm_sample(&context->adpcm, sample,
context->format.nChannels > 1 ? 1 : 0);
@ -1258,6 +1273,9 @@ BOOL freerdp_dsp_supports_format(const AUDIO_FORMAT* format, BOOL encode)
return freerdp_dsp_ffmpeg_supports_format(format, encode);
#else
#if !defined(WITH_DSP_EXPERIMENTAL)
WINPR_UNUSED(encode);
#endif
switch (format->wFormatTag)
{
case WAVE_FORMAT_PCM:

View File

@ -375,16 +375,16 @@ static BOOL openh264_load_functionpointers(H264_CONTEXT* h264, const char* name)
if (!sysContexts)
return FALSE;
sysContexts->lib = sysContexts->lib = LoadLibraryA(name);
sysContexts->lib = LoadLibraryA(name);
if (!sysContexts->lib)
return FALSE;
sysContexts->WelsGetCodecVersionEx = GetProcAddress(sysContexts->lib, "WelsGetCodecVersionEx");
sysContexts->WelsCreateDecoder = GetProcAddress(sysContexts->lib, "WelsCreateDecoder");
sysContexts->WelsDestroyDecoder = GetProcAddress(sysContexts->lib, "WelsDestroyDecoder");
sysContexts->WelsCreateSVCEncoder = GetProcAddress(sysContexts->lib, "WelsCreateSVCEncoder");
sysContexts->WelsDestroySVCEncoder = GetProcAddress(sysContexts->lib, "WelsDestroySVCEncoder");
sysContexts->WelsGetCodecVersionEx = (pWelsGetCodecVersionEx) GetProcAddress(sysContexts->lib, "WelsGetCodecVersionEx");
sysContexts->WelsCreateDecoder = (pWelsCreateDecoder) GetProcAddress(sysContexts->lib, "WelsCreateDecoder");
sysContexts->WelsDestroyDecoder = (pWelsDestroyDecoder) GetProcAddress(sysContexts->lib, "WelsDestroyDecoder");
sysContexts->WelsCreateSVCEncoder = (pWelsCreateSVCEncoder) GetProcAddress(sysContexts->lib, "WelsCreateSVCEncoder");
sysContexts->WelsDestroySVCEncoder = (pWelsDestroySVCEncoder) GetProcAddress(sysContexts->lib, "WelsDestroySVCEncoder");
if (!sysContexts->WelsCreateDecoder || !sysContexts->WelsDestroyDecoder ||
!sysContexts->WelsCreateSVCEncoder || !sysContexts->WelsDestroySVCEncoder ||

View File

@ -453,6 +453,16 @@ UWAC_API void* UwacWindowGetDrawingBuffer(UwacWindow* window);
UWAC_API UwacReturnCode UwacWindowAddDamage(UwacWindow* window, uint32_t x, uint32_t y,
uint32_t width, uint32_t height);
/**
* returns the geometry of the given UwacWindow buffer
*
* @param window the UwacWindow
* @param geometry the geometry to fill
* @param stride the length of a buffer line in bytes
* @return UWAC_SUCCESS on success, an Uwac error otherwise
*/
UWAC_API UwacReturnCode UwacWindowGetDrawingBufferGeometry(UwacWindow* window, UwacSize* geometry, size_t* stride);
/**
* Sends a frame to the compositor with the content of the drawing buffer
*

View File

@ -150,6 +150,9 @@ UwacReturnCode UwacSeatRegisterClipboard(UwacSeat* s)
if (!s)
return UWAC_ERROR_INTERNAL;
if (!s->display->data_device_manager || !s->data_device)
return UWAC_NOT_ENOUGH_RESOURCES;
UwacRegisterDeviceListener(s);
rc = UwacCreateDataSource(s);

View File

@ -147,7 +147,8 @@ static void UwacSeatRegisterDDM(UwacSeat *seat)
if (!d->data_device_manager)
return;
seat->data_device = wl_data_device_manager_get_data_device(d->data_device_manager, seat->seat);
if (!seat->data_device)
seat->data_device = wl_data_device_manager_get_data_device(d->data_device_manager, seat->seat);
}
static void registry_handle_global(void* data, struct wl_registry* registry, uint32_t id,
@ -222,6 +223,7 @@ static void registry_handle_global(void* data, struct wl_registry* registry, uin
wl_list_for_each(seat, &d->seats, link)
{
UwacSeatRegisterDDM(seat);
UwacSeatRegisterClipboard(seat);
}
}
else if (strcmp(interface, "wl_shell") == 0)

View File

@ -223,7 +223,6 @@ struct uwac_window {
struct wl_region *opaque_region;
struct wl_region *input_region;
struct wl_callback *frame_callback;
UwacBuffer *drawingBuffer, *pendingBuffer;
struct wl_surface *surface;
struct wl_shell_surface *shell_surface;

View File

@ -515,9 +515,6 @@ UwacReturnCode UwacDestroyWindow(UwacWindow** pwindow)
w = *pwindow;
UwacWindowDestroyBuffers(w);
if (w->frame_callback)
wl_callback_destroy(w->frame_callback);
if (w->deco)
zxdg_toplevel_decoration_v1_destroy(w->deco);
@ -607,6 +604,7 @@ static void UwacSubmitBufferPtr(UwacWindow* window, UwacBuffer* buffer)
const RECTANGLE_16* box;
#endif
wl_surface_attach(window->surface, buffer->wayland_buffer, 0, 0);
#if 0
#ifdef HAVE_PIXMAN_REGION
box = pixman_region32_rectangles(&buffer->damage, &nrects);
@ -621,12 +619,11 @@ static void UwacSubmitBufferPtr(UwacWindow* window, UwacBuffer* buffer)
(box->bottom - box->top));
#endif
if (window->frame_callback)
wl_callback_destroy(window->frame_callback);
window->frame_callback = wl_surface_frame(window->surface);
wl_callback_add_listener(window->frame_callback, &frame_listener, window);
#else
wl_surface_damage(window->surface, 0, 0, window->width, window->height);
#endif
struct wl_callback* frame_callback = wl_surface_frame(window->surface);
wl_callback_add_listener(frame_callback, &frame_listener, window);
wl_surface_commit(window->surface);
#ifdef HAVE_PIXMAN_REGION
pixman_region32_clear(&buffer->damage);
@ -640,6 +637,8 @@ static void frame_done_cb(void* data, struct wl_callback* callback, uint32_t tim
{
UwacWindow* window = (UwacWindow*)data;
UwacFrameDoneEvent* event;
wl_callback_destroy(callback);
window->pendingBuffer = NULL;
event = (UwacFrameDoneEvent*)UwacDisplayNewEvent(window->display, UWAC_EVENT_FRAME_DONE);
@ -670,20 +669,30 @@ UwacReturnCode UwacWindowAddDamage(UwacWindow* window, uint32_t x, uint32_t y, u
return UWAC_SUCCESS;
}
UwacReturnCode UwacWindowGetDrawingBufferGeometry(UwacWindow* window, UwacSize* geometry, size_t* stride)
{
if (!window || !window->drawingBuffer)
return UWAC_ERROR_INTERNAL;
if (geometry)
{
geometry->width = window->width;
geometry->height = window->height;
}
if (stride)
*stride = window->stride;
return UWAC_SUCCESS;
}
UwacReturnCode UwacWindowSubmitBuffer(UwacWindow* window, bool copyContentForNextFrame)
{
UwacBuffer* drawingBuffer = window->drawingBuffer;
if (window->pendingBuffer)
{
/* we already have a pending frame. resubmit as the buffer
* might have been discarded due to focus loss */
UwacSubmitBufferPtr(window, window->pendingBuffer);
return UWAC_SUCCESS;
}
UwacSubmitBufferPtr(window, drawingBuffer);
window->pendingBuffer = window->drawingBuffer;
window->drawingBuffer = UwacWindowFindFreeBuffer(window);
@ -691,10 +700,9 @@ UwacReturnCode UwacWindowSubmitBuffer(UwacWindow* window, bool copyContentForNex
return UWAC_ERROR_NOMEMORY;
if (copyContentForNextFrame)
{
memcpy(window->drawingBuffer->data, window->pendingBuffer->data, window->stride * window->height);
}
UwacSubmitBufferPtr(window, drawingBuffer);
return UWAC_SUCCESS;
}