tsdemux/mux: Add support for GstAudioClippingMeta for Opus

https://bugzilla.gnome.org/show_bug.cgi?id=757153
This commit is contained in:
Sebastian Dröge 2015-11-02 18:02:55 +02:00
parent 8a837c6715
commit ecf7c7742c
4 changed files with 32 additions and 11 deletions

View file

@ -15,7 +15,7 @@ libgstmpegtsdemux_la_LIBADD = \
$(top_builddir)/gst-libs/gst/mpegts/libgstmpegts-$(GST_API_VERSION).la \
$(top_builddir)/gst-libs/gst/codecparsers/libgstcodecparsers-$(GST_API_VERSION).la \
$(GST_PLUGINS_BASE_LIBS) -lgsttag-$(GST_API_VERSION) \
-lgstpbutils-@GST_API_VERSION@ \
-lgstpbutils-@GST_API_VERSION@ -lgstaudio-$(GST_API_VERSION) \
$(GST_BASE_LIBS) $(GST_LIBS) $(LIBM)
libgstmpegtsdemux_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
libgstmpegtsdemux_la_LIBTOOLFLAGS = $(GST_PLUGIN_LIBTOOLFLAGS)

View file

@ -38,6 +38,7 @@
#include <gst/tag/tag.h>
#include <gst/pbutils/pbutils.h>
#include <gst/base/base.h>
#include <gst/audio/audio.h>
#include "mpegtsbase.h"
#include "tsdemux.h"
@ -2363,13 +2364,11 @@ parse_opus_access_unit (TSDemuxStream * stream)
if (start_trim_flag) {
if (!gst_byte_reader_get_uint16_be (&reader, &start_trim))
goto error;
start_trim >>= 3;
}
if (end_trim_flag) {
if (!gst_byte_reader_get_uint16_be (&reader, &end_trim))
goto error;
end_trim >>= 3;
}
if (control_extension_flag) {
@ -2393,13 +2392,13 @@ parse_opus_access_unit (TSDemuxStream * stream)
goto error;
buffer = gst_buffer_new_wrapped (packet_data, packet_size);
gst_buffer_list_add (buffer_list, buffer);
/* FIXME: Do something with start_trim and end_trim */
if (start_trim != 0 || end_trim != 0)
GST_FIXME
("Handling of Opus start_trim (%u) and end_trim (%u) not implemented",
if (start_trim != 0 || end_trim != 0) {
gst_buffer_add_audio_clipping_meta (buffer, GST_FORMAT_DEFAULT,
start_trim, end_trim);
}
gst_buffer_list_add (buffer_list, buffer);
} while (gst_byte_reader_get_remaining (&reader) > 0);
g_free (stream->data);

View file

@ -11,8 +11,9 @@ libgstmpegtsmux_la_SOURCES = \
libgstmpegtsmux_la_CFLAGS = $(GST_PLUGINS_BAD_CFLAGS) $(GST_PLUGINS_BASE_CFLAGS) \
$(GST_BASE_CFLAGS) $(GST_CFLAGS)
libgstmpegtsmux_la_LIBADD = $(top_builddir)/gst/mpegtsmux/tsmux/libtsmux.la \
-lgsttag-@GST_API_VERSION@ \
$(GST_PLUGINS_BASE_LIBS) -lgstvideo-@GST_API_VERSION@ $(GST_BASE_LIBS) $(GST_LIBS)
$(GST_PLUGINS_BASE_LIBS) -lgstvideo-@GST_API_VERSION@ \
-lgstaudio-@GST_API_VERSION@ -lgsttag-@GST_API_VERSION@ \
$(GST_BASE_LIBS) $(GST_LIBS)
libgstmpegtsmux_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
libgstmpegtsmux_la_LIBTOOLFLAGS = $(GST_PLUGIN_LIBTOOLFLAGS)

View file

@ -86,6 +86,7 @@
#include "mpegtsmux_opus.h"
#include <string.h>
#include <gst/audio/audio.h>
#define GST_CAT_DEFAULT mpegtsmux_debug
@ -98,9 +99,15 @@ mpegtsmux_prepare_opus (GstBuffer * buf, MpegTsPadData * pad_data,
GstBuffer *outbuf;
GstMapInfo map;
guint n;
GstAudioClippingMeta *cmeta = gst_buffer_get_audio_clipping_meta (buf);
g_assert (!cmeta || cmeta->format == GST_FORMAT_DEFAULT);
/* TODO: Write start/end trim */
outsize = 2 + insize / 255 + 1;
if (cmeta && cmeta->start)
outsize += 2;
if (cmeta && cmeta->end)
outsize += 2;
outbuf = gst_buffer_new_and_alloc (outsize);
gst_buffer_copy_into (outbuf, buf,
@ -108,6 +115,12 @@ mpegtsmux_prepare_opus (GstBuffer * buf, MpegTsPadData * pad_data,
gst_buffer_map (outbuf, &map, GST_MAP_WRITE);
map.data[0] = 0x7f;
map.data[1] = 0xe0;
if (cmeta && cmeta->start)
map.data[1] |= 0x10;
if (cmeta && cmeta->end)
map.data[1] |= 0x08;
n = 2;
do {
g_assert (n < outsize);
@ -120,6 +133,14 @@ mpegtsmux_prepare_opus (GstBuffer * buf, MpegTsPadData * pad_data,
n++;
} while (insize >= 0);
if (cmeta && cmeta->start) {
GST_WRITE_UINT16_BE (&map.data[n], cmeta->start);
n += 2;
}
if (cmeta && cmeta->end)
GST_WRITE_UINT16_BE (&map.data[n], cmeta->end);
gst_buffer_unmap (outbuf, &map);
outbuf = gst_buffer_append (outbuf, gst_buffer_ref (buf));