summaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
authorWim Taymans <wim.taymans@collabora.co.uk>2009-05-13 16:09:20 +0200
committerWim Taymans <wim.taymans@collabora.co.uk>2009-05-13 16:22:58 +0200
commit3d19b7514722a2ee0578f55f411fa5e6ac6d7050 (patch)
tree61272be4e2ffcef05b1a1473821c8669f76a919a /libs
parent8ceff30ca9a7e5958355de93c8f2411893de383a (diff)
adapter: add method to keep track of timestamps
Keep track of the timestamp and offset associated with the current head of the adapter. API: GstAdapter::gst_adapter_prev_timestamp()
Diffstat (limited to 'libs')
-rw-r--r--libs/gst/base/gstadapter.c51
-rw-r--r--libs/gst/base/gstadapter.h10
2 files changed, 60 insertions, 1 deletions
diff --git a/libs/gst/base/gstadapter.c b/libs/gst/base/gstadapter.c
index dcc3bd553..1e29ce9ef 100644
--- a/libs/gst/base/gstadapter.c
+++ b/libs/gst/base/gstadapter.c
@@ -131,6 +131,8 @@ gst_adapter_init (GstAdapter * adapter, GstAdapterClass * g_class)
{
adapter->assembled_data = g_malloc (DEFAULT_SIZE);
adapter->assembled_size = DEFAULT_SIZE;
+ adapter->abidata.ABI.timestamp = GST_CLOCK_TIME_NONE;
+ adapter->abidata.ABI.distance = 0;
}
static void
@@ -184,6 +186,22 @@ gst_adapter_clear (GstAdapter * adapter)
adapter->size = 0;
adapter->skip = 0;
adapter->assembled_len = 0;
+ adapter->abidata.ABI.timestamp = GST_CLOCK_TIME_NONE;
+ adapter->abidata.ABI.distance = 0;
+}
+
+static inline void
+update_timestamp (GstAdapter * adapter, GstBuffer * buf)
+{
+ GstClockTime timestamp;
+
+ timestamp = GST_BUFFER_TIMESTAMP (buf);
+ if (GST_CLOCK_TIME_IS_VALID (timestamp)) {
+ GST_LOG_OBJECT (adapter, "new timestamp %" GST_TIME_FORMAT,
+ GST_TIME_ARGS (timestamp));
+ adapter->abidata.ABI.timestamp = timestamp;
+ adapter->abidata.ABI.distance = 0;
+ }
}
/**
@@ -216,6 +234,7 @@ gst_adapter_push (GstAdapter * adapter, GstBuffer * buf)
if (G_UNLIKELY (adapter->buflist == NULL)) {
GST_LOG_OBJECT (adapter, "pushing first %u bytes", size);
adapter->buflist = adapter->buflist_end = g_slist_append (NULL, buf);
+ update_timestamp (adapter, buf);
} else {
/* Otherwise append to the end, and advance our end pointer */
GST_LOG_OBJECT (adapter, "pushing %u bytes at end, size now %u", size,
@@ -448,16 +467,21 @@ gst_adapter_flush (GstAdapter * adapter, guint flush)
GST_LOG_OBJECT (adapter, "flushing out head buffer");
flush -= size;
adapter->skip = 0;
+ adapter->abidata.ABI.distance += size;
adapter->buflist =
g_slist_delete_link (adapter->buflist, adapter->buflist);
if (G_UNLIKELY (adapter->buflist == NULL)) {
GST_LOG_OBJECT (adapter, "adapter empty now");
adapter->buflist_end = NULL;
+ } else {
+ /* there is a new head buffer, update the timestamp */
+ update_timestamp (adapter, GST_BUFFER_CAST (adapter->buflist->data));
}
gst_buffer_unref (cur);
} else {
adapter->skip += flush;
+ adapter->abidata.ABI.distance += flush;
break;
}
}
@@ -640,3 +664,30 @@ gst_adapter_available_fast (GstAdapter * adapter)
/* we can quickly get the data of the first buffer */
return size - adapter->skip;
}
+
+/**
+ * gst_adapter_prev_timestamp:
+ * @adapter: a #GstAdapter
+ * @distance: pointer to location for distance or NULL
+ *
+ * Get the timestamp that was before the current byte in the adapter. When
+ * @distance is given, the amount of bytes between the timestamp and the current
+ * position is returned.
+ *
+ * The timestamp is reset to GST_CLOCK_TIME_NONE when the adapter is first
+ * created or when it is cleared.
+ *
+ * Returns: The previously seen timestamp.
+ *
+ * Since: 0.10.24
+ */
+GstClockTime
+gst_adapter_prev_timestamp (GstAdapter * adapter, guint64 * distance)
+{
+ g_return_val_if_fail (GST_IS_ADAPTER (adapter), GST_CLOCK_TIME_NONE);
+
+ if (distance)
+ *distance = adapter->abidata.ABI.distance;
+
+ return adapter->abidata.ABI.timestamp;
+}
diff --git a/libs/gst/base/gstadapter.h b/libs/gst/base/gstadapter.h
index 1b3416903..34fa395da 100644
--- a/libs/gst/base/gstadapter.h
+++ b/libs/gst/base/gstadapter.h
@@ -63,7 +63,13 @@ struct _GstAdapter {
/* Remember where the end of our buffer list is to
* speed up the push */
GSList *buflist_end;
- gpointer _gst_reserved[GST_PADDING - 1];
+ union {
+ struct {
+ GstClockTime timestamp;
+ guint64 distance;
+ } ABI;
+ gpointer _gst_reserved[GST_PADDING - 1];
+ } abidata;
};
struct _GstAdapterClass {
@@ -88,6 +94,8 @@ GstBuffer* gst_adapter_take_buffer (GstAdapter *adapter, guint nbytes);
guint gst_adapter_available (GstAdapter *adapter);
guint gst_adapter_available_fast (GstAdapter *adapter);
+GstClockTime gst_adapter_prev_timestamp (GstAdapter *adapter, guint64 *distance);
+
G_END_DECLS
#endif /* __GST_ADAPTER_H__ */