Re: [pulseaudio-discuss] New release - mpd has stopped working with same user

2012-11-20 Thread Damir Jelić
> I would not rule that out. I use systemd which basically just starts
> "mpd --no-daemon" as root. Thanks for trying to help and checking
> things out, will await more comments from others.

Have you tried starting mpd manually?
I think the "as root" part could be problematic.

You can also try to modify the mpd.service file, just
add User=myUserName so it starts mpd as your user.
___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


Re: [pulseaudio-discuss] [PATCH v2 1/2 pavucontrol] mainwindow: Show the availability of the ports and profiles.

2012-11-21 Thread Damir Jelić
On Wed, Nov 21, 2012 at 10:31:51AM +0530, Arun Raghavan wrote:
> On Fri, 2012-11-16 at 00:12 +0100, poljar (Damir Jelić) wrote:
> > From: "poljar (Damir Jelić)" 
> > 
> > If we know if a certain port is available/unavailable, we can print
> > that out, as a help to the user (and as debugging for ourselves).
> > A profile is also available/unavailable if all ports which have that
> > profile are available/unavailable.
> 
> I'm not sure how other UIs are handling this, but it's a bit odd to see 
> "Speakers (unplugged)" when headphones are plugged in. Anything we can
> do about that? Maybe special-case speakers with s/unplugged/unavailable?
> 

Sure thing. I've attached a simple patch which can be squashed
together, or should I resend everything?
>From 60d489dffed0ab3009f798fe38ea362db960e1be Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?"poljar=20(Damir=20Jeli=C4=87)"?= 
Date: Wed, 21 Nov 2012 16:28:21 +0100
Subject: [PATCH v3 3/3 pavucontrol] mainwindow: Add a special case for the 
speakers
 availability.

---
 src/mainwindow.cc | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/mainwindow.cc b/src/mainwindow.cc
index 5a1c8f4..45f0b72 100644
--- a/src/mainwindow.cc
+++ b/src/mainwindow.cc
@@ -268,8 +268,12 @@ static void updatePorts(DeviceWidget *w, 
std::map &port
 
 if (p.available == PA_PORT_AVAILABLE_YES)
 desc +=  _(" (plugged in)");
-else if (p.available == PA_PORT_AVAILABLE_NO)
-desc += _(" (unplugged)");
+else if (p.available == PA_PORT_AVAILABLE_NO) {
+if (p.name == "analog-output-speaker")
+desc += _(" (unavailable)");
+else
+desc += _(" (unplugged)");
+}
 
 w->ports[i].second = desc;
 }
-- 
1.8.0

___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


Re: [pulseaudio-discuss] [PATCH v2 1/2 pavucontrol] mainwindow: Show the availability of the ports and profiles.

2012-11-21 Thread Damir Jelić
On Wed, Nov 21, 2012 at 07:03:30PM +0100, David Henningsson wrote:
> On 11/21/2012 04:33 PM, Damir Jelić wrote:
> >On Wed, Nov 21, 2012 at 10:31:51AM +0530, Arun Raghavan wrote:
> >>On Fri, 2012-11-16 at 00:12 +0100, poljar (Damir Jelić) wrote:
> >>>From: "poljar (Damir Jelić)" 
> >>>
> >>>If we know if a certain port is available/unavailable, we can print
> >>>that out, as a help to the user (and as debugging for ourselves).
> >>>A profile is also available/unavailable if all ports which have that
> >>>profile are available/unavailable.
> >>
> >>I'm not sure how other UIs are handling this, but it's a bit odd to see
> >>"Speakers (unplugged)" when headphones are plugged in. Anything we can
> >>do about that? Maybe special-case speakers with s/unplugged/unavailable?
> >>
> >
> >Sure thing. I've attached a simple patch which can be squashed
> >together, or should I resend everything?
> 
> If so the same should apply to "Internal Mic" as well.

Oh thats right. New version attached.
>From b308c786afbbd02227c1052a4ea10281bc3b2f99 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?"poljar=20(Damir=20Jeli=C4=87)"?= 
Date: Wed, 21 Nov 2012 16:28:21 +0100
Subject: [PATCH v4 3/3 pavucontrol] mainwindow: Add a special case for the 
speakers/internal
 mic availability.

---
 src/mainwindow.cc | 9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/src/mainwindow.cc b/src/mainwindow.cc
index 5a1c8f4..b5f3081 100644
--- a/src/mainwindow.cc
+++ b/src/mainwindow.cc
@@ -268,8 +268,13 @@ static void updatePorts(DeviceWidget *w, 
std::map &port
 
 if (p.available == PA_PORT_AVAILABLE_YES)
 desc +=  _(" (plugged in)");
-else if (p.available == PA_PORT_AVAILABLE_NO)
-desc += _(" (unplugged)");
+else if (p.available == PA_PORT_AVAILABLE_NO) {
+if (p.name == "analog-output-speaker" ||
+p.name == "analog-input-microphone-internal")
+desc += _(" (unavailable)");
+else
+desc += _(" (unplugged)");
+}
 
 w->ports[i].second = desc;
 }
-- 
1.8.0

___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


Re: [pulseaudio-discuss] Bluetooth regression: a2dp not selectable

2012-11-23 Thread Damir Jelić
On Fri, Nov 23, 2012 at 04:40:07PM +0100, David Henningsson wrote:
> Under PulseAudio 2.1 I can select a2dp without problem.
> 
> Under PulseAudio 2.99.2, when I execute "pactl set-card-profile 1
> a2dp" I get "Failure: Input/Output Error" back (as the output from
> pactl), and I see the following in PulseAudio's log:
> 
> module-bluetooth-device.c: Profile has no transport
> 
> ...and the profile is not changed to a2dp. Anyone want to debug with me?

That sounds familiar. I think I hit the bug and traced it back to bluez.
Bluez did not create the transport accordingly.
I compiled bluez from git and the issue disappeared.

I can't reproduce this anymore but I have a different issue.

I get a crash when I try to connect the headphones. (short snip below)

