[polypaudio-commits] r888 - in /trunk/src: modules/ modules/rtp/ polyp/ polypcore/ tests/

svnmailer-noreply at 0pointer.de svnmailer-noreply at 0pointer.de
Tue May 16 16:47:41 PDT 2006


Author: lennart
Date: Wed May 17 01:47:38 2006
New Revision: 888

URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=888&root=polypaudio&view=rev
Log:
* modify pa_channel_map_init_auto() to take an extra argument specifying the standard to use (ALSA, AIFF, ...)
* add some more validity checks to pa_source_new(),pa_sink_new(),pa_sink_input_new(),pa_source_output_new()

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
    trunk/src/modules/module-combine.c
    trunk/src/modules/module-jack-sink.c
    trunk/src/modules/module-jack-source.c
    trunk/src/modules/module-null-sink.c
    trunk/src/modules/module-oss-mmap.c
    trunk/src/modules/module-oss.c
    trunk/src/modules/module-pipe-sink.c
    trunk/src/modules/module-pipe-source.c
    trunk/src/modules/module-tunnel.c
    trunk/src/modules/rtp/module-rtp-send.c
    trunk/src/polyp/channelmap.c
    trunk/src/polyp/channelmap.h
    trunk/src/polyp/stream.c
    trunk/src/polypcore/core-scache.c
    trunk/src/polypcore/modargs.c
    trunk/src/polypcore/modargs.h
    trunk/src/polypcore/resampler.c
    trunk/src/polypcore/sink-input.c
    trunk/src/polypcore/sink.c
    trunk/src/polypcore/sound-file.c
    trunk/src/polypcore/source-output.c
    trunk/src/polypcore/source.c
    trunk/src/tests/channelmap-test.c

Modified: trunk/src/modules/alsa-util.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/modules/alsa-util.c?rev=888&root=polypaudio&r1=887&r2=888&view=diff
==============================================================================
--- trunk/src/modules/alsa-util.c (original)
+++ trunk/src/modules/alsa-util.c Wed May 17 01:47:38 2006
@@ -340,47 +340,3 @@
 
     return elem;
 }
-
-pa_channel_map* pa_alsa_channel_map_init_auto(pa_channel_map *m, unsigned channels) {
-    assert(m);
-    assert(channels > 0);
-    assert(channels <= PA_CHANNELS_MAX);
-
-    pa_channel_map_init(m);
-
-    m->channels = channels;
-
-    /* The standard ALSA channel order */
-    
-    switch (channels) {
-        case 1:
-            m->map[0] = PA_CHANNEL_POSITION_MONO;
-            return m;
-
-        case 8:
-            m->map[6] = PA_CHANNEL_POSITION_SIDE_LEFT;
-            m->map[7] = PA_CHANNEL_POSITION_SIDE_RIGHT;
-            /* Fall through */
-
-        case 6:
-            m->map[5] = PA_CHANNEL_POSITION_LFE;
-            /* Fall through */
-            
-        case 5:
-            m->map[4] = PA_CHANNEL_POSITION_FRONT_CENTER;
-            /* Fall through */
-            
-        case 4:
-            m->map[2] = PA_CHANNEL_POSITION_REAR_LEFT;
-            m->map[3] = PA_CHANNEL_POSITION_REAR_RIGHT;
-            /* Fall through */
-            
-        case 2:
-            m->map[0] = PA_CHANNEL_POSITION_FRONT_LEFT;
-            m->map[1] = PA_CHANNEL_POSITION_FRONT_RIGHT;
-            return m;
-
-        default:
-            return NULL;
-    }
-}

Modified: trunk/src/modules/alsa-util.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/modules/alsa-util.h?rev=888&root=polypaudio&r1=887&r2=888&view=diff
==============================================================================
--- trunk/src/modules/alsa-util.h (original)
+++ trunk/src/modules/alsa-util.h Wed May 17 01:47:38 2006
@@ -42,6 +42,4 @@
 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);
 
-pa_channel_map* pa_alsa_channel_map_init_auto(pa_channel_map *m, unsigned channels);
-
 #endif

Modified: trunk/src/modules/module-alsa-sink.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/modules/module-alsa-sink.c?rev=888&root=polypaudio&r1=887&r2=888&view=diff
==============================================================================
--- trunk/src/modules/module-alsa-sink.c (original)
+++ trunk/src/modules/module-alsa-sink.c Wed May 17 01:47:38 2006
@@ -324,19 +324,8 @@
     }
 
     ss = c->default_sample_spec;
-    if (pa_modargs_get_sample_spec(ma, &ss) < 0) {
-        pa_log(__FILE__": failed to parse sample specification");
-        goto fail;
-    }
-
-    pa_alsa_channel_map_init_auto(&map, ss.channels);
-    if ((pa_modargs_get_channel_map(ma, &map) < 0)) {
-        pa_log(__FILE__": invalid channel map.");
-        goto fail;
-    }
-
-    if (ss.channels != map.channels) {
-        pa_log(__FILE__": channel map and sample specification don't match.");
+    if (pa_modargs_get_sample_spec_and_channel_map(ma, &ss, &map, PA_CHANNEL_MAP_ALSA) < 0) {
+        pa_log(__FILE__": failed to parse sample specification and channel map");
         goto fail;
     }
 

Modified: trunk/src/modules/module-alsa-source.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/modules/module-alsa-source.c?rev=888&root=polypaudio&r1=887&r2=888&view=diff
==============================================================================
--- trunk/src/modules/module-alsa-source.c (original)
+++ trunk/src/modules/module-alsa-source.c Wed May 17 01:47:38 2006
@@ -316,19 +316,8 @@
     }
 
     ss = c->default_sample_spec;
