static int dxa_read_packet(AVFormatContext *s, AVPacket *pkt)

{

    DXAContext *c = s->priv_data;

    int ret;

    uint32_t size;

    uint8_t buf[DXA_EXTRA_SIZE], pal[768+4];

    int pal_size = 0;



    if(!c->readvid && c->has_sound && c->bytes_left){

        c->readvid = 1;

        avio_seek(s->pb, c->wavpos, SEEK_SET);

        size = FFMIN(c->bytes_left, c->bpc);

        ret = av_get_packet(s->pb, pkt, size);

        pkt->stream_index = 1;

        if(ret != size)

            return AVERROR(EIO);

        c->bytes_left -= size;

        c->wavpos = avio_tell(s->pb);

        return 0;

    }

    avio_seek(s->pb, c->vidpos, SEEK_SET);

    while(!url_feof(s->pb) && c->frames){

        avio_read(s->pb, buf, 4);

        switch(AV_RL32(buf)){

        case MKTAG('N', 'U', 'L', 'L'):

            if(av_new_packet(pkt, 4 + pal_size) < 0)

                return AVERROR(ENOMEM);

            pkt->stream_index = 0;

            if(pal_size) memcpy(pkt->data, pal, pal_size);

            memcpy(pkt->data + pal_size, buf, 4);

            c->frames--;

            c->vidpos = avio_tell(s->pb);

            c->readvid = 0;

            return 0;

        case MKTAG('C', 'M', 'A', 'P'):

            pal_size = 768+4;

            memcpy(pal, buf, 4);

            avio_read(s->pb, pal + 4, 768);

            break;

        case MKTAG('F', 'R', 'A', 'M'):

            avio_read(s->pb, buf + 4, DXA_EXTRA_SIZE - 4);

            size = AV_RB32(buf + 5);

            if(size > 0xFFFFFF){

                av_log(s, AV_LOG_ERROR, "Frame size is too big: %d\n", size);

                return AVERROR_INVALIDDATA;

            }

            if(av_new_packet(pkt, size + DXA_EXTRA_SIZE + pal_size) < 0)

                return AVERROR(ENOMEM);

            memcpy(pkt->data + pal_size, buf, DXA_EXTRA_SIZE);

            ret = avio_read(s->pb, pkt->data + DXA_EXTRA_SIZE + pal_size, size);

            if(ret != size){

                av_free_packet(pkt);

                return AVERROR(EIO);

            }

            if(pal_size) memcpy(pkt->data, pal, pal_size);

            pkt->stream_index = 0;

            c->frames--;

            c->vidpos = avio_tell(s->pb);

            c->readvid = 0;

            return 0;

        default:

            av_log(s, AV_LOG_ERROR, "Unknown tag %c%c%c%c\n", buf[0], buf[1], buf[2], buf[3]);

            return AVERROR_INVALIDDATA;

        }

    }

    return AVERROR_EOF;

}

static int dxa_read_packet(AVFormatContext *s, AVPacket *pkt)

