X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=nageru%2Fultimate.lua;h=566b465c65c1be8784e4ff258ccc252819752414;hb=4d2991a8d05b23222912fb904b436af5f4d740c2;hp=aec368dbbdbf3e61c35ea39252d585578f4051e9;hpb=9fabdacf449b4a5e65fdde981dfd48883a29af87;p=ultimatescore diff --git a/nageru/ultimate.lua b/nageru/ultimate.lua index aec368d..566b465 100644 --- a/nageru/ultimate.lua +++ b/nageru/ultimate.lua @@ -1,6 +1,6 @@ -- Nageru theme for TFK mini-tournament 2017, based on the default theme. -local futatabi_server = "http://gruessi.trd.sesse.net:9096" +local futatabi_server = "http://10.1.0.172:9096" local state = { transition_start = -2.0, @@ -9,16 +9,6 @@ local state = { transition_src_signal = 0, transition_dst_signal = 0, - neutral_colors = { - {0.5, 0.5, 0.5}, -- Input 0. - {0.5, 0.5, 0.5}, -- Input 1. - {0.5, 0.5, 0.5}, -- Input 2. - {0.5, 0.5, 0.5}, -- Input 3. - {0.5, 0.5, 0.5}, -- Input 4. - {0.5, 0.5, 0.5} -- Input 5. - -- Will also be filled with VIDEO_SIGNAL_NUM below. - }, - overlay_transition_start = -2.0, overlay_transition_end = -1.0, overlay_alpha_src = 0.0, @@ -34,7 +24,7 @@ local state = { live_signal_num = 0, preview_signal_num = 1 } -local NUM_CAMERAS = 6 -- Remember to update neutral_colors, too. +local NUM_CAMERAS = 6 -- Valid values for live_signal_num and preview_signal_num. local INPUT0_SIGNAL_NUM = 0 @@ -43,11 +33,9 @@ local INPUT2_SIGNAL_NUM = 2 local INPUT3_SIGNAL_NUM = 3 local INPUT4_SIGNAL_NUM = 4 local INPUT5_SIGNAL_NUM = 5 -local SBS_SIGNAL_NUM = NUM_CAMERAS -local STATIC_SIGNAL_NUM = NUM_CAMERAS + 1 -local VIDEO_SIGNAL_NUM = NUM_CAMERAS + 2 - -state.neutral_colors[VIDEO_SIGNAL_NUM - INPUT0_SIGNAL_NUM + 1] = {0.5, 0.5, 0.5} +local VIDEO_SIGNAL_NUM = NUM_CAMERAS +local SBS_SIGNAL_NUM = NUM_CAMERAS + 1 +local STATIC_SIGNAL_NUM = NUM_CAMERAS + 2 -- Preview-only signal showing the current signal with the overlay. -- Not valid for live_signal_num! @@ -70,8 +58,11 @@ cef_input:execute_javascript_async("play()") local bg_video = VideoInput.new(cef_path .. "/flow-720.mp4", Nageru.VIDEO_FORMAT_YCBCR) -- local iptv_video = VideoInput.new("http://10.34.129.69:9060/1/v.flv", Nageru.VIDEO_FORMAT_YCBCR) local iptv_video = VideoInput.new(futatabi_server, Nageru.VIDEO_FORMAT_YCBCR) +iptv_video:change_rate(10.0) local static_image = ImageInput.new(cef_path .. "/nageru/dsn-bg.png") +local first_frame = true +local multiviewer_enabled = false function reload_cef() cef_input:reload() @@ -82,6 +73,10 @@ function disconnect_iptv() iptv_video:disconnect() end +function toggle_multiviewer() + multiviewer_enabled = not multiviewer_enabled +end + -- An overlay with variable alpha. function make_overlay(scene, base) local image = scene:add_input(cef_input) @@ -98,7 +93,7 @@ function make_fade_input(scene) local ret = { input = scene:add_input(), resample_effect = scene:add_optional_effect(ResampleEffect.new()), -- Activated if scaling. - wb_effect = scene:add_optional_effect(WhiteBalanceEffect.new()) -- Activated for video inputs. + wb_effect = scene:add_auto_white_balance() } ret.overlay = make_overlay(scene, ret.wb_effect) return ret @@ -139,16 +134,16 @@ fade_scene = make_fade_scene() function make_sbs_input(scene, has_overlay) local input = scene:add_input() - local resample_effect = ResampleEffect.new() - local resize_effect = ResizeEffect.new() + local wb_effect = scene:add_auto_white_balance() + local overlay = has_overlay and make_overlay(scene, wb_effect) or nil + local resample_effect = scene:add_effect({ResampleEffect.new(), ResizeEffect.new()}) + local padding_effect = scene:add_effect(IntegralPaddingEffect.new()) return { input = input, - overlay = has_overlay and make_overlay(scene, input) or nil, + overlay = overlay, resample_effect = resample_effect, - resize_effect = resize_effect, - resample_switcher = scene:add_effect({resample_effect, resize_effect}), - wb_effect = scene:add_effect(WhiteBalanceEffect.new()), - padding_effect = scene:add_effect(IntegralPaddingEffect.new()) + wb_effect = wb_effect, + padding_effect = padding_effect } end @@ -184,7 +179,7 @@ function make_simple_scene_no_finalize() local input = scene:add_input() local resample_effect = scene:add_effect({ResampleEffect.new(), ResizeEffect.new(), IdentityEffect.new()}) - local wb_effect = scene:add_effect(WhiteBalanceEffect.new()) + local wb_effect = scene:add_auto_white_balance() local overlay = make_overlay(scene, wb_effect) return { @@ -202,13 +197,12 @@ function make_simple_scene() scene.scene:finalize() return scene end - local simple_scene = make_simple_scene() -- Load all the stinger frames. local stinger_images = {} for idx=0,24 do - local filename = cef_path .. "/stinger/blur" .. string.rep("0", 3 - string.len(tostring(idx))) .. idx .. ".png" + local filename = cef_path .. "/stinger/esk-blur" .. string.rep("0", 3 - string.len(tostring(idx))) .. idx .. ".png" stinger_images[idx] = ImageInput.new(filename) end @@ -233,6 +227,36 @@ local overlay_scene_lq = Scene.new(16, 9) local overlay_scene_lq_input = overlay_scene_lq:add_input(cef_input) overlay_scene_lq:finalize(false) +-- A debugging scene to show a simple multiviewer. HQ only, since there is no preview. +function make_multiview_scene() + local scene = Scene.new(16, 9) + local bg = scene:add_input(ImageInput.new(cef_path .. "/nageru/white.png")) + local mv_width = 1280 / 3 + local mv_height = 720 / 3 + local mv_offset = (720 - mv_height * 2) / 2 + + for input_idx=0,5 do + local input = scene:add_input(input_idx) + + local resize = scene:add_effect(ResizeEffect.new()) + resize:set_int("width", mv_width) + resize:set_int("height", mv_height) + + local padding = scene:add_effect(IntegralPaddingEffect.new()) + padding:set_int("width", 1280) + padding:set_int("height", 720) + padding:set_int("left", (input_idx % 3) * mv_width) + padding:set_int("top", math.floor(input_idx / 3) * mv_height + mv_offset) + + local overlay = scene:add_effect(OverlayEffect.new(), bg, padding) + bg = overlay + end + + scene:finalize(true) + return scene +end +local multiview_scene_hq = make_multiview_scene() + function needs_scale(signals, signal_num, width, height) if signal_num == STATIC_SIGNAL_NUM then -- We assume this is already correctly scaled at load time. @@ -242,17 +266,24 @@ function needs_scale(signals, signal_num, width, height) return (signals:get_width(signal_num) ~= width or signals:get_height(signal_num) ~= height) end -function set_scale_parameters_if_needed(scene_or_input, signals, signal_num, width, height) +function set_scale_parameters_if_needed(scene, signals, signal_num, width, height, hq) + -- Futatabi rescaling will be linear, but original frames come back unscaled; + -- make them linear, too, so that we don't get more sharpness on every other + -- frame. This won't be right for fading, but it's probably hard to notice. + if signal_num == VIDEO_SIGNAL_NUM then + hq = false + end + if needs_scale(signals, signal_num, width, height) then if hq then - scene_or_input.resample_effect:choose(ResampleEffect) -- High-quality resampling. + scene.resample_effect:choose(ResampleEffect) -- High-quality resampling. else - scene_or_input.resample_effect:choose(ResizeEffect) -- Low-quality resampling. + scene.resample_effect:choose(ResizeEffect) -- Low-quality resampling. end - scene_or_input.resample_effect:set_int("width", width) - scene_or_input.resample_effect:set_int("height", height) + scene.resample_effect:set_int("width", width) + scene.resample_effect:set_int("height", height) else - scene_or_input.resample_effect:disable() + scene.resample_effect:disable() end end @@ -339,20 +370,20 @@ function channel_name(channel) elseif signal_num == INPUT3_SIGNAL_NUM then return "Goal R (" .. get_channel_resolution(signal_num) .. ")" elseif signal_num == INPUT4_SIGNAL_NUM then - return "Commentators (" .. get_channel_resolution(signal_num) .. ")" + return "Ambience (" .. get_channel_resolution(signal_num) .. ")" elseif signal_num == INPUT5_SIGNAL_NUM then - return "Laptop (" .. get_channel_resolution(signal_num) .. ")" - elseif signal_num == SBS_SIGNAL_NUM then - return "Side-by-side" - elseif signal_num == STATIC_SIGNAL_NUM then - return "Static picture" + return "Commentators (" .. get_channel_resolution(signal_num) .. ")" elseif signal_num == VIDEO_SIGNAL_NUM then local res = last_resolution[iptv_video:get_signal_num()] if (not res) or res.last_subtitle == nil then - return "IPTV" + return "Futatabi" else - return "IPTV (" .. get_futatabi_status(res.last_subtitle) .. ")" + return "Futatabi (" .. get_futatabi_status(res.last_subtitle) .. ")" end + elseif signal_num == SBS_SIGNAL_NUM then + return "Side-by-side" + elseif signal_num == STATIC_SIGNAL_NUM then + return "Static picture" elseif signal_num == OVERLAY_SIGNAL_NUM then return "Overlay" end @@ -420,15 +451,6 @@ function supports_set_wb(channel) return is_plain_signal(channel - 2) end --- API ENTRY POINT --- Gets called with a new gray point when the white balance is changing. --- The color is in linear light (not sRGB gamma). -function set_wb(channel, red, green, blue) - if is_plain_signal(channel - 2) then - state.neutral_colors[channel - 2 + 1] = { red, green, blue } - end -end - function finish_transitions(t) if state.transition_type ~= NO_TRANSITION and t >= state.transition_end then state.live_signal_num = state.transition_dst_signal @@ -618,14 +640,11 @@ end function setup_fade_input(state, input, signals, signal_num, width, height) if signal_num == STATIC_SIGNAL_NUM then input.input:display(static_image) - input.wb_effect:disable() -- We assume this is already correctly scaled at load time. input.resample_effect:disable() else input.input:display(signal_num) - input.wb_effect:enable() - set_neutral_color(input.wb_effect, state.neutral_colors[signal_num - INPUT0_SIGNAL_NUM + 1]) if (signals:get_width(signal_num) ~= width or signals:get_height(signal_num) ~= height) then input.resample_effect:enable() @@ -705,6 +724,25 @@ function fetch_input_resolution(signals, signal_num) return res end +function update_volume() + if Nageru.get_num_audio_buses() < 3 or + Nageru.get_audio_bus_name(2) ~= 'Sound Shark' then + -- We haven't loaded the right audio mapping. + return + end + + if first_frame then + Nageru.set_audio_bus_fader_level_db(2, -math.huge) + first_frame = false + end + + local volume_db = Nageru.get_audio_bus_fader_level_db(2) + if Nageru.get_audio_bus_mute(2) or volume_db < -100.0 then + volume_db = -100.0 + end + cef_input:execute_javascript_async("set_sound_shark_volume_db(" .. volume_db .. ")") +end + local last_rate = 0.0 -- API ENTRY POINT @@ -724,6 +762,10 @@ local last_rate = 0.0 -- want to set (through set_int() etc.). The parameters will be snapshot -- at return time and used during rendering. function get_scene(num, t, width, height, signals) + if num == 0 then + update_volume() + end + local input_resolution = {} for signal_num=0,(NUM_CAMERAS-1) do input_resolution[signal_num] = fetch_input_resolution(signals, signal_num) @@ -746,19 +788,23 @@ function get_scene(num, t, width, height, signals) last_rate = new_rate end + if num == 0 and multiviewer_enabled then -- Live, with debugging on. + return multiview_scene_hq + end + if num == 0 then -- Live. -- See if we're in a transition. finish_transitions(t) if state.transition_type == ZOOM_TRANSITION then -- Transition in or out of SBS. sbs_scene.input0.overlay.overlay_effect:enable_if(state.overlay_enabled) - prepare_sbs_scene(state, sbs_scene, calc_zoom_progress(t), state.transition_type, state.transition_src_signal, state.transition_dst_signal, width, height, input_resolution) + prepare_sbs_scene(state, sbs_scene, calc_zoom_progress(t), state.transition_type, state.transition_src_signal, state.transition_dst_signal, width, height, input_resolution, true) prepare_overlay_live(state, sbs_scene, t, 1.0) return sbs_scene.scene elseif state.transition_type == NO_TRANSITION and state.live_signal_num == SBS_SIGNAL_NUM then -- Static SBS view. sbs_scene.input0.overlay.overlay_effect:enable_if(state.overlay_enabled) - prepare_sbs_scene(state, sbs_scene, 0.0, NO_TRANSITION, 0, SBS_SIGNAL_NUM, width, height, input_resolution) + prepare_sbs_scene(state, sbs_scene, 0.0, NO_TRANSITION, 0, SBS_SIGNAL_NUM, width, height, input_resolution, true) prepare_overlay_live(state, sbs_scene, t, 1.0) return sbs_scene.scene elseif state.transition_type == FADE_TRANSITION then @@ -767,9 +813,12 @@ function get_scene(num, t, width, height, signals) local overlay_really_enabled = state.overlay_enabled and simple_signal_has_overlay(state.live_signal_num) if state.stinger_in_progress then stinger_scene.overlay.overlay_effect:enable_if(overlay_really_enabled) - stinger_scene.input:display(state.live_signal_num) - set_scale_parameters_if_needed(stinger_scene, signals, state.live_signal_num, width, height) - set_neutral_color_from_signal(state, stinger_scene.wb_effect, state.live_signal_num) + if state.live_signal_num == VIDEO_SIGNAL_NUM then + stinger_scene.input:display(iptv_video) + else + stinger_scene.input:display(state.live_signal_num) + end + set_scale_parameters_if_needed(stinger_scene, signals, state.live_signal_num, width, height, true) stinger_scene.stinger_input:display(stinger_images[state.stinger_frame]) state.stinger_frame = state.stinger_frame + 1 @@ -794,9 +843,12 @@ function get_scene(num, t, width, height, signals) return stinger_scene.scene else simple_scene.overlay.overlay_effect:enable_if(overlay_really_enabled) - simple_scene.input:display(state.live_signal_num) - set_scale_parameters_if_needed(simple_scene, signals, state.live_signal_num, width, height) - set_neutral_color_from_signal(state, simple_scene.wb_effect, state.live_signal_num) + if state.live_signal_num == VIDEO_SIGNAL_NUM then + simple_scene.input:display(iptv_video) + else + simple_scene.input:display(state.live_signal_num) + end + set_scale_parameters_if_needed(simple_scene, signals, state.live_signal_num, width, height, true) prepare_overlay_live(state, simple_scene, t, 1.0) return simple_scene.scene end @@ -828,15 +880,18 @@ function get_scene(num, t, width, height, signals) if is_plain_signal(num - 2) then local signal_num = num - 2 simple_scene.overlay.overlay_effect:enable_if(show_overlay) - simple_scene.input:display(signal_num) - set_scale_parameters_if_needed(simple_scene, signals, signal_num, width, height) - set_neutral_color_from_signal(state, simple_scene.wb_effect, signal_num) + if signal_num == VIDEO_SIGNAL_NUM then + simple_scene.input:display(iptv_video) + else + simple_scene.input:display(signal_num) + end + set_scale_parameters_if_needed(simple_scene, signals, signal_num, width, height, false) prepare_overlay_static(simple_scene, t) return simple_scene.scene end if num == SBS_SIGNAL_NUM + 2 then sbs_scene.input0.overlay.overlay_effect:enable_if(show_overlay) - prepare_sbs_scene(state, sbs_scene, 0.0, NO_TRANSITION, 0, SBS_SIGNAL_NUM, width, height, input_resolution) + prepare_sbs_scene(state, sbs_scene, 0.0, NO_TRANSITION, 0, SBS_SIGNAL_NUM, width, height, input_resolution, false) return sbs_scene.scene end if num == STATIC_SIGNAL_NUM + 2 then @@ -876,11 +931,9 @@ function pos_from_top_left(x, y, width, height, screen_width, screen_height) } end -function prepare_sbs_scene(state, scene, t, transition_type, src_signal, dst_signal, screen_width, screen_height, input_resolution) +function prepare_sbs_scene(state, scene, t, transition_type, src_signal, dst_signal, screen_width, screen_height, input_resolution, hq) scene.input0.input:display(0) - scene.input1.input:display(4) - set_neutral_color(scene.input0.wb_effect, state.neutral_colors[1]) - set_neutral_color(scene.input1.wb_effect, state.neutral_colors[5]) + scene.input1.input:display(5) -- Both inputs are the same size (true side-by-side). local pos0 = pos_from_top_left(1280 - 616 - 16, 186, 616, 347, screen_width, screen_height) @@ -912,8 +965,8 @@ function prepare_sbs_scene(state, scene, t, transition_type, src_signal, dst_sig end -- NOTE: input_resolution is not 1-indexed, unlike usual Lua arrays. - place_rectangle_with_affine(scene.input0, pos0, affine_param, screen_width, screen_height, input_resolution[0].width, input_resolution[0].height) - place_rectangle_with_affine(scene.input1, pos1, affine_param, screen_width, screen_height, input_resolution[1].width, input_resolution[1].height) + place_rectangle_with_affine(scene.input0, pos0, affine_param, screen_width, screen_height, input_resolution[0].width, input_resolution[0].height, hq) + place_rectangle_with_affine(scene.input1, pos1, affine_param, screen_width, screen_height, input_resolution[1].width, input_resolution[1].height, hq) end -- Find the transformation that changes the first rectangle to the second one. @@ -928,13 +981,13 @@ function find_affine_param(a, b) } end -function place_rectangle_with_affine(input, pos, aff, screen_width, screen_height, input_width, input_height) +function place_rectangle_with_affine(input, pos, aff, screen_width, screen_height, input_width, input_height, hq) local x0 = pos.x0 * aff.sx + aff.tx local x1 = pos.x1 * aff.sx + aff.tx local y0 = pos.y0 * aff.sy + aff.ty local y1 = pos.y1 * aff.sy + aff.ty - place_rectangle(input, x0, y0, x1, y1, screen_width, screen_height, input_width, input_height) + place_rectangle(input, x0, y0, x1, y1, screen_width, screen_height, input_width, input_height, hq) end function place_rectangle(input, x0, y0, x1, y1, screen_width, screen_height, input_width, input_height, hq) @@ -943,9 +996,9 @@ function place_rectangle(input, x0, y0, x1, y1, screen_width, screen_height, inp -- Cull. if x0 > screen_width or x1 < 0.0 or y0 > screen_height or y1 < 0.0 then - input.resample_switcher:choose(ResizeEffect) -- Low-quality resizing. - input.resize_effect:set_int("width", 1) - input.resize_effect:set_int("height", 1) + input.resample_effect:choose(ResizeEffect) -- Low-quality resizing. + input.resample_effect:set_int("width", 1) + input.resample_effect:set_int("height", 1) input.padding_effect:set_int("left", screen_width + 100) input.padding_effect:set_int("top", screen_height + 100) return @@ -976,7 +1029,7 @@ function place_rectangle(input, x0, y0, x1, y1, screen_width, screen_height, inp if hq then -- High-quality resampling. - input.resample_switcher:choose(ResampleEffect) + local resample_effect = input.resample_effect:choose(ResampleEffect) local x_subpixel_offset = x0 - math.floor(x0) local y_subpixel_offset = y0 - math.floor(y0) @@ -992,18 +1045,18 @@ function place_rectangle(input, x0, y0, x1, y1, screen_width, screen_height, inp -- excess edge of pixels and subpixels, which we'll correct for soon.) local zoom_x = (x1 - x0) / (width * (srcx1 - srcx0)) local zoom_y = (y1 - y0) / (height * (srcy1 - srcy0)) - input.resample_effect:set_float("zoom_x", zoom_x) - input.resample_effect:set_float("zoom_y", zoom_y) - input.resample_effect:set_float("zoom_center_x", 0.0) - input.resample_effect:set_float("zoom_center_y", 0.0) + resample_effect:set_float("zoom_x", zoom_x) -- Use the actual effect specialization; specific to ResampleEffect. + resample_effect:set_float("zoom_y", zoom_y) + resample_effect:set_float("zoom_center_x", 0.0) + resample_effect:set_float("zoom_center_y", 0.0) -- Padding must also be to a whole-pixel offset. input.padding_effect:set_int("left", math.floor(x0)) input.padding_effect:set_int("top", math.floor(y0)) -- Correct _that_ discrepancy by subpixel offset in the resampling. - input.resample_effect:set_float("left", srcx0 * input_width - x_subpixel_offset / zoom_x) - input.resample_effect:set_float("top", srcy0 * input_height - y_subpixel_offset / zoom_y) + resample_effect:set_float("left", srcx0 * input_width - x_subpixel_offset / zoom_x) + resample_effect:set_float("top", srcy0 * input_height - y_subpixel_offset / zoom_y) -- Finally, adjust the border so it is exactly where we want it. input.padding_effect:set_float("border_offset_left", x_subpixel_offset) @@ -1012,12 +1065,12 @@ function place_rectangle(input, x0, y0, x1, y1, screen_width, screen_height, inp input.padding_effect:set_float("border_offset_bottom", y1 - (math.floor(y0) + height)) else -- Lower-quality simple resizing. - input.resample_switcher:choose(ResizeEffect) + input.resample_effect:choose(ResizeEffect) local width = round(x1 - x0) local height = round(y1 - y0) - input.resize_effect:set_int("width", width) - input.resize_effect:set_int("height", height) + input.resample_effect:set_int("width", width) + input.resample_effect:set_int("height", height) -- Padding must also be to a whole-pixel offset. input.padding_effect:set_int("left", math.floor(x0)) @@ -1051,16 +1104,6 @@ function prepare_overlay_static(scene) end end -function set_neutral_color(effect, color) - effect:set_vec3("neutral_color", color[1], color[2], color[3]) -end - -function set_neutral_color_from_signal(state, effect, signal) - if is_plain_signal(signal) then - set_neutral_color(effect, state.neutral_colors[signal - INPUT0_SIGNAL_NUM + 1]) - end -end - function calc_zoom_progress(t) if t < state.transition_start then return 0.0 @@ -1091,5 +1134,6 @@ end ThemeMenu.set( { "Reload overlay", reload_cef }, - { "Disconnect IPTV", disconnect_iptv } + { "Disconnect IPTV", disconnect_iptv }, + { "Toggle multiviewer", toggle_multiviewer } )