FreeRDP
server/rdpgfx_main.c File Reference
#include <freerdp/config.h>
#include <winpr/assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <winpr/crt.h>
#include <winpr/synch.h>
#include <winpr/thread.h>
#include <winpr/stream.h>
#include <freerdp/freerdp.h>
#include <freerdp/codec/color.h>
#include <freerdp/channels/wtsvc.h>
#include <freerdp/channels/log.h>
#include "rdpgfx_common.h"
#include "rdpgfx_main.h"

Macros

#define TAG   CHANNELS_TAG("rdpgfx.server")
 
#define RDPGFX_RESET_GRAPHICS_PDU_SIZE   340
 
#define checkCapsAreExchanged(context)    checkCapsAreExchangedInt(context, __FILE__, __func__, __LINE__)
 

Functions

static BOOL checkCapsAreExchangedInt (RdpgfxServerContext *context, const char *file, const char *fkt, size_t line)
 
static INLINE UINT32 rdpgfx_pdu_length (UINT32 dataLen)
 
static INLINE UINT rdpgfx_server_packet_init_header (wStream *s, UINT16 cmdId, UINT32 pduLength)
 
static INLINE BOOL rdpgfx_server_packet_complete_header (wStream *s, size_t start)
 
static UINT rdpgfx_server_packet_send (RdpgfxServerContext *context, wStream *s)
 
static wStreamrdpgfx_server_single_packet_new (wLog *log, UINT16 cmdId, UINT32 dataLen)
 
static INLINE UINT rdpgfx_server_single_packet_send (RdpgfxServerContext *context, wStream *s)
 
static UINT rdpgfx_send_caps_confirm_pdu (RdpgfxServerContext *context, const RDPGFX_CAPS_CONFIRM_PDU *capsConfirm)
 
static UINT rdpgfx_send_reset_graphics_pdu (RdpgfxServerContext *context, const RDPGFX_RESET_GRAPHICS_PDU *pdu)
 
static UINT rdpgfx_send_evict_cache_entry_pdu (RdpgfxServerContext *context, const RDPGFX_EVICT_CACHE_ENTRY_PDU *pdu)
 
static UINT rdpgfx_send_cache_import_reply_pdu (RdpgfxServerContext *context, const RDPGFX_CACHE_IMPORT_REPLY_PDU *pdu)
 
static UINT rdpgfx_process_cache_import_offer_pdu (RdpgfxServerContext *context, const RDPGFX_CACHE_IMPORT_OFFER_PDU *cacheImportOffer)
 
static UINT rdpgfx_send_create_surface_pdu (RdpgfxServerContext *context, const RDPGFX_CREATE_SURFACE_PDU *pdu)
 
static UINT rdpgfx_send_delete_surface_pdu (RdpgfxServerContext *context, const RDPGFX_DELETE_SURFACE_PDU *pdu)
 
static INLINE BOOL rdpgfx_write_start_frame_pdu (wStream *s, const RDPGFX_START_FRAME_PDU *pdu)
 
static INLINE BOOL rdpgfx_write_end_frame_pdu (wStream *s, const RDPGFX_END_FRAME_PDU *pdu)
 
static UINT rdpgfx_send_start_frame_pdu (RdpgfxServerContext *context, const RDPGFX_START_FRAME_PDU *pdu)
 
static UINT rdpgfx_send_end_frame_pdu (RdpgfxServerContext *context, const RDPGFX_END_FRAME_PDU *pdu)
 
static INLINE UINT32 rdpgfx_estimate_h264_avc420 (const RDPGFX_AVC420_BITMAP_STREAM *havc420)
 
static INLINE UINT32 rdpgfx_estimate_surface_command (const RDPGFX_SURFACE_COMMAND *cmd)
 
static INLINE UINT16 rdpgfx_surface_command_cmdid (const RDPGFX_SURFACE_COMMAND *cmd)
 
static UINT rdpgfx_write_h264_metablock (wLog *log, wStream *s, const RDPGFX_H264_METABLOCK *meta)
 
static INLINE UINT rdpgfx_write_h264_avc420 (wLog *log, wStream *s, RDPGFX_AVC420_BITMAP_STREAM *havc420)
 
static UINT rdpgfx_write_surface_command (wLog *log, wStream *s, const RDPGFX_SURFACE_COMMAND *cmd)
 
static UINT rdpgfx_send_surface_command (RdpgfxServerContext *context, const RDPGFX_SURFACE_COMMAND *cmd)
 
