diff options
Diffstat (limited to 'plugins/elements/gstidentity.c')
-rw-r--r-- | plugins/elements/gstidentity.c | 133 |
1 files changed, 71 insertions, 62 deletions
diff --git a/plugins/elements/gstidentity.c b/plugins/elements/gstidentity.c index 9929533348..c06f384292 100644 --- a/plugins/elements/gstidentity.c +++ b/plugins/elements/gstidentity.c @@ -91,11 +91,11 @@ enum }; -#define _do_init(bla) \ +#define _do_init \ GST_DEBUG_CATEGORY_INIT (gst_identity_debug, "identity", 0, "identity element"); - -GST_BOILERPLATE_FULL (GstIdentity, gst_identity, GstBaseTransform, - GST_TYPE_BASE_TRANSFORM, _do_init); +#define gst_identity_parent_class parent_class +G_DEFINE_TYPE_WITH_CODE (GstIdentity, gst_identity, GST_TYPE_BASE_TRANSFORM, + _do_init); static void gst_identity_finalize (GObject * object); static void gst_identity_set_property (GObject * object, guint prop_id, @@ -117,21 +117,6 @@ static guint gst_identity_signals[LAST_SIGNAL] = { 0 }; static GParamSpec *pspec_last_message = NULL; static void -gst_identity_base_init (gpointer g_class) -{ - GstElementClass *gstelement_class = GST_ELEMENT_CLASS (g_class); - - gst_element_class_set_details_simple (gstelement_class, - "Identity", - "Generic", - "Pass data without modification", "Erik Walthinsen <omega@cse.ogi.edu>"); - gst_element_class_add_pad_template (gstelement_class, - gst_static_pad_template_get (&srctemplate)); - gst_element_class_add_pad_template (gstelement_class, - gst_static_pad_template_get (&sinktemplate)); -} - -static void gst_identity_finalize (GObject * object) { GstIdentity *identity; @@ -172,16 +157,18 @@ marshal_VOID__MINIOBJECT (GClosure * closure, GValue * return_value, (marshalfunc_VOID__MINIOBJECT) (marshal_data ? marshal_data : cc->callback); - callback (data1, gst_value_get_mini_object (param_values + 1), data2); + callback (data1, g_value_get_boxed (param_values + 1), data2); } static void gst_identity_class_init (GstIdentityClass * klass) { GObjectClass *gobject_class; + GstElementClass *gstelement_class; GstBaseTransformClass *gstbasetrans_class; gobject_class = G_OBJECT_CLASS (klass); + gstelement_class = GST_ELEMENT_CLASS (klass); gstbasetrans_class = GST_BASE_TRANSFORM_CLASS (klass); gobject_class->set_property = gst_identity_set_property; @@ -210,7 +197,7 @@ gst_identity_class_init (GstIdentityClass * klass) G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); g_object_class_install_property (gobject_class, PROP_SINGLE_SEGMENT, g_param_spec_boolean ("single-segment", "Single Segment", - "Timestamp buffers and eat newsegments so as to appear as one segment", + "Timestamp buffers and eat segments so as to appear as one segment", DEFAULT_SINGLE_SEGMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); pspec_last_message = g_param_spec_string ("last-message", "last-message", "last-message", NULL, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); @@ -271,6 +258,15 @@ gst_identity_class_init (GstIdentityClass * klass) gobject_class->finalize = gst_identity_finalize; + gst_element_class_set_details_simple (gstelement_class, + "Identity", + "Generic", + "Pass data without modification", "Erik Walthinsen <omega@cse.ogi.edu>"); + gst_element_class_add_pad_template (gstelement_class, + gst_static_pad_template_get (&srctemplate)); + gst_element_class_add_pad_template (gstelement_class, + gst_static_pad_template_get (&sinktemplate)); + gstbasetrans_class->event = GST_DEBUG_FUNCPTR (gst_identity_event); gstbasetrans_class->transform_ip = GST_DEBUG_FUNCPTR (gst_identity_transform_ip); @@ -281,7 +277,7 @@ gst_identity_class_init (GstIdentityClass * klass) } static void -gst_identity_init (GstIdentity * identity, GstIdentityClass * g_class) +gst_identity_init (GstIdentity * identity) { identity->sleep_time = DEFAULT_SLEEP_TIME; identity->error_after = DEFAULT_ERROR_AFTER; @@ -352,17 +348,16 @@ gst_identity_event (GstBaseTransform * trans, GstEvent * event) gst_identity_notify_last_message (identity); } - if (identity->single_segment - && (GST_EVENT_TYPE (event) == GST_EVENT_NEWSEGMENT)) { - if (trans->have_newsegment == FALSE) { + if (identity->single_segment && (GST_EVENT_TYPE (event) == GST_EVENT_SEGMENT)) { + if (trans->have_segment == FALSE) { GstEvent *news; - GstFormat format; + GstSegment segment; - gst_event_parse_new_segment (event, NULL, NULL, &format, NULL, NULL, - NULL); + gst_event_copy_segment (event, &segment); - /* This is the first newsegment, send out a (0, -1) newsegment */ - news = gst_event_new_new_segment (TRUE, 1.0, format, 0, -1, 0); + /* This is the first segment, send out a (0, -1) segment */ + gst_segment_init (&segment, segment.format); + news = gst_event_new_segment (&segment); gst_pad_event_default (trans->sinkpad, news); } @@ -370,15 +365,14 @@ gst_identity_event (GstBaseTransform * trans, GstEvent * event) /* Reset previous timestamp, duration and offsets on NEWSEGMENT * to prevent false warnings when checking for perfect streams */ - if (GST_EVENT_TYPE (event) == GST_EVENT_NEWSEGMENT) { + if (GST_EVENT_TYPE (event) == GST_EVENT_SEGMENT) { identity->prev_timestamp = identity->prev_duration = GST_CLOCK_TIME_NONE; identity->prev_offset = identity->prev_offset_end = GST_BUFFER_OFFSET_NONE; } - ret = parent_class->event (trans, event); + ret = GST_BASE_TRANSFORM_CLASS (parent_class)->event (trans, event); - if (identity->single_segment - && (GST_EVENT_TYPE (event) == GST_EVENT_NEWSEGMENT)) { + if (identity->single_segment && (GST_EVENT_TYPE (event) == GST_EVENT_SEGMENT)) { /* eat up segments */ ret = FALSE; } @@ -394,13 +388,13 @@ gst_identity_prepare_output_buffer (GstBaseTransform * trans, /* only bother if we may have to alter metadata */ if (identity->datarate > 0 || identity->single_segment) { - if (gst_buffer_is_metadata_writable (in_buf)) + if (gst_buffer_is_writable (in_buf)) *out_buf = gst_buffer_ref (in_buf); else { /* make even less writable */ gst_buffer_ref (in_buf); /* extra ref is dropped going through the official process */ - *out_buf = gst_buffer_make_metadata_writable (in_buf); + *out_buf = gst_buffer_make_writable (in_buf); } } else *out_buf = gst_buffer_ref (in_buf); @@ -560,7 +554,7 @@ print_pretty_time (gchar * ts_str, gsize ts_str_len, GstClockTime ts) static void gst_identity_update_last_message_for_buffer (GstIdentity * identity, - const gchar * action, GstBuffer * buf) + const gchar * action, GstBuffer * buf, gsize size) { gchar ts_str[64], dur_str[64]; @@ -568,14 +562,13 @@ gst_identity_update_last_message_for_buffer (GstIdentity * identity, g_free (identity->last_message); identity->last_message = g_strdup_printf ("%s ******* (%s:%s)i " - "(%u bytes, timestamp: %s, duration: %s, offset: %" G_GINT64_FORMAT ", " - "offset_end: % " G_GINT64_FORMAT ", flags: %d) %p", action, - GST_DEBUG_PAD_NAME (GST_BASE_TRANSFORM_CAST (identity)->sinkpad), - GST_BUFFER_SIZE (buf), - print_pretty_time (ts_str, sizeof (ts_str), GST_BUFFER_TIMESTAMP (buf)), - print_pretty_time (dur_str, sizeof (dur_str), GST_BUFFER_DURATION (buf)), - GST_BUFFER_OFFSET (buf), GST_BUFFER_OFFSET_END (buf), - GST_BUFFER_FLAGS (buf), buf); + "(%" G_GSIZE_FORMAT " bytes, timestamp: %s, duration: %s, offset: %" + G_GINT64_FORMAT ", " "offset_end: % " G_GINT64_FORMAT ", flags: %d) %p", + action, GST_DEBUG_PAD_NAME (GST_BASE_TRANSFORM_CAST (identity)->sinkpad), + size, print_pretty_time (ts_str, sizeof (ts_str), + GST_BUFFER_TIMESTAMP (buf)), print_pretty_time (dur_str, + sizeof (dur_str), GST_BUFFER_DURATION (buf)), GST_BUFFER_OFFSET (buf), + GST_BUFFER_OFFSET_END (buf), GST_BUFFER_FLAGS (buf), buf); GST_OBJECT_UNLOCK (identity); @@ -588,6 +581,10 @@ gst_identity_transform_ip (GstBaseTransform * trans, GstBuffer * buf) GstFlowReturn ret = GST_FLOW_OK; GstIdentity *identity = GST_IDENTITY (trans); GstClockTime runtimestamp = G_GINT64_CONSTANT (0); + guint8 *data; + gsize size; + + data = gst_buffer_map (buf, &size, NULL, GST_MAP_READ); if (identity->check_perfect) gst_identity_check_perfect (identity, buf); @@ -604,29 +601,21 @@ gst_identity_transform_ip (GstBaseTransform * trans, GstBuffer * buf) if (identity->error_after >= 0) { identity->error_after--; - if (identity->error_after == 0) { - GST_ELEMENT_ERROR (identity, CORE, FAILED, - (_("Failed after iterations as requested.")), (NULL)); - return GST_FLOW_ERROR; - } + if (identity->error_after == 0) + goto error_after; } if (identity->drop_probability > 0.0) { - if ((gfloat) (1.0 * rand () / (RAND_MAX)) < identity->drop_probability) { - if (!identity->silent) { - gst_identity_update_last_message_for_buffer (identity, "dropping", buf); - } - /* return DROPPED to basetransform. */ - return GST_BASE_TRANSFORM_FLOW_DROPPED; - } + if ((gfloat) (1.0 * rand () / (RAND_MAX)) < identity->drop_probability) + goto dropped; } if (identity->dump) { - gst_util_dump_mem (GST_BUFFER_DATA (buf), GST_BUFFER_SIZE (buf)); + gst_util_dump_mem (data, size); } if (!identity->silent) { - gst_identity_update_last_message_for_buffer (identity, "chain", buf); + gst_identity_update_last_message_for_buffer (identity, "chain", buf, size); } if (identity->datarate > 0) { @@ -634,8 +623,7 @@ gst_identity_transform_ip (GstBaseTransform * trans, GstBuffer * buf) GST_SECOND, identity->datarate); GST_BUFFER_TIMESTAMP (buf) = time; - GST_BUFFER_DURATION (buf) = - GST_BUFFER_SIZE (buf) * GST_SECOND / identity->datarate; + GST_BUFFER_DURATION (buf) = size * GST_SECOND / identity->datarate; } if (identity->signal_handoffs) @@ -673,7 +661,7 @@ gst_identity_transform_ip (GstBaseTransform * trans, GstBuffer * buf) GST_OBJECT_UNLOCK (identity); } - identity->offset += GST_BUFFER_SIZE (buf); + identity->offset += size; if (identity->sleep_time && ret == GST_FLOW_OK) g_usleep (identity->sleep_time); @@ -685,7 +673,28 @@ gst_identity_transform_ip (GstBaseTransform * trans, GstBuffer * buf) GST_BUFFER_OFFSET_END (buf) = GST_CLOCK_TIME_NONE; } + gst_buffer_unmap (buf, data, size); + return ret; + + /* ERRORS */ +error_after: + { + GST_ELEMENT_ERROR (identity, CORE, FAILED, + (_("Failed after iterations as requested.")), (NULL)); + gst_buffer_unmap (buf, data, size); + return GST_FLOW_ERROR; + } +dropped: + { + if (!identity->silent) { + gst_identity_update_last_message_for_buffer (identity, "dropping", buf, + size); + } + gst_buffer_unmap (buf, data, size); + /* return DROPPED to basetransform. */ + return GST_BASE_TRANSFORM_FLOW_DROPPED; + } } static void |