2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3 * Copyright (C) 2003 Ronald Bultje <rbultje@ronald.bitfreak.net>
4 * Copyright (C) 2005-2012 David Schleef <ds@schleef.org>
5 * Copyright (C) 2022 Thibault Saunier <tsaunier@igalia.com>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
24 * SECTION:element-videoconvertscale
25 * @title: videoconvertscale
27 * This element resizes video frames and allows changing colorspace. By default
28 * the element will try to negotiate to the same size on the source and sinkpad
29 * so that no scaling is needed. It is therefore safe to insert this element in
30 * a pipeline to get more robust behaviour without any cost if no scaling is
33 * This element supports a wide range of color spaces including various YUV and
34 * RGB formats and is therefore generally able to operate anywhere in a
37 * ## Example pipelines
39 * gst-launch-1.0 -v filesrc location=videotestsrc.ogg ! oggdemux ! theoradec ! videoconvertscale ! autovideosink
41 * Decode an Ogg/Theora and display the video. If the video sink chosen
42 * cannot perform scaling, the video scaling will be performed by videoconvertscale
43 * when you resize the video window.
44 * To create the test Ogg/Theora file refer to the documentation of theoraenc.
46 * gst-launch-1.0 -v filesrc location=videotestsrc.ogg ! oggdemux ! theoradec ! videoconvertscale ! video/x-raw,width=100 ! autovideosink
48 * Decode an Ogg/Theora and display the video with a width of 100.
54 * Formulas for PAR, DAR, width and height relations:
65 * w = h * ----- * -----
69 * h = w * ----- * -----
81 #include <gst/video/gstvideometa.h>
82 #include <gst/video/gstvideopool.h>
84 #include "gstvideoconvertscale.h"
89 GstVideoScaleMethod method;
96 GstVideoDitherMethod dither;
97 guint dither_quantization;
98 GstVideoResamplerMethod chroma_resampler;
99 GstVideoAlphaMode alpha_mode;
100 GstVideoChromaMode chroma_mode;
101 GstVideoMatrixMode matrix_mode;
102 GstVideoGammaMode gamma_mode;
103 GstVideoPrimariesMode primaries_mode;
106 GstVideoConverter *convert;
110 } GstVideoConvertScalePrivate;
112 #define gst_video_convert_scale_parent_class parent_class
113 G_DEFINE_TYPE_WITH_PRIVATE (GstVideoConvertScale, gst_video_convert_scale,
114 GST_TYPE_VIDEO_FILTER);
115 GST_ELEMENT_REGISTER_DEFINE (videoconvertscale, "videoconvertscale",
116 GST_RANK_SECONDARY, GST_TYPE_VIDEO_CONVERT_SCALE);
118 #define PRIV(self) gst_video_convert_scale_get_instance_private(((GstVideoConvertScale*) self))
120 #define GST_CAT_DEFAULT video_convertscale_debug
121 GST_DEBUG_CATEGORY_STATIC (video_convertscale_debug);
122 GST_DEBUG_CATEGORY_STATIC (CAT_PERFORMANCE);
124 #define DEFAULT_PROP_METHOD GST_VIDEO_SCALE_BILINEAR
125 #define DEFAULT_PROP_ADD_BORDERS TRUE
126 #define DEFAULT_PROP_SHARPNESS 1.0
127 #define DEFAULT_PROP_SHARPEN 0.0
128 #define DEFAULT_PROP_DITHER GST_VIDEO_DITHER_BAYER
129 #define DEFAULT_PROP_ENVELOPE 2.0
130 #define DEFAULT_PROP_DITHER_QUANTIZATION 1
131 #define DEFAULT_PROP_CHROMA_RESAMPLER GST_VIDEO_RESAMPLER_METHOD_LINEAR
132 #define DEFAULT_PROP_ALPHA_MODE GST_VIDEO_ALPHA_MODE_COPY
133 #define DEFAULT_PROP_ALPHA_VALUE 1.0
134 #define DEFAULT_PROP_CHROMA_MODE GST_VIDEO_CHROMA_MODE_FULL
135 #define DEFAULT_PROP_MATRIX_MODE GST_VIDEO_MATRIX_MODE_FULL
136 #define DEFAULT_PROP_GAMMA_MODE GST_VIDEO_GAMMA_MODE_NONE
137 #define DEFAULT_PROP_PRIMARIES_MODE GST_VIDEO_PRIMARIES_MODE_NONE
138 #define DEFAULT_PROP_N_THREADS 1
140 static GQuark _colorspace_quark;
153 PROP_DITHER_QUANTIZATION,
154 PROP_CHROMA_RESAMPLER,
163 #undef GST_VIDEO_SIZE_RANGE
164 #define GST_VIDEO_SIZE_RANGE "(int) [ 1, 32767]"
166 /* FIXME: add v210 support
167 * FIXME: add v216 support
168 * FIXME: add UYVP support
169 * FIXME: add A420 support
170 * FIXME: add YUV9 support
171 * FIXME: add YVU9 support
172 * FIXME: add IYU1 support
173 * FIXME: add r210 support
176 #define GST_VIDEO_FORMATS GST_VIDEO_FORMATS_ALL
178 static GstStaticCaps gst_video_convert_scale_format_caps =
179 GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE (GST_VIDEO_FORMATS) ";"
180 GST_VIDEO_CAPS_MAKE_WITH_FEATURES ("ANY", GST_VIDEO_FORMATS));
182 static GQuark _size_quark;
183 static GQuark _scale_quark;
185 #define GST_TYPE_VIDEO_SCALE_METHOD (gst_video_scale_method_get_type())
187 gst_video_scale_method_get_type (void)
189 static GType video_scale_method_type = 0;
191 static const GEnumValue video_scale_methods[] = {
192 {GST_VIDEO_SCALE_NEAREST, "Nearest Neighbour", "nearest-neighbour"},
193 {GST_VIDEO_SCALE_BILINEAR, "Bilinear (2-tap)", "bilinear"},
194 {GST_VIDEO_SCALE_4TAP, "4-tap Sinc", "4-tap"},
195 {GST_VIDEO_SCALE_LANCZOS, "Lanczos", "lanczos"},
196 {GST_VIDEO_SCALE_BILINEAR2, "Bilinear (multi-tap)", "bilinear2"},
197 {GST_VIDEO_SCALE_SINC, "Sinc (multi-tap)", "sinc"},
198 {GST_VIDEO_SCALE_HERMITE, "Hermite (multi-tap)", "hermite"},
199 {GST_VIDEO_SCALE_SPLINE, "Spline (multi-tap)", "spline"},
200 {GST_VIDEO_SCALE_CATROM, "Catmull-Rom (multi-tap)", "catrom"},
201 {GST_VIDEO_SCALE_MITCHELL, "Mitchell (multi-tap)", "mitchell"},
205 if (!video_scale_method_type) {
206 video_scale_method_type =
207 g_enum_register_static ("GstVideoScaleMethod", video_scale_methods);
209 return video_scale_method_type;
213 gst_video_convert_scale_get_capslist (void)
215 static GstCaps *caps = NULL;
216 static gsize inited = 0;
218 if (g_once_init_enter (&inited)) {
219 caps = gst_static_caps_get (&gst_video_convert_scale_format_caps);
220 g_once_init_leave (&inited, 1);
225 static GstPadTemplate *
226 gst_video_convert_scale_src_template_factory (void)
228 return gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
229 gst_video_convert_scale_get_capslist ());
232 static GstPadTemplate *
233 gst_video_convert_scale_sink_template_factory (void)
235 return gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
236 gst_video_convert_scale_get_capslist ());
240 static void gst_video_convert_scale_finalize (GstVideoConvertScale * self);
241 static gboolean gst_video_convert_scale_src_event (GstBaseTransform * trans,
244 /* base transform vmethods */
245 static GstCaps *gst_video_convert_scale_transform_caps (GstBaseTransform *
246 trans, GstPadDirection direction, GstCaps * caps, GstCaps * filter);
247 static GstCaps *gst_video_convert_scale_fixate_caps (GstBaseTransform * base,
248 GstPadDirection direction, GstCaps * caps, GstCaps * othercaps);
249 static gboolean gst_video_convert_scale_transform_meta (GstBaseTransform *
250 trans, GstBuffer * outbuf, GstMeta * meta, GstBuffer * inbuf);
252 static gboolean gst_video_convert_scale_set_info (GstVideoFilter * filter,
253 GstCaps * in, GstVideoInfo * in_info, GstCaps * out,
254 GstVideoInfo * out_info);
255 static GstFlowReturn gst_video_convert_scale_transform_frame (GstVideoFilter *
256 filter, GstVideoFrame * in, GstVideoFrame * out);
258 static void gst_video_convert_scale_set_property (GObject * object,
259 guint prop_id, const GValue * value, GParamSpec * pspec);
260 static void gst_video_convert_scale_get_property (GObject * object,
261 guint prop_id, GValue * value, GParamSpec * pspec);
263 static GstCapsFeatures *features_format_interlaced,
264 *features_format_interlaced_sysmem;
267 gst_video_convert_scale_filter_meta (GstBaseTransform * trans, GstQuery * query,
268 GType api, const GstStructure * params)
270 /* This element cannot passthrough the crop meta, because it would convert the
271 * wrong sub-region of the image, and worst, our output image may not be large
272 * enough for the crop to be applied later */
273 if (api == GST_VIDEO_CROP_META_API_TYPE)
276 /* propose all other metadata upstream */
281 gst_video_convert_scale_class_init (GstVideoConvertScaleClass * klass)
283 GObjectClass *gobject_class = (GObjectClass *) klass;
284 GstElementClass *element_class = (GstElementClass *) klass;
285 GstBaseTransformClass *trans_class = (GstBaseTransformClass *) klass;
286 GstVideoFilterClass *filter_class = (GstVideoFilterClass *) klass;
288 GST_DEBUG_CATEGORY_INIT (video_convertscale_debug, "videoconvertscale", 0,
289 "videoconvertscale element");
290 GST_DEBUG_CATEGORY_GET (CAT_PERFORMANCE, "GST_PERFORMANCE");
292 features_format_interlaced =
293 gst_caps_features_new (GST_CAPS_FEATURE_FORMAT_INTERLACED, NULL);
294 features_format_interlaced_sysmem =
295 gst_caps_features_copy (features_format_interlaced);
296 gst_caps_features_add (features_format_interlaced_sysmem,
297 GST_CAPS_FEATURE_MEMORY_SYSTEM_MEMORY);
299 _colorspace_quark = g_quark_from_static_string ("colorspace");
301 gobject_class->finalize =
302 (GObjectFinalizeFunc) gst_video_convert_scale_finalize;
303 gobject_class->set_property = gst_video_convert_scale_set_property;
304 gobject_class->get_property = gst_video_convert_scale_get_property;
306 g_object_class_install_property (gobject_class, PROP_METHOD,
307 g_param_spec_enum ("method", "method", "method",
308 GST_TYPE_VIDEO_SCALE_METHOD, DEFAULT_PROP_METHOD,
309 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
311 g_object_class_install_property (gobject_class, PROP_ADD_BORDERS,
312 g_param_spec_boolean ("add-borders", "Add Borders",
313 "Add black borders if necessary to keep the display aspect ratio",
314 DEFAULT_PROP_ADD_BORDERS,
315 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
317 g_object_class_install_property (gobject_class, PROP_SHARPNESS,
318 g_param_spec_double ("sharpness", "Sharpness",
319 "Sharpness of filter", 0.5, 1.5, DEFAULT_PROP_SHARPNESS,
320 G_PARAM_CONSTRUCT | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
322 g_object_class_install_property (gobject_class, PROP_SHARPEN,
323 g_param_spec_double ("sharpen", "Sharpen",
324 "Sharpening", 0.0, 1.0, DEFAULT_PROP_SHARPEN,
325 G_PARAM_CONSTRUCT | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
327 g_object_class_install_property (gobject_class, PROP_DITHER,
328 g_param_spec_enum ("dither", "Dither", "Apply dithering while converting",
329 gst_video_dither_method_get_type (), DEFAULT_PROP_DITHER,
330 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
331 g_object_class_install_property (gobject_class, PROP_ENVELOPE,
332 g_param_spec_double ("envelope", "Envelope",
333 "Size of filter envelope", 1.0, 5.0, DEFAULT_PROP_ENVELOPE,
334 G_PARAM_CONSTRUCT | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
336 g_object_class_install_property (gobject_class, PROP_N_THREADS,
337 g_param_spec_uint ("n-threads", "Threads",
338 "Maximum number of threads to use", 0, G_MAXUINT,
339 DEFAULT_PROP_N_THREADS,
340 G_PARAM_CONSTRUCT | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
342 g_object_class_install_property (gobject_class, PROP_DITHER_QUANTIZATION,
343 g_param_spec_uint ("dither-quantization", "Dither Quantize",
344 "Quantizer to use", 0, G_MAXUINT, DEFAULT_PROP_DITHER_QUANTIZATION,
345 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
346 g_object_class_install_property (gobject_class, PROP_CHROMA_RESAMPLER,
347 g_param_spec_enum ("chroma-resampler", "Chroma resampler",
348 "Chroma resampler method", gst_video_resampler_method_get_type (),
349 DEFAULT_PROP_CHROMA_RESAMPLER,
350 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
351 g_object_class_install_property (gobject_class, PROP_ALPHA_MODE,
352 g_param_spec_enum ("alpha-mode", "Alpha Mode",
353 "Alpha Mode to use", gst_video_alpha_mode_get_type (),
354 DEFAULT_PROP_ALPHA_MODE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
355 g_object_class_install_property (gobject_class, PROP_ALPHA_VALUE,
356 g_param_spec_double ("alpha-value", "Alpha Value",
357 "Alpha Value to use", 0.0, 1.0,
358 DEFAULT_PROP_ALPHA_VALUE,
359 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
360 g_object_class_install_property (gobject_class, PROP_CHROMA_MODE,
361 g_param_spec_enum ("chroma-mode", "Chroma Mode", "Chroma Resampling Mode",
362 gst_video_chroma_mode_get_type (), DEFAULT_PROP_CHROMA_MODE,
363 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
364 g_object_class_install_property (gobject_class, PROP_MATRIX_MODE,
365 g_param_spec_enum ("matrix-mode", "Matrix Mode", "Matrix Conversion Mode",
366 gst_video_matrix_mode_get_type (), DEFAULT_PROP_MATRIX_MODE,
367 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
368 g_object_class_install_property (gobject_class, PROP_GAMMA_MODE,
369 g_param_spec_enum ("gamma-mode", "Gamma Mode", "Gamma Conversion Mode",
370 gst_video_gamma_mode_get_type (), DEFAULT_PROP_GAMMA_MODE,
371 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
372 g_object_class_install_property (gobject_class, PROP_PRIMARIES_MODE,
373 g_param_spec_enum ("primaries-mode", "Primaries Mode",
374 "Primaries Conversion Mode", gst_video_primaries_mode_get_type (),
375 DEFAULT_PROP_PRIMARIES_MODE,
376 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
378 gst_element_class_set_static_metadata (element_class,
379 "Video colorspace converter and scaler",
380 "Filter/Converter/Video/Scaler/Colorspace",
381 "Converts video from one colorspace to another",
382 "Wim Taymans <wim.taymans@gmail.com>");
384 gst_element_class_add_pad_template (element_class,
385 gst_video_convert_scale_sink_template_factory ());
386 gst_element_class_add_pad_template (element_class,
387 gst_video_convert_scale_src_template_factory ());
389 _size_quark = g_quark_from_static_string (GST_META_TAG_VIDEO_SIZE_STR);
390 _scale_quark = gst_video_meta_transform_scale_get_quark ();
392 gst_type_mark_as_plugin_api (GST_TYPE_VIDEO_SCALE_METHOD, 0);
393 trans_class->transform_caps =
394 GST_DEBUG_FUNCPTR (gst_video_convert_scale_transform_caps);
395 trans_class->fixate_caps =
396 GST_DEBUG_FUNCPTR (gst_video_convert_scale_fixate_caps);
397 trans_class->filter_meta =
398 GST_DEBUG_FUNCPTR (gst_video_convert_scale_filter_meta);
399 trans_class->src_event =
400 GST_DEBUG_FUNCPTR (gst_video_convert_scale_src_event);
401 trans_class->transform_meta =
402 GST_DEBUG_FUNCPTR (gst_video_convert_scale_transform_meta);
404 filter_class->set_info = GST_DEBUG_FUNCPTR (gst_video_convert_scale_set_info);
405 filter_class->transform_frame =
406 GST_DEBUG_FUNCPTR (gst_video_convert_scale_transform_frame);
408 klass->any_memory = FALSE;
409 klass->converts = TRUE;
410 klass->scales = TRUE;
414 gst_video_convert_scale_init (GstVideoConvertScale * self)
416 GstVideoConvertScalePrivate *priv = PRIV (self);
418 priv->method = DEFAULT_PROP_METHOD;
419 priv->add_borders = DEFAULT_PROP_ADD_BORDERS;
420 priv->sharpness = DEFAULT_PROP_SHARPNESS;
421 priv->sharpen = DEFAULT_PROP_SHARPEN;
422 priv->envelope = DEFAULT_PROP_ENVELOPE;
423 priv->n_threads = DEFAULT_PROP_N_THREADS;
424 priv->dither = DEFAULT_PROP_DITHER;
425 priv->dither_quantization = DEFAULT_PROP_DITHER_QUANTIZATION;
426 priv->chroma_resampler = DEFAULT_PROP_CHROMA_RESAMPLER;
427 priv->alpha_mode = DEFAULT_PROP_ALPHA_MODE;
428 priv->alpha_value = DEFAULT_PROP_ALPHA_VALUE;
429 priv->chroma_mode = DEFAULT_PROP_CHROMA_MODE;
430 priv->matrix_mode = DEFAULT_PROP_MATRIX_MODE;
431 priv->gamma_mode = DEFAULT_PROP_GAMMA_MODE;
432 priv->primaries_mode = DEFAULT_PROP_PRIMARIES_MODE;
436 gst_video_convert_scale_finalize (GstVideoConvertScale * self)
438 GstVideoConvertScalePrivate *priv = PRIV (self);
441 gst_video_converter_free (priv->convert);
443 G_OBJECT_CLASS (parent_class)->finalize (G_OBJECT (self));
447 gst_video_convert_scale_set_property (GObject * object, guint prop_id,
448 const GValue * value, GParamSpec * pspec)
450 GstVideoConvertScalePrivate *priv = PRIV (object);
452 GST_OBJECT_LOCK (object);
455 priv->method = g_value_get_enum (value);
457 case PROP_ADD_BORDERS:
458 priv->add_borders = g_value_get_boolean (value);
459 GST_OBJECT_UNLOCK (object);
461 gst_base_transform_reconfigure_src (GST_BASE_TRANSFORM_CAST (object));
464 priv->sharpness = g_value_get_double (value);
467 priv->sharpen = g_value_get_double (value);
470 priv->submethod = g_value_get_int (value);
473 priv->envelope = g_value_get_double (value);
476 priv->n_threads = g_value_get_uint (value);
479 priv->dither = g_value_get_enum (value);
481 case PROP_CHROMA_RESAMPLER:
482 priv->chroma_resampler = g_value_get_enum (value);
484 case PROP_ALPHA_MODE:
485 priv->alpha_mode = g_value_get_enum (value);
487 case PROP_ALPHA_VALUE:
488 priv->alpha_value = g_value_get_double (value);
490 case PROP_CHROMA_MODE:
491 priv->chroma_mode = g_value_get_enum (value);
493 case PROP_MATRIX_MODE:
494 priv->matrix_mode = g_value_get_enum (value);
496 case PROP_GAMMA_MODE:
497 priv->gamma_mode = g_value_get_enum (value);
499 case PROP_PRIMARIES_MODE:
500 priv->primaries_mode = g_value_get_enum (value);
502 case PROP_DITHER_QUANTIZATION:
503 priv->dither_quantization = g_value_get_uint (value);
506 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
509 GST_OBJECT_UNLOCK (object);
513 gst_video_convert_scale_get_property (GObject * object, guint prop_id,
514 GValue * value, GParamSpec * pspec)
516 GstVideoConvertScalePrivate *priv = PRIV (object);
518 GST_OBJECT_LOCK (object);
521 g_value_set_enum (value, priv->method);
523 case PROP_ADD_BORDERS:
524 g_value_set_boolean (value, priv->add_borders);
527 g_value_set_double (value, priv->sharpness);
530 g_value_set_double (value, priv->sharpen);
533 g_value_set_int (value, priv->submethod);
536 g_value_set_double (value, priv->envelope);
539 g_value_set_uint (value, priv->n_threads);
542 g_value_set_enum (value, priv->dither);
544 case PROP_CHROMA_RESAMPLER:
545 g_value_set_enum (value, priv->chroma_resampler);
547 case PROP_ALPHA_MODE:
548 g_value_set_enum (value, priv->alpha_mode);
550 case PROP_ALPHA_VALUE:
551 g_value_set_double (value, priv->alpha_value);
553 case PROP_CHROMA_MODE:
554 g_value_set_enum (value, priv->chroma_mode);
556 case PROP_MATRIX_MODE:
557 g_value_set_enum (value, priv->matrix_mode);
559 case PROP_GAMMA_MODE:
560 g_value_set_enum (value, priv->gamma_mode);
562 case PROP_PRIMARIES_MODE:
563 g_value_set_enum (value, priv->primaries_mode);
565 case PROP_DITHER_QUANTIZATION:
566 g_value_set_uint (value, priv->dither_quantization);
569 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
572 GST_OBJECT_UNLOCK (object);
576 gst_video_convert_caps_remove_format_and_rangify_size_info (GstVideoConvertScale
577 * self, GstCaps * caps)
579 GstVideoConvertScaleClass *klass = GST_VIDEO_CONVERT_SCALE_GET_CLASS (self);
581 GstStructure *structure;
582 GstCapsFeatures *features;
585 ret = gst_caps_new_empty ();
587 n = gst_caps_get_size (caps);
588 for (i = 0; i < n; i++) {
589 structure = gst_caps_get_structure (caps, i);
590 features = gst_caps_get_features (caps, i);
592 /* If this is already expressed by the existing caps
593 * skip this structure */
594 if (i > 0 && gst_caps_is_subset_structure_full (ret, structure, features))
597 structure = gst_structure_copy (structure);
598 /* Only remove format info for the cases when we can actually convert */
599 if (!gst_caps_features_is_any (features)
600 && (gst_caps_features_is_equal (features,
601 GST_CAPS_FEATURES_MEMORY_SYSTEM_MEMORY)
602 || gst_caps_features_is_equal (features, features_format_interlaced)
603 || gst_caps_features_is_equal (features,
604 features_format_interlaced_sysmem))) {
606 gst_structure_set (structure, "width", GST_TYPE_INT_RANGE, 1, G_MAXINT,
607 "height", GST_TYPE_INT_RANGE, 1, G_MAXINT, NULL);
608 /* if pixel aspect ratio, make a range of it */
609 if (gst_structure_has_field (structure, "pixel-aspect-ratio")) {
610 gst_structure_set (structure, "pixel-aspect-ratio",
611 GST_TYPE_FRACTION_RANGE, 1, G_MAXINT, G_MAXINT, 1, NULL);
615 if (klass->converts) {
616 gst_structure_remove_fields (structure, "format", "colorimetry",
617 "chroma-site", NULL);
620 gst_caps_append_structure_full (ret, structure,
621 gst_caps_features_copy (features));
628 gst_video_convert_scale_transform_caps (GstBaseTransform * trans,
629 GstPadDirection direction, GstCaps * caps, GstCaps * filter)
631 GstVideoConvertScale *self = GST_VIDEO_CONVERT_SCALE (trans);
635 GST_DEBUG_OBJECT (trans,
636 "Transforming caps %" GST_PTR_FORMAT " in direction %s", caps,
637 (direction == GST_PAD_SINK) ? "sink" : "src");
639 ret = gst_video_convert_caps_remove_format_and_rangify_size_info (self, caps);
641 GstCaps *intersection;
644 gst_caps_intersect_full (filter, ret, GST_CAPS_INTERSECT_FIRST);
645 gst_caps_unref (ret);
649 if (GST_VIDEO_CONVERT_SCALE_GET_CLASS (trans)->any_memory)
652 for (i = 0; i < gst_caps_get_size (ret); i++) {
654 GstCapsFeatures *f = gst_caps_get_features (ret, i);
656 if (!f || gst_caps_features_is_any (f) ||
657 gst_caps_features_is_equal (f, GST_CAPS_FEATURES_MEMORY_SYSTEM_MEMORY))
660 for (j = 0; j < gst_caps_features_get_size (f); j++) {
661 const gchar *feature = gst_caps_features_get_nth (f, j);
663 if (g_str_has_prefix (feature, "memory:")) {
664 GST_DEBUG_OBJECT (trans, "Can not work with memory `%s`", feature);
665 gst_caps_remove_structure (ret, i);
671 GST_DEBUG_OBJECT (trans, "returning caps: %" GST_PTR_FORMAT, ret);
677 gst_video_convert_scale_transform_meta (GstBaseTransform * trans,
678 GstBuffer * outbuf, GstMeta * meta, GstBuffer * inbuf)
680 GstVideoFilter *videofilter = GST_VIDEO_FILTER (trans);
681 const GstMetaInfo *info = meta->info;
682 const gchar *const *tags;
683 const gchar *const *curr = NULL;
684 gboolean should_copy = TRUE;
685 const gchar *const valid_tags[] = {
686 GST_META_TAG_VIDEO_STR,
687 GST_META_TAG_VIDEO_ORIENTATION_STR,
688 GST_META_TAG_VIDEO_SIZE_STR,
691 tags = gst_meta_api_type_get_tags (info->api);
693 /* No specific tags, we are good to copy */
698 if (gst_meta_api_type_has_tag (info->api, _colorspace_quark)) {
699 /* don't copy colorspace specific metadata, FIXME, we need a MetaTransform
700 * for the colorspace metadata. */
704 /* We are only changing size, we can preserve other metas tagged as
705 orientation and colorspace */
706 for (curr = tags; *curr; ++curr) {
708 /* We dont handle any other tag */
709 if (!g_strv_contains (valid_tags, *curr)) {
715 /* Cant handle the tags in this meta, let the parent class handle it */
717 return GST_BASE_TRANSFORM_CLASS (parent_class)->transform_meta (trans,
718 outbuf, meta, inbuf);
721 /* This meta is size sensitive, try to transform it accordingly */
722 if (gst_meta_api_type_has_tag (info->api, _size_quark)) {
723 GstVideoMetaTransform trans =
724 { &videofilter->in_info, &videofilter->out_info };
726 if (info->transform_func)
727 info->transform_func (outbuf, meta, inbuf, _scale_quark, &trans);
731 /* No need to transform, we can safely copy this meta */
736 gst_video_convert_scale_set_info (GstVideoFilter * filter, GstCaps * in,
737 GstVideoInfo * in_info, GstCaps * out, GstVideoInfo * out_info)
739 GstVideoConvertScale *self = GST_VIDEO_CONVERT_SCALE (filter);
740 GstVideoConvertScalePrivate *priv = PRIV (self);
741 gint from_dar_n, from_dar_d, to_dar_n, to_dar_d;
742 GstVideoInfo tmp_info;
745 gst_video_converter_free (priv->convert);
746 priv->convert = NULL;
749 if (!gst_util_fraction_multiply (in_info->width,
750 in_info->height, in_info->par_n, in_info->par_d, &from_dar_n,
752 from_dar_n = from_dar_d = -1;
755 if (!gst_util_fraction_multiply (out_info->width,
756 out_info->height, out_info->par_n, out_info->par_d, &to_dar_n,
758 to_dar_n = to_dar_d = -1;
761 priv->borders_w = priv->borders_h = 0;
762 if (to_dar_n != from_dar_n || to_dar_d != from_dar_d) {
763 if (priv->add_borders) {
764 gint n, d, to_h, to_w;
766 if (from_dar_n != -1 && from_dar_d != -1
767 && gst_util_fraction_multiply (from_dar_n, from_dar_d,
768 out_info->par_d, out_info->par_n, &n, &d)) {
769 to_h = gst_util_uint64_scale_int (out_info->width, d, n);
770 if (to_h <= out_info->height) {
771 priv->borders_h = out_info->height - to_h;
774 to_w = gst_util_uint64_scale_int (out_info->height, n, d);
775 g_assert (to_w <= out_info->width);
777 priv->borders_w = out_info->width - to_w;
780 GST_WARNING_OBJECT (self, "Can't calculate borders");
783 GST_WARNING_OBJECT (self, "Can't keep DAR!");
787 /* if present, these must match */
788 if (in_info->interlace_mode != out_info->interlace_mode)
789 goto format_mismatch;
791 /* if the only thing different in the caps is the transfer function, and
792 * we're converting between equivalent transfer functions, do passthrough */
794 tmp_info.colorimetry.transfer = out_info->colorimetry.transfer;
795 if (gst_video_info_is_equal (&tmp_info, out_info)) {
796 if (gst_video_transfer_function_is_equivalent (in_info->colorimetry.
797 transfer, in_info->finfo->bits, out_info->colorimetry.transfer,
798 out_info->finfo->bits)) {
799 gst_base_transform_set_passthrough (GST_BASE_TRANSFORM (filter), TRUE);
802 GstStructure *options;
803 GST_CAT_DEBUG_OBJECT (CAT_PERFORMANCE, filter, "setup videoscaling");
804 gst_base_transform_set_passthrough (GST_BASE_TRANSFORM (filter), FALSE);
806 options = gst_structure_new_empty ("videoconvertscale");
808 switch (priv->method) {
809 case GST_VIDEO_SCALE_NEAREST:
810 gst_structure_set (options,
811 GST_VIDEO_CONVERTER_OPT_RESAMPLER_METHOD,
812 GST_TYPE_VIDEO_RESAMPLER_METHOD, GST_VIDEO_RESAMPLER_METHOD_NEAREST,
815 case GST_VIDEO_SCALE_BILINEAR:
816 gst_structure_set (options,
817 GST_VIDEO_CONVERTER_OPT_RESAMPLER_METHOD,
818 GST_TYPE_VIDEO_RESAMPLER_METHOD, GST_VIDEO_RESAMPLER_METHOD_LINEAR,
819 GST_VIDEO_RESAMPLER_OPT_MAX_TAPS, G_TYPE_INT, 2, NULL);
821 case GST_VIDEO_SCALE_4TAP:
822 gst_structure_set (options,
823 GST_VIDEO_CONVERTER_OPT_RESAMPLER_METHOD,
824 GST_TYPE_VIDEO_RESAMPLER_METHOD, GST_VIDEO_RESAMPLER_METHOD_SINC,
825 GST_VIDEO_RESAMPLER_OPT_MAX_TAPS, G_TYPE_INT, 4, NULL);
827 case GST_VIDEO_SCALE_LANCZOS:
828 gst_structure_set (options,
829 GST_VIDEO_CONVERTER_OPT_RESAMPLER_METHOD,
830 GST_TYPE_VIDEO_RESAMPLER_METHOD, GST_VIDEO_RESAMPLER_METHOD_LANCZOS,
833 case GST_VIDEO_SCALE_BILINEAR2:
834 gst_structure_set (options,
835 GST_VIDEO_CONVERTER_OPT_RESAMPLER_METHOD,
836 GST_TYPE_VIDEO_RESAMPLER_METHOD, GST_VIDEO_RESAMPLER_METHOD_LINEAR,
839 case GST_VIDEO_SCALE_SINC:
840 gst_structure_set (options,
841 GST_VIDEO_CONVERTER_OPT_RESAMPLER_METHOD,
842 GST_TYPE_VIDEO_RESAMPLER_METHOD, GST_VIDEO_RESAMPLER_METHOD_SINC,
845 case GST_VIDEO_SCALE_HERMITE:
846 gst_structure_set (options,
847 GST_VIDEO_CONVERTER_OPT_RESAMPLER_METHOD,
848 GST_TYPE_VIDEO_RESAMPLER_METHOD, GST_VIDEO_RESAMPLER_METHOD_CUBIC,
849 GST_VIDEO_RESAMPLER_OPT_CUBIC_B, G_TYPE_DOUBLE, (gdouble) 0.0,
850 GST_VIDEO_RESAMPLER_OPT_CUBIC_C, G_TYPE_DOUBLE, (gdouble) 0.0,
853 case GST_VIDEO_SCALE_SPLINE:
854 gst_structure_set (options,
855 GST_VIDEO_CONVERTER_OPT_RESAMPLER_METHOD,
856 GST_TYPE_VIDEO_RESAMPLER_METHOD, GST_VIDEO_RESAMPLER_METHOD_CUBIC,
857 GST_VIDEO_RESAMPLER_OPT_CUBIC_B, G_TYPE_DOUBLE, (gdouble) 1.0,
858 GST_VIDEO_RESAMPLER_OPT_CUBIC_C, G_TYPE_DOUBLE, (gdouble) 0.0,
861 case GST_VIDEO_SCALE_CATROM:
862 gst_structure_set (options,
863 GST_VIDEO_CONVERTER_OPT_RESAMPLER_METHOD,
864 GST_TYPE_VIDEO_RESAMPLER_METHOD, GST_VIDEO_RESAMPLER_METHOD_CUBIC,
865 GST_VIDEO_RESAMPLER_OPT_CUBIC_B, G_TYPE_DOUBLE, (gdouble) 0.0,
866 GST_VIDEO_RESAMPLER_OPT_CUBIC_C, G_TYPE_DOUBLE, (gdouble) 0.5,
869 case GST_VIDEO_SCALE_MITCHELL:
870 gst_structure_set (options,
871 GST_VIDEO_CONVERTER_OPT_RESAMPLER_METHOD,
872 GST_TYPE_VIDEO_RESAMPLER_METHOD, GST_VIDEO_RESAMPLER_METHOD_CUBIC,
873 GST_VIDEO_RESAMPLER_OPT_CUBIC_B, G_TYPE_DOUBLE, (gdouble) 1.0 / 3.0,
874 GST_VIDEO_RESAMPLER_OPT_CUBIC_C, G_TYPE_DOUBLE, (gdouble) 1.0 / 3.0,
878 gst_structure_set (options,
879 GST_VIDEO_RESAMPLER_OPT_ENVELOPE, G_TYPE_DOUBLE, priv->envelope,
880 GST_VIDEO_RESAMPLER_OPT_SHARPNESS, G_TYPE_DOUBLE, priv->sharpness,
881 GST_VIDEO_RESAMPLER_OPT_SHARPEN, G_TYPE_DOUBLE, priv->sharpen,
882 GST_VIDEO_CONVERTER_OPT_DEST_X, G_TYPE_INT, priv->borders_w / 2,
883 GST_VIDEO_CONVERTER_OPT_DEST_Y, G_TYPE_INT, priv->borders_h / 2,
884 GST_VIDEO_CONVERTER_OPT_DEST_WIDTH, G_TYPE_INT,
885 out_info->width - priv->borders_w, GST_VIDEO_CONVERTER_OPT_DEST_HEIGHT,
886 G_TYPE_INT, out_info->height - priv->borders_h,
887 GST_VIDEO_CONVERTER_OPT_DITHER_METHOD, GST_TYPE_VIDEO_DITHER_METHOD,
888 priv->dither, GST_VIDEO_CONVERTER_OPT_DITHER_QUANTIZATION, G_TYPE_UINT,
889 priv->dither_quantization,
890 GST_VIDEO_CONVERTER_OPT_CHROMA_RESAMPLER_METHOD,
891 GST_TYPE_VIDEO_RESAMPLER_METHOD, priv->chroma_resampler,
892 GST_VIDEO_CONVERTER_OPT_ALPHA_MODE, GST_TYPE_VIDEO_ALPHA_MODE,
893 priv->alpha_mode, GST_VIDEO_CONVERTER_OPT_ALPHA_VALUE, G_TYPE_DOUBLE,
894 priv->alpha_value, GST_VIDEO_CONVERTER_OPT_CHROMA_MODE,
895 GST_TYPE_VIDEO_CHROMA_MODE, priv->chroma_mode,
896 GST_VIDEO_CONVERTER_OPT_MATRIX_MODE, GST_TYPE_VIDEO_MATRIX_MODE,
897 priv->matrix_mode, GST_VIDEO_CONVERTER_OPT_GAMMA_MODE,
898 GST_TYPE_VIDEO_GAMMA_MODE, priv->gamma_mode,
899 GST_VIDEO_CONVERTER_OPT_PRIMARIES_MODE, GST_TYPE_VIDEO_PRIMARIES_MODE,
900 priv->primaries_mode, GST_VIDEO_CONVERTER_OPT_THREADS, G_TYPE_UINT,
901 priv->n_threads, NULL);
903 priv->convert = gst_video_converter_new (in_info, out_info, options);
904 if (priv->convert == NULL)
908 GST_DEBUG_OBJECT (filter, "converting format %s -> %s",
909 gst_video_format_to_string (GST_VIDEO_INFO_FORMAT (in_info)),
910 gst_video_format_to_string (GST_VIDEO_INFO_FORMAT (out_info)));
911 GST_DEBUG_OBJECT (self, "from=%dx%d (par=%d/%d dar=%d/%d), size %"
912 G_GSIZE_FORMAT " -> to=%dx%d (par=%d/%d dar=%d/%d borders=%d:%d), "
913 "size %" G_GSIZE_FORMAT,
914 in_info->width, in_info->height, in_info->par_n, in_info->par_d,
915 from_dar_n, from_dar_d, in_info->size, out_info->width,
916 out_info->height, out_info->par_n, out_info->par_d, to_dar_n, to_dar_d,
917 priv->borders_w, priv->borders_h, out_info->size);
924 GST_ERROR_OBJECT (self, "input and output formats do not match");
929 GST_ERROR_OBJECT (self, "could not create converter");
935 * This is an incomplete matrix of in formats and a score for the preferred output
938 * out: RGB24 RGB16 ARGB AYUV YUV444 YUV422 YUV420 YUV411 YUV410 PAL GRAY
940 * RGB24 0 2 1 2 2 3 4 5 6 7 8
941 * RGB16 1 0 1 2 2 3 4 5 6 7 8
942 * ARGB 2 3 0 1 4 5 6 7 8 9 10
943 * AYUV 3 4 1 0 2 5 6 7 8 9 10
944 * YUV444 2 4 3 1 0 5 6 7 8 9 10
945 * YUV422 3 5 4 2 1 0 6 7 8 9 10
946 * YUV420 4 6 5 3 2 1 0 7 8 9 10
947 * YUV411 4 6 5 3 2 1 7 0 8 9 10
948 * YUV410 6 8 7 5 4 3 2 1 0 9 10
949 * PAL 1 3 2 6 4 6 7 8 9 0 10
950 * GRAY 1 4 3 2 1 5 6 7 8 9 0
952 * PAL or GRAY are never preferred, if we can we would convert to PAL instead
954 * less subsampling is preferred and if any, preferably horizontal
955 * We would like to keep the alpha, even if we would need to to colorspace conversion
958 #define SCORE_FORMAT_CHANGE 1
959 #define SCORE_DEPTH_CHANGE 1
960 #define SCORE_ALPHA_CHANGE 1
961 #define SCORE_CHROMA_W_CHANGE 1
962 #define SCORE_CHROMA_H_CHANGE 1
963 #define SCORE_PALETTE_CHANGE 1
965 #define SCORE_COLORSPACE_LOSS 2 /* RGB <-> YUV */
966 #define SCORE_DEPTH_LOSS 4 /* change bit depth */
967 #define SCORE_ALPHA_LOSS 8 /* lose the alpha channel */
968 #define SCORE_CHROMA_W_LOSS 16 /* vertical subsample */
969 #define SCORE_CHROMA_H_LOSS 32 /* horizontal subsample */
970 #define SCORE_PALETTE_LOSS 64 /* convert to palette format */
971 #define SCORE_COLOR_LOSS 128 /* convert to GRAY */
973 #define COLORSPACE_MASK (GST_VIDEO_FORMAT_FLAG_YUV | \
974 GST_VIDEO_FORMAT_FLAG_RGB | GST_VIDEO_FORMAT_FLAG_GRAY)
975 #define ALPHA_MASK (GST_VIDEO_FORMAT_FLAG_ALPHA)
976 #define PALETTE_MASK (GST_VIDEO_FORMAT_FLAG_PALETTE)
978 /* calculate how much loss a conversion would be */
980 score_value (GstBaseTransform * base, const GstVideoFormatInfo * in_info,
981 const GValue * val, gint * min_loss, const GstVideoFormatInfo ** out_info)
984 const GstVideoFormatInfo *t_info;
985 GstVideoFormatFlags in_flags, t_flags;
988 fname = g_value_get_string (val);
989 t_info = gst_video_format_get_info (gst_video_format_from_string (fname));
990 if (!t_info || t_info->format == GST_VIDEO_FORMAT_UNKNOWN)
993 /* accept input format immediately without loss */
994 if (in_info == t_info) {
1000 loss = SCORE_FORMAT_CHANGE;
1002 in_flags = GST_VIDEO_FORMAT_INFO_FLAGS (in_info);
1003 in_flags &= ~GST_VIDEO_FORMAT_FLAG_LE;
1004 in_flags &= ~GST_VIDEO_FORMAT_FLAG_COMPLEX;
1005 in_flags &= ~GST_VIDEO_FORMAT_FLAG_UNPACK;
1007 t_flags = GST_VIDEO_FORMAT_INFO_FLAGS (t_info);
1008 t_flags &= ~GST_VIDEO_FORMAT_FLAG_LE;
1009 t_flags &= ~GST_VIDEO_FORMAT_FLAG_COMPLEX;
1010 t_flags &= ~GST_VIDEO_FORMAT_FLAG_UNPACK;
1012 if ((t_flags & PALETTE_MASK) != (in_flags & PALETTE_MASK)) {
1013 loss += SCORE_PALETTE_CHANGE;
1014 if (t_flags & PALETTE_MASK)
1015 loss += SCORE_PALETTE_LOSS;
1018 if ((t_flags & COLORSPACE_MASK) != (in_flags & COLORSPACE_MASK)) {
1019 loss += SCORE_COLORSPACE_LOSS;
1020 if (t_flags & GST_VIDEO_FORMAT_FLAG_GRAY)
1021 loss += SCORE_COLOR_LOSS;
1024 if ((t_flags & ALPHA_MASK) != (in_flags & ALPHA_MASK)) {
1025 loss += SCORE_ALPHA_CHANGE;
1026 if (in_flags & ALPHA_MASK)
1027 loss += SCORE_ALPHA_LOSS;
1030 if ((in_info->h_sub[1]) != (t_info->h_sub[1])) {
1031 loss += SCORE_CHROMA_H_CHANGE;
1032 if ((in_info->h_sub[1]) < (t_info->h_sub[1]))
1033 loss += SCORE_CHROMA_H_LOSS;
1035 if ((in_info->w_sub[1]) != (t_info->w_sub[1])) {
1036 loss += SCORE_CHROMA_W_CHANGE;
1037 if ((in_info->w_sub[1]) < (t_info->w_sub[1]))
1038 loss += SCORE_CHROMA_W_LOSS;
1041 if ((in_info->bits) != (t_info->bits)) {
1042 loss += SCORE_DEPTH_CHANGE;
1043 if ((in_info->bits) > (t_info->bits))
1044 loss += SCORE_DEPTH_LOSS;
1047 GST_DEBUG_OBJECT (base, "score %s -> %s = %d",
1048 GST_VIDEO_FORMAT_INFO_NAME (in_info),
1049 GST_VIDEO_FORMAT_INFO_NAME (t_info), loss);
1051 if (loss < *min_loss) {
1052 GST_DEBUG_OBJECT (base, "found new best %d", loss);
1059 gst_video_convert_scale_fixate_format (GstBaseTransform * base, GstCaps * caps,
1062 GstStructure *ins, *outs;
1063 const gchar *in_format;
1064 const GstVideoFormatInfo *in_info, *out_info = NULL;
1065 gint min_loss = G_MAXINT;
1068 ins = gst_caps_get_structure (caps, 0);
1069 in_format = gst_structure_get_string (ins, "format");
1073 GST_DEBUG_OBJECT (base, "source format %s", in_format);
1076 gst_video_format_get_info (gst_video_format_from_string (in_format));
1080 outs = gst_caps_get_structure (result, 0);
1082 capslen = gst_caps_get_size (result);
1083 GST_DEBUG_OBJECT (base, "iterate %d structures", capslen);
1084 for (i = 0; i < capslen; i++) {
1085 GstStructure *tests;
1086 const GValue *format;
1088 tests = gst_caps_get_structure (result, i);
1089 format = gst_structure_get_value (tests, "format");
1090 gst_structure_remove_fields (tests, "height", "width", "pixel-aspect-ratio",
1091 "display-aspect-ratio", NULL);
1092 /* should not happen */
1096 if (GST_VALUE_HOLDS_LIST (format)) {
1099 len = gst_value_list_get_size (format);
1100 GST_DEBUG_OBJECT (base, "have %d formats", len);
1101 for (j = 0; j < len; j++) {
1104 val = gst_value_list_get_value (format, j);
1105 if (G_VALUE_HOLDS_STRING (val)) {
1106 score_value (base, in_info, val, &min_loss, &out_info);
1111 } else if (G_VALUE_HOLDS_STRING (format)) {
1112 score_value (base, in_info, format, &min_loss, &out_info);
1116 gst_structure_set (outs, "format", G_TYPE_STRING,
1117 GST_VIDEO_FORMAT_INFO_NAME (out_info), NULL);
1121 subsampling_unchanged (GstVideoInfo * in_info, GstVideoInfo * out_info)
1124 const GstVideoFormatInfo *in_format, *out_format;
1126 if (GST_VIDEO_INFO_N_COMPONENTS (in_info) !=
1127 GST_VIDEO_INFO_N_COMPONENTS (out_info))
1130 in_format = in_info->finfo;
1131 out_format = out_info->finfo;
1133 for (i = 0; i < GST_VIDEO_INFO_N_COMPONENTS (in_info); i++) {
1134 if (GST_VIDEO_FORMAT_INFO_W_SUB (in_format,
1135 i) != GST_VIDEO_FORMAT_INFO_W_SUB (out_format, i))
1137 if (GST_VIDEO_FORMAT_INFO_H_SUB (in_format,
1138 i) != GST_VIDEO_FORMAT_INFO_H_SUB (out_format, i))
1146 transfer_colorimetry_from_input (GstBaseTransform * trans, GstCaps * in_caps,
1149 GstStructure *out_caps_s = gst_caps_get_structure (out_caps, 0);
1150 GstStructure *in_caps_s = gst_caps_get_structure (in_caps, 0);
1151 gboolean have_colorimetry =
1152 gst_structure_has_field (out_caps_s, "colorimetry");
1153 gboolean have_chroma_site =
1154 gst_structure_has_field (out_caps_s, "chroma-site");
1156 /* If the output already has colorimetry and chroma-site, stop,
1157 * otherwise try and transfer what we can from the input caps */
1158 if (have_colorimetry && have_chroma_site)
1162 GstVideoInfo in_info, out_info;
1163 const GValue *in_colorimetry =
1164 gst_structure_get_value (in_caps_s, "colorimetry");
1165 GstCaps *tmp_caps = NULL;
1166 GstStructure *tmp_caps_s;
1168 if (!gst_video_info_from_caps (&in_info, in_caps)) {
1169 GST_WARNING_OBJECT (trans,
1170 "Failed to convert sink pad caps to video info");
1174 /* We are before fixate_size(), the width and height of
1175 the output caps may be absent or not fixed. */
1176 tmp_caps = gst_caps_copy (out_caps);
1177 tmp_caps = gst_caps_fixate (tmp_caps);
1178 tmp_caps_s = gst_caps_get_structure (tmp_caps, 0);
1179 if (!gst_structure_has_field (tmp_caps_s, "width"))
1180 gst_structure_set_value (tmp_caps_s, "width",
1181 gst_structure_get_value (in_caps_s, "width"));
1182 if (!gst_structure_has_field (tmp_caps_s, "height"))
1183 gst_structure_set_value (tmp_caps_s, "height",
1184 gst_structure_get_value (in_caps_s, "height"));
1186 if (!gst_video_info_from_caps (&out_info, tmp_caps)) {
1187 gst_clear_caps (&tmp_caps);
1188 GST_WARNING_OBJECT (trans,
1189 "Failed to convert src pad caps to video info");
1192 gst_clear_caps (&tmp_caps);
1194 if (!have_colorimetry && in_colorimetry != NULL) {
1195 if ((GST_VIDEO_INFO_IS_YUV (&out_info)
1196 && GST_VIDEO_INFO_IS_YUV (&in_info))
1197 || (GST_VIDEO_INFO_IS_RGB (&out_info)
1198 && GST_VIDEO_INFO_IS_RGB (&in_info))
1199 || (GST_VIDEO_INFO_IS_GRAY (&out_info)
1200 && GST_VIDEO_INFO_IS_GRAY (&in_info))) {
1201 /* Can transfer the colorimetry intact from the input if it has it */
1202 gst_structure_set_value (out_caps_s, "colorimetry", in_colorimetry);
1204 gchar *colorimetry_str;
1206 /* Changing between YUV/RGB - forward primaries and transfer function, but use
1207 * default range and matrix.
1208 * the primaries is used for conversion between RGB and XYZ (CIE 1931 coordinate).
1209 * the transfer function could be another reference (e.g., HDR)
1211 out_info.colorimetry.primaries = in_info.colorimetry.primaries;
1212 out_info.colorimetry.transfer = in_info.colorimetry.transfer;
1215 gst_video_colorimetry_to_string (&out_info.colorimetry);
1216 gst_caps_set_simple (out_caps, "colorimetry", G_TYPE_STRING,
1217 colorimetry_str, NULL);
1218 g_free (colorimetry_str);
1222 /* Only YUV output needs chroma-site. If the input was also YUV and had the same chroma
1223 * subsampling, transfer the siting. If the sub-sampling is changing, then the planes get
1224 * scaled anyway so there's no real reason to prefer the input siting. */
1225 if (!have_chroma_site && GST_VIDEO_INFO_IS_YUV (&out_info)) {
1226 if (GST_VIDEO_INFO_IS_YUV (&in_info)) {
1227 const GValue *in_chroma_site =
1228 gst_structure_get_value (in_caps_s, "chroma-site");
1229 if (in_chroma_site != NULL
1230 && subsampling_unchanged (&in_info, &out_info))
1231 gst_structure_set_value (out_caps_s, "chroma-site", in_chroma_site);
1239 gst_video_convert_scale_get_fixed_format (GstBaseTransform * trans,
1240 GstPadDirection direction, GstCaps * caps, GstCaps * othercaps)
1244 result = gst_caps_intersect (othercaps, caps);
1245 if (gst_caps_is_empty (result)) {
1246 gst_caps_unref (result);
1247 result = gst_caps_copy (othercaps);
1250 result = gst_caps_make_writable (result);
1251 gst_video_convert_scale_fixate_format (trans, caps, result);
1253 /* fixate remaining fields */
1254 result = gst_caps_fixate (result);
1256 if (direction == GST_PAD_SINK) {
1257 if (gst_caps_is_subset (caps, result)) {
1258 gst_caps_replace (&result, caps);
1260 /* Try and preserve input colorimetry / chroma information */
1261 transfer_colorimetry_from_input (trans, caps, result);
1269 gst_video_convert_scale_fixate_size (GstBaseTransform * base,
1270 GstPadDirection direction, GstCaps * caps, GstCaps * othercaps)
1272 GstStructure *ins, *outs;
1273 const GValue *from_par, *to_par;
1274 GValue fpar = { 0, };
1275 GValue tpar = { 0, };
1277 othercaps = gst_caps_truncate (othercaps);
1278 othercaps = gst_caps_make_writable (othercaps);
1279 ins = gst_caps_get_structure (caps, 0);
1280 outs = gst_caps_get_structure (othercaps, 0);
1282 from_par = gst_structure_get_value (ins, "pixel-aspect-ratio");
1283 to_par = gst_structure_get_value (outs, "pixel-aspect-ratio");
1285 /* If we're fixating from the sinkpad we always set the PAR and
1286 * assume that missing PAR on the sinkpad means 1/1 and
1287 * missing PAR on the srcpad means undefined
1289 if (direction == GST_PAD_SINK) {
1291 g_value_init (&fpar, GST_TYPE_FRACTION);
1292 gst_value_set_fraction (&fpar, 1, 1);
1296 g_value_init (&tpar, GST_TYPE_FRACTION_RANGE);
1297 gst_value_set_fraction_range_full (&tpar, 1, G_MAXINT, G_MAXINT, 1);
1302 g_value_init (&tpar, GST_TYPE_FRACTION);
1303 gst_value_set_fraction (&tpar, 1, 1);
1306 gst_structure_set (outs, "pixel-aspect-ratio", GST_TYPE_FRACTION, 1, 1,
1310 g_value_init (&fpar, GST_TYPE_FRACTION);
1311 gst_value_set_fraction (&fpar, 1, 1);
1316 /* we have both PAR but they might not be fixated */
1318 gint from_w, from_h, from_par_n, from_par_d, to_par_n, to_par_d;
1320 gint from_dar_n, from_dar_d;
1323 /* from_par should be fixed */
1324 g_return_val_if_fail (gst_value_is_fixed (from_par), othercaps);
1326 from_par_n = gst_value_get_fraction_numerator (from_par);
1327 from_par_d = gst_value_get_fraction_denominator (from_par);
1329 gst_structure_get_int (ins, "width", &from_w);
1330 gst_structure_get_int (ins, "height", &from_h);
1332 gst_structure_get_int (outs, "width", &w);
1333 gst_structure_get_int (outs, "height", &h);
1335 /* if both width and height are already fixed, we can't do anything
1336 * about it anymore */
1340 GST_DEBUG_OBJECT (base, "dimensions already set to %dx%d, not fixating",
1342 if (!gst_value_is_fixed (to_par)) {
1343 if (gst_video_calculate_display_ratio (&n, &d, from_w, from_h,
1344 from_par_n, from_par_d, w, h)) {
1345 GST_DEBUG_OBJECT (base, "fixating to_par to %dx%d", n, d);
1346 if (gst_structure_has_field (outs, "pixel-aspect-ratio"))
1347 gst_structure_fixate_field_nearest_fraction (outs,
1348 "pixel-aspect-ratio", n, d);
1350 gst_structure_set (outs, "pixel-aspect-ratio", GST_TYPE_FRACTION,
1357 /* Calculate input DAR */
1358 if (!gst_util_fraction_multiply (from_w, from_h, from_par_n, from_par_d,
1359 &from_dar_n, &from_dar_d)) {
1360 GST_ELEMENT_ERROR (base, CORE, NEGOTIATION, (NULL),
1361 ("Error calculating the output scaled size - integer overflow"));
1365 GST_DEBUG_OBJECT (base, "Input DAR is %d/%d", from_dar_n, from_dar_d);
1367 /* If either width or height are fixed there's not much we
1368 * can do either except choosing a height or width and PAR
1369 * that matches the DAR as good as possible
1373 gint set_w, set_par_n, set_par_d;
1375 GST_DEBUG_OBJECT (base, "height is fixed (%d)", h);
1377 /* If the PAR is fixed too, there's not much to do
1378 * except choosing the width that is nearest to the
1379 * width with the same DAR */
1380 if (gst_value_is_fixed (to_par)) {
1381 to_par_n = gst_value_get_fraction_numerator (to_par);
1382 to_par_d = gst_value_get_fraction_denominator (to_par);
1384 GST_DEBUG_OBJECT (base, "PAR is fixed %d/%d", to_par_n, to_par_d);
1386 if (!gst_util_fraction_multiply (from_dar_n, from_dar_d, to_par_d,
1387 to_par_n, &num, &den)) {
1388 GST_ELEMENT_ERROR (base, CORE, NEGOTIATION, (NULL),
1389 ("Error calculating the output scaled size - integer overflow"));
1393 w = (guint) gst_util_uint64_scale_int_round (h, num, den);
1394 gst_structure_fixate_field_nearest_int (outs, "width", w);
1399 /* The PAR is not fixed and it's quite likely that we can set
1400 * an arbitrary PAR. */
1402 /* Check if we can keep the input width */
1403 tmp = gst_structure_copy (outs);
1404 gst_structure_fixate_field_nearest_int (tmp, "width", from_w);
1405 gst_structure_get_int (tmp, "width", &set_w);
1407 /* Might have failed but try to keep the DAR nonetheless by
1408 * adjusting the PAR */
1409 if (!gst_util_fraction_multiply (from_dar_n, from_dar_d, h, set_w,
1410 &to_par_n, &to_par_d)) {
1411 GST_ELEMENT_ERROR (base, CORE, NEGOTIATION, (NULL),
1412 ("Error calculating the output scaled size - integer overflow"));
1413 gst_structure_free (tmp);
1417 if (!gst_structure_has_field (tmp, "pixel-aspect-ratio"))
1418 gst_structure_set_value (tmp, "pixel-aspect-ratio", to_par);
1419 gst_structure_fixate_field_nearest_fraction (tmp, "pixel-aspect-ratio",
1420 to_par_n, to_par_d);
1421 gst_structure_get_fraction (tmp, "pixel-aspect-ratio", &set_par_n,
1423 gst_structure_free (tmp);
1425 /* Check if the adjusted PAR is accepted */
1426 if (set_par_n == to_par_n && set_par_d == to_par_d) {
1427 if (gst_structure_has_field (outs, "pixel-aspect-ratio") ||
1428 set_par_n != set_par_d)
1429 gst_structure_set (outs, "width", G_TYPE_INT, set_w,
1430 "pixel-aspect-ratio", GST_TYPE_FRACTION, set_par_n, set_par_d,
1435 /* Otherwise scale the width to the new PAR and check if the
1436 * adjusted with is accepted. If all that fails we can't keep
1438 if (!gst_util_fraction_multiply (from_dar_n, from_dar_d, set_par_d,
1439 set_par_n, &num, &den)) {
1440 GST_ELEMENT_ERROR (base, CORE, NEGOTIATION, (NULL),
1441 ("Error calculating the output scaled size - integer overflow"));
1445 w = (guint) gst_util_uint64_scale_int_round (h, num, den);
1446 gst_structure_fixate_field_nearest_int (outs, "width", w);
1447 if (gst_structure_has_field (outs, "pixel-aspect-ratio") ||
1448 set_par_n != set_par_d)
1449 gst_structure_set (outs, "pixel-aspect-ratio", GST_TYPE_FRACTION,
1450 set_par_n, set_par_d, NULL);
1455 gint set_h, set_par_n, set_par_d;
1457 GST_DEBUG_OBJECT (base, "width is fixed (%d)", w);
1459 /* If the PAR is fixed too, there's not much to do
1460 * except choosing the height that is nearest to the
1461 * height with the same DAR */
1462 if (gst_value_is_fixed (to_par)) {
1463 to_par_n = gst_value_get_fraction_numerator (to_par);
1464 to_par_d = gst_value_get_fraction_denominator (to_par);
1466 GST_DEBUG_OBJECT (base, "PAR is fixed %d/%d", to_par_n, to_par_d);
1468 if (!gst_util_fraction_multiply (from_dar_n, from_dar_d, to_par_d,
1469 to_par_n, &num, &den)) {
1470 GST_ELEMENT_ERROR (base, CORE, NEGOTIATION, (NULL),
1471 ("Error calculating the output scaled size - integer overflow"));
1475 h = (guint) gst_util_uint64_scale_int_round (w, den, num);
1476 gst_structure_fixate_field_nearest_int (outs, "height", h);
1481 /* The PAR is not fixed and it's quite likely that we can set
1482 * an arbitrary PAR. */
1484 /* Check if we can keep the input height */
1485 tmp = gst_structure_copy (outs);
1486 gst_structure_fixate_field_nearest_int (tmp, "height", from_h);
1487 gst_structure_get_int (tmp, "height", &set_h);
1489 /* Might have failed but try to keep the DAR nonetheless by
1490 * adjusting the PAR */
1491 if (!gst_util_fraction_multiply (from_dar_n, from_dar_d, set_h, w,
1492 &to_par_n, &to_par_d)) {
1493 GST_ELEMENT_ERROR (base, CORE, NEGOTIATION, (NULL),
1494 ("Error calculating the output scaled size - integer overflow"));
1495 gst_structure_free (tmp);
1498 if (!gst_structure_has_field (tmp, "pixel-aspect-ratio"))
1499 gst_structure_set_value (tmp, "pixel-aspect-ratio", to_par);
1500 gst_structure_fixate_field_nearest_fraction (tmp, "pixel-aspect-ratio",
1501 to_par_n, to_par_d);
1502 gst_structure_get_fraction (tmp, "pixel-aspect-ratio", &set_par_n,
1504 gst_structure_free (tmp);
1506 /* Check if the adjusted PAR is accepted */
1507 if (set_par_n == to_par_n && set_par_d == to_par_d) {
1508 if (gst_structure_has_field (outs, "pixel-aspect-ratio") ||
1509 set_par_n != set_par_d)
1510 gst_structure_set (outs, "height", G_TYPE_INT, set_h,
1511 "pixel-aspect-ratio", GST_TYPE_FRACTION, set_par_n, set_par_d,
1516 /* Otherwise scale the height to the new PAR and check if the
1517 * adjusted with is accepted. If all that fails we can't keep
1519 if (!gst_util_fraction_multiply (from_dar_n, from_dar_d, set_par_d,
1520 set_par_n, &num, &den)) {
1521 GST_ELEMENT_ERROR (base, CORE, NEGOTIATION, (NULL),
1522 ("Error calculating the output scaled size - integer overflow"));
1526 h = (guint) gst_util_uint64_scale_int_round (w, den, num);
1527 gst_structure_fixate_field_nearest_int (outs, "height", h);
1528 if (gst_structure_has_field (outs, "pixel-aspect-ratio") ||
1529 set_par_n != set_par_d)
1530 gst_structure_set (outs, "pixel-aspect-ratio", GST_TYPE_FRACTION,
1531 set_par_n, set_par_d, NULL);
1534 } else if (gst_value_is_fixed (to_par)) {
1536 gint set_h, set_w, f_h, f_w;
1538 to_par_n = gst_value_get_fraction_numerator (to_par);
1539 to_par_d = gst_value_get_fraction_denominator (to_par);
1541 /* Calculate scale factor for the PAR change */
1542 if (!gst_util_fraction_multiply (from_dar_n, from_dar_d, to_par_n,
1543 to_par_d, &num, &den)) {
1544 GST_ELEMENT_ERROR (base, CORE, NEGOTIATION, (NULL),
1545 ("Error calculating the output scaled size - integer overflow"));
1549 /* Try to keep the input height (because of interlacing) */
1550 tmp = gst_structure_copy (outs);
1551 gst_structure_fixate_field_nearest_int (tmp, "height", from_h);
1552 gst_structure_get_int (tmp, "height", &set_h);
1554 /* This might have failed but try to scale the width
1555 * to keep the DAR nonetheless */
1556 w = (guint) gst_util_uint64_scale_int_round (set_h, num, den);
1557 gst_structure_fixate_field_nearest_int (tmp, "width", w);
1558 gst_structure_get_int (tmp, "width", &set_w);
1559 gst_structure_free (tmp);
1561 /* We kept the DAR and the height is nearest to the original height */
1563 gst_structure_set (outs, "width", G_TYPE_INT, set_w, "height",
1564 G_TYPE_INT, set_h, NULL);
1571 /* If the former failed, try to keep the input width at least */
1572 tmp = gst_structure_copy (outs);
1573 gst_structure_fixate_field_nearest_int (tmp, "width", from_w);
1574 gst_structure_get_int (tmp, "width", &set_w);
1576 /* This might have failed but try to scale the width
1577 * to keep the DAR nonetheless */
1578 h = (guint) gst_util_uint64_scale_int_round (set_w, den, num);
1579 gst_structure_fixate_field_nearest_int (tmp, "height", h);
1580 gst_structure_get_int (tmp, "height", &set_h);
1581 gst_structure_free (tmp);
1583 /* We kept the DAR and the width is nearest to the original width */
1585 gst_structure_set (outs, "width", G_TYPE_INT, set_w, "height",
1586 G_TYPE_INT, set_h, NULL);
1590 /* If all this failed, keep the dimensions with the DAR that was closest
1591 * to the correct DAR. This changes the DAR but there's not much else to
1594 if (set_w * ABS (set_h - h) < ABS (f_w - w) * f_h) {
1598 gst_structure_set (outs, "width", G_TYPE_INT, f_w, "height", G_TYPE_INT,
1603 gint set_h, set_w, set_par_n, set_par_d, tmp2;
1605 /* width, height and PAR are not fixed but passthrough is not possible */
1607 /* First try to keep the height and width as good as possible
1609 tmp = gst_structure_copy (outs);
1610 gst_structure_fixate_field_nearest_int (tmp, "height", from_h);
1611 gst_structure_get_int (tmp, "height", &set_h);
1612 gst_structure_fixate_field_nearest_int (tmp, "width", from_w);
1613 gst_structure_get_int (tmp, "width", &set_w);
1615 if (!gst_util_fraction_multiply (from_dar_n, from_dar_d, set_h, set_w,
1616 &to_par_n, &to_par_d)) {
1617 GST_ELEMENT_ERROR (base, CORE, NEGOTIATION, (NULL),
1618 ("Error calculating the output scaled size - integer overflow"));
1619 gst_structure_free (tmp);
1623 if (!gst_structure_has_field (tmp, "pixel-aspect-ratio"))
1624 gst_structure_set_value (tmp, "pixel-aspect-ratio", to_par);
1625 gst_structure_fixate_field_nearest_fraction (tmp, "pixel-aspect-ratio",
1626 to_par_n, to_par_d);
1627 gst_structure_get_fraction (tmp, "pixel-aspect-ratio", &set_par_n,
1629 gst_structure_free (tmp);
1631 if (set_par_n == to_par_n && set_par_d == to_par_d) {
1632 gst_structure_set (outs, "width", G_TYPE_INT, set_w, "height",
1633 G_TYPE_INT, set_h, NULL);
1635 if (gst_structure_has_field (outs, "pixel-aspect-ratio") ||
1636 set_par_n != set_par_d)
1637 gst_structure_set (outs, "pixel-aspect-ratio", GST_TYPE_FRACTION,
1638 set_par_n, set_par_d, NULL);
1642 /* Otherwise try to scale width to keep the DAR with the set
1644 if (!gst_util_fraction_multiply (from_dar_n, from_dar_d, set_par_d,
1645 set_par_n, &num, &den)) {
1646 GST_ELEMENT_ERROR (base, CORE, NEGOTIATION, (NULL),
1647 ("Error calculating the output scaled size - integer overflow"));
1651 w = (guint) gst_util_uint64_scale_int_round (set_h, num, den);
1652 tmp = gst_structure_copy (outs);
1653 gst_structure_fixate_field_nearest_int (tmp, "width", w);
1654 gst_structure_get_int (tmp, "width", &tmp2);
1655 gst_structure_free (tmp);
1658 gst_structure_set (outs, "width", G_TYPE_INT, tmp2, "height",
1659 G_TYPE_INT, set_h, NULL);
1660 if (gst_structure_has_field (outs, "pixel-aspect-ratio") ||
1661 set_par_n != set_par_d)
1662 gst_structure_set (outs, "pixel-aspect-ratio", GST_TYPE_FRACTION,
1663 set_par_n, set_par_d, NULL);
1667 /* ... or try the same with the height */
1668 h = (guint) gst_util_uint64_scale_int_round (set_w, den, num);
1669 tmp = gst_structure_copy (outs);
1670 gst_structure_fixate_field_nearest_int (tmp, "height", h);
1671 gst_structure_get_int (tmp, "height", &tmp2);
1672 gst_structure_free (tmp);
1675 gst_structure_set (outs, "width", G_TYPE_INT, set_w, "height",
1676 G_TYPE_INT, tmp2, NULL);
1677 if (gst_structure_has_field (outs, "pixel-aspect-ratio") ||
1678 set_par_n != set_par_d)
1679 gst_structure_set (outs, "pixel-aspect-ratio", GST_TYPE_FRACTION,
1680 set_par_n, set_par_d, NULL);
1684 /* If all fails we can't keep the DAR and take the nearest values
1685 * for everything from the first try */
1686 gst_structure_set (outs, "width", G_TYPE_INT, set_w, "height",
1687 G_TYPE_INT, set_h, NULL);
1688 if (gst_structure_has_field (outs, "pixel-aspect-ratio") ||
1689 set_par_n != set_par_d)
1690 gst_structure_set (outs, "pixel-aspect-ratio", GST_TYPE_FRACTION,
1691 set_par_n, set_par_d, NULL);
1696 othercaps = gst_caps_fixate (othercaps);
1698 GST_DEBUG_OBJECT (base, "fixated othercaps to %" GST_PTR_FORMAT, othercaps);
1700 if (from_par == &fpar)
1701 g_value_unset (&fpar);
1702 if (to_par == &tpar)
1703 g_value_unset (&tpar);
1709 gst_video_convert_scale_fixate_caps (GstBaseTransform * base,
1710 GstPadDirection direction, GstCaps * caps, GstCaps * othercaps)
1714 GST_DEBUG_OBJECT (base,
1715 "trying to fixate othercaps %" GST_PTR_FORMAT " based on caps %"
1716 GST_PTR_FORMAT, othercaps, caps);
1718 format = gst_video_convert_scale_get_fixed_format (base, direction, caps,
1721 if (gst_caps_is_empty (format)) {
1722 GST_ERROR_OBJECT (base, "Could not convert formats");
1727 gst_video_convert_scale_fixate_size (base, direction, caps, othercaps);
1728 if (gst_caps_get_size (othercaps) == 1) {
1730 const gchar *format_fields[] = { "format", "colorimetry", "chroma-site" };
1731 GstStructure *format_struct = gst_caps_get_structure (format, 0);
1732 GstStructure *fixated_struct;
1734 othercaps = gst_caps_make_writable (othercaps);
1735 fixated_struct = gst_caps_get_structure (othercaps, 0);
1737 for (i = 0; i < G_N_ELEMENTS (format_fields); i++) {
1738 if (gst_structure_has_field (format_struct, format_fields[i])) {
1739 gst_structure_set (fixated_struct, format_fields[i], G_TYPE_STRING,
1740 gst_structure_get_string (format_struct, format_fields[i]), NULL);
1742 gst_structure_remove_field (fixated_struct, format_fields[i]);
1746 gst_caps_unref (format);
1748 GST_DEBUG_OBJECT (base, "fixated othercaps to %" GST_PTR_FORMAT, othercaps);
1753 #define GET_LINE(frame, line) \
1754 (gpointer)(((guint8*)(GST_VIDEO_FRAME_PLANE_DATA (frame, 0))) + \
1755 GST_VIDEO_FRAME_PLANE_STRIDE (frame, 0) * (line))
1757 static GstFlowReturn
1758 gst_video_convert_scale_transform_frame (GstVideoFilter * filter,
1759 GstVideoFrame * in_frame, GstVideoFrame * out_frame)
1761 GstVideoConvertScalePrivate *priv = PRIV (filter);
1762 GstFlowReturn ret = GST_FLOW_OK;
1764 GST_CAT_DEBUG_OBJECT (CAT_PERFORMANCE, filter, "doing video scaling");
1766 gst_video_converter_frame (priv->convert, in_frame, out_frame);
1772 gst_video_convert_scale_src_event (GstBaseTransform * trans, GstEvent * event)
1774 GstVideoConvertScale *self = GST_VIDEO_CONVERT_SCALE_CAST (trans);
1775 GstVideoFilter *filter = GST_VIDEO_FILTER_CAST (trans);
1779 GST_DEBUG_OBJECT (self, "handling %s event", GST_EVENT_TYPE_NAME (event));
1781 switch (GST_EVENT_TYPE (event)) {
1782 case GST_EVENT_NAVIGATION:
1783 if (filter->in_info.width != filter->out_info.width ||
1784 filter->in_info.height != filter->out_info.height) {
1785 event = gst_event_make_writable (event);
1787 if (gst_navigation_event_get_coordinates (event, &x, &y)) {
1788 gst_navigation_event_set_coordinates (event,
1789 x * filter->in_info.width / filter->out_info.width,
1790 y * filter->in_info.height / filter->out_info.height);
1798 ret = GST_BASE_TRANSFORM_CLASS (parent_class)->src_event (trans, event);