From 77f309c94ff17f5627290a7a5a4477db714ecd1e Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 25 Oct 2019 00:25:05 +0200 Subject: vo_gpu, options: don't return NaN through API Internally, vo_gpu uses NaN for some options to indicate a default value that is different depending on the context (e.g. different scalers). There are 2 problems with this: 1. you couldn't reset the options to their defaults 2. NaN is a damn mess and shouldn't be part of the API The option parser already rejected NaN explicitly, which is why 1. didn't work. Regarding 2., JSON might be a good example, and actually caused a bug report. Fix this by mapping NaN to the special value "default". I think I'd prefer other mechanisms (maybe just having every scaler expose separate options?), but for now this will do. See you in a future commit, which painfully deprecates this and replaces it with something else. I refrained from using "no" (my favorite magic value for "unset" etc.) because then I'd have e.g. make --no-scale-param1 work, which in addition to a lot of effort looks dumb and nobody will use it. Here's also an apology for the shitty added test script. Fixes: #6691 --- TOOLS/lua/nan-test.lua | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 TOOLS/lua/nan-test.lua (limited to 'TOOLS') diff --git a/TOOLS/lua/nan-test.lua b/TOOLS/lua/nan-test.lua new file mode 100644 index 0000000000..d3f1c8cc8f --- /dev/null +++ b/TOOLS/lua/nan-test.lua @@ -0,0 +1,37 @@ +-- Test a float property which internally uses NaN. +-- Run with --no-config (or just scale-param1 not set). + +local utils = require 'mp.utils' + +prop_name = "scale-param1" + +-- internal NaN, return string "default" instead of NaN +v = mp.get_property_native(prop_name, "fail") +print("Exp:", "string", "\"default\"") +print("Got:", type(v), utils.to_string(v)) + +v = mp.get_property(prop_name) +print("Exp:", "default") +print("Got:", v) + +-- not representable -> return provided fallback value +v = mp.get_property_number(prop_name, -100) +print("Exp:", -100) +print("Got:", v) + +mp.set_property_native(prop_name, 123) +v = mp.get_property_number(prop_name, -100) +print("Exp:", "number", 123) +print("Got:", type(v), utils.to_string(v)) + +-- try to set an actual NaN +st, msg = mp.set_property_number(prop_name, 0.0/0) +print("Exp:", nil, "") +print("Got:", st, msg) + +-- set default +mp.set_property(prop_name, "default") + +v = mp.get_property(prop_name) +print("Exp:", "default") +print("Got:", v) -- cgit v1.2.3