diff options
author | Wim Taymans <wim.taymans@collabora.co.uk> | 2011-10-16 16:28:58 +0200 |
---|---|---|
committer | Wim Taymans <wim.taymans@collabora.co.uk> | 2011-10-16 16:28:58 +0200 |
commit | 0806e5cbb9d4fc227eee2ea8da8e23cf4bee774a (patch) | |
tree | e39867ea1fbc6a466b282f5ab5842138e47cf53f /gst/bayer | |
parent | 7f851794d62ea3651ad50587bbd402f5c1ea9929 (diff) | |
download | gstreamer-plugins-bad-0806e5cbb9d4fc227eee2ea8da8e23cf4bee774a.tar.gz |
bayer: port to 0.11
Diffstat (limited to 'gst/bayer')
-rw-r--r-- | gst/bayer/gstbayer2rgb.c | 134 | ||||
-rw-r--r-- | gst/bayer/gstrgb2bayer.c | 114 | ||||
-rw-r--r-- | gst/bayer/gstrgb2bayer.h | 2 |
3 files changed, 83 insertions, 167 deletions
diff --git a/gst/bayer/gstbayer2rgb.c b/gst/bayer/gstbayer2rgb.c index 8f9ed124d..05923db40 100644 --- a/gst/bayer/gstbayer2rgb.c +++ b/gst/bayer/gstbayer2rgb.c @@ -111,10 +111,9 @@ struct _GstBayer2RGB GstBaseTransform basetransform; /* < private > */ + GstVideoInfo info; int width; int height; - int stride; - int pixsize; /* bytes per pixel */ int r_off; /* offset for red */ int g_off; /* offset for green */ int b_off; /* offset for blue */ @@ -127,14 +126,7 @@ struct _GstBayer2RGBClass }; #define SRC_CAPS \ - GST_VIDEO_CAPS_RGBx ";" \ - GST_VIDEO_CAPS_xRGB ";" \ - GST_VIDEO_CAPS_BGRx ";" \ - GST_VIDEO_CAPS_xBGR ";" \ - GST_VIDEO_CAPS_RGBA ";" \ - GST_VIDEO_CAPS_ARGB ";" \ - GST_VIDEO_CAPS_BGRA ";" \ - GST_VIDEO_CAPS_ABGR + GST_VIDEO_CAPS_MAKE ("RGBx, xRGB, BGRx, xBGR, RGBA, ARGB, BGRA, ABGR") #define SINK_CAPS "video/x-raw-bayer,format=(string){bggr,grbg,gbrg,rggb}," \ "width=(int)[1,MAX],height=(int)[1,MAX],framerate=(fraction)[0/1,MAX]" @@ -144,12 +136,10 @@ enum PROP_0 }; -#define DEBUG_INIT(bla) \ - GST_DEBUG_CATEGORY_INIT (gst_bayer2rgb_debug, "bayer2rgb", 0, "bayer2rgb element"); - GType gst_bayer2rgb_get_type (void); -GST_BOILERPLATE_FULL (GstBayer2RGB, gst_bayer2rgb, GstBaseTransform, - GST_TYPE_BASE_TRANSFORM, DEBUG_INIT); + +#define gst_bayer2rgb_parent_class parent_class +G_DEFINE_TYPE (GstBayer2RGB, gst_bayer2rgb, GST_TYPE_BASE_TRANSFORM); static void gst_bayer2rgb_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec); @@ -162,37 +152,34 @@ static GstFlowReturn gst_bayer2rgb_transform (GstBaseTransform * base, GstBuffer * inbuf, GstBuffer * outbuf); static void gst_bayer2rgb_reset (GstBayer2RGB * filter); static GstCaps *gst_bayer2rgb_transform_caps (GstBaseTransform * base, - GstPadDirection direction, GstCaps * caps); + GstPadDirection direction, GstCaps * caps, GstCaps * filter); static gboolean gst_bayer2rgb_get_unit_size (GstBaseTransform * base, - GstCaps * caps, guint * size); + GstCaps * caps, gsize * size); static void -gst_bayer2rgb_base_init (gpointer klass) +gst_bayer2rgb_class_init (GstBayer2RGBClass * klass) { - GstElementClass *element_class = GST_ELEMENT_CLASS (klass); + GObjectClass *gobject_class; + GstElementClass *gstelement_class; - gst_element_class_set_details_simple (element_class, + gobject_class = (GObjectClass *) klass; + gstelement_class = (GstElementClass *) klass; + + gobject_class->set_property = gst_bayer2rgb_set_property; + gobject_class->get_property = gst_bayer2rgb_get_property; + + gst_element_class_set_details_simple (gstelement_class, "Bayer to RGB decoder for cameras", "Filter/Converter/Video", - "Converts video/x-raw-bayer to video/x-raw-rgb", + "Converts video/x-raw-bayer to video/x-raw", "William Brack <wbrack@mmm.com.hk>"); - gst_element_class_add_pad_template (element_class, + gst_element_class_add_pad_template (gstelement_class, gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS, gst_caps_from_string (SRC_CAPS))); - gst_element_class_add_pad_template (element_class, + gst_element_class_add_pad_template (gstelement_class, gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS, gst_caps_from_string (SINK_CAPS))); -} - -static void -gst_bayer2rgb_class_init (GstBayer2RGBClass * klass) -{ - GObjectClass *gobject_class; - - gobject_class = (GObjectClass *) klass; - gobject_class->set_property = gst_bayer2rgb_set_property; - gobject_class->get_property = gst_bayer2rgb_get_property; GST_BASE_TRANSFORM_CLASS (klass)->transform_caps = GST_DEBUG_FUNCPTR (gst_bayer2rgb_transform_caps); @@ -202,10 +189,13 @@ gst_bayer2rgb_class_init (GstBayer2RGBClass * klass) GST_DEBUG_FUNCPTR (gst_bayer2rgb_set_caps); GST_BASE_TRANSFORM_CLASS (klass)->transform = GST_DEBUG_FUNCPTR (gst_bayer2rgb_transform); + + GST_DEBUG_CATEGORY_INIT (gst_bayer2rgb_debug, "bayer2rgb", 0, + "bayer2rgb element"); } static void -gst_bayer2rgb_init (GstBayer2RGB * filter, GstBayer2RGBClass * klass) +gst_bayer2rgb_init (GstBayer2RGB * filter) { gst_bayer2rgb_reset (filter); gst_base_transform_set_in_place (GST_BASE_TRANSFORM (filter), TRUE); @@ -236,35 +226,14 @@ gst_bayer2rgb_get_property (GObject * object, guint prop_id, } } -/* Routine to convert colormask value into relative byte offset */ -static int -get_pix_offset (int mask, int bpp) -{ - int bpp32 = (bpp / 8) - 3; - - switch (mask) { - case 255: - return 2 + bpp32; - case 65280: - return 1 + bpp32; - case 16711680: - return 0 + bpp32; - case -16777216: - return 0; - default: - GST_ERROR ("Invalid color mask 0x%08x", mask); - return -1; - } -} - static gboolean gst_bayer2rgb_set_caps (GstBaseTransform * base, GstCaps * incaps, GstCaps * outcaps) { GstBayer2RGB *bayer2rgb = GST_BAYER2RGB (base); GstStructure *structure; - int val, bpp; const char *format; + GstVideoInfo info; GST_DEBUG ("in caps %" GST_PTR_FORMAT " out caps %" GST_PTR_FORMAT, incaps, outcaps); @@ -273,7 +242,6 @@ gst_bayer2rgb_set_caps (GstBaseTransform * base, GstCaps * incaps, gst_structure_get_int (structure, "width", &bayer2rgb->width); gst_structure_get_int (structure, "height", &bayer2rgb->height); - bayer2rgb->stride = GST_ROUND_UP_4 (bayer2rgb->width); format = gst_structure_get_string (structure, "format"); if (g_str_equal (format, "bggr")) { @@ -289,15 +257,12 @@ gst_bayer2rgb_set_caps (GstBaseTransform * base, GstCaps * incaps, } /* To cater for different RGB formats, we need to set params for later */ - structure = gst_caps_get_structure (outcaps, 0); - gst_structure_get_int (structure, "bpp", &bpp); - bayer2rgb->pixsize = bpp / 8; - gst_structure_get_int (structure, "red_mask", &val); - bayer2rgb->r_off = get_pix_offset (val, bpp); - gst_structure_get_int (structure, "green_mask", &val); - bayer2rgb->g_off = get_pix_offset (val, bpp); - gst_structure_get_int (structure, "blue_mask", &val); - bayer2rgb->b_off = get_pix_offset (val, bpp); + gst_video_info_from_caps (&info, outcaps); + bayer2rgb->r_off = GST_VIDEO_INFO_COMP_OFFSET (&info, 0); + bayer2rgb->g_off = GST_VIDEO_INFO_COMP_OFFSET (&info, 1); + bayer2rgb->b_off = GST_VIDEO_INFO_COMP_OFFSET (&info, 2); + + bayer2rgb->info = info; return TRUE; } @@ -307,16 +272,15 @@ gst_bayer2rgb_reset (GstBayer2RGB * filter) { filter->width = 0; filter->height = 0; - filter->stride = 0; - filter->pixsize = 0; filter->r_off = 0; filter->g_off = 0; filter->b_off = 0; + gst_video_info_init (&filter->info); } static GstCaps * gst_bayer2rgb_transform_caps (GstBaseTransform * base, - GstPadDirection direction, GstCaps * caps) + GstPadDirection direction, GstCaps * caps, GstCaps * filter) { GstStructure *structure; GstCaps *newcaps; @@ -330,7 +294,7 @@ gst_bayer2rgb_transform_caps (GstBaseTransform * base, newcaps = gst_caps_from_string ("video/x-raw-bayer," "format=(string){bggr,grbg,gbrg,rggb}"); } else { - newcaps = gst_caps_new_simple ("video/x-raw-rgb", NULL); + newcaps = gst_caps_new_simple ("video/x-raw", NULL); } newstruct = gst_caps_get_structure (newcaps, 0); @@ -348,12 +312,11 @@ gst_bayer2rgb_transform_caps (GstBaseTransform * base, static gboolean gst_bayer2rgb_get_unit_size (GstBaseTransform * base, GstCaps * caps, - guint * size) + gsize * size) { GstStructure *structure; int width; int height; - int pixsize; const char *name; structure = gst_caps_get_structure (caps, 0); @@ -362,15 +325,13 @@ gst_bayer2rgb_get_unit_size (GstBaseTransform * base, GstCaps * caps, gst_structure_get_int (structure, "height", &height)) { name = gst_structure_get_name (structure); /* Our name must be either video/x-raw-bayer video/x-raw-rgb */ - if (strcmp (name, "video/x-raw-rgb")) { + if (strcmp (name, "video/x-raw")) { *size = GST_ROUND_UP_4 (width) * height; return TRUE; } else { - /* For output, calculate according to format */ - if (gst_structure_get_int (structure, "bpp", &pixsize)) { - *size = width * height * (pixsize / 8); - return TRUE; - } + /* For output, calculate according to format (always 32 bits) */ + *size = width * height * 4; + return TRUE; } } @@ -487,20 +448,17 @@ gst_bayer2rgb_transform (GstBaseTransform * base, GstBuffer * inbuf, { GstBayer2RGB *filter = GST_BAYER2RGB (base); uint8_t *input, *output; - - /* - * We need to lock our filter params to prevent changing - * caps in the middle of a transformation (nice way to get - * segfaults) - */ - GST_OBJECT_LOCK (filter); + GstVideoFrame frame; GST_DEBUG ("transforming buffer"); - input = (uint8_t *) GST_BUFFER_DATA (inbuf); - output = (uint8_t *) GST_BUFFER_DATA (outbuf); + input = gst_buffer_map (inbuf, NULL, NULL, GST_MAP_READ); + gst_video_frame_map (&frame, &filter->info, inbuf, GST_MAP_WRITE); + + output = GST_VIDEO_FRAME_PLANE_DATA (&frame, 0); gst_bayer2rgb_process (filter, output, filter->width * 4, input, filter->width); + gst_video_frame_unmap (&frame); + gst_buffer_unmap (inbuf, input, -1); - GST_OBJECT_UNLOCK (filter); return GST_FLOW_OK; } diff --git a/gst/bayer/gstrgb2bayer.c b/gst/bayer/gstrgb2bayer.c index 819d0e6ac..5cc34a314 100644 --- a/gst/bayer/gstrgb2bayer.c +++ b/gst/bayer/gstrgb2bayer.c @@ -30,31 +30,24 @@ #define GST_CAT_DEFAULT gst_rgb2bayer_debug GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT); -static void gst_rgb2bayer_dispose (GObject * object); static void gst_rgb2bayer_finalize (GObject * object); static GstCaps *gst_rgb2bayer_transform_caps (GstBaseTransform * trans, - GstPadDirection direction, GstCaps * caps); + GstPadDirection direction, GstCaps * caps, GstCaps * filter); static gboolean gst_rgb2bayer_get_unit_size (GstBaseTransform * trans, GstCaps * caps, - guint * size); + gsize * size); static gboolean gst_rgb2bayer_set_caps (GstBaseTransform * trans, GstCaps * incaps, GstCaps * outcaps); -static gboolean gst_rgb2bayer_start (GstBaseTransform * trans); -static gboolean gst_rgb2bayer_stop (GstBaseTransform * trans); -static gboolean gst_rgb2bayer_event (GstBaseTransform * trans, - GstEvent * event); static GstFlowReturn gst_rgb2bayer_transform (GstBaseTransform * trans, GstBuffer * inbuf, GstBuffer * outbuf); -static gboolean gst_rgb2bayer_src_event (GstBaseTransform * trans, - GstEvent * event); static GstStaticPadTemplate gst_rgb2bayer_sink_template = GST_STATIC_PAD_TEMPLATE ("sink", GST_PAD_SINK, GST_PAD_ALWAYS, - GST_STATIC_CAPS (GST_VIDEO_CAPS_ARGB) + GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE ("ARGB")) ); #if 0 @@ -81,16 +74,18 @@ GST_STATIC_PAD_TEMPLATE ("src", /* class initialization */ -#define DEBUG_INIT(bla) \ - GST_DEBUG_CATEGORY_INIT (gst_rgb2bayer_debug, "rgb2bayer", 0, "rgb2bayer element"); - -GST_BOILERPLATE_FULL (GstRGB2Bayer, gst_rgb2bayer, GstBaseTransform, - GST_TYPE_BASE_TRANSFORM, DEBUG_INIT); +#define gst_rgb2bayer_parent_class parent_class +G_DEFINE_TYPE (GstRGB2Bayer, gst_rgb2bayer, GST_TYPE_BASE_TRANSFORM); static void -gst_rgb2bayer_base_init (gpointer g_class) +gst_rgb2bayer_class_init (GstRGB2BayerClass * klass) { - GstElementClass *element_class = GST_ELEMENT_CLASS (g_class); + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + GstElementClass *element_class = GST_ELEMENT_CLASS (klass); + GstBaseTransformClass *base_transform_class = + GST_BASE_TRANSFORM_CLASS (klass); + + gobject_class->finalize = gst_rgb2bayer_finalize; gst_element_class_add_pad_template (element_class, gst_static_pad_template_get (&gst_rgb2bayer_src_template)); @@ -100,46 +95,27 @@ gst_rgb2bayer_base_init (gpointer g_class) gst_element_class_set_details_simple (element_class, "RGB to Bayer converter", "Filter/Converter/Video", - "Converts video/x-raw-rgb to video/x-raw-bayer", + "Converts video/x-raw to video/x-raw-bayer", "David Schleef <ds@entropywave.com>"); -} -static void -gst_rgb2bayer_class_init (GstRGB2BayerClass * klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - GstBaseTransformClass *base_transform_class = - GST_BASE_TRANSFORM_CLASS (klass); - - gobject_class->dispose = gst_rgb2bayer_dispose; - gobject_class->finalize = gst_rgb2bayer_finalize; base_transform_class->transform_caps = GST_DEBUG_FUNCPTR (gst_rgb2bayer_transform_caps); base_transform_class->get_unit_size = GST_DEBUG_FUNCPTR (gst_rgb2bayer_get_unit_size); base_transform_class->set_caps = GST_DEBUG_FUNCPTR (gst_rgb2bayer_set_caps); - base_transform_class->start = GST_DEBUG_FUNCPTR (gst_rgb2bayer_start); - base_transform_class->stop = GST_DEBUG_FUNCPTR (gst_rgb2bayer_stop); - base_transform_class->event = GST_DEBUG_FUNCPTR (gst_rgb2bayer_event); base_transform_class->transform = GST_DEBUG_FUNCPTR (gst_rgb2bayer_transform); - base_transform_class->src_event = GST_DEBUG_FUNCPTR (gst_rgb2bayer_src_event); + GST_DEBUG_CATEGORY_INIT (gst_rgb2bayer_debug, "rgb2bayer", 0, + "rgb2bayer element"); } static void -gst_rgb2bayer_init (GstRGB2Bayer * rgb2bayer, - GstRGB2BayerClass * rgb2bayer_class) +gst_rgb2bayer_init (GstRGB2Bayer * rgb2bayer) { } void -gst_rgb2bayer_dispose (GObject * object) -{ - G_OBJECT_CLASS (parent_class)->dispose (object); -} - -void gst_rgb2bayer_finalize (GObject * object) { G_OBJECT_CLASS (parent_class)->finalize (object); @@ -148,7 +124,7 @@ gst_rgb2bayer_finalize (GObject * object) static GstCaps * gst_rgb2bayer_transform_caps (GstBaseTransform * trans, - GstPadDirection direction, GstCaps * caps) + GstPadDirection direction, GstCaps * caps, GstCaps * filter) { GstStructure *structure; GstStructure *new_structure; @@ -160,7 +136,7 @@ gst_rgb2bayer_transform_caps (GstBaseTransform * trans, structure = gst_caps_get_structure (caps, 0); if (direction == GST_PAD_SRC) { - newcaps = gst_caps_new_simple ("video/x-raw-rgb", NULL); + newcaps = gst_caps_new_simple ("video/x-raw", NULL); } else { newcaps = gst_caps_new_simple ("video/x-raw-bayer", NULL); } @@ -183,12 +159,11 @@ gst_rgb2bayer_transform_caps (GstBaseTransform * trans, static gboolean gst_rgb2bayer_get_unit_size (GstBaseTransform * trans, GstCaps * caps, - guint * size) + gsize * size) { GstStructure *structure; int width; int height; - int pixsize; const char *name; structure = gst_caps_get_structure (caps, 0); @@ -196,16 +171,14 @@ gst_rgb2bayer_get_unit_size (GstBaseTransform * trans, GstCaps * caps, if (gst_structure_get_int (structure, "width", &width) && gst_structure_get_int (structure, "height", &height)) { name = gst_structure_get_name (structure); - /* Our name must be either video/x-raw-bayer video/x-raw-rgb */ + /* Our name must be either video/x-raw-bayer video/x-raw */ if (g_str_equal (name, "video/x-raw-bayer")) { *size = width * height; return TRUE; } else { /* For output, calculate according to format */ - if (gst_structure_get_int (structure, "bpp", &pixsize)) { - *size = width * height * (pixsize / 8); - return TRUE; - } + *size = width * height * 4; + return TRUE; } } @@ -220,10 +193,16 @@ gst_rgb2bayer_set_caps (GstBaseTransform * trans, GstCaps * incaps, GstRGB2Bayer *rgb2bayer = GST_RGB_2_BAYER (trans); GstStructure *structure; const char *format; + GstVideoInfo info; GST_DEBUG ("in caps %" GST_PTR_FORMAT " out caps %" GST_PTR_FORMAT, incaps, outcaps); + if (!gst_video_info_from_caps (&info, incaps)) + return FALSE; + + rgb2bayer->info = info; + structure = gst_caps_get_structure (outcaps, 0); gst_structure_get_int (structure, "width", &rgb2bayer->width); @@ -245,27 +224,6 @@ gst_rgb2bayer_set_caps (GstBaseTransform * trans, GstCaps * incaps, return TRUE; } -static gboolean -gst_rgb2bayer_start (GstBaseTransform * trans) -{ - - return TRUE; -} - -static gboolean -gst_rgb2bayer_stop (GstBaseTransform * trans) -{ - - return TRUE; -} - -static gboolean -gst_rgb2bayer_event (GstBaseTransform * trans, GstEvent * event) -{ - - return TRUE; -} - static GstFlowReturn gst_rgb2bayer_transform (GstBaseTransform * trans, GstBuffer * inbuf, GstBuffer * outbuf) @@ -276,9 +234,12 @@ gst_rgb2bayer_transform (GstBaseTransform * trans, GstBuffer * inbuf, int i, j; int height = rgb2bayer->height; int width = rgb2bayer->width; + GstVideoFrame frame; + + gst_video_frame_map (&frame, &rgb2bayer->info, inbuf, GST_MAP_READ); - dest = GST_BUFFER_DATA (outbuf); - src = GST_BUFFER_DATA (inbuf); + dest = gst_buffer_map (outbuf, NULL, NULL, GST_MAP_READ); + src = GST_VIDEO_FRAME_PLANE_DATA (&frame, 0); for (j = 0; j < height; j++) { guint8 *dest_line = dest + width * j; @@ -295,13 +256,8 @@ gst_rgb2bayer_transform (GstBaseTransform * trans, GstBuffer * inbuf, } } } + gst_buffer_unmap (outbuf, dest, -1); + gst_video_frame_unmap (&frame); return GST_FLOW_OK; } - -static gboolean -gst_rgb2bayer_src_event (GstBaseTransform * trans, GstEvent * event) -{ - - return TRUE; -} diff --git a/gst/bayer/gstrgb2bayer.h b/gst/bayer/gstrgb2bayer.h index 7b7f073ee..cf37872d2 100644 --- a/gst/bayer/gstrgb2bayer.h +++ b/gst/bayer/gstrgb2bayer.h @@ -22,6 +22,7 @@ #include <gst/gst.h> #include <gst/base/gstbasetransform.h> +#include <gst/video/video.h> G_BEGIN_DECLS @@ -45,6 +46,7 @@ struct _GstRGB2Bayer { GstBaseTransform base_rgb2bayer; + GstVideoInfo info; int width, height; int format; }; |