Commit 8c7da1d4 authored by Sebastian Dröge's avatar Sebastian Dröge 🍵

adapter: Rename functions and implement new functions, update test

We don't do calculations with different units (buffer offsets and bytes)
anymore but have functions for:
1) getting the number of bytes since the last discont
2) getting the offset (and pts/dts) at the last discont

and the previously added function to get the last offset and its distance from
the current adapter position.

https://bugzilla.gnome.org/show_bug.cgi?id=766647
parent 67ae0ad2
......@@ -179,7 +179,10 @@ gst_adapter_prev_dts
gst_adapter_prev_pts_at_offset
gst_adapter_prev_dts_at_offset
gst_adapter_prev_offset
gst_adapter_get_offset_from_discont
gst_adapter_pts_at_discont
gst_adapter_dts_at_discont
gst_adapter_offset_at_discont
gst_adapter_distance_from_discont
gst_adapter_masked_scan_uint32
gst_adapter_masked_scan_uint32_peek
<SUBSECTION Standard>
......
......@@ -96,12 +96,13 @@
* (#GST_BUFFER_OFFSET) that were pushed. The last seen offset before the
* current position can be queried with gst_adapter_prev_offset(). This function
* can optionally return the number of bytes between the start of the buffer
* that carried the offset and the current adapter position. If the meaning of
* #GST_BUFFER_OFFSET for the stream being handled corresponds to bytes, then
* the accumulated offset since the last #GST_BUFFER_FLAG_DISCONT buffer can be
* queried with gst_adapter_get_offset_from_discont(). This is useful for
* elements that want to track the position of data in the stream based on the
* offset of the incoming buffers.
* that carried the offset and the current adapter position.
*
* Additionally the adapter also keeps track of the PTS, DTS and buffer offset
* at the last discontinuity, which can be retrieved with
* gst_adapter_pts_at_discont(), gst_adapter_dts_at_discont() and
* gst_adapter_offset_at_discont(). The number of bytes that were consumed
* since then can be queried with gst_adapter_distance_from_discont().
*
* A last thing to note is that while #GstAdapter is pretty optimized,
* merging buffers still might be an operation that requires a malloc() and
......@@ -129,8 +130,6 @@
/* default size for the assembled data buffer */
#define DEFAULT_SIZE 4096
#define INCREASE_OFFSET(a, offs) if ((a)->offset_discont != GST_BUFFER_OFFSET_NONE) { (a)->offset_discont += (offs); }
static void gst_adapter_flush_unchecked (GstAdapter * adapter, gsize flush);
GST_DEBUG_CATEGORY_STATIC (gst_adapter_debug);
......@@ -162,7 +161,11 @@ struct _GstAdapter
gsize scan_offset;
GSList *scan_entry;
guint64 offset_discont;
GstClockTime pts_at_discont;
GstClockTime dts_at_discont;
guint64 offset_at_discont;
guint64 distance_from_discont;
GstMapInfo info;
};
......@@ -200,7 +203,10 @@ gst_adapter_init (GstAdapter * adapter)
adapter->dts_distance = 0;
adapter->offset = GST_BUFFER_OFFSET_NONE;
adapter->offset_distance = 0;
adapter->offset_discont = GST_BUFFER_OFFSET_NONE;
adapter->pts_at_discont = GST_CLOCK_TIME_NONE;
adapter->dts_at_discont = GST_CLOCK_TIME_NONE;
adapter->offset_at_discont = GST_BUFFER_OFFSET_NONE;
adapter->distance_from_discont = 0;
}
static void
......@@ -264,9 +270,12 @@ gst_adapter_clear (GstAdapter * adapter)
adapter->dts_distance = 0;
adapter->offset = GST_BUFFER_OFFSET_NONE;
adapter->offset_distance = 0;
adapter->pts_at_discont = GST_CLOCK_TIME_NONE;
adapter->dts_at_discont = GST_CLOCK_TIME_NONE;
adapter->offset_at_discont = GST_BUFFER_OFFSET_NONE;
adapter->distance_from_discont = 0;
adapter->scan_offset = 0;
adapter->scan_entry = NULL;
adapter->offset_discont = GST_BUFFER_OFFSET_NONE;
}
static inline void
......@@ -288,17 +297,19 @@ update_timestamps_and_offset (GstAdapter * adapter, GstBuffer * buf)
adapter->dts_distance = 0;
}
offset = GST_BUFFER_OFFSET (buf);
if (GST_BUFFER_IS_DISCONT (buf)) {
/* Take offset as-is (might be NONE) */
adapter->offset_discont = offset;
GST_LOG_OBJECT (adapter, "offset discont now %" G_GUINT64_FORMAT,
adapter->offset_discont);
}
if (offset != GST_BUFFER_OFFSET_NONE) {
GST_LOG_OBJECT (adapter, "new offset %" G_GUINT64_FORMAT, offset);
adapter->offset = offset;
adapter->offset_distance = 0;
}
if (GST_BUFFER_IS_DISCONT (buf)) {
/* Take values as-is (might be NONE) */
adapter->pts_at_discont = pts;
adapter->dts_at_discont = dts;
adapter->offset_at_discont = offset;
adapter->distance_from_discont = 0;
}
}
/* copy data into @dest, skipping @skip bytes from the head buffers */
......@@ -634,7 +645,7 @@ gst_adapter_flush_unchecked (GstAdapter * adapter, gsize flush)
adapter->pts_distance -= adapter->skip;
adapter->dts_distance -= adapter->skip;
adapter->offset_distance -= adapter->skip;
INCREASE_OFFSET (adapter, -adapter->skip);
adapter->distance_from_discont -= adapter->skip;
g = adapter->buflist;
cur = g->data;
......@@ -645,8 +656,8 @@ gst_adapter_flush_unchecked (GstAdapter * adapter, gsize flush)
adapter->pts_distance += size;
adapter->dts_distance += size;
adapter->offset_distance += size;
adapter->distance_from_discont += size;
flush -= size;
INCREASE_OFFSET (adapter, size);
gst_buffer_unref (cur);
g = g_slist_delete_link (g, g);
......@@ -668,7 +679,7 @@ gst_adapter_flush_unchecked (GstAdapter * adapter, gsize flush)
adapter->pts_distance += flush;
adapter->dts_distance += flush;
adapter->offset_distance += flush;
INCREASE_OFFSET (adapter, flush);
adapter->distance_from_discont += flush;
/* invalidate scan position */
adapter->scan_offset = 0;
adapter->scan_entry = NULL;
......@@ -1354,24 +1365,81 @@ gst_adapter_available_fast (GstAdapter * adapter)
}
/**
* gst_adapter_get_offset_from_discont:
* gst_adapter_get_distance_from_discont:
* @adapter: a #GstAdapter
*
* Get the offset of the adapter based on the incoming buffer offset. Will only
* return valid values if the incoming buffers have valid offsets set on them.
* Get the distance in bytes since the last buffer with the
* %GST_BUFFER_FLAG_DISCONT flag.
*
* The offset will be initially recorded for all buffers with
* %GST_BUFFER_FLAG_DISCONT on them, and then calculated for all other following
* buffers based on their size.
* The distance will be reset to 0 for all buffers with
* %GST_BUFFER_FLAG_DISCONT on them, and then calculated for all other
* following buffers based on their size.
*
* Since: 1.10
*
* Returns: The offset. Can be %GST_BUFFER_OFFSET_NONE.
*/
guint64
gst_adapter_get_offset_from_discont (GstAdapter * adapter)
gst_adapter_distance_from_discont (GstAdapter * adapter)
{
return adapter->distance_from_discont;
}
/**
* gst_adapter_offset_at_discont:
* @adapter: a #GstAdapter
*
* Get the offset that was on the last buffer with the GST_BUFFER_FLAG_DISCONT
* flag, or GST_BUFFER_OFFSET_NONE.
*
* Since: 1.10
*
* Returns: The offset at the last discont or GST_BUFFER_OFFSET_NONE.
*/
guint64
gst_adapter_offset_at_discont (GstAdapter * adapter)
{
g_return_val_if_fail (GST_IS_ADAPTER (adapter), GST_BUFFER_OFFSET_NONE);
return adapter->offset_at_discont;
}
/**
* gst_adapter_pts_at_discont:
* @adapter: a #GstAdapter
*
* Get the PTS that was on the last buffer with the GST_BUFFER_FLAG_DISCONT
* flag, or GST_CLOCK_TIME_NONE.
*
* Since: 1.10
*
* Returns: The PTS at the last discont or GST_CLOCK_TIME_NONE.
*/
GstClockTime
gst_adapter_pts_at_discont (GstAdapter * adapter)
{
g_return_val_if_fail (GST_IS_ADAPTER (adapter), GST_CLOCK_TIME_NONE);
return adapter->pts_at_discont;
}
/**
* gst_adapter_dts_at_discont:
* @adapter: a #GstAdapter
*
* Get the DTS that was on the last buffer with the GST_BUFFER_FLAG_DISCONT
* flag, or GST_CLOCK_TIME_NONE.
*
* Since: 1.10
*
* Returns: The DTS at the last discont or GST_CLOCK_TIME_NONE.
*/
GstClockTime
gst_adapter_dts_at_discont (GstAdapter * adapter)
{
return adapter->offset_discont;
g_return_val_if_fail (GST_IS_ADAPTER (adapter), GST_CLOCK_TIME_NONE);
return adapter->dts_at_discont;
}
/**
......@@ -1401,7 +1469,6 @@ gst_adapter_prev_offset (GstAdapter * adapter, guint64 * distance)
*distance = adapter->offset_distance;
return adapter->offset;
}
/**
......
......@@ -76,7 +76,12 @@ GstClockTime gst_adapter_prev_dts (GstAdapter *adapter, gu
GstClockTime gst_adapter_prev_pts_at_offset (GstAdapter * adapter, gsize offset, guint64 * distance);
GstClockTime gst_adapter_prev_dts_at_offset (GstAdapter * adapter, gsize offset, guint64 * distance);
guint64 gst_adapter_prev_offset (GstAdapter *adapter, guint64 *distance);
guint64 gst_adapter_get_offset_from_discont (GstAdapter *adapter);
GstClockTime gst_adapter_pts_at_discont (GstAdapter *adapter);
GstClockTime gst_adapter_dts_at_discont (GstAdapter *adapter);
guint64 gst_adapter_offset_at_discont (GstAdapter *adapter);
guint64 gst_adapter_distance_from_discont (GstAdapter *adapter);
gssize gst_adapter_masked_scan_uint32 (GstAdapter * adapter, guint32 mask,
guint32 pattern, gsize offset, gsize size);
......
This diff is collapsed.
......@@ -4,22 +4,25 @@ EXPORTS
gst_adapter_clear
gst_adapter_copy
gst_adapter_copy_bytes
gst_adapter_distance_from_discont
gst_adapter_dts_at_discont
gst_adapter_flush
gst_adapter_get_buffer
gst_adapter_get_buffer_fast
gst_adapter_get_buffer_list
gst_adapter_get_list
gst_adapter_get_offset_from_discont
gst_adapter_get_type
gst_adapter_map
gst_adapter_masked_scan_uint32
gst_adapter_masked_scan_uint32_peek
gst_adapter_new
gst_adapter_offset_at_discont
gst_adapter_prev_dts
gst_adapter_prev_dts_at_offset
gst_adapter_prev_offset
gst_adapter_prev_pts
gst_adapter_prev_pts_at_offset
gst_adapter_pts_at_discont
gst_adapter_push
gst_adapter_take
gst_adapter_take_buffer
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment