<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p>Hi,</p>
    <p>I have made some python wrappers for easier building gstreamer
      applications.<br>
      And in there I have added some debug/performance measure tools.<br>
      I have done that using buffer probes.</p>
    <p>I think your problem is that the buffers you get from 'rtspsrc'
      are not necessarily frames (I guess depending on format, packet
      sizes, ...).<br>
      So I would recommend you measure after 'decodebin', there you
      should get frames.</p>
    <p>This is how I measured "performance" using buffer probes on
      specific elements:<br>
    </p>
    <div style="color: #d4d4d4;background-color: #1e1e1e;font-family: 'Droid Sans Mono', 'monospace', monospace;font-weight: normal;font-size: 14px;line-height: 19px;white-space: pre;"><div><span style="color: #569cd6;">def</span><span style="color: #d4d4d4;"> </span><span style="color: #dcdcaa;">measure_elem_stats</span><span style="color: #d4d4d4;">(</span><span style="color: #9cdcfe;">self</span><span style="color: #d4d4d4;">, </span><span style="color: #9cdcfe;">elem</span><span style="color: #d4d4d4;">: Gst.Element) -> </span><span style="color: #569cd6;">None</span><span style="color: #d4d4d4;">:</span></div><div><span style="color: #d4d4d4;">        </span><span style="color: #ce9178;">"""Measure bitrate, fps and latency of gstreamer element"""</span></div><div><span style="color: #d4d4d4;">        </span><span style="color: #9cdcfe;">stats</span><span style="color: #d4d4d4;"> = </span><span style="color: #4ec9b0;">GstPipeline</span><span style="color: #d4d4d4;">.</span><span style="color: #4ec9b0;">GstElementStats</span><span style="color: #d4d4d4;">(</span><span style="color: #9cdcfe;">elem</span><span style="color: #d4d4d4;">)</span></div><div><span style="color: #d4d4d4;">        </span><span style="color: #dcdcaa;">add_buffer_probe</span><span style="color: #d4d4d4;">(</span><span style="color: #9cdcfe;">elem</span><span style="color: #d4d4d4;">, </span><span style="color: #ce9178;">"src"</span><span style="color: #d4d4d4;">, </span><span style="color: #9cdcfe;">self</span><span style="color: #d4d4d4;">.</span><span style="color: #dcdcaa;">_calc_stats</span><span style="color: #d4d4d4;">, </span><span style="color: #9cdcfe;">stats</span><span style="color: #d4d4d4;">)</span></div><div><span style="color: #d4d4d4;">        </span><span style="color: #dcdcaa;">add_buffer_probe</span><span style="color: #d4d4d4;">(</span><span style="color: #9cdcfe;">elem</span><span style="color: #d4d4d4;">, </span><span style="color: #ce9178;">"sink"</span><span style="color: #d4d4d4;">, </span><span style="color: #9cdcfe;">self</span><span style="color: #d4d4d4;">.</span><span style="color: #dcdcaa;">_probe_in</span><span style="color: #d4d4d4;">, </span><span style="color: #9cdcfe;">stats</span><span style="color: #d4d4d4;">)</span></div><div><span style="color: #d4d4d4;">
