RidgeRun / gst-shark

GstShark is a front-end for GStreamer traces
GNU Lesser General Public License v2.1
92 stars 45 forks source link

rtspsrc and interlatency tracer #102

Open nicolone opened 3 years ago

nicolone commented 3 years ago

@michaelgruner It seems that your fix https://github.com/RidgeRun/gst-shark/pull/93 solved the SegFaults, but it skips interlatency tracing for source pads with no parent.

For example, I don't get any interlatency tracing for the following simple pipeline with a public stream:

GST_DEBUG="GST_TRACER:7" GST_TRACERS="interlatency" gst-launch-1.0 \
rtspsrc location=rtsp://demo:demo@ipvmdemo.dyndns.org:5541/onvif-media/media.amp?profile=profile_1_h264&sessiontimeout=60&streamtype=unicast protocols=tcp \
! rtph264depay ! h264parse ! fakesink

Instead I get the following warning many times printed on the screen:

** (gst-launch-1.0:22154): CRITICAL **: 12:35:02.973: calculate_latency: assertion 'parent' failed

Is there a way to make the interlatency tracing work with the rtspsrc element? Maybe adding a parent to the rtspsrc element?

nicolone commented 3 years ago

BTW: other tracers like framerate and proctime have a similar issue with SEGFAULTs like interlatency had before:

gst_shark_tracer_hook_pad_push_pre (object=0x555555923570, ts=1466896730, pad=0x7fffe805a7c0, buffer=0x555555a2d6c0) at gstsharktracer.c:411
nicolone commented 3 years ago

I forgot to mention that I use the master of gstreamer (version 1.19.1.1) and master of gst-shark.

nicolone commented 3 years ago

The following patch seems to fix it:

diff --git a/plugins/tracers/gstinterlatency.c b/plugins/tracers/gstinterlatency.c
index b8475af..0e579c1 100644
--- a/plugins/tracers/gstinterlatency.c
+++ b/plugins/tracers/gstinterlatency.c
@@ -101,11 +101,23 @@ get_real_pad_parent (GstPad * pad)
     return NULL;

   parent = GST_OBJECT_PARENT (pad);
+  if (parent == NULL) {
+    gpointer private_data = gst_pad_get_element_private(pad);
+    if (GST_IS_ELEMENT(private_data)) {
+      parent = GST_OBJECT_CAST (private_data);
+    }
+  }

   /* if parent of pad is a ghost-pad, then pad is a proxy_pad */
   if (parent && GST_IS_GHOST_PAD (parent)) {
     pad = GST_PAD_CAST (parent);
     parent = GST_OBJECT_PARENT (pad);
+    if (parent == NULL) {
+      gpointer private_data = gst_pad_get_element_private(pad);
+      if (GST_IS_ELEMENT(private_data)) {
+        parent = GST_OBJECT_CAST (private_data);
+      }
+    }
   }

   return GST_ELEMENT_CAST (parent);
@@ -157,7 +169,8 @@ send_latency_probe (GstElement * parent, GstPad * pad, guint64 ts)
   g_return_if_fail (parent);
   g_return_if_fail (pad);

