After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 746762 - alsa: add uri handler
alsa: add uri handler
Status: RESOLVED OBSOLETE
Product: GStreamer
Classification: Platform
Component: gst-plugins-base
1.10.4
Other Linux
: Normal enhancement
: git master
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on: 779765
Blocks:
 
 
Reported: 2015-03-25 16:42 UTC by Marc Leeman
Modified: 2018-11-03 11:36 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
GstUri interface on alsa (17.75 KB, patch)
2015-03-25 16:42 UTC, Marc Leeman
none Details | Review
Add uri handler for alsasrc and alsasink elements (10.68 KB, patch)
2017-03-10 13:05 UTC, Marc Leeman
none Details | Review
Correct pointer (964 bytes, patch)
2017-04-18 10:22 UTC, Marc Leeman
none Details | Review
alsa: add uri-handler for src/sink (10.72 KB, patch)
2018-10-27 12:33 UTC, Marc Leeman
none Details | Review
alsasrc/sink: add uri-handler (10.72 KB, patch)
2018-10-27 12:46 UTC, Marc Leeman
none Details | Review
[PATCH] Add uri handler for alsasrc and alsasink elements (10.72 KB, patch)
2018-10-30 13:12 UTC, Marc Leeman
none Details | Review

Description Marc Leeman 2015-03-25 16:42:56 UTC
Created attachment 300296 [details] [review]
GstUri interface on alsa

Add a uri interface to alsa.

Code was written against 1.4.5 (after being used internally for 2 years) with gsturi from git (in gstreamer-core).
Comment 1 Tim-Philipp Müller 2015-03-30 11:01:34 UTC
Comment on attachment 300296 [details] [review]
GstUri interface on alsa

Why do we need the "uri" property here in addition to the uri handler?

That gst_barco_*() functionality should obviously live somewhere in core if we want to support that kind of thing.
Comment 2 Marc Leeman 2015-03-30 13:49:51 UTC
yes, the gst_barco_ stuff is copied in different places throughout the uri patches I submitted. 

I msg'd Sebastian about this, but I do not quite know where to put it just yet.

@uri: consistency: though it is often used with autoplugging, the uri property allows to test the same on a much lower level with the same input.
Comment 3 Marc Leeman 2015-04-16 10:19:51 UTC
ah yeah, the g_hash_table_destroy needs to be g_hash_table_unref
Comment 4 Marc Leeman 2017-03-10 13:05:58 UTC
Created attachment 347629 [details] [review]
Add uri handler for alsasrc and alsasink elements
Comment 5 Nicolas Dufresne (ndufresne) 2017-03-10 21:36:55 UTC
Review of attachment 347629 [details] [review]:

::: ext/alsa/gstalsasink.c
@@ +81,3 @@
+    gst_alsasink_init_interfaces (g_define_type_id);
+    G_IMPLEMENT_INTERFACE (GST_TYPE_URI_HANDLER,
+        gst_alsasink_uri_handler_init));

None sense, this is a sink.

::: ext/alsa/gstalsasrc.c
@@ +201,3 @@
+          gst_uri_unref (src->uri);
+
+        src->uri = gst_uri_from_string (g_value_get_string (value));

May fail.

@@ +203,3 @@
+        src->uri = gst_uri_from_string (g_value_get_string (value));
+
+        gst_object_set_properties_from_uri_query_parameters (G_OBJECT (src), src->uri);

Need filtering, at least device.

@@ +236,3 @@
+        gchar *string = gst_uri_to_string (src->uri);
+
+        g_value_set_string (value, string);

g_value_take_string() please.
Comment 6 Marc Leeman 2017-04-18 10:22:03 UTC
Created attachment 349987 [details] [review]
Correct pointer
Comment 7 Marc Leeman 2018-10-27 12:33:43 UTC
Created attachment 374061 [details] [review]
alsa: add uri-handler for src/sink
Comment 8 Marc Leeman 2018-10-27 12:46:18 UTC
Created attachment 374062 [details] [review]
alsasrc/sink: add uri-handler

