[vlc-devel] [PATCH 1/2] libvlc: added a formatted log callback

Jeremy Vignelles jeremy.vignelles at dev3i.fr
Sat May 18 22:38:19 CEST 2019


> Le 18 mai 2019 à 09:29, Rémi Denis-Courmont <remi at remlab.net> a écrit :
> 
> 
> Le perjantaina 17. toukokuuta 2019, 11.05.00 EEST Jérémy VIGNELLES a écrit :
> > ---
> >  include/vlc/libvlc.h | 64 ++++++++++++++++++++++++++++++++++++++++++++
> >  lib/libvlc.sym | 3 +++
> >  lib/log.c | 55 +++++++++++++++++++++++++++++++++++++
> >  3 files changed, 122 insertions(+)
> > 
> > diff --git a/include/vlc/libvlc.h b/include/vlc/libvlc.h
> > index 1c2550fe3b..1b21c2da66 100644
> > --- a/include/vlc/libvlc.h
> > +++ b/include/vlc/libvlc.h
> > @@ -433,6 +433,26 @@ LIBVLC_API void libvlc_log_get_object(const
> > libvlc_log_t *ctx, typedef void (*libvlc_log_cb)(void *data, int level,
> > const libvlc_log_t *ctx, const char *fmt, va_list args);
> > 
> > +/**
> > + * Callback prototype for LibVLC preformatted log message handler.
> > + *
> > + * \param data data pointer as given to libvlc_log_set()
> > + * \param level message level (@ref libvlc_log_level)
> > + * \param ctx message context (meta-information about the message)
> > + * \param message the message, already formatted
> > + * \note Log message handlers must be thread-safe.
> > + * \warning The message context pointer, and the message string parameters
> > + * are only valid until the callback returns.
> > + */
> > +typedef void (*libvlc_log_preformatted_cb)(void *data, int level, const
> > libvlc_log_t *ctx, + const char *message);
> 
> There is no logic there. Many languages will either not support callbacks at 
> all, or have no ways to make them thread safe, or will be unable to marshall 
> pointers from callbacks, etc.

I don't know all languages, but C# is definitely not one of those. Callbacks can be declared and called from native code, we already do that in LibVLCSharp, for example to handle events.

> And the libvlc_log_t is definitely not supported in higher level languages, 
> neither are many other compound types.

This is why we recreate the structure in the C# side. The runtime is then smart enough to marshal the structure to be used in C#. For example, here is how we declare the event union in LibVLCSharp:
https://github.com/videolan/libvlcsharp/blob/b120bbe6bce9f2c427e61e41c5928fd1ee273075/LibVLCSharp/Shared/LibVLCEvents.cs#L169


> In fact, even 'int' is iffy, since 
> typically only fixed-size types are handeld.

You are right, int in C# means something different that int in C.

> We *used* to have a log API that was "easy" to call from other languages. We 
> removed it because it was so incredibly broken and intrinsically unfixable.

I'm not saying that the whole libvlc API is hard to call from other languages, this one is the only API that causes issues with C#.

> LibVLC is not, or rather no longer for a decade or so, meant to be called 
> directly from foreign interfaces.

You know more about the history of libvlc than I do, but the fact is that there are a lot of libvlc bindings out there:

- vlcj https://github.com/caprica/vlcj for java
- vlc-rs https://github.com/garkimasera/vlc-rs for rust
- vlc-go https://github.com/adrg/libvlc-go
- Vlc.DotNet https://github.com/ZeBobo5/Vlc.DotNet for C#
- and now LibVLCSharp, which is supported by VideoLAN and which first stable version has already been downloaded 179 times in just five days of existence.

Being able to use the power of LibVLC in other languages is great, and the fact that those projects are still being worked on makes me think that it is possible, even if not the top priority of the core devs.

> -- 
> Rémi Denis-Courmont
> http://www.remlab.net/
> 
> 
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel


More information about the vlc-devel mailing list