From: Steinar H. Gunderson Date: Tue, 22 Dec 2015 19:17:22 +0000 (+0100) Subject: Expose width and height information to Lua during get_chain(). X-Git-Tag: 1.0.0~75 X-Git-Url: https://git.sesse.net/?p=nageru;a=commitdiff_plain;h=fedd382abdd2723a2cc9b6868145101fab17b4e7 Expose width and height information to Lua during get_chain(). Useful for choosing e.g. between chains that contain scalers versus not, and then later also deinterlacers. --- diff --git a/theme.cpp b/theme.cpp index 8229bdc..2fe9d89 100644 --- a/theme.cpp +++ b/theme.cpp @@ -210,6 +210,22 @@ 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); @@ -326,6 +342,9 @@ 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 } }; @@ -458,6 +477,26 @@ 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) { @@ -521,6 +560,7 @@ Theme::Chain Theme::get_chain(unsigned num, float t, unsigned width, unsigned he lua_pushnumber(L, width); lua_pushnumber(L, height); + this->input_state = &input_state; if (lua_pcall(L, 4, 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 b60df14..4f2c232 100644 --- a/theme.h +++ b/theme.h @@ -86,9 +86,15 @@ 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)