Revision
14810
Author
gmaruzz
Date
2009-09-10 15:22:12 -0500 (Thu, 10 Sep 2009)

Log Message

celliax: now asterisk too initialize ALSA only when needed, and shutdown it when not in a call

Modified Paths

Diff

Modified: freeswitch/branches/gmaruzz/mod_celliax/asterisk/Makefile (14809 => 14810)


--- freeswitch/branches/gmaruzz/mod_celliax/asterisk/Makefile	2009-09-10 20:20:23 UTC (rev 14809)
+++ freeswitch/branches/gmaruzz/mod_celliax/asterisk/Makefile	2009-09-10 20:22:12 UTC (rev 14810)
@@ -17,7 +17,7 @@
 #ASTERISK INCLUDE FILES
 #The directory that contains the Asterisk include files (eg: /usr/include or /usr/include/asterisk or /usr/src/asterisk/include or ...)
 #AST_INCLUDE_DIR=/usr/src/off_dev/asterisk-1.2.rev137401/include
-AST_INCLUDE_DIR=/usr/src/asterisk-1.4.26/include
+AST_INCLUDE_DIR=/usr/src/asterisk-1.4.26.2/include
 #AST_INCLUDE_DIR=/usr/src/asterisk-1.6.0.10/include
 
 #ASTERISK VERSION

Modified: freeswitch/branches/gmaruzz/mod_celliax/asterisk/chan_celliax.c (14809 => 14810)


--- freeswitch/branches/gmaruzz/mod_celliax/asterisk/chan_celliax.c	2009-09-10 20:20:23 UTC (rev 14809)
+++ freeswitch/branches/gmaruzz/mod_celliax/asterisk/chan_celliax.c	2009-09-10 20:22:12 UTC (rev 14810)
@@ -634,6 +634,7 @@
 int celliax_hangup(struct ast_channel *c)
 {
   struct celliax_pvt *p;
+        int res;
 
   /* get our celliax pvt interface from channel */
   p = c->tech_pvt;
@@ -674,7 +675,6 @@
     if (p->interface_state != AST_STATE_DOWN) {
       /* actually hangup through the serial port */
       if (p->controldevprotocol != PROTOCOL_NO_SERIAL) {
-        int res;
         res = celliax_serial_hangup(p);
         if (res) {
           ERRORA("celliax_serial_hangup error: %d\n", CELLIAX_P_LOG, res);
@@ -712,6 +712,15 @@
 
   snd_pcm_prepare(p->alsac);
   snd_pcm_start(p->alsac);
+
+    /* shutdown the sound system, close sound fds, and if exist shutdown the sound managing threads */
+    DEBUGA_SOUND("shutting down sound\n", CELLIAX_P_LOG);
+    res = celliax_sound_shutdown(p);
+    if (res == -1) {
+      ERRORA("Failed to shutdown sound\n", CELLIAX_P_LOG);
+    }
+
+
 #endif /* CELLIAX_ALSA */
 
 #endif /* __CYGWIN__ */
@@ -1138,7 +1147,18 @@
 
 #endif /* ASTERISK_VERSION_1_4 */
   if (tmp) {
+int res;
 
+/* initialize the soundcard channels (input and output) used by this interface (a multichannel soundcard can be used by multiple interfaces), optionally starting the sound managing threads */
+  res = celliax_sound_init(p);
+  if (res == -1) {
+    ERRORA("Failed initializing sound device\n", CELLIAX_P_LOG);
+    /* we failed, free the PVT */
+    if (tmp)
+      free(tmp);
+    return NULL;
+  }
+
     /* give a name to the newly created channel */
 #ifndef ASTERISK_VERSION_1_4
     snprintf(tmp->name, sizeof(tmp->name), "Celliax/%s", p->name);
@@ -1940,6 +1960,15 @@
     }
   }
 #endif /* CELLIAX_CVM */
+  if (tmp->need_acoustic_ring) {
+    /* alloc and initialize a new dsp struct for this interface pvt, WITH silence suppression */
+    if (celliax_sound_dsp_set(tmp, tmp->dsp_silence_threshold, 1)) {
+      ERRORA("celliax_sound_dsp_set failed\n", CELLIAX_TMP_LOG);
+      celliax_sound_shutdown(tmp);
+      if (tmp)
+        free(tmp);
+      return NULL;
+    }
 
 /* initialize the soundcard channels (input and output) used by this interface (a multichannel soundcard can be used by multiple interfaces), optionally starting the sound managing threads */
   res = celliax_sound_init(tmp);
@@ -1950,15 +1979,7 @@
       free(tmp);
     return NULL;
   }
-  if (tmp->need_acoustic_ring) {
-    /* alloc and initialize a new dsp struct for this interface pvt, WITH silence suppression */
-    if (celliax_sound_dsp_set(tmp, tmp->dsp_silence_threshold, 1)) {
-      ERRORA("celliax_sound_dsp_set failed\n", CELLIAX_TMP_LOG);
-      celliax_sound_shutdown(tmp);
-      if (tmp)
-        free(tmp);
-      return NULL;
-    }
+
   }
 
   /* init the serial port */