videomixer: Some cleanup and fix the calculation of the frame size in bytes

This commit is contained in:
Sebastian Dröge 2009-05-28 13:54:14 +02:00
parent 699b696db8
commit 83fc39ccff
5 changed files with 44 additions and 30 deletions

View file

@ -176,13 +176,9 @@ gst_videomixer_blend_ayuv_ayuv (guint8 * src, gint xpos, gint ypos,
guint8 * dest, gint dest_width, gint dest_height) guint8 * dest, gint dest_width, gint dest_height)
{ {
gint alpha, b_alpha; gint alpha, b_alpha;
gint i, j; gint i, j;
gint src_stride, dest_stride; gint src_stride, dest_stride;
gint src_add, dest_add; gint src_add, dest_add;
gint Y, U, V; gint Y, U, V;
src_stride = src_width * 4; src_stride = src_width * 4;
@ -268,3 +264,9 @@ gst_videomixer_fill_ayuv_color (guint8 * dest, gint width, gint height,
} }
} }
} }
size_t
gst_videomixer_calculate_frame_size_ayuv (gint width, gint height)
{
return GST_ROUND_UP_4 (width) * height * 4;
}

View file

@ -111,7 +111,6 @@ gst_videomixer_fill_bgra_color (guint8 * dest, gint width, gint height,
gint red, green, blue; gint red, green, blue;
gint i, j; gint i, j;
//check this conversion
red = 1.164 * (colY - 16) + 1.596 * (colV - 128); red = 1.164 * (colY - 16) + 1.596 * (colV - 128);
green = 1.164 * (colY - 16) - 0.813 * (colV - 128) - 0.391 * (colU - 128); green = 1.164 * (colY - 16) - 0.813 * (colV - 128) - 0.391 * (colU - 128);
blue = 1.164 * (colY - 16) + 2.018 * (colU - 128); blue = 1.164 * (colY - 16) + 2.018 * (colU - 128);
@ -126,3 +125,9 @@ gst_videomixer_fill_bgra_color (guint8 * dest, gint width, gint height,
} }
} }
} }
size_t
gst_videomixer_calculate_frame_size_bgra (gint width, gint height)
{
return GST_ROUND_UP_4 (width) * height * 4;
}

View file

@ -316,3 +316,10 @@ gst_videomixer_fill_i420_color (guint8 * dest, gint width, gint height,
memset (dest + VIDEO_V_OFFSET (width, height), colV, size); memset (dest + VIDEO_V_OFFSET (width, height), colV, size);
} }
size_t
gst_videomixer_calculate_frame_size_i420 (gint width, gint height)
{
return GST_ROUND_UP_4 (width) * GST_ROUND_UP_2 (height) +
2 * (GST_ROUND_UP_8 (width) / 2) * (GST_ROUND_UP_2 (height) / 2);
}

View file

