static int decode_frame(NUTContext *nut, AVPacket *pkt, int frame_code)
{
    AVFormatContext *s = nut->avf;
    AVIOContext *bc    = s->pb;
    int size, stream_id, discard;
    int64_t pts, last_IP_pts;
    StreamContext *stc;
    uint8_t header_idx;
    size = decode_frame_header(nut, &pts, &stream_id, &header_idx, frame_code);
    if (size < 0)
        return size;
    stc = &nut->stream[stream_id];
    if (stc->last_flags & FLAG_KEY)
        stc->skip_until_key_frame = 0;
    discard     = s->streams[stream_id]->discard;
    last_IP_pts = s->streams[stream_id]->last_IP_pts;
    if ((discard >= AVDISCARD_NONKEY && !(stc->last_flags & FLAG_KEY)) ||
        (discard >= AVDISCARD_BIDIR  && last_IP_pts != AV_NOPTS_VALUE &&
         last_IP_pts > pts) ||
        discard >= AVDISCARD_ALL ||
        stc->skip_until_key_frame) {
        avio_skip(bc, size);
        return 1;
    }
    av_new_packet(pkt, size + nut->header_len[header_idx]);
    memcpy(pkt->data, nut->header[header_idx], nut->header_len[header_idx]);
    pkt->pos = avio_tell(bc);
    avio_read(bc, pkt->data + nut->header_len[header_idx], size);
    pkt->stream_index = stream_id;
    if (stc->last_flags & FLAG_KEY)
        pkt->flags |= AV_PKT_FLAG_KEY;
    pkt->pts = pts;
    return 0;
}
['static int decode_frame(NUTContext *nut, AVPacket *pkt, int frame_code)\n{\n    AVFormatContext *s = nut->avf;\n    AVIOContext *bc    = s->pb;\n    int size, stream_id, discard;\n    int64_t pts, last_IP_pts;\n    StreamContext *stc;\n    uint8_t header_idx;\n    size = decode_frame_header(nut, &pts, &stream_id, &header_idx, frame_code);\n    if (size < 0)\n        return size;\n    stc = &nut->stream[stream_id];\n    if (stc->last_flags & FLAG_KEY)\n        stc->skip_until_key_frame = 0;\n    discard     = s->streams[stream_id]->discard;\n    last_IP_pts = s->streams[stream_id]->last_IP_pts;\n    if ((discard >= AVDISCARD_NONKEY && !(stc->last_flags & FLAG_KEY)) ||\n        (discard >= AVDISCARD_BIDIR  && last_IP_pts != AV_NOPTS_VALUE &&\n         last_IP_pts > pts) ||\n        discard >= AVDISCARD_ALL ||\n        stc->skip_until_key_frame) {\n        avio_skip(bc, size);\n        return 1;\n    }\n    av_new_packet(pkt, size + nut->header_len[header_idx]);\n    memcpy(pkt->data, nut->header[header_idx], nut->header_len[header_idx]);\n    pkt->pos = avio_tell(bc);\n    avio_read(bc, pkt->data + nut->header_len[header_idx], size);\n    pkt->stream_index = stream_id;\n    if (stc->last_flags & FLAG_KEY)\n        pkt->flags |= AV_PKT_FLAG_KEY;\n    pkt->pts = pts;\n    return 0;\n}', 'int av_new_packet(AVPacket *pkt, int size)\n{\n    uint8_t *data = NULL;\n    if ((unsigned)size < (unsigned)size + FF_INPUT_BUFFER_PADDING_SIZE)\n        data = av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE);\n    if (data) {\n        memset(data + size, 0, FF_INPUT_BUFFER_PADDING_SIZE);\n    } else\n        size = 0;\n    av_init_packet(pkt);\n    pkt->data     = data;\n    pkt->size     = size;\n    pkt->destruct = av_destruct_packet;\n    if (!data)\n        return AVERROR(ENOMEM);\n    return 0;\n}', 'void *av_malloc(size_t size)\n{\n    void *ptr = NULL;\n#if CONFIG_MEMALIGN_HACK\n    long diff;\n#endif\n    if (size > (INT_MAX-32) || !size)\n        return NULL;\n#if CONFIG_MEMALIGN_HACK\n    ptr = malloc(size+32);\n    if(!ptr)\n        return ptr;\n    diff= ((-(long)ptr - 1)&31) + 1;\n    ptr = (char*)ptr + diff;\n    ((char*)ptr)[-1]= diff;\n#elif HAVE_POSIX_MEMALIGN\n    if (posix_memalign(&ptr,32,size))\n        ptr = NULL;\n#elif HAVE_ALIGNED_MALLOC\n    ptr = _aligned_malloc(size, 32);\n#elif HAVE_MEMALIGN\n    ptr = memalign(32,size);\n#else\n    ptr = malloc(size);\n#endif\n    return ptr;\n}', 'void av_init_packet(AVPacket *pkt)\n{\n    pkt->pts                  = AV_NOPTS_VALUE;\n    pkt->dts                  = AV_NOPTS_VALUE;\n    pkt->pos                  = -1;\n    pkt->duration             = 0;\n    pkt->convergence_duration = 0;\n    pkt->flags                = 0;\n    pkt->stream_index         = 0;\n    pkt->destruct             = NULL;\n    pkt->side_data            = NULL;\n    pkt->side_data_elems      = 0;\n}']