diff options
52 files changed, 695 insertions, 695 deletions
diff --git a/DOCS/man/en/options.rst b/DOCS/man/en/options.rst index 936f3b3293..c629d35046 100644 --- a/DOCS/man/en/options.rst +++ b/DOCS/man/en/options.rst @@ -1605,10 +1605,11 @@ :sqcif|qcif|cif|4cif|pal|ntsc: set standard image size :w=<value>: image width in pixels :h=<value>: image height in pixels - :i420|yv12|yuy2|y8: set colorspace :format=<value>: colorspace (fourcc) in hex or string - constant. Use ``--rawvideo=format=help`` - for a list of possible strings. + constant. + :mp-format=<value>: colorspace by internal video format + Use ``--rawvideo=mp-format=help`` + for a list of possible formats. :size=<value>: frame size in Bytes *EXAMPLE*: diff --git a/core/cfg-mplayer.h b/core/cfg-mplayer.h index 9627a25140..0aef77ae70 100644 --- a/core/cfg-mplayer.h +++ b/core/cfg-mplayer.h @@ -107,7 +107,7 @@ const m_option_t tvopts_conf[]={ {"width", &stream_tv_defaults.width, CONF_TYPE_INT, 0, 0, 4096, NULL}, {"height", &stream_tv_defaults.height, CONF_TYPE_INT, 0, 0, 4096, NULL}, {"input", &stream_tv_defaults.input, CONF_TYPE_INT, 0, 0, 20, NULL}, - {"outfmt", &stream_tv_defaults.outfmt, CONF_TYPE_IMGFMT, 0, 0, 0, NULL}, + {"outfmt", &stream_tv_defaults.outfmt, CONF_TYPE_FOURCC, 0, 0, 0, NULL}, {"fps", &stream_tv_defaults.fps, CONF_TYPE_FLOAT, 0, 0, 100.0, NULL}, {"channels", &stream_tv_defaults.channels, CONF_TYPE_STRING_LIST, 0, 0, 0, NULL}, {"brightness", &stream_tv_defaults.brightness, CONF_TYPE_INT, CONF_RANGE, -100, 100, NULL}, diff --git a/core/m_option.c b/core/m_option.c index 7ea25c25b0..82f6265124 100644 --- a/core/m_option.c +++ b/core/m_option.c @@ -1203,6 +1203,41 @@ const m_option_type_t m_option_type_imgfmt = { .copy = copy_opt, }; +static int parse_fourcc(const m_option_t *opt, struct bstr name, + struct bstr param, void *dst) +{ + if (param.len == 0) + return M_OPT_MISSING_PARAM; + + unsigned int value; + + if (param.len == 4) { + uint8_t *s = param.start; + value = s[0] | (s[1] << 8) | (s[2] << 16) | (s[3] << 24); + } else { + bstr rest; + value = bstrtoll(param, &rest, 16); + if (rest.len != 0) { + mp_msg(MSGT_CFGPARSER, MSGL_ERR, + "Option %.*s: invalid FourCC: '%.*s'\n", + BSTR_P(name), BSTR_P(param)); + return M_OPT_INVALID; + } + } + + if (dst) + *((unsigned int *)dst) = value; + + return 1; +} + +const m_option_type_t m_option_type_fourcc = { + .name = "FourCC", + .size = sizeof(unsigned int), + .parse = parse_fourcc, + .copy = copy_opt, +}; + #include "audio/format.h" static int parse_afmt(const m_option_t *opt, struct bstr name, diff --git a/core/m_option.h b/core/m_option.h index 20bcfba1c2..f6c346521a 100644 --- a/core/m_option.h +++ b/core/m_option.h @@ -53,6 +53,7 @@ extern const m_option_type_t m_option_type_print_func_param; extern const m_option_type_t m_option_type_subconfig; extern const m_option_type_t m_option_type_subconfig_struct; extern const m_option_type_t m_option_type_imgfmt; +extern const m_option_type_t m_option_type_fourcc; extern const m_option_type_t m_option_type_afmt; extern const m_option_type_t m_option_type_color; @@ -177,6 +178,7 @@ struct m_sub_options { #define CONF_TYPE_SUBCONFIG (&m_option_type_subconfig) #define CONF_TYPE_STRING_LIST (&m_option_type_string_list) #define CONF_TYPE_IMGFMT (&m_option_type_imgfmt) +#define CONF_TYPE_FOURCC (&m_option_type_fourcc) #define CONF_TYPE_AFMT (&m_option_type_afmt) #define CONF_TYPE_SPAN (&m_option_type_span) #define CONF_TYPE_OBJ_SETTINGS_LIST (&m_option_type_obj_settings_list) @@ -198,6 +200,7 @@ union m_option_value { char *string; char **string_list; int imgfmt; + unsigned int fourcc; int afmt; m_span_t span; m_obj_settings_t *obj_settings_list; diff --git a/core/mp_common.h b/core/mp_common.h index 184cea2a32..0ee14ab484 100644 --- a/core/mp_common.h +++ b/core/mp_common.h @@ -28,6 +28,9 @@ // both int64_t and double should be able to represent this exactly #define MP_NOPTS_VALUE (-1LL<<63) +#define MP_CONCAT_(a, b) a ## b +#define MP_CONCAT(a, b) MP_CONCAT_(a, b) + #define ROUND(x) ((int)((x) < 0 ? (x) - 0.5 : (x) + 0.5)) extern const char *mplayer_version; diff --git a/demux/demux_mng.c b/demux/demux_mng.c index 1d21d9d218..74f633d64e 100644 --- a/demux/demux_mng.c +++ b/demux/demux_mng.c @@ -31,7 +31,7 @@ #include "stream/stream.h" #include "demux.h" #include "stheader.h" -#include "video/img_format.h" +#include "video/img_fourcc.h" #define MNG_SUPPORT_READ #define MNG_SUPPORT_DISPLAY @@ -437,7 +437,8 @@ static demuxer_t * demux_mng_open(demuxer_t * demuxer) sh_video->ds = demuxer->video; // set format of pixels in video packets - sh_video->format = IMGFMT_RGB32; + sh_video->format = MP_FOURCC_RAWVIDEO; + sh_video->imgfmt = MP_FOURCC_RGB32; // set framerate to some value (MNG does not have a fixed framerate) sh_video->fps = 5.0f; diff --git a/demux/demux_rawvideo.c b/demux/demux_rawvideo.c index 68dc270e44..47d32f933e 100644 --- a/demux/demux_rawvideo.c +++ b/demux/demux_rawvideo.c @@ -30,8 +30,10 @@ #include "stheader.h" #include "video/img_format.h" +#include "video/img_fourcc.h" -static int format = IMGFMT_I420; +static int format = MP_FOURCC_I420; +static int mp_format; static int size_id = 0; static int width = 0; static int height = 0; @@ -51,15 +53,8 @@ const m_option_t demux_rawvideo_opts[] = { { "16cif", &size_id, CONF_TYPE_FLAG,0,0,7, NULL }, { "sif", &size_id, CONF_TYPE_FLAG,0,0,8, NULL }, // format: - { "format", &format, CONF_TYPE_IMGFMT, 0, 0 , 0, NULL }, - // below options are obsolete - { "i420", &format, CONF_TYPE_FLAG, 0, 0 , IMGFMT_I420, NULL }, - { "yv12", &format, CONF_TYPE_FLAG, 0, 0 , IMGFMT_YV12, NULL }, - { "nv12", &format, CONF_TYPE_FLAG, 0, 0 , IMGFMT_NV12, NULL }, - { "hm12", &format, CONF_TYPE_FLAG, 0, 0 , IMGFMT_HM12, NULL }, - { "yuy2", &format, CONF_TYPE_FLAG, 0, 0 , IMGFMT_YUY2, NULL }, - { "uyvy", &format, CONF_TYPE_FLAG, 0, 0 , IMGFMT_UYVY, NULL }, - { "y8", &format, CONF_TYPE_FLAG, 0, 0 , IMGFMT_Y8, NULL }, + { "format", &format, CONF_TYPE_FOURCC, 0, 0 , 0, NULL }, + { "mp-format", &mp_format, CONF_TYPE_IMGFMT, 0, 0 , 0, NULL }, // misc: { "fps", &fps, CONF_TYPE_FLOAT,CONF_RANGE,0.001,1000, NULL }, { "size", &imgsize, CONF_TYPE_INT, CONF_RANGE, 1 , 8192*8192*4, NULL }, @@ -86,30 +81,58 @@ static demuxer_t* demux_rawvideo_open(demuxer_t* demuxer) { return 0; } - if(!imgsize) - switch(format){ - case IMGFMT_I420: - case IMGFMT_IYUV: - case IMGFMT_NV12: - case IMGFMT_HM12: - case IMGFMT_YV12: imgsize=width*height+2*(width>>1)*(height>>1);break; - case IMGFMT_YUY2: - case IMGFMT_UYVY: imgsize=width*height*2;break; - case IMGFMT_Y800: - case IMGFMT_Y8: imgsize=width*height;break; - default: - if (IMGFMT_IS_RGB(format)) - imgsize = width * height * ((IMGFMT_RGB_DEPTH(format) + 7) >> 3); - else if (IMGFMT_IS_BGR(format)) - imgsize = width * height * ((IMGFMT_BGR_DEPTH(format) + 7) >> 3); - else { + int tag, fmt; + if (mp_format) { + tag = MP_FOURCC_IMGFMT; + fmt = mp_format; + if (!imgsize) { + struct mp_imgfmt_desc desc = mp_imgfmt_get_desc(mp_format); + for (int p = 0; p < desc.num_planes; p++) { + imgsize += ((width >> desc.xs[p]) * (height >> desc.ys[p]) * + desc.bpp[p] + 7) / 8; + } + } + } else { + tag = MP_FOURCC_RAWVIDEO; + fmt = format; + } + + if (!imgsize) { + int bpp = 0; + switch(format){ + case MP_FOURCC_I420: case MP_FOURCC_IYUV: + case MP_FOURCC_NV12: case MP_FOURCC_NV21: + case MP_FOURCC_HM12: + case MP_FOURCC_YV12: + bpp = 12; + break; + case MP_FOURCC_RGB12: case MP_FOURCC_BGR12: + case MP_FOURCC_RGB15: case MP_FOURCC_BGR15: + case MP_FOURCC_RGB16: case MP_FOURCC_BGR16: + case MP_FOURCC_YUY2: case MP_FOURCC_UYVY: + bpp = 16; + break; + case MP_FOURCC_RGB8: case MP_FOURCC_BGR8: + case MP_FOURCC_Y800: case MP_FOURCC_Y8: + bpp = 8; + break; + case MP_FOURCC_RGB24: case MP_FOURCC_BGR24: + bpp = 24; + break; + case MP_FOURCC_RGB32: case MP_FOURCC_BGR32: + bpp = 32; + break; + } + if (!bpp) { mp_msg(MSGT_DEMUX,MSGL_ERR,"rawvideo: img size not specified and unknown format!\n"); return 0; - } + } + imgsize = width * height * bpp / 8; } sh_video = new_sh_video(demuxer,0); - sh_video->format=format; + sh_video->format=tag; + sh_video->imgfmt=fmt; sh_video->fps=fps; sh_video->frametime=1.0/fps; sh_video->disp_w=width; diff --git a/demux/stheader.h b/demux/stheader.h index 4745e452d5..97d079f4e6 100644 --- a/demux/stheader.h +++ b/demux/stheader.h @@ -154,6 +154,7 @@ typedef struct sh_video { int disp_w, disp_h; // display size (filled by demuxer) int colorspace; // mp_csp int color_range; // mp_csp_levels + int imgfmt; // raw video image format // output driver/filters: (set by libmpcodecs core) unsigned int outfmt; struct vf_instance *vfilter; // video filter chain diff --git a/etc/codecs.conf b/etc/codecs.conf index 46f87e1cd6..ba00957a94 100644 --- a/etc/codecs.conf +++ b/etc/codecs.conf @@ -1430,6 +1430,15 @@ videocodec ffrawy800 driver ffmpeg dll rawvideo +; used by some demuxers (demux_rawvideo.c, demux_mng.c, stream/tv.c) +videocodec ffrawvideo + info "RAW video" + status working + fourcc MPrv + fourcc MPvf ; internal mpv FourCC for demux_rawvideo + driver ffmpeg + dll rawvideo + ;============================================================================= ; AUDIO CODECS ;============================================================================= 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)); diff --git a/video/decode/lavc.h b/video/decode/lavc.h index a355f61310..df3f97ef87 100644 --- a/video/decode/lavc.h +++ b/video/decode/lavc.h @@ -21,7 +21,6 @@ typedef struct ffmpeg_ctx { double inv_qp_sum; AVRational last_sample_aspect_ratio; enum AVDiscard skip_frame; - int rawvideo_fmt; AVCodec *software_fallback; struct FramePool *dr1_buffer_pool; struct mp_image_pool *non_dr1_pool; diff --git a/video/decode/vd_lavc.c b/video/decode/vd_lavc.c index 24c3ba4e36..bf4cd42ba3 100644 --- a/video/decode/vd_lavc.c +++ b/video/decode/vd_lavc.c @@ -244,7 +244,6 @@ static int init(sh_video_t *sh) AVCodec *lavc_codec = NULL; ctx = sh->context = talloc_zero(NULL, vd_ffmpeg_ctx); - ctx->rawvideo_fmt = PIX_FMT_NONE; ctx->non_dr1_pool = talloc_steal(ctx, mp_image_pool_new(16)); if (sh->codec->dll) { @@ -264,10 +263,6 @@ static int init(sh_video_t *sh) uninit(sh); return 0; } - } else if (!IMGFMT_IS_HWACCEL(sh->format)) { - ctx->rawvideo_fmt = imgfmt2pixfmt(sh->format); - if (ctx->rawvideo_fmt != PIX_FMT_NONE) - lavc_codec = avcodec_find_decoder_by_name("rawvideo"); } if (!lavc_codec) { uninit(sh); @@ -358,11 +353,7 @@ static int init_avctx(sh_video_t *sh, AVCodec *lavc_codec, struct hwdec *hwdec) if (lavc_param->gray) avctx->flags |= CODEC_FLAG_GRAY; avctx->flags2 |= lavc_param->fast; - if (ctx->rawvideo_fmt == PIX_FMT_NONE) { - avctx->codec_tag = sh->format; - } else { - avctx->pix_fmt = ctx->rawvideo_fmt; - } + avctx->codec_tag = sh->format; if (sh->gsh->lavf_codec_tag) avctx->codec_tag = sh->gsh->lavf_codec_tag; avctx->stream_codec_tag = sh->video.fccHandler; @@ -440,6 +431,14 @@ static int init_avctx(sh_video_t *sh, AVCodec *lavc_codec, struct hwdec *hwdec) } break; + case MKTAG('M', 'P', 'v', 'f'): + avctx->codec_tag = 0; + avctx->pix_fmt = imgfmt2pixfmt(sh->imgfmt); + break; + case MKTAG('M', 'P', 'r', 'v'): + avctx->codec_tag = sh->imgfmt; + break; + default: if (!sh->bih || sh->bih->biSize <= sizeof(*sh->bih)) break; diff --git a/video/filter/vf_crop.c b/video/filter/vf_crop.c index 692d05bcc9..c1cb069a81 100644 --- a/video/filter/vf_crop.c +++ b/video/filter/vf_crop.c @@ -54,18 +54,14 @@ static int config(struct vf_instance *vf, if(!IMGFMT_IS_RGB(outfmt) && !IMGFMT_IS_BGR(outfmt)){ switch(outfmt){ case IMGFMT_444P: - case IMGFMT_Y800: case IMGFMT_Y8: break; - case IMGFMT_YVU9: - case IMGFMT_IF09: + case IMGFMT_410P: vf->priv->crop_y&=~3; case IMGFMT_411P: vf->priv->crop_x&=~3; break; - case IMGFMT_YV12: - case IMGFMT_I420: - case IMGFMT_IYUV: + case IMGFMT_420P: vf->priv->crop_y&=~1; default: vf->priv->crop_x&=~1; diff --git a/video/filter/vf_delogo.c b/video/filter/vf_delogo.c index f709aad4d0..346eb468f5 100644 --- a/video/filter/vf_delogo.c +++ b/video/filter/vf_delogo.c @@ -207,18 +207,14 @@ static void uninit(struct vf_instance *vf){ static int query_format(struct vf_instance *vf, unsigned int fmt){ switch(fmt) { - case IMGFMT_YV12: - case IMGFMT_I420: - case IMGFMT_IYUV: + case IMGFMT_420P: return vf_next_query_format(vf,vf->priv->outfmt); } return 0; } static const unsigned int fmt_list[]={ - IMGFMT_YV12, - IMGFMT_I420, - IMGFMT_IYUV, + IMGFMT_420P, 0 }; @@ -306,7 +302,7 @@ static int vf_open(vf_instance_t *vf, char *args){ fix_band(vf->priv); // check csp: - vf->priv->outfmt=vf_match_csp(&vf->next,fmt_list,IMGFMT_YV12); + vf->priv->outfmt=vf_match_csp(&vf->next,fmt_list,IMGFMT_420P); if(!vf->priv->outfmt) { uninit(vf); diff --git a/video/filter/vf_divtc.c b/video/filter/vf_divtc.c index dadccf9a9b..19b23ac481 100644 --- a/video/filter/vf_divtc.c +++ b/video/filter/vf_divtc.c @@ -577,11 +577,10 @@ static int query_format(struct vf_instance *vf, unsigned int fmt) { switch(fmt) { - case IMGFMT_444P: case IMGFMT_IYUV: case IMGFMT_RGB24: + case IMGFMT_444P: case IMGFMT_RGB24: case IMGFMT_422P: case IMGFMT_UYVY: case IMGFMT_BGR24: - case IMGFMT_411P: case IMGFMT_YUY2: case IMGFMT_IF09: - case IMGFMT_YV12: case IMGFMT_I420: case IMGFMT_YVU9: - case IMGFMT_IUYV: case IMGFMT_Y800: case IMGFMT_Y8: + case IMGFMT_411P: case IMGFMT_YUYV: case IMGFMT_410P: + case IMGFMT_420P: case IMGFMT_Y8: return vf_next_query_format(vf,fmt); } diff --git a/video/filter/vf_down3dright.c b/video/filter/vf_down3dright.c index b1835cd26b..21616a4ad2 100644 --- a/video/filter/vf_down3dright.c +++ b/video/filter/vf_down3dright.c @@ -114,7 +114,7 @@ static int config(struct vf_instance *vf, { /* FIXME - also support UYVY output? */ return vf_next_config(vf, width * vf->priv->scalew, - height / vf->priv->scaleh - vf->priv->skipline, d_width, d_height, flags, IMGFMT_YV12); + height / vf->priv->scaleh - vf->priv->skipline, d_width, d_height, flags, IMGFMT_420P); } @@ -122,10 +122,8 @@ static int query_format(struct vf_instance *vf, unsigned int fmt) { /* FIXME - really any YUV 4:2:0 input format should work */ switch (fmt) { - case IMGFMT_YV12: - case IMGFMT_IYUV: - case IMGFMT_I420: - return vf_next_query_format(vf, IMGFMT_YV12); + case IMGFMT_420P: + return vf_next_query_format(vf, IMGFMT_420P); } return 0; } diff --git a/video/filter/vf_eq.c b/video/filter/vf_eq.c index cfbe7ea17e..76a8b2bc99 100644 --- a/video/filter/vf_eq.c +++ b/video/filter/vf_eq.c @@ -425,16 +425,13 @@ static int query_format (vf_instance_t *vf, unsigned fmt) { switch (fmt) { - case IMGFMT_YVU9: - case IMGFMT_IF09: - case IMGFMT_YV12: - case IMGFMT_I420: - case IMGFMT_IYUV: - case IMGFMT_Y800: case IMGFMT_Y8: case IMGFMT_444P: case IMGFMT_422P: + case IMGFMT_440P: + case IMGFMT_420P: case IMGFMT_411P: + case IMGFMT_410P: return vf_next_query_format (vf, fmt); } diff --git a/video/filter/vf_expand.c b/video/filter/vf_expand.c index 5ce5db16bd..f8ebbd0b18 100644 --- a/video/filter/vf_expand.c +++ b/video/filter/vf_expand.c @@ -66,7 +66,7 @@ static int config(struct vf_instance *vf, struct MPOpts *opts = vf->opts; mp_image_t test_mpi; mp_image_setfmt(&test_mpi, outfmt); - if (outfmt == IMGFMT_IF09 || !test_mpi.bpp) return 0; + if (test_mpi.num_planes > 3 || !test_mpi.bpp) return 0; vf->priv->exp_x = vf->priv->cfg_exp_x; vf->priv->exp_y = vf->priv->cfg_exp_y; vf->priv->exp_w = vf->priv->cfg_exp_w; diff --git a/video/filter/vf_format.c b/video/filter/vf_format.c index 8abbd9b054..71e3ad7669 100644 --- a/video/filter/vf_format.c +++ b/video/filter/vf_format.c @@ -35,7 +35,7 @@ static struct vf_priv_s { unsigned int fmt; unsigned int outfmt; } const vf_priv_dflt = { - IMGFMT_YUY2, + IMGFMT_YUYV, 0 }; diff --git a/video/filter/vf_gradfun.c b/video/filter/vf_gradfun.c index b9d07bc907..b3c0702375 100644 --- a/video/filter/vf_gradfun.c +++ b/video/filter/vf_gradfun.c @@ -321,20 +321,15 @@ static struct mp_image *filter(struct vf_instance *vf, struct mp_image *mpi) static int query_format(struct vf_instance *vf, unsigned int fmt) { switch (fmt){ - case IMGFMT_YVU9: - case IMGFMT_IF09: - case IMGFMT_YV12: - case IMGFMT_I420: - case IMGFMT_IYUV: - case IMGFMT_CLPL: - case IMGFMT_Y800: - case IMGFMT_Y8: case IMGFMT_NV12: case IMGFMT_NV21: + case IMGFMT_Y8: case IMGFMT_444P: case IMGFMT_422P: + case IMGFMT_440P: + case IMGFMT_420P: case IMGFMT_411P: - case IMGFMT_HM12: + case IMGFMT_410P: return vf_next_query_format(vf,fmt); } return 0; diff --git a/video/filter/vf_hqdn3d.c b/video/filter/vf_hqdn3d.c index 1ec0cc5c66..4f49f12715 100644 --- a/video/filter/vf_hqdn3d.c +++ b/video/filter/vf_hqdn3d.c @@ -245,13 +245,12 @@ static struct mp_image *filter(struct vf_instance *vf, struct mp_image *mpi) static int query_format(struct vf_instance *vf, unsigned int fmt){ switch(fmt) { - case IMGFMT_YV12: - case IMGFMT_I420: - case IMGFMT_IYUV: - case IMGFMT_YVU9: - case IMGFMT_444P: - case IMGFMT_422P: - case IMGFMT_411P: + case IMGFMT_444P: + case IMGFMT_422P: + case IMGFMT_440P: + case IMGFMT_420P: + case IMGFMT_411P: + case IMGFMT_410P: return vf_next_query_format(vf, fmt); } return 0; diff --git a/video/filter/vf_ilpack.c b/video/filter/vf_ilpack.c index 73f816cb9e..f153a4b7d0 100644 --- a/video/filter/vf_ilpack.c +++ b/video/filter/vf_ilpack.c @@ -389,7 +389,7 @@ static int config(struct vf_instance *vf, unsigned int flags, unsigned int outfmt) { /* FIXME - also support UYVY output? */ - return vf_next_config(vf, width, height, d_width, d_height, flags, IMGFMT_YUY2); + return vf_next_config(vf, width, height, d_width, d_height, flags, IMGFMT_YUYV); } @@ -397,10 +397,8 @@ static int query_format(struct vf_instance *vf, unsigned int fmt) { /* FIXME - really any YUV 4:2:0 input format should work */ switch (fmt) { - case IMGFMT_YV12: - case IMGFMT_IYUV: - case IMGFMT_I420: - return vf_next_query_format(vf,IMGFMT_YUY2); + case IMGFMT_420P: + return vf_next_query_format(vf,IMGFMT_YUYV); } return 0; } diff --git a/video/filter/vf_mirror.c b/video/filter/vf_mirror.c index b826ee46f7..56fc2ebb3d 100644 --- a/video/filter/vf_mirror.c +++ b/video/filter/vf_mirror.c @@ -50,8 +50,7 @@ static void mirror(unsigned char* dst,unsigned char* src,int dststride,int srcst dst[x*4+3]=src[1+(w2-x-1)*4]; } break; } - case IMGFMT_YUY2: - case IMGFMT_YVYU: { + case IMGFMT_YUYV: { // packed YUV is tricky. U,V are 32bpp while Y is 16bpp: int w2=w>>1; for(x=0;x<w2;x++){ diff --git a/video/filter/vf_noformat.c b/video/filter/vf_noformat.c index 6964a2955c..3d7e841db6 100644 --- a/video/filter/vf_noformat.c +++ b/video/filter/vf_noformat.c @@ -34,7 +34,7 @@ static struct vf_priv_s { unsigned int fmt; } const vf_priv_dflt = { - IMGFMT_YV12 + IMGFMT_420P }; //===========================================================================// diff --git a/video/filter/vf_noise.c b/video/filter/vf_noise.c index 44f96765b4..0af7da5c9a 100644 --- a/video/filter/vf_noise.c +++ b/video/filter/vf_noise.c @@ -358,9 +358,7 @@ static void uninit(struct vf_instance *vf){ static int query_format(struct vf_instance *vf, unsigned int fmt){ switch(fmt) { - case IMGFMT_YV12: - case IMGFMT_I420: - case IMGFMT_IYUV: + case IMGFMT_420P: return vf_next_query_format(vf,vf->priv->outfmt); } return 0; @@ -391,9 +389,7 @@ static void parse(FilterParam *fp, char* args){ } static const unsigned int fmt_list[]={ - IMGFMT_YV12, - IMGFMT_I420, - IMGFMT_IYUV, + IMGFMT_420P, 0 }; @@ -412,7 +408,7 @@ static int vf_open(vf_instance_t *vf, char *args){ } // check csp: - vf->priv->outfmt=vf_match_csp(&vf->next,fmt_list,IMGFMT_YV12); + vf->priv->outfmt=vf_match_csp(&vf->next,fmt_list,IMGFMT_420P); if(!vf->priv->outfmt) { uninit(vf); diff --git a/video/filter/vf_pp.c b/video/filter/vf_pp.c index 8a6b1cf172..157dc3e068 100644 --- a/video/filter/vf_pp.c +++ b/video/filter/vf_pp.c @@ -72,11 +72,9 @@ static void uninit(struct vf_instance *vf){ static int query_format(struct vf_instance *vf, unsigned int fmt){ switch(fmt){ - case IMGFMT_YV12: - case IMGFMT_I420: - case IMGFMT_IYUV: case IMGFMT_444P: case IMGFMT_422P: + case IMGFMT_420P: case IMGFMT_411P: return vf_next_query_format(vf,fmt); } @@ -133,9 +131,7 @@ static struct mp_image *filter(struct vf_instance *vf, struct mp_image *mpi) extern int divx_quality; static const unsigned int fmt_list[]={ - IMGFMT_YV12, - IMGFMT_I420, - IMGFMT_IYUV, + IMGFMT_420P, IMGFMT_444P, IMGFMT_422P, IMGFMT_411P, @@ -155,7 +151,7 @@ static int vf_open(vf_instance_t *vf, char *args){ vf->priv->context=NULL; // check csp: - vf->priv->outfmt=vf_match_csp(&vf->next,fmt_list,IMGFMT_YV12); + vf->priv->outfmt=vf_match_csp(&vf->next,fmt_list,IMGFMT_420P); if(!vf->priv->outfmt) return 0; // no csp match :( char *name = args ? args : "de"; diff --git a/video/filter/vf_pullup.c b/video/filter/vf_pullup.c index 45e80b6b57..0a6e4c6b25 100644 --- a/video/filter/vf_pullup.c +++ b/video/filter/vf_pullup.c @@ -224,9 +224,7 @@ static int query_format(struct vf_instance *vf, unsigned int fmt) { /* FIXME - support more formats */ switch (fmt) { - case IMGFMT_YV12: - case IMGFMT_IYUV: - case IMGFMT_I420: + case IMGFMT_420P: return vf_next_query_format(vf, fmt); } return 0; diff --git a/video/filter/vf_rotate.c b/video/filter/vf_rotate.c index f44c874c1f..d6d2d0df85 100644 --- a/video/filter/vf_rotate.c +++ b/video/filter/vf_rotate.c @@ -111,14 +111,10 @@ static int query_format(struct vf_instance *vf, unsigned int fmt){ if(IMGFMT_IS_RGB(fmt) || IMGFMT_IS_BGR(fmt)) return vf_next_query_format(vf, fmt); // we can support only symmetric (chroma_x_shift==chroma_y_shift) YUV formats: switch(fmt) { - case IMGFMT_YV12: - case IMGFMT_I420: - case IMGFMT_IYUV: - case IMGFMT_YVU9: -// case IMGFMT_IF09: case IMGFMT_Y8: - case IMGFMT_Y800: - case IMGFMT_444P: + case IMGFMT_444P: + case IMGFMT_420P: + case IMGFMT_410P: return vf_next_query_format(vf, fmt); } return 0; diff --git a/video/filter/vf_scale.c b/video/filter/vf_scale.c index a10825ee56..ca06436dd5 100644 --- a/video/filter/vf_scale.c +++ b/video/filter/vf_scale.c @@ -87,8 +87,7 @@ static const unsigned int outfmt_list[]={ IMGFMT_422P10_BE, IMGFMT_422P9_LE, IMGFMT_422P9_BE, - IMGFMT_YV12, - IMGFMT_I420, + IMGFMT_420P, IMGFMT_420P16_LE, IMGFMT_420P16_BE, IMGFMT_420P14_LE, @@ -99,14 +98,12 @@ static const unsigned int outfmt_list[]={ IMGFMT_420P10_BE, IMGFMT_420P9_LE, IMGFMT_420P9_BE, - IMGFMT_420A, - IMGFMT_IYUV, - IMGFMT_YVU9, - IMGFMT_IF09, + IMGFMT_420AP, + IMGFMT_410P, IMGFMT_411P, IMGFMT_NV12, IMGFMT_NV21, - IMGFMT_YUY2, + IMGFMT_YUYV, IMGFMT_UYVY, IMGFMT_440P, // RGB and grayscale (Y8 and Y800): @@ -119,24 +116,22 @@ static const unsigned int outfmt_list[]={ IMGFMT_BGR24, IMGFMT_RGB24, IMGFMT_GBRP, - IMGFMT_RGB48LE, - IMGFMT_RGB48BE, + IMGFMT_RGB48_LE, + IMGFMT_RGB48_BE, IMGFMT_BGR16, IMGFMT_RGB16, IMGFMT_BGR15, IMGFMT_RGB15, IMGFMT_BGR12, IMGFMT_RGB12, - IMGFMT_Y800, IMGFMT_Y8, IMGFMT_BGR8, IMGFMT_RGB8, IMGFMT_BGR4, IMGFMT_RGB4, - IMGFMT_BG4B, - IMGFMT_RG4B, - IMGFMT_BGR1, - IMGFMT_RGB1, + IMGFMT_RGB4_BYTE, + IMGFMT_BGR4_BYTE, + IMGFMT_MONO, 0 }; @@ -147,13 +142,13 @@ static const unsigned int outfmt_list[]={ * fast assembler implementation. */ static int preferred_conversions[][2] = { - {IMGFMT_YUY2, IMGFMT_UYVY}, - {IMGFMT_YUY2, IMGFMT_422P}, - {IMGFMT_UYVY, IMGFMT_YUY2}, + {IMGFMT_YUYV, IMGFMT_UYVY}, + {IMGFMT_YUYV, IMGFMT_422P}, + {IMGFMT_UYVY, IMGFMT_YUYV}, {IMGFMT_UYVY, IMGFMT_422P}, - {IMGFMT_422P, IMGFMT_YUY2}, + {IMGFMT_422P, IMGFMT_YUYV}, {IMGFMT_422P, IMGFMT_UYVY}, - {IMGFMT_420P10, IMGFMT_YV12}, + {IMGFMT_420P10, IMGFMT_420P}, {IMGFMT_GBRP, IMGFMT_BGR24}, {IMGFMT_GBRP, IMGFMT_RGB24}, {IMGFMT_GBRP, IMGFMT_BGR32}, @@ -277,13 +272,11 @@ static int config(struct vf_instance *vf, // calculate the missing parameters: switch(best) { - case IMGFMT_YV12: /* YV12 needs w & h rounded to 2 */ - case IMGFMT_I420: - case IMGFMT_IYUV: + case IMGFMT_420P: /* YV12 needs w & h rounded to 2 */ case IMGFMT_NV12: case IMGFMT_NV21: vf->priv->h = (vf->priv->h + 1) & ~1; - case IMGFMT_YUY2: /* YUY2 needs w rounded to 2 */ + case IMGFMT_YUYV: /* YUY2 needs w rounded to 2 */ case IMGFMT_UYVY: vf->priv->w = (vf->priv->w + 1) & ~1; } diff --git a/video/filter/vf_sub.c b/video/filter/vf_sub.c index 96100801ff..8cda9f5e79 100644 --- a/video/filter/vf_sub.c +++ b/video/filter/vf_sub.c @@ -61,8 +61,6 @@ static int config(struct vf_instance *vf, unsigned int flags, unsigned int outfmt) { struct MPOpts *opts = vf->opts; - if (outfmt == IMGFMT_IF09) - return 0; vf->priv->outh = height + vf->priv->opt_top_margin + vf->priv->opt_bottom_margin; @@ -178,9 +176,7 @@ static struct mp_image *filter(struct vf_instance *vf, struct mp_image *mpi) static int query_format(struct vf_instance *vf, unsigned int fmt) { switch (fmt) { - case IMGFMT_YV12: - case IMGFMT_I420: - case IMGFMT_IYUV: + case IMGFMT_420P: return vf_next_query_format(vf, vf->priv->outfmt); } return 0; @@ -209,15 +205,13 @@ static void uninit(struct vf_instance *vf) } static const unsigned int fmt_list[] = { - IMGFMT_YV12, - IMGFMT_I420, - IMGFMT_IYUV, + IMGFMT_420P, 0 }; static int vf_open(vf_instance_t *vf, char *args) { - vf->priv->outfmt = vf_match_csp(&vf->next, fmt_list, IMGFMT_YV12); + vf->priv->outfmt = vf_match_csp(&vf->next, fmt_list, IMGFMT_420P); if (!vf->priv->outfmt) { uninit(vf); return 0; diff --git a/video/filter/vf_swapuv.c b/video/filter/vf_swapuv.c index 5e879ff557..a9083ccaa8 100644 --- a/video/filter/vf_swapuv.c +++ b/video/filter/vf_swapuv.c @@ -42,13 +42,12 @@ static struct mp_image *filter(struct vf_instance *vf, struct mp_image *mpi) static int query_format(struct vf_instance *vf, unsigned int fmt){ switch(fmt) { - case IMGFMT_YV12: - case IMGFMT_I420: - case IMGFMT_IYUV: - case IMGFMT_YVU9: case IMGFMT_444P: - case IMGFMT_422P: - case IMGFMT_411P: + case IMGFMT_422P: + case IMGFMT_440P: + case IMGFMT_420P: + case IMGFMT_411P: + case IMGFMT_410P: return vf_next_query_format(vf, fmt); } return 0; diff --git a/video/filter/vf_unsharp.c b/video/filter/vf_unsharp.c index c3150b9a33..dcca82df5b 100644 --- a/video/filter/vf_unsharp.c +++ b/video/filter/vf_unsharp.c @@ -206,9 +206,7 @@ static void uninit( struct vf_instance *vf ) { static int query_format( struct vf_instance *vf, unsigned int fmt ) { switch(fmt) { - case IMGFMT_YV12: - case IMGFMT_I420: - case IMGFMT_IYUV: + case IMGFMT_420P: return vf_next_query_format( vf, vf->priv->outfmt ); } return 0; @@ -241,9 +239,7 @@ static void parse( FilterParam *fp, char* args ) { //===========================================================================// static const unsigned int fmt_list[] = { - IMGFMT_YV12, - IMGFMT_I420, - IMGFMT_IYUV, + IMGFMT_420P, 0 }; @@ -279,7 +275,7 @@ static int vf_open( vf_instance_t *vf, char *args ) { } // check csp: - vf->priv->outfmt = vf_match_csp( &vf->next, fmt_list, IMGFMT_YV12 ); + vf->priv->outfmt = vf_match_csp( &vf->next, fmt_list, IMGFMT_420P ); if( !vf->priv->outfmt ) { uninit( vf ); return 0; // no csp match :( diff --git a/video/filter/vf_yadif.c b/video/filter/vf_yadif.c index 4e53ef168c..10ce6d9e8e 100644 --- a/video/filter/vf_yadif.c +++ b/video/filter/vf_yadif.c @@ -477,10 +477,7 @@ static void uninit(struct vf_instance *vf){ //===========================================================================// static int query_format(struct vf_instance *vf, unsigned int fmt){ switch(fmt){ - case IMGFMT_YV12: - case IMGFMT_I420: - case IMGFMT_IYUV: - case IMGFMT_Y800: + case IMGFMT_420P: case IMGFMT_Y8: return vf_next_query_format(vf,fmt); } diff --git a/video/fmt-conversion.c b/video/fmt-conversion.c index 6a45713f7c..cf3aaa7452 100644 --- a/video/fmt-conversion.c +++ b/video/fmt-conversion.c @@ -29,52 +29,47 @@ static const struct { {IMGFMT_ARGB, PIX_FMT_ARGB}, {IMGFMT_BGRA, PIX_FMT_BGRA}, {IMGFMT_BGR24, PIX_FMT_BGR24}, - {IMGFMT_BGR16BE, PIX_FMT_RGB565BE}, - {IMGFMT_BGR16LE, PIX_FMT_RGB565LE}, - {IMGFMT_BGR15BE, PIX_FMT_RGB555BE}, - {IMGFMT_BGR15LE, PIX_FMT_RGB555LE}, - {IMGFMT_BGR12BE, PIX_FMT_RGB444BE}, - {IMGFMT_BGR12LE, PIX_FMT_RGB444LE}, + {IMGFMT_BGR16_BE, PIX_FMT_RGB565BE}, + {IMGFMT_BGR16_LE, PIX_FMT_RGB565LE}, + {IMGFMT_BGR15_BE, PIX_FMT_RGB555BE}, + {IMGFMT_BGR15_LE, PIX_FMT_RGB555LE}, + {IMGFMT_BGR12_BE, PIX_FMT_RGB444BE}, + {IMGFMT_BGR12_LE, PIX_FMT_RGB444LE}, {IMGFMT_BGR8, PIX_FMT_RGB8}, {IMGFMT_BGR4, PIX_FMT_RGB4}, - {IMGFMT_BGR1, PIX_FMT_MONOBLACK}, - {IMGFMT_RGB1, PIX_FMT_MONOBLACK}, - {IMGFMT_RG4B, PIX_FMT_BGR4_BYTE}, - {IMGFMT_BG4B, PIX_FMT_RGB4_BYTE}, - {IMGFMT_RGB48LE, PIX_FMT_RGB48LE}, - {IMGFMT_RGB48BE, PIX_FMT_RGB48BE}, + {IMGFMT_MONO, PIX_FMT_MONOBLACK}, + {IMGFMT_RGB4_BYTE, PIX_FMT_BGR4_BYTE}, + {IMGFMT_BGR4_BYTE, PIX_FMT_RGB4_BYTE}, + {IMGFMT_RGB48_LE, PIX_FMT_RGB48LE}, + {IMGFMT_RGB48_BE, PIX_FMT_RGB48BE}, {IMGFMT_ABGR, PIX_FMT_ABGR}, {IMGFMT_RGBA, PIX_FMT_RGBA}, {IMGFMT_RGB24, PIX_FMT_RGB24}, - {IMGFMT_RGB16BE, PIX_FMT_BGR565BE}, - {IMGFMT_RGB16LE, PIX_FMT_BGR565LE}, - {IMGFMT_RGB15BE, PIX_FMT_BGR555BE}, - {IMGFMT_RGB15LE, PIX_FMT_BGR555LE}, - {IMGFMT_RGB12BE, PIX_FMT_BGR444BE}, - {IMGFMT_RGB12LE, PIX_FMT_BGR444LE}, + {IMGFMT_RGB16_BE, PIX_FMT_BGR565BE}, + {IMGFMT_RGB16_LE, PIX_FMT_BGR565LE}, + {IMGFMT_RGB15_BE, PIX_FMT_BGR555BE}, + {IMGFMT_RGB15_LE, PIX_FMT_BGR555LE}, + {IMGFMT_RGB12_BE, PIX_FMT_BGR444BE}, + {IMGFMT_RGB12_LE, PIX_FMT_BGR444LE}, {IMGFMT_RGB8, PIX_FMT_BGR8}, {IMGFMT_RGB4, PIX_FMT_BGR4}, {IMGFMT_PAL8, PIX_FMT_PAL8}, {IMGFMT_GBRP, PIX_FMT_GBRP}, - {IMGFMT_YUY2, PIX_FMT_YUYV422}, + {IMGFMT_YUYV, PIX_FMT_YUYV422}, {IMGFMT_UYVY, PIX_FMT_UYVY422}, {IMGFMT_NV12, PIX_FMT_NV12}, {IMGFMT_NV21, PIX_FMT_NV21}, - {IMGFMT_Y800, PIX_FMT_GRAY8}, {IMGFMT_Y8, PIX_FMT_GRAY8}, - {IMGFMT_Y16LE, PIX_FMT_GRAY16LE}, - {IMGFMT_Y16BE, PIX_FMT_GRAY16BE}, - {IMGFMT_YVU9, PIX_FMT_YUV410P}, - {IMGFMT_IF09, PIX_FMT_YUV410P}, - {IMGFMT_YV12, PIX_FMT_YUV420P}, - {IMGFMT_I420, PIX_FMT_YUV420P}, - {IMGFMT_IYUV, PIX_FMT_YUV420P}, + {IMGFMT_Y16_LE, PIX_FMT_GRAY16LE}, + {IMGFMT_Y16_BE, PIX_FMT_GRAY16BE}, + {IMGFMT_410P, PIX_FMT_YUV410P}, + {IMGFMT_420P, PIX_FMT_YUV420P}, {IMGFMT_411P, PIX_FMT_YUV411P}, {IMGFMT_422P, PIX_FMT_YUV422P}, {IMGFMT_444P, PIX_FMT_YUV444P}, {IMGFMT_440P, PIX_FMT_YUV440P}, - {IMGFMT_420A, PIX_FMT_YUVA420P}, + {IMGFMT_420AP, PIX_FMT_YUVA420P}, {IMGFMT_420P16_LE, PIX_FMT_YUV420P16LE}, {IMGFMT_420P16_BE, PIX_FMT_YUV420P16BE}, @@ -95,10 +90,9 @@ static const struct { {IMGFMT_444P16_LE, PIX_FMT_YUV444P16LE}, {IMGFMT_444P16_BE, PIX_FMT_YUV444P16BE}, - // YUVJ are YUV formats that use the full Y range and not just - // 16 - 235 (see colorspaces.txt). - // Currently they are all treated the same way. - {IMGFMT_YV12, PIX_FMT_YUVJ420P}, + // YUVJ are YUV formats that use the full Y range. Decoder color range + // information is used instead. Deprecated in ffmpeg. + {IMGFMT_420P, PIX_FMT_YUVJ420P}, {IMGFMT_422P, PIX_FMT_YUVJ422P}, {IMGFMT_444P, PIX_FMT_YUVJ444P}, {IMGFMT_440P, PIX_FMT_YUVJ440P}, diff --git a/video/image_writer.c b/video/image_writer.c index 8d3b746ef7..3a25e91b07 100644 --- a/video/image_writer.c +++ b/video/image_writer.c @@ -215,16 +215,16 @@ static const struct img_writer img_writers[] = { { "ppm", write_lavc, .lavc_codec = CODEC_ID_PPM }, { "pgm", write_lavc, .lavc_codec = CODEC_ID_PGM, - .pixfmts = (int[]) { IMGFMT_Y800, 0 }, + .pixfmts = (int[]) { IMGFMT_Y8, 0 }, }, { "pgmyuv", write_lavc, .lavc_codec = CODEC_ID_PGMYUV, - .pixfmts = (int[]) { IMGFMT_YV12, 0 }, + .pixfmts = (int[]) { IMGFMT_420P, 0 }, }, { "tga", write_lavc, .lavc_codec = CODEC_ID_TARGA, - .pixfmts = (int[]) { IMGFMT_BGR24, IMGFMT_BGRA, IMGFMT_BGR15LE, - IMGFMT_Y800, 0}, + .pixfmts = (int[]) { IMGFMT_BGR24, IMGFMT_BGRA, IMGFMT_BGR15_LE, + IMGFMT_Y8, 0}, }, #ifdef CONFIG_JPEG { "jpg", write_jpeg }, diff --git a/video/img_format.c b/video/img_format.c index e540dd24cf..bf75ba8a18 100644 --- a/video/img_format.c +++ b/video/img_format.c @@ -17,133 +17,87 @@ */ #include <assert.h> +#include <string.h> #include <libavutil/pixfmt.h> #include <libavutil/pixdesc.h> -#include "config.h" #include "video/img_format.h" #include "video/mp_image.h" #include "video/fmt-conversion.h" -#include <string.h> +#define FMT(string, id) \ + {string, id}, + +#define FMT_ENDIAN(string, id) \ + {string, id}, \ + {string "le", MP_CONCAT(id, _LE)}, \ + {string "be", MP_CONCAT(id, _BE)}, \ struct mp_imgfmt_entry mp_imgfmt_list[] = { - {"444p16le", IMGFMT_444P16_LE}, - {"444p16be", IMGFMT_444P16_BE}, - {"444p14le", IMGFMT_444P14_LE}, - {"444p14be", IMGFMT_444P14_BE}, - {"444p12le", IMGFMT_444P12_LE}, - {"444p12be", IMGFMT_444P12_BE}, - {"444p10le", IMGFMT_444P10_LE}, - {"444p10be", IMGFMT_444P10_BE}, - {"444p9le", IMGFMT_444P9_LE}, - {"444p9be", IMGFMT_444P9_BE}, - {"422p16le", IMGFMT_422P16_LE}, - {"422p16be", IMGFMT_422P16_BE}, - {"422p14le", IMGFMT_422P14_LE}, - {"422p14be", IMGFMT_422P14_BE}, - {"422p12le", IMGFMT_422P12_LE}, - {"422p12be", IMGFMT_422P12_BE}, - {"422p10le", IMGFMT_422P10_LE}, - {"422p10be", IMGFMT_422P10_BE}, - {"422p9le", IMGFMT_422P9_LE}, - {"422p9be", IMGFMT_422P9_BE}, - {"420p16le", IMGFMT_420P16_LE}, - {"420p16be", IMGFMT_420P16_BE}, - {"420p14le", IMGFMT_420P14_LE}, - {"420p14be", IMGFMT_420P14_BE}, - {"420p12le", IMGFMT_420P12_LE}, - {"420p12be", IMGFMT_420P12_BE}, - {"420p10le", IMGFMT_420P10_LE}, - {"420p10be", IMGFMT_420P10_BE}, - {"420p9le", IMGFMT_420P9_LE}, - {"420p9be", IMGFMT_420P9_BE}, - {"444p16", IMGFMT_444P16}, - {"444p14", IMGFMT_444P14}, - {"444p12", IMGFMT_444P12}, - {"444p10", IMGFMT_444P10}, - {"444p9", IMGFMT_444P9}, - {"422p16", IMGFMT_422P16}, - {"422p14", IMGFMT_422P14}, - {"422p12", IMGFMT_422P12}, - {"422p10", IMGFMT_422P10}, - {"420p14", IMGFMT_420P14}, - {"420p12", IMGFMT_420P12}, - {"420p10", IMGFMT_420P10}, - {"420p9", IMGFMT_420P9}, - {"420p16", IMGFMT_420P16}, - {"420a", IMGFMT_420A}, - {"444p", IMGFMT_444P}, - {"422p", IMGFMT_422P}, - {"411p", IMGFMT_411P}, - {"440p", IMGFMT_440P}, - {"yuy2", IMGFMT_YUY2}, - {"yvyu", IMGFMT_YVYU}, - {"uyvy", IMGFMT_UYVY}, - {"yvu9", IMGFMT_YVU9}, - {"if09", IMGFMT_IF09}, - {"yv12", IMGFMT_YV12}, - {"i420", IMGFMT_I420}, - {"iyuv", IMGFMT_IYUV}, - {"clpl", IMGFMT_CLPL}, - {"hm12", IMGFMT_HM12}, - {"y800", IMGFMT_Y800}, - {"y8", IMGFMT_Y8}, - {"y16ne", IMGFMT_Y16}, - {"y16le", IMGFMT_Y16LE}, - {"y16be", IMGFMT_Y16BE}, - {"nv12", IMGFMT_NV12}, - {"nv21", IMGFMT_NV21}, - {"bgr24", IMGFMT_BGR24}, - {"bgr32", IMGFMT_BGR32}, - {"bgr16", IMGFMT_BGR16}, - {"bgr15", IMGFMT_BGR15}, - {"bgr12", IMGFMT_BGR12}, - {"bgr8", IMGFMT_BGR8}, - {"bgr4", IMGFMT_BGR4}, - {"bg4b", IMGFMT_BG4B}, - {"bgr1", IMGFMT_BGR1}, - {"rgb48be", IMGFMT_RGB48BE}, - {"rgb48le", IMGFMT_RGB48LE}, - {"rgb48ne", IMGFMT_RGB48NE}, - {"rgb24", IMGFMT_RGB24}, - {"rgb32", IMGFMT_RGB32}, - {"rgb16", IMGFMT_RGB16}, - {"rgb15", IMGFMT_RGB15}, - {"rgb12", IMGFMT_RGB12}, - {"rgb8", IMGFMT_RGB8}, - {"pal8", IMGFMT_PAL8}, - {"rgb4", IMGFMT_RGB4}, - {"rg4b", IMGFMT_RG4B}, - {"rgb1", IMGFMT_RGB1}, - {"rgba", IMGFMT_RGBA}, - {"argb", IMGFMT_ARGB}, - {"bgra", IMGFMT_BGRA}, - {"abgr", IMGFMT_ABGR}, - {"bgr0", IMGFMT_BGR0}, - {"gbrp", IMGFMT_GBRP}, - {"mjpeg", IMGFMT_MJPEG}, - {"mjpg", IMGFMT_MJPEG}, - {"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}, + FMT("y8", IMGFMT_Y8) + FMT_ENDIAN("y16", IMGFMT_Y16) + FMT("yuyv", IMGFMT_YUYV) + FMT("uyvy", IMGFMT_UYVY) + FMT("nv12", IMGFMT_NV12) + FMT("nv21", IMGFMT_NV21) + FMT("444p", IMGFMT_444P) + FMT("422p", IMGFMT_422P) + FMT("440p", IMGFMT_440P) + FMT("420p", IMGFMT_420P) + FMT("yv12", IMGFMT_420P) // old alias for UI + FMT("411p", IMGFMT_411P) + FMT("410p", IMGFMT_410P) + FMT_ENDIAN("444p16", IMGFMT_444P16) + FMT_ENDIAN("444p14", IMGFMT_444P14) + FMT_ENDIAN("444p12", IMGFMT_444P12) + FMT_ENDIAN("444p10", IMGFMT_444P10) + FMT_ENDIAN("444p9", IMGFMT_444P9) + FMT_ENDIAN("422p16", IMGFMT_422P16) + FMT_ENDIAN("422p14", IMGFMT_422P14) + FMT_ENDIAN("422p12", IMGFMT_422P12) + FMT_ENDIAN("422p10", IMGFMT_422P10) + FMT_ENDIAN("422p9", IMGFMT_422P9) + FMT_ENDIAN("420p16", IMGFMT_420P16) + FMT_ENDIAN("420p14", IMGFMT_420P14) + FMT_ENDIAN("420p12", IMGFMT_420P12) + FMT_ENDIAN("420p10", IMGFMT_420P10) + FMT_ENDIAN("420p9", IMGFMT_420P9) + FMT("420ap", IMGFMT_420AP) + FMT("argb", IMGFMT_ARGB) + FMT("bgra", IMGFMT_BGRA) + FMT("bgr0", IMGFMT_BGR0) + FMT("abgr", IMGFMT_ABGR) + FMT("rgba", IMGFMT_RGBA) + FMT("rgb32", IMGFMT_RGB32) + FMT("bgr32", IMGFMT_BGR32) + FMT("bgr24", IMGFMT_BGR24) + FMT("rgb24", IMGFMT_RGB24) + FMT_ENDIAN("rgb48", IMGFMT_RGB48) + FMT("rgb8", IMGFMT_RGB8) + FMT("bgr8", IMGFMT_BGR8) + FMT("rgb4_byte", IMGFMT_RGB4_BYTE) + FMT("bgr4_byte", IMGFMT_BGR4_BYTE) + FMT("rgb4", IMGFMT_RGB4) + FMT("bgr4", IMGFMT_BGR4) + FMT("mono", IMGFMT_MONO) + FMT_ENDIAN("rgb12", IMGFMT_RGB12) + FMT_ENDIAN("rgb15", IMGFMT_RGB15) + FMT_ENDIAN("rgb16", IMGFMT_RGB16) + FMT_ENDIAN("bgr12", IMGFMT_BGR12) + FMT_ENDIAN("bgr15", IMGFMT_BGR15) + FMT_ENDIAN("bgr16", IMGFMT_BGR16) + FMT("pal8", IMGFMT_PAL8) + FMT("gbrp", IMGFMT_GBRP) + FMT("vdpau_mpeg1", IMGFMT_VDPAU_MPEG1) + FMT("vdpau_mpeg2", IMGFMT_VDPAU_MPEG2) + FMT("vdpau_h264", IMGFMT_VDPAU_H264) + FMT("vdpau_wmv3", IMGFMT_VDPAU_WMV3) + FMT("vdpau_vc1", IMGFMT_VDPAU_VC1) + FMT("vdpau_mpeg4", IMGFMT_VDPAU_MPEG4) {0} }; -const char *vo_format_name(int format) -{ - const char *name = mp_imgfmt_to_name(format); - if (name) - return name; - static char unknown_format[20]; - snprintf(unknown_format, 20, "Unknown 0x%04x", format); - return unknown_format; -} - int mp_get_chroma_shift(int format, int *x_shift, int *y_shift, int *component_bits) { @@ -162,12 +116,6 @@ int mp_get_chroma_shift(int format, int *x_shift, int *y_shift, unsigned int mp_imgfmt_from_name(bstr name, bool allow_hwaccel) { - 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)) @@ -241,8 +189,15 @@ static struct mp_imgfmt_desc get_avutil_fmt(enum PixelFormat fmt) desc.num_planes++; } - if (desc.bpp[0] <= 8 || !(pd->flags & PIX_FMT_BE)) - desc.flags |= MP_IMGFLAG_NE; + // Packed RGB formats are the only formats that have less than 8 bits per + // component, and still require endian dependent access. + if (pd->comp[0].depth_minus1 + 1 <= 8 && + !(mpfmt >= IMGFMT_RGB12_LE || mpfmt <= IMGFMT_BGR16_BE)) + { + desc.flags |= MP_IMGFLAG_LE | MP_IMGFLAG_BE; + } else { + desc.flags |= (pd->flags & PIX_FMT_BE) ? MP_IMGFLAG_BE : MP_IMGFLAG_LE; + } desc.plane_bits = planedepth[0]; @@ -297,20 +252,15 @@ static struct mp_imgfmt_desc get_avutil_fmt(enum PixelFormat fmt) // compatibility with old mp_image_setfmt() switch (desc.id) { - case IMGFMT_I420: - case IMGFMT_IYUV: - desc.flags |= MP_IMGFLAG_SWAPPED; // completely pointless - break; case IMGFMT_UYVY: desc.flags |= MP_IMGFLAG_SWAPPED; // for vf_mpi_clear() /* fallthrough */ - case IMGFMT_YUY2: + case IMGFMT_YUYV: desc.chroma_ys = 1; // ??? break; case IMGFMT_Y8: - case IMGFMT_Y800: - case IMGFMT_Y16LE: - case IMGFMT_Y16BE: + case IMGFMT_Y16_LE: + case IMGFMT_Y16_BE: // probably for vo_opengl, and possibly more code using Y8 desc.chroma_xs = desc.chroma_ys = 31; break; @@ -324,7 +274,6 @@ static struct mp_imgfmt_desc get_avutil_fmt(enum PixelFormat fmt) break; case IMGFMT_RGB4: case IMGFMT_BGR4: - case IMGFMT_BGR1: desc.flags ^= MP_IMGFLAG_SWAPPED; // ??? break; case IMGFMT_BGR0: @@ -335,6 +284,12 @@ static struct mp_imgfmt_desc get_avutil_fmt(enum PixelFormat fmt) if (pd->flags & PIX_FMT_HWACCEL) desc.chroma_xs = desc.chroma_ys = 0; + if (!(pd->flags & PIX_FMT_HWACCEL) && !(pd->flags & PIX_FMT_BITSTREAM)) { + desc.flags |= MP_IMGFLAG_BYTE_ALIGNED; + for (int p = 0; p < desc.num_planes; p++) + desc.bytes[p] = desc.bpp[p] / 8; + } + for (int p = 0; p < desc.num_planes; p++) { desc.xs[p] = (p == 1 || p == 2) ? desc.chroma_xs : 0; desc.ys[p] = (p == 1 || p == 2) ? desc.chroma_ys : 0; diff --git a/video/img_format.h b/video/img_format.h index 48780cc694..1f617b573b 100644 --- a/video/img_format.h +++ b/video/img_format.h @@ -19,12 +19,20 @@ #ifndef MPLAYER_IMG_FORMAT_H #define MPLAYER_IMG_FORMAT_H +#include <inttypes.h> #include <sys/types.h> -#include "config.h" #include "core/bstr.h" +#if BYTE_ORDER == BIG_ENDIAN +#define MP_SELECT_LE_BE(LE, BE) BE +#else +#define MP_SELECT_LE_BE(LE, BE) LE +#endif + #define MP_MAX_PLANES 4 +// All pixels start in byte boundaries +#define MP_IMGFLAG_BYTE_ALIGNED 0x1 // set if (possibly) alpha is included (might be not definitive for packed RGB) #define MP_IMGFLAG_ALPHA 0x80 // set if number of planes > 1 @@ -33,14 +41,18 @@ #define MP_IMGFLAG_YUV 0x200 // set if it's swapped (BGR or YVU) plane/byteorder #define MP_IMGFLAG_SWAPPED 0x400 -// set if the format is standard YUV format: +// set if the format is in a standard YUV format: // - planar and yuv colorspace // - chroma shift 0-2 // - 1-4 planes (1: gray, 2: gray/alpha, 3: yuv, 4: yuv/alpha) // - 8-16 bit per pixel/plane, all planes have same depth #define MP_IMGFLAG_YUV_P 0x1000 -// set if format is in native endian, or <= 8 bit per pixel/plane -#define MP_IMGFLAG_NE 0x2000 +// set if in little endian, or endian independent +#define MP_IMGFLAG_LE 0x2000 +// set if in big endian, or endian independent +#define MP_IMGFLAG_BE 0x4000 +// set if in native (host) endian, or endian independent +#define MP_IMGFLAG_NE MP_SELECT_LE_BE(MP_IMGFLAG_LE, MP_IMGFLAG_BE) #define MP_IMGFLAG_FMT_MASK 0x3FFF @@ -49,92 +61,181 @@ struct mp_imgfmt_desc { int avformat; // AV_PIX_FMT_* (or AV_PIX_FMT_NONE) const char *name; // e.g. "420p16" int flags; // MP_IMGFLAG_* bitfield - int num_planes; - int chroma_xs, chroma_ys; // chroma shift (i.e. log2 of chroma pixel size) - int avg_bpp; - int bpp[MP_MAX_PLANES]; - int plane_bits; // number of bits in use for plane 0 + int8_t num_planes; + int8_t chroma_xs, chroma_ys; // chroma shift (i.e. log2 of chroma pixel size) + int8_t avg_bpp; + int8_t bytes[MP_MAX_PLANES]; // bytes per pixel (MP_IMGFLAG_BYTE_ALIGNED) + int8_t bpp[MP_MAX_PLANES]; // bits per pixel + int8_t plane_bits; // number of bits in use for plane 0 // chroma shifts per plane (provided for convenience with planar formats) - int xs[MP_MAX_PLANES]; - int ys[MP_MAX_PLANES]; + int8_t xs[MP_MAX_PLANES]; + int8_t ys[MP_MAX_PLANES]; }; struct mp_imgfmt_desc mp_imgfmt_get_desc(unsigned int out_fmt); -/* RGB/BGR Formats */ - -#define IMGFMT_RGB_MASK 0xFFFFFF00 -#define IMGFMT_RGB (('R'<<24)|('G'<<16)|('B'<<8)) -#define IMGFMT_RGB1 (IMGFMT_RGB|1) -#define IMGFMT_RGB4 (IMGFMT_RGB|4) -#define IMGFMT_RGB4_CHAR (IMGFMT_RGB|4|128) // RGB4 with 1 pixel per byte -#define IMGFMT_RGB8 (IMGFMT_RGB|8) -#define IMGFMT_RGB12 (IMGFMT_RGB|12) -#define IMGFMT_RGB15 (IMGFMT_RGB|15) -#define IMGFMT_RGB16 (IMGFMT_RGB|16) -#define IMGFMT_RGB24 (IMGFMT_RGB|24) -#define IMGFMT_RGB32 (IMGFMT_RGB|32) -#define IMGFMT_RGB48LE (IMGFMT_RGB|48) -#define IMGFMT_RGB48BE (IMGFMT_RGB|48|128) - -#define IMGFMT_BGR_MASK 0xFFFFFF00 -#define IMGFMT_BGR (('B'<<24)|('G'<<16)|('R'<<8)) -#define IMGFMT_BGR1 (IMGFMT_BGR|1) -#define IMGFMT_BGR4 (IMGFMT_BGR|4) -#define IMGFMT_BGR4_CHAR (IMGFMT_BGR|4|128) // BGR4 with 1 pixel per byte -#define IMGFMT_BGR8 (IMGFMT_BGR|8) -#define IMGFMT_BGR12 (IMGFMT_BGR|12) -#define IMGFMT_BGR15 (IMGFMT_BGR|15) -#define IMGFMT_BGR16 (IMGFMT_BGR|16) -#define IMGFMT_BGR24 (IMGFMT_BGR|24) -#define IMGFMT_BGR32 (IMGFMT_BGR|32) - -#define IMGFMT_GBRP (('G'<<24)|('B'<<16)|('R'<<8)|24) - -#if BYTE_ORDER == BIG_ENDIAN -#define IMGFMT_ABGR IMGFMT_RGB32 -#define IMGFMT_BGRA (IMGFMT_RGB32|128) -#define IMGFMT_ARGB IMGFMT_BGR32 -#define IMGFMT_RGBA (IMGFMT_BGR32|128) -#define IMGFMT_RGB48NE IMGFMT_RGB48BE -#define IMGFMT_RGB12BE IMGFMT_RGB12 -#define IMGFMT_RGB12LE (IMGFMT_RGB12|128) -#define IMGFMT_RGB15BE IMGFMT_RGB15 -#define IMGFMT_RGB15LE (IMGFMT_RGB15|128) -#define IMGFMT_RGB16BE IMGFMT_RGB16 -#define IMGFMT_RGB16LE (IMGFMT_RGB16|128) -#define IMGFMT_BGR12BE IMGFMT_BGR12 -#define IMGFMT_BGR12LE (IMGFMT_BGR12|128) -#define IMGFMT_BGR15BE IMGFMT_BGR15 -#define IMGFMT_BGR15LE (IMGFMT_BGR15|128) -#define IMGFMT_BGR16BE IMGFMT_BGR16 -#define IMGFMT_BGR16LE (IMGFMT_BGR16|128) -#else -#define IMGFMT_ABGR (IMGFMT_BGR32|128) -#define IMGFMT_BGRA IMGFMT_BGR32 -#define IMGFMT_ARGB (IMGFMT_RGB32|128) -#define IMGFMT_RGBA IMGFMT_RGB32 -#define IMGFMT_RGB48NE IMGFMT_RGB48LE -#define IMGFMT_RGB12BE (IMGFMT_RGB12|128) -#define IMGFMT_RGB12LE IMGFMT_RGB12 -#define IMGFMT_RGB15BE (IMGFMT_RGB15|128) -#define IMGFMT_RGB15LE IMGFMT_RGB15 -#define IMGFMT_RGB16BE (IMGFMT_RGB16|128) -#define IMGFMT_RGB16LE IMGFMT_RGB16 -#define IMGFMT_BGR12BE (IMGFMT_BGR12|128) -#define IMGFMT_BGR12LE IMGFMT_BGR12 -#define IMGFMT_BGR15BE (IMGFMT_BGR15|128) -#define IMGFMT_BGR15LE IMGFMT_BGR15 -#define IMGFMT_BGR16BE (IMGFMT_BGR16|128) -#define IMGFMT_BGR16LE IMGFMT_BGR16 -#endif - -/* old names for compatibility */ -#define IMGFMT_RG4B IMGFMT_RGB4_CHAR -#define IMGFMT_BG4B IMGFMT_BGR4_CHAR - -// AV_PIX_FMT_BGR0 -#define IMGFMT_BGR0 0x1DC70000 +enum mp_imgfmt { + IMGFMT_NONE = 0, + + // Offset to make confusing with ffmpeg formats harder + IMGFMT_START = 1000, + + // Planar YUV formats + + IMGFMT_444P, // 1x1 + IMGFMT_422P, // 2x1 + IMGFMT_440P, // 1x2 + IMGFMT_420P, // 2x2 + IMGFMT_411P, // 4x1 + IMGFMT_410P, // 4x4 + + // YUV formats with 2 bytes per plane-pixel. Formats with 9-15 bits pad the + // most significant bits with 0 (use shifts to expand them to 16 bits). + + IMGFMT_444P16_LE, + IMGFMT_444P16_BE, + IMGFMT_444P14_LE, + IMGFMT_444P14_BE, + IMGFMT_444P12_LE, + IMGFMT_444P12_BE, + IMGFMT_444P10_LE, + IMGFMT_444P10_BE, + IMGFMT_444P9_LE, + IMGFMT_444P9_BE, + + IMGFMT_422P16_LE, + IMGFMT_422P16_BE, + IMGFMT_422P14_LE, + IMGFMT_422P14_BE, + IMGFMT_422P12_LE, + IMGFMT_422P12_BE, + IMGFMT_422P10_LE, + IMGFMT_422P10_BE, + IMGFMT_422P9_LE, + IMGFMT_422P9_BE, + + IMGFMT_420P16_LE, + IMGFMT_420P16_BE, + IMGFMT_420P14_LE, + IMGFMT_420P14_BE, + IMGFMT_420P12_LE, + IMGFMT_420P12_BE, + IMGFMT_420P10_LE, + IMGFMT_420P10_BE, + IMGFMT_420P9_LE, + IMGFMT_420P9_BE, + + // Planar YUV with alpha (4th plane) + IMGFMT_420AP, + + // Gray + IMGFMT_Y8, + IMGFMT_Y16_LE, + IMGFMT_Y16_BE, + + // Packed YUV formats (components are byte-accessed) + IMGFMT_YUYV, // Y0 U Y1 V + IMGFMT_UYVY, // U Y0 V Y1 + + // Y plane + packed plane for chroma + IMGFMT_NV12, + IMGFMT_NV21, + + // RGB/BGR Formats + + // Byte accessed (low address to high address) + IMGFMT_ARGB, + IMGFMT_BGRA, + IMGFMT_BGR0, + IMGFMT_ABGR, + IMGFMT_RGBA, + IMGFMT_BGR24, + IMGFMT_RGB24, + IMGFMT_RGB48_LE, + IMGFMT_RGB48_BE, + + // Accessed with bit-shifts (components ordered from LSB to MSB) + IMGFMT_RGB8, // r3 g3 b2 + IMGFMT_BGR8, + IMGFMT_RGB4_BYTE, // r1 g2 b1 with 1 pixel per byte + IMGFMT_BGR4_BYTE, + IMGFMT_RGB4, // r1 g2 b1, bit-packed + IMGFMT_BGR4, + IMGFMT_MONO, // 1 bit per pixel, bit-packed + + // Accessed with bit-shifts after endian-swapping the uint16_t pixel + IMGFMT_RGB12_LE, // 4r 4g 4b 4a (LSB to MSB) + IMGFMT_RGB12_BE, + IMGFMT_RGB15_LE, // 5r 5g 5b 1a + IMGFMT_RGB15_BE, + IMGFMT_RGB16_LE, // 5r 6g 5b + IMGFMT_RGB16_BE, + IMGFMT_BGR12_LE, // 4b 4r 4g 4a + IMGFMT_BGR12_BE, + IMGFMT_BGR15_LE, // 5b 5g 5r 1a + IMGFMT_BGR15_BE, + IMGFMT_BGR16_LE, // 5b 6g 5r + IMGFMT_BGR16_BE, + + IMGFMT_PAL8, // Palette entries are IMGFMT_BGR32 + + // Planar RGB (planes are shuffled: plane 0 is G, etc.) + IMGFMT_GBRP, + + // Hardware acclerated formats. Plane data points to special data + // structures, instead of pixel data. + + IMGFMT_VDPAU_MPEG1, + IMGFMT_VDPAU_MPEG2, + IMGFMT_VDPAU_H264, + IMGFMT_VDPAU_WMV3, + IMGFMT_VDPAU_VC1, + IMGFMT_VDPAU_MPEG4, + + IMGFMT_VDPAU_FIRST = IMGFMT_VDPAU_MPEG1, + IMGFMT_VDPAU_LAST = IMGFMT_VDPAU_MPEG4, + + IMGFMT_END, + + // Redundant format aliases for native endian access + // For all formats that have _LE/_BE, define a native-endian entry without + // the suffix. + + // The IMGFMT_RGB32 and IMGFMT_BGR32 formats provide bit-shift access to + // normally byte-accessed formats: + // IMGFMT_RGB32 = r | (g << 8) | (b << 16) | (a << 24) + // IMGFMT_BGR32 = b | (g << 8) | (r << 16) | (a << 24) + IMGFMT_RGB32 = MP_SELECT_LE_BE(IMGFMT_RGBA, IMGFMT_ABGR), + IMGFMT_BGR32 = MP_SELECT_LE_BE(IMGFMT_BGRA, IMGFMT_ARGB), + + IMGFMT_RGB12 = MP_SELECT_LE_BE(IMGFMT_RGB12_LE, IMGFMT_RGB12_BE), + IMGFMT_RGB15 = MP_SELECT_LE_BE(IMGFMT_RGB15_LE, IMGFMT_RGB15_BE), + IMGFMT_RGB16 = MP_SELECT_LE_BE(IMGFMT_RGB16_LE, IMGFMT_RGB16_BE), + IMGFMT_BGR12 = MP_SELECT_LE_BE(IMGFMT_BGR12_LE, IMGFMT_BGR12_BE), + IMGFMT_BGR15 = MP_SELECT_LE_BE(IMGFMT_BGR15_LE, IMGFMT_BGR15_BE), + IMGFMT_BGR16 = MP_SELECT_LE_BE(IMGFMT_BGR16_LE, IMGFMT_BGR16_BE), + IMGFMT_RGB48 = MP_SELECT_LE_BE(IMGFMT_RGB48_LE, IMGFMT_RGB48_BE), + + IMGFMT_444P16 = MP_SELECT_LE_BE(IMGFMT_444P16_LE, IMGFMT_444P16_BE), + IMGFMT_444P14 = MP_SELECT_LE_BE(IMGFMT_444P14_LE, IMGFMT_444P14_BE), + IMGFMT_444P12 = MP_SELECT_LE_BE(IMGFMT_444P12_LE, IMGFMT_444P12_BE), + IMGFMT_444P10 = MP_SELECT_LE_BE(IMGFMT_444P10_LE, IMGFMT_444P10_BE), + IMGFMT_444P9 = MP_SELECT_LE_BE(IMGFMT_444P9_LE, IMGFMT_444P9_BE), + + IMGFMT_422P16 = MP_SELECT_LE_BE(IMGFMT_422P16_LE, IMGFMT_422P16_BE), + IMGFMT_422P14 = MP_SELECT_LE_BE(IMGFMT_422P14_LE, IMGFMT_422P14_BE), + IMGFMT_422P12 = MP_SELECT_LE_BE(IMGFMT_422P12_LE, IMGFMT_422P12_BE), + IMGFMT_422P10 = MP_SELECT_LE_BE(IMGFMT_422P10_LE, IMGFMT_422P10_BE), + IMGFMT_422P9 = MP_SELECT_LE_BE(IMGFMT_422P9_LE, IMGFMT_422P9_BE), + + IMGFMT_420P16 = MP_SELECT_LE_BE(IMGFMT_420P16_LE, IMGFMT_420P16_BE), + IMGFMT_420P14 = MP_SELECT_LE_BE(IMGFMT_420P14_LE, IMGFMT_420P14_BE), + IMGFMT_420P12 = MP_SELECT_LE_BE(IMGFMT_420P12_LE, IMGFMT_420P12_BE), + IMGFMT_420P10 = MP_SELECT_LE_BE(IMGFMT_420P10_LE, IMGFMT_420P10_BE), + IMGFMT_420P9 = MP_SELECT_LE_BE(IMGFMT_420P9_LE, IMGFMT_420P9_BE), + + IMGFMT_Y16 = MP_SELECT_LE_BE(IMGFMT_Y16_LE, IMGFMT_Y16_BE), +}; static inline bool IMGFMT_IS_RGB(unsigned int fmt) { @@ -152,172 +253,31 @@ static inline bool IMGFMT_IS_BGR(unsigned int fmt) #define IMGFMT_RGB_DEPTH(fmt) (mp_imgfmt_get_desc(fmt).plane_bits) #define IMGFMT_BGR_DEPTH(fmt) (mp_imgfmt_get_desc(fmt).plane_bits) -// AV_PIX_FMT_GRAY16LE -#define IMGFMT_Y16LE 0x1DC70001 -// AV_PIX_FMT_GRAY16BE -#define IMGFMT_Y16BE 0x1DC70002 -// AV_PIX_FMT_PAL8 -#define IMGFMT_PAL8 0x1DC70003 - #if BYTE_ORDER == BIG_ENDIAN -#define IMGFMT_Y16 IMGFMT_Y16BE -#else -#define IMGFMT_Y16 IMGFMT_Y16LE -#endif - -/* Planar YUV Formats */ - -#define IMGFMT_YVU9 0x39555659 -#define IMGFMT_IF09 0x39304649 -#define IMGFMT_YV12 0x32315659 -#define IMGFMT_I420 0x30323449 -#define IMGFMT_IYUV 0x56555949 -#define IMGFMT_CLPL 0x4C504C43 -#define IMGFMT_Y800 0x30303859 -#define IMGFMT_Y8 0x20203859 -#define IMGFMT_NV12 0x3231564E -#define IMGFMT_NV21 0x3132564E - -/* unofficial Planar Formats, FIXME if official 4CC exists */ -#define IMGFMT_444P 0x50343434 -#define IMGFMT_422P 0x50323234 -#define IMGFMT_411P 0x50313134 -#define IMGFMT_440P 0x50303434 -#define IMGFMT_HM12 0x32314D48 - -// 4:2:0 planar with alpha -#define IMGFMT_420A 0x41303234 - -#define IMGFMT_444P16_LE 0x51343434 -#define IMGFMT_444P16_BE 0x34343451 -#define IMGFMT_444P10_LE 0x52343434 -#define IMGFMT_444P10_BE 0x34343452 -#define IMGFMT_444P9_LE 0x53343434 -#define IMGFMT_444P9_BE 0x34343453 -#define IMGFMT_444P12_LE 0x54343434 -#define IMGFMT_444P12_BE 0x34343454 -#define IMGFMT_444P14_LE 0x55343434 -#define IMGFMT_444P14_BE 0x34343455 -#define IMGFMT_422P16_LE 0x51323234 -#define IMGFMT_422P16_BE 0x34323251 -#define IMGFMT_422P10_LE 0x52323234 -#define IMGFMT_422P10_BE 0x34323252 -#define IMGFMT_422P9_LE 0x53323234 -#define IMGFMT_422P9_BE 0x34323253 -#define IMGFMT_422P12_LE 0x54323234 -#define IMGFMT_422P12_BE 0x34323254 -#define IMGFMT_422P14_LE 0x55323234 -#define IMGFMT_422P14_BE 0x34323255 -#define IMGFMT_420P16_LE 0x51303234 -#define IMGFMT_420P16_BE 0x34323051 -#define IMGFMT_420P10_LE 0x52303234 -#define IMGFMT_420P10_BE 0x34323052 -#define IMGFMT_420P9_LE 0x53303234 -#define IMGFMT_420P9_BE 0x34323053 -#define IMGFMT_420P12_LE 0x54303234 -#define IMGFMT_420P12_BE 0x34323054 -#define IMGFMT_420P14_LE 0x55303234 -#define IMGFMT_420P14_BE 0x34323055 -#if BYTE_ORDER == BIG_ENDIAN -#define IMGFMT_444P16 IMGFMT_444P16_BE -#define IMGFMT_444P14 IMGFMT_444P14_BE -#define IMGFMT_444P12 IMGFMT_444P12_BE -#define IMGFMT_444P10 IMGFMT_444P10_BE -#define IMGFMT_444P9 IMGFMT_444P9_BE -#define IMGFMT_422P16 IMGFMT_422P16_BE -#define IMGFMT_422P14 IMGFMT_422P14_BE -#define IMGFMT_422P12 IMGFMT_422P12_BE -#define IMGFMT_422P10 IMGFMT_422P10_BE -#define IMGFMT_422P9 IMGFMT_422P9_BE -#define IMGFMT_420P16 IMGFMT_420P16_BE -#define IMGFMT_420P14 IMGFMT_420P14_BE -#define IMGFMT_420P12 IMGFMT_420P12_BE -#define IMGFMT_420P10 IMGFMT_420P10_BE -#define IMGFMT_420P9 IMGFMT_420P9_BE #define IMGFMT_IS_YUVP16_NE(fmt) IMGFMT_IS_YUVP16_BE(fmt) #else -#define IMGFMT_444P16 IMGFMT_444P16_LE -#define IMGFMT_444P14 IMGFMT_444P14_LE -#define IMGFMT_444P12 IMGFMT_444P12_LE -#define IMGFMT_444P10 IMGFMT_444P10_LE -#define IMGFMT_444P9 IMGFMT_444P9_LE -#define IMGFMT_422P16 IMGFMT_422P16_LE -#define IMGFMT_422P14 IMGFMT_422P14_LE -#define IMGFMT_422P12 IMGFMT_422P12_LE -#define IMGFMT_422P10 IMGFMT_422P10_LE -#define IMGFMT_422P9 IMGFMT_422P9_LE -#define IMGFMT_420P16 IMGFMT_420P16_LE -#define IMGFMT_420P14 IMGFMT_420P14_LE -#define IMGFMT_420P12 IMGFMT_420P12_LE -#define IMGFMT_420P10 IMGFMT_420P10_LE -#define IMGFMT_420P9 IMGFMT_420P9_LE #define IMGFMT_IS_YUVP16_NE(fmt) IMGFMT_IS_YUVP16_LE(fmt) #endif // These functions are misnamed - they actually match 9 to 16 bits (inclusive) static inline bool IMGFMT_IS_YUVP16_LE(int fmt) { struct mp_imgfmt_desc desc = mp_imgfmt_get_desc(fmt); - bool le_is_ne = BYTE_ORDER == LITTLE_ENDIAN; return (desc.flags & MP_IMGFLAG_YUV_P) && desc.plane_bits > 8 && - (le_is_ne == !!(desc.flags & MP_IMGFLAG_NE)); + (desc.flags & MP_IMGFLAG_LE); } static inline bool IMGFMT_IS_YUVP16_BE(int fmt) { struct mp_imgfmt_desc desc = mp_imgfmt_get_desc(fmt); - bool be_is_ne = BYTE_ORDER == BIG_ENDIAN; return (desc.flags & MP_IMGFLAG_YUV_P) && desc.plane_bits > 8 && - (be_is_ne == !!(desc.flags & MP_IMGFLAG_NE)); + (desc.flags & MP_IMGFLAG_BE); } #define IMGFMT_IS_YUVP16(fmt) (IMGFMT_IS_YUVP16_LE(fmt) || IMGFMT_IS_YUVP16_BE(fmt)) -/* Packed YUV Formats */ - -#define IMGFMT_IUYV 0x56595549 // Interlaced UYVY -#define IMGFMT_IY41 0x31435949 // Interlaced Y41P -#define IMGFMT_IYU1 0x31555949 -#define IMGFMT_IYU2 0x32555949 -#define IMGFMT_UYVY 0x59565955 -#define IMGFMT_UYNV 0x564E5955 // Exactly same as UYVY -#define IMGFMT_cyuv 0x76757963 // upside-down UYVY -#define IMGFMT_Y422 0x32323459 // Exactly same as UYVY -#define IMGFMT_YUY2 0x32595559 -#define IMGFMT_YUNV 0x564E5559 // Exactly same as YUY2 -#define IMGFMT_YVYU 0x55595659 -#define IMGFMT_Y41P 0x50313459 -#define IMGFMT_Y211 0x31313259 -#define IMGFMT_Y41T 0x54313459 // Y41P, Y lsb = transparency -#define IMGFMT_Y42T 0x54323459 // UYVY, Y lsb = transparency -#define IMGFMT_V422 0x32323456 // upside-down UYVY? -#define IMGFMT_V655 0x35353656 -#define IMGFMT_CLJR 0x524A4C43 -#define IMGFMT_YUVP 0x50565559 // 10-bit YUYV -#define IMGFMT_UYVP 0x50565955 // 10-bit UYVY - -/* Compressed Formats */ -#define IMGFMT_MJPEG (('M')|('J'<<8)|('P'<<16)|('G'<<24)) - -// VDPAU specific format. -#define IMGFMT_VDPAU 0x1DC80000 -#define IMGFMT_VDPAU_MASK 0xFFFF0000 -#define IMGFMT_IS_VDPAU(fmt) (((fmt)&IMGFMT_VDPAU_MASK)==IMGFMT_VDPAU) -#define IMGFMT_VDPAU_MPEG1 (IMGFMT_VDPAU|0x01) -#define IMGFMT_VDPAU_MPEG2 (IMGFMT_VDPAU|0x02) -#define IMGFMT_VDPAU_H264 (IMGFMT_VDPAU|0x03) -#define IMGFMT_VDPAU_WMV3 (IMGFMT_VDPAU|0x04) -#define IMGFMT_VDPAU_VC1 (IMGFMT_VDPAU|0x05) -#define IMGFMT_VDPAU_MPEG4 (IMGFMT_VDPAU|0x06) +#define IMGFMT_IS_VDPAU(fmt) \ + (((fmt) >= IMGFMT_VDPAU_FIRST) && ((fmt) <= IMGFMT_VDPAU_LAST)) #define IMGFMT_IS_HWACCEL(fmt) IMGFMT_IS_VDPAU(fmt) -typedef struct { - void* data; - int size; - int id; // stream id. usually 0x1E0 - int timestamp; // pts, 90000 Hz counter based -} vo_mpegpes_t; - -const char *vo_format_name(int format); - /** * Calculates the scale shifts for the chroma planes for planar YUV * @@ -336,4 +296,6 @@ extern struct mp_imgfmt_entry mp_imgfmt_list[]; unsigned int mp_imgfmt_from_name(bstr name, bool allow_hwaccel); const char *mp_imgfmt_to_name(unsigned int fmt); +#define vo_format_name mp_imgfmt_to_name + #endif /* MPLAYER_IMG_FORMAT_H */ diff --git a/video/img_fourcc.h b/video/img_fourcc.h new file mode 100644 index 0000000000..fecb13f297 --- /dev/null +++ b/video/img_fourcc.h @@ -0,0 +1,57 @@ +#ifndef MPV_IMG_FOURCC_H +#define MPV_IMG_FOURCC_H + +#include <sys/types.h> + +#define MP_FOURCC(a,b,c,d) ((a) | ((b)<<8) | ((c)<<16) | ((unsigned)(d)<<24)) + +#if BYTE_ORDER == BIG_ENDIAN +#define MP_FOURCC_E(a,b,c,d) MP_FOURCC(a,b,c,d) +#else +#define MP_FOURCC_E(a,b,c,d) MP_FOURCC(d,c,b,a) +#endif + +#define MP_FOURCC_RGB8 MP_FOURCC_E(8, 'B', 'G', 'R') +#define MP_FOURCC_RGB12 MP_FOURCC_E(12, 'B', 'G', 'R') +#define MP_FOURCC_RGB15 MP_FOURCC_E(15, 'B', 'G', 'R') +#define MP_FOURCC_RGB16 MP_FOURCC_E(16, 'B', 'G', 'R') +#define MP_FOURCC_RGB24 MP_FOURCC_E(24, 'B', 'G', 'R') +#define MP_FOURCC_RGB32 MP_FOURCC_E('A', 'B', 'G', 'R') + +#define MP_FOURCC_BGR8 MP_FOURCC_E(8, 'R', 'G', 'B') +#define MP_FOURCC_BGR12 MP_FOURCC_E(12, 'R', 'G', 'B') +#define MP_FOURCC_BGR15 MP_FOURCC_E(15, 'R', 'G', 'B') +#define MP_FOURCC_BGR16 MP_FOURCC_E(16, 'R', 'G', 'B') +#define MP_FOURCC_BGR24 MP_FOURCC_E(24, 'R', 'G', 'B') +#define MP_FOURCC_BGR32 MP_FOURCC_E('A', 'R', 'G', 'B') + +#define MP_FOURCC_YVU9 MP_FOURCC('Y', 'U', 'V', '9') +#define MP_FOURCC_YUV9 MP_FOURCC('Y', 'V', 'U', '9') +#define MP_FOURCC_YV12 MP_FOURCC('Y', 'V', '1', '2') +#define MP_FOURCC_I420 MP_FOURCC('I', '4', '2', '0') +#define MP_FOURCC_IYUV MP_FOURCC('I', 'Y', 'U', 'V') +#define MP_FOURCC_Y800 MP_FOURCC('Y', '8', '0', '0') +#define MP_FOURCC_Y8 MP_FOURCC('Y', '8', ' ', ' ') +#define MP_FOURCC_NV12 MP_FOURCC('N', 'V', '1', '2') +#define MP_FOURCC_NV21 MP_FOURCC('N', 'V', '2', '1') + +#define MP_FOURCC_UYVY MP_FOURCC('U', 'Y', 'V', 'Y') +#define MP_FOURCC_YUY2 MP_FOURCC('Y', 'U', 'Y', '2') + +#define MP_FOURCC_MJPEG MP_FOURCC('M', 'J', 'P', 'G') + +/* mplayer internal FourCCs + * see codecs.conf/vd_lavc.c + */ + +// lavc raw video decoder uses fourcc specified in sh_video->imgfmt +#define MP_FOURCC_RAWVIDEO MP_FOURCC('M', 'P', 'r', 'v') + +// lavc raw video decoder uses image format (IMGFMT_*) in sh_video->imgfmt +#define MP_FOURCC_IMGFMT MP_FOURCC('M', 'P', 'v', 'f') + +// NOTE: no "HM12" decoder exists, as vd_hmblck has been removed +// likely breaks video with some TV cards +#define MP_FOURCC_HM12 0x32314D48 + +#endif diff --git a/video/out/gl_common.c b/video/out/gl_common.c index b7b30702a6..697b1bbbbc 100644 --- a/video/out/gl_common.c +++ b/video/out/gl_common.c @@ -141,13 +141,13 @@ int glFindFormat(uint32_t fmt, int have_texture_rg, int *bpp, GLint *gl_texfmt, else if (IMGFMT_IS_YUVP16_BE(fmt)) fmt = IMGFMT_420P16_BE; else - fmt = IMGFMT_YV12; + fmt = IMGFMT_420P; } *bpp = IMGFMT_IS_BGR(fmt) ? IMGFMT_BGR_DEPTH(fmt) : IMGFMT_RGB_DEPTH(fmt); *gl_texfmt = 3; switch (fmt) { - case IMGFMT_RGB48NE: + case IMGFMT_RGB48: *gl_format = GL_RGB; *gl_type = GL_UNSIGNED_SHORT; break; @@ -167,9 +167,8 @@ int glFindFormat(uint32_t fmt, int have_texture_rg, int *bpp, GLint *gl_texfmt, *gl_format = have_texture_rg ? GL_RED : GL_LUMINANCE; *gl_type = GL_UNSIGNED_SHORT; break; - case IMGFMT_YV12: + case IMGFMT_420P: supported = 0; // no native YV12 support - case IMGFMT_Y800: case IMGFMT_Y8: *gl_texfmt = 1; *bpp = 8; @@ -177,9 +176,6 @@ int glFindFormat(uint32_t fmt, int have_texture_rg, int *bpp, GLint *gl_texfmt, *gl_type = GL_UNSIGNED_BYTE; break; case IMGFMT_UYVY: - // IMGFMT_YUY2 would be more logical for the _REV format, - // but gives clearly swapped colors. - case IMGFMT_YVYU: *gl_texfmt = GL_YCBCR_MESA; *bpp = 16; *gl_format = GL_YCBCR_MESA; diff --git a/video/out/vo.h b/video/out/vo.h index eb55417f4c..73eb19c8d7 100644 --- a/video/out/vo.h +++ b/video/out/vo.h @@ -156,7 +156,7 @@ struct vo_driver { /* * Whether the given image format is supported and config() will succeed. - * format: fourcc of pixel format + * format: one of IMGFMT_* * returns: 0 on not supported, otherwise a bitmask of VFCAP_* values */ int (*query_format)(struct vo *vo, uint32_t format); diff --git a/video/out/vo_corevideo.m b/video/out/vo_corevideo.m index 5e1ecf25a7..a31a2bd7b1 100644 --- a/video/out/vo_corevideo.m +++ b/video/out/vo_corevideo.m @@ -248,7 +248,7 @@ static int query_format(struct vo *vo, uint32_t format) const int flags = VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW | VFCAP_OSD; switch (format) { - case IMGFMT_YUY2: + case IMGFMT_YUYV: p->pixelFormat = kYUVSPixelFormat; return flags; @@ -346,7 +346,7 @@ static int get_image_fmt(struct vo *vo) { struct priv *p = vo->priv; switch (p->pixelFormat) { - case kYUVSPixelFormat: return IMGFMT_YUY2; + case kYUVSPixelFormat: return IMGFMT_YUYV; case k24RGBPixelFormat: return IMGFMT_RGB24; case k32ARGBPixelFormat: return IMGFMT_ARGB; case k32BGRAPixelFormat: return IMGFMT_BGRA; diff --git a/video/out/vo_direct3d.c b/video/out/vo_direct3d.c index 51caaf2be9..6dbf1d3d59 100644 --- a/video/out/vo_direct3d.c +++ b/video/out/vo_direct3d.c @@ -202,12 +202,12 @@ struct fmt_entry { static const struct fmt_entry fmt_table[] = { // planar YUV - {IMGFMT_YV12, MAKEFOURCC('Y','V','1','2')}, - {IMGFMT_I420, MAKEFOURCC('I','4','2','0')}, - {IMGFMT_IYUV, MAKEFOURCC('I','Y','U','V')}, - {IMGFMT_YVU9, MAKEFOURCC('Y','V','U','9')}, + {IMGFMT_420P, MAKEFOURCC('Y','V','1','2')}, + {IMGFMT_420P, MAKEFOURCC('I','4','2','0')}, + {IMGFMT_420P, MAKEFOURCC('I','Y','U','V')}, + {IMGFMT_410P, MAKEFOURCC('Y','V','U','9')}, // packed YUV - {IMGFMT_YUY2, D3DFMT_YUY2}, + {IMGFMT_YUYV, D3DFMT_YUY2}, {IMGFMT_UYVY, D3DFMT_UYVY}, // packed RGB {IMGFMT_BGR32, D3DFMT_X8R8G8B8}, @@ -1460,7 +1460,7 @@ static int control(struct vo *vo, uint32_t request, void *data) * @param d_height Screen (destination) height * @param options Options bitmap * @param format Movie colorspace format (using MPlayer's - * defines, e.g. IMGFMT_YUY2) + * defines, e.g. IMGFMT_YUYV) * @return 0 on success, VO_ERROR on failure */ static int config(struct vo *vo, uint32_t width, uint32_t height, diff --git a/video/out/vo_opengl.c b/video/out/vo_opengl.c index 665e008178..d0c435c59a 100644 --- a/video/out/vo_opengl.c +++ b/video/out/vo_opengl.c @@ -237,7 +237,7 @@ struct fmt_entry { }; static const struct fmt_entry mp_to_gl_formats[] = { - {IMGFMT_RGB48NE, GL_RGB16, GL_RGB, 16, GL_UNSIGNED_SHORT}, + {IMGFMT_RGB48, GL_RGB16, GL_RGB, 16, GL_UNSIGNED_SHORT}, {IMGFMT_RGB24, GL_RGB, GL_RGB, 8, GL_UNSIGNED_BYTE}, {IMGFMT_RGBA, GL_RGBA, GL_RGBA, 8, GL_UNSIGNED_BYTE}, {IMGFMT_RGB15, GL_RGBA, GL_RGBA, 5, GL_UNSIGNED_SHORT_1_5_5_5_REV}, diff --git a/video/out/vo_opengl_old.c b/video/out/vo_opengl_old.c index 6605876226..de38fcb067 100644 --- a/video/out/vo_opengl_old.c +++ b/video/out/vo_opengl_old.c @@ -831,9 +831,9 @@ static int query_format(struct vo *vo, uint32_t format) return caps; // HACK, otherwise we get only b&w with some filters (e.g. -vf eq) // ideally MPlayer should be fixed instead not to use Y800 when it has the choice - if (!p->use_yuv && (format == IMGFMT_Y8 || format == IMGFMT_Y800)) + if (!p->use_yuv && (format == IMGFMT_Y8)) return 0; - if (!p->use_ycbcr && (format == IMGFMT_UYVY || format == IMGFMT_YVYU)) + if (!p->use_ycbcr && (format == IMGFMT_UYVY)) return 0; if (p->many_fmts && glFindFormat(format, p->have_texture_rg, NULL, NULL, NULL, NULL)) diff --git a/video/out/vo_sdl.c b/video/out/vo_sdl.c index c3ed3c6774..d760aff50c 100644 --- a/video/out/vo_sdl.c +++ b/video/out/vo_sdl.c @@ -54,11 +54,11 @@ struct formatmap_entry { int is_rgba; }; const struct formatmap_entry formats[] = { - {SDL_PIXELFORMAT_YV12, IMGFMT_YV12, 0}, - {SDL_PIXELFORMAT_IYUV, IMGFMT_IYUV, 0}, - {SDL_PIXELFORMAT_YUY2, IMGFMT_YUY2, 0}, + {SDL_PIXELFORMAT_YV12, IMGFMT_420P, 0}, + {SDL_PIXELFORMAT_IYUV, IMGFMT_420P, 0}, + {SDL_PIXELFORMAT_YUY2, IMGFMT_YUYV, 0}, {SDL_PIXELFORMAT_UYVY, IMGFMT_UYVY, 0}, - {SDL_PIXELFORMAT_YVYU, IMGFMT_YVYU, 0}, + //{SDL_PIXELFORMAT_YVYU, IMGFMT_YVYU, 0}, #if BYTE_ORDER == BIG_ENDIAN {SDL_PIXELFORMAT_RGBX8888, IMGFMT_RGBA, 0}, // has no alpha -> bad for OSD {SDL_PIXELFORMAT_BGRX8888, IMGFMT_BGRA, 0}, // has no alpha -> bad for OSD @@ -172,6 +172,7 @@ struct priv { int renderer_index; SDL_RendererInfo renderer_info; SDL_Texture *tex; + int tex_swapped; mp_image_t texmpi; mp_image_t *ssmpi; struct mp_rect src_rect; @@ -427,6 +428,7 @@ static int config(struct vo *vo, uint32_t width, uint32_t height, return -1; } + vc->tex_swapped = texfmt == SDL_PIXELFORMAT_YV12; vc->tex = SDL_CreateTexture(vc->renderer, texfmt, SDL_TEXTUREACCESS_STREAMING, width, height); if (!vc->tex) { @@ -878,7 +880,7 @@ static void draw_image(struct vo *vo, mp_image_t *mpi) texmpi->planes[0] = pixels; texmpi->stride[0] = pitch; if (texmpi->num_planes == 3) { - if (texmpi->imgfmt == IMGFMT_YV12) { + if (vc->tex_swapped) { texmpi->planes[2] = ((Uint8 *) texmpi->planes[0] + texmpi->h * pitch); texmpi->stride[2] = pitch / 2; diff --git a/video/out/vo_vdpau.c b/video/out/vo_vdpau.c index 42c8bc6a24..1d5f0ed86c 100644 --- a/video/out/vo_vdpau.c +++ b/video/out/vo_vdpau.c @@ -756,15 +756,13 @@ static int initialize_vdpau_objects(struct vo *vo) vc->vdp_chroma_type = VDP_CHROMA_TYPE_420; switch (vc->image_format) { - case IMGFMT_YV12: - case IMGFMT_I420: - case IMGFMT_IYUV: + case IMGFMT_420P: vc->vdp_pixel_format = VDP_YCBCR_FORMAT_YV12; break; case IMGFMT_NV12: vc->vdp_pixel_format = VDP_YCBCR_FORMAT_NV12; break; - case IMGFMT_YUY2: + case IMGFMT_YUYV: vc->vdp_pixel_format = VDP_YCBCR_FORMAT_YUYV; vc->vdp_chroma_type = VDP_CHROMA_TYPE_422; break; @@ -1428,11 +1426,9 @@ static int query_format(struct vo *vo, uint32_t format) int default_flags = VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW | VFCAP_OSD | VFCAP_FLIP; switch (format) { - case IMGFMT_YV12: - case IMGFMT_I420: - case IMGFMT_IYUV: + case IMGFMT_420P: case IMGFMT_NV12: - case IMGFMT_YUY2: + case IMGFMT_YUYV: case IMGFMT_UYVY: case IMGFMT_VDPAU_MPEG1: case IMGFMT_VDPAU_MPEG2: diff --git a/video/out/vo_x11.c b/video/out/vo_x11.c index 5a81648233..2ce28a4292 100644 --- a/video/out/vo_x11.c +++ b/video/out/vo_x11.c @@ -536,9 +536,7 @@ static int query_format(struct vo *vo, uint32_t format) } switch (format) { - case IMGFMT_I420: - case IMGFMT_IYUV: - case IMGFMT_YV12: + case IMGFMT_420P: return VFCAP_CSP_SUPPORTED | VFCAP_OSD; } return 0; 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; } |