Early media refers to any media that is played to the initial caller’s phone before the remote party has picked up the phone. That “brrrrrrrring!” noise you hear before the person you called has picked up the phone is an example of early media.

That ringing noise is not actually the other person’s phone, but a tone that’s generated by the system that’s setting up the call. Theoretically that ring can be anything, including music or audio files.

Asterisk can set up calls while generating early media. In fact, the “r” flag in the Dial command tells asterisk to generate the necessary tones for the “rrrrring!” audio.

exten => s,1,Dial(SIP/flowroute/16466429000,30,r);  <--- that "r" flag will generate ringing while Asterisk is setting up the call.

One of the great things about Asterisk is that it tries to “abstract” out the notion of a phone call. In other words, virtually all of Asterisk’s commands work the same way regardless of whether the actual call was SIP, IAX, H323, SS7, or any other crazy VoIP protocol.

However, this doesn’t work perfectly in practice. Each VoIP protocol behaves in slightly different ways, and sometimes that conflicts with Asterisk commands. SIP and IAX will allow early media but others may not. Also, some VoIP providers will block early media and replace it with their own.

There are a couple of ways to use early media. The first way is to play a message before initiating the call. An example of this would be a message that says “please stay on the line while I complete that call” followed by ringing the other caller’s phone. The other way is to basically replace the preset ringing tone with an audio stream. An example might be to play music to the initial caller as the remote phone is ringing. As soon as the remote party picks up the phone the song would stop.

How to play early media to a caller before ringing the phone:

exten => _1NXXNXXXXXX,1,Progress()
exten => _1NXXNXXXXXX,n,Playback(demo-abouttotry,noanswer)
exten => _1NXXNXXXXXX,n,Dial(SIP/flowroute/${EXTEN},30,r)
  • Progress() will let the phone system know that we are about to forward the call to another line. This is important for SIP calls, but may be optional for IAX calls. Just to be on the safe side, use it whenever you are about to generate early media.
  • Playback() needs to include the “noanswer” flag so that it won’t automatically answer the channel when it plays the media. The remote phone won’t ring until this audio file has fully played.
  • Dial() works as you would expect.

How to play early media to a caller while ringing the phone:

exten => s,1,Progress()
exten => s,n,Dial(IAX2/ck987_iax,30,m(ck987_moh))
  • Progress() will let the phone system know that we are about to forward the call to another line. This is important for SIP calls, but may be optional for IAX calls. Just to be on the safe side, use it whenever you are about to generate early media.
  • Dial() uses the “m(music_on_hold_class)” flag to play back audio while generating the call. See below for information on how to set up Music On Hold.

More Information on Early Media

Music On Hold

The most obvious use for Music on Hold (or “moh”) is to give a caller something to listen to while they are on hold or in a queue. You can set up various Music On Hold “classes” in your musiconhold.conf files. Here’s what mine looks like:

[ck987_moh]
mode=files
directory=/home/ck987/asterisk_sounds/moh
sort=random
  • mode=files means that this moh class will use audio files as its source.
  • directory=/home/ck987/asterisk_sounds/moh tells asterisk to play any file that’s in this directory
  • sort=random will randomly play a file in this directory. The other option would be “alpha” which would go through the list in alphabetical order.

In your dialplan, you can set a channel’s music on hold like this:

exten => s,n,Set(CHANNEL(musicclass)=ck987_moh); <---replace ck987_moh with your moh class.

If a SIP or IAX phone is placed on hold, the other caller should start to hear the audio defined by the active moh class. There is a MusicOnHold() command which will force Music On Hold to start, but you really should avoid this command. If you want to play an audio file, use Playback or Background. Music on Hold is a service that other commands can use. For example, Music On Hold can be used to play “early media” to a phone while it tries to connect another phone. See above for more info.

ADVANCED: Streaming External Audio for Music On Hold
Don’t try this unless it all makes sense to you!
A music on hold class can accept properly formatted audio streams as input. The audio must be 8000 hz, 16 bit, mono, PCM (uncompressed). The data is streamed through “Standard Out” (STDOUT).

When you make a class that uses an external process and do “module reload”, it will start the process at that exact moment. This means that it is sitting in the background, using up resources on the system. That’s fine for a few streams, but may become an issue if there’s a lot of them.

Here’s a Music On Hold class where I use an app called mpg123 to reformat and output the NPR Radio MP3 stream. Feel free to use this class in your own dialplans:

