Limit duration to a maximum of five seconds for tmplayer format where we can guess...
authorTim-Philipp Müller <tim@centricular.net>
Sun, 25 May 2008 20:51:35 +0000 (20:51 +0000)
committerTim-Philipp Müller <tim@centricular.net>
Sun, 25 May 2008 20:51:35 +0000 (20:51 +0000)
Original commit message from CVS:
* gst/subparse/gstsubparse.c: (parser_state_init),
(gst_sub_parse_format_autodetect), (handle_buffer):
* gst/subparse/gstsubparse.h:
* tests/check/elements/subparse.c: (test_tmplayer_style3b):
Limit duration to a maximum of five seconds for tmplayer format where
we can guess the duration only from the timestamp of the next line of
text. We don't want to show a text for eternities just because nothing
else is being said for a while.

ChangeLog
gst/subparse/gstsubparse.c
gst/subparse/gstsubparse.h
tests/check/elements/subparse.c

index 3209e28..c66fdfd 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2008-05-25  Tim-Philipp Müller  <tim.muller at collabora co uk>
+
+       * gst/subparse/gstsubparse.c: (parser_state_init),
+         (gst_sub_parse_format_autodetect), (handle_buffer):
+       * gst/subparse/gstsubparse.h:
+       * tests/check/elements/subparse.c: (test_tmplayer_style3b):
+         Limit duration to a maximum of five seconds for tmplayer format where
+         we can guess the duration only from the timestamp of the next line of
+         text. We don't want to show a text for eternities just because nothing
+         else is being said for a while.
+
 2008-05-23  Wim Taymans  <wim.taymans@collabora.co.uk>
 
        * gst-libs/gst/rtp/gstbasertpdepayload.c:
index 1cd68d5..87a7c9c 100644 (file)
@@ -870,6 +870,7 @@ parser_state_init (ParserState * state)
 
   state->start_time = 0;
   state->duration = 0;
+  state->max_duration = 0;      /* no limit */
   state->state = 0;
   state->segment = NULL;
 }
@@ -991,6 +992,7 @@ gst_sub_parse_format_autodetect (GstSubParse * self)
       return gst_caps_new_simple ("text/x-pango-markup", NULL);
     case GST_SUB_PARSE_FORMAT_TMPLAYER:
       self->parse_line = parse_tmplayer;
+      self->state.max_duration = 5 * GST_SECOND;
       return gst_caps_new_simple ("text/plain", NULL);
     case GST_SUB_PARSE_FORMAT_MPL2:
       self->parse_line = parse_mpl2;
@@ -1083,6 +1085,16 @@ handle_buffer (GstSubParse * self, GstBuffer * buf)
         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);
 
index 1e3f348..86bf301 100644 (file)
@@ -60,6 +60,7 @@ typedef struct {
   GString *buf;
   guint64  start_time;
   guint64  duration;
+  guint64  max_duration; /* to clamp duration, 0 = no limit (used by tmplayer parser) */
   GstSegment *segment;
   gpointer user_data;
   gdouble  fps;          /* used by microdvd parser */
index c0b5c45..c5127b7 100644 (file)
@@ -389,6 +389,8 @@ GST_START_TEST (test_tmplayer_style3)
 
 GST_END_TEST;
 
+/* also tests the max_duration stuff (see second-last chunk which is supposed
+ * to be clipped to 5s duration) */
 GST_START_TEST (test_tmplayer_style3b)
 {
   static SubParseInputChunk tmplayer_style3b_input[] = {
@@ -399,8 +401,10 @@ GST_START_TEST (test_tmplayer_style3b)
           "0:00:14:a lush and fertile planet.\n",
           14 * GST_SECOND, 16 * GST_SECOND,
         "a lush and fertile planet."}, {
-          "0:00:16:Yet another line.",
-        16 * GST_SECOND, GST_CLOCK_TIME_NONE, "Yet another line."}
+          "0:00:16:And they liked it a lot.\n",
+        16 * GST_SECOND, (16 + 5) * GST_SECOND, "And they liked it a lot."}, {
+          "0:00:30:Last line.",
+        30 * GST_SECOND, GST_CLOCK_TIME_NONE, "Last line."}
   };
 
   test_tmplayer_do_test (tmplayer_style3b_input,