コード例 #1
0
ファイル: CLibTest.cs プロジェクト: ilyi1116/ffmpeg.net
        public void TestMemset()
        {
            var Pointer = CLib.malloc(8);

            CLib.memset(Pointer, 1, 4);
            CollectionAssert.AreEqual(new byte[] { 1, 1, 1, 1, 0, 0, 0, 0 }, Pointer.Data.ToArray());
        }
コード例 #2
0
        private object Decode <TType>(byte[] Data, AVCodec AVCodec, Action <AVCodecContext, AVPacket, TType> Action)
        {
            var context = new AVCodecContext();
            var packet  = new AVPacket();

            packet.data = Pointer <byte> .Create(new AllocatedMemory(Data));

            packet.size = Data.Length;

            context.get_buffer = (AVCodecContext, AVFrame) =>
            {
                var width  = AVCodecContext.width;
                var height = AVCodecContext.height;
                AVFrame.linesize[0] = width * 4;
                AVFrame.data[0]     = CLib.malloc(AVFrame.linesize[0] * height);
                return(0);
            };

            context.release_buffer = (AVCodecContext, AVFrame) =>
            {
                CLib.free(AVFrame.data[0]);
            };

            AVCodec.init(context);
            try
            {
                object obj = null;
                if (AVCodec.decode(context, ref obj, packet) < 0)
                {
                    throw(new Exception());
                }
                Action(context, packet, (TType)obj);
                return(obj);
            }
            finally
            {
                AVCodec.close(context);
            }
        }