Re: [pulseaudio-discuss] [PATCH 1/2] alsa: add jack detection support

2011-05-20 Thread Jorge Eduardo Candelaria

On May 19, 2011, at 3:11 PM, Tanu Kaskinen wrote:

 I tried to apply the patch for easier review in meld, but unfortunately
 it seems that some helpful software has eaten the first space on lines
 that begin with one or more spaces. Because of that, git am doesn't
 accept the patch.
 
 I'll review this anyway, without meld.
 
 Overall comments: there is some confusion about whether the jack stuff
 is a core concept (hooks in pa_core) or an alsa specific thing (all jack
 related type definitions are in alsa-jack.h). I think it probably makes
 sense to keep alsa-jack.h as an alsa specific thing, but then the core
 hooks shouldn't be tied to alsa-jack.h like they are now. In the longer
 term I hope the thing how policy modules interact with jack detection
 will be monitoring the (currently not existing) available status of the
 port objects. However, if you don't want to start working on that now,

 I'd just move alsa-jack.h under pulsecore (and of course rename it).

I think the best solution for now would be to move it to pulsecore.

 
 The only major issue in my opinion is the jack_fd reading. It should be
 made non-blocking.
 
 -- 
 Tanu
 
 On Thu, 2011-05-19 at 11:44 -0500, Jorge Eduardo Candelaria wrote:
 From: Margarita Olaya Cabrera m...@slimlogic.co.uk
 
 This patch adds support to module-alsa-card so that we can read jack 
 insertion
 and removal events using the input device subsystem. i.e. we can detect
 headphone insertions and removals.
 
 This patch adds a new module parameter called jack_id that contains the ID of
 the jack input device associated with this sound card. If we receive a valid
 jack_id during module init then we start a reader thread that will read the
 jack input device and fire a hook on every removal and insertion event.
 
 Jack support development was kindly sponsored by Wolfson Microelectronics PLC
 
 Signed-off-by: Margarita Olaya Cabrera m...@slimlogic.co.uk
 Signed-off-by: Jorge Eduardo Candelaria j...@slimlogic.co.uk
 ---
 src/modules/alsa/alsa-jack.h|   42 
 src/modules/alsa/module-alsa-card.c |  120 
 +++
 src/pulsecore/core.h|2 +
 3 files changed, 164 insertions(+), 0 deletions(-)
 create mode 100644 src/modules/alsa/alsa-jack.h
 
 diff --git a/src/modules/alsa/alsa-jack.h b/src/modules/alsa/alsa-jack.h
 new file mode 100644
 index 000..4fc67c6
 --- /dev/null
 +++ b/src/modules/alsa/alsa-jack.h
 @@ -0,0 +1,42 @@
 +#ifndef foopulsejackdetecthfoo
 +#define foopulsejackdetecthfoo
 +
 +/***
 +  This file is part of PulseAudio.
 +
 +  Copyright 2011 Wolfson Microelectronics PLC
 +  Author Margarita Olaya m...@slimlogic.co.uk
 +
 +  PulseAudio is free software; you can redistribute it and/or modify
 +  it under the terms of the GNU Lesser General Public License as published
 +  by the Free Software Foundation; either version 2.1 of the License,
 +  or (at your option) any later version.
 +
 +  PulseAudio is distributed in the hope that it will be useful, but
 +  WITHOUT ANY WARRANTY; without even the implied warranty of
 +  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 +  General Public License for more details.
 +
 +  You should have received a copy of the GNU Lesser General Public License
 +  along with PulseAudio; if not, write to the Free Software
 +  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 +  USA.
 +***/
 +
 +#include inttypes.h
 +
 +typedef enum pa_jack_event {
 +PA_JACK_HEADPHONES,
 +PA_JACK_HEADSET,
 +PA_JACK_MICROPHONE,
 +PA_JACK_LINEOUT,
 +PA_JACK_UNKNOWN,
 +PA_JACK_MAX
 +} pa_jack_event_t;
 +
 +typedef struct pa_jack_detect {
 +pa_jack_event_t event;
 +char *card;
 
 Instead of the card name, would it be better to store a pa_card pointer
 here? It seems that you have the card object available when you
 initialize this struct.

It seemed unnecessary since only the card name is being extracted from the
struct, but I get your point. I will change this.

 
 +} pa_jack_detect_t;
 
 Structs shouldn't have the _t suffix. (Enum typedefs should, so the
 pa_jack_event_t name is correct.)
 
 If this is alsa specific, like it seems to be, judging from the file
 location and name, I recommend prefixing the types with pa_alsa_jack_,
 because all other alsa stuff uses pa_alsa_ prefix too. Hmm... on the
 other hand, this struct is passed to a core hook, so maybe these types
 are not really alsa specific, and should be defined in a header under
 src/pulsecore/?

Then these structs should defined the alsa-jack.h header, since it's going
to be moved to pulsecore.

 
 Also, I think pa_jack_event would be a better name for what you've now
 named pa_jack_detect, and the enum could be pa_jack_type_t.

Agreed, I will change this.

 
 +#endif
 diff --git a/src/modules/alsa/module-alsa-card.c 
 b/src/modules/alsa/module-alsa-card.c
 index e60aa5e..75202fb 100644
 --- a/src/modules/alsa/module-alsa-card.c
 +++ b/src/modules/alsa

[pulseaudio-discuss] [PATCH 0/0] Jack detection support.

2011-05-19 Thread Jorge Eduardo Candelaria
The following series of patches add support for jack detection.