{

    DXAContext *c = s->priv_data;

    int ret;

    uint32_t size;

    uint8_t buf[DXA_EXTRA_SIZE], pal[768+4];

    int pal_size = 0;



    if(!c->readvid && c->has_sound && c->bytes_left){

        c->readvid = 1;

        avio_seek(s->pb, c->wavpos, SEEK_SET);

        size = FFMIN(c->bytes_left, c->bpc);

        ret = av_get_packet(s->pb, pkt, size);

        pkt->stream_index = 1;

        if(ret != size)

            return AVERROR(EIO);

        c->bytes_left -= size;

        c->wavpos = avio_tell(s->pb);

        return 0;

    }

    avio_seek(s->pb, c->vidpos, SEEK_SET);

    while(!url_feof(s->pb) && c->frames){

        avio_read(s->pb, buf, 4);

        switch(AV_RL32(buf)){

        case MKTAG('N', 'U', 'L', 'L'):

            if(av_new_packet(pkt, 4 + pal_size) < 0)

                return AVERROR(ENOMEM);

            pkt->stream_index = 0;

            if(pal_size) memcpy(pkt->data, pal, pal_size);

            memcpy(pkt->data + pal_size, buf, 4);

            c->frames--;

            c->vidpos = avio_tell(s->pb);

            c->readvid = 0;

            return 0;

        case MKTAG('C', 'M', 'A', 'P'):

            pal_size = 768+4;

            memcpy(pal, buf, 4);

            avio_read(s->pb, pal + 4, 768);

            break;

        case MKTAG('F', 'R', 'A', 'M'):

            avio_read(s->pb, buf + 4, DXA_EXTRA_SIZE - 4);

            size = AV_RB32(buf + 5);

            if(size > 0xFFFFFF){

                av_log(s, AV_LOG_ERROR, "Frame size is too big: %d\n", size);

                return AVERROR_INVALIDDATA;

            }

            if(av_new_packet(pkt, size + DXA_EXTRA_SIZE + pal_size) < 0)

                return AVERROR(ENOMEM);

            memcpy(pkt->data + pal_size, buf, DXA_EXTRA_SIZE);

            ret = avio_read(s->pb, pkt->data + DXA_EXTRA_SIZE + pal_size, size);

            if(ret != size){

                av_free_packet(pkt);

                return AVERROR(EIO);

            }

            if(pal_size) memcpy(pkt->data, pal, pal_size);

            pkt->stream_index = 0;

            c->frames--;

            c->vidpos = avio_tell(s->pb);

            c->readvid = 0;

            return 0;

        default:

            av_log(s, AV_LOG_ERROR, "Unknown tag %c%c%c%c\n", buf[0], buf[1], buf[2], buf[3]);

            return AVERROR_INVALIDDATA;

        }

    }

    return AVERROR_EOF;

}

        avio_read(s->pb, buf, 4);             avio_read(s->pb, buf + 4, DXA_EXTRA_SIZE - 4);
static int FUNC_0(AVFormatContext *VAR_0, AVPacket *VAR_1)

{

    DXAContext *c = VAR_0->priv_data;

    int VAR_2;

    uint32_t size;

    uint8_t buf[DXA_EXTRA_SIZE], pal[768+4];

    int VAR_3 = 0;



    if(!c->readvid && c->has_sound && c->bytes_left){

        c->readvid = 1;

        avio_seek(VAR_0->pb, c->wavpos, SEEK_SET);

        size = FFMIN(c->bytes_left, c->bpc);

        VAR_2 = av_get_packet(VAR_0->pb, VAR_1, size);

        VAR_1->stream_index = 1;

        if(VAR_2 != size)

            return AVERROR(EIO);

        c->bytes_left -= size;

        c->wavpos = avio_tell(VAR_0->pb);

        return 0;

    }

    avio_seek(VAR_0->pb, c->vidpos, SEEK_SET);

    while(!url_feof(VAR_0->pb) && c->frames){

        avio_read(VAR_0->pb, buf, 4);

        switch(AV_RL32(buf)){

        case MKTAG('N', 'U', 'L', 'L'):

            if(av_new_packet(VAR_1, 4 + VAR_3) < 0)

                return AVERROR(ENOMEM);

            VAR_1->stream_index = 0;

            if(VAR_3) memcpy(VAR_1->data, pal, VAR_3);

            memcpy(VAR_1->data + VAR_3, buf, 4);

            c->frames--;

            c->vidpos = avio_tell(VAR_0->pb);

            c->readvid = 0;

            return 0;

        case MKTAG('C', 'M', 'A', 'P'):

            VAR_3 = 768+4;

            memcpy(pal, buf, 4);

            avio_read(VAR_0->pb, pal + 4, 768);

            break;

        case MKTAG('F', 'R', 'A', 'M'):

            avio_read(VAR_0->pb, buf + 4, DXA_EXTRA_SIZE - 4);

            size = AV_RB32(buf + 5);

            if(size > 0xFFFFFF){

                av_log(VAR_0, AV_LOG_ERROR, "Frame size is too big: %d\n", size);

                return AVERROR_INVALIDDATA;

            }

            if(av_new_packet(VAR_1, size + DXA_EXTRA_SIZE + VAR_3) < 0)

                return AVERROR(ENOMEM);

            memcpy(VAR_1->data + VAR_3, buf, DXA_EXTRA_SIZE);

            VAR_2 = avio_read(VAR_0->pb, VAR_1->data + DXA_EXTRA_SIZE + VAR_3, size);

            if(VAR_2 != size){

                av_free_packet(VAR_1);

                return AVERROR(EIO);

            }

            if(VAR_3) memcpy(VAR_1->data, pal, VAR_3);

            VAR_1->stream_index = 0;

            c->frames--;

            c->vidpos = avio_tell(VAR_0->pb);

            c->readvid = 0;

            return 0;

        default:

            av_log(VAR_0, AV_LOG_ERROR, "Unknown tag %c%c%c%c\n", buf[0], buf[1], buf[2], buf[3]);

            return AVERROR_INVALIDDATA;

        }

    }

    return AVERROR_EOF;

}

