From: Thomas Vander Stichele Date: Mon, 11 Jul 2005 15:06:27 +0000 (+0000) Subject: add num-buffers property to basesrc X-Git-Tag: RELEASE-0_9_2~257 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=aff85422dc794e0068b8ee7601bbbc6240b9e48f;p=platform%2Fupstream%2Fgstreamer.git add num-buffers property to basesrc Original commit message from CVS: add num-buffers property to basesrc --- diff --git a/ChangeLog b/ChangeLog index b7da1de..545df6d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2005-07-11 Thomas Vander Stichele + + * docs/gst/tmpl/gstbasesrc.sgml: + * docs/gst/tmpl/gstfakesrc.sgml: + * gst/base/gstbasesrc.c: (gst_base_src_class_init), + (gst_base_src_init), (gst_base_src_set_property), + (gst_base_src_get_property), (gst_base_src_get_range), + (gst_base_src_start): + * gst/base/gstbasesrc.h: + add num-buffers property + * gst/elements/gstfakesrc.c: (gst_fakesrc_class_init), + (gst_fakesrc_init), (gst_fakesrc_set_property), + (gst_fakesrc_get_property), (gst_fakesrc_create), + (gst_fakesrc_start): + remove num-buffers property + 2005-07-10 Thomas Vander Stichele * docs/gst/gstreamer-sections.txt: diff --git a/docs/gst/tmpl/gstbasesrc.sgml b/docs/gst/tmpl/gstbasesrc.sgml index f89f8b6..949ef42 100644 --- a/docs/gst/tmpl/gstbasesrc.sgml +++ b/docs/gst/tmpl/gstbasesrc.sgml @@ -35,6 +35,8 @@ GstBaseSrc @segment_loop: @offset: @size: +@num_buffers: +@num_buffers_left: @@ -51,6 +53,11 @@ GstBaseSrc + + + + + diff --git a/docs/gst/tmpl/gstfakesrc.sgml b/docs/gst/tmpl/gstfakesrc.sgml index ad368cf..e78986e 100644 --- a/docs/gst/tmpl/gstfakesrc.sgml +++ b/docs/gst/tmpl/gstfakesrc.sgml @@ -68,11 +68,6 @@ GstFakeSrc - - - - - diff --git a/gst/base/gstbasesrc.c b/gst/base/gstbasesrc.c index 0a37e08..197a4dd 100644 --- a/gst/base/gstbasesrc.c +++ b/gst/base/gstbasesrc.c @@ -33,6 +33,7 @@ #include #define DEFAULT_BLOCKSIZE 4096 +#define DEFAULT_NUM_BUFFERS -1 GST_DEBUG_CATEGORY_STATIC (gst_base_src_debug); #define GST_CAT_DEFAULT gst_base_src_debug @@ -50,6 +51,7 @@ enum PROP_BLOCKSIZE, PROP_HAS_LOOP, PROP_HAS_GETRANGE, + PROP_NUM_BUFFERS, }; static GstElementClass *parent_class = NULL; @@ -150,6 +152,11 @@ gst_base_src_class_init (GstBaseSrcClass * klass) "True if the element should expose a getrange function", TRUE, G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); + g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_NUM_BUFFERS, + g_param_spec_int ("num-buffers", "num-buffers", + "Number of buffers to output before sending EOS", -1, G_MAXINT, + DEFAULT_NUM_BUFFERS, G_PARAM_READWRITE)); + gstelement_class->change_state = GST_DEBUG_FUNCPTR (gst_base_src_change_state); @@ -165,6 +172,8 @@ gst_base_src_init (GstBaseSrc * basesrc, gpointer g_class) basesrc->is_live = FALSE; basesrc->live_lock = g_mutex_new (); basesrc->live_cond = g_cond_new (); + basesrc->num_buffers = DEFAULT_NUM_BUFFERS; + basesrc->num_buffers_left = -1; pad_template = gst_element_class_get_pad_template (GST_ELEMENT_CLASS (g_class), "src"); @@ -503,6 +512,9 @@ gst_base_src_set_property (GObject * object, guint prop_id, src->has_getrange = g_value_get_boolean (value); gst_base_src_set_dataflow_funcs (src); break; + case PROP_NUM_BUFFERS: + src->num_buffers = g_value_get_int (value); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -527,6 +539,9 @@ gst_base_src_get_property (GObject * object, guint prop_id, GValue * value, case PROP_HAS_GETRANGE: g_value_set_boolean (value, src->has_getrange); break; + case PROP_NUM_BUFFERS: + g_value_set_int (value, src->num_buffers); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -579,6 +594,13 @@ gst_base_src_get_range (GstPad * pad, guint64 offset, guint length, if (length == 0) goto unexpected_length; + if (src->num_buffers_left == 0) { + goto reached_num_buffers; + } else { + if (src->num_buffers_left > 0) + src->num_buffers_left--; + } + ret = bclass->create (src, offset, length, buf); return ret; @@ -599,6 +621,11 @@ unexpected_length: GST_DEBUG_OBJECT (src, "unexpected length %u", length); return GST_FLOW_UNEXPECTED; } +reached_num_buffers: + { + GST_DEBUG_OBJECT (src, "sent all buffers"); + return GST_FLOW_UNEXPECTED; + } } static gboolean @@ -796,6 +823,8 @@ gst_base_src_start (GstBaseSrc * basesrc) if (GST_FLAG_IS_SET (basesrc, GST_BASE_SRC_STARTED)) return TRUE; + basesrc->num_buffers_left = basesrc->num_buffers; + bclass = GST_BASE_SRC_GET_CLASS (basesrc); if (bclass->start) result = bclass->start (basesrc); diff --git a/gst/base/gstbasesrc.h b/gst/base/gstbasesrc.h index 245e6e4..f8713b1 100644 --- a/gst/base/gstbasesrc.h +++ b/gst/base/gstbasesrc.h @@ -95,6 +95,9 @@ struct _GstBaseSrc { guint64 offset; /* current offset in the resource */ guint64 size; /* total size of the resource */ + + gint num_buffers; + gint num_buffers_left; }; /** diff --git a/gst/elements/gstfakesrc.c b/gst/elements/gstfakesrc.c index 0d44076..3f64b6a 100644 --- a/gst/elements/gstfakesrc.c +++ b/gst/elements/gstfakesrc.c @@ -63,7 +63,6 @@ enum #define DEFAULT_DATARATE 0 #define DEFAULT_SYNC FALSE #define DEFAULT_PATTERN NULL -#define DEFAULT_NUM_BUFFERS -1 #define DEFAULT_EOS FALSE #define DEFAULT_SIGNAL_HANDOFFS FALSE #define DEFAULT_SILENT FALSE @@ -82,7 +81,6 @@ enum PROP_DATARATE, PROP_SYNC, PROP_PATTERN, - PROP_NUM_BUFFERS, PROP_EOS, PROP_SIGNAL_HANDOFFS, PROP_SILENT, @@ -262,10 +260,6 @@ gst_fakesrc_class_init (GstFakeSrcClass * klass) g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_PATTERN, g_param_spec_string ("pattern", "pattern", "pattern", DEFAULT_PATTERN, G_PARAM_READWRITE)); - g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_NUM_BUFFERS, - g_param_spec_int ("num-buffers", "num-buffers", - "Number of buffers to output before sending EOS", -1, G_MAXINT, - DEFAULT_NUM_BUFFERS, G_PARAM_READWRITE)); g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_LAST_MESSAGE, g_param_spec_string ("last-message", "last-message", "The last status message", NULL, G_PARAM_READABLE)); @@ -311,8 +305,6 @@ gst_fakesrc_init (GstFakeSrc * fakesrc) fakesrc->output = FAKESRC_FIRST_LAST_LOOP; fakesrc->segment_start = -1; fakesrc->segment_end = -1; - fakesrc->num_buffers = DEFAULT_NUM_BUFFERS; - fakesrc->rt_num_buffers = -1; fakesrc->buffer_count = 0; fakesrc->silent = DEFAULT_SILENT; fakesrc->signal_handoffs = DEFAULT_SIGNAL_HANDOFFS; @@ -414,9 +406,6 @@ gst_fakesrc_set_property (GObject * object, guint prop_id, const GValue * value, break; case PROP_PATTERN: break; - case PROP_NUM_BUFFERS: - src->num_buffers = g_value_get_int (value); - break; case PROP_SILENT: src->silent = g_value_get_boolean (value); break; @@ -486,9 +475,6 @@ gst_fakesrc_get_property (GObject * object, guint prop_id, GValue * value, case PROP_PATTERN: g_value_set_string (value, src->pattern); break; - case PROP_NUM_BUFFERS: - g_value_set_int (value, src->num_buffers); - break; case PROP_SILENT: g_value_set_boolean (value, src->silent); break; @@ -669,13 +655,6 @@ gst_fakesrc_create (GstBaseSrc * basesrc, guint64 offset, guint length, return GST_FLOW_UNEXPECTED; } - if (src->rt_num_buffers == 0) { - return GST_FLOW_UNEXPECTED; - } else { - if (src->rt_num_buffers > 0) - src->rt_num_buffers--; - } - buf = gst_fakesrc_create_buffer (src); GST_BUFFER_OFFSET (buf) = src->buffer_count++; @@ -729,7 +708,6 @@ gst_fakesrc_start (GstBaseSrc * basesrc) src->buffer_count = 0; src->pattern_byte = 0x00; src->bytes_sent = 0; - src->rt_num_buffers = src->num_buffers; return TRUE; } diff --git a/libs/gst/base/gstbasesrc.c b/libs/gst/base/gstbasesrc.c index 0a37e08..197a4dd 100644 --- a/libs/gst/base/gstbasesrc.c +++ b/libs/gst/base/gstbasesrc.c @@ -33,6 +33,7 @@ #include #define DEFAULT_BLOCKSIZE 4096 +#define DEFAULT_NUM_BUFFERS -1 GST_DEBUG_CATEGORY_STATIC (gst_base_src_debug); #define GST_CAT_DEFAULT gst_base_src_debug @@ -50,6 +51,7 @@ enum PROP_BLOCKSIZE, PROP_HAS_LOOP, PROP_HAS_GETRANGE, + PROP_NUM_BUFFERS, }; static GstElementClass *parent_class = NULL; @@ -150,6 +152,11 @@ gst_base_src_class_init (GstBaseSrcClass * klass) "True if the element should expose a getrange function", TRUE, G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); + g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_NUM_BUFFERS, + g_param_spec_int ("num-buffers", "num-buffers", + "Number of buffers to output before sending EOS", -1, G_MAXINT, + DEFAULT_NUM_BUFFERS, G_PARAM_READWRITE)); + gstelement_class->change_state = GST_DEBUG_FUNCPTR (gst_base_src_change_state); @@ -165,6 +172,8 @@ gst_base_src_init (GstBaseSrc * basesrc, gpointer g_class) basesrc->is_live = FALSE; basesrc->live_lock = g_mutex_new (); basesrc->live_cond = g_cond_new (); + basesrc->num_buffers = DEFAULT_NUM_BUFFERS; + basesrc->num_buffers_left = -1; pad_template = gst_element_class_get_pad_template (GST_ELEMENT_CLASS (g_class), "src"); @@ -503,6 +512,9 @@ gst_base_src_set_property (GObject * object, guint prop_id, src->has_getrange = g_value_get_boolean (value); gst_base_src_set_dataflow_funcs (src); break; + case PROP_NUM_BUFFERS: + src->num_buffers = g_value_get_int (value); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -527,6 +539,9 @@ gst_base_src_get_property (GObject * object, guint prop_id, GValue * value, case PROP_HAS_GETRANGE: g_value_set_boolean (value, src->has_getrange); break; + case PROP_NUM_BUFFERS: + g_value_set_int (value, src->num_buffers); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -579,6 +594,13 @@ gst_base_src_get_range (GstPad * pad, guint64 offset, guint length, if (length == 0) goto unexpected_length; + if (src->num_buffers_left == 0) { + goto reached_num_buffers; + } else { + if (src->num_buffers_left > 0) + src->num_buffers_left--; + } + ret = bclass->create (src, offset, length, buf); return ret; @@ -599,6 +621,11 @@ unexpected_length: GST_DEBUG_OBJECT (src, "unexpected length %u", length); return GST_FLOW_UNEXPECTED; } +reached_num_buffers: + { + GST_DEBUG_OBJECT (src, "sent all buffers"); + return GST_FLOW_UNEXPECTED; + } } static gboolean @@ -796,6 +823,8 @@ gst_base_src_start (GstBaseSrc * basesrc) if (GST_FLAG_IS_SET (basesrc, GST_BASE_SRC_STARTED)) return TRUE; + basesrc->num_buffers_left = basesrc->num_buffers; + bclass = GST_BASE_SRC_GET_CLASS (basesrc); if (bclass->start) result = bclass->start (basesrc); diff --git a/libs/gst/base/gstbasesrc.h b/libs/gst/base/gstbasesrc.h index 245e6e4..f8713b1 100644 --- a/libs/gst/base/gstbasesrc.h +++ b/libs/gst/base/gstbasesrc.h @@ -95,6 +95,9 @@ struct _GstBaseSrc { guint64 offset; /* current offset in the resource */ guint64 size; /* total size of the resource */ + + gint num_buffers; + gint num_buffers_left; }; /** diff --git a/plugins/elements/gstfakesrc.c b/plugins/elements/gstfakesrc.c index 0d44076..3f64b6a 100644 --- a/plugins/elements/gstfakesrc.c +++ b/plugins/elements/gstfakesrc.c @@ -63,7 +63,6 @@ enum #define DEFAULT_DATARATE 0 #define DEFAULT_SYNC FALSE #define DEFAULT_PATTERN NULL -#define DEFAULT_NUM_BUFFERS -1 #define DEFAULT_EOS FALSE #define DEFAULT_SIGNAL_HANDOFFS FALSE #define DEFAULT_SILENT FALSE @@ -82,7 +81,6 @@ enum PROP_DATARATE, PROP_SYNC, PROP_PATTERN, - PROP_NUM_BUFFERS, PROP_EOS, PROP_SIGNAL_HANDOFFS, PROP_SILENT, @@ -262,10 +260,6 @@ gst_fakesrc_class_init (GstFakeSrcClass * klass) g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_PATTERN, g_param_spec_string ("pattern", "pattern", "pattern", DEFAULT_PATTERN, G_PARAM_READWRITE)); - g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_NUM_BUFFERS, - g_param_spec_int ("num-buffers", "num-buffers", - "Number of buffers to output before sending EOS", -1, G_MAXINT, - DEFAULT_NUM_BUFFERS, G_PARAM_READWRITE)); g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_LAST_MESSAGE, g_param_spec_string ("last-message", "last-message", "The last status message", NULL, G_PARAM_READABLE)); @@ -311,8 +305,6 @@ gst_fakesrc_init (GstFakeSrc * fakesrc) fakesrc->output = FAKESRC_FIRST_LAST_LOOP; fakesrc->segment_start = -1; fakesrc->segment_end = -1; - fakesrc->num_buffers = DEFAULT_NUM_BUFFERS; - fakesrc->rt_num_buffers = -1; fakesrc->buffer_count = 0; fakesrc->silent = DEFAULT_SILENT; fakesrc->signal_handoffs = DEFAULT_SIGNAL_HANDOFFS; @@ -414,9 +406,6 @@ gst_fakesrc_set_property (GObject * object, guint prop_id, const GValue * value, break; case PROP_PATTERN: break; - case PROP_NUM_BUFFERS: - src->num_buffers = g_value_get_int (value); - break; case PROP_SILENT: src->silent = g_value_get_boolean (value); break; @@ -486,9 +475,6 @@ gst_fakesrc_get_property (GObject * object, guint prop_id, GValue * value, case PROP_PATTERN: g_value_set_string (value, src->pattern); break; - case PROP_NUM_BUFFERS: - g_value_set_int (value, src->num_buffers); - break; case PROP_SILENT: g_value_set_boolean (value, src->silent); break; @@ -669,13 +655,6 @@ gst_fakesrc_create (GstBaseSrc * basesrc, guint64 offset, guint length, return GST_FLOW_UNEXPECTED; } - if (src->rt_num_buffers == 0) { - return GST_FLOW_UNEXPECTED; - } else { - if (src->rt_num_buffers > 0) - src->rt_num_buffers--; - } - buf = gst_fakesrc_create_buffer (src); GST_BUFFER_OFFSET (buf) = src->buffer_count++; @@ -729,7 +708,6 @@ gst_fakesrc_start (GstBaseSrc * basesrc) src->buffer_count = 0; src->pattern_byte = 0x00; src->bytes_sent = 0; - src->rt_num_buffers = src->num_buffers; return TRUE; }