[vlc-commits] [Git][videolan/vlc][master] 2 commits: sout: add a tracer utility stream filter

Jean-Baptiste Kempf (@jbk) gitlab at videolan.org
Wed Aug 2 16:18:29 UTC 2023



Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC


Commits:
73d1a84f by Alaric Senat at 2023-08-02T16:05:49+00:00
sout: add a tracer utility stream filter

The VLC tracing API is really useful in a lot of debugging scenario. It
was previously implemented in playback but lack an implementation in the
stream output chain.

This patch propose a named stream filter that can be placed before any
other module and trace their input. It allow the user to choose
precisely at which node of the chain they want tracing and under which
name.

An example usage can be found in the help section of the module:

```sout
```

- - - - -
2ea41a7c by Alaric Senat at 2023-08-02T16:05:49+00:00
meson: sout: add the trace module

- - - - -


3 changed files:

- modules/stream_out/Makefile.am
- modules/stream_out/meson.build
- + modules/stream_out/trace.c


Changes:

=====================================
modules/stream_out/Makefile.am
=====================================
@@ -16,6 +16,7 @@ libstream_out_autodel_plugin_la_SOURCES = stream_out/autodel.c
 libstream_out_record_plugin_la_SOURCES = stream_out/record.c
 libstream_out_smem_plugin_la_SOURCES = stream_out/smem.c
 libstream_out_setid_plugin_la_SOURCES = stream_out/setid.c
+libstream_out_trace_plugin_la_SOURCES = stream_out/trace.c
 libstream_out_transcode_plugin_la_SOURCES = \
 	stream_out/transcode/transcode.c stream_out/transcode/transcode.h \
 	stream_out/transcode/encoder/encoder.c \
@@ -50,6 +51,7 @@ sout_LTLIBRARIES = \
 	libstream_out_record_plugin.la \
 	libstream_out_smem_plugin.la \
 	libstream_out_setid_plugin.la \
+	libstream_out_trace_plugin.la \
 	libstream_out_transcode_plugin.la \
 	libstream_out_udp_plugin.la
 


=====================================
modules/stream_out/meson.build
=====================================
@@ -112,6 +112,12 @@ vlc_modules += {
     'dependencies' : [m_lib]
 }
 
