[PATCH] Implement av_samples_fill_arrays().
Stefano Sabatini
stefano.sabatini-lala
Sat Jan 15 00:00:00 CET 2011
---
libavcore/samplefmt.c | 33 +++++++++++++++++++++++++++++++++
libavcore/samplefmt.h | 29 +++++++++++++++++++++++++++++
2 files changed, 62 insertions(+), 0 deletions(-)
diff --git a/libavcore/samplefmt.c b/libavcore/samplefmt.c
index 532acd9..d2a7c4f 100644
--- a/libavcore/samplefmt.c
+++ b/libavcore/samplefmt.c
@@ -68,3 +68,36 @@ 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 buf_size,
+ enum AVSampleFormat sample_fmt, int planar,
+ int nb_channels)
+{
+ int i, step_size = 0;
+ int sample_size = av_get_bits_per_sample_fmt(sample_fmt) >>3;
+ int per_channel_size;
+
+ per_channel_size = buf_size / nb_channels;
+ if (pointers) {
+ pointers[0] = buf;
+ if (planar) {
+ for (i = 1; i < nb_channels; i++) {
+ step_size += per_channel_size;
+ pointers[i] = buf + step_size;
+ }
+ } else { /* packed */
+ for (i = 1; i < nb_channels; i++)
+ pointers[i] = buf;
+ }
+ memset(&pointers[nb_channels], 0, (8-nb_channels) * sizeof(pointers[0]));
+ }
+
+ if (linesizes) {
+ 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 per_channel_size / sample_size;
+}
diff --git a/libavcore/samplefmt.h b/libavcore/samplefmt.h
index 9701efe..b1abe3d 100644
--- a/libavcore/samplefmt.h
+++ b/libavcore/samplefmt.h
@@ -69,4 +69,33 @@ char *av_get_sample_fmt_string(char *buf, int buf_size, enum AVSampleFormat samp
*/
int av_get_bits_per_sample_fmt(enum AVSampleFormat sample_fmt);
+/**
+ * Fill channel data pointers and linesizes for samples with sample
+ * format sample_fmt.
+ *
+ * The data array is filled with the pointers to the samples data:
+ * 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.
+ *
+ * The linesize for each channel specifies the number of bytes to
+ * traverse to reach the next sample of a particular channel:
+ * for planar, it is set to the sample size,
+ * for packed, it is set to number of channels * sample_size.
+ *
+ * @param data array to be filled with the pointer for each channel, may be NULL
+ * @param linesizes array to be filled with the linesize for each channel, may be NULL
+ * @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 >0 if the samples layout is planar, 0 if it is packed
+ * @param nb_channels the number of channels
+ * @return the number of samples in buf, a negative error code in case
+ * of failure
+ * @see av_samples_fill_pointers() and av_samples_fill_linesizes()
+ */
+int av_samples_fill_arrays(uint8_t *data[8], int linesizes[8],
+ uint8_t *buf, int buf_size,
+ enum AVSampleFormat sample_fmt, int planar,
+ int nb_channels);
+
#endif /* AVCORE_SAMPLEFMT_H */
--
1.7.2.3
--4Ckj6UjgE2iN1+kY--
More information about the ffmpeg-devel
mailing list