mpegtsmux: add support for DVB subtitle and teletext streams

See bug #673582.

Conflicts:

	gst/mpegtsmux/Makefile.am
This commit is contained in:
Mark Nauwelaerts 2012-06-16 16:50:43 +02:00
parent 898f6b48be
commit beceb09acc
6 changed files with 288 additions and 3 deletions

View file

@ -4,7 +4,8 @@ SUBDIRS = tsmux
libgstmpegtsmux_la_SOURCES = \
mpegtsmux.c \
mpegtsmux_aac.c
mpegtsmux_aac.c \
mpegtsmux_ttxt.c
libgstmpegtsmux_la_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_BASE_CFLAGS) $(GST_CFLAGS)
libgstmpegtsmux_la_LIBADD = $(top_builddir)/gst/mpegtsmux/tsmux/libtsmux.la \
@ -14,4 +15,5 @@ libgstmpegtsmux_la_LIBTOOLFLAGS = --tag=disable-static
noinst_HEADERS = \
mpegtsmux.h \
mpegtsmux_aac.h
mpegtsmux_aac.h \
mpegtsmux_ttxt.h

View file

@ -97,6 +97,7 @@
#include "mpegtsmux.h"
#include "mpegtsmux_aac.h"
#include "mpegtsmux_ttxt.h"
GST_DEBUG_CATEGORY (mpegtsmux_debug);
#define GST_CAT_DEFAULT mpegtsmux_debug
@ -133,7 +134,8 @@ static GstStaticPadTemplate mpegtsmux_sink_factory =
"channels = (int) [ 1, 8 ], "
"dynamic_range = (int) [ 0, 255 ], "
"emphasis = (boolean) { FALSE, TRUE }, "
"mute = (boolean) { FALSE, TRUE }; " "audio/x-ac3;" "audio/x-dts"));
"mute = (boolean) { FALSE, TRUE }; " "audio/x-ac3;" "audio/x-dts;"
"subpicture/x-dvb;" "private/teletext"));
static GstStaticPadTemplate mpegtsmux_src_factory =
GST_STATIC_PAD_TEMPLATE ("src",
@ -635,6 +637,12 @@ mpegtsmux_create_stream (MpegTsMux * mux, MpegTsPadData * ts_data)
GST_WARNING_OBJECT (pad, "unsupported mpegversion %d", mpegversion);
goto not_negotiated;
}
} else if (strcmp (mt, "subpicture/x-dvb") == 0) {
st = TSMUX_ST_PS_DVB_SUBPICTURE;
} else if (strcmp (mt, "private/teletext") == 0) {
st = TSMUX_ST_PS_TELETEXT;
/* needs a particularly sized layout */
ts_data->prepare_func = mpegtsmux_prepare_teletext;
}
if (st != TSMUX_ST_RESERVED) {

View file

@ -0,0 +1,156 @@
/*
* Copyright 2006, 2007, 2008 Fluendo S.A.
* Authors: Jan Schmidt <jan@fluendo.com>
* Kapil Agrawal <kapil@fluendo.com>
* Julien Moutte <julien@fluendo.com>
*
* This library is licensed under 4 different licenses and you
* can choose to use it under the terms of any one of them. The
* four licenses are the MPL 1.1, the LGPL, the GPL and the MIT
* license.
*
* MPL:
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/.
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* LGPL:
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
* GPL:
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* MIT:
*
* Unless otherwise indicated, Source Code is licensed under MIT license.
* See further explanation attached in License Statement (distributed in the file
* LICENSE).
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "mpegtsmux_ttxt.h"
#include <string.h>
#define GST_CAT_DEFAULT mpegtsmux_debug
/* from EN 300 472 spec: ITU-R System B Teletext in DVB
*
* PES packet = PES header + PES payload data
* where PES header must be fixed at 45 bytes (likely by using PES stuffing)
* PES packet must completely fill an integral number of TS packets
* using (184 bytes) payload data only (so no adaptation field stuffing)
*/
GstBuffer *
mpegtsmux_prepare_teletext (GstBuffer * buf, MpegTsPadData * pad_data,
MpegTsMux * mux)
{
GstBuffer *out_buf;
guint8 *data, *odata;
gint size, stuff;
gboolean add_id;
GstMapInfo map, omap;
gst_buffer_map (buf, &map, GST_MAP_READ);
size = map.size;
data = map.data;
/* check if leading data_identifier byte is already present,
* if not increase size since it will need to be added */
if (data[0] < 0x10 || data[0] > 0x1F) {
size += 1;
add_id = TRUE;
}
if (size <= 184 - 45) {
stuff = 184 - 45 - size;
} else {
stuff = size - (184 - 45);
stuff = 184 - (stuff % 184);
}
if (G_UNLIKELY (stuff == 1))
stuff += 184;
GST_DEBUG_OBJECT (mux, "Preparing teletext buffer for output");
out_buf = gst_buffer_new_and_alloc (size + stuff);
gst_buffer_copy_into (out_buf, buf,
GST_BUFFER_COPY_METADATA | GST_BUFFER_COPY_TIMESTAMPS, 0, 0);
/* copy data */
gst_buffer_map (out_buf, &omap, GST_MAP_WRITE);
odata = omap.data;
/* add data_identifier if needed */
if (add_id) {
*odata = 0x10;
memcpy (odata + 1, data, size - 1);
} else {
memcpy (odata, data, size);
}
/* add stuffing data_unit */
odata += size;
*odata++ = 0xFF;
*odata = stuff;
gst_buffer_unmap (buf, &map);
gst_buffer_unmap (out_buf, &omap);
return out_buf;
}

View file

@ -0,0 +1,91 @@
/*
* Copyright 2006, 2007, 2008 Fluendo S.A.
* Authors: Jan Schmidt <jan@fluendo.com>
* Kapil Agrawal <kapil@fluendo.com>
* Julien Moutte <julien@fluendo.com>
*
* This library is licensed under 4 different licenses and you
* can choose to use it under the terms of any one of them. The
* four licenses are the MPL 1.1, the LGPL, the GPL and the MIT
* license.
*
* MPL:
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/.
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* LGPL:
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
* GPL:
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* MIT:
*
* Unless otherwise indicated, Source Code is licensed under MIT license.
* See further explanation attached in License Statement (distributed in the file
* LICENSE).
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/
#ifndef __MPEGTSMUX_TTXT_H__
#define __MPEGTSMUX_TTXT_H__
#include "mpegtsmux.h"
GstBuffer * mpegtsmux_prepare_teletext (GstBuffer * buf, MpegTsPadData * data,
MpegTsMux * mux);
#endif /* __MPEGTSMUX_TTXT_H__ */

View file

@ -175,6 +175,18 @@ tsmux_stream_new (guint16 pid, TsMuxStreamType stream_type)
TSMUX_PACKET_FLAG_PES_FULL_HEADER |
TSMUX_PACKET_FLAG_PES_EXT_STREAMID;
break;
case TSMUX_ST_PS_TELETEXT:
/* needs fixes PES header length */
stream->pi.pes_header_length = 36;
case TSMUX_ST_PS_DVB_SUBPICTURE:
/* private stream 1 */
stream->id = 0xBD;
stream->stream_type = TSMUX_ST_PRIVATE_DATA;
stream->pi.flags |=
TSMUX_PACKET_FLAG_PES_FULL_HEADER |
TSMUX_PACKET_FLAG_PES_DATA_ALIGNMENT;
break;
default:
g_critical ("Stream type 0x%0x not yet implemented", stream_type);
break;
@ -865,6 +877,20 @@ tsmux_stream_get_es_descrs (TsMuxStream * stream, guint8 * buf, guint16 * len)
case TSMUX_ST_PS_AUDIO_LPCM:
/* FIXME */
break;
case TSMUX_ST_PS_DVB_SUBPICTURE:
/* tag */
*pos++ = 0x59;
/* FIXME empty descriptor for now;
* should be provided by upstream in event or so ? */
*pos = 0;
break;
case TSMUX_ST_PS_TELETEXT:
/* tag */
*pos++ = 0x56;
/* FIXME empty descriptor for now;
* should be provided by upstream in event or so ? */
*pos = 0;
break;
default:
break;
}

View file

@ -138,6 +138,8 @@ enum TsMuxStreamType {
TSMUX_ST_PS_AUDIO_AC3 = 0x81,
TSMUX_ST_PS_AUDIO_DTS = 0x8a,
TSMUX_ST_PS_AUDIO_LPCM = 0x8b,
TSMUX_ST_PS_DVB_SUBPICTURE = 0x8c,
TSMUX_ST_PS_TELETEXT = 0x8d,
TSMUX_ST_PS_DVD_SUBPICTURE = 0xff,
/* Non-standard definitions */