On date Sunday 2011-06-05 18:22:06 -0400, Justin Ruggles encoded: > On 06/05/2011 05:33 PM, Justin Ruggles wrote: > > > On 06/05/2011 05:00 PM, Stefano Sabatini wrote: [...] > >> In case the sense of the text above was not clear, I meant: do you > >> have some reason to suppose that we may add a sample format with a non > >> integer number of bytes? > > > > no. > > Well, I guess maybe someday we might encounter some hardware device that > uses fractional bits per sample, in which case it might be nice to > convert to such a theoretical sample format in our theoretical future > audio conversion lib. So maybe we should have both variants in > libavutil to avoid dividing by 8 everywhere now and also stay adaptable > to future unknowns.
Check attached patch.
>From 2d2cc2a73abf3ceb739f4188f29377b17de26165 Mon Sep 17 00:00:00 2001 From: Stefano Sabatini <[email protected]> Date: Mon, 6 Jun 2011 01:14:50 +0200 Subject: [PATCH] samplefmt: add av_get_bytes_per_sample() Deprecate av_get_bits_per_sample_fmt(), which was a misnamed function. For the moment we don't have sample formats with a non-integer number of bytes, in that case we may need to create a new av_get_bits_per_sample() function. In the meanwhile we prefer to adopt this variant, since avoids divisions by 8 all over the place. --- doc/APIchanges | 3 +++ libavutil/avutil.h | 3 +++ libavutil/samplefmt.c | 8 ++++++++ libavutil/samplefmt.h | 16 +++++++++++++--- 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/doc/APIchanges b/doc/APIchanges index 77eb6d2..89d45e9 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -13,6 +13,9 @@ libavutil: 2011-04-18 API changes, most recent first: +2011-06-XX - xxxxxx - lavu 51.X.0 - av_get_bytes_per_sample() + Add av_get_bytes_per_sample() in libavutil/samplefmt.h. + 2011-06-xx - xxxxxxx - lavu 51.3.0 - opt.h Add av_opt_free convenience function. diff --git a/libavutil/avutil.h b/libavutil/avutil.h index 5085a6d..e6b9817 100644 --- a/libavutil/avutil.h +++ b/libavutil/avutil.h @@ -57,6 +57,9 @@ * Those FF_API_* defines are not part of public API. * They may change, break or disappear at any time. */ +#ifndef FF_API_GET_BITS_PER_SAMPLE_FMT +#define FF_API_GET_BITS_PER_SAMPLE_FMT (LIBAVUTIL_VERSION_MAJOR < 52) +#endif /** * Return the LIBAVUTIL_VERSION_INT constant. diff --git a/libavutil/samplefmt.c b/libavutil/samplefmt.c index 06b50d9..5b0bfa0 100644 --- a/libavutil/samplefmt.c +++ b/libavutil/samplefmt.c @@ -66,8 +66,16 @@ char *av_get_sample_fmt_string (char *buf, int buf_size, enum AVSampleFormat sam return buf; } +int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt) +{ + return sample_fmt < 0 || sample_fmt >= AV_SAMPLE_FMT_NB ? + 0 : sample_fmt_info[sample_fmt].bits >> 3; +} + +#if FF_API_GET_BITS_PER_SAMPLE_FMT 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; } +#endif diff --git a/libavutil/samplefmt.h b/libavutil/samplefmt.h index 2326f4a..e382149 100644 --- a/libavutil/samplefmt.h +++ b/libavutil/samplefmt.h @@ -19,6 +19,8 @@ #ifndef AVUTIL_SAMPLEFMT_H #define AVUTIL_SAMPLEFMT_H +#include "avutil.h" + /** * all in native-endian format */ @@ -58,13 +60,21 @@ enum AVSampleFormat av_get_sample_fmt(const char *name); */ char *av_get_sample_fmt_string(char *buf, int buf_size, enum AVSampleFormat sample_fmt); +#if FF_API_GET_BITS_PER_SAMPLE_FMT +/** + * @deprecated Use av_get_bytes_per_sample() instead. + */ +attribute_deprecated +int av_get_bits_per_sample_fmt(enum AVSampleFormat sample_fmt); +#endif + /** - * Return sample format bits per sample. + * Return number of bytes per sample. * * @param sample_fmt the sample format - * @return number of bits per sample or zero if unknown for the given + * @return number of bytes per sample or zero if unknown for the given * sample format */ -int av_get_bits_per_sample_fmt(enum AVSampleFormat sample_fmt); +int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt); #endif /* AVUTIL_SAMPLEFMT_H */ -- 1.7.2.3
_______________________________________________ libav-devel mailing list [email protected] https://lists.libav.org/mailman/listinfo/libav-devel
