[libav-api] How to play/decode audio file with libav

Ronald S. Bultje rsbultje at gmail.com
Tue Jun 28 02:38:49 CEST 2011


Hi,

On Mon, Jun 27, 2011 at 3:12 AM, Manuel Reimer
<manuel.spam at nurfuerspam.de> wrote:
> What I can't find out is how to read my custom stream.
>
> What I have is a C++ class. I create a instance of this and pass the URL to the
> constructor. The class then offers a "read" function, which returns a memory
> buffer to what already has been received and a byte count so I know how many
> bytes are in that buffer. The buffer has to be emptied completely, so I hope
> ffmpeg provides buffers with an matching size... At end of playback the class
> function "close" has to be called.
>
> First problem is, that I need a way to forward the class pointer of my c++ class
> down to whatever function libavcodec uses to read the stream, so I can avoid
> global variables.
>
> And the biggest problem: I have no idea how I can connect my custom stream
> handling to libavcodec... "Seek", of course, doesn't work for a stream. So what
> I need is some kind of "open()", "read()" and "close()".

You set your own I/O through a AVIOContext, which you set in
AVFormatContext->pb. mplayer, gstreamer and others use this to provide
custom I/O into libavformat. In this class, though
avio_alloc_context(), you set function pointers to read/write/etc.
from your customs tream, plus some private data (e.g. pointer to your
class).

Ronald


More information about the libav-api mailing list