static UINT rdpgfx_send_surface_frame_command (RdpgfxServerContext *context, const RDPGFX_SURFACE_COMMAND *cmd, const RDPGFX_START_FRAME_PDU *startFrame, const RDPGFX_END_FRAME_PDU *endFrame)
 
static UINT rdpgfx_send_delete_encoding_context_pdu (RdpgfxServerContext *context, const RDPGFX_DELETE_ENCODING_CONTEXT_PDU *pdu)
 
static UINT rdpgfx_send_solid_fill_pdu (RdpgfxServerContext *context, const RDPGFX_SOLID_FILL_PDU *pdu)
 
static UINT rdpgfx_send_surface_to_surface_pdu (RdpgfxServerContext *context, const RDPGFX_SURFACE_TO_SURFACE_PDU *pdu)
 
static UINT rdpgfx_send_surface_to_cache_pdu (RdpgfxServerContext *context, const RDPGFX_SURFACE_TO_CACHE_PDU *pdu)
 
static UINT rdpgfx_send_cache_to_surface_pdu (RdpgfxServerContext *context, const RDPGFX_CACHE_TO_SURFACE_PDU *pdu)
 
static UINT rdpgfx_send_map_surface_to_output_pdu (RdpgfxServerContext *context, const RDPGFX_MAP_SURFACE_TO_OUTPUT_PDU *pdu)
 
static UINT rdpgfx_send_map_surface_to_window_pdu (RdpgfxServerContext *context, const RDPGFX_MAP_SURFACE_TO_WINDOW_PDU *pdu)
 
static UINT rdpgfx_send_map_surface_to_scaled_window_pdu (RdpgfxServerContext *context, const RDPGFX_MAP_SURFACE_TO_SCALED_WINDOW_PDU *pdu)
 
static UINT rdpgfx_recv_frame_acknowledge_pdu (RdpgfxServerContext *context, wStream *s)
 
static UINT rdpgfx_recv_cache_import_offer_pdu (RdpgfxServerContext *context, wStream *s)
 
static UINT rdpgfx_recv_caps_advertise_pdu (RdpgfxServerContext *context, wStream *s)
 
static UINT rdpgfx_recv_qoe_frame_acknowledge_pdu (RdpgfxServerContext *context, wStream *s)
 
static UINT rdpgfx_send_map_surface_to_scaled_output_pdu (RdpgfxServerContext *context, const RDPGFX_MAP_SURFACE_TO_SCALED_OUTPUT_PDU *pdu)
 
static UINT rdpgfx_server_receive_pdu (RdpgfxServerContext *context, wStream *s)
 
static BOOL rdpgfx_server_close (RdpgfxServerContext *context)
 
static DWORD WINAPI rdpgfx_server_thread_func (LPVOID arg)
 
static BOOL rdpgfx_server_open (RdpgfxServerContext *context)
 
static BOOL rdpgfx_server_initialize (RdpgfxServerContext *context, BOOL externalThread)
 
RdpgfxServerContext * rdpgfx_server_context_new (HANDLE vcm)
 
void rdpgfx_server_context_free (RdpgfxServerContext *context)
 
HANDLE rdpgfx_server_get_event_handle (RdpgfxServerContext *context)
 
UINT rdpgfx_server_handle_messages (RdpgfxServerContext *context)
 

Macro Definition Documentation

◆ checkCapsAreExchanged

#define checkCapsAreExchanged (   context)     checkCapsAreExchangedInt(context, __FILE__, __func__, __LINE__)

◆ RDPGFX_RESET_GRAPHICS_PDU_SIZE

#define RDPGFX_RESET_GRAPHICS_PDU_SIZE   340

◆ TAG

#define TAG   CHANNELS_TAG("rdpgfx.server")

FreeRDP: A Remote Desktop Protocol Implementation Graphics Pipeline Extension

Copyright 2016 Jiang Zihao zihao.nosp@m..jia.nosp@m.ng@ya.nosp@m.hoo..nosp@m.com

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.

Function Documentation

◆ checkCapsAreExchangedInt()

static BOOL checkCapsAreExchangedInt ( RdpgfxServerContext *  context,
const char *  file,
const char *  fkt,
size_t  line 
)
static
Here is the call graph for this function:

◆ rdpgfx_estimate_h264_avc420()

