summaryrefslogtreecommitdiffstats
path: root/src/modules/alsa
diff options
context:
space:
mode:
authorTanu Kaskinen <tanuk@iki.fi>2009-08-16 21:25:48 +0300
committerTanu Kaskinen <tanuk@iki.fi>2009-08-16 21:25:48 +0300
commitbcaba0b1b43d6a1b32aadfa98860f40b2c93e136 (patch)
tree6bd0d60a8fa822bfd688b90d062d0f73eee2e47e /src/modules/alsa
parent2bb3eef414f80189cf6af6cd66c519630e4c0a43 (diff)
parent01e4b61a910afdd21f860fadbe98075735c2bf51 (diff)
Merge branch 'master' of git://0pointer.de/pulseaudio into dbus-work
Conflicts: src/Makefile.am src/daemon/daemon-conf.c src/daemon/daemon.conf.in src/modules/module-stream-restore.c src/pulse/client-conf.c src/pulsecore/namereg.c
Diffstat (limited to 'src/modules/alsa')
-rw-r--r--src/modules/alsa/alsa-mixer.c8
-rw-r--r--src/modules/alsa/alsa-sink.c42
-rw-r--r--src/modules/alsa/alsa-source.c33
-rw-r--r--src/modules/alsa/alsa-util.c55
l---------src/modules/alsa/mixer/Makefile1
l---------src/modules/alsa/mixer/paths/Makefile1
-rw-r--r--src/modules/alsa/mixer/paths/analog-output-headphones.conf4
-rw-r--r--src/modules/alsa/mixer/paths/analog-output-lfe-on-mono.conf6
-rw-r--r--src/modules/alsa/mixer/paths/analog-output-mono.conf6
-rw-r--r--src/modules/alsa/mixer/paths/analog-output.conf6
-rw-r--r--src/modules/alsa/mixer/paths/analog-output.conf.common4
l---------src/modules/alsa/mixer/profile-sets/Makefile1
12 files changed, 124 insertions, 43 deletions
diff --git a/src/modules/alsa/alsa-mixer.c b/src/modules/alsa/alsa-mixer.c
index a5515e1b..a4c2ee0f 100644
--- a/src/modules/alsa/alsa-mixer.c
+++ b/src/modules/alsa/alsa-mixer.c
@@ -940,7 +940,6 @@ int pa_alsa_path_select(pa_alsa_path *p, snd_mixer_t *m) {
PA_LLIST_FOREACH(e, p->elements) {
switch (e->switch_use) {
- case PA_ALSA_SWITCH_MUTE:
case PA_ALSA_SWITCH_OFF:
r = element_set_switch(e, m, FALSE);
break;
@@ -949,6 +948,7 @@ int pa_alsa_path_select(pa_alsa_path *p, snd_mixer_t *m) {
r = element_set_switch(e, m, TRUE);
break;
+ case PA_ALSA_SWITCH_MUTE:
case PA_ALSA_SWITCH_IGNORE:
case PA_ALSA_SWITCH_SELECT:
r = 0;
@@ -960,7 +960,6 @@ int pa_alsa_path_select(pa_alsa_path *p, snd_mixer_t *m) {
switch (e->volume_use) {
case PA_ALSA_VOLUME_OFF:
- case PA_ALSA_VOLUME_MERGE:
r = element_mute_volume(e, m);
break;
@@ -968,6 +967,7 @@ int pa_alsa_path_select(pa_alsa_path *p, snd_mixer_t *m) {
r = element_zero_volume(e, m);
break;
+ case PA_ALSA_VOLUME_MERGE:
case PA_ALSA_VOLUME_IGNORE:
r = 0;
break;
@@ -2838,9 +2838,9 @@ static int mapping_verify(pa_alsa_mapping *m, const pa_channel_map *bonus) {
if (bonus) {
if (pa_channel_map_equal(&m->channel_map, bonus))
- m->priority += 5000;
+ m->priority += 50;
else if (m->channel_map.channels == bonus->channels)
- m->priority += 4000;
+ m->priority += 30;
}
return 0;
diff --git a/src/modules/alsa/alsa-sink.c b/src/modules/alsa/alsa-sink.c
index c584362d..a91b4b8a 100644
--- a/src/modules/alsa/alsa-sink.c
+++ b/src/modules/alsa/alsa-sink.c
@@ -169,10 +169,10 @@ static int reserve_init(struct userdata *u, const char *dname) {
if (pa_in_system_mode())
return 0;
- /* We are resuming, try to lock the device */
if (!(rname = pa_alsa_get_reserve_name(dname)))
return 0;
+ /* We are resuming, try to lock the device */
u->reserve = pa_reserve_wrapper_get(u->core, rname);
pa_xfree(rname);
@@ -222,7 +222,6 @@ static int reserve_monitor_init(struct userdata *u, const char *dname) {
if (pa_in_system_mode())
return 0;
- /* We are resuming, try to lock the device */
if (!(rname = pa_alsa_get_reserve_name(dname)))
return 0;
@@ -341,6 +340,9 @@ static int try_recover(struct userdata *u, const char *call, int err) {
if (err == -EPIPE)
pa_log_debug("%s: Buffer underrun!", call);
+ if (err == -ESTRPIPE)
+ pa_log_debug("%s: System suspended!", call);
+
if ((err = snd_pcm_recover(u->pcm_handle, err, 1)) < 0) {
pa_log("%s: %s", call, pa_alsa_strerror(err));
return -1;
@@ -402,6 +404,7 @@ static int mmap_write(struct userdata *u, pa_usec_t *sleep_usec, pa_bool_t polle
snd_pcm_sframes_t n;
size_t n_bytes;
int r;
+ pa_bool_t after_avail = TRUE;
/* First we determine how many samples are missing to fill the
* buffer up to 100% */
@@ -485,6 +488,9 @@ static int mmap_write(struct userdata *u, pa_usec_t *sleep_usec, pa_bool_t polle
if (PA_UNLIKELY((err = pa_alsa_safe_mmap_begin(u->pcm_handle, &areas, &offset, &frames, u->hwbuf_size, &u->sink->sample_spec)) < 0)) {
+ if (!after_avail && err == -EAGAIN)
+ break;
+
if ((r = try_recover(u, "snd_pcm_mmap_begin", err)) == 0)
continue;
@@ -495,6 +501,12 @@ static int mmap_write(struct userdata *u, pa_usec_t *sleep_usec, pa_bool_t polle
if (frames > pa_mempool_block_size_max(u->sink->core->mempool)/u->frame_size)
frames = pa_mempool_block_size_max(u->sink->core->mempool)/u->frame_size;
+ if (!after_avail && frames == 0)
+ break;
+
+ pa_assert(frames > 0);
+ after_avail = FALSE;
+
/* Check these are multiples of 8 bit */
pa_assert((areas[0].first & 7) == 0);
pa_assert((areas[0].step & 7)== 0);
@@ -615,6 +627,7 @@ static int unix_write(struct userdata *u, pa_usec_t *sleep_usec, pa_bool_t polle
for (;;) {
snd_pcm_sframes_t frames;
void *p;
+ pa_bool_t after_avail = TRUE;
/* pa_log_debug("%lu frames to write", (unsigned long) frames); */
@@ -632,16 +645,23 @@ static int unix_write(struct userdata *u, pa_usec_t *sleep_usec, pa_bool_t polle
frames = snd_pcm_writei(u->pcm_handle, (const uint8_t*) p + u->memchunk.index, (snd_pcm_uframes_t) frames);
pa_memblock_release(u->memchunk.memblock);
- pa_assert(frames != 0);
-
if (PA_UNLIKELY(frames < 0)) {
+ if (!after_avail && (int) frames == -EAGAIN)
+ break;
+
if ((r = try_recover(u, "snd_pcm_writei", (int) frames)) == 0)
continue;
return r;
}
+ if (!after_avail && frames == 0)
+ break;
+
+ pa_assert(frames > 0);
+ after_avail = FALSE;
+
u->memchunk.index += (size_t) frames * u->frame_size;
u->memchunk.length -= (size_t) frames * u->frame_size;
@@ -882,9 +902,13 @@ static int unsuspend(struct userdata *u) {
if (build_pollfd(u) < 0)
goto fail;
+ u->write_count = 0;
+ pa_smoother_reset(u->smoother, pa_rtclock_now(), TRUE);
+
u->first = TRUE;
u->since_start = 0;
+
pa_log_info("Resumed successfully...");
return 0;
@@ -1178,8 +1202,11 @@ static int process_rewind(struct userdata *u) {
pa_log_debug("before: %lu", (unsigned long) in_frames);
if ((out_frames = snd_pcm_rewind(u->pcm_handle, (snd_pcm_uframes_t) in_frames)) < 0) {
pa_log("snd_pcm_rewind() failed: %s", pa_alsa_strerror((int) out_frames));
- return -1;
+ if (try_recover(u, "process_rewind", out_frames) < 0)
+ return -1;
+ out_frames = 0;
}
+
pa_log_debug("after: %lu", (unsigned long) out_frames);
rewind_nbytes = (size_t) out_frames * u->frame_size;
@@ -1187,7 +1214,7 @@ static int process_rewind(struct userdata *u) {
if (rewind_nbytes <= 0)
pa_log_info("Tried rewind, but was apparently not possible.");
else {
- u->write_count -= out_frames * u->frame_size;
+ u->write_count -= rewind_nbytes;
pa_log_debug("Rewound %lu bytes.", (unsigned long) rewind_nbytes);
pa_sink_process_rewind(u->sink, rewind_nbytes);
@@ -1265,7 +1292,8 @@ static void thread_func(void *userdata) {
* we have filled the buffer at least once
* completely.*/
- pa_log_debug("Cutting sleep time for the initial iterations by half.");
+ if (pa_log_ratelimit())
+ pa_log_debug("Cutting sleep time for the initial iterations by half.");
sleep_usec /= 2;
}
diff --git a/src/modules/alsa/alsa-source.c b/src/modules/alsa/alsa-source.c
index a6760e1e..9a51f857 100644
--- a/src/modules/alsa/alsa-source.c
+++ b/src/modules/alsa/alsa-source.c
@@ -333,6 +333,9 @@ static int try_recover(struct userdata *u, const char *call, int err) {
if (err == -EPIPE)
pa_log_debug("%s: Buffer overrun!", call);
+ if (err == -ESTRPIPE)
+ pa_log_debug("%s: System suspended!", call);
+
if ((err = snd_pcm_recover(u->pcm_handle, err, 1)) < 0) {
pa_log("%s: %s", call, pa_alsa_strerror(err));
return -1;
@@ -391,6 +394,7 @@ static int mmap_read(struct userdata *u, pa_usec_t *sleep_usec, pa_bool_t polled
snd_pcm_sframes_t n;
size_t n_bytes;
int r;
+ pa_bool_t after_avail = TRUE;
if (PA_UNLIKELY((n = pa_alsa_safe_avail(u->pcm_handle, u->hwbuf_size, &u->source->sample_spec)) < 0)) {
@@ -463,6 +467,9 @@ static int mmap_read(struct userdata *u, pa_usec_t *sleep_usec, pa_bool_t polled
if (PA_UNLIKELY((err = pa_alsa_safe_mmap_begin(u->pcm_handle, &areas, &offset, &frames, u->hwbuf_size, &u->source->sample_spec)) < 0)) {
+ if (!after_avail && err == -EAGAIN)
+ break;
+
if ((r = try_recover(u, "snd_pcm_mmap_begin", err)) == 0)
continue;
@@ -473,6 +480,12 @@ static int mmap_read(struct userdata *u, pa_usec_t *sleep_usec, pa_bool_t polled
if (frames > pa_mempool_block_size_max(u->source->core->mempool)/u->frame_size)
frames = pa_mempool_block_size_max(u->source->core->mempool)/u->frame_size;
+ if (!after_avail && frames == 0)
+ break;
+
+ pa_assert(frames > 0);
+ after_avail = FALSE;
+
/* Check these are multiples of 8 bit */
pa_assert((areas[0].first & 7) == 0);
pa_assert((areas[0].step & 7)== 0);
@@ -539,6 +552,7 @@ static int unix_read(struct userdata *u, pa_usec_t *sleep_usec, pa_bool_t polled
snd_pcm_sframes_t n;
size_t n_bytes;
int r;
+ pa_bool_t after_avail = TRUE;
if (PA_UNLIKELY((n = pa_alsa_safe_avail(u->pcm_handle, u->hwbuf_size, &u->source->sample_spec)) < 0)) {
@@ -599,17 +613,26 @@ static int unix_read(struct userdata *u, pa_usec_t *sleep_usec, pa_bool_t polled
frames = snd_pcm_readi(u->pcm_handle, (uint8_t*) p, (snd_pcm_uframes_t) frames);
pa_memblock_release(chunk.memblock);
- pa_assert(frames != 0);
-
if (PA_UNLIKELY(frames < 0)) {
pa_memblock_unref(chunk.memblock);
- if ((r = try_recover(u, "snd_pcm_readi", (int) (frames))) == 0)
+ if (!after_avail && (int) frames == -EAGAIN)
+ break;
+
+ if ((r = try_recover(u, "snd_pcm_readi", (int) frames)) == 0)
continue;
return r;
}
+ if (!after_avail && frames == 0) {
+ pa_memblock_unref(chunk.memblock);
+ break;
+ }
+
+ pa_assert(frames > 0);
+ after_avail = FALSE;
+
chunk.index = 0;
chunk.length = (size_t) frames * u->frame_size;
@@ -834,7 +857,9 @@ static int unsuspend(struct userdata *u) {
/* FIXME: We need to reload the volume somehow */
snd_pcm_start(u->pcm_handle);
- pa_smoother_resume(u->smoother, pa_rtclock_now(), TRUE);
+
+ u->read_count = 0;
+ pa_smoother_reset(u->smoother, pa_rtclock_now(), TRUE);
pa_log_info("Resumed successfully...");
diff --git a/src/modules/alsa/alsa-util.c b/src/modules/alsa/alsa-util.c
index 1f3e5dcd..a47a8958 100644
--- a/src/modules/alsa/alsa-util.c
+++ b/src/modules/alsa/alsa-util.c
@@ -233,14 +233,16 @@ int pa_alsa_set_hw_params(
goto finish;
}
- if (_period_size && tsched_size && _periods) {
+ if (_period_size > 0 && tsched_size > 0 && _periods > 0) {
+ snd_pcm_uframes_t buffer_size;
+ unsigned int p;
/* Adjust the buffer sizes, if we didn't get the rate we were asking for */
_period_size = (snd_pcm_uframes_t) (((uint64_t) _period_size * r) / ss->rate);
tsched_size = (snd_pcm_uframes_t) (((uint64_t) tsched_size * r) / ss->rate);
if (_use_tsched) {
- snd_pcm_uframes_t buffer_size = 0;
+ buffer_size = 0;
if ((ret = snd_pcm_hw_params_get_buffer_size_max(hwparams, &buffer_size)) < 0)
pa_log_warn("snd_pcm_hw_params_get_buffer_size_max() failed: %s", pa_alsa_strerror(ret));
@@ -251,32 +253,33 @@ int pa_alsa_set_hw_params(
_periods = 1;
}
- if (_period_size > 0 && _periods > 0) {
- snd_pcm_uframes_t buffer_size;
-
- buffer_size = _periods * _period_size;
-
- if ((ret = snd_pcm_hw_params_set_buffer_size_near(pcm_handle, hwparams, &buffer_size)) < 0)
- pa_log_info("snd_pcm_hw_params_set_buffer_size_near() failed: %s", pa_alsa_strerror(ret));
- }
-
- if (_periods > 0) {
-
- /* First we pass 0 as direction to get exactly what we
- * asked for. That this is necessary is presumably a bug
- * in ALSA. All in all this is mostly a hint to ALSA, so
- * we don't care if this fails. */
-
- dir = 0;
- if (snd_pcm_hw_params_set_periods_near(pcm_handle, hwparams, &_periods, &dir) < 0) {
- dir = 1;
- if (snd_pcm_hw_params_set_periods_near(pcm_handle, hwparams, &_periods, &dir) < 0) {
- dir = -1;
- if ((ret = snd_pcm_hw_params_set_periods_near(pcm_handle, hwparams, &_periods, &dir)) < 0)
- pa_log_info("snd_pcm_hw_params_set_periods_near() failed: %s", pa_alsa_strerror(ret));
- }
+ /* Some ALSA drivers really don't like if we set the buffer
+ * size first and the number of periods second. (which would
+ * make a lot more sense to me) So, follow this rule and
+ * adjust the periods first and the buffer size second */
+
+ /* First we pass 0 as direction to get exactly what we
+ * asked for. That this is necessary is presumably a bug
+ * in ALSA. All in all this is mostly a hint to ALSA, so
+ * we don't care if this fails. */
+
+ p = _periods;
+ dir = 0;
+ if (snd_pcm_hw_params_set_periods_near(pcm_handle, hwparams, &p, &dir) < 0) {
+ p = _periods;
+ dir = 1;
+ if (snd_pcm_hw_params_set_periods_near(pcm_handle, hwparams, &p, &dir) < 0) {
+ p = _periods;
+ dir = -1;
+ if ((ret = snd_pcm_hw_params_set_periods_near(pcm_handle, hwparams, &p, &dir)) < 0)
+ pa_log_info("snd_pcm_hw_params_set_periods_near() failed: %s", pa_alsa_strerror(ret));
}
}
+
+ /* Now set the buffer size */
+ buffer_size = _periods * _period_size;
+ if ((ret = snd_pcm_hw_params_set_buffer_size_near(pcm_handle, hwparams, &buffer_size)) < 0)
+ pa_log_info("snd_pcm_hw_params_set_buffer_size_near() failed: %s", pa_alsa_strerror(ret));
}
if ((ret = snd_pcm_hw_params(pcm_handle, hwparams)) < 0)
diff --git a/src/modules/alsa/mixer/Makefile b/src/modules/alsa/mixer/Makefile
new file mode 120000
index 00000000..b4955194
--- /dev/null
+++ b/src/modules/alsa/mixer/Makefile
@@ -0,0 +1 @@
+../../../pulse/Makefile \ No newline at end of file
diff --git a/src/modules/alsa/mixer/paths/Makefile b/src/modules/alsa/mixer/paths/Makefile
new file mode 120000
index 00000000..dc23aaa2
--- /dev/null
+++ b/src/modules/alsa/mixer/paths/Makefile
@@ -0,0 +1 @@
+../../../../pulse/Makefile \ No newline at end of file
diff --git a/src/modules/alsa/mixer/paths/analog-output-headphones.conf b/src/modules/alsa/mixer/paths/analog-output-headphones.conf
index c018e0eb..691cb3f2 100644
--- a/src/modules/alsa/mixer/paths/analog-output-headphones.conf
+++ b/src/modules/alsa/mixer/paths/analog-output-headphones.conf
@@ -44,6 +44,10 @@ volume = merge
override-map.1 = all
override-map.2 = all-left,all-right
+[Element Speaker]
+switch = off
+volume = off
+
[Element Front]
switch = off
volume = off
diff --git a/src/modules/alsa/mixer/paths/analog-output-lfe-on-mono.conf b/src/modules/alsa/mixer/paths/analog-output-lfe-on-mono.conf
index 7a267890..2db976a5 100644
--- a/src/modules/alsa/mixer/paths/analog-output-lfe-on-mono.conf
+++ b/src/modules/alsa/mixer/paths/analog-output-lfe-on-mono.conf
@@ -45,6 +45,12 @@ override-map.2 = lfe,lfe
switch = off
volume = off
+[Element Speaker]
+switch = mute
+volume = merge
+override-map.1 = all
+override-map.2 = all-left,all-right
+
[Element Front]
switch = off
volume = off
diff --git a/src/modules/alsa/mixer/paths/analog-output-mono.conf b/src/modules/alsa/mixer/paths/analog-output-mono.conf
index f6cb9f8a..a58cc970 100644
--- a/src/modules/alsa/mixer/paths/analog-output-mono.conf
+++ b/src/modules/alsa/mixer/paths/analog-output-mono.conf
@@ -42,6 +42,12 @@ override-map.2 = all-left,all-right
switch = off
volume = off
+[Element Speaker]
+switch = mute
+volume = merge
+override-map.1 = all
+override-map.2 = all-left,all-right
+
[Element Front]
switch = off
volume = off
diff --git a/src/modules/alsa/mixer/paths/analog-output.conf b/src/modules/alsa/mixer/paths/analog-output.conf
index ea108aaf..b412a437 100644
--- a/src/modules/alsa/mixer/paths/analog-output.conf
+++ b/src/modules/alsa/mixer/paths/analog-output.conf
@@ -41,6 +41,12 @@ volume = off
switch = off
volume = off
+[Element Speaker]
+switch = mute
+volume = merge
+override-map.1 = all
+override-map.2 = all-left,all-right
+
[Element Front]
switch = mute
volume = merge
diff --git a/src/modules/alsa/mixer/paths/analog-output.conf.common b/src/modules/alsa/mixer/paths/analog-output.conf.common
index cc1185f4..3c6ce803 100644
--- a/src/modules/alsa/mixer/paths/analog-output.conf.common
+++ b/src/modules/alsa/mixer/paths/analog-output.conf.common
@@ -104,8 +104,8 @@ switch = select
[Option External Amplifier:on]
name = output-amplifier-on
-priority = 0
+priority = 10
[Option External Amplifier:off]
name = output-amplifier-off
-priority = 10
+priority = 0
diff --git a/src/modules/alsa/mixer/profile-sets/Makefile b/src/modules/alsa/mixer/profile-sets/Makefile
new file mode 120000
index 00000000..dc23aaa2
--- /dev/null
+++ b/src/modules/alsa/mixer/profile-sets/Makefile
@@ -0,0 +1 @@
+../../../../pulse/Makefile \ No newline at end of file