summaryrefslogtreecommitdiff
path: root/libavutil/samplefmt.c
diff options
context:
space:
mode:
Diffstat (limited to 'libavutil/samplefmt.c')
-rw-r--r--libavutil/samplefmt.c55
1 files changed, 51 insertions, 4 deletions
diff --git a/libavutil/samplefmt.c b/libavutil/samplefmt.c
index 06b50d9bd9..ea004d926a 100644
--- a/libavutil/samplefmt.c
+++ b/libavutil/samplefmt.c
@@ -1,18 +1,18 @@
/*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -71,3 +71,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);
+}