[FFmpeg-devel] [PATCH] Implement av_samples_fill_linesizes().

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


---
 libavcore/audioconvert.c |   20 ++++++++++++++++++++
 libavcore/audioconvert.h |   18 +++++++++++++++++-
 2 files changed, 37 insertions(+), 1 deletions(-)

diff --git a/libavcore/audioconvert.c b/libavcore/audioconvert.c
index c720733..031c57f 100644
--- a/libavcore/audioconvert.c
+++ b/libavcore/audioconvert.c
@@ -114,3 +114,23 @@ int av_get_channel_layout_nb_channels(int64_t channel_layout)
         x &= x-1; // unset lowest set bit
     return count;
 }
+
+int av_samples_fill_linesizes(int linesizes[8], enum AVSampleFormat sample_fmt,
+                              int planar, int64_t channel_layout, int nb_channels)
+{
+    int i, sample_size = av_get_bits_per_sample_fmt(sample_fmt) >>3;
+
+    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);
+    }
+
+    for (i = 0; i < nb_channels; i++)
+        linesizes[i] = planar ? sample_size : nb_channels * sample_size;
+    memset(&linesizes[nb_channels], 0, (8-nb_channels) * sizeof(linesizes[0]));
+
+    return 0;
+}
diff --git a/libavcore/audioconvert.h b/libavcore/audioconvert.h
index 89e9c55..bbb8c6e 100644
--- a/libavcore/audioconvert.h
+++ b/libavcore/audioconvert.h
@@ -27,7 +27,7 @@
  * audio conversion routines
  */
 
-#include "avcore.h"
+#include "samplefmt.h"
 
 /* Audio channel masks */
 #define AV_CH_FRONT_LEFT             0x00000001
@@ -92,4 +92,20 @@ void av_get_channel_layout_string(char *buf, int buf_size, int nb_channels, int6
  */
 int av_get_channel_layout_nb_channels(int64_t channel_layout);
 
+/**
+ * Fill linesizes for samples with sample format sample_fmt.
+ * The linesize for each channel specifies the number of bytes to
+ * traverse to reach next sample of a particular channel:
+ * For planar, this is simply the sample size.
+ * For packed, this is the number of channels * sample_size.
+ *
+ * @param channel_layout flags which specify the channel layout, see
+ * AV_CH_LAYOUT_*, <= 0 if unknown
+ * @param nb_channels the number of channels, <=0 is unknown
+ * @param linesizes array to be filled with the linesize for each channel
+ * @return >= 0 in case of success, a negative error code otherwise
+ */
+int av_samples_fill_linesizes(int linesizes[8], 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