X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=theme.cpp;h=d6c9a239b219556ce8fb2d9d2b7222b538e4ce6e;hb=379449a2d9d8f75cf7e37302ebe6b54e373bc2e4;hp=1d0cd2d643db006a4fae075f8aed7c817e5e176f;hpb=c6af897e02de1e5653de71fc4993449e828bb94f;p=nageru diff --git a/theme.cpp b/theme.cpp index 1d0cd2d..d6c9a23 100644 --- a/theme.cpp +++ b/theme.cpp @@ -24,6 +24,7 @@ #include #include "defs.h" +#include "flags.h" #include "image_input.h" #include "mixer.h" @@ -44,19 +45,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 +66,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 +382,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 +569,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 +708,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 &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 +727,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 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 +849,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 +887,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)