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