2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3 * Copyright (C) 2005 David Schleef <ds@schleef.org>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
22 * SECTION:element-videoscale
23 * @see_also: videorate, ffmpegcolorspace
25 * This element resizes video frames. By default the element will try to
26 * negotiate to the same size on the source and sinkpad so that no scaling
27 * is needed. It is therefore safe to insert this element in a pipeline to
28 * get more robust behaviour without any cost if no scaling is needed.
30 * This element supports a wide range of color spaces including various YUV and
31 * RGB formats and is therefore generally able to operate anywhere in a
35 * <title>Example pipelines</title>
37 * gst-launch -v filesrc location=videotestsrc.ogg ! oggdemux ! theoradec ! ffmpegcolorspace ! videoscale ! ximagesink
38 * ]| Decode an Ogg/Theora and display the video using ximagesink. Since
39 * ximagesink cannot perform scaling, the video scaling will be performed by
40 * videoscale when you resize the video window.
41 * To create the test Ogg/Theora file refer to the documentation of theoraenc.
43 * gst-launch -v filesrc location=videotestsrc.ogg ! oggdemux ! theoradec ! videoscale ! video/x-raw-yuv, width=50 ! xvimagesink
44 * ]| Decode an Ogg/Theora and display the video using xvimagesink with a width
48 * Last reviewed on 2006-03-02 (0.10.4)
52 * Formulas for PAR, DAR, width and height relations:
63 * w = h * ----- * -----
67 * h = w * ----- * -----
79 #include <gst/video/video.h>
81 #include "gstvideoscale.h"
82 #include "gstvideoscaleorc.h"
85 #include "vs_fill_borders.h"
87 /* debug variable definition */
88 GST_DEBUG_CATEGORY (video_scale_debug);
90 #define DEFAULT_PROP_METHOD GST_VIDEO_SCALE_BILINEAR
91 #define DEFAULT_PROP_ADD_BORDERS FALSE
101 #undef GST_VIDEO_SIZE_RANGE
102 #define GST_VIDEO_SIZE_RANGE "(int) [ 1, 32767]"
104 static GstStaticCaps gst_video_scale_format_caps[] = {
105 GST_STATIC_CAPS (GST_VIDEO_CAPS_RGBA),
106 GST_STATIC_CAPS (GST_VIDEO_CAPS_ARGB),
107 GST_STATIC_CAPS (GST_VIDEO_CAPS_BGRA),
108 GST_STATIC_CAPS (GST_VIDEO_CAPS_ABGR),
109 GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("AYUV")),
110 GST_STATIC_CAPS (GST_VIDEO_CAPS_RGBx),
111 GST_STATIC_CAPS (GST_VIDEO_CAPS_xRGB),
112 GST_STATIC_CAPS (GST_VIDEO_CAPS_BGRx),
113 GST_STATIC_CAPS (GST_VIDEO_CAPS_xBGR),
114 GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("Y444")),
115 GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("v308")),
116 GST_STATIC_CAPS (GST_VIDEO_CAPS_RGB),
117 GST_STATIC_CAPS (GST_VIDEO_CAPS_BGR),
118 GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("Y42B")),
119 GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("YUY2")),
120 GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("YVYU")),
121 GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("UYVY")),
122 GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("I420")),
123 GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("YV12")),
124 GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("Y41B")),
125 GST_STATIC_CAPS (GST_VIDEO_CAPS_RGB_16),
126 GST_STATIC_CAPS (GST_VIDEO_CAPS_RGB_15),
127 GST_STATIC_CAPS (GST_VIDEO_CAPS_GRAY16 ("BYTE_ORDER")),
128 GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("Y16 ")),
129 GST_STATIC_CAPS (GST_VIDEO_CAPS_GRAY8),
130 GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("Y800")),
131 GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("Y8 ")),
132 GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("GREY")),
133 GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("AY64")),
134 GST_STATIC_CAPS (GST_VIDEO_CAPS_ARGB_64)
137 #define GST_TYPE_VIDEO_SCALE_METHOD (gst_video_scale_method_get_type())
139 gst_video_scale_method_get_type (void)
141 static GType video_scale_method_type = 0;
143 static const GEnumValue video_scale_methods[] = {
144 {GST_VIDEO_SCALE_NEAREST, "Nearest Neighbour", "nearest-neighbour"},
145 {GST_VIDEO_SCALE_BILINEAR, "Bilinear", "bilinear"},
146 {GST_VIDEO_SCALE_4TAP, "4-tap", "4-tap"},
150 if (!video_scale_method_type) {
151 video_scale_method_type =
152 g_enum_register_static ("GstVideoScaleMethod", video_scale_methods);
154 return video_scale_method_type;
158 gst_video_scale_get_capslist (void)
160 static GstCaps *caps = NULL;
161 static volatile gsize inited = 0;
163 if (g_once_init_enter (&inited)) {
166 g_assert (caps == NULL);
168 caps = gst_caps_new_empty ();
169 for (i = 0; i < G_N_ELEMENTS (gst_video_scale_format_caps); i++)
170 gst_caps_append (caps,
171 gst_caps_make_writable
172 (gst_static_caps_get (&gst_video_scale_format_caps[i])));
173 g_once_init_leave (&inited, 1);
179 static GstPadTemplate *
180 gst_video_scale_src_template_factory (void)
182 return gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
183 gst_caps_ref (gst_video_scale_get_capslist ()));
186 static GstPadTemplate *
187 gst_video_scale_sink_template_factory (void)
189 return gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
190 gst_caps_ref (gst_video_scale_get_capslist ()));
194 static void gst_video_scale_finalize (GstVideoScale * videoscale);
195 static gboolean gst_video_scale_src_event (GstBaseTransform * trans,
198 /* base transform vmethods */
199 static GstCaps *gst_video_scale_transform_caps (GstBaseTransform * trans,
200 GstPadDirection direction, GstCaps * caps);
201 static gboolean gst_video_scale_set_caps (GstBaseTransform * trans,
202 GstCaps * in, GstCaps * out);
203 static gboolean gst_video_scale_get_unit_size (GstBaseTransform * trans,
204 GstCaps * caps, guint * size);
205 static GstFlowReturn gst_video_scale_transform (GstBaseTransform * trans,
206 GstBuffer * in, GstBuffer * out);
207 static void gst_video_scale_fixate_caps (GstBaseTransform * base,
208 GstPadDirection direction, GstCaps * caps, GstCaps * othercaps);
210 static void gst_video_scale_set_property (GObject * object, guint prop_id,
211 const GValue * value, GParamSpec * pspec);
212 static void gst_video_scale_get_property (GObject * object, guint prop_id,
213 GValue * value, GParamSpec * pspec);
215 GST_BOILERPLATE (GstVideoScale, gst_video_scale, GstVideoFilter,
216 GST_TYPE_VIDEO_FILTER);
219 gst_video_scale_base_init (gpointer g_class)
221 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
223 gst_element_class_set_details_simple (element_class,
224 "Video scaler", "Filter/Converter/Video/Scaler",
225 "Resizes video", "Wim Taymans <wim.taymans@chello.be>");
227 gst_element_class_add_pad_template (element_class,
228 gst_video_scale_sink_template_factory ());
229 gst_element_class_add_pad_template (element_class,
230 gst_video_scale_src_template_factory ());
234 gst_video_scale_class_init (GstVideoScaleClass * klass)
236 GObjectClass *gobject_class = (GObjectClass *) klass;
237 GstBaseTransformClass *trans_class = (GstBaseTransformClass *) klass;
239 gobject_class->finalize = (GObjectFinalizeFunc) gst_video_scale_finalize;
240 gobject_class->set_property = gst_video_scale_set_property;
241 gobject_class->get_property = gst_video_scale_get_property;
243 g_object_class_install_property (gobject_class, PROP_METHOD,
244 g_param_spec_enum ("method", "method", "method",
245 GST_TYPE_VIDEO_SCALE_METHOD, DEFAULT_PROP_METHOD,
246 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
248 g_object_class_install_property (gobject_class, PROP_ADD_BORDERS,
249 g_param_spec_boolean ("add-borders", "Add Borders",
250 "Add black borders if necessary to keep the display aspect ratio",
251 DEFAULT_PROP_ADD_BORDERS,
252 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
254 trans_class->transform_caps =
255 GST_DEBUG_FUNCPTR (gst_video_scale_transform_caps);
256 trans_class->set_caps = GST_DEBUG_FUNCPTR (gst_video_scale_set_caps);
257 trans_class->get_unit_size =
258 GST_DEBUG_FUNCPTR (gst_video_scale_get_unit_size);
259 trans_class->transform = GST_DEBUG_FUNCPTR (gst_video_scale_transform);
260 trans_class->fixate_caps = GST_DEBUG_FUNCPTR (gst_video_scale_fixate_caps);
261 trans_class->src_event = GST_DEBUG_FUNCPTR (gst_video_scale_src_event);
265 gst_video_scale_init (GstVideoScale * videoscale, GstVideoScaleClass * klass)
267 videoscale->tmp_buf = NULL;
268 videoscale->method = DEFAULT_PROP_METHOD;
269 videoscale->add_borders = DEFAULT_PROP_ADD_BORDERS;
273 gst_video_scale_finalize (GstVideoScale * videoscale)
275 if (videoscale->tmp_buf)
276 g_free (videoscale->tmp_buf);
278 G_OBJECT_CLASS (parent_class)->finalize (G_OBJECT (videoscale));
282 gst_video_scale_set_property (GObject * object, guint prop_id,
283 const GValue * value, GParamSpec * pspec)
285 GstVideoScale *vscale = GST_VIDEO_SCALE (object);
289 GST_OBJECT_LOCK (vscale);
290 vscale->method = g_value_get_enum (value);
291 GST_OBJECT_UNLOCK (vscale);
293 case PROP_ADD_BORDERS:
294 GST_OBJECT_LOCK (vscale);
295 vscale->add_borders = g_value_get_boolean (value);
296 GST_OBJECT_UNLOCK (vscale);
297 gst_base_transform_reconfigure (GST_BASE_TRANSFORM_CAST (vscale));
300 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
306 gst_video_scale_get_property (GObject * object, guint prop_id, GValue * value,
309 GstVideoScale *vscale = GST_VIDEO_SCALE (object);
313 GST_OBJECT_LOCK (vscale);
314 g_value_set_enum (value, vscale->method);
315 GST_OBJECT_UNLOCK (vscale);
317 case PROP_ADD_BORDERS:
318 GST_OBJECT_LOCK (vscale);
319 g_value_set_boolean (value, vscale->add_borders);
320 GST_OBJECT_UNLOCK (vscale);
323 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
329 gst_video_scale_transform_caps (GstBaseTransform * trans,
330 GstPadDirection direction, GstCaps * caps)
333 GstStructure *structure;
335 /* this function is always called with a simple caps */
336 g_return_val_if_fail (GST_CAPS_IS_SIMPLE (caps), NULL);
338 GST_DEBUG_OBJECT (trans,
339 "Transforming caps %" GST_PTR_FORMAT " in direction %s", caps,
340 (direction == GST_PAD_SINK) ? "sink" : "src");
342 ret = gst_caps_copy (caps);
343 structure = gst_structure_copy (gst_caps_get_structure (ret, 0));
345 gst_structure_set (structure,
346 "width", GST_TYPE_INT_RANGE, 1, G_MAXINT,
347 "height", GST_TYPE_INT_RANGE, 1, G_MAXINT, NULL);
349 /* if pixel aspect ratio, make a range of it */
350 if (gst_structure_has_field (structure, "pixel-aspect-ratio")) {
351 gst_structure_set (structure, "pixel-aspect-ratio", GST_TYPE_FRACTION_RANGE,
352 1, G_MAXINT, G_MAXINT, 1, NULL);
354 gst_caps_append_structure (ret, structure);
356 GST_DEBUG_OBJECT (trans, "returning caps: %" GST_PTR_FORMAT, ret);
362 gst_video_scale_set_caps (GstBaseTransform * trans, GstCaps * in, GstCaps * out)
364 GstVideoScale *videoscale = GST_VIDEO_SCALE (trans);
366 gint from_dar_n, from_dar_d, to_dar_n, to_dar_d;
367 gint from_par_n, from_par_d, to_par_n, to_par_d;
370 gst_video_format_parse_caps (in, &videoscale->format,
371 &videoscale->from_width, &videoscale->from_height);
373 gst_video_format_parse_caps (out, NULL, &videoscale->to_width,
374 &videoscale->to_height);
378 videoscale->src_size = gst_video_format_get_size (videoscale->format,
379 videoscale->from_width, videoscale->from_height);
380 videoscale->dest_size = gst_video_format_get_size (videoscale->format,
381 videoscale->to_width, videoscale->to_height);
383 if (!gst_video_parse_caps_pixel_aspect_ratio (in, &from_par_n, &from_par_d))
384 from_par_n = from_par_d = 1;
385 if (!gst_video_parse_caps_pixel_aspect_ratio (out, &to_par_n, &to_par_d))
386 to_par_n = to_par_d = 1;
388 if (!gst_util_fraction_multiply (videoscale->from_width,
389 videoscale->from_height, from_par_n, from_par_d, &from_dar_n,
391 from_dar_n = from_dar_d = -1;
394 if (!gst_util_fraction_multiply (videoscale->to_width,
395 videoscale->to_height, to_par_n, to_par_d, &to_dar_n, &to_dar_d)) {
396 to_dar_n = to_dar_d = -1;
399 videoscale->borders_w = videoscale->borders_h = 0;
400 if (to_dar_n != from_dar_n || to_dar_d != from_dar_d) {
401 if (videoscale->add_borders) {
402 gint n, d, to_h, to_w;
404 if (from_dar_n != -1 && from_dar_d != -1
405 && gst_util_fraction_multiply (from_dar_n, from_dar_d, to_par_n,
407 to_h = gst_util_uint64_scale_int (videoscale->to_width, d, n);
408 if (to_h <= videoscale->to_height) {
409 videoscale->borders_h = videoscale->to_height - to_h;
410 videoscale->borders_w = 0;
412 to_w = gst_util_uint64_scale_int (videoscale->to_height, n, d);
413 g_assert (to_w <= videoscale->to_width);
414 videoscale->borders_h = 0;
415 videoscale->borders_w = videoscale->to_width - to_w;
418 GST_WARNING_OBJECT (videoscale, "Can't calculate borders");
421 GST_WARNING_OBJECT (videoscale, "Can't keep DAR!");
425 if (videoscale->tmp_buf)
426 g_free (videoscale->tmp_buf);
427 videoscale->tmp_buf = g_malloc (videoscale->to_width * 8 * 4);
429 gst_base_transform_set_passthrough (trans,
430 (videoscale->from_width == videoscale->to_width
431 && videoscale->from_height == videoscale->to_height));
433 GST_DEBUG_OBJECT (videoscale, "from=%dx%d (par=%d/%d dar=%d/%d), size %d "
434 "-> to=%dx%d (par=%d/%d dar=%d/%d borders=%d:%d), size %d",
435 videoscale->from_width, videoscale->from_height, from_par_n, from_par_d,
436 from_dar_n, from_dar_d, videoscale->src_size, videoscale->to_width,
437 videoscale->to_height, to_par_n, to_par_d, to_dar_n, to_dar_d,
438 videoscale->borders_w, videoscale->borders_h, videoscale->dest_size);
445 gst_video_scale_get_unit_size (GstBaseTransform * trans, GstCaps * caps,
448 GstVideoFormat format;
451 if (!gst_video_format_parse_caps (caps, &format, &width, &height))
454 *size = gst_video_format_get_size (format, width, height);
460 gst_video_scale_fixate_caps (GstBaseTransform * base, GstPadDirection direction,
461 GstCaps * caps, GstCaps * othercaps)
463 GstStructure *ins, *outs;
464 const GValue *from_par, *to_par;
465 GValue fpar = { 0, }, tpar = {
468 g_return_if_fail (gst_caps_is_fixed (caps));
470 GST_DEBUG_OBJECT (base, "trying to fixate othercaps %" GST_PTR_FORMAT
471 " based on caps %" GST_PTR_FORMAT, othercaps, caps);
473 ins = gst_caps_get_structure (caps, 0);
474 outs = gst_caps_get_structure (othercaps, 0);
476 from_par = gst_structure_get_value (ins, "pixel-aspect-ratio");
477 to_par = gst_structure_get_value (outs, "pixel-aspect-ratio");
479 /* If we're fixating from the sinkpad we always set the PAR and
480 * assume that missing PAR on the sinkpad means 1/1 and
481 * missing PAR on the srcpad means undefined
483 if (direction == GST_PAD_SINK) {
485 g_value_init (&fpar, GST_TYPE_FRACTION);
486 gst_value_set_fraction (&fpar, 1, 1);
490 g_value_init (&tpar, GST_TYPE_FRACTION_RANGE);
491 gst_value_set_fraction_range_full (&tpar, 1, G_MAXINT, G_MAXINT, 1);
496 g_value_init (&tpar, GST_TYPE_FRACTION);
497 gst_value_set_fraction (&tpar, 1, 1);
500 gst_structure_set (outs, "pixel-aspect-ratio", GST_TYPE_FRACTION, 1, 1,
504 g_value_init (&fpar, GST_TYPE_FRACTION);
505 gst_value_set_fraction (&fpar, 1, 1);
510 /* we have both PAR but they might not be fixated */
512 gint from_w, from_h, from_par_n, from_par_d, to_par_n, to_par_d;
514 gint from_dar_n, from_dar_d;
517 /* from_par should be fixed */
518 g_return_if_fail (gst_value_is_fixed (from_par));
520 from_par_n = gst_value_get_fraction_numerator (from_par);
521 from_par_d = gst_value_get_fraction_denominator (from_par);
523 gst_structure_get_int (ins, "width", &from_w);
524 gst_structure_get_int (ins, "height", &from_h);
526 gst_structure_get_int (outs, "width", &w);
527 gst_structure_get_int (outs, "height", &h);
529 /* if both width and height are already fixed, we can't do anything
530 * about it anymore */
534 GST_DEBUG_OBJECT (base, "dimensions already set to %dx%d, not fixating",
536 if (!gst_value_is_fixed (to_par)) {
537 if (gst_video_calculate_display_ratio (&n, &d, from_w, from_h,
538 from_par_n, from_par_d, w, h)) {
539 GST_DEBUG_OBJECT (base, "fixating to_par to %dx%d", n, d);
540 if (gst_structure_has_field (outs, "pixel-aspect-ratio"))
541 gst_structure_fixate_field_nearest_fraction (outs,
542 "pixel-aspect-ratio", n, d);
544 gst_structure_set (outs, "pixel-aspect-ratio", GST_TYPE_FRACTION,
551 /* Calculate input DAR */
552 if (!gst_util_fraction_multiply (from_w, from_h, from_par_n, from_par_d,
553 &from_dar_n, &from_dar_d)) {
554 GST_ELEMENT_ERROR (base, CORE, NEGOTIATION, (NULL),
555 ("Error calculating the output scaled size - integer overflow"));
559 GST_DEBUG_OBJECT (base, "Input DAR is %d/%d", from_dar_n, from_dar_d);
561 /* If either width or height are fixed there's not much we
562 * can do either except choosing a height or width and PAR
563 * that matches the DAR as good as possible
567 gint set_w, set_par_n, set_par_d;
569 GST_DEBUG_OBJECT (base, "height is fixed (%d)", h);
571 /* If the PAR is fixed too, there's not much to do
572 * except choosing the width that is nearest to the
573 * width with the same DAR */
574 if (gst_value_is_fixed (to_par)) {
575 to_par_n = gst_value_get_fraction_numerator (to_par);
576 to_par_d = gst_value_get_fraction_denominator (to_par);
578 GST_DEBUG_OBJECT (base, "PAR is fixed %d/%d", to_par_n, to_par_d);
580 if (!gst_util_fraction_multiply (from_dar_n, from_dar_d, to_par_d,
581 to_par_n, &num, &den)) {
582 GST_ELEMENT_ERROR (base, CORE, NEGOTIATION, (NULL),
583 ("Error calculating the output scaled size - integer overflow"));
587 w = (guint) gst_util_uint64_scale_int (h, num, den);
588 gst_structure_fixate_field_nearest_int (outs, "width", w);
593 /* The PAR is not fixed and it's quite likely that we can set
594 * an arbitrary PAR. */
596 /* Check if we can keep the input width */
597 tmp = gst_structure_copy (outs);
598 gst_structure_fixate_field_nearest_int (tmp, "width", from_w);
599 gst_structure_get_int (tmp, "width", &set_w);
601 /* Might have failed but try to keep the DAR nonetheless by
602 * adjusting the PAR */
603 if (!gst_util_fraction_multiply (from_dar_n, from_dar_d, h, set_w,
604 &to_par_n, &to_par_d)) {
605 GST_ELEMENT_ERROR (base, CORE, NEGOTIATION, (NULL),
606 ("Error calculating the output scaled size - integer overflow"));
607 gst_structure_free (tmp);
611 if (!gst_structure_has_field (tmp, "pixel-aspect-ratio"))
612 gst_structure_set_value (tmp, "pixel-aspect-ratio", to_par);
613 gst_structure_fixate_field_nearest_fraction (tmp, "pixel-aspect-ratio",
615 gst_structure_get_fraction (tmp, "pixel-aspect-ratio", &set_par_n,
617 gst_structure_free (tmp);
619 /* Check if the adjusted PAR is accepted */
620 if (set_par_n == to_par_n && set_par_d == to_par_d) {
621 if (gst_structure_has_field (outs, "pixel-aspect-ratio") ||
622 set_par_n != set_par_d)
623 gst_structure_set (outs, "width", G_TYPE_INT, set_w,
624 "pixel-aspect-ratio", GST_TYPE_FRACTION, set_par_n, set_par_d,
629 /* Otherwise scale the width to the new PAR and check if the
630 * adjusted with is accepted. If all that fails we can't keep
632 if (!gst_util_fraction_multiply (from_dar_n, from_dar_d, set_par_d,
633 set_par_n, &num, &den)) {
634 GST_ELEMENT_ERROR (base, CORE, NEGOTIATION, (NULL),
635 ("Error calculating the output scaled size - integer overflow"));
639 w = (guint) gst_util_uint64_scale_int (h, num, den);
640 gst_structure_fixate_field_nearest_int (outs, "width", w);
641 if (gst_structure_has_field (outs, "pixel-aspect-ratio") ||
642 set_par_n != set_par_d)
643 gst_structure_set (outs, "pixel-aspect-ratio", GST_TYPE_FRACTION,
644 set_par_n, set_par_d, NULL);
649 gint set_h, set_par_n, set_par_d;
651 GST_DEBUG_OBJECT (base, "width is fixed (%d)", w);
653 /* If the PAR is fixed too, there's not much to do
654 * except choosing the height that is nearest to the
655 * height with the same DAR */
656 if (gst_value_is_fixed (to_par)) {
657 to_par_n = gst_value_get_fraction_numerator (to_par);
658 to_par_d = gst_value_get_fraction_denominator (to_par);
660 GST_DEBUG_OBJECT (base, "PAR is fixed %d/%d", to_par_n, to_par_d);
662 if (!gst_util_fraction_multiply (from_dar_n, from_dar_d, to_par_d,
663 to_par_n, &num, &den)) {
664 GST_ELEMENT_ERROR (base, CORE, NEGOTIATION, (NULL),
665 ("Error calculating the output scaled size - integer overflow"));
669 h = (guint) gst_util_uint64_scale_int (w, den, num);
670 gst_structure_fixate_field_nearest_int (outs, "height", h);
675 /* The PAR is not fixed and it's quite likely that we can set
676 * an arbitrary PAR. */
678 /* Check if we can keep the input height */
679 tmp = gst_structure_copy (outs);
680 gst_structure_fixate_field_nearest_int (tmp, "height", from_h);
681 gst_structure_get_int (tmp, "height", &set_h);
683 /* Might have failed but try to keep the DAR nonetheless by
684 * adjusting the PAR */
685 if (!gst_util_fraction_multiply (from_dar_n, from_dar_d, set_h, w,
686 &to_par_n, &to_par_d)) {
687 GST_ELEMENT_ERROR (base, CORE, NEGOTIATION, (NULL),
688 ("Error calculating the output scaled size - integer overflow"));
689 gst_structure_free (tmp);
692 if (!gst_structure_has_field (tmp, "pixel-aspect-ratio"))
693 gst_structure_set_value (tmp, "pixel-aspect-ratio", to_par);
694 gst_structure_fixate_field_nearest_fraction (tmp, "pixel-aspect-ratio",
696 gst_structure_get_fraction (tmp, "pixel-aspect-ratio", &set_par_n,
698 gst_structure_free (tmp);
700 /* Check if the adjusted PAR is accepted */
701 if (set_par_n == to_par_n && set_par_d == to_par_d) {
702 if (gst_structure_has_field (outs, "pixel-aspect-ratio") ||
703 set_par_n != set_par_d)
704 gst_structure_set (outs, "height", G_TYPE_INT, set_h,
705 "pixel-aspect-ratio", GST_TYPE_FRACTION, set_par_n, set_par_d,
710 /* Otherwise scale the height to the new PAR and check if the
711 * adjusted with is accepted. If all that fails we can't keep
713 if (!gst_util_fraction_multiply (from_dar_n, from_dar_d, set_par_d,
714 set_par_n, &num, &den)) {
715 GST_ELEMENT_ERROR (base, CORE, NEGOTIATION, (NULL),
716 ("Error calculating the output scaled size - integer overflow"));
720 h = (guint) gst_util_uint64_scale_int (w, den, num);
721 gst_structure_fixate_field_nearest_int (outs, "height", h);
722 if (gst_structure_has_field (outs, "pixel-aspect-ratio") ||
723 set_par_n != set_par_d)
724 gst_structure_set (outs, "pixel-aspect-ratio", GST_TYPE_FRACTION,
725 set_par_n, set_par_d, NULL);
728 } else if (gst_value_is_fixed (to_par)) {
730 gint set_h, set_w, f_h, f_w;
732 to_par_n = gst_value_get_fraction_numerator (to_par);
733 to_par_d = gst_value_get_fraction_denominator (to_par);
735 /* Calculate scale factor for the PAR change */
736 if (!gst_util_fraction_multiply (from_dar_n, from_dar_d, to_par_n,
737 to_par_d, &num, &den)) {
738 GST_ELEMENT_ERROR (base, CORE, NEGOTIATION, (NULL),
739 ("Error calculating the output scaled size - integer overflow"));
743 /* Try to keep the input height (because of interlacing) */
744 tmp = gst_structure_copy (outs);
745 gst_structure_fixate_field_nearest_int (tmp, "height", from_h);
746 gst_structure_get_int (tmp, "height", &set_h);
748 /* This might have failed but try to scale the width
749 * to keep the DAR nonetheless */
750 w = (guint) gst_util_uint64_scale_int (set_h, num, den);
751 gst_structure_fixate_field_nearest_int (tmp, "width", w);
752 gst_structure_get_int (tmp, "width", &set_w);
753 gst_structure_free (tmp);
755 /* We kept the DAR and the height is nearest to the original height */
757 gst_structure_set (outs, "width", G_TYPE_INT, set_w, "height",
758 G_TYPE_INT, set_h, NULL);
765 /* If the former failed, try to keep the input width at least */
766 tmp = gst_structure_copy (outs);
767 gst_structure_fixate_field_nearest_int (tmp, "width", from_w);
768 gst_structure_get_int (tmp, "width", &set_w);
770 /* This might have failed but try to scale the width
771 * to keep the DAR nonetheless */
772 h = (guint) gst_util_uint64_scale_int (set_w, den, num);
773 gst_structure_fixate_field_nearest_int (tmp, "height", h);
774 gst_structure_get_int (tmp, "height", &set_h);
775 gst_structure_free (tmp);
777 /* We kept the DAR and the width is nearest to the original width */
779 gst_structure_set (outs, "width", G_TYPE_INT, set_w, "height",
780 G_TYPE_INT, set_h, NULL);
784 /* If all this failed, keep the height that was nearest to the orignal
785 * height and the nearest possible width. This changes the DAR but
786 * there's not much else to do here.
788 gst_structure_set (outs, "width", G_TYPE_INT, f_w, "height", G_TYPE_INT,
793 gint set_h, set_w, set_par_n, set_par_d, tmp2;
795 /* width, height and PAR are not fixed but passthrough is not possible */
797 /* First try to keep the height and width as good as possible
799 tmp = gst_structure_copy (outs);
800 gst_structure_fixate_field_nearest_int (tmp, "height", from_h);
801 gst_structure_get_int (tmp, "height", &set_h);
802 gst_structure_fixate_field_nearest_int (tmp, "width", from_w);
803 gst_structure_get_int (tmp, "width", &set_w);
805 if (!gst_util_fraction_multiply (from_dar_n, from_dar_d, set_h, set_w,
806 &to_par_n, &to_par_d)) {
807 GST_ELEMENT_ERROR (base, CORE, NEGOTIATION, (NULL),
808 ("Error calculating the output scaled size - integer overflow"));
812 if (!gst_structure_has_field (tmp, "pixel-aspect-ratio"))
813 gst_structure_set_value (tmp, "pixel-aspect-ratio", to_par);
814 gst_structure_fixate_field_nearest_fraction (tmp, "pixel-aspect-ratio",
816 gst_structure_get_fraction (tmp, "pixel-aspect-ratio", &set_par_n,
818 gst_structure_free (tmp);
820 if (set_par_n == to_par_n && set_par_d == to_par_d) {
821 gst_structure_set (outs, "width", G_TYPE_INT, set_w, "height",
822 G_TYPE_INT, set_h, NULL);
824 if (gst_structure_has_field (outs, "pixel-aspect-ratio") ||
825 set_par_n != set_par_d)
826 gst_structure_set (outs, "pixel-aspect-ratio", GST_TYPE_FRACTION,
827 set_par_n, set_par_d, NULL);
831 /* Otherwise try to scale width to keep the DAR with the set
833 if (!gst_util_fraction_multiply (from_dar_n, from_dar_d, set_par_d,
834 set_par_n, &num, &den)) {
835 GST_ELEMENT_ERROR (base, CORE, NEGOTIATION, (NULL),
836 ("Error calculating the output scaled size - integer overflow"));
840 w = (guint) gst_util_uint64_scale_int (set_h, num, den);
841 tmp = gst_structure_copy (outs);
842 gst_structure_fixate_field_nearest_int (tmp, "width", w);
843 gst_structure_get_int (tmp, "width", &tmp2);
844 gst_structure_free (tmp);
847 gst_structure_set (outs, "width", G_TYPE_INT, tmp2, "height",
848 G_TYPE_INT, set_h, NULL);
849 if (gst_structure_has_field (outs, "pixel-aspect-ratio") ||
850 set_par_n != set_par_d)
851 gst_structure_set (outs, "pixel-aspect-ratio", GST_TYPE_FRACTION,
852 set_par_n, set_par_d, NULL);
856 /* ... or try the same with the height */
857 h = (guint) gst_util_uint64_scale_int (set_w, den, num);
858 tmp = gst_structure_copy (outs);
859 gst_structure_fixate_field_nearest_int (tmp, "height", h);
860 gst_structure_get_int (tmp, "height", &tmp2);
861 gst_structure_free (tmp);
864 gst_structure_set (outs, "width", G_TYPE_INT, set_w, "height",
865 G_TYPE_INT, tmp2, NULL);
866 if (gst_structure_has_field (outs, "pixel-aspect-ratio") ||
867 set_par_n != set_par_d)
868 gst_structure_set (outs, "pixel-aspect-ratio", GST_TYPE_FRACTION,
869 set_par_n, set_par_d, NULL);
873 /* If all fails we can't keep the DAR and take the nearest values
874 * for everything from the first try */
875 gst_structure_set (outs, "width", G_TYPE_INT, set_w, "height",
876 G_TYPE_INT, set_h, NULL);
877 if (gst_structure_has_field (outs, "pixel-aspect-ratio") ||
878 set_par_n != set_par_d)
879 gst_structure_set (outs, "pixel-aspect-ratio", GST_TYPE_FRACTION,
880 set_par_n, set_par_d, NULL);
885 GST_DEBUG_OBJECT (base, "fixated othercaps to %" GST_PTR_FORMAT, othercaps);
887 if (from_par == &fpar)
888 g_value_unset (&fpar);
890 g_value_unset (&tpar);
894 gst_video_scale_setup_vs_image (VSImage * image, GstVideoFormat format,
895 gint component, gint width, gint height, gint b_w, gint b_h, uint8_t * data)
898 gst_video_format_get_component_width (format, component, width);
900 gst_video_format_get_component_height (format, component, height);
902 gst_video_format_get_component_width (format, component, MAX (1,
905 gst_video_format_get_component_height (format, component, MAX (1,
907 image->stride = gst_video_format_get_row_stride (format, component, width);
909 image->border_top = (image->real_height - image->height) / 2;
910 image->border_bottom = image->real_height - image->height - image->border_top;
912 if (format == GST_VIDEO_FORMAT_YUY2 || format == GST_VIDEO_FORMAT_YVYU
913 || format == GST_VIDEO_FORMAT_UYVY) {
914 g_assert (component == 0);
916 image->border_left = (image->real_width - image->width) / 2;
918 if (image->border_left % 2 == 1)
919 image->border_left--;
920 image->border_right = image->real_width - image->width - image->border_left;
922 image->border_left = (image->real_width - image->width) / 2;
923 image->border_right = image->real_width - image->width - image->border_left;
926 if (format == GST_VIDEO_FORMAT_I420
927 || format == GST_VIDEO_FORMAT_YV12
928 || format == GST_VIDEO_FORMAT_Y444
929 || format == GST_VIDEO_FORMAT_Y42B || format == GST_VIDEO_FORMAT_Y41B) {
930 image->real_pixels = data + gst_video_format_get_component_offset (format,
931 component, width, height);
933 g_assert (component == 0);
934 image->real_pixels = data;
938 image->real_pixels + image->border_top * image->stride +
939 image->border_left * gst_video_format_get_pixel_stride (format,
943 static const guint8 *
944 _get_black_for_format (GstVideoFormat format)
946 static const guint8 black[][4] = {
947 {255, 0, 0, 0}, /* 0 = ARGB, ABGR, xRGB, xBGR */
948 {0, 0, 0, 255}, /* 1 = RGBA, BGRA, RGBx, BGRx */
949 {255, 16, 128, 128}, /* 2 = AYUV */
950 {0, 0, 0, 0}, /* 3 = RGB and BGR */
951 {16, 128, 128, 0}, /* 4 = v301 */
952 {16, 128, 16, 128}, /* 5 = YUY2, YUYV */
953 {128, 16, 128, 16}, /* 6 = UYVY */
954 {16, 0, 0, 0}, /* 7 = Y */
955 {0, 0, 0, 0} /* 8 = RGB565, RGB666 */
959 case GST_VIDEO_FORMAT_ARGB:
960 case GST_VIDEO_FORMAT_ABGR:
961 case GST_VIDEO_FORMAT_xRGB:
962 case GST_VIDEO_FORMAT_xBGR:
963 case GST_VIDEO_FORMAT_ARGB64:
965 case GST_VIDEO_FORMAT_RGBA:
966 case GST_VIDEO_FORMAT_BGRA:
967 case GST_VIDEO_FORMAT_RGBx:
968 case GST_VIDEO_FORMAT_BGRx:
970 case GST_VIDEO_FORMAT_AYUV:
971 case GST_VIDEO_FORMAT_AYUV64:
973 case GST_VIDEO_FORMAT_RGB:
974 case GST_VIDEO_FORMAT_BGR:
976 case GST_VIDEO_FORMAT_v308:
978 case GST_VIDEO_FORMAT_YUY2:
979 case GST_VIDEO_FORMAT_YVYU:
981 case GST_VIDEO_FORMAT_UYVY:
983 case GST_VIDEO_FORMAT_Y800:
984 case GST_VIDEO_FORMAT_GRAY8:
986 case GST_VIDEO_FORMAT_GRAY16_LE:
987 case GST_VIDEO_FORMAT_GRAY16_BE:
988 case GST_VIDEO_FORMAT_Y16:
989 return NULL; /* Handled by the caller */
990 case GST_VIDEO_FORMAT_I420:
991 case GST_VIDEO_FORMAT_YV12:
992 case GST_VIDEO_FORMAT_Y444:
993 case GST_VIDEO_FORMAT_Y42B:
994 case GST_VIDEO_FORMAT_Y41B:
995 return black[4]; /* Y, U, V, 0 */
996 case GST_VIDEO_FORMAT_RGB16:
997 case GST_VIDEO_FORMAT_RGB15:
1004 static GstFlowReturn
1005 gst_video_scale_transform (GstBaseTransform * trans, GstBuffer * in,
1008 GstVideoScale *videoscale = GST_VIDEO_SCALE (trans);
1009 GstFlowReturn ret = GST_FLOW_OK;
1010 VSImage dest = { NULL, };
1011 VSImage src = { NULL, };
1012 VSImage dest_u = { NULL, };
1013 VSImage dest_v = { NULL, };
1014 VSImage src_u = { NULL, };
1015 VSImage src_v = { NULL, };
1017 const guint8 *black = _get_black_for_format (videoscale->format);
1018 gboolean add_borders;
1020 GST_OBJECT_LOCK (videoscale);
1021 method = videoscale->method;
1022 add_borders = videoscale->add_borders;
1023 GST_OBJECT_UNLOCK (videoscale);
1025 if (videoscale->from_width == 1) {
1026 method = GST_VIDEO_SCALE_NEAREST;
1028 if (method == GST_VIDEO_SCALE_4TAP &&
1029 (videoscale->from_width < 4 || videoscale->from_height < 4)) {
1030 method = GST_VIDEO_SCALE_BILINEAR;
1033 gst_video_scale_setup_vs_image (&src, videoscale->format, 0,
1034 videoscale->from_width, videoscale->from_height, 0, 0,
1035 GST_BUFFER_DATA (in));
1036 gst_video_scale_setup_vs_image (&dest, videoscale->format, 0,
1037 videoscale->to_width, videoscale->to_height, videoscale->borders_w,
1038 videoscale->borders_h, GST_BUFFER_DATA (out));
1040 if (videoscale->format == GST_VIDEO_FORMAT_I420
1041 || videoscale->format == GST_VIDEO_FORMAT_YV12
1042 || videoscale->format == GST_VIDEO_FORMAT_Y444
1043 || videoscale->format == GST_VIDEO_FORMAT_Y42B
1044 || videoscale->format == GST_VIDEO_FORMAT_Y41B) {
1045 gst_video_scale_setup_vs_image (&src_u, videoscale->format, 1,
1046 videoscale->from_width, videoscale->from_height, 0, 0,
1047 GST_BUFFER_DATA (in));
1048 gst_video_scale_setup_vs_image (&src_v, videoscale->format, 2,
1049 videoscale->from_width, videoscale->from_height, 0, 0,
1050 GST_BUFFER_DATA (in));
1051 gst_video_scale_setup_vs_image (&dest_u, videoscale->format, 1,
1052 videoscale->to_width, videoscale->to_height, videoscale->borders_w,
1053 videoscale->borders_h, GST_BUFFER_DATA (out));
1054 gst_video_scale_setup_vs_image (&dest_v, videoscale->format, 2,
1055 videoscale->to_width, videoscale->to_height, videoscale->borders_w,
1056 videoscale->borders_h, GST_BUFFER_DATA (out));
1059 switch (videoscale->format) {
1060 case GST_VIDEO_FORMAT_RGBx:
1061 case GST_VIDEO_FORMAT_xRGB:
1062 case GST_VIDEO_FORMAT_BGRx:
1063 case GST_VIDEO_FORMAT_xBGR:
1064 case GST_VIDEO_FORMAT_RGBA:
1065 case GST_VIDEO_FORMAT_ARGB:
1066 case GST_VIDEO_FORMAT_BGRA:
1067 case GST_VIDEO_FORMAT_ABGR:
1068 case GST_VIDEO_FORMAT_AYUV:
1070 vs_fill_borders_RGBA (&dest, black);
1072 case GST_VIDEO_SCALE_NEAREST:
1073 vs_image_scale_nearest_RGBA (&dest, &src, videoscale->tmp_buf);
1075 case GST_VIDEO_SCALE_BILINEAR:
1076 vs_image_scale_linear_RGBA (&dest, &src, videoscale->tmp_buf);
1078 case GST_VIDEO_SCALE_4TAP:
1079 vs_image_scale_4tap_RGBA (&dest, &src, videoscale->tmp_buf);
1085 case GST_VIDEO_FORMAT_ARGB64:
1086 case GST_VIDEO_FORMAT_AYUV64:
1088 vs_fill_borders_AYUV64 (&dest, black);
1090 case GST_VIDEO_SCALE_NEAREST:
1091 vs_image_scale_nearest_AYUV64 (&dest, &src, videoscale->tmp_buf);
1093 case GST_VIDEO_SCALE_BILINEAR:
1094 vs_image_scale_linear_AYUV64 (&dest, &src, videoscale->tmp_buf);
1096 case GST_VIDEO_SCALE_4TAP:
1097 vs_image_scale_4tap_AYUV64 (&dest, &src, videoscale->tmp_buf);
1103 case GST_VIDEO_FORMAT_RGB:
1104 case GST_VIDEO_FORMAT_BGR:
1105 case GST_VIDEO_FORMAT_v308:
1107 vs_fill_borders_RGB (&dest, black);
1109 case GST_VIDEO_SCALE_NEAREST:
1110 vs_image_scale_nearest_RGB (&dest, &src, videoscale->tmp_buf);
1112 case GST_VIDEO_SCALE_BILINEAR:
1113 vs_image_scale_linear_RGB (&dest, &src, videoscale->tmp_buf);
1115 case GST_VIDEO_SCALE_4TAP:
1116 vs_image_scale_4tap_RGB (&dest, &src, videoscale->tmp_buf);
1122 case GST_VIDEO_FORMAT_YUY2:
1123 case GST_VIDEO_FORMAT_YVYU:
1125 vs_fill_borders_YUYV (&dest, black);
1127 case GST_VIDEO_SCALE_NEAREST:
1128 vs_image_scale_nearest_YUYV (&dest, &src, videoscale->tmp_buf);
1130 case GST_VIDEO_SCALE_BILINEAR:
1131 vs_image_scale_linear_YUYV (&dest, &src, videoscale->tmp_buf);
1133 case GST_VIDEO_SCALE_4TAP:
1134 vs_image_scale_4tap_YUYV (&dest, &src, videoscale->tmp_buf);
1140 case GST_VIDEO_FORMAT_UYVY:
1142 vs_fill_borders_UYVY (&dest, black);
1144 case GST_VIDEO_SCALE_NEAREST:
1145 vs_image_scale_nearest_UYVY (&dest, &src, videoscale->tmp_buf);
1147 case GST_VIDEO_SCALE_BILINEAR:
1148 vs_image_scale_linear_UYVY (&dest, &src, videoscale->tmp_buf);
1150 case GST_VIDEO_SCALE_4TAP:
1151 vs_image_scale_4tap_UYVY (&dest, &src, videoscale->tmp_buf);
1157 case GST_VIDEO_FORMAT_Y800:
1158 case GST_VIDEO_FORMAT_GRAY8:
1160 vs_fill_borders_Y (&dest, black);
1162 case GST_VIDEO_SCALE_NEAREST:
1163 vs_image_scale_nearest_Y (&dest, &src, videoscale->tmp_buf);
1165 case GST_VIDEO_SCALE_BILINEAR:
1166 vs_image_scale_linear_Y (&dest, &src, videoscale->tmp_buf);
1168 case GST_VIDEO_SCALE_4TAP:
1169 vs_image_scale_4tap_Y (&dest, &src, videoscale->tmp_buf);
1175 case GST_VIDEO_FORMAT_GRAY16_LE:
1176 case GST_VIDEO_FORMAT_GRAY16_BE:
1177 case GST_VIDEO_FORMAT_Y16:
1179 vs_fill_borders_Y16 (&dest, 0);
1181 case GST_VIDEO_SCALE_NEAREST:
1182 vs_image_scale_nearest_Y16 (&dest, &src, videoscale->tmp_buf);
1184 case GST_VIDEO_SCALE_BILINEAR:
1185 vs_image_scale_linear_Y16 (&dest, &src, videoscale->tmp_buf);
1187 case GST_VIDEO_SCALE_4TAP:
1188 vs_image_scale_4tap_Y16 (&dest, &src, videoscale->tmp_buf);
1194 case GST_VIDEO_FORMAT_I420:
1195 case GST_VIDEO_FORMAT_YV12:
1196 case GST_VIDEO_FORMAT_Y444:
1197 case GST_VIDEO_FORMAT_Y42B:
1198 case GST_VIDEO_FORMAT_Y41B:
1200 vs_fill_borders_Y (&dest, black);
1201 vs_fill_borders_Y (&dest_u, black + 1);
1202 vs_fill_borders_Y (&dest_v, black + 2);
1205 case GST_VIDEO_SCALE_NEAREST:
1206 vs_image_scale_nearest_Y (&dest, &src, videoscale->tmp_buf);
1207 vs_image_scale_nearest_Y (&dest_u, &src_u, videoscale->tmp_buf);
1208 vs_image_scale_nearest_Y (&dest_v, &src_v, videoscale->tmp_buf);
1210 case GST_VIDEO_SCALE_BILINEAR:
1211 vs_image_scale_linear_Y (&dest, &src, videoscale->tmp_buf);
1212 vs_image_scale_linear_Y (&dest_u, &src_u, videoscale->tmp_buf);
1213 vs_image_scale_linear_Y (&dest_v, &src_v, videoscale->tmp_buf);
1215 case GST_VIDEO_SCALE_4TAP:
1216 vs_image_scale_4tap_Y (&dest, &src, videoscale->tmp_buf);
1217 vs_image_scale_4tap_Y (&dest_u, &src_u, videoscale->tmp_buf);
1218 vs_image_scale_4tap_Y (&dest_v, &src_v, videoscale->tmp_buf);
1224 case GST_VIDEO_FORMAT_RGB16:
1226 vs_fill_borders_RGB565 (&dest, black);
1228 case GST_VIDEO_SCALE_NEAREST:
1229 vs_image_scale_nearest_RGB565 (&dest, &src, videoscale->tmp_buf);
1231 case GST_VIDEO_SCALE_BILINEAR:
1232 vs_image_scale_linear_RGB565 (&dest, &src, videoscale->tmp_buf);
1234 case GST_VIDEO_SCALE_4TAP:
1235 vs_image_scale_4tap_RGB565 (&dest, &src, videoscale->tmp_buf);
1241 case GST_VIDEO_FORMAT_RGB15:
1243 vs_fill_borders_RGB555 (&dest, black);
1245 case GST_VIDEO_SCALE_NEAREST:
1246 vs_image_scale_nearest_RGB555 (&dest, &src, videoscale->tmp_buf);
1248 case GST_VIDEO_SCALE_BILINEAR:
1249 vs_image_scale_linear_RGB555 (&dest, &src, videoscale->tmp_buf);
1251 case GST_VIDEO_SCALE_4TAP:
1252 vs_image_scale_4tap_RGB555 (&dest, &src, videoscale->tmp_buf);
1262 GST_LOG_OBJECT (videoscale, "pushing buffer of %d bytes",
1263 GST_BUFFER_SIZE (out));
1270 GST_ELEMENT_ERROR (videoscale, STREAM, NOT_IMPLEMENTED, (NULL),
1271 ("Unsupported format %d for scaling method %d",
1272 videoscale->format, method));
1273 return GST_FLOW_ERROR;
1277 GST_ELEMENT_ERROR (videoscale, STREAM, NOT_IMPLEMENTED, (NULL),
1278 ("Unknown scaling method %d", videoscale->method));
1279 return GST_FLOW_ERROR;
1284 gst_video_scale_src_event (GstBaseTransform * trans, GstEvent * event)
1286 GstVideoScale *videoscale = GST_VIDEO_SCALE (trans);
1289 GstStructure *structure;
1291 GST_DEBUG_OBJECT (videoscale, "handling %s event",
1292 GST_EVENT_TYPE_NAME (event));
1294 switch (GST_EVENT_TYPE (event)) {
1295 case GST_EVENT_NAVIGATION:
1297 GST_EVENT (gst_mini_object_make_writable (GST_MINI_OBJECT (event)));
1299 structure = (GstStructure *) gst_event_get_structure (event);
1300 if (gst_structure_get_double (structure, "pointer_x", &a)) {
1301 gst_structure_set (structure, "pointer_x", G_TYPE_DOUBLE,
1302 a * videoscale->from_width / videoscale->to_width, NULL);
1304 if (gst_structure_get_double (structure, "pointer_y", &a)) {
1305 gst_structure_set (structure, "pointer_y", G_TYPE_DOUBLE,
1306 a * videoscale->from_height / videoscale->to_height, NULL);
1313 ret = GST_BASE_TRANSFORM_CLASS (parent_class)->src_event (trans, event);
1319 plugin_init (GstPlugin * plugin)
1321 gst_videoscale_orc_init ();
1323 if (!gst_element_register (plugin, "videoscale", GST_RANK_NONE,
1324 GST_TYPE_VIDEO_SCALE))
1327 GST_DEBUG_CATEGORY_INIT (video_scale_debug, "videoscale", 0,
1328 "videoscale element");
1335 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
1338 "Resizes video", plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME,