start on playrtp split
[disorder] / clients / playrtp.h
CommitLineData
8e3fe3d8 1/*
2 * This file is part of DisOrder.
3 * Copyright (C) 2007 Richard Kettlewell
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18 * USA
19 */
20/** @file clients/playrtp.h
21 * @brief RTP player
22 */
23
24#ifndef PLAYRTP_H
25#define PLAYRTP_H
26
27/** @brief Maximum samples per packet we'll support
28 *
29 * NB that two channels = two samples in this program.
30 */
31#define MAXSAMPLES 2048
32
33/** @brief Number of samples to infill by in one go
34 *
35 * This is an upper bound - in practice we expect the underlying audio API to
36 * only ask for a much smaller number of samples in any one go.
37 */
38#define INFILL_SAMPLES (44100 * 2) /* 1s */
39
40/** @brief Received packet
41 *
42 * Received packets are kept in a binary heap (see @ref pheap) ordered by
43 * timestamp.
44 */
45struct packet {
46 /** @brief Next packet in @ref next_free_packet or @ref received_packets */
47 struct packet *next;
48
49 /** @brief Number of samples in this packet */
50 uint32_t nsamples;
51
52 /** @brief Timestamp from RTP packet
53 *
54 * NB that "timestamps" are really sample counters. Use lt() or lt_packet()
55 * to compare timestamps.
56 */
57 uint32_t timestamp;
58
59 /** @brief Flags
60 *
61 * Valid values are:
62 * - @ref IDLE - the idle bit was set in the RTP packet
63 */
64 unsigned flags;
65/** @brief idle bit set in RTP packet*/
66#define IDLE 0x0001
67
68 /** @brief Raw sample data
69 *
70 * Only the first @p nsamples samples are defined; the rest is uninitialized
71 * data.
72 */
73 uint16_t samples_raw[MAXSAMPLES];
74};
75
76/** @brief Structure of free packet list */
77union free_packet {
78 struct packet p;
79 union free_packet *next;
80};
81
82/** @brief Return true iff \f$a < b\f$ in sequence-space arithmetic
83 *
84 * Specifically it returns true if \f$(a-b) mod 2^{32} < 2^{31}\f$.
85 *
86 * See also lt_packet().
87 */
88static inline int lt(uint32_t a, uint32_t b) {
89 return (uint32_t)(a - b) & 0x80000000;
90}
91
92/** @brief Return true iff a >= b in sequence-space arithmetic */
93static inline int ge(uint32_t a, uint32_t b) {
94 return !lt(a, b);
95}
96
97/** @brief Return true iff a > b in sequence-space arithmetic */
98static inline int gt(uint32_t a, uint32_t b) {
99 return lt(b, a);
100}
101
102/** @brief Return true iff a <= b in sequence-space arithmetic */
103static inline int le(uint32_t a, uint32_t b) {
104 return !lt(b, a);
105}
106
107/** @brief Ordering for packets, used by @ref pheap */
108static inline int lt_packet(const struct packet *a, const struct packet *b) {
109 return lt(a->timestamp, b->timestamp);
110}
111
112/** @struct pheap
113 * @brief Binary heap of packets ordered by timestamp */
114HEAP_TYPE(pheap, struct packet *, lt_packet);
115
116struct packet *new_packet(void);
117void free_packet(struct packet *p);
118
119extern const char *device;
120extern struct packet *received_packets;
121extern struct packet **received_tail;
122extern pthread_mutex_t receive_lock;
123extern pthread_cond_t receive_cond;
124extern uint32_t nreceived;
125extern struct pheap packets;
126extern volatile uint32_t nsamples;
127extern uint32_t next_timestamp;
128extern int active;
129extern pthread_mutex_t lock;
130extern pthread_cond_t cond;
131
132
133#endif /* PLAYRTP_H */
134
135/*
136Local Variables:
137c-basic-offset:2
138comment-column:40
139fill-column:79
140indent-tabs-mode:nil
141End:
142*/