From: Steinar H. Gunderson Date: Wed, 23 Dec 2015 01:14:32 +0000 (+0100) Subject: Redo get_width/get_height to not work on a LiveInputWrapper, since we do not really... X-Git-Tag: 1.0.0~73 X-Git-Url: https://git.sesse.net/?p=nageru;a=commitdiff_plain;h=2b806ed340112b4b464b6f2b9c34e4873de5f1c5 Redo get_width/get_height to not work on a LiveInputWrapper, since we do not really know which one to use before we have selected the chain (at which point it really is too late). --- diff --git a/theme.cpp b/theme.cpp index caedbf4..aed350f 100644 --- a/theme.cpp +++ b/theme.cpp @@ -90,6 +90,15 @@ Effect *get_effect(lua_State *L, int idx) return nullptr; } +InputState *get_input_state(lua_State *L, int idx) +{ + if (luaL_testudata(L, idx, "InputState")) { + return (InputState *)lua_touserdata(L, idx); + } + luaL_error(L, "Error: Index #%d was not InputState\n", idx); + return nullptr; +} + bool checkbool(lua_State* L, int idx) { luaL_checktype(L, idx, LUA_TBOOLEAN); @@ -210,22 +219,6 @@ int LiveInputWrapper_connect_signal(lua_State* L) return 0; } -int LiveInputWrapper_get_width(lua_State* L) -{ - assert(lua_gettop(L) == 1); - LiveInputWrapper *input = (LiveInputWrapper *)luaL_checkudata(L, 1, "LiveInputWrapper"); - lua_pushnumber(L, input->get_width()); - return 1; -} - -int LiveInputWrapper_get_height(lua_State* L) -{ - assert(lua_gettop(L) == 1); - LiveInputWrapper *input = (LiveInputWrapper *)luaL_checkudata(L, 1, "LiveInputWrapper"); - lua_pushnumber(L, input->get_height()); - return 1; -} - int ImageInput_new(lua_State* L) { assert(lua_gettop(L) == 1); @@ -275,6 +268,36 @@ int MixEffect_new(lua_State* L) return wrap_lua_object(L, "MixEffect"); } +int InputState_gc(lua_State* L) +{ + assert(lua_gettop(L) == 1); + InputState *input_state = get_input_state(L, 1); + input_state->~InputState(); + return 0; +} + +int InputState_get_width(lua_State* L) +{ + assert(lua_gettop(L) == 2); + InputState *input_state = (InputState *)lua_touserdata(L, 1); + int signal_num = luaL_checknumber(L, 2); + BufferedFrame frame = input_state->buffered_frames[signal_num][0]; + const PBOFrameAllocator::Userdata *userdata = (const PBOFrameAllocator::Userdata *)frame.frame->userdata; + lua_pushnumber(L, userdata->last_width[frame.field_number]); + return 1; +} + +int InputState_get_height(lua_State* L) +{ + assert(lua_gettop(L) == 2); + InputState *input_state = (InputState *)lua_touserdata(L, 1); + int signal_num = luaL_checknumber(L, 2); + BufferedFrame frame = input_state->buffered_frames[signal_num][0]; + const PBOFrameAllocator::Userdata *userdata = (const PBOFrameAllocator::Userdata *)frame.frame->userdata; + lua_pushnumber(L, userdata->last_height[frame.field_number]); + return 1; +} + int Effect_set_float(lua_State *L) { assert(lua_gettop(L) == 3); @@ -342,9 +365,6 @@ const luaL_Reg EffectChain_funcs[] = { const luaL_Reg LiveInputWrapper_funcs[] = { { "connect_signal", LiveInputWrapper_connect_signal }, - // These are only valid during calls to get_chain and the setup chain callback. - { "get_width", LiveInputWrapper_get_width }, - { "get_height", LiveInputWrapper_get_height }, { NULL, NULL } }; @@ -420,6 +440,13 @@ const luaL_Reg MixEffect_funcs[] = { { NULL, NULL } }; +const luaL_Reg InputState_funcs[] = { + { "__gc", InputState_gc }, + { "get_width", InputState_get_width }, + { "get_height", InputState_get_height }, + { NULL, NULL } +}; + } // namespace LiveInputWrapper::LiveInputWrapper(Theme *theme, EffectChain *chain, bool override_bounce) @@ -477,26 +504,6 @@ void LiveInputWrapper::connect_signal(int signal_num) input->set_height(userdata->last_height[frame.field_number]); } -unsigned LiveInputWrapper::get_width() const -{ - if (last_connected_signal_num == -1) { - return 0; - } - BufferedFrame frame = theme->input_state->buffered_frames[last_connected_signal_num][0]; - const PBOFrameAllocator::Userdata *userdata = (const PBOFrameAllocator::Userdata *)frame.frame->userdata; - return userdata->last_width[frame.field_number]; -} - -unsigned LiveInputWrapper::get_height() const -{ - if (last_connected_signal_num == -1) { - return 0; - } - BufferedFrame frame = theme->input_state->buffered_frames[last_connected_signal_num][0]; - const PBOFrameAllocator::Userdata *userdata = (const PBOFrameAllocator::Userdata *)frame.frame->userdata; - return userdata->last_height[frame.field_number]; -} - Theme::Theme(const char *filename, ResourcePool *resource_pool, unsigned num_cards) : resource_pool(resource_pool), num_cards(num_cards) { @@ -513,6 +520,7 @@ Theme::Theme(const char *filename, ResourcePool *resource_pool, unsigned num_car register_class("OverlayEffect", OverlayEffect_funcs); register_class("ResizeEffect", ResizeEffect_funcs); register_class("MixEffect", MixEffect_funcs); + register_class("InputState", InputState_funcs); // Run script. lua_settop(L, 0); @@ -559,9 +567,9 @@ Theme::Chain Theme::get_chain(unsigned num, float t, unsigned width, unsigned he lua_pushnumber(L, t); lua_pushnumber(L, width); lua_pushnumber(L, height); + wrap_lua_object(L, "InputState", input_state); - this->input_state = &input_state; - if (lua_pcall(L, 4, 2, 0) != 0) { + if (lua_pcall(L, 5, 2, 0) != 0) { fprintf(stderr, "error running function `get_chain': %s\n", lua_tostring(L, -1)); exit(1); } diff --git a/theme.h b/theme.h index 4f2c232..b60df14 100644 --- a/theme.h +++ b/theme.h @@ -86,15 +86,9 @@ public: return input; } - // Of last connected signal number (see connect_signal()). - // Only valid during get_chain() or the setup callback. - unsigned get_width() const; - unsigned get_height() const; - private: Theme *theme; // Not owned by us. movit::YCbCrInput *input; // Owned by the chain. - int last_connected_signal_num = -1; }; #endif // !defined(_THEME_H) diff --git a/theme.lua b/theme.lua index 1243ad1..0f390f4 100644 --- a/theme.lua +++ b/theme.lua @@ -313,6 +313,11 @@ end -- the output, although you can ignore them if you don't need them -- (they're useful if you want to e.g. know what to resample by). -- +-- is basically an exposed InputState, which you can use to +-- query for information about the signals at the point of the current +-- frame. In particular, you can call get_width() and get_height() +-- for any signal number, and use that to e.g. assist in chain selection. +-- -- You should return two objects; the chain itself, and then a -- function (taking no parameters) that is run just before rendering. -- The function needs to call connect_signal on any inputs, so that @@ -324,7 +329,7 @@ end -- -- NOTE: The chain returned must be finalized with the Y'CbCr flag -- if and only if num==0. -function get_chain(num, t, width, height) +function get_chain(num, t, width, height, signals) if num == 0 then -- Live. if live_signal_num == INPUT0_SIGNAL_NUM or live_signal_num == INPUT1_SIGNAL_NUM then -- Plain input. prepare = function()