[FFmpeg-devel] [RFC][PATCH] avformat/flvdec: avoid reseting eof_reached to 0 silently

wm4 nfxjfg at googlemail.com
Fri Apr 10 16:04:12 CEST 2015

On Fri, 10 Apr 2015 21:17:42 +0800
Zhang Rui <bbcallen at gmail.com> wrote:

> > IMO the approach might be ok.
> I'm not sure, I need more advises about FFmpeg's error convention.
> > definitely needs work. Functions which are not static need either a ff_
> > prefix (if they're private), or a av prefix if they're public. Also,
> Actually, I want something like c++ exception to interrupt the whole stream.
> At least, like
> int avio2_r8(AVIOContext *s, AVErrorInfo *error);
> for us to introduce some fare error handling mechanism, as below:
>     AVErrorInfo error;
>     for (;; avio2_skip(s->pb, 4, &error)) {
>         pos  = avio2_tell(s->pb, &error);
>         type = (avio2_r8(s->pb, &error) & 0x1F);
>         size = avio2_rb24(s->pb, &error);
>         dts  = avio2_rb24(s->pb, &error);
>         dts |= avio2_r8(s->pb, &error) << 24;
>         if (error.error != 0) {
>             av_log(s, AV_LOG_ERROR, "IO failed: %d, %s\n",
> error.error, error.msg);
>             return AVERROR_EOF;
>         }
>         if (avio_feof(s->pb))
>             return AVERROR_EOF;
>         ....
> This kind of error handling need some more work in aviobuf.c,
> and more advises from ffmpeg developers.
> And i prefer this way than the patch I posted.

stdio.h does it this way: FILE has an error flag that is set when
something goes wrong.

> > there's nothing "safe" about these functions, even if they facilitate
> > safe behavior. They merely return with an error when EOF was reached.
> safe_io_skip()/safe_io_seek() is only a trick until it's OK to
> introduce avio2_ stuffs.
> Yes, 'safe_' prefix is ugly. I prefer 'avio2_'. :)
> > Also, why doesn't avio_skip() return an error if the skip count is not
> > 0 and the stream has reached EOF?
> The eof handling is quite confusing in ffplay for me. AVERROR_EOF is
> clear enough.

Well, I have no idea what avio_skip() even returns... it just calls
avio_seek(), which is a goddamn fucked up mess thanks to years of
people adding hacks.

ffplay probably does it wrong. Wouldn't be surprising. It checks
avio_feof() after a av_read_frame() call, which doesn't look correct.
File EOF has absolutely nothing to do with whether a demuxer still has

On a side note, I'm not sure whether av_read_frame() returning
AVERROR_EOF is an error at all, or just signals that the end of the
file was reached. The doxygen on this function isn't helpful either.

> But for the left, if we are already at a wrong position without loud error.
> avio_feof(ic->pb) would lead us to the wrong way, more deep.
> and send completely broken packets to decoder, or do some insane seek on stream.
> It can be easily reduced by set "timeout" to some very short time
> (20000 for 20 milliseconds).
> for flv samples on remote http server.
> AVERROR_EOF is not good for safe_io_skip, but some other error code is
> not good enough.

More information about the ffmpeg-devel mailing list