mirror of
https://github.com/burrow-dev/burrow-server.git
synced 2026-11-21 17: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,33 @@
|
||||
package org.osmf.net.dvr
|
||||
{
|
||||
[ExcludeClass]
|
||||
public class DVRCastConstants
|
||||
{
|
||||
|
||||
public static const RPC_GET_STREAM_INFO:String = "DVRGetStreamInfo";
|
||||
|
||||
public static const RPC_SUBSCRIBE:String = "DVRSubscribe";
|
||||
|
||||
public static const RPC_UNSUBSCRIBE:String = "DVRUnsubscribe";
|
||||
|
||||
public static const RESULT_GET_STREAM_INFO_SUCCESS:String = "NetStream.DVRStreamInfo.Success";
|
||||
|
||||
public static const RESULT_GET_STREAM_INFO_RETRY:String = "NetStream.DVRStreamInfo.Retry";
|
||||
|
||||
public static const STREAM_INFO_KEY:String = "http://www.osmf.org/dvrCast/1.0/streamInfo";
|
||||
|
||||
public static const RECORDING_INFO_KEY:String = "http://www.osmf.org/dvrCast/1.0/recordingInfo";
|
||||
|
||||
public static const STREAM_INFO_UPDATE_DELAY:Number = 3000;
|
||||
|
||||
public static const LOCAL_DURATION_UPDATE_INTERVAL:Number = 500;
|
||||
|
||||
public static const LIVE_POSITION_SEEK_DELAY:Number = 1.5;
|
||||
|
||||
public function DVRCastConstants()
|
||||
{
|
||||
super();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
package org.osmf.net.dvr
|
||||
{
|
||||
import flash.errors.IllegalOperationError;
|
||||
import flash.events.Event;
|
||||
import flash.events.TimerEvent;
|
||||
import flash.net.NetConnection;
|
||||
import flash.net.NetStream;
|
||||
import flash.utils.Timer;
|
||||
import org.osmf.events.MediaError;
|
||||
import org.osmf.events.MediaErrorCodes;
|
||||
import org.osmf.events.MediaErrorEvent;
|
||||
import org.osmf.media.MediaResourceBase;
|
||||
import org.osmf.traits.DVRTrait;
|
||||
import org.osmf.utils.OSMFStrings;
|
||||
|
||||
[ExcludeClass]
|
||||
internal class DVRCastDVRTrait extends DVRTrait
|
||||
{
|
||||
|
||||
private var connection:NetConnection;
|
||||
|
||||
private var stream:NetStream;
|
||||
|
||||
private var streamInfo:DVRCastStreamInfo;
|
||||
|
||||
private var recordingInfo:DVRCastRecordingInfo;
|
||||
|
||||
private var streamInfoUpdateTimer:Timer;
|
||||
|
||||
private var streamInfoRetriever:DVRCastStreamInfoRetriever;
|
||||
|
||||
private var offset:Number;
|
||||
|
||||
public function DVRCastDVRTrait(connection:NetConnection, stream:NetStream, resource:MediaResourceBase)
|
||||
{
|
||||
if(connection != null && stream != null)
|
||||
{
|
||||
this.stream = stream;
|
||||
this.streamInfo = resource.getMetadataValue(DVRCastConstants.STREAM_INFO_KEY) as DVRCastStreamInfo;
|
||||
this.recordingInfo = resource.getMetadataValue(DVRCastConstants.RECORDING_INFO_KEY) as DVRCastRecordingInfo;
|
||||
this.streamInfoRetriever = new DVRCastStreamInfoRetriever(connection,this.streamInfo.streamName);
|
||||
this.streamInfoRetriever.addEventListener(Event.COMPLETE,this.onStreamInfoRetrieverComplete);
|
||||
this.streamInfoUpdateTimer = new Timer(DVRCastConstants.STREAM_INFO_UPDATE_DELAY);
|
||||
this.streamInfoUpdateTimer.addEventListener(TimerEvent.TIMER,this.onStreamInfoUpdateTimer);
|
||||
this.streamInfoUpdateTimer.start();
|
||||
super(this.streamInfo.isRecording);
|
||||
this.updateProperties();
|
||||
return;
|
||||
}
|
||||
throw new IllegalOperationError(OSMFStrings.getString(OSMFStrings.NULL_PARAM));
|
||||
}
|
||||
|
||||
override protected function isRecordingChangeStart(value:Boolean) : void
|
||||
{
|
||||
if(value)
|
||||
{
|
||||
this.recordingInfo.startDuration = this.streamInfo.currentLength;
|
||||
this.recordingInfo.startTime = new Date();
|
||||
}
|
||||
}
|
||||
|
||||
private function updateProperties() : void
|
||||
{
|
||||
setIsRecording(this.streamInfo.isRecording);
|
||||
}
|
||||
|
||||
private function onStreamInfoUpdateTimer(event:TimerEvent) : void
|
||||
{
|
||||
this.streamInfoRetriever.retrieve();
|
||||
}
|
||||
|
||||
private function onStreamInfoRetrieverComplete(event:Event) : void
|
||||
{
|
||||
if(this.streamInfoRetriever.streamInfo != null)
|
||||
{
|
||||
this.streamInfo.readFromDVRCastStreamInfo(this.streamInfoRetriever.streamInfo);
|
||||
this.updateProperties();
|
||||
}
|
||||
else
|
||||
{
|
||||
dispatchEvent(new MediaErrorEvent(MediaErrorEvent.MEDIA_ERROR,false,false,new MediaError(MediaErrorCodes.DVRCAST_STREAM_INFO_RETRIEVAL_FAILED)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,153 @@
|
||||
package org.osmf.net.dvr
|
||||
{
|
||||
import flash.events.Event;
|
||||
import flash.net.NetConnection;
|
||||
import flash.net.Responder;
|
||||
import flash.utils.Dictionary;
|
||||
import org.osmf.events.MediaError;
|
||||
import org.osmf.events.MediaErrorCodes;
|
||||
import org.osmf.events.NetConnectionFactoryEvent;
|
||||
import org.osmf.media.URLResource;
|
||||
import org.osmf.net.DynamicStreamingItem;
|
||||
import org.osmf.net.DynamicStreamingResource;
|
||||
import org.osmf.net.NetConnectionFactory;
|
||||
import org.osmf.net.NetConnectionFactoryBase;
|
||||
import org.osmf.net.NetStreamUtils;
|
||||
import org.osmf.net.StreamingURLResource;
|
||||
|
||||
[ExcludeClass]
|
||||
public class DVRCastNetConnectionFactory extends NetConnectionFactoryBase
|
||||
{
|
||||
|
||||
private var innerFactory:NetConnectionFactoryBase;
|
||||
|
||||
private var subscribedStreams:Dictionary = new Dictionary();
|
||||
|
||||
public function DVRCastNetConnectionFactory(factory:NetConnectionFactoryBase = null)
|
||||
{
|
||||
this.innerFactory = factory || new NetConnectionFactory();
|
||||
this.innerFactory.addEventListener(NetConnectionFactoryEvent.CREATION_COMPLETE,this.onCreationComplete);
|
||||
this.innerFactory.addEventListener(NetConnectionFactoryEvent.CREATION_ERROR,this.onCreationError);
|
||||
super();
|
||||
}
|
||||
|
||||
override public function create(resource:URLResource) : void
|
||||
{
|
||||
this.innerFactory.create(resource);
|
||||
}
|
||||
|
||||
override public function closeNetConnection(netConnection:NetConnection) : void
|
||||
{
|
||||
var streamName:String = this.subscribedStreams[netConnection];
|
||||
if(streamName != null)
|
||||
{
|
||||
netConnection.call(DVRCastConstants.RPC_UNSUBSCRIBE,null,streamName);
|
||||
delete this.subscribedStreams[netConnection];
|
||||
}
|
||||
this.innerFactory.closeNetConnection(netConnection);
|
||||
}
|
||||
|
||||
private function onCreationComplete(event:NetConnectionFactoryEvent) : void
|
||||
{
|
||||
var urlIncludesFMSApplicationInstance:Boolean;
|
||||
var dynamicResource:DynamicStreamingResource;
|
||||
var responder:Responder;
|
||||
var urlResource:URLResource = null;
|
||||
var netConnection:NetConnection = null;
|
||||
var streamNames:Vector.<String> = null;
|
||||
var totalRpcSubscribeInvocation:int = 0;
|
||||
var streamingResource:StreamingURLResource = null;
|
||||
var onStreamSubscriptionResult:Function = null;
|
||||
var onStreamInfoRetrieverComplete:Function = null;
|
||||
var onServerCallError:Function = null;
|
||||
var items:Vector.<DynamicStreamingItem> = null;
|
||||
var i:int = 0;
|
||||
onStreamSubscriptionResult = function(result:Object):void
|
||||
{
|
||||
var streamInfoRetriever:DVRCastStreamInfoRetriever = null;
|
||||
--totalRpcSubscribeInvocation;
|
||||
if(totalRpcSubscribeInvocation <= 0)
|
||||
{
|
||||
streamInfoRetriever = new DVRCastStreamInfoRetriever(netConnection,streamNames[0]);
|
||||
streamInfoRetriever.addEventListener(Event.COMPLETE,onStreamInfoRetrieverComplete);
|
||||
streamInfoRetriever.retrieve();
|
||||
}
|
||||
};
|
||||
onStreamInfoRetrieverComplete = function(event:Event):void
|
||||
{
|
||||
var recordingInfo:DVRCastRecordingInfo = null;
|
||||
var streamInfoRetriever:DVRCastStreamInfoRetriever = event.target as DVRCastStreamInfoRetriever;
|
||||
removeEventListener(NetConnectionFactoryEvent.CREATION_COMPLETE,onCreationComplete);
|
||||
if(streamInfoRetriever.streamInfo != null)
|
||||
{
|
||||
if(streamInfoRetriever.streamInfo.offline == true)
|
||||
{
|
||||
dispatchEvent(new NetConnectionFactoryEvent(NetConnectionFactoryEvent.CREATION_ERROR,false,false,netConnection,urlResource,new MediaError(MediaErrorCodes.DVRCAST_CONTENT_OFFLINE)));
|
||||
for(i = 0; i < streamNames.length; ++i)
|
||||
{
|
||||
netConnection.call(DVRCastConstants.RPC_UNSUBSCRIBE,null,streamNames[i]);
|
||||
}
|
||||
netConnection = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
recordingInfo = new DVRCastRecordingInfo();
|
||||
recordingInfo.startDuration = streamInfoRetriever.streamInfo.currentLength;
|
||||
recordingInfo.startOffset = calculateOffset(streamInfoRetriever.streamInfo);
|
||||
recordingInfo.startTime = new Date();
|
||||
streamingResource.addMetadataValue(DVRCastConstants.STREAM_INFO_KEY,streamInfoRetriever.streamInfo);
|
||||
streamingResource.addMetadataValue(DVRCastConstants.RECORDING_INFO_KEY,recordingInfo);
|
||||
subscribedStreams[netConnection] = streamNames[0];
|
||||
dispatchEvent(new NetConnectionFactoryEvent(NetConnectionFactoryEvent.CREATION_COMPLETE,false,false,netConnection,urlResource));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
onServerCallError(streamInfoRetriever.error);
|
||||
}
|
||||
};
|
||||
onServerCallError = function(error:Object):void
|
||||
{
|
||||
dispatchEvent(new NetConnectionFactoryEvent(NetConnectionFactoryEvent.CREATION_ERROR,false,false,netConnection,urlResource,new MediaError(MediaErrorCodes.DVRCAST_SUBSCRIBE_FAILED,Boolean(error) ? error.message : "")));
|
||||
};
|
||||
urlResource = event.resource as URLResource;
|
||||
netConnection = event.netConnection;
|
||||
streamNames = new Vector.<String>();
|
||||
totalRpcSubscribeInvocation = 0;
|
||||
event.stopImmediatePropagation();
|
||||
streamingResource = urlResource as StreamingURLResource;
|
||||
urlIncludesFMSApplicationInstance = Boolean(streamingResource) ? streamingResource.urlIncludesFMSApplicationInstance : false;
|
||||
dynamicResource = streamingResource as DynamicStreamingResource;
|
||||
if(dynamicResource != null)
|
||||
{
|
||||
items = dynamicResource.streamItems;
|
||||
totalRpcSubscribeInvocation = int(items.length);
|
||||
for(i = 0; i < items.length; i++)
|
||||
{
|
||||
streamNames.push(items[i].streamName);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
totalRpcSubscribeInvocation = 1;
|
||||
streamNames.push(NetStreamUtils.getStreamNameFromURL(urlResource.url,urlIncludesFMSApplicationInstance));
|
||||
}
|
||||
responder = new TestableResponder(onStreamSubscriptionResult,onServerCallError);
|
||||
for(i = 0; i < streamNames.length; i++)
|
||||
{
|
||||
event.netConnection.call(DVRCastConstants.RPC_SUBSCRIBE,responder,streamNames[i]);
|
||||
}
|
||||
}
|
||||
|
||||
private function onCreationError(event:NetConnectionFactoryEvent) : void
|
||||
{
|
||||
dispatchEvent(event.clone());
|
||||
}
|
||||
|
||||
private function calculateOffset(streamInfo:DVRCastStreamInfo) : Number
|
||||
{
|
||||
return DVRUtils.calculateOffset(streamInfo.beginOffset,streamInfo.endOffset,streamInfo.currentLength);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
package org.osmf.net.dvr
|
||||
{
|
||||
import flash.net.NetConnection;
|
||||
import flash.net.NetStream;
|
||||
import org.osmf.media.MediaResourceBase;
|
||||
import org.osmf.media.URLResource;
|
||||
import org.osmf.net.NetStreamLoadTrait;
|
||||
import org.osmf.net.NetStreamUtils;
|
||||
import org.osmf.net.StreamType;
|
||||
import org.osmf.net.StreamingURLResource;
|
||||
import org.osmf.net.rtmpstreaming.RTMPDynamicStreamingNetLoader;
|
||||
import org.osmf.traits.LoadState;
|
||||
|
||||
public class DVRCastNetLoader extends RTMPDynamicStreamingNetLoader
|
||||
{
|
||||
|
||||
public function DVRCastNetLoader(factory:DVRCastNetConnectionFactory = null)
|
||||
{
|
||||
if(factory == null)
|
||||
{
|
||||
factory = new DVRCastNetConnectionFactory();
|
||||
}
|
||||
super(factory);
|
||||
}
|
||||
|
||||
override public function canHandleResource(resource:MediaResourceBase) : Boolean
|
||||
{
|
||||
var result:Boolean = false;
|
||||
var streamingURLResource:StreamingURLResource = null;
|
||||
if(super.canHandleResource(resource))
|
||||
{
|
||||
streamingURLResource = resource as StreamingURLResource;
|
||||
if(streamingURLResource != null)
|
||||
{
|
||||
result = streamingURLResource.streamType == StreamType.DVR && NetStreamUtils.isRTMPStream(streamingURLResource.url);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
override protected function createNetStream(connection:NetConnection, resource:URLResource) : NetStream
|
||||
{
|
||||
return new DVRCastNetStream(connection,resource);
|
||||
}
|
||||
|
||||
override protected function processFinishLoading(loadTrait:NetStreamLoadTrait) : void
|
||||
{
|
||||
loadTrait.setTrait(new DVRCastDVRTrait(loadTrait.connection,loadTrait.netStream,loadTrait.resource));
|
||||
loadTrait.setTrait(new DVRCastTimeTrait(loadTrait.connection,loadTrait.netStream,loadTrait.resource));
|
||||
updateLoadTrait(loadTrait,LoadState.READY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package org.osmf.net.dvr
|
||||
{
|
||||
import flash.net.NetConnection;
|
||||
import flash.net.NetStream;
|
||||
import flash.net.NetStreamPlayOptions;
|
||||
import org.osmf.media.MediaResourceBase;
|
||||
|
||||
[ExcludeClass]
|
||||
public class DVRCastNetStream extends NetStream
|
||||
{
|
||||
|
||||
private var recordingInfo:DVRCastRecordingInfo;
|
||||
|
||||
public function DVRCastNetStream(connection:NetConnection, resource:MediaResourceBase)
|
||||
{
|
||||
super(connection);
|
||||
this.recordingInfo = resource.getMetadataValue(DVRCastConstants.RECORDING_INFO_KEY) as DVRCastRecordingInfo;
|
||||
}
|
||||
|
||||
override public function play(... arguments) : void
|
||||
{
|
||||
super.play(arguments[0],this.recordingInfo.startOffset,-1);
|
||||
}
|
||||
|
||||
override public function play2(param:NetStreamPlayOptions) : void
|
||||
{
|
||||
if(Boolean(param))
|
||||
{
|
||||
param.start = this.recordingInfo.startOffset;
|
||||
param.len = -1;
|
||||
}
|
||||
super.play2(param);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package org.osmf.net.dvr
|
||||
{
|
||||
[ExcludeClass]
|
||||
public class DVRCastRecordingInfo
|
||||
{
|
||||
|
||||
public var startTime:Date = null;
|
||||
|
||||
public var startDuration:Number;
|
||||
|
||||
public var startOffset:Number;
|
||||
|
||||
public function DVRCastRecordingInfo()
|
||||
{
|
||||
super();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
package org.osmf.net.dvr
|
||||
{
|
||||
import flash.errors.IllegalOperationError;
|
||||
import org.osmf.utils.OSMFStrings;
|
||||
|
||||
[ExcludeClass]
|
||||
public class DVRCastStreamInfo
|
||||
{
|
||||
|
||||
public var callTime:Date;
|
||||
|
||||
public var offline:Boolean;
|
||||
|
||||
public var beginOffset:Number;
|
||||
|
||||
public var endOffset:Number;
|
||||
|
||||
public var recordingStart:Date;
|
||||
|
||||
public var recordingEnd:Date;
|
||||
|
||||
public var isRecording:Boolean;
|
||||
|
||||
public var streamName:String;
|
||||
|
||||
public var lastUpdate:Date;
|
||||
|
||||
public var currentLength:Number;
|
||||
|
||||
public var maxLength:Number;
|
||||
|
||||
public function DVRCastStreamInfo(value:Object)
|
||||
{
|
||||
super();
|
||||
this.readFromDynamicObject(value);
|
||||
}
|
||||
|
||||
public function readFromDynamicObject(value:Object) : void
|
||||
{
|
||||
try
|
||||
{
|
||||
this.callTime = value.callTime;
|
||||
this.offline = value.offline;
|
||||
this.beginOffset = value.begOffset;
|
||||
this.endOffset = value.endOffset;
|
||||
this.recordingStart = value.startRec;
|
||||
this.recordingEnd = value.stopRec;
|
||||
this.isRecording = value.isRec;
|
||||
this.streamName = value.streamName;
|
||||
this.lastUpdate = value.lastUpdate;
|
||||
this.currentLength = value.currLen;
|
||||
this.maxLength = value.maxLen;
|
||||
}
|
||||
catch(e:Error)
|
||||
{
|
||||
throw new IllegalOperationError(OSMFStrings.getString(OSMFStrings.INVALID_PARAM));
|
||||
}
|
||||
}
|
||||
|
||||
public function readFromDVRCastStreamInfo(value:DVRCastStreamInfo) : void
|
||||
{
|
||||
try
|
||||
{
|
||||
this.callTime = value.callTime;
|
||||
this.offline = value.offline;
|
||||
this.beginOffset = value.beginOffset;
|
||||
this.endOffset = value.endOffset;
|
||||
this.recordingStart = value.recordingStart;
|
||||
this.recordingEnd = value.recordingEnd;
|
||||
this.isRecording = value.isRecording;
|
||||
this.streamName = value.streamName;
|
||||
this.lastUpdate = value.lastUpdate;
|
||||
this.currentLength = value.currentLength;
|
||||
this.maxLength = value.maxLength;
|
||||
}
|
||||
catch(e:Error)
|
||||
{
|
||||
throw new IllegalOperationError(OSMFStrings.getString(OSMFStrings.INVALID_PARAM));
|
||||
}
|
||||
}
|
||||
|
||||
public function toString() : String
|
||||
{
|
||||
return "callTime: " + this.callTime + "\noffline: " + this.offline + "\nbeginOffset: " + this.beginOffset + "\nendOffset: " + this.endOffset + "\nrecordingStart: " + this.recordingStart + "\nrecordingEnd: " + this.recordingEnd + "\nisRecording: " + this.isRecording + "\nstreamName: " + this.streamName + "\nlastUpdate: " + this.lastUpdate + "\ncurrentLength: " + this.currentLength + "\nmaxLength: " + this.maxLength;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,117 @@
|
||||
package org.osmf.net.dvr
|
||||
{
|
||||
import flash.errors.IllegalOperationError;
|
||||
import flash.events.Event;
|
||||
import flash.events.EventDispatcher;
|
||||
import flash.events.TimerEvent;
|
||||
import flash.net.NetConnection;
|
||||
import flash.net.Responder;
|
||||
import flash.utils.Timer;
|
||||
import org.osmf.utils.OSMFStrings;
|
||||
|
||||
[Event(name="complete",type="flash.events.Event")]
|
||||
[ExcludeClass]
|
||||
internal class DVRCastStreamInfoRetriever extends EventDispatcher
|
||||
{
|
||||
|
||||
private var connection:NetConnection;
|
||||
|
||||
private var streamName:String;
|
||||
|
||||
private var retries:Number;
|
||||
|
||||
private var timer:Timer;
|
||||
|
||||
private var _streamInfo:DVRCastStreamInfo;
|
||||
|
||||
private var _error:Object;
|
||||
|
||||
public function DVRCastStreamInfoRetriever(connection:NetConnection, streamName:String)
|
||||
{
|
||||
super();
|
||||
if(connection == null || streamName == null)
|
||||
{
|
||||
throw new IllegalOperationError(OSMFStrings.getString(OSMFStrings.NULL_PARAM));
|
||||
}
|
||||
this.connection = connection;
|
||||
this.streamName = streamName;
|
||||
}
|
||||
|
||||
public function get streamInfo() : DVRCastStreamInfo
|
||||
{
|
||||
return this._streamInfo;
|
||||
}
|
||||
|
||||
public function get error() : Object
|
||||
{
|
||||
return this._error;
|
||||
}
|
||||
|
||||
public function retrieve(retries:int = 5, timeOut:Number = 3) : void
|
||||
{
|
||||
if(isNaN(this.retries))
|
||||
{
|
||||
retries ||= 1;
|
||||
this._streamInfo = null;
|
||||
this._error = this._error = {"message":OSMFStrings.getString(OSMFStrings.DVR_MAXIMUM_RPC_ATTEMPTS).replace("%i",retries)};
|
||||
this.retries = retries;
|
||||
this.timer = new Timer(timeOut * 1000,1);
|
||||
this.getStreamInfo();
|
||||
}
|
||||
}
|
||||
|
||||
private function getStreamInfo() : void
|
||||
{
|
||||
var responder:Responder = new TestableResponder(this.onGetStreamInfoResult,this.onServerCallError);
|
||||
--this.retries;
|
||||
this.connection.call(DVRCastConstants.RPC_GET_STREAM_INFO,responder,this.streamName);
|
||||
}
|
||||
|
||||
private function onGetStreamInfoResult(result:Object) : void
|
||||
{
|
||||
if(Boolean(result) && result.code == DVRCastConstants.RESULT_GET_STREAM_INFO_SUCCESS)
|
||||
{
|
||||
this._error = null;
|
||||
this._streamInfo = new DVRCastStreamInfo(result.data);
|
||||
this.complete();
|
||||
}
|
||||
else if(Boolean(result) && result.code == DVRCastConstants.RESULT_GET_STREAM_INFO_RETRY)
|
||||
{
|
||||
if(this.retries != 0)
|
||||
{
|
||||
this.timer.addEventListener(TimerEvent.TIMER_COMPLETE,this.onTimerComplete);
|
||||
this.timer.start();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.complete();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this._error = {"message":OSMFStrings.getString(OSMFStrings.DVR_UNEXPECTED_SERVER_RESPONSE) + result.code};
|
||||
this.complete();
|
||||
}
|
||||
}
|
||||
|
||||
private function onServerCallError(error:Object) : void
|
||||
{
|
||||
this._error = error;
|
||||
this.complete();
|
||||
}
|
||||
|
||||
private function onTimerComplete(event:TimerEvent) : void
|
||||
{
|
||||
this.timer.removeEventListener(TimerEvent.TIMER_COMPLETE,this.onTimerComplete);
|
||||
this.getStreamInfo();
|
||||
}
|
||||
|
||||
private function complete() : void
|
||||
{
|
||||
this.retries = NaN;
|
||||
this.timer = null;
|
||||
dispatchEvent(new Event(Event.COMPLETE));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
package org.osmf.net.dvr
|
||||
{
|
||||
import flash.errors.IllegalOperationError;
|
||||
import flash.events.NetStatusEvent;
|
||||
import flash.events.TimerEvent;
|
||||
import flash.net.NetConnection;
|
||||
import flash.net.NetStream;
|
||||
import flash.utils.Timer;
|
||||
import org.osmf.events.TimeEvent;
|
||||
import org.osmf.media.MediaResourceBase;
|
||||
import org.osmf.traits.TimeTrait;
|
||||
import org.osmf.utils.OSMFStrings;
|
||||
|
||||
[ExcludeClass]
|
||||
internal class DVRCastTimeTrait extends TimeTrait
|
||||
{
|
||||
|
||||
private var durationUpdateTimer:Timer;
|
||||
|
||||
private var oldDuration:Number;
|
||||
|
||||
private var stream:NetStream;
|
||||
|
||||
private var streamInfo:DVRCastStreamInfo;
|
||||
|
||||
private var recordingInfo:DVRCastRecordingInfo;
|
||||
|
||||
public function DVRCastTimeTrait(connection:NetConnection, stream:NetStream, resource:MediaResourceBase)
|
||||
{
|
||||
super(NaN);
|
||||
if(connection == null || stream == null)
|
||||
{
|
||||
throw new IllegalOperationError(OSMFStrings.getString(OSMFStrings.NULL_PARAM));
|
||||
}
|
||||
this.stream = stream;
|
||||
stream.addEventListener(NetStatusEvent.NET_STATUS,this.onNetStatus);
|
||||
this.durationUpdateTimer = new Timer(DVRCastConstants.LOCAL_DURATION_UPDATE_INTERVAL);
|
||||
this.durationUpdateTimer.addEventListener(TimerEvent.TIMER,this.onDurationUpdateTimer);
|
||||
this.durationUpdateTimer.start();
|
||||
this.streamInfo = resource.getMetadataValue(DVRCastConstants.STREAM_INFO_KEY) as DVRCastStreamInfo;
|
||||
this.recordingInfo = resource.getMetadataValue(DVRCastConstants.RECORDING_INFO_KEY) as DVRCastRecordingInfo;
|
||||
}
|
||||
|
||||
override public function get duration() : Number
|
||||
{
|
||||
var result:Number = NaN;
|
||||
if(this.streamInfo.isRecording)
|
||||
{
|
||||
result = this.recordingInfo.startDuration - this.recordingInfo.startOffset + (new Date().time - this.recordingInfo.startTime.time) / 1000;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = this.streamInfo.currentLength - this.recordingInfo.startOffset;
|
||||
}
|
||||
return isNaN(result) ? NaN : Math.max(0,result);
|
||||
}
|
||||
|
||||
override public function get currentTime() : Number
|
||||
{
|
||||
return this.stream.time;
|
||||
}
|
||||
|
||||
private function onDurationUpdateTimer(event:TimerEvent) : void
|
||||
{
|
||||
var newDuration:Number = this.duration;
|
||||
if(newDuration != this.oldDuration)
|
||||
{
|
||||
this.oldDuration = newDuration;
|
||||
dispatchEvent(new TimeEvent(TimeEvent.DURATION_CHANGE,false,false,newDuration));
|
||||
}
|
||||
}
|
||||
|
||||
private function onNetStatus(event:NetStatusEvent) : void
|
||||
{
|
||||
if(event.info.code == "NetStream.Play.Stop")
|
||||
{
|
||||
if(Boolean(this.durationUpdateTimer))
|
||||
{
|
||||
this.durationUpdateTimer.stop();
|
||||
}
|
||||
signalComplete();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package org.osmf.net.dvr
|
||||
{
|
||||
[ExcludeClass]
|
||||
public class DVRUtils
|
||||
{
|
||||
|
||||
public function DVRUtils()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public static function calculateOffset(beginOffset:Number, endOffset:Number, currentDuration:Number) : Number
|
||||
{
|
||||
var offset:Number = 0;
|
||||
if(endOffset != 0)
|
||||
{
|
||||
if(currentDuration > endOffset)
|
||||
{
|
||||
offset = currentDuration - endOffset;
|
||||
}
|
||||
else
|
||||
{
|
||||
offset = Math.min(beginOffset,currentDuration);
|
||||
}
|
||||
}
|
||||
else if(beginOffset != 0)
|
||||
{
|
||||
offset = Math.min(beginOffset,currentDuration);
|
||||
}
|
||||
return offset;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package org.osmf.net.dvr
|
||||
{
|
||||
import flash.net.Responder;
|
||||
|
||||
[ExcludeClass]
|
||||
internal class TestableResponder extends Responder
|
||||
{
|
||||
|
||||
private var _result:Function;
|
||||
|
||||
private var _status:Function;
|
||||
|
||||
public function TestableResponder(result:Function, status:Function = null)
|
||||
{
|
||||
this._result = result;
|
||||
this._status = status;
|
||||
super(result,status);
|
||||
}
|
||||
|
||||
internal function get result() : Function
|
||||
{
|
||||
return this._result;
|
||||
}
|
||||
|
||||
internal function get status() : Function
|
||||
{
|
||||
return this._status;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user