introduce INIT_STDERR_LOCKING macro
[paraslash.git] / audiod.h
1 /** \file audiod.h symbols exported from audiod.c */
2 int num_filters(int audio_format_num);
3 int get_audio_format_num(char *name);
4
5 /** enum of audio formats supported by para_audiod */
6 enum {AUDIOD_AUDIO_FORMATS_ENUM};
7
8 /** array of audio format names supported by para_audiod */
9 extern const char *audio_formats[];
10
11 /** maximal number of simultaneous instances */
12 #define MAX_STREAM_SLOTS 5
13
14 /**
15  * the possible modes of operation
16  *
17  * - off: disconnect from para_server
18  * - on: receive status information from para_server and play the audio stream
19  * - sb: only receive status information but not the audio stream
20 */
21 enum {AUDIOD_OFF, AUDIOD_ON, AUDIOD_STANDBY};
22
23 /**
24  * describes one instance of a receiver-filter-writer chain
25  *
26  * \sa receier_node, receiver, filter, filter_node, filter_chain, writer,
27  * writer_node, writer_node_group.
28   */
29 struct slot_info {
30         /** number of the audio format in this slot */
31         int format;
32         /** writer start time */
33         struct timeval wstime;
34         /** the receiver info associated with this slot */
35         struct receiver_node *receiver_node;
36         /** the active filter chain */
37         struct filter_chain *fc;
38         /** the active writer node group */
39         struct writer_node_group *wng;
40 };
41
42 /**
43  * the main task of audiod
44  *
45  * \sa struct task, struct sched
46  */
47 struct audiod_task {
48         struct timeval *now;
49         struct task task;
50 };
51
52 /**
53  * the task for obtaining para_server's status (para_client stat)
54  *
55  * \sa struct task, struct sched
56  */
57 struct status_task {
58         /** the associated task structure of audiod */
59         struct task task;
60         /** client data associated with the stat task */
61         struct private_client_data *pcd;
62         /** the array of status items sent by para_server */
63         char *stat_item_values[NUM_STAT_ITEMS];
64         /** do not restart client command until this time */
65         struct timeval restart_barrier;
66         /** last time we received status data from para_server */
67         struct timeval last_status_read;
68         /** the offset value announced by para_server */
69         int offset_seconds;
70         /** the length of the current audio file as announced by para_server */
71         int length_seconds;
72         /** the start of the current stream from the view of para_server */
73         struct timeval server_stream_start;
74         /** the average time deviation between para_server and para_audiod */
75         struct timeval sa_time_diff;
76         /** whether client time is ahead of server time */
77         int sa_time_diff_sign;
78         /** non-zero if para_server's status is "playing" */
79         int playing;
80         /** number of times the clock difference is to be checked */
81         unsigned clock_diff_count;
82         /** when to start the next check for clock difference */
83         struct timeval clock_diff_barrier;
84 };
85
86 extern struct status_task *stat_task;
87 extern struct slot_info slot[MAX_STREAM_SLOTS];
88 extern struct audiod_args_info conf;
89 extern int audiod_status;
90 extern const char *status_item_list[NUM_STAT_ITEMS];
91
92 void __noreturn clean_exit(int status, const char *msg);
93 int handle_connect(int accept_fd);
94 void audiod_status_dump(void);
95 void dump_empty_status(void);
96
97 /** iterate over all slots */
98 #define FOR_EACH_SLOT(_slot) for (_slot = 0; _slot < MAX_STREAM_SLOTS; _slot++)