gboolean write_udp (xmmsc_vis_udp_t *t, xmms_vis_client_t *c, int32_t id, struct timeval *time, int channels, int size, short *buf, int socket) { xmmsc_vis_udp_data_t packet_d; xmmsc_vischunk_t *__unaligned_dest; short res; int offset; char* packet; /* first check if the client is still there */ if (t->grace == 0) { delete_client (id); return FALSE; } if (t->socket == 0) { return FALSE; } packet = packet_init_data (&packet_d); t->grace--; XMMSC_VIS_UNALIGNED_WRITE (packet_d.__unaligned_grace, htons (t->grace), uint16_t); __unaligned_dest = packet_d.__unaligned_data; XMMSC_VIS_UNALIGNED_WRITE (&__unaligned_dest->timestamp[0], (int32_t)htonl (time->tv_sec), int32_t); XMMSC_VIS_UNALIGNED_WRITE (&__unaligned_dest->timestamp[1], (int32_t)htonl (time->tv_usec), int32_t); XMMSC_VIS_UNALIGNED_WRITE (&__unaligned_dest->format, (uint16_t)htons (c->format), uint16_t); res = fill_buffer (__unaligned_dest->data, &c->prop, channels, size, buf); XMMSC_VIS_UNALIGNED_WRITE (&__unaligned_dest->size, (uint16_t)htons (res), uint16_t); offset = ((char*)&__unaligned_dest->data - (char*)__unaligned_dest); sendto (socket, packet, XMMS_VISPACKET_UDP_OFFSET + offset + res * sizeof (int16_t), 0, (struct sockaddr *)&t->addr, sizeof (t->addr)); free (packet); return TRUE; }
int read_do_udp (xmmsc_vis_udp_t *t, xmmsc_visualization_t *v, short *buffer, int drawtime, unsigned int blocking) { int old; int ret; int i, size; xmmsc_vis_udp_data_t packet_d; char* packet = packet_init_data (&packet_d); xmmsc_vischunk_t data; if (blocking) { wait_for_socket (t, blocking); } ret = recv (t->socket[0], packet, packet_d.size, 0); if ((ret > 0) && (*packet_d.__unaligned_type == 'V')) { uint16_t grace; struct timeval rtv; XMMSC_VIS_UNALIGNED_READ (data, packet_d.__unaligned_data, xmmsc_vischunk_t); /* resync connection */ XMMSC_VIS_UNALIGNED_READ (grace, packet_d.__unaligned_grace, uint16_t); grace = ntohs (grace); if (grace < 1000) { if (t->grace != 0) { t->grace = 0; /* use second socket here, so vis packets don't get lost */ t->timediff = udp_timediff (v->id, t->socket[1]); } } else { t->grace = grace; } /* include the measured time difference */ rtv.tv_sec = ntohl (data.timestamp[0]); rtv.tv_usec = ntohl (data.timestamp[1]); double interim = tv2ts (&rtv); interim -= t->timediff; ts2net (data.timestamp, interim); ret = 1; } else { if (ret == 1 && *packet_d.__unaligned_type == 'K') { ret = -1; } else if (ret > -1 || xmms_socket_error_recoverable ()) { ret = 0; } else { ret = -1; } free (packet); return ret; } old = check_drawtime (net2ts (data.timestamp), drawtime); if (!old) { size = ntohs (data.size); for (i = 0; i < size; ++i) { buffer[i] = (int16_t)ntohs (data.data[i]); } } free (packet); if (!old) { return size; } return 0; }