mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-18 14:26:43 +00:00
videomixer: Add support for ARGB
And clean up the caps parsing.
This commit is contained in:
parent
abd383a2a6
commit
69f9b7c8d6
3 changed files with 155 additions and 142 deletions
|
@ -1,8 +1,8 @@
|
||||||
plugin_LTLIBRARIES = libgstvideomixer.la
|
plugin_LTLIBRARIES = libgstvideomixer.la
|
||||||
|
|
||||||
libgstvideomixer_la_SOURCES = videomixer.c blend_ayuv.c blend_bgra.c blend_i420.c
|
libgstvideomixer_la_SOURCES = videomixer.c blend_ayuv.c blend_bgra.c blend_i420.c
|
||||||
libgstvideomixer_la_CFLAGS = $(GST_CFLAGS) $(GST_BASE_CFLAGS) $(GST_CONTROLLER_CFLAGS) $(GST_PLUGINS_BASE_CFLAGS)
|
libgstvideomixer_la_CFLAGS = $(GST_CFLAGS) $(GST_BASE_CFLAGS) $(GST_CONTROLLER_CFLAGS) $(GST_PLUGINS_BASE_CFLAGS)
|
||||||
libgstvideomixer_la_LIBADD = $(GST_LIBS) $(GST_BASE_LIBS) $(GST_CONTROLLER_LIBS)
|
libgstvideomixer_la_LIBADD = $(GST_LIBS) $(GST_BASE_LIBS) $(GST_CONTROLLER_LIBS) $(GST_PLUGINS_BASE_CFLAGS) -lgstvideo-@GST_MAJORMINOR@
|
||||||
libgstvideomixer_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
|
libgstvideomixer_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
|
||||||
libgstvideomixer_la_LIBTOOLFLAGS = --tag=disable-static
|
libgstvideomixer_la_LIBTOOLFLAGS = --tag=disable-static
|
||||||
|
|
||||||
|
|
|
@ -26,109 +26,115 @@
|
||||||
|
|
||||||
#define BLEND_MODE BLEND_NORMAL
|
#define BLEND_MODE BLEND_NORMAL
|
||||||
|
|
||||||
void
|
#define CREATE_FUNCTIONS(name, a, r, g, b) \
|
||||||
gst_videomixer_blend_bgra_bgra (guint8 * src, gint xpos, gint ypos,
|
void \
|
||||||
gint src_width, gint src_height, gdouble src_alpha,
|
gst_videomixer_blend_##name##_##name (guint8 * src, gint xpos, gint ypos, \
|
||||||
guint8 * dest, gint dest_width, gint dest_height)
|
gint src_width, gint src_height, gdouble src_alpha, \
|
||||||
{
|
guint8 * dest, gint dest_width, gint dest_height) \
|
||||||
gint alpha, b_alpha;
|
{ \
|
||||||
gint i, j;
|
gint alpha, b_alpha; \
|
||||||
gint src_stride, dest_stride;
|
gint i, j; \
|
||||||
gint src_add, dest_add;
|
gint src_stride, dest_stride; \
|
||||||
gint B, G, R;
|
gint src_add, dest_add; \
|
||||||
|
gint B, G, R; \
|
||||||
src_stride = src_width * 4;
|
\
|
||||||
dest_stride = dest_width * 4;
|
src_stride = src_width * 4; \
|
||||||
|
dest_stride = dest_width * 4; \
|
||||||
b_alpha = (gint) (src_alpha * 255);
|
\
|
||||||
|
b_alpha = (gint) (src_alpha * 255); \
|
||||||
/* adjust src pointers for negative sizes */
|
\
|
||||||
if (xpos < 0) {
|
/* adjust src pointers for negative sizes */ \
|
||||||
src += -xpos * 4;
|
if (xpos < 0) { \
|
||||||
src_width -= -xpos;
|
src += -xpos * 4; \
|
||||||
xpos = 0;
|
src_width -= -xpos; \
|
||||||
}
|
xpos = 0; \
|
||||||
if (ypos < 0) {
|
} \
|
||||||
src += -ypos * src_stride;
|
if (ypos < 0) { \
|
||||||
src_height -= -ypos;
|
src += -ypos * src_stride; \
|
||||||
ypos = 0;
|
src_height -= -ypos; \
|
||||||
}
|
ypos = 0; \
|
||||||
/* adjust width/height if the src is bigger than dest */
|
} \
|
||||||
if (xpos + src_width > dest_width) {
|
/* adjust width/height if the src is bigger than dest */ \
|
||||||
src_width = dest_width - xpos;
|
if (xpos + src_width > dest_width) { \
|
||||||
}
|
src_width = dest_width - xpos; \
|
||||||
if (ypos + src_height > dest_height) {
|
} \
|
||||||
src_height = dest_height - ypos;
|
if (ypos + src_height > dest_height) { \
|
||||||
}
|
src_height = dest_height - ypos; \
|
||||||
|
} \
|
||||||
src_add = src_stride - (4 * src_width);
|
\
|
||||||
dest_add = dest_stride - (4 * src_width);
|
src_add = src_stride - (4 * src_width); \
|
||||||
|
dest_add = dest_stride - (4 * src_width); \
|
||||||
dest = dest + 4 * xpos + (ypos * dest_stride);
|
\
|
||||||
|
dest = dest + 4 * xpos + (ypos * dest_stride); \
|
||||||
/* we convert a square of 2x2 samples to generate 4 Luma and 2 chroma samples */
|
\
|
||||||
for (i = 0; i < src_height; i++) {
|
/* we convert a square of 2x2 samples to generate 4 Luma and 2 chroma samples */ \
|
||||||
for (j = 0; j < src_width; j++) {
|
for (i = 0; i < src_height; i++) { \
|
||||||
alpha = (src[3] * b_alpha) >> 8;
|
for (j = 0; j < src_width; j++) { \
|
||||||
BLEND_MODE (dest[0], dest[1], dest[2], src[0], src[1], src[2],
|
alpha = (src[a] * b_alpha) >> 8; \
|
||||||
B, G, R, alpha);
|
BLEND_MODE (dest[b], dest[g], dest[r], src[b], src[g], src[r], \
|
||||||
dest[0] = B;
|
B, G, R, alpha); \
|
||||||
dest[1] = G;
|
dest[b] = B; \
|
||||||
dest[2] = R;
|
dest[g] = G; \
|
||||||
dest[3] = 0xff;
|
dest[r] = R; \
|
||||||
|
dest[a] = 0xff; \
|
||||||
src += 4;
|
\
|
||||||
dest += 4;
|
src += 4; \
|
||||||
}
|
dest += 4; \
|
||||||
src += src_add;
|
} \
|
||||||
dest += dest_add;
|
src += src_add; \
|
||||||
}
|
dest += dest_add; \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
\
|
||||||
|
/* fill a buffer with a checkerboard pattern */ \
|
||||||
|
void \
|
||||||
|
gst_videomixer_fill_##name##_checker (guint8 * dest, gint width, gint height) \
|
||||||
|
{ \
|
||||||
|
gint i, j; \
|
||||||
|
static const int tab[] = { 80, 160, 80, 160 }; \
|
||||||
|
\
|
||||||
|
for (i = 0; i < height; i++) { \
|
||||||
|
for (j = 0; j < width; j++) { \
|
||||||
|
dest[b] = tab[((i & 0x8) >> 3) + ((j & 0x8) >> 3)]; /* blue */ \
|
||||||
|
dest[g] = tab[((i & 0x8) >> 3) + ((j & 0x8) >> 3)]; /* green */ \
|
||||||
|
dest[r] = tab[((i & 0x8) >> 3) + ((j & 0x8) >> 3)]; /* red */ \
|
||||||
|
dest[a] = 0xFF; /* alpha */ \
|
||||||
|
dest += 4; \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
\
|
||||||
|
void \
|
||||||
|
gst_videomixer_fill_##name##_color (guint8 * dest, gint width, gint height, \
|
||||||
|
gint colY, gint colU, gint colV) \
|
||||||
|
{ \
|
||||||
|
gint red, green, blue; \
|
||||||
|
gint i, j; \
|
||||||
|
\
|
||||||
|
red = CLAMP (1.164 * (colY - 16) + 1.596 * (colV - 128), 0, 255); \
|
||||||
|
green = \
|
||||||
|
CLAMP (1.164 * (colY - 16) - 0.813 * (colV - 128) - 0.391 * (colU - 128), \
|
||||||
|
0, 255); \
|
||||||
|
blue = CLAMP (1.164 * (colY - 16) + 2.018 * (colU - 128), 0, 255); \
|
||||||
|
\
|
||||||
|
for (i = 0; i < height; i++) { \
|
||||||
|
for (j = 0; j < width; j++) { \
|
||||||
|
dest[b] = blue; \
|
||||||
|
dest[g] = green; \
|
||||||
|
dest[r] = red; \
|
||||||
|
dest[a] = 0xff; \
|
||||||
|
dest += 4; \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef BLEND_MODE
|
CREATE_FUNCTIONS (argb, 0, 1, 2, 3);
|
||||||
|
CREATE_FUNCTIONS (bgra, 3, 2, 1, 0);
|
||||||
/* fill a buffer with a checkerboard pattern */
|
|
||||||
void
|
|
||||||
gst_videomixer_fill_bgra_checker (guint8 * dest, gint width, gint height)
|
|
||||||
{
|
|
||||||
gint i, j;
|
|
||||||
static int tab[] = { 80, 160, 80, 160 };
|
|
||||||
|
|
||||||
for (i = 0; i < height; i++) {
|
|
||||||
for (j = 0; j < width; j++) {
|
|
||||||
*dest++ = tab[((i & 0x8) >> 3) + ((j & 0x8) >> 3)]; /* blue */
|
|
||||||
*dest++ = tab[((i & 0x8) >> 3) + ((j & 0x8) >> 3)]; /* green */
|
|
||||||
*dest++ = tab[((i & 0x8) >> 3) + ((j & 0x8) >> 3)]; /* red */
|
|
||||||
*dest++ = 0xFF; /* alpha */
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
gst_videomixer_fill_bgra_color (guint8 * dest, gint width, gint height,
|
|
||||||
gint colY, gint colU, gint colV)
|
|
||||||
{
|
|
||||||
gint red, green, blue;
|
|
||||||
gint i, j;
|
|
||||||
|
|
||||||
red = CLAMP (1.164 * (colY - 16) + 1.596 * (colV - 128), 0, 255);
|
|
||||||
green =
|
|
||||||
CLAMP (1.164 * (colY - 16) - 0.813 * (colV - 128) - 0.391 * (colU - 128),
|
|
||||||
0, 255);
|
|
||||||
blue = CLAMP (1.164 * (colY - 16) + 2.018 * (colU - 128), 0, 255);
|
|
||||||
|
|
||||||
for (i = 0; i < height; i++) {
|
|
||||||
for (j = 0; j < width; j++) {
|
|
||||||
*dest++ = blue;
|
|
||||||
*dest++ = green;
|
|
||||||
*dest++ = red;
|
|
||||||
*dest++ = 0xff;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t
|
size_t
|
||||||
gst_videomixer_calculate_frame_size_bgra (gint width, gint height)
|
gst_videomixer_calculate_frame_size_bgra (gint width, gint height)
|
||||||
{
|
{
|
||||||
return GST_ROUND_UP_4 (width) * height * 4;
|
return GST_ROUND_UP_4 (width) * height * 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#undef BLEND_MODE
|
||||||
|
|
|
@ -20,12 +20,12 @@
|
||||||
/**
|
/**
|
||||||
* SECTION:element-videomixer
|
* SECTION:element-videomixer
|
||||||
*
|
*
|
||||||
* Videomixer can accept AYUV and BGRA video streams. For each of the requested
|
* Videomixer can accept AYUV, ARGB and BGRA video streams. For each of the requested
|
||||||
* sink pads it will compare the incoming geometry and framerate to define the
|
* sink pads it will compare the incoming geometry and framerate to define the
|
||||||
* output parameters. Indeed output video frames will have the geometry of the
|
* output parameters. Indeed output video frames will have the geometry of the
|
||||||
* biggest incoming video stream and the framerate of the fastest incoming one.
|
* biggest incoming video stream and the framerate of the fastest incoming one.
|
||||||
*
|
*
|
||||||
* All sink pads must be either AYUV or BGRA, but a mixture of them is not
|
* All sink pads must be either AYUV, ARGB or BGRA, but a mixture of them is not
|
||||||
* supported. The src pad will have the same colorspace as the sinks.
|
* supported. The src pad will have the same colorspace as the sinks.
|
||||||
* No colorspace conversion is done.
|
* No colorspace conversion is done.
|
||||||
*
|
*
|
||||||
|
@ -105,13 +105,19 @@ void gst_videomixer_fill_ayuv_checker (guint8 * dest, gint width, gint height);
|
||||||
void gst_videomixer_fill_ayuv_color (guint8 * dest, gint width, gint height,
|
void gst_videomixer_fill_ayuv_color (guint8 * dest, gint width, gint height,
|
||||||
gint colY, gint colU, gint colV);
|
gint colY, gint colU, gint colV);
|
||||||
size_t gst_videomixer_calculate_frame_size_ayuv (gint width, gint height);
|
size_t gst_videomixer_calculate_frame_size_ayuv (gint width, gint height);
|
||||||
/*BGRA function definitions see file: blend_ayuv*/
|
/*BGRA/ARGB function definitions see file: blend_bgra*/
|
||||||
void gst_videomixer_blend_bgra_bgra (guint8 * src, gint xpos, gint ypos,
|
void gst_videomixer_blend_bgra_bgra (guint8 * src, gint xpos, gint ypos,
|
||||||
gint src_width, gint src_height, gdouble src_alpha,
|
gint src_width, gint src_height, gdouble src_alpha,
|
||||||
guint8 * dest, gint dest_width, gint dest_height);
|
guint8 * dest, gint dest_width, gint dest_height);
|
||||||
void gst_videomixer_fill_bgra_checker (guint8 * dest, gint width, gint height);
|
void gst_videomixer_fill_bgra_checker (guint8 * dest, gint width, gint height);
|
||||||
void gst_videomixer_fill_bgra_color (guint8 * dest, gint width, gint height,
|
void gst_videomixer_fill_bgra_color (guint8 * dest, gint width, gint height,
|
||||||
gint colY, gint colU, gint colV);
|
gint colY, gint colU, gint colV);
|
||||||
|
void gst_videomixer_blend_argb_argb (guint8 * src, gint xpos, gint ypos,
|
||||||
|
gint src_width, gint src_height, gdouble src_alpha,
|
||||||
|
guint8 * dest, gint dest_width, gint dest_height);
|
||||||
|
void gst_videomixer_fill_argb_checker (guint8 * dest, gint width, gint height);
|
||||||
|
void gst_videomixer_fill_argb_color (guint8 * dest, gint width, gint height,
|
||||||
|
gint colY, gint colU, gint colV);
|
||||||
size_t gst_videomixer_calculate_frame_size_bgra (gint width, gint height);
|
size_t gst_videomixer_calculate_frame_size_bgra (gint width, gint height);
|
||||||
/*I420 function definitions see file: blend_i420.c*/
|
/*I420 function definitions see file: blend_i420.c*/
|
||||||
void gst_videomixer_blend_i420_i420 (guint8 * src, gint xpos, gint ypos,
|
void gst_videomixer_blend_i420_i420 (guint8 * src, gint xpos, gint ypos,
|
||||||
|
@ -462,14 +468,14 @@ static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
|
||||||
GST_PAD_SRC,
|
GST_PAD_SRC,
|
||||||
GST_PAD_ALWAYS,
|
GST_PAD_ALWAYS,
|
||||||
GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("AYUV") ";" GST_VIDEO_CAPS_BGRA ";"
|
GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("AYUV") ";" GST_VIDEO_CAPS_BGRA ";"
|
||||||
GST_VIDEO_CAPS_YUV ("I420"))
|
GST_VIDEO_CAPS_ARGB ";" GST_VIDEO_CAPS_YUV ("I420"))
|
||||||
);
|
);
|
||||||
|
|
||||||
static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink_%d",
|
static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink_%d",
|
||||||
GST_PAD_SINK,
|
GST_PAD_SINK,
|
||||||
GST_PAD_REQUEST,
|
GST_PAD_REQUEST,
|
||||||
GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("AYUV") ";" GST_VIDEO_CAPS_BGRA ";"
|
GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("AYUV") ";" GST_VIDEO_CAPS_BGRA ";"
|
||||||
GST_VIDEO_CAPS_YUV ("I420"))
|
GST_VIDEO_CAPS_ARGB ";" GST_VIDEO_CAPS_YUV ("I420"))
|
||||||
);
|
);
|
||||||
|
|
||||||
static void gst_videomixer_finalize (GObject * object);
|
static void gst_videomixer_finalize (GObject * object);
|
||||||
|
@ -914,56 +920,57 @@ gst_videomixer_getcaps (GstPad * pad)
|
||||||
static gboolean
|
static gboolean
|
||||||
gst_videomixer_setcaps (GstPad * pad, GstCaps * caps)
|
gst_videomixer_setcaps (GstPad * pad, GstCaps * caps)
|
||||||
{
|
{
|
||||||
GstElement *element;
|
GstVideoMixer *mixer = GST_VIDEO_MIXER (gst_pad_get_parent_element (pad));
|
||||||
GstVideoMixer *mixer;
|
GstVideoFormat fmt;
|
||||||
GstStructure *str;
|
gboolean ret = FALSE;
|
||||||
element = gst_pad_get_parent_element (pad);
|
|
||||||
g_assert (element);
|
|
||||||
mixer = GST_VIDEO_MIXER (element);
|
|
||||||
g_assert (mixer);
|
|
||||||
GST_INFO_OBJECT (mixer, "set src caps: \n%" GST_PTR_FORMAT, caps);
|
GST_INFO_OBJECT (mixer, "set src caps: \n%" GST_PTR_FORMAT, caps);
|
||||||
|
|
||||||
str = gst_caps_get_structure (caps, 0);
|
mixer->blend = NULL;
|
||||||
|
mixer->fill_checker = NULL;
|
||||||
|
mixer->fill_color = NULL;
|
||||||
|
mixer->calculate_frame_size = NULL;
|
||||||
|
|
||||||
if (gst_structure_has_name (str, "video/x-raw-yuv")) {
|
if (!gst_video_format_parse_caps (caps, &fmt, NULL, NULL))
|
||||||
guint32 format;
|
goto done;
|
||||||
int ret;
|
|
||||||
ret = gst_structure_get_fourcc (str, "format", &format);
|
switch (fmt) {
|
||||||
if (!ret) {
|
case GST_VIDEO_FORMAT_AYUV:
|
||||||
mixer->blend = NULL;
|
|
||||||
mixer->fill_checker = NULL;
|
|
||||||
mixer->fill_color = NULL;
|
|
||||||
mixer->calculate_frame_size = NULL;
|
|
||||||
} else if (format == GST_STR_FOURCC ("AYUV")) {
|
|
||||||
mixer->blend = gst_videomixer_blend_ayuv_ayuv;
|
mixer->blend = gst_videomixer_blend_ayuv_ayuv;
|
||||||
mixer->fill_checker = gst_videomixer_fill_ayuv_checker;
|
mixer->fill_checker = gst_videomixer_fill_ayuv_checker;
|
||||||
mixer->fill_color = gst_videomixer_fill_ayuv_color;
|
mixer->fill_color = gst_videomixer_fill_ayuv_color;
|
||||||
mixer->calculate_frame_size = gst_videomixer_calculate_frame_size_ayuv;
|
mixer->calculate_frame_size = gst_videomixer_calculate_frame_size_ayuv;
|
||||||
} else if (format == GST_STR_FOURCC ("I420")) {
|
ret = TRUE;
|
||||||
|
break;
|
||||||
|
case GST_VIDEO_FORMAT_I420:
|
||||||
mixer->blend = gst_videomixer_blend_i420_i420;
|
mixer->blend = gst_videomixer_blend_i420_i420;
|
||||||
mixer->fill_checker = gst_videomixer_fill_i420_checker;
|
mixer->fill_checker = gst_videomixer_fill_i420_checker;
|
||||||
mixer->fill_color = gst_videomixer_fill_i420_color;
|
mixer->fill_color = gst_videomixer_fill_i420_color;
|
||||||
mixer->calculate_frame_size = gst_videomixer_calculate_frame_size_i420;
|
mixer->calculate_frame_size = gst_videomixer_calculate_frame_size_i420;
|
||||||
} else {
|
ret = TRUE;
|
||||||
mixer->blend = NULL;
|
break;
|
||||||
mixer->fill_checker = NULL;
|
case GST_VIDEO_FORMAT_BGRA:
|
||||||
mixer->fill_color = NULL;
|
mixer->blend = gst_videomixer_blend_bgra_bgra;
|
||||||
mixer->calculate_frame_size = NULL;
|
mixer->fill_checker = gst_videomixer_fill_bgra_checker;
|
||||||
}
|
mixer->fill_color = gst_videomixer_fill_bgra_color;
|
||||||
} else if (gst_structure_has_name (str, "video/x-raw-rgb")) {
|
mixer->calculate_frame_size = gst_videomixer_calculate_frame_size_bgra;
|
||||||
mixer->blend = gst_videomixer_blend_bgra_bgra;
|
ret = TRUE;
|
||||||
mixer->fill_checker = gst_videomixer_fill_bgra_checker;
|
break;
|
||||||
mixer->fill_color = gst_videomixer_fill_bgra_color;
|
case GST_VIDEO_FORMAT_ARGB:
|
||||||
mixer->calculate_frame_size = gst_videomixer_calculate_frame_size_bgra;
|
mixer->blend = gst_videomixer_blend_argb_argb;
|
||||||
} else {
|
mixer->fill_checker = gst_videomixer_fill_argb_checker;
|
||||||
mixer->blend = NULL;
|
mixer->fill_color = gst_videomixer_fill_argb_color;
|
||||||
mixer->fill_checker = NULL;
|
mixer->calculate_frame_size = gst_videomixer_calculate_frame_size_bgra;
|
||||||
mixer->fill_color = NULL;
|
ret = TRUE;
|
||||||
mixer->calculate_frame_size = NULL;
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
gst_object_unref (element);
|
|
||||||
|
|
||||||
return TRUE;
|
done:
|
||||||
|
gst_object_unref (mixer);
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static GstPad *
|
static GstPad *
|
||||||
|
|
Loading…
Reference in a new issue