7e94b5840ffd964fe46981cee1eb9005620ed198
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. */
11 * Number of bytes of the paraslash udp header.
13 * The udp sender prepends a header at the beginning of each data chunk. Within
14 * this header, the type of the current audio stream and the * type of this
15 * data chunk is coded.
17 #define UDP_AUDIO_HEADER_LEN 16
19 /** The possible stream types. */
20 enum udp_stream_type
{
21 /** Used for mp3 and aac streams. */
23 /** Ogg vorbis streams. */
25 /** stream type not yet known. */
29 /** The possible packet types. */
30 enum udp_audio_packet_type
{
31 /** Beginning of file. */
35 /** Combined header/data packet (ogg only). */
37 /** Packet contains only audio file data. */
39 /** Invalid packet type. */
43 /** The contents of an udp audio header. */
44 struct udp_audio_header
{
45 /** see \ref udp_stream_type. */
47 /** see \ref udp_audio_packet_type. */
49 /** Non-zero only for header packets. */
51 /** Length of header plus audio file data. */
56 * Write a struct udp_audio_header to a buffer.
58 * \param buf The buffer to write to.
59 * \param h The audio header to write.
61 * Used by the udp sender.
64 _static_inline_
void write_udp_audio_header(char *buf
, struct udp_audio_header
*h
)
66 memcpy(buf
, "UDPM", 4);
67 write_u8(buf
+ 4, h
->stream_type
);
68 write_u8(buf
+ 5, h
->packet_type
);
69 write_u16(buf
+ 6, h
->header_len
);
70 write_u16(buf
+ 8, h
->payload_len
);
71 memset(buf
+ 10, 0, 6);
75 * Used by the udp receiver to read a struct udp_audio_header from a buffer.
77 * \param buf The buffer to read from.
78 * \param len The length of \a buf.
79 * \param h Result pointer.
81 * \return 1 if \a buf contains a valid udp audio header, -1 else.
83 _static_inline_
int read_udp_audio_header(char *buf
, size_t len
,
84 struct udp_audio_header
*h
)
88 if (memcmp(buf
, "UDPM", 4))
90 h
->stream_type
= read_u8(buf
+ 4);
91 h
->packet_type
= read_u8(buf
+ 5);
92 h
->header_len
= read_u16(buf
+ 6);
93 h
->payload_len
= read_u16(buf
+ 8);
96 h
->stream_type
= UDP_UNKNOWN_STREAM
;
97 h
->packet_type
= UDP_UNKNOWN_PACKET
;
98 h
->header_len
= h
->payload_len
= 0;