summaryrefslogtreecommitdiffstats
path: root/video/out/vo_xv.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2012-12-23 20:03:30 +0100
committerwm4 <wm4@nowhere>2013-01-13 20:04:11 +0100
commit8751a0e261c0c7150874f78b23c7f1d3539883b5 (patch)
treebe72a06e1d1470cf968835e432c19f6d3a0e49b2 /video/out/vo_xv.c
parent0c5311f17cb9078f0ddde7c41cad61d00aea4a94 (diff)
downloadmpv-8751a0e261c0c7150874f78b23c7f1d3539883b5.tar.bz2
mpv-8751a0e261c0c7150874f78b23c7f1d3539883b5.tar.xz
video: decouple internal pixel formats from FourCCs
mplayer's video chain traditionally used FourCCs for pixel formats. For example, it used IMGFMT_YV12 for 4:2:0 YUV, which was defined to the string 'YV12' interpreted as unsigned int. Additionally, it used to encode information into the numeric values of some formats. The RGB formats had their bit depth and endian encoded into the least significant byte. Extended planar formats (420P10 etc.) had chroma shift, endian, and component bit depth encoded. (This has been removed in recent commits.) Replace the FourCC mess with a simple enum. Remove all the redundant formats like YV12/I420/IYUV. Replace some image format names by something more intuitive, most importantly IMGFMT_YV12 -> IMGFMT_420P. Add img_fourcc.h, which contains the old IDs for code that actually uses FourCCs. Change the way demuxers, that output raw video, identify the video format: they set either MP_FOURCC_RAWVIDEO or MP_FOURCC_IMGFMT to request the rawvideo decoder, and sh_video->imgfmt specifies the pixel format. Like the previous hack, this is supposed to avoid the need for a complete codecs.cfg entry per format, or other lookup tables. (Note that the RGB raw video FourCCs mostly rely on ffmpeg's mappings for NUT raw video, but this is still considered better than adding a raw video decoder - even if trivial, it would be full of annoying lookup tables.) The TV code has not been tested. Some corrective changes regarding endian and other image format flags creep in.
Diffstat (limited to 'video/out/vo_xv.c')
-rw-r--r--video/out/vo_xv.c36
1 files changed, 30 insertions, 6 deletions
diff --git a/video/out/vo_xv.c b/video/out/vo_xv.c
index d5225cd7cd..dc7f805e4b 100644
--- a/video/out/vo_xv.c
+++ b/video/out/vo_xv.c
@@ -47,6 +47,7 @@
#include "vo.h"
#include "video/vfcap.h"
#include "video/mp_image.h"
+#include "video/img_fourcc.h"
#include "x11_common.h"
#include "video/memcpy_pic.h"
#include "sub/sub.h"
@@ -88,10 +89,31 @@ struct xvctx {
#endif
};
+struct fmt_entry {
+ int imgfmt;
+ int fourcc;
+};
+static const struct fmt_entry fmt_table[] = {
+ {IMGFMT_420P, MP_FOURCC_YV12},
+ {IMGFMT_420P, MP_FOURCC_I420},
+ {IMGFMT_YUYV, MP_FOURCC_YUY2},
+ {IMGFMT_UYVY, MP_FOURCC_UYVY},
+ {0}
+};
+
static void allocate_xvimage(struct vo *, int);
static void deallocate_xvimage(struct vo *vo, int foo);
static struct mp_image get_xv_buffer(struct vo *vo, int buf_index);
+static int find_xv_format(int imgfmt)
+{
+ for (int n = 0; fmt_table[n].imgfmt; n++) {
+ if (fmt_table[n].imgfmt == imgfmt)
+ return fmt_table[n].fourcc;
+ }
+ return 0;
+}
+
static void read_xv_csp(struct vo *vo)
{
struct xvctx *ctx = vo->priv;
@@ -158,7 +180,7 @@ static int config(struct vo *vo, uint32_t width, uint32_t height,
mp_msg(MSGT_VO, MSGL_V, "Xvideo image format: 0x%x (%4.4s) %s\n",
ctx->fo[i].id, (char *) &ctx->fo[i].id,
(ctx->fo[i].format == XvPacked) ? "packed" : "planar");
- if (ctx->fo[i].id == format)
+ if (ctx->fo[i].id == find_xv_format(format))
ctx->xv_format = ctx->fo[i].id;
}
if (!ctx->xv_format)
@@ -320,7 +342,7 @@ static struct mp_image get_xv_buffer(struct vo *vo, int buf_index)
mp_image_set_size(&img, ctx->image_width, ctx->image_height);
mp_image_setfmt(&img, ctx->image_format);
- bool swapuv = ctx->image_format == IMGFMT_YV12;
+ bool swapuv = ctx->xv_format == MP_FOURCC_YV12;
for (int n = 0; n < img.num_planes; n++) {
int sn = n > 0 && swapuv ? (n == 1 ? 2 : 1) : n;
img.planes[n] = xv_image->data + xv_image->offsets[sn];
@@ -417,10 +439,12 @@ static int query_format(struct vo *vo, uint32_t format)
uint32_t i;
int flag = VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW | VFCAP_OSD;
- /* check image formats */
- for (i = 0; i < ctx->formats; i++) {
- if (ctx->fo[i].id == format)
- return flag; //xv_format = fo[i].id;
+ int fourcc = find_xv_format(format);
+ if (fourcc) {
+ for (i = 0; i < ctx->formats; i++) {
+ if (ctx->fo[i].id == fourcc)
+ return flag;
+ }
}
return 0;
}