summaryrefslogtreecommitdiffstats
path: root/core
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 /core
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 'core')
-rw-r--r--core/cfg-mplayer.h2
-rw-r--r--core/m_option.c35
-rw-r--r--core/m_option.h3
-rw-r--r--core/mp_common.h3
4 files changed, 42 insertions, 1 deletions
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;