static int ogg_read_header(AVFormatContext *s)

{

    struct ogg *ogg = s->priv_data;

    int ret, i;



    ogg->curidx = -1;



    //linear headers seek from start

    do {

        ret = ogg_packet(s, NULL, NULL, NULL, NULL);

        if (ret < 0) {

            ogg_read_close(s);

            return ret;

        }

    } while (!ogg->headers);

    av_log(s, AV_LOG_TRACE, "found headers\n");



    for (i = 0; i < ogg->nstreams; i++) {

        struct ogg_stream *os = ogg->streams + i;



        if (ogg->streams[i].header < 0) {

            av_log(s, AV_LOG_ERROR, "Header parsing failed for stream %d\n", i);

            ogg->streams[i].codec = NULL;


        } else if (os->codec && os->nb_header < os->codec->nb_header) {

            av_log(s, AV_LOG_WARNING,

                   "Headers mismatch for stream %d: "

                   "expected %d received %d.\n",

                   i, os->codec->nb_header, os->nb_header);

            if (s->error_recognition & AV_EF_EXPLODE)

                return AVERROR_INVALIDDATA;

        }

        if (os->start_granule != OGG_NOGRANULE_VALUE)

            os->lastpts = s->streams[i]->start_time =

                ogg_gptopts(s, i, os->start_granule, NULL);

    }



    //linear granulepos seek from end

    ret = ogg_get_length(s);

    if (ret < 0) {

        ogg_read_close(s);

        return ret;

    }



    return 0;

}
static int ogg_read_header(AVFormatContext *s)

{

    struct ogg *ogg = s->priv_data;

    int ret, i;



    ogg->curidx = -1;



    

    do {

        ret = ogg_packet(s, NULL, NULL, NULL, NULL);

        if (ret < 0) {

            ogg_read_close(s);

            return ret;

        }

    } while (!ogg->headers);

    av_log(s, AV_LOG_TRACE, "found headers\n");



    for (i = 0; i < ogg->nstreams; i++) {

        struct ogg_stream *os = ogg->streams + i;



        if (ogg->streams[i].header < 0) {

            av_log(s, AV_LOG_ERROR, "Header parsing failed for stream %d\n", i);

            ogg->streams[i].codec = NULL;


        } else if (os->codec && os->nb_header < os->codec->nb_header) {

            av_log(s, AV_LOG_WARNING,

                   "Headers mismatch for stream %d: "

                   "expected %d received %d.\n",

                   i, os->codec->nb_header, os->nb_header);

            if (s->error_recognition & AV_EF_EXPLODE)

                return AVERROR_INVALIDDATA;

        }

        if (os->start_granule != OGG_NOGRANULE_VALUE)

            os->lastpts = s->streams[i]->start_time =

                ogg_gptopts(s, i, os->start_granule, NULL);

    }



    

    ret = ogg_get_length(s);

    if (ret < 0) {

        ogg_read_close(s);

        return ret;

    }



    return 0;

}
static int FUNC_0(AVFormatContext *VAR_0)

{

    struct VAR_1 *VAR_1 = VAR_0->priv_data;

    int VAR_2, VAR_3;



    VAR_1->curidx = -1;



    

    do {

        VAR_2 = ogg_packet(VAR_0, NULL, NULL, NULL, NULL);

        if (VAR_2 < 0) {

            ogg_read_close(VAR_0);

            return VAR_2;

        }

    } while (!VAR_1->headers);

    av_log(VAR_0, AV_LOG_TRACE, "found headers\n");



    for (VAR_3 = 0; VAR_3 < VAR_1->nstreams; VAR_3++) {

        struct ogg_stream *VAR_4 = VAR_1->streams + VAR_3;



        if (VAR_1->streams[VAR_3].header < 0) {

            av_log(VAR_0, AV_LOG_ERROR, "Header parsing failed for stream %d\n", VAR_3);

            VAR_1->streams[VAR_3].codec = NULL;


        } else if (VAR_4->codec && VAR_4->nb_header < VAR_4->codec->nb_header) {

            av_log(VAR_0, AV_LOG_WARNING,

                   "Headers mismatch for stream %d: "

                   "expected %d received %d.\n",

                   VAR_3, VAR_4->codec->nb_header, VAR_4->nb_header);

            if (VAR_0->error_recognition & AV_EF_EXPLODE)

                return AVERROR_INVALIDDATA;

        }

        if (VAR_4->start_granule != OGG_NOGRANULE_VALUE)

            VAR_4->lastpts = VAR_0->streams[VAR_3]->start_time =

                ogg_gptopts(VAR_0, VAR_3, VAR_4->start_granule, NULL);

    }



    

    VAR_2 = ogg_get_length(VAR_0);

    if (VAR_2 < 0) {

        ogg_read_close(VAR_0);

        return VAR_2;

    }



    return 0;

}
static int FUNC_0(AVFormatContext *VAR_0)
{ struct VAR_1 *VAR_1 = VAR_0->priv_data; int VAR_2, VAR_3; VAR_1->curidx = -1; do { VAR_2 = ogg_packet(VAR_0, NULL, NULL, NULL, NULL); if (VAR_2 < 0) { ogg_read_close(VAR_0); return VAR_2; } } while (!VAR_1->headers); av_log(VAR_0, AV_LOG_TRACE, "found headers\n"); for (VAR_3 = 0; VAR_3 < VAR_1->nstreams; VAR_3++) { struct ogg_stream *VAR_4 = VAR_1->streams + VAR_3; if (VAR_1->streams[VAR_3].header < 0) { av_log(VAR_0, AV_LOG_ERROR, "Header parsing failed for stream %d\n", VAR_3); VAR_1->streams[VAR_3].codec = NULL; } else if (VAR_4->codec && VAR_4->nb_header < VAR_4->codec->nb_header) { av_log(VAR_0, AV_LOG_WARNING,
"Headers mismatch for stream %d: "
"expected %d received %d.\n",
VAR_3, VAR_4->codec->nb_header, VAR_4->nb_header); if (VAR_0->error_recognition & AV_EF_EXPLODE)
return AVERROR_INVALIDDATA; } if (VAR_4->start_granule != OGG_NOGRANULE_VALUE)
VAR_4->lastpts = VAR_0->streams[VAR_3]->start_time =
ogg_gptopts(VAR_0, VAR_3, VAR_4->start_granule, NULL); } VAR_2 = ogg_get_length(VAR_0); if (VAR_2 < 0) { ogg_read_close(VAR_0); return VAR_2; } return 0; }