1 /*****************************************************************
2 * gavl - a general purpose audio/video processing library
3 *
4 * Copyright (c) 2001 - 2011 Members of the Gmerlin project
5 * gmerlin-general@lists.sourceforge.net
6 * http://gmerlin.sourceforge.net
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * *****************************************************************/
21
22 #include <stdlib.h> /* calloc, free */
23 #include <string.h> /* calloc, free */
24
25 #ifdef DEBUG
26 #include <stdio.h>
27 #endif
28
29 #include <gavl.h>
30 #include <config.h>
31 #include <video.h>
32 #include <accel.h>
33
34 /***************************************************
35 * Default Options
36 ***************************************************/
37
run_func_default(void (* func)(void *,int,int),void * gavl_data,int start,int len,void * client_data,int thread)38 static void run_func_default(void (*func)(void*, int, int),
39 void * gavl_data,
40 int start, int len,
41 void * client_data, int thread)
42 {
43 func(gavl_data, start, len);
44 }
45
stop_func_default(void * client_data,int thread)46 static void stop_func_default(void * client_data, int thread)
47 {
48 }
49
gavl_video_options_set_defaults(gavl_video_options_t * opt)50 void gavl_video_options_set_defaults(gavl_video_options_t * opt)
51 {
52 memset(opt, 0, sizeof(*opt));
53 opt->accel_flags = gavl_accel_supported();
54 opt->scale_order = 4;
55 opt->quality = GAVL_QUALITY_DEFAULT;
56 opt->downscale_blur = 1.0;
57 opt->downscale_filter = GAVL_DOWNSCALE_FILTER_WIDE;
58
59 opt->num_threads = 1;
60 opt->run_func = run_func_default;
61 opt->stop_func = stop_func_default;
62
63 gavl_init_memcpy();
64 }
65
gavl_video_options_get_num_threads(gavl_video_options_t * opt)66 int gavl_video_options_get_num_threads(gavl_video_options_t * opt)
67 {
68 return opt->num_threads;
69 }
70
gavl_video_options_set_num_threads(gavl_video_options_t * opt,int n)71 void gavl_video_options_set_num_threads(gavl_video_options_t * opt, int n)
72 {
73 opt->num_threads = n;
74 }
75
gavl_video_options_set_run_func(gavl_video_options_t * opt,void (* run)(void (* func)(void *,int start,int num),void * gavl_data,int start,int num,void * client_data,int thread),void * client_data)76 void gavl_video_options_set_run_func(gavl_video_options_t * opt,
77 void (*run)(void (*func)(void*, int start, int num),
78 void * gavl_data,
79 int start, int num,
80 void * client_data, int thread),
81 void * client_data)
82 {
83 opt->run_func = run;
84 opt->run_data = client_data;
85 }
86
gavl_video_options_get_run_func(gavl_video_options_t * opt,void ** client_data)87 gavl_video_run_func gavl_video_options_get_run_func(gavl_video_options_t * opt,
88 void ** client_data)
89 {
90 *client_data = opt->run_data;
91 return opt->run_func;
92 }
93
94
gavl_video_options_set_stop_func(gavl_video_options_t * opt,void (* stop)(void * client_data,int thread),void * client_data)95 void gavl_video_options_set_stop_func(gavl_video_options_t * opt,
96 void (*stop)(void * client_data, int thread),
97 void * client_data)
98 {
99 opt->stop_func = stop;
100 opt->stop_data = client_data;
101 }
102
gavl_video_options_get_stop_func(gavl_video_options_t * opt,void ** client_data)103 gavl_video_stop_func gavl_video_options_get_stop_func(gavl_video_options_t * opt,
104 void ** client_data)
105 {
106 *client_data = opt->stop_data;
107 return opt->stop_func;
108 }
109
gavl_video_options_set_rectangles(gavl_video_options_t * opt,const gavl_rectangle_f_t * src_rect,const gavl_rectangle_i_t * dst_rect)110 void gavl_video_options_set_rectangles(gavl_video_options_t * opt,
111 const gavl_rectangle_f_t * src_rect,
112 const gavl_rectangle_i_t * dst_rect)
113 {
114 if(!src_rect || !dst_rect)
115 {
116 opt->have_rectangles = 0;
117 return;
118 }
119 gavl_rectangle_f_copy(&opt->src_rect, src_rect);
120 gavl_rectangle_i_copy(&opt->dst_rect, dst_rect);
121 opt->have_rectangles = 1;
122 }
123
gavl_video_options_get_rectangles(gavl_video_options_t * opt,gavl_rectangle_f_t * src_rect,gavl_rectangle_i_t * dst_rect)124 void gavl_video_options_get_rectangles(gavl_video_options_t * opt,
125 gavl_rectangle_f_t * src_rect,
126 gavl_rectangle_i_t * dst_rect)
127 {
128 gavl_rectangle_f_copy(src_rect, &opt->src_rect);
129 gavl_rectangle_i_copy(dst_rect, &opt->dst_rect);
130 }
131
132 #define SET_INT(p) opt->p = p
133
134
gavl_video_options_set_quality(gavl_video_options_t * opt,int quality)135 void gavl_video_options_set_quality(gavl_video_options_t * opt, int quality)
136 {
137 SET_INT(quality);
138 }
139
gavl_video_options_get_quality(gavl_video_options_t * opt)140 int gavl_video_options_get_quality(gavl_video_options_t * opt)
141 {
142 return opt->quality;
143 }
144
gavl_video_options_set_accel_flags(gavl_video_options_t * opt,int accel_flags)145 void gavl_video_options_set_accel_flags(gavl_video_options_t * opt,
146 int accel_flags)
147 {
148 SET_INT(accel_flags);
149 }
150
gavl_video_options_get_accel_flags(gavl_video_options_t * opt)151 int gavl_video_options_get_accel_flags(gavl_video_options_t * opt)
152 {
153 return opt->accel_flags;
154 }
155
gavl_video_options_set_conversion_flags(gavl_video_options_t * opt,int conversion_flags)156 void gavl_video_options_set_conversion_flags(gavl_video_options_t * opt,
157 int conversion_flags)
158 {
159 SET_INT(conversion_flags);
160 }
161
gavl_video_options_get_conversion_flags(gavl_video_options_t * opt)162 int gavl_video_options_get_conversion_flags(gavl_video_options_t * opt)
163 {
164 return opt->conversion_flags;
165 }
166
gavl_video_options_set_alpha_mode(gavl_video_options_t * opt,gavl_alpha_mode_t alpha_mode)167 void gavl_video_options_set_alpha_mode(gavl_video_options_t * opt,
168 gavl_alpha_mode_t alpha_mode)
169 {
170 SET_INT(alpha_mode);
171 }
172
173 gavl_alpha_mode_t
gavl_video_options_get_alpha_mode(gavl_video_options_t * opt)174 gavl_video_options_get_alpha_mode(gavl_video_options_t * opt)
175 {
176 return opt->alpha_mode;
177 }
178
gavl_video_options_set_scale_mode(gavl_video_options_t * opt,gavl_scale_mode_t scale_mode)179 void gavl_video_options_set_scale_mode(gavl_video_options_t * opt,
180 gavl_scale_mode_t scale_mode)
181 {
182 SET_INT(scale_mode);
183 }
184
gavl_video_options_get_scale_mode(gavl_video_options_t * opt)185 gavl_scale_mode_t gavl_video_options_get_scale_mode(gavl_video_options_t * opt)
186 {
187 return opt->scale_mode;
188 }
189
190
191
gavl_video_options_set_scale_order(gavl_video_options_t * opt,int scale_order)192 void gavl_video_options_set_scale_order(gavl_video_options_t * opt,
193 int scale_order)
194 {
195 SET_INT(scale_order);
196 }
197
gavl_video_options_get_scale_order(gavl_video_options_t * opt)198 int gavl_video_options_get_scale_order(gavl_video_options_t * opt)
199 {
200 return opt->scale_order;
201 }
202
203 void
gavl_video_options_set_deinterlace_mode(gavl_video_options_t * opt,gavl_deinterlace_mode_t deinterlace_mode)204 gavl_video_options_set_deinterlace_mode(gavl_video_options_t * opt,
205 gavl_deinterlace_mode_t deinterlace_mode)
206 {
207 SET_INT(deinterlace_mode);
208 }
209
210 gavl_deinterlace_mode_t
gavl_video_options_get_deinterlace_mode(gavl_video_options_t * opt)211 gavl_video_options_get_deinterlace_mode(gavl_video_options_t * opt)
212 {
213 return opt->deinterlace_mode;
214 }
215
216
217
218 void
gavl_video_options_set_deinterlace_drop_mode(gavl_video_options_t * opt,gavl_deinterlace_drop_mode_t deinterlace_drop_mode)219 gavl_video_options_set_deinterlace_drop_mode(gavl_video_options_t * opt,
220 gavl_deinterlace_drop_mode_t deinterlace_drop_mode)
221 {
222 SET_INT(deinterlace_drop_mode);
223 }
224
225 gavl_deinterlace_drop_mode_t
gavl_video_options_get_deinterlace_drop_mode(gavl_video_options_t * opt)226 gavl_video_options_get_deinterlace_drop_mode(gavl_video_options_t * opt)
227 {
228 return opt->deinterlace_drop_mode;
229 }
230
231 #undef SET_INT
232
233 #define CLIP_FLOAT(a) if(a < 0.0) a = 0.0; if(a>1.0) a = 1.0;
234
gavl_video_options_set_background_color(gavl_video_options_t * opt,const float * color)235 void gavl_video_options_set_background_color(gavl_video_options_t * opt,
236 const float * color)
237 {
238 memcpy(opt->background_float, color, 3*sizeof(*color));
239
240 CLIP_FLOAT(opt->background_float[0]);
241 CLIP_FLOAT(opt->background_float[1]);
242 CLIP_FLOAT(opt->background_float[2]);
243 opt->background_16[0] = (uint16_t)(opt->background_float[0] * 65535.0 + 0.5);
244 opt->background_16[1] = (uint16_t)(opt->background_float[1] * 65535.0 + 0.5);
245 opt->background_16[2] = (uint16_t)(opt->background_float[2] * 65535.0 + 0.5);
246
247 }
248
gavl_video_options_get_background_color(gavl_video_options_t * opt,float * color)249 void gavl_video_options_get_background_color(gavl_video_options_t * opt,
250 float * color)
251 {
252 memcpy(color, opt->background_float, 3*sizeof(*color));
253 }
254
gavl_video_options_set_downscale_filter(gavl_video_options_t * opt,gavl_downscale_filter_t f)255 void gavl_video_options_set_downscale_filter(gavl_video_options_t * opt,
256 gavl_downscale_filter_t f)
257 {
258 opt->downscale_filter = f;
259
260 }
261
262 gavl_downscale_filter_t
gavl_video_options_get_downscale_filter(gavl_video_options_t * opt)263 gavl_video_options_get_downscale_filter(gavl_video_options_t * opt)
264 {
265 return opt->downscale_filter;
266 }
267
gavl_video_options_set_downscale_blur(gavl_video_options_t * opt,float f)268 void gavl_video_options_set_downscale_blur(gavl_video_options_t * opt,
269 float f)
270 {
271 opt->downscale_blur = f;
272 }
273
274
275 /*! \ingroup video_options
276 * \brief Get blur factor for downscaling
277 * \param opt Video options
278 * \returns Factor
279 *
280 * Since 1.1.0
281 */
282
gavl_video_options_get_downscale_blur(gavl_video_options_t * opt)283 float gavl_video_options_get_downscale_blur(gavl_video_options_t * opt)
284 {
285 return opt->downscale_blur;
286 }
287
288
gavl_video_options_create()289 gavl_video_options_t * gavl_video_options_create()
290 {
291 gavl_video_options_t * ret = calloc(1, sizeof(*ret));
292 gavl_video_options_set_defaults(ret);
293 return ret;
294 }
295
gavl_video_options_copy(gavl_video_options_t * dst,const gavl_video_options_t * src)296 void gavl_video_options_copy(gavl_video_options_t * dst,
297 const gavl_video_options_t * src)
298 {
299 memcpy(dst, src, sizeof(*dst));
300 }
301
gavl_video_options_destroy(gavl_video_options_t * opt)302 void gavl_video_options_destroy(gavl_video_options_t * opt)
303 {
304 free(opt);
305 }
306
307