From: Philippe Kalaf Date: Sat, 16 Jul 2005 15:41:04 +0000 (+0000) Subject: gst/elements/gstfdsrc.c gst/elements/gstfdsrc.h gst/elements/gstelements.c gst/elemen... X-Git-Tag: RELEASE-0_9_2~225 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4b888578a0024bae33c7ddaf91de0cafea8b733f;p=platform%2Fupstream%2Fgstreamer.git gst/elements/gstfdsrc.c gst/elements/gstfdsrc.h gst/elements/gstelements.c gst/elements/Makefile.am Original commit message from CVS: 2005-07-16 Philippe Khalaf * gst/elements/gstfdsrc.c * gst/elements/gstfdsrc.h * gst/elements/gstelements.c * gst/elements/Makefile.am Ported fdsrc to 0.9. --- diff --git a/gst/elements/Makefile.am b/gst/elements/Makefile.am index 1c7d194..f1efc28 100644 --- a/gst/elements/Makefile.am +++ b/gst/elements/Makefile.am @@ -14,6 +14,7 @@ libgstelements_la_SOURCES = \ gstfakesink.c \ gstfilesink.c \ gstfilesrc.c \ + gstfdsrc.c \ gstidentity.c \ gstelements.c \ gsttee.c \ @@ -31,6 +32,7 @@ noinst_HEADERS = \ gstfakesrc.h \ gstfilesink.h \ gstfilesrc.h \ + gstfdsrc.h \ gstidentity.h \ gsttee.h \ gsttypefindelement.h diff --git a/gst/elements/gstelements.c b/gst/elements/gstelements.c index ba1d02d..256af9a 100644 --- a/gst/elements/gstelements.c +++ b/gst/elements/gstelements.c @@ -31,6 +31,7 @@ #include "gstfakesrc.h" #include "gstfilesink.h" #include "gstfilesrc.h" +#include "gstfdsrc.h" #include "gstidentity.h" #include "gsttee.h" #include "gsttypefindelement.h" @@ -51,6 +52,7 @@ static struct _elements_entry _elements[] = { {"fakesrc", GST_RANK_NONE, gst_fake_src_get_type}, {"fakesink", GST_RANK_NONE, gst_fake_sink_get_type}, {"filesrc", GST_RANK_NONE, gst_file_src_get_type}, + {"fdsrc", GST_RANK_NONE, gst_fdsrc_get_type}, {"identity", GST_RANK_NONE, gst_identity_get_type}, {"filesink", GST_RANK_NONE, gst_file_sink_get_type}, {"tee", GST_RANK_NONE, gst_tee_get_type}, diff --git a/gst/elements/gstfdsrc.c b/gst/elements/gstfdsrc.c index b61498e..f530388 100644 --- a/gst/elements/gstfdsrc.c +++ b/gst/elements/gstfdsrc.c @@ -1,6 +1,7 @@ /* GStreamer * Copyright (C) 1999,2000 Erik Walthinsen * 2000 Wim Taymans + * 2005 Philippe Khalaf * * gstfdsrc.c: * @@ -73,7 +74,7 @@ static guint gst_fdsrc_signals[LAST_SIGNAL] = { 0 }; #define _do_init(bla) \ GST_DEBUG_CATEGORY_INIT (gst_fdsrc_debug, "fdsrc", 0, "fdsrc element"); -GST_BOILERPLATE_FULL (GstFdSrc, gst_fdsrc, GstElement, GST_TYPE_ELEMENT, +GST_BOILERPLATE_FULL (GstFdSrc, gst_fdsrc, GstElement, GST_TYPE_PUSH_SRC, _do_init); static void gst_fdsrc_set_property (GObject * object, guint prop_id, @@ -83,8 +84,7 @@ static void gst_fdsrc_get_property (GObject * object, guint prop_id, static GstElementStateReturn gst_fdsrc_change_state (GstElement * element); -static GstData *gst_fdsrc_get (GstPad * pad); - +static GstFlowReturn gst_fdsrc_create (GstPushSrc * psrc, GstBuffer ** outbuf); static void gst_fdsrc_base_init (gpointer g_class) @@ -99,9 +99,15 @@ static void gst_fdsrc_class_init (GstFdSrcClass * klass) { GObjectClass *gobject_class; + GstBaseSrcClass *gstbasesrc_class; GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass); + GstPushSrcClass *gstpush_src_class; gobject_class = G_OBJECT_CLASS (klass); + gstbasesrc_class = (GstBaseSrcClass *) klass; + gstpush_src_class = (GstPushSrcClass *) klass; + + parent_class = g_type_class_ref (GST_TYPE_PUSH_SRC); gobject_class->set_property = gst_fdsrc_set_property; gobject_class->get_property = gst_fdsrc_get_property; @@ -123,17 +129,16 @@ gst_fdsrc_class_init (GstFdSrcClass * klass) g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); gstelement_class->change_state = gst_fdsrc_change_state; + + gstpush_src_class->create = gst_fdsrc_create; + } static void gst_fdsrc_init (GstFdSrc * fdsrc) { - fdsrc->srcpad = - gst_pad_new_from_template (gst_static_pad_template_get (&srctemplate), - "src"); - - gst_pad_set_get_function (fdsrc->srcpad, gst_fdsrc_get); - gst_element_add_pad (GST_ELEMENT (fdsrc), fdsrc->srcpad); + // TODO set live only if it's actually a live source + gst_base_src_set_live (GST_BASE_SRC (fdsrc), TRUE); fdsrc->fd = 0; fdsrc->curoffset = 0; @@ -220,8 +225,8 @@ gst_fdsrc_get_property (GObject * object, guint prop_id, GValue * value, } } -static GstData * -gst_fdsrc_get (GstPad * pad) +static GstFlowReturn +gst_fdsrc_create (GstPushSrc * psrc, GstBuffer ** outbuf) { GstFdSrc *src; GstBuffer *buf; @@ -233,7 +238,7 @@ gst_fdsrc_get (GstPad * pad) gint retval; #endif - src = GST_FDSRC (gst_pad_get_parent (pad)); + src = GST_FDSRC (psrc); /* create the buffer */ buf = gst_buffer_new_and_alloc (src->blocksize); @@ -254,12 +259,10 @@ gst_fdsrc_get (GstPad * pad) if (retval == -1) { GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL), ("select on file descriptor: %s.", g_strerror (errno))); - gst_element_set_eos (GST_ELEMENT (src)); - return GST_DATA (gst_event_new (GST_EVENT_EOS)); + return GST_FLOW_ERROR; } else if (retval == 0) { g_signal_emit (G_OBJECT (src), gst_fdsrc_signals[SIGNAL_TIMEOUT], 0); - gst_element_set_eos (GST_ELEMENT (src)); - return GST_DATA (gst_event_new (GST_EVENT_EOS)); + return GST_FLOW_ERROR; } #endif @@ -274,14 +277,13 @@ gst_fdsrc_get (GstPad * pad) src->curoffset += readbytes; /* we're done, return the buffer */ - return GST_DATA (buf); + *outbuf = buf; + return GST_FLOW_OK; } else if (readbytes == 0) { - gst_element_set_eos (GST_ELEMENT (src)); - return GST_DATA (gst_event_new (GST_EVENT_EOS)); + return GST_FLOW_ERROR; } else { GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL), ("read on file descriptor: %s.", g_strerror (errno))); - gst_element_set_eos (GST_ELEMENT (src)); - return GST_DATA (gst_event_new (GST_EVENT_EOS)); + return GST_FLOW_ERROR; } } diff --git a/gst/elements/gstfdsrc.h b/gst/elements/gstfdsrc.h index 3bb9e78..0004242 100644 --- a/gst/elements/gstfdsrc.h +++ b/gst/elements/gstfdsrc.h @@ -1,6 +1,7 @@ /* GStreamer * Copyright (C) 1999,2000 Erik Walthinsen * 2000 Wim Taymans + * 2005 Philippe Khalaf * * gstfdsrc.h: * @@ -25,6 +26,7 @@ #define __GST_FDSRC_H__ #include +#include G_BEGIN_DECLS @@ -45,9 +47,7 @@ typedef struct _GstFdSrc GstFdSrc; typedef struct _GstFdSrcClass GstFdSrcClass; struct _GstFdSrc { - GstElement element; - /* pads */ - GstPad *srcpad; + GstPushSrc element; /* fd */ gint fd; @@ -60,7 +60,7 @@ struct _GstFdSrc { }; struct _GstFdSrcClass { - GstElementClass parent_class; + GstPushSrcClass parent_class; /* signals */ void (*timeout) (GstElement *element); diff --git a/plugins/elements/Makefile.am b/plugins/elements/Makefile.am index 1c7d194..f1efc28 100644 --- a/plugins/elements/Makefile.am +++ b/plugins/elements/Makefile.am @@ -14,6 +14,7 @@ libgstelements_la_SOURCES = \ gstfakesink.c \ gstfilesink.c \ gstfilesrc.c \ + gstfdsrc.c \ gstidentity.c \ gstelements.c \ gsttee.c \ @@ -31,6 +32,7 @@ noinst_HEADERS = \ gstfakesrc.h \ gstfilesink.h \ gstfilesrc.h \ + gstfdsrc.h \ gstidentity.h \ gsttee.h \ gsttypefindelement.h diff --git a/plugins/elements/gstelements.c b/plugins/elements/gstelements.c index ba1d02d..256af9a 100644 --- a/plugins/elements/gstelements.c +++ b/plugins/elements/gstelements.c @@ -31,6 +31,7 @@ #include "gstfakesrc.h" #include "gstfilesink.h" #include "gstfilesrc.h" +#include "gstfdsrc.h" #include "gstidentity.h" #include "gsttee.h" #include "gsttypefindelement.h" @@ -51,6 +52,7 @@ static struct _elements_entry _elements[] = { {"fakesrc", GST_RANK_NONE, gst_fake_src_get_type}, {"fakesink", GST_RANK_NONE, gst_fake_sink_get_type}, {"filesrc", GST_RANK_NONE, gst_file_src_get_type}, + {"fdsrc", GST_RANK_NONE, gst_fdsrc_get_type}, {"identity", GST_RANK_NONE, gst_identity_get_type}, {"filesink", GST_RANK_NONE, gst_file_sink_get_type}, {"tee", GST_RANK_NONE, gst_tee_get_type}, diff --git a/plugins/elements/gstfdsrc.c b/plugins/elements/gstfdsrc.c index b61498e..f530388 100644 --- a/plugins/elements/gstfdsrc.c +++ b/plugins/elements/gstfdsrc.c @@ -1,6 +1,7 @@ /* GStreamer * Copyright (C) 1999,2000 Erik Walthinsen * 2000 Wim Taymans + * 2005 Philippe Khalaf * * gstfdsrc.c: * @@ -73,7 +74,7 @@ static guint gst_fdsrc_signals[LAST_SIGNAL] = { 0 }; #define _do_init(bla) \ GST_DEBUG_CATEGORY_INIT (gst_fdsrc_debug, "fdsrc", 0, "fdsrc element"); -GST_BOILERPLATE_FULL (GstFdSrc, gst_fdsrc, GstElement, GST_TYPE_ELEMENT, +GST_BOILERPLATE_FULL (GstFdSrc, gst_fdsrc, GstElement, GST_TYPE_PUSH_SRC, _do_init); static void gst_fdsrc_set_property (GObject * object, guint prop_id, @@ -83,8 +84,7 @@ static void gst_fdsrc_get_property (GObject * object, guint prop_id, static GstElementStateReturn gst_fdsrc_change_state (GstElement * element); -static GstData *gst_fdsrc_get (GstPad * pad); - +static GstFlowReturn gst_fdsrc_create (GstPushSrc * psrc, GstBuffer ** outbuf); static void gst_fdsrc_base_init (gpointer g_class) @@ -99,9 +99,15 @@ static void gst_fdsrc_class_init (GstFdSrcClass * klass) { GObjectClass *gobject_class; + GstBaseSrcClass *gstbasesrc_class; GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass); + GstPushSrcClass *gstpush_src_class; gobject_class = G_OBJECT_CLASS (klass); + gstbasesrc_class = (GstBaseSrcClass *) klass; + gstpush_src_class = (GstPushSrcClass *) klass; + + parent_class = g_type_class_ref (GST_TYPE_PUSH_SRC); gobject_class->set_property = gst_fdsrc_set_property; gobject_class->get_property = gst_fdsrc_get_property; @@ -123,17 +129,16 @@ gst_fdsrc_class_init (GstFdSrcClass * klass) g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); gstelement_class->change_state = gst_fdsrc_change_state; + + gstpush_src_class->create = gst_fdsrc_create; + } static void gst_fdsrc_init (GstFdSrc * fdsrc) { - fdsrc->srcpad = - gst_pad_new_from_template (gst_static_pad_template_get (&srctemplate), - "src"); - - gst_pad_set_get_function (fdsrc->srcpad, gst_fdsrc_get); - gst_element_add_pad (GST_ELEMENT (fdsrc), fdsrc->srcpad); + // TODO set live only if it's actually a live source + gst_base_src_set_live (GST_BASE_SRC (fdsrc), TRUE); fdsrc->fd = 0; fdsrc->curoffset = 0; @@ -220,8 +225,8 @@ gst_fdsrc_get_property (GObject * object, guint prop_id, GValue * value, } } -static GstData * -gst_fdsrc_get (GstPad * pad) +static GstFlowReturn +gst_fdsrc_create (GstPushSrc * psrc, GstBuffer ** outbuf) { GstFdSrc *src; GstBuffer *buf; @@ -233,7 +238,7 @@ gst_fdsrc_get (GstPad * pad) gint retval; #endif - src = GST_FDSRC (gst_pad_get_parent (pad)); + src = GST_FDSRC (psrc); /* create the buffer */ buf = gst_buffer_new_and_alloc (src->blocksize); @@ -254,12 +259,10 @@ gst_fdsrc_get (GstPad * pad) if (retval == -1) { GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL), ("select on file descriptor: %s.", g_strerror (errno))); - gst_element_set_eos (GST_ELEMENT (src)); - return GST_DATA (gst_event_new (GST_EVENT_EOS)); + return GST_FLOW_ERROR; } else if (retval == 0) { g_signal_emit (G_OBJECT (src), gst_fdsrc_signals[SIGNAL_TIMEOUT], 0); - gst_element_set_eos (GST_ELEMENT (src)); - return GST_DATA (gst_event_new (GST_EVENT_EOS)); + return GST_FLOW_ERROR; } #endif @@ -274,14 +277,13 @@ gst_fdsrc_get (GstPad * pad) src->curoffset += readbytes; /* we're done, return the buffer */ - return GST_DATA (buf); + *outbuf = buf; + return GST_FLOW_OK; } else if (readbytes == 0) { - gst_element_set_eos (GST_ELEMENT (src)); - return GST_DATA (gst_event_new (GST_EVENT_EOS)); + return GST_FLOW_ERROR; } else { GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL), ("read on file descriptor: %s.", g_strerror (errno))); - gst_element_set_eos (GST_ELEMENT (src)); - return GST_DATA (gst_event_new (GST_EVENT_EOS)); + return GST_FLOW_ERROR; } } diff --git a/plugins/elements/gstfdsrc.h b/plugins/elements/gstfdsrc.h index 3bb9e78..0004242 100644 --- a/plugins/elements/gstfdsrc.h +++ b/plugins/elements/gstfdsrc.h @@ -1,6 +1,7 @@ /* GStreamer * Copyright (C) 1999,2000 Erik Walthinsen * 2000 Wim Taymans + * 2005 Philippe Khalaf * * gstfdsrc.h: * @@ -25,6 +26,7 @@ #define __GST_FDSRC_H__ #include +#include G_BEGIN_DECLS @@ -45,9 +47,7 @@ typedef struct _GstFdSrc GstFdSrc; typedef struct _GstFdSrcClass GstFdSrcClass; struct _GstFdSrc { - GstElement element; - /* pads */ - GstPad *srcpad; + GstPushSrc element; /* fd */ gint fd; @@ -60,7 +60,7 @@ struct _GstFdSrc { }; struct _GstFdSrcClass { - GstElementClass parent_class; + GstPushSrcClass parent_class; /* signals */ void (*timeout) (GstElement *element);