ff_rm_parse_packet (AVFormatContext *s, ByteIOContext *pb,

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

                    int *seq, int *flags, int64_t *timestamp)

{

    RMDemuxContext *rm = s->priv_data;



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

        rm->current_stream= st->id;

        if(rm_assemble_video_frame(s, pb, rm, ast, pkt, len))

            return -1; //got partial frame

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

        if ((st->codec->codec_id == CODEC_ID_RA_288) ||

            (st->codec->codec_id == CODEC_ID_COOK) ||

            (st->codec->codec_id == CODEC_ID_ATRAC3) ||

            (st->codec->codec_id == CODEC_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(st->codec->codec_id) {

                case CODEC_ID_RA_288:

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

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

                    break;

                case CODEC_ID_ATRAC3:

                case CODEC_ID_COOK:

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

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

                    break;

            }



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

                return -1;

            else {

                ast->sub_packet_cnt = 0;

                rm->audio_stream_num = st->index;

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

                // Release first audio packet

                av_new_packet(pkt, st->codec->block_align);

                memcpy(pkt->data, ast->pkt.data, st->codec->block_align); //FIXME avoid this

                *timestamp = ast->audiotimestamp;

                *flags = 2; // Mark first packet as keyframe

            }

        } else if (st->codec->codec_id == CODEC_ID_AAC) {

            int x;

            rm->audio_stream_num = st->index;

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

            if (ast->sub_packet_cnt) {

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

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

                // Release first audio packet

                rm->audio_pkt_cnt = ast->sub_packet_cnt - 1;

                av_get_packet(pb, pkt, ast->sub_packet_lengths[0]);

                *flags = 2; // Mark first packet as keyframe

            }

        } else {

            av_get_packet(pb, pkt, len);

            rm_ac3_swap_bytes(st, pkt);

        }

    } else

        av_get_packet(pb, pkt, len);



    if(  (st->discard >= AVDISCARD_NONKEY && !(*flags&2))

       || st->discard >= AVDISCARD_ALL){

        av_free_packet(pkt);

        return -1;

    }



    pkt->stream_index = st->index;



#if 0

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

        if(st->codec->codec_id == 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 |= PKT_FLAG_KEY;



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

}

ff_rm_parse_packet (AVFormatContext *s, ByteIOContext *pb,

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

                    int *seq, int *flags, int64_t *timestamp)

{

    RMDemuxContext *rm = s->priv_data;



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

        rm->current_stream= st->id;

        if(rm_assemble_video_frame(s, pb, rm, ast, pkt, len))

            return -1; 

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

        if ((st->codec->codec_id == CODEC_ID_RA_288) ||

            (st->codec->codec_id == CODEC_ID_COOK) ||

            (st->codec->codec_id == CODEC_ID_ATRAC3) ||

            (st->codec->codec_id == CODEC_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(st->codec->codec_id) {

                case CODEC_ID_RA_288:

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

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

                    break;

                case CODEC_ID_ATRAC3:

                case CODEC_ID_COOK:

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

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

                    break;

            }



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

                return -1;

            else {

                ast->sub_packet_cnt = 0;

                rm->audio_stream_num = st->index;

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

                

                av_new_packet(pkt, st->codec->block_align);

                memcpy(pkt->data, ast->pkt.data, st->codec->block_align); 

                *timestamp = ast->audiotimestamp;

                *flags = 2; 

            }

        } else if (st->codec->codec_id == CODEC_ID_AAC) {

            int x;

            rm->audio_stream_num = st->index;

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

            if (ast->sub_packet_cnt) {

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

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

                

                rm->audio_pkt_cnt = ast->sub_packet_cnt - 1;

                av_get_packet(pb, pkt, ast->sub_packet_lengths[0]);

                *flags = 2; 

            }

        } else {

            av_get_packet(pb, pkt, len);

            rm_ac3_swap_bytes(st, pkt);

        }

    } else

        av_get_packet(pb, pkt, len);



    if(  (st->discard >= AVDISCARD_NONKEY && !(*flags&2))

       || st->discard >= AVDISCARD_ALL){

        av_free_packet(pkt);

        return -1;

    }



    pkt->stream_index = st->index;



#if 0

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

        if(st->codec->codec_id == 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 |= PKT_FLAG_KEY;



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

}

FUNC_0 (AVFormatContext *VAR_0, ByteIOContext *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;



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

        rm->current_stream= VAR_2->id;

        if(rm_assemble_video_frame(VAR_0, VAR_1, rm, VAR_3, VAR_5, VAR_4))

            return -1; 

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

        if ((VAR_2->codec->codec_id == CODEC_ID_RA_288) ||

            (VAR_2->codec->codec_id == CODEC_ID_COOK) ||

            (VAR_2->codec->codec_id == CODEC_ID_ATRAC3) ||

            (VAR_2->codec->codec_id == CODEC_ID_SIPR)) {

            int VAR_15;

            int VAR_10 = VAR_3->sub_packet_size;

            int VAR_11 = VAR_3->coded_framesize;

            int VAR_12 = VAR_3->sub_packet_h;

            int VAR_13 = VAR_3->sub_packet_cnt;

            int VAR_14 = VAR_3->audio_framesize;



            if (*VAR_7 & 2)

                VAR_13 = VAR_3->sub_packet_cnt = 0;

            if (!VAR_13)

                VAR_3->audiotimestamp = *VAR_8;



            switch(VAR_2->codec->codec_id) {

                case CODEC_ID_RA_288:

                    for (VAR_15 = 0; VAR_15 < VAR_12/2; VAR_15++)

                        get_buffer(VAR_1, VAR_3->VAR_5.data+VAR_15*2*VAR_14+VAR_13*VAR_11, VAR_11);

                    break;

                case CODEC_ID_ATRAC3:

                case CODEC_ID_COOK:

                    for (VAR_15 = 0; VAR_15 < VAR_14/VAR_10; VAR_15++)

                        get_buffer(VAR_1, VAR_3->VAR_5.data+VAR_10*(VAR_12*VAR_15+((VAR_12+1)/2)*(VAR_13&1)+(VAR_13>>1)), VAR_10);

                    break;

            }



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

                return -1;

            else {

                VAR_3->sub_packet_cnt = 0;

                rm->audio_stream_num = VAR_2->index;

                rm->audio_pkt_cnt = VAR_12 * VAR_14 / VAR_2->codec->block_align - 1;

                

                av_new_packet(VAR_5, VAR_2->codec->block_align);

                memcpy(VAR_5->data, VAR_3->VAR_5.data, VAR_2->codec->block_align); 

                *VAR_8 = VAR_3->audiotimestamp;

                *VAR_7 = 2; 

            }

        } else if (VAR_2->codec->codec_id == CODEC_ID_AAC) {

            int VAR_15;

            rm->audio_stream_num = VAR_2->index;

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

            if (VAR_3->sub_packet_cnt) {

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

                    VAR_3->sub_packet_lengths[VAR_15] = get_be16(VAR_1);

                

                rm->audio_pkt_cnt = VAR_3->sub_packet_cnt - 1;

                av_get_packet(VAR_1, VAR_5, VAR_3->sub_packet_lengths[0]);

                *VAR_7 = 2; 

            }

        } 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);



    if(  (VAR_2->discard >= AVDISCARD_NONKEY && !(*VAR_7&2))

       || VAR_2->discard >= AVDISCARD_ALL){

        av_free_packet(VAR_5);

        return -1;

    }



    VAR_5->stream_index = VAR_2->index;



#if 0

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

        if(VAR_2->codec->codec_id == 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 |= PKT_FLAG_KEY;



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

}

FUNC_0 (AVFormatContext *VAR_0, ByteIOContext *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; if (VAR_2->codec->codec_type == CODEC_TYPE_VIDEO) { rm->current_stream= VAR_2->id; if(rm_assemble_video_frame(VAR_0, VAR_1, rm, VAR_3, VAR_5, VAR_4))
return -1; } else if (VAR_2->codec->codec_type == CODEC_TYPE_AUDIO) { if ((VAR_2->codec->codec_id == CODEC_ID_RA_288) ||
(VAR_2->codec->codec_id == CODEC_ID_COOK) ||
(VAR_2->codec->codec_id == CODEC_ID_ATRAC3) ||
(VAR_2->codec->codec_id == CODEC_ID_SIPR)) { int VAR_15; int VAR_10 = VAR_3->sub_packet_size; int VAR_11 = VAR_3->coded_framesize; int VAR_12 = VAR_3->sub_packet_h; int VAR_13 = VAR_3->sub_packet_cnt; int VAR_14 = VAR_3->audio_framesize; if (*VAR_7 & 2)
VAR_13 = VAR_3->sub_packet_cnt = 0; if (!VAR_13)
VAR_3->audiotimestamp = *VAR_8; switch(VAR_2->codec->codec_id) { case CODEC_ID_RA_288:
for (VAR_15 = 0; VAR_15 < VAR_12/2; VAR_15++) get_buffer(VAR_1, VAR_3->VAR_5.data+VAR_15*2*VAR_14+VAR_13*VAR_11, VAR_11); break; case CODEC_ID_ATRAC3:
case CODEC_ID_COOK:
for (VAR_15 = 0; VAR_15 < VAR_14/VAR_10; VAR_15++) get_buffer(VAR_1, VAR_3->VAR_5.data+VAR_10*(VAR_12*VAR_15+((VAR_12+1)/2)*(VAR_13&1)+(VAR_13>>1)), VAR_10); break; } if (++(VAR_3->sub_packet_cnt) < VAR_12)
return -1; else { VAR_3->sub_packet_cnt = 0; rm->audio_stream_num = VAR_2->index; rm->audio_pkt_cnt = VAR_12 * VAR_14 / VAR_2->codec->block_align - 1; av_new_packet(VAR_5, VAR_2->codec->block_align); memcpy(VAR_5->data, VAR_3->VAR_5.data, VAR_2->codec->block_align); *VAR_8 = VAR_3->audiotimestamp; *VAR_7 = 2; } } else if (VAR_2->codec->codec_id == CODEC_ID_AAC) { int VAR_15; rm->audio_stream_num = VAR_2->index; VAR_3->sub_packet_cnt = (get_be16(VAR_1) & 0xf0) >> 4; if (VAR_3->sub_packet_cnt) { for (VAR_15 = 0; VAR_15 < VAR_3->sub_packet_cnt; VAR_15++) VAR_3->sub_packet_lengths[VAR_15] = get_be16(VAR_1); rm->audio_pkt_cnt = VAR_3->sub_packet_cnt - 1; av_get_packet(VAR_1, VAR_5, VAR_3->sub_packet_lengths[0]); *VAR_7 = 2; } } 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); if(  (VAR_2->discard >= AVDISCARD_NONKEY && !(*VAR_7&2))
|| VAR_2->discard >= AVDISCARD_ALL){ av_free_packet(VAR_5); return -1; } VAR_5->stream_index = VAR_2->index; #if 0
if (VAR_2->codec->codec_type == CODEC_TYPE_VIDEO) { if(VAR_2->codec->codec_id == 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 |= PKT_FLAG_KEY; return VAR_2->codec->codec_type == CODEC_TYPE_AUDIO ? rm->audio_pkt_cnt : 0; }