int ff_audio_data_copy(AudioData *dst, AudioData *src)
{
    int ret, p;

    /* validate input/output compatibility */
    if (dst->sample_fmt != src->sample_fmt || dst->channels < src->channels)
        return AVERROR(EINVAL);

    /* if the input is empty, just empty the output */
    if (!src->nb_samples) {
        dst->nb_samples = 0;
        return 0;
    }

    /* reallocate output if necessary */
    ret = ff_audio_data_realloc(dst, src->nb_samples);
    if (ret < 0)
        return ret;

    /* copy data */
    for (p = 0; p < src->planes; p++)
        memcpy(dst->data[p], src->data[p], src->nb_samples * src->stride);
    dst->nb_samples = src->nb_samples;

    return 0;
}