core/audio: Set up the gstreamer bus for the gui
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
1d76990fd1
commit
03196c3efa
|
@ -15,7 +15,7 @@ static struct track *audio_track = NULL;
|
||||||
static GstElement *audio_player = NULL;
|
static GstElement *audio_player = NULL;
|
||||||
static struct audio_ops *audio_ops = NULL;
|
static struct audio_ops *audio_ops = NULL;
|
||||||
static int audio_pause_count = -1;
|
static int audio_pause_count = -1;
|
||||||
|
static guint audio_bus = 0;
|
||||||
|
|
||||||
static void __audio_save()
|
static void __audio_save()
|
||||||
{
|
{
|
||||||
|
@ -64,15 +64,35 @@ static struct track *__audio_next(GstState state)
|
||||||
return track;
|
return track;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gboolean __audio_message(GstBus *bus, GstMessage *message, gpointer data)
|
||||||
|
{
|
||||||
|
switch (GST_MESSAGE_TYPE(message)) {
|
||||||
|
case GST_MESSAGE_ERROR:
|
||||||
|
audio_error(message);
|
||||||
|
break;
|
||||||
|
case GST_MESSAGE_EOS:
|
||||||
|
audio_eos();
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void audio_init(int *argc, char ***argv, struct audio_ops *ops)
|
void audio_init(int *argc, char ***argv, struct audio_ops *ops)
|
||||||
{
|
{
|
||||||
unsigned int track;
|
unsigned int track;
|
||||||
|
GstBus *bus;
|
||||||
|
|
||||||
gst_init(argc, argv);
|
gst_init(argc, argv);
|
||||||
audio_player = gst_element_factory_make("playbin", "ocarina_player");
|
audio_player = gst_element_factory_make("playbin", "ocarina_player");
|
||||||
audio_ops = ops;
|
audio_ops = ops;
|
||||||
|
|
||||||
|
bus = gst_pipeline_get_bus(GST_PIPELINE(audio_player));
|
||||||
|
audio_bus = gst_bus_add_watch(bus, __audio_message, NULL);
|
||||||
|
gst_object_unref(bus);
|
||||||
|
|
||||||
file_init(&audio_file, "cur_track", 0);
|
file_init(&audio_file, "cur_track", 0);
|
||||||
if (file_open(&audio_file, OPEN_READ)) {
|
if (file_open(&audio_file, OPEN_READ)) {
|
||||||
file_readf(&audio_file, "%u", &track);
|
file_readf(&audio_file, "%u", &track);
|
||||||
|
@ -85,6 +105,7 @@ void audio_deinit()
|
||||||
{
|
{
|
||||||
gst_element_set_state(audio_player, GST_STATE_NULL);
|
gst_element_set_state(audio_player, GST_STATE_NULL);
|
||||||
gst_object_unref(GST_ELEMENT(audio_player));
|
gst_object_unref(GST_ELEMENT(audio_player));
|
||||||
|
g_source_remove(audio_bus);
|
||||||
|
|
||||||
audio_player = NULL;
|
audio_player = NULL;
|
||||||
audio_track = NULL;
|
audio_track = NULL;
|
||||||
|
@ -204,14 +225,17 @@ void audio_error(GstMessage *error)
|
||||||
gchar *path = NULL, *debug = NULL;
|
gchar *path = NULL, *debug = NULL;
|
||||||
GError *err = NULL;
|
GError *err = NULL;
|
||||||
|
|
||||||
if (audio_track)
|
if (audio_track) {
|
||||||
|
collection_check_library(audio_track->tr_library);
|
||||||
path = track_path(audio_track);
|
path = track_path(audio_track);
|
||||||
|
}
|
||||||
if (error)
|
if (error)
|
||||||
gst_message_parse_error(error, &err, &debug);
|
gst_message_parse_error(error, &err, &debug);
|
||||||
|
|
||||||
g_print("Error: %s (%s)\n", err->message, path);
|
g_print("Error: %s (%s)\n", err->message, path);
|
||||||
if (debug)
|
if (debug)
|
||||||
g_print("Debug details: %s\n", debug);
|
g_print("Debug details: %s\n", debug);
|
||||||
|
|
||||||
audio_next();
|
audio_next();
|
||||||
|
|
||||||
g_error_free(err);
|
g_error_free(err);
|
||||||
|
|
43
gui/gst.cpp
43
gui/gst.cpp
|
@ -14,8 +14,6 @@ extern "C" {
|
||||||
#include <gst/gst.h>
|
#include <gst/gst.h>
|
||||||
|
|
||||||
|
|
||||||
static GstBus *gst_bus;
|
|
||||||
|
|
||||||
static Gtk::Button *o_next;
|
static Gtk::Button *o_next;
|
||||||
static Gtk::Button *o_pause;
|
static Gtk::Button *o_pause;
|
||||||
static Gtk::Button *o_play;
|
static Gtk::Button *o_play;
|
||||||
|
@ -86,45 +84,6 @@ struct audio_ops audio_ops = {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
static int parse_gst_error(GstMessage *error)
|
|
||||||
{
|
|
||||||
GError *err;
|
|
||||||
struct track *track = audio_cur_track();
|
|
||||||
gchar *path;
|
|
||||||
int ret = 0;
|
|
||||||
|
|
||||||
gst_message_parse_error(error, &err, NULL);
|
|
||||||
|
|
||||||
if (track) {
|
|
||||||
path = track_path(track);
|
|
||||||
g_print("Error playing file: %s\n", path);
|
|
||||||
ret = collection_check_library(track->tr_library);
|
|
||||||
g_free(path);
|
|
||||||
}
|
|
||||||
g_print("Error: %s\n", err->message);
|
|
||||||
g_error_free(err);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean on_gst_message(GstBus *bus, GstMessage *message, gpointer data)
|
|
||||||
{
|
|
||||||
switch (GST_MESSAGE_TYPE(message)) {
|
|
||||||
case GST_MESSAGE_ERROR:
|
|
||||||
if (parse_gst_error(message) < 0)
|
|
||||||
break;
|
|
||||||
audio_next();
|
|
||||||
gst :: play();
|
|
||||||
break;
|
|
||||||
case GST_MESSAGE_EOS:
|
|
||||||
audio_eos();
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool on_seek(Gtk::ScrollType type, double value)
|
static bool on_seek(Gtk::ScrollType type, double value)
|
||||||
{
|
{
|
||||||
audio_seek(value);
|
audio_seek(value);
|
||||||
|
@ -229,7 +188,5 @@ void gst :: init_pre()
|
||||||
|
|
||||||
void gst :: init()
|
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);
|
Glib :: signal_timeout().connect(sigc::ptr_fun(on_timeout), 500);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue