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
This commit is contained in:
Sebastian Dröge 2016-06-07 11:32:47 +03:00
parent 67ae0ad225
commit 8c7da1d426
5 changed files with 245 additions and 56 deletions

View file

@ -179,7 +179,10 @@ gst_adapter_prev_dts
gst_adapter_prev_pts_at_offset gst_adapter_prev_pts_at_offset
gst_adapter_prev_dts_at_offset gst_adapter_prev_dts_at_offset
gst_adapter_prev_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
gst_adapter_masked_scan_uint32_peek gst_adapter_masked_scan_uint32_peek
<SUBSECTION Standard> <SUBSECTION Standard>

View file

@ -96,12 +96,13 @@
* (#GST_BUFFER_OFFSET) that were pushed. The last seen offset before the * (#GST_BUFFER_OFFSET) that were pushed. The last seen offset before the
* current position can be queried with gst_adapter_prev_offset(). This function * 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 * 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 * that carried the offset and the current adapter position.
* #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 * Additionally the adapter also keeps track of the PTS, DTS and buffer offset
* queried with gst_adapter_get_offset_from_discont(). This is useful for * at the last discontinuity, which can be retrieved with
* elements that want to track the position of data in the stream based on the * gst_adapter_pts_at_discont(), gst_adapter_dts_at_discont() and
* offset of the incoming buffers. * 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, * A last thing to note is that while #GstAdapter is pretty optimized,
* merging buffers still might be an operation that requires a malloc() and * merging buffers still might be an operation that requires a malloc() and
@ -129,8 +130,6 @@
/* default size for the assembled data buffer */ /* default size for the assembled data buffer */
#define DEFAULT_SIZE 4096 #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); static void gst_adapter_flush_unchecked (GstAdapter * adapter, gsize flush);
GST_DEBUG_CATEGORY_STATIC (gst_adapter_debug); GST_DEBUG_CATEGORY_STATIC (gst_adapter_debug);
@ -162,7 +161,11 @@ struct _GstAdapter
gsize scan_offset; gsize scan_offset;
GSList *scan_entry; GSList *scan_entry;
guint64 offset_discont; GstClockTime pts_at_discont;
GstClockTime dts_at_discont;
guint64 offset_at_discont;
guint64 distance_from_discont;
GstMapInfo info; GstMapInfo info;
}; };
@ -200,7 +203,10 @@ gst_adapter_init (GstAdapter * adapter)
adapter->dts_distance = 0; adapter->dts_distance = 0;
adapter->offset = GST_BUFFER_OFFSET_NONE; adapter->offset = GST_BUFFER_OFFSET_NONE;
adapter->offset_distance = 0; 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 static void
@ -264,9 +270,12 @@ gst_adapter_clear (GstAdapter * adapter)
adapter->dts_distance = 0; adapter->dts_distance = 0;
adapter->offset = GST_BUFFER_OFFSET_NONE; adapter->offset = GST_BUFFER_OFFSET_NONE;
adapter->offset_distance = 0; 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_offset = 0;
adapter->scan_entry = NULL; adapter->scan_entry = NULL;
adapter->offset_discont = GST_BUFFER_OFFSET_NONE;
} }
static inline void static inline void
@ -288,17 +297,19 @@ update_timestamps_and_offset (GstAdapter * adapter, GstBuffer * buf)
adapter->dts_distance = 0; adapter->dts_distance = 0;
} }
offset = GST_BUFFER_OFFSET (buf); 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) { if (offset != GST_BUFFER_OFFSET_NONE) {
GST_LOG_OBJECT (adapter, "new offset %" G_GUINT64_FORMAT, offset); GST_LOG_OBJECT (adapter, "new offset %" G_GUINT64_FORMAT, offset);
adapter->offset = offset; adapter->offset = offset;
adapter->offset_distance = 0; 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 */ /* 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->pts_distance -= adapter->skip;
adapter->dts_distance -= adapter->skip; adapter->dts_distance -= adapter->skip;
adapter->offset_distance -= adapter->skip; adapter->offset_distance -= adapter->skip;
INCREASE_OFFSET (adapter, -adapter->skip); adapter->distance_from_discont -= adapter->skip;
g = adapter->buflist; g = adapter->buflist;
cur = g->data; cur = g->data;
@ -645,8 +656,8 @@ gst_adapter_flush_unchecked (GstAdapter * adapter, gsize flush)
adapter->pts_distance += size; adapter->pts_distance += size;
adapter->dts_distance += size; adapter->dts_distance += size;
adapter->offset_distance += size; adapter->offset_distance += size;
adapter->distance_from_discont += size;
flush -= size; flush -= size;
INCREASE_OFFSET (adapter, size);
gst_buffer_unref (cur); gst_buffer_unref (cur);
g = g_slist_delete_link (g, g); g = g_slist_delete_link (g, g);
@ -668,7 +679,7 @@ gst_adapter_flush_unchecked (GstAdapter * adapter, gsize flush)
adapter->pts_distance += flush; adapter->pts_distance += flush;
adapter->dts_distance += flush; adapter->dts_distance += flush;
adapter->offset_distance += flush; adapter->offset_distance += flush;
INCREASE_OFFSET (adapter, flush); adapter->distance_from_discont += flush;
/* invalidate scan position */ /* invalidate scan position */
adapter->scan_offset = 0; adapter->scan_offset = 0;
adapter->scan_entry = NULL; 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 * @adapter: a #GstAdapter
* *
* Get the offset of the adapter based on the incoming buffer offset. Will only * Get the distance in bytes since the last buffer with the
* return valid values if the incoming buffers have valid offsets set on them. * %GST_BUFFER_FLAG_DISCONT flag.
* *
* The offset will be initially recorded for all buffers with * The distance will be reset to 0 for all buffers with
* %GST_BUFFER_FLAG_DISCONT on them, and then calculated for all other following * %GST_BUFFER_FLAG_DISCONT on them, and then calculated for all other
* buffers based on their size. * following buffers based on their size.
* *
* Since: 1.10 * Since: 1.10
* *
* Returns: The offset. Can be %GST_BUFFER_OFFSET_NONE. * Returns: The offset. Can be %GST_BUFFER_OFFSET_NONE.
*/ */
guint64 guint64
gst_adapter_get_offset_from_discont (GstAdapter * adapter) gst_adapter_distance_from_discont (GstAdapter * adapter)
{ {
return adapter->offset_discont; 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)
{
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; *distance = adapter->offset_distance;
return adapter->offset; return adapter->offset;
} }
/** /**

View file

@ -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_pts_at_offset (GstAdapter * adapter, gsize offset, guint64 * distance);
GstClockTime gst_adapter_prev_dts_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_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, gssize gst_adapter_masked_scan_uint32 (GstAdapter * adapter, guint32 mask,
guint32 pattern, gsize offset, gsize size); guint32 pattern, gsize offset, gsize size);

View file

@ -381,9 +381,20 @@ GST_START_TEST (test_timestamp)
fail_unless (timestamp == GST_CLOCK_TIME_NONE); fail_unless (timestamp == GST_CLOCK_TIME_NONE);
fail_unless (dist == 0); fail_unless (dist == 0);
timestamp = gst_adapter_pts_at_discont (adapter);
fail_unless (timestamp == GST_CLOCK_TIME_NONE);
/* Offset should be undefined */ /* Offset should be undefined */
offset = gst_adapter_get_offset_from_discont (adapter); offset = gst_adapter_prev_offset (adapter, &dist);
fail_unless (offset == GST_BUFFER_OFFSET_NONE); fail_unless (offset == GST_BUFFER_OFFSET_NONE);
fail_unless (dist == 0);
offset = gst_adapter_offset_at_discont (adapter);
fail_unless (offset == GST_CLOCK_TIME_NONE);
/* 0 bytes since discont */
dist = gst_adapter_distance_from_discont (adapter);
fail_unless (dist == 0);
gst_adapter_flush (adapter, 50); gst_adapter_flush (adapter, 50);
avail = gst_adapter_available (adapter); avail = gst_adapter_available (adapter);
@ -394,9 +405,20 @@ GST_START_TEST (test_timestamp)
fail_unless (timestamp == GST_CLOCK_TIME_NONE); fail_unless (timestamp == GST_CLOCK_TIME_NONE);
fail_unless (dist == 50); fail_unless (dist == 50);
timestamp = gst_adapter_pts_at_discont (adapter);
fail_unless (timestamp == GST_CLOCK_TIME_NONE);
/* Offset still undefined */ /* Offset still undefined */
offset = gst_adapter_get_offset_from_discont (adapter); offset = gst_adapter_prev_offset (adapter, &dist);
fail_unless (offset == GST_BUFFER_OFFSET_NONE); fail_unless (offset == GST_BUFFER_OFFSET_NONE);
fail_unless (dist == 50);
offset = gst_adapter_offset_at_discont (adapter);
fail_unless (offset == GST_CLOCK_TIME_NONE);
/* 50 bytes since discont */
dist = gst_adapter_distance_from_discont (adapter);
fail_unless (dist == 50);
buffer = gst_buffer_new_and_alloc (100); buffer = gst_buffer_new_and_alloc (100);
GST_BUFFER_TIMESTAMP (buffer) = 1 * GST_SECOND; GST_BUFFER_TIMESTAMP (buffer) = 1 * GST_SECOND;
@ -411,6 +433,21 @@ GST_START_TEST (test_timestamp)
fail_unless (timestamp == GST_CLOCK_TIME_NONE); fail_unless (timestamp == GST_CLOCK_TIME_NONE);
fail_unless (dist == 50); fail_unless (dist == 50);
timestamp = gst_adapter_pts_at_discont (adapter);
fail_unless (timestamp == GST_CLOCK_TIME_NONE);
/* Offset still undefined */
offset = gst_adapter_prev_offset (adapter, &dist);
fail_unless (offset == GST_BUFFER_OFFSET_NONE);
fail_unless (dist == 50);
offset = gst_adapter_offset_at_discont (adapter);
fail_unless (offset == GST_CLOCK_TIME_NONE);
/* 50 bytes since discont */
dist = gst_adapter_distance_from_discont (adapter);
fail_unless (dist == 50);
/* flush out first buffer we are now at the second buffer timestamp */ /* flush out first buffer we are now at the second buffer timestamp */
gst_adapter_flush (adapter, 50); gst_adapter_flush (adapter, 50);
avail = gst_adapter_available (adapter); avail = gst_adapter_available (adapter);
@ -420,6 +457,14 @@ GST_START_TEST (test_timestamp)
fail_unless (timestamp == 1 * GST_SECOND); fail_unless (timestamp == 1 * GST_SECOND);
fail_unless (dist == 0); fail_unless (dist == 0);
/* timestamp was undefined at discont */
timestamp = gst_adapter_pts_at_discont (adapter);
fail_unless (timestamp == GST_CLOCK_TIME_NONE);
/* 100 bytes since discont */
dist = gst_adapter_distance_from_discont (adapter);
fail_unless (dist == 100);
/* move some more, still the same timestamp but further away */ /* move some more, still the same timestamp but further away */
gst_adapter_flush (adapter, 50); gst_adapter_flush (adapter, 50);
avail = gst_adapter_available (adapter); avail = gst_adapter_available (adapter);
@ -429,6 +474,10 @@ GST_START_TEST (test_timestamp)
fail_unless (timestamp == 1 * GST_SECOND); fail_unless (timestamp == 1 * GST_SECOND);
fail_unless (dist == 50); fail_unless (dist == 50);
/* timestamp was undefined at discont */
timestamp = gst_adapter_pts_at_discont (adapter);
fail_unless (timestamp == GST_CLOCK_TIME_NONE);
/* push a buffer without timestamp in the adapter */ /* push a buffer without timestamp in the adapter */
buffer = gst_buffer_new_and_alloc (100); buffer = gst_buffer_new_and_alloc (100);
gst_adapter_push (adapter, buffer); gst_adapter_push (adapter, buffer);
@ -446,6 +495,10 @@ GST_START_TEST (test_timestamp)
fail_unless (timestamp == 1 * GST_SECOND); fail_unless (timestamp == 1 * GST_SECOND);
fail_unless (dist == 50); fail_unless (dist == 50);
/* timestamp was undefined at discont */
timestamp = gst_adapter_pts_at_discont (adapter);
fail_unless (timestamp == GST_CLOCK_TIME_NONE);
/* flush away buffer with the timestamp */ /* flush away buffer with the timestamp */
gst_adapter_flush (adapter, 50); gst_adapter_flush (adapter, 50);
avail = gst_adapter_available (adapter); avail = gst_adapter_available (adapter);
@ -454,6 +507,10 @@ GST_START_TEST (test_timestamp)
fail_unless (timestamp == 1 * GST_SECOND); fail_unless (timestamp == 1 * GST_SECOND);
fail_unless (dist == 100); fail_unless (dist == 100);
/* timestamp was undefined at discont */
timestamp = gst_adapter_pts_at_discont (adapter);
fail_unless (timestamp == GST_CLOCK_TIME_NONE);
/* move into the second buffer */ /* move into the second buffer */
gst_adapter_flush (adapter, 50); gst_adapter_flush (adapter, 50);
avail = gst_adapter_available (adapter); avail = gst_adapter_available (adapter);
@ -462,6 +519,10 @@ GST_START_TEST (test_timestamp)
fail_unless (timestamp == 1 * GST_SECOND); fail_unless (timestamp == 1 * GST_SECOND);
fail_unless (dist == 150); fail_unless (dist == 150);
/* timestamp was undefined at discont */
timestamp = gst_adapter_pts_at_discont (adapter);
fail_unless (timestamp == GST_CLOCK_TIME_NONE);
/* move to third buffer we move to the new timestamp */ /* move to third buffer we move to the new timestamp */
gst_adapter_flush (adapter, 50); gst_adapter_flush (adapter, 50);
avail = gst_adapter_available (adapter); avail = gst_adapter_available (adapter);
@ -470,6 +531,10 @@ GST_START_TEST (test_timestamp)
fail_unless (timestamp == 2 * GST_SECOND); fail_unless (timestamp == 2 * GST_SECOND);
fail_unless (dist == 0); fail_unless (dist == 0);
/* timestamp was undefined at discont */
timestamp = gst_adapter_pts_at_discont (adapter);
fail_unless (timestamp == GST_CLOCK_TIME_NONE);
/* move everything out */ /* move everything out */
gst_adapter_flush (adapter, 100); gst_adapter_flush (adapter, 100);
avail = gst_adapter_available (adapter); avail = gst_adapter_available (adapter);
@ -486,6 +551,10 @@ GST_START_TEST (test_timestamp)
fail_unless (timestamp == GST_CLOCK_TIME_NONE); fail_unless (timestamp == GST_CLOCK_TIME_NONE);
fail_unless (dist == 0); fail_unless (dist == 0);
/* timestamp was undefined at discont */
timestamp = gst_adapter_pts_at_discont (adapter);
fail_unless (timestamp == GST_CLOCK_TIME_NONE);
/* push an empty buffer with timestamp in the adapter */ /* push an empty buffer with timestamp in the adapter */
buffer = gst_buffer_new (); buffer = gst_buffer_new ();
GST_BUFFER_TIMESTAMP (buffer) = 2 * GST_SECOND; GST_BUFFER_TIMESTAMP (buffer) = 2 * GST_SECOND;
@ -496,6 +565,11 @@ GST_START_TEST (test_timestamp)
fail_unless (timestamp == 2 * GST_SECOND); fail_unless (timestamp == 2 * GST_SECOND);
fail_unless (dist == 0); fail_unless (dist == 0);
/* timestamp was undefined at discont (clearing the adapter is not
* necessarily a discont) */
timestamp = gst_adapter_pts_at_discont (adapter);
fail_unless (timestamp == GST_CLOCK_TIME_NONE);
/* push another empty buffer */ /* push another empty buffer */
buffer = gst_buffer_new (); buffer = gst_buffer_new ();
GST_BUFFER_TIMESTAMP (buffer) = 3 * GST_SECOND; GST_BUFFER_TIMESTAMP (buffer) = 3 * GST_SECOND;
@ -591,23 +665,31 @@ GST_START_TEST (test_offset)
fail_unless (avail == 100); fail_unless (avail == 100);
/* Offset should be undefined */ /* Offset should be undefined */
offset = gst_adapter_get_offset_from_discont (adapter); offset = gst_adapter_distance_from_discont (adapter);
fail_unless_equals_uint64 (offset, GST_BUFFER_OFFSET_NONE); fail_unless_equals_uint64 (offset, 0);
offset = gst_adapter_prev_offset (adapter, &dist); offset = gst_adapter_prev_offset (adapter, &dist);
fail_unless_equals_uint64 (offset, GST_BUFFER_OFFSET_NONE); fail_unless_equals_uint64 (offset, GST_BUFFER_OFFSET_NONE);
fail_unless_equals_int (dist, 0); fail_unless_equals_int (dist, 0);
/* Offset is undefined */
offset = gst_adapter_offset_at_discont (adapter);
fail_unless_equals_uint64 (offset, GST_BUFFER_OFFSET_NONE);
gst_adapter_flush (adapter, 50); gst_adapter_flush (adapter, 50);
avail = gst_adapter_available (adapter); avail = gst_adapter_available (adapter);
fail_unless (avail == 50); fail_unless (avail == 50);
/* Offset still undefined, dist changed though */ /* Offset still undefined, dist changed though */
offset = gst_adapter_get_offset_from_discont (adapter); offset = gst_adapter_distance_from_discont (adapter);
fail_unless_equals_uint64 (offset, GST_BUFFER_OFFSET_NONE); fail_unless_equals_uint64 (offset, 50);
offset = gst_adapter_prev_offset (adapter, &dist); offset = gst_adapter_prev_offset (adapter, &dist);
fail_unless_equals_uint64 (offset, GST_BUFFER_OFFSET_NONE); fail_unless_equals_uint64 (offset, GST_BUFFER_OFFSET_NONE);
fail_unless_equals_int (dist, 50); fail_unless_equals_int (dist, 50);
/* Offset is undefined */
offset = gst_adapter_offset_at_discont (adapter);
fail_unless_equals_uint64 (offset, GST_BUFFER_OFFSET_NONE);
/* Let's push in a discont buffer with a valid offset */ /* Let's push in a discont buffer with a valid offset */
buffer = gst_buffer_new_and_alloc (100); buffer = gst_buffer_new_and_alloc (100);
GST_BUFFER_OFFSET (buffer) = 10000; GST_BUFFER_OFFSET (buffer) = 10000;
@ -619,34 +701,45 @@ GST_START_TEST (test_offset)
fail_unless (avail == 150); fail_unless (avail == 150);
/* offset is still undefined */ /* offset is still undefined */
offset = gst_adapter_get_offset_from_discont (adapter); offset = gst_adapter_distance_from_discont (adapter);
fail_unless_equals_uint64 (offset, GST_BUFFER_OFFSET_NONE); fail_unless_equals_uint64 (offset, 50);
offset = gst_adapter_prev_offset (adapter, &dist); offset = gst_adapter_prev_offset (adapter, &dist);
fail_unless_equals_uint64 (offset, GST_BUFFER_OFFSET_NONE); fail_unless_equals_uint64 (offset, GST_BUFFER_OFFSET_NONE);
fail_unless_equals_int (dist, 50); fail_unless_equals_int (dist, 50);
/* Offset is undefined */
offset = gst_adapter_offset_at_discont (adapter);
fail_unless_equals_uint64 (offset, GST_BUFFER_OFFSET_NONE);
/* flush out first buffer we are now at the second buffer offset */ /* flush out first buffer we are now at the second buffer offset */
gst_adapter_flush (adapter, 50); gst_adapter_flush (adapter, 50);
avail = gst_adapter_available (adapter); avail = gst_adapter_available (adapter);
fail_unless (avail == 100); fail_unless (avail == 100);
offset = gst_adapter_get_offset_from_discont (adapter); offset = gst_adapter_distance_from_discont (adapter);
fail_unless_equals_uint64 (offset, 10000); fail_unless_equals_uint64 (offset, 0);
offset = gst_adapter_prev_offset (adapter, &dist); offset = gst_adapter_prev_offset (adapter, &dist);
fail_unless_equals_uint64 (offset, 10000); fail_unless_equals_uint64 (offset, 10000);
fail_unless_equals_int (dist, 0); fail_unless_equals_int (dist, 0);
/* Offset should be defined now */
offset = gst_adapter_offset_at_discont (adapter);
fail_unless_equals_uint64 (offset, 10000);
/* move some more, we should have an updated offset */ /* move some more, we should have an updated offset */
gst_adapter_flush (adapter, 50); gst_adapter_flush (adapter, 50);
avail = gst_adapter_available (adapter); avail = gst_adapter_available (adapter);
fail_unless (avail == 50); fail_unless (avail == 50);
offset = gst_adapter_get_offset_from_discont (adapter); offset = gst_adapter_distance_from_discont (adapter);
fail_unless_equals_uint64 (offset, 10050); fail_unless_equals_uint64 (offset, 50);
offset = gst_adapter_prev_offset (adapter, &dist); offset = gst_adapter_prev_offset (adapter, &dist);
fail_unless_equals_uint64 (offset, 10000); fail_unless_equals_uint64 (offset, 10000);
fail_unless_equals_int (dist, 50); fail_unless_equals_int (dist, 50);
offset = gst_adapter_offset_at_discont (adapter);
fail_unless_equals_uint64 (offset, 10000);
/* push a buffer without offset in the adapter (contiguous with the /* push a buffer without offset in the adapter (contiguous with the
other) */ other) */
buffer = gst_buffer_new_and_alloc (100); buffer = gst_buffer_new_and_alloc (100);
@ -663,65 +756,83 @@ GST_START_TEST (test_offset)
fail_unless (avail == 250); fail_unless (avail == 250);
/* offset still as it was before the push */ /* offset still as it was before the push */
offset = gst_adapter_get_offset_from_discont (adapter); offset = gst_adapter_distance_from_discont (adapter);
fail_unless_equals_uint64 (offset, 10050); fail_unless_equals_uint64 (offset, 50);
offset = gst_adapter_prev_offset (adapter, &dist); offset = gst_adapter_prev_offset (adapter, &dist);
fail_unless_equals_uint64 (offset, 10000); fail_unless_equals_uint64 (offset, 10000);
fail_unless_equals_int (dist, 50); fail_unless_equals_int (dist, 50);
offset = gst_adapter_offset_at_discont (adapter);
fail_unless_equals_uint64 (offset, 10000);
/* flush away buffer with the offset */ /* flush away buffer with the offset */
gst_adapter_flush (adapter, 50); gst_adapter_flush (adapter, 50);
avail = gst_adapter_available (adapter); avail = gst_adapter_available (adapter);
fail_unless (avail == 200); fail_unless (avail == 200);
offset = gst_adapter_get_offset_from_discont (adapter); offset = gst_adapter_distance_from_discont (adapter);
fail_unless_equals_uint64 (offset, 10100); fail_unless_equals_uint64 (offset, 100);
/* The previous valid offset seen is now 100 bytes away */ /* The previous valid offset seen is now 100 bytes away */
offset = gst_adapter_prev_offset (adapter, &dist); offset = gst_adapter_prev_offset (adapter, &dist);
fail_unless_equals_uint64 (offset, 10000); fail_unless_equals_uint64 (offset, 10000);
fail_unless_equals_int (dist, 100); fail_unless_equals_int (dist, 100);
offset = gst_adapter_offset_at_discont (adapter);
fail_unless_equals_uint64 (offset, 10000);
/* move into the second buffer */ /* move into the second buffer */
gst_adapter_flush (adapter, 50); gst_adapter_flush (adapter, 50);
avail = gst_adapter_available (adapter); avail = gst_adapter_available (adapter);
fail_unless (avail == 150); fail_unless (avail == 150);
offset = gst_adapter_get_offset_from_discont (adapter); offset = gst_adapter_distance_from_discont (adapter);
fail_unless_equals_uint64 (offset, 10150); fail_unless_equals_uint64 (offset, 150);
offset = gst_adapter_prev_offset (adapter, &dist); offset = gst_adapter_prev_offset (adapter, &dist);
fail_unless_equals_uint64 (offset, 10000); fail_unless_equals_uint64 (offset, 10000);
fail_unless_equals_int (dist, 150); fail_unless_equals_int (dist, 150);
offset = gst_adapter_offset_at_discont (adapter);
fail_unless_equals_uint64 (offset, 10000);
/* move to third buffer, we should still see a continuously increasing /* move to third buffer, we should still see a continuously increasing
* offset and ignore the non-discont offset */ * offset and ignore the non-discont offset */
gst_adapter_flush (adapter, 50); gst_adapter_flush (adapter, 50);
avail = gst_adapter_available (adapter); avail = gst_adapter_available (adapter);
fail_unless (avail == 100); fail_unless (avail == 100);
offset = gst_adapter_get_offset_from_discont (adapter); offset = gst_adapter_distance_from_discont (adapter);
fail_unless_equals_uint64 (offset, 10200); fail_unless_equals_uint64 (offset, 200);
/* But the prev_offset *does* give us the actual buffer offset value */ /* But the prev_offset *does* give us the actual buffer offset value */
offset = gst_adapter_prev_offset (adapter, &dist); offset = gst_adapter_prev_offset (adapter, &dist);
fail_unless_equals_uint64 (offset, 50000); fail_unless_equals_uint64 (offset, 50000);
fail_unless_equals_int (dist, 0); fail_unless_equals_int (dist, 0);
offset = gst_adapter_offset_at_discont (adapter);
fail_unless_equals_uint64 (offset, 10000);
/* move everything out, we end up at the last offset */ /* move everything out, we end up at the last offset */
gst_adapter_flush (adapter, 100); gst_adapter_flush (adapter, 100);
avail = gst_adapter_available (adapter); avail = gst_adapter_available (adapter);
fail_unless (avail == 0); fail_unless (avail == 0);
offset = gst_adapter_get_offset_from_discont (adapter); offset = gst_adapter_distance_from_discont (adapter);
fail_unless_equals_uint64 (offset, 10300); fail_unless_equals_uint64 (offset, 300);
offset = gst_adapter_prev_offset (adapter, &dist); offset = gst_adapter_prev_offset (adapter, &dist);
fail_unless_equals_uint64 (offset, 50000); fail_unless_equals_uint64 (offset, 50000);
fail_unless_equals_int (dist, 100); fail_unless_equals_int (dist, 100);
offset = gst_adapter_offset_at_discont (adapter);
fail_unless_equals_uint64 (offset, 10000);
/* clear everything */ /* clear everything */
gst_adapter_clear (adapter); gst_adapter_clear (adapter);
avail = gst_adapter_available (adapter); avail = gst_adapter_available (adapter);
fail_unless (avail == 0); fail_unless (avail == 0);
offset = gst_adapter_get_offset_from_discont (adapter); offset = gst_adapter_distance_from_discont (adapter);
fail_unless_equals_uint64 (offset, GST_BUFFER_OFFSET_NONE); fail_unless_equals_uint64 (offset, 0);
offset = gst_adapter_prev_offset (adapter, &dist); offset = gst_adapter_prev_offset (adapter, &dist);
fail_unless_equals_uint64 (offset, GST_BUFFER_OFFSET_NONE); fail_unless_equals_uint64 (offset, GST_BUFFER_OFFSET_NONE);
fail_unless_equals_int (dist, 0); fail_unless_equals_int (dist, 0);
offset = gst_adapter_offset_at_discont (adapter);
fail_unless_equals_uint64 (offset, GST_BUFFER_OFFSET_NONE);
g_object_unref (adapter); g_object_unref (adapter);
} }

