2004-01-15 08:58:22 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
|
2010-09-13 19:48:50 +00:00
|
|
|
* This file:
|
|
|
|
* Copyright (C) 2003 Ronald Bultje <rbultje@ronald.bitfreak.net>
|
|
|
|
* Copyright (C) 2010 David Schleef <ds@schleef.org>
|
2004-01-15 08:58:22 +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.
|
2004-01-15 08:58:22 +00:00
|
|
|
*/
|
|
|
|
|
2010-09-13 19:48:50 +00:00
|
|
|
/**
|
2011-06-15 15:49:21 +00:00
|
|
|
* SECTION:element-videoconvert
|
2010-09-13 19:48:50 +00:00
|
|
|
*
|
2011-06-16 10:48:33 +00:00
|
|
|
* Convert video frames between a great variety of video formats.
|
2010-09-13 19:48:50 +00:00
|
|
|
*
|
|
|
|
* <refsect2>
|
|
|
|
* <title>Example launch line</title>
|
|
|
|
* |[
|
2012-08-08 10:04:32 +00:00
|
|
|
* gst-launch -v videotestsrc ! video/x-raw,format=\(string\)YUY2 ! videoconvert ! ximagesink
|
2010-09-13 19:48:50 +00:00
|
|
|
* ]|
|
|
|
|
* </refsect2>
|
|
|
|
*/
|
|
|
|
|
2004-01-15 08:58:22 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2010-09-13 19:48:50 +00:00
|
|
|
# include "config.h"
|
2004-01-15 08:58:22 +00:00
|
|
|
#endif
|
2010-09-13 19:48:50 +00:00
|
|
|
|
2011-06-15 15:49:21 +00:00
|
|
|
#include "gstvideoconvert.h"
|
2011-12-21 22:46:53 +00:00
|
|
|
|
2004-01-15 08:58:22 +00:00
|
|
|
#include <gst/video/video.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>
|
2004-01-15 08:58:22 +00:00
|
|
|
|
2010-11-02 15:05:37 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2011-06-15 15:49:21 +00:00
|
|
|
GST_DEBUG_CATEGORY (videoconvert_debug);
|
|
|
|
#define GST_CAT_DEFAULT videoconvert_debug
|
2012-02-09 15:00:59 +00:00
|
|
|
GST_DEBUG_CATEGORY_EXTERN (GST_CAT_PERFORMANCE);
|
2012-02-09 14:28:54 +00:00
|
|
|
|
2012-03-01 16:36:08 +00:00
|
|
|
GType gst_video_convert_get_type (void);
|
|
|
|
|
|
|
|
static GQuark _colorspace_quark;
|
|
|
|
|
|
|
|
#define gst_video_convert_parent_class parent_class
|
|
|
|
G_DEFINE_TYPE (GstVideoConvert, gst_video_convert, GST_TYPE_VIDEO_FILTER);
|
2010-09-13 19:48:50 +00:00
|
|
|
|
2014-12-02 10:51:19 +00:00
|
|
|
#define DEFAULT_PROP_DITHER GST_VIDEO_DITHER_BAYER
|
|
|
|
#define DEFAULT_PROP_DITHER_QUANTIZATION 1
|
|
|
|
|
2011-02-21 06:43:56 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
2014-12-02 10:51:19 +00:00
|
|
|
PROP_DITHER,
|
|
|
|
PROP_DITHER_QUANTIZATION
|
2011-02-21 06:43:56 +00:00
|
|
|
};
|
|
|
|
|
2013-04-08 06:15:15 +00:00
|
|
|
#define CSP_VIDEO_CAPS GST_VIDEO_CAPS_MAKE (GST_VIDEO_FORMATS_ALL) ";" \
|
|
|
|
GST_VIDEO_CAPS_MAKE_WITH_FEATURES ("ANY", GST_VIDEO_FORMATS_ALL)
|
2010-09-13 19:48:50 +00:00
|
|
|
|
2011-06-15 15:49:21 +00:00
|
|
|
static GstStaticPadTemplate gst_video_convert_src_template =
|
2010-09-13 19:48:50 +00:00
|
|
|
GST_STATIC_PAD_TEMPLATE ("src",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS (CSP_VIDEO_CAPS)
|
|
|
|
);
|
2004-01-15 08:58:22 +00:00
|
|
|
|
2011-06-15 15:49:21 +00:00
|
|
|
static GstStaticPadTemplate gst_video_convert_sink_template =
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_STATIC_PAD_TEMPLATE ("sink",
|
2004-01-15 08:58:22 +00:00
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
2010-09-13 19:48:50 +00:00
|
|
|
GST_STATIC_CAPS (CSP_VIDEO_CAPS)
|
2004-03-14 22:34:33 +00:00
|
|
|
);
|
2004-01-15 08:58:22 +00:00
|
|
|
|
2011-06-15 15:49:21 +00:00
|
|
|
static void gst_video_convert_set_property (GObject * object,
|
2011-02-21 06:43:56 +00:00
|
|
|
guint property_id, const GValue * value, GParamSpec * pspec);
|
2011-06-15 15:49:21 +00:00
|
|
|
static void gst_video_convert_get_property (GObject * object,
|
2011-02-21 06:43:56 +00:00
|
|
|
guint property_id, GValue * value, GParamSpec * pspec);
|
|
|
|
|
2011-12-21 22:46:53 +00:00
|
|
|
static gboolean gst_video_convert_set_info (GstVideoFilter * filter,
|
|
|
|
GstCaps * incaps, GstVideoInfo * in_info, GstCaps * outcaps,
|
|
|
|
GstVideoInfo * out_info);
|
|
|
|
static GstFlowReturn gst_video_convert_transform_frame (GstVideoFilter * filter,
|
|
|
|
GstVideoFrame * in_frame, GstVideoFrame * out_frame);
|
2004-01-15 08:58:22 +00:00
|
|
|
|
2010-09-13 19:48:50 +00:00
|
|
|
/* copies the given caps */
|
|
|
|
static GstCaps *
|
2011-06-15 15:49:21 +00:00
|
|
|
gst_video_convert_caps_remove_format_info (GstCaps * caps)
|
2004-03-14 22:34:33 +00:00
|
|
|
{
|
2011-06-16 10:48:33 +00:00
|
|
|
GstStructure *st;
|
2013-04-08 06:15:15 +00:00
|
|
|
GstCapsFeatures *f;
|
2011-06-15 14:52:52 +00:00
|
|
|
gint i, n;
|
|
|
|
GstCaps *res;
|
2004-01-15 08:58:22 +00:00
|
|
|
|
2011-06-15 14:52:52 +00:00
|
|
|
res = gst_caps_new_empty ();
|
2004-01-15 08:58:22 +00:00
|
|
|
|
2011-06-15 14:52:52 +00:00
|
|
|
n = gst_caps_get_size (caps);
|
|
|
|
for (i = 0; i < n; i++) {
|
2011-06-16 10:48:33 +00:00
|
|
|
st = gst_caps_get_structure (caps, i);
|
2013-04-08 06:15:15 +00:00
|
|
|
f = gst_caps_get_features (caps, i);
|
2004-01-15 08:58:22 +00:00
|
|
|
|
2011-06-15 14:52:52 +00:00
|
|
|
/* If this is already expressed by the existing caps
|
|
|
|
* skip this structure */
|
2013-04-08 06:15:15 +00:00
|
|
|
if (i > 0 && gst_caps_is_subset_structure_full (res, st, f))
|
2011-06-15 14:52:52 +00:00
|
|
|
continue;
|
2004-01-15 08:58:22 +00:00
|
|
|
|
2011-06-16 10:48:33 +00:00
|
|
|
st = gst_structure_copy (st);
|
2013-04-08 06:15:15 +00:00
|
|
|
/* Only remove format info for the cases when we can actually convert */
|
|
|
|
if (!gst_caps_features_is_any (f)
|
|
|
|
&& gst_caps_features_is_equal (f,
|
|
|
|
GST_CAPS_FEATURES_MEMORY_SYSTEM_MEMORY))
|
|
|
|
gst_structure_remove_fields (st, "format", "colorimetry", "chroma-site",
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
gst_caps_append_structure_full (res, st, gst_caps_features_copy (f));
|
2004-01-15 08:58:22 +00:00
|
|
|
}
|
|
|
|
|
2011-06-15 14:52:52 +00:00
|
|
|
return res;
|
2004-01-15 08:58:22 +00:00
|
|
|
}
|
|
|
|
|
2014-01-24 11:19:43 +00:00
|
|
|
/*
|
|
|
|
* This is an incomplete matrix of in formats and a score for the prefered 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 prefered, if we can we would convert to PAL instead
|
|
|
|
* of GRAY, though
|
|
|
|
* less subsampling is prefered 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)
|
2013-03-28 17:13:10 +00:00
|
|
|
|
|
|
|
/* 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)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* accept input format immediately without loss */
|
|
|
|
if (in_info == t_info) {
|
|
|
|
*min_loss = 0;
|
|
|
|
*out_info = t_info;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-01-24 11:19:43 +00:00
|
|
|
loss = SCORE_FORMAT_CHANGE;
|
2013-03-28 17:13:10 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2014-01-24 11:19:43 +00:00
|
|
|
if ((t_flags & PALETTE_MASK) != (in_flags & PALETTE_MASK)) {
|
|
|
|
loss += SCORE_PALETTE_CHANGE;
|
|
|
|
if (t_flags & PALETTE_MASK)
|
|
|
|
loss += SCORE_PALETTE_LOSS;
|
|
|
|
}
|
2013-03-28 17:13:10 +00:00
|
|
|
|
2014-01-24 11:19:43 +00:00
|
|
|
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;
|
|
|
|
}
|
2013-03-28 17:13:10 +00:00
|
|
|
|
2014-01-24 11:19:43 +00:00
|
|
|
if ((t_flags & ALPHA_MASK) != (in_flags & ALPHA_MASK)) {
|
|
|
|
loss += SCORE_ALPHA_CHANGE;
|
|
|
|
if (in_flags & ALPHA_MASK)
|
|
|
|
loss += SCORE_ALPHA_LOSS;
|
|
|
|
}
|
2013-03-28 17:13:10 +00:00
|
|
|
|
2014-01-24 11:19:43 +00:00
|
|
|
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;
|
|
|
|
}
|
2013-03-28 17:13:10 +00:00
|
|
|
|
2014-01-24 11:19:43 +00:00
|
|
|
if ((in_info->bits) != (t_info->bits)) {
|
|
|
|
loss += SCORE_DEPTH_CHANGE;
|
|
|
|
if ((in_info->bits) > (t_info->bits))
|
|
|
|
loss += SCORE_DEPTH_LOSS;
|
|
|
|
}
|
2013-03-28 17:13:10 +00:00
|
|
|
|
|
|
|
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_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");
|
|
|
|
/* 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)
|
|
|
|
gst_structure_set (outs, "format", G_TYPE_STRING,
|
|
|
|
GST_VIDEO_FORMAT_INFO_NAME (out_info), NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-22 11:27:49 +00:00
|
|
|
static GstCaps *
|
2012-02-20 11:36:02 +00:00
|
|
|
gst_video_convert_fixate_caps (GstBaseTransform * trans,
|
|
|
|
GstPadDirection direction, GstCaps * caps, GstCaps * othercaps)
|
|
|
|
{
|
2012-02-22 14:31:12 +00:00
|
|
|
GstCaps *result;
|
2012-02-22 11:27:49 +00:00
|
|
|
|
2013-03-28 17:13:10 +00:00
|
|
|
GST_DEBUG_OBJECT (trans, "trying to fixate othercaps %" GST_PTR_FORMAT
|
|
|
|
" based on caps %" GST_PTR_FORMAT, othercaps, caps);
|
2012-02-20 11:36:02 +00:00
|
|
|
|
2012-02-22 14:31:12 +00:00
|
|
|
result = gst_caps_intersect (othercaps, caps);
|
|
|
|
if (gst_caps_is_empty (result)) {
|
2012-04-02 15:01:59 +00:00
|
|
|
gst_caps_unref (result);
|
2012-02-22 14:31:12 +00:00
|
|
|
result = othercaps;
|
|
|
|
} else {
|
|
|
|
gst_caps_unref (othercaps);
|
2012-02-20 11:36:02 +00:00
|
|
|
}
|
|
|
|
|
2013-03-28 17:13:10 +00:00
|
|
|
GST_DEBUG_OBJECT (trans, "now fixating %" GST_PTR_FORMAT, result);
|
|
|
|
|
|
|
|
result = gst_caps_make_writable (result);
|
|
|
|
gst_video_convert_fixate_format (trans, caps, result);
|
|
|
|
|
2012-02-20 11:36:02 +00:00
|
|
|
/* fixate remaining fields */
|
2012-03-11 18:04:41 +00:00
|
|
|
result = gst_caps_fixate (result);
|
2012-02-22 11:27:49 +00:00
|
|
|
|
2012-02-22 14:31:12 +00:00
|
|
|
return result;
|
2012-02-20 11:36:02 +00:00
|
|
|
}
|
|
|
|
|
2012-03-02 16:35:40 +00:00
|
|
|
static gboolean
|
|
|
|
gst_video_convert_filter_meta (GstBaseTransform * trans, GstQuery * query,
|
2012-07-06 09:50:44 +00:00
|
|
|
GType api, const GstStructure * params)
|
2012-03-02 16:35:40 +00:00
|
|
|
{
|
|
|
|
/* propose all metadata upstream */
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-09-13 19:48:50 +00:00
|
|
|
/* The caps can be transformed into any other caps with format info removed.
|
|
|
|
* However, we should prefer passthrough, so if passthrough is possible,
|
|
|
|
* put it first in the list. */
|
2004-03-14 22:34:33 +00:00
|
|
|
static GstCaps *
|
2011-06-15 15:49:21 +00:00
|
|
|
gst_video_convert_transform_caps (GstBaseTransform * btrans,
|
2011-06-15 14:28:44 +00:00
|
|
|
GstPadDirection direction, GstCaps * caps, GstCaps * filter)
|
2004-01-15 08:58:22 +00:00
|
|
|
{
|
2010-09-13 19:48:50 +00:00
|
|
|
GstCaps *tmp, *tmp2;
|
|
|
|
GstCaps *result;
|
|
|
|
|
|
|
|
/* Get all possible caps that we can transform to */
|
2011-06-15 15:49:21 +00:00
|
|
|
tmp = gst_video_convert_caps_remove_format_info (caps);
|
2004-01-15 08:58:22 +00:00
|
|
|
|
2011-06-15 14:52:52 +00:00
|
|
|
if (filter) {
|
|
|
|
tmp2 = gst_caps_intersect_full (filter, tmp, GST_CAPS_INTERSECT_FIRST);
|
|
|
|
gst_caps_unref (tmp);
|
|
|
|
tmp = tmp2;
|
2010-09-13 19:48:50 +00:00
|
|
|
}
|
2004-01-15 08:58:22 +00:00
|
|
|
|
2011-06-15 14:52:52 +00:00
|
|
|
result = tmp;
|
2004-01-15 08:58:22 +00:00
|
|
|
|
2010-09-13 19:48:50 +00:00
|
|
|
GST_DEBUG_OBJECT (btrans, "transformed %" GST_PTR_FORMAT " into %"
|
|
|
|
GST_PTR_FORMAT, caps, result);
|
2004-01-15 08:58:22 +00:00
|
|
|
|
2010-09-13 19:48:50 +00:00
|
|
|
return result;
|
2004-01-15 08:58:22 +00:00
|
|
|
}
|
|
|
|
|
2012-03-02 16:35:40 +00:00
|
|
|
static gboolean
|
|
|
|
gst_video_convert_transform_meta (GstBaseTransform * trans, GstBuffer * outbuf,
|
|
|
|
GstMeta * meta, GstBuffer * inbuf)
|
|
|
|
{
|
|
|
|
const GstMetaInfo *info = meta->info;
|
|
|
|
gboolean ret;
|
|
|
|
|
|
|
|
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. */
|
|
|
|
ret = FALSE;
|
|
|
|
} else {
|
|
|
|
/* copy other metadata */
|
|
|
|
ret = TRUE;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-12-21 17:58:42 +00:00
|
|
|
static gboolean
|
2011-12-21 22:46:53 +00:00
|
|
|
gst_video_convert_set_info (GstVideoFilter * filter,
|
|
|
|
GstCaps * incaps, GstVideoInfo * in_info, GstCaps * outcaps,
|
|
|
|
GstVideoInfo * out_info)
|
2004-01-15 08:58:22 +00:00
|
|
|
{
|
2011-06-15 15:49:21 +00:00
|
|
|
GstVideoConvert *space;
|
2004-01-15 08:58:22 +00:00
|
|
|
|
2011-12-21 22:46:53 +00:00
|
|
|
space = GST_VIDEO_CONVERT_CAST (filter);
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2011-02-19 21:13:13 +00:00
|
|
|
if (space->convert) {
|
2014-09-24 14:19:30 +00:00
|
|
|
gst_video_converter_free (space->convert);
|
2013-03-23 23:38:22 +00:00
|
|
|
space->convert = NULL;
|
2011-02-19 21:13:13 +00:00
|
|
|
}
|
|
|
|
|
2010-09-13 19:48:50 +00:00
|
|
|
/* these must match */
|
2011-12-21 22:46:53 +00:00
|
|
|
if (in_info->width != out_info->width || in_info->height != out_info->height
|
|
|
|
|| in_info->fps_n != out_info->fps_n || in_info->fps_d != out_info->fps_d)
|
2010-09-13 19:48:50 +00:00
|
|
|
goto format_mismatch;
|
2004-01-15 08:58:22 +00:00
|
|
|
|
2010-09-13 19:48:50 +00:00
|
|
|
/* if present, these must match too */
|
2011-12-21 22:46:53 +00:00
|
|
|
if (in_info->par_n != out_info->par_n || in_info->par_d != out_info->par_d)
|
2010-09-13 19:48:50 +00:00
|
|
|
goto format_mismatch;
|
2004-01-15 08:58:22 +00:00
|
|
|
|
2010-09-13 19:48:50 +00:00
|
|
|
/* if present, these must match too */
|
2012-04-19 10:13:03 +00:00
|
|
|
if (in_info->interlace_mode != out_info->interlace_mode)
|
2010-09-13 19:48:50 +00:00
|
|
|
goto format_mismatch;
|
2004-01-15 08:58:22 +00:00
|
|
|
|
2014-09-24 13:49:42 +00:00
|
|
|
|
2014-09-24 14:19:30 +00:00
|
|
|
space->convert = gst_video_converter_new (in_info, out_info,
|
2014-09-24 13:49:42 +00:00
|
|
|
gst_structure_new ("GstVideoConvertConfig",
|
2014-12-02 10:51:19 +00:00
|
|
|
GST_VIDEO_CONVERTER_OPT_DITHER_METHOD, GST_TYPE_VIDEO_DITHER_METHOD,
|
|
|
|
space->dither,
|
|
|
|
GST_VIDEO_CONVERTER_OPT_DITHER_QUANTIZATION, G_TYPE_UINT,
|
|
|
|
space->dither_quantization, NULL));
|
2011-06-17 13:31:59 +00:00
|
|
|
if (space->convert == NULL)
|
|
|
|
goto no_convert;
|
|
|
|
|
2011-12-21 22:46:53 +00:00
|
|
|
GST_DEBUG ("reconfigured %d %d", GST_VIDEO_INFO_FORMAT (in_info),
|
|
|
|
GST_VIDEO_INFO_FORMAT (out_info));
|
2004-01-15 08:58:22 +00:00
|
|
|
|
2010-09-13 19:48:50 +00:00
|
|
|
return TRUE;
|
2004-01-15 08:58:22 +00:00
|
|
|
|
2010-09-13 19:48:50 +00:00
|
|
|
/* ERRORS */
|
|
|
|
format_mismatch:
|
|
|
|
{
|
2010-09-14 01:49:43 +00:00
|
|
|
GST_ERROR_OBJECT (space, "input and output formats do not match");
|
2011-12-21 22:46:53 +00:00
|
|
|
return FALSE;
|
2004-01-15 08:58:22 +00:00
|
|
|
}
|
2011-06-17 13:31:59 +00:00
|
|
|
no_convert:
|
|
|
|
{
|
|
|
|
GST_ERROR_OBJECT (space, "could not create converter");
|
2011-12-21 22:46:53 +00:00
|
|
|
return FALSE;
|
2011-06-17 13:31:59 +00:00
|
|
|
}
|
2004-01-15 08:58:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-06-15 15:49:21 +00:00
|
|
|
gst_video_convert_finalize (GObject * obj)
|
2004-01-15 08:58:22 +00:00
|
|
|
{
|
2011-06-15 15:49:21 +00:00
|
|
|
GstVideoConvert *space = GST_VIDEO_CONVERT (obj);
|
2011-02-16 02:12:02 +00:00
|
|
|
|
|
|
|
if (space->convert) {
|
2014-09-24 14:19:30 +00:00
|
|
|
gst_video_converter_free (space->convert);
|
2011-02-16 02:12:02 +00:00
|
|
|
}
|
|
|
|
|
2010-09-13 19:48:50 +00:00
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-06-15 15:49:21 +00:00
|
|
|
gst_video_convert_class_init (GstVideoConvertClass * klass)
|
2010-09-13 19:48:50 +00:00
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = (GObjectClass *) klass;
|
2011-06-15 14:28:44 +00:00
|
|
|
GstElementClass *gstelement_class = (GstElementClass *) klass;
|
2010-09-13 19:48:50 +00:00
|
|
|
GstBaseTransformClass *gstbasetransform_class =
|
|
|
|
(GstBaseTransformClass *) klass;
|
2011-12-21 22:46:53 +00:00
|
|
|
GstVideoFilterClass *gstvideofilter_class = (GstVideoFilterClass *) klass;
|
2004-01-15 08:58:22 +00:00
|
|
|
|
2011-06-15 15:49:21 +00:00
|
|
|
gobject_class->set_property = gst_video_convert_set_property;
|
|
|
|
gobject_class->get_property = gst_video_convert_get_property;
|
|
|
|
gobject_class->finalize = gst_video_convert_finalize;
|
2004-01-15 08:58:22 +00:00
|
|
|
|
2011-06-15 14:28:44 +00:00
|
|
|
gst_element_class_add_pad_template (gstelement_class,
|
2011-06-15 15:49:21 +00:00
|
|
|
gst_static_pad_template_get (&gst_video_convert_src_template));
|
2011-06-15 14:28:44 +00:00
|
|
|
gst_element_class_add_pad_template (gstelement_class,
|
2011-06-15 15:49:21 +00:00
|
|
|
gst_static_pad_template_get (&gst_video_convert_sink_template));
|
2011-06-15 14:28:44 +00:00
|
|
|
|
2012-04-09 23:45:16 +00:00
|
|
|
gst_element_class_set_static_metadata (gstelement_class,
|
2012-09-25 11:16:45 +00:00
|
|
|
"Colorspace converter", "Filter/Converter/Video",
|
2011-06-15 14:28:44 +00:00
|
|
|
"Converts video from one colorspace to another",
|
|
|
|
"GStreamer maintainers <gstreamer-devel@lists.sourceforge.net>");
|
|
|
|
|
2010-09-13 19:48:50 +00:00
|
|
|
gstbasetransform_class->transform_caps =
|
2011-06-15 15:49:21 +00:00
|
|
|
GST_DEBUG_FUNCPTR (gst_video_convert_transform_caps);
|
2012-02-20 11:36:02 +00:00
|
|
|
gstbasetransform_class->fixate_caps =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_video_convert_fixate_caps);
|
2012-03-02 16:35:40 +00:00
|
|
|
gstbasetransform_class->filter_meta =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_video_convert_filter_meta);
|
|
|
|
gstbasetransform_class->transform_meta =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_video_convert_transform_meta);
|
2004-01-15 08:58:22 +00:00
|
|
|
|
2010-09-13 19:48:50 +00:00
|
|
|
gstbasetransform_class->passthrough_on_same_caps = TRUE;
|
2011-02-21 06:43:56 +00:00
|
|
|
|
2011-12-21 22:46:53 +00:00
|
|
|
gstvideofilter_class->set_info =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_video_convert_set_info);
|
|
|
|
gstvideofilter_class->transform_frame =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_video_convert_transform_frame);
|
|
|
|
|
2011-02-21 06:43:56 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_DITHER,
|
|
|
|
g_param_spec_enum ("dither", "Dither", "Apply dithering while converting",
|
2014-12-02 10:51:19 +00:00
|
|
|
gst_video_dither_method_get_type (), DEFAULT_PROP_DITHER,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
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,
|
2011-02-21 06:43:56 +00:00
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2004-01-15 08:58:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-06-15 15:49:21 +00:00
|
|
|
gst_video_convert_init (GstVideoConvert * space)
|
2004-01-15 08:58:22 +00:00
|
|
|
{
|
2014-12-02 10:51:19 +00:00
|
|
|
space->dither = DEFAULT_PROP_DITHER;
|
|
|
|
space->dither_quantization = DEFAULT_PROP_DITHER_QUANTIZATION;
|
2004-01-15 08:58:22 +00:00
|
|
|
}
|
|
|
|
|
2011-02-21 06:43:56 +00:00
|
|
|
void
|
2011-06-15 15:49:21 +00:00
|
|
|
gst_video_convert_set_property (GObject * object, guint property_id,
|
2011-02-21 06:43:56 +00:00
|
|
|
const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
2011-06-15 15:49:21 +00:00
|
|
|
GstVideoConvert *csp;
|
2011-02-21 06:43:56 +00:00
|
|
|
|
2011-06-15 15:49:21 +00:00
|
|
|
csp = GST_VIDEO_CONVERT (object);
|
2011-02-21 06:43:56 +00:00
|
|
|
|
|
|
|
switch (property_id) {
|
|
|
|
case PROP_DITHER:
|
|
|
|
csp->dither = g_value_get_enum (value);
|
|
|
|
break;
|
2014-12-02 10:51:19 +00:00
|
|
|
case PROP_DITHER_QUANTIZATION:
|
|
|
|
csp->dither_quantization = g_value_get_uint (value);
|
|
|
|
break;
|
2011-02-21 06:43:56 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-06-15 15:49:21 +00:00
|
|
|
gst_video_convert_get_property (GObject * object, guint property_id,
|
2011-02-21 06:43:56 +00:00
|
|
|
GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
2011-06-15 15:49:21 +00:00
|
|
|
GstVideoConvert *csp;
|
2011-02-21 06:43:56 +00:00
|
|
|
|
2011-06-15 15:49:21 +00:00
|
|
|
csp = GST_VIDEO_CONVERT (object);
|
2011-02-21 06:43:56 +00:00
|
|
|
|
|
|
|
switch (property_id) {
|
|
|
|
case PROP_DITHER:
|
|
|
|
g_value_set_enum (value, csp->dither);
|
|
|
|
break;
|
2014-12-02 10:51:19 +00:00
|
|
|
case PROP_DITHER_QUANTIZATION:
|
|
|
|
g_value_set_uint (value, csp->dither_quantization);
|
|
|
|
break;
|
2011-02-21 06:43:56 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-13 19:48:50 +00:00
|
|
|
static GstFlowReturn
|
2011-12-21 22:46:53 +00:00
|
|
|
gst_video_convert_transform_frame (GstVideoFilter * filter,
|
|
|
|
GstVideoFrame * in_frame, GstVideoFrame * out_frame)
|
2004-01-15 08:58:22 +00:00
|
|
|
{
|
2011-06-15 15:49:21 +00:00
|
|
|
GstVideoConvert *space;
|
2004-01-15 08:58:22 +00:00
|
|
|
|
2011-12-21 22:46:53 +00:00
|
|
|
space = GST_VIDEO_CONVERT_CAST (filter);
|
2004-01-15 08:58:22 +00:00
|
|
|
|
2012-02-09 14:28:54 +00:00
|
|
|
GST_CAT_DEBUG_OBJECT (GST_CAT_PERFORMANCE, filter,
|
|
|
|
"doing colorspace conversion from %s -> to %s",
|
|
|
|
GST_VIDEO_INFO_NAME (&filter->in_info),
|
2011-12-21 22:46:53 +00:00
|
|
|
GST_VIDEO_INFO_NAME (&filter->out_info));
|
2004-01-15 08:58:22 +00:00
|
|
|
|
2014-10-24 09:45:13 +00:00
|
|
|
gst_video_converter_frame (space->convert, in_frame, out_frame);
|
2004-01-15 08:58:22 +00:00
|
|
|
|
2010-09-13 19:48:50 +00:00
|
|
|
return GST_FLOW_OK;
|
2004-01-15 08:58:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2004-03-14 22:34:33 +00:00
|
|
|
plugin_init (GstPlugin * plugin)
|
2004-01-15 08:58:22 +00:00
|
|
|
{
|
2011-06-15 15:49:21 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT (videoconvert_debug, "videoconvert", 0,
|
2010-09-13 19:48:50 +00:00
|
|
|
"Colorspace Converter");
|
2004-01-15 08:58:22 +00:00
|
|
|
|
2012-03-01 16:36:08 +00:00
|
|
|
_colorspace_quark = g_quark_from_static_string ("colorspace");
|
|
|
|
|
2011-06-15 15:49:21 +00:00
|
|
|
return gst_element_register (plugin, "videoconvert",
|
|
|
|
GST_RANK_NONE, GST_TYPE_VIDEO_CONVERT);
|
2004-01-15 08:58:22 +00:00
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
|
|
|
|
GST_VERSION_MINOR,
|
2012-09-25 11:16:45 +00:00
|
|
|
videoconvert, "Colorspace conversion", plugin_init, VERSION, GST_LICENSE,
|
|
|
|
GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)
|