From 2cfdc16faed93a8d5d1ec391788547409df986de Mon Sep 17 00:00:00 2001 From: Ondrej Holy Date: Thu, 26 Mar 2026 15:57:28 +0100 Subject: [PATCH] [channels,video] unify error handling Partial backport of commit 635ae3c8193256db01774fab5ff11bcae57aed6b. Made-with: Cursor --- channels/video/client/video_main.c | 45 ++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/channels/video/client/video_main.c b/channels/video/client/video_main.c index a8031fc86..641231b1d 100644 --- a/channels/video/client/video_main.c +++ b/channels/video/client/video_main.c @@ -25,7 +25,9 @@ #include #include +#include #include +#include #include #include #include @@ -351,14 +353,24 @@ static void VideoClientContextPriv_free(VideoClientContextPriv* priv) free(priv); } +static UINT video_channel_write(VIDEO_PLUGIN* video, const BYTE* data, UINT32 length) +{ + WINPR_ASSERT(video); + + if (!video->control_callback || !video->control_callback->channel_callback) + return ERROR_BAD_CONFIGURATION; + IWTSVirtualChannel* channel = video->control_callback->channel_callback->channel; + if (!channel || !channel->Write) + return ERROR_BAD_CONFIGURATION; + return channel->Write(channel, length, data, NULL); +} + static UINT video_control_send_presentation_response(VideoClientContext* context, TSMM_PRESENTATION_RESPONSE* resp) { BYTE buf[12]; wStream* s; VIDEO_PLUGIN* video = (VIDEO_PLUGIN*)context->handle; - IWTSVirtualChannel* channel; - UINT ret; s = Stream_New(buf, 12); if (!s) @@ -370,11 +382,9 @@ static UINT video_control_send_presentation_response(VideoClientContext* context Stream_Zero(s, 3); Stream_SealLength(s); - channel = video->control_callback->channel_callback->channel; - ret = channel->Write(channel, 12, buf, NULL); Stream_Free(s, FALSE); - return ret; + return video_channel_write(video, buf, sizeof(buf)); } static BOOL video_onMappedGeometryUpdate(MAPPED_GEOMETRY* geometry) @@ -592,8 +602,6 @@ static UINT video_control_send_client_notification(VideoClientContext* context, BYTE buf[100]; wStream* s; VIDEO_PLUGIN* video = (VIDEO_PLUGIN*)context->handle; - IWTSVirtualChannel* channel; - UINT ret; UINT32 cbSize; s = Stream_New(buf, 30); @@ -627,10 +635,7 @@ static UINT video_control_send_client_notification(VideoClientContext* context, Stream_Write_UINT32(s, cbSize); Stream_Free(s, FALSE); - channel = video->control_callback->channel_callback->channel; - ret = channel->Write(channel, cbSize, buf, NULL); - - return ret; + return video_channel_write(video, buf, cbSize); } static void video_timer(VideoClientContext* video, UINT64 now) @@ -952,12 +957,30 @@ static UINT video_data_on_data_received(IWTSVirtualChannelCallback* pChannelCall */ static UINT video_control_on_close(IWTSVirtualChannelCallback* pChannelCallback) { + if (pChannelCallback) + { + VIDEO_LISTENER_CALLBACK* listener_callback = (VIDEO_LISTENER_CALLBACK*)pChannelCallback; + VIDEO_PLUGIN* video = (VIDEO_PLUGIN*)listener_callback->plugin; + if (video && video->control_callback) + { + video->control_callback->channel_callback = NULL; + } + } free(pChannelCallback); return CHANNEL_RC_OK; } static UINT video_data_on_close(IWTSVirtualChannelCallback* pChannelCallback) { + if (pChannelCallback) + { + VIDEO_LISTENER_CALLBACK* listener_callback = (VIDEO_LISTENER_CALLBACK*)pChannelCallback; + VIDEO_PLUGIN* video = (VIDEO_PLUGIN*)listener_callback->plugin; + if (video && video->data_callback) + { + video->data_callback->channel_callback = NULL; + } + } free(pChannelCallback); return CHANNEL_RC_OK; } -- 2.53.0