summaryrefslogtreecommitdiff
path: root/backends
diff options
context:
space:
mode:
authorMichal Ratajsky <[email protected]>2014-10-31 14:39:11 +0100
committerMichal Ratajsky <[email protected]>2014-10-31 14:39:11 +0100
commit1897445a80677ec89e7eef9f2a76e630fd088588 (patch)
tree378995fb00ace7e3f338351176433b52f6372d7e /backends
parentb839e8ca0c73f9715654497e241d4aa3e3042125 (diff)
downloadlibmatemixer-1897445a80677ec89e7eef9f2a76e630fd088588.tar.bz2
libmatemixer-1897445a80677ec89e7eef9f2a76e630fd088588.tar.xz
oss: Improve *_list_streams functions and handling of device streams
Makes the functions compatible with the ALSA code. As streams in OSS are not dynamic elements, they are removed as soon as they are known to be useless.
Diffstat (limited to 'backends')
-rw-r--r--backends/oss/oss-backend.c20
-rw-r--r--backends/oss/oss-device.c68
2 files changed, 51 insertions, 37 deletions
diff --git a/backends/oss/oss-backend.c b/backends/oss/oss-backend.c
index 78ed69b..eb4d742 100644
--- a/backends/oss/oss-backend.c
+++ b/backends/oss/oss-backend.c
@@ -268,23 +268,23 @@ oss_backend_list_streams (MateMixerBackend *backend)
/* Walk through the list of devices and create the stream list, each
* device has at most one input and one output stream */
- list = oss->priv->devices;
+ list = g_list_last (oss->priv->devices);
while (list != NULL) {
OssDevice *device = OSS_DEVICE (list->data);
OssStream *stream;
- stream = oss_device_get_input_stream (device);
- if (stream != NULL) {
- oss->priv->streams =
- g_list_append (oss->priv->streams, g_object_ref (stream));
- }
stream = oss_device_get_output_stream (device);
- if (stream != NULL) {
+ if (stream != NULL)
oss->priv->streams =
- g_list_append (oss->priv->streams, g_object_ref (stream));
- }
- list = list->next;
+ g_list_prepend (oss->priv->streams, g_object_ref (stream));
+
+ stream = oss_device_get_input_stream (device);
+ if (stream != NULL)
+ oss->priv->streams =
+ g_list_prepend (oss->priv->streams, g_object_ref (stream));
+
+ list = list->prev;
}
}
return oss->priv->streams;
diff --git a/backends/oss/oss-device.c b/backends/oss/oss-device.c
index 44ed18f..0c5f3f3 100644
--- a/backends/oss/oss-device.c
+++ b/backends/oss/oss-device.c
@@ -278,7 +278,6 @@ oss_device_new (const gchar *name,
gint fd)
{
OssDevice *device;
- gchar *stream_name;
g_return_val_if_fail (name != NULL, NULL);
g_return_val_if_fail (label != NULL, NULL);
@@ -293,18 +292,6 @@ oss_device_new (const gchar *name,
device->priv->fd = dup (fd);
device->priv->path = g_strdup (path);
- stream_name = g_strdup_printf ("oss-input-%s", name);
- device->priv->input = oss_stream_new (stream_name,
- MATE_MIXER_DEVICE (device),
- MATE_MIXER_DIRECTION_INPUT);
- g_free (stream_name);
-
- stream_name = g_strdup_printf ("oss-output-%s", name);
- device->priv->output = oss_stream_new (stream_name,
- MATE_MIXER_DEVICE (device),
- MATE_MIXER_DIRECTION_OUTPUT);
- g_free (stream_name);
-
return device;
}
@@ -370,7 +357,7 @@ oss_device_close (OssDevice *device)
return;
/* Make each stream remove its controls and switch */
- if (oss_stream_has_controls (device->priv->input) == TRUE) {
+ if (device->priv->input != NULL) {
const gchar *name =
mate_mixer_stream_get_name (MATE_MIXER_STREAM (device->priv->input));
@@ -380,9 +367,11 @@ oss_device_close (OssDevice *device)
g_signal_emit_by_name (G_OBJECT (device),
"stream-removed",
name);
+
+ g_clear_object (&device->priv->input);
}
- if (oss_stream_has_controls (device->priv->output) == TRUE) {
+ if (device->priv->output != NULL) {
const gchar *name =
mate_mixer_stream_get_name (MATE_MIXER_STREAM (device->priv->output));
@@ -392,6 +381,8 @@ oss_device_close (OssDevice *device)
g_signal_emit_by_name (G_OBJECT (device),
"stream-removed",
name);
+
+ g_clear_object (&device->priv->output);
}
if (device->priv->poll_tag != 0)
@@ -410,10 +401,26 @@ void
oss_device_load (OssDevice *device)
{
const GList *controls;
+ const gchar *name;
+ gchar *stream_name;
guint i;
g_return_if_fail (OSS_IS_DEVICE (device));
+ name = mate_mixer_device_get_name (MATE_MIXER_DEVICE (device));
+
+ stream_name = g_strdup_printf ("oss-input-%s", name);
+ device->priv->input = oss_stream_new (stream_name,
+ MATE_MIXER_DEVICE (device),
+ MATE_MIXER_DIRECTION_INPUT);
+ g_free (stream_name);
+
+ stream_name = g_strdup_printf ("oss-output-%s", name);
+ device->priv->output = oss_stream_new (stream_name,
+ MATE_MIXER_DEVICE (device),
+ MATE_MIXER_DIRECTION_OUTPUT);
+ g_free (stream_name);
+
read_mixer_devices (device);
/* Set default input control */
@@ -431,7 +438,12 @@ oss_device_load (OssDevice *device)
OSS_STREAM_CONTROL (item->data));
break;
}
- }
+
+ /* Create an input switch for recording sources */
+ if (device->priv->recmask != 0)
+ read_mixer_switch (device);
+ } else
+ g_clear_object (&device->priv->input);
/* Set default output control */
if (oss_stream_has_controls (device->priv->output) == TRUE) {
@@ -448,10 +460,8 @@ oss_device_load (OssDevice *device)
OSS_STREAM_CONTROL (item->data));
break;
}
- }
-
- if (device->priv->recmask != 0)
- read_mixer_switch (device);
+ } else
+ g_clear_object (&device->priv->output);
/* See if we can use the modify_counter field to optimize polling */
#ifdef SOUND_MIXER_INFO
@@ -519,6 +529,7 @@ oss_device_list_streams (MateMixerDevice *mmd)
if (device->priv->output != NULL)
device->priv->streams = g_list_prepend (device->priv->streams,
g_object_ref (device->priv->output));
+
if (device->priv->input != NULL)
device->priv->streams = g_list_prepend (device->priv->streams,
g_object_ref (device->priv->input));
@@ -551,7 +562,8 @@ read_mixer_devices (OssDevice *device)
stream = device->priv->output;
stereo = OSS_MASK_HAS_DEVICE (device->priv->stereodevs, i);
- control = oss_stream_control_new (oss_devices[i].name, gettext (oss_devices[i].label),
+ control = oss_stream_control_new (oss_devices[i].name,
+ gettext (oss_devices[i].label),
oss_devices[i].role,
stream,
device->priv->fd,
@@ -591,7 +603,8 @@ read_mixer_switch (OssDevice *device)
for (i = 0; i < OSS_N_DEVICES; i++) {
OssSwitchOption *option;
- if (OSS_MASK_HAS_DEVICE (device->priv->recmask, i) == FALSE)
+ if (OSS_MASK_HAS_DEVICE (device->priv->devmask, i) == FALSE ||
+ OSS_MASK_HAS_DEVICE (device->priv->recmask, i) == FALSE)
continue;
option = oss_switch_option_new (oss_devices[i].name,
@@ -642,17 +655,18 @@ poll_mixer (OssDevice *device)
return G_SOURCE_REMOVE;
}
- if (device->priv->poll_counter < info.modify_counter) {
+ if (device->priv->poll_counter < info.modify_counter)
device->priv->poll_counter = info.modify_counter;
- } else {
+ else
load = FALSE;
- }
}
#endif
if (load == TRUE) {
- oss_stream_load (device->priv->input);
- oss_stream_load (device->priv->output);
+ if (device->priv->input != NULL)
+ oss_stream_load (device->priv->input);
+ if (device->priv->output != NULL)
+ oss_stream_load (device->priv->output);
if (device->priv->poll_use_counter == TRUE &&
device->priv->poll_mode == OSS_POLL_NORMAL) {