ff_rm_parse_packet (AVFormatContext *s, AVIOContext *pb,

                    AVStream *st, RMStream *ast, int len, AVPacket *pkt,

                    int *seq, int flags, int64_t timestamp)

{

    RMDemuxContext *rm = s->priv_data;

    int ret;



    if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {

        rm->current_stream= st->id;

        ret = rm_assemble_video_frame(s, pb, rm, ast, pkt, len, seq, &timestamp);

        if(ret)

            return ret < 0 ? ret : -1; //got partial frame or error

    } else if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {

        if ((ast->deint_id == DEINT_ID_GENR) ||

            (ast->deint_id == DEINT_ID_INT4) ||

            (ast->deint_id == DEINT_ID_SIPR)) {

            int x;

            int sps = ast->sub_packet_size;

            int cfs = ast->coded_framesize;

            int h = ast->sub_packet_h;

            int y = ast->sub_packet_cnt;

            int w = ast->audio_framesize;



            if (flags & 2)

                y = ast->sub_packet_cnt = 0;

            if (!y)

                ast->audiotimestamp = timestamp;



            switch (ast->deint_id) {

                case DEINT_ID_INT4:

                    for (x = 0; x < h/2; x++)

                        avio_read(pb, ast->pkt.data+x*2*w+y*cfs, cfs);

                    break;

                case DEINT_ID_GENR:

                    for (x = 0; x < w/sps; x++)

                        avio_read(pb, ast->pkt.data+sps*(h*x+((h+1)/2)*(y&1)+(y>>1)), sps);

                    break;

                case DEINT_ID_SIPR:

                    avio_read(pb, ast->pkt.data + y * w, w);

                    break;

            }



            if (++(ast->sub_packet_cnt) < h)

                return -1;

            if (ast->deint_id == DEINT_ID_SIPR)

                ff_rm_reorder_sipr_data(ast->pkt.data, h, w);



             ast->sub_packet_cnt = 0;

             rm->audio_stream_num = st->index;

             rm->audio_pkt_cnt = h * w / st->codec->block_align;

        } else if ((ast->deint_id == DEINT_ID_VBRF) ||

                   (ast->deint_id == DEINT_ID_VBRS)) {

            int x;

            rm->audio_stream_num = st->index;

            ast->sub_packet_cnt = (avio_rb16(pb) & 0xf0) >> 4;

            if (ast->sub_packet_cnt) {

                for (x = 0; x < ast->sub_packet_cnt; x++)

                    ast->sub_packet_lengths[x] = avio_rb16(pb);

                rm->audio_pkt_cnt = ast->sub_packet_cnt;

                ast->audiotimestamp = timestamp;

            } else

                return -1;

        } else {

            av_get_packet(pb, pkt, len);

            rm_ac3_swap_bytes(st, pkt);

        }

    } else

        av_get_packet(pb, pkt, len);



    pkt->stream_index = st->index;



#if 0

    if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {

        if(st->codec->codec_id == AV_CODEC_ID_RV20){

            int seq= 128*(pkt->data[2]&0x7F) + (pkt->data[3]>>1);

            av_log(s, AV_LOG_DEBUG, "%d %"PRId64" %d\n", *timestamp, *timestamp*512LL/25, seq);



            seq |= (timestamp&~0x3FFF);

            if(seq - timestamp >  0x2000) seq -= 0x4000;

            if(seq - timestamp < -0x2000) seq += 0x4000;

        }

    }

#endif



    pkt->pts = timestamp;

    if (flags & 2)

        pkt->flags |= AV_PKT_FLAG_KEY;



    return st->codec->codec_type == AVMEDIA_TYPE_AUDIO ? rm->audio_pkt_cnt : 0;

}

ff_rm_parse_packet (AVFormatContext *s, AVIOContext *pb,

                    AVStream *st, RMStream *ast, int len, AVPacket *pkt,

                    int *seq, int flags, int64_t timestamp)

