[FFmpeg-devel] [PATCH] lavdevice: SDL Audio Playback

Ivo ivop
Fri Dec 4 21:38:44 CET 2009


On Wednesday 02 December 2009, 21:44:03, Michael Niedermayer wrote:
> On Fri, Nov 27, 2009 at 05:38:41PM +0100, Ivo wrote:
> > Hi,
> >
> > The attached patch implements an SDL audio playback muxer in
> > libavdevice. Sadly, SDL does not support recording. In theory this
> > should also enable audio playback on windows/cygwin (not tested).
>
> [...]
>
> > +static void sdl_audio_callback(void *opaque, Uint8 *stream, int len) {
> > +    AVFormatContext *s1 = opaque;
> > +    SdlAudioData    *s  = s1->priv_data;
> > +    int size;
> > +
> > +    size = av_fifo_size(s->buffer);
> > +
> > +    av_fifo_generic_read(s->buffer, stream, FFMIN(size,len), NULL);
> > +
> > +    if (size < len) {
> > +        memset(stream+size, 0, len-size);
> > +        av_log(s1, AV_LOG_ERROR, "buffer underrun\n");
> > +    }
> > +}
>
> [...]
>
> > +static int audio_write_packet(AVFormatContext *s1, AVPacket *pkt) {
> > +    SdlAudioData *s = s1->priv_data;
> > +    int counter, ret, space, size = pkt->size;
> > +    uint8_t *data = pkt->data;
> > +
> >
> > +    if (size*4 > s->bufsize) {
> > +        if (av_fifo_realloc2(s->buffer, size*4) < 0)
> > +            return AVERROR(ENOMEM);
> > +        s->bufsize = size*4;
> > +    }
>
> does not look thread safe

Yes, you are right. I'll fix it next time I resend the patch. First I want 
to have the libavdevice API for audio and video output devices changed, so 
I can start writing a whole bunch of those. I'll send a proposal next week.

--Ivo



More information about the ffmpeg-devel mailing list