]> git.ipfire.org Git - thirdparty/shairport-sync.git/blob - metadata_hub.h
Update check_classic_systemd_full.yml
[thirdparty/shairport-sync.git] / metadata_hub.h
1 #pragma once
2 #include "common.h"
3 #include "config.h"
4 #include <pthread.h>
5
6 #define number_of_watchers 2
7
8 typedef enum {
9 PS_NOT_AVAILABLE = 0,
10 PS_STOPPED,
11 PS_PAUSED,
12 PS_PLAYING,
13 } play_status_type;
14
15 typedef enum {
16 AM_INACTIVE = 0,
17 AM_ACTIVE,
18 } active_state_type;
19
20 typedef enum {
21 SS_NOT_AVAILABLE = 0,
22 SS_OFF,
23 SS_ON,
24 } shuffle_status_type;
25
26 typedef enum {
27 RS_NOT_AVAILABLE = 0,
28 RS_OFF,
29 RS_ONE,
30 RS_ALL,
31 } repeat_status_type;
32
33 int string_update(char **str, int *changed, char *s);
34 int int_update(int *receptacle, int *changed, int value);
35
36 struct metadata_bundle;
37
38 typedef void (*metadata_watcher)(struct metadata_bundle *argc, void *userdata);
39
40 typedef struct metadata_bundle {
41
42 char *client_ip; // IP number used by the audio source (i.e. the "client"), which is also the DACP
43 // server
44 int client_ip_changed;
45
46 char *client_name; // the name of the client device, if available
47 int client_name_changed;
48
49 char *server_ip; // IP number used by Shairport Sync
50 int server_ip_changed;
51
52 char *stream_type; // Realtime or Buffered
53 int stream_type_changed;
54
55 char *progress_string; // progress string, emitted by the source from time to time
56 int progress_string_changed;
57
58 char *frame_position_string; // frame position string emitted by SPS on request
59 int frame_position_string_changed;
60
61 char *first_frame_position_string; // first frame position string emitted by SPS on request
62 int first_frame_position_string_changed;
63
64 int player_thread_active; // true if a play thread is running
65 int dacp_server_active; // true if there's a reachable DACP server (assumed to be the Airplay
66 // client) ; false otherwise
67 int advanced_dacp_server_active; // true if there's a reachable DACP server with iTunes
68 // capabilitiues
69 // ; false otherwise
70 int dacp_server_has_been_active; // basically this is a delayed version of dacp_server_active,
71 // used detect transitions between server activity being on or off
72 // e.g. to reease metadata when a server goes inactive, but not if it's permanently
73 // inactive.
74 play_status_type play_status;
75 shuffle_status_type shuffle_status;
76 repeat_status_type repeat_status;
77
78 // the following pertain to the track playing
79
80 char *cover_art_pathname;
81 int cover_art_pathname_changed;
82
83 uint64_t item_id; // seems to be a track ID -- see itemid in DACP.c
84 int item_id_changed;
85 int item_id_is_valid;
86
87 unsigned char
88 item_composite_id[16]; // seems to be nowplaying 4 ids: dbid, plid, playlistItem, itemid
89 int item_composite_id_changed;
90 int item_composite_id_is_valid;
91
92 int song_data_kind;
93 int song_data_kind_changed;
94 int song_data_kind_is_valid;
95
96 char *track_name;
97 int track_name_changed;
98
99 char *artist_name;
100 int artist_name_changed;
101
102 char *album_artist_name;
103 int album_artist_name_changed;
104
105 char *album_name;
106 int album_name_changed;
107
108 char *genre;
109 int genre_changed;
110
111 char *comment;
112 int comment_changed;
113
114 char *composer;
115 int composer_changed;
116
117 char *file_kind;
118 int file_kind_changed;
119
120 char *song_description;
121 int song_description_changed;
122
123 char *song_album_artist;
124 int song_album_artist_changed;
125
126 char *sort_name;
127 int sort_name_changed;
128
129 char *sort_artist;
130 int sort_artist_changed;
131
132 char *sort_album;
133 int sort_album_changed;
134
135 char *sort_composer;
136 int sort_composer_changed;
137
138 uint32_t songtime_in_milliseconds;
139 int songtime_in_milliseconds_changed;
140 int songtime_in_milliseconds_is_valid;
141
142 // end
143
144 play_status_type
145 player_state; // this is the state of the actual player itself, which can be a bit noisy.
146 active_state_type active_state;
147
148 int speaker_volume; // this is the actual speaker volume, allowing for the main volume and the
149 // speaker volume control
150 double airplay_volume;
151
152 metadata_watcher watchers[number_of_watchers]; // functions to call if the metadata is changed.
153 void *watchers_data[number_of_watchers]; // their individual data
154
155 } metadata_bundle;
156
157 extern struct metadata_bundle metadata_store;
158
159 void add_metadata_watcher(metadata_watcher fn, void *userdata);
160
161 void metadata_hub_init(void);
162 void metadata_hub_stop(void);
163 void metadata_hub_process_metadata(uint32_t type, uint32_t code, char *data, uint32_t length);
164 void metadata_hub_reset_track_metadata(void);
165 void metadata_hub_release_track_artwork(void);
166
167 // these functions lock and unlock the read-write mutex on the metadata hub and run the watchers
168 // afterwards
169 void _metadata_hub_modify_prolog(const char *filename, const int linenumber);
170 void _metadata_hub_modify_epilog(
171 int modified, const char *filename,
172 const int linenumber); // set to true if modifications occurred, 0 otherwise
173
174 /*
175 // these are for safe reading
176 void _metadata_hub_read_prolog(const char *filename, const int linenumber);
177 void _metadata_hub_read_epilog(const char *filename, const int linenumber);
178 */
179
180 #define metadata_hub_modify_prolog(void) _metadata_hub_modify_prolog(__FILE__, __LINE__)
181 #define metadata_hub_modify_epilog(modified) \
182 _metadata_hub_modify_epilog(modified, __FILE__, __LINE__)
183
184 #define metadata_hub_read_prolog(void) _metadata_hub_read_prolog(__FILE__, __LINE__)
185 #define metadata_hub_read_epilog(void) _metadata_hub_modify_epilog(__FILE__, __LINE__)