/src/FreeRDP/libfreerdp/core/codecs.c
Line | Count | Source (jump to first uncovered line) |
1 | | /** |
2 | | * FreeRDP: A Remote Desktop Protocol Implementation |
3 | | * RDP Codecs |
4 | | * |
5 | | * Copyright 2014 Marc-Andre Moreau <marcandre.moreau@gmail.com> |
6 | | * |
7 | | * Licensed under the Apache License, Version 2.0 (the "License"); |
8 | | * you may not use this file except in compliance with the License. |
9 | | * You may obtain a copy of the License at |
10 | | * |
11 | | * http://www.apache.org/licenses/LICENSE-2.0 |
12 | | * |
13 | | * Unless required by applicable law or agreed to in writing, software |
14 | | * distributed under the License is distributed on an "AS IS" BASIS, |
15 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
16 | | * See the License for the specific language governing permissions and |
17 | | * limitations under the License. |
18 | | */ |
19 | | |
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 | | |
30 | | static void codecs_free_int(rdpCodecs* codecs, UINT32 flags) |
31 | 0 | { |
32 | 0 | WINPR_ASSERT(codecs); |
33 | | |
34 | 0 | if (flags & FREERDP_CODEC_REMOTEFX) |
35 | 0 | { |
36 | 0 | if (codecs->rfx) |
37 | 0 | { |
38 | 0 | rfx_context_free(codecs->rfx); |
39 | 0 | codecs->rfx = NULL; |
40 | 0 | } |
41 | 0 | } |
42 | |
|
43 | 0 | if (flags & FREERDP_CODEC_NSCODEC) |
44 | 0 | { |
45 | 0 | if (codecs->nsc) |
46 | 0 | { |
47 | 0 | nsc_context_free(codecs->nsc); |
48 | 0 | codecs->nsc = NULL; |
49 | 0 | } |
50 | 0 | } |
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 | 0 | if (flags & FREERDP_CODEC_CLEARCODEC) |
64 | 0 | { |
65 | 0 | if (codecs->clear) |
66 | 0 | { |
67 | 0 | clear_context_free(codecs->clear); |
68 | 0 | codecs->clear = NULL; |
69 | 0 | } |
70 | 0 | } |
71 | |
|
72 | 0 | if (flags & FREERDP_CODEC_PROGRESSIVE) |
73 | 0 | { |
74 | 0 | if (codecs->progressive) |
75 | 0 | { |
76 | 0 | progressive_context_free(codecs->progressive); |
77 | 0 | codecs->progressive = NULL; |
78 | 0 | } |
79 | 0 | } |
80 | |
|
81 | 0 | if (flags & FREERDP_CODEC_PLANAR) |
82 | 0 | { |
83 | 0 | if (codecs->planar) |
84 | 0 | { |
85 | 0 | freerdp_bitmap_planar_context_free(codecs->planar); |
86 | 0 | codecs->planar = NULL; |
87 | 0 | } |
88 | 0 | } |
89 | |
|
90 | 0 | if (flags & FREERDP_CODEC_INTERLEAVED) |
91 | 0 | { |
92 | 0 | if (codecs->interleaved) |
93 | 0 | { |
94 | 0 | bitmap_interleaved_context_free(codecs->interleaved); |
95 | 0 | codecs->interleaved = NULL; |
96 | 0 | } |
97 | 0 | } |
98 | 0 | } |
99 | | BOOL freerdp_client_codecs_prepare(rdpCodecs* codecs, UINT32 flags, UINT32 width, UINT32 height) |
100 | 0 | { |
101 | 0 | codecs_free_int(codecs, flags); |
102 | 0 | if ((flags & FREERDP_CODEC_INTERLEAVED)) |
103 | 0 | { |
104 | 0 | if (!(codecs->interleaved = bitmap_interleaved_context_new(FALSE))) |
105 | 0 | { |
106 | 0 | WLog_ERR(TAG, "Failed to create interleaved codec context"); |
107 | 0 | return FALSE; |
108 | 0 | } |
109 | 0 | } |
110 | | |
111 | 0 | if ((flags & FREERDP_CODEC_PLANAR)) |
112 | 0 | { |
113 | 0 | if (!(codecs->planar = freerdp_bitmap_planar_context_new(0, 64, 64))) |
114 | 0 | { |
115 | 0 | WLog_ERR(TAG, "Failed to create planar bitmap codec context"); |
116 | 0 | return FALSE; |
117 | 0 | } |
118 | 0 | } |
119 | | |
120 | 0 | if ((flags & FREERDP_CODEC_NSCODEC)) |
121 | 0 | { |
122 | 0 | if (!(codecs->nsc = nsc_context_new())) |
123 | 0 | { |
124 | 0 | WLog_ERR(TAG, "Failed to create nsc codec context"); |
125 | 0 | return FALSE; |
126 | 0 | } |
127 | 0 | } |
128 | | |
129 | 0 | UINT32 threadingFlags = |
130 | 0 | freerdp_settings_get_uint32(codecs->context->settings, FreeRDP_ThreadingFlags); |
131 | 0 | if ((flags & FREERDP_CODEC_REMOTEFX)) |
132 | 0 | { |
133 | 0 | if (!(codecs->rfx = rfx_context_new_ex(FALSE, threadingFlags))) |
134 | 0 | { |
135 | 0 | WLog_ERR(TAG, "Failed to create rfx codec context"); |
136 | 0 | return FALSE; |
137 | 0 | } |
138 | 0 | } |
139 | | |
140 | 0 | if ((flags & FREERDP_CODEC_CLEARCODEC)) |
141 | 0 | { |
142 | 0 | if (!(codecs->clear = clear_context_new(FALSE))) |
143 | 0 | { |
144 | 0 | WLog_ERR(TAG, "Failed to create clear codec context"); |
145 | 0 | return FALSE; |
146 | 0 | } |
147 | 0 | } |
148 | | |
149 | 0 | if (flags & FREERDP_CODEC_ALPHACODEC) |
150 | 0 | { |
151 | 0 | } |
152 | |
|
153 | 0 | if ((flags & FREERDP_CODEC_PROGRESSIVE)) |
154 | 0 | { |
155 | 0 | if (!(codecs->progressive = progressive_context_new_ex(FALSE, threadingFlags))) |
156 | 0 | { |
157 | 0 | WLog_ERR(TAG, "Failed to create progressive codec context"); |
158 | 0 | return FALSE; |
159 | 0 | } |
160 | 0 | } |
161 | | |
162 | | #ifdef WITH_GFX_H264 |
163 | | if ((flags & (FREERDP_CODEC_AVC420 | FREERDP_CODEC_AVC444))) |
164 | | { |
165 | | if (!(codecs->h264 = h264_context_new(FALSE))) |
166 | | { |
167 | | WLog_WARN(TAG, "Failed to create h264 codec context"); |
168 | | } |
169 | | } |
170 | | #endif |
171 | | |
172 | 0 | return freerdp_client_codecs_reset(codecs, flags, width, height); |
173 | 0 | } |
174 | | |
175 | | BOOL freerdp_client_codecs_reset(rdpCodecs* codecs, UINT32 flags, UINT32 width, UINT32 height) |
176 | 0 | { |
177 | 0 | BOOL rc = TRUE; |
178 | |
|
179 | 0 | if (flags & FREERDP_CODEC_INTERLEAVED) |
180 | 0 | { |
181 | 0 | if (codecs->interleaved) |
182 | 0 | { |
183 | 0 | rc &= bitmap_interleaved_context_reset(codecs->interleaved); |
184 | 0 | } |
185 | 0 | } |
186 | |
|
187 | 0 | if (flags & FREERDP_CODEC_PLANAR) |
188 | 0 | { |
189 | 0 | if (codecs->planar) |
190 | 0 | { |
191 | 0 | rc &= freerdp_bitmap_planar_context_reset(codecs->planar, width, height); |
192 | 0 | } |
193 | 0 | } |
194 | |
|
195 | 0 | if (flags & FREERDP_CODEC_NSCODEC) |
196 | 0 | { |
197 | 0 | if (codecs->nsc) |
198 | 0 | { |
199 | 0 | rc &= nsc_context_reset(codecs->nsc, width, height); |
200 | 0 | } |
201 | 0 | } |
202 | |
|
203 | 0 | if (flags & FREERDP_CODEC_REMOTEFX) |
204 | 0 | { |
205 | 0 | if (codecs->rfx) |
206 | 0 | { |
207 | 0 | rc &= rfx_context_reset(codecs->rfx, width, height); |
208 | 0 | } |
209 | 0 | } |
210 | |
|
211 | 0 | if (flags & FREERDP_CODEC_CLEARCODEC) |
212 | 0 | { |
213 | 0 | if (codecs->clear) |
214 | 0 | { |
215 | 0 | rc &= clear_context_reset(codecs->clear); |
216 | 0 | } |
217 | 0 | } |
218 | |
|
219 | 0 | if (flags & FREERDP_CODEC_ALPHACODEC) |
220 | 0 | { |
221 | 0 | } |
222 | |
|
223 | 0 | if (flags & FREERDP_CODEC_PROGRESSIVE) |
224 | 0 | { |
225 | 0 | if (codecs->progressive) |
226 | 0 | { |
227 | 0 | rc &= progressive_context_reset(codecs->progressive); |
228 | 0 | } |
229 | 0 | } |
230 | |
|
231 | | #ifdef WITH_GFX_H264 |
232 | | if (flags & (FREERDP_CODEC_AVC420 | FREERDP_CODEC_AVC444)) |
233 | | { |
234 | | if (codecs->h264) |
235 | | { |
236 | | rc &= h264_context_reset(codecs->h264, width, height); |
237 | | } |
238 | | } |
239 | | #endif |
240 | |
|
241 | 0 | return rc; |
242 | 0 | } |
243 | | |
244 | | rdpCodecs* codecs_new(rdpContext* context) |
245 | 0 | { |
246 | 0 | rdpCodecs* codecs = NULL; |
247 | 0 | codecs = (rdpCodecs*)calloc(1, sizeof(rdpCodecs)); |
248 | |
|
249 | 0 | if (codecs) |
250 | 0 | codecs->context = context; |
251 | |
|
252 | 0 | return codecs; |
253 | 0 | } |
254 | | |
255 | | void codecs_free(rdpCodecs* codecs) |
256 | 7.99k | { |
257 | 7.99k | if (!codecs) |
258 | 7.99k | return; |
259 | | |
260 | 0 | codecs_free_int(codecs, FREERDP_CODEC_ALL); |
261 | |
|
262 | 0 | free(codecs); |
263 | 0 | } |