static INLINE UINT32 rdpgfx_estimate_h264_avc420 ( const RDPGFX_AVC420_BITMAP_STREAM havc420)
static

Function description Estimate RFX_AVC420_BITMAP_STREAM structure size in stream

Returns
estimated size
Here is the caller graph for this function:

◆ rdpgfx_estimate_surface_command()

static INLINE UINT32 rdpgfx_estimate_surface_command ( const RDPGFX_SURFACE_COMMAND cmd)
static

Function description Estimate surface command packet size in stream without header

Returns
estimated size
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rdpgfx_pdu_length()

static INLINE UINT32 rdpgfx_pdu_length ( UINT32  dataLen)
static

Function description Calculate packet size from data length. It would be data length + header.

Parameters
dataLenestimated data length without header
Returns
new stream
Here is the caller graph for this function:

◆ rdpgfx_process_cache_import_offer_pdu()

static UINT rdpgfx_process_cache_import_offer_pdu ( RdpgfxServerContext *  context,
const RDPGFX_CACHE_IMPORT_OFFER_PDU cacheImportOffer 
)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rdpgfx_recv_cache_import_offer_pdu()

static UINT rdpgfx_recv_cache_import_offer_pdu ( RdpgfxServerContext *  context,
wStream s 
)
static

Function description

Returns
0 on success, otherwise a Win32 error code
Here is the caller graph for this function:

◆ rdpgfx_recv_caps_advertise_pdu()

static UINT rdpgfx_recv_caps_advertise_pdu ( RdpgfxServerContext *  context,
wStream s 
)
static

Function description

Returns
0 on success, otherwise a Win32 error code
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rdpgfx_recv_frame_acknowledge_pdu()

static UINT rdpgfx_recv_frame_acknowledge_pdu ( RdpgfxServerContext *  context,
wStream s 
)
static

Function description

Returns
0 on success, otherwise a Win32 error code
Here is the caller graph for this function:

◆ rdpgfx_recv_qoe_frame_acknowledge_pdu()

static UINT rdpgfx_recv_qoe_frame_acknowledge_pdu ( RdpgfxServerContext *  context,
wStream s 
)
static

Function description

Returns
0 on success, otherwise a Win32 error code
Here is the caller graph for this function:

◆ rdpgfx_send_cache_import_reply_pdu()

static UINT rdpgfx_send_cache_import_reply_pdu ( RdpgfxServerContext *  context,
const RDPGFX_CACHE_IMPORT_REPLY_PDU pdu 
)
static

Function description

Returns
0 on success, otherwise a Win32 error code
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rdpgfx_send_cache_to_surface_pdu()

static UINT rdpgfx_send_cache_to_surface_pdu ( RdpgfxServerContext *  context,
const RDPGFX_CACHE_TO_SURFACE_PDU pdu 
)
static

Function description

Returns
0 on success, otherwise a Win32 error code
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rdpgfx_send_caps_confirm_pdu()

static UINT rdpgfx_send_caps_confirm_pdu ( RdpgfxServerContext *  context,
const RDPGFX_CAPS_CONFIRM_PDU capsConfirm 
)
static

Function description

Returns
0 on success, otherwise a Win32 error code
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rdpgfx_send_create_surface_pdu()

static UINT rdpgfx_send_create_surface_pdu ( RdpgfxServerContext *  context,
const RDPGFX_CREATE_SURFACE_PDU pdu 
)
static

Function description

Returns
0 on success, otherwise a Win32 error code
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rdpgfx_send_delete_encoding_context_pdu()

static UINT rdpgfx_send_delete_encoding_context_pdu ( RdpgfxServerContext *  context,
const RDPGFX_DELETE_ENCODING_CONTEXT_PDU pdu 
)
static

Function description

Returns
0 on success, otherwise a Win32 error code
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rdpgfx_send_delete_surface_pdu()

static UINT rdpgfx_send_delete_surface_pdu ( RdpgfxServerContext *  context,
const RDPGFX_DELETE_SURFACE_PDU pdu 
)
static

Function description

Returns
0 on success, otherwise a Win32 error code
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rdpgfx_send_end_frame_pdu()

static UINT rdpgfx_send_end_frame_pdu ( RdpgfxServerContext *  context,
const RDPGFX_END_FRAME_PDU pdu 
)
static

Function description

Returns
0 on success, otherwise a Win32 error code
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rdpgfx_send_evict_cache_entry_pdu()

