mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-02-23 06:26:23 +00:00
oggdemux: Add GstAudioClippingMeta for Opus for accurate start/end clipping
https://bugzilla.gnome.org/show_bug.cgi?id=757153
This commit is contained in:
parent
35ea6fdddf
commit
a135868262
4 changed files with 33 additions and 0 deletions
|
@ -30,6 +30,7 @@ libgstogg_la_LIBADD = \
|
|||
$(top_builddir)/gst-libs/gst/riff/libgstriff-$(GST_API_VERSION).la \
|
||||
$(top_builddir)/gst-libs/gst/tag/libgsttag-$(GST_API_VERSION).la \
|
||||
$(top_builddir)/gst-libs/gst/pbutils/libgstpbutils-$(GST_API_VERSION).la \
|
||||
$(top_builddir)/gst-libs/gst/audio/libgstaudio-$(GST_API_VERSION).la \
|
||||
$(GST_BASE_LIBS) \
|
||||
$(GST_LIBS) \
|
||||
$(OGG_LIBS)
|
||||
|
|
|
@ -41,6 +41,7 @@
|
|||
#include <string.h>
|
||||
#include <gst/gst-i18n-plugin.h>
|
||||
#include <gst/tag/tag.h>
|
||||
#include <gst/audio/audio.h>
|
||||
|
||||
#include "gstoggdemux.h"
|
||||
|
||||
|
@ -500,6 +501,7 @@ gst_ogg_demux_chain_peer (GstOggPad * pad, ogg_packet * packet,
|
|||
guint64 out_offset, out_offset_end;
|
||||
gboolean delta_unit = FALSE;
|
||||
gboolean is_header;
|
||||
guint64 clip_start = 0, clip_end = 0;
|
||||
|
||||
ret = cret = GST_FLOW_OK;
|
||||
GST_DEBUG_OBJECT (pad, "Chaining %d %d %" GST_TIME_FORMAT " %d %p",
|
||||
|
@ -723,9 +725,29 @@ gst_ogg_demux_chain_peer (GstOggPad * pad, ogg_packet * packet,
|
|||
pad->prev_granule);
|
||||
else
|
||||
out_timestamp = 0;
|
||||
|
||||
if (pad->map.audio_clipping
|
||||
&& pad->current_granule < pad->prev_granule + duration) {
|
||||
clip_end = pad->prev_granule + duration - pad->current_granule;
|
||||
}
|
||||
if (pad->map.audio_clipping
|
||||
&& pad->current_granule - duration < -pad->map.granule_offset) {
|
||||
if (pad->current_granule >= -pad->map.granule_offset)
|
||||
clip_start = -pad->map.granule_offset;
|
||||
else
|
||||
clip_start = pad->current_granule;
|
||||
}
|
||||
} else {
|
||||
out_timestamp = gst_ogg_stream_granule_to_time (&pad->map,
|
||||
pad->current_granule - duration);
|
||||
|
||||
if (pad->map.audio_clipping
|
||||
&& pad->current_granule - duration < -pad->map.granule_offset) {
|
||||
if (pad->current_granule >= -pad->map.granule_offset)
|
||||
clip_start = -pad->map.granule_offset;
|
||||
else
|
||||
clip_start = pad->current_granule;
|
||||
}
|
||||
}
|
||||
out_duration =
|
||||
gst_ogg_stream_granule_to_time (&pad->map,
|
||||
|
@ -751,6 +773,14 @@ gst_ogg_demux_chain_peer (GstOggPad * pad, ogg_packet * packet,
|
|||
|
||||
buf = gst_buffer_new_and_alloc (packet->bytes - offset - trim);
|
||||
|
||||
if (pad->map.audio_clipping && (clip_start || clip_end)) {
|
||||
GST_DEBUG_OBJECT (pad,
|
||||
"Adding audio clipping %" G_GUINT64_FORMAT " %" G_GUINT64_FORMAT,
|
||||
clip_start, clip_end);
|
||||
gst_buffer_add_audio_clipping_meta (buf, GST_FORMAT_DEFAULT, clip_start,
|
||||
clip_end);
|
||||
}
|
||||
|
||||
/* set delta flag for OGM content */
|
||||
if (delta_unit)
|
||||
GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_DELTA_UNIT);
|
||||
|
|
|
@ -2000,6 +2000,7 @@ setup_opus_mapper (GstOggStream * pad, ogg_packet * packet)
|
|||
pad->granuleshift = 0;
|
||||
pad->n_header_packets = 2;
|
||||
pad->first_granpos = -1;
|
||||
pad->audio_clipping = TRUE;
|
||||
|
||||
/* pre-skip is in samples at 48000 Hz, which matches granule one for one */
|
||||
pad->granule_offset = -GST_READ_UINT16_LE (packet->packet + 10);
|
||||
|
|
|
@ -70,6 +70,7 @@ struct _GstOggStream
|
|||
gint bitrate;
|
||||
guint64 total_time;
|
||||
gboolean is_sparse;
|
||||
gboolean audio_clipping;
|
||||
|
||||
GstCaps *caps;
|
||||
|
||||
|
|
Loading…
Reference in a new issue