]> git.sesse.net Git - nageru/blobdiff - theme.cpp
Write 1.4.0 changelog.
[nageru] / theme.cpp
index 1d0cd2d643db006a4fae075f8aed7c817e5e176f..3f52c838fe53ecfcac11238cb0ffeff8a3cc44b6 100644 (file)
--- a/theme.cpp
+++ b/theme.cpp
@@ -1,17 +1,19 @@
 #include "theme.h"
 
 #include <assert.h>
+#include <bmusb/bmusb.h>
+#include <epoxy/gl.h>
 #include <lauxlib.h>
 #include <lua.hpp>
 #include <movit/effect.h>
 #include <movit/effect_chain.h>
 #include <movit/image_format.h>
 #include <movit/mix_effect.h>
+#include <movit/multiply_effect.h>
 #include <movit/overlay_effect.h>
 #include <movit/padding_effect.h>
 #include <movit/resample_effect.h>
 #include <movit/resize_effect.h>
-#include <movit/multiply_effect.h>
 #include <movit/util.h>
 #include <movit/white_balance_effect.h>
 #include <movit/ycbcr.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <cstddef>
+#include <memory>
 #include <new>
 #include <utility>
-#include <memory>
 
 #include "defs.h"
+#include "deinterlace_effect.h"
+#include "flags.h"
 #include "image_input.h"
