summaryrefslogtreecommitdiffstats
path: root/stream
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 /stream
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 'stream')
-rw-r--r--stream/tv.c45
-rw-r--r--stream/tvi_bsdbt848.c6
-rw-r--r--stream/tvi_def.h12
-rw-r--r--stream/tvi_dummy.c7
-rw-r--r--stream/tvi_v4l2.c98
5 files changed, 84 insertions, 84 deletions
diff --git a/stream/tv.c b/stream/tv.c
index e5e64dd636..a9bc535cee 100644
--- a/stream/tv.c
+++ b/stream/tv.c
@@ -42,7 +42,7 @@
#include "demux/stheader.h"
#include "audio/format.h"
-#include "video/img_format.h"
+#include "video/img_fourcc.h"
#include "libavutil/avstring.h"
#include "osdep/timer.h"
@@ -409,14 +409,14 @@ static int open_tv(tvi_handle_t *tvh)
int i;
const tvi_functions_t *funcs = tvh->functions;
static const int tv_fmt_list[] = {
- IMGFMT_YV12,
- IMGFMT_I420,
- IMGFMT_UYVY,
- IMGFMT_YUY2,
- IMGFMT_RGB32,
- IMGFMT_RGB24,
- IMGFMT_RGB16,
- IMGFMT_RGB15
+ MP_FOURCC_YV12,
+ MP_FOURCC_I420,
+ MP_FOURCC_UYVY,
+ MP_FOURCC_YUY2,
+ MP_FOURCC_RGB32,
+ MP_FOURCC_RGB24,
+ MP_FOURCC_RGB16,
+ MP_FOURCC_RGB15
};
if (funcs->control(tvh->priv, TVI_CONTROL_IS_VIDEO, 0) != TVI_CONTROL_TRUE)
@@ -437,16 +437,16 @@ static int open_tv(tvi_handle_t *tvh)
{
switch(tvh->tv_param->outfmt)
{
- case IMGFMT_YV12:
- case IMGFMT_I420:
- case IMGFMT_UYVY:
- case IMGFMT_YUY2:
- case IMGFMT_RGB32:
- case IMGFMT_RGB24:
- case IMGFMT_BGR32:
- case IMGFMT_BGR24:
- case IMGFMT_BGR16:
- case IMGFMT_BGR15:
+ case MP_FOURCC_YV12:
+ case MP_FOURCC_I420:
+ case MP_FOURCC_UYVY:
+ case MP_FOURCC_YUY2:
+ case MP_FOURCC_RGB32:
+ case MP_FOURCC_RGB24:
+ case MP_FOURCC_BGR32:
+ case MP_FOURCC_BGR24:
+ case MP_FOURCC_BGR16:
+ case MP_FOURCC_BGR15:
break;
default:
mp_tmsg(MSGT_TV, MSGL_ERR,
@@ -715,9 +715,10 @@ static demuxer_t* demux_open_tv(demuxer_t *demuxer)
sh_video = new_sh_video(demuxer, 0);
/* get IMAGE FORMAT */
- funcs->control(tvh->priv, TVI_CONTROL_VID_GET_FORMAT, &sh_video->format);
-// if (IMGFMT_IS_RGB(sh_video->format) || IMGFMT_IS_BGR(sh_video->format))
-// sh_video->format = 0x0;
+ int fourcc;
+ funcs->control(tvh->priv, TVI_CONTROL_VID_GET_FORMAT, &fourcc);
+ sh_video->format = MP_FOURCC_RAWVIDEO;
+ sh_video->imgfmt = fourcc;
/* set FPS and FRAMETIME */
diff --git a/stream/tvi_bsdbt848.c b/stream/tvi_bsdbt848.c
index 19d68dd899..4f101ee74f 100644
--- a/stream/tvi_bsdbt848.c
+++ b/stream/tvi_bsdbt848.c
@@ -79,7 +79,7 @@
#endif
#include "audio/format.h"
-#include "video/img_format.h"
+#include "video/img_fourcc.h"
#include "tv.h"
#include "core/mp_msg.h"
@@ -450,14 +450,14 @@ static int control(priv_t *priv, int cmd, void *arg)
}
case TVI_CONTROL_VID_GET_FORMAT:
- *(int *)arg = IMGFMT_UYVY;
+ *(int *)arg = MP_FOURCC_UYVY;
return TVI_CONTROL_TRUE;
case TVI_CONTROL_VID_SET_FORMAT:
{
int req_fmt = *(int *)arg;
- if(req_fmt != IMGFMT_UYVY) return TVI_CONTROL_FALSE;
+ if(req_fmt != MP_FOURCC_UYVY) return TVI_CONTROL_FALSE;
return TVI_CONTROL_TRUE;
}
diff --git a/stream/tvi_def.h b/stream/tvi_def.h
index 367f2adb35..959237aa04 100644
--- a/stream/tvi_def.h
+++ b/stream/tvi_def.h
@@ -21,7 +21,7 @@
#include <stdlib.h> /* malloc */
#include <string.h> /* memset */
-#include "video/img_format.h"
+#include "video/img_fourcc.h"
#include "tv.h"
static int init(priv_t *priv);
@@ -54,17 +54,17 @@ static inline void fill_blank_frame(char* buffer,int len,int fmt){
// RGB(0,0,255) <-> YVU(41,110,240)
switch(fmt){
- case IMGFMT_YV12:
+ case MP_FOURCC_YV12:
memset(buffer, 41,4*len/6); //Y
memset(buffer+4*len/6, 110,len/6);//V
memset(buffer+5*len/6, 240,len/6);//U
break;
- case IMGFMT_I420:
+ case MP_FOURCC_I420:
memset(buffer, 41,4*len/6); //Y
memset(buffer+4*len/6, 240,len/6);//U
memset(buffer+5*len/6, 110,len/6);//V
break;
- case IMGFMT_UYVY:
+ case MP_FOURCC_UYVY:
for(i=0;i<len;i+=4){
buffer[i]=0xFF;
buffer[i+1]=0;
@@ -72,7 +72,7 @@ static inline void fill_blank_frame(char* buffer,int len,int fmt){
buffer[i+3]=0;
}
break;
- case IMGFMT_YUY2:
+ case MP_FOURCC_YUY2:
for(i=0;i<len;i+=4){
buffer[i]=0;
buffer[i+1]=0xFF;
@@ -80,7 +80,7 @@ static inline void fill_blank_frame(char* buffer,int len,int fmt){
buffer[i+3]=0;
}
break;
- case IMGFMT_MJPEG:
+ case MP_FOURCC_MJPEG:
/*
This is compressed format. I don't know yet how to fill such frame with blue color.
Keeping frame unchanged.
diff --git a/stream/tvi_dummy.c b/stream/tvi_dummy.c
index 48a745450e..c0bf8bba32 100644
--- a/stream/tvi_dummy.c
+++ b/stream/tvi_dummy.c
@@ -21,7 +21,7 @@
#include "config.h"
#include <stdio.h>
-#include "video/img_format.h"
+#include "video/img_fourcc.h"
#include "tv.h"
static tvi_handle_t *tvi_init_dummy(tv_param_t* tv_param);
@@ -74,14 +74,13 @@ static int control(priv_t *priv, int cmd, void *arg)
case TVI_CONTROL_IS_VIDEO:
return TVI_CONTROL_TRUE;
case TVI_CONTROL_VID_GET_FORMAT:
-// *(int *)arg = IMGFMT_YV12;
- *(int *)arg = IMGFMT_YV12;
+ *(int *)arg = MP_FOURCC_YV12;
return TVI_CONTROL_TRUE;
case TVI_CONTROL_VID_SET_FORMAT:
{
// int req_fmt = *(int *)arg;
int req_fmt = *(int *)arg;
- if (req_fmt != IMGFMT_YV12)
+ if (req_fmt != MP_FOURCC_YV12)
return TVI_CONTROL_FALSE;
return TVI_CONTROL_TRUE;
}
diff --git a/stream/tvi_v4l2.c b/stream/tvi_v4l2.c
index 14313d0966..abe455d8bf 100644
--- a/stream/tvi_v4l2.c
+++ b/stream/tvi_v4l2.c
@@ -56,7 +56,7 @@ known issues:
#include <linux/videodev2.h>
#endif
#include "core/mp_msg.h"
-#include "video/img_format.h"
+#include "video/img_fourcc.h"
#include "audio/format.h"
#include "tv.h"
#include "audio_in.h"
@@ -180,27 +180,27 @@ static void *video_grabber(void *data);
Only few of the fourccs are the same in v4l2 and mplayer:
- IMGFMT_YVU9 == V4L2_PIX_FMT_YVU410
- IMGFMT_YV12 == V4L2_PIX_FMT_YVU420
- IMGFMT_NV12 == V4L2_PIX_FMT_NV12
- IMGFMT_422P == V4L2_PIX_FMT_YUV422P
- IMGFMT_411P == V4L2_PIX_FMT_YUV411P
- IMGFMT_UYVY == V4L2_PIX_FMT_UYVY
- IMGFMT_Y41P == V4L2_PIX_FMT_Y41P
+ MP_FOURCC_YVU9 == V4L2_PIX_FMT_YVU410
+ MP_FOURCC_YV12 == V4L2_PIX_FMT_YVU420
+ MP_FOURCC_NV12 == V4L2_PIX_FMT_NV12
+ MP_FOURCC_422P == V4L2_PIX_FMT_YUV422P
+ MP_FOURCC_411P == V4L2_PIX_FMT_YUV411P
+ MP_FOURCC_UYVY == V4L2_PIX_FMT_UYVY
+ MP_FOURCC_Y41P == V4L2_PIX_FMT_Y41P
This may be an useful translation table for some others:
- IMGFMT_RGB8 == V4L2_PIX_FMT_RGB332
- IMGFMT_BGR15 == V4L2_PIX_FMT_RGB555
- IMGFMT_BGR16 == V4L2_PIX_FMT_RGB565
- IMGFMT_RGB24 == V4L2_PIX_FMT_RGB24
- IMGFMT_RGB32 == V4L2_PIX_FMT_RGB32
- IMGFMT_BGR24 == V4L2_PIX_FMT_BGR24
- IMGFMT_BGR32 == V4L2_PIX_FMT_BGR32
- IMGFMT_Y800 == V4L2_PIX_FMT_GREY
- IMGFMT_IF09 == V4L2_PIX_FMT_YUV410
- IMGFMT_I420 == V4L2_PIX_FMT_YUV420
- IMGFMT_YUY2 == V4L2_PIX_FMT_YUYV
+ MP_FOURCC_RGB8 == V4L2_PIX_FMT_RGB332
+ MP_FOURCC_BGR15 == V4L2_PIX_FMT_RGB555
+ MP_FOURCC_BGR16 == V4L2_PIX_FMT_RGB565
+ MP_FOURCC_RGB24 == V4L2_PIX_FMT_RGB24
+ MP_FOURCC_RGB32 == V4L2_PIX_FMT_RGB32
+ MP_FOURCC_BGR24 == V4L2_PIX_FMT_BGR24
+ MP_FOURCC_BGR32 == V4L2_PIX_FMT_BGR32
+ MP_FOURCC_Y800 == V4L2_PIX_FMT_GREY
+ MP_FOURCC_YUV9 == V4L2_PIX_FMT_YUV410
+ MP_FOURCC_I420 == V4L2_PIX_FMT_YUV420
+ MP_FOURCC_YUY2 == V4L2_PIX_FMT_YUYV
\**********************************************************************/
@@ -210,20 +210,20 @@ static void *video_grabber(void *data);
static int fcc_mp2vl(int fcc)
{
switch (fcc) {
- case IMGFMT_RGB8: return V4L2_PIX_FMT_RGB332;
- case IMGFMT_BGR15: return V4L2_PIX_FMT_RGB555;
- case IMGFMT_BGR16: return V4L2_PIX_FMT_RGB565;
- case IMGFMT_RGB24: return V4L2_PIX_FMT_RGB24;
- case IMGFMT_RGB32: return V4L2_PIX_FMT_RGB32;
- case IMGFMT_BGR24: return V4L2_PIX_FMT_BGR24;
- case IMGFMT_BGR32: return V4L2_PIX_FMT_BGR32;
- case IMGFMT_Y800: return V4L2_PIX_FMT_GREY;
- case IMGFMT_IF09: return V4L2_PIX_FMT_YUV410;
- case IMGFMT_I420: return V4L2_PIX_FMT_YUV420;
- case IMGFMT_YUY2: return V4L2_PIX_FMT_YUYV;
- case IMGFMT_YV12: return V4L2_PIX_FMT_YVU420;
- case IMGFMT_UYVY: return V4L2_PIX_FMT_UYVY;
- case IMGFMT_MJPEG: return V4L2_PIX_FMT_MJPEG;
+ case MP_FOURCC_RGB8: return V4L2_PIX_FMT_RGB332;
+ case MP_FOURCC_BGR15: return V4L2_PIX_FMT_RGB555;
+ case MP_FOURCC_BGR16: return V4L2_PIX_FMT_RGB565;
+ case MP_FOURCC_RGB24: return V4L2_PIX_FMT_RGB24;
+ case MP_FOURCC_RGB32: return V4L2_PIX_FMT_RGB32;
+ case MP_FOURCC_BGR24: return V4L2_PIX_FMT_BGR24;
+ case MP_FOURCC_BGR32: return V4L2_PIX_FMT_BGR32;
+ case MP_FOURCC_Y800: return V4L2_PIX_FMT_GREY;
+ case MP_FOURCC_YUV9: return V4L2_PIX_FMT_YUV410;
+ case MP_FOURCC_I420: return V4L2_PIX_FMT_YUV420;
+ case MP_FOURCC_YUY2: return V4L2_PIX_FMT_YUYV;
+ case MP_FOURCC_YV12: return V4L2_PIX_FMT_YVU420;
+ case MP_FOURCC_UYVY: return V4L2_PIX_FMT_UYVY;
+ case MP_FOURCC_MJPEG: return V4L2_PIX_FMT_MJPEG;
}
return fcc;
}
@@ -234,20 +234,20 @@ static int fcc_mp2vl(int fcc)
static int fcc_vl2mp(int fcc)
{
switch (fcc) {
- case V4L2_PIX_FMT_RGB332: return IMGFMT_RGB8;
- case V4L2_PIX_FMT_RGB555: return IMGFMT_BGR15;
- case V4L2_PIX_FMT_RGB565: return IMGFMT_BGR16;
- case V4L2_PIX_FMT_RGB24: return IMGFMT_RGB24;
- case V4L2_PIX_FMT_RGB32: return IMGFMT_RGB32;
- case V4L2_PIX_FMT_BGR24: return IMGFMT_BGR24;
- case V4L2_PIX_FMT_BGR32: return IMGFMT_BGR32;
- case V4L2_PIX_FMT_GREY: return IMGFMT_Y800;
- case V4L2_PIX_FMT_YUV410: return IMGFMT_IF09;
- case V4L2_PIX_FMT_YUV420: return IMGFMT_I420;
- case V4L2_PIX_FMT_YVU420: return IMGFMT_YV12;
- case V4L2_PIX_FMT_YUYV: return IMGFMT_YUY2;
- case V4L2_PIX_FMT_UYVY: return IMGFMT_UYVY;
- case V4L2_PIX_FMT_MJPEG: return IMGFMT_MJPEG;
+ case V4L2_PIX_FMT_RGB332: return MP_FOURCC_RGB8;
+ case V4L2_PIX_FMT_RGB555: return MP_FOURCC_BGR15;
+ case V4L2_PIX_FMT_RGB565: return MP_FOURCC_BGR16;
+ case V4L2_PIX_FMT_RGB24: return MP_FOURCC_RGB24;
+ case V4L2_PIX_FMT_RGB32: return MP_FOURCC_RGB32;
+ case V4L2_PIX_FMT_BGR24: return MP_FOURCC_BGR24;
+ case V4L2_PIX_FMT_BGR32: return MP_FOURCC_BGR32;
+ case V4L2_PIX_FMT_GREY: return MP_FOURCC_Y800;
+ case V4L2_PIX_FMT_YUV410: return MP_FOURCC_YUV9;
+ case V4L2_PIX_FMT_YUV420: return MP_FOURCC_I420;
+ case V4L2_PIX_FMT_YVU420: return MP_FOURCC_YV12;
+ case V4L2_PIX_FMT_YUYV: return MP_FOURCC_YUY2;
+ case V4L2_PIX_FMT_UYVY: return MP_FOURCC_UYVY;
+ case V4L2_PIX_FMT_MJPEG: return MP_FOURCC_MJPEG;
}
return fcc;
}
@@ -1252,9 +1252,9 @@ static int init(priv_t *priv)
if (ioctl(priv->video_fd, VIDIOC_ENUM_FMT, &fmtdesc) < 0) {
break;
}
- mp_msg(MSGT_TV, MSGL_V, " Format %-6s (%2d bits, %s): %s\n",
+ mp_msg(MSGT_TV, MSGL_V, " Format %-6s (%2d bits, %s)\n",
pixfmt2name(fmtdesc.pixelformat), pixfmt2depth(fmtdesc.pixelformat),
- fmtdesc.description, vo_format_name(fcc_vl2mp(fmtdesc.pixelformat)));
+ fmtdesc.description);
}
mp_msg(MSGT_TV, MSGL_INFO, " Current format: %s\n",
pixfmt2name(priv->format.fmt.pix.pixelformat));