]> git.sesse.net Git - nageru/commitdiff
Redo get_width/get_height to not work on a LiveInputWrapper, since we do not really...
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Wed, 23 Dec 2015 01:14:32 +0000 (02:14 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Wed, 23 Dec 2015 01:33:55 +0000 (02:33 +0100)
theme.cpp
theme.h
theme.lua

index caedbf4b1899a0bee3d26497142376c81d884440..aed350f0973ac50b81307f99b128797d448351d0 100644 (file)
--- 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<MixEffect>(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<InputState>(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 4f2c2327c223c0917cab5e16d556b41b37f17769..b60df1490190059fb0a0900ed543aab6fa0b7266 100644 (file)
--- 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)
index 1243ad15de6be7cfb64d059969f958487de837f3..0f390f426aadb8503f374b0bca77046a73db4f56 100644 (file)
--- 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).
 --
+-- <signals> 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()