2002-03-20 21:45:04 +00:00
|
|
|
/* GStreamer
|
2001-12-22 23:26:33 +00:00
|
|
|
* 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 */
|
2003-06-29 19:46:13 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
2001-12-23 04:38:37 +00:00
|
|
|
#include <gstmpeg2subt.h>
|
2001-12-22 23:26:33 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static void gst_mpeg2subt_class_init (GstMpeg2SubtClass * klass);
|
|
|
|
static void gst_mpeg2subt_base_init (GstMpeg2SubtClass * klass);
|
|
|
|
static void gst_mpeg2subt_init (GstMpeg2Subt * mpeg2subt);
|
2001-12-22 23:26:33 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static void gst_mpeg2subt_chain_video (GstPad * pad, GstData * _data);
|
|
|
|
static void gst_mpeg2subt_chain_subtitle (GstPad * pad, GstData * _data);
|
2001-12-22 23:26:33 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static void gst_mpeg2subt_merge_title (GstMpeg2Subt * mpeg2subt,
|
|
|
|
GstBuffer * buf);
|
2001-12-22 23:26:33 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
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);
|
2001-12-22 23:26:33 +00:00
|
|
|
|
|
|
|
/* elementfactory information */
|
|
|
|
static GstElementDetails mpeg2subt_details = {
|
|
|
|
"MPEG2 subtitle Decoder",
|
2003-11-16 22:02:23 +00:00
|
|
|
"Codec/Decoder/Video",
|
2001-12-22 23:26:33 +00:00
|
|
|
"Decodes and merges MPEG2 subtitles into a video frame",
|
2003-11-02 21:02:37 +00:00
|
|
|
"Wim Taymans <wim.taymans@chello.be>"
|
2001-12-22 23:26:33 +00:00
|
|
|
};
|
2003-10-29 05:09:40 +00:00
|
|
|
|
2001-12-22 23:26:33 +00:00
|
|
|
/* GstMpeg2Subt signals and args */
|
2004-03-14 22:34:33 +00:00
|
|
|
enum
|
|
|
|
{
|
2001-12-22 23:26:33 +00:00
|
|
|
/* FILL ME */
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
enum
|
|
|
|
{
|
2001-12-22 23:26:33 +00:00
|
|
|
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;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2001-12-22 23:26:33 +00:00
|
|
|
/*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 = {
|
2004-03-14 22:34:33 +00:00
|
|
|
sizeof (GstMpeg2SubtClass),
|
|
|
|
(GBaseInitFunc) gst_mpeg2subt_base_init,
|
2001-12-22 23:26:33 +00:00
|
|
|
NULL,
|
2004-03-14 22:34:33 +00:00
|
|
|
(GClassInitFunc) gst_mpeg2subt_class_init,
|
2001-12-22 23:26:33 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2004-03-14 22:34:33 +00:00
|
|
|
sizeof (GstMpeg2Subt),
|
2001-12-22 23:26:33 +00:00
|
|
|
0,
|
2004-03-14 22:34:33 +00:00
|
|
|
(GInstanceInitFunc) gst_mpeg2subt_init,
|
2001-12-22 23:26:33 +00:00
|
|
|
};
|
2004-03-14 22:34:33 +00:00
|
|
|
mpeg2subt_type =
|
|
|
|
g_type_register_static (GST_TYPE_ELEMENT, "GstMpeg2Subt",
|
|
|
|
&mpeg2subt_info, 0);
|
2001-12-22 23:26:33 +00:00
|
|
|
}
|
|
|
|
return mpeg2subt_type;
|
|
|
|
}
|
|
|
|
|
2003-11-02 21:02:37 +00:00
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_mpeg2subt_base_init (GstMpeg2SubtClass * klass)
|
2003-11-02 21:02:37 +00:00
|
|
|
{
|
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
|
|
|
|
|
|
|
|
gst_element_class_set_details (element_class, &mpeg2subt_details);
|
|
|
|
}
|
|
|
|
|
2001-12-22 23:26:33 +00:00
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_mpeg2subt_class_init (GstMpeg2SubtClass * klass)
|
2001-12-22 23:26:33 +00:00
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GstElementClass *gstelement_class;
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
gobject_class = (GObjectClass *) klass;
|
|
|
|
gstelement_class = (GstElementClass *) klass;
|
2001-12-22 23:26:33 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
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 */
|
2001-12-22 23:26:33 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
|
2001-12-22 23:26:33 +00:00
|
|
|
|
|
|
|
gobject_class->set_property = gst_mpeg2subt_set_property;
|
|
|
|
gobject_class->get_property = gst_mpeg2subt_get_property;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_mpeg2subt_init (GstMpeg2Subt * mpeg2subt)
|
2001-12-22 23:26:33 +00:00
|
|
|
{
|
2004-03-14 22:34:33 +00:00
|
|
|
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);
|
2001-12-22 23:26:33 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
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);
|
2001-12-22 23:26:33 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
mpeg2subt->srcpad = gst_pad_new ("src", GST_PAD_SRC);
|
|
|
|
gst_element_add_pad (GST_ELEMENT (mpeg2subt), mpeg2subt->srcpad);
|
2001-12-22 23:26:33 +00:00
|
|
|
|
|
|
|
mpeg2subt->partialbuf = NULL;
|
|
|
|
mpeg2subt->have_title = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_mpeg2subt_chain_video (GstPad * pad, GstData * _data)
|
2001-12-22 23:26:33 +00:00
|
|
|
{
|
2003-10-08 16:08:19 +00:00
|
|
|
GstBuffer *buf = GST_BUFFER (_data);
|
2001-12-22 23:26:33 +00:00
|
|
|
GstMpeg2Subt *mpeg2subt;
|
|
|
|
guchar *data;
|
|
|
|
glong size;
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
g_return_if_fail (pad != NULL);
|
|
|
|
g_return_if_fail (GST_IS_PAD (pad));
|
|
|
|
g_return_if_fail (buf != NULL);
|
2001-12-22 23:26:33 +00:00
|
|
|
|
|
|
|
mpeg2subt = GST_MPEG2SUBT (GST_OBJECT_PARENT (pad));
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
data = GST_BUFFER_DATA (buf);
|
|
|
|
size = GST_BUFFER_SIZE (buf);
|
2001-12-22 23:26:33 +00:00
|
|
|
|
|
|
|
if (mpeg2subt->have_title && mpeg2subt->duration != 0) {
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_mpeg2subt_merge_title (mpeg2subt, buf);
|
2001-12-22 23:26:33 +00:00
|
|
|
mpeg2subt->duration--;
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_pad_push (mpeg2subt->srcpad, GST_DATA (buf));
|
2001-12-22 23:26:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_mpeg2subt_parse_header (GstMpeg2Subt * mpeg2subt)
|
2001-12-22 23:26:33 +00:00
|
|
|
{
|
2004-03-14 22:34:33 +00:00
|
|
|
guchar *buffer = GST_BUFFER_DATA (mpeg2subt->partialbuf);
|
2001-12-22 23:26:33 +00:00
|
|
|
guchar dummy;
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
i = mpeg2subt->data_size + 4;
|
2004-03-14 22:34:33 +00:00
|
|
|
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 ("mpeg2subt: colors %d %d %d %d", mpeg2subt->color[0],
|
|
|
|
mpeg2subt->color[1], mpeg2subt->color[2], mpeg2subt->color[3]);
|
2001-12-22 23:26:33 +00:00
|
|
|
i += 3;
|
|
|
|
break;
|
2004-03-14 22:34:33 +00:00
|
|
|
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 ("mpeg2subt: transparency %d %d %d %d", mpeg2subt->trans[0],
|
|
|
|
mpeg2subt->trans[1], mpeg2subt->trans[2], mpeg2subt->trans[3]);
|
|
|
|
i += 3;
|
2001-12-22 23:26:33 +00:00
|
|
|
break;
|
2004-03-14 22:34:33 +00:00
|
|
|
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];
|
2001-12-22 23:26:33 +00:00
|
|
|
i += 5;
|
|
|
|
break;
|
2004-03-14 22:34:33 +00:00
|
|
|
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;
|
2001-12-22 23:26:33 +00:00
|
|
|
|
2003-06-29 19:46:13 +00:00
|
|
|
GST_DEBUG ("duration %d", mpeg2subt->duration);
|
2001-12-22 23:26:33 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
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]);
|
2001-12-22 23:26:33 +00:00
|
|
|
/* FIXME */
|
|
|
|
/* exit(1); */
|
|
|
|
}
|
|
|
|
i += 5;
|
|
|
|
break;
|
|
|
|
default:
|
2004-03-14 22:34:33 +00:00
|
|
|
g_print ("mpeg2subt: invalid sequence in control header (%.2x) !\n",
|
|
|
|
dummy);
|
2001-12-22 23:26:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2004-03-14 22:34:33 +00:00
|
|
|
get_nibble (guchar * buffer, gint * offset, gint id, gint * aligned)
|
2001-12-22 23:26:33 +00:00
|
|
|
{
|
|
|
|
static int next;
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
if (*aligned) {
|
2001-12-22 23:26:33 +00:00
|
|
|
next = buffer[offset[id]];
|
|
|
|
offset[id]++;
|
|
|
|
|
|
|
|
*aligned = 0;
|
|
|
|
return next >> 4;
|
2004-03-14 22:34:33 +00:00
|
|
|
} else {
|
2001-12-22 23:26:33 +00:00
|
|
|
*aligned = 1;
|
|
|
|
return next & 0xf;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_mpeg2subt_merge_title (GstMpeg2Subt * mpeg2subt, GstBuffer * buf)
|
2001-12-22 23:26:33 +00:00
|
|
|
{
|
2004-03-14 22:34:33 +00:00
|
|
|
gint x = 0, y = 0;
|
2001-12-22 23:26:33 +00:00
|
|
|
gint width = mpeg2subt->width;
|
|
|
|
gint height = mpeg2subt->height;
|
2004-03-14 22:34:33 +00:00
|
|
|
guchar *buffer = GST_BUFFER_DATA (mpeg2subt->partialbuf);
|
|
|
|
guchar *target = GST_BUFFER_DATA (buf);
|
|
|
|
gint id = 0, aligned = 1;
|
2001-12-22 23:26:33 +00:00
|
|
|
gint offset[2];
|
|
|
|
|
|
|
|
offset[0] = mpeg2subt->offset[0];
|
|
|
|
offset[1] = mpeg2subt->offset[1];
|
|
|
|
#define get_nibble() get_nibble (buffer, offset, id, &aligned)
|
|
|
|
|
2003-06-29 19:46:13 +00:00
|
|
|
GST_DEBUG ("mpeg2subt: merging subtitle");
|
2001-12-22 23:26:33 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
while ((offset[1] < mpeg2subt->data_size + 2) && (y < height)) {
|
2001-12-22 23:26:33 +00:00
|
|
|
gint code;
|
|
|
|
gint length, colorid;
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
code = get_nibble ();
|
|
|
|
if (code >= 0x4) { /* 4 .. f */
|
|
|
|
found_code:
|
2001-12-22 23:26:33 +00:00
|
|
|
length = code >> 2;
|
|
|
|
colorid = code & 3;
|
|
|
|
while (length--)
|
2004-03-14 22:34:33 +00:00
|
|
|
if (x++ < width) {
|
2001-12-22 23:26:33 +00:00
|
|
|
if (mpeg2subt->trans[colorid] != 0x0) {
|
2004-03-14 22:34:33 +00:00
|
|
|
*target++ = mpeg2subt->color[colorid];
|
|
|
|
} else
|
|
|
|
target++;
|
2001-12-22 23:26:33 +00:00
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
if (x >= width) {
|
|
|
|
if (!aligned)
|
|
|
|
get_nibble ();
|
|
|
|
goto next_line;
|
2001-12-22 23:26:33 +00:00
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
code = (code << 4) + get_nibble ();
|
|
|
|
if (code >= 0x10) /* 1x .. 3x */
|
2001-12-22 23:26:33 +00:00
|
|
|
goto found_code;
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
code = (code << 4) + get_nibble ();
|
|
|
|
if (code >= 0x40) /* 04x .. 0fx */
|
2001-12-22 23:26:33 +00:00
|
|
|
goto found_code;
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
code = (code << 4) + get_nibble ();
|
|
|
|
if (code >= 0x100) /* 01xx .. 03xx */
|
2001-12-22 23:26:33 +00:00
|
|
|
goto found_code;
|
|
|
|
|
|
|
|
/* 00xx - should only happen for 00 00 */
|
|
|
|
if (!aligned)
|
2004-03-14 22:34:33 +00:00
|
|
|
code = (code << 4) + get_nibble (); /* 0 0x xx */
|
2001-12-22 23:26:33 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
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);
|
2001-12-22 23:26:33 +00:00
|
|
|
goto next_line;
|
|
|
|
}
|
2004-03-14 22:34:33 +00:00
|
|
|
next_line:
|
2001-12-22 23:26:33 +00:00
|
|
|
/* aligned 00 00 */
|
|
|
|
if (y < height) {
|
2004-03-14 22:34:33 +00:00
|
|
|
target += (width - x);
|
2001-12-22 23:26:33 +00:00
|
|
|
x = 0;
|
|
|
|
y++;
|
|
|
|
id = 1 - id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_mpeg2subt_chain_subtitle (GstPad * pad, GstData * _data)
|
2001-12-22 23:26:33 +00:00
|
|
|
{
|
2003-10-08 16:08:19 +00:00
|
|
|
GstBuffer *buf = GST_BUFFER (_data);
|
2001-12-22 23:26:33 +00:00
|
|
|
GstMpeg2Subt *mpeg2subt;
|
|
|
|
guchar *data;
|
|
|
|
glong size = 0;
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
g_return_if_fail (pad != NULL);
|
|
|
|
g_return_if_fail (GST_IS_PAD (pad));
|
|
|
|
g_return_if_fail (buf != NULL);
|
2001-12-22 23:26:33 +00:00
|
|
|
/* g_return_if_fail(GST_IS_BUFFER(buf)); */
|
|
|
|
|
|
|
|
mpeg2subt = GST_MPEG2SUBT (GST_OBJECT_PARENT (pad));
|
|
|
|
|
|
|
|
if (mpeg2subt->have_title) {
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_buffer_unref (mpeg2subt->partialbuf);
|
2001-12-22 23:26:33 +00:00
|
|
|
mpeg2subt->partialbuf = NULL;
|
|
|
|
mpeg2subt->have_title = FALSE;
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_DEBUG ("presentation time %" G_GUINT64_FORMAT,
|
|
|
|
GST_BUFFER_TIMESTAMP (buf));
|
2001-12-22 23:26:33 +00:00
|
|
|
|
|
|
|
/* deal with partial frame from previous buffer */
|
|
|
|
if (mpeg2subt->partialbuf) {
|
2004-03-06 20:56:28 +00:00
|
|
|
GstBuffer *merge;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
|
|
|
merge = gst_buffer_merge (mpeg2subt->partialbuf, buf);
|
2004-03-06 20:56:28 +00:00
|
|
|
gst_buffer_unref (mpeg2subt->partialbuf);
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_buffer_unref (buf);
|
2004-03-06 20:56:28 +00:00
|
|
|
mpeg2subt->partialbuf = merge;
|
2004-03-14 22:34:33 +00:00
|
|
|
} else {
|
2001-12-22 23:26:33 +00:00
|
|
|
mpeg2subt->partialbuf = buf;
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
data = GST_BUFFER_DATA (mpeg2subt->partialbuf);
|
|
|
|
size = GST_BUFFER_SIZE (mpeg2subt->partialbuf);
|
2001-12-22 23:26:33 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
mpeg2subt->packet_size = GUINT16_FROM_BE (*(guint16 *) data);
|
2001-12-22 23:26:33 +00:00
|
|
|
|
|
|
|
if (mpeg2subt->packet_size == size) {
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_DEBUG ("mpeg2subt: subtitle packet size %d, current size %ld",
|
|
|
|
mpeg2subt->packet_size, size);
|
2001-12-22 23:26:33 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
mpeg2subt->data_size = GUINT16_FROM_BE (*(guint16 *) (data + 2));
|
2001-12-22 23:26:33 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_mpeg2subt_parse_header (mpeg2subt);
|
2001-12-22 23:26:33 +00:00
|
|
|
mpeg2subt->have_title = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_mpeg2subt_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec)
|
2001-12-22 23:26:33 +00:00
|
|
|
{
|
|
|
|
GstMpeg2Subt *src;
|
|
|
|
|
|
|
|
/* it's not null if we got it, but it might not be ours */
|
2004-03-14 22:34:33 +00:00
|
|
|
g_return_if_fail (GST_IS_MPEG2SUBT (object));
|
|
|
|
src = GST_MPEG2SUBT (object);
|
2001-12-22 23:26:33 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_mpeg2subt_get_property (GObject * object, guint prop_id, GValue * value,
|
|
|
|
GParamSpec * pspec)
|
2001-12-22 23:26:33 +00:00
|
|
|
{
|
|
|
|
GstMpeg2Subt *src;
|
|
|
|
|
|
|
|
/* it's not null if we got it, but it might not be ours */
|
2004-03-14 22:34:33 +00:00
|
|
|
g_return_if_fail (GST_IS_MPEG2SUBT (object));
|
|
|
|
src = GST_MPEG2SUBT (object);
|
2001-12-22 23:26:33 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2004-03-14 22:34:33 +00:00
|
|
|
plugin_init (GstPlugin * plugin)
|
2001-12-22 23:26:33 +00:00
|
|
|
{
|
2004-03-14 22:34:33 +00:00
|
|
|
return gst_element_register (plugin, "mpeg2subt",
|
|
|
|
GST_RANK_NONE, GST_TYPE_MPEG2SUBT);
|
2001-12-22 23:26:33 +00:00
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
|
|
|
|
GST_VERSION_MINOR,
|
|
|
|
"mpeg2sub",
|
|
|
|
"MPEG-2 video subtitle parser",
|
|
|
|
plugin_init, VERSION, "LGPL", GST_PACKAGE, GST_ORIGIN)
|