diff options
author | Reinhard Tartler <siretart@tauware.de> | 2011-02-07 14:37:08 +0100 |
---|---|---|
committer | Reinhard Tartler <siretart@tauware.de> | 2011-02-15 16:18:21 +0100 |
commit | 737eb5976f6a37703923ce3c3d5e6ca8eeabb43a (patch) | |
tree | ab13f1d9bc6e2d47882bb54c50f26f16ecdcf28b /libavutil/samplefmt.c | |
parent | 8ed4cc65a19b5a6cc7ae6ed5072be2d3836dbeb2 (diff) | |
download | ffmpeg-737eb5976f6a37703923ce3c3d5e6ca8eeabb43a.tar.gz |
Merge libavcore into libavutil
It is pretty hopeless that other considerable projects will adopt
libavutil alone in other projects. Projects that need small footprint
are better off with more specialized libraries such as gnulib or rather
just copy the necessary parts that they need. With this in mind, nobody
is helped by having libavutil and libavcore split. In order to ease
maintenance inside and around FFmpeg and to reduce confusion where to
put common code, avcore's functionality is merged (back) to avutil.
Signed-off-by: Reinhard Tartler <siretart@tauware.de>
Diffstat (limited to 'libavutil/samplefmt.c')
-rw-r--r-- | libavutil/samplefmt.c | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/libavutil/samplefmt.c b/libavutil/samplefmt.c new file mode 100644 index 0000000000..c9ffd1ac55 --- /dev/null +++ b/libavutil/samplefmt.c @@ -0,0 +1,73 @@ +/* + * 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 "samplefmt.h" + +#include <stdio.h> +#include <stdlib.h> +#include <string.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; +} + +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; +} |