static int ogg_get_length(AVFormatContext *s)

{

    struct ogg *ogg = s->priv_data;

    int i;

    int64_t size, end;

    int streams_left=0;



    if(!s->pb->seekable)

        return 0;



// already set

    if (s->duration != AV_NOPTS_VALUE)

        return 0;



    size = avio_size(s->pb);

    if(size < 0)

        return 0;

    end = size > MAX_PAGE_SIZE? size - MAX_PAGE_SIZE: 0;



    ogg_save (s);

    avio_seek (s->pb, end, SEEK_SET);



    while (!ogg_read_page (s, &i)){

        if (ogg->streams[i].granule != -1 && ogg->streams[i].granule != 0 &&

            ogg->streams[i].codec) {

            s->streams[i]->duration =

                ogg_gptopts (s, i, ogg->streams[i].granule, NULL);

            if (s->streams[i]->start_time != AV_NOPTS_VALUE){

                s->streams[i]->duration -= s->streams[i]->start_time;

                streams_left-= (ogg->streams[i].got_start==-1);

                ogg->streams[i].got_start= 1;

            }else if(!ogg->streams[i].got_start){

                ogg->streams[i].got_start= -1;

                streams_left++;

            }

        }

    }



    ogg_restore (s, 0);



    ogg_save (s);

    avio_seek (s->pb, s->data_offset, SEEK_SET);

    ogg_reset(s);


    while (!ogg_packet(s, &i, NULL, NULL, NULL)) {


        int64_t pts = ogg_calc_pts(s, i, NULL);

        if (pts != AV_NOPTS_VALUE && s->streams[i]->start_time == AV_NOPTS_VALUE && !ogg->streams[i].got_start){

            s->streams[i]->duration -= pts;

            ogg->streams[i].got_start= 1;

            streams_left--;

        }else if(s->streams[i]->start_time != AV_NOPTS_VALUE && !ogg->streams[i].got_start){

            ogg->streams[i].got_start= 1;

            streams_left--;

        }

        }

            if(streams_left<=0)

                break;

    }

    ogg_restore (s, 0);



    return 0;

}
static int ogg_get_length(AVFormatContext *s)

{

    struct ogg *ogg = s->priv_data;

    int i;

    int64_t size, end;

    int streams_left=0;



    if(!s->pb->seekable)

        return 0;





    if (s->duration != AV_NOPTS_VALUE)

        return 0;



    size = avio_size(s->pb);

    if(size < 0)

        return 0;

    end = size > MAX_PAGE_SIZE? size - MAX_PAGE_SIZE: 0;



    ogg_save (s);

    avio_seek (s->pb, end, SEEK_SET);



    while (!ogg_read_page (s, &i)){

        if (ogg->streams[i].granule != -1 && ogg->streams[i].granule != 0 &&

            ogg->streams[i].codec) {

            s->streams[i]->duration =

                ogg_gptopts (s, i, ogg->streams[i].granule, NULL);

            if (s->streams[i]->start_time != AV_NOPTS_VALUE){

                s->streams[i]->duration -= s->streams[i]->start_time;

                streams_left-= (ogg->streams[i].got_start==-1);

                ogg->streams[i].got_start= 1;

            }else if(!ogg->streams[i].got_start){

                ogg->streams[i].got_start= -1;

                streams_left++;

            }

        }

    }



    ogg_restore (s, 0);



    ogg_save (s);

    avio_seek (s->pb, s->data_offset, SEEK_SET);

    ogg_reset(s);


    while (!ogg_packet(s, &i, NULL, NULL, NULL)) {


        int64_t pts = ogg_calc_pts(s, i, NULL);

        if (pts != AV_NOPTS_VALUE && s->streams[i]->start_time == AV_NOPTS_VALUE && !ogg->streams[i].got_start){

            s->streams[i]->duration -= pts;

            ogg->streams[i].got_start= 1;

            streams_left--;

        }else if(s->streams[i]->start_time != AV_NOPTS_VALUE && !ogg->streams[i].got_start){

            ogg->streams[i].got_start= 1;

            streams_left--;

        }

        }

            if(streams_left<=0)

                break;

    }

    ogg_restore (s, 0);



    return 0;

}
static int FUNC_0(AVFormatContext *VAR_0)