-  if (!GST_IS_BIN (parent)) {
+  // TODO why was this implemented: if (!GST_IS_BIN (parent)) {
+  {
     GstEvent *latency_probe = gst_event_new_custom (GST_EVENT_CUSTOM_DOWNSTREAM,
         gst_structure_new_id (latency_probe_id,
             latency_probe_pad, GST_TYPE_PAD, pad,
@@ -172,12 +185,16 @@ calculate_latency (GstInterLatencyTracer * interlatency_tracer,
     GstElement * parent, GstPad * pad, guint64 ts)
 {
   g_return_if_fail (interlatency_tracer);
-  g_return_if_fail (parent);
   g_return_if_fail (pad);

+  if (parent == NULL) {
+    parent = get_real_pad_parent(pad);
+    g_return_if_fail (parent);
+  }
+ 
   if (!GST_IS_BIN (parent)) {
     GstEvent *ev = g_object_get_qdata ((GObject *) pad, latency_probe_id);
-
+ 
     if (GST_IS_EVENT (ev))
       log_latency (interlatency_tracer, gst_event_get_structure (ev), pad, ts);
   }
diff --git a/plugins/tracers/gstproctime.c b/plugins/tracers/gstproctime.c
index 643e0fa..23b5703 100644
--- a/plugins/tracers/gstproctime.c
+++ b/plugins/tracers/gstproctime.c
@@ -75,11 +75,17 @@ do_push_buffer_pre (GstTracer * self, guint64 ts, GstPad * pad)
   gchar *time_string;
   gboolean should_log;
   gboolean should_calculate;
+  GstObject* parent;

   proc_time_tracer = GST_PROC_TIME_TRACER (self);
   shark_tracer = GST_SHARK_TRACER (proc_time_tracer);
   proc_time = proc_time_tracer->proc_time;
-  name = GST_OBJECT_NAME (GST_OBJECT_PARENT (pad));
+  parent = GST_OBJECT_PARENT (pad);
+  if (parent) {
+    name = GST_OBJECT_NAME (parent);
+  } else {
+    return;
+  }

   pad_peer = gst_pad_get_peer (pad);
   if (!pad_peer) {
diff --git a/plugins/tracers/gstsharktracer.c b/plugins/tracers/gstsharktracer.c
index 12c4539..3527733 100644
--- a/plugins/tracers/gstsharktracer.c
+++ b/plugins/tracers/gstsharktracer.c
@@ -406,8 +406,14 @@ gst_shark_tracer_hook_pad_push_pre (GObject * object, GstClockTime ts,
   GstSharkTracerPrivate *priv = GST_SHARK_TRACER_PRIVATE (self);
   GCallback hook;
   const gchar *elname;
+  GstObject* parent;

-  elname = GST_OBJECT_NAME (GST_OBJECT_PARENT (pad));
+  parent = GST_OBJECT_PARENT (pad);
+  if (parent) {
+    elname = GST_OBJECT_NAME (parent);
+  } else {
+    elname = GST_OBJECT_NAME (pad);
+  }
   if (FALSE == gst_shark_tracer_element_is_filtered (self, elname)) {
     return;
   }
diff --git a/scripts/graphics/gstshark-plot b/scripts/graphics/gstshark-plot
index fd185b8..473a9c4 100755
--- a/scripts/graphics/gstshark-plot
+++ b/scripts/graphics/gstshark-plot
@@ -185,7 +185,8 @@ do
 done

 # Create plots
-octave -qf ${PERSIST} ./gstshark-plot.m "${processing_tracer_list[@]}" "${SAVEFIG}" "${FORMAT}" "${LEGEND}"
+SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
+octave -qf ${PERSIST} --path "${SCRIPT_DIR}" "${SCRIPT_DIR}/gstshark-plot.m" "${processing_tracer_list[@]}" "${SAVEFIG}" "${FORMAT}" "${LEGEND}"

 # Remove files
 rm -f datastream.log
michaelgruner commented 2 years ago

Thanks for sharing, checking now.

nicolone commented 2 years ago

Any updates?

supremassi commented 2 years ago

Hello, So I tried your patched but the same error remains :

** (gst-launch-1.0:4695): CRITICAL **: 09:29:59.956: calculate_latency: assertion 'parent' failed and this is the command line I used :

GST_DEBUG="GST_TRACER:7" GST_TRACERS="interlatency" gst-launch-1.0 rtspsrc location=rtsp://admin:admin1357@192.168.88.10:554/Stream1 ! rtph264depay ! h264parse ! avdec_h264 ! videoconvert ! autovideosink sync=true

I'm trying to get the latency of gstreamer to decode et play a live rtsp stream from my ip camera

Have you any suggestion ?

Thank you for your help

nicolone commented 2 years ago

You might want to add the environment variables: GST_SHARK_LOCATION="gstshark_tracer_directory" GST_SHARK_FILE_BUFFERING=0

Otherwise you might want to look for other errors with GST_DEBUG="6,GST_TRACER:7". Good luck and please post your fixes here again ;-)