From a24689a3067562d7b8d4c01c90e1edc6106627e6 Mon Sep 17 00:00:00 2001 From: Nicolas Huet Date: Wed, 27 Apr 2016 10:57:29 +0200 Subject: [PATCH] adapter: fix distance when getting prev pts/dts at offset https://bugzilla.gnome.org/show_bug.cgi?id=765662 --- libs/gst/base/gstadapter.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/libs/gst/base/gstadapter.c b/libs/gst/base/gstadapter.c index fd7119577a..18c9d45488 100644 --- a/libs/gst/base/gstadapter.c +++ b/libs/gst/base/gstadapter.c @@ -1550,6 +1550,7 @@ gst_adapter_prev_pts_at_offset (GstAdapter * adapter, gsize offset, GstBuffer *cur; GSList *g; gsize read_offset = 0; + gsize pts_offset = 0; GstClockTime pts = adapter->pts; g_return_val_if_fail (GST_IS_ADAPTER (adapter), GST_CLOCK_TIME_NONE); @@ -1559,16 +1560,17 @@ gst_adapter_prev_pts_at_offset (GstAdapter * adapter, gsize offset, while (g && read_offset < offset + adapter->skip) { cur = g->data; - read_offset += gst_buffer_get_size (cur); if (GST_CLOCK_TIME_IS_VALID (GST_BUFFER_PTS (cur))) { pts = GST_BUFFER_PTS (cur); + pts_offset = read_offset; } + read_offset += gst_buffer_get_size (cur); g = g_slist_next (g); } if (distance) - *distance = adapter->pts_distance + offset; + *distance = adapter->pts_distance + offset - pts_offset; return pts; } @@ -1598,6 +1600,7 @@ gst_adapter_prev_dts_at_offset (GstAdapter * adapter, gsize offset, GstBuffer *cur; GSList *g; gsize read_offset = 0; + gsize dts_offset = 0; GstClockTime dts = adapter->dts; g_return_val_if_fail (GST_IS_ADAPTER (adapter), GST_CLOCK_TIME_NONE); @@ -1607,16 +1610,17 @@ gst_adapter_prev_dts_at_offset (GstAdapter * adapter, gsize offset, while (g && read_offset < offset + adapter->skip) { cur = g->data; - read_offset += gst_buffer_get_size (cur); if (GST_CLOCK_TIME_IS_VALID (GST_BUFFER_DTS (cur))) { dts = GST_BUFFER_DTS (cur); + dts_offset = read_offset; } + read_offset += gst_buffer_get_size (cur); g = g_slist_next (g); } if (distance) - *distance = adapter->dts_distance + offset; + *distance = adapter->dts_distance + offset - dts_offset; return dts; }