[ck987_stream]
mode=custom
application=/usr/bin/mpg123 -q -r 8000 -0 -s http://nprdmp.ic.llnwd.net/stream/nprdmp_live01_mp3
  • -q stops the app from listing the name of the stream at the beginning of playback
  • -r 8000 resamples the audio to 8000Hz
  • -0 uses only the “left” channel, which is fine since we need mono and NPR isn’t in stereo. (-m would mix down a stereo stream to mono.)
  • -s sends the data to STDOUT
  • http://nprdmp.ic.llnwd.net/stream/nprdmp_live01_mp3 is the URL for National Public Radio’s realtime MP3 stream.

Early Media and Music on Hold的更多相关文章

  1. Latest China Scam: I've Been Arrested in the Brothel Crackdown!

    Latest China Scam: I've Been Arrested in the Brothel Crackdown! If the sex industry is fastest to se ...

  2. linphone3.4.0代码分析

    主要类型定义: 1.LinphoneCoreVTable /** * This structure holds all callbacks that the application should im ...

  3. SIP UserAgent (B2BUA client)——linphonec

    1.linphone编译 linphone一般用在android/ios/windows/mobile上,但是没有图形界面的linphonec命令行程序用在资源紧张的硬件平台上也跟pjsip命令行一样 ...

  4. Rx

    more detailed in WIKI's document SDP :session description protocal book AAA AA-Answer 鉴权授权应答AAR AA-R ...

  5. ICE学习笔记 -- RFC 5245

    RFC 5245 ICE   1, offer/answer model 2, ICE Step:    1) 产生候选地址(1.公网 2.NAT反射 3.Relay转发地址) Generate ca ...

  6. 转:SIP相关的RFC文档索引

    索引来源于http://www.packetizer.com/ipmc/sip/standards.html SIP Standards Core SIP Documents RFC Document ...

  7. Efficient ticket lock synchronization implementation using early wakeup in the presence of oversubscription

    A turn-oriented thread and/or process synchronization facility obtains a ticket value from a monoton ...

  8. 3 Financial Services Social Media Success Storie

    As financial services firms step-up their use of social media, we’ve been looking for some early suc ...

  9. Early 80386 CPUs

    Assembling a detailed and accurate history of the 80386, including a complete listing of all the &qu ...

随机推荐

  1. jQuery 获取DOM元素

    (function (window){ var arr=[]; var VP=function(selector,context){ return new VP.fn.init(selector,co ...

  2. Cloudera Manager 和 CDH 4 终极安装

    转载请注明出处:http://www.cnblogs.com/thinkCoding/p/3567408.html 系统环境 操作系统:CentOS 6.5 Cloudera Manager 版本:4 ...

  3. P13在O(1)时间内删除链表结点

    package offer; //在 O(1)时间删除链表结点 public class Problem13 { public static void main(String[] args) { Li ...

  4. Java获取系统属性及环境变量

    当程序中需要使用与操作系统相关的变量(例如:文件分隔符.换行符)时,Java提供了System类的静态方法getenv()和getProperty()用于返回系统相关的变量与属性,getenv方法返回 ...

  5. js错误: Unexpected number in JSON at position 2792 value里面有双引号怎么解决

    源头  出现这个报错提示,大家从错误就可以看的出来,这就是json的错误,一般来说都是json格式出现了错误,本人遇到比较多的情况就是json字符串里面出现了一些会影响json格式的符号,这次出现这个 ...

  6. android 5.0 默认水波纹背景属性,可设置不论什么View

    actionBarItemBackground   5.0以上超出边界圆形水波纹 selectableItemBackground  5.0以上边界内圆形水波纹 这两个属性在5.0下面是默认的灰色效果 ...

  7. Idftp.DirectoryListing 里面的内容为什么会是空的呢?(转)

    最近在项目中要用到FTP上传,用的是delphi的IdFTP控件,用IdFtp.List(list),发现List里面有内容,可 是到IdFtp.DirectoryListing.Items[iCou ...

  8. Android错误之Location of the Android SDK has not been setup in the preferences

    解决的方法:打开Help-Install new software,更新文件就可以,这时国内的朋友就须要FQ了,详细有代理,能够网上自行搜索.

  9. Mysql 的存储引擎,myisam和innodb的区别。

    简单的表达. MyISAM 是非事务的存储引擎. innodb是支持事务的存储引擎. innodb的引擎比较适合于插入和更新操作比较多的应用 而MyISAM 则适合用于频繁查询的应用 MyISAM - ...

  10. KVC基本使用

    首先,创建两个类.person类和book类.如图: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/ ...