/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  |   if ((flags & FREERDP_CODEC_REMOTEFX))  | 
130  | 0  |   { | 
131  | 0  |     if (!(codecs->rfx = rfx_context_new_ex(FALSE, codecs->ThreadingFlags)))  | 
132  | 0  |     { | 
133  | 0  |       WLog_ERR(TAG, "Failed to create rfx codec context");  | 
134  | 0  |       return FALSE;  | 
135  | 0  |     }  | 
136  | 0  |   }  | 
137  |  |  | 
138  | 0  |   if ((flags & FREERDP_CODEC_CLEARCODEC))  | 
139  | 0  |   { | 
140  | 0  |     if (!(codecs->clear = clear_context_new(FALSE)))  | 
141  | 0  |     { | 
142  | 0  |       WLog_ERR(TAG, "Failed to create clear codec context");  | 
143  | 0  |       return FALSE;  | 
144  | 0  |     }  | 
145  | 0  |   }  | 
146  |  |  | 
147  | 0  |   if (flags & FREERDP_CODEC_ALPHACODEC)  | 
148  | 0  |   { | 
149  | 0  |   }  | 
150  |  | 
  | 
151  | 0  |   if ((flags & FREERDP_CODEC_PROGRESSIVE))  | 
152  | 0  |   { | 
153  | 0  |     if (!(codecs->progressive = progressive_context_new_ex(FALSE, codecs->ThreadingFlags)))  | 
154  | 0  |     { | 
155  | 0  |       WLog_ERR(TAG, "Failed to create progressive codec context");  | 
156  | 0  |       return FALSE;  | 
157  | 0  |     }  | 
158  | 0  |   }  | 
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  | 0  |   return freerdp_client_codecs_reset(codecs, flags, width, height);  | 
171  | 0  | }  | 
172  |  |  | 
173  |  | BOOL freerdp_client_codecs_reset(rdpCodecs* codecs, UINT32 flags, UINT32 width, UINT32 height)  | 
174  | 0  | { | 
175  | 0  |   BOOL rc = TRUE;  | 
176  |  | 
  | 
177  | 0  |   if (flags & FREERDP_CODEC_INTERLEAVED)  | 
178  | 0  |   { | 
179  | 0  |     if (codecs->interleaved)  | 
180  | 0  |     { | 
181  | 0  |       rc &= bitmap_interleaved_context_reset(codecs->interleaved);  | 
182  | 0  |     }  | 
183  | 0  |   }  | 
184  |  | 
  | 
185  | 0  |   if (flags & FREERDP_CODEC_PLANAR)  | 
186  | 0  |   { | 
187  | 0  |     if (codecs->planar)  | 
188  | 0  |     { | 
189  | 0  |       rc &= freerdp_bitmap_planar_context_reset(codecs->planar, width, height);  | 
190  | 0  |     }  | 
191  | 0  |   }  | 
192  |  | 
  | 
193  | 0  |   if (flags & FREERDP_CODEC_NSCODEC)  | 
194  | 0  |   { | 
195  | 0  |     if (codecs->nsc)  | 
196  | 0  |     { | 
197  | 0  |       rc &= nsc_context_reset(codecs->nsc, width, height);  | 
198  | 0  |     }  | 
199  | 0  |   }  | 
200  |  | 
  | 
201  | 0  |   if (flags & FREERDP_CODEC_REMOTEFX)  | 
202  | 0  |   { | 
203  | 0  |     if (codecs->rfx)  | 
204  | 0  |     { | 
205  | 0  |       rc &= rfx_context_reset(codecs->rfx, width, height);  | 
206  | 0  |     }  | 
207  | 0  |   }  | 
208  |  | 
  | 
209  | 0  |   if (flags & FREERDP_CODEC_CLEARCODEC)  | 
210  | 0  |   { | 
211  | 0  |     if (codecs->clear)  | 
212  | 0  |     { | 
213  | 0  |       rc &= clear_context_reset(codecs->clear);  | 
214  | 0  |     }  | 
215  | 0  |   }  | 
216  |  | 
  | 
217  | 0  |   if (flags & FREERDP_CODEC_ALPHACODEC)  | 
218  | 0  |   { | 
219  | 0  |   }  | 
220  |  | 
  | 
221  | 0  |   if (flags & FREERDP_CODEC_PROGRESSIVE)  | 
222  | 0  |   { | 
223  | 0  |     if (codecs->progressive)  | 
224  | 0  |     { | 
225  | 0  |       rc &= progressive_context_reset(codecs->progressive);  | 
226  | 0  |     }  | 
227  | 0  |   }  | 
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  | 0  |   return rc;  | 
240  | 0  | }  | 
241  |  |  | 
242  |  | rdpCodecs* codecs_new(rdpContext* context)  | 
243  | 0  | { | 
244  | 0  |   if (!context || !context->settings)  | 
245  | 0  |     return NULL;  | 
246  |  |  | 
247  | 0  |   const UINT32 flags = freerdp_settings_get_uint32(context->settings, FreeRDP_ThreadingFlags);  | 
248  | 0  |   return freerdp_client_codecs_new(flags);  | 
249  | 0  | }  | 
250  |  |  | 
251  |  | void codecs_free(rdpCodecs* codecs)  | 
252  | 0  | { | 
253  | 0  |   freerdp_client_codecs_free(codecs);  | 
254  | 0  | }  | 
255  |  |  | 
256  |  | rdpCodecs* freerdp_client_codecs_new(UINT32 ThreadingFlags)  | 
257  | 0  | { | 
258  | 0  |   rdpCodecs* codecs = (rdpCodecs*)calloc(1, sizeof(rdpCodecs));  | 
259  |  | 
  | 
260  | 0  |   if (!codecs)  | 
261  | 0  |     return NULL;  | 
262  |  |  | 
263  | 0  |   codecs->ThreadingFlags = ThreadingFlags;  | 
264  |  | 
  | 
265  | 0  |   return codecs;  | 
266  | 0  | }  | 
267  |  |  | 
268  |  | void freerdp_client_codecs_free(rdpCodecs* codecs)  | 
269  | 6.93k  | { | 
270  | 6.93k  |   if (!codecs)  | 
271  | 6.93k  |     return;  | 
272  |  |  | 
273  | 0  |   codecs_free_int(codecs, FREERDP_CODEC_ALL);  | 
274  |  | 
  | 
275  | 0  |   free(codecs);  | 
276  | 0  | }  |