From fd2a251c149c9fd3549caa2ffef2283635c9ca35 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Sat, 20 Dec 2014 10:16:44 -0500 Subject: [PATCH] audio: Initialize GST from the gui layer This means I no longer need to pass argc and argv parameters to core/, so I can eventually work towards removing the Driver :: init() function. Signed-off-by: Anna Schumaker --- core/audio.cpp | 4 ++-- core/core.cpp | 4 ++-- gui/gst.cpp | 30 +++++++++++++++--------------- gui/main.cpp | 2 +- include/core/audio.h | 5 +---- include/core/core.h | 5 +---- include/core/driver.h | 4 +--- include/gui/ocarina.h | 2 +- lib/lib.cpp | 2 +- tests/core/audio.cpp | 12 ++++++------ 10 files changed, 31 insertions(+), 39 deletions(-) diff --git a/core/audio.cpp b/core/audio.cpp index 0bd09b32..2cc24e86 100644 --- a/core/audio.cpp +++ b/core/audio.cpp @@ -84,11 +84,11 @@ static void on_eos() _load_track(deck :: next(), continue_playback()); } -void audio :: init(int *argc, char ***argv) +void audio :: init() { unsigned int id; - cur_driver->init(argc, argv, on_eos); + cur_driver->init(on_eos); if (f_cur_track.exists()) { f_cur_track.open(OPEN_READ); f_cur_track >> id; diff --git a/core/core.cpp b/core/core.cpp index 8725b4d8..ec85e6f5 100644 --- a/core/core.cpp +++ b/core/core.cpp @@ -10,11 +10,11 @@ #include -void core :: init(int *argc, char ***argv) +void core :: init() { tags :: init(); library :: init(); playlist :: init(); deck :: init(); - audio :: init(argc, argv); + audio :: init(); } diff --git a/gui/gst.cpp b/gui/gst.cpp index a7f84209..588fd5b3 100644 --- a/gui/gst.cpp +++ b/gui/gst.cpp @@ -27,7 +27,7 @@ public: /** * GStreamer audio driver constructor. */ - GSTDriver(); + GSTDriver(int *, char ***); /** * GStreamer audio driver destructor. @@ -36,11 +36,9 @@ public: /** * Called to initialize the GStreamer audio driver. - * @param argc Argc passed to the application's main() function. - * @param argv Argv passed to the applicaiton's main() function. * @param eos_cb End-of-stream callback function. */ - void init(int *, char ***, void (*)()); + void init(void (*)()); /** * Load a track into the gstreamer pipeline. @@ -113,7 +111,16 @@ static void parse_gst_error(GstMessage *error, const std::string filepath) g_free(debug); } -GSTDriver :: GSTDriver() {} +GSTDriver :: GSTDriver(int *argc, char ***argv) + : Driver() +{ + GstBus *bus; + + gst_init(argc, argv); + player = gst_element_factory_make("playbin", "ocarina_player"); + bus = gst_pipeline_get_bus(GST_PIPELINE(player)); + gst_bus_add_watch(bus, on_gst_message, this); +} GSTDriver :: ~GSTDriver() { @@ -133,16 +140,9 @@ bool GSTDriver :: change_state(GstState state) } } -void GSTDriver :: init(int *argc, char ***argv, void (*eos_cb)()) +void GSTDriver :: init(void (*eos_cb)()) { - GstBus *bus; - on_eos = eos_cb; - - gst_init(argc, argv); - player = gst_element_factory_make("playbin", "ocarina_player"); - bus = gst_pipeline_get_bus(GST_PIPELINE(player)); - gst_bus_add_watch(bus, on_gst_message, this); } void GSTDriver :: load(const std::string &filepath) @@ -211,9 +211,9 @@ void GSTDriver :: on_message(GstMessage *message) } -void init_gst() +void init_gst(int *argc, char ***argv) { - gst_driver = new GSTDriver(); + gst_driver = new GSTDriver(argc, argv); } void quit_gst() diff --git a/gui/main.cpp b/gui/main.cpp index 1920ed10..5135b40c 100644 --- a/gui/main.cpp +++ b/gui/main.cpp @@ -8,7 +8,7 @@ Gtk::Window *ocarina_init(int *argc, char ***argv) { - init_gst(); + init_gst(argc, argv); lib :: init(argc, argv, "ocarina6.glade"); Gtk::Window *window = setup_gui(); diff --git a/include/core/audio.h b/include/core/audio.h index 9d45d5c5..33102e33 100644 --- a/include/core/audio.h +++ b/include/core/audio.h @@ -17,11 +17,8 @@ namespace audio /** * Initializes the audio layer and currently configured audio driver. - * - * @param argc Pointer to the argc initially passed to core :: init(). - * @param argv Pointer to the argv initially passed to core :: init(). */ - void init(int *, char ***); + void init(); void play(); /** Begin playback. */ void pause(); /** Pause playback. */ diff --git a/include/core/core.h b/include/core/core.h index 5435ce6a..763e7b9b 100644 --- a/include/core/core.h +++ b/include/core/core.h @@ -14,11 +14,8 @@ namespace core /** * Initializes all components of the core library, including reading * databases from disk and setting up gstreamer. - * - * @param argc Pointer to the argc initially passed to main() - * @param argv Pointer to the argv initially passed to main() */ - void init(int *, char ***); + void init(); } diff --git a/include/core/driver.h b/include/core/driver.h index 4e482ef8..00a08421 100644 --- a/include/core/driver.h +++ b/include/core/driver.h @@ -27,11 +27,9 @@ public: /** * Initialize an audio driver. * - * @param argc Argc passed to the application's main() function. - * @param argv Argv passed to the applicaiton's main() function. * @param eos_cb End-of-stream callback function. */ - virtual void init(int *argc, char ***argv, void (*eos_cb)()) = 0; + virtual void init(void (*eos_cb)()) = 0; /** diff --git a/include/gui/ocarina.h b/include/gui/ocarina.h index e5f6b97d..018c5f69 100644 --- a/include/gui/ocarina.h +++ b/include/gui/ocarina.h @@ -25,7 +25,7 @@ void post_init_queue_tabs(); /* gst.cpp */ -void init_gst(); +void init_gst(int *, char ***); void quit_gst(); diff --git a/lib/lib.cpp b/lib/lib.cpp index ddbf58df..bc150bfc 100644 --- a/lib/lib.cpp +++ b/lib/lib.cpp @@ -30,7 +30,7 @@ void lib :: init(int *argc, char ***argv, const std::string >k_xml) if (!builder->add_from_file(lib :: share_file(gtk_xml))) exit(1); - core :: init(argc, argv); + core :: init(); } const std::string lib :: share_file(const std::string &f) diff --git a/tests/core/audio.cpp b/tests/core/audio.cpp index 03842dd4..ff552f3c 100644 --- a/tests/core/audio.cpp +++ b/tests/core/audio.cpp @@ -22,7 +22,7 @@ public: TestDriver() : playing(false), cur_pos(0), cur_duration(0) {} ~TestDriver() {}; - void init(int *argc, char ***argv, void (*eos_cb)()) + void init(void (*eos_cb)()) { on_eos = eos_cb; } @@ -70,7 +70,7 @@ void test_driver() test_not_equal(audio :: get_driver(), (Driver *)NULL); test_equal((Driver *)&driver, audio :: get_driver()); - driver.init(0, NULL, on_eos); + driver.init(on_eos); driver.load(file); test_equal(driver.cur_file, file); @@ -134,19 +134,19 @@ void test_pre_init() test_equal(audio :: current_track(), TRACK_NULL); } -void test_init(int argc, char **argv) +void test_init() { Track *track; test :: cp_data_dir(); - audio :: init(&argc, &argv); + audio :: init(); track = audio :: current_track(); test_equal(track, TRACK_NULL); tags :: init(); library :: init(); - audio :: init(&argc, &argv); + audio :: init(); track = audio :: current_track(); test_not_equal(track, TRACK_NULL); @@ -254,7 +254,7 @@ int main(int argc, char **argv) TestDriver driver; run_test("Test Audio Pre-Init", test_pre_init); - run_test("Test Audio Init", test_init, argc, argv); + run_test("Test Audio Init", test_init); run_test("Test Audio Playback Controls", test_playback_controls); run_test("Test Audio Track Controls", test_track_controls); run_test("Test Audio Automatic Pausing", test_autopause);