diff options
author | David Schleef <ds@schleef.org> | 2003-12-03 07:53:00 +0000 |
---|---|---|
committer | David Schleef <ds@schleef.org> | 2003-12-03 07:53:00 +0000 |
commit | 89b15cdb194c8f3374b0e4dc230a2a7599fa4a48 (patch) | |
tree | 81f5d7bceed56c45666938d45e7cee9453651b21 | |
parent | 46778047cb4374ffa7b55069a7bf01c3ae24a7f9 (diff) | |
download | gstreamer-plugins-base-89b15cdb194c8f3374b0e4dc230a2a7599fa4a48.tar.gz |
convert to new caps
Original commit message from CVS:
convert to new caps
-rw-r--r-- | gst/videoscale/gstvideoscale.c | 222 | ||||
-rw-r--r-- | gst/videoscale/videoscale.c | 129 | ||||
-rw-r--r-- | gst/videoscale/videoscale.h | 6 |
3 files changed, 134 insertions, 223 deletions
diff --git a/gst/videoscale/gstvideoscale.c b/gst/videoscale/gstvideoscale.c index 07ac1e713..dd7cceef1 100644 --- a/gst/videoscale/gstvideoscale.c +++ b/gst/videoscale/gstvideoscale.c @@ -65,83 +65,33 @@ gst_videoscale_method_get_type (void) return videoscale_method_type; } -static GstCaps * +static GstCaps2 * gst_videoscale_get_capslist(void) { - static GstCaps *capslist = NULL; - GstCaps *caps; + GstCaps2 *caps; int i; - if (capslist){ - gst_caps_ref(capslist); - return capslist; - } - + caps = gst_caps2_new_empty(); for(i=0;i<videoscale_n_formats;i++){ - caps = videoscale_get_caps(videoscale_formats + i); - capslist = gst_caps_append(capslist, caps); + gst_caps2_append_cap (caps, + videoscale_get_structure (videoscale_formats + i)); } - gst_caps_ref(capslist); - return capslist; + return caps; } static GstPadTemplate * gst_videoscale_src_template_factory(void) { - static GstPadTemplate *templ = NULL; - - if(!templ){ - GstCaps *caps; - GstCaps *caps1 = GST_CAPS_NEW("src","video/x-raw-yuv", - "width", GST_PROPS_INT_RANGE (0, G_MAXINT), - "height", GST_PROPS_INT_RANGE (0, G_MAXINT), - "framerate", GST_PROPS_FLOAT_RANGE (0, G_MAXFLOAT)); - GstCaps *caps2 = GST_CAPS_NEW("src","video/x-raw-rgb", - "width", GST_PROPS_INT_RANGE (0, G_MAXINT), - "height", GST_PROPS_INT_RANGE (0, G_MAXINT), - "framerate", GST_PROPS_FLOAT_RANGE (0, G_MAXFLOAT)); - - caps = gst_caps_intersect(caps1, gst_videoscale_get_capslist ()); - gst_caps_unref (caps1); - caps1 = caps; - caps = gst_caps_intersect(caps2, gst_videoscale_get_capslist ()); - gst_caps_unref (caps2); - caps2 = caps; - caps = gst_caps_append(caps1, caps2); - - templ = GST_PAD_TEMPLATE_NEW("src", GST_PAD_SRC, GST_PAD_ALWAYS, caps); - } - return templ; + return gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS, + gst_videoscale_get_capslist()); } static GstPadTemplate * gst_videoscale_sink_template_factory(void) { - static GstPadTemplate *templ = NULL; - - if(!templ){ - GstCaps *caps; - GstCaps *caps1 = GST_CAPS_NEW("src","video/x-raw-yuv", - "width", GST_PROPS_INT_RANGE (0, G_MAXINT), - "height", GST_PROPS_INT_RANGE (0, G_MAXINT), - "framerate", GST_PROPS_FLOAT_RANGE (0, G_MAXFLOAT)); - GstCaps *caps2 = GST_CAPS_NEW("src","video/x-raw-rgb", - "width", GST_PROPS_INT_RANGE (0, G_MAXINT), - "height", GST_PROPS_INT_RANGE (0, G_MAXINT), - "framerate", GST_PROPS_FLOAT_RANGE (0, G_MAXFLOAT)); - - caps = gst_caps_intersect(caps1, gst_videoscale_get_capslist ()); - gst_caps_unref (caps1); - caps1 = caps; - caps = gst_caps_intersect(caps2, gst_videoscale_get_capslist ()); - gst_caps_unref (caps2); - caps2 = caps; - caps = gst_caps_append(caps1, caps2); - - templ = GST_PAD_TEMPLATE_NEW("sink", GST_PAD_SINK, GST_PAD_ALWAYS, caps); - } - return templ; + return gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS, + gst_videoscale_get_capslist()); } static void gst_videoscale_base_init (gpointer g_class); @@ -152,7 +102,7 @@ static void gst_videoscale_set_property (GObject *object, guint prop_id, const static void gst_videoscale_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec); static void gst_videoscale_chain (GstPad *pad, GstData *_data); -static GstCaps * gst_videoscale_get_capslist(void); +static GstCaps2 * gst_videoscale_get_capslist(void); static GstElementClass *parent_class = NULL; /*static guint gst_videoscale_signals[LAST_SIGNAL] = { 0 }; */ @@ -209,17 +159,14 @@ gst_videoscale_class_init (GstVideoscaleClass *klass) } -static GstCaps * -gst_videoscale_getcaps (GstPad *pad, GstCaps *caps) +static GstCaps2 * +gst_videoscale_getcaps (GstPad *pad) { GstVideoscale *videoscale; - //GstCaps *capslist = NULL; - GstCaps *peercaps; - //GstCaps *sizecaps1, *sizecaps2; - //GstCaps *sizecaps; - GstCaps *handled_caps; - GstCaps *icaps; + GstCaps2 *peercaps; + GstCaps2 *caps; GstPad *otherpad; + int i; GST_DEBUG ("gst_videoscale_getcaps"); videoscale = GST_VIDEOSCALE (gst_pad_get_parent (pad)); @@ -238,139 +185,64 @@ gst_videoscale_getcaps (GstPad *pad, GstCaps *caps) } peercaps = gst_pad_get_allowed_caps (GST_PAD_PEER(otherpad)); - GST_DEBUG("othercaps are %s", gst_caps_to_string(peercaps)); - - { - GstCaps *caps1 = GST_CAPS_NEW("src","video/x-raw-yuv", - "width", GST_PROPS_INT_RANGE (0, G_MAXINT), - "height", GST_PROPS_INT_RANGE (0, G_MAXINT), - "framerate", GST_PROPS_FLOAT_RANGE (0, G_MAXFLOAT)); - GstCaps *caps2 = GST_CAPS_NEW("src","video/x-raw-rgb", - "width", GST_PROPS_INT_RANGE (0, G_MAXINT), - "height", GST_PROPS_INT_RANGE (0, G_MAXINT), - "framerate", GST_PROPS_FLOAT_RANGE (0, G_MAXFLOAT)); - - caps = gst_caps_intersect(caps1, gst_videoscale_get_capslist ()); - gst_caps_unref (caps1); - caps1 = caps; - caps = gst_caps_intersect(caps2, gst_videoscale_get_capslist ()); - gst_caps_unref (caps2); - caps2 = caps; - handled_caps = gst_caps_append(caps1, caps2); - } + GST_DEBUG_CAPS("othercaps are", peercaps); + + caps = gst_caps2_copy (peercaps); + for(i=0;i<gst_caps2_get_n_structures(caps);i++) { + GstStructure *structure = gst_caps2_get_nth_cap (caps, i); - icaps = gst_caps_intersect (handled_caps, gst_caps_copy(peercaps)); + gst_structure_set (structure, + "width", GST_TYPE_INT_RANGE, 1, G_MAXINT, + "height", GST_TYPE_INT_RANGE, 1, G_MAXINT, + NULL); + } - GST_DEBUG("returning caps %s", gst_caps_to_string (icaps)); + GST_DEBUG_CAPS ("returning caps", caps); - return icaps; + return caps; } static GstPadLinkReturn -gst_videoscale_link (GstPad *pad, GstCaps *caps) +gst_videoscale_link (GstPad *pad, const GstCaps2 *caps) { GstVideoscale *videoscale; GstPadLinkReturn ret; - GstCaps *othercaps; + GstCaps2 *othercaps; GstPad *otherpad; - GstCaps *icaps; + GstStructure *structure; GST_DEBUG ("gst_videoscale_link"); videoscale = GST_VIDEOSCALE (gst_pad_get_parent (pad)); - if (!GST_CAPS_IS_FIXED (caps)) { - return GST_PAD_LINK_DELAYED; - } - if (pad == videoscale->srcpad) { otherpad = videoscale->sinkpad; } else { otherpad = videoscale->srcpad; } - if (otherpad == NULL) { - return GST_PAD_LINK_DELAYED; - } - - othercaps = GST_PAD_CAPS (otherpad); - - if (othercaps) { - GstCaps *othercaps_wh; - - GST_DEBUG ("otherpad caps are already set"); - GST_DEBUG ("otherpad caps are %s", gst_caps_to_string(othercaps)); - othercaps_wh = gst_caps_copy (othercaps); - gst_caps_set(othercaps_wh, "width", GST_PROPS_INT_RANGE (1, G_MAXINT), - "height", GST_PROPS_INT_RANGE (1, G_MAXINT), NULL); + ret = gst_pad_try_set_caps (otherpad, caps); + if (ret == GST_PAD_LINK_OK) { + /* cool, we can use passthru */ + videoscale->passthru = TRUE; -#if 1 - icaps = othercaps; -#else - /* FIXME this is disabled because videotestsrc ! videoscale ! ximagesink - * doesn't negotiate caps correctly the first time, so we pretend it's - * still ok here. */ - icaps = gst_caps_intersect (othercaps_wh, caps); - - GST_DEBUG ("intersected caps are %s", gst_caps_to_string(icaps)); - - if (icaps == NULL) { - /* the new caps are not compatible with the existing, set caps */ - /* currently, we don't force renegotiation */ - return GST_PAD_LINK_REFUSED; - } -#endif - - if (!GST_CAPS_IS_FIXED (icaps)) { - return GST_PAD_LINK_REFUSED; - } - - /* ok, we have a candidate caps */ - } else { - GstCaps *othercaps_wh; - - GST_DEBUG ("otherpad caps are unset"); - - othercaps = gst_pad_get_allowed_caps (pad); - - othercaps_wh = gst_caps_copy (othercaps); - gst_caps_set(othercaps_wh, "width", GST_PROPS_INT_RANGE (1, G_MAXINT), - "height", GST_PROPS_INT_RANGE (1, G_MAXINT), NULL); - - icaps = gst_caps_intersect (othercaps_wh, caps); - - GST_DEBUG ("intersected caps are %s", gst_caps_to_string(icaps)); - - if (icaps == NULL) { - /* the new caps are not compatible with the existing, set caps */ - /* currently, we don't force renegotiation */ - return GST_PAD_LINK_REFUSED; - } - - if (!GST_CAPS_IS_FIXED (icaps)) { - return GST_PAD_LINK_REFUSED; - } - - /* ok, we have a candidate caps */ - ret = gst_pad_try_set_caps (otherpad, gst_caps_copy(icaps)); - if (ret == GST_PAD_LINK_DELAYED || ret == GST_PAD_LINK_REFUSED) { - return ret; - } + return GST_PAD_LINK_OK; } + othercaps = GST_PAD_CAPS (otherpad); + + structure = gst_caps2_get_nth_cap (caps, 0); if (pad == videoscale->srcpad) { - gst_caps_get_int (icaps, "width", &videoscale->from_width); - gst_caps_get_int (icaps, "height", &videoscale->from_height); - gst_caps_get_int (caps, "width", &videoscale->to_width); - gst_caps_get_int (caps, "height", &videoscale->to_height); + ret = gst_structure_get_int (structure, "width", &videoscale->to_width); + ret &= gst_structure_get_int (structure, "height", &videoscale->to_height); } else { - gst_caps_get_int (icaps, "width", &videoscale->to_width); - gst_caps_get_int (icaps, "height", &videoscale->to_height); - gst_caps_get_int (caps, "width", &videoscale->from_width); - gst_caps_get_int (caps, "height", &videoscale->from_height); + ret = gst_structure_get_int (structure, "width", &videoscale->from_width); + ret &= gst_structure_get_int (structure, "height", &videoscale->from_height); } - videoscale->format = videoscale_find_by_caps (caps); + if(!ret) return GST_PAD_LINK_REFUSED; + + videoscale->format = videoscale_find_by_structure (structure); gst_videoscale_setup(videoscale); return GST_PAD_LINK_OK; @@ -448,7 +320,7 @@ gst_videoscale_chain (GstPad *pad, GstData *_data) GST_BUFFER_TIMESTAMP(outbuf) = GST_BUFFER_TIMESTAMP(buf); g_return_if_fail(videoscale->format); - GST_DEBUG ("format %s",videoscale->format->fourcc); + GST_DEBUG ("format " GST_FOURCC_FORMAT,GST_FOURCC_ARGS(videoscale->format->fourcc)); g_return_if_fail(videoscale->format->scale); videoscale->format->scale(videoscale, GST_BUFFER_DATA(outbuf), data); diff --git a/gst/videoscale/videoscale.c b/gst/videoscale/videoscale.c index 2457fa631..abf103cca 100644 --- a/gst/videoscale/videoscale.c +++ b/gst/videoscale/videoscale.c @@ -67,76 +67,115 @@ static void gst_videoscale_scale_nearest_24bit (GstVideoscale *scale, static void gst_videoscale_scale_nearest_16bit (GstVideoscale *scale, unsigned char *dest, unsigned char *src, int sw, int sh, int dw, int dh); +#define fourcc_YUY2 GST_MAKE_FOURCC('Y','U','Y','2') +#define fourcc_UYVY GST_MAKE_FOURCC('U','Y','V','Y') +#define fourcc_Y422 GST_MAKE_FOURCC('Y','4','2','2') +#define fourcc_UYNV GST_MAKE_FOURCC('U','Y','N','V') +#define fourcc_YVYU GST_MAKE_FOURCC('Y','V','Y','U') +#define fourcc_YV12 GST_MAKE_FOURCC('Y','V','1','2') +#define fourcc_I420 GST_MAKE_FOURCC('I','4','2','0') +#define fourcc_Y800 GST_MAKE_FOURCC('Y','8','0','0') +#define fourcc_RGB_ GST_MAKE_FOURCC('R','G','B',' ') + struct videoscale_format_struct videoscale_formats[] = { /* packed */ - { "YUY2", 16, gst_videoscale_packed422, }, - { "UYVY", 16, gst_videoscale_packed422rev, }, - { "Y422", 16, gst_videoscale_packed422rev, }, - { "UYNV", 16, gst_videoscale_packed422rev, }, - { "YVYU", 16, gst_videoscale_packed422, }, + { fourcc_YUY2, 16, gst_videoscale_packed422, }, + { fourcc_UYVY, 16, gst_videoscale_packed422rev, }, + { fourcc_Y422, 16, gst_videoscale_packed422rev, }, + { fourcc_UYNV, 16, gst_videoscale_packed422rev, }, + { fourcc_YVYU, 16, gst_videoscale_packed422, }, /* planar */ - { "YV12", 12, gst_videoscale_planar411, }, - { "I420", 12, gst_videoscale_planar411, }, - { "Y800", 8, gst_videoscale_planar400, }, + { fourcc_YV12, 12, gst_videoscale_planar411, }, + { fourcc_I420, 12, gst_videoscale_planar411, }, + { fourcc_Y800, 8, gst_videoscale_planar400, }, /* RGB */ - { "RGB ", 32, gst_videoscale_32bit, 24, G_BIG_ENDIAN, 0x00ff0000, 0x0000ff00, 0x000000ff }, - { "RGB ", 32, gst_videoscale_32bit, 24, G_BIG_ENDIAN, 0x000000ff, 0x0000ff00, 0x00ff0000 }, - { "RGB ", 32, gst_videoscale_32bit, 24, G_BIG_ENDIAN, 0xff000000, 0x00ff0000, 0x0000ff00 }, - { "RGB ", 32, gst_videoscale_32bit, 24, G_BIG_ENDIAN, 0x0000ff00, 0x00ff0000, 0xff000000 }, - { "RGB ", 24, gst_videoscale_24bit, 24, G_BIG_ENDIAN, 0xff0000, 0x00ff00, 0x0000ff }, - { "RGB ", 24, gst_videoscale_24bit, 24, G_BIG_ENDIAN, 0x0000ff, 0x00ff00, 0xff0000 }, - { "RGB ", 16, gst_videoscale_16bit, 16, G_BYTE_ORDER, 0xf800, 0x07e0, 0x001f }, - { "RGB ", 16, gst_videoscale_16bit, 15, G_BYTE_ORDER, 0x7c00, 0x03e0, 0x001f }, + { fourcc_RGB_, 32, gst_videoscale_32bit, 24, G_BIG_ENDIAN, 0x00ff0000, 0x0000ff00, 0x000000ff }, + { fourcc_RGB_, 32, gst_videoscale_32bit, 24, G_BIG_ENDIAN, 0x000000ff, 0x0000ff00, 0x00ff0000 }, + { fourcc_RGB_, 32, gst_videoscale_32bit, 24, G_BIG_ENDIAN, 0xff000000, 0x00ff0000, 0x0000ff00 }, + { fourcc_RGB_, 32, gst_videoscale_32bit, 24, G_BIG_ENDIAN, 0x0000ff00, 0x00ff0000, 0xff000000 }, + { fourcc_RGB_, 24, gst_videoscale_24bit, 24, G_BIG_ENDIAN, 0xff0000, 0x00ff00, 0x0000ff }, + { fourcc_RGB_, 24, gst_videoscale_24bit, 24, G_BIG_ENDIAN, 0x0000ff, 0x00ff00, 0xff0000 }, + { fourcc_RGB_, 16, gst_videoscale_16bit, 16, G_BYTE_ORDER, 0xf800, 0x07e0, 0x001f }, + { fourcc_RGB_, 16, gst_videoscale_16bit, 15, G_BYTE_ORDER, 0x7c00, 0x03e0, 0x001f }, }; int videoscale_n_formats = sizeof(videoscale_formats)/sizeof(videoscale_formats[0]); -GstCaps * -videoscale_get_caps(struct videoscale_format_struct *format) +GstStructure * +videoscale_get_structure (struct videoscale_format_struct *format) { - unsigned int fourcc; - GstCaps *caps; + GstStructure *structure; if(format->scale==NULL) return NULL; - fourcc = GST_MAKE_FOURCC(format->fourcc[0],format->fourcc[1],format->fourcc[2],format->fourcc[3]); - if(format->bpp){ - caps = GST_CAPS_NEW ("videoscale", "video/x-raw-rgb", - "depth", GST_PROPS_INT(format->bpp), - "bpp", GST_PROPS_INT(format->depth), - "endianness", GST_PROPS_INT(format->endianness), - "red_mask", GST_PROPS_INT(format->red_mask), - "green_mask", GST_PROPS_INT(format->green_mask), - "blue_mask", GST_PROPS_INT(format->blue_mask)); + structure = gst_structure_new ("video/x-raw-rgb", + "depth", G_TYPE_INT, format->bpp, + "bpp", G_TYPE_INT, format->depth, + "endianness", G_TYPE_INT, format->endianness, + "red_mask", G_TYPE_INT, format->red_mask, + "green_mask", G_TYPE_INT, format->green_mask, + "blue_mask", G_TYPE_INT, format->blue_mask, + NULL); }else{ - caps = GST_CAPS_NEW ("videoscale", "video/x-raw-yuv", - "format", GST_PROPS_FOURCC (fourcc)); + structure = gst_structure_new ("video/x-raw-yuv", + "fourcc", GST_TYPE_FOURCC, format->fourcc, NULL); } - return caps; + gst_structure_set(structure, + "width", GST_TYPE_INT_RANGE, 0, G_MAXINT, + "height", GST_TYPE_INT_RANGE, 0, G_MAXINT, + "framerate", GST_TYPE_DOUBLE_RANGE, 0, G_MAXDOUBLE, + NULL); + + return structure; } struct videoscale_format_struct * -videoscale_find_by_caps(GstCaps *caps) +videoscale_find_by_structure(GstStructure *structure) { int i; + gboolean ret; + struct videoscale_format_struct *format; - GST_DEBUG ("finding %p",caps); + GST_DEBUG ("finding %p",structure); - g_return_val_if_fail(caps != NULL, NULL); + g_return_val_if_fail(structure != NULL, NULL); - for (i = 0; i < videoscale_n_formats; i++){ - GstCaps *c; + if(strcmp(gst_structure_get_name(structure),"video/x-raw-yuv")==0){ + unsigned int fourcc; - c = videoscale_get_caps(videoscale_formats + i); - if(c){ - if(gst_caps_is_always_compatible(caps, c)){ - gst_caps_unref(c); - return videoscale_formats + i; + ret = gst_structure_get_fourcc (structure, "format", &fourcc); + if(!ret) return NULL; + for (i = 0; i < videoscale_n_formats; i++){ + format = videoscale_formats + i; + if(format->bpp==0 && format->fourcc == fourcc){ + return format; + } + } + }else{ + int bpp; + int depth; + int endianness; + int red_mask; + int green_mask; + int blue_mask; + + ret = gst_structure_get_int (structure, "bpp", &bpp); + ret &= gst_structure_get_int (structure, "depth", &depth); + ret &= gst_structure_get_int (structure, "endianness", &endianness); + ret &= gst_structure_get_int (structure, "red_mask", &red_mask); + ret &= gst_structure_get_int (structure, "green_mask", &green_mask); + ret &= gst_structure_get_int (structure, "blue_mask", &blue_mask); + if(!ret) return NULL; + for (i = 0; i < videoscale_n_formats; i++){ + format = videoscale_formats + i; + if(format->bpp == bpp && format->depth == depth && + format->endianness == endianness && format->red_mask == red_mask && + format->green_mask == green_mask && format->blue_mask == blue_mask) { + return format; } - gst_caps_unref(c); } } @@ -149,8 +188,8 @@ gst_videoscale_setup (GstVideoscale *videoscale) g_return_if_fail (GST_IS_VIDEOSCALE (videoscale)); g_return_if_fail (videoscale->format != NULL); - GST_DEBUG ("format=%p \"%s\" from %dx%d to %dx%d", - videoscale->format, videoscale->format->fourcc, + GST_DEBUG ("format=%p " GST_FOURCC_FORMAT " from %dx%d to %dx%d", + videoscale->format, GST_FOURCC_ARGS(videoscale->format->fourcc), videoscale->from_width, videoscale->from_height, videoscale->to_width, videoscale->to_height); diff --git a/gst/videoscale/videoscale.h b/gst/videoscale/videoscale.h index 1ebf35ad2..c351c2bcd 100644 --- a/gst/videoscale/videoscale.h +++ b/gst/videoscale/videoscale.h @@ -24,7 +24,7 @@ #include "gstvideoscale.h" struct videoscale_format_struct { - char *fourcc; + unsigned int fourcc; int depth; void (*scale)(GstVideoscale *,unsigned char *dest, unsigned char *src); int bpp; @@ -37,9 +37,9 @@ struct videoscale_format_struct { extern struct videoscale_format_struct videoscale_formats[]; extern int videoscale_n_formats; -GstCaps *videoscale_get_caps(struct videoscale_format_struct *format); +GstStructure *videoscale_get_structure(struct videoscale_format_struct *format); -struct videoscale_format_struct *videoscale_find_by_caps(GstCaps *caps); +struct videoscale_format_struct *videoscale_find_by_structure (GstStructure *structure); #endif |