mirror of https://github.com/mpv-player/mpv
options, codecs.conf, img_format: unify imgfmt name handling
Remove the duplication of image format name lists from codec-cfg.c and img_format.c. Remove the list of "long" image format names from img_format.c. One user visible change is that now mplayer won't print "long" format names anymore: e.g. instead of "Planar 420P 10-bit little-endian", the name "420p10le" is used. This is consistent with the names used by the option parser, and also less noisy. Partially based on mplayer2 commit f98e47574de15, with some differences.
This commit is contained in:
parent
d5aa8dc88f
commit
7bb95cd8a5
83
codec-cfg.c
83
codec-cfg.c
|
@ -141,78 +141,6 @@ static int add_to_format(char *s, char *alias,unsigned int *fourcc, unsigned int
|
|||
return 1;
|
||||
}
|
||||
|
||||
static const struct {
|
||||
const char *name;
|
||||
const unsigned int num;
|
||||
} fmt_table[] = {
|
||||
// note: due to parser deficiencies/simplicity, if one format
|
||||
// name matches the beginning of another, the longer one _must_
|
||||
// come first in this list.
|
||||
{"YV12", IMGFMT_YV12},
|
||||
{"I420", IMGFMT_I420},
|
||||
{"IYUV", IMGFMT_IYUV},
|
||||
{"NV12", IMGFMT_NV12},
|
||||
{"NV21", IMGFMT_NV21},
|
||||
{"YVU9", IMGFMT_YVU9},
|
||||
{"IF09", IMGFMT_IF09},
|
||||
{"444P16LE", IMGFMT_444P16_LE},
|
||||
{"444P16BE", IMGFMT_444P16_BE},
|
||||
{"422P16LE", IMGFMT_422P16_LE},
|
||||
{"422P16BE", IMGFMT_422P16_BE},
|
||||
{"420P16LE", IMGFMT_420P16_LE},
|
||||
{"420P16BE", IMGFMT_420P16_BE},
|
||||
{"444P16", IMGFMT_444P16},
|
||||
{"444P10", IMGFMT_444P10},
|
||||
{"444P9", IMGFMT_444P9},
|
||||
{"422P16", IMGFMT_422P16},
|
||||
{"422P10", IMGFMT_422P10},
|
||||
{"422P9", IMGFMT_422P9},
|
||||
{"420P16", IMGFMT_420P16},
|
||||
{"420P10", IMGFMT_420P10},
|
||||
{"420P9", IMGFMT_420P9},
|
||||
{"420A", IMGFMT_420A},
|
||||
{"444P", IMGFMT_444P},
|
||||
{"422P", IMGFMT_422P},
|
||||
{"411P", IMGFMT_411P},
|
||||
{"440P", IMGFMT_440P},
|
||||
{"Y800", IMGFMT_Y800},
|
||||
{"Y8", IMGFMT_Y8},
|
||||
|
||||
{"YUY2", IMGFMT_YUY2},
|
||||
{"UYVY", IMGFMT_UYVY},
|
||||
{"YVYU", IMGFMT_YVYU},
|
||||
|
||||
{"RGB48LE", IMGFMT_RGB48LE},
|
||||
{"RGB48BE", IMGFMT_RGB48BE},
|
||||
{"RGB4", IMGFMT_RGB4},
|
||||
{"RGB8", IMGFMT_RGB8},
|
||||
{"RGB15", IMGFMT_RGB15},
|
||||
{"RGB16", IMGFMT_RGB16},
|
||||
{"RGB24", IMGFMT_RGB24},
|
||||
{"RGB32", IMGFMT_RGB32},
|
||||
{"BGR4", IMGFMT_BGR4},
|
||||
{"BGR8", IMGFMT_BGR8},
|
||||
{"BGR15", IMGFMT_BGR15},
|
||||
{"BGR16", IMGFMT_BGR16},
|
||||
{"BGR24", IMGFMT_BGR24},
|
||||
{"BGR32", IMGFMT_BGR32},
|
||||
{"RGB1", IMGFMT_RGB1},
|
||||
{"BGR1", IMGFMT_BGR1},
|
||||
{"GBRP", IMGFMT_GBRP},
|
||||
|
||||
{"MPES", IMGFMT_MPEGPES},
|
||||
|
||||
{"VDPAU_MPEG1",IMGFMT_VDPAU_MPEG1},
|
||||
{"VDPAU_MPEG2",IMGFMT_VDPAU_MPEG2},
|
||||
{"VDPAU_H264",IMGFMT_VDPAU_H264},
|
||||
{"VDPAU_WMV3",IMGFMT_VDPAU_WMV3},
|
||||
{"VDPAU_VC1",IMGFMT_VDPAU_VC1},
|
||||
{"VDPAU_MPEG4",IMGFMT_VDPAU_MPEG4},
|
||||
|
||||
{NULL, 0}
|
||||
};
|
||||
|
||||
|
||||
static int add_to_inout(char *sfmt, char *sflags, unsigned int *outfmt,
|
||||
unsigned char *outflags)
|
||||
{
|
||||
|
@ -253,15 +181,14 @@ static int add_to_inout(char *sfmt, char *sflags, unsigned int *outfmt,
|
|||
}
|
||||
|
||||
do {
|
||||
for (j = 0; fmt_table[j].name != NULL; j++)
|
||||
if (!strncmp(sfmt, fmt_table[j].name, strlen(fmt_table[j].name)))
|
||||
break;
|
||||
if (fmt_table[j].name == NULL)
|
||||
for (j = 0; isalnum(sfmt[j]) || sfmt[j] == '_'; j++);
|
||||
unsigned int fmt = mp_imgfmt_from_name((bstr) {sfmt, j}, true);
|
||||
if (!fmt)
|
||||
goto err_out_parse_error;
|
||||
outfmt[i] = fmt_table[j].num;
|
||||
outfmt[i] = fmt;
|
||||
outflags[i] = flags;
|
||||
++i;
|
||||
sfmt+=strlen(fmt_table[j].name);
|
||||
sfmt += j;
|
||||
} while ((*(sfmt++) == ',') && --freeslots);
|
||||
|
||||
if (!freeslots)
|
||||
|
|
|
@ -25,95 +25,10 @@
|
|||
|
||||
const char *vo_format_name(int format)
|
||||
{
|
||||
const char *name = mp_imgfmt_to_name(format);
|
||||
if (name)
|
||||
return name;
|
||||
static char unknown_format[20];
|
||||
switch(format)
|
||||
{
|
||||
case IMGFMT_RGB1: return "RGB 1-bit";
|
||||
case IMGFMT_RGB4: return "RGB 4-bit";
|
||||
case IMGFMT_RG4B: return "RGB 4-bit per byte";
|
||||
case IMGFMT_RGB8: return "RGB 8-bit";
|
||||
case IMGFMT_RGB12: return "RGB 12-bit";
|
||||
case IMGFMT_RGB15: return "RGB 15-bit";
|
||||
case IMGFMT_RGB16: return "RGB 16-bit";
|
||||
case IMGFMT_RGB24: return "RGB 24-bit";
|
||||
// case IMGFMT_RGB32: return "RGB 32-bit";
|
||||
case IMGFMT_RGB48LE: return "RGB 48-bit LE";
|
||||
case IMGFMT_RGB48BE: return "RGB 48-bit BE";
|
||||
case IMGFMT_BGR1: return "BGR 1-bit";
|
||||
case IMGFMT_BGR4: return "BGR 4-bit";
|
||||
case IMGFMT_BG4B: return "BGR 4-bit per byte";
|
||||
case IMGFMT_BGR8: return "BGR 8-bit";
|
||||
case IMGFMT_BGR12: return "BGR 12-bit";
|
||||
case IMGFMT_BGR15: return "BGR 15-bit";
|
||||
case IMGFMT_BGR16: return "BGR 16-bit";
|
||||
case IMGFMT_BGR24: return "BGR 24-bit";
|
||||
// case IMGFMT_BGR32: return "BGR 32-bit";
|
||||
case IMGFMT_ABGR: return "ABGR";
|
||||
case IMGFMT_BGRA: return "BGRA";
|
||||
case IMGFMT_ARGB: return "ARGB";
|
||||
case IMGFMT_RGBA: return "RGBA";
|
||||
case IMGFMT_GBRP: return "Planar GBR 24-bit";
|
||||
case IMGFMT_YVU9: return "Planar YVU9";
|
||||
case IMGFMT_IF09: return "Planar IF09";
|
||||
case IMGFMT_YV12: return "Planar YV12";
|
||||
case IMGFMT_I420: return "Planar I420";
|
||||
case IMGFMT_IYUV: return "Planar IYUV";
|
||||
case IMGFMT_CLPL: return "Planar CLPL";
|
||||
case IMGFMT_Y800: return "Planar Y800";
|
||||
case IMGFMT_Y8: return "Planar Y8";
|
||||
case IMGFMT_420P16_LE: return "Planar 420P 16-bit little-endian";
|
||||
case IMGFMT_420P16_BE: return "Planar 420P 16-bit big-endian";
|
||||
case IMGFMT_420P10_LE: return "Planar 420P 10-bit little-endian";
|
||||
case IMGFMT_420P10_BE: return "Planar 420P 10-bit big-endian";
|
||||
case IMGFMT_420P9_LE: return "Planar 420P 9-bit little-endian";
|
||||
case IMGFMT_420P9_BE: return "Planar 420P 9-bit big-endian";
|
||||
case IMGFMT_422P16_LE: return "Planar 422P 16-bit little-endian";
|
||||
case IMGFMT_422P16_BE: return "Planar 422P 16-bit big-endian";
|
||||
case IMGFMT_422P10_LE: return "Planar 422P 10-bit little-endian";
|
||||
case IMGFMT_422P10_BE: return "Planar 422P 10-bit big-endian";
|
||||
case IMGFMT_422P9_LE: return "Planar 422P 9-bit little-endian";
|
||||
case IMGFMT_422P9_BE: return "Planar 422P 9-bit big-endian";
|
||||
case IMGFMT_444P16_LE: return "Planar 444P 16-bit little-endian";
|
||||
case IMGFMT_444P16_BE: return "Planar 444P 16-bit big-endian";
|
||||
case IMGFMT_444P10_LE: return "Planar 444P 10-bit little-endian";
|
||||
case IMGFMT_444P10_BE: return "Planar 444P 10-bit big-endian";
|
||||
case IMGFMT_444P9_LE: return "Planar 444P 9-bit little-endian";
|
||||
case IMGFMT_444P9_BE: return "Planar 444P 9-bit big-endian";
|
||||
case IMGFMT_420A: return "Planar 420P with alpha";
|
||||
case IMGFMT_444P: return "Planar 444P";
|
||||
case IMGFMT_422P: return "Planar 422P";
|
||||
case IMGFMT_411P: return "Planar 411P";
|
||||
case IMGFMT_NV12: return "Planar NV12";
|
||||
case IMGFMT_NV21: return "Planar NV21";
|
||||
case IMGFMT_HM12: return "Planar NV12 Macroblock";
|
||||
case IMGFMT_IUYV: return "Packed IUYV";
|
||||
case IMGFMT_IY41: return "Packed IY41";
|
||||
case IMGFMT_IYU1: return "Packed IYU1";
|
||||
case IMGFMT_IYU2: return "Packed IYU2";
|
||||
case IMGFMT_UYVY: return "Packed UYVY";
|
||||
case IMGFMT_UYNV: return "Packed UYNV";
|
||||
case IMGFMT_cyuv: return "Packed CYUV";
|
||||
case IMGFMT_Y422: return "Packed Y422";
|
||||
case IMGFMT_YUY2: return "Packed YUY2";
|
||||
case IMGFMT_YUNV: return "Packed YUNV";
|
||||
case IMGFMT_YVYU: return "Packed YVYU";
|
||||
case IMGFMT_Y41P: return "Packed Y41P";
|
||||
case IMGFMT_Y211: return "Packed Y211";
|
||||
case IMGFMT_Y41T: return "Packed Y41T";
|
||||
case IMGFMT_Y42T: return "Packed Y42T";
|
||||
case IMGFMT_V422: return "Packed V422";
|
||||
case IMGFMT_V655: return "Packed V655";
|
||||
case IMGFMT_CLJR: return "Packed CLJR";
|
||||
case IMGFMT_YUVP: return "Packed YUVP";
|
||||
case IMGFMT_UYVP: return "Packed UYVP";
|
||||
case IMGFMT_MPEGPES: return "Mpeg PES";
|
||||
case IMGFMT_VDPAU_MPEG1: return "MPEG1 VDPAU acceleration";
|
||||
case IMGFMT_VDPAU_MPEG2: return "MPEG2 VDPAU acceleration";
|
||||
case IMGFMT_VDPAU_H264: return "H.264 VDPAU acceleration";
|
||||
case IMGFMT_VDPAU_MPEG4: return "MPEG-4 Part 2 VDPAU acceleration";
|
||||
case IMGFMT_VDPAU_WMV3: return "WMV3 VDPAU acceleration";
|
||||
case IMGFMT_VDPAU_VC1: return "VC1 VDPAU acceleration";
|
||||
}
|
||||
snprintf(unknown_format, 20, "Unknown 0x%04x", format);
|
||||
return unknown_format;
|
||||
}
|
||||
|
@ -279,17 +194,30 @@ struct mp_imgfmt_entry mp_imgfmt_list[] = {
|
|||
{"gbrp", IMGFMT_GBRP},
|
||||
{"mjpeg", IMGFMT_MJPEG},
|
||||
{"mjpg", IMGFMT_MJPEG},
|
||||
{ NULL, 0 }
|
||||
{"mpes", IMGFMT_MPEGPES},
|
||||
{"vdpau_h264", IMGFMT_VDPAU_H264},
|
||||
{"vdpau_mpeg1", IMGFMT_VDPAU_MPEG1},
|
||||
{"vdpau_mpeg2", IMGFMT_VDPAU_MPEG2},
|
||||
{"vdpau_mpeg4", IMGFMT_VDPAU_MPEG4},
|
||||
{"vdpau_wmv3", IMGFMT_VDPAU_WMV3},
|
||||
{"vdpau_vc1", IMGFMT_VDPAU_VC1},
|
||||
{0}
|
||||
};
|
||||
|
||||
unsigned int mp_imgfmt_from_name(const char *name)
|
||||
unsigned int mp_imgfmt_from_name(bstr name, bool allow_hwaccel)
|
||||
{
|
||||
struct mp_imgfmt_entry *p = mp_imgfmt_list;
|
||||
if (!name)
|
||||
return 0;
|
||||
for(; p->name; ++p) {
|
||||
if(!strcmp(name, p->name))
|
||||
if (bstr_startswith0(name, "0x")) {
|
||||
bstr rest;
|
||||
unsigned int fmt = bstrtoll(name, &rest, 16);
|
||||
if (rest.len == 0)
|
||||
return fmt;
|
||||
}
|
||||
for(struct mp_imgfmt_entry *p = mp_imgfmt_list; p->name; ++p) {
|
||||
if(!bstrcasecmp0(name, p->name)) {
|
||||
if (!allow_hwaccel && IMGFMT_IS_HWACCEL(p->fmt))
|
||||
return 0;
|
||||
return p->fmt;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
|
||||
#include <sys/types.h>
|
||||
#include "config.h"
|
||||
#include "bstr.h"
|
||||
|
||||
/* RGB/BGR Formats */
|
||||
|
||||
|
@ -235,7 +236,7 @@ struct mp_imgfmt_entry {
|
|||
|
||||
extern struct mp_imgfmt_entry mp_imgfmt_list[];
|
||||
|
||||
unsigned int mp_imgfmt_from_name(const char *name);
|
||||
unsigned int mp_imgfmt_from_name(bstr name, bool allow_hwaccel);
|
||||
const char *mp_imgfmt_to_name(unsigned int fmt);
|
||||
|
||||
#endif /* MPLAYER_IMG_FORMAT_H */
|
||||
|
|
|
@ -112,7 +112,8 @@ static int config(struct vf_instance *vf,
|
|||
}
|
||||
|
||||
if (vf->priv->filter.out_fmt)
|
||||
vf->priv->outfmt = mp_imgfmt_from_name(vf->priv->filter.out_fmt);
|
||||
vf->priv->outfmt = mp_imgfmt_from_name(bstr0(vf->priv->filter.out_fmt),
|
||||
false);
|
||||
else {
|
||||
struct vf_dlopen_formatpair *p = vf->priv->filter.format_mapping;
|
||||
vf->priv->outfmt = 0;
|
||||
|
@ -120,7 +121,7 @@ static int config(struct vf_instance *vf,
|
|||
for (; p->from; ++p) {
|
||||
// TODO support pixel format classes in matching
|
||||
if (!strcmp(p->from, vf->priv->filter.in_fmt)) {
|
||||
vf->priv->outfmt = p->to ? mp_imgfmt_from_name(p->to) : fmt;
|
||||
vf->priv->outfmt = mp_imgfmt_from_name(bstr0(p->to), false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -261,7 +262,7 @@ static int query_format(struct vf_instance *vf, unsigned int fmt)
|
|||
for (; p->from; ++p) {
|
||||
// TODO support pixel format classes in matching
|
||||
if (!strcmp(p->from, fmtname)) {
|
||||
outfmt = p->to ? mp_imgfmt_from_name(p->to) : fmt;
|
||||
outfmt = mp_imgfmt_from_name(bstr0(p->to), false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
26
m_option.c
26
m_option.c
|
@ -918,35 +918,23 @@ const m_option_type_t m_option_type_subconfig_struct = {
|
|||
static int parse_imgfmt(const m_option_t *opt, struct bstr name,
|
||||
struct bstr param, void *dst)
|
||||
{
|
||||
uint32_t fmt = 0;
|
||||
int i;
|
||||
|
||||
if (param.len == 0)
|
||||
return M_OPT_MISSING_PARAM;
|
||||
|
||||
if (!bstrcmp0(param, "help")) {
|
||||
mp_msg(MSGT_CFGPARSER, MSGL_INFO, "Available formats:");
|
||||
for (i = 0; mp_imgfmt_list[i].name; i++)
|
||||
for (int i = 0; mp_imgfmt_list[i].name; i++)
|
||||
mp_msg(MSGT_CFGPARSER, MSGL_INFO, " %s", mp_imgfmt_list[i].name);
|
||||
mp_msg(MSGT_CFGPARSER, MSGL_INFO, "\n");
|
||||
return M_OPT_EXIT - 1;
|
||||
}
|
||||
|
||||
if (bstr_startswith0(param, "0x"))
|
||||
fmt = bstrtoll(param, NULL, 16);
|
||||
else {
|
||||
for (i = 0; mp_imgfmt_list[i].name; i++) {
|
||||
if (!bstrcasecmp0(param, mp_imgfmt_list[i].name)) {
|
||||
fmt = mp_imgfmt_list[i].fmt;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!mp_imgfmt_list[i].name) {
|
||||
mp_msg(MSGT_CFGPARSER, MSGL_ERR,
|
||||
"Option %.*s: unknown format name: '%.*s'\n",
|
||||
BSTR_P(name), BSTR_P(param));
|
||||
return M_OPT_INVALID;
|
||||
}
|
||||
unsigned int fmt = mp_imgfmt_from_name(param, false);
|
||||
if (!fmt) {
|
||||
mp_msg(MSGT_CFGPARSER, MSGL_ERR,
|
||||
"Option %.*s: unknown format name: '%.*s'\n",
|
||||
BSTR_P(name), BSTR_P(param));
|
||||
return M_OPT_INVALID;
|
||||
}
|
||||
|
||||
if (dst)
|
||||
|
|
Loading…
Reference in New Issue