Asterisk 1.8 MusicOnHold() with MP3 files doesn't work

My Asterisk 1.8.0 (released) installation will not play MP3 files. This same installation will play 16-bit, Monaural, 8Ksample/Sec WAV files. It appears to me after spending many hours that the feature to play MP3 files is broken, or non-existent.

Anyone know how to make Asterisk 1.8.0 play MP3 files? The “mode” options in the musiconhold.conf file strongly suggest this should be possible…

; valid mode options: ; quietmp3 -- default ; mp3 -- loud ; mp3nb -- unbuffered ; quietmp3nb -- quiet unbuffered ; custom -- run a custom application ; files -- read files from a directory in any Asterisk supported format

Here is what I have/tried:

/var/lib/asterisk/mohmp3 # ll total 36666 -rw-r--r-- 1 root root 2474709 2008-03-23 21:17 BeachBoys-CaliforniaGirl.mp3 -rw-r--r-- 1 root root 2597060 2008-03-23 21:17 BeachBoys-DontWorryBaby.mp3 -rw-r--r-- 1 root root 2705228 2008-03-23 21:17 BeachBoys-GodOnlyKnows.mp3 -rw-r--r-- 1 root root 2172845 2008-03-23 21:17 BeachBoys-InMyRoom.mp3 -rw-r--r-- 1 root root 3449687 2008-03-23 21:17 BeachBoys-Kokomo.mp3 -rw-r--r-- 1 root root 3512073 2008-03-23 21:17 BeachBoys-SloopJohnB.mp3 -rw-r--r-- 1 root root 3070653 2008-03-23 21:17 BeachBoys-WouldntItBeNice.mp3

extensions.conf:

exten => 27,1,Answer
exten => 27,2,MusicOnHold(default)
exten => 27,3,Hangup

musiconhold.conf:

[default]
directory=/var/lib/asterisk/mohmp3
mode=mp3

CLI> moh reload
CLI> moh show files
Class: default
File: /var/lib/asterisk/mohmp3/BeachBoys-SloopJohnB
File: /var/lib/asterisk/mohmp3/BeachBoys-CaliforniaGirl
File: /var/lib/asterisk/mohmp3/BeachBoys-DontWorryBaby
File: /var/lib/asterisk/mohmp3/BeachBoys-Kokomo
File: /var/lib/asterisk/mohmp3/BeachBoys-WouldntItBeNice
File: /var/lib/asterisk/mohmp3/BeachBoys-InMyRoom
File: /var/lib/asterisk/mohmp3/BeachBoys-GodOnlyKnows
CLI> moh show classes
Class: default
Mode: mp3
Directory: /var/lib/asterisk/mohmp3
Format: slin

After dialing the MOH -test- extension 27, I get the following on the console, and no sound:

== Using SIP RTP TOS bits 184 == Using SIP RTP CoS mark 5 -- Executing [27@home:1] Answer("SIP/LINE2-0000000a", "") in new stack -- Executing [27@home:2] MusicOnHold("SIP/LINE2-0000000a", "default") in new stack -- Started music on hold, class 'default', on SIP/LINE2-0000000a [Dec 6 19:41:25] WARNING[26528]: file.c:648 ast_openstream_full: File /var/lib/asterisk/mohmp3/BeachBoys-SloopJohnB does not exist in any format [Dec 6 19:41:25] WARNING[26528]: res_musiconhold.c:326 ast_moh_files_next: Unable to open file '/var/lib/asterisk/mohmp3/BeachBoys-SloopJohnB': No such file or directory [Dec 6 19:41:25] WARNING[26528]: file.c:648 ast_openstream_full: File /var/lib/asterisk/mohmp3/BeachBoys-CaliforniaGirl does not exist in any format [Dec 6 19:41:25] WARNING[26528]: res_musiconhold.c:326 ast_moh_files_next: Unable to open file '/var/lib/asterisk/mohmp3/BeachBoys-CaliforniaGirl': No such file or directory [Dec 6 19:41:25] WARNING[26528]: file.c:648 ast_openstream_full: File /var/lib/asterisk/mohmp3/BeachBoys-DontWorryBaby does not exist in any format [Dec 6 19:41:25] WARNING[26528]: res_musiconhold.c:326 ast_moh_files_next: Unable to open file '/var/lib/asterisk/mohmp3/BeachBoys-DontWorryBaby': No such file or directory [Dec 6 19:41:25] WARNING[26528]: file.c:648 ast_openstream_full: File /var/lib/asterisk/mohmp3/BeachBoys-Kokomo does not exist in any format [Dec 6 19:41:25] WARNING[26528]: res_musiconhold.c:326 ast_moh_files_next: Unable to open file '/var/lib/asterisk/mohmp3/BeachBoys-Kokomo': No such file or directory [Dec 6 19:41:25] WARNING[26528]: file.c:648 ast_openstream_full: File /var/lib/asterisk/mohmp3/wav does not exist in any format [Dec 6 19:41:25] WARNING[26528]: res_musiconhold.c:326 ast_moh_files_next: Unable to open file '/var/lib/asterisk/mohmp3/wav': No such file or directory [Dec 6 19:41:25] WARNING[26528]: file.c:648 ast_openstream_full: File /var/lib/asterisk/mohmp3/BeachBoys-WouldntItBeNice does not exist in any format [Dec 6 19:41:25] WARNING[26528]: res_musiconhold.c:326 ast_moh_files_next: Unable to open file '/var/lib/asterisk/mohmp3/BeachBoys-WouldntItBeNice': No such file or directory [Dec 6 19:41:25] WARNING[26528]: file.c:648 ast_openstream_full: File /var/lib/asterisk/mohmp3/BeachBoys-InMyRoom does not exist in any format [Dec 6 19:41:25] WARNING[26528]: res_musiconhold.c:326 ast_moh_files_next: Unable to open file '/var/lib/asterisk/mohmp3/BeachBoys-InMyRoom': No such file or directory [Dec 6 19:41:25] WARNING[26528]: file.c:648 ast_openstream_full: File /var/lib/asterisk/mohmp3/BeachBoys-GodOnlyKnows does not exist in any format [Dec 6 19:41:25] WARNING[26528]: res_musiconhold.c:326 ast_moh_files_next: Unable to open file '/var/lib/asterisk/mohmp3/BeachBoys-GodOnlyKnows': No such file or directory -- Stopped music on hold on SIP/LINE2-0000000a == Spawn extension (home, 27, 2) exited non-zero on 'SIP/LINE2-0000000a'

Howdy,

Did you compile format_mp3 into your Asterisk build?

/usr/lib/asterisk/modules/format_mp3.so

Cheers

Why not pre-convert the MP3 files? The quality will be the same and you will put much less load on the machine.

For anyone else scouring the net (as I did) to solve this problem in the 1.8.0 release, Malcomd is right, and here is what I needed to know;

  1. Run “make menuselect”
  2. Select “Add-ons”
  3. Make sure “format_mp3” is selected: [*]format_mp3
  4. Use the “Menu Select” command ‘x’ to Save and Quit
  5. Run “contrib/scripts/get_mp3_source.sh” <-- IMPORTANT or you won’t have MP3 source to compile and your build will fail!
  6. Run “make install”

You will now have MP3 support in Asterisk in addition to the default 16-bit, monaural, 8KHz sample rate WAV file format.

This didn’t stop me from making more mistakes in the “/etc/asterisk/musiconhold.conf” file triggering bugs in the code https://issues.asterisk.org/view.php?id=18434. Here is what works;

musiconhold.conf

[code][default]
directory=mohdefault
mode=files
random=yes

[mp3]
mode=files
directory=mohmp3
random=yes
[/code]

The “directory” referred to is a subdirectory in “/var/lib/asterisk”. DO NOT USE ABSOLUTE PATHS {starting with /} as the bug I triggered will show up and Asterisk will report it isn’t finding the files, even though “moh show files” will lead you to think it has.