static UINT rdpgfx_send_evict_cache_entry_pdu ( RdpgfxServerContext *  context,
const RDPGFX_EVICT_CACHE_ENTRY_PDU pdu 
)
static

Function description

Returns
0 on success, otherwise a Win32 error code
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rdpgfx_send_map_surface_to_output_pdu()

static UINT rdpgfx_send_map_surface_to_output_pdu ( RdpgfxServerContext *  context,
const RDPGFX_MAP_SURFACE_TO_OUTPUT_PDU pdu 
)
static

Function description

Returns
0 on success, otherwise a Win32 error code
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rdpgfx_send_map_surface_to_scaled_output_pdu()

static UINT rdpgfx_send_map_surface_to_scaled_output_pdu ( RdpgfxServerContext *  context,
const RDPGFX_MAP_SURFACE_TO_SCALED_OUTPUT_PDU pdu 
)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rdpgfx_send_map_surface_to_scaled_window_pdu()

static UINT rdpgfx_send_map_surface_to_scaled_window_pdu ( RdpgfxServerContext *  context,
const RDPGFX_MAP_SURFACE_TO_SCALED_WINDOW_PDU pdu 
)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rdpgfx_send_map_surface_to_window_pdu()

static UINT rdpgfx_send_map_surface_to_window_pdu ( RdpgfxServerContext *  context,
const RDPGFX_MAP_SURFACE_TO_WINDOW_PDU pdu 
)
static

Function description

Returns
0 on success, otherwise a Win32 error code
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rdpgfx_send_reset_graphics_pdu()

static UINT rdpgfx_send_reset_graphics_pdu ( RdpgfxServerContext *  context,
const RDPGFX_RESET_GRAPHICS_PDU pdu 
)
static

Function description

Returns
0 on success, otherwise a Win32 error code
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rdpgfx_send_solid_fill_pdu()

static UINT rdpgfx_send_solid_fill_pdu ( RdpgfxServerContext *  context,
const RDPGFX_SOLID_FILL_PDU pdu 
)
static

Function description

Returns
0 on success, otherwise a Win32 error code
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rdpgfx_send_start_frame_pdu()

static UINT rdpgfx_send_start_frame_pdu ( RdpgfxServerContext *  context,
const RDPGFX_START_FRAME_PDU pdu 
)
static

Function description

Returns
0 on success, otherwise a Win32 error code
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rdpgfx_send_surface_command()

static UINT rdpgfx_send_surface_command ( RdpgfxServerContext *  context,
const RDPGFX_SURFACE_COMMAND cmd 
)
static

Function description Send RDPGFX_CMDID_WIRETOSURFACE_1 or RDPGFX_CMDID_WIRETOSURFACE_2 message according to codecId

Returns
0 on success, otherwise a Win32 error code
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rdpgfx_send_surface_frame_command()

static UINT rdpgfx_send_surface_frame_command ( RdpgfxServerContext *  context,
const RDPGFX_SURFACE_COMMAND cmd,
const RDPGFX_START_FRAME_PDU startFrame,
const RDPGFX_END_FRAME_PDU endFrame 
)
static

Function description Send RDPGFX_CMDID_WIRETOSURFACE_1 or RDPGFX_CMDID_WIRETOSURFACE_2 message according to codecId. Prepend/append start/end frame message in same packet if exists.

Returns
0 on success, otherwise a Win32 error code
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rdpgfx_send_surface_to_cache_pdu()

static UINT rdpgfx_send_surface_to_cache_pdu ( RdpgfxServerContext *  context,
const RDPGFX_SURFACE_TO_CACHE_PDU pdu 
)
static

Function description

Returns
0 on success, otherwise a Win32 error code
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rdpgfx_send_surface_to_surface_pdu()

static UINT rdpgfx_send_surface_to_surface_pdu ( RdpgfxServerContext *  context,
const RDPGFX_SURFACE_TO_SURFACE_PDU pdu 
)
static

Function description

Returns
0 on success, otherwise a Win32 error code
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rdpgfx_server_close()

BOOL rdpgfx_server_close ( RdpgfxServerContext *  context)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rdpgfx_server_context_free()

void rdpgfx_server_context_free ( RdpgfxServerContext *  context)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rdpgfx_server_context_new()

RdpgfxServerContext* rdpgfx_server_context_new ( HANDLE  vcm)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rdpgfx_server_get_event_handle()

