Ejemplo n.º 1
0
 public static extern int avcodec_decode_video2(ref AVCodecContext pAVCodecContext, AVFrame* pAVFrame,
     [MarshalAs(UnmanagedType.Bool)]out bool got_picture_ptr,
     ref AVPacket packet);
Ejemplo n.º 2
0
 public static extern AVError av_read_packet(ref AVFormatContext pAVFormatContext, ref AVPacket pAVPacket);
Ejemplo n.º 3
0
 public static extern int av_write_frame(ref AVFormatContext pAVFormatContext, ref AVPacket pAVPacket);
Ejemplo n.º 4
0
 public static extern AVError av_new_packet(ref AVPacket pAVPacket, int size);
Ejemplo n.º 5
0
 public static extern void av_pkt_dump(IntPtr pFile, ref AVPacket pAVPacket, [MarshalAs(UnmanagedType.Bool)] bool dump_payload);
Ejemplo n.º 6
0
        protected override bool DecodePacket(ref AVPacket packet)
        {
            // decode video frame
            bool frameFinished = false;
            int byteCount = FFmpeg.avcodec_decode_video2(ref m_avCodecCtx, m_avFrame, out frameFinished, ref packet);
            if (byteCount < 0)
                throw new DecoderException("Couldn't decode frame");

            // copy data into our managed buffer
            if (m_avFrame->data[0] == IntPtr.Zero)
                m_bufferUsedSize = 0;
            else
                m_bufferUsedSize = FFmpeg.avpicture_layout((AVPicture*)m_avFrame, PixelFormat, Width, Height, m_buffer, m_buffer.Length);

            if (m_bufferUsedSize < 0)
                throw new DecoderException("Error copying decoded frame into managed memory");

            return frameFinished;
        }
Ejemplo n.º 7
0
 public static extern int av_interleave_packet_per_dts(ref AVFormatContext pAVFormatContext, ref AVPacket p_out_AVPacket,
     ref AVPacket pAVPacket, [MarshalAs(UnmanagedType.Bool)]bool flush);
Ejemplo n.º 8
0
 public static extern AVError av_dup_packet(ref AVPacket pAVPacket);
Ejemplo n.º 9
0
 /// <summary>
 /// Free a packet
 /// </summary>
 /// <param name="pAVPacket">packet to free</param>
 /// <remarks>
 /// Inline function defined in avformat.h, thus its code must be duplicated here since inline functions 
 /// cannot be DllImported
 /// </remarks>
 public static void av_free_packet(ref AVPacket packet)
 {
     if (packet.destruct != null)
         packet.destruct(ref packet);
 }
Ejemplo n.º 10
0
 protected abstract bool DecodePacket(ref AVPacket packet);
Ejemplo n.º 11
0
 public static extern void av_destruct_packet_nofree(ref AVPacket pAVPacket);
Ejemplo n.º 12
0
 public static extern int av_get_packet(ref AVIOContext s, ref AVPacket pkt, int size);
Ejemplo n.º 13
0
        internal void EnqueueNextPacket()
        {
            AVPacket packet = new AVPacket();
            FFmpeg.av_init_packet(ref packet);

            if (FFmpeg.av_read_frame(ref FormatContext, ref packet) < 0)
                throw new System.IO.EndOfStreamException();

            DecoderStream dest = null;
            if (m_streams.TryGetValue(packet.stream_index, out dest))
                dest.PacketQueue.Enqueue(packet);
            else
                FFmpeg.av_free_packet(ref packet);
        }
Ejemplo n.º 14
0
        protected override bool DecodePacket(ref AVPacket packet)
        {
            int totalOutput = 0;

            // Copy the data pointer to we can muck with it
            int packetSize = packet.size;
            byte* packetData = (byte*)packet.data;

            // May be necessary to loop multiple times if more than one frame is in the compressed packet
            fixed (byte* pBuffer = m_buffer)
            do
            {
                if (m_disposed)
                {
                    m_bufferUsedSize = 0;
                    return false;
                }

                int outputBufferUsedSize = m_buffer.Length - totalOutput; //Must be initialized before sending in as per docs

                short* pcmWritePtr = (short*)(pBuffer + totalOutput);

                int usedInputBytes = FFmpeg.avcodec_decode_audio2(ref m_avCodecCtx, pcmWritePtr, ref outputBufferUsedSize, packetData, packetSize);

                if (usedInputBytes < 0) //Error in packet, ignore packet
                    break;

                if (outputBufferUsedSize > 0)
                    totalOutput += outputBufferUsedSize;

                packetData += usedInputBytes;
                packetSize -= usedInputBytes;
            }
            while (packetSize > 0);

            m_bufferUsedSize = totalOutput;
            return true;
        }
Ejemplo n.º 15
0
 public static extern void av_free_packet(ref AVPacket pkt);
Ejemplo n.º 16
0
 public static extern int av_get_packet(ref ByteIOContext pByteIOContext, ref AVPacket pAVPacket, int size);
Ejemplo n.º 17
0
 public static extern void av_init_packet(ref AVPacket pkt);
Ejemplo n.º 18
0
        private void EncodeAndWritePacket()
        {
            byte[] frameBuffer = new byte[FrameSize];
            m_buffer.Read(frameBuffer, 0, frameBuffer.Length);

            fixed (byte* pcmSamples = frameBuffer)
            {
                if (m_disposed)
                    throw new ObjectDisposedException(this.ToString());

                AVPacket outPacket = new AVPacket();
                FFmpeg.av_init_packet(ref outPacket);

                byte[] buffer = new byte[FFmpeg.FF_MIN_BUFFER_SIZE];
                fixed (byte* encodedData = buffer)
                {
                    try
                    {
                        outPacket.size = FFmpeg.avcodec_encode_audio(ref m_avCodecCtx, encodedData, FFmpeg.FF_MIN_BUFFER_SIZE, (short*)pcmSamples);
                        outPacket.pts = m_avCodecCtx.coded_frame->pts;
                        outPacket.flags |= FFmpeg.PKT_FLAG_KEY;
                        outPacket.stream_index = m_avStream.index;
                        outPacket.data = (IntPtr)encodedData;

                        if (outPacket.size > 0)
                        {
                            if (FFmpeg.av_write_frame(ref m_avFormatCtx, ref outPacket) != 0)
                                throw new IOException("Error while writing encoded audio frame to file");
                        }
                    }
                    finally
                    {
                        FFmpeg.av_free_packet(ref outPacket);
                    }
                }
            }
        }