Wowza MediaCache模塊配置

一、安裝:

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>randomAcce***eaderClass</Name>

<Value>com.wowza.wms.plugin.mediacache.impl.MediaCacheRandomAcce***eader</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報告的是相匹配的。


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章