FreeRDP/libfreerdp/core/codecs.c

240 lines
4.6 KiB
C
Raw Normal View History

/**
* 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>
2021-09-17 10:09:48 +03:00
#include <winpr/assert.h>
#include "rdp.h"
#include <freerdp/codecs.h>
#define TAG FREERDP_TAG("core.codecs")
2021-09-17 10:09:48 +03:00
static void codecs_free_int(rdpCodecs* codecs)
{
WINPR_ASSERT(codecs);
if (codecs->rfx)
{
rfx_context_free(codecs->rfx);
codecs->rfx = NULL;
}
if (codecs->nsc)
{
nsc_context_free(codecs->nsc);
codecs->nsc = NULL;
}
#ifdef WITH_GFX_H264
if (codecs->h264)
{
h264_context_free(codecs->h264);
codecs->h264 = NULL;
}
#endif
if (codecs->clear)
{
clear_context_free(codecs->clear);
codecs->clear = NULL;
}
if (codecs->progressive)
{
progressive_context_free(codecs->progressive);
codecs->progressive = NULL;
}
if (codecs->planar)
{
freerdp_bitmap_planar_context_free(codecs->planar);
codecs->planar = NULL;
}
if (codecs->interleaved)
{
bitmap_interleaved_context_free(codecs->interleaved);
codecs->interleaved = NULL;
}
}
2019-11-06 17:24:51 +03:00
BOOL freerdp_client_codecs_prepare(rdpCodecs* codecs, UINT32 flags, UINT32 width, UINT32 height)
{
2021-09-17 10:09:48 +03:00
codecs_free_int(codecs);
2020-12-01 14:35:38 +03:00
if ((flags & FREERDP_CODEC_INTERLEAVED))
{
if (!(codecs->interleaved = bitmap_interleaved_context_new(FALSE)))
{
WLog_ERR(TAG, "Failed to create interleaved codec context");
return FALSE;
}
}
2020-12-01 14:35:38 +03:00
if ((flags & FREERDP_CODEC_PLANAR))
{
if (!(codecs->planar = freerdp_bitmap_planar_context_new(FALSE, 64, 64)))
{
WLog_ERR(TAG, "Failed to create planar bitmap codec context");
return FALSE;
}
}
2020-12-01 14:35:38 +03:00
if ((flags & FREERDP_CODEC_NSCODEC))
{
if (!(codecs->nsc = nsc_context_new()))
{
WLog_ERR(TAG, "Failed to create nsc codec context");
return FALSE;
}
}
2020-12-01 14:35:38 +03:00
if ((flags & FREERDP_CODEC_REMOTEFX))
{
if (!(codecs->rfx = rfx_context_new_ex(FALSE, codecs->context->settings->ThreadingFlags)))
{
WLog_ERR(TAG, "Failed to create rfx codec context");
return FALSE;
}
}
2020-12-01 14:35:38 +03:00
if ((flags & FREERDP_CODEC_CLEARCODEC))
{
if (!(codecs->clear = clear_context_new(FALSE)))
{
WLog_ERR(TAG, "Failed to create clear codec context");
return FALSE;
}
}
if (flags & FREERDP_CODEC_ALPHACODEC)
{
}
2020-12-01 14:35:38 +03:00
if ((flags & FREERDP_CODEC_PROGRESSIVE))
{
if (!(codecs->progressive = progressive_context_new(FALSE)))
{
WLog_ERR(TAG, "Failed to create progressive codec context");
return FALSE;
}
}
#ifdef WITH_GFX_H264
2020-12-01 14:35:38 +03:00
if ((flags & (FREERDP_CODEC_AVC420 | FREERDP_CODEC_AVC444)))
{
if (!(codecs->h264 = h264_context_new(FALSE)))
{
WLog_WARN(TAG, "Failed to create h264 codec context");
}
}
#endif
2016-07-14 17:08:06 +03:00
return freerdp_client_codecs_reset(codecs, flags, width, height);
}
2019-11-06 17:24:51 +03:00
BOOL freerdp_client_codecs_reset(rdpCodecs* codecs, UINT32 flags, UINT32 width, UINT32 height)
{
BOOL rc = TRUE;
if (flags & FREERDP_CODEC_INTERLEAVED)
{
if (codecs->interleaved)
{
rc &= bitmap_interleaved_context_reset(codecs->interleaved);
}
}
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);
}
}
if (flags & FREERDP_CODEC_NSCODEC)
{
if (codecs->nsc)
{
rc &= nsc_context_reset(codecs->nsc, width, height);
}
}
if (flags & FREERDP_CODEC_REMOTEFX)
{
if (codecs->rfx)
{
rc &= rfx_context_reset(codecs->rfx, width, height);
}
}
if (flags & FREERDP_CODEC_CLEARCODEC)
{
if (codecs->clear)
{
rc &= clear_context_reset(codecs->clear);
}
}
if (flags & FREERDP_CODEC_ALPHACODEC)
{
}
if (flags & FREERDP_CODEC_PROGRESSIVE)
{
if (codecs->progressive)
{
rc &= progressive_context_reset(codecs->progressive);
}
}
#ifdef WITH_GFX_H264
2016-03-02 17:16:49 +03:00
if (flags & (FREERDP_CODEC_AVC420 | FREERDP_CODEC_AVC444))
{
if (codecs->h264)
{
rc &= h264_context_reset(codecs->h264, width, height);
}
}
#endif
return rc;
}
rdpCodecs* codecs_new(rdpContext* context)
{
rdpCodecs* codecs;
2019-11-06 17:24:51 +03:00
codecs = (rdpCodecs*)calloc(1, sizeof(rdpCodecs));
if (codecs)
codecs->context = context;
return codecs;
}
void codecs_free(rdpCodecs* codecs)
{
if (!codecs)
return;
2021-09-17 10:09:48 +03:00
codecs_free_int(codecs);
free(codecs);
}