From aa7b6ad5b0e94004a0e27007fcdf807baa34bce0 Mon Sep 17 00:00:00 2001 From: waker Date: Sun, 4 Aug 2013 19:32:58 +0200 Subject: added new API for querying/handling background jobs --- deadbeef.h | 8 ++++++++ plugins.c | 31 +++++++++++++++++++++++++++++++ plugins.h | 9 +++++++++ 3 files changed, 48 insertions(+) diff --git a/deadbeef.h b/deadbeef.h index 60294d9d..b9d88a12 100644 --- a/deadbeef.h +++ b/deadbeef.h @@ -795,9 +795,17 @@ typedef struct { // data size must be float[DDB_AUDIO_MEMORY_FRAMES] void (*audio_get_waveform_data) (int type, float *data); + // this is useful to mute/unmute audio, and query the muted status, from + // plugins, without touching the volume control void (*audio_set_mute) (int mute); int (*audio_is_mute) (void); + // this is useful for prompting a user when he attempts to quit the player + // while something is working in background, e.g. the Converter, + // and let him finish or cancel the background jobs. + void (*background_job_increment) (void); + void (*background_job_decrement) (void); + int (*have_background_jobs) (void); } DB_functions_t; // NOTE: an item placement must be selected like this diff --git a/plugins.c b/plugins.c index a12b026c..f3a92c46 100644 --- a/plugins.c +++ b/plugins.c @@ -344,6 +344,9 @@ static DB_functions_t deadbeef_api = { .audio_get_waveform_data = audio_get_waveform_data, .audio_set_mute = audio_set_mute, .audio_is_mute = audio_is_mute, + .background_job_increment = background_job_increment, + .background_job_decrement = background_job_decrement, + .have_background_jobs = have_background_jobs, }; DB_functions_t *deadbeef = &deadbeef_api; @@ -407,6 +410,9 @@ DB_output_t *output_plugin = NULL; #define MAX_PLAYLIST_PLUGINS 10 DB_playlist_t *g_playlist_plugins[MAX_PLAYLIST_PLUGINS+1]; +static uintptr_t background_jobs_mutex; +static int num_background_jobs; + void plug_md5 (uint8_t sig[16], const char *in, int len) { md5_state_t st; @@ -786,6 +792,8 @@ plug_load_all (void) { trace ("\033[0;31mDISABLE_VERSIONCHECK=1! do not distribute!\033[0;m\n"); #endif + background_jobs_mutex = mutex_create (); + const char *dirname = deadbeef->get_plugin_dir (); #ifndef ANDROID @@ -1062,6 +1070,10 @@ plug_unload_all (void) { memset (g_playlist_plugins, 0, sizeof (g_playlist_plugins)); trace ("all plugins had been unloaded\n"); + if (background_jobs_mutex) { + mutex_free (background_jobs_mutex); + background_jobs_mutex = 0; + } } void @@ -1260,3 +1272,22 @@ plug_is_local_file (const char *fname) { return 1; } + +void +background_job_increment (void) { + mutex_lock (background_jobs_mutex); + num_background_jobs++; + mutex_unlock (background_jobs_mutex); +} + +void +background_job_decrement (void) { + mutex_lock (background_jobs_mutex); + num_background_jobs--; + mutex_unlock (background_jobs_mutex); +} + +int +have_background_jobs (void) { + return num_background_jobs; +} diff --git a/plugins.h b/plugins.h index 1fdb6b82..e05e45f6 100644 --- a/plugins.h +++ b/plugins.h @@ -136,4 +136,13 @@ plug_get_gui_names (void); void plug_event_call (ddb_event_t *ev); +void +background_job_increment (void); + +void +background_job_decrement (void); + +int +have_background_jobs (void); + #endif // __PLUGINS_H -- cgit v1.2.3