@ -104,6 +104,7 @@ void gst_videomixer_blend_ayuv_ayuv (guint8 * src, gint xpos, gint ypos,
void gst_videomixer_fill_ayuv_checker (guint8 * dest, gint width, gint height); 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);
/*BGRA function definitions see file: blend_ayuv*/ /*BGRA function definitions see file: blend_ayuv*/
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,
@ -111,6 +112,7 @@ void gst_videomixer_blend_bgra_bgra (guint8 * src, gint xpos, gint ypos,
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);
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,
gint src_width, gint src_height, gdouble src_alpha, gint src_width, gint src_height, gdouble src_alpha,
@ -118,6 +120,7 @@ void gst_videomixer_blend_i420_i420 (guint8 * src, gint xpos, gint ypos,
void gst_videomixer_fill_i420_checker (guint8 * dest, gint width, gint height); void gst_videomixer_fill_i420_checker (guint8 * dest, gint width, gint height);
void gst_videomixer_fill_i420_color (guint8 * dest, gint width, gint height, void gst_videomixer_fill_i420_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_i420 (gint width, gint height);
#define DEFAULT_PAD_ZORDER 0 #define DEFAULT_PAD_ZORDER 0
#define DEFAULT_PAD_XPOS 0 #define DEFAULT_PAD_XPOS 0
@ -927,36 +930,36 @@ gst_videomixer_setcaps (GstPad * pad, GstCaps * caps)
int ret; int ret;
ret = gst_structure_get_fourcc (str, "format", &format); ret = gst_structure_get_fourcc (str, "format", &format);
if (!ret) { if (!ret) {
mixer->blend = 0; mixer->blend = NULL;
mixer->fill_checker = 0; mixer->fill_checker = NULL;
mixer->fill_color = 0; mixer->fill_color = NULL;
mixer->bpp = 0; mixer->calculate_frame_size = NULL;
} else if (format == GST_STR_FOURCC ("AYUV")) { } 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->bpp = 32; mixer->calculate_frame_size = gst_videomixer_calculate_frame_size_ayuv;
} else if (format == GST_STR_FOURCC ("I420")) { } else if (format == GST_STR_FOURCC ("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->bpp = 12; mixer->calculate_frame_size = gst_videomixer_calculate_frame_size_i420;
} else { } else {
mixer->blend = 0; mixer->blend = NULL;
mixer->fill_checker = 0; mixer->fill_checker = NULL;
mixer->fill_color = 0; mixer->fill_color = NULL;
mixer->bpp = 0; mixer->calculate_frame_size = NULL;
} }
} else if (gst_structure_has_name (str, "video/x-raw-rgb")) { } else if (gst_structure_has_name (str, "video/x-raw-rgb")) {
mixer->blend = gst_videomixer_blend_bgra_bgra; mixer->blend = gst_videomixer_blend_bgra_bgra;
mixer->fill_checker = gst_videomixer_fill_bgra_checker; mixer->fill_checker = gst_videomixer_fill_bgra_checker;
mixer->fill_color = gst_videomixer_fill_bgra_color; mixer->fill_color = gst_videomixer_fill_bgra_color;
mixer->bpp = 32; mixer->calculate_frame_size = gst_videomixer_calculate_frame_size_bgra;
} else { } else {
mixer->blend = 0; mixer->blend = NULL;
mixer->fill_checker = 0; mixer->fill_checker = NULL;
mixer->fill_color = 0; mixer->fill_color = NULL;
mixer->bpp = 0; mixer->calculate_frame_size = NULL;
} }
gst_object_unref (element); gst_object_unref (element);
@ -1301,7 +1304,6 @@ gst_videomixer_collected (GstCollectPads * pads, GstVideoMixer * mix)
newcaps = gst_caps_make_writable newcaps = gst_caps_make_writable
(gst_pad_get_negotiated_caps (GST_PAD (mix->master))); (gst_pad_get_negotiated_caps (GST_PAD (mix->master)));
gst_caps_set_simple (newcaps, gst_caps_set_simple (newcaps,
//"format", GST_TYPE_FOURCC, GST_STR_FOURCC ("AYUV"),
"width", G_TYPE_INT, mix->in_width, "width", G_TYPE_INT, mix->in_width,
"height", G_TYPE_INT, mix->in_height, NULL); "height", G_TYPE_INT, mix->in_height, NULL);
@ -1310,17 +1312,15 @@ gst_videomixer_collected (GstCollectPads * pads, GstVideoMixer * mix)
mix->setcaps = FALSE; mix->setcaps = FALSE;
/* Calculating out buffer size from input size */ /* Calculating out buffer size from input size */
gst_pad_set_caps (mix->srcpad, newcaps); //bpp would be 0 otherwise gst_pad_set_caps (mix->srcpad, newcaps);
outsize = outsize = mix->calculate_frame_size (mix->out_width, mix->out_height);
(mix->bpp / 8.0) * mix->in_width * GST_ROUND_UP_2 (mix->in_height);
ret = ret =
gst_pad_alloc_buffer_and_set_caps (mix->srcpad, GST_BUFFER_OFFSET_NONE, gst_pad_alloc_buffer_and_set_caps (mix->srcpad, GST_BUFFER_OFFSET_NONE,
outsize, newcaps, &outbuf); outsize, newcaps, &outbuf);
gst_caps_unref (newcaps); gst_caps_unref (newcaps);
} else { /* Otherwise we just allocate a buffer from current caps */ } else { /* Otherwise we just allocate a buffer from current caps */
/* Calculating out buffer size from input size */ /* Calculating out buffer size from input size */
outsize = outsize = mix->calculate_frame_size (mix->out_width, mix->out_height);
(mix->bpp / 8.0) * mix->in_width * GST_ROUND_UP_2 (mix->in_height);
ret = ret =
gst_pad_alloc_buffer_and_set_caps (mix->srcpad, GST_BUFFER_OFFSET_NONE, gst_pad_alloc_buffer_and_set_caps (mix->srcpad, GST_BUFFER_OFFSET_NONE,
outsize, GST_PAD_CAPS (mix->srcpad), &outbuf); outsize, GST_PAD_CAPS (mix->srcpad), &outbuf);
@ -1333,7 +1333,7 @@ gst_videomixer_collected (GstCollectPads * pads, GstVideoMixer * mix)
switch (mix->background) { switch (mix->background) {
case VIDEO_MIXER_BACKGROUND_CHECKER: case VIDEO_MIXER_BACKGROUND_CHECKER:
if (G_UNLIKELY (mix->fill_checker == NULL)) { if (G_UNLIKELY (mix->fill_checker == NULL)) {
g_warning ("fill checker function pointer not set"); goto error;
} else { } else {
mix->fill_checker (GST_BUFFER_DATA (outbuf), mix->out_width, mix->fill_checker (GST_BUFFER_DATA (outbuf), mix->out_width,
mix->out_height); mix->out_height);
@ -1341,7 +1341,7 @@ gst_videomixer_collected (GstCollectPads * pads, GstVideoMixer * mix)
break; break;
case VIDEO_MIXER_BACKGROUND_BLACK: case VIDEO_MIXER_BACKGROUND_BLACK:
if (G_UNLIKELY (mix->fill_color == NULL)) { if (G_UNLIKELY (mix->fill_color == NULL)) {
g_warning ("fill color function pointer not set"); goto error;
} else { } else {
mix->fill_color (GST_BUFFER_DATA (outbuf), mix->out_width, mix->fill_color (GST_BUFFER_DATA (outbuf), mix->out_width,
mix->out_height, 16, 128, 128); mix->out_height, 16, 128, 128);
@ -1350,7 +1350,7 @@ gst_videomixer_collected (GstCollectPads * pads, GstVideoMixer * mix)
case VIDEO_MIXER_BACKGROUND_WHITE: case VIDEO_MIXER_BACKGROUND_WHITE:
if (G_UNLIKELY (mix->fill_color == NULL)) { if (G_UNLIKELY (mix->fill_color == NULL)) {
g_warning ("fill color function pointer not set"); goto error;
} else { } else {
mix->fill_color (GST_BUFFER_DATA (outbuf), mix->out_width, mix->fill_color (GST_BUFFER_DATA (outbuf), mix->out_width,
mix->out_height, 240, 128, 128); mix->out_height, 240, 128, 128);

View file

@ -82,7 +82,6 @@ struct _GstVideoMixer
gint in_width, in_height; gint in_width, in_height;
gint out_width, out_height; gint out_width, out_height;
gint bpp;
gboolean setcaps; gboolean setcaps;
gboolean sendseg; gboolean sendseg;
@ -104,6 +103,7 @@ struct _GstVideoMixer
void (*fill_checker) (guint8 * dest, gint width, gint height); void (*fill_checker) (guint8 * dest, gint width, gint height);
void (*fill_color) (guint8 * dest, gint width, gint height, gint colY, gint colU, gint colV); void (*fill_color) (guint8 * dest, gint width, gint height, gint colY, gint colU, gint colV);
size_t (*calculate_frame_size) (gint width, gint height);
}; };
struct _GstVideoMixerClass struct _GstVideoMixerClass