[igt-dev] [PATCH i-g-t v3 08/10] lib/igt_audio: make audio_extract_channel_s32_le support a NULL dst

Simon Ser simon.ser at intel.com
Mon May 27 14:34:16 UTC 2019


This adds a snprintf-like behaviour to audio_extract_channel_s32_le.

Signed-off-by: Simon Ser <simon.ser at intel.com>
Reviewed-by: Martin Peres <martin.peres at linux.intel.com>
---
 lib/igt_audio.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/lib/igt_audio.c b/lib/igt_audio.c
index be665b03116f..08c0fb6af0db 100644
--- a/lib/igt_audio.c
+++ b/lib/igt_audio.c
@@ -445,7 +445,13 @@ bool audio_signal_detect(struct audio_signal *signal, int sampling_rate,
 }
 
 /**
- * Extracts a single channel from a multi-channel S32_LE input buffer.
+ * audio_extract_channel_s32_le: extracts a single channel from a multi-channel
+ * S32_LE input buffer.
+ *
+ * If dst_cap is zero, no copy is performed. This can be used to compute the
+ * minimum required capacity.
+ *
+ * Returns: the number of samples extracted.
  */
 size_t audio_extract_channel_s32_le(double *dst, size_t dst_cap,
 				    int32_t *src, size_t src_len,
@@ -456,6 +462,9 @@ size_t audio_extract_channel_s32_le(double *dst, size_t dst_cap,
 	igt_assert(channel < n_channels);
 	igt_assert(src_len % n_channels == 0);
 	dst_len = src_len / n_channels;
+	if (dst_cap == 0)
+		return dst_len;
+
 	igt_assert(dst_len <= dst_cap);
 	for (i = 0; i < dst_len; i++)
 		dst[i] = (double) src[i * n_channels + channel] / INT32_MAX;
-- 
2.21.0



More information about the igt-dev mailing list