int av_new_packet(AVPacket *pkt, int size)
{
    uint8_t *data;
    if((unsigned)size > (unsigned)size + FF_INPUT_BUFFER_PADDING_SIZE)
        return AVERROR(ENOMEM);
    data = av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE);
    if (!data)
        return AVERROR(ENOMEM);
    memset(data + size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
    av_init_packet(pkt);
    pkt->data = data;
    pkt->size = size;
    pkt->destruct = av_destruct_packet;
    return 0;
}
['static int roq_read_packet(AVFormatContext *s,\n                           AVPacket *pkt)\n{\n    RoqDemuxContext *roq = s->priv_data;\n    ByteIOContext *pb = s->pb;\n    int ret = 0;\n    unsigned int chunk_size;\n    unsigned int chunk_type;\n    unsigned int codebook_size;\n    unsigned char preamble[RoQ_CHUNK_PREAMBLE_SIZE];\n    int packet_read = 0;\n    offset_t codebook_offset;\n    while (!packet_read) {\n        if (url_feof(s->pb))\n            return AVERROR(EIO);\n        if ((ret = get_buffer(pb, preamble, RoQ_CHUNK_PREAMBLE_SIZE)) !=\n            RoQ_CHUNK_PREAMBLE_SIZE)\n            return AVERROR(EIO);\n        chunk_type = AV_RL16(&preamble[0]);\n        chunk_size = AV_RL32(&preamble[2]);\n        if(chunk_size > INT_MAX)\n            return AVERROR_INVALIDDATA;\n        switch (chunk_type) {\n        case RoQ_INFO:\n            url_fseek(pb, RoQ_CHUNK_PREAMBLE_SIZE, SEEK_CUR);\n            break;\n        case RoQ_QUAD_CODEBOOK:\n            codebook_offset = url_ftell(pb) - RoQ_CHUNK_PREAMBLE_SIZE;\n            codebook_size = chunk_size;\n            url_fseek(pb, codebook_size, SEEK_CUR);\n            if (get_buffer(pb, preamble, RoQ_CHUNK_PREAMBLE_SIZE) !=\n                RoQ_CHUNK_PREAMBLE_SIZE)\n                return AVERROR(EIO);\n            chunk_size = AV_RL32(&preamble[2]) + RoQ_CHUNK_PREAMBLE_SIZE * 2 +\n                codebook_size;\n            url_fseek(pb, codebook_offset, SEEK_SET);\n            ret= av_get_packet(pb, pkt, chunk_size);\n            if (ret != chunk_size)\n                return AVERROR(EIO);\n            pkt->stream_index = roq->video_stream_index;\n            pkt->pts = roq->video_pts;\n            roq->video_pts += roq->frame_pts_inc;\n            packet_read = 1;\n            break;\n        case RoQ_SOUND_MONO:\n        case RoQ_SOUND_STEREO:\n        case RoQ_QUAD_VQ:\n            if (av_new_packet(pkt, chunk_size + RoQ_CHUNK_PREAMBLE_SIZE))\n                return AVERROR(EIO);\n            memcpy(pkt->data, preamble, RoQ_CHUNK_PREAMBLE_SIZE);\n            if (chunk_type == RoQ_QUAD_VQ) {\n                pkt->stream_index = roq->video_stream_index;\n                pkt->pts = roq->video_pts;\n                roq->video_pts += roq->frame_pts_inc;\n            } else {\n                pkt->stream_index = roq->audio_stream_index;\n                pkt->pts = roq->audio_frame_count;\n                pkt->pts *= 90000;\n                pkt->pts /= RoQ_AUDIO_SAMPLE_RATE;\n                roq->audio_frame_count += (chunk_size / roq->audio_channels);\n            }\n            pkt->pos= url_ftell(pb);\n            ret = get_buffer(pb, pkt->data + RoQ_CHUNK_PREAMBLE_SIZE,\n                chunk_size);\n            if (ret != chunk_size)\n                ret = AVERROR(EIO);\n            packet_read = 1;\n            break;\n        default:\n            av_log(s, AV_LOG_ERROR, "  unknown RoQ chunk (%04X)\\n", chunk_type);\n            return AVERROR_INVALIDDATA;\n            break;\n        }\n    }\n    return ret;\n}', 'int av_new_packet(AVPacket *pkt, int size)\n{\n    uint8_t *data;\n    if((unsigned)size > (unsigned)size + FF_INPUT_BUFFER_PADDING_SIZE)\n        return AVERROR(ENOMEM);\n    data = av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE);\n    if (!data)\n        return AVERROR(ENOMEM);\n    memset(data + size, 0, FF_INPUT_BUFFER_PADDING_SIZE);\n    av_init_packet(pkt);\n    pkt->data = data;\n    pkt->size = size;\n    pkt->destruct = av_destruct_packet;\n    return 0;\n}']