subparse: Add drop-out-of-segment property 72/267272/5 accepted/tizen_unified tizen accepted/tizen/unified/20211202.120742 submit/tizen/20211201.073856
authorGilbok Lee <gilbok.lee@samsung.com>
Wed, 1 Dec 2021 00:34:36 +0000 (09:34 +0900)
committerGilbok Lee <gilbok.lee@samsung.com>
Wed, 1 Dec 2021 06:38:03 +0000 (15:38 +0900)
- When property 'drop-out-of-segment' is set to false,
  subparser will not drop the buffer even
  the start time of the parsed buffer is out of the segment.

Change-Id: Ia7d84ad26c2e93cda46778c86d35bd67442e907b

gst/subparse/gstsubparse.c
gst/subparse/gstsubparse.h
packaging/gst-plugins-base.spec

index 38b1d2c..b2e55d7 100644 (file)
@@ -46,7 +46,6 @@ GST_DEBUG_CATEGORY (sub_parse_debug);
 #define SUBPARSE_SEEK_TRYLOCK(elem)     g_mutex_trylock(SUBPARSE_SEEK_GET_LOCK(elem))
 #define SUBPARSE_SEEK_UNLOCK(elem)      g_mutex_unlock(SUBPARSE_SEEK_GET_LOCK(elem))
 #endif
-
 #define DEFAULT_ENCODING   NULL
 #define ATTRIBUTE_REGEX "\\s?[a-zA-Z0-9\\. \t\\(\\)]*"
 static const gchar *allowed_srt_tags[] = { "i", "b", "u", NULL };
@@ -56,13 +55,19 @@ static const gchar *allowed_vtt_tags[] =
 #ifdef TIZEN_FEATURE_SUBPARSE_MODIFICATION
 #define DEFAULT_CURRENT_LANGUAGE   NULL
 #endif
+#ifdef TIZEN_FEATURE_SUBPARSE_DROP_OUT_OF_SEGMENT
+#define DEFAULT_DROP_OUT_OF_SEGMENT TRUE
+#endif
 enum
 {
   PROP_0,
   PROP_ENCODING,
   PROP_VIDEOFPS,
 #ifdef TIZEN_FEATURE_SUBPARSE_MODIFICATION
-  PROP_EXTSUB_CURRENT_LANGUAGE
+  PROP_EXTSUB_CURRENT_LANGUAGE,
+#endif
+#ifdef TIZEN_FEATURE_SUBPARSE_DROP_OUT_OF_SEGMENT
+  PROP_DROP_OUT_OF_SEGMENT,
 #endif
 };
 #ifdef TIZEN_FEATURE_HLS_WEBVTT
@@ -188,6 +193,15 @@ gst_sub_parse_class_init (GstSubParseClass * klass)
           DEFAULT_CURRENT_LANGUAGE,
           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 #endif
+
+#ifdef TIZEN_FEATURE_SUBPARSE_DROP_OUT_OF_SEGMENT
+  g_object_class_install_property (object_class, PROP_DROP_OUT_OF_SEGMENT,
+      g_param_spec_boolean ("drop-out-of-segment",
+          "Drop out-of-segment buffers",
+          "Drop and don't send out-of-segment buffers",
+          DEFAULT_DROP_OUT_OF_SEGMENT,
+          G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+#endif
 }
 
 static void
@@ -225,9 +239,11 @@ gst_sub_parse_init (GstSubParse * subparse)
   subparse->state.language_list = NULL;
   subparse->state.current_language = NULL;
   subparse->state.langlist_msg_posted = FALSE;
-
   g_mutex_init (&subparse->seek_lock);
 #endif
+#ifdef TIZEN_FEATURE_SUBPARSE_DROP_OUT_OF_SEGMENT
+  subparse->state.drop_out_of_segment = DEFAULT_DROP_OUT_OF_SEGMENT;
+#endif
 }
 
 /*
@@ -413,6 +429,13 @@ gst_sub_parse_set_property (GObject * object, guint prop_id,
       sami_context_change_language (&subparse->state);
       break;
 #endif
+#ifdef TIZEN_FEATURE_SUBPARSE_DROP_OUT_OF_SEGMENT
+    case PROP_DROP_OUT_OF_SEGMENT:
+      subparse->state.drop_out_of_segment = g_value_get_boolean (value);
+      GST_DEBUG_OBJECT (object, "Drop out of segment set to %d",
+          subparse->state.drop_out_of_segment);
+      break;
+#endif
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -439,6 +462,11 @@ gst_sub_parse_get_property (GObject * object, guint prop_id,
       g_value_set_string (value, subparse->state.current_language);
       break;
 #endif
+#ifdef TIZEN_FEATURE_SUBPARSE_DROP_OUT_OF_SEGMENT
+    case PROP_DROP_OUT_OF_SEGMENT:
+      g_value_set_boolean (value, subparse->state.drop_out_of_segment);
+      break;
+#endif
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -685,6 +713,9 @@ parse_mdvdsub (ParserState * state, const gchar * line)
       state->fps_n);
 
   /* Check our segment start/stop */
