From fbf8ac7d2a37b6069bb462df15e18472df004a6f Mon Sep 17 00:00:00 2001 From: Marton Balint Date: Fri, 30 Sep 2016 11:08:51 +0200 Subject: [PATCH] lavd/openal: don't return zero sized packet if no samples are available Signed-off-by: Marton Balint --- libavdevice/openal-dec.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/libavdevice/openal-dec.c b/libavdevice/openal-dec.c index 0647952f9c..6eb0efe38f 100644 --- a/libavdevice/openal-dec.c +++ b/libavdevice/openal-dec.c @@ -187,9 +187,16 @@ static int read_packet(AVFormatContext* ctx, AVPacket *pkt) const char *error_msg; ALCint nb_samples; - /* Get number of samples available */ - alcGetIntegerv(ad->device, ALC_CAPTURE_SAMPLES, (ALCsizei) sizeof(ALCint), &nb_samples); - if (error = al_get_error(ad->device, &error_msg)) goto fail; + for (;;) { + /* Get number of samples available */ + alcGetIntegerv(ad->device, ALC_CAPTURE_SAMPLES, (ALCsizei) sizeof(ALCint), &nb_samples); + if (error = al_get_error(ad->device, &error_msg)) goto fail; + if (nb_samples > 0) + break; + if (ctx->flags & AVFMT_FLAG_NONBLOCK) + return AVERROR(EAGAIN); + av_usleep(1000); + } /* Create a packet of appropriate size */ if ((error = av_new_packet(pkt, nb_samples*ad->sample_step)) < 0)