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)
{
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;
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)
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);
}