diff options
author | Stefano Sabatini <stefano.sabatini-lala@poste.it> | 2010-11-02 22:08:02 +0000 |
---|---|---|
committer | Stefano Sabatini <stefano.sabatini-lala@poste.it> | 2010-11-02 22:08:02 +0000 |
commit | d63e456a2abcc8c23962f2b8828004c6a35ca1fe (patch) | |
tree | 06ff602fe7de05832fe92a70011319326585a763 /libavcore | |
parent | 262d1c5d2206467809fd81d841d09ad70cc8ba13 (diff) | |
download | ffmpeg-d63e456a2abcc8c23962f2b8828004c6a35ca1fe.tar.gz |
Implement functions:
av_get_sample_fmt_name()
av_get_sample_fmt()
av_get_sample_fmt_string()
in libavcore, and deprecate the corresponding libavcodec/audioconvert.h functions:
avcodec_get_sample_fmt_name()
avcodec_get_sample_fmt()
avcodec_sample_fmt_string()
Originally committed as revision 25653 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcore')
-rw-r--r-- | libavcore/Makefile | 1 | ||||
-rw-r--r-- | libavcore/avcore.h | 2 | ||||
-rw-r--r-- | libavcore/samplefmt.c | 64 | ||||
-rw-r--r-- | libavcore/samplefmt.h | 26 |
4 files changed, 92 insertions, 1 deletions
diff --git a/libavcore/Makefile b/libavcore/Makefile index 97d973fa28..037f55ebf7 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/avcore.h b/libavcore/avcore.h index 5870817f23..dd1cd75f02 100644 --- a/libavcore/avcore.h +++ b/libavcore/avcore.h @@ -27,7 +27,7 @@ #include "libavutil/avutil.h" #define LIBAVCORE_VERSION_MAJOR 0 -#define LIBAVCORE_VERSION_MINOR 10 +#define LIBAVCORE_VERSION_MINOR 11 #define LIBAVCORE_VERSION_MICRO 0 #define LIBAVCORE_VERSION_INT AV_VERSION_INT(LIBAVCORE_VERSION_MAJOR, \ diff --git a/libavcore/samplefmt.c b/libavcore/samplefmt.c new file mode 100644 index 0000000000..49ab8296f7 --- /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 163246b35f..482bb48471 100644 --- a/libavcore/samplefmt.h +++ b/libavcore/samplefmt.h @@ -32,4 +32,30 @@ enum AVSampleFormat { AV_SAMPLE_FMT_NB ///< Number of sample formats. DO NOT USE if dynamically linking to libavcore }; +/** + * 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. + * @return the pointer to the filled buffer or NULL if sample_fmt is + * unknown or in case of other errors + */ +char *av_get_sample_fmt_string(char *buf, int buf_size, enum AVSampleFormat sample_fmt); + #endif /* AVCORE_SAMPLEFMT_H */ |