/// <summary> /// Helper method that creates a user friendly type from the internal interop structure. /// </summary> /// <param name="s">TrackDescriptionStructure from interop</param> /// <returns>public TrackDescription to be consumed by the user</returns> internal static MediaTrack Build(this MediaTrackStructure s) { AudioTrack audioTrack = default; VideoTrack videoTrack = default; SubtitleTrack subtitleTrack = default; switch (s.TrackType) { case TrackType.Audio: audioTrack = MarshalUtils.PtrToStructure <AudioTrack>(s.TrackData); break; case TrackType.Video: videoTrack = MarshalUtils.PtrToStructure <VideoTrack>(s.TrackData); break; case TrackType.Text: subtitleTrack = MarshalUtils.PtrToStructure <SubtitleTrackStructure>(s.TrackData).Build(); break; case TrackType.Unknown: break; } return(new MediaTrack(s.Codec, s.OriginalFourcc, s.Id, s.TrackType, s.Profile, s.Level, new MediaTrackData(audioTrack, videoTrack, subtitleTrack), s.Bitrate, s.Language.FromUtf8(), s.Description.FromUtf8())); }
/// <summary> /// Helper method that mashals a UTF8 native string ptr to a UTF16 managed string. /// Optionally frees the native string ptr /// </summary> /// <param name="nativeString">the native string to marshal to managed</param> /// <param name="libvlcFree">frees the native pointer of the libvlc string (use only for char*)</param> /// <returns>a managed UTF16 string</returns> internal static string FromUtf8(this IntPtr nativeString, bool libvlcFree = false) { if (nativeString == IntPtr.Zero) { return(null); } var length = 0; while (Marshal.ReadByte(nativeString, length) != 0) { length++; } byte[] buffer = new byte[length]; Marshal.Copy(nativeString, buffer, 0, buffer.Length); if (libvlcFree) { MarshalUtils.LibVLCFree(ref nativeString); } return(Encoding.UTF8.GetString(buffer, 0, buffer.Length)); }
/// <summary> /// Helper method that creates a user friendly type from the internal interop structure. /// </summary> /// <param name="s">TrackDescriptionStructure from interop</param> /// <returns>public TrackDescription to be consumed by the user</returns> internal static MediaTrack Build(this MediaTrackStructure s) { AudioTrack audioTrack = default; VideoTrack videoTrack = default; SubtitleTrack subtitleTrack = default; switch (s.TrackType) { case TrackType.Audio: audioTrack = MarshalUtils.PtrToStructure <AudioTrack>(s.TrackData); break; case TrackType.Video: videoTrack = MarshalUtils.PtrToStructure <VideoTrack>(s.TrackData); break; case TrackType.Text: subtitleTrack = MarshalUtils.PtrToStructure <SubtitleTrackStructure>(s.TrackData).Build(); break; case TrackType.Unknown: break; } var language = Utf8StringMarshaler.GetInstance().MarshalNativeToManaged(s.Language) as string; var des = Utf8StringMarshaler.GetInstance().MarshalNativeToManaged(s.Description) as string; return(new MediaTrack(s.Codec, s.OriginalFourcc, s.Id, s.TrackType, s.Profile, s.Level, new MediaTrackData(audioTrack, videoTrack, subtitleTrack), s.Bitrate, language, des)); }