Index: Makefile =================================================================== RCS file: /usr/cvsroot/asterisk/Makefile,v retrieving revision 1.80 diff -u -r1.80 Makefile --- Makefile 23 Mar 2004 17:00:13 -0000 1.80 +++ Makefile 6 Apr 2004 08:19:01 -0000 @@ -115,6 +115,11 @@ CFLAGS+=-pthread endif +# Uncomment _ONLY_ one of the following to select an MP3 player +# for "Music On Hold". +CFLAGS+= -DUSE_MADPLAY +#CFLAGS+= -DUSE_MPG_123 + #Uncomment this to use the older DSP routines #CFLAGS+=-DOLD_DSP_ROUTINES Index: apps/app_mp3.c =================================================================== RCS file: /usr/cvsroot/asterisk/apps/app_mp3.c,v retrieving revision 1.14 diff -u -r1.14 app_mp3.c --- apps/app_mp3.c 29 Mar 2004 08:20:35 -0000 1.14 +++ apps/app_mp3.c 6 Apr 2004 08:19:10 -0000 @@ -28,6 +28,15 @@ #include #include +/* MIC: Check for mp3 player selection */ +#if !defined(USE_MADPLAY) +#if !defined(USE_MPG_123) +#error "You must select an MP3 player to use!" +#endif +#endif + +#define LOCAL_MADPLAY "/usr/local/bin/madplay" +#define MADPLAY "/usr/bin/madplay" #define LOCAL_MPG_123 "/usr/local/bin/mpg123" #define MPG_123 "/usr/bin/mpg123" @@ -60,6 +69,9 @@ if (x != STDOUT_FILENO) close(x); } + + /* MIC: Spawn the mp3 player */ +#if defined(USE_MPG_123) /* Execute mpg123, but buffer if it's a net connection */ if (strncmp(filename, "http://", 7)) { /* Most commonly installed in /usr/local/bin */ @@ -77,6 +89,17 @@ /* As a last-ditch effort, try to use PATH */ execlp("mpg123", "mpg123", "-q", "-s", "--mono", "-r", "8000", filename, (char *)NULL); } +#elif defined(USE_MADPLAY) + /* Execute madplay */ + /* Most commonly installed in /usr/local/bin */ + execl(LOCAL_MADPLAY, "madplay", "-Q", "--sample-rate", "8000", "--mono", "-o", "raw:-", filename, (char *)NULL); + /* But many places has it in /usr/bin */ + execl(MADPLAY, "madplay", "-Q", "--sample-rate", "8000", "--mono", "-o", "raw:-", filename, (char *)NULL); + /* As a last-ditch effort, try to use PATH */ + execl("madplay", "madplay", "-Q", "--sample-rate", "8000", "--mono", "-o", "raw:-", filename, (char *)NULL); +#else +#error "You must select an MP3 player to use!" +#endif ast_log(LOG_WARNING, "Execute of mpg123 failed\n"); return -1; } Index: res/res_musiconhold.c =================================================================== RCS file: /usr/cvsroot/asterisk/res/res_musiconhold.c,v retrieving revision 1.23 diff -u -r1.23 res_musiconhold.c --- res/res_musiconhold.c 27 Mar 2004 06:50:12 -0000 1.23 +++ res/res_musiconhold.c 6 Apr 2004 08:19:21 -0000 @@ -73,7 +73,7 @@ char dir[256]; char miscargs[256]; int destroyme; - int pid; /* PID of mpg123 */ + int pid; /* PID of mp3 player */ int quiet; pthread_t thread; struct mohdata *members; @@ -95,6 +95,15 @@ static ast_mutex_t moh_lock = AST_MUTEX_INITIALIZER; +/* MIC: Check for mp3 player selection */ +#if !defined(USE_MADPLAY) +#if !defined(USE_MPG_123) +#error "You must select an MP3 player to use!" +#endif +#endif + +#define LOCAL_MADPLAY "/usr/local/bin/madplay" +#define MADPLAY "/usr/bin/madplay" #define LOCAL_MPG_123 "/usr/local/bin/mpg123" #define MPG_123 "/usr/bin/mpg123" #define MAX_MP3S 256 @@ -115,6 +124,9 @@ ast_log(LOG_WARNING, "%s is not a valid directory\n", class->dir); return -1; } + + /* MIC: Fill the arguments per player */ +#if defined(USE_MPG_123) argv[0] = "mpg123"; argv[1] = "-q"; argv[2] = "-s"; @@ -129,6 +141,23 @@ argv[argc++] = "4096"; } else argv[argc++] = "8192"; + } +#elif defined(USE_MADPLAY) + argv[0] = "madplay"; + argv[1] = "-Q"; + argv[2] = "--sample-rate"; + argv[3] = "8000"; + argv[4] = "--mono"; + argv[5] = "-o"; + argv[6] = "raw:-"; + argc = 7; + if (class->quiet) { + argv[argc++] = "-a"; + argv[argc++] = "-8"; + } +#else +#error "You must select an MP3 player to use!" +#endif /* Look for extra arguments and add them to the list */ strncpy(xargs, class->miscargs, sizeof(xargs) - 1); @@ -187,12 +216,26 @@ close(x); /* Child */ chdir(class->dir); + + /* MIC: Spawn the mp3 player */ +#if defined(USE_MPG_123) /* Default install is /usr/local/bin */ execv(LOCAL_MPG_123, argv); /* Many places have it in /usr/bin */ execv(MPG_123, argv); /* Check PATH as a last-ditch effort */ execvp("mpg123", argv); +#elif defined(USE_MADPLAY) + /* Try in /usr/local/bin */ + execv(LOCAL_MADPLAY, argv); + /* Try in /usr/bin */ + execv(MADPLAY, argv); + /* Check PATH as a last-ditch effort */ + execvp("madplay", argv); +#else +#error "You must select an MP3 player to use!" +#endif + ast_log(LOG_WARNING, "Exec failed: %s\n", strerror(errno)); close(fds[1]); exit(1); @@ -269,7 +312,7 @@ } if (delay > 0) usleep(delay * 1000); - res = 800; /* 800 samples */ + res = 800; /* 100 samples */ } if (!class->members) continue; @@ -442,6 +485,8 @@ short buf[1280 + AST_FRIENDLY_OFFSET / 2]; int res; + if (len <= 0) + ast_log(LOG_DEBUG, " WTF? len <= 0?\n"); len = samples * 2; if (len > sizeof(buf) - AST_FRIENDLY_OFFSET) { ast_log(LOG_WARNING, "Only doing %d of %d requested bytes on %s\n", sizeof(buf), len, chan->name); @@ -587,16 +632,18 @@ moh = mohclasses; while(moh) { if (moh->pid) { - ast_log(LOG_DEBUG, "killing %d!\n", moh->pid); + if (option_debug) + ast_log(LOG_DEBUG, "Killing process %d!\n", moh->pid); stime = time(NULL); kill(moh->pid, SIGKILL); while ((bytes = read(moh->srcfd, buff, 8192)) && time(NULL) < stime + 5) { tbytes = tbytes + bytes; } - ast_log(LOG_DEBUG, "mpg123 pid %d and child died after %d bytes read\n", moh->pid, tbytes); + if (option_debug) + ast_log(LOG_DEBUG, "MP3 player pid %d and child died after %d bytes read\n", moh->pid, tbytes); close(moh->srcfd); moh->pid = 0; - } + } moh = moh->next; } ast_mutex_unlock(&moh_lock);