Пример #1
0
        public MediaTrackInfosStructure[] GetMediaTracksInformations(VlcMediaInstance mediaInstance)
        {
            if (mediaInstance == IntPtr.Zero)
            {
                throw new ArgumentException("Media instance is not initialized.");
            }
            IntPtr fullBuffer;
            var    cpt = myLibraryLoader.GetInteropDelegate <GetMediaTracksInformations>().Invoke(mediaInstance, out fullBuffer);

            if (cpt <= 0)
            {
                return(new MediaTrackInfosStructure[0]);
            }
            var result = new MediaTrackInfosStructure[cpt];
            var buffer = fullBuffer;

            for (int index = 0; index < cpt; index++)
            {
                result[index] = MarshalHelper.PtrToStructure <MediaTrackInfosStructure>(buffer);
                buffer        = IntPtr.Size == 4
                    ? new IntPtr(buffer.ToInt32() + MarshalHelper.SizeOf <MediaTrackInfosStructure>())
                    : new IntPtr(buffer.ToInt64() + MarshalHelper.SizeOf <MediaTrackInfosStructure>());
            }
            Free(fullBuffer);
            return(result);
        }
        public List <AudioOutputDescriptionStructure> GetAudioOutputsDescriptions()
        {
            EnsureVlcInstance();

            var first  = GetInteropDelegate <GetAudioOutputsDescriptions>().Invoke(myVlcInstance);
            var result = new List <AudioOutputDescriptionStructure>();

            if (first == IntPtr.Zero)
            {
                return(result);
            }

            try
            {
                var currentPtr = first;
                while (currentPtr != IntPtr.Zero)
                {
                    var current = MarshalHelper.PtrToStructure <AudioOutputDescriptionStructureInternal>(currentPtr);
                    result.Add(new AudioOutputDescriptionStructure
                    {
                        Name        = Utf8InteropStringConverter.Utf8InteropToString(current.Name),
                        Description = Utf8InteropStringConverter.Utf8InteropToString(current.Description)
                    });

                    currentPtr = current.NextAudioOutputDescription;
                }

                return(result);
            }
            finally
            {
                GetInteropDelegate <ReleaseAudioOutputDescription>().Invoke(first);
            }
        }
        public IEnumerable <AudioOutputDevice> GetAudioOutputDeviceList(string outputName)
        {
            using (var outputNameHandle = Utf8InteropStringConverter.ToUtf8StringHandle(outputName))
            {
                var deviceList = myLibraryLoader.GetInteropDelegate <GetAudioOutputDeviceList>().Invoke(this.myVlcInstance, outputNameHandle);
                try
                {
                    var result         = new List <AudioOutputDevice>();
                    var currentPointer = deviceList;
                    while (currentPointer != IntPtr.Zero)
                    {
                        var current = MarshalHelper.PtrToStructure <LibvlcAudioOutputDeviceT>(currentPointer);
                        result.Add(new AudioOutputDevice
                        {
                            DeviceIdentifier = Utf8InteropStringConverter.Utf8InteropToString(current.DeviceIdentifier),
                            Description      = Utf8InteropStringConverter.Utf8InteropToString(current.Description)
                        });
                        currentPointer = current.Next;
                    }

                    return(result);
                }
                finally
                {
                    myLibraryLoader.GetInteropDelegate <ReleaseAudioOutputDeviceList>().Invoke(deviceList);
                }
            }
        }
        public MediaTrack[] GetMediaTracks(VlcMediaInstance mediaInstance)
        {
            if (mediaInstance == IntPtr.Zero)
            {
                throw new ArgumentException("Media instance is not initialized.");
            }

            var cpt = GetInteropDelegate <GetMediaTracks>().Invoke(mediaInstance, out var fullBuffer);

            if (cpt <= 0)
            {
                return(new MediaTrack[0]);
            }
            try
            {
                var result = new MediaTrack[cpt];
                for (int index = 0; index < cpt; index++)
                {
                    var current = MarshalHelper.PtrToStructure <LibvlcMediaTrackT>(Marshal.ReadIntPtr(fullBuffer, index * MarshalHelper.SizeOf <IntPtr>()));

                    TrackInfo trackInfo = null;

                    switch (current.Type)
                    {
                    case MediaTrackTypes.Audio:
                        var audio = MarshalHelper.PtrToStructure <LibvlcAudioTrackT>(current.TypedTrack);
                        trackInfo = new AudioTrack
                        {
                            Channels = audio.Channels,
                            Rate     = audio.Rate
                        };
                        break;

                    case MediaTrackTypes.Video:
                        var video = MarshalHelper.PtrToStructure <LibvlcVideoTrackT>(current.TypedTrack);
                        trackInfo = new VideoTrack
                        {
                            Height       = video.Height,
                            Width        = video.Width,
                            SarNum       = video.SarNum,
                            SarDen       = video.SarDen,
                            FrameRateNum = video.FrameRateNum,
                            FrameRateDen = video.FrameRateDen,
                            Orientation  = video.Orientation,
                            Projection   = video.Projection,
                            Pose         = video.Pose
                        };
                        break;

                    case MediaTrackTypes.Text:
                        var text = MarshalHelper.PtrToStructure <LibvlcSubtitleTrackT>(current.TypedTrack);
                        trackInfo = new SubtitleTrack
                        {
                            Encoding = Utf8InteropStringConverter.Utf8InteropToString(text.Encoding)
                        };
                        break;
                    }

                    result[index] = new MediaTrack
                    {
                        CodecFourcc    = current.Codec,
                        OriginalFourcc = current.OriginalFourCC,
                        Id             = current.Id,
                        Type           = current.Type,
                        Profile        = current.Profile,
                        Level          = current.Level,
                        TrackInfo      = trackInfo,
                        Bitrate        = current.Bitrate,
                        Language       = Utf8InteropStringConverter.Utf8InteropToString(current.Language),
                        Description    = Utf8InteropStringConverter.Utf8InteropToString(current.Description)
                    };
                }
                return(result);
            }
            finally
            {
                GetInteropDelegate <ReleaseMediaTracks>().Invoke(fullBuffer, cpt);
            }
        }