Beispiel #1
0
        static IntPtr CtorFromCallbacks(LibVLC libVLC, Stream stream)
        {
            if (libVLC == null)
            {
                throw new ArgumentNullException(nameof(libVLC));
            }
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }

            var openMedia  = new OpenMedia(CallbackOpenMedia);
            var readMedia  = new ReadMedia(CallbackReadMedia);
            var seekMedia  = new SeekMedia(CallbackSeekMedia);
            var closeMedia = new CloseMedia(CallbackCloseMedia);

            var opaque = AddStream(stream, openMedia, readMedia, seekMedia, closeMedia);

            if (opaque == IntPtr.Zero)
            {
                throw new InvalidOperationException("Cannot create opaque parameter");
            }

            return(Native.LibVLCMediaNewCallbacks(libVLC.NativeReference,
                                                  Marshal.GetFunctionPointerForDelegate(openMedia),
                                                  Marshal.GetFunctionPointerForDelegate(readMedia),
                                                  Marshal.GetFunctionPointerForDelegate(seekMedia),
                                                  Marshal.GetFunctionPointerForDelegate(closeMedia),
                                                  opaque));
        }
Beispiel #2
0
 public StreamData(IntPtr handle, Stream stream, byte[] buffer, OpenMedia openMedia, ReadMedia readMedia, SeekMedia seekMedia, CloseMedia closeMedia)
 {
     Handle     = handle;
     Stream     = stream;
     Buffer     = buffer;
     OpenMedia  = openMedia;
     ReadMedia  = readMedia;
     SeekMedia  = seekMedia;
     CloseMedia = closeMedia;
 }
Beispiel #3
0
        static IntPtr AddStream(Stream stream, OpenMedia openMedia, ReadMedia readMedia, SeekMedia seekMedia, CloseMedia closeMedia)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }

            IntPtr handle;

            lock (DicStreams)
            {
                _streamIndex++;

                handle             = new IntPtr(_streamIndex);
                DicStreams[handle] = new StreamData
                {
                    Buffer     = new byte[0x4000],
                    Handle     = handle,
                    Stream     = stream,
                    OpenMedia  = openMedia,
                    ReadMedia  = readMedia,
                    SeekMedia  = seekMedia,
                    CloseMedia = closeMedia
                };
            }
            return(handle);
        }