This document is a work in progress. It is incomplete and untested.
This documentation is for Release 3.0.0.
These instructions provide a recipe for configuring Avalon to use Adobe Media Server (AMS) for content streaming.These instructions assume that the Apache server used is the one installed with AMS. If a separate Apache is used, make changes accordingly.
This example uses the default AMS installation location: /opt/adobe/ams
Configuring AMS
# 1. Download the Avalon configuration for AMS $ wget -o avalon-vod.zip https://github.com/avalonmediasystem/avalon-vod/archive/master.zip $ unzip avalon-vod.zip # 2.
Configuration changes within AMS:
/opt/adobe/ams/Apache2.2/conf/httpd.conf
Include avalon.conf by adding this line at the end:
Include conf/avalon.conf
/opt/adobe/ams/Apache2.2/conf/avalon.conf
<IfModule mod_disk_cache.c> CacheEnable disk /avalon </IfModule> RewriteEngine on RewriteLock /tmp/avalon_rewrite_lock RewriteMap avalon_auth prg:/opt/adobe/ams/Apache2.2/bin/avalon_auth RewriteCond %{QUERY_STRING} audio-only=true RewriteCond %{QUERY_STRING} codec=aac RewriteCond %{QUERY_STRING} token=([^&]+) RewriteRule ^/avalon/(.+).m3u8$ /avalon/audio-only-aac/$1.m3u8?token=%1 [R=301,L] RewriteCond %{QUERY_STRING} audio-only=true RewriteCond %{QUERY_STRING} token=([^&]+) RewriteRule ^/avalon/(.+).m3u8$ /avalon/audio-only/$1.m3u8?token=%1 [R=301,L] RewriteCond %{QUERY_STRING} token=([^&]+) RewriteRule ^/avalon ${avalon_auth:%{REQUEST_URI}?token=%1} RewriteCond %{REQUEST_URI} !(.+).ts$ RewriteCond %{QUERY_STRING} !token= RewriteRule ^/avalon - [F] RewriteRule ^/avalon/forbidden - [F] <Location /avalon> HLSHttpStreamingEnabled true HLSMediaFileDuration 2000 HttpStreamingContentPath "../webroot/avalon" HLSFmsDirPath ".." HLSJITConfAllowed true HLSM3U8MaxAge 86400 HLSTSSegmentMaxAge 86400 HLSMetaMaxAge 3600 Options -Indexes FollowSymLinks </Location>
/opt/adobe/ams/Apache2.2/bin/avalon_auth
#!/bin/bash auth_url=`grep AVALON.AUTH_URL /opt/adobe/ams/conf/ams.ini | cut -d '=' -f 2 | sed 's/^ *//g'` while read uri; do saveIFS=$IFS IFS='=&' parm=($uri) IFS=$saveIFS raw=`curl -s "${auth_url}.txt?token=${parm[1]}"` resp="${raw//[[:space:]]/}" valid=`echo ${parm[1]} | grep ^${resp}` if [ -n "${valid}" ] && [ -n "${resp}" ]; then echo $uri else echo '/avalon/forbidden' fi done
/opt/adobe/ams/conf/ams.ini
Add avalon substitution variables at the end:
AVALON.STREAM_PATH = /opt/adobe/ams/webroot/avalon AVALON.AUTH_URL = http://localhost/authorize
Setup the Avalon application
/opt/adobe/ams/applications/avalon/Application.xml
<Application> <JSEngine> <ApplicationObject> <config> <avalonAuthUrl>${AVALON.AUTH_URL}</avalonAuthUrl> </config> </ApplicationObject> </JSEngine> <StreamManager> <VirtualDirectory> <!-- Specifies application specific virtual directory mapping for recorded streams. --> <Streams>/;${AVALON.STREAM_PATH}</Streams> </VirtualDirectory> </StreamManager> <!-- Settings specific to runtime script engine memory --> <ScriptEngine> <!-- This specifies the max size (Kb.) the runtime can grow to before --> <!-- garbage collection is performed. --> <RuntimeSize>20480</RuntimeSize> </ScriptEngine> <Client> <Bandwidth> <!-- Specified in bytes/sec --> <ServerToClient>2500000</ServerToClient> <!-- Specified in bytes/sec --> <ClientToServer>2500000</ClientToServer> </Bandwidth> <MsgQueue> <Live> <!-- Drop live audio if audio q exceeds time specified. time in milliseconds --> <MaxAudioLatency>2000</MaxAudioLatency> <!-- Default buffer length in millisecond for live audio and video queue. --> <MinBufferTime>2000</MinBufferTime> </Live> <Recorded> <!-- Default buffer length in millisecond for live audio and video, value cannot be set below this by Flash player. --> <MinBufferTime>2000</MinBufferTime> </Recorded> <Server> <!-- Ratio of the buffer length used by server side stream --> <!-- to live buffer. The value is between 0 and 1. To --> <!-- avoid break up of audio, the ratio should not be more --> <!-- than 0.5 of the live buffer. --> <BufferRatio>0.5</BufferRatio> </Server> </MsgQueue> </Client> </Application>
/opt/adobe/ams/applications/avalon/main.asc
/* * Avalon Media System authenticated RTMP streaming application for * Adobe Media Server. * * Add the following keys to your <ams_install_home>/conf/ams.ini: * AVALON.AUTH_URL = http://localhost/authorize * AVALON.STREAM_PATH = /opt/adobe/ams/webroot/avalon */ application.onAppStart = function() { // Logging trace("Starting Avalon Streaming app..."); this.avalonAuthUrl = application.config.avalonAuthUrl; trace("Requests will be authenticated against " + this.avalonAuthUrl); trace("...loading completed."); } application.onConnect = function( p_client, p_autoSenseBW ) { //Add security here p_client.writeAccess = ""; // prevents creating shared object or live streams. p_client.readAccess = ""; // no access by default var xhttp = new LoadVars(); xhttp.decode(p_client.uri.split("?")[1]); if (!xhttp.hasOwnProperty('token')) { trace('Missing token in request.'); application.rejectConnection(p_client); return false; } var authed = false; xhttp.onHTTPStatus = function(status) { trace('Received ' + status); switch (status) { case 202: trace("Authorized") authed = true; break; case 403: trace("Unauthorized") authed = false; break; }; } xhttp.onLoad = function() { if (authed) { // grant access to the specific mediapackage directories authorized p_client.readAccess = xhttp['authorized']; } // Accept the connection no matter what; the denial will happen when the stream is requested application.acceptConnection(p_client); if (p_client.readAccess.length > 0) { trace("Client can read " + p_client.readAccess); } else { trace("Client cannot read anything"); } if (p_autoSenseBW) p_client.checkBandwidth(); else p_client.call("onBWDone"); } var authUrl = application.avalonAuthUrl; trace('Authorizing against ' + authUrl); xhttp.addRequestHeader('accept','application/x-www-urlform-encoded') xhttp.sendAndLoad(authUrl,xhttp); return null; }
Configure Matterhorn
1. /usr/local/matterhorn/etc/config.properties
org.opencastproject.server.url=http://<host>:18080 . . org.opencastproject.streaming.url=rtmp://<host>/avalon org.opencastproject.hls.url=http://<host>/streams org.opencastproject.streaming.directory=/var/avalon/rtmp_streams org.opencastproject.hls.directory=/var/avalon/hls_streams . . org.avalonmediasystem.avalon.url=http://<host>/
Configure Avalon
1./var/www/avalon/shared/avalon.yml
streaming: server: :generic # or :adobe rtmp_base: rtmp://<host>/avalon/ http_base: http://<host>:3000/streams/ stream_token_ttl: 20 #minutes
Other Resources
https://github.com/avalonmediasystem/avalon-vod