+++ /dev/null
-/*
- * 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. */
-#include <net/if.h>
-
-/**
- * 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 16
-
-/** The possible stream types. */
-enum udp_stream_type {
- /** Used for mp3 and aac streams. */
- UDP_PLAIN_STREAM,
- /** Ogg vorbis streams. */
- UDP_HEADER_STREAM,
- /** stream type not yet known. */
- UDP_UNKNOWN_STREAM
-};
-
-/** The possible packet types. */
-enum udp_audio_packet_type {
- /** Beginning of file. */
- UDP_BOF_PACKET,
- /** End of file. */
- UDP_EOF_PACKET,
- /** Combined header/data packet (ogg only). */
- UDP_HEADER_PACKET,
- /** Packet contains only audio file data. */
- UDP_DATA_PACKET,
- /** Invalid packet type. */
- UDP_UNKNOWN_PACKET
-};
-
-/** The contents of an udp audio header. */
-struct udp_audio_header {
- /** see \ref udp_stream_type. */
- uint8_t stream_type;
- /** see \ref udp_audio_packet_type. */
- uint8_t packet_type;
- /** Non-zero only for header packets. */
- uint16_t header_len;
- /** Length of header plus audio file data. */
- uint16_t payload_len;
-};
-
-/**
- * Write a struct udp_audio_header to a buffer.
- *
- * \param buf The buffer to write to.
- * \param h The audio header to write.
- *
- * Used by the udp sender.
- *
- */
-_static_inline_ void write_udp_audio_header(char *buf, struct udp_audio_header *h)
-{
- memcpy(buf, "UDPM", 4);
- write_u8(buf + 4, h->stream_type);
- write_u8(buf + 5, h->packet_type);
- write_u16(buf + 6, h->header_len);
- write_u16(buf + 8, h->payload_len);
- memset(buf + 10, 0, 6);
-}
-
-/**
- * Used by the udp receiver to read a struct udp_audio_header from a buffer.
- *
- * \param buf The buffer to read from.
- * \param len The length of \a buf.
- * \param h Result pointer.
- *
- * \return 1 if \a buf contains a valid udp audio header, -1 else.
- */
-_static_inline_ int read_udp_audio_header(char *buf, size_t len,
- struct udp_audio_header *h)
-{
- if (len < 4)
- goto err;
- if (memcmp(buf, "UDPM", 4))
- goto err;
- h->stream_type = read_u8(buf + 4);
- h->packet_type = read_u8(buf + 5);
- h->header_len = read_u16(buf + 6);
- h->payload_len = read_u16(buf + 8);
- return 1;
-err:
- h->stream_type = UDP_UNKNOWN_STREAM;
- h->packet_type = UDP_UNKNOWN_PACKET;
- h->header_len = h->payload_len = 0;
- return -1;
-}