Merge /home/maan/scm/paraslash_fml/paraslash into mmap
[paraslash.git] / audiod.h
1 /*
2  * Copyright (C) 2006-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 audiod.h symbols exported from audiod.c */
20
21
22 int num_filters(int audio_format_num);
23 int get_audio_format_num(char *name);
24
25 /** enum of audio formats supported by para_audiod */
26 enum {AUDIOD_AUDIO_FORMATS_ENUM};
27
28 /** array of audio format names supported by para_audiod */
29 extern const char *audio_formats[];
30
31 /** maximal number of simultaneous instances */
32 #define MAX_STREAM_SLOTS 5
33
34 /**
35  * the possible modes of operation
36  *
37  * - off: disconnect from para_server
38  * - on: receive status information from para_server and play the audio stream
39  * - sb: only receive status information but not the audio stream
40  */
41 enum audiod_status_info {AUDIOD_OFF, AUDIOD_ON, AUDIOD_STANDBY};
42
43 /** defines one command of para_audiod */
44 struct audiod_command {
45         /** the name of the command */
46         const char *name;
47         /** pointer to the function that handles the command */
48         int (*handler)(int, int, char**);
49         /**
50          * if the command prefers to handle the full line (rather than the usual
51          * argv[] array), it stores a pointer to the corresponding line handling
52          * function here. In this case, the above \a handler pointer must be NULL.
53          */
54         int (*line_handler)(int, char*);
55         /** one-line description of the command */
56         const char *description;
57         /** summary of the command line options */
58         const char *usage;
59         /** the long help text */
60         const char *help;
61 };
62
63 /**
64  * describes one instance of a receiver-filter-writer chain
65  *
66  * \sa receier_node, receiver, filter, filter_node, filter_chain, writer,
67  * writer_node, writer_node_group.
68  */
69 struct slot_info {
70         /** number of the audio format in this slot */
71         int format;
72         /** writer start time */
73         struct timeval wstime;
74         /** the receiver info associated with this slot */
75         struct receiver_node *receiver_node;
76         /** the active filter chain */
77         struct filter_chain *fc;
78         /** the active writer node group */
79         struct writer_node_group *wng;
80 };
81
82 /**
83  * the task for obtaining para_server's status (para_client stat)
84  *
85  * \sa struct task, struct sched
86  */
87 struct status_task {
88         /** the associated task structure of audiod */
89         struct task task;
90         /** client data associated with the stat task */
91         struct private_client_data *pcd;
92         /** the array of status items sent by para_server */
93         char *stat_item_values[NUM_STAT_ITEMS];
94         /** do not restart client command until this time */
95         struct timeval restart_barrier;
96         /** last time we received status data from para_server */
97         struct timeval last_status_read;
98         /** the offset value announced by para_server */
99         int offset_seconds;
100         /** the length of the current audio file as announced by para_server */
101         int length_seconds;
102         /** the start of the current stream from the view of para_server */
103         struct timeval server_stream_start;
104         /** the average time deviation between para_server and para_audiod */
105         struct timeval sa_time_diff;
106         /** whether client time is ahead of server time */
107         int sa_time_diff_sign;
108         /** non-zero if para_server's status is "playing" */
109         int playing;
110         /** number of times the clock difference is to be checked */
111         unsigned clock_diff_count;
112         /** when to start the next check for clock difference */
113         struct timeval clock_diff_barrier;
114 };
115
116 extern struct status_task *stat_task;
117 extern struct slot_info slot[MAX_STREAM_SLOTS];
118 extern struct audiod_args_info conf;
119 extern int audiod_status;
120 extern const char *status_item_list[NUM_STAT_ITEMS];
121
122 void __noreturn clean_exit(int status, const char *msg);
123 int handle_connect(int accept_fd);
124 void audiod_status_dump(void);
125 void dump_empty_status(void);
126
127 /** iterate over all slots */
128 #define FOR_EACH_SLOT(_slot) for (_slot = 0; _slot < MAX_STREAM_SLOTS; _slot++)