static int sync(AVFormatContext *s, int64_t *timestamp, int *flags, int *stream_index, int64_t *pos){

    RMDemuxContext *rm = s->priv_data;

    ByteIOContext *pb = s->pb;

    int len, num, res, i;

    AVStream *st;

    uint32_t state=0xFFFFFFFF;



    while(!url_feof(pb)){

        *pos= url_ftell(pb) - 3;

        if(rm->remaining_len > 0){

            num= rm->current_stream;

            len= rm->remaining_len;

            *timestamp = AV_NOPTS_VALUE;

            *flags= 0;

        }else{

            state= (state<<8) + get_byte(pb);



            if(state == MKBETAG('I', 'N', 'D', 'X')){

                int n_pkts, expected_len;

                len = get_be32(pb);

                url_fskip(pb, 2);

                n_pkts = get_be32(pb);

                expected_len = 20 + n_pkts * 14;

                if (len == 20)

                    /* some files don't add index entries to chunk size... */

                    len = expected_len;

                else if (len != expected_len)

                    av_log(s, AV_LOG_WARNING,

                           "Index size %d (%d pkts) is wrong, should be %d.\n",

                           len, n_pkts, expected_len);

                len -= 14; // we already read part of the index header

                if(len<0)

                    continue;

                goto skip;

            }



            if(state > (unsigned)0xFFFF || state < 12)

                continue;

            len=state;

            state= 0xFFFFFFFF;



            num = get_be16(pb);

            *timestamp = get_be32(pb);

            res= get_byte(pb); /* reserved */

            *flags = get_byte(pb); /* flags */





            len -= 12;

        }

        for(i=0;i<s->nb_streams;i++) {

            st = s->streams[i];

            if (num == st->id)

                break;

        }

        if (i == s->nb_streams) {

skip:

            /* skip packet if unknown number */

            url_fskip(pb, len);

            rm->remaining_len = 0;

            continue;

        }

        *stream_index= i;



        return len;

    }

    return -1;

}

static int sync(AVFormatContext *s, int64_t *timestamp, int *flags, int *stream_index, int64_t *pos){

    RMDemuxContext *rm = s->priv_data;

    ByteIOContext *pb = s->pb;

    int len, num, res, i;

    AVStream *st;

    uint32_t state=0xFFFFFFFF;



    while(!url_feof(pb)){

        *pos= url_ftell(pb) - 3;

        if(rm->remaining_len > 0){

            num= rm->current_stream;

            len= rm->remaining_len;

            *timestamp = AV_NOPTS_VALUE;

            *flags= 0;

        }else{

            state= (state<<8) + get_byte(pb);



            if(state == MKBETAG('I', 'N', 'D', 'X')){

                int n_pkts, expected_len;

                len = get_be32(pb);

                url_fskip(pb, 2);

                n_pkts = get_be32(pb);

                expected_len = 20 + n_pkts * 14;

                if (len == 20)

                    

                    len = expected_len;

                else if (len != expected_len)

                    av_log(s, AV_LOG_WARNING,

                           "Index size %d (%d pkts) is wrong, should be %d.\n",

                           len, n_pkts, expected_len);

                len -= 14; 

                if(len<0)

                    continue;

                goto skip;

            }



            if(state > (unsigned)0xFFFF || state < 12)

                continue;

            len=state;

            state= 0xFFFFFFFF;



            num = get_be16(pb);

            *timestamp = get_be32(pb);

            res= get_byte(pb); 

            *flags = get_byte(pb); 





            len -= 12;

        }

        for(i=0;i<s->nb_streams;i++) {

            st = s->streams[i];

            if (num == st->id)

                break;

        }

        if (i == s->nb_streams) {

skip:

            

            url_fskip(pb, len);

            rm->remaining_len = 0;

            continue;

        }

        *stream_index= i;



        return len;

    }

    return -1;

}

