diff --git a/libvisca.lua b/libvisca.lua index 8d40501..3e01cbd 100644 --- a/libvisca.lua +++ b/libvisca.lua @@ -297,6 +297,9 @@ function Visca.set_log_function(func) end --- @class PayloadCommand object +--- @field category integer The Visca command category +--- @field command integer The Visca command +--- @field arguments table The command data bytes Visca.PayloadCommand = {} Visca.PayloadCommand.__index = Visca.PayloadCommand @@ -366,6 +369,9 @@ function Visca.PayloadCommand:as_string() end --- @class PayloadReply object +--- @field error_type integer The reply error type - if any +--- @field arguments table The command reply data bytes +--- @field argument_cnt integer The nummer of reply data bytes Visca.PayloadReply = {} Visca.PayloadReply.__index = Visca.PayloadReply @@ -535,6 +541,10 @@ function Visca.PayloadReply:as_string() end --- @class Message Visca Message object +--- @field payload_size number The lenght in bytes of the payload in the message +--- @field seq_nr number Sequential incrementing number of the message +--- @field payload table The raw data in the massage +--- @field message table Structure containing the decoded response object, either a PayloadCommand or PayloadReply Visca.Message = {} Visca.Message.__index = Visca.Message @@ -607,7 +617,7 @@ end --- Generate a data bytestring of this message --- ---- @param mode ViscaModes +--- @param mode ViscaModes|integer --- @return string function Visca.Message:to_data(mode) mode = mode or Visca.modes.generic @@ -641,7 +651,7 @@ end --- Generate a human readable representation in hex of this message --- ---- @param mode ViscaModes +--- @param mode ViscaModes|integer function Visca.Message:as_string(mode) mode = mode or Visca.modes.generic local bin_str = self:to_data(mode) @@ -716,8 +726,12 @@ Visca.ReplyServer = { function Visca.ReplyServer.add_listener_for(address, port) local cnt = (Visca.ReplyServer.clients[port] or 0) + --- @type string|table|nil + local err + if cnt == 0 then - local sock_address, err, num = socket.find_first_address("*", port, + local sock_address, num + sock_address, err, num = socket.find_first_address("*", port, {family="inet", socket_type="dgram", protocol="udp"}) if sock_address then local server @@ -811,6 +825,8 @@ end --- @class Transmission The Transmission object tracks responses received on a send message. --- It stores the response by type (ack, error or completion) and tracks timeout. +--- @field send Message The message send +--- @field send_timestamp number|nil The timestamp in nanseconds at which the message was send, or nil Visca.Transmission = {} Visca.Transmission.__index = Visca.Transmission @@ -874,13 +890,19 @@ function Visca.Transmission:inquiry_data() end --- @class Connection Connection to a Visca camera +--- @field private sock_address unknown The socket address structure of the destination +--- @field public sock_err string The last error obtained from the socket or address detection +--- @field private address string The IP address or DNS of the camera +--- @field private transmission_queue Transmission[] List of Transmission objects +--- @field private callbacks table List of callbacks: [type][id] = function +--- @field private compatibility table List of compatibility settings (key/value) Visca.Connection = {} Visca.Connection.__index = Visca.Connection --- Visca Connection constructor --- --- @param address string The IP address or DNS of the camera ---- @param port number The Visca control port of the camera +--- @param port integer|nil The Visca control port of the camera --- @return Connection function Visca.Connection.new(address, port) port = port or Visca.default_port @@ -913,7 +935,7 @@ function Visca.Connection.new(address, port) return connection end ---- @param mode ViscaModes +--- @param mode ViscaModes|integer function Visca.Connection:set_mode(mode) if Visca.modes:has_value(mode or Visca.modes.generic) then self.mode = mode @@ -1036,16 +1058,17 @@ function Visca.Connection:__transmissions_process() local transmit_size = 0 local transmit_data + local remove_transmission = false for i,t in pairs(self.transmission_queue) do if t:timed_out() then self:__exec_callback('timeout', t) - t = nil + remove_transmission = true elseif t.error or t.completion then -- Message transaction completed, remove from queue - t = nil + remove_transmission = true end - if not t then + if remove_transmission or not t then self.transmission_queue[i] = nil end end @@ -1601,8 +1624,9 @@ end --- Connect to a Visca capable camera --- --- @param address string The IP address or DNS of the camera ---- @param port number The Visca control port of the camera +--- @param port integer|nil The Visca control port of the camera --- @return Connection +--- @overload fun(addres: string, port: integer|nil): nil,string function Visca.connect(address, port) ---@type Connection local connection = Visca.Connection.new(address, port) diff --git a/obs-visca-control.lua b/obs-visca-control.lua index 1c5ccf5..719dfe6 100644 --- a/obs-visca-control.lua +++ b/obs-visca-control.lua @@ -1284,7 +1284,7 @@ local function source_signal_processor(source_settings, source_name, signal) -- In case the stop action applies to a different camera than the scene for which the activate signal is -- send, the stop action execution is postponed until the scene deactivation, to speed up transition. for program_scene_name, program_scene_active in pairs(plugin_data.program_scene) do - if program_scene_active and current_program_scene_name ~= program_scene_name then + if program_scene_active and (current_program_scene_name ~= program_scene_name) then for _, program_source_name, program_source_settings, program_source_is_visible in get_plugin_settings_from_scene(program_scene_name, camera_id) do if program_source_settings ~= nil and program_source_is_visible then diff --git a/test/libvisca_test.lua b/test/libvisca_test.lua index 02267ef..028090a 100644 --- a/test/libvisca_test.lua +++ b/test/libvisca_test.lua @@ -41,18 +41,26 @@ end module("libvisca_test", lunit.testcase, package.seeall) ---- @type: Visca.Connection +--- @type Connection local connection function setup() + --- @diagnostic disable-next-line: cast-local-type connection = Visca.connect('127.1.2.101') - lunit.assert_true(connection:set_mode(Visca.modes.generic)) + lunit.assert_not_nil(connection) + if connection ~= nil then + lunit.assert_true(connection:set_mode(Visca.modes.generic)) + end end function teardown() --connection:close() end +function test_visca_mode() + lunit.assert_equal(0, Visca.modes.generic) +end + function test_set_preset_4() local set_preset_4 = Visca.Message.new():from_data("\x01\x00\x00\x07\x00\x00\x00\x01\x81\x01\x04\x3f\x02\x03\xff"):dump("set preset 4") lunit.assert_equal(Visca.payload_types.visca_command, set_preset_4.payload_type, "invalid payload") @@ -130,7 +138,6 @@ function test_cam_reset_recall_8_ptzoptics() end function test_cam_reset_recall_6_jvc() - connection:set_compatibility(nil) local _, data = connection:Cam_Preset_Recall(6) local recv_msg = Visca.Message.new():from_data(data):dump("Cam_Preset_Recall 6 normal") lunit.assert_not_nil(recv_msg.message.command) diff --git a/test/stubs/obslua.lua b/test/stubs/obslua.lua index 1871d7a..11ff5c5 100644 --- a/test/stubs/obslua.lua +++ b/test/stubs/obslua.lua @@ -1,3 +1,5 @@ +--- @meta OBS + local socket = require("socket") -- Definition of globals to reproduce the Lua scripting environment in OBS - bfxdev 2020 @@ -26,7 +28,7 @@ function gcinfo(param) end --- either a new, empty metatable on it or using the metatable of another newproxy instance. We are --- then free to modify the metatable from Lua. This is the only way to create a proxy object from --- Lua which honors certain metamethods, such as __len. ---- @param param bool +--- @param param boolean function newproxy(param) end --- OBS function that returns the path of the folder of the current script @@ -39,6 +41,57 @@ function swig_equals() end --- SWIG function that returns as a string the type of object pointed to by the argument (assuming it was a SWIG wrapped object) function swig_type(obj) end +--- OBS Objects + +--- @class obs_data_item Data Settings +--- @field name string Name of data item +local obs_data_item = {} + +--- @class obs_data Data Settings +--- @field json string Json representation +--- @field items array List of obs_data_items +local obs_data = {} + +--- @type table +local obs_data_array = {} + +--- @class obs_property Data Settings +local obs_property = {} + +--- @class obs_properties Data Settings +local obs_properties = {} + +--- @class obs_encoder Encoder +local obs_encoder = {} + +--- @enum obs_frontend_event OBS Frontend Event +local obs_frontend_event = {} + +--- @class obs_frontend_source +local obs_frontend_source = {} + +--- @type table +local obs_frontend_source_list = {} + +--- @class obs_hotkey data structure +--- @field id integer Internal hotkey identifier +--- @field name string The shortname +--- @field description string Descriptive name of the shorcut show in the UI +local obs_hotkey = {} + +--- @class obs_scene data structure +--- @field source obs_source +local obs_scene = {} + +--- @class obs_scene_item data structure +local obs_scene_item = {} + +--- @class obs_source data structure +local obs_source = {} + +--- @type table +local sources_list = {} + --- Main obslua module obslua = {} @@ -461,7 +514,6 @@ function obslua.blog(log_level, format) end --- --- C definition: `void *bmalloc(size_t size)` --- @param size number ---- @return void function obslua.bmalloc(size) end --- Duplicates memory. @@ -469,7 +521,6 @@ function obslua.bmalloc(size) end --- C definition: `void *bmemdup(const void *ptr, size_t size)` --- @param ptr ref_void* --- @param size number ---- @return void function obslua.bmemdup(ptr, size) end --- Returns current number of active allocations. @@ -484,7 +535,6 @@ function obslua.bnum_allocs() end --- C definition: `void *brealloc(void *ptr, size_t size)` --- @param ptr ref_void* --- @param size number ---- @return void function obslua.brealloc(ptr, size) end --- Duplicates a string. @@ -578,7 +628,7 @@ function obslua.calldata_free(data) end --- C definition: Not available --- @param param1 calldata --- @param param2 string ---- @param param3 bool +--- @param param3 boolean function obslua.calldata_get_bool(param1, param2, param3) end --- Not mentioned in OBS documentation @@ -659,7 +709,6 @@ function obslua.calldata_int(data, name) end --- C definition: `void *calldata_ptr(const calldata_t *data, const char *name)` --- @param data calldata --- @param name string ---- @return void function obslua.calldata_ptr(data, name) end --- Casts a pointer parameter of a calldata_t object to an @@ -1187,7 +1236,6 @@ function obslua.gs_effect_get_technique(effect, name) end --- --- C definition: `void *gs_effect_get_val(gs_eparam_t *param)` --- @param param gs_effect_param ---- @return void function obslua.gs_effect_get_val(param) end --- Returns the size in bytes of the param's current value. @@ -1714,7 +1762,6 @@ function obslua.gs_indexbuffer_flush_direct(indexbuffer, data) end --- --- C definition: `void *gs_indexbuffer_get_data(const gs_indexbuffer_t *indexbuffer)` --- @param indexbuffer gs_index_buffer ---- @return void function obslua.gs_indexbuffer_get_data(indexbuffer) end --- Gets the number of indices associated with this index buffer. @@ -2574,7 +2621,7 @@ function obslua.gs_timer_range_end(param1) end --- --- C definition: Not available --- @param param1 gs_timer_range ---- @param param2 bool +--- @param param2 boolean --- @param param3 unsigned_long_long function obslua.gs_timer_range_get_data(param1, param2, param3) end @@ -3433,7 +3480,9 @@ function obslua.obs_data_get_autoselect_vec4(param1, param2, param3) end --- @param data obs_data --- @param name string --- @return boolean -function obslua.obs_data_get_bool(data, name) end +function obslua.obs_data_get_bool(data, name) + return (data[name] or (data[name] == "true") or (data[name] == "1")) and true or false +end --- Not mentioned in OBS documentation --- @@ -4209,7 +4258,7 @@ function obslua.obs_data_set_quat(param1, param2, param3) end --- C definition: `void obs_data_set_string(obs_data_t *data, const char *name, const char *val)` --- @param data obs_data --- @param name string ---- @param val string +--- @param val string|nil function obslua.obs_data_set_string(data, name, val) end --- Not mentioned in OBS documentation @@ -4880,8 +4929,8 @@ function obslua.obs_find_module_file(module, file) end --- :param private_data: Private data associated with the callback. --- --- C definition: `void obs_frontend_add_event_callback(obs_frontend_event_cb callback, void *private_data)` ---- @param callback obs_frontend_event_cb ---- @param private_data void* +--- @param callback fun(event: obs_frontend_event, private_data: void*) +--- @param private_data void*|nil function obslua.obs_frontend_add_event_callback(callback, private_data) end --- Adds a callback that will be called when the current scene collection @@ -4995,8 +5044,8 @@ function obslua.obs_frontend_get_scene_names() end --- :c:func:`obs_frontend_source_list_free`. --- --- C definition: `void obs_frontend_get_scenes(struct obs_frontend_source_list *sources)` ---- @param sources obs_frontend_source_list* -function obslua.obs_frontend_get_scenes(sources) end +--- @return obs_frontend_source_list +function obslua.obs_frontend_get_scenes() end --- :return: A new reference to the current streaming output. --- @@ -5078,7 +5127,7 @@ function obslua.obs_frontend_recording_stop() end --- :param private_data: Private data associated with the callback. --- --- C definition: `void obs_frontend_remove_event_callback(obs_frontend_event_cb callback, void *private_data)` ---- @param callback obs_frontend_event_cb +--- @param callback fun(event: obs_frontend_event, private_data: void*) --- @param private_data void* function obslua.obs_frontend_remove_event_callback(callback, private_data) end @@ -5198,7 +5247,6 @@ function obslua.obs_frontend_streaming_stop() end --- Takes a screenshot of the main OBS output. --- --- C definition: `void *obs_frontend_take_screenshot(void)` ---- @return void* function obslua.obs_frontend_take_screenshot() end --- Takes a screenshot of the specified source. @@ -5206,7 +5254,6 @@ function obslua.obs_frontend_take_screenshot() end --- :param source: The source to take screenshot of. --- C definition: `void *obs_frontend_take_source_screenshot(obs_source_t *source)` --- @param source obs_source ---- @return void* function obslua.obs_frontend_take_source_screenshot(source) end --- Not mentioned in OBS documentation @@ -5709,16 +5756,17 @@ function obslua.obs_hotkey_pair_unregister(param1) end --- the callback. --- --- C definition: Not available ---- @param name unknown ---- @param description unknown +--- @param name string +--- @param description string --- @param callback unknown ---- @return unknown +--- @return integer function obslua.obs_hotkey_register_frontend(name, description, callback) end --- Not mentioned in OBS documentation --- --- C definition: Not available --- @param param1 number +--- @return obs_data_array function obslua.obs_hotkey_save(param1) end --- Not mentioned in OBS documentation @@ -7081,7 +7129,6 @@ function obslua.obs_properties_get_flags(props) end --- --- C definition: `void *obs_properties_get_param(obs_properties_t *props)` --- @param props obs_properties ---- @return void function obslua.obs_properties_get_param(props) end --- C definition: `obs_properties_t *obs_properties_get_parent(obs_properties_t *props)` @@ -7542,8 +7589,8 @@ function obslua.obs_property_set_long_description(p, long_description) end --- obs_data_t *settings); --- --- C definition: `void obs_property_set_modified_callback(obs_property_t *p, obs_property_modified_t modified)` ---- @param p obs_property_t* ---- @param modified obs_property_modified_t +--- @param p obs_property +--- @param modified fun(props: obs_properties, property: obs_property, settings: obs_data): boolean function obslua.obs_property_set_modified_callback(p, modified) end --- Allows the ability to change the properties depending on what @@ -7849,10 +7896,8 @@ function obslua.obs_scene_duplicate(scene, name, type) end --- --- C definition: Not available --- @param scene obs_scene ---- @param param2 f_p_struct_obs_scene_p_struct_obs_scene_item_p_void__bool ---- @param param3 ref_void* ---- @return unknown -function obslua.obs_scene_enum_items(scene, param2, param3) end +--- @return sources_list +function obslua.obs_scene_enum_items(scene) end --- :param id: The unique numeric identifier of the scene item --- :return: The scene item if found, otherwise *NULL* if not found @@ -10350,7 +10395,6 @@ function obslua.os_dlclose(module) end --- --- C definition: `void *os_dlopen(const char *path)` --- @param path string ---- @return void function obslua.os_dlopen(path) end --- Returns a symbol from a dynamic library. @@ -10358,7 +10402,6 @@ function obslua.os_dlopen(path) end --- C definition: `void *os_dlsym(void *module, const char *func)` --- @param module ref_void* --- @param func string ---- @return void function obslua.os_dlsym(module, func) end --- Converts a double to a string.