static int FUNC_0(AVFormatContext *VAR_0, AVPacket *VAR_1)
{ DXAContext *c = VAR_0->priv_data; int VAR_2; uint32_t size; uint8_t buf[DXA_EXTRA_SIZE], pal[768+4]; int VAR_3 = 0; if(!c->readvid && c->has_sound && c->bytes_left){ c->readvid = 1; avio_seek(VAR_0->pb, c->wavpos, SEEK_SET); size = FFMIN(c->bytes_left, c->bpc); VAR_2 = av_get_packet(VAR_0->pb, VAR_1, size); VAR_1->stream_index = 1; if(VAR_2 != size)
return AVERROR(EIO); c->bytes_left -= size; c->wavpos = avio_tell(VAR_0->pb); return 0; } avio_seek(VAR_0->pb, c->vidpos, SEEK_SET); while(!url_feof(VAR_0->pb) && c->frames){ avio_read(VAR_0->pb, buf, 4); switch(AV_RL32(buf)){ case MKTAG('N', 'U', 'L', 'L'):
if(av_new_packet(VAR_1, 4 + VAR_3) < 0)
return AVERROR(ENOMEM); VAR_1->stream_index = 0; if(VAR_3) memcpy(VAR_1->data, pal, VAR_3); memcpy(VAR_1->data + VAR_3, buf, 4); c->frames--; c->vidpos = avio_tell(VAR_0->pb); c->readvid = 0; return 0; case MKTAG('C', 'M', 'A', 'P'):
VAR_3 = 768+4; memcpy(pal, buf, 4); avio_read(VAR_0->pb, pal + 4, 768); break; case MKTAG('F', 'R', 'A', 'M'):
avio_read(VAR_0->pb, buf + 4, DXA_EXTRA_SIZE - 4); size = AV_RB32(buf + 5); if(size > 0xFFFFFF){ av_log(VAR_0, AV_LOG_ERROR, "Frame size is too big: %d\n", size); return AVERROR_INVALIDDATA; } if(av_new_packet(VAR_1, size + DXA_EXTRA_SIZE + VAR_3) < 0)
return AVERROR(ENOMEM); memcpy(VAR_1->data + VAR_3, buf, DXA_EXTRA_SIZE); VAR_2 = avio_read(VAR_0->pb, VAR_1->data + DXA_EXTRA_SIZE + VAR_3, size); if(VAR_2 != size){ av_free_packet(VAR_1); return AVERROR(EIO); } if(VAR_3) memcpy(VAR_1->data, pal, VAR_3); VAR_1->stream_index = 0; c->frames--; c->vidpos = avio_tell(VAR_0->pb); c->readvid = 0; return 0; default:
av_log(VAR_0, AV_LOG_ERROR, "Unknown tag %c%c%c%c\n", buf[0], buf[1], buf[2], buf[3]); return AVERROR_INVALIDDATA; } } return AVERROR_EOF; }