+#ifdef TIZEN_FEATURE_SUBPARSE_DROP_OUT_OF_SEGMENT
+  if (state->drop_out_of_segment) {
+#endif
   in_seg = gst_segment_clip (state->segment, GST_FORMAT_TIME,
       state->start_time, state->start_time + state->duration, &clip_start,
       &clip_stop);
@@ -696,6 +727,9 @@ parse_mdvdsub (ParserState * state, const gchar * line)
   } else {
     return NULL;
   }
+#ifdef TIZEN_FEATURE_SUBPARSE_DROP_OUT_OF_SEGMENT
+  }
+#endif
 
   markup = g_string_new (NULL);
   while (1) {
@@ -1187,9 +1221,17 @@ parse_subrip (ParserState * state, const gchar * line)
       if ((end_time = strstr (line, " --> ")) &&
           parse_subrip_time (line, &ts_start) &&
           parse_subrip_time (end_time + strlen (" --> "), &ts_end) &&
+#ifdef TIZEN_FEATURE_HLS_WEBVTT
+          state->start_time <=
+              ts_end + MPEGTIME_TO_GSTTIME (state->mpegts) - state->local) {
+#else
           state->start_time <= ts_end) {
+#endif
         state->state = 2;
         state->start_time = ts_start;
+#ifdef TIZEN_FEATURE_HLS_WEBVTT
+        state->start_time += MPEGTIME_TO_GSTTIME (state->mpegts) - state->local;
+#endif
         state->duration = ts_end - ts_start;
       } else {
         GST_DEBUG ("error parsing subrip time line '%s'", line);
@@ -1200,6 +1242,9 @@ parse_subrip (ParserState * state, const gchar * line)
     case 2:
     {
       /* No need to parse that text if it's out of segment */
+#ifdef TIZEN_FEATURE_SUBPARSE_DROP_OUT_OF_SEGMENT
+      if (state->drop_out_of_segment) {
+#endif
       guint64 clip_start = 0, clip_stop = 0;
       gboolean in_seg = FALSE;
 
@@ -1215,6 +1260,9 @@ parse_subrip (ParserState * state, const gchar * line)
         state->state = 0;
         return NULL;
       }
+#ifdef TIZEN_FEATURE_SUBPARSE_DROP_OUT_OF_SEGMENT
+      }
+#endif
     }
       /* looking for subtitle text; empty line ends this subtitle entry */
       if (state->buf->len)
@@ -1377,6 +1425,9 @@ parse_subviewer (ParserState * state, const gchar * line)
     case 1:
     {
       /* No need to parse that text if it's out of segment */
+#ifdef TIZEN_FEATURE_SUBPARSE_DROP_OUT_OF_SEGMENT
+      if (state->drop_out_of_segment) {
+#endif
       guint64 clip_start = 0, clip_stop = 0;
       gboolean in_seg = FALSE;
 
@@ -1392,6 +1443,9 @@ parse_subviewer (ParserState * state, const gchar * line)
         state->state = 0;
         return NULL;
       }
+#ifdef TIZEN_FEATURE_SUBPARSE_DROP_OUT_OF_SEGMENT
+      }
+#endif
     }
       /* looking for subtitle text; empty line ends this subtitle entry */
       if (state->buf->len)
