diff options
author | Sebastian Dröge <sebastian@centricular.com> | 2015-11-03 11:11:57 +0200 |
---|---|---|
committer | Sebastian Dröge <sebastian@centricular.com> | 2015-11-03 20:35:33 +0200 |
commit | 0fa8d284c7b831db83c2ac1c74cc990c737cacf9 (patch) | |
tree | 64dae9540e8e5893bbe8d6c2675e36240a871b20 /ext | |
parent | a135868262f183eecd1957c0053da75cebb956bf (diff) |
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
Diffstat (limited to 'ext')
-rw-r--r-- | ext/ogg/gstoggmux.c | 45 |
1 files changed, 31 insertions, 14 deletions
diff --git a/ext/ogg/gstoggmux.c b/ext/ogg/gstoggmux.c index 08eeea814..4e1ce9431 100644 --- a/ext/ogg/gstoggmux.c +++ b/ext/ogg/gstoggmux.c @@ -39,6 +39,7 @@ #include <gst/gst.h> #include <gst/base/gstbytewriter.h> +#include <gst/audio/audio.h> #include <gst/tag/tag.h> #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 |