static int matroska_parse_rm_audio(MatroskaDemuxContext *matroska,

                                   MatroskaTrack *track,

                                   AVStream *st,

                                   uint8_t *data, int size,

                                   uint64_t timecode,

                                   int64_t pos)

{

    int a = st->codec->block_align;

    int sps = track->audio.sub_packet_size;

    int cfs = track->audio.coded_framesize;

    int h = track->audio.sub_packet_h;

    int y = track->audio.sub_packet_cnt;

    int w = track->audio.frame_size;

    int x;



    if (!track->audio.pkt_cnt) {

        if (track->audio.sub_packet_cnt == 0)

            track->audio.buf_timecode = timecode;

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

            if (size < cfs * h / 2) {

                av_log(matroska->ctx, AV_LOG_ERROR,

                       "Corrupt int4 RM-style audio packet size\n");

                return AVERROR_INVALIDDATA;

            }

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

                memcpy(track->audio.buf+x*2*w+y*cfs,

                       data+x*cfs, cfs);

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

            if (size < w) {

                av_log(matroska->ctx, AV_LOG_ERROR,

                       "Corrupt sipr RM-style audio packet size\n");

                return AVERROR_INVALIDDATA;

            }

            memcpy(track->audio.buf + y*w, data, w);

        } else {

            if (size < sps * w / sps) {

                av_log(matroska->ctx, AV_LOG_ERROR,

                       "Corrupt generic RM-style audio packet size\n");

                return AVERROR_INVALIDDATA;

            }

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

                memcpy(track->audio.buf+sps*(h*x+((h+1)/2)*(y&1)+(y>>1)), data+x*sps, sps);

        }



        if (++track->audio.sub_packet_cnt >= h) {

            if (st->codec->codec_id == AV_CODEC_ID_SIPR)

                ff_rm_reorder_sipr_data(track->audio.buf, h, w);

            track->audio.sub_packet_cnt = 0;

            track->audio.pkt_cnt = h*w / a;

        }

    }



    while (track->audio.pkt_cnt) {

        AVPacket *pkt = NULL;

        if (!(pkt = av_mallocz(sizeof(AVPacket))) || av_new_packet(pkt, a) < 0){

            av_free(pkt);

            return AVERROR(ENOMEM);

        }

        memcpy(pkt->data, track->audio.buf

               + a * (h*w / a - track->audio.pkt_cnt--), a);

        pkt->pts = track->audio.buf_timecode;

        track->audio.buf_timecode = AV_NOPTS_VALUE;

        pkt->pos = pos;

        pkt->stream_index = st->index;

        dynarray_add(&matroska->packets,&matroska->num_packets,pkt);

    }



    return 0;

}

static int matroska_parse_rm_audio(MatroskaDemuxContext *matroska,

                                   MatroskaTrack *track,

                                   AVStream *st,

                                   uint8_t *data, int size,

                                   uint64_t timecode,

                                   int64_t pos)

