FreeRDP
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Modules Pages
codecs.c
1
20#include <freerdp/config.h>
21
22#include <winpr/assert.h>
23
24#include "rdp.h"
25
26#include <freerdp/codecs.h>
27
28#define TAG FREERDP_TAG("core.codecs")
29
30static void codecs_free_int(rdpCodecs* codecs, UINT32 flags)
31{
32 WINPR_ASSERT(codecs);
33
34 if (flags & FREERDP_CODEC_REMOTEFX)
35 {
36 if (codecs->rfx)
37 {
38 rfx_context_free(codecs->rfx);
39 codecs->rfx = NULL;
40 }
41 }
42
43 if (flags & FREERDP_CODEC_NSCODEC)
44 {
45 if (codecs->nsc)
46 {
47 nsc_context_free(codecs->nsc);
48 codecs->nsc = NULL;
49 }
50 }
51
52#ifdef WITH_GFX_H264
53 if (flags & (FREERDP_CODEC_AVC420 | FREERDP_CODEC_AVC444))
54 {
55 if (codecs->h264)
56 {
57 h264_context_free(codecs->h264);
58 codecs->h264 = NULL;
59 }
60 }
61#endif
62
63 if (flags & FREERDP_CODEC_CLEARCODEC)
64 {
65 if (codecs->clear)
66 {
67 clear_context_free(codecs->clear);
68 codecs->clear = NULL;
69 }
70 }
71
72 if (flags & FREERDP_CODEC_PROGRESSIVE)
73 {
74 if (codecs->progressive)
75 {
76 progressive_context_free(codecs->progressive);
77 codecs->progressive = NULL;
78 }
79 }
80
81 if (flags & FREERDP_CODEC_PLANAR)
82 {
83 if (codecs->planar)
84 {
85 freerdp_bitmap_planar_context_free(codecs->planar);
86 codecs->planar = NULL;
87 }
88 }
89
90 if (flags & FREERDP_CODEC_INTERLEAVED)
91 {
92 if (codecs->interleaved)
93 {
94 bitmap_interleaved_context_free(codecs->interleaved);
95 codecs->interleaved = NULL;
96 }
97 }
98}
99BOOL freerdp_client_codecs_prepare(rdpCodecs* codecs, UINT32 flags, UINT32 width, UINT32 height)
100{
101 codecs_free_int(codecs, flags);
102 if ((flags & FREERDP_CODEC_INTERLEAVED))
103 {
104 if (!(codecs->interleaved = bitmap_interleaved_context_new(FALSE)))
105 {
106 WLog_ERR(TAG, "Failed to create interleaved codec context");
107 return FALSE;
108 }
109 }
110
111 if ((flags & FREERDP_CODEC_PLANAR))
112 {
113 if (!(codecs->planar = freerdp_bitmap_planar_context_new(0, 64, 64)))
114 {
115 WLog_ERR(TAG, "Failed to create planar bitmap codec context");
116 return FALSE;
117 }
118 }
119
120 if ((flags & FREERDP_CODEC_NSCODEC))
121 {
122 if (!(codecs->nsc = nsc_context_new()))
123 {
124 WLog_ERR(TAG, "Failed to create nsc codec context");
125 return FALSE;
126 }
127 }
128
129 if ((flags & FREERDP_CODEC_REMOTEFX))
130 {
131 if (!(codecs->rfx = rfx_context_new_ex(FALSE, codecs->ThreadingFlags)))
132 {
133 WLog_ERR(TAG, "Failed to create rfx codec context");
134 return FALSE;
135 }
136 }
137
138 if ((flags & FREERDP_CODEC_CLEARCODEC))
139 {
140 if (!(codecs->clear = clear_context_new(FALSE)))
141 {
142 WLog_ERR(TAG, "Failed to create clear codec context");
143 return FALSE;
144 }
145 }
146
147 if (flags & FREERDP_CODEC_ALPHACODEC)
148 {
149 }
150
151 if ((flags & FREERDP_CODEC_PROGRESSIVE))
152 {
153 if (!(codecs->progressive = progressive_context_new_ex(FALSE, codecs->ThreadingFlags)))
154 {
155 WLog_ERR(TAG, "Failed to create progressive codec context");
156 return FALSE;
157 }
158 }
159
160#ifdef WITH_GFX_H264
161 if ((flags & (FREERDP_CODEC_AVC420 | FREERDP_CODEC_AVC444)))
162 {
163 if (!(codecs->h264 = h264_context_new(FALSE)))
164 {
165 WLog_WARN(TAG, "Failed to create h264 codec context");
166 }
167 }
168#endif
169
170 return freerdp_client_codecs_reset(codecs, flags, width, height);
171}
172
173BOOL freerdp_client_codecs_reset(rdpCodecs* codecs, UINT32 flags, UINT32 width, UINT32 height)
174{
175 BOOL rc = TRUE;
176
177 if (flags & FREERDP_CODEC_INTERLEAVED)
178 {
179 if (codecs->interleaved)
180 {
181 rc &= bitmap_interleaved_context_reset(codecs->interleaved);
182 }
183 }
184
185 if (flags & FREERDP_CODEC_PLANAR)
186 {
187 if (codecs->planar)
188 {
189 rc &= freerdp_bitmap_planar_context_reset(codecs->planar, width, height);
190 }
191 }
192
193 if (flags & FREERDP_CODEC_NSCODEC)
194 {
195 if (codecs->nsc)
196 {
197 rc &= nsc_context_reset(codecs->nsc, width, height);
198 }
199 }
200
201 if (flags & FREERDP_CODEC_REMOTEFX)
202 {
203 if (codecs->rfx)
204 {
205 rc &= rfx_context_reset(codecs->rfx, width, height);
206 }
207 }
208
209 if (flags & FREERDP_CODEC_CLEARCODEC)
210 {
211 if (codecs->clear)
212 {
213 rc &= clear_context_reset(codecs->clear);
214 }
215 }
216
217 if (flags & FREERDP_CODEC_ALPHACODEC)
218 {
219 }
220
221 if (flags & FREERDP_CODEC_PROGRESSIVE)
222 {
223 if (codecs->progressive)
224 {
225 rc &= progressive_context_reset(codecs->progressive);
226 }
227 }
228
229#ifdef WITH_GFX_H264
230 if (flags & (FREERDP_CODEC_AVC420 | FREERDP_CODEC_AVC444))
231 {
232 if (codecs->h264)
233 {
234 rc &= h264_context_reset(codecs->h264, width, height);
235 }
236 }
237#endif
238
239 return rc;
240}
241
242#if !defined(WITHOUT_FREERDP_3x_DEPRECATED)
243rdpCodecs* codecs_new(rdpContext* context)
244{
245 if (!context || !context->settings)
246 return NULL;
247
248 const UINT32 flags = freerdp_settings_get_uint32(context->settings, FreeRDP_ThreadingFlags);
249 return freerdp_client_codecs_new(flags);
250}
251
252void codecs_free(rdpCodecs* codecs)
253{
254 freerdp_client_codecs_free(codecs);
255}
256#endif
257
258rdpCodecs* freerdp_client_codecs_new(UINT32 ThreadingFlags)
259{
260 rdpCodecs* codecs = (rdpCodecs*)calloc(1, sizeof(rdpCodecs));
261
262 if (!codecs)
263 return NULL;
264
265 codecs->ThreadingFlags = ThreadingFlags;
266
267 return codecs;
268}
269
270void freerdp_client_codecs_free(rdpCodecs* codecs)
271{
272 if (!codecs)
273 return;
274
275 codecs_free_int(codecs, FREERDP_CODEC_ALL);
276
277 free(codecs);
278}
FREERDP_API UINT32 freerdp_settings_get_uint32(const rdpSettings *settings, FreeRDP_Settings_Keys_UInt32 id)
Returns a UINT32 settings value.