一、安装:

1、复制lib/wms-plugin-mediacache.jarWowza安装目录下的[install-dir]/lib中。

2、复制conf/MediaCache.xmlwowza安装目录的[install-dir]/conf

3、创建目录[install-dir]/application/mediacache

4、创建目录[install-dir]/conf/mediacache并复制[install-dir]/conf/Applications.xml这个文件到这个新的目录中。

5、编辑新复制过来的Application.xml,做如下修改:

a、设置RTP/Authentication/PlayMethod为:none

b、添加下面的属性到MediaReader/Properties,修改后的应该如下面这样:

<MediaReader>

<Properties>

<Property>

<Name>randomAccessReaderClass</Name>

<Value>com.wowza.wms.plugin.mediacache.impl.MediaCacheRandomAccessReader</Value>

</Property>

<Property>

<Name>bufferSeekIO</Name>

<Value>true</Value>

<Type>Boolean</Type>

</Property>

</Properties>

</MediaReader>


6、修改[install-dir]/conf/Server.xml,添加下面内容到<ServerListeners>段中:

<ServerListener>

<BaseClass>com.wowza.wms.plugin.mediacache.impl.MediaCacheServerListener</BaseClass>

</ServerListener>


二、配置:

默认的MediaCache.xml文件被配置从HTTP源服务器转发内容。默认的配置文件默认假设Wowza服务器运行在32位系统上,并且配置使用1200M1.2GBJava heap siza,使用单一的机械硬盘用来做缓冲。


这个文件包含了附加的注释掉的调试建议,包括基于堆大小(heap size),磁盘速度和磁盘工艺。


下面我们将探索配置不同的配置选项。让我们出发看一下[install-dir]/conf/MediaCache.xml文件。



1MediaCache配置



WriterThreadPool/PoolSize

向缓冲系统写入media blocks的写入池中的线程数。

这个值应该设置为cpu核心数的2倍。


ReadAheadPool/PoolSizeReadAhead:理解为预加载)

设置多少读线程被用来在响应请求之前从源读取块。

这个read ahead system保持在播放期间来自源的比特流可以平稳的进入缓冲中。

这个参数的值应该设置为cpu的核心数。


MaxPendingWriteRequestSize

在块被等待写入存储前可以使用的存储bytes数。把它想象成为一个基于缓存的临时memory

该项的值的单位默认为bytes。也支持K (kilobytes), M (megabytes), G (gigabytes) or T (terabytes).


MaxPendingReadAheadRequestSize

read ahead的块等待被写入存储时能占用的内存bytes数。

该项的值的单位默认为bytes。也支持K (kilobytes), M (megabytes), G (gigabytes) or T (terabytes).



GCFrequencyGC频率)

The number of milliseconds between cache purging/pruning sessions. Based on time to live settings, items stored in the cache will be purged when they have not been used in a given period of time (maximum time to live) or if there is content waiting to enter the cache (minimum time to live).

缓冲清除/修改sessions之间的毫秒数。基于存活时间的设置,当在一段时间内(最大生存时间)没有被使用的、存储在缓冲中的项目将被清除或者如果有内容等待写入缓冲中(最小生存时间)缓冲中的项目将被清除或修改。


ContextMapperClass

预留


Properties

addFileExtensionIfNeeded属性

如果该属性值为true,流名称不包括文件扩展名文件扩展名将被加载基于流名称的前缀


urlEscapeStreamNameSpaces

如果该属性值为true,在流名称中的空格将在URL发送到源HTTP服务器前被避开(流名称中的空格将被忽略)(escaped:避开)


urlEscapeStreamNameAll

如果为true,全部的流名称将在URL发送到源HTTP服务器之前被避开(全部流名称被忽略)


2MediaCacheStores 配置

<MediaCacheStores>部分定义缓冲文件将被放置在哪里。你可以配置在一台机器上多个卷上配置多重缓冲来存储被缓冲的内容。你可以使用RAID技术在多块硬盘上创建一个存储。


Path

存储的路径。定义路径时务必使用正斜杠。缓冲文件将被存储在一个2层的目录结构中。


MaxSize

可以缓冲的最大数。该项的值的单位默认为bytes。也支持K (kilobytes), M (megabytes), G (gigabytes) or T (terabytes).


Level1FolderCount

在第一层存储缓冲的项目数


Level2FolderCount

在第二层存储缓冲的项目数


FileCount

可存储在每个2级目录中的项目数。例如,一级目录数设置为16,二级目录数设置为16FileCount设置为1000,那么16x16x1000 或者 256000个文件可以被存储在这个缓冲中。


