Libav 0.7.1
|
00001 /* 00002 * This file is part of Libav. 00003 * 00004 * Libav is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU Lesser General Public 00006 * License as published by the Free Software Foundation; either 00007 * version 2.1 of the License, or (at your option) any later version. 00008 * 00009 * Libav is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 * Lesser General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU Lesser General Public 00015 * License along with Libav; if not, write to the Free Software 00016 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 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 /* print header */ 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_bytes_per_sample(enum AVSampleFormat sample_fmt) 00070 { 00071 return sample_fmt < 0 || sample_fmt >= AV_SAMPLE_FMT_NB ? 00072 0 : sample_fmt_info[sample_fmt].bits >> 3; 00073 } 00074 00075 #if FF_API_GET_BITS_PER_SAMPLE_FMT 00076 int av_get_bits_per_sample_fmt(enum AVSampleFormat sample_fmt) 00077 { 00078 return sample_fmt < 0 || sample_fmt >= AV_SAMPLE_FMT_NB ? 00079 0 : sample_fmt_info[sample_fmt].bits; 00080 } 00081 #endif