The udev module will match a list of input devices against the current audio 
card.
When it finds an input that belongs to the card, we get the input number and 
send it
to the alsa-card through a new parameter called jack_id.

If the jack id is valid, a new thread is started that reads the jack input 
device and
fires a hook in case of an insertion or removal event.

Changes from v2:
- Create a new alsa module parameter: jack_id.
- Pass the jack_id module parameter to the alsa card.
- Use jack_id parameter to register a new jack input.
- Move jack detection code to module-alsa-card, instead of being a standalone 
module.

GIT: [PATCH 1/2] alsa: add jack detection support
GIT: [PATCH 2/2] alsa: load jack detection module
___
pulseaudio-discuss mailing list
pulseaudio-discuss@mail.0pointer.de
https://tango.0pointer.de/mailman/listinfo/pulseaudio-discuss


[pulseaudio-discuss] [PATCH 1/2] alsa: add jack detection support

2011-05-19 Thread Jorge Eduardo Candelaria
From: Margarita Olaya Cabrera m...@slimlogic.co.uk

This patch adds support to module-alsa-card so that we can read jack insertion
and removal events using the input device subsystem. i.e. we can detect
headphone insertions and removals.

This patch adds a new module parameter called jack_id that contains the ID of
the jack input device associated with this sound card. If we receive a valid
jack_id during module init then we start a reader thread that will read the
jack input device and fire a hook on every removal and insertion event.

Jack support development was kindly sponsored by Wolfson Microelectronics PLC

Signed-off-by: Margarita Olaya Cabrera m...@slimlogic.co.uk
Signed-off-by: Jorge Eduardo Candelaria j...@slimlogic.co.uk
---
src/modules/alsa/alsa-jack.h|   42 
src/modules/alsa/module-alsa-card.c |  120 +++
src/pulsecore/core.h|2 +
3 files changed, 164 insertions(+), 0 deletions(-)
create mode 100644 src/modules/alsa/alsa-jack.h

diff --git a/src/modules/alsa/alsa-jack.h b/src/modules/alsa/alsa-jack.h
new file mode 100644
index 000..4fc67c6
--- /dev/null
+++ b/src/modules/alsa/alsa-jack.h
@@ -0,0 +1,42 @@
+#ifndef foopulsejackdetecthfoo
+#define foopulsejackdetecthfoo
+
+/***
+  This file is part of PulseAudio.
+
+  Copyright 2011 Wolfson Microelectronics PLC
+  Author Margarita Olaya m...@slimlogic.co.uk
+
+  PulseAudio is free software; you can redistribute it and/or modify
+  it under the terms of the GNU Lesser General Public License as published
+  by the Free Software Foundation; either version 2.1 of the License,
+  or (at your option) any later version.
+
+  PulseAudio is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public License
+  along with PulseAudio; if not, write to the Free Software
+  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+  USA.
+***/
+
+#include inttypes.h
+
+typedef enum pa_jack_event {
+PA_JACK_HEADPHONES,
+PA_JACK_HEADSET,
+PA_JACK_MICROPHONE,
+PA_JACK_LINEOUT,
+PA_JACK_UNKNOWN,
+PA_JACK_MAX
+} pa_jack_event_t;
+
+typedef struct pa_jack_detect {
+pa_jack_event_t event;
+char *card;
+} pa_jack_detect_t;
+
+#endif
diff --git a/src/modules/alsa/module-alsa-card.c 
b/src/modules/alsa/module-alsa-card.c
index e60aa5e..75202fb 100644
--- a/src/modules/alsa/module-alsa-card.c
+++ b/src/modules/alsa/module-alsa-card.c
@@ -29,6 +29,9 @@
#include pulsecore/core-util.h
#include pulsecore/modargs.h
#include pulsecore/queue.h
+#include pulsecore/thread.h
+
+#include linux/input.h

#include modules/reserve-wrap.h

@@ -39,6 +42,7 @@
#include alsa-util.h
#include alsa-sink.h
#include alsa-source.h
+#include alsa-jack.h
#include module-alsa-card-symdef.h

