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>
|
2020-04-17 19:23:03 +00:00
|
|
|
* Copyright (C) 2003 Ronald Bultje <rbultje@ronald.bitfreak.net>
|
2012-01-30 16:21:54 +00:00
|
|
|
* Copyright (C) 2005-2012 David Schleef <ds@schleef.org>
|
2020-04-17 19:23:03 +00:00
|
|
|
* Copyright (C) 2022 Thibault Saunier <tsaunier@igalia.com>
|
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
|
2012-11-03 23:05:09 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2001-12-22 23:27:17 +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
|
|
|
/**
|
2020-04-17 19:23:03 +00:00
|
|
|
* SECTION:element-videoconvertscale
|
|
|
|
* @title: videoconvertscale
|
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
|
|
|
*
|
2020-04-17 19:23:03 +00:00
|
|
|
* This element resizes video frames and allows changing colorspace. 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
|
|
|
*
|
2017-01-23 19:36:11 +00:00
|
|
|
* ## Example pipelines
|
2008-07-11 06:10:24 +00:00
|
|
|
* |[
|
2020-04-17 19:23:03 +00:00
|
|
|
* gst-launch-1.0 -v filesrc location=videotestsrc.ogg ! oggdemux ! theoradec ! videoconvertscale ! autovideosink
|
2017-01-23 19:36:11 +00:00
|
|
|
* ]|
|
|
|
|
* Decode an Ogg/Theora and display the video. If the video sink chosen
|
2020-04-17 19:23:03 +00:00
|
|
|
* cannot perform scaling, the video scaling will be performed by videoconvertscale
|
2015-05-09 21:33:26 +00:00
|
|
|
* 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
|
|
|
* |[
|
2020-04-17 19:23:03 +00:00
|
|
|
* gst-launch-1.0 -v filesrc location=videotestsrc.ogg ! oggdemux ! theoradec ! videoconvertscale ! video/x-raw,width=100 ! autovideosink
|
2017-01-23 19:36:11 +00:00
|
|
|
* ]|
|
|
|
|
* Decode an Ogg/Theora and display the video with a width of 100.
|
|
|
|
*
|
2020-04-17 19:23:03 +00:00
|
|
|
* Since: 1.22
|
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
|
|
|
|
2021-01-04 22:25:10 +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
|
2021-01-04 22:25:10 +00:00
|
|
|
*
|
2010-07-17 18:24:18 +00:00
|
|
|
* 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>
|
|
|
|
|
2011-10-31 01:23:21 +00:00
|
|
|
#include <gst/video/gstvideometa.h>
|
2011-07-29 15:15:39 +00:00
|
|
|
#include <gst/video/gstvideopool.h>
|
2005-07-01 17:03:13 +00:00
|
|
|
|
2020-04-17 19:23:03 +00:00
|
|
|
#include "gstvideoconvertscale.h"
|
2005-07-01 17:03:13 +00:00
|
|
|
|
2020-04-17 19:23:03 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
/* properties */
|
|
|
|
GstVideoScaleMethod method;
|
|
|
|
gboolean add_borders;
|
|
|
|
double sharpness;
|
|
|
|
double sharpen;
|
|
|
|
int submethod;
|
|
|
|
double envelope;
|
|
|
|
gint n_threads;
|
|
|
|
GstVideoDitherMethod dither;
|
|
|
|
guint dither_quantization;
|
|
|
|
GstVideoResamplerMethod chroma_resampler;
|
|
|
|
GstVideoAlphaMode alpha_mode;
|
|
|
|
GstVideoChromaMode chroma_mode;
|
|
|
|
GstVideoMatrixMode matrix_mode;
|
|
|
|
GstVideoGammaMode gamma_mode;
|
|
|
|
GstVideoPrimariesMode primaries_mode;
|
|
|
|
gdouble alpha_value;
|
|
|
|
|
|
|
|
GstVideoConverter *convert;
|
|
|
|
|
2022-03-23 13:38:00 +00:00
|
|
|
GstStructure *converter_config;
|
|
|
|
gboolean converter_config_changed;
|
|
|
|
|
2020-04-17 19:23:03 +00:00
|
|
|
gint borders_h;
|
|
|
|
gint borders_w;
|
|
|
|
} GstVideoConvertScalePrivate;
|
|
|
|
|
|
|
|
#define gst_video_convert_scale_parent_class parent_class
|
|
|
|
G_DEFINE_TYPE_WITH_PRIVATE (GstVideoConvertScale, gst_video_convert_scale,
|
|
|
|
GST_TYPE_VIDEO_FILTER);
|
|
|
|
GST_ELEMENT_REGISTER_DEFINE (videoconvertscale, "videoconvertscale",
|
|
|
|
GST_RANK_SECONDARY, GST_TYPE_VIDEO_CONVERT_SCALE);
|
|
|
|
|
2022-08-05 11:16:00 +00:00
|
|
|
#define PRIV(self) gst_video_convert_scale_get_instance_private(((GstVideoConvertScale*) self))
|
2020-04-17 19:23:03 +00:00
|
|
|
|
|
|
|
#define GST_CAT_DEFAULT video_convertscale_debug
|
|
|
|
GST_DEBUG_CATEGORY_STATIC (video_convertscale_debug);
|
2016-02-20 11:31:43 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (CAT_PERFORMANCE);
|
2001-12-22 23:27:17 +00:00
|
|
|
|
2010-07-17 18:24:18 +00:00
|
|
|
#define DEFAULT_PROP_METHOD GST_VIDEO_SCALE_BILINEAR
|
2013-03-21 10:14:27 +00:00
|
|
|
#define DEFAULT_PROP_ADD_BORDERS TRUE
|
2011-03-18 02:13:58 +00:00
|
|
|
#define DEFAULT_PROP_SHARPNESS 1.0
|
|
|
|
#define DEFAULT_PROP_SHARPEN 0.0
|
2020-04-17 19:23:03 +00:00
|
|
|
#define DEFAULT_PROP_DITHER GST_VIDEO_DITHER_BAYER
|
2011-03-18 02:13:58 +00:00
|
|
|
#define DEFAULT_PROP_ENVELOPE 2.0
|
2020-04-17 19:23:03 +00:00
|
|
|
#define DEFAULT_PROP_DITHER_QUANTIZATION 1
|
|
|
|
#define DEFAULT_PROP_CHROMA_RESAMPLER GST_VIDEO_RESAMPLER_METHOD_LINEAR
|
|
|
|
#define DEFAULT_PROP_ALPHA_MODE GST_VIDEO_ALPHA_MODE_COPY
|
|
|
|
#define DEFAULT_PROP_ALPHA_VALUE 1.0
|
|
|
|
#define DEFAULT_PROP_CHROMA_MODE GST_VIDEO_CHROMA_MODE_FULL
|
|
|
|
#define DEFAULT_PROP_MATRIX_MODE GST_VIDEO_MATRIX_MODE_FULL
|
|
|
|
#define DEFAULT_PROP_GAMMA_MODE GST_VIDEO_GAMMA_MODE_NONE
|
|
|
|
#define DEFAULT_PROP_PRIMARIES_MODE GST_VIDEO_PRIMARIES_MODE_NONE
|
|
|
|
#define DEFAULT_PROP_N_THREADS 1
|
|
|
|
|
|
|
|
static GQuark _colorspace_quark;
|
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,
|
2011-03-18 02:13:58 +00:00
|
|
|
PROP_ADD_BORDERS,
|
|
|
|
PROP_SHARPNESS,
|
|
|
|
PROP_SHARPEN,
|
|
|
|
PROP_DITHER,
|
|
|
|
PROP_SUBMETHOD,
|
2014-11-25 10:54:51 +00:00
|
|
|
PROP_ENVELOPE,
|
2020-04-17 19:23:03 +00:00
|
|
|
PROP_N_THREADS,
|
|
|
|
PROP_DITHER_QUANTIZATION,
|
|
|
|
PROP_CHROMA_RESAMPLER,
|
|
|
|
PROP_ALPHA_MODE,
|
|
|
|
PROP_ALPHA_VALUE,
|
|
|
|
PROP_CHROMA_MODE,
|
|
|
|
PROP_MATRIX_MODE,
|
|
|
|
PROP_GAMMA_MODE,
|
|
|
|
PROP_PRIMARIES_MODE,
|
2022-03-23 13:38:00 +00:00
|
|
|
PROP_CONVERTER_CONFIG,
|
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]"
|
|
|
|
|
2012-08-05 16:21:31 +00:00
|
|
|
/* FIXME: add v210 support
|
|
|
|
* FIXME: add v216 support
|
|
|
|
* FIXME: add UYVP support
|
|
|
|
* FIXME: add A420 support
|
|
|
|
* FIXME: add YUV9 support
|
|
|
|
* FIXME: add YVU9 support
|
|
|
|
* FIXME: add IYU1 support
|
|
|
|
* FIXME: add r210 support
|
|
|
|
*/
|
|
|
|
|
2014-10-24 15:08:43 +00:00
|
|
|
#define GST_VIDEO_FORMATS GST_VIDEO_FORMATS_ALL
|
2011-06-16 10:48:33 +00:00
|
|
|
|
2020-04-17 19:23:03 +00:00
|
|
|
static GstStaticCaps gst_video_convert_scale_format_caps =
|
2013-04-08 06:29:34 +00:00
|
|
|
GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE (GST_VIDEO_FORMATS) ";"
|
2023-09-27 11:55:33 +00:00
|
|
|
GST_VIDEO_CAPS_MAKE_WITH_FEATURES ("ANY", GST_VIDEO_FORMATS_ANY));
|
2005-07-01 16:55:43 +00:00
|
|
|
|
2020-08-28 11:30:43 +00:00
|
|
|
static GQuark _size_quark;
|
|
|
|
static GQuark _scale_quark;
|
2020-01-23 17:02:52 +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"},
|
2014-11-25 10:28:42 +00:00
|
|
|
{GST_VIDEO_SCALE_BILINEAR, "Bilinear (2-tap)", "bilinear"},
|
2014-11-27 08:45:07 +00:00
|
|
|
{GST_VIDEO_SCALE_4TAP, "4-tap Sinc", "4-tap"},
|
2014-11-25 10:28:42 +00:00
|
|
|
{GST_VIDEO_SCALE_LANCZOS, "Lanczos", "lanczos"},
|
|
|
|
{GST_VIDEO_SCALE_BILINEAR2, "Bilinear (multi-tap)", "bilinear2"},
|
|
|
|
{GST_VIDEO_SCALE_SINC, "Sinc (multi-tap)", "sinc"},
|
|
|
|
{GST_VIDEO_SCALE_HERMITE, "Hermite (multi-tap)", "hermite"},
|
|
|
|
{GST_VIDEO_SCALE_SPLINE, "Spline (multi-tap)", "spline"},
|
|
|
|
{GST_VIDEO_SCALE_CATROM, "Catmull-Rom (multi-tap)", "catrom"},
|
|
|
|
{GST_VIDEO_SCALE_MITCHELL, "Mitchell (multi-tap)", "mitchell"},
|
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 *
|
2020-04-17 19:23:03 +00:00
|
|
|
gst_video_convert_scale_get_capslist (void)
|
2001-12-22 23:27:17 +00:00
|
|
|
{
|
2010-04-23 13:14:56 +00:00
|
|
|
static GstCaps *caps = NULL;
|
2021-03-18 08:18:36 +00:00
|
|
|
static 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)) {
|
2020-04-17 19:23:03 +00:00
|
|
|
caps = gst_static_caps_get (&gst_video_convert_scale_format_caps);
|
2010-04-23 13:14:56 +00:00
|
|
|
g_once_init_leave (&inited, 1);
|
2003-11-02 20:48:33 +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 *
|
2020-04-17 19:23:03 +00:00
|
|
|
gst_video_convert_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,
|
2020-04-17 19:23:03 +00:00
|
|
|
gst_video_convert_scale_get_capslist ());
|
2003-04-22 07:32:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GstPadTemplate *
|
2020-04-17 19:23:03 +00:00
|
|
|
gst_video_convert_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,
|
2020-04-17 19:23:03 +00:00
|
|
|
gst_video_convert_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
|
|
|
|
2020-04-17 19:23:03 +00:00
|
|
|
static void gst_video_convert_scale_finalize (GstVideoConvertScale * self);
|
|
|
|
static gboolean gst_video_convert_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 */
|
2020-04-17 19:23:03 +00:00
|
|
|
static GstCaps *gst_video_convert_scale_transform_caps (GstBaseTransform *
|
|
|
|
trans, GstPadDirection direction, GstCaps * caps, GstCaps * filter);
|
|
|
|
static GstCaps *gst_video_convert_scale_fixate_caps (GstBaseTransform * base,
|
2005-11-18 17:31:17 +00:00
|
|
|
GstPadDirection direction, GstCaps * caps, GstCaps * othercaps);
|
2020-04-17 19:23:03 +00:00
|
|
|
static gboolean gst_video_convert_scale_transform_meta (GstBaseTransform *
|
|
|
|
trans, GstBuffer * outbuf, GstMeta * meta, GstBuffer * inbuf);
|
2005-07-01 17:03:13 +00:00
|
|
|
|
2020-04-17 19:23:03 +00:00
|
|
|
static gboolean gst_video_convert_scale_set_info (GstVideoFilter * filter,
|
2011-12-21 22:46:53 +00:00
|
|
|
GstCaps * in, GstVideoInfo * in_info, GstCaps * out,
|
|
|
|
GstVideoInfo * out_info);
|
2020-04-17 19:23:03 +00:00
|
|
|
static GstFlowReturn gst_video_convert_scale_transform_frame (GstVideoFilter *
|
|
|
|
filter, GstVideoFrame * in, GstVideoFrame * out);
|
2003-11-02 20:48:33 +00:00
|
|
|
|
2020-04-17 19:23:03 +00:00
|
|
|
static void gst_video_convert_scale_set_property (GObject * object,
|
|
|
|
guint prop_id, const GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_video_convert_scale_get_property (GObject * object,
|
|
|
|
guint prop_id, GValue * value, GParamSpec * pspec);
|
2005-07-01 17:03:13 +00:00
|
|
|
|
2021-02-04 16:22:15 +00:00
|
|
|
static GstCapsFeatures *features_format_interlaced,
|
|
|
|
*features_format_interlaced_sysmem;
|
|
|
|
|
2020-04-17 19:23:03 +00:00
|
|
|
static gboolean
|
|
|
|
gst_video_convert_scale_filter_meta (GstBaseTransform * trans, GstQuery * query,
|
|
|
|
GType api, const GstStructure * params)
|
|
|
|
{
|
|
|
|
/* This element cannot passthrough the crop meta, because it would convert the
|
|
|
|
* wrong sub-region of the image, and worst, our output image may not be large
|
|
|
|
* enough for the crop to be applied later */
|
|
|
|
if (api == GST_VIDEO_CROP_META_API_TYPE)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* propose all other metadata upstream */
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2003-11-02 20:48:33 +00:00
|
|
|
static void
|
2020-04-17 19:23:03 +00:00
|
|
|
gst_video_convert_scale_class_init (GstVideoConvertScaleClass * 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;
|
2011-12-21 22:46:53 +00:00
|
|
|
GstVideoFilterClass *filter_class = (GstVideoFilterClass *) klass;
|
2003-11-02 20:48:33 +00:00
|
|
|
|
2020-04-17 19:23:03 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT (video_convertscale_debug, "videoconvertscale", 0,
|
|
|
|
"videoconvertscale element");
|
|
|
|
GST_DEBUG_CATEGORY_GET (CAT_PERFORMANCE, "GST_PERFORMANCE");
|
|
|
|
|
|
|
|
features_format_interlaced =
|
2024-09-03 09:16:19 +00:00
|
|
|
gst_caps_features_new_static_str (GST_CAPS_FEATURE_FORMAT_INTERLACED,
|
|
|
|
NULL);
|
2020-04-17 19:23:03 +00:00
|
|
|
features_format_interlaced_sysmem =
|
|
|
|
gst_caps_features_copy (features_format_interlaced);
|
|
|
|
gst_caps_features_add (features_format_interlaced_sysmem,
|
|
|
|
GST_CAPS_FEATURE_MEMORY_SYSTEM_MEMORY);
|
|
|
|
|
|
|
|
_colorspace_quark = g_quark_from_static_string ("colorspace");
|
|
|
|
|
|
|
|
gobject_class->finalize =
|
|
|
|
(GObjectFinalizeFunc) gst_video_convert_scale_finalize;
|
|
|
|
gobject_class->set_property = gst_video_convert_scale_set_property;
|
|
|
|
gobject_class->get_property = gst_video_convert_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-03-18 02:13:58 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_SHARPNESS,
|
|
|
|
g_param_spec_double ("sharpness", "Sharpness",
|
2013-04-06 20:00:02 +00:00
|
|
|
"Sharpness of filter", 0.5, 1.5, DEFAULT_PROP_SHARPNESS,
|
2011-03-18 02:13:58 +00:00
|
|
|
G_PARAM_CONSTRUCT | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, PROP_SHARPEN,
|
|
|
|
g_param_spec_double ("sharpen", "Sharpen",
|
|
|
|
"Sharpening", 0.0, 1.0, DEFAULT_PROP_SHARPEN,
|
|
|
|
G_PARAM_CONSTRUCT | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, PROP_DITHER,
|
2020-04-17 19:23:03 +00:00
|
|
|
g_param_spec_enum ("dither", "Dither", "Apply dithering while converting",
|
|
|
|
gst_video_dither_method_get_type (), DEFAULT_PROP_DITHER,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2011-03-18 02:13:58 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_ENVELOPE,
|
|
|
|
g_param_spec_double ("envelope", "Envelope",
|
2013-04-06 20:00:02 +00:00
|
|
|
"Size of filter envelope", 1.0, 5.0, DEFAULT_PROP_ENVELOPE,
|
2011-03-18 02:13:58 +00:00
|
|
|
G_PARAM_CONSTRUCT | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2017-02-20 19:38:17 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_N_THREADS,
|
|
|
|
g_param_spec_uint ("n-threads", "Threads",
|
|
|
|
"Maximum number of threads to use", 0, G_MAXUINT,
|
|
|
|
DEFAULT_PROP_N_THREADS,
|
|
|
|
G_PARAM_CONSTRUCT | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2014-11-25 10:54:51 +00:00
|
|
|
|
2020-04-17 19:23:03 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_DITHER_QUANTIZATION,
|
|
|
|
g_param_spec_uint ("dither-quantization", "Dither Quantize",
|
|
|
|
"Quantizer to use", 0, G_MAXUINT, DEFAULT_PROP_DITHER_QUANTIZATION,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
g_object_class_install_property (gobject_class, PROP_CHROMA_RESAMPLER,
|
|
|
|
g_param_spec_enum ("chroma-resampler", "Chroma resampler",
|
|
|
|
"Chroma resampler method", gst_video_resampler_method_get_type (),
|
|
|
|
DEFAULT_PROP_CHROMA_RESAMPLER,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
g_object_class_install_property (gobject_class, PROP_ALPHA_MODE,
|
|
|
|
g_param_spec_enum ("alpha-mode", "Alpha Mode",
|
|
|
|
"Alpha Mode to use", gst_video_alpha_mode_get_type (),
|
|
|
|
DEFAULT_PROP_ALPHA_MODE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
g_object_class_install_property (gobject_class, PROP_ALPHA_VALUE,
|
|
|
|
g_param_spec_double ("alpha-value", "Alpha Value",
|
|
|
|
"Alpha Value to use", 0.0, 1.0,
|
|
|
|
DEFAULT_PROP_ALPHA_VALUE,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
g_object_class_install_property (gobject_class, PROP_CHROMA_MODE,
|
|
|
|
g_param_spec_enum ("chroma-mode", "Chroma Mode", "Chroma Resampling Mode",
|
|
|
|
gst_video_chroma_mode_get_type (), DEFAULT_PROP_CHROMA_MODE,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
g_object_class_install_property (gobject_class, PROP_MATRIX_MODE,
|
|
|
|
g_param_spec_enum ("matrix-mode", "Matrix Mode", "Matrix Conversion Mode",
|
|
|
|
gst_video_matrix_mode_get_type (), DEFAULT_PROP_MATRIX_MODE,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
g_object_class_install_property (gobject_class, PROP_GAMMA_MODE,
|
|
|
|
g_param_spec_enum ("gamma-mode", "Gamma Mode", "Gamma Conversion Mode",
|
|
|
|
gst_video_gamma_mode_get_type (), DEFAULT_PROP_GAMMA_MODE,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
g_object_class_install_property (gobject_class, PROP_PRIMARIES_MODE,
|
|
|
|
g_param_spec_enum ("primaries-mode", "Primaries Mode",
|
|
|
|
"Primaries Conversion Mode", gst_video_primaries_mode_get_type (),
|
|
|
|
DEFAULT_PROP_PRIMARIES_MODE,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2022-03-23 13:38:00 +00:00
|
|
|
/**
|
|
|
|
* GstVideoConvertScale:converter-config:
|
|
|
|
*
|
|
|
|
* A #GstStructure describing the configuration that should be used. This
|
|
|
|
* configuration, if set, takes precedence over the other similar conversion
|
|
|
|
* properties.
|
|
|
|
*
|
|
|
|
* Since: 1.24
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_CONVERTER_CONFIG, g_param_spec_boxed ("converter-config",
|
|
|
|
"Converter configuration",
|
|
|
|
"A GstStructure describing the configuration that should be used."
|
|
|
|
" This configuration, if set, takes precedence over the other similar conversion properties.",
|
|
|
|
GST_TYPE_STRUCTURE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
|
|
|
|
2012-04-09 23:45:16 +00:00
|
|
|
gst_element_class_set_static_metadata (element_class,
|
2020-04-17 19:23:03 +00:00
|
|
|
"Video colorspace converter and scaler",
|
|
|
|
"Filter/Converter/Video/Scaler/Colorspace",
|
2022-11-08 14:42:58 +00:00
|
|
|
"Resizes video and converts from one colorspace to another",
|
2020-04-17 19:23:03 +00:00
|
|
|
"Wim Taymans <wim.taymans@gmail.com>");
|
2011-04-19 09:35:53 +00:00
|
|
|
|
|
|
|
gst_element_class_add_pad_template (element_class,
|
2020-04-17 19:23:03 +00:00
|
|
|
gst_video_convert_scale_sink_template_factory ());
|
2011-04-19 09:35:53 +00:00
|
|
|
gst_element_class_add_pad_template (element_class,
|
2020-04-17 19:23:03 +00:00
|
|
|
gst_video_convert_scale_src_template_factory ());
|
2020-01-23 17:02:52 +00:00
|
|
|
|
|
|
|
_size_quark = g_quark_from_static_string (GST_META_TAG_VIDEO_SIZE_STR);
|
|
|
|
_scale_quark = gst_video_meta_transform_scale_get_quark ();
|
2020-05-29 00:43:59 +00:00
|
|
|
|
2020-06-05 22:41:17 +00:00
|
|
|
gst_type_mark_as_plugin_api (GST_TYPE_VIDEO_SCALE_METHOD, 0);
|
2020-04-17 19:23:03 +00:00
|
|
|
trans_class->transform_caps =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_video_convert_scale_transform_caps);
|
|
|
|
trans_class->fixate_caps =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_video_convert_scale_fixate_caps);
|
|
|
|
trans_class->filter_meta =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_video_convert_scale_filter_meta);
|
|
|
|
trans_class->src_event =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_video_convert_scale_src_event);
|
|
|
|
trans_class->transform_meta =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_video_convert_scale_transform_meta);
|
|
|
|
|
|
|
|
filter_class->set_info = GST_DEBUG_FUNCPTR (gst_video_convert_scale_set_info);
|
|
|
|
filter_class->transform_frame =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_video_convert_scale_transform_frame);
|
2022-08-05 11:52:19 +00:00
|
|
|
|
|
|
|
klass->converts = TRUE;
|
|
|
|
klass->scales = TRUE;
|
2023-04-12 23:11:51 +00:00
|
|
|
|
|
|
|
gst_type_mark_as_plugin_api (GST_TYPE_VIDEO_CONVERT_SCALE, 0);
|
2001-12-22 23:27:17 +00:00
|
|
|
}
|
|
|
|
|
2005-07-01 17:03:13 +00:00
|
|
|
static void
|
2020-04-17 19:23:03 +00:00
|
|
|
gst_video_convert_scale_init (GstVideoConvertScale * self)
|
2001-12-22 23:27:17 +00:00
|
|
|
{
|
2020-04-17 19:23:03 +00:00
|
|
|
GstVideoConvertScalePrivate *priv = PRIV (self);
|
|
|
|
|
|
|
|
priv->method = DEFAULT_PROP_METHOD;
|
|
|
|
priv->add_borders = DEFAULT_PROP_ADD_BORDERS;
|
|
|
|
priv->sharpness = DEFAULT_PROP_SHARPNESS;
|
|
|
|
priv->sharpen = DEFAULT_PROP_SHARPEN;
|
|
|
|
priv->envelope = DEFAULT_PROP_ENVELOPE;
|
|
|
|
priv->n_threads = DEFAULT_PROP_N_THREADS;
|
|
|
|
priv->dither = DEFAULT_PROP_DITHER;
|
|
|
|
priv->dither_quantization = DEFAULT_PROP_DITHER_QUANTIZATION;
|
|
|
|
priv->chroma_resampler = DEFAULT_PROP_CHROMA_RESAMPLER;
|
|
|
|
priv->alpha_mode = DEFAULT_PROP_ALPHA_MODE;
|
|
|
|
priv->alpha_value = DEFAULT_PROP_ALPHA_VALUE;
|
|
|
|
priv->chroma_mode = DEFAULT_PROP_CHROMA_MODE;
|
|
|
|
priv->matrix_mode = DEFAULT_PROP_MATRIX_MODE;
|
|
|
|
priv->gamma_mode = DEFAULT_PROP_GAMMA_MODE;
|
|
|
|
priv->primaries_mode = DEFAULT_PROP_PRIMARIES_MODE;
|
2022-03-23 13:38:00 +00:00
|
|
|
|
|
|
|
priv->converter_config = NULL;
|
|
|
|
priv->converter_config_changed = FALSE;
|
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
|
2020-04-17 19:23:03 +00:00
|
|
|
gst_video_convert_scale_finalize (GstVideoConvertScale * self)
|
2006-07-28 17:17:24 +00:00
|
|
|
{
|
2020-04-17 19:23:03 +00:00
|
|
|
GstVideoConvertScalePrivate *priv = PRIV (self);
|
2006-07-28 17:17:24 +00:00
|
|
|
|
2020-04-17 19:23:03 +00:00
|
|
|
if (priv->convert)
|
|
|
|
gst_video_converter_free (priv->convert);
|
|
|
|
|
2022-03-23 13:38:00 +00:00
|
|
|
if (priv->converter_config)
|
|
|
|
gst_structure_free (priv->converter_config);
|
|
|
|
priv->converter_config = NULL;
|
|
|
|
|
2020-04-17 19:23:03 +00:00
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (G_OBJECT (self));
|
2006-07-28 17:17:24 +00:00
|
|
|
}
|
2003-11-11 05:35:31 +00:00
|
|
|
|
2005-07-01 17:03:13 +00:00
|
|
|
static void
|
2020-04-17 19:23:03 +00:00
|
|
|
gst_video_convert_scale_set_property (GObject * object, guint prop_id,
|
2005-07-01 17:03:13 +00:00
|
|
|
const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
2020-04-17 19:23:03 +00:00
|
|
|
GstVideoConvertScalePrivate *priv = PRIV (object);
|
2003-12-22 01:47:09 +00:00
|
|
|
|
2020-04-17 19:23:03 +00:00
|
|
|
GST_OBJECT_LOCK (object);
|
2005-07-01 17:03:13 +00:00
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_METHOD:
|
2020-04-17 19:23:03 +00:00
|
|
|
priv->method = g_value_get_enum (value);
|
2005-07-01 17:03:13 +00:00
|
|
|
break;
|
2010-07-17 18:24:18 +00:00
|
|
|
case PROP_ADD_BORDERS:
|
2020-04-17 19:23:03 +00:00
|
|
|
priv->add_borders = g_value_get_boolean (value);
|
|
|
|
GST_OBJECT_UNLOCK (object);
|
|
|
|
|
|
|
|
gst_base_transform_reconfigure_src (GST_BASE_TRANSFORM_CAST (object));
|
|
|
|
return;
|
2011-03-18 02:13:58 +00:00
|
|
|
case PROP_SHARPNESS:
|
2020-04-17 19:23:03 +00:00
|
|
|
priv->sharpness = g_value_get_double (value);
|
2011-03-18 02:13:58 +00:00
|
|
|
break;
|
|
|
|
case PROP_SHARPEN:
|
2020-04-17 19:23:03 +00:00
|
|
|
priv->sharpen = g_value_get_double (value);
|
2011-03-18 02:13:58 +00:00
|
|
|
break;
|
|
|
|
case PROP_SUBMETHOD:
|
2020-04-17 19:23:03 +00:00
|
|
|
priv->submethod = g_value_get_int (value);
|
2011-03-18 02:13:58 +00:00
|
|
|
break;
|
|
|
|
case PROP_ENVELOPE:
|
2020-04-17 19:23:03 +00:00
|
|
|
priv->envelope = g_value_get_double (value);
|
2014-11-25 10:54:51 +00:00
|
|
|
break;
|
2017-02-20 19:38:17 +00:00
|
|
|
case PROP_N_THREADS:
|
2020-04-17 19:23:03 +00:00
|
|
|
priv->n_threads = g_value_get_uint (value);
|
|
|
|
break;
|
|
|
|
case PROP_DITHER:
|
|
|
|
priv->dither = g_value_get_enum (value);
|
|
|
|
break;
|
|
|
|
case PROP_CHROMA_RESAMPLER:
|
|
|
|
priv->chroma_resampler = g_value_get_enum (value);
|
|
|
|
break;
|
|
|
|
case PROP_ALPHA_MODE:
|
|
|
|
priv->alpha_mode = g_value_get_enum (value);
|
|
|
|
break;
|
|
|
|
case PROP_ALPHA_VALUE:
|
|
|
|
priv->alpha_value = g_value_get_double (value);
|
|
|
|
break;
|
|
|
|
case PROP_CHROMA_MODE:
|
|
|
|
priv->chroma_mode = g_value_get_enum (value);
|
|
|
|
break;
|
|
|
|
case PROP_MATRIX_MODE:
|
|
|
|
priv->matrix_mode = g_value_get_enum (value);
|
|
|
|
break;
|
|
|
|
case PROP_GAMMA_MODE:
|
|
|
|
priv->gamma_mode = g_value_get_enum (value);
|
|
|
|
break;
|
|
|
|
case PROP_PRIMARIES_MODE:
|
|
|
|
priv->primaries_mode = g_value_get_enum (value);
|
|
|
|
break;
|
|
|
|
case PROP_DITHER_QUANTIZATION:
|
|
|
|
priv->dither_quantization = g_value_get_uint (value);
|
2017-02-20 19:38:17 +00:00
|
|
|
break;
|
2022-03-23 13:38:00 +00:00
|
|
|
case PROP_CONVERTER_CONFIG:
|
|
|
|
if (priv->converter_config)
|
|
|
|
gst_structure_free (priv->converter_config);
|
|
|
|
priv->converter_config = g_value_dup_boxed (value);
|
|
|
|
priv->converter_config_changed = TRUE;
|
|
|
|
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
|
|
|
}
|
2020-04-17 19:23:03 +00:00
|
|
|
GST_OBJECT_UNLOCK (object);
|
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
|
2020-04-17 19:23:03 +00:00
|
|
|
gst_video_convert_scale_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec)
|
2005-07-01 16:55:43 +00:00
|
|
|
{
|
2020-04-17 19:23:03 +00:00
|
|
|
GstVideoConvertScalePrivate *priv = PRIV (object);
|
2005-07-01 16:55:43 +00:00
|
|
|
|
2020-04-17 19:23:03 +00:00
|
|
|
GST_OBJECT_LOCK (object);
|
2005-07-01 17:03:13 +00:00
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_METHOD:
|
2020-04-17 19:23:03 +00:00
|
|
|
g_value_set_enum (value, priv->method);
|
2005-07-01 17:03:13 +00:00
|
|
|
break;
|
2010-07-17 18:24:18 +00:00
|
|
|
case PROP_ADD_BORDERS:
|
2020-04-17 19:23:03 +00:00
|
|
|
g_value_set_boolean (value, priv->add_borders);
|
2010-07-17 18:24:18 +00:00
|
|
|
break;
|
2011-03-18 02:13:58 +00:00
|
|
|
case PROP_SHARPNESS:
|
2020-04-17 19:23:03 +00:00
|
|
|
g_value_set_double (value, priv->sharpness);
|
2011-03-18 02:13:58 +00:00
|
|
|
break;
|
|
|
|
case PROP_SHARPEN:
|
2020-04-17 19:23:03 +00:00
|
|
|
g_value_set_double (value, priv->sharpen);
|
2011-03-18 02:13:58 +00:00
|
|
|
break;
|
|
|
|
case PROP_SUBMETHOD:
|
2020-04-17 19:23:03 +00:00
|
|
|
g_value_set_int (value, priv->submethod);
|
2011-03-18 02:13:58 +00:00
|
|
|
break;
|
|
|
|
case PROP_ENVELOPE:
|
2020-04-17 19:23:03 +00:00
|
|
|
g_value_set_double (value, priv->envelope);
|
2014-11-25 10:54:51 +00:00
|
|
|
break;
|
2017-02-20 19:38:17 +00:00
|
|
|
case PROP_N_THREADS:
|
2020-04-17 19:23:03 +00:00
|
|
|
g_value_set_uint (value, priv->n_threads);
|
|
|
|
break;
|
|
|
|
case PROP_DITHER:
|
|
|
|
g_value_set_enum (value, priv->dither);
|
|
|
|
break;
|
|
|
|
case PROP_CHROMA_RESAMPLER:
|
|
|
|
g_value_set_enum (value, priv->chroma_resampler);
|
|
|
|
break;
|
|
|
|
case PROP_ALPHA_MODE:
|
|
|
|
g_value_set_enum (value, priv->alpha_mode);
|
|
|
|
break;
|
|
|
|
case PROP_ALPHA_VALUE:
|
|
|
|
g_value_set_double (value, priv->alpha_value);
|
|
|
|
break;
|
|
|
|
case PROP_CHROMA_MODE:
|
|
|
|
g_value_set_enum (value, priv->chroma_mode);
|
|
|
|
break;
|
|
|
|
case PROP_MATRIX_MODE:
|
|
|
|
g_value_set_enum (value, priv->matrix_mode);
|
|
|
|
break;
|
|
|
|
case PROP_GAMMA_MODE:
|
|
|
|
g_value_set_enum (value, priv->gamma_mode);
|
|
|
|
break;
|
|
|
|
case PROP_PRIMARIES_MODE:
|
|
|
|
g_value_set_enum (value, priv->primaries_mode);
|
|
|
|
break;
|
|
|
|
case PROP_DITHER_QUANTIZATION:
|
|
|
|
g_value_set_uint (value, priv->dither_quantization);
|
2017-02-20 19:38:17 +00:00
|
|
|
break;
|
2022-03-23 13:38:00 +00:00
|
|
|
case PROP_CONVERTER_CONFIG:
|
|
|
|
g_value_set_boxed (value, priv->converter_config);
|
|
|
|
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
|
|
|
}
|
2020-04-17 19:23:03 +00:00
|
|
|
GST_OBJECT_UNLOCK (object);
|
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 *
|
2022-08-05 11:52:19 +00:00
|
|
|
gst_video_convert_caps_remove_format_and_rangify_size_info (GstVideoConvertScale
|
|
|
|
* self, GstCaps * caps)
|
2001-12-22 23:27:17 +00:00
|
|
|
{
|
2022-08-05 11:52:19 +00:00
|
|
|
GstVideoConvertScaleClass *klass = GST_VIDEO_CONVERT_SCALE_GET_CLASS (self);
|
2014-10-24 15:08:43 +00:00
|
|
|
GstCaps *ret;
|
2006-04-28 14:33:45 +00:00
|
|
|
GstStructure *structure;
|
2013-04-08 06:29:34 +00:00
|
|
|
GstCapsFeatures *features;
|
2011-05-27 10:13:14 +00:00
|
|
|
gint i, n;
|
2007-12-22 12:06:47 +00:00
|
|
|
|
2011-05-27 12:30:19 +00:00
|
|
|
ret = gst_caps_new_empty ();
|
2020-04-17 19:23:03 +00:00
|
|
|
|
2011-05-27 10:13:14 +00:00
|
|
|
n = gst_caps_get_size (caps);
|
|
|
|
for (i = 0; i < n; i++) {
|
2011-05-27 12:30:19 +00:00
|
|
|
structure = gst_caps_get_structure (caps, i);
|
2013-04-08 06:29:34 +00:00
|
|
|
features = gst_caps_get_features (caps, i);
|
2011-05-27 12:30:19 +00:00
|
|
|
|
|
|
|
/* If this is already expressed by the existing caps
|
|
|
|
* skip this structure */
|
2013-04-08 06:29:34 +00:00
|
|
|
if (i > 0 && gst_caps_is_subset_structure_full (ret, structure, features))
|
2011-05-27 12:30:19 +00:00
|
|
|
continue;
|
2011-05-27 10:13:14 +00:00
|
|
|
|
2011-05-27 12:30:19 +00:00
|
|
|
structure = gst_structure_copy (structure);
|
2020-04-17 19:23:03 +00:00
|
|
|
/* Only remove format info for the cases when we can actually convert */
|
2013-04-08 06:29:34 +00:00
|
|
|
if (!gst_caps_features_is_any (features)
|
2021-02-04 16:22:15 +00:00
|
|
|
&& (gst_caps_features_is_equal (features,
|
|
|
|
GST_CAPS_FEATURES_MEMORY_SYSTEM_MEMORY)
|
|
|
|
|| gst_caps_features_is_equal (features, features_format_interlaced)
|
|
|
|
|| gst_caps_features_is_equal (features,
|
|
|
|
features_format_interlaced_sysmem))) {
|
2022-08-05 11:52:19 +00:00
|
|
|
if (klass->scales) {
|
2024-09-03 10:19:17 +00:00
|
|
|
gst_structure_set_static_str (structure, "width", GST_TYPE_INT_RANGE, 1,
|
|
|
|
G_MAXINT, "height", GST_TYPE_INT_RANGE, 1, G_MAXINT, NULL);
|
2022-08-05 11:52:19 +00:00
|
|
|
/* if pixel aspect ratio, make a range of it */
|
|
|
|
if (gst_structure_has_field (structure, "pixel-aspect-ratio")) {
|
2024-09-03 10:19:17 +00:00
|
|
|
gst_structure_set_static_str (structure, "pixel-aspect-ratio",
|
2022-08-05 11:52:19 +00:00
|
|
|
GST_TYPE_FRACTION_RANGE, 1, G_MAXINT, G_MAXINT, 1, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (klass->converts) {
|
|
|
|
gst_structure_remove_fields (structure, "format", "colorimetry",
|
|
|
|
"chroma-site", NULL);
|
2013-04-08 06:29:34 +00:00
|
|
|
}
|
2011-05-27 10:13:14 +00:00
|
|
|
}
|
2013-04-08 06:29:34 +00:00
|
|
|
gst_caps_append_structure_full (ret, structure,
|
|
|
|
gst_caps_features_copy (features));
|
2003-04-22 07:32:50 +00:00
|
|
|
}
|
|
|
|
|
2020-04-17 19:23:03 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstCaps *
|
|
|
|
gst_video_convert_scale_transform_caps (GstBaseTransform * trans,
|
|
|
|
GstPadDirection direction, GstCaps * caps, GstCaps * filter)
|
|
|
|
{
|
2022-08-05 11:52:19 +00:00
|
|
|
GstVideoConvertScale *self = GST_VIDEO_CONVERT_SCALE (trans);
|
2020-04-17 19:23:03 +00:00
|
|
|
GstCaps *ret;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (trans,
|
|
|
|
"Transforming caps %" GST_PTR_FORMAT " in direction %s", caps,
|
|
|
|
(direction == GST_PAD_SINK) ? "sink" : "src");
|
|
|
|
|
2022-08-05 11:52:19 +00:00
|
|
|
ret = gst_video_convert_caps_remove_format_and_rangify_size_info (self, caps);
|
2011-05-16 10:02:48 +00:00
|
|
|
if (filter) {
|
|
|
|
GstCaps *intersection;
|
|
|
|
|
|
|
|
intersection =
|
|
|
|
gst_caps_intersect_full (filter, ret, GST_CAPS_INTERSECT_FIRST);
|
|
|
|
gst_caps_unref (ret);
|
|
|
|
ret = intersection;
|
|
|
|
}
|
|
|
|
|
2005-07-01 17:03:13 +00:00
|
|
|
return ret;
|
2004-07-18 18:35:43 +00:00
|
|
|
}
|
|
|
|
|
2020-01-23 17:02:52 +00:00
|
|
|
static gboolean
|
2020-04-17 19:23:03 +00:00
|
|
|
gst_video_convert_scale_transform_meta (GstBaseTransform * trans,
|
|
|
|
GstBuffer * outbuf, GstMeta * meta, GstBuffer * inbuf)
|
2020-01-23 17:02:52 +00:00
|
|
|
{
|
|
|
|
GstVideoFilter *videofilter = GST_VIDEO_FILTER (trans);
|
|
|
|
const GstMetaInfo *info = meta->info;
|
|
|
|
const gchar *const *tags;
|
|
|
|
const gchar *const *curr = NULL;
|
|
|
|
gboolean should_copy = TRUE;
|
2020-04-17 19:23:03 +00:00
|
|
|
const gchar *const valid_tags[] = {
|
|
|
|
GST_META_TAG_VIDEO_STR,
|
2020-01-23 17:02:52 +00:00
|
|
|
GST_META_TAG_VIDEO_ORIENTATION_STR,
|
2020-04-17 19:23:03 +00:00
|
|
|
GST_META_TAG_VIDEO_SIZE_STR,
|
2022-12-19 14:22:15 +00:00
|
|
|
NULL
|
2020-01-23 17:02:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
tags = gst_meta_api_type_get_tags (info->api);
|
|
|
|
|
|
|
|
/* No specific tags, we are good to copy */
|
|
|
|
if (!tags) {
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2020-04-17 19:23:03 +00:00
|
|
|
if (gst_meta_api_type_has_tag (info->api, _colorspace_quark)) {
|
|
|
|
/* don't copy colorspace specific metadata, FIXME, we need a MetaTransform
|
|
|
|
* for the colorspace metadata. */
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2020-01-23 17:02:52 +00:00
|
|
|
/* We are only changing size, we can preserve other metas tagged as
|
|
|
|
orientation and colorspace */
|
|
|
|
for (curr = tags; *curr; ++curr) {
|
|
|
|
|
|
|
|
/* We dont handle any other tag */
|
|
|
|
if (!g_strv_contains (valid_tags, *curr)) {
|
|
|
|
should_copy = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Cant handle the tags in this meta, let the parent class handle it */
|
|
|
|
if (!should_copy) {
|
|
|
|
return GST_BASE_TRANSFORM_CLASS (parent_class)->transform_meta (trans,
|
2020-10-08 11:52:33 +00:00
|
|
|
outbuf, meta, inbuf);
|
2020-01-23 17:02:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* This meta is size sensitive, try to transform it accordingly */
|
|
|
|
if (gst_meta_api_type_has_tag (info->api, _size_quark)) {
|
|
|
|
GstVideoMetaTransform trans =
|
|
|
|
{ &videofilter->in_info, &videofilter->out_info };
|
|
|
|
|
2020-08-18 07:26:48 +00:00
|
|
|
if (info->transform_func)
|
2022-02-02 15:28:21 +00:00
|
|
|
info->transform_func (outbuf, meta, inbuf, _scale_quark, &trans);
|
2020-08-18 07:26:48 +00:00
|
|
|
return FALSE;
|
2020-01-23 17:02:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* No need to transform, we can safely copy this meta */
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2022-03-23 13:38:00 +00:00
|
|
|
static GstStructure *
|
|
|
|
gst_video_convert_scale_get_converter_config (GstVideoConvertScale * self,
|
|
|
|
GstVideoInfo * out_info)
|
|
|
|
{
|
|
|
|
GstVideoConvertScalePrivate *priv = PRIV (self);
|
|
|
|
return gst_structure_copy (priv->converter_config);
|
|
|
|
}
|
|
|
|
|
2005-08-24 15:07:54 +00:00
|
|
|
static gboolean
|
2020-04-17 19:23:03 +00:00
|
|
|
gst_video_convert_scale_set_info (GstVideoFilter * filter, GstCaps * in,
|
2011-12-21 22:46:53 +00:00
|
|
|
GstVideoInfo * in_info, GstCaps * out, GstVideoInfo * out_info)
|
2005-08-24 15:07:54 +00:00
|
|
|
{
|
2020-04-17 19:23:03 +00:00
|
|
|
GstVideoConvertScale *self = GST_VIDEO_CONVERT_SCALE (filter);
|
|
|
|
GstVideoConvertScalePrivate *priv = PRIV (self);
|
2010-05-10 13:13:20 +00:00
|
|
|
gint from_dar_n, from_dar_d, to_dar_n, to_dar_d;
|
2020-04-17 19:23:03 +00:00
|
|
|
GstVideoInfo tmp_info;
|
2022-03-23 13:38:00 +00:00
|
|
|
GstStructure *options;
|
2020-04-17 19:23:03 +00:00
|
|
|
|
|
|
|
if (priv->convert) {
|
|
|
|
gst_video_converter_free (priv->convert);
|
|
|
|
priv->convert = NULL;
|
|
|
|
}
|
2005-08-24 15:07:54 +00:00
|
|
|
|
2011-12-21 22:46:53 +00:00
|
|
|
if (!gst_util_fraction_multiply (in_info->width,
|
2013-03-20 18:34:06 +00:00
|
|
|
in_info->height, in_info->par_n, in_info->par_d, &from_dar_n,
|
2010-05-10 13:13:20 +00:00
|
|
|
&from_dar_d)) {
|
|
|
|
from_dar_n = from_dar_d = -1;
|
|
|
|
}
|
|
|
|
|
2011-12-21 22:46:53 +00:00
|
|
|
if (!gst_util_fraction_multiply (out_info->width,
|
|
|
|
out_info->height, out_info->par_n, out_info->par_d, &to_dar_n,
|
2011-06-17 13:31:59 +00:00
|
|
|
&to_dar_d)) {
|
2010-05-10 13:13:20 +00:00
|
|
|
to_dar_n = to_dar_d = -1;
|
|
|
|
}
|
|
|
|
|
2020-04-17 19:23:03 +00:00
|
|
|
priv->borders_w = priv->borders_h = 0;
|
2010-07-17 18:24:18 +00:00
|
|
|
if (to_dar_n != from_dar_n || to_dar_d != from_dar_d) {
|
2020-04-17 19:23:03 +00:00
|
|
|
if (priv->add_borders) {
|
2010-07-17 18:24:18 +00:00
|
|
|
gint n, d, to_h, to_w;
|
|
|
|
|
|
|
|
if (from_dar_n != -1 && from_dar_d != -1
|
2011-12-21 22:46:53 +00:00
|
|
|
&& gst_util_fraction_multiply (from_dar_n, from_dar_d,
|
2013-03-20 18:34:06 +00:00
|
|
|
out_info->par_d, out_info->par_n, &n, &d)) {
|
2011-12-21 22:46:53 +00:00
|
|
|
to_h = gst_util_uint64_scale_int (out_info->width, d, n);
|
|
|
|
if (to_h <= out_info->height) {
|
2020-04-17 19:23:03 +00:00
|
|
|
priv->borders_h = out_info->height - to_h;
|
|
|
|
priv->borders_w = 0;
|
2010-07-17 18:24:18 +00:00
|
|
|
} else {
|
2011-12-21 22:46:53 +00:00
|
|
|
to_w = gst_util_uint64_scale_int (out_info->height, n, d);
|
|
|
|
g_assert (to_w <= out_info->width);
|
2020-04-17 19:23:03 +00:00
|
|
|
priv->borders_h = 0;
|
|
|
|
priv->borders_w = out_info->width - to_w;
|
2010-07-17 18:24:18 +00:00
|
|
|
}
|
|
|
|
} else {
|
2020-04-17 19:23:03 +00:00
|
|
|
GST_WARNING_OBJECT (self, "Can't calculate borders");
|
2010-07-17 18:24:18 +00:00
|
|
|
}
|
|
|
|
} else {
|
2023-11-29 13:44:37 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "Can't keep DAR!");
|
2010-07-17 18:24:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-17 19:23:03 +00:00
|
|
|
/* if present, these must match */
|
|
|
|
if (in_info->interlace_mode != out_info->interlace_mode)
|
|
|
|
goto format_mismatch;
|
|
|
|
|
2022-03-23 13:38:00 +00:00
|
|
|
if (priv->converter_config) {
|
|
|
|
options = gst_video_convert_scale_get_converter_config (self, out_info);
|
|
|
|
GST_DEBUG_OBJECT (self,
|
|
|
|
"Using user-provided converter-config: %" GST_PTR_FORMAT, options);
|
|
|
|
goto build_converter;
|
|
|
|
}
|
|
|
|
|
2020-04-17 19:23:03 +00:00
|
|
|
/* if the only thing different in the caps is the transfer function, and
|
2023-08-14 13:53:01 +00:00
|
|
|
* we're converting between equivalent transfer functions and not
|
|
|
|
* quantizing/dithering or adjusting alpha, then do passthrough */
|
2020-04-17 19:23:03 +00:00
|
|
|
tmp_info = *in_info;
|
|
|
|
tmp_info.colorimetry.transfer = out_info->colorimetry.transfer;
|
2023-08-14 13:53:01 +00:00
|
|
|
|
|
|
|
gboolean need_dither = (priv->dither_quantization > 1)
|
|
|
|
&& (priv->dither != GST_VIDEO_DITHER_NONE);
|
|
|
|
gboolean need_alpha = GST_VIDEO_INFO_HAS_ALPHA (out_info)
|
|
|
|
&& ((priv->alpha_mode == GST_VIDEO_ALPHA_MODE_SET) ||
|
|
|
|
(priv->alpha_mode == GST_VIDEO_ALPHA_MODE_MULT
|
|
|
|
&& priv->alpha_value != 1.0));
|
|
|
|
|
2022-08-23 14:02:31 +00:00
|
|
|
if (gst_video_info_is_equal (&tmp_info, out_info) &&
|
|
|
|
gst_video_transfer_function_is_equivalent (in_info->colorimetry.transfer,
|
|
|
|
in_info->finfo->bits, out_info->colorimetry.transfer,
|
2023-08-14 13:53:01 +00:00
|
|
|
out_info->finfo->bits) && !need_dither && !need_alpha) {
|
2022-08-23 14:02:31 +00:00
|
|
|
gst_base_transform_set_passthrough (GST_BASE_TRANSFORM (filter), TRUE);
|
2012-02-09 14:28:54 +00:00
|
|
|
} else {
|
2016-02-20 11:31:43 +00:00
|
|
|
GST_CAT_DEBUG_OBJECT (CAT_PERFORMANCE, filter, "setup videoscaling");
|
2012-02-09 14:28:54 +00:00
|
|
|
gst_base_transform_set_passthrough (GST_BASE_TRANSFORM (filter), FALSE);
|
2014-10-24 15:08:43 +00:00
|
|
|
|
2024-09-03 10:19:17 +00:00
|
|
|
options = gst_structure_new_static_str_empty ("videoconvertscale");
|
2014-10-24 15:08:43 +00:00
|
|
|
|
2020-04-17 19:23:03 +00:00
|
|
|
switch (priv->method) {
|
2014-10-24 15:08:43 +00:00
|
|
|
case GST_VIDEO_SCALE_NEAREST:
|
2024-09-03 10:19:17 +00:00
|
|
|
gst_structure_set_static_str (options,
|
2014-10-24 15:08:43 +00:00
|
|
|
GST_VIDEO_CONVERTER_OPT_RESAMPLER_METHOD,
|
|
|
|
GST_TYPE_VIDEO_RESAMPLER_METHOD, GST_VIDEO_RESAMPLER_METHOD_NEAREST,
|
|
|
|
NULL);
|
|
|
|
break;
|
|
|
|
case GST_VIDEO_SCALE_BILINEAR:
|
2024-09-03 10:19:17 +00:00
|
|
|
gst_structure_set_static_str (options,
|
2014-10-24 15:08:43 +00:00
|
|
|
GST_VIDEO_CONVERTER_OPT_RESAMPLER_METHOD,
|
|
|
|
GST_TYPE_VIDEO_RESAMPLER_METHOD, GST_VIDEO_RESAMPLER_METHOD_LINEAR,
|
2014-11-25 10:28:42 +00:00
|
|
|
GST_VIDEO_RESAMPLER_OPT_MAX_TAPS, G_TYPE_INT, 2, NULL);
|
2014-10-24 15:08:43 +00:00
|
|
|
break;
|
|
|
|
case GST_VIDEO_SCALE_4TAP:
|
2024-09-03 10:19:17 +00:00
|
|
|
gst_structure_set_static_str (options,
|
2014-10-24 15:08:43 +00:00
|
|
|
GST_VIDEO_CONVERTER_OPT_RESAMPLER_METHOD,
|
2014-11-25 10:28:42 +00:00
|
|
|
GST_TYPE_VIDEO_RESAMPLER_METHOD, GST_VIDEO_RESAMPLER_METHOD_SINC,
|
|
|
|
GST_VIDEO_RESAMPLER_OPT_MAX_TAPS, G_TYPE_INT, 4, NULL);
|
2014-10-24 15:08:43 +00:00
|
|
|
break;
|
|
|
|
case GST_VIDEO_SCALE_LANCZOS:
|
2024-09-03 10:19:17 +00:00
|
|
|
gst_structure_set_static_str (options,
|
2014-10-24 15:08:43 +00:00
|
|
|
GST_VIDEO_CONVERTER_OPT_RESAMPLER_METHOD,
|
|
|
|
GST_TYPE_VIDEO_RESAMPLER_METHOD, GST_VIDEO_RESAMPLER_METHOD_LANCZOS,
|
2014-11-25 10:28:42 +00:00
|
|
|
NULL);
|
|
|
|
break;
|
|
|
|
case GST_VIDEO_SCALE_BILINEAR2:
|
2024-09-03 10:19:17 +00:00
|
|
|
gst_structure_set_static_str (options,
|
2014-11-25 10:28:42 +00:00
|
|
|
GST_VIDEO_CONVERTER_OPT_RESAMPLER_METHOD,
|
|
|
|
GST_TYPE_VIDEO_RESAMPLER_METHOD, GST_VIDEO_RESAMPLER_METHOD_LINEAR,
|
|
|
|
NULL);
|
|
|
|
break;
|
|
|
|
case GST_VIDEO_SCALE_SINC:
|
2024-09-03 10:19:17 +00:00
|
|
|
gst_structure_set_static_str (options,
|
2014-11-25 10:28:42 +00:00
|
|
|
GST_VIDEO_CONVERTER_OPT_RESAMPLER_METHOD,
|
|
|
|
GST_TYPE_VIDEO_RESAMPLER_METHOD, GST_VIDEO_RESAMPLER_METHOD_SINC,
|
|
|
|
NULL);
|
|
|
|
break;
|
|
|
|
case GST_VIDEO_SCALE_HERMITE:
|
2024-09-03 10:19:17 +00:00
|
|
|
gst_structure_set_static_str (options,
|
2014-11-25 10:28:42 +00:00
|
|
|
GST_VIDEO_CONVERTER_OPT_RESAMPLER_METHOD,
|
|
|
|
GST_TYPE_VIDEO_RESAMPLER_METHOD, GST_VIDEO_RESAMPLER_METHOD_CUBIC,
|
|
|
|
GST_VIDEO_RESAMPLER_OPT_CUBIC_B, G_TYPE_DOUBLE, (gdouble) 0.0,
|
|
|
|
GST_VIDEO_RESAMPLER_OPT_CUBIC_C, G_TYPE_DOUBLE, (gdouble) 0.0,
|
|
|
|
NULL);
|
|
|
|
break;
|
|
|
|
case GST_VIDEO_SCALE_SPLINE:
|
2024-09-03 10:19:17 +00:00
|
|
|
gst_structure_set_static_str (options,
|
2014-11-25 10:28:42 +00:00
|
|
|
GST_VIDEO_CONVERTER_OPT_RESAMPLER_METHOD,
|
|
|
|
GST_TYPE_VIDEO_RESAMPLER_METHOD, GST_VIDEO_RESAMPLER_METHOD_CUBIC,
|
|
|
|
GST_VIDEO_RESAMPLER_OPT_CUBIC_B, G_TYPE_DOUBLE, (gdouble) 1.0,
|
|
|
|
GST_VIDEO_RESAMPLER_OPT_CUBIC_C, G_TYPE_DOUBLE, (gdouble) 0.0,
|
|
|
|
NULL);
|
|
|
|
break;
|
|
|
|
case GST_VIDEO_SCALE_CATROM:
|
2024-09-03 10:19:17 +00:00
|
|
|
gst_structure_set_static_str (options,
|
2014-11-25 10:28:42 +00:00
|
|
|
GST_VIDEO_CONVERTER_OPT_RESAMPLER_METHOD,
|
|
|
|
GST_TYPE_VIDEO_RESAMPLER_METHOD, GST_VIDEO_RESAMPLER_METHOD_CUBIC,
|
|
|
|
GST_VIDEO_RESAMPLER_OPT_CUBIC_B, G_TYPE_DOUBLE, (gdouble) 0.0,
|
|
|
|
GST_VIDEO_RESAMPLER_OPT_CUBIC_C, G_TYPE_DOUBLE, (gdouble) 0.5,
|
|
|
|
NULL);
|
|
|
|
break;
|
|
|
|
case GST_VIDEO_SCALE_MITCHELL:
|
2024-09-03 10:19:17 +00:00
|
|
|
gst_structure_set_static_str (options,
|
2014-11-25 10:28:42 +00:00
|
|
|
GST_VIDEO_CONVERTER_OPT_RESAMPLER_METHOD,
|
|
|
|
GST_TYPE_VIDEO_RESAMPLER_METHOD, GST_VIDEO_RESAMPLER_METHOD_CUBIC,
|
|
|
|
GST_VIDEO_RESAMPLER_OPT_CUBIC_B, G_TYPE_DOUBLE, (gdouble) 1.0 / 3.0,
|
|
|
|
GST_VIDEO_RESAMPLER_OPT_CUBIC_C, G_TYPE_DOUBLE, (gdouble) 1.0 / 3.0,
|
2014-10-24 15:08:43 +00:00
|
|
|
NULL);
|
|
|
|
break;
|
|
|
|
}
|
2024-09-03 10:19:17 +00:00
|
|
|
gst_structure_set_static_str (options,
|
2020-04-17 19:23:03 +00:00
|
|
|
GST_VIDEO_RESAMPLER_OPT_ENVELOPE, G_TYPE_DOUBLE, priv->envelope,
|
|
|
|
GST_VIDEO_RESAMPLER_OPT_SHARPNESS, G_TYPE_DOUBLE, priv->sharpness,
|
|
|
|
GST_VIDEO_RESAMPLER_OPT_SHARPEN, G_TYPE_DOUBLE, priv->sharpen,
|
|
|
|
GST_VIDEO_CONVERTER_OPT_DEST_X, G_TYPE_INT, priv->borders_w / 2,
|
|
|
|
GST_VIDEO_CONVERTER_OPT_DEST_Y, G_TYPE_INT, priv->borders_h / 2,
|
2014-10-24 15:08:43 +00:00
|
|
|
GST_VIDEO_CONVERTER_OPT_DEST_WIDTH, G_TYPE_INT,
|
2020-04-17 19:23:03 +00:00
|
|
|
out_info->width - priv->borders_w, GST_VIDEO_CONVERTER_OPT_DEST_HEIGHT,
|
|
|
|
G_TYPE_INT, out_info->height - priv->borders_h,
|
|
|
|
GST_VIDEO_CONVERTER_OPT_DITHER_METHOD, GST_TYPE_VIDEO_DITHER_METHOD,
|
|
|
|
priv->dither, GST_VIDEO_CONVERTER_OPT_DITHER_QUANTIZATION, G_TYPE_UINT,
|
|
|
|
priv->dither_quantization,
|
|
|
|
GST_VIDEO_CONVERTER_OPT_CHROMA_RESAMPLER_METHOD,
|
|
|
|
GST_TYPE_VIDEO_RESAMPLER_METHOD, priv->chroma_resampler,
|
|
|
|
GST_VIDEO_CONVERTER_OPT_ALPHA_MODE, GST_TYPE_VIDEO_ALPHA_MODE,
|
|
|
|
priv->alpha_mode, GST_VIDEO_CONVERTER_OPT_ALPHA_VALUE, G_TYPE_DOUBLE,
|
|
|
|
priv->alpha_value, GST_VIDEO_CONVERTER_OPT_CHROMA_MODE,
|
|
|
|
GST_TYPE_VIDEO_CHROMA_MODE, priv->chroma_mode,
|
2015-05-08 11:57:03 +00:00
|
|
|
GST_VIDEO_CONVERTER_OPT_MATRIX_MODE, GST_TYPE_VIDEO_MATRIX_MODE,
|
2020-04-17 19:23:03 +00:00
|
|
|
priv->matrix_mode, GST_VIDEO_CONVERTER_OPT_GAMMA_MODE,
|
|
|
|
GST_TYPE_VIDEO_GAMMA_MODE, priv->gamma_mode,
|
|
|
|
GST_VIDEO_CONVERTER_OPT_PRIMARIES_MODE, GST_TYPE_VIDEO_PRIMARIES_MODE,
|
|
|
|
priv->primaries_mode, GST_VIDEO_CONVERTER_OPT_THREADS, G_TYPE_UINT,
|
|
|
|
priv->n_threads, NULL);
|
|
|
|
|
2022-03-23 13:38:00 +00:00
|
|
|
build_converter:
|
2020-04-17 19:23:03 +00:00
|
|
|
priv->convert = gst_video_converter_new (in_info, out_info, options);
|
|
|
|
if (priv->convert == NULL)
|
|
|
|
goto no_convert;
|
2012-02-09 14:28:54 +00:00
|
|
|
}
|
2010-05-13 10:16:38 +00:00
|
|
|
|
2020-04-17 19:23:03 +00:00
|
|
|
GST_DEBUG_OBJECT (filter, "converting format %s -> %s",
|
|
|
|
gst_video_format_to_string (GST_VIDEO_INFO_FORMAT (in_info)),
|
|
|
|
gst_video_format_to_string (GST_VIDEO_INFO_FORMAT (out_info)));
|
|
|
|
GST_DEBUG_OBJECT (self, "from=%dx%d (par=%d/%d dar=%d/%d), size %"
|
2011-08-09 14:39:31 +00:00
|
|
|
G_GSIZE_FORMAT " -> to=%dx%d (par=%d/%d dar=%d/%d borders=%d:%d), "
|
|
|
|
"size %" G_GSIZE_FORMAT,
|
2013-03-20 18:34:06 +00:00
|
|
|
in_info->width, in_info->height, in_info->par_n, in_info->par_d,
|
2011-12-21 22:46:53 +00:00
|
|
|
from_dar_n, from_dar_d, in_info->size, out_info->width,
|
|
|
|
out_info->height, out_info->par_n, out_info->par_d, to_dar_n, to_dar_d,
|
2020-04-17 19:23:03 +00:00
|
|
|
priv->borders_w, priv->borders_h, out_info->size);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
format_mismatch:
|
|
|
|
{
|
|
|
|
GST_ERROR_OBJECT (self, "input and output formats do not match");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
no_convert:
|
|
|
|
{
|
|
|
|
GST_ERROR_OBJECT (self, "could not create converter");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is an incomplete matrix of in formats and a score for the preferred output
|
|
|
|
* format.
|
|
|
|
*
|
|
|
|
* out: RGB24 RGB16 ARGB AYUV YUV444 YUV422 YUV420 YUV411 YUV410 PAL GRAY
|
|
|
|
* in
|
|
|
|
* RGB24 0 2 1 2 2 3 4 5 6 7 8
|
|
|
|
* RGB16 1 0 1 2 2 3 4 5 6 7 8
|
|
|
|
* ARGB 2 3 0 1 4 5 6 7 8 9 10
|
|
|
|
* AYUV 3 4 1 0 2 5 6 7 8 9 10
|
|
|
|
* YUV444 2 4 3 1 0 5 6 7 8 9 10
|
|
|
|
* YUV422 3 5 4 2 1 0 6 7 8 9 10
|
|
|
|
* YUV420 4 6 5 3 2 1 0 7 8 9 10
|
|
|
|
* YUV411 4 6 5 3 2 1 7 0 8 9 10
|
|
|
|
* YUV410 6 8 7 5 4 3 2 1 0 9 10
|
|
|
|
* PAL 1 3 2 6 4 6 7 8 9 0 10
|
|
|
|
* GRAY 1 4 3 2 1 5 6 7 8 9 0
|
|
|
|
*
|
|
|
|
* PAL or GRAY are never preferred, if we can we would convert to PAL instead
|
|
|
|
* of GRAY, though
|
|
|
|
* less subsampling is preferred and if any, preferably horizontal
|
|
|
|
* We would like to keep the alpha, even if we would need to to colorspace conversion
|
|
|
|
* or lose depth.
|
|
|
|
*/
|
|
|
|
#define SCORE_FORMAT_CHANGE 1
|
|
|
|
#define SCORE_DEPTH_CHANGE 1
|
|
|
|
#define SCORE_ALPHA_CHANGE 1
|
|
|
|
#define SCORE_CHROMA_W_CHANGE 1
|
|
|
|
#define SCORE_CHROMA_H_CHANGE 1
|
|
|
|
#define SCORE_PALETTE_CHANGE 1
|
|
|
|
|
|
|
|
#define SCORE_COLORSPACE_LOSS 2 /* RGB <-> YUV */
|
|
|
|
#define SCORE_DEPTH_LOSS 4 /* change bit depth */
|
|
|
|
#define SCORE_ALPHA_LOSS 8 /* lose the alpha channel */
|
|
|
|
#define SCORE_CHROMA_W_LOSS 16 /* vertical subsample */
|
|
|
|
#define SCORE_CHROMA_H_LOSS 32 /* horizontal subsample */
|
|
|
|
#define SCORE_PALETTE_LOSS 64 /* convert to palette format */
|
|
|
|
#define SCORE_COLOR_LOSS 128 /* convert to GRAY */
|
|
|
|
|
|
|
|
#define COLORSPACE_MASK (GST_VIDEO_FORMAT_FLAG_YUV | \
|
|
|
|
GST_VIDEO_FORMAT_FLAG_RGB | GST_VIDEO_FORMAT_FLAG_GRAY)
|
|
|
|
#define ALPHA_MASK (GST_VIDEO_FORMAT_FLAG_ALPHA)
|
|
|
|
#define PALETTE_MASK (GST_VIDEO_FORMAT_FLAG_PALETTE)
|
|
|
|
|
|
|
|
/* calculate how much loss a conversion would be */
|
|
|
|
static void
|
|
|
|
score_value (GstBaseTransform * base, const GstVideoFormatInfo * in_info,
|
|
|
|
const GValue * val, gint * min_loss, const GstVideoFormatInfo ** out_info)
|
|
|
|
{
|
|
|
|
const gchar *fname;
|
|
|
|
const GstVideoFormatInfo *t_info;
|
|
|
|
GstVideoFormatFlags in_flags, t_flags;
|
|
|
|
gint loss;
|
|
|
|
|
|
|
|
fname = g_value_get_string (val);
|
|
|
|
t_info = gst_video_format_get_info (gst_video_format_from_string (fname));
|
|
|
|
if (!t_info || t_info->format == GST_VIDEO_FORMAT_UNKNOWN)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* accept input format immediately without loss */
|
|
|
|
if (in_info == t_info) {
|
|
|
|
*min_loss = 0;
|
|
|
|
*out_info = t_info;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
loss = SCORE_FORMAT_CHANGE;
|
|
|
|
|
|
|
|
in_flags = GST_VIDEO_FORMAT_INFO_FLAGS (in_info);
|
|
|
|
in_flags &= ~GST_VIDEO_FORMAT_FLAG_LE;
|
|
|
|
in_flags &= ~GST_VIDEO_FORMAT_FLAG_COMPLEX;
|
|
|
|
in_flags &= ~GST_VIDEO_FORMAT_FLAG_UNPACK;
|
|
|
|
|
|
|
|
t_flags = GST_VIDEO_FORMAT_INFO_FLAGS (t_info);
|
|
|
|
t_flags &= ~GST_VIDEO_FORMAT_FLAG_LE;
|
|
|
|
t_flags &= ~GST_VIDEO_FORMAT_FLAG_COMPLEX;
|
|
|
|
t_flags &= ~GST_VIDEO_FORMAT_FLAG_UNPACK;
|
|
|
|
|
|
|
|
if ((t_flags & PALETTE_MASK) != (in_flags & PALETTE_MASK)) {
|
|
|
|
loss += SCORE_PALETTE_CHANGE;
|
|
|
|
if (t_flags & PALETTE_MASK)
|
|
|
|
loss += SCORE_PALETTE_LOSS;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((t_flags & COLORSPACE_MASK) != (in_flags & COLORSPACE_MASK)) {
|
|
|
|
loss += SCORE_COLORSPACE_LOSS;
|
|
|
|
if (t_flags & GST_VIDEO_FORMAT_FLAG_GRAY)
|
|
|
|
loss += SCORE_COLOR_LOSS;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((t_flags & ALPHA_MASK) != (in_flags & ALPHA_MASK)) {
|
|
|
|
loss += SCORE_ALPHA_CHANGE;
|
|
|
|
if (in_flags & ALPHA_MASK)
|
|
|
|
loss += SCORE_ALPHA_LOSS;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((in_info->h_sub[1]) != (t_info->h_sub[1])) {
|
|
|
|
loss += SCORE_CHROMA_H_CHANGE;
|
|
|
|
if ((in_info->h_sub[1]) < (t_info->h_sub[1]))
|
|
|
|
loss += SCORE_CHROMA_H_LOSS;
|
|
|
|
}
|
|
|
|
if ((in_info->w_sub[1]) != (t_info->w_sub[1])) {
|
|
|
|
loss += SCORE_CHROMA_W_CHANGE;
|
|
|
|
if ((in_info->w_sub[1]) < (t_info->w_sub[1]))
|
|
|
|
loss += SCORE_CHROMA_W_LOSS;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((in_info->bits) != (t_info->bits)) {
|
|
|
|
loss += SCORE_DEPTH_CHANGE;
|
|
|
|
if ((in_info->bits) > (t_info->bits))
|
|
|
|
loss += SCORE_DEPTH_LOSS;
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (base, "score %s -> %s = %d",
|
|
|
|
GST_VIDEO_FORMAT_INFO_NAME (in_info),
|
|
|
|
GST_VIDEO_FORMAT_INFO_NAME (t_info), loss);
|
|
|
|
|
|
|
|
if (loss < *min_loss) {
|
|
|
|
GST_DEBUG_OBJECT (base, "found new best %d", loss);
|
|
|
|
*out_info = t_info;
|
|
|
|
*min_loss = loss;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_video_convert_scale_fixate_format (GstBaseTransform * base, GstCaps * caps,
|
|
|
|
GstCaps * result)
|
|
|
|
{
|
|
|
|
GstStructure *ins, *outs;
|
|
|
|
const gchar *in_format;
|
|
|
|
const GstVideoFormatInfo *in_info, *out_info = NULL;
|
|
|
|
gint min_loss = G_MAXINT;
|
|
|
|
guint i, capslen;
|
|
|
|
|
|
|
|
ins = gst_caps_get_structure (caps, 0);
|
|
|
|
in_format = gst_structure_get_string (ins, "format");
|
|
|
|
if (!in_format)
|
|
|
|
return;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (base, "source format %s", in_format);
|
|
|
|
|
|
|
|
in_info =
|
|
|
|
gst_video_format_get_info (gst_video_format_from_string (in_format));
|
|
|
|
if (!in_info)
|
|
|
|
return;
|
|
|
|
|
|
|
|
outs = gst_caps_get_structure (result, 0);
|
|
|
|
|
|
|
|
capslen = gst_caps_get_size (result);
|
|
|
|
GST_DEBUG_OBJECT (base, "iterate %d structures", capslen);
|
|
|
|
for (i = 0; i < capslen; i++) {
|
|
|
|
GstStructure *tests;
|
|
|
|
const GValue *format;
|
|
|
|
|
|
|
|
tests = gst_caps_get_structure (result, i);
|
|
|
|
format = gst_structure_get_value (tests, "format");
|
|
|
|
gst_structure_remove_fields (tests, "height", "width", "pixel-aspect-ratio",
|
|
|
|
"display-aspect-ratio", NULL);
|
|
|
|
/* should not happen */
|
|
|
|
if (format == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (GST_VALUE_HOLDS_LIST (format)) {
|
|
|
|
gint j, len;
|
|
|
|
|
|
|
|
len = gst_value_list_get_size (format);
|
|
|
|
GST_DEBUG_OBJECT (base, "have %d formats", len);
|
|
|
|
for (j = 0; j < len; j++) {
|
|
|
|
const GValue *val;
|
|
|
|
|
|
|
|
val = gst_value_list_get_value (format, j);
|
|
|
|
if (G_VALUE_HOLDS_STRING (val)) {
|
|
|
|
score_value (base, in_info, val, &min_loss, &out_info);
|
|
|
|
if (min_loss == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (G_VALUE_HOLDS_STRING (format)) {
|
|
|
|
score_value (base, in_info, format, &min_loss, &out_info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (out_info)
|
2024-09-03 10:19:17 +00:00
|
|
|
gst_structure_set_static_str (outs, "format", G_TYPE_STRING,
|
2020-04-17 19:23:03 +00:00
|
|
|
GST_VIDEO_FORMAT_INFO_NAME (out_info), NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
subsampling_unchanged (GstVideoInfo * in_info, GstVideoInfo * out_info)
|
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
const GstVideoFormatInfo *in_format, *out_format;
|
|
|
|
|
|
|
|
if (GST_VIDEO_INFO_N_COMPONENTS (in_info) !=
|
|
|
|
GST_VIDEO_INFO_N_COMPONENTS (out_info))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
in_format = in_info->finfo;
|
|
|
|
out_format = out_info->finfo;
|
|
|
|
|
|
|
|
for (i = 0; i < GST_VIDEO_INFO_N_COMPONENTS (in_info); i++) {
|
|
|
|
if (GST_VIDEO_FORMAT_INFO_W_SUB (in_format,
|
|
|
|
i) != GST_VIDEO_FORMAT_INFO_W_SUB (out_format, i))
|
|
|
|
return FALSE;
|
|
|
|
if (GST_VIDEO_FORMAT_INFO_H_SUB (in_format,
|
|
|
|
i) != GST_VIDEO_FORMAT_INFO_H_SUB (out_format, i))
|
|
|
|
return FALSE;
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2020-04-17 19:23:03 +00:00
|
|
|
static void
|
|
|
|
transfer_colorimetry_from_input (GstBaseTransform * trans, GstCaps * in_caps,
|
|
|
|
GstCaps * out_caps)
|
|
|
|
{
|
|
|
|
GstStructure *out_caps_s = gst_caps_get_structure (out_caps, 0);
|
|
|
|
GstStructure *in_caps_s = gst_caps_get_structure (in_caps, 0);
|
|
|
|
gboolean have_colorimetry =
|
|
|
|
gst_structure_has_field (out_caps_s, "colorimetry");
|
|
|
|
gboolean have_chroma_site =
|
|
|
|
gst_structure_has_field (out_caps_s, "chroma-site");
|
|
|
|
|
|
|
|
/* If the output already has colorimetry and chroma-site, stop,
|
|
|
|
* otherwise try and transfer what we can from the input caps */
|
|
|
|
if (have_colorimetry && have_chroma_site)
|
|
|
|
return;
|
|
|
|
|
|
|
|
{
|
|
|
|
GstVideoInfo in_info, out_info;
|
|
|
|
const GValue *in_colorimetry =
|
|
|
|
gst_structure_get_value (in_caps_s, "colorimetry");
|
2022-04-24 15:19:00 +00:00
|
|
|
GstCaps *tmp_caps = NULL;
|
|
|
|
GstStructure *tmp_caps_s;
|
2020-04-17 19:23:03 +00:00
|
|
|
|
|
|
|
if (!gst_video_info_from_caps (&in_info, in_caps)) {
|
|
|
|
GST_WARNING_OBJECT (trans,
|
|
|
|
"Failed to convert sink pad caps to video info");
|
|
|
|
return;
|
|
|
|
}
|
2022-04-24 15:19:00 +00:00
|
|
|
|
|
|
|
/* We are before fixate_size(), the width and height of
|
|
|
|
the output caps may be absent or not fixed. */
|
|
|
|
tmp_caps = gst_caps_copy (out_caps);
|
|
|
|
tmp_caps = gst_caps_fixate (tmp_caps);
|
|
|
|
tmp_caps_s = gst_caps_get_structure (tmp_caps, 0);
|
|
|
|
if (!gst_structure_has_field (tmp_caps_s, "width"))
|
2024-09-03 10:19:17 +00:00
|
|
|
gst_structure_set_value_static_str (tmp_caps_s, "width",
|
2022-04-24 15:19:00 +00:00
|
|
|
gst_structure_get_value (in_caps_s, "width"));
|
|
|
|
if (!gst_structure_has_field (tmp_caps_s, "height"))
|
2024-09-03 10:19:17 +00:00
|
|
|
gst_structure_set_value_static_str (tmp_caps_s, "height",
|
2022-04-24 15:19:00 +00:00
|
|
|
gst_structure_get_value (in_caps_s, "height"));
|
|
|
|
|
|
|
|
if (!gst_video_info_from_caps (&out_info, tmp_caps)) {
|
|
|
|
gst_clear_caps (&tmp_caps);
|
2020-04-17 19:23:03 +00:00
|
|
|
GST_WARNING_OBJECT (trans,
|
|
|
|
"Failed to convert src pad caps to video info");
|
|
|
|
return;
|
|
|
|
}
|
2022-04-24 15:19:00 +00:00
|
|
|
gst_clear_caps (&tmp_caps);
|
2020-04-17 19:23:03 +00:00
|
|
|
|
|
|
|
if (!have_colorimetry && in_colorimetry != NULL) {
|
|
|
|
if ((GST_VIDEO_INFO_IS_YUV (&out_info)
|
|
|
|
&& GST_VIDEO_INFO_IS_YUV (&in_info))
|
|
|
|
|| (GST_VIDEO_INFO_IS_RGB (&out_info)
|
|
|
|
&& GST_VIDEO_INFO_IS_RGB (&in_info))
|
|
|
|
|| (GST_VIDEO_INFO_IS_GRAY (&out_info)
|
|
|
|
&& GST_VIDEO_INFO_IS_GRAY (&in_info))) {
|
|
|
|
/* Can transfer the colorimetry intact from the input if it has it */
|
2024-09-03 10:19:17 +00:00
|
|
|
gst_structure_set_value_static_str (out_caps_s, "colorimetry",
|
|
|
|
in_colorimetry);
|
2020-04-17 19:23:03 +00:00
|
|
|
} else {
|
|
|
|
gchar *colorimetry_str;
|
|
|
|
|
|
|
|
/* Changing between YUV/RGB - forward primaries and transfer function, but use
|
|
|
|
* default range and matrix.
|
|
|
|
* the primaries is used for conversion between RGB and XYZ (CIE 1931 coordinate).
|
|
|
|
* the transfer function could be another reference (e.g., HDR)
|
|
|
|
*/
|
|
|
|
out_info.colorimetry.primaries = in_info.colorimetry.primaries;
|
|
|
|
out_info.colorimetry.transfer = in_info.colorimetry.transfer;
|
|
|
|
|
|
|
|
colorimetry_str =
|
|
|
|
gst_video_colorimetry_to_string (&out_info.colorimetry);
|
2024-09-03 10:19:17 +00:00
|
|
|
gst_caps_set_simple_static_str (out_caps, "colorimetry", G_TYPE_STRING,
|
2020-04-17 19:23:03 +00:00
|
|
|
colorimetry_str, NULL);
|
|
|
|
g_free (colorimetry_str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Only YUV output needs chroma-site. If the input was also YUV and had the same chroma
|
|
|
|
* subsampling, transfer the siting. If the sub-sampling is changing, then the planes get
|
|
|
|
* scaled anyway so there's no real reason to prefer the input siting. */
|
|
|
|
if (!have_chroma_site && GST_VIDEO_INFO_IS_YUV (&out_info)) {
|
|
|
|
if (GST_VIDEO_INFO_IS_YUV (&in_info)) {
|
|
|
|
const GValue *in_chroma_site =
|
|
|
|
gst_structure_get_value (in_caps_s, "chroma-site");
|
|
|
|
if (in_chroma_site != NULL
|
|
|
|
&& subsampling_unchanged (&in_info, &out_info))
|
2024-09-03 10:19:17 +00:00
|
|
|
gst_structure_set_value_static_str (out_caps_s, "chroma-site",
|
|
|
|
in_chroma_site);
|
2020-04-17 19:23:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static GstCaps *
|
|
|
|
gst_video_convert_scale_get_fixed_format (GstBaseTransform * trans,
|
|
|
|
GstPadDirection direction, GstCaps * caps, GstCaps * othercaps)
|
|
|
|
{
|
|
|
|
GstCaps *result;
|
|
|
|
|
|
|
|
result = gst_caps_intersect (othercaps, caps);
|
|
|
|
if (gst_caps_is_empty (result)) {
|
|
|
|
gst_caps_unref (result);
|
|
|
|
result = gst_caps_copy (othercaps);
|
|
|
|
}
|
|
|
|
|
2022-07-04 07:27:50 +00:00
|
|
|
result = gst_caps_make_writable (result);
|
2020-04-17 19:23:03 +00:00
|
|
|
gst_video_convert_scale_fixate_format (trans, caps, result);
|
|
|
|
|
|
|
|
/* fixate remaining fields */
|
|
|
|
result = gst_caps_fixate (result);
|
|
|
|
|
|
|
|
if (direction == GST_PAD_SINK) {
|
|
|
|
if (gst_caps_is_subset (caps, result)) {
|
|
|
|
gst_caps_replace (&result, caps);
|
|
|
|
} else {
|
|
|
|
/* Try and preserve input colorimetry / chroma information */
|
|
|
|
transfer_colorimetry_from_input (trans, caps, result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2012-02-22 11:27:49 +00:00
|
|
|
static GstCaps *
|
2020-04-17 19:23:03 +00:00
|
|
|
gst_video_convert_scale_fixate_size (GstBaseTransform * base,
|
|
|
|
GstPadDirection direction, GstCaps * caps, GstCaps * othercaps)
|
2005-11-18 17:31:17 +00:00
|
|
|
{
|
|
|
|
GstStructure *ins, *outs;
|
|
|
|
const GValue *from_par, *to_par;
|
2020-01-23 18:38:44 +00:00
|
|
|
GValue fpar = { 0, };
|
|
|
|
GValue tpar = { 0, };
|
2005-11-18 17:31:17 +00:00
|
|
|
|
2012-03-11 18:04:41 +00:00
|
|
|
othercaps = gst_caps_truncate (othercaps);
|
2012-02-22 11:27:49 +00:00
|
|
|
othercaps = gst_caps_make_writable (othercaps);
|
2005-11-18 17:31:17 +00:00
|
|
|
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;
|
|
|
|
|
2024-09-03 10:19:17 +00:00
|
|
|
gst_structure_set_static_str (outs, "pixel-aspect-ratio",
|
|
|
|
GST_TYPE_FRACTION, 1, 1, NULL);
|
2010-05-10 15:09:28 +00:00
|
|
|
}
|
|
|
|
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 */
|
2012-02-22 11:27:49 +00:00
|
|
|
g_return_val_if_fail (gst_value_is_fixed (from_par), othercaps);
|
2006-04-28 14:33:45 +00:00
|
|
|
|
|
|
|
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)
|
2024-09-03 10:19:17 +00:00
|
|
|
gst_structure_set_static_str (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;
|
|
|
|
}
|
|
|
|
|
2019-01-09 13:42:31 +00:00
|
|
|
w = (guint) gst_util_uint64_scale_int_round (h, num, den);
|
2010-05-10 15:09:28 +00:00
|
|
|
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"))
|
2024-09-03 10:19:17 +00:00
|
|
|
gst_structure_set_value_static_str (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)
|
2024-09-03 10:19:17 +00:00
|
|
|
gst_structure_set_static_str (outs, "width", G_TYPE_INT, set_w,
|
2010-08-11 15:03:11 +00:00
|
|
|
"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;
|
|
|
|
}
|
|
|
|
|
2019-01-09 13:42:31 +00:00
|
|
|
w = (guint) gst_util_uint64_scale_int_round (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)
|
2024-09-03 10:19:17 +00:00
|
|
|
gst_structure_set_static_str (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;
|
|
|
|
}
|
|
|
|
|
2019-01-09 13:42:31 +00:00
|
|
|
h = (guint) gst_util_uint64_scale_int_round (w, den, num);
|
2010-05-10 15:09:28 +00:00
|
|
|
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"))
|
2024-09-03 10:19:17 +00:00
|
|
|
gst_structure_set_value_static_str (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)
|
2024-09-03 10:19:17 +00:00
|
|
|
gst_structure_set_static_str (outs, "height", G_TYPE_INT, set_h,
|
2010-08-11 15:03:11 +00:00
|
|
|
"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;
|
|
|
|
}
|
|
|
|
|
2019-01-09 13:42:31 +00:00
|
|
|
h = (guint) gst_util_uint64_scale_int_round (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)
|
2024-09-03 10:19:17 +00:00
|
|
|
gst_structure_set_static_str (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 */
|
2019-01-09 13:42:31 +00:00
|
|
|
w = (guint) gst_util_uint64_scale_int_round (set_h, num, den);
|
2010-05-10 15:09:28 +00:00
|
|
|
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) {
|
2024-09-03 10:19:17 +00:00
|
|
|
gst_structure_set_static_str (outs, "width", G_TYPE_INT, set_w,
|
|
|
|
"height", G_TYPE_INT, set_h, NULL);
|
2010-05-10 15:09:28 +00:00
|
|
|
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 */
|
2019-01-09 13:42:31 +00:00
|
|
|
h = (guint) gst_util_uint64_scale_int_round (set_w, den, num);
|
2010-05-10 15:09:28 +00:00
|
|
|
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) {
|
2024-09-03 10:19:17 +00:00
|
|
|
gst_structure_set_static_str (outs, "width", G_TYPE_INT, set_w,
|
|
|
|
"height", G_TYPE_INT, set_h, NULL);
|
2010-05-10 15:09:28 +00:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2019-01-09 13:24:35 +00:00
|
|
|
/* If all this failed, keep the dimensions with the DAR that was closest
|
|
|
|
* to the correct DAR. This changes the DAR but there's not much else to
|
|
|
|
* do here.
|
2010-05-10 15:09:28 +00:00
|
|
|
*/
|
2019-01-09 13:24:35 +00:00
|
|
|
if (set_w * ABS (set_h - h) < ABS (f_w - w) * f_h) {
|
|
|
|
f_h = set_h;
|
|
|
|
f_w = set_w;
|
|
|
|
}
|
2024-09-03 10:19:17 +00:00
|
|
|
gst_structure_set_static_str (outs, "width", G_TYPE_INT, f_w, "height",
|
|
|
|
G_TYPE_INT, f_h, NULL);
|
2010-05-10 15:09:28 +00:00
|
|
|
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"));
|
2015-02-04 12:08:21 +00:00
|
|
|
gst_structure_free (tmp);
|
2010-05-10 15:09:28 +00:00
|
|
|
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"))
|
2024-09-03 10:19:17 +00:00
|
|
|
gst_structure_set_value_static_str (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) {
|
2024-09-03 10:19:17 +00:00
|
|
|
gst_structure_set_static_str (outs, "width", G_TYPE_INT, set_w,
|
|
|
|
"height", G_TYPE_INT, set_h, NULL);
|
2010-08-11 15:03:11 +00:00
|
|
|
|
|
|
|
if (gst_structure_has_field (outs, "pixel-aspect-ratio") ||
|
|
|
|
set_par_n != set_par_d)
|
2024-09-03 10:19:17 +00:00
|
|
|
gst_structure_set_static_str (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
|
|
|
|
2019-01-09 13:42:31 +00:00
|
|
|
w = (guint) gst_util_uint64_scale_int_round (set_h, num, den);
|
2010-05-10 15:09:28 +00:00
|
|
|
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) {
|
2024-09-03 10:19:17 +00:00
|
|
|
gst_structure_set_static_str (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)
|
2024-09-03 10:19:17 +00:00
|
|
|
gst_structure_set_static_str (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 */
|
2019-01-09 13:42:31 +00:00
|
|
|
h = (guint) gst_util_uint64_scale_int_round (set_w, den, num);
|
2010-05-10 15:09:28 +00:00
|
|
|
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) {
|
2024-09-03 10:19:17 +00:00
|
|
|
gst_structure_set_static_str (outs, "width", G_TYPE_INT, set_w,
|
|
|
|
"height", G_TYPE_INT, tmp2, NULL);
|
|
|
|
if (gst_structure_has_field (outs, "pixel-aspect-ratio")
|
|
|
|
|| set_par_n != set_par_d)
|
|
|
|
gst_structure_set_static_str (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 */
|
2024-09-03 10:19:17 +00:00
|
|
|
gst_structure_set_static_str (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)
|
2024-09-03 10:19:17 +00:00
|
|
|
gst_structure_set_static_str (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:
|
2020-08-25 09:56:21 +00:00
|
|
|
othercaps = gst_caps_fixate (othercaps);
|
|
|
|
|
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);
|
2012-02-22 11:27:49 +00:00
|
|
|
|
|
|
|
return othercaps;
|
2005-11-18 17:31:17 +00:00
|
|
|
}
|
|
|
|
|
2020-04-17 19:23:03 +00:00
|
|
|
static GstCaps *
|
|
|
|
gst_video_convert_scale_fixate_caps (GstBaseTransform * base,
|
|
|
|
GstPadDirection direction, GstCaps * caps, GstCaps * othercaps)
|
|
|
|
{
|
|
|
|
GstCaps *format;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (base,
|
|
|
|
"trying to fixate othercaps %" GST_PTR_FORMAT " based on caps %"
|
|
|
|
GST_PTR_FORMAT, othercaps, caps);
|
|
|
|
|
|
|
|
format = gst_video_convert_scale_get_fixed_format (base, direction, caps,
|
|
|
|
othercaps);
|
|
|
|
|
|
|
|
if (gst_caps_is_empty (format)) {
|
|
|
|
GST_ERROR_OBJECT (base, "Could not convert formats");
|
|
|
|
return format;
|
|
|
|
}
|
|
|
|
|
|
|
|
othercaps =
|
|
|
|
gst_video_convert_scale_fixate_size (base, direction, caps, othercaps);
|
|
|
|
if (gst_caps_get_size (othercaps) == 1) {
|
|
|
|
gint i;
|
|
|
|
const gchar *format_fields[] = { "format", "colorimetry", "chroma-site" };
|
|
|
|
GstStructure *format_struct = gst_caps_get_structure (format, 0);
|
|
|
|
GstStructure *fixated_struct;
|
|
|
|
|
|
|
|
othercaps = gst_caps_make_writable (othercaps);
|
|
|
|
fixated_struct = gst_caps_get_structure (othercaps, 0);
|
|
|
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (format_fields); i++) {
|
|
|
|
if (gst_structure_has_field (format_struct, format_fields[i])) {
|
2024-09-03 10:19:17 +00:00
|
|
|
gst_structure_set_static_str (fixated_struct, format_fields[i],
|
|
|
|
G_TYPE_STRING, gst_structure_get_string (format_struct,
|
|
|
|
format_fields[i]), NULL);
|
2020-04-17 19:23:03 +00:00
|
|
|
} else {
|
|
|
|
gst_structure_remove_field (fixated_struct, format_fields[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
gst_caps_unref (format);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (base, "fixated othercaps to %" GST_PTR_FORMAT, othercaps);
|
|
|
|
|
|
|
|
return othercaps;
|
|
|
|
}
|
|
|
|
|
2014-10-24 15:08:43 +00:00
|
|
|
#define GET_LINE(frame, line) \
|
|
|
|
(gpointer)(((guint8*)(GST_VIDEO_FRAME_PLANE_DATA (frame, 0))) + \
|
|
|
|
GST_VIDEO_FRAME_PLANE_STRIDE (frame, 0) * (line))
|
2005-07-01 17:03:13 +00:00
|
|
|
|
|
|
|
static GstFlowReturn
|
2020-04-17 19:23:03 +00:00
|
|
|
gst_video_convert_scale_transform_frame (GstVideoFilter * filter,
|
2011-12-21 22:46:53 +00:00
|
|
|
GstVideoFrame * in_frame, GstVideoFrame * out_frame)
|
2005-07-01 17:03:13 +00:00
|
|
|
{
|
2020-04-17 19:23:03 +00:00
|
|
|
GstVideoConvertScalePrivate *priv = PRIV (filter);
|
2005-08-24 15:07:54 +00:00
|
|
|
GstFlowReturn ret = GST_FLOW_OK;
|
2013-02-05 09:46:50 +00:00
|
|
|
|
2016-02-20 11:31:43 +00:00
|
|
|
GST_CAT_DEBUG_OBJECT (CAT_PERFORMANCE, filter, "doing video scaling");
|
2015-07-15 10:45:10 +00:00
|
|
|
|
2022-03-23 13:38:00 +00:00
|
|
|
if (priv->converter_config_changed) {
|
|
|
|
GstStructure *options =
|
|
|
|
gst_video_convert_scale_get_converter_config (GST_VIDEO_CONVERT_SCALE
|
|
|
|
(filter), &filter->out_info);
|
|
|
|
|
|
|
|
gst_video_converter_free (priv->convert);
|
|
|
|
priv->convert =
|
|
|
|
gst_video_converter_new (&filter->in_info, &filter->out_info, options);
|
|
|
|
|
|
|
|
priv->converter_config_changed = FALSE;
|
|
|
|
}
|
|
|
|
|
2020-04-17 19:23:03 +00:00
|
|
|
gst_video_converter_frame (priv->convert, in_frame, out_frame);
|
2013-02-05 09:46:50 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2005-07-01 17:03:13 +00:00
|
|
|
static gboolean
|
2020-04-17 19:23:03 +00:00
|
|
|
gst_video_convert_scale_src_event (GstBaseTransform * trans, GstEvent * event)
|
2001-12-22 23:27:17 +00:00
|
|
|
{
|
2020-04-17 19:23:03 +00:00
|
|
|
GstVideoConvertScale *self = GST_VIDEO_CONVERT_SCALE_CAST (trans);
|
2011-12-21 22:46:53 +00:00
|
|
|
GstVideoFilter *filter = GST_VIDEO_FILTER_CAST (trans);
|
2005-11-16 12:23:02 +00:00
|
|
|
gboolean ret;
|
2022-02-14 15:08:23 +00:00
|
|
|
gdouble x, y;
|
2001-12-22 23:27:17 +00:00
|
|
|
|
2020-04-17 19:23:03 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "handling %s event", GST_EVENT_TYPE_NAME (event));
|
2005-11-16 12:23:02 +00:00
|
|
|
|
2005-07-01 17:03:13 +00:00
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
|
|
|
case GST_EVENT_NAVIGATION:
|
2012-09-11 08:56:43 +00:00
|
|
|
if (filter->in_info.width != filter->out_info.width ||
|
|
|
|
filter->in_info.height != filter->out_info.height) {
|
2022-02-14 15:08:23 +00:00
|
|
|
event = gst_event_make_writable (event);
|
2012-09-11 08:56:43 +00:00
|
|
|
|
2022-02-14 15:08:23 +00:00
|
|
|
if (gst_navigation_event_get_coordinates (event, &x, &y)) {
|
|
|
|
gst_navigation_event_set_coordinates (event,
|
|
|
|
x * filter->in_info.width / filter->out_info.width,
|
|
|
|
y * filter->in_info.height / filter->out_info.height);
|
2012-09-11 08:56:43 +00:00
|
|
|
}
|
2005-07-01 17:03:13 +00:00
|
|
|
}
|
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
|
|
|
}
|