]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - udp_send.c
Merge commit 'athcx/master'
[paraslash.git] / udp_send.c
index e83239d346bdcad9c97c7defb8874a68d9dcf997..3804c39c1b96571e6a6553c97ed5dd690284c47f 100644 (file)
@@ -68,6 +68,7 @@ static void udp_delete_target(struct udp_target *ut, const char *msg)
        free(ut);
 }
 
+/** The maximal size of the per-target chunk queue. */
 #define UDP_CQ_BYTES 40000
 
 static int udp_init_session(struct udp_target *ut)
@@ -136,9 +137,12 @@ static void udp_shutdown_targets(void)
 {
        char buf[UDP_AUDIO_HEADER_LEN];
        struct udp_target *ut, *tmp;
+       struct udp_audio_header uah = {
+               .stream_type = UDP_UNKNOWN_STREAM,
+               .packet_type = UDP_EOF_PACKET,
+       };
 
-       udp_write_packet_type(buf, UDP_EOF_PACKET);
-       udp_write_magic(buf);
+       write_udp_audio_header(buf, &uah);
        list_for_each_entry_safe(ut, tmp, &targets, node) {
                if (ut->fd < 0)
                        continue;
@@ -165,11 +169,10 @@ static void udp_send(long unsigned current_chunk, __a_unused long unsigned chunk
                const char *buf, size_t len, const char *header_buf,
                size_t header_len)
 {
-       size_t sendbuf_len;
-       uint8_t packet_type = UDP_DATA_PACKET;
        char *sendbuf;
+       size_t sendbuf_len;
        struct timeval *chunk_tv;
-       uint8_t stream_type = header_len? UDP_HEADER_STREAM : UDP_PLAIN_STREAM;
+       struct udp_audio_header uah;
 
 //     PARA_NOTICE_LOG("len: %zd, header_len: %zd\n", len, header_len);
        if (sender_status != SENDER_ON)
@@ -181,22 +184,22 @@ static void udp_send(long unsigned current_chunk, __a_unused long unsigned chunk
                return;
        if (list_empty(&targets))
                return;
-       if (!need_extra_header(current_chunk))
-               header_len = 0;
+       uah.stream_type = header_len? UDP_HEADER_STREAM : UDP_PLAIN_STREAM;
+       uah.header_len = 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;
+               uah.packet_type = UDP_BOF_PACKET;
+       else if (uah.header_len)
+               uah.packet_type = UDP_HEADER_PACKET;
+       else
+               uah.packet_type = UDP_DATA_PACKET;
+       uah.payload_len = uah.header_len + len;
+       sendbuf_len = UDP_AUDIO_HEADER_LEN + uah.payload_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)
+       write_udp_audio_header(sendbuf, &uah);
+       if (uah.header_len)
                memcpy(sendbuf + UDP_AUDIO_HEADER_LEN, header_buf,
-                       header_len);
-       memcpy(sendbuf + UDP_AUDIO_HEADER_LEN + header_len, buf, len);
+                       uah.header_len);
+       memcpy(sendbuf + UDP_AUDIO_HEADER_LEN + uah.header_len, buf, len);
        udp_send_buf(sendbuf, sendbuf_len);
        free(sendbuf);
 }