summaryrefslogtreecommitdiffstats
path: root/gst/mpeg2sub
diff options
context:
space:
mode:
Diffstat (limited to 'gst/mpeg2sub')
-rw-r--r--gst/mpeg2sub/.gitignore7
-rw-r--r--gst/mpeg2sub/Makefile.am18
-rw-r--r--gst/mpeg2sub/Notes.txt324
-rw-r--r--gst/mpeg2sub/gstmpeg2subt.c443
-rw-r--r--gst/mpeg2sub/gstmpeg2subt.h82
5 files changed, 874 insertions, 0 deletions
diff --git a/gst/mpeg2sub/.gitignore b/gst/mpeg2sub/.gitignore
new file mode 100644
index 00000000..08f5ed37
--- /dev/null
+++ b/gst/mpeg2sub/.gitignore
@@ -0,0 +1,7 @@
+Makefile
+Makefile.in
+*.o
+*.lo
+*.la
+.deps
+.libs
diff --git a/gst/mpeg2sub/Makefile.am b/gst/mpeg2sub/Makefile.am
new file mode 100644
index 00000000..d8bfe888
--- /dev/null
+++ b/gst/mpeg2sub/Makefile.am
@@ -0,0 +1,18 @@
+filterdir = $(libdir)/gst
+
+filter_LTLIBRARIES = libgstmpeg2subt.la
+
+libgstmpeg2subt_la_SOURCES = gstmpeg2subt.c
+
+if HAVE_CPU_I386
+ARCHCFLAGS = -m486
+else
+ARCHCFLAGS =
+endif
+
+libgstmpeg2subt_la_CFLAGS = -O3 $(ARCHCFLAGS) -fschedule-insns2 $(FOMIT_FRAME_POINTER) -finline-functions -ffast-math $(GST_CFLAGS)
+
+noinst_HEADERS = gstmpeg2subt.h
+
+EXTRA_DIST = Notes.txt
+
diff --git a/gst/mpeg2sub/Notes.txt b/gst/mpeg2sub/Notes.txt
new file mode 100644
index 00000000..a0e56e3c
--- /dev/null
+++ b/gst/mpeg2sub/Notes.txt
@@ -0,0 +1,324 @@
+
+ DVD subtitles
+ ---------------
+
+
+ 0. Introduction
+ 1. Basics
+ 2. The data structure
+ 3. Reading the control header
+ 4. Decoding the graphics
+ 5. What I do not know yet / What I need
+ 6. Thanks
+ 7. Changes
+
+
+
+
+
+The latest version of this document can be found here:
+http://www.via.ecp.fr/~sam/doc/dvd/
+
+
+
+
+
+0. Introduction
+
+ One of the last things we missed in DVD decoding under my system was the
+decoding of subtitles. I found no information on the web or Usenet about them,
+apart from a few words on them being run-length encoded in the DVD FAQ.
+
+ So we decided to reverse-engineer their format (it's completely legal in
+France, since we did it on interoperability purposes), and managed to get
+almost all of it.
+
+
+
+
+
+1. Basics
+
+ DVD subtitles are hidden in private PS packets (0x000001ba), just like AC3
+streams are.
+
+ Within the PS packet, there are PES packets, and like AC3, the header for the
+ones containing subtitles have a 0x000001bd header.
+ As for AC3, where there's an ID like (0x80 + x), there's a subtitle ID equal
+to (0x20 + x), where x is the subtitle ID. Thus there seems to be only
+16 possible different subtitles on a DVD (my Taxi Driver copy has 16).
+
+ I'll suppose you know how to extract AC3 from a DVD, and jump to the
+interesting part of this documentation. Anyway you're unlikely to have
+understood what I said without already being familiar with MPEG2.
+
+
+
+
+
+2. The data structure
+
+A subtitle packet, after its parts have been collected and appended, looks
+like this :
+
+ +----------------------------------------------------------+
+ | |
+ | 0 2 size |
+ | +----+------------------------+-----------------+ |
+ | |size| data packet | control | |
+ | +----+------------------------+-----------------+ |
+ | |
+ | a subtitle packet |
+ | |
+ +----------------------------------------------------------+
+
+size is a 2 bytes word, and data packet and control may have any size.
+
+
+Here is the structure of the data packet :
+
+ +----------------------------------------------------------+
+ | |
+ | 2 4 S0+2 |
+ | +----+------------------------------------------+ |
+ | | S0 | data | |
+ | +----+------------------------------------------+ |
+ | |
+ | the data packet |
+ | |
+ +----------------------------------------------------------+
+
+S0, the data packet size, is a 2 bytes word.
+
+
+Finally, here's the structure of the control packet :
+
+ +----------------------------------------------------------+
+ | |
+ | S0+2 S0+4 S1 size |
+ | +----+---------+---------+--+---------+--+---------+ |
+ | | S1 |ctrl seq |ctrl seq |..|ctrl seq |ff| end seq | |
+ | +----+---------+---------+--+---------+--+---------+ |
+ | |
+ | the control packet |
+ | |
+ +----------------------------------------------------------+
+
+To summarize :
+
+ - S1, at offset S0+2, the position of the end sequence
+ - several control sequences
+ - the 'ff' byte
+ - the end sequence
+
+
+
+
+
+3. Reading the control header
+
+The first thing to read is the control sequences. There are several
+types of them, and each type is determined by its first byte. As far
+as I know, each type has a fixed length.
+
+ * type 0x01 : '01' - 1 byte
+ it seems to be an empty control sequence.
+
+ * type 0x03 : '03wxyz' - 3 bytes
+ this one has the palette information ; it basically says 'encoded color 0
+ is the wth color of the palette, encoded color 1 is the xth color, aso.
+
+ * type 0x04 : '04wxyz' - 3 bytes
+ I *think* this is the alpha channel information ; I only saw values of 0 or f
+ for those nibbles, so I can't really be sure, but it seems plausable.
+
+ * type 0x05 : '05xxxXXXyyyYYY' - 7 bytes
+ the coordinates of the subtitle on the screen :
+ xxx is the first column of the subtitle
+ XXX is the last column of the subtitle
+ yyy is the first line of the subtitle
+ YYY is the last line of the subtitle
+ thus the subtitle's size is (XXX-xxx+1) x (YYY-yyy+1)
+
+ * type 0x06 : '06xxxxyyyy' - 5 bytes
+ xxxx is the position of the first graphic line, and yyyy is the position of
+ the second one (the graphics are interlaced, so it helps a lot :p)
+
+The end sequence has this structure:
+
+ xxxx yyyy 02 ff (ff)
+
+ it ends with 'ff' or 'ffff', to make the whole packet have an even length.
+
+FIXME: I absolutely don't know what xxxx is. I suppose it may be some date
+information since I found it nowhere else, but I can't be sure.
+
+ yyyy is equal to S1 (see picture).
+
+
+Example of a control header :
+----
+0A 0C 01 03 02 31 04 0F F0 05 00 02 CF 00 22 3E 06 00 06 04 E9 FF 00 93 0A 0C 02 FF
+----
+Let's decode it. First of all, S1 = 0x0a0c.
+
+The control sequences are :
+ 01
+ Nothing to say about this one
+ 03 02 31
+ Color 0 is 0, color 1 is 2, color 2 is 3, and color 3 is 1.
+ 04 0F F0
+ Colors 0 and 3 are transparent, and colors 2 and 3 are opaque (not sure of this one)
+ 05 00 02 CF 00 22 3E
+ The first column is 0x000, the last one is 0x2cf, the first line is 0x002, and
+ the last line is 0x23e. Thus the subtitle's size is 0x2d0 x 0x23d.
+ 06 00 06 04 E9
+ The first encoded image starts at offset 0x006, and the second one starts at 0x04e9.
+
+And the end sequence is :
+ 00 93 0A 0C 02 FF
+ Which means... well, not many things now. We can at least verify that S1 (0x0a0c) is
+ there.
+
+
+
+
+
+4. Decoding the graphics
+
+ The graphics are rather easy to decode (at least, when you know how to do it - it
+ took us one whole week to figure out what the encoding was :p).
+
+ The picture is interlaced, for instance for a 40 lines picture :
+
+ line 0 ---------------#----------
+ line 2 ------#-------------------
+ ...
+ line 38 ------------#-------------
+ line 1 ------------------#-------
+ line 3 --------#-----------------
+ ...
+ line 39 -------------#------------
+
+ When decoding you should get:
+
+ line 0 ---------------#----------
+ line 1 ------------------#-------
+ line 2 ------#-------------------
+ line 3 --------#-----------------
+ ...
+ line 38 ------------#-------------
+ line 39 -------------#------------
+
+ Computers with weak processors could choose only to decode even lines
+ in order to gain some time, for instance.
+
+
+ The encoding is run-length encoded, with the following alphabet:
+
+ 0xf
+ 0xe
+ 0xd
+ 0xc
+ 0xb
+ 0xa
+ 0x9
+ 0x8
+ 0x7
+ 0x6
+ 0x5
+ 0x4
+ 0x3-
+ 0x2-
+ 0x1-
+ 0x0f-
+ 0x0e-
+ 0x0d-
+ 0x0c-
+ 0x0b-
+ 0x0a-
+ 0x09-
+ 0x08-
+ 0x07-
+ 0x06-
+ 0x05-
+ 0x04-
+ 0x03--
+ 0x02--
+ 0x01--
+ 0x0000
+
+ '-' stands for any other nibble. Once a sequence X of this alphabet has
+ been read, the pixels can be displayed : (X >> 2) is the number of pixels
+ to display, and (X & 0x3) is the color of the pixel.
+
+ For instance, 0x23 means "8 pixels of color 3".
+
+ "0000" has a special meaning : it's a carriage return. The decoder should
+ do a carriage return when reaching the end of the line, or when encountering
+ this "0000" sequence. When doing a carriage return, the parser should be
+ reset to the next even position (it cannot be nibble-aligned at the start
+ of a line).
+
+ After a carriage return, the parser should read a line on the other
+ interlaced picture, and swap like this after each carriage return.
+
+ Perhaps I don't explain this very well, so you'd better have a look at
+ the enclosed source.
+
+
+
+
+
+5. What I do not know yet / What I need
+
+I don't know what's in the end sequence yet.
+
+Also, I don't know exactly when to display subtitles, and when to remove them.
+
+I don't know if there are other types of control sequences (in my programs I consider
+0xff as a control sequence type, as well as 0x02. I don't know if it's correct or not,
+so please comment on this).
+
+I don't know what the "official" color palette is.
+
+I don't know how to handle transparency information.
+
+I don't know if this document is generic enough.
+
+So what I need is you :
+
+ - if you can, patch this document or my programs to fix strange behaviour with your subtitles.
+
+ - send me your subtitles (there's a program to extract them enclosed) ; the first 10 KB
+ of subtitles in a VOB should be enough, but it would be cool if you sent me one subtitle
+ file per language.
+
+
+
+
+
+6. Thanks
+
+ Thanks to Michel Lespinasse <walken@via.ecp.fr> for his great help on understanding
+the RLE stuff, and for all the ideas he had.
+
+ Thanks to mass (David Waite) and taaz (David I. Lehn) from irc at
+openprojects.net for sending me their subtitles.
+
+
+
+
+
+7. Changes
+
+ 20000116: added the 'changes' section.
+ 20000116: added David Waite's and David I. Lehn's name.
+ 20000116: changed "x0" and "x1" to "S0" and "S1" to make it less confusing.
+
+
+
+
+--
+Paris, January 16th 2000
+Samuel Hocevar <sam@via.ecp.fr>
diff --git a/gst/mpeg2sub/gstmpeg2subt.c b/gst/mpeg2sub/gstmpeg2subt.c
new file mode 100644
index 00000000..ee51d067
--- /dev/null
+++ b/gst/mpeg2sub/gstmpeg2subt.c
@@ -0,0 +1,443 @@
+/* Gnome-Streamer
+ * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
+ *
+ * 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.
+ */
+
+
+/*#define DEBUG_ENABLED */
+#include <mpeg2subt.h>
+
+static void gst_mpeg2subt_class_init (GstMpeg2SubtClass *klass);
+static void gst_mpeg2subt_init (GstMpeg2Subt *mpeg2subt);
+
+static void gst_mpeg2subt_chain_video (GstPad *pad,GstBuffer *buf);
+static void gst_mpeg2subt_chain_subtitle (GstPad *pad,GstBuffer *buf);
+
+static void gst_mpeg2subt_merge_title (GstMpeg2Subt *mpeg2subt, GstBuffer *buf);
+
+static void gst_mpeg2subt_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
+static void gst_mpeg2subt_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
+
+/* elementfactory information */
+static GstElementDetails mpeg2subt_details = {
+ "MPEG2 subtitle Decoder",
+ "Filter/Decoder/Video",
+ "Decodes and merges MPEG2 subtitles into a video frame",
+ VERSION,
+ "Samuel Hocevar <sam@via.ecp.fr>\n"
+ "Michel Lespinasse <walken@via.ecp.fr>\n"
+ "Wim Taymans <wim.taymans@chello.be>",
+ "(C) 2000",
+};
+
+static GstTypeDefinition mpeg2subtitledefinition = {
+ "mpeg2subt_video/mpeg2ubtitle",
+ "video/mpeg2subtitle",
+ NULL,
+ NULL,
+};
+
+/* GstMpeg2Subt signals and args */
+enum {
+ /* FILL ME */
+ LAST_SIGNAL
+};
+
+enum {
+ ARG_0,
+ ARG_SKIP,
+ /* FILL ME */
+};
+
+static guchar yuv_color[16] = {
+ 0x99,
+ 0x00,
+ 0xFF,
+ 0x00,
+ 0x40,
+ 0x50,
+ 0x60,
+ 0x70,
+ 0x80,
+ 0x90,
+ 0xA0,
+ 0xB0,
+ 0xC0,
+ 0xD0,
+ 0xE0,
+ 0xF0
+};
+
+
+
+
+static GstElementClass *parent_class = NULL;
+/*static guint gst_mpeg2subt_signals[LAST_SIGNAL] = { 0 };*/
+
+GType
+gst_mpeg2subt_get_type (void)
+{
+ static GType mpeg2subt_type = 0;
+
+ if (!mpeg2subt_type) {
+ static const GTypeInfo mpeg2subt_info = {
+ sizeof(GstMpeg2SubtClass), NULL,
+ NULL,
+ (GClassInitFunc)gst_mpeg2subt_class_init,
+ NULL,
+ NULL,
+ sizeof(GstMpeg2Subt),
+ 0,
+ (GInstanceInitFunc)gst_mpeg2subt_init,
+ };
+ mpeg2subt_type = g_type_register_static(GST_TYPE_ELEMENT, "GstMpeg2Subt", &mpeg2subt_info, 0);
+ }
+ return mpeg2subt_type;
+}
+
+static void
+gst_mpeg2subt_class_init (GstMpeg2SubtClass *klass)
+{
+ GObjectClass *gobject_class;
+ GstElementClass *gstelement_class;
+
+ gobject_class = (GObjectClass*)klass;
+ gstelement_class = (GstElementClass*)klass;
+
+ g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_SKIP,
+ g_param_spec_int("skip","skip","skip",
+ G_MININT,G_MAXINT,0,G_PARAM_READWRITE)); /* CHECKME */
+
+ parent_class = g_type_class_ref(GST_TYPE_ELEMENT);
+
+ gobject_class->set_property = gst_mpeg2subt_set_property;
+ gobject_class->get_property = gst_mpeg2subt_get_property;
+
+}
+
+static void
+gst_mpeg2subt_init (GstMpeg2Subt *mpeg2subt)
+{
+ mpeg2subt->videopad = gst_pad_new("video",GST_PAD_SINK);
+ gst_element_add_pad(GST_ELEMENT(mpeg2subt),mpeg2subt->videopad);
+ gst_pad_set_chain_function(mpeg2subt->videopad,gst_mpeg2subt_chain_video);
+
+ mpeg2subt->subtitlepad = gst_pad_new("subtitle",GST_PAD_SINK);
+ gst_element_add_pad(GST_ELEMENT(mpeg2subt),mpeg2subt->subtitlepad);
+ gst_pad_set_chain_function(mpeg2subt->subtitlepad,gst_mpeg2subt_chain_subtitle);
+
+ mpeg2subt->srcpad = gst_pad_new("src",GST_PAD_SRC);
+ gst_element_add_pad(GST_ELEMENT(mpeg2subt),mpeg2subt->srcpad);
+
+ mpeg2subt->partialbuf = NULL;
+ mpeg2subt->have_title = FALSE;
+}
+
+static void
+gst_mpeg2subt_chain_video (GstPad *pad, GstBuffer *buf)
+{
+ GstMpeg2Subt *mpeg2subt;
+ guchar *data;
+ glong size;
+
+ g_return_if_fail(pad != NULL);
+ g_return_if_fail(GST_IS_PAD(pad));
+ g_return_if_fail(buf != NULL);
+
+ mpeg2subt = GST_MPEG2SUBT (GST_OBJECT_PARENT (pad));
+
+ data = GST_BUFFER_DATA(buf);
+ size = GST_BUFFER_SIZE(buf);
+
+ if (mpeg2subt->have_title && mpeg2subt->duration != 0) {
+ gst_mpeg2subt_merge_title(mpeg2subt, buf);
+ mpeg2subt->duration--;
+ }
+
+ gst_pad_push(mpeg2subt->srcpad, buf);
+}
+
+
+static void
+gst_mpeg2subt_parse_header (GstMpeg2Subt *mpeg2subt)
+{
+ guchar *buffer = GST_BUFFER_DATA(mpeg2subt->partialbuf);
+ guchar dummy;
+ guint i;
+
+ i = mpeg2subt->data_size + 4;
+ while (i < mpeg2subt->packet_size)
+ {
+ dummy = buffer [i];
+ switch (dummy)
+ {
+ case 0x01: /* null packet ? */
+ i++;
+ break;
+ case 0x02: /* 02 ff (ff) is the end of the packet */
+ i = mpeg2subt->packet_size;
+ break;
+ case 0x03: /* palette */
+ mpeg2subt->color[0] = yuv_color[buffer [i+1] >> 4];
+ mpeg2subt->color[1] = yuv_color[buffer [i+1] & 0xf];
+ mpeg2subt->color[2] = yuv_color[buffer [i+2] >> 4];
+ mpeg2subt->color[3] = yuv_color[buffer [i+2] & 0xf];
+ mpeg2subt->color[4] = yuv_color[0xf];
+ GST_DEBUG (0,"mpeg2subt: colors %d %d %d %d\n", mpeg2subt->color[0],mpeg2subt->color[1],mpeg2subt->color[2],mpeg2subt->color[3]);
+ i += 3;
+ break;
+ case 0x04: /* transparency palette */
+ mpeg2subt->trans[3] = buffer [i+1] >> 4;
+ mpeg2subt->trans[2] = buffer [i+1] & 0xf;
+ mpeg2subt->trans[1] = buffer [i+2] >> 4;
+ mpeg2subt->trans[0] = buffer [i+2] & 0xf;
+ GST_DEBUG (0,"mpeg2subt: transparency %d %d %d %d\n", mpeg2subt->trans[0],mpeg2subt->trans[1],mpeg2subt->trans[2],mpeg2subt->trans[3]);
+ i += 3;
+ break;
+ case 0x05: /* image coordinates */
+ mpeg2subt->width = 1 + ( ((buffer[i+2] & 0x0f) << 8) + buffer[i+3] )
+ - ( (((unsigned int)buffer[i+1]) << 4) + (buffer[i+2] >> 4) );
+ mpeg2subt->height = 1 + ( ((buffer[i+5] & 0x0f) << 8) + buffer[i+6] )
+ - ( (((unsigned int)buffer[i+4]) << 4) + (buffer[i+5] >> 4) );
+ i += 7;
+ break;
+ case 0x06: /* image 1 / image 2 offsets */
+ mpeg2subt->offset[0] = (((unsigned int)buffer[i+1]) << 8) + buffer[i+2];
+ mpeg2subt->offset[1] = (((unsigned int)buffer[i+3]) << 8) + buffer[i+4];
+ i += 5;
+ break;
+ case 0xff: /* "ff xx yy zz uu" with 'zz uu' == start of control packet
+ * xx and yy are the end time in 90th/sec
+ */
+ mpeg2subt->duration = (((buffer[i+1] << 8) + buffer[i+2]) * 25)/90;
+
+ GST_DEBUG (0,"duration %d\n", mpeg2subt->duration);
+
+ if ( (buffer[i+3] != buffer[mpeg2subt->data_size+2])
+ || (buffer[i+4] != buffer[mpeg2subt->data_size+3]) )
+ {
+ g_print("mpeg2subt: invalid control header (%.2x%.2x != %.2x%.2x) !\n",
+ buffer[i+3], buffer[i+4], buffer[mpeg2subt->data_size+2], buffer[mpeg2subt->data_size+3] );
+/* FIXME */
+/* exit(1); */
+ }
+ i += 5;
+ break;
+ default:
+ g_print("mpeg2subt: invalid sequence in control header (%.2x) !\n", dummy);
+ break;
+ }
+ }
+}
+
+static int
+get_nibble (guchar *buffer, gint *offset, gint id, gint *aligned)
+{
+ static int next;
+
+ if (*aligned)
+ {
+ next = buffer[offset[id]];
+ offset[id]++;
+
+ *aligned = 0;
+ return next >> 4;
+ }
+ else
+ {
+ *aligned = 1;
+ return next & 0xf;
+ }
+}
+
+static void
+gst_mpeg2subt_merge_title (GstMpeg2Subt *mpeg2subt, GstBuffer *buf)
+{
+ gint x=0, y=0;
+ gint width = mpeg2subt->width;
+ gint height = mpeg2subt->height;
+ guchar *buffer = GST_BUFFER_DATA(mpeg2subt->partialbuf);
+ guchar *target = GST_BUFFER_DATA(buf);
+ gint id=0, aligned=1;
+ gint offset[2];
+
+ offset[0] = mpeg2subt->offset[0];
+ offset[1] = mpeg2subt->offset[1];
+#define get_nibble() get_nibble (buffer, offset, id, &aligned)
+
+ GST_DEBUG (0,"mpeg2subt: merging subtitle\n");
+
+ while ((offset[1] < mpeg2subt->data_size + 2) && (y < height))
+ {
+ gint code;
+ gint length, colorid;
+
+ code = get_nibble();
+ if (code >= 0x4) /* 4 .. f */
+ {
+found_code:
+ length = code >> 2;
+ colorid = code & 3;
+ while (length--)
+ if (x++ < width) {
+ if (mpeg2subt->trans[colorid] != 0x0) {
+ *target++ = mpeg2subt->color[colorid];
+ }
+ else target++;
+ }
+
+ if (x >= width)
+ {
+ if (!aligned)
+ get_nibble ();
+ goto next_line;
+ }
+ continue;
+ }
+
+ code = (code << 4) + get_nibble();
+ if (code >= 0x10) /* 1x .. 3x */
+ goto found_code;
+
+ code = (code << 4) + get_nibble();
+ if (code >= 0x40) /* 04x .. 0fx */
+ goto found_code;
+
+ code = (code << 4) + get_nibble();
+ if (code >= 0x100) /* 01xx .. 03xx */
+ goto found_code;
+
+ /* 00xx - should only happen for 00 00 */
+ if (!aligned)
+ code = (code << 4) + get_nibble(); /* 0 0x xx */
+
+ if (code)
+ {
+ g_print("mpeg2subt: got unknown code 00%x (offset %x side %x, x=%d, y=%d)\n", code, mpeg2subt->offset[id], id, x, y);
+ goto next_line;
+ }
+next_line:
+ /* aligned 00 00 */
+ if (y < height) {
+ target+=(width-x);
+ x = 0;
+ y++;
+ id = 1 - id;
+ }
+ }
+}
+
+static void
+gst_mpeg2subt_chain_subtitle (GstPad *pad, GstBuffer *buf)
+{
+ GstMpeg2Subt *mpeg2subt;
+ guchar *data;
+ glong size = 0;
+
+ g_return_if_fail(pad != NULL);
+ g_return_if_fail(GST_IS_PAD(pad));
+ g_return_if_fail(buf != NULL);
+/* g_return_if_fail(GST_IS_BUFFER(buf)); */
+
+ mpeg2subt = GST_MPEG2SUBT (GST_OBJECT_PARENT (pad));
+
+ if (mpeg2subt->have_title) {
+ gst_buffer_unref(mpeg2subt->partialbuf);
+ mpeg2subt->partialbuf = NULL;
+ mpeg2subt->have_title = FALSE;
+ }
+
+ GST_DEBUG (0,"presentation time %llu\n", GST_BUFFER_TIMESTAMP(buf));
+
+ /* deal with partial frame from previous buffer */
+ if (mpeg2subt->partialbuf) {
+
+ mpeg2subt->partialbuf = gst_buffer_append(mpeg2subt->partialbuf, buf);;
+ /* and the one we received.. */
+ gst_buffer_unref(buf);
+ }
+ else {
+ mpeg2subt->partialbuf = buf;
+ }
+
+ data = GST_BUFFER_DATA(mpeg2subt->partialbuf);
+ size = GST_BUFFER_SIZE(mpeg2subt->partialbuf);
+
+ mpeg2subt->packet_size = GUINT16_FROM_BE(*(guint16 *)data);
+
+ if (mpeg2subt->packet_size == size) {
+
+ GST_DEBUG (0,"mpeg2subt: subtitle packet size %d, current size %ld\n", mpeg2subt->packet_size, size);
+
+ mpeg2subt->data_size = GUINT16_FROM_BE(*(guint16 *)(data+2));
+
+ gst_mpeg2subt_parse_header(mpeg2subt);
+ mpeg2subt->have_title = TRUE;
+ }
+}
+
+static void
+gst_mpeg2subt_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
+{
+ GstMpeg2Subt *src;
+
+ /* it's not null if we got it, but it might not be ours */
+ g_return_if_fail(GST_IS_MPEG2SUBT(object));
+ src = GST_MPEG2SUBT(object);
+
+ switch (prop_id) {
+ default:
+ break;
+ }
+}
+
+static void
+gst_mpeg2subt_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
+{
+ GstMpeg2Subt *src;
+
+ /* it's not null if we got it, but it might not be ours */
+ g_return_if_fail(GST_IS_MPEG2SUBT(object));
+ src = GST_MPEG2SUBT(object);
+
+ switch (prop_id) {
+ default:
+ break;
+ }
+}
+
+static gboolean
+plugin_init (GModule *module, GstPlugin *plugin)
+{
+ GstElementFactory *factory;
+
+ /* create an elementfactory for the mpeg2subt element */
+ factory = gst_elementfactory_new("mpeg2subt",GST_TYPE_MPEG2SUBT,
+ &mpeg2subt_details);
+ g_return_val_if_fail(factory != NULL, FALSE);
+
+ gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (factory));
+
+ return TRUE;
+}
+
+GstPluginDesc plugin_desc = {
+ GST_VERSION_MAJOR,
+ GST_VERSION_MINOR,
+ "mpeg2subt",
+ plugin_init
+};
diff --git a/gst/mpeg2sub/gstmpeg2subt.h b/gst/mpeg2sub/gstmpeg2subt.h
new file mode 100644
index 00000000..71e88909
--- /dev/null
+++ b/gst/mpeg2sub/gstmpeg2subt.h
@@ -0,0 +1,82 @@
+/* Gnome-Streamer
+ * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
+ *
+ * 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.
+ */
+
+
+#ifndef __GST_MPEG2SUBT_H__
+#define __GST_MPEG2SUBT_H__
+
+
+#include <config.h>
+#include <gst/gst.h>
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+
+#define GST_TYPE_MPEG2SUBT \
+ (gst_mpeg2subt_get_type())
+#define GST_MPEG2SUBT(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_MPEG2SUBT,GstMpeg2Subt))
+#define GST_MPEG2SUBT_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_MPEG2SUBT,GstMpeg2Subt))
+#define GST_IS_MPEG2SUBT(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_MPEG2SUBT))
+#define GST_IS_MPEG2SUBT_CLASS(obj) \
+ (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_MPEG2SUBT))
+
+typedef struct _GstMpeg2Subt GstMpeg2Subt;
+typedef struct _GstMpeg2SubtClass GstMpeg2SubtClass;
+
+struct _GstMpeg2Subt {
+ GstElement element;
+
+ GstPad *videopad,*subtitlepad,*srcpad;
+
+ GstBuffer *partialbuf; /* previous buffer (if carryover) */
+
+ gboolean have_title;
+
+ guint16 packet_size;
+ guint16 data_size;
+
+ gint offset[2];
+ guchar color[5];
+ guchar trans[4];
+
+ guint duration;
+
+ gint width, height;
+
+};
+
+struct _GstMpeg2SubtClass {
+ GstElementClass parent_class;
+};
+
+GType gst_mpeg2subt_get_type(void);
+
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+
+#endif /* __GST_MPEG2SUBT_H__ */