Merge pull request #10273 from akallabeth/rdpecam-fixups

Rdpecam fixups
This commit is contained in:
akallabeth 2024-06-12 11:03:23 +02:00 committed by GitHub
commit b73964beda
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 80 additions and 33 deletions

View File

@ -31,6 +31,8 @@ else()
message(FATAL_ERROR "libv4l-dev required for CHANNEL_RDPECAM_CLIENT")
endif()
include_directories(${SWScale_INCLUDE_DIR})
set(${MODULE_PREFIX}_SRCS
camera_device_enum_main.c
camera_device_main.c

View File

@ -84,7 +84,7 @@ UINT ecam_channel_write(CameraPlugin* ecam, GENERIC_CHANNEL_CALLBACK* hchannel,
return ERROR_INVALID_PARAMETER;
Stream_SealLength(out);
WINPR_ASSERT(Stream_Length(out) <= ULONG_MAX);
WINPR_ASSERT(Stream_Length(out) <= UINT32_MAX);
WLog_DBG(TAG, "ChannelId=%d, MessageId=0x%02" PRIx8 ", Length=%d",
hchannel->channel_mgr->GetChannelId(hchannel->channel), msg, Stream_Length(out));
@ -145,7 +145,11 @@ static UINT ecam_ihal_device_added_callback(CameraPlugin* ecam, GENERIC_CHANNEL_
if (!HashTable_ContainsKey(ecam->devices, deviceId))
{
CameraDevice* dev = ecam_dev_create(ecam, deviceId, deviceName);
HashTable_Insert(ecam->devices, deviceId, dev);
if (!HashTable_Insert(ecam->devices, deviceId, dev))
{
ecam_dev_destroy(dev);
return ERROR_INTERNAL_ERROR;
}
}
else
{

View File

@ -53,6 +53,7 @@ typedef struct
int fd;
size_t nBuffers;
CamV4lBuffer* buffers;
HANDLE captureThread;
} CamV4lStream;
@ -64,6 +65,10 @@ typedef struct
} CamV4lHal;
static void cam_v4l_stream_free(void* obj);
static void cam_v4l_stream_close_device(CamV4lStream* stream);
static UINT cam_v4l_stream_stop(CamV4lStream* stream);
/**
* Function description
*
@ -71,7 +76,7 @@ typedef struct
*/
static const char* cam_v4l_get_fourcc_str(unsigned int fourcc)
{
static char buf[5];
static char buf[5] = { 0 };
buf[0] = (fourcc & 0xFF);
buf[1] = (fourcc >> 8) & 0xFF;
buf[2] = (fourcc >> 16) & 0xFF;
@ -447,7 +452,7 @@ static UINT cam_v4l_stream_capture_thread(void* param)
*
* @return void
*/
static void cam_v4l_stream_close_device(CamV4lStream* stream)
void cam_v4l_stream_close_device(CamV4lStream* stream)
{
if (stream->fd != -1)
{
@ -492,13 +497,20 @@ static CamV4lStream* cam_v4l_stream_create(CameraDevice* dev, int streamIndex,
*
* @return 0 on success, otherwise a Win32 error code
*/
static UINT cam_v4l_stream_stop(CamV4lStream* stream)
UINT cam_v4l_stream_stop(CamV4lStream* stream)
{
if (!stream || !stream->streaming)
return CHANNEL_RC_OK;
stream->streaming = FALSE; /* this will terminate capture thread */
if (stream->captureThread)
{
WaitForSingleObject(stream->captureThread, INFINITE);
CloseHandle(stream->captureThread);
stream->captureThread = NULL;
}
EnterCriticalSection(&stream->lock);
/* stop streaming */
@ -536,7 +548,11 @@ static UINT cam_v4l_stream_start(ICamHal* ihal, CameraDevice* dev, int streamInd
if (!stream)
return CAM_ERROR_CODE_OutOfMemory;
HashTable_Insert(hal->streams, dev->deviceId, stream);
if (!HashTable_Insert(hal->streams, dev->deviceId, stream))
{
cam_v4l_stream_free(stream);
return CAM_ERROR_CODE_UnexpectedError;
}
}
if (stream->streaming)
@ -599,16 +615,7 @@ static UINT cam_v4l_stream_start(ICamHal* ihal, CameraDevice* dev, int streamInd
if (maxSample == 0)
{
WLog_ERR(TAG, "Failure to allocate video buffers");
cam_v4l_stream_close_device(stream);
return CAM_ERROR_CODE_OutOfMemory;
}
HANDLE captureThread = CreateThread(NULL, 0, cam_v4l_stream_capture_thread, stream, 0, NULL);
if (!captureThread)
{
WLog_ERR(TAG, "CreateThread failure");
cam_v4l_stream_free_buffers(stream);
cam_v4l_stream_close_device(stream);
cam_v4l_stream_stop(stream);
return CAM_ERROR_CODE_OutOfMemory;
}
@ -624,6 +631,14 @@ static UINT cam_v4l_stream_start(ICamHal* ihal, CameraDevice* dev, int streamInd
return CAM_ERROR_CODE_UnexpectedError;
}
stream->captureThread = CreateThread(NULL, 0, cam_v4l_stream_capture_thread, stream, 0, NULL);
if (!stream->captureThread)
{
WLog_ERR(TAG, "CreateThread failure");
cam_v4l_stream_stop(stream);
return CAM_ERROR_CODE_OutOfMemory;
}
WLog_INFO(TAG, "Camera format: %s, width: %d, height: %d, fps: %d",
cam_v4l_get_fourcc_str(pixelFormat), mediaType->Width, mediaType->Height,
mediaType->FrameRateNumerator);
@ -655,7 +670,7 @@ static UINT cam_v4l_stream_stop_by_device_id(ICamHal* ihal, const char* deviceId
*
* @return void
*/
static void cam_v4l_stream_free(void* obj)
void cam_v4l_stream_free(void* obj)
{
CamV4lStream* stream = (CamV4lStream*)obj;
if (!stream)
@ -712,7 +727,10 @@ FREERDP_ENTRY_POINT(
hal->streams = HashTable_New(FALSE);
if (!hal->streams)
return CHANNEL_RC_NO_MEMORY;
{
ret = CHANNEL_RC_NO_MEMORY;
goto error;
}
HashTable_SetupForStringData(hal->streams, FALSE);

View File

@ -45,14 +45,22 @@
#include <freerdp/server/cliprdr.h>
#include <freerdp/server/echo.h>
#include <freerdp/server/rdpdr.h>
#if defined(CHANNEL_RAIL_SERVER)
#include <freerdp/server/rdpei.h>
#endif
#include <freerdp/server/drdynvc.h>
#include <freerdp/server/remdesk.h>
#include <freerdp/server/encomsp.h>
#if defined(CHANNEL_RAIL_SERVER)
#include <freerdp/server/rail.h>
#endif
#include <freerdp/server/telemetry.h>
#if defined(CHANNEL_RDPGFX_SERVER)
#include <freerdp/server/rdpgfx.h>
#endif
#if defined(CHANNEL_DISP_SERVER)
#include <freerdp/server/disp.h>
#endif
#if defined(CHANNEL_RDPEMSC_SERVER)
#include <freerdp/server/rdpemsc.h>
@ -87,13 +95,21 @@ void freerdp_channels_dummy(void)
echo_server_context* echo = NULL;
RdpdrServerContext* rdpdr = NULL;
DrdynvcServerContext* drdynvc = NULL;
#if defined(CHANNEL_RDPEI_SERVER)
RdpeiServerContext* rdpei = NULL;
#endif
RemdeskServerContext* remdesk = NULL;
EncomspServerContext* encomsp = NULL;
#if defined(CHANNEL_RAIL_SERVER)
RailServerContext* rail = NULL;
#endif
TelemetryServerContext* telemetry = NULL;
#if defined(CHANNEL_RDPGFX_SERVER)
RdpgfxServerContext* rdpgfx = NULL;
#endif
#if defined(CHANNEL_DISP_SERVER)
DispServerContext* disp = NULL;
#endif
#if defined(CHANNEL_RDPEMSC_SERVER)
MouseCursorServerContext* mouse_cursor = NULL;
#endif /* CHANNEL_RDPEMSC_SERVER */
@ -123,21 +139,28 @@ void freerdp_channels_dummy(void)
rdpdr_server_context_free(rdpdr);
drdynvc = drdynvc_server_context_new(NULL);
drdynvc_server_context_free(drdynvc);
#if defined(CHANNEL_RDPEI_SERVER)
rdpei = rdpei_server_context_new(NULL);
rdpei_server_context_free(rdpei);
#endif
remdesk = remdesk_server_context_new(NULL);
remdesk_server_context_free(remdesk);
encomsp = encomsp_server_context_new(NULL);
encomsp_server_context_free(encomsp);
#if defined(CHANNEL_RAIL_SERVER)
rail = rail_server_context_new(NULL);
rail_server_context_free(rail);
#endif
telemetry = telemetry_server_context_new(NULL);
telemetry_server_context_free(telemetry);
#if defined(CHANNEL_RDPGFX_SERVER)
rdpgfx = rdpgfx_server_context_new(NULL);
rdpgfx_server_context_free(rdpgfx);
#endif
#if defined(CHANNEL_DISP_SERVER)
disp = disp_server_context_new(NULL);
disp_server_context_free(disp);
#endif
#if defined(CHANNEL_RDPEMSC_SERVER)
mouse_cursor = mouse_cursor_server_context_new(NULL);
mouse_cursor_server_context_free(mouse_cursor);

View File

@ -41,26 +41,16 @@ UINT shadow_client_channels_post_connect(rdpShadowClient* client)
shadow_client_audin_init(client);
if (freerdp_settings_get_bool(client->context.settings, FreeRDP_SupportGraphicsPipeline))
{
shadow_client_rdpgfx_init(client);
}
shadow_client_rdpgfx_init(client);
return CHANNEL_RC_OK;
}
void shadow_client_channels_free(rdpShadowClient* client)
{
if (freerdp_settings_get_bool(client->context.settings, FreeRDP_SupportGraphicsPipeline))
{
shadow_client_rdpgfx_uninit(client);
}
shadow_client_rdpgfx_uninit(client);
shadow_client_audin_uninit(client);
shadow_client_rdpsnd_uninit(client);
shadow_client_remdesk_uninit(client);
shadow_client_encomsp_uninit(client);
}

View File

@ -2196,10 +2196,12 @@ static DWORD WINAPI shadow_client_thread(LPVOID arg)
events[nCount++] = ChannelEvent;
events[nCount++] = MessageQueue_Event(MsgQueue);
#if defined(CHANNEL_RDPGFX_SERVER)
HANDLE gfxevent = rdpgfx_server_get_event_handle(client->rdpgfx);
if (gfxevent)
events[nCount++] = gfxevent;
#endif
status = WaitForMultipleObjects(nCount, events, FALSE, INFINITE);
@ -2329,6 +2331,7 @@ static DWORD WINAPI shadow_client_thread(LPVOID arg)
}
}
#if defined(CHANNEL_RDPGFX_SERVER)
if (gfxevent)
{
if (WaitForSingleObject(gfxevent, 0) == WAIT_OBJECT_0)
@ -2336,6 +2339,7 @@ static DWORD WINAPI shadow_client_thread(LPVOID arg)
rdpgfx_server_handle_messages(client->rdpgfx);
}
}
#endif
if (WaitForSingleObject(MessageQueue_Event(MsgQueue), 0) == WAIT_OBJECT_0)
{

View File

@ -29,11 +29,13 @@ int shadow_client_rdpgfx_init(rdpShadowClient* client)
{
WINPR_ASSERT(client);
if (!freerdp_settings_get_bool(client->context.settings, FreeRDP_SupportGraphicsPipeline))
return 1;
#if defined(CHANNEL_RDPGFX_SERVER)
RdpgfxServerContext* rdpgfx = client->rdpgfx = rdpgfx_server_context_new(client->vcm);
if (!rdpgfx)
{
return 0;
}
rdpgfx->rdpcontext = &client->context;
@ -41,15 +43,19 @@ int shadow_client_rdpgfx_init(rdpShadowClient* client)
if (!IFCALLRESULT(CHANNEL_RC_OK, rdpgfx->Initialize, rdpgfx, TRUE))
return -1;
#endif
return 1;
}
void shadow_client_rdpgfx_uninit(rdpShadowClient* client)
{
WINPR_ASSERT(client);
if (client->rdpgfx)
{
#if defined(CHANNEL_RDPGFX_SERVER)
rdpgfx_server_context_free(client->rdpgfx);
#endif
client->rdpgfx = NULL;
}
}