{

    RMDemuxContext *rm = s->priv_data;

    int ret;



    if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {

        rm->current_stream= st->id;

        ret = rm_assemble_video_frame(s, pb, rm, ast, pkt, len, seq, &timestamp);

        if(ret)

            return ret < 0 ? ret : -1; 

    } else if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {

        if ((ast->deint_id == DEINT_ID_GENR) ||

            (ast->deint_id == DEINT_ID_INT4) ||

            (ast->deint_id == DEINT_ID_SIPR)) {

            int x;

            int sps = ast->sub_packet_size;

            int cfs = ast->coded_framesize;

            int h = ast->sub_packet_h;

            int y = ast->sub_packet_cnt;

            int w = ast->audio_framesize;



            if (flags & 2)

                y = ast->sub_packet_cnt = 0;

            if (!y)

                ast->audiotimestamp = timestamp;



            switch (ast->deint_id) {

                case DEINT_ID_INT4:

                    for (x = 0; x < h/2; x++)

                        avio_read(pb, ast->pkt.data+x*2*w+y*cfs, cfs);

                    break;

                case DEINT_ID_GENR:

                    for (x = 0; x < w/sps; x++)

                        avio_read(pb, ast->pkt.data+sps*(h*x+((h+1)/2)*(y&1)+(y>>1)), sps);

                    break;

                case DEINT_ID_SIPR:

                    avio_read(pb, ast->pkt.data + y * w, w);

                    break;

            }



            if (++(ast->sub_packet_cnt) < h)

                return -1;

            if (ast->deint_id == DEINT_ID_SIPR)

                ff_rm_reorder_sipr_data(ast->pkt.data, h, w);



             ast->sub_packet_cnt = 0;

             rm->audio_stream_num = st->index;

             rm->audio_pkt_cnt = h * w / st->codec->block_align;

        } else if ((ast->deint_id == DEINT_ID_VBRF) ||

                   (ast->deint_id == DEINT_ID_VBRS)) {

            int x;

            rm->audio_stream_num = st->index;

            ast->sub_packet_cnt = (avio_rb16(pb) & 0xf0) >> 4;

            if (ast->sub_packet_cnt) {

                for (x = 0; x < ast->sub_packet_cnt; x++)

                    ast->sub_packet_lengths[x] = avio_rb16(pb);

                rm->audio_pkt_cnt = ast->sub_packet_cnt;

                ast->audiotimestamp = timestamp;

            } else

                return -1;

        } else {

            av_get_packet(pb, pkt, len);

            rm_ac3_swap_bytes(st, pkt);

        }

    } else

        av_get_packet(pb, pkt, len);



    pkt->stream_index = st->index;



#if 0

    if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {

        if(st->codec->codec_id == AV_CODEC_ID_RV20){

            int seq= 128*(pkt->data[2]&0x7F) + (pkt->data[3]>>1);

            av_log(s, AV_LOG_DEBUG, "%d %"PRId64" %d\n", *timestamp, *timestamp*512LL/25, seq);



            seq |= (timestamp&~0x3FFF);

            if(seq - timestamp >  0x2000) seq -= 0x4000;

            if(seq - timestamp < -0x2000) seq += 0x4000;

        }

    }

#endif



    pkt->pts = timestamp;

    if (flags & 2)

        pkt->flags |= AV_PKT_FLAG_KEY;



    return st->codec->codec_type == AVMEDIA_TYPE_AUDIO ? rm->audio_pkt_cnt : 0;

}

                        avio_read(pb, ast->pkt.data+x*2*w+y*cfs, cfs);                         avio_read(pb, ast->pkt.data+sps*(h*x+((h+1)/2)*(y&1)+(y>>1)), sps);                     avio_read(pb, ast->pkt.data + y * w, w);
FUNC_0 (AVFormatContext *VAR_0, AVIOContext *VAR_1,

                    AVStream *VAR_2, RMStream *VAR_3, int VAR_4, AVPacket *VAR_5,

                    int *VAR_6, int VAR_7, int64_t VAR_8)

