diff options
author | Thomas Vander Stichele <thomas@apestaart.org> | 2004-03-14 22:34:33 +0000 |
---|---|---|
committer | Thomas Vander Stichele <thomas@apestaart.org> | 2004-03-14 22:34:33 +0000 |
commit | 7a778ee4b7ec09a1f5b2185c9cceee3910dfbdf2 (patch) | |
tree | f863b467dea9559a6ec9c48affbfae11f8104164 /sys/glsink/gstglsink.c | |
parent | a19db4bbdc4a15ea0d8f4d28e9a1302c9c3d1657 (diff) | |
download | gst-plugins-bad-7a778ee4b7ec09a1f5b2185c9cceee3910dfbdf2.tar.gz gst-plugins-bad-7a778ee4b7ec09a1f5b2185c9cceee3910dfbdf2.tar.bz2 gst-plugins-bad-7a778ee4b7ec09a1f5b2185c9cceee3910dfbdf2.zip |
gst-indent
Original commit message from CVS:
gst-indent
Diffstat (limited to 'sys/glsink/gstglsink.c')
-rw-r--r-- | sys/glsink/gstglsink.c | 550 |
1 files changed, 278 insertions, 272 deletions
diff --git a/sys/glsink/gstglsink.c b/sys/glsink/gstglsink.c index 21cac1f3..a545c2a8 100644 --- a/sys/glsink/gstglsink.c +++ b/sys/glsink/gstglsink.c @@ -52,37 +52,39 @@ static GstElementDetails gst_glsink_details = { /* default template - initiated with class struct to allow gst-register to work with X running */ GST_PAD_TEMPLATE_FACTORY (gst_glsink_sink_template_factory, - "sink", - GST_PAD_SINK, - GST_PAD_ALWAYS, - GST_CAPS_NEW ( "glsink_rgbsink", "video/x-raw-rgb", - "framerate", GST_PROPS_FLOAT_RANGE(0, G_MAXFLOAT), - "width", GST_PROPS_INT_RANGE(0, G_MAXINT), - "height", GST_PROPS_INT_RANGE(0, G_MAXINT)), - GST_CAPS_NEW ( "glsink_yuvsink", "video/x-raw-yuv", - "framerate", GST_PROPS_FLOAT_RANGE(0, G_MAXFLOAT), - "width", GST_PROPS_INT_RANGE(0, G_MAXINT), - "height", GST_PROPS_INT_RANGE(0, G_MAXINT)) -) + "sink", + GST_PAD_SINK, + GST_PAD_ALWAYS, + GST_CAPS_NEW ("glsink_rgbsink", "video/x-raw-rgb", + "framerate", GST_PROPS_FLOAT_RANGE (0, G_MAXFLOAT), + "width", GST_PROPS_INT_RANGE (0, G_MAXINT), + "height", GST_PROPS_INT_RANGE (0, G_MAXINT)), + GST_CAPS_NEW ("glsink_yuvsink", "video/x-raw-yuv", + "framerate", GST_PROPS_FLOAT_RANGE (0, G_MAXFLOAT), + "width", GST_PROPS_INT_RANGE (0, G_MAXINT), + "height", GST_PROPS_INT_RANGE (0, G_MAXINT)) + ) /* glsink signals and args */ -enum { - LAST_SIGNAL -}; - - -enum { - ARG_0, - ARG_WIDTH, - ARG_HEIGHT, - ARG_FRAMES_DISPLAYED, - ARG_FRAME_TIME, - ARG_HOOK, - ARG_MUTE, - ARG_REPAINT, - ARG_DEMO, - ARG_DUMP -}; + enum + { + LAST_SIGNAL + }; + + + enum + { + ARG_0, + ARG_WIDTH, + ARG_HEIGHT, + ARG_FRAMES_DISPLAYED, + ARG_FRAME_TIME, + ARG_HOOK, + ARG_MUTE, + ARG_REPAINT, + ARG_DEMO, + ARG_DUMP + }; /* GLsink class */ #define GST_TYPE_GLSINK (gst_glsink_get_type()) @@ -91,96 +93,105 @@ enum { #define GST_IS_GLSINK(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_TYPE_GLSINK)) #define GST_IS_GLSINK_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_GLSINK)) -typedef struct _GstGLSink GstGLSink; -typedef struct _GstGLSinkClass GstGLSinkClass; + typedef struct _GstGLSink GstGLSink; + typedef struct _GstGLSinkClass GstGLSinkClass; -struct _GstGLSink { - GstElement element; + struct _GstGLSink + { + GstElement element; - GstPad *sinkpad; + GstPad *sinkpad; - gint frames_displayed; - guint64 frame_time; - gint width, height; - gboolean muted; - gint demo; // some kind of fun demo mode to let GL show its 3D capabilities - gboolean dumpvideo; // dump the video down to .ppm:s - GstBuffer *last_image; /* not thread safe ? */ - - GstClock *clock; + gint frames_displayed; + guint64 frame_time; + gint width, height; + gboolean muted; + gint demo; // some kind of fun demo mode to let GL show its 3D capabilities + gboolean dumpvideo; // dump the video down to .ppm:s + GstBuffer *last_image; /* not thread safe ? */ - GMutex *cache_lock; - GList *cache; - - /* plugins */ - GstImagePlugin* plugin; - GstImageConnection *conn; - - /* allow anybody to hook in here */ - GstImageInfo *hook; -}; + GstClock *clock; -struct _GstGLSinkClass { - GstElementClass parent_class; + GMutex *cache_lock; + GList *cache; - /* plugins */ - GList *plugins; -}; + /* plugins */ + GstImagePlugin *plugin; + GstImageConnection *conn; + + /* allow anybody to hook in here */ + GstImageInfo *hook; + }; + struct _GstGLSinkClass + { + GstElementClass parent_class; + + /* plugins */ + GList *plugins; + }; + + + static GType gst_glsink_get_type (void); + static void gst_glsink_base_init (gpointer g_class); + static void gst_glsink_class_init (GstGLSinkClass * klass); + static void gst_glsink_init (GstGLSink * sink); -static GType gst_glsink_get_type (void); -static void gst_glsink_base_init (gpointer g_class); -static void gst_glsink_class_init (GstGLSinkClass *klass); -static void gst_glsink_init (GstGLSink *sink); /* static void gst_glsink_dispose (GObject *object); */ -static void gst_glsink_chain (GstPad *pad, GstData *_data); -static void gst_glsink_set_clock (GstElement *element, GstClock *clock); -static GstElementStateReturn gst_glsink_change_state (GstElement *element); -static GstPadLinkReturn gst_glsink_sinkconnect (GstPad *pad, GstCaps *caps); -static GstCaps * gst_glsink_getcaps (GstPad *pad, GstCaps *caps); + static void gst_glsink_chain (GstPad * pad, GstData * _data); + static void gst_glsink_set_clock (GstElement * element, GstClock * clock); + static GstElementStateReturn gst_glsink_change_state (GstElement * + element); + static GstPadLinkReturn gst_glsink_sinkconnect (GstPad * pad, + GstCaps * caps); + static GstCaps *gst_glsink_getcaps (GstPad * pad, GstCaps * caps); -static void gst_glsink_set_property (GObject *object, guint prop_id, - const GValue *value, GParamSpec *pspec); -static void gst_glsink_get_property (GObject *object, guint prop_id, - GValue *value, GParamSpec *pspec); + static void gst_glsink_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec); + static void gst_glsink_get_property (GObject * object, guint prop_id, + GValue * value, GParamSpec * pspec); -static void gst_glsink_release_conn (GstGLSink *sink); -static void gst_glsink_append_cache (GstGLSink *sink, GstImageData *image); -static gboolean gst_glsink_set_caps (GstGLSink *sink, GstCaps *caps); + static void gst_glsink_release_conn (GstGLSink * sink); + static void gst_glsink_append_cache (GstGLSink * sink, + GstImageData * image); + static gboolean gst_glsink_set_caps (GstGLSink * sink, GstCaps * caps); /* prototypes from plugins */ -extern GstImagePlugin* get_gl_rgbimage_plugin (void); -extern GstImagePlugin* get_gl_nvimage_plugin (void); + extern GstImagePlugin *get_gl_rgbimage_plugin (void); + extern GstImagePlugin *get_gl_nvimage_plugin (void); + /* default output */ -extern void gst_glxwindow_new (GstGLSink *sink); -extern void gst_glxwindow_hook_context (GstImageInfo *info); -extern void gst_glxwindow_unhook_context (GstImageInfo *info); + extern void gst_glxwindow_new (GstGLSink * sink); + extern void gst_glxwindow_hook_context (GstImageInfo * info); + extern void gst_glxwindow_unhook_context (GstImageInfo * info); -static GstPadTemplate *sink_template; + static GstPadTemplate *sink_template; + + static GstElementClass *parent_class = NULL; -static GstElementClass *parent_class = NULL; /* static guint gst_glsink_signals[LAST_SIGNAL] = { 0 }; */ -static GType -gst_glsink_get_type (void) + static GType gst_glsink_get_type (void) { static GType videosink_type = 0; if (!videosink_type) { static const GTypeInfo videosink_info = { - sizeof(GstGLSinkClass), + sizeof (GstGLSinkClass), gst_glsink_base_init, NULL, (GClassInitFunc) gst_glsink_class_init, NULL, NULL, - sizeof(GstGLSink), + sizeof (GstGLSink), 0, (GInstanceInitFunc) gst_glsink_init, }; - videosink_type = g_type_register_static(GST_TYPE_ELEMENT, "GstGLSink", &videosink_info, 0); + videosink_type = + g_type_register_static (GST_TYPE_ELEMENT, "GstGLSink", &videosink_info, + 0); } return videosink_type; } @@ -189,56 +200,52 @@ static void gst_glsink_base_init (gpointer g_class) { GstElementClass *element_class = GST_ELEMENT_CLASS (g_class); - + gst_element_class_set_details (element_class, &gst_glsink_details); - gst_element_class_add_pad_template ( - element_class, - GST_PAD_TEMPLATE_GET (gst_glsink_sink_template_factory)); + gst_element_class_add_pad_template (element_class, + GST_PAD_TEMPLATE_GET (gst_glsink_sink_template_factory)); } static void -gst_glsink_class_init (GstGLSinkClass *klass) +gst_glsink_class_init (GstGLSinkClass * klass) { GObjectClass *gobject_class; GstElementClass *gstelement_class; gobject_class = (GObjectClass *) klass; - gstelement_class = (GstElementClass*) klass; + gstelement_class = (GstElementClass *) klass; parent_class = g_type_class_ref (GST_TYPE_ELEMENT); - g_object_class_install_property (gobject_class, ARG_WIDTH, - g_param_spec_int ("width", "Width", "The video width", - G_MININT, G_MAXINT, 0, G_PARAM_READABLE)); /* CHECKME */ - g_object_class_install_property (gobject_class, ARG_HEIGHT, - g_param_spec_int ("height", "Height", "The video height", - G_MININT, G_MAXINT, 0, G_PARAM_READABLE)); /* CHECKME */ - g_object_class_install_property (gobject_class, ARG_FRAMES_DISPLAYED, - g_param_spec_int ("frames_displayed", "Frames Displayed", "The number of frames displayed so far", - G_MININT,G_MAXINT, 0, G_PARAM_READWRITE)); /* CHECKME */ - g_object_class_install_property (gobject_class, ARG_FRAME_TIME, - g_param_spec_int ("frame_time", "Frame time", "The interval between frames", - G_MININT, G_MAXINT, 0, G_PARAM_READWRITE)); /* CHECKME */ + g_object_class_install_property (gobject_class, ARG_WIDTH, g_param_spec_int ("width", "Width", "The video width", G_MININT, G_MAXINT, 0, G_PARAM_READABLE)); /* CHECKME */ + g_object_class_install_property (gobject_class, ARG_HEIGHT, g_param_spec_int ("height", "Height", "The video height", G_MININT, G_MAXINT, 0, G_PARAM_READABLE)); /* CHECKME */ + g_object_class_install_property (gobject_class, ARG_FRAMES_DISPLAYED, g_param_spec_int ("frames_displayed", "Frames Displayed", "The number of frames displayed so far", G_MININT, G_MAXINT, 0, G_PARAM_READWRITE)); /* CHECKME */ + g_object_class_install_property (gobject_class, ARG_FRAME_TIME, g_param_spec_int ("frame_time", "Frame time", "The interval between frames", G_MININT, G_MAXINT, 0, G_PARAM_READWRITE)); /* CHECKME */ g_object_class_install_property (gobject_class, ARG_HOOK, - g_param_spec_pointer ("hook", "Hook", "The object receiving the output", G_PARAM_WRITABLE)); + g_param_spec_pointer ("hook", "Hook", "The object receiving the output", + G_PARAM_WRITABLE)); g_object_class_install_property (gobject_class, ARG_MUTE, - g_param_spec_boolean ("mute", "Mute", "mute the output ?", FALSE, G_PARAM_READWRITE)); + g_param_spec_boolean ("mute", "Mute", "mute the output ?", FALSE, + G_PARAM_READWRITE)); g_object_class_install_property (gobject_class, ARG_REPAINT, - g_param_spec_boolean ("repaint", "Repaint", "repaint the current frame", FALSE, G_PARAM_WRITABLE)); + g_param_spec_boolean ("repaint", "Repaint", "repaint the current frame", + FALSE, G_PARAM_WRITABLE)); g_object_class_install_property (gobject_class, ARG_DEMO, - g_param_spec_int ("demo", "Demo", "demo mode (shows 3D capabilities)",0, 1, 0, G_PARAM_READWRITE)); + g_param_spec_int ("demo", "Demo", "demo mode (shows 3D capabilities)", 0, + 1, 0, G_PARAM_READWRITE)); g_object_class_install_property (gobject_class, ARG_DUMP, - g_param_spec_boolean ("dump", "Dump", "stores sequence of frames in .ppm files", FALSE, G_PARAM_READWRITE)); + g_param_spec_boolean ("dump", "Dump", + "stores sequence of frames in .ppm files", FALSE, G_PARAM_READWRITE)); gobject_class->set_property = gst_glsink_set_property; gobject_class->get_property = gst_glsink_get_property; /*gobject_class->dispose = gst_glsink_dispose; */ - + gstelement_class->change_state = gst_glsink_change_state; gstelement_class->set_clock = gst_glsink_set_clock; - + /* plugins */ klass->plugins = NULL; klass->plugins = g_list_append (klass->plugins, get_gl_rgbimage_plugin ()); @@ -251,7 +258,7 @@ gst_glsink_class_init (GstGLSinkClass *klass) buffer upload */ static void -gst_glsink_init (GstGLSink *sink) +gst_glsink_init (GstGLSink * sink) { sink->sinkpad = gst_pad_new_from_template (sink_template, "sink"); gst_element_add_pad (GST_ELEMENT (sink), sink->sinkpad); @@ -264,53 +271,52 @@ gst_glsink_init (GstGLSink *sink) sink->width = 0; sink->height = 0; sink->muted = FALSE; - sink->clock = NULL; - GST_FLAG_SET(sink, GST_ELEMENT_THREAD_SUGGESTED); + sink->clock = NULL; + GST_FLAG_SET (sink, GST_ELEMENT_THREAD_SUGGESTED); GST_FLAG_SET (sink, GST_ELEMENT_EVENT_AWARE); - + /* create bufferpool and image cache */ GST_DEBUG ("glsink: creating bufferpool"); - sink->cache_lock = g_mutex_new(); - sink->cache = NULL; - + sink->cache_lock = g_mutex_new (); + sink->cache = NULL; + /* plugins */ sink->plugin = NULL; sink->conn = NULL; - + /* do initialization of default hook here */ - gst_glxwindow_new (sink); + gst_glxwindow_new (sink); //printf("GLSink_init: Current context %p\n", glXGetCurrentContext()); - gst_glxwindow_unhook_context(sink->hook); + gst_glxwindow_unhook_context (sink->hook); } /** frees the temporary connection that tests the window system capabilities */ static void -gst_glsink_release_conn (GstGLSink *sink) +gst_glsink_release_conn (GstGLSink * sink) { - if (sink->conn == NULL) return; - + if (sink->conn == NULL) + return; + /* free last image if any */ - if (sink->last_image != NULL) - { + if (sink->last_image != NULL) { gst_buffer_unref (sink->last_image); sink->last_image = NULL; } /* free cache */ g_mutex_lock (sink->cache_lock); - while (sink->cache) - { + while (sink->cache) { sink->plugin->free_image ((GstImageData *) sink->cache->data); sink->cache = g_list_delete_link (sink->cache, sink->cache); } g_mutex_unlock (sink->cache_lock); - + /* release connection */ sink->conn->free_conn (sink->conn); sink->conn = NULL; } -static void -gst_glsink_append_cache (GstGLSink *sink, GstImageData *image) +static void +gst_glsink_append_cache (GstGLSink * sink, GstImageData * image) { g_mutex_lock (sink->cache_lock); sink->cache = g_list_prepend (sink->cache, image); @@ -322,16 +328,16 @@ gst_glsink_append_cache (GstGLSink *sink, GstImageData *image) Create a new buffer to hand up the chain. This allows the plugins to make its own decoding buffers */ -static GstBuffer* -gst_glsink_buffer_new (GstBufferPool *pool, gint64 location, - guint size, gpointer user_data) +static GstBuffer * +gst_glsink_buffer_new (GstBufferPool * pool, gint64 location, + guint size, gpointer user_data) { GstGLSink *sink; GstBuffer *buffer; GstImageData *image; - + sink = GST_GLSINK (user_data); - + /* If cache is non-empty, get buffer from there */ if (sink->cache != NULL) { g_mutex_lock (sink->cache_lock); @@ -342,12 +348,12 @@ gst_glsink_buffer_new (GstBufferPool *pool, gint64 location, /* otherwise, get one from the plugin */ image = sink->plugin->get_image (sink->hook, sink->conn); } - + buffer = gst_buffer_new (); GST_BUFFER_DATA (buffer) = image->data; GST_BUFFER_SIZE (buffer) = image->size; GST_BUFFER_POOL_PRIVATE (buffer) = image; - + return buffer; } @@ -355,11 +361,15 @@ gst_glsink_buffer_new (GstBufferPool *pool, gint64 location, Free a buffer that the chain doesn't need anymore. */ static void -gst_glsink_buffer_free (GstBufferPool *pool, GstBuffer *buffer, gpointer user_data) +gst_glsink_buffer_free (GstBufferPool * pool, GstBuffer * buffer, + gpointer user_data) { - GstGLSink *sink = GST_GLSINK (gst_buffer_pool_get_user_data (GST_BUFFER_BUFFERPOOL (buffer))); + GstGLSink *sink = + GST_GLSINK (gst_buffer_pool_get_user_data (GST_BUFFER_BUFFERPOOL + (buffer))); - gst_glsink_append_cache (sink, (GstImageData *) GST_BUFFER_POOL_PRIVATE (buffer)); + gst_glsink_append_cache (sink, + (GstImageData *) GST_BUFFER_POOL_PRIVATE (buffer)); /* set to NULL so the data is not freed */ GST_BUFFER_DATA (buffer) = NULL; @@ -373,23 +383,23 @@ gst_glsink_buffer_free (GstBufferPool *pool, GstBuffer *buffer, gpointer user_da Go through the plugin list, finding the plugin that first fits the given parameters */ static gboolean -gst_glsink_set_caps (GstGLSink *sink, GstCaps *caps) +gst_glsink_set_caps (GstGLSink * sink, GstCaps * caps) { - g_warning("in glsink set caps!\n"); - printf("Getting GLstring, context is %p\n", glXGetCurrentContext()); - + g_warning ("in glsink set caps!\n"); + printf ("Getting GLstring, context is %p\n", glXGetCurrentContext ()); + GList *list = ((GstGLSinkClass *) G_OBJECT_GET_CLASS (sink))->plugins; GstImageConnection *conn = NULL; - while (list) - { - printf("AGetting GLstring, context is %p\n", glXGetCurrentContext()); + + while (list) { + printf ("AGetting GLstring, context is %p\n", glXGetCurrentContext ()); GstImagePlugin *plugin = (GstImagePlugin *) list->data; - if ((conn = plugin->set_caps (sink->hook, caps)) != NULL) - { + + if ((conn = plugin->set_caps (sink->hook, caps)) != NULL) { //gst_glsink_release_conn (sink); - printf("BGetting GLstring, context is %p\n", glXGetCurrentContext()); + printf ("BGetting GLstring, context is %p\n", glXGetCurrentContext ()); sink->conn = conn; - printf("CGetting GLstring, context is %p\n", glXGetCurrentContext()); + printf ("CGetting GLstring, context is %p\n", glXGetCurrentContext ()); sink->plugin = plugin; sink->conn->open_conn (sink->conn, sink->hook); return TRUE; @@ -403,9 +413,9 @@ gst_glsink_set_caps (GstGLSink *sink, GstCaps *caps) Link the input video sink internally. */ static GstPadLinkReturn -gst_glsink_sinkconnect (GstPad *pad, GstCaps *caps) +gst_glsink_sinkconnect (GstPad * pad, GstCaps * caps) { - g_warning("in glsink sinkconnect!\n"); + g_warning ("in glsink sinkconnect!\n"); GstGLSink *sink; guint32 fourcc, print_format, result; @@ -414,25 +424,24 @@ gst_glsink_sinkconnect (GstPad *pad, GstCaps *caps) /* we are not going to act on variable caps */ if (!GST_CAPS_IS_FIXED (caps)) return GST_PAD_LINK_DELAYED; - - gst_glxwindow_hook_context(sink->hook); + + gst_glxwindow_hook_context (sink->hook); /* try to set the caps on the output */ result = gst_glsink_set_caps (sink, caps); - gst_glxwindow_unhook_context(sink->hook); + gst_glxwindow_unhook_context (sink->hook); + + if (result == FALSE) { + return GST_PAD_LINK_REFUSED; + } - if (result == FALSE) - { - return GST_PAD_LINK_REFUSED; - } - /* remember width & height */ gst_caps_get_int (caps, "width", &sink->width); gst_caps_get_int (caps, "height", &sink->height); gst_caps_get_fourcc_int (caps, "format", &fourcc); print_format = GULONG_FROM_LE (fourcc); - GST_DEBUG ("glsink: setting %08x (%4.4s) %dx%d\n", - fourcc, (gchar*)&print_format, sink->width, sink->height); + GST_DEBUG ("glsink: setting %08x (%4.4s) %dx%d\n", + fourcc, (gchar *) & print_format, sink->width, sink->height); /* emit signal */ g_object_freeze_notify (G_OBJECT (sink)); @@ -443,34 +452,35 @@ gst_glsink_sinkconnect (GstPad *pad, GstCaps *caps) return GST_PAD_LINK_OK; } static GstCaps * -gst_glsink_getcaps (GstPad *pad, GstCaps *caps) +gst_glsink_getcaps (GstPad * pad, GstCaps * caps) { - g_warning("in glsink get caps!\n"); + g_warning ("in glsink get caps!\n"); /* what is the "caps" parameter good for? */ GstGLSink *sink = GST_GLSINK (gst_pad_get_parent (pad)); GstCaps *ret = NULL; GList *list = ((GstGLSinkClass *) G_OBJECT_GET_CLASS (sink))->plugins; - - gst_glxwindow_hook_context(sink->hook); - while (list) - { - ret = gst_caps_append (ret, ((GstImagePlugin *) list->data)->get_caps (sink->hook)); + + gst_glxwindow_hook_context (sink->hook); + while (list) { + ret = + gst_caps_append (ret, + ((GstImagePlugin *) list->data)->get_caps (sink->hook)); list = g_list_next (list); } - gst_glxwindow_unhook_context(sink->hook); + gst_glxwindow_unhook_context (sink->hook); return ret; } static void -gst_glsink_set_clock (GstElement *element, GstClock *clock) +gst_glsink_set_clock (GstElement * element, GstClock * clock) { GstGLSink *sink = GST_GLSINK (element); - + sink->clock = clock; } static void -gst_glsink_chain (GstPad *pad, GstData *_data) +gst_glsink_chain (GstPad * pad, GstData * _data) { //g_warning("in glsink_chain!\n"); GstBuffer *buf = GST_BUFFER (_data); @@ -489,30 +499,30 @@ gst_glsink_chain (GstPad *pad, GstData *_data) switch (GST_EVENT_TYPE (event)) { default: - gst_pad_event_default (pad, event); + gst_pad_event_default (pad, event); } return; } - GST_DEBUG ("glsink: clock wait: %llu %u", - GST_BUFFER_TIMESTAMP (buf), GST_BUFFER_SIZE (buf)); + GST_DEBUG ("glsink: clock wait: %llu %u", + GST_BUFFER_TIMESTAMP (buf), GST_BUFFER_SIZE (buf)); #if 0 GstClockTime time = GST_BUFFER_TIMESTAMP (buf); static int frame_drops = 0; if (sink->clock && time != -1) { - if (time < gst_clock_get_time(sink->clock)) - { - g_warning("Frame drop (%d consecutive) !!", frame_drops); - /* we are going to drop late buffers */ - gst_buffer_unref (buf); - frame_drops++; - return; - } - frame_drops = 0; // we made it - reset time + if (time < gst_clock_get_time (sink->clock)) { + g_warning ("Frame drop (%d consecutive) !!", frame_drops); + /* we are going to drop late buffers */ + gst_buffer_unref (buf); + frame_drops++; + return; + } + frame_drops = 0; // we made it - reset time GstClockReturn ret; - GstClockID id = gst_clock_new_single_shot_id (sink->clock, GST_BUFFER_TIMESTAMP (buf)); + GstClockID id = + gst_clock_new_single_shot_id (sink->clock, GST_BUFFER_TIMESTAMP (buf)); ret = gst_element_clock_wait (GST_ELEMENT (sink), id, NULL); gst_clock_id_free (id); @@ -529,71 +539,74 @@ gst_glsink_chain (GstPad *pad, GstData *_data) sink->frames_displayed++; g_object_notify (G_OBJECT (sink), "frames_displayed"); - if (!sink->muted) - { - if (glXGetCurrentContext() == NULL) - { - printf("Rehooking window !\n"); - gst_glxwindow_hook_context(sink->hook); + if (!sink->muted) { + if (glXGetCurrentContext () == NULL) { + printf ("Rehooking window !\n"); + gst_glxwindow_hook_context (sink->hook); #if 1 - GST_DEBUG("Initializing OpenGL parameters\n"); - /* initialize OpenGL drawing */ - glEnable(GL_DEPTH_TEST); - glEnable(GL_TEXTURE_2D); - glClearDepth(1.0f); - glClearColor(0, 0, 0, 0); - - glEnable(GL_AUTO_NORMAL); // let OpenGL generate the Normals - - glDisable(GL_BLEND); - glDisable(GL_CULL_FACE); - glPolygonMode(GL_FRONT, GL_FILL); - glPolygonMode(GL_BACK, GL_FILL); - - glShadeModel(GL_SMOOTH); - glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST); - - GstGLImageInfo *window = (GstGLImageInfo *)sink->hook; - int w=window->width, h = window->height; - - glViewport(0, 0, (GLint) w, (GLint) h); - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - - GLfloat aspect = (GLfloat) w / (GLfloat) h; - glFrustum(-aspect, aspect, -1.0, 1.0, 5.0, 500.0); + GST_DEBUG ("Initializing OpenGL parameters\n"); + /* initialize OpenGL drawing */ + glEnable (GL_DEPTH_TEST); + glEnable (GL_TEXTURE_2D); + glClearDepth (1.0f); + glClearColor (0, 0, 0, 0); + + glEnable (GL_AUTO_NORMAL); // let OpenGL generate the Normals + + glDisable (GL_BLEND); + glDisable (GL_CULL_FACE); + glPolygonMode (GL_FRONT, GL_FILL); + glPolygonMode (GL_BACK, GL_FILL); + + glShadeModel (GL_SMOOTH); + glHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); + + GstGLImageInfo *window = (GstGLImageInfo *) sink->hook; + int w = window->width, h = window->height; + + glViewport (0, 0, (GLint) w, (GLint) h); + glMatrixMode (GL_PROJECTION); + glLoadIdentity (); + + GLfloat aspect = (GLfloat) w / (GLfloat) h; + + glFrustum (-aspect, aspect, -1.0, 1.0, 5.0, 500.0); #endif - gst_glxwindow_unhook_context(sink->hook); - gst_glxwindow_hook_context(sink->hook); - glMatrixMode(GL_MODELVIEW); -#if 0 - sink->hook->free_info(sink->hook); - printf("Reallocating window brutally !\n"); - gst_glxwindow_new(sink); + gst_glxwindow_unhook_context (sink->hook); + gst_glxwindow_hook_context (sink->hook); + glMatrixMode (GL_MODELVIEW); +#if 0 + sink->hook->free_info (sink->hook); + printf ("Reallocating window brutally !\n"); + gst_glxwindow_new (sink); #endif - } - + } + /* free last_image, if any */ if (sink->last_image != NULL) gst_buffer_unref (sink->last_image); if (sink->bufferpool && GST_BUFFER_BUFFERPOOL (buf) == sink->bufferpool) { - + // awful hack ! But I currently have no other solution without changing the API sink->hook->demo = sink->demo; sink->hook->dumpvideo = sink->dumpvideo; - sink->plugin->put_image (sink->hook, (GstImageData *) GST_BUFFER_POOL_PRIVATE (buf)); + sink->plugin->put_image (sink->hook, + (GstImageData *) GST_BUFFER_POOL_PRIVATE (buf)); sink->last_image = buf; } else { - buffer = gst_buffer_new_from_pool (gst_glsink_get_bufferpool (sink->sinkpad), - 0, GST_BUFFER_SIZE (buf)); - memcpy (GST_BUFFER_DATA (buffer), GST_BUFFER_DATA (buf), - GST_BUFFER_SIZE (buf) > GST_BUFFER_SIZE (buffer) ? - GST_BUFFER_SIZE (buffer) : GST_BUFFER_SIZE (buf)); + buffer = + gst_buffer_new_from_pool (gst_glsink_get_bufferpool (sink->sinkpad), + 0, GST_BUFFER_SIZE (buf)); + memcpy (GST_BUFFER_DATA (buffer), GST_BUFFER_DATA (buf), + GST_BUFFER_SIZE (buf) > + GST_BUFFER_SIZE (buffer) ? GST_BUFFER_SIZE (buffer) : + GST_BUFFER_SIZE (buf)); - sink->plugin->put_image (sink->hook, (GstImageData *) GST_BUFFER_POOL_PRIVATE (buffer)); + sink->plugin->put_image (sink->hook, + (GstImageData *) GST_BUFFER_POOL_PRIVATE (buffer)); sink->last_image = buffer; gst_buffer_unref (buf); @@ -601,12 +614,13 @@ gst_glsink_chain (GstPad *pad, GstData *_data) //gst_glxwindow_unhook_context(sink->hook); } - + } static void -gst_glsink_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) +gst_glsink_set_property (GObject * object, guint prop_id, const GValue * value, + GParamSpec * pspec) { //g_warning("in set_property!\n"); GstGLSink *sink; @@ -625,8 +639,7 @@ gst_glsink_set_property (GObject *object, guint prop_id, const GValue *value, GP sink->frame_time = g_value_get_int (value); break; case ARG_HOOK: - if (sink->hook) - { + if (sink->hook) { sink->hook->free_info (sink->hook); } sink->hook = g_value_get_pointer (value); @@ -645,7 +658,8 @@ gst_glsink_set_property (GObject *object, guint prop_id, const GValue *value, GP break; case ARG_REPAINT: if (sink->last_image != NULL) { - sink->plugin->put_image (sink->hook, (GstImageData *) GST_BUFFER_POOL_PRIVATE (sink->last_image)); + sink->plugin->put_image (sink->hook, + (GstImageData *) GST_BUFFER_POOL_PRIVATE (sink->last_image)); } break; default: @@ -655,13 +669,14 @@ gst_glsink_set_property (GObject *object, guint prop_id, const GValue *value, GP } static void -gst_glsink_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) +gst_glsink_get_property (GObject * object, guint prop_id, GValue * value, + GParamSpec * pspec) { //g_warning("in get_property!\n"); GstGLSink *sink; /* it's not null if we got it, but it might not be ours */ - sink = GST_GLSINK(object); + sink = GST_GLSINK (object); switch (prop_id) { case ARG_WIDTH: @@ -674,7 +689,7 @@ gst_glsink_get_property (GObject *object, guint prop_id, GValue *value, GParamSp g_value_set_int (value, sink->frames_displayed); break; case ARG_FRAME_TIME: - g_value_set_int (value, sink->frame_time/1000000); + g_value_set_int (value, sink->frame_time / 1000000); break; case ARG_MUTE: g_value_set_boolean (value, sink->muted); @@ -685,7 +700,7 @@ gst_glsink_get_property (GObject *object, guint prop_id, GValue *value, GParamSp case ARG_DUMP: g_value_set_boolean (value, sink->dumpvideo); break; - default: + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } @@ -693,7 +708,7 @@ gst_glsink_get_property (GObject *object, guint prop_id, GValue *value, GParamSp static GstElementStateReturn -gst_glsink_change_state (GstElement *element) +gst_glsink_change_state (GstElement * element) { //g_warning("in change_state!\n"); GstGLSink *sink; @@ -704,23 +719,23 @@ gst_glsink_change_state (GstElement *element) case GST_STATE_NULL_TO_READY: break; case GST_STATE_READY_TO_PAUSED: - { - //g_warning("Going GST_STATE_READY_TO_PAUSED: %p", sink->conn); - } + { + //g_warning("Going GST_STATE_READY_TO_PAUSED: %p", sink->conn); + } break; case GST_STATE_PAUSED_TO_PLAYING: - { - //g_warning("Going GST_STATE_PAUSED_TO_PLAYING: %p", sink->conn); - } + { + //g_warning("Going GST_STATE_PAUSED_TO_PLAYING: %p", sink->conn); + } break; case GST_STATE_PLAYING_TO_PAUSED: break; case GST_STATE_PAUSED_TO_READY: if (sink->conn) - sink->conn->close_conn (sink->conn, sink->hook); + sink->conn->close_conn (sink->conn, sink->hook); if (sink->last_image) { gst_buffer_unref (sink->last_image); - sink->last_image = NULL; + sink->last_image = NULL; } break; case GST_STATE_READY_TO_NULL: @@ -734,18 +749,15 @@ gst_glsink_change_state (GstElement *element) } static gboolean -plugin_init (GstPlugin *plugin) +plugin_init (GstPlugin * plugin) { /* Loading the library containing GstVideoSink, our parent object */ if (!gst_library_load ("gstvideo")) return FALSE; /* this is needed later on in the _real_ init (during a gst-launch) */ - sink_template = gst_pad_template_new ( - "sink", - GST_PAD_SINK, - GST_PAD_ALWAYS, - NULL); + sink_template = gst_pad_template_new ("sink", + GST_PAD_SINK, GST_PAD_ALWAYS, NULL); if (!gst_element_register (plugin, "glsink", GST_RANK_NONE, GST_TYPE_GLSINK)) return FALSE; @@ -753,14 +765,8 @@ plugin_init (GstPlugin *plugin) return TRUE; } -GST_PLUGIN_DEFINE ( - GST_VERSION_MAJOR, - GST_VERSION_MINOR, - "glsink", - "An OpenGL based video sink - uses OpenGL and GLX to draw video, utilizing different acceleration options", - plugin_init, - VERSION, - GST_LICENSE, - GST_PACKAGE, - GST_ORIGIN -); +GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, + GST_VERSION_MINOR, + "glsink", + "An OpenGL based video sink - uses OpenGL and GLX to draw video, utilizing different acceleration options", + plugin_init, VERSION, GST_LICENSE, GST_PACKAGE, GST_ORIGIN); |