static int FUNC_0(AVFormatContext *VAR_0, int64_t *VAR_1, int *VAR_2, int *VAR_3, int64_t *VAR_4){

    RMDemuxContext *rm = VAR_0->priv_data;

    ByteIOContext *pb = VAR_0->pb;

    int VAR_5, VAR_6, VAR_7, VAR_8;

    AVStream *st;

    uint32_t state=0xFFFFFFFF;



    while(!url_feof(pb)){

        *VAR_4= url_ftell(pb) - 3;

        if(rm->remaining_len > 0){

            VAR_6= rm->current_stream;

            VAR_5= rm->remaining_len;

            *VAR_1 = AV_NOPTS_VALUE;

            *VAR_2= 0;

        }else{

            state= (state<<8) + get_byte(pb);



            if(state == MKBETAG('I', 'N', 'D', 'X')){

                int VAR_9, VAR_10;

                VAR_5 = get_be32(pb);

                url_fskip(pb, 2);

                VAR_9 = get_be32(pb);

                VAR_10 = 20 + VAR_9 * 14;

                if (VAR_5 == 20)

                    

                    VAR_5 = VAR_10;

                else if (VAR_5 != VAR_10)

                    av_log(VAR_0, AV_LOG_WARNING,

                           "Index size %d (%d pkts) is wrong, should be %d.\n",

                           VAR_5, VAR_9, VAR_10);

                VAR_5 -= 14; 

                if(VAR_5<0)

                    continue;

                goto skip;

            }



            if(state > (unsigned)0xFFFF || state < 12)

                continue;

            VAR_5=state;

            state= 0xFFFFFFFF;



            VAR_6 = get_be16(pb);

            *VAR_1 = get_be32(pb);

            VAR_7= get_byte(pb); 

            *VAR_2 = get_byte(pb); 





            VAR_5 -= 12;

        }

        for(VAR_8=0;VAR_8<VAR_0->nb_streams;VAR_8++) {

            st = VAR_0->streams[VAR_8];

            if (VAR_6 == st->id)

                break;

        }

        if (VAR_8 == VAR_0->nb_streams) {

skip:

            

            url_fskip(pb, VAR_5);

            rm->remaining_len = 0;

            continue;

        }

        *VAR_3= VAR_8;



        return VAR_5;

    }

    return -1;

}

static int FUNC_0(AVFormatContext *VAR_0, int64_t *VAR_1, int *VAR_2, int *VAR_3, int64_t *VAR_4){ RMDemuxContext *rm = VAR_0->priv_data; ByteIOContext *pb = VAR_0->pb; int VAR_5, VAR_6, VAR_7, VAR_8; AVStream *st; uint32_t state=0xFFFFFFFF; while(!url_feof(pb)){ *VAR_4= url_ftell(pb) - 3; if(rm->remaining_len > 0){ VAR_6= rm->current_stream; VAR_5= rm->remaining_len; *VAR_1 = AV_NOPTS_VALUE; *VAR_2= 0; }else{ state= (state<<8) + get_byte(pb); if(state == MKBETAG('I', 'N', 'D', 'X')){ int VAR_9, VAR_10; VAR_5 = get_be32(pb); url_fskip(pb, 2); VAR_9 = get_be32(pb); VAR_10 = 20 + VAR_9 * 14; if (VAR_5 == 20)
VAR_5 = VAR_10; else if (VAR_5 != VAR_10)
av_log(VAR_0, AV_LOG_WARNING,
"Index size %d (%d pkts) is wrong, should be %d.\n",
VAR_5, VAR_9, VAR_10); VAR_5 -= 14; if(VAR_5<0)
continue; goto skip; } if(state > (unsigned)0xFFFF || state < 12)
continue; VAR_5=state; state= 0xFFFFFFFF; VAR_6 = get_be16(pb); *VAR_1 = get_be32(pb); VAR_7= get_byte(pb); *VAR_2 = get_byte(pb); VAR_5 -= 12; } for(VAR_8=0;VAR_8<VAR_0->nb_streams;VAR_8++) { st = VAR_0->streams[VAR_8]; if (VAR_6 == st->id)
break; } if (VAR_8 == VAR_0->nb_streams) { skip:
url_fskip(pb, VAR_5); rm->remaining_len = 0; continue; } *VAR_3= VAR_8; return VAR_5; } return -1; }