{

    RMDemuxContext *rm = VAR_0->priv_data;

    int VAR_9;



    if (VAR_2->codec->codec_type == AVMEDIA_TYPE_VIDEO) {

        rm->current_stream= VAR_2->id;

        VAR_9 = rm_assemble_video_frame(VAR_0, VAR_1, rm, VAR_3, VAR_5, VAR_4, VAR_6, &VAR_8);

        if(VAR_9)

            return VAR_9 < 0 ? VAR_9 : -1; 

    } else if (VAR_2->codec->codec_type == AVMEDIA_TYPE_AUDIO) {

        if ((VAR_3->deint_id == DEINT_ID_GENR) ||

            (VAR_3->deint_id == DEINT_ID_INT4) ||

            (VAR_3->deint_id == DEINT_ID_SIPR)) {

            int VAR_16;

            int VAR_11 = VAR_3->sub_packet_size;

            int VAR_12 = VAR_3->coded_framesize;

            int VAR_13 = VAR_3->sub_packet_h;

            int VAR_14 = VAR_3->sub_packet_cnt;

            int VAR_15 = VAR_3->audio_framesize;



            if (VAR_7 & 2)

                VAR_14 = VAR_3->sub_packet_cnt = 0;

            if (!VAR_14)

                VAR_3->audiotimestamp = VAR_8;



            switch (VAR_3->deint_id) {

                case DEINT_ID_INT4:

                    for (VAR_16 = 0; VAR_16 < VAR_13/2; VAR_16++)

                        avio_read(VAR_1, VAR_3->VAR_5.data+VAR_16*2*VAR_15+VAR_14*VAR_12, VAR_12);

                    break;

                case DEINT_ID_GENR:

                    for (VAR_16 = 0; VAR_16 < VAR_15/VAR_11; VAR_16++)

                        avio_read(VAR_1, VAR_3->VAR_5.data+VAR_11*(VAR_13*VAR_16+((VAR_13+1)/2)*(VAR_14&1)+(VAR_14>>1)), VAR_11);

                    break;

                case DEINT_ID_SIPR:

                    avio_read(VAR_1, VAR_3->VAR_5.data + VAR_14 * VAR_15, VAR_15);

                    break;

            }



            if (++(VAR_3->sub_packet_cnt) < VAR_13)

                return -1;

            if (VAR_3->deint_id == DEINT_ID_SIPR)

                ff_rm_reorder_sipr_data(VAR_3->VAR_5.data, VAR_13, VAR_15);



             VAR_3->sub_packet_cnt = 0;

             rm->audio_stream_num = VAR_2->index;

             rm->audio_pkt_cnt = VAR_13 * VAR_15 / VAR_2->codec->block_align;

        } else if ((VAR_3->deint_id == DEINT_ID_VBRF) ||

                   (VAR_3->deint_id == DEINT_ID_VBRS)) {

            int VAR_16;

            rm->audio_stream_num = VAR_2->index;

            VAR_3->sub_packet_cnt = (avio_rb16(VAR_1) & 0xf0) >> 4;

            if (VAR_3->sub_packet_cnt) {

                for (VAR_16 = 0; VAR_16 < VAR_3->sub_packet_cnt; VAR_16++)

                    VAR_3->sub_packet_lengths[VAR_16] = avio_rb16(VAR_1);

                rm->audio_pkt_cnt = VAR_3->sub_packet_cnt;

                VAR_3->audiotimestamp = VAR_8;

            } else

                return -1;

        } else {

            av_get_packet(VAR_1, VAR_5, VAR_4);

            rm_ac3_swap_bytes(VAR_2, VAR_5);

        }

    } else

        av_get_packet(VAR_1, VAR_5, VAR_4);



    VAR_5->stream_index = VAR_2->index;



#if 0

    if (VAR_2->codec->codec_type == AVMEDIA_TYPE_VIDEO) {

        if(VAR_2->codec->codec_id == AV_CODEC_ID_RV20){

            int VAR_6= 128*(VAR_5->data[2]&0x7F) + (VAR_5->data[3]>>1);

            av_log(VAR_0, AV_LOG_DEBUG, "%d %"PRId64" %d\n", *VAR_8, *VAR_8*512LL/25, VAR_6);



            VAR_6 |= (VAR_8&~0x3FFF);

            if(VAR_6 - VAR_8 >  0x2000) VAR_6 -= 0x4000;

            if(VAR_6 - VAR_8 < -0x2000) VAR_6 += 0x4000;

        }

    }

#endif



    VAR_5->pts = VAR_8;

    if (VAR_7 & 2)

        VAR_5->VAR_7 |= AV_PKT_FLAG_KEY;



    return VAR_2->codec->codec_type == AVMEDIA_TYPE_AUDIO ? rm->audio_pkt_cnt : 0;

}

