On date Wednesday 2015-11-18 15:21:15 +0100, Nicolas George encoded:
> Le septidi 27 brumaire, an CCXXIV, Stefano Sabatini a écrit :
> > Fix demuxing of files for which the demuxer returns AVERROR(EAGAIN) at
> > some point. Also returns error code to the caller in case of different
> > non EOF error.
> > ---
> >  ffprobe.c | 11 ++++++++++-
> >  1 file changed, 10 insertions(+), 1 deletion(-)
> > 
> > diff --git a/ffprobe.c b/ffprobe.c
> > index c304a6d..481ff0b 100644
> > --- a/ffprobe.c
> > +++ b/ffprobe.c
> > @@ -2027,7 +2027,16 @@ static int read_interval_packets(WriterContext *w, 
> > AVFormatContext *fmt_ctx,
> >          ret = AVERROR(ENOMEM);
> >          goto end;
> >      }
> > -    while (!av_read_frame(fmt_ctx, &pkt)) {
> 
> > +    while (1) {
> > +        ret = av_read_frame(fmt_ctx, &pkt);
> > +        if (ret == AVERROR(EAGAIN))
> > +            continue;
> 
> This is a busy wait, this is one of the evilest constructions possible.
> 

> For real EAGAIN cases, a sleep would be needed, until we have a real event
> loop. Other cases are bugs in the demuxers.

Yes, updated patch with EAGAIN (if this is fine, I'll send patches to
fix the examples).

In my case the EAGAIN is triggered by the flv demuxer code in
flvdec.c:935:

        /* skip empty data packets */
        if (!size) {
            ret = AVERROR(EAGAIN);
            goto leave;
        }

introduced in 527c2e64295671bfcd9c86ca2cfd75e0f4d79f73.

Not sure if this is a defect.
-- 
FFmpeg = Fast and Furious Magic Proud Eager Guide
>From 50ead71633e99197ead0bae8d99640dbac28e1d0 Mon Sep 17 00:00:00 2001
From: Stefano Sabatini <stefa...@gmail.com>
Date: Tue, 17 Nov 2015 15:11:09 +0100
Subject: [PATCH] ffprobe: Sleep and retry when the demuxer returns
 AVERROR(EAGAIN)

Fix demuxing of files for which the demuxer returns AVERROR(EAGAIN) at
some point. Also return error code to the caller in case of non-EOF
error.
---
 ffprobe.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/ffprobe.c b/ffprobe.c
index c304a6d..b4ab286 100644
--- a/ffprobe.c
+++ b/ffprobe.c
@@ -41,6 +41,7 @@
 #include "libavutil/intreadwrite.h"
 #include "libavutil/libm.h"
 #include "libavutil/parseutils.h"
+#include "libavutil/time.h"
 #include "libavutil/timecode.h"
 #include "libavutil/timestamp.h"
 #include "libavdevice/avdevice.h"
@@ -2027,7 +2028,18 @@ static int read_interval_packets(WriterContext *w, AVFormatContext *fmt_ctx,
         ret = AVERROR(ENOMEM);
         goto end;
     }
-    while (!av_read_frame(fmt_ctx, &pkt)) {
+    while (1) {
+        ret = av_read_frame(fmt_ctx, &pkt);
+        if (ret == AVERROR(EAGAIN)) {
+            av_usleep(10000);
+            continue;
+        }
+        if (ret < 0) {
+            if (ret == AVERROR_EOF)
+                ret = 0;
+            break;
+        }
+
         if (fmt_ctx->nb_streams > nb_streams) {
             REALLOCZ_ARRAY_STREAM(nb_streams_frames,  nb_streams, fmt_ctx->nb_streams);
             REALLOCZ_ARRAY_STREAM(nb_streams_packets, nb_streams, fmt_ctx->nb_streams);
-- 
1.9.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

Reply via email to