@@ -1429,6 +1483,9 @@ parse_mpsub (ParserState * state, const gchar * line)
       return NULL;
     case 1:
     {                           /* No need to parse that text if it's out of segment */
+#ifdef TIZEN_FEATURE_SUBPARSE_DROP_OUT_OF_SEGMENT
+      if (state->drop_out_of_segment) {
+#endif
       guint64 clip_start = 0, clip_stop = 0;
       gboolean in_seg = FALSE;
 
@@ -1444,6 +1501,9 @@ parse_mpsub (ParserState * state, const gchar * line)
         state->state = 0;
         return NULL;
       }
+#ifdef TIZEN_FEATURE_SUBPARSE_DROP_OUT_OF_SEGMENT
+      }
+#endif
     }
       /* looking for subtitle text; empty line ends this
        * subtitle entry */
@@ -1506,7 +1566,9 @@ parse_dks (ParserState * state, const gchar * line)
         GST_WARNING ("Failed to parse subtitle end time");
         return NULL;
       }
-
+#ifdef TIZEN_FEATURE_SUBPARSE_DROP_OUT_OF_SEGMENT
+      if (state->drop_out_of_segment) {
+#endif
       /* Check if this subtitle is out of the current segment */
       in_seg = gst_segment_clip (state->segment, GST_FORMAT_TIME,
           state->start_time, state->start_time + state->duration,
@@ -1515,6 +1577,9 @@ parse_dks (ParserState * state, const gchar * line)
       if (!in_seg) {
         return NULL;
       }
+#ifdef TIZEN_FEATURE_SUBPARSE_DROP_OUT_OF_SEGMENT
+      }
+#endif
 
       state->start_time = clip_start;
       state->duration = clip_stop - clip_start;
@@ -1550,15 +1615,6 @@ parser_state_init (ParserState * state)
   state->local = 0;
   state->mpegts = 0;
 #endif
-
-#ifdef TIZEN_FEATURE_SUBPARSE_MODIFICATION
-  state->language_list = NULL;
-
-  g_free (state->current_language);
-  state->current_language = NULL;
-
-  state->langlist_msg_posted = FALSE;
-#endif
 }
 
 static void
index 893f16e..7adb4f3 100644 (file)
@@ -87,6 +87,9 @@ typedef struct {
   guint64 local;
   guint64 mpegts;
 #endif
+#ifdef TIZEN_FEATURE_SUBPARSE_DROP_OUT_OF_SEGMENT
+  gboolean drop_out_of_segment;
+#endif
 } ParserState;
 
 typedef gchar* (*Parser) (ParserState *state, const gchar *line);
index a97d604..42643b9 100644 (file)
@@ -5,7 +5,7 @@
 
 Name:           gst-plugins-base
 Version:        1.16.2
-Release:        22
+Release:        23
 License:        LGPL-2.0+
 Summary:        GStreamer Streaming-Media Framework Plug-Ins
 Url:            http://gstreamer.freedesktop.org/
@@ -91,6 +91,7 @@ export CFLAGS="%{optflags} -fno-strict-aliasing\
  -DTIZEN_FEATURE_DISABLE_MIME_TYPES\
  -DTIZEN_FEATURE_VIDEO_MODIFICATION\
  -DTIZEN_FEATURE_SUBPARSE_MODIFICATION\
+ -DTIZEN_FEATURE_SUBPARSE_DROP_OUT_OF_SEGMENT\
  -DTIZEN_FEATURE_HLS_WEBVTT\
  -DTIZEN_FEATURE_VOLUME_MODIFICATION\
  -DTIZEN_FEATURE_FORCE_SW_DECODER\