static int ogg_packet(AVFormatContext *s, int *str, int *dstart, int *dsize,

                      int64_t *fpos)

{

    struct ogg *ogg = s->priv_data;

    int idx, i, ret;

    struct ogg_stream *os;

    int complete = 0;

    int segp = 0, psize = 0;



    av_dlog(s, "ogg_packet: curidx=%i\n", ogg->curidx);



    do{

        idx = ogg->curidx;



        while (idx < 0){

            ret = ogg_read_page(s, &idx);

            if (ret < 0)

                return ret;

        }



        os = ogg->streams + idx;



        av_dlog(s, "ogg_packet: idx=%d pstart=%d psize=%d segp=%d nsegs=%d\n",

                idx, os->pstart, os->psize, os->segp, os->nsegs);



        if (!os->codec){

            if (os->header < 0){

                os->codec = ogg_find_codec (os->buf, os->bufpos);

                if (!os->codec){

                    av_log(s, AV_LOG_WARNING, "Codec not found\n");

                    os->header = 0;

                    return 0;

                }

            }else{

                return 0;

            }

        }



        segp = os->segp;

        psize = os->psize;



        while (os->segp < os->nsegs){

            int ss = os->segments[os->segp++];

            os->psize += ss;

            if (ss < 255){

                complete = 1;

                break;

            }

        }



        if (!complete && os->segp == os->nsegs){

            ogg->curidx = -1;

            os->incomplete = 1;

        }

    }while (!complete);





    if (os->granule == -1)

        av_log(s, AV_LOG_WARNING, "Page at %"PRId64" is missing granule\n", os->page_pos);



    ogg->curidx = idx;

    os->incomplete = 0;



    if (os->header) {

        os->header = os->codec->header (s, idx);

        if (!os->header){

            os->segp = segp;

            os->psize = psize;



            // We have reached the first non-header packet in this stream.

            // Unfortunately more header packets may still follow for others,

            // but if we continue with header parsing we may lose data packets.

            ogg->headers = 1;



            // Update the header state for all streams and

            // compute the data_offset.

            if (!s->data_offset)

                s->data_offset = os->sync_pos;

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

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



                // if we have a partial non-header packet, its start is

                // obviously at or after the data start

                if (cur_os->incomplete)

                    s->data_offset = FFMIN(s->data_offset, cur_os->sync_pos);

            }

        }else{

            os->pstart += os->psize;

            os->psize = 0;

        }

    } else {

        os->pflags = 0;

        os->pduration = 0;

        if (os->codec && os->codec->packet)

            os->codec->packet (s, idx);

        if (str)

            *str = idx;

        if (dstart)

            *dstart = os->pstart;

        if (dsize)

            *dsize = os->psize;

        if (fpos)

            *fpos = os->sync_pos;

        os->pstart += os->psize;

        os->psize = 0;

        if(os->pstart == os->bufpos)

            os->bufpos = os->pstart = 0;

        os->sync_pos = os->page_pos;

    }



    // determine whether there are more complete packets in this page

    // if not, the page's granule will apply to this packet

    os->page_end = 1;

    for (i = os->segp; i < os->nsegs; i++)

        if (os->segments[i] < 255) {

            os->page_end = 0;

            break;

        }



    if (os->segp == os->nsegs)

        ogg->curidx = -1;



    return 0;

}

static int ogg_packet(AVFormatContext *s, int *str, int *dstart, int *dsize,

                      int64_t *fpos)

{

    struct ogg *ogg = s->priv_data;

    int idx, i, ret;

    struct ogg_stream *os;

    int complete = 0;

    int segp = 0, psize = 0;



    av_dlog(s, "ogg_packet: curidx=%i\n", ogg->curidx);



    do{

        idx = ogg->curidx;



        while (idx < 0){

            ret = ogg_read_page(s, &idx);

            if (ret < 0)

                return ret;

        }



        os = ogg->streams + idx;



        av_dlog(s, "ogg_packet: idx=%d pstart=%d psize=%d segp=%d nsegs=%d\n",

                idx, os->pstart, os->psize, os->segp, os->nsegs);



        if (!os->codec){

            if (os->header < 0){

                os->codec = ogg_find_codec (os->buf, os->bufpos);

                if (!os->codec){

                    av_log(s, AV_LOG_WARNING, "Codec not found\n");

                    os->header = 0;

                    return 0;

                }

            }else{

                return 0;

            }

        }



        segp = os->segp;

        psize = os->psize;



        while (os->segp < os->nsegs){

            int ss = os->segments[os->segp++];

            os->psize += ss;

            if (ss < 255){

                complete = 1;

                break;

            }

        }



        if (!complete && os->segp == os->nsegs){

            ogg->curidx = -1;

            os->incomplete = 1;

        }

    }while (!complete);





    if (os->granule == -1)

        av_log(s, AV_LOG_WARNING, "Page at %"PRId64" is missing granule\n", os->page_pos);



    ogg->curidx = idx;

    os->incomplete = 0;



    if (os->header) {

        os->header = os->codec->header (s, idx);

        if (!os->header){

            os->segp = segp;

            os->psize = psize;



            

            

            

            ogg->headers = 1;



            

            

            if (!s->data_offset)

                s->data_offset = os->sync_pos;

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

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



                

                

                if (cur_os->incomplete)

                    s->data_offset = FFMIN(s->data_offset, cur_os->sync_pos);

            }

        }else{

            os->pstart += os->psize;

            os->psize = 0;

        }

    } else {

        os->pflags = 0;

        os->pduration = 0;

        if (os->codec && os->codec->packet)

            os->codec->packet (s, idx);

        if (str)

            *str = idx;

        if (dstart)

            *dstart = os->pstart;

        if (dsize)

            *dsize = os->psize;

        if (fpos)

            *fpos = os->sync_pos;

        os->pstart += os->psize;

        os->psize = 0;

        if(os->pstart == os->bufpos)

            os->bufpos = os->pstart = 0;

        os->sync_pos = os->page_pos;

    }



    

    

    os->page_end = 1;

    for (i = os->segp; i < os->nsegs; i++)

        if (os->segments[i] < 255) {

            os->page_end = 0;

            break;

        }



    if (os->segp == os->nsegs)

        ogg->curidx = -1;



    return 0;

}

            os->incomplete = 1;
