static int cinaudio_decode_frame(AVCodecContext *avctx,
                                 void *data, int *data_size,
                                 AVPacket *avpkt)
{
    const uint8_t *buf = avpkt->data;
    CinAudioContext *cin = avctx->priv_data;
    const uint8_t *buf_end = buf + avpkt->size;
    int16_t *samples = data;
    int delta, out_size;

    out_size = (avpkt->size - cin->initial_decode_frame) *
               av_get_bytes_per_sample(avctx->sample_fmt);
    if (*data_size < out_size) {
        av_log(avctx, AV_LOG_ERROR, "Output buffer is too small\n");
        return AVERROR(EINVAL);
    }

    delta = cin->delta;
    if (cin->initial_decode_frame) {
        cin->initial_decode_frame = 0;
        delta = (int16_t)AV_RL16(buf);
        buf += 2;
        *samples++ = delta;
    }
    while (buf < buf_end) {
        delta += cinaudio_delta16_table[*buf++];
        delta = av_clip_int16(delta);
        *samples++ = delta;
    }
    cin->delta = delta;

    *data_size = out_size;

    return avpkt->size;
}