]> code.delx.au - pulseaudio/blobdiff - src/modules/module-alsa-source.c
* if an ALSA device doesn't support the channel count requested, use what ALSA sugges...
[pulseaudio] / src / modules / module-alsa-source.c
index 414efda882abd8922437d5483e72c9a958c83a9f..10b98f75b9d21907b5aded2ba9462ee1cb717037 100644 (file)
@@ -335,7 +335,7 @@ int pa__init(pa_core *c, pa_module*m) {
     }
     period_size = fragsize/frame_size;
     
-    u = pa_xmalloc0(sizeof(struct userdata));
+    u = pa_xnew(struct userdata, 1);
     m->userdata = u;
     u->module = m;
     
@@ -356,6 +356,10 @@ int pa__init(pa_core *c, pa_module*m) {
         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;
@@ -367,8 +371,10 @@ int pa__init(pa_core *c, pa_module*m) {
         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 @@ int pa__init(pa_core *c, pa_module*m) {
         }
         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;