[FFmpeg-devel] [PATCH 2/2] Implement functions: av_get_sample_fmt_name() av_get_sample_fmt() av_get_sample_fmt_string()
Stefano Sabatini
stefano.sabatini-lala
Fri Oct 29 09:32:20 CEST 2010
in libavcore, and deprecate the corresponding libavcodec/audioconvert.h functions:
avcodec_get_sample_fmt_name()
avcodec_get_sample_fmt()
avcodec_sample_fmt_string()
---
doc/APIchanges | 6 ++++
libavcodec/audioconvert.c | 36 ++++---------------------
libavcodec/audioconvert.h | 19 +++++-------
libavcore/Makefile | 1 +
libavcore/samplefmt.c | 64 +++++++++++++++++++++++++++++++++++++++++++++
libavcore/samplefmt.h | 28 +++++++++++++++++++
6 files changed, 113 insertions(+), 41 deletions(-)
create mode 100644 libavcore/samplefmt.c
diff --git a/doc/APIchanges b/doc/APIchanges
index 12b1015..0b3f688 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -14,6 +14,12 @@ libavutil: 2009-03-08
API changes, most recent first:
2010-XX-XX - rXXXXX - lavcore 0.X.0 - samplefmt.h
+ Add sample format functions:
+ av_get_sample_fmt_name(),
+ av_get_sample_fmt(),
+ av_get_sample_fmt_string().
+
+2010-XX-XX - rXXXXX - lavcore 0.X.0 - samplefmt.h
Define enum AVSampleFormat in libavcore/samplefmt.h, deprecate enum
SampleFormat.
diff --git a/libavcodec/audioconvert.c b/libavcodec/audioconvert.c
index c6dc1b1..4e4063f 100644
--- a/libavcodec/audioconvert.c
+++ b/libavcodec/audioconvert.c
@@ -27,50 +27,26 @@
#include "libavutil/avstring.h"
#include "libavutil/libm.h"
+#include "libavcore/samplefmt.h"
#include "avcodec.h"
#include "audioconvert.h"
-typedef struct SampleFmtInfo {
- const char *name;
- int bits;
-} SampleFmtInfo;
-
-/** this table gives more information about formats */
-static const SampleFmtInfo sample_fmt_info[SAMPLE_FMT_NB] = {
- [SAMPLE_FMT_U8] = { .name = "u8", .bits = 8 },
- [SAMPLE_FMT_S16] = { .name = "s16", .bits = 16 },
- [SAMPLE_FMT_S32] = { .name = "s32", .bits = 32 },
- [SAMPLE_FMT_FLT] = { .name = "flt", .bits = 32 },
- [SAMPLE_FMT_DBL] = { .name = "dbl", .bits = 64 },
-};
-
+#if FF_API_OLD_SAMPLE_FMT
const char *avcodec_get_sample_fmt_name(int sample_fmt)
{
- if (sample_fmt < 0 || sample_fmt >= SAMPLE_FMT_NB)
- return NULL;
- return sample_fmt_info[sample_fmt].name;
+ return av_get_sample_fmt_name(sample_fmt);
}
enum SampleFormat avcodec_get_sample_fmt(const char* name)
{
- int i;
-
- for (i=0; i < SAMPLE_FMT_NB; i++)
- if (!strcmp(sample_fmt_info[i].name, name))
- return i;
- return SAMPLE_FMT_NONE;
+ return av_get_sample_fmt(name);
}
void avcodec_sample_fmt_string (char *buf, int buf_size, int sample_fmt)
{
- /* print header */
- if (sample_fmt < 0)
- snprintf (buf, buf_size, "name " " depth");
- else if (sample_fmt < SAMPLE_FMT_NB) {
- SampleFmtInfo info= sample_fmt_info[sample_fmt];
- snprintf (buf, buf_size, "%-6s" " %2d ", info.name, info.bits);
- }
+ av_get_sample_fmt_string(buf, buf_size, sample_fmt);
}
+#endif
static const char* const channel_names[]={
"FL", "FR", "FC", "LFE", "BL", "BR", "FLC", "FRC",
diff --git a/libavcodec/audioconvert.h b/libavcodec/audioconvert.h
index 349065e..e7d262b 100644
--- a/libavcodec/audioconvert.h
+++ b/libavcodec/audioconvert.h
@@ -32,28 +32,25 @@
#include "libavutil/cpu.h"
#include "avcodec.h"
-
+#if FF_API_OLD_SAMPLE_FMT
/**
- * Generate string corresponding to the sample format with
- * number sample_fmt, or a header if sample_fmt is negative.
- *
- * @param[in] buf the buffer where to write the string
- * @param[in] buf_size the size of buf
- * @param[in] sample_fmt the number of the sample format to print the corresponding info string, or
- * a negative value to print the corresponding header.
- * Meaningful values for obtaining a sample format info vary from 0 to SAMPLE_FMT_NB -1.
+ * @deprecated Use av_get_sample_fmt_string() instead.
*/
+attribute_deprecated
void avcodec_sample_fmt_string(char *buf, int buf_size, int sample_fmt);
/**
- * @return NULL on error
+ * @deprecated Use av_get_sample_fmt_name() instead.
*/
+attribute_deprecated
const char *avcodec_get_sample_fmt_name(int sample_fmt);
/**
- * @return SAMPLE_FMT_NONE on error
+ * @deprecated Use av_get_sample_fmt() instead.
*/
+attribute_deprecated
enum SampleFormat avcodec_get_sample_fmt(const char* name);
+#endif
/**
* @return NULL on error
diff --git a/libavcore/Makefile b/libavcore/Makefile
index 97d973f..037f55e 100644
--- a/libavcore/Makefile
+++ b/libavcore/Makefile
@@ -10,6 +10,7 @@ HEADERS = avcore.h \
OBJS = imgutils.o \
parseutils.o \
+ samplefmt.o \
utils.o \
include $(SUBDIR)../subdir.mak
diff --git a/libavcore/samplefmt.c b/libavcore/samplefmt.c
new file mode 100644
index 0000000..49ab829
--- /dev/null
+++ b/libavcore/samplefmt.c
@@ -0,0 +1,64 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "avcore.h"
+#include "samplefmt.h"
+
+typedef struct SampleFmtInfo {
+ const char *name;
+ int bits;
+} SampleFmtInfo;
+
+/** this table gives more information about formats */
+static const SampleFmtInfo sample_fmt_info[AV_SAMPLE_FMT_NB] = {
+ [AV_SAMPLE_FMT_U8] = { .name = "u8", .bits = 8 },
+ [AV_SAMPLE_FMT_S16] = { .name = "s16", .bits = 16 },
+ [AV_SAMPLE_FMT_S32] = { .name = "s32", .bits = 32 },
+ [AV_SAMPLE_FMT_FLT] = { .name = "flt", .bits = 32 },
+ [AV_SAMPLE_FMT_DBL] = { .name = "dbl", .bits = 64 },
+};
+
+const char *av_get_sample_fmt_name(enum AVSampleFormat sample_fmt)
+{
+ if (sample_fmt < 0 || sample_fmt >= AV_SAMPLE_FMT_NB)
+ return NULL;
+ return sample_fmt_info[sample_fmt].name;
+}
+
+enum AVSampleFormat av_get_sample_fmt(const char *name)
+{
+ int i;
+
+ for (i = 0; i < AV_SAMPLE_FMT_NB; i++)
+ if (!strcmp(sample_fmt_info[i].name, name))
+ return i;
+ return AV_SAMPLE_FMT_NONE;
+}
+
+char *av_get_sample_fmt_string (char *buf, int buf_size, enum AVSampleFormat sample_fmt)
+{
+ /* print header */
+ if (sample_fmt < 0)
+ snprintf(buf, buf_size, "name " " depth");
+ else if (sample_fmt < AV_SAMPLE_FMT_NB) {
+ SampleFmtInfo info = sample_fmt_info[sample_fmt];
+ snprintf (buf, buf_size, "%-6s" " %2d ", info.name, info.bits);
+ }
+
+ return buf;
+}
diff --git a/libavcore/samplefmt.h b/libavcore/samplefmt.h
index 0051c8d..3db3cd7 100644
--- a/libavcore/samplefmt.h
+++ b/libavcore/samplefmt.h
@@ -32,4 +32,32 @@ enum AVSampleFormat {
AV_SAMPLE_FMT_NB ///< Number of sample formats. DO NOT USE if dynamically linking to libavcodec
};
+/**
+ * Return the name of sample_fmt, or NULL if sample_fmt is not
+ * recognized.
+ */
+const char *av_get_sample_fmt_name(enum AVSampleFormat sample_fmt);
+
+/**
+ * Return a sample format corresponding to name, or AV_SAMPLE_FMT_NONE
+ * on error.
+ */
+enum AVSampleFormat av_get_sample_fmt(const char *name);
+
+/**
+ * Generate a string corresponding to the sample format with
+ * sample_fmt, or a header if sample_fmt is negative.
+ *
+ * @param buf the buffer where to write the string
+ * @param buf_size the size of buf
+ * @param sample_fmt the number of the sample format to print the
+ * corresponding info string, or a negative value to print the
+ * corresponding header.
+ * Meaningful values for obtaining a sample format info vary from 0 to
+ * AV_SAMPLE_FMT_NB -1.
+ * @return the pointer to the filled buffer or NULL in case of
+ * failure
+ */
+char *av_get_sample_fmt_string(char *buf, int buf_size, enum AVSampleFormat sample_fmt);
+
#endif /* AVCORE_SAMPLEFMT_H */
--
1.7.1
More information about the ffmpeg-devel
mailing list