From 65262fe0812f26b35471e641c7349f8122255809 Mon Sep 17 00:00:00 2001 From: "Ronald S. Bultje" Date: Sat, 8 Jan 2005 18:22:41 +0000 Subject: OGM text support, Matroska UTF-8 text support, deadlock fixes all over the place, subtitle awareness in decodebin/pla... Original commit message from CVS: * configure.ac: * ext/ogg/gstoggdemux.c: (gst_ogg_pad_new): * ext/ogg/gstogmparse.c: (gst_ogm_text_parse_get_type), (gst_ogm_text_parse_base_init), (gst_ogm_text_parse_init), (gst_ogm_parse_get_sink_querytypes), (gst_ogm_parse_sink_convert), (gst_ogm_parse_sink_query), (gst_ogm_parse_chain), (gst_ogm_parse_plugin_init): * ext/pango/gsttextoverlay.c: (gst_textoverlay_linkedpads), (gst_textoverlay_link), (gst_textoverlay_getcaps), (gst_textoverlay_event), (gst_textoverlay_video_chain), (gst_textoverlay_loop), (gst_textoverlay_init), (plugin_init): * ext/pango/gsttextoverlay.h: * gst/matroska/matroska-demux.c: (gst_matroska_demux_add_stream), (gst_matroska_demux_handle_seek_event), (gst_matroska_demux_sync_streams), (gst_matroska_demux_parse_blockgroup), (gst_matroska_demux_subtitle_caps), (gst_matroska_demux_plugin_init): * gst/matroska/matroska-ids.h: * gst/playback/gstdecodebin.c: (close_pad_link): * gst/playback/gstplaybasebin.c: (gst_play_base_bin_init), (gen_preroll_element), (remove_groups), (add_stream), (new_decoded_pad), (setup_subtitles), (gen_source_element), (setup_source): * gst/playback/gstplaybasebin.h: * gst/playback/gstplaybin.c: (gen_text_element), (setup_sinks): * gst/subparse/Makefile.am: * gst/subparse/gstsubparse.c: (gst_subparse_get_type), (gst_subparse_base_init), (gst_subparse_class_init), (gst_subparse_init), (gst_subparse_formats), (gst_subparse_eventmask), (gst_subparse_event), (gst_subparse_handle_event), (convert_encoding), (get_next_line), (parse_mdvdsub), (parse_mdvdsub_init), (parse_subrip), (parse_subrip_deinit), (parse_subrip_init), (parse_mpsub), (parse_mpsub_deinit), (parse_mpsub_init), (gst_subparse_buffer_format_autodetect), (gst_subparse_format_autodetect), (gst_subparse_loop), (gst_subparse_change_state), (gst_subparse_type_find), (plugin_init): * gst/subparse/gstsubparse.h: * gst/typefind/gsttypefindfunctions.c: (ogmtext_type_find), (plugin_init): Add subtitle support, .sub parser (supports SRT and MPsub), OGM text support, Matroska UTF-8 text support, deadlock fixes all over the place, subtitle awareness in decodebin/playbin and some fixes to textoverlay to handle subtitles in a stream correctly. Fixes #100931. --- gst/matroska/matroska-demux.c | 64 +++++++++++++++++++++++++++++++++++++++++-- gst/matroska/matroska-ids.h | 3 ++ 2 files changed, 64 insertions(+), 3 deletions(-) (limited to 'gst') diff --git a/gst/matroska/matroska-demux.c b/gst/matroska/matroska-demux.c index c816665c..ec085cb8 100644 --- a/gst/matroska/matroska-demux.c +++ b/gst/matroska/matroska-demux.c @@ -313,6 +313,7 @@ gst_matroska_demux_add_stream (GstMatroskaDemux * demux) context->index = demux->num_streams; context->type = 0; /* no type yet */ context->default_duration = 0; + context->pos = 0; demux->num_streams++; /* start with the master */ @@ -1099,7 +1100,9 @@ gst_matroska_demux_handle_seek_event (GstMatroskaDemux * demux) gst_event_ref (event); gst_pad_push (demux->src[i]->pad, GST_DATA (event)); } + demux->src[i]->pos = entry->time; } + demux->pos = entry->time; gst_event_unref (event); @@ -1741,6 +1744,47 @@ gst_matroska_ebmlnum_sint (guint8 * data, guint size, gint64 * num) return res; } +/* + * Mostly used for subtitles. We add void filler data for each + * lagging stream to make sure we don't deadlock. + */ + +static void +gst_matroska_demux_sync_streams (GstMatroskaDemux * demux) +{ + gint stream_nr; + GstMatroskaTrackContext *context; + + GST_DEBUG ("Sync to %" GST_TIME_FORMAT, GST_TIME_ARGS (demux->pos)); + + for (stream_nr = 0; stream_nr < demux->num_streams; stream_nr++) { + context = demux->src[stream_nr]; + if (context->type != GST_MATROSKA_TRACK_TYPE_SUBTITLE) + continue; + GST_DEBUG ("Checking for resync on stream %d (%" GST_TIME_FORMAT ")", + stream_nr, GST_TIME_ARGS (context->pos)); + + /* does it lag? 1 second is a random treshold... */ + if (context->pos + (GST_SECOND / 2) < demux->pos) { + /* send filler */ + GstEvent *event; + + event = gst_event_new_filler_stamped (context->pos, + demux->pos - context->pos); + context->pos = demux->pos; + + /* sync */ + GST_DEBUG ("Synchronizing stream %d with others by sending filler " + "at time %" GST_TIME_FORMAT " and duration %" GST_TIME_FORMAT + " to time %" GST_TIME_FORMAT, stream_nr, + GST_TIME_ARGS (context->pos), + GST_TIME_ARGS (demux->pos - context->pos), + GST_TIME_ARGS (demux->pos)); + gst_pad_push (context->pad, GST_DATA (event)); + } + } +} + static gboolean gst_matroska_demux_parse_blockgroup (GstMatroskaDemux * demux, guint64 cluster_time) @@ -1982,13 +2026,22 @@ gst_matroska_demux_parse_blockgroup (GstMatroskaDemux * demux, GST_BUFFER_TIMESTAMP (sub) = cluster_time; else GST_BUFFER_TIMESTAMP (sub) = cluster_time + time; + demux->pos = GST_BUFFER_TIMESTAMP (sub); } + gst_matroska_demux_sync_streams (demux); + demux->src[stream]->pos = demux->pos; - /* do all laces have the same lenght? */ + /* FIXME: do all laces have the same lenght? */ if (duration) { GST_BUFFER_DURATION (sub) = duration / laces; + demux->src[stream]->pos += GST_BUFFER_DURATION (sub); } + GST_DEBUG ("Pushing data of size %d for stream %d, time=%" + GST_TIME_FORMAT " and duration=%" GST_TIME_FORMAT, + GST_BUFFER_SIZE (sub), stream, + GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (sub)), + GST_TIME_ARGS (GST_BUFFER_DURATION (sub))); gst_pad_push (demux->src[stream]->pad, GST_DATA (sub)); size -= lace_size[n]; @@ -2800,9 +2853,13 @@ static GstCaps * gst_matroska_demux_subtitle_caps (GstMatroskaTrackSubtitleContext * subtitlecontext, const gchar * codec_id, gpointer data, guint size) { + /*GstMatroskaTrackContext *context = + (GstMatroskaTrackContext *) subtitlecontext; */ GstCaps *caps = NULL; - //.. + if (!strcmp (codec_id, GST_MATROSKA_CODEC_ID_SUBTITLE_UTF8)) { + caps = gst_caps_new_simple ("text/plain", NULL); + } return caps; } @@ -2862,7 +2919,8 @@ gst_matroska_demux_plugin_init (GstPlugin * plugin) /* FILLME */ NULL,} , *subtitle_id[] = { - /* FILLME */ + GST_MATROSKA_CODEC_ID_SUBTITLE_UTF8, + /* FILLME */ NULL,}; /* this filter needs the riff parser */ diff --git a/gst/matroska/matroska-ids.h b/gst/matroska/matroska-ids.h index 1c425c17..ec87fa56 100644 --- a/gst/matroska/matroska-ids.h +++ b/gst/matroska/matroska-ids.h @@ -153,6 +153,8 @@ #define GST_MATROSKA_CODEC_ID_AUDIO_TTA "A_TTA1" /* TODO: AC3-9/10 (?), Real, Musepack, Quicktime */ +#define GST_MATROSKA_CODEC_ID_SUBTITLE_UTF8 "S_TEXT/UTF8" + /* * Matrodka tags. Strings. */ @@ -223,6 +225,7 @@ typedef struct _GstMatroskaTrackContext { guint uid, num; GstMatroskaTrackFlags flags; guint64 default_duration; + guint64 pos; } GstMatroskaTrackContext; typedef struct _GstMatroskaTrackVideoContext { -- cgit