core/audio: Move audio_init() out of the audio namespace
I also move the gstreamer playbin back into core/ Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
b7bd7622b3
commit
d9540b29d6
|
@ -10,19 +10,21 @@ extern "C" {
|
|||
}
|
||||
|
||||
|
||||
static struct file audio_file;
|
||||
static GstElement *audio_player = NULL;
|
||||
|
||||
static bool _pause_enabled = false;
|
||||
static unsigned int _pause_count = 0;
|
||||
|
||||
static struct track *cur_track = NULL;
|
||||
static struct file f_cur_track;
|
||||
static AudioDriver *cur_driver = NULL;
|
||||
|
||||
|
||||
static void save_state()
|
||||
{
|
||||
file_open(&f_cur_track, OPEN_WRITE);
|
||||
file_writef(&f_cur_track, "%u\n", cur_track->tr_dbe.dbe_index);
|
||||
file_close(&f_cur_track);
|
||||
file_open(&audio_file, OPEN_WRITE);
|
||||
file_writef(&audio_file, "%u\n", cur_track->tr_dbe.dbe_index);
|
||||
file_close(&audio_file);
|
||||
}
|
||||
|
||||
static void _load_track(struct track *track, bool start_playback)
|
||||
|
@ -83,16 +85,18 @@ void AudioDriver :: eos()
|
|||
|
||||
|
||||
|
||||
void audio :: init()
|
||||
void audio_init(int *argc, char ***argv)
|
||||
{
|
||||
unsigned int id;
|
||||
unsigned int track;
|
||||
|
||||
file_init(&f_cur_track, "cur_track", 0);
|
||||
if (file_exists(&f_cur_track)) {
|
||||
file_open(&f_cur_track, OPEN_READ);
|
||||
file_readf(&f_cur_track, "%u", &id);
|
||||
file_close(&f_cur_track);
|
||||
audio :: load_track(track_get(id));
|
||||
gst_init(argc, argv);
|
||||
audio_player = gst_element_factory_make("playbin", "ocarina_player");
|
||||
|
||||
file_init(&audio_file, "cur_track", 0);
|
||||
if (file_open(&audio_file, OPEN_READ)) {
|
||||
file_readf(&audio_file, "%u", &track);
|
||||
file_close(&audio_file);
|
||||
audio :: load_track(track_get(track));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -186,3 +190,8 @@ AudioDriver *audio :: get_driver()
|
|||
{
|
||||
return cur_driver;
|
||||
}
|
||||
|
||||
GstElement *audio_get_player()
|
||||
{
|
||||
return audio_player;
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ extern "C" {
|
|||
}
|
||||
|
||||
|
||||
void core :: init(struct core_init_data *init)
|
||||
void core :: init(int *argc, char ***argv, struct core_init_data *init)
|
||||
{
|
||||
filter_init();
|
||||
tags_init();
|
||||
|
@ -21,7 +21,7 @@ void core :: init(struct core_init_data *init)
|
|||
collection_init(init->collection_ops);
|
||||
history_init(init->history_ops);
|
||||
tempq_init(init->tempq_ops);
|
||||
audio :: init();
|
||||
audio_init(argc, argv);
|
||||
}
|
||||
|
||||
void core :: deinit()
|
||||
|
|
23
gui/gst.cpp
23
gui/gst.cpp
|
@ -15,7 +15,6 @@ extern "C" {
|
|||
|
||||
|
||||
static GstBus *gst_bus;
|
||||
static GstElement *gst_player;
|
||||
|
||||
static Gtk::Button *o_next;
|
||||
static Gtk::Button *o_pause;
|
||||
|
@ -37,7 +36,7 @@ static Glib::RefPtr<Gtk::Adjustment> o_progress;
|
|||
|
||||
static bool gst_change_state(GstState state)
|
||||
{
|
||||
GstStateChangeReturn ret = gst_element_set_state(gst_player, state);
|
||||
GstStateChangeReturn ret = gst_element_set_state(audio_get_player(), state);
|
||||
switch (ret) {
|
||||
case GST_STATE_CHANGE_SUCCESS:
|
||||
case GST_STATE_CHANGE_ASYNC:
|
||||
|
@ -66,7 +65,7 @@ public:
|
|||
gchar *str;
|
||||
|
||||
gst_change_state(GST_STATE_NULL);
|
||||
g_object_set(G_OBJECT(gst_player), "uri", uri, NULL);
|
||||
g_object_set(G_OBJECT(audio_get_player()), "uri", uri, NULL);
|
||||
g_free(uri);
|
||||
|
||||
str = g_strdup_printf("From: %s", track->tr_album->al_name);
|
||||
|
@ -105,7 +104,7 @@ public:
|
|||
bool is_playing()
|
||||
{
|
||||
GstState state;
|
||||
gst_element_get_state(gst_player,
|
||||
gst_element_get_state(audio_get_player(),
|
||||
&state,
|
||||
NULL,
|
||||
GST_CLOCK_TIME_NONE);
|
||||
|
@ -114,7 +113,7 @@ public:
|
|||
|
||||
void seek_to(int64_t offset)
|
||||
{
|
||||
gst_element_seek_simple(gst_player,
|
||||
gst_element_seek_simple(audio_get_player(),
|
||||
GST_FORMAT_TIME,
|
||||
GST_SEEK_FLAG_FLUSH,
|
||||
offset);
|
||||
|
@ -123,7 +122,7 @@ public:
|
|||
int64_t position()
|
||||
{
|
||||
int64_t position;
|
||||
if (gst_element_query_position(gst_player,
|
||||
if (gst_element_query_position(audio_get_player(),
|
||||
GST_FORMAT_TIME,
|
||||
&position))
|
||||
return position;
|
||||
|
@ -133,7 +132,7 @@ public:
|
|||
int64_t duration()
|
||||
{
|
||||
int64_t duration;
|
||||
if (gst_element_query_duration(gst_player,
|
||||
if (gst_element_query_duration(audio_get_player(),
|
||||
GST_FORMAT_TIME,
|
||||
&duration))
|
||||
return duration;
|
||||
|
@ -230,12 +229,8 @@ void gst :: toggle()
|
|||
audio :: play();
|
||||
}
|
||||
|
||||
void gst :: init(int *argc, char ***argv)
|
||||
void gst :: init_pre()
|
||||
{
|
||||
gst_init(argc, argv);
|
||||
|
||||
gst_player = gst_element_factory_make("playbin", "ocarina_player");
|
||||
gst_bus = gst_pipeline_get_bus(GST_PIPELINE(gst_player));
|
||||
gst_driver = new GSTDriver();
|
||||
|
||||
o_next = gui :: get_widget<Gtk::Button>("o_next");
|
||||
|
@ -264,7 +259,11 @@ void gst :: init(int *argc, char ***argv)
|
|||
|
||||
o_count->signal_changed().connect(sigc::ptr_fun(on_pause_count));
|
||||
o_enabled->signal_toggled().connect(sigc::ptr_fun(on_pause_enabled));
|
||||
}
|
||||
|
||||
void gst :: init()
|
||||
{
|
||||
gst_bus = gst_pipeline_get_bus(GST_PIPELINE(audio_get_player()));
|
||||
gst_bus_add_watch(gst_bus, on_gst_message, NULL);
|
||||
Glib :: signal_timeout().connect(sigc::ptr_fun(on_timeout), 500);
|
||||
}
|
||||
|
|
|
@ -61,9 +61,8 @@ int main(int argc, char **argv)
|
|||
if (!gui::__O_BUILDER->add_from_file(gui::share_file("ocarina6.glade")))
|
||||
exit(1);
|
||||
|
||||
gst :: init(&argc, &argv);
|
||||
|
||||
core :: init(&init_data);
|
||||
gst :: init_pre();
|
||||
core :: init(&argc, &argv, &init_data);
|
||||
|
||||
plist :: init();
|
||||
manager :: init();
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
extern "C" {
|
||||
#include <core/tags/track.h>
|
||||
}
|
||||
#include <gst/gst.h>
|
||||
#include <string>
|
||||
#include <stdint.h>
|
||||
|
||||
|
@ -83,7 +84,6 @@ public:
|
|||
namespace audio
|
||||
{
|
||||
|
||||
void init(); /**< Initializes the audio layer. */
|
||||
void play(); /**< Begin playback. */
|
||||
void pause(); /**< Pause playback. */
|
||||
|
||||
|
@ -154,4 +154,10 @@ namespace audio
|
|||
AudioDriver *get_driver();
|
||||
};
|
||||
|
||||
|
||||
/* Called to initialize the audio manager. */
|
||||
void audio_init(int *, char ***);
|
||||
|
||||
|
||||
GstElement *audio_get_player();
|
||||
#endif /* OCARINA_CORE_AUDIO_H */
|
||||
|
|
|
@ -24,7 +24,7 @@ namespace core
|
|||
* Initializes all components of the core library, including reading
|
||||
* databases from disk and setting up gstreamer.
|
||||
*/
|
||||
void init(struct core_init_data *);
|
||||
void init(int *, char ***, struct core_init_data *);
|
||||
void deinit();
|
||||
|
||||
}
|
||||
|
|
|
@ -44,7 +44,8 @@ namespace gst
|
|||
{
|
||||
void next();
|
||||
void toggle();
|
||||
void init(int *, char ***);
|
||||
void init_pre();
|
||||
void init();
|
||||
void quit();
|
||||
}
|
||||
|
||||
|
|
|
@ -42,6 +42,8 @@ res += [ CoreTest("playlist") ]
|
|||
res += [ CoreTest("collection") ]
|
||||
res += [ CoreTest("history") ]
|
||||
res += [ CoreTest("tempq") ]
|
||||
|
||||
core_objs += [ env.Object("../../core/core.cpp") ]
|
||||
res += [ CoreTest("audio") ]
|
||||
|
||||
Return("res")
|
||||
|
|
|
@ -4,12 +4,8 @@
|
|||
#include <core/audio.h>
|
||||
extern "C" {
|
||||
#include <core/collection.h>
|
||||
#include <core/filter.h>
|
||||
#include <core/history.h>
|
||||
#include <core/playlist.h>
|
||||
#include <core/tags/tags.h>
|
||||
#include <core/tempq.h>
|
||||
}
|
||||
#include <core/core.h>
|
||||
#include "test.h"
|
||||
|
||||
struct track *TRACK_NULL = NULL;
|
||||
|
@ -44,6 +40,28 @@ public:
|
|||
} driver;
|
||||
|
||||
|
||||
static struct core_init_data test_init_data = {
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
};
|
||||
|
||||
|
||||
static void test_init()
|
||||
{
|
||||
test_equal(audio :: current_track(), NULL);
|
||||
test_equal(audio_get_player(), NULL);
|
||||
|
||||
core :: init(NULL, NULL, &test_init_data);
|
||||
|
||||
test_equal(audio :: current_track(), NULL);
|
||||
test_not_equal(audio_get_player(), NULL);
|
||||
|
||||
core :: deinit();
|
||||
}
|
||||
|
||||
|
||||
void test_pre_init()
|
||||
{
|
||||
TestDriver *driver = (TestDriver *)audio :: get_driver();
|
||||
|
@ -78,24 +96,17 @@ void test_pre_init()
|
|||
test_equal(audio :: current_track(), TRACK_NULL);
|
||||
}
|
||||
|
||||
void test_init()
|
||||
void test_init2()
|
||||
{
|
||||
struct track *track;
|
||||
|
||||
test_cp_data_dir();
|
||||
audio :: init();
|
||||
audio_init(NULL, NULL);
|
||||
|
||||
track = audio :: current_track();
|
||||
test_equal(track, TRACK_NULL);
|
||||
|
||||
filter_init();
|
||||
tags_init();
|
||||
playlist_init(NULL);
|
||||
collection_init(NULL);
|
||||
history_init(NULL);
|
||||
tempq_init(NULL);
|
||||
audio :: init();
|
||||
|
||||
core :: init(NULL, NULL, &test_init_data);
|
||||
track = audio :: current_track();
|
||||
test_not_equal(track, TRACK_NULL);
|
||||
}
|
||||
|
@ -194,8 +205,9 @@ void test_autopause()
|
|||
}
|
||||
|
||||
DECLARE_UNIT_TESTS(
|
||||
UNIT_TEST("Audio Initialization", test_init),
|
||||
UNIT_TEST("Test Audio Pre-Init", test_pre_init),
|
||||
UNIT_TEST("Test Audio Init", test_init),
|
||||
UNIT_TEST("Test Audio Init 2", test_init2),
|
||||
UNIT_TEST("Test Audio Playback Controls", test_playback_controls),
|
||||
UNIT_TEST("Test Audio Automatic Pausing", test_autopause),
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue