]> git.sesse.net Git - nageru/blobdiff - theme.cpp
Split interlaced frames into two fields that are sent along separately to the mixer...
[nageru] / theme.cpp
index bd1259062780ae0859b65b4042fdfa644785d745..61e149c3320c9256d0985d51a3db26dc913e99f2 100644 (file)
--- a/theme.cpp
+++ b/theme.cpp
 #include <cstddef>
 #include <new>
 #include <utility>
+#include <memory>
 
+#include "defs.h"
 #include "image_input.h"
 
 namespace movit {
 class ResourcePool;
 }  // namespace movit
 
-#define WIDTH 1280  // FIXME
-#define HEIGHT 720  // FIXME
-
 using namespace std;
 using namespace movit;
 
@@ -37,6 +36,23 @@ namespace {
 
 vector<LiveInputWrapper *> live_inputs;
 
+class LuaRefWithDeleter {
+public:
+       LuaRefWithDeleter(mutex *m, lua_State *L, int ref) : m(m), L(L), ref(ref) {}
+       ~LuaRefWithDeleter() {
+               unique_lock<mutex> lock(*m);
+               luaL_unref(L, LUA_REGISTRYINDEX, ref);
+       }
+       int get() const { return ref; }
+
+private:
+       LuaRefWithDeleter(const LuaRefWithDeleter &) = delete;
+
+       mutex *m;
+       lua_State *L;
+       int ref;
+};
+
 template<class T, class... Args>
 int wrap_lua_object(lua_State* L, const char *class_name, Args&&... args)
 {
@@ -501,14 +517,14 @@ Theme::get_chain(unsigned num, float t, unsigned width, unsigned height)
                exit(1);
        }
        lua_pushvalue(L, -1);
-       int funcref = luaL_ref(L, LUA_REGISTRYINDEX);  // TODO: leak!
+       shared_ptr<LuaRefWithDeleter> funcref(new LuaRefWithDeleter(&m, L, luaL_ref(L, LUA_REGISTRYINDEX)));
        lua_pop(L, 2);
        assert(lua_gettop(L) == 0);
        return make_pair(chain, [this, funcref]{
                unique_lock<mutex> lock(m);
 
                // Set up state, including connecting signals.
-               lua_rawgeti(L, LUA_REGISTRYINDEX, funcref);
+               lua_rawgeti(L, LUA_REGISTRYINDEX, funcref->get());
                if (lua_pcall(L, 0, 0, 0) != 0) {
                        fprintf(stderr, "error running chain setup callback: %s\n", lua_tostring(L, -1));
                        exit(1);
@@ -597,6 +613,8 @@ void Theme::connect_signal(YCbCrInput *input, int signal_num)
        }
        input->set_texture_num(0, input_textures[signal_num].tex_y);
        input->set_texture_num(1, input_textures[signal_num].tex_cbcr);
+       input->set_width(input_textures[signal_num].width);
+       input->set_height(input_textures[signal_num].height);
 }
 
 void Theme::transition_clicked(int transition_num, float t)