ogg_afh.c: make vi_sampling_rate, vi_bitrate local
[paraslash.git] / recv.h
1 /*
2  * Copyright (C) 2005-2007 Andre Noll <maan@systemlinux.org>
3  *
4  *     This program is free software; you can redistribute it and/or modify
5  *     it under the terms of the GNU General Public License as published by
6  *     the Free Software Foundation; either version 2 of the License, or
7  *     (at your option) any later version.
8  *
9  *     This program is distributed in the hope that it will be useful,
10  *     but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *     GNU General Public License for more details.
13  *
14  *     You should have received a copy of the GNU General Public License
15  *     along with this program; if not, write to the Free Software
16  *     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
17  */
18
19 /** \file recv.h receiver-related structures and exported symbols of recv_common.c */
20
21 /**
22  * describes one instance of a receiver
23  */
24 struct receiver_node {
25         /** points to the corresponding receiver */
26         struct receiver *receiver;
27         /** the output buffer */
28         char *buf;
29         /** the amount of bytes in \a buf */
30         size_t loaded;
31         /** receiver-specific data */
32         void *private_data;
33         /** set to 1 if end of file is reached */
34         int eof;
35         /** pointer to the eof member of the consumer */
36         int *output_eof;
37         /** pointer to the configuration data for this instance */
38         void *conf;
39         /** the task associated with this instance */
40         struct task task;
41 };
42
43 /**
44  * describes one supported paraslash receiver
45  *
46  * \sa http_recv.c, ortp_recv.c
47  */
48 struct receiver {
49 /**
50  * the name of the receiver
51  */
52         const char *name;
53 /**
54  * the receiver init function
55  *
56  * It must fill in all other function pointers and is assumed to succeed.
57  *
58  * \sa http_recv_init ortp_recv_init
59  */
60         void (*init)(struct receiver *r);
61 /**
62  * the command line parser of the receiver
63  *
64  * It should check whether the command line options given by \a argc and \a
65  * argv are valid.  On success, it should return a pointer to the
66  * receiver-specific configuration data determined by \a argc and \a argv.
67  * Note that this might be called more than once with different values of
68  * \a argc and \a argv.
69  */
70         void * (*parse_config)(int argc, char **argv);
71 /**
72  * open one instance of the receiver
73  *
74  * This should allocate the output buffer of \a rn. and may also perform any
75  * other work necessary for retrieving the stream according to the
76  * configuration stored in the \a conf member of \a rn which is guaranteed to
77  * point to valid configuration data (as previously obtained from the config
78  * parser).
79  *
80  * \sa receiver_node::conf, receiver_node::buf
81  */
82         int (*open)(struct receiver_node *rn);
83 /**
84  * close this instance of the receiver
85  *
86  * It should free all resources associated with given receiver node that were
87  * allocated during the corresponding open call.
88  *
89  * \sa receiver_node
90  */
91         void (*close)(struct receiver_node *rn);
92 /**
93  * deactivate the receiver
94  *
95  * Clean up what init has allocated.
96  */
97         void (*shutdown)(void);
98 /**
99  * add file descriptors to fd_sets and compute timeout for select(2)
100  *
101  * The pre_select function gets called from the driving application before
102  * entering its select loop. The receiver may use this hook to add any file
103  * descriptors to the sets of file descriptors given by \a s.
104  *
105  * \sa select(2), time.c struct task, struct sched
106  */
107         void (*pre_select)(struct sched *s, struct task *t);
108 /**
109  * evaluate the result from select()
110  *
111  * This hook gets called after the call to select(). It should check all file
112  * descriptors which were added to any of the the fd sets during the previous
113  * call to pre_select. According to the result, it may then use any
114  * non-blocking I/O to establish a connection or to receive the audio data.
115  *
116  * \sa select(2), struct receiver
117  */
118         void (*post_select)(struct sched *s, struct task *t);
119 };
120
121
122 /** \cond */
123 extern void http_recv_init(struct receiver *r);
124 #define HTTP_RECEIVER {.name = "http", .init = http_recv_init},
125 extern void dccp_recv_init(struct receiver *r);
126 #define DCCP_RECEIVER {.name = "dccp", .init = dccp_recv_init},
127
128 #ifdef HAVE_ORTP
129 extern void ortp_recv_init(struct receiver *r);
130 #define ORTP_RECEIVER {.name = "ortp", .init = ortp_recv_init},
131 #else
132 #define ORTP_RECEIVER
133 #endif
134
135 extern struct receiver receivers[];
136 /** \endcond */
137
138 /** define an array of all available receivers */
139 #define DEFINE_RECEIVER_ARRAY struct receiver receivers[] = { \
140         HTTP_RECEIVER \
141         DCCP_RECEIVER \
142         ORTP_RECEIVER \
143         {.name = NULL}};
144
145 void *check_receiver_arg(char *ra, int *receiver_num);