2002-03-20 21:45:03 +00:00
|
|
|
/* GStreamer
|
2001-12-22 23:27:17 +00:00
|
|
|
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
|
2005-07-01 17:03:13 +00:00
|
|
|
* Copyright (C) 2005 David Schleef <ds@schleef.org>
|
2001-12-22 23:27:17 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
docs/plugins/: Added videoscale to docs.
Original commit message from CVS:
* docs/plugins/Makefile.am:
* docs/plugins/gst-plugins-base-plugins-docs.sgml:
* docs/plugins/gst-plugins-base-plugins-sections.txt:
Added videoscale to docs.
* gst/videorate/gstvideorate.c: (gst_video_rate_flush_prev),
(gst_video_rate_swap_prev), (gst_video_rate_event),
(gst_video_rate_chain):
Fix typo in docs.
* gst/videoscale/gstvideoscale.c: (gst_video_scale_class_init),
(gst_video_scale_init), (gst_video_scale_prepare_size),
(gst_video_scale_set_caps), (gst_video_scale_get_unit_size),
(gst_video_scale_fixate_caps), (gst_video_scale_transform):
* gst/videoscale/gstvideoscale.h:
Added docs, examples.
Some code cleanups.
Post errors instead of g_warning.
2006-03-02 17:46:36 +00:00
|
|
|
/**
|
|
|
|
* SECTION:element-videoscale
|
|
|
|
* @see_also: videorate, ffmpegcolorspace
|
|
|
|
*
|
|
|
|
* This element resizes video frames. By default the element will try to
|
|
|
|
* negotiate to the same size on the source and sinkpad so that no scaling
|
|
|
|
* is needed. It is therefore safe to insert this element in a pipeline to
|
|
|
|
* get more robust behaviour without any cost if no scaling is needed.
|
2008-07-11 06:10:24 +00:00
|
|
|
*
|
2006-05-08 15:51:15 +00:00
|
|
|
* This element supports a wide range of color spaces including various YUV and
|
|
|
|
* RGB formats and is therefore generally able to operate anywhere in a
|
|
|
|
* pipeline.
|
2008-07-11 06:10:24 +00:00
|
|
|
*
|
|
|
|
* <refsect2>
|
docs/plugins/: Added videoscale to docs.
Original commit message from CVS:
* docs/plugins/Makefile.am:
* docs/plugins/gst-plugins-base-plugins-docs.sgml:
* docs/plugins/gst-plugins-base-plugins-sections.txt:
Added videoscale to docs.
* gst/videorate/gstvideorate.c: (gst_video_rate_flush_prev),
(gst_video_rate_swap_prev), (gst_video_rate_event),
(gst_video_rate_chain):
Fix typo in docs.
* gst/videoscale/gstvideoscale.c: (gst_video_scale_class_init),
(gst_video_scale_init), (gst_video_scale_prepare_size),
(gst_video_scale_set_caps), (gst_video_scale_get_unit_size),
(gst_video_scale_fixate_caps), (gst_video_scale_transform):
* gst/videoscale/gstvideoscale.h:
Added docs, examples.
Some code cleanups.
Post errors instead of g_warning.
2006-03-02 17:46:36 +00:00
|
|
|
* <title>Example pipelines</title>
|
2008-07-11 06:10:24 +00:00
|
|
|
* |[
|
docs/plugins/: Added videoscale to docs.
Original commit message from CVS:
* docs/plugins/Makefile.am:
* docs/plugins/gst-plugins-base-plugins-docs.sgml:
* docs/plugins/gst-plugins-base-plugins-sections.txt:
Added videoscale to docs.
* gst/videorate/gstvideorate.c: (gst_video_rate_flush_prev),
(gst_video_rate_swap_prev), (gst_video_rate_event),
(gst_video_rate_chain):
Fix typo in docs.
* gst/videoscale/gstvideoscale.c: (gst_video_scale_class_init),
(gst_video_scale_init), (gst_video_scale_prepare_size),
(gst_video_scale_set_caps), (gst_video_scale_get_unit_size),
(gst_video_scale_fixate_caps), (gst_video_scale_transform):
* gst/videoscale/gstvideoscale.h:
Added docs, examples.
Some code cleanups.
Post errors instead of g_warning.
2006-03-02 17:46:36 +00:00
|
|
|
* gst-launch -v filesrc location=videotestsrc.ogg ! oggdemux ! theoradec ! ffmpegcolorspace ! videoscale ! ximagesink
|
2008-07-11 06:10:24 +00:00
|
|
|
* ]| Decode an Ogg/Theora and display the video using ximagesink. Since
|
2006-05-08 15:51:15 +00:00
|
|
|
* ximagesink cannot perform scaling, the video scaling will be performed by
|
|
|
|
* videoscale when you resize the video window.
|
docs/plugins/: Added videoscale to docs.
Original commit message from CVS:
* docs/plugins/Makefile.am:
* docs/plugins/gst-plugins-base-plugins-docs.sgml:
* docs/plugins/gst-plugins-base-plugins-sections.txt:
Added videoscale to docs.
* gst/videorate/gstvideorate.c: (gst_video_rate_flush_prev),
(gst_video_rate_swap_prev), (gst_video_rate_event),
(gst_video_rate_chain):
Fix typo in docs.
* gst/videoscale/gstvideoscale.c: (gst_video_scale_class_init),
(gst_video_scale_init), (gst_video_scale_prepare_size),
(gst_video_scale_set_caps), (gst_video_scale_get_unit_size),
(gst_video_scale_fixate_caps), (gst_video_scale_transform):
* gst/videoscale/gstvideoscale.h:
Added docs, examples.
Some code cleanups.
Post errors instead of g_warning.
2006-03-02 17:46:36 +00:00
|
|
|
* To create the test Ogg/Theora file refer to the documentation of theoraenc.
|
2008-07-11 06:10:24 +00:00
|
|
|
* |[
|
docs/plugins/: Added videoscale to docs.
Original commit message from CVS:
* docs/plugins/Makefile.am:
* docs/plugins/gst-plugins-base-plugins-docs.sgml:
* docs/plugins/gst-plugins-base-plugins-sections.txt:
Added videoscale to docs.
* gst/videorate/gstvideorate.c: (gst_video_rate_flush_prev),
(gst_video_rate_swap_prev), (gst_video_rate_event),
(gst_video_rate_chain):
Fix typo in docs.
* gst/videoscale/gstvideoscale.c: (gst_video_scale_class_init),
(gst_video_scale_init), (gst_video_scale_prepare_size),
(gst_video_scale_set_caps), (gst_video_scale_get_unit_size),
(gst_video_scale_fixate_caps), (gst_video_scale_transform):
* gst/videoscale/gstvideoscale.h:
Added docs, examples.
Some code cleanups.
Post errors instead of g_warning.
2006-03-02 17:46:36 +00:00
|
|
|
* gst-launch -v filesrc location=videotestsrc.ogg ! oggdemux ! theoradec ! videoscale ! video/x-raw-yuv, width=50 ! xvimagesink
|
2008-07-11 06:10:24 +00:00
|
|
|
* ]| Decode an Ogg/Theora and display the video using xvimagesink with a width
|
|
|
|
* of 50.
|
docs/plugins/: Added videoscale to docs.
Original commit message from CVS:
* docs/plugins/Makefile.am:
* docs/plugins/gst-plugins-base-plugins-docs.sgml:
* docs/plugins/gst-plugins-base-plugins-sections.txt:
Added videoscale to docs.
* gst/videorate/gstvideorate.c: (gst_video_rate_flush_prev),
(gst_video_rate_swap_prev), (gst_video_rate_event),
(gst_video_rate_chain):
Fix typo in docs.
* gst/videoscale/gstvideoscale.c: (gst_video_scale_class_init),
(gst_video_scale_init), (gst_video_scale_prepare_size),
(gst_video_scale_set_caps), (gst_video_scale_get_unit_size),
(gst_video_scale_fixate_caps), (gst_video_scale_transform):
* gst/videoscale/gstvideoscale.h:
Added docs, examples.
Some code cleanups.
Post errors instead of g_warning.
2006-03-02 17:46:36 +00:00
|
|
|
* </refsect2>
|
|
|
|
*
|
|
|
|
* Last reviewed on 2006-03-02 (0.10.4)
|
|
|
|
*/
|
2001-12-22 23:27:17 +00:00
|
|
|
|
2010-07-17 18:24:18 +00:00
|
|
|
/*
|
|
|
|
* Formulas for PAR, DAR, width and height relations:
|
|
|
|
*
|
|
|
|
* dar_n w par_n
|
|
|
|
* ----- = - * -----
|
|
|
|
* dar_d h par_d
|
|
|
|
*
|
|
|
|
* par_n h dar_n
|
|
|
|
* ----- = - * -----
|
|
|
|
* par_d w dar_d
|
|
|
|
*
|
|
|
|
* dar_n par_d
|
|
|
|
* w = h * ----- * -----
|
|
|
|
* dar_d par_n
|
|
|
|
*
|
|
|
|
* dar_d par_n
|
|
|
|
* h = w * ----- * -----
|
|
|
|
* dar_n par_d
|
|
|
|
*/
|
|
|
|
|
2003-06-29 19:46:12 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
2001-12-22 23:27:17 +00:00
|
|
|
|
2005-07-01 16:55:43 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2010-05-10 15:09:28 +00:00
|
|
|
#include <math.h>
|
|
|
|
|
2005-07-01 17:03:13 +00:00
|
|
|
#include <gst/video/video.h>
|
|
|
|
|
|
|
|
#include "gstvideoscale.h"
|
2010-09-09 08:57:41 +00:00
|
|
|
#include "gstvideoscaleorc.h"
|
2005-07-01 16:55:43 +00:00
|
|
|
#include "vs_image.h"
|
2006-11-14 23:08:38 +00:00
|
|
|
#include "vs_4tap.h"
|
2010-07-17 18:24:18 +00:00
|
|
|
#include "vs_fill_borders.h"
|
2005-07-01 17:03:13 +00:00
|
|
|
|
2004-02-25 17:37:26 +00:00
|
|
|
/* debug variable definition */
|
2005-12-01 01:12:55 +00:00
|
|
|
GST_DEBUG_CATEGORY (video_scale_debug);
|
2001-12-22 23:27:17 +00:00
|
|
|
|
2010-07-17 18:24:18 +00:00
|
|
|
#define DEFAULT_PROP_METHOD GST_VIDEO_SCALE_BILINEAR
|
|
|
|
#define DEFAULT_PROP_ADD_BORDERS FALSE
|
docs/plugins/: Added videoscale to docs.
Original commit message from CVS:
* docs/plugins/Makefile.am:
* docs/plugins/gst-plugins-base-plugins-docs.sgml:
* docs/plugins/gst-plugins-base-plugins-sections.txt:
Added videoscale to docs.
* gst/videorate/gstvideorate.c: (gst_video_rate_flush_prev),
(gst_video_rate_swap_prev), (gst_video_rate_event),
(gst_video_rate_chain):
Fix typo in docs.
* gst/videoscale/gstvideoscale.c: (gst_video_scale_class_init),
(gst_video_scale_init), (gst_video_scale_prepare_size),
(gst_video_scale_set_caps), (gst_video_scale_get_unit_size),
(gst_video_scale_fixate_caps), (gst_video_scale_transform):
* gst/videoscale/gstvideoscale.h:
Added docs, examples.
Some code cleanups.
Post errors instead of g_warning.
2006-03-02 17:46:36 +00:00
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
enum
|
|
|
|
{
|
2005-07-01 17:03:13 +00:00
|
|
|
PROP_0,
|
2010-07-17 18:24:18 +00:00
|
|
|
PROP_METHOD,
|
|
|
|
PROP_ADD_BORDERS
|
2004-05-21 22:39:30 +00:00
|
|
|
/* FILL ME */
|
2001-12-22 23:27:17 +00:00
|
|
|
};
|
|
|
|
|
2009-07-30 10:37:07 +00:00
|
|
|
#undef GST_VIDEO_SIZE_RANGE
|
|
|
|
#define GST_VIDEO_SIZE_RANGE "(int) [ 1, 32767]"
|
|
|
|
|
2005-12-01 01:12:55 +00:00
|
|
|
static GstStaticCaps gst_video_scale_format_caps[] = {
|
2006-06-19 09:08:05 +00:00
|
|
|
GST_STATIC_CAPS (GST_VIDEO_CAPS_RGBA),
|
|
|
|
GST_STATIC_CAPS (GST_VIDEO_CAPS_ARGB),
|
|
|
|
GST_STATIC_CAPS (GST_VIDEO_CAPS_BGRA),
|
|
|
|
GST_STATIC_CAPS (GST_VIDEO_CAPS_ABGR),
|
2010-04-23 12:42:50 +00:00
|
|
|
GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("AYUV")),
|
|
|
|
GST_STATIC_CAPS (GST_VIDEO_CAPS_RGBx),
|
|
|
|
GST_STATIC_CAPS (GST_VIDEO_CAPS_xRGB),
|
|
|
|
GST_STATIC_CAPS (GST_VIDEO_CAPS_BGRx),
|
|
|
|
GST_STATIC_CAPS (GST_VIDEO_CAPS_xBGR),
|
2010-04-23 13:06:13 +00:00
|
|
|
GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("Y444")),
|
2010-04-23 12:42:50 +00:00
|
|
|
GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("v308")),
|
2005-07-01 16:55:43 +00:00
|
|
|
GST_STATIC_CAPS (GST_VIDEO_CAPS_RGB),
|
|
|
|
GST_STATIC_CAPS (GST_VIDEO_CAPS_BGR),
|
2010-04-23 13:06:13 +00:00
|
|
|
GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("Y42B")),
|
2005-07-01 16:55:43 +00:00
|
|
|
GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("YUY2")),
|
|
|
|
GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("YVYU")),
|
|
|
|
GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("UYVY")),
|
|
|
|
GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("I420")),
|
|
|
|
GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("YV12")),
|
2010-04-23 13:06:13 +00:00
|
|
|
GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("Y41B")),
|
2005-07-01 16:55:43 +00:00
|
|
|
GST_STATIC_CAPS (GST_VIDEO_CAPS_RGB_16),
|
2009-03-28 09:06:24 +00:00
|
|
|
GST_STATIC_CAPS (GST_VIDEO_CAPS_RGB_15),
|
2010-06-12 11:00:26 +00:00
|
|
|
GST_STATIC_CAPS (GST_VIDEO_CAPS_GRAY16 ("BYTE_ORDER")),
|
2010-06-12 11:59:32 +00:00
|
|
|
GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("Y16 ")),
|
2010-06-12 11:00:26 +00:00
|
|
|
GST_STATIC_CAPS (GST_VIDEO_CAPS_GRAY8),
|
2010-06-12 11:59:32 +00:00
|
|
|
GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("Y800")),
|
|
|
|
GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("Y8 ")),
|
2011-02-20 02:50:37 +00:00
|
|
|
GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("GREY")),
|
|
|
|
GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("AY64")),
|
|
|
|
GST_STATIC_CAPS (GST_VIDEO_CAPS_ARGB_64)
|
2005-07-01 16:55:43 +00:00
|
|
|
};
|
|
|
|
|
2005-12-01 01:12:55 +00:00
|
|
|
#define GST_TYPE_VIDEO_SCALE_METHOD (gst_video_scale_method_get_type())
|
2001-12-22 23:27:17 +00:00
|
|
|
static GType
|
2005-12-01 01:12:55 +00:00
|
|
|
gst_video_scale_method_get_type (void)
|
2001-12-22 23:27:17 +00:00
|
|
|
{
|
2005-12-01 01:12:55 +00:00
|
|
|
static GType video_scale_method_type = 0;
|
2008-06-04 04:24:27 +00:00
|
|
|
|
Const-ify GEnumValue and GFlagsValue arrays. Use
Original commit message from CVS:
* ext/pango/gsttextoverlay.c: (gst_text_overlay_valign_get_type),
(gst_text_overlay_halign_get_type),
(gst_text_overlay_wrap_mode_get_type):
* ext/theora/theoradec.c: (theora_handle_type_packet),
(theora_handle_data_packet):
* ext/theora/theoraenc.c: (gst_border_mode_get_type),
(theora_enc_sink_setcaps), (theora_enc_chain):
* gst-libs/gst/cdda/gstcddabasesrc.c:
(gst_cdda_base_src_mode_get_type):
* gst/audiotestsrc/gstaudiotestsrc.c:
(gst_audiostestsrc_wave_get_type):
* gst/playback/gststreaminfo.c: (gst_stream_type_get_type):
* gst/tcp/gstfdset.c: (gst_fdset_mode_get_type):
* gst/tcp/gstmultifdsink.c: (gst_recover_policy_get_type),
(gst_sync_method_get_type), (gst_unit_type_get_type),
(gst_client_status_get_type):
* gst/videoscale/gstvideoscale.c:
(gst_video_scale_method_get_type):
* gst/videotestsrc/gstvideotestsrc.c:
(gst_video_test_src_pattern_get_type):
* gst/videotestsrc/videotestsrc.c: (paint_setup_I420),
(paint_setup_YV12), (paint_setup_YUY2), (paint_setup_UYVY),
(paint_setup_YVYU), (paint_setup_IYU2), (paint_setup_Y41B),
(paint_setup_Y42B), (paint_setup_Y800), (paint_setup_YVU9),
(paint_setup_YUV9), (paint_setup_RGB888), (paint_setup_BGR888),
(paint_setup_RGB565), (paint_setup_xRGB1555):
Const-ify GEnumValue and GFlagsValue arrays. Use
GST_ROUND_UP_* macros instead of home-made ones.
2006-05-09 19:24:46 +00:00
|
|
|
static const GEnumValue video_scale_methods[] = {
|
2005-12-01 01:12:55 +00:00
|
|
|
{GST_VIDEO_SCALE_NEAREST, "Nearest Neighbour", "nearest-neighbour"},
|
|
|
|
{GST_VIDEO_SCALE_BILINEAR, "Bilinear", "bilinear"},
|
2006-11-14 23:08:38 +00:00
|
|
|
{GST_VIDEO_SCALE_4TAP, "4-tap", "4-tap"},
|
2004-03-14 22:34:34 +00:00
|
|
|
{0, NULL, NULL},
|
2001-12-22 23:27:17 +00:00
|
|
|
};
|
2004-03-15 19:32:28 +00:00
|
|
|
|
2005-12-01 01:12:55 +00:00
|
|
|
if (!video_scale_method_type) {
|
|
|
|
video_scale_method_type =
|
|
|
|
g_enum_register_static ("GstVideoScaleMethod", video_scale_methods);
|
2001-12-22 23:27:17 +00:00
|
|
|
}
|
2005-12-01 01:12:55 +00:00
|
|
|
return video_scale_method_type;
|
2001-12-22 23:27:17 +00:00
|
|
|
}
|
|
|
|
|
2003-11-02 20:48:33 +00:00
|
|
|
static GstCaps *
|
2005-12-01 01:12:55 +00:00
|
|
|
gst_video_scale_get_capslist (void)
|
2001-12-22 23:27:17 +00:00
|
|
|
{
|
2010-04-23 13:14:56 +00:00
|
|
|
static GstCaps *caps = NULL;
|
|
|
|
static volatile gsize inited = 0;
|
2005-07-01 16:55:43 +00:00
|
|
|
|
2010-04-23 13:14:56 +00:00
|
|
|
if (g_once_init_enter (&inited)) {
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
g_assert (caps == NULL);
|
2001-12-22 23:27:17 +00:00
|
|
|
|
2005-07-01 16:55:43 +00:00
|
|
|
caps = gst_caps_new_empty ();
|
2005-12-01 01:12:55 +00:00
|
|
|
for (i = 0; i < G_N_ELEMENTS (gst_video_scale_format_caps); i++)
|
2005-07-01 16:55:43 +00:00
|
|
|
gst_caps_append (caps,
|
2005-07-01 17:03:13 +00:00
|
|
|
gst_caps_make_writable
|
2005-12-01 01:12:55 +00:00
|
|
|
(gst_static_caps_get (&gst_video_scale_format_caps[i])));
|
2010-04-23 13:14:56 +00:00
|
|
|
g_once_init_leave (&inited, 1);
|
2003-11-02 20:48:33 +00:00
|
|
|
}
|
2001-12-22 23:27:17 +00:00
|
|
|
|
2005-07-01 17:03:13 +00:00
|
|
|
return caps;
|
2001-12-22 23:27:17 +00:00
|
|
|
}
|
|
|
|
|
2003-04-22 07:32:50 +00:00
|
|
|
static GstPadTemplate *
|
2005-12-01 01:12:55 +00:00
|
|
|
gst_video_scale_src_template_factory (void)
|
2003-04-22 07:32:50 +00:00
|
|
|
{
|
2003-12-22 01:47:09 +00:00
|
|
|
return gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
|
2005-12-01 01:12:55 +00:00
|
|
|
gst_caps_ref (gst_video_scale_get_capslist ()));
|
2003-04-22 07:32:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GstPadTemplate *
|
2005-12-01 01:12:55 +00:00
|
|
|
gst_video_scale_sink_template_factory (void)
|
2001-12-22 23:27:17 +00:00
|
|
|
{
|
2003-12-22 01:47:09 +00:00
|
|
|
return gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
|
2005-12-01 01:12:55 +00:00
|
|
|
gst_caps_ref (gst_video_scale_get_capslist ()));
|
2003-04-22 07:32:50 +00:00
|
|
|
}
|
2001-12-22 23:27:17 +00:00
|
|
|
|
2005-07-01 17:03:13 +00:00
|
|
|
|
2006-07-28 17:17:24 +00:00
|
|
|
static void gst_video_scale_finalize (GstVideoScale * videoscale);
|
2006-03-14 11:11:59 +00:00
|
|
|
static gboolean gst_video_scale_src_event (GstBaseTransform * trans,
|
2004-03-14 22:34:34 +00:00
|
|
|
GstEvent * event);
|
2003-11-02 20:48:33 +00:00
|
|
|
|
2005-08-24 13:32:52 +00:00
|
|
|
/* base transform vmethods */
|
2005-12-01 01:12:55 +00:00
|
|
|
static GstCaps *gst_video_scale_transform_caps (GstBaseTransform * trans,
|
2005-08-24 13:32:52 +00:00
|
|
|
GstPadDirection direction, GstCaps * caps);
|
2005-12-01 01:12:55 +00:00
|
|
|
static gboolean gst_video_scale_set_caps (GstBaseTransform * trans,
|
2005-07-01 17:03:13 +00:00
|
|
|
GstCaps * in, GstCaps * out);
|
2005-12-01 01:12:55 +00:00
|
|
|
static gboolean gst_video_scale_get_unit_size (GstBaseTransform * trans,
|
2011-03-27 14:35:28 +00:00
|
|
|
GstCaps * caps, gsize * size);
|
2005-12-01 01:12:55 +00:00
|
|
|
static GstFlowReturn gst_video_scale_transform (GstBaseTransform * trans,
|
2005-07-15 10:44:19 +00:00
|
|
|
GstBuffer * in, GstBuffer * out);
|
2005-12-01 01:12:55 +00:00
|
|
|
static void gst_video_scale_fixate_caps (GstBaseTransform * base,
|
2005-11-18 17:31:17 +00:00
|
|
|
GstPadDirection direction, GstCaps * caps, GstCaps * othercaps);
|
2005-07-01 17:03:13 +00:00
|
|
|
|
2005-12-01 01:12:55 +00:00
|
|
|
static void gst_video_scale_set_property (GObject * object, guint prop_id,
|
2004-03-14 22:34:34 +00:00
|
|
|
const GValue * value, GParamSpec * pspec);
|
2005-12-01 01:12:55 +00:00
|
|
|
static void gst_video_scale_get_property (GObject * object, guint prop_id,
|
2004-03-14 22:34:34 +00:00
|
|
|
GValue * value, GParamSpec * pspec);
|
2003-11-02 20:48:33 +00:00
|
|
|
|
2011-04-19 09:35:53 +00:00
|
|
|
#define gst_video_scale_parent_class parent_class
|
|
|
|
G_DEFINE_TYPE (GstVideoScale, gst_video_scale, GST_TYPE_VIDEO_FILTER);
|
2005-07-01 17:03:13 +00:00
|
|
|
|
2003-11-02 20:48:33 +00:00
|
|
|
static void
|
2005-12-01 01:12:55 +00:00
|
|
|
gst_video_scale_class_init (GstVideoScaleClass * klass)
|
2003-11-02 20:48:33 +00:00
|
|
|
{
|
2010-04-23 13:14:56 +00:00
|
|
|
GObjectClass *gobject_class = (GObjectClass *) klass;
|
2011-04-19 09:35:53 +00:00
|
|
|
GstElementClass *element_class = (GstElementClass *) klass;
|
2010-04-23 13:14:56 +00:00
|
|
|
GstBaseTransformClass *trans_class = (GstBaseTransformClass *) klass;
|
2003-11-02 20:48:33 +00:00
|
|
|
|
2006-07-28 17:17:24 +00:00
|
|
|
gobject_class->finalize = (GObjectFinalizeFunc) gst_video_scale_finalize;
|
2005-12-01 01:12:55 +00:00
|
|
|
gobject_class->set_property = gst_video_scale_set_property;
|
|
|
|
gobject_class->get_property = gst_video_scale_get_property;
|
2003-04-22 07:32:50 +00:00
|
|
|
|
2006-06-22 10:10:51 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_METHOD,
|
2005-07-01 17:03:13 +00:00
|
|
|
g_param_spec_enum ("method", "method", "method",
|
2008-03-22 15:00:53 +00:00
|
|
|
GST_TYPE_VIDEO_SCALE_METHOD, DEFAULT_PROP_METHOD,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2005-07-01 17:03:13 +00:00
|
|
|
|
2010-07-17 18:24:18 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_ADD_BORDERS,
|
2010-07-19 13:44:40 +00:00
|
|
|
g_param_spec_boolean ("add-borders", "Add Borders",
|
2010-07-17 18:24:18 +00:00
|
|
|
"Add black borders if necessary to keep the display aspect ratio",
|
|
|
|
DEFAULT_PROP_ADD_BORDERS,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2011-04-19 09:35:53 +00:00
|
|
|
gst_element_class_set_details_simple (element_class,
|
|
|
|
"Video scaler", "Filter/Converter/Video/Scaler",
|
|
|
|
"Resizes video", "Wim Taymans <wim.taymans@chello.be>");
|
|
|
|
|
|
|
|
gst_element_class_add_pad_template (element_class,
|
|
|
|
gst_video_scale_sink_template_factory ());
|
|
|
|
gst_element_class_add_pad_template (element_class,
|
|
|
|
gst_video_scale_src_template_factory ());
|
|
|
|
|
2005-11-18 17:31:17 +00:00
|
|
|
trans_class->transform_caps =
|
2005-12-01 01:12:55 +00:00
|
|
|
GST_DEBUG_FUNCPTR (gst_video_scale_transform_caps);
|
|
|
|
trans_class->set_caps = GST_DEBUG_FUNCPTR (gst_video_scale_set_caps);
|
|
|
|
trans_class->get_unit_size =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_video_scale_get_unit_size);
|
|
|
|
trans_class->transform = GST_DEBUG_FUNCPTR (gst_video_scale_transform);
|
|
|
|
trans_class->fixate_caps = GST_DEBUG_FUNCPTR (gst_video_scale_fixate_caps);
|
2006-03-14 11:11:59 +00:00
|
|
|
trans_class->src_event = GST_DEBUG_FUNCPTR (gst_video_scale_src_event);
|
2001-12-22 23:27:17 +00:00
|
|
|
}
|
|
|
|
|
2005-07-01 17:03:13 +00:00
|
|
|
static void
|
2011-04-19 09:35:53 +00:00
|
|
|
gst_video_scale_init (GstVideoScale * videoscale)
|
2001-12-22 23:27:17 +00:00
|
|
|
{
|
2005-08-24 15:07:54 +00:00
|
|
|
videoscale->tmp_buf = NULL;
|
docs/plugins/: Added videoscale to docs.
Original commit message from CVS:
* docs/plugins/Makefile.am:
* docs/plugins/gst-plugins-base-plugins-docs.sgml:
* docs/plugins/gst-plugins-base-plugins-sections.txt:
Added videoscale to docs.
* gst/videorate/gstvideorate.c: (gst_video_rate_flush_prev),
(gst_video_rate_swap_prev), (gst_video_rate_event),
(gst_video_rate_chain):
Fix typo in docs.
* gst/videoscale/gstvideoscale.c: (gst_video_scale_class_init),
(gst_video_scale_init), (gst_video_scale_prepare_size),
(gst_video_scale_set_caps), (gst_video_scale_get_unit_size),
(gst_video_scale_fixate_caps), (gst_video_scale_transform):
* gst/videoscale/gstvideoscale.h:
Added docs, examples.
Some code cleanups.
Post errors instead of g_warning.
2006-03-02 17:46:36 +00:00
|
|
|
videoscale->method = DEFAULT_PROP_METHOD;
|
2010-07-17 18:24:18 +00:00
|
|
|
videoscale->add_borders = DEFAULT_PROP_ADD_BORDERS;
|
2005-07-01 17:03:13 +00:00
|
|
|
}
|
2003-11-11 05:35:31 +00:00
|
|
|
|
2006-07-28 17:17:24 +00:00
|
|
|
static void
|
|
|
|
gst_video_scale_finalize (GstVideoScale * videoscale)
|
|
|
|
{
|
|
|
|
if (videoscale->tmp_buf)
|
|
|
|
g_free (videoscale->tmp_buf);
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (G_OBJECT (videoscale));
|
|
|
|
}
|
2003-11-11 05:35:31 +00:00
|
|
|
|
2005-07-01 17:03:13 +00:00
|
|
|
static void
|
2005-12-01 01:12:55 +00:00
|
|
|
gst_video_scale_set_property (GObject * object, guint prop_id,
|
2005-07-01 17:03:13 +00:00
|
|
|
const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
2007-12-22 12:06:47 +00:00
|
|
|
GstVideoScale *vscale = GST_VIDEO_SCALE (object);
|
2003-12-22 01:47:09 +00:00
|
|
|
|
2005-07-01 17:03:13 +00:00
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_METHOD:
|
2007-12-22 12:06:47 +00:00
|
|
|
GST_OBJECT_LOCK (vscale);
|
|
|
|
vscale->method = g_value_get_enum (value);
|
|
|
|
GST_OBJECT_UNLOCK (vscale);
|
2005-07-01 17:03:13 +00:00
|
|
|
break;
|
2010-07-17 18:24:18 +00:00
|
|
|
case PROP_ADD_BORDERS:
|
|
|
|
GST_OBJECT_LOCK (vscale);
|
|
|
|
vscale->add_borders = g_value_get_boolean (value);
|
|
|
|
GST_OBJECT_UNLOCK (vscale);
|
|
|
|
gst_base_transform_reconfigure (GST_BASE_TRANSFORM_CAST (vscale));
|
|
|
|
break;
|
2005-07-01 17:03:13 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
2003-12-22 01:47:09 +00:00
|
|
|
}
|
2001-12-22 23:27:17 +00:00
|
|
|
}
|
2003-04-22 07:32:50 +00:00
|
|
|
|
2005-07-01 17:03:13 +00:00
|
|
|
static void
|
2005-12-01 01:12:55 +00:00
|
|
|
gst_video_scale_get_property (GObject * object, guint prop_id, GValue * value,
|
2005-07-01 17:03:13 +00:00
|
|
|
GParamSpec * pspec)
|
2005-07-01 16:55:43 +00:00
|
|
|
{
|
2007-12-22 12:06:47 +00:00
|
|
|
GstVideoScale *vscale = GST_VIDEO_SCALE (object);
|
2005-07-01 16:55:43 +00:00
|
|
|
|
2005-07-01 17:03:13 +00:00
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_METHOD:
|
2007-12-22 12:06:47 +00:00
|
|
|
GST_OBJECT_LOCK (vscale);
|
|
|
|
g_value_set_enum (value, vscale->method);
|
|
|
|
GST_OBJECT_UNLOCK (vscale);
|
2005-07-01 17:03:13 +00:00
|
|
|
break;
|
2010-07-17 18:24:18 +00:00
|
|
|
case PROP_ADD_BORDERS:
|
|
|
|
GST_OBJECT_LOCK (vscale);
|
|
|
|
g_value_set_boolean (value, vscale->add_borders);
|
|
|
|
GST_OBJECT_UNLOCK (vscale);
|
|
|
|
break;
|
2005-07-01 17:03:13 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
2005-07-01 16:55:43 +00:00
|
|
|
}
|
|
|
|
}
|
2001-12-22 23:27:17 +00:00
|
|
|
|
2005-07-01 17:03:13 +00:00
|
|
|
static GstCaps *
|
2005-12-01 01:12:55 +00:00
|
|
|
gst_video_scale_transform_caps (GstBaseTransform * trans,
|
2005-08-24 13:32:52 +00:00
|
|
|
GstPadDirection direction, GstCaps * caps)
|
2001-12-22 23:27:17 +00:00
|
|
|
{
|
2005-07-01 17:03:13 +00:00
|
|
|
GstCaps *ret;
|
2006-04-28 14:33:45 +00:00
|
|
|
GstStructure *structure;
|
2007-12-22 12:06:47 +00:00
|
|
|
|
|
|
|
/* this function is always called with a simple caps */
|
|
|
|
g_return_val_if_fail (GST_CAPS_IS_SIMPLE (caps), NULL);
|
2004-07-27 16:43:24 +00:00
|
|
|
|
2010-08-11 15:03:11 +00:00
|
|
|
GST_DEBUG_OBJECT (trans,
|
|
|
|
"Transforming caps %" GST_PTR_FORMAT " in direction %s", caps,
|
|
|
|
(direction == GST_PAD_SINK) ? "sink" : "src");
|
|
|
|
|
2007-12-22 12:06:47 +00:00
|
|
|
ret = gst_caps_copy (caps);
|
2008-06-04 04:24:27 +00:00
|
|
|
structure = gst_structure_copy (gst_caps_get_structure (ret, 0));
|
2006-04-28 14:33:45 +00:00
|
|
|
|
|
|
|
gst_structure_set (structure,
|
2006-11-28 16:43:18 +00:00
|
|
|
"width", GST_TYPE_INT_RANGE, 1, G_MAXINT,
|
|
|
|
"height", GST_TYPE_INT_RANGE, 1, G_MAXINT, NULL);
|
2006-04-28 14:33:45 +00:00
|
|
|
|
|
|
|
/* if pixel aspect ratio, make a range of it */
|
2010-05-10 12:52:15 +00:00
|
|
|
if (gst_structure_has_field (structure, "pixel-aspect-ratio")) {
|
2010-08-11 15:03:11 +00:00
|
|
|
gst_structure_set (structure, "pixel-aspect-ratio", GST_TYPE_FRACTION_RANGE,
|
|
|
|
1, G_MAXINT, G_MAXINT, 1, NULL);
|
2003-04-22 07:32:50 +00:00
|
|
|
}
|
2010-08-11 15:03:11 +00:00
|
|
|
gst_caps_append_structure (ret, structure);
|
2003-04-22 07:32:50 +00:00
|
|
|
|
2005-08-24 13:32:52 +00:00
|
|
|
GST_DEBUG_OBJECT (trans, "returning caps: %" GST_PTR_FORMAT, ret);
|
2006-04-28 14:33:45 +00:00
|
|
|
|
2005-07-01 17:03:13 +00:00
|
|
|
return ret;
|
2004-07-18 18:35:43 +00:00
|
|
|
}
|
|
|
|
|
2005-08-24 15:07:54 +00:00
|
|
|
static gboolean
|
2005-12-01 01:12:55 +00:00
|
|
|
gst_video_scale_set_caps (GstBaseTransform * trans, GstCaps * in, GstCaps * out)
|
2005-08-24 15:07:54 +00:00
|
|
|
{
|
2010-04-23 13:14:56 +00:00
|
|
|
GstVideoScale *videoscale = GST_VIDEO_SCALE (trans);
|
2005-08-24 15:07:54 +00:00
|
|
|
gboolean ret;
|
2010-05-10 13:13:20 +00:00
|
|
|
gint from_dar_n, from_dar_d, to_dar_n, to_dar_d;
|
|
|
|
gint from_par_n, from_par_d, to_par_n, to_par_d;
|
2005-08-24 15:07:54 +00:00
|
|
|
|
2010-06-12 11:35:47 +00:00
|
|
|
ret =
|
|
|
|
gst_video_format_parse_caps (in, &videoscale->format,
|
|
|
|
&videoscale->from_width, &videoscale->from_height);
|
2009-07-28 11:55:30 +00:00
|
|
|
ret &=
|
2010-06-12 11:35:47 +00:00
|
|
|
gst_video_format_parse_caps (out, NULL, &videoscale->to_width,
|
|
|
|
&videoscale->to_height);
|
2005-08-24 15:07:54 +00:00
|
|
|
if (!ret)
|
|
|
|
goto done;
|
|
|
|
|
2010-06-12 11:35:47 +00:00
|
|
|
videoscale->src_size = gst_video_format_get_size (videoscale->format,
|
|
|
|
videoscale->from_width, videoscale->from_height);
|
|
|
|
videoscale->dest_size = gst_video_format_get_size (videoscale->format,
|
|
|
|
videoscale->to_width, videoscale->to_height);
|
|
|
|
|
|
|
|
if (!gst_video_parse_caps_pixel_aspect_ratio (in, &from_par_n, &from_par_d))
|
2010-05-10 13:13:20 +00:00
|
|
|
from_par_n = from_par_d = 1;
|
2010-06-12 11:35:47 +00:00
|
|
|
if (!gst_video_parse_caps_pixel_aspect_ratio (out, &to_par_n, &to_par_d))
|
2010-05-10 13:13:20 +00:00
|
|
|
to_par_n = to_par_d = 1;
|
|
|
|
|
2010-05-10 15:09:28 +00:00
|
|
|
if (!gst_util_fraction_multiply (videoscale->from_width,
|
2010-05-10 13:13:20 +00:00
|
|
|
videoscale->from_height, from_par_n, from_par_d, &from_dar_n,
|
|
|
|
&from_dar_d)) {
|
|
|
|
from_dar_n = from_dar_d = -1;
|
|
|
|
}
|
|
|
|
|
2010-07-17 18:24:18 +00:00
|
|
|
if (!gst_util_fraction_multiply (videoscale->to_width,
|
|
|
|
videoscale->to_height, to_par_n, to_par_d, &to_dar_n, &to_dar_d)) {
|
2010-05-10 13:13:20 +00:00
|
|
|
to_dar_n = to_dar_d = -1;
|
|
|
|
}
|
|
|
|
|
2010-07-17 18:24:18 +00:00
|
|
|
videoscale->borders_w = videoscale->borders_h = 0;
|
|
|
|
if (to_dar_n != from_dar_n || to_dar_d != from_dar_d) {
|
|
|
|
if (videoscale->add_borders) {
|
|
|
|
gint n, d, to_h, to_w;
|
|
|
|
|
|
|
|
if (from_dar_n != -1 && from_dar_d != -1
|
|
|
|
&& gst_util_fraction_multiply (from_dar_n, from_dar_d, to_par_n,
|
|
|
|
to_par_d, &n, &d)) {
|
|
|
|
to_h = gst_util_uint64_scale_int (videoscale->to_width, d, n);
|
|
|
|
if (to_h <= videoscale->to_height) {
|
|
|
|
videoscale->borders_h = videoscale->to_height - to_h;
|
|
|
|
videoscale->borders_w = 0;
|
|
|
|
} else {
|
|
|
|
to_w = gst_util_uint64_scale_int (videoscale->to_height, n, d);
|
|
|
|
g_assert (to_w <= videoscale->to_width);
|
|
|
|
videoscale->borders_h = 0;
|
|
|
|
videoscale->borders_w = videoscale->to_width - to_w;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
GST_WARNING_OBJECT (videoscale, "Can't calculate borders");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
GST_WARNING_OBJECT (videoscale, "Can't keep DAR!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (videoscale->tmp_buf)
|
|
|
|
g_free (videoscale->tmp_buf);
|
2011-02-20 02:50:37 +00:00
|
|
|
videoscale->tmp_buf = g_malloc (videoscale->to_width * 8 * 4);
|
2010-05-10 15:09:28 +00:00
|
|
|
|
2010-05-13 10:16:38 +00:00
|
|
|
gst_base_transform_set_passthrough (trans,
|
|
|
|
(videoscale->from_width == videoscale->to_width
|
|
|
|
&& videoscale->from_height == videoscale->to_height));
|
|
|
|
|
2010-05-10 13:13:20 +00:00
|
|
|
GST_DEBUG_OBJECT (videoscale, "from=%dx%d (par=%d/%d dar=%d/%d), size %d "
|
2010-07-17 18:24:18 +00:00
|
|
|
"-> to=%dx%d (par=%d/%d dar=%d/%d borders=%d:%d), size %d",
|
2010-05-10 13:13:20 +00:00
|
|
|
videoscale->from_width, videoscale->from_height, from_par_n, from_par_d,
|
|
|
|
from_dar_n, from_dar_d, videoscale->src_size, videoscale->to_width,
|
|
|
|
videoscale->to_height, to_par_n, to_par_d, to_dar_n, to_dar_d,
|
2010-07-17 18:24:18 +00:00
|
|
|
videoscale->borders_w, videoscale->borders_h, videoscale->dest_size);
|
check/: Add extra tests for basetransform based components.
Original commit message from CVS:
* check/Makefile.am:
* check/pipelines/simple_launch_lines.c: (setup_pipeline),
(run_pipeline), (GST_START_TEST), (simple_launch_lines_suite):
Add extra tests for basetransform based components.
Comment out the test_element_negotiation test until we decide
if it's testing correct behaviour.
* ext/libvisual/visual.c: (gst_visual_init), (get_buffer),
(gst_visual_chain), (gst_visual_change_state):
Slightly more correct but still bogus timestamping.
Fix state change function.
* gst/audioconvert/gstaudioconvert.c:
(gst_audio_convert_class_init):
* gst/audioresample/gstaudioresample.c:
* gst/ffmpegcolorspace/gstffmpegcolorspace.c:
(gst_ffmpegcsp_class_init):
* gst/videoscale/gstvideoscale.c: (gst_videoscale_class_init),
(gst_videoscale_prepare_size), (gst_videoscale_set_caps),
(gst_videoscale_prepare_image):
* gst/volume/gstvolume.c: (gst_volume_class_init),
(volume_transform_ip):
Basetransform updates. Enable passthrough modes.
* sys/ximage/ximagesink.c: (gst_ximage_buffer_init),
(gst_ximagesink_renegotiate_size), (gst_ximagesink_xcontext_get),
(gst_ximagesink_setcaps), (gst_ximagesink_buffer_alloc):
Negotiation fix that allows the window to return to the original
size and renegotiate passthrough upstream. Extra debug output.
2005-09-09 17:53:47 +00:00
|
|
|
|
2005-08-24 15:07:54 +00:00
|
|
|
done:
|
|
|
|
return ret;
|
2005-07-01 17:03:13 +00:00
|
|
|
}
|
|
|
|
|
2005-08-24 13:32:52 +00:00
|
|
|
static gboolean
|
2005-12-01 01:12:55 +00:00
|
|
|
gst_video_scale_get_unit_size (GstBaseTransform * trans, GstCaps * caps,
|
2011-03-27 14:35:28 +00:00
|
|
|
gsize * size)
|
2005-07-20 17:30:45 +00:00
|
|
|
{
|
2010-06-12 11:35:47 +00:00
|
|
|
GstVideoFormat format;
|
|
|
|
gint width, height;
|
2005-08-24 15:07:54 +00:00
|
|
|
|
2010-06-12 11:35:47 +00:00
|
|
|
if (!gst_video_format_parse_caps (caps, &format, &width, &height))
|
2005-08-24 15:07:54 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2010-06-12 11:35:47 +00:00
|
|
|
*size = gst_video_format_get_size (format, width, height);
|
2005-08-04 19:52:32 +00:00
|
|
|
|
2005-08-24 13:32:52 +00:00
|
|
|
return TRUE;
|
2005-07-20 17:30:45 +00:00
|
|
|
}
|
|
|
|
|
2005-11-18 17:31:17 +00:00
|
|
|
static void
|
2005-12-01 01:12:55 +00:00
|
|
|
gst_video_scale_fixate_caps (GstBaseTransform * base, GstPadDirection direction,
|
2005-11-18 17:31:17 +00:00
|
|
|
GstCaps * caps, GstCaps * othercaps)
|
|
|
|
{
|
|
|
|
GstStructure *ins, *outs;
|
|
|
|
const GValue *from_par, *to_par;
|
2010-05-10 15:09:28 +00:00
|
|
|
GValue fpar = { 0, }, tpar = {
|
|
|
|
0,};
|
2005-11-18 17:31:17 +00:00
|
|
|
|
|
|
|
g_return_if_fail (gst_caps_is_fixed (caps));
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (base, "trying to fixate othercaps %" GST_PTR_FORMAT
|
|
|
|
" based on caps %" GST_PTR_FORMAT, othercaps, caps);
|
|
|
|
|
|
|
|
ins = gst_caps_get_structure (caps, 0);
|
|
|
|
outs = gst_caps_get_structure (othercaps, 0);
|
|
|
|
|
|
|
|
from_par = gst_structure_get_value (ins, "pixel-aspect-ratio");
|
|
|
|
to_par = gst_structure_get_value (outs, "pixel-aspect-ratio");
|
|
|
|
|
2010-05-10 15:09:28 +00:00
|
|
|
/* If we're fixating from the sinkpad we always set the PAR and
|
|
|
|
* assume that missing PAR on the sinkpad means 1/1 and
|
|
|
|
* missing PAR on the srcpad means undefined
|
|
|
|
*/
|
|
|
|
if (direction == GST_PAD_SINK) {
|
|
|
|
if (!from_par) {
|
|
|
|
g_value_init (&fpar, GST_TYPE_FRACTION);
|
|
|
|
gst_value_set_fraction (&fpar, 1, 1);
|
|
|
|
from_par = &fpar;
|
|
|
|
}
|
|
|
|
if (!to_par) {
|
|
|
|
g_value_init (&tpar, GST_TYPE_FRACTION_RANGE);
|
|
|
|
gst_value_set_fraction_range_full (&tpar, 1, G_MAXINT, G_MAXINT, 1);
|
|
|
|
to_par = &tpar;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!to_par) {
|
|
|
|
g_value_init (&tpar, GST_TYPE_FRACTION);
|
|
|
|
gst_value_set_fraction (&tpar, 1, 1);
|
|
|
|
to_par = &tpar;
|
|
|
|
|
|
|
|
gst_structure_set (outs, "pixel-aspect-ratio", GST_TYPE_FRACTION, 1, 1,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
if (!from_par) {
|
2011-02-24 11:42:34 +00:00
|
|
|
g_value_init (&fpar, GST_TYPE_FRACTION);
|
|
|
|
gst_value_set_fraction (&fpar, 1, 1);
|
2010-05-10 15:09:28 +00:00
|
|
|
from_par = &fpar;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-04-28 14:33:45 +00:00
|
|
|
/* we have both PAR but they might not be fixated */
|
2010-05-10 15:09:28 +00:00
|
|
|
{
|
docs/plugins/: Added videoscale to docs.
Original commit message from CVS:
* docs/plugins/Makefile.am:
* docs/plugins/gst-plugins-base-plugins-docs.sgml:
* docs/plugins/gst-plugins-base-plugins-sections.txt:
Added videoscale to docs.
* gst/videorate/gstvideorate.c: (gst_video_rate_flush_prev),
(gst_video_rate_swap_prev), (gst_video_rate_event),
(gst_video_rate_chain):
Fix typo in docs.
* gst/videoscale/gstvideoscale.c: (gst_video_scale_class_init),
(gst_video_scale_init), (gst_video_scale_prepare_size),
(gst_video_scale_set_caps), (gst_video_scale_get_unit_size),
(gst_video_scale_fixate_caps), (gst_video_scale_transform):
* gst/videoscale/gstvideoscale.h:
Added docs, examples.
Some code cleanups.
Post errors instead of g_warning.
2006-03-02 17:46:36 +00:00
|
|
|
gint from_w, from_h, from_par_n, from_par_d, to_par_n, to_par_d;
|
2010-05-10 15:09:28 +00:00
|
|
|
gint w = 0, h = 0;
|
|
|
|
gint from_dar_n, from_dar_d;
|
|
|
|
gint num, den;
|
2005-11-18 17:31:17 +00:00
|
|
|
|
2006-04-28 14:33:45 +00:00
|
|
|
/* from_par should be fixed */
|
|
|
|
g_return_if_fail (gst_value_is_fixed (from_par));
|
|
|
|
|
|
|
|
from_par_n = gst_value_get_fraction_numerator (from_par);
|
|
|
|
from_par_d = gst_value_get_fraction_denominator (from_par);
|
|
|
|
|
2010-05-10 11:01:44 +00:00
|
|
|
gst_structure_get_int (ins, "width", &from_w);
|
|
|
|
gst_structure_get_int (ins, "height", &from_h);
|
2006-04-28 14:33:45 +00:00
|
|
|
|
2010-07-17 17:57:00 +00:00
|
|
|
gst_structure_get_int (outs, "width", &w);
|
|
|
|
gst_structure_get_int (outs, "height", &h);
|
|
|
|
|
2005-11-18 17:31:17 +00:00
|
|
|
/* if both width and height are already fixed, we can't do anything
|
|
|
|
* about it anymore */
|
2010-07-17 17:57:00 +00:00
|
|
|
if (w && h) {
|
2010-05-10 15:09:28 +00:00
|
|
|
guint n, d;
|
|
|
|
|
2005-11-18 17:31:17 +00:00
|
|
|
GST_DEBUG_OBJECT (base, "dimensions already set to %dx%d, not fixating",
|
|
|
|
w, h);
|
2010-05-10 11:01:44 +00:00
|
|
|
if (!gst_value_is_fixed (to_par)) {
|
2010-05-10 15:09:28 +00:00
|
|
|
if (gst_video_calculate_display_ratio (&n, &d, from_w, from_h,
|
2010-05-10 11:01:44 +00:00
|
|
|
from_par_n, from_par_d, w, h)) {
|
2010-06-12 19:04:48 +00:00
|
|
|
GST_DEBUG_OBJECT (base, "fixating to_par to %dx%d", n, d);
|
2010-05-10 15:09:28 +00:00
|
|
|
if (gst_structure_has_field (outs, "pixel-aspect-ratio"))
|
|
|
|
gst_structure_fixate_field_nearest_fraction (outs,
|
|
|
|
"pixel-aspect-ratio", n, d);
|
2010-08-11 15:03:11 +00:00
|
|
|
else if (n != d)
|
2010-05-10 15:09:28 +00:00
|
|
|
gst_structure_set (outs, "pixel-aspect-ratio", GST_TYPE_FRACTION,
|
|
|
|
n, d, NULL);
|
2010-05-10 11:01:44 +00:00
|
|
|
}
|
|
|
|
}
|
2010-05-10 15:09:28 +00:00
|
|
|
goto done;
|
2010-05-10 11:01:44 +00:00
|
|
|
}
|
|
|
|
|
2010-05-10 15:09:28 +00:00
|
|
|
/* Calculate input DAR */
|
|
|
|
if (!gst_util_fraction_multiply (from_w, from_h, from_par_n, from_par_d,
|
|
|
|
&from_dar_n, &from_dar_d)) {
|
2006-05-12 21:30:00 +00:00
|
|
|
GST_ELEMENT_ERROR (base, CORE, NEGOTIATION, (NULL),
|
|
|
|
("Error calculating the output scaled size - integer overflow"));
|
2010-05-10 15:09:28 +00:00
|
|
|
goto done;
|
2006-05-12 21:30:00 +00:00
|
|
|
}
|
|
|
|
|
2010-05-10 15:09:28 +00:00
|
|
|
GST_DEBUG_OBJECT (base, "Input DAR is %d/%d", from_dar_n, from_dar_d);
|
2005-11-18 17:31:17 +00:00
|
|
|
|
2010-05-10 15:09:28 +00:00
|
|
|
/* If either width or height are fixed there's not much we
|
|
|
|
* can do either except choosing a height or width and PAR
|
|
|
|
* that matches the DAR as good as possible
|
|
|
|
*/
|
2006-04-28 14:33:45 +00:00
|
|
|
if (h) {
|
2010-05-10 15:09:28 +00:00
|
|
|
GstStructure *tmp;
|
|
|
|
gint set_w, set_par_n, set_par_d;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (base, "height is fixed (%d)", h);
|
|
|
|
|
|
|
|
/* If the PAR is fixed too, there's not much to do
|
|
|
|
* except choosing the width that is nearest to the
|
|
|
|
* width with the same DAR */
|
|
|
|
if (gst_value_is_fixed (to_par)) {
|
|
|
|
to_par_n = gst_value_get_fraction_numerator (to_par);
|
|
|
|
to_par_d = gst_value_get_fraction_denominator (to_par);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (base, "PAR is fixed %d/%d", to_par_n, to_par_d);
|
|
|
|
|
|
|
|
if (!gst_util_fraction_multiply (from_dar_n, from_dar_d, to_par_d,
|
|
|
|
to_par_n, &num, &den)) {
|
|
|
|
GST_ELEMENT_ERROR (base, CORE, NEGOTIATION, (NULL),
|
|
|
|
("Error calculating the output scaled size - integer overflow"));
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
w = (guint) gst_util_uint64_scale_int (h, num, den);
|
|
|
|
gst_structure_fixate_field_nearest_int (outs, "width", w);
|
|
|
|
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The PAR is not fixed and it's quite likely that we can set
|
|
|
|
* an arbitrary PAR. */
|
|
|
|
|
|
|
|
/* Check if we can keep the input width */
|
|
|
|
tmp = gst_structure_copy (outs);
|
|
|
|
gst_structure_fixate_field_nearest_int (tmp, "width", from_w);
|
|
|
|
gst_structure_get_int (tmp, "width", &set_w);
|
|
|
|
|
|
|
|
/* Might have failed but try to keep the DAR nonetheless by
|
|
|
|
* adjusting the PAR */
|
|
|
|
if (!gst_util_fraction_multiply (from_dar_n, from_dar_d, h, set_w,
|
|
|
|
&to_par_n, &to_par_d)) {
|
|
|
|
GST_ELEMENT_ERROR (base, CORE, NEGOTIATION, (NULL),
|
|
|
|
("Error calculating the output scaled size - integer overflow"));
|
|
|
|
gst_structure_free (tmp);
|
|
|
|
goto done;
|
|
|
|
}
|
2010-08-11 15:03:11 +00:00
|
|
|
|
|
|
|
if (!gst_structure_has_field (tmp, "pixel-aspect-ratio"))
|
|
|
|
gst_structure_set_value (tmp, "pixel-aspect-ratio", to_par);
|
2010-05-10 15:09:28 +00:00
|
|
|
gst_structure_fixate_field_nearest_fraction (tmp, "pixel-aspect-ratio",
|
|
|
|
to_par_n, to_par_d);
|
|
|
|
gst_structure_get_fraction (tmp, "pixel-aspect-ratio", &set_par_n,
|
|
|
|
&set_par_d);
|
|
|
|
gst_structure_free (tmp);
|
|
|
|
|
|
|
|
/* Check if the adjusted PAR is accepted */
|
|
|
|
if (set_par_n == to_par_n && set_par_d == to_par_d) {
|
2010-08-11 15:03:11 +00:00
|
|
|
if (gst_structure_has_field (outs, "pixel-aspect-ratio") ||
|
|
|
|
set_par_n != set_par_d)
|
|
|
|
gst_structure_set (outs, "width", G_TYPE_INT, set_w,
|
|
|
|
"pixel-aspect-ratio", GST_TYPE_FRACTION, set_par_n, set_par_d,
|
|
|
|
NULL);
|
2010-05-10 15:09:28 +00:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Otherwise scale the width to the new PAR and check if the
|
|
|
|
* adjusted with is accepted. If all that fails we can't keep
|
|
|
|
* the DAR */
|
|
|
|
if (!gst_util_fraction_multiply (from_dar_n, from_dar_d, set_par_d,
|
|
|
|
set_par_n, &num, &den)) {
|
|
|
|
GST_ELEMENT_ERROR (base, CORE, NEGOTIATION, (NULL),
|
|
|
|
("Error calculating the output scaled size - integer overflow"));
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2006-05-19 13:02:46 +00:00
|
|
|
w = (guint) gst_util_uint64_scale_int (h, num, den);
|
2010-05-10 15:09:28 +00:00
|
|
|
gst_structure_fixate_field_nearest_int (outs, "width", w);
|
2010-08-11 15:03:11 +00:00
|
|
|
if (gst_structure_has_field (outs, "pixel-aspect-ratio") ||
|
|
|
|
set_par_n != set_par_d)
|
|
|
|
gst_structure_set (outs, "pixel-aspect-ratio", GST_TYPE_FRACTION,
|
|
|
|
set_par_n, set_par_d, NULL);
|
2010-05-10 15:09:28 +00:00
|
|
|
|
|
|
|
goto done;
|
2006-04-28 14:33:45 +00:00
|
|
|
} else if (w) {
|
2010-05-10 15:09:28 +00:00
|
|
|
GstStructure *tmp;
|
|
|
|
gint set_h, set_par_n, set_par_d;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (base, "width is fixed (%d)", w);
|
|
|
|
|
|
|
|
/* If the PAR is fixed too, there's not much to do
|
|
|
|
* except choosing the height that is nearest to the
|
|
|
|
* height with the same DAR */
|
|
|
|
if (gst_value_is_fixed (to_par)) {
|
|
|
|
to_par_n = gst_value_get_fraction_numerator (to_par);
|
|
|
|
to_par_d = gst_value_get_fraction_denominator (to_par);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (base, "PAR is fixed %d/%d", to_par_n, to_par_d);
|
|
|
|
|
|
|
|
if (!gst_util_fraction_multiply (from_dar_n, from_dar_d, to_par_d,
|
|
|
|
to_par_n, &num, &den)) {
|
|
|
|
GST_ELEMENT_ERROR (base, CORE, NEGOTIATION, (NULL),
|
|
|
|
("Error calculating the output scaled size - integer overflow"));
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
h = (guint) gst_util_uint64_scale_int (w, den, num);
|
|
|
|
gst_structure_fixate_field_nearest_int (outs, "height", h);
|
|
|
|
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The PAR is not fixed and it's quite likely that we can set
|
|
|
|
* an arbitrary PAR. */
|
|
|
|
|
|
|
|
/* Check if we can keep the input height */
|
|
|
|
tmp = gst_structure_copy (outs);
|
|
|
|
gst_structure_fixate_field_nearest_int (tmp, "height", from_h);
|
|
|
|
gst_structure_get_int (tmp, "height", &set_h);
|
|
|
|
|
|
|
|
/* Might have failed but try to keep the DAR nonetheless by
|
|
|
|
* adjusting the PAR */
|
|
|
|
if (!gst_util_fraction_multiply (from_dar_n, from_dar_d, set_h, w,
|
|
|
|
&to_par_n, &to_par_d)) {
|
|
|
|
GST_ELEMENT_ERROR (base, CORE, NEGOTIATION, (NULL),
|
|
|
|
("Error calculating the output scaled size - integer overflow"));
|
|
|
|
gst_structure_free (tmp);
|
|
|
|
goto done;
|
|
|
|
}
|
2010-08-11 15:03:11 +00:00
|
|
|
if (!gst_structure_has_field (tmp, "pixel-aspect-ratio"))
|
|
|
|
gst_structure_set_value (tmp, "pixel-aspect-ratio", to_par);
|
2010-05-10 15:09:28 +00:00
|
|
|
gst_structure_fixate_field_nearest_fraction (tmp, "pixel-aspect-ratio",
|
|
|
|
to_par_n, to_par_d);
|
|
|
|
gst_structure_get_fraction (tmp, "pixel-aspect-ratio", &set_par_n,
|
|
|
|
&set_par_d);
|
|
|
|
gst_structure_free (tmp);
|
|
|
|
|
|
|
|
/* Check if the adjusted PAR is accepted */
|
|
|
|
if (set_par_n == to_par_n && set_par_d == to_par_d) {
|
2010-08-11 15:03:11 +00:00
|
|
|
if (gst_structure_has_field (outs, "pixel-aspect-ratio") ||
|
|
|
|
set_par_n != set_par_d)
|
|
|
|
gst_structure_set (outs, "height", G_TYPE_INT, set_h,
|
|
|
|
"pixel-aspect-ratio", GST_TYPE_FRACTION, set_par_n, set_par_d,
|
|
|
|
NULL);
|
2010-05-10 15:09:28 +00:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Otherwise scale the height to the new PAR and check if the
|
|
|
|
* adjusted with is accepted. If all that fails we can't keep
|
|
|
|
* the DAR */
|
|
|
|
if (!gst_util_fraction_multiply (from_dar_n, from_dar_d, set_par_d,
|
|
|
|
set_par_n, &num, &den)) {
|
|
|
|
GST_ELEMENT_ERROR (base, CORE, NEGOTIATION, (NULL),
|
|
|
|
("Error calculating the output scaled size - integer overflow"));
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2006-05-19 13:02:46 +00:00
|
|
|
h = (guint) gst_util_uint64_scale_int (w, den, num);
|
2010-05-10 15:09:28 +00:00
|
|
|
gst_structure_fixate_field_nearest_int (outs, "height", h);
|
2010-08-11 15:03:11 +00:00
|
|
|
if (gst_structure_has_field (outs, "pixel-aspect-ratio") ||
|
|
|
|
set_par_n != set_par_d)
|
|
|
|
gst_structure_set (outs, "pixel-aspect-ratio", GST_TYPE_FRACTION,
|
|
|
|
set_par_n, set_par_d, NULL);
|
2010-05-10 15:09:28 +00:00
|
|
|
|
|
|
|
goto done;
|
|
|
|
} else if (gst_value_is_fixed (to_par)) {
|
|
|
|
GstStructure *tmp;
|
|
|
|
gint set_h, set_w, f_h, f_w;
|
|
|
|
|
|
|
|
to_par_n = gst_value_get_fraction_numerator (to_par);
|
|
|
|
to_par_d = gst_value_get_fraction_denominator (to_par);
|
|
|
|
|
|
|
|
/* Calculate scale factor for the PAR change */
|
|
|
|
if (!gst_util_fraction_multiply (from_dar_n, from_dar_d, to_par_n,
|
|
|
|
to_par_d, &num, &den)) {
|
|
|
|
GST_ELEMENT_ERROR (base, CORE, NEGOTIATION, (NULL),
|
|
|
|
("Error calculating the output scaled size - integer overflow"));
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Try to keep the input height (because of interlacing) */
|
|
|
|
tmp = gst_structure_copy (outs);
|
|
|
|
gst_structure_fixate_field_nearest_int (tmp, "height", from_h);
|
|
|
|
gst_structure_get_int (tmp, "height", &set_h);
|
|
|
|
|
|
|
|
/* This might have failed but try to scale the width
|
|
|
|
* to keep the DAR nonetheless */
|
|
|
|
w = (guint) gst_util_uint64_scale_int (set_h, num, den);
|
|
|
|
gst_structure_fixate_field_nearest_int (tmp, "width", w);
|
|
|
|
gst_structure_get_int (tmp, "width", &set_w);
|
|
|
|
gst_structure_free (tmp);
|
|
|
|
|
|
|
|
/* We kept the DAR and the height is nearest to the original height */
|
|
|
|
if (set_w == w) {
|
|
|
|
gst_structure_set (outs, "width", G_TYPE_INT, set_w, "height",
|
|
|
|
G_TYPE_INT, set_h, NULL);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
f_h = set_h;
|
|
|
|
f_w = set_w;
|
|
|
|
|
|
|
|
/* If the former failed, try to keep the input width at least */
|
|
|
|
tmp = gst_structure_copy (outs);
|
|
|
|
gst_structure_fixate_field_nearest_int (tmp, "width", from_w);
|
|
|
|
gst_structure_get_int (tmp, "width", &set_w);
|
|
|
|
|
|
|
|
/* This might have failed but try to scale the width
|
|
|
|
* to keep the DAR nonetheless */
|
|
|
|
h = (guint) gst_util_uint64_scale_int (set_w, den, num);
|
|
|
|
gst_structure_fixate_field_nearest_int (tmp, "height", h);
|
|
|
|
gst_structure_get_int (tmp, "height", &set_h);
|
|
|
|
gst_structure_free (tmp);
|
|
|
|
|
|
|
|
/* We kept the DAR and the width is nearest to the original width */
|
|
|
|
if (set_h == h) {
|
|
|
|
gst_structure_set (outs, "width", G_TYPE_INT, set_w, "height",
|
|
|
|
G_TYPE_INT, set_h, NULL);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If all this failed, keep the height that was nearest to the orignal
|
|
|
|
* height and the nearest possible width. This changes the DAR but
|
|
|
|
* there's not much else to do here.
|
|
|
|
*/
|
|
|
|
gst_structure_set (outs, "width", G_TYPE_INT, f_w, "height", G_TYPE_INT,
|
|
|
|
f_h, NULL);
|
|
|
|
goto done;
|
2005-11-18 17:31:17 +00:00
|
|
|
} else {
|
2010-05-10 15:09:28 +00:00
|
|
|
GstStructure *tmp;
|
|
|
|
gint set_h, set_w, set_par_n, set_par_d, tmp2;
|
|
|
|
|
|
|
|
/* width, height and PAR are not fixed but passthrough is not possible */
|
|
|
|
|
|
|
|
/* First try to keep the height and width as good as possible
|
|
|
|
* and scale PAR */
|
|
|
|
tmp = gst_structure_copy (outs);
|
|
|
|
gst_structure_fixate_field_nearest_int (tmp, "height", from_h);
|
|
|
|
gst_structure_get_int (tmp, "height", &set_h);
|
|
|
|
gst_structure_fixate_field_nearest_int (tmp, "width", from_w);
|
|
|
|
gst_structure_get_int (tmp, "width", &set_w);
|
|
|
|
|
|
|
|
if (!gst_util_fraction_multiply (from_dar_n, from_dar_d, set_h, set_w,
|
|
|
|
&to_par_n, &to_par_d)) {
|
|
|
|
GST_ELEMENT_ERROR (base, CORE, NEGOTIATION, (NULL),
|
|
|
|
("Error calculating the output scaled size - integer overflow"));
|
|
|
|
goto done;
|
2006-04-28 14:33:45 +00:00
|
|
|
}
|
2005-11-18 17:31:17 +00:00
|
|
|
|
2010-08-11 15:03:11 +00:00
|
|
|
if (!gst_structure_has_field (tmp, "pixel-aspect-ratio"))
|
|
|
|
gst_structure_set_value (tmp, "pixel-aspect-ratio", to_par);
|
2010-05-10 15:09:28 +00:00
|
|
|
gst_structure_fixate_field_nearest_fraction (tmp, "pixel-aspect-ratio",
|
|
|
|
to_par_n, to_par_d);
|
|
|
|
gst_structure_get_fraction (tmp, "pixel-aspect-ratio", &set_par_n,
|
|
|
|
&set_par_d);
|
|
|
|
gst_structure_free (tmp);
|
|
|
|
|
|
|
|
if (set_par_n == to_par_n && set_par_d == to_par_d) {
|
|
|
|
gst_structure_set (outs, "width", G_TYPE_INT, set_w, "height",
|
2010-08-11 15:03:11 +00:00
|
|
|
G_TYPE_INT, set_h, NULL);
|
|
|
|
|
|
|
|
if (gst_structure_has_field (outs, "pixel-aspect-ratio") ||
|
|
|
|
set_par_n != set_par_d)
|
|
|
|
gst_structure_set (outs, "pixel-aspect-ratio", GST_TYPE_FRACTION,
|
|
|
|
set_par_n, set_par_d, NULL);
|
2010-05-10 15:09:28 +00:00
|
|
|
goto done;
|
|
|
|
}
|
2005-11-18 17:31:17 +00:00
|
|
|
|
2010-05-10 15:09:28 +00:00
|
|
|
/* Otherwise try to scale width to keep the DAR with the set
|
|
|
|
* PAR and height */
|
|
|
|
if (!gst_util_fraction_multiply (from_dar_n, from_dar_d, set_par_d,
|
|
|
|
set_par_n, &num, &den)) {
|
|
|
|
GST_ELEMENT_ERROR (base, CORE, NEGOTIATION, (NULL),
|
|
|
|
("Error calculating the output scaled size - integer overflow"));
|
|
|
|
goto done;
|
2005-11-18 17:31:17 +00:00
|
|
|
}
|
2010-05-10 15:09:28 +00:00
|
|
|
|
|
|
|
w = (guint) gst_util_uint64_scale_int (set_h, num, den);
|
|
|
|
tmp = gst_structure_copy (outs);
|
|
|
|
gst_structure_fixate_field_nearest_int (tmp, "width", w);
|
|
|
|
gst_structure_get_int (tmp, "width", &tmp2);
|
|
|
|
gst_structure_free (tmp);
|
|
|
|
|
|
|
|
if (tmp2 == w) {
|
|
|
|
gst_structure_set (outs, "width", G_TYPE_INT, tmp2, "height",
|
2010-08-11 15:03:11 +00:00
|
|
|
G_TYPE_INT, set_h, NULL);
|
|
|
|
if (gst_structure_has_field (outs, "pixel-aspect-ratio") ||
|
|
|
|
set_par_n != set_par_d)
|
|
|
|
gst_structure_set (outs, "pixel-aspect-ratio", GST_TYPE_FRACTION,
|
|
|
|
set_par_n, set_par_d, NULL);
|
2010-05-10 15:09:28 +00:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ... or try the same with the height */
|
|
|
|
h = (guint) gst_util_uint64_scale_int (set_w, den, num);
|
|
|
|
tmp = gst_structure_copy (outs);
|
|
|
|
gst_structure_fixate_field_nearest_int (tmp, "height", h);
|
|
|
|
gst_structure_get_int (tmp, "height", &tmp2);
|
|
|
|
gst_structure_free (tmp);
|
|
|
|
|
|
|
|
if (tmp2 == h) {
|
|
|
|
gst_structure_set (outs, "width", G_TYPE_INT, set_w, "height",
|
2010-08-11 15:03:11 +00:00
|
|
|
G_TYPE_INT, tmp2, NULL);
|
|
|
|
if (gst_structure_has_field (outs, "pixel-aspect-ratio") ||
|
|
|
|
set_par_n != set_par_d)
|
|
|
|
gst_structure_set (outs, "pixel-aspect-ratio", GST_TYPE_FRACTION,
|
|
|
|
set_par_n, set_par_d, NULL);
|
2010-05-10 15:09:28 +00:00
|
|
|
goto done;
|
2005-11-18 17:31:17 +00:00
|
|
|
}
|
2010-05-10 15:09:28 +00:00
|
|
|
|
|
|
|
/* If all fails we can't keep the DAR and take the nearest values
|
|
|
|
* for everything from the first try */
|
|
|
|
gst_structure_set (outs, "width", G_TYPE_INT, set_w, "height",
|
2010-08-11 15:03:11 +00:00
|
|
|
G_TYPE_INT, set_h, NULL);
|
|
|
|
if (gst_structure_has_field (outs, "pixel-aspect-ratio") ||
|
|
|
|
set_par_n != set_par_d)
|
|
|
|
gst_structure_set (outs, "pixel-aspect-ratio", GST_TYPE_FRACTION,
|
|
|
|
set_par_n, set_par_d, NULL);
|
2005-11-18 17:31:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-10 15:09:28 +00:00
|
|
|
done:
|
2005-11-18 17:31:17 +00:00
|
|
|
GST_DEBUG_OBJECT (base, "fixated othercaps to %" GST_PTR_FORMAT, othercaps);
|
2010-05-10 15:09:28 +00:00
|
|
|
|
|
|
|
if (from_par == &fpar)
|
|
|
|
g_value_unset (&fpar);
|
|
|
|
if (to_par == &tpar)
|
|
|
|
g_value_unset (&tpar);
|
2005-11-18 17:31:17 +00:00
|
|
|
}
|
|
|
|
|
2010-07-17 18:24:18 +00:00
|
|
|
static void
|
|
|
|
gst_video_scale_setup_vs_image (VSImage * image, GstVideoFormat format,
|
|
|
|
gint component, gint width, gint height, gint b_w, gint b_h, uint8_t * data)
|
2005-07-01 17:03:13 +00:00
|
|
|
{
|
2010-07-17 18:24:18 +00:00
|
|
|
image->real_width =
|
|
|
|
gst_video_format_get_component_width (format, component, width);
|
|
|
|
image->real_height =
|
|
|
|
gst_video_format_get_component_height (format, component, height);
|
|
|
|
image->width =
|
|
|
|
gst_video_format_get_component_width (format, component, MAX (1,
|
|
|
|
width - b_w));
|
|
|
|
image->height =
|
|
|
|
gst_video_format_get_component_height (format, component, MAX (1,
|
|
|
|
height - b_h));
|
|
|
|
image->stride = gst_video_format_get_row_stride (format, component, width);
|
|
|
|
|
|
|
|
image->border_top = (image->real_height - image->height) / 2;
|
|
|
|
image->border_bottom = image->real_height - image->height - image->border_top;
|
|
|
|
|
|
|
|
if (format == GST_VIDEO_FORMAT_YUY2 || format == GST_VIDEO_FORMAT_YVYU
|
|
|
|
|| format == GST_VIDEO_FORMAT_UYVY) {
|
|
|
|
g_assert (component == 0);
|
|
|
|
|
|
|
|
image->border_left = (image->real_width - image->width) / 2;
|
|
|
|
|
|
|
|
if (image->border_left % 2 == 1)
|
|
|
|
image->border_left--;
|
|
|
|
image->border_right = image->real_width - image->width - image->border_left;
|
|
|
|
} else {
|
|
|
|
image->border_left = (image->real_width - image->width) / 2;
|
|
|
|
image->border_right = image->real_width - image->width - image->border_left;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (format == GST_VIDEO_FORMAT_I420
|
|
|
|
|| format == GST_VIDEO_FORMAT_YV12
|
|
|
|
|| format == GST_VIDEO_FORMAT_Y444
|
|
|
|
|| format == GST_VIDEO_FORMAT_Y42B || format == GST_VIDEO_FORMAT_Y41B) {
|
|
|
|
image->real_pixels = data + gst_video_format_get_component_offset (format,
|
|
|
|
component, width, height);
|
|
|
|
} else {
|
|
|
|
g_assert (component == 0);
|
|
|
|
image->real_pixels = data;
|
|
|
|
}
|
|
|
|
|
|
|
|
image->pixels =
|
|
|
|
image->real_pixels + image->border_top * image->stride +
|
|
|
|
image->border_left * gst_video_format_get_pixel_stride (format,
|
|
|
|
component);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const guint8 *
|
|
|
|
_get_black_for_format (GstVideoFormat format)
|
|
|
|
{
|
|
|
|
static const guint8 black[][4] = {
|
|
|
|
{255, 0, 0, 0}, /* 0 = ARGB, ABGR, xRGB, xBGR */
|
|
|
|
{0, 0, 0, 255}, /* 1 = RGBA, BGRA, RGBx, BGRx */
|
|
|
|
{255, 16, 128, 128}, /* 2 = AYUV */
|
|
|
|
{0, 0, 0, 0}, /* 3 = RGB and BGR */
|
|
|
|
{16, 128, 128, 0}, /* 4 = v301 */
|
|
|
|
{16, 128, 16, 128}, /* 5 = YUY2, YUYV */
|
|
|
|
{128, 16, 128, 16}, /* 6 = UYVY */
|
|
|
|
{16, 0, 0, 0}, /* 7 = Y */
|
|
|
|
{0, 0, 0, 0} /* 8 = RGB565, RGB666 */
|
|
|
|
};
|
2005-08-24 15:07:54 +00:00
|
|
|
|
|
|
|
switch (format) {
|
2010-07-17 18:24:18 +00:00
|
|
|
case GST_VIDEO_FORMAT_ARGB:
|
|
|
|
case GST_VIDEO_FORMAT_ABGR:
|
|
|
|
case GST_VIDEO_FORMAT_xRGB:
|
|
|
|
case GST_VIDEO_FORMAT_xBGR:
|
2011-02-20 02:50:37 +00:00
|
|
|
case GST_VIDEO_FORMAT_ARGB64:
|
2010-07-17 18:24:18 +00:00
|
|
|
return black[0];
|
|
|
|
case GST_VIDEO_FORMAT_RGBA:
|
|
|
|
case GST_VIDEO_FORMAT_BGRA:
|
|
|
|
case GST_VIDEO_FORMAT_RGBx:
|
|
|
|
case GST_VIDEO_FORMAT_BGRx:
|
|
|
|
return black[1];
|
|
|
|
case GST_VIDEO_FORMAT_AYUV:
|
2011-02-20 02:50:37 +00:00
|
|
|
case GST_VIDEO_FORMAT_AYUV64:
|
2010-07-17 18:24:18 +00:00
|
|
|
return black[2];
|
|
|
|
case GST_VIDEO_FORMAT_RGB:
|
|
|
|
case GST_VIDEO_FORMAT_BGR:
|
|
|
|
return black[3];
|
|
|
|
case GST_VIDEO_FORMAT_v308:
|
|
|
|
return black[4];
|
|
|
|
case GST_VIDEO_FORMAT_YUY2:
|
|
|
|
case GST_VIDEO_FORMAT_YVYU:
|
|
|
|
return black[5];
|
|
|
|
case GST_VIDEO_FORMAT_UYVY:
|
|
|
|
return black[6];
|
|
|
|
case GST_VIDEO_FORMAT_Y800:
|
|
|
|
case GST_VIDEO_FORMAT_GRAY8:
|
|
|
|
return black[7];
|
|
|
|
case GST_VIDEO_FORMAT_GRAY16_LE:
|
|
|
|
case GST_VIDEO_FORMAT_GRAY16_BE:
|
|
|
|
case GST_VIDEO_FORMAT_Y16:
|
|
|
|
return NULL; /* Handled by the caller */
|
2010-06-12 11:35:47 +00:00
|
|
|
case GST_VIDEO_FORMAT_I420:
|
|
|
|
case GST_VIDEO_FORMAT_YV12:
|
|
|
|
case GST_VIDEO_FORMAT_Y444:
|
|
|
|
case GST_VIDEO_FORMAT_Y42B:
|
|
|
|
case GST_VIDEO_FORMAT_Y41B:
|
2010-07-17 18:24:18 +00:00
|
|
|
return black[4]; /* Y, U, V, 0 */
|
|
|
|
case GST_VIDEO_FORMAT_RGB16:
|
|
|
|
case GST_VIDEO_FORMAT_RGB15:
|
|
|
|
return black[8];
|
2005-07-01 16:55:43 +00:00
|
|
|
default:
|
2010-07-17 18:24:18 +00:00
|
|
|
return NULL;
|
2005-07-01 16:55:43 +00:00
|
|
|
}
|
2005-07-01 17:03:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
2005-12-01 01:12:55 +00:00
|
|
|
gst_video_scale_transform (GstBaseTransform * trans, GstBuffer * in,
|
2005-07-15 10:44:19 +00:00
|
|
|
GstBuffer * out)
|
2005-07-01 17:03:13 +00:00
|
|
|
{
|
2009-07-28 11:55:30 +00:00
|
|
|
GstVideoScale *videoscale = GST_VIDEO_SCALE (trans);
|
2005-08-24 15:07:54 +00:00
|
|
|
GstFlowReturn ret = GST_FLOW_OK;
|
2010-07-17 18:24:18 +00:00
|
|
|
VSImage dest = { NULL, };
|
|
|
|
VSImage src = { NULL, };
|
2009-07-28 11:55:30 +00:00
|
|
|
VSImage dest_u = { NULL, };
|
|
|
|
VSImage dest_v = { NULL, };
|
|
|
|
VSImage src_u = { NULL, };
|
|
|
|
VSImage src_v = { NULL, };
|
2007-12-22 12:06:47 +00:00
|
|
|
gint method;
|
2010-07-17 18:24:18 +00:00
|
|
|
const guint8 *black = _get_black_for_format (videoscale->format);
|
|
|
|
gboolean add_borders;
|
2011-03-27 14:35:28 +00:00
|
|
|
guint8 *in_data, *out_data;
|
|
|
|
gsize in_size, out_size;
|
2005-07-01 17:03:13 +00:00
|
|
|
|
2007-12-22 12:06:47 +00:00
|
|
|
GST_OBJECT_LOCK (videoscale);
|
|
|
|
method = videoscale->method;
|
2010-07-17 18:24:18 +00:00
|
|
|
add_borders = videoscale->add_borders;
|
2007-12-22 12:06:47 +00:00
|
|
|
GST_OBJECT_UNLOCK (videoscale);
|
|
|
|
|
2011-04-23 19:44:50 +00:00
|
|
|
if (videoscale->from_width == 1) {
|
|
|
|
method = GST_VIDEO_SCALE_NEAREST;
|
|
|
|
}
|
|
|
|
if (method == GST_VIDEO_SCALE_4TAP &&
|
|
|
|
(videoscale->from_width < 4 || videoscale->from_height < 4)) {
|
|
|
|
method = GST_VIDEO_SCALE_BILINEAR;
|
|
|
|
}
|
|
|
|
|
2011-03-27 14:35:28 +00:00
|
|
|
in_data = gst_buffer_map (in, &in_size, NULL, GST_MAP_READ);
|
|
|
|
out_data = gst_buffer_map (out, &out_size, NULL, GST_MAP_WRITE);
|
|
|
|
|
2010-07-17 18:24:18 +00:00
|
|
|
gst_video_scale_setup_vs_image (&src, videoscale->format, 0,
|
2011-03-27 14:35:28 +00:00
|
|
|
videoscale->from_width, videoscale->from_height, 0, 0, in_data);
|
2010-07-17 18:24:18 +00:00
|
|
|
gst_video_scale_setup_vs_image (&dest, videoscale->format, 0,
|
|
|
|
videoscale->to_width, videoscale->to_height, videoscale->borders_w,
|
2011-03-27 14:35:28 +00:00
|
|
|
videoscale->borders_h, out_data);
|
2010-07-17 18:24:18 +00:00
|
|
|
|
|
|
|
if (videoscale->format == GST_VIDEO_FORMAT_I420
|
|
|
|
|| videoscale->format == GST_VIDEO_FORMAT_YV12
|
|
|
|
|| videoscale->format == GST_VIDEO_FORMAT_Y444
|
|
|
|
|| videoscale->format == GST_VIDEO_FORMAT_Y42B
|
|
|
|
|| videoscale->format == GST_VIDEO_FORMAT_Y41B) {
|
|
|
|
gst_video_scale_setup_vs_image (&src_u, videoscale->format, 1,
|
2011-03-27 14:35:28 +00:00
|
|
|
videoscale->from_width, videoscale->from_height, 0, 0, in_data);
|
2010-07-17 18:24:18 +00:00
|
|
|
gst_video_scale_setup_vs_image (&src_v, videoscale->format, 2,
|
2011-03-27 14:35:28 +00:00
|
|
|
videoscale->from_width, videoscale->from_height, 0, 0, in_data);
|
2010-07-17 18:24:18 +00:00
|
|
|
gst_video_scale_setup_vs_image (&dest_u, videoscale->format, 1,
|
|
|
|
videoscale->to_width, videoscale->to_height, videoscale->borders_w,
|
2011-03-27 14:35:28 +00:00
|
|
|
videoscale->borders_h, out_data);
|
2010-07-17 18:24:18 +00:00
|
|
|
gst_video_scale_setup_vs_image (&dest_v, videoscale->format, 2,
|
|
|
|
videoscale->to_width, videoscale->to_height, videoscale->borders_w,
|
2011-03-27 14:35:28 +00:00
|
|
|
videoscale->borders_h, out_data);
|
2010-07-17 18:24:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (videoscale->format) {
|
|
|
|
case GST_VIDEO_FORMAT_RGBx:
|
|
|
|
case GST_VIDEO_FORMAT_xRGB:
|
|
|
|
case GST_VIDEO_FORMAT_BGRx:
|
|
|
|
case GST_VIDEO_FORMAT_xBGR:
|
|
|
|
case GST_VIDEO_FORMAT_RGBA:
|
|
|
|
case GST_VIDEO_FORMAT_ARGB:
|
|
|
|
case GST_VIDEO_FORMAT_BGRA:
|
|
|
|
case GST_VIDEO_FORMAT_ABGR:
|
|
|
|
case GST_VIDEO_FORMAT_AYUV:
|
|
|
|
if (add_borders)
|
|
|
|
vs_fill_borders_RGBA (&dest, black);
|
|
|
|
switch (method) {
|
|
|
|
case GST_VIDEO_SCALE_NEAREST:
|
2010-07-16 18:41:02 +00:00
|
|
|
vs_image_scale_nearest_RGBA (&dest, &src, videoscale->tmp_buf);
|
|
|
|
break;
|
2010-07-17 18:24:18 +00:00
|
|
|
case GST_VIDEO_SCALE_BILINEAR:
|
|
|
|
vs_image_scale_linear_RGBA (&dest, &src, videoscale->tmp_buf);
|
2010-07-16 18:41:02 +00:00
|
|
|
break;
|
2010-07-17 18:24:18 +00:00
|
|
|
case GST_VIDEO_SCALE_4TAP:
|
|
|
|
vs_image_scale_4tap_RGBA (&dest, &src, videoscale->tmp_buf);
|
2010-07-16 18:41:02 +00:00
|
|
|
break;
|
2010-07-17 18:24:18 +00:00
|
|
|
default:
|
|
|
|
goto unknown_mode;
|
|
|
|
}
|
|
|
|
break;
|
2011-02-20 02:50:37 +00:00
|
|
|
case GST_VIDEO_FORMAT_ARGB64:
|
|
|
|
case GST_VIDEO_FORMAT_AYUV64:
|
|
|
|
if (add_borders)
|
|
|
|
vs_fill_borders_AYUV64 (&dest, black);
|
|
|
|
switch (method) {
|
|
|
|
case GST_VIDEO_SCALE_NEAREST:
|
|
|
|
vs_image_scale_nearest_AYUV64 (&dest, &src, videoscale->tmp_buf);
|
|
|
|
break;
|
|
|
|
case GST_VIDEO_SCALE_BILINEAR:
|
|
|
|
vs_image_scale_linear_AYUV64 (&dest, &src, videoscale->tmp_buf);
|
|
|
|
break;
|
|
|
|
case GST_VIDEO_SCALE_4TAP:
|
|
|
|
vs_image_scale_4tap_AYUV64 (&dest, &src, videoscale->tmp_buf);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto unknown_mode;
|
|
|
|
}
|
|
|
|
break;
|
2010-07-17 18:24:18 +00:00
|
|
|
case GST_VIDEO_FORMAT_RGB:
|
|
|
|
case GST_VIDEO_FORMAT_BGR:
|
|
|
|
case GST_VIDEO_FORMAT_v308:
|
|
|
|
if (add_borders)
|
|
|
|
vs_fill_borders_RGB (&dest, black);
|
|
|
|
switch (method) {
|
|
|
|
case GST_VIDEO_SCALE_NEAREST:
|
|
|
|
vs_image_scale_nearest_RGB (&dest, &src, videoscale->tmp_buf);
|
2010-07-16 18:41:02 +00:00
|
|
|
break;
|
2010-07-17 18:24:18 +00:00
|
|
|
case GST_VIDEO_SCALE_BILINEAR:
|
|
|
|
vs_image_scale_linear_RGB (&dest, &src, videoscale->tmp_buf);
|
2010-07-16 18:41:02 +00:00
|
|
|
break;
|
2010-07-17 18:24:18 +00:00
|
|
|
case GST_VIDEO_SCALE_4TAP:
|
|
|
|
vs_image_scale_4tap_RGB (&dest, &src, videoscale->tmp_buf);
|
2010-07-16 18:41:02 +00:00
|
|
|
break;
|
2010-07-17 18:24:18 +00:00
|
|
|
default:
|
|
|
|
goto unknown_mode;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GST_VIDEO_FORMAT_YUY2:
|
|
|
|
case GST_VIDEO_FORMAT_YVYU:
|
|
|
|
if (add_borders)
|
|
|
|
vs_fill_borders_YUYV (&dest, black);
|
|
|
|
switch (method) {
|
|
|
|
case GST_VIDEO_SCALE_NEAREST:
|
|
|
|
vs_image_scale_nearest_YUYV (&dest, &src, videoscale->tmp_buf);
|
2010-07-16 18:41:02 +00:00
|
|
|
break;
|
2010-07-17 18:24:18 +00:00
|
|
|
case GST_VIDEO_SCALE_BILINEAR:
|
|
|
|
vs_image_scale_linear_YUYV (&dest, &src, videoscale->tmp_buf);
|
2010-07-16 18:41:02 +00:00
|
|
|
break;
|
2010-07-17 18:24:18 +00:00
|
|
|
case GST_VIDEO_SCALE_4TAP:
|
|
|
|
vs_image_scale_4tap_YUYV (&dest, &src, videoscale->tmp_buf);
|
2010-07-16 18:41:02 +00:00
|
|
|
break;
|
|
|
|
default:
|
2010-07-17 18:24:18 +00:00
|
|
|
goto unknown_mode;
|
2005-07-01 16:55:43 +00:00
|
|
|
}
|
2010-07-16 18:41:02 +00:00
|
|
|
break;
|
2010-07-17 18:24:18 +00:00
|
|
|
case GST_VIDEO_FORMAT_UYVY:
|
|
|
|
if (add_borders)
|
|
|
|
vs_fill_borders_UYVY (&dest, black);
|
|
|
|
switch (method) {
|
|
|
|
case GST_VIDEO_SCALE_NEAREST:
|
|
|
|
vs_image_scale_nearest_UYVY (&dest, &src, videoscale->tmp_buf);
|
2010-07-16 18:41:02 +00:00
|
|
|
break;
|
2010-07-17 18:24:18 +00:00
|
|
|
case GST_VIDEO_SCALE_BILINEAR:
|
2010-07-16 18:41:02 +00:00
|
|
|
vs_image_scale_linear_UYVY (&dest, &src, videoscale->tmp_buf);
|
|
|
|
break;
|
2010-07-17 18:24:18 +00:00
|
|
|
case GST_VIDEO_SCALE_4TAP:
|
|
|
|
vs_image_scale_4tap_UYVY (&dest, &src, videoscale->tmp_buf);
|
2010-07-16 18:41:02 +00:00
|
|
|
break;
|
2010-07-17 18:24:18 +00:00
|
|
|
default:
|
|
|
|
goto unknown_mode;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GST_VIDEO_FORMAT_Y800:
|
|
|
|
case GST_VIDEO_FORMAT_GRAY8:
|
|
|
|
if (add_borders)
|
|
|
|
vs_fill_borders_Y (&dest, black);
|
|
|
|
switch (method) {
|
|
|
|
case GST_VIDEO_SCALE_NEAREST:
|
|
|
|
vs_image_scale_nearest_Y (&dest, &src, videoscale->tmp_buf);
|
2010-07-16 18:41:02 +00:00
|
|
|
break;
|
2010-07-17 18:24:18 +00:00
|
|
|
case GST_VIDEO_SCALE_BILINEAR:
|
2010-07-16 18:41:02 +00:00
|
|
|
vs_image_scale_linear_Y (&dest, &src, videoscale->tmp_buf);
|
|
|
|
break;
|
2010-07-17 18:24:18 +00:00
|
|
|
case GST_VIDEO_SCALE_4TAP:
|
|
|
|
vs_image_scale_4tap_Y (&dest, &src, videoscale->tmp_buf);
|
2010-07-16 18:41:02 +00:00
|
|
|
break;
|
|
|
|
default:
|
2010-07-17 18:24:18 +00:00
|
|
|
goto unknown_mode;
|
2009-07-28 13:54:14 +00:00
|
|
|
}
|
2010-07-16 18:41:02 +00:00
|
|
|
break;
|
2010-07-17 18:24:18 +00:00
|
|
|
case GST_VIDEO_FORMAT_GRAY16_LE:
|
|
|
|
case GST_VIDEO_FORMAT_GRAY16_BE:
|
|
|
|
case GST_VIDEO_FORMAT_Y16:
|
|
|
|
if (add_borders)
|
|
|
|
vs_fill_borders_Y16 (&dest, 0);
|
|
|
|
switch (method) {
|
|
|
|
case GST_VIDEO_SCALE_NEAREST:
|
|
|
|
vs_image_scale_nearest_Y16 (&dest, &src, videoscale->tmp_buf);
|
2010-07-16 18:41:02 +00:00
|
|
|
break;
|
2010-07-17 18:24:18 +00:00
|
|
|
case GST_VIDEO_SCALE_BILINEAR:
|
|
|
|
vs_image_scale_linear_Y16 (&dest, &src, videoscale->tmp_buf);
|
2010-07-16 18:41:02 +00:00
|
|
|
break;
|
2010-07-17 18:24:18 +00:00
|
|
|
case GST_VIDEO_SCALE_4TAP:
|
|
|
|
vs_image_scale_4tap_Y16 (&dest, &src, videoscale->tmp_buf);
|
2010-07-16 18:41:02 +00:00
|
|
|
break;
|
2010-07-17 18:24:18 +00:00
|
|
|
default:
|
|
|
|
goto unknown_mode;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GST_VIDEO_FORMAT_I420:
|
|
|
|
case GST_VIDEO_FORMAT_YV12:
|
|
|
|
case GST_VIDEO_FORMAT_Y444:
|
|
|
|
case GST_VIDEO_FORMAT_Y42B:
|
|
|
|
case GST_VIDEO_FORMAT_Y41B:
|
|
|
|
if (add_borders) {
|
|
|
|
vs_fill_borders_Y (&dest, black);
|
|
|
|
vs_fill_borders_Y (&dest_u, black + 1);
|
|
|
|
vs_fill_borders_Y (&dest_v, black + 2);
|
|
|
|
}
|
|
|
|
switch (method) {
|
|
|
|
case GST_VIDEO_SCALE_NEAREST:
|
|
|
|
vs_image_scale_nearest_Y (&dest, &src, videoscale->tmp_buf);
|
|
|
|
vs_image_scale_nearest_Y (&dest_u, &src_u, videoscale->tmp_buf);
|
|
|
|
vs_image_scale_nearest_Y (&dest_v, &src_v, videoscale->tmp_buf);
|
2010-07-16 18:41:02 +00:00
|
|
|
break;
|
2010-07-17 18:24:18 +00:00
|
|
|
case GST_VIDEO_SCALE_BILINEAR:
|
|
|
|
vs_image_scale_linear_Y (&dest, &src, videoscale->tmp_buf);
|
|
|
|
vs_image_scale_linear_Y (&dest_u, &src_u, videoscale->tmp_buf);
|
|
|
|
vs_image_scale_linear_Y (&dest_v, &src_v, videoscale->tmp_buf);
|
2010-07-16 18:41:02 +00:00
|
|
|
break;
|
2010-07-17 18:24:18 +00:00
|
|
|
case GST_VIDEO_SCALE_4TAP:
|
2010-07-16 18:41:02 +00:00
|
|
|
vs_image_scale_4tap_Y (&dest, &src, videoscale->tmp_buf);
|
|
|
|
vs_image_scale_4tap_Y (&dest_u, &src_u, videoscale->tmp_buf);
|
|
|
|
vs_image_scale_4tap_Y (&dest_v, &src_v, videoscale->tmp_buf);
|
|
|
|
break;
|
2010-07-17 18:24:18 +00:00
|
|
|
default:
|
|
|
|
goto unknown_mode;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GST_VIDEO_FORMAT_RGB16:
|
|
|
|
if (add_borders)
|
|
|
|
vs_fill_borders_RGB565 (&dest, black);
|
|
|
|
switch (method) {
|
|
|
|
case GST_VIDEO_SCALE_NEAREST:
|
|
|
|
vs_image_scale_nearest_RGB565 (&dest, &src, videoscale->tmp_buf);
|
|
|
|
break;
|
|
|
|
case GST_VIDEO_SCALE_BILINEAR:
|
|
|
|
vs_image_scale_linear_RGB565 (&dest, &src, videoscale->tmp_buf);
|
|
|
|
break;
|
|
|
|
case GST_VIDEO_SCALE_4TAP:
|
2010-07-16 18:41:02 +00:00
|
|
|
vs_image_scale_4tap_RGB565 (&dest, &src, videoscale->tmp_buf);
|
|
|
|
break;
|
2010-07-17 18:24:18 +00:00
|
|
|
default:
|
|
|
|
goto unknown_mode;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GST_VIDEO_FORMAT_RGB15:
|
|
|
|
if (add_borders)
|
|
|
|
vs_fill_borders_RGB555 (&dest, black);
|
|
|
|
switch (method) {
|
|
|
|
case GST_VIDEO_SCALE_NEAREST:
|
|
|
|
vs_image_scale_nearest_RGB555 (&dest, &src, videoscale->tmp_buf);
|
|
|
|
break;
|
|
|
|
case GST_VIDEO_SCALE_BILINEAR:
|
|
|
|
vs_image_scale_linear_RGB555 (&dest, &src, videoscale->tmp_buf);
|
|
|
|
break;
|
|
|
|
case GST_VIDEO_SCALE_4TAP:
|
2010-07-16 18:41:02 +00:00
|
|
|
vs_image_scale_4tap_RGB555 (&dest, &src, videoscale->tmp_buf);
|
|
|
|
break;
|
|
|
|
default:
|
2010-07-17 18:24:18 +00:00
|
|
|
goto unknown_mode;
|
2009-07-28 13:54:14 +00:00
|
|
|
}
|
2010-07-16 18:41:02 +00:00
|
|
|
break;
|
|
|
|
default:
|
2010-07-17 18:24:18 +00:00
|
|
|
goto unsupported;
|
2005-07-01 16:55:43 +00:00
|
|
|
}
|
2001-12-22 23:27:17 +00:00
|
|
|
|
2004-07-27 15:56:55 +00:00
|
|
|
GST_LOG_OBJECT (videoscale, "pushing buffer of %d bytes",
|
2011-03-27 14:35:28 +00:00
|
|
|
gst_buffer_get_size (out));
|
|
|
|
|
|
|
|
done:
|
|
|
|
gst_buffer_unmap (in, in_data, in_size);
|
|
|
|
gst_buffer_unmap (out, out_data, out_size);
|
2003-04-22 07:32:50 +00:00
|
|
|
|
2005-08-24 15:07:54 +00:00
|
|
|
return ret;
|
docs/plugins/: Added videoscale to docs.
Original commit message from CVS:
* docs/plugins/Makefile.am:
* docs/plugins/gst-plugins-base-plugins-docs.sgml:
* docs/plugins/gst-plugins-base-plugins-sections.txt:
Added videoscale to docs.
* gst/videorate/gstvideorate.c: (gst_video_rate_flush_prev),
(gst_video_rate_swap_prev), (gst_video_rate_event),
(gst_video_rate_chain):
Fix typo in docs.
* gst/videoscale/gstvideoscale.c: (gst_video_scale_class_init),
(gst_video_scale_init), (gst_video_scale_prepare_size),
(gst_video_scale_set_caps), (gst_video_scale_get_unit_size),
(gst_video_scale_fixate_caps), (gst_video_scale_transform):
* gst/videoscale/gstvideoscale.h:
Added docs, examples.
Some code cleanups.
Post errors instead of g_warning.
2006-03-02 17:46:36 +00:00
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
unsupported:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (videoscale, STREAM, NOT_IMPLEMENTED, (NULL),
|
|
|
|
("Unsupported format %d for scaling method %d",
|
2007-12-22 12:06:47 +00:00
|
|
|
videoscale->format, method));
|
2011-03-27 14:35:28 +00:00
|
|
|
ret = GST_FLOW_ERROR;
|
|
|
|
goto done;
|
docs/plugins/: Added videoscale to docs.
Original commit message from CVS:
* docs/plugins/Makefile.am:
* docs/plugins/gst-plugins-base-plugins-docs.sgml:
* docs/plugins/gst-plugins-base-plugins-sections.txt:
Added videoscale to docs.
* gst/videorate/gstvideorate.c: (gst_video_rate_flush_prev),
(gst_video_rate_swap_prev), (gst_video_rate_event),
(gst_video_rate_chain):
Fix typo in docs.
* gst/videoscale/gstvideoscale.c: (gst_video_scale_class_init),
(gst_video_scale_init), (gst_video_scale_prepare_size),
(gst_video_scale_set_caps), (gst_video_scale_get_unit_size),
(gst_video_scale_fixate_caps), (gst_video_scale_transform):
* gst/videoscale/gstvideoscale.h:
Added docs, examples.
Some code cleanups.
Post errors instead of g_warning.
2006-03-02 17:46:36 +00:00
|
|
|
}
|
|
|
|
unknown_mode:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (videoscale, STREAM, NOT_IMPLEMENTED, (NULL),
|
|
|
|
("Unknown scaling method %d", videoscale->method));
|
2011-03-27 14:35:28 +00:00
|
|
|
ret = GST_FLOW_ERROR;
|
|
|
|
goto done;
|
docs/plugins/: Added videoscale to docs.
Original commit message from CVS:
* docs/plugins/Makefile.am:
* docs/plugins/gst-plugins-base-plugins-docs.sgml:
* docs/plugins/gst-plugins-base-plugins-sections.txt:
Added videoscale to docs.
* gst/videorate/gstvideorate.c: (gst_video_rate_flush_prev),
(gst_video_rate_swap_prev), (gst_video_rate_event),
(gst_video_rate_chain):
Fix typo in docs.
* gst/videoscale/gstvideoscale.c: (gst_video_scale_class_init),
(gst_video_scale_init), (gst_video_scale_prepare_size),
(gst_video_scale_set_caps), (gst_video_scale_get_unit_size),
(gst_video_scale_fixate_caps), (gst_video_scale_transform):
* gst/videoscale/gstvideoscale.h:
Added docs, examples.
Some code cleanups.
Post errors instead of g_warning.
2006-03-02 17:46:36 +00:00
|
|
|
}
|
2001-12-22 23:27:17 +00:00
|
|
|
}
|
|
|
|
|
2005-07-01 17:03:13 +00:00
|
|
|
static gboolean
|
2006-03-14 11:11:59 +00:00
|
|
|
gst_video_scale_src_event (GstBaseTransform * trans, GstEvent * event)
|
2001-12-22 23:27:17 +00:00
|
|
|
{
|
2010-04-23 13:14:56 +00:00
|
|
|
GstVideoScale *videoscale = GST_VIDEO_SCALE (trans);
|
2005-11-16 12:23:02 +00:00
|
|
|
gboolean ret;
|
2010-04-23 13:14:56 +00:00
|
|
|
gdouble a;
|
2005-07-01 17:03:13 +00:00
|
|
|
GstStructure *structure;
|
2001-12-22 23:27:17 +00:00
|
|
|
|
2005-11-16 12:23:02 +00:00
|
|
|
GST_DEBUG_OBJECT (videoscale, "handling %s event",
|
|
|
|
GST_EVENT_TYPE_NAME (event));
|
|
|
|
|
2005-07-01 17:03:13 +00:00
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
|
|
|
case GST_EVENT_NAVIGATION:
|
|
|
|
event =
|
|
|
|
GST_EVENT (gst_mini_object_make_writable (GST_MINI_OBJECT (event)));
|
examples/seeking/seek.c: Update seek example.
Original commit message from CVS:
* examples/seeking/seek.c: (setup_dynamic_link),
(make_dv_pipeline), (make_vorbis_theora_pipeline), (query_rates),
(query_positions_elems), (query_positions_pads), (do_seek):
Update seek example.
* ext/ogg/gstoggdemux.c: (gst_ogg_pad_event),
(gst_ogg_pad_typefind), (gst_ogg_demux_chain_elem_pad),
(gst_ogg_demux_queue_data), (gst_ogg_demux_chain_peer),
(gst_ogg_pad_submit_packet), (gst_ogg_pad_submit_page),
(gst_ogg_demux_handle_event),
(gst_ogg_demux_deactivate_current_chain),
(gst_ogg_demux_activate_chain), (gst_ogg_demux_perform_seek),
(gst_ogg_demux_collect_chain_info), (gst_ogg_demux_collect_info),
(gst_ogg_demux_chain), (gst_ogg_demux_send_event),
(gst_ogg_demux_loop):
* ext/ogg/gstoggmux.c: (gst_ogg_mux_collected):
* ext/theora/theoradec.c: (theora_dec_src_event),
(theora_dec_src_getcaps), (theora_dec_sink_event),
(theora_dec_push), (theora_dec_chain):
* ext/vorbis/Makefile.am:
* ext/vorbis/vorbisdec.c: (vorbis_dec_src_event),
(vorbis_dec_sink_event), (vorbis_dec_push),
(vorbis_handle_data_packet):
* ext/vorbis/vorbisenc.c: (gst_vorbisenc_sink_event),
(gst_vorbisenc_chain):
* gst/playback/gststreaminfo.c: (cb_probe):
* gst/subparse/gstsubparse.c: (gst_subparse_src_event):
* gst/videorate/gstvideorate.c: (gst_videorate_event):
* gst/videoscale/gstvideoscale.c:
(gst_videoscale_handle_src_event):
* gst/videotestsrc/gstvideotestsrc.c: (gst_videotestsrc_event):
* sys/ximage/ximagesink.c: (gst_ximagesink_show_frame),
(gst_ximagesink_navigation_send_event):
* sys/xvimage/xvimagesink.c:
(gst_xvimagesink_navigation_send_event):
Various event updates and cleanups
2005-07-27 18:34:29 +00:00
|
|
|
|
|
|
|
structure = (GstStructure *) gst_event_get_structure (event);
|
2005-07-01 17:03:13 +00:00
|
|
|
if (gst_structure_get_double (structure, "pointer_x", &a)) {
|
|
|
|
gst_structure_set (structure, "pointer_x", G_TYPE_DOUBLE,
|
|
|
|
a * videoscale->from_width / videoscale->to_width, NULL);
|
|
|
|
}
|
|
|
|
if (gst_structure_get_double (structure, "pointer_y", &a)) {
|
|
|
|
gst_structure_set (structure, "pointer_y", G_TYPE_DOUBLE,
|
|
|
|
a * videoscale->from_height / videoscale->to_height, NULL);
|
|
|
|
}
|
2005-11-16 12:23:02 +00:00
|
|
|
break;
|
2001-12-22 23:27:17 +00:00
|
|
|
default:
|
2005-11-16 12:23:02 +00:00
|
|
|
break;
|
2001-12-22 23:27:17 +00:00
|
|
|
}
|
2005-11-16 12:23:02 +00:00
|
|
|
|
2006-03-14 11:11:59 +00:00
|
|
|
ret = GST_BASE_TRANSFORM_CLASS (parent_class)->src_event (trans, event);
|
2005-11-16 12:23:02 +00:00
|
|
|
|
|
|
|
return ret;
|
2001-12-22 23:27:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2004-03-14 22:34:34 +00:00
|
|
|
plugin_init (GstPlugin * plugin)
|
2001-12-22 23:27:17 +00:00
|
|
|
{
|
2010-09-09 08:57:41 +00:00
|
|
|
gst_videoscale_orc_init ();
|
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
if (!gst_element_register (plugin, "videoscale", GST_RANK_NONE,
|
2005-12-01 01:12:55 +00:00
|
|
|
GST_TYPE_VIDEO_SCALE))
|
2004-02-25 17:37:26 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2005-12-01 01:12:55 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT (video_scale_debug, "videoscale", 0,
|
2004-03-14 22:34:34 +00:00
|
|
|
"videoscale element");
|
2004-02-25 17:37:26 +00:00
|
|
|
|
2006-11-14 23:08:38 +00:00
|
|
|
vs_4tap_init ();
|
|
|
|
|
2004-02-25 17:37:26 +00:00
|
|
|
return TRUE;
|
2001-12-22 23:27:17 +00:00
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
|
|
|
|
GST_VERSION_MINOR,
|
|
|
|
"videoscale",
|
2005-10-16 13:54:44 +00:00
|
|
|
"Resizes video", plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME,
|
|
|
|
GST_PACKAGE_ORIGIN)
|