Skip to content

Commit

Permalink
Add play/pause/stop MPRIS and quieten some debug messages
Browse files Browse the repository at this point in the history
  • Loading branch information
mikebrady committed Feb 21, 2018
1 parent 71a9a0c commit 64d3669
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 21 deletions.
38 changes: 24 additions & 14 deletions metadata_hub.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ void metadata_hub_modify_prolog(void) {
}

void metadata_hub_release_track_artwork(void) {
debug(1,"release track artwork");
// debug(1,"release track artwork");
release_char_string(&metadata_store.cover_art_pathname);
}

void metadata_hub_reset_track_metadata(void) {
debug(1,"release track metadata");
//debug(1,"release track metadata");
release_char_string(&metadata_store.track_name);
release_char_string(&metadata_store.artist_name);
release_char_string(&metadata_store.album_name);
Expand Down Expand Up @@ -259,13 +259,17 @@ void metadata_hub_process_metadata(uint32_t type, uint32_t code, char *data, uin

if (type == 'core') {
switch (code) {
case 'mper':
metadata_store.item_id = ntohl(*(uint32_t*)data);
debug(2, "MH Item ID set to: \"%u\"", metadata_store.item_id);
break;
case 'asal':
if ((metadata_store.album_name == NULL) ||
(strncmp(metadata_store.album_name, data, length) != 0)) {
if (metadata_store.album_name)
free(metadata_store.album_name);
metadata_store.album_name = strndup(data, length);
debug(1, "MH Album name set to: \"%s\"", metadata_store.album_name);
debug(2, "MH Album name set to: \"%s\"", metadata_store.album_name);
metadata_store.album_name_changed = 1;
metadata_store.changed = 1;
}
Expand All @@ -276,7 +280,7 @@ void metadata_hub_process_metadata(uint32_t type, uint32_t code, char *data, uin
if (metadata_store.artist_name)
free(metadata_store.artist_name);
metadata_store.artist_name = strndup(data, length);
debug(1, "MH Artist name set to: \"%s\"", metadata_store.artist_name);
debug(2, "MH Artist name set to: \"%s\"", metadata_store.artist_name);
metadata_store.artist_name_changed = 1;
metadata_store.changed = 1;
}
Expand All @@ -287,7 +291,7 @@ void metadata_hub_process_metadata(uint32_t type, uint32_t code, char *data, uin
if (metadata_store.comment)
free(metadata_store.comment);
metadata_store.comment = strndup(data, length);
debug(1, "MH Comment set to: \"%s\"", metadata_store.comment);
debug(2, "MH Comment set to: \"%s\"", metadata_store.comment);
metadata_store.comment_changed = 1;
metadata_store.changed = 1;
}
Expand All @@ -297,7 +301,7 @@ void metadata_hub_process_metadata(uint32_t type, uint32_t code, char *data, uin
if (metadata_store.genre)
free(metadata_store.genre);
metadata_store.genre = strndup(data, length);
debug(1, "MH Genre set to: \"%s\"", metadata_store.genre);
debug(2, "MH Genre set to: \"%s\"", metadata_store.genre);
metadata_store.genre_changed = 1;
metadata_store.changed = 1;
}
Expand All @@ -308,7 +312,7 @@ void metadata_hub_process_metadata(uint32_t type, uint32_t code, char *data, uin
if (metadata_store.track_name)
free(metadata_store.track_name);
metadata_store.track_name = strndup(data, length);
debug(1, "MH Track name set to: \"%s\"", metadata_store.track_name);
debug(2, "MH Track name set to: \"%s\"", metadata_store.track_name);
metadata_store.track_name_changed = 1;
metadata_store.changed = 1;
}
Expand All @@ -319,7 +323,7 @@ void metadata_hub_process_metadata(uint32_t type, uint32_t code, char *data, uin
if (metadata_store.composer)
free(metadata_store.composer);
metadata_store.composer = strndup(data, length);
debug(1, "MH Composer set to: \"%s\"", metadata_store.composer);
debug(2, "MH Composer set to: \"%s\"", metadata_store.composer);
metadata_store.composer_changed = 1;
metadata_store.changed = 1;
}
Expand All @@ -330,7 +334,7 @@ void metadata_hub_process_metadata(uint32_t type, uint32_t code, char *data, uin
if (metadata_store.file_kind)
free(metadata_store.file_kind);
metadata_store.file_kind = strndup(data, length);
debug(1, "MH File Kind set to: \"%s\"", metadata_store.file_kind);
debug(2, "MH File Kind set to: \"%s\"", metadata_store.file_kind);
metadata_store.file_kind_changed = 1;
metadata_store.changed = 1;
}
Expand All @@ -341,7 +345,7 @@ void metadata_hub_process_metadata(uint32_t type, uint32_t code, char *data, uin
if (metadata_store.file_kind)
free(metadata_store.file_kind);
metadata_store.file_kind = strndup(data, length);
debug(1, "MH File Kind set to: \"%s\"", metadata_store.file_kind);
debug(2, "MH File Kind set to: \"%s\"", metadata_store.file_kind);
metadata_store.file_kind_changed = 1;
metadata_store.changed = 1;
}
Expand All @@ -352,7 +356,7 @@ void metadata_hub_process_metadata(uint32_t type, uint32_t code, char *data, uin
if (metadata_store.sort_as)
free(metadata_store.sort_as);
metadata_store.sort_as = strndup(data, length);
debug(1, "MH Sort As set to: \"%s\"", metadata_store.sort_as);
debug(2, "MH Sort As set to: \"%s\"", metadata_store.sort_as);
metadata_store.sort_as_changed = 1;
metadata_store.changed = 1;
}
Expand Down Expand Up @@ -387,19 +391,19 @@ void metadata_hub_process_metadata(uint32_t type, uint32_t code, char *data, uin
break;

case 'mdst':
debug(1, "MH Metadata stream processing start.");
debug(2, "MH Metadata stream processing start.");
metadata_hub_modify_prolog();
metadata_hub_reset_track_metadata();
metadata_hub_release_track_artwork();
break;
case 'mden':
metadata_hub_modify_epilog(1);
debug(1, "MH Metadata stream processing end.");
debug(2, "MH Metadata stream processing end.");
break;
case 'PICT':
if (length > 16) {
metadata_hub_modify_prolog();
debug(1, "MH Picture received, length %u bytes.", length);
debug(2, "MH Picture received, length %u bytes.", length);
if (metadata_store.cover_art_pathname)
free(metadata_store.cover_art_pathname);
metadata_store.cover_art_pathname = metadata_write_image_file(data, length);
Expand Down Expand Up @@ -430,6 +434,12 @@ void metadata_hub_process_metadata(uint32_t type, uint32_t code, char *data, uin
metadata_hub_modify_epilog(1);
}
break;
case 'pbeg':
case 'pend':
case 'pfls':
case 'prsm':
break;

default: {
char typestring[5];
*(uint32_t *)typestring = htonl(type);
Expand Down
4 changes: 2 additions & 2 deletions metadata_hub.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
#define number_of_watchers 2

enum play_status_type {
PS_PLAYING = 0,
PS_STOPPED = 0,
PS_PAUSED,
PS_STOPPED,
PS_PLAYING,
} play_status_type;

enum shuffle_status_type {
Expand Down
35 changes: 30 additions & 5 deletions mpris-service.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
void mpris_metadata_watcher(struct metadata_bundle *argc, void *userdata) {
// debug(1, "MPRIS metadata watcher called");
char response[100];

switch (argc->repeat_status) {
case RS_NONE:
strcpy(response, "None");
Expand All @@ -31,6 +32,21 @@ void mpris_metadata_watcher(struct metadata_bundle *argc, void *userdata) {

// debug(1,"Set loop status to \"%s\"",response);
media_player2_player_set_loop_status(mprisPlayerPlayerSkeleton, response);

switch (argc->player_state) {
case PS_STOPPED:
strcpy(response, "Stopped");
break;
case PS_PAUSED:
strcpy(response, "Paused");
break;
case PS_PLAYING:
strcpy(response, "Playing");
break;
}

// debug(1,"From player_state, set playback status to \"%s\"",response);
media_player2_player_set_playback_status(mprisPlayerPlayerSkeleton, response);

GVariantBuilder *dict_builder, *aa;

Expand Down Expand Up @@ -63,30 +79,39 @@ void mpris_metadata_watcher(struct metadata_bundle *argc, void *userdata) {
}
*pt = 0;
if (non_zero) {
// debug(1, "Item composite ID set to 0x%s.", st);
//debug(1, "Set ID using composite ID: \"0x%s\".", st);
char trackidstring[1024];
sprintf(trackidstring, "/org/gnome/ShairportSync/%s", st);
GVariant* trackid = g_variant_new("o", trackidstring);
g_variant_builder_add(dict_builder, "{sv}", "mpris:trackid", trackid);
} else if (argc->item_id) {
char trackidstring[128];
//debug(1, "Set ID using mper ID: \"%u\".",argc->item_id);
sprintf(trackidstring, "/org/gnome/ShairportSync/mper_%u", argc->item_id);
GVariant* trackid = g_variant_new("o", trackidstring);
g_variant_builder_add(dict_builder, "{sv}", "mpris:trackid", trackid);
}

// Add the track length if it's non-zero
if (argc->songtime_in_milliseconds) {
uint64_t track_length_in_microseconds = argc->songtime_in_milliseconds;
track_length_in_microseconds *= 1000; // to microseconds in 64-bit precision
uint64_t track_length_in_microseconds = argc->songtime_in_milliseconds;
track_length_in_microseconds *= 1000; // to microseconds in 64-bit precision
// Make up the track name and album name
GVariant *tracklength = g_variant_new("x", track_length_in_microseconds);
g_variant_builder_add(dict_builder, "{sv}", "mpris:length", tracklength);
//debug(1, "Set tracklength to %lu.", track_length_in_microseconds);
GVariant *tracklength = g_variant_new("x", track_length_in_microseconds);
g_variant_builder_add(dict_builder, "{sv}", "mpris:length", tracklength);
}

// Add the track name if there is one
if (argc->track_name) {
// debug(1, "Track name set to \"%s\".", argc->track_name);
GVariant *trackname = g_variant_new("s", argc->track_name);
g_variant_builder_add(dict_builder, "{sv}", "xesam:title", trackname);
}

// Add the album name if there is one
if (argc->album_name) {
// debug(1, "Album name set to \"%s\".", argc->album_name);
GVariant *albumname = g_variant_new("s", argc->album_name);
g_variant_builder_add(dict_builder, "{sv}", "xesam:album", albumname);
}
Expand Down
6 changes: 6 additions & 0 deletions player.c
Original file line number Diff line number Diff line change
Expand Up @@ -1057,6 +1057,12 @@ static abuf_t *buffer_get_frame(rtsp_conn_info *conn) {
send_ssnc_metadata('prsm', NULL, 0,
0); // "resume", but don't wait if the queue is locked
#endif
#ifdef HAVE_METADATA_HUB
metadata_hub_modify_prolog();
metadata_store.player_state = PS_PLAYING;
metadata_hub_modify_epilog(1);
#endif

}
}
}
Expand Down

0 comments on commit 64d3669

Please sign in to comment.