diff mbox series

[FFmpeg-devel,2/5] lavf/demux: treat EAGAIN as REDO unless AVFMT_FLAG_NONBLOCK is set

Message ID 20221108112550.8375-2-anton@khirnov.net
State New
Headers show
Series [FFmpeg-devel,1/5] lavf/rtpdec_asf: set AVFMT_FLAG_NONBLOCK | expand

Checks

Context Check Description
yinshiyou/configure_loongarch64 warning Failed to run configure
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Anton Khirnov Nov. 8, 2022, 11:25 a.m. UTC
Lavf only supports a very limited approximation of non-blocking
behavior, so we should not return random EAGAINs to callers unless they
specifically requested it.
---
 libavformat/demux.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

Comments

Michael Niedermayer Nov. 10, 2022, 12:28 p.m. UTC | #1
On Tue, Nov 08, 2022 at 12:25:47PM +0100, Anton Khirnov wrote:
> Lavf only supports a very limited approximation of non-blocking
> behavior, so we should not return random EAGAINs to callers unless they
> specifically requested it.
> ---
>  libavformat/demux.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)

this changes seeking behavior of for example:
libavformat/tests/seek fate-suite/dss/sp.dss

(this seemed to return EAGAIN before sometimes)

thx

[...]
Anton Khirnov Nov. 10, 2022, 12:31 p.m. UTC | #2
Quoting Michael Niedermayer (2022-11-10 13:28:27)
> On Tue, Nov 08, 2022 at 12:25:47PM +0100, Anton Khirnov wrote:
> > Lavf only supports a very limited approximation of non-blocking
> > behavior, so we should not return random EAGAINs to callers unless they
> > specifically requested it.
> > ---
> >  libavformat/demux.c | 8 ++++++--
> >  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> this changes seeking behavior of for example:
> libavformat/tests/seek fate-suite/dss/sp.dss
> 
> (this seemed to return EAGAIN before sometimes)

Are you saying that is wrong? I don't see why seeks should return EAGAIN
either.
Paul B Mahol Nov. 10, 2022, 12:52 p.m. UTC | #3
On 11/10/22, Anton Khirnov <anton@khirnov.net> wrote:
> Quoting Michael Niedermayer (2022-11-10 13:28:27)
>> On Tue, Nov 08, 2022 at 12:25:47PM +0100, Anton Khirnov wrote:
>> > Lavf only supports a very limited approximation of non-blocking
>> > behavior, so we should not return random EAGAINs to callers unless they
>> > specifically requested it.
>> > ---
>> >  libavformat/demux.c | 8 ++++++--
>> >  1 file changed, 6 insertions(+), 2 deletions(-)
>>
>> this changes seeking behavior of for example:
>> libavformat/tests/seek fate-suite/dss/sp.dss
>>
>> (this seemed to return EAGAIN before sometimes)
>
> Are you saying that is wrong? I don't see why seeks should return EAGAIN
> either.
>

It returns internally when passing seeking to generic seeking.
Please  do not break seeking in demuxers.

> --
> Anton Khirnov
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
>
Anton Khirnov Nov. 10, 2022, 1:33 p.m. UTC | #4
Quoting Paul B Mahol (2022-11-10 13:52:52)
> On 11/10/22, Anton Khirnov <anton@khirnov.net> wrote:
> > Quoting Michael Niedermayer (2022-11-10 13:28:27)
> >> On Tue, Nov 08, 2022 at 12:25:47PM +0100, Anton Khirnov wrote:
> >> > Lavf only supports a very limited approximation of non-blocking
> >> > behavior, so we should not return random EAGAINs to callers unless they
> >> > specifically requested it.
> >> > ---
> >> >  libavformat/demux.c | 8 ++++++--
> >> >  1 file changed, 6 insertions(+), 2 deletions(-)
> >>
> >> this changes seeking behavior of for example:
> >> libavformat/tests/seek fate-suite/dss/sp.dss
> >>
> >> (this seemed to return EAGAIN before sometimes)
> >
> > Are you saying that is wrong? I don't see why seeks should return EAGAIN
> > either.
> >
> 
> It returns internally when passing seeking to generic seeking.
> Please  do not break seeking in demuxers.

What exact use case is being broken by this?
Michael Niedermayer Nov. 10, 2022, 7:52 p.m. UTC | #5
On Thu, Nov 10, 2022 at 01:31:44PM +0100, Anton Khirnov wrote:
> Quoting Michael Niedermayer (2022-11-10 13:28:27)
> > On Tue, Nov 08, 2022 at 12:25:47PM +0100, Anton Khirnov wrote:
> > > Lavf only supports a very limited approximation of non-blocking
> > > behavior, so we should not return random EAGAINs to callers unless they
> > > specifically requested it.
> > > ---
> > >  libavformat/demux.c | 8 ++++++--
> > >  1 file changed, 6 insertions(+), 2 deletions(-)
> > 
> > this changes seeking behavior of for example:
> > libavformat/tests/seek fate-suite/dss/sp.dss
> > 
> > (this seemed to return EAGAIN before sometimes)
> 
> Are you saying that is wrong? I don't see why seeks should return EAGAIN
> either.