HANDLE rdpgfx_server_get_event_handle ( RdpgfxServerContext *  context)
Here is the caller graph for this function:

◆ rdpgfx_server_handle_messages()

UINT rdpgfx_server_handle_messages ( RdpgfxServerContext *  context)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rdpgfx_server_initialize()

static BOOL rdpgfx_server_initialize ( RdpgfxServerContext *  context,
BOOL  externalThread 
)
static
Here is the caller graph for this function:

◆ rdpgfx_server_open()

static BOOL rdpgfx_server_open ( RdpgfxServerContext *  context)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rdpgfx_server_packet_complete_header()

static INLINE BOOL rdpgfx_server_packet_complete_header ( wStream s,
size_t  start 
)
static

Function description Complete the rdpgfx packet header.

Parameters
sstream
startsaved start pos of the packet in the stream
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rdpgfx_server_packet_init_header()

static INLINE UINT rdpgfx_server_packet_init_header ( wStream s,
UINT16  cmdId,
UINT32  pduLength 
)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rdpgfx_server_packet_send()

static UINT rdpgfx_server_packet_send ( RdpgfxServerContext *  context,
wStream s 
)
static

Function description Send the stream for rdpgfx server packet. The packet would be compressed according to [MS-RDPEGFX].

Returns
0 on success, otherwise a Win32 error code
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rdpgfx_server_receive_pdu()

static UINT rdpgfx_server_receive_pdu ( RdpgfxServerContext *  context,
wStream s 
)
static

Function description

Returns
0 on success, otherwise a Win32 error code
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rdpgfx_server_single_packet_new()

static wStream* rdpgfx_server_single_packet_new ( wLog *  log,
UINT16  cmdId,
UINT32  dataLen 
)
static

Function description Create new stream for single rdpgfx packet. The new stream length would be required data length + header. The header will be written to the stream before return, but the pduLength field might be changed in rdpgfx_server_single_packet_send.

Parameters
cmdIdThe CommandID to write
dataLenestimated data length without header
Returns
new stream
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rdpgfx_server_single_packet_send()

static INLINE UINT rdpgfx_server_single_packet_send ( RdpgfxServerContext *  context,
wStream s 
)
static

Function description Send the stream for single rdpgfx packet. The header will be filled with actual length. The packet would be compressed according to [MS-RDPEGFX].

Returns
0 on success, otherwise a Win32 error code
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rdpgfx_server_thread_func()

static DWORD WINAPI rdpgfx_server_thread_func ( LPVOID  arg)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rdpgfx_surface_command_cmdid()

static INLINE UINT16 rdpgfx_surface_command_cmdid ( const RDPGFX_SURFACE_COMMAND cmd)
static

Function description Resolve RDPGFX_CMDID_WIRETOSURFACE_1 or RDPGFX_CMDID_WIRETOSURFACE_2 according to codecId

Returns
0 on success, otherwise a Win32 error code
Here is the caller graph for this function:

◆ rdpgfx_write_end_frame_pdu()

static INLINE BOOL rdpgfx_write_end_frame_pdu ( wStream s,
const RDPGFX_END_FRAME_PDU pdu 
)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rdpgfx_write_h264_avc420()

static INLINE UINT rdpgfx_write_h264_avc420 ( wLog *  log,
wStream s,
RDPGFX_AVC420_BITMAP_STREAM havc420 
)
static

Function description Write RFX_AVC420_BITMAP_STREAM structure to stream

Returns
0 on success, otherwise a Win32 error code
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rdpgfx_write_h264_metablock()

static UINT rdpgfx_write_h264_metablock ( wLog *  log,
wStream s,
const RDPGFX_H264_METABLOCK meta 
)
static

Function description

Returns
0 on success, otherwise a Win32 error code
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rdpgfx_write_start_frame_pdu()

static INLINE BOOL rdpgfx_write_start_frame_pdu ( wStream s,
const RDPGFX_START_FRAME_PDU pdu 
)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rdpgfx_write_surface_command()

static UINT rdpgfx_write_surface_command ( wLog *  log,
wStream s,
const RDPGFX_SURFACE_COMMAND cmd 
)
static

Function description Write RDPGFX_CMDID_WIRETOSURFACE_1 or RDPGFX_CMDID_WIRETOSURFACE_2 to the stream according to RDPGFX_SURFACE_COMMAND message

Returns
0 on success, otherwise a Win32 error code
Here is the call graph for this function:
Here is the caller graph for this function: