X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=theme.cpp;h=84f37ba0002d07db95983828944c66bc6777d7c7;hb=0fc51edaacfad77471a8736c4a7c66d46db9930b;hp=2b5c5b4257eeef1b0270e5dfc862702e11af0b89;hpb=5c6163ad5daa01b486e44c394dd7cc9878ec5df5;p=nageru diff --git a/theme.cpp b/theme.cpp index 2b5c5b4..84f37ba 100644 --- a/theme.cpp +++ b/theme.cpp @@ -1,17 +1,19 @@ #include "theme.h" #include +#include +#include #include #include #include #include #include #include +#include #include #include #include #include -#include #include #include #include @@ -19,14 +21,19 @@ #include #include #include +#include #include #include -#include #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; @@ -45,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; @@ -65,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; } @@ -252,17 +261,15 @@ int EffectChain_finalize(lua_State* L) if (is_main_chain) { YCbCrFormat output_ycbcr_format; - // We actually output 4:2:0 in the end, but chroma subsampling - // happens in a pass not run by Movit (see Mixer::subsample_chroma()). + // We actually output 4:2:0 and/or 4:2:2 in the end, but chroma subsampling + // happens in a pass not run by Movit (see ChromaSubsampler::subsample_chroma()). output_ycbcr_format.chroma_subsampling_x = 1; output_ycbcr_format.chroma_subsampling_y = 1; - - // Rec. 709 would be the sane thing to do, but it seems many players - // (e.g. MPlayer and VLC) just default to BT.601 coefficients no matter - // what (see discussions in e.g. https://trac.ffmpeg.org/ticket/4978). - // We _do_ set the right flags, though, so that a player that works - // properly doesn't have to guess. - output_ycbcr_format.luma_coefficients = YCBCR_REC_601; + if (global_flags.ycbcr_rec709_coefficients) { + output_ycbcr_format.luma_coefficients = YCBCR_REC_709; + } else { + output_ycbcr_format.luma_coefficients = YCBCR_REC_601; + } output_ycbcr_format.full_range = false; output_ycbcr_format.num_levels = 256; @@ -380,6 +387,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); @@ -557,6 +574,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 } @@ -611,9 +629,9 @@ LiveInputWrapper::LiveInputWrapper(Theme *theme, EffectChain *chain, bool overri } for (unsigned i = 0; i < num_inputs; ++i) { if (override_bounce) { - inputs.push_back(new NonBouncingYCbCrInput(inout_format, input_ycbcr_format, WIDTH, HEIGHT, YCBCR_INPUT_SPLIT_Y_AND_CBCR)); + inputs.push_back(new NonBouncingYCbCrInput(inout_format, input_ycbcr_format, global_flags.width, global_flags.height, YCBCR_INPUT_SPLIT_Y_AND_CBCR)); } else { - inputs.push_back(new YCbCrInput(inout_format, input_ycbcr_format, WIDTH, HEIGHT, YCBCR_INPUT_SPLIT_Y_AND_CBCR)); + inputs.push_back(new YCbCrInput(inout_format, input_ycbcr_format, global_flags.width, global_flags.height, YCBCR_INPUT_SPLIT_Y_AND_CBCR)); } chain->add_input(inputs.back()); } @@ -695,7 +713,7 @@ int call_num_channels(lua_State *L) } // namespace -Theme::Theme(const char *filename, ResourcePool *resource_pool, unsigned 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(); @@ -714,11 +732,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); @@ -811,11 +854,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) @@ -844,10 +892,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) @@ -909,12 +963,28 @@ int Theme::map_signal(int signal_num) if (signal_to_card_mapping.count(signal_num)) { return signal_to_card_mapping[signal_num]; } - if (signal_num >= int(num_cards)) { - fprintf(stderr, "WARNING: Theme asked for input %d, but we only have %u card(s).\n", signal_num, num_cards); - fprintf(stderr, "Mapping to card %d instead.\n", signal_num % num_cards); + + int card_index; + if (global_flags.output_card != -1 && num_cards > 1) { + // Try to exclude the output card from the default card_index. + card_index = signal_num % (num_cards - 1); + if (card_index >= global_flags.output_card) { + ++card_index; + } + if (signal_num >= int(num_cards - 1)) { + fprintf(stderr, "WARNING: Theme asked for input %d, but we only have %u input card(s) (card %d is busy with output).\n", + signal_num, num_cards - 1, global_flags.output_card); + fprintf(stderr, "Mapping to card %d instead.\n", card_index); + } + } else { + card_index = signal_num % num_cards; + if (signal_num >= int(num_cards)) { + fprintf(stderr, "WARNING: Theme asked for input %d, but we only have %u card(s).\n", signal_num, num_cards); + fprintf(stderr, "Mapping to card %d instead.\n", card_index); + } } - signal_to_card_mapping[signal_num] = signal_num % num_cards; - return signal_num % num_cards; + signal_to_card_mapping[signal_num] = card_index; + return card_index; } void Theme::set_signal_mapping(int signal_num, int card_num)