WriteRate

内容可以被写到这个存储上的最大速率(每秒比特率)。控制写入速率,有助于控制内容写入的流量。因此他不会因为内容而淹没文件系统。内容会被放在缓冲外服务。

该项的值的单位默认为bytes。也支持K (kilobytes), M (megabytes), G (gigabytes) or T (terabytes).


WriteRateMaxBucketSize

这个值与WriteRate一致工作,用来控制写入速率的节流。这个值应该设置为WriteRate6倍。

该项的值的单位默认为bytes。也支持K (kilobytes), M (megabytes), G (gigabytes) or T (terabytes).


WriteRateFillFrequency

多长时间写入速率的控制机制被刷新(以毫秒为单位)。这个值与WriteRate一致工作,用来控制写入速率的节流,这个值应该设置为100.


Properties

Properties stored in the MediaCacheStore.getProperties() container.



3MediaCacheSources配置

<MediaCacheSource>部分定义了wowza服务器内容来源。这部分将将列举并解释设置,下一部分将包含更多的例子。


Name

给源一个简单的名称用来日志记录。这个名称不是用来控制流或内容寻址的。


BasePath and Prefix

BasePath Prefix设置是一起工作的,用来控制内容映射到来源配置

Prefix被用来映射流名称的源。

To restream the content prefix部分将被BasePath的值取代

例如:

如果设置Prefixcontent1/ BasePathhttp://那么

流名称:content1/mycoolvideo.flv


将从url重新取回:

http://mycoolvideo.flv


默认配置设置Prefixhttp/,设置BasePathhttp://。这使任何http://基础的内容可以高效以流的形式闯过存储。


BaseClass

目前有2MediaCacheSource实现可供选择:

com.wowza.wms.plugin.mediacache.impl.MediaCacheItemHTTPImpl - HTTP content

com.wowza.wms.plugin.mediacache.impl.MediaCacheItemFileImpl - File base (NFS, NAS…)


ReaderClass

现在没有使用


DefaultBlockSize

从源读取填充缓冲的数据的块大小

Values are expressed in bytes and the following units are supported K (kilobytes), M (megabytes), G (gigabytes) or T (terabytes).


MaxTimeToLive

在缓冲中不使用的项目的最大存活时间(毫秒)。存活时间在最后一个客户端停止查看内容后开始计时。如果在在存活时间内没有其他浏览者浏览该内容,该内容将从缓冲中清除。


MinTimeToLive

如果有项目等待进入缓冲,但是此时缓冲已满,保存在缓冲中未被使用的项目的最小保存时间(毫秒)。


ReadAhead and ReadAheadThreshold

如果ReadAhead设置为true,内容块将基于ReadAheadThreshold的百分比被预填充到缓冲中。如果设置为false,将不会有预加载发生。ReadAheadThreshold是当请求读取下一个块时控制的百分比。

例如:如果ReadAheadThreshold设置为50%,那么当任何内容读取超过内容块的一半的标记时,下一个块将排进读取队列中。


IsPassThru

现在不使用,但是将被用来控制管理缓冲中的内容,但是不驻留在缓冲中。


Properties

Properties存储在MediaCacheSource.getProperties()容器中。下面是一些有趣的有效的Properties(这些Properties在默认的conf/MediaCache.xml 文件中是被注释掉的,如果使用,取消注释。)


maxPoolSize

每个源HTTP TCP链接MediaCache系统创建一个池。请求使用这个HTTP TCP池发送到源。这个property控制这个池中的HTTP TCP连接数。


httpReadTimeout, httpConnectionTimeout, httpReadRetries

这些设置控制如何处理HTTP TCP连接这个源

httpConnectionTimeout是服务器等待TCP连接的毫秒数。

httpReadTimeout是服务器等待一个读请求被满足的毫秒数。

httpReadRetriesHTTP请求失败的重试次数。


httpSendBufferSize and httpReceiveBufferSize

这些设置为这个源控制低等级TCP缓存设置(发送和得到以bytes为单位的buffer大小)。


isAmazonS3 and s3BucketNameInDomain

This enables re-streaming from an Amazon S3 bucket. This property when set to true, instructs MediaCache to do extra URL formatting to properly address content on S3. The s3BucketNameInDomain property controls how the HTTP requests are formatted. If true, the domain name will be include the bucket name. If false, the bucket name will included as part of the HTTP path.


