improve and clean up audiod_status_dump()
[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 enum {
5         AUDIO_FORMAT_MP3,
6         AUDIO_FORMAT_OGG,
7         AUDIO_FORMAT_AAC,
8         NUM_AUDIO_FORMATS
9 };
10 extern const char *audio_formats[];
11 #define DEFINE_AUDIO_FORMAT_ARRAY const char *audio_formats[] = {"mp3", "ogg", "aac", NULL}
12 #define MAX_STREAM_SLOTS 5
13 /**
14  * the possible modes of operation
15  *
16  * - off: disconnect from para_server
17  * - on: receive status information from para_server and play the audio stream
18  * - sb: only receive status information but not the audio stream
19 */
20 enum {AUDIOD_OFF, AUDIOD_ON, AUDIOD_STANDBY};
21
22 /**
23  * describes one instance of a receiver-filter-writer chain
24  *
25  * \sa receier_node, receiver, filter, filter_node, filter_chain, writer,
26  * writer_node, writer_node_group.
27   */
28 struct slot_info {
29         /** number of the audio format in this slot */
30         int format;
31         /** writer start time */
32         struct timeval wstime;
33         /** the receiver info associated with this slot */
34         struct receiver_node *receiver_node;
35         /** the active filter chain */
36         struct filter_chain *fc;
37         /** the active writer node group */
38         struct writer_node_group *wng;
39 };
40
41 /**
42  * the main task of audiod
43  *
44  * \sa struct task, struct sched
45  */
46 struct audiod_task {
47         struct timeval *now;
48         struct task task;
49 };
50
51 /**
52  * the task for audiod's child (para_client stat)
53  *
54  * \sa struct task, struct sched
55  */
56 struct status_task {
57         /** the associated task structure of audiod */
58         struct task task;
59         struct private_client_data *pcd;
60         /** the array of status items sent by para_server */
61         char *stat_item_values[NUM_STAT_ITEMS];
62         /** do not restart client command until this time */
63         struct timeval restart_barrier;
64         /** the offset value announced by para_server */
65         int offset_seconds;
66         /** the length of the current audio file as announced by para_server */
67         int length_seconds;
68         /** the start of the current stream from the view of para_server */
69         struct timeval server_stream_start;
70         /** the averaged time deviation between para_server and para_audiod */
71         struct timeval sa_time_diff;
72         /** whether client time is ahead of server time */
73         int sa_time_diff_sign;
74         /** the audio format announced in server status */
75         char *af_status;
76         /** non-zero if \a af_status is "playing" */
77         int playing;
78 };
79
80 extern struct status_task *stat_task;
81 extern struct slot_info slot[MAX_STREAM_SLOTS];
82 extern struct audiod_args_info conf;
83 extern int audiod_status;
84 extern const char *status_item_list[NUM_STAT_ITEMS];
85
86 void __noreturn clean_exit(int status, const char *msg);
87 int handle_connect(int accept_fd);
88 void audiod_status_dump(void);
89 void dump_empty_status(void);
90
91 /** iterate over all slots */
92 #define FOR_EACH_SLOT(_slot) for (_slot = 0; _slot < MAX_STREAM_SLOTS; _slot++)