static int smacker_read_packet(AVFormatContext *s, AVPacket *pkt)
{
    SmackerContext *smk = s->priv_data;
    int flags;
    int ret;
    int i;
    int frame_size = 0;
    int palchange = 0;
    int pos;
    if (url_feof(s->pb) || smk->cur_frame >= smk->frames)
        return AVERROR(EIO);
    if(smk->curstream < 0) {
        url_fseek(s->pb, smk->nextpos, 0);
        frame_size = smk->frm_size[smk->cur_frame] & (~3);
        flags = smk->frm_flags[smk->cur_frame];
        pos = url_ftell(s->pb);
        if(flags & SMACKER_PAL){
            int size, sz, t, off, j, pos;
            uint8_t *pal = smk->pal;
            uint8_t oldpal[768];
            memcpy(oldpal, pal, 768);
            size = get_byte(s->pb);
            size = size * 4 - 1;
            frame_size -= size;
            frame_size--;
            sz = 0;
            pos = url_ftell(s->pb) + size;
            while(sz < 256){
                t = get_byte(s->pb);
                if(t & 0x80){
                    sz += (t & 0x7F) + 1;
                    pal += ((t & 0x7F) + 1) * 3;
                } else if(t & 0x40){
                    off = get_byte(s->pb) * 3;
                    j = (t & 0x3F) + 1;
                    while(j-- && sz < 256) {
                        *pal++ = oldpal[off + 0];
                        *pal++ = oldpal[off + 1];
                        *pal++ = oldpal[off + 2];
                        sz++;
                        off += 3;
                    }
                } else {
                    *pal++ = smk_pal[t];
                    *pal++ = smk_pal[get_byte(s->pb) & 0x3F];
                    *pal++ = smk_pal[get_byte(s->pb) & 0x3F];
                    sz++;
                }
            }
            url_fseek(s->pb, pos, 0);
            palchange |= 1;
        }
        flags >>= 1;
        smk->curstream = -1;
        for(i = 0; i < 7; i++) {
            if(flags & 1) {
                int size;
                size = get_le32(s->pb) - 4;
                frame_size -= size;
                frame_size -= 4;
                smk->curstream++;
                smk->bufs[smk->curstream] = av_realloc(smk->bufs[smk->curstream], size);
                smk->buf_sizes[smk->curstream] = size;
                ret = get_buffer(s->pb, smk->bufs[smk->curstream], size);
                if(ret != size)
                    return AVERROR(EIO);
                smk->stream_id[smk->curstream] = smk->indexes[i];
            }
            flags >>= 1;
        }
        if (av_new_packet(pkt, frame_size + 768))
            return AVERROR(ENOMEM);
        if(smk->frm_size[smk->cur_frame] & 1)
            palchange |= 2;
        pkt->data[0] = palchange;
        memcpy(pkt->data + 1, smk->pal, 768);
        ret = get_buffer(s->pb, pkt->data + 769, frame_size);
        if(ret != frame_size)
            return AVERROR(EIO);
        pkt->stream_index = smk->videoindex;
        pkt->size = ret + 769;
        smk->cur_frame++;
        smk->nextpos = url_ftell(s->pb);
    } else {
        if (av_new_packet(pkt, smk->buf_sizes[smk->curstream]))
            return AVERROR(ENOMEM);
        memcpy(pkt->data, smk->bufs[smk->curstream], smk->buf_sizes[smk->curstream]);
        pkt->size = smk->buf_sizes[smk->curstream];
        pkt->stream_index = smk->stream_id[smk->curstream];
        pkt->pts = smk->aud_pts[smk->curstream];
        smk->aud_pts[smk->curstream] += AV_RL32(pkt->data);
        smk->curstream--;
    }
    return 0;
}
['static int smacker_read_packet(AVFormatContext *s, AVPacket *pkt)\n{\n    SmackerContext *smk = s->priv_data;\n    int flags;\n    int ret;\n    int i;\n    int frame_size = 0;\n    int palchange = 0;\n    int pos;\n    if (url_feof(s->pb) || smk->cur_frame >= smk->frames)\n        return AVERROR(EIO);\n    if(smk->curstream < 0) {\n        url_fseek(s->pb, smk->nextpos, 0);\n        frame_size = smk->frm_size[smk->cur_frame] & (~3);\n        flags = smk->frm_flags[smk->cur_frame];\n        pos = url_ftell(s->pb);\n        if(flags & SMACKER_PAL){\n            int size, sz, t, off, j, pos;\n            uint8_t *pal = smk->pal;\n            uint8_t oldpal[768];\n            memcpy(oldpal, pal, 768);\n            size = get_byte(s->pb);\n            size = size * 4 - 1;\n            frame_size -= size;\n            frame_size--;\n            sz = 0;\n            pos = url_ftell(s->pb) + size;\n            while(sz < 256){\n                t = get_byte(s->pb);\n                if(t & 0x80){\n                    sz += (t & 0x7F) + 1;\n                    pal += ((t & 0x7F) + 1) * 3;\n                } else if(t & 0x40){\n                    off = get_byte(s->pb) * 3;\n                    j = (t & 0x3F) + 1;\n                    while(j-- && sz < 256) {\n                        *pal++ = oldpal[off + 0];\n                        *pal++ = oldpal[off + 1];\n                        *pal++ = oldpal[off + 2];\n                        sz++;\n                        off += 3;\n                    }\n                } else {\n                    *pal++ = smk_pal[t];\n                    *pal++ = smk_pal[get_byte(s->pb) & 0x3F];\n                    *pal++ = smk_pal[get_byte(s->pb) & 0x3F];\n                    sz++;\n                }\n            }\n            url_fseek(s->pb, pos, 0);\n            palchange |= 1;\n        }\n        flags >>= 1;\n        smk->curstream = -1;\n        for(i = 0; i < 7; i++) {\n            if(flags & 1) {\n                int size;\n                size = get_le32(s->pb) - 4;\n                frame_size -= size;\n                frame_size -= 4;\n                smk->curstream++;\n                smk->bufs[smk->curstream] = av_realloc(smk->bufs[smk->curstream], size);\n                smk->buf_sizes[smk->curstream] = size;\n                ret = get_buffer(s->pb, smk->bufs[smk->curstream], size);\n                if(ret != size)\n                    return AVERROR(EIO);\n                smk->stream_id[smk->curstream] = smk->indexes[i];\n            }\n            flags >>= 1;\n        }\n        if (av_new_packet(pkt, frame_size + 768))\n            return AVERROR(ENOMEM);\n        if(smk->frm_size[smk->cur_frame] & 1)\n            palchange |= 2;\n        pkt->data[0] = palchange;\n        memcpy(pkt->data + 1, smk->pal, 768);\n        ret = get_buffer(s->pb, pkt->data + 769, frame_size);\n        if(ret != frame_size)\n            return AVERROR(EIO);\n        pkt->stream_index = smk->videoindex;\n        pkt->size = ret + 769;\n        smk->cur_frame++;\n        smk->nextpos = url_ftell(s->pb);\n    } else {\n        if (av_new_packet(pkt, smk->buf_sizes[smk->curstream]))\n            return AVERROR(ENOMEM);\n        memcpy(pkt->data, smk->bufs[smk->curstream], smk->buf_sizes[smk->curstream]);\n        pkt->size = smk->buf_sizes[smk->curstream];\n        pkt->stream_index = smk->stream_id[smk->curstream];\n        pkt->pts = smk->aud_pts[smk->curstream];\n        smk->aud_pts[smk->curstream] += AV_RL32(pkt->data);\n        smk->curstream--;\n    }\n    return 0;\n}']