static int FUNC_0(AVFormatContext *VAR_0, int *VAR_1, int *VAR_2, int *VAR_3,

                      int64_t *VAR_4)

{

    struct VAR_5 *VAR_5 = VAR_0->priv_data;

    int VAR_6, VAR_7, VAR_8;

    struct ogg_stream *VAR_9;

    int VAR_10 = 0;

    int VAR_11 = 0, VAR_12 = 0;



    av_dlog(VAR_0, "FUNC_0: curidx=%VAR_7\n", VAR_5->curidx);



    do{

        VAR_6 = VAR_5->curidx;



        while (VAR_6 < 0){

            VAR_8 = ogg_read_page(VAR_0, &VAR_6);

            if (VAR_8 < 0)

                return VAR_8;

        }



        VAR_9 = VAR_5->streams + VAR_6;



        av_dlog(VAR_0, "FUNC_0: VAR_6=%d pstart=%d VAR_12=%d VAR_11=%d nsegs=%d\n",

                VAR_6, VAR_9->pstart, VAR_9->VAR_12, VAR_9->VAR_11, VAR_9->nsegs);



        if (!VAR_9->codec){

            if (VAR_9->header < 0){

                VAR_9->codec = ogg_find_codec (VAR_9->buf, VAR_9->bufpos);

                if (!VAR_9->codec){

                    av_log(VAR_0, AV_LOG_WARNING, "Codec not found\n");

                    VAR_9->header = 0;

                    return 0;

                }

            }else{

                return 0;

            }

        }



        VAR_11 = VAR_9->VAR_11;

        VAR_12 = VAR_9->VAR_12;



        while (VAR_9->VAR_11 < VAR_9->nsegs){

            int VAR_13 = VAR_9->segments[VAR_9->VAR_11++];

            VAR_9->VAR_12 += VAR_13;

            if (VAR_13 < 255){

                VAR_10 = 1;

                break;

            }

        }



        if (!VAR_10 && VAR_9->VAR_11 == VAR_9->nsegs){

            VAR_5->curidx = -1;

            VAR_9->incomplete = 1;

        }

    }while (!VAR_10);





    if (VAR_9->granule == -1)

        av_log(VAR_0, AV_LOG_WARNING, "Page at %"PRId64" is missing granule\n", VAR_9->page_pos);



    VAR_5->curidx = VAR_6;

    VAR_9->incomplete = 0;



    if (VAR_9->header) {

        VAR_9->header = VAR_9->codec->header (VAR_0, VAR_6);

        if (!VAR_9->header){

            VAR_9->VAR_11 = VAR_11;

            VAR_9->VAR_12 = VAR_12;



            

            

            

            VAR_5->headers = 1;



            

            

            if (!VAR_0->data_offset)

                VAR_0->data_offset = VAR_9->sync_pos;

            for (VAR_7 = 0; VAR_7 < VAR_5->nstreams; VAR_7++) {

                struct ogg_stream *VAR_14 = VAR_5->streams + VAR_7;



                

                

                if (VAR_14->incomplete)

                    VAR_0->data_offset = FFMIN(VAR_0->data_offset, VAR_14->sync_pos);

            }

        }else{

            VAR_9->pstart += VAR_9->VAR_12;

            VAR_9->VAR_12 = 0;

        }

    } else {

        VAR_9->pflags = 0;

        VAR_9->pduration = 0;

        if (VAR_9->codec && VAR_9->codec->packet)

            VAR_9->codec->packet (VAR_0, VAR_6);

        if (VAR_1)

            *VAR_1 = VAR_6;

        if (VAR_2)

            *VAR_2 = VAR_9->pstart;

        if (VAR_3)

            *VAR_3 = VAR_9->VAR_12;

        if (VAR_4)

            *VAR_4 = VAR_9->sync_pos;

        VAR_9->pstart += VAR_9->VAR_12;

        VAR_9->VAR_12 = 0;

        if(VAR_9->pstart == VAR_9->bufpos)

            VAR_9->bufpos = VAR_9->pstart = 0;

        VAR_9->sync_pos = VAR_9->page_pos;

    }



    

    

    VAR_9->page_end = 1;

    for (VAR_7 = VAR_9->VAR_11; VAR_7 < VAR_9->nsegs; VAR_7++)

        if (VAR_9->segments[VAR_7] < 255) {

            VAR_9->page_end = 0;

            break;

        }



    if (VAR_9->VAR_11 == VAR_9->nsegs)

        VAR_5->curidx = -1;



    return 0;

}