extensions.conf

[code]exten => 27,1,Answer
exten => 27,2,MusicOnHold(default)
exten => 27,3,Hangup

exten => 28,1,Answer
exten => 28,2,MusicOnHold(mp3)
exten => 28,3,Hangup[/code]

Now put your MP3 files in /var/lib/asterisk/mohmp3/, dial “28” and you should hear your MP3 files play.

Put your 16-bit, monaural, 8KHz sample rate WAV files in /var/lib/asterisk/moh/, dial 27, and you should hear your WAV files play.

And hopefully the Asterisk team will get that pesky Bug 0018434 fixed so dumb configuration errors don’t bring Asterisk down in flames. Even with a working configuration, Asterisk still crashes as described in bug report 18434, but does otherwise work.

david55- Care to elaborate on what “pre-convert” means and how to accomplish “pre-convert”?
I tried various permutations of
"lame -decode -b8 -a BeachBoys-SloopJohnB.mp3 BeachBoys-SloopJohnB.wav" and kept getting Asterisk messages telling me it didn’t get what it expected and wouldn’t play the files. I also tried
"sox -r 8000 -u -b -c 1 BeachBoys-SloopJohnB.mp3 BeachBoys-SloopJohnB.wav" with no success.

You need to use the same options as would be used for an on the fly conversion.

Asterisk .wav files are 16 bit sample, 8kHz sampling rate, signed linear files. If you use sox, you need to use options to force those attributes. I don’t have an mp3 file on a suitable machine, but I think you would want

There are some additional options which change the trade off between quality and processing time, but, as you will end up with G.711, or worse, they are probably not worth investigating.

You do want the -c 1 option for sox also, as it forces it down to mono from what’s usually stereo.

I tried David55’s

and received the error
"sox stio: Failed reading `…/mohmp3/BeachBoys-Kokomo.mp3’: Do not understand format type: mp3"

The version of sox on my system reports “sox: v13.0.0”

It seems weird that “sox” which is supposed to read and write -many- popular formats, doesn’t know about mp3. The man page on my system says it should handle .mp3 input files. The sox executable I’m running comes from /usr/bin/sox. Now I’m confused.

Any other/further suggestions?

Not sure what the dependency for it is, but no problems using sox to go from mp3 to wav on an Ubuntu 10.10 system. shrug

Yeah, I tried downloading sox 14.3.1 source and installing… I also tried sox: SoX v14.1.0 under OpenSUSE11.1/64AMD and it also doesn’t know how to handle mp3 formats.

Anyone know how to do this conversion with LAME or LAME/SOX?

looks like sox will need some repair to run in my 64-bit environment:

gerty:/usr/local/src/sox-14.3.1 # make -s Making all in lpc10 Making all in libgsm Making all in src sox.c: In function ‘parse_effects’: sox.c:808: warning: passing argument 1 of ‘calloc’ with different width due to prototype sox.c:808: warning: passing argument 2 of ‘calloc’ with different width due to prototype sox.c:811: warning: passing argument 1 of ‘calloc’ with different width due to prototype sox.c:811: warning: passing argument 2 of ‘calloc’ with different width due to prototype sox.c: In function ‘open_output_file’: sox.c:1453: warning: passing argument 1 of ‘calloc’ with different width due to prototype sox.c:1453: warning: passing argument 2 of ‘calloc’ with different width due to prototype sox.c:1708:1: warning: embedding a directive within macro arguments is not portable sox.c:1710:1: warning: embedding a directive within macro arguments is not portable sox.c:1712:1: warning: embedding a directive within macro arguments is not portable sox.c: In function ‘parse_gopts_and_fopts’: sox.c:2201: warning: passing argument 1 of ‘calloc’ with different width due to prototype sox.c:2201: warning: passing argument 2 of ‘calloc’ with different width due to prototype sox.c:2202: warning: passing argument 1 of ‘calloc’ with different width due to prototype sox.c:2202: warning: passing argument 2 of ‘calloc’ with different width due to prototype sox.c:2211: warning: passing argument 1 of ‘calloc’ with different width due to prototype sox.c:2211: warning: passing argument 2 of ‘calloc’ with different width due to prototype hcom.c: In function ‘stopwrite’: hcom.c:436: warning: dereferencing type-punned pointer will break strict-aliasing rules mp3.c:60: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘const’ mp3.c:60: warning: ISO C does not allow extra ‘;’ outside of a function In file included from mp3.c:248: mp3-util.h: In function ‘write_comments’: mp3-util.h:41: warning: passing argument 2 of ‘p->id3tag_set_pad’ with different width due to prototype mp3.c: In function ‘get_id3v2_tag_size’: mp3.c:604: warning: passing argument 2 of ‘fread’ with different width due to prototype mp3.c:611: warning: passing argument 3 of ‘strncmp’ with different width due to prototype mp3.c: In function ‘rewrite_id3v2_tag’: mp3.c:650: warning: format ‘%d’ expects type ‘int’, but argument 2 has type ‘size_t’ mp3.c:672: warning: passing argument 3 of ‘fwrite’ with different width due to prototype mp3.c:673: warning: format ‘%d’ expects type ‘int’, but argument 2 has type ‘size_t’ mp3.c: In function ‘rewrite_tags’: mp3.c:725: warning: passing argument 2 of ‘fwrite’ with different width due to prototype mp3.c:725: warning: passing argument 3 of ‘fwrite’ with different width due to prototype make[1]: *** [libsox_la-mp3.lo] Error 1 make: *** [all-recursive] Error 1

Perhaps you need libmad?

Malcomd - you might be right, and I thank you for your observations, but I was trying to keep this from turning into yet another software development effort.

My read on this is sox is written for building and running a 32-bit environment, and isn’t yet ready for 64.

The real effort is to easily get my mp3 files playing on Asterisk in a stable (and very complex) OpenSUSE 10.3 64-bit AMD environment.

Asterisk lacks support for playing MP3 files, as evidenced by my needing to include “unsupported” mp3 code in the build. This unsupported code does mostly work, but keeps throwing “Bad Frame xxxxxxx” messages while playing in my AMD64 environment, and does eventually lock the Asterisk application… probably why the decision was made to leave the code in an unsupported state. I can’t argue with this, and can see good reasons why this might need to be as it is, for now. So Asterisk 1.8.0 Released isn’t able to play MP3 files… reliably, in all cases if we are quibbling.

Then david55 tried to offer assistance by suggesting the sox application. You say works in an Ubuntu 10.10 environment, though there is no mention if this is an AMD64 environment. So what we now know from this feedback is the options for sox are correctly identified, and may work for some users. My efforts show it doesn’t work in my environment because sox in my environment was built without mp3 support. So david55’s information is good, but I can’t use it.

For my installation, Asterisk can’t play MP3 files and there is no easy workaround for me. I won’t be able to play MP3 files. Since what I really need is a working Asterisk system, and the rest of my Asterisk 1.8.0 install appears to perform this function reliably and well, this is a small sacrifice. I’m sure someday, the priority to play/convert MP3 files will become a significant enough issue that effort will eventually be applied to resolve this issue, in Asterisk, for all platforms.

So unless there is another way for me to easily pre-convert MP3 files, I’ve hit the wall, and would be better off spending my time to make T.38 FAX work with SPA2100, SPA3000 units for my installation. Thank you all for your suggestions, effort, and time.

Howdy,

Good luck.

The environment I’m using is an amd64 environment.

MP3 decoding is left up to the user because inclusion of that into the mainline Asterisk source would preclude Asterisk’s inclusion into some distributions (Fedora) due to licensing concerns. Thus, you’ve got to build it yourself.

Cheers.

The reason MP3 might not work with sox is that it is a patented algorithm, so code to support it may not be freely distributable in the USA.

If you can convert MP3 to an equivalent lossless format using any tool, you can use sox to get to the 8khz, 16 bit, mono, signed linear needed by Asterisk.