+# trace
+vlc_modules += {
+    'name' : 'stream_out_trace',
+    'sources' : files('trace.c')
+}
+
 # UDP
 vlc_modules += {
     'name' : 'stream_out_udp',


=====================================
modules/stream_out/trace.c
=====================================
@@ -0,0 +1,169 @@
+/*****************************************************************************
+ * trace.c: Trace frame timestamps and PCRs
+ *****************************************************************************
+ * Copyright (C) 2023 VLC authors and VideoLAN
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <vlc_common.h>
+
+#include <vlc_configuration.h>
+#include <vlc_frame.h>
+#include <vlc_plugin.h>
+#include <vlc_sout.h>
+#include <vlc_tracer.h>
+
+typedef struct
+{
+    const char *es_id;
+    void *next_id;
+} sout_stream_id_sys_t;
+
+static void *
+Add(sout_stream_t *stream, const es_format_t *fmt, const char *es_id)
+{
+    sout_stream_id_sys_t *id = malloc(sizeof(*id));
+    if (unlikely(id == NULL))
+        return NULL;
+
+    id->es_id = es_id;
+    id->next_id = sout_StreamIdAdd(stream->p_next, fmt, es_id);
+    if (id->next_id == NULL)
+        FREENULL(id);
+    return id;
+}
+
+static int Send(sout_stream_t *stream, void *id, vlc_frame_t *frame)
+{
+    sout_stream_id_sys_t *sys_id = id;
+
+    struct vlc_tracer *tracer = vlc_object_get_tracer(VLC_OBJECT(stream));
+    if (tracer != NULL)
+    {
+        if (frame->i_dts != VLC_TICK_INVALID)
+        {
+            vlc_tracer_TraceStreamDTS(tracer,
+                                      stream->p_sys,
+                                      sys_id->es_id,
+                                      "IN",
+                                      frame->i_pts,
+                                      frame->i_dts);
+        }
+        else
+        {
+            vlc_tracer_TraceStreamPTS(
+                tracer, stream->p_sys, sys_id->es_id, "IN", frame->i_pts);
+        }
+    }
+
+    return sout_StreamIdSend(stream->p_next, sys_id->next_id, frame);
+}
+
+static void Del(sout_stream_t *stream, void *id)
+{
+    sout_stream_id_sys_t *sys_id = id;
+    sout_StreamIdDel(stream->p_next, sys_id->next_id);
+    free(sys_id);
+}
+
+static void SetPCR(sout_stream_t *stream, vlc_tick_t pcr)
+{
+    struct vlc_tracer *tracer = vlc_object_get_tracer(VLC_OBJECT(stream));
+    if (tracer != NULL)
+        vlc_tracer_TracePCR(tracer, stream->p_sys, "PCR", pcr);
+
+    sout_StreamSetPCR(stream->p_next, pcr);
+}
+
+static int Control(sout_stream_t *stream, int query, va_list args)
+{
+    if (query == SOUT_STREAM_ID_SPU_HIGHLIGHT)
+    {
+        sout_stream_id_sys_t *sys_id = va_arg(args, void *);
+        return sout_StreamControl(
+            stream->p_next, query, sys_id->next_id, va_arg(args, void *));
+    }
+    return sout_StreamControlVa(stream->p_next, query, args);
+}
+
+static void Flush(sout_stream_t *stream, void *id)
+{
+    sout_stream_id_sys_t *sys_id = id;
+    sout_StreamFlush(stream->p_next, sys_id->next_id);
+}
+
+#define SOUT_CFG_PREFIX "sout-trace-"
+
+static int Open(vlc_object_t *this)
+{
+    sout_stream_t *stream = (sout_stream_t *)this;
+    static const char *sout_options[] = {"name", NULL};
+    config_ChainParse(stream, SOUT_CFG_PREFIX, sout_options, stream->p_cfg);
+
+    char *name_in_cfg = var_GetNonEmptyString(stream, SOUT_CFG_PREFIX "name");
+    stream->p_sys =
+        (name_in_cfg != NULL) ? name_in_cfg : strdup(stream->p_next->psz_name);
+    if (unlikely(stream->p_sys == NULL))
+        return VLC_ENOMEM;
+
+    static const struct sout_stream_operations ops = {
+        .add = Add,
+        .del = Del,
+        .send = Send,
+        .set_pcr = SetPCR,
+        .control = Control,
+        .flush = Flush,
+    };
+    stream->ops = &ops;
+
+    return VLC_SUCCESS;
+}
+
+static void Close(vlc_object_t *this)
+{
+    sout_stream_t *stream = (sout_stream_t *)this;
+    free(stream->p_sys);
+}
+
+#define HELP_TEXT                                                              \
+    N_("This filter module traces all frames and timestamps passing through "  \
+       "it using the VLC tracer."                                              \
+       "Here's a stream output chain example:\n"                               \
+       "  #autodel:trace:transcode{...}:trace:file{...}\n "                    \
+       "The name of the traced output defaults to the next module's name. A "  \
+       "custom name can be passed for complex `duplicate` chains or VLM "      \
+       "scenario where mutliple stages of the chain are traced:\n"             \
+       "  #duplicate{dst=trace{name=dup1}:dummy,dst=trace{name=dup2}:dummy}")
+
+#define NAME_TEXT N_("Name of the traced output")
+#define NAME_LONGTEXT                                                          \
+    N_("Give meaning and context to the traced output. Defaults to the next "  \
+       "stream name")
+
+vlc_module_begin()
+    set_shortname(N_("Trace"))
+    set_description(N_("Trace frame timestamps and PCR events"))
+    set_capability("sout filter", 0)
+    set_help(HELP_TEXT)
+    add_shortcut("trace")
+    set_callbacks(Open, Close)
+
+    add_string(SOUT_CFG_PREFIX "name", NULL, NAME_TEXT, NAME_LONGTEXT)
+vlc_module_end()



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/fa67b748170979aebdb838ad6048e7845ba4e347...2ea41a7ca922aa2f4a796f04c681c9e7031e7673

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/fa67b748170979aebdb838ad6048e7845ba4e347...2ea41a7ca922aa2f4a796f04c681c9e7031e7673
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list