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

Zhang Rui bbcallen at gmail.com
Fri Apr 10 15:17:42 CEST 2015


> 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.

> 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.
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