</span></div><div>
<div style="color: #d4d4d4;background-color: #1e1e1e;font-family: 'Droid Sans Mono', 'monospace', monospace;font-weight: normal;font-size: 14px;line-height: 19px;white-space: pre;"><div><span style="color: #569cd6;">def</span><span style="color: #d4d4d4;"> </span><span style="color: #dcdcaa;">add_buffer_probe</span><span style="color: #d4d4d4;">(</span></div><div><span style="color: #d4d4d4;">    </span><span style="color: #9cdcfe;">elem</span><span style="color: #d4d4d4;">: Gst.Element,</span></div><div><span style="color: #d4d4d4;">    </span><span style="color: #9cdcfe;">pad_name</span><span style="color: #d4d4d4;">: </span><span style="color: #4ec9b0;">str</span><span style="color: #d4d4d4;">,</span></div><div><span style="color: #d4d4d4;">    </span><span style="color: #9cdcfe;">func</span><span style="color: #d4d4d4;">,</span></div><div><span style="color: #d4d4d4;">    </span><span style="color: #9cdcfe;">data</span><span style="color: #d4d4d4;">: </span><span style="color: #4ec9b0;">Optional</span><span style="color: #d4d4d4;">[</span><span style="color: #4ec9b0;">object</span><span style="color: #d4d4d4;">] = </span><span style="color: #569cd6;">None</span><span style="color: #d4d4d4;">,</span></div><div><span style="color: #d4d4d4;">) -> </span><span style="color: #4ec9b0;">bool</span><span style="color: #d4d4d4;">:</span></div><div><span style="color: #d4d4d4;">    </span><span style="color: #ce9178;">"""Add a buffer probe to pad of element</span></div>
<div><span style="color: #ce9178;">    :param elem: element to probe</span></div><div><span style="color: #ce9178;">    :param pad_name: name of the pad to probe, normally 'sink' or 'src'</span></div><div><span style="color: #ce9178;">    :param func: callback function called when a buffer is received on the pad</span></div><div><span style="color: #ce9178;">    :param data: optional data to pass to probe function, defaults to None</span></div><div><span style="color: #ce9178;">    :return: True if the probe was sucessfully installed,</span></div><div><span style="color: #ce9178;">             False otherwise.</span></div><div><span style="color: #ce9178;">    """</span></div><div><span style="color: #d4d4d4;">    </span><span style="color: #c586c0;">if</span><span style="color: #d4d4d4;"> </span><span style="color: #569cd6;">not</span><span style="color: #d4d4d4;"> </span><span style="color: #9cdcfe;">elem</span><span style="color: #d4d4d4;">:</span></div><div><span style="color: #d4d4d4;">        </span><span style="color: #c586c0;">return</span><span style="color: #d4d4d4;"> </span><span style="color: #569cd6;">False</span></div><div><span style="color: #d4d4d4;">    </span><span style="color: #9cdcfe;">pad</span><span style="color: #d4d4d4;"> = </span><span style="color: #9cdcfe;">elem</span><span style="color: #d4d4d4;">.get_static_pad(</span><span style="color: #9cdcfe;">pad_name</span><span style="color: #d4d4d4;">)</span></div><div><span style="color: #d4d4d4;">    </span><span style="color: #c586c0;">if</span><span style="color: #d4d4d4;"> </span><span style="color: #569cd6;">not</span><span style="color: #d4d4d4;"> </span><span style="color: #9cdcfe;">pad</span><span style="color: #d4d4d4;">:</span></div><div><span style="color: #d4d4d4;">        </span><span style="color: #6a9955;"># print(f"Couldn't find {elem.name}::{pad_name}")</span></div><div><span style="color: #d4d4d4;">        </span><span style="color: #c586c0;">return</span><span style="color: #d4d4d4;"> </span><span style="color: #569cd6;">False</span></div>
<div><span style="color: #d4d4d4;">    </span><span style="color: #9cdcfe;">pad</span><span style="color: #d4d4d4;">.add_probe(Gst.PadProbeType.BUFFER, </span><span style="color: #9cdcfe;">func</span><span style="color: #d4d4d4;">, </span><span style="color: #9cdcfe;">data</span><span style="color: #d4d4d4;">)</span></div>
<div><span style="color: #d4d4d4;">    </span><span style="color: #c586c0;">return</span><span style="color: #d4d4d4;"> </span><span style="color: #569cd6;">True</span></div><div><span style="color: #569cd6;">
</span></div><div>
<div style="color: #d4d4d4;background-color: #1e1e1e;font-family: 'Droid Sans Mono', 'monospace', monospace;font-weight: normal;font-size: 14px;line-height: 19px;white-space: pre;"><div><span style="color: #569cd6;">def</span><span style="color: #d4d4d4;"> </span><span style="color: #dcdcaa;">_calc_stats</span><span style="color: #d4d4d4;">(</span></div><div><span style="color: #d4d4d4;">        </span><span style="color: #9cdcfe;">self</span><span style="color: #d4d4d4;">, </span><span style="color: #9cdcfe;">pad</span><span style="color: #d4d4d4;">: Gst.Pad, </span><span style="color: #9cdcfe;">info</span><span style="color: #d4d4d4;">: Gst.PadProbeInfo, </span><span style="color: #9cdcfe;">stats</span><span style="color: #d4d4d4;">: </span><span style="color: #4ec9b0;">GstElementStats</span></div><div><span style="color: #d4d4d4;">    ) -> Gst.PadProbeReturn:</span></div><div><span style="color: #d4d4d4;">        </span><span style="color: #ce9178;">"""Callback of buffer probe for measuring bitrate, fps and latency"""</span></div><div><span style="color: #d4d4d4;">        </span><span style="color: #9cdcfe;">buf</span><span style="color: #d4d4d4;"> = </span><span style="color: #9cdcfe;">info</span><span style="color: #d4d4d4;">.get_buffer()</span></div><div><span style="color: #d4d4d4;">        </span><span style="color: #9cdcfe;">time</span><span style="color: #d4d4d4;"> = </span><span style="color: #9cdcfe;">self</span><span style="color: #d4d4d4;">.</span><span style="color: #dcdcaa;">get_pipe_timestamp</span><span style="color: #d4d4d4;">()</span></div><div><span style="color: #d4d4d4;">        </span><span style="color: #9cdcfe;">diff</span><span style="color: #d4d4d4;"> = </span><span style="color: #9cdcfe;">time</span><span style="color: #d4d4d4;"> - </span><span style="color: #9cdcfe;">buf</span><span style="color: #d4d4d4;">.pts  </span><span style="color: #6a9955;"># total latency from src</span></div><div><span style="color: #d4d4d4;">        </span><span style="color: #9cdcfe;">elapsed</span><span style="color: #d4d4d4;"> = </span><span style="color: #9cdcfe;">time</span><span style="color: #d4d4d4;"> - </span><span style="color: #9cdcfe;">stats</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">perf_sink</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">prev_time</span></div>
<div><span style="color: #d4d4d4;">        </span><span style="color: #c586c0;">if</span><span style="color: #d4d4d4;"> </span><span style="color: #569cd6;">not</span><span style="color: #d4d4d4;"> </span><span style="color: #dcdcaa;">is_clock_valid</span><span style="color: #d4d4d4;">(</span><span style="color: #9cdcfe;">stats</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">perf_sink</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">prev_time</span><span style="color: #d4d4d4;">):</span></div><div><span style="color: #d4d4d4;">            </span><span style="color: #9cdcfe;">stats</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">perf_sink</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">prev_time</span><span style="color: #d4d4d4;"> = </span><span style="color: #9cdcfe;">time</span></div><div><span style="color: #d4d4d4;">        </span><span style="color: #c586c0;">elif</span><span style="color: #d4d4d4;"> </span><span style="color: #dcdcaa;">is_clock_valid</span><span style="color: #d4d4d4;">(</span><span style="color: #9cdcfe;">time</span><span style="color: #d4d4d4;">) </span><span style="color: #569cd6;">and</span><span style="color: #d4d4d4;"> </span><span style="color: #9cdcfe;">elapsed</span><span style="color: #d4d4d4;"> > Gst.SECOND:</span></div><div><span style="color: #d4d4d4;">            </span><span style="color: #6a9955;"># frames per second</span></div><div><span style="color: #d4d4d4;">            </span><span style="color: #9cdcfe;">factor_n</span><span style="color: #d4d4d4;"> = </span><span style="color: #9cdcfe;">elapsed</span><span style="color: #d4d4d4;"> / Gst.MSECOND</span></div><div><span style="color: #d4d4d4;">            </span><span style="color: #9cdcfe;">factor_d</span><span style="color: #d4d4d4;"> = Gst.SECOND / Gst.MSECOND</span></div>
<div><span style="color: #d4d4d4;">            </span><span style="color: #6a9955;"># bytes per second</span></div><div><span style="color: #d4d4d4;">            </span><span style="color: #9cdcfe;">bps</span><span style="color: #d4d4d4;"> = </span><span style="color: #9cdcfe;">stats</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">perf_sink</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">bps</span><span style="color: #d4d4d4;"> * </span><span style="color: #9cdcfe;">factor_d</span><span style="color: #d4d4d4;"> / </span><span style="color: #9cdcfe;">factor_n</span></div><div><span style="color: #d4d4d4;">            </span><span style="color: #9cdcfe;">stats</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">bitrate</span><span style="color: #d4d4d4;"> = </span><span style="color: #9cdcfe;">bps</span><span style="color: #d4d4d4;"> / (</span><span style="color: #b5cea8;">1024</span><span style="color: #d4d4d4;"> * </span><span style="color: #b5cea8;">1024</span><span style="color: #d4d4d4;"> / </span><span style="color: #b5cea8;">8</span><span style="color: #d4d4d4;">)  </span><span style="color: #6a9955;"># Mbps</span></div>
<div><span style="color: #d4d4d4;">            </span><span style="color: #9cdcfe;">stats</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">fps</span><span style="color: #d4d4d4;"> = </span><span style="color: #9cdcfe;">stats</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">perf_sink</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">frame_count</span><span style="color: #d4d4d4;"> * </span><span style="color: #9cdcfe;">factor_d</span><span style="color: #d4d4d4;"> / </span><span style="color: #9cdcfe;">factor_n</span></div>
<div><span style="color: #d4d4d4;">            </span><span style="color: #9cdcfe;">latency</span><span style="color: #d4d4d4;"> = </span><span style="color: #9cdcfe;">stats</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">perf_sink</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">latency</span><span style="color: #d4d4d4;"> / </span><span style="color: #9cdcfe;">stats</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">perf_sink</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">frame_count</span></div><div><span style="color: #d4d4d4;">            </span><span style="color: #9cdcfe;">stats</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">elem_latency</span><span style="color: #d4d4d4;"> = </span><span style="color: #9cdcfe;">latency</span><span style="color: #d4d4d4;"> - </span><span style="color: #9cdcfe;">stats</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">src_latency</span></div>
<div><span style="color: #d4d4d4;">            </span><span style="color: #9cdcfe;">self</span><span style="color: #d4d4d4;">.__logger.debug(</span></div><div><span style="color: #d4d4d4;">                </span><span style="color: #569cd6;">f</span><span style="color: #ce9178;">"</span><span style="color: #569cd6;">{</span><span style="color: #9cdcfe;">stats</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">elem_name</span><span style="color: #569cd6;">}</span><span style="color: #ce9178;">: "</span></div><div><span style="color: #d4d4d4;">                </span><span style="color: #569cd6;">f</span><span style="color: #ce9178;">"bitrate=</span><span style="color: #569cd6;">{</span><span style="color: #9cdcfe;">stats</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">bitrate</span><span style="color: #569cd6;">}</span><span style="color: #ce9178;"> Mbps "</span></div><div><span style="color: #d4d4d4;">                </span><span style="color: #569cd6;">f</span><span style="color: #ce9178;">"fps=</span><span style="color: #569cd6;">{</span><span style="color: #9cdcfe;">stats</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">fps</span><span style="color: #569cd6;">}</span><span style="color: #ce9178;"> "</span></div><div><span style="color: #d4d4d4;">                </span><span style="color: #569cd6;">f</span><span style="color: #ce9178;">"latency elem=</span><span style="color: #569cd6;">{</span><span style="color: #dcdcaa;">timestamp_msecs</span><span style="color: #d4d4d4;">(</span><span style="color: #9cdcfe;">stats</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">elem_latency</span><span style="color: #d4d4d4;">)</span><span style="color: #569cd6;">}</span><span style="color: #ce9178;"> ms "</span></div><div><span style="color: #d4d4d4;">                </span><span style="color: #569cd6;">f</span><span style="color: #ce9178;">"total=</span><span style="color: #569cd6;">{</span><span style="color: #dcdcaa;">timestamp_msecs</span><span style="color: #d4d4d4;">(</span><span style="color: #9cdcfe;">latency</span><span style="color: #d4d4d4;">)</span><span style="color: #569cd6;">}</span><span style="color: #ce9178;"> ms"</span></div><div><span style="color: #d4d4d4;">            )</span></div><div><span style="color: #d4d4d4;">            </span><span style="color: #9cdcfe;">self</span><span style="color: #d4d4d4;">.</span><span style="color: #dcdcaa;">_plot_stats</span><span style="color: #d4d4d4;">(</span><span style="color: #9cdcfe;">time</span><span style="color: #d4d4d4;">, </span><span style="color: #9cdcfe;">stats</span><span style="color: #d4d4d4;">)</span></div>
<div><span style="color: #d4d4d4;">            </span><span style="color: #9cdcfe;">stats</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">perf_sink</span><span style="color: #d4d4d4;">.</span><span style="color: #dcdcaa;">reset</span><span style="color: #d4d4d4;">(</span><span style="color: #9cdcfe;">time</span><span style="color: #d4d4d4;">)</span></div>
<div><span style="color: #d4d4d4;">        </span><span style="color: #9cdcfe;">stats</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">perf_sink</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">frame_count</span><span style="color: #d4d4d4;"> += </span><span style="color: #b5cea8;">1</span></div><div><span style="color: #d4d4d4;">        </span><span style="color: #9cdcfe;">stats</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">perf_sink</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">bps</span><span style="color: #d4d4d4;"> += </span><span style="color: #9cdcfe;">buf</span><span style="color: #d4d4d4;">.get_size()</span></div><div><span style="color: #d4d4d4;">        </span><span style="color: #9cdcfe;">stats</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">perf_sink</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">latency</span><span style="color: #d4d4d4;"> += </span><span style="color: #9cdcfe;">diff</span></div>
<div><span style="color: #d4d4d4;">        </span><span style="color: #c586c0;">return</span><span style="color: #d4d4d4;"> Gst.PadProbeReturn.OK</span></div><div><span style="color: #d4d4d4;">
</span></div><div>
<div style="color: #d4d4d4;background-color: #1e1e1e;font-family: 'Droid Sans Mono', 'monospace', monospace;font-weight: normal;font-size: 14px;line-height: 19px;white-space: pre;"><div><span style="color: #d4d4d4;">    </span><span style="color: #569cd6;">def</span><span style="color: #d4d4d4;"> </span><span style="color: #dcdcaa;">_probe_in</span><span style="color: #d4d4d4;">(</span></div><div><span style="color: #d4d4d4;">        </span><span style="color: #9cdcfe;">self</span><span style="color: #d4d4d4;">, </span><span style="color: #9cdcfe;">pad</span><span style="color: #d4d4d4;">: Gst.Pad, </span><span style="color: #9cdcfe;">info</span><span style="color: #d4d4d4;">: Gst.PadProbeInfo, </span><span style="color: #9cdcfe;">stats</span><span style="color: #d4d4d4;">: </span><span style="color: #4ec9b0;">GstElementStats</span></div><div><span style="color: #d4d4d4;">    ) -> Gst.PadProbeReturn:</span></div><div><span style="color: #d4d4d4;">        </span><span style="color: #ce9178;">"""Callback of buffer probe for measuring processing time"""</span></div><div><span style="color: #d4d4d4;">        </span><span style="color: #9cdcfe;">buf</span><span style="color: #d4d4d4;"> = </span><span style="color: #9cdcfe;">info</span><span style="color: #d4d4d4;">.get_buffer()</span></div><div><span style="color: #d4d4d4;">        </span><span style="color: #9cdcfe;">time</span><span style="color: #d4d4d4;"> = </span><span style="color: #9cdcfe;">self</span><span style="color: #d4d4d4;">.</span><span style="color: #dcdcaa;">get_pipe_timestamp</span><span style="color: #d4d4d4;">()</span></div><div><span style="color: #d4d4d4;">        </span><span style="color: #9cdcfe;">diff</span><span style="color: #d4d4d4;"> = </span><span style="color: #9cdcfe;">time</span><span style="color: #d4d4d4;"> - </span><span style="color: #9cdcfe;">buf</span><span style="color: #d4d4d4;">.pts  </span><span style="color: #6a9955;"># latency from src</span></div><div><span style="color: #d4d4d4;">        </span><span style="color: #9cdcfe;">elapsed</span><span style="color: #d4d4d4;"> = </span><span style="color: #9cdcfe;">time</span><span style="color: #d4d4d4;"> - </span><span style="color: #9cdcfe;">stats</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">perf_src</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">prev_time</span></div>
<div><span style="color: #d4d4d4;">        </span><span style="color: #c586c0;">if</span><span style="color: #d4d4d4;"> </span><span style="color: #569cd6;">not</span><span style="color: #d4d4d4;"> </span><span style="color: #dcdcaa;">is_clock_valid</span><span style="color: #d4d4d4;">(</span><span style="color: #9cdcfe;">stats</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">perf_src</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">prev_time</span><span style="color: #d4d4d4;">):</span></div><div><span style="color: #d4d4d4;">            </span><span style="color: #9cdcfe;">stats</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">perf_src</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">prev_time</span><span style="color: #d4d4d4;"> = </span><span style="color: #9cdcfe;">time</span></div><div><span style="color: #d4d4d4;">        </span><span style="color: #c586c0;">elif</span><span style="color: #d4d4d4;"> </span><span style="color: #dcdcaa;">is_clock_valid</span><span style="color: #d4d4d4;">(</span><span style="color: #9cdcfe;">time</span><span style="color: #d4d4d4;">) </span><span style="color: #569cd6;">and</span><span style="color: #d4d4d4;"> </span><span style="color: #9cdcfe;">elapsed</span><span style="color: #d4d4d4;"> > Gst.SECOND:</span></div><div><span style="color: #d4d4d4;">            </span><span style="color: #9cdcfe;">stats</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">src_latency</span><span style="color: #d4d4d4;"> = </span><span style="color: #9cdcfe;">stats</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">perf_src</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">latency</span><span style="color: #d4d4d4;"> / </span><span style="color: #9cdcfe;">stats</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">perf_src</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">frame_count</span></div>
<div><span style="color: #d4d4d4;">            </span><span style="color: #6a9955;"># self.__logger.debug(</span></div><div><span style="color: #d4d4d4;">            </span><span style="color: #6a9955;">#    f"{stats.elem_name}: src_latency={latency / Gst.MSECOND} ms"</span></div><div><span style="color: #d4d4d4;">            </span><span style="color: #6a9955;"># )</span></div>
<div><span style="color: #d4d4d4;">            </span><span style="color: #9cdcfe;">stats</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">perf_src</span><span style="color: #d4d4d4;">.</span><span style="color: #dcdcaa;">reset</span><span style="color: #d4d4d4;">(</span><span style="color: #9cdcfe;">time</span><span style="color: #d4d4d4;">)</span></div>
<div><span style="color: #d4d4d4;">        </span><span style="color: #9cdcfe;">stats</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">perf_src</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">frame_count</span><span style="color: #d4d4d4;"> += </span><span style="color: #b5cea8;">1</span></div><div><span style="color: #d4d4d4;">        </span><span style="color: #9cdcfe;">stats</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">perf_src</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">latency</span><span style="color: #d4d4d4;"> += </span><span style="color: #9cdcfe;">diff</span></div>
<div><span style="color: #d4d4d4;">        </span><span style="color: #c586c0;">return</span><span style="color: #d4d4d4;"> Gst.PadProbeReturn.OK</span></div><div><span style="color: #d4d4d4;">
</span></div><div>
<div style="color: #d4d4d4;background-color: #1e1e1e;font-family: 'Droid Sans Mono', 'monospace', monospace;font-weight: normal;font-size: 14px;line-height: 19px;white-space: pre;"><div><span style="color: #569cd6;">class</span><span style="color: #d4d4d4;"> </span><span style="color: #4ec9b0;">GstElementStats</span><span style="color: #d4d4d4;">:</span></div><div><span style="color: #d4d4d4;">        </span><span style="color: #ce9178;">"""Statistic values for Gst.Element</span></div>
<div><span style="color: #ce9178;">        :param elem: gstreamer element to measure statistics on</span></div><div><span style="color: #ce9178;">        """</span></div>
<div><span style="color: #d4d4d4;">        </span><span style="color: #569cd6;">class</span><span style="color: #d4d4d4;"> </span><span style="color: #4ec9b0;">PerfData</span><span style="color: #d4d4d4;">:</span></div><div><span style="color: #d4d4d4;">            </span><span style="color: #ce9178;">"""Used for measuring bitrate, fps and latencies in buffer probes"""</span></div>
<div><span style="color: #d4d4d4;">            </span><span style="color: #569cd6;">def</span><span style="color: #d4d4d4;"> </span><span style="color: #dcdcaa;">__init__</span><span style="color: #d4d4d4;">(</span><span style="color: #9cdcfe;">self</span><span style="color: #d4d4d4;">):</span></div><div><span style="color: #d4d4d4;">                </span><span style="color: #ce9178;">"""Constructor"""</span></div><div><span style="color: #d4d4d4;">                </span><span style="color: #9cdcfe;">self</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">prev_time</span><span style="color: #d4d4d4;"> = Gst.CLOCK_TIME_NONE</span></div><div><span style="color: #d4d4d4;">                </span><span style="color: #9cdcfe;">self</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">frame_count</span><span style="color: #d4d4d4;"> = </span><span style="color: #b5cea8;">0</span></div><div><span style="color: #d4d4d4;">                </span><span style="color: #9cdcfe;">self</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">bps</span><span style="color: #d4d4d4;"> = </span><span style="color: #b5cea8;">0</span></div><div><span style="color: #d4d4d4;">                </span><span style="color: #9cdcfe;">self</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">latency</span><span style="color: #d4d4d4;"> = </span><span style="color: #b5cea8;">0</span></div>
<div><span style="color: #d4d4d4;">            </span><span style="color: #569cd6;">def</span><span style="color: #d4d4d4;"> </span><span style="color: #dcdcaa;">reset</span><span style="color: #d4d4d4;">(</span><span style="color: #9cdcfe;">self</span><span style="color: #d4d4d4;">, </span><span style="color: #9cdcfe;">time</span><span style="color: #d4d4d4;">: </span><span style="color: #4ec9b0;">int</span><span style="color: #d4d4d4;">) -> </span><span style="color: #569cd6;">None</span><span style="color: #d4d4d4;">:</span></div><div><span style="color: #d4d4d4;">                </span><span style="color: #ce9178;">"""Reset values"""</span></div><div><span style="color: #d4d4d4;">                </span><span style="color: #9cdcfe;">self</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">frame_count</span><span style="color: #d4d4d4;"> = </span><span style="color: #b5cea8;">0</span></div><div><span style="color: #d4d4d4;">                </span><span style="color: #9cdcfe;">self</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">bps</span><span style="color: #d4d4d4;"> = </span><span style="color: #b5cea8;">0</span></div><div><span style="color: #d4d4d4;">                </span><span style="color: #9cdcfe;">self</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">latency</span><span style="color: #d4d4d4;"> = </span><span style="color: #b5cea8;">0</span></div><div><span style="color: #d4d4d4;">                </span><span style="color: #9cdcfe;">self</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">prev_time</span><span style="color: #d4d4d4;"> = </span><span style="color: #9cdcfe;">time</span></div>
<div><span style="color: #d4d4d4;">        </span><span style="color: #569cd6;">def</span><span style="color: #d4d4d4;"> </span><span style="color: #dcdcaa;">__init__</span><span style="color: #d4d4d4;">(</span><span style="color: #9cdcfe;">self</span><span style="color: #d4d4d4;">, </span><span style="color: #9cdcfe;">elem</span><span style="color: #d4d4d4;">: Gst.Element):</span></div><div><span style="color: #d4d4d4;">            </span><span style="color: #ce9178;">"""Constructor"""</span></div><div><span style="color: #d4d4d4;">            </span><span style="color: #9cdcfe;">self</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">bitrate</span><span style="color: #d4d4d4;"> = </span><span style="color: #b5cea8;">0</span><span style="color: #d4d4d4;">  </span><span style="color: #6a9955;"># in Mbps</span></div><div><span style="color: #d4d4d4;">            </span><span style="color: #9cdcfe;">self</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">fps</span><span style="color: #d4d4d4;"> = </span><span style="color: #b5cea8;">0</span></div><div><span style="color: #d4d4d4;">            </span><span style="color: #9cdcfe;">self</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">src_latency</span><span style="color: #d4d4d4;"> = </span><span style="color: #b5cea8;">0</span><span style="color: #d4d4d4;">  </span><span style="color: #6a9955;"># in ms</span></div><div><span style="color: #d4d4d4;">            </span><span style="color: #9cdcfe;">self</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">elem_latency</span><span style="color: #d4d4d4;"> = </span><span style="color: #b5cea8;">0</span><span style="color: #d4d4d4;">  </span><span style="color: #6a9955;"># in ms</span></div><div><span style="color: #d4d4d4;">            </span><span style="color: #9cdcfe;">self</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">elem_name</span><span style="color: #d4d4d4;"> = </span><span style="color: #9cdcfe;">elem</span><span style="color: #d4d4d4;">.name</span></div><div><span style="color: #d4d4d4;">            </span><span style="color: #9cdcfe;">self</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">perf_src</span><span style="color: #d4d4d4;"> = </span><span style="color: #4ec9b0;">GstPipeline</span><span style="color: #d4d4d4;">.</span><span style="color: #4ec9b0;">GstElementStats</span><span style="color: #d4d4d4;">.</span><span style="color: #4ec9b0;">PerfData</span><span style="color: #d4d4d4;">()</span></div><div><span style="color: #d4d4d4;">            </span><span style="color: #9cdcfe;">self</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">perf_sink</span><span style="color: #d4d4d4;"> = </span><span style="color: #4ec9b0;">GstPipeline</span><span style="color: #d4d4d4;">.</span><span style="color: #4ec9b0;">GstElementStats</span><span style="color: #d4d4d4;">.</span><span style="color: #4ec9b0;">PerfData</span><span style="color: #d4d4d4;">()</span></div></div><span style="color: #d4d4d4;"></span></div></div><span style="color: #d4d4d4;"></span></div></div><span style="color: #569cd6;"></span></div></div><span style="color: #d4d4d4;"></span></div></div>
    <p><br>
    </p>
    <p>Otherwise it is also possible to use GST_TRACERS (either the
      standard gstreamer ones or possible also the ones from gst-shark
      from ridgeRun) and get the values inside your application using a
      custom log function:<br>
    </p>
    <div style="color: #d4d4d4;background-color: #1e1e1e;font-family: 'Droid Sans Mono', 'monospace', monospace;font-weight: normal;font-size: 14px;line-height: 19px;white-space: pre;"><div><span style="color: #ce9178;">Gstreamer Tracers can be enabled by setting them through the correct</span><div style="color: #d4d4d4;background-color: #1e1e1e;font-family: 'Droid Sans Mono', 'monospace', monospace;font-weight: normal;font-size: 14px;line-height: 19px;white-space: pre;"><div><span style="color: #ce9178;">    environment variable (`GST_TRACERS`).</span></div><div><span style="color: #ce9178;">    See <a class="moz-txt-link-freetext" href="https://gstreamer.freedesktop.org/documentation/additional/design/">https://gstreamer.freedesktop.org/documentation/additional/design/</a></span></div><div><span style="color: #ce9178;">    tracing.html?gi-language=python#latency</span></div>
<div><span style="color: #ce9178;">    Latency tracer:</span></div>
<div><span style="color: #ce9178;">        GST_TRACERS="latency(flags=pipeline+element+reported)" python3 pipeline.py</span></div>
<div><span style="color: #ce9178;">    CPU usage tracer:</span></div><div><span style="color: #ce9178;">
</span></div><div><span style="color: #ce9178;">        GST_TRACERS="stats;rusage" python3 pipeline.py</span></div></div><span style="color: #569cd6;"></span></div><div><span style="color: #569cd6;">
</span></div><div>
<div style="color: #d4d4d4;background-color: #1e1e1e;font-family: 'Droid Sans Mono', 'monospace', monospace;font-weight: normal;font-size: 14px;line-height: 19px;white-space: pre;"><div><span style="color: #6a9955;">    # tracer: must be set before 'Gst.init()': no runtime control</span></div><div><span style="color: #d4d4d4;">    </span><span style="color: #6a9955;"># Example tracers</span></div><div><span style="color: #d4d4d4;">    </span><span style="color: #9cdcfe;">LATENCY_TRACER</span><span style="color: #d4d4d4;"> = </span><span style="color: #ce9178;">"latency(flags=pipeline+element+reported)"</span></div><div><span style="color: #d4d4d4;">    </span><span style="color: #9cdcfe;">CPU_USAGE_TRACER</span><span style="color: #d4d4d4;"> = </span><span style="color: #ce9178;">"stats;rusage"</span></div><div><span style="color: #d4d4d4;">    </span><span style="color: #9cdcfe;">DESIRED_TRACERS</span><span style="color: #d4d4d4;"> = </span><span style="color: #569cd6;">None</span></div><div><span style="color: #d4d4d4;">    </span><span style="color: #c586c0;">if</span><span style="color: #d4d4d4;"> </span><span style="color: #569cd6;">not</span><span style="color: #d4d4d4;"> </span><span style="color: #4ec9b0;">os</span><span style="color: #d4d4d4;">.</span><span style="color: #dcdcaa;">getenv</span><span style="color: #d4d4d4;">(</span><span style="color: #ce9178;">"GST_TRACERS"</span><span style="color: #d4d4d4;">) </span><span style="color: #569cd6;">and</span><span style="color: #d4d4d4;"> </span><span style="color: #9cdcfe;">DESIRED_TRACERS</span><span style="color: #d4d4d4;">:</span></div><div><span style="color: #d4d4d4;">        </span><span style="color: #4ec9b0;">os</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">environ</span><span style="color: #d4d4d4;">[</span><span style="color: #ce9178;">"GST_TRACERS"</span><span style="color: #d4d4d4;">] = </span><span style="color: #9cdcfe;">DESIRED_TRACERS</span></div></div><span style="color: #569cd6;"></span></div><div><span style="color: #569cd6;">
</span></div><div><span style="color: #569cd6;">
</span></div><div><span style="color: #569cd6;">def</span><span style="color: #d4d4d4;"> </span><span style="color: #dcdcaa;">_on_debug</span><span style="color: #d4d4d4;">(</span></div><div><span style="color: #d4d4d4;">        </span><span style="color: #9cdcfe;">self</span><span style="color: #d4d4d4;">,</span></div><div><span style="color: #d4d4d4;">        </span><span style="color: #9cdcfe;">category</span><span style="color: #d4d4d4;">: Gst.DebugCategory,</span></div><div><span style="color: #d4d4d4;">        </span><span style="color: #9cdcfe;">level</span><span style="color: #d4d4d4;">: Gst.DebugLevel,</span></div><div><span style="color: #d4d4d4;">        </span><span style="color: #9cdcfe;">file</span><span style="color: #d4d4d4;">: </span><span style="color: #4ec9b0;">str</span><span style="color: #d4d4d4;">,</span></div><div><span style="color: #d4d4d4;">        </span><span style="color: #9cdcfe;">function</span><span style="color: #d4d4d4;">: </span><span style="color: #4ec9b0;">str</span><span style="color: #d4d4d4;">,</span></div><div><span style="color: #d4d4d4;">        </span><span style="color: #9cdcfe;">line</span><span style="color: #d4d4d4;">: </span><span style="color: #4ec9b0;">int</span><span style="color: #d4d4d4;">,</span></div><div><span style="color: #d4d4d4;">        </span><span style="color: #9cdcfe;">source</span><span style="color: #d4d4d4;">: GObject.Object,</span></div><div><span style="color: #d4d4d4;">        </span><span style="color: #9cdcfe;">message</span><span style="color: #d4d4d4;">: Gst.DebugMessage,</span></div><div><span style="color: #d4d4d4;">        </span><span style="color: #9cdcfe;">user_data</span><span style="color: #d4d4d4;">: </span><span style="color: #4ec9b0;">Optional</span><span style="color: #d4d4d4;">[</span><span style="color: #4ec9b0;">object</span><span style="color: #d4d4d4;">] = </span><span style="color: #569cd6;">None</span><span style="color: #d4d4d4;">,</span></div><div><span style="color: #d4d4d4;">    ):</span></div><div><span style="color: #d4d4d4;">        </span><span style="color: #ce9178;">"""Custom gstreamer log function"""</span></div><div><span style="color: #d4d4d4;">        </span><span style="color: #9cdcfe;">level_name</span><span style="color: #d4d4d4;"> = Gst.DebugLevel.get_name(</span><span style="color: #9cdcfe;">level</span><span style="color: #d4d4d4;">)</span></div><div><span style="color: #d4d4d4;">        </span><span style="color: #9cdcfe;">text</span><span style="color: #d4d4d4;"> = </span><span style="color: #569cd6;">f</span><span style="color: #ce9178;">"Gstreamer </span><span style="color: #569cd6;">{</span><span style="color: #9cdcfe;">level_name</span><span style="color: #569cd6;">}</span><span style="color: #ce9178;"> </span><span style="color: #569cd6;">{</span><span style="color: #9cdcfe;">category</span><span style="color: #d4d4d4;">.get_name()</span><span style="color: #569cd6;">}</span><span style="color: #ce9178;"> "</span></div><div><span style="color: #d4d4d4;">        </span><span style="color: #c586c0;">if</span><span style="color: #d4d4d4;"> </span><span style="color: #9cdcfe;">source</span><span style="color: #d4d4d4;">:</span></div><div><span style="color: #d4d4d4;">            </span><span style="color: #9cdcfe;">file_name</span><span style="color: #d4d4d4;"> = </span><span style="color: #4ec9b0;">os</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">path</span><span style="color: #d4d4d4;">.</span><span style="color: #dcdcaa;">basename</span><span style="color: #d4d4d4;">(</span><span style="color: #9cdcfe;">file</span><span style="color: #d4d4d4;">)</span></div><div><span style="color: #d4d4d4;">            </span><span style="color: #9cdcfe;">text</span><span style="color: #d4d4d4;"> += </span><span style="color: #569cd6;">f</span><span style="color: #ce9178;">"</span><span style="color: #569cd6;">{</span><span style="color: #9cdcfe;">file_name</span><span style="color: #569cd6;">}</span><span style="color: #ce9178;">:</span><span style="color: #569cd6;">{</span><span style="color: #9cdcfe;">line</span><span style="color: #569cd6;">}</span><span style="color: #ce9178;">:</span><span style="color: #569cd6;">{</span><span style="color: #9cdcfe;">function</span><span style="color: #569cd6;">}</span><span style="color: #ce9178;"><</span><span style="color: #569cd6;">{</span><span style="color: #9cdcfe;">source</span><span style="color: #d4d4d4;">.name</span><span style="color: #569cd6;">}</span><span style="color: #ce9178;">>"</span></div><div><span style="color: #d4d4d4;">        </span><span style="color: #9cdcfe;">text</span><span style="color: #d4d4d4;"> += </span><span style="color: #569cd6;">f</span><span style="color: #ce9178;">": </span><span style="color: #569cd6;">{</span><span style="color: #9cdcfe;">message</span><span style="color: #d4d4d4;">.get()</span><span style="color: #569cd6;">}</span><span style="color: #ce9178;">"</span></div>
<div><span style="color: #d4d4d4;">        </span><span style="color: #6a9955;"># currently ignoring gst debug log level below DEBUG</span></div><div><span style="color: #d4d4d4;">        </span><span style="color: #c586c0;">if</span><span style="color: #d4d4d4;"> </span><span style="color: #9cdcfe;">level</span><span style="color: #d4d4d4;"> == Gst.DebugLevel.ERROR:</span></div><div><span style="color: #d4d4d4;">            </span><span style="color: #9cdcfe;">self</span><span style="color: #d4d4d4;">.__logger.error(</span><span style="color: #9cdcfe;">text</span><span style="color: #d4d4d4;">)</span></div><div><span style="color: #d4d4d4;">        </span><span style="color: #c586c0;">elif</span><span style="color: #d4d4d4;"> </span><span style="color: #9cdcfe;">level</span><span style="color: #d4d4d4;"> == Gst.DebugLevel.WARNING:</span></div><div><span style="color: #d4d4d4;">            </span><span style="color: #9cdcfe;">self</span><span style="color: #d4d4d4;">.__logger.warning(</span><span style="color: #9cdcfe;">text</span><span style="color: #d4d4d4;">)</span></div><div><span style="color: #d4d4d4;">        </span><span style="color: #c586c0;">elif</span><span style="color: #d4d4d4;"> </span><span style="color: #9cdcfe;">level</span><span style="color: #d4d4d4;"> == Gst.DebugLevel.INFO:</span></div><div><span style="color: #d4d4d4;">            </span><span style="color: #9cdcfe;">self</span><span style="color: #d4d4d4;">.__logger.info(</span><span style="color: #9cdcfe;">text</span><span style="color: #d4d4d4;">)</span></div><div><span style="color: #d4d4d4;">        </span><span style="color: #c586c0;">elif</span><span style="color: #d4d4d4;"> </span><span style="color: #9cdcfe;">level</span><span style="color: #d4d4d4;"> == Gst.DebugLevel.DEBUG:</span></div><div><span style="color: #d4d4d4;">            </span><span style="color: #9cdcfe;">self</span><span style="color: #d4d4d4;">.__logger.debug(</span><span style="color: #9cdcfe;">text</span><span style="color: #d4d4d4;">)</span></div><div><span style="color: #d4d4d4;">        </span><span style="color: #6a9955;"># handle GST_TRACERS</span></div><div><span style="color: #d4d4d4;">        </span><span style="color: #c586c0;">elif</span><span style="color: #d4d4d4;"> </span><span style="color: #9cdcfe;">level</span><span style="color: #d4d4d4;"> == Gst.DebugLevel.TRACE:</span></div><div><span style="color: #d4d4d4;">            </span><span style="color: #6a9955;"># self.__logger.debug(text)</span></div><div><span style="color: #d4d4d4;">            </span><span style="color: #9cdcfe;">self</span><span style="color: #d4d4d4;">.</span><span style="color: #dcdcaa;">_handle_tracer_output</span><span style="color: #d4d4d4;">(</span><span style="color: #9cdcfe;">category</span><span style="color: #d4d4d4;">, </span><span style="color: #9cdcfe;">message</span><span style="color: #d4d4d4;">)</span></div><div><span style="color: #d4d4d4;">
</span></div><div>
<div style="color: #d4d4d4;background-color: #1e1e1e;font-family: 'Droid Sans Mono', 'monospace', monospace;font-weight: normal;font-size: 14px;line-height: 19px;white-space: pre;"><div><span style="color: #569cd6;">def</span><span style="color: #d4d4d4;"> </span><span style="color: #dcdcaa;">_handle_tracer_output</span><span style="color: #d4d4d4;">(</span></div><div><span style="color: #d4d4d4;">        </span><span style="color: #9cdcfe;">self</span><span style="color: #d4d4d4;">, </span><span style="color: #9cdcfe;">category</span><span style="color: #d4d4d4;">: Gst.DebugCategory, </span><span style="color: #9cdcfe;">message</span><span style="color: #d4d4d4;">: Gst.DebugMessage</span></div><div><span style="color: #d4d4d4;">    ) -> </span><span style="color: #569cd6;">None</span><span style="color: #d4d4d4;">:</span></div><div><span style="color: #d4d4d4;">        </span><span style="color: #ce9178;">"""Handle the output generated by Gstreamer Tracers</span></div>
<div><span style="color: #ce9178;">        Detect the type of tracer and generate the relevant internal Event</span></div><div><span style="color: #ce9178;">        """</span></div><div><span style="color: #d4d4d4;">        </span><span style="color: #c586c0;">if</span><span style="color: #d4d4d4;"> </span><span style="color: #9cdcfe;">category</span><span style="color: #d4d4d4;">.get_name() == </span><span style="color: #ce9178;">"GST_TRACER"</span><span style="color: #d4d4d4;">:</span></div><div><span style="color: #d4d4d4;">            </span><span style="color: #9cdcfe;">tracer</span><span style="color: #d4d4d4;"> = </span><span style="color: #9cdcfe;">self</span><span style="color: #d4d4d4;">.</span><span style="color: #dcdcaa;">_parse_trace_msg</span><span style="color: #d4d4d4;">(</span><span style="color: #9cdcfe;">message</span><span style="color: #d4d4d4;">.get())</span></div>
<div><span style="color: #d4d4d4;">            </span><span style="color: #6a9955;"># 'Gst.Structure.from_string' fails for some types of tracer messages</span></div><div><span style="color: #d4d4d4;">            </span><span style="color: #c586c0;">if</span><span style="color: #d4d4d4;"> </span><span style="color: #9cdcfe;">tracer</span><span style="color: #d4d4d4;"> == </span><span style="color: #ce9178;">"message"</span><span style="color: #d4d4d4;"> </span><span style="color: #569cd6;">or</span><span style="color: #d4d4d4;"> </span><span style="color: #9cdcfe;">tracer</span><span style="color: #d4d4d4;"> == </span><span style="color: #ce9178;">"query"</span><span style="color: #d4d4d4;">:</span></div><div><span style="color: #d4d4d4;">                </span><span style="color: #6a9955;"># self.__logger.debug(f"{category.get_name()}: {message.get()}")</span></div><div><span style="color: #d4d4d4;">                </span><span style="color: #c586c0;">return</span></div>
<div><span style="color: #d4d4d4;">            </span><span style="color: #c586c0;">try</span><span style="color: #d4d4d4;">:</span></div><div><span style="color: #d4d4d4;">                </span><span style="color: #9cdcfe;">s</span><span style="color: #d4d4d4;">, </span><span style="color: #9cdcfe;">_</span><span style="color: #d4d4d4;"> = Gst.Structure.from_string(</span><span style="color: #9cdcfe;">message</span><span style="color: #d4d4d4;">.get())</span></div><div><span style="color: #d4d4d4;">                </span><span style="color: #6a9955;"># tracer = s.get_name()</span></div><div><span style="color: #d4d4d4;">            </span><span style="color: #c586c0;">except</span><span style="color: #d4d4d4;"> </span><span style="color: #4ec9b0;">Exception</span><span style="color: #d4d4d4;">:</span></div><div><span style="color: #d4d4d4;">                </span><span style="color: #9cdcfe;">self</span><span style="color: #d4d4d4;">.__logger.warning(</span><span style="color: #ce9178;">"Failed parsing structure"</span><span style="color: #d4d4d4;">)</span></div><div><span style="color: #d4d4d4;">                </span><span style="color: #9cdcfe;">self</span><span style="color: #d4d4d4;">.__logger.debug(</span><span style="color: #569cd6;">f</span><span style="color: #ce9178;">"</span><span style="color: #569cd6;">{</span><span style="color: #9cdcfe;">category</span><span style="color: #d4d4d4;">.get_name()</span><span style="color: #569cd6;">}</span><span style="color: #ce9178;">: </span><span style="color: #569cd6;">{</span><span style="color: #9cdcfe;">message</span><span style="color: #d4d4d4;">.get()</span><span style="color: #569cd6;">}</span><span style="color: #ce9178;">"</span><span style="color: #d4d4d4;">)</span></div><div><span style="color: #d4d4d4;">                </span><span style="color: #c586c0;">return</span></div>
<div><span style="color: #d4d4d4;">            </span><span style="color: #c586c0;">if</span><span style="color: #d4d4d4;"> </span><span style="color: #9cdcfe;">tracer</span><span style="color: #d4d4d4;"> == </span><span style="color: #ce9178;">"element-latency"</span><span style="color: #d4d4d4;">:</span></div><div><span style="color: #d4d4d4;">                </span><span style="color: #9cdcfe;">type</span><span style="color: #d4d4d4;"> = </span><span style="color: #4ec9b0;">GstPipeline</span><span style="color: #d4d4d4;">.</span><span style="color: #4ec9b0;">GstEvent</span><span style="color: #d4d4d4;">.</span><span style="color: #4ec9b0;">GstTracerEventType</span><span style="color: #d4d4d4;">.</span><span style="color: #4fc1ff;">ELEM_LATENCY</span></div><div><span style="color: #d4d4d4;">                </span><span style="color: #9cdcfe;">self</span><span style="color: #d4d4d4;">.</span><span style="color: #dcdcaa;">_plot_elem_latency</span><span style="color: #d4d4d4;">(</span><span style="color: #9cdcfe;">s</span><span style="color: #d4d4d4;">)</span></div><div><span style="color: #d4d4d4;">            </span><span style="color: #c586c0;">elif</span><span style="color: #d4d4d4;"> </span><span style="color: #9cdcfe;">tracer</span><span style="color: #d4d4d4;"> == </span><span style="color: #ce9178;">"latency"</span><span style="color: #d4d4d4;">:</span></div><div><span style="color: #d4d4d4;">                </span><span style="color: #9cdcfe;">type</span><span style="color: #d4d4d4;"> = </span><span style="color: #4ec9b0;">GstPipeline</span><span style="color: #d4d4d4;">.</span><span style="color: #4ec9b0;">GstEvent</span><span style="color: #d4d4d4;">.</span><span style="color: #4ec9b0;">GstTracerEventType</span><span style="color: #d4d4d4;">.</span><span style="color: #4fc1ff;">LATENCY</span></div><div><span style="color: #d4d4d4;">            </span><span style="color: #c586c0;">elif</span><span style="color: #d4d4d4;"> </span><span style="color: #9cdcfe;">tracer</span><span style="color: #d4d4d4;"> == </span><span style="color: #ce9178;">"thread-rusage"</span><span style="color: #d4d4d4;">:</span></div><div><span style="color: #d4d4d4;">                </span><span style="color: #6a9955;"># self._plot_rusage(s)</span></div><div><span style="color: #d4d4d4;">                </span><span style="color: #9cdcfe;">type</span><span style="color: #d4d4d4;"> = </span><span style="color: #4ec9b0;">GstPipeline</span><span style="color: #d4d4d4;">.</span><span style="color: #4ec9b0;">GstEvent</span><span style="color: #d4d4d4;">.</span><span style="color: #4ec9b0;">GstTracerEventType</span><span style="color: #d4d4d4;">.</span><span style="color: #4fc1ff;">THREAD_RUSAGE</span></div><div><span style="color: #d4d4d4;">            </span><span style="color: #c586c0;">elif</span><span style="color: #d4d4d4;"> </span><span style="color: #9cdcfe;">tracer</span><span style="color: #d4d4d4;"> == </span><span style="color: #ce9178;">"proc-rusage"</span><span style="color: #d4d4d4;">:</span></div><div><span style="color: #d4d4d4;">                </span><span style="color: #6a9955;"># self._plot_rusage(s)</span></div><div><span style="color: #d4d4d4;">                </span><span style="color: #9cdcfe;">type</span><span style="color: #d4d4d4;"> = </span><span style="color: #4ec9b0;">GstPipeline</span><span style="color: #d4d4d4;">.</span><span style="color: #4ec9b0;">GstEvent</span><span style="color: #d4d4d4;">.</span><span style="color: #4ec9b0;">GstTracerEventType</span><span style="color: #d4d4d4;">.</span><span style="color: #4fc1ff;">PROC_RUSAGE</span></div><div><span style="color: #d4d4d4;">            </span><span style="color: #c586c0;">else</span><span style="color: #d4d4d4;">:</span></div><div><span style="color: #d4d4d4;">                </span><span style="color: #9cdcfe;">type</span><span style="color: #d4d4d4;"> = </span><span style="color: #4ec9b0;">GstPipeline</span><span style="color: #d4d4d4;">.</span><span style="color: #4ec9b0;">GstEvent</span><span style="color: #d4d4d4;">.</span><span style="color: #4ec9b0;">GstTracerEventType</span><span style="color: #d4d4d4;">.</span><span style="color: #4fc1ff;">TRACER</span></div><div><span style="color: #d4d4d4;">            </span><span style="color: #9cdcfe;">self</span><span style="color: #d4d4d4;">.</span><span style="color: #dcdcaa;">queue_event</span><span style="color: #d4d4d4;">(</span></div><div><span style="color: #d4d4d4;">                </span><span style="color: #4ec9b0;">GstPipeline</span><span style="color: #d4d4d4;">.</span><span style="color: #4ec9b0;">GstEvent</span><span style="color: #d4d4d4;">(</span></div><div><span style="color: #d4d4d4;">                    </span><span style="color: #9cdcfe;">type</span><span style="color: #d4d4d4;">,</span></div><div><span style="color: #d4d4d4;">                    </span><span style="color: #569cd6;">f</span><span style="color: #ce9178;">"</span><span style="color: #569cd6;">{</span><span style="color: #9cdcfe;">s</span><span style="color: #d4d4d4;">.to_string()</span><span style="color: #569cd6;">}</span><span style="color: #ce9178;">"</span><span style="color: #d4d4d4;">,</span></div><div><span style="color: #d4d4d4;">                )</span></div><div><span style="color: #d4d4d4;">            )</span></div><div><span style="color: #d4d4d4;">
</span></div><div>
<div style="color: #d4d4d4;background-color: #1e1e1e;font-family: 'Droid Sans Mono', 'monospace', monospace;font-weight: normal;font-size: 14px;line-height: 19px;white-space: pre;"><div><span style="color: #569cd6;">def</span><span style="color: #d4d4d4;"> </span><span style="color: #dcdcaa;">_config_gst_log</span><span style="color: #d4d4d4;">(</span><span style="color: #9cdcfe;">self</span><span style="color: #d4d4d4;">) -> </span><span style="color: #569cd6;">None</span><span style="color: #d4d4d4;">:</span></div><div><span style="color: #d4d4d4;">        </span><span style="color: #ce9178;">"""Configure custom gstreamer logging function</span></div>
<div><span style="color: #ce9178;">        If 'GST_DEBUG' is set though the command line the custom 'on_debug()'</span></div><div><span style="color: #ce9178;">        will be ignored and the default gstreamer logging will be used instead.</span></div>
<div><span style="color: #ce9178;">        Also enable the gstreamer tracing system (when required).</span></div><div><span style="color: #ce9178;">        """</span></div><div><span style="color: #d4d4d4;">        </span><span style="color: #c586c0;">if</span><span style="color: #d4d4d4;"> </span><span style="color: #569cd6;">not</span><span style="color: #d4d4d4;"> Gst.debug_is_active():</span></div><div><span style="color: #d4d4d4;">            Gst.debug_remove_log_function(</span><span style="color: #569cd6;">None</span><span style="color: #d4d4d4;">)</span></div><div><span style="color: #d4d4d4;">            Gst.debug_add_log_function(</span><span style="color: #9cdcfe;">self</span><span style="color: #d4d4d4;">.</span><span style="color: #dcdcaa;">_on_debug</span><span style="color: #d4d4d4;">, </span><span style="color: #569cd6;">None</span><span style="color: #d4d4d4;">)</span></div><div><span style="color: #d4d4d4;">            </span><span style="color: #9cdcfe;">level</span><span style="color: #d4d4d4;"> = Gst.debug_get_default_threshold()</span></div><div><span style="color: #d4d4d4;">            </span><span style="color: #c586c0;">if</span><span style="color: #d4d4d4;"> </span><span style="color: #9cdcfe;">level</span><span style="color: #d4d4d4;"> < Gst.DebugLevel.ERROR:</span></div><div><span style="color: #d4d4d4;">                Gst.debug_set_default_threshold(Gst.DebugLevel.WARNING)</span></div><div><span style="color: #d4d4d4;">            </span><span style="color: #6a9955;"># enable tracer</span></div><div><span style="color: #d4d4d4;">            </span><span style="color: #c586c0;">if</span><span style="color: #d4d4d4;"> </span><span style="color: #9cdcfe;">self</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">DESIRED_TRACERS</span><span style="color: #d4d4d4;">:</span></div><div><span style="color: #d4d4d4;">                Gst.debug_set_threshold_for_name(</span><span style="color: #ce9178;">"GST_TRACER"</span><span style="color: #d4d4d4;">, Gst.DebugLevel.TRACE)</span></div><div><span style="color: #d4d4d4;">            Gst.debug_set_active(</span><span style="color: #569cd6;">True</span><span style="color: #d4d4d4;">)</span></div></div><span style="color: #d4d4d4;"></span></div></div><span style="color: #d4d4d4;"></span></div></div>
    <p>Best Regards</p>
    <p>Marianna<br>
    </p>
    <div class="moz-cite-prefix">On 17.03.2023 05.04,
      <a class="moz-txt-link-abbreviated" href="mailto:gstreamer-devel-request@lists.freedesktop.org">gstreamer-devel-request@lists.freedesktop.org</a> wrote:<br>
    </div>
    <blockquote type="cite"
cite="mid:mailman.8825.1679025872.929.gstreamer-devel@lists.freedesktop.org">
      <pre class="moz-quote-pre" wrap="">hello all,

i am attempting to measure FPS of a source stream (e.g. rtsp or hls). I am
currently using an identity element immediately after the source element
(e.g. rtspsrc -> identity -> decodebin -> fakesink). Using the handoff
signal on identity, I am able to get a good calculation of buffers per
second.

However, it seems that this value is not always 1:1 with frames per second.
It very frequently is on stable streams (e.g. I often see 29-31 buffers/sec
on a 30fps stream). However, on streams with intermittent connectivity, it
doesn't seem to tell the whole story.

I've seen fpsdisplaysink which actually works really well (I am able to see
"real" fps values that are dynamically changing as the pipeline plays).
However, a) I don't want to measure the fps at the sink (i have a tee'd
pipeline with multiple sinks and more interesting in measuring source fps
than that of my pipeline) and b) this element seems to just overlay it ?
ideally i would be able to get the average "recent" fps as a property.

I've seen ridgerun's gst-perf element, but that only seems to log values.

Is there a recommended approach to monitoring "real" FPS of an incoming
live stream? Ideally using identity, but open to other options.

Thanks,
Matt</pre>
    </blockquote>
    <pre class="moz-signature" cols="72">-- 
Best regards / Med venlig hilsen
“Marianna Smidth Buschle”</pre>
  </body>
</html>