2009-02-05 15:54:01 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2008 Benjamin Schmitz <vortex@wolpzone.de>
|
2009-12-07 13:05:22 +00:00
|
|
|
* Copyright (c) 2009 Sebastian Dröge <sebastian.droege@collabora.co.uk>
|
2009-02-05 15:54:01 +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.
|
|
|
|
*/
|
|
|
|
|
2009-12-08 13:46:35 +00:00
|
|
|
/**
|
|
|
|
* SECTION:element-assrender
|
|
|
|
*
|
|
|
|
* Renders timestamped SSA/ASS subtitles on top of a video stream.
|
|
|
|
*
|
|
|
|
* <refsect2>
|
|
|
|
* <title>Example launch line</title>
|
|
|
|
* |[
|
|
|
|
* gst-launch -v filesrc location=/path/to/mkv ! matroskademux name=d ! queue ! mp3parse ! mad ! audioconvert ! autoaudiosink d. ! queue ! ffdec_h264 ! ffmpegcolorspace ! r. d. ! queue ! "application/x-ass" ! assrender name=r ! ffmpegcolorspace ! autovideosink
|
|
|
|
* ]| This pipeline demuxes a Matroska file with h.264 video, MP3 audio and embedded ASS subtitles and renders the subtitles on top of the video.
|
|
|
|
* </refsect2>
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2009-02-05 15:54:01 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "gstassrender.h"
|
|
|
|
|
2009-12-07 17:30:05 +00:00
|
|
|
#include <string.h>
|
2009-02-05 16:00:30 +00:00
|
|
|
|
2009-12-07 13:05:22 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (gst_ass_render_debug);
|
|
|
|
GST_DEBUG_CATEGORY_STATIC (gst_ass_render_lib_debug);
|
|
|
|
#define GST_CAT_DEFAULT gst_ass_render_debug
|
2009-02-05 15:54:01 +00:00
|
|
|
|
|
|
|
/* Filter signals and props */
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
2009-12-07 13:05:22 +00:00
|
|
|
PROP_0,
|
|
|
|
PROP_ENABLE,
|
|
|
|
PROP_EMBEDDEDFONTS
|
2009-02-05 15:54:01 +00:00
|
|
|
};
|
|
|
|
|
2011-10-06 08:58:32 +00:00
|
|
|
#define FORMATS "{ RGB, BGR, xRGB, xBGR, RGBx, BGRx, I420 }"
|
|
|
|
|
2009-02-05 15:54:01 +00:00
|
|
|
static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
2011-10-06 08:58:32 +00:00
|
|
|
GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE (FORMATS))
|
2009-02-05 15:54:01 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
static GstStaticPadTemplate video_sink_factory =
|
2011-10-06 08:58:32 +00:00
|
|
|
GST_STATIC_PAD_TEMPLATE ("video_sink",
|
2009-02-05 15:54:01 +00:00
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
2011-10-06 08:58:32 +00:00
|
|
|
GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE (FORMATS))
|
2009-02-05 15:54:01 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
static GstStaticPadTemplate text_sink_factory =
|
|
|
|
GST_STATIC_PAD_TEMPLATE ("text_sink",
|
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS ("application/x-ass; application/x-ssa")
|
|
|
|
);
|
|
|
|
|
2009-12-07 13:05:22 +00:00
|
|
|
static void gst_ass_render_set_property (GObject * object, guint prop_id,
|
2009-02-05 15:54:01 +00:00
|
|
|
const GValue * value, GParamSpec * pspec);
|
2009-12-07 13:05:22 +00:00
|
|
|
static void gst_ass_render_get_property (GObject * object, guint prop_id,
|
2009-02-05 15:54:01 +00:00
|
|
|
GValue * value, GParamSpec * pspec);
|
|
|
|
|
2009-12-07 13:05:22 +00:00
|
|
|
static void gst_ass_render_finalize (GObject * object);
|
2009-02-05 15:54:01 +00:00
|
|
|
|
2009-12-07 13:05:22 +00:00
|
|
|
static GstStateChangeReturn gst_ass_render_change_state (GstElement * element,
|
2009-11-04 11:50:18 +00:00
|
|
|
GstStateChange transition);
|
|
|
|
|
2011-10-06 08:58:32 +00:00
|
|
|
#define gst_ass_render_parent_class parent_class
|
|
|
|
G_DEFINE_TYPE (GstAssRender, gst_ass_render, GST_TYPE_ELEMENT);
|
2009-02-05 15:54:01 +00:00
|
|
|
|
2011-10-06 08:58:32 +00:00
|
|
|
static GstCaps *gst_ass_render_getcaps (GstPad * pad, GstCaps * filter);
|
2009-02-05 15:54:01 +00:00
|
|
|
|
2009-12-07 13:05:22 +00:00
|
|
|
static gboolean gst_ass_render_setcaps_video (GstPad * pad, GstCaps * caps);
|
|
|
|
static gboolean gst_ass_render_setcaps_text (GstPad * pad, GstCaps * caps);
|
2009-02-05 15:54:01 +00:00
|
|
|
|
2011-11-17 14:53:42 +00:00
|
|
|
static GstFlowReturn gst_ass_render_chain_video (GstPad * pad,
|
|
|
|
GstObject * parent, GstBuffer * buf);
|
|
|
|
static GstFlowReturn gst_ass_render_chain_text (GstPad * pad,
|
|
|
|
GstObject * parent, GstBuffer * buf);
|
|
|
|
|
|
|
|
static gboolean gst_ass_render_event_video (GstPad * pad, GstObject * parent,
|
|
|
|
GstEvent * event);
|
|
|
|
static gboolean gst_ass_render_event_text (GstPad * pad, GstObject * parent,
|
|
|
|
GstEvent * event);
|
|
|
|
static gboolean gst_ass_render_event_src (GstPad * pad, GstObject * parent,
|
|
|
|
GstEvent * event);
|
2009-02-05 15:54:01 +00:00
|
|
|
|
2011-11-16 16:28:10 +00:00
|
|
|
static gboolean gst_ass_render_query_video (GstPad * pad, GstObject * parent,
|
|
|
|
GstQuery * query);
|
|
|
|
static gboolean gst_ass_render_query_src (GstPad * pad, GstObject * parent,
|
|
|
|
GstQuery * query);
|
2009-12-09 08:57:58 +00:00
|
|
|
|
2009-02-05 15:54:01 +00:00
|
|
|
/* initialize the plugin's class */
|
|
|
|
static void
|
2009-12-07 13:05:22 +00:00
|
|
|
gst_ass_render_class_init (GstAssRenderClass * klass)
|
2009-02-05 15:54:01 +00:00
|
|
|
{
|
2009-12-07 13:05:22 +00:00
|
|
|
GObjectClass *gobject_class = (GObjectClass *) klass;
|
|
|
|
GstElementClass *gstelement_class = (GstElementClass *) klass;
|
2009-02-05 15:54:01 +00:00
|
|
|
|
2009-12-07 13:05:22 +00:00
|
|
|
gobject_class->set_property = gst_ass_render_set_property;
|
|
|
|
gobject_class->get_property = gst_ass_render_get_property;
|
|
|
|
gobject_class->finalize = gst_ass_render_finalize;
|
2009-02-05 15:54:01 +00:00
|
|
|
|
2009-12-07 13:05:22 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_ENABLE,
|
2009-12-08 13:46:35 +00:00
|
|
|
g_param_spec_boolean ("enable", "Enable",
|
2009-02-05 16:42:37 +00:00
|
|
|
"Enable rendering of subtitles", TRUE,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2009-12-07 13:05:22 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_EMBEDDEDFONTS,
|
2009-12-08 13:46:35 +00:00
|
|
|
g_param_spec_boolean ("embeddedfonts", "Embedded Fonts",
|
2009-02-05 16:42:37 +00:00
|
|
|
"Extract and use fonts embedded in the stream", TRUE,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2009-11-04 11:50:18 +00:00
|
|
|
|
|
|
|
gstelement_class->change_state =
|
2009-12-07 13:05:22 +00:00
|
|
|
GST_DEBUG_FUNCPTR (gst_ass_render_change_state);
|
2011-10-06 08:58:32 +00:00
|
|
|
|
|
|
|
gst_element_class_add_pad_template (gstelement_class,
|
|
|
|
gst_static_pad_template_get (&src_factory));
|
|
|
|
gst_element_class_add_pad_template (gstelement_class,
|
|
|
|
gst_static_pad_template_get (&video_sink_factory));
|
|
|
|
gst_element_class_add_pad_template (gstelement_class,
|
|
|
|
gst_static_pad_template_get (&text_sink_factory));
|
|
|
|
|
|
|
|
gst_element_class_set_details_simple (gstelement_class, "ASS/SSA Render",
|
|
|
|
"Mixer/Video/Overlay/Subtitle",
|
|
|
|
"Renders ASS/SSA subtitles with libass",
|
|
|
|
"Benjamin Schmitz <vortex@wolpzone.de>, "
|
|
|
|
"Sebastian Dröge <sebastian.droege@collabora.co.uk>");
|
2009-02-05 15:54:01 +00:00
|
|
|
}
|
|
|
|
|
2009-12-08 10:25:39 +00:00
|
|
|
#if defined(LIBASS_VERSION) && LIBASS_VERSION >= 0x00907000
|
2009-12-07 12:26:39 +00:00
|
|
|
static void
|
2010-06-27 10:24:37 +00:00
|
|
|
_libass_message_cb (gint level, const gchar * fmt, va_list args,
|
|
|
|
gpointer render)
|
2009-12-07 12:26:39 +00:00
|
|
|
{
|
|
|
|
gchar *message = g_strdup_vprintf (fmt, args);
|
|
|
|
|
|
|
|
if (level < 2)
|
2010-04-08 00:41:31 +00:00
|
|
|
GST_CAT_ERROR_OBJECT (gst_ass_render_lib_debug, render, "%s", message);
|
2009-12-07 12:26:39 +00:00
|
|
|
else if (level < 4)
|
2010-04-08 00:41:31 +00:00
|
|
|
GST_CAT_WARNING_OBJECT (gst_ass_render_lib_debug, render, "%s", message);
|
2009-12-07 12:26:39 +00:00
|
|
|
else if (level < 5)
|
2010-04-08 00:41:31 +00:00
|
|
|
GST_CAT_INFO_OBJECT (gst_ass_render_lib_debug, render, "%s", message);
|
2009-12-07 12:26:39 +00:00
|
|
|
else if (level < 6)
|
2010-04-08 00:41:31 +00:00
|
|
|
GST_CAT_DEBUG_OBJECT (gst_ass_render_lib_debug, render, "%s", message);
|
2009-12-07 12:26:39 +00:00
|
|
|
else
|
2010-04-08 00:41:31 +00:00
|
|
|
GST_CAT_LOG_OBJECT (gst_ass_render_lib_debug, render, "%s", message);
|
2009-12-07 12:26:39 +00:00
|
|
|
|
|
|
|
g_free (message);
|
|
|
|
}
|
2009-12-08 10:25:39 +00:00
|
|
|
#endif
|
2009-12-07 12:26:39 +00:00
|
|
|
|
2009-02-05 15:54:01 +00:00
|
|
|
static void
|
2011-10-06 08:58:32 +00:00
|
|
|
gst_ass_render_init (GstAssRender * render)
|
2009-02-05 15:54:01 +00:00
|
|
|
{
|
|
|
|
GST_DEBUG_OBJECT (render, "init");
|
|
|
|
|
2009-02-05 16:42:37 +00:00
|
|
|
render->srcpad = gst_pad_new_from_static_template (&src_factory, "src");
|
|
|
|
render->video_sinkpad =
|
|
|
|
gst_pad_new_from_static_template (&video_sink_factory, "video_sink");
|
|
|
|
render->text_sinkpad =
|
|
|
|
gst_pad_new_from_static_template (&text_sink_factory, "text_sink");
|
2009-02-05 15:54:01 +00:00
|
|
|
|
|
|
|
gst_pad_set_chain_function (render->video_sinkpad,
|
2009-12-07 13:05:22 +00:00
|
|
|
GST_DEBUG_FUNCPTR (gst_ass_render_chain_video));
|
2009-02-05 15:54:01 +00:00
|
|
|
gst_pad_set_chain_function (render->text_sinkpad,
|
2009-12-07 13:05:22 +00:00
|
|
|
GST_DEBUG_FUNCPTR (gst_ass_render_chain_text));
|
2009-02-05 15:54:01 +00:00
|
|
|
|
|
|
|
gst_pad_set_event_function (render->video_sinkpad,
|
2009-12-07 13:05:22 +00:00
|
|
|
GST_DEBUG_FUNCPTR (gst_ass_render_event_video));
|
2009-02-05 15:54:01 +00:00
|
|
|
gst_pad_set_event_function (render->text_sinkpad,
|
2009-12-07 13:05:22 +00:00
|
|
|
GST_DEBUG_FUNCPTR (gst_ass_render_event_text));
|
2009-12-09 08:51:20 +00:00
|
|
|
gst_pad_set_event_function (render->srcpad,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_ass_render_event_src));
|
2009-02-05 15:54:01 +00:00
|
|
|
|
2009-12-09 08:57:58 +00:00
|
|
|
gst_pad_set_query_function (render->srcpad,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_ass_render_query_src));
|
2011-11-15 15:34:13 +00:00
|
|
|
gst_pad_set_query_function (render->video_sinkpad,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_ass_render_query_video));
|
2009-12-09 08:57:58 +00:00
|
|
|
|
2009-02-05 15:54:01 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (render), render->srcpad);
|
|
|
|
gst_element_add_pad (GST_ELEMENT (render), render->video_sinkpad);
|
|
|
|
gst_element_add_pad (GST_ELEMENT (render), render->text_sinkpad);
|
|
|
|
|
2011-10-06 08:58:32 +00:00
|
|
|
gst_video_info_init (&render->info);
|
2009-02-05 15:54:01 +00:00
|
|
|
|
2012-01-19 10:34:26 +00:00
|
|
|
g_mutex_init (&render->subtitle_mutex);
|
|
|
|
g_cond_init (&render->subtitle_cond);
|
2009-11-04 11:50:18 +00:00
|
|
|
|
2009-02-05 15:54:01 +00:00
|
|
|
render->renderer_init_ok = FALSE;
|
|
|
|
render->track_init_ok = FALSE;
|
|
|
|
render->enable = TRUE;
|
|
|
|
render->embeddedfonts = TRUE;
|
|
|
|
|
2009-02-05 16:42:37 +00:00
|
|
|
gst_segment_init (&render->video_segment, GST_FORMAT_TIME);
|
2009-11-05 16:06:18 +00:00
|
|
|
gst_segment_init (&render->subtitle_segment, GST_FORMAT_TIME);
|
2009-02-05 15:54:01 +00:00
|
|
|
|
2012-01-19 10:34:26 +00:00
|
|
|
g_mutex_init (&render->ass_mutex);
|
2009-02-05 15:54:01 +00:00
|
|
|
render->ass_library = ass_library_init ();
|
2009-12-08 10:25:39 +00:00
|
|
|
#if defined(LIBASS_VERSION) && LIBASS_VERSION >= 0x00907000
|
2009-12-07 12:26:39 +00:00
|
|
|
ass_set_message_cb (render->ass_library, _libass_message_cb, render);
|
2009-12-08 10:25:39 +00:00
|
|
|
#endif
|
2009-12-07 12:40:56 +00:00
|
|
|
ass_set_extract_fonts (render->ass_library, 1);
|
2009-02-05 15:54:01 +00:00
|
|
|
|
|
|
|
render->ass_renderer = ass_renderer_init (render->ass_library);
|
|
|
|
if (!render->ass_renderer) {
|
|
|
|
GST_WARNING_OBJECT (render, "cannot create renderer instance");
|
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
|
|
|
|
|
|
|
render->ass_track = NULL;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (render, "init complete");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-12-07 13:05:22 +00:00
|
|
|
gst_ass_render_finalize (GObject * object)
|
2009-02-05 15:54:01 +00:00
|
|
|
{
|
2009-12-07 13:05:22 +00:00
|
|
|
GstAssRender *render = GST_ASS_RENDER (object);
|
2009-02-05 15:54:01 +00:00
|
|
|
|
2012-01-19 10:34:26 +00:00
|
|
|
g_mutex_clear (&render->subtitle_mutex);
|
|
|
|
g_cond_clear (&render->subtitle_cond);
|
2009-11-04 11:50:18 +00:00
|
|
|
|
2009-02-05 15:54:01 +00:00
|
|
|
if (render->ass_track) {
|
|
|
|
ass_free_track (render->ass_track);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (render->ass_renderer) {
|
|
|
|
ass_renderer_done (render->ass_renderer);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (render->ass_library) {
|
|
|
|
ass_library_done (render->ass_library);
|
|
|
|
}
|
|
|
|
|
2012-01-19 10:34:26 +00:00
|
|
|
g_mutex_clear (&render->ass_mutex);
|
2010-02-23 17:16:48 +00:00
|
|
|
|
2009-02-05 15:54:01 +00:00
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-12-07 13:05:22 +00:00
|
|
|
gst_ass_render_set_property (GObject * object, guint prop_id,
|
2009-02-05 15:54:01 +00:00
|
|
|
const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
2009-12-07 13:05:22 +00:00
|
|
|
GstAssRender *render = GST_ASS_RENDER (object);
|
2009-02-05 15:54:01 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
2009-12-07 13:05:22 +00:00
|
|
|
case PROP_ENABLE:
|
2009-02-05 15:54:01 +00:00
|
|
|
render->enable = g_value_get_boolean (value);
|
|
|
|
break;
|
2009-12-07 13:05:22 +00:00
|
|
|
case PROP_EMBEDDEDFONTS:
|
2009-02-05 15:54:01 +00:00
|
|
|
render->embeddedfonts = g_value_get_boolean (value);
|
2012-01-19 10:34:26 +00:00
|
|
|
g_mutex_lock (&render->ass_mutex);
|
2009-12-07 12:40:56 +00:00
|
|
|
ass_set_extract_fonts (render->ass_library, render->embeddedfonts);
|
2012-01-19 10:34:26 +00:00
|
|
|
g_mutex_unlock (&render->ass_mutex);
|
2009-02-05 15:54:01 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-12-07 13:05:22 +00:00
|
|
|
gst_ass_render_get_property (GObject * object, guint prop_id,
|
2009-02-05 15:54:01 +00:00
|
|
|
GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
2009-12-07 13:05:22 +00:00
|
|
|
GstAssRender *render = GST_ASS_RENDER (object);
|
2009-02-05 15:54:01 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
2009-12-07 13:05:22 +00:00
|
|
|
case PROP_ENABLE:
|
2009-02-05 15:54:01 +00:00
|
|
|
g_value_set_boolean (value, render->enable);
|
|
|
|
break;
|
2009-12-07 13:05:22 +00:00
|
|
|
case PROP_EMBEDDEDFONTS:
|
2009-02-05 15:54:01 +00:00
|
|
|
g_value_set_boolean (value, render->embeddedfonts);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-04 11:50:18 +00:00
|
|
|
static GstStateChangeReturn
|
2009-12-07 13:05:22 +00:00
|
|
|
gst_ass_render_change_state (GstElement * element, GstStateChange transition)
|
2009-11-04 11:50:18 +00:00
|
|
|
{
|
2009-12-07 13:05:22 +00:00
|
|
|
GstAssRender *render = GST_ASS_RENDER (element);
|
2009-11-04 11:50:18 +00:00
|
|
|
GstStateChangeReturn ret;
|
|
|
|
|
|
|
|
switch (transition) {
|
|
|
|
case GST_STATE_CHANGE_READY_TO_PAUSED:
|
2009-11-04 12:11:44 +00:00
|
|
|
render->subtitle_flushing = FALSE;
|
2009-11-05 16:06:18 +00:00
|
|
|
gst_segment_init (&render->video_segment, GST_FORMAT_TIME);
|
|
|
|
gst_segment_init (&render->subtitle_segment, GST_FORMAT_TIME);
|
2009-11-04 12:11:44 +00:00
|
|
|
break;
|
|
|
|
case GST_STATE_CHANGE_NULL_TO_READY:
|
2009-11-04 11:50:18 +00:00
|
|
|
case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GST_STATE_CHANGE_PAUSED_TO_READY:
|
2012-01-19 10:34:26 +00:00
|
|
|
g_mutex_lock (&render->subtitle_mutex);
|
2009-11-05 11:25:25 +00:00
|
|
|
render->subtitle_flushing = TRUE;
|
2009-11-04 11:50:18 +00:00
|
|
|
if (render->subtitle_pending)
|
|
|
|
gst_buffer_unref (render->subtitle_pending);
|
|
|
|
render->subtitle_pending = NULL;
|
2012-01-19 10:34:26 +00:00
|
|
|
g_cond_signal (&render->subtitle_cond);
|
|
|
|
g_mutex_unlock (&render->subtitle_mutex);
|
2009-11-04 11:50:18 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
|
|
|
|
|
|
|
|
switch (transition) {
|
|
|
|
case GST_STATE_CHANGE_PAUSED_TO_READY:
|
2012-01-19 10:34:26 +00:00
|
|
|
g_mutex_lock (&render->ass_mutex);
|
2009-11-04 11:50:18 +00:00
|
|
|
if (render->ass_track)
|
|
|
|
ass_free_track (render->ass_track);
|
|
|
|
render->ass_track = NULL;
|
2012-01-19 10:34:26 +00:00
|
|
|
g_mutex_unlock (&render->ass_mutex);
|
2009-11-04 11:50:18 +00:00
|
|
|
render->track_init_ok = FALSE;
|
|
|
|
render->renderer_init_ok = FALSE;
|
|
|
|
break;
|
|
|
|
case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
|
|
|
|
case GST_STATE_CHANGE_READY_TO_NULL:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-12-09 08:57:58 +00:00
|
|
|
static gboolean
|
2011-11-16 16:28:10 +00:00
|
|
|
gst_ass_render_query_src (GstPad * pad, GstObject * parent, GstQuery * query)
|
2009-12-09 08:57:58 +00:00
|
|
|
{
|
2011-11-15 15:34:13 +00:00
|
|
|
gboolean res = FALSE;
|
|
|
|
|
|
|
|
switch (GST_QUERY_TYPE (query)) {
|
|
|
|
case GST_QUERY_CAPS:
|
|
|
|
{
|
|
|
|
GstCaps *filter, *caps;
|
2009-12-09 08:57:58 +00:00
|
|
|
|
2011-11-15 15:34:13 +00:00
|
|
|
gst_query_parse_caps (query, &filter);
|
|
|
|
caps = gst_ass_render_getcaps (pad, filter);
|
|
|
|
gst_query_set_caps_result (query, caps);
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
res = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
2011-11-16 16:28:10 +00:00
|
|
|
res = gst_pad_query_default (pad, parent, query);
|
2011-11-15 15:34:13 +00:00
|
|
|
break;
|
|
|
|
}
|
2009-12-09 08:57:58 +00:00
|
|
|
|
2011-11-15 15:34:13 +00:00
|
|
|
return res;
|
2009-12-09 08:57:58 +00:00
|
|
|
}
|
|
|
|
|
2009-12-09 08:51:20 +00:00
|
|
|
static gboolean
|
2011-11-17 14:53:42 +00:00
|
|
|
gst_ass_render_event_src (GstPad * pad, GstObject * parent, GstEvent * event)
|
2009-12-09 08:51:20 +00:00
|
|
|
{
|
2011-11-17 14:53:42 +00:00
|
|
|
GstAssRender *render = GST_ASS_RENDER (parent);
|
2009-12-09 08:51:20 +00:00
|
|
|
gboolean ret = FALSE;
|
|
|
|
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
|
|
|
case GST_EVENT_SEEK:{
|
|
|
|
GstSeekFlags flags;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (render, "seek received, driving from here");
|
|
|
|
|
|
|
|
gst_event_parse_seek (event, NULL, NULL, &flags, NULL, NULL, NULL, NULL);
|
|
|
|
|
|
|
|
/* Flush downstream, only for flushing seek */
|
|
|
|
if (flags & GST_SEEK_FLAG_FLUSH)
|
|
|
|
gst_pad_push_event (render->srcpad, gst_event_new_flush_start ());
|
|
|
|
|
|
|
|
/* Mark subtitle as flushing, unblocks chains */
|
2012-01-19 10:34:26 +00:00
|
|
|
g_mutex_lock (&render->subtitle_mutex);
|
2009-12-09 08:51:20 +00:00
|
|
|
if (render->subtitle_pending)
|
|
|
|
gst_buffer_unref (render->subtitle_pending);
|
|
|
|
render->subtitle_pending = NULL;
|
|
|
|
render->subtitle_flushing = TRUE;
|
2012-01-19 10:34:26 +00:00
|
|
|
g_cond_signal (&render->subtitle_cond);
|
|
|
|
g_mutex_unlock (&render->subtitle_mutex);
|
2009-12-09 08:51:20 +00:00
|
|
|
|
|
|
|
/* Seek on each sink pad */
|
|
|
|
gst_event_ref (event);
|
|
|
|
ret = gst_pad_push_event (render->video_sinkpad, event);
|
|
|
|
if (ret) {
|
|
|
|
ret = gst_pad_push_event (render->text_sinkpad, event);
|
|
|
|
} else {
|
|
|
|
gst_event_unref (event);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
gst_event_ref (event);
|
|
|
|
ret = gst_pad_push_event (render->video_sinkpad, event);
|
|
|
|
gst_pad_push_event (render->text_sinkpad, event);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-02-05 15:54:01 +00:00
|
|
|
static GstCaps *
|
2011-10-06 08:58:32 +00:00
|
|
|
gst_ass_render_getcaps (GstPad * pad, GstCaps * filter)
|
2009-02-05 15:54:01 +00:00
|
|
|
{
|
2009-12-07 13:05:22 +00:00
|
|
|
GstAssRender *render = GST_ASS_RENDER (gst_pad_get_parent (pad));
|
2009-02-05 15:54:01 +00:00
|
|
|
GstPad *otherpad;
|
|
|
|
GstCaps *caps;
|
|
|
|
|
|
|
|
if (pad == render->srcpad)
|
|
|
|
otherpad = render->video_sinkpad;
|
|
|
|
else
|
|
|
|
otherpad = render->srcpad;
|
|
|
|
|
|
|
|
/* we can do what the peer can */
|
2011-11-15 16:24:07 +00:00
|
|
|
caps = gst_pad_peer_query_caps (otherpad, filter);
|
2009-02-05 15:54:01 +00:00
|
|
|
if (caps) {
|
|
|
|
GstCaps *temp;
|
|
|
|
const GstCaps *templ;
|
|
|
|
|
|
|
|
/* filtered against our padtemplate */
|
|
|
|
templ = gst_pad_get_pad_template_caps (otherpad);
|
|
|
|
temp = gst_caps_intersect (caps, templ);
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
/* this is what we can do */
|
|
|
|
caps = temp;
|
|
|
|
} else {
|
|
|
|
/* no peer, our padtemplate is enough then */
|
|
|
|
caps = gst_caps_copy (gst_pad_get_pad_template_caps (pad));
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_object_unref (render);
|
|
|
|
|
|
|
|
return caps;
|
|
|
|
}
|
|
|
|
|
2009-12-07 14:31:41 +00:00
|
|
|
#define CREATE_RGB_BLIT_FUNCTION(name,bpp,R,G,B) \
|
|
|
|
static void \
|
2011-10-06 08:58:32 +00:00
|
|
|
blit_##name (GstAssRender * render, ASS_Image * ass_image, GstVideoFrame * frame) \
|
2009-12-07 14:31:41 +00:00
|
|
|
{ \
|
|
|
|
guint counter = 0; \
|
2009-12-08 10:26:02 +00:00
|
|
|
gint alpha, r, g, b, k; \
|
2009-12-07 14:31:41 +00:00
|
|
|
const guint8 *src; \
|
2011-10-06 08:58:32 +00:00
|
|
|
guint8 *dst, *data; \
|
2009-12-07 14:31:41 +00:00
|
|
|
gint x, y, w, h; \
|
2011-10-06 08:58:32 +00:00
|
|
|
gint width; \
|
|
|
|
gint height; \
|
|
|
|
gint dst_stride; \
|
2009-12-07 14:31:41 +00:00
|
|
|
gint dst_skip; \
|
2010-11-09 20:43:14 +00:00
|
|
|
gint src_skip; \
|
2009-12-07 14:31:41 +00:00
|
|
|
\
|
2011-10-06 08:58:32 +00:00
|
|
|
width = GST_VIDEO_FRAME_WIDTH (frame); \
|
|
|
|
height = GST_VIDEO_FRAME_HEIGHT (frame); \
|
|
|
|
dst_stride = GST_VIDEO_FRAME_PLANE_STRIDE (frame, 0); \
|
|
|
|
data = GST_VIDEO_FRAME_PLANE_DATA (frame, 0); \
|
|
|
|
\
|
2009-12-07 14:31:41 +00:00
|
|
|
while (ass_image) { \
|
|
|
|
if (ass_image->dst_y > height || ass_image->dst_x > width) \
|
|
|
|
goto next; \
|
|
|
|
\
|
|
|
|
/* blend subtitles onto the video frame */ \
|
|
|
|
alpha = 255 - ((ass_image->color) & 0xff); \
|
|
|
|
r = ((ass_image->color) >> 24) & 0xff; \
|
|
|
|
g = ((ass_image->color) >> 16) & 0xff; \
|
|
|
|
b = ((ass_image->color) >> 8) & 0xff; \
|
|
|
|
src = ass_image->bitmap; \
|
2011-10-06 08:58:32 +00:00
|
|
|
dst = data + ass_image->dst_y * dst_stride + ass_image->dst_x * bpp; \
|
2009-12-07 14:31:41 +00:00
|
|
|
\
|
|
|
|
w = MIN (ass_image->w, width - ass_image->dst_x); \
|
|
|
|
h = MIN (ass_image->h, height - ass_image->dst_y); \
|
|
|
|
src_skip = ass_image->stride - w; \
|
|
|
|
dst_skip = dst_stride - w * bpp; \
|
|
|
|
\
|
|
|
|
for (y = 0; y < h; y++) { \
|
|
|
|
for (x = 0; x < w; x++) { \
|
2009-12-08 10:26:02 +00:00
|
|
|
k = src[0] * alpha / 255; \
|
2009-12-07 14:31:41 +00:00
|
|
|
dst[R] = (k * r + (255 - k) * dst[R]) / 255; \
|
|
|
|
dst[G] = (k * g + (255 - k) * dst[G]) / 255; \
|
|
|
|
dst[B] = (k * b + (255 - k) * dst[B]) / 255; \
|
|
|
|
src++; \
|
|
|
|
dst += bpp; \
|
|
|
|
} \
|
|
|
|
src += src_skip; \
|
|
|
|
dst += dst_skip; \
|
|
|
|
} \
|
|
|
|
next: \
|
|
|
|
counter++; \
|
|
|
|
ass_image = ass_image->next; \
|
|
|
|
} \
|
|
|
|
GST_LOG_OBJECT (render, "amount of rendered ass_image: %u", counter); \
|
|
|
|
}
|
|
|
|
|
|
|
|
CREATE_RGB_BLIT_FUNCTION (rgb, 3, 0, 1, 2);
|
|
|
|
CREATE_RGB_BLIT_FUNCTION (bgr, 3, 2, 1, 0);
|
|
|
|
CREATE_RGB_BLIT_FUNCTION (xrgb, 4, 1, 2, 3);
|
|
|
|
CREATE_RGB_BLIT_FUNCTION (xbgr, 4, 3, 2, 1);
|
|
|
|
CREATE_RGB_BLIT_FUNCTION (rgbx, 4, 0, 1, 2);
|
|
|
|
CREATE_RGB_BLIT_FUNCTION (bgrx, 4, 2, 1, 0);
|
|
|
|
|
|
|
|
#undef CREATE_RGB_BLIT_FUNCTION
|
|
|
|
|
2009-12-08 10:26:02 +00:00
|
|
|
static inline gint
|
|
|
|
rgb_to_y (gint r, gint g, gint b)
|
|
|
|
{
|
|
|
|
gint ret;
|
|
|
|
|
|
|
|
ret = (gint) (((19595 * r) >> 16) + ((38470 * g) >> 16) + ((7471 * b) >> 16));
|
|
|
|
ret = CLAMP (ret, 0, 255);
|
|
|
|
return ret;
|
2009-12-07 16:04:04 +00:00
|
|
|
}
|
|
|
|
|
2009-12-08 10:26:02 +00:00
|
|
|
static inline gint
|
|
|
|
rgb_to_u (gint r, gint g, gint b)
|
|
|
|
{
|
|
|
|
gint ret;
|
|
|
|
|
|
|
|
ret =
|
|
|
|
(gint) (-((11059 * r) >> 16) - ((21709 * g) >> 16) + ((32768 * b) >> 16) +
|
|
|
|
128);
|
|
|
|
ret = CLAMP (ret, 0, 255);
|
|
|
|
return ret;
|
2009-12-07 16:04:04 +00:00
|
|
|
}
|
|
|
|
|
2009-12-08 10:26:02 +00:00
|
|
|
static inline gint
|
|
|
|
rgb_to_v (gint r, gint g, gint b)
|
|
|
|
{
|
|
|
|
gint ret;
|
|
|
|
|
|
|
|
ret =
|
|
|
|
(gint) (((32768 * r) >> 16) - ((27439 * g) >> 16) - ((5329 * b) >> 16) +
|
|
|
|
128);
|
|
|
|
ret = CLAMP (ret, 0, 255);
|
|
|
|
return ret;
|
2009-12-07 16:04:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-10-06 08:58:32 +00:00
|
|
|
blit_i420 (GstAssRender * render, ASS_Image * ass_image, GstVideoFrame * frame)
|
2009-12-07 16:04:04 +00:00
|
|
|
{
|
|
|
|
guint counter = 0;
|
2009-12-08 10:26:02 +00:00
|
|
|
gint alpha, r, g, b, k, k2;
|
|
|
|
gint Y, U, V;
|
2009-12-07 16:04:04 +00:00
|
|
|
const guint8 *src;
|
2009-12-08 10:26:02 +00:00
|
|
|
guint8 *dst_y, *dst_u, *dst_v;
|
2009-12-07 16:04:04 +00:00
|
|
|
gint x, y, w, h;
|
2011-07-18 18:53:31 +00:00
|
|
|
/* FIXME ignoring source image stride might be wrong here */
|
|
|
|
#if 0
|
2010-11-25 17:26:21 +00:00
|
|
|
gint w2;
|
2011-07-18 18:53:31 +00:00
|
|
|
gint src_stride;
|
|
|
|
#endif
|
2011-10-06 08:58:32 +00:00
|
|
|
gint width, height;
|
|
|
|
guint8 *y_data, *u_data, *v_data;
|
|
|
|
gint y_stride, u_stride, v_stride;
|
|
|
|
|
|
|
|
width = GST_VIDEO_FRAME_WIDTH (frame);
|
|
|
|
height = GST_VIDEO_FRAME_HEIGHT (frame);
|
|
|
|
|
|
|
|
y_data = GST_VIDEO_FRAME_COMP_DATA (frame, 0);
|
|
|
|
u_data = GST_VIDEO_FRAME_COMP_DATA (frame, 1);
|
|
|
|
v_data = GST_VIDEO_FRAME_COMP_DATA (frame, 2);
|
|
|
|
|
|
|
|
y_stride = GST_VIDEO_FRAME_COMP_STRIDE (frame, 0);
|
|
|
|
u_stride = GST_VIDEO_FRAME_COMP_STRIDE (frame, 1);
|
|
|
|
v_stride = GST_VIDEO_FRAME_COMP_STRIDE (frame, 2);
|
2009-12-07 16:04:04 +00:00
|
|
|
|
|
|
|
while (ass_image) {
|
|
|
|
if (ass_image->dst_y > height || ass_image->dst_x > width)
|
|
|
|
goto next;
|
|
|
|
|
|
|
|
/* blend subtitles onto the video frame */
|
|
|
|
alpha = 255 - ((ass_image->color) & 0xff);
|
|
|
|
r = ((ass_image->color) >> 24) & 0xff;
|
|
|
|
g = ((ass_image->color) >> 16) & 0xff;
|
|
|
|
b = ((ass_image->color) >> 8) & 0xff;
|
|
|
|
|
2009-12-08 10:26:02 +00:00
|
|
|
Y = rgb_to_y (r, g, b);
|
|
|
|
U = rgb_to_u (r, g, b);
|
|
|
|
V = rgb_to_v (r, g, b);
|
2009-12-07 16:04:04 +00:00
|
|
|
|
|
|
|
w = MIN (ass_image->w, width - ass_image->dst_x);
|
|
|
|
h = MIN (ass_image->h, height - ass_image->dst_y);
|
|
|
|
|
2011-07-18 18:53:31 +00:00
|
|
|
#if 0
|
2009-12-08 10:26:02 +00:00
|
|
|
w2 = (w + 1) / 2;
|
|
|
|
|
2009-12-07 16:04:04 +00:00
|
|
|
src_stride = ass_image->stride;
|
2011-07-18 18:53:31 +00:00
|
|
|
#endif
|
2009-12-07 16:04:04 +00:00
|
|
|
|
|
|
|
src = ass_image->bitmap;
|
2011-10-06 08:58:32 +00:00
|
|
|
#if 0
|
|
|
|
dst_y = y_data + ass_image->dst_y * y_stride + ass_image->dst_x;
|
|
|
|
dst_u = u_data + (ass_image->dst_y / 2) * u_stride + ass_image->dst_x / 2;
|
|
|
|
dst_v = v_data + (ass_image->dst_y / 2) * v_stride + ass_image->dst_x / 2;
|
|
|
|
#endif
|
2011-04-15 03:46:52 +00:00
|
|
|
|
|
|
|
for (y = 0; y < h; y++) {
|
2011-10-06 08:58:32 +00:00
|
|
|
dst_y = y_data + (ass_image->dst_y + y) * y_stride + ass_image->dst_x;
|
2011-04-15 03:46:52 +00:00
|
|
|
for (x = 0; x < w; x++) {
|
|
|
|
k = src[y * ass_image->w + x] * alpha / 255;
|
|
|
|
dst_y[x] = (k * Y + (255 - k) * dst_y[x]) / 255;
|
|
|
|
}
|
|
|
|
}
|
2009-12-08 10:26:02 +00:00
|
|
|
|
2011-04-15 03:46:52 +00:00
|
|
|
y = 0;
|
|
|
|
if (ass_image->dst_y & 1) {
|
2011-10-06 08:58:32 +00:00
|
|
|
dst_u = u_data + (ass_image->dst_y / 2) * u_stride + ass_image->dst_x / 2;
|
|
|
|
dst_v = v_data + (ass_image->dst_y / 2) * v_stride + ass_image->dst_x / 2;
|
2011-04-15 03:46:52 +00:00
|
|
|
x = 0;
|
|
|
|
if (ass_image->dst_x & 1) {
|
|
|
|
k2 = src[y * ass_image->w + x] * alpha / 255;
|
|
|
|
k2 = (k2 + 2) >> 2;
|
|
|
|
dst_u[0] = (k2 * U + (255 - k2) * dst_u[0]) / 255;
|
|
|
|
dst_v[0] = (k2 * V + (255 - k2) * dst_v[0]) / 255;
|
|
|
|
x++;
|
|
|
|
dst_u++;
|
|
|
|
dst_v++;
|
|
|
|
}
|
|
|
|
for (; x < w - 1; x += 2) {
|
|
|
|
k2 = src[y * ass_image->w + x] * alpha / 255;
|
|
|
|
k2 += src[y * ass_image->w + x + 1] * alpha / 255;
|
|
|
|
k2 = (k2 + 2) >> 2;
|
2009-12-08 10:26:02 +00:00
|
|
|
dst_u[0] = (k2 * U + (255 - k2) * dst_u[0]) / 255;
|
|
|
|
dst_v[0] = (k2 * V + (255 - k2) * dst_v[0]) / 255;
|
|
|
|
dst_u++;
|
|
|
|
dst_v++;
|
2009-12-07 16:04:04 +00:00
|
|
|
}
|
2009-12-08 10:26:02 +00:00
|
|
|
if (x < w) {
|
2011-04-15 03:46:52 +00:00
|
|
|
k2 = src[y * ass_image->w + x] * alpha / 255;
|
|
|
|
k2 = (k2 + 2) >> 2;
|
|
|
|
dst_u[0] = (k2 * U + (255 - k2) * dst_u[0]) / 255;
|
|
|
|
dst_v[0] = (k2 * V + (255 - k2) * dst_v[0]) / 255;
|
|
|
|
}
|
|
|
|
}
|
2009-12-08 10:26:02 +00:00
|
|
|
|
2011-04-15 03:46:52 +00:00
|
|
|
for (; y < h - 1; y += 2) {
|
2011-10-06 08:58:32 +00:00
|
|
|
dst_u = u_data + ((ass_image->dst_y + y) / 2) * u_stride +
|
2011-04-15 03:46:52 +00:00
|
|
|
ass_image->dst_x / 2;
|
2011-10-06 08:58:32 +00:00
|
|
|
dst_v = v_data + ((ass_image->dst_y + y) / 2) * v_stride +
|
2011-04-15 03:46:52 +00:00
|
|
|
ass_image->dst_x / 2;
|
|
|
|
x = 0;
|
|
|
|
if (ass_image->dst_x & 1) {
|
|
|
|
k2 = src[y * ass_image->w + x] * alpha / 255;
|
|
|
|
k2 += src[(y + 1) * ass_image->w + x] * alpha / 255;
|
|
|
|
k2 = (k2 + 2) >> 2;
|
2009-12-08 10:26:02 +00:00
|
|
|
dst_u[0] = (k2 * U + (255 - k2) * dst_u[0]) / 255;
|
|
|
|
dst_v[0] = (k2 * V + (255 - k2) * dst_v[0]) / 255;
|
2011-04-15 03:46:52 +00:00
|
|
|
x++;
|
2009-12-08 10:26:02 +00:00
|
|
|
dst_u++;
|
|
|
|
dst_v++;
|
2009-12-07 16:04:04 +00:00
|
|
|
}
|
2011-04-15 03:46:52 +00:00
|
|
|
for (; x < w - 1; x += 2) {
|
|
|
|
k2 = src[y * ass_image->w + x] * alpha / 255;
|
|
|
|
k2 += src[y * ass_image->w + x + 1] * alpha / 255;
|
|
|
|
k2 += src[(y + 1) * ass_image->w + x] * alpha / 255;
|
|
|
|
k2 += src[(y + 1) * ass_image->w + x + 1] * alpha / 255;
|
|
|
|
k2 = (k2 + 2) >> 2;
|
|
|
|
dst_u[0] = (k2 * U + (255 - k2) * dst_u[0]) / 255;
|
|
|
|
dst_v[0] = (k2 * V + (255 - k2) * dst_v[0]) / 255;
|
|
|
|
dst_u++;
|
|
|
|
dst_v++;
|
|
|
|
}
|
|
|
|
if (x < w) {
|
|
|
|
k2 = src[y * ass_image->w + x] * alpha / 255;
|
|
|
|
k2 += src[(y + 1) * ass_image->w + x] * alpha / 255;
|
|
|
|
k2 = (k2 + 2) >> 2;
|
|
|
|
dst_u[0] = (k2 * U + (255 - k2) * dst_u[0]) / 255;
|
|
|
|
dst_v[0] = (k2 * V + (255 - k2) * dst_v[0]) / 255;
|
|
|
|
}
|
2009-12-07 16:04:04 +00:00
|
|
|
}
|
2009-12-08 10:26:02 +00:00
|
|
|
|
|
|
|
if (y < h) {
|
2011-10-06 08:58:32 +00:00
|
|
|
dst_u = u_data + (ass_image->dst_y / 2) * u_stride + ass_image->dst_x / 2;
|
|
|
|
dst_v = v_data + (ass_image->dst_y / 2) * v_stride + ass_image->dst_x / 2;
|
2011-04-15 03:46:52 +00:00
|
|
|
x = 0;
|
|
|
|
if (ass_image->dst_x & 1) {
|
|
|
|
k2 = src[y * ass_image->w + x] * alpha / 255;
|
|
|
|
k2 = (k2 + 2) >> 2;
|
|
|
|
dst_u[0] = (k2 * U + (255 - k2) * dst_u[0]) / 255;
|
|
|
|
dst_v[0] = (k2 * V + (255 - k2) * dst_v[0]) / 255;
|
|
|
|
x++;
|
|
|
|
dst_u++;
|
|
|
|
dst_v++;
|
|
|
|
}
|
|
|
|
for (; x < w - 1; x += 2) {
|
|
|
|
k2 = src[y * ass_image->w + x] * alpha / 255;
|
|
|
|
k2 += src[y * ass_image->w + x + 1] * alpha / 255;
|
|
|
|
k2 = (k2 + 2) >> 2;
|
2009-12-08 10:26:02 +00:00
|
|
|
dst_u[0] = (k2 * U + (255 - k2) * dst_u[0]) / 255;
|
|
|
|
dst_v[0] = (k2 * V + (255 - k2) * dst_v[0]) / 255;
|
|
|
|
dst_u++;
|
|
|
|
dst_v++;
|
|
|
|
}
|
|
|
|
if (x < w) {
|
2011-04-15 03:46:52 +00:00
|
|
|
k2 = src[y * ass_image->w + x] * alpha / 255;
|
|
|
|
k2 = (k2 + 2) >> 2;
|
2009-12-08 10:26:02 +00:00
|
|
|
dst_u[0] = (k2 * U + (255 - k2) * dst_u[0]) / 255;
|
|
|
|
dst_v[0] = (k2 * V + (255 - k2) * dst_v[0]) / 255;
|
2009-12-07 16:04:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-15 03:46:52 +00:00
|
|
|
|
|
|
|
|
2009-12-07 16:04:04 +00:00
|
|
|
next:
|
|
|
|
counter++;
|
|
|
|
ass_image = ass_image->next;
|
|
|
|
}
|
2009-12-08 10:26:02 +00:00
|
|
|
|
2009-12-07 16:04:04 +00:00
|
|
|
GST_LOG_OBJECT (render, "amount of rendered ass_image: %u", counter);
|
|
|
|
}
|
|
|
|
|
2009-02-05 15:54:01 +00:00
|
|
|
static gboolean
|
2009-12-07 13:05:22 +00:00
|
|
|
gst_ass_render_setcaps_video (GstPad * pad, GstCaps * caps)
|
2009-02-05 15:54:01 +00:00
|
|
|
{
|
2009-12-07 13:05:22 +00:00
|
|
|
GstAssRender *render = GST_ASS_RENDER (gst_pad_get_parent (pad));
|
2009-02-05 15:54:01 +00:00
|
|
|
gboolean ret = FALSE;
|
2009-02-05 16:42:37 +00:00
|
|
|
gint par_n = 1, par_d = 1;
|
2009-12-07 14:31:41 +00:00
|
|
|
gdouble dar;
|
2011-10-06 08:58:32 +00:00
|
|
|
GstVideoInfo info;
|
2009-02-05 15:54:01 +00:00
|
|
|
|
2011-10-06 08:58:32 +00:00
|
|
|
if (!gst_video_info_from_caps (&info, caps))
|
|
|
|
goto invalid_caps;
|
2009-02-05 15:54:01 +00:00
|
|
|
|
2011-10-06 08:58:32 +00:00
|
|
|
render->info = info;
|
2009-02-05 15:54:01 +00:00
|
|
|
|
2009-12-07 14:31:41 +00:00
|
|
|
ret = gst_pad_set_caps (render->srcpad, caps);
|
|
|
|
if (!ret)
|
|
|
|
goto out;
|
2009-08-31 07:11:34 +00:00
|
|
|
|
2011-10-06 08:58:32 +00:00
|
|
|
switch (GST_VIDEO_INFO_FORMAT (&info)) {
|
2009-12-07 14:31:41 +00:00
|
|
|
case GST_VIDEO_FORMAT_RGB:
|
|
|
|
render->blit = blit_rgb;
|
|
|
|
break;
|
|
|
|
case GST_VIDEO_FORMAT_BGR:
|
|
|
|
render->blit = blit_bgr;
|
|
|
|
break;
|
|
|
|
case GST_VIDEO_FORMAT_xRGB:
|
|
|
|
render->blit = blit_xrgb;
|
|
|
|
break;
|
|
|
|
case GST_VIDEO_FORMAT_xBGR:
|
|
|
|
render->blit = blit_xbgr;
|
|
|
|
break;
|
|
|
|
case GST_VIDEO_FORMAT_RGBx:
|
|
|
|
render->blit = blit_rgbx;
|
|
|
|
break;
|
|
|
|
case GST_VIDEO_FORMAT_BGRx:
|
|
|
|
render->blit = blit_bgrx;
|
|
|
|
break;
|
2009-12-07 16:04:04 +00:00
|
|
|
case GST_VIDEO_FORMAT_I420:
|
|
|
|
render->blit = blit_i420;
|
|
|
|
break;
|
2009-12-07 14:31:41 +00:00
|
|
|
default:
|
|
|
|
ret = FALSE;
|
|
|
|
goto out;
|
|
|
|
}
|
2009-08-31 07:11:34 +00:00
|
|
|
|
2012-01-19 10:34:26 +00:00
|
|
|
g_mutex_lock (&render->ass_mutex);
|
2011-10-06 08:58:32 +00:00
|
|
|
ass_set_frame_size (render->ass_renderer, info.width, info.height);
|
2009-12-07 14:31:41 +00:00
|
|
|
|
2011-10-06 08:58:32 +00:00
|
|
|
dar = (((gdouble) par_n) * ((gdouble) info.width))
|
|
|
|
/ (((gdouble) par_d) * ((gdouble) info.height));
|
2009-09-07 15:33:15 +00:00
|
|
|
#if !defined(LIBASS_VERSION) || LIBASS_VERSION < 0x00907000
|
2009-12-07 14:31:41 +00:00
|
|
|
ass_set_aspect_ratio (render->ass_renderer, dar);
|
2009-08-31 07:11:34 +00:00
|
|
|
#else
|
2009-12-07 14:31:41 +00:00
|
|
|
ass_set_aspect_ratio (render->ass_renderer,
|
2011-10-06 08:58:32 +00:00
|
|
|
dar, ((gdouble) info.width) / ((gdouble) info.height));
|
2009-08-31 07:11:34 +00:00
|
|
|
#endif
|
2009-12-07 14:31:41 +00:00
|
|
|
ass_set_font_scale (render->ass_renderer, 1.0);
|
2010-02-02 00:44:20 +00:00
|
|
|
ass_set_hinting (render->ass_renderer, ASS_HINTING_LIGHT);
|
2009-08-31 07:11:34 +00:00
|
|
|
|
2009-09-07 15:33:15 +00:00
|
|
|
#if !defined(LIBASS_VERSION) || LIBASS_VERSION < 0x00907000
|
2009-12-07 14:31:41 +00:00
|
|
|
ass_set_fonts (render->ass_renderer, "Arial", "sans-serif");
|
|
|
|
ass_set_fonts (render->ass_renderer, NULL, "Sans");
|
2009-08-31 07:11:34 +00:00
|
|
|
#else
|
2009-12-07 14:31:41 +00:00
|
|
|
ass_set_fonts (render->ass_renderer, "Arial", "sans-serif", 1, NULL, 1);
|
|
|
|
ass_set_fonts (render->ass_renderer, NULL, "Sans", 1, NULL, 1);
|
2009-08-31 07:11:34 +00:00
|
|
|
#endif
|
2009-12-07 14:31:41 +00:00
|
|
|
ass_set_margins (render->ass_renderer, 0, 0, 0, 0);
|
|
|
|
ass_set_use_margins (render->ass_renderer, 0);
|
2012-01-19 10:34:26 +00:00
|
|
|
g_mutex_unlock (&render->ass_mutex);
|
2009-02-05 15:54:01 +00:00
|
|
|
|
2009-12-07 14:31:41 +00:00
|
|
|
render->renderer_init_ok = TRUE;
|
2009-02-05 15:54:01 +00:00
|
|
|
|
2009-12-07 14:31:41 +00:00
|
|
|
GST_DEBUG_OBJECT (render, "ass renderer setup complete");
|
2009-02-05 15:54:01 +00:00
|
|
|
|
2009-12-07 14:31:41 +00:00
|
|
|
out:
|
2009-02-05 15:54:01 +00:00
|
|
|
gst_object_unref (render);
|
|
|
|
|
|
|
|
return ret;
|
2011-10-06 08:58:32 +00:00
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
invalid_caps:
|
|
|
|
{
|
|
|
|
GST_ERROR_OBJECT (render, "Can't parse caps: %" GST_PTR_FORMAT, caps);
|
|
|
|
ret = FALSE;
|
|
|
|
goto out;
|
|
|
|
}
|
2009-02-05 15:54:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2009-12-07 13:05:22 +00:00
|
|
|
gst_ass_render_setcaps_text (GstPad * pad, GstCaps * caps)
|
2009-02-05 15:54:01 +00:00
|
|
|
{
|
2009-12-07 13:05:22 +00:00
|
|
|
GstAssRender *render = GST_ASS_RENDER (gst_pad_get_parent (pad));
|
2009-02-05 15:54:01 +00:00
|
|
|
GstStructure *structure;
|
|
|
|
const GValue *value;
|
|
|
|
GstBuffer *priv;
|
2012-01-25 17:49:58 +00:00
|
|
|
GstMapInfo map;
|
2009-02-05 15:54:01 +00:00
|
|
|
gboolean ret = FALSE;
|
|
|
|
|
|
|
|
structure = gst_caps_get_structure (caps, 0);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (render, "text pad linked with caps: %" GST_PTR_FORMAT,
|
|
|
|
caps);
|
|
|
|
|
2009-02-05 16:42:37 +00:00
|
|
|
value = gst_structure_get_value (structure, "codec_data");
|
2009-02-05 15:54:01 +00:00
|
|
|
|
2012-01-19 10:34:26 +00:00
|
|
|
g_mutex_lock (&render->ass_mutex);
|
2009-02-05 16:42:37 +00:00
|
|
|
if (value != NULL) {
|
2009-12-07 13:05:22 +00:00
|
|
|
priv = gst_value_get_buffer (value);
|
2009-02-05 16:42:37 +00:00
|
|
|
g_return_val_if_fail (priv != NULL, FALSE);
|
2009-02-05 15:54:01 +00:00
|
|
|
|
2012-01-25 17:49:58 +00:00
|
|
|
gst_buffer_map (priv, &map, GST_MAP_READ);
|
2009-02-05 15:54:01 +00:00
|
|
|
|
2009-12-07 13:23:22 +00:00
|
|
|
if (!render->ass_track)
|
|
|
|
render->ass_track = ass_new_track (render->ass_library);
|
2009-02-05 15:54:01 +00:00
|
|
|
|
2012-01-25 17:49:58 +00:00
|
|
|
ass_process_codec_private (render->ass_track, (char *) map.data, map.size);
|
2009-02-05 15:54:01 +00:00
|
|
|
|
2012-01-25 17:49:58 +00:00
|
|
|
gst_buffer_unmap (priv, &map);
|
2011-10-06 08:58:32 +00:00
|
|
|
|
2009-02-05 16:42:37 +00:00
|
|
|
GST_DEBUG_OBJECT (render, "ass track created");
|
2009-02-05 15:54:01 +00:00
|
|
|
|
2009-02-05 16:42:37 +00:00
|
|
|
render->track_init_ok = TRUE;
|
2009-02-05 15:54:01 +00:00
|
|
|
|
2009-02-05 16:42:37 +00:00
|
|
|
ret = TRUE;
|
|
|
|
} else if (!render->ass_track) {
|
|
|
|
render->ass_track = ass_new_track (render->ass_library);
|
2010-02-16 21:22:39 +00:00
|
|
|
|
|
|
|
render->track_init_ok = TRUE;
|
|
|
|
|
2009-02-05 16:42:37 +00:00
|
|
|
ret = TRUE;
|
2009-02-05 15:54:01 +00:00
|
|
|
}
|
2012-01-19 10:34:26 +00:00
|
|
|
g_mutex_unlock (&render->ass_mutex);
|
2009-02-05 15:54:01 +00:00
|
|
|
|
|
|
|
gst_object_unref (render);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-11-04 11:50:18 +00:00
|
|
|
|
|
|
|
static void
|
2009-12-07 13:05:22 +00:00
|
|
|
gst_ass_render_process_text (GstAssRender * render, GstBuffer * buffer,
|
2009-11-05 16:06:18 +00:00
|
|
|
GstClockTime running_time, GstClockTime duration)
|
2009-11-04 11:50:18 +00:00
|
|
|
{
|
2012-01-25 17:49:58 +00:00
|
|
|
GstMapInfo map;
|
2009-12-07 13:05:22 +00:00
|
|
|
gdouble pts_start, pts_end;
|
2009-11-04 11:50:18 +00:00
|
|
|
|
2009-11-05 16:06:18 +00:00
|
|
|
pts_start = running_time;
|
2009-11-04 11:50:18 +00:00
|
|
|
pts_start /= GST_MSECOND;
|
2009-11-05 16:06:18 +00:00
|
|
|
pts_end = duration;
|
2009-11-04 11:50:18 +00:00
|
|
|
pts_end /= GST_MSECOND;
|
|
|
|
|
2009-11-05 16:06:18 +00:00
|
|
|
GST_DEBUG_OBJECT (render,
|
|
|
|
"Processing subtitles with running time %" GST_TIME_FORMAT
|
|
|
|
" and duration %" GST_TIME_FORMAT, GST_TIME_ARGS (running_time),
|
|
|
|
GST_TIME_ARGS (duration));
|
2011-10-06 08:58:32 +00:00
|
|
|
|
2012-01-25 17:49:58 +00:00
|
|
|
gst_buffer_map (buffer, &map, GST_MAP_READ);
|
2011-10-06 08:58:32 +00:00
|
|
|
|
2012-01-19 10:34:26 +00:00
|
|
|
g_mutex_lock (&render->ass_mutex);
|
2012-01-25 17:49:58 +00:00
|
|
|
ass_process_chunk (render->ass_track, (gchar *) map.data, map.size,
|
|
|
|
pts_start, pts_end);
|
2012-01-19 10:34:26 +00:00
|
|
|
g_mutex_unlock (&render->ass_mutex);
|
2009-12-09 08:55:32 +00:00
|
|
|
|
2012-01-25 17:49:58 +00:00
|
|
|
gst_buffer_unmap (buffer, &map);
|
2011-10-06 08:58:32 +00:00
|
|
|
gst_buffer_unref (buffer);
|
2009-12-09 08:55:32 +00:00
|
|
|
}
|
|
|
|
|
2009-02-05 15:54:01 +00:00
|
|
|
static GstFlowReturn
|
2011-11-17 14:53:42 +00:00
|
|
|
gst_ass_render_chain_video (GstPad * pad, GstObject * parent,
|
|
|
|
GstBuffer * buffer)
|
2009-02-05 15:54:01 +00:00
|
|
|
{
|
2011-11-17 14:53:42 +00:00
|
|
|
GstAssRender *render = GST_ASS_RENDER (parent);
|
2009-02-05 15:54:01 +00:00
|
|
|
GstFlowReturn ret = GST_FLOW_OK;
|
|
|
|
gboolean in_seg = FALSE;
|
2011-10-06 08:58:32 +00:00
|
|
|
guint64 start, stop, clip_start = 0, clip_stop = 0;
|
2009-08-31 07:11:34 +00:00
|
|
|
ASS_Image *ass_image;
|
2009-02-05 15:54:01 +00:00
|
|
|
|
|
|
|
if (!GST_BUFFER_TIMESTAMP_IS_VALID (buffer)) {
|
|
|
|
GST_WARNING_OBJECT (render, "buffer without timestamp, discarding");
|
|
|
|
gst_buffer_unref (buffer);
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ignore buffers that are outside of the current segment */
|
|
|
|
start = GST_BUFFER_TIMESTAMP (buffer);
|
|
|
|
|
|
|
|
if (!GST_BUFFER_DURATION_IS_VALID (buffer)) {
|
|
|
|
stop = GST_CLOCK_TIME_NONE;
|
|
|
|
} else {
|
|
|
|
stop = start + GST_BUFFER_DURATION (buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* segment_clip() will adjust start unconditionally to segment_start if
|
|
|
|
* no stop time is provided, so handle this ourselves */
|
2009-02-05 16:42:37 +00:00
|
|
|
if (stop == GST_CLOCK_TIME_NONE && start < render->video_segment.start)
|
2009-02-05 15:54:01 +00:00
|
|
|
goto out_of_segment;
|
|
|
|
|
|
|
|
in_seg =
|
2009-02-05 16:42:37 +00:00
|
|
|
gst_segment_clip (&render->video_segment, GST_FORMAT_TIME, start, stop,
|
2009-02-05 15:54:01 +00:00
|
|
|
&clip_start, &clip_stop);
|
|
|
|
|
|
|
|
if (!in_seg)
|
|
|
|
goto out_of_segment;
|
|
|
|
|
|
|
|
/* if the buffer is only partially in the segment, fix up stamps */
|
|
|
|
if (clip_start != start || (stop != -1 && clip_stop != stop)) {
|
|
|
|
GST_DEBUG_OBJECT (render, "clipping buffer timestamp/duration to segment");
|
2011-10-06 08:58:32 +00:00
|
|
|
buffer = gst_buffer_make_writable (buffer);
|
2009-02-05 15:54:01 +00:00
|
|
|
GST_BUFFER_TIMESTAMP (buffer) = clip_start;
|
|
|
|
if (stop != -1)
|
|
|
|
GST_BUFFER_DURATION (buffer) = clip_stop - clip_start;
|
|
|
|
}
|
|
|
|
|
2011-10-06 08:58:32 +00:00
|
|
|
render->video_segment.position = clip_start;
|
2009-02-05 15:54:01 +00:00
|
|
|
|
2012-01-19 10:34:26 +00:00
|
|
|
g_mutex_lock (&render->subtitle_mutex);
|
2009-11-04 11:50:18 +00:00
|
|
|
if (render->subtitle_pending) {
|
2009-11-05 16:06:18 +00:00
|
|
|
GstClockTime sub_running_time, vid_running_time;
|
2009-11-06 10:44:50 +00:00
|
|
|
GstClockTime sub_running_time_end, vid_running_time_end;
|
2009-11-05 16:06:18 +00:00
|
|
|
|
|
|
|
sub_running_time =
|
|
|
|
gst_segment_to_running_time (&render->subtitle_segment, GST_FORMAT_TIME,
|
|
|
|
GST_BUFFER_TIMESTAMP (render->subtitle_pending));
|
2009-11-06 10:44:50 +00:00
|
|
|
sub_running_time_end =
|
|
|
|
gst_segment_to_running_time (&render->subtitle_segment, GST_FORMAT_TIME,
|
|
|
|
GST_BUFFER_TIMESTAMP (render->subtitle_pending) +
|
|
|
|
GST_BUFFER_DURATION (render->subtitle_pending));
|
2009-11-05 16:06:18 +00:00
|
|
|
vid_running_time =
|
|
|
|
gst_segment_to_running_time (&render->video_segment, GST_FORMAT_TIME,
|
|
|
|
GST_BUFFER_TIMESTAMP (buffer));
|
2009-11-06 10:44:50 +00:00
|
|
|
vid_running_time_end =
|
|
|
|
gst_segment_to_running_time (&render->video_segment, GST_FORMAT_TIME,
|
|
|
|
GST_BUFFER_TIMESTAMP (buffer) + GST_BUFFER_DURATION (buffer));
|
2009-11-05 16:06:18 +00:00
|
|
|
|
2010-02-27 10:23:14 +00:00
|
|
|
if (sub_running_time_end < vid_running_time) {
|
2009-11-04 11:50:18 +00:00
|
|
|
gst_buffer_unref (render->subtitle_pending);
|
2009-11-06 10:44:50 +00:00
|
|
|
GST_DEBUG_OBJECT (render,
|
|
|
|
"Too late text buffer, dropping (%" GST_TIME_FORMAT " < %"
|
|
|
|
GST_TIME_FORMAT, GST_TIME_ARGS (sub_running_time_end),
|
|
|
|
GST_TIME_ARGS (vid_running_time));
|
2009-11-04 11:50:18 +00:00
|
|
|
render->subtitle_pending = NULL;
|
2012-01-19 10:34:26 +00:00
|
|
|
g_cond_signal (&render->subtitle_cond);
|
2010-02-27 10:23:14 +00:00
|
|
|
} else if (sub_running_time <= vid_running_time_end + GST_SECOND / 2) {
|
|
|
|
gst_ass_render_process_text (render, render->subtitle_pending,
|
|
|
|
sub_running_time, sub_running_time_end - sub_running_time);
|
|
|
|
render->subtitle_pending = NULL;
|
2012-01-19 10:34:26 +00:00
|
|
|
g_cond_signal (&render->subtitle_cond);
|
2009-11-04 11:50:18 +00:00
|
|
|
}
|
|
|
|
}
|
2012-01-19 10:34:26 +00:00
|
|
|
g_mutex_unlock (&render->subtitle_mutex);
|
2009-11-04 11:50:18 +00:00
|
|
|
|
2009-02-05 15:54:01 +00:00
|
|
|
/* now start rendering subtitles, if all conditions are met */
|
|
|
|
if (render->renderer_init_ok && render->track_init_ok && render->enable) {
|
2009-11-05 16:06:18 +00:00
|
|
|
GstClockTime running_time;
|
2009-12-07 13:05:22 +00:00
|
|
|
gdouble timestamp;
|
|
|
|
#ifndef GST_DISABLE_GST_DEBUG
|
|
|
|
gdouble step;
|
|
|
|
#endif
|
2009-11-05 16:06:18 +00:00
|
|
|
|
|
|
|
running_time =
|
|
|
|
gst_segment_to_running_time (&render->video_segment, GST_FORMAT_TIME,
|
|
|
|
GST_BUFFER_TIMESTAMP (buffer));
|
|
|
|
GST_DEBUG_OBJECT (render,
|
|
|
|
"rendering frame for running time %" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (running_time));
|
2009-02-05 15:54:01 +00:00
|
|
|
/* libass needs timestamps in ms */
|
2009-11-05 16:06:18 +00:00
|
|
|
timestamp = running_time / GST_MSECOND;
|
2009-02-05 15:54:01 +00:00
|
|
|
|
2012-01-19 10:34:26 +00:00
|
|
|
g_mutex_lock (&render->ass_mutex);
|
2009-12-07 13:05:22 +00:00
|
|
|
#ifndef GST_DISABLE_GST_DEBUG
|
2009-02-05 15:54:01 +00:00
|
|
|
/* only for testing right now. could possibly be used for optimizations? */
|
|
|
|
step = ass_step_sub (render->ass_track, timestamp, 1);
|
2009-11-05 16:06:18 +00:00
|
|
|
GST_DEBUG_OBJECT (render, "Current running time: %" GST_TIME_FORMAT
|
2009-02-05 15:54:01 +00:00
|
|
|
" // Next event: %" GST_TIME_FORMAT,
|
2009-11-05 16:06:18 +00:00
|
|
|
GST_TIME_ARGS (running_time), GST_TIME_ARGS (step * GST_MSECOND));
|
2009-12-07 13:05:22 +00:00
|
|
|
#endif
|
2009-02-05 15:54:01 +00:00
|
|
|
|
|
|
|
/* not sure what the last parameter to this call is for (detect_change) */
|
|
|
|
ass_image = ass_render_frame (render->ass_renderer, render->ass_track,
|
2009-12-07 14:31:41 +00:00
|
|
|
timestamp, NULL);
|
2012-01-19 10:34:26 +00:00
|
|
|
g_mutex_unlock (&render->ass_mutex);
|
2009-02-05 15:54:01 +00:00
|
|
|
|
2010-01-14 11:59:21 +00:00
|
|
|
if (ass_image != NULL) {
|
2011-10-06 08:58:32 +00:00
|
|
|
GstVideoFrame frame;
|
|
|
|
|
2010-01-14 11:59:21 +00:00
|
|
|
buffer = gst_buffer_make_writable (buffer);
|
2011-10-06 08:58:32 +00:00
|
|
|
|
|
|
|
gst_video_frame_map (&frame, &render->info, buffer, GST_MAP_WRITE);
|
|
|
|
render->blit (render, ass_image, &frame);
|
|
|
|
gst_video_frame_unmap (&frame);
|
2010-01-14 11:59:21 +00:00
|
|
|
} else {
|
2009-02-05 15:54:01 +00:00
|
|
|
GST_LOG_OBJECT (render, "nothing to render right now");
|
|
|
|
}
|
2010-01-14 11:59:21 +00:00
|
|
|
} else {
|
|
|
|
GST_LOG_OBJECT (render, "rendering disabled, doing buffer passthrough");
|
2009-02-05 15:54:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = gst_pad_push (render->srcpad, buffer);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
out_of_segment:
|
|
|
|
{
|
|
|
|
GST_DEBUG_OBJECT (render, "buffer out of segment, discarding");
|
|
|
|
gst_buffer_unref (buffer);
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
2011-11-17 14:53:42 +00:00
|
|
|
gst_ass_render_chain_text (GstPad * pad, GstObject * parent, GstBuffer * buffer)
|
2009-02-05 15:54:01 +00:00
|
|
|
{
|
|
|
|
GstFlowReturn ret = GST_FLOW_OK;
|
2011-11-17 14:53:42 +00:00
|
|
|
GstAssRender *render = GST_ASS_RENDER (parent);
|
2009-11-05 12:17:27 +00:00
|
|
|
GstClockTime timestamp, duration;
|
2009-11-05 16:06:18 +00:00
|
|
|
GstClockTime sub_running_time, vid_running_time;
|
2009-11-06 10:44:50 +00:00
|
|
|
GstClockTime sub_running_time_end;
|
2011-10-06 08:58:32 +00:00
|
|
|
guint64 cstart, cstop;
|
2010-02-26 17:06:24 +00:00
|
|
|
gboolean in_seg;
|
2009-02-05 15:54:01 +00:00
|
|
|
|
2009-12-07 13:05:22 +00:00
|
|
|
if (render->subtitle_flushing) {
|
|
|
|
gst_buffer_unref (buffer);
|
2012-02-08 15:37:13 +00:00
|
|
|
return GST_FLOW_FLUSHING;
|
2009-12-07 13:05:22 +00:00
|
|
|
}
|
2009-11-04 12:11:44 +00:00
|
|
|
|
2009-11-04 11:50:18 +00:00
|
|
|
timestamp = GST_BUFFER_TIMESTAMP (buffer);
|
2009-11-05 12:17:27 +00:00
|
|
|
duration = GST_BUFFER_DURATION (buffer);
|
|
|
|
|
|
|
|
if (G_UNLIKELY (!GST_CLOCK_TIME_IS_VALID (timestamp)
|
|
|
|
|| !GST_CLOCK_TIME_IS_VALID (duration))) {
|
|
|
|
GST_WARNING_OBJECT (render,
|
|
|
|
"Text buffer without valid timestamp" " or duration, dropping");
|
|
|
|
gst_buffer_unref (buffer);
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
2009-02-05 15:54:01 +00:00
|
|
|
|
2010-02-26 17:06:24 +00:00
|
|
|
in_seg =
|
|
|
|
gst_segment_clip (&render->subtitle_segment, GST_FORMAT_TIME, timestamp,
|
|
|
|
timestamp + duration, &cstart, &cstop);
|
|
|
|
if (!in_seg) {
|
|
|
|
GST_DEBUG_OBJECT (render,
|
|
|
|
"Text buffer before segment start (%" GST_TIME_FORMAT " < %"
|
|
|
|
GST_TIME_FORMAT ")", GST_TIME_ARGS (timestamp),
|
|
|
|
GST_TIME_ARGS (render->subtitle_segment.start));
|
|
|
|
gst_buffer_unref (buffer);
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_BUFFER_TIMESTAMP (buffer) = timestamp = cstart;
|
|
|
|
GST_BUFFER_DURATION (buffer) = duration = cstop - cstart;
|
|
|
|
|
2011-10-06 08:58:32 +00:00
|
|
|
render->subtitle_segment.position = GST_BUFFER_TIMESTAMP (buffer);
|
2009-12-07 13:26:46 +00:00
|
|
|
|
2009-11-05 16:06:18 +00:00
|
|
|
sub_running_time =
|
|
|
|
gst_segment_to_running_time (&render->subtitle_segment, GST_FORMAT_TIME,
|
|
|
|
timestamp);
|
2009-11-06 10:44:50 +00:00
|
|
|
sub_running_time_end =
|
|
|
|
gst_segment_to_running_time (&render->subtitle_segment, GST_FORMAT_TIME,
|
|
|
|
timestamp + duration);
|
2009-11-05 16:06:18 +00:00
|
|
|
vid_running_time =
|
|
|
|
gst_segment_to_running_time (&render->video_segment, GST_FORMAT_TIME,
|
2011-10-06 08:58:32 +00:00
|
|
|
render->video_segment.position);
|
2009-11-05 16:06:18 +00:00
|
|
|
|
2011-10-06 08:58:32 +00:00
|
|
|
if (render->info.fps_n && render->info.fps_d)
|
2009-12-08 13:06:23 +00:00
|
|
|
vid_running_time +=
|
2011-10-06 08:58:32 +00:00
|
|
|
gst_util_uint64_scale (GST_SECOND, render->info.fps_d,
|
|
|
|
render->info.fps_n);
|
2009-12-08 13:06:23 +00:00
|
|
|
|
2010-02-27 10:23:14 +00:00
|
|
|
if (sub_running_time > vid_running_time + GST_SECOND / 2) {
|
2009-11-04 11:50:18 +00:00
|
|
|
g_assert (render->subtitle_pending == NULL);
|
2012-01-19 10:34:26 +00:00
|
|
|
g_mutex_lock (&render->subtitle_mutex);
|
2009-11-05 11:25:25 +00:00
|
|
|
if (G_UNLIKELY (render->subtitle_flushing)) {
|
|
|
|
GST_DEBUG_OBJECT (render, "Text pad flushing");
|
2011-10-18 13:41:48 +00:00
|
|
|
gst_buffer_unref (buffer);
|
2012-01-19 10:34:26 +00:00
|
|
|
g_mutex_unlock (&render->subtitle_mutex);
|
2012-02-08 15:37:13 +00:00
|
|
|
return GST_FLOW_FLUSHING;
|
2009-11-05 11:25:25 +00:00
|
|
|
}
|
2009-11-06 10:44:50 +00:00
|
|
|
GST_DEBUG_OBJECT (render,
|
|
|
|
"Too early text buffer, waiting (%" GST_TIME_FORMAT " > %"
|
|
|
|
GST_TIME_FORMAT, GST_TIME_ARGS (sub_running_time),
|
|
|
|
GST_TIME_ARGS (vid_running_time));
|
2009-11-04 11:50:18 +00:00
|
|
|
render->subtitle_pending = buffer;
|
2012-01-19 10:34:26 +00:00
|
|
|
g_cond_wait (&render->subtitle_cond, &render->subtitle_mutex);
|
|
|
|
g_mutex_unlock (&render->subtitle_mutex);
|
2009-11-06 10:44:50 +00:00
|
|
|
} else if (sub_running_time_end < vid_running_time) {
|
|
|
|
GST_DEBUG_OBJECT (render,
|
|
|
|
"Too late text buffer, dropping (%" GST_TIME_FORMAT " < %"
|
|
|
|
GST_TIME_FORMAT, GST_TIME_ARGS (sub_running_time_end),
|
|
|
|
GST_TIME_ARGS (vid_running_time));
|
2009-11-05 12:17:27 +00:00
|
|
|
gst_buffer_unref (buffer);
|
|
|
|
ret = GST_FLOW_OK;
|
2009-11-04 11:50:18 +00:00
|
|
|
} else {
|
2009-12-07 13:05:22 +00:00
|
|
|
gst_ass_render_process_text (render, buffer, sub_running_time,
|
2009-11-06 10:44:50 +00:00
|
|
|
sub_running_time_end - sub_running_time);
|
2009-12-07 13:05:22 +00:00
|
|
|
ret = GST_FLOW_OK;
|
2009-11-04 11:50:18 +00:00
|
|
|
}
|
2009-02-05 15:54:01 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (render,
|
2009-11-05 12:17:27 +00:00
|
|
|
"processed text packet with timestamp %" GST_TIME_FORMAT
|
|
|
|
" and duration %" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (timestamp), GST_TIME_ARGS (duration));
|
2009-02-05 15:54:01 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-12-07 13:35:55 +00:00
|
|
|
static void
|
|
|
|
gst_ass_render_handle_tags (GstAssRender * render, GstTagList * taglist)
|
|
|
|
{
|
2011-10-06 08:58:32 +00:00
|
|
|
#if 0
|
2009-12-07 17:30:05 +00:00
|
|
|
static const gchar *mimetypes[] = {
|
|
|
|
"application/x-font-ttf",
|
|
|
|
"application/x-font-otf",
|
|
|
|
"application/x-truetype-font"
|
|
|
|
};
|
|
|
|
static const gchar *extensions[] = {
|
|
|
|
".otf",
|
|
|
|
".ttf"
|
|
|
|
};
|
2011-10-06 08:58:32 +00:00
|
|
|
#endif
|
2009-12-07 13:35:55 +00:00
|
|
|
guint tag_size;
|
|
|
|
|
|
|
|
if (!taglist)
|
|
|
|
return;
|
|
|
|
|
|
|
|
tag_size = gst_tag_list_get_tag_size (taglist, GST_TAG_ATTACHMENT);
|
|
|
|
if (tag_size > 0 && render->embeddedfonts) {
|
2011-10-27 14:23:10 +00:00
|
|
|
#if 0
|
2009-12-07 13:35:55 +00:00
|
|
|
const GValue *value;
|
|
|
|
GstBuffer *buf;
|
|
|
|
GstCaps *caps;
|
|
|
|
GstStructure *structure;
|
2009-12-07 17:30:05 +00:00
|
|
|
gboolean valid_mimetype, valid_extension;
|
|
|
|
guint j;
|
|
|
|
const gchar *filename;
|
2011-10-06 08:58:32 +00:00
|
|
|
#endif
|
|
|
|
guint index;
|
2009-12-07 13:35:55 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (render, "TAG event has attachments");
|
|
|
|
|
|
|
|
for (index = 0; index < tag_size; index++) {
|
2011-10-27 14:23:10 +00:00
|
|
|
#if 0
|
2009-12-07 13:35:55 +00:00
|
|
|
value = gst_tag_list_get_value_index (taglist, GST_TAG_ATTACHMENT, index);
|
|
|
|
buf = gst_value_get_buffer (value);
|
|
|
|
if (!buf || !GST_BUFFER_CAPS (buf))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
caps = GST_BUFFER_CAPS (buf);
|
|
|
|
structure = gst_caps_get_structure (caps, 0);
|
|
|
|
|
2009-12-07 17:30:05 +00:00
|
|
|
valid_mimetype = FALSE;
|
|
|
|
valid_extension = FALSE;
|
|
|
|
|
|
|
|
for (j = 0; j < G_N_ELEMENTS (mimetypes); j++) {
|
|
|
|
if (gst_structure_has_name (structure, mimetypes[j])) {
|
|
|
|
valid_mimetype = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
filename = gst_structure_get_string (structure, "filename");
|
|
|
|
if (!filename)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!valid_mimetype) {
|
|
|
|
guint len = strlen (filename);
|
|
|
|
const gchar *extension = filename + len - 4;
|
|
|
|
for (j = 0; j < G_N_ELEMENTS (extensions); j++) {
|
|
|
|
if (g_ascii_strcasecmp (extension, extensions[j]) == 0) {
|
|
|
|
valid_extension = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (valid_mimetype || valid_extension) {
|
2012-01-19 10:34:26 +00:00
|
|
|
g_mutex_lock (&render->ass_mutex);
|
2009-12-07 13:35:55 +00:00
|
|
|
ass_add_font (render->ass_library, (gchar *) filename,
|
|
|
|
(gchar *) GST_BUFFER_DATA (buf), GST_BUFFER_SIZE (buf));
|
|
|
|
GST_DEBUG_OBJECT (render, "registered new font %s", filename);
|
2012-01-19 10:34:26 +00:00
|
|
|
g_mutex_unlock (&render->ass_mutex);
|
2009-12-07 13:35:55 +00:00
|
|
|
}
|
2011-10-06 08:58:32 +00:00
|
|
|
#endif
|
2009-12-07 13:35:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-05 15:54:01 +00:00
|
|
|
static gboolean
|
2011-11-17 14:53:42 +00:00
|
|
|
gst_ass_render_event_video (GstPad * pad, GstObject * parent, GstEvent * event)
|
2009-02-05 15:54:01 +00:00
|
|
|
{
|
|
|
|
gboolean ret = FALSE;
|
2011-11-17 14:53:42 +00:00
|
|
|
GstAssRender *render = GST_ASS_RENDER (parent);
|
2009-02-05 15:54:01 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (pad, "received video event %s",
|
|
|
|
GST_EVENT_TYPE_NAME (event));
|
|
|
|
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
2011-10-06 08:58:32 +00:00
|
|
|
case GST_EVENT_CAPS:
|
2009-02-05 15:54:01 +00:00
|
|
|
{
|
2011-10-06 08:58:32 +00:00
|
|
|
GstCaps *caps;
|
|
|
|
|
|
|
|
gst_event_parse_caps (event, &caps);
|
|
|
|
ret = gst_ass_render_setcaps_video (pad, caps);
|
|
|
|
gst_event_unref (event);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GST_EVENT_SEGMENT:
|
|
|
|
{
|
|
|
|
GstSegment segment;
|
2009-02-05 15:54:01 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (render, "received new segment");
|
|
|
|
|
2011-10-06 08:58:32 +00:00
|
|
|
gst_event_copy_segment (event, &segment);
|
2009-02-05 15:54:01 +00:00
|
|
|
|
2011-10-06 08:58:32 +00:00
|
|
|
if (segment.format == GST_FORMAT_TIME) {
|
2009-02-05 15:54:01 +00:00
|
|
|
GST_DEBUG_OBJECT (render, "VIDEO SEGMENT now: %" GST_SEGMENT_FORMAT,
|
2009-02-05 16:42:37 +00:00
|
|
|
&render->video_segment);
|
2009-02-05 15:54:01 +00:00
|
|
|
|
2011-10-06 08:58:32 +00:00
|
|
|
render->video_segment = segment;
|
2009-11-05 16:41:53 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (render, "VIDEO SEGMENT after: %" GST_SEGMENT_FORMAT,
|
|
|
|
&render->video_segment);
|
2009-11-05 15:41:56 +00:00
|
|
|
ret = gst_pad_push_event (render->srcpad, event);
|
2009-02-05 15:54:01 +00:00
|
|
|
} else {
|
|
|
|
GST_ELEMENT_WARNING (render, STREAM, MUX, (NULL),
|
|
|
|
("received non-TIME newsegment event on video input"));
|
2009-11-05 15:41:56 +00:00
|
|
|
ret = FALSE;
|
|
|
|
gst_event_unref (event);
|
2009-02-05 15:54:01 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GST_EVENT_TAG:
|
|
|
|
{
|
2009-12-07 13:35:55 +00:00
|
|
|
GstTagList *taglist = NULL;
|
2009-02-05 15:54:01 +00:00
|
|
|
|
2009-02-05 15:57:55 +00:00
|
|
|
/* tag events may contain attachments which might be fonts */
|
|
|
|
GST_DEBUG_OBJECT (render, "got TAG event");
|
|
|
|
|
2009-02-05 15:54:01 +00:00
|
|
|
gst_event_parse_tag (event, &taglist);
|
2009-12-07 13:35:55 +00:00
|
|
|
gst_ass_render_handle_tags (render, taglist);
|
2009-12-07 13:05:22 +00:00
|
|
|
ret = gst_pad_push_event (render->srcpad, event);
|
2009-02-05 15:54:01 +00:00
|
|
|
break;
|
|
|
|
}
|
2009-11-06 06:12:03 +00:00
|
|
|
case GST_EVENT_FLUSH_STOP:
|
|
|
|
gst_segment_init (&render->video_segment, GST_FORMAT_TIME);
|
2009-02-05 15:54:01 +00:00
|
|
|
default:
|
2009-12-07 13:05:22 +00:00
|
|
|
ret = gst_pad_push_event (render->srcpad, event);
|
2009-02-05 15:54:01 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-11-15 15:34:13 +00:00
|
|
|
static gboolean
|
2011-11-16 16:28:10 +00:00
|
|
|
gst_ass_render_query_video (GstPad * pad, GstObject * parent, GstQuery * query)
|
2011-11-15 15:34:13 +00:00
|
|
|
{
|
|
|
|
gboolean res = FALSE;
|
|
|
|
|
|
|
|
switch (GST_QUERY_TYPE (query)) {
|
|
|
|
case GST_QUERY_CAPS:
|
|
|
|
{
|
|
|
|
GstCaps *filter, *caps;
|
|
|
|
|
|
|
|
gst_query_parse_caps (query, &filter);
|
|
|
|
caps = gst_ass_render_getcaps (pad, filter);
|
|
|
|
gst_query_set_caps_result (query, caps);
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
res = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
2011-11-16 16:28:10 +00:00
|
|
|
res = gst_pad_query_default (pad, parent, query);
|
2011-11-15 15:34:13 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2009-02-05 15:54:01 +00:00
|
|
|
static gboolean
|
2011-11-17 14:53:42 +00:00
|
|
|
gst_ass_render_event_text (GstPad * pad, GstObject * parent, GstEvent * event)
|
2009-02-05 15:54:01 +00:00
|
|
|
{
|
2009-12-07 13:05:22 +00:00
|
|
|
gint i;
|
2009-02-05 15:54:01 +00:00
|
|
|
gboolean ret = FALSE;
|
2011-11-17 14:53:42 +00:00
|
|
|
GstAssRender *render = GST_ASS_RENDER (parent);
|
2009-02-05 15:54:01 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (pad, "received text event %s", GST_EVENT_TYPE_NAME (event));
|
|
|
|
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
2011-10-06 08:58:32 +00:00
|
|
|
case GST_EVENT_CAPS:
|
|
|
|
{
|
|
|
|
GstCaps *caps;
|
|
|
|
|
|
|
|
gst_event_parse_caps (event, &caps);
|
|
|
|
ret = gst_ass_render_setcaps_text (pad, caps);
|
|
|
|
gst_event_unref (event);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GST_EVENT_SEGMENT:
|
2009-02-05 15:54:01 +00:00
|
|
|
{
|
2011-10-06 08:58:32 +00:00
|
|
|
GstSegment segment;
|
2009-11-05 15:44:09 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (render, "received new segment");
|
|
|
|
|
2011-10-06 08:58:32 +00:00
|
|
|
gst_event_copy_segment (event, &segment);
|
2009-11-05 15:44:09 +00:00
|
|
|
|
2011-10-06 08:58:32 +00:00
|
|
|
if (segment.format == GST_FORMAT_TIME) {
|
2009-11-05 15:44:09 +00:00
|
|
|
GST_DEBUG_OBJECT (render, "SUBTITLE SEGMENT now: %" GST_SEGMENT_FORMAT,
|
|
|
|
&render->subtitle_segment);
|
|
|
|
|
2011-10-06 08:58:32 +00:00
|
|
|
render->subtitle_segment = segment;
|
2009-11-05 16:41:53 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (render,
|
|
|
|
"SUBTITLE SEGMENT after: %" GST_SEGMENT_FORMAT,
|
|
|
|
&render->subtitle_segment);
|
2009-11-05 15:44:09 +00:00
|
|
|
ret = TRUE;
|
|
|
|
gst_event_unref (event);
|
|
|
|
} else {
|
|
|
|
GST_ELEMENT_WARNING (render, STREAM, MUX, (NULL),
|
|
|
|
("received non-TIME newsegment event on subtitle input"));
|
|
|
|
ret = FALSE;
|
|
|
|
gst_event_unref (event);
|
|
|
|
}
|
2009-02-05 15:54:01 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GST_EVENT_FLUSH_STOP:
|
2009-11-06 06:12:03 +00:00
|
|
|
gst_segment_init (&render->subtitle_segment, GST_FORMAT_TIME);
|
2009-11-04 12:11:44 +00:00
|
|
|
render->subtitle_flushing = FALSE;
|
2009-02-05 15:54:01 +00:00
|
|
|
gst_event_unref (event);
|
|
|
|
ret = TRUE;
|
|
|
|
break;
|
|
|
|
case GST_EVENT_FLUSH_START:
|
|
|
|
GST_DEBUG_OBJECT (render, "begin flushing");
|
2012-01-19 10:34:26 +00:00
|
|
|
g_mutex_lock (&render->ass_mutex);
|
2009-02-05 15:54:01 +00:00
|
|
|
if (render->ass_track) {
|
|
|
|
/* delete any events on the ass_track */
|
|
|
|
for (i = 0; i < render->ass_track->n_events; i++) {
|
|
|
|
GST_DEBUG_OBJECT (render, "deleted event with eid %i", i);
|
|
|
|
ass_free_event (render->ass_track, i);
|
|
|
|
}
|
|
|
|
render->ass_track->n_events = 0;
|
|
|
|
GST_DEBUG_OBJECT (render, "done flushing");
|
|
|
|
}
|
2012-01-19 10:34:26 +00:00
|
|
|
g_mutex_unlock (&render->ass_mutex);
|
|
|
|
g_mutex_lock (&render->subtitle_mutex);
|
2009-11-04 12:07:27 +00:00
|
|
|
if (render->subtitle_pending)
|
|
|
|
gst_buffer_unref (render->subtitle_pending);
|
|
|
|
render->subtitle_pending = NULL;
|
2009-11-04 12:11:44 +00:00
|
|
|
render->subtitle_flushing = TRUE;
|
2012-01-19 10:34:26 +00:00
|
|
|
g_cond_signal (&render->subtitle_cond);
|
|
|
|
g_mutex_unlock (&render->subtitle_mutex);
|
2009-02-05 15:54:01 +00:00
|
|
|
gst_event_unref (event);
|
|
|
|
ret = TRUE;
|
|
|
|
break;
|
|
|
|
case GST_EVENT_EOS:
|
|
|
|
GST_OBJECT_LOCK (render);
|
|
|
|
GST_INFO_OBJECT (render, "text EOS");
|
|
|
|
GST_OBJECT_UNLOCK (render);
|
|
|
|
gst_event_unref (event);
|
|
|
|
ret = TRUE;
|
|
|
|
break;
|
|
|
|
case GST_EVENT_TAG:
|
|
|
|
{
|
2009-12-07 13:35:55 +00:00
|
|
|
GstTagList *taglist = NULL;
|
2009-02-05 15:54:01 +00:00
|
|
|
|
2009-12-07 13:35:55 +00:00
|
|
|
/* tag events may contain attachments which might be fonts */
|
2009-02-05 15:57:55 +00:00
|
|
|
GST_DEBUG_OBJECT (render, "got TAG event");
|
|
|
|
|
2009-02-05 15:54:01 +00:00
|
|
|
gst_event_parse_tag (event, &taglist);
|
2009-12-07 13:35:55 +00:00
|
|
|
gst_ass_render_handle_tags (render, taglist);
|
2009-12-07 13:05:22 +00:00
|
|
|
ret = gst_pad_push_event (render->srcpad, event);
|
2009-02-05 15:54:01 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
2009-12-07 13:05:22 +00:00
|
|
|
ret = gst_pad_push_event (render->srcpad, event);
|
2009-02-05 15:54:01 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
plugin_init (GstPlugin * plugin)
|
|
|
|
{
|
2009-12-07 13:05:22 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT (gst_ass_render_debug, "assrender",
|
2009-02-05 15:54:01 +00:00
|
|
|
0, "ASS/SSA subtitle renderer");
|
2009-12-07 13:05:22 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT (gst_ass_render_lib_debug, "assrender_library",
|
2009-12-07 12:26:39 +00:00
|
|
|
0, "ASS/SSA subtitle renderer library");
|
2009-02-05 15:54:01 +00:00
|
|
|
|
|
|
|
return gst_element_register (plugin, "assrender",
|
2009-12-07 13:05:22 +00:00
|
|
|
GST_RANK_PRIMARY, GST_TYPE_ASS_RENDER);
|
2009-02-05 15:54:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
|
|
|
|
GST_VERSION_MINOR,
|
|
|
|
"assrender",
|
|
|
|
"ASS/SSA subtitle renderer",
|
2009-02-05 16:42:37 +00:00
|
|
|
plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)
|