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
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
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>
|
|
|
|
* |[
|
2011-06-16 10:48:33 +00:00
|
|
|
* gst-launch -v videotestsrc ! video/x-raw,format=\(fourcc\)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"
|
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
|
|
|
|
GST_DEBUG_CATEGORY (videoconvert_performance);
|
2010-09-13 19:48:50 +00:00
|
|
|
|
2011-02-21 06:43:56 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_DITHER
|
|
|
|
};
|
|
|
|
|
2011-06-16 10:48:33 +00:00
|
|
|
#define CSP_VIDEO_CAPS GST_VIDEO_CAPS_MAKE (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
|
|
|
GType gst_video_convert_get_type (void);
|
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-06-15 15:49:21 +00:00
|
|
|
static gboolean gst_video_convert_set_caps (GstBaseTransform * btrans,
|
2010-09-13 19:48:50 +00:00
|
|
|
GstCaps * incaps, GstCaps * outcaps);
|
2011-12-01 14:47:16 +00:00
|
|
|
static gboolean gst_video_convert_transform_size (GstBaseTransform * btrans,
|
|
|
|
GstPadDirection direction, GstCaps * caps, gsize size,
|
|
|
|
GstCaps * othercaps, gsize * othersize);
|
2011-06-15 15:49:21 +00:00
|
|
|
static GstFlowReturn gst_video_convert_transform (GstBaseTransform * btrans,
|
2010-09-13 19:48:50 +00:00
|
|
|
GstBuffer * inbuf, GstBuffer * outbuf);
|
2004-01-15 08:58:22 +00:00
|
|
|
|
2011-02-21 06:43:56 +00:00
|
|
|
static GType
|
|
|
|
dither_method_get_type (void)
|
|
|
|
{
|
|
|
|
static GType gtype = 0;
|
|
|
|
|
|
|
|
if (gtype == 0) {
|
|
|
|
static const GEnumValue values[] = {
|
|
|
|
{DITHER_NONE, "No dithering (default)", "none"},
|
|
|
|
{DITHER_VERTERR, "Vertical error propogation", "verterr"},
|
|
|
|
{DITHER_HALFTONE, "Half-tone", "halftone"},
|
|
|
|
{0, NULL, NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
gtype = g_enum_register_static ("GstColorspaceDitherMethod", values);
|
|
|
|
}
|
|
|
|
return gtype;
|
|
|
|
}
|
|
|
|
|
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;
|
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);
|
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 */
|
2011-06-16 10:48:33 +00:00
|
|
|
if (i > 0 && gst_caps_is_subset_structure (res, st))
|
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);
|
|
|
|
gst_structure_remove_fields (st, "format", "palette_data",
|
2011-08-23 16:57:35 +00:00
|
|
|
"colorimetry", "chroma-site", NULL);
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2011-06-16 10:48:33 +00:00
|
|
|
gst_caps_append_structure (res, st);
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2011-12-21 17:58:42 +00:00
|
|
|
/* Answer the allocation query downstream. This is only called for
|
|
|
|
* non-passthrough cases */
|
|
|
|
static gboolean
|
|
|
|
gst_video_convert_propose_allocation (GstBaseTransform * trans,
|
|
|
|
GstQuery * query)
|
|
|
|
{
|
|
|
|
GstVideoConvert *space = GST_VIDEO_CONVERT_CAST (trans);
|
|
|
|
GstBufferPool *pool;
|
|
|
|
GstCaps *caps;
|
|
|
|
gboolean need_pool;
|
|
|
|
guint size;
|
|
|
|
|
|
|
|
gst_query_parse_allocation (query, &caps, &need_pool);
|
|
|
|
|
|
|
|
size = GST_VIDEO_INFO_SIZE (&space->from_info);
|
|
|
|
|
|
|
|
if (need_pool) {
|
|
|
|
GstStructure *structure;
|
|
|
|
|
|
|
|
pool = gst_video_buffer_pool_new ();
|
|
|
|
|
|
|
|
structure = gst_buffer_pool_get_config (pool);
|
|
|
|
gst_buffer_pool_config_set (structure, caps, size, 0, 0, 0, 15);
|
|
|
|
if (!gst_buffer_pool_set_config (pool, structure))
|
|
|
|
goto config_failed;
|
|
|
|
} else
|
|
|
|
pool = NULL;
|
|
|
|
|
|
|
|
gst_query_set_allocation_params (query, size, 0, 0, 0, 15, pool);
|
|
|
|
gst_object_unref (pool);
|
|
|
|
|
|
|
|
gst_query_add_allocation_meta (query, GST_VIDEO_META_API);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
config_failed:
|
|
|
|
{
|
|
|
|
GST_ERROR_OBJECT (space, "failed to set config.");
|
|
|
|
gst_object_unref (pool);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* configure the allocation query that was answered downstream, we can configure
|
|
|
|
* some properties on it. Only called in passthrough mode. */
|
2011-06-20 15:34:57 +00:00
|
|
|
static gboolean
|
2011-08-26 12:20:30 +00:00
|
|
|
gst_video_convert_decide_allocation (GstBaseTransform * trans, GstQuery * query)
|
2011-06-20 15:34:57 +00:00
|
|
|
{
|
|
|
|
GstBufferPool *pool = NULL;
|
|
|
|
guint size, min, max, prefix, alignment;
|
|
|
|
|
|
|
|
gst_query_parse_allocation_params (query, &size, &min, &max, &prefix,
|
|
|
|
&alignment, &pool);
|
|
|
|
|
|
|
|
if (pool) {
|
|
|
|
GstStructure *config;
|
|
|
|
|
|
|
|
config = gst_buffer_pool_get_config (pool);
|
2011-07-29 15:15:39 +00:00
|
|
|
gst_buffer_pool_config_add_option (config,
|
2011-10-31 01:23:21 +00:00
|
|
|
GST_BUFFER_POOL_OPTION_VIDEO_META);
|
2011-06-20 15:34:57 +00:00
|
|
|
gst_buffer_pool_set_config (pool, config);
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-09-13 19:48:50 +00:00
|
|
|
static gboolean
|
2011-06-15 15:49:21 +00:00
|
|
|
gst_video_convert_set_caps (GstBaseTransform * btrans, GstCaps * incaps,
|
2010-09-13 19:48:50 +00:00
|
|
|
GstCaps * outcaps)
|
2004-01-15 08:58:22 +00:00
|
|
|
{
|
2011-06-15 15:49:21 +00:00
|
|
|
GstVideoConvert *space;
|
2011-06-17 07:21:27 +00:00
|
|
|
GstVideoInfo in_info;
|
|
|
|
GstVideoInfo out_info;
|
2010-10-31 21:39:38 +00:00
|
|
|
ColorSpaceColorSpec in_spec, out_spec;
|
2011-06-17 13:31:59 +00:00
|
|
|
gboolean interlaced;
|
2004-01-15 08:58:22 +00:00
|
|
|
|
2011-06-15 15:49:21 +00:00
|
|
|
space = GST_VIDEO_CONVERT_CAST (btrans);
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2011-02-19 21:13:13 +00:00
|
|
|
if (space->convert) {
|
2011-06-15 15:49:21 +00:00
|
|
|
videoconvert_convert_free (space->convert);
|
2011-02-19 21:13:13 +00:00
|
|
|
}
|
|
|
|
|
2010-09-13 19:48:50 +00:00
|
|
|
/* input caps */
|
2011-06-20 15:34:57 +00:00
|
|
|
if (!gst_video_info_from_caps (&in_info, incaps))
|
2011-06-17 07:21:27 +00:00
|
|
|
goto invalid_caps;
|
2004-01-15 08:58:22 +00:00
|
|
|
|
2011-07-04 08:19:13 +00:00
|
|
|
if (in_info.finfo->flags & GST_VIDEO_FORMAT_FLAG_RGB) {
|
2010-10-31 21:39:38 +00:00
|
|
|
in_spec = COLOR_SPEC_RGB;
|
2011-07-04 08:19:13 +00:00
|
|
|
} else if (in_info.finfo->flags & GST_VIDEO_FORMAT_FLAG_YUV) {
|
2011-08-23 16:57:35 +00:00
|
|
|
if (in_info.colorimetry.matrix == GST_VIDEO_COLOR_MATRIX_BT709)
|
2010-10-31 21:39:38 +00:00
|
|
|
in_spec = COLOR_SPEC_YUV_BT709;
|
|
|
|
else
|
|
|
|
in_spec = COLOR_SPEC_YUV_BT470_6;
|
|
|
|
} else {
|
|
|
|
in_spec = COLOR_SPEC_GRAY;
|
|
|
|
}
|
2004-01-15 08:58:22 +00:00
|
|
|
|
2010-09-13 19:48:50 +00:00
|
|
|
/* output caps */
|
2011-06-20 15:34:57 +00:00
|
|
|
if (!gst_video_info_from_caps (&out_info, outcaps))
|
2011-06-17 07:21:27 +00:00
|
|
|
goto invalid_caps;
|
2004-01-15 08:58:22 +00:00
|
|
|
|
2011-07-04 08:19:13 +00:00
|
|
|
if (out_info.finfo->flags & GST_VIDEO_FORMAT_FLAG_RGB) {
|
2010-10-31 21:39:38 +00:00
|
|
|
out_spec = COLOR_SPEC_RGB;
|
2011-07-04 08:19:13 +00:00
|
|
|
} else if (out_info.finfo->flags & GST_VIDEO_FORMAT_FLAG_YUV) {
|
2011-08-23 16:57:35 +00:00
|
|
|
if (out_info.colorimetry.matrix == GST_VIDEO_COLOR_MATRIX_BT709)
|
2010-10-31 21:39:38 +00:00
|
|
|
out_spec = COLOR_SPEC_YUV_BT709;
|
|
|
|
else
|
|
|
|
out_spec = COLOR_SPEC_YUV_BT470_6;
|
|
|
|
} else {
|
|
|
|
out_spec = COLOR_SPEC_GRAY;
|
|
|
|
}
|
2004-01-15 08:58:22 +00:00
|
|
|
|
2010-09-13 19:48:50 +00:00
|
|
|
/* these must match */
|
2011-06-17 07:21:27 +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-06-17 07:21:27 +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 */
|
2011-06-17 07:21:27 +00:00
|
|
|
if ((in_info.flags & GST_VIDEO_FLAG_INTERLACED) !=
|
|
|
|
(out_info.flags & GST_VIDEO_FLAG_INTERLACED))
|
2010-09-13 19:48:50 +00:00
|
|
|
goto format_mismatch;
|
2004-01-15 08:58:22 +00:00
|
|
|
|
2011-06-17 07:21:27 +00:00
|
|
|
space->from_info = in_info;
|
2010-10-31 21:39:38 +00:00
|
|
|
space->from_spec = in_spec;
|
2011-06-17 07:21:27 +00:00
|
|
|
space->to_info = out_info;
|
2010-10-31 21:39:38 +00:00
|
|
|
space->to_spec = out_spec;
|
2011-06-17 13:31:59 +00:00
|
|
|
|
|
|
|
interlaced = (in_info.flags & GST_VIDEO_FLAG_INTERLACED) != 0;
|
2004-01-15 08:58:22 +00:00
|
|
|
|
2011-06-17 07:21:27 +00:00
|
|
|
space->convert =
|
2011-07-04 08:19:13 +00:00
|
|
|
videoconvert_convert_new (GST_VIDEO_INFO_FORMAT (&out_info), out_spec,
|
|
|
|
GST_VIDEO_INFO_FORMAT (&in_info), in_spec, in_info.width, in_info.height);
|
2011-06-17 13:31:59 +00:00
|
|
|
if (space->convert == NULL)
|
|
|
|
goto no_convert;
|
|
|
|
|
|
|
|
videoconvert_convert_set_interlaced (space->convert, interlaced);
|
|
|
|
|
2010-09-13 19:48:50 +00:00
|
|
|
/* palette, only for from data */
|
2011-07-04 08:19:13 +00:00
|
|
|
if (GST_VIDEO_INFO_FORMAT (&space->from_info) ==
|
|
|
|
GST_VIDEO_FORMAT_RGB8_PALETTED
|
|
|
|
&& GST_VIDEO_INFO_FORMAT (&space->to_info) ==
|
|
|
|
GST_VIDEO_FORMAT_RGB8_PALETTED) {
|
2010-11-02 15:05:37 +00:00
|
|
|
goto format_mismatch;
|
2011-07-04 08:19:13 +00:00
|
|
|
} else if (GST_VIDEO_INFO_FORMAT (&space->from_info) ==
|
|
|
|
GST_VIDEO_FORMAT_RGB8_PALETTED) {
|
2010-11-02 15:05:37 +00:00
|
|
|
GstBuffer *palette;
|
2011-06-15 14:28:44 +00:00
|
|
|
guint32 *data;
|
2010-11-02 15:05:37 +00:00
|
|
|
|
|
|
|
palette = gst_video_parse_caps_palette (incaps);
|
|
|
|
|
2011-06-15 14:28:44 +00:00
|
|
|
if (!palette || gst_buffer_get_size (palette) < 256 * 4) {
|
2010-11-02 15:05:37 +00:00
|
|
|
if (palette)
|
|
|
|
gst_buffer_unref (palette);
|
|
|
|
goto invalid_palette;
|
|
|
|
}
|
2011-06-15 14:28:44 +00:00
|
|
|
|
|
|
|
data = gst_buffer_map (palette, NULL, NULL, GST_MAP_READ);
|
2011-06-15 15:49:21 +00:00
|
|
|
videoconvert_convert_set_palette (space->convert, data);
|
2011-06-15 14:28:44 +00:00
|
|
|
gst_buffer_unmap (palette, data, -1);
|
|
|
|
|
2010-11-02 15:05:37 +00:00
|
|
|
gst_buffer_unref (palette);
|
2011-07-04 08:19:13 +00:00
|
|
|
} else if (GST_VIDEO_INFO_FORMAT (&space->to_info) ==
|
|
|
|
GST_VIDEO_FORMAT_RGB8_PALETTED) {
|
2010-11-02 15:05:37 +00:00
|
|
|
const guint32 *palette;
|
|
|
|
GstBuffer *p_buf;
|
|
|
|
|
2011-06-15 15:49:21 +00:00
|
|
|
palette = videoconvert_convert_get_palette (space->convert);
|
2011-06-15 14:28:44 +00:00
|
|
|
|
2010-11-02 15:05:37 +00:00
|
|
|
p_buf = gst_buffer_new_and_alloc (256 * 4);
|
2011-06-15 14:28:44 +00:00
|
|
|
gst_buffer_fill (p_buf, 0, palette, 256 * 4);
|
2010-11-02 15:05:37 +00:00
|
|
|
gst_caps_set_simple (outcaps, "palette_data", GST_TYPE_BUFFER, p_buf, NULL);
|
|
|
|
gst_buffer_unref (p_buf);
|
|
|
|
}
|
2004-01-15 08:58:22 +00:00
|
|
|
|
2011-07-04 08:19:13 +00:00
|
|
|
GST_DEBUG ("reconfigured %d %d", GST_VIDEO_INFO_FORMAT (&space->from_info),
|
|
|
|
GST_VIDEO_INFO_FORMAT (&space->to_info));
|
|
|
|
|
|
|
|
space->negotiated = TRUE;
|
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 */
|
2011-06-17 07:21:27 +00:00
|
|
|
invalid_caps:
|
2010-09-13 19:48:50 +00:00
|
|
|
{
|
2011-06-17 07:21:27 +00:00
|
|
|
GST_ERROR_OBJECT (space, "invalid caps");
|
2011-07-04 08:19:13 +00:00
|
|
|
goto error_done;
|
2004-01-15 08:58:22 +00:00
|
|
|
}
|
2010-09-13 19:48:50 +00:00
|
|
|
format_mismatch:
|
|
|
|
{
|
2010-09-14 01:49:43 +00:00
|
|
|
GST_ERROR_OBJECT (space, "input and output formats do not match");
|
2011-07-04 08:19:13 +00:00
|
|
|
goto error_done;
|
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-07-04 08:19:13 +00:00
|
|
|
goto error_done;
|
2011-06-17 13:31:59 +00:00
|
|
|
}
|
2010-11-02 15:05:37 +00:00
|
|
|
invalid_palette:
|
|
|
|
{
|
|
|
|
GST_ERROR_OBJECT (space, "invalid palette");
|
2011-07-04 08:19:13 +00:00
|
|
|
goto error_done;
|
|
|
|
}
|
|
|
|
error_done:
|
|
|
|
{
|
|
|
|
space->negotiated = FALSE;
|
2010-11-02 15:05:37 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2004-01-15 08:58:22 +00:00
|
|
|
}
|
|
|
|
|
2011-06-15 15:49:21 +00:00
|
|
|
#define gst_video_convert_parent_class parent_class
|
|
|
|
G_DEFINE_TYPE (GstVideoConvert, gst_video_convert, GST_TYPE_VIDEO_FILTER);
|
2011-02-21 06:43:56 +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) {
|
2011-06-15 15:49:21 +00:00
|
|
|
videoconvert_convert_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;
|
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
|
|
|
|
|
|
|
gst_element_class_set_details_simple (gstelement_class,
|
|
|
|
" Colorspace converter", "Filter/Converter/Video",
|
|
|
|
"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);
|
|
|
|
gstbasetransform_class->set_caps =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_video_convert_set_caps);
|
2011-12-01 14:47:16 +00:00
|
|
|
gstbasetransform_class->transform_size =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_video_convert_transform_size);
|
2011-12-21 17:58:42 +00:00
|
|
|
gstbasetransform_class->propose_allocation =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_video_convert_propose_allocation);
|
2011-08-26 12:20:30 +00:00
|
|
|
gstbasetransform_class->decide_allocation =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_video_convert_decide_allocation);
|
2011-06-15 15:49:21 +00:00
|
|
|
gstbasetransform_class->transform =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_video_convert_transform);
|
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
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, PROP_DITHER,
|
|
|
|
g_param_spec_enum ("dither", "Dither", "Apply dithering while converting",
|
|
|
|
dither_method_get_type (), DITHER_NONE,
|
|
|
|
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
|
|
|
{
|
2011-07-04 08:19:13 +00:00
|
|
|
space->negotiated = FALSE;
|
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;
|
|
|
|
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;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-13 19:48:50 +00:00
|
|
|
static gboolean
|
2011-12-01 14:47:16 +00:00
|
|
|
gst_video_convert_transform_size (GstBaseTransform * btrans,
|
|
|
|
GstPadDirection direction, GstCaps * caps, gsize size,
|
|
|
|
GstCaps * othercaps, gsize * othersize)
|
2004-01-15 08:58:22 +00:00
|
|
|
{
|
2010-09-13 19:48:50 +00:00
|
|
|
gboolean ret = TRUE;
|
2011-06-17 07:21:27 +00:00
|
|
|
GstVideoInfo info;
|
2004-01-15 08:58:22 +00:00
|
|
|
|
2010-09-13 19:48:50 +00:00
|
|
|
g_assert (size);
|
2004-01-15 08:58:22 +00:00
|
|
|
|
2011-12-01 14:47:16 +00:00
|
|
|
ret = gst_video_info_from_caps (&info, othercaps);
|
|
|
|
if (ret)
|
|
|
|
*othersize = info.size;
|
2004-01-15 08:58:22 +00:00
|
|
|
|
2010-09-13 19:48:50 +00:00
|
|
|
return ret;
|
2004-01-15 08:58:22 +00:00
|
|
|
}
|
|
|
|
|
2010-09-13 19:48:50 +00:00
|
|
|
static GstFlowReturn
|
2011-06-15 15:49:21 +00:00
|
|
|
gst_video_convert_transform (GstBaseTransform * btrans, GstBuffer * inbuf,
|
2010-09-13 19:48:50 +00:00
|
|
|
GstBuffer * outbuf)
|
2004-01-15 08:58:22 +00:00
|
|
|
{
|
2011-06-15 15:49:21 +00:00
|
|
|
GstVideoConvert *space;
|
2011-06-17 13:31:59 +00:00
|
|
|
GstVideoFrame in_frame, out_frame;
|
2004-01-15 08:58:22 +00:00
|
|
|
|
2011-06-15 15:49:21 +00:00
|
|
|
space = GST_VIDEO_CONVERT_CAST (btrans);
|
2004-01-15 08:58:22 +00:00
|
|
|
|
2011-07-04 08:19:13 +00:00
|
|
|
GST_DEBUG ("from %s -> to %s", GST_VIDEO_INFO_NAME (&space->from_info),
|
|
|
|
GST_VIDEO_INFO_NAME (&space->to_info));
|
2004-01-15 08:58:22 +00:00
|
|
|
|
2011-07-04 08:19:13 +00:00
|
|
|
if (G_UNLIKELY (!space->negotiated))
|
2010-09-13 19:48:50 +00:00
|
|
|
goto unknown_format;
|
2004-01-15 08:58:22 +00:00
|
|
|
|
2011-06-15 15:49:21 +00:00
|
|
|
videoconvert_convert_set_dither (space->convert, space->dither);
|
2011-02-21 06:43:56 +00:00
|
|
|
|
2011-06-17 13:31:59 +00:00
|
|
|
if (!gst_video_frame_map (&in_frame, &space->from_info, inbuf, GST_MAP_READ))
|
|
|
|
goto invalid_buffer;
|
2011-06-15 14:28:44 +00:00
|
|
|
|
2011-06-17 13:31:59 +00:00
|
|
|
if (!gst_video_frame_map (&out_frame, &space->to_info, outbuf, GST_MAP_WRITE))
|
|
|
|
goto invalid_buffer;
|
2011-06-17 07:21:27 +00:00
|
|
|
|
2011-06-17 13:31:59 +00:00
|
|
|
videoconvert_convert_convert (space->convert, &out_frame, &in_frame);
|
2011-06-17 07:21:27 +00:00
|
|
|
|
2011-06-17 13:31:59 +00:00
|
|
|
gst_video_frame_unmap (&out_frame);
|
|
|
|
gst_video_frame_unmap (&in_frame);
|
2004-01-15 08:58:22 +00:00
|
|
|
|
2010-09-13 19:48:50 +00:00
|
|
|
/* baseclass copies timestamps */
|
2011-07-04 08:19:13 +00:00
|
|
|
GST_DEBUG ("from %s -> to %s done", GST_VIDEO_INFO_NAME (&space->from_info),
|
|
|
|
GST_VIDEO_INFO_NAME (&space->to_info));
|
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
|
|
|
|
2010-09-13 19:48:50 +00:00
|
|
|
/* ERRORS */
|
|
|
|
unknown_format:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (space, CORE, NOT_IMPLEMENTED, (NULL),
|
|
|
|
("attempting to convert colorspaces between unknown formats"));
|
|
|
|
return GST_FLOW_NOT_NEGOTIATED;
|
2004-01-15 08:58:22 +00:00
|
|
|
}
|
2011-06-17 13:31:59 +00:00
|
|
|
invalid_buffer:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_WARNING (space, CORE, NOT_IMPLEMENTED, (NULL),
|
|
|
|
("invalid video buffer received"));
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
2010-09-13 19:48:50 +00:00
|
|
|
#if 0
|
|
|
|
not_supported:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (space, CORE, NOT_IMPLEMENTED, (NULL),
|
|
|
|
("cannot convert between formats"));
|
|
|
|
return GST_FLOW_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
#endif
|
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");
|
2011-06-15 15:49:21 +00:00
|
|
|
GST_DEBUG_CATEGORY_GET (videoconvert_performance, "GST_PERFORMANCE");
|
2004-01-15 08:58:22 +00:00
|
|
|
|
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,
|
2011-06-15 15:49:21 +00:00
|
|
|
"videoconvert", "Colorspace conversion", plugin_init, VERSION, "LGPL", "",
|
|
|
|
"")
|