Streamlined rdpCodec cleanup routines

This commit is contained in:
akallabeth 2021-09-17 09:09:48 +02:00 committed by akallabeth
parent ce8ef33ea4
commit c2d126cdd8

View File

@ -21,18 +21,66 @@
#include "config.h" #include "config.h"
#endif #endif
#include <winpr/assert.h>
#include "rdp.h" #include "rdp.h"
#include <freerdp/codecs.h> #include <freerdp/codecs.h>
#define TAG FREERDP_TAG("core.codecs") #define TAG FREERDP_TAG("core.codecs")
BOOL freerdp_client_codecs_prepare(rdpCodecs* codecs, UINT32 flags, UINT32 width, UINT32 height) static void codecs_free_int(rdpCodecs* codecs)
{ {
if ((flags & FREERDP_CODEC_INTERLEAVED)) 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); bitmap_interleaved_context_free(codecs->interleaved);
codecs->interleaved = NULL;
}
}
BOOL freerdp_client_codecs_prepare(rdpCodecs* codecs, UINT32 flags, UINT32 width, UINT32 height)
{
codecs_free_int(codecs);
if ((flags & FREERDP_CODEC_INTERLEAVED))
{
if (!(codecs->interleaved = bitmap_interleaved_context_new(FALSE))) if (!(codecs->interleaved = bitmap_interleaved_context_new(FALSE)))
{ {
WLog_ERR(TAG, "Failed to create interleaved codec context"); WLog_ERR(TAG, "Failed to create interleaved codec context");
@ -42,8 +90,6 @@ BOOL freerdp_client_codecs_prepare(rdpCodecs* codecs, UINT32 flags, UINT32 width
if ((flags & FREERDP_CODEC_PLANAR)) if ((flags & FREERDP_CODEC_PLANAR))
{ {
freerdp_bitmap_planar_context_free(codecs->planar);
if (!(codecs->planar = freerdp_bitmap_planar_context_new(FALSE, 64, 64))) if (!(codecs->planar = freerdp_bitmap_planar_context_new(FALSE, 64, 64)))
{ {
WLog_ERR(TAG, "Failed to create planar bitmap codec context"); WLog_ERR(TAG, "Failed to create planar bitmap codec context");
@ -53,8 +99,6 @@ BOOL freerdp_client_codecs_prepare(rdpCodecs* codecs, UINT32 flags, UINT32 width
if ((flags & FREERDP_CODEC_NSCODEC)) if ((flags & FREERDP_CODEC_NSCODEC))
{ {
nsc_context_free(codecs->nsc);
if (!(codecs->nsc = nsc_context_new())) if (!(codecs->nsc = nsc_context_new()))
{ {
WLog_ERR(TAG, "Failed to create nsc codec context"); WLog_ERR(TAG, "Failed to create nsc codec context");
@ -64,7 +108,6 @@ BOOL freerdp_client_codecs_prepare(rdpCodecs* codecs, UINT32 flags, UINT32 width
if ((flags & FREERDP_CODEC_REMOTEFX)) if ((flags & FREERDP_CODEC_REMOTEFX))
{ {
rfx_context_free(codecs->rfx);
if (!(codecs->rfx = rfx_context_new_ex(FALSE, codecs->context->settings->ThreadingFlags))) if (!(codecs->rfx = rfx_context_new_ex(FALSE, codecs->context->settings->ThreadingFlags)))
{ {
WLog_ERR(TAG, "Failed to create rfx codec context"); WLog_ERR(TAG, "Failed to create rfx codec context");
@ -74,8 +117,6 @@ BOOL freerdp_client_codecs_prepare(rdpCodecs* codecs, UINT32 flags, UINT32 width
if ((flags & FREERDP_CODEC_CLEARCODEC)) if ((flags & FREERDP_CODEC_CLEARCODEC))
{ {
clear_context_free(codecs->clear);
if (!(codecs->clear = clear_context_new(FALSE))) if (!(codecs->clear = clear_context_new(FALSE)))
{ {
WLog_ERR(TAG, "Failed to create clear codec context"); WLog_ERR(TAG, "Failed to create clear codec context");
@ -89,8 +130,6 @@ BOOL freerdp_client_codecs_prepare(rdpCodecs* codecs, UINT32 flags, UINT32 width
if ((flags & FREERDP_CODEC_PROGRESSIVE)) if ((flags & FREERDP_CODEC_PROGRESSIVE))
{ {
progressive_context_free(codecs->progressive);
if (!(codecs->progressive = progressive_context_new(FALSE))) if (!(codecs->progressive = progressive_context_new(FALSE)))
{ {
WLog_ERR(TAG, "Failed to create progressive codec context"); WLog_ERR(TAG, "Failed to create progressive codec context");
@ -101,8 +140,6 @@ BOOL freerdp_client_codecs_prepare(rdpCodecs* codecs, UINT32 flags, UINT32 width
#ifdef WITH_GFX_H264 #ifdef WITH_GFX_H264
if ((flags & (FREERDP_CODEC_AVC420 | FREERDP_CODEC_AVC444))) if ((flags & (FREERDP_CODEC_AVC420 | FREERDP_CODEC_AVC444)))
{ {
h264_context_free(codecs->h264);
if (!(codecs->h264 = h264_context_new(FALSE))) if (!(codecs->h264 = h264_context_new(FALSE)))
{ {
WLog_ERR(TAG, "Failed to create h264 codec context"); WLog_ERR(TAG, "Failed to create h264 codec context");
@ -201,49 +238,7 @@ void codecs_free(rdpCodecs* codecs)
if (!codecs) if (!codecs)
return; return;
if (codecs->rfx) codecs_free_int(codecs);
{
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;
}
free(codecs); free(codecs);
} }