lavd/openal: don't return zero sized packet if no samples are available
authorMarton Balint <cus@passwd.hu>
Fri, 30 Sep 2016 09:08:51 +0000 (11:08 +0200)
committerMarton Balint <cus@passwd.hu>
Mon, 3 Oct 2016 19:15:48 +0000 (21:15 +0200)
Signed-off-by: Marton Balint <cus@passwd.hu>
libavdevice/openal-dec.c

index 0647952..6eb0efe 100644 (file)
@@ -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)