For example, if you set the BasePath value to http://s3.amazonaws.com/ and the Prefix to amazons3/ then MediaCache will treat stream names that start with the amazons3/ prefix as Amazon S3 content. The first path element of the stream name after the prefix is the bucket name and the rest of the elements are the path to the content. For example, if the stream name is: mp4:amazons3/mybucket/mypath/myfile.mp4

The bucket name is mybucket and the path to the content is mypath/myfile.mp4. Based on the s3BucketNameInDomain setting MediaCache will fetch the content from one of the following URLs:

If s3BucketNameInDomain is true:

http://mybucket.s3.amazonaws.com/mypath/myfile.mp4

If s3BucketNameInDomain is false:

http://s3.amazonaws.com/mybucket/mypath/myfile.mp4


awsSecretAccessKey and awsAccessKeyId

This enables re-streaming from an Amazon S3 bucket that is not publicly available. Set these properties to your Amazon S3 secret access key and key id to instruct MediaCache to properly sign the HTTP requests so that they are authenticated for access to protected content.


proxyHost, proxyPort and requestFullURL

如果设置了这个propertiesMediaCache系统将发送所有的HTTP请求到定义的代理。



三、配置实例


1


<MediaCacheSource>

<Name>http</Name>

<BasePath>http://</BasePath>

<Prefix>http/</Prefix>

<BaseClass>com.wowza.wms.plugin.mediacache.impl.MediaCacheItemHTTPImpl</BaseClass>

<ReaderClass></ReaderClass>

<DefaultBlockSize>262144</DefaultBlockSize>

<MaxTimeToLive>1200000</MaxTimeToLive>

<MinTimeToLive>600000</MinTimeToLive>

<ReadAhead>true</ReadAhead>

<ReadAheadThreshold>50</ReadAheadThreshold>

<IsPassThru>false</IsPassThru>

<Properties>

</Properties>

</MediaCacheSource>


这是一个简单的HTTP配置,可以试任何的基于HTTP的内容流通过MedaiCache系统。


例如,假如有一个媒体文件在这样一个URL

http://mycompany.com/media/sample.mp4


要播放这个流,使用下面的URL和流名称(see the How to play a video on demand file tutorial for more detailed information and example players):


To play using Adobe Flash player (RTMP)

Server: rtmp://[wowza-address]/mediacache

Stream: mp4:http/mycompany.com/media/sample.mp4


To play using Adobe Flash player (San Jose/Flash HTTP)

http://[wowza-ip-address]:1935/mediacache/_definst_/mp4:http/ mycompany.com/media/sample.mp4/manifest.f4m


To play using an Apple iOS device (Cupertino/Apple HTTP Live Streaming)

http://[wowza-ip-address]:1935/mediacache/_definst_/mp4:http/ mycompany.com/media/sample.mp4/playlist.m3u8


To play using Microsoft Silverlight (Smooth Streaming)

http://[wowza-ip-address]:1935/mediacache/_definst_/mp4:http/ mycompany.com/media/sample.mp4/Manifest


To play using RTSP/RTP player or device

rtsp://[wowza-ip-address]:1935/mediacache/_definst_/mp4:http/ mycompany.com/media/sample.mp4



2

<MediaCacheSource>

<Name>http1</Name>

<BasePath>http://mycompany.com/</BasePath>

<Prefix>http1/</Prefix>

<BaseClass>com.wowza.wms.plugin.mediacache.impl.MediaCacheItemHTTPImpl</BaseClass>

<ReaderClass></ReaderClass>

<DefaultBlockSize>262144</DefaultBlockSize>

<MaxTimeToLive>1200000</MaxTimeToLive>

<MinTimeToLive>600000</MinTimeToLive>

<ReadAhead>true</ReadAhead>

<ReadAheadThreshold>50</ReadAheadThreshold>

<IsPassThru>false</IsPassThru>

<Properties>

</Properties>

</MediaCacheSource>


这是一个限制流到指定域名的HTTP配置。在这个例子中我们映射前缀http1/Prefix)到基础路径http://mycompany.comBasePath)。


例如:假设有一个媒体文件在这样一个URL

http://mycompany.com/media/sample.mp4


要播放这个流,使用下面的URL和流名称(see the How to play a video on demand file tutorial for more detailed information and example players):


To play using Adobe Flash player (RTMP)

Server: rtmp://[wowza-address]/mediacache

Stream: mp4:http1/media/sample.mp4


To play using Adobe Flash player (San Jose/Flash HTTP)