-    if (pa_modargs_get_sample_spec(ma, &ss) < 0) {
+    if (pa_modargs_get_sample_spec_and_channel_map(ma, &ss, &map, PA_CHANNEL_MAP_ALSA) < 0) {
         pa_log(__FILE__": failed to parse sample specification");
-        goto fail;
-    }
-
-    pa_alsa_channel_map_init_auto(&map, ss.channels);
-    if ((pa_modargs_get_channel_map(ma, &map) < 0)) {
-        pa_log(__FILE__": invalid channel map.");
-        goto fail;
-    }
-
-    if (ss.channels != map.channels) {
-        pa_log(__FILE__": channel map and sample specification don't match.");
         goto fail;
     }
 

Modified: trunk/src/modules/module-combine.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/modules/module-combine.c?rev=888&root=polypaudio&r1=887&r2=888&view=diff
==============================================================================
--- trunk/src/modules/module-combine.c (original)
+++ trunk/src/modules/module-combine.c Wed May 17 01:47:38 2006
@@ -361,7 +361,7 @@
     if (ss.channels == master_sink->sample_spec.channels)
         map = master_sink->channel_map;
     else
-        pa_channel_map_init_auto(&map, ss.channels);
+        pa_channel_map_init_auto(&map, ss.channels, PA_CHANNEL_MAP_DEFAULT);
 
     if ((pa_modargs_get_channel_map(ma, &map) < 0)) {
         pa_log(__FILE__": invalid channel map.");

Modified: trunk/src/modules/module-jack-sink.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/modules/module-jack-sink.c?rev=888&root=polypaudio&r1=887&r2=888&view=diff
==============================================================================
--- trunk/src/modules/module-jack-sink.c (original)
+++ trunk/src/modules/module-jack-sink.c Wed May 17 01:47:38 2006
@@ -296,7 +296,7 @@
         goto fail;
     }
 
-    pa_channel_map_init_auto(&map, channels);
+    pa_channel_map_init_auto(&map, channels, PA_CHANNEL_MAP_ALSA);
     if (pa_modargs_get_channel_map(ma, &map) < 0 || map.channels != channels) {
         pa_log(__FILE__": failed to parse channel_map= argument.");
         goto fail;

Modified: trunk/src/modules/module-jack-source.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/modules/module-jack-source.c?rev=888&root=polypaudio&r1=887&r2=888&view=diff
==============================================================================
--- trunk/src/modules/module-jack-source.c (original)
+++ trunk/src/modules/module-jack-source.c Wed May 17 01:47:38 2006
@@ -294,7 +294,7 @@
         goto fail;
     }
 
-    pa_channel_map_init_auto(&map, channels);
+    pa_channel_map_init_auto(&map, channels, PA_CHANNEL_MAP_ALSA);
     if (pa_modargs_get_channel_map(ma, &map) < 0 || map.channels != channels) {
         pa_log(__FILE__": failed to parse channel_map= argument.");
         goto fail;

Modified: trunk/src/modules/module-null-sink.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/modules/module-null-sink.c?rev=888&root=polypaudio&r1=887&r2=888&view=diff
==============================================================================
--- trunk/src/modules/module-null-sink.c (original)
+++ trunk/src/modules/module-null-sink.c Wed May 17 01:47:38 2006
@@ -104,7 +104,7 @@
     }
 
     ss = c->default_sample_spec;
-    if (pa_modargs_get_sample_spec_and_channel_map(ma, &ss, &map) < 0) {
+    if (pa_modargs_get_sample_spec_and_channel_map(ma, &ss, &map, PA_CHANNEL_MAP_DEFAULT) < 0) {
         pa_log(__FILE__": invalid sample format specification or channel map.");
         goto fail;
     }

Modified: trunk/src/modules/module-oss-mmap.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/modules/module-oss-mmap.c?rev=888&root=polypaudio&r1=887&r2=888&view=diff
==============================================================================
--- trunk/src/modules/module-oss-mmap.c (original)
+++ trunk/src/modules/module-oss-mmap.c Wed May 17 01:47:38 2006
@@ -383,7 +383,7 @@
     }
 
     u->sample_spec = c->default_sample_spec;
-    if (pa_modargs_get_sample_spec_and_channel_map(ma, &u->sample_spec, &map) < 0) {
+    if (pa_modargs_get_sample_spec_and_channel_map(ma, &u->sample_spec, &map, PA_CHANNEL_MAP_ALSA) < 0) {
         pa_log(__FILE__": failed to parse sample specification or channel map");
         goto fail;
     }

Modified: trunk/src/modules/module-oss.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/modules/module-oss.c?rev=888&root=polypaudio&r1=887&r2=888&view=diff
==============================================================================
--- trunk/src/modules/module-oss.c (original)
+++ trunk/src/modules/module-oss.c Wed May 17 01:47:38 2006
@@ -347,7 +347,7 @@
     mode = (playback&&record) ? O_RDWR : (playback ? O_WRONLY : (record ? O_RDONLY : 0));
 
     ss = c->default_sample_spec;
-    if (pa_modargs_get_sample_spec_and_channel_map(ma, &ss, &map) < 0) {
+    if (pa_modargs_get_sample_spec_and_channel_map(ma, &ss, &map, PA_CHANNEL_MAP_ALSA) < 0) {
         pa_log(__FILE__": failed to parse sample specification or channel map");
         goto fail;
     }

Modified: trunk/src/modules/module-pipe-sink.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/modules/module-pipe-sink.c?rev=888&root=polypaudio&r1=887&r2=888&view=diff
==============================================================================
--- trunk/src/modules/module-pipe-sink.c (original)
+++ trunk/src/modules/module-pipe-sink.c Wed May 17 01:47:38 2006
@@ -154,7 +154,7 @@
     }
 
     ss = c->default_sample_spec;
-    if (pa_modargs_get_sample_spec_and_channel_map(ma, &ss, &map) < 0) {
+    if (pa_modargs_get_sample_spec_and_channel_map(ma, &ss, &map, PA_CHANNEL_MAP_DEFAULT) < 0) {
         pa_log(__FILE__": invalid sample format specification");
         goto fail;
     }

Modified: trunk/src/modules/module-pipe-source.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/modules/module-pipe-source.c?rev=888&root=polypaudio&r1=887&r2=888&view=diff
==============================================================================
--- trunk/src/modules/module-pipe-source.c (original)
+++ trunk/src/modules/module-pipe-source.c Wed May 17 01:47:38 2006
@@ -132,7 +132,7 @@
     }
 
     ss = c->default_sample_spec;
-    if (pa_modargs_get_sample_spec_and_channel_map(ma, &ss, &map) < 0) {
+    if (pa_modargs_get_sample_spec_and_channel_map(ma, &ss, &map, PA_CHANNEL_MAP_DEFAULT) < 0) {
         pa_log(__FILE__": invalid sample format specification or channel map");
         goto fail;
     }

Modified: trunk/src/modules/module-tunnel.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/modules/module-tunnel.c?rev=888&root=polypaudio&r1=887&r2=888&view=diff
==============================================================================
--- trunk/src/modules/module-tunnel.c (original)
+++ trunk/src/modules/module-tunnel.c Wed May 17 01:47:38 2006
@@ -895,7 +895,7 @@
     }
 
     ss = c->default_sample_spec;
-    if (pa_modargs_get_sample_spec_and_channel_map(ma, &ss, &map) < 0) {
+    if (pa_modargs_get_sample_spec_and_channel_map(ma, &ss, &map, PA_CHANNEL_MAP_DEFAULT) < 0) {
         pa_log(__FILE__": invalid sample format specification");
         goto fail;
     }

Modified: trunk/src/modules/rtp/module-rtp-send.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/modules/rtp/module-rtp-send.c?rev=888&root=polypaudio&r1=887&r2=888&view=diff
==============================================================================
--- trunk/src/modules/rtp/module-rtp-send.c (original)
+++ trunk/src/modules/rtp/module-rtp-send.c Wed May 17 01:47:38 2006
@@ -197,7 +197,7 @@
     }
 
     if (ss.channels != cm.channels)
-        pa_channel_map_init_auto(&cm, ss.channels);
+        pa_channel_map_init_auto(&cm, ss.channels, PA_CHANNEL_MAP_AIFF);
 
     payload = pa_rtp_payload_from_sample_spec(&ss);
 

Modified: trunk/src/polyp/channelmap.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/polyp/channelmap.c?rev=888&root=polypaudio&r1=887&r2=888&view=diff
==============================================================================
--- trunk/src/polyp/channelmap.c (original)
+++ trunk/src/polyp/channelmap.c Wed May 17 01:47:38 2006
@@ -112,7 +112,7 @@
     return m;
 }
 
-pa_channel_map* pa_channel_map_init_auto(pa_channel_map *m, unsigned channels) {
+pa_channel_map* pa_channel_map_init_auto(pa_channel_map *m, unsigned channels, pa_channel_map_def_t def) {
     assert(m);
     assert(channels > 0);
     assert(channels <= PA_CHANNELS_MAX);
@@ -121,46 +121,99 @@
 
     m->channels = channels;
 
-    /* This is somewhat compatible with RFC3551 */
-    
-    switch (channels) {
-        case 1:
-            m->map[0] = PA_CHANNEL_POSITION_MONO;
+    switch (def) {
+        case PA_CHANNEL_MAP_AIFF:
+            
+            /* This is somewhat compatible with RFC3551 */
+            
+            switch (channels) {
+                case 1:
+                    m->map[0] = PA_CHANNEL_POSITION_MONO;
+                    return m;
+                    
+                case 6:
+                    m->map[0] = PA_CHANNEL_POSITION_FRONT_LEFT;
+                    m->map[1] = PA_CHANNEL_POSITION_SIDE_LEFT;
+                    m->map[2] = PA_CHANNEL_POSITION_FRONT_CENTER;
+                    m->map[3] = PA_CHANNEL_POSITION_FRONT_RIGHT;
+                    m->map[4] = PA_CHANNEL_POSITION_SIDE_RIGHT;
+                    m->map[5] = PA_CHANNEL_POSITION_LFE;
+                    return m;
+                    
+                case 5:
+                    m->map[2] = PA_CHANNEL_POSITION_FRONT_CENTER;
+                    m->map[3] = PA_CHANNEL_POSITION_REAR_LEFT;
+                    m->map[4] = PA_CHANNEL_POSITION_REAR_RIGHT;
+                    /* Fall through */
+                    
+                case 2:
+                    m->map[0] = PA_CHANNEL_POSITION_FRONT_LEFT;
+                    m->map[1] = PA_CHANNEL_POSITION_FRONT_RIGHT;
+                    return m;
+                    
+                case 3:
+                    m->map[0] = PA_CHANNEL_POSITION_LEFT;
+                    m->map[1] = PA_CHANNEL_POSITION_RIGHT;
+                    m->map[2] = PA_CHANNEL_POSITION_CENTER;
+                    return m;
+                    
+                case 4:
+                    m->map[0] = PA_CHANNEL_POSITION_LEFT;
+                    m->map[1] = PA_CHANNEL_POSITION_CENTER;
+                    m->map[2] = PA_CHANNEL_POSITION_RIGHT;
+                    m->map[3] = PA_CHANNEL_POSITION_LFE;
+                    return m;
+                    
+                default:
+                    return NULL;
+            }
+
+        case PA_CHANNEL_MAP_ALSA:
+
+            switch (channels) {
+                case 1:
+                    m->map[0] = PA_CHANNEL_POSITION_MONO;
+                    return m;
+                    
+                case 8:
+                    m->map[6] = PA_CHANNEL_POSITION_SIDE_LEFT;
+                    m->map[7] = PA_CHANNEL_POSITION_SIDE_RIGHT;
+                    /* Fall through */
+                    
+                case 6:
+                    m->map[5] = PA_CHANNEL_POSITION_LFE;
+                    /* Fall through */
+                    
+                case 5:
+                    m->map[4] = PA_CHANNEL_POSITION_FRONT_CENTER;
+                    /* Fall through */
+                    
+                case 4:
+                    m->map[2] = PA_CHANNEL_POSITION_REAR_LEFT;
+                    m->map[3] = PA_CHANNEL_POSITION_REAR_RIGHT;
+                    /* Fall through */
+                    
+                case 2:
+                    m->map[0] = PA_CHANNEL_POSITION_FRONT_LEFT;
+                    m->map[1] = PA_CHANNEL_POSITION_FRONT_RIGHT;
+                    return m;
+                    
+                default:
+                    return NULL;
+            }
+
+        case PA_CHANNEL_MAP_AUX: {
+            unsigned i;
+            
+            if (channels >= PA_CHANNELS_MAX)
+                return NULL;
+
+            for (i = 0; i < channels; i++)
+                m->map[i] = PA_CHANNEL_POSITION_AUX0 + i;
+            
             return m;
-
-        case 6:
-            m->map[0] = PA_CHANNEL_POSITION_FRONT_LEFT;
-            m->map[1] = PA_CHANNEL_POSITION_SIDE_LEFT;
-            m->map[2] = PA_CHANNEL_POSITION_FRONT_CENTER;
-            m->map[3] = PA_CHANNEL_POSITION_FRONT_RIGHT;
-            m->map[4] = PA_CHANNEL_POSITION_SIDE_RIGHT;
-            m->map[5] = PA_CHANNEL_POSITION_LFE;
-            return m;
-            
-        case 5:
-            m->map[2] = PA_CHANNEL_POSITION_FRONT_CENTER;
-            m->map[3] = PA_CHANNEL_POSITION_REAR_LEFT;
-            m->map[4] = PA_CHANNEL_POSITION_REAR_RIGHT;
-            /* Fall through */
-            
-        case 2:
-            m->map[0] = PA_CHANNEL_POSITION_FRONT_LEFT;
-            m->map[1] = PA_CHANNEL_POSITION_FRONT_RIGHT;
-            return m;
-
-        case 3:
-            m->map[0] = PA_CHANNEL_POSITION_LEFT;
-            m->map[1] = PA_CHANNEL_POSITION_RIGHT;
-            m->map[2] = PA_CHANNEL_POSITION_CENTER;
-            return m;
-
-        case 4:
-            m->map[0] = PA_CHANNEL_POSITION_LEFT;
-            m->map[1] = PA_CHANNEL_POSITION_CENTER;
-            m->map[2] = PA_CHANNEL_POSITION_RIGHT;
-            m->map[3] = PA_CHANNEL_POSITION_LFE;
-            return m;
-            
+        }
+
         default:
             return NULL;
     }

Modified: trunk/src/polyp/channelmap.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/polyp/channelmap.h?rev=888&root=polypaudio&r1=887&r2=888&view=diff
==============================================================================
--- trunk/src/polyp/channelmap.h (original)
+++ trunk/src/polyp/channelmap.h Wed May 17 01:47:38 2006
@@ -120,6 +120,15 @@
     PA_CHANNEL_POSITION_MAX
 } pa_channel_position_t;
 
+/** A list of channel mapping definitions for pa_channel_map_init_auto() */
+typedef enum pa_channel_map_def {
+    PA_CHANNEL_MAP_AIFF, /**< The mapping from RFC3551, which is based on AIFF-C */
+    PA_CHANNEL_MAP_ALSA, /**< The default mapping used by ALSA */
+    PA_CHANNEL_MAP_AUX,  /**< Only aux channels */
+    
+    PA_CHANNEL_MAP_DEFAULT = PA_CHANNEL_MAP_AIFF /**< The default channel map */
+} pa_channel_map_def_t;
+
 /** A channel map which can be used to attach labels to specific
  * channels of a stream. These values are relevant for conversion and
  * mixing of streams */
@@ -138,9 +147,8 @@
 pa_channel_map* pa_channel_map_init_stereo(pa_channel_map *m);
 
 /** Initialize the specified channel map for the specified number
- * of channels using default labels and return a pointer to it.
- * Uses the mapping from RFC3551, which is based on AIFF-C. */
-pa_channel_map* pa_channel_map_init_auto(pa_channel_map *m, unsigned channels);
+ * of channels using default labels and return a pointer to it. */
+pa_channel_map* pa_channel_map_init_auto(pa_channel_map *m, unsigned channels, pa_channel_map_def_t def);
 
 /** Return a text label for the specified channel position */
 const char* pa_channel_position_to_string(pa_channel_position_t pos);

Modified: trunk/src/polyp/stream.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/polyp/stream.c?rev=888&root=polypaudio&r1=887&r2=888&view=diff
==============================================================================
--- trunk/src/polyp/stream.c (original)
+++ trunk/src/polyp/stream.c Wed May 17 01:47:38 2006
@@ -74,7 +74,7 @@
     if (map)
         s->channel_map = *map;
     else
-        pa_channel_map_init_auto(&s->channel_map, ss->channels);
+        pa_channel_map_init_auto(&s->channel_map, ss->channels, PA_CHANNEL_MAP_DEFAULT);
     
     s->channel = 0;
     s->channel_valid = 0;

Modified: trunk/src/polypcore/core-scache.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/polypcore/core-scache.c?rev=888&root=polypaudio&r1=887&r2=888&view=diff
==============================================================================
--- trunk/src/polypcore/core-scache.c (original)
+++ trunk/src/polypcore/core-scache.c Wed May 17 01:47:38 2006
@@ -141,7 +141,7 @@
 
     if (ss) {
         e->sample_spec = *ss;
-        pa_channel_map_init_auto(&e->channel_map, ss->channels);
+        pa_channel_map_init_auto(&e->channel_map, ss->channels, PA_CHANNEL_MAP_DEFAULT);
         e->volume.channels = e->sample_spec.channels;
     }
 

Modified: trunk/src/polypcore/modargs.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/polypcore/modargs.c?rev=888&root=polypaudio&r1=887&r2=888&view=diff
==============================================================================
--- trunk/src/polypcore/modargs.c (original)
+++ trunk/src/polypcore/modargs.c Wed May 17 01:47:38 2006
@@ -280,7 +280,7 @@
     return 0;
 }
 
-int pa_modargs_get_sample_spec_and_channel_map(pa_modargs *ma, pa_sample_spec *rss, pa_channel_map *rmap) {
+int pa_modargs_get_sample_spec_and_channel_map(pa_modargs *ma, pa_sample_spec *rss, pa_channel_map *rmap, pa_channel_map_def_t def) {
     pa_sample_spec ss;
     pa_channel_map map;
     
@@ -293,7 +293,8 @@
     if (pa_modargs_get_sample_spec(ma, &ss) < 0)
         return -1;
 
-    pa_channel_map_init_auto(&map, ss.channels);
+    if (!pa_channel_map_init_auto(&map, ss.channels, def))
+        map.channels = 0;
 
     if (pa_modargs_get_channel_map(ma, &map) < 0)
         return -1;

Modified: trunk/src/polypcore/modargs.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/polypcore/modargs.h?rev=888&root=polypaudio&r1=887&r2=888&view=diff
==============================================================================
--- trunk/src/polypcore/modargs.h (original)
+++ trunk/src/polypcore/modargs.h Wed May 17 01:47:38 2006
@@ -55,6 +55,6 @@
 initializes the map parameter based on the channels field of the ss
 structure if no channel_map is found, using pa_channel_map_init_auto() */
 
-int pa_modargs_get_sample_spec_and_channel_map(pa_modargs *ma, pa_sample_spec *ss, pa_channel_map *map);
+int pa_modargs_get_sample_spec_and_channel_map(pa_modargs *ma, pa_sample_spec *ss, pa_channel_map *map, pa_channel_map_def_t def);
 
 #endif

Modified: trunk/src/polypcore/resampler.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/polypcore/resampler.c?rev=888&root=polypaudio&r1=887&r2=888&view=diff
==============================================================================
--- trunk/src/polypcore/resampler.c (original)
+++ trunk/src/polypcore/resampler.c Wed May 17 01:47:38 2006
@@ -101,12 +101,12 @@
     if (am)
         r->i_cm = *am;
     else
-        pa_channel_map_init_auto(&r->i_cm, r->i_ss.channels);
+        pa_channel_map_init_auto(&r->i_cm, r->i_ss.channels, PA_CHANNEL_MAP_DEFAULT);
 
     if (bm)
         r->o_cm = *bm;
     else
-        pa_channel_map_init_auto(&r->o_cm, r->o_ss.channels);
+        pa_channel_map_init_auto(&r->o_cm, r->o_ss.channels, PA_CHANNEL_MAP_DEFAULT);
     
     r->i_fz = pa_frame_size(a);
     r->o_fz = pa_frame_size(b);

Modified: trunk/src/polypcore/sink-input.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/polypcore/sink-input.c?rev=888&root=polypaudio&r1=887&r2=888&view=diff
==============================================================================
--- trunk/src/polypcore/sink-input.c (original)
+++ trunk/src/polypcore/sink-input.c Wed May 17 01:47:38 2006
@@ -32,32 +32,53 @@
 #include <polypcore/xmalloc.h>
 #include <polypcore/core-subscribe.h>
 #include <polypcore/log.h>
+#include <polypcore/utf8.h>
 
 #include "sink-input.h"
 
 #define CONVERT_BUFFER_LENGTH 4096
 
+#define CHECK_VALIDITY_RETURN_NULL(condition) \
+do {\
+if (!(condition)) \
+    return NULL; \
+} while (0)
+
 pa_sink_input* pa_sink_input_new(
-    pa_sink *s,
-    const char *driver,
-    const char *name,
-    const pa_sample_spec *spec,
-    const pa_channel_map *map,
-    const pa_cvolume *volume, 
-    int variable_rate,
-    int resample_method) {
+        pa_sink *s,
+        const char *driver,
+        const char *name,
+        const pa_sample_spec *spec,
+        const pa_channel_map *map,
+        const pa_cvolume *volume, 
+        int variable_rate,
+        int resample_method) {
     
     pa_sink_input *i;
     pa_resampler *resampler = NULL;
     int r;
     char st[256];
     pa_channel_map tmap;
+    pa_cvolume tvol;
 
     assert(s);
     assert(spec);
     assert(s->state == PA_SINK_RUNNING);
 
-
+    CHECK_VALIDITY_RETURN_NULL(pa_sample_spec_valid(spec));
+
+    if (!map)
+        map = pa_channel_map_init_auto(&tmap, spec->channels, PA_CHANNEL_MAP_DEFAULT);
+    if (!volume)
+        volume = pa_cvolume_reset(&tvol, spec->channels);
+
+    CHECK_VALIDITY_RETURN_NULL(map && pa_channel_map_valid(map));
+    CHECK_VALIDITY_RETURN_NULL(volume && pa_cvolume_valid(volume));
+    CHECK_VALIDITY_RETURN_NULL(map->channels == spec->channels);
+    CHECK_VALIDITY_RETURN_NULL(volume->channels == spec->channels);
+    CHECK_VALIDITY_RETURN_NULL(!driver || pa_utf8_valid(driver));
+    CHECK_VALIDITY_RETURN_NULL(pa_utf8_valid(name));
+            
     if (pa_idxset_size(s->inputs) >= PA_MAX_INPUTS_PER_SINK) {
         pa_log_warn(__FILE__": Failed to create sink input: too many inputs per sink.");
         return NULL;
@@ -66,19 +87,6 @@
     if (resample_method == PA_RESAMPLER_INVALID)
         resample_method = s->core->resample_method;
     
-    if (map && spec->channels != map->channels)
-        return NULL;
-
-    if (volume && spec->channels != volume->channels)
-        return NULL;
-
-    if (!map) {
-        if (!(pa_channel_map_init_auto(&tmap, spec->channels)))
-            return NULL;
-        
-        map = &tmap;
-    }
-
     if (variable_rate || !pa_sample_spec_equal(spec, &s->sample_spec) || !pa_channel_map_equal(map, &s->channel_map))
         if (!(resampler = pa_resampler_new(spec, map, &s->sample_spec, &s->channel_map, s->core->memblock_stat, resample_method)))
             return NULL;
@@ -94,12 +102,8 @@
 
     i->sample_spec = *spec;
     i->channel_map = *map;
-
-    if (volume)
-        i->volume = *volume;
-    else
-        pa_cvolume_reset(&i->volume, spec->channels);
-    
+    i->volume = *volume;
+        
     i->peek = NULL;
     i->drop = NULL;
     i->kill = NULL;

Modified: trunk/src/polypcore/sink.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/polypcore/sink.c?rev=888&root=polypaudio&r1=887&r2=888&view=diff
==============================================================================
--- trunk/src/polypcore/sink.c (original)
+++ trunk/src/polypcore/sink.c Wed May 17 01:47:38 2006
@@ -29,6 +29,7 @@
 #include <stdio.h>
 
 #include <polyp/introspect.h>
+
 #include <polypcore/sink-input.h>
 #include <polypcore/namereg.h>
 #include <polypcore/util.h>
@@ -36,29 +37,46 @@
 #include <polypcore/xmalloc.h>
 #include <polypcore/core-subscribe.h>
 #include <polypcore/log.h>
+#include <polypcore/utf8.h>
 
 #include "sink.h"
 
 #define MAX_MIX_CHANNELS 32
 
+#define CHECK_VALIDITY_RETURN_NULL(condition) \
+do {\
+if (!(condition)) \
+    return NULL; \
+} while (0)
+
 pa_sink* pa_sink_new(
-    pa_core *core,
-    const char *driver,
-    const char *name,
-    int fail,
-    const pa_sample_spec *spec,
-    const pa_channel_map *map) {
+        pa_core *core,
+        const char *driver,
+        const char *name,
+        int fail,
+        const pa_sample_spec *spec,
+        const pa_channel_map *map) {
     
     pa_sink *s;
     char *n = NULL;
     char st[256];
     int r;
+    pa_channel_map tmap;
 
     assert(core);
     assert(name);
-    assert(*name);
     assert(spec);
 
+    CHECK_VALIDITY_RETURN_NULL(pa_sample_spec_valid(spec));
+    
+    if (!map)
+        map = pa_channel_map_init_auto(&tmap, spec->channels, PA_CHANNEL_MAP_DEFAULT);
+
+    CHECK_VALIDITY_RETURN_NULL(map && pa_channel_map_valid(map));
+    CHECK_VALIDITY_RETURN_NULL(map->channels == spec->channels);
+    CHECK_VALIDITY_RETURN_NULL(!driver || pa_utf8_valid(driver));
+    CHECK_VALIDITY_RETURN_NULL(pa_utf8_valid(name) && *name);
+    
     s = pa_xnew(pa_sink, 1);
 
     if (!(name = pa_namereg_register(core, name, PA_NAMEREG_SINK, s, fail))) {
@@ -75,10 +93,7 @@
     s->owner = NULL;
 
     s->sample_spec = *spec;
-    if (map)
-        s->channel_map = *map;
-    else
-        pa_channel_map_init_auto(&s->channel_map, spec->channels);
+    s->channel_map = *map;
     
     s->inputs = pa_idxset_new(NULL, NULL);
 

Modified: trunk/src/polypcore/sound-file.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/polypcore/sound-file.c?rev=888&root=polypaudio&r1=887&r2=888&view=diff
==============================================================================
--- trunk/src/polypcore/sound-file.c (original)
+++ trunk/src/polypcore/sound-file.c Wed May 17 01:47:38 2006
@@ -75,7 +75,7 @@
     }
 
     if (map)
-        pa_channel_map_init_auto(map, ss->channels);
+        pa_channel_map_init_auto(map, ss->channels, PA_CHANNEL_MAP_DEFAULT);
     
     if ((l = pa_frame_size(ss)*sfinfo.frames) > PA_SCACHE_ENTRY_SIZE_MAX) {
         pa_log(__FILE__": File too large");

Modified: trunk/src/polypcore/source-output.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/polypcore/source-output.c?rev=888&root=polypaudio&r1=887&r2=888&view=diff
==============================================================================
--- trunk/src/polypcore/source-output.c (original)
+++ trunk/src/polypcore/source-output.c Wed May 17 01:47:38 2006
@@ -31,16 +31,23 @@
 #include <polypcore/xmalloc.h>
 #include <polypcore/core-subscribe.h>
 #include <polypcore/log.h>
+#include <polypcore/utf8.h>
 
 #include "source-output.h"
 
+#define CHECK_VALIDITY_RETURN_NULL(condition) \
+do {\
+if (!(condition)) \
+    return NULL; \
+} while (0)
+
 pa_source_output* pa_source_output_new(
-    pa_source *s,
-    const char *driver,
-    const char *name,
-    const pa_sample_spec *spec,
-    const pa_channel_map *map,
-    int resample_method) {
+        pa_source *s,
+        const char *driver,
+        const char *name,
+        const pa_sample_spec *spec,
+        const pa_channel_map *map,
+        int resample_method) {
     
     pa_source_output *o;
     pa_resampler *resampler = NULL;
@@ -51,7 +58,17 @@
     assert(s);
     assert(spec);
     assert(s->state == PA_SOURCE_RUNNING);
-    
+
+    CHECK_VALIDITY_RETURN_NULL(pa_sample_spec_valid(spec));
+
+    if (!map)
+        map = pa_channel_map_init_auto(&tmap, spec->channels, PA_CHANNEL_MAP_DEFAULT);
+    
+    CHECK_VALIDITY_RETURN_NULL(map && pa_channel_map_valid(map));
+    CHECK_VALIDITY_RETURN_NULL(map->channels == spec->channels);
+    CHECK_VALIDITY_RETURN_NULL(!driver || pa_utf8_valid(driver));
+    CHECK_VALIDITY_RETURN_NULL(pa_utf8_valid(name));
+
     if (pa_idxset_size(s->outputs) >= PA_MAX_OUTPUTS_PER_SOURCE) {
         pa_log(__FILE__": Failed to create source output: too many outputs per source.");
         return NULL;
@@ -60,16 +77,11 @@
     if (resample_method == PA_RESAMPLER_INVALID)
         resample_method = s->core->resample_method;
 
-    if (!map) {
-        pa_channel_map_init_auto(&tmap, spec->channels);
-        map = &tmap;
-    }
-    
     if (!pa_sample_spec_equal(&s->sample_spec, spec) || !pa_channel_map_equal(&s->channel_map, map))
         if (!(resampler = pa_resampler_new(&s->sample_spec, &s->channel_map, spec, map, s->core->memblock_stat, resample_method)))
             return NULL;
     
-    o = pa_xmalloc(sizeof(pa_source_output));
+    o = pa_xnew(pa_source_output, 1);
     o->ref = 1;
     o->state = PA_SOURCE_OUTPUT_RUNNING;
     o->name = pa_xstrdup(name);
@@ -137,7 +149,6 @@
     pa_xfree(o);
 }
 
-
 void pa_source_output_unref(pa_source_output* o) {
     assert(o);
     assert(o->ref >= 1);

Modified: trunk/src/polypcore/source.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/polypcore/source.c?rev=888&root=polypaudio&r1=887&r2=888&view=diff
==============================================================================
--- trunk/src/polypcore/source.c (original)
+++ trunk/src/polypcore/source.c Wed May 17 01:47:38 2006
@@ -34,25 +34,42 @@
 #include <polypcore/core-subscribe.h>
 #include <polypcore/log.h>
 #include <polypcore/sample-util.h>
+#include <polypcore/utf8.h>
 
 #include "source.h"
 
+#define CHECK_VALIDITY_RETURN_NULL(condition) \
+do {\
+if (!(condition)) \
+    return NULL; \
+} while (0)
+
 pa_source* pa_source_new(
-    pa_core *core,
-    const char *driver,
-    const char *name,
-    int fail,
-    const pa_sample_spec *spec,
-    const pa_channel_map *map) {
+        pa_core *core,
+        const char *driver,
+        const char *name,
+        int fail,
+        const pa_sample_spec *spec,
+        const pa_channel_map *map) {
     
     pa_source *s;
     char st[256];
     int r;
+    pa_channel_map tmap;
     
     assert(core);
     assert(name);
-    assert(*name);
     assert(spec);
+
+    CHECK_VALIDITY_RETURN_NULL(pa_sample_spec_valid(spec));
+
+    if (!map)
+        map = pa_channel_map_init_auto(&tmap, spec->channels, PA_CHANNEL_MAP_DEFAULT);
+
+    CHECK_VALIDITY_RETURN_NULL(map && pa_channel_map_valid(map));
+    CHECK_VALIDITY_RETURN_NULL(map->channels == spec->channels);
+    CHECK_VALIDITY_RETURN_NULL(!driver || pa_utf8_valid(driver));
+    CHECK_VALIDITY_RETURN_NULL(pa_utf8_valid(name) && *name);
 
     s = pa_xnew(pa_source, 1);
 
@@ -70,10 +87,7 @@
     s->owner = NULL;
     
     s->sample_spec = *spec;
-    if (map)
-        s->channel_map = *map;
-    else
-        pa_channel_map_init_auto(&s->channel_map, spec->channels);
+    s->channel_map = *map;
 
     s->outputs = pa_idxset_new(NULL, NULL);
     s->monitor_of = NULL;

Modified: trunk/src/tests/channelmap-test.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/tests/channelmap-test.c?rev=888&root=polypaudio&r1=887&r2=888&view=diff
==============================================================================
--- trunk/src/tests/channelmap-test.c (original)
+++ trunk/src/tests/channelmap-test.c Wed May 17 01:47:38 2006
@@ -10,10 +10,18 @@
     char cm[PA_CHANNEL_MAP_SNPRINT_MAX];
     pa_channel_map map, map2;
 
-    pa_channel_map_init_auto(&map, 5);
+    pa_channel_map_init_auto(&map, 6, PA_CHANNEL_MAP_AIFF);
     
     fprintf(stderr, "map: <%s>\n", pa_channel_map_snprint(cm, sizeof(cm), &map));
 
+    pa_channel_map_init_auto(&map, 6, PA_CHANNEL_MAP_AUX);
+    
+    fprintf(stderr, "map: <%s>\n", pa_channel_map_snprint(cm, sizeof(cm), &map));
+
+    pa_channel_map_init_auto(&map, 6, PA_CHANNEL_MAP_ALSA);
+    
+    fprintf(stderr, "map: <%s>\n", pa_channel_map_snprint(cm, sizeof(cm), &map));
+    
     pa_channel_map_parse(&map2, cm);
 
     assert(pa_channel_map_equal(&map, &map2));




More information about the pulseaudio-commits mailing list