[FFmpeg-cvslog] Implement av_samples_alloc() and av_samples_fill_arrays().
Stefano Sabatini
stefano.sabatini-lala
Thu Feb 3 19:34:25 CET 2011
On date Wednesday 2011-02-02 03:26:32 +0100, Stefano Sabatini wrote:
> ffmpeg | branch: master | Stefano Sabatini <stefano.sabatini-lala at poste.it> | Sat Jan 15 00:00:00 2011 +0100| [e98b8e2f2fae3e75f87d0d87098a8faee691a514] | committer: Michael Niedermayer
>
> Implement av_samples_alloc() and av_samples_fill_arrays().
>
> With minor changes by michael
>
> Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
>
> > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=e98b8e2f2fae3e75f87d0d87098a8faee691a514
> ---
>
> libavcore/samplefmt.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
> libavcore/samplefmt.h | 39 +++++++++++++++++++++++++++++++++++++++
> 2 files changed, 86 insertions(+), 0 deletions(-)
>
> diff --git a/libavcore/samplefmt.c b/libavcore/samplefmt.c
> index 532acd9..db6b93c 100644
> --- a/libavcore/samplefmt.c
> +++ b/libavcore/samplefmt.c
> @@ -68,3 +68,50 @@ int av_get_bits_per_sample_fmt(enum AVSampleFormat sample_fmt)
> return sample_fmt < 0 || sample_fmt >= AV_SAMPLE_FMT_NB ?
> 0 : sample_fmt_info[sample_fmt].bits;
> }
> +
> +int av_samples_fill_arrays(uint8_t *pointers[8], int linesizes[8],
> + uint8_t *buf, int nb_channels, int nb_samples,
> + enum AVSampleFormat sample_fmt, int planar, int align)
> +{
> + int i, step_size = 0;
> + int sample_size = av_get_bits_per_sample_fmt(sample_fmt) >> 3;
Maybe more correct: (av_get_bits_per_sample_fmt(sample_fmt) + 7) >> 3;
> + int channel_step = planar ? FFALIGN(nb_samples*sample_size, align) : sample_size;
> +
> + if(nb_channels * (uint64_t)nb_samples * sample_size >= INT_MAX - align*(uint64_t)nb_channels)
> + return AVERROR(EINVAL);
> +
> + if (pointers) {
> + pointers[0] = buf;
> + for (i = 0; i < nb_channels; i++) {
> + pointers[i] = buf + step_size;
> + step_size += channel_step;
> + }
> + memset(&pointers[nb_channels], 0, (8-nb_channels) * sizeof(pointers[0]));
> + }
> +
> + if (linesizes) {
> + linesizes[0] = planar ? sample_size : nb_channels*sample_size;
> + memset(&linesizes[1], 0, (8-1) * sizeof(linesizes[0]));
> + }
> +
> + return planar ? channel_step * nb_channels : FFALIGN(nb_channels*sample_size*nb_samples, align);
> +}
OK so in this case we have:
linesize[0] = { sample component step for each plane }
linesize[i] = 0 for i > 0
pointers[i] = { plane buffer number i or NULL }
in this case linesize use is consistent with the use in
av_audio_convert().
I can see just a problem, if you want to copy a samples buffer you
can't just do it with:
void av_samples_copy(uint8_t *dst_data[8], int dst_linesizes[8],
const uint8_t *src_data[8], const int src_linesizes[8],
enum AVSampleFormat sample_fmt, int nb_samples);
while preserving the same alignment (you also need to pass align).
Also the layout is not consistent with that of imgutils (linesize
contains the size of each aligned plane), I wonder if having the thing
consistent may be helpful.
[...]
--
FFmpeg = Formidable Foolish Mortal Peaceful Ecumenical Governor
More information about the ffmpeg-cvslog
mailing list