[FFmpeg-cvslog] lavu/samplefmt: return the size of the allocated samples buffer at the next bump

Stefano Sabatini git at videolan.org
Sun Nov 25 23:57:01 CET 2012


ffmpeg | branch: master | Stefano Sabatini <stefasab at gmail.com> | Sun Nov 25 20:23:32 2012 +0100| [b473c9937ebe9aafef9d2e07f080fb12ecc53ef4] | committer: Stefano Sabatini

lavu/samplefmt: return the size of the allocated samples buffer at the next bump

Make the functions av_samples_fill_arrays, av_samples_alloc, and
avcodec_fill_audio_frame return a buffer size rather than 0 in case of
success. This will be enabled at the next libavutil major bump, in order
to preserve backward compatibility.

Returning the size allows to simplify the code, avoiding a few function
calls.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=b473c9937ebe9aafef9d2e07f080fb12ecc53ef4
---

 libavcodec/avcodec.h  |    4 +++-
 libavutil/samplefmt.c |    8 ++++++++
 libavutil/samplefmt.h |    7 +++++--
 libavutil/version.h   |    3 +++
 4 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index d5fd387..5ebad92 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -4780,7 +4780,9 @@ int avcodec_default_execute2(AVCodecContext *c, int (*func)(AVCodecContext *c2,
  * @param buf         buffer to use for frame data
  * @param buf_size    size of buffer
  * @param align       plane size sample alignment (0 = default)
- * @return            0 on success, negative error code on failure
+ * @return            >=0 on success, negative error code on failure
+ * @todo return the size of the allocated frame size in case of
+ * success, at the next libavutil bump
  */
 int avcodec_fill_audio_frame(AVFrame *frame, int nb_channels,
                              enum AVSampleFormat sample_fmt, const uint8_t *buf,
diff --git a/libavutil/samplefmt.c b/libavutil/samplefmt.c
index 96cc5fb..6f762df 100644
--- a/libavutil/samplefmt.c
+++ b/libavutil/samplefmt.c
@@ -171,7 +171,11 @@ int av_samples_fill_arrays(uint8_t **audio_data, int *linesize,
     if (linesize)
         *linesize = line_size;
 
+#if FF_API_SAMPLES_UTILS_RETURN_ZERO
     return 0;
+#else
+    return buf_size;
+#endif
 }
 
 int av_samples_alloc(uint8_t **audio_data, int *linesize, int nb_channels,
@@ -196,7 +200,11 @@ int av_samples_alloc(uint8_t **audio_data, int *linesize, int nb_channels,
 
     av_samples_set_silence(audio_data, 0, nb_samples, nb_channels, sample_fmt);
 
+#if FF_API_SAMPLES_UTILS_RETURN_ZERO
     return 0;
+#else
+    return size;
+#endif
 }
 
 int av_samples_copy(uint8_t **dst, uint8_t * const *src, int dst_offset,
diff --git a/libavutil/samplefmt.h b/libavutil/samplefmt.h
index 17300d1..e222ba2 100644
--- a/libavutil/samplefmt.h
+++ b/libavutil/samplefmt.h
@@ -183,7 +183,9 @@ int av_samples_get_buffer_size(int *linesize, int nb_channels, int nb_samples,
  * @param nb_samples       the number of samples in a single channel
  * @param sample_fmt       the sample format
  * @param align            buffer size alignment (0 = default, 1 = no alignment)
- * @return                 0 on success or a negative error code on failure
+ * @return                 >=0 on success or a negative error code on failure
+ * @todo return minimum size in bytes required for the buffer in case
+ * of success at the next bump
  */
 int av_samples_fill_arrays(uint8_t **audio_data, int *linesize,
                            const uint8_t *buf,
@@ -204,7 +206,8 @@ int av_samples_fill_arrays(uint8_t **audio_data, int *linesize,
  * @param nb_channels      number of audio channels
  * @param nb_samples       number of samples per channel
  * @param align            buffer size alignment (0 = default, 1 = no alignment)
- * @return                 0 on success or a negative error code on failure
+ * @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()
  */
 int av_samples_alloc(uint8_t **audio_data, int *linesize, int nb_channels,
diff --git a/libavutil/version.h b/libavutil/version.h
index 8b9c813..af60f71 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -126,6 +126,9 @@
 #ifndef FF_API_CPU_FLAG_MMX2
 #define FF_API_CPU_FLAG_MMX2            (LIBAVUTIL_VERSION_MAJOR < 53)
 #endif
+#ifndef FF_API_SAMPLES_UTILS_RETURN_ZERO
+#define FF_API_SAMPLES_UTILS_RETURN_ZERO (LIBAVUTIL_VERSION_MAJOR < 53)
+#endif
 
 /**
  * @}



More information about the ffmpeg-cvslog mailing list