示例#1
0
        public void Index_ReturnsNativeIndex()
        {
            var nativeStream = new NativeAVStream
            {
                index = 6,
            };

            var stream = new AVStream(&nativeStream);

            Assert.Equal(6, stream.Index);
        }
示例#2
0
        public void Metadata_ReturnsNull()
        {
            var nativeStream = new NativeAVStream
            {
                metadata = null,
            };

            var stream = new AVStream(&nativeStream);

            Assert.Null(stream.Metadata);
        }
示例#3
0
        public void Metadata_ReturnsNativeMetadata()
        {
            var nativeDictionary = new NativeAVDictionary
            {
            };

            var nativeStream = new NativeAVStream
            {
                metadata = &nativeDictionary,
            };

            var stream = new AVStream(&nativeStream);

            Assert.Empty(stream.Metadata);
        }
示例#4
0
        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();
        }
示例#5
0
        public void CodecContext_ReturnsNativeCodecContext()
        {
            var codecParameters = new NativeAVCodecParameters
            {
                codec_type = NativeAVMediaType.AVMEDIA_TYPE_VIDEO,
            };

            var nativeStream = new NativeAVStream
            {
                codecpar = &codecParameters,
            };

            var stream = new AVStream(&nativeStream);

            Assert.Equal(NativeAVMediaType.AVMEDIA_TYPE_VIDEO, stream.CodecParameters.Type);
        }
示例#6
0
        public void TimeBase_ReturnsNativeTimeBase()
        {
            var nativeTimeBase = new NativeAVRational
            {
                den = 100,
                num = 4,
            };

            var nativeStream = new NativeAVStream
            {
                time_base = nativeTimeBase,
            };

            var stream = new AVStream(&nativeStream);

            Assert.Equal(4, stream.TimeBase.num);
            Assert.Equal(100, stream.TimeBase.den);
        }
示例#7
0
        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();
        }
示例#8
0
        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();
        }
示例#9
0
        public void AVCodec_InitializesInstance()
        {
            var nativeCodec = new NativeAVCodec()
            {
                capabilities = (int)AVCodecCapabilities.Truncated,
            };

            var ffmpegMock = new Mock <FFmpegClient>();

            ffmpegMock
            .Setup(c => c.FindDecoder(AVCodecID.AV_CODEC_ID_H264))
            .Returns((IntPtr)(&nativeCodec))
            .Verifiable();

            var codecParameters = new NativeAVCodecParameters
            {
                codec_type = NativeAVMediaType.AVMEDIA_TYPE_VIDEO,
                codec_id   = AVCodecID.AV_CODEC_ID_H264,
            };

            var nativeCodecContext = new NativeAVCodecContext()
            {
                codec_id = AVCodecID.AV_CODEC_ID_H264,
            };

#pragma warning disable CS0618 // Type or member is obsolete
            var nativeStream = new NativeAVStream
            {
                codecpar = &codecParameters,
                codec    = &nativeCodecContext,
            };

            var stream = new AVStream(&nativeStream);

            var ffmpeg = ffmpegMock.Object;
            var codec  = new AVCodec(ffmpeg, stream);

            Assert.Equal((int)AVCodecCapabilities.Truncated, stream.CodecContext->flags);
#pragma warning restore CS0618 // Type or member is obsolete
        }