From 4e3bdbb0bc8649208400b9eb63751db15bc9bcda Mon Sep 17 00:00:00 2001 From: waker Date: Thu, 14 Apr 2011 20:50:40 +0200 Subject: new event passing system --- deadbeef.h | 95 +++++++++++++++++++---------------- main.c | 18 ++++++- messagepump.c | 72 ++++++++++++++++++++++++++- messagepump.h | 5 ++ playlist.c | 23 ++++----- plugins.c | 112 +++++++++++++---------------------------- plugins.h | 2 +- plugins/alsa/alsa.c | 15 ++++-- plugins/artwork/artwork.c | 16 ++++-- plugins/ffmpeg/ffmpeg.c | 11 ++-- plugins/gtkui/ddblistview.c | 9 ---- plugins/gtkui/gtkui.c | 119 +++++++++++++++++--------------------------- plugins/lastfm/lastfm.c | 25 +++++++--- plugins/notify/notify.c | 15 ++++-- plugins/oss/oss.c | 15 ++++-- plugins/sid/csid.cpp | 14 ++++-- plugins/sid/csid.h | 1 + plugins/sid/plugin.c | 1 + plugins/sndfile/sndfile.c | 12 +++-- streamer.c | 13 ++--- 20 files changed, 334 insertions(+), 259 deletions(-) diff --git a/deadbeef.h b/deadbeef.h index 3b5e04ac..774c2fc7 100644 --- a/deadbeef.h +++ b/deadbeef.h @@ -188,27 +188,27 @@ enum playback_mode_t { typedef struct { int event; - time_t time; -} DB_event_t; + int size; +} ddb_event_t; typedef struct { - DB_event_t ev; + ddb_event_t ev; DB_playItem_t *track; -} DB_event_track_t; +} ddb_event_track_t; typedef struct { - DB_event_t ev; + ddb_event_t ev; DB_playItem_t *from; DB_playItem_t *to; -} DB_event_trackchange_t; +} ddb_event_trackchange_t; typedef struct { - DB_event_t ev; + ddb_event_t ev; int state; -} DB_event_state_t; +} ddb_event_state_t; typedef struct { - DB_event_t ev; + ddb_event_t ev; DB_playItem_t *track; float playpos; } ddb_event_playpos_t; @@ -220,22 +220,40 @@ typedef struct DB_conf_item_s { } DB_conf_item_t; // event callback type -typedef int (*DB_callback_t)(DB_event_t *, uintptr_t data); +typedef int (*DB_callback_t)(ddb_event_t *, uintptr_t data); + +// message ids for communicating with player +enum { + M_SONGFINISHED, + M_NEXT, + M_PREV, + M_PLAY_CURRENT, + M_PLAY_NUM, + M_STOP, + M_PAUSE, + M_PLAY_RANDOM, + M_TERMINATE, // must be sent to player thread to terminate + M_PLAYLIST_REFRESH, // means + M_REINIT_SOUND, + M_CONFIG_CHANGED, // no arguments + M_TOGGLE_PAUSE, +}; // events enum { - DB_EV_SONGCHANGED = 1, // triggers when current song changed from one to another, see DB_event_trackchange_t, both pointers can be NULL - DB_EV_SONGSTARTED = 2, // triggers when song started playing (for scrobblers and such) - DB_EV_SONGFINISHED = 3, // triggers when song finished playing (for scrobblers and such) - DB_EV_CONFIGCHANGED = 5, // configuration option changed - DB_EV_ACTIVATE = 6, // will be fired every time player is activated - DB_EV_TRACKINFOCHANGED = 7, // notify plugins that trackinfo was changed - DB_EV_PAUSED = 8, // player was paused or unpaused - DB_EV_PLAYLISTCHANGED = 9, // playlist contents were changed - DB_EV_VOLUMECHANGED = 10, // volume was changed - DB_EV_OUTPUTCHANGED = 11, // sound output plugin changed - DB_EV_PLAYLISTSWITCH = 13, // playlist switch occured - DB_EV_SEEKED = 14, // seek happened, see ddb_event_playpos_t + DB_EV_FIRST = 1000, + DB_EV_SONGCHANGED = 1000, // triggers when current song changed from one to another, see ddb_event_trackchange_t, both pointers can be NULL + DB_EV_SONGSTARTED = 1001, // triggers when song started playing (for scrobblers and such) + DB_EV_SONGFINISHED = 1002, // triggers when song finished playing (for scrobblers and such) + DB_EV_CONFIGCHANGED = 1003, // configuration option changed + DB_EV_ACTIVATE = 1004, // will be fired every time player is activated + DB_EV_TRACKINFOCHANGED = 1005, // notify plugins that trackinfo was changed + DB_EV_PAUSED = 1006, // player was paused or unpaused + DB_EV_PLAYLISTCHANGED = 1007, // playlist contents were changed + DB_EV_VOLUMECHANGED = 1008, // volume was changed + DB_EV_OUTPUTCHANGED = 1009, // sound output plugin changed + DB_EV_PLAYLISTSWITCH = 1010, // playlist switch occured + DB_EV_SEEKED = 1011, // seek happened, see ddb_event_playpos_t DB_EV_MAX }; @@ -256,27 +274,10 @@ enum { DDB_REPLAYGAIN_TRACKPEAK, }; -// message ids for communicating with player -enum { - M_SONGFINISHED, - M_NEXT, - M_PREV, - M_PLAY_CURRENT, - M_PLAY_NUM, - M_STOP, - M_PAUSE, - M_PLAY_RANDOM, - M_TERMINATE, // must be sent to player thread to terminate - M_PLAYLIST_REFRESH, // means - M_REINIT_SOUND, - M_CONFIG_CHANGED, // no arguments - M_TOGGLE_PAUSE, -}; - // typecasting macros #define DB_PLUGIN(x) ((DB_plugin_t *)(x)) #define DB_CALLBACK(x) ((DB_callback_t)(x)) -#define DB_EVENT(x) ((DB_event_t *)(x)) +#define DB_EVENT(x) ((ddb_event_t *)(x)) #define DB_PLAYITEM(x) ((DB_playItem_t *)(x)) // FILE object wrapper for vfs access @@ -307,10 +308,6 @@ typedef struct { int vmajor; int vminor; - // event subscribing - void (*ev_subscribe) (struct DB_plugin_s *plugin, int ev, DB_callback_t callback, uintptr_t data); - void (*ev_unsubscribe) (struct DB_plugin_s *plugin, int ev, DB_callback_t callback, uintptr_t data); - // md5sum calc void (*md5) (uint8_t sig[16], const char *in, int len); void (*md5_to_str) (char *str, const uint8_t sig[16]); @@ -573,6 +570,11 @@ typedef struct { // message passing int (*sendmessage) (uint32_t id, uintptr_t ctx, uint32_t p1, uint32_t p2); + // convenience functions to send events, uses sendmessage internally + ddb_event_t *(*event_alloc) (uint32_t id); + void (*event_free) (ddb_event_t *ev); + int (*event_send) (ddb_event_t *ev, uint32_t p1, uint32_t p2); + // configuration access // // conf_get_str_fast is not thread-safe, and @@ -714,6 +716,11 @@ typedef struct DB_plugin_s { // @returns linked list of actions DB_plugin_action_t* (*get_actions) (DB_playItem_t *it); + // mainloop will call this function for every plugin + // so that plugins may handle all events; + // can be NULL + int (*message) (uint32_t id, uintptr_t ctx, uint32_t p1, uint32_t p2); + // plugin configuration dialog is constructed from this data // can be NULL const char *configdialog; diff --git a/main.c b/main.c index 1668eaee..c0ae2efd 100644 --- a/main.c +++ b/main.c @@ -238,7 +238,6 @@ server_exec_command_line (const char *cmdline, int len, char *sendback, int sbsi pl_reset_cursor (); } if (parg < pend) { - printf ("query to add files\n"); deadbeef->pl_add_files_begin (curr_plt); while (parg < pend) { char resolved[PATH_MAX]; @@ -393,7 +392,15 @@ player_mainloop (void) { uint32_t p1; uint32_t p2; messagepump_wait (); + int term = 0; while (messagepump_pop(&msg, &ctx, &p1, &p2) != -1) { + // broadcast to all plugins + DB_plugin_t **plugs = plug_get_list (); + for (int n = 0; plugs[n]; n++) { + if (plugs[n]->message) { + plugs[n]->message (msg, ctx, p1, p2); + } + } DB_output_t *output = plug_get_output (); switch (msg) { case M_REINIT_SOUND: @@ -401,7 +408,8 @@ player_mainloop (void) { conf_save (); break; case M_TERMINATE: - return; + term = 1; + break; case M_PLAY_CURRENT: if (p1) { output->stop (); @@ -458,6 +466,12 @@ player_mainloop (void) { plug_trigger_event (DB_EV_CONFIGCHANGED, 0); break; } + if (msg >= DB_EV_FIRST && ctx) { + messagepump_event_free ((ddb_event_t *)ctx); + } + } + if (term) { + return; } //usleep(50000); //plug_trigger_event (DB_EV_FRAMEUPDATE, 0); diff --git a/messagepump.c b/messagepump.c index 931b67db..d58623ea 100644 --- a/messagepump.c +++ b/messagepump.c @@ -17,8 +17,11 @@ */ #include #include +#include +#include #include "messagepump.h" #include "threading.h" +#include "playlist.h" typedef struct message_s { uint32_t id; @@ -71,7 +74,7 @@ messagepump_reset (void) { int messagepump_push (uint32_t id, uintptr_t ctx, uint32_t p1, uint32_t p2) { if (!mfree) { - printf ("WARNING: message queue is full! message ignored (%d %p %d %d)\n", id, (void*)ctx, p1, p2); + fprintf (stderr, "WARNING: message queue is full! message ignored (%d %p %d %d)\n", id, (void*)ctx, p1, p2); return -1; } mutex_lock (mutex); @@ -126,3 +129,70 @@ int messagepump_hasmessages (void) { return mqueue ? 1 : 0; } + +ddb_event_t * +messagepump_event_alloc (uint32_t id) { + int sz = 0; + ddb_event_t *ev; + switch (id) { + case DB_EV_SONGCHANGED: + sz = sizeof (ddb_event_trackchange_t); + break; + case DB_EV_SONGSTARTED: + case DB_EV_SONGFINISHED: + case DB_EV_TRACKINFOCHANGED: + sz = sizeof (ddb_event_track_t); + break; + case DB_EV_SEEKED: + sz = sizeof (ddb_event_playpos_t); + break; + } + assert (("Invalid event %d to use with messagepump_event_alloc, use sendmessage instead\n", id)); + ev = malloc (sz); + memset (ev, 0, sz); + ev->event = id; + ev->size = sz; + return ev; +} + +void +messagepump_event_free (ddb_event_t *ev) { + switch (ev->event) { + case DB_EV_SONGCHANGED: + { + ddb_event_trackchange_t *tc = (ddb_event_trackchange_t*)ev; + if (tc->from) { + pl_item_unref ((playItem_t *)tc->from); + } + if (tc->to) { + pl_item_unref ((playItem_t *)tc->to); + } + } + break; + case DB_EV_SONGSTARTED: + case DB_EV_SONGFINISHED: + case DB_EV_TRACKINFOCHANGED: + { + ddb_event_track_t *tc = (ddb_event_track_t*)ev; + if (tc->track) { + pl_item_unref ((playItem_t *)tc->track); + } + } + break; + case DB_EV_SEEKED: + { + ddb_event_playpos_t *tc = (ddb_event_playpos_t*)ev; + if (tc->track) { + pl_item_unref ((playItem_t *)tc->track); + } + } + break; + } + free (ev); +} + +int +messagepump_push_event (ddb_event_t *ev, uint32_t p1, uint32_t p2) { + return messagepump_push (ev->event, (uintptr_t)ev, p1, p2); +} + diff --git a/messagepump.h b/messagepump.h index b22da711..30f43c5e 100644 --- a/messagepump.h +++ b/messagepump.h @@ -19,6 +19,7 @@ #define __MESSAGEPUMP_H #include +#include int messagepump_init (void); void messagepump_free (void); @@ -26,4 +27,8 @@ int messagepump_push (uint32_t id, uintptr_t ctx, uint32_t p1, uint32_t p2); int messagepump_pop (uint32_t *id, uintptr_t *ctx, uint32_t *p1, uint32_t *p2); void messagepump_wait (void); +ddb_event_t *messagepump_event_alloc (uint32_t id); +void messagepump_event_free (ddb_event_t *ev); +int messagepump_push_event (ddb_event_t *ev, uint32_t p1, uint32_t p2); + #endif // __MESSAGEPUMP_H diff --git a/playlist.c b/playlist.c index e1d0d500..2d8231cd 100644 --- a/playlist.c +++ b/playlist.c @@ -311,7 +311,7 @@ plt_add (int before, const char *title) { if (!plt_loading) { pl_save_n (before); conf_save (); - plug_trigger_event (DB_EV_PLAYLISTSWITCH, 0); + messagepump_push (DB_EV_PLAYLISTSWITCH, 0, 0, 0); } return playlists_count-1; } @@ -360,7 +360,7 @@ plt_remove (int plt) { plt_gen_conf (); conf_save (); pl_save_n (0); - plug_trigger_event (DB_EV_PLAYLISTSWITCH, 0); + messagepump_push (DB_EV_PLAYLISTSWITCH, 0, 0, 0); return; } if (i != plt) { @@ -404,7 +404,7 @@ plt_remove (int plt) { plt_gen_conf (); conf_save (); if (!plt_loading) { - plug_trigger_event (DB_EV_PLAYLISTSWITCH, 0); + messagepump_push (DB_EV_PLAYLISTSWITCH, 0, 0, 0); } } @@ -431,7 +431,7 @@ plt_set_curr (int plt) { if (p != playlist) { playlist = p; if (!plt_loading) { - plug_trigger_event (DB_EV_PLAYLISTSWITCH, 0); + messagepump_push (DB_EV_PLAYLISTSWITCH, 0, 0, 0); conf_set_int ("playlist.current", plt_get_curr ()); conf_save (); } @@ -496,7 +496,7 @@ plt_set_title (playlist_t *p, const char *title) { UNLOCK; conf_save (); if (!plt_loading) { - plug_trigger_event (DB_EV_PLAYLISTSWITCH, 0); + messagepump_push (DB_EV_PLAYLISTSWITCH, 0, 0, 0); } return 0; } @@ -1469,7 +1469,6 @@ pl_insert_file (playItem_t *after, const char *fname, int *pabort, int (*cb)(pla if (!strcasecmp (exts[e], eol)) { playItem_t *inserted = (playItem_t *)decoders[i]->insert (DB_PLAYITEM (after), fname); if (inserted != NULL) { - printf ("inserted %s\n", fname); if (cb && cb (inserted, user_data) < 0) { *pabort = 1; } @@ -1599,12 +1598,12 @@ pl_add_dir (const char *dirname, int (*cb)(playItem_t *it, void *data), void *us void pl_add_files_begin (int plt) { addfiles_playlist = plt_get (plt); - printf ("adding to playlist %d (%s)\n", plt, addfiles_playlist->title); + trace ("adding to playlist %d (%s)\n", plt, addfiles_playlist->title); } void pl_add_files_end (void) { - printf ("end adding to playlist %s\n", addfiles_playlist->title); + trace ("end adding to playlist %s\n", addfiles_playlist->title); addfiles_playlist = NULL; } @@ -2197,7 +2196,7 @@ pl_load (const char *fname) { for (p = 0; plug[p]; p++) { for (e = 0; plug[p]->extensions[e]; e++) { if (plug[p]->load && !strcasecmp (ext, plug[p]->extensions[e])) { - DB_playItem_t *it = plug[p]->load (it, fname, NULL, NULL, NULL); + /*DB_playItem_t *it = */plug[p]->load (NULL, fname, NULL, NULL, NULL); UNLOCK; return 0; } @@ -2360,7 +2359,7 @@ pl_load (const char *fname) { if (fread (&l, 1, 2, fp) != 2) { goto load_fail; } - if (l < 0 || l >= 20000) { + if (l >= 20000) { goto load_fail; } char key[l+1]; @@ -2371,7 +2370,7 @@ pl_load (const char *fname) { if (fread (&l, 1, 2, fp) != 2) { goto load_fail; } - if (l<0 || l >= 20000) { + if (l >= 20000) { // skip fseek (fp, l, SEEK_CUR); } @@ -2502,7 +2501,7 @@ pl_load_all (void) { plt_set_curr (0); plt_loading = 0; plt_gen_conf (); - plug_trigger_event (DB_EV_PLAYLISTSWITCH, 0); + messagepump_push (DB_EV_PLAYLISTSWITCH, 0, 0, 0); UNLOCK; trace ("pl_load_all finished\n"); return err; diff --git a/plugins.c b/plugins.c index dae0ed7a..eb7fc9f2 100644 --- a/plugins.c +++ b/plugins.c @@ -62,8 +62,6 @@ static DB_functions_t deadbeef_api = { // FIXME: set to 1.0 after api freeze .vmajor = 0, .vminor = 0, - .ev_subscribe = plug_ev_subscribe, - .ev_unsubscribe = plug_ev_unsubscribe, .md5 = plug_md5, .md5_to_str = plug_md5_to_str, .md5_init = (void (*)(DB_md5_t *s))md5_init, @@ -258,6 +256,9 @@ static DB_functions_t deadbeef_api = { .fabort = vfs_fabort, // message passing .sendmessage = messagepump_push, + .event_alloc = messagepump_event_alloc, + .event_free = messagepump_event_free, + .event_send = messagepump_push_event, // configuration access .conf_lock = conf_lock, .conf_unlock = conf_unlock, @@ -378,15 +379,6 @@ plug_md5_to_str (char *str, const uint8_t sig[16]) { *str = 0; } -// event handlers -typedef struct { - DB_plugin_t *plugin; - DB_callback_t callback; - uintptr_t data; -} evhandler_t; -#define MAX_HANDLERS 100 -static evhandler_t handlers[DB_EV_MAX][MAX_HANDLERS]; - // plugin control structures typedef struct plugin_s { void *handle; @@ -409,40 +401,6 @@ plug_unlock (void) { pl_unlock (); } -void -plug_ev_subscribe (DB_plugin_t *plugin, int ev, DB_callback_t callback, uintptr_t data) { - assert (ev < DB_EV_MAX && ev >= 0); - int i; - plug_lock (); - for (i = 0; i < MAX_HANDLERS; i++) { - if (!handlers[ev][i].plugin) { - handlers[ev][i].plugin = plugin; - handlers[ev][i].callback = callback; - handlers[ev][i].data = data; - break; - } - } - plug_unlock (); - if (i == MAX_HANDLERS) { - trace ("failed to subscribe plugin %s to event %d (too many event handlers)\n", plugin->name, ev); - } -} - -void -plug_ev_unsubscribe (DB_plugin_t *plugin, int ev, DB_callback_t callback, uintptr_t data) { - assert (ev < DB_EV_MAX && ev >= 0); - plug_lock (); - for (int i = 0; i < MAX_HANDLERS; i++) { - if (handlers[ev][i].plugin == plugin) { - handlers[ev][i].plugin = NULL; - handlers[ev][i].callback = NULL; - handlers[ev][i].data = 0; - break; - } - } - plug_unlock (); -} - float plug_playback_get_pos (void) { playItem_t *trk = streamer_get_playing_track (); @@ -477,12 +435,12 @@ plug_playback_set_pos (float pos) { } /////// non-api functions (plugin support) +#if 0 void -plug_event_call (DB_event_t *ev) { +plug_event_call (ddb_event_t *ev) { if (!mutex) { trace ("plug: event passed before plugin initialization\n"); } - ev->time = time (NULL); // printf ("plug_event_call enter %d\n", ev->event); plug_lock (); @@ -499,68 +457,68 @@ plug_event_call (DB_event_t *ev) { plug_unlock (); // printf ("plug_event_call leave %d\n", ev->event); } +#endif +// FIXME: this is backward-compatibility layer, should be killed void plug_trigger_event (int ev, uintptr_t param) { - DB_event_t *event; + ddb_event_t *event = NULL; switch (ev) { case DB_EV_SONGSTARTED: case DB_EV_SONGFINISHED: { - DB_event_track_t *pev = alloca (sizeof (DB_event_track_t)); + ddb_event_track_t *pev = (ddb_event_track_t *)messagepump_event_alloc (ev); playItem_t *pltrack = streamer_get_playing_track (); pev->track = DB_PLAYITEM (pltrack); - if (pltrack) { - pl_item_unref (pltrack); - } event = DB_EVENT (pev); } break; - default: - event = alloca (sizeof (DB_event_t)); } - event->event = ev; - plug_event_call (event); + if (event) { + messagepump_push_event (event, 0, 0); + } + else { + messagepump_push (ev, param, 0, 0); + } } void plug_trigger_event_trackchange (playItem_t *from, playItem_t *to) { - DB_event_trackchange_t event; - event.ev.event = DB_EV_SONGCHANGED; - //printf ("plug_trigger_event_trackchange %p %d %p %d\n", from, from ? from->_refc : -1, to, to ? to->_refc : -1); - event.from = (DB_playItem_t *)from; - event.to = (DB_playItem_t *)to; - plug_event_call (DB_EVENT (&event)); + ddb_event_trackchange_t *event = (ddb_event_trackchange_t *)messagepump_event_alloc (DB_EV_SONGCHANGED); + if (from) { + pl_item_ref (from); + } + if (to) { + pl_item_ref (to); + } + event->from = (DB_playItem_t *)from; + event->to = (DB_playItem_t *)to; + messagepump_push_event ((ddb_event_t *)event, 0, 0); } + void plug_trigger_event_trackinfochanged (playItem_t *track) { - DB_event_track_t event; - event.ev.event = DB_EV_TRACKINFOCHANGED; - event.track = DB_PLAYITEM (track); - //printf ("\033[0;31mtrackinfochanged %p(%s), playing: %p, streaming: %p\033[37;0m\n", track, track->fname, streamer_get_playing_track (), streamer_get_streaming_track ()); - plug_event_call (DB_EVENT (&event)); + ddb_event_track_t *ev = (ddb_event_track_t *)messagepump_event_alloc (DB_EV_TRACKINFOCHANGED); + ev->track = DB_PLAYITEM (track); + if (track) { + pl_item_ref (track); + } + messagepump_push_event ((ddb_event_t*)ev, 0, 0); } void plug_trigger_event_paused (int paused) { - DB_event_state_t event; - event.ev.event = DB_EV_PAUSED; - event.state = paused; - plug_event_call (DB_EVENT (&event)); + messagepump_push (DB_EV_PAUSED, 0, paused, 0); } void plug_trigger_event_playlistchanged (void) { - DB_event_t event; - event.event = DB_EV_PLAYLISTCHANGED; - plug_event_call (DB_EVENT (&event)); + messagepump_push (DB_EV_PLAYLISTCHANGED, 0, 0, 0); } void plug_trigger_event_volumechanged (void) { - DB_event_t event; - event.event = DB_EV_VOLUMECHANGED; - plug_event_call (DB_EVENT (&event)); + messagepump_push (DB_EV_VOLUMECHANGED, 0, 0, 0); } int diff --git a/plugins.h b/plugins.h index 5537888b..8a41bb67 100644 --- a/plugins.h +++ b/plugins.h @@ -144,6 +144,6 @@ const char ** plug_get_gui_names (void); void -plug_event_call (DB_event_t *ev); +plug_event_call (ddb_event_t *ev); #endif // __PLUGINS_H diff --git a/plugins/alsa/alsa.c b/plugins/alsa/alsa.c index 07b0c869..04a14bdd 100644 --- a/plugins/alsa/alsa.c +++ b/plugins/alsa/alsa.c @@ -687,7 +687,7 @@ palsa_callback (char *stream, int len) { } static int -palsa_configchanged (DB_event_t *ev, uintptr_t data) { +alsa_configchanged (void) { deadbeef->conf_lock (); const char *alsa_soundcard = deadbeef->conf_get_str_fast ("alsa_soundcard", "default"); int buffer = deadbeef->conf_get_int ("alsa.buffer", DEFAULT_BUFFER_SIZE); @@ -737,15 +737,23 @@ palsa_get_state (void) { return state; } +static int +alsa_message (uint32_t id, uintptr_t ctx, uint32_t p1, uint32_t p2) { + switch (id) { + case DB_EV_CONFIGCHANGED: + alsa_configchanged (); + break; + } + return 0; +} + static int alsa_start (void) { - deadbeef->ev_subscribe (DB_PLUGIN (&plugin), DB_EV_CONFIGCHANGED, DB_CALLBACK (palsa_configchanged), 0); return 0; } static int alsa_stop (void) { - deadbeef->ev_unsubscribe (DB_PLUGIN (&plugin), DB_EV_CONFIGCHANGED, DB_CALLBACK (palsa_configchanged), 0); return 0; } @@ -791,6 +799,7 @@ static DB_output_t plugin = { .plugin.start = alsa_start, .plugin.stop = alsa_stop, .plugin.configdialog = settings_dlg, + .plugin.message = alsa_message, .init = palsa_init, .free = palsa_free, .setformat = palsa_setformat, diff --git a/plugins/artwork/artwork.c b/plugins/artwork/artwork.c index b29db8f2..a86b83a7 100644 --- a/plugins/artwork/artwork.c +++ b/plugins/artwork/artwork.c @@ -722,7 +722,7 @@ artwork_reset (int fast) { } static int -artwork_on_configchanged (DB_event_t *ev, uintptr_t data) { +artwork_configchanged (void) { int new_artwork_enable_embedded = deadbeef->conf_get_int ("artwork.enable_embedded", 1); int new_artwork_enable_local = deadbeef->conf_get_int ("artwork.enable_localfolder", 1); int new_artwork_enable_lfm = deadbeef->conf_get_int ("artwork.enable_lastfm", 0); @@ -751,6 +751,16 @@ artwork_on_configchanged (DB_event_t *ev, uintptr_t data) { return 0; } +static int +artwork_message (uint32_t id, uintptr_t ctx, uint32_t p1, uint32_t p2) { + switch (id) { + case DB_EV_CONFIGCHANGED: + artwork_configchanged (); + break; + } + return 0; +} + static int artwork_plugin_start (void) { @@ -777,8 +787,6 @@ artwork_plugin_start (void) artwork_filemask[sizeof(artwork_filemask)-1] = 0; - deadbeef->ev_subscribe (DB_PLUGIN (&plugin), DB_EV_CONFIGCHANGED, DB_CALLBACK (artwork_on_configchanged), 0); - mutex = deadbeef->mutex_create_nonrecursive (); imlib_mutex = deadbeef->mutex_create_nonrecursive (); cond = deadbeef->cond_create (); @@ -790,7 +798,6 @@ artwork_plugin_start (void) static int artwork_plugin_stop (void) { - deadbeef->ev_unsubscribe (DB_PLUGIN (&plugin), DB_EV_CONFIGCHANGED, DB_CALLBACK (artwork_on_configchanged), 0); if (current_file) { deadbeef->fabort (current_file); } @@ -861,6 +868,7 @@ static DB_artwork_plugin_t plugin = { .plugin.plugin.start = artwork_plugin_start, .plugin.plugin.stop = artwork_plugin_stop, .plugin.plugin.configdialog = settings_dlg, + .plugin.plugin.message = artwork_message, .get_album_art = get_album_art, .reset = artwork_reset, .get_default_cover = get_default_cover, diff --git a/plugins/ffmpeg/ffmpeg.c b/plugins/ffmpeg/ffmpeg.c index 020f2a1c..8082b1d2 100644 --- a/plugins/ffmpeg/ffmpeg.c +++ b/plugins/ffmpeg/ffmpeg.c @@ -693,15 +693,18 @@ ffmpeg_init_exts (void) { } static int -ffmpeg_on_configchanged (DB_event_t *ev, uintptr_t data) { - ffmpeg_init_exts (); +ffmpeg_message (uint32_t id, uintptr_t ctx, uint32_t p1, uint32_t p2) { + switch (id) { + case DB_EV_CONFIGCHANGED: + ffmpeg_init_exts (); + break; + } return 0; } static int ffmpeg_start (void) { ffmpeg_init_exts (); - deadbeef->ev_subscribe (DB_PLUGIN (&plugin), DB_EV_CONFIGCHANGED, DB_CALLBACK (ffmpeg_on_configchanged), 0); avcodec_init (); av_register_all (); av_register_protocol (&vfswrapper); @@ -710,7 +713,6 @@ ffmpeg_start (void) { static int ffmpeg_stop (void) { - deadbeef->ev_unsubscribe (DB_PLUGIN (&plugin), DB_EV_CONFIGCHANGED, DB_CALLBACK (ffmpeg_on_configchanged), 0); for (int i = 0; exts[i]; i++) { free (exts[i]); } @@ -806,6 +808,7 @@ static DB_decoder_t plugin = { .plugin.start = ffmpeg_start, .plugin.stop = ffmpeg_stop, .plugin.configdialog = settings_dlg, + .plugin.message = ffmpeg_message, .open = ffmpeg_open, .init = ffmpeg_init, .free = ffmpeg_free, diff --git a/plugins/gtkui/ddblistview.c b/plugins/gtkui/ddblistview.c index c50dd9df..1406e95b 100644 --- a/plugins/gtkui/ddblistview.c +++ b/plugins/gtkui/ddblistview.c @@ -607,7 +607,6 @@ ddb_listview_list_render (DdbListview *listview, int x, int y, int w, int h) { ddb_listview_groupcheck (listview); // find 1st group DdbListviewGroup *grp = listview->groups; - printf ("starting to render listview, groups=%p, num_items=%d\n", grp, grp?grp->num_items : 0); int grp_y = 0; while (grp && grp_y + grp->height < y + listview->scrollpos) { grp_y += grp->height; @@ -919,7 +918,6 @@ ddb_listview_list_drag_data_received (GtkWidget *widget, guint time, gpointer user_data) { - printf ("target_type: %d, format: %d\n", target_type, data->format); DdbListview *ps = DDB_LISTVIEW (g_object_get_data (G_OBJECT (widget), "owner")); ps->scroll_direction = 0; // interrupt autoscrolling, if on ps->scroll_active = 0; @@ -2907,7 +2905,6 @@ ddb_listview_build_groups (DdbListview *listview) { memset (grp, 0, sizeof (DdbListviewGroup)); grp->head = it; grp->num_items = listview->binding->count (); - printf ("numitems: %d\n", grp->num_items); listview->grouptitle_height = 0; grp->height = listview->grouptitle_height + grp->num_items * listview->rowheight; // if (grp->height < min_height) { @@ -2953,12 +2950,6 @@ ddb_listview_build_groups (DdbListview *listview) { } listview->fullheight += grp->height; } - if (!listview->groups) { - printf ("empty!\n"); - } - else { - printf ("groupsize: %d!\n", listview->groups->num_items); - } deadbeef->pl_unlock (); if (old_height != listview->fullheight) { ddb_listview_refresh (listview, DDB_REFRESH_VSCROLL); diff --git a/plugins/gtkui/gtkui.c b/plugins/gtkui/gtkui.c index 0a268a52..22570b87 100644 --- a/plugins/gtkui/gtkui.c +++ b/plugins/gtkui/gtkui.c @@ -337,12 +337,6 @@ activate_cb (gpointer nothing) { return FALSE; } -static int -gtkui_on_activate (DB_event_t *ev, uintptr_t data) { - g_idle_add (activate_cb, NULL); - return 0; -} - void redraw_queued_tracks (DdbListview *pl, int list) { DB_playItem_t *it; @@ -386,12 +380,6 @@ gtkpl_songchanged_wrapper (DB_playItem_t *from, DB_playItem_t *to) { g_idle_add (redraw_queued_tracks_cb, NULL); } -static int -gtkui_on_songchanged (DB_event_trackchange_t *ev, uintptr_t data) { - gtkpl_songchanged_wrapper (ev->from, ev->to); - return 0; -} - void gtkui_set_titlebar (DB_playItem_t *it) { if (!it) { @@ -450,15 +438,6 @@ trackinfochanged_cb (gpointer data) { return FALSE; } -static int -gtkui_on_trackinfochanged (DB_event_track_t *ev, uintptr_t data) { - if (ev->track) { - deadbeef->pl_item_ref (ev->track); - } - g_idle_add (trackinfochanged_cb, ev->track); - return 0; -} - static gboolean paused_cb (gpointer nothing) { DB_playItem_t *curr = deadbeef->streamer_get_playing_track (); @@ -471,12 +450,6 @@ paused_cb (gpointer nothing) { return FALSE; } -static int -gtkui_on_paused (DB_event_state_t *ev, uintptr_t data) { - g_idle_add (paused_cb, NULL); - return 0; -} - void playlist_refresh (void) { DdbListview *ps = DDB_LISTVIEW (lookup_widget (mainwin, "playlist")); @@ -495,13 +468,6 @@ gtkui_playlist_changed (void) { g_idle_add (playlistchanged_cb, NULL); } -static int -gtkui_on_playlistchanged (DB_event_t *ev, uintptr_t data) { - printf ("gtkui_on_playlistchanged\n"); - gtkui_playlist_changed (); - return 0; -} - static gboolean playlistswitch_cb (gpointer none) { GtkWidget *tabstrip = lookup_widget (mainwin, "tabstrip"); @@ -529,12 +495,6 @@ playlistswitch_cb (gpointer none) { return FALSE; } -static int -gtkui_on_playlistswitch (DB_event_t *ev, uintptr_t data) { - g_idle_add (playlistswitch_cb, NULL); - return 0; -} - static gboolean gtkui_on_frameupdate (gpointer data) { update_songinfo (NULL); @@ -549,13 +509,6 @@ gtkui_volumechanged_cb (gpointer ctx) { return FALSE; } -static int -gtkui_on_volumechanged (DB_event_t *ev, uintptr_t data) { - g_idle_add (gtkui_volumechanged_cb, NULL); - - return 0; -} - static gboolean gtkui_update_status_icon (gpointer unused) { int hide_tray_icon = deadbeef->conf_get_int ("gtkui.hide_tray_icon", 0); @@ -630,7 +583,7 @@ gtkui_get_curr_playlist_modtime (void) { } static int -gtkui_on_configchanged (DB_event_t *ev, uintptr_t data) { +gtkui_on_configchanged (ddb_event_t *ev, uintptr_t data) { // order and looping const char *w; @@ -669,12 +622,6 @@ outputchanged_cb (gpointer nothing) { return FALSE; } -static int -gtkui_on_outputchanged (DB_event_t *ev, uintptr_t nothing) { - g_idle_add (outputchanged_cb, NULL); - return 0; -} - char last_playlist_save_name[1024] = ""; void @@ -992,6 +939,49 @@ gtkui_setup_gui_refresh (void) { refresh_timeout = g_timeout_add (tm, gtkui_on_frameupdate, NULL); } +int +gtkui_message (uint32_t id, uintptr_t ctx, uint32_t p1, uint32_t p2) { + switch (id) { + case DB_EV_ACTIVATE: + g_idle_add (activate_cb, NULL); + break; + case DB_EV_SONGCHANGED: + { + ddb_event_trackchange_t *ev = (ddb_event_trackchange_t *)ctx; + gtkpl_songchanged_wrapper (ev->from, ev->to); + } + break; + case DB_EV_TRACKINFOCHANGED: + { + ddb_event_track_t *ev = (ddb_event_track_t *)ctx; + if (ev->track) { + deadbeef->pl_item_ref (ev->track); + } + g_idle_add (trackinfochanged_cb, ev->track); + } + break; + case DB_EV_PAUSED: + g_idle_add (paused_cb, NULL); + break; + case DB_EV_PLAYLISTCHANGED: + gtkui_playlist_changed (); + break; + case DB_EV_VOLUMECHANGED: + g_idle_add (gtkui_volumechanged_cb, NULL); + break; + case DB_EV_CONFIGCHANGED: + gtkui_on_configchanged ((ddb_event_t *)ctx, 0); + break; + case DB_EV_OUTPUTCHANGED: + g_idle_add (outputchanged_cb, NULL); + break; + case DB_EV_PLAYLISTSWITCH: + g_idle_add (playlistswitch_cb, NULL); + break; + } + return 0; +} + void gtkui_thread (void *ctx) { // let's start some gtk @@ -1072,16 +1062,6 @@ gtkui_thread (void *ctx) { gtk_widget_show (mainwin); - deadbeef->ev_subscribe (DB_PLUGIN (&plugin), DB_EV_ACTIVATE, DB_CALLBACK (gtkui_on_activate), 0); - deadbeef->ev_subscribe (DB_PLUGIN (&plugin), DB_EV_SONGCHANGED, DB_CALLBACK (gtkui_on_songchanged), 0); - deadbeef->ev_subscribe (DB_PLUGIN (&plugin), DB_EV_TRACKINFOCHANGED, DB_CALLBACK (gtkui_on_trackinfochanged), 0); - deadbeef->ev_subscribe (DB_PLUGIN (&plugin), DB_EV_PAUSED, DB_CALLBACK (gtkui_on_paused), 0); - deadbeef->ev_subscribe (DB_PLUGIN (&plugin), DB_EV_PLAYLISTCHANGED, DB_CALLBACK (gtkui_on_playlistchanged), 0); - deadbeef->ev_subscribe (DB_PLUGIN (&plugin), DB_EV_VOLUMECHANGED, DB_CALLBACK (gtkui_on_volumechanged), 0); - deadbeef->ev_subscribe (DB_PLUGIN (&plugin), DB_EV_CONFIGCHANGED, DB_CALLBACK (gtkui_on_configchanged), 0); - deadbeef->ev_subscribe (DB_PLUGIN (&plugin), DB_EV_OUTPUTCHANGED, DB_CALLBACK (gtkui_on_outputchanged), 0); - deadbeef->ev_subscribe (DB_PLUGIN (&plugin), DB_EV_PLAYLISTSWITCH, DB_CALLBACK (gtkui_on_playlistswitch), 0); - gtkui_setup_gui_refresh (); char fmt[500]; @@ -1269,16 +1249,6 @@ gtkui_stop (void) { coverart_plugin->plugin.plugin.stop (); coverart_plugin = NULL; } - trace ("unsubscribing events\n"); - deadbeef->ev_unsubscribe (DB_PLUGIN (&plugin), DB_EV_ACTIVATE, DB_CALLBACK (gtkui_on_activate), 0); - deadbeef->ev_unsubscribe (DB_PLUGIN (&plugin), DB_EV_SONGCHANGED, DB_CALLBACK (gtkui_on_songchanged), 0); - deadbeef->ev_unsubscribe (DB_PLUGIN (&plugin), DB_EV_TRACKINFOCHANGED, DB_CALLBACK (gtkui_on_trackinfochanged), 0); - deadbeef->ev_unsubscribe (DB_PLUGIN (&plugin), DB_EV_PAUSED, DB_CALLBACK (gtkui_on_paused), 0); - deadbeef->ev_unsubscribe (DB_PLUGIN (&plugin), DB_EV_PLAYLISTCHANGED, DB_CALLBACK (gtkui_on_playlistchanged), 0); - deadbeef->ev_unsubscribe (DB_PLUGIN (&plugin), DB_EV_VOLUMECHANGED, DB_CALLBACK (gtkui_on_volumechanged), 0); - deadbeef->ev_unsubscribe (DB_PLUGIN (&plugin), DB_EV_CONFIGCHANGED, DB_CALLBACK (gtkui_on_configchanged), 0); - deadbeef->ev_unsubscribe (DB_PLUGIN (&plugin), DB_EV_OUTPUTCHANGED, DB_CALLBACK (gtkui_on_outputchanged), 0); - deadbeef->ev_unsubscribe (DB_PLUGIN (&plugin), DB_EV_PLAYLISTSWITCH, DB_CALLBACK (gtkui_on_playlistswitch), 0); trace ("quitting gtk\n"); g_idle_add (quit_gtk_cb, NULL); trace ("waiting for gtk thread to finish\n"); @@ -1342,6 +1312,7 @@ static ddb_gtkui_t plugin = { .gui.plugin.stop = gtkui_stop, .gui.plugin.connect = gtkui_connect, .gui.plugin.configdialog = settings_dlg, + .gui.plugin.message = gtkui_message, .gui.run_dialog = gtkui_run_dialog_root, .get_mainwin = gtkui_get_mainwin, }; diff --git a/plugins/lastfm/lastfm.c b/plugins/lastfm/lastfm.c index 14299a54..45e37489 100644 --- a/plugins/lastfm/lastfm.c +++ b/plugins/lastfm/lastfm.c @@ -488,7 +488,7 @@ lfm_format_uri (int subm, DB_playItem_t *song, char *out, int outl) { } static int -lastfm_songstarted (DB_event_track_t *ev, uintptr_t data) { +lastfm_songstarted (ddb_event_track_t *ev, uintptr_t data) { trace ("lfm songstarted %s\n", ev->track->fname); if (!deadbeef->conf_get_int ("lastfm.enable", 0)) { return 0; @@ -507,7 +507,7 @@ lastfm_songstarted (DB_event_track_t *ev, uintptr_t data) { } static int -lastfm_songfinished (DB_event_track_t *ev, uintptr_t data) { +lastfm_songfinished (ddb_event_track_t *ev, uintptr_t data) { trace ("lfm songfinished %s\n", ev->track->fname); if (!deadbeef->conf_get_int ("lastfm.enable", 0)) { return 0; @@ -798,6 +798,19 @@ auth_v2 (void) { #endif // }}} +static int +lfm_message (uint32_t id, uintptr_t ctx, uint32_t p1, uint32_t p2) { + switch (id) { + // subscribe to frameupdate event + case DB_EV_SONGSTARTED: + lastfm_songstarted ((ddb_event_track_t *)ctx, 0); + break; + case DB_EV_SONGCHANGED: + lastfm_songfinished ((ddb_event_track_t *)ctx, 0); + break; + } + return 0; +} static int lastfm_start (void) { @@ -809,9 +822,6 @@ lastfm_start (void) { lfm_mutex = deadbeef->mutex_create_nonrecursive (); lfm_cond = deadbeef->cond_create (); lfm_tid = deadbeef->thread_start (lfm_thread, NULL); - // subscribe to frameupdate event - deadbeef->ev_subscribe (DB_PLUGIN (&plugin), DB_EV_SONGSTARTED, DB_CALLBACK (lastfm_songstarted), 0); - deadbeef->ev_subscribe (DB_PLUGIN (&plugin), DB_EV_SONGCHANGED, DB_CALLBACK (lastfm_songfinished), 0); return 0; } @@ -821,8 +831,6 @@ lastfm_stop (void) { trace ("lastfm_stop\n"); if (lfm_mutex) { lfm_stopthread = 1; - deadbeef->ev_unsubscribe (DB_PLUGIN (&plugin), DB_EV_SONGSTARTED, DB_CALLBACK (lastfm_songstarted), 0); - deadbeef->ev_unsubscribe (DB_PLUGIN (&plugin), DB_EV_SONGCHANGED, DB_CALLBACK (lastfm_songfinished), 0); trace ("lfm_stop signalling cond\n"); deadbeef->cond_signal (lfm_cond); @@ -937,5 +945,6 @@ static DB_misc_t plugin = { .plugin.start = lastfm_start, .plugin.stop = lastfm_stop, .plugin.configdialog = settings_dlg, - .plugin.get_actions = lfm_get_actions + .plugin.get_actions = lfm_get_actions, + .plugin.message = lfm_message, }; diff --git a/plugins/notify/notify.c b/plugins/notify/notify.c index 7896baf9..a273a3a1 100644 --- a/plugins/notify/notify.c +++ b/plugins/notify/notify.c @@ -243,7 +243,7 @@ static void show_notification (DB_playItem_t *track) { } static int -on_songstarted (DB_event_track_t *ev, uintptr_t data) { +on_songstarted (ddb_event_track_t *ev) { if (ev->track && deadbeef->conf_get_int ("notify.enable", 0)) { DB_playItem_t *track = ev->track; if (track) { @@ -253,15 +253,23 @@ on_songstarted (DB_event_track_t *ev, uintptr_t data) { return 0; } +static int +notify_message (uint32_t id, uintptr_t ctx, uint32_t p1, uint32_t p2) { + switch (id) { + case DB_EV_SONGSTARTED: + on_songstarted ((ddb_event_track_t *)ctx); + break; + } + return 0; +} + int notify_start (void) { - deadbeef->ev_subscribe (DB_PLUGIN (&plugin), DB_EV_SONGSTARTED, DB_CALLBACK (on_songstarted), 0); return 0; } int notify_stop (void) { - deadbeef->ev_unsubscribe (DB_PLUGIN (&plugin), DB_EV_SONGSTARTED, DB_CALLBACK (on_songstarted), 0); return 0; } @@ -316,6 +324,7 @@ DB_misc_t plugin = { .plugin.connect = notify_connect, .plugin.disconnect = notify_disconnect, .plugin.configdialog = settings_dlg, + .plugin.message = notify_message, }; DB_plugin_t * diff --git a/plugins/oss/oss.c b/plugins/oss/oss.c index 953398af..e64e1fc0 100644 --- a/plugins/oss/oss.c +++ b/plugins/oss/oss.c @@ -315,7 +315,7 @@ oss_get_state (void) { } static int -oss_configchanged (DB_event_t *ev, uintptr_t data) { +oss_configchanged (void) { deadbeef->conf_lock (); const char *dev = deadbeef->conf_get_str_fast ("oss.device", "/dev/dsp"); if (strcmp (dev, oss_device)) { @@ -327,16 +327,24 @@ oss_configchanged (DB_event_t *ev, uintptr_t data) { return 0; } +static int +oss_message (uint32_t id, uintptr_t ctx, uint32_t p1, uint32_t p2) { + switch (id) { + case DB_EV_CONFIGCHANGED: + oss_configchanged (); + break; + } + return 0; +} + static int oss_plugin_start (void) { deadbeef->conf_get_str ("oss.device", "/dev/dsp", oss_device, sizeof (oss_device)); - deadbeef->ev_subscribe (DB_PLUGIN (&plugin), DB_EV_CONFIGCHANGED, DB_CALLBACK (oss_configchanged), 0); return 0; } static int oss_plugin_stop (void) { - deadbeef->ev_unsubscribe (DB_PLUGIN (&plugin), DB_EV_CONFIGCHANGED, DB_CALLBACK (oss_configchanged), 0); return 0; } @@ -379,6 +387,7 @@ static DB_output_t plugin = { .plugin.start = oss_plugin_start, .plugin.stop = oss_plugin_stop, .plugin.configdialog = settings_dlg, + .plugin.message = oss_message, .init = oss_init, .free = oss_free, .setformat = oss_setformat, diff --git a/plugins/sid/csid.cpp b/plugins/sid/csid.cpp index ffdd4548..20293812 100644 --- a/plugins/sid/csid.cpp +++ b/plugins/sid/csid.cpp @@ -605,7 +605,7 @@ csid_mutevoice (DB_fileinfo_t *_info, int voice, int mute) { #endif static int -csid_on_configchanged (DB_event_t *ev, uintptr_t data) { +sid_configchanged (void) { int conf_hvsc_enable = deadbeef->conf_get_int ("hvsc_enable", 0); int disable = !conf_hvsc_enable; if (disable != sldb_disable) { @@ -622,15 +622,23 @@ csid_on_configchanged (DB_event_t *ev, uintptr_t data) { return 0; } +int +sid_message (uint32_t id, uintptr_t ctx, uint32_t p1, uint32_t p2) { + switch (id) { + case DB_EV_CONFIGCHANGED: + sid_configchanged (); + break; + } + return 0; +} + int csid_start (void) { - deadbeef->ev_subscribe (DB_PLUGIN (&sid_plugin), DB_EV_CONFIGCHANGED, DB_CALLBACK (csid_on_configchanged), 0); return 0; } int csid_stop (void) { - deadbeef->ev_unsubscribe (DB_PLUGIN (&sid_plugin), DB_EV_CONFIGCHANGED, DB_CALLBACK (csid_on_configchanged), 0); if (sldb) { free (sldb); sldb = NULL; diff --git a/plugins/sid/csid.h b/plugins/sid/csid.h index c35be3d7..66ad0ff5 100644 --- a/plugins/sid/csid.h +++ b/plugins/sid/csid.h @@ -33,6 +33,7 @@ int csid_numvoices (DB_fileinfo_t *); void csid_mutevoice (DB_fileinfo_t *, int voice, int mute); int csid_start (void); int csid_stop (void); +int sid_message (uint32_t id, uintptr_t ctx, uint32_t p1, uint32_t p2); #ifdef __cplusplus } diff --git a/plugins/sid/plugin.c b/plugins/sid/plugin.c index c8f1f7b0..ff350da6 100644 --- a/plugins/sid/plugin.c +++ b/plugins/sid/plugin.c @@ -63,6 +63,7 @@ DB_decoder_t sid_plugin = { .plugin.stop = csid_stop, .plugin.configdialog = settings_dlg, .plugin.id = "stdsid", + .plugin.message = sid_message, .open = csid_open, .init = csid_init, .free = csid_free, diff --git a/plugins/sndfile/sndfile.c b/plugins/sndfile/sndfile.c index 3af4616f..bc7eaf1a 100644 --- a/plugins/sndfile/sndfile.c +++ b/plugins/sndfile/sndfile.c @@ -411,23 +411,24 @@ sndfile_init_exts (void) { exts[n] = NULL; } - static int -sndfile_on_configchanged (DB_event_t *ev, uintptr_t data) { - sndfile_init_exts (); +sndfile_message (uint32_t id, uintptr_t ctx, uint32_t p1, uint32_t p2) { + switch (id) { + case DB_EV_CONFIGCHANGED: + sndfile_init_exts (); + break; + } return 0; } static int sndfile_start (void) { sndfile_init_exts (); - deadbeef->ev_subscribe (DB_PLUGIN (&plugin), DB_EV_CONFIGCHANGED, DB_CALLBACK (sndfile_on_configchanged), 0); return 0; } static int sndfile_stop (void) { - deadbeef->ev_unsubscribe (DB_PLUGIN (&plugin), DB_EV_CONFIGCHANGED, DB_CALLBACK (sndfile_on_configchanged), 0); for (int i = 0; exts[i]; i++) { free (exts[i]); } @@ -479,6 +480,7 @@ static DB_decoder_t plugin = { .plugin.start = sndfile_start, .plugin.stop = sndfile_stop, .plugin.configdialog = settings_dlg, + .plugin.message = sndfile_message, }; DB_plugin_t * diff --git a/streamer.c b/streamer.c index 3f8873a0..e957033e 100644 --- a/streamer.c +++ b/streamer.c @@ -1137,12 +1137,13 @@ streamer_thread (void *ctx) { avg_bitrate = -1; streamer_unlock(); } - ddb_event_playpos_t tp; - tp.ev.event = DB_EV_SEEKED; - tp.ev.time = time (NULL); - tp.track = (DB_playItem_t *)playing_track; - tp.playpos = playpos; - plug_event_call (DB_EVENT (&tp)); + ddb_event_playpos_t *ev = (ddb_event_playpos_t *)messagepump_event_alloc (DB_EV_SEEKED); + ev->track = DB_PLAYITEM (playing_track); + if (playing_track) { + pl_item_ref (playing_track); + } + ev->playpos = playpos; + messagepump_push_event ((ddb_event_t*)ev, 0, 0); } // read ahead at 2x speed of output samplerate, in 4k blocks -- cgit v1.2.3