FUNC_0 (AVFormatContext *VAR_0, AVIOContext *VAR_1,
AVStream *VAR_2, RMStream *VAR_3, int VAR_4, AVPacket *VAR_5,
int *VAR_6, int VAR_7, int64_t VAR_8)
{ RMDemuxContext *rm = VAR_0->priv_data; int VAR_9; if (VAR_2->codec->codec_type == AVMEDIA_TYPE_VIDEO) { rm->current_stream= VAR_2->id; VAR_9 = rm_assemble_video_frame(VAR_0, VAR_1, rm, VAR_3, VAR_5, VAR_4, VAR_6, &VAR_8); if(VAR_9)
return VAR_9 < 0 ? VAR_9 : -1; } else if (VAR_2->codec->codec_type == AVMEDIA_TYPE_AUDIO) { if ((VAR_3->deint_id == DEINT_ID_GENR) ||
(VAR_3->deint_id == DEINT_ID_INT4) ||
(VAR_3->deint_id == DEINT_ID_SIPR)) { int VAR_16; int VAR_11 = VAR_3->sub_packet_size; int VAR_12 = VAR_3->coded_framesize; int VAR_13 = VAR_3->sub_packet_h; int VAR_14 = VAR_3->sub_packet_cnt; int VAR_15 = VAR_3->audio_framesize; if (VAR_7 & 2)
VAR_14 = VAR_3->sub_packet_cnt = 0; if (!VAR_14)
VAR_3->audiotimestamp = VAR_8; switch (VAR_3->deint_id) { case DEINT_ID_INT4:
for (VAR_16 = 0; VAR_16 < VAR_13/2; VAR_16++) avio_read(VAR_1, VAR_3->VAR_5.data+VAR_16*2*VAR_15+VAR_14*VAR_12, VAR_12); break; case DEINT_ID_GENR:
for (VAR_16 = 0; VAR_16 < VAR_15/VAR_11; VAR_16++) avio_read(VAR_1, VAR_3->VAR_5.data+VAR_11*(VAR_13*VAR_16+((VAR_13+1)/2)*(VAR_14&1)+(VAR_14>>1)), VAR_11); break; case DEINT_ID_SIPR:
avio_read(VAR_1, VAR_3->VAR_5.data + VAR_14 * VAR_15, VAR_15); break; } if (++(VAR_3->sub_packet_cnt) < VAR_13)
return -1; if (VAR_3->deint_id == DEINT_ID_SIPR)
ff_rm_reorder_sipr_data(VAR_3->VAR_5.data, VAR_13, VAR_15); VAR_3->sub_packet_cnt = 0; rm->audio_stream_num = VAR_2->index; rm->audio_pkt_cnt = VAR_13 * VAR_15 / VAR_2->codec->block_align; } else if ((VAR_3->deint_id == DEINT_ID_VBRF) || (VAR_3->deint_id == DEINT_ID_VBRS)) { int VAR_16; rm->audio_stream_num = VAR_2->index; VAR_3->sub_packet_cnt = (avio_rb16(VAR_1) & 0xf0) >> 4; if (VAR_3->sub_packet_cnt) { for (VAR_16 = 0; VAR_16 < VAR_3->sub_packet_cnt; VAR_16++) VAR_3->sub_packet_lengths[VAR_16] = avio_rb16(VAR_1); rm->audio_pkt_cnt = VAR_3->sub_packet_cnt; VAR_3->audiotimestamp = VAR_8; } else return -1; } else { av_get_packet(VAR_1, VAR_5, VAR_4); rm_ac3_swap_bytes(VAR_2, VAR_5); } } else av_get_packet(VAR_1, VAR_5, VAR_4); VAR_5->stream_index = VAR_2->index; #if 0
if (VAR_2->codec->codec_type == AVMEDIA_TYPE_VIDEO) { if(VAR_2->codec->codec_id == AV_CODEC_ID_RV20){ int VAR_6= 128*(VAR_5->data[2]&0x7F) + (VAR_5->data[3]>>1); av_log(VAR_0, AV_LOG_DEBUG, "%d %"PRId64" %d\n", *VAR_8, *VAR_8*512LL/25, VAR_6); VAR_6 |= (VAR_8&~0x3FFF); if(VAR_6 - VAR_8 >  0x2000) VAR_6 -= 0x4000; if(VAR_6 - VAR_8 < -0x2000) VAR_6 += 0x4000; } } #endif
VAR_5->pts = VAR_8; if (VAR_7 & 2)
VAR_5->VAR_7 |= AV_PKT_FLAG_KEY; return VAR_2->codec->codec_type == AVMEDIA_TYPE_AUDIO ? rm->audio_pkt_cnt : 0; }