static int read_packet(AVFormatContext *s,

                           AVPacket *pkt)

{

    MmDemuxContext *mm = s->priv_data;

    AVIOContext *pb = s->pb;

    unsigned char preamble[MM_PREAMBLE_SIZE];

    unsigned int type, length;



    while(1) {



        if (avio_read(pb, preamble, MM_PREAMBLE_SIZE) != MM_PREAMBLE_SIZE) {

            return AVERROR(EIO);

        }



        type = AV_RL16(&preamble[0]);

        length = AV_RL16(&preamble[2]);



        switch(type) {

        case MM_TYPE_PALETTE :

        case MM_TYPE_INTER :

        case MM_TYPE_INTRA :

        case MM_TYPE_INTRA_HH :

        case MM_TYPE_INTER_HH :

        case MM_TYPE_INTRA_HHV :

        case MM_TYPE_INTER_HHV :

            /* output preamble + data */

            if (av_new_packet(pkt, length + MM_PREAMBLE_SIZE))

                return AVERROR(ENOMEM);

            memcpy(pkt->data, preamble, MM_PREAMBLE_SIZE);

            if (avio_read(pb, pkt->data + MM_PREAMBLE_SIZE, length) != length)

                return AVERROR(EIO);

            pkt->size = length + MM_PREAMBLE_SIZE;

            pkt->stream_index = 0;

            pkt->pts = mm->video_pts;

            if (type!=MM_TYPE_PALETTE)

                mm->video_pts++;

            return 0;



        case MM_TYPE_AUDIO :

            if (av_get_packet(s->pb, pkt, length)<0)

                return AVERROR(ENOMEM);

            pkt->size = length;

            pkt->stream_index = 1;

            pkt->pts = mm->audio_pts++;

            return 0;



        default :

            av_log(s, AV_LOG_INFO, "unknown chunk type 0x%x\n", type);

            avio_skip(pb, length);

        }

    }

}

static int read_packet(AVFormatContext *s,

                           AVPacket *pkt)

{

    MmDemuxContext *mm = s->priv_data;

    AVIOContext *pb = s->pb;

    unsigned char preamble[MM_PREAMBLE_SIZE];

    unsigned int type, length;



    while(1) {



        if (avio_read(pb, preamble, MM_PREAMBLE_SIZE) != MM_PREAMBLE_SIZE) {

            return AVERROR(EIO);

        }



        type = AV_RL16(&preamble[0]);

        length = AV_RL16(&preamble[2]);



        switch(type) {

        case MM_TYPE_PALETTE :

        case MM_TYPE_INTER :

        case MM_TYPE_INTRA :

        case MM_TYPE_INTRA_HH :

        case MM_TYPE_INTER_HH :

        case MM_TYPE_INTRA_HHV :

        case MM_TYPE_INTER_HHV :

            

            if (av_new_packet(pkt, length + MM_PREAMBLE_SIZE))

                return AVERROR(ENOMEM);

            memcpy(pkt->data, preamble, MM_PREAMBLE_SIZE);

            if (avio_read(pb, pkt->data + MM_PREAMBLE_SIZE, length) != length)

                return AVERROR(EIO);

            pkt->size = length + MM_PREAMBLE_SIZE;

            pkt->stream_index = 0;

            pkt->pts = mm->video_pts;

            if (type!=MM_TYPE_PALETTE)

                mm->video_pts++;

            return 0;



        case MM_TYPE_AUDIO :

            if (av_get_packet(s->pb, pkt, length)<0)

                return AVERROR(ENOMEM);

            pkt->size = length;

            pkt->stream_index = 1;

            pkt->pts = mm->audio_pts++;

            return 0;



        default :

            av_log(s, AV_LOG_INFO, "unknown chunk type 0x%x\n", type);

            avio_skip(pb, length);

        }

    }

}

static int FUNC_0(AVFormatContext *VAR_0,

                           AVPacket *VAR_1)

