2007-12-18 13:30:15 +00:00
|
|
|
/* GStreamer AVI GAB2 subtitle parser
|
2007-12-18 09:13:12 +00:00
|
|
|
* Copyright (C) <2007> Thijs Vermeir <thijsvermeir@gmail.com>
|
2007-12-18 13:30:15 +00:00
|
|
|
* Copyright (C) <2007> Tim-Philipp Müller <tim centricular net>
|
2007-12-18 09:13:12 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2008-02-01 18:29:21 +00:00
|
|
|
/**
|
|
|
|
* SECTION:element-avisubtitle
|
|
|
|
*
|
|
|
|
* <refsect2>
|
|
|
|
* <para>
|
|
|
|
* Parses the subtitle stream from an avi file.
|
|
|
|
* </para>
|
|
|
|
* <title>Example launch line</title>
|
|
|
|
* <para>
|
|
|
|
* <programlisting>
|
|
|
|
* gst-launch filesrc location=subtitle.avi ! avidemux name=demux ! queue ! avisubtitle ! subparse ! textoverlay name=overlay ! ffmpegcolorspace ! autovideosink demux. ! queue ! decodebin ! overlay.
|
|
|
|
* </programlisting>
|
|
|
|
* This plays an avi file with a video and subtitle stream.
|
|
|
|
* </para>
|
|
|
|
* </refsect2>
|
|
|
|
*
|
|
|
|
* Last reviewed on 2008-02-01
|
|
|
|
*/
|
2007-12-18 13:30:15 +00:00
|
|
|
|
|
|
|
/* example of a subtitle chunk in an avi file
|
|
|
|
* 00000000: 47 41 42 32 00 02 00 10 00 00 00 45 00 6e 00 67 GAB2.......E.n.g
|
|
|
|
* 00000010: 00 6c 00 69 00 73 00 68 00 00 00 04 00 8e 00 00 .l.i.s.h........
|
|
|
|
* 00000020: 00 ef bb bf 31 0d 0a 30 30 3a 30 30 3a 30 30 2c ....1..00:00:00,
|
|
|
|
* 00000030: 31 30 30 20 2d 2d 3e 20 30 30 3a 30 30 3a 30 32 100 --> 00:00:02
|
|
|
|
* 00000040: 2c 30 30 30 0d 0a 3c 62 3e 41 6e 20 55 54 46 38 ,000..<b>An UTF8
|
|
|
|
* 00000050: 20 53 75 62 74 69 74 6c 65 20 77 69 74 68 20 42 Subtitle with B
|
|
|
|
* 00000060: 4f 4d 3c 2f 62 3e 0d 0a 0d 0a 32 0d 0a 30 30 3a OM</b>....2..00:
|
|
|
|
* 00000070: 30 30 3a 30 32 2c 31 30 30 20 2d 2d 3e 20 30 30 00:02,100 --> 00
|
|
|
|
* 00000080: 3a 30 30 3a 30 34 2c 30 30 30 0d 0a 53 6f 6d 65 :00:04,000..Some
|
|
|
|
* 00000090: 74 68 69 6e 67 20 6e 6f 6e 41 53 43 49 49 20 2d thing nonASCII -
|
|
|
|
* 000000a0: 20 c2 b5 c3 b6 c3 a4 c3 bc c3 9f 0d 0a 0d 0a ..............
|
|
|
|
*/
|
2007-12-18 09:13:12 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "gstavisubtitle.h"
|
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_STATIC (avisubtitle_debug);
|
|
|
|
#define GST_CAT_DEFAULT avisubtitle_debug
|
|
|
|
|
|
|
|
static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
|
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS ("application/x-subtitle-avi")
|
|
|
|
);
|
|
|
|
|
|
|
|
static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS ("application/x-subtitle")
|
|
|
|
);
|
|
|
|
|
2008-01-02 13:54:10 +00:00
|
|
|
static void gst_avi_subtitle_title_tag (GstAviSubtitle * sub, gchar * title);
|
2011-11-17 14:02:55 +00:00
|
|
|
static GstFlowReturn gst_avi_subtitle_chain (GstPad * pad, GstObject * parent,
|
|
|
|
GstBuffer * buffer);
|
2007-12-18 13:30:15 +00:00
|
|
|
static GstStateChangeReturn gst_avi_subtitle_change_state (GstElement * element,
|
|
|
|
GstStateChange transition);
|
2007-12-18 21:13:05 +00:00
|
|
|
static gboolean gst_avi_subtitle_send_event (GstElement * element,
|
|
|
|
GstEvent * event);
|
2007-12-18 09:13:12 +00:00
|
|
|
|
2011-04-19 15:20:19 +00:00
|
|
|
#define gst_avi_subtitle_parent_class parent_class
|
|
|
|
G_DEFINE_TYPE (GstAviSubtitle, gst_avi_subtitle, GST_TYPE_ELEMENT);
|
2007-12-18 09:13:12 +00:00
|
|
|
|
2007-12-18 14:31:36 +00:00
|
|
|
#define IS_BOM_UTF8(data) ((GST_READ_UINT32_BE(data) >> 8) == 0xEFBBBF)
|
|
|
|
#define IS_BOM_UTF16_BE(data) (GST_READ_UINT16_BE(data) == 0xFEFF)
|
|
|
|
#define IS_BOM_UTF16_LE(data) (GST_READ_UINT16_LE(data) == 0xFEFF)
|
|
|
|
#define IS_BOM_UTF32_BE(data) (GST_READ_UINT32_BE(data) == 0xFEFF)
|
|
|
|
#define IS_BOM_UTF32_LE(data) (GST_READ_UINT32_LE(data) == 0xFEFF)
|
|
|
|
|
2007-12-18 09:13:12 +00:00
|
|
|
static GstBuffer *
|
2007-12-18 14:31:36 +00:00
|
|
|
gst_avi_subtitle_extract_file (GstAviSubtitle * sub, GstBuffer * buffer,
|
|
|
|
guint offset, guint len)
|
2007-12-18 09:13:12 +00:00
|
|
|
{
|
2007-12-18 14:31:36 +00:00
|
|
|
const gchar *input_enc = NULL;
|
2008-01-14 12:11:43 +00:00
|
|
|
GstBuffer *ret = NULL;
|
2012-01-23 16:25:37 +00:00
|
|
|
gchar *data;
|
|
|
|
GstMapInfo map;
|
2007-12-18 14:31:36 +00:00
|
|
|
|
2012-01-23 16:25:37 +00:00
|
|
|
gst_buffer_map (buffer, &map, GST_MAP_READ);
|
|
|
|
data = (gchar *) (map.data + offset);
|
2007-12-18 14:31:36 +00:00
|
|
|
|
|
|
|
if (len >= (3 + 1) && IS_BOM_UTF8 (data) &&
|
|
|
|
g_utf8_validate (data + 3, len - 3, NULL)) {
|
2011-04-05 09:13:36 +00:00
|
|
|
ret =
|
|
|
|
gst_buffer_copy_region (buffer, GST_BUFFER_COPY_ALL, offset + 3,
|
|
|
|
len - 3);
|
2007-12-18 14:31:36 +00:00
|
|
|
} else if (len >= 2 && IS_BOM_UTF16_BE (data)) {
|
|
|
|
input_enc = "UTF-16BE";
|
|
|
|
data += 2;
|
|
|
|
len -= 2;
|
|
|
|
} else if (len >= 2 && IS_BOM_UTF16_LE (data)) {
|
|
|
|
input_enc = "UTF-16LE";
|
|
|
|
data += 2;
|
|
|
|
len -= 2;
|
|
|
|
} else if (len >= 4 && IS_BOM_UTF32_BE (data)) {
|
|
|
|
input_enc = "UTF-32BE";
|
|
|
|
data += 4;
|
|
|
|
len -= 4;
|
|
|
|
} else if (len >= 4 && IS_BOM_UTF32_LE (data)) {
|
|
|
|
input_enc = "UTF-32LE";
|
|
|
|
data += 4;
|
|
|
|
len -= 4;
|
|
|
|
} else if (g_utf8_validate (data, len, NULL)) {
|
|
|
|
/* not specified, check if it's UTF-8 */
|
2011-04-05 09:13:36 +00:00
|
|
|
ret = gst_buffer_copy_region (buffer, GST_BUFFER_COPY_ALL, offset, len);
|
2007-12-18 14:31:36 +00:00
|
|
|
} else {
|
|
|
|
/* we could fall back to gst_tag_freeform_to_utf8() here */
|
|
|
|
GST_WARNING_OBJECT (sub, "unspecified encoding, and not UTF-8");
|
2011-04-05 09:13:36 +00:00
|
|
|
ret = NULL;
|
|
|
|
goto done;
|
2007-12-18 14:31:36 +00:00
|
|
|
}
|
|
|
|
|
2008-01-14 12:11:43 +00:00
|
|
|
g_return_val_if_fail (ret != NULL || input_enc != NULL, NULL);
|
|
|
|
|
2007-12-18 14:31:36 +00:00
|
|
|
if (input_enc) {
|
|
|
|
GError *err = NULL;
|
|
|
|
gchar *utf8;
|
2011-04-05 09:13:36 +00:00
|
|
|
gsize slen;
|
2007-12-18 09:13:12 +00:00
|
|
|
|
2007-12-18 14:31:36 +00:00
|
|
|
GST_DEBUG_OBJECT (sub, "converting subtitles from %s to UTF-8", input_enc);
|
|
|
|
utf8 = g_convert (data, len, "UTF-8", input_enc, NULL, NULL, &err);
|
|
|
|
|
|
|
|
if (err != NULL) {
|
|
|
|
GST_WARNING_OBJECT (sub, "conversion to UTF-8 failed : %s", err->message);
|
|
|
|
g_error_free (err);
|
2011-04-05 09:13:36 +00:00
|
|
|
ret = NULL;
|
|
|
|
goto done;
|
2007-12-18 14:31:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = gst_buffer_new ();
|
2011-04-05 09:13:36 +00:00
|
|
|
slen = strlen (utf8);
|
2012-03-30 16:13:08 +00:00
|
|
|
gst_buffer_append_memory (ret,
|
2012-02-22 01:06:17 +00:00
|
|
|
gst_memory_new_wrapped (0, utf8, slen, 0, slen, utf8, g_free));
|
2011-04-05 09:13:36 +00:00
|
|
|
|
2007-12-18 14:31:36 +00:00
|
|
|
GST_BUFFER_OFFSET (ret) = 0;
|
2007-12-18 09:13:12 +00:00
|
|
|
}
|
2011-04-05 09:13:36 +00:00
|
|
|
|
|
|
|
done:
|
2012-01-23 16:25:37 +00:00
|
|
|
gst_buffer_unmap (buffer, &map);
|
2011-04-05 09:13:36 +00:00
|
|
|
|
2007-12-18 14:31:36 +00:00
|
|
|
return ret;
|
2007-12-18 09:13:12 +00:00
|
|
|
}
|
|
|
|
|
2008-01-02 13:54:10 +00:00
|
|
|
/**
|
|
|
|
* gst_avi_subtitle_title_tag:
|
|
|
|
* @sub: subtitle element
|
|
|
|
* @title: the title of this subtitle stream
|
|
|
|
*
|
|
|
|
* Send an event to the srcpad of the @sub element with the title
|
|
|
|
* of the subtitle stream as a GST_TAG_TITLE
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
gst_avi_subtitle_title_tag (GstAviSubtitle * sub, gchar * title)
|
|
|
|
{
|
2011-10-30 11:44:53 +00:00
|
|
|
gst_pad_push_event (sub->src,
|
2012-07-27 22:19:51 +00:00
|
|
|
gst_event_new_tag (gst_tag_list_new (GST_TAG_TITLE, title, NULL)));
|
2008-01-02 13:54:10 +00:00
|
|
|
}
|
|
|
|
|
2007-12-18 09:13:12 +00:00
|
|
|
static GstFlowReturn
|
2007-12-18 13:30:15 +00:00
|
|
|
gst_avi_subtitle_parse_gab2_chunk (GstAviSubtitle * sub, GstBuffer * buf)
|
2007-12-18 09:13:12 +00:00
|
|
|
{
|
2007-12-18 13:30:15 +00:00
|
|
|
gchar *name_utf8;
|
|
|
|
guint name_length;
|
|
|
|
guint file_length;
|
2012-01-23 16:25:37 +00:00
|
|
|
GstMapInfo map;
|
2007-12-18 09:13:12 +00:00
|
|
|
|
2012-01-23 16:25:37 +00:00
|
|
|
gst_buffer_map (buf, &map, GST_MAP_READ);
|
2007-12-18 09:13:12 +00:00
|
|
|
|
2007-12-18 13:30:15 +00:00
|
|
|
/* check the magic word "GAB2\0", and the next word must be 2 */
|
2012-01-23 16:25:37 +00:00
|
|
|
if (map.size < 12 || memcmp (map.data, "GAB2\0\2\0", 5 + 2) != 0)
|
2007-12-18 09:13:12 +00:00
|
|
|
goto wrong_magic_word;
|
|
|
|
|
2007-12-18 13:30:15 +00:00
|
|
|
/* read 'name' of subtitle */
|
2012-01-23 16:25:37 +00:00
|
|
|
name_length = GST_READ_UINT32_LE (map.data + 5 + 2);
|
2007-12-18 13:30:15 +00:00
|
|
|
GST_LOG_OBJECT (sub, "length of name: %u", name_length);
|
2012-01-23 16:25:37 +00:00
|
|
|
if (map.size <= 17 + name_length)
|
2007-12-18 13:30:15 +00:00
|
|
|
goto wrong_name_length;
|
2007-12-18 09:13:12 +00:00
|
|
|
|
2012-01-23 16:25:37 +00:00
|
|
|
name_utf8 =
|
|
|
|
g_convert ((gchar *) map.data + 11, name_length, "UTF-8", "UTF-16LE",
|
2007-12-18 13:30:15 +00:00
|
|
|
NULL, NULL, NULL);
|
2007-12-18 09:13:12 +00:00
|
|
|
|
2007-12-18 13:30:15 +00:00
|
|
|
if (name_utf8) {
|
|
|
|
GST_LOG_OBJECT (sub, "subtitle name: %s", name_utf8);
|
2008-01-02 13:54:10 +00:00
|
|
|
gst_avi_subtitle_title_tag (sub, name_utf8);
|
2007-12-18 13:30:15 +00:00
|
|
|
g_free (name_utf8);
|
|
|
|
}
|
2007-12-18 09:13:12 +00:00
|
|
|
|
|
|
|
/* next word must be 4 */
|
2012-01-23 16:25:37 +00:00
|
|
|
if (GST_READ_UINT16_LE (map.data + 11 + name_length) != 0x4)
|
2007-12-18 09:13:12 +00:00
|
|
|
goto wrong_fixed_word_2;
|
|
|
|
|
2012-01-23 16:25:37 +00:00
|
|
|
file_length = GST_READ_UINT32_LE (map.data + 13 + name_length);
|
2007-12-18 13:30:15 +00:00
|
|
|
GST_LOG_OBJECT (sub, "length srt/ssa file: %u", file_length);
|
2007-12-18 09:13:12 +00:00
|
|
|
|
2012-01-23 16:25:37 +00:00
|
|
|
if (map.size < (17 + name_length + file_length))
|
2007-12-18 09:13:12 +00:00
|
|
|
goto wrong_total_length;
|
|
|
|
|
2007-12-18 13:30:15 +00:00
|
|
|
/* store this, so we can send it again after a seek; note that we shouldn't
|
|
|
|
* assume all the remaining data in the chunk is subtitle data, there may
|
|
|
|
* be padding at the end for some reason, so only parse file_length bytes */
|
|
|
|
sub->subfile =
|
2007-12-18 14:31:36 +00:00
|
|
|
gst_avi_subtitle_extract_file (sub, buf, 17 + name_length, file_length);
|
|
|
|
|
|
|
|
if (sub->subfile == NULL)
|
|
|
|
goto extract_failed;
|
2007-12-18 09:13:12 +00:00
|
|
|
|
2012-01-23 16:25:37 +00:00
|
|
|
gst_buffer_unmap (buf, &map);
|
2011-04-05 09:13:36 +00:00
|
|
|
|
2007-12-18 13:30:15 +00:00
|
|
|
return GST_FLOW_OK;
|
2007-12-18 09:13:12 +00:00
|
|
|
|
2007-12-18 13:30:15 +00:00
|
|
|
/* ERRORS */
|
2007-12-18 09:13:12 +00:00
|
|
|
wrong_magic_word:
|
2007-12-18 13:30:15 +00:00
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (sub, STREAM, DECODE, (NULL), ("Wrong magic word"));
|
2012-01-23 16:25:37 +00:00
|
|
|
gst_buffer_unmap (buf, &map);
|
2007-12-18 13:30:15 +00:00
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
|
|
|
wrong_name_length:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (sub, STREAM, DECODE, (NULL),
|
2012-01-23 16:25:37 +00:00
|
|
|
("name doesn't fit in buffer (%" G_GSIZE_FORMAT " < %d)", map.size,
|
2011-11-21 19:31:31 +00:00
|
|
|
17 + name_length));
|
2012-01-23 16:25:37 +00:00
|
|
|
gst_buffer_unmap (buf, &map);
|
2007-12-18 13:30:15 +00:00
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
|
|
|
wrong_fixed_word_2:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (sub, STREAM, DECODE, (NULL),
|
|
|
|
("wrong fixed word: expected %u, got %u", 4,
|
2012-01-23 16:25:37 +00:00
|
|
|
GST_READ_UINT16_LE (map.data + 11 + name_length)));
|
|
|
|
gst_buffer_unmap (buf, &map);
|
2007-12-18 13:30:15 +00:00
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
|
|
|
wrong_total_length:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (sub, STREAM, DECODE, (NULL),
|
2011-11-21 19:31:31 +00:00
|
|
|
("buffer size is wrong: need %d bytes, have %" G_GSIZE_FORMAT " bytes",
|
2012-01-23 16:25:37 +00:00
|
|
|
17 + name_length + file_length, map.size));
|
|
|
|
gst_buffer_unmap (buf, &map);
|
2007-12-18 13:30:15 +00:00
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
2007-12-18 14:31:36 +00:00
|
|
|
extract_failed:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (sub, STREAM, DECODE, (NULL),
|
|
|
|
("could not extract subtitles"));
|
2012-01-23 16:25:37 +00:00
|
|
|
gst_buffer_unmap (buf, &map);
|
2007-12-18 14:31:36 +00:00
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
2007-12-18 13:30:15 +00:00
|
|
|
}
|
2007-12-18 09:13:12 +00:00
|
|
|
|
2007-12-18 13:30:15 +00:00
|
|
|
static GstFlowReturn
|
2011-11-17 14:02:55 +00:00
|
|
|
gst_avi_subtitle_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer)
|
2007-12-18 13:30:15 +00:00
|
|
|
{
|
2011-11-17 14:02:55 +00:00
|
|
|
GstAviSubtitle *sub = GST_AVI_SUBTITLE (parent);
|
2007-12-18 13:30:15 +00:00
|
|
|
GstFlowReturn ret;
|
2007-12-18 09:13:12 +00:00
|
|
|
|
2007-12-18 13:30:15 +00:00
|
|
|
if (sub->subfile != NULL) {
|
|
|
|
GST_WARNING_OBJECT (sub, "Got more buffers than expected, dropping");
|
2012-01-03 14:26:21 +00:00
|
|
|
ret = GST_FLOW_EOS;
|
2007-12-18 13:30:15 +00:00
|
|
|
goto done;
|
|
|
|
}
|
2007-12-18 09:13:12 +00:00
|
|
|
|
2007-12-18 13:30:15 +00:00
|
|
|
/* we expect exactly one buffer with the whole srt/ssa file in it */
|
|
|
|
ret = gst_avi_subtitle_parse_gab2_chunk (sub, buffer);
|
|
|
|
if (ret != GST_FLOW_OK)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
/* now push the subtitle data downstream */
|
|
|
|
ret = gst_pad_push (sub->src, gst_buffer_ref (sub->subfile));
|
|
|
|
|
|
|
|
done:
|
2007-12-18 09:13:12 +00:00
|
|
|
|
|
|
|
gst_buffer_unref (buffer);
|
2007-12-18 13:30:15 +00:00
|
|
|
return ret;
|
2007-12-18 09:13:12 +00:00
|
|
|
}
|
|
|
|
|
2007-12-18 21:13:05 +00:00
|
|
|
static gboolean
|
|
|
|
gst_avi_subtitle_send_event (GstElement * element, GstEvent * event)
|
|
|
|
{
|
|
|
|
GstAviSubtitle *avisubtitle = GST_AVI_SUBTITLE (element);
|
|
|
|
gboolean ret = FALSE;
|
|
|
|
|
|
|
|
if (GST_EVENT_TYPE (event) == GST_EVENT_SEEK) {
|
|
|
|
if (avisubtitle->subfile) {
|
|
|
|
if (gst_pad_push (avisubtitle->src,
|
|
|
|
gst_buffer_ref (avisubtitle->subfile)) == GST_FLOW_OK)
|
|
|
|
ret = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
gst_event_unref (event);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-12-18 09:13:12 +00:00
|
|
|
static void
|
2011-04-19 15:20:19 +00:00
|
|
|
gst_avi_subtitle_class_init (GstAviSubtitleClass * klass)
|
2007-12-18 09:13:12 +00:00
|
|
|
{
|
2011-04-19 15:20:19 +00:00
|
|
|
GstElementClass *gstelement_class = (GstElementClass *) klass;
|
2007-12-18 09:13:12 +00:00
|
|
|
|
2007-12-18 13:30:15 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT (avisubtitle_debug, "avisubtitle", 0,
|
|
|
|
"parse avi subtitle stream");
|
|
|
|
|
2011-04-19 15:20:19 +00:00
|
|
|
gstelement_class->change_state =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_avi_subtitle_change_state);
|
|
|
|
gstelement_class->send_event =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_avi_subtitle_send_event);
|
|
|
|
|
|
|
|
gst_element_class_add_pad_template (gstelement_class,
|
2007-12-18 09:13:12 +00:00
|
|
|
gst_static_pad_template_get (&sink_template));
|
2011-04-19 15:20:19 +00:00
|
|
|
gst_element_class_add_pad_template (gstelement_class,
|
2007-12-18 09:13:12 +00:00
|
|
|
gst_static_pad_template_get (&src_template));
|
|
|
|
|
2012-04-09 23:51:41 +00:00
|
|
|
gst_element_class_set_static_metadata (gstelement_class,
|
2008-02-01 18:29:21 +00:00
|
|
|
"Avi subtitle parser", "Codec/Parser/Subtitle",
|
|
|
|
"Parse avi subtitle stream", "Thijs Vermeir <thijsvermeir@gmail.com>");
|
2007-12-18 09:13:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-04-19 15:20:19 +00:00
|
|
|
gst_avi_subtitle_init (GstAviSubtitle * self)
|
2007-12-18 09:13:12 +00:00
|
|
|
{
|
2011-01-18 09:33:06 +00:00
|
|
|
GstCaps *caps;
|
|
|
|
|
2007-12-18 09:13:12 +00:00
|
|
|
self->src = gst_pad_new_from_static_template (&src_template, "src");
|
|
|
|
gst_element_add_pad (GST_ELEMENT (self), self->src);
|
|
|
|
|
|
|
|
self->sink = gst_pad_new_from_static_template (&sink_template, "sink");
|
2007-12-18 13:30:15 +00:00
|
|
|
gst_pad_set_chain_function (self->sink,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_avi_subtitle_chain));
|
2011-01-18 09:33:06 +00:00
|
|
|
|
|
|
|
caps = gst_static_pad_template_get_caps (&src_template);
|
|
|
|
gst_pad_set_caps (self->src, caps);
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
|
|
|
|
gst_pad_use_fixed_caps (self->src);
|
2007-12-18 09:13:12 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (self), self->sink);
|
2007-12-18 21:13:05 +00:00
|
|
|
|
|
|
|
self->subfile = NULL;
|
2007-12-18 13:30:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GstStateChangeReturn
|
|
|
|
gst_avi_subtitle_change_state (GstElement * element, GstStateChange transition)
|
|
|
|
{
|
|
|
|
GstStateChangeReturn ret;
|
|
|
|
GstAviSubtitle *sub = GST_AVI_SUBTITLE (element);
|
|
|
|
|
|
|
|
switch (transition) {
|
|
|
|
case GST_STATE_CHANGE_NULL_TO_READY:
|
|
|
|
case GST_STATE_CHANGE_READY_TO_PAUSED:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
|
|
|
|
if (ret == GST_STATE_CHANGE_FAILURE)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
switch (transition) {
|
|
|
|
case GST_STATE_CHANGE_PAUSED_TO_READY:
|
|
|
|
if (sub->subfile) {
|
|
|
|
gst_buffer_unref (sub->subfile);
|
|
|
|
sub->subfile = NULL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2007-12-18 09:13:12 +00:00
|
|
|
}
|