Lines Matching defs:packet
64 #include "raop-packet-buffer.h"
134 /* Audio TCP packet header [16x8] (cf. rfc4571):
136 * [2,3] RTP packet size (following): 0x0000 (to be set)
150 /* Audio UDP packet header [12x8] (cf. rfc3550):
163 /* Audio retransmission UDP packet header [4x8]:
174 /* Sync packet header [8x8] (cf. rfc3550):
184 /* Timing packet header [8x8] (cf. rfc3550):
277 static size_t write_ALAC_data(uint8_t *packet, const size_t max, uint8_t *raw, size_t *length, bool compress) {
283 bp = packet;
284 pa_memzero(packet, max);
315 static size_t build_tcp_audio_packet(pa_raop_client *c, pa_memchunk *block, pa_memchunk *packet) {
322 buffer = pa_memblock_acquire(packet->memblock);
323 buffer += packet->index / sizeof(uint32_t);
340 size += write_ALAC_data(((uint8_t *) buffer + head), packet->length - head, raw, &length, false);
343 pa_memzero(((uint8_t *) buffer + head), packet->length - head);
355 pa_memblock_release(packet->memblock);
356 packet->length = size;
364 pa_memchunk *packet = NULL;
370 packet = pa_raop_packet_buffer_retrieve(c->pbuf, c->seq);
372 if (!packet || (packet && packet->length <= 0)) {
375 if (!(packet = pa_raop_packet_buffer_prepare(c->pbuf, c->seq, max)))
378 packet->index = 0;
379 packet->length = max;
380 if (!build_tcp_audio_packet(c, block, packet))
384 buffer = pa_memblock_acquire(packet->memblock);
388 buffer += packet->index;
389 if (buffer && packet->length > 0)
390 written = pa_write(c->tcp_sfd, buffer, packet->length, &write_type);
392 progress = (double) written / (double) packet->length;
393 packet->length -= written;
394 packet->index += written;
401 pa_memblock_release(packet->memblock);
406 static size_t build_udp_audio_packet(pa_raop_client *c, pa_memchunk *block, pa_memchunk *packet) {
413 buffer = pa_memblock_acquire(packet->memblock);
414 buffer += packet->index / sizeof(uint32_t);
427 size += write_ALAC_data(((uint8_t *) buffer + head), packet->length - head, raw, &length, false);
430 pa_memzero(((uint8_t *) buffer + head), packet->length - head);
447 pa_memblock_release(packet->memblock);
448 packet->length = size;
455 pa_memchunk *packet = NULL;
459 /* UDP packet has to be sent at once ! */
462 if (!(packet = pa_raop_packet_buffer_prepare(c->pbuf, c->seq, max)))
465 packet->index = sizeof(udp_audio_retrans_header);
466 packet->length = max - sizeof(udp_audio_retrans_header);
467 if (!build_udp_audio_packet(c, block, packet))
470 buffer = pa_memblock_acquire(packet->memblock);
474 buffer += packet->index;
475 if (buffer && packet->length > 0)
476 written = pa_write(c->udp_sfd, buffer, packet->length, NULL);
478 pa_log_debug("Discarding UDP (audio, seq=%d) packet due to EAGAIN (%s)", c->seq, pa_cstrerror(errno));
479 written = packet->length;
482 pa_memblock_release(packet->memblock);
490 static size_t rebuild_udp_audio_packet(pa_raop_client *c, uint16_t seq, pa_memchunk *packet) {
494 buffer = pa_memblock_acquire(packet->memblock);
498 size += packet->length;
500 pa_memblock_release(packet->memblock);
501 packet->length += sizeof(udp_audio_retrans_header);
502 packet->index -= sizeof(udp_audio_retrans_header);
512 pa_memchunk *packet = NULL;
516 if (!(packet = pa_raop_packet_buffer_retrieve(c->pbuf, seq + i)))
519 if (packet->index > 0) {
520 if (!rebuild_udp_audio_packet(c, seq + i, packet))
524 pa_assert(packet->index == 0);
526 buffer = pa_memblock_acquire(packet->memblock);
530 if (buffer && packet->length > 0)
531 written = pa_write(c->udp_cfd, buffer, packet->length, NULL);
533 pa_log_debug("Discarding UDP (audio-retransmitted, seq=%d) packet due to EAGAIN", seq + i);
534 pa_memblock_release(packet->memblock);
538 pa_memblock_release(packet->memblock);
545 /* Caller has to free the allocated memory region for packet */
546 static size_t build_udp_sync_packet(pa_raop_client *c, uint32_t stamp, uint32_t **packet) {
553 *packet = NULL;
569 *packet = buffer;
574 uint32_t * packet = NULL;
578 size = build_udp_sync_packet(c, stamp, &packet);
579 if (packet != NULL && size > 0) {
580 written = pa_loop_write(c->udp_cfd, packet, size, NULL);
581 pa_xfree(packet);
587 static size_t handle_udp_control_packet(pa_raop_client *c, const uint8_t packet[], ssize_t size) {
593 if (size != 8 || packet[0] != 0x80)
596 seq = ntohs((uint16_t) (packet[4] | packet[5] << 8));
597 nbp = ntohs((uint16_t) (packet[6] | packet[7] << 8));
601 /* The marker bit is always set (see rfc3550 for packet structure) ! */
602 payload = packet[1] ^ 0x80;
617 /* Caller has to free the allocated memory region for packet */
618 static size_t build_udp_timing_packet(pa_raop_client *c, const uint32_t data[6], uint64_t received, uint32_t **packet) {
624 *packet = NULL;
629 /* Copying originate timestamp from the incoming request packet. */
640 *packet = buffer;
645 uint32_t * packet = NULL;
649 size = build_udp_timing_packet(c, data, received, &packet);
650 if (packet != NULL && size > 0) {
651 written = pa_loop_write(c->udp_tfd, packet, size, NULL);
652 pa_xfree(packet);
658 static size_t handle_udp_timing_packet(pa_raop_client *c, const uint8_t packet[], ssize_t size) {
666 if (size != 32 || packet[0] != 0x80)
670 data = (uint32_t *) (packet + sizeof(udp_timing_header));
672 /* The marker bit is always set (see rfc3550 for packet structure) ! */
673 payload = packet[1] ^ 0x80;
676 pa_log_debug("Sending timing packet at %" PRIu64 , rci);
1096 /* Send an initial UDP packet so a connection tracking firewall
1101 pa_log_debug("Sent initial timing packet to UDP port %d", tport);
1806 void pa_raop_client_handle_oob_packet(pa_raop_client *c, const int fd, const uint8_t packet[], ssize_t size) {
1809 pa_assert(packet);
1813 pa_log_debug("Received UDP control packet...");
1814 handle_udp_control_packet(c, packet, size);
1816 pa_log_debug("Received UDP timing packet...");
1817 handle_udp_timing_packet(c, packet, size);