{

    MmDemuxContext *mm = VAR_0->priv_data;

    AVIOContext *pb = VAR_0->pb;

    unsigned char VAR_2[MM_PREAMBLE_SIZE];

    unsigned int VAR_3, VAR_4;



    while(1) {



        if (avio_read(pb, VAR_2, MM_PREAMBLE_SIZE) != MM_PREAMBLE_SIZE) {

            return AVERROR(EIO);

        }



        VAR_3 = AV_RL16(&VAR_2[0]);

        VAR_4 = AV_RL16(&VAR_2[2]);



        switch(VAR_3) {

        case MM_TYPE_PALETTE :

        case MM_TYPE_INTER :

        case MM_TYPE_INTRA :

        case MM_TYPE_INTRA_HH :

        case MM_TYPE_INTER_HH :

        case MM_TYPE_INTRA_HHV :

        case MM_TYPE_INTER_HHV :

            

            if (av_new_packet(VAR_1, VAR_4 + MM_PREAMBLE_SIZE))

                return AVERROR(ENOMEM);

            memcpy(VAR_1->data, VAR_2, MM_PREAMBLE_SIZE);

            if (avio_read(pb, VAR_1->data + MM_PREAMBLE_SIZE, VAR_4) != VAR_4)

                return AVERROR(EIO);

            VAR_1->size = VAR_4 + MM_PREAMBLE_SIZE;

            VAR_1->stream_index = 0;

            VAR_1->pts = mm->video_pts;

            if (VAR_3!=MM_TYPE_PALETTE)

                mm->video_pts++;

            return 0;



        case MM_TYPE_AUDIO :

            if (av_get_packet(VAR_0->pb, VAR_1, VAR_4)<0)

                return AVERROR(ENOMEM);

            VAR_1->size = VAR_4;

            VAR_1->stream_index = 1;

            VAR_1->pts = mm->audio_pts++;

            return 0;



        default :

            av_log(VAR_0, AV_LOG_INFO, "unknown chunk VAR_3 0x%x\n", VAR_3);

            avio_skip(pb, VAR_4);

        }

    }

}

static int FUNC_0(AVFormatContext *VAR_0,
AVPacket *VAR_1)
{ MmDemuxContext *mm = VAR_0->priv_data; AVIOContext *pb = VAR_0->pb; unsigned char VAR_2[MM_PREAMBLE_SIZE]; unsigned int VAR_3, VAR_4; while(1) { if (avio_read(pb, VAR_2, MM_PREAMBLE_SIZE) != MM_PREAMBLE_SIZE) { return AVERROR(EIO); } VAR_3 = AV_RL16(&VAR_2[0]); VAR_4 = AV_RL16(&VAR_2[2]); switch(VAR_3) { case MM_TYPE_PALETTE :
case MM_TYPE_INTER :
case MM_TYPE_INTRA :
case MM_TYPE_INTRA_HH :
case MM_TYPE_INTER_HH :
case MM_TYPE_INTRA_HHV :
case MM_TYPE_INTER_HHV :
if (av_new_packet(VAR_1, VAR_4 + MM_PREAMBLE_SIZE))
return AVERROR(ENOMEM); memcpy(VAR_1->data, VAR_2, MM_PREAMBLE_SIZE); if (avio_read(pb, VAR_1->data + MM_PREAMBLE_SIZE, VAR_4) != VAR_4)
return AVERROR(EIO); VAR_1->size = VAR_4 + MM_PREAMBLE_SIZE; VAR_1->stream_index = 0; VAR_1->pts = mm->video_pts; if (VAR_3!=MM_TYPE_PALETTE)
mm->video_pts++; return 0; case MM_TYPE_AUDIO :
if (av_get_packet(VAR_0->pb, VAR_1, VAR_4)<0)
return AVERROR(ENOMEM); VAR_1->size = VAR_4; VAR_1->stream_index = 1; VAR_1->pts = mm->audio_pts++; return 0; default :
av_log(VAR_0, AV_LOG_INFO, "unknown chunk VAR_3 0x%x\n", VAR_3); avio_skip(pb, VAR_4); } } }