FreeRDP
Loading...
Searching...
No Matches
hevc.c
1
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>
23
24#define TAG FREERDP_TAG("codec.hevc")
25
26struct S_FREERDP_HEVC_CONTEXT
27{
28 BOOL Compressor;
29 wLog* log;
30 H264_CONTEXT* decoder;
31};
32
33WINPR_ATTR_NODISCARD
34static H264_CONTEXT_OPTION hevc2h264option(FREERDP_HEVC_CONTEXT_OPTION option)
35{
36 switch (option)
37 {
38 case FREERDP_HEVC_CONTEXT_OPTION_PROFILE:
39 return H264_CONTEXT_OPTION_QP;
40 case FREERDP_HEVC_CONTEXT_OPTION_RATECONTROL:
41 return H264_CONTEXT_OPTION_RATECONTROL;
42 case FREERDP_HEVC_CONTEXT_OPTION_BITRATE:
43 return H264_CONTEXT_OPTION_BITRATE;
44 case FREERDP_HEVC_CONTEXT_OPTION_USAGETYPE:
45 return H264_CONTEXT_OPTION_USAGETYPE;
46 case FREERDP_HEVC_CONTEXT_OPTION_HW_ACCEL:
47 return H264_CONTEXT_OPTION_HW_ACCEL;
48 default:
49 return 0;
50 }
51}
52BOOL freerdp_hevc_context_set_option(WINPR_ATTR_UNUSED FREERDP_HEVC_CONTEXT* hevc,
53 WINPR_ATTR_UNUSED FREERDP_HEVC_CONTEXT_OPTION option,
54 WINPR_ATTR_UNUSED UINT32 value)
55{
56 WINPR_ASSERT(hevc);
57 if (!hevc->Compressor)
58 return h264_context_set_option(hevc->decoder, hevc2h264option(option), value);
59 return FALSE;
60}
61
62UINT32 freerdp_hevc_context_get_option(WINPR_ATTR_UNUSED FREERDP_HEVC_CONTEXT* hevc,
63 WINPR_ATTR_UNUSED FREERDP_HEVC_CONTEXT_OPTION option)
64{
65 WINPR_ASSERT(hevc);
66 if (!hevc->Compressor)
67 return h264_context_get_option(hevc->decoder, hevc2h264option(option));
68 return 0;
69}
70
71INT32 freerdp_hevc_compress(WINPR_ATTR_UNUSED FREERDP_HEVC_CONTEXT* hevc,
72 WINPR_ATTR_UNUSED const BYTE* pSrcData,
73 WINPR_ATTR_UNUSED DWORD SrcFormat, WINPR_ATTR_UNUSED UINT32 nSrcStep,
74 WINPR_ATTR_UNUSED UINT32 nSrcWidth, WINPR_ATTR_UNUSED UINT32 nSrcHeight,
75 WINPR_ATTR_UNUSED const RECTANGLE_16* regionRect,
76 WINPR_ATTR_UNUSED BYTE** ppDstData, WINPR_ATTR_UNUSED UINT32* pDstSize,
77 WINPR_ATTR_UNUSED RDPGFX_H264_METABLOCK* meta)
78{
79 WINPR_ASSERT(hevc);
80 WLog_Print(hevc->log, WLOG_ERROR,
81 "This build does not support HEVC codec. Recompile with '-DWITH_AVM=ON' or "
82 "'-DWITH_DHEVCD=ON'");
83 return -1;
84}
85
86INT32 freerdp_hevc_decompress(WINPR_ATTR_UNUSED FREERDP_HEVC_CONTEXT* hevc,
87 WINPR_ATTR_UNUSED const BYTE* pSrcData,
88 WINPR_ATTR_UNUSED UINT32 SrcSize, WINPR_ATTR_UNUSED BYTE* pDstData,
89 WINPR_ATTR_UNUSED DWORD DstFormat, WINPR_ATTR_UNUSED UINT32 nDstStep,
90 WINPR_ATTR_UNUSED UINT32 nDstWidth,
91 WINPR_ATTR_UNUSED UINT32 nDstHeight,
92 WINPR_ATTR_UNUSED const RECTANGLE_16* regionRects,
93 WINPR_ATTR_UNUSED UINT32 numRegionRect)
94{
95 WINPR_ASSERT(hevc);
96 return avc420_decompress(hevc->decoder, pSrcData, SrcSize, pDstData, DstFormat, nDstStep,
97 nDstWidth, nDstHeight, regionRects, numRegionRect);
98}
99
100BOOL freerdp_hevc_context_reset(WINPR_ATTR_UNUSED FREERDP_HEVC_CONTEXT* hevc,
101 WINPR_ATTR_UNUSED UINT32 width, WINPR_ATTR_UNUSED UINT32 height)
102{
103 WINPR_ASSERT(hevc);
104 if (!hevc->Compressor)
105 return h264_context_reset(hevc->decoder, width, height);
106
107 WLog_Print(hevc->log, WLOG_WARN,
108 "This build does not support HEVC codec. Recompile with '-DWITH_AVM=ON' or "
109 "'-DWITH_DHEVCD=ON'");
110 return FALSE;
111}
112
113void freerdp_hevc_context_free(WINPR_ATTR_UNUSED FREERDP_HEVC_CONTEXT* hevc)
114{
115 if (!hevc)
116 return;
117
118 h264_context_free(hevc->decoder);
119 free(hevc);
120}
121
122FREERDP_HEVC_CONTEXT* freerdp_hevc_context_new(BOOL Compressor)
123{
124 FREERDP_HEVC_CONTEXT* ctx = calloc(1, sizeof(FREERDP_HEVC_CONTEXT));
125 if (!ctx)
126 return nullptr;
127 ctx->Compressor = Compressor;
128 ctx->log = WLog_Get(TAG);
129 return ctx;
130}