From 9a5eb9c9d6592b269ba0e39f9cee22ef3313f685 Mon Sep 17 00:00:00 2001
From: cbdev <cb@cbcdn.com>
Date: Fri, 23 Oct 2020 19:58:58 +0200
Subject: Implement ArtNet realtime option

---
 backends/artnet.c | 23 +++++++++++++++--------
 backends/artnet.h |  1 +
 2 files changed, 16 insertions(+), 8 deletions(-)

(limited to 'backends')

diff --git a/backends/artnet.c b/backends/artnet.c
index 4a7907d..dae9ba3 100644
--- a/backends/artnet.c
+++ b/backends/artnet.c
@@ -168,6 +168,10 @@ static int artnet_configure_instance(instance* inst, char* option, char* value){
 
 		return mmbackend_parse_sockaddr(host, port ? port : ARTNET_PORT, &data->dest_addr, &data->dest_len);
 	}
+	else if(!strcmp(option, "realtime")){
+		data->realtime = strtoul(value, NULL, 10);
+		return 0;
+	}
 
 	LOGPF("Unknown instance option %s for instance %s", option, inst->name);
 	return 1;
@@ -294,21 +298,24 @@ static int artnet_set(instance* inst, size_t num, channel** c, channel_value* v)
 	}
 
 	if(mark){
-		//find last frame time
+		//find output control data for the instance
 		for(u = 0; u < global_cfg.fd[data->fd_index].output_instances; u++){
 			if(global_cfg.fd[data->fd_index].output_instance[u].label == inst->ident){
 				break;
 			}
 		}
 
-		frame_delta = mm_timestamp() - global_cfg.fd[data->fd_index].output_instance[u].last_frame;
-		//check output rate limit, request next frame
-		if(frame_delta < ARTNET_FRAME_TIMEOUT){
-			global_cfg.fd[data->fd_index].output_instance[u].mark = 1;
-			if(!global_cfg.next_frame || global_cfg.next_frame > (ARTNET_FRAME_TIMEOUT - frame_delta)){
-				global_cfg.next_frame = (ARTNET_FRAME_TIMEOUT - frame_delta);
+		if(!data->realtime){
+			frame_delta = mm_timestamp() - global_cfg.fd[data->fd_index].output_instance[u].last_frame;
+
+			//check output rate limit, request next frame
+			if(frame_delta < ARTNET_FRAME_TIMEOUT){
+				global_cfg.fd[data->fd_index].output_instance[u].mark = 1;
+				if(!global_cfg.next_frame || global_cfg.next_frame > (ARTNET_FRAME_TIMEOUT - frame_delta)){
+					global_cfg.next_frame = (ARTNET_FRAME_TIMEOUT - frame_delta);
+				}
+				return 0;
 			}
-			return 0;
 		}
 		return artnet_transmit(inst, global_cfg.fd[data->fd_index].output_instance + u);
 	}
diff --git a/backends/artnet.h b/backends/artnet.h
index ecd775e..b42646d 100644
--- a/backends/artnet.h
+++ b/backends/artnet.h
@@ -48,6 +48,7 @@ typedef struct /*_artnet_instance_model*/ {
 	artnet_universe data;
 	size_t fd_index;
 	uint64_t last_input;
+	uint8_t realtime;
 } artnet_instance_data;
 
 typedef union /*_artnet_instance_id*/ {
-- 
cgit v1.2.3