http://[wowza-ip-address]:1935/mediacache/_definst_/mp4:http1/media/sample.mp4/manifest.f4m


To play using an Apple iOS device (Cupertino/Apple HTTP Live Streaming)

http://[wowza-ip-address]:1935/mediacache/_definst_/mp4:http1/media/sample.mp4/playlist.m3u8


To play using Microsoft Silverlight (Smooth Streaming)

http://[wowza-ip-address]:1935/mediacache/_definst_/mp4:http1/media/sample.mp4/Manifest


To play using RTSP/RTP player or device

rtsp://[wowza-ip-address]:1935/mediacache/_definst_/mp4:http1/media/sample.mp4



3

<MediaCacheSource>

<Name>http1</Name>

<BasePath>http://www.mycompany.com/</BasePath>

<Prefix>http1/</Prefix>

<BaseClass>com.wowza.wms.plugin.mediacache.impl.MediaCacheItemHTTPImpl</BaseClass>

<ReaderClass></ReaderClass>

<DefaultBlockSize>262144</DefaultBlockSize>

<MaxTimeToLive>1200000</MaxTimeToLive>

<MinTimeToLive>600000</MinTimeToLive>

<ReadAhead>true</ReadAhead>

<ReadAheadThreshold>50</ReadAheadThreshold>

<IsPassThru>false</IsPassThru>

<Properties>

<Property>

<Name>proxyHost</Name>

<Value>myproxy.mycompany.com</Value>

</Property>

<Property>

<Name>proxyPort</Name>

<Value>8080</Value>

<Type>Integer</Type>

</Property>

<Property>

<Name>requestFullURL</Name>

<Value>true</Value>

<Type>Boolean</Type>

</Property>

</Properties>

</MediaCacheSource>


这是一个限制流到指定域名并发送所有请求通过一个代理服务器。代理服务器详细指定了proxyHost, proxyPortrequestFullURLproperties

requestFullURL命令MediaCache系统发送请求到代理服务器时使用全URLs

这是一个设置多层缓冲系统的好方法。

例如:如果你想从多个数据中心发送相同的文件,你可以在每个数据中心设置一个转发代理服务。


4

<MediaCacheSource>

<Name>content1</Name>

<BasePath>C:/content/</BasePath>

<Prefix>path1/</Prefix>

<BaseClass>com.wowza.wms.plugin.mediacache.impl.MediaCacheItemFileImpl</BaseClass>

<ReaderClass></ReaderClass>

<DefaultBlockSize>262144</DefaultBlockSize>

<MaxTimeToLive>1200000</MaxTimeToLive>

<MinTimeToLive>600000</MinTimeToLive>

<ReadAhead>true</ReadAhead>

<ReadAheadThreshold>50</ReadAheadThreshold>

<IsPassThru>false</IsPassThru>

<Properties>

</Properties>

</MediaCacheSource>


这是一个网络随机存储例子。这里使用的BaseClass为: com.wowza.wms.plugin.mediacache.impl.MediaCacheItemFileImp

在这个例子中前缀是path1/(Prefix)并且pathc:/content/(BasePath).


假如,有一个媒体文件在如下URL

C:/content/media/sample.mp4


要播放这个流,使用下面的URL和流名称(see the How to play a video on demand file tutorial for more detailed information and example players):


To play using Adobe Flash player (RTMP)

Server: rtmp://[wowza-address]/mediacache

Stream: mp4:path1/media/sample.mp4


To play using Adobe Flash player (San Jose/Flash HTTP)

http://[wowza-ip-address]:1935/mediacache/_definst_/mp4:path1/media/sample.mp4/manifest.f4m


To play using an Apple iOS device (Cupertino/Apple HTTP Live Streaming)

http://[wowza-ip-address]:1935/mediacache/_definst_/mp4:path1/media/sample.mp4/playlist.m3u8


To play using Microsoft Silverlight (Smooth Streaming)

http://[wowza-ip-address]:1935/mediacache/_definst_/mp4:path1/media/sample.mp4/Manifest


To play using RTSP/RTP player or device

rtsp://[wowza-ip-address]:1935/mediacache/_definst_/mp4:path1/media/sample.mp4


四、记录和观察


MediaCache磁盘分配



Linux操作系统,你可以看到MediaCache报告的磁盘使用率与系统报告的的差异。


当一个项目进入缓冲并且一个文件进行块填充时,MediaCache预先分配了整个文件的大小。


所以你把磁盘上所有单个文件大小进行相加,你就会看到它与MediaCache报告的是相匹配的。