diff mbox

[FFmpeg-devel] lavd/openal: don't return zero sized packet if no samples are available

Message ID 1475267743-17200-1-git-send-email-cus@passwd.hu
State Accepted
Commit fbf8ac7d2a37b6069bb462df15e18472df004a6f
Headers show

Commit Message

Marton Balint Sept. 30, 2016, 8:35 p.m. UTC
Signed-off-by: Marton Balint <cus@passwd.hu>
---
 libavdevice/openal-dec.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

Comments

Marton Balint Oct. 3, 2016, 8:40 p.m. UTC | #1
On Fri, 30 Sep 2016, Marton Balint wrote:

> Signed-off-by: Marton Balint <cus@passwd.hu>
> ---
> 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 0647952..6eb0efe 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)
> --

Nobody seemed interested in openal, and the EAGAIN issue pointed out by 
Nicolas is fixed, so I pushed this.

Regards,
Marton
diff mbox

Patch

diff --git a/libavdevice/openal-dec.c b/libavdevice/openal-dec.c
index 0647952..6eb0efe 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)