]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - udp_header.h
Replace the ortp sender/receiver by the generic udp sender/receiver.
[paraslash.git] / udp_header.h
diff --git a/udp_header.h b/udp_header.h
new file mode 100644 (file)
index 0000000..5551805
--- /dev/null
@@ -0,0 +1,138 @@
+/*
+ * Copyright (C) 2006-2009 Andre Noll <maan@systemlinux.org>
+ *
+ * Licensed under the GPL v2. For licencing details see COPYING.
+ */
+
+/** \file udp_header.h some macros used by udp_send.c and udp_recv.c. */
+
+/**
+ * Number of bytes of the paraslash udp header.
+ *
+ * The udp sender prepends a header at the beginning of each data chunk. Within
+ * this header, the type of the current audio stream and the * type of this
+ * data chunk is coded.
+ */
+#define UDP_AUDIO_HEADER_LEN 8
+
+/** The possible stream types. */
+enum udp_stream_type {
+       /** Used for mp3 and aac streams. */
+       UDP_PLAIN_STREAM,
+       /* Ogg vorbis streams. */
+       UDP_HEADER_STREAM
+};
+
+/** The possible packet types. */
+enum udp_audio_packet_type {
+       /** End of file. */
+       UDP_EOF_PACKET,
+       /** Beginning of file. */
+       UDP_BOF_PACKET,
+       /** Combined header/data packet (ogg only). */
+       UDP_HEADER_PACKET,
+       /** Packet contains only audio file data. */
+       UDP_DATA_PACKET
+};
+
+/**
+ * Write the magic bytes to the beginning of a buffer.
+ *
+ * \param buf The buffer.
+ */
+_static_inline_ void udp_write_magic(char *buf)
+{
+       memcpy(buf, "UDPM", 4);
+}
+
+/**
+ * Check whether this buffer contains the magic bytes.
+ *
+ * \param buf The buffer.
+ * \param len The number of bytes of \a buf.
+ *
+ * \return Positive if \a buf contains the magic bytes,
+ * -1 otherwise.
+ */
+_static_inline_ int udp_check_magic(char *buf, size_t len)
+{
+       if (len < 4)
+               return -1;
+       if (memcmp(buf, "UDPM", 4))
+               return -1;
+       return 1;
+}
+
+/**
+ * Write the type of the audio stream to a buffer.
+ *
+ * \param buf The buffer.
+ * \param type The type to be written.
+ *
+ * \sa \ref udp_stream_type.
+ */
+_static_inline_ void udp_write_stream_type(char *buf, uint8_t type)
+{
+       write_u8(buf + 4, type);
+}
+
+/**
+ * Read the type of the audio stream from a buffer.
+ *
+ * \param buf The buffer.
+ *
+ * \return Either UDP_PLAIN_STREAM or UDP_HEADER_STREAM.
+ * \sa \ref udp_stream_type.
+ */
+_static_inline_ uint8_t udp_read_stream_type(char *buf)
+{
+       return read_u8(buf + 4);
+}
+
+/**
+ * Write the type of this packet to a buffer.
+ *
+ * \param buf The buffer.
+ * \param type The type to be written.
+ *
+ * \sa \ref udp_audio_packet_type.
+ */
+_static_inline_ void udp_write_packet_type(char *buf, uint8_t type)
+{
+       write_u8(buf + 5, type);
+}
+
+/**
+ * Read the type of this buffer.
+ *
+ * \param buf The buffer.
+ *
+ * \return One of the four differnt packet types.
+ * \sa \ref udp_stream_type.
+ */
+_static_inline_ uint8_t udp_read_packet_type(char *buf)
+{
+       return read_u8(buf + 5);
+}
+
+/**
+ * Write the length of the header (non-zero only for ogg streams).
+ *
+ * \param buf The buffer.
+ * \param len The length of the header in bytes.
+ */
+_static_inline_ void udp_write_header_len(char *buf, uint16_t len)
+{
+       write_u16(buf + 6, len);
+}
+
+/**
+ * Read the length of the header.
+ *
+ * \param buf The buffer.
+ * \return The header length in bytes.
+ */
+_static_inline_ uint16_t udp_read_header_len(char *buf)
+{
+       return read_u16(buf + 6);
+}