2014-09-10 08:42:41 +04:00
|
|
|
/**
|
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
|
|
|
* RDP Codecs
|
|
|
|
*
|
|
|
|
* Copyright 2014 Marc-Andre Moreau <marcandre.moreau@gmail.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.
|
|
|
|
*/
|
|
|
|
|
2022-02-16 13:20:38 +03:00
|
|
|
#include <freerdp/config.h>
|
2014-09-10 08:42:41 +04:00
|
|
|
|
2021-09-17 10:09:48 +03:00
|
|
|
#include <winpr/assert.h>
|
|
|
|
|
2014-09-10 08:42:41 +04:00
|
|
|
#include "rdp.h"
|
|
|
|
|
|
|
|
#include <freerdp/codecs.h>
|
|
|
|
|
2015-04-28 18:00:41 +03:00
|
|
|
#define TAG FREERDP_TAG("core.codecs")
|
|
|
|
|
2022-06-21 10:25:54 +03:00
|
|
|
static void codecs_free_int(rdpCodecs* codecs, UINT32 flags)
|
2021-09-17 10:09:48 +03:00
|
|
|
{
|
|
|
|
WINPR_ASSERT(codecs);
|
2022-06-21 10:25:54 +03:00
|
|
|
|
|
|
|
if (flags & FREERDP_CODEC_REMOTEFX)
|
2021-09-17 10:09:48 +03:00
|
|
|
{
|
2022-06-21 10:25:54 +03:00
|
|
|
if (codecs->rfx)
|
|
|
|
{
|
|
|
|
rfx_context_free(codecs->rfx);
|
|
|
|
codecs->rfx = NULL;
|
|
|
|
}
|
2021-09-17 10:09:48 +03:00
|
|
|
}
|
|
|
|
|
2022-06-21 10:25:54 +03:00
|
|
|
if (flags & FREERDP_CODEC_NSCODEC)
|
2021-09-17 10:09:48 +03:00
|
|
|
{
|
2022-06-21 10:25:54 +03:00
|
|
|
if (codecs->nsc)
|
|
|
|
{
|
|
|
|
nsc_context_free(codecs->nsc);
|
|
|
|
codecs->nsc = NULL;
|
|
|
|
}
|
2021-09-17 10:09:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef WITH_GFX_H264
|
2022-06-21 10:25:54 +03:00
|
|
|
if (flags & (FREERDP_CODEC_AVC420 | FREERDP_CODEC_AVC444))
|
2021-09-17 10:09:48 +03:00
|
|
|
{
|
2022-06-21 10:25:54 +03:00
|
|
|
if (codecs->h264)
|
|
|
|
{
|
|
|
|
h264_context_free(codecs->h264);
|
|
|
|
codecs->h264 = NULL;
|
|
|
|
}
|
2021-09-17 10:09:48 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2022-06-21 10:25:54 +03:00
|
|
|
if (flags & FREERDP_CODEC_CLEARCODEC)
|
2021-09-17 10:09:48 +03:00
|
|
|
{
|
2022-06-21 10:25:54 +03:00
|
|
|
if (codecs->clear)
|
|
|
|
{
|
|
|
|
clear_context_free(codecs->clear);
|
|
|
|
codecs->clear = NULL;
|
|
|
|
}
|
2021-09-17 10:09:48 +03:00
|
|
|
}
|
|
|
|
|
2022-06-21 10:25:54 +03:00
|
|
|
if (flags & FREERDP_CODEC_PROGRESSIVE)
|
2021-09-17 10:09:48 +03:00
|
|
|
{
|
2022-06-21 10:25:54 +03:00
|
|
|
if (codecs->progressive)
|
|
|
|
{
|
|
|
|
progressive_context_free(codecs->progressive);
|
|
|
|
codecs->progressive = NULL;
|
|
|
|
}
|
2021-09-17 10:09:48 +03:00
|
|
|
}
|
|
|
|
|
2022-06-21 10:25:54 +03:00
|
|
|
if (flags & FREERDP_CODEC_PLANAR)
|
2021-09-17 10:09:48 +03:00
|
|
|
{
|
2022-06-21 10:25:54 +03:00
|
|
|
if (codecs->planar)
|
|
|
|
{
|
|
|
|
freerdp_bitmap_planar_context_free(codecs->planar);
|
|
|
|
codecs->planar = NULL;
|
|
|
|
}
|
2021-09-17 10:09:48 +03:00
|
|
|
}
|
|
|
|
|
2022-06-21 10:25:54 +03:00
|
|
|
if (flags & FREERDP_CODEC_INTERLEAVED)
|
2021-09-17 10:09:48 +03:00
|
|
|
{
|
2022-06-21 10:25:54 +03:00
|
|
|
if (codecs->interleaved)
|
|
|
|
{
|
|
|
|
bitmap_interleaved_context_free(codecs->interleaved);
|
|
|
|
codecs->interleaved = NULL;
|
|
|
|
}
|
2021-09-17 10:09:48 +03:00
|
|
|
}
|
|
|
|
}
|
2019-11-06 17:24:51 +03:00
|
|
|
BOOL freerdp_client_codecs_prepare(rdpCodecs* codecs, UINT32 flags, UINT32 width, UINT32 height)
|
2014-09-10 08:42:41 +04:00
|
|
|
{
|
2022-06-21 10:25:54 +03:00
|
|
|
codecs_free_int(codecs, flags);
|
2020-12-01 14:35:38 +03:00
|
|
|
if ((flags & FREERDP_CODEC_INTERLEAVED))
|
2014-09-10 08:42:41 +04:00
|
|
|
{
|
2015-04-28 18:00:41 +03:00
|
|
|
if (!(codecs->interleaved = bitmap_interleaved_context_new(FALSE)))
|
2014-09-10 08:42:41 +04:00
|
|
|
{
|
2015-04-28 18:00:41 +03:00
|
|
|
WLog_ERR(TAG, "Failed to create interleaved codec context");
|
|
|
|
return FALSE;
|
2014-09-10 08:42:41 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-01 14:35:38 +03:00
|
|
|
if ((flags & FREERDP_CODEC_PLANAR))
|
2014-09-10 08:42:41 +04:00
|
|
|
{
|
2023-05-16 11:33:47 +03:00
|
|
|
if (!(codecs->planar = freerdp_bitmap_planar_context_new(0, 64, 64)))
|
2014-09-10 08:42:41 +04:00
|
|
|
{
|
2015-04-28 18:00:41 +03:00
|
|
|
WLog_ERR(TAG, "Failed to create planar bitmap codec context");
|
|
|
|
return FALSE;
|
2014-09-10 08:42:41 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-01 14:35:38 +03:00
|
|
|
if ((flags & FREERDP_CODEC_NSCODEC))
|
2014-09-10 08:42:41 +04:00
|
|
|
{
|
2015-04-28 18:00:41 +03:00
|
|
|
if (!(codecs->nsc = nsc_context_new()))
|
2014-09-10 08:42:41 +04:00
|
|
|
{
|
2015-04-28 18:00:41 +03:00
|
|
|
WLog_ERR(TAG, "Failed to create nsc codec context");
|
|
|
|
return FALSE;
|
2014-09-10 08:42:41 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-01 14:35:38 +03:00
|
|
|
if ((flags & FREERDP_CODEC_REMOTEFX))
|
2014-09-10 08:42:41 +04:00
|
|
|
{
|
2024-05-29 14:39:17 +03:00
|
|
|
if (!(codecs->rfx = rfx_context_new_ex(FALSE, codecs->ThreadingFlags)))
|
2014-09-10 08:42:41 +04:00
|
|
|
{
|
2015-04-28 18:00:41 +03:00
|
|
|
WLog_ERR(TAG, "Failed to create rfx codec context");
|
|
|
|
return FALSE;
|
2014-09-10 08:42:41 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-01 14:35:38 +03:00
|
|
|
if ((flags & FREERDP_CODEC_CLEARCODEC))
|
2014-09-10 08:42:41 +04:00
|
|
|
{
|
2015-04-28 18:00:41 +03:00
|
|
|
if (!(codecs->clear = clear_context_new(FALSE)))
|
2014-09-10 08:42:41 +04:00
|
|
|
{
|
2015-04-28 18:00:41 +03:00
|
|
|
WLog_ERR(TAG, "Failed to create clear codec context");
|
|
|
|
return FALSE;
|
2014-09-10 08:42:41 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & FREERDP_CODEC_ALPHACODEC)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-12-01 14:35:38 +03:00
|
|
|
if ((flags & FREERDP_CODEC_PROGRESSIVE))
|
2014-09-10 08:42:41 +04:00
|
|
|
{
|
2024-05-29 14:39:17 +03:00
|
|
|
if (!(codecs->progressive = progressive_context_new_ex(FALSE, codecs->ThreadingFlags)))
|
2014-09-10 08:42:41 +04:00
|
|
|
{
|
2015-04-28 18:00:41 +03:00
|
|
|
WLog_ERR(TAG, "Failed to create progressive codec context");
|
|
|
|
return FALSE;
|
2014-09-10 08:42:41 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-17 11:37:15 +03:00
|
|
|
#ifdef WITH_GFX_H264
|
2020-12-01 14:35:38 +03:00
|
|
|
if ((flags & (FREERDP_CODEC_AVC420 | FREERDP_CODEC_AVC444)))
|
2014-09-10 08:42:41 +04:00
|
|
|
{
|
2015-04-28 18:00:41 +03:00
|
|
|
if (!(codecs->h264 = h264_context_new(FALSE)))
|
2014-09-10 08:42:41 +04:00
|
|
|
{
|
2021-12-02 17:50:08 +03:00
|
|
|
WLog_WARN(TAG, "Failed to create h264 codec context");
|
2014-09-10 08:42:41 +04:00
|
|
|
}
|
|
|
|
}
|
2017-07-17 11:37:15 +03:00
|
|
|
#endif
|
2014-09-10 08:42:41 +04:00
|
|
|
|
2016-07-14 17:08:06 +03:00
|
|
|
return freerdp_client_codecs_reset(codecs, flags, width, height);
|
2014-09-10 08:42:41 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
BOOL freerdp_client_codecs_reset(rdpCodecs* codecs, UINT32 flags, UINT32 width, UINT32 height)
|
2014-09-12 22:57:44 +04:00
|
|
|
{
|
2016-03-01 18:17:28 +03:00
|
|
|
BOOL rc = TRUE;
|
|
|
|
|
2014-09-12 22:57:44 +04:00
|
|
|
if (flags & FREERDP_CODEC_INTERLEAVED)
|
|
|
|
{
|
|
|
|
if (codecs->interleaved)
|
|
|
|
{
|
2016-03-01 18:17:28 +03:00
|
|
|
rc &= bitmap_interleaved_context_reset(codecs->interleaved);
|
2014-09-12 22:57:44 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & FREERDP_CODEC_PLANAR)
|
|
|
|
{
|
|
|
|
if (codecs->planar)
|
|
|
|
{
|
2016-04-14 00:18:55 +03:00
|
|
|
rc &= freerdp_bitmap_planar_context_reset(codecs->planar, width, height);
|
2014-09-12 22:57:44 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & FREERDP_CODEC_NSCODEC)
|
|
|
|
{
|
|
|
|
if (codecs->nsc)
|
|
|
|
{
|
2016-03-01 18:17:28 +03:00
|
|
|
rc &= nsc_context_reset(codecs->nsc, width, height);
|
2014-09-12 22:57:44 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & FREERDP_CODEC_REMOTEFX)
|
|
|
|
{
|
|
|
|
if (codecs->rfx)
|
|
|
|
{
|
2016-03-01 18:17:28 +03:00
|
|
|
rc &= rfx_context_reset(codecs->rfx, width, height);
|
2014-09-12 22:57:44 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & FREERDP_CODEC_CLEARCODEC)
|
|
|
|
{
|
|
|
|
if (codecs->clear)
|
|
|
|
{
|
2016-03-01 18:17:28 +03:00
|
|
|
rc &= clear_context_reset(codecs->clear);
|
2014-09-12 22:57:44 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & FREERDP_CODEC_ALPHACODEC)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & FREERDP_CODEC_PROGRESSIVE)
|
|
|
|
{
|
|
|
|
if (codecs->progressive)
|
|
|
|
{
|
2016-03-01 18:17:28 +03:00
|
|
|
rc &= progressive_context_reset(codecs->progressive);
|
2014-09-12 22:57:44 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-17 11:37:15 +03:00
|
|
|
#ifdef WITH_GFX_H264
|
2016-03-02 17:16:49 +03:00
|
|
|
if (flags & (FREERDP_CODEC_AVC420 | FREERDP_CODEC_AVC444))
|
2014-09-12 22:57:44 +04:00
|
|
|
{
|
|
|
|
if (codecs->h264)
|
|
|
|
{
|
2016-03-01 18:17:28 +03:00
|
|
|
rc &= h264_context_reset(codecs->h264, width, height);
|
2014-09-12 22:57:44 +04:00
|
|
|
}
|
|
|
|
}
|
2017-07-17 11:37:15 +03:00
|
|
|
#endif
|
2014-09-12 22:57:44 +04:00
|
|
|
|
2016-03-01 18:17:28 +03:00
|
|
|
return rc;
|
2014-09-12 22:57:44 +04:00
|
|
|
}
|
|
|
|
|
2014-09-10 08:42:41 +04:00
|
|
|
rdpCodecs* codecs_new(rdpContext* context)
|
|
|
|
{
|
2024-05-29 14:39:17 +03:00
|
|
|
if (!context || !context->settings)
|
|
|
|
return NULL;
|
2014-09-10 08:42:41 +04:00
|
|
|
|
2024-05-29 14:39:17 +03:00
|
|
|
const UINT32 flags = freerdp_settings_get_uint32(context->settings, FreeRDP_ThreadingFlags);
|
|
|
|
return freerdp_client_codecs_new(flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
void codecs_free(rdpCodecs* codecs)
|
|
|
|
{
|
|
|
|
freerdp_client_codecs_free(codecs);
|
|
|
|
}
|
|
|
|
|
|
|
|
rdpCodecs* freerdp_client_codecs_new(UINT32 ThreadingFlags)
|
|
|
|
{
|
|
|
|
rdpCodecs* codecs = (rdpCodecs*)calloc(1, sizeof(rdpCodecs));
|
|
|
|
|
|
|
|
if (!codecs)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
codecs->ThreadingFlags = ThreadingFlags;
|
2014-09-10 08:42:41 +04:00
|
|
|
|
|
|
|
return codecs;
|
|
|
|
}
|
|
|
|
|
2024-05-29 14:39:17 +03:00
|
|
|
void freerdp_client_codecs_free(rdpCodecs* codecs)
|
2014-09-10 08:42:41 +04:00
|
|
|
{
|
|
|
|
if (!codecs)
|
|
|
|
return;
|
|
|
|
|
2022-06-21 10:25:54 +03:00
|
|
|
codecs_free_int(codecs, FREERDP_CODEC_ALL);
|
2014-09-10 08:42:41 +04:00
|
|
|
|
|
|
|
free(codecs);
|
|
|
|
}
|