00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "samplefmt.h"
00020
00021 #include <stdio.h>
00022 #include <stdlib.h>
00023 #include <string.h>
00024
00025 typedef struct SampleFmtInfo {
00026 const char *name;
00027 int bits;
00028 } SampleFmtInfo;
00029
00031 static const SampleFmtInfo sample_fmt_info[AV_SAMPLE_FMT_NB] = {
00032 [AV_SAMPLE_FMT_U8] = { .name = "u8", .bits = 8 },
00033 [AV_SAMPLE_FMT_S16] = { .name = "s16", .bits = 16 },
00034 [AV_SAMPLE_FMT_S32] = { .name = "s32", .bits = 32 },
00035 [AV_SAMPLE_FMT_FLT] = { .name = "flt", .bits = 32 },
00036 [AV_SAMPLE_FMT_DBL] = { .name = "dbl", .bits = 64 },
00037 };
00038
00039 const char *av_get_sample_fmt_name(enum AVSampleFormat sample_fmt)
00040 {
00041 if (sample_fmt < 0 || sample_fmt >= AV_SAMPLE_FMT_NB)
00042 return NULL;
00043 return sample_fmt_info[sample_fmt].name;
00044 }
00045
00046 enum AVSampleFormat av_get_sample_fmt(const char *name)
00047 {
00048 int i;
00049
00050 for (i = 0; i < AV_SAMPLE_FMT_NB; i++)
00051 if (!strcmp(sample_fmt_info[i].name, name))
00052 return i;
00053 return AV_SAMPLE_FMT_NONE;
00054 }
00055
00056 char *av_get_sample_fmt_string (char *buf, int buf_size, enum AVSampleFormat sample_fmt)
00057 {
00058
00059 if (sample_fmt < 0)
00060 snprintf(buf, buf_size, "name " " depth");
00061 else if (sample_fmt < AV_SAMPLE_FMT_NB) {
00062 SampleFmtInfo info = sample_fmt_info[sample_fmt];
00063 snprintf (buf, buf_size, "%-6s" " %2d ", info.name, info.bits);
00064 }
00065
00066 return buf;
00067 }
00068
00069 int av_get_bits_per_sample_fmt(enum AVSampleFormat sample_fmt)
00070 {
00071 return sample_fmt < 0 || sample_fmt >= AV_SAMPLE_FMT_NB ?
00072 0 : sample_fmt_info[sample_fmt].bits;
00073 }