Ejemplo n.º 1
0
        /// <summary>
        /// Code taken from Vlc.DotNet
        /// </summary>
        /// <param name="data"></param>
        /// <param name="level"></param>
        /// <param name="ctx"></param>
        /// <param name="format"></param>
        /// <param name="args"></param>
        void OnLogInternal(IntPtr data, LogLevel level, IntPtr ctx, string format, IntPtr args)
        {
            if (_log == null)
            {
                return;
            }

            // Original source for va_list handling: https://stackoverflow.com/a/37629480/2663813
            var byteLength = Native._vscprintf(format, args) + 1;
            var utf8Buffer = Marshal.AllocHGlobal(byteLength);

            string formattedDecodedMessage;

            try
            {
                Native.vsprintf(utf8Buffer, format, args);

                formattedDecodedMessage = (string)Utf8StringMarshaler.GetInstance().MarshalNativeToManaged(utf8Buffer);
            }
            finally
            {
                Marshal.FreeHGlobal(utf8Buffer);
            }

            GetLogContext(ctx, out var module, out var file, out var line);

            // Do the notification on another thread, so that VLC is not interrupted by the logging
            Task.Run(() => _log?.Invoke(NativeReference, new LogEventArgs(level, formattedDecodedMessage, module, file, line)));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets log message debug infos.
        ///
        /// This function retrieves self-debug information about a log message:
        /// - the name of the VLC module emitting the message,
        /// - the name of the source code module (i.e.file) and
        /// - the line number within the source code module.
        ///
        /// The returned module name and file name will be NULL if unknown.
        /// The returned line number will similarly be zero if unknown.
        /// </summary>
        /// <param name="logContext">The log message context (as passed to the <see cref="LogCallback"/>)</param>
        /// <param name="module">The module name storage.</param>
        /// <param name="file">The source code file name storage.</param>
        /// <param name="line">The source code file line number storage.</param>
        void GetLogContext(IntPtr logContext, out string module, out string file, out uint?line)
        {
            Native.LibVLCLogGetContext(logContext, out var modulePtr, out var filePtr, out var linePtr);

            line   = linePtr == UIntPtr.Zero ? null : (uint?)linePtr.ToUInt32();
            module = Utf8StringMarshaler.GetInstance().MarshalNativeToManaged(modulePtr) as string;
            file   = Utf8StringMarshaler.GetInstance().MarshalNativeToManaged(filePtr) as string;
        }
Ejemplo n.º 3
0
        /// <summary>Read the meta of the media.</summary>
        /// <param name="metadataType">the meta to read</param>
        /// <returns>the media's meta</returns>
        /// <remarks>
        /// If the media has not yet been parsed this will return NULL.
        /// </remarks>
        public string Meta(MetadataType metadataType)
        {
            var metaPtr = Internal.LibVLCMediaGetMeta(NativeReference, metadataType);

            if (metaPtr == IntPtr.Zero)
            {
                return(string.Empty);
            }
            return(Utf8StringMarshaler.GetInstance().MarshalNativeToManaged(metaPtr) as string);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Get the name of a particular equalizer preset.
 /// This name can be used, for example, to prepare a preset label or menu in a user interface.
 /// </summary>
 /// <param name="index">index of the preset, counting from zero</param>
 /// <returns>preset name, or empty string if there is no such preset</returns>
 public string PresetName(uint index) => (string)Utf8StringMarshaler.GetInstance().MarshalNativeToManaged(Native.LibVLCAudioEqualizerGetPresetName(index));