summaryrefslogtreecommitdiff
path: root/backends/oss/oss-stream.c
diff options
context:
space:
mode:
authorMichal Ratajsky <[email protected]>2014-08-12 04:56:55 +0200
committerMichal Ratajsky <[email protected]>2014-08-12 04:56:55 +0200
commit6c6d4239ddc807e922df3874654f99eea291aadb (patch)
tree558f48fc965476344a946d93088680db3b5bac41 /backends/oss/oss-stream.c
parent8436ec1641eee8868128755f6d1475230cea25e6 (diff)
downloadlibmatemixer-6c6d4239ddc807e922df3874654f99eea291aadb.tar.bz2
libmatemixer-6c6d4239ddc807e922df3874654f99eea291aadb.tar.xz
Add ALSA, improve OSS and remove OSS4
Diffstat (limited to 'backends/oss/oss-stream.c')
-rw-r--r--backends/oss/oss-stream.c266
1 files changed, 67 insertions, 199 deletions
diff --git a/backends/oss/oss-stream.c b/backends/oss/oss-stream.c
index 69bfd06..5f0c629 100644
--- a/backends/oss/oss-stream.c
+++ b/backends/oss/oss-stream.c
@@ -15,301 +15,169 @@
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
-#include <string.h>
#include <glib.h>
#include <glib-object.h>
+#include <libmatemixer/matemixer.h>
-#include <libmatemixer/matemixer-device.h>
-#include <libmatemixer/matemixer-enums.h>
-#include <libmatemixer/matemixer-stream.h>
-
+#include "oss-device.h"
#include "oss-stream.h"
#include "oss-stream-control.h"
struct _OssStreamPrivate
{
- gchar *name;
- gchar *description;
- MateMixerDevice *device;
- MateMixerStreamFlags flags;
- MateMixerStreamState state;
- GHashTable *ports;
- GList *ports_list;
- GHashTable *controls;
- GList *controls_list;
- OssStreamControl *control;
-};
-
-enum {
- PROP_0,
- PROP_NAME,
- PROP_DESCRIPTION,
- PROP_DEVICE,
- PROP_FLAGS,
- PROP_STATE,
- PROP_ACTIVE_PORT,
+ GHashTable *controls;
+ OssStreamControl *control;
};
-static void mate_mixer_stream_interface_init (MateMixerStreamInterface *iface);
-
static void oss_stream_class_init (OssStreamClass *klass);
-static void oss_stream_get_property (GObject *object,
- guint param_id,
- GValue *value,
- GParamSpec *pspec);
-
static void oss_stream_init (OssStream *ostream);
static void oss_stream_dispose (GObject *object);
static void oss_stream_finalize (GObject *object);
-G_DEFINE_TYPE_WITH_CODE (OssStream, oss_stream, G_TYPE_OBJECT,
- G_IMPLEMENT_INTERFACE (MATE_MIXER_TYPE_STREAM,
- mate_mixer_stream_interface_init))
-
-static const gchar * oss_stream_get_name (MateMixerStream *stream);
-static const gchar * oss_stream_get_description (MateMixerStream *stream);
+G_DEFINE_TYPE (OssStream, oss_stream, MATE_MIXER_TYPE_STREAM)
static MateMixerStreamControl *oss_stream_get_control (MateMixerStream *stream,
const gchar *name);
static MateMixerStreamControl *oss_stream_get_default_control (MateMixerStream *stream);
-static const GList * oss_stream_list_controls (MateMixerStream *stream);
-static const GList * oss_stream_list_ports (MateMixerStream *stream);
-
-static void
-mate_mixer_stream_interface_init (MateMixerStreamInterface *iface)
-{
- iface->get_name = oss_stream_get_name;
- iface->get_description = oss_stream_get_description;
- iface->get_control = oss_stream_get_control;
- iface->get_default_control = oss_stream_get_default_control;
- iface->list_controls = oss_stream_list_controls;
- iface->list_ports = oss_stream_list_ports;
-}
+static GList * oss_stream_list_controls (MateMixerStream *stream);
static void
oss_stream_class_init (OssStreamClass *klass)
{
- GObjectClass *object_class;
+ GObjectClass *object_class;
+ MateMixerStreamClass *stream_class;
object_class = G_OBJECT_CLASS (klass);
- object_class->dispose = oss_stream_dispose;
- object_class->finalize = oss_stream_finalize;
- object_class->get_property = oss_stream_get_property;
+ object_class->dispose = oss_stream_dispose;
+ object_class->finalize = oss_stream_finalize;
- g_object_class_override_property (object_class, PROP_NAME, "name");
- g_object_class_override_property (object_class, PROP_DESCRIPTION, "description");
- g_object_class_override_property (object_class, PROP_DEVICE, "device");
- g_object_class_override_property (object_class, PROP_FLAGS, "flags");
- g_object_class_override_property (object_class, PROP_STATE, "state");
- g_object_class_override_property (object_class, PROP_ACTIVE_PORT, "active-port");
+ stream_class = MATE_MIXER_STREAM_CLASS (klass);
+ stream_class->get_control = oss_stream_get_control;
+ stream_class->get_default_control = oss_stream_get_default_control;
+ stream_class->list_controls = oss_stream_list_controls;
g_type_class_add_private (object_class, sizeof (OssStreamPrivate));
}
static void
-oss_stream_get_property (GObject *object,
- guint param_id,
- GValue *value,
- GParamSpec *pspec)
+oss_stream_init (OssStream *stream)
{
- OssStream *ostream;
-
- ostream = OSS_STREAM (object);
-
- switch (param_id) {
- case PROP_NAME:
- g_value_set_string (value, ostream->priv->name);
- break;
- case PROP_DESCRIPTION:
- g_value_set_string (value, ostream->priv->description);
- break;
- case PROP_DEVICE:
- g_value_set_object (value, ostream->priv->device);
- break;
- case PROP_FLAGS:
- g_value_set_flags (value, ostream->priv->flags);
- break;
- case PROP_STATE:
- /* Not supported */
- g_value_set_enum (value, MATE_MIXER_STREAM_STATE_UNKNOWN);
- break;
- case PROP_ACTIVE_PORT:
- // XXX
- g_value_set_object (value, NULL);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
- break;
- }
-}
+ stream->priv = G_TYPE_INSTANCE_GET_PRIVATE (stream,
+ OSS_TYPE_STREAM,
+ OssStreamPrivate);
-static void
-oss_stream_init (OssStream *ostream)
-{
- ostream->priv = G_TYPE_INSTANCE_GET_PRIVATE (ostream,
- OSS_TYPE_STREAM,
- OssStreamPrivate);
-
- ostream->priv->controls = g_hash_table_new_full (g_str_hash,
- g_str_equal,
- g_free,
- g_object_unref);
-
- ostream->priv->ports = g_hash_table_new_full (g_str_hash,
- g_str_equal,
- g_free,
- g_object_unref);
+ stream->priv->controls = g_hash_table_new_full (g_str_hash,
+ g_str_equal,
+ g_free,
+ g_object_unref);
}
static void
oss_stream_dispose (GObject *object)
{
- OssStream *ostream;
+ OssStream *stream;
- ostream = OSS_STREAM (object);
+ stream = OSS_STREAM (object);
- g_hash_table_remove_all (ostream->priv->controls);
- g_hash_table_remove_all (ostream->priv->ports);
+ g_clear_object (&stream->priv->control);
+ g_hash_table_remove_all (stream->priv->controls);
- G_OBJECT_CLASS (oss_stream_parent_class)->finalize (object);
+ G_OBJECT_CLASS (oss_stream_parent_class)->dispose (object);
}
static void
oss_stream_finalize (GObject *object)
{
- OssStream *ostream;
-
- ostream = OSS_STREAM (object);
+ OssStream *stream;
- g_free (ostream->priv->name);
- g_free (ostream->priv->description);
+ stream = OSS_STREAM (object);
- g_hash_table_destroy (ostream->priv->controls);
- g_hash_table_destroy (ostream->priv->ports);
+ g_hash_table_destroy (stream->priv->controls);
G_OBJECT_CLASS (oss_stream_parent_class)->finalize (object);
}
OssStream *
oss_stream_new (const gchar *name,
- const gchar *description,
+ MateMixerDevice *device,
MateMixerStreamFlags flags)
{
OssStream *stream;
- stream = g_object_new (OSS_TYPE_STREAM, NULL);
-
- stream->priv->name = g_strdup (name);
- stream->priv->description = g_strdup (description);
- stream->priv->flags = flags;
-
+ stream = g_object_new (OSS_TYPE_STREAM,
+ "name", name,
+ "device", device,
+ "flags", flags,
+ NULL);
return stream;
}
gboolean
-oss_stream_add_control (OssStream *ostream, OssStreamControl *octl)
+oss_stream_add_control (OssStream *stream, OssStreamControl *control)
{
const gchar *name;
- g_return_val_if_fail (OSS_IS_STREAM (ostream), FALSE);
- g_return_val_if_fail (OSS_IS_STREAM_CONTROL (octl), FALSE);
+ g_return_val_if_fail (OSS_IS_STREAM (stream), FALSE);
+ g_return_val_if_fail (OSS_IS_STREAM_CONTROL (control), FALSE);
- name = mate_mixer_stream_control_get_name (MATE_MIXER_STREAM_CONTROL (octl));
+ name = mate_mixer_stream_control_get_name (MATE_MIXER_STREAM_CONTROL (control));
- g_hash_table_insert (ostream->priv->controls,
+ g_hash_table_insert (stream->priv->controls,
g_strdup (name),
- octl);
+ control);
return TRUE;
}
gboolean
-oss_stream_set_default_control (OssStream *ostream, OssStreamControl *octl)
+oss_stream_set_default_control (OssStream *stream, OssStreamControl *control)
{
- g_return_val_if_fail (OSS_IS_STREAM (ostream), FALSE);
- g_return_val_if_fail (OSS_IS_STREAM_CONTROL (octl), FALSE);
+ g_return_val_if_fail (OSS_IS_STREAM (stream), FALSE);
+ g_return_val_if_fail (OSS_IS_STREAM_CONTROL (control), FALSE);
/* This function is only used internally so avoid validating that the control
* belongs to this stream */
- if (ostream->priv->control != NULL)
- g_object_unref (ostream->priv->control);
-
- ostream->priv->control = g_object_ref (octl);
- return TRUE;
-}
+ if (stream->priv->control != NULL)
+ g_object_unref (stream->priv->control);
-gboolean
-oss_stream_add_port (OssStream *ostream, MateMixerPort *port)
-{
- g_return_val_if_fail (OSS_IS_STREAM (ostream), FALSE);
- g_return_val_if_fail (MATE_MIXER_IS_PORT (port), FALSE);
+ if G_LIKELY (control != NULL)
+ stream->priv->control = g_object_ref (control);
+ else
+ stream->priv->control = NULL;
- g_hash_table_insert (ostream->priv->ports,
- g_strdup (mate_mixer_port_get_name (port)),
- port);
return TRUE;
}
-static const gchar *
-oss_stream_get_name (MateMixerStream *stream)
-{
- g_return_val_if_fail (OSS_IS_STREAM (stream), NULL);
-
- return OSS_STREAM (stream)->priv->name;
-}
-
-static const gchar *
-oss_stream_get_description (MateMixerStream *stream)
-{
- g_return_val_if_fail (OSS_IS_STREAM (stream), NULL);
-
- return OSS_STREAM (stream)->priv->description;
-}
-
static MateMixerStreamControl *
-oss_stream_get_control (MateMixerStream *stream, const gchar *name)
+oss_stream_get_control (MateMixerStream *mms, const gchar *name)
{
- g_return_val_if_fail (OSS_IS_STREAM (stream), NULL);
+ g_return_val_if_fail (OSS_IS_STREAM (mms), NULL);
g_return_val_if_fail (name != NULL, NULL);
- return g_hash_table_lookup (OSS_STREAM (stream)->priv->controls, name);
+ return g_hash_table_lookup (OSS_STREAM (mms)->priv->controls, name);
}
static MateMixerStreamControl *
-oss_stream_get_default_control (MateMixerStream *stream)
-{
- g_return_val_if_fail (OSS_IS_STREAM (stream), NULL);
-
- return MATE_MIXER_STREAM_CONTROL (OSS_STREAM (stream)->priv->control);
-}
-
-static const GList *
-oss_stream_list_controls (MateMixerStream *stream)
+oss_stream_get_default_control (MateMixerStream *mms)
{
- OssStream *ostream;
-
- g_return_val_if_fail (OSS_IS_STREAM (stream), NULL);
-
- ostream = OSS_STREAM (stream);
+ g_return_val_if_fail (OSS_IS_STREAM (mms), NULL);
- if (ostream->priv->controls_list == NULL)
- ostream->priv->controls_list = g_hash_table_get_values (ostream->priv->controls);
-
- return ostream->priv->controls_list;
+ return MATE_MIXER_STREAM_CONTROL (OSS_STREAM (mms)->priv->control);
}
-static const GList *
-oss_stream_list_ports (MateMixerStream *stream)
+static GList *
+oss_stream_list_controls (MateMixerStream *mms)
{
- OssStream *ostream;
-
- g_return_val_if_fail (OSS_IS_STREAM (stream), NULL);
+ GList *list;
- ostream = OSS_STREAM (stream);
+ g_return_val_if_fail (OSS_IS_STREAM (mms), NULL);
- if (ostream->priv->ports_list == NULL)
- ostream->priv->ports_list = g_hash_table_get_values (ostream->priv->ports);
+ /* Convert the hash table to a linked list, this list is expected to be
+ * cached in the main library */
+ list = g_hash_table_get_values (OSS_STREAM (mms)->priv->controls);
+ if (list != NULL)
+ g_list_foreach (list, (GFunc) g_object_ref, NULL);
- return ostream->priv->ports_list;
+ return list;
}