summaryrefslogtreecommitdiffstats
path: root/video/img_format.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-06-14 09:58:48 +0200
committerwm4 <wm4@nowhere>2014-06-14 09:58:48 +0200
commit6ab72f976035f094406584795f680d2de8761c2b (patch)
treea0a78435bd651c01542d510477c8f4d07d20e9b0 /video/img_format.c
parent6842d4bde5977a7bd76c4492e5a27e4b716fd5ec (diff)
downloadmpv-6ab72f976035f094406584795f680d2de8761c2b.tar.bz2
mpv-6ab72f976035f094406584795f680d2de8761c2b.tar.xz
video: automatically strip "le" and "be" suffix from pixle format names
These suffixes are annoying when they're redundant, so strip them automatically. On little endian machines, always strip the "le" suffix, and on big endian machines vice versa (although I don't think anyone ever tried to run mpv on a big endian machine). Since pixel format strings are returned by a certain function and we can't just change static strings, use a trick to pass a stack buffer transparently. But this also means the string can't be permanently stored by the caller, so vf_dlopen.c has to be updated. There seems to be no other case where this is done, though.
Diffstat (limited to 'video/img_format.c')
-rw-r--r--video/img_format.c38
1 files changed, 22 insertions, 16 deletions
diff --git a/video/img_format.c b/video/img_format.c
index 01bf2b2b87..3802e1b58e 100644
--- a/video/img_format.c
+++ b/video/img_format.c
@@ -44,10 +44,6 @@ struct mp_imgfmt_entry {
static const struct mp_imgfmt_entry mp_imgfmt_list[] = {
// not in ffmpeg
FMT("vdpau_output", IMGFMT_VDPAU_OUTPUT)
- // these formats are pretty common, and the "le"/"be" suffixes enforced
- // by FFmpeg are annoying
- FMT("yuv420p10", IMGFMT_420P10)
- FMT("yuv420p16", IMGFMT_420P16)
// these names are weirdly different from FFmpeg's
FMT_ENDIAN("rgb12", IMGFMT_RGB12)
FMT_ENDIAN("rgb15", IMGFMT_RGB15)
@@ -66,6 +62,7 @@ static const struct mp_imgfmt_entry mp_imgfmt_list[] = {
FMT("vda", IMGFMT_VDA)
FMT("vaapi", IMGFMT_VAAPI)
// names below this are not preferred over the FFmpeg names
+ // the "none" entry makes mp_imgfmt_to_name prefer FFmpeg names
FMT("none", 0)
// endian-specific aliases (not in FFmpeg)
FMT("rgb32", IMGFMT_RGB32)
@@ -74,8 +71,8 @@ static const struct mp_imgfmt_entry mp_imgfmt_list[] = {
FMT("y8", IMGFMT_Y8)
FMT("420p", IMGFMT_420P)
FMT("yv12", IMGFMT_420P)
- FMT_ENDIAN("420p16", IMGFMT_420P16)
- FMT_ENDIAN("420p10", IMGFMT_420P10)
+ FMT("420p16", IMGFMT_420P16)
+ FMT("420p10", IMGFMT_420P10)
FMT("444p", IMGFMT_444P)
FMT("444p9", IMGFMT_444P9)
FMT("444p10", IMGFMT_444P10)
@@ -93,7 +90,7 @@ char **mp_imgfmt_name_list(void)
for (int n = IMGFMT_START; n < IMGFMT_END; n++) {
const char *name = mp_imgfmt_to_name(n);
if (strcmp(name, "none") != 0 && strcmp(name, "unknown") != 0)
- list[num++] = (char *)name;
+ list[num++] = talloc_strdup(list, name);
}
return list;
}
@@ -117,17 +114,28 @@ int mp_imgfmt_from_name(bstr name, bool allow_hwaccel)
return img_fmt;
}
-const char *mp_imgfmt_to_name(int fmt)
+char *mp_imgfmt_to_name_buf(char *buf, size_t buf_size, int fmt)
{
+ const char *name = NULL;
const struct mp_imgfmt_entry *p = mp_imgfmt_list;
for (; p->fmt; p++) {
- if (p->name && p->fmt == fmt)
- return p->name;
+ if (p->name && p->fmt == fmt) {
+ name = p->name;
+ break;
+ }
+ }
+ if (!name) {
+ const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(imgfmt2pixfmt(fmt));
+ if (pixdesc)
+ name = pixdesc->name;
}
- const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(imgfmt2pixfmt(fmt));
- if (pixdesc && pixdesc->name)
- return pixdesc->name;
- return "unknown";
+ if (!name)
+ name = "unknown";
+ snprintf(buf, buf_size, "%s", name);
+ int len = strlen(buf);
+ if (len > 2 && buf[len - 2] == MP_SELECT_LE_BE('l', 'b') && buf[len - 1] == 'e')
+ buf[len - 2] = '\0';
+ return buf;
}
static struct mp_imgfmt_desc mp_only_imgfmt_desc(int mpfmt)
@@ -137,7 +145,6 @@ static struct mp_imgfmt_desc mp_only_imgfmt_desc(int mpfmt)
return (struct mp_imgfmt_desc) {
.id = mpfmt,
.avformat = AV_PIX_FMT_NONE,
- .name = mp_imgfmt_to_name(mpfmt),
.flags = MP_IMGFLAG_BE | MP_IMGFLAG_LE | MP_IMGFLAG_RGB,
};
}
@@ -154,7 +161,6 @@ struct mp_imgfmt_desc mp_imgfmt_get_desc(int mpfmt)
struct mp_imgfmt_desc desc = {
.id = mpfmt,
.avformat = fmt,
- .name = mp_imgfmt_to_name(mpfmt),
.chroma_xs = pd->log2_chroma_w,
.chroma_ys = pd->log2_chroma_h,
};