· KLDP.org · KLDP.net · KLDP Wiki · KLDP BBS ·
Asterisk Inst/Music On Hold

AsteriskInst/MusicOnHold

* MusicOnHold(class)

* musiconhold.conf
  • mode, directory, application, random, format
[classname]
mode => mode
directory => directory
application => application

[default]
mode=custom
application=/usr/sbin/streamplayer 192.168.100.52 888
format=ulaw
  • Is this backwards compatible?
    • If the category is "classes" or "moh_files", then the configuration will be parsed as it was done originally.
The format up to Asterisk 1.0 was with one line per class under the [classes] section 
[classes]
classname => mode:directory,application

[classes]
;default => quietmp3:/var/lib/asterisk/mohmp3
;loud => mp3:/var/lib/asterisk/mohmp3
;random => quietmp3:/var/lib/asterisk/mohmp3,-z
[moh_files]
default => /var/lib/asterisk/moh-native 

* SetMusicOnHold(class)

* MP3Player(location)
Executes the mpg123 unix program to play the given location which typically would either be the filename of an MP3 sound file, or the URL of an MP3 stream. The callers can exit by dialing any digit. 
* mpg123 format_mp3
Install MP3 Support

In order to play Music-On-Hold (MOH) Linux needs to be able to decode and handle the MP3 file format. This can be done in two different ways, by installation of the classic mpg123 module or by using the new format_mp3 module contained in Asterisk Addons. Be sure to install only one of these solutions and not both!

1.) MP3 playbyck with mpg123

This is a proven and reliable solution. Without applying the patch below there is a known security issue, but the most serious drawback is the fact that mpg123 is not being actively maintained any more. Download both the latest mpg123 installation source and security patch, copy both to /usr/src und install them as follows:

cd /usr/src
rpm -i mpg123-0.59s-513.i586.rpm
rpm -i mpg123-0.59s-513.i586.patch.rpm

2.) MP3 playback with format_mp3  

This is a new light-weight mp3 module found in Asterisk Addons V.1.2.3. This is a solution with a more promising future, even though it is not quite ready for production yet. The author states that is has only been tested with Solaris 2.6 and there are known issues with MP3 files encoded with LAME that may lead to Linux crashes. You should also make sure to convert your mp3 files to 8 kHz Mono format in order to avoid high CPU load. For latest installation instructions see the README inside the Asterisk Addons package.

Unless you want to install an ISDN card, you are now ready to install Asterisk.
* lame sox
  • $ lame --decode soundfile1.mp3 soundfile1.wav
  • $ sox -V soundfile1.wav -r 8000 -c 1 -w soundfile1.raw
  • MP3 files encoded with LAME may lead to Linux crashes
  • convert mp3 files to 8 kHz Mono format in order to avoid high CPU load
  • /etc/asterisk/musiconhold.conf
[default]
mode=files
directory=/var/lib/asterisk/mohmp3 
  • /etc/asterisk/extensions.conf
exten => 9000,1,Answer
exten => 9000,2,SetMusicOnHold(default)
exten => 9000,3,WaitMusicOnHold(20)
exten => 9000,4,Hangup 

* streaming audio

source

* res_musiconhold.c
  • int load_module(void)
    • res = ast_register_application(app0, moh0_exec, synopsis0, descrip0);
    • res = ast_register_application(app1, moh1_exec, synopsis1, descrip1);
    • res = ast_register_application(app2, moh2_exec, synopsis2, descrip2);
    • res = ast_register_application(app3, moh3_exec, synopsis3, descrip3);
    • res = ast_register_application(app4, moh4_exec, synopsis4, descrip4);
    • if (!init_classes(0))
      • ast_install_music_functions(local_ast_moh_start, local_ast_moh_stop, local_ast_moh_cleanup);
static char *app0 = "MusicOnHold";
static char *app1 = "WaitMusicOnHold";
static char *app2 = "SetMusicOnHold";
static char *app3 = "StartMusicOnHold";
static char *app4 = "StopMusicOnHold";
  • static int moh0_exec(struct ast_channel *chan, void *data)
    • ast_moh_start(chan, data)
    • ast_safe_sleep(chan, 10000)
    • ast_moh_stop(chan);
  • static int moh1_exec(struct ast_channel *chan, void *data)
    • ast_moh_start(chan, NULL)
    • res = ast_safe_sleep(chan, atoi(data) * 1000);
    • ast_moh_stop(chan);
  • static int moh2_exec(struct ast_channel *chan, void *data)
    • strncpy(chan->musicclass, data, sizeof(chan->musicclass) - 1);
  • static int moh3_exec(struct ast_channel *chan, void *data)
    • ast_moh_start(chan, class)
  • static int moh4_exec(struct ast_channel *chan, void *data)
    • ast_moh_stop(chan);
  • static int init_classes(int reload)
    • load_moh_classes(reload)
  • static int load_moh_classes(int reload)
    • cfg = ast_config_load("musiconhold.conf");
    • moh_register(class, reload);
  • static int moh_register(struct mohclass *moh, int reload)
    • if mode mp3, mp3nb, quietmp3, quietmp3nb, httpmp3, custom
      • ast_pthread_create(&moh->thread, NULL, monmp3thread, moh)
  • static void *monmp3thread(void *data)
    • class->srcfd = spawn_mp3(class)
  • static int spawn_mp3(struct mohclass *class)
    • execv(argv0, argv); mpg123
    • execv(LOCAL_MPG_123, argv);
    • execv(MPG_123, argv);
    • execvp("mpg123", argv);
* pbx.c
  • int ast_register_application(const char *app, int (*execute)(struct ast_channel *, void *), const char *synopsis, const char *description)
* channel.c
void ast_install_music_functions(int (*start_ptr)(struct ast_channel *, char *),
                                                                 void (*stop_ptr)(struct ast_channel *),
                                                                 void (*cleanup_ptr)(struct ast_channel *)
                                                                 )
{
        ast_moh_start_ptr = start_ptr;
        ast_moh_stop_ptr = stop_ptr;
        ast_moh_cleanup_ptr = cleanup_ptr;
}



sponsored by andamiro
sponsored by cdnetworks
sponsored by HP

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2008-07-28 15:30:18
Processing time 0.0362 sec