This module stream files from a directory and multiple channels connected to the same stream will hear the same (looped) file playback .. similar to a shoutcast stream. Useful for Music-on-hold type scenarios.
This comes from the sample local_stream.conf.xml file. It demonstrates what all is possible in a given local stream. Note that music on hold is really just a local stream for the directory where the default music files are stored:
- name - The name of the stream, used in the dialplan, i.e. local_stream://<name>
- path - Path to the directory containing the sound files for this stream
- rate - the sampling rate (in Hertz) of the sound files
- shuffle - when set to true will randomize the order in which the sound files are played
- channels - number of channels in the sound files (usually "1" but stereo would be "2")
- interval - number of milliseconds of silence in between sound files
- timer-name - which timer to use (do not change unless you know what you are doing)
- chime-list - comma-separated list of "break-in" sound files to play
- chime-freq - number of seconds in between the start of each "break-in"
- chime-max - max number of "break-in" attempts
Using a playlist
You can stream a playlist by placing a file call 'moh.loc' in the directory path folder. For example, if your stream is configured like:
You can place a file called 'moh.loc' in '/var/lib/moh/playlist1' which contains a list of file paths like so:
This configuration will play the files listed in 'moh.loc'
It is possible to play a shoutcast stream in local_stream.
For details on how to set it up please see mod_shout#Using_shoutcast_stream_for_MOH
How do I call it?
Call it from the dialplan as follows:
To set for legs/bridges etc:
There is a "timeout=" parameter expressed in milliseconds that limits the duration of the local_stream played. This is useful when multiple instances of local_stream is needed in a single statement.
In this example, an incoming call rings local extensions, if no one answers, cell phones are bridged into the call. It would be helpful to let the caller know the progress of the call. As soon as the bridge command starts we want the caller to hear:
- Custom greeting to caller based on caller ID. 3 seconds.
- Music for 20 seconds <--- If we use US Ring, some callers are confused by a voice followed by ringing, so music is better.
- Custom 2nd greeting telling caller to please wait while call is forwarded. 3 seconds. Cell phones start ringing due to leg_delay_start=23 in bridge
- Music for 20 seconds
If the call times out: please leave a message, vm, emailed, etc.....
If a single bridge was used to ring extenstions, then cell phones, we would need a single early media stream that would play steps 1 through 4:
Without the timeout, the first moh would play until the originate_timeout occurred and the caller would never hear foo2 or anything else remaining in the ringback.
Safely reloads a local_stream configuration using the local_stream.conf.xml
Please note, the reload is not instantaneous. In order to not drop calls, the reload will wait until a streaming file is done playing and the stream is not in use. In the case that the streaming file is done playing and the stream is in use, a partial reload will take place. Once the stream is not in use and a file is done playing, the full reload will take place.
- On a partial reload, the following parameters are reloaded from local_stream.conf.xml:
- On a full reload, the ALL parameters are reloaded from local_stream.conf.xml
Stops and unloads a local_stream.
In order to not drop calls the 'stop' action will be queued and fire once the local_stream is not in use.
Instantly starts a new local_stream. The stream must be configured in local_stream.conf.xml
Shows status of local_streams. If stream_name is provided, it will display details about the stream.
The API changed in 1.6, earlier in 1.4 it was:
hup_local_stream => local_stream hup <stream>
reload_local_stream => local_stream reload <stream>
stop_local_stream => local_stream stop <stream>
start_local_stream => local_stream start <stream>
show_local_stream => local_stream show <stream> [as xml]
What file formats can be in directory?
Q: Do the files need to be of a certain format (eg, wav) and/or a certain sample rate / bit width?
A. It can handle any format, bitrate, and bit width supported by sndfile (See: FreeSwitch Dependencies), but optimal performance will be achieved by resampling to PCM encapsulated in a WAV container at the native bitrate and bit width of the channel. For example, 8kHz, 16kHz, and 32kHz.
What's this I keep seeing about a leaking stream handle?
Q: I keep seeing an error like this: "Leaking stream handle!" - what should I do?
A: You should not panic. This is more of an "oh by the way" warning than a serious error. Anthony had this to say on a ML thread on the subject:
A: A normal file handle waits for you to read, the local_stream one has a buffer feeding it from a master stream, so when you don't read from it, you lose the audio because the music is playing on without you even when you pause a playlist .
In other words don't sweat it.