Skip to content

Commit

Permalink
Add special compatibility behavior option for sequence numbering; app…
Browse files Browse the repository at this point in the history
…ly for NewTek PTZ1 NDI (#7)
  • Loading branch information
vwout committed Jan 5, 2023
1 parent ded1892 commit 40bbb8a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
31 changes: 26 additions & 5 deletions libvisca.lua
Expand Up @@ -256,6 +256,12 @@ Visca.CameraModel = {
}
setmetatable(Visca.CameraModel, Visca.CameraModelMeta)

--- @class ViscaCompatibility Configuration table with camera compatibility options
Visca.compatibility = {
fixed_sequence_number = nil, -- Set to a non-nil numeric value to keep the message sequence counter at a fixed value
}


--- @class PayloadCommand object
Visca.PayloadCommand = {}
Visca.PayloadCommand.__index = Visca.PayloadCommand
Expand Down Expand Up @@ -795,7 +801,8 @@ function Visca.Connection.new(address, port)
sock_err = sock_err,
mode = Visca.modes.generic,
transmission_queue = {}, -- List of Transmission objects
callbacks = {} -- List of callbacks: [type][id] = function
callbacks = {}, -- List of callbacks: [type][id] = function
compatibility = {} -- List of compatibility settings (key/value)
}
setmetatable(connection, Visca.Connection)

Expand All @@ -821,6 +828,15 @@ function Visca.Connection:set_mode(mode)
end
end

--- @param compatibility ViscaCompatibility
function Visca.Connection:set_compatibility(compatibility)
compatibility = compatibility or {}

for k,v in pairs(compatibility) do
self.compatibility[k] = v
end
end

function Visca.Connection:__register_callback(callback_type, id, callback)
if type(self.callbacks[callback_type]) ~= 'table' then
self.callbacks[callback_type] = {}
Expand Down Expand Up @@ -972,12 +988,17 @@ end

--- @param message Message
function Visca.Connection:send(message)
if self.last_seq_nr < 0xFFFFFFFF then
self.last_seq_nr = self.last_seq_nr + 1
if self.compatibility.fixed_sequence_number then
message.seq_nr = self.compatibility.fixed_sequence_number or self.last_seq_nr
else
self.last_seq_nr = 0
if self.last_seq_nr < 0xFFFFFFFF then
self.last_seq_nr = self.last_seq_nr + 1
else
self.last_seq_nr = 0
end

message.seq_nr = self.last_seq_nr
end
message.seq_nr = self.last_seq_nr

table.insert(self.transmission_queue, Visca.Transmission.new(message))
return self:__transmissions_process()
Expand Down
5 changes: 5 additions & 0 deletions obs-visca-control.lua
Expand Up @@ -416,6 +416,11 @@ local function open_visca_connection(camera_id)
local version_info_setting = string.format("cam_%d_version_info", camera_id)
obs.obs_data_set_string(plugin_settings, version_info_setting, version_info)
log("Set setting %s to %s", version_info_setting, version_info)

if t_data.vendor_id == 0x0001 and t_data.model_code == 0x0513 then
-- NewTek PTZ1 NDI
connection.set_compatibility({ fixed_sequence_number = 1 })
end
end

if t_data.zoom or t_data.pan or t_data.tilt then
Expand Down

0 comments on commit 40bbb8a

Please sign in to comment.