2010-12-15 20:14:38 +00:00
|
|
|
/* GStreamer
|
2021-05-20 22:50:46 +00:00
|
|
|
* Copyright 2010 ST-Ericsson SA
|
2010-12-15 20:14:38 +00:00
|
|
|
* @author: Benjamin Gaignard <benjamin.gaignard@stericsson.com>
|
2023-03-31 16:28:09 +00:00
|
|
|
* Copyright 2023 Igalia S.L.
|
|
|
|
* @author: Thibault Saunier <tsaunier@igalia.com>
|
2021-05-20 22:50:46 +00:00
|
|
|
*
|
2010-12-15 20:14:38 +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 20:38:00 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2010-12-15 20:14:38 +00:00
|
|
|
*/
|
|
|
|
/*
|
2010-12-16 08:56:00 +00:00
|
|
|
* test autovideoconvert:
|
2010-12-15 20:14:38 +00:00
|
|
|
* if rgb2bayer is present
|
2015-12-14 02:09:46 +00:00
|
|
|
* gst-launch-1.0 videotestsrc num-buffers=2 ! "video/x-raw,width=100,height=100,framerate=10/1" ! autovideoconvert ! "video/x-bayer,width=100,height=100,format=bggr,framerate=10/1" ! fakesink -v
|
2010-12-15 20:14:38 +00:00
|
|
|
* if bayer2rgb is present
|
2015-12-14 02:09:46 +00:00
|
|
|
* gst-launch-1.0 videotestsrc num-buffers=2 ! "video/x-bayer,width=100,height=100,format=bggr,framerate=10/1" ! autovideoconvert ! "video/x-raw,width=100,height=100,framerate=10/1" ! fakesink -v
|
2012-09-14 14:29:23 +00:00
|
|
|
* test with videoconvert
|
2015-12-14 02:09:46 +00:00
|
|
|
* gst-launch-1.0 videotestsrc num-buffers=2 ! "video/x-raw,format=RGBx,width=100,height=100,framerate=10/1" ! autovideoconvert ! "video/x-raw,format=RGB16,width=100,height=100,framerate=10/1" ! fakesink -v
|
2010-12-15 20:14:38 +00:00
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
2010-12-16 08:56:00 +00:00
|
|
|
#include "gstautovideoconvert.h"
|
2023-03-31 20:14:19 +00:00
|
|
|
#include "gstautovideo.h"
|
2010-12-15 20:14:38 +00:00
|
|
|
|
2010-12-16 08:56:00 +00:00
|
|
|
GST_DEBUG_CATEGORY (autovideoconvert_debug);
|
|
|
|
#define GST_CAT_DEFAULT (autovideoconvert_debug)
|
2010-12-15 20:14:38 +00:00
|
|
|
|
2021-05-20 22:50:46 +00:00
|
|
|
struct _GstAutoVideoConvert
|
|
|
|
{
|
2023-03-31 16:28:09 +00:00
|
|
|
GstBaseAutoConvert parent;
|
2021-05-20 22:50:46 +00:00
|
|
|
};
|
2010-12-15 20:14:38 +00:00
|
|
|
|
2021-05-20 22:50:46 +00:00
|
|
|
G_DEFINE_TYPE (GstAutoVideoConvert, gst_auto_video_convert,
|
2023-03-31 16:28:09 +00:00
|
|
|
GST_TYPE_BASE_AUTO_CONVERT);
|
2010-12-15 20:14:38 +00:00
|
|
|
|
2021-05-20 22:50:46 +00:00
|
|
|
GST_ELEMENT_REGISTER_DEFINE (autovideoconvert, "autovideoconvert",
|
|
|
|
GST_RANK_NONE, gst_auto_video_convert_get_type ());
|
2010-12-15 20:14:38 +00:00
|
|
|
|
2022-03-28 17:09:56 +00:00
|
|
|
static void
|
2023-03-31 16:28:09 +00:00
|
|
|
gst_auto_video_convert_class_init (GstAutoVideoConvertClass * klass)
|
2022-03-28 17:09:56 +00:00
|
|
|
{
|
2023-03-31 16:28:09 +00:00
|
|
|
GstElementClass *gstelement_class = (GstElementClass *) klass;
|
2022-03-28 17:09:56 +00:00
|
|
|
|
2023-03-31 16:28:09 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT (autovideoconvert_debug, "autovideoconvert", 0,
|
|
|
|
"Auto color space converter");
|
2022-03-28 17:09:56 +00:00
|
|
|
|
2023-03-31 16:28:09 +00:00
|
|
|
gst_element_class_set_static_metadata (gstelement_class,
|
|
|
|
"Select color space converter and scalers based on caps",
|
|
|
|
"Bin/Colorspace/Scale/Video/Converter",
|
|
|
|
"Selects the right color space converter based on the caps",
|
2022-03-28 17:09:56 +00:00
|
|
|
"Thibault Saunier <tsaunier@igalia.com>");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2023-03-31 16:28:09 +00:00
|
|
|
gst_auto_video_convert_init (GstAutoVideoConvert * autovideoconvert)
|
2022-03-28 17:09:56 +00:00
|
|
|
{
|
|
|
|
/* *INDENT-OFF* */
|
2023-03-31 16:28:09 +00:00
|
|
|
static const GstAutoVideoFilterGenerator gen[] = {
|
2022-03-28 17:09:56 +00:00
|
|
|
{
|
2023-03-31 16:28:09 +00:00
|
|
|
.first_elements = { "bayer2rgb", NULL},
|
|
|
|
.colorspace_converters = { "videoconvertscale", NULL },
|
|
|
|
.last_elements = { NULL } ,
|
|
|
|
.filters = { NULL},
|
2022-03-28 17:09:56 +00:00
|
|
|
.rank = GST_RANK_SECONDARY,
|
|
|
|
},
|
|
|
|
{
|
2023-03-31 16:28:09 +00:00
|
|
|
.first_elements = { NULL, },
|
|
|
|
.colorspace_converters = { "videoconvertscale", NULL },
|
|
|
|
.last_elements = { "rgb2bayer", NULL },
|
|
|
|
.filters = { NULL },
|
2022-03-28 17:09:56 +00:00
|
|
|
.rank = GST_RANK_SECONDARY,
|
|
|
|
},
|
|
|
|
{
|
2023-03-31 16:28:09 +00:00
|
|
|
.first_elements = { NULL, },
|
|
|
|
.colorspace_converters = { "videoconvertscale", NULL },
|
|
|
|
.last_elements = { NULL, },
|
|
|
|
.filters = { NULL },
|
|
|
|
.rank = GST_RANK_SECONDARY,
|
2022-03-28 17:09:56 +00:00
|
|
|
},
|
|
|
|
{
|
2023-03-31 16:28:09 +00:00
|
|
|
.first_elements = { NULL, },
|
|
|
|
.colorspace_converters = { "glcolorconvert", "glcolorscale", "glcolorconvert", NULL },
|
|
|
|
.last_elements = { NULL, },
|
|
|
|
.filters = { NULL },
|
|
|
|
.rank = GST_RANK_PRIMARY,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.first_elements = { "glupload", },
|
|
|
|
.colorspace_converters = { "glcolorconvert", "glcolorscale", "glcolorconvert", NULL },
|
|
|
|
.last_elements = { NULL, },
|
|
|
|
.filters = { NULL },
|
|
|
|
.rank = GST_RANK_PRIMARY,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.first_elements = { "videoconvertscale", "glupload", NULL },
|
|
|
|
.colorspace_converters = { NULL },
|
|
|
|
.last_elements = { NULL },
|
|
|
|
.filters = { NULL },
|
|
|
|
.rank = GST_RANK_MARGINAL + 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.first_elements = { "glcolorconvert", "gldownload", NULL },
|
|
|
|
.colorspace_converters = { NULL },
|
|
|
|
.last_elements = { NULL },
|
|
|
|
.filters = { NULL },
|
|
|
|
.rank = GST_RANK_MARGINAL + 2,
|
|
|
|
},
|
|
|
|
{ /* Worst case we upload/download as required */
|
|
|
|
.first_elements = { "glupload", "gldownload", NULL },
|
|
|
|
.colorspace_converters = { "glcolorconvert", "glcolorscale", "glcolorconvert", NULL },
|
|
|
|
.last_elements = { "glupload", "gldownload", NULL },
|
|
|
|
.filters = { NULL },
|
|
|
|
.rank = GST_RANK_MARGINAL + 1,
|
|
|
|
},
|
|
|
|
{ /* Pure cuda is preferred */
|
|
|
|
.first_elements = { NULL },
|
|
|
|
.colorspace_converters = { "cudaconvertscale", NULL },
|
|
|
|
.last_elements = { NULL },
|
|
|
|
.filters = { NULL },
|
|
|
|
.rank = GST_RANK_PRIMARY,
|
|
|
|
},
|
2023-04-28 22:33:26 +00:00
|
|
|
{ /* FIXME: Generically make it so we go through cudaconvert for formats not supported by `glcolorconvert` */
|
|
|
|
.first_elements = { "capsfilter caps=video/x-raw(ANY),format={I420_10LE,I422_10LE,I422_12LE}", "cudaupload", NULL },
|
|
|
|
.colorspace_converters = { "cudaconvert", NULL },
|
|
|
|
.last_elements = { "cudadownload", "capsfilter caps=video/x-raw(memory:GLMemory)", NULL },
|
|
|
|
.filters = { NULL },
|
|
|
|
.rank = GST_RANK_SECONDARY + 2,
|
|
|
|
},
|
2023-03-31 16:28:09 +00:00
|
|
|
{ /* CUDA -> GL */
|
|
|
|
.first_elements = { "capsfilter caps=video/x-raw(memory:CUDAMemory)", "cudadownload", NULL },
|
|
|
|
.colorspace_converters = { "glcolorconvert", "glcolorscale", "glcolorconvert", NULL },
|
|
|
|
.last_elements = { "glupload", "gldownload", NULL },
|
|
|
|
.filters = { NULL },
|
2022-03-28 17:09:56 +00:00
|
|
|
.rank = GST_RANK_SECONDARY,
|
|
|
|
},
|
2023-03-31 16:28:09 +00:00
|
|
|
{ /* GL memory to cuda */
|
|
|
|
.first_elements = { NULL },
|
|
|
|
.colorspace_converters = { "glcolorconvert", "glcolorscale", "glcolorconvert", NULL },
|
|
|
|
.last_elements = { "cudaupload", "capsfilter caps=video/x-raw(memory:CUDAMemory)", NULL },
|
|
|
|
.filters = { NULL },
|
|
|
|
.rank = GST_RANK_MARGINAL,
|
|
|
|
},
|
|
|
|
{ /* System memory to cuda */
|
|
|
|
.first_elements = { NULL },
|
|
|
|
.colorspace_converters = { "videoconvertscale", NULL },
|
|
|
|
.last_elements = { "cudaupload", "capsfilter caps=video/x-raw(memory:CUDAMemory)", NULL },
|
|
|
|
.filters = { NULL },
|
|
|
|
.rank = GST_RANK_MARGINAL,
|
|
|
|
},
|
2022-03-28 17:09:56 +00:00
|
|
|
{
|
2023-03-31 16:28:09 +00:00
|
|
|
.first_elements = { NULL, },
|
|
|
|
.colorspace_converters = { "d3d11convert", NULL },
|
|
|
|
.last_elements = { NULL, },
|
|
|
|
.filters = { NULL },
|
2022-03-28 17:09:56 +00:00
|
|
|
.rank = GST_RANK_PRIMARY,
|
|
|
|
},
|
2023-03-31 16:28:09 +00:00
|
|
|
{
|
|
|
|
.first_elements = { "d3d11download", "d3d11upload", NULL},
|
|
|
|
.colorspace_converters = { "glcolorconvert", "glcolorscale", "glcolorconvert", NULL },
|
|
|
|
.last_elements = { "d3d11download", "d3d11upload", NULL },
|
|
|
|
.filters = { NULL },
|
|
|
|
.rank = GST_RANK_MARGINAL,
|
|
|
|
},
|
|
|
|
{ /* Worst case we upload/download as required */
|
|
|
|
.first_elements = { NULL},
|
|
|
|
.colorspace_converters = { NULL },
|
|
|
|
.last_elements = { NULL },
|
|
|
|
.filters = { NULL },
|
|
|
|
.rank = 0,
|
|
|
|
},
|
2022-03-28 17:09:56 +00:00
|
|
|
};
|
|
|
|
/* *INDENT-ON* */
|
|
|
|
|
2010-12-15 20:14:38 +00:00
|
|
|
|
2023-03-31 16:28:09 +00:00
|
|
|
gst_auto_video_register_well_known_bins (GST_BASE_AUTO_CONVERT
|
|
|
|
(autovideoconvert), gen);
|
2010-12-15 20:14:38 +00:00
|
|
|
}
|