summaryrefslogtreecommitdiffstats
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
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.
-rw-r--r--video/filter/vf_dlopen.c5
-rw-r--r--video/img_format.c38
-rw-r--r--video/img_format.h4
3 files changed, 27 insertions, 20 deletions
diff --git a/video/filter/vf_dlopen.c b/video/filter/vf_dlopen.c
index 1646d3fbcf..9f9cd20318 100644
--- a/video/filter/vf_dlopen.c
+++ b/video/filter/vf_dlopen.c
@@ -102,7 +102,7 @@ static int config(struct vf_instance *vf,
vf->priv->filter.in_height = height;
vf->priv->filter.in_d_width = d_width;
vf->priv->filter.in_d_height = d_height;
- vf->priv->filter.in_fmt = mp_imgfmt_to_name(fmt);
+ vf->priv->filter.in_fmt = talloc_strdup(vf, mp_imgfmt_to_name(fmt));
vf->priv->filter.out_width = width;
vf->priv->filter.out_height = height;
vf->priv->filter.out_d_width = d_width;
@@ -142,7 +142,8 @@ static int config(struct vf_instance *vf,
}
} else
vf->priv->outfmt = fmt;
- vf->priv->filter.out_fmt = mp_imgfmt_to_name(vf->priv->outfmt);
+ vf->priv->filter.out_fmt =
+ talloc_strdup(vf, mp_imgfmt_to_name(vf->priv->outfmt));
}
if (!vf->priv->outfmt) {
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,
};
diff --git a/video/img_format.h b/video/img_format.h
index 9277b0698c..64662aba08 100644
--- a/video/img_format.h
+++ b/video/img_format.h
@@ -71,7 +71,6 @@
struct mp_imgfmt_desc {
int id; // IMGFMT_*
int avformat; // AV_PIX_FMT_* (or AV_PIX_FMT_NONE)
- const char *name; // e.g. "420p16"
int flags; // MP_IMGFLAG_* bitfield
int8_t num_planes;
int8_t chroma_xs, chroma_ys; // chroma shift (i.e. log2 of chroma pixel size)
@@ -335,7 +334,8 @@ static inline bool IMGFMT_IS_RGB(int fmt)
(fmt) == IMGFMT_VAAPI || (fmt) == IMGFMT_VDA)
int mp_imgfmt_from_name(bstr name, bool allow_hwaccel);
-const char *mp_imgfmt_to_name(int fmt);
+char *mp_imgfmt_to_name_buf(char *buf, size_t buf_size, int fmt);
+#define mp_imgfmt_to_name(fmt) mp_imgfmt_to_name_buf((char[16]){0}, 16, (fmt))
char **mp_imgfmt_name_list(void);