[FFmpeg-devel] [PATCH] Add av_samples_fill_pointers().

Stefano Sabatini stefano.sabatini-lala
Sat Jan 15 02:26:49 CET 2011


---
 libavcore/audioconvert.c |   32 ++++++++++++++++++++++++++++++++
 libavcore/audioconvert.h |   21 +++++++++++++++++++++
 2 files changed, 53 insertions(+), 0 deletions(-)

diff --git a/libavcore/audioconvert.c b/libavcore/audioconvert.c
index 031c57f..1c6a511 100644
--- a/libavcore/audioconvert.c
+++ b/libavcore/audioconvert.c
@@ -134,3 +134,35 @@ int av_samples_fill_linesizes(int linesizes[8], enum AVSampleFormat sample_fmt,
 
     return 0;
 }
+
+int av_samples_fill_pointers(uint8_t *pointers[8], uint8_t *buf, int buf_size,
+                             enum AVSampleFormat sample_fmt, int planar,
+                             int64_t channel_layout, int nb_channels)
+{
+    int i, step_size = 0;
+    int sample_size = av_get_bits_per_sample_fmt(sample_fmt) >>3;
+    int per_channel_size;
+
+    if (nb_channels <= 0) {
+        if (channel_layout > 0) {
+            nb_channels = av_get_channel_layout_nb_channels(channel_layout);
+        } else
+            /* not enough information for computing the linesizes */
+            return AVERROR(EINVAL);
+    }
+
+    per_channel_size = buf_size / nb_channels;
+    pointers[0] = buf;
+    if (planar) {
+        for (i = 1; i < nb_channels; i++) {
+            step_size += per_channel_size;
+            pointers[i] = buf + step_size;
+        }
+    } else {
+        for (i = 1; i < nb_channels; i++)
+            pointers[i] = buf;
+    }
+    memset(&pointers[nb_channels], 0, (8-nb_channels) * sizeof(pointers[0]));
+
+    return per_channel_size / sample_size;
+}
diff --git a/libavcore/audioconvert.h b/libavcore/audioconvert.h
index bbb8c6e..297f147 100644
--- a/libavcore/audioconvert.h
+++ b/libavcore/audioconvert.h
@@ -108,4 +108,25 @@ int av_get_channel_layout_nb_channels(int64_t channel_layout);
 int av_samples_fill_linesizes(int linesizes[8], enum AVSampleFormat sample_fmt,
                               int planar, int64_t channel_layout, int nb_channels);
 
+/**
+ * Fill channel data pointers for samples with sample format sample_fmt and
+ * For planar, set the start point of each channel's data within the buffer.
+ * For packed, set the start point of the entire buffer only.
+ *
+ * @param pointers pointers array to be filled with the pointer for each image plane
+ * @param buf the pointer to a buffer containing the samples, must
+ * contain an integer number of samples
+ * @param buf_size the size of buf in bytes
+ * @param planar if >0 if the samples layout is planar, 0 if it is packed
+ * @param channel_layout flags which specify the channel layout, see
+ * AV_CH_LAYOUT_*, <= 0 if unknown
+ * @param nb_channels the number of channels, <=0 if unknown
+ * @param linesizes array to be filled with the linesize for each channel
+ * @return the number of samples in buf, a negative error code in case
+ * of failure
+ */
+int av_samples_fill_pointers(uint8_t *pointers[8], uint8_t *buf, int buf_size,
+                             enum AVSampleFormat sample_fmt, int planar,
+                             int64_t channel_layout, int nb_channels);
+
 #endif /* AVCORE_AUDIOCONVERT_H */
-- 
1.7.2.3




More information about the ffmpeg-devel mailing list