Exemplo n.º 1
0
        public AVIOContextWrapper(ulong bufferSize, ReadPacket readPacket)
        {
            buffer               = (byte *)Interop.FFmpeg.av_mallocz(bufferSize);
            this.readPacket      = readPacket;
            readFunctionDelegate = ReadPacket;
            var readFunction = new avio_alloc_context_read_packet_func
            {
                Pointer = Marshal.GetFunctionPointerForDelegate(readFunctionDelegate)
            };
            var writeFunction = new avio_alloc_context_write_packet_func {
                Pointer = IntPtr.Zero
            };
            var seekFunction = new avio_alloc_context_seek_func {
                Pointer = IntPtr.Zero
            };

            context = Interop.FFmpeg.avio_alloc_context(buffer,
                                                        (int)bufferSize,
                                                        0,
                                                        (void *)GCHandle.ToIntPtr(
                                                            GCHandle.Alloc(
                                                                this)),
                                                        readFunction,
                                                        writeFunction,
                                                        seekFunction);

            if (context == null)
            {
                throw new FFmpegException("Cannot allocate AVIOContext");
            }

            context->seekable   = 0;
            context->write_flag = 0;
        }
Exemplo n.º 2
0
 public unsafe ByteReader()
 {
     _currentPosition = 0;
     _readDelegate    = Read;
     _seekDelegate    = Seek;
     ReadFunc         = new avio_alloc_context_read_packet_func {
         Pointer = Marshal.GetFunctionPointerForDelegate(_readDelegate)
     };
     SeekFunc = new avio_alloc_context_seek_func {
         Pointer = Marshal.GetFunctionPointerForDelegate(_seekDelegate)
     };
 }
Exemplo n.º 3
0
 private static extern AVIOContext *avio_alloc_context(byte *buffer, int buffer_size, int write_flag, void *opaque, avio_alloc_context_read_packet_func read_packet, avio_alloc_context_write_packet_func write_packet, avio_alloc_context_seek_func seek);
Exemplo n.º 4
0
        /// <summary>
        /// Allocate and initialize an AVIOContext for buffered I/O. It must be later freed with avio_context_free().
        /// </summary>
        /// <param name="buffer">
        /// Memory block for input/output operations via AVIOContext. The buffer must be allocated with av_malloc() and friends.
        /// It may be freed and replaced with a new buffer by libavformat. AVIOContext.buffer holds the buffer currently in use, which must be later freed with av_free().
        /// </param>
        /// <param name="buffer_size">
        /// The buffer size is very important for performance. For protocols with fixed blocksize it should be set to this blocksize. For others a typical size is a cache page, e.g. 4kb.
        /// </param>
        /// <param name="write_flag">
        /// Set to 1 if the buffer should be writable, 0 otherwise.
        /// </param>
        /// <param name="opaque">
        /// An opaque pointer to user-specific data.
        /// </param>
        /// <param name="read_packet">
        /// A function for refilling the buffer, may be NULL. For stream protocols, must never return 0 but rather a proper AVERROR code.
        /// </param>
        /// <param name="write_packet">
        /// A function for writing the buffer contents, may be NULL. The function may not change the input buffers content.
        /// </param>
        /// <param name="seek">
        /// A function for seeking to specified byte position, may be NULL.
        /// </param>
        /// <returns>
        /// Allocated AVIOContext.
        /// </returns>
        public NativeAVIOContext *AllocAVIOContext(byte *buffer, int buffer_size, int write_flag, void *opaque, avio_alloc_context_read_packet_func read_packet, avio_alloc_context_write_packet_func write_packet, avio_alloc_context_seek_func seek)
        {
            var avio_ctx = ffmpeg.avio_alloc_context(buffer, buffer_size, write_flag, opaque, read_packet, write_packet, seek);

            if (avio_ctx == null)
            {
                throw new OutOfMemoryException();
            }

            return(avio_ctx);
        }