server: fix surface command types
authorNorbert Federa <norbert.federa@thincast.com>
Fri, 3 Apr 2020 12:04:12 +0000 (14:04 +0200)
committerakallabeth <akallabeth@users.noreply.github.com>
Fri, 3 Apr 2020 12:35:58 +0000 (14:35 +0200)
- Legacy RemoteFX is encapsulated in a "Stream Surface Bits Command" (CMDTYPE_STREAM_SURFACE_BITS)
- NSCodec is encapsulated in a "Set Surface Bits Command" (CMDTYPE_SET_SURFACE_BITS)

References:
- MS-RDPRFX 3.1.8.3.1 RemoteFX Stream / Encode Message Sequencing
- MS-RDPNSC 2.2.2 NSCodec Compressed Bitmap Stream

server/Sample/sfreerdp.c
server/shadow/shadow_client.c
server/shadow/shadow_encoder.c

index 73fe06d..bb9cc2d 100644 (file)
@@ -201,6 +201,7 @@ static BOOL test_peer_draw_background(freerdp_peer* client)
 
        if (client->settings->RemoteFxCodec)
        {
+               WLog_DBG(TAG, "Using RemoteFX codec");
                if (!rfx_compose_message(context->rfx_context, s, &rect, 1, rgb_data, rect.width,
                                         rect.height, rect.width * 3))
                {
@@ -208,15 +209,17 @@ static BOOL test_peer_draw_background(freerdp_peer* client)
                }
 
                cmd.bmp.codecID = client->settings->RemoteFxCodecId;
+               cmd.cmdType = CMDTYPE_STREAM_SURFACE_BITS;
        }
        else
        {
+               WLog_DBG(TAG, "Using NSCodec");
                nsc_compose_message(context->nsc_context, s, rgb_data, rect.width, rect.height,
                                    rect.width * 3);
                cmd.bmp.codecID = client->settings->NSCodecId;
+               cmd.cmdType = CMDTYPE_SET_SURFACE_BITS;
        }
 
-       cmd.cmdType = CMDTYPE_SET_SURFACE_BITS;
        cmd.destLeft = 0;
        cmd.destTop = 0;
        cmd.destRight = rect.width;
@@ -322,24 +325,28 @@ static void test_peer_draw_icon(freerdp_peer* client, int x, int y)
        rect.width = context->icon_width;
        rect.height = context->icon_height;
 