PA_MODULE_AUTHOR(Lennart Poettering);
@@ -55,6 +59,7 @@ PA_MODULE_USAGE(
source_properties=properties for the source 
namereg_fail=pa_namereg_register() fail parameter value 
device_id=ALSA card index 
+jack_id=Jack device index 
format=sample format 
rate=sample rate 
fragments=number of fragments 
@@ -90,6 +95,7 @@ static const char* const valid_modargs[] = {
ignore_dB,
sync_volume,
profile_set,
+jack_id,
NULL
};

@@ -106,6 +112,14 @@ struct userdata {
pa_modargs *modargs;

pa_alsa_profile_set *profile_set;
+
+ /*userdata needed for jack detection */
+int jack_fd;
+char *jack_id;
+pa_thread *thread;
+pa_thread_mq thread_mq;
+pa_rtpoll *rtpoll;
+pa_rtpoll_item *rtpoll_item;
};

struct profile_data {
@@ -284,11 +298,89 @@ static void set_card_name(pa_card_new_data *data, 
pa_modargs *ma, const char *de
pa_xfree(t);
}

+/* Jack detection API */
+static void jack_report(struct userdata *u, struct input_event *event)
+{
+pa_jack_detect_t jack;
+
+jack.card = u-card-name ;
+
+pa_log_debug(jack: card %s event type %x code %x value %x, 
u-card-name, event-type, event-code, event-value);
+
+/* only process switch events */
+if (event-type != EV_SW) {
+pa_log_debug(jack: card %s ignored event type %x, u-card-name, 
event-type);
+return;
+}
+
+switch (event-code) {
+case SW_HEADPHONE_INSERT:
+jack.event = PA_JACK_HEADPHONES;
+break;
+case SW_MICROPHONE_INSERT:
+jack.event = PA_JACK_MICROPHONE;
+break;
+case SW_LINEOUT_INSERT:
+jack.event = PA_JACK_LINEOUT;
+break;
+case SW_JACK_PHYSICAL_INSERT:
+jack.event = PA_JACK_UNKNOWN;
+break;
+default:
+pa_log_debug(jack: card %s ignored event code %x, u-card-name, 
event-code);
+break;
+}
+
+if (event-value)
+pa_hook_fire(u-core-hooks[PA_CORE_HOOK_JACK_INSERT

[pulseaudio-discuss] [PATCH 2/2] alsa: load jack detection module

2011-05-19 Thread Jorge Eduardo Candelaria
From: Margarita Olaya Cabrera m...@slimlogic.co.uk

This patch adds support for udev detection of sound card jack event devices.

When a new card is detected, the code now also checks for the presence of any
associated input device via udev, and report the device to module-alsa-card
via its jack_id parameter.

Jack support development was kindly sponsored by Wolfson Microelectronics PLC

Signed-off-by: Margarita Olaya Cabrera m...@slimlogic.co.uk
Signed-off-by: Jorge Eduardo Candelaria j...@slimlogic.co.uk
---
src/modules/module-udev-detect.c |   68 ++---
1 files changed, 62 insertions(+), 6 deletions(-)

diff --git a/src/modules/module-udev-detect.c b/src/modules/module-udev-detect.c
index 63ad195..4321b32 100644
--- a/src/modules/module-udev-detect.c
+++ b/src/modules/module-udev-detect.c
@@ -71,6 +71,8 @@ struct userdata {

int inotify_fd;
pa_io_event *inotify_io;
+
+char *card_name;
};

static const char* const valid_modargs[] = {
@@ -163,6 +165,21 @@ static pa_bool_t pcm_is_modem(const char *card_idx, const 
char *pcm) {
return is_modem;
}

+static pa_bool_t input_node_belongs_to_device(
+struct device *d,
+const char *node) {
+
+char *cd;
+pa_bool_t b;
+
+cd = pa_sprintf_malloc(/sys%s, d-path);
+
+b = pa_startswith(node, cd);
+pa_xfree(cd);
+
+return b;
+}
+
static pa_bool_t is_card_busy(const char *id) {
char *card_path = NULL, *pcm_path = NULL, *sub_status = NULL;
DIR *card_dir = NULL, *pcm_dir = NULL;
@@ -352,11 +369,26 @@ static void verify_access(struct userdata *u, struct 
device *d) {
}
}

+static const char *jack_get_input_id(const char *path) {
+int i;
+
+for( i = 0; i  strlen(path); i++) {
+if (pa_startswith(path + i, /input))
+return path + i + 6;
+}
+
+return NULL;
+}
+
static void card_changed(struct userdata *u, struct udev_device *dev) {
struct device *d;
+struct udev_enumerate *enumerate;
+struct udev_list_entry *item, *first;
const char *path;
const char *t;
char *n;
+char *jack_path;
+char *jack_input;

pa_assert(u);
pa_assert(dev);
@@ -383,6 +415,28 @@ static void card_changed(struct userdata *u, struct 
udev_device *dev) {

n = pa_namereg_make_valid_name(t);
d-card_name = pa_sprintf_malloc(alsa_card.%s, n);
+
+if (!(enumerate = udev_enumerate_new(u-udev)))
+pa_log(Failed to initialize udev enumerator);
+else {
+if (!udev_enumerate_add_match_subsystem(enumerate, input))
+pa_log_debug(Failed to match to subsystem input);
+
+if (udev_enumerate_scan_devices(enumerate))
+pa_log_debug(Failed to scan for devices);
+
+first = udev_enumerate_get_list_entry(enumerate);
+udev_list_entry_foreach(item, first) {
+jack_path = udev_list_entry_get_name(item);
+if (input_node_belongs_to_device(d, jack_path)) {
+jack_input = pa_xstrdup(jack_get_input_id(jack_path));
+pa_log_debug(jack is %s\n, jack_input);
+break;
+}
+}
+udev_enumerate_unref(enumerate);
+}
+
d-args = pa_sprintf_malloc(device_id=\%s\ 
name=\%s\ 
card_name=\%s\ 
@@ -390,15 +444,19 @@ static void card_changed(struct userdata *u, struct 
udev_device *dev) {
tsched=%s 
ignore_dB=%s 
sync_volume=%s 
+jack_id=\%s\ 

card_properties=\module-udev-detect.discovered=1\,
path_get_card_id(path),
n,
d-card_name,
pa_yes_no(u-use_tsched),
pa_yes_no(u-ignore_dB),
-pa_yes_no(u-sync_volume));
-pa_xfree(n);
+pa_yes_no(u-sync_volume),
+jack_input);

+pa_xfree(n);
+pa_xfree(jack_input);
+u-card_name = d-card_name;
pa_hashmap_put(u-devices, d-path, d);

verify_access(u, d);
@@ -481,13 +539,11 @@ static void monitor_cb(
goto fail;
}

-if (!path_get_card_id(udev_device_get_devpath(dev))) {
+if (path_get_card_id(udev_device_get_devpath(dev))) {
+process_device(u, dev);
udev_device_unref(dev);
-return;
}

-process_device(u, dev);
-udev_device_unref(dev);
return;

fail:
-- 
1.7.1
___
pulseaudio-discuss mailing list
pulseaudio-discuss@mail.0pointer.de
https://tango.0pointer.de/mailman/listinfo/pulseaudio-discuss


Re: [pulseaudio-discuss] [PATCHv3 0/4] Read and store UCM data as proplist

2011-05-19 Thread Jorge Eduardo Candelaria

On May 18, 2011, at 2:01 AM, Colin Guthrie wrote:

 'Twas brillig, and Jorge Eduardo Candelaria at 18/05/11 07:22 did gyre
 and gimble:
 
 On May 17, 2011, at 8:56 AM, Lu Guanqun wrote:
 
 On Thu, May 12, 2011 at 02:56:04AM +0800, Jorge Eduardo Candelaria wrote:
 Ok, I'll copy the jack code we have into module-alsa-card. This will allow 
 for simple jack removal/insertion events to be propagated to pulseaudio. 
 We won't be able to do the complicated stuff mentioned above, but should 
 at least be able to do simple speaker/headphone switching. 
 
 Hi Jorge,
 
 I'm interested in your jack detection code, when do you decide to send
 it out? :-)
 
 Don't worry, I haven't forgotten about it :). I plan to send the new patches 
 tomorrow
 if all goes well with testing.
 
 Have you spoken with David about this off-list by any chance?
 
 As I mentioned previously, we have quite specific needs for jack
 detection for it to be accepted so I hope further discussions have
 happened or that you have managed to be super awesome and make it all
 just work as we want it, otherwise more tweaks will be ultimately be
 needed :)

Somehow I missed your reply yesterday, sorry I didn't answer.

I submitted about an hour ago a new set of patches for jack detection code. I 
believe
this set should be alright since it only provides the basic functionality 
without
being majorly intrusive. I'm not trying to make it all just work atm, only 
provide
a basis to continue working on and advance the discussion.

I have incorporated some changes based on the comments made through this list, 
and the
more complicated and specific code can be incorporated in incremental patches.

Regards,
Jorge

 
 Take care
 
 Col
 
 -- 
 
 Colin Guthrie
 gmane(at)colin.guthr.ie
 http://colin.guthr.ie/
 
 Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
 Open Source:
  Mageia Contributor [http://www.mageia.org/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]
 
 ___
 pulseaudio-discuss mailing list
 pulseaudio-discuss@mail.0pointer.de
 https://tango.0pointer.de/mailman/listinfo/pulseaudio-discuss

___
pulseaudio-discuss mailing list
pulseaudio-discuss@mail.0pointer.de
https://tango.0pointer.de/mailman/listinfo/pulseaudio-discuss


Re: [pulseaudio-discuss] [PATCHv3 0/4] Read and store UCM data as proplist

2011-05-18 Thread Jorge Eduardo Candelaria

On May 17, 2011, at 8:56 AM, Lu Guanqun wrote:

 On Thu, May 12, 2011 at 02:56:04AM +0800, Jorge Eduardo Candelaria wrote:
 Ok, I'll copy the jack code we have into module-alsa-card. This will allow 
 for simple jack removal/insertion events to be propagated to pulseaudio. We 
 won't be able to do the complicated stuff mentioned above, but should at 
 least be able to do simple speaker/headphone switching. 
 
 Hi Jorge,
 
 I'm interested in your jack detection code, when do you decide to send
 it out? :-)

Don't worry, I haven't forgotten about it :). I plan to send the new patches 
tomorrow
if all goes well with testing.

Regards,
Jorge

 
 -- 
 guanqun

___
pulseaudio-discuss mailing list
pulseaudio-discuss@mail.0pointer.de
https://tango.0pointer.de/mailman/listinfo/pulseaudio-discuss


Re: [pulseaudio-discuss] [PATCHv3 0/4] Read and store UCM data as proplist

2011-05-11 Thread Jorge Eduardo Candelaria

On May 11, 2011, at 6:43 AM, Colin Guthrie wrote:

 'Twas brillig, and Jorge Eduardo Candelaria at 10/05/11 21:29 did gyre
 and gimble:
 This is the third version of the Pulseaudio and UCM integration. 
 
 This set of patches cover adding ucm data to proplist, adding a ucm API
 to get and set data to proplist, and lets module-alsa-card scan ucm data
 when the card is probed.
 
 Another set of patches dealing with jack module detection will be sent
 separately.
 
 Thanks for this. I believe David will be helping review this stuff, but
 is currently at UDS.
 
 WRT the jack detection, I think we all agreed that it needs to be
 handled more internally in the alsa code rather than separated as a module.
 
 I'm not 100% sure of the finer details but I know David had ideas here too.
 
 We basically need to match up the jack stuff with the appropriate
 sink/source device on the system and then develop a way to automatically
 change sink/source ports accordingly (it may also require that we change
 the card profile too - e.g. change from a 5.1 profile to a stereo
 profile when plugging in stereo headphones).

Unfortunately, the jack matching to source is not that clever yet in the
drivers. :( There is no way to really be sure that Jack X matches stream Y.
This information should be available in the future though (for ASoC drivers
at least) when the DAPM graphs are exported. In the mean time all we can
do is know whether a jack is inserted or removed for a particular sound card.

 
 I'm not sure how to detect multiple jacks - e.g. if you plug in 3 jacks
 to do 5.1 output, should 5.1 be handled automatically?

Again, this is something that requires better driver and core alsa support.

 
 Anyway, all the jack detection stuff should be totally separate from UCM
 stuff and could in theory be committed first. UCM should just hook into
 port/profile changes for pushing new configs up to ucm and set the
 appropriate verb+modifiers on the device.

Ok, I'll copy the jack code we have into module-alsa-card. This will allow for 
simple jack removal/insertion events to be propagated to pulseaudio. We won't 
be able to do the complicated stuff mentioned above, but should at least be 
able to do simple speaker/headphone switching. 

 
 (disclaimer, my UCM foo is still not awesome, but I think this is all
 the consensus we reached on the matter!).
 
 Col
 
 -- 
 
 Colin Guthrie
 gmane(at)colin.guthr.ie
 http://colin.guthr.ie/
 
 Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
 Open Source:
  Mageia Contributor [http://www.mageia.org/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]
 
 ___
 pulseaudio-discuss mailing list
 pulseaudio-discuss@mail.0pointer.de
 https://tango.0pointer.de/mailman/listinfo/pulseaudio-discuss

___
pulseaudio-discuss mailing list
pulseaudio-discuss@mail.0pointer.de
https://tango.0pointer.de/mailman/listinfo/pulseaudio-discuss


[pulseaudio-discuss] [PATCHv3 1/4] alsa: Export alsa-mixer API

2011-05-10 Thread Jorge Eduardo Candelaria
From: Margarita Olaya Cabrera m...@slimlogic.co.uk

The UCM core needs the alsa-mixer API to be exported, so that it can
create its UCM mappings.

Signed-off-by: Margarita Olaya Cabrera m...@slimlogic.co.uk
Signed-off-by: Jorge Eduardo Candelaria j...@slimlogic.co.uk
---
src/modules/alsa/alsa-mixer.c |   10 +-
src/modules/alsa/alsa-mixer.h |   12 
2 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/src/modules/alsa/alsa-mixer.c b/src/modules/alsa/alsa-mixer.c
index 3eef5f9..07670f0 100644
--- a/src/modules/alsa/alsa-mixer.c
+++ b/src/modules/alsa/alsa-mixer.c
@@ -2909,7 +2909,7 @@ void pa_alsa_profile_set_free(pa_alsa_profile_set *ps) {
pa_xfree(ps);
}

-static pa_alsa_mapping *mapping_get(pa_alsa_profile_set *ps, const char *name) 
{
+pa_alsa_mapping *mapping_get(pa_alsa_profile_set *ps, const char *name) {
pa_alsa_mapping *m;

if (!pa_startswith(name, Mapping ))
@@ -3364,7 +3364,7 @@ fail:
return -1;
}

-static int mapping_verify(pa_alsa_mapping *m, const pa_channel_map *bonus) {
+int mapping_verify(pa_alsa_mapping *m, const pa_channel_map *bonus) {

static const struct description_map well_known_descriptions[] = {
{ analog-mono,N_(Analog Mono) },
@@ -3437,7 +3437,7 @@ void pa_alsa_mapping_dump(pa_alsa_mapping *m) {
 m-direction);
}

-static void profile_set_add_auto_pair(
+void profile_set_add_auto_pair(
pa_alsa_profile_set *ps,
pa_alsa_mapping *m, /* output */
pa_alsa_mapping *n  /* input */) {
@@ -3485,7 +3485,7 @@ static void profile_set_add_auto_pair(
pa_hashmap_put(ps-profiles, p-name, p);
}

-static void profile_set_add_auto(pa_alsa_profile_set *ps) {
+void profile_set_add_auto(pa_alsa_profile_set *ps) {
pa_alsa_mapping *m, *n;
void *m_state, *n_state;

@@ -3502,7 +3502,7 @@ static void profile_set_add_auto(pa_alsa_profile_set *ps) 
{
profile_set_add_auto_pair(ps, NULL, n);
}

-static int profile_verify(pa_alsa_profile *p) {
+int profile_verify(pa_alsa_profile *p) {

static const struct description_map well_known_descriptions[] = {
{ output:analog-mono+input:analog-mono, N_(Analog Mono Duplex) 
},
diff --git a/src/modules/alsa/alsa-mixer.h b/src/modules/alsa/alsa-mixer.h
index c24a896..ad8e980 100644
--- a/src/modules/alsa/alsa-mixer.h
+++ b/src/modules/alsa/alsa-mixer.h
@@ -220,6 +220,11 @@ int pa_alsa_path_set_mute(pa_alsa_path *path, snd_mixer_t 
*m, pa_bool_t muted);
int pa_alsa_path_select(pa_alsa_path *p, snd_mixer_t *m);
void pa_alsa_path_set_callback(pa_alsa_path *p, snd_mixer_t *m, 
snd_mixer_elem_callback_t cb, void *userdata);
void pa_alsa_path_free(pa_alsa_path *p);
+pa_alsa_mapping *mapping_get(pa_alsa_profile_set *ps, const char *name);
+int mapping_verify(pa_alsa_mapping *m, const pa_channel_map *bonus);
+void profile_set_add_auto(pa_alsa_profile_set *ps);
+void profile_set_add_auto_pair(pa_alsa_profile_set *ps, pa_alsa_mapping *m, 
pa_alsa_mapping *n);
+int profile_verify(pa_alsa_profile *p);

pa_alsa_path_set *pa_alsa_path_set_new(pa_alsa_mapping *m, pa_alsa_direction_t 
direction);
void pa_alsa_path_set_probe(pa_alsa_path_set *s, snd_mixer_t *m, pa_bool_t 
ignore_dB);
@@ -227,6 +232,13 @@ void pa_alsa_path_set_dump(pa_alsa_path_set *s);
void pa_alsa_path_set_set_callback(pa_alsa_path_set *ps, snd_mixer_t *m, 
snd_mixer_elem_callback_t cb, void *userdata);
void pa_alsa_path_set_free(pa_alsa_path_set *s);

+/* Data structure that UCM uses to extract alsa profile
+ * information. 
+ */
+struct profile_data {
+pa_alsa_profile *profile;
+};
+
struct pa_alsa_mapping {
pa_alsa_profile_set *profile_set;

-- 
1.7.1
___
pulseaudio-discuss mailing list
pulseaudio-discuss@mail.0pointer.de
https://tango.0pointer.de/mailman/listinfo/pulseaudio-discuss


[pulseaudio-discuss] [PATCHv3 0/4] Read and store UCM data as proplist

2011-05-10 Thread Jorge Eduardo Candelaria
This is the third version of the Pulseaudio and UCM integration. 

This set of patches cover adding ucm data to proplist, adding a ucm API
to get and set data to proplist, and lets module-alsa-card scan ucm data
when the card is probed.

Another set of patches dealing with jack module detection will be sent
separately.

Changes from v2:
- clean up and add documentation to some structures and functions.
- changed commit subjects to better reflect changes in code.
- used pa_log_debug() instead of pa_log() to avoid saturating the output.


___
pulseaudio-discuss mailing list
pulseaudio-discuss@mail.0pointer.de
https://tango.0pointer.de/mailman/listinfo/pulseaudio-discuss


[pulseaudio-discuss] [PATCHv3 2/4] alsa: Add UCM proplist items

2011-05-10 Thread Jorge Eduardo Candelaria
From: Margarita Olaya Cabrera m...@slimlogic.co.uk

UCM has various items we would like to store in a proplist. Add
these to the proplist property types.

Signed-off-by: Margarita Olaya Cabrera m...@slimlogic.co.uk
Signed-off-by: Jorge Eduardo Candelaria j...@slimlogic.co.uk
---
src/pulse/proplist.h |   27 +++
1 files changed, 27 insertions(+), 0 deletions(-)

diff --git a/src/pulse/proplist.h b/src/pulse/proplist.h
index 5db3ada..26429d7 100644
--- a/src/pulse/proplist.h
+++ b/src/pulse/proplist.h
@@ -245,6 +245,33 @@ PA_C_DECL_BEGIN
/** For modules: a version string for the module. e.g. 0.9.15 */
#define PA_PROP_MODULE_VERSION module.version

+/** For devices: List of verbs, devices or modifiers availables */
+#define PA_PROP_UCM_NAME   ucm.name
+
+/** For devices: List of supported devices per verb*/
+#define PA_PROP_UCM_DESCRIPTIONucm.description
+
+/** For devices: Playback device name e.g PlaybackPCM */
+#define PA_PROP_UCM_SINK   ucm.sink
+
+/** For devices: Capture device name e.g CapturePCM*/
+#define PA_PROP_UCM_SOURCE ucm.source
+
+/** For devices: Playback control volume ID string. e.g PlaybackVolume */
+#define PA_PROP_UCM_PLAYBACK_VOLUMEucm.playback.volume
+
+/** For devices: Playback switch e.g PlaybackSwitch */
+#define PA_PROP_UCM_PLAYBACK_SWITCHucm.playback.switch
+
+/** For devices: Capture controls volume ID string. e.g CaptureVolume */
+#define PA_PROP_UCM_CAPTURE_VOLUME ucm.capture.volume
+
+/** For devices: Capture switch e.g CaptureSwitch */
+#define PA_PROP_UCM_CAPTURE_SWITCH ucm.capture.switch
+
+/** For devices: Quality of Service */
+#define PA_PROP_UCM_QOSucm.qos
+
/** A property list object. Basically a dictionary with ASCII strings
 * as keys and arbitrary data as values. \since 0.9.11 */
typedef struct pa_proplist pa_proplist;
-- 
1.7.1
___
pulseaudio-discuss mailing list
pulseaudio-discuss@mail.0pointer.de
https://tango.0pointer.de/mailman/listinfo/pulseaudio-discuss


[pulseaudio-discuss] [PATCHv3 4/4] alsa: Support UCM profiles in module-alsa-card

2011-05-10 Thread Jorge Eduardo Candelaria
From: Margarita Olaya Cabrera m...@slimlogic.co.uk

This patch adds ALSA UCM (Use Case Manager) support to module alsa card.
It checks if UCM is available for each card and if found it uses the profiles
generated with ucm data.

Using a udev-rule user can decide if UCM will be used or not,
Depending on the status of USE_UCM property, a flag is passed as
module argument to module-alsa-card.

Signed-off-by: Margarita Olaya Cabrera m...@slimlogic.co.uk
Signed-off-by: Jorge Eduardo Candelaria j...@slimlogic.co.uk
---
src/modules/alsa/module-alsa-card.c |  120 +++
src/modules/module-udev-detect.c|   11 +++-
2 files changed, 117 insertions(+), 14 deletions(-)

diff --git a/src/modules/alsa/module-alsa-card.c 
b/src/modules/alsa/module-alsa-card.c
index e60aa5e..312a42b 100644
--- a/src/modules/alsa/module-alsa-card.c
+++ b/src/modules/alsa/module-alsa-card.c
@@ -39,6 +39,7 @@
#include alsa-util.h
#include alsa-sink.h
#include alsa-source.h
+#include alsa-ucm.h
#include module-alsa-card-symdef.h

PA_MODULE_AUTHOR(Lennart Poettering);
@@ -66,7 +67,8 @@ PA_MODULE_USAGE(
profile=profile name 
ignore_dB=ignore dB information from the device? 
sync_volume=syncronize sw and hw voluchanges in IO-thread? 
-profile_set=profile set configuration file );
+profile_set=profile set configuration file 
+use_ucm=Load Use Case Manager );

static const char* const valid_modargs[] = {
name,
@@ -90,6 +92,7 @@ static const char* const valid_modargs[] = {
ignore_dB,
sync_volume,
profile_set,
+use_ucm,
NULL
};

@@ -106,10 +109,8 @@ struct userdata {
pa_modargs *modargs;

pa_alsa_profile_set *profile_set;
-};

-struct profile_data {
-pa_alsa_profile *profile;
+pa_alsa_ucm_config ucm;
};

static void add_profiles(struct userdata *u, pa_hashmap *h) {
@@ -207,6 +208,15 @@ static int card_set_profile(pa_card *c, pa_card_profile 
*new_profile) {
am-source = NULL;
}

+/* if UCM is avalible for this card then update the verb */
+if (u-ucm.status == PA_ALSA_UCM_ENABLED) {
+struct profile_data *d;
+   /* current profile */
+d = PA_CARD_PROFILE_DATA(u-card-active_profile);
+if (ucm_set_profile(u-ucm, nd-profile-name, d)  0)
+return -1;
+}
+
if (nd-profile  nd-profile-output_mappings)
PA_IDXSET_FOREACH(am, nd-profile-output_mappings, idx) {

@@ -240,15 +250,40 @@ static int card_set_profile(pa_card *c, pa_card_profile 
*new_profile) {
return 0;
}

-static void init_profile(struct userdata *u) {
+static int init_profile(struct userdata *u) {
uint32_t idx;
pa_alsa_mapping *am;
struct profile_data *d;
+char *device_name, *verb_name, *tmp;
+struct pa_alsa_ucm_config *ucm = u-ucm;

pa_assert(u);

d = PA_CARD_PROFILE_DATA(u-card-active_profile);

+if (u-ucm.status == PA_ALSA_UCM_ENABLED) {
+/* Set initial verb and device */
+verb_name = pa_xstrdup(d-profile-name);
+tmp = strchr(verb_name, ':');
+if (!tmp) {
+pa_log(no new verb found for %s, d-profile-name);
+pa_xfree(verb_name);
+return -1;
+}
+*tmp = 0;
+
+if ((snd_use_case_set(ucm-ucm_mgr, _verb, verb_name))  0) {
+pa_log(failed to set verb %s, d-profile-name);
+return -1;
+}
+
+device_name = strchr(d-profile-name, ':') + 2;
+if (snd_use_case_set(ucm-ucm_mgr, _enadev, device_name)  0) {
+pa_log(failed to set device %s, device_name);
+return -1;
+}
+}
+
if (d-profile  d-profile-output_mappings)
PA_IDXSET_FOREACH(am, d-profile-output_mappings, idx)
am-sink = pa_alsa_sink_new(u-module, u-modargs, __FILE__, 
u-card, am);
@@ -256,6 +291,8 @@ static void init_profile(struct userdata *u) {
if (d-profile  d-profile-input_mappings)
PA_IDXSET_FOREACH(am, d-profile-input_mappings, idx)
am-source = pa_alsa_source_new(u-module, u-modargs, __FILE__, 
u-card, am);
+
+return 0;
}

static void set_card_name(pa_card_new_data *data, pa_modargs *ma, const char 
*device_id) {
@@ -284,6 +321,56 @@ static void set_card_name(pa_card_new_data *data, 
pa_modargs *ma, const char *de
pa_xfree(t);
}

+static int card_query_ucm_profiles(struct userdata *u, int card_index)
+{
+char *card_name;
+const char **verb_list;
+int num_verbs, i, err;
+
+/* is UCM available for this card ? */
+snd_card_get_name(card_index, card_name);
+err = snd_use_case_mgr_open(u-ucm.ucm_mgr, card_name);
+if (err  0) {
+pa_log(UCM not avaliable for card %s, card_name);
+u-ucm.status = PA_ALSA_UCM_DISABLED;
+return 0;
+}
+
+pa_log_info(UCM avaliable for card %s, card_name);
+
+/* get a list of all UCM verbs (profiles) for this card */
+num_verbs = snd_use_case_verb_list(u-ucm.ucm_mgr, verb_list);
+if (num_verbs = 0

[pulseaudio-discuss] [PATCHv3 3/4] alsa: Add UCM API for managing UCM propoerties

2011-05-10 Thread Jorge Eduardo Candelaria
From: Margarita Olaya Cabrera m...@slimlogic.co.uk

The UCM stores the mixer settings per use case in configuration files, these
files contains information such:
- list of use case verbs per card or machine
- supported devices per use case verb
- use case sink device
- use case source device
- hardware playback volume control id (per use case verb and device)
- hardware playback mute switch id
- hardware capture volume control id
- hardware capture mute switch id

The new ucm data structures are used to store that info so it can be used by
pulseaudio.

This patch also adds ALSA UCM (Use Case Manager) calls.
It checks if UCM is available for each card and if found, scans each UCM
property verb, device and modifier for the card. It then then creates
mappings for each supported UCM verb and device so that changes to the
pulseaudio profile cause corresponding changes to the UCM verb and
device for the card.

Signed-off-by: Margarita Olaya Cabrera m...@slimlogic.co.uk
Signed-off-by: Jorge Eduardo Candelaria j...@slimlogic.co.uk
---
src/Makefile.am |2 +-
src/modules/alsa/alsa-ucm.c |  532 +++
src/modules/alsa/alsa-ucm.h |   80 +++
3 files changed, 613 insertions(+), 1 deletions(-)
create mode 100644 src/modules/alsa/alsa-ucm.c
create mode 100644 src/modules/alsa/alsa-ucm.h

diff --git a/src/Makefile.am b/src/Makefile.am
index 71ad19b..38bc903 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1553,7 +1553,7 @@ module_coreaudio_device_la_LIBADD = $(MODULE_LIBADD)

# ALSA

-libalsa_util_la_SOURCES = modules/alsa/alsa-util.c modules/alsa/alsa-util.h 
modules/alsa/alsa-mixer.c modules/alsa/alsa-mixer.h modules/alsa/alsa-sink.c 
modules/alsa/alsa-sink.h modules/alsa/alsa-source.c modules/alsa/alsa-source.h 
modules/reserve-wrap.c modules/reserve-wrap.h
+libalsa_util_la_SOURCES = modules/alsa/alsa-util.c modules/alsa/alsa-util.h 
modules/alsa/alsa-mixer.c modules/alsa/alsa-mixer.h modules/alsa/alsa-sink.c 
modules/alsa/alsa-sink.h modules/alsa/alsa-source.c modules/alsa/alsa-source.h 
modules/alsa/alsa-ucm.c modules/alsa/alsa-ucm.h modules/reserve-wrap.c 
modules/reserve-wrap.h
libalsa_util_la_LDFLAGS = -avoid-version
libalsa_util_la_LIBADD = $(MODULE_LIBADD) $(ASOUNDLIB_LIBS)
libalsa_util_la_CFLAGS = $(AM_CFLAGS) $(ASOUNDLIB_CFLAGS)
diff --git a/src/modules/alsa/alsa-ucm.c b/src/modules/alsa/alsa-ucm.c
new file mode 100644
index 000..8182a3b
--- /dev/null
+++ b/src/modules/alsa/alsa-ucm.c
@@ -0,0 +1,532 @@
+/***
+ This file is part of PulseAudio.
+
+ Copyright 2011 Wolfson Microelectronics PLC
+ Author Margarita Olaya m...@slimlogic.co.uk
+
+ PulseAudio is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2.1 of the License,
+ or (at your option) any later version.
+
+ PulseAudio is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with PulseAudio; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ USA.
+
+***/
+
+#ifdef HAVE_CONFIG_H
+#include config.h
+#endif
+
+#include sys/types.h
+#include limits.h
+#include asoundlib.h
+
+#ifdef HAVE_VALGRIND_MEMCHECK_H
+#include valgrind/memcheck.h
+#endif
+
+#include pulse/sample.h
+#include pulse/xmalloc.h
+#include pulse/timeval.h
+#include pulse/util.h
+#include pulse/i18n.h
+#include pulse/utf8.h
+
+#include pulsecore/log.h
+#include pulsecore/macro.h
+#include pulsecore/core-util.h
+#include pulsecore/atomic.h
+#include pulsecore/core-error.h
+#include pulsecore/once.h
+#include pulsecore/thread.h
+#include pulsecore/conf-parser.h
+#include pulsecore/strbuf.h
+
+#include alsa-mixer.h
+#include alsa-util.h
+#include alsa-ucm.h
+
+struct ucm_items {
+const char *id;
+const char *property;
+};
+
+struct ucm_info {
+const char *id;
+int priority;
+pa_alsa_direction_t direction;
+int channels;
+};
+
+/* UCM items - structure to set proplist items*/
+static struct ucm_items item[] = {
+{PlaybackPCM, PA_PROP_UCM_SINK},
+{CapturePCM, PA_PROP_UCM_SOURCE},
+{PlaybackVolume, PA_PROP_UCM_PLAYBACK_VOLUME},
+{PlaybackSwitch, PA_PROP_UCM_PLAYBACK_SWITCH},
+{CaptureVolume, PA_PROP_UCM_CAPTURE_VOLUME},
+{CaptureSwitch, PA_PROP_UCM_CAPTURE_SWITCH},
+{TQ, PA_PROP_UCM_QOS},
+{NULL, NULL},
+};
+
+/* UCM device info - this should eventually be part of policy manangement */
+static struct ucm_info dev_info[] = {
+{SND_USE_CASE_DEV_SPEAKER, 100, PA_ALSA_DIRECTION_OUTPUT, 2},
+{SND_USE_CASE_DEV_LINE, 100, PA_ALSA_DIRECTION_ANY, 2},
+{SND_USE_CASE_DEV_HEADPHONES, 100, PA_ALSA_DIRECTION_OUTPUT, 2},
+{SND_USE_CASE_DEV_HEADSET