[channels,rdpecam] ensure sws context size matches

This commit is contained in:
akallabeth
2026-01-26 10:38:03 +01:00
parent 622bb7b440
commit d2d4f44931
4 changed files with 47 additions and 13 deletions

View File

@@ -121,6 +121,8 @@ typedef struct
#endif
/* sws_scale */
uint32_t swsWidth;
uint32_t swsHeight;
struct SwsContext* sws;
} CameraDeviceStream;

View File

@@ -121,7 +121,7 @@ static BOOL mediaSupportDrops(CAM_MEDIA_FORMAT format)
}
}
static UINT ecam_dev_send_pending(CameraDevice* dev, int streamIndex, CameraDeviceStream* stream)
static UINT ecam_dev_send_pending(CameraDevice* dev, size_t streamIndex, CameraDeviceStream* stream)
{
WINPR_ASSERT(dev);
WINPR_ASSERT(stream);
@@ -160,8 +160,7 @@ static UINT ecam_dev_send_pending(CameraDevice* dev, int streamIndex, CameraDevi
stream->samplesRequested--;
stream->haveSample = FALSE;
return ecam_dev_send_sample_response(dev, WINPR_ASSERTING_INT_CAST(size_t, streamIndex),
encodedSample, encodedSize);
return ecam_dev_send_sample_response(dev, streamIndex, encodedSample, encodedSize);
}
static UINT ecam_dev_sample_captured_callback(CameraDevice* dev, int streamIndex,
@@ -229,7 +228,7 @@ static UINT ecam_dev_sample_captured_callback(CameraDevice* dev, int streamIndex
Stream_SealLength(stream->pendingSample);
stream->haveSample = TRUE;
ret = ecam_dev_send_pending(dev, streamIndex, stream);
ret = ecam_dev_send_pending(dev, WINPR_ASSERTING_INT_CAST(size_t, streamIndex), stream);
out:
LeaveCriticalSection(&stream->lock);

View File

@@ -220,6 +220,30 @@ static enum AVPixelFormat ecamToAVPixFormat(CAM_MEDIA_FORMAT ecamFormat)
}
}
static void ecam_sws_free(CameraDeviceStream* stream)
{
if (stream->sws)
{
sws_freeContext(stream->sws);
stream->sws = NULL;
}
}
static BOOL ecam_sws_valid(const CameraDeviceStream* stream)
{
if (!stream->sws)
return FALSE;
if (stream->swsWidth != stream->currMediaType.Width)
return FALSE;
if (stream->swsHeight != stream->currMediaType.Height)
return FALSE;
if (stream->currMediaType.Width > INT32_MAX)
return FALSE;
if (stream->currMediaType.Height > INT32_MAX)
return FALSE;
return TRUE;
}
/**
* Function description
* initialize libswscale
@@ -230,9 +254,16 @@ static BOOL ecam_init_sws_context(CameraDeviceStream* stream, enum AVPixelFormat
{
WINPR_ASSERT(stream);
if (stream->sws)
if (stream->currMediaType.Width > INT32_MAX)
return FALSE;
if (stream->currMediaType.Height > INT32_MAX)
return FALSE;
if (ecam_sws_valid(stream))
return TRUE;
ecam_sws_free(stream);
/* replacing deprecated JPEG formats, still produced by decoder */
switch (pixFormat)
{
@@ -260,8 +291,10 @@ static BOOL ecam_init_sws_context(CameraDeviceStream* stream, enum AVPixelFormat
break;
}
const int width = (int)stream->currMediaType.Width;
const int height = (int)stream->currMediaType.Height;
stream->swsWidth = stream->currMediaType.Width;
stream->swsHeight = stream->currMediaType.Height;
const int width = WINPR_ASSERTING_INT_CAST(int, stream->currMediaType.Width);
const int height = WINPR_ASSERTING_INT_CAST(int, stream->currMediaType.Height);
const enum AVPixelFormat outPixFormat =
h264_context_get_option(stream->h264, H264_CONTEXT_OPTION_HW_ACCEL) ? AV_PIX_FMT_NV12
@@ -295,6 +328,9 @@ static BOOL ecam_encoder_compress_h264(CameraDeviceStream* stream, const BYTE* s
CAM_MEDIA_FORMAT inputFormat = streamInputFormat(stream);
enum AVPixelFormat pixFormat = AV_PIX_FMT_NONE;
if (!ecam_sws_valid(stream))
return FALSE;
#if defined(WITH_INPUT_FORMAT_H264)
if (inputFormat == CAM_MEDIA_FORMAT_MJPG_H264)
{
@@ -385,11 +421,7 @@ static void ecam_encoder_context_free_h264(CameraDeviceStream* stream)
{
WINPR_ASSERT(stream);
if (stream->sws)
{
sws_freeContext(stream->sws);
stream->sws = NULL;
}
ecam_sws_free(stream);
#if defined(WITH_INPUT_FORMAT_MJPG)
if (stream->avOutFrame)

View File

@@ -526,7 +526,8 @@ static DWORD WINAPI remdesk_server_thread(LPVOID arg)
Stream_SealLength(s);
Stream_SetPosition(s, 0);
if ((error = remdesk_server_receive_pdu(context, s)))
error = remdesk_server_receive_pdu(context, s);
if (error)
{
WLog_ERR(TAG, "remdesk_server_receive_pdu failed with error %" PRIu32 "!",
error);