-static int need_extra_header(long unsigned current_chunk)
-{
- static struct timeval last_header;
- struct timeval diff;
-
- if (!current_chunk)
- return 0;
- tv_diff(now, &last_header, &diff);
- if (tv2ms(&diff) < conf.udp_header_interval_arg)
- return 0;
- last_header = *now;
- return 1;
-}
-
-static void udp_send(long unsigned current_chunk, __a_unused long unsigned chunks_sent,
- const char *buf, size_t len, const char *header_buf,
- size_t header_len)
-{
- struct udp_target *ut, *tmp;
- size_t sendbuf_len;
- uint8_t packet_type = UDP_DATA_PACKET;
- int ret;
- char *sendbuf;
- struct timeval *chunk_tv;
- uint8_t stream_type = header_len? UDP_HEADER_STREAM : UDP_PLAIN_STREAM;
-
-// PARA_NOTICE_LOG("header_len: %zd, header_buf: %p\n", header_len,
-// header_buf);
- if (sender_status != SENDER_ON)
- return;
-
- /* we might not yet know the chunk time */
- chunk_tv = vss_chunk_time();
- if (!chunk_tv)
- return;
- if (list_empty(&targets))
- return;
- list_for_each_entry_safe(ut, tmp, &targets, node) {
- ret = udp_init_session(ut);
- if (ret < 0)
- udp_delete_target(ut, para_strerror(-ret));
- }
- if (!need_extra_header(current_chunk))
- header_len = 0;
- if (!current_chunk)
- packet_type = UDP_BOF_PACKET;
- else if (header_len)
- packet_type = UDP_HEADER_PACKET;
- sendbuf_len = UDP_AUDIO_HEADER_LEN + header_len + len;
- sendbuf = para_malloc(sendbuf_len);
- udp_write_magic(sendbuf);
- udp_write_stream_type(sendbuf, stream_type);
- udp_write_packet_type(sendbuf, packet_type);
- udp_write_header_len(sendbuf, header_len);
- if (header_len)
- memcpy(sendbuf + UDP_AUDIO_HEADER_LEN, header_buf,
- header_len);
- memcpy(sendbuf + UDP_AUDIO_HEADER_LEN + header_len, buf, len);
- udp_send_buf(sendbuf, sendbuf_len);
- free(sendbuf);
-}
-