From aa5b5b908538ead710ed81b21032659ee943ae31 Mon Sep 17 00:00:00 2001 From: Vincent Penquerc'h Date: Thu, 5 Jun 2014 14:54:31 +0100 Subject: [PATCH] oggmux: set correct granpos on last page when samples are clipped Samples may be clipped at the end, and this is conveyed by a granulepos that's smaller than it would otherwise be. Use the segment stop time to detect this, and calculate the right granulepos. --- ext/ogg/gstoggmux.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/ext/ogg/gstoggmux.c b/ext/ogg/gstoggmux.c index b4f18166c3..6899f798f9 100644 --- a/ext/ogg/gstoggmux.c +++ b/ext/ogg/gstoggmux.c @@ -816,7 +816,7 @@ static GstBuffer * gst_ogg_mux_decorate_buffer (GstOggMux * ogg_mux, GstOggPadData * pad, GstBuffer * buf) { - GstClockTime time; + GstClockTime time, end_time; gint64 duration, granule, limit; GstClockTime next_time; GstClockTimeDiff diff; @@ -866,6 +866,24 @@ gst_ogg_mux_decorate_buffer (GstOggMux * ogg_mux, GstOggPadData * pad, goto no_granule; } + /* The last packet may have clipped samples. We need to test against + * the segment to ensure we do not use a granpos that encompasses those. + */ + end_time = + gst_ogg_stream_granule_to_time (&pad->map, pad->next_granule + duration); + if (!GST_CLOCK_TIME_IS_VALID (gst_segment_to_running_time (&pad->segment, + GST_FORMAT_TIME, end_time))) { + gint64 actual_duration = + gst_util_uint64_scale_round (pad->segment.stop - time, + pad->map.granulerate_n, + GST_SECOND * pad->map.granulerate_d); + GST_INFO_OBJECT (ogg_mux, + "Got clipped last packet of duration %" G_GINT64_FORMAT " (%" + G_GINT64_FORMAT " clipped)", actual_duration, + duration - actual_duration); + duration = actual_duration; + } + GST_LOG_OBJECT (pad->collect.pad, "buffer ts %" GST_TIME_FORMAT ", duration %" GST_TIME_FORMAT ", granule duration %" G_GINT64_FORMAT, GST_TIME_ARGS (time), GST_TIME_ARGS (GST_BUFFER_DURATION (buf)),