{

    struct VAR_1 *VAR_1 = VAR_0->priv_data;

    int VAR_2;

    int64_t size, end;

    int VAR_3=0;



    if(!VAR_0->pb->seekable)

        return 0;





    if (VAR_0->duration != AV_NOPTS_VALUE)

        return 0;



    size = avio_size(VAR_0->pb);

    if(size < 0)

        return 0;

    end = size > MAX_PAGE_SIZE? size - MAX_PAGE_SIZE: 0;



    ogg_save (VAR_0);

    avio_seek (VAR_0->pb, end, SEEK_SET);



    while (!ogg_read_page (VAR_0, &VAR_2)){

        if (VAR_1->streams[VAR_2].granule != -1 && VAR_1->streams[VAR_2].granule != 0 &&

            VAR_1->streams[VAR_2].codec) {

            VAR_0->streams[VAR_2]->duration =

                ogg_gptopts (VAR_0, VAR_2, VAR_1->streams[VAR_2].granule, NULL);

            if (VAR_0->streams[VAR_2]->start_time != AV_NOPTS_VALUE){

                VAR_0->streams[VAR_2]->duration -= VAR_0->streams[VAR_2]->start_time;

                VAR_3-= (VAR_1->streams[VAR_2].got_start==-1);

                VAR_1->streams[VAR_2].got_start= 1;

            }else if(!VAR_1->streams[VAR_2].got_start){

                VAR_1->streams[VAR_2].got_start= -1;

                VAR_3++;

            }

        }

    }



    FUNC_1 (VAR_0, 0);



    ogg_save (VAR_0);

    avio_seek (VAR_0->pb, VAR_0->data_offset, SEEK_SET);

    ogg_reset(VAR_0);


    while (!ogg_packet(VAR_0, &VAR_2, NULL, NULL, NULL)) {


        int64_t pts = ogg_calc_pts(VAR_0, VAR_2, NULL);

        if (pts != AV_NOPTS_VALUE && VAR_0->streams[VAR_2]->start_time == AV_NOPTS_VALUE && !VAR_1->streams[VAR_2].got_start){

            VAR_0->streams[VAR_2]->duration -= pts;

            VAR_1->streams[VAR_2].got_start= 1;

            VAR_3--;

        }else if(VAR_0->streams[VAR_2]->start_time != AV_NOPTS_VALUE && !VAR_1->streams[VAR_2].got_start){

            VAR_1->streams[VAR_2].got_start= 1;

            VAR_3--;

        }

        }

            if(VAR_3<=0)

                break;

    }

    FUNC_1 (VAR_0, 0);



    return 0;

}
static int FUNC_0(AVFormatContext *VAR_0)
{ struct VAR_1 *VAR_1 = VAR_0->priv_data; int VAR_2; int64_t size, end; int VAR_3=0; if(!VAR_0->pb->seekable)
return 0; if (VAR_0->duration != AV_NOPTS_VALUE)
return 0; size = avio_size(VAR_0->pb); if(size < 0)
return 0; end = size > MAX_PAGE_SIZE? size - MAX_PAGE_SIZE: 0; ogg_save (VAR_0); avio_seek (VAR_0->pb, end, SEEK_SET); while (!ogg_read_page (VAR_0, &VAR_2)){ if (VAR_1->streams[VAR_2].granule != -1 && VAR_1->streams[VAR_2].granule != 0 &&
VAR_1->streams[VAR_2].codec) { VAR_0->streams[VAR_2]->duration =
ogg_gptopts (VAR_0, VAR_2, VAR_1->streams[VAR_2].granule, NULL); if (VAR_0->streams[VAR_2]->start_time != AV_NOPTS_VALUE){ VAR_0->streams[VAR_2]->duration -= VAR_0->streams[VAR_2]->start_time; VAR_3-= (VAR_1->streams[VAR_2].got_start==-1); VAR_1->streams[VAR_2].got_start= 1; }else if(!VAR_1->streams[VAR_2].got_start){ VAR_1->streams[VAR_2].got_start= -1; VAR_3++; } } } FUNC_1 (VAR_0, 0); ogg_save (VAR_0); avio_seek (VAR_0->pb, VAR_0->data_offset, SEEK_SET); ogg_reset(VAR_0); while (!ogg_packet(VAR_0, &VAR_2, NULL, NULL, NULL)) { int64_t pts = ogg_calc_pts(VAR_0, VAR_2, NULL); if (pts != AV_NOPTS_VALUE && VAR_0->streams[VAR_2]->start_time == AV_NOPTS_VALUE && !VAR_1->streams[VAR_2].got_start){ VAR_0->streams[VAR_2]->duration -= pts; VAR_1->streams[VAR_2].got_start= 1; VAR_3--; }else if(VAR_0->streams[VAR_2]->start_time != AV_NOPTS_VALUE && !VAR_1->streams[VAR_2].got_start){ VAR_1->streams[VAR_2].got_start= 1; VAR_3--; } } if(VAR_3<=0)
break; } FUNC_1 (VAR_0, 0); return 0; }