mirror of
https://github.com/burrow-dev/burrow-server.git
synced 2026-11-21 09:37:50 -05:00
Brought up to date with the private repository (feea4c7)
This commit is contained in:
1 parent
1aa738d692
commit
1b1df1ae48
7925 files changed
+2617237
-20
No files matched your search
@@ -0,0 +1,73 @@
|
||||
package org.osmf.net.httpstreaming
|
||||
{
|
||||
import org.osmf.net.SwitchingRuleBase;
|
||||
|
||||
[ExcludeClass]
|
||||
public class DownloadRatioRule extends SwitchingRuleBase
|
||||
{
|
||||
|
||||
private var aggressiveUpswitch:Boolean = false;
|
||||
|
||||
public function DownloadRatioRule(metrics:HTTPNetStreamMetrics, aggressiveUpswitch:Boolean = true)
|
||||
{
|
||||
super(metrics);
|
||||
this.aggressiveUpswitch = aggressiveUpswitch;
|
||||
}
|
||||
|
||||
override public function getNewIndex() : int
|
||||
{
|
||||
var switchRatio:Number = NaN;
|
||||
var proposedIndex:int = -1;
|
||||
if(this.httpMetrics.downloadRatio < 1)
|
||||
{
|
||||
if(this.httpMetrics.currentIndex > 0)
|
||||
{
|
||||
switchRatio = this.getSwitchRatio(this.httpMetrics.currentIndex - 1);
|
||||
if(this.httpMetrics.downloadRatio < switchRatio)
|
||||
{
|
||||
proposedIndex = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
proposedIndex = this.httpMetrics.currentIndex - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(this.httpMetrics.currentIndex < this.httpMetrics.maxAllowedIndex)
|
||||
{
|
||||
switchRatio = this.getSwitchRatio(this.httpMetrics.currentIndex + 1);
|
||||
if(this.httpMetrics.downloadRatio >= switchRatio)
|
||||
{
|
||||
if(this.httpMetrics.downloadRatio > 100 || !this.aggressiveUpswitch)
|
||||
{
|
||||
proposedIndex = this.httpMetrics.currentIndex + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
while(++proposedIndex < this.httpMetrics.maxAllowedIndex + 1)
|
||||
{
|
||||
switchRatio = this.getSwitchRatio(proposedIndex);
|
||||
if(this.httpMetrics.downloadRatio < switchRatio)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
proposedIndex--;
|
||||
}
|
||||
}
|
||||
}
|
||||
return proposedIndex;
|
||||
}
|
||||
|
||||
private function getSwitchRatio(index:int) : Number
|
||||
{
|
||||
return this.httpMetrics.getBitrateForIndex(index) / this.httpMetrics.getBitrateForIndex(metrics.currentIndex);
|
||||
}
|
||||
|
||||
private function get httpMetrics() : HTTPNetStreamMetrics
|
||||
{
|
||||
return metrics as HTTPNetStreamMetrics;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
+28
@@ -0,0 +1,28 @@
|
||||
package org.osmf.net.httpstreaming
|
||||
{
|
||||
import org.osmf.net.NetStreamMetricsBase;
|
||||
|
||||
[ExcludeClass]
|
||||
public class HTTPNetStreamMetrics extends NetStreamMetricsBase
|
||||
{
|
||||
|
||||
private var httpNetStream:HTTPNetStream;
|
||||
|
||||
public function HTTPNetStreamMetrics(netStream:HTTPNetStream)
|
||||
{
|
||||
super(netStream);
|
||||
this.httpNetStream = netStream;
|
||||
}
|
||||
|
||||
public function get downloadRatio() : Number
|
||||
{
|
||||
return this.httpNetStream.downloadRatio;
|
||||
}
|
||||
|
||||
public function getBitrateForIndex(index:int) : Number
|
||||
{
|
||||
return this.resource.streamItems[index].bitrate;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
package org.osmf.net.httpstreaming
|
||||
{
|
||||
import flash.net.URLRequest;
|
||||
|
||||
[ExcludeClass]
|
||||
public class HTTPStreamRequest
|
||||
{
|
||||
|
||||
private var _urlRequest:URLRequest;
|
||||
|
||||
private var _quality:int;
|
||||
|
||||
private var _truncateAt:Number;
|
||||
|
||||
private var _retryAfter:Number;
|
||||
|
||||
private var _unpublishNotify:Boolean;
|
||||
|
||||
public function HTTPStreamRequest(url:String = null, quality:int = -1, truncateAt:Number = -1, retryAfter:Number = -1, unpublishNotify:Boolean = false)
|
||||
{
|
||||
super();
|
||||
if(Boolean(url))
|
||||
{
|
||||
this._urlRequest = new URLRequest(HTTPStreamingUtils.normalizeURL(url));
|
||||
}
|
||||
else
|
||||
{
|
||||
this._urlRequest = null;
|
||||
}
|
||||
this._quality = quality;
|
||||
this._truncateAt = truncateAt;
|
||||
this._retryAfter = retryAfter;
|
||||
this._unpublishNotify = unpublishNotify;
|
||||
}
|
||||
|
||||
public function get urlRequest() : URLRequest
|
||||
{
|
||||
return this._urlRequest;
|
||||
}
|
||||
|
||||
public function get retryAfter() : Number
|
||||
{
|
||||
return this._retryAfter;
|
||||
}
|
||||
|
||||
public function get unpublishNotify() : Boolean
|
||||
{
|
||||
return this._unpublishNotify;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
package org.osmf.net.httpstreaming
|
||||
{
|
||||
import flash.errors.IllegalOperationError;
|
||||
import flash.events.EventDispatcher;
|
||||
import flash.utils.ByteArray;
|
||||
import flash.utils.IDataInput;
|
||||
|
||||
[ExcludeClass]
|
||||
[Event(name="notifyTimeBias",type="org.osmf.events.HTTPStreamingFileHandlerEvent")]
|
||||
[Event(name="notifySegmentDuration",type="org.osmf.events.HTTPStreamingFileHandlerEvent")]
|
||||
public class HTTPStreamingFileHandlerBase extends EventDispatcher
|
||||
{
|
||||
|
||||
public function HTTPStreamingFileHandlerBase()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public function beginProcessFile(seek:Boolean, seekTime:Number) : void
|
||||
{
|
||||
throw new IllegalOperationError("The beginProcessFile() method must be overridden by HttpStreamingFileHandlerBase\'s derived class.");
|
||||
}
|
||||
|
||||
public function get inputBytesNeeded() : Number
|
||||
{
|
||||
throw new IllegalOperationError("The inputBytesNeeded() method must be overridden by HttpStreamingFileHandlerBase\'s derived class.");
|
||||
}
|
||||
|
||||
public function processFileSegment(input:IDataInput) : ByteArray
|
||||
{
|
||||
throw new IllegalOperationError("The processFileSegment() method must be overridden by HttpStreamingFileHandlerBase\'s derived class.");
|
||||
}
|
||||
|
||||
public function endProcessFile(input:IDataInput) : ByteArray
|
||||
{
|
||||
throw new IllegalOperationError("The endProcessFile() method must be overridden by HttpStreamingFileHandlerBase\'s derived class.");
|
||||
}
|
||||
|
||||
public function flushFileSegment(input:IDataInput) : ByteArray
|
||||
{
|
||||
throw new IllegalOperationError("The flushFileSegment() method must be overridden by HttpStreamingFileHandlerBase\'s derived class.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
package org.osmf.net.httpstreaming
|
||||
{
|
||||
import flash.errors.IllegalOperationError;
|
||||
import flash.events.EventDispatcher;
|
||||
|
||||
[ExcludeClass]
|
||||
[Event(name="DVRStreamInfo",type="org.osmf.events.DVRStreamInfoEvent")]
|
||||
[Event(name="notifyError",type="org.osmf.events.HTTPStreamingFileIndexHandlerEvent")]
|
||||
[Event(name="requestLoadIndex",type="org.osmf.events.HTTPStreamingFileIndexHandlerEvent")]
|
||||
[Event(name="notifyTotalDuration",type="org.osmf.events.HTTPStreamingFileIndexHandlerEvent")]
|
||||
[Event(name="notifyRates",type="org.osmf.events.HTTPStreamingFileIndexHandlerEvent")]
|
||||
[Event(name="notifyIndexReady",type="org.osmf.events.HTTPStreamingFileIndexHandlerEvent")]
|
||||
public class HTTPStreamingIndexHandlerBase extends EventDispatcher
|
||||
{
|
||||
|
||||
public function HTTPStreamingIndexHandlerBase()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public function initialize(indexInfo:Object) : void
|
||||
{
|
||||
throw new IllegalOperationError("The initialize() method must be overridden by the derived class.");
|
||||
}
|
||||
|
||||
public function processIndexData(data:*, indexContext:Object) : void
|
||||
{
|
||||
throw new IllegalOperationError("The processIndexData() method must be overridden by the derived class.");
|
||||
}
|
||||
|
||||
public function getFileForTime(time:Number, quality:int) : HTTPStreamRequest
|
||||
{
|
||||
throw new IllegalOperationError("The getFileForTime() method must be overridden by the derived class.");
|
||||
}
|
||||
|
||||
public function getNextFile(quality:int) : HTTPStreamRequest
|
||||
{
|
||||
throw new IllegalOperationError("The getNextFile() method must be overridden by the derived class.");
|
||||
}
|
||||
|
||||
public function dvrGetStreamInfo(indexInfo:Object) : void
|
||||
{
|
||||
throw new IllegalOperationError("The dvrGetStreamInfo() method must be overridden by the derived class.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package org.osmf.net.httpstreaming
|
||||
{
|
||||
[ExcludeClass]
|
||||
public class HTTPStreamingIndexInfoBase
|
||||
{
|
||||
|
||||
public function HTTPStreamingIndexInfoBase()
|
||||
{
|
||||
super();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+95
@@ -0,0 +1,95 @@
|
||||
package org.osmf.net.httpstreaming
|
||||
{
|
||||
import flash.net.NetConnection;
|
||||
import flash.net.NetStream;
|
||||
import org.osmf.events.DVRStreamInfoEvent;
|
||||
import org.osmf.media.MediaResourceBase;
|
||||
import org.osmf.media.URLResource;
|
||||
import org.osmf.metadata.Metadata;
|
||||
import org.osmf.metadata.MetadataNamespaces;
|
||||
import org.osmf.net.DynamicStreamingResource;
|
||||
import org.osmf.net.NetLoader;
|
||||
import org.osmf.net.NetStreamLoadTrait;
|
||||
import org.osmf.net.NetStreamSwitchManager;
|
||||
import org.osmf.net.NetStreamSwitchManagerBase;
|
||||
import org.osmf.net.SwitchingRuleBase;
|
||||
import org.osmf.net.httpstreaming.dvr.DVRInfo;
|
||||
import org.osmf.net.httpstreaming.dvr.HTTPStreamingDVRCastDVRTrait;
|
||||
import org.osmf.net.httpstreaming.dvr.HTTPStreamingDVRCastTimeTrait;
|
||||
import org.osmf.net.httpstreaming.f4f.HTTPStreamingF4FFileHandler;
|
||||
import org.osmf.net.httpstreaming.f4f.HTTPStreamingF4FIndexHandler;
|
||||
import org.osmf.net.rtmpstreaming.DroppedFramesRule;
|
||||
import org.osmf.traits.LoadState;
|
||||
|
||||
public class HTTPStreamingNetLoader extends NetLoader
|
||||
{
|
||||
|
||||
public function HTTPStreamingNetLoader()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
override public function canHandleResource(resource:MediaResourceBase) : Boolean
|
||||
{
|
||||
return resource.getMetadataValue(MetadataNamespaces.HTTP_STREAMING_METADATA) as Metadata != null;
|
||||
}
|
||||
|
||||
override protected function createNetStream(connection:NetConnection, resource:URLResource) : NetStream
|
||||
{
|
||||
var fileHandler:HTTPStreamingFileHandlerBase = new HTTPStreamingF4FFileHandler();
|
||||
var indexHandler:HTTPStreamingIndexHandlerBase = new HTTPStreamingF4FIndexHandler(fileHandler);
|
||||
var httpNetStream:HTTPNetStream = new HTTPNetStream(connection,indexHandler,fileHandler);
|
||||
httpNetStream.manualSwitchMode = true;
|
||||
httpNetStream.indexInfo = HTTPStreamingUtils.createF4FIndexInfo(resource);
|
||||
return httpNetStream;
|
||||
}
|
||||
|
||||
override protected function createNetStreamSwitchManager(connection:NetConnection, netStream:NetStream, dsResource:DynamicStreamingResource) : NetStreamSwitchManagerBase
|
||||
{
|
||||
var metrics:HTTPNetStreamMetrics = null;
|
||||
if(dsResource != null)
|
||||
{
|
||||
metrics = new HTTPNetStreamMetrics(netStream as HTTPNetStream);
|
||||
return new NetStreamSwitchManager(connection,netStream,dsResource,metrics,this.getDefaultSwitchingRules(metrics));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
override protected function processFinishLoading(loadTrait:NetStreamLoadTrait) : void
|
||||
{
|
||||
var netStream:HTTPNetStream = null;
|
||||
var onDVRStreamInfo:Function = null;
|
||||
onDVRStreamInfo = function(event:DVRStreamInfoEvent):void
|
||||
{
|
||||
netStream.removeEventListener(DVRStreamInfoEvent.DVRSTREAMINFO,onDVRStreamInfo);
|
||||
loadTrait.setTrait(new HTTPStreamingDVRCastDVRTrait(loadTrait.connection,netStream,event.info as DVRInfo));
|
||||
loadTrait.setTrait(new HTTPStreamingDVRCastTimeTrait(loadTrait.connection,netStream,event.info as DVRInfo));
|
||||
updateLoadTrait(loadTrait,LoadState.READY);
|
||||
};
|
||||
var resource:URLResource = loadTrait.resource as URLResource;
|
||||
if(!this.dvrMetadataPresent(resource))
|
||||
{
|
||||
updateLoadTrait(loadTrait,LoadState.READY);
|
||||
return;
|
||||
}
|
||||
netStream = loadTrait.netStream as HTTPNetStream;
|
||||
netStream.addEventListener(DVRStreamInfoEvent.DVRSTREAMINFO,onDVRStreamInfo);
|
||||
netStream.DVRGetStreamInfo(null);
|
||||
}
|
||||
|
||||
private function dvrMetadataPresent(resource:URLResource) : Boolean
|
||||
{
|
||||
var metadata:Metadata = resource.getMetadataValue(MetadataNamespaces.DVR_METADATA) as Metadata;
|
||||
return metadata != null;
|
||||
}
|
||||
|
||||
private function getDefaultSwitchingRules(metrics:HTTPNetStreamMetrics) : Vector.<SwitchingRuleBase>
|
||||
{
|
||||
var rules:Vector.<SwitchingRuleBase> = new Vector.<SwitchingRuleBase>();
|
||||
rules.push(new DownloadRatioRule(metrics));
|
||||
rules.push(new DroppedFramesRule(metrics));
|
||||
return rules;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
package org.osmf.net.httpstreaming
|
||||
{
|
||||
[ExcludeClass]
|
||||
internal class HTTPStreamingState
|
||||
{
|
||||
|
||||
internal static const INIT:String = "init";
|
||||
|
||||
internal static const LOAD_SEEK:String = "loadSeek";
|
||||
|
||||
internal static const LOAD_SEEK_RETRY_WAIT:String = "loadSeekRetryWait";
|
||||
|
||||
internal static const LOAD:String = "load";
|
||||
|
||||
internal static const LOAD_WAIT:String = "loadWait";
|
||||
|
||||
internal static const LOAD_NEXT:String = "loadNext";
|
||||
|
||||
internal static const LOAD_NEXT_RETRY_WAIT:String = "loadNextRetryWait";
|
||||
|
||||
internal static const PLAY_START_SEEK:String = "playStartSeek";
|
||||
|
||||
internal static const PLAY_START_NEXT:String = "playStartNext";
|
||||
|
||||
internal static const PLAY_START_COMMON:String = "playStartCommon";
|
||||
|
||||
internal static const PLAY:String = "play";
|
||||
|
||||
internal static const END_SEGMENT:String = "endSegment";
|
||||
|
||||
internal static const SEEK:String = "seek";
|
||||
|
||||
internal static const STOP:String = "stop";
|
||||
|
||||
internal static const HALT:String = "halt";
|
||||
|
||||
public function HTTPStreamingState()
|
||||
{
|
||||
super();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+184
@@ -0,0 +1,184 @@
|
||||
package org.osmf.net.httpstreaming
|
||||
{
|
||||
import flash.utils.ByteArray;
|
||||
import org.osmf.elements.f4mClasses.BootstrapInfo;
|
||||
import org.osmf.media.URLResource;
|
||||
import org.osmf.metadata.Metadata;
|
||||
import org.osmf.metadata.MetadataNamespaces;
|
||||
import org.osmf.net.DynamicStreamingItem;
|
||||
import org.osmf.net.DynamicStreamingResource;
|
||||
import org.osmf.net.httpstreaming.dvr.DVRInfo;
|
||||
import org.osmf.net.httpstreaming.f4f.HTTPStreamingF4FIndexInfo;
|
||||
import org.osmf.net.httpstreaming.f4f.HTTPStreamingF4FStreamInfo;
|
||||
|
||||
[ExcludeClass]
|
||||
public class HTTPStreamingUtils
|
||||
{
|
||||
|
||||
public function HTTPStreamingUtils()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public static function createHTTPStreamingMetadata(abstUrl:String, abstData:ByteArray, serverBaseUrls:Vector.<String>) : Metadata
|
||||
{
|
||||
var metadata:Metadata = new Metadata();
|
||||
var bootstrap:BootstrapInfo = new BootstrapInfo();
|
||||
if(abstUrl != null && abstUrl.length > 0)
|
||||
{
|
||||
bootstrap.url = abstUrl;
|
||||
}
|
||||
bootstrap.data = abstData;
|
||||
metadata.addValue(MetadataNamespaces.HTTP_STREAMING_BOOTSTRAP_KEY,bootstrap);
|
||||
if(serverBaseUrls != null && serverBaseUrls.length > 0)
|
||||
{
|
||||
metadata.addValue(MetadataNamespaces.HTTP_STREAMING_SERVER_BASE_URLS_KEY,serverBaseUrls);
|
||||
}
|
||||
return metadata;
|
||||
}
|
||||
|
||||
public static function createF4FIndexInfo(resource:URLResource) : HTTPStreamingF4FIndexInfo
|
||||
{
|
||||
var serverBaseURLs:Vector.<String> = null;
|
||||
var streamInfos:Vector.<HTTPStreamingF4FStreamInfo> = null;
|
||||
var dvrInfo:DVRInfo = null;
|
||||
var indexInfo:HTTPStreamingF4FIndexInfo = null;
|
||||
var httpMetadata:Metadata = resource.getMetadataValue(MetadataNamespaces.HTTP_STREAMING_METADATA) as Metadata;
|
||||
var dvrMetadata:Metadata = resource.getMetadataValue(MetadataNamespaces.DVR_METADATA) as Metadata;
|
||||
if(httpMetadata != null)
|
||||
{
|
||||
serverBaseURLs = httpMetadata.getValue(MetadataNamespaces.HTTP_STREAMING_SERVER_BASE_URLS_KEY) as Vector.<String>;
|
||||
streamInfos = generateStreamInfos(resource);
|
||||
dvrInfo = generateDVRInfo(dvrMetadata);
|
||||
indexInfo = new HTTPStreamingF4FIndexInfo(serverBaseURLs != null && serverBaseURLs.length > 0 ? serverBaseURLs[0] : null,streamInfos,dvrInfo);
|
||||
}
|
||||
return indexInfo;
|
||||
}
|
||||
|
||||
public static function normalizeURL(url:String) : String
|
||||
{
|
||||
var temp:String = null;
|
||||
var i:int = 0;
|
||||
var ret:String = "";
|
||||
var protocol:String = "";
|
||||
if(url.indexOf("http://") == 0)
|
||||
{
|
||||
protocol = "http://";
|
||||
}
|
||||
else if(url.indexOf("https://") == 0)
|
||||
{
|
||||
protocol = "https://";
|
||||
}
|
||||
if(protocol.length > 0)
|
||||
{
|
||||
temp = url.substr(protocol.length);
|
||||
}
|
||||
else
|
||||
{
|
||||
temp = url;
|
||||
}
|
||||
var items:Array = temp.split("/");
|
||||
var index:int = items.indexOf("..");
|
||||
while(index >= 0)
|
||||
{
|
||||
items.splice(index - 1,2);
|
||||
index = items.indexOf("..");
|
||||
}
|
||||
ret = protocol;
|
||||
if(items.length > 0)
|
||||
{
|
||||
for(i = 0; i < items.length; i++)
|
||||
{
|
||||
if(i != 0)
|
||||
{
|
||||
ret += "/";
|
||||
}
|
||||
ret += items[i] as String;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
private static function generateDVRInfo(metadata:Metadata) : DVRInfo
|
||||
{
|
||||
if(metadata == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var dvrInfo:DVRInfo = new DVRInfo();
|
||||
dvrInfo.id = "";
|
||||
dvrInfo.beginOffset = NaN;
|
||||
dvrInfo.endOffset = NaN;
|
||||
dvrInfo.offline = false;
|
||||
if(metadata.getValue(MetadataNamespaces.HTTP_STREAMING_DVR_ID_KEY) != null)
|
||||
{
|
||||
dvrInfo.id = metadata.getValue(MetadataNamespaces.HTTP_STREAMING_DVR_ID_KEY) as String;
|
||||
}
|
||||
if(metadata.getValue(MetadataNamespaces.HTTP_STREAMING_DVR_BEGIN_OFFSET_KEY) != null)
|
||||
{
|
||||
dvrInfo.beginOffset = metadata.getValue(MetadataNamespaces.HTTP_STREAMING_DVR_BEGIN_OFFSET_KEY) as uint;
|
||||
}
|
||||
if(metadata.getValue(MetadataNamespaces.HTTP_STREAMING_DVR_END_OFFSET_KEY) != null)
|
||||
{
|
||||
dvrInfo.endOffset = metadata.getValue(MetadataNamespaces.HTTP_STREAMING_DVR_END_OFFSET_KEY) as uint;
|
||||
}
|
||||
if(metadata.getValue(MetadataNamespaces.HTTP_STREAMING_DVR_OFFLINE_KEY) != null)
|
||||
{
|
||||
dvrInfo.offline = metadata.getValue(MetadataNamespaces.HTTP_STREAMING_DVR_OFFLINE_KEY) as Boolean;
|
||||
}
|
||||
return dvrInfo;
|
||||
}
|
||||
|
||||
private static function generateStreamInfos(resource:URLResource) : Vector.<HTTPStreamingF4FStreamInfo>
|
||||
{
|
||||
var streamMetadata:Object = null;
|
||||
var xmpMetadata:ByteArray = null;
|
||||
var streamItem:DynamicStreamingItem = null;
|
||||
var streamName:String = null;
|
||||
var streamInfos:Vector.<HTTPStreamingF4FStreamInfo> = new Vector.<HTTPStreamingF4FStreamInfo>();
|
||||
var drmMetadata:Metadata = resource.getMetadataValue(MetadataNamespaces.DRM_METADATA) as Metadata;
|
||||
var httpMetadata:Metadata = resource.getMetadataValue(MetadataNamespaces.HTTP_STREAMING_METADATA) as Metadata;
|
||||
var additionalHeader:ByteArray = null;
|
||||
var bootstrap:BootstrapInfo = null;
|
||||
var dsResource:DynamicStreamingResource = resource as DynamicStreamingResource;
|
||||
if(dsResource != null)
|
||||
{
|
||||
for each(streamItem in dsResource.streamItems)
|
||||
{
|
||||
additionalHeader = null;
|
||||
bootstrap = null;
|
||||
streamMetadata = null;
|
||||
xmpMetadata = null;
|
||||
if(drmMetadata != null)
|
||||
{
|
||||
additionalHeader = drmMetadata.getValue(MetadataNamespaces.DRM_ADDITIONAL_HEADER_KEY + streamItem.streamName) as ByteArray;
|
||||
}
|
||||
if(httpMetadata != null)
|
||||
{
|
||||
bootstrap = httpMetadata.getValue(MetadataNamespaces.HTTP_STREAMING_BOOTSTRAP_KEY + streamItem.streamName) as BootstrapInfo;
|
||||
streamMetadata = httpMetadata.getValue(MetadataNamespaces.HTTP_STREAMING_STREAM_METADATA_KEY + streamItem.streamName);
|
||||
xmpMetadata = httpMetadata.getValue(MetadataNamespaces.HTTP_STREAMING_XMP_METADATA_KEY + streamItem.streamName) as ByteArray;
|
||||
}
|
||||
streamInfos.push(new HTTPStreamingF4FStreamInfo(bootstrap,streamItem.streamName,streamItem.bitrate,additionalHeader,streamMetadata,xmpMetadata));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(drmMetadata != null)
|
||||
{
|
||||
additionalHeader = drmMetadata.getValue(MetadataNamespaces.DRM_ADDITIONAL_HEADER_KEY) as ByteArray;
|
||||
}
|
||||
if(httpMetadata != null)
|
||||
{
|
||||
bootstrap = httpMetadata.getValue(MetadataNamespaces.HTTP_STREAMING_BOOTSTRAP_KEY) as BootstrapInfo;
|
||||
streamMetadata = httpMetadata.getValue(MetadataNamespaces.HTTP_STREAMING_STREAM_METADATA_KEY);
|
||||
xmpMetadata = httpMetadata.getValue(MetadataNamespaces.HTTP_STREAMING_XMP_METADATA_KEY) as ByteArray;
|
||||
}
|
||||
streamName = resource.url;
|
||||
streamInfos.push(new HTTPStreamingF4FStreamInfo(bootstrap,streamName,NaN,additionalHeader,streamMetadata,xmpMetadata));
|
||||
}
|
||||
return streamInfos;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package org.osmf.net.httpstreaming.dvr
|
||||
{
|
||||
[ExcludeClass]
|
||||
public class DVRInfo
|
||||
{
|
||||
|
||||
public var id:String;
|
||||
|
||||
public var url:String;
|
||||
|
||||
public var beginOffset:uint = 0;
|
||||
|
||||
public var endOffset:uint = 0;
|
||||
|
||||
public var offline:Boolean;
|
||||
|
||||
public var isRecording:Boolean;
|
||||
|
||||
public var curLength:Number;
|
||||
|
||||
public var startTime:Number = NaN;
|
||||
|
||||
public function DVRInfo()
|
||||
{
|
||||
super();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
package org.osmf.net.httpstreaming.dvr
|
||||
{
|
||||
import flash.net.NetConnection;
|
||||
import org.osmf.events.DVRStreamInfoEvent;
|
||||
import org.osmf.net.httpstreaming.HTTPNetStream;
|
||||
import org.osmf.traits.DVRTrait;
|
||||
|
||||
[ExcludeClass]
|
||||
public class HTTPStreamingDVRCastDVRTrait extends DVRTrait
|
||||
{
|
||||
|
||||
private var _connection:NetConnection;
|
||||
|
||||
private var _stream:HTTPNetStream;
|
||||
|
||||
private var _dvrInfo:DVRInfo;
|
||||
|
||||
public function HTTPStreamingDVRCastDVRTrait(connection:NetConnection, stream:HTTPNetStream, dvrInfo:DVRInfo)
|
||||
{
|
||||
this._connection = connection;
|
||||
this._stream = stream;
|
||||
this._dvrInfo = dvrInfo;
|
||||
this._stream.addEventListener(DVRStreamInfoEvent.DVRSTREAMINFO,this.onDVRStreamInfo);
|
||||
super(dvrInfo.isRecording);
|
||||
}
|
||||
|
||||
private function onDVRStreamInfo(event:DVRStreamInfoEvent) : void
|
||||
{
|
||||
this._dvrInfo = event.info as DVRInfo;
|
||||
setIsRecording(this._dvrInfo == null ? false : this._dvrInfo.isRecording);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
package org.osmf.net.httpstreaming.dvr
|
||||
{
|
||||
import flash.events.NetStatusEvent;
|
||||
import flash.net.NetConnection;
|
||||
import org.osmf.events.DVRStreamInfoEvent;
|
||||
import org.osmf.net.NetStreamCodes;
|
||||
import org.osmf.net.httpstreaming.HTTPNetStream;
|
||||
import org.osmf.traits.TimeTrait;
|
||||
|
||||
[ExcludeClass]
|
||||
public class HTTPStreamingDVRCastTimeTrait extends TimeTrait
|
||||
{
|
||||
|
||||
private var _connection:NetConnection;
|
||||
|
||||
private var _stream:HTTPNetStream;
|
||||
|
||||
private var _dvrInfo:DVRInfo;
|
||||
|
||||
public function HTTPStreamingDVRCastTimeTrait(connection:NetConnection, stream:HTTPNetStream, dvrInfo:DVRInfo)
|
||||
{
|
||||
super(NaN);
|
||||
this._connection = connection;
|
||||
this._stream = stream;
|
||||
this._dvrInfo = dvrInfo;
|
||||
this._stream.addEventListener(DVRStreamInfoEvent.DVRSTREAMINFO,this.onDVRStreamInfo);
|
||||
this._stream.addEventListener(NetStatusEvent.NET_STATUS,this.onNetStatus);
|
||||
}
|
||||
|
||||
override public function get duration() : Number
|
||||
{
|
||||
if(this._dvrInfo == null)
|
||||
{
|
||||
return NaN;
|
||||
}
|
||||
return this._dvrInfo.curLength;
|
||||
}
|
||||
|
||||
override public function get currentTime() : Number
|
||||
{
|
||||
return this._stream.time;
|
||||
}
|
||||
|
||||
private function onDVRStreamInfo(event:DVRStreamInfoEvent) : void
|
||||
{
|
||||
this._dvrInfo = event.info as DVRInfo;
|
||||
setDuration(this._dvrInfo.curLength);
|
||||
}
|
||||
|
||||
private function onNetStatus(event:NetStatusEvent) : void
|
||||
{
|
||||
switch(event.info.code)
|
||||
{
|
||||
case NetStreamCodes.NETSTREAM_PLAY_UNPUBLISH_NOTIFY:
|
||||
signalComplete();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+224
@@ -0,0 +1,224 @@
|
||||
package org.osmf.net.httpstreaming.f4f
|
||||
{
|
||||
[ExcludeClass]
|
||||
public class AdobeBootstrapBox extends FullBox
|
||||
{
|
||||
|
||||
private var _bootstrapVersion:uint;
|
||||
|
||||
private var _profile:uint;
|
||||
|
||||
private var _live:Boolean;
|
||||
|
||||
private var _update:Boolean;
|
||||
|
||||
private var _timeScale:uint;
|
||||
|
||||
private var _currentMediaTime:Number;
|
||||
|
||||
private var _smpteTimeCodeOffset:Number;
|
||||
|
||||
private var _movieIdentifier:String;
|
||||
|
||||
private var _serverEntryCount:uint;
|
||||
|
||||
private var _serverBaseURLs:Vector.<String>;
|
||||
|
||||
private var _qualitySegmentURLModifiers:Vector.<String>;
|
||||
|
||||
private var _drmData:String;
|
||||
|
||||
private var _metadata:String;
|
||||
|
||||
private var _segmentRunTables:Vector.<AdobeSegmentRunTable>;
|
||||
|
||||
private var _fragmentRunTables:Vector.<AdobeFragmentRunTable>;
|
||||
|
||||
public function AdobeBootstrapBox()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public function get bootstrapVersion() : uint
|
||||
{
|
||||
return this._bootstrapVersion;
|
||||
}
|
||||
|
||||
public function set bootstrapVersion(value:uint) : void
|
||||
{
|
||||
this._bootstrapVersion = value;
|
||||
}
|
||||
|
||||
public function get profile() : uint
|
||||
{
|
||||
return this._profile;
|
||||
}
|
||||
|
||||
public function set profile(value:uint) : void
|
||||
{
|
||||
this._profile = value;
|
||||
}
|
||||
|
||||
public function get live() : Boolean
|
||||
{
|
||||
return this._live;
|
||||
}
|
||||
|
||||
public function set live(value:Boolean) : void
|
||||
{
|
||||
this._live = value;
|
||||
}
|
||||
|
||||
public function get update() : Boolean
|
||||
{
|
||||
return this._update;
|
||||
}
|
||||
|
||||
public function set update(value:Boolean) : void
|
||||
{
|
||||
this._update = value;
|
||||
}
|
||||
|
||||
public function get timeScale() : uint
|
||||
{
|
||||
return this._timeScale;
|
||||
}
|
||||
|
||||
public function set timeScale(value:uint) : void
|
||||
{
|
||||
this._timeScale = value;
|
||||
}
|
||||
|
||||
public function get currentMediaTime() : Number
|
||||
{
|
||||
return this._currentMediaTime;
|
||||
}
|
||||
|
||||
public function set currentMediaTime(value:Number) : void
|
||||
{
|
||||
this._currentMediaTime = value;
|
||||
}
|
||||
|
||||
public function get smpteTimeCodeOffset() : Number
|
||||
{
|
||||
return this._smpteTimeCodeOffset;
|
||||
}
|
||||
|
||||
public function set smpteTimeCodeOffset(value:Number) : void
|
||||
{
|
||||
this._smpteTimeCodeOffset = value;
|
||||
}
|
||||
|
||||
public function get movieIdentifier() : String
|
||||
{
|
||||
return this._movieIdentifier;
|
||||
}
|
||||
|
||||
public function set movieIdentifier(value:String) : void
|
||||
{
|
||||
this._movieIdentifier = value;
|
||||
}
|
||||
|
||||
public function get serverBaseURLs() : Vector.<String>
|
||||
{
|
||||
return this._serverBaseURLs;
|
||||
}
|
||||
|
||||
public function set serverBaseURLs(value:Vector.<String>) : void
|
||||
{
|
||||
this._serverBaseURLs = value;
|
||||
}
|
||||
|
||||
public function get qualitySegmentURLModifiers() : Vector.<String>
|
||||
{
|
||||
return this._qualitySegmentURLModifiers;
|
||||
}
|
||||
|
||||
public function set qualitySegmentURLModifiers(value:Vector.<String>) : void
|
||||
{
|
||||
this._qualitySegmentURLModifiers = value;
|
||||
}
|
||||
|
||||
public function get drmData() : String
|
||||
{
|
||||
return this._drmData;
|
||||
}
|
||||
|
||||
public function set drmData(value:String) : void
|
||||
{
|
||||
this._drmData = value;
|
||||
}
|
||||
|
||||
public function get metadata() : String
|
||||
{
|
||||
return this._metadata;
|
||||
}
|
||||
|
||||
public function set metadata(value:String) : void
|
||||
{
|
||||
this._metadata = value;
|
||||
}
|
||||
|
||||
public function get segmentRunTables() : Vector.<AdobeSegmentRunTable>
|
||||
{
|
||||
return this._segmentRunTables;
|
||||
}
|
||||
|
||||
public function set segmentRunTables(value:Vector.<AdobeSegmentRunTable>) : void
|
||||
{
|
||||
this._segmentRunTables = value;
|
||||
}
|
||||
|
||||
public function get fragmentRunTables() : Vector.<AdobeFragmentRunTable>
|
||||
{
|
||||
return this._fragmentRunTables;
|
||||
}
|
||||
|
||||
public function set fragmentRunTables(value:Vector.<AdobeFragmentRunTable>) : void
|
||||
{
|
||||
var frt:AdobeFragmentRunTable = null;
|
||||
this._fragmentRunTables = value;
|
||||
if(value != null && value.length > 0)
|
||||
{
|
||||
frt = value[value.length - 1];
|
||||
frt.adjustEndEntryDurationAccrued(this._currentMediaTime);
|
||||
}
|
||||
}
|
||||
|
||||
public function findSegmentId(fragmentId:uint) : uint
|
||||
{
|
||||
return this._segmentRunTables[0].findSegmentIdByFragmentId(fragmentId);
|
||||
}
|
||||
|
||||
public function get totalFragments() : uint
|
||||
{
|
||||
var afrt:AdobeFragmentRunTable = this._fragmentRunTables[this._fragmentRunTables.length - 1];
|
||||
var fdps:Vector.<FragmentDurationPair> = afrt.fragmentDurationPairs;
|
||||
var lastValidFdp:FragmentDurationPair = fdps[fdps.length - 1];
|
||||
if(lastValidFdp.duration == 0)
|
||||
{
|
||||
lastValidFdp = fdps[fdps.length - 2];
|
||||
}
|
||||
var deltaTime:Number = this._currentMediaTime - lastValidFdp.durationAccrued;
|
||||
var fragCount:uint = deltaTime <= 0 ? 0 : uint(deltaTime / lastValidFdp.duration);
|
||||
return lastValidFdp.firstFragment + fragCount - 1;
|
||||
}
|
||||
|
||||
public function get totalDuration() : uint
|
||||
{
|
||||
if(this._fragmentRunTables == null || this._fragmentRunTables.length < 1)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
var frt:AdobeFragmentRunTable = this._fragmentRunTables[0];
|
||||
return this._currentMediaTime - frt.fragmentDurationPairs[0].durationAccrued;
|
||||
}
|
||||
|
||||
public function contentComplete() : Boolean
|
||||
{
|
||||
var frt:AdobeFragmentRunTable = this._fragmentRunTables[this._fragmentRunTables.length - 1];
|
||||
return frt.tableComplete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
package org.osmf.net.httpstreaming.f4f
|
||||
{
|
||||
[ExcludeClass]
|
||||
internal class AdobeFragmentRandomAccessBox extends FullBox
|
||||
{
|
||||
|
||||
private var _timeScale:uint;
|
||||
|
||||
private var _localRandomAccessEntries:Vector.<LocalRandomAccessEntry>;
|
||||
|
||||
private var _globalRandomAccessEntries:Vector.<GlobalRandomAccessEntry>;
|
||||
|
||||
public function AdobeFragmentRandomAccessBox()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public function get timeScale() : uint
|
||||
{
|
||||
return this._timeScale;
|
||||
}
|
||||
|
||||
public function set timeScale(value:uint) : void
|
||||
{
|
||||
this._timeScale = value;
|
||||
}
|
||||
|
||||
public function get localRandomAccessEntries() : Vector.<LocalRandomAccessEntry>
|
||||
{
|
||||
return this._localRandomAccessEntries;
|
||||
}
|
||||
|
||||
public function set localRandomAccessEntries(value:Vector.<LocalRandomAccessEntry>) : void
|
||||
{
|
||||
this._localRandomAccessEntries = value;
|
||||
}
|
||||
|
||||
public function get globalRandomAccessEntries() : Vector.<GlobalRandomAccessEntry>
|
||||
{
|
||||
return this._globalRandomAccessEntries;
|
||||
}
|
||||
|
||||
public function set globalRandomAccessEntries(value:Vector.<GlobalRandomAccessEntry>) : void
|
||||
{
|
||||
this._globalRandomAccessEntries = value;
|
||||
}
|
||||
|
||||
public function findNearestKeyFrameOffset(seekToTime:Number) : LocalRandomAccessEntry
|
||||
{
|
||||
var entry:LocalRandomAccessEntry = null;
|
||||
var i:int = this._localRandomAccessEntries.length - 1;
|
||||
while(i >= 0)
|
||||
{
|
||||
entry = this._localRandomAccessEntries[i];
|
||||
if(entry.time <= seekToTime)
|
||||
{
|
||||
return entry;
|
||||
}
|
||||
i--;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+237
@@ -0,0 +1,237 @@
|
||||
package org.osmf.net.httpstreaming.f4f
|
||||
{
|
||||
[ExcludeClass]
|
||||
internal class AdobeFragmentRunTable extends FullBox
|
||||
{
|
||||
|
||||
private var _timeScale:uint;
|
||||
|
||||
private var _qualitySegmentURLModifiers:Vector.<String>;
|
||||
|
||||
private var _fragmentDurationPairs:Vector.<FragmentDurationPair>;
|
||||
|
||||
public function AdobeFragmentRunTable()
|
||||
{
|
||||
super();
|
||||
this._fragmentDurationPairs = new Vector.<FragmentDurationPair>();
|
||||
}
|
||||
|
||||
public function get timeScale() : uint
|
||||
{
|
||||
return this._timeScale;
|
||||
}
|
||||
|
||||
public function set timeScale(value:uint) : void
|
||||
{
|
||||
this._timeScale = value;
|
||||
}
|
||||
|
||||
public function get qualitySegmentURLModifiers() : Vector.<String>
|
||||
{
|
||||
return this._qualitySegmentURLModifiers;
|
||||
}
|
||||
|
||||
public function set qualitySegmentURLModifiers(value:Vector.<String>) : void
|
||||
{
|
||||
this._qualitySegmentURLModifiers = value;
|
||||
}
|
||||
|
||||
public function get fragmentDurationPairs() : Vector.<FragmentDurationPair>
|
||||
{
|
||||
return this._fragmentDurationPairs;
|
||||
}
|
||||
|
||||
public function addFragmentDurationPair(fdp:FragmentDurationPair) : void
|
||||
{
|
||||
this._fragmentDurationPairs.push(fdp);
|
||||
}
|
||||
|
||||
public function findFragmentIdByTime(time:Number, totalDuration:Number, live:Boolean = false) : FragmentAccessInformation
|
||||
{
|
||||
if(this._fragmentDurationPairs.length <= 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var fdp:FragmentDurationPair = null;
|
||||
for(var i:uint = 1; i < this._fragmentDurationPairs.length; i++)
|
||||
{
|
||||
fdp = this._fragmentDurationPairs[i];
|
||||
if(fdp.durationAccrued >= time)
|
||||
{
|
||||
return this.validateFragment(this.calculateFragmentId(this._fragmentDurationPairs[i - 1],time),totalDuration,live);
|
||||
}
|
||||
}
|
||||
return this.validateFragment(this.calculateFragmentId(this._fragmentDurationPairs[this._fragmentDurationPairs.length - 1],time),totalDuration,live);
|
||||
}
|
||||
|
||||
public function validateFragment(fragId:uint, totalDuration:Number, live:Boolean = false) : FragmentAccessInformation
|
||||
{
|
||||
var curFdp:FragmentDurationPair = null;
|
||||
var nextFdp:FragmentDurationPair = null;
|
||||
var timeResidue:Number = NaN;
|
||||
var timeDistance:Number = NaN;
|
||||
var fragStartTime:Number = NaN;
|
||||
var lastFdp:FragmentDurationPair = null;
|
||||
var size:uint = this._fragmentDurationPairs.length - 1;
|
||||
var fai:FragmentAccessInformation = null;
|
||||
for(var i:uint = 0; i < size; i++)
|
||||
{
|
||||
curFdp = this._fragmentDurationPairs[i];
|
||||
nextFdp = this._fragmentDurationPairs[i + 1];
|
||||
if(curFdp.firstFragment <= fragId && fragId < nextFdp.firstFragment)
|
||||
{
|
||||
if(curFdp.duration <= 0)
|
||||
{
|
||||
fai = this.getNextValidFragment(i + 1,totalDuration);
|
||||
}
|
||||
else
|
||||
{
|
||||
fai = new FragmentAccessInformation();
|
||||
fai.fragId = fragId;
|
||||
fai.fragDuration = curFdp.duration;
|
||||
fai.fragmentEndTime = curFdp.durationAccrued + curFdp.duration * (fragId - curFdp.firstFragment + 1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
if(curFdp.firstFragment <= fragId && this.endOfStreamEntry(nextFdp))
|
||||
{
|
||||
if(curFdp.duration > 0)
|
||||
{
|
||||
timeResidue = totalDuration - curFdp.durationAccrued;
|
||||
timeDistance = (fragId - curFdp.firstFragment + 1) * curFdp.duration;
|
||||
fragStartTime = (fragId - curFdp.firstFragment) * curFdp.duration;
|
||||
if(timeResidue > fragStartTime)
|
||||
{
|
||||
if(!live || fragStartTime + curFdp.duration + curFdp.durationAccrued <= totalDuration)
|
||||
{
|
||||
fai = new FragmentAccessInformation();
|
||||
fai.fragId = fragId;
|
||||
fai.fragDuration = curFdp.duration;
|
||||
if(timeResidue >= timeDistance)
|
||||
{
|
||||
fai.fragmentEndTime = curFdp.durationAccrued + timeDistance;
|
||||
}
|
||||
else
|
||||
{
|
||||
fai.fragmentEndTime = curFdp.durationAccrued + timeResidue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(fai == null)
|
||||
{
|
||||
lastFdp = this._fragmentDurationPairs[size];
|
||||
if(lastFdp.duration > 0 && fragId >= lastFdp.firstFragment)
|
||||
{
|
||||
timeResidue = totalDuration - lastFdp.durationAccrued;
|
||||
timeDistance = (fragId - lastFdp.firstFragment + 1) * lastFdp.duration;
|
||||
fragStartTime = (fragId - lastFdp.firstFragment) * lastFdp.duration;
|
||||
if(timeResidue > fragStartTime)
|
||||
{
|
||||
if(!live || fragStartTime + lastFdp.duration + lastFdp.durationAccrued <= totalDuration)
|
||||
{
|
||||
fai = new FragmentAccessInformation();
|
||||
fai.fragId = fragId;
|
||||
fai.fragDuration = lastFdp.duration;
|
||||
if(timeResidue >= timeDistance)
|
||||
{
|
||||
fai.fragmentEndTime = lastFdp.durationAccrued + timeDistance;
|
||||
}
|
||||
else
|
||||
{
|
||||
fai.fragmentEndTime = lastFdp.durationAccrued + timeResidue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return fai;
|
||||
}
|
||||
|
||||
private function getNextValidFragment(startIdx:uint, totalDuration:Number) : FragmentAccessInformation
|
||||
{
|
||||
var fdp:FragmentDurationPair = null;
|
||||
var fai:FragmentAccessInformation = null;
|
||||
for(var i:uint = startIdx; i < this._fragmentDurationPairs.length; i++)
|
||||
{
|
||||
fdp = this._fragmentDurationPairs[i];
|
||||
if(fdp.duration > 0)
|
||||
{
|
||||
fai = new FragmentAccessInformation();
|
||||
fai.fragId = fdp.firstFragment;
|
||||
fai.fragDuration = fdp.duration;
|
||||
fai.fragmentEndTime = fdp.durationAccrued + fdp.duration;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return fai;
|
||||
}
|
||||
|
||||
private function endOfStreamEntry(fdp:FragmentDurationPair) : Boolean
|
||||
{
|
||||
return fdp.duration == 0 && fdp.discontinuityIndicator == 0;
|
||||
}
|
||||
|
||||
public function fragmentsLeft(fragId:uint, currentMediaTime:Number) : uint
|
||||
{
|
||||
if(this._fragmentDurationPairs == null || this._fragmentDurationPairs.length == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
var fdp:FragmentDurationPair = this._fragmentDurationPairs[this.fragmentDurationPairs.length - 1] as FragmentDurationPair;
|
||||
return uint((currentMediaTime - fdp.durationAccrued) / fdp.duration + fdp.firstFragment - fragId - 1);
|
||||
}
|
||||
|
||||
public function tableComplete() : Boolean
|
||||
{
|
||||
if(this._fragmentDurationPairs == null || this._fragmentDurationPairs.length <= 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var fdp:FragmentDurationPair = this._fragmentDurationPairs[this.fragmentDurationPairs.length - 1] as FragmentDurationPair;
|
||||
return fdp.duration == 0 && fdp.discontinuityIndicator == 0;
|
||||
}
|
||||
|
||||
public function adjustEndEntryDurationAccrued(value:Number) : void
|
||||
{
|
||||
var fdp:FragmentDurationPair = this._fragmentDurationPairs[this._fragmentDurationPairs.length - 1];
|
||||
if(fdp.duration == 0)
|
||||
{
|
||||
fdp.durationAccrued = value;
|
||||
}
|
||||
}
|
||||
|
||||
private function findValidFragmentDurationPair(index:uint) : FragmentDurationPair
|
||||
{
|
||||
var fdp:FragmentDurationPair = null;
|
||||
for(var i:uint = index; index < this._fragmentDurationPairs.length; i++)
|
||||
{
|
||||
fdp = this._fragmentDurationPairs[i];
|
||||
if(fdp.duration > 0)
|
||||
{
|
||||
return fdp;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private function calculateFragmentId(fdp:FragmentDurationPair, time:Number) : uint
|
||||
{
|
||||
if(fdp.duration <= 0)
|
||||
{
|
||||
return fdp.firstFragment;
|
||||
}
|
||||
var deltaTime:Number = time - fdp.durationAccrued;
|
||||
var count:uint = deltaTime > 0 ? uint(deltaTime / fdp.duration) : 1;
|
||||
if(deltaTime % fdp.duration > 0)
|
||||
{
|
||||
count++;
|
||||
}
|
||||
return fdp.firstFragment + count - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+73
@@ -0,0 +1,73 @@
|
||||
package org.osmf.net.httpstreaming.f4f
|
||||
{
|
||||
[ExcludeClass]
|
||||
internal class AdobeSegmentRunTable extends FullBox
|
||||
{
|
||||
|
||||
private var _qualitySegmentURLModifiers:Vector.<String>;
|
||||
|
||||
private var _segmentFragmentPairs:Vector.<SegmentFragmentPair>;
|
||||
|
||||
public function AdobeSegmentRunTable()
|
||||
{
|
||||
super();
|
||||
this._segmentFragmentPairs = new Vector.<SegmentFragmentPair>();
|
||||
}
|
||||
|
||||
public function get qualitySegmentURLModifiers() : Vector.<String>
|
||||
{
|
||||
return this._qualitySegmentURLModifiers;
|
||||
}
|
||||
|
||||
public function set qualitySegmentURLModifiers(value:Vector.<String>) : void
|
||||
{
|
||||
this._qualitySegmentURLModifiers = value;
|
||||
}
|
||||
|
||||
public function get segmentFragmentPairs() : Vector.<SegmentFragmentPair>
|
||||
{
|
||||
return this._segmentFragmentPairs;
|
||||
}
|
||||
|
||||
public function addSegmentFragmentPair(sfp:SegmentFragmentPair) : void
|
||||
{
|
||||
var prevSfp:SegmentFragmentPair = this._segmentFragmentPairs.length <= 0 ? null : this._segmentFragmentPairs[this._segmentFragmentPairs.length - 1];
|
||||
var fragmentsAccrued:uint = 0;
|
||||
if(prevSfp != null)
|
||||
{
|
||||
fragmentsAccrued = prevSfp.fragmentsAccrued + (sfp.firstSegment - prevSfp.firstSegment) * prevSfp.fragmentsPerSegment;
|
||||
}
|
||||
sfp.fragmentsAccrued = fragmentsAccrued;
|
||||
this._segmentFragmentPairs.push(sfp);
|
||||
}
|
||||
|
||||
public function findSegmentIdByFragmentId(fragmentId:uint) : uint
|
||||
{
|
||||
var curSfp:SegmentFragmentPair = null;
|
||||
if(fragmentId < 1)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
for(var i:uint = 1; i < this._segmentFragmentPairs.length; i++)
|
||||
{
|
||||
curSfp = this._segmentFragmentPairs[i];
|
||||
if(curSfp.fragmentsAccrued >= fragmentId)
|
||||
{
|
||||
return this.calculateSegmentId(this._segmentFragmentPairs[i - 1],fragmentId);
|
||||
}
|
||||
}
|
||||
return this.calculateSegmentId(this._segmentFragmentPairs[this._segmentFragmentPairs.length - 1],fragmentId);
|
||||
}
|
||||
|
||||
public function get totalFragments() : uint
|
||||
{
|
||||
return this._segmentFragmentPairs[this._segmentFragmentPairs.length - 1].fragmentsPerSegment + this._segmentFragmentPairs[this._segmentFragmentPairs.length - 1].fragmentsAccrued;
|
||||
}
|
||||
|
||||
private function calculateSegmentId(sfp:SegmentFragmentPair, fragmentId:uint) : uint
|
||||
{
|
||||
return sfp.firstSegment + int((fragmentId - sfp.fragmentsAccrued - 1) / sfp.fragmentsPerSegment);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
package org.osmf.net.httpstreaming.f4f
|
||||
{
|
||||
[ExcludeClass]
|
||||
internal class Box
|
||||
{
|
||||
|
||||
private var _size:Number;
|
||||
|
||||
private var _type:String;
|
||||
|
||||
private var _boxLength:uint;
|
||||
|
||||
public function Box()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public function get size() : Number
|
||||
{
|
||||
return this._size;
|
||||
}
|
||||
|
||||
public function set size(value:Number) : void
|
||||
{
|
||||
this._size = value;
|
||||
}
|
||||
|
||||
public function get type() : String
|
||||
{
|
||||
return this._type;
|
||||
}
|
||||
|
||||
public function set type(value:String) : void
|
||||
{
|
||||
this._type = value;
|
||||
}
|
||||
|
||||
public function get boxLength() : uint
|
||||
{
|
||||
return this._boxLength;
|
||||
}
|
||||
|
||||
public function set boxLength(value:uint) : void
|
||||
{
|
||||
this._boxLength = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package org.osmf.net.httpstreaming.f4f
|
||||
{
|
||||
[ExcludeClass]
|
||||
internal class BoxInfo
|
||||
{
|
||||
|
||||
private var _size:Number;
|
||||
|
||||
private var _type:String;
|
||||
|
||||
public function BoxInfo(size:Number, type:String)
|
||||
{
|
||||
super();
|
||||
this._size = size;
|
||||
this._type = type;
|
||||
}
|
||||
|
||||
public function get size() : Number
|
||||
{
|
||||
return this._size;
|
||||
}
|
||||
|
||||
public function set size(value:Number) : void
|
||||
{
|
||||
this._size = value;
|
||||
}
|
||||
|
||||
public function get type() : String
|
||||
{
|
||||
return this._type;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,391 @@
|
||||
package org.osmf.net.httpstreaming.f4f
|
||||
{
|
||||
import flash.errors.IllegalOperationError;
|
||||
import flash.events.EventDispatcher;
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
[ExcludeClass]
|
||||
internal class BoxParser extends EventDispatcher
|
||||
{
|
||||
|
||||
private static const FULL_BOX_FIELD_FLAGS_LENGTH:uint = 3;
|
||||
|
||||
private static const AFRA_MASK_LONG_ID:uint = 128;
|
||||
|
||||
private static const AFRA_MASK_LONG_OFFSET:uint = 64;
|
||||
|
||||
private static const AFRA_MASK_GLOBAL_ENTRIES:uint = 32;
|
||||
|
||||
private var _ba:ByteArray;
|
||||
|
||||
public function BoxParser()
|
||||
{
|
||||
super();
|
||||
this._ba = null;
|
||||
}
|
||||
|
||||
public function init(ba:ByteArray) : void
|
||||
{
|
||||
this._ba = ba;
|
||||
this._ba.position = 0;
|
||||
}
|
||||
|
||||
public function getNextBoxInfo() : BoxInfo
|
||||
{
|
||||
if(this._ba == null || this._ba.bytesAvailable < F4FConstants.FIELD_SIZE_LENGTH + F4FConstants.FIELD_TYPE_LENGTH)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var size:Number = this._ba.readUnsignedInt();
|
||||
var type:String = this._ba.readUTFBytes(F4FConstants.FIELD_TYPE_LENGTH);
|
||||
return new BoxInfo(size,type);
|
||||
}
|
||||
|
||||
public function getBoxes() : Vector.<Box>
|
||||
{
|
||||
var abst:AdobeBootstrapBox = null;
|
||||
var afra:AdobeFragmentRandomAccessBox = null;
|
||||
var mdat:MediaDataBox = null;
|
||||
var boxes:Vector.<Box> = new Vector.<Box>();
|
||||
var bi:BoxInfo = this.getNextBoxInfo();
|
||||
while(bi != null)
|
||||
{
|
||||
if(bi.type == F4FConstants.BOX_TYPE_ABST)
|
||||
{
|
||||
abst = new AdobeBootstrapBox();
|
||||
this.parseAdobeBootstrapBox(bi,abst);
|
||||
boxes.push(abst);
|
||||
}
|
||||
else if(bi.type == F4FConstants.BOX_TYPE_AFRA)
|
||||
{
|
||||
afra = new AdobeFragmentRandomAccessBox();
|
||||
this.parseAdobeFragmentRandomAccessBox(bi,afra);
|
||||
boxes.push(afra);
|
||||
}
|
||||
else if(bi.type == F4FConstants.BOX_TYPE_MDAT)
|
||||
{
|
||||
mdat = new MediaDataBox();
|
||||
this.parseMediaDataBox(bi,mdat);
|
||||
boxes.push(mdat);
|
||||
}
|
||||
else
|
||||
{
|
||||
this._ba.position = this._ba.position + bi.size - (F4FConstants.FIELD_SIZE_LENGTH + F4FConstants.FIELD_TYPE_LENGTH);
|
||||
}
|
||||
bi = this.getNextBoxInfo();
|
||||
if(bi != null && bi.size <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
return boxes;
|
||||
}
|
||||
|
||||
public function readFragmentRandomAccessBox(bi:BoxInfo) : AdobeFragmentRandomAccessBox
|
||||
{
|
||||
var afra:AdobeFragmentRandomAccessBox = new AdobeFragmentRandomAccessBox();
|
||||
this.parseAdobeFragmentRandomAccessBox(bi,afra);
|
||||
return afra;
|
||||
}
|
||||
|
||||
public function readAdobeBootstrapBox(bi:BoxInfo) : AdobeBootstrapBox
|
||||
{
|
||||
var abst:AdobeBootstrapBox = new AdobeBootstrapBox();
|
||||
this.parseAdobeBootstrapBox(bi,abst);
|
||||
return abst;
|
||||
}
|
||||
|
||||
internal function readLongUIntToNumber() : Number
|
||||
{
|
||||
if(this._ba == null || this._ba.bytesAvailable < 8)
|
||||
{
|
||||
throw new IllegalOperationError("not enough length for readLongUIntToNumer");
|
||||
}
|
||||
var result:Number = this._ba.readUnsignedInt();
|
||||
result *= 4294967296;
|
||||
return result + this._ba.readUnsignedInt();
|
||||
}
|
||||
|
||||
private function readUnsignedInt() : uint
|
||||
{
|
||||
if(this._ba == null || this._ba.bytesAvailable < 4)
|
||||
{
|
||||
throw new IllegalOperationError("not enough length for readUnsignedInt");
|
||||
}
|
||||
return this._ba.readUnsignedInt();
|
||||
}
|
||||
|
||||
private function readBytes(bytes:ByteArray, offset:uint = 0, length:uint = 0) : void
|
||||
{
|
||||
if(this._ba == null || this._ba.bytesAvailable < length)
|
||||
{
|
||||
throw new IllegalOperationError("not enough length for readBytes: " + length);
|
||||
}
|
||||
return this._ba.readBytes(bytes,offset,length);
|
||||
}
|
||||
|
||||
private function readUnsignedByte() : uint
|
||||
{
|
||||
if(this._ba == null || this._ba.bytesAvailable < 1)
|
||||
{
|
||||
throw new IllegalOperationError("not enough length for readUnsingedByte");
|
||||
}
|
||||
return this._ba.readUnsignedByte();
|
||||
}
|
||||
|
||||
private function readBytesToUint(length:uint) : uint
|
||||
{
|
||||
var byte:uint = 0;
|
||||
if(this._ba == null || this._ba.bytesAvailable < length)
|
||||
{
|
||||
throw new IllegalOperationError("not enough length for readUnsingedByte");
|
||||
}
|
||||
if(length > 4)
|
||||
{
|
||||
throw new IllegalOperationError("number of bytes to read must be equal or less than 4");
|
||||
}
|
||||
var result:uint = 0;
|
||||
for(var i:uint = 0; i < length; i++)
|
||||
{
|
||||
result <<= 8;
|
||||
byte = this._ba.readUnsignedByte();
|
||||
result += byte;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private function readString() : String
|
||||
{
|
||||
var c:uint = 0;
|
||||
var pos:uint = this._ba.position;
|
||||
while(this._ba.position < this._ba.length)
|
||||
{
|
||||
c = uint(this._ba.readByte());
|
||||
if(c == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
var length:uint = this._ba.position - pos;
|
||||
this._ba.position = pos;
|
||||
return this._ba.readUTFBytes(length);
|
||||
}
|
||||
|
||||
private function parseBox(boxInfo:BoxInfo, box:Box) : void
|
||||
{
|
||||
var extendedType:ByteArray = null;
|
||||
var size:Number = boxInfo.size;
|
||||
var boxLength:uint = F4FConstants.FIELD_SIZE_LENGTH + F4FConstants.FIELD_TYPE_LENGTH;
|
||||
if(boxInfo.size == F4FConstants.FLAG_USE_LARGE_SIZE)
|
||||
{
|
||||
size = this.readLongUIntToNumber();
|
||||
boxLength += F4FConstants.FIELD_LARGE_SIZE_LENGTH;
|
||||
}
|
||||
if(boxInfo.type == F4FConstants.EXTENDED_TYPE)
|
||||
{
|
||||
extendedType = new ByteArray();
|
||||
this.readBytes(extendedType,0,F4FConstants.FIELD_EXTENDED_TYPE_LENGTH);
|
||||
boxLength += F4FConstants.FIELD_EXTENDED_TYPE_LENGTH;
|
||||
}
|
||||
box.size = size;
|
||||
box.type = boxInfo.type;
|
||||
box.boxLength = boxLength;
|
||||
}
|
||||
|
||||
private function parseFullBox(boxInfo:BoxInfo, fullBox:FullBox) : void
|
||||
{
|
||||
this.parseBox(boxInfo,fullBox);
|
||||
fullBox.version = this.readUnsignedByte();
|
||||
fullBox.flags = this.readBytesToUint(FULL_BOX_FIELD_FLAGS_LENGTH);
|
||||
}
|
||||
|
||||
private function parseAdobeBootstrapBox(boxInfo:BoxInfo, abst:AdobeBootstrapBox) : void
|
||||
{
|
||||
var asrt:AdobeSegmentRunTable = null;
|
||||
var afrt:AdobeFragmentRunTable = null;
|
||||
this.parseFullBox(boxInfo,abst);
|
||||
abst.bootstrapVersion = this.readUnsignedInt();
|
||||
var temp:uint = this.readUnsignedByte();
|
||||
abst.profile = temp >> 6;
|
||||
abst.live = (temp & 0x20) == 32;
|
||||
abst.update = (temp & 1) == 1;
|
||||
abst.timeScale = this.readUnsignedInt();
|
||||
abst.currentMediaTime = this.readLongUIntToNumber();
|
||||
abst.smpteTimeCodeOffset = this.readLongUIntToNumber();
|
||||
abst.movieIdentifier = this.readString();
|
||||
var serverEntryCount:uint = this.readUnsignedByte();
|
||||
var serverBaseURLs:Vector.<String> = new Vector.<String>();
|
||||
for(var i:int = 0; i < serverEntryCount; i++)
|
||||
{
|
||||
serverBaseURLs.push(this.readString());
|
||||
}
|
||||
abst.serverBaseURLs = serverBaseURLs;
|
||||
var qualityEntryCount:uint = this.readUnsignedByte();
|
||||
var qualitySegmentURLModifiers:Vector.<String> = new Vector.<String>();
|
||||
for(i = 0; i < qualityEntryCount; i++)
|
||||
{
|
||||
qualitySegmentURLModifiers.push(this.readString());
|
||||
}
|
||||
abst.qualitySegmentURLModifiers = qualitySegmentURLModifiers;
|
||||
abst.drmData = this.readString();
|
||||
abst.metadata = this.readString();
|
||||
var segmentRunTableCount:uint = this.readUnsignedByte();
|
||||
var segmentRunTables:Vector.<AdobeSegmentRunTable> = new Vector.<AdobeSegmentRunTable>();
|
||||
for(i = 0; i < segmentRunTableCount; i++)
|
||||
{
|
||||
boxInfo = this.getNextBoxInfo();
|
||||
if(boxInfo.type != F4FConstants.BOX_TYPE_ASRT)
|
||||
{
|
||||
throw new IllegalOperationError("Unexpected data structure: " + boxInfo.type);
|
||||
}
|
||||
asrt = new AdobeSegmentRunTable();
|
||||
this.parseAdobeSegmentRunTable(boxInfo,asrt);
|
||||
segmentRunTables.push(asrt);
|
||||
}
|
||||
abst.segmentRunTables = segmentRunTables;
|
||||
var fragmentRunTableCount:uint = this.readUnsignedByte();
|
||||
var fragmentRunTables:Vector.<AdobeFragmentRunTable> = new Vector.<AdobeFragmentRunTable>();
|
||||
for(i = 0; i < fragmentRunTableCount; i++)
|
||||
{
|
||||
boxInfo = this.getNextBoxInfo();
|
||||
if(boxInfo.type != F4FConstants.BOX_TYPE_AFRT)
|
||||
{
|
||||
throw new IllegalOperationError("Unexpected data structure: " + boxInfo.type);
|
||||
}
|
||||
afrt = new AdobeFragmentRunTable();
|
||||
this.parseAdobeFragmentRunTable(boxInfo,afrt);
|
||||
fragmentRunTables.push(afrt);
|
||||
}
|
||||
abst.fragmentRunTables = fragmentRunTables;
|
||||
}
|
||||
|
||||
private function parseAdobeSegmentRunTable(boxInfo:BoxInfo, asrt:AdobeSegmentRunTable) : void
|
||||
{
|
||||
this.parseFullBox(boxInfo,asrt);
|
||||
var qualityEntryCount:uint = this.readUnsignedByte();
|
||||
var qualitySegmentURLModifiers:Vector.<String> = new Vector.<String>();
|
||||
for(var i:uint = 0; i < qualityEntryCount; i++)
|
||||
{
|
||||
qualitySegmentURLModifiers.push(this.readString());
|
||||
}
|
||||
asrt.qualitySegmentURLModifiers = qualitySegmentURLModifiers;
|
||||
var entryCount:uint = this.readUnsignedInt();
|
||||
for(i = 0; i < entryCount; i++)
|
||||
{
|
||||
asrt.addSegmentFragmentPair(new SegmentFragmentPair(this.readUnsignedInt(),this.readUnsignedInt()));
|
||||
}
|
||||
}
|
||||
|
||||
private function parseAdobeFragmentRunTable(boxInfo:BoxInfo, afrt:AdobeFragmentRunTable) : void
|
||||
{
|
||||
var fdp:FragmentDurationPair = null;
|
||||
this.parseFullBox(boxInfo,afrt);
|
||||
afrt.timeScale = this.readUnsignedInt();
|
||||
var qualityEntryCount:uint = this.readUnsignedByte();
|
||||
var qualitySegmentURLModifiers:Vector.<String> = new Vector.<String>();
|
||||
for(var i:uint = 0; i < qualityEntryCount; i++)
|
||||
{
|
||||
qualitySegmentURLModifiers.push(this.readString());
|
||||
}
|
||||
afrt.qualitySegmentURLModifiers = qualitySegmentURLModifiers;
|
||||
var entryCount:uint = this.readUnsignedInt();
|
||||
for(i = 0; i < entryCount; i++)
|
||||
{
|
||||
fdp = new FragmentDurationPair();
|
||||
this.parseFragmentDurationPair(fdp);
|
||||
afrt.addFragmentDurationPair(fdp);
|
||||
}
|
||||
}
|
||||
|
||||
private function parseFragmentDurationPair(fdp:FragmentDurationPair) : void
|
||||
{
|
||||
fdp.firstFragment = this.readUnsignedInt();
|
||||
fdp.durationAccrued = this.readLongUIntToNumber();
|
||||
fdp.duration = this.readUnsignedInt();
|
||||
if(fdp.duration == 0)
|
||||
{
|
||||
fdp.discontinuityIndicator = this.readUnsignedByte();
|
||||
}
|
||||
}
|
||||
|
||||
private function parseAdobeFragmentRandomAccessBox(boxInfo:BoxInfo, afra:AdobeFragmentRandomAccessBox) : void
|
||||
{
|
||||
var lrae:LocalRandomAccessEntry = null;
|
||||
var grae:GlobalRandomAccessEntry = null;
|
||||
this.parseFullBox(boxInfo,afra);
|
||||
var sizes:uint = this.readBytesToUint(1);
|
||||
var longIdFields:Boolean = (sizes & AFRA_MASK_LONG_ID) > 0;
|
||||
var longOffsetFields:Boolean = (sizes & AFRA_MASK_LONG_OFFSET) > 0;
|
||||
var globalEntries:Boolean = (sizes & AFRA_MASK_GLOBAL_ENTRIES) > 0;
|
||||
afra.timeScale = this.readUnsignedInt();
|
||||
var entryCount:uint = this.readUnsignedInt();
|
||||
var localRandomAccessEntries:Vector.<LocalRandomAccessEntry> = new Vector.<LocalRandomAccessEntry>();
|
||||
for(var i:uint = 0; i < entryCount; i++)
|
||||
{
|
||||
lrae = new LocalRandomAccessEntry();
|
||||
this.parseLocalRandomAccessEntry(lrae,longOffsetFields);
|
||||
localRandomAccessEntries.push(lrae);
|
||||
}
|
||||
afra.localRandomAccessEntries = localRandomAccessEntries;
|
||||
var globalRandomAccessEntries:Vector.<GlobalRandomAccessEntry> = new Vector.<GlobalRandomAccessEntry>();
|
||||
if(globalEntries)
|
||||
{
|
||||
entryCount = this.readUnsignedInt();
|
||||
for(i = 0; i < entryCount; i++)
|
||||
{
|
||||
grae = new GlobalRandomAccessEntry();
|
||||
this.parseGlobalRandomAccessEntry(grae,longIdFields,longOffsetFields);
|
||||
globalRandomAccessEntries.push(grae);
|
||||
}
|
||||
}
|
||||
afra.globalRandomAccessEntries = globalRandomAccessEntries;
|
||||
}
|
||||
|
||||
private function parseLocalRandomAccessEntry(lrae:LocalRandomAccessEntry, longOffsetFields:Boolean) : void
|
||||
{
|
||||
lrae.time = this.readLongUIntToNumber();
|
||||
if(longOffsetFields)
|
||||
{
|
||||
lrae.offset = this.readLongUIntToNumber();
|
||||
}
|
||||
else
|
||||
{
|
||||
lrae.offset = this.readUnsignedInt();
|
||||
}
|
||||
}
|
||||
|
||||
private function parseGlobalRandomAccessEntry(grae:GlobalRandomAccessEntry, longIdFields:Boolean, longOffsetFields:Boolean) : void
|
||||
{
|
||||
grae.time = this.readLongUIntToNumber();
|
||||
if(longIdFields)
|
||||
{
|
||||
grae.segment = this.readUnsignedInt();
|
||||
grae.fragment = this.readUnsignedInt();
|
||||
}
|
||||
else
|
||||
{
|
||||
grae.segment = this.readBytesToUint(2);
|
||||
grae.fragment = this.readBytesToUint(2);
|
||||
}
|
||||
if(longOffsetFields)
|
||||
{
|
||||
grae.afraOffset = this.readLongUIntToNumber();
|
||||
grae.offsetFromAfra = this.readLongUIntToNumber();
|
||||
}
|
||||
else
|
||||
{
|
||||
grae.afraOffset = this.readUnsignedInt();
|
||||
grae.offsetFromAfra = this.readUnsignedInt();
|
||||
}
|
||||
}
|
||||
|
||||
private function parseMediaDataBox(boxInfo:BoxInfo, mdat:MediaDataBox) : void
|
||||
{
|
||||
this.parseBox(boxInfo,mdat);
|
||||
var data:ByteArray = new ByteArray();
|
||||
this.readBytes(data,0,mdat.size - mdat.boxLength);
|
||||
mdat.data = data;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package org.osmf.net.httpstreaming.f4f
|
||||
{
|
||||
[ExcludeClass]
|
||||
internal class F4FConstants
|
||||
{
|
||||
|
||||
internal static const BOX_TYPE_UUID:String = "uuid";
|
||||
|
||||
internal static const BOX_TYPE_ABST:String = "abst";
|
||||
|
||||
internal static const BOX_TYPE_ASRT:String = "asrt";
|
||||
|
||||
internal static const BOX_TYPE_AFRT:String = "afrt";
|
||||
|
||||
internal static const BOX_TYPE_AFRA:String = "afra";
|
||||
|
||||
internal static const BOX_TYPE_MDAT:String = "mdat";
|
||||
|
||||
internal static const BOX_TYPE_MOOF:String = "moof";
|
||||
|
||||
internal static const EXTENDED_TYPE:String = "uuid";
|
||||
|
||||
internal static const FIELD_SIZE_LENGTH:uint = 4;
|
||||
|
||||
internal static const FIELD_TYPE_LENGTH:uint = 4;
|
||||
|
||||
internal static const FIELD_LARGE_SIZE_LENGTH:uint = 8;
|
||||
|
||||
internal static const FIELD_EXTENDED_TYPE_LENGTH:uint = 16;
|
||||
|
||||
internal static const FLAG_USE_LARGE_SIZE:uint = 1;
|
||||
|
||||
public function F4FConstants()
|
||||
{
|
||||
super();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package org.osmf.net.httpstreaming.f4f
|
||||
{
|
||||
[ExcludeClass]
|
||||
internal class FragmentAccessInformation
|
||||
{
|
||||
|
||||
public var fragId:uint;
|
||||
|
||||
public var fragmentEndTime:Number;
|
||||
|
||||
public var fragDuration:uint;
|
||||
|
||||
public function FragmentAccessInformation()
|
||||
{
|
||||
super();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
package org.osmf.net.httpstreaming.f4f
|
||||
{
|
||||
[ExcludeClass]
|
||||
internal class FragmentDurationPair
|
||||
{
|
||||
|
||||
private var _firstFragment:uint;
|
||||
|
||||
private var _duration:uint;
|
||||
|
||||
private var _durationAccrued:Number;
|
||||
|
||||
private var _discontinuityIndicator:uint = 0;
|
||||
|
||||
public function FragmentDurationPair()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public function get firstFragment() : uint
|
||||
{
|
||||
return this._firstFragment;
|
||||
}
|
||||
|
||||
public function set firstFragment(value:uint) : void
|
||||
{
|
||||
this._firstFragment = value;
|
||||
}
|
||||
|
||||
public function get duration() : uint
|
||||
{
|
||||
return this._duration;
|
||||
}
|
||||
|
||||
public function set duration(value:uint) : void
|
||||
{
|
||||
this._duration = value;
|
||||
}
|
||||
|
||||
public function get durationAccrued() : Number
|
||||
{
|
||||
return this._durationAccrued;
|
||||
}
|
||||
|
||||
public function set durationAccrued(value:Number) : void
|
||||
{
|
||||
this._durationAccrued = value;
|
||||
}
|
||||
|
||||
public function get discontinuityIndicator() : uint
|
||||
{
|
||||
return this._discontinuityIndicator;
|
||||
}
|
||||
|
||||
public function set discontinuityIndicator(value:uint) : void
|
||||
{
|
||||
this._discontinuityIndicator = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package org.osmf.net.httpstreaming.f4f
|
||||
{
|
||||
[ExcludeClass]
|
||||
internal class FullBox extends Box
|
||||
{
|
||||
|
||||
private var _version:uint;
|
||||
|
||||
private var _flags:uint;
|
||||
|
||||
public function FullBox()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public function get version() : uint
|
||||
{
|
||||
return this._version;
|
||||
}
|
||||
|
||||
public function set version(value:uint) : void
|
||||
{
|
||||
this._version = value;
|
||||
}
|
||||
|
||||
public function get flags() : uint
|
||||
{
|
||||
return this._flags;
|
||||
}
|
||||
|
||||
public function set flags(value:uint) : void
|
||||
{
|
||||
this._flags = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+73
@@ -0,0 +1,73 @@
|
||||
package org.osmf.net.httpstreaming.f4f
|
||||
{
|
||||
[ExcludeClass]
|
||||
internal class GlobalRandomAccessEntry
|
||||
{
|
||||
|
||||
private var _time:Number;
|
||||
|
||||
private var _segment:uint;
|
||||
|
||||
private var _fragment:uint;
|
||||
|
||||
private var _afraOffset:Number;
|
||||
|
||||
private var _offsetFromAfra:Number;
|
||||
|
||||
public function GlobalRandomAccessEntry()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public function get time() : Number
|
||||
{
|
||||
return this._time;
|
||||
}
|
||||
|
||||
public function set time(value:Number) : void
|
||||
{
|
||||
this._time = value;
|
||||
}
|
||||
|
||||
public function get segment() : uint
|
||||
{
|
||||
return this._segment;
|
||||
}
|
||||
|
||||
public function set segment(value:uint) : void
|
||||
{
|
||||
this._segment = value;
|
||||
}
|
||||
|
||||
public function get fragment() : uint
|
||||
{
|
||||
return this._fragment;
|
||||
}
|
||||
|
||||
public function set fragment(value:uint) : void
|
||||
{
|
||||
this._fragment = value;
|
||||
}
|
||||
|
||||
public function get afraOffset() : Number
|
||||
{
|
||||
return this._afraOffset;
|
||||
}
|
||||
|
||||
public function set afraOffset(value:Number) : void
|
||||
{
|
||||
this._afraOffset = value;
|
||||
}
|
||||
|
||||
public function get offsetFromAfra() : Number
|
||||
{
|
||||
return this._offsetFromAfra;
|
||||
}
|
||||
|
||||
public function set offsetFromAfra(value:Number) : void
|
||||
{
|
||||
this._offsetFromAfra = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+227
@@ -0,0 +1,227 @@
|
||||
package org.osmf.net.httpstreaming.f4f
|
||||
{
|
||||
import flash.utils.ByteArray;
|
||||
import flash.utils.IDataInput;
|
||||
import org.osmf.events.HTTPStreamingFileHandlerEvent;
|
||||
import org.osmf.net.httpstreaming.HTTPStreamingFileHandlerBase;
|
||||
|
||||
[ExcludeClass]
|
||||
public class HTTPStreamingF4FFileHandler extends HTTPStreamingFileHandlerBase
|
||||
{
|
||||
|
||||
private static const MAX_BYTES_PER_MDAT_READ:uint = 5 * 1024;
|
||||
|
||||
private var _afra:AdobeFragmentRandomAccessBox;
|
||||
|
||||
private var _ba:ByteArray;
|
||||
|
||||
private var _boxInfoPending:Boolean;
|
||||
|
||||
private var _bytesNeeded:uint;
|
||||
|
||||
private var _bytesReadSinceAfraStart:uint;
|
||||
|
||||
private var _countingReadBytes:Boolean;
|
||||
|
||||
private var _mdatBytesPending:uint;
|
||||
|
||||
private var _nextBox:BoxInfo;
|
||||
|
||||
private var _parser:BoxParser = new BoxParser();
|
||||
|
||||
private var _seekToTime:Number;
|
||||
|
||||
private var _mdatBytesOffset:Number;
|
||||
|
||||
private var _processRequestWasSeek:Boolean = false;
|
||||
|
||||
public function HTTPStreamingF4FFileHandler()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
override public function beginProcessFile(seek:Boolean, seekTime:Number) : void
|
||||
{
|
||||
this._processRequestWasSeek = seek;
|
||||
this._seekToTime = seek ? seekTime : 0;
|
||||
this._bytesNeeded = F4FConstants.FIELD_SIZE_LENGTH + F4FConstants.FIELD_TYPE_LENGTH + F4FConstants.FIELD_LARGE_SIZE_LENGTH + F4FConstants.FIELD_EXTENDED_TYPE_LENGTH;
|
||||
this._bytesReadSinceAfraStart = 0;
|
||||
this._countingReadBytes = false;
|
||||
this._boxInfoPending = true;
|
||||
this._nextBox = null;
|
||||
}
|
||||
|
||||
override public function get inputBytesNeeded() : Number
|
||||
{
|
||||
return this._bytesNeeded;
|
||||
}
|
||||
|
||||
override public function processFileSegment(input:IDataInput) : ByteArray
|
||||
{
|
||||
var pos:uint = 0;
|
||||
var abst:AdobeBootstrapBox = null;
|
||||
if(input.bytesAvailable < this._bytesNeeded)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var returnByteArray:ByteArray = null;
|
||||
var bytesRead:Number = F4FConstants.FIELD_SIZE_LENGTH + F4FConstants.FIELD_TYPE_LENGTH;
|
||||
if(this._boxInfoPending)
|
||||
{
|
||||
this._ba = new ByteArray();
|
||||
input.readBytes(this._ba,0,bytesRead);
|
||||
if(this._countingReadBytes)
|
||||
{
|
||||
this._bytesReadSinceAfraStart += bytesRead;
|
||||
}
|
||||
this._parser.init(this._ba);
|
||||
this._nextBox = this._parser.getNextBoxInfo();
|
||||
if(this._nextBox.size == F4FConstants.FLAG_USE_LARGE_SIZE)
|
||||
{
|
||||
bytesRead += F4FConstants.FIELD_LARGE_SIZE_LENGTH;
|
||||
this._ba.position = 0;
|
||||
input.readBytes(this._ba,0,F4FConstants.FIELD_LARGE_SIZE_LENGTH);
|
||||
if(this._countingReadBytes)
|
||||
{
|
||||
this._bytesReadSinceAfraStart += F4FConstants.FIELD_LARGE_SIZE_LENGTH;
|
||||
}
|
||||
this._nextBox.size = this._parser.readLongUIntToNumber();
|
||||
}
|
||||
this._boxInfoPending = false;
|
||||
if(this._nextBox.type == F4FConstants.BOX_TYPE_MDAT)
|
||||
{
|
||||
this._bytesNeeded = 0;
|
||||
this._mdatBytesPending = this._nextBox.size - bytesRead;
|
||||
}
|
||||
else
|
||||
{
|
||||
this._bytesNeeded = this._nextBox.size - bytesRead;
|
||||
this._mdatBytesPending = 0;
|
||||
if(this._nextBox.type == F4FConstants.BOX_TYPE_AFRA)
|
||||
{
|
||||
this._bytesReadSinceAfraStart = bytesRead;
|
||||
this._countingReadBytes = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(this._bytesNeeded > 0)
|
||||
{
|
||||
pos = this._ba.position;
|
||||
input.readBytes(this._ba,this._ba.length,this._nextBox.size - bytesRead);
|
||||
if(this._countingReadBytes)
|
||||
{
|
||||
this._bytesReadSinceAfraStart += this._nextBox.size - bytesRead;
|
||||
}
|
||||
this._ba.position = pos;
|
||||
if(this._nextBox.type == F4FConstants.BOX_TYPE_ABST)
|
||||
{
|
||||
abst = this._parser.readAdobeBootstrapBox(this._nextBox);
|
||||
if(abst != null)
|
||||
{
|
||||
dispatchEvent(new HTTPStreamingFileHandlerEvent(HTTPStreamingFileHandlerEvent.NOTIFY_BOOTSTRAP_BOX,false,false,0,null,false,false,abst));
|
||||
}
|
||||
}
|
||||
else if(this._nextBox.type == F4FConstants.BOX_TYPE_AFRA)
|
||||
{
|
||||
this._afra = this._parser.readFragmentRandomAccessBox(this._nextBox);
|
||||
this.processSeekToTime();
|
||||
}
|
||||
else if(this._nextBox.type == F4FConstants.BOX_TYPE_MOOF)
|
||||
{
|
||||
}
|
||||
this._bytesNeeded = F4FConstants.FIELD_SIZE_LENGTH + F4FConstants.FIELD_TYPE_LENGTH + F4FConstants.FIELD_LARGE_SIZE_LENGTH + F4FConstants.FIELD_EXTENDED_TYPE_LENGTH;
|
||||
this._boxInfoPending = true;
|
||||
this._nextBox = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
returnByteArray = this.getMDATBytes(input,false);
|
||||
}
|
||||
return returnByteArray;
|
||||
}
|
||||
|
||||
override public function endProcessFile(input:IDataInput) : ByteArray
|
||||
{
|
||||
if(this._bytesNeeded > 0)
|
||||
{
|
||||
dispatchEvent(new HTTPStreamingFileHandlerEvent(HTTPStreamingFileHandlerEvent.NOTIFY_ERROR,false,false,0,null,false,false,null,true));
|
||||
}
|
||||
return this.getMDATBytes(input,true);
|
||||
}
|
||||
|
||||
override public function flushFileSegment(input:IDataInput) : ByteArray
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
private function getMDATBytes(input:IDataInput, endOfFile:Boolean) : ByteArray
|
||||
{
|
||||
var ba:ByteArray = null;
|
||||
var bytesToRead:uint = 0;
|
||||
if(input == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
this.skipSeekBytes(input);
|
||||
if(this._mdatBytesPending > 0)
|
||||
{
|
||||
bytesToRead = this._mdatBytesPending < input.bytesAvailable ? this._mdatBytesPending : input.bytesAvailable;
|
||||
if(!endOfFile && bytesToRead > MAX_BYTES_PER_MDAT_READ)
|
||||
{
|
||||
bytesToRead = MAX_BYTES_PER_MDAT_READ;
|
||||
}
|
||||
ba = new ByteArray();
|
||||
this._mdatBytesPending -= bytesToRead;
|
||||
input.readBytes(ba,0,bytesToRead);
|
||||
}
|
||||
return ba;
|
||||
}
|
||||
|
||||
private function skipSeekBytes(input:IDataInput) : void
|
||||
{
|
||||
var skip:uint = 0;
|
||||
var ba:ByteArray = null;
|
||||
if(this._bytesReadSinceAfraStart < this._mdatBytesOffset)
|
||||
{
|
||||
skip = this._mdatBytesOffset - this._bytesReadSinceAfraStart;
|
||||
if(input.bytesAvailable < skip)
|
||||
{
|
||||
skip = input.bytesAvailable;
|
||||
}
|
||||
ba = new ByteArray();
|
||||
input.readBytes(ba,0,skip);
|
||||
this._bytesReadSinceAfraStart += skip;
|
||||
this._mdatBytesPending -= skip;
|
||||
}
|
||||
}
|
||||
|
||||
private function processSeekToTime() : void
|
||||
{
|
||||
var timeBias:Number = 0;
|
||||
var entry:LocalRandomAccessEntry = null;
|
||||
if(this._seekToTime <= 0)
|
||||
{
|
||||
this._mdatBytesOffset = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
entry = this.getMDATBytesOffset(this._seekToTime);
|
||||
if(entry != null)
|
||||
{
|
||||
this._mdatBytesOffset = entry.offset;
|
||||
timeBias = entry.time;
|
||||
}
|
||||
else
|
||||
{
|
||||
this._mdatBytesOffset = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function getMDATBytesOffset(seekToTime:Number) : LocalRandomAccessEntry
|
||||
{
|
||||
return !isNaN(seekToTime) ? this._afra.findNearestKeyFrameOffset(seekToTime * this._afra.timeScale) : null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+489
@@ -0,0 +1,489 @@
|
||||
package org.osmf.net.httpstreaming.f4f
|
||||
{
|
||||
import flash.net.URLRequest;
|
||||
import flash.utils.ByteArray;
|
||||
import org.osmf.elements.f4mClasses.BootstrapInfo;
|
||||
import org.osmf.events.DVRStreamInfoEvent;
|
||||
import org.osmf.events.HTTPStreamingFileHandlerEvent;
|
||||
import org.osmf.events.HTTPStreamingIndexHandlerEvent;
|
||||
import org.osmf.net.dvr.DVRUtils;
|
||||
import org.osmf.net.httpstreaming.HTTPStreamRequest;
|
||||
import org.osmf.net.httpstreaming.HTTPStreamingFileHandlerBase;
|
||||
import org.osmf.net.httpstreaming.HTTPStreamingIndexHandlerBase;
|
||||
import org.osmf.net.httpstreaming.HTTPStreamingUtils;
|
||||
import org.osmf.net.httpstreaming.flv.FLVTagScriptDataObject;
|
||||
|
||||
[ExcludeClass]
|
||||
public class HTTPStreamingF4FIndexHandler extends HTTPStreamingIndexHandlerBase
|
||||
{
|
||||
|
||||
public static const DEFAULT_FRAGMENTS_THRESHOLD:uint = 5;
|
||||
|
||||
private var pendingIndexLoads:int;
|
||||
|
||||
private var pendingIndexUpdates:int;
|
||||
|
||||
private var bootstrapBoxes:Vector.<AdobeBootstrapBox>;
|
||||
|
||||
private var serverBaseURL:String;
|
||||
|
||||
private var streamInfos:Vector.<HTTPStreamingF4FStreamInfo>;
|
||||
|
||||
private var currentQuality:int;
|
||||
|
||||
private var currentFAI:FragmentAccessInformation;
|
||||
|
||||
private var fragmentsThreshold:uint;
|
||||
|
||||
private var fragmentRunTablesUpdating:Boolean;
|
||||
|
||||
private var f4fIndexInfo:HTTPStreamingF4FIndexInfo;
|
||||
|
||||
private var fileHandler:HTTPStreamingFileHandlerBase;
|
||||
|
||||
private var dvrGetStreamInfoCall:Boolean;
|
||||
|
||||
private var playInProgress:Boolean;
|
||||
|
||||
private var offsetFromCurrent:Number = 5;
|
||||
|
||||
private var delay:Number = 0.05;
|
||||
|
||||
private var pureLiveOffset:Number = NaN;
|
||||
|
||||
public function HTTPStreamingF4FIndexHandler(fileHandler:HTTPStreamingFileHandlerBase, fragmentsThreshold:uint = 5)
|
||||
{
|
||||
super();
|
||||
this.currentQuality = -1;
|
||||
this.currentFAI = null;
|
||||
this.fragmentRunTablesUpdating = false;
|
||||
this.fileHandler = fileHandler;
|
||||
this.fragmentsThreshold = fragmentsThreshold;
|
||||
this.dvrGetStreamInfoCall = false;
|
||||
fileHandler.addEventListener(HTTPStreamingFileHandlerEvent.NOTIFY_BOOTSTRAP_BOX,this.onNewBootstrapBox);
|
||||
}
|
||||
|
||||
public function get bootstrapInfo() : AdobeBootstrapBox
|
||||
{
|
||||
return this.currentQuality < 0 ? null : this.bootstrapBoxes[this.currentQuality];
|
||||
}
|
||||
|
||||
override public function dvrGetStreamInfo(indexInfo:Object) : void
|
||||
{
|
||||
this.dvrGetStreamInfoCall = true;
|
||||
this.playInProgress = false;
|
||||
this.initialize(indexInfo);
|
||||
}
|
||||
|
||||
override public function initialize(indexInfo:Object) : void
|
||||
{
|
||||
var bootstrapBox:AdobeBootstrapBox = null;
|
||||
var bootstrap:BootstrapInfo = null;
|
||||
this.f4fIndexInfo = indexInfo as HTTPStreamingF4FIndexInfo;
|
||||
if(this.f4fIndexInfo == null || this.f4fIndexInfo.streamInfos == null || this.f4fIndexInfo.streamInfos.length <= 0)
|
||||
{
|
||||
dispatchEvent(new HTTPStreamingIndexHandlerEvent(HTTPStreamingIndexHandlerEvent.NOTIFY_ERROR));
|
||||
return;
|
||||
}
|
||||
this.bootstrapBoxes = new Vector.<AdobeBootstrapBox>(this.f4fIndexInfo.streamInfos.length);
|
||||
this.fragmentRunTablesUpdating = false;
|
||||
this.playInProgress = false;
|
||||
this.pendingIndexLoads = 0;
|
||||
this.pureLiveOffset = NaN;
|
||||
this.serverBaseURL = this.f4fIndexInfo.serverBaseURL;
|
||||
this.streamInfos = this.f4fIndexInfo.streamInfos;
|
||||
for(var i:int = 0; i < this.streamInfos.length; i++)
|
||||
{
|
||||
bootstrap = this.streamInfos[i].bootstrapInfo;
|
||||
if(bootstrap == null || bootstrap.url == null && bootstrap.data == null)
|
||||
{
|
||||
dispatchEvent(new HTTPStreamingIndexHandlerEvent(HTTPStreamingIndexHandlerEvent.NOTIFY_ERROR));
|
||||
return;
|
||||
}
|
||||
if(bootstrap.data != null)
|
||||
{
|
||||
bootstrapBox = this.processBootstrapData(bootstrap.data,null);
|
||||
if(bootstrapBox == null)
|
||||
{
|
||||
dispatchEvent(new HTTPStreamingIndexHandlerEvent(HTTPStreamingIndexHandlerEvent.NOTIFY_ERROR));
|
||||
return;
|
||||
}
|
||||
this.bootstrapBoxes[i] = bootstrapBox;
|
||||
}
|
||||
else
|
||||
{
|
||||
++this.pendingIndexLoads;
|
||||
dispatchEvent(new HTTPStreamingIndexHandlerEvent(HTTPStreamingIndexHandlerEvent.REQUEST_LOAD_INDEX,false,false,false,NaN,null,null,new URLRequest(HTTPStreamingUtils.normalizeURL(bootstrap.url)),i,true));
|
||||
}
|
||||
}
|
||||
if(this.pendingIndexLoads == 0)
|
||||
{
|
||||
dispatchEvent(new HTTPStreamingIndexHandlerEvent(HTTPStreamingIndexHandlerEvent.NOTIFY_RATES,false,false,false,NaN,this.getStreamNames(this.streamInfos),this.getQualityRates(this.streamInfos)));
|
||||
this.notifyIndexReady(0);
|
||||
}
|
||||
}
|
||||
|
||||
override public function processIndexData(data:*, indexContext:Object) : void
|
||||
{
|
||||
var index:int = indexContext as int;
|
||||
var bootstrapBox:AdobeBootstrapBox = this.processBootstrapData(data,index);
|
||||
if(bootstrapBox == null)
|
||||
{
|
||||
dispatchEvent(new HTTPStreamingIndexHandlerEvent(HTTPStreamingIndexHandlerEvent.NOTIFY_ERROR));
|
||||
return;
|
||||
}
|
||||
if(!this.fragmentRunTablesUpdating)
|
||||
{
|
||||
--this.pendingIndexLoads;
|
||||
}
|
||||
else
|
||||
{
|
||||
--this.pendingIndexUpdates;
|
||||
if(this.pendingIndexUpdates == 0)
|
||||
{
|
||||
this.fragmentRunTablesUpdating = false;
|
||||
this.dispatchDVRStreamInfo(bootstrapBox);
|
||||
}
|
||||
}
|
||||
if(this.bootstrapBoxes[index] == null || this.bootstrapBoxes[index].bootstrapVersion < bootstrapBox.bootstrapVersion || this.bootstrapBoxes[index].currentMediaTime < bootstrapBox.currentMediaTime)
|
||||
{
|
||||
this.delay = 0.05;
|
||||
this.bootstrapBoxes[index] = bootstrapBox;
|
||||
}
|
||||
if(this.pendingIndexLoads == 0 && !this.fragmentRunTablesUpdating)
|
||||
{
|
||||
dispatchEvent(new HTTPStreamingIndexHandlerEvent(HTTPStreamingIndexHandlerEvent.NOTIFY_RATES,false,false,false,NaN,this.getStreamNames(this.streamInfos),this.getQualityRates(this.streamInfos)));
|
||||
this.notifyIndexReady(index);
|
||||
}
|
||||
}
|
||||
|
||||
override public function getFileForTime(time:Number, quality:int) : HTTPStreamRequest
|
||||
{
|
||||
var fdp:FragmentDurationPair = null;
|
||||
var segId:uint = 0;
|
||||
var requestUrl:String = null;
|
||||
var abst:AdobeBootstrapBox = this.bootstrapBoxes[quality];
|
||||
var streamRequest:HTTPStreamRequest = null;
|
||||
if(!this.playInProgress && this.stopPlaying(abst))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
this.checkMetadata(quality,abst);
|
||||
var frt:AdobeFragmentRunTable = this.getFragmentRunTable(abst);
|
||||
if(time >= 0 && time * abst.timeScale <= abst.currentMediaTime && quality >= 0 && quality < this.streamInfos.length)
|
||||
{
|
||||
this.currentFAI = frt.findFragmentIdByTime(time * abst.timeScale,abst.currentMediaTime,abst.contentComplete() ? false : abst.live);
|
||||
if(this.currentFAI == null || this.fragmentOverflow(abst,this.currentFAI.fragId))
|
||||
{
|
||||
if(abst.contentComplete())
|
||||
{
|
||||
if(abst.live)
|
||||
{
|
||||
return new HTTPStreamRequest(null,quality,-1,-1,true);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
this.adjustDelay();
|
||||
this.refreshBootstrapInfo(quality);
|
||||
return new HTTPStreamRequest(null,quality,0,this.delay);
|
||||
}
|
||||
this.playInProgress = true;
|
||||
fdp = frt.fragmentDurationPairs[0];
|
||||
segId = abst.findSegmentId(this.currentFAI.fragId - fdp.firstFragment + 1);
|
||||
requestUrl = "";
|
||||
if((this.streamInfos[quality].streamName as String).indexOf("http") != 0)
|
||||
{
|
||||
requestUrl = this.serverBaseURL + "/" + this.streamInfos[quality].streamName + "Seg" + segId + "-Frag" + this.currentFAI.fragId;
|
||||
}
|
||||
else
|
||||
{
|
||||
requestUrl = this.streamInfos[quality].streamName + "Seg" + segId + "-Frag" + this.currentFAI.fragId;
|
||||
}
|
||||
streamRequest = new HTTPStreamRequest(requestUrl);
|
||||
this.checkQuality(quality);
|
||||
this.notifyFragmentDuration(this.currentFAI.fragDuration / abst.timeScale);
|
||||
}
|
||||
return streamRequest;
|
||||
}
|
||||
|
||||
override public function getNextFile(quality:int) : HTTPStreamRequest
|
||||
{
|
||||
var frt:AdobeFragmentRunTable = null;
|
||||
var oldCurrentFAI:FragmentAccessInformation = null;
|
||||
var fdp:FragmentDurationPair = null;
|
||||
var segId:uint = 0;
|
||||
var requestUrl:String = null;
|
||||
var abst:AdobeBootstrapBox = this.bootstrapBoxes[quality];
|
||||
var streamRequest:HTTPStreamRequest = null;
|
||||
if(!this.playInProgress && this.stopPlaying(abst))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
this.checkMetadata(quality,abst);
|
||||
if(quality >= 0 && quality < this.streamInfos.length)
|
||||
{
|
||||
frt = this.getFragmentRunTable(abst);
|
||||
oldCurrentFAI = this.currentFAI;
|
||||
this.currentFAI = frt.validateFragment(this.currentFAI.fragId + 1,abst.currentMediaTime,abst.contentComplete() ? false : abst.live);
|
||||
if(this.currentFAI == null || this.fragmentOverflow(abst,this.currentFAI.fragId))
|
||||
{
|
||||
if(!abst.live || abst.contentComplete())
|
||||
{
|
||||
if(abst.live)
|
||||
{
|
||||
return new HTTPStreamRequest(null,quality,-1,-1,true);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
this.adjustDelay();
|
||||
this.currentFAI = oldCurrentFAI;
|
||||
this.refreshBootstrapInfo(quality);
|
||||
return new HTTPStreamRequest(null,quality,0,this.delay);
|
||||
}
|
||||
this.playInProgress = true;
|
||||
fdp = frt.fragmentDurationPairs[0];
|
||||
segId = abst.findSegmentId(this.currentFAI.fragId - fdp.firstFragment + 1);
|
||||
requestUrl = "";
|
||||
if((this.streamInfos[quality].streamName as String).indexOf("http") != 0)
|
||||
{
|
||||
requestUrl = this.serverBaseURL + "/" + this.streamInfos[quality].streamName + "Seg" + segId + "-Frag" + this.currentFAI.fragId;
|
||||
}
|
||||
else
|
||||
{
|
||||
requestUrl = this.streamInfos[quality].streamName + "Seg" + segId + "-Frag" + this.currentFAI.fragId;
|
||||
}
|
||||
streamRequest = new HTTPStreamRequest(requestUrl);
|
||||
this.checkQuality(quality);
|
||||
this.notifyFragmentDuration(this.currentFAI.fragDuration / abst.timeScale);
|
||||
}
|
||||
return streamRequest;
|
||||
}
|
||||
|
||||
internal function calculateSegmentDuration(abst:AdobeBootstrapBox, timeBias:Number) : Number
|
||||
{
|
||||
var fragmentDurationPair:FragmentDurationPair = null;
|
||||
var duration:Number = NaN;
|
||||
var durationAccrued:Number = NaN;
|
||||
var fragmentDurationPairs:Vector.<FragmentDurationPair> = abst.fragmentRunTables[0].fragmentDurationPairs;
|
||||
var fragmentId:uint = this.currentFAI.fragId;
|
||||
var index:int = fragmentDurationPairs.length - 1;
|
||||
while(index >= 0)
|
||||
{
|
||||
fragmentDurationPair = fragmentDurationPairs[index];
|
||||
if(fragmentDurationPair.firstFragment <= fragmentId)
|
||||
{
|
||||
duration = fragmentDurationPair.duration;
|
||||
durationAccrued = fragmentDurationPair.durationAccrued;
|
||||
durationAccrued += (fragmentId - fragmentDurationPair.firstFragment) * fragmentDurationPair.duration;
|
||||
if(timeBias > 0)
|
||||
{
|
||||
duration -= timeBias - durationAccrued;
|
||||
}
|
||||
return duration;
|
||||
}
|
||||
index--;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private function checkQuality(quality:int) : void
|
||||
{
|
||||
var prevAdditionalHeader:ByteArray = null;
|
||||
var newAdditionalHeader:ByteArray = null;
|
||||
var flvTag:FLVTagScriptDataObject = null;
|
||||
if(this.currentQuality != quality)
|
||||
{
|
||||
prevAdditionalHeader = this.currentQuality < 0 ? null : this.streamInfos[this.currentQuality].additionalHeader;
|
||||
this.currentQuality = quality;
|
||||
newAdditionalHeader = this.streamInfos[this.currentQuality].additionalHeader;
|
||||
if(newAdditionalHeader != prevAdditionalHeader && newAdditionalHeader != null)
|
||||
{
|
||||
flvTag = new FLVTagScriptDataObject();
|
||||
flvTag.data = newAdditionalHeader;
|
||||
dispatchEvent(new HTTPStreamingIndexHandlerEvent(HTTPStreamingIndexHandlerEvent.NOTIFY_SCRIPT_DATA,false,false,false,NaN,null,null,null,null,true,0,flvTag,true,false));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function checkMetadata(quality:int, abst:AdobeBootstrapBox) : void
|
||||
{
|
||||
if(this.currentQuality != quality)
|
||||
{
|
||||
this.notifyTotalDuration(abst.totalDuration / abst.timeScale,quality);
|
||||
}
|
||||
}
|
||||
|
||||
private function refreshBootstrapInfo(quality:uint) : void
|
||||
{
|
||||
++this.pendingIndexUpdates;
|
||||
this.fragmentRunTablesUpdating = true;
|
||||
dispatchEvent(new HTTPStreamingIndexHandlerEvent(HTTPStreamingIndexHandlerEvent.REQUEST_LOAD_INDEX,false,false,false,NaN,null,null,new URLRequest(HTTPStreamingUtils.normalizeURL((this.streamInfos[quality] as HTTPStreamingF4FStreamInfo).bootstrapInfo.url)),quality,true));
|
||||
}
|
||||
|
||||
private function processBootstrapData(data:*, indexContext:Object) : AdobeBootstrapBox
|
||||
{
|
||||
var boxes:Vector.<Box> = null;
|
||||
var bootstrapBox:AdobeBootstrapBox = null;
|
||||
var parser:BoxParser = new BoxParser();
|
||||
data.position = 0;
|
||||
parser.init(data);
|
||||
try
|
||||
{
|
||||
boxes = parser.getBoxes();
|
||||
}
|
||||
catch(e:Error)
|
||||
{
|
||||
boxes = null;
|
||||
}
|
||||
if(boxes == null || boxes.length < 1)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
bootstrapBox = boxes[0] as AdobeBootstrapBox;
|
||||
if(bootstrapBox == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if(this.serverBaseURL == null || this.serverBaseURL.length <= 0)
|
||||
{
|
||||
if(bootstrapBox.serverBaseURLs == null || bootstrapBox.serverBaseURLs.length <= 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return bootstrapBox;
|
||||
}
|
||||
|
||||
private function getQualityRates(streamInfos:Vector.<HTTPStreamingF4FStreamInfo>) : Array
|
||||
{
|
||||
var i:int = 0;
|
||||
var streamInfo:HTTPStreamingF4FStreamInfo = null;
|
||||
var rates:Array = [];
|
||||
if(streamInfos.length >= 1)
|
||||
{
|
||||
for(i = 0; i < streamInfos.length; i++)
|
||||
{
|
||||
streamInfo = streamInfos[i] as HTTPStreamingF4FStreamInfo;
|
||||
rates.push(streamInfo.bitrate);
|
||||
}
|
||||
}
|
||||
return rates;
|
||||
}
|
||||
|
||||
private function getStreamNames(streamInfos:Vector.<HTTPStreamingF4FStreamInfo>) : Array
|
||||
{
|
||||
var i:int = 0;
|
||||
var streamInfo:HTTPStreamingF4FStreamInfo = null;
|
||||
var streamNames:Array = [];
|
||||
if(streamInfos.length >= 1)
|
||||
{
|
||||
for(i = 0; i < streamInfos.length; i++)
|
||||
{
|
||||
streamInfo = streamInfos[i] as HTTPStreamingF4FStreamInfo;
|
||||
streamNames.push(streamInfo.streamName);
|
||||
}
|
||||
}
|
||||
return streamNames;
|
||||
}
|
||||
|
||||
private function getFragmentRunTable(abst:AdobeBootstrapBox) : AdobeFragmentRunTable
|
||||
{
|
||||
return abst.fragmentRunTables[0];
|
||||
}
|
||||
|
||||
private function notifyTotalDuration(duration:Number, quality:int) : void
|
||||
{
|
||||
var sdo:FLVTagScriptDataObject = new FLVTagScriptDataObject();
|
||||
var metaInfo:Object = this.f4fIndexInfo.streamInfos[quality].streamMetadata;
|
||||
if(metaInfo == null)
|
||||
{
|
||||
metaInfo = new Object();
|
||||
}
|
||||
metaInfo.duration = duration;
|
||||
sdo.objects = ["onMetaData",metaInfo];
|
||||
dispatchEvent(new HTTPStreamingIndexHandlerEvent(HTTPStreamingIndexHandlerEvent.NOTIFY_SCRIPT_DATA,false,false,false,NaN,null,null,null,null,false,0,sdo,false,true));
|
||||
}
|
||||
|
||||
private function notifyFragmentDuration(duration:Number) : void
|
||||
{
|
||||
dispatchEvent(new HTTPStreamingIndexHandlerEvent(HTTPStreamingIndexHandlerEvent.NOTIFY_SEGMENT_DURATION,false,false,false,NaN,null,null,null,null,true,duration));
|
||||
}
|
||||
|
||||
private function notifyIndexReady(quality:int) : void
|
||||
{
|
||||
var abst:AdobeBootstrapBox = this.bootstrapBoxes[quality];
|
||||
var frt:AdobeFragmentRunTable = this.getFragmentRunTable(abst);
|
||||
this.dispatchDVRStreamInfo(abst);
|
||||
if(!this.dvrGetStreamInfoCall)
|
||||
{
|
||||
if(abst.live && this.f4fIndexInfo.dvrInfo == null && isNaN(this.pureLiveOffset))
|
||||
{
|
||||
this.pureLiveOffset = abst.currentMediaTime - this.offsetFromCurrent * abst.timeScale > 0 ? abst.currentMediaTime / abst.timeScale - this.offsetFromCurrent : NaN;
|
||||
}
|
||||
dispatchEvent(new HTTPStreamingIndexHandlerEvent(HTTPStreamingIndexHandlerEvent.NOTIFY_INDEX_READY,false,false,abst.live,this.pureLiveOffset));
|
||||
}
|
||||
this.dvrGetStreamInfoCall = false;
|
||||
}
|
||||
|
||||
private function stopPlaying(abst:AdobeBootstrapBox) : Boolean
|
||||
{
|
||||
var frt:AdobeFragmentRunTable = this.getFragmentRunTable(abst);
|
||||
if(this.f4fIndexInfo.dvrInfo == null && abst.live && frt.tableComplete() || this.f4fIndexInfo.dvrInfo != null && this.f4fIndexInfo.dvrInfo.offline)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private function onNewBootstrapBox(event:HTTPStreamingFileHandlerEvent) : void
|
||||
{
|
||||
var abst:AdobeBootstrapBox = this.bootstrapBoxes[this.currentQuality];
|
||||
if(abst.bootstrapVersion < event.bootstrapBox.bootstrapVersion || abst.currentMediaTime < event.bootstrapBox.currentMediaTime)
|
||||
{
|
||||
this.bootstrapBoxes[this.currentQuality] = event.bootstrapBox;
|
||||
this.dispatchDVRStreamInfo(event.bootstrapBox);
|
||||
}
|
||||
}
|
||||
|
||||
private function dispatchDVRStreamInfo(abst:AdobeBootstrapBox) : void
|
||||
{
|
||||
var frt:AdobeFragmentRunTable = this.getFragmentRunTable(abst);
|
||||
if(this.f4fIndexInfo.dvrInfo != null)
|
||||
{
|
||||
this.f4fIndexInfo.dvrInfo.isRecording = !frt.tableComplete();
|
||||
if(isNaN(this.f4fIndexInfo.dvrInfo.startTime))
|
||||
{
|
||||
this.f4fIndexInfo.dvrInfo.startTime = frt.tableComplete() ? 0 : DVRUtils.calculateOffset(this.f4fIndexInfo.dvrInfo.beginOffset < 0 || isNaN(this.f4fIndexInfo.dvrInfo.beginOffset) ? 0 : this.f4fIndexInfo.dvrInfo.beginOffset,this.f4fIndexInfo.dvrInfo.endOffset < 0 || isNaN(this.f4fIndexInfo.dvrInfo.endOffset) ? 0 : this.f4fIndexInfo.dvrInfo.endOffset,abst.totalDuration / abst.timeScale);
|
||||
this.f4fIndexInfo.dvrInfo.startTime += frt.fragmentDurationPairs[0].durationAccrued / abst.timeScale;
|
||||
if(this.f4fIndexInfo.dvrInfo.startTime > abst.currentMediaTime)
|
||||
{
|
||||
this.f4fIndexInfo.dvrInfo.startTime = abst.currentMediaTime;
|
||||
}
|
||||
}
|
||||
this.f4fIndexInfo.dvrInfo.curLength = abst.currentMediaTime / abst.timeScale - this.f4fIndexInfo.dvrInfo.startTime;
|
||||
dispatchEvent(new DVRStreamInfoEvent(DVRStreamInfoEvent.DVRSTREAMINFO,false,false,this.f4fIndexInfo.dvrInfo));
|
||||
}
|
||||
}
|
||||
|
||||
private function fragmentOverflow(abst:AdobeBootstrapBox, fragId:uint) : Boolean
|
||||
{
|
||||
var fragmentRunTable:AdobeFragmentRunTable = abst.fragmentRunTables[0];
|
||||
var fdp:FragmentDurationPair = fragmentRunTable.fragmentDurationPairs[0];
|
||||
var segmentRunTable:AdobeSegmentRunTable = abst.segmentRunTables[0];
|
||||
return segmentRunTable == null || segmentRunTable.totalFragments + fdp.firstFragment - 1 < fragId;
|
||||
}
|
||||
|
||||
private function adjustDelay() : void
|
||||
{
|
||||
if(this.delay < 1)
|
||||
{
|
||||
this.delay *= 2;
|
||||
if(this.delay > 1)
|
||||
{
|
||||
this.delay = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
package org.osmf.net.httpstreaming.f4f
|
||||
{
|
||||
import org.osmf.net.httpstreaming.HTTPStreamingIndexInfoBase;
|
||||
import org.osmf.net.httpstreaming.dvr.DVRInfo;
|
||||
|
||||
[ExcludeClass]
|
||||
public class HTTPStreamingF4FIndexInfo extends HTTPStreamingIndexInfoBase
|
||||
{
|
||||
|
||||
private var _serverBaseURL:String;
|
||||
|
||||
private var _dvrInfo:DVRInfo;
|
||||
|
||||
private var _streamInfos:Vector.<HTTPStreamingF4FStreamInfo>;
|
||||
|
||||
public function HTTPStreamingF4FIndexInfo(serverBaseURL:String = null, streamInfos:Vector.<HTTPStreamingF4FStreamInfo> = null, dvrInfo:DVRInfo = null)
|
||||
{
|
||||
super();
|
||||
this._serverBaseURL = serverBaseURL;
|
||||
this._streamInfos = streamInfos;
|
||||
this._dvrInfo = dvrInfo;
|
||||
}
|
||||
|
||||
public function get serverBaseURL() : String
|
||||
{
|
||||
return this._serverBaseURL;
|
||||
}
|
||||
|
||||
public function get streamInfos() : Vector.<HTTPStreamingF4FStreamInfo>
|
||||
{
|
||||
return this._streamInfos;
|
||||
}
|
||||
|
||||
public function get dvrInfo() : DVRInfo
|
||||
{
|
||||
return this._dvrInfo;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
package org.osmf.net.httpstreaming.f4f
|
||||
{
|
||||
import flash.utils.ByteArray;
|
||||
import org.osmf.elements.f4mClasses.BootstrapInfo;
|
||||
|
||||
[ExcludeClass]
|
||||
public class HTTPStreamingF4FStreamInfo
|
||||
{
|
||||
|
||||
private var _streamName:String;
|
||||
|
||||
private var _bitrate:Number;
|
||||
|
||||
private var _bootstrap:BootstrapInfo;
|
||||
|
||||
private var _additionalHeader:ByteArray;
|
||||
|
||||
private var _streamMetadata:Object;
|
||||
|
||||
private var _xmpMetadata:ByteArray;
|
||||
|
||||
public function HTTPStreamingF4FStreamInfo(bootstrap:BootstrapInfo, streamName:String, bitrate:Number, additionalHeader:ByteArray, streamMetadata:Object, xmpMetadata:ByteArray)
|
||||
{
|
||||
super();
|
||||
this._streamName = streamName;
|
||||
this._bitrate = bitrate;
|
||||
this._additionalHeader = additionalHeader;
|
||||
this._bootstrap = bootstrap;
|
||||
this._streamMetadata = streamMetadata;
|
||||
this._xmpMetadata = xmpMetadata;
|
||||
}
|
||||
|
||||
public function get streamName() : String
|
||||
{
|
||||
return this._streamName;
|
||||
}
|
||||
|
||||
public function get bitrate() : Number
|
||||
{
|
||||
return this._bitrate;
|
||||
}
|
||||
|
||||
public function get additionalHeader() : ByteArray
|
||||
{
|
||||
return this._additionalHeader;
|
||||
}
|
||||
|
||||
public function get bootstrapInfo() : BootstrapInfo
|
||||
{
|
||||
return this._bootstrap;
|
||||
}
|
||||
|
||||
public function get streamMetadata() : Object
|
||||
{
|
||||
return this._streamMetadata;
|
||||
}
|
||||
|
||||
public function get xmpMetadata() : ByteArray
|
||||
{
|
||||
return this._xmpMetadata;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
package org.osmf.net.httpstreaming.f4f
|
||||
{
|
||||
[ExcludeClass]
|
||||
internal class LocalRandomAccessEntry
|
||||
{
|
||||
|
||||
private var _time:Number;
|
||||
|
||||
private var _offset:Number;
|
||||
|
||||
public function LocalRandomAccessEntry()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public function get time() : Number
|
||||
{
|
||||
return this._time;
|
||||
}
|
||||
|
||||
public function set time(value:Number) : void
|
||||
{
|
||||
this._time = value;
|
||||
}
|
||||
|
||||
public function get offset() : Number
|
||||
{
|
||||
return this._offset;
|
||||
}
|
||||
|
||||
public function set offset(value:Number) : void
|
||||
{
|
||||
this._offset = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package org.osmf.net.httpstreaming.f4f
|
||||
{
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
[ExcludeClass]
|
||||
internal class MediaDataBox extends Box
|
||||
{
|
||||
|
||||
private var _data:ByteArray;
|
||||
|
||||
public function MediaDataBox()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public function get data() : ByteArray
|
||||
{
|
||||
return this._data;
|
||||
}
|
||||
|
||||
public function set data(value:ByteArray) : void
|
||||
{
|
||||
this._data = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
package org.osmf.net.httpstreaming.f4f
|
||||
{
|
||||
[ExcludeClass]
|
||||
internal class SegmentFragmentPair
|
||||
{
|
||||
|
||||
private var _firstSegment:uint;
|
||||
|
||||
private var _fragmentsPerSegment:uint;
|
||||
|
||||
private var _fragmentsAccrued:uint;
|
||||
|
||||
public function SegmentFragmentPair(firstSegment:uint, fragmentsPerSegment:uint)
|
||||
{
|
||||
super();
|
||||
this._firstSegment = firstSegment;
|
||||
this._fragmentsPerSegment = fragmentsPerSegment;
|
||||
}
|
||||
|
||||
public function get firstSegment() : uint
|
||||
{
|
||||
return this._firstSegment;
|
||||
}
|
||||
|
||||
public function get fragmentsPerSegment() : uint
|
||||
{
|
||||
return this._fragmentsPerSegment;
|
||||
}
|
||||
|
||||
public function set fragmentsAccrued(v:uint) : void
|
||||
{
|
||||
this._fragmentsAccrued = v;
|
||||
}
|
||||
|
||||
public function get fragmentsAccrued() : uint
|
||||
{
|
||||
return this._fragmentsAccrued;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,128 @@
|
||||
package org.osmf.net.httpstreaming.flv
|
||||
{
|
||||
import flash.utils.ByteArray;
|
||||
import flash.utils.IDataInput;
|
||||
import flash.utils.IDataOutput;
|
||||
|
||||
[ExcludeClass]
|
||||
public class FLVHeader
|
||||
{
|
||||
|
||||
public static const MIN_FILE_HEADER_BYTE_COUNT:int = 9;
|
||||
|
||||
private var _hasVideoTags:Boolean = true;
|
||||
|
||||
private var _hasAudioTags:Boolean = true;
|
||||
|
||||
private var offset:uint;
|
||||
|
||||
public function FLVHeader(input:IDataInput = null)
|
||||
{
|
||||
super();
|
||||
if(input != null)
|
||||
{
|
||||
this.readHeader(input);
|
||||
this.readRest(input);
|
||||
}
|
||||
}
|
||||
|
||||
public function get hasAudioTags() : Boolean
|
||||
{
|
||||
return this._hasAudioTags;
|
||||
}
|
||||
|
||||
public function set hasAudioTags(value:Boolean) : void
|
||||
{
|
||||
this._hasAudioTags = value;
|
||||
}
|
||||
|
||||
public function get hasVideoTags() : Boolean
|
||||
{
|
||||
return this._hasVideoTags;
|
||||
}
|
||||
|
||||
public function set hasVideoTags(value:Boolean) : void
|
||||
{
|
||||
this._hasVideoTags = value;
|
||||
}
|
||||
|
||||
public function write(output:IDataOutput) : void
|
||||
{
|
||||
output.writeByte(70);
|
||||
output.writeByte(76);
|
||||
output.writeByte(86);
|
||||
output.writeByte(1);
|
||||
var flags:uint = 0;
|
||||
if(this._hasAudioTags)
|
||||
{
|
||||
flags |= 4;
|
||||
}
|
||||
if(this._hasVideoTags)
|
||||
{
|
||||
flags |= 1;
|
||||
}
|
||||
output.writeByte(flags);
|
||||
var offsetToWrite:uint = uint(MIN_FILE_HEADER_BYTE_COUNT);
|
||||
output.writeUnsignedInt(offsetToWrite);
|
||||
var previousTagSize0:uint = 0;
|
||||
output.writeUnsignedInt(previousTagSize0);
|
||||
}
|
||||
|
||||
internal function readHeader(input:IDataInput) : void
|
||||
{
|
||||
if(input.bytesAvailable < MIN_FILE_HEADER_BYTE_COUNT)
|
||||
{
|
||||
throw new Error("FLVHeader() input too short");
|
||||
}
|
||||
if(input.readByte() != 70)
|
||||
{
|
||||
throw new Error("FLVHeader readHeader() Signature[0] not \'F\'");
|
||||
}
|
||||
if(input.readByte() != 76)
|
||||
{
|
||||
throw new Error("FLVHeader readHeader() Signature[1] not \'L\'");
|
||||
}
|
||||
if(input.readByte() != 86)
|
||||
{
|
||||
throw new Error("FLVHeader readHeader() Signature[2] not \'V\'");
|
||||
}
|
||||
if(input.readByte() != 1)
|
||||
{
|
||||
throw new Error("FLVHeader readHeader() Version not 0x01");
|
||||
}
|
||||
var flags:int = input.readByte();
|
||||
this._hasAudioTags = Boolean(flags & 4) ? true : false;
|
||||
this._hasVideoTags = Boolean(flags & 1) ? true : false;
|
||||
this.offset = input.readUnsignedInt();
|
||||
if(this.offset < MIN_FILE_HEADER_BYTE_COUNT)
|
||||
{
|
||||
throw new Error("FLVHeader() offset smaller than minimum");
|
||||
}
|
||||
}
|
||||
|
||||
internal function readRest(input:IDataInput) : void
|
||||
{
|
||||
var discard:ByteArray = null;
|
||||
if(this.offset > MIN_FILE_HEADER_BYTE_COUNT)
|
||||
{
|
||||
if(this.offset - MIN_FILE_HEADER_BYTE_COUNT < input.bytesAvailable - FLVTag.PREV_TAG_BYTE_COUNT)
|
||||
{
|
||||
throw new Error("FLVHeader() input too short for nonstandard offset");
|
||||
}
|
||||
discard = new ByteArray();
|
||||
input.readBytes(discard,0,this.offset - MIN_FILE_HEADER_BYTE_COUNT);
|
||||
}
|
||||
if(input.bytesAvailable < FLVTag.PREV_TAG_BYTE_COUNT)
|
||||
{
|
||||
throw new Error("FLVHeader() input too short for previousTagSize0");
|
||||
}
|
||||
input.readUnsignedInt();
|
||||
}
|
||||
|
||||
internal function get restBytesNeeded() : int
|
||||
{
|
||||
return FLVTag.PREV_TAG_BYTE_COUNT + (this.offset - MIN_FILE_HEADER_BYTE_COUNT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,176 @@
|
||||
package org.osmf.net.httpstreaming.flv
|
||||
{
|
||||
import flash.utils.ByteArray;
|
||||
import flash.utils.IDataInput;
|
||||
import flash.utils.IDataOutput;
|
||||
|
||||
[ExcludeClass]
|
||||
public class FLVParser
|
||||
{
|
||||
|
||||
private var state:String;
|
||||
|
||||
private var savedBytes:ByteArray;
|
||||
|
||||
private var currentTag:FLVTag = null;
|
||||
|
||||
private var flvHeader:FLVHeader;
|
||||
|
||||
public function FLVParser(startWithFileHeader:Boolean)
|
||||
{
|
||||
super();
|
||||
this.savedBytes = new ByteArray();
|
||||
if(startWithFileHeader)
|
||||
{
|
||||
this.state = FLVParserState.FILE_HEADER;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.state = FLVParserState.TYPE;
|
||||
}
|
||||
}
|
||||
|
||||
public function flush(output:IDataOutput) : void
|
||||
{
|
||||
output.writeBytes(this.savedBytes);
|
||||
}
|
||||
|
||||
public function parse(input:IDataInput, consumeAll:Boolean, onEachFLVTag:Function) : void
|
||||
{
|
||||
var source:IDataInput = null;
|
||||
var type:int = 0;
|
||||
var continueParsing:Boolean = true;
|
||||
while(continueParsing)
|
||||
{
|
||||
switch(this.state)
|
||||
{
|
||||
case FLVParserState.FILE_HEADER:
|
||||
source = this.byteSource(input,FLVHeader.MIN_FILE_HEADER_BYTE_COUNT);
|
||||
if(source != null)
|
||||
{
|
||||
this.flvHeader = new FLVHeader();
|
||||
this.flvHeader.readHeader(source);
|
||||
this.state = FLVParserState.FILE_HEADER_REST;
|
||||
}
|
||||
else
|
||||
{
|
||||
continueParsing = false;
|
||||
}
|
||||
break;
|
||||
case FLVParserState.FILE_HEADER_REST:
|
||||
source = this.byteSource(input,this.flvHeader.restBytesNeeded);
|
||||
if(source != null)
|
||||
{
|
||||
this.flvHeader.readRest(source);
|
||||
this.state = FLVParserState.TYPE;
|
||||
}
|
||||
else
|
||||
{
|
||||
continueParsing = false;
|
||||
}
|
||||
break;
|
||||
case FLVParserState.TYPE:
|
||||
source = this.byteSource(input,1);
|
||||
if(source != null)
|
||||
{
|
||||
type = source.readByte();
|
||||
switch(type)
|
||||
{
|
||||
case FLVTag.TAG_TYPE_AUDIO:
|
||||
case FLVTag.TAG_TYPE_ENCRYPTED_AUDIO:
|
||||
this.currentTag = new FLVTagAudio(type);
|
||||
break;
|
||||
case FLVTag.TAG_TYPE_VIDEO:
|
||||
case FLVTag.TAG_TYPE_ENCRYPTED_VIDEO:
|
||||
this.currentTag = new FLVTagVideo(type);
|
||||
break;
|
||||
case FLVTag.TAG_TYPE_SCRIPTDATAOBJECT:
|
||||
case FLVTag.TAG_TYPE_ENCRYPTED_SCRIPTDATAOBJECT:
|
||||
this.currentTag = new FLVTagScriptDataObject(type);
|
||||
break;
|
||||
default:
|
||||
this.currentTag = new FLVTag(type);
|
||||
}
|
||||
this.state = FLVParserState.HEADER;
|
||||
}
|
||||
else
|
||||
{
|
||||
continueParsing = false;
|
||||
}
|
||||
break;
|
||||
case FLVParserState.HEADER:
|
||||
source = this.byteSource(input,FLVTag.TAG_HEADER_BYTE_COUNT - 1);
|
||||
if(source != null)
|
||||
{
|
||||
this.currentTag.readRemainingHeader(source);
|
||||
if(Boolean(this.currentTag.dataSize))
|
||||
{
|
||||
this.state = FLVParserState.DATA;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.state = FLVParserState.PREV_TAG;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
continueParsing = false;
|
||||
}
|
||||
break;
|
||||
case FLVParserState.DATA:
|
||||
source = this.byteSource(input,this.currentTag.dataSize);
|
||||
if(source != null)
|
||||
{
|
||||
this.currentTag.readData(source);
|
||||
this.state = FLVParserState.PREV_TAG;
|
||||
}
|
||||
else
|
||||
{
|
||||
continueParsing = false;
|
||||
}
|
||||
break;
|
||||
case FLVParserState.PREV_TAG:
|
||||
source = this.byteSource(input,FLVTag.PREV_TAG_BYTE_COUNT);
|
||||
if(source != null)
|
||||
{
|
||||
this.currentTag.readPrevTag(source);
|
||||
this.state = FLVParserState.TYPE;
|
||||
continueParsing = onEachFLVTag(this.currentTag);
|
||||
}
|
||||
else
|
||||
{
|
||||
continueParsing = false;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new Error("FLVParser state machine in unknown state");
|
||||
}
|
||||
}
|
||||
if(consumeAll)
|
||||
{
|
||||
input.readBytes(this.savedBytes,this.savedBytes.length);
|
||||
}
|
||||
}
|
||||
|
||||
private function byteSource(input:IDataInput, numBytes:int) : IDataInput
|
||||
{
|
||||
var needed:int = 0;
|
||||
if(this.savedBytes.bytesAvailable + input.bytesAvailable < numBytes)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if(Boolean(this.savedBytes.bytesAvailable))
|
||||
{
|
||||
needed = numBytes - this.savedBytes.bytesAvailable;
|
||||
if(needed > 0)
|
||||
{
|
||||
input.readBytes(this.savedBytes,this.savedBytes.length,needed);
|
||||
}
|
||||
return this.savedBytes;
|
||||
}
|
||||
this.savedBytes.length = 0;
|
||||
return input;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package org.osmf.net.httpstreaming.flv
|
||||
{
|
||||
[ExcludeClass]
|
||||
internal class FLVParserState
|
||||
{
|
||||
|
||||
internal static const FILE_HEADER:String = "fileHeader";
|
||||
|
||||
internal static const FILE_HEADER_REST:String = "fileHeaderRest";
|
||||
|
||||
internal static const TYPE:String = "type";
|
||||
|
||||
internal static const HEADER:String = "header";
|
||||
|
||||
internal static const DATA:String = "data";
|
||||
|
||||
internal static const PREV_TAG:String = "prevTag";
|
||||
|
||||
public function FLVParserState()
|
||||
{
|
||||
super();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,156 @@
|
||||
package org.osmf.net.httpstreaming.flv
|
||||
{
|
||||
import flash.utils.ByteArray;
|
||||
import flash.utils.IDataInput;
|
||||
import flash.utils.IDataOutput;
|
||||
|
||||
[ExcludeClass]
|
||||
public class FLVTag
|
||||
{
|
||||
|
||||
public static const TAG_TYPE_AUDIO:int = 8;
|
||||
|
||||
public static const TAG_TYPE_VIDEO:int = 9;
|
||||
|
||||
public static const TAG_TYPE_SCRIPTDATAOBJECT:int = 18;
|
||||
|
||||
public static const TAG_FLAG_ENCRYPTED:int = 32;
|
||||
|
||||
public static const TAG_TYPE_ENCRYPTED_AUDIO:int = TAG_TYPE_AUDIO + TAG_FLAG_ENCRYPTED;
|
||||
|
||||
public static const TAG_TYPE_ENCRYPTED_VIDEO:int = TAG_TYPE_VIDEO + TAG_FLAG_ENCRYPTED;
|
||||
|
||||
public static const TAG_TYPE_ENCRYPTED_SCRIPTDATAOBJECT:int = TAG_TYPE_SCRIPTDATAOBJECT + TAG_FLAG_ENCRYPTED;
|
||||
|
||||
internal static const TAG_HEADER_BYTE_COUNT:int = 11;
|
||||
|
||||
internal static const PREV_TAG_BYTE_COUNT:int = 4;
|
||||
|
||||
protected var bytes:ByteArray = null;
|
||||
|
||||
public function FLVTag(type:int)
|
||||
{
|
||||
super();
|
||||
this.bytes = new ByteArray();
|
||||
this.bytes.length = TAG_HEADER_BYTE_COUNT;
|
||||
this.bytes[0] = type;
|
||||
}
|
||||
|
||||
public function read(input:IDataInput) : void
|
||||
{
|
||||
this.readType(input);
|
||||
this.readRemainingHeader(input);
|
||||
this.readData(input);
|
||||
this.readPrevTag(input);
|
||||
}
|
||||
|
||||
public function readType(input:IDataInput) : void
|
||||
{
|
||||
if(input.bytesAvailable < 1)
|
||||
{
|
||||
throw new Error("FLVTag.readType() input too short");
|
||||
}
|
||||
input.readBytes(this.bytes,0,1);
|
||||
}
|
||||
|
||||
public function readRemaining(input:IDataInput) : void
|
||||
{
|
||||
this.readRemainingHeader(input);
|
||||
this.readData(input);
|
||||
this.readPrevTag(input);
|
||||
}
|
||||
|
||||
public function readRemainingHeader(input:IDataInput) : void
|
||||
{
|
||||
if(input.bytesAvailable < 10)
|
||||
{
|
||||
throw new Error("FLVTag.readHeader() input too short");
|
||||
}
|
||||
input.readBytes(this.bytes,1,TAG_HEADER_BYTE_COUNT - 1);
|
||||
}
|
||||
|
||||
public function readData(input:IDataInput) : void
|
||||
{
|
||||
if(this.dataSize > 0)
|
||||
{
|
||||
if(input.bytesAvailable < this.dataSize)
|
||||
{
|
||||
throw new Error("FLVTag().readData input shorter than dataSize");
|
||||
}
|
||||
input.readBytes(this.bytes,TAG_HEADER_BYTE_COUNT,this.dataSize);
|
||||
}
|
||||
}
|
||||
|
||||
public function readPrevTag(input:IDataInput) : void
|
||||
{
|
||||
if(input.bytesAvailable < 4)
|
||||
{
|
||||
throw new Error("FLVTag.readPrevTag() input too short");
|
||||
}
|
||||
input.readUnsignedInt();
|
||||
}
|
||||
|
||||
public function write(output:IDataOutput) : void
|
||||
{
|
||||
output.writeBytes(this.bytes,0,TAG_HEADER_BYTE_COUNT + this.dataSize);
|
||||
output.writeUnsignedInt(TAG_HEADER_BYTE_COUNT + this.dataSize);
|
||||
}
|
||||
|
||||
public function get tagType() : uint
|
||||
{
|
||||
return this.bytes[0];
|
||||
}
|
||||
|
||||
public function set tagType(value:uint) : void
|
||||
{
|
||||
this.bytes[0] = value;
|
||||
}
|
||||
|
||||
public function get isEncrpted() : Boolean
|
||||
{
|
||||
return Boolean(this.bytes[0] & TAG_FLAG_ENCRYPTED) ? true : false;
|
||||
}
|
||||
|
||||
public function get dataSize() : uint
|
||||
{
|
||||
return this.bytes[1] << 16 | this.bytes[2] << 8 | this.bytes[3];
|
||||
}
|
||||
|
||||
public function set dataSize(value:uint) : void
|
||||
{
|
||||
this.bytes[1] = value >> 16 & 0xFF;
|
||||
this.bytes[2] = value >> 8 & 0xFF;
|
||||
this.bytes[3] = value & 0xFF;
|
||||
this.bytes.length = TAG_HEADER_BYTE_COUNT + value;
|
||||
}
|
||||
|
||||
public function get timestamp() : uint
|
||||
{
|
||||
return this.bytes[7] << 24 | this.bytes[4] << 16 | this.bytes[5] << 8 | this.bytes[6];
|
||||
}
|
||||
|
||||
public function set timestamp(value:uint) : void
|
||||
{
|
||||
this.bytes[7] = value >> 24 & 0xFF;
|
||||
this.bytes[4] = value >> 16 & 0xFF;
|
||||
this.bytes[5] = value >> 8 & 0xFF;
|
||||
this.bytes[6] = value & 0xFF;
|
||||
}
|
||||
|
||||
public function get data() : ByteArray
|
||||
{
|
||||
var data:ByteArray = new ByteArray();
|
||||
data.writeBytes(this.bytes,TAG_HEADER_BYTE_COUNT,this.dataSize);
|
||||
return data;
|
||||
}
|
||||
|
||||
public function set data(value:ByteArray) : void
|
||||
{
|
||||
this.bytes.length = TAG_HEADER_BYTE_COUNT + value.length;
|
||||
this.bytes.position = TAG_HEADER_BYTE_COUNT;
|
||||
this.bytes.writeBytes(value,0,value.length);
|
||||
this.dataSize = value.length;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,247 @@
|
||||
package org.osmf.net.httpstreaming.flv
|
||||
{
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
[ExcludeClass]
|
||||
public class FLVTagAudio extends FLVTag
|
||||
{
|
||||
|
||||
public static const SOUND_FORMAT_LINEAR:int = 0;
|
||||
|
||||
public static const SOUND_FORMAT_ADPCM:int = 1;
|
||||
|
||||
public static const SOUND_FORMAT_MP3:int = 2;
|
||||
|
||||
public static const SOUND_FORMAT_LINEAR_LE:int = 3;
|
||||
|
||||
public static const SOUND_FORMAT_NELLYMOSER_16K:int = 4;
|
||||
|
||||
public static const SOUND_FORMAT_NELLYMOSER_8K:int = 5;
|
||||
|
||||
public static const SOUND_FORMAT_NELLYMOSER:int = 6;
|
||||
|
||||
public static const SOUND_FORMAT_G711A:int = 7;
|
||||
|
||||
public static const SOUND_FORMAT_G711U:int = 8;
|
||||
|
||||
public static const SOUND_FORMAT_AAC:int = 10;
|
||||
|
||||
public static const SOUND_FORMAT_SPEEX:int = 11;
|
||||
|
||||
public static const SOUND_FORMAT_MP3_8K:int = 14;
|
||||
|
||||
public static const SOUND_FORMAT_DEVICE_SPECIFIC:int = 15;
|
||||
|
||||
public static const SOUND_RATE_5K:Number = 5512.5;
|
||||
|
||||
public static const SOUND_RATE_11K:Number = 11025;
|
||||
|
||||
public static const SOUND_RATE_22K:Number = 22050;
|
||||
|
||||
public static const SOUND_RATE_44K:Number = 44100;
|
||||
|
||||
public static const SOUND_SIZE_8BITS:int = 8;
|
||||
|
||||
public static const SOUND_SIZE_16BITS:int = 16;
|
||||
|
||||
public static const SOUND_CHANNELS_MONO:int = 1;
|
||||
|
||||
public static const SOUND_CHANNELS_STEREO:int = 2;
|
||||
|
||||
public function FLVTagAudio(type:int = 8)
|
||||
{
|
||||
super(type);
|
||||
}
|
||||
|
||||
public function get soundFormatByte() : int
|
||||
{
|
||||
return bytes[TAG_HEADER_BYTE_COUNT + 0];
|
||||
}
|
||||
|
||||
public function set soundFormatByte(value:int) : void
|
||||
{
|
||||
bytes[TAG_HEADER_BYTE_COUNT + 0] = value;
|
||||
}
|
||||
|
||||
public function get soundFormat() : int
|
||||
{
|
||||
return bytes[TAG_HEADER_BYTE_COUNT + 0] >> 4 & 0x0F;
|
||||
}
|
||||
|
||||
public function set soundFormat(value:int) : void
|
||||
{
|
||||
bytes[TAG_HEADER_BYTE_COUNT + 0] &= 15;
|
||||
bytes[TAG_HEADER_BYTE_COUNT + 0] |= value << 4 & 0xF0;
|
||||
if(value == SOUND_FORMAT_AAC)
|
||||
{
|
||||
this.soundRate = SOUND_RATE_44K;
|
||||
this.soundChannels = SOUND_CHANNELS_STEREO;
|
||||
this.isAACSequenceHeader = false;
|
||||
}
|
||||
}
|
||||
|
||||
public function get soundRate() : Number
|
||||
{
|
||||
switch(bytes[TAG_HEADER_BYTE_COUNT + 0] >> 2 & 3)
|
||||
{
|
||||
case 0:
|
||||
return SOUND_RATE_5K;
|
||||
case 1:
|
||||
return SOUND_RATE_11K;
|
||||
case 2:
|
||||
return SOUND_RATE_22K;
|
||||
case 3:
|
||||
return SOUND_RATE_44K;
|
||||
default:
|
||||
throw new Error("get soundRate() a two-bit number wasn\'t 0, 1, 2, or 3. impossible.");
|
||||
}
|
||||
}
|
||||
|
||||
public function set soundRate(value:Number) : void
|
||||
{
|
||||
var setting:int = 0;
|
||||
switch(value)
|
||||
{
|
||||
case SOUND_RATE_5K:
|
||||
setting = 0;
|
||||
break;
|
||||
case SOUND_RATE_11K:
|
||||
setting = 1;
|
||||
break;
|
||||
case SOUND_RATE_22K:
|
||||
setting = 2;
|
||||
break;
|
||||
case SOUND_RATE_44K:
|
||||
setting = 3;
|
||||
break;
|
||||
default:
|
||||
throw new Error("set soundRate valid values 5512.5, 11025, 22050, 44100");
|
||||
}
|
||||
bytes[TAG_HEADER_BYTE_COUNT + 0] &= 243;
|
||||
bytes[TAG_HEADER_BYTE_COUNT + 0] |= setting << 2;
|
||||
}
|
||||
|
||||
public function get soundSize() : int
|
||||
{
|
||||
if(Boolean(bytes[TAG_HEADER_BYTE_COUNT + 0] >> 1 & 1))
|
||||
{
|
||||
return SOUND_SIZE_16BITS;
|
||||
}
|
||||
return SOUND_SIZE_8BITS;
|
||||
}
|
||||
|
||||
public function set soundSize(value:int) : void
|
||||
{
|
||||
switch(value)
|
||||
{
|
||||
case SOUND_SIZE_8BITS:
|
||||
bytes[TAG_HEADER_BYTE_COUNT + 0] &= 253;
|
||||
break;
|
||||
case SOUND_SIZE_16BITS:
|
||||
bytes[TAG_HEADER_BYTE_COUNT + 0] |= 2;
|
||||
break;
|
||||
default:
|
||||
throw new Error("set soundSize valid values 8, 16");
|
||||
}
|
||||
}
|
||||
|
||||
public function get soundChannels() : int
|
||||
{
|
||||
if(Boolean(bytes[TAG_HEADER_BYTE_COUNT + 0] & 1))
|
||||
{
|
||||
return SOUND_CHANNELS_STEREO;
|
||||
}
|
||||
return SOUND_CHANNELS_MONO;
|
||||
}
|
||||
|
||||
public function set soundChannels(value:int) : void
|
||||
{
|
||||
switch(value)
|
||||
{
|
||||
case SOUND_CHANNELS_MONO:
|
||||
bytes[TAG_HEADER_BYTE_COUNT + 0] &= 254;
|
||||
break;
|
||||
case SOUND_CHANNELS_STEREO:
|
||||
bytes[TAG_HEADER_BYTE_COUNT + 0] |= 1;
|
||||
break;
|
||||
default:
|
||||
throw new Error("set soundChannels valid values 1, 2");
|
||||
}
|
||||
}
|
||||
|
||||
public function get isAACSequenceHeader() : Boolean
|
||||
{
|
||||
if(this.soundFormat != SOUND_FORMAT_AAC)
|
||||
{
|
||||
throw new Error("get isAACSequenceHeader not valid if soundFormat != SOUND_FORMAT_AAC");
|
||||
}
|
||||
if(bytes[TAG_HEADER_BYTE_COUNT + 1] == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function set isAACSequenceHeader(value:Boolean) : void
|
||||
{
|
||||
if(this.soundFormat != SOUND_FORMAT_AAC)
|
||||
{
|
||||
throw new Error("set isAACSequenceHeader not valid if soundFormat != SOUND_FORMAT_AAC");
|
||||
}
|
||||
if(value)
|
||||
{
|
||||
bytes[TAG_HEADER_BYTE_COUNT + 1] = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
bytes[TAG_HEADER_BYTE_COUNT + 1] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
public function get isCodecConfiguration() : Boolean
|
||||
{
|
||||
switch(this.soundFormat)
|
||||
{
|
||||
case FLVTagAudio.SOUND_FORMAT_AAC:
|
||||
if(this.isAACSequenceHeader)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
override public function get data() : ByteArray
|
||||
{
|
||||
var data:ByteArray = new ByteArray();
|
||||
if(this.soundFormat == SOUND_FORMAT_AAC)
|
||||
{
|
||||
data.writeBytes(bytes,TAG_HEADER_BYTE_COUNT + 2,dataSize - 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
data.writeBytes(bytes,TAG_HEADER_BYTE_COUNT + 1,dataSize - 1);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
override public function set data(value:ByteArray) : void
|
||||
{
|
||||
if(this.soundFormat == SOUND_FORMAT_AAC)
|
||||
{
|
||||
bytes.length = TAG_HEADER_BYTE_COUNT + value.length + 2;
|
||||
bytes.position = TAG_HEADER_BYTE_COUNT + 2;
|
||||
bytes.writeBytes(value,0,value.length);
|
||||
dataSize = value.length + 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
bytes.length = TAG_HEADER_BYTE_COUNT + value.length + 1;
|
||||
bytes.position = TAG_HEADER_BYTE_COUNT + 1;
|
||||
bytes.writeBytes(value,0,value.length);
|
||||
dataSize = value.length + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
package org.osmf.net.httpstreaming.flv
|
||||
{
|
||||
import flash.net.ObjectEncoding;
|
||||
|
||||
[ExcludeClass]
|
||||
public class FLVTagScriptDataObject extends FLVTag
|
||||
{
|
||||
|
||||
public function FLVTagScriptDataObject(type:int = 18)
|
||||
{
|
||||
super(type);
|
||||
}
|
||||
|
||||
public function get objects() : Array
|
||||
{
|
||||
var array:Array = new Array();
|
||||
bytes.position = TAG_HEADER_BYTE_COUNT;
|
||||
while(Boolean(bytes.bytesAvailable))
|
||||
{
|
||||
array.push(bytes.readObject());
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
public function set objects(array:Array) : void
|
||||
{
|
||||
var object:Object = null;
|
||||
bytes.objectEncoding = ObjectEncoding.AMF0;
|
||||
bytes.length = TAG_HEADER_BYTE_COUNT;
|
||||
bytes.position = TAG_HEADER_BYTE_COUNT;
|
||||
for each(object in array)
|
||||
{
|
||||
bytes.writeObject(object);
|
||||
}
|
||||
dataSize = bytes.length - TAG_HEADER_BYTE_COUNT;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,176 @@
|
||||
package org.osmf.net.httpstreaming.flv
|
||||
{
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
[ExcludeClass]
|
||||
public class FLVTagVideo extends FLVTag
|
||||
{
|
||||
|
||||
public static const FRAME_TYPE_KEYFRAME:int = 1;
|
||||
|
||||
public static const FRAME_TYPE_INTER:int = 2;
|
||||
|
||||
public static const FRAME_TYPE_DISPOSABLE_INTER:int = 3;
|
||||
|
||||
public static const FRAME_TYPE_GENERATED_KEYFRAME:int = 4;
|
||||
|
||||
public static const FRAME_TYPE_INFO:int = 5;
|
||||
|
||||
public static const CODEC_ID_JPEG:int = 1;
|
||||
|
||||
public static const CODEC_ID_SORENSON:int = 2;
|
||||
|
||||
public static const CODEC_ID_SCREEN:int = 3;
|
||||
|
||||
public static const CODEC_ID_VP6:int = 4;
|
||||
|
||||
public static const CODEC_ID_VP6_ALPHA:int = 5;
|
||||
|
||||
public static const CODEC_ID_SCREEN_V2:int = 6;
|
||||
|
||||
public static const CODEC_ID_AVC:int = 7;
|
||||
|
||||
public static const AVC_PACKET_TYPE_SEQUENCE_HEADER:int = 0;
|
||||
|
||||
public static const AVC_PACKET_TYPE_NALU:int = 1;
|
||||
|
||||
public static const AVC_PACKET_TYPE_END_OF_SEQUENCE:int = 2;
|
||||
|
||||
public static const INFO_PACKET_SEEK_START:int = 0;
|
||||
|
||||
public static const INFO_PACKET_SEEK_END:int = 1;
|
||||
|
||||
public function FLVTagVideo(type:int = 9)
|
||||
{
|
||||
super(type);
|
||||
}
|
||||
|
||||
public function get frameType() : int
|
||||
{
|
||||
return bytes[TAG_HEADER_BYTE_COUNT + 0] >> 4 & 0x0F;
|
||||
}
|
||||
|
||||
public function set frameType(value:int) : void
|
||||
{
|
||||
bytes[TAG_HEADER_BYTE_COUNT + 0] &= 15;
|
||||
bytes[TAG_HEADER_BYTE_COUNT + 0] |= (value & 0x0F) << 4;
|
||||
}
|
||||
|
||||
public function get codecID() : int
|
||||
{
|
||||
return bytes[TAG_HEADER_BYTE_COUNT + 0] & 0x0F;
|
||||
}
|
||||
|
||||
public function set codecID(value:int) : void
|
||||
{
|
||||
bytes[TAG_HEADER_BYTE_COUNT + 0] &= 240;
|
||||
bytes[TAG_HEADER_BYTE_COUNT + 0] |= value & 0x0F;
|
||||
}
|
||||
|
||||
public function get infoPacketValue() : int
|
||||
{
|
||||
if(this.frameType != FRAME_TYPE_INFO)
|
||||
{
|
||||
throw new Error("get infoPacketValue() not permitted unless frameType is FRAME_TYPE_INFO");
|
||||
}
|
||||
return bytes[TAG_HEADER_BYTE_COUNT + 1];
|
||||
}
|
||||
|
||||
public function set infoPacketValue(value:int) : void
|
||||
{
|
||||
if(this.frameType != FRAME_TYPE_INFO)
|
||||
{
|
||||
throw new Error("get infoPacketValue() not permitted unless frameType is FRAME_TYPE_INFO");
|
||||
}
|
||||
bytes[TAG_HEADER_BYTE_COUNT + 1] = value;
|
||||
bytes.length = TAG_HEADER_BYTE_COUNT + 2;
|
||||
dataSize = 2;
|
||||
}
|
||||
|
||||
public function get avcPacketType() : int
|
||||
{
|
||||
if(this.codecID != CODEC_ID_AVC)
|
||||
{
|
||||
throw new Error("get avcPacketType() not permitted unless codecID is CODEC_ID_AVC");
|
||||
}
|
||||
return bytes[TAG_HEADER_BYTE_COUNT + 1];
|
||||
}
|
||||
|
||||
public function set avcPacketType(value:int) : void
|
||||
{
|
||||
if(this.codecID != CODEC_ID_AVC)
|
||||
{
|
||||
throw new Error("set avcPacketType() not permitted unless codecID is CODEC_ID_AVC");
|
||||
}
|
||||
bytes[TAG_HEADER_BYTE_COUNT + 1] = value;
|
||||
if(this.avcPacketType != AVC_PACKET_TYPE_NALU)
|
||||
{
|
||||
bytes[TAG_HEADER_BYTE_COUNT + 2] = 0;
|
||||
bytes[TAG_HEADER_BYTE_COUNT + 3] = 0;
|
||||
bytes[TAG_HEADER_BYTE_COUNT + 4] = 0;
|
||||
bytes.length = TAG_HEADER_BYTE_COUNT + 5;
|
||||
dataSize = 5;
|
||||
}
|
||||
}
|
||||
|
||||
public function get avcCompositionTimeOffset() : int
|
||||
{
|
||||
if(this.codecID != CODEC_ID_AVC || this.avcPacketType != AVC_PACKET_TYPE_NALU)
|
||||
{
|
||||
throw new Error("get avcCompositionTimeOffset() not permitted unless codecID is CODEC_ID_AVC and avcPacketType is AVC NALU");
|
||||
}
|
||||
var value:int = bytes[TAG_HEADER_BYTE_COUNT + 2] << 16;
|
||||
value |= bytes[TAG_HEADER_BYTE_COUNT + 3] << 8;
|
||||
value |= bytes[TAG_HEADER_BYTE_COUNT + 4];
|
||||
if(Boolean(value & 0x800000))
|
||||
{
|
||||
value |= 4278190080;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public function set avcCompositionTimeOffset(value:int) : void
|
||||
{
|
||||
if(this.codecID != CODEC_ID_AVC || this.avcPacketType != AVC_PACKET_TYPE_NALU)
|
||||
{
|
||||
throw new Error("set avcCompositionTimeOffset() not permitted unless codecID is CODEC_ID_AVC and avcPacketType is AVC NALU");
|
||||
}
|
||||
bytes[TAG_HEADER_BYTE_COUNT + 2] = value >> 16 & 0xFF;
|
||||
bytes[TAG_HEADER_BYTE_COUNT + 3] = value >> 8 & 0xFF;
|
||||
bytes[TAG_HEADER_BYTE_COUNT + 4] = value & 0xFF;
|
||||
}
|
||||
|
||||
override public function get data() : ByteArray
|
||||
{
|
||||
var data:ByteArray = new ByteArray();
|
||||
if(this.codecID == CODEC_ID_AVC)
|
||||
{
|
||||
data.writeBytes(bytes,TAG_HEADER_BYTE_COUNT + 5,dataSize - 5);
|
||||
}
|
||||
else
|
||||
{
|
||||
data.writeBytes(bytes,TAG_HEADER_BYTE_COUNT + 1,dataSize - 1);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
override public function set data(value:ByteArray) : void
|
||||
{
|
||||
if(this.codecID == CODEC_ID_AVC)
|
||||
{
|
||||
bytes.length = TAG_HEADER_BYTE_COUNT + value.length + 5;
|
||||
bytes.position = TAG_HEADER_BYTE_COUNT + 5;
|
||||
bytes.writeBytes(value,0,value.length);
|
||||
dataSize = value.length + 5;
|
||||
}
|
||||
else
|
||||
{
|
||||
bytes.length = TAG_HEADER_BYTE_COUNT + value.length + 1;
|
||||
bytes.position = TAG_HEADER_BYTE_COUNT + 1;
|
||||
bytes.writeBytes(value,0,value.length);
|
||||
dataSize = value.length + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user