Sane FreeBSD patch
[asterisk/asterisk.git] / apps / app_intercom.c
index a50b533..4c2379c 100755 (executable)
@@ -11,6 +11,7 @@
  * the GNU General Public License
  */
  
+#include <asterisk/lock.h>
 #include <asterisk/file.h>
 #include <asterisk/frame.h>
 #include <asterisk/logger.h>
 #include <stdlib.h>
 #include <pthread.h>
 #include <sys/time.h>
+#ifdef __linux__
 #include <linux/soundcard.h>
+#elif defined(__FreeBSD__)
+#include <machine/soundcard.h>
+#else
+#include <soundcard.h>
+#endif
 #include <netinet/in.h>
 
 #define DEV_DSP "/dev/dsp"
@@ -37,34 +44,40 @@ static char *tdesc = "Intercom using /dev/dsp for output";
 
 static char *app = "Intercom";
 
+static char *synopsis = "(Obsolete) Send to Intercom";
+static char *descrip = 
+"  Intercom(): Sends the user to the intercom (i.e. /dev/dsp).  This program\n"
+"is generally considered  obselete by the chan_oss module.  Returns 0 if the\n"
+"user exits with a DTMF tone, or -1 if they hangup.\n";
+
 STANDARD_LOCAL_USER;
 
 LOCAL_USER_DECL;
 
-static pthread_mutex_t sound_lock = PTHREAD_MUTEX_INITIALIZER;
+static ast_mutex_t sound_lock = AST_MUTEX_INITIALIZER;
 static int sound = -1;
 
 static int write_audio(short *data, int len)
 {
        int res;
        struct audio_buf_info info;
-       pthread_mutex_lock(&sound_lock);
+       ast_mutex_lock(&sound_lock);
        if (sound < 0) {
                ast_log(LOG_WARNING, "Sound device closed?\n");
-               pthread_mutex_unlock(&sound_lock);
+               ast_mutex_unlock(&sound_lock);
                return -1;
        }
     if (ioctl(sound, SNDCTL_DSP_GETOSPACE, &info)) {
                ast_log(LOG_WARNING, "Unable to read output space\n");
-               pthread_mutex_unlock(&sound_lock);
+               ast_mutex_unlock(&sound_lock);
         return -1;
     }
        res = write(sound, data, len);
-       pthread_mutex_unlock(&sound_lock);
+       ast_mutex_unlock(&sound_lock);
        return res;
 }
 
-static int create_audio()
+static int create_audio(void)
 {
        int fmt, desired, res, fd;
        fd = open(DEV_DSP, O_WRONLY);
@@ -117,10 +130,6 @@ static int intercom_exec(struct ast_channel *chan, void *data)
        struct localuser *u;
        struct ast_frame *f;
        int oreadformat;
-       if (!data) {
-               ast_log(LOG_WARNING, "Playback requires an argument (filename)\n");
-               return -1;
-       }
        LOCAL_USER_ADD(u);
        /* Remember original read format */
        oreadformat = chan->readformat;
@@ -173,7 +182,7 @@ int load_module(void)
 {
        if (create_audio())
                return -1;
-       return ast_register_application(app, intercom_exec);
+       return ast_register_application(app, intercom_exec, synopsis, descrip);
 }
 
 char *description(void)