2 * Copyright (C) 2006-2009 Andre Noll <maan@systemlinux.org>
4 * Licensed under the GPL v2. For licencing details see COPYING.
7 /** \file udp_header.h some macros used by udp_send.c and udp_recv.c. */
10 * Number of bytes of the paraslash udp header.
12 * The udp sender prepends a header at the beginning of each data chunk. Within
13 * this header, the type of the current audio stream and the * type of this
14 * data chunk is coded.
16 #define UDP_AUDIO_HEADER_LEN 16
18 /** The possible stream types. */
19 enum udp_stream_type {
20 /** Used for mp3 and aac streams. */
22 /** Ogg vorbis streams. */
24 /** stream type not yet known. */
28 /** The possible packet types. */
29 enum udp_audio_packet_type {
30 /** Beginning of file. */
34 /** Combined header/data packet (ogg only). */
36 /** Packet contains only audio file data. */
38 /** Invalid packet type. */
42 /** The contents of an udp audio header. */
43 struct udp_audio_header {
44 /** see \ref udp_stream_type. */
46 /** see \ref udp_audio_packet_type. */
48 /** Non-zero only for header packets. */
50 /** Length of header plus audio file data. */
55 * Write a struct udp_audio_header to a buffer.
57 * \param buf The buffer to write to.
58 * \param h The audio header to write.
60 * Used by the udp sender.
63 _static_inline_ void write_udp_audio_header(char *buf, struct udp_audio_header *h)
65 memcpy(buf, "UDPM", 4);
66 write_u8(buf + 4, h->stream_type);
67 write_u8(buf + 5, h->packet_type);
68 write_u16(buf + 6, h->header_len);
69 write_u16(buf + 8, h->payload_len);
70 memset(buf + 10, 0, 6);
74 * Used by the udp receiver to read a struct udp_audio_header from a buffer.
76 * \param buf The buffer to read from.
77 * \param len The length of \a buf.
78 * \param h Result pointer.
80 * \return 1 if \a buf contains a valid udp audio header, -1 else.
82 _static_inline_ int read_udp_audio_header(char *buf, size_t len,
83 struct udp_audio_header *h)
87 if (memcmp(buf, "UDPM", 4))
89 h->stream_type = read_u8(buf + 4);
90 h->packet_type = read_u8(buf + 5);
91 h->header_len = read_u16(buf + 6);
92 h->payload_len = read_u16(buf + 8);
95 h->stream_type = UDP_UNKNOWN_STREAM;
96 h->packet_type = UDP_UNKNOWN_PACKET;
97 h->header_len = h->payload_len = 0;