From: Antonio Ospite Date: Thu, 24 Oct 2013 20:08:31 +0000 (+0200) Subject: Rename all occurrences of "fbdev" into "am7xxx" X-Git-Url: https://git.ao2.it/gst-am7xxxsink.git/commitdiff_plain/a4f104c73cff3ef6c9f637be33e9df351dd924e2?ds=inline Rename all occurrences of "fbdev" into "am7xxx" The plugin still has the same functionality of the fbdev one for now. --- diff --git a/.gitignore b/.gitignore index 7ef3ee1..b1b1734 100644 --- a/.gitignore +++ b/.gitignore @@ -8,7 +8,7 @@ config.guess config.sub config.rpath configure -gst-fbdevsink.spec +gst-am7xxxsink.spec libtool stamp-h stamp-h.in @@ -23,7 +23,7 @@ depcomp autoregen.sh ABOUT-NLS INSTALL -gst-fbdevsink-*.tar.* +gst-am7xxxsink-*.tar.* .deps .libs diff --git a/configure.ac b/configure.ac index ecd1a85..3e6efb0 100644 --- a/configure.ac +++ b/configure.ac @@ -1,13 +1,13 @@ dnl required version of autoconf AC_PREREQ([2.53]) -AC_INIT([gst-fbdevsink],[0.1.0],[http://ao2.it],[gst-fbdevsink]) +AC_INIT([gst-am7xxxsink],[0.1.0],[http://ao2.it],[gst-am7xxxsink]) dnl required versions of gstreamer and plugins-base GST_REQUIRED=1.0.0 GSTPB_REQUIRED=1.0.0 -AC_CONFIG_SRCDIR([src/gstfbdevsink.c]) +AC_CONFIG_SRCDIR([src/gstam7xxxsink.c]) AC_CONFIG_HEADERS([config.h]) dnl required version of automake diff --git a/src/Makefile.am b/src/Makefile.am index 06a03e0..7971f2c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,15 +1,15 @@ # Note: plugindir is set in configure -plugin_LTLIBRARIES = libgstfbdevsink.la +plugin_LTLIBRARIES = libgstam7xxxsink.la # sources used to compile this plug-in -libgstfbdevsink_la_SOURCES = gstfbdevsink.c gstfbdevsink.h +libgstam7xxxsink_la_SOURCES = gstam7xxxsink.c gstam7xxxsink.h # compiler and linker flags used to compile this plugin, set in configure.ac -libgstfbdevsink_la_CFLAGS = $(GST_CFLAGS) -libgstfbdevsink_la_LIBADD = $(GST_LIBS) -libgstfbdevsink_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS) -libgstfbdevsink_la_LIBTOOLFLAGS = --tag=disable-static +libgstam7xxxsink_la_CFLAGS = $(GST_CFLAGS) +libgstam7xxxsink_la_LIBADD = $(GST_LIBS) +libgstam7xxxsink_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS) +libgstam7xxxsink_la_LIBTOOLFLAGS = --tag=disable-static # headers we need but don't want installed -noinst_HEADERS = gstfbdevsink.h +noinst_HEADERS = gstam7xxxsink.h diff --git a/src/gstam7xxxsink.c b/src/gstam7xxxsink.c new file mode 100644 index 0000000..cd25d21 --- /dev/null +++ b/src/gstam7xxxsink.c @@ -0,0 +1,453 @@ +/* GStreamer am7xxx plugin + * Copyright (C) 2007 Sean D'Epagnier + * + * 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 + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +/* currently the driver does not switch modes, instead uses current mode. + the video is centered and cropped if needed to fit onscreen. + Whatever bitdepth is set is used, and tested to work for 16, 24, 32 bits +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "gstam7xxxsink.h" + +enum +{ + ARG_0, + ARG_DEVICE +}; + +#if 0 +static void gst_am7xxxsink_get_times (GstBaseSink * basesink, + GstBuffer * buffer, GstClockTime * start, GstClockTime * end); +#endif + +static GstFlowReturn gst_am7xxxsink_show_frame (GstVideoSink * videosink, + GstBuffer * buff); + +static gboolean gst_am7xxxsink_start (GstBaseSink * bsink); +static gboolean gst_am7xxxsink_stop (GstBaseSink * bsink); + +static GstCaps *gst_am7xxxsink_getcaps (GstBaseSink * bsink, GstCaps * filter); +static gboolean gst_am7xxxsink_setcaps (GstBaseSink * bsink, GstCaps * caps); + +static void gst_am7xxxsink_finalize (GObject * object); +static void gst_am7xxxsink_set_property (GObject * object, + guint prop_id, const GValue * value, GParamSpec * pspec); +static void gst_am7xxxsink_get_property (GObject * object, + guint prop_id, GValue * value, GParamSpec * pspec); +static GstStateChangeReturn gst_am7xxxsink_change_state (GstElement * element, + GstStateChange transition); + +#define VIDEO_CAPS "{ RGB, BGR, BGRx, xBGR, RGB, RGBx, xRGB, RGB15, RGB16 }" + +static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink", + GST_PAD_SINK, + GST_PAD_ALWAYS, + GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE (VIDEO_CAPS)) + ); + +#define parent_class gst_am7xxxsink_parent_class +G_DEFINE_TYPE (GstAM7XXXSink, gst_am7xxxsink, GST_TYPE_VIDEO_SINK); + +static void +gst_am7xxxsink_init (GstAM7XXXSink * am7xxxsink) +{ + /* nothing to do here yet */ +} + +#if 0 +static void +gst_am7xxxsink_get_times (GstBaseSink * basesink, GstBuffer * buffer, + GstClockTime * start, GstClockTime * end) +{ + GstAM7XXXSink *am7xxxsink; + + am7xxxsink = GST_AM7XXXSINK (basesink); + + if (GST_BUFFER_TIMESTAMP_IS_VALID (buffer)) { + *start = GST_BUFFER_TIMESTAMP (buffer); + if (GST_BUFFER_DURATION_IS_VALID (buffer)) { + *end = *start + GST_BUFFER_DURATION (buffer); + } else { + if (am7xxxsink->fps_n > 0) { + *end = *start + + gst_util_uint64_scale_int (GST_SECOND, am7xxxsink->fps_d, + am7xxxsink->fps_n); + } + } + } +} +#endif + +static GstCaps * +gst_am7xxxsink_getcaps (GstBaseSink * bsink, GstCaps * filter) +{ + GstAM7XXXSink *am7xxxsink; + GstVideoFormat format; + GstCaps *caps; + uint32_t rmask; + uint32_t gmask; + uint32_t bmask; + uint32_t tmask; + int endianness, depth, bpp; + + am7xxxsink = GST_AM7XXXSINK (bsink); + + caps = gst_static_pad_template_get_caps (&sink_template); + + /* FIXME: locking */ + if (!am7xxxsink->framebuffer) + goto done; + + bpp = am7xxxsink->varinfo.bits_per_pixel; + + rmask = ((1 << am7xxxsink->varinfo.red.length) - 1) + << am7xxxsink->varinfo.red.offset; + gmask = ((1 << am7xxxsink->varinfo.green.length) - 1) + << am7xxxsink->varinfo.green.offset; + bmask = ((1 << am7xxxsink->varinfo.blue.length) - 1) + << am7xxxsink->varinfo.blue.offset; + tmask = ((1 << am7xxxsink->varinfo.transp.length) - 1) + << am7xxxsink->varinfo.transp.offset; + + depth = am7xxxsink->varinfo.red.length + am7xxxsink->varinfo.green.length + + am7xxxsink->varinfo.blue.length; + + switch (am7xxxsink->varinfo.bits_per_pixel) { + case 32: + /* swap endianness of masks */ + rmask = GUINT32_SWAP_LE_BE (rmask); + gmask = GUINT32_SWAP_LE_BE (gmask); + bmask = GUINT32_SWAP_LE_BE (bmask); + tmask = GUINT32_SWAP_LE_BE (tmask); + depth += am7xxxsink->varinfo.transp.length; + endianness = G_BIG_ENDIAN; + break; + case 24:{ + /* swap red and blue masks */ + tmask = rmask; + rmask = bmask; + bmask = tmask; + tmask = 0; + endianness = G_BIG_ENDIAN; + break; + } + case 15: + case 16: + tmask = 0; + endianness = G_LITTLE_ENDIAN; + break; + default: + goto unsupported_bpp; + } + + format = gst_video_format_from_masks (depth, bpp, endianness, rmask, gmask, + bmask, tmask); + + if (format == GST_VIDEO_FORMAT_UNKNOWN) + goto unknown_format; + + caps = gst_caps_make_writable (caps); + gst_caps_set_simple (caps, "format", G_TYPE_STRING, + gst_video_format_to_string (format), NULL); + +done: + + if (filter != NULL) { + GstCaps *icaps; + + icaps = gst_caps_intersect (caps, filter); + gst_caps_unref (caps); + caps = icaps; + } + + return caps; + +/* ERRORS */ +unsupported_bpp: + { + GST_WARNING_OBJECT (bsink, "unsupported bit depth: %d", bpp); + return NULL; + } +unknown_format: + { + GST_WARNING_OBJECT (bsink, "could not map am7xxx format to GstVideoFormat: " + "depth=%u, bpp=%u, endianness=%u, rmask=0x%08x, gmask=0x%08x, " + "bmask=0x%08x, tmask=0x%08x", depth, bpp, endianness, rmask, gmask, + bmask, tmask); + return NULL; + } +} + +static gboolean +gst_am7xxxsink_setcaps (GstBaseSink * bsink, GstCaps * vscapslist) +{ + GstAM7XXXSink *am7xxxsink; + GstStructure *structure; + const GValue *fps; + + am7xxxsink = GST_AM7XXXSINK (bsink); + + structure = gst_caps_get_structure (vscapslist, 0); + + fps = gst_structure_get_value (structure, "framerate"); + am7xxxsink->fps_n = gst_value_get_fraction_numerator (fps); + am7xxxsink->fps_d = gst_value_get_fraction_denominator (fps); + + gst_structure_get_int (structure, "width", &am7xxxsink->width); + gst_structure_get_int (structure, "height", &am7xxxsink->height); + + /* calculate centering and scanlengths for the video */ + am7xxxsink->bytespp = am7xxxsink->fixinfo.line_length / am7xxxsink->varinfo.xres; + + am7xxxsink->cx = ((int) am7xxxsink->varinfo.xres - am7xxxsink->width) / 2; + if (am7xxxsink->cx < 0) + am7xxxsink->cx = 0; + + am7xxxsink->cy = ((int) am7xxxsink->varinfo.yres - am7xxxsink->height) / 2; + if (am7xxxsink->cy < 0) + am7xxxsink->cy = 0; + + am7xxxsink->linelen = am7xxxsink->width * am7xxxsink->bytespp; + if (am7xxxsink->linelen > am7xxxsink->fixinfo.line_length) + am7xxxsink->linelen = am7xxxsink->fixinfo.line_length; + + am7xxxsink->lines = am7xxxsink->height; + if (am7xxxsink->lines > am7xxxsink->varinfo.yres) + am7xxxsink->lines = am7xxxsink->varinfo.yres; + + return TRUE; +} + + +static GstFlowReturn +gst_am7xxxsink_show_frame (GstVideoSink * videosink, GstBuffer * buf) +{ + + GstAM7XXXSink *am7xxxsink; + GstMapInfo map; + int i; + + am7xxxsink = GST_AM7XXXSINK (videosink); + + /* optimization could remove this memcpy by allocating the buffer + in framebuffer memory, but would only work when xres matches + the video width */ + if (!gst_buffer_map (buf, &map, GST_MAP_READ)) + return GST_FLOW_ERROR; + + for (i = 0; i < am7xxxsink->lines; i++) { + memcpy (am7xxxsink->framebuffer + + (i + am7xxxsink->cy) * am7xxxsink->fixinfo.line_length + + am7xxxsink->cx * am7xxxsink->bytespp, + map.data + i * am7xxxsink->width * am7xxxsink->bytespp, + am7xxxsink->linelen); + } + + gst_buffer_unmap (buf, &map); + + return GST_FLOW_OK; +} + +static gboolean +gst_am7xxxsink_start (GstBaseSink * bsink) +{ + GstAM7XXXSink *am7xxxsink; + + am7xxxsink = GST_AM7XXXSINK (bsink); + + if (!am7xxxsink->device) { + am7xxxsink->device = g_strdup ("/dev/fb0"); + } + + am7xxxsink->fd = open (am7xxxsink->device, O_RDWR); + + if (am7xxxsink->fd == -1) + return FALSE; + + /* get the fixed screen info */ + if (ioctl (am7xxxsink->fd, FBIOGET_FSCREENINFO, &am7xxxsink->fixinfo)) + return FALSE; + + /* get the variable screen info */ + if (ioctl (am7xxxsink->fd, FBIOGET_VSCREENINFO, &am7xxxsink->varinfo)) + return FALSE; + + /* map the framebuffer */ + am7xxxsink->framebuffer = mmap (0, am7xxxsink->fixinfo.smem_len, + PROT_WRITE, MAP_SHARED, am7xxxsink->fd, 0); + if (am7xxxsink->framebuffer == MAP_FAILED) + return FALSE; + + return TRUE; +} + +static gboolean +gst_am7xxxsink_stop (GstBaseSink * bsink) +{ + GstAM7XXXSink *am7xxxsink; + + am7xxxsink = GST_AM7XXXSINK (bsink); + + if (munmap (am7xxxsink->framebuffer, am7xxxsink->fixinfo.smem_len)) + return FALSE; + + if (close (am7xxxsink->fd)) + return FALSE; + + + return TRUE; +} + +static void +gst_am7xxxsink_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec) +{ + GstAM7XXXSink *am7xxxsink; + + am7xxxsink = GST_AM7XXXSINK (object); + + switch (prop_id) { + case ARG_DEVICE:{ + g_free (am7xxxsink->device); + am7xxxsink->device = g_value_dup_string (value); + break; + } + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + + +static void +gst_am7xxxsink_get_property (GObject * object, guint prop_id, GValue * value, + GParamSpec * pspec) +{ + GstAM7XXXSink *am7xxxsink; + + am7xxxsink = GST_AM7XXXSINK (object); + + switch (prop_id) { + case ARG_DEVICE:{ + g_value_set_string (value, am7xxxsink->device); + break; + } + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static GstStateChangeReturn +gst_am7xxxsink_change_state (GstElement * element, GstStateChange transition) +{ + GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS; + + g_return_val_if_fail (GST_IS_AM7XXXSINK (element), GST_STATE_CHANGE_FAILURE); + + ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition); + + switch (transition) { + default: + break; + } + return ret; +} + +static gboolean +plugin_init (GstPlugin * plugin) +{ + if (!gst_element_register (plugin, "am7xxxsink", GST_RANK_NONE, + GST_TYPE_AM7XXXSINK)) + return FALSE; + + return TRUE; +} + +static void +gst_am7xxxsink_class_init (GstAM7XXXSinkClass * klass) +{ + GObjectClass *gobject_class; + GstElementClass *gstelement_class; + GstBaseSinkClass *basesink_class; + GstVideoSinkClass *videosink_class; + + gobject_class = (GObjectClass *) klass; + gstelement_class = (GstElementClass *) klass; + basesink_class = (GstBaseSinkClass *) klass; + videosink_class = (GstVideoSinkClass *) klass; + + gobject_class->set_property = gst_am7xxxsink_set_property; + gobject_class->get_property = gst_am7xxxsink_get_property; + gobject_class->finalize = gst_am7xxxsink_finalize; + + gstelement_class->change_state = + GST_DEBUG_FUNCPTR (gst_am7xxxsink_change_state); + + g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_DEVICE, + g_param_spec_string ("device", "device", + "The framebuffer device eg: /dev/fb0", NULL, G_PARAM_READWRITE)); + + basesink_class->set_caps = GST_DEBUG_FUNCPTR (gst_am7xxxsink_setcaps); + basesink_class->get_caps = GST_DEBUG_FUNCPTR (gst_am7xxxsink_getcaps); +#if 0 + basesink_class->get_times = GST_DEBUG_FUNCPTR (gst_am7xxxsink_get_times); +#endif + basesink_class->start = GST_DEBUG_FUNCPTR (gst_am7xxxsink_start); + basesink_class->stop = GST_DEBUG_FUNCPTR (gst_am7xxxsink_stop); + + videosink_class->show_frame = GST_DEBUG_FUNCPTR (gst_am7xxxsink_show_frame); + + gst_element_class_set_static_metadata (gstelement_class, "am7xxx video sink", + "Sink/Video", "Linux framebuffer videosink", + "Sean D'Epagnier "); + + gst_element_class_add_pad_template (gstelement_class, + gst_static_pad_template_get (&sink_template)); +} + +static void +gst_am7xxxsink_finalize (GObject * object) +{ + GstAM7XXXSink *am7xxxsink = GST_AM7XXXSINK (object); + + g_free (am7xxxsink->device); + + G_OBJECT_CLASS (parent_class)->finalize (object); +} + +GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, + GST_VERSION_MINOR, + am7xxxsink, + "Linux framebuffer video sink", + plugin_init, VERSION, "LGPL", "gst-am7xxxsink", "http://ao2.it") diff --git a/src/gstam7xxxsink.h b/src/gstam7xxxsink.h new file mode 100644 index 0000000..59075be --- /dev/null +++ b/src/gstam7xxxsink.h @@ -0,0 +1,73 @@ +/* GStreamer + * Copyright (C) 2007 Sean D'Epagnier sean@depagnier.com + * + * 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 + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + + +#ifndef __GST_AM7XXXSINK_H__ +#define __GST_AM7XXXSINK_H__ + +#include +#include +#include + +#include + +G_BEGIN_DECLS + +#define GST_TYPE_AM7XXXSINK \ + (gst_am7xxxsink_get_type()) +#define GST_AM7XXXSINK(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_AM7XXXSINK,GstAM7XXXSink)) +#define GST_AM7XXXSINK_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_AM7XXXSINK,GstAM7XXXSinkClass)) +#define GST_IS_AM7XXXSINK(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_AM7XXXSINK)) +#define GST_IS_AM7XXXSINK_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_AM7XXXSINK)) + +typedef struct _GstAM7XXXSink GstAM7XXXSink; +typedef struct _GstAM7XXXSinkClass GstAM7XXXSinkClass; + +struct _GstAM7XXXSink { + GstVideoSink videosink; + + /*< private >*/ + struct fb_fix_screeninfo fixinfo; + struct fb_var_screeninfo varinfo; + + int fd; + unsigned char *framebuffer; + + char *device; + + int width, height; + int cx, cy, linelen, lines, bytespp; + + int fps_n, fps_d; +}; + +struct _GstAM7XXXSinkClass { + GstVideoSinkClass videosink_class; + +}; + +GType gst_am7xxxsink_get_type(void); + +G_END_DECLS + +#endif /* __GST_AM7XXXSINK_H__ */ diff --git a/src/gstfbdevsink.c b/src/gstfbdevsink.c deleted file mode 100644 index 31018aa..0000000 --- a/src/gstfbdevsink.c +++ /dev/null @@ -1,453 +0,0 @@ -/* GStreamer fbdev plugin - * Copyright (C) 2007 Sean D'Epagnier - * - * 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 - * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -/* currently the driver does not switch modes, instead uses current mode. - the video is centered and cropped if needed to fit onscreen. - Whatever bitdepth is set is used, and tested to work for 16, 24, 32 bits -*/ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include "gstfbdevsink.h" - -enum -{ - ARG_0, - ARG_DEVICE -}; - -#if 0 -static void gst_fbdevsink_get_times (GstBaseSink * basesink, - GstBuffer * buffer, GstClockTime * start, GstClockTime * end); -#endif - -static GstFlowReturn gst_fbdevsink_show_frame (GstVideoSink * videosink, - GstBuffer * buff); - -static gboolean gst_fbdevsink_start (GstBaseSink * bsink); -static gboolean gst_fbdevsink_stop (GstBaseSink * bsink); - -static GstCaps *gst_fbdevsink_getcaps (GstBaseSink * bsink, GstCaps * filter); -static gboolean gst_fbdevsink_setcaps (GstBaseSink * bsink, GstCaps * caps); - -static void gst_fbdevsink_finalize (GObject * object); -static void gst_fbdevsink_set_property (GObject * object, - guint prop_id, const GValue * value, GParamSpec * pspec); -static void gst_fbdevsink_get_property (GObject * object, - guint prop_id, GValue * value, GParamSpec * pspec); -static GstStateChangeReturn gst_fbdevsink_change_state (GstElement * element, - GstStateChange transition); - -#define VIDEO_CAPS "{ RGB, BGR, BGRx, xBGR, RGB, RGBx, xRGB, RGB15, RGB16 }" - -static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink", - GST_PAD_SINK, - GST_PAD_ALWAYS, - GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE (VIDEO_CAPS)) - ); - -#define parent_class gst_fbdevsink_parent_class -G_DEFINE_TYPE (GstFBDEVSink, gst_fbdevsink, GST_TYPE_VIDEO_SINK); - -static void -gst_fbdevsink_init (GstFBDEVSink * fbdevsink) -{ - /* nothing to do here yet */ -} - -#if 0 -static void -gst_fbdevsink_get_times (GstBaseSink * basesink, GstBuffer * buffer, - GstClockTime * start, GstClockTime * end) -{ - GstFBDEVSink *fbdevsink; - - fbdevsink = GST_FBDEVSINK (basesink); - - if (GST_BUFFER_TIMESTAMP_IS_VALID (buffer)) { - *start = GST_BUFFER_TIMESTAMP (buffer); - if (GST_BUFFER_DURATION_IS_VALID (buffer)) { - *end = *start + GST_BUFFER_DURATION (buffer); - } else { - if (fbdevsink->fps_n > 0) { - *end = *start + - gst_util_uint64_scale_int (GST_SECOND, fbdevsink->fps_d, - fbdevsink->fps_n); - } - } - } -} -#endif - -static GstCaps * -gst_fbdevsink_getcaps (GstBaseSink * bsink, GstCaps * filter) -{ - GstFBDEVSink *fbdevsink; - GstVideoFormat format; - GstCaps *caps; - uint32_t rmask; - uint32_t gmask; - uint32_t bmask; - uint32_t tmask; - int endianness, depth, bpp; - - fbdevsink = GST_FBDEVSINK (bsink); - - caps = gst_static_pad_template_get_caps (&sink_template); - - /* FIXME: locking */ - if (!fbdevsink->framebuffer) - goto done; - - bpp = fbdevsink->varinfo.bits_per_pixel; - - rmask = ((1 << fbdevsink->varinfo.red.length) - 1) - << fbdevsink->varinfo.red.offset; - gmask = ((1 << fbdevsink->varinfo.green.length) - 1) - << fbdevsink->varinfo.green.offset; - bmask = ((1 << fbdevsink->varinfo.blue.length) - 1) - << fbdevsink->varinfo.blue.offset; - tmask = ((1 << fbdevsink->varinfo.transp.length) - 1) - << fbdevsink->varinfo.transp.offset; - - depth = fbdevsink->varinfo.red.length + fbdevsink->varinfo.green.length - + fbdevsink->varinfo.blue.length; - - switch (fbdevsink->varinfo.bits_per_pixel) { - case 32: - /* swap endianness of masks */ - rmask = GUINT32_SWAP_LE_BE (rmask); - gmask = GUINT32_SWAP_LE_BE (gmask); - bmask = GUINT32_SWAP_LE_BE (bmask); - tmask = GUINT32_SWAP_LE_BE (tmask); - depth += fbdevsink->varinfo.transp.length; - endianness = G_BIG_ENDIAN; - break; - case 24:{ - /* swap red and blue masks */ - tmask = rmask; - rmask = bmask; - bmask = tmask; - tmask = 0; - endianness = G_BIG_ENDIAN; - break; - } - case 15: - case 16: - tmask = 0; - endianness = G_LITTLE_ENDIAN; - break; - default: - goto unsupported_bpp; - } - - format = gst_video_format_from_masks (depth, bpp, endianness, rmask, gmask, - bmask, tmask); - - if (format == GST_VIDEO_FORMAT_UNKNOWN) - goto unknown_format; - - caps = gst_caps_make_writable (caps); - gst_caps_set_simple (caps, "format", G_TYPE_STRING, - gst_video_format_to_string (format), NULL); - -done: - - if (filter != NULL) { - GstCaps *icaps; - - icaps = gst_caps_intersect (caps, filter); - gst_caps_unref (caps); - caps = icaps; - } - - return caps; - -/* ERRORS */ -unsupported_bpp: - { - GST_WARNING_OBJECT (bsink, "unsupported bit depth: %d", bpp); - return NULL; - } -unknown_format: - { - GST_WARNING_OBJECT (bsink, "could not map fbdev format to GstVideoFormat: " - "depth=%u, bpp=%u, endianness=%u, rmask=0x%08x, gmask=0x%08x, " - "bmask=0x%08x, tmask=0x%08x", depth, bpp, endianness, rmask, gmask, - bmask, tmask); - return NULL; - } -} - -static gboolean -gst_fbdevsink_setcaps (GstBaseSink * bsink, GstCaps * vscapslist) -{ - GstFBDEVSink *fbdevsink; - GstStructure *structure; - const GValue *fps; - - fbdevsink = GST_FBDEVSINK (bsink); - - structure = gst_caps_get_structure (vscapslist, 0); - - fps = gst_structure_get_value (structure, "framerate"); - fbdevsink->fps_n = gst_value_get_fraction_numerator (fps); - fbdevsink->fps_d = gst_value_get_fraction_denominator (fps); - - gst_structure_get_int (structure, "width", &fbdevsink->width); - gst_structure_get_int (structure, "height", &fbdevsink->height); - - /* calculate centering and scanlengths for the video */ - fbdevsink->bytespp = fbdevsink->fixinfo.line_length / fbdevsink->varinfo.xres; - - fbdevsink->cx = ((int) fbdevsink->varinfo.xres - fbdevsink->width) / 2; - if (fbdevsink->cx < 0) - fbdevsink->cx = 0; - - fbdevsink->cy = ((int) fbdevsink->varinfo.yres - fbdevsink->height) / 2; - if (fbdevsink->cy < 0) - fbdevsink->cy = 0; - - fbdevsink->linelen = fbdevsink->width * fbdevsink->bytespp; - if (fbdevsink->linelen > fbdevsink->fixinfo.line_length) - fbdevsink->linelen = fbdevsink->fixinfo.line_length; - - fbdevsink->lines = fbdevsink->height; - if (fbdevsink->lines > fbdevsink->varinfo.yres) - fbdevsink->lines = fbdevsink->varinfo.yres; - - return TRUE; -} - - -static GstFlowReturn -gst_fbdevsink_show_frame (GstVideoSink * videosink, GstBuffer * buf) -{ - - GstFBDEVSink *fbdevsink; - GstMapInfo map; - int i; - - fbdevsink = GST_FBDEVSINK (videosink); - - /* optimization could remove this memcpy by allocating the buffer - in framebuffer memory, but would only work when xres matches - the video width */ - if (!gst_buffer_map (buf, &map, GST_MAP_READ)) - return GST_FLOW_ERROR; - - for (i = 0; i < fbdevsink->lines; i++) { - memcpy (fbdevsink->framebuffer - + (i + fbdevsink->cy) * fbdevsink->fixinfo.line_length - + fbdevsink->cx * fbdevsink->bytespp, - map.data + i * fbdevsink->width * fbdevsink->bytespp, - fbdevsink->linelen); - } - - gst_buffer_unmap (buf, &map); - - return GST_FLOW_OK; -} - -static gboolean -gst_fbdevsink_start (GstBaseSink * bsink) -{ - GstFBDEVSink *fbdevsink; - - fbdevsink = GST_FBDEVSINK (bsink); - - if (!fbdevsink->device) { - fbdevsink->device = g_strdup ("/dev/fb0"); - } - - fbdevsink->fd = open (fbdevsink->device, O_RDWR); - - if (fbdevsink->fd == -1) - return FALSE; - - /* get the fixed screen info */ - if (ioctl (fbdevsink->fd, FBIOGET_FSCREENINFO, &fbdevsink->fixinfo)) - return FALSE; - - /* get the variable screen info */ - if (ioctl (fbdevsink->fd, FBIOGET_VSCREENINFO, &fbdevsink->varinfo)) - return FALSE; - - /* map the framebuffer */ - fbdevsink->framebuffer = mmap (0, fbdevsink->fixinfo.smem_len, - PROT_WRITE, MAP_SHARED, fbdevsink->fd, 0); - if (fbdevsink->framebuffer == MAP_FAILED) - return FALSE; - - return TRUE; -} - -static gboolean -gst_fbdevsink_stop (GstBaseSink * bsink) -{ - GstFBDEVSink *fbdevsink; - - fbdevsink = GST_FBDEVSINK (bsink); - - if (munmap (fbdevsink->framebuffer, fbdevsink->fixinfo.smem_len)) - return FALSE; - - if (close (fbdevsink->fd)) - return FALSE; - - - return TRUE; -} - -static void -gst_fbdevsink_set_property (GObject * object, guint prop_id, - const GValue * value, GParamSpec * pspec) -{ - GstFBDEVSink *fbdevsink; - - fbdevsink = GST_FBDEVSINK (object); - - switch (prop_id) { - case ARG_DEVICE:{ - g_free (fbdevsink->device); - fbdevsink->device = g_value_dup_string (value); - break; - } - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - - -static void -gst_fbdevsink_get_property (GObject * object, guint prop_id, GValue * value, - GParamSpec * pspec) -{ - GstFBDEVSink *fbdevsink; - - fbdevsink = GST_FBDEVSINK (object); - - switch (prop_id) { - case ARG_DEVICE:{ - g_value_set_string (value, fbdevsink->device); - break; - } - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static GstStateChangeReturn -gst_fbdevsink_change_state (GstElement * element, GstStateChange transition) -{ - GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS; - - g_return_val_if_fail (GST_IS_FBDEVSINK (element), GST_STATE_CHANGE_FAILURE); - - ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition); - - switch (transition) { - default: - break; - } - return ret; -} - -static gboolean -plugin_init (GstPlugin * plugin) -{ - if (!gst_element_register (plugin, "fbdevsink", GST_RANK_NONE, - GST_TYPE_FBDEVSINK)) - return FALSE; - - return TRUE; -} - -static void -gst_fbdevsink_class_init (GstFBDEVSinkClass * klass) -{ - GObjectClass *gobject_class; - GstElementClass *gstelement_class; - GstBaseSinkClass *basesink_class; - GstVideoSinkClass *videosink_class; - - gobject_class = (GObjectClass *) klass; - gstelement_class = (GstElementClass *) klass; - basesink_class = (GstBaseSinkClass *) klass; - videosink_class = (GstVideoSinkClass *) klass; - - gobject_class->set_property = gst_fbdevsink_set_property; - gobject_class->get_property = gst_fbdevsink_get_property; - gobject_class->finalize = gst_fbdevsink_finalize; - - gstelement_class->change_state = - GST_DEBUG_FUNCPTR (gst_fbdevsink_change_state); - - g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_DEVICE, - g_param_spec_string ("device", "device", - "The framebuffer device eg: /dev/fb0", NULL, G_PARAM_READWRITE)); - - basesink_class->set_caps = GST_DEBUG_FUNCPTR (gst_fbdevsink_setcaps); - basesink_class->get_caps = GST_DEBUG_FUNCPTR (gst_fbdevsink_getcaps); -#if 0 - basesink_class->get_times = GST_DEBUG_FUNCPTR (gst_fbdevsink_get_times); -#endif - basesink_class->start = GST_DEBUG_FUNCPTR (gst_fbdevsink_start); - basesink_class->stop = GST_DEBUG_FUNCPTR (gst_fbdevsink_stop); - - videosink_class->show_frame = GST_DEBUG_FUNCPTR (gst_fbdevsink_show_frame); - - gst_element_class_set_static_metadata (gstelement_class, "fbdev video sink", - "Sink/Video", "Linux framebuffer videosink", - "Sean D'Epagnier "); - - gst_element_class_add_pad_template (gstelement_class, - gst_static_pad_template_get (&sink_template)); -} - -static void -gst_fbdevsink_finalize (GObject * object) -{ - GstFBDEVSink *fbdevsink = GST_FBDEVSINK (object); - - g_free (fbdevsink->device); - - G_OBJECT_CLASS (parent_class)->finalize (object); -} - -GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, - GST_VERSION_MINOR, - fbdevsink, - "Linux framebuffer video sink", - plugin_init, VERSION, "LGPL", "gst-fbdevsink", "http://ao2.it") diff --git a/src/gstfbdevsink.h b/src/gstfbdevsink.h deleted file mode 100644 index 7998217..0000000 --- a/src/gstfbdevsink.h +++ /dev/null @@ -1,73 +0,0 @@ -/* GStreamer - * Copyright (C) 2007 Sean D'Epagnier sean@depagnier.com - * - * 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 - * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - - -#ifndef __GST_FBDEVSINK_H__ -#define __GST_FBDEVSINK_H__ - -#include -#include -#include - -#include - -G_BEGIN_DECLS - -#define GST_TYPE_FBDEVSINK \ - (gst_fbdevsink_get_type()) -#define GST_FBDEVSINK(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_FBDEVSINK,GstFBDEVSink)) -#define GST_FBDEVSINK_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_FBDEVSINK,GstFBDEVSinkClass)) -#define GST_IS_FBDEVSINK(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_FBDEVSINK)) -#define GST_IS_FBDEVSINK_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_FBDEVSINK)) - -typedef struct _GstFBDEVSink GstFBDEVSink; -typedef struct _GstFBDEVSinkClass GstFBDEVSinkClass; - -struct _GstFBDEVSink { - GstVideoSink videosink; - - /*< private >*/ - struct fb_fix_screeninfo fixinfo; - struct fb_var_screeninfo varinfo; - - int fd; - unsigned char *framebuffer; - - char *device; - - int width, height; - int cx, cy, linelen, lines, bytespp; - - int fps_n, fps_d; -}; - -struct _GstFBDEVSinkClass { - GstVideoSinkClass videosink_class; - -}; - -GType gst_fbdevsink_get_type(void); - -G_END_DECLS - -#endif /* __GST_FBDEVSINK_H__ */