From 0fa8d284c7b831db83c2ac1c74cc990c737cacf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Tue, 3 Nov 2015 11:11:57 +0200 Subject: [PATCH] oggmux: Use GstAudioClippingMeta for Opus for accurate end clipping ... instead of relying on the segment. For the clipping at the start we assume a proper value in the OpusHead, as generated by opusparse or opusenc. Transmuxing in general is not guaranteed to produce the correct values, or even have a OpusHead (e.g. when having RTP input). https://bugzilla.gnome.org/show_bug.cgi?id=757153 --- ext/ogg/gstoggmux.c | 45 +++++++++++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/ext/ogg/gstoggmux.c b/ext/ogg/gstoggmux.c index 08eeea8141..4e1ce94313 100644 --- a/ext/ogg/gstoggmux.c +++ b/ext/ogg/gstoggmux.c @@ -39,6 +39,7 @@ #include #include +#include #include #include "gstoggmux.h" @@ -806,6 +807,7 @@ gst_ogg_mux_decorate_buffer (GstOggMux * ogg_mux, GstOggPadData * pad, GstClockTimeDiff diff; GstMapInfo map; ogg_packet packet; + gboolean end_clip = TRUE; /* ensure messing with metadata is ok */ buf = gst_buffer_make_writable (buf); @@ -853,20 +855,35 @@ gst_ogg_mux_decorate_buffer (GstOggMux * ogg_mux, GstOggPadData * pad, /* 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 (end_time > pad->segment.stop - && !GST_CLOCK_TIME_IS_VALID (gst_segment_to_running_time (&pad->segment, - GST_FORMAT_TIME, pad->segment.start + 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; + if (pad->map.audio_clipping) { + GstAudioClippingMeta *cmeta = gst_buffer_get_audio_clipping_meta (buf); + + g_assert (!cmeta || cmeta->format == GST_FORMAT_DEFAULT); + if (cmeta && cmeta->end && cmeta->end < duration) { + GST_DEBUG_OBJECT (pad->collect.pad, + "Clipping %" G_GUINT64_FORMAT " samples at the end", cmeta->end); + duration -= cmeta->end; + end_clip = FALSE; + } + } + + if (end_clip) { + end_time = + gst_ogg_stream_granule_to_time (&pad->map, + pad->next_granule + duration); + if (end_time > pad->segment.stop + && !GST_CLOCK_TIME_IS_VALID (gst_segment_to_running_time (&pad->segment, + GST_FORMAT_TIME, pad->segment.start + 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