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 8
18 /** The possible stream types. */
19 enum udp_stream_type {
20 /** Used for mp3 and aac streams. */
22 /* Ogg vorbis streams. */
26 /** The possible packet types. */
27 enum udp_audio_packet_type {
28 /** Beginning of file. */
32 /** Combined header/data packet (ogg only). */
34 /** Packet contains only audio file data. */
39 * Write the magic bytes to the beginning of a buffer.
41 * \param buf The buffer.
43 _static_inline_ void udp_write_magic(char *buf)
45 memcpy(buf, "UDPM", 4);
49 * Check whether this buffer contains the magic bytes.
51 * \param buf The buffer.
52 * \param len The number of bytes of \a buf.
54 * \return Positive if \a buf contains the magic bytes,
57 _static_inline_ int udp_check_magic(char *buf, size_t len)
61 if (memcmp(buf, "UDPM", 4))
67 * Write the type of the audio stream to a buffer.
69 * \param buf The buffer.
70 * \param type The type to be written.
72 * \sa \ref udp_stream_type.
74 _static_inline_ void udp_write_stream_type(char *buf, uint8_t type)
76 write_u8(buf + 4, type);
80 * Read the type of the audio stream from a buffer.
82 * \param buf The buffer.
84 * \return Either UDP_PLAIN_STREAM or UDP_HEADER_STREAM.
85 * \sa \ref udp_stream_type.
87 _static_inline_ uint8_t udp_read_stream_type(char *buf)
89 return read_u8(buf + 4);
93 * Write the type of this packet to a buffer.
95 * \param buf The buffer.
96 * \param type The type to be written.
98 * \sa \ref udp_audio_packet_type.
100 _static_inline_ void udp_write_packet_type(char *buf, uint8_t type)
102 write_u8(buf + 5, type);
106 * Read the type of this buffer.
108 * \param buf The buffer.
110 * \return The packet type, see \ref udp_stream_type.
112 _static_inline_ uint8_t udp_read_packet_type(char *buf)
114 return read_u8(buf + 5);
118 * Write the length of the header (non-zero only for ogg streams).
120 * \param buf The buffer.
121 * \param len The length of the header in bytes.
123 _static_inline_ void udp_write_header_len(char *buf, uint16_t len)
125 write_u16(buf + 6, len);
129 * Read the length of the header.
131 * \param buf The buffer.
132 * \return The header length in bytes.
134 _static_inline_ uint16_t udp_read_header_len(char *buf)
136 return read_u16(buf + 6);