[FFmpeg-devel] [PATCH] lavu/samplefmt: add function av_samples_alloc_pointers()

Stefano Sabatini stefasab at gmail.com
Thu Mar 21 20:54:33 CET 2013


---
 libavutil/samplefmt.c |   12 ++++++++++++
 libavutil/samplefmt.h |   13 +++++++++++++
 2 files changed, 25 insertions(+)

diff --git a/libavutil/samplefmt.c b/libavutil/samplefmt.c
index 6f762df..2066c97 100644
--- a/libavutil/samplefmt.c
+++ b/libavutil/samplefmt.c
@@ -207,6 +207,18 @@ int av_samples_alloc(uint8_t **audio_data, int *linesize, int nb_channels,
 #endif
 }
 
+int av_samples_alloc_pointers(uint8_t ***audio_data, int *linesize, int nb_channels,
+                              int nb_samples, enum AVSampleFormat sample_fmt, int align)
+{
+    int nb_planes = av_sample_fmt_is_planar(sample_fmt) ? nb_channels : 1;
+
+    *audio_data = av_malloc(sizeof(*audio_data) * nb_planes);
+    if (!*audio_data)
+        return AVERROR(ENOMEM);
+    return av_samples_alloc(*audio_data, linesize, nb_channels,
+                            nb_samples, sample_fmt, align);
+}
+
 int av_samples_copy(uint8_t **dst, uint8_t * const *src, int dst_offset,
                     int src_offset, int nb_samples, int nb_channels,
                     enum AVSampleFormat sample_fmt)
diff --git a/libavutil/samplefmt.h b/libavutil/samplefmt.h
index 529711f..a592127 100644
--- a/libavutil/samplefmt.h
+++ b/libavutil/samplefmt.h
@@ -209,11 +209,24 @@ int av_samples_fill_arrays(uint8_t **audio_data, int *linesize,
  * @return                 >=0 on success or a negative error code on failure
  * @todo return the size of the allocated buffer in case of success at the next bump
  * @see av_samples_fill_arrays()
+ * @see av_samples_alloc()
  */
 int av_samples_alloc(uint8_t **audio_data, int *linesize, int nb_channels,
                      int nb_samples, enum AVSampleFormat sample_fmt, int align);
 
 /**
+ * Allocate a data pointers array, samples buffer for nb_samples
+ * samples, and fill data pointers and linesize accordingly.
+ *
+ * This is the same as av_samples_alloc(), but also allocate the
+ * pointers array.
+ *
+ * @see av_samples_alloc()
+ */
+int av_samples_alloc_pointers(uint8_t ***audio_data, int *linesize, int nb_channels,
+                              int nb_samples, enum AVSampleFormat sample_fmt, int align);
+
+/**
  * Copy samples from src to dst.
  *
  * @param dst destination array of pointers to data planes
-- 
1.7.9.5



More information about the ffmpeg-devel mailing list