823
823
static gchar *FIXME_find_sink_file() {
824
824
// FIXME because this function pokes directly pulseaudio's config file.
825
// We should not do this! Do not even mension you've seen this horrible piece of code ;-)
825
// We should not do this! Do not even mension you've seen this horrible piece of code ;-)
827
// The question is: How to find default (or running) sink-device by using GStreamer functions?
827
// The question is: How to find default (or running) sink-device by using GStreamer functions?
828
828
// Please tell me if you know.
830
830
// $ pactl list | grep -A6 State
832
832
// State: RUNNING
833
// Name: alsa_output.pci-0000_00_1b.0.analog-stereo
834
// Description: Built-in Audio Analog Stereo
836
#define PULSEAUDIO_LOCAL_CONFIG ".config/pulse/"
833
// Name: alsa_output.pci-0000_00_1b.0.analog-stereo
834
// Description: Built-in Audio Analog Stereo
836
#define PULSEAUDIO_LOCAL_CONFIG ".config/pulse/"
838
838
// $ cat ~/.config/pulse/*-default-sink
840
gchar *home = get_home_dir();
840
gchar *home = get_home_dir();
841
841
gchar *path = g_build_path("/", home, PULSEAUDIO_LOCAL_CONFIG, NULL);
842
842
gchar *ret = NULL;
847
847
g_error_free(error);
851
851
const gchar *fname = g_dir_read_name(dir);
854
854
if (g_str_has_suffix(fname, "-default-sink")) {
855
855
ret = g_build_path("/", path, fname, NULL);
859
859
fname = g_dir_read_name(dir);
867
g_dir_close(dir); dir = NULL;
873
874
static gchar *FIXME_get_default_sink_dev() {
874
875
// FIXME because this function pokes directly pulseaudio's config file.
875
876
// We should not do this! Do not even mension you've seen this horrible piece of code ;-)
877
878
// Possible solutions:
878
879
// 1) Create a pipeline with pulsesink element, make it rolling and read its device id (it may still be NULL !).
880
881
// 2) Better idea:
881
882
// Create a pipeline with a LEVEL element for each audio-card (that are .monitor devices). And check if it produces sound (if we find pulse on the pipe).
884
gchar *fname = FIXME_find_sink_file();
885
gchar *fname = FIXME_find_sink_file();
886
887
gchar *sink_dev = NULL;
887
888
GError *error = NULL;
888
889
gsize siz = NULL;
889
890
g_file_get_contents(fname, &sink_dev, &siz, &error);
894
895
g_error_free(error);
897
898
str_trim(sink_dev);
903
904
audiotestsrc wave=sine freq=512 ! audioconvert ! audioresample ! pulsesink
905
gst-launch audiotestsrc ! audioconvert ! pulsesink
906
gst-launch audiotestsrc ! audioconvert ! pulsesink
914
How to find DEFAULT sink-device by using GStreamer functions?
918
GError *error = NULL;
919
GstElement *p = gst_parse_launch("fakesrc ! audioconvert ! audioresample ! pulsesink name=plssnk", &error);
920
gst_element_set_state(p, GST_STATE_PLAYING);
922
GstElement *sink = gst_bin_get_by_name(GST_BIN(p), "plssnk");
925
g_object_get(G_OBJECT(sink), "device", &dev_id, "name", &name, NULL);
927
GValue value = {0, };
928
g_value_init(&value, G_TYPE_STRING);
929
g_object_get_property(G_OBJECT(sink), "device", &value);
931
dev_id = g_value_dup_string(&value);
933
g_value_unset(&value);
937
GstElement *e = gst_element_factory_make("pulsesink", "pulsesink");
938
if (GST_IS_ELEMENT(e)) {
940
g_object_get(G_OBJECT(e), "device", &dev_id, NULL);
943
dev_id = (gchar*)g_object_get(G_OBJECT(e), "device", NULL);
945
GValue value = {0, };
946
g_value_init(&value, G_TYPE_STRING);
947
g_object_get_property(G_OBJECT(e), "device", &value);
949
dev_id = g_value_dup_string(&value);
951
g_value_unset(&value);
953
gst_object_unref(GST_OBJECT(e));
956
g_print("SINK DEVICE=%s - %s\n", dev_id, name);
915
How to find DEFAULT sink-device by using GStreamer functions?
919
GError *error = NULL;
920
GstElement *p = gst_parse_launch("fakesrc ! audioconvert ! audioresample ! pulsesink name=plssnk", &error);
921
gst_element_set_state(p, GST_STATE_PLAYING);
923
GstElement *sink = gst_bin_get_by_name(GST_BIN(p), "plssnk");
926
g_object_get(G_OBJECT(sink), "device", &dev_id, "name", &name, NULL);
928
GValue value = {0, };
929
g_value_init(&value, G_TYPE_STRING);
930
g_object_get_property(G_OBJECT(sink), "device", &value);
932
dev_id = g_value_dup_string(&value);
934
g_value_unset(&value);
938
GstElement *e = gst_element_factory_make("pulsesink", "pulsesink");
939
if (GST_IS_ELEMENT(e)) {
941
g_object_get(G_OBJECT(e), "device", &dev_id, NULL);
944
dev_id = (gchar*)g_object_get(G_OBJECT(e), "device", NULL);
946
GValue value = {0, };
947
g_value_init(&value, G_TYPE_STRING);
948
g_object_get_property(G_OBJECT(e), "device", &value);
950
dev_id = g_value_dup_string(&value);
952
g_value_unset(&value);
954
gst_object_unref(GST_OBJECT(e));
957
g_print("SINK DEVICE=%s - %s\n", dev_id, name);