2012-02-01 08:29:25 -05:00
|
|
|
// Copyright (c) 2012 Bryan Schumaker.
|
2012-11-08 08:09:05 -05:00
|
|
|
//#include <gst/interfaces/propertyprobe.h>
|
2012-09-12 08:15:31 -04:00
|
|
|
#include <audio.h>
|
|
|
|
#include <prefs.h>
|
|
|
|
#include <print.h>
|
2012-02-01 08:29:25 -05:00
|
|
|
#include "audio.h"
|
|
|
|
|
|
|
|
#include <list>
|
|
|
|
using namespace std;
|
|
|
|
|
2012-03-22 08:32:26 -04:00
|
|
|
//static GstElement *alsa = NULL;
|
2012-02-01 08:29:25 -05:00
|
|
|
static list<string> devices;
|
2012-02-09 08:04:52 -05:00
|
|
|
gulong about_to_finish_id;
|
2012-03-22 08:32:26 -04:00
|
|
|
/*
|
2012-02-09 08:04:52 -05:00
|
|
|
static void about_to_finish(GstElement *playbin, gpointer data)
|
|
|
|
{
|
|
|
|
string file;
|
|
|
|
|
|
|
|
println("About to finish!");
|
2012-03-18 10:01:36 -04:00
|
|
|
//file = libsaria::next_file();
|
2012-02-09 08:04:52 -05:00
|
|
|
if (file != "")
|
|
|
|
load_file(playbin, file);
|
|
|
|
}
|
2012-02-01 08:29:25 -05:00
|
|
|
|
|
|
|
static void probe_devices()
|
|
|
|
{
|
|
|
|
GValueArray *array;
|
|
|
|
GValue *value;
|
|
|
|
|
|
|
|
devices.clear();
|
|
|
|
array = gst_property_probe_probe_and_get_values_name(GST_PROPERTY_PROBE(alsa), "device");
|
|
|
|
|
|
|
|
devices.push_back("default");
|
|
|
|
for (unsigned int i = 0; i < array->n_values; i++) {
|
|
|
|
value = g_value_array_get_nth(array, i);
|
|
|
|
devices.push_back(g_value_get_string(value));
|
|
|
|
}
|
2012-02-10 08:29:13 -05:00
|
|
|
|
|
|
|
g_value_array_free(array);
|
2012-02-01 08:29:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void set_alsa_device(string device)
|
|
|
|
{
|
|
|
|
g_object_set(G_OBJECT(alsa), "device", device.c_str(), NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void add_alsa()
|
|
|
|
{
|
|
|
|
println("Adding ALSA");
|
|
|
|
alsa = gst_element_factory_make("alsasink", "alsa");
|
|
|
|
probe_devices();
|
|
|
|
set_audio_sink(alsa);
|
2012-02-09 08:04:52 -05:00
|
|
|
about_to_finish_id = g_signal_connect(player,
|
|
|
|
"about-to-finish",
|
|
|
|
G_CALLBACK(about_to_finish),
|
|
|
|
NULL);
|
2012-02-01 08:29:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void remove_alsa()
|
|
|
|
{
|
|
|
|
println("Removing ALSA");
|
2012-02-09 08:04:52 -05:00
|
|
|
g_signal_handler_disconnect(player, about_to_finish_id);
|
2012-03-22 08:32:26 -04:00
|
|
|
set_alsa_device("default");*/
|
2012-02-01 08:29:25 -05:00
|
|
|
/* Removing the sink will also deallocate it */
|
2012-03-22 08:32:26 -04:00
|
|
|
/* set_audio_sink(NULL);
|
|
|
|
}*/
|
2012-02-01 08:29:25 -05:00
|
|
|
|
|
|
|
namespace libsaria
|
|
|
|
{
|
|
|
|
|
2012-03-22 08:32:26 -04:00
|
|
|
/*void audio::use_alsa(bool use)
|
2012-02-01 08:29:25 -05:00
|
|
|
{
|
|
|
|
struct StoredAudioState state;
|
|
|
|
save_audio_state(&state);
|
|
|
|
|
|
|
|
if (use == true)
|
|
|
|
add_alsa();
|
|
|
|
else
|
|
|
|
remove_alsa();
|
|
|
|
|
|
|
|
load_audio_state(&state);
|
|
|
|
prefs::set("alsa", use);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool audio::using_alsa()
|
|
|
|
{
|
2012-03-10 11:44:04 -05:00
|
|
|
return false;
|
|
|
|
//return prefs::get_bool("alsa");
|
2012-02-01 08:29:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void audio::init_alsa()
|
|
|
|
{
|
2012-02-10 08:28:08 -05:00
|
|
|
if (using_alsa())
|
|
|
|
add_alsa();
|
2012-02-01 08:29:25 -05:00
|
|
|
}
|
|
|
|
|
2012-02-10 08:27:29 -05:00
|
|
|
void audio::quit_alsa()
|
|
|
|
{
|
|
|
|
if (using_alsa())
|
|
|
|
remove_alsa();
|
|
|
|
}
|
|
|
|
|
2012-02-01 08:29:25 -05:00
|
|
|
list<string> *audio::get_alsa_devices()
|
|
|
|
{
|
|
|
|
return &devices;
|
|
|
|
}
|
|
|
|
|
|
|
|
void audio::set_device(string &device)
|
|
|
|
{
|
|
|
|
struct StoredAudioState state;
|
|
|
|
|
|
|
|
save_audio_state(&state);
|
|
|
|
g_object_set(G_OBJECT(alsa), "device", device.c_str(), NULL);
|
|
|
|
load_audio_state(&state);
|
2012-03-22 08:32:26 -04:00
|
|
|
}*/
|
2012-02-01 08:29:25 -05:00
|
|
|
|
|
|
|
}; /* Namespace: libsaria */
|