D: [pulseaudio] module-bluetooth-discover.c: Loading module-bluetooth-device 
address="00:1A:7D:26:87:41" path="/org/bluez/702/hci0/dev_00_1A_7D_26_87_41"
Inconsistency detected by ld.so: dl-open.c: 666: _dl_open: Assertion 
`_dl_debug_initialize (0, args.nsid)->r_state == RT_CONSISTENT' failed!

I'll start a new thread for this with proper logs.
___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


Re: [pulseaudio-discuss] [PATCH v2 1/2 pavucontrol] mainwindow: Show the availability of the ports and profiles.

2012-11-24 Thread Damir Jelić
On Sat, Nov 24, 2012 at 04:29:05PM +0200, Tanu Kaskinen wrote:
> On Fri, 2012-11-16 at 00:12 +0100, poljar (Damir Jelić) wrote:
> > diff --git a/src/mainwindow.cc b/src/mainwindow.cc
> > index 1041eab..63e02e8 100644
> > --- a/src/mainwindow.cc
> > +++ b/src/mainwindow.cc
> > @@ -254,12 +254,31 @@ static void set_icon_name_fallback(Gtk::Image *i, 
> > const char *name, Gtk::IconSiz
> >  
> >  static void updatePorts(DeviceWidget *w, std::map 
> > &ports) {
> >  std::map::iterator it;
> > +PortInfo p;
> > +
> > +for (uint32_t i = 0; i < w->ports.size(); i++) {
> > +Glib::ustring desc;
> > +it = ports.find(w->ports[i].first);
> > +
> > +if (it == ports.end())
> > +continue;
> > +
> > +p = (*it).second;
> 
> Out of curiosity, is the reason for using (*it).second instead of
> it->second that you think it looks better, or something else?
> 
I think I saw that somewhere else so I tried to be consistent, but I'm
not completely sure anymore.
___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


Re: [pulseaudio-discuss] Why are we checking various sample rates?

2012-12-02 Thread Damir Jelić
On Sun, Dec 02, 2012 at 05:10:53AM +0200, Tanu Kaskinen wrote:
> On Fri, 2012-11-30 at 09:59 +0100, David Henningsson wrote:
> > Hi,
> > 
> > I'm researching a bug where some set of USB speakers stopped working, 
> > probably in 2.x. The peculiar thing about this sound card is that seems 
> > to only work at a sample rate of 46875 Hz.
> > 
> > So in 2.x, the probe fails with
> > "E: [pulseaudio] alsa-sink.c: Failed to find any supported sample 
> > rates.", whereas in an earlier version, it would just happily work at 
> > 46875 Hz instead, as I understand it.
> > 
> > So my first question is; why do we check all these rates, when we end up 
> > just alternating between default-sample-rate (44100 Hz) and 
> > alternate-sample-rate (48000 Hz) anyway?
> 
> I don't have an answer for that.
> 
> > And second, can we try not to fail if we can't find any supported sample 
> > rates, so we can fix this regression?
> 
> I don't see any fundamental reason why we couldn't support any crazy
> sample rate.
> 
> > For reference, this is the bug (with pulse verbose logs in it):
> > 
> > https://bugs.launchpad.net/ubuntu/+source/alsa-driver/+bug/1074783
> 
> A related bug: https://bugs.freedesktop.org/show_bug.cgi?id=48109
> 
> -- 
> Tanu
> 
Hi.
I played around a bit and found seemingly a solution to this. I'm not sure
if this is the proper solution but it seems to work for me. Let me know
if I should clean this up a little further.

Patch attached.
>From 6a2a994592564d0534fc5308e909e38067bcdc18 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?poljar=20=28Damir=20Jeli=C4=87=29?= 
Date: Sun, 2 Dec 2012 21:56:46 +0100
Subject: [PATCH] alsa: Find all supported sink/source sample rates.

This is needed for some obscure hardware that supports only weird sample
rates.
Instead of relying on a static rates list we get the min/max supported
sample rate from alsa and probe every rate inbetween.

The static list is still used as a fallback if we don't get proper
min/max rates from alsa.

BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=48109
---
 src/modules/alsa/alsa-util.c | 28 ++--
 1 file changed, 26 insertions(+), 2 deletions(-)

diff --git a/src/modules/alsa/alsa-util.c b/src/modules/alsa/alsa-util.c
index 4a29a9a..ca6a3bb 100644
--- a/src/modules/alsa/alsa-util.c
+++ b/src/modules/alsa/alsa-util.c
@@ -1335,8 +1335,8 @@ unsigned int *pa_alsa_get_supported_rates(snd_pcm_t *pcm) 
{
 384000 };
 pa_bool_t supported[PA_ELEMENTSOF(all_rates)] = { FALSE, };
 snd_pcm_hw_params_t *hwparams;
-unsigned int i, j, n, *rates = NULL;
-int ret;
+unsigned int i, j, n, *rates = NULL, rate_min, rate_max;
+int ret, dir;
 
 snd_pcm_hw_params_alloca(&hwparams);
 
@@ -1345,6 +1345,30 @@ unsigned int *pa_alsa_get_supported_rates(snd_pcm_t 
*pcm) {
 return NULL;
 }
 
+if ((ret =snd_pcm_hw_params_get_rate_min(hwparams, &rate_min, &dir)) < 0) {
+pa_log_debug("snd_pcm_hw_params_get_rate_min() failed: %s", 
pa_alsa_strerror(ret));
+goto fallback;
+}
+
+if ((ret =snd_pcm_hw_params_get_rate_max(hwparams, &rate_max, &dir)) < 0) {
+pa_log_debug("snd_pcm_hw_params_get_rate_max() failed: %s", 
pa_alsa_strerror(ret));
+goto fallback;
+}
+pa_log_debug("Found min - max rates: %d - %d", rate_min, rate_max);
+
+for (i = rate_min, n = 0; i <= rate_max; i++) {
+if (snd_pcm_hw_params_test_rate(pcm, hwparams, i, 0) == 0) {
+rates = pa_xrealloc(rates, ++n * sizeof(unsigned int));
+rates[n-1] = i;
+}
+}
+/* This is here to check if we get bogus min/max rates */
+if (n == 0)
+goto fallback;
+
+return rates;
+
+fallback:
 for (i = 0, n = 0; i < PA_ELEMENTSOF(all_rates); i++) {
 if (snd_pcm_hw_params_test_rate(pcm, hwparams, all_rates[i], 0) == 0) {
 supported[i] = TRUE;
-- 
1.8.0.1

___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


Re: [pulseaudio-discuss] Why are we checking various sample rates?

2012-12-03 Thread Damir Jelić
On Mon, Dec 03, 2012 at 11:25:19AM +0800, Raymond Yau wrote:
> 
>this create a extreme large array for those drivers which support
>SNDRV_PCM_RATE_CONTINUOUS
> 
I wasn't aware that some cards support continuous rates, Arun's fix
should work better in that case. 

Thanks.
___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


[pulseaudio-discuss] [PATCH RFC 0/4] Store volume information in the porst struct.

2013-01-04 Thread Damir Jelić
This patch set is for now an RFC.
This should move the volume saving/restoring to the ports and card-restore. 
The sinks/sources should then only inherit the volume from the active port.

The last patch is just a quick hack so device-restore doesn't load the
volume for newly created sinks.

This should fix bug 55262.

BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=55262

___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


[pulseaudio-discuss] [PATCH RFC 1/4] device-port: Add volume to the ports struct.

2013-01-04 Thread Damir Jelić
This patch adds a volume to the ports.
Now we can save and restore the volume per port.

BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=55262
---
 src/pulsecore/device-port.c | 16 
 src/pulsecore/device-port.h |  3 +++
 2 files changed, 19 insertions(+)

diff --git a/src/pulsecore/device-port.c b/src/pulsecore/device-port.c
index 9ea54e3..c7605d5 100644
--- a/src/pulsecore/device-port.c
+++ b/src/pulsecore/device-port.c
@@ -98,6 +98,7 @@ pa_device_port *pa_device_port_new(pa_core *c, const char 
*name, const char *des
 p->is_input = FALSE;
 p->is_output = FALSE;
 p->latency_offset = 0;
+pa_cvolume_init(&p->volume);
 p->proplist = pa_proplist_new();
 
 return p;
@@ -147,3 +148,18 @@ void pa_device_port_set_latency_offset(pa_device_port *p, 
int64_t offset) {
 if (p == pa_hashmap_get(card->ports, p->name))
 pa_subscription_post(core, 
PA_SUBSCRIPTION_EVENT_CARD|PA_SUBSCRIPTION_EVENT_CHANGE, card->index);
 }
+
+void pa_device_port_set_volume(pa_device_port *p, pa_cvolume volume) {
+uint32_t state;
+pa_core *core;
+pa_card *card;
+
+pa_assert(p);
+
+p->volume = volume;
+
+pa_assert_se(core = p->core);
+PA_IDXSET_FOREACH(card, core->cards, state)
+if (p == pa_hashmap_get(card->ports, p->name))
+pa_subscription_post(core, 
PA_SUBSCRIPTION_EVENT_CARD|PA_SUBSCRIPTION_EVENT_CHANGE, card->index);
+}
diff --git a/src/pulsecore/device-port.h b/src/pulsecore/device-port.h
index a5c6420..0d56079 100644
--- a/src/pulsecore/device-port.h
+++ b/src/pulsecore/device-port.h
@@ -33,6 +33,7 @@ typedef struct pa_device_port pa_device_port;
 #include 
 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -52,6 +53,7 @@ struct pa_device_port {
 pa_bool_t is_input:1;
 pa_bool_t is_output:1;
 int64_t latency_offset;
+pa_cvolume volume;
 
 /* .. followed by some implementation specific data */
 };
@@ -70,4 +72,5 @@ void pa_device_port_set_available(pa_device_port *p, 
pa_port_available_t availab
 
 void pa_device_port_set_latency_offset(pa_device_port *p, int64_t offset);
 
+void pa_device_port_set_volume(pa_device_port *p, pa_cvolume volume);
 #endif
-- 
1.8.1

___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


[pulseaudio-discuss] [PATCH RFC 2/4] card-restore: Save/restore the volume for the ports.

2013-01-04 Thread Damir Jelić
The card-restore module now saves and restores the volume per port.
This change includes a entry version bump.

BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=55262
---
 src/modules/module-card-restore.c | 30 +-
 1 file changed, 21 insertions(+), 9 deletions(-)

diff --git a/src/modules/module-card-restore.c 
b/src/modules/module-card-restore.c
index 643e074..1f1c89f 100644
--- a/src/modules/module-card-restore.c
+++ b/src/modules/module-card-restore.c
@@ -68,11 +68,12 @@ struct userdata {
 pa_database *database;
 };
 
-#define ENTRY_VERSION 2
+#define ENTRY_VERSION 3
 
 struct port_info {
 char *name;
 int64_t offset;
+pa_cvolume volume;
 };
 
 struct entry {
@@ -145,6 +146,7 @@ static pa_bool_t entry_write(struct userdata *u, const char 
*name, const struct
 PA_HASHMAP_FOREACH(p_info, e->ports, state) {
 pa_tagstruct_puts(t, p_info->name);
 pa_tagstruct_puts64(t, p_info->offset);
+pa_tagstruct_put_cvolume(t, &p_info->volume);
 }
 
 key.data = (char *) name;
@@ -232,9 +234,11 @@ static struct entry* entry_read(struct userdata *u, const 
char *name) {
 uint32_t port_count = 0;
 const char *port_name = NULL;
 int64_t port_offset = 0;
+pa_cvolume port_volume;
 struct port_info *p_info;
 unsigned i;
 
+pa_cvolume_init(&port_volume);
 if (pa_tagstruct_getu32(t, &port_count) < 0)
 goto fail;
 
@@ -242,12 +246,14 @@ static struct entry* entry_read(struct userdata *u, const 
char *name) {
 if (pa_tagstruct_gets(t, &port_name) < 0 ||
 !port_name ||
 pa_hashmap_get(e->ports, port_name) ||
-pa_tagstruct_gets64(t, &port_offset) < 0)
+pa_tagstruct_gets64(t, &port_offset) < 0 ||
+(e->version >= 3 && pa_tagstruct_get_cvolume(t, &port_volume) 
< 0))
 goto fail;
 
 p_info = pa_xnew(struct port_info, 1);
 p_info->name = pa_xstrdup(port_name);
 p_info->offset = port_offset;
+p_info->volume = port_volume;
 
 pa_assert_se(pa_hashmap_put(e->ports, p_info->name, p_info) >= 0);
 }
@@ -313,6 +319,7 @@ static void subscribe_callback(pa_core *c, 
pa_subscription_event_type_t t, uint3
 p_info = pa_xnew(struct port_info, 1);
 p_info->name = pa_xstrdup(p->name);
 p_info->offset = p->latency_offset;
+p_info->volume = p->volume;
 
 pa_assert_se(pa_hashmap_put(entry->ports, p_info->name, p_info) >= 0);
 }
@@ -332,7 +339,8 @@ static void subscribe_callback(pa_core *c, 
pa_subscription_event_type_t t, uint3
 
 PA_HASHMAP_FOREACH(old_p_info, old->ports, state) {
 if ((p_info = pa_hashmap_get(entry->ports, old_p_info->name))) 
{
-if (p_info->offset != old_p_info->offset) {
+if (p_info->offset != old_p_info->offset ||
+!pa_cvolume_equal(&p_info->volume, 
&old_p_info->volume)) {
 dirty = true;
 break;
 }
@@ -354,9 +362,9 @@ static void subscribe_callback(pa_core *c, 
pa_subscription_event_type_t t, uint3
 }
 
 if (card->save_profile)
-pa_log_info("Storing profile and port latency offsets for card %s.", 
card->name);
+pa_log_info("Storing profile and port volume and latency offsets for 
card %s.", card->name);
 else
-pa_log_info("Storing port latency offsets for card %s.", card->name);
+pa_log_info("Storing port volume and latency offsets for card %s.", 
card->name);
 
 if (entry_write(u, card->name, entry))
 trigger_save(u);
@@ -369,6 +377,7 @@ static pa_hook_result_t card_new_hook_callback(pa_core *c, 
pa_card_new_data *new
 void *state;
 pa_device_port *p;
 struct port_info *p_info;
+char buf[PA_CVOLUME_SNPRINT_MAX];
 
 pa_assert(new_data);
 
@@ -385,14 +394,17 @@ static pa_hook_result_t card_new_hook_callback(pa_core 
*c, pa_card_new_data *new
 pa_log_debug("Not restoring profile for card %s, because already 
set.", new_data->name);
 }
 
-/* Always restore the latency offsets because their
- * initial value is always 0 */
+/* Always restore the latency offsets and volume because their
+ * initial value is always 0 and PA_VOLUME_INVALID*/
 
-pa_log_info("Restoring port latency offsets for card %s.", new_data->name);
+pa_log_info("Restoring port volume and latency offsets for card %s.", 
new_data->name);
 
 PA_HASHMAP_FOREACH(p_info, e->ports, state)
-if ((p = pa_hashmap_get(new_data->ports, p_info->name)))
+if ((p = pa_hashmap_get(new_data->ports, p_info->name))) {
 p->latency_offset = p_info->offset;
+p->volume = p_info->volume;
+pa_log_info("Restored volume: for port %s - %s", p->name, 
pa_cvolume_snprint(buf, PA_CVOLUME_SNPRINT_MAX, &p_i

[pulseaudio-discuss] [PATCH RFC 3/4] sink: Inherit the volume from the active port.

2013-01-04 Thread Damir Jelić
Since the port now holds the volume information we can simply inherit
the volume from the active port if the volume isn't set while creating
the sink.

BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=55262
---
 src/pulsecore/sink.c | 14 +++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/src/pulsecore/sink.c b/src/pulsecore/sink.c
index a8a91d6..37cabb6 100644
--- a/src/pulsecore/sink.c
+++ b/src/pulsecore/sink.c
@@ -276,7 +276,6 @@ pa_sink* pa_sink_new(
 s->n_corked = 0;
 s->input_to_master = NULL;
 
-s->reference_volume = s->real_volume = data->volume;
 pa_cvolume_reset(&s->soft_volume, s->sample_spec.channels);
 s->base_volume = PA_VOLUME_NORM;
 s->n_volume_steps = PA_VOLUME_NORM+1;
@@ -309,10 +308,18 @@ pa_sink* pa_sink_new(
 s->active_port = p;
 }
 
-if (s->active_port)
+if (s->active_port) {
 s->latency_offset = s->active_port->latency_offset;
-else
+
+if (pa_cvolume_valid(&s->active_port->volume) && !data->volume_is_set)
+s->reference_volume = s->real_volume = s->active_port->volume;
+else
+s->reference_volume = s->real_volume = data->volume;
+
+} else {
 s->latency_offset = 0;
+s->reference_volume = s->real_volume = data->volume;
+}
 
 s->save_volume = data->save_volume;
 s->save_muted = data->save_muted;
@@ -1976,6 +1983,7 @@ void pa_sink_set_volume(
 }
 
 pa_cvolume_remap(&new_reference_volume, &s->channel_map, 
&root_sink->channel_map);
+pa_device_port_set_volume(s->active_port, new_reference_volume);
 
 if (update_reference_volume(root_sink, &new_reference_volume, 
&root_sink->channel_map, save)) {
 if (pa_sink_flat_volume_enabled(root_sink)) {
-- 
1.8.1

___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


[pulseaudio-discuss] [PATCH RFC 4/4] device-restore: Remove the ability to restore volumes for sinks.

2013-01-04 Thread Damir Jelić
Volume saving/restoring for sinks is now provided by module-card-restore.
---
 src/modules/module-device-restore.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/modules/module-device-restore.c 
b/src/modules/module-device-restore.c
index 2a666ac..5504cb1 100644
--- a/src/modules/module-device-restore.c
+++ b/src/modules/module-device-restore.c
@@ -775,6 +775,7 @@ static pa_hook_result_t sink_fixate_hook_callback(pa_core 
*c, pa_sink_new_data *
 
 if ((e = perportentry_read(u, name, new_data->active_port))) {
 
+/*
 if (u->restore_volume && e->volume_valid) {
 
 if (!new_data->volume_is_set) {
@@ -791,6 +792,7 @@ static pa_hook_result_t sink_fixate_hook_callback(pa_core 
*c, pa_sink_new_data *
 } else
 pa_log_debug("Not restoring volume for sink %s, because 
already set.", new_data->name);
 }
+*/
 
 if (u->restore_muted && e->muted_valid) {
 
-- 
1.8.1

___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


Re: [pulseaudio-discuss] [PATCH RFC 4/4] device-restore: Remove the ability to restore volumes for sinks.

2013-01-14 Thread Damir Jelić
Hi David, thanks for the review.

On Fri, Jan 11, 2013 at 04:24:01PM +0100, David Henningsson wrote:
> On 01/05/2013 12:19 AM, poljar (Damir Jelić) wrote:
> >Volume saving/restoring for sinks is now provided by module-card-restore.
> 
> 1) What about sources and
> 2) What about sinks/sources that don't have ports?

1) Sources should be handled the same way as sinks, I'll add that in a
separate patch after I figure out the right way to handle sinks.

2) I guess eventually we want all sinks/sources to have at least one
port (virtual port?) but you are right for now we should provide a
fallback. I'll fix that in the next version of the patchset.
___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


Re: [pulseaudio-discuss] [PATCH RFC 1/4] device-port: Add volume to the ports struct.

2013-01-14 Thread Damir Jelić
On Fri, Jan 11, 2013 at 04:14:53PM +0100, David Henningsson wrote:
> One comment here, btw:
> 
> If we tell clients that the port volume changed, there should also
> be a way for the clients to tell the port volume. I e, you need to
> add the port volume in the PROTOCOL, introspect.h, and maybe a
> client function to set it too?

I wasn't sure if we want to confuse the user further with volume setting
controls, but sure I can add that too that shouldn't be too hard anyways.
___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


Re: [pulseaudio-discuss] [PATCH RFC 3/4] sink: Inherit the volume from the active port.

2013-01-14 Thread Damir Jelić
On Fri, Jan 11, 2013 at 04:13:18PM +0100, David Henningsson wrote:
> On 01/05/2013 12:19 AM, poljar (Damir Jelić) wrote:
> >Since the port now holds the volume information we can simply inherit
> >the volume from the active port if the volume isn't set while creating
> >the sink.
> 
> Here's where it gets tricky: sinks are having a massive amount of
> volumes, so I have difficulties telling all them apart. But I hope
> you're doing the right thing :-)
> 

More eyes would be welcome here, I'm not sure either. :P

> >
> >BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=55262
> >---
> >  src/pulsecore/sink.c | 14 +++---
> >  1 file changed, 11 insertions(+), 3 deletions(-)
> >
> >diff --git a/src/pulsecore/sink.c b/src/pulsecore/sink.c
> >index a8a91d6..37cabb6 100644
> >--- a/src/pulsecore/sink.c
> >+++ b/src/pulsecore/sink.c
> >@@ -276,7 +276,6 @@ pa_sink* pa_sink_new(
> >  s->n_corked = 0;
> >  s->input_to_master = NULL;
> >
> >-s->reference_volume = s->real_volume = data->volume;
> >  pa_cvolume_reset(&s->soft_volume, s->sample_spec.channels);
> >  s->base_volume = PA_VOLUME_NORM;
> >  s->n_volume_steps = PA_VOLUME_NORM+1;
> >@@ -309,10 +308,18 @@ pa_sink* pa_sink_new(
> >  s->active_port = p;
> >  }
> >
> >-if (s->active_port)
> >+if (s->active_port) {
> >  s->latency_offset = s->active_port->latency_offset;
> >-else
> >+
> >+if (pa_cvolume_valid(&s->active_port->volume) && 
> >!data->volume_is_set)
> >+s->reference_volume = s->real_volume = s->active_port->volume;
> >+else
> >+s->reference_volume = s->real_volume = data->volume;
> >+
> >+} else {
> >  s->latency_offset = 0;
> >+s->reference_volume = s->real_volume = data->volume;
> >+}
> >
> >  s->save_volume = data->save_volume;
> >  s->save_muted = data->save_muted;
> >@@ -1976,6 +1983,7 @@ void pa_sink_set_volume(
> >  }
> >
> >  pa_cvolume_remap(&new_reference_volume, &s->channel_map, 
> > &root_sink->channel_map);
> >+pa_device_port_set_volume(s->active_port, new_reference_volume);
> 
> Hmm, are we really guaranteed that (s->active_port != NULL) here? I
> don't think so.
> 

Yes that's a good catch. Will fix it.
___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


Re: [pulseaudio-discuss] [PATCH RFC 2/4] card-restore: Save/restore the volume for the ports.

2013-01-14 Thread Damir Jelić
On Fri, Jan 11, 2013 at 04:10:32PM +0100, David Henningsson wrote:
> On 01/05/2013 12:19 AM, poljar (Damir Jelić) wrote:
> >The card-restore module now saves and restores the volume per port.
> >This change includes a entry version bump.
> 
> No big comments here either, just minor stuff. Good work :-)
> 

Thanks David, I'll fix all your nitpicks. :p
___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


Re: [pulseaudio-discuss] [PATCH RFC 1/4] device-port: Add volume to the ports struct.

2013-01-15 Thread Damir Jelić
On Tue, Jan 15, 2013 at 09:42:11AM +0100, David Henningsson wrote:
> On 01/14/2013 01:58 PM, Damir Jelić wrote:
> >On Fri, Jan 11, 2013 at 04:14:53PM +0100, David Henningsson wrote:
> >>One comment here, btw:
> >>
> >>If we tell clients that the port volume changed, there should also
> >>be a way for the clients to tell the port volume. I e, you need to
> >>add the port volume in the PROTOCOL, introspect.h, and maybe a
> >>client function to set it too?
> >
> >I wasn't sure if we want to confuse the user further with volume setting
> >controls, but sure I can add that too that shouldn't be too hard anyways.
> 
> You can also act incrementally; so that you don't send the card
> change event in this patch (but possibly in a later patch).
> 
> I mean, it's probably confusing for a client to get a card change
> event, then go polling the card just to find that nothing (that it
> can read) has changed.
> 

The card change event is already needed for module-card-restore. I could 
move the event sending into the card-restore patch but I don't really 
see a need for this.
___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


Re: [pulseaudio-discuss] [PATCH RFC 1/4] device-port: Add volume to the ports struct.

2013-01-15 Thread Damir Jelić
On Tue, Jan 15, 2013 at 01:11:26PM +0100, David Henningsson wrote:
> On 01/15/2013 12:51 PM, Damir Jelić wrote:
> >On Tue, Jan 15, 2013 at 09:42:11AM +0100, David Henningsson wrote:
> >>On 01/14/2013 01:58 PM, Damir Jelić wrote:
> >>>On Fri, Jan 11, 2013 at 04:14:53PM +0100, David Henningsson wrote:
> >>>>One comment here, btw:
> >>>>
> >>>>If we tell clients that the port volume changed, there should also
> >>>>be a way for the clients to tell the port volume. I e, you need to
> >>>>add the port volume in the PROTOCOL, introspect.h, and maybe a
> >>>>client function to set it too?
> >>>
> >>>I wasn't sure if we want to confuse the user further with volume setting
> >>>controls, but sure I can add that too that shouldn't be too hard anyways.
> >>
> >>You can also act incrementally; so that you don't send the card
> >>change event in this patch (but possibly in a later patch).
> >>
> >>I mean, it's probably confusing for a client to get a card change
> >>event, then go polling the card just to find that nothing (that it
> >>can read) has changed.
> >>
> >
> >The card change event is already needed for module-card-restore. I could
> >move the event sending into the card-restore patch but I don't really
> >see a need for this.
> 
> Ok...this is not your fault, but maybe module-card-restore needs to
> change from using the event notification to using hooks instead?
> 
> From the problems we have in module-dbus-protocol, I like hooks
> better, as they more precisely control when things happen. It is
> easier to do things in the correct order.
> 

There was some talk about this during the summer, but I never got around
to actually fixing it. I'll add this to my TODO.
___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


[pulseaudio-discuss] (no subject)

2013-01-17 Thread Damir Jelić
Hi.

Patches 1-4 are just small cleanup/preparation patches for patch no. 5.

Patch 5 removes the event notifications from card-restore and replaces it
with hooks as David suggested a couple of day ago. 

This changes a lot of the code in card-restore but the functionality 
should stay the same, that is users shouldn't notice any difference.

Logging is a little more precise. We now print out what are the changes 
that we are actually storing (profile, latency offset, all of it...).

Below is the diffstat. Thanks.

 src/modules/module-card-restore.c | 241 
++---
 src/pulsecore/card.c  |  10 ++-
 src/pulsecore/core.h  |   1 +
 src/pulsecore/device-port.c   |  26 +--
 src/pulsecore/device-port.h   |   2 +
 5 files changed, 194 insertions(+), 86 deletions(-)


___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


[pulseaudio-discuss] [PATCH 1/5] device-port: Add a card pointer to the ports.

2013-01-17 Thread Damir Jelić
This way we can directly access the card that owns the port instead of
iterating over all cards.
---
 src/pulsecore/card.c| 10 +-
 src/pulsecore/device-port.c |  1 +
 src/pulsecore/device-port.h |  2 ++
 3 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/src/pulsecore/card.c b/src/pulsecore/card.c
index 1cde297..3077193 100644
--- a/src/pulsecore/card.c
+++ b/src/pulsecore/card.c
@@ -102,8 +102,10 @@ void pa_card_add_ports(pa_card *c, pa_hashmap *ports) {
 pa_assert(ports);
 
 /* take ownership of the ports */
-PA_HASHMAP_FOREACH(p, ports, state)
+PA_HASHMAP_FOREACH(p, ports, state) {
+p->card = c;
 pa_assert_se(pa_hashmap_put(c->ports, p->name, p) >= 0);
+}
 
 pa_subscription_post(c->core, 
PA_SUBSCRIPTION_EVENT_CARD|PA_SUBSCRIPTION_EVENT_CHANGE, c->index);
 
@@ -145,6 +147,7 @@ pa_card *pa_card_new(pa_core *core, pa_card_new_data *data) 
{
 const char *name;
 void *state;
 pa_card_profile *profile;
+pa_device_port *port;
 
 pa_core_assert_ref(core);
 pa_assert(data);
@@ -188,6 +191,11 @@ pa_card *pa_card_new(pa_core *core, pa_card_new_data 
*data) {
 profile->card = c;
 }
 
+if (c->ports) {
+PA_HASHMAP_FOREACH(port, c->ports, state)
+port->card = c;
+}
+
 c->active_profile = NULL;
 c->save_profile = FALSE;
 
diff --git a/src/pulsecore/device-port.c b/src/pulsecore/device-port.c
index 9ea54e3..cb6fa98 100644
--- a/src/pulsecore/device-port.c
+++ b/src/pulsecore/device-port.c
@@ -92,6 +92,7 @@ pa_device_port *pa_device_port_new(pa_core *c, const char 
*name, const char *des
 p->name = pa_xstrdup(name);
 p->description = pa_xstrdup(description);
 p->core = c;
+p->card = NULL;
 p->priority = 0;
 p->available = PA_PORT_AVAILABLE_UNKNOWN;
 p->profiles = pa_hashmap_new(pa_idxset_string_hash_func, 
pa_idxset_string_compare_func);
diff --git a/src/pulsecore/device-port.h b/src/pulsecore/device-port.h
index a5c6420..cea00e6 100644
--- a/src/pulsecore/device-port.h
+++ b/src/pulsecore/device-port.h
@@ -36,10 +36,12 @@ typedef struct pa_device_port pa_device_port;
 #include 
 #include 
 #include 
+#include 
 
 struct pa_device_port {
 pa_object parent; /* Needed for reference counting */
 pa_core *core;
+pa_card *card;
 
 char *name;
 char *description;
-- 
1.8.1.1

___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


[pulseaudio-discuss] [PATCH 2/5] device-port: Access the cards directly.

2013-01-17 Thread Damir Jelić
Since the ports now know which card owns them we don't need to iterate
through all of them anymore.
---
 src/pulsecore/device-port.c | 14 --
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/src/pulsecore/device-port.c b/src/pulsecore/device-port.c
index cb6fa98..93e539a 100644
--- a/src/pulsecore/device-port.c
+++ b/src/pulsecore/device-port.c
@@ -28,9 +28,8 @@ PA_DEFINE_PUBLIC_CLASS(pa_device_port, pa_object);
 
 void pa_device_port_set_available(pa_device_port *p, pa_port_available_t 
status)
 {
-uint32_t state;
-pa_card *card;
-/*pa_source *source;
+/*uint32_t state;
+pa_source *source;
 pa_sink *sink; */
 pa_core *core;
 
@@ -47,9 +46,7 @@ void pa_device_port_set_available(pa_device_port *p, 
pa_port_available_t status)
 
 /* Post subscriptions to the card which owns us */
 pa_assert_se(core = p->core);
-PA_IDXSET_FOREACH(card, core->cards, state)
-if (p == pa_hashmap_get(card->ports, p->name))
-pa_subscription_post(core, 
PA_SUBSCRIPTION_EVENT_CARD|PA_SUBSCRIPTION_EVENT_CHANGE, card->index);
+pa_subscription_post(core, 
PA_SUBSCRIPTION_EVENT_CARD|PA_SUBSCRIPTION_EVENT_CHANGE, p->card->index);
 #if 0
 /* This stuff is temporarily commented out while figuring out whether to 
actually do this */
 if (p->is_output)
@@ -118,7 +115,6 @@ void pa_device_port_hashmap_free(pa_hashmap *h) {
 void pa_device_port_set_latency_offset(pa_device_port *p, int64_t offset) {
 uint32_t state;
 pa_core *core;
-pa_card *card;
 
 pa_assert(p);
 
@@ -144,7 +140,5 @@ void pa_device_port_set_latency_offset(pa_device_port *p, 
int64_t offset) {
 }
 
 pa_assert_se(core = p->core);
-PA_IDXSET_FOREACH(card, core->cards, state)
-if (p == pa_hashmap_get(card->ports, p->name))
-pa_subscription_post(core, 
PA_SUBSCRIPTION_EVENT_CARD|PA_SUBSCRIPTION_EVENT_CHANGE, card->index);
+pa_subscription_post(core, 
PA_SUBSCRIPTION_EVENT_CARD|PA_SUBSCRIPTION_EVENT_CHANGE, p->card->index);
 }
-- 
1.8.1.1

___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


[pulseaudio-discuss] [PATCH 3/5] device-port: Cleanup of the sink/source subscription events.

2013-01-17 Thread Damir Jelić
Since it's now decided that we deprecated port info for sinks and
sources this isn't needed anymore.
---
 src/pulsecore/device-port.c | 14 --
 1 file changed, 14 deletions(-)

diff --git a/src/pulsecore/device-port.c b/src/pulsecore/device-port.c
index 93e539a..4ca26d9 100644
--- a/src/pulsecore/device-port.c
+++ b/src/pulsecore/device-port.c
@@ -28,9 +28,6 @@ PA_DEFINE_PUBLIC_CLASS(pa_device_port, pa_object);
 
 void pa_device_port_set_available(pa_device_port *p, pa_port_available_t 
status)
 {
-/*uint32_t state;
-pa_source *source;
-pa_sink *sink; */
 pa_core *core;
 
 pa_assert(p);
@@ -47,17 +44,6 @@ void pa_device_port_set_available(pa_device_port *p, 
pa_port_available_t status)
 /* Post subscriptions to the card which owns us */
 pa_assert_se(core = p->core);
 pa_subscription_post(core, 
PA_SUBSCRIPTION_EVENT_CARD|PA_SUBSCRIPTION_EVENT_CHANGE, p->card->index);
-#if 0
-/* This stuff is temporarily commented out while figuring out whether to 
actually do this */
-if (p->is_output)
-PA_IDXSET_FOREACH(sink, core->sinks, state)
-if (p == pa_hashmap_get(sink->ports, p->name))
-pa_subscription_post(core, 
PA_SUBSCRIPTION_EVENT_SINK|PA_SUBSCRIPTION_EVENT_CHANGE, sink->index);
-if (p->is_input)
-PA_IDXSET_FOREACH(source, core->sources, state)
-if (p == pa_hashmap_get(source->ports, p->name))
-pa_subscription_post(core, 
PA_SUBSCRIPTION_EVENT_SOURCE|PA_SUBSCRIPTION_EVENT_CHANGE, source->index);
-#endif
 
 pa_hook_fire(&core->hooks[PA_CORE_HOOK_PORT_AVAILABLE_CHANGED], p);
 }
-- 
1.8.1.1

___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


[pulseaudio-discuss] [PATCH 4/5] device-port: Fire a hook when the latency offset changes.

2013-01-17 Thread Damir Jelić
This change adds a new hook type: PA_CORE_HOOK_PORT_OFFSET_CHANGED
And it is fired when the port latency offset changes.
---
 src/pulsecore/core.h| 1 +
 src/pulsecore/device-port.c | 1 +
 2 files changed, 2 insertions(+)

diff --git a/src/pulsecore/core.h b/src/pulsecore/core.h
index cf7cc11..ad289ff 100644
--- a/src/pulsecore/core.h
+++ b/src/pulsecore/core.h
@@ -116,6 +116,7 @@ typedef enum pa_core_hook {
 PA_CORE_HOOK_CARD_PROFILE_ADDED,
 PA_CORE_HOOK_PORT_AVAILABLE_CHANGED,
 PA_CORE_HOOK_PORT_ADDED,
+PA_CORE_HOOK_PORT_OFFSET_CHANGED,
 PA_CORE_HOOK_MAX
 } pa_core_hook_t;
 
diff --git a/src/pulsecore/device-port.c b/src/pulsecore/device-port.c
index 4ca26d9..8b4cdd6 100644
--- a/src/pulsecore/device-port.c
+++ b/src/pulsecore/device-port.c
@@ -127,4 +127,5 @@ void pa_device_port_set_latency_offset(pa_device_port *p, 
int64_t offset) {
 
 pa_assert_se(core = p->core);
 pa_subscription_post(core, 
PA_SUBSCRIPTION_EVENT_CARD|PA_SUBSCRIPTION_EVENT_CHANGE, p->card->index);
+pa_hook_fire(&core->hooks[PA_CORE_HOOK_PORT_OFFSET_CHANGED], p);
 }
-- 
1.8.1.1

___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


[pulseaudio-discuss] [PATCH 5/5] card-restore: Only use hooks for the events.

2013-01-17 Thread Damir Jelić
Notification events can be error prone, this patch removes the use of
notification events from card-restore and replaces them with hooks.
---
 src/modules/module-card-restore.c | 241 --
 1 file changed, 178 insertions(+), 63 deletions(-)

diff --git a/src/modules/module-card-restore.c 
b/src/modules/module-card-restore.c
index 643e074..d515f37 100644
--- a/src/modules/module-card-restore.c
+++ b/src/modules/module-card-restore.c
@@ -62,10 +62,14 @@ static const char* const valid_modargs[] = {
 struct userdata {
 pa_core *core;
 pa_module *module;
-pa_subscription *subscription;
 pa_hook_slot *card_new_hook_slot;
+pa_hook_slot *card_put_hook_slot;
+pa_hook_slot *card_profile_hook_slot;
+pa_hook_slot *port_new_hook_slot;
+pa_hook_slot *port_offset_hook_slot;
 pa_time_event *save_time_event;
 pa_database *database;
+bool hooks_connected;
 };
 
 #define ENTRY_VERSION 2
@@ -110,6 +114,27 @@ static struct entry* entry_new(void) {
 return r;
 }
 
+static struct port_info *port_info_new(pa_device_port *port) {
+struct port_info *p_info;
+
+if (port) {
+p_info = pa_xnew(struct port_info, 1);
+p_info->name = pa_xstrdup(port->name);
+p_info->offset = port->latency_offset;
+} else
+p_info = pa_xnew0(struct port_info, 1);
+
+return p_info;
+}
+
+static void port_info_clone(struct port_info *p_info, pa_device_port *port) {
+pa_assert(p_info);
+pa_assert(port);
+
+p_info->name = pa_xstrdup(port->name);
+p_info->offset = port->latency_offset;
+}
+
 static void port_info_free(struct port_info *p_info, void *userdata) {
 pa_assert(p_info);
 
@@ -126,6 +151,44 @@ static void entry_free(struct entry* e) {
 pa_xfree(e);
 }
 
+static void entry_prepare_full(struct entry *entry , pa_card *card) {
+struct port_info *p_info;
+pa_device_port *port;
+void *state;
+
+if (card->save_profile)
+entry->profile = pa_xstrdup(card->active_profile->name);
+
+PA_HASHMAP_FOREACH(port, card->ports, state) {
+p_info = port_info_new(port);
+pa_assert_se(pa_hashmap_put(entry->ports, p_info->name, p_info) >= 0);
+}
+}
+
+static bool entrys_equal(struct entry *a, struct entry *b) {
+void *state;
+
+if (!pa_streq(a->profile, b->profile) ||
+pa_hashmap_size(a->ports) != pa_hashmap_size(b->ports))
+return false;
+
+else {
+struct port_info *Ap_info, *Bp_info;
+
+PA_HASHMAP_FOREACH(Ap_info, a->ports, state) {
+if ((Bp_info = pa_hashmap_get(b->ports, Ap_info->name))) {
+if (Ap_info->offset != Bp_info->offset) {
+return false;
+}
+
+} else {
+return false;
+}
+}
+}
+return true;
+}
+
 static pa_bool_t entry_write(struct userdata *u, const char *name, const 
struct entry *e) {
 pa_tagstruct *t;
 pa_datum key, data;
@@ -245,7 +308,7 @@ static struct entry* entry_read(struct userdata *u, const 
char *name) {
 pa_tagstruct_gets64(t, &port_offset) < 0)
 goto fail;
 
-p_info = pa_xnew(struct port_info, 1);
+p_info = port_info_new(NULL);
 p_info->name = pa_xstrdup(port_name);
 p_info->offset = port_offset;
 
@@ -286,82 +349,134 @@ fail:
 return NULL;
 }
 
-static void subscribe_callback(pa_core *c, pa_subscription_event_type_t t, 
uint32_t idx, void *userdata) {
-struct userdata *u = userdata;
+static void show_full_info (pa_card *card) {
+pa_assert(card);
+
+if (card->save_profile)
+pa_log_info("Storing profile and port latency offsets for card %s.", 
card->name);
+else
+pa_log_info("Storing port latency offsets for card %s.", card->name);
+}
+
+static pa_hook_result_t card_put_hook_callback(pa_core *c, pa_card *card, 
struct userdata *u) {
 struct entry *entry, *old;
-void *state;
-pa_card *card;
-pa_device_port *p;
-struct port_info *p_info;
 
 pa_assert(c);
-pa_assert(u);
 
-if (t != (PA_SUBSCRIPTION_EVENT_CARD|PA_SUBSCRIPTION_EVENT_NEW) &&
-t != (PA_SUBSCRIPTION_EVENT_CARD|PA_SUBSCRIPTION_EVENT_CHANGE))
-return;
+entry = entry_new();
+entry_prepare_full(entry, card);
 
-if (!(card = pa_idxset_get_by_index(c->cards, idx)))
-return;
+if ((old = entry_read(u, card->name))) {
+if (entrys_equal(entry, old))
+goto finish;
+else if (!card->save_profile)
+entry->profile = pa_xstrdup(old->profile);
+}
 
-entry = entry_new();
+show_full_info(card);
 
-if (card->save_profile)
-entry->profile = pa_xstrdup(card->active_profile->name);
+if (entry_write(u, card->name, entry))
+trigger_save(u);
 
-PA_HASHMAP_FOREACH(p, card->ports, state) {
-p_info = pa_xnew(struct port_info, 1);
-p_info->name = pa_xstrdup(p->name);
-

[pulseaudio-discuss] [PATCH 0/5] card-restore: Use only hooks.

2013-01-17 Thread Damir Jelić
Sorry, forgott the subject. :p
___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


Re: [pulseaudio-discuss] [PATCH 5/5] card-restore: Only use hooks for the events.

2013-01-20 Thread Damir Jelić
Hi Tanu.
Thanks for the review.

Here is v2 of the patch, I hope I fixed all the issues and didn't
introduce new ones. :p

I also found a bug where I don't initialize entry->profile (because
card->save->profile is false) and then check if two entries are equal.
Since entry->profile for one of them is NULL this resulted in a crash.

Patch attached.
>From 468a97fefe38dd39b2ea71232b0e039198e95e87 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?poljar=20=28Damir=20Jeli=C4=87=29?= 
Date: Tue, 15 Jan 2013 23:51:30 +0100
Subject: [PATCH v2] card-restore: Only use hooks for the events.

Notification events can be error prone, this patch removes the use of
notification events from card-restore and replaces them with hooks.
---
 src/modules/module-card-restore.c | 241 --
 1 file changed, 176 insertions(+), 65 deletions(-)

diff --git a/src/modules/module-card-restore.c 
b/src/modules/module-card-restore.c
index 643e074..51923fd 100644
--- a/src/modules/module-card-restore.c
+++ b/src/modules/module-card-restore.c
@@ -62,10 +62,14 @@ static const char* const valid_modargs[] = {
 struct userdata {
 pa_core *core;
 pa_module *module;
-pa_subscription *subscription;
 pa_hook_slot *card_new_hook_slot;
+pa_hook_slot *card_put_hook_slot;
+pa_hook_slot *card_profile_hook_slot;
+pa_hook_slot *port_new_hook_slot;
+pa_hook_slot *port_offset_hook_slot;
 pa_time_event *save_time_event;
 pa_database *database;
+bool hooks_connected;
 };
 
 #define ENTRY_VERSION 2
@@ -110,6 +114,28 @@ static struct entry* entry_new(void) {
 return r;
 }
 
+static struct port_info *port_info_new(pa_device_port *port) {
+struct port_info *p_info;
+
+if (port) {
+p_info = pa_xnew(struct port_info, 1);
+p_info->name = pa_xstrdup(port->name);
+p_info->offset = port->latency_offset;
+} else
+p_info = pa_xnew0(struct port_info, 1);
+
+return p_info;
+}
+
+static void port_info_update(struct port_info *p_info, pa_device_port *port) {
+pa_assert(p_info);
+pa_assert(port);
+
+pa_xfree(p_info->name);
+p_info->name = pa_xstrdup(port->name);
+p_info->offset = port->latency_offset;
+}
+
 static void port_info_free(struct port_info *p_info, void *userdata) {
 pa_assert(p_info);
 
@@ -126,6 +152,48 @@ static void entry_free(struct entry* e) {
 pa_xfree(e);
 }
 
+static struct entry *entry_from_card(pa_card *card) {
+struct port_info *p_info;
+struct entry *entry;
+pa_device_port *port;
+void *state;
+
+pa_assert(card);
+
+entry = entry_new();
+if (card->save_profile)
+entry->profile = pa_xstrdup(card->active_profile->name);
+
+PA_HASHMAP_FOREACH(port, card->ports, state) {
+p_info = port_info_new(port);
+pa_assert_se(pa_hashmap_put(entry->ports, p_info->name, p_info) >= 0);
+}
+
+return entry;
+}
+
+static bool entrys_equal(struct entry *a, struct entry *b) {
+struct port_info *Ap_info, *Bp_info;
+void *state;
+
+pa_assert(a);
+pa_assert(b);
+
+if (!pa_streq(a->profile, b->profile) ||
+pa_hashmap_size(a->ports) != pa_hashmap_size(b->ports))
+return false;
+
+PA_HASHMAP_FOREACH(Ap_info, a->ports, state) {
+if ((Bp_info = pa_hashmap_get(b->ports, Ap_info->name))) {
+if (Ap_info->offset != Bp_info->offset)
+return false;
+} else
+return false;
+}
+
+return true;
+}
+
 static pa_bool_t entry_write(struct userdata *u, const char *name, const 
struct entry *e) {
 pa_tagstruct *t;
 pa_datum key, data;
@@ -245,7 +313,7 @@ static struct entry* entry_read(struct userdata *u, const 
char *name) {
 pa_tagstruct_gets64(t, &port_offset) < 0)
 goto fail;
 
-p_info = pa_xnew(struct port_info, 1);
+p_info = port_info_new(NULL);
 p_info->name = pa_xstrdup(port_name);
 p_info->offset = port_offset;
 
@@ -286,82 +354,125 @@ fail:
 return NULL;
 }
 
-static void subscribe_callback(pa_core *c, pa_subscription_event_type_t t, 
uint32_t idx, void *userdata) {
-struct userdata *u = userdata;
+static void show_full_info(pa_card *card) {
+pa_assert(card);
+
+if (card->save_profile)
+pa_log_info("Storing profile and port latency offsets for card %s.", 
card->name);
+else
+pa_log_info("Storing port latency offsets for card %s.", card->name);
+}
+
+static pa_hook_result_t card_put_hook_callback(pa_core *c, pa_card *card, 
struct userdata *u) {
 struct entry *entry, *old;
-void *state;
-pa_card *card;
-pa_device_port *p;
-struct port_info *p_info;
 
-pa_assert(c);
-pa_assert(u);
+pa_assert(card);
 
-if (t != (PA_SUBSCRIPTION_EVENT_CARD|PA_SUBSCRIPTION_EVENT_NEW) &&
-t != (PA_SUBSCRIPTION_EVENT_CARD|PA_SUBSCRIPTION_EVENT_CHANGE))
-return;
+entry = entry_from_card(card);
 
-if (!(card = pa_idxset

[pulseaudio-discuss] Zsh completion for PulseAudio and utilities.

2013-01-21 Thread Damir Jelić
Hi.
When working with PulseAudio on the command line I really miss
completion for it so I've written this zsh completion. 

I'm not sure if this should be part of PulseAudio or zsh, but 
seeing that systemd ships its own completion, I assume that it
should be fine here.

Btw I'm not sure if I've modified the Makefile correctly.

Patch attached.
>From 1b20109e864305154505370ca5a9d491fb9e0c66 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?poljar=20=28Damir=20Jeli=C4=87=29?= 
Date: Sat, 19 Jan 2013 17:07:59 +0100
Subject: [PATCH] build: Add zsh completion

This patch adds zsh completion for pulseaudio and all of the utilities.
Channel maps and properties are not yet completed.

This should make mostly pactl/pacmd more usefull for zsh users.
---
 Makefile.am|   1 +
 shell-completion/pulseaudio-zsh-completion.zsh | 486 +
 2 files changed, 487 insertions(+)
 create mode 100644 shell-completion/pulseaudio-zsh-completion.zsh

diff --git a/Makefile.am b/Makefile.am
index 09fe5ef..dbaaa95 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -33,6 +33,7 @@ EXTRA_DIST = \
vala/libpulse.vapi \
vala/libpulse-mainloop-glib.deps \
vala/libpulse-mainloop-glib.vapi \
+   shell-completion/pulseaudio-zsh-completion.zsh \
.gitignore \
doxygen/.gitignore \
m4/.gitignore \
diff --git a/shell-completion/pulseaudio-zsh-completion.zsh 
b/shell-completion/pulseaudio-zsh-completion.zsh
new file mode 100644
index 000..c3baf9d
--- /dev/null
+++ b/shell-completion/pulseaudio-zsh-completion.zsh
@@ -0,0 +1,486 @@
+#compdef pulseaudio pactl pacmd pacat paplay parecord padsp pasuspender
+
+_devices() {
+local -a _device_list
+local cmd _device _device_description
+
+if [[ $service == pactl  || $service == pacmd ]]; then
+case $words[$((CURRENT - 1))] in
+set-sink-input-*) cmd=('sink-inputs');;
+set-sink-*) cmd=('sinks');;
+set-source-output-*) cmd=('source-outputs');;
+set-source-*) cmd=('sources');;
+suspend-sink) cmd=('sinks');;
+suspend-source) cmd=('sources');;
+move-sink-input) cmd=('sink-inputs');;
+move-source-output) cmd=('source-outputs');;
+kill-sink-input) cmd=('sink-inputs');;
+kill-source-output) cmd=('source-outputs');;
+esac
+
+case $words[$((CURRENT - 2))] in
+move-sink-input) cmd=('sinks');;
+move-source-output) cmd=('sources');;
+esac
+
+elif [[ $service == (pacat|paplay|parecord) ]]; then
+if [[ $words == *-r[[:space:]]* ]]; then
+cmd=('sources')
+elif [[ $words == *-p[[:space:]]* ]]; then
+cmd=('sinks')
+else
+cmd=('sinks' 'sources')
+fi
+
+elif [[ $service == paplay ]]; then
+cmd=('sinks')
+elif [[ $service == parecord ]]; then
+cmd=('sources')
+fi
+
+for target in $cmd; do
+for device_info in ${(ps:\n\n:)"$(_call_program card_tag "pactl list 
$target")"}; do
+for line in ${(f)device_info}; do
+if [[ $target == (sink-inputs|source-outputs) ]]; then
+if [[ $line == (Sink*Input|Source*Output)* ]]; then
+_device=${line#*\#}
+elif [[ $line == *application.name* ]]; then
+_device_description=${line#*= }
+fi
+
+else
+if [[ $words[$((CURRENT - 1))] == *set-sink-formats* ]]; 
then
+if [[ $line == Sink* ]]; then
+_device=${line#*\#}
+elif [[ $line == *Description:* ]]; then
+_device_description=${line#*: }
+fi
+
+else
+if [[ $line == *Name:* ]]; then
+_device=${line#*: }
+elif [[ $line == *Description:* ]]; then
+_device_description=${line#*: }
+fi
+fi
+fi
+done
+_device_list+=($_device:$_device_description)
+done
+done
+
+_describe 'device list' _device_list
+}
+
+_profiles() {
+local -a _profile_list
+local _current_card _raw_profiles _profile_name _profile_description
+
+_current_card=$words[$((CURRENT - 1))]
+
+for card in ${(ps:\n\n:)"$(_call_program card_tag "pactl list cards")"}; do
+if [[ $card == *$_current_card* ]]; then
+_raw_profiles=${card##*Profiles:}
+_raw_profiles=${_raw_profiles%%Active Profile:*}
+for profile in ${(f)_raw_profiles}; do
+if [[ $profile != [[:blank:]] ]]; then
+_profile_name=${profile%%: *}
+_profile_name=${_profile_name//[[:blank:]]/}
+_profile_name=${_

[pulseaudio-discuss] [PATCH] pactl: Add the ability to toggle mute state.

2013-01-23 Thread Damir Jelić
This patch adds the ability to toggle mute for sink/sources and
sink-inputs and source outputs.

All mute commands now accept 1|0|toggle as an argument.
---
 man/pactl.1.xml.in |   8 ++--
 src/utils/pactl.c  | 127 -
 2 files changed, 111 insertions(+), 24 deletions(-)

diff --git a/man/pactl.1.xml.in b/man/pactl.1.xml.in
index bae518c..1dc063d 100644
--- a/man/pactl.1.xml.in
+++ b/man/pactl.1.xml.in
@@ -209,22 +209,22 @@ USA.
 
 
 
-  set-sink-mute SINK 1|0
+  set-sink-mute SINK 1|0|toggle
   Set the mute status of the specified sink (identified by its 
symbolic name or numerical index).
 
 
 
-  set-source-mute SOURCE 1|0
+  set-source-mute SOURCE 1|0|toggle
   Set the mute status of the specified source (identified by 
its symbolic name or numerical index).
 
 
 
-  set-sink-input-mute INPUT 1|0
+  set-sink-input-mute INPUT 
1|0|toggle
   Set the mute status of the specified sink input (identified 
by its numerical index).
 
 
 
-  set-source-output-mute INPUT 1|0
+  set-source-output-mute INPUT 
1|0|toggle
   Set the mute status of the specified source output 
(identified by its numerical index).
 
 
diff --git a/src/utils/pactl.c b/src/utils/pactl.c
index 8d1d947..89bc6da 100644
--- a/src/utils/pactl.c
+++ b/src/utils/pactl.c
@@ -69,7 +69,6 @@ static pa_bool_t short_list_format = FALSE;
 static uint32_t module_index;
 static int32_t latency_offset;
 static pa_bool_t suspend;
-static pa_bool_t mute;
 static pa_volume_t volume;
 static enum volume_flags {
 VOL_UINT = 0,
@@ -80,6 +79,13 @@ static enum volume_flags {
 VOL_RELATIVE = 1 << 4,
 } volume_flags;
 
+static enum mute_flags {
+INVALID_MUTE = -1,
+UNMUTE = 0,
+MUTE = 1,
+TOGGLE_MUTE = 2
+} mute = INVALID_MUTE;
+
 static pa_proplist *proplist = NULL;
 
 static SNDFILE *sndfile = NULL;
@@ -958,6 +964,66 @@ static void get_source_output_volume_callback(pa_context 
*c, const pa_source_out
 pa_operation_unref(pa_context_set_source_output_volume(c, 
source_output_idx, &cv, simple_callback, NULL));
 }
 
+static void sink_toggle_mute_callback(pa_context *c, const pa_sink_info *i, 
int is_last, void *userdata) {
+if (is_last < 0) {
+pa_log(_("Failed to get sink information: %s"), 
pa_strerror(pa_context_errno(c)));
+quit(1);
+return;
+}
+
+if (is_last)
+return;
+
+pa_assert(i);
+
+pa_operation_unref(pa_context_set_sink_mute_by_name(c, i->name, !i->mute, 
simple_callback, NULL));
+}
+
+static void source_toggle_mute_callback(pa_context *c, const pa_source_info 
*o, int is_last, void *userdata) {
+if (is_last < 0) {
+pa_log(_("Failed to get source information: %s"), 
pa_strerror(pa_context_errno(c)));
+quit(1);
+return;
+}
+
+if (is_last)
+return;
+
+pa_assert(o);
+
+pa_operation_unref(pa_context_set_source_mute_by_name(c, o->name, 
!o->mute, simple_callback, NULL));
+}
+
+static void sink_input_toggle_mute_callback(pa_context *c, const 
pa_sink_input_info *i, int is_last, void *userdata) {
+if (is_last < 0) {
+pa_log(_("Failed to get sink input information: %s"), 
pa_strerror(pa_context_errno(c)));
+quit(1);
+return;
+}
+
+if (is_last)
+return;
+
+pa_assert(i);
+
+pa_operation_unref(pa_context_set_sink_input_mute(c, i->index, !i->mute, 
simple_callback, NULL));
+}
+
+static void source_output_toggle_mute_callback(pa_context *c, const 
pa_source_output_info *o, int is_last, void *userdata) {
+if (is_last < 0) {
+pa_log(_("Failed to get source output information: %s"), 
pa_strerror(pa_context_errno(c)));
+quit(1);
+return;
+}
+
+if (is_last)
+return;
+
+pa_assert(o);
+
+pa_operation_unref(pa_context_set_source_output_mute(c, o->index, 
!o->mute, simple_callback, NULL));
+}
+
 /* PA_MAX_FORMATS is defined in internal.h so we just define a sane value here 
*/
 #define MAX_FORMATS 256
 
@@ -1223,19 +1289,31 @@ static void context_state_callback(pa_context *c, void 
*userdata) {
 break;
 
 case SET_SINK_MUTE:
-pa_operation_unref(pa_context_set_sink_mute_by_name(c, 
sink_name, mute, simple_callback, NULL));
+if (mute == TOGGLE_MUTE)
+pa_operation_unref(pa_context_get_sink_info_by_name(c, 
sink_name, sink_toggle_mute_callback, NULL));
+else
+pa_operation_unref(pa_context_set_sink_mute_by_name(c, 
sink_name, mute, simple_callback, NULL));
 break;
 
 case SET_SOURCE_MUTE:
-pa_operation_unref(pa_context_set_source_mute_by_name(c, 
source_name, mute, simple_callback, NULL));
+if (mute == TOGGLE_MUTE)
+
pa_operation_unref(pa_context_get_source_info_by_name(c, sou

[pulseaudio-discuss] [PATCH 1/2] pactl: Add a command for setting the default sink/source.

2013-01-29 Thread Damir Jelić
This adds two new commands to pactl:
set-sink-set-default
set-source-set-default

This command has been part of the native protocol for a long time,
no reason not to expose it in the client API and pactl.
---
 man/pactl.1.xml.in | 10 ++
 src/map-file   |  2 ++
 src/pulse/introspect.c | 44 
 src/pulse/introspect.h |  6 ++
 src/utils/pactl.c  | 31 +++
 5 files changed, 93 insertions(+)

diff --git a/man/pactl.1.xml.in b/man/pactl.1.xml.in
index 1dc063d..aa3c78d 100644
--- a/man/pactl.1.xml.in
+++ b/man/pactl.1.xml.in
@@ -163,11 +163,21 @@ USA.
 
 
 
+  set-sink-default SINK
+  Make the specified sink (identified by its symbolic name) 
the default sink.
+
+
+
   set-sink-port SINK PORT
   Set the specified sink (identified by its symbolic name or 
numerical index) to the specified port (identified by its symbolic 
name).
 
 
 
+  set-source-default SOURCE
+  Make the specified source (identified by its symbolic name) 
the default source.
+
+
+
   set-source-port SOURCE PORT
   Set the specified source (identified by its symbolic name or 
numerical index) to the specified port (identified by its symbolic 
name).
 
diff --git a/src/map-file b/src/map-file
index 91d61c2..b50dbdc 100644
--- a/src/map-file
+++ b/src/map-file
@@ -96,6 +96,7 @@ pa_context_set_sink_mute_by_index;
 pa_context_set_sink_mute_by_name;
 pa_context_set_sink_port_by_index;
 pa_context_set_sink_port_by_name;
+pa_context_set_sink_default_by_name;
 pa_context_set_sink_volume_by_index;
 pa_context_set_sink_volume_by_name;
 pa_context_set_source_output_mute;
@@ -104,6 +105,7 @@ pa_context_set_source_mute_by_index;
 pa_context_set_source_mute_by_name;
 pa_context_set_source_port_by_index;
 pa_context_set_source_port_by_name;
+pa_context_set_source_default_by_name;
 pa_context_set_source_volume_by_index;
 pa_context_set_source_volume_by_name;
 pa_context_set_state_callback;
diff --git a/src/pulse/introspect.c b/src/pulse/introspect.c
index 9ca3fd3..e959e96 100644
--- a/src/pulse/introspect.c
+++ b/src/pulse/introspect.c
@@ -405,6 +405,28 @@ pa_operation* pa_context_set_sink_port_by_name(pa_context 
*c, const char *name,
 return o;
 }
 
+pa_operation* pa_context_set_sink_default_by_name(pa_context *c, const char 
*name, pa_context_success_cb_t cb, void *userdata) {
+pa_operation *o;
+pa_tagstruct *t;
+uint32_t tag;
+
+pa_assert(c);
+pa_assert(PA_REFCNT_VALUE(c) >= 1);
+
+PA_CHECK_VALIDITY_RETURN_NULL(c, !pa_detect_fork(), PA_ERR_FORKED);
+PA_CHECK_VALIDITY_RETURN_NULL(c, c->state == PA_CONTEXT_READY, 
PA_ERR_BADSTATE);
+PA_CHECK_VALIDITY_RETURN_NULL(c, !name || *name, PA_ERR_INVALID);
+
+o = pa_operation_new(c, NULL, (pa_operation_cb_t) cb, userdata);
+
+t = pa_tagstruct_command(c, PA_COMMAND_SET_DEFAULT_SINK, &tag);
+pa_tagstruct_puts(t, name);
+pa_pstream_send_tagstruct(c->pstream, t);
+pa_pdispatch_register_reply(c->pdispatch, tag, DEFAULT_TIMEOUT, 
pa_context_simple_ack_callback, pa_operation_ref(o), (pa_free_cb_t) 
pa_operation_unref);
+
+return o;
+}
+
 /*** Source info ***/
 
 static void context_get_source_info_callback(pa_pdispatch *pd, uint32_t 
command, uint32_t tag, pa_tagstruct *t, void *userdata) {
@@ -678,6 +700,28 @@ pa_operation* 
pa_context_set_source_port_by_name(pa_context *c, const char *name
 return o;
 }
 
+pa_operation* pa_context_set_source_default_by_name(pa_context *c, const char 
*name, pa_context_success_cb_t cb, void *userdata) {
+pa_operation *o;
+pa_tagstruct *t;
+uint32_t tag;
+
+pa_assert(c);
+pa_assert(PA_REFCNT_VALUE(c) >= 1);
+
+PA_CHECK_VALIDITY_RETURN_NULL(c, !pa_detect_fork(), PA_ERR_FORKED);
+PA_CHECK_VALIDITY_RETURN_NULL(c, c->state == PA_CONTEXT_READY, 
PA_ERR_BADSTATE);
+PA_CHECK_VALIDITY_RETURN_NULL(c, !name || *name, PA_ERR_INVALID);
+
+o = pa_operation_new(c, NULL, (pa_operation_cb_t) cb, userdata);
+
+t = pa_tagstruct_command(c, PA_COMMAND_SET_DEFAULT_SOURCE, &tag);
+pa_tagstruct_puts(t, name);
+pa_pstream_send_tagstruct(c->pstream, t);
+pa_pdispatch_register_reply(c->pdispatch, tag, DEFAULT_TIMEOUT, 
pa_context_simple_ack_callback, pa_operation_ref(o), (pa_free_cb_t) 
pa_operation_unref);
+
+return o;
+}
+
 /*** Client info ***/
 
 static void context_get_client_info_callback(pa_pdispatch *pd, uint32_t 
command, uint32_t tag, pa_tagstruct *t, void *userdata) {
diff --git a/src/pulse/introspect.h b/src/pulse/introspect.h
index a833471..fd6f289 100644
--- a/src/pulse/introspect.h
+++ b/src/pulse/introspect.h
@@ -271,6 +271,9 @@ pa_operation* pa_context_set_sink_port_by_index(pa_context 
*c, uint32_t idx, con
 /** Change the profile of a sink. \since 0.9.15 */
 pa_operation* pa_context_set_sink_port_by_name(pa_context *c, const char*name, 
const char*port, pa_context_success_cb_t cb, void *userdata);
 
+/** Chang

[pulseaudio-discuss] [PATCH 2/2] pactl: Show the default sink/source in the list command.

2013-01-29 Thread Damir Jelić
This includes exposing the information in the protocol for the
get sink/source info commands and adding 2 new reply fields for
these commands.

Update protocol to 28.
---
 PROTOCOL| 10 ++
 configure.ac|  2 +-
 src/modules/module-tunnel.c | 10 ++
 src/pulse/introspect.c  | 14 ++
 src/pulse/introspect.h  |  2 ++
 src/pulsecore/protocol-native.c | 18 ++
 src/utils/pactl.c   |  4 
 7 files changed, 59 insertions(+), 1 deletion(-)

diff --git a/PROTOCOL b/PROTOCOL
index 01abeed..d0ea360 100644
--- a/PROTOCOL
+++ b/PROTOCOL
@@ -333,6 +333,16 @@ PA_COMMAND_GET_CARD_INFO(_LIST)):
 
 The field is added once for every port.
 
+## v28, implemented by >= 3.0
+
+New field in reply from PA_COMMAND_GET_SINK_INFO (and thus
+PA_COMMAND_GET_SINK_INFO_LIST)
+bool sink_default
+
+New field in reply from PA_COMMAND_GET_SOURCE_INFO (and thus
+PA_COMMAND_GET_SOURCE_INFO_LIST)
+bool source_default
+
  If you just changed the protocol, read this
 ## module-tunnel depends on the sink/source/sink-input/source-input protocol
 ## internals, so if you changed these, you might have broken module-tunnel.
diff --git a/configure.ac b/configure.ac
index 6d340fd..89d7ee3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -40,7 +40,7 @@ AC_SUBST(PA_MINOR, pa_minor)
 AC_SUBST(PA_MAJORMINOR, pa_major.pa_minor)
 
 AC_SUBST(PA_API_VERSION, 12)
-AC_SUBST(PA_PROTOCOL_VERSION, 27)
+AC_SUBST(PA_PROTOCOL_VERSION, 28)
 
 # The stable ABI for client applications, for the version info x:y:z
 # always will hold y=z
diff --git a/src/modules/module-tunnel.c b/src/modules/module-tunnel.c
index 66b9617..993bbb0 100644
--- a/src/modules/module-tunnel.c
+++ b/src/modules/module-tunnel.c
@@ -1063,6 +1063,7 @@ static void sink_info_cb(pa_pdispatch *pd, uint32_t 
command,  uint32_t tag, pa_t
 pa_channel_map cm;
 pa_cvolume volume;
 pa_bool_t mute;
+bool sink_default;
 pa_usec_t latency;
 
 pa_assert(pd);
@@ -1125,6 +1126,10 @@ static void sink_info_cb(pa_pdispatch *pd, uint32_t 
command,  uint32_t tag, pa_t
 if (u->version >= 21 && read_formats(u, t) < 0)
 goto fail;
 
+if (u->version >=28)
+if (pa_tagstruct_get_boolean(t, &sink_default) < 0)
+goto fail;
+
 if (!pa_tagstruct_eof(t)) {
 pa_log("Packet too long");
 goto fail;
@@ -1264,6 +1269,7 @@ static void source_info_cb(pa_pdispatch *pd, uint32_t 
command,  uint32_t tag, pa
 pa_channel_map cm;
 pa_cvolume volume;
 pa_bool_t mute;
+bool source_default;
 pa_usec_t latency, configured_latency;
 
 pa_assert(pd);
@@ -1324,6 +1330,10 @@ static void source_info_cb(pa_pdispatch *pd, uint32_t 
command,  uint32_t tag, pa
 if (u->version >= 22 && read_formats(u, t) < 0)
 goto fail;
 
+if (u->version >=28)
+if (pa_tagstruct_get_boolean(t, &source_default) < 0)
+goto fail;
+
 if (!pa_tagstruct_eof(t)) {
 pa_log("Packet too long");
 goto fail;
diff --git a/src/pulse/introspect.c b/src/pulse/introspect.c
index e959e96..ff86022 100644
--- a/src/pulse/introspect.c
+++ b/src/pulse/introspect.c
@@ -253,6 +253,13 @@ static void context_get_sink_info_callback(pa_pdispatch 
*pd, uint32_t command, u
 }
 }
 
+if (o->context->version >= 28) {
+bool sink_default;
+if (pa_tagstruct_get_boolean(t, &sink_default) < 0)
+goto fail;
+i.sink_default = (int) sink_default;
+}
+
 i.mute = (int) mute;
 i.flags = (pa_sink_flags_t) flags;
 i.state = (pa_sink_state_t) state;
@@ -548,6 +555,13 @@ static void context_get_source_info_callback(pa_pdispatch 
*pd, uint32_t command,
 }
 }
 
+if (o->context->version >= 28) {
+bool source_default;
+if (pa_tagstruct_get_boolean(t, &source_default) < 0)
+goto fail;
+i.source_default = (int) source_default;
+}
+
 i.mute = (int) mute;
 i.flags = (pa_source_flags_t) flags;
 i.state = (pa_source_state_t) state;
diff --git a/src/pulse/introspect.h b/src/pulse/introspect.h
index fd6f289..f546955 100644
--- a/src/pulse/introspect.h
+++ b/src/pulse/introspect.h
@@ -233,6 +233,7 @@ typedef struct pa_sink_info {
 pa_sink_port_info* active_port;/**< Pointer to active port in the 
array, or NULL. \since 0.9.16 */
 uint8_t n_formats; /**< Number of formats supported by the 
sink. \since 1.0 */
 pa_format_info **formats;  /**< Array of formats supported by the 
sink. \since 1.0 */
+int sink_default;  /**< Default sink flag. \since 4.0 */
 } pa_sink_info;
 
 /** Callback prototype for pa_context_get_sink_info_by_name() and friends */
@@ -316,6 +317,7 @@ typedef struct pa_sou

Re: [pulseaudio-discuss] [PATCH 2/2] pactl: Show the default sink/source in the list command.

2013-01-29 Thread Damir Jelić
On Wed, Jan 30, 2013 at 02:05:29AM +0100, David Henningsson wrote:
> On 01/29/2013 05:41 PM, poljar (Damir Jelić) wrote:
> >This includes exposing the information in the protocol for the
> >get sink/source info commands and adding 2 new reply fields for
> >these commands.
> >
> >Update protocol to 28.
> >---
> >  PROTOCOL| 10 ++
> >  configure.ac|  2 +-
> >  src/modules/module-tunnel.c | 10 ++
> >  src/pulse/introspect.c  | 14 ++
> >  src/pulse/introspect.h  |  2 ++
> >  src/pulsecore/protocol-native.c | 18 ++
> >  src/utils/pactl.c   |  4 
> >  7 files changed, 59 insertions(+), 1 deletion(-)
> >
> >diff --git a/PROTOCOL b/PROTOCOL
> >index 01abeed..d0ea360 100644
> >--- a/PROTOCOL
> >+++ b/PROTOCOL
> >@@ -333,6 +333,16 @@ PA_COMMAND_GET_CARD_INFO(_LIST)):
> >
> >  The field is added once for every port.
> >
> >+## v28, implemented by >= 3.0
> 
> You probably mean >= 4.0 ?
> 
Oh, yeah you're right about that.

> Otherwise looks good (I did a quick read review only, no testing).
> 
> (Slightly cleaner to have the pactl changes in a separate patch but
> I'm not picky about that.)
> 

I wasn't even sure if we want to print that info since it's available
with 'pactl info' and I'm not sure if I should hide that info if the
protocol doesn't support this (if it's not supported it prints always
'no').

Thanks for the review.
___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


[pulseaudio-discuss] [PATCH v2] pactl: Add a command for setting the default sink/source.

2013-01-30 Thread Damir Jelić
This adds two new commands to pactl:
set-default-sink
set-default-source

This command has been part of the native protocol for a long time,
no reason not to expose it in pactl.
---
 man/pactl.1.xml.in | 10 ++
 src/utils/pactl.c  | 31 +++
 2 files changed, 41 insertions(+)

diff --git a/man/pactl.1.xml.in b/man/pactl.1.xml.in
index 1dc063d..29071b3 100644
--- a/man/pactl.1.xml.in
+++ b/man/pactl.1.xml.in
@@ -163,11 +163,21 @@ USA.
 
 
 
+  set-default-sink SINK
+  Make the specified sink (identified by its symbolic name) 
the default sink.
+
+
+
   set-sink-port SINK PORT
   Set the specified sink (identified by its symbolic name or 
numerical index) to the specified port (identified by its symbolic 
name).
 
 
 
+  set-default-source SOURCE
+  Make the specified source (identified by its symbolic name) 
the default source.
+
+
+
   set-source-port SOURCE PORT
   Set the specified source (identified by its symbolic name or 
numerical index) to the specified port (identified by its symbolic 
name).
 
diff --git a/src/utils/pactl.c b/src/utils/pactl.c
index 79b1545..020085d 100644
--- a/src/utils/pactl.c
+++ b/src/utils/pactl.c
@@ -114,7 +114,9 @@ static enum {
 SUSPEND_SOURCE,
 SET_CARD_PROFILE,
 SET_SINK_PORT,
+SET_DEFAULT_SINK,
 SET_SOURCE_PORT,
+SET_DEFAULT_SOURCE,
 SET_SINK_VOLUME,
 SET_SOURCE_VOLUME,
 SET_SINK_INPUT_VOLUME,
@@ -1284,10 +1286,18 @@ static void context_state_callback(pa_context *c, void 
*userdata) {
 pa_operation_unref(pa_context_set_sink_port_by_name(c, 
sink_name, port_name, simple_callback, NULL));
 break;
 
+case SET_DEFAULT_SINK:
+pa_operation_unref(pa_context_set_default_sink(c, 
sink_name, simple_callback, NULL));
+break;
+
 case SET_SOURCE_PORT:
 pa_operation_unref(pa_context_set_source_port_by_name(c, 
source_name, port_name, simple_callback, NULL));
 break;
 
+case SET_DEFAULT_SOURCE:
+pa_operation_unref(pa_context_set_default_source(c, 
source_name, simple_callback, NULL));
+break;
+
 case SET_SINK_MUTE:
 if (mute == TOGGLE_MUTE)
 pa_operation_unref(pa_context_get_sink_info_by_name(c, 
sink_name, sink_toggle_mute_callback, NULL));
@@ -1491,6 +1501,7 @@ static void help(const char *argv0) {
 printf("%s %s %s %s\n", argv0, _("[options]"), 
"move-(sink-input|source-output)", _("#N SINK|SOURCE"));
 printf("%s %s %s %s\n", argv0, _("[options]"), "suspend-(sink|source)", 
_("NAME|#N 1|0"));
 printf("%s %s %s %s\n", argv0, _("[options]"), "set-card-profile ", 
_("CARD PROFILE"));
+printf("%s %s %s %s\n", argv0, _("[options]"), 
"set-default-(sink|source)", _("NAME"));
 printf("%s %s %s %s\n", argv0, _("[options]"), "set-(sink|source)-port", 
_("NAME|#N PORT"));
 printf("%s %s %s %s\n", argv0, _("[options]"), "set-(sink|source)-volume", 
_("NAME|#N VOLUME"));
 printf("%s %s %s %s\n", argv0, _("[options]"), 
"set-(sink-input|source-output)-volume", _("#N VOLUME"));
@@ -1779,6 +1790,16 @@ int main(int argc, char *argv[]) {
 sink_name = pa_xstrdup(argv[optind+1]);
 port_name = pa_xstrdup(argv[optind+2]);
 
+} else if (pa_streq(argv[optind], "set-default-sink")) {
+action = SET_DEFAULT_SINK;
+
+if (argc != optind+2) {
+pa_log(_("You have to specify a sink name"));
+goto quit;
+}
+
+sink_name = pa_xstrdup(argv[optind+1]);
+
 } else if (pa_streq(argv[optind], "set-source-port")) {
 action = SET_SOURCE_PORT;
 
@@ -1790,6 +1811,16 @@ int main(int argc, char *argv[]) {
 source_name = pa_xstrdup(argv[optind+1]);
 port_name = pa_xstrdup(argv[optind+2]);
 
+} else if (pa_streq(argv[optind], "set-default-source")) {
+action = SET_DEFAULT_SOURCE;
+
+if (argc != optind+2) {
+pa_log(_("You have to specify a source name"));
+goto quit;
+}
+
+source_name = pa_xstrdup(argv[optind+1]);
+
 } else if (pa_streq(argv[optind], "set-sink-volume")) {
 action = SET_SINK_VOLUME;
 
-- 
1.8.1.2

___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


[pulseaudio-discuss] [PATCH] build: Add bash completion

2013-01-30 Thread Damir Jelić
This patch adds bash completion for pulseaudio and all of the utilities.
Channel maps and properties are not yet completed.

This should make mostly pactl/pacmd more useful for bash users.

Thanks to Denis Kasak for the awk magic (fetching ports and profiles
from the card info).
---
 Makefile.am|   1 +
 shell-completion/pulseaudio-bash-completion.sh | 561 +
 2 files changed, 562 insertions(+)
 create mode 100644 shell-completion/pulseaudio-bash-completion.sh

diff --git a/Makefile.am b/Makefile.am
index dbaaa95..893bc24 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -34,6 +34,7 @@ EXTRA_DIST = \
vala/libpulse-mainloop-glib.deps \
vala/libpulse-mainloop-glib.vapi \
shell-completion/pulseaudio-zsh-completion.zsh \
+   shell-completion/pulseaudio-bash-completion.sh \
.gitignore \
doxygen/.gitignore \
m4/.gitignore \
diff --git a/shell-completion/pulseaudio-bash-completion.sh 
b/shell-completion/pulseaudio-bash-completion.sh
new file mode 100644
index 000..686178e
--- /dev/null
+++ b/shell-completion/pulseaudio-bash-completion.sh
@@ -0,0 +1,561 @@
+#!/bin/bash
+
+__cards () {
+while IFS=$'\t' read idx name _; do
+printf "%s %s\n" "$idx" "$name"
+done < <(pactl list cards short 2> /dev/null)
+}
+
+__sinks () {
+while IFS=$'\t' read _ name _ _ _; do
+printf "%s\n" "$name"
+done < <(pactl list sinks short 2> /dev/null)
+}
+
+__sinks_idx () {
+while IFS=$'\t' read idx _ _ _ _; do
+printf "%s\n" "$idx"
+done < <(pactl list sinks short 2> /dev/null)
+}
+
+__sources () {
+while IFS=$'\t' read _ name _ _ _; do
+printf "%s\n" "$name"
+done < <(pactl list sources short 2> /dev/null)
+}
+
+__sink_inputs () {
+while IFS=$'\t' read idx _ _ _ _; do
+printf "%s\n" "$idx"
+done < <(pactl list sink-inputs short 2> /dev/null)
+}
+
+__source_outputs () {
+while IFS=$'\t' read idx _ _ _ _; do
+printf "%s\n" "$idx"
+done < <(pactl list source-outputs short 2> /dev/null)
+}
+
+__ports () {
+pactl list cards 2> /dev/null | awk -e \
+'/^\tPorts:/ {
+flag=1; next
+ }
+
+ /^\t[A-Za-z]/ {
+ flag=0
+ }
+
+ flag {
+ if (/^\t\t[A-Za-z]/)
+ ports = ports substr($0, 3, index($0, ":")-3) " "
+ }
+
+ END {
+ print ports
+ }'
+}
+
+__profiles () {
+pactl list cards 2> /dev/null | awk -e \
+'/^\tProfiles:/ {
+flag=1; next
+}
+
+/^\t[A-Za-z]/ {
+flag=0
+}
+
+flag {
+if (/^\t\t[A-Za-z]/)
+profiles = profiles substr($0, 3, index($0, ": ")-3) " "
+}
+
+END {
+print profiles
+}'
+}
+
+__all_modules () {
+while read name; do
+name=${name%% *}
+printf "%s\n" "$name"
+done < <(pulseaudio --dump-modules 2> /dev/null)
+}
+
+__loaded_modules () {
+while IFS=$'\t' read idx name _; do
+printf "%s %s\n" "$idx" "$name"
+done < <(pactl list modules short 2> /dev/null)
+}
+
+__resample_methods () {
+while read name; do
+printf "%s\n" "$name"
+done < <(pulseaudio --dump-resample-methods 2> /dev/null)
+}
+
+_pacat_file_formats () {
+while IFS=$'\t' read name _; do
+printf "%s\n" "$name"
+done < <(pacat --list-file-formats 2> /dev/null)
+}
+
+in_array() {
+local i
+for i in "${@:2}"; do
+[[ $1 = "$i" ]] && return
+done
+}
+
+_pactl() {
+local cur prev words cword preprev command
+local comps
+local flags='-h --help --version -s --server= --client-name='
+local list_types='short sinks sources sink-inputs source outputs cards
+modules samples clients'
+local commands=(stat info list exit upload-sample play-sample remove-sample
+load-module unload-module move-sink-input 
move-source-output
+suspend-sink suspend-source set-card-profile set-sink-port
+set-source-port set-sink-volume set-source-volume
+set-sink-input-volume set-source-output-volume 
set-sink-mute
+set-source-mute set-sink-input-mute set-source-output-mute
+set-sink-formats set-port-latency-offset subscribe help)
+
+_init_completion -n = || return
+preprev=${words[$cword-2]}
+
+for word in "${COMP_WORDS[@]}"; do
+if in_array "$word" "${commands[@]}"; then
+command=$word
+break
+fi
+done
+
+case $preprev in
+list) COMPREPLY=($(compgen -W 'short' -- "$cur")) ;;
+
+play-sample)
+comps=$(__sinks)
+COMPREPLY=($(compgen -W '${comps[*]}' -- "$cur"))
+;;
+
+move-sink-input)
+comps=$(__sinks)
+COMPREPLY=($(compgen -W '${comps[*]}' -- "$cur"))
+;;
+

[pulseaudio-discuss] [PATCH] bash-completion: Don't complete devices in the list commands

2013-01-31 Thread Damir Jelić
This fixes some wrong completion for the list commands for example:
pactl list sinks _sink_name_
---
 shell-completion/pulseaudio-bash-completion.sh | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/shell-completion/pulseaudio-bash-completion.sh 
b/shell-completion/pulseaudio-bash-completion.sh
index 686178e..a82b10e 100644
--- a/shell-completion/pulseaudio-bash-completion.sh
+++ b/shell-completion/pulseaudio-bash-completion.sh
@@ -174,6 +174,7 @@ _pactl() {
 _known_hosts_real "$cur"
 ;;
 esac
+[[ $COMPREPLY ]] && return 0
 
 case $prev in
 list) COMPREPLY=($(compgen -W '${list_types[*]}' -- "$cur")) ;;
@@ -234,6 +235,7 @@ _pactl() {
 -s)
 _known_hosts_real "$cur" ;;
 esac
+[[ $COMPREPLY ]] && return 0
 
 case $cur in
 --server=*)
@@ -316,6 +318,7 @@ _pacmd() {
 esac
 
 case $prev in
+list-*) ;;
 describe-module|load-module)
 comps=$(__all_modules)
 COMPREPLY=($(compgen -W '${comps[*]}' -- "$cur"))
-- 
1.8.1.2

___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


Re: [pulseaudio-discuss] Setting default sink programmatically in PulseAudio 2.1

2013-02-18 Thread Damir Jelić
Hi.

On Thu, Feb 14, 2013 at 07:55:51PM +0100, Frank Groeneveld wrote:
> Hello,
> 
> I'm trying to develop a program that will capture all audio using
> PulseAudio 2.1. It needs to capture this and prevent the audio from
> being played back over the default speakers. To achive this, I'm
> loading the null module programmatically like so:
> 
> pa_context_load_module(context, "module-null-sink", NULL,
> module_loaded, userdata);
> 
> This works great and the callback receives an index number of the
> sink. However, I can't seem to find out how to set the default sink to
> this new sink. I know how to do it via the commandline:
> 
> pacmd set-default-sink null
> 
> However, I'd rather do it using a normal function call. Is that
> possible in PulseAudio 2.1?

You can use pa_context_set_default_sink().

> 
> Also, unloading the module using pa_context_unload_module doesn't seem
> to work, the success callback is never called, although I'm calling
> the unload function with the correct index number (the one received
> when loading). Unloading using the following command works fine:
> 
> pacmd unload-module 
> 
> Any help will be greatly appreciated.

You can look up how pactl does this.
___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


[pulseaudio-discuss] [PATCH v1 0/4] Store volume information in the porst struct.

2013-03-17 Thread Damir Jelić
Changes since v0 (I called the last set RFC):
- patch 1 - device-port: fire a hook for the volume change event
- patch 2 - card-restore: update to use hooks instead of subscription events
- patch 2 - card-restore: if the volumes in the entries are invalid assume 
the 
entries are not equal (this silences an assertion)
- patch 4 - device-restore: Still save the volume inside device-restore if 
  the sink doesn't have ports
- fix Davids "nitpicks"

From original cover letter [2]:

> This patch set is for now an RFC.
> This should move the volume saving/restoring to the ports and card-restore. 
> The sinks/sources should then only inherit the volume from the active port.

> The last patch is just a quick hack so device-restore doesn't load the
> volume for newly created sinks.

> This should fix bug 55262.

[1] https://bugs.freedesktop.org/show_bug.cgi?id=55262
[2] http://thread.gmane.org/gmane.comp.audio.pulseaudio.general/15477

PS: Sorry for the long delay between the patch series.

poljar (Damir Jelić) (4):
  device-port: Add volume to the ports struct.
  card-restore: Save/restore volume for the ports.
  sink: Inherit the volume from the active port.
  device-restore: Remove the ability to restore volumes for sinks.

 src/modules/module-card-restore.c   | 68 -
 src/modules/module-device-restore.c |  4 +--
 src/pulsecore/core.h|  1 +
 src/pulsecore/device-port.c | 15 
 src/pulsecore/device-port.h |  3 ++
 src/pulsecore/sink.c| 15 ++--
 6 files changed, 92 insertions(+), 14 deletions(-)

-- 
1.8.2

___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


[pulseaudio-discuss] [PATCH v1 1/4] device-port: Add volume to the ports struct.

2013-03-17 Thread Damir Jelić
This patch adds a volume to the ports.
Now we can save and restore the volume per port.

This adds a new hook:
PA_CORE_HOOK_PORT_VOLUME_CHANGED

BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=55262
---
 src/pulsecore/core.h|  1 +
 src/pulsecore/device-port.c | 15 +++
 src/pulsecore/device-port.h |  3 +++
 3 files changed, 19 insertions(+)

diff --git a/src/pulsecore/core.h b/src/pulsecore/core.h
index 381897a..078c237 100644
--- a/src/pulsecore/core.h
+++ b/src/pulsecore/core.h
@@ -118,6 +118,7 @@ typedef enum pa_core_hook {
 PA_CORE_HOOK_PORT_AVAILABLE_CHANGED,
 PA_CORE_HOOK_PORT_ADDED,
 PA_CORE_HOOK_PORT_LATENCY_OFFSET_CHANGED,
+PA_CORE_HOOK_PORT_VOLUME_CHANGED,
 PA_CORE_HOOK_MAX
 } pa_core_hook_t;
 
diff --git a/src/pulsecore/device-port.c b/src/pulsecore/device-port.c
index f16de3a..608effa 100644
--- a/src/pulsecore/device-port.c
+++ b/src/pulsecore/device-port.c
@@ -84,6 +84,7 @@ pa_device_port *pa_device_port_new(pa_core *c, const char 
*name, const char *des
 p->is_input = FALSE;
 p->is_output = FALSE;
 p->latency_offset = 0;
+pa_cvolume_init(&p->volume);
 p->proplist = pa_proplist_new();
 
 return p;
@@ -123,3 +124,17 @@ void pa_device_port_set_latency_offset(pa_device_port *p, 
int64_t offset) {
 pa_subscription_post(core, 
PA_SUBSCRIPTION_EVENT_CARD|PA_SUBSCRIPTION_EVENT_CHANGE, p->card->index);
 pa_hook_fire(&core->hooks[PA_CORE_HOOK_PORT_LATENCY_OFFSET_CHANGED], p);
 }
+
+void pa_device_port_set_volume(pa_device_port *p, pa_cvolume volume) {
+pa_core *core;
+
+pa_assert(p);
+
+if (pa_cvolume_equal(&p->volume, &volume))
+return;
+
+p->volume = volume;
+
+pa_assert_se(core = p->core);
+pa_hook_fire(&core->hooks[PA_CORE_HOOK_PORT_VOLUME_CHANGED], p);
+}
diff --git a/src/pulsecore/device-port.h b/src/pulsecore/device-port.h
index c0c00cf..9796707 100644
--- a/src/pulsecore/device-port.h
+++ b/src/pulsecore/device-port.h
@@ -33,6 +33,7 @@ typedef struct pa_device_port pa_device_port;
 #include 
 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -54,6 +55,7 @@ struct pa_device_port {
 pa_bool_t is_input:1;
 pa_bool_t is_output:1;
 int64_t latency_offset;
+pa_cvolume volume;
 
 /* .. followed by some implementation specific data */
 };
@@ -70,4 +72,5 @@ void pa_device_port_set_available(pa_device_port *p, 
pa_available_t available);
 
 void pa_device_port_set_latency_offset(pa_device_port *p, int64_t offset);
 
+void pa_device_port_set_volume(pa_device_port *p, pa_cvolume volume);
 #endif
-- 
1.8.2

___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


[pulseaudio-discuss] [PATCH v1 2/4] card-restore: Save/restore volume for the ports.

2013-03-17 Thread Damir Jelić
The card-restore module now saves and restores the volume per port.
This change includes a entry version bump.

BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=55262
---
 src/modules/module-card-restore.c | 68 +--
 1 file changed, 59 insertions(+), 9 deletions(-)

diff --git a/src/modules/module-card-restore.c 
b/src/modules/module-card-restore.c
index 3b061b6..b7ff7bc 100644
--- a/src/modules/module-card-restore.c
+++ b/src/modules/module-card-restore.c
@@ -67,16 +67,18 @@ struct userdata {
 pa_hook_slot *card_profile_hook_slot;
 pa_hook_slot *port_new_hook_slot;
 pa_hook_slot *port_offset_hook_slot;
+pa_hook_slot *port_volume_hook_slot;
 pa_time_event *save_time_event;
 pa_database *database;
 bool hooks_connected;
 };
 
-#define ENTRY_VERSION 2
+#define ENTRY_VERSION 3
 
 struct port_info {
 char *name;
 int64_t offset;
+pa_cvolume volume;
 };
 
 struct entry {
@@ -121,6 +123,7 @@ static struct port_info *port_info_new(pa_device_port 
*port) {
 p_info = pa_xnew(struct port_info, 1);
 p_info->name = pa_xstrdup(port->name);
 p_info->offset = port->latency_offset;
+p_info->volume = port->volume;
 } else
 p_info = pa_xnew0(struct port_info, 1);
 
@@ -134,6 +137,7 @@ static void port_info_update(struct port_info *p_info, 
pa_device_port *port) {
 pa_xfree(p_info->name);
 p_info->name = pa_xstrdup(port->name);
 p_info->offset = port->latency_offset;
+p_info->volume = port->volume;
 }
 
 static void port_info_free(struct port_info *p_info) {
@@ -185,7 +189,10 @@ static bool entrys_equal(struct entry *a, struct entry *b) 
{
 
 PA_HASHMAP_FOREACH(Ap_info, a->ports, state) {
 if ((Bp_info = pa_hashmap_get(b->ports, Ap_info->name))) {
-if (Ap_info->offset != Bp_info->offset)
+if (Ap_info->offset != Bp_info->offset ||
+!pa_cvolume_valid(&Ap_info->volume) ||
+!pa_cvolume_valid(&Bp_info->volume) ||
+!pa_cvolume_equal(&Ap_info->volume, &Bp_info->volume))
 return false;
 } else
 return false;
@@ -213,6 +220,7 @@ static pa_bool_t entry_write(struct userdata *u, const char 
*name, const struct
 PA_HASHMAP_FOREACH(p_info, e->ports, state) {
 pa_tagstruct_puts(t, p_info->name);
 pa_tagstruct_puts64(t, p_info->offset);
+pa_tagstruct_put_cvolume(t, &p_info->volume);
 }
 
 key.data = (char *) name;
@@ -300,22 +308,26 @@ static struct entry* entry_read(struct userdata *u, const 
char *name) {
 uint32_t port_count = 0;
 const char *port_name = NULL;
 int64_t port_offset = 0;
+pa_cvolume port_volume;
 struct port_info *p_info;
 unsigned i;
 
 if (pa_tagstruct_getu32(t, &port_count) < 0)
 goto fail;
 
+pa_cvolume_init(&port_volume);
 for (i = 0; i < port_count; i++) {
 if (pa_tagstruct_gets(t, &port_name) < 0 ||
 !port_name ||
 pa_hashmap_get(e->ports, port_name) ||
-pa_tagstruct_gets64(t, &port_offset) < 0)
+pa_tagstruct_gets64(t, &port_offset) < 0 ||
+(e->version >= 3 && pa_tagstruct_get_cvolume(t, &port_volume) 
< 0))
 goto fail;
 
 p_info = port_info_new(NULL);
 p_info->name = pa_xstrdup(port_name);
 p_info->offset = port_offset;
+p_info->volume = port_volume;
 
 pa_assert_se(pa_hashmap_put(e->ports, p_info->name, p_info) >= 0);
 }
@@ -358,9 +370,9 @@ static void show_full_info(pa_card *card) {
 pa_assert(card);
 
 if (card->save_profile)
-pa_log_info("Storing profile and port latency offsets for card %s.", 
card->name);
+pa_log_info("Storing profile, port volumes and latency offsets for 
card %s.", card->name);
 else
-pa_log_info("Storing port latency offsets for card %s.", card->name);
+pa_log_info("Storing port volumes and latency offsets for card %s.", 
card->name);
 }
 
 static pa_hook_result_t card_put_hook_callback(pa_core *c, pa_card *card, 
struct userdata *u) {
@@ -475,6 +487,37 @@ static pa_hook_result_t 
port_offset_change_callback(pa_core *c, pa_device_port *
 return PA_HOOK_OK;
 }
 
+static pa_hook_result_t port_volume_change_callback(pa_core *c, pa_device_port 
*port, struct userdata *u) {
+struct entry *entry;
+pa_card *card;
+
+pa_assert(port);
+card = port->card;
+
+if ((entry = entry_read(u, card->name))) {
+struct port_info *p_info;
+
+if ((p_info = pa_hashmap_get(entry->ports, port->name)))
+p_info->volume = port->volume;
+else {
+p_info = port_info_new(port);
+pa_assert_se(pa_hashmap_put(entry->ports, p_info->name, p_info) >= 
0);
+}
+
+pa_log_info("Storing volumes for port %s on card %s.", port->name, 
card->name);

[pulseaudio-discuss] [PATCH v1 3/4] sink: Inherit the volume from the active port.

2013-03-17 Thread Damir Jelić
Since the port now holds the volume information we can simply inherit
the volume from the active port if the volume isn't set while creating
the sink.

BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=55262
---
 src/pulsecore/sink.c | 15 ---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/src/pulsecore/sink.c b/src/pulsecore/sink.c
index 6ebe956..a56a0b9 100644
--- a/src/pulsecore/sink.c
+++ b/src/pulsecore/sink.c
@@ -277,7 +277,6 @@ pa_sink* pa_sink_new(
 s->n_corked = 0;
 s->input_to_master = NULL;
 
-s->reference_volume = s->real_volume = data->volume;
 pa_cvolume_reset(&s->soft_volume, s->sample_spec.channels);
 s->base_volume = PA_VOLUME_NORM;
 s->n_volume_steps = PA_VOLUME_NORM+1;
@@ -310,10 +309,18 @@ pa_sink* pa_sink_new(
 s->active_port = p;
 }
 
-if (s->active_port)
+if (s->active_port) {
 s->latency_offset = s->active_port->latency_offset;
-else
+
+if (pa_cvolume_valid(&s->active_port->volume) && !data->volume_is_set)
+s->reference_volume = s->real_volume = s->active_port->volume;
+else
+s->reference_volume = s->real_volume = data->volume;
+
+} else {
 s->latency_offset = 0;
+s->reference_volume = s->real_volume = data->volume;
+}
 
 s->save_volume = data->save_volume;
 s->save_muted = data->save_muted;
@@ -1972,6 +1979,8 @@ void pa_sink_set_volume(
 }
 
 pa_cvolume_remap(&new_reference_volume, &s->channel_map, 
&root_sink->channel_map);
+if (s->active_port)
+pa_device_port_set_volume(s->active_port, new_reference_volume);
 
 if (update_reference_volume(root_sink, &new_reference_volume, 
&root_sink->channel_map, save)) {
 if (pa_sink_flat_volume_enabled(root_sink)) {
-- 
1.8.2

___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


[pulseaudio-discuss] [PATCH v1 4/4] device-restore: Remove the ability to restore volumes for sinks.

2013-03-17 Thread Damir Jelić
This change disables volume restoring for sinks that have a port. Sinks
with ports inherit the restored volume from the port.

For sinks without ports nothing is changed.
---
 src/modules/module-device-restore.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/modules/module-device-restore.c 
b/src/modules/module-device-restore.c
index 8360a05..f5b33c7 100644
--- a/src/modules/module-device-restore.c
+++ b/src/modules/module-device-restore.c
@@ -775,7 +775,7 @@ static pa_hook_result_t sink_fixate_hook_callback(pa_core 
*c, pa_sink_new_data *
 
 if ((e = perportentry_read(u, name, new_data->active_port))) {
 
-if (u->restore_volume && e->volume_valid) {
+if (u->restore_volume && e->volume_valid && !new_data->active_port) {
 
 if (!new_data->volume_is_set) {
 pa_cvolume v;
@@ -823,7 +823,7 @@ static pa_hook_result_t sink_port_hook_callback(pa_core *c, 
pa_sink *sink, struc
 
 if ((e = perportentry_read(u, name, (sink->active_port ? 
sink->active_port->name : NULL {
 
-if (u->restore_volume && e->volume_valid) {
+if (u->restore_volume && e->volume_valid && !sink->active_port) {
 pa_cvolume v;
 char buf[PA_CVOLUME_SNPRINT_MAX];
 
-- 
1.8.2

___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


[pulseaudio-discuss] [PATCH 0/3] ZSH completion fixes

2013-03-17 Thread Damir Jelić
Hi. These patches are some minor fixes to the zsh completion.

They are kept separate if someone wants to review them but they 
can be squashed together if we don't want to pollute the commit
log with completion commits.

poljar (Damir Jelić) (3):
  zsh-completion: Add support for remote servers.
  zsh-completion: Add support for the new pactl commands.
  zsh-completion: Fix pacat completion.

 shell-completion/pulseaudio-zsh-completion.zsh | 82 --
 1 file changed, 65 insertions(+), 17 deletions(-)

-- 
1.8.2

___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


[pulseaudio-discuss] [PATCH 1/3] zsh-completion: Add support for remote servers.

2013-03-17 Thread Damir Jelić
This patch adds support for completion of remote PulseAudio server
arguments it also suppresses error messages when unable to connect to
PulseAudio (only for the completion function).
---
 shell-completion/pulseaudio-zsh-completion.zsh | 75 --
 1 file changed, 60 insertions(+), 15 deletions(-)

diff --git a/shell-completion/pulseaudio-zsh-completion.zsh 
b/shell-completion/pulseaudio-zsh-completion.zsh
index c3baf9d..f9002ef 100644
--- a/shell-completion/pulseaudio-zsh-completion.zsh
+++ b/shell-completion/pulseaudio-zsh-completion.zsh
@@ -2,7 +2,7 @@
 
 _devices() {
 local -a _device_list
-local cmd _device _device_description
+local cmd _device _device_description _remote_cmd
 
 if [[ $service == pactl  || $service == pacmd ]]; then
 case $words[$((CURRENT - 1))] in
@@ -38,8 +38,15 @@ _devices() {
 cmd=('sources')
 fi
 
+for (( i = 0; i < ${#words[@]}; i++ )) do
+if [[ ${words[$i]} == -s ]]; then
+_remote_cmd="-s ${words[$i+1]}"
+break;
+fi
+done
+
 for target in $cmd; do
-for device_info in ${(ps:\n\n:)"$(_call_program card_tag "pactl list 
$target")"}; do
+for device_info in ${(ps:\n\n:)"$(_call_program device_tag "pactl 
$_remote_cmd list $target 2> /dev/null")"}; do
 for line in ${(f)device_info}; do
 if [[ $target == (sink-inputs|source-outputs) ]]; then
 if [[ $line == (Sink*Input|Source*Output)* ]]; then
@@ -74,11 +81,18 @@ _devices() {
 
 _profiles() {
 local -a _profile_list
-local _current_card _raw_profiles _profile_name _profile_description
+local _current_card _raw_profiles _profile_name _profile_description 
_remote_cmd
 
 _current_card=$words[$((CURRENT - 1))]
 
-for card in ${(ps:\n\n:)"$(_call_program card_tag "pactl list cards")"}; do
+for (( i = 0; i < ${#words[@]}; i++ )) do
+if [[ ${words[$i]} == -s ]]; then
+_remote_cmd="-s ${words[$i+1]}"
+break;
+fi
+done
+
+for card in ${(ps:\n\n:)"$(_call_program profiles_tag "pactl $_remote_cmd 
list cards 2> /dev/null")"}; do
 if [[ $card == *$_current_card* ]]; then
 _raw_profiles=${card##*Profiles:}
 _raw_profiles=${_raw_profiles%%Active Profile:*}
@@ -99,7 +113,7 @@ _profiles() {
 
 _ports() {
 local -a _port_list
-local _raw_ports _port_name _port_description _current_device
+local _raw_ports _port_name _port_description _current_device _remote_cmd
 
 case $words[$((CURRENT - 2))] in
 set-sink-port) cmd="sinks";;
@@ -109,7 +123,14 @@ _ports() {
 
 _current_device=$words[$((CURRENT - 1))]
 
-for device in ${(ps:\n\n:)"$(_call_program card_tag "pactl list $cmd")"}; 
do
+for (( i = 0; i < ${#words[@]}; i++ )) do
+if [[ ${words[$i]} == -s ]]; then
+_remote_cmd="-s ${words[$i+1]}"
+break;
+fi
+done
+
+for device in ${(ps:\n\n:)"$(_call_program port_tag "pactl $_remote_cmd 
list $cmd 2> /dev/null")"}; do
 if [[ $device == *Ports:* && $device == *$_current_device* ]]; then
 _raw_ports=${device##*Ports:}
 _raw_ports=${_raw_ports%%Active Port:*}
@@ -130,8 +151,16 @@ _ports() {
 
 _cards(){
 local -a _card_list
-local _card _cad_name
-for card_info in ${(ps:\n\n:)"$(_call_program card_tag "pactl list 
cards")"}; do
+local _card _cad_name _remote_cmd
+
+for (( i = 0; i < ${#words[@]}; i++ )) do
+if [[ ${words[$i]} == -s ]]; then
+_remote_cmd="-s ${words[$i+1]}"
+break;
+fi
+done
+
+for card_info in ${(ps:\n\n:)"$(_call_program card_tag "pactl $_remote_cmd 
list cards 2> /dev/null")"}; do
 for line in ${(f)card_info}; do
 if [[ $line == *Name:* ]]; then
 _card=${line#*: }
@@ -148,15 +177,23 @@ _cards(){
 
 _all_modules(){
 local -a _all_modules_list
-for module in ${(f)"$(_call_program modules_tag "pulseaudio 
--dump-modules")"}; do
+for module in ${(f)"$(_call_program modules_tag "pulseaudio --dump-modules 
2> /dev/null")"}; do
 _all_modules_list+=${module%% *}
 done
 _describe 'module list' _all_modules_list
 }
 
 _loaded_modules(){
-local -a _loaded_modules_list
-for module in ${(f)"$(_call_program modules_tag "pactl list modules 
short")"}; do
+local -a _loaded_modules_list _remote_cmd
+
+for (( i = 0; i < ${#words[@]}; i++ )) do
+if [[ ${words[$i]} == -s ]]; then
+_remote_cmd="-s ${words[$i+1]}"
+break;
+fi
+done
+
+for module in ${(f)"$(_call_program modules_tag "pactl $_remote_cmd list 
modules short 2> /dev/null")"}; do
 _loaded_modules_list+=(${${(ps:\t:)module}[1]}:${${(ps:\t:)module}[2]})
 done
 _describe 'module list' _loaded_modules_list
@@ -164,7 +201,7 @@ _loaded_modules(){
 
 _resample_methods() {
 local -a _resample_method_list
-f

[pulseaudio-discuss] [PATCH 2/3] zsh-completion: Add support for the new pactl commands.

2013-03-17 Thread Damir Jelić
This adds support for set-(sink|source)-default completion and adds
toggle to the supported arguments for the mute command.
---
 shell-completion/pulseaudio-zsh-completion.zsh | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/shell-completion/pulseaudio-zsh-completion.zsh 
b/shell-completion/pulseaudio-zsh-completion.zsh
index f9002ef..4a85956 100644
--- a/shell-completion/pulseaudio-zsh-completion.zsh
+++ b/shell-completion/pulseaudio-zsh-completion.zsh
@@ -257,6 +257,8 @@ _pactl_completion() {
 'suspend-sink: suspend or resume a sink'
 'suspend-source: suspend or resume a source'
 'set-card-profile: set a card profile:cards:_cards'
+'set-sink-default: set the default sink'
+'set-source-default: set the default source'
 'set-sink-port: set the sink port of a sink'
 'set-source-port: set the source port of a source'
 'set-port-latency-offset: set a latency offset on a port'
@@ -313,7 +315,7 @@ _pactl_completion() {
 set-card-profile) _profiles;;
 set-(sink|source)-port) _ports;;
 set-port-latency-offset) _ports;;
-set-*-mute) compadd true false;;
+set-*-mute) compadd true false toggle;;
 suspend-*) compadd true false;;
 list) compadd short;;
 move-*) _devices;;
-- 
1.8.2

___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


[pulseaudio-discuss] [PATCH 3/3] zsh-completion: Fix pacat completion.

2013-03-17 Thread Damir Jelić
pacat --format needs = (--format=).
Also pacat should complete files firstly and command line arguments
secondly.
---
 shell-completion/pulseaudio-zsh-completion.zsh | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/shell-completion/pulseaudio-zsh-completion.zsh 
b/shell-completion/pulseaudio-zsh-completion.zsh
index 4a85956..d73b74d 100644
--- a/shell-completion/pulseaudio-zsh-completion.zsh
+++ b/shell-completion/pulseaudio-zsh-completion.zsh
@@ -470,8 +470,9 @@ _pacat_completion() {
 '--property=[set the specified property]:property' \
 '--raw[record/play raw PCM data]' \
 '--passthrough[passtrough data]' \
-'--file-format[record/play formatted PCM 
data]:format:_pacat_file_formats' \
+'--file-format=[record/play formatted PCM 
data]:format:_pacat_file_formats' \
 '--list-file-formats[list available formats]' \
+'::files:_files' \
 }
 
 # TODO log-target file completion
-- 
1.8.2

___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


Re: [pulseaudio-discuss] [PATCH v1 4/4] device-restore: Remove the ability to restore volumes for sinks.

2013-03-18 Thread Damir Jelić
On Mon, Mar 18, 2013 at 02:33:08PM +0200, Tanu Kaskinen wrote:
> On Sun, 2013-03-17 at 21:48 +0100, poljar (Damir Jelić) wrote:
> > This change disables volume restoring for sinks that have a port. Sinks
> > with ports inherit the restored volume from the port.
> > 
> > For sinks without ports nothing is changed.
> > ---
> >  src/modules/module-device-restore.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/src/modules/module-device-restore.c 
> > b/src/modules/module-device-restore.c
> > index 8360a05..f5b33c7 100644
> > --- a/src/modules/module-device-restore.c
> > +++ b/src/modules/module-device-restore.c
> > @@ -775,7 +775,7 @@ static pa_hook_result_t 
> > sink_fixate_hook_callback(pa_core *c, pa_sink_new_data *
> >  
> >  if ((e = perportentry_read(u, name, new_data->active_port))) {
> >  
> > -if (u->restore_volume && e->volume_valid) {
> > +if (u->restore_volume && e->volume_valid && 
> > !new_data->active_port) {
> >  
> >  if (!new_data->volume_is_set) {
> >  pa_cvolume v;
> > @@ -823,7 +823,7 @@ static pa_hook_result_t sink_port_hook_callback(pa_core 
> > *c, pa_sink *sink, struc
> >  
> >  if ((e = perportentry_read(u, name, (sink->active_port ? 
> > sink->active_port->name : NULL {
> >  
> > -if (u->restore_volume && e->volume_valid) {
> > +if (u->restore_volume && e->volume_valid && !sink->active_port) {
> 
> You can remove this whole if block. The hook is called when
> sink->active_port changes, and it never changes to NULL, so you can
> assume here that it's always set.
> 
> Now I realized that these patches do nothing for sources. Do you plan to
> send separate patches for sources?
> 

Yes. After I sort out all the issues for the sinks I will send a
patchset with similiar changes for sources or do you prefer me to do
that right away?
___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


[pulseaudio-discuss] [PATCH] device-port: Introduce port_new_data struct.

2013-03-26 Thread Damir Jelić
Port creation is now slightly different. It is now similar to how
other objects are created (e.g. sinks/sources/cards).

This should become more useful in the future when we move more stuff to
the ports.

Functionally nothing has changed.
---
 src/modules/alsa/alsa-mixer.c   |  8 +++-
 src/modules/alsa/alsa-ucm.c |  9 +++-
 src/modules/bluetooth/module-bluetooth-device.c | 26 
 src/pulsecore/device-port.c | 56 +
 src/pulsecore/device-port.h | 17 +++-
 5 files changed, 97 insertions(+), 19 deletions(-)

diff --git a/src/modules/alsa/alsa-mixer.c b/src/modules/alsa/alsa-mixer.c
index 2814add..cb81579 100644
--- a/src/modules/alsa/alsa-mixer.c
+++ b/src/modules/alsa/alsa-mixer.c
@@ -4459,8 +4459,14 @@ static pa_device_port* device_port_alsa_init(pa_hashmap 
*ports,
 
 if (!p) {
 pa_alsa_port_data *data;
+pa_device_port_new_data port_data;
 
-p = pa_device_port_new(core, name, description, 
sizeof(pa_alsa_port_data));
+pa_device_port_new_data_init(&port_data);
+pa_device_port_new_data_set_name(&port_data, name);
+pa_device_port_new_data_set_description(&port_data, description);
+
+p = pa_device_port_new(core, &port_data, sizeof(pa_alsa_port_data));
+pa_device_port_new_data_done(&port_data);
 pa_assert(p);
 pa_hashmap_put(ports, p->name, p);
 pa_proplist_update(p->proplist, PA_UPDATE_REPLACE, path->proplist);
diff --git a/src/modules/alsa/alsa-ucm.c b/src/modules/alsa/alsa-ucm.c
index f69ee89..437aa4d 100644
--- a/src/modules/alsa/alsa-ucm.c
+++ b/src/modules/alsa/alsa-ucm.c
@@ -688,7 +688,14 @@ static void ucm_add_port_combination(
 
 port = pa_hashmap_get(ports, name);
 if (!port) {
-port = pa_device_port_new(core, pa_strna(name), desc, 0);
+pa_device_port_new_data port_data;
+
+pa_device_port_new_data_init(&port_data);
+pa_device_port_new_data_set_name(&port_data, pa_strna(name));
+pa_device_port_new_data_set_description(&port_data, desc);
+
+port = pa_device_port_new(core, &port_data, 0);
+pa_device_port_new_data_done(&port_data);
 pa_assert(port);
 
 pa_hashmap_put(ports, port->name, port);
diff --git a/src/modules/bluetooth/module-bluetooth-device.c 
b/src/modules/bluetooth/module-bluetooth-device.c
index c877df2..aba9ac2 100644
--- a/src/modules/bluetooth/module-bluetooth-device.c
+++ b/src/modules/bluetooth/module-bluetooth-device.c
@@ -2070,6 +2070,8 @@ off:
 /* Run from main thread */
 static void create_card_ports(struct userdata *u, pa_hashmap *ports) {
 pa_device_port *port;
+pa_device_port_new_data output_port_data, input_port_data;
+
 const char *name_prefix = NULL;
 const char *input_description = NULL;
 const char *output_description = NULL;
@@ -2140,17 +2142,23 @@ static void create_card_ports(struct userdata *u, 
pa_hashmap *ports) {
 u->output_port_name = pa_sprintf_malloc("%s-output", name_prefix);
 u->input_port_name = pa_sprintf_malloc("%s-input", name_prefix);
 
-pa_assert_se(port = pa_device_port_new(u->core, u->output_port_name, 
output_description, 0));
+pa_device_port_new_data_init(&output_port_data);
+pa_device_port_new_data_set_name(&output_port_data, u->output_port_name);
+pa_device_port_new_data_set_description(&output_port_data, 
output_description);
+pa_device_port_new_data_set_direction(&output_port_data, 
PA_DIRECTION_OUTPUT);
+pa_device_port_new_data_set_availability(&output_port_data, 
get_port_availability(u, PA_DIRECTION_OUTPUT));
+pa_assert_se(port = pa_device_port_new(u->core, &output_port_data, 0));
 pa_assert_se(pa_hashmap_put(ports, port->name, port) >= 0);
-port->is_output = 1;
-port->is_input = 0;
-port->available = get_port_availability(u, PA_DIRECTION_OUTPUT);
-
-pa_assert_se(port = pa_device_port_new(u->core, u->input_port_name, 
input_description, 0));
+pa_device_port_new_data_done(&output_port_data);
+
+pa_device_port_new_data_init(&input_port_data);
+pa_device_port_new_data_set_name(&input_port_data, u->input_port_name);
+pa_device_port_new_data_set_description(&input_port_data, 
output_description);
+pa_device_port_new_data_set_direction(&input_port_data, 
PA_DIRECTION_INPUT);
+pa_device_port_new_data_set_availability(&input_port_data, 
get_port_availability(u, PA_DIRECTION_INPUT));
+pa_assert_se(port = pa_device_port_new(u->core, &input_port_data, 0));
 pa_assert_se(pa_hashmap_put(ports, port->name, port) >= 0);
-port->is_output = 0;
-port->is_input = 1;
-port->available = get_port_availability(u, PA_DIRECTION_INPUT);
+pa_device_port_new_data_done(&input_port_data);
 }
 
 /* Run from main thread */
diff --git a/src/pulsecore/device-port.c b/src/pulsecore/device-port.c
index f16de3a..7438dec 100644
--- a/src/pulsecore/device-port.c
+++ b/src/pulsecore/de

Re: [pulseaudio-discuss] [PATCH] device-port: Introduce port_new_data struct.

2013-03-27 Thread Damir Jelić
Hi Tanu. Thanks for the review.

On Wed, Mar 27, 2013 at 03:22:32PM +0200, Tanu Kaskinen wrote:
> On Tue, 2013-03-26 at 21:54 +0100, poljar (Damir Jelić) wrote:
> > Port creation is now slightly different. It is now similar to how
> > other objects are created (e.g. sinks/sources/cards).
> > 
> > This should become more useful in the future when we move more stuff to
> > the ports.
> > 
> > Functionally nothing has changed.
> > ---
> >  src/modules/alsa/alsa-mixer.c   |  8 +++-
> >  src/modules/alsa/alsa-ucm.c |  9 +++-
> >  src/modules/bluetooth/module-bluetooth-device.c | 26 
> >  src/pulsecore/device-port.c | 56 
> > +
> >  src/pulsecore/device-port.h | 17 +++-
> >  5 files changed, 97 insertions(+), 19 deletions(-)
> 
> > diff --git a/src/modules/bluetooth/module-bluetooth-device.c 
> > b/src/modules/bluetooth/module-bluetooth-device.c
> > index c877df2..aba9ac2 100644
> > --- a/src/modules/bluetooth/module-bluetooth-device.c
> > +++ b/src/modules/bluetooth/module-bluetooth-device.c
> > @@ -2070,6 +2070,8 @@ off:
> >  /* Run from main thread */
> >  static void create_card_ports(struct userdata *u, pa_hashmap *ports) {
> >  pa_device_port *port;
> > +pa_device_port_new_data output_port_data, input_port_data;
> 
> It doesn't seem necessary to have two separate structs.
> 
> > diff --git a/src/pulsecore/device-port.c b/src/pulsecore/device-port.c
> > index f16de3a..7438dec 100644
> > --- a/src/pulsecore/device-port.c
> > +++ b/src/pulsecore/device-port.c
> > @@ -26,6 +26,46 @@
> >  
> >  PA_DEFINE_PUBLIC_CLASS(pa_device_port, pa_object);
> >  
> > +pa_device_port_new_data 
> > *pa_device_port_new_data_init(pa_device_port_new_data *data) {
> > +pa_assert(data);
> > +
> > +pa_zero(*data);
> > +return data;
> 
> I think it would be good to explicitly initialize available to
> PA_AVAILABLE_UNKNOWN. Sure, UNKNOWN is defined as zero, so there's no
> practical effect, but I don't like assuming any knowledge about the
> numeric values of enumerations.
> 

Heh. I actually did this and then looked up what the definition for
UNKNOWN is and removed it :P

> > +}
> > +
> > +void pa_device_port_new_data_set_name(pa_device_port_new_data *data, const 
> > char *name) {
> > +pa_assert(data);
> > +
> > +pa_xfree(data->name);
> > +data->name = pa_xstrdup(name);
> > +}
> > +
> > +void pa_device_port_new_data_set_description(pa_device_port_new_data 
> > *data, const char *descritpion) {
> 
> Typo: "descritpion"
> 
> > +pa_assert(data);
> > +
> > +pa_xfree(data->description);
> > +data->description = pa_xstrdup(descritpion);
> > +}
> > +
> > +void pa_device_port_new_data_set_availability(pa_device_port_new_data 
> > *data, pa_available_t available) {
> 
> I think "set_available" would be better, because the field name is
> "available".
> 
> > +pa_assert(data);
> > +
> > +data->available = available;
> > +}
> > +
> > +void pa_device_port_new_data_set_direction(pa_device_port_new_data *data, 
> > pa_direction_t direction) {
> > +pa_assert(data);
> > +
> > +if (direction == PA_DIRECTION_OUTPUT)
> > +data->is_output = true;
> > +else if (direction == PA_DIRECTION_INPUT)
> > +data->is_output = true;
> > +}
> 
> I think the direction should be set either always or never with
> pa_device_port_new_data_set_direction(). I'd prefer the "always" option,
> but since alsa modules can have dual-direction ports, they can't really
> use pa_device_port_new_data_set_direction(), so as a second best
> alternative, I suggest that you remove this function.
> 
> Or there's another alternative: I could push a patch set[1] that removes
> the possibility of dual-direction ports. That would possibly require
> some rebasing work from you. What do you prefer? Remove
> pa_device_port_new_data_set_direction() for now, or rebase on top of the
> mentioned patch set after I've applied that?
> 
> [1] 
> http://thread.gmane.org/gmane.comp.audio.pulseaudio.general/13010/focus=13626
> 

The second solution sounds better to me. If we're cleaning up this stuff we
should do it properly. Isn't the feature freeze a problem here? (also I
have an exam next week but I should find time to do this anyway)

> > +
> > +void

[pulseaudio-discuss] [PATCH v2] device-port: Introduce port_new_data struct.

2013-03-28 Thread Damir Jelić
Port creation is now slightly different. It is now similar to how
other objects are created (e.g. sinks/sources/cards).

This should become more useful in the future when we move more stuff to
the ports.

Functionally nothing has changed.
---
 src/modules/alsa/alsa-mixer.c   | 10 +++--
 src/modules/alsa/alsa-ucm.c | 10 -
 src/modules/bluetooth/module-bluetooth-device.c | 22 ++---
 src/pulsecore/device-port.c | 60 ++---
 src/pulsecore/device-port.h | 16 ++-
 5 files changed, 101 insertions(+), 17 deletions(-)

diff --git a/src/modules/alsa/alsa-mixer.c b/src/modules/alsa/alsa-mixer.c
index a6f3980..4ebce39 100644
--- a/src/modules/alsa/alsa-mixer.c
+++ b/src/modules/alsa/alsa-mixer.c
@@ -4496,11 +4496,15 @@ static pa_device_port* device_port_alsa_init(pa_hashmap 
*ports, /* card ports */
 
 if (!p) {
 pa_alsa_port_data *data;
-pa_direction_t direction;
+pa_device_port_new_data port_data;
 
-direction = path->direction == PA_ALSA_DIRECTION_OUTPUT ? 
PA_DIRECTION_OUTPUT : PA_DIRECTION_INPUT;
+pa_device_port_new_data_init(&port_data);
+pa_device_port_new_data_set_name(&port_data, name);
+pa_device_port_new_data_set_description(&port_data, description);
+pa_device_port_new_data_set_direction(&port_data, path->direction == 
PA_ALSA_DIRECTION_OUTPUT ? PA_DIRECTION_OUTPUT : PA_DIRECTION_INPUT);
 
-p = pa_device_port_new(core, name, description, direction, 
sizeof(pa_alsa_port_data));
+p = pa_device_port_new(core, &port_data, sizeof(pa_alsa_port_data));
+pa_device_port_new_data_done(&port_data);
 pa_assert(p);
 pa_hashmap_put(ports, p->name, p);
 pa_proplist_update(p->proplist, PA_UPDATE_REPLACE, path->proplist);
diff --git a/src/modules/alsa/alsa-ucm.c b/src/modules/alsa/alsa-ucm.c
index a6de7aa..d8ff621 100644
--- a/src/modules/alsa/alsa-ucm.c
+++ b/src/modules/alsa/alsa-ucm.c
@@ -688,7 +688,15 @@ static void ucm_add_port_combination(
 
 port = pa_hashmap_get(ports, name);
 if (!port) {
-port = pa_device_port_new(core, pa_strna(name), desc, is_sink ? 
PA_DIRECTION_OUTPUT : PA_DIRECTION_INPUT, 0);
+pa_device_port_new_data port_data;
+
+pa_device_port_new_data_init(&port_data);
+pa_device_port_new_data_set_name(&port_data, pa_strna(name));
+pa_device_port_new_data_set_description(&port_data, desc);
+pa_device_port_new_data_set_direction(&port_data, is_sink ? 
PA_DIRECTION_OUTPUT : PA_DIRECTION_INPUT);
+
+port = pa_device_port_new(core, &port_data, 0);
+pa_device_port_new_data_done(&port_data);
 pa_assert(port);
 
 pa_hashmap_put(ports, port->name, port);
diff --git a/src/modules/bluetooth/module-bluetooth-device.c 
b/src/modules/bluetooth/module-bluetooth-device.c
index 2e21221..cd0a515 100644
--- a/src/modules/bluetooth/module-bluetooth-device.c
+++ b/src/modules/bluetooth/module-bluetooth-device.c
@@ -2070,6 +2070,8 @@ off:
 /* Run from main thread */
 static void create_card_ports(struct userdata *u, pa_hashmap *ports) {
 pa_device_port *port;
+pa_device_port_new_data port_data;
+
 const char *name_prefix = NULL;
 const char *input_description = NULL;
 const char *output_description = NULL;
@@ -2140,13 +2142,23 @@ static void create_card_ports(struct userdata *u, 
pa_hashmap *ports) {
 u->output_port_name = pa_sprintf_malloc("%s-output", name_prefix);
 u->input_port_name = pa_sprintf_malloc("%s-input", name_prefix);
 
-pa_assert_se(port = pa_device_port_new(u->core, u->output_port_name, 
output_description, PA_DIRECTION_OUTPUT, 0));
+pa_device_port_new_data_init(&port_data);
+pa_device_port_new_data_set_name(&port_data, u->output_port_name);
+pa_device_port_new_data_set_description(&port_data, output_description);
+pa_device_port_new_data_set_direction(&port_data, PA_DIRECTION_OUTPUT);
+pa_device_port_new_data_set_available(&port_data, get_port_availability(u, 
PA_DIRECTION_OUTPUT));
+pa_assert_se(port = pa_device_port_new(u->core, &port_data, 0));
 pa_assert_se(pa_hashmap_put(ports, port->name, port) >= 0);
-port->available = get_port_availability(u, PA_DIRECTION_OUTPUT);
-
-pa_assert_se(port = pa_device_port_new(u->core, u->input_port_name, 
input_description, PA_DIRECTION_OUTPUT, 0));
+pa_device_port_new_data_done(&port_data);
+
+pa_device_port_new_data_init(&port_data);
+pa_device_port_new_data_set_name(&port_data, u->input_port_name);
+pa_device_port_new_data_set_description(&port_data, output_description);
+pa_device_port_new_data_set_direction(&port_data, PA_DIRECTION_INPUT);
+pa_device_port_new_data_set_available(&port_data, get_port_availability(u, 
PA_DIRECTION_INPUT));
+pa_assert_se(port = pa_device_port_new(u->core, &port_data, 0));
 pa_assert_se(pa_hashmap_put(ports, port->name, port) >= 0);
-  

[pulseaudio-discuss] [PATCH] systemd-login: Remove unused variable session.

2013-03-29 Thread Damir Jelić
---
 src/modules/module-systemd-login.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/src/modules/module-systemd-login.c 
b/src/modules/module-systemd-login.c
index cc8b462..72de47f 100644
--- a/src/modules/module-systemd-login.c
+++ b/src/modules/module-systemd-login.c
@@ -211,7 +211,6 @@ fail:
 
 void pa__done(pa_module *m) {
 struct userdata *u;
-struct session *session;
 
 pa_assert(m);
 
-- 
1.8.2

___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


[pulseaudio-discuss] [[PATCH 0/5] Create ports with a card name.

2013-04-17 Thread Damir Jelić
Hi.

This is a patch series that should further prepare moving the sink volume
to the ports.

This whole patch series addresses the issue that we can't restore anything for
the ports if we don't know the card name that the port belongs to.

The second patch is a bit questionable and mostly I need feedback on this patch.
The other stuff should be quite straightforward.

Thanks, poljar.

poljar (Damir Jelić) (5):
  device-port: Allow setting the card name while creating a port.
  alsa-card/bluetooth-device: Set the card name while creating ports.
  device-port: Allow setting the latency offset during port creation.
  device-port: Fire a hook when creating a new port.
  card-restore: Restore the latency offset while creating the port.

 src/modules/alsa/alsa-mixer.c   | 13 ++
 src/modules/alsa/alsa-mixer.h   |  2 +-
 src/modules/alsa/alsa-ucm.c | 14 +++
 src/modules/alsa/alsa-ucm.h |  1 +
 src/modules/alsa/module-alsa-card.c | 12 -
 src/modules/bluetooth/module-bluetooth-device.c |  6 +++--
 src/modules/module-card-restore.c   | 33 -
 src/pulsecore/core.h|  1 +
 src/pulsecore/device-port.c | 26 ++-
 src/pulsecore/device-port.h |  5 
 10 files changed, 81 insertions(+), 32 deletions(-)

-- 
1.8.2.1

___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


[pulseaudio-discuss] [[PATCH v0] 1/5] device-port: Allow setting the card name while creating a port.

2013-04-17 Thread Damir Jelić
Since we want to be able to set/restore port properties while creating a
port and the port properties are saved with the card name as a key we
need to know the card name before the port is connected to a card.

This patch enables assigning a card name to the port_new_data struct.
---
 src/pulsecore/device-port.c | 8 
 src/pulsecore/device-port.h | 2 ++
 2 files changed, 10 insertions(+)

diff --git a/src/pulsecore/device-port.c b/src/pulsecore/device-port.c
index 9660702..e170841 100644
--- a/src/pulsecore/device-port.c
+++ b/src/pulsecore/device-port.c
@@ -48,6 +48,13 @@ void 
pa_device_port_new_data_set_description(pa_device_port_new_data *data, cons
 data->description = pa_xstrdup(description);
 }
 
+void pa_device_port_new_data_set_card_name(pa_device_port_new_data *data, 
const char *card_name) {
+pa_assert(data);
+
+pa_xfree(data->card_name);
+data->card_name = pa_xstrdup(card_name);
+}
+
 void pa_device_port_new_data_set_available(pa_device_port_new_data *data, 
pa_available_t available) {
 pa_assert(data);
 
@@ -65,6 +72,7 @@ void pa_device_port_new_data_done(pa_device_port_new_data 
*data) {
 
 pa_xfree(data->name);
 pa_xfree(data->description);
+pa_xfree(data->card_name);
 }
 
 void pa_device_port_set_available(pa_device_port *p, pa_available_t status)
diff --git a/src/pulsecore/device-port.h b/src/pulsecore/device-port.h
index b10d554..213a6f7 100644
--- a/src/pulsecore/device-port.h
+++ b/src/pulsecore/device-port.h
@@ -65,6 +65,7 @@ PA_DECLARE_PUBLIC_CLASS(pa_device_port);
 typedef struct pa_device_port_new_data {
 char *name;
 char *description;
+char *card_name;
 pa_available_t available;
 pa_direction_t direction;
 } pa_device_port_new_data;
@@ -72,6 +73,7 @@ typedef struct pa_device_port_new_data {
 pa_device_port_new_data *pa_device_port_new_data_init(pa_device_port_new_data 
*data);
 void pa_device_port_new_data_set_name(pa_device_port_new_data *data, const 
char *name);
 void pa_device_port_new_data_set_description(pa_device_port_new_data *data, 
const char *description);
+void pa_device_port_new_data_set_card_name(pa_device_port_new_data *data, 
const char *card_name);
 void pa_device_port_new_data_set_available(pa_device_port_new_data *data, 
pa_available_t available);
 void pa_device_port_new_data_set_direction(pa_device_port_new_data *data, 
pa_direction_t direction);
 void pa_device_port_new_data_done(pa_device_port_new_data *data);
-- 
1.8.2.1

___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


[pulseaudio-discuss] [[PATCH v0] 2/5] alsa-card/bluetooth-device: Set the card name while creating ports.

2013-04-17 Thread Damir Jelić
While creating ports also set the card name.
---
 src/modules/alsa/alsa-mixer.c   | 13 -
 src/modules/alsa/alsa-mixer.h   |  2 +-
 src/modules/alsa/alsa-ucm.c | 14 +-
 src/modules/alsa/alsa-ucm.h |  1 +
 src/modules/alsa/module-alsa-card.c | 12 ++--
 src/modules/bluetooth/module-bluetooth-device.c |  6 --
 6 files changed, 29 insertions(+), 19 deletions(-)

diff --git a/src/modules/alsa/alsa-mixer.c b/src/modules/alsa/alsa-mixer.c
index be9ee4e..046ace0 100644
--- a/src/modules/alsa/alsa-mixer.c
+++ b/src/modules/alsa/alsa-mixer.c
@@ -4480,8 +4480,9 @@ void 
pa_alsa_profile_set_drop_unsupported(pa_alsa_profile_set *ps) {
 }
 
 static pa_device_port* device_port_alsa_init(pa_hashmap *ports, /* card ports 
*/
-const char* name,
-const char* description,
+const char *name,
+const char *description,
+const char *card_name,
 pa_alsa_path *path,
 pa_alsa_setting *setting,
 pa_card_profile *cp,
@@ -4500,6 +4501,7 @@ static pa_device_port* device_port_alsa_init(pa_hashmap 
*ports, /* card ports */
 
 pa_device_port_new_data_init(&port_data);
 pa_device_port_new_data_set_name(&port_data, name);
+pa_device_port_new_data_set_card_name(&port_data, card_name);
 pa_device_port_new_data_set_description(&port_data, description);
 pa_device_port_new_data_set_direction(&port_data, path->direction == 
PA_ALSA_DIRECTION_OUTPUT ? PA_DIRECTION_OUTPUT : PA_DIRECTION_INPUT);
 
@@ -4528,6 +4530,7 @@ static pa_device_port* device_port_alsa_init(pa_hashmap 
*ports, /* card ports */
 
 void pa_alsa_path_set_add_ports(
 pa_alsa_path_set *ps,
+const char *card_name,
 pa_card_profile *cp,
 pa_hashmap *ports, /* card ports */
 pa_hashmap *extra, /* sink/source ports */
@@ -4546,7 +4549,7 @@ void pa_alsa_path_set_add_ports(
 /* If there is no or just one setting we only need a
  * single entry */
 pa_device_port *port = device_port_alsa_init(ports, path->name,
-path->description, path, path->settings, cp, extra, core);
+path->description, card_name, path, path->settings, cp, extra, 
core);
 port->priority = path->priority * 100;
 
 } else {
@@ -4562,7 +4565,7 @@ void pa_alsa_path_set_add_ports(
 else
 d = pa_xstrdup(path->description);
 
-port = device_port_alsa_init(ports, n, d, path, s, cp, extra, 
core);
+port = device_port_alsa_init(ports, n, d, card_name, path, s, 
cp, extra, core);
 port->priority = path->priority * 100 + s->priority;
 
 pa_xfree(n);
@@ -4585,7 +4588,7 @@ void pa_alsa_add_ports(void *sink_or_source_new_data, 
pa_alsa_path_set *ps, pa_c
 
 if (ps->paths && pa_hashmap_size(ps->paths) > 0) {
 pa_assert(card);
-pa_alsa_path_set_add_ports(ps, NULL, card->ports, ports, card->core);
+pa_alsa_path_set_add_ports(ps, card->name, NULL, card->ports, ports, 
card->core);
 }
 
 pa_log_debug("Added %u ports", pa_hashmap_size(ports));
diff --git a/src/modules/alsa/alsa-mixer.h b/src/modules/alsa/alsa-mixer.h
index 3d50ebb..442ac6b 100644
--- a/src/modules/alsa/alsa-mixer.h
+++ b/src/modules/alsa/alsa-mixer.h
@@ -351,6 +351,6 @@ struct pa_alsa_port_data {
 };
 
 void pa_alsa_add_ports(void *sink_or_source_new_data, pa_alsa_path_set *ps, 
pa_card *card);
-void pa_alsa_path_set_add_ports(pa_alsa_path_set *ps, pa_card_profile *cp, 
pa_hashmap *ports, pa_hashmap *extra, pa_core *core);
+void pa_alsa_path_set_add_ports(pa_alsa_path_set *ps, const char *card_name, 
pa_card_profile *cp, pa_hashmap *ports, pa_hashmap *extra, pa_core *core);
 
 #endif
diff --git a/src/modules/alsa/alsa-ucm.c b/src/modules/alsa/alsa-ucm.c
index 3b55e82..6904eb5 100644
--- a/src/modules/alsa/alsa-ucm.c
+++ b/src/modules/alsa/alsa-ucm.c
@@ -648,6 +648,7 @@ static void ucm_add_port_combination(
 pa_alsa_ucm_device **pdevices,
 int num,
 pa_hashmap *ports,
+const char *card_name,
 pa_card_profile *cp,
 pa_core *core) {
 
@@ -693,6 +694,7 @@ static void ucm_add_port_combination(
 pa_device_port_new_data_init(&port_data);
 pa_device_port_new_data_set_name(&port_data, name);
 pa_device_port_new_data_set_description(&port_data, desc);
+pa_device_port_new_data_set_card_name(&port_data, card_name);
 pa_device_port_new_data_set_direction(&port_data, is_sink ? 
PA_DIRECTION_OUTPUT : PA_DIRECTION_INPUT);
 
 port = pa_device_port_new(core, &port_data, 0);
@@ -807,6 +809,7 @@ static void ucm_add_ports_combination(
 int dev_num,
 uint32_t map_index,
 pa_hashmap *ports,
+const char *card_name,
 pa_card_profile *cp,
 pa_core *core) {
 
@@ -821,13 +824,13 @@ static void ucm_add_ports_combi

[pulseaudio-discuss] [[PATCH v0] 3/5] device-port: Allow setting the latency offset during port creation.

2013-04-17 Thread Damir Jelić
This should make latency setting during port creation consistent with
other port properties.
---
 src/pulsecore/device-port.c | 13 -
 src/pulsecore/device-port.h |  3 +++
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/src/pulsecore/device-port.c b/src/pulsecore/device-port.c
index e170841..b771d23 100644
--- a/src/pulsecore/device-port.c
+++ b/src/pulsecore/device-port.c
@@ -67,6 +67,13 @@ void 
pa_device_port_new_data_set_direction(pa_device_port_new_data *data, pa_dir
 data->direction = direction;
 }
 
+void pa_device_port_new_data_set_latency_offset(pa_device_port_new_data *data, 
int64_t offset) {
+pa_assert(data);
+
+data->latency_offset_is_set = true;
+data->latency_offset = offset;
+}
+
 void pa_device_port_new_data_done(pa_device_port_new_data *data) {
 pa_assert(data);
 
@@ -136,7 +143,11 @@ pa_device_port *pa_device_port_new(pa_core *c, 
pa_device_port_new_data *data, si
 p->profiles = pa_hashmap_new(pa_idxset_string_hash_func, 
pa_idxset_string_compare_func);
 p->direction = data->direction;
 
-p->latency_offset = 0;
+if (!data->latency_offset_is_set)
+p->latency_offset = 0;
+else
+p->latency_offset = data->latency_offset;
+
 p->proplist = pa_proplist_new();
 
 return p;
diff --git a/src/pulsecore/device-port.h b/src/pulsecore/device-port.h
index 213a6f7..f7d2989 100644
--- a/src/pulsecore/device-port.h
+++ b/src/pulsecore/device-port.h
@@ -68,6 +68,8 @@ typedef struct pa_device_port_new_data {
 char *card_name;
 pa_available_t available;
 pa_direction_t direction;
+int64_t latency_offset;
+bool latency_offset_is_set;
 } pa_device_port_new_data;
 
 pa_device_port_new_data *pa_device_port_new_data_init(pa_device_port_new_data 
*data);
@@ -76,6 +78,7 @@ void 
pa_device_port_new_data_set_description(pa_device_port_new_data *data, cons
 void pa_device_port_new_data_set_card_name(pa_device_port_new_data *data, 
const char *card_name);
 void pa_device_port_new_data_set_available(pa_device_port_new_data *data, 
pa_available_t available);
 void pa_device_port_new_data_set_direction(pa_device_port_new_data *data, 
pa_direction_t direction);
+void pa_device_port_new_data_set_latency_offset(pa_device_port_new_data *data, 
int64_t offset);
 void pa_device_port_new_data_done(pa_device_port_new_data *data);
 
 pa_device_port *pa_device_port_new(pa_core *c, pa_device_port_new_data *data, 
size_t extra);
-- 
1.8.2.1

___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


[pulseaudio-discuss] [[PATCH v0] 4/5] device-port: Fire a hook when creating a new port.

2013-04-17 Thread Damir Jelić
This adds a new hook: PA_HOOK_PORT_NEW
---
 src/pulsecore/core.h| 1 +
 src/pulsecore/device-port.c | 5 +
 2 files changed, 6 insertions(+)

diff --git a/src/pulsecore/core.h b/src/pulsecore/core.h
index a8cff5c..2f75b56 100644
--- a/src/pulsecore/core.h
+++ b/src/pulsecore/core.h
@@ -119,6 +119,7 @@ typedef enum pa_core_hook {
 PA_CORE_HOOK_CARD_PROFILE_AVAILABLE_CHANGED,
 PA_CORE_HOOK_PORT_AVAILABLE_CHANGED,
 PA_CORE_HOOK_PORT_LATENCY_OFFSET_CHANGED,
+PA_CORE_HOOK_PORT_NEW,
 PA_CORE_HOOK_MAX
 } pa_core_hook_t;
 
diff --git a/src/pulsecore/device-port.c b/src/pulsecore/device-port.c
index b771d23..6b8a62b 100644
--- a/src/pulsecore/device-port.c
+++ b/src/pulsecore/device-port.c
@@ -132,6 +132,11 @@ pa_device_port *pa_device_port_new(pa_core *c, 
pa_device_port_new_data *data, si
 p = PA_DEVICE_PORT(pa_object_new_internal(PA_ALIGN(sizeof(pa_device_port)) 
+ extra, pa_device_port_type_id, pa_device_port_check_type));
 p->parent.free = device_port_free;
 
+if (pa_hook_fire(&c->hooks[PA_CORE_HOOK_PORT_NEW], data) < 0) {
+pa_xfree(p);
+return NULL;
+}
+
 p->name = data->name;
 data->name = NULL;
 p->description = data->description;
-- 
1.8.2.1

___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


[pulseaudio-discuss] [[PATCH v0] 5/5] card-restore: Restore the latency offset while creating the port.

2013-04-17 Thread Damir Jelić
This changes the way the latency offset is restored.

It is now restored separately for every port during port creation.
The debug message was also changed, it now prints the port name and
offset.
---
 src/modules/module-card-restore.c | 33 +
 1 file changed, 21 insertions(+), 12 deletions(-)

diff --git a/src/modules/module-card-restore.c 
b/src/modules/module-card-restore.c
index 2b3235c..bb1be68 100644
--- a/src/modules/module-card-restore.c
+++ b/src/modules/module-card-restore.c
@@ -65,6 +65,7 @@ struct userdata {
 pa_hook_slot *card_new_hook_slot;
 pa_hook_slot *card_put_hook_slot;
 pa_hook_slot *card_profile_hook_slot;
+pa_hook_slot *port_new_hook_slot;
 pa_hook_slot *port_offset_hook_slot;
 pa_time_event *save_time_event;
 pa_database *database;
@@ -434,11 +435,26 @@ static pa_hook_result_t 
port_offset_change_callback(pa_core *c, pa_device_port *
 return PA_HOOK_OK;
 }
 
+static pa_hook_result_t port_new_callback(pa_core *c, pa_device_port_new_data 
*new_data, struct userdata *u) {
+struct entry *entry;
+struct port_info *p_info;
+
+if (!new_data->card_name || !(entry = entry_read(u, new_data->card_name)))
+return PA_HOOK_OK;
+
+
+if ((p_info = pa_hashmap_get(entry->ports, new_data->name))) {
+pa_log_info("Restoring port latency offsets for port %s: %" PRId64 " 
usecs", new_data->name, p_info->offset);
+pa_device_port_new_data_set_latency_offset(new_data, p_info->offset);
+}
+
+entry_free(entry);
+
+return PA_HOOK_OK;
+}
+
 static pa_hook_result_t card_new_hook_callback(pa_core *c, pa_card_new_data 
*new_data, struct userdata *u) {
 struct entry *e;
-void *state;
-pa_device_port *p;
-struct port_info *p_info;
 
 pa_assert(new_data);
 
@@ -455,15 +471,6 @@ static pa_hook_result_t card_new_hook_callback(pa_core *c, 
pa_card_new_data *new
 pa_log_debug("Not restoring profile for card %s, because already 
set.", new_data->name);
 }
 
-/* Always restore the latency offsets because their
- * initial value is always 0 */
-
-pa_log_info("Restoring port latency offsets for card %s.", new_data->name);
-
-PA_HASHMAP_FOREACH(p_info, e->ports, state)
-if ((p = pa_hashmap_get(new_data->ports, p_info->name)))
-p->latency_offset = p_info->offset;
-
 entry_free(e);
 
 return PA_HOOK_OK;
@@ -488,6 +495,7 @@ int pa__init(pa_module*m) {
 u->card_new_hook_slot = 
pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_CARD_NEW], PA_HOOK_EARLY, 
(pa_hook_cb_t) card_new_hook_callback, u);
 u->card_put_hook_slot = 
pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_CARD_PUT], PA_HOOK_NORMAL, 
(pa_hook_cb_t) card_put_hook_callback, u);
 u->card_profile_hook_slot = 
pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_CARD_PROFILE_CHANGED], 
PA_HOOK_NORMAL, (pa_hook_cb_t) card_profile_change_callback, u);
+u->port_new_hook_slot = 
pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_PORT_NEW], PA_HOOK_EARLY, 
(pa_hook_cb_t) port_new_callback, u);
 u->port_offset_hook_slot = 
pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_PORT_LATENCY_OFFSET_CHANGED], 
PA_HOOK_NORMAL, (pa_hook_cb_t) port_offset_change_callback, u);
 u->hooks_connected = true;
 
@@ -527,6 +535,7 @@ void pa__done(pa_module*m) {
 pa_hook_slot_free(u->card_new_hook_slot);
 pa_hook_slot_free(u->card_put_hook_slot);
 pa_hook_slot_free(u->card_profile_hook_slot);
+pa_hook_slot_free(u->port_new_hook_slot);
 pa_hook_slot_free(u->port_offset_hook_slot);
 }
 
-- 
1.8.2.1

___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


[pulseaudio-discuss] GSoC Proposal: Resampling Improvements

2013-04-18 Thread Damir Jelić
Hi.

For those who don't know, I'm Damir Jelić from Croatia and I would like to
work on the "Resampling Improvements" project during this year's Summer of
Code.

Last year I participated and finished the "Latency offset" project. After
the summer I tried to become a regular contributor. For those who are
interested, all my contributions can be seen in the git log [1].

I know I said that last year should be my final year as a student but I
prolonged my studies for a year and I'm still eligible for this year's
Summer of Code.

I picked this project because it's a part of pulseaudio that I consider
quite interesting and didn't had the chance to touch yet.

I have some DSP background (although more from control theory than from
digital audio) and also I have some assembly background, but not from any
modern instruction set (z80), which should make me a good candidate for this
project.

What I would like to do over the summer:
- enable resampling with libav
- write some test coverage for the libav resampling method
- deprecate the ffmpeg resample method
- update the speex resample method

The ideas page mentions also libresample, if I'm not mistaken pulseaudio
already supports resampling via libresample and I'm not sure what would I
need to do about this.

Speex has been obsoleted [2] and the resampler seems to had been moved to
opus-tools. There are some interesting commits [3] inside this repo and I think
it would be nice to update our speex resample method although I'm not sure
if it's ok to drop speex and replace it with opus-tools just like that.

Suggestions and comments are welcome.

Thanks, poljar.

[1] http://cgit.freedesktop.org/pulseaudio/pulseaudio/log/?qt=author&q=poljar
[2] http://www.speex.org/
[3] 
http://git.xiph.org/?p=opus-tools.git;a=history;f=src/resample.c;h=d957090b2910c212abba567b0ec2f52f2beadb4a;hb=HEAD
___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


[pulseaudio-discuss] [PATCH] switch-on-port-available: Silence gcc warning.

2013-04-19 Thread Damir Jelić
This silences this gcc warning:
module-switch-on-port-available.c:111:12: warning:
'good' may be used uninitialized in this function
---
 src/modules/module-switch-on-port-available.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/modules/module-switch-on-port-available.c 
b/src/modules/module-switch-on-port-available.c
index 82ccb12..1c40295 100644
--- a/src/modules/module-switch-on-port-available.c
+++ b/src/modules/module-switch-on-port-available.c
@@ -92,7 +92,7 @@ static int try_to_switch_profile(pa_device_port *port) {
 pa_log_debug("Finding best profile");
 
 PA_HASHMAP_FOREACH(profile, port->profiles, state) {
-bool good;
+bool good = false;
 
 if (best_profile && best_profile->priority >= profile->priority)
 continue;
-- 
1.8.2.1

___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


Re: [pulseaudio-discuss] GSoC Proposal: Resampling Improvements

2013-04-19 Thread Damir Jelić
Adding pulseaudio-discuss back. Sorry about that.

On Fri, Apr 19, 2013 at 07:08:46PM +0200, Damir Jelić wrote:
> On Fri, Apr 19, 2013 at 07:48:36PM +0300, Tanu Kaskinen wrote:
> > On Thu, 2013-04-18 at 15:26 +0200, Damir Jelić wrote:
> > > Hi.
> > > 
> > > For those who don't know, I'm Damir Jelić from Croatia and I would like to
> > > work on the "Resampling Improvements" project during this year's Summer of
> > > Code.
> > > 
> > > Last year I participated and finished the "Latency offset" project. After
> > > the summer I tried to become a regular contributor. For those who are
> > > interested, all my contributions can be seen in the git log [1].
> > > 
> > > I know I said that last year should be my final year as a student but I
> > > prolonged my studies for a year and I'm still eligible for this year's
> > > Summer of Code.
> > > 
> > > I picked this project because it's a part of pulseaudio that I consider
> > > quite interesting and didn't had the chance to touch yet.
> > > 
> > > I have some DSP background (although more from control theory than from
> > > digital audio) and also I have some assembly background, but not from any
> > > modern instruction set (z80), which should make me a good candidate for 
> > > this
> > > project.
> > > 
> > > What I would like to do over the summer:
> > > - enable resampling with libav
> > > - write some test coverage for the libav resampling method
> > > - deprecate the ffmpeg resample method
> > > - update the speex resample method
> > > 
> > > The ideas page mentions also libresample, if I'm not mistaken pulseaudio
> > > already supports resampling via libresample and I'm not sure what would I
> > > need to do about this.
> > 
> > By "libresample", I guess you mean "libsamplerate". Peter can correct me
> > if I'm intepreting him wrong, but my understanding is that libsamplerate
> > was only mentioned as an example of a resampler with a problematic
> > license. I don't know either what should be done about it - perhaps the
> > idea was to compare the different resamplers, and if it turns out that
> > we don't have any good reason to keep using libsamplerate, we could drop
> > that code.
> > 
> 
> Yes, I've got it wrong since there are some libs named libresample.
> 
> https://ccrma.stanford.edu/~jos/resample/README-libresample-0.1.3.txt
> 
> > > Speex has been obsoleted [2] and the resampler seems to had been moved to
> > > opus-tools. There are some interesting commits [3] inside this repo and I 
> > > think
> > > it would be nice to update our speex resample method although I'm not sure
> > > if it's ok to drop speex and replace it with opus-tools just like that.
> > 
> > To me replacing the speex resampler with the opus-tools resampler sounds
> > like an obvious thing to do, if the upstream says that the speex
> > resampler code is deprecated in favour of opus-tools.
> > 
> 
> Ok, sounds good.
> 
> > -- 
> > Tanu
> > 
> > -
> > Intel Finland Oy
> > Registered Address: PL 281, 00181 Helsinki 
> > Business Identity Code: 0357606 - 4 
> > Domiciled in Helsinki 
> > 
> > This e-mail and any attachments may contain confidential material for
> > the sole use of the intended recipient(s). Any review or distribution
> > by others is strictly prohibited. If you are not the intended
> > recipient, please contact the sender and delete all copies.
___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


Re: [pulseaudio-discuss] GSoC Proposal: Resampling Improvements

2013-04-22 Thread Damir Jelić
Hi Peter.

On Sun, Apr 21, 2013 at 08:31:18PM +0200, Peter Meerwald wrote:
> Hello,
> 
> > > > > What I would like to do over the summer:
> > > > > - enable resampling with libav
> > > > > - write some test coverage for the libav resampling method
> > > > > - deprecate the ffmpeg resample method
> > > > > - update the speex resample method
> 
> > > > > The ideas page mentions also libresample, if I'm not mistaken 
> > > > > pulseaudio
> > > > > already supports resampling via libresample and I'm not sure what 
> > > > > would I
> > > > > need to do about this.
> > > > 
> > > > By "libresample", I guess you mean "libsamplerate". Peter can correct me
> > > > if I'm intepreting him wrong, but my understanding is that libsamplerate
> > > > was only mentioned as an example of a resampler with a problematic
> > > > license. I don't know either what should be done about it - perhaps the
> > > > idea was to compare the different resamplers, and if it turns out that
> > > > we don't have any good reason to keep using libsamplerate, we could drop
> > > > that code.
> 
> libsamplerate was mentioned because of the GPL license;
> to work around, a loadable module interface could be offered, so the user 
> can decide
> 

This sounds like a lot of complexity for little gain. What is wrong with
compile time switches/options?

> > > > > Speex has been obsoleted [2] and the resampler seems to had been 
> > > > > moved to
> > > > > opus-tools. There are some interesting commits [3] inside this repo 
> > > > > and I think
> > > > > it would be nice to update our speex resample method although I'm not 
> > > > > sure
> > > > > if it's ok to drop speex and replace it with opus-tools just like 
> > > > > that.
> 
> > > > To me replacing the speex resampler with the opus-tools resampler sounds
> > > > like an obvious thing to do, if the upstream says that the speex
> > > > resampler code is deprecated in favour of opus-tools.
> 
> yeah, there seem to be interesting fixes/improvements
> 
> p.
> 
> -- 
> 
> Peter Meerwald
> +43-664-218 (mobile)

By the way is there some explicit reason you have chosen libav for this
project? 

FFmpeg now also has a resampling library [1] and I found an interesting
blog post about "ffmpeg vs libav" [2].

Maybe we should support both so different distributions can choose what
to use depending on the default lib they are using.

[1] http://ffmpeg.org/doxygen/trunk/group__lswr.html
[2] 
http://aballier.wordpress.com/2013/01/18/ffmpeg-vs-libav-a-distribution-maintainer-point-of-view-almost-two-years-after-the-split/
___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


Re: [pulseaudio-discuss] GSoC Proposal: Resampling Improvements

2013-04-27 Thread Damir Jelić
On Mon, Apr 22, 2013 at 06:33:08PM +0200, Peter Meerwald wrote:
> Hello, 
> 
> > > > > > By "libresample", I guess you mean "libsamplerate". Peter can 
> > > > > > correct me
> > > > > > if I'm intepreting him wrong, but my understanding is that 
> > > > > > libsamplerate
> > > > > > was only mentioned as an example of a resampler with a problematic
> > > > > > license. I don't know either what should be done about it - perhaps 
> > > > > > the
> > > > > > idea was to compare the different resamplers, and if it turns out 
> > > > > > that
> > > > > > we don't have any good reason to keep using libsamplerate, we could 
> > > > > > drop
> > > > > > that code.
> 
> > > libsamplerate was mentioned because of the GPL license;
> > > to work around, a loadable module interface could be offered, so the user 
> > > can decide
> 
> > This sounds like a lot of complexity for little gain. What is wrong with
> > compile time switches/options?
> 
> maybe yes; depends on how many resamplers there will be
> 
> a loadable module interface enforces a stricter and more stable interface, 
> which may be a good thing
> 
> some refactoring is in place anyway, so depends how far we want to take it
> 

So I checked this out a little bit and I think I could also add this to
my proposal.

Here is what I came up with:
- make the pa_resampler structure implementation agnostic
- replace the static resampling method table with a hashmap or
  idxset
- move the resampler methods to modules and let them register
  themself inside with the core

How does that sound to you?

What do the other devs think about this?

> > > > > > > Speex has been obsoleted [2] and the resampler seems to had been 
> > > > > > > moved to
> > > > > > > opus-tools. There are some interesting commits [3] inside this 
> > > > > > > repo and I think
> > > > > > > it would be nice to update our speex resample method although I'm 
> > > > > > > not sure
> > > > > > > if it's ok to drop speex and replace it with opus-tools just like 
> > > > > > > that.
> > > 
> > > > > > To me replacing the speex resampler with the opus-tools resampler 
> > > > > > sounds
> > > > > > like an obvious thing to do, if the upstream says that the speex
> > > > > > resampler code is deprecated in favour of opus-tools.
> 
> > By the way is there some explicit reason you have chosen libav for this
> > project? 
> > FFmpeg now also has a resampling library [1] and I found an interesting
> > blog post about "ffmpeg vs libav" [2].
> 
> ffmpeg vs. libav is a mess, but I think the dust has settled a little by 
> now
> 
> my impression is that ffmpeg merged libav stuff, but not vice-versa; so 
> there is libswresample and libavresample in ffmpeg, libavresample coming 
> from libav
> 
> > Maybe we should support both so different distributions can choose what
> > to use depending on the default lib they are using.
> 
> libavresample can be provided by ffmpeg and libav; not sure if 
> libswresample should be supported

According to this [1] libswresample should perform better or on par
libavresample, and if it doesn't we can complain.

Supporting both shouldn't be hard anyways and does no harm that I'm
aware of.

[1] http://ffmpeg.org/pipermail/ffmpeg-devel/2012-April/123746.html
___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


[pulseaudio-discuss] [PATCH] shell-completion: Add list-cards to the pacmd completion.

2013-05-22 Thread Damir Jelić
The list-cards command was missing for both of the shell completions.
This fixes it.
---
 shell-completion/pulseaudio-bash-completion.sh | 2 +-
 shell-completion/pulseaudio-zsh-completion.zsh | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/shell-completion/pulseaudio-bash-completion.sh 
b/shell-completion/pulseaudio-bash-completion.sh
index a82b10e..5f60092 100644
--- a/shell-completion/pulseaudio-bash-completion.sh
+++ b/shell-completion/pulseaudio-bash-completion.sh
@@ -259,7 +259,7 @@ _pacmd() {
 local cur prev words cword preprev command
 local comps
 local flags='-h --help --version'
-local commands=(exit help list-modules list-sinks list-sources list-clients
+local commands=(exit help list-modules list-cards list-sinks list-sources 
list-clients
 list-samples list-sink-inputs list-source-outputs stat info
 load-module unload-module describe-module set-sink-volume
 set-source-volume set-sink-input-volume 
set-source-output-volume
diff --git a/shell-completion/pulseaudio-zsh-completion.zsh 
b/shell-completion/pulseaudio-zsh-completion.zsh
index d73b74d..cde82b3 100644
--- a/shell-completion/pulseaudio-zsh-completion.zsh
+++ b/shell-completion/pulseaudio-zsh-completion.zsh
@@ -329,6 +329,7 @@ _pacmd_completion() {
 _pacmd_commands=(
 'help: show help and exit'
 'list-modules: list modules'
+'list-cards: list clients'
 'list-sinks: list sinks'
 'list-sources: list sources'
 'list-clients: list clients'
-- 
1.8.2.3

___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


Re: [pulseaudio-discuss] [[PATCH v0] 1/5] device-port: Allow setting the card name while creating a port.

2013-06-03 Thread Damir Jelić
On Mon, Jun 03, 2013 at 08:31:22PM +0300, Tanu Kaskinen wrote:
> On Thu, 2013-04-18 at 02:24 +0200, poljar (Damir Jelić) wrote:
> > Since we want to be able to set/restore port properties while creating a
> > port and the port properties are saved with the card name as a key we
> > need to know the card name before the port is connected to a card.
> > 
> > This patch enables assigning a card name to the port_new_data struct.
> 
> Thanks, will apply. I added an assertion to pa_device_port_new():
> pa_assert(data->card_name).
> 
> BTW, in case you used the double brackets "[[PATCH v0] 1/5]" in the
> subject on purpose, please don't do it again, or fix git am, which
> doesn't handle it well :)
> 

Sorry about that. I used the --subject-prefix option wrongly for git
format-pacth.

Thanks.
___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


[pulseaudio-discuss] [Git pull] Big cleanup branch

2013-06-18 Thread Damir Jelić
Hi.

I played around with sed and cleaned up the pulseaudio tree.
I've fixed style and whitespace issues and removed some old cruft.

I think the patches would be too big for the mailing list so I have
pushed them to my github repo.

Please take a look at this github branch:
https://github.com/poljar/pulseaudio/tree/cleaning

Thanks.
___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


Re: [pulseaudio-discuss] [Git pull] Big cleanup branch

2013-06-18 Thread Damir Jelić
On Tue, Jun 18, 2013 at 09:48:35PM +0300, Tanu Kaskinen wrote:
> On Tue, 2013-06-18 at 17:06 +0200, Damir Jelić wrote:
> > Hi.
> > 
> > I played around with sed and cleaned up the pulseaudio tree.
> > I've fixed style and whitespace issues and removed some old cruft.
> > 
> > I think the patches would be too big for the mailing list so I have
> > pushed them to my github repo.
> > 
> > Please take a look at this github branch:
> > https://github.com/poljar/pulseaudio/tree/cleaning
> 
> Thanks! I probably won't take the "Remove emacs indentation modeline"
> patch. The commit message says that "these mode lines are actually
> harmful since they conflict with our coding style". I think it's the
> opposite: they are useful precisely because they conflict with our
> coding style. All the changed files are mirrored from external sources,
> which use a different indentation style. For the same reason the tab
> removal shouldn't be done for the modules/reserve* files. Otherwise,
> looks good to me.
> 

Oh, I wasn't aware that the modules/reserve* files were mirrored from
external sources.

Should I redo the patches excluding the modules/reserve* files like I
excluded the ffmpeg tree?
___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


Re: [pulseaudio-discuss] [Git pull] Big cleanup branch

2013-06-18 Thread Damir Jelić
On Tue, Jun 18, 2013 at 10:00:32PM +0300, Tanu Kaskinen wrote:
> On Tue, 2013-06-18 at 20:56 +0200, Damir Jelić wrote:
> > On Tue, Jun 18, 2013 at 09:48:35PM +0300, Tanu Kaskinen wrote:
> > > On Tue, 2013-06-18 at 17:06 +0200, Damir Jelić wrote:
> > > > Hi.
> > > > 
> > > > I played around with sed and cleaned up the pulseaudio tree.
> > > > I've fixed style and whitespace issues and removed some old cruft.
> > > > 
> > > > I think the patches would be too big for the mailing list so I have
> > > > pushed them to my github repo.
> > > > 
> > > > Please take a look at this github branch:
> > > > https://github.com/poljar/pulseaudio/tree/cleaning
> > > 
> > > Thanks! I probably won't take the "Remove emacs indentation modeline"
> > > patch. The commit message says that "these mode lines are actually
> > > harmful since they conflict with our coding style". I think it's the
> > > opposite: they are useful precisely because they conflict with our
> > > coding style. All the changed files are mirrored from external sources,
> > > which use a different indentation style. For the same reason the tab
> > > removal shouldn't be done for the modules/reserve* files. Otherwise,
> > > looks good to me.
> > > 
> > 
> > Oh, I wasn't aware that the modules/reserve* files were mirrored from
> > external sources.
> > 
> > Should I redo the patches excluding the modules/reserve* files like I
> > excluded the ffmpeg tree?
> 
> That would be good.
> 

Updated patches are in this new branch:
https://github.com/poljar/pulseaudio/tree/cleaning_v2

Thanks.
___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


[pulseaudio-discuss] [Git pull] Big pa_bool -> bool cleanup branch

2013-06-25 Thread Damir Jelić
Hi.

I played around with sed some more and replaced pa_bool with bool.

Patches are in this branch on github:
https://github.com/poljar/pulseaudio/tree/bool

Thanks.
___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


Re: [pulseaudio-discuss] [Git pull] Big pa_bool -> bool cleanup branch

2013-06-28 Thread Damir Jelić
As discussed on IRC there were some issues with these patches.

Second version of this patchset is in this branch:
https://github.com/poljar/pulseaudio/commits/bool_v2

Changes since v1:
- modify the sed script to match only whole words
- ignore some files that contain gboolean, dbus_bool_t and BOOL
- fix alignment issues caused by the script
- revert dbus_bool_t and BOOL to use TRUE/FALSE

Thanks.
___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


Re: [pulseaudio-discuss] [PATCH] resampler: Fix peaks resampler's channel handling

2013-07-10 Thread Damir Jelić
On Wed, Jul 10, 2013 at 09:48:40PM +0300, Tanu Kaskinen wrote:
> In the resampling phase the input and output data have the same number
> of channels (o_ss.channels).

Isn't work_channels used to represent the number of channels in the
resampling phase?

> ---
>  src/pulsecore/resampler.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/src/pulsecore/resampler.c b/src/pulsecore/resampler.c
> index cdfaf8f..341d85b 100644
> --- a/src/pulsecore/resampler.c
> +++ b/src/pulsecore/resampler.c
> @@ -1526,7 +1526,7 @@ static void peaks_resample(pa_resampler *r, const 
> pa_memchunk *input, unsigned i
>  o_index++, r->peaks.o_counter++;
>  }
>  } else if (r->work_format == PA_SAMPLE_S16NE) {
> -int16_t *s = (int16_t*) src + r->i_ss.channels * i;
> +int16_t *s = (int16_t*) src + r->o_ss.channels * i;
>  int16_t *d = (int16_t*) dst + r->o_ss.channels * o_index;
>  
>  for (; i < i_end && i < in_n_frames; i++)
> @@ -1545,7 +1545,7 @@ static void peaks_resample(pa_resampler *r, const 
> pa_memchunk *input, unsigned i
>  o_index++, r->peaks.o_counter++;
>  }
>  } else {
> -float *s = (float*) src + r->i_ss.channels * i;
> +float *s = (float*) src + r->o_ss.channels * i;
>  float *d = (float*) dst + r->o_ss.channels * o_index;
>  
>  for (; i < i_end && i < in_n_frames; i++)
> -- 
> 1.8.1.2
> 
> ___
> pulseaudio-discuss mailing list
> pulseaudio-discuss@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss
___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


[pulseaudio-discuss] [PATCH 00/18] resampler: Refactor and cleanup

2013-07-15 Thread Damir Jelić
Hi.
This is my first patch series for this years Summer of Code.

The only user visible change is that we don't show unsupported (not
compiled in) resample methods with --dump-resample-methods. This 
also means we don't allow running the daemon with an unsupported 
resample method.

A nice overview what has been done can be found on my blog [1].

Thanks.

[1] http://poljar.blogspot.com/2013/07/vol-1-refactoring.html

poljar (Damir Jelić) (18):
  resampler: Make resampler struct implementation agnostic
  resampler: Move the fix method logic into a separate function
  resampler: fix_method use switch instead of if/else
  resampler: Move the work format finding logic into a separate function
  resampler: choose_work_format use switch instead of if/else
  resampler: Add a function for comparing sample format precision
  Resampler: Don't use the peaks resampler for upsampling
  resampler: Introduce a implementation specific struct
  resampler: Add assert to set_input/output_rate
  resampler: Replace the big init table with a impl_table
  resampler: Refactor the logic for finding the implementation
  resampler: Simplify the resample_method_supported() function
  resampler: Get rid of redundant implementation specific structs
  resampler: Add a choose_auto_resampler function
  resampler: Move the method strings into the implementation struct
  resampler: Don't check for unsupported methods in fix_method
  resampler: Add the auto resampling implementation
  resampler: Remove double newlines

 src/pulsecore/resampler.c | 720 +++---
 src/pulsecore/resampler.h |  13 +
 2 files changed, 441 insertions(+), 292 deletions(-)

-- 
1.8.3.2

___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


[pulseaudio-discuss] [PATCH 01/18] resampler: Make resampler struct implementation agnostic

2013-07-15 Thread Damir Jelić
The pa_resampler struct contains many implementation specific
structures. These create overhead and don't belong there anyways.

This patch moves the implementation specific structures out of the
pa_resampler structure.
---
 src/pulsecore/resampler.c | 223 +-
 1 file changed, 139 insertions(+), 84 deletions(-)

diff --git a/src/pulsecore/resampler.c b/src/pulsecore/resampler.c
index cdfaf8f..f70f186 100644
--- a/src/pulsecore/resampler.c
+++ b/src/pulsecore/resampler.c
@@ -78,37 +78,37 @@ struct pa_resampler {
 void (*impl_update_rates)(pa_resampler *r);
 void (*impl_resample)(pa_resampler *r, const pa_memchunk *in, unsigned 
in_samples, pa_memchunk *out, unsigned *out_samples);
 void (*impl_reset)(pa_resampler *r);
+void *impl_data;
+};
 
-struct { /* data specific to the trivial resampler */
-unsigned o_counter;
-unsigned i_counter;
-} trivial;
-
-struct { /* data specific to the peak finder pseudo resampler */
-unsigned o_counter;
-unsigned i_counter;
+struct trivial { /* data specific to the trivial resampler */
+unsigned o_counter;
+unsigned i_counter;
+};
 
-float max_f[PA_CHANNELS_MAX];
-int16_t max_i[PA_CHANNELS_MAX];
+struct peaks{ /* data specific to the peak finder pseudo resampler */
+unsigned o_counter;
+unsigned i_counter;
 
-} peaks;
+float max_f[PA_CHANNELS_MAX];
+int16_t max_i[PA_CHANNELS_MAX];
+};
 
 #ifdef HAVE_LIBSAMPLERATE
-struct { /* data specific to libsamplerate */
-SRC_STATE *state;
-} src;
+struct src{ /* data specific to libsamplerate */
+SRC_STATE *state;
+};
 #endif
 
 #ifdef HAVE_SPEEX
-struct { /* data specific to speex */
-SpeexResamplerState* state;
-} speex;
+struct speex{ /* data specific to speex */
+SpeexResamplerState* state;
+};
 #endif
 
-struct { /* data specific to ffmpeg */
-struct AVResampleContext *state;
-pa_memchunk buf[PA_CHANNELS_MAX];
-} ffmpeg;
+struct ffmpeg { /* data specific to ffmpeg */
+struct AVResampleContext *state;
+pa_memchunk buf[PA_CHANNELS_MAX];
 };
 
 static int copy_init(pa_resampler *r);
@@ -355,6 +355,7 @@ void pa_resampler_free(pa_resampler *r) {
 if (r->from_work_format_buf.memblock)
 pa_memblock_unref(r->from_work_format_buf.memblock);
 
+pa_xfree(r->impl_data);
 pa_xfree(r);
 }
 
@@ -1256,12 +1257,14 @@ static void save_leftover(pa_resampler *r, void *buf, 
size_t len) {
 #ifdef HAVE_LIBSAMPLERATE
 static void libsamplerate_resample(pa_resampler *r, const pa_memchunk *input, 
unsigned in_n_frames, pa_memchunk *output, unsigned *out_n_frames) {
 SRC_DATA data;
+struct src *libsamplerate_data;
 
 pa_assert(r);
 pa_assert(input);
 pa_assert(output);
 pa_assert(out_n_frames);
 
+libsamplerate_data = r->impl_data;
 memset(&data, 0, sizeof(data));
 
 data.data_in = pa_memblock_acquire_chunk(input);
@@ -1273,7 +1276,7 @@ static void libsamplerate_resample(pa_resampler *r, const 
pa_memchunk *input, un
 data.src_ratio = (double) r->o_ss.rate / r->i_ss.rate;
 data.end_of_input = 0;
 
-pa_assert_se(src_process(r->src.state, &data) == 0);
+pa_assert_se(src_process(libsamplerate_data->state, &data) == 0);
 
 if (data.input_frames_used < in_n_frames) {
 void *leftover_data = data.data_in + data.input_frames_used * 
r->o_ss.channels;
@@ -1289,36 +1292,46 @@ static void libsamplerate_resample(pa_resampler *r, 
const pa_memchunk *input, un
 }
 
 static void libsamplerate_update_rates(pa_resampler *r) {
+struct src *libsamplerate_data;
 pa_assert(r);
 
-pa_assert_se(src_set_ratio(r->src.state, (double) r->o_ss.rate / 
r->i_ss.rate) == 0);
+libsamplerate_data = r->impl_data;
+pa_assert_se(src_set_ratio(libsamplerate_data->state, (double) 
r->o_ss.rate / r->i_ss.rate) == 0);
 }
 
 static void libsamplerate_reset(pa_resampler *r) {
+struct src *libsamplerate_data;
 pa_assert(r);
 
-pa_assert_se(src_reset(r->src.state) == 0);
+libsamplerate_data = r->impl_data;
+pa_assert_se(src_reset(libsamplerate_data->state) == 0);
 }
 
 static void libsamplerate_free(pa_resampler *r) {
+struct src *libsamplerate_data;
 pa_assert(r);
 
-if (r->src.state)
-src_delete(r->src.state);
+libsamplerate_data = r->impl_data;
+if (libsamplerate_data->state)
+src_delete(libsamplerate_data->state);
 }
 
 static int libsamplerate_init(pa_resampler *r) {
 int err;
+struct src *libsamplerate_data;
 
 pa_assert(r);
 
-if (!(r->src.state = src_new(r->method, r->o_ss.channels, &err)))
+libsamplerate_data = pa_xnew(struct src, 1);
+
+if (!(libsamplerate_data->state = src_new(r->method, r->o_ss.channels, 
&err)))
 return -1;
 
 r->impl_free = libsamplerate_free;
 r->impl_update_rates = libsamplerate_update_rates;
 r->impl_resample = libsamplerate_resample;
 r->impl_res

[pulseaudio-discuss] [PATCH 02/18] resampler: Move the fix method logic into a separate function

2013-07-15 Thread Damir Jelić
---
 src/pulsecore/resampler.c | 52 ++-
 1 file changed, 33 insertions(+), 19 deletions(-)

diff --git a/src/pulsecore/resampler.c b/src/pulsecore/resampler.c
index f70f186..35bcaf9 100644
--- a/src/pulsecore/resampler.c
+++ b/src/pulsecore/resampler.c
@@ -192,28 +192,18 @@ static int (* const init_table[])(pa_resampler*r) = {
 [PA_RESAMPLER_PEAKS]   = peaks_init,
 };
 
-pa_resampler* pa_resampler_new(
-pa_mempool *pool,
-const pa_sample_spec *a,
-const pa_channel_map *am,
-const pa_sample_spec *b,
-const pa_channel_map *bm,
-pa_resample_method_t method,
-pa_resample_flags_t flags) {
-
-pa_resampler *r = NULL;
-
-pa_assert(pool);
-pa_assert(a);
-pa_assert(b);
-pa_assert(pa_sample_spec_valid(a));
-pa_assert(pa_sample_spec_valid(b));
+static pa_resample_method_t pa_resampler_fix_method(
+pa_resample_flags_t flags,
+pa_resample_method_t method,
+const uint32_t rate_a,
+const uint32_t rate_b) {
+
+pa_assert(rate_a > 0 && rate_a <= PA_RATE_MAX);
+pa_assert(rate_b > 0 && rate_b <= PA_RATE_MAX);
 pa_assert(method >= 0);
 pa_assert(method < PA_RESAMPLER_MAX);
 
-/* Fix method */
-
-if (!(flags & PA_RESAMPLER_VARIABLE_RATE) && a->rate == b->rate) {
+if (!(flags & PA_RESAMPLER_VARIABLE_RATE) && rate_a == rate_b) {
 pa_log_info("Forcing resampler 'copy', because of fixed, identical 
sample rates.");
 method = PA_RESAMPLER_COPY;
 }
@@ -244,6 +234,30 @@ pa_resampler* pa_resampler_new(
 #endif
 }
 
+return method;
+}
+
+pa_resampler* pa_resampler_new(
+pa_mempool *pool,
+const pa_sample_spec *a,
+const pa_channel_map *am,
+const pa_sample_spec *b,
+const pa_channel_map *bm,
+pa_resample_method_t method,
+pa_resample_flags_t flags) {
+
+pa_resampler *r = NULL;
+
+pa_assert(pool);
+pa_assert(a);
+pa_assert(b);
+pa_assert(pa_sample_spec_valid(a));
+pa_assert(pa_sample_spec_valid(b));
+pa_assert(method >= 0);
+pa_assert(method < PA_RESAMPLER_MAX);
+
+method = pa_resampler_fix_method(flags, method, a->rate, b->rate);
+
 r = pa_xnew0(pa_resampler, 1);
 r->mempool = pool;
 r->method = method;
-- 
1.8.3.2

___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


[pulseaudio-discuss] [PATCH 03/18] resampler: fix_method use switch instead of if/else

2013-07-15 Thread Damir Jelić
This way the fix method function should be more readable and easier to
expand in the future.
---
 src/pulsecore/resampler.c | 18 ++
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/src/pulsecore/resampler.c b/src/pulsecore/resampler.c
index 35bcaf9..b3bbb18 100644
--- a/src/pulsecore/resampler.c
+++ b/src/pulsecore/resampler.c
@@ -213,14 +213,16 @@ static pa_resample_method_t pa_resampler_fix_method(
 method = PA_RESAMPLER_AUTO;
 }
 
-if (method == PA_RESAMPLER_FFMPEG && (flags & PA_RESAMPLER_VARIABLE_RATE)) 
{
-pa_log_info("Resampler 'ffmpeg' cannot do variable rate, reverting to 
resampler 'auto'.");
-method = PA_RESAMPLER_AUTO;
-}
-
-if (method == PA_RESAMPLER_COPY && ((flags & PA_RESAMPLER_VARIABLE_RATE) 
|| a->rate != b->rate)) {
-pa_log_info("Resampler 'copy' cannot change sampling rate, reverting 
to resampler 'auto'.");
-method = PA_RESAMPLER_AUTO;
+switch (method) {
+case PA_RESAMPLER_COPY: /* fall through */
+case PA_RESAMPLER_FFMPEG:
+if (flags & PA_RESAMPLER_VARIABLE_RATE) {
+pa_log_info("Resampler '%s' cannot do variable rate, reverting 
to resampler 'auto'.", pa_resample_method_to_string(method));
+method = PA_RESAMPLER_AUTO;
+}
+break;
+default:
+break;
 }
 
 if (method == PA_RESAMPLER_AUTO) {
-- 
1.8.3.2

___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


[pulseaudio-discuss] [PATCH 04/18] resampler: Move the work format finding logic into a separate function

2013-07-15 Thread Damir Jelić
---
 src/pulsecore/resampler.c | 69 +--
 1 file changed, 43 insertions(+), 26 deletions(-)

diff --git a/src/pulsecore/resampler.c b/src/pulsecore/resampler.c
index b3bbb18..0adde29 100644
--- a/src/pulsecore/resampler.c
+++ b/src/pulsecore/resampler.c
@@ -239,6 +239,48 @@ static pa_resample_method_t pa_resampler_fix_method(
 return method;
 }
 
+static pa_sample_format_t pa_resampler_choose_work_format(
+pa_resample_method_t method,
+pa_sample_format_t a,
+pa_sample_format_t b,
+bool map_required) {
+pa_sample_format_t work_format;
+
+pa_assert(a >= 0 && a < PA_SAMPLE_MAX);
+pa_assert(b >= 0 && b < PA_SAMPLE_MAX);
+pa_assert(method >= 0);
+pa_assert(method < PA_RESAMPLER_MAX);
+
+if ((method >= PA_RESAMPLER_SPEEX_FIXED_BASE && method <= 
PA_RESAMPLER_SPEEX_FIXED_MAX) ||
+(method == PA_RESAMPLER_FFMPEG))
+work_format = PA_SAMPLE_S16NE;
+else if (method == PA_RESAMPLER_TRIVIAL || method == PA_RESAMPLER_COPY || 
method == PA_RESAMPLER_PEAKS) {
+
+if (map_required || a != b || method == PA_RESAMPLER_PEAKS) {
+
+if (a == PA_SAMPLE_S16NE || b == PA_SAMPLE_S16NE)
+work_format = PA_SAMPLE_S16NE;
+else if (a == PA_SAMPLE_S32NE || a == PA_SAMPLE_S32RE ||
+a == PA_SAMPLE_FLOAT32NE || a == PA_SAMPLE_FLOAT32RE ||
+a == PA_SAMPLE_S24NE || a == PA_SAMPLE_S24RE ||
+a == PA_SAMPLE_S24_32NE || a == PA_SAMPLE_S24_32RE ||
+b == PA_SAMPLE_S32NE || b == PA_SAMPLE_S32RE ||
+b == PA_SAMPLE_FLOAT32NE || b == PA_SAMPLE_FLOAT32RE ||
+b == PA_SAMPLE_S24NE || b == PA_SAMPLE_S24RE ||
+b == PA_SAMPLE_S24_32NE || b == PA_SAMPLE_S24_32RE)
+work_format = PA_SAMPLE_FLOAT32NE;
+else
+work_format = PA_SAMPLE_S16NE;
+
+} else
+work_format = a;
+
+} else
+work_format = PA_SAMPLE_FLOAT32NE;
+
+return work_format;
+}
+
 pa_resampler* pa_resampler_new(
 pa_mempool *pool,
 const pa_sample_spec *a,
@@ -291,32 +333,7 @@ pa_resampler* pa_resampler_new(
 
 pa_log_info("Using resampler '%s'", pa_resample_method_to_string(method));
 
-if ((method >= PA_RESAMPLER_SPEEX_FIXED_BASE && method <= 
PA_RESAMPLER_SPEEX_FIXED_MAX) ||
-(method == PA_RESAMPLER_FFMPEG))
-r->work_format = PA_SAMPLE_S16NE;
-else if (method == PA_RESAMPLER_TRIVIAL || method == PA_RESAMPLER_COPY || 
method == PA_RESAMPLER_PEAKS) {
-
-if (r->map_required || a->format != b->format || method == 
PA_RESAMPLER_PEAKS) {
-
-if (a->format == PA_SAMPLE_S16NE || b->format == PA_SAMPLE_S16NE)
-r->work_format = PA_SAMPLE_S16NE;
-else if (a->format == PA_SAMPLE_S32NE || a->format == 
PA_SAMPLE_S32RE ||
-a->format == PA_SAMPLE_FLOAT32NE || a->format == 
PA_SAMPLE_FLOAT32RE ||
-a->format == PA_SAMPLE_S24NE || a->format == PA_SAMPLE_S24RE ||
-a->format == PA_SAMPLE_S24_32NE || a->format == 
PA_SAMPLE_S24_32RE ||
-b->format == PA_SAMPLE_S32NE || b->format == PA_SAMPLE_S32RE ||
-b->format == PA_SAMPLE_FLOAT32NE || b->format == 
PA_SAMPLE_FLOAT32RE ||
-b->format == PA_SAMPLE_S24NE || b->format == PA_SAMPLE_S24RE ||
-b->format == PA_SAMPLE_S24_32NE || b->format == 
PA_SAMPLE_S24_32RE)
-r->work_format = PA_SAMPLE_FLOAT32NE;
-else
-r->work_format = PA_SAMPLE_S16NE;
-
-} else
-r->work_format = a->format;
-
-} else
-r->work_format = PA_SAMPLE_FLOAT32NE;
+r->work_format = pa_resampler_choose_work_format(method, a->format, 
b->format, r->map_required);
 
 pa_log_info("Using %s as working format.", 
pa_sample_format_to_string(r->work_format));
 
-- 
1.8.3.2

___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


[pulseaudio-discuss] [PATCH 05/18] resampler: choose_work_format use switch instead of if/else

2013-07-15 Thread Damir Jelić
This way the function for choosing the work format should
be more readable and easier to expand in the future.
---
 src/pulsecore/resampler.c | 33 +++--
 1 file changed, 23 insertions(+), 10 deletions(-)

diff --git a/src/pulsecore/resampler.c b/src/pulsecore/resampler.c
index 0adde29..e3be709 100644
--- a/src/pulsecore/resampler.c
+++ b/src/pulsecore/resampler.c
@@ -251,13 +251,27 @@ static pa_sample_format_t pa_resampler_choose_work_format(
 pa_assert(method >= 0);
 pa_assert(method < PA_RESAMPLER_MAX);
 
-if ((method >= PA_RESAMPLER_SPEEX_FIXED_BASE && method <= 
PA_RESAMPLER_SPEEX_FIXED_MAX) ||
-(method == PA_RESAMPLER_FFMPEG))
-work_format = PA_SAMPLE_S16NE;
-else if (method == PA_RESAMPLER_TRIVIAL || method == PA_RESAMPLER_COPY || 
method == PA_RESAMPLER_PEAKS) {
+if (method >= PA_RESAMPLER_SPEEX_FIXED_BASE && method <= 
PA_RESAMPLER_SPEEX_FIXED_MAX)
+method = PA_RESAMPLER_SPEEX_FIXED_BASE;
 
-if (map_required || a != b || method == PA_RESAMPLER_PEAKS) {
+switch (method) {
+/* This block is for resampling functions that only
+ * support the S16 sample format. */
+case PA_RESAMPLER_SPEEX_FIXED_BASE: /* fall through */
+case PA_RESAMPLER_FFMPEG:
+work_format = PA_SAMPLE_S16NE;
+break;
 
+/* This block is for resampling functions that support
+ * any sample format. */
+case PA_RESAMPLER_COPY: /* fall through */
+case PA_RESAMPLER_TRIVIAL:
+if (!map_required && a == b) {
+work_format = a;
+break;
+}
+/* Else fall trough */
+case PA_RESAMPLER_PEAKS:
 if (a == PA_SAMPLE_S16NE || b == PA_SAMPLE_S16NE)
 work_format = PA_SAMPLE_S16NE;
 else if (a == PA_SAMPLE_S32NE || a == PA_SAMPLE_S32RE ||
@@ -271,12 +285,11 @@ static pa_sample_format_t pa_resampler_choose_work_format(
 work_format = PA_SAMPLE_FLOAT32NE;
 else
 work_format = PA_SAMPLE_S16NE;
+break;
 
-} else
-work_format = a;
-
-} else
-work_format = PA_SAMPLE_FLOAT32NE;
+default:
+work_format = PA_SAMPLE_FLOAT32NE;
+}
 
 return work_format;
 }
-- 
1.8.3.2

___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


[pulseaudio-discuss] [PATCH 06/18] resampler: Add a function for comparing sample format precision

2013-07-15 Thread Damir Jelić
---
 src/pulsecore/resampler.c | 58 ---
 1 file changed, 50 insertions(+), 8 deletions(-)

diff --git a/src/pulsecore/resampler.c b/src/pulsecore/resampler.c
index e3be709..740d9cd 100644
--- a/src/pulsecore/resampler.c
+++ b/src/pulsecore/resampler.c
@@ -239,6 +239,54 @@ static pa_resample_method_t pa_resampler_fix_method(
 return method;
 }
 
+/* Return true if a is a more precise sample format than b, else return false 
*/
+static bool sample_format_more_precise(pa_sample_format_t a, 
pa_sample_format_t b) {
+pa_assert(a >= 0 && a < PA_SAMPLE_MAX);
+pa_assert(b >= 0 && b < PA_SAMPLE_MAX);
+
+switch (a) {
+case PA_SAMPLE_U8:
+case PA_SAMPLE_ALAW:
+case PA_SAMPLE_ULAW:
+return false;
+break;
+
+case PA_SAMPLE_S16LE:
+case PA_SAMPLE_S16BE:
+if (b == PA_SAMPLE_ULAW || b == PA_SAMPLE_ALAW || b == 
PA_SAMPLE_U8 ||
+b == PA_SAMPLE_S16LE || b == PA_SAMPLE_S16BE)
+return false;
+else
+return true;
+break;
+
+case PA_SAMPLE_S24LE:
+case PA_SAMPLE_S24BE:
+case PA_SAMPLE_S24_32LE:
+case PA_SAMPLE_S24_32BE:
+if (b == PA_SAMPLE_ULAW || b == PA_SAMPLE_ALAW || b == 
PA_SAMPLE_U8 ||
+b == PA_SAMPLE_S16LE || b == PA_SAMPLE_S16BE)
+return true;
+else
+return false;
+break;
+
+case PA_SAMPLE_FLOAT32LE:
+case PA_SAMPLE_FLOAT32BE:
+case PA_SAMPLE_S32LE:
+case PA_SAMPLE_S32BE:
+if (b == PA_SAMPLE_FLOAT32LE || b == PA_SAMPLE_FLOAT32BE ||
+b == PA_SAMPLE_S32LE || b == PA_SAMPLE_FLOAT32BE)
+return false;
+else
+return true;
+break;
+
+default:
+return false;
+}
+}
+
 static pa_sample_format_t pa_resampler_choose_work_format(
 pa_resample_method_t method,
 pa_sample_format_t a,
@@ -274,14 +322,8 @@ static pa_sample_format_t pa_resampler_choose_work_format(
 case PA_RESAMPLER_PEAKS:
 if (a == PA_SAMPLE_S16NE || b == PA_SAMPLE_S16NE)
 work_format = PA_SAMPLE_S16NE;
-else if (a == PA_SAMPLE_S32NE || a == PA_SAMPLE_S32RE ||
-a == PA_SAMPLE_FLOAT32NE || a == PA_SAMPLE_FLOAT32RE ||
-a == PA_SAMPLE_S24NE || a == PA_SAMPLE_S24RE ||
-a == PA_SAMPLE_S24_32NE || a == PA_SAMPLE_S24_32RE ||
-b == PA_SAMPLE_S32NE || b == PA_SAMPLE_S32RE ||
-b == PA_SAMPLE_FLOAT32NE || b == PA_SAMPLE_FLOAT32RE ||
-b == PA_SAMPLE_S24NE || b == PA_SAMPLE_S24RE ||
-b == PA_SAMPLE_S24_32NE || b == PA_SAMPLE_S24_32RE)
+else if (sample_format_more_precise(a, PA_SAMPLE_S16NE) ||
+ sample_format_more_precise(b, PA_SAMPLE_S16NE))
 work_format = PA_SAMPLE_FLOAT32NE;
 else
 work_format = PA_SAMPLE_S16NE;
-- 
1.8.3.2

___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


[pulseaudio-discuss] [PATCH 07/18] Resampler: Don't use the peaks resampler for upsampling

2013-07-15 Thread Damir Jelić
This patch fixes this assertion:
Assertion 'r->i_ss.rate >= r->o_ss.rate' failed at 
../../src/pulsecore/resampler.c:1744, function peaks_init(). Aborting.
---
 src/pulsecore/resampler.c | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/src/pulsecore/resampler.c b/src/pulsecore/resampler.c
index 740d9cd..4d542bc 100644
--- a/src/pulsecore/resampler.c
+++ b/src/pulsecore/resampler.c
@@ -221,6 +221,16 @@ static pa_resample_method_t pa_resampler_fix_method(
 method = PA_RESAMPLER_AUTO;
 }
 break;
+
+/* The Peaks resampler only supports downsampling.
+ * Revert to auto if we are upsampling */
+case PA_RESAMPLER_PEAKS:
+if (rate_a < rate_b) {
+pa_log_warn("The 'peaks' resampler only supports downsampling, 
reverting to resampler 'auto'.");
+method = PA_RESAMPLER_AUTO;
+}
+break;
+
 default:
 break;
 }
-- 
1.8.3.2

___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


[pulseaudio-discuss] [PATCH 08/18] resampler: Introduce a implementation specific struct

2013-07-15 Thread Damir Jelić
This struct holds all the implementation specific data in one place.
---
 src/pulsecore/resampler.c | 98 +++
 src/pulsecore/resampler.h |  9 +
 2 files changed, 56 insertions(+), 51 deletions(-)

diff --git a/src/pulsecore/resampler.c b/src/pulsecore/resampler.c
index 4d542bc..ea5f1aa 100644
--- a/src/pulsecore/resampler.c
+++ b/src/pulsecore/resampler.c
@@ -74,11 +74,7 @@ struct pa_resampler {
 pa_remap_t remap;
 bool map_required;
 
-void (*impl_free)(pa_resampler *r);
-void (*impl_update_rates)(pa_resampler *r);
-void (*impl_resample)(pa_resampler *r, const pa_memchunk *in, unsigned 
in_samples, pa_memchunk *out, unsigned *out_samples);
-void (*impl_reset)(pa_resampler *r);
-void *impl_data;
+pa_resampler_implementation implementation;
 };
 
 struct trivial { /* data specific to the trivial resampler */
@@ -441,8 +437,8 @@ fail:
 void pa_resampler_free(pa_resampler *r) {
 pa_assert(r);
 
-if (r->impl_free)
-r->impl_free(r);
+if (r->implementation.free)
+r->implementation.free(r);
 
 if (r->to_work_format_buf.memblock)
 pa_memblock_unref(r->to_work_format_buf.memblock);
@@ -453,7 +449,7 @@ void pa_resampler_free(pa_resampler *r) {
 if (r->from_work_format_buf.memblock)
 pa_memblock_unref(r->from_work_format_buf.memblock);
 
-pa_xfree(r->impl_data);
+pa_xfree(r->implementation.data);
 pa_xfree(r);
 }
 
@@ -466,7 +462,7 @@ void pa_resampler_set_input_rate(pa_resampler *r, uint32_t 
rate) {
 
 r->i_ss.rate = rate;
 
-r->impl_update_rates(r);
+r->implementation.update_rates(r);
 }
 
 void pa_resampler_set_output_rate(pa_resampler *r, uint32_t rate) {
@@ -478,7 +474,7 @@ void pa_resampler_set_output_rate(pa_resampler *r, uint32_t 
rate) {
 
 r->o_ss.rate = rate;
 
-r->impl_update_rates(r);
+r->implementation.update_rates(r);
 }
 
 size_t pa_resampler_request(pa_resampler *r, size_t out_length) {
@@ -544,8 +540,8 @@ size_t pa_resampler_max_block_size(pa_resampler *r) {
 void pa_resampler_reset(pa_resampler *r) {
 pa_assert(r);
 
-if (r->impl_reset)
-r->impl_reset(r);
+if (r->implementation.reset)
+r->implementation.reset(r);
 
 r->remap_buf_contains_leftover_data = false;
 }
@@ -1235,7 +1231,7 @@ static pa_memchunk *resample(pa_resampler *r, pa_memchunk 
*input) {
 
 /* Resample the data and place the result in resample_buf. */
 
-if (!r->impl_resample || !input->length)
+if (!r->implementation.resample || !input->length)
 return input;
 
 in_n_samples = (unsigned) (input->length / r->w_sz);
@@ -1255,7 +1251,7 @@ static pa_memchunk *resample(pa_resampler *r, pa_memchunk 
*input) {
 r->resample_buf.memblock = pa_memblock_new(r->mempool, 
r->resample_buf.length);
 }
 
-r->impl_resample(r, input, in_n_frames, &r->resample_buf, &out_n_frames);
+r->implementation.resample(r, input, in_n_frames, &r->resample_buf, 
&out_n_frames);
 r->resample_buf.length = out_n_frames * r->w_sz * r->o_ss.channels;
 
 return &r->resample_buf;
@@ -1362,7 +1358,7 @@ static void libsamplerate_resample(pa_resampler *r, const 
pa_memchunk *input, un
 pa_assert(output);
 pa_assert(out_n_frames);
 
-libsamplerate_data = r->impl_data;
+libsamplerate_data = r->implementation.data;
 memset(&data, 0, sizeof(data));
 
 data.data_in = pa_memblock_acquire_chunk(input);
@@ -1393,7 +1389,7 @@ static void libsamplerate_update_rates(pa_resampler *r) {
 struct src *libsamplerate_data;
 pa_assert(r);
 
-libsamplerate_data = r->impl_data;
+libsamplerate_data = r->implementation.data;
 pa_assert_se(src_set_ratio(libsamplerate_data->state, (double) 
r->o_ss.rate / r->i_ss.rate) == 0);
 }
 
@@ -1401,7 +1397,7 @@ static void libsamplerate_reset(pa_resampler *r) {
 struct src *libsamplerate_data;
 pa_assert(r);
 
-libsamplerate_data = r->impl_data;
+libsamplerate_data = r->implementation.data;
 pa_assert_se(src_reset(libsamplerate_data->state) == 0);
 }
 
@@ -1409,7 +1405,7 @@ static void libsamplerate_free(pa_resampler *r) {
 struct src *libsamplerate_data;
 pa_assert(r);
 
-libsamplerate_data = r->impl_data;
+libsamplerate_data = r->implementation.data;
 if (libsamplerate_data->state)
 src_delete(libsamplerate_data->state);
 }
@@ -1425,11 +1421,11 @@ static int libsamplerate_init(pa_resampler *r) {
 if (!(libsamplerate_data->state = src_new(r->method, r->o_ss.channels, 
&err)))
 return -1;
 
-r->impl_free = libsamplerate_free;
-r->impl_update_rates = libsamplerate_update_rates;
-r->impl_resample = libsamplerate_resample;
-r->impl_reset = libsamplerate_reset;
-r->impl_data = libsamplerate_data;
+r->implementation.free = libsamplerate_free;
+r->implementation.update_rates = libsamplerate_update_rates;
+r->implementation.resample = libsamplerate_resample;
+r->implementation.r

[pulseaudio-discuss] [PATCH 09/18] resampler: Add assert to set_input/output_rate

2013-07-15 Thread Damir Jelić
This adds asserts to check if the implementation has an update rate
function defined.
---
 src/pulsecore/resampler.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/pulsecore/resampler.c b/src/pulsecore/resampler.c
index ea5f1aa..35342af 100644
--- a/src/pulsecore/resampler.c
+++ b/src/pulsecore/resampler.c
@@ -456,6 +456,7 @@ void pa_resampler_free(pa_resampler *r) {
 void pa_resampler_set_input_rate(pa_resampler *r, uint32_t rate) {
 pa_assert(r);
 pa_assert(rate > 0);
+pa_assert(r->implementation.update_rates);
 
 if (r->i_ss.rate == rate)
 return;
@@ -468,6 +469,7 @@ void pa_resampler_set_input_rate(pa_resampler *r, uint32_t 
rate) {
 void pa_resampler_set_output_rate(pa_resampler *r, uint32_t rate) {
 pa_assert(r);
 pa_assert(rate > 0);
+pa_assert(r->implementation.update_rates);
 
 if (r->o_ss.rate == rate)
 return;
-- 
1.8.3.2

___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


[pulseaudio-discuss] [PATCH 10/18] resampler: Replace the big init table with a impl_table

2013-07-15 Thread Damir Jelić
This gets rid of multiple entries of a implementation in the init table.
---
 src/pulsecore/resampler.c | 192 ++
 src/pulsecore/resampler.h |   1 +
 2 files changed, 94 insertions(+), 99 deletions(-)

diff --git a/src/pulsecore/resampler.c b/src/pulsecore/resampler.c
index 35342af..c297188 100644
--- a/src/pulsecore/resampler.c
+++ b/src/pulsecore/resampler.c
@@ -77,115 +77,117 @@ struct pa_resampler {
 pa_resampler_implementation implementation;
 };
 
-struct trivial { /* data specific to the trivial resampler */
-unsigned o_counter;
-unsigned i_counter;
+static int copy_init(pa_resampler *r);
+
+static pa_resampler_implementation copy_impl = {
+.init = copy_init,
 };
 
-struct peaks{ /* data specific to the peak finder pseudo resampler */
+static int trivial_init(pa_resampler*r);
+static void trivial_resample(pa_resampler *r, const pa_memchunk *input, 
unsigned in_n_frames, pa_memchunk *output, unsigned *out_n_frames);
+static void trivial_update_rates_or_reset(pa_resampler *r);
+
+struct trivial { /* data specific to the trivial resampler */
 unsigned o_counter;
 unsigned i_counter;
-
-float max_f[PA_CHANNELS_MAX];
-int16_t max_i[PA_CHANNELS_MAX];
 };
 
-#ifdef HAVE_LIBSAMPLERATE
-struct src{ /* data specific to libsamplerate */
-SRC_STATE *state;
+static pa_resampler_implementation trivial_impl = {
+.init = trivial_init,
+.resample = trivial_resample,
+.update_rates = trivial_update_rates_or_reset,
+.reset = trivial_update_rates_or_reset,
 };
-#endif
 
 #ifdef HAVE_SPEEX
+static int speex_init(pa_resampler*r);
+static void speex_free(pa_resampler *r);
+static void speex_update_rates(pa_resampler *r);
+static void speex_reset(pa_resampler *r);
+
 struct speex{ /* data specific to speex */
 SpeexResamplerState* state;
 };
+
+static pa_resampler_implementation speex_impl = {
+.init = speex_init,
+.free = speex_free,
+.update_rates = speex_update_rates,
+.reset = speex_reset,
+};
 #endif
 
+static int ffmpeg_init(pa_resampler*r);
+static void ffmpeg_resample(pa_resampler *r, const pa_memchunk *input, 
unsigned in_n_frames, pa_memchunk *output, unsigned *out_n_frames);
+static void ffmpeg_free(pa_resampler *r);
+
 struct ffmpeg { /* data specific to ffmpeg */
 struct AVResampleContext *state;
 pa_memchunk buf[PA_CHANNELS_MAX];
 };
 
-static int copy_init(pa_resampler *r);
-static int trivial_init(pa_resampler*r);
-#ifdef HAVE_SPEEX
-static int speex_init(pa_resampler*r);
-#endif
-static int ffmpeg_init(pa_resampler*r);
+static pa_resampler_implementation ffmpeg_impl = {
+.init = ffmpeg_init,
+.free = ffmpeg_free,
+.resample = ffmpeg_resample,
+};
+
 static int peaks_init(pa_resampler*r);
+static void peaks_resample(pa_resampler *r, const pa_memchunk *input, unsigned 
in_n_frames, pa_memchunk *output, unsigned *out_n_frames);
+static void peaks_update_rates_or_reset(pa_resampler *r);
+
+static pa_resampler_implementation peaks_impl = {
+.init = peaks_init,
+.resample = peaks_resample,
+.update_rates = peaks_update_rates_or_reset,
+.reset = peaks_update_rates_or_reset,
+};
+
+struct peaks{ /* data specific to the peak finder pseudo resampler */
+unsigned o_counter;
+unsigned i_counter;
+
+float max_f[PA_CHANNELS_MAX];
+int16_t max_i[PA_CHANNELS_MAX];
+};
+
 #ifdef HAVE_LIBSAMPLERATE
 static int libsamplerate_init(pa_resampler*r);
+static void libsamplerate_resample(pa_resampler *r, const pa_memchunk *input, 
unsigned in_n_frames, pa_memchunk *output, unsigned *out_n_frames);
+static void libsamplerate_update_rates(pa_resampler *r);
+static void libsamplerate_reset(pa_resampler *r);
+static void libsamplerate_free(pa_resampler *r);
+
+struct src{ /* data specific to libsamplerate */
+SRC_STATE *state;
+};
+
+static pa_resampler_implementation libsamplerate_impl = {
+.init = libsamplerate_init,
+.free = libsamplerate_free,
+.resample = libsamplerate_resample,
+.update_rates = libsamplerate_update_rates,
+.reset = libsamplerate_reset,
+};
 #endif
 
 static void calc_map_table(pa_resampler *r);
 
-static int (* const init_table[])(pa_resampler*r) = {
+static pa_resampler_implementation *impl_table[] = {
 #ifdef HAVE_LIBSAMPLERATE
-[PA_RESAMPLER_SRC_SINC_BEST_QUALITY]   = libsamplerate_init,
-[PA_RESAMPLER_SRC_SINC_MEDIUM_QUALITY] = libsamplerate_init,
-[PA_RESAMPLER_SRC_SINC_FASTEST]= libsamplerate_init,
-[PA_RESAMPLER_SRC_ZERO_ORDER_HOLD] = libsamplerate_init,
-[PA_RESAMPLER_SRC_LINEAR]  = libsamplerate_init,
+[PA_RESAMPLER_SRC_LINEAR] = &libsamplerate_impl,
 #else
-[PA_RESAMPLER_SRC_SINC_BEST_QUALITY]   = NULL,
-[PA_RESAMPLER_SRC_SINC_MEDIUM_QUALITY] = NULL,
-[PA_RESAMPLER_SRC_SINC_FASTEST]= NULL,
-[PA_RESAMPLER_SRC_ZERO_ORDER_HOLD] = NULL,
-[PA_RESAMPLER_SRC_LINEAR]  = NULL,
+[PA_RESAMPLER_SRC_LINEAR] = NULL,
 #endif
-[PA_R

[pulseaudio-discuss] [PATCH 11/18] resampler: Refactor the logic for finding the implementation

2013-07-15 Thread Damir Jelić
---
 src/pulsecore/resampler.c | 22 ++
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/src/pulsecore/resampler.c b/src/pulsecore/resampler.c
index c297188..6ecb408 100644
--- a/src/pulsecore/resampler.c
+++ b/src/pulsecore/resampler.c
@@ -344,6 +344,18 @@ static pa_sample_format_t pa_resampler_choose_work_format(
 return work_format;
 }
 
+static pa_resample_method_t find_base_method(pa_resample_method_t method) {
+pa_assert(method >= 0);
+pa_assert(method < PA_RESAMPLER_MAX);
+
+if (method >= PA_RESAMPLER_SPEEX_FLOAT_BASE && method <= 
PA_RESAMPLER_SPEEX_FIXED_MAX) {
+return PA_RESAMPLER_SPEEX_FIXED_BASE;
+} else if (method <= PA_RESAMPLER_SRC_LINEAR)
+return PA_RESAMPLER_SRC_LINEAR;
+else
+return method;
+}
+
 pa_resampler* pa_resampler_new(
 pa_mempool *pool,
 const pa_sample_spec *a,
@@ -368,14 +380,8 @@ pa_resampler* pa_resampler_new(
 r = pa_xnew0(pa_resampler, 1);
 r->mempool = pool;
 r->method = method;
-if (method >= PA_RESAMPLER_SPEEX_FIXED_BASE && method <= 
PA_RESAMPLER_SPEEX_FIXED_MAX)
-r->implementation = *impl_table[PA_RESAMPLER_SPEEX_FIXED_BASE];
-else if (method >= PA_RESAMPLER_SPEEX_FLOAT_BASE && method <= 
PA_RESAMPLER_SPEEX_FLOAT_MAX) {
-r->implementation = *impl_table[PA_RESAMPLER_SPEEX_FIXED_BASE];
-} else if (method <= PA_RESAMPLER_SRC_LINEAR)
-r->implementation = *impl_table[PA_RESAMPLER_SRC_LINEAR];
-else
-r->implementation = *impl_table[method];
+
+r->implementation = *impl_table[find_base_method(method)];
 
 r->flags = flags;
 
-- 
1.8.3.2

___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


[pulseaudio-discuss] [PATCH 12/18] resampler: Simplify the resample_method_supported() function

2013-07-15 Thread Damir Jelić
---
 src/pulsecore/resampler.c | 18 +++---
 1 file changed, 3 insertions(+), 15 deletions(-)

diff --git a/src/pulsecore/resampler.c b/src/pulsecore/resampler.c
index 6ecb408..2d83315 100644
--- a/src/pulsecore/resampler.c
+++ b/src/pulsecore/resampler.c
@@ -640,22 +640,10 @@ const char 
*pa_resample_method_to_string(pa_resample_method_t m) {
 
 int pa_resample_method_supported(pa_resample_method_t m) {
 
-if (m < 0 || m >= PA_RESAMPLER_MAX)
-return 0;
-
-#ifndef HAVE_LIBSAMPLERATE
-if (m <= PA_RESAMPLER_SRC_LINEAR)
-return 0;
-#endif
-
-#ifndef HAVE_SPEEX
-if (m >= PA_RESAMPLER_SPEEX_FLOAT_BASE && m <= 
PA_RESAMPLER_SPEEX_FLOAT_MAX)
-return 0;
-if (m >= PA_RESAMPLER_SPEEX_FIXED_BASE && m <= 
PA_RESAMPLER_SPEEX_FIXED_MAX)
+if(impl_table[find_base_method(m)] == NULL)
 return 0;
-#endif
-
-return 1;
+else
+return 1;
 }
 
 pa_resample_method_t pa_parse_resample_method(const char *string) {
-- 
1.8.3.2

___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


[pulseaudio-discuss] [PATCH 13/18] resampler: Get rid of redundant implementation specific structs

2013-07-15 Thread Damir Jelić
This patch removes implementation specific structs that contain a single
member.
---
 src/pulsecore/resampler.c | 84 +--
 1 file changed, 38 insertions(+), 46 deletions(-)

diff --git a/src/pulsecore/resampler.c b/src/pulsecore/resampler.c
index 2d83315..c4434ff 100644
--- a/src/pulsecore/resampler.c
+++ b/src/pulsecore/resampler.c
@@ -105,10 +105,6 @@ static void speex_free(pa_resampler *r);
 static void speex_update_rates(pa_resampler *r);
 static void speex_reset(pa_resampler *r);
 
-struct speex{ /* data specific to speex */
-SpeexResamplerState* state;
-};
-
 static pa_resampler_implementation speex_impl = {
 .init = speex_init,
 .free = speex_free,
@@ -158,10 +154,6 @@ static void libsamplerate_update_rates(pa_resampler *r);
 static void libsamplerate_reset(pa_resampler *r);
 static void libsamplerate_free(pa_resampler *r);
 
-struct src{ /* data specific to libsamplerate */
-SRC_STATE *state;
-};
-
 static pa_resampler_implementation libsamplerate_impl = {
 .init = libsamplerate_init,
 .free = libsamplerate_free,
@@ -456,6 +448,8 @@ void pa_resampler_free(pa_resampler *r) {
 
 if (r->implementation.free)
 r->implementation.free(r);
+else
+pa_xfree(r->implementation.data);
 
 if (r->to_work_format_buf.memblock)
 pa_memblock_unref(r->to_work_format_buf.memblock);
@@ -466,7 +460,6 @@ void pa_resampler_free(pa_resampler *r) {
 if (r->from_work_format_buf.memblock)
 pa_memblock_unref(r->from_work_format_buf.memblock);
 
-pa_xfree(r->implementation.data);
 pa_xfree(r);
 }
 
@@ -1358,14 +1351,14 @@ static void save_leftover(pa_resampler *r, void *buf, 
size_t len) {
 #ifdef HAVE_LIBSAMPLERATE
 static void libsamplerate_resample(pa_resampler *r, const pa_memchunk *input, 
unsigned in_n_frames, pa_memchunk *output, unsigned *out_n_frames) {
 SRC_DATA data;
-struct src *libsamplerate_data;
+SRC_STATE *state;
 
 pa_assert(r);
 pa_assert(input);
 pa_assert(output);
 pa_assert(out_n_frames);
 
-libsamplerate_data = r->implementation.data;
+state = r->implementation.data;
 memset(&data, 0, sizeof(data));
 
 data.data_in = pa_memblock_acquire_chunk(input);
@@ -1377,7 +1370,7 @@ static void libsamplerate_resample(pa_resampler *r, const 
pa_memchunk *input, un
 data.src_ratio = (double) r->o_ss.rate / r->i_ss.rate;
 data.end_of_input = 0;
 
-pa_assert_se(src_process(libsamplerate_data->state, &data) == 0);
+pa_assert_se(src_process(state, &data) == 0);
 
 if (data.input_frames_used < in_n_frames) {
 void *leftover_data = data.data_in + data.input_frames_used * 
r->o_ss.channels;
@@ -1393,42 +1386,41 @@ static void libsamplerate_resample(pa_resampler *r, 
const pa_memchunk *input, un
 }
 
 static void libsamplerate_update_rates(pa_resampler *r) {
-struct src *libsamplerate_data;
+SRC_STATE *state;
 pa_assert(r);
 
-libsamplerate_data = r->implementation.data;
-pa_assert_se(src_set_ratio(libsamplerate_data->state, (double) 
r->o_ss.rate / r->i_ss.rate) == 0);
+state = r->implementation.data;
+pa_assert_se(src_set_ratio(state, (double) r->o_ss.rate / r->i_ss.rate) == 
0);
 }
 
 static void libsamplerate_reset(pa_resampler *r) {
-struct src *libsamplerate_data;
+SRC_STATE *state;
 pa_assert(r);
 
-libsamplerate_data = r->implementation.data;
-pa_assert_se(src_reset(libsamplerate_data->state) == 0);
+state = r->implementation.data;
+pa_assert_se(src_reset(state) == 0);
 }
 
 static void libsamplerate_free(pa_resampler *r) {
-struct src *libsamplerate_data;
+SRC_STATE *state;
 pa_assert(r);
 
-libsamplerate_data = r->implementation.data;
-if (libsamplerate_data->state)
-src_delete(libsamplerate_data->state);
+state = r->implementation.data;
+if (state)
+src_delete(state);
 }
 
 static int libsamplerate_init(pa_resampler *r) {
 int err;
-struct src *libsamplerate_data;
+SRC_STATE *state = NULL;
 
 pa_assert(r);
 
-libsamplerate_data = pa_xnew(struct src, 1);
-r->implementation.data = libsamplerate_data;
 
-if (!(libsamplerate_data->state = src_new(r->method, r->o_ss.channels, 
&err)))
+if (!(state = src_new(r->method, r->o_ss.channels, &err)))
 return -1;
 
+r->implementation.data = state;
 
 return 0;
 }
@@ -1440,19 +1432,19 @@ static int libsamplerate_init(pa_resampler *r) {
 static void speex_resample_float(pa_resampler *r, const pa_memchunk *input, 
unsigned in_n_frames, pa_memchunk *output, unsigned *out_n_frames) {
 float *in, *out;
 uint32_t inf = in_n_frames, outf = *out_n_frames;
-struct speex *speex_data;
+SpeexResamplerState *state;
 
 pa_assert(r);
 pa_assert(input);
 pa_assert(output);
 pa_assert(out_n_frames);
 
-speex_data = r->implementation.data;
+state = r->implementation.data;
 
 in = pa_memblock_acquire_chunk(input);
 

[pulseaudio-discuss] [PATCH 14/18] resampler: Add a choose_auto_resampler function

2013-07-15 Thread Damir Jelić
This function returns our preferred resampler if the user choose the
auto (or if he has chosen an unsupported) resampler.
---
 src/pulsecore/resampler.c | 25 +++--
 1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/src/pulsecore/resampler.c b/src/pulsecore/resampler.c
index c4434ff..eb1ee6c 100644
--- a/src/pulsecore/resampler.c
+++ b/src/pulsecore/resampler.c
@@ -182,6 +182,19 @@ static pa_resampler_implementation *impl_table[] = {
 [PA_RESAMPLER_PEAKS] = &peaks_impl,
 };
 
+static pa_resample_method_t choose_auto_resampler(pa_resample_flags_t flags) {
+pa_resample_method_t method;
+
+if (pa_resample_method_supported(PA_RESAMPLER_SPEEX_FLOAT_BASE + 1))
+method = PA_RESAMPLER_SPEEX_FLOAT_BASE + 1;
+else if (flags & PA_RESAMPLER_VARIABLE_RATE)
+method = PA_RESAMPLER_TRIVIAL;
+else
+method = PA_RESAMPLER_FFMPEG;
+
+return method;
+}
+
 static pa_resample_method_t pa_resampler_fix_method(
 pa_resample_flags_t flags,
 pa_resample_method_t method,
@@ -225,16 +238,8 @@ static pa_resample_method_t pa_resampler_fix_method(
 break;
 }
 
-if (method == PA_RESAMPLER_AUTO) {
-#ifdef HAVE_SPEEX
-method = PA_RESAMPLER_SPEEX_FLOAT_BASE + 1;
-#else
-if (flags & PA_RESAMPLER_VARIABLE_RATE)
-method = PA_RESAMPLER_TRIVIAL;
-else
-method = PA_RESAMPLER_FFMPEG;
-#endif
-}
+if (method == PA_RESAMPLER_AUTO)
+method = choose_auto_resampler(flags);
 
 return method;
 }
-- 
1.8.3.2

___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


[pulseaudio-discuss] [PATCH 15/18] resampler: Move the method strings into the implementation struct

2013-07-15 Thread Damir Jelić
---
 src/pulsecore/resampler.c | 88 ---
 src/pulsecore/resampler.h |  3 ++
 2 files changed, 48 insertions(+), 43 deletions(-)

diff --git a/src/pulsecore/resampler.c b/src/pulsecore/resampler.c
index eb1ee6c..c29e406 100644
--- a/src/pulsecore/resampler.c
+++ b/src/pulsecore/resampler.c
@@ -81,6 +81,7 @@ static int copy_init(pa_resampler *r);
 
 static pa_resampler_implementation copy_impl = {
 .init = copy_init,
+.names = { "copy" },
 };
 
 static int trivial_init(pa_resampler*r);
@@ -97,6 +98,7 @@ static pa_resampler_implementation trivial_impl = {
 .resample = trivial_resample,
 .update_rates = trivial_update_rates_or_reset,
 .reset = trivial_update_rates_or_reset,
+.names = { "trivial" },
 };
 
 #ifdef HAVE_SPEEX
@@ -110,6 +112,29 @@ static pa_resampler_implementation speex_impl = {
 .free = speex_free,
 .update_rates = speex_update_rates,
 .reset = speex_reset,
+.names = { "speex-float-0",
+   "speex-float-1",
+   "speex-float-2",
+   "speex-float-3",
+   "speex-float-4",
+   "speex-float-5",
+   "speex-float-6",
+   "speex-float-7",
+   "speex-float-8",
+   "speex-float-9",
+   "speex-float-10",
+   "speex-fixed-0",
+   "speex-fixed-1",
+   "speex-fixed-2",
+   "speex-fixed-3",
+   "speex-fixed-4",
+   "speex-fixed-5",
+   "speex-fixed-6",
+   "speex-fixed-7",
+   "speex-fixed-8",
+   "speex-fixed-9",
+   "speex-fixed-10",
+}
 };
 #endif
 
@@ -126,6 +151,7 @@ static pa_resampler_implementation ffmpeg_impl = {
 .init = ffmpeg_init,
 .free = ffmpeg_free,
 .resample = ffmpeg_resample,
+.names = { "ffmpeg" },
 };
 
 static int peaks_init(pa_resampler*r);
@@ -137,6 +163,7 @@ static pa_resampler_implementation peaks_impl = {
 .resample = peaks_resample,
 .update_rates = peaks_update_rates_or_reset,
 .reset = peaks_update_rates_or_reset,
+.names = { "peaks" },
 };
 
 struct peaks{ /* data specific to the peak finder pseudo resampler */
@@ -160,6 +187,12 @@ static pa_resampler_implementation libsamplerate_impl = {
 .resample = libsamplerate_resample,
 .update_rates = libsamplerate_update_rates,
 .reset = libsamplerate_reset,
+.names = { "src-sinc-best-quality",
+   "src-sinc-best-quality",
+   "src-sinc-fastest",
+   "src-zero-order-hold",
+   "src-linear"
+},
 };
 #endif
 
@@ -167,15 +200,15 @@ static void calc_map_table(pa_resampler *r);
 
 static pa_resampler_implementation *impl_table[] = {
 #ifdef HAVE_LIBSAMPLERATE
-[PA_RESAMPLER_SRC_LINEAR] = &libsamplerate_impl,
+[PA_RESAMPLER_SRC_SINC_FASTEST] = &libsamplerate_impl,
 #else
-[PA_RESAMPLER_SRC_LINEAR] = NULL,
+[PA_RESAMPLER_SRC_SINC_FASTEST] = NULL,
 #endif
 [PA_RESAMPLER_TRIVIAL] = &trivial_impl,
 #ifdef HAVE_SPEEX
-[PA_RESAMPLER_SPEEX_FIXED_BASE] = &speex_impl,
+[PA_RESAMPLER_SPEEX_FLOAT_BASE] = &speex_impl,
 #else
-[PA_RESAMPLER_SPEEX_FIXED_BASE] = NULL,
+[PA_RESAMPLER_SPEEX_FLOAT_BASE] = NULL,
 #endif
 [PA_RESAMPLER_FFMPEG] = &ffmpeg_impl,
 [PA_RESAMPLER_COPY] = ©_impl,
@@ -346,9 +379,9 @@ static pa_resample_method_t 
find_base_method(pa_resample_method_t method) {
 pa_assert(method < PA_RESAMPLER_MAX);
 
 if (method >= PA_RESAMPLER_SPEEX_FLOAT_BASE && method <= 
PA_RESAMPLER_SPEEX_FIXED_MAX) {
-return PA_RESAMPLER_SPEEX_FIXED_BASE;
+return PA_RESAMPLER_SPEEX_FLOAT_BASE;
 } else if (method <= PA_RESAMPLER_SRC_LINEAR)
-return PA_RESAMPLER_SRC_LINEAR;
+return PA_RESAMPLER_SRC_SINC_BEST_QUALITY;
 else
 return method;
 }
@@ -593,47 +626,16 @@ const pa_sample_spec* 
pa_resampler_output_sample_spec(pa_resampler *r) {
 return &r->o_ss;
 }
 
-static const char * const resample_methods[] = {
-"src-sinc-best-quality",
-"src-sinc-medium-quality",
-"src-sinc-fastest",
-"src-zero-order-hold",
-"src-linear",
-"trivial",
-"speex-float-0",
-"speex-float-1",
-"speex-float-2",
-"speex-float-3",
-"speex-float-4",
-"speex-float-5",
-"speex-float-6",
-"speex-float-7",
-"speex-float-8",
-"speex-float-9",
-"speex-float-10",
-"speex-fixed-0",
-"speex-fixed-1",
-"speex-fixed-2",
-"speex-fixed-3",
-"speex-fixed-4",
-"speex-fixed-5",
-"speex-fixed-6",
-"speex-fixed-7",
-"speex-fixed-8",
-"speex-fixed-9",
-"speex-fixed-10",
-"ffmpeg",
-"auto",
-"copy",
-"peaks"
-};
-
 const char *pa_resample_method_to_string(pa_resample_method_t m) {
+struct pa_resampler_implementation *impl;
 
 if (m < 0 || m >= PA_RESAMPLER_MAX)
 return NULL;
 
-return resample_methods[m];
+if ((impl = impl_table[find_base

[pulseaudio-discuss] [PATCH 17/18] resampler: Add the auto resampling implementation

2013-07-15 Thread Damir Jelić
This adds back the 'auto' resampling method to the supported resampler
methods.
---
 src/pulsecore/resampler.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/src/pulsecore/resampler.c b/src/pulsecore/resampler.c
index 673d43b..2ed757f 100644
--- a/src/pulsecore/resampler.c
+++ b/src/pulsecore/resampler.c
@@ -77,6 +77,10 @@ struct pa_resampler {
 pa_resampler_implementation implementation;
 };
 
+static pa_resampler_implementation auto_impl = {
+.names = { "auto" },
+};
+
 static int copy_init(pa_resampler *r);
 
 static pa_resampler_implementation copy_impl = {
@@ -211,6 +215,7 @@ static pa_resampler_implementation *impl_table[] = {
 [PA_RESAMPLER_SPEEX_FLOAT_BASE] = NULL,
 #endif
 [PA_RESAMPLER_FFMPEG] = &ffmpeg_impl,
+[PA_RESAMPLER_AUTO] = &auto_impl,
 [PA_RESAMPLER_COPY] = ©_impl,
 [PA_RESAMPLER_PEAKS] = &peaks_impl,
 };
-- 
1.8.3.2

___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


[pulseaudio-discuss] [PATCH 16/18] resampler: Don't check for unsupported methods in fix_method

2013-07-15 Thread Damir Jelić
With split of the resample_methods table the parse_method function
doesn't allow choosing an unsupported resampling method.

This check is now dead code and is therefore removed.
---
 src/pulsecore/resampler.c | 5 -
 1 file changed, 5 deletions(-)

diff --git a/src/pulsecore/resampler.c b/src/pulsecore/resampler.c
index c29e406..673d43b 100644
--- a/src/pulsecore/resampler.c
+++ b/src/pulsecore/resampler.c
@@ -244,11 +244,6 @@ static pa_resample_method_t pa_resampler_fix_method(
 method = PA_RESAMPLER_COPY;
 }
 
-if (!pa_resample_method_supported(method)) {
-pa_log_warn("Support for resampler '%s' not compiled in, reverting to 
'auto'.", pa_resample_method_to_string(method));
-method = PA_RESAMPLER_AUTO;
-}
-
 switch (method) {
 case PA_RESAMPLER_COPY: /* fall through */
 case PA_RESAMPLER_FFMPEG:
-- 
1.8.3.2

___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


[pulseaudio-discuss] [PATCH 18/18] resampler: Remove double newlines

2013-07-15 Thread Damir Jelić
---
 src/pulsecore/resampler.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/src/pulsecore/resampler.c b/src/pulsecore/resampler.c
index 2ed757f..d34de37 100644
--- a/src/pulsecore/resampler.c
+++ b/src/pulsecore/resampler.c
@@ -1423,7 +1423,6 @@ static int libsamplerate_init(pa_resampler *r) {
 
 pa_assert(r);
 
-
 if (!(state = src_new(r->method, r->o_ss.channels, &err)))
 return -1;
 
@@ -1519,7 +1518,6 @@ static int speex_init(pa_resampler *r) {
 
 pa_assert(r);
 
-
 if (r->method >= PA_RESAMPLER_SPEEX_FIXED_BASE && r->method <= 
PA_RESAMPLER_SPEEX_FIXED_MAX) {
 
 q = r->method - PA_RESAMPLER_SPEEX_FIXED_BASE;
-- 
1.8.3.2

___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


[pulseaudio-discuss] [PATCH] card-restore: Watch for profiles added after card creation.

2013-07-25 Thread Damir Jelić
This patch adds the ability to restore profiles if they are added after
card creation.

Adding profiles after card creation mainly happens for bluetooth cards.

Buglink: https://bugs.freedesktop.org/show_bug.cgi?id=65349
---
 src/modules/module-card-restore.c | 29 +
 1 file changed, 25 insertions(+), 4 deletions(-)

diff --git a/src/modules/module-card-restore.c 
b/src/modules/module-card-restore.c
index 928f153..4feb68b 100644
--- a/src/modules/module-card-restore.c
+++ b/src/modules/module-card-restore.c
@@ -64,7 +64,8 @@ struct userdata {
 pa_module *module;
 pa_hook_slot *card_new_hook_slot;
 pa_hook_slot *card_put_hook_slot;
-pa_hook_slot *card_profile_hook_slot;
+pa_hook_slot *card_profile_changed_hook_slot;
+pa_hook_slot *card_profile_added_hook_slot;
 pa_hook_slot *port_offset_hook_slot;
 pa_time_event *save_time_event;
 pa_database *database;
@@ -380,7 +381,7 @@ finish:
 return PA_HOOK_OK;
 }
 
-static pa_hook_result_t card_profile_change_callback(pa_core *c, pa_card 
*card, struct userdata *u) {
+static pa_hook_result_t card_profile_changed_callback(pa_core *c, pa_card 
*card, struct userdata *u) {
 struct entry *entry;
 
 pa_assert(card);
@@ -403,6 +404,24 @@ static pa_hook_result_t 
card_profile_change_callback(pa_core *c, pa_card *card,
 return PA_HOOK_OK;
 }
 
+static pa_hook_result_t card_profile_added_callback(pa_core *c, 
pa_card_profile *profile, struct userdata *u) {
+struct entry *entry;
+
+pa_assert(profile);
+
+if (!(entry = entry_read(u, profile->card->name)))
+return PA_HOOK_OK;
+
+if (pa_safe_streq(entry->profile, profile->name)) {
+pa_card_set_profile(profile->card, profile->name, true);
+pa_log_info("Restored profile '%s' for card %s.", profile->name, 
profile->card->name);
+}
+
+entry_free(entry);
+
+return PA_HOOK_OK;
+}
+
 static pa_hook_result_t port_offset_change_callback(pa_core *c, pa_device_port 
*port, struct userdata *u) {
 struct entry *entry;
 pa_card *card;
@@ -487,7 +506,8 @@ int pa__init(pa_module*m) {
 
 u->card_new_hook_slot = 
pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_CARD_NEW], PA_HOOK_EARLY, 
(pa_hook_cb_t) card_new_hook_callback, u);
 u->card_put_hook_slot = 
pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_CARD_PUT], PA_HOOK_NORMAL, 
(pa_hook_cb_t) card_put_hook_callback, u);
-u->card_profile_hook_slot = 
pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_CARD_PROFILE_CHANGED], 
PA_HOOK_NORMAL, (pa_hook_cb_t) card_profile_change_callback, u);
+u->card_profile_changed_hook_slot = 
pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_CARD_PROFILE_CHANGED], 
PA_HOOK_NORMAL, (pa_hook_cb_t) card_profile_changed_callback, u);
+u->card_profile_added_hook_slot = 
pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_CARD_PROFILE_ADDED], 
PA_HOOK_NORMAL, (pa_hook_cb_t) card_profile_added_callback, u);
 u->port_offset_hook_slot = 
pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_PORT_LATENCY_OFFSET_CHANGED], 
PA_HOOK_NORMAL, (pa_hook_cb_t) port_offset_change_callback, u);
 u->hooks_connected = true;
 
@@ -526,7 +546,8 @@ void pa__done(pa_module*m) {
 if (u->hooks_connected) {
 pa_hook_slot_free(u->card_new_hook_slot);
 pa_hook_slot_free(u->card_put_hook_slot);
-pa_hook_slot_free(u->card_profile_hook_slot);
+pa_hook_slot_free(u->card_profile_changed_hook_slot);
+pa_hook_slot_free(u->card_profile_added_hook_slot);
 pa_hook_slot_free(u->port_offset_hook_slot);
 }
 
-- 
1.8.3.3

___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


Re: [pulseaudio-discuss] Is there a mail list archive

2013-07-27 Thread Damir Jelić
On Sat, Jul 27, 2013 at 01:59:03PM +0200, Alex Schenkman wrote:
>Hi list,
>Is there a mail list archive?
>I'd like to search the mail list before I ask questions to the list.
>Thanks in advance!

General info:
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss

Archive:
http://lists.freedesktop.org/archives/pulseaudio-discuss/
___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


[pulseaudio-discuss] [PATCH] bash-completion: Fix device completion for pacat

2013-08-14 Thread Damir Jelić
The Bash shell completion for pacat --device combines the names
of sinks and their monitor sources.

This patch fixes that by adding a whitespace separator in the list of
devices.

Buglink: https://bugs.freedesktop.org/show_bug.cgi?id=68106
---
 shell-completion/pulseaudio-bash-completion.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/shell-completion/pulseaudio-bash-completion.sh 
b/shell-completion/pulseaudio-bash-completion.sh
index 5f60092..d5b99db 100644
--- a/shell-completion/pulseaudio-bash-completion.sh
+++ b/shell-completion/pulseaudio-bash-completion.sh
@@ -452,7 +452,7 @@ _pacat () {
 --device=*)
 cur=${cur#*=}
 comps=$(__sinks)
-comps+=$(__sources)
+comps+=" "$(__sources)
 COMPREPLY=($(compgen -W '${comps[*]}' -- "$cur"))
 ;;
 
@@ -481,7 +481,7 @@ _pacat () {
 -s) _known_hosts_real "$cur" ;;
 -d)
 comps=$(__sinks)
-comps+=$(__sources)
+comps+=" "$(__sources)
 COMPREPLY=($(compgen -W '${comps[*]}' -- "$cur"))
 ;;
 esac
-- 
1.8.3.4

___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


[pulseaudio-discuss] [PATCH 1/3] bash-completion: Add --monitor-stream completion to pacat

2013-08-15 Thread Damir Jelić
---
 shell-completion/pulseaudio-bash-completion.sh | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/shell-completion/pulseaudio-bash-completion.sh 
b/shell-completion/pulseaudio-bash-completion.sh
index d5b99db..43f4a2c 100644
--- a/shell-completion/pulseaudio-bash-completion.sh
+++ b/shell-completion/pulseaudio-bash-completion.sh
@@ -439,7 +439,7 @@ _pacat () {
 --rate= --format= --channels= --channel-map= --fix-format 
--fix-rate
 --fix-channels --no-remix --no-remap --latency= --process-time=
 --latency-msec= --process-time-msec= --property= --raw 
--passthrough
---file-format= --list-file-formats'
+--file-format= --list-file-formats --monitor-stream='
 
 _init_completion -n = || return
 
@@ -456,6 +456,12 @@ _pacat () {
 COMPREPLY=($(compgen -W '${comps[*]}' -- "$cur"))
 ;;
 
+--monitor-stream=*)
+cur=${cur#*=}
+comps=$(__sink_inputs)
+COMPREPLY=($(compgen -W '${comps[*]}' -- "$cur"))
+;;
+
 --rate=*)
 cur=${cur#*=}
 COMPREPLY=($(compgen -W '32000 44100 48000 9600 192000' -- "$cur"))
-- 
1.8.3.4

___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


[pulseaudio-discuss] [PATCH 2/3] zsh-completion: Fix pacat device completion

2013-08-15 Thread Damir Jelić
The pacat completion didn't complete the right devices for the --record
and --playback flags.

This patch fixes this and makes the device completion for pacat easily
expandable.
---
 shell-completion/pulseaudio-zsh-completion.zsh | 38 ++
 1 file changed, 27 insertions(+), 11 deletions(-)

diff --git a/shell-completion/pulseaudio-zsh-completion.zsh 
b/shell-completion/pulseaudio-zsh-completion.zsh
index 142d031..e872736 100644
--- a/shell-completion/pulseaudio-zsh-completion.zsh
+++ b/shell-completion/pulseaudio-zsh-completion.zsh
@@ -24,18 +24,34 @@ _devices() {
 esac
 
 elif [[ $service == (pacat|paplay|parecord) ]]; then
-if [[ $words == *-r[[:space:]]* ]]; then
-cmd=('sources')
-elif [[ $words == *-p[[:space:]]* ]]; then
-cmd=('sinks')
-else
-cmd=('sinks' 'sources')
-fi
+case $words[$((CURRENT))] in
+--device=*)
+if [[ $words == *(--playback|-p)[[:space:]]* ||
+$service == paplay ]]; then
+cmd=('sinks')
+elif [[ $words == *(--record|-r)[[:space:]]* ||
+$service == parecord ]]; then
+cmd=('sources')
+else
+cmd=('sinks' 'sources')
+fi
+;;
+esac
+
+case $words[$((CURRENT - 1))] in
+-d)
+if [[ $words == *(--playback|-p)[[:space:]]* ||
+$service == paplay ]]; then
+cmd=('sinks')
+elif [[ $words == *(--record|-r)[[:space:]]* ||
+$service == parecord ]]; then
+cmd=('sources')
+else
+cmd=('sinks' 'sources')
+fi
+;;
+esac
 
-elif [[ $service == paplay ]]; then
-cmd=('sinks')
-elif [[ $service == parecord ]]; then
-cmd=('sources')
 fi
 
 for (( i = 0; i < ${#words[@]}; i++ )) do
-- 
1.8.3.4

___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


[pulseaudio-discuss] [PATCH 3/3] zsh-completion: Add --monitor-stream completion to pacat

2013-08-15 Thread Damir Jelić
---
 shell-completion/pulseaudio-zsh-completion.zsh | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/shell-completion/pulseaudio-zsh-completion.zsh 
b/shell-completion/pulseaudio-zsh-completion.zsh
index e872736..abc443a 100644
--- a/shell-completion/pulseaudio-zsh-completion.zsh
+++ b/shell-completion/pulseaudio-zsh-completion.zsh
@@ -36,6 +36,7 @@ _devices() {
 cmd=('sinks' 'sources')
 fi
 ;;
+--monitor-stream=*) cmd=('sink-inputs');;
 esac
 
 case $words[$((CURRENT - 1))] in
@@ -468,6 +469,7 @@ _pacat_completion() {
 {-p,--playback}'[create a connection for playback]' \
 {-s,--server=}'[name of server to connect to]:host:_hosts' \
 {-d,--device=}'[name of sink/source to connect to]:device:_devices' \
+'--monitor-stream=[index of the sink input to record 
from]:device:_devices' \
 {-n,--client-name=}'[client name to use]:name' \
 '--stream-name=[how to call this stream]:name' \
 '--volume=[initial volume to use]:volume' \
-- 
1.8.3.4

___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


Re: [pulseaudio-discuss] [PATCH] alsa-ucm: Make combination port names deterministic

2013-08-21 Thread Damir Jelić
On Wed, Aug 21, 2013 at 03:00:29PM +0530, Arun Raghavan wrote:
> At the moment, port names combined from multiple devices are generated
> based on the order that the devices are specified in config. This makes
> programmatic use of thsee ports a bit painful, so let's make them be
> combined in alphabetical order.
> ---
>  src/modules/alsa/alsa-ucm.c | 21 ++---
>  1 file changed, 18 insertions(+), 3 deletions(-)
> 
> diff --git a/src/modules/alsa/alsa-ucm.c b/src/modules/alsa/alsa-ucm.c
> index a6ee9a8..d88c80b 100644
> --- a/src/modules/alsa/alsa-ucm.c
> +++ b/src/modules/alsa/alsa-ucm.c
> @@ -671,6 +671,14 @@ int pa_alsa_ucm_get_verb(snd_use_case_mgr_t *uc_mgr, 
> const char *verb_name, cons
>  return 0;
>  }
>  
> +static int pa_alsa_ucm_device_cmp(const void *a, const void *b)
> +{

Opening bracket not on the same line as the expression.

> +const pa_alsa_ucm_device *d1 = *(pa_alsa_ucm_device **)a;
> +const pa_alsa_ucm_device *d2 = *(pa_alsa_ucm_device **)b;
> +
> +return strcmp(pa_proplist_gets(d1->proplist, PA_ALSA_PROP_UCM_NAME), 
> pa_proplist_gets(d2->proplist, PA_ALSA_PROP_UCM_NAME));
> +}
> +
>  static void ucm_add_port_combination(
>  pa_hashmap *hash,
>  pa_alsa_ucm_mapping_context *context,
> @@ -687,9 +695,16 @@ static void ucm_add_port_combination(
>  char *name, *desc;
>  const char *dev_name;
>  const char *direction;
> -pa_alsa_ucm_device *dev;
> +pa_alsa_ucm_device *sorted[num], *dev;
> +
> +for (i = 0; i < num; i++)
> +sorted[i] = pdevices[i];

Couldn't we use memcpy() here which would possibly be faster?

> +
> +/* Sort by alphabetical order so as to have a deterministic naming scheme
> + * for combination ports */
> +qsort(&sorted[0], num, sizeof(pa_alsa_ucm_device *), 
> pa_alsa_ucm_device_cmp);
>  
> -dev = pdevices[0];
> +dev = sorted[0];
>  dev_name = pa_proplist_gets(dev->proplist, PA_ALSA_PROP_UCM_NAME);
>  
>  name = pa_sprintf_malloc("%s%s", is_sink ? PA_UCM_PRE_TAG_OUTPUT : 
> PA_UCM_PRE_TAG_INPUT, dev_name);
> @@ -701,7 +716,7 @@ static void ucm_add_port_combination(
>  for (i = 1; i < num; i++) {
>  char *tmp;
>  
> -dev = pdevices[i];
> +dev = sorted[i];
>  dev_name = pa_proplist_gets(dev->proplist, PA_ALSA_PROP_UCM_NAME);
>  
>  tmp = pa_sprintf_malloc("%s+%s", name, dev_name);

Rest looks sensible. I haven't compile or run tested this, just wanted to 
make sure that the coding style error doesn't get in since I posted patches 
that should fix all of these "bracket style" issues.
___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


[pulseaudio-discuss] [PATCH] log: Add support for the systemd journal

2013-09-11 Thread Damir Jelić
The journal is a component of systemd, that captures Syslog messages,
Kernel log messages, initial RAM disk and early boot messages as well
as messages written to STDOUT/STDERR of all services, indexes them and
makes this available to the user.

It can be used in parallel, or in place of a traditional syslog daemon,
such as rsyslog or syslog-ng.

The journal offers a couple of improvements over traditional logging
facilities (e.g. advanced filtering capabilities).

This patch adds support for logging directly to the journal using its
native API.
---
 configure.ac   | 18 ++
 man/pulse-daemon.conf.5.xml.in | 10 +-
 man/pulseaudio.1.xml.in|  5 +++--
 src/Makefile.am|  5 +
 src/daemon/cmdline.c   |  4 
 src/pulsecore/log.c| 39 +++
 src/pulsecore/log.h|  3 +++
 7 files changed, 77 insertions(+), 7 deletions(-)

diff --git a/configure.ac b/configure.ac
index 616a990..f5456f6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1145,6 +1145,22 @@ AC_SUBST(HAVE_SYSTEMD)
 AM_CONDITIONAL([HAVE_SYSTEMD], [test "x$HAVE_SYSTEMD" = x1])
 AS_IF([test "x$HAVE_SYSTEMD" = "x1"], AC_DEFINE([HAVE_SYSTEMD], 1, [Have 
SYSTEMD?]))
 
+ journal support (optional) 
+
+AC_ARG_ENABLE([journal],
+AS_HELP_STRING([--disable-journal],[Disable optional journal support]))
+
+AS_IF([test "x$enable_journal" != "xno"],
+[PKG_CHECK_MODULES(JOURNAL, [ libsystemd-journal ], HAVE_JOURNAL=1, 
HAVE_JOURNAL=0)],
+HAVE_JOURNAL=0)
+
+AS_IF([test "x$enable_journal" = "xyes" && test "x$HAVE_JOURNAL" = "x0"],
+[AC_MSG_ERROR([*** Needed journal support not found])])
+
+AC_SUBST(HAVE_JOURNAL)
+AM_CONDITIONAL([HAVE_JOURNAL], [test "x$HAVE_JOURNAL" = x1])
+AS_IF([test "x$HAVE_JOURNAL" = "x1"], AC_DEFINE([HAVE_JOURNAL], 1, [Have 
JOURNAL?]))
+
  Build and Install man pages 
 
 AC_ARG_ENABLE([manpages],
@@ -1389,6 +1405,7 @@ AS_IF([test "x$HAVE_XEN" = "x1"], ENABLE_XEN=yes, 
ENABLE_XEN=no)
 AS_IF([test "x$HAVE_DBUS" = "x1"], ENABLE_DBUS=yes, ENABLE_DBUS=no)
 AS_IF([test "x$HAVE_UDEV" = "x1"], ENABLE_UDEV=yes, ENABLE_UDEV=no)
 AS_IF([test "x$HAVE_SYSTEMD" = "x1"], ENABLE_SYSTEMD=yes, ENABLE_SYSTEMD=no)
+AS_IF([test "x$HAVE_JOURNAL" = "x1"], ENABLE_JOURNAL=yes, ENABLE_JOURNAL=no)
 AS_IF([test "x$HAVE_BLUEZ" = "x1"], ENABLE_BLUEZ=yes, ENABLE_BLUEZ=no)
 AS_IF([test "x$HAVE_HAL_COMPAT" = "x1"], ENABLE_HAL_COMPAT=yes, 
ENABLE_HAL_COMPAT=no)
 AS_IF([test "x$HAVE_TCPWRAP" = "x1"], ENABLE_TCPWRAP=yes, ENABLE_TCPWRAP=no)
@@ -1444,6 +1461,7 @@ echo "
 Enable udev:   ${ENABLE_UDEV}
   Enable HAL->udev compat: ${ENABLE_HAL_COMPAT}
 Enable systemd login:  ${ENABLE_SYSTEMD}
+Enable systemd journal:${ENABLE_JOURNAL}
 Enable TCP Wrappers:   ${ENABLE_TCPWRAP}
 Enable libsamplerate:  ${ENABLE_LIBSAMPLERATE}
 Enable IPv6:   ${ENABLE_IPV6}
diff --git a/man/pulse-daemon.conf.5.xml.in b/man/pulse-daemon.conf.5.xml.in
index c40d570..bab2873 100644
--- a/man/pulse-daemon.conf.5.xml.in
+++ b/man/pulse-daemon.conf.5.xml.in
@@ -297,11 +297,11 @@ USA.
 
 
   log-target= The default log target. Use either
-  stderr, syslog, auto,
-  file:PATH or newfile:PATH. auto is
-  equivalent to sylog in case daemonize is enabled,
-  otherwise to stderr. If set to file:PATH, logging
-  is directed to the file indicated by PATH. newfile:PATH is
+  stderr, syslog, journal (optional),
+  auto, file:PATH or newfile:PATH.
+  auto is equivalent to sylog in case 
daemonize
+  is enabled, otherwise to stderr. If set to 
file:PATH,
+  logging is directed to the file indicated by PATH. 
newfile:PATH is
   otherwise the same as file:PATH, but existing files are never
   overwritten. If the specified file already exists, a suffix is added to
   the file name to avoid overwriting. Defaults to auto. The
diff --git a/man/pulseaudio.1.xml.in b/man/pulseaudio.1.xml.in
index d7d7458..114cd96 100644
--- a/man/pulseaudio.1.xml.in
+++ b/man/pulseaudio.1.xml.in
@@ -217,12 +217,13 @@ USA.
 
 
 
-  
--log-target={auto,syslog,stderr,file:PATH,newfile:PATH}
+  
--log-target={auto,syslog,journal,stderr,file:PATH,newfile:PATH}
 
   Specify the log target. If set to auto
   (which is the default), then logging is directed to syslog when
   --daemonize is passed, otherwise to
-  STDERR. If set to file:PATH, logging is directed to
+  STDERR. If set to journal logging is directed to the systemd
+  journal. If set to file:PATH, logging is directed to
   the file indicated by PATH. newfile:PATH is otherwise
   the same as file:PATH, but existing files are never overwritten.
   If the specified file already exists, a suffix is added to the
diff --git a/src/Makefile.am b/src/Makefile.am
index 27477e9..e596235 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -687,

Re: [pulseaudio-discuss] [PATCH] log: Add support for the systemd journal

2013-09-11 Thread Damir Jelić
On Wed, Sep 11, 2013 at 01:49:36PM +0200, Peter Meerwald wrote:
> Hi,
> 
> > This patch adds support for logging directly to the journal using its
> > native API.
> 
> does this have any advantages over using syslog?

Yes. As already mentioned in the commit message, one of the biggest
advantages over syslog is the advanced filtering ability of log messages.

The only downside in comparison to syslog is that the logs are not stored 
as plain text and you need to use a tool like journalctl to view the log 
messages.

Some more advantages:
* Lines of error priority (and higher) will be highlighted red.
* Lines of notice/warning priority will be highlighted bold.
* The timestamps are converted into your local time-zone.
* The output is auto-paged with your pager of choice (defaults to less).

More info on this:
http://0pointer.de/blog/projects/journalctl.html

> I suggest to make the relation between 'journal' and systemd more clear in 
> configure (so one knows what to install)

In what way? "--disable-systemd-journal"? I thought that this would be
to long and figured that if someone knows what the journal is he/she
knows that it's related to systemd or if someone knows about systemd
he/she knows that the journal is responsible for most (or all) of the 
logging on the system.

> the default log target (if deamonized) could be changed from syslog to 
> journal if available
> 

This is true. But I thought that it would annoy to many people that way.
Distributions can change the default log target anyways. But if everyone
else seems to be fine with this I'll add it.

> what version of systemd is required?

As of v38+ (released 25.08.2011) systemd ships with the journal. (The current 
stable version
of systemd is 206).

> one nitpick inline
> 
> regards, p.
> 
> > ---
> >  configure.ac   | 18 ++
> >  man/pulse-daemon.conf.5.xml.in | 10 +-
> >  man/pulseaudio.1.xml.in|  5 +++--
> >  src/Makefile.am|  5 +
> >  src/daemon/cmdline.c   |  4 
> >  src/pulsecore/log.c| 39 +++
> >  src/pulsecore/log.h|  3 +++
> >  7 files changed, 77 insertions(+), 7 deletions(-)
> > 
> > diff --git a/configure.ac b/configure.ac
> > index 616a990..f5456f6 100644
> > --- a/configure.ac
> > +++ b/configure.ac
> > @@ -1145,6 +1145,22 @@ AC_SUBST(HAVE_SYSTEMD)
> >  AM_CONDITIONAL([HAVE_SYSTEMD], [test "x$HAVE_SYSTEMD" = x1])
> >  AS_IF([test "x$HAVE_SYSTEMD" = "x1"], AC_DEFINE([HAVE_SYSTEMD], 1, [Have 
> > SYSTEMD?]))
> >  
> > + journal support (optional) 
> > +
> > +AC_ARG_ENABLE([journal],
> > +AS_HELP_STRING([--disable-journal],[Disable optional journal support]))
> > +
> > +AS_IF([test "x$enable_journal" != "xno"],
> > +[PKG_CHECK_MODULES(JOURNAL, [ libsystemd-journal ], HAVE_JOURNAL=1, 
> > HAVE_JOURNAL=0)],
> > +HAVE_JOURNAL=0)
> > +
> > +AS_IF([test "x$enable_journal" = "xyes" && test "x$HAVE_JOURNAL" = "x0"],
> > +[AC_MSG_ERROR([*** Needed journal support not found])])
> > +
> > +AC_SUBST(HAVE_JOURNAL)
> > +AM_CONDITIONAL([HAVE_JOURNAL], [test "x$HAVE_JOURNAL" = x1])
> > +AS_IF([test "x$HAVE_JOURNAL" = "x1"], AC_DEFINE([HAVE_JOURNAL], 1, [Have 
> > JOURNAL?]))
> > +
> >   Build and Install man pages 
> >  
> >  AC_ARG_ENABLE([manpages],
> > @@ -1389,6 +1405,7 @@ AS_IF([test "x$HAVE_XEN" = "x1"], ENABLE_XEN=yes, 
> > ENABLE_XEN=no)
> >  AS_IF([test "x$HAVE_DBUS" = "x1"], ENABLE_DBUS=yes, ENABLE_DBUS=no)
> >  AS_IF([test "x$HAVE_UDEV" = "x1"], ENABLE_UDEV=yes, ENABLE_UDEV=no)
> >  AS_IF([test "x$HAVE_SYSTEMD" = "x1"], ENABLE_SYSTEMD=yes, 
> > ENABLE_SYSTEMD=no)
> > +AS_IF([test "x$HAVE_JOURNAL" = "x1"], ENABLE_JOURNAL=yes, 
> > ENABLE_JOURNAL=no)
> >  AS_IF([test "x$HAVE_BLUEZ" = "x1"], ENABLE_BLUEZ=yes, ENABLE_BLUEZ=no)
> >  AS_IF([test "x$HAVE_HAL_COMPAT" = "x1"], ENABLE_HAL_COMPAT=yes, 
> > ENABLE_HAL_COMPAT=no)
> >  AS_IF([test "x$HAVE_TCPWRAP" = "x1"], ENABLE_TCPWRAP=yes, 
> > ENABLE_TCPWRAP=no)
> > @@ -1444,6 +1461,7 @@ echo "
> >  Enable udev:   ${ENABLE_UDEV}
> >Enable HAL->udev compat: ${ENABLE_HAL_COMPAT}
> >  Enable systemd login:  ${ENABLE_SYSTEMD}
> > +Enable systemd journal:${ENABLE_JOURNAL}
> >  Enable TCP Wrappers:   ${ENABLE_TCPWRAP}
> >  Enable libsamplerate:  ${ENABLE_LIBSAMPLERATE}
> >  Enable IPv6:   ${ENABLE_IPV6}
> > diff --git a/man/pulse-daemon.conf.5.xml.in b/man/pulse-daemon.conf.5.xml.in
> > index c40d570..bab2873 100644
> > --- a/man/pulse-daemon.conf.5.xml.in
> > +++ b/man/pulse-daemon.conf.5.xml.in
> > @@ -297,11 +297,11 @@ USA.
> >  
> >  
> >log-target= The default log target. Use either
> > -  stderr, syslog, auto,
> > -  file:PATH or newfile:PATH. auto is
> > -  equivalent to sylog in case daemonize is 
> > enabled,
> > -  otherwise to stderr. If set to file:PATH, 
> > logging
> > -

[pulseaudio-discuss] [PATCH] resampler: Revert to auto if the rates are equal and copy is chosen

2013-09-11 Thread Damir Jelić
This patch fixes a small mistake where we actually log that we are
reverting to the auto resampler if we can't use the 'copy' resampler but
never do the revert.

This would lead to a crash if the user chooses the 'copy' resampler and
then tries to play something that needs to be resampled.
---
 src/pulsecore/resampler.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/pulsecore/resampler.c b/src/pulsecore/resampler.c
index 4480823..46cf2ab 100644
--- a/src/pulsecore/resampler.c
+++ b/src/pulsecore/resampler.c
@@ -214,6 +214,7 @@ static pa_resample_method_t pa_resampler_fix_method(
 case PA_RESAMPLER_COPY:
 if (rate_a != rate_b) {
 pa_log_info("Resampler 'copy' cannot change sampling rate, 
reverting to resampler 'auto'.");
+method = PA_RESAMPLER_AUTO;
 break;
 }
  /* Else fall through */
-- 
1.8.4

___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


[pulseaudio-discuss] [PATCH 0/4] Build fixes

2013-09-15 Thread Damir Jelić
I finally got annoyed enough by multiple warnings from Autoconf and 
Automake to fix them.

The first patch explicitly enables the subdir-objects option. This option
has been supported by automake for over a decade:

http://git.savannah.gnu.org/cgit/automake.git/commit/?id=88b595974744cad79fa4bc2492a796c6037eea49

The next 2 patches add brackets around AC_LANG_PROGRAM and avoid the same
warning. This is kept in separate commits because one of the files is from
an external source but I couldn't find an updated version of it. Squash
them if needed.

This warning is the result of an change in autoconf 2.68:
The macros AC_PREPROC_IFELSE, AC_COMPILE_IFELSE, AC_LINK_IFELSE, and
AC_RUN_IFELSE now warn if the first argument failed to use
AC_LANG_SOURCE or AC_LANG_PROGRAM to generate the conftest file
contents.

Source: https://lists.gnu.org/archive/html/autoconf/2010-09/msg00069.html

The last patch updates the ax_pthread.m4 file from the GNU Autoconf Archive
tarball and avoids the same warning as the last two patches.

poljar (Damir Jelić) (4):
  build: Enable subdir-objects option
  build: Silence warning about missing AC_LANG_SOURCE call in
configure.ac
  build: Silence warning about missing AC_LANG_SOURCE call in
acx_libwrap.m4
  build: Update ax_pthread macro

 configure.ac  | 16 
 m4/acx_libwrap.m4 |  4 ++--
 m4/ax_pthread.m4  | 47 +++
 3 files changed, 41 insertions(+), 26 deletions(-)

-- 
1.8.4

___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


[pulseaudio-discuss] [PATCH 1/4] build: Enable subdir-objects option

2013-09-15 Thread Damir Jelić
Automake 1.14 throws a warning when source files are in a sub directory
and the 'subdir-objecs' option is not enabled.

News: https://lists.gnu.org/archive/html/automake/2013-06/msg00040.html
---
 configure.ac | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/configure.ac b/configure.ac
index 616a990..5b052e2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -27,7 +27,7 @@ AC_CONFIG_SRCDIR([src/daemon/main.c])
 AC_CONFIG_MACRO_DIR([m4])
 AC_CONFIG_HEADERS([config.h])
 AC_CONFIG_AUX_DIR([build-aux])
-AM_INIT_AUTOMAKE([foreign 1.11 -Wall -Wno-portability silent-rules color-tests 
dist-xz tar-ustar])
+AM_INIT_AUTOMAKE([foreign 1.11 -Wall -Wno-portability subdir-objects 
silent-rules color-tests dist-xz tar-ustar])
 
 AS_IF([! test -n "$VERSION"], [
AC_MSG_ERROR([git-version-gen failed])
-- 
1.8.4

___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


[pulseaudio-discuss] [PATCH 2/4] build: Silence warning about missing AC_LANG_SOURCE call in configure.ac

2013-09-15 Thread Damir Jelić
This silences multiple warnings like this on autoconf 2.68+:
configure.ac:471: warning: AC_LANG_CONFTEST: no AC_LANG_SOURCE call 
detected in body
---
 configure.ac | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/configure.ac b/configure.ac
index 5b052e2..438fd06 100644
--- a/configure.ac
+++ b/configure.ac
@@ -225,7 +225,7 @@ need_libatomic_ops=yes
 AC_CACHE_CHECK([whether $CC knows __sync_bool_compare_and_swap()],
 pulseaudio_cv_sync_bool_compare_and_swap, [
 AC_LINK_IFELSE(
-AC_LANG_PROGRAM([], [[int a = 4; __sync_bool_compare_and_swap(&a, 4, 
5);]]),
+[AC_LANG_PROGRAM([], [[int a = 4; __sync_bool_compare_and_swap(&a, 4, 
5);]])],
 [pulseaudio_cv_sync_bool_compare_and_swap=yes],
 [pulseaudio_cv_sync_bool_compare_and_swap=no])
 ])
@@ -252,7 +252,7 @@ else
 AC_CACHE_CHECK([compiler support for arm inline asm atomic 
operations],
 pulseaudio_cv_support_arm_atomic_ops, [
 AC_COMPILE_IFELSE(
-AC_LANG_PROGRAM([], [[
+[AC_LANG_PROGRAM([], [[
 volatile int a=0;
 int o=0, n=1, r;
 asm volatile ("ldrex%0, [%1]\n"
@@ -262,7 +262,7 @@ else
   : "r" (&a), "Ir" (o), "r" (n)
   : "cc");
 return (a==1 ? 0 : -1);
-]]),
+]])],
 [pulseaudio_cv_support_arm_atomic_ops=yes],
 [pulseaudio_cv_support_arm_atomic_ops=no])
 ])
@@ -292,7 +292,7 @@ case $host in
 AC_CACHE_CHECK([support for required armv6 instructions],
   pulseaudio_cv_support_armv6,
   [AC_COMPILE_IFELSE(
- AC_LANG_PROGRAM([],
+ [AC_LANG_PROGRAM([],
[[volatile int a = -6, b = 0x, c = 0x;
  asm volatile ("ldr r0, %2 \n"
"ldr r2, %3 \n"
@@ -305,7 +305,7 @@ case $host in
: "m" (a), "m" (b), "m" (c)
: "r0", "r1", "r2", "r3", "cc");
  return (a == -128 && b == 0xaabb) ? 0 : -1;
-   ]]),
+   ]])],
  [pulseaudio_cv_support_armv6=yes],
  [pulseaudio_cv_support_armv6=no])
   ])
@@ -324,7 +324,7 @@ AC_ARG_ENABLE([neon-opt],
 AS_IF([test "x$enable_neon_opt" != "xno"],
 [save_CFLAGS="$CFLAGS"; CFLAGS="-mfpu=neon $CFLAGS"
  AC_COMPILE_IFELSE(
-AC_LANG_PROGRAM([[#include ]], []),
+[AC_LANG_PROGRAM([[#include ]], [])],
 [
  HAVE_NEON=1
  NEON_CFLAGS="-mfpu=neon"
@@ -453,7 +453,7 @@ AX_CHECK_DEFINE([netinet/in.h], [INADDR_NONE], [],
 AC_CACHE_CHECK([whether $CC knows _Bool],
 pulseaudio_cv__Bool,
 [AC_COMPILE_IFELSE(
-AC_LANG_PROGRAM([], [[_Bool b;]]),
+[AC_LANG_PROGRAM([], [[_Bool b;]])],
 [pulseaudio_cv__Bool=yes],
 [pulseaudio_cv__Bool=no])
 ])
-- 
1.8.4

___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


  1   2   >