-#include "mixer.h"
+#include "input.h"
+#include "input_state.h"
+#include "pbo_frame_allocator.h"
+
+class Mixer;
 
 namespace movit {
 class ResourcePool;
@@ -44,19 +52,20 @@ namespace {
 struct InputStateInfo {
        InputStateInfo(const InputState& input_state);
 
-       unsigned last_width[MAX_CARDS], last_height[MAX_CARDS];
-       bool last_interlaced[MAX_CARDS], last_has_signal[MAX_CARDS];
-       unsigned last_frame_rate_nom[MAX_CARDS], last_frame_rate_den[MAX_CARDS];
+       unsigned last_width[MAX_VIDEO_CARDS], last_height[MAX_VIDEO_CARDS];
+       bool last_interlaced[MAX_VIDEO_CARDS], last_has_signal[MAX_VIDEO_CARDS], last_is_connected[MAX_VIDEO_CARDS];
+       unsigned last_frame_rate_nom[MAX_VIDEO_CARDS], last_frame_rate_den[MAX_VIDEO_CARDS];
 };
 
 InputStateInfo::InputStateInfo(const InputState &input_state)
 {
-       for (unsigned signal_num = 0; signal_num < MAX_CARDS; ++signal_num) {
+       for (unsigned signal_num = 0; signal_num < MAX_VIDEO_CARDS; ++signal_num) {
                BufferedFrame frame = input_state.buffered_frames[signal_num][0];
                if (frame.frame == nullptr) {
                        last_width[signal_num] = last_height[signal_num] = 0;
                        last_interlaced[signal_num] = false;
                        last_has_signal[signal_num] = false;
+                       last_is_connected[signal_num] = false;
                        continue;
                }
                const PBOFrameAllocator::Userdata *userdata = (const PBOFrameAllocator::Userdata *)frame.frame->userdata;
@@ -64,6 +73,7 @@ InputStateInfo::InputStateInfo(const InputState &input_state)
                last_height[signal_num] = userdata->last_height[frame.field_number];
                last_interlaced[signal_num] = userdata->last_interlaced;
                last_has_signal[signal_num] = userdata->last_has_signal;
+               last_is_connected[signal_num] = userdata->last_is_connected;
                last_frame_rate_nom[signal_num] = userdata->last_frame_rate_nom;
                last_frame_rate_den[signal_num] = userdata->last_frame_rate_den;
        }
@@ -379,6 +389,16 @@ int InputStateInfo_get_has_signal(lua_State* L)
        return 1;
 }
 
+int InputStateInfo_get_is_connected(lua_State* L)
+{
+       assert(lua_gettop(L) == 2);
+       InputStateInfo *input_state_info = get_input_state_info(L, 1);
+       Theme *theme = get_theme_updata(L);
+       int signal_num = theme->map_signal(luaL_checknumber(L, 2));
+       lua_pushboolean(L, input_state_info->last_is_connected[signal_num]);
+       return 1;
+}
+
 int InputStateInfo_get_frame_rate_nom(lua_State* L)
 {
        assert(lua_gettop(L) == 2);
@@ -556,6 +576,7 @@ const luaL_Reg InputStateInfo_funcs[] = {
        { "get_height", InputStateInfo_get_height },
        { "get_interlaced", InputStateInfo_get_interlaced },
        { "get_has_signal", InputStateInfo_get_has_signal },
+       { "get_is_connected", InputStateInfo_get_is_connected },
        { "get_frame_rate_nom", InputStateInfo_get_frame_rate_nom },
        { "get_frame_rate_den", InputStateInfo_get_frame_rate_den },
        { NULL, NULL }
@@ -694,8 +715,8 @@ int call_num_channels(lua_State *L)
 
 }  // namespace
 
-Theme::Theme(const char *filename, ResourcePool *resource_pool, unsigned num_cards)
-       : resource_pool(resource_pool), num_cards(num_cards)
+Theme::Theme(const string &filename, const vector<string> &search_dirs, ResourcePool *resource_pool, unsigned num_cards)
+       : resource_pool(resource_pool), num_cards(num_cards), signal_to_card_mapping(global_flags.default_stream_mapping)
 {
        L = luaL_newstate();
         luaL_openlibs(L);
@@ -713,11 +734,36 @@ Theme::Theme(const char *filename, ResourcePool *resource_pool, unsigned num_car
        register_class("MixEffect", MixEffect_funcs);
        register_class("InputStateInfo", InputStateInfo_funcs);
 
-       // Run script.
+       // Run script. Search through all directories until we find a file that will load
+       // (as in, does not return LUA_ERRFILE); then run it. We store load errors
+       // from all the attempts, and show them once we know we can't find any of them.
        lua_settop(L, 0);
-       if (luaL_dofile(L, filename)) {
-               fprintf(stderr, "error: %s\n", lua_tostring(L, -1));
+       vector<string> errors;
+       bool success = false;
+       for (size_t i = 0; i < search_dirs.size(); ++i) {
+               string path = search_dirs[i] + "/" + filename;
+               int err = luaL_loadfile(L, path.c_str());
+               if (err == 0) {
+                       // Success; actually call the code.
+                       if (lua_pcall(L, 0, LUA_MULTRET, 0)) {
+                               fprintf(stderr, "Error when running %s: %s\n", path.c_str(), lua_tostring(L, -1));
+                               exit(1);
+                       }
+                       success = true;
+                       break;
+               }
+               errors.push_back(lua_tostring(L, -1));
                lua_pop(L, 1);
+               if (err != LUA_ERRFILE) {
+                       // The file actually loaded, but failed to parse somehow. Abort; don't try the next one.
+                       break;
+               }
+       }
+
+       if (!success) {
+               for (const string &error : errors) {
+                       fprintf(stderr, "%s\n", error.c_str());
+               }
                exit(1);
        }
        assert(lua_gettop(L) == 0);
@@ -810,11 +856,16 @@ string Theme::get_channel_name(unsigned channel)
                fprintf(stderr, "error running function `channel_name': %s\n", lua_tostring(L, -1));
                exit(1);
        }
+       const char *ret = lua_tostring(L, -1);
+       if (ret == nullptr) {
+               fprintf(stderr, "function `channel_name' returned nil for channel %d\n", channel);
+               exit(1);
+       }
 
-       string ret = lua_tostring(L, -1);
+       string retstr = ret;
        lua_pop(L, 1);
        assert(lua_gettop(L) == 0);
-       return ret;
+       return retstr;
 }
 
 int Theme::get_channel_signal(unsigned channel)
@@ -843,10 +894,16 @@ std::string Theme::get_channel_color(unsigned channel)
                exit(1);
        }
 
-       std::string ret = checkstdstring(L, -1);
+       const char *ret = lua_tostring(L, -1);
+       if (ret == nullptr) {
+               fprintf(stderr, "function `channel_color' returned nil for channel %d\n", channel);
+               exit(1);
+       }
+
+       string retstr = ret;
        lua_pop(L, 1);
        assert(lua_gettop(L) == 0);
-       return ret;
+       return retstr;
 }
 
 bool Theme::get_supports_set_wb(unsigned channel)