[polypaudio-commits] r992 - in /trunk/src/modules: alsa-util.c alsa-util.h module-alsa-sink.c module-alsa-source.c
svnmailer-noreply at 0pointer.de
svnmailer-noreply at 0pointer.de
Tue May 30 15:05:09 PDT 2006
Author: lennart
Date: Wed May 31 00:05:07 2006
New Revision: 992
URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=992&root=polypaudio&view=rev
Log:
* if an ALSA device doesn't support the channel count requested, use what ALSA suggests instead
* if an ALSA device doesn't support the sampling freq requested, use what ALSA suggests and resample if this deviates more than 10% from what we requested
* fix segfault freeing an unitialized mixer_fdl field
Modified:
trunk/src/modules/alsa-util.c
trunk/src/modules/alsa-util.h
trunk/src/modules/module-alsa-sink.c
trunk/src/modules/module-alsa-source.c
Modified: trunk/src/modules/alsa-util.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/modules/alsa-util.c?rev=992&root=polypaudio&r1=991&r2=992&view=diff
==============================================================================
--- trunk/src/modules/alsa-util.c (original)
+++ trunk/src/modules/alsa-util.c Wed May 31 00:05:07 2006
@@ -249,11 +249,12 @@
/* Set the hardware parameters of the given ALSA device. Returns the
* selected fragment settings in *period and *period_size */
-int pa_alsa_set_hw_params(snd_pcm_t *pcm_handle, const pa_sample_spec *ss, uint32_t *periods, snd_pcm_uframes_t *period_size) {
+int pa_alsa_set_hw_params(snd_pcm_t *pcm_handle, pa_sample_spec *ss, uint32_t *periods, snd_pcm_uframes_t *period_size) {
int ret = -1;
snd_pcm_uframes_t buffer_size;
snd_pcm_hw_params_t *hwparams = NULL;
unsigned int r = ss->rate;
+ unsigned int c = ss->channels;
static const snd_pcm_format_t format_trans[] = {
[PA_SAMPLE_U8] = SND_PCM_FORMAT_U8,
@@ -273,14 +274,24 @@
(ret = snd_pcm_hw_params_set_access(pcm_handle, hwparams, SND_PCM_ACCESS_RW_INTERLEAVED)) < 0 ||
(ret = snd_pcm_hw_params_set_format(pcm_handle, hwparams, format_trans[ss->format])) < 0 ||
(ret = snd_pcm_hw_params_set_rate_near(pcm_handle, hwparams, &r, NULL)) < 0 ||
- (ret = snd_pcm_hw_params_set_channels(pcm_handle, hwparams, ss->channels)) < 0 ||
+ (ret = snd_pcm_hw_params_set_channels_near(pcm_handle, hwparams, &c)) < 0 ||
(*period_size > 0 && (ret = snd_pcm_hw_params_set_period_size_near(pcm_handle, hwparams, period_size, NULL)) < 0) ||
(*periods > 0 && (ret = snd_pcm_hw_params_set_buffer_size_near(pcm_handle, hwparams, &buffer_size)) < 0) ||
(ret = snd_pcm_hw_params(pcm_handle, hwparams)) < 0)
goto finish;
- if (ss->rate != r)
+ if (ss->rate != r) {
pa_log_info(__FILE__": device doesn't support %u Hz, changed to %u Hz.", ss->rate, r);
+
+ /* If the sample rate deviates too much, we need to resample */
+ if (r < ss->rate*.9 || r > ss->rate*1.1)
+ ss->rate = r;
+ }
+
+ if (ss->channels != c) {
+ pa_log_info(__FILE__": device doesn't support %u channels, changed to %u.", ss->channels, c);
+ ss->channels = c;
+ }
if ((ret = snd_pcm_prepare(pcm_handle)) < 0)
goto finish;
Modified: trunk/src/modules/alsa-util.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/modules/alsa-util.h?rev=992&root=polypaudio&r1=991&r2=992&view=diff
==============================================================================
--- trunk/src/modules/alsa-util.h (original)
+++ trunk/src/modules/alsa-util.h Wed May 31 00:05:07 2006
@@ -37,7 +37,7 @@
int pa_alsa_fdlist_init_pcm(struct pa_alsa_fdlist *fdl, snd_pcm_t *pcm_handle, pa_mainloop_api* m, void (*cb)(void *userdata), void *userdata);
int pa_alsa_fdlist_init_mixer(struct pa_alsa_fdlist *fdl, snd_mixer_t *mixer_handle, pa_mainloop_api* m);
-int pa_alsa_set_hw_params(snd_pcm_t *pcm_handle, const pa_sample_spec *ss, uint32_t *periods, snd_pcm_uframes_t *period_size);
+int pa_alsa_set_hw_params(snd_pcm_t *pcm_handle, pa_sample_spec *ss, uint32_t *periods, snd_pcm_uframes_t *period_size);
int pa_alsa_prepare_mixer(snd_mixer_t *mixer, const char *dev);
snd_mixer_elem_t *pa_alsa_find_elem(snd_mixer_t *mixer, const char *name);
Modified: trunk/src/modules/module-alsa-sink.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/modules/module-alsa-sink.c?rev=992&root=polypaudio&r1=991&r2=992&view=diff
==============================================================================
--- trunk/src/modules/module-alsa-sink.c (original)
+++ trunk/src/modules/module-alsa-sink.c Wed May 31 00:05:07 2006
@@ -363,6 +363,10 @@
goto fail;
}
+ if (ss.channels != map.channels)
+ /* Seems ALSA didn't like the channel number, so let's fix the channel map */
+ pa_channel_map_init_auto(&map, ss.channels, PA_CHANNEL_MAP_ALSA);
+
if ((err = snd_mixer_open(&u->mixer_handle, 0)) < 0) {
pa_log(__FILE__": Error opening mixer: %s", snd_strerror(err));
goto fail;
@@ -374,8 +378,10 @@
u->mixer_handle = NULL;
}
- u->sink = pa_sink_new(c, __FILE__, pa_modargs_get_value(ma, "sink_name", DEFAULT_SINK_NAME), 0, &ss, &map);
- assert(u->sink);
+ if (!(u->sink = pa_sink_new(c, __FILE__, pa_modargs_get_value(ma, "sink_name", DEFAULT_SINK_NAME), 0, &ss, &map))) {
+ pa_log(__FILE__": Failed to create sink object");
+ goto fail;
+ }
u->sink->get_latency = sink_get_latency_cb;
if (u->mixer_handle) {
@@ -420,7 +426,8 @@
}
snd_mixer_elem_set_callback(u->mixer_elem, mixer_callback);
snd_mixer_elem_set_callback_private(u->mixer_elem, u);
- }
+ } else
+ u->mixer_fdl = NULL;
u->frame_size = frame_size;
u->fragment_size = period_size * frame_size;
Modified: trunk/src/modules/module-alsa-source.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/modules/module-alsa-source.c?rev=992&root=polypaudio&r1=991&r2=992&view=diff
==============================================================================
--- trunk/src/modules/module-alsa-source.c (original)
+++ trunk/src/modules/module-alsa-source.c Wed May 31 00:05:07 2006
@@ -335,7 +335,7 @@
}
period_size = fragsize/frame_size;
- u = pa_xmalloc0(sizeof(struct userdata));
+ u = pa_xnew(struct userdata, 1);
m->userdata = u;
u->module = m;
@@ -355,6 +355,10 @@
pa_log(__FILE__": Failed to set hardware parameters: %s", snd_strerror(err));
goto fail;
}
+
+ if (ss.channels != map.channels)
+ /* Seems ALSA didn't like the channel number, so let's fix the channel map */
+ pa_channel_map_init_auto(&map, ss.channels, PA_CHANNEL_MAP_ALSA);
if ((err = snd_mixer_open(&u->mixer_handle, 0)) < 0) {
pa_log(__FILE__": Error opening mixer: %s", snd_strerror(err));
@@ -367,8 +371,10 @@
u->mixer_handle = NULL;
}
- u->source = pa_source_new(c, __FILE__, pa_modargs_get_value(ma, "source_name", DEFAULT_SOURCE_NAME), 0, &ss, &map);
- assert(u->source);
+ if (!(u->source = pa_source_new(c, __FILE__, pa_modargs_get_value(ma, "source_name", DEFAULT_SOURCE_NAME), 0, &ss, &map))) {
+ pa_log(__FILE__": Failed to create source object");
+ goto fail;
+ }
u->source->userdata = u;
u->source->get_latency = source_get_latency_cb;
@@ -413,7 +419,8 @@
}
snd_mixer_elem_set_callback(u->mixer_elem, mixer_callback);
snd_mixer_elem_set_callback_private(u->mixer_elem, u);
- }
+ } else
+ u->mixer_fdl = NULL;
u->frame_size = frame_size;
u->fragment_size = period_size * frame_size;
More information about the pulseaudio-commits
mailing list