public void Disposes_Twice() { var ffmpegMock = new Mock <FFmpegClient>(); ffmpegMock .Setup(c => c.CloseFormatContext(It.IsAny <AVFormatContext>())) .Verifiable(); var ffmpeg = ffmpegMock.Object; var nativeAVFormatContext = new NativeAVFormatContext { nb_streams = 1, }; var nativeIOContext = new NativeAVIOContext { }; using (var handle = new AVFormatContextHandle(ffmpeg, &nativeAVFormatContext)) { var ioContextMock = new Mock <AVIOContext>(ffmpeg, new AVIOContextHandle(ffmpeg, &nativeIOContext)) { CallBase = true, }; var formatContext = new AVFormatContext(ffmpeg, ioContextMock.Object, handle); formatContext.Dispose(); formatContext.Dispose(); ioContextMock.Verify(c => c.Dispose(), Times.Once); } }
public void GetVideoStream_ThrowsOnMultipleStreams() { var ffmpegMock = new Mock <FFmpegClient>(); ffmpegMock .Setup(c => c.FreeAVFormatContext(It.IsAny <IntPtr>())) .Verifiable(); var ffmpeg = ffmpegMock.Object; var nativeAVFormatContext = new NativeAVFormatContext { nb_streams = 2, }; var nativeIOContext = new NativeAVIOContext { }; using (var handle = new AVFormatContextHandle(ffmpeg, &nativeAVFormatContext)) using (var ioContext = new AVIOContext(ffmpeg, new AVIOContextHandle(ffmpeg, &nativeIOContext))) using (var formatContext = new AVFormatContext(ffmpeg, ioContext, handle)) { Assert.Throws <InvalidOperationException>(() => formatContext.GetVideoStream()); } ffmpegMock.Verify(); }
public void Close_Closes() { var ffmpegMock = new Mock <FFmpegClient>(); ffmpegMock .Setup(c => c.CloseFormatContext(It.IsAny <AVFormatContext>())) .Verifiable(); var ffmpeg = ffmpegMock.Object; var nativeAVFormatContext = new NativeAVFormatContext { nb_streams = 1, }; var nativeIOContext = new NativeAVIOContext { }; using (var handle = new AVFormatContextHandle(ffmpeg, &nativeAVFormatContext)) using (var ioContext = new AVIOContext(ffmpeg, new AVIOContextHandle(ffmpeg, &nativeIOContext))) using (var formatContext = new AVFormatContext(ffmpeg, ioContext, handle)) { formatContext.Close(); } ffmpegMock.Verify(); }
public void GetStream_ThrowsOnIllegalIndex() { var ffmpegMock = new Mock <FFmpegClient>(); ffmpegMock .Setup(c => c.FreeAVFormatContext(It.IsAny <IntPtr>())) .Verifiable(); var ffmpeg = ffmpegMock.Object; var nativeAVFormatContext = new NativeAVFormatContext { nb_streams = 1, }; var nativeIOContext = new NativeAVIOContext { }; using (var handle = new AVFormatContextHandle(ffmpeg, &nativeAVFormatContext)) using (var ioContext = new AVIOContext(ffmpeg, new AVIOContextHandle(ffmpeg, &nativeIOContext))) using (var formatContext = new AVFormatContext(ffmpeg, ioContext, handle)) { Assert.Throws <ArgumentOutOfRangeException>("index", () => formatContext.GetStream(20)); Assert.Throws <ArgumentOutOfRangeException>("index", () => formatContext.GetStream(-1)); } ffmpegMock.Verify(); }
public void Constructor_InitializesInstance() { var ffmpegMock = new Mock <FFmpegClient>(); var codecParameters = new NativeAVCodecParameters { codec_type = NativeAVMediaType.AVMEDIA_TYPE_VIDEO, }; var nativeStream = new NativeAVStream { codecpar = &codecParameters, }; var streamPtr = new IntPtr(&nativeStream); var nativeAVFormatContext = new NativeAVFormatContext { duration = 10, nb_streams = 1, event_flags = (int)AVFormatContextEventFlags.MetadataUpdated, ctx_flags = (int)AVFormatContextFlags.NoHeader, streams = (NativeAVStream **)streamPtr, }; var nativeIOContext = new NativeAVIOContext { }; ffmpegMock .Setup(c => c.FreeAVFormatContext(It.IsAny <IntPtr>())) .Verifiable(); var ffmpeg = ffmpegMock.Object; using (var handle = new AVFormatContextHandle(ffmpeg, &nativeAVFormatContext)) using (var ioContext = new AVIOContext(ffmpeg, new AVIOContextHandle(ffmpeg, &nativeIOContext))) using (var formatContext = new AVFormatContext(ffmpeg, ioContext, handle)) { Assert.Equal(handle, formatContext.Handle); Assert.Equal <uint>(1, formatContext.StreamCount); Assert.False(formatContext.IsClosed); Assert.False(handle.IsClosed); Assert.Equal((int)AVFormatContextEventFlags.MetadataUpdated, (int)formatContext.EventFlags); Assert.Equal((int)AVFormatContextFlags.NoHeader, (int)formatContext.Flags); } ffmpegMock.Verify(); }
public void Constuctor_InitializesInstance() { var ffmpegMock = new Mock <FFmpegClient>(); var nativeAVFormatContext = new NativeAVFormatContext { duration = 10, }; // ffmpegMock // .Setup(c => c.FreeAVFormatContext(It.IsAny<IntPtr>())) // .Verifiable(); using (var handle = new AVFormatContextHandle(ffmpegMock.Object, &nativeAVFormatContext)) { Assert.Equal((int)&nativeAVFormatContext, (int)handle.DangerousGetHandle().ToPointer()); } ffmpegMock.Verify(); }
public void GetVideoStream_ThrowsOnWrongType() { var ffmpegMock = new Mock <FFmpegClient>(); ffmpegMock .Setup(c => c.FreeAVFormatContext(It.IsAny <IntPtr>())) .Verifiable(); var ffmpeg = ffmpegMock.Object; var codecParameters = new NativeAVCodecParameters { format = 12346, codec_type = NativeAVMediaType.AVMEDIA_TYPE_AUDIO, }; var nativeStream = new NativeAVStream { codecpar = &codecParameters, }; var streamPtr = new IntPtr(&nativeStream); var nativeAVFormatContext = new NativeAVFormatContext { nb_streams = 1, streams = (NativeAVStream **)&streamPtr, }; var nativeIOContext = new NativeAVIOContext { }; using (var handle = new AVFormatContextHandle(ffmpeg, &nativeAVFormatContext)) using (var ioContext = new AVIOContext(ffmpeg, new AVIOContextHandle(ffmpeg, &nativeIOContext))) using (var formatContext = new AVFormatContext(ffmpeg, ioContext, handle)) { Assert.Throws <InvalidOperationException>(() => formatContext.GetVideoStream()); } ffmpegMock.Verify(); }
public void GetStream_ReturnsStream() { var ffmpegMock = new Mock <FFmpegClient>(); ffmpegMock .Setup(c => c.FreeAVFormatContext(It.IsAny <IntPtr>())) .Verifiable(); var ffmpeg = ffmpegMock.Object; var codecParameters = new NativeAVCodecParameters { format = 12346, }; var nativeStream = new NativeAVStream { codecpar = &codecParameters, }; var streamPtr = new IntPtr(&nativeStream); var nativeAVFormatContext = new NativeAVFormatContext { nb_streams = 1, streams = (NativeAVStream **)&streamPtr, }; var nativeIOContext = new NativeAVIOContext { }; using (var handle = new AVFormatContextHandle(ffmpeg, &nativeAVFormatContext)) using (var ioContext = new AVIOContext(ffmpeg, new AVIOContextHandle(ffmpeg, &nativeIOContext))) using (var formatContext = new AVFormatContext(ffmpeg, ioContext, handle)) { var stream = formatContext.GetStream(0); Assert.Equal(12346, stream.CodecParameters.Format); } ffmpegMock.Verify(); }
public void IOContext_Get() { var ffmpegMock = new Mock <FFmpegClient>(); ffmpegMock .Setup(c => c.FreeAVFormatContext(It.IsAny <IntPtr>())) .Verifiable(); var ffmpeg = ffmpegMock.Object; var bytes = new byte[] { (byte)'t', (byte)'e', (byte)'s', (byte)'t' }; var bytesHandle = Marshal.AllocHGlobal(bytes.Length); Marshal.Copy(bytes, 0, bytesHandle, bytes.Length); var nativeIOContext = new NativeAVIOContext { buffer = (byte *)bytesHandle, pos = 5, }; var nativeAVFormatContext = new NativeAVFormatContext { pb = &nativeIOContext, }; using (var handle = new AVFormatContextHandle(ffmpeg, &nativeAVFormatContext)) using (var ioContext = new AVIOContext(ffmpeg, new AVIOContextHandle(ffmpeg, &nativeIOContext))) using (var formatContext = new AVFormatContext(ffmpeg, ioContext, handle)) { var result = new byte[4]; Marshal.Copy((IntPtr)formatContext.IOContext.Buffer.NativeObject, result, 0, bytes.Length); Assert.Equal(bytes, result); } ffmpegMock.Verify(); Marshal.FreeHGlobal(bytesHandle); }