From 21987266304ea91668089a38af0d1f679f78101d Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Thu, 27 Dec 2001 00:40:50 +0000 Subject: [PATCH] Added a property to make identity fail after N buffers Original commit message from CVS: Added a property to make identity fail after N buffers --- gst/elements/gstidentity.c | 34 +++++++++++++++++++++++++++++++++- gst/elements/gstidentity.h | 1 + plugins/elements/gstidentity.c | 34 +++++++++++++++++++++++++++++++++- plugins/elements/gstidentity.h | 1 + 4 files changed, 68 insertions(+), 2 deletions(-) diff --git a/gst/elements/gstidentity.c b/gst/elements/gstidentity.c index ddd4c02a66..04054464d3 100644 --- a/gst/elements/gstidentity.c +++ b/gst/elements/gstidentity.c @@ -46,6 +46,7 @@ enum { ARG_LOOP_BASED, ARG_SLEEP_TIME, ARG_DUPLICATE, + ARG_ERROR_AFTER, ARG_SILENT, }; @@ -98,8 +99,11 @@ gst_identity_class_init (GstIdentityClass *klass) g_param_spec_uint ("sleep_time", "sleep_time", "sleep_time", 0, G_MAXUINT, 0, G_PARAM_READWRITE)); g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_DUPLICATE, - g_param_spec_uint ("duplicate", "duplicate", "duplicate", + g_param_spec_uint ("duplicate", "Duplicate Buffers", "Push the buffers N times", 0, G_MAXUINT, 1, G_PARAM_READWRITE)); + g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_ERROR_AFTER, + g_param_spec_int ("error_after", "Error After", "Error after N buffers", + G_MININT, G_MAXINT, -1, G_PARAM_READWRITE)); g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_SILENT, g_param_spec_boolean ("silent", "silent", "silent", TRUE,G_PARAM_READWRITE)); @@ -160,6 +164,7 @@ gst_identity_init (GstIdentity *identity) identity->loop_based = FALSE; identity->sleep_time = 0; identity->duplicate = 1; + identity->error_after = -1; identity->silent = FALSE; } @@ -175,6 +180,15 @@ gst_identity_chain (GstPad *pad, GstBuffer *buf) identity = GST_IDENTITY (gst_pad_get_parent (pad)); + if (identity->error_after >= 0) { + identity->error_after--; + if (identity->error_after == 0) { + gst_buffer_unref (buf); + gst_element_error (GST_ELEMENT (identity), "errored after iterations as requested"); + return; + } + } + for (i=identity->duplicate; i; i--) { if (!identity->silent) g_print("identity: chain ******* (%s:%s)i (%d bytes, %llu) \n", @@ -206,6 +220,18 @@ gst_identity_loop (GstElement *element) identity = GST_IDENTITY (element); buf = gst_pad_pull (identity->sinkpad); + if (GST_IS_EVENT (buf)) { + gst_pad_event_default (identity->sinkpad, GST_EVENT (buf)); + } + + if (identity->error_after >= 0) { + identity->error_after--; + if (identity->error_after == 0) { + gst_buffer_unref (buf); + gst_element_error (element, "errored after iterations as requested"); + return; + } + } for (i=identity->duplicate; i; i--) { if (!identity->silent) @@ -256,6 +282,9 @@ gst_identity_set_property (GObject *object, guint prop_id, const GValue *value, case ARG_DUPLICATE: identity->duplicate = g_value_get_uint (value); break; + case ARG_ERROR_AFTER: + identity->error_after = g_value_get_uint (value); + break; default: break; } @@ -279,6 +308,9 @@ static void gst_identity_get_property(GObject *object, guint prop_id, GValue *va case ARG_DUPLICATE: g_value_set_uint (value, identity->duplicate); break; + case ARG_ERROR_AFTER: + g_value_set_uint (value, identity->error_after); + break; case ARG_SILENT: g_value_set_boolean (value, identity->silent); break; diff --git a/gst/elements/gstidentity.h b/gst/elements/gstidentity.h index 86e56ddc40..5b21c95ad3 100644 --- a/gst/elements/gstidentity.h +++ b/gst/elements/gstidentity.h @@ -59,6 +59,7 @@ struct _GstIdentity { gboolean loop_based; guint duplicate; + gint error_after; guint sleep_time; gboolean silent; }; diff --git a/plugins/elements/gstidentity.c b/plugins/elements/gstidentity.c index ddd4c02a66..04054464d3 100644 --- a/plugins/elements/gstidentity.c +++ b/plugins/elements/gstidentity.c @@ -46,6 +46,7 @@ enum { ARG_LOOP_BASED, ARG_SLEEP_TIME, ARG_DUPLICATE, + ARG_ERROR_AFTER, ARG_SILENT, }; @@ -98,8 +99,11 @@ gst_identity_class_init (GstIdentityClass *klass) g_param_spec_uint ("sleep_time", "sleep_time", "sleep_time", 0, G_MAXUINT, 0, G_PARAM_READWRITE)); g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_DUPLICATE, - g_param_spec_uint ("duplicate", "duplicate", "duplicate", + g_param_spec_uint ("duplicate", "Duplicate Buffers", "Push the buffers N times", 0, G_MAXUINT, 1, G_PARAM_READWRITE)); + g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_ERROR_AFTER, + g_param_spec_int ("error_after", "Error After", "Error after N buffers", + G_MININT, G_MAXINT, -1, G_PARAM_READWRITE)); g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_SILENT, g_param_spec_boolean ("silent", "silent", "silent", TRUE,G_PARAM_READWRITE)); @@ -160,6 +164,7 @@ gst_identity_init (GstIdentity *identity) identity->loop_based = FALSE; identity->sleep_time = 0; identity->duplicate = 1; + identity->error_after = -1; identity->silent = FALSE; } @@ -175,6 +180,15 @@ gst_identity_chain (GstPad *pad, GstBuffer *buf) identity = GST_IDENTITY (gst_pad_get_parent (pad)); + if (identity->error_after >= 0) { + identity->error_after--; + if (identity->error_after == 0) { + gst_buffer_unref (buf); + gst_element_error (GST_ELEMENT (identity), "errored after iterations as requested"); + return; + } + } + for (i=identity->duplicate; i; i--) { if (!identity->silent) g_print("identity: chain ******* (%s:%s)i (%d bytes, %llu) \n", @@ -206,6 +220,18 @@ gst_identity_loop (GstElement *element) identity = GST_IDENTITY (element); buf = gst_pad_pull (identity->sinkpad); + if (GST_IS_EVENT (buf)) { + gst_pad_event_default (identity->sinkpad, GST_EVENT (buf)); + } + + if (identity->error_after >= 0) { + identity->error_after--; + if (identity->error_after == 0) { + gst_buffer_unref (buf); + gst_element_error (element, "errored after iterations as requested"); + return; + } + } for (i=identity->duplicate; i; i--) { if (!identity->silent) @@ -256,6 +282,9 @@ gst_identity_set_property (GObject *object, guint prop_id, const GValue *value, case ARG_DUPLICATE: identity->duplicate = g_value_get_uint (value); break; + case ARG_ERROR_AFTER: + identity->error_after = g_value_get_uint (value); + break; default: break; } @@ -279,6 +308,9 @@ static void gst_identity_get_property(GObject *object, guint prop_id, GValue *va case ARG_DUPLICATE: g_value_set_uint (value, identity->duplicate); break; + case ARG_ERROR_AFTER: + g_value_set_uint (value, identity->error_after); + break; case ARG_SILENT: g_value_set_boolean (value, identity->silent); break; diff --git a/plugins/elements/gstidentity.h b/plugins/elements/gstidentity.h index 86e56ddc40..5b21c95ad3 100644 --- a/plugins/elements/gstidentity.h +++ b/plugins/elements/gstidentity.h @@ -59,6 +59,7 @@ struct _GstIdentity { gboolean loop_based; guint duplicate; + gint error_after; guint sleep_time; gboolean silent; };