I do not know if its wrong or not. I remember some seeking used error
returns to switch to generic seeking and such stuff.
I just reporrted this as i saw a difference in the tests/seek output

thx

[...]
Anton Khirnov Nov. 14, 2022, 9:23 a.m. UTC | #6
Quoting Michael Niedermayer (2022-11-10 20:52:33)
> On Thu, Nov 10, 2022 at 01:31:44PM +0100, Anton Khirnov wrote:
> > Quoting Michael Niedermayer (2022-11-10 13:28:27)
> > > On Tue, Nov 08, 2022 at 12:25:47PM +0100, Anton Khirnov wrote:
> > > > Lavf only supports a very limited approximation of non-blocking
> > > > behavior, so we should not return random EAGAINs to callers unless they
> > > > specifically requested it.
> > > > ---
> > > >  libavformat/demux.c | 8 ++++++--
> > > >  1 file changed, 6 insertions(+), 2 deletions(-)
> > > 
> > > this changes seeking behavior of for example:
> > > libavformat/tests/seek fate-suite/dss/sp.dss
> > > 
> > > (this seemed to return EAGAIN before sometimes)
> > 
> > Are you saying that is wrong? I don't see why seeks should return EAGAIN
> > either.
> 
> I do not know if its wrong or not. I remember some seeking used error
> returns to switch to generic seeking and such stuff.
> I just reporrted this as i saw a difference in the tests/seek output

AFAICT the differences are only in av_read_frame() calls, which no
longer return EAGAIN. That is exactly what this patch is supposed to do,
so I'd say there is no problem.

If noone has further objections, I'll push this patch soonish.
Nicolas George Nov. 14, 2022, 10:44 a.m. UTC | #7
Anton Khirnov (12022-11-14):
> If noone has further objections, I'll push this patch soonish.

You will do no scu thing since it is bogus, as I explained.
Anton Khirnov Nov. 14, 2022, 11 a.m. UTC | #8
Quoting Nicolas George (2022-11-14 11:44:55)
> Anton Khirnov (12022-11-14):
> > If noone has further objections, I'll push this patch soonish.
> 
> You will do no scu thing since it is bogus, as I explained.

I do not see any objections from you to this patch.
Nicolas George Nov. 14, 2022, 11:05 a.m. UTC | #9
Anton Khirnov (12022-11-14):
> I do not see any objections from you to this patch.

My explanations for the other patch apply to this one, obviously: if you
treat EAGAIN as REDO, you introduce a busy wait.
Anton Khirnov Nov. 14, 2022, 11:12 a.m. UTC | #10
Quoting Nicolas George (2022-11-14 12:05:10)
> Anton Khirnov (12022-11-14):
> > I do not see any objections from you to this patch.
> 
> My explanations for the other patch apply to this one, obviously: if you
> treat EAGAIN as REDO, you introduce a busy wait.

In what specific case would this supposed busy wait happen and why is it
wrong?
Nicolas George Nov. 14, 2022, 12:40 p.m. UTC | #11
Anton Khirnov (12022-11-14):
> In what specific case would this supposed busy wait happen and why is it
> wrong?

See my mail from 9 Nov 2022 13:42:24 +0100 for explanations about the
semantic of EAGAIN.
Anton Khirnov Nov. 14, 2022, 4:17 p.m. UTC | #12
Quoting Nicolas George (2022-11-14 13:40:35)
> Anton Khirnov (12022-11-14):
> > In what specific case would this supposed busy wait happen and why is it
> > wrong?
> 
> See my mail from 9 Nov 2022 13:42:24 +0100 for explanations about the
> semantic of EAGAIN.

You wrote a whole lot of text and I don't see how any of it applies to
this patch.

The standard convention everywhere is that IO may return EAGAIN in
non-blocking mode and blocks otherwise. And that is exactly what this
patch implements.
Nicolas George Nov. 14, 2022, 4:22 p.m. UTC | #13
Anton Khirnov (12022-11-14):
> You wrote a whole lot of text and I don't see how any of it applies to
> this patch.
> 
> The standard convention everywhere is that IO may return EAGAIN in
> non-blocking mode and blocks otherwise. And that is exactly what this
> patch implements.

To implement blocking on top of EAGAIN, a sleep is necessary.

REDO must not sleep.
diff mbox series

Patch

diff --git a/libavformat/demux.c b/libavformat/demux.c
index 2dfd82a63c..5cd9522367 100644
--- a/libavformat/demux.c
+++ b/libavformat/demux.c
@@ -574,8 +574,12 @@  FF_ENABLE_DEPRECATION_WARNINGS
 
             /* Some demuxers return FFERROR_REDO when they consume
                data and discard it (ignored streams, junk, extradata).
-               We must re-call the demuxer to get the real packet. */
-            if (err == FFERROR_REDO)
+               We must re-call the demuxer to get the real packet.
+
+               Treat EAGAIN the same as FFERROR_REDO, unless the user
+               requested non-blocking behavior. */
+            if (err == FFERROR_REDO ||
+                (err == AVERROR(EAGAIN) && !(s->flags & AVFMT_FLAG_NONBLOCK)))
                 continue;
             if (!pktl || err == AVERROR(EAGAIN))
                 return err;