timecodestamper: Only allow requesting LTC audio pad in NULL/READY states
authorSebastian Dröge <sebastian@centricular.com>
Thu, 9 Jan 2020 13:27:28 +0000 (15:27 +0200)
committerSebastian Dröge <sebastian@centricular.com>
Fri, 10 Jan 2020 13:59:21 +0000 (15:59 +0200)
And don't introduce any latency at all if not LTC audio pad was
requested.

gst/timecode/gsttimecodestamper.c

index d86a6ee..8e2051a 100644 (file)
@@ -877,7 +877,7 @@ gst_timecodestamper_query (GstBaseTransform * trans,
       g_mutex_lock (&timecodestamper->mutex);
       if (res && timecodestamper->vinfo.fps_n && timecodestamper->vinfo.fps_d) {
         gst_query_parse_latency (query, &live, &min_latency, &max_latency);
-        if (live) {
+        if (live && timecodestamper->ltcpad) {
           /* Introduce additional 8 frames of latency for LTC processing as
            * the LTC library seems to usually lag behind 1-6 frames with the
            * values reported back to us. */
@@ -1171,7 +1171,7 @@ gst_timecodestamper_transform_ip (GstBaseTransform * vfilter,
 
   /* Update LTC-based timecode as needed */
 #if HAVE_LTC
-  {
+  if (timecodestamper->ltcpad) {
     GstClockTime frame_duration;
     gchar *tc_str;
     LTCFrameExt ltc_frame;
@@ -1520,6 +1520,14 @@ gst_timecodestamper_request_new_pad (GstElement * element,
     return NULL;
   }
 
+  if (GST_STATE (timecodestamper) > GST_STATE_READY ||
+      GST_STATE_TARGET (timecodestamper) > GST_STATE_READY) {
+    GST_ERROR_OBJECT (timecodestamper,
+        "LTC audio pad can only be requested in NULL or READY state");
+    GST_OBJECT_UNLOCK (timecodestamper);
+    return NULL;
+  }
+
   timecodestamper->ltcpad = gst_pad_new_from_static_template
       (&gst_timecodestamper_ltc_template, "ltc_sink");