// Copyright (c) 2012 Bryan Schumaker. #include #include #include #include #include "audio.h" #include using namespace std; static GstElement *alsa = NULL; static list devices; 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)); } } 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); } static void remove_alsa() { println("Removing ALSA"); set_alsa_device("default"); /* Removing the sink will also deallocate it */ set_audio_sink(NULL); } namespace libsaria { void audio::use_alsa(bool use) { 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() { return prefs::get_bool("alsa"); } void audio::init_alsa() { use_alsa(using_alsa()); } list *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); } }; /* Namespace: libsaria */