{

    int a = st->codec->block_align;

    int sps = track->audio.sub_packet_size;

    int cfs = track->audio.coded_framesize;

    int h = track->audio.sub_packet_h;

    int y = track->audio.sub_packet_cnt;

    int w = track->audio.frame_size;

    int x;



    if (!track->audio.pkt_cnt) {

        if (track->audio.sub_packet_cnt == 0)

            track->audio.buf_timecode = timecode;

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

            if (size < cfs * h / 2) {

                av_log(matroska->ctx, AV_LOG_ERROR,

                       "Corrupt int4 RM-style audio packet size\n");

                return AVERROR_INVALIDDATA;

            }

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

                memcpy(track->audio.buf+x*2*w+y*cfs,

                       data+x*cfs, cfs);

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

            if (size < w) {

                av_log(matroska->ctx, AV_LOG_ERROR,

                       "Corrupt sipr RM-style audio packet size\n");

                return AVERROR_INVALIDDATA;

            }

            memcpy(track->audio.buf + y*w, data, w);

        } else {

            if (size < sps * w / sps) {

                av_log(matroska->ctx, AV_LOG_ERROR,

                       "Corrupt generic RM-style audio packet size\n");

                return AVERROR_INVALIDDATA;

            }

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

                memcpy(track->audio.buf+sps*(h*x+((h+1)/2)*(y&1)+(y>>1)), data+x*sps, sps);

        }



        if (++track->audio.sub_packet_cnt >= h) {

            if (st->codec->codec_id == AV_CODEC_ID_SIPR)

                ff_rm_reorder_sipr_data(track->audio.buf, h, w);

            track->audio.sub_packet_cnt = 0;

            track->audio.pkt_cnt = h*w / a;

        }

    }



    while (track->audio.pkt_cnt) {

        AVPacket *pkt = NULL;

        if (!(pkt = av_mallocz(sizeof(AVPacket))) || av_new_packet(pkt, a) < 0){

            av_free(pkt);

            return AVERROR(ENOMEM);

        }

        memcpy(pkt->data, track->audio.buf

               + a * (h*w / a - track->audio.pkt_cnt--), a);

        pkt->pts = track->audio.buf_timecode;

        track->audio.buf_timecode = AV_NOPTS_VALUE;

        pkt->pos = pos;

        pkt->stream_index = st->index;

        dynarray_add(&matroska->packets,&matroska->num_packets,pkt);

    }



    return 0;

}

            if (size < sps * w / sps) {
static int FUNC_0(MatroskaDemuxContext *VAR_0,

                                   MatroskaTrack *VAR_1,

                                   AVStream *VAR_2,

                                   uint8_t *VAR_3, int VAR_4,

                                   uint64_t VAR_5,

                                   int64_t VAR_6)

{

    int VAR_7 = VAR_2->codec->block_align;

    int VAR_8 = VAR_1->audio.sub_packet_size;

    int VAR_9 = VAR_1->audio.coded_framesize;

    int VAR_10 = VAR_1->audio.sub_packet_h;

    int VAR_11 = VAR_1->audio.sub_packet_cnt;

    int VAR_12 = VAR_1->audio.frame_size;

    int VAR_13;



    if (!VAR_1->audio.pkt_cnt) {

        if (VAR_1->audio.sub_packet_cnt == 0)

            VAR_1->audio.buf_timecode = VAR_5;

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

            if (VAR_4 < VAR_9 * VAR_10 / 2) {

                av_log(VAR_0->ctx, AV_LOG_ERROR,

                       "Corrupt int4 RM-style audio packet VAR_4\n");

                return AVERROR_INVALIDDATA;

            }

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

                memcpy(VAR_1->audio.buf+VAR_13*2*VAR_12+VAR_11*VAR_9,

                       VAR_3+VAR_13*VAR_9, VAR_9);

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

            if (VAR_4 < VAR_12) {

                av_log(VAR_0->ctx, AV_LOG_ERROR,

                       "Corrupt sipr RM-style audio packet VAR_4\n");

                return AVERROR_INVALIDDATA;

            }

            memcpy(VAR_1->audio.buf + VAR_11*VAR_12, VAR_3, VAR_12);

        } else {

            if (VAR_4 < VAR_8 * VAR_12 / VAR_8) {

                av_log(VAR_0->ctx, AV_LOG_ERROR,

                       "Corrupt generic RM-style audio packet VAR_4\n");

                return AVERROR_INVALIDDATA;

            }

            for (VAR_13=0; VAR_13<VAR_12/VAR_8; VAR_13++)

                memcpy(VAR_1->audio.buf+VAR_8*(VAR_10*VAR_13+((VAR_10+1)/2)*(VAR_11&1)+(VAR_11>>1)), VAR_3+VAR_13*VAR_8, VAR_8);

        }



        if (++VAR_1->audio.sub_packet_cnt >= VAR_10) {

            if (VAR_2->codec->codec_id == AV_CODEC_ID_SIPR)

                ff_rm_reorder_sipr_data(VAR_1->audio.buf, VAR_10, VAR_12);

            VAR_1->audio.sub_packet_cnt = 0;

            VAR_1->audio.pkt_cnt = VAR_10*VAR_12 / VAR_7;

        }

    }



    while (VAR_1->audio.pkt_cnt) {

        AVPacket *pkt = NULL;

        if (!(pkt = av_mallocz(sizeof(AVPacket))) || av_new_packet(pkt, VAR_7) < 0){

            av_free(pkt);

            return AVERROR(ENOMEM);

        }

        memcpy(pkt->VAR_3, VAR_1->audio.buf

               + VAR_7 * (VAR_10*VAR_12 / VAR_7 - VAR_1->audio.pkt_cnt--), VAR_7);

        pkt->pts = VAR_1->audio.buf_timecode;

        VAR_1->audio.buf_timecode = AV_NOPTS_VALUE;

        pkt->VAR_6 = VAR_6;

        pkt->stream_index = VAR_2->index;

        dynarray_add(&VAR_0->packets,&VAR_0->num_packets,pkt);

    }



    return 0;

}

