18#include <freerdp/codec/hevc.h>
19#include <freerdp/primitives.h>
20#include <freerdp/log.h>
21#include <freerdp/codec/region.h>
22#include <freerdp/codec/h264.h>
26#define TAG FREERDP_TAG("codec.hevc")
28struct S_FREERDP_HEVC_CONTEXT
32 H264_CONTEXT* context;
36static H264_CONTEXT_OPTION hevc2h264option(FREERDP_HEVC_CONTEXT_OPTION option)
40 case FREERDP_HEVC_CONTEXT_OPTION_PROFILE:
41 return H264_CONTEXT_OPTION_HEVC444;
42 case FREERDP_HEVC_CONTEXT_OPTION_RATECONTROL:
43 return H264_CONTEXT_OPTION_RATECONTROL;
44 case FREERDP_HEVC_CONTEXT_OPTION_BITRATE:
45 return H264_CONTEXT_OPTION_BITRATE;
46 case FREERDP_HEVC_CONTEXT_OPTION_USAGETYPE:
47 return H264_CONTEXT_OPTION_USAGETYPE;
48 case FREERDP_HEVC_CONTEXT_OPTION_HW_ACCEL:
49 return H264_CONTEXT_OPTION_HW_ACCEL;
54BOOL freerdp_hevc_context_set_option(FREERDP_HEVC_CONTEXT* hevc, FREERDP_HEVC_CONTEXT_OPTION option,
58 if (option == FREERDP_HEVC_CONTEXT_OPTION_RATECONTROL)
62 if (value != FREERDP_HEVC_VBR)
64 WLog_Print(hevc->log, WLOG_WARN,
65 "HEVC rate control is only supported in FREERDP_HEVC_VBR mode");
68 return h264_context_set_option(hevc->context, H264_CONTEXT_OPTION_RATECONTROL,
69 H264_RATECONTROL_VBR);
71 return h264_context_set_option(hevc->context, hevc2h264option(option), value);
74UINT32 freerdp_hevc_context_get_option(FREERDP_HEVC_CONTEXT* hevc,
75 FREERDP_HEVC_CONTEXT_OPTION option)
78 return h264_context_get_option(hevc->context, hevc2h264option(option));
81INT32 freerdp_hevc_compress(FREERDP_HEVC_CONTEXT* hevc,
const BYTE* pSrcData, DWORD SrcFormat,
82 UINT32 nSrcStep, UINT32 nSrcWidth, UINT32 nSrcHeight,
83 const RECTANGLE_16* regionRect, BYTE** ppDstData, UINT32* pDstSize,
88 H264_CONTEXT* h264 = hevc->context;
92 BYTE* coded =
nullptr;
95 if (!h264 || !h264->Compressor)
98 if (!h264->subsystem->Compress)
101 if (!avc420_ensure_buffer(h264, nSrcStep, nSrcWidth, nSrcHeight))
104 if (!avc444_ensure_buffer(h264, nSrcHeight))
107 prim_size_t roi = { .width = nSrcWidth, .height = nSrcHeight };
113 const pstatus_t res = p->RGBToYUV444_8u_P3AC4R(pSrcData, SrcFormat, nSrcStep, h264->pYUV444Data,
114 h264->iYUV444Stride, &roi);
117 const BYTE* pcYUV444Data[3] = { h264->pYUV444Data[0], h264->pYUV444Data[1],
118 h264->pYUV444Data[2] };
120 if (!detect_changes(!h264->firstLumaFrameDone, h264->QP, regionRect, h264->pYUV444Data,
121 h264->pOldYUV444Data, h264->iYUV444Stride, 0, meta))
123 if (h264->subsystem->Compress(h264, pcYUV444Data, h264->iYUV444Stride, &coded, &codedSize) < 0)
125 h264->firstLumaFrameDone = TRUE;
128 *pDstSize = codedSize;
132 free_h264_metablock(meta);
136INT32 freerdp_hevc_decompress(FREERDP_HEVC_CONTEXT* hevc,
const BYTE* pSrcData, UINT32 SrcSize,
137 BYTE* pDstData, DWORD DstFormat, UINT32 nDstStep, UINT32 nDstWidth,
139 UINT32 numRegionRect)
142 return h26X_decompress(hevc->context, pSrcData, SrcSize, pDstData, DstFormat, nDstStep,
143 nDstWidth, nDstHeight, regionRects, numRegionRect);
146BOOL freerdp_hevc_context_reset(FREERDP_HEVC_CONTEXT* hevc, UINT32 width, UINT32 height)
149 return h264_context_reset(hevc->context, width, height);
152void freerdp_hevc_context_free(FREERDP_HEVC_CONTEXT* hevc)
157 h264_context_free(hevc->context);
161FREERDP_HEVC_CONTEXT* freerdp_hevc_context_new(BOOL Compressor)
163 FREERDP_HEVC_CONTEXT* ctx = calloc(1,
sizeof(FREERDP_HEVC_CONTEXT));
166 ctx->Compressor = Compressor;
167 ctx->log = WLog_Get(TAG);
168 ctx->context = h264_context_new_ex(Compressor, TRUE, TRUE);
174 freerdp_hevc_context_free(ctx);