GST_STATIC_CAPS ("text/plain; text/x-pango-markup")
);
-static void gst_sub_parse_base_init (GstSubParseClass * klass);
-static void gst_sub_parse_class_init (GstSubParseClass * klass);
-static void gst_sub_parse_init (GstSubParse * subparse);
static gboolean gst_sub_parse_src_event (GstPad * pad, GstEvent * event);
static gboolean gst_sub_parse_src_query (GstPad * pad, GstQuery * query);
static GstFlowReturn gst_sub_parse_chain (GstPad * sinkpad, GstBuffer * buf);
-static GstElementClass *parent_class = NULL;
-
-GType
-gst_sub_parse_get_type (void)
-{
- static GType sub_parse_type = 0;
-
- if (!sub_parse_type) {
- static const GTypeInfo sub_parse_info = {
- sizeof (GstSubParseClass),
- (GBaseInitFunc) gst_sub_parse_base_init,
- NULL,
- (GClassInitFunc) gst_sub_parse_class_init,
- NULL,
- NULL,
- sizeof (GstSubParse),
- 0,
- (GInstanceInitFunc) gst_sub_parse_init,
- };
-
- sub_parse_type = g_type_register_static (GST_TYPE_ELEMENT,
- "GstSubParse", &sub_parse_info, 0);
- }
-
- return sub_parse_type;
-}
-
-static void
-gst_sub_parse_base_init (GstSubParseClass * klass)
-{
- GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
-
- gst_element_class_add_pad_template (element_class,
- gst_static_pad_template_get (&sink_templ));
- gst_element_class_add_pad_template (element_class,
- gst_static_pad_template_get (&src_templ));
- gst_element_class_set_details_simple (element_class,
- "Subtitle parser", "Codec/Parser/Subtitle",
- "Parses subtitle (.sub) files into text streams",
- "Gustavo J. A. M. Carneiro <gjc@inescporto.pt>, "
- "GStreamer maintainers <gstreamer-devel@lists.sourceforge.net>");
-}
+#define gst_sub_parse_parent_class parent_class
+G_DEFINE_TYPE (GstSubParse, gst_sub_parse, GST_TYPE_ELEMENT);
static void
gst_sub_parse_dispose (GObject * object)
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
- parent_class = g_type_class_peek_parent (klass);
-
object_class->dispose = gst_sub_parse_dispose;
object_class->set_property = gst_sub_parse_set_property;
object_class->get_property = gst_sub_parse_get_property;
+ gst_element_class_add_pad_template (element_class,
+ gst_static_pad_template_get (&sink_templ));
+ gst_element_class_add_pad_template (element_class,
+ gst_static_pad_template_get (&src_templ));
+ gst_element_class_set_details_simple (element_class,
+ "Subtitle parser", "Codec/Parser/Subtitle",
+ "Parses subtitle (.sub) files into text streams",
+ "Gustavo J. A. M. Carneiro <gjc@inescporto.pt>, "
+ "GStreamer maintainers <gstreamer-devel@lists.sourceforge.net>");
+
element_class->change_state = gst_sub_parse_change_state;
g_object_class_install_property (object_class, PROP_ENCODING,
ret = gst_pad_peer_query (self->sinkpad, query);
} else {
ret = TRUE;
- gst_query_set_position (query, GST_FORMAT_TIME,
- self->segment.last_stop);
+ gst_query_set_position (query, GST_FORMAT_TIME, self->segment.position);
}
break;
}
case GST_EVENT_SEEK:
{
GstFormat format;
+ GstSeekFlags flags;
GstSeekType start_type, stop_type;
gint64 start, stop;
gdouble rate;
gboolean update;
- gst_event_parse_seek (event, &rate, &format, &self->segment_flags,
+ gst_event_parse_seek (event, &rate, &format, &flags,
&start_type, &start, &stop_type, &stop);
if (format != GST_FORMAT_TIME) {
/* Convert that seek to a seeking in bytes at position 0,
FIXME: could use an index */
ret = gst_pad_push_event (self->sinkpad,
- gst_event_new_seek (rate, GST_FORMAT_BYTES, self->segment_flags,
+ gst_event_new_seek (rate, GST_FORMAT_BYTES, flags,
GST_SEEK_TYPE_SET, 0, GST_SEEK_TYPE_NONE, 0));
if (ret) {
/* Apply the seek to our segment */
- gst_segment_set_seek (&self->segment, rate, format, self->segment_flags,
+ gst_segment_do_seek (&self->segment, rate, format, flags,
start_type, start, stop_type, stop, &update);
GST_DEBUG_OBJECT (self, "segment after seek: %" GST_SEGMENT_FORMAT,
const gchar *line_split;
gchar *line_chunk;
guint start_frame, end_frame;
- gint64 clip_start = 0, clip_stop = 0;
+ guint64 clip_start = 0, clip_stop = 0;
gboolean in_seg = FALSE;
GString *markup;
gchar *ret;
case 2:
{
/* No need to parse that text if it's out of segment */
- gint64 clip_start = 0, clip_stop = 0;
+ guint64 clip_start = 0, clip_stop = 0;
gboolean in_seg = FALSE;
/* Check our segment start/stop */
case 1:
{
/* No need to parse that text if it's out of segment */
- gint64 clip_start = 0, clip_stop = 0;
+ guint64 clip_start = 0, clip_stop = 0;
gboolean in_seg = FALSE;
/* Check our segment start/stop */
return NULL;
case 1:
{ /* No need to parse that text if it's out of segment */
- gint64 clip_start = 0, clip_stop = 0;
+ guint64 clip_start = 0, clip_stop = 0;
gboolean in_seg = FALSE;
/* Check our segment start/stop */
return NULL;
case 1:
{
- gint64 clip_start = 0, clip_stop = 0;
+ guint64 clip_start = 0, clip_stop = 0;
gboolean in_seg;
gchar *ret;
gboolean discont;
gsize consumed;
gchar *input = NULL;
+ const guint8 *data;
+ gsize avail;
discont = GST_BUFFER_IS_DISCONT (buf);
* subtitles which are discontinuous by nature. */
}
- self->offset = GST_BUFFER_OFFSET (buf) + GST_BUFFER_SIZE (buf);
+ self->offset = GST_BUFFER_OFFSET (buf) + gst_buffer_get_size (buf);
self->next_offset = self->offset;
gst_adapter_push (self->adapter, buf);
- input =
- convert_encoding (self, (const gchar *) gst_adapter_peek (self->adapter,
- gst_adapter_available (self->adapter)),
- (gsize) gst_adapter_available (self->adapter), &consumed);
+ avail = gst_adapter_available (self->adapter);
+ data = gst_adapter_map (self->adapter, avail);
+ input = convert_encoding (self, (const gchar *) data, avail, &consumed);
if (input && consumed > 0) {
self->textbuf = g_string_append (self->textbuf, input);
- gst_adapter_flush (self->adapter, consumed);
+ gst_adapter_unmap (self->adapter, consumed);
+ } else {
+ gst_adapter_unmap (self->adapter, 0);
}
g_free (input);
{
GstFlowReturn ret = GST_FLOW_OK;
GstCaps *caps = NULL;
- gchar *line, *subtitle;
+ gchar *line, *subtitle, *data;
+ gsize size;
if (self->first_buffer) {
- self->detected_encoding =
- detect_encoding ((gchar *) GST_BUFFER_DATA (buf),
- GST_BUFFER_SIZE (buf));
+ data = gst_buffer_map (buf, &size, NULL, GST_MAP_READ);
+ self->detected_encoding = detect_encoding (data, size);
+ gst_buffer_unmap (buf, data, size);
self->first_buffer = FALSE;
self->state.fps_n = self->fps_n;
self->state.fps_d = self->fps_d;
guint subtitle_len = strlen (subtitle);
/* +1 for terminating NUL character */
- ret = gst_pad_alloc_buffer_and_set_caps (self->srcpad,
- GST_BUFFER_OFFSET_NONE, subtitle_len + 1,
- GST_PAD_CAPS (self->srcpad), &buf);
-
- if (ret == GST_FLOW_OK) {
- /* copy terminating NUL character as well */
- memcpy (GST_BUFFER_DATA (buf), subtitle, subtitle_len + 1);
- GST_BUFFER_SIZE (buf) = subtitle_len;
- GST_BUFFER_TIMESTAMP (buf) = self->state.start_time;
- GST_BUFFER_DURATION (buf) = self->state.duration;
-
- /* in some cases (e.g. tmplayer) we can only determine the duration
- * of a text chunk from the timestamp of the next text chunk; in those
- * cases, we probably want to limit the duration to something
- * reasonable, so we don't end up showing some text for e.g. 40 seconds
- * just because nothing else is being said during that time */
- if (self->state.max_duration > 0 && GST_BUFFER_DURATION_IS_VALID (buf)) {
- if (GST_BUFFER_DURATION (buf) > self->state.max_duration)
- GST_BUFFER_DURATION (buf) = self->state.max_duration;
- }
+ buf = gst_buffer_new_and_alloc (subtitle_len + 1);
+
+ /* copy terminating NUL character as well */
+ gst_buffer_fill (buf, 0, subtitle, subtitle_len + 1);
+ gst_buffer_set_size (buf, subtitle_len);
+
+ GST_BUFFER_TIMESTAMP (buf) = self->state.start_time;
+ GST_BUFFER_DURATION (buf) = self->state.duration;
+
+ /* in some cases (e.g. tmplayer) we can only determine the duration
+ * of a text chunk from the timestamp of the next text chunk; in those
+ * cases, we probably want to limit the duration to something
+ * reasonable, so we don't end up showing some text for e.g. 40 seconds
+ * just because nothing else is being said during that time */
+ if (self->state.max_duration > 0 && GST_BUFFER_DURATION_IS_VALID (buf)) {
+ if (GST_BUFFER_DURATION (buf) > self->state.max_duration)
+ GST_BUFFER_DURATION (buf) = self->state.max_duration;
+ }
- gst_segment_set_last_stop (&self->segment, GST_FORMAT_TIME,
- self->state.start_time);
+ self->segment.position = self->state.start_time;
- GST_DEBUG_OBJECT (self, "Sending text '%s', %" GST_TIME_FORMAT " + %"
- GST_TIME_FORMAT, subtitle, GST_TIME_ARGS (self->state.start_time),
- GST_TIME_ARGS (self->state.duration));
+ GST_DEBUG_OBJECT (self, "Sending text '%s', %" GST_TIME_FORMAT " + %"
+ GST_TIME_FORMAT, subtitle, GST_TIME_ARGS (self->state.start_time),
+ GST_TIME_ARGS (self->state.duration));
- ret = gst_pad_push (self->srcpad, buf);
- }
+ ret = gst_pad_push (self->srcpad, buf);
/* move this forward (the tmplayer parser needs this) */
if (self->state.duration != GST_CLOCK_TIME_NONE)
GST_LOG_OBJECT (self, "pushing newsegment event with %" GST_SEGMENT_FORMAT,
&self->segment);
- gst_pad_push_event (self->srcpad, gst_event_new_new_segment (FALSE,
- self->segment.rate, self->segment.format,
- self->segment.last_stop, self->segment.stop, self->segment.time));
+ gst_pad_push_event (self->srcpad, gst_event_new_segment (&self->segment));
self->need_segment = FALSE;
}
self->parser_type == GST_SUB_PARSE_FORMAT_TMPLAYER ||
self->parser_type == GST_SUB_PARSE_FORMAT_MPL2 ||
self->parser_type == GST_SUB_PARSE_FORMAT_QTTEXT) {
+ gchar term_chars[] = { '\n', '\n', '\0' };
GstBuffer *buf = gst_buffer_new_and_alloc (2 + 1);
GST_DEBUG ("EOS. Pushing remaining text (if any)");
- GST_BUFFER_DATA (buf)[0] = '\n';
- GST_BUFFER_DATA (buf)[1] = '\n';
- GST_BUFFER_DATA (buf)[2] = '\0'; /* play it safe */
- GST_BUFFER_SIZE (buf) = 2;
+ gst_buffer_fill (buf, 0, term_chars, 3);
+ gst_buffer_set_size (buf, 2);
+
GST_BUFFER_OFFSET (buf) = self->offset;
gst_sub_parse_chain (pad, buf);
}
ret = gst_pad_event_default (pad, event);
break;
}
- case GST_EVENT_NEWSEGMENT:
+ case GST_EVENT_SEGMENT:
{
- GstFormat format;
- gdouble rate;
- gint64 start, stop, time;
- gboolean update;
-
- gst_event_parse_new_segment (event, &update, &rate, &format, &start,
- &stop, &time);
-
- GST_DEBUG_OBJECT (self, "newsegment (%s)", gst_format_get_name (format));
-
- if (format == GST_FORMAT_TIME) {
- gst_segment_set_newsegment (&self->segment, update, rate, format,
- start, stop, time);
- } else {
- /* if not time format, we'll either start with a 0 timestamp anyway or
- * it's following a seek in which case we'll have saved the requested
- * seek segment and don't want to overwrite it (remember that on a seek
- * we always just seek back to the start in BYTES format and just throw
- * away all text that's before the requested position; if the subtitles
- * come from an upstream demuxer, it won't be able to handle our BYTES
- * seek request and instead send us a newsegment from the seek request
- * it received via its video pads instead, so all is fine then too) */
- }
-
+ gst_event_copy_segment (event, &self->segment);
+ GST_DEBUG_OBJECT (self, "newsegment (%s)",
+ gst_format_get_name (self->segment.format));
+
+ /* if not time format, we'll either start with a 0 timestamp anyway or
+ * it's following a seek in which case we'll have saved the requested
+ * seek segment and don't want to overwrite it (remember that on a seek
+ * we always just seek back to the start in BYTES format and just throw
+ * away all text that's before the requested position; if the subtitles
+ * come from an upstream demuxer, it won't be able to handle our BYTES
+ * seek request and instead send us a newsegment from the seek request
+ * it received via its video pads instead, so all is fine then too) */
ret = TRUE;
gst_event_unref (event);
break;
break;
}
- ret = parent_class->change_state (element, transition);
+ ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
if (ret == GST_STATE_CHANGE_FAILURE)
return ret;