2010-11-29 20:06:07 +00:00
|
|
|
/* GStreamer DVB subtitles overlay
|
|
|
|
* Copyright (c) 2010 Mart Raudsepp <mart.raudsepp@collabora.co.uk>
|
2011-08-03 12:42:20 +00:00
|
|
|
* Copyright (c) 2010 ONELAN Ltd.
|
2010-11-29 20:06:07 +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
|
2012-11-03 20:38:00 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2010-11-29 20:06:07 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SECTION:element-dvbsuboverlay
|
|
|
|
*
|
|
|
|
* Renders DVB subtitles on top of a video stream.
|
|
|
|
*
|
|
|
|
* <refsect2>
|
|
|
|
* <title>Example launch line</title>
|
|
|
|
* |[ FIXME
|
|
|
|
* gst-launch -v filesrc location=/path/to/ts ! mpegtsdemux name=d ! queue ! mp3parse ! mad ! audioconvert ! autoaudiosink \
|
2011-10-10 08:15:05 +00:00
|
|
|
* d. ! queue ! mpeg2dec ! videoconvert ! r. \
|
|
|
|
* d. ! queue ! "subpicture/x-dvb" ! dvbsuboverlay name=r ! videoconvert ! autovideosink
|
2010-11-29 20:06:07 +00:00
|
|
|
* ]| This pipeline demuxes a MPEG-TS file with MPEG2 video, MP3 audio and embedded DVB subtitles and renders the subtitles on top of the video.
|
|
|
|
* </refsect2>
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
|
|
|
|
2012-01-27 14:49:58 +00:00
|
|
|
#include <gst/glib-compat-private.h>
|
2010-11-29 20:06:07 +00:00
|
|
|
#include "gstdvbsuboverlay.h"
|
|
|
|
|
2012-07-17 12:02:14 +00:00
|
|
|
#include <gst/video/gstvideometa.h>
|
|
|
|
|
2010-11-29 20:06:07 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_STATIC (gst_dvbsub_overlay_debug);
|
|
|
|
#define GST_CAT_DEFAULT gst_dvbsub_overlay_debug
|
|
|
|
|
|
|
|
/* Filter signals and props */
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
2010-12-14 13:28:45 +00:00
|
|
|
PROP_ENABLE,
|
|
|
|
PROP_MAX_PAGE_TIMEOUT,
|
2012-07-11 11:45:14 +00:00
|
|
|
PROP_FORCE_END
|
2010-11-29 20:06:07 +00:00
|
|
|
};
|
|
|
|
|
2010-12-15 19:53:21 +00:00
|
|
|
#define DEFAULT_ENABLE (TRUE)
|
|
|
|
#define DEFAULT_MAX_PAGE_TIMEOUT (0)
|
2012-07-11 11:45:14 +00:00
|
|
|
#define DEFAULT_FORCE_END (FALSE)
|
2010-12-15 19:53:21 +00:00
|
|
|
|
2013-02-19 13:00:01 +00:00
|
|
|
#define VIDEO_FORMATS GST_VIDEO_OVERLAY_COMPOSITION_BLEND_FORMATS
|
|
|
|
|
2014-03-16 16:36:06 +00:00
|
|
|
#define DVBSUB_OVERLAY_CAPS GST_VIDEO_CAPS_MAKE(VIDEO_FORMATS)
|
|
|
|
|
|
|
|
#define DVBSUB_OVERLAY_ALL_CAPS DVBSUB_OVERLAY_CAPS ";" \
|
|
|
|
GST_VIDEO_CAPS_MAKE_WITH_FEATURES ("ANY", GST_VIDEO_FORMATS_ALL)
|
|
|
|
|
|
|
|
static GstStaticCaps sw_template_caps = GST_STATIC_CAPS (DVBSUB_OVERLAY_CAPS);
|
|
|
|
|
2010-11-29 20:06:07 +00:00
|
|
|
static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
2014-03-16 16:36:06 +00:00
|
|
|
GST_STATIC_CAPS (DVBSUB_OVERLAY_ALL_CAPS)
|
2010-11-29 20:06:07 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
static GstStaticPadTemplate video_sink_factory =
|
2010-12-03 14:46:40 +00:00
|
|
|
GST_STATIC_PAD_TEMPLATE ("video_sink",
|
2010-11-29 20:06:07 +00:00
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
2014-03-16 16:36:06 +00:00
|
|
|
GST_STATIC_CAPS (DVBSUB_OVERLAY_ALL_CAPS)
|
2010-11-29 20:06:07 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
static GstStaticPadTemplate text_sink_factory =
|
|
|
|
GST_STATIC_PAD_TEMPLATE ("text_sink",
|
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
2010-12-15 20:11:29 +00:00
|
|
|
GST_STATIC_CAPS ("subpicture/x-dvb")
|
2010-11-29 20:06:07 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
static void gst_dvbsub_overlay_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_dvbsub_overlay_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec);
|
|
|
|
|
|
|
|
static void gst_dvbsub_overlay_finalize (GObject * object);
|
|
|
|
|
|
|
|
static GstStateChangeReturn gst_dvbsub_overlay_change_state (GstElement *
|
|
|
|
element, GstStateChange transition);
|
|
|
|
|
2011-10-10 08:15:05 +00:00
|
|
|
#define gst_dvbsub_overlay_parent_class parent_class
|
|
|
|
G_DEFINE_TYPE (GstDVBSubOverlay, gst_dvbsub_overlay, GST_TYPE_ELEMENT);
|
2010-11-29 20:06:07 +00:00
|
|
|
|
2014-03-16 16:36:06 +00:00
|
|
|
static GstCaps *gst_dvbsub_overlay_get_videosink_caps (GstDVBSubOverlay *
|
|
|
|
render, GstPad * pad, GstCaps * filter);
|
|
|
|
static GstCaps *gst_dvbsub_overlay_get_src_caps (GstDVBSubOverlay * render,
|
2012-09-12 13:08:01 +00:00
|
|
|
GstPad * pad, GstCaps * filter);
|
2010-11-29 20:06:07 +00:00
|
|
|
|
|
|
|
static GstFlowReturn gst_dvbsub_overlay_chain_video (GstPad * pad,
|
2011-11-17 14:53:42 +00:00
|
|
|
GstObject * parent, GstBuffer * buf);
|
2010-11-29 20:06:07 +00:00
|
|
|
static GstFlowReturn gst_dvbsub_overlay_chain_text (GstPad * pad,
|
2011-11-17 14:53:42 +00:00
|
|
|
GstObject * parent, GstBuffer * buf);
|
2010-11-29 20:06:07 +00:00
|
|
|
|
2011-11-17 14:53:42 +00:00
|
|
|
static gboolean gst_dvbsub_overlay_event_video (GstPad * pad,
|
|
|
|
GstObject * parent, GstEvent * event);
|
|
|
|
static gboolean gst_dvbsub_overlay_event_text (GstPad * pad, GstObject * parent,
|
|
|
|
GstEvent * event);
|
|
|
|
static gboolean gst_dvbsub_overlay_event_src (GstPad * pad, GstObject * parent,
|
|
|
|
GstEvent * event);
|
2010-11-29 20:06:07 +00:00
|
|
|
|
2010-12-01 03:26:02 +00:00
|
|
|
static void new_dvb_subtitles_cb (DvbSub * dvb_sub, DVBSubtitles * subs,
|
|
|
|
gpointer user_data);
|
2010-11-29 20:06:07 +00:00
|
|
|
|
2011-11-16 16:28:10 +00:00
|
|
|
static gboolean gst_dvbsub_overlay_query_video (GstPad * pad,
|
|
|
|
GstObject * parent, GstQuery * query);
|
|
|
|
static gboolean gst_dvbsub_overlay_query_src (GstPad * pad, GstObject * parent,
|
|
|
|
GstQuery * query);
|
2010-11-29 20:06:07 +00:00
|
|
|
|
|
|
|
/* initialize the plugin's class */
|
|
|
|
static void
|
|
|
|
gst_dvbsub_overlay_class_init (GstDVBSubOverlayClass * klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = (GObjectClass *) klass;
|
|
|
|
GstElementClass *gstelement_class = (GstElementClass *) klass;
|
|
|
|
|
|
|
|
gobject_class->set_property = gst_dvbsub_overlay_set_property;
|
|
|
|
gobject_class->get_property = gst_dvbsub_overlay_get_property;
|
|
|
|
gobject_class->finalize = gst_dvbsub_overlay_finalize;
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, PROP_ENABLE, g_param_spec_boolean ("enable", "Enable", /* FIXME: "enable" vs "silent"? */
|
2010-12-15 19:53:21 +00:00
|
|
|
"Enable rendering of subtitles", DEFAULT_ENABLE,
|
2010-11-29 20:06:07 +00:00
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2010-12-14 13:28:45 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_MAX_PAGE_TIMEOUT,
|
|
|
|
g_param_spec_int ("max-page-timeout", "max-page-timeout",
|
|
|
|
"Limit maximum display time of a subtitle page (0 - disabled, value in seconds)",
|
2010-12-15 19:53:21 +00:00
|
|
|
0, G_MAXINT, DEFAULT_MAX_PAGE_TIMEOUT,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2010-12-14 13:28:45 +00:00
|
|
|
|
2012-07-11 11:45:14 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_FORCE_END,
|
|
|
|
g_param_spec_boolean ("force-end", "Force End",
|
|
|
|
"Assume PES-aligned subtitles and force end-of-display",
|
|
|
|
DEFAULT_FORCE_END, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2010-11-29 20:06:07 +00:00
|
|
|
gstelement_class->change_state =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_dvbsub_overlay_change_state);
|
2011-10-10 08:15:05 +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));
|
|
|
|
|
2012-10-17 16:34:26 +00:00
|
|
|
gst_element_class_set_static_metadata (gstelement_class,
|
2011-10-10 08:15:05 +00:00
|
|
|
"DVB Subtitles Overlay",
|
|
|
|
"Mixer/Video/Overlay/Subtitle",
|
|
|
|
"Renders DVB subtitles", "Mart Raudsepp <mart.raudsepp@collabora.co.uk>");
|
2010-11-29 20:06:07 +00:00
|
|
|
}
|
|
|
|
|
2010-12-03 15:05:56 +00:00
|
|
|
static void
|
|
|
|
gst_dvbsub_overlay_flush_subtitles (GstDVBSubOverlay * render)
|
|
|
|
{
|
|
|
|
DVBSubtitles *subs;
|
|
|
|
|
2012-01-19 10:34:26 +00:00
|
|
|
g_mutex_lock (&render->dvbsub_mutex);
|
2010-12-03 15:05:56 +00:00
|
|
|
while ((subs = g_queue_pop_head (render->pending_subtitles))) {
|
|
|
|
dvb_subtitles_free (subs);
|
|
|
|
}
|
|
|
|
|
2011-01-04 13:51:21 +00:00
|
|
|
if (render->current_subtitle)
|
|
|
|
dvb_subtitles_free (render->current_subtitle);
|
|
|
|
render->current_subtitle = NULL;
|
|
|
|
|
2012-07-13 10:27:57 +00:00
|
|
|
if (render->current_comp)
|
|
|
|
gst_video_overlay_composition_unref (render->current_comp);
|
|
|
|
render->current_comp = NULL;
|
|
|
|
|
2010-12-03 15:05:56 +00:00
|
|
|
if (render->dvb_sub)
|
2010-12-24 14:24:12 +00:00
|
|
|
dvb_sub_free (render->dvb_sub);
|
|
|
|
|
2010-12-03 15:05:56 +00:00
|
|
|
render->dvb_sub = dvb_sub_new ();
|
|
|
|
|
|
|
|
{
|
|
|
|
DvbSubCallbacks dvbsub_callbacks = { &new_dvb_subtitles_cb, };
|
|
|
|
dvb_sub_set_callbacks (render->dvb_sub, &dvbsub_callbacks, render);
|
|
|
|
}
|
|
|
|
|
2012-07-11 11:45:14 +00:00
|
|
|
render->last_text_pts = GST_CLOCK_TIME_NONE;
|
|
|
|
render->pending_sub = FALSE;
|
|
|
|
|
2012-01-19 10:34:26 +00:00
|
|
|
g_mutex_unlock (&render->dvbsub_mutex);
|
2010-12-03 15:05:56 +00:00
|
|
|
}
|
|
|
|
|
2010-11-29 20:06:07 +00:00
|
|
|
static void
|
2011-10-10 08:15:05 +00:00
|
|
|
gst_dvbsub_overlay_init (GstDVBSubOverlay * render)
|
2010-11-29 20:06:07 +00:00
|
|
|
{
|
|
|
|
GST_DEBUG_OBJECT (render, "init");
|
|
|
|
|
|
|
|
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");
|
|
|
|
|
|
|
|
gst_pad_set_chain_function (render->video_sinkpad,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_dvbsub_overlay_chain_video));
|
|
|
|
gst_pad_set_chain_function (render->text_sinkpad,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_dvbsub_overlay_chain_text));
|
|
|
|
|
|
|
|
gst_pad_set_event_function (render->video_sinkpad,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_dvbsub_overlay_event_video));
|
|
|
|
gst_pad_set_event_function (render->text_sinkpad,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_dvbsub_overlay_event_text));
|
|
|
|
gst_pad_set_event_function (render->srcpad,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_dvbsub_overlay_event_src));
|
|
|
|
|
2011-11-15 15:34:13 +00:00
|
|
|
gst_pad_set_query_function (render->video_sinkpad,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_dvbsub_overlay_query_video));
|
2010-11-29 20:06:07 +00:00
|
|
|
gst_pad_set_query_function (render->srcpad,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_dvbsub_overlay_query_src));
|
|
|
|
|
2013-02-19 11:24:55 +00:00
|
|
|
GST_PAD_SET_PROXY_ALLOCATION (render->video_sinkpad);
|
|
|
|
|
2010-11-29 20:06:07 +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-10 08:15:05 +00:00
|
|
|
gst_video_info_init (&render->info);
|
2010-11-29 20:06:07 +00:00
|
|
|
|
2010-12-01 04:01:15 +00:00
|
|
|
render->current_subtitle = NULL;
|
|
|
|
render->pending_subtitles = g_queue_new ();
|
|
|
|
|
2010-12-15 19:53:21 +00:00
|
|
|
render->enable = DEFAULT_ENABLE;
|
|
|
|
render->max_page_timeout = DEFAULT_MAX_PAGE_TIMEOUT;
|
2012-07-11 11:45:14 +00:00
|
|
|
render->force_end = DEFAULT_FORCE_END;
|
2010-11-29 20:06:07 +00:00
|
|
|
|
2012-01-19 10:34:26 +00:00
|
|
|
g_mutex_init (&render->dvbsub_mutex);
|
2010-12-03 15:05:56 +00:00
|
|
|
gst_dvbsub_overlay_flush_subtitles (render);
|
2010-11-29 20:06:07 +00:00
|
|
|
|
2010-12-03 15:05:56 +00:00
|
|
|
gst_segment_init (&render->video_segment, GST_FORMAT_TIME);
|
|
|
|
gst_segment_init (&render->subtitle_segment, GST_FORMAT_TIME);
|
2010-11-29 20:06:07 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (render, "init complete");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_dvbsub_overlay_finalize (GObject * object)
|
|
|
|
{
|
|
|
|
GstDVBSubOverlay *overlay = GST_DVBSUB_OVERLAY (object);
|
2010-12-03 14:46:40 +00:00
|
|
|
DVBSubtitles *subs;
|
2010-11-29 20:06:07 +00:00
|
|
|
|
2010-12-03 14:46:40 +00:00
|
|
|
while ((subs = g_queue_pop_head (overlay->pending_subtitles))) {
|
|
|
|
dvb_subtitles_free (subs);
|
2010-12-01 04:01:15 +00:00
|
|
|
}
|
2010-12-03 14:46:40 +00:00
|
|
|
g_queue_free (overlay->pending_subtitles);
|
2010-12-01 04:01:15 +00:00
|
|
|
|
2011-01-04 13:51:21 +00:00
|
|
|
if (overlay->current_subtitle)
|
|
|
|
dvb_subtitles_free (overlay->current_subtitle);
|
|
|
|
overlay->current_subtitle = NULL;
|
|
|
|
|
2012-07-13 10:27:57 +00:00
|
|
|
if (overlay->current_comp)
|
|
|
|
gst_video_overlay_composition_unref (overlay->current_comp);
|
|
|
|
overlay->current_comp = NULL;
|
|
|
|
|
2010-12-24 14:24:12 +00:00
|
|
|
if (overlay->dvb_sub)
|
|
|
|
dvb_sub_free (overlay->dvb_sub);
|
2010-11-29 20:06:07 +00:00
|
|
|
|
2012-01-19 10:34:26 +00:00
|
|
|
g_mutex_clear (&overlay->dvbsub_mutex);
|
2010-11-29 20:06:07 +00:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_dvbsub_overlay_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstDVBSubOverlay *overlay = GST_DVBSUB_OVERLAY (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_ENABLE:
|
2010-12-14 13:34:56 +00:00
|
|
|
g_atomic_int_set (&overlay->enable, g_value_get_boolean (value));
|
2010-11-29 20:06:07 +00:00
|
|
|
break;
|
2010-12-14 13:28:45 +00:00
|
|
|
case PROP_MAX_PAGE_TIMEOUT:
|
|
|
|
g_atomic_int_set (&overlay->max_page_timeout, g_value_get_int (value));
|
|
|
|
break;
|
2012-07-11 11:45:14 +00:00
|
|
|
case PROP_FORCE_END:
|
|
|
|
g_atomic_int_set (&overlay->force_end, g_value_get_boolean (value));
|
|
|
|
break;
|
2010-11-29 20:06:07 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_dvbsub_overlay_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstDVBSubOverlay *overlay = GST_DVBSUB_OVERLAY (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_ENABLE:
|
2010-12-16 10:29:07 +00:00
|
|
|
g_value_set_boolean (value, g_atomic_int_get (&overlay->enable));
|
2010-11-29 20:06:07 +00:00
|
|
|
break;
|
2010-12-14 13:28:45 +00:00
|
|
|
case PROP_MAX_PAGE_TIMEOUT:
|
|
|
|
g_value_set_int (value, g_atomic_int_get (&overlay->max_page_timeout));
|
|
|
|
break;
|
2012-07-11 11:45:14 +00:00
|
|
|
case PROP_FORCE_END:
|
|
|
|
g_value_set_boolean (value, g_atomic_int_get (&overlay->force_end));
|
|
|
|
break;
|
2010-11-29 20:06:07 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstStateChangeReturn
|
|
|
|
gst_dvbsub_overlay_change_state (GstElement * element,
|
|
|
|
GstStateChange transition)
|
|
|
|
{
|
|
|
|
GstDVBSubOverlay *render = GST_DVBSUB_OVERLAY (element);
|
|
|
|
GstStateChangeReturn ret;
|
|
|
|
|
|
|
|
switch (transition) {
|
|
|
|
case GST_STATE_CHANGE_READY_TO_PAUSED:
|
|
|
|
gst_segment_init (&render->video_segment, GST_FORMAT_TIME);
|
|
|
|
gst_segment_init (&render->subtitle_segment, GST_FORMAT_TIME);
|
|
|
|
break;
|
|
|
|
case GST_STATE_CHANGE_NULL_TO_READY:
|
|
|
|
case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
|
|
|
|
|
|
|
|
switch (transition) {
|
|
|
|
case GST_STATE_CHANGE_PAUSED_TO_READY:
|
2010-12-03 15:05:56 +00:00
|
|
|
gst_dvbsub_overlay_flush_subtitles (render);
|
|
|
|
gst_segment_init (&render->video_segment, GST_FORMAT_TIME);
|
|
|
|
gst_segment_init (&render->subtitle_segment, GST_FORMAT_TIME);
|
2011-10-10 08:15:05 +00:00
|
|
|
gst_video_info_init (&render->info);
|
2010-12-03 15:05:56 +00:00
|
|
|
break;
|
2010-11-29 20:06:07 +00:00
|
|
|
case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
|
|
|
|
case GST_STATE_CHANGE_READY_TO_NULL:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2011-11-16 16:28:10 +00:00
|
|
|
gst_dvbsub_overlay_query_src (GstPad * pad, GstObject * parent,
|
|
|
|
GstQuery * query)
|
2010-11-29 20:06:07 +00:00
|
|
|
{
|
2011-11-16 16:28:10 +00:00
|
|
|
GstDVBSubOverlay *render = GST_DVBSUB_OVERLAY (parent);
|
2010-11-29 20:06:07 +00:00
|
|
|
gboolean ret;
|
|
|
|
|
2011-11-15 15:34:13 +00:00
|
|
|
switch (GST_QUERY_TYPE (query)) {
|
|
|
|
case GST_QUERY_CAPS:
|
|
|
|
{
|
|
|
|
GstCaps *filter, *caps;
|
|
|
|
|
|
|
|
gst_query_parse_caps (query, &filter);
|
2014-03-16 16:36:06 +00:00
|
|
|
caps = gst_dvbsub_overlay_get_src_caps (render, pad, filter);
|
2011-11-15 15:34:13 +00:00
|
|
|
gst_query_set_caps_result (query, caps);
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
ret = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
2012-09-12 13:08:01 +00:00
|
|
|
ret = gst_pad_query_default (pad, parent, query);
|
2011-11-15 15:34:13 +00:00
|
|
|
break;
|
|
|
|
}
|
2010-11-29 20:06:07 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2011-11-17 14:53:42 +00:00
|
|
|
gst_dvbsub_overlay_event_src (GstPad * pad, GstObject * parent,
|
|
|
|
GstEvent * event)
|
2010-11-29 20:06:07 +00:00
|
|
|
{
|
2011-11-17 14:53:42 +00:00
|
|
|
GstDVBSubOverlay *render = GST_DVBSUB_OVERLAY (parent);
|
2010-11-29 20:06:07 +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 ());
|
|
|
|
|
2010-12-03 15:05:56 +00:00
|
|
|
gst_dvbsub_overlay_flush_subtitles (render);
|
2010-11-29 20:06:07 +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;
|
|
|
|
}
|
|
|
|
|
2014-03-16 16:36:06 +00:00
|
|
|
/**
|
|
|
|
* gst_dvbsub_overlay_add_feature_and_intersect:
|
|
|
|
*
|
|
|
|
* Creates a new #GstCaps containing the (given caps +
|
|
|
|
* given caps feature) + (given caps intersected by the
|
|
|
|
* given filter).
|
|
|
|
*
|
|
|
|
* Returns: the new #GstCaps
|
|
|
|
*/
|
|
|
|
static GstCaps *
|
|
|
|
gst_dvbsub_overlay_add_feature_and_intersect (GstCaps * caps,
|
|
|
|
const gchar * feature, GstCaps * filter)
|
|
|
|
{
|
|
|
|
int i, caps_size;
|
|
|
|
GstCaps *new_caps;
|
|
|
|
|
|
|
|
new_caps = gst_caps_copy (caps);
|
|
|
|
|
|
|
|
caps_size = gst_caps_get_size (new_caps);
|
|
|
|
for (i = 0; i < caps_size; i++) {
|
|
|
|
GstCapsFeatures *features = gst_caps_get_features (new_caps, i);
|
2014-05-11 05:55:59 +00:00
|
|
|
if (!gst_caps_features_is_any (features)) {
|
|
|
|
gst_caps_features_add (features, feature);
|
|
|
|
}
|
2014-03-16 16:36:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gst_caps_append (new_caps, gst_caps_intersect_full (caps,
|
|
|
|
filter, GST_CAPS_INTERSECT_FIRST));
|
|
|
|
|
|
|
|
return new_caps;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_dvbsub_overlay_intersect_by_feature:
|
|
|
|
*
|
|
|
|
* Creates a new #GstCaps based on the following filtering rule.
|
|
|
|
*
|
|
|
|
* For each individual caps contained in given caps, if the
|
|
|
|
* caps uses the given caps feature, keep a version of the caps
|
|
|
|
* with the feature and an another one without. Otherwise, intersect
|
|
|
|
* the caps with the given filter.
|
|
|
|
*
|
|
|
|
* Returns: the new #GstCaps
|
|
|
|
*/
|
2010-11-29 20:06:07 +00:00
|
|
|
static GstCaps *
|
2014-03-16 16:36:06 +00:00
|
|
|
gst_dvbsub_overlay_intersect_by_feature (GstCaps * caps,
|
|
|
|
const gchar * feature, GstCaps * filter)
|
|
|
|
{
|
|
|
|
int i, caps_size;
|
|
|
|
GstCaps *new_caps;
|
|
|
|
|
|
|
|
new_caps = gst_caps_new_empty ();
|
|
|
|
|
|
|
|
caps_size = gst_caps_get_size (caps);
|
|
|
|
for (i = 0; i < caps_size; i++) {
|
|
|
|
GstStructure *caps_structure = gst_caps_get_structure (caps, i);
|
|
|
|
GstCapsFeatures *caps_features =
|
|
|
|
gst_caps_features_copy (gst_caps_get_features (caps, i));
|
|
|
|
GstCaps *filtered_caps;
|
|
|
|
GstCaps *simple_caps =
|
|
|
|
gst_caps_new_full (gst_structure_copy (caps_structure), NULL);
|
|
|
|
gst_caps_set_features (simple_caps, 0, caps_features);
|
|
|
|
|
|
|
|
if (gst_caps_features_contains (caps_features, feature)) {
|
|
|
|
gst_caps_append (new_caps, gst_caps_copy (simple_caps));
|
|
|
|
|
|
|
|
gst_caps_features_remove (caps_features, feature);
|
|
|
|
filtered_caps = gst_caps_ref (simple_caps);
|
|
|
|
} else {
|
|
|
|
filtered_caps = gst_caps_intersect_full (simple_caps, filter,
|
|
|
|
GST_CAPS_INTERSECT_FIRST);
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_caps_unref (simple_caps);
|
|
|
|
gst_caps_append (new_caps, filtered_caps);
|
|
|
|
}
|
|
|
|
|
|
|
|
return new_caps;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstCaps *
|
|
|
|
gst_dvbsub_overlay_get_videosink_caps (GstDVBSubOverlay * render, GstPad * pad,
|
2012-09-12 13:08:01 +00:00
|
|
|
GstCaps * filter)
|
2010-11-29 20:06:07 +00:00
|
|
|
{
|
2014-03-16 16:36:06 +00:00
|
|
|
GstPad *srcpad = render->srcpad;
|
|
|
|
GstCaps *peer_caps = NULL, *caps = NULL, *dvdsub_overlay_filter = NULL;
|
|
|
|
|
|
|
|
if (filter) {
|
|
|
|
/* filter caps + composition feature + filter caps
|
|
|
|
* filtered by the software caps. */
|
|
|
|
GstCaps *sw_caps = gst_static_caps_get (&sw_template_caps);
|
|
|
|
dvdsub_overlay_filter =
|
|
|
|
gst_dvbsub_overlay_add_feature_and_intersect (filter,
|
|
|
|
GST_CAPS_FEATURE_META_GST_VIDEO_OVERLAY_COMPOSITION, sw_caps);
|
|
|
|
gst_caps_unref (sw_caps);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (render, "dvdsub_overlay filter %" GST_PTR_FORMAT,
|
|
|
|
dvdsub_overlay_filter);
|
|
|
|
}
|
2010-11-29 20:06:07 +00:00
|
|
|
|
2014-03-16 16:36:06 +00:00
|
|
|
peer_caps = gst_pad_peer_query_caps (srcpad, dvdsub_overlay_filter);
|
|
|
|
|
|
|
|
if (dvdsub_overlay_filter)
|
|
|
|
gst_caps_unref (dvdsub_overlay_filter);
|
|
|
|
|
|
|
|
if (peer_caps) {
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (pad, "peer caps %" GST_PTR_FORMAT, peer_caps);
|
|
|
|
|
|
|
|
if (gst_caps_is_any (peer_caps)) {
|
|
|
|
|
|
|
|
/* if peer returns ANY caps, return filtered src pad template caps */
|
|
|
|
caps = gst_caps_copy (gst_pad_get_pad_template_caps (srcpad));
|
|
|
|
if (filter) {
|
|
|
|
GstCaps *intersection = gst_caps_intersect_full (filter, caps,
|
|
|
|
GST_CAPS_INTERSECT_FIRST);
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
caps = intersection;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
/* duplicate caps which contains the composition into one version with
|
|
|
|
* the meta and one without. Filter the other caps by the software caps */
|
|
|
|
GstCaps *sw_caps = gst_static_caps_get (&sw_template_caps);
|
|
|
|
caps = gst_dvbsub_overlay_intersect_by_feature (peer_caps,
|
|
|
|
GST_CAPS_FEATURE_META_GST_VIDEO_OVERLAY_COMPOSITION, sw_caps);
|
|
|
|
gst_caps_unref (sw_caps);
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_caps_unref (peer_caps);
|
2010-11-29 20:06:07 +00:00
|
|
|
|
2014-03-16 16:36:06 +00:00
|
|
|
} else {
|
|
|
|
/* no peer, our padtemplate is enough then */
|
|
|
|
caps = gst_pad_get_pad_template_caps (pad);
|
|
|
|
if (filter) {
|
|
|
|
GstCaps *intersection;
|
|
|
|
|
|
|
|
intersection =
|
|
|
|
gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST);
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
caps = intersection;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (render, "returning %" GST_PTR_FORMAT, caps);
|
|
|
|
|
|
|
|
return caps;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstCaps *
|
|
|
|
gst_dvbsub_overlay_get_src_caps (GstDVBSubOverlay * render, GstPad * pad,
|
|
|
|
GstCaps * filter)
|
|
|
|
{
|
|
|
|
GstPad *sinkpad = render->video_sinkpad;
|
|
|
|
GstCaps *peer_caps = NULL, *caps = NULL, *dvdsub_overlay_filter = NULL;
|
|
|
|
|
|
|
|
if (filter) {
|
|
|
|
/* duplicate filter caps which contains the composition into one version
|
|
|
|
* with the meta and one without. Filter the other caps by the software
|
|
|
|
* caps */
|
|
|
|
GstCaps *sw_caps = gst_static_caps_get (&sw_template_caps);
|
|
|
|
dvdsub_overlay_filter =
|
|
|
|
gst_dvbsub_overlay_intersect_by_feature (filter,
|
|
|
|
GST_CAPS_FEATURE_META_GST_VIDEO_OVERLAY_COMPOSITION, sw_caps);
|
|
|
|
gst_caps_unref (sw_caps);
|
|
|
|
}
|
|
|
|
|
|
|
|
peer_caps = gst_pad_peer_query_caps (sinkpad, dvdsub_overlay_filter);
|
|
|
|
|
|
|
|
if (dvdsub_overlay_filter)
|
|
|
|
gst_caps_unref (dvdsub_overlay_filter);
|
2012-03-11 18:06:59 +00:00
|
|
|
|
2014-03-16 16:36:06 +00:00
|
|
|
if (peer_caps) {
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (pad, "peer caps %" GST_PTR_FORMAT, peer_caps);
|
|
|
|
|
|
|
|
if (gst_caps_is_any (peer_caps)) {
|
|
|
|
|
|
|
|
/* if peer returns ANY caps, return filtered sink pad template caps */
|
|
|
|
caps = gst_caps_copy (gst_pad_get_pad_template_caps (sinkpad));
|
|
|
|
if (filter) {
|
|
|
|
GstCaps *intersection = gst_caps_intersect_full (filter, caps,
|
|
|
|
GST_CAPS_INTERSECT_FIRST);
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
caps = intersection;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
/* return upstream caps + composition feature + upstream caps
|
|
|
|
* filtered by the software caps. */
|
|
|
|
GstCaps *sw_caps = gst_static_caps_get (&sw_template_caps);
|
|
|
|
caps = gst_dvbsub_overlay_add_feature_and_intersect (peer_caps,
|
|
|
|
GST_CAPS_FEATURE_META_GST_VIDEO_OVERLAY_COMPOSITION, sw_caps);
|
|
|
|
gst_caps_unref (sw_caps);
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_caps_unref (peer_caps);
|
2010-11-29 20:06:07 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
/* no peer, our padtemplate is enough then */
|
2014-03-16 16:36:06 +00:00
|
|
|
caps = gst_pad_get_pad_template_caps (pad);
|
|
|
|
if (filter) {
|
|
|
|
GstCaps *intersection;
|
|
|
|
|
|
|
|
intersection =
|
|
|
|
gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST);
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
caps = intersection;
|
|
|
|
}
|
2010-11-29 20:06:07 +00:00
|
|
|
}
|
|
|
|
|
2014-03-16 16:36:06 +00:00
|
|
|
GST_DEBUG_OBJECT (render, "returning %" GST_PTR_FORMAT, caps);
|
|
|
|
|
2010-11-29 20:06:07 +00:00
|
|
|
return caps;
|
|
|
|
}
|
|
|
|
|
2014-03-16 16:36:06 +00:00
|
|
|
static gboolean
|
|
|
|
gst_dvbsub_overlay_can_handle_caps (GstCaps * incaps)
|
|
|
|
{
|
|
|
|
gboolean ret;
|
|
|
|
GstCaps *caps;
|
|
|
|
GstStaticCaps static_caps = GST_STATIC_CAPS (DVBSUB_OVERLAY_CAPS);
|
|
|
|
|
|
|
|
caps = gst_static_caps_get (&static_caps);
|
|
|
|
ret = gst_caps_is_subset (incaps, caps);
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-07-13 10:32:51 +00:00
|
|
|
/* only negotiate/query video overlay composition support for now */
|
|
|
|
static gboolean
|
|
|
|
gst_dvbsub_overlay_negotiate (GstDVBSubOverlay * overlay)
|
|
|
|
{
|
|
|
|
GstCaps *target;
|
|
|
|
GstQuery *query;
|
|
|
|
gboolean attach = FALSE;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (overlay, "performing negotiation");
|
|
|
|
|
|
|
|
target = gst_pad_get_current_caps (overlay->srcpad);
|
|
|
|
|
|
|
|
if (!target || gst_caps_is_empty (target))
|
|
|
|
goto no_format;
|
|
|
|
|
|
|
|
/* find supported meta */
|
|
|
|
query = gst_query_new_allocation (target, TRUE);
|
|
|
|
|
|
|
|
if (!gst_pad_peer_query (overlay->srcpad, query)) {
|
|
|
|
/* no problem, we use the query defaults */
|
|
|
|
GST_DEBUG_OBJECT (overlay, "ALLOCATION query failed");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gst_query_find_allocation_meta (query,
|
|
|
|
GST_VIDEO_OVERLAY_COMPOSITION_META_API_TYPE, NULL))
|
|
|
|
attach = TRUE;
|
|
|
|
|
|
|
|
overlay->attach_compo_to_buffer = attach;
|
|
|
|
|
|
|
|
gst_query_unref (query);
|
|
|
|
gst_caps_unref (target);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
no_format:
|
|
|
|
{
|
|
|
|
if (target)
|
|
|
|
gst_caps_unref (target);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-29 20:06:07 +00:00
|
|
|
static gboolean
|
|
|
|
gst_dvbsub_overlay_setcaps_video (GstPad * pad, GstCaps * caps)
|
|
|
|
{
|
|
|
|
GstDVBSubOverlay *render = GST_DVBSUB_OVERLAY (gst_pad_get_parent (pad));
|
|
|
|
gboolean ret = FALSE;
|
2011-10-10 08:15:05 +00:00
|
|
|
GstVideoInfo info;
|
2010-11-29 20:06:07 +00:00
|
|
|
|
2011-10-10 08:15:05 +00:00
|
|
|
if (!gst_video_info_from_caps (&info, caps))
|
|
|
|
goto invalid_caps;
|
2010-11-29 20:06:07 +00:00
|
|
|
|
2011-10-10 08:15:05 +00:00
|
|
|
render->info = info;
|
2010-11-29 20:06:07 +00:00
|
|
|
|
|
|
|
ret = gst_pad_set_caps (render->srcpad, caps);
|
|
|
|
if (!ret)
|
|
|
|
goto out;
|
|
|
|
|
2012-07-13 10:32:51 +00:00
|
|
|
gst_dvbsub_overlay_negotiate (render);
|
|
|
|
|
2014-03-16 16:36:06 +00:00
|
|
|
if (!render->attach_compo_to_buffer &&
|
|
|
|
!gst_dvbsub_overlay_can_handle_caps (caps))
|
|
|
|
goto unsupported_caps;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (render, "dvbsub overlay renderer setup complete");
|
2010-11-29 20:06:07 +00:00
|
|
|
|
|
|
|
out:
|
|
|
|
gst_object_unref (render);
|
|
|
|
|
|
|
|
return ret;
|
2011-10-10 08:15:05 +00:00
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
invalid_caps:
|
|
|
|
{
|
|
|
|
GST_ERROR_OBJECT (render, "Can't parse caps: %" GST_PTR_FORMAT, caps);
|
|
|
|
ret = FALSE;
|
|
|
|
goto out;
|
|
|
|
}
|
2014-03-16 16:36:06 +00:00
|
|
|
unsupported_caps:
|
|
|
|
{
|
|
|
|
GST_ERROR_OBJECT (render, "Unsupported caps: %" GST_PTR_FORMAT, caps);
|
|
|
|
ret = FALSE;
|
|
|
|
goto out;
|
|
|
|
}
|
2010-11-29 20:06:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-11-30 02:45:54 +00:00
|
|
|
gst_dvbsub_overlay_process_text (GstDVBSubOverlay * overlay, GstBuffer * buffer,
|
|
|
|
guint64 pts)
|
2010-11-29 20:06:07 +00:00
|
|
|
{
|
2012-01-25 13:50:50 +00:00
|
|
|
GstMapInfo map;
|
2010-11-29 20:06:07 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (overlay,
|
2012-07-11 11:48:32 +00:00
|
|
|
"Processing subtitles with PTS=%" G_GUINT64_FORMAT
|
|
|
|
" which is a time of %" GST_TIME_FORMAT, pts, GST_TIME_ARGS (pts));
|
2011-10-10 08:15:05 +00:00
|
|
|
|
2012-01-25 13:50:50 +00:00
|
|
|
gst_buffer_map (buffer, &map, GST_MAP_READ);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (overlay, "Feeding %" G_GSIZE_FORMAT " bytes to libdvbsub",
|
|
|
|
map.size);
|
2011-10-10 08:15:05 +00:00
|
|
|
|
2012-01-19 10:34:26 +00:00
|
|
|
g_mutex_lock (&overlay->dvbsub_mutex);
|
2012-07-11 11:45:14 +00:00
|
|
|
overlay->pending_sub = TRUE;
|
2012-07-11 11:49:14 +00:00
|
|
|
dvb_sub_feed_with_pts (overlay->dvb_sub, pts, map.data, map.size);
|
2012-01-19 10:34:26 +00:00
|
|
|
g_mutex_unlock (&overlay->dvbsub_mutex);
|
2011-10-10 08:15:05 +00:00
|
|
|
|
2012-01-25 13:50:50 +00:00
|
|
|
gst_buffer_unmap (buffer, &map);
|
2010-11-29 20:06:07 +00:00
|
|
|
gst_buffer_unref (buffer);
|
2012-07-11 11:45:14 +00:00
|
|
|
|
|
|
|
if (overlay->pending_sub && overlay->force_end) {
|
|
|
|
GST_DEBUG_OBJECT (overlay, "forcing subtitle end");
|
|
|
|
dvb_sub_feed_with_pts (overlay->dvb_sub, overlay->last_text_pts, NULL, 0);
|
|
|
|
g_assert (overlay->pending_sub == FALSE);
|
|
|
|
}
|
2010-11-29 20:06:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-12-01 03:26:02 +00:00
|
|
|
new_dvb_subtitles_cb (DvbSub * dvb_sub, DVBSubtitles * subs, gpointer user_data)
|
2010-11-29 20:06:07 +00:00
|
|
|
{
|
|
|
|
GstDVBSubOverlay *overlay = GST_DVBSUB_OVERLAY (user_data);
|
2010-12-16 00:13:18 +00:00
|
|
|
int max_page_timeout;
|
2012-07-11 12:59:18 +00:00
|
|
|
guint64 start, stop;
|
2010-12-03 14:46:40 +00:00
|
|
|
|
2010-12-16 00:13:18 +00:00
|
|
|
max_page_timeout = g_atomic_int_get (&overlay->max_page_timeout);
|
|
|
|
if (max_page_timeout > 0)
|
|
|
|
subs->page_time_out = MIN (subs->page_time_out, max_page_timeout);
|
2010-12-14 13:28:45 +00:00
|
|
|
|
2010-11-29 20:06:07 +00:00
|
|
|
GST_INFO_OBJECT (overlay,
|
2012-07-11 12:59:18 +00:00
|
|
|
"New DVB subtitles arrived with a page_time_out of %d and %d regions for "
|
|
|
|
"PTS=%" G_GUINT64_FORMAT ", which should be at time %" GST_TIME_FORMAT,
|
2010-12-01 03:26:02 +00:00
|
|
|
subs->page_time_out, subs->num_rects, subs->pts,
|
|
|
|
GST_TIME_ARGS (subs->pts));
|
2010-12-03 14:46:40 +00:00
|
|
|
|
2012-07-10 15:58:22 +00:00
|
|
|
/* spec says page_time_out is not to be taken very accurately anyway,
|
|
|
|
* and 0 does not make useful sense anyway */
|
|
|
|
if (!subs->page_time_out) {
|
|
|
|
GST_WARNING_OBJECT (overlay, "overriding page_time_out 0");
|
|
|
|
subs->page_time_out = 1;
|
|
|
|
}
|
|
|
|
|
2012-07-11 11:48:32 +00:00
|
|
|
/* clip and convert to running time */
|
|
|
|
start = subs->pts;
|
|
|
|
stop = subs->pts + subs->page_time_out;
|
|
|
|
|
|
|
|
if (!(gst_segment_clip (&overlay->subtitle_segment, GST_FORMAT_TIME,
|
|
|
|
start, stop, &start, &stop)))
|
|
|
|
goto out_of_segment;
|
|
|
|
|
|
|
|
subs->page_time_out = stop - start;
|
|
|
|
|
|
|
|
gst_segment_to_running_time (&overlay->subtitle_segment, GST_FORMAT_TIME,
|
|
|
|
start);
|
|
|
|
g_assert (GST_CLOCK_TIME_IS_VALID (start));
|
|
|
|
subs->pts = start;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (overlay, "SUBTITLE real running time: %" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (start));
|
|
|
|
|
2010-12-01 04:01:15 +00:00
|
|
|
g_queue_push_tail (overlay->pending_subtitles, subs);
|
2012-07-11 11:45:14 +00:00
|
|
|
overlay->pending_sub = FALSE;
|
2012-07-11 11:48:32 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
out_of_segment:
|
|
|
|
{
|
|
|
|
GST_DEBUG_OBJECT (overlay, "subtitle out of segment, discarding");
|
|
|
|
dvb_subtitles_free (subs);
|
|
|
|
}
|
2010-11-29 20:06:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
2011-11-17 14:53:42 +00:00
|
|
|
gst_dvbsub_overlay_chain_text (GstPad * pad, GstObject * parent,
|
|
|
|
GstBuffer * buffer)
|
2010-11-29 20:06:07 +00:00
|
|
|
{
|
2011-11-17 14:53:42 +00:00
|
|
|
GstDVBSubOverlay *overlay = GST_DVBSUB_OVERLAY (parent);
|
2010-11-29 20:06:07 +00:00
|
|
|
|
2011-11-21 21:45:15 +00:00
|
|
|
GST_INFO_OBJECT (overlay,
|
|
|
|
"subpicture/x-dvb buffer with size %" G_GSIZE_FORMAT,
|
2011-10-10 08:15:05 +00:00
|
|
|
gst_buffer_get_size (buffer));
|
2010-11-29 20:06:07 +00:00
|
|
|
|
|
|
|
GST_LOG_OBJECT (overlay,
|
|
|
|
"Video segment: %" GST_SEGMENT_FORMAT " --- Subtitle segment: %"
|
2010-11-30 02:45:54 +00:00
|
|
|
GST_SEGMENT_FORMAT " --- BUFFER: ts=%" GST_TIME_FORMAT,
|
|
|
|
&overlay->video_segment, &overlay->subtitle_segment,
|
|
|
|
GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buffer)));
|
2010-11-29 20:06:07 +00:00
|
|
|
|
|
|
|
/* DVB subtitle packets are required to carry the PTS */
|
|
|
|
if (G_UNLIKELY (!GST_BUFFER_TIMESTAMP_IS_VALID (buffer))) {
|
|
|
|
GST_WARNING_OBJECT (overlay,
|
|
|
|
"Text buffer without valid timestamp, dropping");
|
|
|
|
gst_buffer_unref (buffer);
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
|
|
|
|
2012-07-11 11:45:14 +00:00
|
|
|
/* spec states multiple PES packets may have same PTS,
|
|
|
|
* and same PTS packets make up a display set */
|
|
|
|
if (overlay->pending_sub &&
|
|
|
|
overlay->last_text_pts != GST_BUFFER_TIMESTAMP (buffer)) {
|
|
|
|
GST_DEBUG_OBJECT (overlay, "finishing previous subtitle");
|
|
|
|
dvb_sub_feed_with_pts (overlay->dvb_sub, overlay->last_text_pts, NULL, 0);
|
|
|
|
overlay->pending_sub = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
overlay->last_text_pts = GST_BUFFER_TIMESTAMP (buffer);
|
|
|
|
|
2010-11-29 20:06:07 +00:00
|
|
|
/* As the passed start and stop is equal, we shouldn't need to care about out of segment at all,
|
|
|
|
* the subtitle data for the PTS is completely out of interest to us. A given display set must
|
|
|
|
* carry the same PTS value. */
|
|
|
|
/* FIXME: Consider with larger than 64kB display sets, which would be cut into multiple packets,
|
|
|
|
* FIXME: does our waiting + render code work when there are more than one packets before
|
|
|
|
* FIXME: rendering callback will get called? */
|
|
|
|
|
2011-10-10 08:15:05 +00:00
|
|
|
overlay->subtitle_segment.position = GST_BUFFER_TIMESTAMP (buffer);
|
2010-11-29 20:06:07 +00:00
|
|
|
|
2012-07-11 11:48:32 +00:00
|
|
|
gst_dvbsub_overlay_process_text (overlay, buffer,
|
2010-11-30 02:45:54 +00:00
|
|
|
GST_BUFFER_TIMESTAMP (buffer));
|
|
|
|
|
2010-11-29 20:06:07 +00:00
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
|
|
|
|
2012-07-13 10:27:57 +00:00
|
|
|
static GstVideoOverlayComposition *
|
|
|
|
gst_dvbsub_overlay_subs_to_comp (GstDVBSubOverlay * overlay,
|
|
|
|
DVBSubtitles * subs)
|
|
|
|
{
|
|
|
|
GstVideoOverlayComposition *comp = NULL;
|
|
|
|
GstVideoOverlayRectangle *rect;
|
|
|
|
gint width, height, dw, dh, wx, wy;
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
g_return_val_if_fail (subs != NULL && subs->num_rects > 0, NULL);
|
|
|
|
|
|
|
|
width = GST_VIDEO_INFO_WIDTH (&overlay->info);
|
|
|
|
height = GST_VIDEO_INFO_HEIGHT (&overlay->info);
|
|
|
|
|
|
|
|
dw = subs->display_def.display_width;
|
|
|
|
dh = subs->display_def.display_height;
|
|
|
|
|
|
|
|
GST_LOG_OBJECT (overlay,
|
|
|
|
"converting %d rectangles for display %dx%d -> video %dx%d",
|
|
|
|
subs->num_rects, dw, dh, width, height);
|
|
|
|
|
|
|
|
if (subs->display_def.window_flag) {
|
|
|
|
wx = subs->display_def.window_x;
|
|
|
|
wy = subs->display_def.window_y;
|
|
|
|
GST_LOG_OBJECT (overlay, "display window %dx%d @ (%d, %d)",
|
|
|
|
subs->display_def.window_width, subs->display_def.window_height,
|
|
|
|
wx, wy);
|
|
|
|
} else {
|
|
|
|
wx = 0;
|
|
|
|
wy = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < subs->num_rects; i++) {
|
|
|
|
DVBSubtitleRect *srect = &subs->rects[i];
|
|
|
|
GstBuffer *buf;
|
|
|
|
gint w, h;
|
|
|
|
guint8 *in_data;
|
|
|
|
guint32 *palette, *data;
|
|
|
|
gint rx, ry, rw, rh, stride;
|
|
|
|
gint k, l;
|
|
|
|
GstMapInfo map;
|
|
|
|
|
|
|
|
GST_LOG_OBJECT (overlay, "rectangle %d: %dx%d @ (%d, %d)", i,
|
|
|
|
srect->w, srect->h, srect->x, srect->y);
|
|
|
|
|
|
|
|
w = srect->w;
|
|
|
|
h = srect->h;
|
|
|
|
|
|
|
|
buf = gst_buffer_new_and_alloc (w * h * 4);
|
|
|
|
gst_buffer_map (buf, &map, GST_MAP_WRITE);
|
|
|
|
data = (guint32 *) map.data;
|
|
|
|
in_data = srect->pict.data;
|
|
|
|
palette = srect->pict.palette;
|
|
|
|
stride = srect->pict.rowstride;
|
|
|
|
for (k = 0; k < h; k++) {
|
|
|
|
for (l = 0; l < w; l++) {
|
|
|
|
guint32 ayuv;
|
|
|
|
|
|
|
|
ayuv = palette[*in_data];
|
2012-08-30 10:11:20 +00:00
|
|
|
GST_WRITE_UINT32_BE (data, ayuv);
|
2012-07-13 10:27:57 +00:00
|
|
|
in_data++;
|
|
|
|
data++;
|
|
|
|
}
|
|
|
|
in_data += stride - w;
|
|
|
|
}
|
|
|
|
gst_buffer_unmap (buf, &map);
|
|
|
|
|
|
|
|
/* this is assuming the subtitle rectangle coordinates are relative
|
|
|
|
* to the window (if there is one) within a display of specified dimension.
|
|
|
|
* Coordinate wrt the latter is then scaled to the actual dimension of
|
|
|
|
* the video we are dealing with here. */
|
|
|
|
rx = gst_util_uint64_scale (wx + srect->x, width, dw);
|
|
|
|
ry = gst_util_uint64_scale (wy + srect->y, height, dh);
|
|
|
|
rw = gst_util_uint64_scale (srect->w, width, dw);
|
|
|
|
rh = gst_util_uint64_scale (srect->h, height, dh);
|
|
|
|
|
|
|
|
GST_LOG_OBJECT (overlay, "rectangle %d rendered: %dx%d @ (%d, %d)", i,
|
|
|
|
rw, rh, rx, ry);
|
|
|
|
|
2012-07-17 12:02:14 +00:00
|
|
|
gst_buffer_add_video_meta (buf, GST_VIDEO_FRAME_FLAG_NONE,
|
2012-08-30 10:11:20 +00:00
|
|
|
GST_VIDEO_OVERLAY_COMPOSITION_FORMAT_YUV, w, h);
|
|
|
|
rect = gst_video_overlay_rectangle_new_raw (buf, rx, ry, rw, rh, 0);
|
2012-07-13 10:27:57 +00:00
|
|
|
g_assert (rect);
|
|
|
|
if (comp) {
|
|
|
|
gst_video_overlay_composition_add_rectangle (comp, rect);
|
|
|
|
} else {
|
|
|
|
comp = gst_video_overlay_composition_new (rect);
|
|
|
|
}
|
2012-07-17 16:05:00 +00:00
|
|
|
gst_video_overlay_rectangle_unref (rect);
|
|
|
|
gst_buffer_unref (buf);
|
2012-07-13 10:27:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return comp;
|
|
|
|
}
|
|
|
|
|
2010-11-29 20:06:07 +00:00
|
|
|
static GstFlowReturn
|
2011-11-17 14:53:42 +00:00
|
|
|
gst_dvbsub_overlay_chain_video (GstPad * pad, GstObject * parent,
|
|
|
|
GstBuffer * buffer)
|
2010-11-29 20:06:07 +00:00
|
|
|
{
|
2011-11-17 14:53:42 +00:00
|
|
|
GstDVBSubOverlay *overlay = GST_DVBSUB_OVERLAY (parent);
|
2010-11-29 20:06:07 +00:00
|
|
|
GstFlowReturn ret = GST_FLOW_OK;
|
|
|
|
gint64 start, stop;
|
2011-10-10 08:15:05 +00:00
|
|
|
guint64 cstart, cstop;
|
2010-12-03 15:21:15 +00:00
|
|
|
gboolean in_seg;
|
2010-12-06 16:05:28 +00:00
|
|
|
GstClockTime vid_running_time, vid_running_time_end;
|
2010-11-29 20:06:07 +00:00
|
|
|
|
2011-10-10 08:15:05 +00:00
|
|
|
if (GST_VIDEO_INFO_FORMAT (&overlay->info) == GST_VIDEO_FORMAT_UNKNOWN)
|
2010-12-03 15:05:56 +00:00
|
|
|
return GST_FLOW_NOT_NEGOTIATED;
|
|
|
|
|
2010-11-29 20:06:07 +00:00
|
|
|
if (!GST_BUFFER_TIMESTAMP_IS_VALID (buffer))
|
|
|
|
goto missing_timestamp;
|
|
|
|
|
|
|
|
start = GST_BUFFER_TIMESTAMP (buffer);
|
|
|
|
|
|
|
|
GST_LOG_OBJECT (overlay,
|
2011-10-10 08:15:05 +00:00
|
|
|
"Video segment: %" GST_SEGMENT_FORMAT " --- Subtitle position: %"
|
2010-11-30 02:45:54 +00:00
|
|
|
GST_TIME_FORMAT " --- BUFFER: ts=%" GST_TIME_FORMAT,
|
2010-12-08 18:36:48 +00:00
|
|
|
&overlay->video_segment,
|
2011-10-10 08:15:05 +00:00
|
|
|
GST_TIME_ARGS (overlay->subtitle_segment.position),
|
2010-11-30 02:45:54 +00:00
|
|
|
GST_TIME_ARGS (start));
|
2010-11-29 20:06:07 +00:00
|
|
|
|
|
|
|
/* ignore buffers that are outside of the current segment */
|
|
|
|
if (!GST_BUFFER_DURATION_IS_VALID (buffer)) {
|
|
|
|
stop = GST_CLOCK_TIME_NONE;
|
|
|
|
} else {
|
|
|
|
stop = start + GST_BUFFER_DURATION (buffer);
|
|
|
|
}
|
|
|
|
|
2010-12-03 15:21:15 +00:00
|
|
|
in_seg = gst_segment_clip (&overlay->video_segment, GST_FORMAT_TIME,
|
|
|
|
start, stop, &cstart, &cstop);
|
|
|
|
if (!in_seg) {
|
|
|
|
GST_DEBUG_OBJECT (overlay, "Buffer outside configured segment -- dropping");
|
|
|
|
gst_buffer_unref (buffer);
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
|
|
|
|
2011-10-10 08:15:05 +00:00
|
|
|
buffer = gst_buffer_make_writable (buffer);
|
2010-12-03 15:21:15 +00:00
|
|
|
GST_BUFFER_TIMESTAMP (buffer) = cstart;
|
|
|
|
if (GST_BUFFER_DURATION_IS_VALID (buffer))
|
|
|
|
GST_BUFFER_DURATION (buffer) = cstop - cstart;
|
|
|
|
|
2010-12-01 04:01:15 +00:00
|
|
|
vid_running_time =
|
|
|
|
gst_segment_to_running_time (&overlay->video_segment, GST_FORMAT_TIME,
|
2010-12-06 16:05:28 +00:00
|
|
|
cstart);
|
|
|
|
if (GST_BUFFER_DURATION_IS_VALID (buffer))
|
|
|
|
vid_running_time_end =
|
|
|
|
gst_segment_to_running_time (&overlay->video_segment, GST_FORMAT_TIME,
|
|
|
|
cstop);
|
|
|
|
else
|
|
|
|
vid_running_time_end = vid_running_time;
|
|
|
|
|
2010-12-01 04:01:15 +00:00
|
|
|
GST_DEBUG_OBJECT (overlay, "Video running time: %" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (vid_running_time));
|
|
|
|
|
2011-10-10 08:15:05 +00:00
|
|
|
overlay->video_segment.position = GST_BUFFER_TIMESTAMP (buffer);
|
2010-11-29 20:06:07 +00:00
|
|
|
|
2012-01-19 10:34:26 +00:00
|
|
|
g_mutex_lock (&overlay->dvbsub_mutex);
|
2010-12-01 04:01:15 +00:00
|
|
|
if (!g_queue_is_empty (overlay->pending_subtitles)) {
|
2010-12-06 16:05:28 +00:00
|
|
|
DVBSubtitles *tmp, *candidate = NULL;
|
2010-12-03 16:35:36 +00:00
|
|
|
|
|
|
|
while (!g_queue_is_empty (overlay->pending_subtitles)) {
|
2010-12-06 16:05:28 +00:00
|
|
|
tmp = g_queue_peek_head (overlay->pending_subtitles);
|
2010-12-03 16:35:36 +00:00
|
|
|
|
2010-12-06 16:05:28 +00:00
|
|
|
if (tmp->pts > vid_running_time_end) {
|
|
|
|
/* For a future video frame */
|
|
|
|
break;
|
|
|
|
} else if (tmp->num_rects == 0) {
|
2010-12-03 16:35:36 +00:00
|
|
|
/* Clear screen */
|
|
|
|
if (overlay->current_subtitle)
|
|
|
|
dvb_subtitles_free (overlay->current_subtitle);
|
|
|
|
overlay->current_subtitle = NULL;
|
2010-12-06 16:05:28 +00:00
|
|
|
if (candidate)
|
|
|
|
dvb_subtitles_free (candidate);
|
|
|
|
candidate = NULL;
|
|
|
|
g_queue_pop_head (overlay->pending_subtitles);
|
2011-01-04 15:03:01 +00:00
|
|
|
dvb_subtitles_free (tmp);
|
|
|
|
tmp = NULL;
|
2010-12-06 16:05:28 +00:00
|
|
|
} else if (tmp->pts + tmp->page_time_out * GST_SECOND *
|
2011-10-10 08:15:05 +00:00
|
|
|
ABS (overlay->subtitle_segment.rate) >= vid_running_time) {
|
2010-12-06 16:05:28 +00:00
|
|
|
if (candidate)
|
|
|
|
dvb_subtitles_free (candidate);
|
|
|
|
candidate = tmp;
|
2010-12-03 16:35:36 +00:00
|
|
|
g_queue_pop_head (overlay->pending_subtitles);
|
|
|
|
} else {
|
2010-12-06 16:05:28 +00:00
|
|
|
/* Too late */
|
|
|
|
dvb_subtitles_free (tmp);
|
|
|
|
tmp = NULL;
|
|
|
|
g_queue_pop_head (overlay->pending_subtitles);
|
2010-12-03 16:35:36 +00:00
|
|
|
}
|
2010-12-01 04:01:15 +00:00
|
|
|
}
|
2010-12-06 16:05:28 +00:00
|
|
|
|
|
|
|
if (candidate) {
|
|
|
|
GST_DEBUG_OBJECT (overlay,
|
|
|
|
"Time to show the next subtitle page (%" GST_TIME_FORMAT " >= %"
|
|
|
|
GST_TIME_FORMAT ") - it has %u regions",
|
|
|
|
GST_TIME_ARGS (vid_running_time), GST_TIME_ARGS (candidate->pts),
|
|
|
|
candidate->num_rects);
|
|
|
|
dvb_subtitles_free (overlay->current_subtitle);
|
|
|
|
overlay->current_subtitle = candidate;
|
2012-07-13 10:27:57 +00:00
|
|
|
if (overlay->current_comp)
|
|
|
|
gst_video_overlay_composition_unref (overlay->current_comp);
|
|
|
|
overlay->current_comp =
|
|
|
|
gst_dvbsub_overlay_subs_to_comp (overlay, overlay->current_subtitle);
|
2010-12-06 16:05:28 +00:00
|
|
|
}
|
2010-11-29 20:06:07 +00:00
|
|
|
}
|
|
|
|
|
2010-12-01 05:06:35 +00:00
|
|
|
/* Check that we haven't hit the fallback timeout for current subtitle page */
|
|
|
|
if (overlay->current_subtitle
|
|
|
|
&& vid_running_time >
|
|
|
|
(overlay->current_subtitle->pts +
|
2010-12-03 16:35:36 +00:00
|
|
|
overlay->current_subtitle->page_time_out * GST_SECOND *
|
2011-10-10 08:15:05 +00:00
|
|
|
ABS (overlay->subtitle_segment.rate))) {
|
2010-12-01 05:06:35 +00:00
|
|
|
GST_INFO_OBJECT (overlay,
|
|
|
|
"Subtitle page not redefined before fallback page_time_out of %u seconds (missed data?) - deleting current page",
|
|
|
|
overlay->current_subtitle->page_time_out);
|
|
|
|
dvb_subtitles_free (overlay->current_subtitle);
|
|
|
|
overlay->current_subtitle = NULL;
|
|
|
|
}
|
|
|
|
|
2010-12-01 05:20:07 +00:00
|
|
|
/* Now render it */
|
2010-12-15 19:54:35 +00:00
|
|
|
if (g_atomic_int_get (&overlay->enable) && overlay->current_subtitle) {
|
2011-10-10 08:15:05 +00:00
|
|
|
GstVideoFrame frame;
|
|
|
|
|
2012-07-13 10:27:57 +00:00
|
|
|
g_assert (overlay->current_comp);
|
2012-07-13 10:32:51 +00:00
|
|
|
if (overlay->attach_compo_to_buffer) {
|
|
|
|
GST_DEBUG_OBJECT (overlay, "Attaching overlay image to video buffer");
|
|
|
|
gst_buffer_add_video_overlay_composition_meta (buffer,
|
|
|
|
overlay->current_comp);
|
|
|
|
} else {
|
|
|
|
GST_DEBUG_OBJECT (overlay, "Blending overlay image to video buffer");
|
|
|
|
gst_video_frame_map (&frame, &overlay->info, buffer, GST_MAP_WRITE);
|
|
|
|
gst_video_overlay_composition_blend (overlay->current_comp, &frame);
|
|
|
|
gst_video_frame_unmap (&frame);
|
|
|
|
}
|
2010-12-01 05:20:07 +00:00
|
|
|
}
|
2012-01-19 10:34:26 +00:00
|
|
|
g_mutex_unlock (&overlay->dvbsub_mutex);
|
2010-12-01 05:20:07 +00:00
|
|
|
|
2010-11-29 20:06:07 +00:00
|
|
|
ret = gst_pad_push (overlay->srcpad, buffer);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
missing_timestamp:
|
|
|
|
{
|
|
|
|
GST_WARNING_OBJECT (overlay, "video buffer without timestamp, discarding");
|
|
|
|
gst_buffer_unref (buffer);
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-15 15:34:13 +00:00
|
|
|
static gboolean
|
2011-11-16 16:28:10 +00:00
|
|
|
gst_dvbsub_overlay_query_video (GstPad * pad, GstObject * parent,
|
|
|
|
GstQuery * query)
|
2011-11-15 15:34:13 +00:00
|
|
|
{
|
2012-09-12 13:08:01 +00:00
|
|
|
GstDVBSubOverlay *render = (GstDVBSubOverlay *) parent;
|
2011-11-15 15:34:13 +00:00
|
|
|
gboolean ret;
|
|
|
|
|
|
|
|
switch (GST_QUERY_TYPE (query)) {
|
|
|
|
case GST_QUERY_CAPS:
|
|
|
|
{
|
|
|
|
GstCaps *filter, *caps;
|
|
|
|
|
|
|
|
gst_query_parse_caps (query, &filter);
|
2014-03-16 16:36:06 +00:00
|
|
|
caps = gst_dvbsub_overlay_get_videosink_caps (render, pad, filter);
|
2011-11-15 15:34:13 +00:00
|
|
|
gst_query_set_caps_result (query, caps);
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
ret = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
2011-11-16 16:28:10 +00:00
|
|
|
ret = gst_pad_query_default (pad, parent, query);
|
2011-11-15 15:34:13 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-11-29 20:06:07 +00:00
|
|
|
static gboolean
|
2011-11-17 14:53:42 +00:00
|
|
|
gst_dvbsub_overlay_event_video (GstPad * pad, GstObject * parent,
|
|
|
|
GstEvent * event)
|
2010-11-29 20:06:07 +00:00
|
|
|
{
|
|
|
|
gboolean ret = FALSE;
|
2011-11-17 14:53:42 +00:00
|
|
|
GstDVBSubOverlay *render = GST_DVBSUB_OVERLAY (parent);
|
2010-11-29 20:06:07 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (pad, "received video event %s",
|
|
|
|
GST_EVENT_TYPE_NAME (event));
|
|
|
|
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
2011-10-10 08:15:05 +00:00
|
|
|
case GST_EVENT_CAPS:
|
|
|
|
{
|
|
|
|
GstCaps *caps;
|
|
|
|
|
|
|
|
gst_event_parse_caps (event, &caps);
|
|
|
|
ret = gst_dvbsub_overlay_setcaps_video (pad, caps);
|
|
|
|
gst_event_unref (event);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GST_EVENT_SEGMENT:
|
2010-11-29 20:06:07 +00:00
|
|
|
{
|
2011-10-10 08:15:05 +00:00
|
|
|
GstSegment seg;
|
2010-11-29 20:06:07 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (render, "received new segment");
|
|
|
|
|
2011-10-10 08:15:05 +00:00
|
|
|
gst_event_copy_segment (event, &seg);
|
2010-11-29 20:06:07 +00:00
|
|
|
|
2011-10-10 08:15:05 +00:00
|
|
|
if (seg.format == GST_FORMAT_TIME) {
|
2010-11-29 20:06:07 +00:00
|
|
|
GST_DEBUG_OBJECT (render, "VIDEO SEGMENT now: %" GST_SEGMENT_FORMAT,
|
|
|
|
&render->video_segment);
|
|
|
|
|
2011-10-10 08:15:05 +00:00
|
|
|
render->video_segment = seg;
|
2010-11-29 20:06:07 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (render, "VIDEO SEGMENT after: %" GST_SEGMENT_FORMAT,
|
|
|
|
&render->video_segment);
|
|
|
|
ret = gst_pad_push_event (render->srcpad, event);
|
|
|
|
} else {
|
|
|
|
GST_ELEMENT_WARNING (render, STREAM, MUX, (NULL),
|
|
|
|
("received non-TIME newsegment event on video input"));
|
|
|
|
ret = FALSE;
|
|
|
|
gst_event_unref (event);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GST_EVENT_FLUSH_STOP:
|
|
|
|
gst_segment_init (&render->video_segment, GST_FORMAT_TIME);
|
|
|
|
default:
|
|
|
|
ret = gst_pad_push_event (render->srcpad, event);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2011-11-17 14:53:42 +00:00
|
|
|
gst_dvbsub_overlay_event_text (GstPad * pad, GstObject * parent,
|
|
|
|
GstEvent * event)
|
2010-11-29 20:06:07 +00:00
|
|
|
{
|
|
|
|
gboolean ret = FALSE;
|
2011-11-17 14:53:42 +00:00
|
|
|
GstDVBSubOverlay *render = GST_DVBSUB_OVERLAY (parent);
|
2010-11-29 20:06:07 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (pad, "received text event %s", GST_EVENT_TYPE_NAME (event));
|
|
|
|
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
2011-10-10 08:15:05 +00:00
|
|
|
case GST_EVENT_SEGMENT:
|
2010-11-29 20:06:07 +00:00
|
|
|
{
|
2011-10-10 08:15:05 +00:00
|
|
|
GstSegment seg;
|
2010-11-29 20:06:07 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (render, "received new segment");
|
|
|
|
|
2011-10-10 08:15:05 +00:00
|
|
|
gst_event_copy_segment (event, &seg);
|
2010-11-29 20:06:07 +00:00
|
|
|
|
2011-10-10 08:15:05 +00:00
|
|
|
if (seg.format == GST_FORMAT_TIME) {
|
2010-11-29 20:06:07 +00:00
|
|
|
GST_DEBUG_OBJECT (render, "SUBTITLE SEGMENT now: %" GST_SEGMENT_FORMAT,
|
|
|
|
&render->subtitle_segment);
|
|
|
|
|
2011-10-10 08:15:05 +00:00
|
|
|
render->subtitle_segment = seg;
|
2010-11-29 20:06:07 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (render,
|
|
|
|
"SUBTITLE SEGMENT after: %" GST_SEGMENT_FORMAT,
|
|
|
|
&render->subtitle_segment);
|
|
|
|
ret = TRUE;
|
|
|
|
gst_event_unref (event);
|
|
|
|
} else {
|
|
|
|
GST_ELEMENT_WARNING (render, STREAM, MUX, (NULL),
|
2010-12-03 14:46:40 +00:00
|
|
|
("received non-TIME newsegment event on subtitle sinkpad"));
|
2010-11-29 20:06:07 +00:00
|
|
|
ret = FALSE;
|
|
|
|
gst_event_unref (event);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GST_EVENT_FLUSH_STOP:
|
2010-12-03 15:05:56 +00:00
|
|
|
GST_DEBUG_OBJECT (render, "stop flushing");
|
|
|
|
gst_dvbsub_overlay_flush_subtitles (render);
|
2010-11-29 20:06:07 +00:00
|
|
|
gst_segment_init (&render->subtitle_segment, GST_FORMAT_TIME);
|
|
|
|
gst_event_unref (event);
|
|
|
|
ret = TRUE;
|
|
|
|
break;
|
|
|
|
case GST_EVENT_FLUSH_START:
|
|
|
|
GST_DEBUG_OBJECT (render, "begin flushing");
|
|
|
|
gst_event_unref (event);
|
|
|
|
ret = TRUE;
|
|
|
|
break;
|
|
|
|
case GST_EVENT_EOS:
|
|
|
|
GST_INFO_OBJECT (render, "text EOS");
|
|
|
|
gst_event_unref (event);
|
|
|
|
ret = TRUE;
|
|
|
|
break;
|
2014-03-16 00:25:10 +00:00
|
|
|
case GST_EVENT_GAP:
|
|
|
|
gst_event_unref (event);
|
|
|
|
ret = TRUE;
|
|
|
|
break;
|
2013-02-19 11:14:11 +00:00
|
|
|
case GST_EVENT_CAPS:
|
|
|
|
/* don't want to forward the subtitle caps */
|
|
|
|
gst_event_unref (event);
|
|
|
|
ret = TRUE;
|
|
|
|
break;
|
2010-11-29 20:06:07 +00:00
|
|
|
default:
|
|
|
|
ret = gst_pad_push_event (render->srcpad, event);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
plugin_init (GstPlugin * plugin)
|
|
|
|
{
|
|
|
|
GST_DEBUG_CATEGORY_INIT (gst_dvbsub_overlay_debug, "dvbsuboverlay",
|
|
|
|
0, "DVB subtitle overlay");
|
|
|
|
|
|
|
|
return gst_element_register (plugin, "dvbsuboverlay",
|
|
|
|
GST_RANK_PRIMARY, GST_TYPE_DVBSUB_OVERLAY);
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
|
|
|
|
GST_VERSION_MINOR,
|
2012-04-05 16:02:56 +00:00
|
|
|
dvbsuboverlay,
|
2010-11-29 20:06:07 +00:00
|
|
|
"DVB subtitle renderer",
|
|
|
|
plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)
|