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)); }
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; }
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); }