summaryrefslogtreecommitdiff
path: root/gst/pcapparse
diff options
context:
space:
mode:
authorOlivier CrĂȘte <olivier.crete@collabora.co.uk>2009-09-01 21:30:35 -0400
committerOlivier CrĂȘte <olivier.crete@collabora.co.uk>2009-09-03 13:39:36 -0400
commita333fef08ce5bb558dc3ac39d514b84c0d392462 (patch)
tree22da5dc656e99c594141f12a29158a83b8a35910 /gst/pcapparse
parent00f395e82f2732ba33f7e396da7b8f77ec4c7dca (diff)
downloadgstreamer-plugins-bad-a333fef08ce5bb558dc3ac39d514b84c0d392462.tar.gz
pcapparse: Set the GStreamer timestamp according to the pcap timestamps
Diffstat (limited to 'gst/pcapparse')
-rw-r--r--gst/pcapparse/gstpcapparse.c37
-rw-r--r--gst/pcapparse/gstpcapparse.h4
2 files changed, 41 insertions, 0 deletions
diff --git a/gst/pcapparse/gstpcapparse.c b/gst/pcapparse/gstpcapparse.c
index 546ffbe30..6e2021269 100644
--- a/gst/pcapparse/gstpcapparse.c
+++ b/gst/pcapparse/gstpcapparse.c
@@ -87,6 +87,7 @@ static void gst_pcap_parse_set_property (GObject * object, guint prop_id,
static void gst_pcap_parse_reset (GstPcapParse * self);
static GstFlowReturn gst_pcap_parse_chain (GstPad * pad, GstBuffer * buffer);
+static gboolean gst_pcap_sink_event (GstPad * pad, GstEvent * event);
GST_BOILERPLATE (GstPcapParse, gst_pcap_parse, GstElement, GST_TYPE_ELEMENT);
@@ -146,6 +147,8 @@ gst_pcap_parse_init (GstPcapParse * self, GstPcapParseClass * gclass)
gst_pad_set_chain_function (self->sink_pad,
GST_DEBUG_FUNCPTR (gst_pcap_parse_chain));
gst_pad_use_fixed_caps (self->sink_pad);
+ gst_pad_set_event_function (self->sink_pad,
+ GST_DEBUG_FUNCPTR (gst_pcap_sink_event));
gst_element_add_pad (GST_ELEMENT (self), self->sink_pad);
self->src_pad = gst_pad_new_from_static_template (&src_template, "src");
@@ -261,6 +264,8 @@ gst_pcap_parse_reset (GstPcapParse * self)
self->swap_endian = FALSE;
self->cur_packet_size = -1;
self->buffer_offset = 0;
+ self->cur_ts = GST_CLOCK_TIME_NONE;
+ self->newsegment_sent = FALSE;
gst_adapter_clear (self->adapter);
}
@@ -402,7 +407,18 @@ gst_pcap_parse_chain (GstPad * pad, GstBuffer * buffer)
GST_PAD_CAPS (self->src_pad), &out_buf);
if (ret == GST_FLOW_OK) {
+
memcpy (GST_BUFFER_DATA (out_buf), payload_data, payload_size);
+ GST_BUFFER_TIMESTAMP (out_buf) = self->cur_ts;
+
+ if (!self->newsegment_sent &&
+ GST_CLOCK_TIME_IS_VALID (self->cur_ts)) {
+ GstEvent *newsegment =
+ gst_event_new_new_segment (FALSE, 1, GST_FORMAT_TIME,
+ self->cur_ts, -1, 0);
+ gst_pad_push_event (self->src_pad, newsegment);
+ self->newsegment_sent = TRUE;
+ }
ret = gst_pad_push (self->src_pad, out_buf);
@@ -432,6 +448,7 @@ gst_pcap_parse_chain (GstPad * pad, GstBuffer * buffer)
gst_adapter_flush (self->adapter, 16);
+ self->cur_ts = ts_sec * GST_SECOND + ts_usec * GST_USECOND;
self->cur_packet_size = incl_len;
}
} else {
@@ -465,6 +482,26 @@ gst_pcap_parse_chain (GstPad * pad, GstBuffer * buffer)
}
static gboolean
+gst_pcap_sink_event (GstPad * pad, GstEvent * event)
+{
+ gboolean ret = TRUE;
+ GstPcapParse *self = GST_PCAP_PARSE (gst_pad_get_parent (pad));
+
+ switch (GST_EVENT_TYPE (event)) {
+ case GST_EVENT_NEWSEGMENT:
+ /* Drop it, we'll replace it with our own */
+ break;
+ default:
+ ret = gst_pad_push_event (self->src_pad, event);
+ }
+
+ gst_object_unref (self);
+
+ return ret;
+}
+
+
+static gboolean
plugin_init (GstPlugin * plugin)
{
return gst_element_register (plugin, "pcapparse",
diff --git a/gst/pcapparse/gstpcapparse.h b/gst/pcapparse/gstpcapparse.h
index cc1b55f68..caaa52e2b 100644
--- a/gst/pcapparse/gstpcapparse.h
+++ b/gst/pcapparse/gstpcapparse.h
@@ -70,6 +70,10 @@ struct _GstPcapParse
gboolean initialized;
gboolean swap_endian;
gint64 cur_packet_size;
+ GstClockTime cur_ts;
+
+ gboolean newsegment_sent;
+
gint64 buffer_offset;
};