aboutsummaryrefslogtreecommitdiffhomepage
path: root/backends/artnet.c
diff options
context:
space:
mode:
authorcbdev <cb@cbcdn.com>2020-04-19 20:40:42 +0200
committercbdev <cb@cbcdn.com>2020-04-19 20:40:42 +0200
commit79b7e7dae5814942c04ca33e94e92b89547ffeb2 (patch)
tree0b1ca9a30b95d43604c81e7bde78786c33f8c186 /backends/artnet.c
parent7c1a283c9213dd273d04af72e24b08beb83aec12 (diff)
parent462b409d3d1fa16fcab0c7f8b475bb8d8e8b3e90 (diff)
downloadmidimonster-79b7e7dae5814942c04ca33e94e92b89547ffeb2.tar.gz
midimonster-79b7e7dae5814942c04ca33e94e92b89547ffeb2.tar.bz2
midimonster-79b7e7dae5814942c04ca33e94e92b89547ffeb2.zip
Merge current master to rtpmidirtpmidi
Diffstat (limited to 'backends/artnet.c')
-rw-r--r--backends/artnet.c43
1 files changed, 26 insertions, 17 deletions
diff --git a/backends/artnet.c b/backends/artnet.c
index caab6e0..585895b 100644
--- a/backends/artnet.c
+++ b/backends/artnet.c
@@ -206,10 +206,10 @@ static channel* artnet_channel(instance* inst, char* spec, uint8_t flags){
return data->data.channel + chan_a;
}
-static int artnet_transmit(instance* inst){
- size_t u;
+static int artnet_transmit(instance* inst, artnet_output_universe* output){
artnet_instance_data* data = (artnet_instance_data*) inst->impl;
- //output frame
+
+ //build output frame
artnet_pkt frame = {
.magic = {'A', 'r', 't', '-', 'N', 'e', 't', 0x00},
.opcode = htobe16(OpDmx),
@@ -224,16 +224,30 @@ static int artnet_transmit(instance* inst){
memcpy(frame.data, data->data.out, 512);
if(sendto(artnet_fd[data->fd_index].fd, (uint8_t*) &frame, sizeof(frame), 0, (struct sockaddr*) &data->dest_addr, data->dest_len) < 0){
- LOGPF("Failed to output frame for instance %s: %s", inst->name, strerror(errno));
+ #ifndef _WIN32
+ if(errno != EAGAIN){
+ LOGPF("Failed to output frame for instance %s: %s", inst->name, strerror(errno));
+ #else
+ if(WSAGetLastError() != WSAEWOULDBLOCK){
+ char* error = NULL;
+ FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL, WSAGetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &error, 0, NULL);
+ LOGPF("Failed to output frame for instance %s: %s", inst->name, error);
+ LocalFree(error);
+ #endif
+ return 1;
+ }
+ //reschedule frame output
+ output->mark = 1;
+ if(!next_frame || next_frame > ARTNET_SYNTHESIZE_MARGIN){
+ next_frame = ARTNET_SYNTHESIZE_MARGIN;
+ }
+ return 0;
}
//update last frame timestamp
- for(u = 0; u < artnet_fd[data->fd_index].output_instances; u++){
- if(artnet_fd[data->fd_index].output_instance[u].label == inst->ident){
- artnet_fd[data->fd_index].output_instance[u].last_frame = mm_timestamp();
- artnet_fd[data->fd_index].output_instance[u].mark = 0;
- }
- }
+ output->last_frame = mm_timestamp();
+ output->mark = 0;
return 0;
}
@@ -285,7 +299,7 @@ static int artnet_set(instance* inst, size_t num, channel** c, channel_value* v)
}
return 0;
}
- return artnet_transmit(inst);
+ return artnet_transmit(inst, artnet_fd[data->fd_index].output_instance + u);
}
return 0;
@@ -366,7 +380,7 @@ static int artnet_handle(size_t num, managed_fd* fds){
|| synthesize_delta >= ARTNET_KEEPALIVE_INTERVAL){ //keepalive timeout
inst = mm_instance_find(BACKEND_NAME, artnet_fd[u].output_instance[c].label);
if(inst){
- artnet_transmit(inst);
+ artnet_transmit(inst, artnet_fd[u].output_instance + c);
}
}
@@ -378,11 +392,6 @@ static int artnet_handle(size_t num, managed_fd* fds){
}
}
- if(!num){
- //early exit
- return 0;
- }
-
for(u = 0; u < num; u++){
do{
bytes_read = recv(fds[u].fd, recv_buf, sizeof(recv_buf), 0);