Merge ../paraslash.fml/paraslash
[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_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 main task of audiod
84 *
85 * \sa struct task, struct sched
86 */
87 struct audiod_task {
88 struct timeval *now;
89 struct task task;
90 };
91
92 /**
93 * the task for obtaining para_server's status (para_client stat)
94 *
95 * \sa struct task, struct sched
96 */
97 struct status_task {
98 /** the associated task structure of audiod */
99 struct task task;
100 /** client data associated with the stat task */
101 struct private_client_data *pcd;
102 /** the array of status items sent by para_server */
103 char *stat_item_values[NUM_STAT_ITEMS];
104 /** do not restart client command until this time */
105 struct timeval restart_barrier;
106 /** last time we received status data from para_server */
107 struct timeval last_status_read;
108 /** the offset value announced by para_server */
109 int offset_seconds;
110 /** the length of the current audio file as announced by para_server */
111 int length_seconds;
112 /** the start of the current stream from the view of para_server */
113 struct timeval server_stream_start;
114 /** the average time deviation between para_server and para_audiod */
115 struct timeval sa_time_diff;
116 /** whether client time is ahead of server time */
117 int sa_time_diff_sign;
118 /** non-zero if para_server's status is "playing" */
119 int playing;
120 /** number of times the clock difference is to be checked */
121 unsigned clock_diff_count;
122 /** when to start the next check for clock difference */
123 struct timeval clock_diff_barrier;
124 };
125
126 extern struct status_task *stat_task;
127 extern struct slot_info slot[MAX_STREAM_SLOTS];
128 extern struct audiod_args_info conf;
129 extern int audiod_status;
130 extern const char *status_item_list[NUM_STAT_ITEMS];
131
132 void __noreturn clean_exit(int status, const char *msg);
133 int handle_connect(int accept_fd);
134 void audiod_status_dump(void);
135 void dump_empty_status(void);
136
137 /** iterate over all slots */
138 #define FOR_EACH_SLOT(_slot) for (_slot = 0; _slot < MAX_STREAM_SLOTS; _slot++)