core/audio: Rename audio_ops -> audio_callbacks
And make them optional, that way tests don't need to keep creating fake callbacks if they don't need anything from the audio layer. Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
d3df9a69f2
commit
5247bf2de0
16
core/audio.c
16
core/audio.c
|
@ -11,7 +11,7 @@ static const char *SETTINGS_VOLUME = "core.audio.volume";
|
|||
static struct file audio_file = FILE_INIT("cur_track", 0);
|
||||
static struct track *audio_track = NULL;
|
||||
static GstElement *audio_player = NULL;
|
||||
static struct audio_ops *audio_ops = NULL;
|
||||
static struct audio_callbacks *audio_cb = NULL;
|
||||
static int audio_pause_count = -1;
|
||||
static guint audio_bus = 0;
|
||||
|
||||
|
@ -25,7 +25,8 @@ static bool __audio_change_state(GstState state)
|
|||
if (ret == GST_STATE_CHANGE_FAILURE)
|
||||
return false;
|
||||
|
||||
audio_ops->on_state_change(state);
|
||||
if (audio_cb)
|
||||
audio_cb->audio_cb_state_change(state);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -38,7 +39,9 @@ static void __audio_gst_load(struct track *track, GstState state)
|
|||
gst_element_set_state(audio_player, GST_STATE_NULL);
|
||||
g_object_set(G_OBJECT(audio_player), "uri", uri, NULL);
|
||||
__audio_change_state(state);
|
||||
audio_ops->on_load(track);
|
||||
|
||||
if (audio_cb)
|
||||
audio_cb->audio_cb_load(track);
|
||||
|
||||
audio_save();
|
||||
g_free(uri);
|
||||
|
@ -106,14 +109,14 @@ static bool __audio_init_idle(void *data)
|
|||
}
|
||||
|
||||
|
||||
void audio_init(int *argc, char ***argv, struct audio_ops *ops)
|
||||
void audio_init(int *argc, char ***argv, struct audio_callbacks *callbacks)
|
||||
{
|
||||
unsigned int volume = 100;
|
||||
GstBus *bus;
|
||||
|
||||
gst_init(argc, argv);
|
||||
audio_player = gst_element_factory_make("playbin", "ocarina_player");
|
||||
audio_ops = ops;
|
||||
audio_cb = callbacks;
|
||||
|
||||
bus = gst_pipeline_get_bus(GST_PIPELINE(audio_player));
|
||||
audio_bus = gst_bus_add_watch(bus, __audio_message, NULL);
|
||||
|
@ -281,7 +284,8 @@ void audio_pause_after(int n)
|
|||
{
|
||||
if (n != audio_pause_count) {
|
||||
audio_pause_count = n;
|
||||
audio_ops->on_config_pause(audio_pause_count);
|
||||
if (audio_cb)
|
||||
audio_cb->audio_cb_config_pause(audio_pause_count);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ void core_init(int *argc, char ***argv, struct core_init_data *init)
|
|||
settings_init();
|
||||
tags_init();
|
||||
playlist_init(init->playlist_cb);
|
||||
audio_init(argc, argv, init->audio_ops);
|
||||
audio_init(argc, argv, init->audio_cb);
|
||||
|
||||
idle_schedule(IDLE_SYNC, core_defragment, NULL);
|
||||
}
|
||||
|
|
|
@ -57,10 +57,10 @@ static void __gui_audio_config_pause(int n)
|
|||
}
|
||||
|
||||
|
||||
struct audio_ops audio_ops = {
|
||||
.on_load = __gui_audio_load,
|
||||
.on_state_change = __gui_audio_change_state,
|
||||
.on_config_pause = __gui_audio_config_pause,
|
||||
struct audio_callbacks audio_cb = {
|
||||
.audio_cb_load = __gui_audio_load,
|
||||
.audio_cb_state_change = __gui_audio_change_state,
|
||||
.audio_cb_config_pause = __gui_audio_config_pause,
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ const static gchar *OCARINA_APP = "org.gtk.ocarina-debug";
|
|||
|
||||
static struct core_init_data init_data = {
|
||||
.playlist_cb = &playlist_cb,
|
||||
.audio_ops = &audio_ops,
|
||||
.audio_cb = &audio_cb,
|
||||
.idle_sync = IDLE_ASYNC,
|
||||
};
|
||||
|
||||
|
|
|
@ -11,20 +11,20 @@
|
|||
#include <gst/gst.h>
|
||||
|
||||
|
||||
struct audio_ops {
|
||||
struct audio_callbacks {
|
||||
/* Called when a track is loaded. */
|
||||
void (*on_load)(struct track *);
|
||||
void (*audio_cb_load)(struct track *);
|
||||
|
||||
/* Called when playback state changes. */
|
||||
void (*on_state_change)(GstState);
|
||||
void (*audio_cb_state_change)(GstState);
|
||||
|
||||
/* Called when the automatic pause state changes. */
|
||||
void (*on_config_pause)(int);
|
||||
void (*audio_cb_config_pause)(int);
|
||||
};
|
||||
|
||||
|
||||
/* Called to initialize the audio manager. */
|
||||
void audio_init(int *, char ***, struct audio_ops *);
|
||||
void audio_init(int *, char ***, struct audio_callbacks *);
|
||||
|
||||
/* Called to deinitialize the audio manager. */
|
||||
void audio_deinit();
|
||||
|
|
|
@ -8,8 +8,8 @@
|
|||
|
||||
struct core_init_data {
|
||||
struct playlist_callbacks *playlist_cb;
|
||||
struct audio_ops *audio_ops;
|
||||
enum idle_sync_t idle_sync;
|
||||
struct audio_callbacks *audio_cb;
|
||||
enum idle_sync_t idle_sync;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
#include <gui/builder.h>
|
||||
|
||||
/* Audio callback functions. */
|
||||
extern struct audio_ops audio_ops;
|
||||
extern struct audio_callbacks audio_cb;
|
||||
|
||||
/* Called to initialize the GUI audio controls. */
|
||||
void gui_audio_init();
|
||||
|
|
|
@ -41,14 +41,14 @@ static void test_audio_load(struct track *track) { load_count++; }
|
|||
static void test_change_state(GstState state) { state_count++; }
|
||||
static void test_config_pause(int n) { pause_count = n; }
|
||||
|
||||
static struct audio_ops test_audio_ops = {
|
||||
test_audio_load,
|
||||
test_change_state,
|
||||
test_config_pause,
|
||||
static struct audio_callbacks test_audio_cb = {
|
||||
.audio_cb_load = test_audio_load,
|
||||
.audio_cb_state_change = test_change_state,
|
||||
.audio_cb_config_pause = test_config_pause,
|
||||
};
|
||||
|
||||
static struct core_init_data test_init_data = {
|
||||
.audio_ops = &test_audio_ops,
|
||||
.audio_cb = &test_audio_cb,
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -16,18 +16,18 @@ static void test_audio_load(struct track *track)
|
|||
static void test_change_state(GstState state) { }
|
||||
static void test_config_pause(int n) { }
|
||||
|
||||
static struct audio_ops test_audio_ops = {
|
||||
.on_load = test_audio_load,
|
||||
.on_state_change = test_change_state,
|
||||
.on_config_pause = test_config_pause,
|
||||
static struct audio_callbacks test_audio_cb = {
|
||||
.audio_cb_load = test_audio_load,
|
||||
.audio_cb_state_change = test_change_state,
|
||||
.audio_cb_config_pause = test_config_pause,
|
||||
};
|
||||
|
||||
struct core_init_data init_data = {
|
||||
.audio_ops = &test_audio_ops,
|
||||
.audio_cb = &test_audio_cb,
|
||||
#ifdef CONFIG_ALBUM_ART_TEST
|
||||
.idle_sync = IDLE_ASYNC,
|
||||
.idle_sync = IDLE_ASYNC,
|
||||
#else /* CONFIG_ALBUM_ART_TEST */
|
||||
.idle_sync = IDLE_SYNC,
|
||||
.idle_sync = IDLE_SYNC,
|
||||
#endif /* CONFIG_ALBUM_ART_TEST */
|
||||
};
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
#include <tests/test.h>
|
||||
|
||||
struct core_init_data init_data = {
|
||||
.audio_ops = &audio_ops,
|
||||
.audio_cb = &audio_cb,
|
||||
};
|
||||
|
||||
static void test_audio_init()
|
||||
|
|
|
@ -8,19 +8,7 @@
|
|||
#include <gui/model.h>
|
||||
#include <gui/window.h>
|
||||
|
||||
void test_on_load(struct track *track) {}
|
||||
void test_on_state_change(GstState state) {}
|
||||
void test_on_config_pause(int count) {}
|
||||
|
||||
struct audio_ops test_audio_ops = {
|
||||
.on_load = test_on_load,
|
||||
.on_state_change = test_on_state_change,
|
||||
.on_config_pause = test_on_config_pause,
|
||||
};
|
||||
|
||||
struct core_init_data init_data = {
|
||||
.audio_ops = &test_audio_ops,
|
||||
};
|
||||
static struct core_init_data init_data;
|
||||
|
||||
void test_filter()
|
||||
{
|
||||
|
|
|
@ -24,9 +24,6 @@ void on_row_changed(GtkTreeModel *model, GtkTreePath *path,
|
|||
{ count_update++; }
|
||||
|
||||
void test_cb_alloc(struct playlist *playlist) {}
|
||||
void test_on_load(struct track *track) {}
|
||||
void test_on_state_change(GstState state) {}
|
||||
void test_on_config_pause(int count) {}
|
||||
|
||||
struct playlist_callbacks test_cb = {
|
||||
.pl_cb_alloc = test_cb_alloc,
|
||||
|
@ -35,15 +32,8 @@ struct playlist_callbacks test_cb = {
|
|||
.pl_cb_updated = gui_model_update,
|
||||
};
|
||||
|
||||
struct audio_ops test_audio_ops = {
|
||||
.on_load = test_on_load,
|
||||
.on_state_change = test_on_state_change,
|
||||
.on_config_pause = test_on_config_pause,
|
||||
};
|
||||
|
||||
struct core_init_data init_data = {
|
||||
.playlist_cb = &test_cb,
|
||||
.audio_ops = &test_audio_ops,
|
||||
};
|
||||
|
||||
static void test_init()
|
||||
|
|
|
@ -16,15 +16,15 @@ static void test_audio_load(struct track *track)
|
|||
static void test_change_state(GstState state) { }
|
||||
static void test_config_pause(int n) { }
|
||||
|
||||
static struct audio_ops test_audio_ops = {
|
||||
.on_load = test_audio_load,
|
||||
.on_state_change = test_change_state,
|
||||
.on_config_pause = test_config_pause,
|
||||
static struct audio_callbacks test_audio_cb = {
|
||||
.audio_cb_load = test_audio_load,
|
||||
.audio_cb_state_change = test_change_state,
|
||||
.audio_cb_config_pause = test_config_pause,
|
||||
};
|
||||
|
||||
struct core_init_data init_data = {
|
||||
.playlist_cb = &playlist_cb,
|
||||
.audio_ops = &test_audio_ops,
|
||||
.audio_cb = &test_audio_cb,
|
||||
};
|
||||
|
||||
static const gchar *toplevel[3] = { "Queued Tracks", "Collection", "History" };
|
||||
|
|
|
@ -25,19 +25,7 @@ const gchar *GUI_COL_SETTINGS[GUI_MODEL_N_COLUMNS] = {
|
|||
[GUI_MODEL_FONT] = "gui.queue.font",
|
||||
};
|
||||
|
||||
static void test_load(struct track *track) { }
|
||||
static void test_state_change(GstState state) {}
|
||||
static void test_config_pause(int count) {}
|
||||
|
||||
struct audio_ops test_audio_ops = {
|
||||
.on_load = test_load,
|
||||
.on_state_change = test_state_change,
|
||||
.on_config_pause = test_config_pause,
|
||||
};
|
||||
|
||||
struct core_init_data init_data = {
|
||||
.audio_ops = &test_audio_ops,
|
||||
};
|
||||
static struct core_init_data init_data;
|
||||
|
||||
void test_treeview_init()
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue