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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "rdp.h"
|
|
|
|
|
|
|
|
#include <freerdp/codecs.h>
|
|
|
|
|
2015-04-28 18:00:41 +03:00
|
|
|
#define TAG FREERDP_TAG("core.codecs")
|
|
|
|
|
2016-05-28 21:13:47 +03:00
|
|
|
BOOL freerdp_client_codecs_prepare(rdpCodecs* codecs, UINT32 flags, UINT32 width, UINT32 height)
|
2014-09-10 08:42:41 +04:00
|
|
|
{
|
2015-10-13 21:49:30 +03:00
|
|
|
if ((flags & FREERDP_CODEC_INTERLEAVED) && !codecs->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
|
|
|
}
|
2016-05-28 21:13:47 +03:00
|
|
|
|
|
|
|
if (!bitmap_interleaved_context_reset(codecs->interleaved))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Failed to reset interleaved codec context");
|
|
|
|
bitmap_interleaved_context_free(codecs->interleaved);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2014-09-10 08:42:41 +04:00
|
|
|
}
|
|
|
|
|
2015-10-13 21:49:30 +03:00
|
|
|
if ((flags & FREERDP_CODEC_PLANAR) && !codecs->planar)
|
2014-09-10 08:42:41 +04:00
|
|
|
{
|
2015-04-28 18:00:41 +03:00
|
|
|
if (!(codecs->planar = freerdp_bitmap_planar_context_new(FALSE, 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
|
|
|
}
|
2016-05-28 21:13:47 +03:00
|
|
|
|
|
|
|
if (!freerdp_bitmap_planar_context_reset(codecs->planar))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Failed to reset plannar bitmap codec context");
|
|
|
|
freerdp_bitmap_planar_context_free(codecs->planar);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2014-09-10 08:42:41 +04:00
|
|
|
}
|
|
|
|
|
2015-10-13 21:49:30 +03:00
|
|
|
if ((flags & FREERDP_CODEC_NSCODEC) && !codecs->nsc)
|
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
|
|
|
}
|
2016-05-28 21:13:47 +03:00
|
|
|
|
|
|
|
if (!nsc_context_reset(codecs->nsc, width, height))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Failed to reset nsc codec context");
|
|
|
|
nsc_context_free(codecs->nsc);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2014-09-10 08:42:41 +04:00
|
|
|
}
|
|
|
|
|
2015-10-13 21:49:30 +03:00
|
|
|
if ((flags & FREERDP_CODEC_REMOTEFX) && !codecs->rfx)
|
2014-09-10 08:42:41 +04:00
|
|
|
{
|
2015-04-28 18:00:41 +03:00
|
|
|
if (!(codecs->rfx = rfx_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 rfx codec context");
|
|
|
|
return FALSE;
|
2014-09-10 08:42:41 +04:00
|
|
|
}
|
2016-05-28 21:13:47 +03:00
|
|
|
|
|
|
|
if (!rfx_context_reset(codecs->rfx, width, height))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Failed to reset rfx codec context");
|
|
|
|
rfx_context_free(codecs->rfx);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2014-09-10 08:42:41 +04:00
|
|
|
}
|
|
|
|
|
2015-10-13 21:49:30 +03:00
|
|
|
if ((flags & FREERDP_CODEC_CLEARCODEC) && !codecs->clear)
|
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
|
|
|
}
|
2016-05-28 21:13:47 +03:00
|
|
|
|
|
|
|
if (!clear_context_reset(codecs->clear))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Failed to reset clear codec context");
|
|
|
|
clear_context_free(codecs->clear);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2014-09-10 08:42:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & FREERDP_CODEC_ALPHACODEC)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-10-13 21:49:30 +03:00
|
|
|
if ((flags & FREERDP_CODEC_PROGRESSIVE) && !codecs->progressive)
|
2014-09-10 08:42:41 +04:00
|
|
|
{
|
2015-04-28 18:00:41 +03:00
|
|
|
if (!(codecs->progressive = progressive_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 progressive codec context");
|
|
|
|
return FALSE;
|
2014-09-10 08:42:41 +04:00
|
|
|
}
|
2016-05-28 21:13:47 +03:00
|
|
|
|
|
|
|
if (!progressive_context_reset(codecs->progressive))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Failed to reset progressive codec context");
|
|
|
|
progressive_context_free(codecs->progressive);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2014-09-10 08:42:41 +04:00
|
|
|
}
|
|
|
|
|
2016-03-02 17:16:49 +03:00
|
|
|
if ((flags & (FREERDP_CODEC_AVC420 | FREERDP_CODEC_AVC444)) && !codecs->h264)
|
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
|
|
|
{
|
2015-04-28 18:00:41 +03:00
|
|
|
WLog_ERR(TAG, "Failed to create h264 codec context");
|
|
|
|
return FALSE;
|
2014-09-10 08:42:41 +04:00
|
|
|
}
|
2016-05-28 21:13:47 +03:00
|
|
|
|
|
|
|
if (!h264_context_reset(codecs->h264, width, height))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Failed to reset h264 codec context");
|
|
|
|
h264_context_free(codecs->h264);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2014-09-10 08:42:41 +04:00
|
|
|
}
|
|
|
|
|
2015-04-28 18:00:41 +03:00
|
|
|
return TRUE;
|
2014-09-10 08:42:41 +04:00
|
|
|
}
|
|
|
|
|
2016-05-11 20:42:54 +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-03-01 18:17:28 +03:00
|
|
|
rc &= freerdp_bitmap_planar_context_reset(codecs->planar);
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
rdpCodecs* codecs;
|
|
|
|
|
|
|
|
codecs = (rdpCodecs*) calloc(1, sizeof(rdpCodecs));
|
|
|
|
|
|
|
|
if (codecs)
|
|
|
|
codecs->context = context;
|
|
|
|
|
|
|
|
return codecs;
|
|
|
|
}
|
|
|
|
|
|
|
|
void codecs_free(rdpCodecs* codecs)
|
|
|
|
{
|
|
|
|
if (!codecs)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (codecs->rfx)
|
|
|
|
{
|
|
|
|
rfx_context_free(codecs->rfx);
|
|
|
|
codecs->rfx = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (codecs->nsc)
|
|
|
|
{
|
|
|
|
nsc_context_free(codecs->nsc);
|
|
|
|
codecs->nsc = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (codecs->h264)
|
|
|
|
{
|
|
|
|
h264_context_free(codecs->h264);
|
|
|
|
codecs->h264 = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|