Early Media and Music on Hold

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.
时间: 2024-11-06 07:45:25

Early Media and Music on Hold的相关文章

linphone3.4.0代码分析

主要类型定义: 1.LinphoneCoreVTable /** * This structure holds all callbacks that the application should implement. * None is mandatory. **/ typedef struct _LinphoneVTable{ LinphoneGlobalStateCb global_state_changed; /**<Notifies globlal state changes*/ Lin

183SDP回铃设置步骤

第一步:在vos上面的对接网关上设置: 补充设置→协议→远端回铃方式 选择183 Session Progress + SDP 第二步:在奥科中继里面配置 Configuration→VoIP→SIP Definitions→General Parameters 需要修改的几个选项: Enable Early Media                     设置为:Enable Play Ringback Tone to IP 和 Play Ringback tone to tel    

android-NGN-stack中文文档

前言 android-ngn-stack是android2.x(或更高版本)NGN(下一代网络)软件栈.ngn基于doubango框架.doubango是目前世界上最先进的开源3GPP IMS/RCS嵌入式和桌面系统架构.其主要目的就是提供一个开放源码为开发者构建自己的VoIP应用.这一框架提供了一组独特的特征,从音频/视频呼叫,内容共享,消息,会议增强通信社交存在.所有这些功能都是按照GMSA RCS,3GPP IMS或VoLTE标准实施. 介绍 该文档由(Doubango电信)提供,以帮助开

Linphone之Mediastreamer2分析

最近在算法移植中涉及到Linphone,于是开始研究Linphone.首先在Ubuntu下编译成功Linphone,然后开始研究源码,结合网上的资料,写了下面的学习笔记,其中参考的网上资料,在文中添加上链接. Linphone之Mediastreamer2分析 一.Linphone中流媒体处理结构 分为2个部分MEDIASTREAMER2和ORTP MEDIASTREAMER2**负责媒体流的处理**,mediastreamer2是一个功能强大且小巧的流引擎,专门为视频电话应用而开发的.为lin

转:SIP相关的RFC文档索引

索引来源于http://www.packetizer.com/ipmc/sip/standards.html SIP Standards Core SIP Documents RFC Document Title RFC 2543 SIP: Session Initiation Protocol (obsolete) RFC 3261 SIP: Session Initiation Protocol RFC 3262 Reliability of Provisional Responses RF

180还是183?

在FreeSWITCH中怎么配置回180还是183,是一个经常被问到的问题.然而,答案却远没有你想象中的那么简单. 要明白怎么配置,首先你需要明白180和183的来龙去脉.另外,你自己还要知道你要干什么. “什么?我提的问题我当然知道我要干什么!” 也许你会这样咆哮,也许你真的知道你要干什么,但是,我不知道.所以,在你得到有效的回答之前,你得先学会让我知道. 好了,先不争论这个,我们来说说什么是180和183. 在SIP通信中,所有1开头的响应叫临时响应,常见的有100,180和183.这些响应

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 monotonically increasing ticket counter and waits until a memory location contains a value equal to the ticket value, yielding the processor between polls of

a new Webcam Api Tutorial in C++ for Windows(Windows Media Foundation)--WMF

Sample source code: http://pan.baidu.com/s/1o60VAEA Foword from: http://www.dreamincode.net/forums/topic/347938-a-new-webcam-api-tutorial-in-c-for-windows/page__st__0%26 Well, A long time ago I introduced a Webcam Tutorial. It was for Video For Windo

Your Cosmetic Bag Is Going To Hold Out No Matter What Situation You Are In

Therefore, a person who applies for a longer time than other bags? Other materials. In general, heavy canvas material is resistant to water and a great location. But it would be better to make it waterproof for complete protection of the entire portf