used self iso src
Comment 9 Marc Leeman 2018-10-27 12:47:02 UTC
Comment on attachment 374061 [details] [review]
alsa: add uri-handler for src/sink

>From a1363dbf5b11fdf66c1ab9a5c8bd882dd1c75b81 Mon Sep 17 00:00:00 2001
>From: Paul HENRYS <visechelle@gmail.com>
>Date: Thu, 21 Mar 2013 17:14:36 +0100
>Subject: [PATCH] Add uri handler for alsasrc and alsasink elements
>
>The chosen scheme is "alsa://"
>
>Signed-off-by: Marc Leeman <marc.leeman@gmail.com>
>---
> ext/alsa/gstalsasink.c | 86 ++++++++++++++++++++++++++++++++++++++++++++++++--
> ext/alsa/gstalsasink.h |  4 ++-
> ext/alsa/gstalsasrc.c  | 86 ++++++++++++++++++++++++++++++++++++++++++++++++--
> ext/alsa/gstalsasrc.h  |  3 ++
> 4 files changed, 174 insertions(+), 5 deletions(-)
>
>diff --git a/ext/alsa/gstalsasink.c b/ext/alsa/gstalsasink.c
>index e1bb7d7eb..8c0bf1aec 100644
>--- a/ext/alsa/gstalsasink.c
>+++ b/ext/alsa/gstalsasink.c
>@@ -58,6 +58,7 @@
> #define ESTRPIPE EPIPE
> #endif
> 
>+#define DEFAULT_PROP_URI	"alsa://default"
> #define DEFAULT_DEVICE		"default"
> #define DEFAULT_DEVICE_NAME	""
> #define DEFAULT_CARD_NAME	""
>@@ -70,13 +71,18 @@ enum
>   PROP_DEVICE,
>   PROP_DEVICE_NAME,
>   PROP_CARD_NAME,
>+  PROP_URI,
>   PROP_LAST
> };
> 
> static void gst_alsasink_init_interfaces (GType type);
>+static void gst_alsasink_uri_handler_init (gpointer g_iface,
>+    gpointer iface_data);
> #define gst_alsasink_parent_class parent_class
>-G_DEFINE_TYPE_WITH_CODE (GstAlsaSink, gst_alsasink,
>-    GST_TYPE_AUDIO_SINK, gst_alsasink_init_interfaces (g_define_type_id));
>+G_DEFINE_TYPE_WITH_CODE (GstAlsaSink, gst_alsasink, GST_TYPE_AUDIO_SINK,
>+    gst_alsasink_init_interfaces (g_define_type_id);
>+    G_IMPLEMENT_INTERFACE (GST_TYPE_URI_HANDLER,
>+        gst_alsasink_uri_handler_init));
> 
> static void gst_alsasink_finalise (GObject * object);
> static void gst_alsasink_set_property (GObject * object,
>@@ -120,6 +126,9 @@ gst_alsasink_finalise (GObject * object)
> {
>   GstAlsaSink *sink = GST_ALSA_SINK (object);
> 
>+  if (sink->uri)
>+    gst_uri_unref(sink->uri);
>+
>   g_free (sink->device);
>   g_mutex_clear (&sink->alsa_lock);
>   g_mutex_clear (&sink->delay_lock);
>@@ -184,6 +193,11 @@ gst_alsasink_class_init (GstAlsaSinkClass * klass)
>   gstaudiosink_class->delay = GST_DEBUG_FUNCPTR (gst_alsasink_delay);
>   gstaudiosink_class->reset = GST_DEBUG_FUNCPTR (gst_alsasink_reset);
> 
>+  g_object_class_install_property (gobject_class, PROP_URI,
>+      g_param_spec_string ("uri", "URI",
>+          "URI (e.g.: alsa:///default?card-name=generic)",
>+          DEFAULT_PROP_URI, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
>+
>   g_object_class_install_property (gobject_class, PROP_DEVICE,
>       g_param_spec_string ("device", "Device",
>           "ALSA device, as defined in an asound configuration file",
>@@ -209,6 +223,22 @@ gst_alsasink_set_property (GObject * object, guint prop_id,
>   sink = GST_ALSA_SINK (object);
> 
>   switch (prop_id) {
>+    case PROP_URI: {
>+        gchar *path;
>+        if (sink->uri)
>+          gst_uri_unref (sink->uri);
>+
>+        sink->uri = gst_uri_from_string (g_value_get_string (value));
>+        if (sink->uri) {
>+          gst_object_set_properties_from_uri_query_parameters (G_OBJECT (sink), sink->uri);
>+          path = gst_uri_get_path (sink->uri);
>+          if (0 != *(path))
>+            g_object_set (G_OBJECT (sink),
>+                "device", path, NULL);
>+          g_free (path);
>+        }
>+      }
>+      break;
>     case PROP_DEVICE:
>       g_free (sink->device);
>       sink->device = g_value_dup_string (value);
>@@ -232,6 +262,12 @@ gst_alsasink_get_property (GObject * object, guint prop_id,
>   sink = GST_ALSA_SINK (object);
> 
>   switch (prop_id) {
>+    case PROP_URI: {
>+      if (self->uri)
>+        g_value_take_string (value, gst_uri_to_string (self->uri));
>+      else
>+        g_value_set_string (value, NULL);
>+      break;
>     case PROP_DEVICE:
>       g_value_set_string (value, sink->device);
>       break;
>@@ -256,6 +292,7 @@ gst_alsasink_init (GstAlsaSink * alsasink)
> {
>   GST_DEBUG_OBJECT (alsasink, "initializing alsasink");
> 
>+  alsasink->uri = gst_uri_from_string(DEFAULT_PROP_URI);
>   alsasink->device = g_strdup (DEFAULT_DEVICE);
>   alsasink->handle = NULL;
>   alsasink->cached_caps = NULL;
>@@ -1178,3 +1215,48 @@ gst_alsasink_payload (GstAudioBaseSink * sink, GstBuffer * buf)
> 
>   return gst_buffer_ref (buf);
> }
>+
>+/* GstURIHandler interface */
>+static GstURIType
>+gst_alsasink_uri_get_type (GType type)
>+{
>+  return GST_URI_SINK;
>+}
>+
>+static const gchar *const *
>+gst_alsasink_uri_get_protocols (GType type)
>+{
>+  static const gchar *protocols[] = { "alsa", NULL };
>+
>+  return protocols;
>+}
>+
>+static gchar *
>+gst_alsasink_uri_get_uri (GstURIHandler * handler)
>+{
>+  GstAlsaSink *alsasink = GST_ALSA_SINK (handler);
>+
>+  return gst_uri_to_string (alsasink->uri);
>+}
>+
>+static gboolean
>+gst_alsasink_uri_set_uri (GstURIHandler * handler, const gchar * uri,
>+    GError ** error)
>+{
>+  GstAlsaSink *alsasink = GST_ALSA_SINK (handler);
>+
>+  g_object_set (G_OBJECT (alsasink), "uri", uri, NULL);
>+
>+  return TRUE;
>+}
>+
>+static void
>+gst_alsasink_uri_handler_init (gpointer g_iface, gpointer iface_data)
>+{
>+  GstURIHandlerInterface *iface = (GstURIHandlerInterface *) g_iface;
>+
>+  iface->get_type = gst_alsasink_uri_get_type;
>+  iface->get_protocols = gst_alsasink_uri_get_protocols;
>+  iface->get_uri = gst_alsasink_uri_get_uri;
>+  iface->set_uri = gst_alsasink_uri_set_uri;
>+}
>diff --git a/ext/alsa/gstalsasink.h b/ext/alsa/gstalsasink.h
>index b240fe43d..65b94ffb4 100644
>--- a/ext/alsa/gstalsasink.h
>+++ b/ext/alsa/gstalsasink.h
>@@ -1,7 +1,7 @@
> /* GStreamer
>  * Copyright (C)  2005 Wim Taymans <wim@fluendo.com>
>  *
>- * gstalsasink.h: 
>+ * gstalsasink.h:
>  *
>  * This library is free software; you can redistribute it and/or
>  * modify it under the terms of the GNU Library General Public
>@@ -24,6 +24,7 @@
> #define __GST_ALSASINK_H__
> 
> #include <gst/gst.h>
>+#include <gst/gsturi.h>
> #include <gst/audio/audio.h>
> #include <alsa/asoundlib.h>
> 
>@@ -55,6 +56,7 @@ typedef struct _GstAlsaSinkClass GstAlsaSinkClass;
> struct _GstAlsaSink {
>   GstAudioSink    sink;
> 
>+  GstUri                *uri;
>   gchar                 *device;
> 
>   snd_pcm_t             *handle;
>diff --git a/ext/alsa/gstalsasrc.c b/ext/alsa/gstalsasrc.c
>index 6ee0ca887..808c3dc1c 100644
>--- a/ext/alsa/gstalsasrc.c
>+++ b/ext/alsa/gstalsasrc.c
>@@ -54,6 +54,7 @@
> #define ESTRPIPE EPIPE
> #endif
> 
>+#define DEFAULT_PROP_URI		"alsa://default"
> #define DEFAULT_PROP_DEVICE		"default"
> #define DEFAULT_PROP_DEVICE_NAME	""
> #define DEFAULT_PROP_CARD_NAME	        ""
>@@ -64,11 +65,18 @@ enum
>   PROP_DEVICE,
>   PROP_DEVICE_NAME,
>   PROP_CARD_NAME,
>+  PROP_URI,
>   PROP_LAST
> };
> 
>+static void gst_alsasrc_uri_handler_init (gpointer g_iface,
>+    gpointer iface_data);
>+
> #define gst_alsasrc_parent_class parent_class
>-G_DEFINE_TYPE (GstAlsaSrc, gst_alsasrc, GST_TYPE_AUDIO_SRC);
>+G_DEFINE_TYPE_WITH_CODE (GstAlsaSrc, gst_alsasrc, GST_TYPE_AUDIO_SRC,
>+    G_IMPLEMENT_INTERFACE (GST_TYPE_URI_HANDLER, gst_alsasrc_uri_handler_init));
>+
>+
> 
> static void gst_alsasrc_finalize (GObject * object);
> static void gst_alsasrc_set_property (GObject * object,
>@@ -115,7 +123,8 @@ static void
> gst_alsasrc_finalize (GObject * object)
> {
>   GstAlsaSrc *src = GST_ALSA_SRC (object);
>-
>+  if (src->uri)
>+    gst_uri_unref(src->uri);
>   g_free (src->device);
>   g_mutex_clear (&src->alsa_lock);
> 
>@@ -157,6 +166,11 @@ gst_alsasrc_class_init (GstAlsaSrcClass * klass)
>   gstaudiosrc_class->reset = GST_DEBUG_FUNCPTR (gst_alsasrc_reset);
>   gstelement_class->change_state = GST_DEBUG_FUNCPTR (gst_alsasrc_change_state);
> 
>+  g_object_class_install_property (gobject_class, PROP_URI,
>+      g_param_spec_string ("uri", "URI",
>+          "URI (e.g.: alsa:///default?card-name=generic)",
>+          DEFAULT_PROP_URI, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
>+
>   g_object_class_install_property (gobject_class, PROP_DEVICE,
>       g_param_spec_string ("device", "Device",
>           "ALSA device, as defined in an asound configuration file",
>@@ -182,6 +196,22 @@ gst_alsasrc_set_property (GObject * object, guint prop_id,
>   src = GST_ALSA_SRC (object);
> 
>   switch (prop_id) {
>+    case PROP_URI: {
>+        gchar *path;
>+        if (src->uri)
>+          gst_uri_unref (src->uri);
>+
>+        src->uri = gst_uri_from_string (g_value_get_string (value));
>+        if (src->uri) {
>+          gst_object_set_properties_from_uri_query_parameters (G_OBJECT (src), src->uri);
>+          path = gst_uri_get_path (src->uri);
>+          if (0 != *(path))
>+            g_object_set (G_OBJECT (src),
>+                "device", path, NULL);
>+          g_free (path);
>+        }
>+      }
>+      break;
>     case PROP_DEVICE:
>       g_free (src->device);
>       src->device = g_value_dup_string (value);
>@@ -204,6 +234,12 @@ gst_alsasrc_get_property (GObject * object, guint prop_id,
>   src = GST_ALSA_SRC (object);
> 
>   switch (prop_id) {
>+    case PROP_URI: {
>+      if (self->uri)
>+        g_value_take_string (value, gst_uri_to_string (self->uri));
>+      else
>+        g_value_set_string (value, NULL);
>+      break;
>     case PROP_DEVICE:
>       g_value_set_string (value, src->device);
>       break;
>@@ -270,6 +306,7 @@ gst_alsasrc_init (GstAlsaSrc * alsasrc)
> {
>   GST_DEBUG_OBJECT (alsasrc, "initializing");
> 
>+  alsasrc->uri = gst_uri_from_string(DEFAULT_PROP_URI);
>   alsasrc->device = g_strdup (DEFAULT_PROP_DEVICE);
>   alsasrc->cached_caps = NULL;
>   alsasrc->driver_timestamps = FALSE;
>@@ -1048,3 +1085,48 @@ prepare_error:
>     return;
>   }
> }
>+
>+/* GstURIHandler interface */
>+static GstURIType
>+gst_alsasrc_uri_get_type (GType type)
>+{
>+  return GST_URI_SRC;
>+}
>+
>+static const gchar *const *
>+gst_alsasrc_uri_get_protocols (GType type)
>+{
>+  static const gchar *protocols[] = { "alsa", NULL };
>+
>+  return protocols;
>+}
>+
>+static gchar *
>+gst_alsasrc_uri_get_uri (GstURIHandler * handler)
>+{
>+  GstAlsaSrc *alsasrc = GST_ALSA_SRC (handler);
>+
>+  return gst_uri_to_string (alsasrc->uri);
>+}
>+
>+static gboolean
>+gst_alsasrc_uri_set_uri (GstURIHandler * handler, const gchar * uri,
>+    GError ** error)
>+{
>+  GstAlsaSrc *alsasrc = GST_ALSA_SRC (handler);
>+
>+  g_object_set (G_OBJECT (alsasrc), "uri", uri, NULL);
>+
>+  return TRUE;
>+}
>+
>+static void
>+gst_alsasrc_uri_handler_init (gpointer g_iface, gpointer iface_data)
>+{
>+  GstURIHandlerInterface *iface = (GstURIHandlerInterface *) g_iface;
>+
>+  iface->get_type = gst_alsasrc_uri_get_type;
>+  iface->get_protocols = gst_alsasrc_uri_get_protocols;
>+  iface->get_uri = gst_alsasrc_uri_get_uri;
>+  iface->set_uri = gst_alsasrc_uri_set_uri;
>+}
>diff --git a/ext/alsa/gstalsasrc.h b/ext/alsa/gstalsasrc.h
>index 57e27015a..5e00d4f63 100644
>--- a/ext/alsa/gstalsasrc.h
>+++ b/ext/alsa/gstalsasrc.h
>@@ -23,6 +23,8 @@
> #ifndef __GST_ALSASRC_H__
> #define __GST_ALSASRC_H__
> 
>+#include <gst/gst.h>
>+#include <gst/gsturi.h>
> #include <gst/audio/audio.h>
> #include "gstalsa.h"
> 
>@@ -50,6 +52,7 @@ typedef struct _GstAlsaSrcClass GstAlsaSrcClass;
> struct _GstAlsaSrc {
>   GstAudioSrc           src;
> 
>+  GstUri                *uri;
>   gchar                 *device;
> 
>   snd_pcm_t             *handle;
>-- 
>2.16.3
>
Comment 10 Marc Leeman 2018-10-30 13:12:27 UTC
Created attachment 374110 [details] [review]
[PATCH] Add uri handler for alsasrc and alsasink elements

typos fixed.
Comment 11 GStreamer system administrator 2018-11-03 11:36:26 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to freedesktop.org's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/issues/176.