aboutsummaryrefslogtreecommitdiffstats
path: root/libavcore/samplefmt.c
diff options
context:
space:
mode:
authorStefano Sabatini <stefano.sabatini-lala@poste.it>2011-01-15 00:00:00 +0100
committerMichael Niedermayer <michaelni@gmx.at>2011-02-02 03:12:47 +0100
commite98b8e2f2fae3e75f87d0d87098a8faee691a514 (patch)
tree319be9315752e6cde4771c2f29926121ff914f76 /libavcore/samplefmt.c
parent40222b926b6d2f7d08aeeff756de3ade36121396 (diff)
downloadffmpeg-e98b8e2f2fae3e75f87d0d87098a8faee691a514.tar.gz
Implement av_samples_alloc() and av_samples_fill_arrays().
With minor changes by michael Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcore/samplefmt.c')
-rw-r--r--libavcore/samplefmt.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/libavcore/samplefmt.c b/libavcore/samplefmt.c
index 532acd9507..db6b93cd4c 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;
+ 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);
+}
+
+int av_samples_alloc(uint8_t *pointers[8], int linesizes[8],
+ int nb_samples, int nb_channels,
+ enum AVSampleFormat sample_fmt, int planar,
+ int align)
+{
+ uint8_t *buf;
+ int size = av_samples_fill_arrays(NULL, NULL,
+ NULL, nb_channels, nb_samples,
+ sample_fmt, planar, align);
+
+ buf = av_mallocz(size);
+ if (!buf)
+ return AVERROR(ENOMEM);
+
+ return av_samples_fill_arrays(pointers, linesizes,
+ buf, nb_channels, nb_samples,
+ sample_fmt, planar, align);
+}