2014-06-04 08:51:28 +08:00
|
|
|
/**
|
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
|
|
|
* Graphics Pipeline Extension
|
|
|
|
*
|
|
|
|
* Copyright 2014 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
2015-06-09 21:22:26 +08:00
|
|
|
* Copyright 2015 Thincast Technologies GmbH
|
|
|
|
* Copyright 2015 DI (FH) Martin Haimberger <martin.haimberger@thincast.com>
|
2014-06-04 08:51:28 +08:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2022-02-16 18:20:38 +08:00
|
|
|
#include <freerdp/config.h>
|
2014-06-04 08:51:28 +08:00
|
|
|
|
|
|
|
#include <winpr/crt.h>
|
|
|
|
#include <winpr/stream.h>
|
2014-09-12 22:19:32 +08:00
|
|
|
#include <freerdp/log.h>
|
2017-02-15 22:34:50 +08:00
|
|
|
#include <freerdp/utils/profiler.h>
|
2014-06-04 08:51:28 +08:00
|
|
|
|
2014-07-09 05:16:13 +08:00
|
|
|
#include "rdpgfx_common.h"
|
|
|
|
|
2014-06-04 08:51:28 +08:00
|
|
|
#include "rdpgfx_codec.h"
|
|
|
|
|
2014-09-12 22:19:32 +08:00
|
|
|
#define TAG CHANNELS_TAG("rdpgfx.client")
|
|
|
|
|
2015-08-27 20:25:09 +08:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2019-11-06 22:24:51 +08:00
|
|
|
static UINT rdpgfx_read_h264_metablock(RDPGFX_PLUGIN* gfx, wStream* s, RDPGFX_H264_METABLOCK* meta)
|
2014-07-09 05:16:13 +08:00
|
|
|
{
|
|
|
|
UINT32 index;
|
2016-03-02 21:39:36 +08:00
|
|
|
RECTANGLE_16* regionRect;
|
2014-07-09 05:16:13 +08:00
|
|
|
RDPGFX_H264_QUANT_QUALITY* quantQualityVal;
|
2015-09-03 18:00:22 +08:00
|
|
|
UINT error = ERROR_INVALID_DATA;
|
2014-12-07 07:27:06 +08:00
|
|
|
meta->regionRects = NULL;
|
|
|
|
meta->quantQualityVals = NULL;
|
|
|
|
|
2022-04-19 20:29:17 +08:00
|
|
|
if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
|
2015-09-03 18:00:22 +08:00
|
|
|
goto error_out;
|
2014-07-09 05:16:13 +08:00
|
|
|
|
2014-07-09 05:37:29 +08:00
|
|
|
Stream_Read_UINT32(s, meta->numRegionRects); /* numRegionRects (4 bytes) */
|
2014-07-09 05:16:13 +08:00
|
|
|
|
2023-01-24 21:53:36 +08:00
|
|
|
if (!Stream_CheckAndLogRequiredLengthOfSize(TAG, s, meta->numRegionRects, 8ull))
|
2015-09-03 18:00:22 +08:00
|
|
|
goto error_out;
|
2014-07-09 05:16:13 +08:00
|
|
|
|
2019-11-06 22:24:51 +08:00
|
|
|
meta->regionRects = (RECTANGLE_16*)calloc(meta->numRegionRects, sizeof(RECTANGLE_16));
|
2014-07-09 05:16:13 +08:00
|
|
|
|
2014-07-09 05:37:29 +08:00
|
|
|
if (!meta->regionRects)
|
2015-06-09 21:22:26 +08:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "malloc failed!");
|
2015-09-03 18:00:22 +08:00
|
|
|
error = CHANNEL_RC_NO_MEMORY;
|
|
|
|
goto error_out;
|
2015-06-09 21:22:26 +08:00
|
|
|
}
|
2014-07-09 05:16:13 +08:00
|
|
|
|
2019-11-06 22:24:51 +08:00
|
|
|
meta->quantQualityVals =
|
|
|
|
(RDPGFX_H264_QUANT_QUALITY*)calloc(meta->numRegionRects, sizeof(RDPGFX_H264_QUANT_QUALITY));
|
2014-07-09 05:37:29 +08:00
|
|
|
|
|
|
|
if (!meta->quantQualityVals)
|
2015-06-09 21:22:26 +08:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "malloc failed!");
|
|
|
|
error = CHANNEL_RC_NO_MEMORY;
|
|
|
|
goto error_out;
|
|
|
|
}
|
2014-07-09 05:16:13 +08:00
|
|
|
|
2019-11-06 22:24:51 +08:00
|
|
|
WLog_DBG(TAG, "H264_METABLOCK: numRegionRects: %" PRIu32 "", meta->numRegionRects);
|
2014-07-09 05:37:29 +08:00
|
|
|
|
|
|
|
for (index = 0; index < meta->numRegionRects; index++)
|
2014-07-09 05:16:13 +08:00
|
|
|
{
|
2014-07-09 05:37:29 +08:00
|
|
|
regionRect = &(meta->regionRects[index]);
|
2017-02-15 22:34:50 +08:00
|
|
|
|
2015-06-09 21:22:26 +08:00
|
|
|
if ((error = rdpgfx_read_rect16(s, regionRect)))
|
|
|
|
{
|
2019-11-06 22:24:51 +08:00
|
|
|
WLog_ERR(TAG, "rdpgfx_read_rect16 failed with error %" PRIu32 "!", error);
|
2015-06-09 21:22:26 +08:00
|
|
|
goto error_out;
|
|
|
|
}
|
2017-02-15 22:34:50 +08:00
|
|
|
|
|
|
|
WLog_DBG(TAG,
|
2019-11-06 22:24:51 +08:00
|
|
|
"regionRects[%" PRIu32 "]: left: %" PRIu16 " top: %" PRIu16 " right: %" PRIu16
|
|
|
|
" bottom: %" PRIu16 "",
|
2017-02-15 22:34:50 +08:00
|
|
|
index, regionRect->left, regionRect->top, regionRect->right, regionRect->bottom);
|
2014-07-09 05:16:13 +08:00
|
|
|
}
|
|
|
|
|
2023-01-24 21:53:36 +08:00
|
|
|
if (!Stream_CheckAndLogRequiredLengthOfSize(TAG, s, meta->numRegionRects, 2ull))
|
2015-06-09 21:22:26 +08:00
|
|
|
{
|
2015-09-03 18:00:22 +08:00
|
|
|
error = ERROR_INVALID_DATA;
|
|
|
|
goto error_out;
|
2015-06-09 21:22:26 +08:00
|
|
|
}
|
2014-07-09 05:37:29 +08:00
|
|
|
|
|
|
|
for (index = 0; index < meta->numRegionRects; index++)
|
2014-07-09 05:16:13 +08:00
|
|
|
{
|
2014-07-09 05:37:29 +08:00
|
|
|
quantQualityVal = &(meta->quantQualityVals[index]);
|
2019-11-06 22:24:51 +08:00
|
|
|
Stream_Read_UINT8(s, quantQualityVal->qpVal); /* qpVal (1 byte) */
|
2014-07-09 05:16:13 +08:00
|
|
|
Stream_Read_UINT8(s, quantQualityVal->qualityVal); /* qualityVal (1 byte) */
|
|
|
|
quantQualityVal->qp = quantQualityVal->qpVal & 0x3F;
|
|
|
|
quantQualityVal->r = (quantQualityVal->qpVal >> 6) & 1;
|
|
|
|
quantQualityVal->p = (quantQualityVal->qpVal >> 7) & 1;
|
2017-02-15 22:34:50 +08:00
|
|
|
WLog_DBG(TAG,
|
2019-11-06 22:24:51 +08:00
|
|
|
"quantQualityVals[%" PRIu32 "]: qp: %" PRIu8 " r: %" PRIu8 " p: %" PRIu8
|
|
|
|
" qualityVal: %" PRIu8 "",
|
|
|
|
index, quantQualityVal->qp, quantQualityVal->r, quantQualityVal->p,
|
|
|
|
quantQualityVal->qualityVal);
|
2014-07-09 05:16:13 +08:00
|
|
|
}
|
|
|
|
|
2015-06-09 21:22:26 +08:00
|
|
|
return CHANNEL_RC_OK;
|
|
|
|
error_out:
|
2020-11-20 19:37:21 +08:00
|
|
|
free_h264_metablock(meta);
|
2015-06-09 21:22:26 +08:00
|
|
|
return error;
|
2014-07-09 05:16:13 +08:00
|
|
|
}
|
|
|
|
|
2015-08-27 20:25:09 +08:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-03-02 22:16:49 +08:00
|
|
|
static UINT rdpgfx_decode_AVC420(RDPGFX_PLUGIN* gfx, RDPGFX_SURFACE_COMMAND* cmd)
|
2014-06-04 08:51:28 +08:00
|
|
|
{
|
2015-08-27 20:25:09 +08:00
|
|
|
UINT error;
|
2014-07-09 05:16:13 +08:00
|
|
|
wStream* s;
|
2016-03-02 22:16:49 +08:00
|
|
|
RDPGFX_AVC420_BITMAP_STREAM h264;
|
2022-06-21 14:09:00 +08:00
|
|
|
RdpgfxClientContext* context = gfx->context;
|
Fix for #4330
Since ec027bf dynamic resolution is broken when used with egfx. Before that commit
we were tracking a server sent resize by setting a DesktopResize callback. This callback
is called when the desktop is resized by the server. Anyway the problem was that when this
callback is called, the activation sequence is not always completed, which were leading to
some freeze with 2012r2 servers (sending packets before the sequence is finished).
So with the faulty commit, we are tracking server resizes by subscribing to the Actived
event, that is called at the end of a reactivation sequence, so we're sure to not send packets
when not fully activated.
Anyway the issue that shows on (#4330) is that when you use egfx, no reactivation sequence happens,
the server only sends a ResetGraphics message with the new size, and so we miss the resized event.
This fix introduces a new GraphicsReset event, makes the display channel subscribe to that event,
and react accordingly.
2017-12-23 20:50:54 +08:00
|
|
|
s = Stream_New(cmd->data, cmd->length);
|
2018-08-22 19:11:28 +08:00
|
|
|
|
2014-07-09 05:37:29 +08:00
|
|
|
if (!s)
|
2015-06-09 21:22:26 +08:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Stream_New failed!");
|
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
|
|
|
}
|
2014-07-09 05:37:29 +08:00
|
|
|
|
2015-06-09 21:22:26 +08:00
|
|
|
if ((error = rdpgfx_read_h264_metablock(gfx, s, &(h264.meta))))
|
2014-11-17 06:26:56 +08:00
|
|
|
{
|
2018-08-17 19:47:24 +08:00
|
|
|
Stream_Free(s, FALSE);
|
2019-11-06 22:24:51 +08:00
|
|
|
WLog_ERR(TAG, "rdpgfx_read_h264_metablock failed with error %" PRIu32 "!", error);
|
2015-06-09 21:22:26 +08:00
|
|
|
return error;
|
2014-11-17 06:26:56 +08:00
|
|
|
}
|
2014-07-09 05:37:29 +08:00
|
|
|
|
|
|
|
h264.data = Stream_Pointer(s);
|
2019-11-06 22:24:51 +08:00
|
|
|
h264.length = (UINT32)Stream_GetRemainingLength(s);
|
2014-07-09 05:16:13 +08:00
|
|
|
Stream_Free(s, FALSE);
|
2019-11-06 22:24:51 +08:00
|
|
|
cmd->extra = (void*)&h264;
|
2014-07-09 05:37:29 +08:00
|
|
|
|
2015-06-09 21:22:26 +08:00
|
|
|
if (context)
|
2014-07-09 05:37:29 +08:00
|
|
|
{
|
2015-06-09 21:22:26 +08:00
|
|
|
IFCALLRET(context->SurfaceCommand, error, context, cmd);
|
2017-02-15 22:34:50 +08:00
|
|
|
|
2015-06-09 21:22:26 +08:00
|
|
|
if (error)
|
2019-11-06 22:24:51 +08:00
|
|
|
WLog_ERR(TAG, "context->SurfaceCommand failed with error %" PRIu32 "", error);
|
2014-07-09 05:37:29 +08:00
|
|
|
}
|
|
|
|
|
2020-11-20 19:37:21 +08:00
|
|
|
free_h264_metablock(&h264.meta);
|
2015-06-09 21:22:26 +08:00
|
|
|
return error;
|
2014-06-04 08:51:28 +08:00
|
|
|
}
|
|
|
|
|
2016-03-02 22:16:49 +08:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
static UINT rdpgfx_decode_AVC444(RDPGFX_PLUGIN* gfx, RDPGFX_SURFACE_COMMAND* cmd)
|
|
|
|
{
|
|
|
|
UINT error;
|
|
|
|
UINT32 tmp;
|
|
|
|
size_t pos1, pos2;
|
|
|
|
wStream* s;
|
2017-07-13 19:28:00 +08:00
|
|
|
RDPGFX_AVC444_BITMAP_STREAM h264 = { 0 };
|
2022-06-21 14:09:00 +08:00
|
|
|
RdpgfxClientContext* context = gfx->context;
|
2016-03-02 22:16:49 +08:00
|
|
|
s = Stream_New(cmd->data, cmd->length);
|
2018-08-22 19:11:28 +08:00
|
|
|
|
2016-03-02 22:16:49 +08:00
|
|
|
if (!s)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Stream_New failed!");
|
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
|
|
|
}
|
|
|
|
|
2022-04-19 20:29:17 +08:00
|
|
|
if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
|
2017-07-13 19:28:00 +08:00
|
|
|
{
|
|
|
|
error = ERROR_INVALID_DATA;
|
|
|
|
goto fail;
|
|
|
|
}
|
2018-08-22 19:11:28 +08:00
|
|
|
|
2016-03-02 22:16:49 +08:00
|
|
|
Stream_Read_UINT32(s, tmp);
|
|
|
|
h264.cbAvc420EncodedBitstream1 = tmp & 0x3FFFFFFFUL;
|
|
|
|
h264.LC = (tmp >> 30UL) & 0x03UL;
|
|
|
|
|
|
|
|
if (h264.LC == 0x03)
|
2017-07-13 19:28:00 +08:00
|
|
|
{
|
|
|
|
error = ERROR_INVALID_DATA;
|
|
|
|
goto fail;
|
|
|
|
}
|
2016-03-02 22:16:49 +08:00
|
|
|
|
|
|
|
pos1 = Stream_GetPosition(s);
|
2017-02-15 22:34:50 +08:00
|
|
|
|
2016-03-02 22:16:49 +08:00
|
|
|
if ((error = rdpgfx_read_h264_metablock(gfx, s, &(h264.bitstream[0].meta))))
|
|
|
|
{
|
2019-11-06 22:24:51 +08:00
|
|
|
WLog_ERR(TAG, "rdpgfx_read_h264_metablock failed with error %" PRIu32 "!", error);
|
2017-07-13 19:28:00 +08:00
|
|
|
goto fail;
|
2016-03-02 22:16:49 +08:00
|
|
|
}
|
|
|
|
|
2017-02-15 22:34:50 +08:00
|
|
|
pos2 = Stream_GetPosition(s);
|
2016-03-02 22:16:49 +08:00
|
|
|
h264.bitstream[0].data = Stream_Pointer(s);
|
|
|
|
|
|
|
|
if (h264.LC == 0)
|
|
|
|
{
|
|
|
|
tmp = h264.cbAvc420EncodedBitstream1 - pos2 + pos1;
|
2017-02-15 22:34:50 +08:00
|
|
|
|
2022-04-19 20:29:17 +08:00
|
|
|
if (!Stream_CheckAndLogRequiredLength(TAG, s, tmp))
|
2017-07-13 19:28:00 +08:00
|
|
|
{
|
|
|
|
error = ERROR_INVALID_DATA;
|
|
|
|
goto fail;
|
|
|
|
}
|
2016-03-02 22:16:49 +08:00
|
|
|
|
|
|
|
h264.bitstream[0].length = tmp;
|
|
|
|
Stream_Seek(s, tmp);
|
|
|
|
|
|
|
|
if ((error = rdpgfx_read_h264_metablock(gfx, s, &(h264.bitstream[1].meta))))
|
|
|
|
{
|
2019-11-06 22:24:51 +08:00
|
|
|
WLog_ERR(TAG, "rdpgfx_read_h264_metablock failed with error %" PRIu32 "!", error);
|
2017-07-13 19:28:00 +08:00
|
|
|
goto fail;
|
2016-03-02 22:16:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
h264.bitstream[1].data = Stream_Pointer(s);
|
|
|
|
h264.bitstream[1].length = Stream_GetRemainingLength(s);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
h264.bitstream[0].length = Stream_GetRemainingLength(s);
|
|
|
|
|
2019-11-06 22:24:51 +08:00
|
|
|
cmd->extra = (void*)&h264;
|
2016-03-02 22:16:49 +08:00
|
|
|
|
|
|
|
if (context)
|
|
|
|
{
|
|
|
|
IFCALLRET(context->SurfaceCommand, error, context, cmd);
|
2017-02-15 22:34:50 +08:00
|
|
|
|
2016-03-02 22:16:49 +08:00
|
|
|
if (error)
|
2019-11-06 22:24:51 +08:00
|
|
|
WLog_ERR(TAG, "context->SurfaceCommand failed with error %" PRIu32 "", error);
|
2016-03-02 22:16:49 +08:00
|
|
|
}
|
|
|
|
|
2017-07-13 19:28:00 +08:00
|
|
|
fail:
|
|
|
|
Stream_Free(s, FALSE);
|
2020-11-20 19:37:21 +08:00
|
|
|
free_h264_metablock(&h264.bitstream[0].meta);
|
|
|
|
free_h264_metablock(&h264.bitstream[1].meta);
|
2016-03-02 22:16:49 +08:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2015-08-27 20:25:09 +08:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
UINT rdpgfx_decode(RDPGFX_PLUGIN* gfx, RDPGFX_SURFACE_COMMAND* cmd)
|
2014-06-04 08:51:28 +08:00
|
|
|
{
|
2015-08-27 20:25:09 +08:00
|
|
|
UINT error = CHANNEL_RC_OK;
|
2022-06-21 14:09:00 +08:00
|
|
|
RdpgfxClientContext* context = gfx->context;
|
2018-02-15 17:19:15 +08:00
|
|
|
PROFILER_ENTER(context->SurfaceProfiler)
|
2014-06-04 08:51:28 +08:00
|
|
|
|
|
|
|
switch (cmd->codecId)
|
|
|
|
{
|
2016-03-02 22:16:49 +08:00
|
|
|
case RDPGFX_CODECID_AVC420:
|
|
|
|
if ((error = rdpgfx_decode_AVC420(gfx, cmd)))
|
2019-11-06 22:24:51 +08:00
|
|
|
WLog_ERR(TAG, "rdpgfx_decode_AVC420 failed with error %" PRIu32 "", error);
|
2017-02-15 22:34:50 +08:00
|
|
|
|
2016-03-02 22:16:49 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case RDPGFX_CODECID_AVC444:
|
2017-04-10 23:16:57 +08:00
|
|
|
case RDPGFX_CODECID_AVC444v2:
|
2016-03-02 22:16:49 +08:00
|
|
|
if ((error = rdpgfx_decode_AVC444(gfx, cmd)))
|
2019-11-06 22:24:51 +08:00
|
|
|
WLog_ERR(TAG, "rdpgfx_decode_AVC444 failed with error %" PRIu32 "", error);
|
2017-02-15 22:34:50 +08:00
|
|
|
|
2014-06-04 08:51:28 +08:00
|
|
|
break;
|
|
|
|
|
2015-09-03 18:00:22 +08:00
|
|
|
default:
|
|
|
|
if (context)
|
2015-06-09 21:22:26 +08:00
|
|
|
{
|
2015-09-03 18:00:22 +08:00
|
|
|
IFCALLRET(context->SurfaceCommand, error, context, cmd);
|
2017-02-15 22:34:50 +08:00
|
|
|
|
2015-09-03 18:00:22 +08:00
|
|
|
if (error)
|
2019-11-06 22:24:51 +08:00
|
|
|
WLog_ERR(TAG, "context->SurfaceCommand failed with error %" PRIu32 "", error);
|
2015-06-09 21:22:26 +08:00
|
|
|
}
|
2017-02-15 22:34:50 +08:00
|
|
|
|
2014-06-04 08:51:28 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-02-15 17:19:15 +08:00
|
|
|
PROFILER_EXIT(context->SurfaceProfiler)
|
2015-06-09 21:22:26 +08:00
|
|
|
return error;
|
2014-06-04 08:51:28 +08:00
|
|
|
}
|