static int FUNC_0(AVFormatContext *VAR_0, int *VAR_1, int *VAR_2, int *VAR_3,
int64_t *VAR_4)
{ struct VAR_5 *VAR_5 = VAR_0->priv_data; int VAR_6, VAR_7, VAR_8; struct ogg_stream *VAR_9; int VAR_10 = 0; int VAR_11 = 0, VAR_12 = 0; av_dlog(VAR_0, "FUNC_0: curidx=%VAR_7\n", VAR_5->curidx); do{ VAR_6 = VAR_5->curidx; while (VAR_6 < 0){ VAR_8 = ogg_read_page(VAR_0, &VAR_6); if (VAR_8 < 0)
return VAR_8; } VAR_9 = VAR_5->streams + VAR_6; av_dlog(VAR_0, "FUNC_0: VAR_6=%d pstart=%d VAR_12=%d VAR_11=%d nsegs=%d\n",
VAR_6, VAR_9->pstart, VAR_9->VAR_12, VAR_9->VAR_11, VAR_9->nsegs); if (!VAR_9->codec){ if (VAR_9->header < 0){ VAR_9->codec = ogg_find_codec (VAR_9->buf, VAR_9->bufpos); if (!VAR_9->codec){ av_log(VAR_0, AV_LOG_WARNING, "Codec not found\n"); VAR_9->header = 0; return 0; } }else{ return 0; } } VAR_11 = VAR_9->VAR_11; VAR_12 = VAR_9->VAR_12; while (VAR_9->VAR_11 < VAR_9->nsegs){ int VAR_13 = VAR_9->segments[VAR_9->VAR_11++]; VAR_9->VAR_12 += VAR_13; if (VAR_13 < 255){ VAR_10 = 1; break; } } if (!VAR_10 && VAR_9->VAR_11 == VAR_9->nsegs){ VAR_5->curidx = -1; VAR_9->incomplete = 1; } }while (!VAR_10); if (VAR_9->granule == -1)
av_log(VAR_0, AV_LOG_WARNING, "Page at %"PRId64" is missing granule\n", VAR_9->page_pos); VAR_5->curidx = VAR_6; VAR_9->incomplete = 0; if (VAR_9->header) { VAR_9->header = VAR_9->codec->header (VAR_0, VAR_6); if (!VAR_9->header){ VAR_9->VAR_11 = VAR_11; VAR_9->VAR_12 = VAR_12; VAR_5->headers = 1; if (!VAR_0->data_offset)
VAR_0->data_offset = VAR_9->sync_pos; for (VAR_7 = 0; VAR_7 < VAR_5->nstreams; VAR_7++) { struct ogg_stream *VAR_14 = VAR_5->streams + VAR_7; if (VAR_14->incomplete)
VAR_0->data_offset = FFMIN(VAR_0->data_offset, VAR_14->sync_pos); } }else{ VAR_9->pstart += VAR_9->VAR_12; VAR_9->VAR_12 = 0; } } else { VAR_9->pflags = 0; VAR_9->pduration = 0; if (VAR_9->codec && VAR_9->codec->packet)
VAR_9->codec->packet (VAR_0, VAR_6); if (VAR_1)
*VAR_1 = VAR_6; if (VAR_2)
*VAR_2 = VAR_9->pstart; if (VAR_3)
*VAR_3 = VAR_9->VAR_12; if (VAR_4)
*VAR_4 = VAR_9->sync_pos; VAR_9->pstart += VAR_9->VAR_12; VAR_9->VAR_12 = 0; if(VAR_9->pstart == VAR_9->bufpos)
VAR_9->bufpos = VAR_9->pstart = 0; VAR_9->sync_pos = VAR_9->page_pos; } VAR_9->page_end = 1; for (VAR_7 = VAR_9->VAR_11; VAR_7 < VAR_9->nsegs; VAR_7++) if (VAR_9->segments[VAR_7] < 255) { VAR_9->page_end = 0; break; } if (VAR_9->VAR_11 == VAR_9->nsegs)
VAR_5->curidx = -1; return 0; }