View file

@ -4,22 +4,25 @@ EXPORTS
gst_adapter_clear gst_adapter_clear
gst_adapter_copy gst_adapter_copy
gst_adapter_copy_bytes gst_adapter_copy_bytes
gst_adapter_distance_from_discont
gst_adapter_dts_at_discont
gst_adapter_flush gst_adapter_flush
gst_adapter_get_buffer gst_adapter_get_buffer
gst_adapter_get_buffer_fast gst_adapter_get_buffer_fast
gst_adapter_get_buffer_list gst_adapter_get_buffer_list
gst_adapter_get_list gst_adapter_get_list
gst_adapter_get_offset_from_discont
gst_adapter_get_type gst_adapter_get_type
gst_adapter_map gst_adapter_map
gst_adapter_masked_scan_uint32 gst_adapter_masked_scan_uint32
gst_adapter_masked_scan_uint32_peek gst_adapter_masked_scan_uint32_peek
gst_adapter_new gst_adapter_new
gst_adapter_offset_at_discont
gst_adapter_prev_dts gst_adapter_prev_dts
gst_adapter_prev_dts_at_offset gst_adapter_prev_dts_at_offset
gst_adapter_prev_offset gst_adapter_prev_offset
gst_adapter_prev_pts gst_adapter_prev_pts
gst_adapter_prev_pts_at_offset gst_adapter_prev_pts_at_offset
gst_adapter_pts_at_discont
gst_adapter_push gst_adapter_push
gst_adapter_take gst_adapter_take
gst_adapter_take_buffer gst_adapter_take_buffer