static int FUNC_0(MatroskaDemuxContext *VAR_0,
MatroskaTrack *VAR_1,
AVStream *VAR_2,
uint8_t *VAR_3, int VAR_4,
uint64_t VAR_5,
int64_t VAR_6)
{ int VAR_7 = VAR_2->codec->block_align; int VAR_8 = VAR_1->audio.sub_packet_size; int VAR_9 = VAR_1->audio.coded_framesize; int VAR_10 = VAR_1->audio.sub_packet_h; int VAR_11 = VAR_1->audio.sub_packet_cnt; int VAR_12 = VAR_1->audio.frame_size; int VAR_13; if (!VAR_1->audio.pkt_cnt) { if (VAR_1->audio.sub_packet_cnt == 0)
VAR_1->audio.buf_timecode = VAR_5; if (VAR_2->codec->codec_id == AV_CODEC_ID_RA_288) { if (VAR_4 < VAR_9 * VAR_10 / 2) { av_log(VAR_0->ctx, AV_LOG_ERROR,
"Corrupt int4 RM-style audio packet VAR_4\n"); return AVERROR_INVALIDDATA; } for (VAR_13=0; VAR_13<VAR_10/2; VAR_13++) memcpy(VAR_1->audio.buf+VAR_13*2*VAR_12+VAR_11*VAR_9,
VAR_3+VAR_13*VAR_9, VAR_9); } else if (VAR_2->codec->codec_id == AV_CODEC_ID_SIPR) { if (VAR_4 < VAR_12) { av_log(VAR_0->ctx, AV_LOG_ERROR,
"Corrupt sipr RM-style audio packet VAR_4\n"); return AVERROR_INVALIDDATA; } memcpy(VAR_1->audio.buf + VAR_11*VAR_12, VAR_3, VAR_12); } else { if (VAR_4 < VAR_8 * VAR_12 / VAR_8) { av_log(VAR_0->ctx, AV_LOG_ERROR,
"Corrupt generic RM-style audio packet VAR_4\n"); return AVERROR_INVALIDDATA; } for (VAR_13=0; VAR_13<VAR_12/VAR_8; VAR_13++) memcpy(VAR_1->audio.buf+VAR_8*(VAR_10*VAR_13+((VAR_10+1)/2)*(VAR_11&1)+(VAR_11>>1)), VAR_3+VAR_13*VAR_8, VAR_8); } if (++VAR_1->audio.sub_packet_cnt >= VAR_10) { if (VAR_2->codec->codec_id == AV_CODEC_ID_SIPR)
ff_rm_reorder_sipr_data(VAR_1->audio.buf, VAR_10, VAR_12); VAR_1->audio.sub_packet_cnt = 0; VAR_1->audio.pkt_cnt = VAR_10*VAR_12 / VAR_7; } } while (VAR_1->audio.pkt_cnt) { AVPacket *pkt = NULL; if (!(pkt = av_mallocz(sizeof(AVPacket))) || av_new_packet(pkt, VAR_7) < 0){ av_free(pkt); return AVERROR(ENOMEM); } memcpy(pkt->VAR_3, VAR_1->audio.buf
+ VAR_7 * (VAR_10*VAR_12 / VAR_7 - VAR_1->audio.pkt_cnt--), VAR_7); pkt->pts = VAR_1->audio.buf_timecode; VAR_1->audio.buf_timecode = AV_NOPTS_VALUE; pkt->VAR_6 = VAR_6; pkt->stream_index = VAR_2->index; dynarray_add(&VAR_0->packets,&VAR_0->num_packets,pkt); } return 0; }