+       if (client->settings->RemoteFxCodec)
+       {
+               cmd.bmp.codecID = client->settings->RemoteFxCodecId;
+               cmd.cmdType = CMDTYPE_STREAM_SURFACE_BITS;
+       }
+       else
+       {
+               cmd.bmp.codecID = client->settings->NSCodecId;
+               cmd.cmdType = CMDTYPE_SET_SURFACE_BITS;
+       }
+
        if (context->icon_x >= 0)
        {
                s = test_peer_stream_init(context);
 
                if (client->settings->RemoteFxCodec)
-               {
                        rfx_compose_message(context->rfx_context, s, &rect, 1, context->bg_data, rect.width,
                                            rect.height, rect.width * 3);
-                       cmd.bmp.codecID = client->settings->RemoteFxCodecId;
-               }
                else
-               {
                        nsc_compose_message(context->nsc_context, s, context->bg_data, rect.width, rect.height,
                                            rect.width * 3);
-                       cmd.bmp.codecID = client->settings->NSCodecId;
-               }
 
-               cmd.cmdType = CMDTYPE_SET_SURFACE_BITS;
                cmd.destLeft = context->icon_x;
                cmd.destTop = context->icon_y;
                cmd.destRight = context->icon_x + context->icon_width;
@@ -356,19 +363,12 @@ static void test_peer_draw_icon(freerdp_peer* client, int x, int y)
        s = test_peer_stream_init(context);
 
        if (client->settings->RemoteFxCodec)
-       {
                rfx_compose_message(context->rfx_context, s, &rect, 1, context->icon_data, rect.width,
                                    rect.height, rect.width * 3);
-               cmd.bmp.codecID = client->settings->RemoteFxCodecId;
-       }
        else
-       {
                nsc_compose_message(context->nsc_context, s, context->icon_data, rect.width, rect.height,
                                    rect.width * 3);
-               cmd.bmp.codecID = client->settings->NSCodecId;
-       }
 
-       cmd.cmdType = CMDTYPE_SET_SURFACE_BITS;
        cmd.destLeft = x;
        cmd.destTop = y;
        cmd.destRight = x + context->icon_width;
@@ -790,6 +790,7 @@ static DWORD WINAPI test_peer_mainloop(LPVOID arg)
        /* client->settings->EncryptionLevel = ENCRYPTION_LEVEL_LOW; */
        /* client->settings->EncryptionLevel = ENCRYPTION_LEVEL_FIPS; */
        client->settings->RemoteFxCodec = TRUE;
+       client->settings->NSCodec = TRUE;
        client->settings->ColorDepth = 32;
        client->settings->SuppressOutput = TRUE;
        client->settings->RefreshRect = TRUE;
index 90cf632..3dded01 100644 (file)
@@ -976,7 +976,7 @@ static BOOL shadow_client_send_surface_bits(rdpShadowClient* client, BYTE* pSrcD
                        return FALSE;
                }
 
-               cmd.cmdType = CMDTYPE_SET_SURFACE_BITS;
+               cmd.cmdType = CMDTYPE_STREAM_SURFACE_BITS;
                cmd.bmp.codecID = settings->RemoteFxCodecId;
                cmd.destLeft = 0;
                cmd.destTop = 0;
index 35025be..030ef4e 100644 (file)
@@ -24,6 +24,8 @@
 
 #include "shadow_encoder.h"
 
+#define TAG CLIENT_TAG("shadow")
+
 int shadow_encoder_preferred_fps(rdpShadowEncoder* encoder)
 {
        /* Return preferred fps calculated according to the last
@@ -400,6 +402,7 @@ int shadow_encoder_prepare(rdpShadowEncoder* encoder, UINT32 codecs)
 
        if ((codecs & FREERDP_CODEC_REMOTEFX) && !(encoder->codecs & FREERDP_CODEC_REMOTEFX))
        {
+               WLog_DBG(TAG, "initializing RemoteFX encoder");
                status = shadow_encoder_init_rfx(encoder);
 
                if (status < 0)
@@ -408,6 +411,7 @@ int shadow_encoder_prepare(rdpShadowEncoder* encoder, UINT32 codecs)
 
        if ((codecs & FREERDP_CODEC_NSCODEC) && !(encoder->codecs & FREERDP_CODEC_NSCODEC))
        {
+               WLog_DBG(TAG, "initializing NSCodec encoder");
                status = shadow_encoder_init_nsc(encoder);
 
                if (status < 0)
@@ -416,6 +420,7 @@ int shadow_encoder_prepare(rdpShadowEncoder* encoder, UINT32 codecs)
 
        if ((codecs & FREERDP_CODEC_PLANAR) && !(encoder->codecs & FREERDP_CODEC_PLANAR))
        {
+               WLog_DBG(TAG, "initializing planar bitmap encoder");
                status = shadow_encoder_init_planar(encoder);
 
                if (status < 0)
@@ -424,6 +429,7 @@ int shadow_encoder_prepare(rdpShadowEncoder* encoder, UINT32 codecs)
 
        if ((codecs & FREERDP_CODEC_INTERLEAVED) && !(encoder->codecs & FREERDP_CODEC_INTERLEAVED))
        {
+               WLog_DBG(TAG, "initializing interleaved bitmap encoder");
                status = shadow_encoder_init_interleaved(encoder);
 
                if (status < 0)
@@ -433,6 +439,7 @@ int shadow_encoder_prepare(rdpShadowEncoder* encoder, UINT32 codecs)
        if ((codecs & (FREERDP_CODEC_AVC420 | FREERDP_CODEC_AVC444)) &&
            !(encoder->codecs & (FREERDP_CODEC_AVC420 | FREERDP_CODEC_AVC444)))
        {
+               WLog_DBG(TAG, "initializing H.264 encoder");
                status = shadow_encoder_init_h264(encoder);
 
                if (status < 0)