diff --git a/.gitignore b/.gitignore
index 7e47b68..1efbe81 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,3 +6,4 @@ dist
*.iml
+flowplayer.swc
diff --git a/README.md b/README.md
index 0e3ba00..7dd3b74 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,4 @@
-
# Flowplayer Flash
@@ -22,6 +21,8 @@ This is Flowplayer Flash. Flowplayer 5 for HTML5 will be out soon.
Follow [these instructions](http://flowplayer.org/documentation/developer/development-environment.html).
+Addtionally for versions above 3.2.16, check out the [Flash builder](https://github.com/flowplayer/flash-build/) in the same tree as the Flash sources.
+
## License
The Flowplayer Free version is released under the
diff --git a/core/LICENSE_UNLIMITED.txt b/core/LICENSE_UNLIMITED.txt
index 6b26d22..60bb839 100644
--- a/core/LICENSE_UNLIMITED.txt
+++ b/core/LICENSE_UNLIMITED.txt
@@ -1,3 +1,3 @@
Flowplayer Unlimited license terms are available in this page:
-http://flowplayer.org/download/licenses/license_unlimited.htm
\ No newline at end of file
+http://flowplayer.org/license/unlimited.html
\ No newline at end of file
diff --git a/core/README.txt b/core/README.txt
index 1375e00..62e9422 100644
--- a/core/README.txt
+++ b/core/README.txt
@@ -1,7 +1,36 @@
Version history:
+3.2.17
+------
+- #75 set the child display list different when a gradient is set.
+- The clip property 'bufferLength' now accepts decimal values, for example bufferLength: 0.2
+- #121 XSS fix: Only load plugins and external config from the same domain as the player swf is loaded from
+- Made it possible to tab out of the player and into the HTML page using the keyboard alone.
+- Change links in the context menu and in the logos to point to http://flash.flowplayer.org
+- Pausing a live stream now leaves the video frame visible #81
+- Audio plugin is not loaded nor used when the the provider is set excplicitly in the clip to a non-audio value, for
+ example to 'http'
+- Allow playing another instream clip while already playing one. Issue #131
+- Fixed memory leaks related to repeatedly starting playback with the play() API method. #163
+
3.2.16
------
+- new clip event onMetadataChange, dispatched for example when switching bitrate
+
+Fixes:
+
+- Shows logo in accelerated mode #20
+- mid-rolls freeze if multiple providers are used #42
+- onFire fired twice on replay #52
+- rtmp + hw accel + instream clips lose video, or aspect ratio #44
+- URL name parts containing semi-colons (;) should pass validation through linkUrl usage #53
+- cuepoints fired multiple times with the bitrateselect plugin #50
+- fix for dispatching onBegin in certain situations
+- if onStart has been dispatched already prevent dispatching many onBegin events
+
+
+3.2.15
+------
- #15 fixes for #627, handle the display init on startup.
- #615 dispatch begin if in paused mode too early.
- #629 if start has been dispatched already prevent dispatching many begin events.
@@ -10,11 +39,11 @@ Version history:
- #52 when replaying flag start has dispatched on the current clip.
- #44 fixes for #627 check if the stagevideo dimensions and positioning has changed to update the stage video mask with.
- unbinding and binding stage video events caused issues with instream playlists therefore has to be kept binded.
- unbinded stage video events during seeking to prevent the mask repositioning.
+- unbinded stage video events during seeking to prevent the mask repositioning.
- #53 update url filter to accomodate for pretty urls with semi colons.
- #50 if we have metadata already set it is being updated during seeks and switching, dispatch metadata change events instead.
-3.2.15
+3.2.14
------
- #614 when the clip ends if the next clip in the provider has a different provider close the provider stream.
- #627 only detach / attach the display on start events which causes issues in buffering events after a seek in stagevideo.
diff --git a/core/build.properties b/core/build.properties
deleted file mode 100644
index 2ef5d3a..0000000
--- a/core/build.properties
+++ /dev/null
@@ -1,65 +0,0 @@
-
-# you need to adjust following to point to your Flex SDK
-flexdir=/Users/Api/flex_sdk_4.5.0.19786
-
-# change following to point to .exe files when running on Windows
-mxmlc_bin= ${flexbindir}/mxmlc
-compc_bin= ${flexbindir}/compc
-asdoc_bin= /Users/Api/flex_sdk_3/bin/asdoc
-
-devkit-dir=../lib/devkit
-plugins.dir=../plugins
-lib.dir=../lib
-
-site.dir=/Users/api/hyde/site
-js.deploy.dir=${site.dir}/deploy/js
-deploy.dir=${site.dir}/content/swf
-
-#plugin.buildfiles=rtmp/build.xml
-#
-
-# 3.2.16
-plugin.buildfiles=rtmp/build.xml,controls/build.xml,controls/build-tube.xml,controls/build-air.xml,controls/build-skinless.xml, \
- sharing/build.xml,viralvideos/build.xml,bitrateselect/build.xml,bwcheck/build.xml,bwcheck/build-httpstreaming.xml \
- httpstreaming/build.xml,menu/build.xml,pseudostreaming/build.xml
-#
-#plugin.buildfiles=analytics/build.xml,audio/build.xml,bwcheck/build.xml,bwcheck/build-httpstreaming.xml \
-# captions/build.xml,content/build.xml,controls/build.xml,controls/build-tube.xml,controls/build-air.xml,controls/build-skinless.xml, \
-# f4m/build.xml,httpstreaming/build.xml,pseudostreaming/build.xml,rtmp/build.xml,securestreaming/build.xml, \
-# sharing/build.xml,slowmotion/build.xml,smil/build.xml,viralvideos/build.xml, \
-# bitrateselect/build.xml,menu/build.xml,cluster/build.xml
-# all plugins
-allplugins.buildfiles=analytics/build.xml,audio/build.xml,bwcheck/build.xml,bwcheck/build-httpstreaming.xml \
- captions/build.xml,content/build.xml,controls/build.xml,controls/build-tube.xml,controls/build-air.xml,controls/build-skinless.xml, \
- f4m/build.xml,httpstreaming/build.xml,pseudostreaming/build.xml,rtmp/build.xml,securestreaming/build.xml, \
- sharing/build.xml,slowmotion/build.xml,smil/build.xml,viralvideos/build.xml,securedrm/build.xml, \
- bitrateselect/build.xml,menu/build.xml,cluster/build.xml
-
-jsplugins.buildfiles=controls/build.xml,embed/build.xml,ipad/build.xml,playlist/build.xml,bitrateselect/build.xml
-
-cloudfront.version=1.0
-adsense.version=flowplayer.org-1.6.1
-
-# for plugins that can be built inside the player
-plugin-classes=${plugins.dir}/controls/src/actionscript ${lib.dir}/common/src/actionscript
-#plugin-classes=${plugins.dir}/controls/src/actionscript ${plugins.dir}/pseudostreaming/src/actionscript \
-# ${plugins.dir}/rtmp/src/actionscript \
-# ${lib.dir}/common/src/actionscript
-
-plugin-swc=${plugins.dir}/controls/src/flash ${plugins.dir}/pseudostreaming/lib
-
-controls-dir=${plugins.dir}/controls
-compiler.defines=
-
-# following can usually be left as they are
-flexbindir=${flexdir}/bin
-flexlibsdir=${flexdir}/frameworks/libs
-flashplayer_bin=
-framerate=24
-bgcolor=0xFFFFFF
-width=500
-height=350
-
-# Flash Player targets
-flash.use.10.1=true
-flash.target.player=10.2.0
diff --git a/core/build.xml b/core/build.xml
deleted file mode 100644
index a25281a..0000000
--- a/core/build.xml
+++ /dev/null
@@ -1,573 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/core/lib/corelib/src/com/adobe/serialization/json/JSON.as b/core/lib/corelib/src/com/adobe/serialization/json/JSONforFP.as
similarity index 99%
rename from core/lib/corelib/src/com/adobe/serialization/json/JSON.as
rename to core/lib/corelib/src/com/adobe/serialization/json/JSONforFP.as
index 1d2477e..eb2c331 100644
--- a/core/lib/corelib/src/com/adobe/serialization/json/JSON.as
+++ b/core/lib/corelib/src/com/adobe/serialization/json/JSONforFP.as
@@ -47,7 +47,7 @@ package com.adobe.serialization.json {
* var myObject:Object = JSON.decode( jsonString );
*
*/
- public class JSON {
+ public class JSONforFP {
/**
diff --git a/core/lib/goasp/src_go/org/goasap/items/LinearGo.as b/core/lib/goasp/src_go/org/goasap/items/LinearGo.as
index ceaa859..6d350c9 100755
--- a/core/lib/goasp/src_go/org/goasap/items/LinearGo.as
+++ b/core/lib/goasp/src_go/org/goasap/items/LinearGo.as
@@ -20,13 +20,14 @@
* THE SOFTWARE.
*/
package org.goasap.items {
- import flash.utils.getTimer;
+
+ import flash.utils.getTimer;
import org.goasap.GoEngine;
import org.goasap.errors.EasingFormatError;
import org.goasap.events.GoEvent;
import org.goasap.interfaces.IPlayable;
- import org.goasap.managers.LinearGoRepeater;
+ import org.goasap.managers.LinearGoRepeater;
/**
* Dispatched during an animation's first update after the delay
@@ -262,13 +263,14 @@ package org.goasap.items {
}
public function set easing(type:Function):void {
if (_state==STOPPED) {
- try {
+ //try {
if (type(1,1,1,1) is Number) {
_easing = type;
return;
}
- } catch (e:Error) {}
- throw new EasingFormatError();
+ //} catch (e:Error) {}
+ //#163 don't throw an error just because.
+ //throw new EasingFormatError();
}
}
@@ -496,18 +498,25 @@ package org.goasap.items {
defaultDelay = 0;
if (isNaN(defaultDuration))
defaultDuration = 1;
- try { this.easing = defaultEasing; }
- catch (e1:EasingFormatError) { defaultEasing = easeOut; }
+ /*try { this.easing = defaultEasing; }
+ catch (e1:EasingFormatError) { defaultEasing = easeOut; } */
+
+ //#163 set default easing
+ this.easing = easeOut;
// set params
if (!isNaN(delay)) _delay = delay;
else _delay = defaultDelay;
if (!isNaN(duration)) _duration = duration;
else _duration = defaultDuration;
- try { this.easing = easing; }
+ /*try { this.easing = easing; }
catch (e2:EasingFormatError) {
if (easing!=null) { throw e2; } // user passed invalid easing function
this.easing = defaultEasing;
- }
+ }*/
+ //if (easing && easing)
+ //#163 set easing if enabled on the argument, not needed for normal Flowplayer animations.
+ if (easing!=null) this.easing = easing;
+
if (extraEasingParams) _extraEaseParams = extraEasingParams;
if (useRelative) this.useRelative = true;
if (useRounding) this.useRounding = true;
diff --git a/core/lib/licensekey/licensekey.swc b/core/lib/licensekey/licensekey.swc
index 59ed3ab..60f500a 100644
Binary files a/core/lib/licensekey/licensekey.swc and b/core/lib/licensekey/licensekey.swc differ
diff --git a/core/manifest.xml b/core/manifest.xml
deleted file mode 100644
index 67fce13..0000000
--- a/core/manifest.xml
+++ /dev/null
@@ -1,23 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/core/release.xml b/core/release.xml
deleted file mode 100644
index 02ecf46..0000000
--- a/core/release.xml
+++ /dev/null
@@ -1,235 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- <a href="http://flowplayer-releases.s3.amazonaws.com/flowplayer/flowplayer.zip">flowplayer.zip</a> <br />
-
- <a href="http://flowplayer-releases.s3.amazonaws.com/flowplayer/flowplayer.commercial.zip">flowplayer.commercial.zip</a> <br />
-
- <a href="http://flowplayer-releases.s3.amazonaws.com/flowplayer/flowplayer-src.zip">flowplayer-src.zip</a> <br />
-
-
-
-
-
-
-<br />
-<a href="http://flowplayer-releases.s3.amazonaws.com/latest.zip">latest.zip: All latest dev-version swf files in one zip</a> <br />
- <br />
- Build time: ${build.time} GMT
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/core/src/actionscript-commercial/org/flowplayer/view/ContextMenuBuilder.as b/core/src/actionscript-commercial/org/flowplayer/view/ContextMenuBuilder.as
index bd0a43c..7c7f93f 100644
--- a/core/src/actionscript-commercial/org/flowplayer/view/ContextMenuBuilder.as
+++ b/core/src/actionscript-commercial/org/flowplayer/view/ContextMenuBuilder.as
@@ -106,7 +106,7 @@ package org.flowplayer.view {
private function buildMenu(menu:ContextMenu):ContextMenu {
addItem(menu, new ContextMenuItem("About " +VersionInfo.versionInfo()+ "...", false, true), function(event:ContextMenuEvent):void {
- navigateToURL(new URLRequest("http://flowplayer.org"), "_self");
+ navigateToURL(new URLRequest("http://flash.flowplayer.org"), "_self");
});
// 1-3 Required by the GPL license
// 1 copyright notice
diff --git a/core/src/actionscript-commercial/org/flowplayer/view/LicenseKey.as b/core/src/actionscript-commercial/org/flowplayer/view/LicenseKey.as
index b6e59b0..6ba9a70 100644
--- a/core/src/actionscript-commercial/org/flowplayer/view/LicenseKey.as
+++ b/core/src/actionscript-commercial/org/flowplayer/view/LicenseKey.as
@@ -31,7 +31,7 @@ package org.flowplayer.view {
public static function validate(swfUrl:String, version:Array, configuredKeys:Object, externalInterfaceAvailable:Boolean):Boolean {
trace("using validator " + FlowplayerLicenseKey.id);
- return FlowplayerLicenseKey.validate(swfUrl, version, configuredKeys, externalInterfaceAvailable);
+ return FlowplayerLicenseKey.validate(swfUrl, version, configuredKeys, (CONFIG::secondaryDomains).split(" "), externalInterfaceAvailable);
}
}
diff --git a/core/src/actionscript-commercial/org/flowplayer/view/LogoView.as b/core/src/actionscript-commercial/org/flowplayer/view/LogoView.as
index 6c62674..f7e5003 100644
--- a/core/src/actionscript-commercial/org/flowplayer/view/LogoView.as
+++ b/core/src/actionscript-commercial/org/flowplayer/view/LogoView.as
@@ -286,14 +286,18 @@ package org.flowplayer.view {
private function startTimer():void {
_hideTimer = new Timer(_model.displayTime * 1000, 1);
- _hideTimer.addEventListener(TimerEvent.TIMER_COMPLETE,
- function(event:TimerEvent):void {
- log.debug("display time complete");
- hide(_model.fadeSpeed);
- _hideTimer.stop();
- });
+ _hideTimer.addEventListener(TimerEvent.TIMER_COMPLETE, onHideComplete);
_hideTimer.start();
}
+
+ private function onHideComplete(event:TimerEvent):void
+ {
+ log.debug("display time complete");
+ hide(_model.fadeSpeed);
+ _hideTimer.reset();
+ _hideTimer.removeEventListener(TimerEvent.TIMER_COMPLETE, onHideComplete);
+ _hideTimer = null;
+ }
CONFIG::freeVersion
public function setModel(model:Logo):void {
@@ -306,7 +310,7 @@ package org.flowplayer.view {
_model.top = "20";
_model.right = "20";
_model.opacity = 0.3;
- _model.linkUrl = "http://flowplayer.org";
+ _model.linkUrl = "http://flash.flowplayer.org";
log.debug("initial model dimensions " + _model.dimensions);
}
diff --git a/core/src/actionscript-commercial/org/flowplayer/view/PlayButtonOverlayView.as b/core/src/actionscript-commercial/org/flowplayer/view/PlayButtonOverlayView.as
index 73c8fbd..3dc6539 100644
--- a/core/src/actionscript-commercial/org/flowplayer/view/PlayButtonOverlayView.as
+++ b/core/src/actionscript-commercial/org/flowplayer/view/PlayButtonOverlayView.as
@@ -57,6 +57,7 @@ package org.flowplayer.view {
private var _play:PlayButtonOverlay;
private var _rotation:RotatingAnimation;
private var _playDetectTimer:Timer;
+ private var _startTime:Number;
public function PlayButtonOverlayView(resizeToTextWidth:Boolean, play:PlayButtonOverlay, pluginRegistry:PluginRegistry) {
_resizeToTextWidth = resizeToTextWidth;
@@ -464,10 +465,10 @@ package org.flowplayer.view {
private function bufferUntilStarted(event:ClipEvent = null):void {
if (event && event.isDefaultPrevented()) return;
startBuffering();
- createPlaybackStartedCallback(stopBuffering);
+ createPlaybackStartedCallback();
}
- private function createPlaybackStartedCallback(callback:Function):void {
+ private function createPlaybackStartedCallback():void {
log.debug("detectPlayback()");
if (! _player.isPlaying()) {
@@ -479,24 +480,30 @@ package org.flowplayer.view {
return;
}
- var time:Number = _player.status.time;
+ _startTime = _player.status.time;
_playDetectTimer = new Timer(200);
- _playDetectTimer.addEventListener(TimerEvent.TIMER,
- function(event:TimerEvent):void {
- var currentTime:Number = _player.status.time;
- log.debug("on detectPlayback() currentTime " + currentTime + ", time " + time);
-
- if (Math.abs(currentTime - time) > 0.2) {
- _playDetectTimer.stop();
- log.debug("playback started");
- callback();
- } else {
- log.debug("not started yet, currentTime " + currentTime + ", time " + time);
- }
- });
+ _playDetectTimer.addEventListener(TimerEvent.TIMER,onPlayDetect);
log.debug("doStart(), starting timer");
_playDetectTimer.start();
}
+
+ //#163 move play detect timer to external listener and clear when done.
+ private function onPlayDetect(event:TimerEvent):void
+ {
+ var currentTime:Number = _player.status.time;
+ log.debug("on detectPlayback() currentTime " + currentTime + ", time " + _startTime);
+
+ if (Math.abs(currentTime - _startTime) > 0.2) {
+ stopBuffering();
+ _playDetectTimer.stop();
+ _playDetectTimer.removeEventListener(TimerEvent.TIMER,onPlayDetect);
+ _playDetectTimer = null;
+ _startTime = NaN;
+ log.debug("playback started");
+ } else {
+ log.debug("not started yet, currentTime " + currentTime + ", time " + _startTime);
+ }
+ }
}
}
diff --git a/core/src/actionscript/org/flowplayer/config/ConfigParser.as b/core/src/actionscript/org/flowplayer/config/ConfigParser.as
index 7a7c292..9086c59 100644
--- a/core/src/actionscript/org/flowplayer/config/ConfigParser.as
+++ b/core/src/actionscript/org/flowplayer/config/ConfigParser.as
@@ -21,7 +21,7 @@ package org.flowplayer.config {
import org.flowplayer.controller.ResourceLoader;
import org.flowplayer.flow_internal;
import org.flowplayer.util.Log;
- import com.adobe.serialization.json.JSON;
+ import com.adobe.serialization.json.JSONforFP;
use namespace flow_internal;
@@ -33,12 +33,12 @@ package org.flowplayer.config {
flow_internal static function parse(config:String):Object {
//#590 add full package reference to work with Flex 4.6
- return com.adobe.serialization.json.JSON.decode(config);
+ return com.adobe.serialization.json.JSONforFP.decode(config);
}
flow_internal static function parseConfig(config:Object, builtInConfig:Object, playerSwfUrl:String, controlsVersion:String, audioVersion:String):Config {
if (!config) return new Config({}, builtInConfig, playerSwfUrl, controlsVersion, audioVersion);
- var configObj:Object = config is String ? com.adobe.serialization.json.JSON.decode(config as String) : config;
+ var configObj:Object = config is String ? com.adobe.serialization.json.JSONforFP.decode(config as String) : config;
return new Config(configObj, builtInConfig, playerSwfUrl, controlsVersion, audioVersion);
}
diff --git a/core/src/actionscript/org/flowplayer/controller/AbstractDurationTrackingController.as b/core/src/actionscript/org/flowplayer/controller/AbstractDurationTrackingController.as
index 80c8dff..005d178 100644
--- a/core/src/actionscript/org/flowplayer/controller/AbstractDurationTrackingController.as
+++ b/core/src/actionscript/org/flowplayer/controller/AbstractDurationTrackingController.as
@@ -84,13 +84,20 @@ package org.flowplayer.controller {
private function createDurationTracker(clip:Clip):void {
if (durationTracker) {
- durationTracker.stop();
+ clearDurationTracker();
}
durationTracker = new PlayTimeTracker(clip, this);
durationTracker.addEventListener(TimerEvent.TIMER_COMPLETE, durationReached);
durationTracker.start();
}
+ private function clearDurationTracker():void
+ {
+ durationTracker.stop();
+ durationTracker.removeEventListener(TimerEvent.TIMER_COMPLETE, durationReached);
+ durationTracker = null;
+ }
+
public function get time():Number {
if (!durationTracker) return 0;
var time:Number = durationTracker.time;
@@ -166,8 +173,8 @@ package org.flowplayer.controller {
private function stop(event:ClipEvent, closeStream:Boolean, silent:Boolean = false):void {
log.debug("stop " + durationTracker);
if (durationTracker) {
- durationTracker.stop();
durationTracker.time = 0;
+ clearDurationTracker();
}
doStop(silent ? null : event, closeStream);
}
diff --git a/core/src/actionscript/org/flowplayer/controller/InStreamTracker.as b/core/src/actionscript/org/flowplayer/controller/InStreamTracker.as
index 7cabf2e..cdfee19 100644
--- a/core/src/actionscript/org/flowplayer/controller/InStreamTracker.as
+++ b/core/src/actionscript/org/flowplayer/controller/InStreamTracker.as
@@ -64,6 +64,7 @@ package org.flowplayer.controller {
log.debug("stop()");
if (_timer && _timer.running) {
_timer.stop();
+ _timer.removeEventListener(TimerEvent.TIMER, onTimer);
}
}
diff --git a/core/src/actionscript/org/flowplayer/controller/NetStreamCallbacks.as b/core/src/actionscript/org/flowplayer/controller/NetStreamCallbacks.as
index 27ca5f1..79163e4 100644
--- a/core/src/actionscript/org/flowplayer/controller/NetStreamCallbacks.as
+++ b/core/src/actionscript/org/flowplayer/controller/NetStreamCallbacks.as
@@ -36,6 +36,6 @@ package org.flowplayer.controller {
function RtmpSampleAccess(obj:Object):void;
- function onTextData(obj:Object):void;
+ function onTextData(info:Object):void;
}
}
diff --git a/core/src/actionscript/org/flowplayer/controller/NetStreamClient.as b/core/src/actionscript/org/flowplayer/controller/NetStreamClient.as
index acecf3f..1955bd3 100644
--- a/core/src/actionscript/org/flowplayer/controller/NetStreamClient.as
+++ b/core/src/actionscript/org/flowplayer/controller/NetStreamClient.as
@@ -47,10 +47,7 @@ package org.flowplayer.controller {
}
public function onMetaData(infoObject:Object):void {
-
- log.info("onMetaData, current clip " + _clip);
-
- log.debug("onMetaData, data for clip " + _clip + ":");
+ log.debug("onMetaData(), data for clip " + _clip + ":");
var metaData:Object = new Object();
for (var key:String in infoObject) {
if (key == "duration" && _clip && _clip.metaData && _clip.metaData.duration) {
@@ -138,8 +135,12 @@ package org.flowplayer.controller {
_clip.dispatchNetStreamEvent("RtmpSampleAccess", infoObject);
}
- public function onTextData(infoObject:Object):void {
- _clip.dispatchNetStreamEvent("onTextData", infoObject);
+ public function onTextData(info:Object):void {
+ var eventInfo:Object = {};
+ for (var prop:String in info) {
+ eventInfo[prop] = info[prop];
+ }
+ _clip.dispatchNetStreamEvent("onTextData", eventInfo);
}
public function onPlayStatus(...rest):void {
diff --git a/core/src/actionscript/org/flowplayer/controller/NetStreamControllingStreamProvider.as b/core/src/actionscript/org/flowplayer/controller/NetStreamControllingStreamProvider.as
index 1203ac3..dcee556 100644
--- a/core/src/actionscript/org/flowplayer/controller/NetStreamControllingStreamProvider.as
+++ b/core/src/actionscript/org/flowplayer/controller/NetStreamControllingStreamProvider.as
@@ -17,34 +17,29 @@
*/
package org.flowplayer.controller {
- import org.flowplayer.controller.StreamProvider;
- import org.flowplayer.controller.TimeProvider;
- import org.flowplayer.controller.VolumeController;
+ import flash.display.DisplayObject;
+ import flash.errors.IOError;
+ import flash.events.NetStatusEvent;
+ import flash.events.TimerEvent;
+ import flash.media.Video;
+ import flash.net.NetConnection;
+ import flash.net.NetStream;
+ import flash.utils.Dictionary;
+ import flash.utils.Timer;
+
import org.flowplayer.model.Clip;
import org.flowplayer.model.ClipError;
import org.flowplayer.model.ClipEvent;
import org.flowplayer.model.ClipEventType;
- import org.flowplayer.model.EventType;
import org.flowplayer.model.Playlist;
- import org.flowplayer.model.PluginEventType;
import org.flowplayer.model.PluginModel;
import org.flowplayer.model.ProviderModel;
import org.flowplayer.util.Assert;
import org.flowplayer.util.Log;
import org.flowplayer.view.Flowplayer;
- import flash.utils.Dictionary;
- import flash.display.DisplayObject;
- import flash.errors.IOError;
- import flash.events.NetStatusEvent;
- import flash.events.TimerEvent;
- import flash.media.Video;
- import flash.net.NetConnection;
- import flash.net.NetStream;
- import flash.utils.Timer;
-
CONFIG::FLASH_10_1 {
- import org.flowplayer.view.StageVideoWrapper;
+ import org.flowplayer.view.StageVideoWrapper;
}
/**
@@ -64,7 +59,7 @@ package org.flowplayer.controller {
private var _pauseAfterStart:Boolean;
private var _volumeController:VolumeController;
private var _seekTargetWaitTimer:Timer;
- private var _seekTarget:Number;
+ private var _seekTarget:Number = 0;
private var _model:ProviderModel;
private var _connectionProvider:ConnectionProvider;
private var _clipUrlResolverHelper:ClipURLResolverHelper;
@@ -122,7 +117,7 @@ package org.flowplayer.controller {
}
private function _load(clip:Clip, pauseAfterStart:Boolean, attempts:int = 3):void {
- Assert.notNull(clip, "load(clip): clip cannot be null");
+ Assert.notNull(clip, "load(clip): clip cannot be null");
_paused = false;
_stopping = false;
_attempts = attempts;
@@ -211,6 +206,7 @@ package org.flowplayer.controller {
* @inheritDoc
*/
public final function resume(event:ClipEvent):void {
+ log.debug("resume");
_paused = false;
_stopping = false;
doResume(_netStream, event);
@@ -545,13 +541,14 @@ package org.flowplayer.controller {
}
protected function doSwitchStream(event:ClipEvent, netStream:NetStream, clip:Clip, netStreamPlayOptions:Object = null):void {
+ import flash.net.NetStreamPlayOptions;
+
//fix for #279, switch and pause if the current clip is currently in a paused state
//#404 implement netstreamplayoptions for http streams, resets the stream or start loading a new stream.
//implement switch support for flash9 players that do not support dynamic switching
if (CONFIG::FLASH_10_1) {
if (netStreamPlayOptions) {
pauseAfterStart = paused;
- import flash.net.NetStreamPlayOptions;
if (netStreamPlayOptions is NetStreamPlayOptions) {
log.debug("doSwitchStream() calling play2()");
//#461 when we have a clip base url set, we need the complete clip url sent to play2 for http streams.
@@ -788,6 +785,7 @@ package org.flowplayer.controller {
// dispatchPlayEvent(ClipEventType.STOP);
} else if (event.info.code == "NetStream.Seek.Notify") {
+
if (! silentSeek) {
startSeekTargetWait();
} else {
@@ -834,14 +832,23 @@ package org.flowplayer.controller {
if (_seekTarget < 0) return;
if (_seekTargetWaitTimer && _seekTargetWaitTimer.running) return;
log.debug("starting seek target wait timer");
+
+ if (_seekTargetWaitTimer) {
+ _seekTargetWaitTimer.reset();
+ _seekTargetWaitTimer.removeEventListener(TimerEvent.TIMER, onSeekTargetWait);
+ _seekTargetWaitTimer = null;
+ }
+
_seekTargetWaitTimer = new Timer(200);
_seekTargetWaitTimer.addEventListener(TimerEvent.TIMER, onSeekTargetWait);
_seekTargetWaitTimer.start();
}
private function onSeekTargetWait(event:TimerEvent):void {
- if (time >= _seekTarget) {
- _seekTargetWaitTimer.stop();
+ //#104 if the updated time is a fraction less than the seek target time ie for HDS, use a bitwise rounding so the seek time can stop.
+ if ((time|0) >= (_seekTarget|0)) {
+ _seekTargetWaitTimer.reset();
+ _seekTargetWaitTimer.removeEventListener(TimerEvent.TIMER, onSeekTargetWait);
log.debug("dispatching onSeek");
dispatchPlayEvent(ClipEventType.SEEK, _seekTarget);
_seekTarget = -1;
@@ -875,28 +882,27 @@ package org.flowplayer.controller {
_startedClip = null;
log.debug("doStop(), closing netStream and connection");
- if (clip.getContent() is Video) {
- Video(clip.getContent()).clear();
- }
-
try {
netStream.close();
+ _netStream.removeEventListener(NetStatusEvent.NET_STATUS, _onNetStatus);
_netStream = null;
} catch (e:Error) {
}
if (_connection) {
_connection.close();
+ _connection.removeEventListener(NetStatusEvent.NET_STATUS, _onNetStatus);
_connection = null;
}
dispatchPlayEvent(ClipEventType.BUFFER_STOP);
}
- private function _createNetStream():void {
- _netStream = createNetStream(_connection) || new NetStream(_connection);
+ private function _createNetStream():void {
+ _netStream = createNetStream(_connection) || new NetStream(_connection);
netStream.client = new NetStreamClient(clip, _player.config, _streamCallbacks);
_netStream.bufferTime = clip.bufferLength;
+ log.debug("using buffer time of " + _netStream.bufferTime);
_volumeController.netStream = _netStream;
clip.setNetStream(_netStream);
_netStream.addEventListener(NetStatusEvent.NET_STATUS, _onNetStatus);
diff --git a/core/src/actionscript/org/flowplayer/controller/ParallelRTMPConnectionProvider.as b/core/src/actionscript/org/flowplayer/controller/ParallelRTMPConnectionProvider.as
index 9755092..4757e1f 100644
--- a/core/src/actionscript/org/flowplayer/controller/ParallelRTMPConnectionProvider.as
+++ b/core/src/actionscript/org/flowplayer/controller/ParallelRTMPConnectionProvider.as
@@ -90,10 +90,11 @@ package org.flowplayer.controller {
doConnect(_rtmpConnector, _proxyType, objectEncoding, connArgs);
// RTMPT connect is started after 250 ms
+ //#163 weak reference
var delay:Timer = new Timer(_failOverDelay, 1);
delay.addEventListener(TimerEvent.TIMER, function(event:TimerEvent):void {
doConnect(_rtmptConnector, _proxyType, objectEncoding, connArgs);
- });
+ }, false, 0 , true);
delay.start();
} else {
diff --git a/core/src/actionscript/org/flowplayer/controller/ParallelRTMPConnector.as b/core/src/actionscript/org/flowplayer/controller/ParallelRTMPConnector.as
index b9c89a0..b47f99f 100644
--- a/core/src/actionscript/org/flowplayer/controller/ParallelRTMPConnector.as
+++ b/core/src/actionscript/org/flowplayer/controller/ParallelRTMPConnector.as
@@ -57,7 +57,8 @@ package org.flowplayer.controller {
if (_connectionClient) {
_connection.client = _connectionClient;
}
- _connection.addEventListener(NetStatusEvent.NET_STATUS, _onConnectionStatus);
+ //#163 weak reference to listener
+ _connection.addEventListener(NetStatusEvent.NET_STATUS, _onConnectionStatus, false, 0 , true);
log.debug("netConnectionUrl is " + _url);
if (connectionArgs && connectionArgs.length > 0) {
diff --git a/core/src/actionscript/org/flowplayer/controller/PlayListController.as b/core/src/actionscript/org/flowplayer/controller/PlayListController.as
index 62084fe..9321e6f 100644
--- a/core/src/actionscript/org/flowplayer/controller/PlayListController.as
+++ b/core/src/actionscript/org/flowplayer/controller/PlayListController.as
@@ -67,6 +67,7 @@ package org.flowplayer.controller {
flow_internal function setPlaylist(clips:Array):void {
if (getState() != State.WAITING) {
close(false);
+ clearStream();
}
_playList.replaceClips2(clips);
}
@@ -328,8 +329,20 @@ package org.flowplayer.controller {
}
}
+ //#163 detach netstream on the current clip
+ private function clearStream():void
+ {
+ if (_playList.current && _playList.current.getContent() && _playList.current.getContent().hasOwnProperty("attachNetStream")) {
+ Object(_playList.current.getContent()).attachNetStream(null);
+ }
+ }
+
private function replacePlaylistAndPlay(clips:Object):void {
- stop();
+
+ //#163 stop the connection and stream
+ _state.stop(true, true);
+ clearStream();
+
if (clips is Clip) {
_playList.replaceClips(clips as Clip);
} else {
diff --git a/core/src/actionscript/org/flowplayer/controller/PlayState.as b/core/src/actionscript/org/flowplayer/controller/PlayState.as
index a437331..4a29cc6 100644
--- a/core/src/actionscript/org/flowplayer/controller/PlayState.as
+++ b/core/src/actionscript/org/flowplayer/controller/PlayState.as
@@ -129,11 +129,11 @@ package org.flowplayer.controller {
log.debug("stop() called");
if (silent) {
- getMediaController().onEvent(null, [closeStreamAndConnection]);
+ getMediaController().onEvent(ClipEventType.STOP, [closeStreamAndConnection, true]);
if (closeStreamAndConnection && playList.current.parent != null) {
playList.setInStreamClip(null);
- getMediaController().onEvent(null, [true]);
+ getMediaController().onEvent(ClipEventType.STOP, [true, true]);
}
} else {
diff --git a/core/src/actionscript/org/flowplayer/controller/PlayTimeTracker.as b/core/src/actionscript/org/flowplayer/controller/PlayTimeTracker.as
index 78341eb..6c5a5b0 100644
--- a/core/src/actionscript/org/flowplayer/controller/PlayTimeTracker.as
+++ b/core/src/actionscript/org/flowplayer/controller/PlayTimeTracker.as
@@ -28,7 +28,6 @@ package org.flowplayer.controller {
private var _onLastSecondDispatched:Boolean;
private var _controller:MediaController;
private var _endDetectTimer:Timer;
- private var _wasPaused:Boolean = false;
private var _lastTimeDetected:Number;
public function PlayTimeTracker(clip:Clip, controller:MediaController) {
@@ -52,7 +51,9 @@ package org.flowplayer.controller {
public function stop():void {
if (!_progressTimer) return;
_storedTime = time;
- _progressTimer.stop();
+ _progressTimer.reset();
+ _progressTimer.removeEventListener(TimerEvent.TIMER, checkProgress);
+ _progressTimer = null;
log.debug("stopped at time " + _storedTime);
}
@@ -119,6 +120,7 @@ package org.flowplayer.controller {
}
public function get durationReached():Boolean {
+ if (_clip.live) return false;
if (_clip.durationFromMetadata > _clip.duration) {
return time >= _clip.duration;
}
@@ -128,27 +130,29 @@ package org.flowplayer.controller {
private function startEndTimer(clip:Clip):void {
bindEndListeners();
- _endDetectTimer.addEventListener(TimerEvent.TIMER,
- function(event:TimerEvent):void {
- log.debug("last time detected == " + _lastTimeDetected);
- if(time == _lastTimeDetected && _endDetectTimer.running || durationReached) {
- log.debug("clip has reached his end, timer stopped");
- _endDetectTimer.reset();
- completelyPlayed();
- }
- _lastTimeDetected = time;
- }
- );
+ _endDetectTimer.addEventListener(TimerEvent.TIMER, onEndTime);
log.debug("starting end detect timer");
_endDetectTimer.start();
}
+
+ private function onEndTime(event:TimerEvent):void
+ {
+ log.debug("last time detected == " + _lastTimeDetected);
+ if(time == _lastTimeDetected && _endDetectTimer.running || durationReached) {
+ log.debug("clip has reached his end, timer stopped");
+ _endDetectTimer.reset();
+ completelyPlayed();
+ }
+ _lastTimeDetected = time;
+ }
private function completelyPlayed():void {
if(_endDetectTimer.running) {
unbindEndListeners();
_endDetectTimer.reset();
+ _endDetectTimer.removeEventListener(TimerEvent.TIMER, onEndTime);
_endDetectTimer = null;
}
@@ -181,6 +185,8 @@ package org.flowplayer.controller {
log.debug("this cuepoint already fired");
}
}
+
+ points = null;
}
private function collectCuepoints(clip:Clip, timeRounded:Number):Array {
diff --git a/core/src/actionscript/org/flowplayer/controller/VolumeController.as b/core/src/actionscript/org/flowplayer/controller/VolumeController.as
index 484c28e..e2f3404 100644
--- a/core/src/actionscript/org/flowplayer/controller/VolumeController.as
+++ b/core/src/actionscript/org/flowplayer/controller/VolumeController.as
@@ -104,6 +104,7 @@ package org.flowplayer.controller {
dispatchEvent(PlayerEvent.volume(this.volume));
if (!_storeDelayTimer.running) {
log.info("starting delay timer");
+ _storeDelayTimer.addEventListener(TimerEvent.TIMER_COMPLETE, onTimerDelayComplete);
_storeDelayTimer.start();
}
}
@@ -123,6 +124,7 @@ package org.flowplayer.controller {
private function storeVolume(muted:Boolean = false):void {
log.info("persisting volume level");
_storeDelayTimer.stop();
+ _storeDelayTimer.removeEventListener(TimerEvent.TIMER_COMPLETE, onTimerDelayComplete);
_storedVolume.volume = _soundTransform.volume;
_storedVolume.muted = muted;
_storedVolume.persist();
diff --git a/core/src/actionscript/org/flowplayer/model/Clip.as b/core/src/actionscript/org/flowplayer/model/Clip.as
index 171275c..41d0e56 100644
--- a/core/src/actionscript/org/flowplayer/model/Clip.as
+++ b/core/src/actionscript/org/flowplayer/model/Clip.as
@@ -61,7 +61,7 @@ package org.flowplayer.model {
private var _content:DisplayObject;
private var _originalWidth:int;
private var _originalHeight:int;
- private var _bufferLength:int;
+ private var _bufferLength:Number;
private var _backBufferLength:int;
private var _played:Boolean;
private var _provider:String;
@@ -643,11 +643,11 @@ package org.flowplayer.model {
}
[Value]
- public function get bufferLength():int {
+ public function get bufferLength():Number {
return _bufferLength;
}
- public function set bufferLength(bufferLength:int):void {
+ public function set bufferLength(bufferLength:Number):void {
_bufferLength = bufferLength;
}
@@ -670,6 +670,7 @@ package org.flowplayer.model {
[Value]
public function get provider():String {
+ if (_clipObject && _clipObject.hasOwnProperty("provider")) return _clipObject.provider;
if (type == ClipType.AUDIO && _provider == "http") return "audio";
if (_url && _url.toLowerCase().indexOf("rtmp") == 0 && _provider == "http") return "rtmp";
if (parent) return _provider + "Instream";
diff --git a/core/src/actionscript/org/flowplayer/model/ClipEventSupport.as b/core/src/actionscript/org/flowplayer/model/ClipEventSupport.as
index 0349557..e4f07e0 100644
--- a/core/src/actionscript/org/flowplayer/model/ClipEventSupport.as
+++ b/core/src/actionscript/org/flowplayer/model/ClipEventSupport.as
@@ -23,8 +23,8 @@ package org.flowplayer.model {
* @author api
*/
public class ClipEventSupport extends ClipEventDispatcher {
- private var _clips:Array;
- private var _commonClip:Clip;
+ protected var _clips:Array;
+ protected var _commonClip:Clip;
public function ClipEventSupport(commonClip:Clip, clips:Array = null) {
_commonClip = commonClip;
diff --git a/core/src/actionscript/org/flowplayer/model/Playlist.as b/core/src/actionscript/org/flowplayer/model/Playlist.as
index 2b41662..0814c20 100644
--- a/core/src/actionscript/org/flowplayer/model/Playlist.as
+++ b/core/src/actionscript/org/flowplayer/model/Playlist.as
@@ -17,8 +17,11 @@
*/
package org.flowplayer.model {
+
+
import org.flowplayer.flow_internal;
+
use namespace flow_internal;
/**
* @author anssi
@@ -27,28 +30,28 @@ package org.flowplayer.model {
private var _currentPos:Number;
private var _inStreamClip:Clip;
- private var _commonClip:Clip;
- private var _clips:Array;
public function Playlist(commonClip:Clip = null) {
if (commonClip == null) {
commonClip = new NullClip();
}
- super(commonClip);
- _commonClip = commonClip;
+
+ //#163 inherit clips and common clip
+ super(commonClip, new Array());
_commonClip.setParentPlaylist(this);
initialize();
}
- private function initialize(newClips:Array = null):void {
- _clips = new Array();
+ private function initialize(newClips:Array = null):void {
+ //#163 reuse clips and initialize
+ if (_clips) _clips.length = 0;
_inStreamClip = null;
if (newClips) {
for (var i:Number = 0; i < newClips.length; i++) {
doAddClip(newClips[i]);
}
}
- super.setClips(_clips);
+
_currentPos = 0;
log.debug("initialized, current clip is " + current);
}
@@ -73,21 +76,26 @@ package org.flowplayer.model {
for (var i:Number = 0; i < clips.length; i++) {
doAddClip(clips[i], -1, false);
}
- super.setClips(_clips);
}
-
+
private function doReplace(newClips:Array, silent:Boolean = false):void {
var oldClips:Array = _clips.concat([]);
- initialize(newClips);
+
+ initialize(newClips);
+
if (! silent) {
dispatchPlaylistReplace(oldClips);
}
+
+ oldClips.length = 0;
+ oldClips = null;
}
flow_internal function dispatchPlaylistReplace(oldClips:Array = null):void {
log.debug("dispatchPlaylistReplace");
var oldClipsEventHelper:ClipEventSupport = new ClipEventSupport(_commonClip, oldClips || []);
- doDispatchEvent(new ClipEvent(ClipEventType.PLAYLIST_REPLACE, oldClipsEventHelper), true); }
+ doDispatchEvent(new ClipEvent(ClipEventType.PLAYLIST_REPLACE, oldClipsEventHelper), true);
+ }
/**
@@ -98,7 +106,6 @@ package org.flowplayer.model {
* @see ClipEventType#CLIP_ADD
*/
public function addClip(clip:Clip, pos:int = -1, silent:Boolean = false):void {
- var index:Number = positionOf(pos);
if (clip.position >= 0 || clip.position == -1 || clip.position == -2) {
addChildClip(clip, pos);
return;
@@ -114,7 +121,6 @@ package org.flowplayer.model {
log.debug("addClip(), moving to next clip");
next();
}
- super.setClips(_clips);
}
if (! silent) {
doDispatchEvent(new ClipEvent(ClipEventType.CLIP_ADD, pos >= 0 ? pos : clips.length - 1), true);
@@ -136,6 +142,7 @@ package org.flowplayer.model {
if (pos == -1) {
pos = clips.length - 1;
}
+
var parent:Clip = clips[pos];
parent.addChild(clip);
if (clip.position == 0) {
@@ -151,28 +158,31 @@ package org.flowplayer.model {
}
private function doAddClip(clip:Clip, pos:int = -1, dispatchEvents:Boolean = true):void {
- log.debug("doAddClip() " + clip);
+ //log.debug("doAddClip() " + clip);
clip.setParentPlaylist(this);
- var currentInPos:Clip;
+
+
+ //#163 reposition order of clip add
+
+ if (clip != _commonClip) {
+ clip.onAll(_commonClip.onClipEvent);
+ log.debug("adding listener to all before events, common clip listens to other clips");
+ clip.onBeforeAll(_commonClip.onBeforeClipEvent);
+ }
+
if (pos == -1) {
_clips.push(clip);
} else {
- currentInPos = clips[pos];
- _clips.splice(_clips.indexOf(currentInPos.preroll || currentInPos), 0, clip);
+ _clips.splice(_clips.indexOf(_clips[pos].preroll || _clips[pos]), 0, clip);
}
+
var nested:Array = clip.playlist;
for (var i:int = 0; i < nested.length; i++) {
- var nestedClip:Clip = nested[i] as Clip;
- addChildClip(nestedClip, pos, dispatchEvents);
+ addChildClip(nested[i], pos, dispatchEvents);
}
- log.debug("clips now " + _clips);
+ //log.debug("clips now " + _clips);
- if (clip != _commonClip) {
- clip.onAll(_commonClip.onClipEvent);
- log.debug("adding listener to all before events, common clip listens to other clips");
- clip.onBeforeAll(_commonClip.onBeforeClipEvent);
- }
}
/**
@@ -217,7 +227,6 @@ package org.flowplayer.model {
public function setInStreamClip(clip:Clip):void {
log.debug("setInstremClip to " + clip);
- if (clip && _inStreamClip) throw new Error("Already playing an instream clip");
_inStreamClip = clip;
}
diff --git a/core/src/actionscript/org/flowplayer/util/PropertyBinder.as b/core/src/actionscript/org/flowplayer/util/PropertyBinder.as
index 0cd80a1..8e9e120 100644
--- a/core/src/actionscript/org/flowplayer/util/PropertyBinder.as
+++ b/core/src/actionscript/org/flowplayer/util/PropertyBinder.as
@@ -17,11 +17,13 @@
*/
package org.flowplayer.util {
- import flash.utils.describeType;
+
+import flash.utils.describeType;
import flash.utils.getQualifiedClassName;
import org.flowplayer.util.Log;
+ import flash.system.System;
/**
* PropertyBinder is used to populate object's properties by copying values
* from other objects. The target object should be an instance of a class that contains
@@ -42,7 +44,7 @@ package org.flowplayer.util {
* @param extraProps a property name for all properties for which the target does not provide an accessor or a setter function
*/
public function PropertyBinder(object:Object, extraProps:String = null) {
- log.info("created for " + getQualifiedClassName(object));
+ //log.info("created for " + getQualifiedClassName(object));
_object = object;
_extraProps = extraProps;
_objectDesc = describeType(_object);
@@ -57,7 +59,10 @@ package org.flowplayer.util {
copyProperty(prop, source[prop]);
}
}
- log.debug("done with " + getQualifiedClassName(_object));
+
+ //#163 cleanup xml object
+ System.disposeXML(_objectDesc);
+ //log.debug("done with " + getQualifiedClassName(_object));
return _object;
}
diff --git a/core/src/actionscript/org/flowplayer/view/AnimationEngine.as b/core/src/actionscript/org/flowplayer/view/AnimationEngine.as
index ab40a1d..78bf7f5 100644
--- a/core/src/actionscript/org/flowplayer/view/AnimationEngine.as
+++ b/core/src/actionscript/org/flowplayer/view/AnimationEngine.as
@@ -263,7 +263,7 @@ package org.flowplayer.view {
} else {
log.info("previous fadeout was canceled, will not remove " + view + " from panel");
}
- });
+ }, false, 0, true);
} else if (view.parent != _panel) {
_panel.addView(view, null, plugin);
}
@@ -337,12 +337,12 @@ package org.flowplayer.view {
playable.addEventListener(GoEvent.COMPLETE,
function(event:GoEvent):void {
onComplete(view, playable, completeCallback);
- });
+ }, false, 0, true);
if (updateCallback != null) {
playable.addEventListener(GoEvent.UPDATE,
function(event:GoEvent):void {
updateCallback(view);
- });
+ }, false, 0, true);
}
playable.start();
diff --git a/core/src/actionscript/org/flowplayer/view/ClipResizer.as b/core/src/actionscript/org/flowplayer/view/ClipResizer.as
index 397ca7f..3c182df 100644
--- a/core/src/actionscript/org/flowplayer/view/ClipResizer.as
+++ b/core/src/actionscript/org/flowplayer/view/ClipResizer.as
@@ -69,11 +69,7 @@ package org.flowplayer.view {
public function resizeClipTo(clip:Clip, mediaSize:MediaSize, force:Boolean = false):void {
log.debug("resizeClipTo, clip " + clip);
- if ( _resizerTimer ) {
- log.debug("Killing old resize timer");
- _resizerTimer.reset();
- _resizerTimer = null;
- }
+
var resizer:MediaResizer = resizers[clip];
if (! resizer) {
@@ -92,16 +88,26 @@ package org.flowplayer.view {
screen.resized(clip);
}
};
+
+
if ( resizer.hasOrigSize() ) {
log.debug("we have a size, resizing now !");
resizingFunc();
} else {
+
+ if ( _resizerTimer ) {
+ log.debug("Killing old resize timer");
+ _resizerTimer.reset();
+ _resizerTimer.removeEventListener(TimerEvent.TIMER, resizingFunc);
+ _resizerTimer = null;
+ }
+
// delayed one
log.warn("we don't have a size now, delaying the resize");
_resizerTimer = new Timer(500, 5);
_resizerTimer.addEventListener(TimerEvent.TIMER, resizingFunc);
- _resizerTimer.start();
+ //_resizerTimer.start();
}
}
diff --git a/core/src/actionscript/org/flowplayer/view/Flowplayer.as b/core/src/actionscript/org/flowplayer/view/Flowplayer.as
index 100621f..8edeb5a 100644
--- a/core/src/actionscript/org/flowplayer/view/Flowplayer.as
+++ b/core/src/actionscript/org/flowplayer/view/Flowplayer.as
@@ -162,6 +162,7 @@ package org.flowplayer.view {
addCallback("setKeyboardShortcutsEnabled", setKeyboardShortcutsEnabled);
addCallback("isKeyboardShortcutsEnabled", isKeyboardShortcutsEnabled);
addCallback("validateKey", validateKey);
+ addCallback("checkKeyInDomain", checkKeyInDomain);
addCallback("bufferAnimate", bufferAnimate);
@@ -380,10 +381,15 @@ package org.flowplayer.view {
};
}
- private function validateKey(key:Object, pageDomain:Boolean):Boolean {
- var LicenseKey:Class = Class(getDefinitionByName("org.flowplayer.view.LicenseKey"));
- return LicenseKey["validate"](_canvas.loaderInfo.url, version, key, pageDomain);
- }
+ private function validateKey(key:Object, pageDomain:Boolean):Boolean {
+ var LicenseKey:Class = Class(getDefinitionByName("org.flowplayer.view.LicenseKey"));
+ return LicenseKey["validate"](_canvas.loaderInfo.url, version, key, pageDomain);
+ }
+
+ private function checkKeyInDomain(key:Object, domain:String):Boolean {
+ var LicenseKey:Class = Class(getDefinitionByName("org.flowplayer.view.LicenseKey"));
+ return LicenseKey["validate"](domain, version, key, false);
+ }
}
}
diff --git a/core/src/actionscript/org/flowplayer/view/FlowplayerBase.as b/core/src/actionscript/org/flowplayer/view/FlowplayerBase.as
index cf4382e..359f84f 100644
--- a/core/src/actionscript/org/flowplayer/view/FlowplayerBase.as
+++ b/core/src/actionscript/org/flowplayer/view/FlowplayerBase.as
@@ -708,16 +708,17 @@ package org.flowplayer.view {
if (name == "onCuePoint") {
var cuepoint:Cuepoint = Cuepoint.createDynamic(infoObj["time"], "embedded");
for (var prop:String in infoObj) {
- log.debug(prop + ": " + infoObj[prop]);
+// log.debug(prop + ": " + infoObj[prop]);
if (prop == "parameters") {
for (var param:String in infoObj.parameters) {
log.debug(param + ": " + infoObj.parameters[param]);
- cuepoint.addParameter(param, infoObj.parameters[param]);
+ cuepoint.addParameter(param.replace(/[^a-z0-9]+/gi, ""), infoObj.parameters[param]);
}
} else {
cuepoint[prop] = infoObj[prop];
}
}
+ log.debug("Dispatching cuepoint", cuepoint);
playlist.current.dispatch(ClipEventType.forName(name), cuepoint);
return;
}
diff --git a/core/src/actionscript/org/flowplayer/view/Focus.as b/core/src/actionscript/org/flowplayer/view/Focus.as
new file mode 100755
index 0000000..7865869
--- /dev/null
+++ b/core/src/actionscript/org/flowplayer/view/Focus.as
@@ -0,0 +1,195 @@
+/*
+* Copyright (c) 2008 Michael A. Jordan
+* Copyright (c) 2009 Adobe Systems, Inc.
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
+* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
+* 3. Neither the name of the copyright holders nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/*
+
+This code is based on Adobe's SWFFocus class.
+The original SWFFocus class is designed to resolve the accessibility issue in browsers other than Internet Explorer
+when users can't access player controls by keyboard alone. This accessibility issue can be viewed in 2 parts:
+
+1. User can't access player's controls, tabbing skips over the player.
+2. Once user has a focus on player's controls, he can tab through player's controls, but he is 'trapped' inside the player and can't
+shift focus back to the html page elements.
+
+Task #1 is not working in several browsers including Chrome and Opera on Windows. This issue is resolved by javascript code and does not require changes
+in the AS.
+
+Task #2 is resolved by this class and is using the same idea as Adobe's SWFFocus class uses - it injects javascript code into html page embedding the player.
+The code monitors objects receiving the focus and once the user has made a full circle (the first object received a focus again) it injects the javascript
+that shifts focus to the designated "next" html element on the page embedding the player.
+
+Code modified by: Gita Ligure
+GLigure@Books24x7.com
+November 12th, 2013
+
+*/
+package org.flowplayer.view
+{
+ import flash.display.DisplayObject;
+ import flash.display.InteractiveObject;
+ import flash.display.Stage;
+ import flash.events.Event;
+ import flash.events.EventDispatcher;
+ import flash.events.FocusEvent;
+ import flash.events.KeyboardEvent;
+ import flash.external.ExternalInterface;
+ import flash.system.Capabilities;
+ import flash.ui.Keyboard;
+ import flash.utils.setTimeout;
+
+ import org.flowplayer.util.Log;
+
+ public class Focus extends EventDispatcher
+ {
+ private var log:Log = new Log(this);
+
+ private static var _availability:Boolean = ExternalInterface.available;
+ private static var _dispatcher:EventDispatcher = new EventDispatcher();
+ private static var _instance:Focus = new Focus( SingletonLock );
+ private static var _initialized:Boolean = false;
+ private var _stage:Stage;
+
+ private var _firstRoundTabbing:Boolean = true;
+ private var _ignoreNextEvents:Boolean = false;
+
+ private var _firstTabbedObject:InteractiveObject;
+
+ private var _idNext:String;
+
+ /**
+ *
+ * Constructor
+ */
+ public function Focus( lock:Class )
+ {
+ if ( lock != SingletonLock )
+ {
+ throw new Error( "Invalid Singleton access. Use Focus.init." );
+ }
+ }
+
+ /**
+ *
+ * Initiates swffocus object, and sets callbacks
+ */
+ public static function init(stageRef:Stage):void
+ {
+ var swffocus:Focus = _instance;
+ if (stageRef && swffocus._stage != stageRef && !_initialized)
+ {
+ swffocus._stage = stageRef;
+ _initialized = swffocus._initialize();
+ }
+ }
+
+ /**
+ * @private
+ * Set event handles and inject JavaScript code
+ */
+ private function _initialize():Boolean
+ {
+ log.info("Initializing Focus ");
+ if (_availability && Capabilities.playerType.toLowerCase() == "plugin" && !Focus._initialized)
+ {
+ try {
+ ExternalInterface.addCallback("setNextFocusId", _instance.setNextFocusId);
+ } catch (e:Error) {
+ log.debug("Focus._initialize(): Unable to add JS callback.");
+ }
+ _stage.addEventListener(FocusEvent.FOCUS_IN, stage_focusInHandler, false, 0, true);
+ _stage.addEventListener(FocusEvent.FOCUS_OUT, stage_focusOutHandler, false, 0, true);
+ }
+ return true;
+ }
+
+ /**
+ * @private compares with a stored first object tabbed into
+ * and if they match, calls javascript to set focus to a next
+ * html element on the page
+ */
+ private function stage_focusOutHandler(e:FocusEvent):void
+ {
+ if (_ignoreNextEvents != true)
+ {
+ if (!_firstRoundTabbing)
+ {
+ if (_firstTabbedObject && e.relatedObject)
+ {
+ if (_firstTabbedObject.name == e.relatedObject.name) // make sure objects not null
+ {
+ log.info("IT'S A MATCH First object Stored: " + _firstTabbedObject.name + " related object " + e.relatedObject.name);
+ // reset for next round
+ _firstTabbedObject = null;
+ _firstRoundTabbing = true;
+ _ignoreNextEvents = true;
+
+ if (_idNext)
+ {
+ log.info("Should set focus on element " + _idNext);
+ ExternalInterface.call("function(){var elem = document.getElementById('" +_idNext + "'); if (elem) elem.focus();}");
+ }
+ }
+ }
+ }
+ else
+ {
+ _firstRoundTabbing = false;
+ }
+ }
+ else
+ _ignoreNextEvents = false;
+ }
+
+ /**
+ * @private stores the first target focus;
+ */
+ private function stage_focusInHandler(e:FocusEvent):void
+ {
+ if (_ignoreNextEvents != true)
+ {
+ if (_firstRoundTabbing)
+ {
+ log.info("Will store " + e.target + " as a first Tabbed object ");
+ if (e.currentTarget) _firstTabbedObject = InteractiveObject(e.target);
+ }
+ }
+
+ }
+
+ /**
+ *
+ * Callback function for JavaScript, used to set IDs of next and previous
+ * elements in the HTML tab order.
+ *
+ */
+ public function setNextFocusId(idNext:String):void
+ {
+ if (idNext)
+ _idNext = idNext;
+ }
+
+ }
+
+}
+
+
+/**
+ * This is a private class declared outside of the package
+ * that is only accessible to classes inside of the Focus.as
+ * file. Because of that, no outside code is able to get a
+ * reference to this class to pass to the constructor, which
+ * enables us to prevent outside instantiation.
+ */
+class SingletonLock
+{
+} // end class
diff --git a/core/src/actionscript/org/flowplayer/view/Launcher.as b/core/src/actionscript/org/flowplayer/view/Launcher.as
index a98c1ca..b4989f7 100644
--- a/core/src/actionscript/org/flowplayer/view/Launcher.as
+++ b/core/src/actionscript/org/flowplayer/view/Launcher.as
@@ -16,64 +16,57 @@
* along with Flowplayer. If not, see .
*/
package org.flowplayer.view {
+ import flash.display.BlendMode;
+ import flash.display.DisplayObject;
+ import flash.display.DisplayObjectContainer;
+ import flash.display.Sprite;
+ import flash.events.Event;
+ import flash.events.MouseEvent;
+ import flash.events.TimerEvent;
+ import flash.net.URLRequest;
+ import flash.net.navigateToURL;
+ import flash.system.Capabilities;
+ import flash.system.Security;
+ import flash.text.TextField;
+ import flash.text.TextFieldAutoSize;
+ import flash.utils.Timer;
+ import flash.utils.Dictionary;
+
import org.flowplayer.config.Config;
- import org.flowplayer.config.ConfigParser;
- import org.flowplayer.config.ExternalInterfaceHelper;
- import org.flowplayer.config.VersionInfo;
- import org.flowplayer.controller.PlayListController;
- import org.flowplayer.controller.ResourceLoader;
- import org.flowplayer.controller.ResourceLoaderImpl;
+ import org.flowplayer.config.ConfigParser;
+ import org.flowplayer.config.ExternalInterfaceHelper;
+ import org.flowplayer.config.VersionInfo;
+ import org.flowplayer.controller.PlayListController;
+ import org.flowplayer.controller.ResourceLoader;
+ import org.flowplayer.controller.ResourceLoaderImpl;
import org.flowplayer.flow_internal;
- import org.flowplayer.model.Callable;
- import org.flowplayer.model.Clip;
- import org.flowplayer.model.ClipEvent;
+ import org.flowplayer.model.Callable;
+ import org.flowplayer.model.Clip;
+ import org.flowplayer.model.ClipEvent;
import org.flowplayer.model.ClipEventType;
import org.flowplayer.model.DisplayPluginModel;
- import org.flowplayer.model.DisplayProperties;
- import org.flowplayer.model.DisplayPropertiesImpl;
+ import org.flowplayer.model.DisplayProperties;
import org.flowplayer.model.ErrorCode;
+ import org.flowplayer.model.Loadable;
+ import org.flowplayer.model.Logo;
+ import org.flowplayer.model.PlayButtonOverlay;
+ import org.flowplayer.model.PlayerError;
+ import org.flowplayer.model.PlayerEvent;
+ import org.flowplayer.model.Playlist;
+ import org.flowplayer.model.Plugin;
+ import org.flowplayer.model.PluginEvent;
+ import org.flowplayer.model.PluginModel;
+ import org.flowplayer.model.ProviderModel;
+ import org.flowplayer.model.State;
+ import org.flowplayer.util.Arrange;
import org.flowplayer.model.EventDispatcher;
- import org.flowplayer.model.Loadable;
- import org.flowplayer.model.Logo;
- import org.flowplayer.model.PlayButtonOverlay;
- import org.flowplayer.model.PlayerError;
- import org.flowplayer.model.PlayerEvent;
- import org.flowplayer.model.Playlist;
- import org.flowplayer.model.Plugin;
- import org.flowplayer.model.PluginError;
- import org.flowplayer.model.PluginEvent;
- import org.flowplayer.model.PluginModel;
- import org.flowplayer.model.ProviderModel;
- import org.flowplayer.model.State;
- import org.flowplayer.util.Arrange;
- import org.flowplayer.util.Log;
- import org.flowplayer.util.TextUtil;
- import org.flowplayer.util.URLUtil;
- import org.flowplayer.view.Panel;
- import org.flowplayer.view.PluginLoader;
- import org.flowplayer.view.Screen;
- import org.flowplayer.view.KeyboardHandler;
- import org.osflash.thunderbolt.Logger;
-
- import flash.display.DisplayObject;
- import flash.display.DisplayObjectContainer;
- import flash.display.Sprite;
- import flash.display.BlendMode;
-
- import flash.events.Event;
- import flash.events.MouseEvent;
- import flash.events.TimerEvent;
- import flash.net.URLRequest;
- import flash.net.navigateToURL;
- import flash.system.Capabilities;
- import flash.system.Security;
- import flash.text.TextField;
- import flash.text.TextFieldAutoSize;
-
- import flash.utils.*;
+ import org.flowplayer.util.Log;
+ import org.flowplayer.util.TextUtil;
+ import org.flowplayer.util.URLUtil;
+ import org.osflash.thunderbolt.Logger;
CONFIG::FLASH_10_1 {
- import flash.media.StageVideo;
+ import flash.media.StageVideo;
}
use namespace flow_internal;
@@ -99,18 +92,25 @@ package org.flowplayer.view {
private var _clickCount:int;
private var _clickTimer:Timer = new Timer(200, 1);
private var _clickEvent:MouseEvent;
+ private var _fullscreenDelay:Timer;
+
private var _screenMask:Sprite;
[Frame(factoryClass="org.flowplayer.view.Preloader")]
public function Launcher() {
- addEventListener(Event.ADDED_TO_STAGE, function(e:Event):void {
- URLUtil.loaderInfo = loaderInfo;
- trace("Launcher added to stage");
- callAndHandleError(createFlashVarsConfig, PlayerError.INIT_FAILED);
- });
+ //#163 add and remove stage add listener
+ addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
super("#canvas", this);
}
+ private function onAddedToStage(e:Event):void
+ {
+ URLUtil.loaderInfo = loaderInfo;
+ trace("Launcher added to stage");
+ callAndHandleError(createFlashVarsConfig, PlayerError.INIT_FAILED);
+ removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
+ }
+
private function initPhase1():void {
if (_flowplayer) {
@@ -130,8 +130,9 @@ package org.flowplayer.view {
loader = createNewLoader();
rootStyle = _config.canvas.style;
+ //#163 combine resize events
stage.addEventListener(Event.RESIZE, onStageResize);
- stage.addEventListener(Event.RESIZE, arrangeScreen);
+ //stage.addEventListener(Event.RESIZE, arrangeScreen);
setSize(Arrange.parentWidth, Arrange.parentHeight);
@@ -213,6 +214,7 @@ package org.flowplayer.view {
log.debug("no loadable plugins, calling initPhase4");
initPhase4();
}
+ Focus.init(stage);
}
private function initPhase4(event:Event = null):void {
@@ -251,16 +253,18 @@ package org.flowplayer.view {
//#508 disabling the stagevideo screen mask, canvas is visible without it.
private function createScreenMask():void {
blendMode = BlendMode.LAYER;
+
+ var squareEdgeSize:int = Math.max(stage.stageWidth, stage.stageHeight);
_screenMask = new Sprite();
- _screenMask.graphics.beginFill(0xff0000);
- _screenMask.graphics.drawRect(0, 0, 1, 1);
+ _screenMask.graphics.beginFill(0x000000, 1);
+ _screenMask.graphics.drawRect(0, 0, squareEdgeSize, squareEdgeSize);
+ _screenMask.graphics.endFill();
_screenMask.blendMode = BlendMode.ERASE;
_screenMask.x = 0;
_screenMask.y = 0;
- _screenMask.width = 100;
- _screenMask.height = 100;
+
}
private function resizeCanvasLogo():void {
@@ -278,6 +282,8 @@ package org.flowplayer.view {
private function onStageResize(event:Event = null):void {
setSize(Arrange.parentWidth, Arrange.parentHeight);
arrangeCanvasLogo();
+ //#163 move second resize event here
+ arrangeScreen(event);
}
private function arrangeCanvasLogo():void {
@@ -292,7 +298,7 @@ package org.flowplayer.view {
var plugins:Array = _config.getLoadables();
log.debug("will load following plugins: ");
logPluginInfo(plugins);
- _pluginLoader = new PluginLoader(URLUtil.playerBaseUrl, _pluginRegistry, this, useExternalInterface());
+ _pluginLoader = new PluginLoader(URLUtil.playerBaseUrl, _pluginRegistry, this, useExternalInterface(), (CONFIG::secondaryDomains).split(" "));
_pluginLoader.addEventListener(Event.COMPLETE, pluginLoadListener);
_flowplayer.pluginLoader = _pluginLoader;
if (plugins.length == 0) {
@@ -598,14 +604,20 @@ package org.flowplayer.view {
stage.removeEventListener(Event.RESIZE, arrangeScreen);
_enteringFullscreen = true;
- var delay:Timer = new Timer(1000, 1);
- delay.addEventListener(TimerEvent.TIMER_COMPLETE, onTimerComplete);
- delay.start();
+
+ //#163 add / remove delay timer
+ _fullscreenDelay = new Timer(1000, 1);
+ _fullscreenDelay.addEventListener(TimerEvent.TIMER_COMPLETE, onTimerComplete);
+ _fullscreenDelay.start();
}
private function onTimerComplete(event:TimerEvent):void {
log.debug("fullscreen wait delay complete, display clicks are enabled again");
_enteringFullscreen = false;
+
+ _fullscreenDelay.reset();
+ _fullscreenDelay.addEventListener(TimerEvent.TIMER_COMPLETE, onTimerComplete);
+ _fullscreenDelay = null;
}
private function createFlashVarsConfig():void {
@@ -737,6 +749,7 @@ package org.flowplayer.view {
//#508 disabling the stagevideo screen mask, canvas is visible without it.
CONFIG::FLASH_10_1 {
+
_flowplayer.playlist.onStageVideoStateChange(onStageVideoStateChange);
//#44 fixes for #627, now bind and unbind stagevideo events during seeking to prevent the mask repositioning.
@@ -744,7 +757,9 @@ package org.flowplayer.view {
_flowplayer.playlist.unbind(onStageVideoStateChange);
});
- _flowplayer.playlist.onSeek(function(event:ClipEvent):void {
+ //#75 temporary fix for seeking with progressive download as it creates a delay to dispatch seek events because of the seek delay timer.
+ _flowplayer.playlist.onBufferFull(function(event:ClipEvent):void {
+ _flowplayer.playlist.unbind(onStageVideoStateChange);
_flowplayer.playlist.onStageVideoStateChange(onStageVideoStateChange);
});
}
@@ -765,6 +780,7 @@ package org.flowplayer.view {
log.debug("stage video state changed " + stageVideo);
if (stageVideo) {
+ _screenMask.visible = false;
//#44 fixes for #627 check if the stagevideo dimensions and positioning has changed to update the stage video mask with.
//unbinding and binding stage video events caused issues with instream playlists therefore has to be kept binded.
if (_screenMask.width !== stageVideo.viewPort.width) {
@@ -795,11 +811,17 @@ package org.flowplayer.view {
}
CONFIG::commercialVersion {
- addChildAt(_screenMask, 1);
+ //#75 set the child display list different when a gradient is set.
+ addChildAt(_screenMask, style.backgroundGradient ? 1 : 0);
+
}
- //addChildAt(_screenMask, _canvasLogo ? 1 : 0);
+
+
log.debug("adding mask");
}
+ _screenMask.visible = true;
+
+
} else {
if (contains(_screenMask)) {
log.debug("removing mask")
@@ -940,7 +962,7 @@ package org.flowplayer.view {
_canvasLogo.scaleY = _canvasLogo.scaleX;
_canvasLogo.alpha = .4;
_canvasLogo.addEventListener(MouseEvent.CLICK,
- function(event:MouseEvent):void { navigateToURL(new URLRequest("http://flowplayer.org"), "_self"); });
+ function(event:MouseEvent):void { navigateToURL(new URLRequest("http://flash.flowplayer.org"), "_self"); });
_canvasLogo.buttonMode = true;
log.debug("adding logo to display list");
addChild(_canvasLogo);
diff --git a/core/src/actionscript/org/flowplayer/view/Panel.as b/core/src/actionscript/org/flowplayer/view/Panel.as
index 6ec12d9..dc4a238 100644
--- a/core/src/actionscript/org/flowplayer/view/Panel.as
+++ b/core/src/actionscript/org/flowplayer/view/Panel.as
@@ -133,7 +133,7 @@ package org.flowplayer.view {
}
public function getZIndex(view:DisplayObject):int {
- try {
+ try {
return getChildIndex(view);
} catch (e:Error) {
// view not added in this panel
@@ -168,6 +168,8 @@ package org.flowplayer.view {
}
private function createLayout(event:Event):void {
+ //#163 remove event listener
+ removeEventListener(Event.ADDED_TO_STAGE, createLayout);
layout = new MarginLayout(stage);
}
diff --git a/core/src/actionscript/org/flowplayer/view/PluginLoader.as b/core/src/actionscript/org/flowplayer/view/PluginLoader.as
index 2b8bfb0..7a8f901 100644
--- a/core/src/actionscript/org/flowplayer/view/PluginLoader.as
+++ b/core/src/actionscript/org/flowplayer/view/PluginLoader.as
@@ -18,46 +18,42 @@
*/
package org.flowplayer.view {
- import flash.display.AVM1Movie;
+import com.adobe.utils.StringUtil;
+
+import flash.display.AVM1Movie;
+import flash.display.DisplayObject;
+import flash.display.Loader;
+import flash.display.LoaderInfo;
+import flash.events.Event;
+import flash.events.EventDispatcher;
+import flash.events.IOErrorEvent;
+import flash.events.ProgressEvent;
+import flash.net.URLRequest;
+import flash.system.ApplicationDomain;
+import flash.system.LoaderContext;
import flash.system.Security;
-
- import org.flowplayer.model.ErrorCode;
- import org.flowplayer.model.Plugin;
- import org.flowplayer.controller.NetStreamControllingStreamProvider;
-
- import com.adobe.utils.StringUtil;
-
- import org.flowplayer.config.ExternalInterfaceHelper;
- import org.flowplayer.controller.StreamProvider;
- import org.flowplayer.model.Callable;
- import org.flowplayer.model.DisplayPluginModel;
- import org.flowplayer.model.FontProvider;
- import org.flowplayer.model.Loadable;
- import org.flowplayer.model.PlayerError;
- import org.flowplayer.model.PluginError;
- import org.flowplayer.model.PluginEvent;
- import org.flowplayer.model.PluginModel;
- import org.flowplayer.model.ProviderModel;
- import org.flowplayer.util.Log;
- import org.flowplayer.util.URLUtil;
-
- import flash.display.DisplayObject;
- import flash.display.Loader;
- import flash.display.LoaderInfo;
- import flash.events.Event;
- import flash.events.EventDispatcher;
- import flash.events.IOErrorEvent;
- import flash.events.ProgressEvent;
- import flash.net.URLRequest;
- import flash.system.ApplicationDomain;
- import flash.system.LoaderContext;
- import flash.system.SecurityDomain;
- import flash.utils.Dictionary;
- import flash.utils.getDefinitionByName;
- import flash.utils.getQualifiedClassName;
-
-
- /**
+import flash.system.SecurityDomain;
+import flash.utils.Dictionary;
+import flash.utils.getDefinitionByName;
+import flash.utils.getQualifiedClassName;
+
+import org.flowplayer.config.ExternalInterfaceHelper;
+import org.flowplayer.controller.NetStreamControllingStreamProvider;
+import org.flowplayer.controller.StreamProvider;
+import org.flowplayer.model.Callable;
+import org.flowplayer.model.DisplayPluginModel;
+import org.flowplayer.model.FontProvider;
+import org.flowplayer.model.Loadable;
+import org.flowplayer.model.Plugin;
+import org.flowplayer.model.PluginError;
+import org.flowplayer.model.PluginEvent;
+import org.flowplayer.model.PluginModel;
+import org.flowplayer.model.ProviderModel;
+import org.flowplayer.util.DomainUtil;
+import org.flowplayer.util.Log;
+import org.flowplayer.util.URLUtil;
+
+/**
* @author api
*/
public class PluginLoader extends EventDispatcher {
@@ -79,13 +75,15 @@ import flash.system.Security;
private var _allPlugins:Array;
private var _loaderContext:LoaderContext;
private var _loadStartedCount:int = 0;
+ private var _secondaries:Array;
- public function PluginLoader(baseUrl:String, pluginRegistry:PluginRegistry, errorHandler:ErrorHandler, useExternalInterface:Boolean) {
+ public function PluginLoader(baseUrl:String, pluginRegistry:PluginRegistry, errorHandler:ErrorHandler, useExternalInterface:Boolean, secondaries:Array) {
_baseUrl = baseUrl;
_pluginRegistry = pluginRegistry;
_errorHandler = errorHandler;
_useExternalInterface = useExternalInterface;
_loadedCount = 0;
+ _secondaries = secondaries;
}
private function constructUrl(url:String):String {
@@ -162,7 +160,14 @@ import flash.system.Security;
for (var i:Number = 0; i < plugins.length; i++) {
var loadable:Loadable = Loadable(plugins[i]);
if (! loadable.isBuiltIn && loadable.url && result.indexOf(loadable.url) < 0) {
- result.push(constructUrl(loadable.url));
+ var pluginUrl:String = constructUrl(loadable.url);
+
+ if (DomainUtil.allowCodeLoading(pluginUrl, _secondaries)) {
+ result.push(pluginUrl);
+ } else {
+ log.error("Unable to load plugin from " + loadable.url);
+ loadable.dispatchError(PluginError.ERROR, "Unable to load plugin from " + pluginUrl);
+ }
}
}
return result;
diff --git a/core/src/actionscript/org/flowplayer/view/PluginRegistry.as b/core/src/actionscript/org/flowplayer/view/PluginRegistry.as
index 5cfaf91..471f8db 100644
--- a/core/src/actionscript/org/flowplayer/view/PluginRegistry.as
+++ b/core/src/actionscript/org/flowplayer/view/PluginRegistry.as
@@ -75,9 +75,10 @@ package org.flowplayer.view {
public function getPlugin(name:String):Object {
var plugin:Object = _plugins[name] || _providers[name] || _genericPlugins[name];
log.debug("found plugin " + plugin);
- if (plugin is DisplayProperties) {
- updateZIndex(plugin as DisplayProperties);
- }
+ //#163 is this needed ?
+ //if (plugin is DisplayProperties) {
+ //updateZIndex(plugin as DisplayProperties);
+ //}
return plugin;
}
@@ -203,6 +204,9 @@ package org.flowplayer.view {
for each (var model:Object in transientCopy) {
setPlayerToPlugin(model);
}
+
+ transientCopy.length = 0;
+ transientCopy = null;
}
internal function setPlayerToPlugin(plugin:Object):void {
diff --git a/core/src/actionscript/org/flowplayer/view/RotatingAnimation.as b/core/src/actionscript/org/flowplayer/view/RotatingAnimation.as
index 90bc5d9..2fb2d92 100644
--- a/core/src/actionscript/org/flowplayer/view/RotatingAnimation.as
+++ b/core/src/actionscript/org/flowplayer/view/RotatingAnimation.as
@@ -33,10 +33,12 @@ import flash.utils.Timer;
}
public function start():void {
+ _rotationTimer.addEventListener(TimerEvent.TIMER, rotate);
_rotationTimer.start();
}
public function stop():void {
+ _rotationTimer.removeEventListener(TimerEvent.TIMER, rotate);
_rotationTimer.stop();
}
diff --git a/core/src/actionscript/org/flowplayer/view/Screen.as b/core/src/actionscript/org/flowplayer/view/Screen.as
index f510da6..012e476 100644
--- a/core/src/actionscript/org/flowplayer/view/Screen.as
+++ b/core/src/actionscript/org/flowplayer/view/Screen.as
@@ -70,6 +70,10 @@ package org.flowplayer.view {
_pluginRegistry = pluginRegistry;
}
+ //#163 dummy function for plugin registry
+ public function onLoad():void {}
+
+
override public function addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void {
addEventListenerToDisplays(_playList.clips.concat(_playList.childClips), type, listener);
@@ -95,9 +99,8 @@ package org.flowplayer.view {
private function createDisplays(clips:Array):void {
for (var i:Number = 0; i < clips.length; i++) {
- var clip:Clip = clips[i];
- if (! clip.isNullClip) {
- createDisplay(clip);
+ if (! clips[i].isNullClip) {
+ createDisplay(clips[i]);
}
}
}
@@ -112,8 +115,6 @@ package org.flowplayer.view {
_displays[clip] = display;
for(var key:Object in _addDisplayListeners)
_addDisplayListeners[key](display);
- //#375 clearing the event listeners here prevents new events being added when the playlist is replaced
- //_addDisplayListeners = new Dictionary();
}
public function setVideoApiOverlaySize(width:Number, height:Number):void {
@@ -263,7 +264,14 @@ package org.flowplayer.view {
removeChild(_displays[clips[i]]);
for(var key:Object in _removeDisplayListeners)
_removeDisplayListeners[key](_displays[clips[i]]);
+ //#163 clear content and empty display list
+ clips[i].setContent(null);
+ _displays[clips[i]] = null;
+ delete _displays[clips[i]];
}
+
+ //#163 initialize display list
+ _displays.length = 0;
//#375 clearing the event listeners here prevents new events being added when the playlist is replaced
//_removeDisplayListeners = new Dictionary();
}
@@ -293,6 +301,8 @@ package org.flowplayer.view {
private function removeOneShotDisplay(event:ClipEvent):void {
log.debug("removing display of a one shot clip " + event.target);
removeChild(_displays[event.target]);
+ //#163 clear content
+ event.target.setContent(null);
delete _displays[event.target];
}
diff --git a/core/src/javascript/flashembed.js b/core/src/javascript/flashembed.js
index 6d81775..8aaa33b 100644
--- a/core/src/javascript/flashembed.js
+++ b/core/src/javascript/flashembed.js
@@ -88,10 +88,14 @@
conf: GLOBAL_OPTS,
getVersion: function() {
- var fo, ver;
+ var fo, ver, plugin;
try {
- ver = navigator.plugins["Shockwave Flash"].description.slice(16);
+ plugin = navigator.plugins["Shockwave Flash"];
+ // Safari 6 reports version even when disabled
+ // but [0, 0] should be returned (#167)
+ if (plugin[0].enabledPlugin != null)
+ ver = plugin.description.slice(16);
} catch(e) {
try {
diff --git a/core/src/javascript/flowplayer.js/build.xml b/core/src/javascript/flowplayer.js/build.xml
deleted file mode 100644
index 1be9454..0000000
--- a/core/src/javascript/flowplayer.js/build.xml
+++ /dev/null
@@ -1,31 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/core/src/javascript/flowplayer.js/flowplayer-3.2.12.min.js b/core/src/javascript/flowplayer.js/flowplayer-3.2.12.min.js
new file mode 100644
index 0000000..ff7b48f
--- /dev/null
+++ b/core/src/javascript/flowplayer.js/flowplayer-3.2.12.min.js
@@ -0,0 +1,24 @@
+/*
+ * flowplayer.js 3.2.12. The Flowplayer API
+ *
+ * Copyright 2009-2011 Flowplayer Oy
+ *
+ * This file is part of Flowplayer.
+ *
+ * Flowplayer is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Flowplayer is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Flowplayer. If not, see .
+ *
+ * Date: ${date}
+ * Revision: ${revision}
+ */
+!function(){function h(p){console.log("$f.fireEvent",[].slice.call(p))}function l(r){if(!r||typeof r!="object"){return r}var p=new r.constructor();for(var q in r){if(r.hasOwnProperty(q)){p[q]=l(r[q])}}return p}function n(u,r){if(!u){return}var p,q=0,s=u.length;if(s===undefined){for(p in u){if(r.call(u[p],p,u[p])===false){break}}}else{for(var t=u[0];q1){var u=arguments[1],r=(arguments.length==3)?arguments[2]:{};if(typeof u=="string"){u={src:u}}u=j({bgcolor:"#000000",version:[10,1],expressInstall:"http://releases.flowplayer.org/swf/expressinstall.swf",cachebusting:false},u);if(typeof p=="string"){if(p.indexOf(".")!=-1){var t=[];n(o(p),function(){t.push(new b(this,l(u),l(r)))});return new d(t)}else{var s=c(p);return new b(s!==null?s:l(p),l(u),l(r))}}else{if(p){return new b(p,l(u),l(r))}}}return null};j(window.$f,{fireEvent:function(){var q=[].slice.call(arguments);var r=$f(q[0]);return r?r._fireEvent(q.slice(1)):null},addPlugin:function(p,q){b.prototype[p]=q;return $f},each:n,extend:j});if(typeof jQuery=="function"){jQuery.fn.flowplayer=function(r,q){if(!arguments.length||typeof arguments[0]=="number"){var p=[];this.each(function(){var s=$f(this);if(s){p.push(s)}});return arguments.length?p[arguments[0]]:new d(p)}return this.each(function(){$f(this,l(r),q?l(q):{})})}}}();!function(){var h=document.all,j="http://get.adobe.com/flashplayer",c=typeof jQuery=="function",e=/(\d+)[^\d]+(\d+)[^\d]*(\d*)/,b={width:"100%",height:"100%",id:"_"+(""+Math.random()).slice(9),allowfullscreen:true,allowscriptaccess:"always",quality:"high",version:[3,0],onFail:null,expressInstall:null,w3c:false,cachebusting:false};if(window.attachEvent){window.attachEvent("onbeforeunload",function(){__flash_unloadHandler=function(){};__flash_savedUnloadHandler=function(){}})}function i(m,l){if(l){for(var f in l){if(l.hasOwnProperty(f)){m[f]=l[f]}}}return m}function a(f,n){var m=[];for(var l in f){if(f.hasOwnProperty(l)){m[l]=n(f[l])}}return m}window.flashembed=function(f,m,l){if(typeof f=="string"){f=document.getElementById(f.replace("#",""))}if(!f){return}if(typeof m=="string"){m={src:m}}return new d(f,i(i({},b),m),l)};var g=i(window.flashembed,{conf:b,getVersion:function(){var m,f;try{f=navigator.plugins["Shockwave Flash"].description.slice(16)}catch(o){try{m=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");f=m&&m.GetVariable("$version")}catch(n){try{m=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");f=m&&m.GetVariable("$version")}catch(l){}}}f=e.exec(f);return f?[1*f[1],1*f[(f[1]*1>9?2:3)]*1]:[0,0]},asString:function(l){if(l===null||l===undefined){return null}var f=typeof l;if(f=="object"&&l.push){f="array"}switch(f){case"string":l=l.replace(new RegExp('(["\\\\])',"g"),"\\$1");l=l.replace(/^\s?(\d+\.?\d*)%/,"$1pct");return'"'+l+'"';case"array":return"["+a(l,function(o){return g.asString(o)}).join(",")+"]";case"function":return'"function()"';case"object":var m=[];for(var n in l){if(l.hasOwnProperty(n)){m.push('"'+n+'":'+g.asString(l[n]))}}return"{"+m.join(",")+"}"}return String(l).replace(/\s/g," ").replace(/\'/g,'"')},getHTML:function(o,l){o=i({},o);var n='";return n},isSupported:function(f){return k[0]>f[0]||k[0]==f[0]&&k[1]>=f[1]}});var k=g.getVersion();function d(f,n,m){if(g.isSupported(n.version)){f.innerHTML=g.getHTML(n,m)}else{if(n.expressInstall&&g.isSupported([6,65])){f.innerHTML=g.getHTML(i(n,{src:n.expressInstall}),{MMredirectURL:encodeURIComponent(location.href),MMplayerType:"PlugIn",MMdoctitle:document.title})}else{if(!f.innerHTML.replace(/\s/g,"")){f.innerHTML="Flash version "+n.version+" or greater is required
"+(k[0]>0?"Your version is "+k:"You have no flash plugin installed")+"
"+(f.tagName=="A"?"
Click here to download latest version
":"Download latest version from here
");if(f.tagName=="A"||f.tagName=="DIV"){f.onclick=function(){location.href=j}}}if(n.onFail){var l=n.onFail.call(this);if(typeof l=="string"){f.innerHTML=l}}}}if(h){window[n.id]=document.getElementById(n.id)}i(this,{getRoot:function(){return f},getOptions:function(){return n},getConf:function(){return m},getApi:function(){return f.firstChild}})}if(c){jQuery.tools=jQuery.tools||{version:"3.2.12"};jQuery.tools.flashembed={conf:b};jQuery.fn.flashembed=function(l,f){return this.each(function(){$(this).data("flashembed",flashembed(this,l,f))})}}}();
\ No newline at end of file
diff --git a/core/src/javascript/flowplayer.js/flowplayer-src.js b/core/src/javascript/flowplayer.js/flowplayer-src.js
index 163c98e..c216e56 100644
--- a/core/src/javascript/flowplayer.js/flowplayer-src.js
+++ b/core/src/javascript/flowplayer.js/flowplayer-src.js
@@ -1,5 +1,5 @@
/*!
- * flowplayer.js @VERSION. The Flowplayer API
+ * flowplayer.js The Flowplayer API
*
* Copyright 2009-2011 Flowplayer Oy
*
@@ -18,8 +18,6 @@
* You should have received a copy of the GNU General Public License
* along with Flowplayer. If not, see .
*
- * Date: @DATE
- * Revision: @REVISION
*/
!function() {
@@ -262,7 +260,8 @@
}
// 1. clip properties, 2-3. metadata, 4. updates, 5. resumes from nested clip
- if (arg1 && "onBeforeBegin,onMetaData,onStart,onUpdate,onResume".indexOf(evt) != -1) {
+ //#148 add onMetaDataChange event to extend clip properties, this was needed to prevent regular updates during stream switching.
+ if (arg1 && "onBeforeBegin,onMetaData,onMetaDataChange,onStart,onUpdate,onResume".indexOf(evt) != -1) {
// update clip properties
extend(target, arg1);
diff --git a/core/test/analytics.html b/core/test/analytics.html
index 407b6e5..e34a0fa 100644
--- a/core/test/analytics.html
+++ b/core/test/analytics.html
@@ -1,7 +1,8 @@
-
+
+
@@ -16,7 +17,11 @@
id="player">
diff --git a/core/test/audio.html b/core/test/audio.html
index 7186265..b7ba659 100644
--- a/core/test/audio.html
+++ b/core/test/audio.html
@@ -1,7 +1,7 @@
-
+
@@ -16,9 +16,9 @@
id="player">
-->
-
+
@@ -19,7 +18,7 @@
id="player">
-
+
+
+
\ No newline at end of file
diff --git a/core/test/extconfig.html b/core/test/extconfig.html
index 2b27791..3709728 100644
--- a/core/test/extconfig.html
+++ b/core/test/extconfig.html
@@ -18,9 +18,9 @@
id="player">
diff --git a/core/test/http-bitrates.html b/core/test/http-bitrates.html
index 35f58e2..6f9aa31 100644
--- a/core/test/http-bitrates.html
+++ b/core/test/http-bitrates.html
@@ -1,7 +1,7 @@
-
+
@@ -15,10 +15,12 @@
style="display:block;width:440px;height:247px"
id="player">
+
+
-->
-
+
@@ -11,14 +11,14 @@
diff --git a/core/test/instream3.html b/core/test/instream3.html
new file mode 100644
index 0000000..8459709
--- /dev/null
+++ b/core/test/instream3.html
@@ -0,0 +1,75 @@
+
+
+
+
+
+
+
+ Minimal Flowplayer setup
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/core/test/live-rtmp.html b/core/test/live-rtmp.html
index 0f5b26e..cb79d69 100644
--- a/core/test/live-rtmp.html
+++ b/core/test/live-rtmp.html
@@ -16,15 +16,16 @@
id="player">
-->
+
+
+
+
+ Minimal Flowplayer setup
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/core/test/rtmp-test.html b/core/test/rtmp-test.html
index 29beb88..81f2ee4 100644
--- a/core/test/rtmp-test.html
+++ b/core/test/rtmp-test.html
@@ -15,9 +15,13 @@
id="player">
-->
+
+
+
+
+
+ Minimal Flowplayer setup
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/core/test/viral.html b/core/test/viral.html
index 3b13c59..fae4cda 100644
--- a/core/test/viral.html
+++ b/core/test/viral.html
@@ -1,7 +1,7 @@
-
+
@@ -11,12 +11,12 @@
- Hidden frame for Browser History support.
-
-
+
+
+
+
+
+
+
+ Hidden frame for Browser History support.
+
+
diff --git a/lib/osmf/framework/OSMFTest/html-template/swfobject.js b/lib/osmf/framework/OSMFTest/html-template/swfobject.js
index bf35c07..7a9d26f 100644
--- a/lib/osmf/framework/OSMFTest/html-template/swfobject.js
+++ b/lib/osmf/framework/OSMFTest/html-template/swfobject.js
@@ -1,777 +1,777 @@
-/*! SWFObject v2.2
- is released under the MIT License
-*/
-
-var swfobject = function() {
-
- var UNDEF = "undefined",
- OBJECT = "object",
- SHOCKWAVE_FLASH = "Shockwave Flash",
- SHOCKWAVE_FLASH_AX = "ShockwaveFlash.ShockwaveFlash",
- FLASH_MIME_TYPE = "application/x-shockwave-flash",
- EXPRESS_INSTALL_ID = "SWFObjectExprInst",
- ON_READY_STATE_CHANGE = "onreadystatechange",
-
- win = window,
- doc = document,
- nav = navigator,
-
- plugin = false,
- domLoadFnArr = [main],
- regObjArr = [],
- objIdArr = [],
- listenersArr = [],
- storedAltContent,
- storedAltContentId,
- storedCallbackFn,
- storedCallbackObj,
- isDomLoaded = false,
- isExpressInstallActive = false,
- dynamicStylesheet,
- dynamicStylesheetMedia,
- autoHideShow = true,
-
- /* Centralized function for browser feature detection
- - User agent string detection is only used when no good alternative is possible
- - Is executed directly for optimal performance
- */
- ua = function() {
- var w3cdom = typeof doc.getElementById != UNDEF && typeof doc.getElementsByTagName != UNDEF && typeof doc.createElement != UNDEF,
- u = nav.userAgent.toLowerCase(),
- p = nav.platform.toLowerCase(),
- windows = p ? /win/.test(p) : /win/.test(u),
- mac = p ? /mac/.test(p) : /mac/.test(u),
- webkit = /webkit/.test(u) ? parseFloat(u.replace(/^.*webkit\/(\d+(\.\d+)?).*$/, "$1")) : false, // returns either the webkit version or false if not webkit
- ie = !+"\v1", // feature detection based on Andrea Giammarchi's solution: http://webreflection.blogspot.com/2009/01/32-bytes-to-know-if-your-browser-is-ie.html
- playerVersion = [0,0,0],
- d = null;
- if (typeof nav.plugins != UNDEF && typeof nav.plugins[SHOCKWAVE_FLASH] == OBJECT) {
- d = nav.plugins[SHOCKWAVE_FLASH].description;
- if (d && !(typeof nav.mimeTypes != UNDEF && nav.mimeTypes[FLASH_MIME_TYPE] && !nav.mimeTypes[FLASH_MIME_TYPE].enabledPlugin)) { // navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin indicates whether plug-ins are enabled or disabled in Safari 3+
- plugin = true;
- ie = false; // cascaded feature detection for Internet Explorer
- d = d.replace(/^.*\s+(\S+\s+\S+$)/, "$1");
- playerVersion[0] = parseInt(d.replace(/^(.*)\..*$/, "$1"), 10);
- playerVersion[1] = parseInt(d.replace(/^.*\.(.*)\s.*$/, "$1"), 10);
- playerVersion[2] = /[a-zA-Z]/.test(d) ? parseInt(d.replace(/^.*[a-zA-Z]+(.*)$/, "$1"), 10) : 0;
- }
- }
- else if (typeof win.ActiveXObject != UNDEF) {
- try {
- var a = new ActiveXObject(SHOCKWAVE_FLASH_AX);
- if (a) { // a will return null when ActiveX is disabled
- d = a.GetVariable("$version");
- if (d) {
- ie = true; // cascaded feature detection for Internet Explorer
- d = d.split(" ")[1].split(",");
- playerVersion = [parseInt(d[0], 10), parseInt(d[1], 10), parseInt(d[2], 10)];
- }
- }
- }
- catch(e) {}
- }
- return { w3:w3cdom, pv:playerVersion, wk:webkit, ie:ie, win:windows, mac:mac };
- }(),
-
- /* Cross-browser onDomLoad
- - Will fire an event as soon as the DOM of a web page is loaded
- - Internet Explorer workaround based on Diego Perini's solution: http://javascript.nwbox.com/IEContentLoaded/
- - Regular onload serves as fallback
- */
- onDomLoad = function() {
- if (!ua.w3) { return; }
- if ((typeof doc.readyState != UNDEF && doc.readyState == "complete") || (typeof doc.readyState == UNDEF && (doc.getElementsByTagName("body")[0] || doc.body))) { // function is fired after onload, e.g. when script is inserted dynamically
- callDomLoadFunctions();
- }
- if (!isDomLoaded) {
- if (typeof doc.addEventListener != UNDEF) {
- doc.addEventListener("DOMContentLoaded", callDomLoadFunctions, false);
- }
- if (ua.ie && ua.win) {
- doc.attachEvent(ON_READY_STATE_CHANGE, function() {
- if (doc.readyState == "complete") {
- doc.detachEvent(ON_READY_STATE_CHANGE, arguments.callee);
- callDomLoadFunctions();
- }
- });
- if (win == top) { // if not inside an iframe
- (function(){
- if (isDomLoaded) { return; }
- try {
- doc.documentElement.doScroll("left");
- }
- catch(e) {
- setTimeout(arguments.callee, 0);
- return;
- }
- callDomLoadFunctions();
- })();
- }
- }
- if (ua.wk) {
- (function(){
- if (isDomLoaded) { return; }
- if (!/loaded|complete/.test(doc.readyState)) {
- setTimeout(arguments.callee, 0);
- return;
- }
- callDomLoadFunctions();
- })();
- }
- addLoadEvent(callDomLoadFunctions);
- }
- }();
-
- function callDomLoadFunctions() {
- if (isDomLoaded) { return; }
- try { // test if we can really add/remove elements to/from the DOM; we don't want to fire it too early
- var t = doc.getElementsByTagName("body")[0].appendChild(createElement("span"));
- t.parentNode.removeChild(t);
- }
- catch (e) { return; }
- isDomLoaded = true;
- var dl = domLoadFnArr.length;
- for (var i = 0; i < dl; i++) {
- domLoadFnArr[i]();
- }
- }
-
- function addDomLoadEvent(fn) {
- if (isDomLoaded) {
- fn();
- }
- else {
- domLoadFnArr[domLoadFnArr.length] = fn; // Array.push() is only available in IE5.5+
- }
- }
-
- /* Cross-browser onload
- - Based on James Edwards' solution: http://brothercake.com/site/resources/scripts/onload/
- - Will fire an event as soon as a web page including all of its assets are loaded
- */
- function addLoadEvent(fn) {
- if (typeof win.addEventListener != UNDEF) {
- win.addEventListener("load", fn, false);
- }
- else if (typeof doc.addEventListener != UNDEF) {
- doc.addEventListener("load", fn, false);
- }
- else if (typeof win.attachEvent != UNDEF) {
- addListener(win, "onload", fn);
- }
- else if (typeof win.onload == "function") {
- var fnOld = win.onload;
- win.onload = function() {
- fnOld();
- fn();
- };
- }
- else {
- win.onload = fn;
- }
- }
-
- /* Main function
- - Will preferably execute onDomLoad, otherwise onload (as a fallback)
- */
- function main() {
- if (plugin) {
- testPlayerVersion();
- }
- else {
- matchVersions();
- }
- }
-
- /* Detect the Flash Player version for non-Internet Explorer browsers
- - Detecting the plug-in version via the object element is more precise than using the plugins collection item's description:
- a. Both release and build numbers can be detected
- b. Avoid wrong descriptions by corrupt installers provided by Adobe
- c. Avoid wrong descriptions by multiple Flash Player entries in the plugin Array, caused by incorrect browser imports
- - Disadvantage of this method is that it depends on the availability of the DOM, while the plugins collection is immediately available
- */
- function testPlayerVersion() {
- var b = doc.getElementsByTagName("body")[0];
- var o = createElement(OBJECT);
- o.setAttribute("type", FLASH_MIME_TYPE);
- var t = b.appendChild(o);
- if (t) {
- var counter = 0;
- (function(){
- if (typeof t.GetVariable != UNDEF) {
- var d = t.GetVariable("$version");
- if (d) {
- d = d.split(" ")[1].split(",");
- ua.pv = [parseInt(d[0], 10), parseInt(d[1], 10), parseInt(d[2], 10)];
- }
- }
- else if (counter < 10) {
- counter++;
- setTimeout(arguments.callee, 10);
- return;
- }
- b.removeChild(o);
- t = null;
- matchVersions();
- })();
- }
- else {
- matchVersions();
- }
- }
-
- /* Perform Flash Player and SWF version matching; static publishing only
- */
- function matchVersions() {
- var rl = regObjArr.length;
- if (rl > 0) {
- for (var i = 0; i < rl; i++) { // for each registered object element
- var id = regObjArr[i].id;
- var cb = regObjArr[i].callbackFn;
- var cbObj = {success:false, id:id};
- if (ua.pv[0] > 0) {
- var obj = getElementById(id);
- if (obj) {
- if (hasPlayerVersion(regObjArr[i].swfVersion) && !(ua.wk && ua.wk < 312)) { // Flash Player version >= published SWF version: Houston, we have a match!
- setVisibility(id, true);
- if (cb) {
- cbObj.success = true;
- cbObj.ref = getObjectById(id);
- cb(cbObj);
- }
- }
- else if (regObjArr[i].expressInstall && canExpressInstall()) { // show the Adobe Express Install dialog if set by the web page author and if supported
- var att = {};
- att.data = regObjArr[i].expressInstall;
- att.width = obj.getAttribute("width") || "0";
- att.height = obj.getAttribute("height") || "0";
- if (obj.getAttribute("class")) { att.styleclass = obj.getAttribute("class"); }
- if (obj.getAttribute("align")) { att.align = obj.getAttribute("align"); }
- // parse HTML object param element's name-value pairs
- var par = {};
- var p = obj.getElementsByTagName("param");
- var pl = p.length;
- for (var j = 0; j < pl; j++) {
- if (p[j].getAttribute("name").toLowerCase() != "movie") {
- par[p[j].getAttribute("name")] = p[j].getAttribute("value");
- }
- }
- showExpressInstall(att, par, id, cb);
- }
- else { // Flash Player and SWF version mismatch or an older Webkit engine that ignores the HTML object element's nested param elements: display alternative content instead of SWF
- displayAltContent(obj);
- if (cb) { cb(cbObj); }
- }
- }
- }
- else { // if no Flash Player is installed or the fp version cannot be detected we let the HTML object element do its job (either show a SWF or alternative content)
- setVisibility(id, true);
- if (cb) {
- var o = getObjectById(id); // test whether there is an HTML object element or not
- if (o && typeof o.SetVariable != UNDEF) {
- cbObj.success = true;
- cbObj.ref = o;
- }
- cb(cbObj);
- }
- }
- }
- }
- }
-
- function getObjectById(objectIdStr) {
- var r = null;
- var o = getElementById(objectIdStr);
- if (o && o.nodeName == "OBJECT") {
- if (typeof o.SetVariable != UNDEF) {
- r = o;
- }
- else {
- var n = o.getElementsByTagName(OBJECT)[0];
- if (n) {
- r = n;
- }
- }
- }
- return r;
- }
-
- /* Requirements for Adobe Express Install
- - only one instance can be active at a time
- - fp 6.0.65 or higher
- - Win/Mac OS only
- - no Webkit engines older than version 312
- */
- function canExpressInstall() {
- return !isExpressInstallActive && hasPlayerVersion("6.0.65") && (ua.win || ua.mac) && !(ua.wk && ua.wk < 312);
- }
-
- /* Show the Adobe Express Install dialog
- - Reference: http://www.adobe.com/cfusion/knowledgebase/index.cfm?id=6a253b75
- */
- function showExpressInstall(att, par, replaceElemIdStr, callbackFn) {
- isExpressInstallActive = true;
- storedCallbackFn = callbackFn || null;
- storedCallbackObj = {success:false, id:replaceElemIdStr};
- var obj = getElementById(replaceElemIdStr);
- if (obj) {
- if (obj.nodeName == "OBJECT") { // static publishing
- storedAltContent = abstractAltContent(obj);
- storedAltContentId = null;
- }
- else { // dynamic publishing
- storedAltContent = obj;
- storedAltContentId = replaceElemIdStr;
- }
- att.id = EXPRESS_INSTALL_ID;
- if (typeof att.width == UNDEF || (!/%$/.test(att.width) && parseInt(att.width, 10) < 310)) { att.width = "310"; }
- if (typeof att.height == UNDEF || (!/%$/.test(att.height) && parseInt(att.height, 10) < 137)) { att.height = "137"; }
- doc.title = doc.title.slice(0, 47) + " - Flash Player Installation";
- var pt = ua.ie && ua.win ? "ActiveX" : "PlugIn",
- fv = "MMredirectURL=" + encodeURI(window.location).toString().replace(/&/g,"%26") + "&MMplayerType=" + pt + "&MMdoctitle=" + doc.title;
- if (typeof par.flashvars != UNDEF) {
- par.flashvars += "&" + fv;
- }
- else {
- par.flashvars = fv;
- }
- // IE only: when a SWF is loading (AND: not available in cache) wait for the readyState of the object element to become 4 before removing it,
- // because you cannot properly cancel a loading SWF file without breaking browser load references, also obj.onreadystatechange doesn't work
- if (ua.ie && ua.win && obj.readyState != 4) {
- var newObj = createElement("div");
- replaceElemIdStr += "SWFObjectNew";
- newObj.setAttribute("id", replaceElemIdStr);
- obj.parentNode.insertBefore(newObj, obj); // insert placeholder div that will be replaced by the object element that loads expressinstall.swf
- obj.style.display = "none";
- (function(){
- if (obj.readyState == 4) {
- obj.parentNode.removeChild(obj);
- }
- else {
- setTimeout(arguments.callee, 10);
- }
- })();
- }
- createSWF(att, par, replaceElemIdStr);
- }
- }
-
- /* Functions to abstract and display alternative content
- */
- function displayAltContent(obj) {
- if (ua.ie && ua.win && obj.readyState != 4) {
- // IE only: when a SWF is loading (AND: not available in cache) wait for the readyState of the object element to become 4 before removing it,
- // because you cannot properly cancel a loading SWF file without breaking browser load references, also obj.onreadystatechange doesn't work
- var el = createElement("div");
- obj.parentNode.insertBefore(el, obj); // insert placeholder div that will be replaced by the alternative content
- el.parentNode.replaceChild(abstractAltContent(obj), el);
- obj.style.display = "none";
- (function(){
- if (obj.readyState == 4) {
- obj.parentNode.removeChild(obj);
- }
- else {
- setTimeout(arguments.callee, 10);
- }
- })();
- }
- else {
- obj.parentNode.replaceChild(abstractAltContent(obj), obj);
- }
- }
-
- function abstractAltContent(obj) {
- var ac = createElement("div");
- if (ua.win && ua.ie) {
- ac.innerHTML = obj.innerHTML;
- }
- else {
- var nestedObj = obj.getElementsByTagName(OBJECT)[0];
- if (nestedObj) {
- var c = nestedObj.childNodes;
- if (c) {
- var cl = c.length;
- for (var i = 0; i < cl; i++) {
- if (!(c[i].nodeType == 1 && c[i].nodeName == "PARAM") && !(c[i].nodeType == 8)) {
- ac.appendChild(c[i].cloneNode(true));
- }
- }
- }
- }
- }
- return ac;
- }
-
- /* Cross-browser dynamic SWF creation
- */
- function createSWF(attObj, parObj, id) {
- var r, el = getElementById(id);
- if (ua.wk && ua.wk < 312) { return r; }
- if (el) {
- if (typeof attObj.id == UNDEF) { // if no 'id' is defined for the object element, it will inherit the 'id' from the alternative content
- attObj.id = id;
- }
- if (ua.ie && ua.win) { // Internet Explorer + the HTML object element + W3C DOM methods do not combine: fall back to outerHTML
- var att = "";
- for (var i in attObj) {
- if (attObj[i] != Object.prototype[i]) { // filter out prototype additions from other potential libraries
- if (i.toLowerCase() == "data") {
- parObj.movie = attObj[i];
- }
- else if (i.toLowerCase() == "styleclass") { // 'class' is an ECMA4 reserved keyword
- att += ' class="' + attObj[i] + '"';
- }
- else if (i.toLowerCase() != "classid") {
- att += ' ' + i + '="' + attObj[i] + '"';
- }
- }
- }
- var par = "";
- for (var j in parObj) {
- if (parObj[j] != Object.prototype[j]) { // filter out prototype additions from other potential libraries
- par += '';
- }
- }
- el.outerHTML = '';
- objIdArr[objIdArr.length] = attObj.id; // stored to fix object 'leaks' on unload (dynamic publishing only)
- r = getElementById(attObj.id);
- }
- else { // well-behaving browsers
- var o = createElement(OBJECT);
- o.setAttribute("type", FLASH_MIME_TYPE);
- for (var m in attObj) {
- if (attObj[m] != Object.prototype[m]) { // filter out prototype additions from other potential libraries
- if (m.toLowerCase() == "styleclass") { // 'class' is an ECMA4 reserved keyword
- o.setAttribute("class", attObj[m]);
- }
- else if (m.toLowerCase() != "classid") { // filter out IE specific attribute
- o.setAttribute(m, attObj[m]);
- }
- }
- }
- for (var n in parObj) {
- if (parObj[n] != Object.prototype[n] && n.toLowerCase() != "movie") { // filter out prototype additions from other potential libraries and IE specific param element
- createObjParam(o, n, parObj[n]);
- }
- }
- el.parentNode.replaceChild(o, el);
- r = o;
- }
- }
- return r;
- }
-
- function createObjParam(el, pName, pValue) {
- var p = createElement("param");
- p.setAttribute("name", pName);
- p.setAttribute("value", pValue);
- el.appendChild(p);
- }
-
- /* Cross-browser SWF removal
- - Especially needed to safely and completely remove a SWF in Internet Explorer
- */
- function removeSWF(id) {
- var obj = getElementById(id);
- if (obj && obj.nodeName == "OBJECT") {
- if (ua.ie && ua.win) {
- obj.style.display = "none";
- (function(){
- if (obj.readyState == 4) {
- removeObjectInIE(id);
- }
- else {
- setTimeout(arguments.callee, 10);
- }
- })();
- }
- else {
- obj.parentNode.removeChild(obj);
- }
- }
- }
-
- function removeObjectInIE(id) {
- var obj = getElementById(id);
- if (obj) {
- for (var i in obj) {
- if (typeof obj[i] == "function") {
- obj[i] = null;
- }
- }
- obj.parentNode.removeChild(obj);
- }
- }
-
- /* Functions to optimize JavaScript compression
- */
- function getElementById(id) {
- var el = null;
- try {
- el = doc.getElementById(id);
- }
- catch (e) {}
- return el;
- }
-
- function createElement(el) {
- return doc.createElement(el);
- }
-
- /* Updated attachEvent function for Internet Explorer
- - Stores attachEvent information in an Array, so on unload the detachEvent functions can be called to avoid memory leaks
- */
- function addListener(target, eventType, fn) {
- target.attachEvent(eventType, fn);
- listenersArr[listenersArr.length] = [target, eventType, fn];
- }
-
- /* Flash Player and SWF content version matching
- */
- function hasPlayerVersion(rv) {
- var pv = ua.pv, v = rv.split(".");
- v[0] = parseInt(v[0], 10);
- v[1] = parseInt(v[1], 10) || 0; // supports short notation, e.g. "9" instead of "9.0.0"
- v[2] = parseInt(v[2], 10) || 0;
- return (pv[0] > v[0] || (pv[0] == v[0] && pv[1] > v[1]) || (pv[0] == v[0] && pv[1] == v[1] && pv[2] >= v[2])) ? true : false;
- }
-
- /* Cross-browser dynamic CSS creation
- - Based on Bobby van der Sluis' solution: http://www.bobbyvandersluis.com/articles/dynamicCSS.php
- */
- function createCSS(sel, decl, media, newStyle) {
- if (ua.ie && ua.mac) { return; }
- var h = doc.getElementsByTagName("head")[0];
- if (!h) { return; } // to also support badly authored HTML pages that lack a head element
- var m = (media && typeof media == "string") ? media : "screen";
- if (newStyle) {
- dynamicStylesheet = null;
- dynamicStylesheetMedia = null;
- }
- if (!dynamicStylesheet || dynamicStylesheetMedia != m) {
- // create dynamic stylesheet + get a global reference to it
- var s = createElement("style");
- s.setAttribute("type", "text/css");
- s.setAttribute("media", m);
- dynamicStylesheet = h.appendChild(s);
- if (ua.ie && ua.win && typeof doc.styleSheets != UNDEF && doc.styleSheets.length > 0) {
- dynamicStylesheet = doc.styleSheets[doc.styleSheets.length - 1];
- }
- dynamicStylesheetMedia = m;
- }
- // add style rule
- if (ua.ie && ua.win) {
- if (dynamicStylesheet && typeof dynamicStylesheet.addRule == OBJECT) {
- dynamicStylesheet.addRule(sel, decl);
- }
- }
- else {
- if (dynamicStylesheet && typeof doc.createTextNode != UNDEF) {
- dynamicStylesheet.appendChild(doc.createTextNode(sel + " {" + decl + "}"));
- }
- }
- }
-
- function setVisibility(id, isVisible) {
- if (!autoHideShow) { return; }
- var v = isVisible ? "visible" : "hidden";
- if (isDomLoaded && getElementById(id)) {
- getElementById(id).style.visibility = v;
- }
- else {
- createCSS("#" + id, "visibility:" + v);
- }
- }
-
- /* Filter to avoid XSS attacks
- */
- function urlEncodeIfNecessary(s) {
- var regex = /[\\\"<>\.;]/;
- var hasBadChars = regex.exec(s) != null;
- return hasBadChars && typeof encodeURIComponent != UNDEF ? encodeURIComponent(s) : s;
- }
-
- /* Release memory to avoid memory leaks caused by closures, fix hanging audio/video threads and force open sockets/NetConnections to disconnect (Internet Explorer only)
- */
- var cleanup = function() {
- if (ua.ie && ua.win) {
- window.attachEvent("onunload", function() {
- // remove listeners to avoid memory leaks
- var ll = listenersArr.length;
- for (var i = 0; i < ll; i++) {
- listenersArr[i][0].detachEvent(listenersArr[i][1], listenersArr[i][2]);
- }
- // cleanup dynamically embedded objects to fix audio/video threads and force open sockets and NetConnections to disconnect
- var il = objIdArr.length;
- for (var j = 0; j < il; j++) {
- removeSWF(objIdArr[j]);
- }
- // cleanup library's main closures to avoid memory leaks
- for (var k in ua) {
- ua[k] = null;
- }
- ua = null;
- for (var l in swfobject) {
- swfobject[l] = null;
- }
- swfobject = null;
- });
- }
- }();
-
- return {
- /* Public API
- - Reference: http://code.google.com/p/swfobject/wiki/documentation
- */
- registerObject: function(objectIdStr, swfVersionStr, xiSwfUrlStr, callbackFn) {
- if (ua.w3 && objectIdStr && swfVersionStr) {
- var regObj = {};
- regObj.id = objectIdStr;
- regObj.swfVersion = swfVersionStr;
- regObj.expressInstall = xiSwfUrlStr;
- regObj.callbackFn = callbackFn;
- regObjArr[regObjArr.length] = regObj;
- setVisibility(objectIdStr, false);
- }
- else if (callbackFn) {
- callbackFn({success:false, id:objectIdStr});
- }
- },
-
- getObjectById: function(objectIdStr) {
- if (ua.w3) {
- return getObjectById(objectIdStr);
- }
- },
-
- embedSWF: function(swfUrlStr, replaceElemIdStr, widthStr, heightStr, swfVersionStr, xiSwfUrlStr, flashvarsObj, parObj, attObj, callbackFn) {
- var callbackObj = {success:false, id:replaceElemIdStr};
- if (ua.w3 && !(ua.wk && ua.wk < 312) && swfUrlStr && replaceElemIdStr && widthStr && heightStr && swfVersionStr) {
- setVisibility(replaceElemIdStr, false);
- addDomLoadEvent(function() {
- widthStr += ""; // auto-convert to string
- heightStr += "";
- var att = {};
- if (attObj && typeof attObj === OBJECT) {
- for (var i in attObj) { // copy object to avoid the use of references, because web authors often reuse attObj for multiple SWFs
- att[i] = attObj[i];
- }
- }
- att.data = swfUrlStr;
- att.width = widthStr;
- att.height = heightStr;
- var par = {};
- if (parObj && typeof parObj === OBJECT) {
- for (var j in parObj) { // copy object to avoid the use of references, because web authors often reuse parObj for multiple SWFs
- par[j] = parObj[j];
- }
- }
- if (flashvarsObj && typeof flashvarsObj === OBJECT) {
- for (var k in flashvarsObj) { // copy object to avoid the use of references, because web authors often reuse flashvarsObj for multiple SWFs
- if (typeof par.flashvars != UNDEF) {
- par.flashvars += "&" + k + "=" + flashvarsObj[k];
- }
- else {
- par.flashvars = k + "=" + flashvarsObj[k];
- }
- }
- }
- if (hasPlayerVersion(swfVersionStr)) { // create SWF
- var obj = createSWF(att, par, replaceElemIdStr);
- if (att.id == replaceElemIdStr) {
- setVisibility(replaceElemIdStr, true);
- }
- callbackObj.success = true;
- callbackObj.ref = obj;
- }
- else if (xiSwfUrlStr && canExpressInstall()) { // show Adobe Express Install
- att.data = xiSwfUrlStr;
- showExpressInstall(att, par, replaceElemIdStr, callbackFn);
- return;
- }
- else { // show alternative content
- setVisibility(replaceElemIdStr, true);
- }
- if (callbackFn) { callbackFn(callbackObj); }
- });
- }
- else if (callbackFn) { callbackFn(callbackObj); }
- },
-
- switchOffAutoHideShow: function() {
- autoHideShow = false;
- },
-
- ua: ua,
-
- getFlashPlayerVersion: function() {
- return { major:ua.pv[0], minor:ua.pv[1], release:ua.pv[2] };
- },
-
- hasFlashPlayerVersion: hasPlayerVersion,
-
- createSWF: function(attObj, parObj, replaceElemIdStr) {
- if (ua.w3) {
- return createSWF(attObj, parObj, replaceElemIdStr);
- }
- else {
- return undefined;
- }
- },
-
- showExpressInstall: function(att, par, replaceElemIdStr, callbackFn) {
- if (ua.w3 && canExpressInstall()) {
- showExpressInstall(att, par, replaceElemIdStr, callbackFn);
- }
- },
-
- removeSWF: function(objElemIdStr) {
- if (ua.w3) {
- removeSWF(objElemIdStr);
- }
- },
-
- createCSS: function(selStr, declStr, mediaStr, newStyleBoolean) {
- if (ua.w3) {
- createCSS(selStr, declStr, mediaStr, newStyleBoolean);
- }
- },
-
- addDomLoadEvent: addDomLoadEvent,
-
- addLoadEvent: addLoadEvent,
-
- getQueryParamValue: function(param) {
- var q = doc.location.search || doc.location.hash;
- if (q) {
- if (/\?/.test(q)) { q = q.split("?")[1]; } // strip question mark
- if (param == null) {
- return urlEncodeIfNecessary(q);
- }
- var pairs = q.split("&");
- for (var i = 0; i < pairs.length; i++) {
- if (pairs[i].substring(0, pairs[i].indexOf("=")) == param) {
- return urlEncodeIfNecessary(pairs[i].substring((pairs[i].indexOf("=") + 1)));
- }
- }
- }
- return "";
- },
-
- // For internal usage only
- expressInstallCallback: function() {
- if (isExpressInstallActive) {
- var obj = getElementById(EXPRESS_INSTALL_ID);
- if (obj && storedAltContent) {
- obj.parentNode.replaceChild(storedAltContent, obj);
- if (storedAltContentId) {
- setVisibility(storedAltContentId, true);
- if (ua.ie && ua.win) { storedAltContent.style.display = "block"; }
- }
- if (storedCallbackFn) { storedCallbackFn(storedCallbackObj); }
- }
- isExpressInstallActive = false;
- }
- }
- };
-}();
+/*! SWFObject v2.2
+ is released under the MIT License
+*/
+
+var swfobject = function() {
+
+ var UNDEF = "undefined",
+ OBJECT = "object",
+ SHOCKWAVE_FLASH = "Shockwave Flash",
+ SHOCKWAVE_FLASH_AX = "ShockwaveFlash.ShockwaveFlash",
+ FLASH_MIME_TYPE = "application/x-shockwave-flash",
+ EXPRESS_INSTALL_ID = "SWFObjectExprInst",
+ ON_READY_STATE_CHANGE = "onreadystatechange",
+
+ win = window,
+ doc = document,
+ nav = navigator,
+
+ plugin = false,
+ domLoadFnArr = [main],
+ regObjArr = [],
+ objIdArr = [],
+ listenersArr = [],
+ storedAltContent,
+ storedAltContentId,
+ storedCallbackFn,
+ storedCallbackObj,
+ isDomLoaded = false,
+ isExpressInstallActive = false,
+ dynamicStylesheet,
+ dynamicStylesheetMedia,
+ autoHideShow = true,
+
+ /* Centralized function for browser feature detection
+ - User agent string detection is only used when no good alternative is possible
+ - Is executed directly for optimal performance
+ */
+ ua = function() {
+ var w3cdom = typeof doc.getElementById != UNDEF && typeof doc.getElementsByTagName != UNDEF && typeof doc.createElement != UNDEF,
+ u = nav.userAgent.toLowerCase(),
+ p = nav.platform.toLowerCase(),
+ windows = p ? /win/.test(p) : /win/.test(u),
+ mac = p ? /mac/.test(p) : /mac/.test(u),
+ webkit = /webkit/.test(u) ? parseFloat(u.replace(/^.*webkit\/(\d+(\.\d+)?).*$/, "$1")) : false, // returns either the webkit version or false if not webkit
+ ie = !+"\v1", // feature detection based on Andrea Giammarchi's solution: http://webreflection.blogspot.com/2009/01/32-bytes-to-know-if-your-browser-is-ie.html
+ playerVersion = [0,0,0],
+ d = null;
+ if (typeof nav.plugins != UNDEF && typeof nav.plugins[SHOCKWAVE_FLASH] == OBJECT) {
+ d = nav.plugins[SHOCKWAVE_FLASH].description;
+ if (d && !(typeof nav.mimeTypes != UNDEF && nav.mimeTypes[FLASH_MIME_TYPE] && !nav.mimeTypes[FLASH_MIME_TYPE].enabledPlugin)) { // navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin indicates whether plug-ins are enabled or disabled in Safari 3+
+ plugin = true;
+ ie = false; // cascaded feature detection for Internet Explorer
+ d = d.replace(/^.*\s+(\S+\s+\S+$)/, "$1");
+ playerVersion[0] = parseInt(d.replace(/^(.*)\..*$/, "$1"), 10);
+ playerVersion[1] = parseInt(d.replace(/^.*\.(.*)\s.*$/, "$1"), 10);
+ playerVersion[2] = /[a-zA-Z]/.test(d) ? parseInt(d.replace(/^.*[a-zA-Z]+(.*)$/, "$1"), 10) : 0;
+ }
+ }
+ else if (typeof win.ActiveXObject != UNDEF) {
+ try {
+ var a = new ActiveXObject(SHOCKWAVE_FLASH_AX);
+ if (a) { // a will return null when ActiveX is disabled
+ d = a.GetVariable("$version");
+ if (d) {
+ ie = true; // cascaded feature detection for Internet Explorer
+ d = d.split(" ")[1].split(",");
+ playerVersion = [parseInt(d[0], 10), parseInt(d[1], 10), parseInt(d[2], 10)];
+ }
+ }
+ }
+ catch(e) {}
+ }
+ return { w3:w3cdom, pv:playerVersion, wk:webkit, ie:ie, win:windows, mac:mac };
+ }(),
+
+ /* Cross-browser onDomLoad
+ - Will fire an event as soon as the DOM of a web page is loaded
+ - Internet Explorer workaround based on Diego Perini's solution: http://javascript.nwbox.com/IEContentLoaded/
+ - Regular onload serves as fallback
+ */
+ onDomLoad = function() {
+ if (!ua.w3) { return; }
+ if ((typeof doc.readyState != UNDEF && doc.readyState == "complete") || (typeof doc.readyState == UNDEF && (doc.getElementsByTagName("body")[0] || doc.body))) { // function is fired after onload, e.g. when script is inserted dynamically
+ callDomLoadFunctions();
+ }
+ if (!isDomLoaded) {
+ if (typeof doc.addEventListener != UNDEF) {
+ doc.addEventListener("DOMContentLoaded", callDomLoadFunctions, false);
+ }
+ if (ua.ie && ua.win) {
+ doc.attachEvent(ON_READY_STATE_CHANGE, function() {
+ if (doc.readyState == "complete") {
+ doc.detachEvent(ON_READY_STATE_CHANGE, arguments.callee);
+ callDomLoadFunctions();
+ }
+ });
+ if (win == top) { // if not inside an iframe
+ (function(){
+ if (isDomLoaded) { return; }
+ try {
+ doc.documentElement.doScroll("left");
+ }
+ catch(e) {
+ setTimeout(arguments.callee, 0);
+ return;
+ }
+ callDomLoadFunctions();
+ })();
+ }
+ }
+ if (ua.wk) {
+ (function(){
+ if (isDomLoaded) { return; }
+ if (!/loaded|complete/.test(doc.readyState)) {
+ setTimeout(arguments.callee, 0);
+ return;
+ }
+ callDomLoadFunctions();
+ })();
+ }
+ addLoadEvent(callDomLoadFunctions);
+ }
+ }();
+
+ function callDomLoadFunctions() {
+ if (isDomLoaded) { return; }
+ try { // test if we can really add/remove elements to/from the DOM; we don't want to fire it too early
+ var t = doc.getElementsByTagName("body")[0].appendChild(createElement("span"));
+ t.parentNode.removeChild(t);
+ }
+ catch (e) { return; }
+ isDomLoaded = true;
+ var dl = domLoadFnArr.length;
+ for (var i = 0; i < dl; i++) {
+ domLoadFnArr[i]();
+ }
+ }
+
+ function addDomLoadEvent(fn) {
+ if (isDomLoaded) {
+ fn();
+ }
+ else {
+ domLoadFnArr[domLoadFnArr.length] = fn; // Array.push() is only available in IE5.5+
+ }
+ }
+
+ /* Cross-browser onload
+ - Based on James Edwards' solution: http://brothercake.com/site/resources/scripts/onload/
+ - Will fire an event as soon as a web page including all of its assets are loaded
+ */
+ function addLoadEvent(fn) {
+ if (typeof win.addEventListener != UNDEF) {
+ win.addEventListener("load", fn, false);
+ }
+ else if (typeof doc.addEventListener != UNDEF) {
+ doc.addEventListener("load", fn, false);
+ }
+ else if (typeof win.attachEvent != UNDEF) {
+ addListener(win, "onload", fn);
+ }
+ else if (typeof win.onload == "function") {
+ var fnOld = win.onload;
+ win.onload = function() {
+ fnOld();
+ fn();
+ };
+ }
+ else {
+ win.onload = fn;
+ }
+ }
+
+ /* Main function
+ - Will preferably execute onDomLoad, otherwise onload (as a fallback)
+ */
+ function main() {
+ if (plugin) {
+ testPlayerVersion();
+ }
+ else {
+ matchVersions();
+ }
+ }
+
+ /* Detect the Flash Player version for non-Internet Explorer browsers
+ - Detecting the plug-in version via the object element is more precise than using the plugins collection item's description:
+ a. Both release and build numbers can be detected
+ b. Avoid wrong descriptions by corrupt installers provided by Adobe
+ c. Avoid wrong descriptions by multiple Flash Player entries in the plugin Array, caused by incorrect browser imports
+ - Disadvantage of this method is that it depends on the availability of the DOM, while the plugins collection is immediately available
+ */
+ function testPlayerVersion() {
+ var b = doc.getElementsByTagName("body")[0];
+ var o = createElement(OBJECT);
+ o.setAttribute("type", FLASH_MIME_TYPE);
+ var t = b.appendChild(o);
+ if (t) {
+ var counter = 0;
+ (function(){
+ if (typeof t.GetVariable != UNDEF) {
+ var d = t.GetVariable("$version");
+ if (d) {
+ d = d.split(" ")[1].split(",");
+ ua.pv = [parseInt(d[0], 10), parseInt(d[1], 10), parseInt(d[2], 10)];
+ }
+ }
+ else if (counter < 10) {
+ counter++;
+ setTimeout(arguments.callee, 10);
+ return;
+ }
+ b.removeChild(o);
+ t = null;
+ matchVersions();
+ })();
+ }
+ else {
+ matchVersions();
+ }
+ }
+
+ /* Perform Flash Player and SWF version matching; static publishing only
+ */
+ function matchVersions() {
+ var rl = regObjArr.length;
+ if (rl > 0) {
+ for (var i = 0; i < rl; i++) { // for each registered object element
+ var id = regObjArr[i].id;
+ var cb = regObjArr[i].callbackFn;
+ var cbObj = {success:false, id:id};
+ if (ua.pv[0] > 0) {
+ var obj = getElementById(id);
+ if (obj) {
+ if (hasPlayerVersion(regObjArr[i].swfVersion) && !(ua.wk && ua.wk < 312)) { // Flash Player version >= published SWF version: Houston, we have a match!
+ setVisibility(id, true);
+ if (cb) {
+ cbObj.success = true;
+ cbObj.ref = getObjectById(id);
+ cb(cbObj);
+ }
+ }
+ else if (regObjArr[i].expressInstall && canExpressInstall()) { // show the Adobe Express Install dialog if set by the web page author and if supported
+ var att = {};
+ att.data = regObjArr[i].expressInstall;
+ att.width = obj.getAttribute("width") || "0";
+ att.height = obj.getAttribute("height") || "0";
+ if (obj.getAttribute("class")) { att.styleclass = obj.getAttribute("class"); }
+ if (obj.getAttribute("align")) { att.align = obj.getAttribute("align"); }
+ // parse HTML object param element's name-value pairs
+ var par = {};
+ var p = obj.getElementsByTagName("param");
+ var pl = p.length;
+ for (var j = 0; j < pl; j++) {
+ if (p[j].getAttribute("name").toLowerCase() != "movie") {
+ par[p[j].getAttribute("name")] = p[j].getAttribute("value");
+ }
+ }
+ showExpressInstall(att, par, id, cb);
+ }
+ else { // Flash Player and SWF version mismatch or an older Webkit engine that ignores the HTML object element's nested param elements: display alternative content instead of SWF
+ displayAltContent(obj);
+ if (cb) { cb(cbObj); }
+ }
+ }
+ }
+ else { // if no Flash Player is installed or the fp version cannot be detected we let the HTML object element do its job (either show a SWF or alternative content)
+ setVisibility(id, true);
+ if (cb) {
+ var o = getObjectById(id); // test whether there is an HTML object element or not
+ if (o && typeof o.SetVariable != UNDEF) {
+ cbObj.success = true;
+ cbObj.ref = o;
+ }
+ cb(cbObj);
+ }
+ }
+ }
+ }
+ }
+
+ function getObjectById(objectIdStr) {
+ var r = null;
+ var o = getElementById(objectIdStr);
+ if (o && o.nodeName == "OBJECT") {
+ if (typeof o.SetVariable != UNDEF) {
+ r = o;
+ }
+ else {
+ var n = o.getElementsByTagName(OBJECT)[0];
+ if (n) {
+ r = n;
+ }
+ }
+ }
+ return r;
+ }
+
+ /* Requirements for Adobe Express Install
+ - only one instance can be active at a time
+ - fp 6.0.65 or higher
+ - Win/Mac OS only
+ - no Webkit engines older than version 312
+ */
+ function canExpressInstall() {
+ return !isExpressInstallActive && hasPlayerVersion("6.0.65") && (ua.win || ua.mac) && !(ua.wk && ua.wk < 312);
+ }
+
+ /* Show the Adobe Express Install dialog
+ - Reference: http://www.adobe.com/cfusion/knowledgebase/index.cfm?id=6a253b75
+ */
+ function showExpressInstall(att, par, replaceElemIdStr, callbackFn) {
+ isExpressInstallActive = true;
+ storedCallbackFn = callbackFn || null;
+ storedCallbackObj = {success:false, id:replaceElemIdStr};
+ var obj = getElementById(replaceElemIdStr);
+ if (obj) {
+ if (obj.nodeName == "OBJECT") { // static publishing
+ storedAltContent = abstractAltContent(obj);
+ storedAltContentId = null;
+ }
+ else { // dynamic publishing
+ storedAltContent = obj;
+ storedAltContentId = replaceElemIdStr;
+ }
+ att.id = EXPRESS_INSTALL_ID;
+ if (typeof att.width == UNDEF || (!/%$/.test(att.width) && parseInt(att.width, 10) < 310)) { att.width = "310"; }
+ if (typeof att.height == UNDEF || (!/%$/.test(att.height) && parseInt(att.height, 10) < 137)) { att.height = "137"; }
+ doc.title = doc.title.slice(0, 47) + " - Flash Player Installation";
+ var pt = ua.ie && ua.win ? "ActiveX" : "PlugIn",
+ fv = "MMredirectURL=" + encodeURI(window.location).toString().replace(/&/g,"%26") + "&MMplayerType=" + pt + "&MMdoctitle=" + doc.title;
+ if (typeof par.flashvars != UNDEF) {
+ par.flashvars += "&" + fv;
+ }
+ else {
+ par.flashvars = fv;
+ }
+ // IE only: when a SWF is loading (AND: not available in cache) wait for the readyState of the object element to become 4 before removing it,
+ // because you cannot properly cancel a loading SWF file without breaking browser load references, also obj.onreadystatechange doesn't work
+ if (ua.ie && ua.win && obj.readyState != 4) {
+ var newObj = createElement("div");
+ replaceElemIdStr += "SWFObjectNew";
+ newObj.setAttribute("id", replaceElemIdStr);
+ obj.parentNode.insertBefore(newObj, obj); // insert placeholder div that will be replaced by the object element that loads expressinstall.swf
+ obj.style.display = "none";
+ (function(){
+ if (obj.readyState == 4) {
+ obj.parentNode.removeChild(obj);
+ }
+ else {
+ setTimeout(arguments.callee, 10);
+ }
+ })();
+ }
+ createSWF(att, par, replaceElemIdStr);
+ }
+ }
+
+ /* Functions to abstract and display alternative content
+ */
+ function displayAltContent(obj) {
+ if (ua.ie && ua.win && obj.readyState != 4) {
+ // IE only: when a SWF is loading (AND: not available in cache) wait for the readyState of the object element to become 4 before removing it,
+ // because you cannot properly cancel a loading SWF file without breaking browser load references, also obj.onreadystatechange doesn't work
+ var el = createElement("div");
+ obj.parentNode.insertBefore(el, obj); // insert placeholder div that will be replaced by the alternative content
+ el.parentNode.replaceChild(abstractAltContent(obj), el);
+ obj.style.display = "none";
+ (function(){
+ if (obj.readyState == 4) {
+ obj.parentNode.removeChild(obj);
+ }
+ else {
+ setTimeout(arguments.callee, 10);
+ }
+ })();
+ }
+ else {
+ obj.parentNode.replaceChild(abstractAltContent(obj), obj);
+ }
+ }
+
+ function abstractAltContent(obj) {
+ var ac = createElement("div");
+ if (ua.win && ua.ie) {
+ ac.innerHTML = obj.innerHTML;
+ }
+ else {
+ var nestedObj = obj.getElementsByTagName(OBJECT)[0];
+ if (nestedObj) {
+ var c = nestedObj.childNodes;
+ if (c) {
+ var cl = c.length;
+ for (var i = 0; i < cl; i++) {
+ if (!(c[i].nodeType == 1 && c[i].nodeName == "PARAM") && !(c[i].nodeType == 8)) {
+ ac.appendChild(c[i].cloneNode(true));
+ }
+ }
+ }
+ }
+ }
+ return ac;
+ }
+
+ /* Cross-browser dynamic SWF creation
+ */
+ function createSWF(attObj, parObj, id) {
+ var r, el = getElementById(id);
+ if (ua.wk && ua.wk < 312) { return r; }
+ if (el) {
+ if (typeof attObj.id == UNDEF) { // if no 'id' is defined for the object element, it will inherit the 'id' from the alternative content
+ attObj.id = id;
+ }
+ if (ua.ie && ua.win) { // Internet Explorer + the HTML object element + W3C DOM methods do not combine: fall back to outerHTML
+ var att = "";
+ for (var i in attObj) {
+ if (attObj[i] != Object.prototype[i]) { // filter out prototype additions from other potential libraries
+ if (i.toLowerCase() == "data") {
+ parObj.movie = attObj[i];
+ }
+ else if (i.toLowerCase() == "styleclass") { // 'class' is an ECMA4 reserved keyword
+ att += ' class="' + attObj[i] + '"';
+ }
+ else if (i.toLowerCase() != "classid") {
+ att += ' ' + i + '="' + attObj[i] + '"';
+ }
+ }
+ }
+ var par = "";
+ for (var j in parObj) {
+ if (parObj[j] != Object.prototype[j]) { // filter out prototype additions from other potential libraries
+ par += '';
+ }
+ }
+ el.outerHTML = '';
+ objIdArr[objIdArr.length] = attObj.id; // stored to fix object 'leaks' on unload (dynamic publishing only)
+ r = getElementById(attObj.id);
+ }
+ else { // well-behaving browsers
+ var o = createElement(OBJECT);
+ o.setAttribute("type", FLASH_MIME_TYPE);
+ for (var m in attObj) {
+ if (attObj[m] != Object.prototype[m]) { // filter out prototype additions from other potential libraries
+ if (m.toLowerCase() == "styleclass") { // 'class' is an ECMA4 reserved keyword
+ o.setAttribute("class", attObj[m]);
+ }
+ else if (m.toLowerCase() != "classid") { // filter out IE specific attribute
+ o.setAttribute(m, attObj[m]);
+ }
+ }
+ }
+ for (var n in parObj) {
+ if (parObj[n] != Object.prototype[n] && n.toLowerCase() != "movie") { // filter out prototype additions from other potential libraries and IE specific param element
+ createObjParam(o, n, parObj[n]);
+ }
+ }
+ el.parentNode.replaceChild(o, el);
+ r = o;
+ }
+ }
+ return r;
+ }
+
+ function createObjParam(el, pName, pValue) {
+ var p = createElement("param");
+ p.setAttribute("name", pName);
+ p.setAttribute("value", pValue);
+ el.appendChild(p);
+ }
+
+ /* Cross-browser SWF removal
+ - Especially needed to safely and completely remove a SWF in Internet Explorer
+ */
+ function removeSWF(id) {
+ var obj = getElementById(id);
+ if (obj && obj.nodeName == "OBJECT") {
+ if (ua.ie && ua.win) {
+ obj.style.display = "none";
+ (function(){
+ if (obj.readyState == 4) {
+ removeObjectInIE(id);
+ }
+ else {
+ setTimeout(arguments.callee, 10);
+ }
+ })();
+ }
+ else {
+ obj.parentNode.removeChild(obj);
+ }
+ }
+ }
+
+ function removeObjectInIE(id) {
+ var obj = getElementById(id);
+ if (obj) {
+ for (var i in obj) {
+ if (typeof obj[i] == "function") {
+ obj[i] = null;
+ }
+ }
+ obj.parentNode.removeChild(obj);
+ }
+ }
+
+ /* Functions to optimize JavaScript compression
+ */
+ function getElementById(id) {
+ var el = null;
+ try {
+ el = doc.getElementById(id);
+ }
+ catch (e) {}
+ return el;
+ }
+
+ function createElement(el) {
+ return doc.createElement(el);
+ }
+
+ /* Updated attachEvent function for Internet Explorer
+ - Stores attachEvent information in an Array, so on unload the detachEvent functions can be called to avoid memory leaks
+ */
+ function addListener(target, eventType, fn) {
+ target.attachEvent(eventType, fn);
+ listenersArr[listenersArr.length] = [target, eventType, fn];
+ }
+
+ /* Flash Player and SWF content version matching
+ */
+ function hasPlayerVersion(rv) {
+ var pv = ua.pv, v = rv.split(".");
+ v[0] = parseInt(v[0], 10);
+ v[1] = parseInt(v[1], 10) || 0; // supports short notation, e.g. "9" instead of "9.0.0"
+ v[2] = parseInt(v[2], 10) || 0;
+ return (pv[0] > v[0] || (pv[0] == v[0] && pv[1] > v[1]) || (pv[0] == v[0] && pv[1] == v[1] && pv[2] >= v[2])) ? true : false;
+ }
+
+ /* Cross-browser dynamic CSS creation
+ - Based on Bobby van der Sluis' solution: http://www.bobbyvandersluis.com/articles/dynamicCSS.php
+ */
+ function createCSS(sel, decl, media, newStyle) {
+ if (ua.ie && ua.mac) { return; }
+ var h = doc.getElementsByTagName("head")[0];
+ if (!h) { return; } // to also support badly authored HTML pages that lack a head element
+ var m = (media && typeof media == "string") ? media : "screen";
+ if (newStyle) {
+ dynamicStylesheet = null;
+ dynamicStylesheetMedia = null;
+ }
+ if (!dynamicStylesheet || dynamicStylesheetMedia != m) {
+ // create dynamic stylesheet + get a global reference to it
+ var s = createElement("style");
+ s.setAttribute("type", "text/css");
+ s.setAttribute("media", m);
+ dynamicStylesheet = h.appendChild(s);
+ if (ua.ie && ua.win && typeof doc.styleSheets != UNDEF && doc.styleSheets.length > 0) {
+ dynamicStylesheet = doc.styleSheets[doc.styleSheets.length - 1];
+ }
+ dynamicStylesheetMedia = m;
+ }
+ // add style rule
+ if (ua.ie && ua.win) {
+ if (dynamicStylesheet && typeof dynamicStylesheet.addRule == OBJECT) {
+ dynamicStylesheet.addRule(sel, decl);
+ }
+ }
+ else {
+ if (dynamicStylesheet && typeof doc.createTextNode != UNDEF) {
+ dynamicStylesheet.appendChild(doc.createTextNode(sel + " {" + decl + "}"));
+ }
+ }
+ }
+
+ function setVisibility(id, isVisible) {
+ if (!autoHideShow) { return; }
+ var v = isVisible ? "visible" : "hidden";
+ if (isDomLoaded && getElementById(id)) {
+ getElementById(id).style.visibility = v;
+ }
+ else {
+ createCSS("#" + id, "visibility:" + v);
+ }
+ }
+
+ /* Filter to avoid XSS attacks
+ */
+ function urlEncodeIfNecessary(s) {
+ var regex = /[\\\"<>\.;]/;
+ var hasBadChars = regex.exec(s) != null;
+ return hasBadChars && typeof encodeURIComponent != UNDEF ? encodeURIComponent(s) : s;
+ }
+
+ /* Release memory to avoid memory leaks caused by closures, fix hanging audio/video threads and force open sockets/NetConnections to disconnect (Internet Explorer only)
+ */
+ var cleanup = function() {
+ if (ua.ie && ua.win) {
+ window.attachEvent("onunload", function() {
+ // remove listeners to avoid memory leaks
+ var ll = listenersArr.length;
+ for (var i = 0; i < ll; i++) {
+ listenersArr[i][0].detachEvent(listenersArr[i][1], listenersArr[i][2]);
+ }
+ // cleanup dynamically embedded objects to fix audio/video threads and force open sockets and NetConnections to disconnect
+ var il = objIdArr.length;
+ for (var j = 0; j < il; j++) {
+ removeSWF(objIdArr[j]);
+ }
+ // cleanup library's main closures to avoid memory leaks
+ for (var k in ua) {
+ ua[k] = null;
+ }
+ ua = null;
+ for (var l in swfobject) {
+ swfobject[l] = null;
+ }
+ swfobject = null;
+ });
+ }
+ }();
+
+ return {
+ /* Public API
+ - Reference: http://code.google.com/p/swfobject/wiki/documentation
+ */
+ registerObject: function(objectIdStr, swfVersionStr, xiSwfUrlStr, callbackFn) {
+ if (ua.w3 && objectIdStr && swfVersionStr) {
+ var regObj = {};
+ regObj.id = objectIdStr;
+ regObj.swfVersion = swfVersionStr;
+ regObj.expressInstall = xiSwfUrlStr;
+ regObj.callbackFn = callbackFn;
+ regObjArr[regObjArr.length] = regObj;
+ setVisibility(objectIdStr, false);
+ }
+ else if (callbackFn) {
+ callbackFn({success:false, id:objectIdStr});
+ }
+ },
+
+ getObjectById: function(objectIdStr) {
+ if (ua.w3) {
+ return getObjectById(objectIdStr);
+ }
+ },
+
+ embedSWF: function(swfUrlStr, replaceElemIdStr, widthStr, heightStr, swfVersionStr, xiSwfUrlStr, flashvarsObj, parObj, attObj, callbackFn) {
+ var callbackObj = {success:false, id:replaceElemIdStr};
+ if (ua.w3 && !(ua.wk && ua.wk < 312) && swfUrlStr && replaceElemIdStr && widthStr && heightStr && swfVersionStr) {
+ setVisibility(replaceElemIdStr, false);
+ addDomLoadEvent(function() {
+ widthStr += ""; // auto-convert to string
+ heightStr += "";
+ var att = {};
+ if (attObj && typeof attObj === OBJECT) {
+ for (var i in attObj) { // copy object to avoid the use of references, because web authors often reuse attObj for multiple SWFs
+ att[i] = attObj[i];
+ }
+ }
+ att.data = swfUrlStr;
+ att.width = widthStr;
+ att.height = heightStr;
+ var par = {};
+ if (parObj && typeof parObj === OBJECT) {
+ for (var j in parObj) { // copy object to avoid the use of references, because web authors often reuse parObj for multiple SWFs
+ par[j] = parObj[j];
+ }
+ }
+ if (flashvarsObj && typeof flashvarsObj === OBJECT) {
+ for (var k in flashvarsObj) { // copy object to avoid the use of references, because web authors often reuse flashvarsObj for multiple SWFs
+ if (typeof par.flashvars != UNDEF) {
+ par.flashvars += "&" + k + "=" + flashvarsObj[k];
+ }
+ else {
+ par.flashvars = k + "=" + flashvarsObj[k];
+ }
+ }
+ }
+ if (hasPlayerVersion(swfVersionStr)) { // create SWF
+ var obj = createSWF(att, par, replaceElemIdStr);
+ if (att.id == replaceElemIdStr) {
+ setVisibility(replaceElemIdStr, true);
+ }
+ callbackObj.success = true;
+ callbackObj.ref = obj;
+ }
+ else if (xiSwfUrlStr && canExpressInstall()) { // show Adobe Express Install
+ att.data = xiSwfUrlStr;
+ showExpressInstall(att, par, replaceElemIdStr, callbackFn);
+ return;
+ }
+ else { // show alternative content
+ setVisibility(replaceElemIdStr, true);
+ }
+ if (callbackFn) { callbackFn(callbackObj); }
+ });
+ }
+ else if (callbackFn) { callbackFn(callbackObj); }
+ },
+
+ switchOffAutoHideShow: function() {
+ autoHideShow = false;
+ },
+
+ ua: ua,
+
+ getFlashPlayerVersion: function() {
+ return { major:ua.pv[0], minor:ua.pv[1], release:ua.pv[2] };
+ },
+
+ hasFlashPlayerVersion: hasPlayerVersion,
+
+ createSWF: function(attObj, parObj, replaceElemIdStr) {
+ if (ua.w3) {
+ return createSWF(attObj, parObj, replaceElemIdStr);
+ }
+ else {
+ return undefined;
+ }
+ },
+
+ showExpressInstall: function(att, par, replaceElemIdStr, callbackFn) {
+ if (ua.w3 && canExpressInstall()) {
+ showExpressInstall(att, par, replaceElemIdStr, callbackFn);
+ }
+ },
+
+ removeSWF: function(objElemIdStr) {
+ if (ua.w3) {
+ removeSWF(objElemIdStr);
+ }
+ },
+
+ createCSS: function(selStr, declStr, mediaStr, newStyleBoolean) {
+ if (ua.w3) {
+ createCSS(selStr, declStr, mediaStr, newStyleBoolean);
+ }
+ },
+
+ addDomLoadEvent: addDomLoadEvent,
+
+ addLoadEvent: addLoadEvent,
+
+ getQueryParamValue: function(param) {
+ var q = doc.location.search || doc.location.hash;
+ if (q) {
+ if (/\?/.test(q)) { q = q.split("?")[1]; } // strip question mark
+ if (param == null) {
+ return urlEncodeIfNecessary(q);
+ }
+ var pairs = q.split("&");
+ for (var i = 0; i < pairs.length; i++) {
+ if (pairs[i].substring(0, pairs[i].indexOf("=")) == param) {
+ return urlEncodeIfNecessary(pairs[i].substring((pairs[i].indexOf("=") + 1)));
+ }
+ }
+ }
+ return "";
+ },
+
+ // For internal usage only
+ expressInstallCallback: function() {
+ if (isExpressInstallActive) {
+ var obj = getElementById(EXPRESS_INSTALL_ID);
+ if (obj && storedAltContent) {
+ obj.parentNode.replaceChild(storedAltContent, obj);
+ if (storedAltContentId) {
+ setVisibility(storedAltContentId, true);
+ if (ua.ie && ua.win) { storedAltContent.style.display = "block"; }
+ }
+ if (storedCallbackFn) { storedCallbackFn(storedCallbackObj); }
+ }
+ isExpressInstallActive = false;
+ }
+ }
+ };
+}();
diff --git a/lib/osmf/framework/OSMFTest/src/FlexUnitApplication-app.xml b/lib/osmf/framework/OSMFTest/src/FlexUnitApplication-app.xml
deleted file mode 100644
index cc3fe6b..0000000
--- a/lib/osmf/framework/OSMFTest/src/FlexUnitApplication-app.xml
+++ /dev/null
@@ -1,220 +0,0 @@
-
-
-
-
-
-
- FlexUnitApplication
-
-
- FlexUnitApplication
-
-
- FlexUnitApplication
-
-
- 0.0.0
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- [This value will be overwritten by Flash Builder in the output app.xml]
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- false
- false
- false
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/lib/osmf/framework/OSMFTest/src/FlexUnitApplication.mxml b/lib/osmf/framework/OSMFTest/src/FlexUnitApplication.mxml
deleted file mode 100644
index 553bde9..0000000
--- a/lib/osmf/framework/OSMFTest/src/FlexUnitApplication.mxml
+++ /dev/null
@@ -1,192 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/lib/osmf/framework/OSMFTest/src/OSMFTest-app.xml b/lib/osmf/framework/OSMFTest/src/OSMFTest-app.xml
deleted file mode 100644
index e230b4a..0000000
--- a/lib/osmf/framework/OSMFTest/src/OSMFTest-app.xml
+++ /dev/null
@@ -1,220 +0,0 @@
-
-
-
-
-
-
- OSMFTest
-
-
- OSMFTest
-
-
- OSMFTest
-
-
- 0.0.0
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- [This value will be overwritten by Flash Builder in the output app.xml]
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- false
- false
- false
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/lib/osmf/framework/OSMFTest/src/OSMFTest.mxml b/lib/osmf/framework/OSMFTest/src/OSMFTest.mxml
index 016eebc..5f08fb6 100644
--- a/lib/osmf/framework/OSMFTest/src/OSMFTest.mxml
+++ b/lib/osmf/framework/OSMFTest/src/OSMFTest.mxml
@@ -2,184 +2,15 @@
-
+
@@ -201,4 +32,4 @@
-
+
diff --git a/lib/osmf/framework/OSMFTest/src/OSMFTests.as b/lib/osmf/framework/OSMFTest/src/OSMFTests.as
new file mode 100644
index 0000000..775123d
--- /dev/null
+++ b/lib/osmf/framework/OSMFTest/src/OSMFTests.as
@@ -0,0 +1,255 @@
+/*****************************************************
+*
+* Copyright 2010 Adobe Systems Incorporated. All Rights Reserved.
+*
+*****************************************************
+* The contents of this file are subject to the Mozilla Public License
+* Version 1.1 (the "License"); you may not use this file except in
+* compliance with the License. You may obtain a copy of the License at
+* http://www.mozilla.org/MPL/
+*
+* Software distributed under the License is distributed on an "AS IS"
+* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+* License for the specific language governing rights and limitations
+* under the License.
+*
+*
+* The Initial Developer of the Original Code is Adobe Systems Incorporated.
+* Portions created by Adobe Systems Incorporated are Copyright (C) 2010 Adobe Systems
+* Incorporated. All Rights Reserved.
+*
+*****************************************************/
+package
+{
+ import org.osmf.containers.TestHTMLMediaContainer;
+ import org.osmf.containers.TestMediaContainer;
+ import org.osmf.events.TestMediaError;
+ import org.osmf.events.TestMediaErrorAsSubclass;
+ import org.osmf.layout.TestAbsoluteLayoutMetadata;
+ import org.osmf.layout.TestAnchorLayoutMetadata;
+ import org.osmf.layout.TestBinarySearch;
+ import org.osmf.layout.TestBoxAttributesMetadata;
+ import org.osmf.layout.TestGenericLayout;
+ import org.osmf.layout.TestLayoutAttributesMetadata;
+ import org.osmf.layout.TestLayoutMetadata;
+ import org.osmf.layout.TestLayoutRenderer;
+ import org.osmf.layout.TestLayoutRendererBase;
+ import org.osmf.layout.TestLayoutTargetEvent;
+ import org.osmf.layout.TestLayoutTargetRenderers;
+ import org.osmf.layout.TestLayoutTargetSprite;
+ import org.osmf.layout.TestMediaElementLayoutTarget;
+ import org.osmf.layout.TestOverlayLayoutMetadata;
+ import org.osmf.layout.TestPaddingLayoutMetadata;
+ import org.osmf.layout.TestRelativeLayoutMetadata;
+ import org.osmf.layout.TestScaleModeUtils;
+ import org.osmf.logging.TestLog;
+ import org.osmf.media.MediaTraitResolverBaseTestCase;
+ import org.osmf.media.TestDefaultMediaFactory;
+ import org.osmf.media.TestDefaultTraitResolver;
+ import org.osmf.media.TestLoadableElementBase;
+ import org.osmf.media.TestMediaElement;
+ import org.osmf.media.TestMediaElementAsSubclass;
+ import org.osmf.media.TestMediaFactory;
+ import org.osmf.media.TestMediaFactoryItem;
+ import org.osmf.media.TestMediaPlayer;
+ import org.osmf.media.TestMediaPlayerSprite;
+ import org.osmf.media.TestMediaPlayerWithAudioElement;
+ import org.osmf.media.TestMediaPlayerWithAudioElementWithSoundLoader;
+ import org.osmf.media.TestMediaPlayerWithBeaconElement;
+ import org.osmf.media.TestMediaPlayerWithDurationElement;
+ import org.osmf.media.TestMediaPlayerWithDynamicStreamingVideoElement;
+ import org.osmf.media.TestMediaPlayerWithDynamicStreamingVideoElementSubclip;
+ import org.osmf.media.TestMediaPlayerWithLightweightVideoElement;
+ import org.osmf.media.TestMediaPlayerWithProxyElement;
+ import org.osmf.media.TestMediaPlayerWithSerialElementWithDurationElements;
+ import org.osmf.media.TestMediaPlayerWithVideoElement;
+ import org.osmf.media.TestMediaPlayerWithVideoElementSubclip;
+ import org.osmf.media.TestMediaTraitResolver;
+ import org.osmf.media.TestMediaType;
+ import org.osmf.media.TestMediaTypeUtil;
+ import org.osmf.media.TestPluginInfo;
+ import org.osmf.media.TestURLResource;
+ import org.osmf.media.pluginClasses.TestDynamicPluginLoader;
+ import org.osmf.media.pluginClasses.TestPluginElement;
+ import org.osmf.media.pluginClasses.TestPluginLoadingState;
+ import org.osmf.media.pluginClasses.TestPluginManager;
+ import org.osmf.media.pluginClasses.TestStaticPluginLoader;
+ import org.osmf.metadata.TestCuePoint;
+ import org.osmf.metadata.TestMetadata;
+ import org.osmf.metadata.TestMetadataWatcher;
+ import org.osmf.metadata.TestTimelineMarker;
+ import org.osmf.metadata.TestTimelineMetadata;
+ import org.osmf.net.TestDynamicStreamingItem;
+ import org.osmf.net.TestDynamicStreamingResource;
+ import org.osmf.net.TestSwitchManager;
+ import org.osmf.net.drm.TestDRMServices;
+ import org.osmf.net.metrics.TestActualBitrateMetric;
+ import org.osmf.net.metrics.TestAvailableQualityLevelsMetric;
+ import org.osmf.net.metrics.TestBandwidthMetric;
+ import org.osmf.net.metrics.TestBufferFragmentsMetric;
+ import org.osmf.net.metrics.TestBufferLengthMetric;
+ import org.osmf.net.metrics.TestBufferOccupationRatioMetric;
+ import org.osmf.net.metrics.TestCurrentStatusMetric;
+ import org.osmf.net.metrics.TestDefaultMetricFactory;
+ import org.osmf.net.metrics.TestDroppedFPSMetric;
+ import org.osmf.net.metrics.TestEmptyBufferInterruptionMetric;
+ import org.osmf.net.metrics.TestFPSMetric;
+ import org.osmf.net.metrics.TestFragmentCountMetric;
+ import org.osmf.net.metrics.TestMetricBase;
+ import org.osmf.net.metrics.TestMetricFactory;
+ import org.osmf.net.metrics.TestMetricFactoryItem;
+ import org.osmf.net.metrics.TestMetricRepository;
+ import org.osmf.net.metrics.TestMetricValue;
+ import org.osmf.net.metrics.TestRecentSwitchMetric;
+ import org.osmf.net.qos.TestQoSInfoHistory;
+ import org.osmf.net.rules.TestAfterUpSwitchBufferBandwidthRule;
+ import org.osmf.net.rules.TestBandwidthRule;
+ import org.osmf.net.rules.TestBufferBandwidthRule;
+ import org.osmf.net.rules.TestDroppedFPSRule;
+ import org.osmf.net.rules.TestEmptyBufferRule;
+ import org.osmf.net.rules.TestRecommendation;
+ import org.osmf.net.rules.TestRuleUtils;
+ import org.osmf.traits.TestAudioTrait;
+ import org.osmf.traits.TestBufferTrait;
+ import org.osmf.traits.TestBufferTraitAsSubclass;
+ import org.osmf.traits.TestDRMTrait;
+ import org.osmf.traits.TestDVRTrait;
+ import org.osmf.traits.TestDisplayObjectTrait;
+ import org.osmf.traits.TestDisplayObjectTraitAsSubclass;
+ import org.osmf.traits.TestDynamicStreamTrait;
+ import org.osmf.traits.TestLoadTrait;
+ import org.osmf.traits.TestLoadTraitAsSubclass;
+ import org.osmf.traits.TestLoaderBase;
+ import org.osmf.traits.TestPlayTrait;
+ import org.osmf.traits.TestPlayTraitAsSubclass;
+ import org.osmf.traits.TestSeekTrait;
+ import org.osmf.traits.TestTimeTrait;
+ import org.osmf.traits.TestTimeTraitAsSubclass;
+ import org.osmf.traits.TestTraitEventDispatcher;
+ import org.osmf.utils.OSMFUtilTestSettings;
+ import org.osmf.utils.OSMFUtilTestStrings;
+ import org.osmf.utils.OSMFUtilTestTime;
+ import org.osmf.utils.OSMFUtilTestURL;
+ import org.osmf.utils.TestURL;
+
+ public class OSMFTests
+ {
+ public static function currentRunTestSuite():Array
+ {
+ var testsToRun:Array = new Array();
+
+ testsToRun.push(org.osmf.containers.TestHTMLMediaContainer);
+ testsToRun.push(org.osmf.containers.TestMediaContainer);
+ testsToRun.push(org.osmf.events.TestMediaError);
+ testsToRun.push(org.osmf.events.TestMediaErrorAsSubclass);
+ testsToRun.push(org.osmf.layout.TestAbsoluteLayoutMetadata);
+ testsToRun.push(org.osmf.layout.TestAnchorLayoutMetadata);
+ testsToRun.push(org.osmf.layout.TestBinarySearch);
+ testsToRun.push(org.osmf.layout.TestBoxAttributesMetadata);
+ testsToRun.push(org.osmf.layout.TestGenericLayout);
+ testsToRun.push(org.osmf.layout.TestLayoutAttributesMetadata);
+ testsToRun.push(org.osmf.layout.TestLayoutMetadata);
+ testsToRun.push(org.osmf.layout.TestLayoutRenderer);
+ testsToRun.push(org.osmf.layout.TestLayoutRendererBase);
+ testsToRun.push(org.osmf.layout.TestLayoutTargetEvent);
+ testsToRun.push(org.osmf.layout.TestLayoutTargetRenderers);
+ testsToRun.push(org.osmf.layout.TestMediaElementLayoutTarget);
+ testsToRun.push(org.osmf.layout.TestLayoutTargetSprite);
+ testsToRun.push(org.osmf.layout.TestOverlayLayoutMetadata);
+ testsToRun.push(org.osmf.layout.TestPaddingLayoutMetadata);
+ testsToRun.push(org.osmf.layout.TestRelativeLayoutMetadata);
+ testsToRun.push(org.osmf.layout.TestScaleModeUtils);
+ testsToRun.push(org.osmf.logging.TestLog);
+ testsToRun.push(org.osmf.media.MediaTraitResolverBaseTestCase);
+ testsToRun.push(org.osmf.media.TestDefaultMediaFactory);
+ testsToRun.push(org.osmf.media.TestDefaultTraitResolver);
+ testsToRun.push(org.osmf.media.TestLoadableElementBase);
+ testsToRun.push(org.osmf.media.TestMediaElement);
+ testsToRun.push(org.osmf.media.TestMediaElementAsSubclass);
+ testsToRun.push(org.osmf.media.TestMediaFactory);
+ testsToRun.push(org.osmf.media.TestMediaFactoryItem);
+ testsToRun.push(org.osmf.media.TestMediaPlayer);
+ testsToRun.push(org.osmf.media.TestMediaPlayerSprite);
+ testsToRun.push(org.osmf.media.TestMediaPlayerWithAudioElement);
+ testsToRun.push(org.osmf.media.TestMediaPlayerWithAudioElementWithSoundLoader);
+ testsToRun.push(org.osmf.media.TestMediaPlayerWithBeaconElement);
+ testsToRun.push(org.osmf.media.TestMediaPlayerWithDurationElement);
+ testsToRun.push(org.osmf.media.TestMediaPlayerWithDynamicStreamingVideoElement);
+ testsToRun.push(org.osmf.media.TestMediaPlayerWithDynamicStreamingVideoElementSubclip);
+ testsToRun.push(org.osmf.media.TestMediaPlayerWithLightweightVideoElement);
+ testsToRun.push(org.osmf.media.TestMediaPlayerWithProxyElement);
+ testsToRun.push(org.osmf.media.TestMediaPlayerWithSerialElementWithDurationElements);
+ testsToRun.push(org.osmf.media.TestMediaPlayerWithVideoElement);
+ testsToRun.push(org.osmf.media.TestMediaPlayerWithVideoElementSubclip);
+ testsToRun.push(org.osmf.media.TestMediaTraitResolver);
+ testsToRun.push(org.osmf.media.TestMediaType);
+ testsToRun.push(org.osmf.media.TestMediaTypeUtil);
+ testsToRun.push(org.osmf.media.TestPluginInfo);
+ testsToRun.push(org.osmf.media.TestURLResource);
+ testsToRun.push(org.osmf.media.pluginClasses.TestDynamicPluginLoader);
+ testsToRun.push(org.osmf.media.pluginClasses.TestPluginElement);
+ testsToRun.push(org.osmf.media.pluginClasses.TestPluginLoadingState);
+ testsToRun.push(org.osmf.media.pluginClasses.TestPluginManager);
+ testsToRun.push(org.osmf.media.pluginClasses.TestStaticPluginLoader);
+ testsToRun.push(org.osmf.metadata.TestCuePoint);
+ testsToRun.push(org.osmf.metadata.TestMetadata);
+ testsToRun.push(org.osmf.metadata.TestMetadataWatcher);
+ testsToRun.push(org.osmf.metadata.TestTimelineMarker);
+ testsToRun.push(org.osmf.metadata.TestTimelineMetadata);
+ testsToRun.push(org.osmf.net.drm.TestDRMServices);
+ testsToRun.push(org.osmf.net.TestDynamicStreamingItem);
+ testsToRun.push(org.osmf.net.TestDynamicStreamingResource);
+ testsToRun.push(org.osmf.net.TestSwitchManager);
+ testsToRun.push(org.osmf.net.metrics.TestActualBitrateMetric);
+ testsToRun.push(org.osmf.net.metrics.TestAvailableQualityLevelsMetric);
+ testsToRun.push(org.osmf.net.metrics.TestBandwidthMetric);
+ testsToRun.push(org.osmf.net.metrics.TestBufferFragmentsMetric);
+ testsToRun.push(org.osmf.net.metrics.TestBufferLengthMetric);
+ testsToRun.push(org.osmf.net.metrics.TestBufferOccupationRatioMetric);
+ testsToRun.push(org.osmf.net.metrics.TestCurrentStatusMetric);
+ testsToRun.push(org.osmf.net.metrics.TestDefaultMetricFactory);
+ testsToRun.push(org.osmf.net.metrics.TestDroppedFPSMetric);
+ testsToRun.push(org.osmf.net.metrics.TestEmptyBufferInterruptionMetric);
+ testsToRun.push(org.osmf.net.metrics.TestFPSMetric);
+ testsToRun.push(org.osmf.net.metrics.TestFragmentCountMetric);
+ testsToRun.push(org.osmf.net.metrics.TestMetricBase);
+ testsToRun.push(org.osmf.net.metrics.TestMetricFactory);
+ testsToRun.push(org.osmf.net.metrics.TestMetricFactoryItem);
+ testsToRun.push(org.osmf.net.metrics.TestMetricRepository);
+ testsToRun.push(org.osmf.net.metrics.TestMetricValue);
+ testsToRun.push(org.osmf.net.metrics.TestRecentSwitchMetric);
+ testsToRun.push(org.osmf.net.qos.TestQoSInfoHistory);
+ testsToRun.push(org.osmf.net.rules.TestAfterUpSwitchBufferBandwidthRule);
+ testsToRun.push(org.osmf.net.rules.TestBandwidthRule);
+ testsToRun.push(org.osmf.net.rules.TestBufferBandwidthRule);
+ testsToRun.push(org.osmf.net.rules.TestDroppedFPSRule);
+ testsToRun.push(org.osmf.net.rules.TestEmptyBufferRule);
+ testsToRun.push(org.osmf.net.rules.TestRecommendation);
+ testsToRun.push(org.osmf.net.rules.TestRuleUtils);
+ testsToRun.push(org.osmf.traits.TestAudioTrait);
+ testsToRun.push(org.osmf.traits.TestBufferTrait);
+ testsToRun.push(org.osmf.traits.TestBufferTraitAsSubclass);
+ testsToRun.push(org.osmf.traits.TestDisplayObjectTrait);
+ testsToRun.push(org.osmf.traits.TestDisplayObjectTraitAsSubclass);
+ testsToRun.push(org.osmf.traits.TestDRMTrait);
+ testsToRun.push(org.osmf.traits.TestDVRTrait);
+ testsToRun.push(org.osmf.traits.TestDynamicStreamTrait);
+ testsToRun.push(org.osmf.traits.TestLoaderBase);
+ testsToRun.push(org.osmf.traits.TestLoadTrait);
+ testsToRun.push(org.osmf.traits.TestLoadTraitAsSubclass);
+ testsToRun.push(org.osmf.traits.TestPlayTrait);
+ testsToRun.push(org.osmf.traits.TestPlayTraitAsSubclass);
+ testsToRun.push(org.osmf.traits.TestSeekTrait);
+ testsToRun.push(org.osmf.traits.TestTimeTrait);
+ testsToRun.push(org.osmf.traits.TestTimeTraitAsSubclass);
+ testsToRun.push(org.osmf.traits.TestTraitEventDispatcher);
+ testsToRun.push(org.osmf.utils.OSMFUtilTestSettings);
+ testsToRun.push(org.osmf.utils.OSMFUtilTestStrings);
+ testsToRun.push(org.osmf.utils.OSMFUtilTestTime);
+ testsToRun.push(org.osmf.utils.OSMFUtilTestURL);
+ testsToRun.push(org.osmf.utils.TestURL);
+
+ return testsToRun;
+ }
+ }
+}
\ No newline at end of file
diff --git a/lib/osmf/framework/OSMFTest/src/org/osmf/containers/TestHTMLMediaContainer.as b/lib/osmf/framework/OSMFTest/src/org/osmf/containers/TestHTMLMediaContainer.as
index eb5ac84..1f77aaa 100644
--- a/lib/osmf/framework/OSMFTest/src/org/osmf/containers/TestHTMLMediaContainer.as
+++ b/lib/osmf/framework/OSMFTest/src/org/osmf/containers/TestHTMLMediaContainer.as
@@ -1,111 +1,97 @@
-/*****************************************************
-*
-* Copyright 2009 Adobe Systems Incorporated. All Rights Reserved.
-*
-*****************************************************
-* The contents of this file are subject to the Mozilla Public License
-* Version 1.1 (the "License"); you may not use this file except in
-* compliance with the License. You may obtain a copy of the License at
-* http://www.mozilla.org/MPL/
-*
-* Software distributed under the License is distributed on an "AS IS"
-* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
-* License for the specific language governing rights and limitations
-* under the License.
-*
-*
-* The Initial Developer of the Original Code is Adobe Systems Incorporated.
-* Portions created by Adobe Systems Incorporated are Copyright (C) 2009 Adobe Systems
-* Incorporated. All Rights Reserved.
-*
-*****************************************************/
-package org.osmf.containers
-{
- import flash.external.ExternalInterface;
-
- import org.flexunit.Assert;
- import org.osmf.elements.HTMLElement;
- import org.osmf.elements.ProxyElement;
- import org.osmf.media.MediaElement;
-
- public class TestHTMLMediaContainer
- {
- [Test(expects="flash.errors.IllegalOperationError")]
- public function testAddMediaElementNull():void
- {
- var container:HTMLMediaContainer = new HTMLMediaContainer("test");
- container.addMediaElement(null);
- }
-
- [Test(expects="flash.errors.IllegalOperationError")]
- public function testAddMediaElementEmptyMediaElement():void
- {
- var container:HTMLMediaContainer = new HTMLMediaContainer("test");
- container.addMediaElement(new MediaElement());
- }
-
- [Ignore("This test needs further review: it seems to fail on IE for no apparent reason")]
- [Test]
- public function testExternalFunctions():void
- {
- if (ExternalInterface.available)
- {
- var container:HTMLMediaContainer = new HTMLMediaContainer("test");
-
- Assert.assertTrue(ExternalInterface.call("function(){return document.osmf;}"));
- Assert.assertTrue(ExternalInterface.call("function(){return document.osmf.containers;}"));
- Assert.assertTrue(ExternalInterface.call("function(){return document.osmf.containers.MediaFrameworkTest_test;}"));
- }
- }
-
- [Test]
- public function testHTMLMediaContainer():void
- {
- if (ExternalInterface.available)
- {
- var container:HTMLMediaContainer = new HTMLMediaContainer("test");
-
- var element:HTMLElement = new HTMLElement();
- container.addMediaElement(element);
-
- Assert.assertTrue(container.containsMediaElement(element));
- Assert.assertFalse(container.containsMediaElement(null));
- Assert.assertFalse(container.containsMediaElement(new MediaElement()));
-
- try
- {
- container.removeMediaElement(null);
-
- Assert.fail();
- }
- catch(e:Error)
- {
- }
-
- try
- {
- container.removeMediaElement(new MediaElement());
-
- Assert.fail();
- }
- catch(e:Error)
- {
- }
-
- container.removeMediaElement(element);
- Assert.assertFalse(container.containsMediaElement(element));
-
- container.addMediaElement(element);
- Assert.assertTrue(container.containsMediaElement(element));
-
- var element2:HTMLElement = new HTMLElement();
- container.addMediaElement(new ProxyElement(new ProxyElement(element2)));
-
- Assert.assertTrue(container.containsMediaElement(element2));
-
- // Test if the container constructs its own id if we omit it:
- var container2:HTMLMediaContainer = new HTMLMediaContainer();
- }
- }
- }
+/*****************************************************
+*
+* Copyright 2009 Adobe Systems Incorporated. All Rights Reserved.
+*
+*****************************************************
+* The contents of this file are subject to the Mozilla Public License
+* Version 1.1 (the "License"); you may not use this file except in
+* compliance with the License. You may obtain a copy of the License at
+* http://www.mozilla.org/MPL/
+*
+* Software distributed under the License is distributed on an "AS IS"
+* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+* License for the specific language governing rights and limitations
+* under the License.
+*
+*
+* The Initial Developer of the Original Code is Adobe Systems Incorporated.
+* Portions created by Adobe Systems Incorporated are Copyright (C) 2009 Adobe Systems
+* Incorporated. All Rights Reserved.
+*
+*****************************************************/
+package org.osmf.containers
+{
+ import flash.external.ExternalInterface;
+
+ import org.flexunit.Assert;
+ import org.osmf.elements.HTMLElement;
+ import org.osmf.elements.ProxyElement;
+ import org.osmf.media.MediaElement;
+
+ public class TestHTMLMediaContainer
+ {
+ [Test(expects="flash.errors.IllegalOperationError")]
+ public function testAddMediaElementNull():void
+ {
+ var container:HTMLMediaContainer = new HTMLMediaContainer("test");
+ container.addMediaElement(null);
+ }
+
+ [Test(expects="flash.errors.IllegalOperationError")]
+ public function testAddMediaElementEmptyMediaElement():void
+ {
+ var container:HTMLMediaContainer = new HTMLMediaContainer("test");
+ container.addMediaElement(new MediaElement());
+ }
+
+ [Test]
+ public function testHTMLMediaContainer():void
+ {
+ if (ExternalInterface.available)
+ {
+ var container:HTMLMediaContainer = new HTMLMediaContainer("test");
+
+ var element:HTMLElement = new HTMLElement();
+ container.addMediaElement(element);
+
+ Assert.assertTrue(container.containsMediaElement(element));
+ Assert.assertFalse(container.containsMediaElement(null));
+ Assert.assertFalse(container.containsMediaElement(new MediaElement()));
+
+ try
+ {
+ container.removeMediaElement(null);
+
+ Assert.fail();
+ }
+ catch(e:Error)
+ {
+ }
+
+ try
+ {
+ container.removeMediaElement(new MediaElement());
+
+ Assert.fail();
+ }
+ catch(e:Error)
+ {
+ }
+
+ container.removeMediaElement(element);
+ Assert.assertFalse(container.containsMediaElement(element));
+
+ container.addMediaElement(element);
+ Assert.assertTrue(container.containsMediaElement(element));
+
+ var element2:HTMLElement = new HTMLElement();
+ container.addMediaElement(new ProxyElement(new ProxyElement(element2)));
+
+ Assert.assertTrue(container.containsMediaElement(element2));
+
+ // Test if the container constructs its own id if we omit it:
+ var container2:HTMLMediaContainer = new HTMLMediaContainer();
+ }
+ }
+ }
}
\ No newline at end of file
diff --git a/lib/osmf/framework/OSMFTest/src/org/osmf/containers/TestMediaContainer.as b/lib/osmf/framework/OSMFTest/src/org/osmf/containers/TestMediaContainer.as
index c77efc3..e8c41cd 100644
--- a/lib/osmf/framework/OSMFTest/src/org/osmf/containers/TestMediaContainer.as
+++ b/lib/osmf/framework/OSMFTest/src/org/osmf/containers/TestMediaContainer.as
@@ -1,227 +1,227 @@
-/*****************************************************
-*
-* Copyright 2009 Adobe Systems Incorporated. All Rights Reserved.
-*
-*****************************************************
-* The contents of this file are subject to the Mozilla Public License
-* Version 1.1 (the "License"); you may not use this file except in
-* compliance with the License. You may obtain a copy of the License at
-* http://www.mozilla.org/MPL/
-*
-* Software distributed under the License is distributed on an "AS IS"
-* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
-* License for the specific language governing rights and limitations
-* under the License.
-*
-*
-* The Initial Developer of the Original Code is Adobe Systems Incorporated.
-* Portions created by Adobe Systems Incorporated are Copyright (C) 2009 Adobe Systems
-* Incorporated. All Rights Reserved.
-*
-*****************************************************/
-package org.osmf.containers
-{
- import flash.display.Sprite;
- import flash.errors.IllegalOperationError;
-
- import org.flexunit.Assert;
- import org.osmf.layout.HorizontalAlign;
- import org.osmf.layout.LayoutMetadata;
- import org.osmf.layout.LayoutRenderer;
- import org.osmf.layout.LayoutRendererBase;
- import org.osmf.layout.ScaleMode;
- import org.osmf.layout.TesterSprite;
- import org.osmf.layout.VerticalAlign;
- import org.osmf.traits.DisplayObjectTrait;
- import org.osmf.traits.MediaTraitType;
- import org.osmf.utils.DynamicMediaElement;
-
- public class TestMediaContainer
- {
- public function constructContainer(renderer:LayoutRendererBase=null):MediaContainer
- {
- return new MediaContainer(renderer);
- }
-
- [Test(expects="flash.errors.IllegalOperationError")]
- public function testAddChildNull():void
- {
- var container:MediaContainer = constructContainer();
- container.addChild(null);
- }
-
- [Test(expects="flash.errors.IllegalOperationError")]
- public function testAddChildAtNull():void
- {
- var container:MediaContainer = constructContainer();
- container.addChildAt(null, 0);
- }
-
- [Test(expects="flash.errors.IllegalOperationError")]
- public function testRemoveChildNull():void
- {
- var container:MediaContainer = constructContainer();
- container.removeChild(null);
- }
-
- [Test(expects="RangeError")]
- public function testRemoveChildAtNull():void
- {
- var container:MediaContainer = constructContainer();
- container.removeChildAt(0);
- }
-
- [Test(expects="flash.errors.IllegalOperationError")]
- public function testSetChildIndexNull():void
- {
- var container:MediaContainer = constructContainer();
- container.setChildIndex(null,0);
- }
-
- [Test]
- public function testContainerMediaElements():void
- {
- var renderer:LayoutRenderer = new LayoutRenderer();
- var parent:MediaContainer = constructContainer(renderer);
- parent.backgroundColor = 0xff0000;
- parent.backgroundAlpha = 1;
- parent.clipChildren = true;
-
- myAssertThrows(parent.addMediaElement,null);
-
- var element1:DynamicMediaElement = new DynamicMediaElement();
- var element2:DynamicMediaElement = new DynamicMediaElement();
-
- Assert.assertNotNull(parent);
- Assert.assertFalse(parent.containsMediaElement(element1));
- Assert.assertFalse(parent.containsMediaElement(element2));
-
- parent.addMediaElement(element1);
- Assert.assertTrue(parent.containsMediaElement(element1));
-
- myAssertThrows(parent.addMediaElement,element1);
-
- parent.addMediaElement(element2);
- Assert.assertTrue(parent.containsMediaElement(element2));
-
- Assert.assertTrue(element1 == parent.removeMediaElement(element1));
- Assert.assertFalse(parent.containsMediaElement(element1));
-
- var c2:MediaContainer = constructContainer();
- c2.addMediaElement(element2);
-
- Assert.assertFalse(parent.containsMediaElement(element2));
-
- var error:Error;
- try
- {
- parent.removeMediaElement(element1);
- }
- catch(e:Error)
- {
- error = e;
- }
-
- Assert.assertNotNull(error);
- Assert.assertTrue(error is IllegalOperationError);
-
- myAssertThrows(parent.removeMediaElement, null);
- }
-
-
- [Test]
- public function testContainerScaleAndAlign():void
- {
- // Child
-
- var mediaElement:DynamicMediaElement = new DynamicMediaElement();
-
- var viewSprite:Sprite = new TesterSprite();
- var viewTrait:DisplayObjectTrait = new DisplayObjectTrait(viewSprite, 486, 60);
- mediaElement.doAddTrait(MediaTraitType.DISPLAY_OBJECT, viewTrait);
- var layout:LayoutMetadata = new LayoutMetadata();
- mediaElement.addMetadata(LayoutMetadata.LAYOUT_NAMESPACE, layout);
- layout.scaleMode = ScaleMode.NONE;
- layout.verticalAlign = VerticalAlign.MIDDLE;
- layout.horizontalAlign = HorizontalAlign.CENTER;
-
- var container:MediaContainer = constructContainer();
- container.width = 800;
- container.height = 80;
-
- container.addMediaElement(mediaElement);
-
- container.validateNow();
-
- Assert.assertEquals(486, viewSprite.width);
- Assert.assertEquals(60, viewSprite.height);
-
- Assert.assertEquals(800/2 - 486/2, viewSprite.x);
- Assert.assertEquals(80/2 - 60/2, viewSprite.y);
- }
-
- [Test]
- public function testContainerAttributes():void
- {
- var container:MediaContainer = constructContainer();
- container.width = 500;
- container.height = 400;
-
- Assert.assertTrue(isNaN(container.backgroundColor));
- Assert.assertTrue(isNaN(container.backgroundAlpha));
-
- container.backgroundColor = 0xFF00FF;
- Assert.assertEquals(0xFF00FF, container.backgroundColor);
-
- container.backgroundColor = 0xFF00FF;
- Assert.assertEquals(0xFF00FF, container.backgroundColor);
-
- container.backgroundAlpha = 0.5;
- Assert.assertEquals(0.5, container.backgroundAlpha);
-
- container.backgroundAlpha = 0.5;
- Assert.assertEquals(0.5, container.backgroundAlpha);
-
- Assert.assertFalse(container.clipChildren);
- container.clipChildren = true;
- Assert.assertTrue(container.clipChildren);
-
- container.clipChildren = true;
- Assert.assertTrue(container.clipChildren);
-
- container.clipChildren = false;
- Assert.assertFalse(container.clipChildren);
-
- container.validateNow();
- Assert.assertEquals(500, container.width);
- Assert.assertEquals(400, container.height);
- }
-
- [Test]
- public function testConstructor():void
- {
- var renderer:LayoutRenderer = new LayoutRenderer();
- var container:MediaContainer = constructContainer(renderer);
- Assert.assertEquals(renderer, container.layoutRenderer);
-
- var container2:MediaContainer = new MediaContainer();
- Assert.assertNotNull(container2.layoutRenderer);
- }
-
- private function myAssertThrows(f:Function, ...arguments):*
- {
- var result:*;
-
- try
- {
- result = f.apply(null,arguments);
- Assert.fail();
- }
- catch(e:Error)
- {
- }
-
- return result;
- }
- }
+/*****************************************************
+*
+* Copyright 2009 Adobe Systems Incorporated. All Rights Reserved.
+*
+*****************************************************
+* The contents of this file are subject to the Mozilla Public License
+* Version 1.1 (the "License"); you may not use this file except in
+* compliance with the License. You may obtain a copy of the License at
+* http://www.mozilla.org/MPL/
+*
+* Software distributed under the License is distributed on an "AS IS"
+* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+* License for the specific language governing rights and limitations
+* under the License.
+*
+*
+* The Initial Developer of the Original Code is Adobe Systems Incorporated.
+* Portions created by Adobe Systems Incorporated are Copyright (C) 2009 Adobe Systems
+* Incorporated. All Rights Reserved.
+*
+*****************************************************/
+package org.osmf.containers
+{
+ import flash.display.Sprite;
+ import flash.errors.IllegalOperationError;
+
+ import org.flexunit.Assert;
+ import org.osmf.layout.HorizontalAlign;
+ import org.osmf.layout.LayoutMetadata;
+ import org.osmf.layout.LayoutRenderer;
+ import org.osmf.layout.LayoutRendererBase;
+ import org.osmf.layout.ScaleMode;
+ import org.osmf.layout.TesterSprite;
+ import org.osmf.layout.VerticalAlign;
+ import org.osmf.traits.DisplayObjectTrait;
+ import org.osmf.traits.MediaTraitType;
+ import org.osmf.utils.DynamicMediaElement;
+
+ public class TestMediaContainer
+ {
+ public function constructContainer(renderer:LayoutRendererBase=null):MediaContainer
+ {
+ return new MediaContainer(renderer);
+ }
+
+ [Test(expects="flash.errors.IllegalOperationError")]
+ public function testAddChildNull():void
+ {
+ var container:MediaContainer = constructContainer();
+ container.addChild(null);
+ }
+
+ [Test(expects="flash.errors.IllegalOperationError")]
+ public function testAddChildAtNull():void
+ {
+ var container:MediaContainer = constructContainer();
+ container.addChildAt(null, 0);
+ }
+
+ [Test(expects="flash.errors.IllegalOperationError")]
+ public function testRemoveChildNull():void
+ {
+ var container:MediaContainer = constructContainer();
+ container.removeChild(null);
+ }
+
+ [Test(expects="RangeError")]
+ public function testRemoveChildAtNull():void
+ {
+ var container:MediaContainer = constructContainer();
+ container.removeChildAt(0);
+ }
+
+ [Test(expects="flash.errors.IllegalOperationError")]
+ public function testSetChildIndexNull():void
+ {
+ var container:MediaContainer = constructContainer();
+ container.setChildIndex(null,0);
+ }
+
+ [Test]
+ public function testContainerMediaElements():void
+ {
+ var renderer:LayoutRenderer = new LayoutRenderer();
+ var parent:MediaContainer = constructContainer(renderer);
+ parent.backgroundColor = 0xff0000;
+ parent.backgroundAlpha = 1;
+ parent.clipChildren = true;
+
+ myAssertThrows(parent.addMediaElement,null);
+
+ var element1:DynamicMediaElement = new DynamicMediaElement();
+ var element2:DynamicMediaElement = new DynamicMediaElement();
+
+ Assert.assertNotNull(parent);
+ Assert.assertFalse(parent.containsMediaElement(element1));
+ Assert.assertFalse(parent.containsMediaElement(element2));
+
+ parent.addMediaElement(element1);
+ Assert.assertTrue(parent.containsMediaElement(element1));
+
+ myAssertThrows(parent.addMediaElement,element1);
+
+ parent.addMediaElement(element2);
+ Assert.assertTrue(parent.containsMediaElement(element2));
+
+ Assert.assertTrue(element1 == parent.removeMediaElement(element1));
+ Assert.assertFalse(parent.containsMediaElement(element1));
+
+ var c2:MediaContainer = constructContainer();
+ c2.addMediaElement(element2);
+
+ Assert.assertFalse(parent.containsMediaElement(element2));
+
+ var error:Error;
+ try
+ {
+ parent.removeMediaElement(element1);
+ }
+ catch(e:Error)
+ {
+ error = e;
+ }
+
+ Assert.assertNotNull(error);
+ Assert.assertTrue(error is IllegalOperationError);
+
+ myAssertThrows(parent.removeMediaElement, null);
+ }
+
+
+ [Test]
+ public function testContainerScaleAndAlign():void
+ {
+ // Child
+
+ var mediaElement:DynamicMediaElement = new DynamicMediaElement();
+
+ var viewSprite:Sprite = new TesterSprite();
+ var viewTrait:DisplayObjectTrait = new DisplayObjectTrait(viewSprite, 486, 60);
+ mediaElement.doAddTrait(MediaTraitType.DISPLAY_OBJECT, viewTrait);
+ var layout:LayoutMetadata = new LayoutMetadata();
+ mediaElement.addMetadata(LayoutMetadata.LAYOUT_NAMESPACE, layout);
+ layout.scaleMode = ScaleMode.NONE;
+ layout.verticalAlign = VerticalAlign.MIDDLE;
+ layout.horizontalAlign = HorizontalAlign.CENTER;
+
+ var container:MediaContainer = constructContainer();
+ container.width = 800;
+ container.height = 80;
+
+ container.addMediaElement(mediaElement);
+
+ container.validateNow();
+
+ Assert.assertEquals(486, viewSprite.width);
+ Assert.assertEquals(60, viewSprite.height);
+
+ Assert.assertEquals(800/2 - 486/2, viewSprite.x);
+ Assert.assertEquals(80/2 - 60/2, viewSprite.y);
+ }
+
+ [Test]
+ public function testContainerAttributes():void
+ {
+ var container:MediaContainer = constructContainer();
+ container.width = 500;
+ container.height = 400;
+
+ Assert.assertTrue(isNaN(container.backgroundColor));
+ Assert.assertTrue(isNaN(container.backgroundAlpha));
+
+ container.backgroundColor = 0xFF00FF;
+ Assert.assertEquals(0xFF00FF, container.backgroundColor);
+
+ container.backgroundColor = 0xFF00FF;
+ Assert.assertEquals(0xFF00FF, container.backgroundColor);
+
+ container.backgroundAlpha = 0.5;
+ Assert.assertEquals(0.5, container.backgroundAlpha);
+
+ container.backgroundAlpha = 0.5;
+ Assert.assertEquals(0.5, container.backgroundAlpha);
+
+ Assert.assertFalse(container.clipChildren);
+ container.clipChildren = true;
+ Assert.assertTrue(container.clipChildren);
+
+ container.clipChildren = true;
+ Assert.assertTrue(container.clipChildren);
+
+ container.clipChildren = false;
+ Assert.assertFalse(container.clipChildren);
+
+ container.validateNow();
+ Assert.assertEquals(500, container.width);
+ Assert.assertEquals(400, container.height);
+ }
+
+ [Test]
+ public function testConstructor():void
+ {
+ var renderer:LayoutRenderer = new LayoutRenderer();
+ var container:MediaContainer = constructContainer(renderer);
+ Assert.assertEquals(renderer, container.layoutRenderer);
+
+ var container2:MediaContainer = new MediaContainer();
+ Assert.assertNotNull(container2.layoutRenderer);
+ }
+
+ private function myAssertThrows(f:Function, ...arguments):*
+ {
+ var result:*;
+
+ try
+ {
+ result = f.apply(null,arguments);
+ Assert.fail();
+ }
+ catch(e:Error)
+ {
+ }
+
+ return result;
+ }
+ }
}
\ No newline at end of file
diff --git a/lib/osmf/framework/OSMFTest/src/org/osmf/elements/f4mClasses/TestExternalMediaParser.as b/lib/osmf/framework/OSMFTest/src/org/osmf/elements/f4mClasses/TestExternalMediaParser.as
new file mode 100644
index 0000000..505c019
--- /dev/null
+++ b/lib/osmf/framework/OSMFTest/src/org/osmf/elements/f4mClasses/TestExternalMediaParser.as
@@ -0,0 +1,77 @@
+package org.osmf.elements.f4mClasses
+{
+ import org.flexunit.Assert;
+ import org.flexunit.async.Async;
+ import org.osmf.elements.f4mClasses.ExternalMediaParser;
+ import org.osmf.events.ParseEvent;
+
+ public class TestExternalMediaParser
+ {
+
+ [Before]
+ public function setUp():void
+ {
+ parser = new ExternalMediaParser();
+ }
+
+ [After]
+ public function tearDown():void
+ {
+ parser = null;
+ }
+
+ [Test(async, description="Tests a media node from a 2.0 F4M.")]
+ public function testParseExternalMedia():void
+ {
+ var test:XML = ;
+ var asyncHandler:Function = Async.asyncHandler(this, handleExternalParseComplete, TIMEOUT, null, handleTimeout);
+ parser.addEventListener(ParseEvent.PARSE_COMPLETE, asyncHandler, false, 0, true);
+ parser.parse(test.toXMLString());
+ }
+
+ private function handleExternalParseComplete(event:ParseEvent, passThroughData:Object):void
+ {
+ Assert.assertNull(event.data);
+ }
+
+ [Test(async, description="Tests a media node from a 1.0 F4M.")]
+ public function testParseInlineMedia():void
+ {
+ var test:XML =
+
+ AgAKb25NZXRhRGF0YQgAAAAAAAhkdXJhdGlvbgBAYwYy29GUIwAFd2lkdGgAQIgAAAAAAAAABmhlaWdodABAewAAAAAAAAAMdmlkZW9jb2RlY2lkAgAEYXZjMQAMYXVkaW9jb2RlY2lkAgAEbXA0YQAKYXZjcHJvZmlsZQBAUIAAAAAAAAAIYXZjbGV2ZWwAQD4AAAAAAAAABmFhY2FvdAAAAAAAAAAAAAAOdmlkZW9mcmFtZXJhdGUAQDf53LURIocAD2F1ZGlvc2FtcGxlcmF0ZQBA1YiAAAAAAAANYXVkaW9jaGFubmVscwBAAAAAAAAAAAAJdHJhY2tpbmZvCgAAAAIDAAZsZW5ndGgAQUveFIAAAAAACXRpbWVzY2FsZQBA13AAAAAAAAAIbGFuZ3VhZ2UCAANgYGAAAAkDAAZsZW5ndGgAQUmab4AAAAAACXRpbWVzY2FsZQBA1YiAAAAAAAAIbGFuZ3VhZ2UCAANgYGAAAAkAB2N1c3RkZWYKAAAAAAAACQ==
+
+ ;
+ var asyncHandler:Function = Async.asyncHandler(this, handleInlineParseComplete, TIMEOUT, null, handleTimeout);
+ parser.addEventListener(ParseEvent.PARSE_COMPLETE, asyncHandler, false, 0, true);
+ parser.parse(test.toXMLString());
+ }
+
+ private function handleInlineParseComplete(event:ParseEvent, passThroughData:Object):void
+ {
+ var m:Media = event.data as Media;
+
+ Assert.assertNotNull(m);
+ Assert.assertEquals(m.url, 'http://samples.osmf.org/jit/sample1_150kbps');
+ Assert.assertEquals(m.bitrate, 1030);
+ Assert.assertEquals(m.bootstrapInfo.id, 'bootstrap971');
+ }
+
+ private function handleTimeout(passThroughData:Object):void
+ {
+ Assert.fail("Timeout reached before event.");
+ }
+
+ private static const TIMEOUT:Number = 1000;
+
+ private var parser:ExternalMediaParser;
+ }
+}
\ No newline at end of file
diff --git a/lib/osmf/framework/OSMFTest/src/org/osmf/elements/f4mClasses/builders/TestManifestBuilder.as b/lib/osmf/framework/OSMFTest/src/org/osmf/elements/f4mClasses/builders/TestManifestBuilder.as
new file mode 100644
index 0000000..91f3527
--- /dev/null
+++ b/lib/osmf/framework/OSMFTest/src/org/osmf/elements/f4mClasses/builders/TestManifestBuilder.as
@@ -0,0 +1,52 @@
+package org.osmf.elements.f4mClasses.builders
+{
+ import org.flexunit.Assert;
+ import org.hamcrest.assertThat;
+ import org.hamcrest.core.isA;
+ import org.osmf.elements.f4mClasses.builders.ManifestBuilder;
+ import org.osmf.elements.f4mClasses.ManifestParser;
+
+ public class TestManifestBuilder
+ {
+ private var builder:ManifestBuilder;
+
+ [Before]
+ public function setUp():void
+ {
+ builder = new ManifestBuilder();
+ }
+
+ [After]
+ public function tearDown():void
+ {
+ builder = null;
+ }
+
+ [Test]
+ public function testCanParseTrue():void
+ {
+ var test:String = "";
+ var result:Boolean = builder.canParse(test);
+
+ Assert.assertTrue(result);
+ }
+
+ [Test]
+ public function testCanParseFalse():void
+ {
+ var test:String = "";
+ var result:Boolean = builder.canParse(test);
+
+ Assert.assertFalse(result);
+ }
+
+ [Test]
+ public function testBuild():void
+ {
+ var test:String = "";
+ var parser:ManifestParser = builder.build(test);
+
+ assertThat(parser, isA(ManifestParser));
+ }
+ }
+}
\ No newline at end of file
diff --git a/lib/osmf/framework/OSMFTest/src/org/osmf/elements/f4mClasses/builders/TestMultiLevelManifestBuilder.as b/lib/osmf/framework/OSMFTest/src/org/osmf/elements/f4mClasses/builders/TestMultiLevelManifestBuilder.as
new file mode 100644
index 0000000..0324cf1
--- /dev/null
+++ b/lib/osmf/framework/OSMFTest/src/org/osmf/elements/f4mClasses/builders/TestMultiLevelManifestBuilder.as
@@ -0,0 +1,53 @@
+package org.osmf.elements.f4mClasses.builders
+{
+ import org.flexunit.Assert;
+ import org.hamcrest.assertThat;
+ import org.hamcrest.core.isA;
+ import org.osmf.elements.f4mClasses.builders.MultiLevelManifestBuilder;
+ import org.osmf.elements.f4mClasses.ManifestParser;
+ import org.osmf.elements.f4mClasses.MultiLevelManifestParser;
+
+ public class TestMultiLevelManifestBuilder
+ {
+ private var builder:MultiLevelManifestBuilder;
+
+ [Before]
+ public function setUp():void
+ {
+ builder = new MultiLevelManifestBuilder();
+ }
+
+ [After]
+ public function tearDown():void
+ {
+ builder = null;
+ }
+
+ [Test]
+ public function testCanParseTrue():void
+ {
+ var test:String = "";
+ var result:Boolean = builder.canParse(test);
+
+ Assert.assertTrue(result);
+ }
+
+ [Test]
+ public function testCanParseFalse():void
+ {
+ var test:String = "";
+ var result:Boolean = builder.canParse(test);
+
+ Assert.assertFalse(result);
+ }
+
+ [Test]
+ public function testBuild():void
+ {
+ var test:String = "";
+ var parser:ManifestParser = builder.build(test);
+
+ assertThat(parser, isA(MultiLevelManifestParser));
+ }
+ }
+}
\ No newline at end of file
diff --git a/lib/osmf/framework/OSMFTest/src/org/osmf/layout/TestLayoutTargetSprite.as b/lib/osmf/framework/OSMFTest/src/org/osmf/layout/TestLayoutTargetSprite.as
new file mode 100644
index 0000000..0ceba70
--- /dev/null
+++ b/lib/osmf/framework/OSMFTest/src/org/osmf/layout/TestLayoutTargetSprite.as
@@ -0,0 +1,183 @@
+package org.osmf.layout
+{
+ import flexunit.framework.Assert;
+
+ public class TestLayoutTargetSprite
+ {
+ private var layoutTargetSprite:LayoutTargetSprite;
+
+ [Before]
+ public function setUp():void
+ {
+ this.layoutTargetSprite = new LayoutTargetSprite()
+ }
+
+ [After]
+ public function tearDown():void
+ {
+ }
+
+ [BeforeClass]
+ public static function setUpBeforeClass():void
+ {
+ }
+
+ [AfterClass]
+ public static function tearDownAfterClass():void
+ {
+ }
+
+ [Test]
+ public function testXSetterSingleChild():void
+ {
+ var triggered:Boolean = false;
+
+ function genericTriggeredCallback():void
+ {
+ triggered = true;
+ }
+
+ var genericDO:GenericDisplayObject = new GenericDisplayObject(genericTriggeredCallback);
+ this.layoutTargetSprite.addChild(genericDO);
+
+ this.layoutTargetSprite.x = 10;
+
+ Assert.assertTrue(triggered);
+ }
+
+ [Test]
+ public function testYSetterSingleChild():void
+ {
+ var triggered:Boolean = false;
+
+ function genericTriggeredCallback():void
+ {
+ triggered = true;
+ }
+
+ var genericDO:GenericDisplayObject = new GenericDisplayObject(genericTriggeredCallback);
+ this.layoutTargetSprite.addChild(genericDO);
+
+ this.layoutTargetSprite.y = 10;
+
+ Assert.assertTrue(triggered);
+ }
+
+ [Test]
+ public function testXSetterMultipleChildren():void
+ {
+ var triggered1:Boolean = false;
+ var triggered2:Boolean = false;
+
+ function genericTriggeredCallback1():void
+ {
+ triggered1 = true;
+ }
+
+ function genericTriggeredCallback2():void
+ {
+ triggered2 = true;
+ }
+
+ var genericDO1:GenericDisplayObject = new GenericDisplayObject(genericTriggeredCallback1);
+ var genericDO2:GenericDisplayObject = new GenericDisplayObject(genericTriggeredCallback2);
+ this.layoutTargetSprite.addChild(genericDO1);
+ this.layoutTargetSprite.addChild(genericDO2);
+
+ this.layoutTargetSprite.x = 10;
+
+ Assert.assertTrue(triggered1);
+ Assert.assertTrue(triggered2);
+ }
+
+ [Test]
+ public function testYSetterMultipleChildren():void
+ {
+ var triggered1:Boolean = false;
+ var triggered2:Boolean = false;
+
+ function genericTriggeredCallback1():void
+ {
+ triggered1 = true;
+ }
+
+ function genericTriggeredCallback2():void
+ {
+ triggered2 = true;
+ }
+
+ var genericDO1:GenericDisplayObject = new GenericDisplayObject(genericTriggeredCallback1);
+ var genericDO2:GenericDisplayObject = new GenericDisplayObject(genericTriggeredCallback2);
+ this.layoutTargetSprite.addChild(genericDO1);
+ this.layoutTargetSprite.addChild(genericDO2);
+
+ this.layoutTargetSprite.y = 10;
+
+ Assert.assertTrue(triggered1);
+ Assert.assertTrue(triggered2);
+ }
+
+ [Test]
+ public function testXSetterMultipleContainers():void
+ {
+ var triggered:Boolean = false;
+
+ function genericTriggeredCallback():void
+ {
+ triggered = true;
+ }
+
+ var genericDO:GenericDisplayObject = new GenericDisplayObject(genericTriggeredCallback);
+ var middleLayoutTargetSprite:LayoutTargetSprite = new LayoutTargetSprite();
+
+ middleLayoutTargetSprite.addChild(genericDO);
+ this.layoutTargetSprite.addChild(middleLayoutTargetSprite);
+
+ this.layoutTargetSprite.x = 10;
+
+ Assert.assertTrue(triggered);
+ }
+
+ [Test]
+ public function testYSetterMultipleContainers():void
+ {
+ var triggered:Boolean = false;
+
+ function genericTriggeredCallback():void
+ {
+ triggered = true;
+ }
+
+ var genericDO:GenericDisplayObject = new GenericDisplayObject(genericTriggeredCallback);
+ var middleLayoutTargetSprite:LayoutTargetSprite = new LayoutTargetSprite();
+
+ middleLayoutTargetSprite.addChild(genericDO);
+ this.layoutTargetSprite.addChild(middleLayoutTargetSprite);
+
+ this.layoutTargetSprite.y = 10;
+
+ Assert.assertTrue(triggered);
+ }
+ }
+}
+import flash.display.Sprite;
+
+internal class GenericDisplayObject extends Sprite
+{
+ private var _callback:Function;
+
+ public function GenericDisplayObject(callback:Function)
+ {
+ this._callback = callback;
+ }
+
+ override public function set x(value:Number):void
+ {
+ this._callback();
+ }
+
+ override public function set y(value:Number):void
+ {
+ this._callback();
+ }
+}
\ No newline at end of file
diff --git a/lib/osmf/framework/OSMFTest/src/org/osmf/logging/TestLog.as b/lib/osmf/framework/OSMFTest/src/org/osmf/logging/TestLog.as
index 51b00a5..defa098 100644
--- a/lib/osmf/framework/OSMFTest/src/org/osmf/logging/TestLog.as
+++ b/lib/osmf/framework/OSMFTest/src/org/osmf/logging/TestLog.as
@@ -48,47 +48,56 @@ package org.osmf.logging
[Test]
public function testAccessLoggerFactory():void
{
- var loggerFactory:TraceLoggerFactory = new TraceLoggerFactory();
- Log.loggerFactory = loggerFactory;
-
- Assert.assertTrue(loggerFactory == Log.loggerFactory);
+ CONFIG::LOGGING
+ {
+ var loggerFactory:TraceLoggerFactory = new TraceLoggerFactory();
+ Log.loggerFactory = loggerFactory;
+
+ Assert.assertTrue(loggerFactory == Log.loggerFactory);
+ }
}
[Test]
public function testGetLogger():void
{
- var logger:Logger = Log.getLogger("testLogger");
-
CONFIG::LOGGING
{
+ var logger:Logger = Log.getLogger("testLogger");
+
+ CONFIG::LOGGING
+ {
+ Assert.assertTrue(logger != null);
+ logger = null;
+ }
+
+ Assert.assertTrue(logger == null);
+
+ Log.loggerFactory = new TraceLoggerFactory();
+
+ logger = Log.getLogger("testLogger");
Assert.assertTrue(logger != null);
- logger = null;
}
-
- Assert.assertTrue(logger == null);
-
- Log.loggerFactory = new TraceLoggerFactory();
-
- logger = Log.getLogger("testLogger");
- Assert.assertTrue(logger != null);
}
[Test]
public function testLevelEnablements():void
{
- var logger:Logger = new TraceLoggerFactory().getLogger("testLogger");
-
- logger.debug("message");
- logger.error("message");
- logger.info("message");
- logger.warn("message");
- logger.fatal("message");
-
- logger.debug("{0} message", "debug");
- logger.error("{0} message", "error");
- logger.info("{0} message", "info");
- logger.warn("{0} message", "warn");
- logger.fatal("{0} message", "fatal");
+ CONFIG::LOGGING
+ {
+ var logger:Logger = new TraceLoggerFactory().getLogger("testLogger");
+
+ logger.debug("message");
+ logger.error("message");
+ logger.info("message");
+ logger.warn("message");
+ logger.fatal("message");
+
+ logger.debug("{0} message", "debug");
+ logger.error("{0} message", "error");
+ logger.info("{0} message", "info");
+ logger.warn("{0} message", "warn");
+ logger.fatal("{0} message", "fatal");
+ }
}
}
}
\ No newline at end of file
diff --git a/lib/osmf/framework/OSMFTest/src/org/osmf/media/MediaTraitResolverBaseTestCase.as b/lib/osmf/framework/OSMFTest/src/org/osmf/media/MediaTraitResolverBaseTestCase.as
index ccec2cc..2a98a3a 100644
--- a/lib/osmf/framework/OSMFTest/src/org/osmf/media/MediaTraitResolverBaseTestCase.as
+++ b/lib/osmf/framework/OSMFTest/src/org/osmf/media/MediaTraitResolverBaseTestCase.as
@@ -1,101 +1,56 @@
-/*****************************************************
-*
-* Copyright 2009 Adobe Systems Incorporated. All Rights Reserved.
-*
-*****************************************************
-* The contents of this file are subject to the Mozilla Public License
-* Version 1.1 (the "License"); you may not use this file except in
-* compliance with the License. You may obtain a copy of the License at
-* http://www.mozilla.org/MPL/
-*
-* Software distributed under the License is distributed on an "AS IS"
-* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
-* License for the specific language governing rights and limitations
-* under the License.
-*
-*
-* The Initial Developer of the Original Code is Adobe Systems Incorporated.
-* Portions created by Adobe Systems Incorporated are Copyright (C) 2009 Adobe Systems
-* Incorporated. All Rights Reserved.
-*
-*****************************************************/
-package org.osmf.media
-{
- import org.flexunit.Assert;
- import org.osmf.traits.BufferTrait;
- import org.osmf.traits.MediaTraitBase;
- import org.osmf.traits.MediaTraitType;
- import org.osmf.traits.TimeTrait;
- import org.osmf.traits.DisplayObjectTrait;
-
- public class MediaTraitResolverBaseTestCase
- {
- public function constructResolver(type:String, traitOfType:MediaTraitBase):MediaTraitResolver
- {
- return null;
- }
-
- [Ignore]
- [Test(expects="ArgumentError")]
- public function testConstructor():void
- {
- var resolver:MediaTraitResolver;
- resolver = constructResolver(null, null);
- Assert.assertNull(resolver);
- }
-
- [Ignore]
- [Test]
- public function testType():void
- {
- var resolver:MediaTraitResolver;
- resolver = constructResolver(MediaTraitType.BUFFER, new BufferTrait());
- Assert.assertNotNull(resolver);
- Assert.assertEquals(MediaTraitType.BUFFER, resolver.type);
- }
-
- [Test(expects="Error")]
- public function testAddTraitNull():void
- {
- var type:String = MediaTraitType.TIME;
- var resolver:MediaTraitResolver = constructResolver(type, new TimeTrait());
-
- resolver.addTrait(null);
- }
-
- [Test(expects="Error")]
- public function testAddTrait():void
- {
- var type:String = MediaTraitType.TIME;
- var resolver:MediaTraitResolver = constructResolver(type, new TimeTrait());
-
- resolver.addTrait(new DisplayObjectTrait(null));
- }
-
- [Ignore]
- [Test(expects="Error")]
- public function testRemoveTraitNull():void
- {
- var type:String = MediaTraitType.TIME;
- var resolver:MediaTraitResolver = constructResolver(type, new TimeTrait());
-
- resolver.removeTrait(null);
-
- }
-
- [Ignore]
- [Test(expects="Error")]
- public function testRemoveNonAddedTrait():void
- {
- var type:String = MediaTraitType.TIME;
- var resolver:MediaTraitResolver = constructResolver(type, new TimeTrait());
- var tt:TimeTrait = new TimeTrait();
-
- resolver.removeTrait(tt);
-
- //How to test this ...
- //resolver.addTrait(tt);
- //resolver.removeTrait(tt);
- }
- }
+/*****************************************************
+*
+* Copyright 2009 Adobe Systems Incorporated. All Rights Reserved.
+*
+*****************************************************
+* The contents of this file are subject to the Mozilla Public License
+* Version 1.1 (the "License"); you may not use this file except in
+* compliance with the License. You may obtain a copy of the License at
+* http://www.mozilla.org/MPL/
+*
+* Software distributed under the License is distributed on an "AS IS"
+* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+* License for the specific language governing rights and limitations
+* under the License.
+*
+*
+* The Initial Developer of the Original Code is Adobe Systems Incorporated.
+* Portions created by Adobe Systems Incorporated are Copyright (C) 2009 Adobe Systems
+* Incorporated. All Rights Reserved.
+*
+*****************************************************/
+package org.osmf.media
+{
+ import org.flexunit.Assert;
+ import org.osmf.traits.BufferTrait;
+ import org.osmf.traits.MediaTraitBase;
+ import org.osmf.traits.MediaTraitType;
+ import org.osmf.traits.TimeTrait;
+ import org.osmf.traits.DisplayObjectTrait;
+
+ public class MediaTraitResolverBaseTestCase
+ {
+ public function constructResolver(type:String, traitOfType:MediaTraitBase):MediaTraitResolver
+ {
+ return null;
+ }
+
+ [Test(expects="Error")]
+ public function testAddTraitNull():void
+ {
+ var type:String = MediaTraitType.TIME;
+ var resolver:MediaTraitResolver = constructResolver(type, new TimeTrait());
+
+ resolver.addTrait(null);
+ }
+
+ [Test(expects="Error")]
+ public function testAddTrait():void
+ {
+ var type:String = MediaTraitType.TIME;
+ var resolver:MediaTraitResolver = constructResolver(type, new TimeTrait());
+
+ resolver.addTrait(new DisplayObjectTrait(null));
+ }
+ }
}
\ No newline at end of file
diff --git a/lib/osmf/framework/OSMFTest/src/org/osmf/media/TestDefaultTraitResolver.as b/lib/osmf/framework/OSMFTest/src/org/osmf/media/TestDefaultTraitResolver.as
index 6b5cbc5..26e721b 100644
--- a/lib/osmf/framework/OSMFTest/src/org/osmf/media/TestDefaultTraitResolver.as
+++ b/lib/osmf/framework/OSMFTest/src/org/osmf/media/TestDefaultTraitResolver.as
@@ -1,66 +1,66 @@
-/*****************************************************
-*
-* Copyright 2009 Adobe Systems Incorporated. All Rights Reserved.
-*
-*****************************************************
-* The contents of this file are subject to the Mozilla Public License
-* Version 1.1 (the "License"); you may not use this file except in
-* compliance with the License. You may obtain a copy of the License at
-* http://www.mozilla.org/MPL/
-*
-* Software distributed under the License is distributed on an "AS IS"
-* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
-* License for the specific language governing rights and limitations
-* under the License.
-*
-*
-* The Initial Developer of the Original Code is Adobe Systems Incorporated.
-* Portions created by Adobe Systems Incorporated are Copyright (C) 2009 Adobe Systems
-* Incorporated. All Rights Reserved.
-*
-*****************************************************/
-package org.osmf.media
-{
- import org.osmf.traits.MediaTraitBase;
- import org.osmf.traits.MediaTraitType;
- import org.osmf.traits.TimeTrait;
-
- import org.flexunit.Assert;
-
- public class TestDefaultTraitResolver extends MediaTraitResolverBaseTestCase
- {
- override public function constructResolver(type:String, traitOfType:MediaTraitBase):MediaTraitResolver
- {
- return new DefaultTraitResolver(type, traitOfType);
- }
-
- [Test(expects="Error")]
- public function testDefaultTraitResolver():void
- {
- new DefaultTraitResolver(MediaTraitType.AUDIO, new TimeTrait());
- }
-
- [Test(expects="Error")]
- public function testDefaultTraitResolverNull():void
- {
- new DefaultTraitResolver(MediaTraitType.TIME, null);
- }
-
- [Test]
- public function testResolvedTrait():void
- {
- var t1:TimeTrait = new TimeTrait();
- var resolver:DefaultTraitResolver = new DefaultTraitResolver(MediaTraitType.TIME, t1);
-
- Assert.assertEquals(MediaTraitType.TIME, resolver.type);
- Assert.assertEquals(t1, resolver.resolvedTrait);
-
- var t2:TimeTrait = new TimeTrait();
- resolver.addTrait(t2);
- Assert.assertEquals(t2, resolver.resolvedTrait);
-
- resolver.removeTrait(t2);
- Assert.assertEquals(t1, resolver.resolvedTrait);
- }
- }
+/*****************************************************
+*
+* Copyright 2009 Adobe Systems Incorporated. All Rights Reserved.
+*
+*****************************************************
+* The contents of this file are subject to the Mozilla Public License
+* Version 1.1 (the "License"); you may not use this file except in
+* compliance with the License. You may obtain a copy of the License at
+* http://www.mozilla.org/MPL/
+*
+* Software distributed under the License is distributed on an "AS IS"
+* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+* License for the specific language governing rights and limitations
+* under the License.
+*
+*
+* The Initial Developer of the Original Code is Adobe Systems Incorporated.
+* Portions created by Adobe Systems Incorporated are Copyright (C) 2009 Adobe Systems
+* Incorporated. All Rights Reserved.
+*
+*****************************************************/
+package org.osmf.media
+{
+ import org.osmf.traits.MediaTraitBase;
+ import org.osmf.traits.MediaTraitType;
+ import org.osmf.traits.TimeTrait;
+
+ import org.flexunit.Assert;
+
+ public class TestDefaultTraitResolver extends MediaTraitResolverBaseTestCase
+ {
+ override public function constructResolver(type:String, traitOfType:MediaTraitBase):MediaTraitResolver
+ {
+ return new DefaultTraitResolver(type, traitOfType);
+ }
+
+ [Test(expects="Error")]
+ public function testDefaultTraitResolver():void
+ {
+ new DefaultTraitResolver(MediaTraitType.AUDIO, new TimeTrait());
+ }
+
+ [Test(expects="Error")]
+ public function testDefaultTraitResolverNull():void
+ {
+ new DefaultTraitResolver(MediaTraitType.TIME, null);
+ }
+
+ [Test]
+ public function testResolvedTrait():void
+ {
+ var t1:TimeTrait = new TimeTrait();
+ var resolver:DefaultTraitResolver = new DefaultTraitResolver(MediaTraitType.TIME, t1);
+
+ Assert.assertEquals(MediaTraitType.TIME, resolver.type);
+ Assert.assertEquals(t1, resolver.resolvedTrait);
+
+ var t2:TimeTrait = new TimeTrait();
+ resolver.addTrait(t2);
+ Assert.assertEquals(t2, resolver.resolvedTrait);
+
+ resolver.removeTrait(t2);
+ Assert.assertEquals(t1, resolver.resolvedTrait);
+ }
+ }
}
\ No newline at end of file
diff --git a/lib/osmf/framework/OSMFTest/src/org/osmf/media/TestMediaElement.as b/lib/osmf/framework/OSMFTest/src/org/osmf/media/TestMediaElement.as
index 4d93413..9865128 100644
--- a/lib/osmf/framework/OSMFTest/src/org/osmf/media/TestMediaElement.as
+++ b/lib/osmf/framework/OSMFTest/src/org/osmf/media/TestMediaElement.as
@@ -53,41 +53,6 @@ package org.osmf.media
{
_eventDispatcher = null;
}
-
- [Ignore]
- [Test]
- public function testGetTraitTypes():void
- {
- var mediaElement:MediaElement = createMediaElement();
-
- verifyGetTraitTypes(mediaElement, existentTraitTypesOnInitialization);
- }
-
- [Ignore]
- [Test]
- public function testHasTrait():void
- {
- var mediaElement:MediaElement = createMediaElement();
-
- verifyHasTrait(mediaElement, existentTraitTypesOnInitialization);
- }
-
- [Ignore]
- [Test(expects="ArgumentError")]
- public function testHasTraitWhenParamIsNull():void
- {
- var mediaElement:MediaElement = createMediaElement();
- mediaElement.hasTrait(null);
- }
-
- [Ignore]
- [Test]
- public function testGetTrait():void
- {
- var mediaElement:MediaElement = createMediaElement();
-
- verifyGetTrait(mediaElement, existentTraitTypesOnInitialization);
- }
[Test(expects="ArgumentError")]
public function testGetTraitWhenParamIsNull():void
diff --git a/lib/osmf/framework/OSMFTest/src/org/osmf/media/TestMediaPlayerSprite.as b/lib/osmf/framework/OSMFTest/src/org/osmf/media/TestMediaPlayerSprite.as
index 894418a..6571613 100644
--- a/lib/osmf/framework/OSMFTest/src/org/osmf/media/TestMediaPlayerSprite.as
+++ b/lib/osmf/framework/OSMFTest/src/org/osmf/media/TestMediaPlayerSprite.as
@@ -1,132 +1,132 @@
-package org.osmf.media
-{
- import flexunit.framework.Assert;
-
- import org.osmf.containers.MediaContainer;
- import org.osmf.elements.AudioElement;
- import org.osmf.elements.VideoElement;
- import org.osmf.layout.LayoutMetadata;
- import org.osmf.layout.ScaleMode;
-
- public class TestMediaPlayerSprite
- {
- [Test]
- public function testConstructor():void
- {
- var container:MediaContainer = new MediaContainer();
- var player:MediaPlayer = new MediaPlayer();
- var factory:MediaFactory = new MediaFactory();
-
- var mps:MediaPlayerSprite = new MediaPlayerSprite(player, container, factory);
- Assert.assertEquals(mps.mediaPlayer, player);
- Assert.assertEquals(mps.mediaContainer, container);
- Assert.assertEquals(mps.mediaFactory, factory);
-
- mps = new MediaPlayerSprite();
- Assert.assertNotNull(mps.mediaPlayer);
- Assert.assertNotNull(mps.mediaContainer);
- Assert.assertNotNull(mps.mediaFactory);
-
- player.media = new AudioElement();
-
- mps = new MediaPlayerSprite(player);
- Assert.assertTrue(mps.mediaContainer.containsMediaElement(player.media));
- Assert.assertEquals(mps.media, player.media);
- }
-
- [Test]
- public function testMedia():void
- {
- var mps:MediaPlayerSprite = new MediaPlayerSprite();
-
- Assert.assertNull(mps.media);
- Assert.assertNull(mps.mediaPlayer.media);
-
- mps.mediaPlayer.media = new AudioElement();
-
- Assert.assertEquals(mps.media, mps.mediaPlayer.media);
- Assert.assertTrue(mps.mediaContainer.containsMediaElement(mps.media));
-
- mps.media = new VideoElement();
-
- Assert.assertEquals(mps.media, mps.mediaPlayer.media);
- Assert.assertTrue(mps.mediaContainer.containsMediaElement(mps.media));
- Assert.assertTrue(mps.media is VideoElement);
- }
-
- [Test]
- public function testResource():void
- {
- var mps:MediaPlayerSprite = new MediaPlayerSprite();
-
- var resource:URLResource = new URLResource("http://example.com/video.flv");
-
- mps.resource = resource;
-
- Assert.assertEquals(mps.resource, resource);
- Assert.assertNotNull(mps.media);
- Assert.assertEquals(mps.media, mps.mediaPlayer.media);
-
- }
-
- [Test]
- public function testScaleMode():void
- {
- var mps:MediaPlayerSprite = new MediaPlayerSprite();
-
- Assert.assertEquals(mps.scaleMode, ScaleMode.LETTERBOX);
-
- mps.media = new VideoElement();
-
- Assert.assertEquals(mps.scaleMode, ScaleMode.LETTERBOX);
-
- var layout:LayoutMetadata = mps.media.getMetadata(LayoutMetadata.LAYOUT_NAMESPACE) as LayoutMetadata;
-
- Assert.assertEquals(layout.scaleMode, mps.scaleMode, ScaleMode.LETTERBOX);
-
- mps.scaleMode = ScaleMode.NONE;
-
- Assert.assertEquals(layout.scaleMode, mps.scaleMode, ScaleMode.NONE);
-
-
- //Make sure layout is preserved if already set.
- var element:MediaElement = new VideoElement();
- layout = new LayoutMetadata()
- element.addMetadata(LayoutMetadata.LAYOUT_NAMESPACE, layout);
- layout.percentWidth = 50;
- layout.percentHeight = 50;
- layout.percentX = 20;
- layout.percentY = 20;
- layout.scaleMode = ScaleMode.STRETCH;
-
- mps = new MediaPlayerSprite();
-
- mps.media = element;
-
- Assert.assertEquals(mps.scaleMode, ScaleMode.LETTERBOX);
-
- Assert.assertEquals(mps.media.getMetadata(LayoutMetadata.LAYOUT_NAMESPACE), layout);
-
- }
-
- [Test]
- public function testLayout():void
- {
- var mps:MediaPlayerSprite = new MediaPlayerSprite();
-
- mps.media = new VideoElement();
-
- mps.width = 200;
- mps.height = 200;
-
- Assert.assertEquals(mps.mediaContainer.width, mps.width);
- Assert.assertEquals(mps.mediaContainer.height, mps.height);
-
- mps.width = 400;
- mps.height = 400;
-
- Assert.assertEquals(mps.mediaContainer.width, mps.width);
- Assert.assertEquals(mps.mediaContainer.height, mps.height);
- }
- }
+package org.osmf.media
+{
+ import flexunit.framework.Assert;
+
+ import org.osmf.containers.MediaContainer;
+ import org.osmf.elements.AudioElement;
+ import org.osmf.elements.VideoElement;
+ import org.osmf.layout.LayoutMetadata;
+ import org.osmf.layout.ScaleMode;
+
+ public class TestMediaPlayerSprite
+ {
+ [Test]
+ public function testConstructor():void
+ {
+ var container:MediaContainer = new MediaContainer();
+ var player:MediaPlayer = new MediaPlayer();
+ var factory:MediaFactory = new MediaFactory();
+
+ var mps:MediaPlayerSprite = new MediaPlayerSprite(player, container, factory);
+ Assert.assertEquals(mps.mediaPlayer, player);
+ Assert.assertEquals(mps.mediaContainer, container);
+ Assert.assertEquals(mps.mediaFactory, factory);
+
+ mps = new MediaPlayerSprite();
+ Assert.assertNotNull(mps.mediaPlayer);
+ Assert.assertNotNull(mps.mediaContainer);
+ Assert.assertNotNull(mps.mediaFactory);
+
+ player.media = new AudioElement();
+
+ mps = new MediaPlayerSprite(player);
+ Assert.assertTrue(mps.mediaContainer.containsMediaElement(player.media));
+ Assert.assertEquals(mps.media, player.media);
+ }
+
+ [Test]
+ public function testMedia():void
+ {
+ var mps:MediaPlayerSprite = new MediaPlayerSprite();
+
+ Assert.assertNull(mps.media);
+ Assert.assertNull(mps.mediaPlayer.media);
+
+ mps.mediaPlayer.media = new AudioElement();
+
+ Assert.assertEquals(mps.media, mps.mediaPlayer.media);
+ Assert.assertTrue(mps.mediaContainer.containsMediaElement(mps.media));
+
+ mps.media = new VideoElement();
+
+ Assert.assertEquals(mps.media, mps.mediaPlayer.media);
+ Assert.assertTrue(mps.mediaContainer.containsMediaElement(mps.media));
+ Assert.assertTrue(mps.media is VideoElement);
+ }
+
+ [Test]
+ public function testResource():void
+ {
+ var mps:MediaPlayerSprite = new MediaPlayerSprite();
+
+ var resource:URLResource = new URLResource("http://example.com/video.flv");
+
+ mps.resource = resource;
+
+ Assert.assertEquals(mps.resource, resource);
+ Assert.assertNotNull(mps.media);
+ Assert.assertEquals(mps.media, mps.mediaPlayer.media);
+
+ }
+
+ [Test]
+ public function testScaleMode():void
+ {
+ var mps:MediaPlayerSprite = new MediaPlayerSprite();
+
+ Assert.assertEquals(mps.scaleMode, ScaleMode.LETTERBOX);
+
+ mps.media = new VideoElement();
+
+ Assert.assertEquals(mps.scaleMode, ScaleMode.LETTERBOX);
+
+ var layout:LayoutMetadata = mps.media.getMetadata(LayoutMetadata.LAYOUT_NAMESPACE) as LayoutMetadata;
+
+ Assert.assertEquals(layout.scaleMode, mps.scaleMode, ScaleMode.LETTERBOX);
+
+ mps.scaleMode = ScaleMode.NONE;
+
+ Assert.assertEquals(layout.scaleMode, mps.scaleMode, ScaleMode.NONE);
+
+
+ //Make sure layout is preserved if already set.
+ var element:MediaElement = new VideoElement();
+ layout = new LayoutMetadata()
+ element.addMetadata(LayoutMetadata.LAYOUT_NAMESPACE, layout);
+ layout.percentWidth = 50;
+ layout.percentHeight = 50;
+ layout.percentX = 20;
+ layout.percentY = 20;
+ layout.scaleMode = ScaleMode.STRETCH;
+
+ mps = new MediaPlayerSprite();
+
+ mps.media = element;
+
+ Assert.assertEquals(mps.scaleMode, ScaleMode.LETTERBOX);
+
+ Assert.assertEquals(mps.media.getMetadata(LayoutMetadata.LAYOUT_NAMESPACE), layout);
+
+ }
+
+ [Test]
+ public function testLayout():void
+ {
+ var mps:MediaPlayerSprite = new MediaPlayerSprite();
+
+ mps.media = new VideoElement();
+
+ mps.width = 200;
+ mps.height = 200;
+
+ Assert.assertEquals(mps.mediaContainer.width, mps.width);
+ Assert.assertEquals(mps.mediaContainer.height, mps.height);
+
+ mps.width = 400;
+ mps.height = 400;
+
+ Assert.assertEquals(mps.mediaContainer.width, mps.width);
+ Assert.assertEquals(mps.mediaContainer.height, mps.height);
+ }
+ }
}
\ No newline at end of file
diff --git a/lib/osmf/framework/OSMFTest/src/org/osmf/media/TestMediaTraitResolver.as b/lib/osmf/framework/OSMFTest/src/org/osmf/media/TestMediaTraitResolver.as
index 1f94b5a..f192be6 100644
--- a/lib/osmf/framework/OSMFTest/src/org/osmf/media/TestMediaTraitResolver.as
+++ b/lib/osmf/framework/OSMFTest/src/org/osmf/media/TestMediaTraitResolver.as
@@ -1,39 +1,39 @@
-/*****************************************************
-*
-* Copyright 2009 Adobe Systems Incorporated. All Rights Reserved.
-*
-*****************************************************
-* The contents of this file are subject to the Mozilla Public License
-* Version 1.1 (the "License"); you may not use this file except in
-* compliance with the License. You may obtain a copy of the License at
-* http://www.mozilla.org/MPL/
-*
-* Software distributed under the License is distributed on an "AS IS"
-* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
-* License for the specific language governing rights and limitations
-* under the License.
-*
-*
-* The Initial Developer of the Original Code is Adobe Systems Incorporated.
-* Portions created by Adobe Systems Incorporated are Copyright (C) 2009 Adobe Systems
-* Incorporated. All Rights Reserved.
-*
-*****************************************************/
-package org.osmf.media
-{
- import org.osmf.traits.MediaTraitBase;
-
- public class TestMediaTraitResolver extends MediaTraitResolverBaseTestCase
- {
- override public function constructResolver(type:String, traitOfType:MediaTraitBase):MediaTraitResolver
- {
- return new MediaTraitResolver(type) as MediaTraitResolver;
- }
-
- [Test]
- public function test1():void
- {
-
- }
- }
+/*****************************************************
+*
+* Copyright 2009 Adobe Systems Incorporated. All Rights Reserved.
+*
+*****************************************************
+* The contents of this file are subject to the Mozilla Public License
+* Version 1.1 (the "License"); you may not use this file except in
+* compliance with the License. You may obtain a copy of the License at
+* http://www.mozilla.org/MPL/
+*
+* Software distributed under the License is distributed on an "AS IS"
+* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+* License for the specific language governing rights and limitations
+* under the License.
+*
+*
+* The Initial Developer of the Original Code is Adobe Systems Incorporated.
+* Portions created by Adobe Systems Incorporated are Copyright (C) 2009 Adobe Systems
+* Incorporated. All Rights Reserved.
+*
+*****************************************************/
+package org.osmf.media
+{
+ import org.osmf.traits.MediaTraitBase;
+
+ public class TestMediaTraitResolver extends MediaTraitResolverBaseTestCase
+ {
+ override public function constructResolver(type:String, traitOfType:MediaTraitBase):MediaTraitResolver
+ {
+ return new MediaTraitResolver(type) as MediaTraitResolver;
+ }
+
+ [Test]
+ public function test1():void
+ {
+
+ }
+ }
}
\ No newline at end of file
diff --git a/lib/osmf/framework/OSMFTest/src/org/osmf/media/pluginClasses/TestPluginManager.as b/lib/osmf/framework/OSMFTest/src/org/osmf/media/pluginClasses/TestPluginManager.as
index 165ef9c..08adb1c 100644
--- a/lib/osmf/framework/OSMFTest/src/org/osmf/media/pluginClasses/TestPluginManager.as
+++ b/lib/osmf/framework/OSMFTest/src/org/osmf/media/pluginClasses/TestPluginManager.as
@@ -171,12 +171,7 @@ package org.osmf.media.pluginClasses
[Test]
public function testLoadPluginWithDifferentVersions():void
- {
- // Note: This test will need updating any time the framework
- // version number changes. I've added the following Assert.assertion
- // to make this explicit.
- Assert.assertTrue(Version.version == "1.6");
-
+ {
// First number is minimum supported framework version.
// Second number is plugin's framework version.
@@ -185,17 +180,17 @@ package org.osmf.media.pluginClasses
assertPluginHasValidVersion("0.9", "0.95", true);
// But not newer plugins.
- assertPluginHasValidVersion("0.9", "1.9", false);
+ assertPluginHasValidVersion("0.9", "99.9", false);
// And we can't load older plugins if their version is less
// than the minimum.
assertPluginHasValidVersion("0.95", "0.9", false);
assertPluginHasValidVersion("0.95", "0.95", true);
- assertPluginHasValidVersion("0.95", "1.9", false);
+ assertPluginHasValidVersion("0.95", "99.9", false);
assertPluginHasValidVersion("1.1", "0.9", false);
assertPluginHasValidVersion("1.1", "0.95", false);
- assertPluginHasValidVersion("1.1", "1.9", false);
+ assertPluginHasValidVersion("1.1", "99.9", false);
// Verify we take the number of digits in the minor version
// into account.
diff --git a/lib/osmf/framework/OSMFTest/src/org/osmf/metadata/TestCuePoint.as b/lib/osmf/framework/OSMFTest/src/org/osmf/metadata/TestCuePoint.as
index 0db98da..509868b 100644
--- a/lib/osmf/framework/OSMFTest/src/org/osmf/metadata/TestCuePoint.as
+++ b/lib/osmf/framework/OSMFTest/src/org/osmf/metadata/TestCuePoint.as
@@ -1,47 +1,47 @@
-/*****************************************************
-*
-* Copyright 2009 Akamai Technologies, Inc. All Rights Reserved.
-*
-*****************************************************
-* The contents of this file are subject to the Mozilla Public License
-* Version 1.1 (the "License"); you may not use this file except in
-* compliance with the License. You may obtain a copy of the License at
-* http://www.mozilla.org/MPL/
-*
-* Software distributed under the License is distributed on an "AS IS"
-* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
-* License for the specific language governing rights and limitations
-* under the License.
-*
-*
-* The Initial Developer of the Original Code is Akamai Technologies, Inc.
-* Portions created by Akamai Technologies, Inc. are Copyright (C) 2009 Akamai
-* Technologies, Inc. All Rights Reserved.
-*
-*****************************************************/
-package org.osmf.metadata
-{
- import flexunit.framework.Assert;
-
- public class TestCuePoint
- {
- [Test]
- public function testCuePoint():void
- {
- var params:Object = new Object();
- params["100"] = "a";
- params["101"] = "b";
- var cuePoint:CuePoint = new CuePoint(CuePointType.ACTIONSCRIPT, 120, "test cue point", params, 5);
-
- Assert.assertEquals(CuePointType.ACTIONSCRIPT, cuePoint.type);
- Assert.assertEquals(120, cuePoint.time);
- Assert.assertEquals("test cue point", cuePoint.name);
-
- params = cuePoint.parameters;
- Assert.assertEquals("a", params["100"]);
- Assert.assertEquals("b", params["101"]);
-
- Assert.assertEquals(5, cuePoint.duration);
- }
- }
-}
+/*****************************************************
+*
+* Copyright 2009 Akamai Technologies, Inc. All Rights Reserved.
+*
+*****************************************************
+* The contents of this file are subject to the Mozilla Public License
+* Version 1.1 (the "License"); you may not use this file except in
+* compliance with the License. You may obtain a copy of the License at
+* http://www.mozilla.org/MPL/
+*
+* Software distributed under the License is distributed on an "AS IS"
+* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+* License for the specific language governing rights and limitations
+* under the License.
+*
+*
+* The Initial Developer of the Original Code is Akamai Technologies, Inc.
+* Portions created by Akamai Technologies, Inc. are Copyright (C) 2009 Akamai
+* Technologies, Inc. All Rights Reserved.
+*
+*****************************************************/
+package org.osmf.metadata
+{
+ import flexunit.framework.Assert;
+
+ public class TestCuePoint
+ {
+ [Test]
+ public function testCuePoint():void
+ {
+ var params:Object = new Object();
+ params["100"] = "a";
+ params["101"] = "b";
+ var cuePoint:CuePoint = new CuePoint(CuePointType.ACTIONSCRIPT, 120, "test cue point", params, 5);
+
+ Assert.assertEquals(CuePointType.ACTIONSCRIPT, cuePoint.type);
+ Assert.assertEquals(120, cuePoint.time);
+ Assert.assertEquals("test cue point", cuePoint.name);
+
+ params = cuePoint.parameters;
+ Assert.assertEquals("a", params["100"]);
+ Assert.assertEquals("b", params["101"]);
+
+ Assert.assertEquals(5, cuePoint.duration);
+ }
+ }
+}
diff --git a/lib/osmf/framework/OSMFTest/src/org/osmf/metadata/TestTimelineMetadata.as b/lib/osmf/framework/OSMFTest/src/org/osmf/metadata/TestTimelineMetadata.as
index 3ce0440..37609f3 100644
--- a/lib/osmf/framework/OSMFTest/src/org/osmf/metadata/TestTimelineMetadata.as
+++ b/lib/osmf/framework/OSMFTest/src/org/osmf/metadata/TestTimelineMetadata.as
@@ -1,427 +1,427 @@
-/*****************************************************
-*
-* Copyright 2009 Akamai Technologies, Inc. All Rights Reserved.
-*
-*****************************************************
-* The contents of this file are subject to the Mozilla Public License
-* Version 1.1 (the "License"); you may not use this file except in
-* compliance with the License. You may obtain a copy of the License at
-* http://www.mozilla.org/MPL/
-*
-* Software distributed under the License is distributed on an "AS IS"
-* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
-* License for the specific language governing rights and limitations
-* under the License.
-*
-*
-* The Initial Developer of the Original Code is Akamai Technologies, Inc.
-* Portions created by Akamai Technologies, Inc. are Copyright (C) 2009 Akamai
-* Technologies, Inc. All Rights Reserved.
-*
-*****************************************************/
-package org.osmf.metadata
-{
- import __AS3__.vec.Vector;
-
- import flash.events.Event;
- import flash.events.EventDispatcher;
-
- import flexunit.framework.Assert;
-
- import org.osmf.elements.VideoElement;
- import org.osmf.events.LoadEvent;
- import org.osmf.events.MetadataEvent;
- import org.osmf.events.TimelineMetadataEvent;
- import org.osmf.media.MediaResourceBase;
- import org.osmf.media.URLResource;
- import org.osmf.net.NetLoader;
- import org.osmf.net.NetStreamLoadTrait;
- import org.osmf.netmocker.MockNetLoader;
- import org.osmf.traits.LoadState;
- import org.osmf.traits.LoadTrait;
- import org.osmf.traits.MediaTraitType;
- import org.osmf.traits.PlayTrait;
- import org.osmf.traits.SeekTrait;
- import org.osmf.traits.TimeTrait;
- import org.osmf.utils.DynamicMediaElement;
- import org.osmf.utils.NetFactory;
- import org.osmf.utils.TestConstants;
-
- public class TestTimelineMetadata
- {
- [Before]
- public function setUp():void
- {
- netFactory = new NetFactory();
- loader = netFactory.createNetLoader();
- createTemporalData();
- eventDispatcher = new EventDispatcher();
- }
-
- [After]
- public function tearDown():void
- {
- netFactory = null;
- loader = null;
- _testValues = null;
- eventDispatcher = null;
- }
-
- [Test(expects="ArgumentError")]
- public function testConstructorPassingNullArguments():void
- {
- var timelineMetadata:TimelineMetadata = new TimelineMetadata(null);
- }
-
- [Test]
- public function testConstructorPassingValidArguments():void
- {
- var metadata:TimelineMetadata = new TimelineMetadata(new VideoElement());
- Assert.assertTrue(metadata != null);
- }
-
- [Test]
- public function testAddValue():void
- {
- var metadata:TimelineMetadata = new TimelineMetadata(new VideoElement());
- metadata.addEventListener(MetadataEvent.VALUE_ADD, onAdd);
- var addCount:int = 0;
-
- for each(var value:TimelineMarker in _testValues)
- {
- metadata.addValue("" + value.time, value);
- }
- Assert.assertTrue(addCount == _testValues.length);
-
- // Values should be sorted by time when we get them back
- var numMarkers:int = metadata.keys.length
- var lastValue:Number = 0;
-
- for (var i:int = 0; i < numMarkers; i++)
- {
- var val:TimelineMarker = metadata.getMarkerAt(i);
- Assert.assertTrue(val.time > lastValue);
- lastValue = val.time;
- }
-
- // Test invalid values
- try
- {
- metadata.addValue(null, null);
-
- Assert.fail();
- }
- catch(err:ArgumentError)
- {
- }
-
- try
- {
- metadata.addValue("" + -100, new TimelineMarker(-100, -10));
-
- Assert.fail();
- }
- catch(err:ArgumentError)
- {
- }
-
- function onAdd(event:MetadataEvent):void
- {
- addCount++;
- Assert.assertTrue(event.value != null);
- }
- }
-
- [Test]
- public function testAddMarker():void
- {
- var metadata:TimelineMetadata = new TimelineMetadata(new VideoElement());
- metadata.addEventListener(TimelineMetadataEvent.MARKER_ADD, onAdd);
- var addCount:int = 0;
-
- for each (var value:TimelineMarker in _testValues)
- {
- metadata.addMarker(value);
- }
- Assert.assertTrue(addCount == _testValues.length);
-
- // Values should be sorted by time when we get them back
- var numMarkers:int = metadata.numMarkers;
- var lastValue:Number = 0;
-
- for (var i:int = 0; i < numMarkers; i++)
- {
- var val:TimelineMarker = metadata.getMarkerAt(i);
- Assert.assertTrue(val.time > lastValue);
- lastValue = val.time;
- }
-
- // Test invalid values
- try
- {
- metadata.addMarker(null);
-
- Assert.fail();
- }
- catch(err:ArgumentError)
- {
- }
-
- try
- {
- metadata.addMarker(new TimelineMarker(-100, -10));
-
- Assert.fail();
- }
- catch(err:ArgumentError)
- {
- }
-
- function onAdd(event:TimelineMetadataEvent):void
- {
- addCount++;
- Assert.assertTrue(event.marker != null);
- }
- }
-
- [Test]
- public function testRemoveValue():void
- {
- var metadata:TimelineMetadata = new TimelineMetadata(new VideoElement());
- metadata.addEventListener(MetadataEvent.VALUE_REMOVE, onRemove);
- var removeCount:int = 0;
-
- Assert.assertTrue(metadata.removeValue("" + 3) == null);
-
- for each(var value:TimelineMarker in _testValues)
- {
- metadata.addValue("" + value.time, value);
- }
- Assert.assertTrue(removeCount == 0);
-
- var result:* = metadata.removeValue("" + 3);
- Assert.assertTrue(result != null);
- Assert.assertTrue(result is TimelineMarker);
- Assert.assertTrue(TimelineMarker(result).time == 3);
- Assert.assertTrue(TimelineMarker(result).duration == 1);
- Assert.assertTrue(removeCount == 1);
-
- Assert.assertTrue(metadata.removeValue("" + 3) == null);
- Assert.assertTrue(metadata.removeValue("" + 2.8) == null);
- Assert.assertTrue(removeCount == 1);
-
- // Test invalid values
- try
- {
- metadata.removeValue(null);
-
- Assert.fail();
- }
- catch(err:ArgumentError)
- {
- }
-
- function onRemove(event:MetadataEvent):void
- {
- removeCount++;
- Assert.assertTrue(event.value != null);
- }
- }
-
- [Test]
- public function testRemoveMarker():void
- {
- var metadata:TimelineMetadata = new TimelineMetadata(new VideoElement());
- metadata.addEventListener(TimelineMetadataEvent.MARKER_REMOVE, onRemove);
- var removeCount:int = 0;
-
- Assert.assertTrue(metadata.removeMarker(new TimelineMarker(3)) == null);
-
- for each (var value:TimelineMarker in _testValues)
- {
- metadata.addMarker(value);
- }
- Assert.assertTrue(removeCount == 0);
-
- var result:TimelineMarker = metadata.removeMarker(new TimelineMarker(3));
- Assert.assertTrue(result != null);
- Assert.assertTrue(result.time == 3);
- Assert.assertTrue(result.duration == 1);
- Assert.assertTrue(removeCount == 1);
-
- Assert.assertTrue(metadata.removeMarker(new TimelineMarker(3)) == null);
- Assert.assertTrue(metadata.removeMarker(new TimelineMarker(2.8)) == null);
- Assert.assertTrue(removeCount == 1);
-
- // Test invalid values
- try
- {
- metadata.removeMarker(null);
-
- Assert.fail();
- }
- catch(err:ArgumentError)
- {
- }
-
- function onRemove(event:TimelineMetadataEvent):void
- {
- removeCount++;
- Assert.assertTrue(event.marker != null);
- }
- }
-
- [Test]
- public function testGetValue():void
- {
- var metadata:TimelineMetadata = new TimelineMetadata(new VideoElement());
-
- metadata.addValue("" + 500, new TimelineMarker(500, 5));
- metadata.addValue("" + 300, new TimelineMarker(300));
- metadata.addValue("" + 400, new TimelineMarker(400, 2));
-
- Assert.assertTrue(TimelineMarker(metadata.getValue("" + 500)).time == 500);
- Assert.assertTrue(TimelineMarker(metadata.getValue("" + 500)).duration == 5);
- Assert.assertTrue(TimelineMarker(metadata.getValue("" + 300)).time == 300);
- Assert.assertTrue(isNaN(TimelineMarker(metadata.getValue("" + 300)).duration));
- Assert.assertTrue(TimelineMarker(metadata.getValue("" + 400)).time == 400);
- Assert.assertTrue(TimelineMarker(metadata.getValue("" + 400)).duration == 2);
-
- Assert.assertNull(metadata.getValue("" + 123));
- Assert.assertNull(metadata.getValue("foo"));
-
- try
- {
- metadata.getValue(null);
-
- Assert.fail();
- }
- catch(err:ArgumentError)
- {
- }
- }
-
- [Test]
- public function testGetMarkerAt():void
- {
- var metadata:TimelineMetadata = new TimelineMetadata(new VideoElement());
-
- metadata.addMarker(new TimelineMarker(500, 5));
- metadata.addMarker(new TimelineMarker(300));
- metadata.addMarker(new TimelineMarker(400, 2));
-
- Assert.assertTrue(metadata.numMarkers == 3);
- Assert.assertTrue(metadata.getMarkerAt(0).time == 300);
- Assert.assertTrue(isNaN(metadata.getMarkerAt(0).duration));
- Assert.assertTrue(metadata.getMarkerAt(1).time == 400);
- Assert.assertTrue(metadata.getMarkerAt(1).duration == 2);
- Assert.assertTrue(metadata.getMarkerAt(2).time == 500);
- Assert.assertTrue(metadata.getMarkerAt(2).duration == 5);
-
- Assert.assertNull(metadata.getMarkerAt(-5));
- Assert.assertNull(metadata.getMarkerAt(3));
- }
-
- [Test]
- public function testRemovingATrait():void
- {
- var mediaElement:DynamicMediaElement = createDynamicMediaElement();
-
- var metadata:TimelineMetadata = new TimelineMetadata(mediaElement);
-
- for each (var value:TimelineMarker in _testValues)
- {
- metadata.addMarker(value);
- }
-
- var loadTrait:LoadTrait = mediaElement.getTrait(MediaTraitType.LOAD) as LoadTrait;
- Assert.assertTrue(loadTrait != null);
- loadTrait.load();
- Assert.assertTrue(loadTrait.loadState == LoadState.READY);
-
- var playTrait:PlayTrait = mediaElement.getTrait(MediaTraitType.PLAY) as PlayTrait;
- Assert.assertTrue(playTrait != null);
- playTrait.play();
-
- var timeTrait:TimeTrait = mediaElement.getTrait(MediaTraitType.TIME) as TimeTrait;
- Assert.assertTrue(timeTrait != null);
-
- var seekTrait:SeekTrait = mediaElement.getTrait(MediaTraitType.SEEK) as SeekTrait;
- Assert.assertTrue(seekTrait != null);
-
- // Remove the traits while playing
- mediaElement.doRemoveTrait(MediaTraitType.SEEK);
- mediaElement.doRemoveTrait(MediaTraitType.PLAY);
- mediaElement.doRemoveTrait(MediaTraitType.TIME);
- }
-
- private function createTemporalData():void
- {
- _testValues = new Vector.();
-
- _testValues.push(new TimelineMarker(3.5, 1));
- _testValues.push(new TimelineMarker(1));
- _testValues.push(new TimelineMarker(3, 0));
- _testValues.push(new TimelineMarker(2));
- _testValues.push(new TimelineMarker(2.5, 1));
-
- // Add a few duplicates.
- _testValues.push(new TimelineMarker(1, 1));
- _testValues.push(new TimelineMarker(3, 1));
- }
-
-
- private function createMediaElement():VideoElement
- {
- if (loader is MockNetLoader)
- {
- // Give our mock loader an arbitrary duration and size to ensure
- // we get metadata.
- MockNetLoader(loader).netStreamExpectedDuration = TestConstants.REMOTE_PROGRESSIVE_VIDEO_EXPECTED_DURATION;
- MockNetLoader(loader).netStreamExpectedWidth = TestConstants.REMOTE_PROGRESSIVE_VIDEO_EXPECTED_WIDTH;
- MockNetLoader(loader).netStreamExpectedHeight = TestConstants.REMOTE_PROGRESSIVE_VIDEO_EXPECTED_HEIGHT;
- }
-
- return new VideoElement(null, loader);
- }
-
- private function createDynamicMediaElement():DynamicMediaElement
- {
- if (loader is MockNetLoader)
- {
- // Give our mock loader an arbitrary duration and size to ensure
- // we get metadata.
- MockNetLoader(loader).netStreamExpectedDuration = TestConstants.REMOTE_PROGRESSIVE_VIDEO_EXPECTED_DURATION;
- MockNetLoader(loader).netStreamExpectedWidth = TestConstants.REMOTE_PROGRESSIVE_VIDEO_EXPECTED_WIDTH;
- MockNetLoader(loader).netStreamExpectedHeight = TestConstants.REMOTE_PROGRESSIVE_VIDEO_EXPECTED_HEIGHT;
- }
-
- var elem:DynamicMediaElement = new DynamicMediaElement([ MediaTraitType.PLAY,
- MediaTraitType.SEEK, MediaTraitType.TIME ],
- loader, resourceForMediaElement);
- elem.doAddTrait(MediaTraitType.LOAD, new NetStreamLoadTrait(loader, resourceForMediaElement));
- return elem;
- }
-
- private function mustReceiveEvent(event:Event):void
- {
- // Placeholder to ensure an event is received.
- }
-
- private function get resourceForMediaElement():MediaResourceBase
- {
- // Use a valid URL so that the tests will pass if we use
- // a real NetLoader rather than a MockNetLoader.
- return new URLResource(TestConstants.REMOTE_PROGRESSIVE_VIDEO);
- }
-
- private static const TOLERANCE:Number = .25;
- private static const TIMEOUT:Number = 9000;
-
- private var _testValues:Vector.;
-
- private var netFactory:NetFactory;
- private var loader:NetLoader;
- private var eventDispatcher:EventDispatcher;
- }
-}
+/*****************************************************
+*
+* Copyright 2009 Akamai Technologies, Inc. All Rights Reserved.
+*
+*****************************************************
+* The contents of this file are subject to the Mozilla Public License
+* Version 1.1 (the "License"); you may not use this file except in
+* compliance with the License. You may obtain a copy of the License at
+* http://www.mozilla.org/MPL/
+*
+* Software distributed under the License is distributed on an "AS IS"
+* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+* License for the specific language governing rights and limitations
+* under the License.
+*
+*
+* The Initial Developer of the Original Code is Akamai Technologies, Inc.
+* Portions created by Akamai Technologies, Inc. are Copyright (C) 2009 Akamai
+* Technologies, Inc. All Rights Reserved.
+*
+*****************************************************/
+package org.osmf.metadata
+{
+ import __AS3__.vec.Vector;
+
+ import flash.events.Event;
+ import flash.events.EventDispatcher;
+
+ import flexunit.framework.Assert;
+
+ import org.osmf.elements.VideoElement;
+ import org.osmf.events.LoadEvent;
+ import org.osmf.events.MetadataEvent;
+ import org.osmf.events.TimelineMetadataEvent;
+ import org.osmf.media.MediaResourceBase;
+ import org.osmf.media.URLResource;
+ import org.osmf.net.NetLoader;
+ import org.osmf.net.NetStreamLoadTrait;
+ import org.osmf.netmocker.MockNetLoader;
+ import org.osmf.traits.LoadState;
+ import org.osmf.traits.LoadTrait;
+ import org.osmf.traits.MediaTraitType;
+ import org.osmf.traits.PlayTrait;
+ import org.osmf.traits.SeekTrait;
+ import org.osmf.traits.TimeTrait;
+ import org.osmf.utils.DynamicMediaElement;
+ import org.osmf.utils.NetFactory;
+ import org.osmf.utils.TestConstants;
+
+ public class TestTimelineMetadata
+ {
+ [Before]
+ public function setUp():void
+ {
+ netFactory = new NetFactory();
+ loader = netFactory.createNetLoader();
+ createTemporalData();
+ eventDispatcher = new EventDispatcher();
+ }
+
+ [After]
+ public function tearDown():void
+ {
+ netFactory = null;
+ loader = null;
+ _testValues = null;
+ eventDispatcher = null;
+ }
+
+ [Test(expects="ArgumentError")]
+ public function testConstructorPassingNullArguments():void
+ {
+ var timelineMetadata:TimelineMetadata = new TimelineMetadata(null);
+ }
+
+ [Test]
+ public function testConstructorPassingValidArguments():void
+ {
+ var metadata:TimelineMetadata = new TimelineMetadata(new VideoElement());
+ Assert.assertTrue(metadata != null);
+ }
+
+ [Test]
+ public function testAddValue():void
+ {
+ var metadata:TimelineMetadata = new TimelineMetadata(new VideoElement());
+ metadata.addEventListener(MetadataEvent.VALUE_ADD, onAdd);
+ var addCount:int = 0;
+
+ for each(var value:TimelineMarker in _testValues)
+ {
+ metadata.addValue("" + value.time, value);
+ }
+ Assert.assertTrue(addCount == _testValues.length);
+
+ // Values should be sorted by time when we get them back
+ var numMarkers:int = metadata.keys.length
+ var lastValue:Number = 0;
+
+ for (var i:int = 0; i < numMarkers; i++)
+ {
+ var val:TimelineMarker = metadata.getMarkerAt(i);
+ Assert.assertTrue(val.time > lastValue);
+ lastValue = val.time;
+ }
+
+ // Test invalid values
+ try
+ {
+ metadata.addValue(null, null);
+
+ Assert.fail();
+ }
+ catch(err:ArgumentError)
+ {
+ }
+
+ try
+ {
+ metadata.addValue("" + -100, new TimelineMarker(-100, -10));
+
+ Assert.fail();
+ }
+ catch(err:ArgumentError)
+ {
+ }
+
+ function onAdd(event:MetadataEvent):void
+ {
+ addCount++;
+ Assert.assertTrue(event.value != null);
+ }
+ }
+
+ [Test]
+ public function testAddMarker():void
+ {
+ var metadata:TimelineMetadata = new TimelineMetadata(new VideoElement());
+ metadata.addEventListener(TimelineMetadataEvent.MARKER_ADD, onAdd);
+ var addCount:int = 0;
+
+ for each (var value:TimelineMarker in _testValues)
+ {
+ metadata.addMarker(value);
+ }
+ Assert.assertTrue(addCount == _testValues.length);
+
+ // Values should be sorted by time when we get them back
+ var numMarkers:int = metadata.numMarkers;
+ var lastValue:Number = 0;
+
+ for (var i:int = 0; i < numMarkers; i++)
+ {
+ var val:TimelineMarker = metadata.getMarkerAt(i);
+ Assert.assertTrue(val.time > lastValue);
+ lastValue = val.time;
+ }
+
+ // Test invalid values
+ try
+ {
+ metadata.addMarker(null);
+
+ Assert.fail();
+ }
+ catch(err:ArgumentError)
+ {
+ }
+
+ try
+ {
+ metadata.addMarker(new TimelineMarker(-100, -10));
+
+ Assert.fail();
+ }
+ catch(err:ArgumentError)
+ {
+ }
+
+ function onAdd(event:TimelineMetadataEvent):void
+ {
+ addCount++;
+ Assert.assertTrue(event.marker != null);
+ }
+ }
+
+ [Test]
+ public function testRemoveValue():void
+ {
+ var metadata:TimelineMetadata = new TimelineMetadata(new VideoElement());
+ metadata.addEventListener(MetadataEvent.VALUE_REMOVE, onRemove);
+ var removeCount:int = 0;
+
+ Assert.assertTrue(metadata.removeValue("" + 3) == null);
+
+ for each(var value:TimelineMarker in _testValues)
+ {
+ metadata.addValue("" + value.time, value);
+ }
+ Assert.assertTrue(removeCount == 0);
+
+ var result:* = metadata.removeValue("" + 3);
+ Assert.assertTrue(result != null);
+ Assert.assertTrue(result is TimelineMarker);
+ Assert.assertTrue(TimelineMarker(result).time == 3);
+ Assert.assertTrue(TimelineMarker(result).duration == 1);
+ Assert.assertTrue(removeCount == 1);
+
+ Assert.assertTrue(metadata.removeValue("" + 3) == null);
+ Assert.assertTrue(metadata.removeValue("" + 2.8) == null);
+ Assert.assertTrue(removeCount == 1);
+
+ // Test invalid values
+ try
+ {
+ metadata.removeValue(null);
+
+ Assert.fail();
+ }
+ catch(err:ArgumentError)
+ {
+ }
+
+ function onRemove(event:MetadataEvent):void
+ {
+ removeCount++;
+ Assert.assertTrue(event.value != null);
+ }
+ }
+
+ [Test]
+ public function testRemoveMarker():void
+ {
+ var metadata:TimelineMetadata = new TimelineMetadata(new VideoElement());
+ metadata.addEventListener(TimelineMetadataEvent.MARKER_REMOVE, onRemove);
+ var removeCount:int = 0;
+
+ Assert.assertTrue(metadata.removeMarker(new TimelineMarker(3)) == null);
+
+ for each (var value:TimelineMarker in _testValues)
+ {
+ metadata.addMarker(value);
+ }
+ Assert.assertTrue(removeCount == 0);
+
+ var result:TimelineMarker = metadata.removeMarker(new TimelineMarker(3));
+ Assert.assertTrue(result != null);
+ Assert.assertTrue(result.time == 3);
+ Assert.assertTrue(result.duration == 1);
+ Assert.assertTrue(removeCount == 1);
+
+ Assert.assertTrue(metadata.removeMarker(new TimelineMarker(3)) == null);
+ Assert.assertTrue(metadata.removeMarker(new TimelineMarker(2.8)) == null);
+ Assert.assertTrue(removeCount == 1);
+
+ // Test invalid values
+ try
+ {
+ metadata.removeMarker(null);
+
+ Assert.fail();
+ }
+ catch(err:ArgumentError)
+ {
+ }
+
+ function onRemove(event:TimelineMetadataEvent):void
+ {
+ removeCount++;
+ Assert.assertTrue(event.marker != null);
+ }
+ }
+
+ [Test]
+ public function testGetValue():void
+ {
+ var metadata:TimelineMetadata = new TimelineMetadata(new VideoElement());
+
+ metadata.addValue("" + 500, new TimelineMarker(500, 5));
+ metadata.addValue("" + 300, new TimelineMarker(300));
+ metadata.addValue("" + 400, new TimelineMarker(400, 2));
+
+ Assert.assertTrue(TimelineMarker(metadata.getValue("" + 500)).time == 500);
+ Assert.assertTrue(TimelineMarker(metadata.getValue("" + 500)).duration == 5);
+ Assert.assertTrue(TimelineMarker(metadata.getValue("" + 300)).time == 300);
+ Assert.assertTrue(isNaN(TimelineMarker(metadata.getValue("" + 300)).duration));
+ Assert.assertTrue(TimelineMarker(metadata.getValue("" + 400)).time == 400);
+ Assert.assertTrue(TimelineMarker(metadata.getValue("" + 400)).duration == 2);
+
+ Assert.assertNull(metadata.getValue("" + 123));
+ Assert.assertNull(metadata.getValue("foo"));
+
+ try
+ {
+ metadata.getValue(null);
+
+ Assert.fail();
+ }
+ catch(err:ArgumentError)
+ {
+ }
+ }
+
+ [Test]
+ public function testGetMarkerAt():void
+ {
+ var metadata:TimelineMetadata = new TimelineMetadata(new VideoElement());
+
+ metadata.addMarker(new TimelineMarker(500, 5));
+ metadata.addMarker(new TimelineMarker(300));
+ metadata.addMarker(new TimelineMarker(400, 2));
+
+ Assert.assertTrue(metadata.numMarkers == 3);
+ Assert.assertTrue(metadata.getMarkerAt(0).time == 300);
+ Assert.assertTrue(isNaN(metadata.getMarkerAt(0).duration));
+ Assert.assertTrue(metadata.getMarkerAt(1).time == 400);
+ Assert.assertTrue(metadata.getMarkerAt(1).duration == 2);
+ Assert.assertTrue(metadata.getMarkerAt(2).time == 500);
+ Assert.assertTrue(metadata.getMarkerAt(2).duration == 5);
+
+ Assert.assertNull(metadata.getMarkerAt(-5));
+ Assert.assertNull(metadata.getMarkerAt(3));
+ }
+
+ [Test]
+ public function testRemovingATrait():void
+ {
+ var mediaElement:DynamicMediaElement = createDynamicMediaElement();
+
+ var metadata:TimelineMetadata = new TimelineMetadata(mediaElement);
+
+ for each (var value:TimelineMarker in _testValues)
+ {
+ metadata.addMarker(value);
+ }
+
+ var loadTrait:LoadTrait = mediaElement.getTrait(MediaTraitType.LOAD) as LoadTrait;
+ Assert.assertTrue(loadTrait != null);
+ loadTrait.load();
+ Assert.assertTrue(loadTrait.loadState == LoadState.READY);
+
+ var playTrait:PlayTrait = mediaElement.getTrait(MediaTraitType.PLAY) as PlayTrait;
+ Assert.assertTrue(playTrait != null);
+ playTrait.play();
+
+ var timeTrait:TimeTrait = mediaElement.getTrait(MediaTraitType.TIME) as TimeTrait;
+ Assert.assertTrue(timeTrait != null);
+
+ var seekTrait:SeekTrait = mediaElement.getTrait(MediaTraitType.SEEK) as SeekTrait;
+ Assert.assertTrue(seekTrait != null);
+
+ // Remove the traits while playing
+ mediaElement.doRemoveTrait(MediaTraitType.SEEK);
+ mediaElement.doRemoveTrait(MediaTraitType.PLAY);
+ mediaElement.doRemoveTrait(MediaTraitType.TIME);
+ }
+
+ private function createTemporalData():void
+ {
+ _testValues = new Vector.();
+
+ _testValues.push(new TimelineMarker(3.5, 1));
+ _testValues.push(new TimelineMarker(1));
+ _testValues.push(new TimelineMarker(3, 0));
+ _testValues.push(new TimelineMarker(2));
+ _testValues.push(new TimelineMarker(2.5, 1));
+
+ // Add a few duplicates.
+ _testValues.push(new TimelineMarker(1, 1));
+ _testValues.push(new TimelineMarker(3, 1));
+ }
+
+
+ private function createMediaElement():VideoElement
+ {
+ if (loader is MockNetLoader)
+ {
+ // Give our mock loader an arbitrary duration and size to ensure
+ // we get metadata.
+ MockNetLoader(loader).netStreamExpectedDuration = TestConstants.REMOTE_PROGRESSIVE_VIDEO_EXPECTED_DURATION;
+ MockNetLoader(loader).netStreamExpectedWidth = TestConstants.REMOTE_PROGRESSIVE_VIDEO_EXPECTED_WIDTH;
+ MockNetLoader(loader).netStreamExpectedHeight = TestConstants.REMOTE_PROGRESSIVE_VIDEO_EXPECTED_HEIGHT;
+ }
+
+ return new VideoElement(null, loader);
+ }
+
+ private function createDynamicMediaElement():DynamicMediaElement
+ {
+ if (loader is MockNetLoader)
+ {
+ // Give our mock loader an arbitrary duration and size to ensure
+ // we get metadata.
+ MockNetLoader(loader).netStreamExpectedDuration = TestConstants.REMOTE_PROGRESSIVE_VIDEO_EXPECTED_DURATION;
+ MockNetLoader(loader).netStreamExpectedWidth = TestConstants.REMOTE_PROGRESSIVE_VIDEO_EXPECTED_WIDTH;
+ MockNetLoader(loader).netStreamExpectedHeight = TestConstants.REMOTE_PROGRESSIVE_VIDEO_EXPECTED_HEIGHT;
+ }
+
+ var elem:DynamicMediaElement = new DynamicMediaElement([ MediaTraitType.PLAY,
+ MediaTraitType.SEEK, MediaTraitType.TIME ],
+ loader, resourceForMediaElement);
+ elem.doAddTrait(MediaTraitType.LOAD, new NetStreamLoadTrait(loader, resourceForMediaElement));
+ return elem;
+ }
+
+ private function mustReceiveEvent(event:Event):void
+ {
+ // Placeholder to ensure an event is received.
+ }
+
+ private function get resourceForMediaElement():MediaResourceBase
+ {
+ // Use a valid URL so that the tests will pass if we use
+ // a real NetLoader rather than a MockNetLoader.
+ return new URLResource(TestConstants.REMOTE_PROGRESSIVE_VIDEO);
+ }
+
+ private static const TOLERANCE:Number = .25;
+ private static const TIMEOUT:Number = 9000;
+
+ private var _testValues:Vector.;
+
+ private var netFactory:NetFactory;
+ private var loader:NetLoader;
+ private var eventDispatcher:EventDispatcher;
+ }
+}
diff --git a/lib/osmf/framework/OSMFTest/src/org/osmf/net/ABRTestUtils.as b/lib/osmf/framework/OSMFTest/src/org/osmf/net/ABRTestUtils.as
new file mode 100644
index 0000000..9f29184
--- /dev/null
+++ b/lib/osmf/framework/OSMFTest/src/org/osmf/net/ABRTestUtils.as
@@ -0,0 +1,65 @@
+package org.osmf.net
+{
+ import org.osmf.net.rules.RuleBase;
+
+ public class ABRTestUtils
+ {
+ // helper function to test whether two Vector. are equal
+ public static function equalNumberVectors(v:Vector., w:Vector.):Boolean
+ {
+ if (v == w)
+ {
+ return true;
+ }
+
+ if (v == null || w == null)
+ {
+ return false;
+ }
+
+ if (v.length != w.length)
+ {
+ return false;
+ }
+
+ for (var i:uint = 0; i < v.length; i++)
+ {
+ if (v[i] != w[i] && !(isNaN(v[i]) && isNaN(w[i])))
+ {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ // helper function to test whether two Vector. are equal
+ public static function equalRuleBaseVectors(v:Vector., w:Vector.):Boolean
+ {
+ if (v == w)
+ {
+ return true;
+ }
+
+ if (v == null || w == null)
+ {
+ return false;
+ }
+
+ if (v.length != w.length)
+ {
+ return false;
+ }
+
+ for (var i:uint = 0; i < v.length; i++)
+ {
+ if (v[i] != w[i])
+ {
+ return false;
+ }
+ }
+
+ return true;
+ }
+ }
+}
\ No newline at end of file
diff --git a/lib/osmf/framework/OSMFTest/src/org/osmf/net/NetStreamSwitcherMocker.as b/lib/osmf/framework/OSMFTest/src/org/osmf/net/NetStreamSwitcherMocker.as
new file mode 100644
index 0000000..e5b18fd
--- /dev/null
+++ b/lib/osmf/framework/OSMFTest/src/org/osmf/net/NetStreamSwitcherMocker.as
@@ -0,0 +1,75 @@
+/*****************************************************
+ *
+ * Copyright 2011 Adobe Systems Incorporated. All Rights Reserved.
+ *
+ *****************************************************
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ *
+ * The Initial Developer of the Original Code is Adobe Systems Incorporated.
+ * Portions created by Adobe Systems Incorporated are Copyright (C) 2011 Adobe Systems
+ * Incorporated. All Rights Reserved.
+ *
+ *****************************************************/
+package org.osmf.net
+{
+ import flash.net.NetStream;
+
+
+ public class NetStreamSwitcherMocker extends NetStreamSwitcher
+ {
+ public function NetStreamSwitcherMocker(netStream:NetStream, dsResource:DynamicStreamingResource)
+ {
+ super(netStream, dsResource);
+ }
+
+ override public function get currentIndex():uint
+ {
+ return _currentIndexMocker;
+ }
+
+ public function set currentIndex(value:uint):void
+ {
+ _currentIndexMocker = value;
+ }
+
+ override public function get actualIndex():int
+ {
+ return _actualIndexMocker;
+ }
+
+ public function set actualIndex(value:int):void
+ {
+ _actualIndexMocker = value;
+ }
+
+ override public function get switching():Boolean
+ {
+ return _switchingMocker;
+ }
+
+ public function set switching(value:Boolean):void
+ {
+ _switchingMocker = value;
+ }
+
+ override public function switchTo(index:int):void
+ {
+ lastSwitchIndex = index;
+ }
+
+ public var lastSwitchIndex:int = -1;
+
+ private var _currentIndexMocker:uint = 0;
+ private var _actualIndexMocker:int = 0;
+ private var _switchingMocker:Boolean = false;
+ }
+}
\ No newline at end of file
diff --git a/lib/osmf/framework/OSMFTest/src/org/osmf/net/TestSwitchManager.as b/lib/osmf/framework/OSMFTest/src/org/osmf/net/TestSwitchManager.as
new file mode 100644
index 0000000..c2171e3
--- /dev/null
+++ b/lib/osmf/framework/OSMFTest/src/org/osmf/net/TestSwitchManager.as
@@ -0,0 +1,1587 @@
+/*****************************************************
+ *
+ * Copyright 2011 Adobe Systems Incorporated. All Rights Reserved.
+ *
+ *****************************************************
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ *
+ * The Initial Developer of the Original Code is Adobe Systems Incorporated.
+ * Portions created by Adobe Systems Incorporated are Copyright (C) 2011 Adobe Systems
+ * Incorporated. All Rights Reserved.
+ *
+ *****************************************************/
+package org.osmf.net
+{
+ import flash.events.Event;
+ import flash.net.NetConnection;
+ import flash.net.NetStream;
+
+ import flexunit.framework.Assert;
+
+ import org.flexunit.asserts.assertEquals;
+ import org.flexunit.asserts.assertFalse;
+ import org.flexunit.asserts.assertNotNull;
+ import org.flexunit.asserts.assertNull;
+ import org.flexunit.asserts.assertStrictlyEquals;
+ import org.flexunit.asserts.assertTrue;
+ import org.osmf.events.HTTPStreamingEvent;
+ import org.osmf.events.QoSInfoEvent;
+ import org.osmf.net.httpstreaming.DefaultHTTPStreamingSwitchManager;
+ import org.osmf.net.metrics.ActualBitrateMetricMocker;
+ import org.osmf.net.metrics.AvailableQualityLevelsMetricMocker;
+ import org.osmf.net.metrics.BandwidthMetricMocker;
+ import org.osmf.net.metrics.DefaultMetricFactoryMocker;
+ import org.osmf.net.metrics.FragmentCountMetricMocker;
+ import org.osmf.net.metrics.MetricFactory;
+ import org.osmf.net.metrics.MetricRepository;
+ import org.osmf.net.metrics.MetricType;
+ import org.osmf.net.qos.FragmentDetails;
+ import org.osmf.net.qos.QoSInfo;
+ import org.osmf.net.qos.QoSInfoHistory;
+ import org.osmf.net.qos.QualityLevel;
+ import org.osmf.net.rules.Recommendation;
+ import org.osmf.net.rules.RuleBase;
+ import org.osmf.net.rules.RuleMocker;
+
+ public class TestSwitchManager
+ {
+ [Before]
+ public function setUp():void
+ {
+ var conn:NetConnection = new NetConnection();
+ conn.connect(null);
+ netStream = new NetStream(conn);
+ netStream.client = new NetClient();
+ qosInfoHistory = new QoSInfoHistory(netStream);
+ //just to make the metrics work if the metrics have not mocked the getters for the value
+ addQoSInfo(generateQoSInfo(mockTimestamp++, 150, 250, 350, 450, 550));
+
+ metricFactory = new DefaultMetricFactoryMocker(qosInfoHistory);
+ metricRepository = new MetricRepository(metricFactory);
+
+ qualityLevels = new Vector.();
+ for(var i:int = 0; i<5; i++)
+ qualityLevels.push( new QualityLevel(i, 150+100*i, "test" + (150+100*i)));
+
+ }
+
+ [After]
+ public function tearDown():void
+ {
+ }
+
+ [BeforeClass]
+ public static function setUpBeforeClass():void
+ {
+ }
+
+ [AfterClass]
+ public static function tearDownAfterClass():void
+ {
+ }
+
+ [Test]
+ public function testDefaultSwitchManagerInitWith3Rules():void
+ {
+ var ruleWeights:Vector. = new Vector.();
+ ruleWeights.push(0.7);
+ ruleWeights.push(0.2);
+ ruleWeights.push(0.1);
+
+ rules = new Vector.();
+
+ var dsResource:DynamicStreamingResource = new DynamicStreamingResource("http://example.com/vod");
+
+ rules.push(new RuleMocker(new Recommendation("rule1", 500, 1)));
+ rules.push(new RuleMocker(new Recommendation("rule2", 600, 1)));
+ rules.push(new RuleMocker(new Recommendation("rule3", 700, 1)));
+
+ switcher = new NetStreamSwitcherMocker(netStream, dsResource);
+
+ switchManager = new DefaultHTTPStreamingSwitchManager(netStream, switcher, metricRepository, null, true, rules, ruleWeights);
+
+ assertTrue(switchManager.autoSwitch);
+ assertEquals(3, switchManager.normalRuleWeights.length);
+ assertEquals(0.7, switchManager.normalRuleWeights[0]);
+ assertEquals(int.MAX_VALUE, switchManager.maxAllowedIndex);
+ assertEquals(0, switchManager.currentIndex);
+ assertEquals(12, switchManager.metricRepository.metricFactory.numItems);
+ assertEquals(0.85, switchManager.minReliability);
+ assertNull(switchManager.emergencyRules);
+ assertEquals(0, switchManager.actualIndex);
+ assertEquals(3, switchManager.normalRules.length);
+
+ assertTrue(ABRTestUtils.equalRuleBaseVectors(rules, switchManager.normalRules));
+
+ assertEquals(5, switchManager.minReliabilityRecordSize);
+ assertEquals(30, switchManager.maxReliabilityRecordSize);
+
+ assertEquals(0.9, switchManager.climbFactor);
+
+ assertEquals(1, switchManager.maxUpSwitchLimit);
+ assertEquals(2, switchManager.maxDownSwitchLimit);
+
+
+ }
+
+
+ [Test]
+ public function testDefaultSwitchManagerInitNonDefault():void
+ {
+ var ruleWeights:Vector. = new Vector.();
+ ruleWeights.push(0.7);
+ ruleWeights.push(0.2);
+ ruleWeights.push(0.1);
+
+ rules = new Vector.();
+
+ emergencyRules = new Vector.();
+
+ var dsResource:DynamicStreamingResource = new DynamicStreamingResource("http://example.com/vod");
+
+ rules.push(new RuleMocker(new Recommendation("rule1", 500, 1)));
+ rules.push(new RuleMocker(new Recommendation("rule2", 600, 1)));
+ rules.push(new RuleMocker(new Recommendation("rule3", 700, 1)));
+
+ emergencyRules.push(new RuleMocker(new Recommendation("emergencyrule1", 50, 1)));
+ emergencyRules.push(new RuleMocker(new Recommendation("emergencyrule2", 60, 1)));
+
+ switcher = new NetStreamSwitcherMocker(netStream, dsResource);
+
+ switchManager = new DefaultHTTPStreamingSwitchManager(netStream, switcher, metricRepository, emergencyRules, false, rules, ruleWeights, 0.89, 6, 16, 0.85, 3, 4);
+
+ assertFalse(switchManager.autoSwitch);
+ assertEquals(3, switchManager.normalRuleWeights.length);
+ assertEquals(0.7, switchManager.normalRuleWeights[0]);
+ assertEquals(int.MAX_VALUE, switchManager.maxAllowedIndex);
+ assertEquals(0, switchManager.currentIndex);
+ assertEquals(12 ,switchManager.metricRepository.metricFactory.numItems);
+ assertNotNull(switchManager.emergencyRules);
+ assertEquals(2, switchManager.emergencyRules.length);
+ assertTrue(ABRTestUtils.equalRuleBaseVectors(emergencyRules, switchManager.emergencyRules));
+
+ assertEquals(0, switchManager.actualIndex);
+ assertEquals(3, switchManager.normalRules.length);
+ assertTrue(ABRTestUtils.equalRuleBaseVectors(rules, switchManager.normalRules));
+
+ assertEquals(0.89, switchManager.minReliability);
+
+ assertEquals(6, switchManager.minReliabilityRecordSize);
+ assertEquals(16, switchManager.maxReliabilityRecordSize);
+
+ assertEquals(0.85, switchManager.climbFactor);
+
+ assertEquals(3, switchManager.maxUpSwitchLimit);
+ assertEquals(4, switchManager.maxDownSwitchLimit);
+
+ assertFalse(switchManager.autoSwitch);
+ }
+
+ [Test(expects = "ArgumentError")]
+ public function testDefaultSwitchManagerInitWithNullNetStream():void
+ {
+ var ruleWeights:Vector. = generateWeights(0.7, 0.2, 0.1);
+
+ rules = new Vector.();
+
+ var dsResource:DynamicStreamingResource = new DynamicStreamingResource("http://example.com/vod");
+
+ rules.push( new RuleMocker(new Recommendation("rule1", 500, 1)));
+ rules.push( new RuleMocker(new Recommendation("rule2", 600, 1)));
+ rules.push( new RuleMocker(new Recommendation("rule3", 700, 1)));
+
+ switcher = new NetStreamSwitcherMocker(netStream, dsResource);
+
+ switchManager = new DefaultHTTPStreamingSwitchManager(null, switcher, metricRepository, null, true, rules, ruleWeights);
+ }
+
+ [Test(expects = "ArgumentError")]
+ public function testDefaultSwitchManagerInitWithNullSwitcher():void
+ {
+ var ruleWeights:Vector. = generateWeights(0.7, 0.2, 0.1);
+
+ rules = new Vector.();
+
+ var dsResource:DynamicStreamingResource = new DynamicStreamingResource("http://example.com/vod");
+
+ rules.push( new RuleMocker(new Recommendation("rule1", 500, 1)));
+ rules.push( new RuleMocker(new Recommendation("rule2", 600, 1)));
+ rules.push( new RuleMocker(new Recommendation("rule3", 700, 1)));
+
+ switcher = new NetStreamSwitcherMocker(netStream, dsResource);
+
+ switchManager = new DefaultHTTPStreamingSwitchManager(netStream, null, metricRepository, null, true, rules, ruleWeights);
+ }
+
+ [Test(expects = "ArgumentError")]
+ public function testDefaultSwitchManagerInitWithNullMetricRepository():void
+ {
+ var ruleWeights:Vector. = generateWeights(0.7, 0.2, 0.1);
+
+ rules = new Vector.();
+
+ var dsResource:DynamicStreamingResource = new DynamicStreamingResource("http://example.com/vod");
+
+ rules.push( new RuleMocker(new Recommendation("rule1", 500, 1)));
+ rules.push( new RuleMocker(new Recommendation("rule2", 600, 1)));
+ rules.push( new RuleMocker(new Recommendation("rule3", 700, 1)));
+
+ switcher = new NetStreamSwitcherMocker(netStream, dsResource);
+
+ switchManager = new DefaultHTTPStreamingSwitchManager(netStream, switcher, null, null, true, rules, ruleWeights);
+ }
+
+ [Test(expects = "ArgumentError")]
+ public function testDefaultSwitchManagerInitWithNullRules():void
+ {
+ var ruleWeights:Vector. = generateWeights(0.7, 0.2, 0.1);
+
+ rules = new Vector.();
+
+ var dsResource:DynamicStreamingResource = new DynamicStreamingResource("http://example.com/vod");
+
+ rules.push( new RuleMocker(new Recommendation("rule1", 500, 1)));
+ rules.push( new RuleMocker(new Recommendation("rule2", 600, 1)));
+ rules.push( new RuleMocker(new Recommendation("rule3", 700, 1)));
+
+ switcher = new NetStreamSwitcherMocker(netStream, dsResource);
+
+ switchManager = new DefaultHTTPStreamingSwitchManager(netStream, switcher, metricRepository, null, true, null, ruleWeights);
+ }
+
+ [Test(expects = "ArgumentError")]
+ public function testDefaultSwitchManagerInitWithEmptyRulesAndRuleWeights():void
+ {
+ var ruleWeights:Vector. = new Vector.();
+
+ rules = new Vector.();
+
+ var dsResource:DynamicStreamingResource = new DynamicStreamingResource("http://example.com/vod");
+
+ switcher = new NetStreamSwitcherMocker(netStream, dsResource);
+
+ switchManager = new DefaultHTTPStreamingSwitchManager(netStream, switcher, metricRepository, null, true, rules, ruleWeights);
+ }
+
+ [Test(expects = "ArgumentError")]
+ public function testDefaultSwitchManagerInitWithNullRuleWeights():void
+ {
+ var ruleWeights:Vector. = generateWeights(0.7, 0.2, 0.1);
+
+ rules = new Vector.();
+
+ var dsResource:DynamicStreamingResource = new DynamicStreamingResource("http://example.com/vod");
+
+ rules.push( new RuleMocker(new Recommendation("rule1", 500, 1)));
+ rules.push( new RuleMocker(new Recommendation("rule2", 600, 1)));
+ rules.push( new RuleMocker(new Recommendation("rule3", 700, 1)));
+
+ switcher = new NetStreamSwitcherMocker(netStream, dsResource);
+
+ switchManager = new DefaultHTTPStreamingSwitchManager(netStream, switcher, metricRepository, null, true, rules, null);
+ }
+
+ [Test(expects = "ArgumentError")]
+ public function testDefaultSwitchManagerInitWithMinimumReliabilityNaN():void
+ {
+ var ruleWeights:Vector. = generateWeights(0.7, 0.2, 0.1);
+
+ rules = new Vector.();
+
+ var dsResource:DynamicStreamingResource = new DynamicStreamingResource("http://example.com/vod");
+
+ rules.push( new RuleMocker(new Recommendation("rule1", 500, 1)));
+ rules.push( new RuleMocker(new Recommendation("rule2", 600, 1)));
+ rules.push( new RuleMocker(new Recommendation("rule3", 700, 1)));
+
+ switcher = new NetStreamSwitcherMocker(netStream, dsResource);
+
+ switchManager = new DefaultHTTPStreamingSwitchManager(netStream, switcher, metricRepository, null, true, rules, null, NaN);
+ }
+
+ [Test(expects = "ArgumentError")]
+ public function testDefaultSwitchManagerInitWithNegativeMinimumReliability():void
+ {
+ var ruleWeights:Vector. = generateWeights(0.7, 0.2, 0.1);
+
+ rules = new Vector.();
+
+ var dsResource:DynamicStreamingResource = new DynamicStreamingResource("http://example.com/vod");
+
+ rules.push( new RuleMocker(new Recommendation("rule1", 500, 1)));
+ rules.push( new RuleMocker(new Recommendation("rule2", 600, 1)));
+ rules.push( new RuleMocker(new Recommendation("rule3", 700, 1)));
+
+ switcher = new NetStreamSwitcherMocker(netStream, dsResource);
+
+ switchManager = new DefaultHTTPStreamingSwitchManager(netStream, switcher, metricRepository, null, true, rules, ruleWeights, -0.1 );
+ }
+
+ [Test(expects = "ArgumentError")]
+ public function testDefaultSwitchManagerInitWithMinimumReliabilityGreaterThanOne():void
+ {
+ var ruleWeights:Vector. = generateWeights(0.7, 0.2, 0.1);
+
+ rules = new Vector.();
+
+ var dsResource:DynamicStreamingResource = new DynamicStreamingResource("http://example.com/vod");
+
+ rules.push( new RuleMocker(new Recommendation("rule1", 500, 1)));
+ rules.push( new RuleMocker(new Recommendation("rule2", 600, 1)));
+ rules.push( new RuleMocker(new Recommendation("rule3", 700, 1)));
+
+ switcher = new NetStreamSwitcherMocker(netStream, dsResource);
+
+ switchManager = new DefaultHTTPStreamingSwitchManager(netStream, switcher, metricRepository, null, true, rules, ruleWeights, 1.1);
+ }
+
+ [Test]
+ public function testDefaultSwitchManagerInitWithMinimumReliabilityOne():void
+ {
+ var ruleWeights:Vector. = generateWeights(0.7, 0.2, 0.1);
+
+ rules = new Vector.();
+
+ var dsResource:DynamicStreamingResource = new DynamicStreamingResource("http://example.com/vod");
+
+ rules.push( new RuleMocker(new Recommendation("rule1", 500, 1)));
+ rules.push( new RuleMocker(new Recommendation("rule2", 600, 1)));
+ rules.push( new RuleMocker(new Recommendation("rule3", 700, 1)));
+
+ switcher = new NetStreamSwitcherMocker(netStream, dsResource);
+
+ switchManager = new DefaultHTTPStreamingSwitchManager(netStream, switcher, metricRepository, null, true, rules, ruleWeights, 1);
+ assertEquals(1, switchManager.minReliability);
+
+ }
+
+ [Test]
+ public function testDefaultSwitchManagerInitWithMinimumReliabilityZero():void
+ {
+ var ruleWeights:Vector. = generateWeights(0.7, 0.2, 0.1);
+
+ rules = new Vector.();
+
+ var dsResource:DynamicStreamingResource = new DynamicStreamingResource("http://example.com/vod");
+
+ rules.push( new RuleMocker(new Recommendation("rule1", 500, 1)));
+ rules.push( new RuleMocker(new Recommendation("rule2", 600, 1)));
+ rules.push( new RuleMocker(new Recommendation("rule3", 700, 1)));
+
+ switcher = new NetStreamSwitcherMocker(netStream, dsResource);
+
+ switchManager = new DefaultHTTPStreamingSwitchManager(netStream, switcher, metricRepository, null, true, rules, ruleWeights, 0);
+ assertEquals(0, switchManager.minReliability);
+
+ }
+
+ public function testDefaultSwitchManagerInitWithIncorrectRecordSizeInterval():void
+ {
+ var ruleWeights:Vector. = generateWeights(0.7, 0.2, 0.1);
+
+ rules = new Vector.();
+
+ var dsResource:DynamicStreamingResource = new DynamicStreamingResource("http://example.com/vod");
+
+ rules.push( new RuleMocker(new Recommendation("rule1", 500, 1)));
+ rules.push( new RuleMocker(new Recommendation("rule2", 600, 1)));
+ rules.push( new RuleMocker(new Recommendation("rule3", 700, 1)));
+
+ switcher = new NetStreamSwitcherMocker(netStream, dsResource);
+
+ switchManager = new DefaultHTTPStreamingSwitchManager(netStream, switcher, metricRepository, null, true, rules, ruleWeights, 0.9, 20, 10);
+ assertEquals(20, switchManager.minReliabilityRecordSize);
+ assertEquals(20, switchManager.maxReliabilityRecordSize);
+ }
+
+ [Test(expects = "ArgumentError")]
+ public function testDefaultSwitchManagerInitWithIncorrectRecordSizeMinimum():void
+ {
+ var ruleWeights:Vector. = generateWeights(0.7, 0.2, 0.1);
+
+ rules = new Vector.();
+
+ var dsResource:DynamicStreamingResource = new DynamicStreamingResource("http://example.com/vod");
+
+ rules.push( new RuleMocker(new Recommendation("rule1", 500, 1)));
+ rules.push( new RuleMocker(new Recommendation("rule2", 600, 1)));
+ rules.push( new RuleMocker(new Recommendation("rule3", 700, 1)));
+
+ switcher = new NetStreamSwitcherMocker(netStream, dsResource);
+
+ switchManager = new DefaultHTTPStreamingSwitchManager(netStream, switcher, metricRepository, null, true, rules, ruleWeights, 0.9, 0.5, 1, 14);
+ }
+
+ [Test]
+ public function testDefaultSwitchManagerInitWithMinimumRecordInterval():void
+ {
+ var ruleWeights:Vector. = generateWeights(0.7, 0.2, 0.1);
+
+ rules = new Vector.();
+
+ var dsResource:DynamicStreamingResource = new DynamicStreamingResource("http://example.com/vod");
+
+ rules.push( new RuleMocker(new Recommendation("rule1", 500, 1)));
+ rules.push( new RuleMocker(new Recommendation("rule2", 600, 1)));
+ rules.push( new RuleMocker(new Recommendation("rule3", 700, 1)));
+
+ switcher = new NetStreamSwitcherMocker(netStream, dsResource);
+
+ switchManager = new DefaultHTTPStreamingSwitchManager(netStream, switcher, metricRepository, null, true, rules, ruleWeights, 0.9, 2, 2);
+
+ assertEquals(2, switchManager.maxReliabilityRecordSize);
+ assertEquals(2, switchManager.minReliabilityRecordSize);
+ }
+
+
+ public function testDefaultSwitchManagerInitWithZeroUpSwitchLimit():void
+ {
+ var ruleWeights:Vector. = generateWeights(0.7, 0.2, 0.1);
+
+ rules = new Vector.();
+
+ var dsResource:DynamicStreamingResource = new DynamicStreamingResource("http://example.com/vod");
+
+ rules.push( new RuleMocker(new Recommendation("rule1", 500, 1)));
+ rules.push( new RuleMocker(new Recommendation("rule2", 600, 1)));
+ rules.push( new RuleMocker(new Recommendation("rule3", 700, 1)));
+
+ switcher = new NetStreamSwitcherMocker(netStream, dsResource);
+
+ switchManager = new DefaultHTTPStreamingSwitchManager(netStream, switcher, metricRepository, null, true, rules, ruleWeights, 0.9, 4,29, 0.89, 0);
+ assertEquals(-1, switchManager.maxUpSwitchLimit);
+ }
+
+ public function testDefaultSwitchManagerInitWithZeroDownSwitchLimit():void
+ {
+ var ruleWeights:Vector. = generateWeights(0.7, 0.2, 0.1);
+
+ rules = new Vector.();
+
+ var dsResource:DynamicStreamingResource = new DynamicStreamingResource("http://example.com/vod");
+
+ rules.push( new RuleMocker(new Recommendation("rule1", 500, 1)));
+ rules.push( new RuleMocker(new Recommendation("rule2", 600, 1)));
+ rules.push( new RuleMocker(new Recommendation("rule3", 700, 1)));
+
+ switcher = new NetStreamSwitcherMocker(netStream, dsResource);
+
+ switchManager = new DefaultHTTPStreamingSwitchManager(netStream, switcher, metricRepository, null, true, rules, ruleWeights, 0.9, 4,29, 0.89, 1, 0);
+ assertEquals(-1, switchManager.maxUpSwitchLimit);
+ }
+
+ [Test]
+ public function testDefaultSwitchManagerInitWithNegativeSwitchingLimits():void
+ {
+ var ruleWeights:Vector. = generateWeights(0.7, 0.2, 0.1);
+
+ rules = new Vector.();
+
+ var dsResource:DynamicStreamingResource = new DynamicStreamingResource("http://example.com/vod");
+
+ rules.push( new RuleMocker(new Recommendation("rule1", 500, 1)));
+ rules.push( new RuleMocker(new Recommendation("rule2", 600, 1)));
+ rules.push( new RuleMocker(new Recommendation("rule3", 700, 1)));
+
+ switcher = new NetStreamSwitcherMocker(netStream, dsResource);
+
+ switchManager = new DefaultHTTPStreamingSwitchManager(netStream, switcher, metricRepository, null, true, rules, ruleWeights, 1,5, 30, 0.9, -2, -3);
+ assertEquals(-1, switchManager.maxUpSwitchLimit);
+ assertEquals(-1, switchManager.maxDownSwitchLimit);
+ }
+
+ [Test]
+ public function testSetMinimumReliability():void
+ {
+ createSwitchManager3Rules();
+ switchManager.minReliability = 0.77;
+ assertEquals(0.77, switchManager.minReliability);
+ switchManager.minReliability = 0;
+ assertEquals(0, switchManager.minReliability);
+ switchManager.minReliability = 1;
+ assertEquals(1, switchManager.minReliability);
+ }
+
+ [Test(expects = "ArgumentError")]
+ public function testSetMinimumReliabilityNegative():void
+ {
+ createSwitchManager3Rules();
+ switchManager.minReliability = -0.1;
+ }
+
+ [Test(expects = "ArgumentError")]
+ public function testSetMinimumReliabilityGreaterThan1():void
+ {
+ createSwitchManager3Rules();
+ switchManager.minReliability = 1.1;
+ }
+
+ [Test(expects = "ArgumentError")]
+ public function testSetMinimumReliabilityNaN():void
+ {
+ createSwitchManager3Rules();
+ switchManager.minReliability = NaN;
+ }
+
+
+ [Test(expects = "ArgumentError")]
+ public function testSetClimbFactorNegative():void
+ {
+ createSwitchManager3Rules();
+ switchManager.climbFactor = -0.1;
+ }
+
+
+ [Test(expects = "ArgumentError")]
+ public function testSetClimbFactorNaN():void
+ {
+ createSwitchManager3Rules();
+ switchManager.climbFactor = NaN;
+ }
+
+ [Test(expects = "ArgumentError")]
+ public function testSetClimbFactorZero():void
+ {
+ createSwitchManager3Rules();
+ switchManager.climbFactor = 0;
+ }
+
+ [Test]
+ public function testGetAndSetRuleWeights():void
+ {
+ createSwitchManager3Rules();
+ assertEquals(0.7, switchManager.normalRuleWeights[0]);
+ assertEquals(0.2, switchManager.normalRuleWeights[1]);
+ assertEquals(0.1, switchManager.normalRuleWeights[2]);
+ switchManager.normalRuleWeights = generateWeights(10.1, 11.2, 12.3);
+
+ assertEquals(10.1, switchManager.normalRuleWeights[0]);
+ assertEquals(11.2, switchManager.normalRuleWeights[1]);
+ assertEquals(12.3, switchManager.normalRuleWeights[2]);
+ }
+
+ [Test]
+ public function testGetAndSetRuleWeightsOneNotZero():void
+ {
+ createSwitchManager3Rules();
+ assertEquals(0.7, switchManager.normalRuleWeights[0]);
+ assertEquals(0.2, switchManager.normalRuleWeights[1]);
+ assertEquals(0.1, switchManager.normalRuleWeights[2]);
+ switchManager.normalRuleWeights = generateWeights(0, 2, 0);
+
+ assertEquals(0, switchManager.normalRuleWeights[0]);
+ assertEquals(2, switchManager.normalRuleWeights[1]);
+ assertEquals(0, switchManager.normalRuleWeights[2]);
+ }
+
+ [Test(expects = "ArgumentError")]
+ public function testGetAndSetDifferentSizeRuleWeights():void
+ {
+ createSwitchManager3Rules();
+ assertEquals(0.7, switchManager.normalRuleWeights[0]);
+ assertEquals(0.2, switchManager.normalRuleWeights[1]);
+ assertEquals(0.1, switchManager.normalRuleWeights[2]);
+ switchManager.normalRuleWeights = generateWeights(10.1, 11.2, 12.3, 13.4);
+ }
+
+ [Test(expects = "ArgumentError")]
+ public function testGetAndSetAllZeroRuleWeights():void
+ {
+ createSwitchManager3Rules();
+ assertEquals(0.7, switchManager.normalRuleWeights[0]);
+ assertEquals(0.2, switchManager.normalRuleWeights[1]);
+ assertEquals(0.1, switchManager.normalRuleWeights[2]);
+ switchManager.normalRuleWeights = generateWeights(0, 0, 0);
+ }
+
+ [Test(expects = "ArgumentError")]
+ public function testGetAndSetNullRuleWeights():void
+ {
+ createSwitchManager3Rules();
+ assertEquals(0.7, switchManager.normalRuleWeights[0]);
+ assertEquals(0.2, switchManager.normalRuleWeights[1]);
+ assertEquals(0.1, switchManager.normalRuleWeights[2]);
+ switchManager.normalRuleWeights = null;
+ }
+
+
+ [Test(expects = "ArgumentError")]
+ public function testGetAndSetNegativeRuleWeights():void
+ {
+ createSwitchManager3Rules();
+ assertEquals(0.7, switchManager.normalRuleWeights[0]);
+ assertEquals(0.2, switchManager.normalRuleWeights[1]);
+ assertEquals(0.1, switchManager.normalRuleWeights[2]);
+ switchManager.normalRuleWeights = generateWeights(-2, 1, 1);
+ }
+
+ [Test(expects = "ArgumentError")]
+ public function testGetAndSetNaNRuleWeights():void
+ {
+ createSwitchManager3Rules();
+ assertEquals(0.7, switchManager.normalRuleWeights[0]);
+ assertEquals(0.2, switchManager.normalRuleWeights[1]);
+ assertEquals(0.1, switchManager.normalRuleWeights[2]);
+ switchManager.normalRuleWeights = generateWeights(NaN, 1, 1);
+ }
+
+ public function testSetDownSwitchLimit():void
+ {
+ createSwitchManager3Rulesand2EmergencyRulesAndSwitchLimit();
+ assertEquals(2, switchManager.maxDownSwitchLimit);
+ switchManager.maxDownSwitchLimit = 0;
+ assertEquals(-1, switchManager.maxDownSwitchLimit);
+ }
+
+ public function testSetUpSwitchLimit():void
+ {
+ createSwitchManager3Rulesand2EmergencyRulesAndSwitchLimit();
+ assertEquals(1, switchManager.maxUpSwitchLimit);
+ switchManager.maxUpSwitchLimit = 0;
+ assertEquals(-1, switchManager.maxUpSwitchLimit);
+ }
+
+ [Test]
+ public function testSetMaxDownAndUpSwitchLimit():void
+ {
+ createSwitchManager3Rulesand2EmergencyRulesAndSwitchLimit();
+ assertEquals(1, switchManager.maxUpSwitchLimit);
+ assertEquals(2, switchManager.maxDownSwitchLimit);
+ switchManager.maxUpSwitchLimit = 3;
+ switchManager.maxDownSwitchLimit = 4;
+ assertEquals(3, switchManager.maxUpSwitchLimit);
+ assertEquals(4, switchManager.maxDownSwitchLimit);
+
+ switchManager.maxUpSwitchLimit = -3;
+ switchManager.maxDownSwitchLimit = -4;
+ assertEquals(-1, switchManager.maxUpSwitchLimit);
+ assertEquals(-1, switchManager.maxDownSwitchLimit);
+ }
+
+
+
+ /**
+ * Test switch up
+ *
+ **/
+ [Test]
+ public function testGetNewIndexSwitchFrom0To1():void
+ {
+ createSwitchManager3Rules();
+ availableQualityMetric.internalValue = qualityLevels;
+ availableQualityMetric.returnValid = true;
+ (rules[0] as RuleMocker).returnValue = new Recommendation("rule1", 320, 1);
+ (rules[1] as RuleMocker).returnValue = new Recommendation("rule2", 310, 1);
+ (rules[2] as RuleMocker).returnValue = new Recommendation("rule3", 300, 1);
+
+ //should go to 250, switch up 1.
+ assertEquals(1, switchManager.getNewIndex());
+
+ //simmulate switch in metric
+ //the value should be around the declared bitrate
+ mockSwitchTo(250,true);
+ }
+
+ /**
+ * Test switch up blocked by security factor.
+ *
+ **/
+ [Test]
+ public function testGetNewIndexSwitchFrom2To3LimitedByFactor():void
+ {
+ createSwitchManager3Rules();
+ availableQualityMetric.internalValue = qualityLevels;
+ availableQualityMetric.returnValid = true;
+
+ (rules[0] as RuleMocker).returnValue = new Recommendation("rule1", 420, 1);
+ (rules[1] as RuleMocker).returnValue = new Recommendation("rule2", 410, 1);
+ (rules[2] as RuleMocker).returnValue = new Recommendation("rule3", 400, 1);
+
+ //setup: should go to 350, switch up 2.
+ assertEquals(2, switchManager.getNewIndex());
+
+ //simmulate switch in metric
+ //the value should be around the declared bitrate
+ mockSwitchTo(350,true);
+
+
+ (rules[0] as RuleMocker).returnValue = new Recommendation("rule1", (450 + (0.9-1) * 350) / 0.9 - 0.01, 1);
+ (rules[1] as RuleMocker).returnValue = new Recommendation("rule2", 410, 0);
+ (rules[2] as RuleMocker).returnValue = new Recommendation("rule3", 400, 0);
+ //instead of going to 450, switch up 3, should stay on 2
+ assertEquals(2, switchManager.getNewIndex());
+
+ //simmulate switch in metric
+ //the value should be around the declared bitrate
+ mockSwitchTo(350,true);
+
+
+ (rules[0] as RuleMocker).returnValue = new Recommendation("rule1", (450 + (0.9-1) * 350) / 0.9 + 0.01, 1);
+ (rules[1] as RuleMocker).returnValue = new Recommendation("rule2", 410, 0);
+ (rules[2] as RuleMocker).returnValue = new Recommendation("rule3", 400, 0);
+ //switch up to 450 = index 3
+ assertEquals(3, switchManager.getNewIndex());
+
+ //simmulate switch in metric
+ //the value should be around the declared bitrate
+ mockSwitchTo(450,true);
+
+ }
+
+
+ /**
+ * Test switch down
+ *
+ **/
+ [Test]
+ public function testGetNewIndexSwitchFrom2To1():void
+ {
+ createSwitchManager3Rules();
+ availableQualityMetric.internalValue = qualityLevels;
+ availableQualityMetric.returnValid = true;
+ (rules[0] as RuleMocker).returnValue = new Recommendation("rule1", 420, 1);
+ (rules[1] as RuleMocker).returnValue = new Recommendation("rule2", 410, 1);
+ (rules[2] as RuleMocker).returnValue = new Recommendation("rule3", 400, 1);
+
+ //prepare switch, go to 350, switch up to stream 2.
+ assertEquals(2, switchManager.getNewIndex());
+
+ //simmulate switch in metric
+ //the value should be around the declared bitrate
+ mockSwitchTo(350,true);
+
+
+ (rules[0] as RuleMocker).returnValue = new Recommendation("rule1", 320, 1);
+ (rules[1] as RuleMocker).returnValue = new Recommendation("rule2", 310, 1);
+ (rules[2] as RuleMocker).returnValue = new Recommendation("rule3", 300, 1);
+
+ //should go to 250, switch down to 1.
+ assertEquals(1, switchManager.getNewIndex());
+
+ //simmulate switch in metric
+ //the value should be around the declared bitrate
+ mockSwitchTo(250,true);
+
+ }
+
+
+
+ /**
+ * Test unavailable AvailableBitratesMetric
+ *
+ **/
+ [Test(expects = "Error")]
+ public function testGetNewIndexUnavailableAvailableBitratesMetric():void
+ {
+ createSwitchManager3Rules();
+ availableQualityMetric.internalValue = qualityLevels;
+ availableQualityMetric.returnValid = false;
+ (rules[0] as RuleMocker).returnValue = new Recommendation("rule1", 320, 1);
+ (rules[1] as RuleMocker).returnValue = new Recommendation("rule2", 310, 1);
+ (rules[2] as RuleMocker).returnValue = new Recommendation("rule3", 300, 1);
+
+ var i:int = switchManager.getNewIndex();
+
+ }
+
+ /**
+ * Test unavailable ActualBitrate
+ * Note: currentindex cannot be updated in unit tests, will test against a value of 0
+ *
+ **/
+ [Test]
+ public function testGetNewIndexWhenActualBitrateIsInvalid():void
+ {
+ createSwitchManager3Rules();
+ availableQualityMetric.internalValue = qualityLevels;
+ availableQualityMetric.returnValid = true;
+ (rules[0] as RuleMocker).returnValue = new Recommendation("rule1", 420, 1);
+ (rules[1] as RuleMocker).returnValue = new Recommendation("rule2", 410, 1);
+ (rules[2] as RuleMocker).returnValue = new Recommendation("rule3", 400, 1);
+
+ //prepare switch, go to 350, switch up to stream 2.
+ assertEquals(2, switchManager.getNewIndex());
+
+ //simmulate switch in metric
+ //the value should be around the declared bitrate
+ //make it invalid
+ mockSwitchTo(350,false);
+
+ //indirect evaluation of the currentIndex = 0
+ //switch up to 2 should stop to 1
+ (rules[0] as RuleMocker).returnValue = new Recommendation("rule1", 350*0.9 -0.01, 1);
+ (rules[1] as RuleMocker).returnValue = new Recommendation("rule2", 310, 0);
+ (rules[2] as RuleMocker).returnValue = new Recommendation("rule3", 300, 0);
+
+
+ assertEquals(1, switchManager.getNewIndex());
+
+ mockSwitchTo(250,true);
+
+ }
+
+ [Test]
+ public function testGetNewIndexSwitchOnSameIndex():void
+ {
+ createSwitchManager3Rules();
+ availableQualityMetric.internalValue = qualityLevels;
+ availableQualityMetric.returnValid = true;
+ (rules[0] as RuleMocker).returnValue = new Recommendation("rule1", 420, 1);
+ (rules[1] as RuleMocker).returnValue = new Recommendation("rule2", 410, 1);
+ (rules[2] as RuleMocker).returnValue = new Recommendation("rule3", 400, 1);
+
+ //prepare switch, go to 350, switch up to stream 2.
+ assertEquals(2, switchManager.getNewIndex());
+
+ //simmulate switch in metric
+ //the value should be around the declared bitrate
+ mockSwitchTo(350,true);
+
+ (rules[0] as RuleMocker).returnValue = new Recommendation("rule1", 420, 1);
+ (rules[1] as RuleMocker).returnValue = new Recommendation("rule2", 410, 1);
+ (rules[2] as RuleMocker).returnValue = new Recommendation("rule3", 400, 1);
+
+ //prepare switch, go to 350, switch up to stream 2.
+ assertEquals(2, switchManager.getNewIndex());
+
+ //simmulate switch in metric
+ //the value should be around the declared bitrate
+ mockSwitchTo(350,true);
+
+ }
+
+ /**
+ * Test switch up blocked by an unreliable bitrate level.
+ *
+ **/
+ [Test]
+ public function testGetNewIndexSwitchForUnreliableBitrate():void
+ {
+ //setup switches
+ createSwitchManager3Rules();
+ availableQualityMetric.internalValue = qualityLevels;
+ availableQualityMetric.returnValid = true;
+
+ mockRules(3);
+ mockRules(2);
+ mockRules(3);
+ mockRules(1);
+
+ //real test, try to switch to 3
+ (rules[0] as RuleMocker).returnValue = new Recommendation("rule1", 520, 1);
+ (rules[1] as RuleMocker).returnValue = new Recommendation("rule2", 510, 1);
+ (rules[2] as RuleMocker).returnValue = new Recommendation("rule3", 500, 1);
+ //do not switch up due to low Reliability
+ assertEquals(2, switchManager.getNewIndex());
+ mockSwitchTo(350,true);
+
+ }
+
+ [Test]
+ public function testGetReliability():void
+ {
+ //setup switches
+ createSwitchManager3Rules();
+ availableQualityMetric.internalValue = qualityLevels;
+ availableQualityMetric.returnValid = true;
+
+ mockRules(3);
+ mockRules(2);
+
+ mockRules(3);
+
+ var i:int;
+ for (i = 0; i<5; i++)
+ assertTrue(isNaN(switchManager.getCurrentReliability(i)));
+
+ mockRules(1);
+
+ assertEquals(1, switchManager.getCurrentReliability(0));
+ assertTrue(isNaN(switchManager.getCurrentReliability(1)));
+ assertEquals(1, switchManager.getCurrentReliability(2));
+ assertEquals(1-(2*2)/(2*2), switchManager.getCurrentReliability(3));
+ assertTrue(isNaN(switchManager.getCurrentReliability(4)));
+
+ mockRules(2);
+ mockRules(1);
+
+ assertEquals(1, switchManager.getCurrentReliability(0));
+ assertEquals(1, switchManager.getCurrentReliability(1));
+ assertEquals(1-(1*1)/(2*3), switchManager.getCurrentReliability(2));
+ assertEquals(1-(2*2)/(2*3), switchManager.getCurrentReliability(3));
+ assertTrue(isNaN(switchManager.getCurrentReliability(4)));
+ }
+
+ [Test]
+ public function testGetReliabilityforEmergencySwitches():void
+ {
+ //setup switches
+ createSwitchManager3Rulesand2EmergencyRules();
+ availableQualityMetric.internalValue = qualityLevels;
+ availableQualityMetric.returnValid = true;
+
+ mockRules(3);
+ mockRules(2);
+ mockRules(4);
+
+ var i:int;
+ for (i = 0; i<5; i++)
+ assertTrue(isNaN(switchManager.getCurrentReliability(i)));
+
+ mockEmergencyRules(2);
+
+ assertEquals(1, switchManager.getCurrentReliability(0));
+ assertTrue(isNaN(switchManager.getCurrentReliability(1)));
+ assertEquals(1, switchManager.getCurrentReliability(2));
+ assertEquals(1-(1*1)/(1*2), switchManager.getCurrentReliability(3));
+ assertEquals(0,switchManager.getCurrentReliability(4));
+
+ mockRules(1);
+
+ assertEquals(1, switchManager.getCurrentReliability(0));
+ assertTrue(isNaN(switchManager.getCurrentReliability(1)));
+ assertEquals(1-(1*1)/(2*3), switchManager.getCurrentReliability(2));
+ assertEquals(1-(1*1)/(1*3), switchManager.getCurrentReliability(3));
+ assertEquals(0,switchManager.getCurrentReliability(4));
+
+ mockRules(1);
+
+ assertEquals(1, switchManager.getCurrentReliability(0));
+ assertEquals(1, switchManager.getCurrentReliability(1));
+ assertEquals(1-(1*1)/(2*3), switchManager.getCurrentReliability(2));
+ assertEquals(1-(1*1)/(1*3), switchManager.getCurrentReliability(3));
+ assertEquals(0,switchManager.getCurrentReliability(4));
+
+ }
+
+ // http://bugs.adobe.com/jira/browse/FM-1493
+ // [ABR] A stream should be marked unreliable if an emergency down switch occurred, even if the record is small
+ [Test]
+ public function testGetReliabilityforEmergencySwitchWithReliabilityRecordBelowMinThreshold():void
+ {
+ //setup switches
+ createSwitchManager3Rulesand2EmergencyRules();
+ availableQualityMetric.internalValue = qualityLevels;
+ availableQualityMetric.returnValid = true;
+
+ mockRules(3);
+ mockEmergencyRules(2);
+
+ assertEquals(0,switchManager.getCurrentReliability(3));
+ }
+
+ [Test]
+ public function testGetReliabilityforEmergencySwitchesUpwards():void
+ {
+ //setup switches
+ createSwitchManager3Rulesand2EmergencyRules();
+ availableQualityMetric.internalValue = qualityLevels;
+ availableQualityMetric.returnValid = true;
+
+ mockRules(1);
+ mockRules(2);
+ mockRules(2);
+ mockRules(3);
+ mockEmergencyRules(3);
+
+ assertEquals(1, switchManager.getCurrentReliability(0));
+ assertEquals(1, switchManager.getCurrentReliability(1));
+ assertEquals(1, switchManager.getCurrentReliability(2));
+ assertEquals(1, switchManager.getCurrentReliability(3));
+ assertTrue(isNaN(switchManager.getCurrentReliability(4)));
+
+ mockEmergencyRules(4);
+
+ assertEquals(1, switchManager.getCurrentReliability(0));
+ assertEquals(1, switchManager.getCurrentReliability(1));
+ assertEquals(1, switchManager.getCurrentReliability(2));
+ assertEquals(1, switchManager.getCurrentReliability(3));
+ assertTrue(isNaN(switchManager.getCurrentReliability(4)));
+
+
+ }
+
+
+ /**
+ * Test PushToHistory indirect by checking reliability of an idex that should not be any more in history
+ *
+ **/
+ [Test]
+ public function testPushReliabilityToHistory():void
+ {
+ //setup switches 0/401230120101230/1
+ createSwitchManager3Rules();
+ availableQualityMetric.internalValue = qualityLevels;
+ availableQualityMetric.returnValid = true;
+
+
+ mockRules(4);
+ mockRules(0);
+ mockRules(1);
+ mockRules(2);
+ mockRules(3);
+ mockRules(0);
+ mockRules(1);
+ mockRules(2);
+ mockRules(0);
+ mockRules(1);
+ mockRules(0);
+ mockRules(1);
+ mockRules(2);
+ mockRules(3);
+ mockRules(0);
+ assertEquals(1-(1*1)/(1*7), switchManager.getCurrentReliability(4));
+ mockRules(1);
+ //this is the main check
+ assertTrue(isNaN(switchManager.getCurrentReliability(4)));
+
+ }
+
+ [Test]
+ public function testGetNewIndexBitrateOverMax():void
+ {
+ createSwitchManager3Rules();
+ availableQualityMetric.internalValue = qualityLevels;
+ availableQualityMetric.returnValid = true;
+ (rules[0] as RuleMocker).returnValue = new Recommendation("rule1", 3200, 1);
+ (rules[1] as RuleMocker).returnValue = new Recommendation("rule2", 3100, 1);
+ (rules[2] as RuleMocker).returnValue = new Recommendation("rule3", 3000, 1);
+
+ //should go to 550, switch up 4.
+ assertEquals(4, switchManager.getNewIndex());
+
+ //simmulate switch in metric
+ //the value should be around the declared bitrate
+ mockSwitchTo(550,true);
+
+ }
+
+ [Test]
+ public function testGetNewIndexBitrateUnderMin():void
+ {
+ createSwitchManager3Rules();
+ availableQualityMetric.internalValue = qualityLevels;
+ availableQualityMetric.returnValid = true;
+
+ mockRules(4);
+
+ (rules[0] as RuleMocker).returnValue = new Recommendation("rule1", 32, 1);
+ (rules[1] as RuleMocker).returnValue = new Recommendation("rule2", 31, 1);
+ (rules[2] as RuleMocker).returnValue = new Recommendation("rule3", 30, 1);
+
+ //should go to 150, switch down to 0.
+ assertEquals(0, switchManager.getNewIndex());
+
+ //simmulate switch in metric
+ //the value should be around the declared bitrate
+ mockSwitchTo(150,true);
+
+ }
+
+ [Test]
+ public function testGetNewIndexBitrateIgnoreUnsureRules():void
+ {
+ createSwitchManager3Rules();
+ availableQualityMetric.internalValue = qualityLevels;
+ availableQualityMetric.returnValid = true;
+
+ mockRules(2);
+
+ availableQualityMetric.returnValid = true;
+ (rules[0] as RuleMocker).returnValue = new Recommendation("rule1", 320, 0);
+ (rules[1] as RuleMocker).returnValue = new Recommendation("rule2", 310, 0);
+ (rules[2] as RuleMocker).returnValue = new Recommendation("rule3", 300, 0);
+
+ //should stay on the same index
+ assertEquals(2, switchManager.getNewIndex());
+
+ //simmulate switch in metric
+ //the value should be around the declared bitrate
+ mockSwitchTo(350,true);
+ }
+
+
+ [Test]
+ public function testGetNewIndexForEmergencyRule():void
+ {
+ createSwitchManager3Rulesand2EmergencyRules();
+ availableQualityMetric.internalValue = qualityLevels;
+ availableQualityMetric.returnValid = true;
+
+ mockRules(3);
+
+ mockRules(4);
+
+ (emergencyRules[0] as RuleMocker).returnValue = new Recommendation("emergencyrule1", 320, 1);
+ (emergencyRules[1] as RuleMocker).returnValue = new Recommendation("emergencyrule2", 220, 1);
+
+ //call the algorithm run
+
+ netStream.dispatchEvent(new HTTPStreamingEvent(HTTPStreamingEvent.RUN_ALGORITHM));
+
+ //check the ideal zero-time switch result
+ assertEquals(0, switcher.lastSwitchIndex);
+
+ //simmulate switch in metric
+ //the value should be around the declared bitrate
+ mockSwitchTo(150,true);
+
+ }
+
+ [Test]
+ public function testGetNewIndexForUnsureEmergencyRule():void
+ {
+ createSwitchManager3Rulesand2EmergencyRules();
+ availableQualityMetric.internalValue = qualityLevels;
+ availableQualityMetric.returnValid = true;
+ (rules[0] as RuleMocker).returnValue = new Recommendation("rule1", 420, 1);
+ (rules[1] as RuleMocker).returnValue = new Recommendation("rule2", 410, 1);
+ (rules[2] as RuleMocker).returnValue = new Recommendation("rule3", 400, 1);
+
+
+ (emergencyRules[0] as RuleMocker).returnValue = new Recommendation("emergencyrule1", 320, 0.8);
+ (emergencyRules[1] as RuleMocker).returnValue = new Recommendation("emergencyrule2", 220 ,0.6);
+ //should go to 350
+ //call the algorithm run
+
+ netStream.dispatchEvent(new HTTPStreamingEvent(HTTPStreamingEvent.RUN_ALGORITHM));
+
+ //check the ideal zero-time switch result
+ assertEquals(2, switcher.lastSwitchIndex);
+
+ //simmulate switch in metric
+ //the value should be around the declared bitrate
+ mockSwitchTo(350,true);
+ }
+
+
+ /**
+ * Tests the initial value, more will be on integration tests
+ **/
+ [Test]
+ public function testGetCurrentIndex():void
+ {
+ createSwitchManager1Rule();
+ assertEquals(0, switchManager.currentIndex);
+ }
+
+ [Test]
+ public function testGetMetricRepository():void
+ {
+ createSwitchManager1Rule();
+ assertTrue(switchManager.metricRepository is MetricRepository);
+ }
+
+ [Test]
+ public function testGetCurrentReliability():void
+ {
+ createSwitchManager1Rule();
+ assertTrue(isNaN(switchManager.getCurrentReliability(0)));
+ }
+
+ [Test]
+ public function testAutoSwitch():void
+ {
+ //full test will be done in integration suite
+ createSwitchManager1Rule();
+ assertTrue( switchManager.autoSwitch);
+
+ switchManager.autoSwitch = false;
+ assertFalse(switchManager.autoSwitch);
+
+
+ switchManager.autoSwitch = true;
+ assertTrue( switchManager.autoSwitch);
+ }
+
+
+ /**
+ * Tests setting a maxallowedindex
+ * No negative tests, nothing is enforced
+ */
+ [Test]
+ public function testSetMaxAllowedIndex():void
+ {
+ createSwitchManager1Rule();
+ assertEquals(int.MAX_VALUE, switchManager.maxAllowedIndex);
+
+ switchManager.maxAllowedIndex = 4;
+ assertEquals(4, switchManager.maxAllowedIndex);
+
+ }
+
+ [Test]
+ public function testSwitchTo():void
+ {
+ createSwitchManager1Rule();
+ switchManager.autoSwitch = false;
+ switchManager.switchTo(3);
+
+ assertEquals(3, (switcher as NetStreamSwitcherMocker).lastSwitchIndex);
+ }
+
+ [Test(expects = "flash.errors.IllegalOperationError")]
+ public function testSwitchToInAutoSwitchMode():void
+ {
+ createSwitchManager1Rule();
+ switchManager.switchTo(3);
+ }
+
+
+ [Test]
+ public function testGetNewIndexForDownSwitchLimit():void
+ {
+ createSwitchManager3Rulesand2EmergencyRulesAndSwitchLimit();
+ availableQualityMetric.internalValue = qualityLevels;
+ availableQualityMetric.returnValid = true;
+
+ mockRules(1);
+ mockRules(2);
+ mockRules(3);
+ mockRules(4);
+ //real test
+ mockRules(0,2);
+
+ }
+
+ [Test]
+ public function testGetNewIndexForUpSwitchLimit():void
+ {
+ createSwitchManager3Rulesand2EmergencyRulesAndSwitchLimit();
+ availableQualityMetric.internalValue = qualityLevels;
+ availableQualityMetric.returnValid = true;
+
+ mockRules(4, 1);
+
+ }
+
+ [Test]
+ public function testGetNewIndexForDownSwitchLimitAndUnreliable():void
+ {
+ createSwitchManager3Rulesand2EmergencyRulesAndSwitchLimit();
+ availableQualityMetric.internalValue = qualityLevels;
+ availableQualityMetric.returnValid = true;
+ switchManager.maxUpSwitchLimit = 10;
+
+ mockRules(1);
+ mockRules(2);
+ mockEmergencyRules(1);
+ mockRules(3);
+ mockRules(4);
+ //real test
+ mockRules(0, 3);
+
+ }
+
+ [Test]
+ public function testGetNewIndexForUpSwitchLimitAndUnreliable():void
+ {
+ createSwitchManager3Rulesand2EmergencyRulesAndSwitchLimit();
+ availableQualityMetric.internalValue = qualityLevels;
+ availableQualityMetric.returnValid = true;
+
+ mockRules(1);
+ mockRules(2);
+ mockRules(3);
+ mockEmergencyRules(2);
+ mockRules(4, 2);
+
+ }
+
+ //this might overlap with another test
+ [Test]
+ public function testGetNewIndexForUpSwitchLimitAndUnreliableModifiedLimit():void
+ {
+ createSwitchManager3Rulesand2EmergencyRulesAndSwitchLimit();
+ availableQualityMetric.internalValue = qualityLevels;
+ availableQualityMetric.returnValid = true;
+ switchManager.maxUpSwitchLimit = 2;
+
+ mockRules(1);
+ mockRules(2);
+ mockRules(3);
+ mockRules(4);
+ mockEmergencyRules(2);
+ mockRules(4, 3);
+ }
+
+
+ [Test]
+ public function testGetNewIndexForUpSwitchLimitAndNegativeMaxUpSwitchLimit():void
+ {
+ createSwitchManager3Rulesand2EmergencyRulesAndSwitchLimit(-1,2);
+ availableQualityMetric.internalValue = qualityLevels;
+ availableQualityMetric.returnValid = true;
+
+ mockRules(4);
+ }
+
+ [Test]
+ public function testGetNewIndexForDownSwitchLimitAndNegativeMaxDownSwitchLimit():void
+ {
+ createSwitchManager3Rulesand2EmergencyRulesAndSwitchLimit(1,-1);
+ availableQualityMetric.internalValue = qualityLevels;
+ availableQualityMetric.returnValid = true;
+
+ mockRules(1);
+ mockRules(2);
+ mockRules(3);
+ mockRules(4);
+
+ mockRules(0);
+ }
+
+ [Test]
+ public function testGetNewIndexForSwitchLimitAndNegativeMaxSwitchLimits():void
+ {
+ createSwitchManager3Rulesand2EmergencyRulesAndSwitchLimit(-1,-1);
+ availableQualityMetric.internalValue = qualityLevels;
+ availableQualityMetric.returnValid = true;
+
+ mockRules(4);
+
+ mockRules(0);
+ }
+
+ [Test]
+ public function testGetNewIndexForUpSwitchEmergency():void
+ {
+ createSwitchManager3Rulesand2EmergencyRulesAndSwitchLimit();
+ availableQualityMetric.internalValue = qualityLevels;
+ availableQualityMetric.returnValid = true;
+
+ mockEmergencyRules(4);
+ }
+
+ [Test]
+ public function testGetNewIndexForDownSwitchEmergency():void
+ {
+ createSwitchManager3Rulesand2EmergencyRulesAndSwitchLimit();
+ availableQualityMetric.internalValue = qualityLevels;
+ availableQualityMetric.returnValid = true;
+
+ mockRules(1);
+ mockRules(2);
+ mockRules(3);
+ mockRules(4);
+
+ mockEmergencyRules(0);
+ }
+
+
+
+ private function createSwitchManager1Rule():void
+ {
+ var ruleWeights:Vector. = generateWeights(0.6);
+
+ rules = new Vector.();
+
+ rules.push( new RuleMocker(new Recommendation("rule1", 500, 1)));
+
+ var dsResource:DynamicStreamingResource = new DynamicStreamingResource("http://example.com/vod");
+
+ dsResource.streamItems = new Vector.();
+ for (var i:uint = 0; i < 5; i++)
+ {
+ var streamItem:DynamicStreamingItem = new DynamicStreamingItem("stream" + i, 150 + i * 100);
+ dsResource.streamItems.push(streamItem);
+ }
+
+ switcher = new NetStreamSwitcherMocker(netStream, dsResource);
+
+ switchManager = new DefaultHTTPStreamingSwitchManager(netStream, switcher, metricRepository, null, true, rules, ruleWeights, 0.91, 6, 16, 0.9, uint.MAX_VALUE, uint.MAX_VALUE);
+
+ initMetrics();
+
+ }
+
+ private function createSwitchManager3Rules():void
+ {
+ var ruleWeights:Vector. = generateWeights(0.7, 0.2, 0.1);
+
+ rules = new Vector.();
+
+ var dsResource:DynamicStreamingResource = new DynamicStreamingResource("http://example.com/vod");
+
+ rules.push( new RuleMocker(new Recommendation("rule1", 500, 1)));
+ rules.push( new RuleMocker(new Recommendation("rule2", 600, 1)));
+ rules.push( new RuleMocker(new Recommendation("rule3", 700, 1)));
+
+ switcher = new NetStreamSwitcherMocker(netStream, dsResource);
+
+ switchManager = new DefaultHTTPStreamingSwitchManager(netStream, switcher, metricRepository, null, true, rules, ruleWeights, 0.85, 5, 15, 0.9, uint.MAX_VALUE, uint.MAX_VALUE);
+
+ initMetrics();
+ }
+
+
+ private function createSwitchManager3Rulesand2EmergencyRules():void
+ {
+ var ruleWeights:Vector. = generateWeights(0.7, 0.2, 0.1);
+
+ rules = new Vector.();
+ emergencyRules = new Vector.();
+
+ var dsResource:DynamicStreamingResource = new DynamicStreamingResource("http://example.com/vod");
+
+ rules.push( new RuleMocker(new Recommendation("rule1", 500, 1)));
+ rules.push( new RuleMocker(new Recommendation("rule2", 600, 1)));
+ rules.push( new RuleMocker(new Recommendation("rule3", 700, 1)));
+
+ emergencyRules.push( new RuleMocker(new Recommendation("emergencyrule1", 50, 0)));
+ emergencyRules.push( new RuleMocker(new Recommendation("emergencyrule2", 60, 0)));
+
+ switcher = new NetStreamSwitcherMocker(netStream, dsResource);
+
+ switchManager = new DefaultHTTPStreamingSwitchManager(netStream, switcher, metricRepository, emergencyRules, true, rules, ruleWeights, 0.9, 5, 15, 0.9, uint.MAX_VALUE, uint.MAX_VALUE);
+
+ initMetrics();
+ }
+
+ private function createSwitchManager3Rulesand2EmergencyRulesAndSwitchLimit(maxUp:int = 1, maxDown:int = 2):void
+ {
+ var ruleWeights:Vector. = generateWeights(0.7, 0.2, 0.1);
+
+ rules = new Vector.();
+ emergencyRules = new Vector.();
+
+ var dsResource:DynamicStreamingResource = new DynamicStreamingResource("http://example.com/vod");
+
+ rules.push( new RuleMocker(new Recommendation("rule1", 500, 1)));
+ rules.push( new RuleMocker(new Recommendation("rule2", 600, 1)));
+ rules.push( new RuleMocker(new Recommendation("rule3", 700, 1)));
+
+ emergencyRules.push( new RuleMocker(new Recommendation("emergencyrule1", 50, 0)));
+ emergencyRules.push( new RuleMocker(new Recommendation("emergencyrule2", 60, 0)));
+
+ switcher = new NetStreamSwitcherMocker(netStream, dsResource);
+
+ switchManager = new DefaultHTTPStreamingSwitchManager(netStream, switcher, metricRepository, emergencyRules, true, rules, ruleWeights, 0.9, 5, 15, 0.9, maxUp, maxDown);
+
+ initMetrics();
+ }
+
+ private function initMetrics():void
+ {
+ availableQualityMetric = metricRepository.getMetric(MetricType.AVAILABLE_QUALITY_LEVELS) as AvailableQualityLevelsMetricMocker;
+ actualBitrateMetric = metricRepository.getMetric(MetricType.ACTUAL_BITRATE, 10) as ActualBitrateMetricMocker;
+
+ availableQualityMetric.returnValid = true;
+ availableQualityMetric.internalValue = qualityLevels;
+
+ mockSwitchTo(150,true);
+ }
+
+
+ private function generateWeights(... weights):Vector.
+ {
+ var v:Vector. = new Vector.();
+ for(var i:uint = 0; i< weights.length; i++)
+ {
+ v[i] = weights[i] ;
+ }
+ return (v);
+ }
+
+ private function mockSwitchTo(value:Number, valid:Boolean = true):void
+ {
+ //simmulate switch in metric and switcher
+ //the value should be around the declared bitrate
+ //qos needs to be updated to get the non-cached value
+ actualBitrateMetric.internalValue = value;
+ actualBitrateMetric.returnValid = valid;
+ addQoSInfo(generateQoSInfo(mockTimestamp++, 150, 250, 350, 450, 550));
+ (switcher as NetStreamSwitcherMocker).actualIndex = (value - 150) / 100;
+ }
+
+ private function mockRules(index:int, targetIndex:int = -1):void
+ {
+ if (targetIndex==-1)
+ targetIndex=index;
+ var bitrate:Number = 150 + 100*index + 80;
+ (rules[0] as RuleMocker).returnValue = new Recommendation("rule1", bitrate, 1);
+ (rules[1] as RuleMocker).returnValue = new Recommendation("rule2", 510, 0);
+ (rules[2] as RuleMocker).returnValue = new Recommendation("rule3", 500, 0);
+
+ //initiate and check if the correct switch is done
+ netStream.dispatchEvent(new HTTPStreamingEvent(HTTPStreamingEvent.RUN_ALGORITHM));
+
+ var newBitrate:Number = 150 + 100 * targetIndex + 80;
+ //check the ideal zero-time switch result
+ assertEquals(targetIndex, switcher.lastSwitchIndex);
+
+ //simulate switch behind the scenes;
+ mockSwitchTo(newBitrate, true);
+
+ //clear emergency rules for a possible new switch
+ (rules[0] as RuleMocker).returnValue = new Recommendation("rule1", newBitrate, 0);
+ }
+
+ private function mockEmergencyRules(index:int, targetIndex:int = -1):void
+ {
+ if (targetIndex==-1)
+ targetIndex=index;
+ var bitrate:Number = 150 + 100*index + 80;
+ (emergencyRules[0] as RuleMocker).returnValue = new Recommendation("emergencyRule1", bitrate, 1);
+ (emergencyRules[1] as RuleMocker).returnValue = new Recommendation("emergencyRule2", bitrate, 0);
+ //initiate and check if the correct switch is done
+ netStream.dispatchEvent(new HTTPStreamingEvent(HTTPStreamingEvent.RUN_ALGORITHM));
+ //check the ideal zero-time switch result
+ assertEquals(targetIndex, switcher.lastSwitchIndex);
+
+ //simulate switch behind the scenes;
+
+ var newBitrate:Number = 150 + 100 * targetIndex + 80;
+
+ mockSwitchTo(newBitrate, true);
+ //clear emergency rules for a possible new switch
+ (emergencyRules[0] as RuleMocker).returnValue = new Recommendation("emergencyRule1", newBitrate, 0);
+ }
+
+ //helper different from qosinfo tests functions
+
+ private function generateQoSInfo(timestamp:Number, ... qualityLevels):QoSInfo
+ {
+ var v:Vector. = new Vector.();
+ for(var i:uint = 0; i< qualityLevels.length; i++)
+ {
+ v[i] = new QualityLevel( i, qualityLevels[i], "test" + qualityLevels[i] );
+ }
+ return (new QoSInfo(timestamp, timestamp+5678, v, 0, 0, new FragmentDetails(14000, 4000, 568, 2)));
+ }
+
+ //helper identical to qosinfo tests functions
+ private function addQoSInfo(qos:QoSInfo):void
+ {
+ netStream.dispatchEvent(new QoSInfoEvent(QoSInfoEvent.QOS_UPDATE, false, false, qos));
+ }
+
+ private var qosInfoHistory:QoSInfoHistory;
+ private var netStream:NetStream;
+ private var metricFactory:MetricFactory;
+ private var metricRepository:MetricRepository;
+ private var switchManager:DefaultHTTPStreamingSwitchManager;
+ private var switcher:NetStreamSwitcherMocker;
+ private var rules:Vector.;
+ private var emergencyRules:Vector.;
+
+
+ private var availableQualityMetric:AvailableQualityLevelsMetricMocker;
+ private var actualBitrateMetric:ActualBitrateMetricMocker;
+
+ private var qualityLevels:Vector.;
+
+ private var mockTimestamp:int = 0;
+
+
+ }
+}
\ No newline at end of file
diff --git a/lib/osmf/framework/OSMFTest/src/org/osmf/net/drm/TestDRMServices.as b/lib/osmf/framework/OSMFTest/src/org/osmf/net/drm/TestDRMServices.as
new file mode 100644
index 0000000..8bd3003
--- /dev/null
+++ b/lib/osmf/framework/OSMFTest/src/org/osmf/net/drm/TestDRMServices.as
@@ -0,0 +1,91 @@
+/*****************************************************
+ *
+ * Copyright 2009 Adobe Systems Incorporated. All Rights Reserved.
+ *
+ *****************************************************
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ *
+ * The Initial Developer of the Original Code is Adobe Systems Incorporated.
+ * Portions created by Adobe Systems Incorporated are Copyright (C) 2009 Adobe Systems
+ * Incorporated. All Rights Reserved.
+ *
+ * Contributor(s): Akamai Technologies
+ *
+ *****************************************************/
+package org.osmf.net.drm
+{
+ import flash.utils.ByteArray;
+
+ import flexunit.framework.Assert;
+
+ public class TestDRMServices
+ {
+ [Test(description="Using a null or an empty token")]
+ public function convertEmptyTokens():void
+ {
+ CONFIG::FLASH_10_1
+ {
+ var token:ByteArray = null;
+
+ token = DRMServices.convertToken(null);
+ Assert.assertEquals(token, null);
+
+ token = DRMServices.convertToken("");
+ Assert.assertEquals(token, null);
+ }
+ }
+
+ [Test(description="Using a byte array token. Conversion shouldn't happen.")]
+ public function convertByteArrayTokens():void
+ {
+ CONFIG::FLASH_10_1
+ {
+ var token:ByteArray = null;
+
+ var originalToken:ByteArray = new ByteArray();
+ token = DRMServices.convertToken(originalToken);
+ Assert.assertEquals(token, originalToken);
+
+ originalToken.writeUTFBytes(DEFAULT_TOKEN_DATA);
+ token = DRMServices.convertToken(originalToken);
+ Assert.assertEquals(token, originalToken);
+ }
+ }
+
+ [Test(description="Using a string as token. The string content should be serialized as a byte array.")]
+ public function convertStringToken():void
+ {
+ CONFIG::FLASH_10_1
+ {
+ var token:ByteArray = null;
+
+ token = DRMServices.convertToken(DEFAULT_TOKEN_DATA);
+ Assert.assertNotNull(token);
+ Assert.assertEquals(token.bytesAvailable, DEFAULT_TOKEN_DATA_LEN);
+ Assert.assertEquals(token.length, DEFAULT_TOKEN_DATA_LEN);
+ Assert.assertEquals(token.toString(), DEFAULT_TOKEN_DATA);
+
+ token = DRMServices.convertToken(LONGER_TOKEN_DATA);
+ Assert.assertNotNull(token);
+ Assert.assertEquals(token.bytesAvailable, LONGER_TOKEN_DATA_LEN);
+ Assert.assertEquals(token.length, LONGER_TOKEN_DATA_LEN);
+ Assert.assertEquals(token.toString(), LONGER_TOKEN_DATA);
+ }
+ }
+
+ /// Internals
+ private static const DEFAULT_TOKEN_DATA:String = "1234";
+ private static const DEFAULT_TOKEN_DATA_LEN:int = 4;
+ private static const LONGER_TOKEN_DATA:String = "0123456789";
+ private static const LONGER_TOKEN_DATA_LEN:int = 10;
+ }
+}
\ No newline at end of file
diff --git a/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/ActualBitrateMetricMocker.as b/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/ActualBitrateMetricMocker.as
new file mode 100644
index 0000000..5d1ddac
--- /dev/null
+++ b/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/ActualBitrateMetricMocker.as
@@ -0,0 +1,71 @@
+/*****************************************************
+ *
+ * Copyright 2011 Adobe Systems Incorporated. All Rights Reserved.
+ *
+ *****************************************************
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ *
+ * The Initial Developer of the Original Code is Adobe Systems Incorporated.
+ * Portions created by Adobe Systems Incorporated are Copyright (C) 2011 Adobe Systems
+ * Incorporated. All Rights Reserved.
+ *
+ *****************************************************/
+package org.osmf.net.metrics
+{
+ import org.osmf.net.qos.QoSInfoHistory;
+
+ public class ActualBitrateMetricMocker extends ActualBitrateMetric
+ {
+ public function ActualBitrateMetricMocker(qosInfoHistory:QoSInfoHistory, maxFragments:uint = 5)
+ {
+ super(qosInfoHistory, maxFragments);
+ _internalValue=undefined;
+ _returnValid=false;
+ }
+
+ override protected function getValueForced():MetricValue
+ {
+ //returns the internal value for testing reasons
+ //sets the validity to valid on invalid
+ return(new MetricValue(_internalValue, _returnValid));
+
+ }
+
+ override internal function getValue():MetricValue
+ {
+ return getValueForced();
+ }
+
+ public function get returnValid():Boolean
+ {
+ return _returnValid;
+ }
+
+ public function set returnValid(value:Boolean):void
+ {
+ _returnValid = value;
+ }
+
+ public function get internalValue():Number
+ {
+ return _internalValue;
+ }
+
+ public function set internalValue(value:Number):void
+ {
+ _internalValue = value;
+ }
+
+ private var _internalValue:Number=0;
+ private var _returnValid:Boolean;
+ }
+}
\ No newline at end of file
diff --git a/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/AvailableQualityLevelsMetricMocker.as b/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/AvailableQualityLevelsMetricMocker.as
new file mode 100644
index 0000000..27782c3
--- /dev/null
+++ b/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/AvailableQualityLevelsMetricMocker.as
@@ -0,0 +1,72 @@
+/*****************************************************
+ *
+ * Copyright 2011 Adobe Systems Incorporated. All Rights Reserved.
+ *
+ *****************************************************
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ *
+ * The Initial Developer of the Original Code is Adobe Systems Incorporated.
+ * Portions created by Adobe Systems Incorporated are Copyright (C) 2011 Adobe Systems
+ * Incorporated. All Rights Reserved.
+ *
+ *****************************************************/
+package org.osmf.net.metrics
+{
+ import org.osmf.net.qos.QoSInfoHistory;
+ import org.osmf.net.qos.QualityLevel;
+
+ public class AvailableQualityLevelsMetricMocker extends AvailableQualityLevelsMetric
+ {
+ public function AvailableQualityLevelsMetricMocker(qosInfoHistory:QoSInfoHistory)
+ {
+ super(qosInfoHistory);
+ _internalValue=undefined;
+ _returnValid=false;
+ }
+
+ override protected function getValueForced():MetricValue
+ {
+ //returns the internal value for testing reasons
+ //sets the validity to valid on invalid
+ return(new MetricValue(_internalValue, _returnValid));
+
+ }
+
+ override internal function getValue():MetricValue
+ {
+ return getValueForced();
+ }
+
+ public function get returnValid():Boolean
+ {
+ return _returnValid;
+ }
+
+ public function set returnValid(value:Boolean):void
+ {
+ _returnValid = value;
+ }
+
+ public function get internalValue():Vector.
+ {
+ return _internalValue;
+ }
+
+ public function set internalValue(value:Vector.):void
+ {
+ _internalValue = value;
+ }
+
+ private var _internalValue:Vector.=null;
+ private var _returnValid:Boolean;
+ }
+}
\ No newline at end of file
diff --git a/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/BandwidthMetricMocker.as b/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/BandwidthMetricMocker.as
new file mode 100644
index 0000000..5bbebfb
--- /dev/null
+++ b/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/BandwidthMetricMocker.as
@@ -0,0 +1,71 @@
+/*****************************************************
+ *
+ * Copyright 2011 Adobe Systems Incorporated. All Rights Reserved.
+ *
+ *****************************************************
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ *
+ * The Initial Developer of the Original Code is Adobe Systems Incorporated.
+ * Portions created by Adobe Systems Incorporated are Copyright (C) 2011 Adobe Systems
+ * Incorporated. All Rights Reserved.
+ *
+ *****************************************************/
+package org.osmf.net.metrics
+{
+ import org.osmf.net.qos.QoSInfoHistory;
+
+ public class BandwidthMetricMocker extends BandwidthMetric
+ {
+ public function BandwidthMetricMocker(qosInfoHistory:QoSInfoHistory, weights:Vector.)
+ {
+ super(qosInfoHistory, weights);
+ _internalValue=undefined;
+ _returnValid=false;
+ }
+
+ override protected function getValueForced():MetricValue
+ {
+ //returns the internal value for testing reasons
+ //sets the validity to valid on invalid
+ return(new MetricValue(_internalValue, _returnValid));
+
+ }
+
+ override internal function getValue():MetricValue
+ {
+ return getValueForced();
+ }
+
+ public function get returnValid():Boolean
+ {
+ return _returnValid;
+ }
+
+ public function set returnValid(value:Boolean):void
+ {
+ _returnValid = value;
+ }
+
+ public function get internalValue():Number
+ {
+ return _internalValue;
+ }
+
+ public function set internalValue(value:Number):void
+ {
+ _internalValue = value;
+ }
+
+ private var _internalValue:Number=0;
+ private var _returnValid:Boolean;
+ }
+}
\ No newline at end of file
diff --git a/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/BufferFragmentsMetricMocker.as b/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/BufferFragmentsMetricMocker.as
new file mode 100644
index 0000000..dc8bcc8
--- /dev/null
+++ b/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/BufferFragmentsMetricMocker.as
@@ -0,0 +1,71 @@
+/*****************************************************
+ *
+ * Copyright 2011 Adobe Systems Incorporated. All Rights Reserved.
+ *
+ *****************************************************
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ *
+ * The Initial Developer of the Original Code is Adobe Systems Incorporated.
+ * Portions created by Adobe Systems Incorporated are Copyright (C) 2011 Adobe Systems
+ * Incorporated. All Rights Reserved.
+ *
+ *****************************************************/
+package org.osmf.net.metrics
+{
+ import org.osmf.net.qos.QoSInfoHistory;
+
+ public class BufferFragmentsMetricMocker extends BufferFragmentsMetric
+ {
+ public function BufferFragmentsMetricMocker(qosInfoHistory:QoSInfoHistory)
+ {
+ super(qosInfoHistory);
+ _internalValue=undefined;
+ _returnValid=false;
+ }
+
+ override protected function getValueForced():MetricValue
+ {
+ //returns the internal value for testing reasons
+ //sets the validity to valid on invalid
+ return(new MetricValue(_internalValue, _returnValid));
+
+ }
+
+ override internal function getValue():MetricValue
+ {
+ return getValueForced();
+ }
+
+ public function get returnValid():Boolean
+ {
+ return _returnValid;
+ }
+
+ public function set returnValid(value:Boolean):void
+ {
+ _returnValid = value;
+ }
+
+ public function get internalValue():Number
+ {
+ return _internalValue;
+ }
+
+ public function set internalValue(value:Number):void
+ {
+ _internalValue = value;
+ }
+
+ private var _internalValue:Number=0;
+ private var _returnValid:Boolean;
+ }
+}
\ No newline at end of file
diff --git a/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/BufferLengthMetricMocker.as b/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/BufferLengthMetricMocker.as
new file mode 100644
index 0000000..7201f85
--- /dev/null
+++ b/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/BufferLengthMetricMocker.as
@@ -0,0 +1,71 @@
+/*****************************************************
+ *
+ * Copyright 2011 Adobe Systems Incorporated. All Rights Reserved.
+ *
+ *****************************************************
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ *
+ * The Initial Developer of the Original Code is Adobe Systems Incorporated.
+ * Portions created by Adobe Systems Incorporated are Copyright (C) 2011 Adobe Systems
+ * Incorporated. All Rights Reserved.
+ *
+ *****************************************************/
+package org.osmf.net.metrics
+{
+ import org.osmf.net.qos.QoSInfoHistory;
+
+ public class BufferLengthMetricMocker extends BufferLengthMetric
+ {
+ public function BufferLengthMetricMocker(qosInfoHistory:QoSInfoHistory)
+ {
+ super(qosInfoHistory);
+ _internalValue=undefined;
+ _returnValid=false;
+ }
+
+ override protected function getValueForced():MetricValue
+ {
+ //returns the internal value for testing reasons
+ //sets the validity to valid on invalid
+ return(new MetricValue(_internalValue, _returnValid));
+
+ }
+
+ override internal function getValue():MetricValue
+ {
+ return getValueForced();
+ }
+
+ public function get returnValid():Boolean
+ {
+ return _returnValid;
+ }
+
+ public function set returnValid(value:Boolean):void
+ {
+ _returnValid = value;
+ }
+
+ public function get internalValue():Number
+ {
+ return _internalValue;
+ }
+
+ public function set internalValue(value:Number):void
+ {
+ _internalValue = value;
+ }
+
+ private var _internalValue:Number=0;
+ private var _returnValid:Boolean;
+ }
+}
\ No newline at end of file
diff --git a/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/BufferOccupationRatioMetricMocker.as b/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/BufferOccupationRatioMetricMocker.as
new file mode 100644
index 0000000..87ee1fc
--- /dev/null
+++ b/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/BufferOccupationRatioMetricMocker.as
@@ -0,0 +1,71 @@
+/*****************************************************
+ *
+ * Copyright 2011 Adobe Systems Incorporated. All Rights Reserved.
+ *
+ *****************************************************
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ *
+ * The Initial Developer of the Original Code is Adobe Systems Incorporated.
+ * Portions created by Adobe Systems Incorporated are Copyright (C) 2011 Adobe Systems
+ * Incorporated. All Rights Reserved.
+ *
+ *****************************************************/
+package org.osmf.net.metrics
+{
+ import org.osmf.net.qos.QoSInfoHistory;
+
+ public class BufferOccupationRatioMetricMocker extends BufferOccupationRatioMetric
+ {
+ public function BufferOccupationRatioMetricMocker(qosInfoHistory:QoSInfoHistory)
+ {
+ super(qosInfoHistory);
+ _internalValue=undefined;
+ _returnValid=false;
+ }
+
+ override protected function getValueForced():MetricValue
+ {
+ //returns the internal value for testing reasons
+ //sets the validity to valid on invalid
+ return(new MetricValue(_internalValue, _returnValid));
+
+ }
+
+ override internal function getValue():MetricValue
+ {
+ return getValueForced();
+ }
+
+ public function get returnValid():Boolean
+ {
+ return _returnValid;
+ }
+
+ public function set returnValid(value:Boolean):void
+ {
+ _returnValid = value;
+ }
+
+ public function get internalValue():Number
+ {
+ return _internalValue;
+ }
+
+ public function set internalValue(value:Number):void
+ {
+ _internalValue = value;
+ }
+
+ private var _internalValue:Number=0;
+ private var _returnValid:Boolean;
+ }
+}
\ No newline at end of file
diff --git a/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/CurrentStatusMetricMocker.as b/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/CurrentStatusMetricMocker.as
new file mode 100644
index 0000000..21d3732
--- /dev/null
+++ b/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/CurrentStatusMetricMocker.as
@@ -0,0 +1,73 @@
+/*****************************************************
+ *
+ * Copyright 2011 Adobe Systems Incorporated. All Rights Reserved.
+ *
+ *****************************************************
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ *
+ * The Initial Developer of the Original Code is Adobe Systems Incorporated.
+ * Portions created by Adobe Systems Incorporated are Copyright (C) 2011 Adobe Systems
+ * Incorporated. All Rights Reserved.
+ *
+ *****************************************************/
+package org.osmf.net.metrics
+{
+ import org.osmf.net.qos.QoSInfoHistory;
+ import org.osmf.net.qos.QualityLevel;
+
+ public class CurrentStatusMetricMocker extends CurrentStatusMetric
+ {
+ public function CurrentStatusMetricMocker(qosInfoHistory:QoSInfoHistory)
+ {
+ super(qosInfoHistory);
+ _internalValue=undefined;
+ _returnValid=false;
+ }
+
+ override protected function getValueForced():MetricValue
+ {
+ //returns the internal value for testing reasons
+ //sets the validity to valid on invalid
+ return(new MetricValue(_internalValue, _returnValid));
+
+ }
+
+ override internal function getValue():MetricValue
+ {
+ return getValueForced();
+ }
+
+
+ public function get returnValid():Boolean
+ {
+ return _returnValid;
+ }
+
+ public function set returnValid(value:Boolean):void
+ {
+ _returnValid = value;
+ }
+
+ public function get internalValue():Vector.
+ {
+ return _internalValue;
+ }
+
+ public function set internalValue(value:Vector.):void
+ {
+ _internalValue = value;
+ }
+
+ private var _internalValue:Vector.=null;
+ private var _returnValid:Boolean;
+ }
+}
\ No newline at end of file
diff --git a/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/DefaultMetricFactoryMocker.as b/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/DefaultMetricFactoryMocker.as
new file mode 100644
index 0000000..2a8940e
--- /dev/null
+++ b/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/DefaultMetricFactoryMocker.as
@@ -0,0 +1,185 @@
+/*****************************************************
+ *
+ * Copyright 2011 Adobe Systems Incorporated. All Rights Reserved.
+ *
+ *****************************************************
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ *
+ * The Initial Developer of the Original Code is Adobe Systems Incorporated.
+ * Portions created by Adobe Systems Incorporated are Copyright (C) 2011 Adobe Systems
+ * Incorporated. All Rights Reserved.
+ *
+ *****************************************************/
+package org.osmf.net.metrics
+{
+ import org.osmf.net.qos.QoSInfoHistory;
+
+ /**
+ * DefaultMetricFactory is the default implementation of the MetricFactory.
+ *
+ * @langversion 3.0
+ * @playerversion Flash 10
+ * @playerversion AIR 1.5
+ * @productversion OSMF 2.0
+ */
+ public class DefaultMetricFactoryMocker extends MetricFactory
+ {
+ /**
+ * Constructor.
+ *
+ * @langversion 3.0
+ * @playerversion Flash 10
+ * @playerversion AIR 1.5
+ * @productversion OSMF 2.0
+ */
+ public function DefaultMetricFactoryMocker(qosInfoHistory:QoSInfoHistory)
+ {
+ super(qosInfoHistory);
+
+ init();
+ }
+
+ private function init():void
+ {
+ addItem
+ ( new MetricFactoryItem
+ ( MetricType.ACTUAL_BITRATE
+ , function(qosInfoHistory:QoSInfoHistory, maxFragments:uint = 5):MetricBase
+ {
+ return new ActualBitrateMetricMocker(qosInfoHistory, maxFragments);
+ }
+ )
+ );
+
+ addItem
+ ( new MetricFactoryItem
+ ( MetricType.FRAGMENT_COUNT
+ , function(qosInfoHistory:QoSInfoHistory):MetricBase
+ {
+ return new FragmentCountMetricMocker(qosInfoHistory);
+ }
+ )
+ );
+
+ addItem
+ ( new MetricFactoryItem
+ ( MetricType.AVAILABLE_QUALITY_LEVELS
+ , function(qosInfoHistory:QoSInfoHistory):MetricBase
+ {
+ return new AvailableQualityLevelsMetricMocker(qosInfoHistory);
+ }
+ )
+ );
+
+ addItem
+ ( new MetricFactoryItem
+ ( MetricType.CURRENT_STATUS
+ , function(qosInfoHistory:QoSInfoHistory):MetricBase
+ {
+ return new CurrentStatusMetricMocker(qosInfoHistory);
+ }
+ )
+ );
+
+ addItem
+ ( new MetricFactoryItem
+ ( MetricType.BANDWIDTH
+ , function(qosInfoHistory:QoSInfoHistory, weights:Vector.):MetricBase
+ {
+ return new BandwidthMetricMocker(qosInfoHistory, weights);
+ }
+ )
+ );
+
+ addItem
+ ( new MetricFactoryItem
+ ( MetricType.FPS
+ , function(qosInfoHistory:QoSInfoHistory):MetricBase
+ {
+ return new FPSMetricMocker(qosInfoHistory);
+ }
+ )
+ );
+
+ addItem
+ ( new MetricFactoryItem
+ ( MetricType.DROPPED_FPS
+ , function(qosInfoHistory:QoSInfoHistory, desiredSampleLength:Number = 10):MetricBase
+ {
+ return new DroppedFPSMetricMocker(qosInfoHistory, desiredSampleLength);
+ }
+ )
+ );
+
+ addItem
+ ( new MetricFactoryItem
+ ( MetricType.BUFFER_OCCUPATION_RATIO
+ , function(qosInfoHistory:QoSInfoHistory):MetricBase
+ {
+ return new BufferOccupationRatioMetricMocker(qosInfoHistory);
+ }
+ )
+ );
+
+ addItem
+ ( new MetricFactoryItem
+ ( MetricType.BUFFER_LENGTH
+ , function(qosInfoHistory:QoSInfoHistory):MetricBase
+ {
+ return new BufferLengthMetricMocker(qosInfoHistory);
+ }
+ )
+ );
+
+ addItem
+ ( new MetricFactoryItem
+ ( MetricType.BUFFER_FRAGMENTS
+ , function(qosInfoHistory:QoSInfoHistory):MetricBase
+ {
+ return new BufferFragmentsMetricMocker(qosInfoHistory);
+ }
+ )
+ );
+
+ addItem
+ ( new MetricFactoryItem
+ ( MetricType.EMPTY_BUFFER
+ , function(qosInfoHistory:QoSInfoHistory):MetricBase
+ {
+ return new EmptyBufferMetricMocker(qosInfoHistory);
+ }
+ )
+ );
+
+ addItem
+ ( new MetricFactoryItem
+ ( MetricType.RECENT_SWITCH
+ , function(qosInfoHistory:QoSInfoHistory):MetricBase
+ {
+ return new RecentSwitchMetricMocker(qosInfoHistory);
+ }
+ )
+ );
+ }
+
+ private function generateWeights(... weights):Vector.
+ {
+ var v:Vector. = new Vector.();
+ for(var i:uint=0; i< weights.length; i++)
+ {
+ v[i] = weights[i] ;
+ }
+ return (v);
+ }
+
+ }
+}
\ No newline at end of file
diff --git a/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/DroppedFPSMetricMocker.as b/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/DroppedFPSMetricMocker.as
new file mode 100644
index 0000000..7b23053
--- /dev/null
+++ b/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/DroppedFPSMetricMocker.as
@@ -0,0 +1,71 @@
+/*****************************************************
+ *
+ * Copyright 2011 Adobe Systems Incorporated. All Rights Reserved.
+ *
+ *****************************************************
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ *
+ * The Initial Developer of the Original Code is Adobe Systems Incorporated.
+ * Portions created by Adobe Systems Incorporated are Copyright (C) 2011 Adobe Systems
+ * Incorporated. All Rights Reserved.
+ *
+ *****************************************************/
+package org.osmf.net.metrics
+{
+ import org.osmf.net.qos.QoSInfoHistory;
+
+ public class DroppedFPSMetricMocker extends DroppedFPSMetric
+ {
+ public function DroppedFPSMetricMocker(qosInfoHistory:QoSInfoHistory, desiredSampleLength:Number = 10)
+ {
+ super(qosInfoHistory);
+ _internalValue=undefined;
+ _returnValid=false;
+ }
+
+ override protected function getValueForced():MetricValue
+ {
+ //returns the internal value for testing reasons
+ //sets the validity to valid on invalid
+ return(new MetricValue(_internalValue, _returnValid));
+
+ }
+
+ override internal function getValue():MetricValue
+ {
+ return getValueForced();
+ }
+
+ public function get returnValid():Boolean
+ {
+ return _returnValid;
+ }
+
+ public function set returnValid(value:Boolean):void
+ {
+ _returnValid = value;
+ }
+
+ public function get internalValue():Number
+ {
+ return _internalValue;
+ }
+
+ public function set internalValue(value:Number):void
+ {
+ _internalValue = value;
+ }
+
+ private var _internalValue:Number=0;
+ private var _returnValid:Boolean;
+ }
+}
\ No newline at end of file
diff --git a/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/EmptyBufferMetricMocker.as b/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/EmptyBufferMetricMocker.as
new file mode 100644
index 0000000..5f60545
--- /dev/null
+++ b/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/EmptyBufferMetricMocker.as
@@ -0,0 +1,71 @@
+/*****************************************************
+ *
+ * Copyright 2011 Adobe Systems Incorporated. All Rights Reserved.
+ *
+ *****************************************************
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ *
+ * The Initial Developer of the Original Code is Adobe Systems Incorporated.
+ * Portions created by Adobe Systems Incorporated are Copyright (C) 2011 Adobe Systems
+ * Incorporated. All Rights Reserved.
+ *
+ *****************************************************/
+package org.osmf.net.metrics
+{
+ import org.osmf.net.qos.QoSInfoHistory;
+
+ public class EmptyBufferMetricMocker extends EmptyBufferMetric
+ {
+ public function EmptyBufferMetricMocker(qosInfoHistory:QoSInfoHistory)
+ {
+ super(qosInfoHistory);
+ _internalValue=undefined;
+ _returnValid=false;
+ }
+
+ override protected function getValueForced():MetricValue
+ {
+ //returns the internal value for testing reasons
+ //sets the validity to valid on invalid
+ return(new MetricValue(_internalValue, _returnValid));
+
+ }
+
+ override internal function getValue():MetricValue
+ {
+ return getValueForced();
+ }
+
+ public function get returnValid():Boolean
+ {
+ return _returnValid;
+ }
+
+ public function set returnValid(value:Boolean):void
+ {
+ _returnValid = value;
+ }
+
+ public function get internalValue():Boolean
+ {
+ return _internalValue;
+ }
+
+ public function set internalValue(value:Boolean):void
+ {
+ _internalValue = value;
+ }
+
+ private var _internalValue:Boolean = false;
+ private var _returnValid:Boolean;
+ }
+}
\ No newline at end of file
diff --git a/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/FPSMetricMocker.as b/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/FPSMetricMocker.as
new file mode 100644
index 0000000..8aaec9f
--- /dev/null
+++ b/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/FPSMetricMocker.as
@@ -0,0 +1,73 @@
+/*****************************************************
+ *
+ * Copyright 2011 Adobe Systems Incorporated. All Rights Reserved.
+ *
+ *****************************************************
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ *
+ * The Initial Developer of the Original Code is Adobe Systems Incorporated.
+ * Portions created by Adobe Systems Incorporated are Copyright (C) 2011 Adobe Systems
+ * Incorporated. All Rights Reserved.
+ *
+ *****************************************************/
+package org.osmf.net.metrics
+{
+ import org.osmf.net.qos.QoSInfoHistory;
+
+ public class FPSMetricMocker extends FPSMetric
+ {
+ public function FPSMetricMocker(qosInfoHistory:QoSInfoHistory)
+ {
+ super(qosInfoHistory);
+ _internalValue=undefined;
+ _returnValid=false;
+ }
+
+ override protected function getValueForced():MetricValue
+ {
+ //returns the internal value for testing reasons
+ //sets the validity to valid on invalid
+ return(new MetricValue(_internalValue, _returnValid));
+
+ }
+
+
+ override internal function getValue():MetricValue
+ {
+ return getValueForced();
+ }
+
+
+ public function get returnValid():Boolean
+ {
+ return _returnValid;
+ }
+
+ public function set returnValid(value:Boolean):void
+ {
+ _returnValid = value;
+ }
+
+ public function get internalValue():Number
+ {
+ return _internalValue;
+ }
+
+ public function set internalValue(value:Number):void
+ {
+ _internalValue = value;
+ }
+
+ private var _internalValue:Number=0;
+ private var _returnValid:Boolean;
+ }
+}
\ No newline at end of file
diff --git a/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/FragmentCountMetricMocker.as b/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/FragmentCountMetricMocker.as
new file mode 100644
index 0000000..b1e1320
--- /dev/null
+++ b/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/FragmentCountMetricMocker.as
@@ -0,0 +1,71 @@
+/*****************************************************
+ *
+ * Copyright 2011 Adobe Systems Incorporated. All Rights Reserved.
+ *
+ *****************************************************
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ *
+ * The Initial Developer of the Original Code is Adobe Systems Incorporated.
+ * Portions created by Adobe Systems Incorporated are Copyright (C) 2011 Adobe Systems
+ * Incorporated. All Rights Reserved.
+ *
+ *****************************************************/
+package org.osmf.net.metrics
+{
+ import org.osmf.net.qos.QoSInfoHistory;
+
+ public class FragmentCountMetricMocker extends FragmentCountMetric
+ {
+ public function FragmentCountMetricMocker(qosInfoHistory:QoSInfoHistory)
+ {
+ super(qosInfoHistory);
+ _internalValue=undefined;
+ _returnValid=false;
+ }
+
+ override protected function getValueForced():MetricValue
+ {
+ //returns the internal value for testing reasons
+ //sets the validity to valid on invalid
+ return(new MetricValue(_internalValue, _returnValid));
+
+ }
+
+ override internal function getValue():MetricValue
+ {
+ return getValueForced();
+ }
+
+ public function get returnValid():Boolean
+ {
+ return _returnValid;
+ }
+
+ public function set returnValid(value:Boolean):void
+ {
+ _returnValid = value;
+ }
+
+ public function get internalValue():int
+ {
+ return _internalValue;
+ }
+
+ public function set internalValue(value:int):void
+ {
+ _internalValue = value;
+ }
+
+ private var _internalValue:int=0;
+ private var _returnValid:Boolean;
+ }
+}
\ No newline at end of file
diff --git a/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/MetricComplexMocker.as b/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/MetricComplexMocker.as
new file mode 100644
index 0000000..24eb256
--- /dev/null
+++ b/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/MetricComplexMocker.as
@@ -0,0 +1,55 @@
+/*****************************************************
+ *
+ * Copyright 2011 Adobe Systems Incorporated. All Rights Reserved.
+ *
+ *****************************************************
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ *
+ * The Initial Developer of the Original Code is Adobe Systems Incorporated.
+ * Portions created by Adobe Systems Incorporated are Copyright (C) 2011 Adobe Systems
+ * Incorporated. All Rights Reserved.
+ *
+ *****************************************************/
+package org.osmf.net.metrics
+{
+ import org.osmf.net.qos.QoSInfoHistory;
+
+ public class MetricComplexMocker extends MetricBase
+ {
+ public function MetricComplexMocker(type:String, qosInfoHistory:QoSInfoHistory, returnValid:Boolean = true)
+ {
+ super(qosInfoHistory, type);
+ _returnValid = returnValid;
+ }
+
+ override protected function getValueForced():MetricValue
+ {
+ //returns the last playhead time for testing reasons
+ //sets the validity to valid on invalid
+ return(new MetricValue(++internalValue, _returnValid));
+
+ }
+
+ public function get returnValid():Boolean
+ {
+ return _returnValid;
+ }
+
+ public function set returnValid(value:Boolean):void
+ {
+ _returnValid = value;
+ }
+
+ private var internalValue:int=0;
+ private var _returnValid:Boolean;
+ }
+}
\ No newline at end of file
diff --git a/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/MetricFactoryMocker.as b/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/MetricFactoryMocker.as
new file mode 100644
index 0000000..b7e6530
--- /dev/null
+++ b/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/MetricFactoryMocker.as
@@ -0,0 +1,45 @@
+/*****************************************************
+ *
+ * Copyright 2011 Adobe Systems Incorporated. All Rights Reserved.
+ *
+ *****************************************************
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ *
+ * The Initial Developer of the Original Code is Adobe Systems Incorporated.
+ * Portions created by Adobe Systems Incorporated are Copyright (C) 2011 Adobe Systems
+ * Incorporated. All Rights Reserved.
+ *
+ *****************************************************/
+package org.osmf.net.metrics
+{
+ import org.osmf.net.qos.QoSInfoHistory;
+ import org.osmf.net.qos.QoSInfoHistoryGenerator;
+
+ public class MetricFactoryMocker extends MetricFactory
+ {
+ public function MetricFactoryMocker(qosInfoHistory:QoSInfoHistory = null)
+ {
+ super(qosInfoHistory);
+ }
+
+ /**
+ * qosInfoHistory is ignored (so it can safely be null)
+ * the parameters should only contain one MetricValue object (the desired return value of the metric)
+ */
+ override public function buildMetric(type:String, ...args):MetricBase
+ {
+ var returnValue:MetricValue = args[0];
+
+ return new MetricMocker(type, QoSInfoHistoryGenerator.generateSampleQoSInfoHistory(), returnValue);
+ }
+ }
+}
\ No newline at end of file
diff --git a/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/MetricMocker.as b/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/MetricMocker.as
new file mode 100644
index 0000000..421ef7c
--- /dev/null
+++ b/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/MetricMocker.as
@@ -0,0 +1,54 @@
+/*****************************************************
+ *
+ * Copyright 2011 Adobe Systems Incorporated. All Rights Reserved.
+ *
+ *****************************************************
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ *
+ * The Initial Developer of the Original Code is Adobe Systems Incorporated.
+ * Portions created by Adobe Systems Incorporated are Copyright (C) 2011 Adobe Systems
+ * Incorporated. All Rights Reserved.
+ *
+ *****************************************************/
+package org.osmf.net.metrics
+{
+ import org.osmf.net.qos.QoSInfoHistory;
+
+ public class MetricMocker extends MetricBase
+ {
+ public function MetricMocker(type:String, qosInfoHistory:QoSInfoHistory, returnValue:MetricValue = null, v:Vector. = null, ... args)
+ {
+ super(qosInfoHistory, type);
+ _returnValue = returnValue;
+ _vector = v;
+ }
+
+ public function set returnValue(value:MetricValue):void
+ {
+ _returnValue = value;
+ }
+
+ override internal function getValue():MetricValue
+ {
+ return _returnValue;
+ }
+
+ public function get vector():Vector.
+ {
+ return _vector;
+ }
+
+
+ private var _returnValue:MetricValue;
+ private var _vector:Vector.=null;
+ }
+}
\ No newline at end of file
diff --git a/lib/osmf/player/StrobeMediaPlaybackTest/src/org/osmf/net/MockHTTPStreamQoSInfo.as b/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/MetricRepositoryMocker.as
similarity index 62%
rename from lib/osmf/player/StrobeMediaPlaybackTest/src/org/osmf/net/MockHTTPStreamQoSInfo.as
rename to lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/MetricRepositoryMocker.as
index c3afb41..d762966 100644
--- a/lib/osmf/player/StrobeMediaPlaybackTest/src/org/osmf/net/MockHTTPStreamQoSInfo.as
+++ b/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/MetricRepositoryMocker.as
@@ -1,52 +1,42 @@
-/*****************************************************
- *
- * Copyright 2011 Adobe Systems Incorporated. All Rights Reserved.
- *
- *****************************************************
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
- * License for the specific language governing rights and limitations
- * under the License.
- *
- *
- * The Initial Developer of the Original Code is Adobe Systems Incorporated.
- * Portions created by Adobe Systems Incorporated are Copyright (C) 2011 Adobe Systems
- * Incorporated. All Rights Reserved.
- *
- *****************************************************/
-package org.osmf.net
-{
- [ExcludeClass]
-
- import org.osmf.net.httpstreaming.HTTPStreamQoSInfo;
-
- /**
- * @private
- *
- * Mock implementation for HTTP Streaming QOS information.
- */
- public class MockHTTPStreamQoSInfo extends HTTPStreamQoSInfo
- {
- /**
- * Default constructor.
- */
- public function MockHTTPStreamQoSInfo(desiredRatio:Number)
- {
- super(0,0,0);
- _desiredRatio = desiredRatio;
- }
-
- override public function get downloadRatio():Number
- {
- return _desiredRatio;
- }
-
- /// Internals
- private var _desiredRatio:Number = 0;
- }
+/*****************************************************
+ *
+ * Copyright 2011 Adobe Systems Incorporated. All Rights Reserved.
+ *
+ *****************************************************
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ *
+ * The Initial Developer of the Original Code is Adobe Systems Incorporated.
+ * Portions created by Adobe Systems Incorporated are Copyright (C) 2011 Adobe Systems
+ * Incorporated. All Rights Reserved.
+ *
+ *****************************************************/
+package org.osmf.net.metrics
+{
+ import org.osmf.net.qos.QoSInfoHistoryGenerator;
+
+ public class MetricRepositoryMocker extends MetricRepository
+ {
+ public function MetricRepositoryMocker(metricFactory:MetricFactory)
+ {
+ super(metricFactory);
+ }
+
+ /**
+ * Second parameter should be the desired return value of the metric (a MetricValue object)
+ */
+ override public function getMetric(type:String, ...parameters):MetricBase
+ {
+ var returnValue:MetricValue = parameters[0];
+ return new MetricMocker(type, QoSInfoHistoryGenerator.generateSampleQoSInfoHistory(), returnValue);
+ }
+ }
}
\ No newline at end of file
diff --git a/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/RecentSwitchMetricMocker.as b/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/RecentSwitchMetricMocker.as
new file mode 100644
index 0000000..88ac5ea
--- /dev/null
+++ b/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/RecentSwitchMetricMocker.as
@@ -0,0 +1,71 @@
+/*****************************************************
+ *
+ * Copyright 2011 Adobe Systems Incorporated. All Rights Reserved.
+ *
+ *****************************************************
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ *
+ * The Initial Developer of the Original Code is Adobe Systems Incorporated.
+ * Portions created by Adobe Systems Incorporated are Copyright (C) 2011 Adobe Systems
+ * Incorporated. All Rights Reserved.
+ *
+ *****************************************************/
+package org.osmf.net.metrics
+{
+ import org.osmf.net.qos.QoSInfoHistory;
+
+ public class RecentSwitchMetricMocker extends RecentSwitchMetric
+ {
+ public function RecentSwitchMetricMocker(qosInfoHistory:QoSInfoHistory)
+ {
+ super(qosInfoHistory);
+ _internalValue=undefined;
+ _returnValid=false;
+ }
+
+ override protected function getValueForced():MetricValue
+ {
+ //returns the internal value for testing reasons
+ //sets the validity to valid on invalid
+ return(new MetricValue(_internalValue, _returnValid));
+
+ }
+
+ override internal function getValue():MetricValue
+ {
+ return getValueForced();
+ }
+
+ public function get returnValid():Boolean
+ {
+ return _returnValid;
+ }
+
+ public function set returnValid(value:Boolean):void
+ {
+ _returnValid = value;
+ }
+
+ public function get internalValue():int
+ {
+ return _internalValue;
+ }
+
+ public function set internalValue(value:int):void
+ {
+ _internalValue = value;
+ }
+
+ private var _internalValue:int=0;
+ private var _returnValid:Boolean;
+ }
+}
\ No newline at end of file
diff --git a/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/TestActualBitrateMetric.as b/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/TestActualBitrateMetric.as
new file mode 100644
index 0000000..8818c00
--- /dev/null
+++ b/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/TestActualBitrateMetric.as
@@ -0,0 +1,194 @@
+/*****************************************************
+ *
+ * Copyright 2011 Adobe Systems Incorporated. All Rights Reserved.
+ *
+ *****************************************************
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ *
+ * The Initial Developer of the Original Code is Adobe Systems Incorporated.
+ * Portions created by Adobe Systems Incorporated are Copyright (C) 2011 Adobe Systems
+ * Incorporated. All Rights Reserved.
+ *
+ *****************************************************/
+package org.osmf.net.metrics
+{
+ import flash.net.NetConnection;
+ import flash.net.NetStream;
+
+ import flashx.textLayout.debug.assert;
+
+ import flexunit.framework.Assert;
+
+ import org.flexunit.asserts.assertEquals;
+ import org.flexunit.asserts.assertFalse;
+ import org.flexunit.asserts.assertTrue;
+ import org.osmf.events.QoSInfoEvent;
+ import org.osmf.net.qos.FragmentDetails;
+ import org.osmf.net.qos.QoSInfo;
+ import org.osmf.net.qos.QoSInfoHistory;
+ import org.osmf.net.qos.QualityLevel;
+
+ public class TestActualBitrateMetric
+ {
+ [Before]
+ public function setUp():void
+ {
+ var conn:NetConnection = new NetConnection();
+ conn.connect(null);
+ netStream = new NetStream(conn);
+ qosInfoHistory = new QoSInfoHistory(netStream);
+ }
+
+ [After]
+ public function tearDown():void
+ {
+ }
+
+ [BeforeClass]
+ public static function setUpBeforeClass():void
+ {
+ }
+
+ [AfterClass]
+ public static function tearDownAfterClass():void
+ {
+ }
+
+
+ [Test]
+ public function testActualBitrateMetric():void
+ {
+ metric = new ActualBitrateMetric(qosInfoHistory, 5);
+
+ assertEquals(MetricType.ACTUAL_BITRATE, metric.type);
+ assertEquals(5, metric.maxFragments);
+ var metricValue:MetricValue = metric.value;
+
+ assertEquals(undefined, metricValue.value);
+ assertFalse(metricValue.valid);
+ }
+
+
+ [Test(expects="ArgumentError")]
+ public function testActualBitrateMetricZeroFragments():void
+ {
+ metric = new ActualBitrateMetric(qosInfoHistory, 0);
+ }
+
+
+ [Test]
+ public function testGetValueForMoreFragmentsNoSimilarFragmentsOutside():void
+ {
+ metric = new ActualBitrateMetric(qosInfoHistory, 5);
+ assertEquals(MetricType.ACTUAL_BITRATE, metric.type);
+
+ addQoSInfo(generateQoSInfo(1111, 0, new FragmentDetails(1400000, 4010, 2001, 0)));
+ addQoSInfo(generateQoSInfo(2222, 0, new FragmentDetails(2400000, 4020, 4001, 1)));
+ addQoSInfo(generateQoSInfo(3333, 1, new FragmentDetails(3500000, 4040, 6001, 1)));
+ addQoSInfo(generateQoSInfo(4444, 1, new FragmentDetails(4600000, 4030, 8001, 0)));
+ addQoSInfo(generateQoSInfo(5555, 0, new FragmentDetails(5400000, 4050, 3001, 1)));
+ addQoSInfo(generateQoSInfo(6666, 1, new FragmentDetails(3200000, 4070, 5001, 2)));
+
+
+ var metricValue:MetricValue = metric.value;
+
+ assertEquals((2400000+3500000+5400000) / (4020+4040+4050)*8/1000, metricValue.value);
+ assertTrue(metricValue.valid);
+ }
+
+ [Test]
+ public function testGetValueForMoreFragments():void
+ {
+ metric = new ActualBitrateMetric(qosInfoHistory, 5);
+ assertEquals(MetricType.ACTUAL_BITRATE, metric.type);
+
+ addQoSInfo(generateQoSInfo(1111, 0, new FragmentDetails(1400000, 4010, 2001, 0)));
+ addQoSInfo(generateQoSInfo(2222, 0, new FragmentDetails(2400000, 4020, 4001, 1)));
+ addQoSInfo(generateQoSInfo(3333, 1, new FragmentDetails(3500000, 4040, 6001, 1)));
+ addQoSInfo(generateQoSInfo(3333, 1, new FragmentDetails(3500001, 4041, 6001, 1)));
+ addQoSInfo(generateQoSInfo(3333, 1, new FragmentDetails(3500002, 4042, 6001, 1)));
+ addQoSInfo(generateQoSInfo(3333, 1, new FragmentDetails(3500003, 4043, 6001, 1)));
+ addQoSInfo(generateQoSInfo(4444, 1, new FragmentDetails(4600000, 4030, 8001, 0)));
+ addQoSInfo(generateQoSInfo(5555, 0, new FragmentDetails(5400000, 4050, 3001, 1)));
+ addQoSInfo(generateQoSInfo(6666, 1, new FragmentDetails(3200000, 4070, 5001, 2)));
+
+
+ var metricValue:MetricValue = metric.value;
+
+ assertEquals((3500002+3500003+5400000) / (4042+4043+4050)*8/1000, metricValue.value);
+ assertTrue(metricValue.valid);
+ }
+
+ [Test]
+ public function testGetValueForLessFragmentsAndShortHistory():void
+ {
+ metric = new ActualBitrateMetric(qosInfoHistory, 5);
+ assertEquals(MetricType.ACTUAL_BITRATE, metric.type);
+
+ addQoSInfo(generateQoSInfo(1111, 0, new FragmentDetails(1400000, 4010, 2001, 0)));
+ addQoSInfo(generateQoSInfo(2222, 0, new FragmentDetails(2400000, 4020, 4001, 1)));
+ addQoSInfo(generateQoSInfo(3333, 1, new FragmentDetails(3500000, 4040, 6001, 1)));
+
+
+ var metricValue:MetricValue = metric.value;
+
+ assertEquals((2400000+3500000) / (4020+4040)*8.0/1000, metricValue.value);
+ assertTrue(metricValue.valid);
+ }
+
+ [Test]
+ public function testGetValueForIndexNotFound():void
+ {
+ metric = new ActualBitrateMetric(qosInfoHistory, 5);
+ assertEquals(MetricType.ACTUAL_BITRATE, metric.type);
+
+ addQoSInfo(generateQoSInfo(1111, 0, new FragmentDetails(1400000, 4010, 2001, 0)));
+ addQoSInfo(generateQoSInfo(2222, 0, new FragmentDetails(2400000, 4020, 4001, 1)));
+ addQoSInfo(generateQoSInfo(3333, 1, new FragmentDetails(3500000, 4040, 6001, 1)));
+ addQoSInfo(generateQoSInfo(4444, 1, new FragmentDetails(4600000, 4030, 8001, 0)));
+ addQoSInfo(generateQoSInfo(5555, 0, new FragmentDetails(5400000, 4050, 3001, 1)));
+ addQoSInfo(generateQoSInfo(6666, 4, new FragmentDetails(3200000, 4070, 5001, 2)));
+
+
+ var metricValue:MetricValue = metric.value;
+
+ assertEquals(undefined, metricValue.value);
+ assertFalse(metricValue.valid);
+ }
+
+
+ //helper different from qosinfo tests functions
+
+ private function generateQoSInfo(timestamp:Number, currentIndex:Number, fragmentDetails:FragmentDetails):QoSInfo
+ {
+ var v:Vector. = new Vector.();
+ for(var i:uint=0; i< 3; i++)
+ {
+ v[i] = new QualityLevel( i, 150+ 100*i, "test" + (150+ 100*i) );
+ }
+ return (new QoSInfo(timestamp, 5678+timestamp, v, currentIndex, currentIndex, fragmentDetails));
+ }
+
+ //helper identical to qosinfo tests functions
+ private function addQoSInfo(qos:QoSInfo):void
+ {
+ netStream.dispatchEvent(new QoSInfoEvent(QoSInfoEvent.QOS_UPDATE, false, false, qos));
+ }
+
+ private var metric:ActualBitrateMetric;
+ private var qosInfoHistory:QoSInfoHistory;
+ private var netStream:NetStream;
+
+
+
+ }
+}
\ No newline at end of file
diff --git a/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/TestAvailableQualityLevelsMetric.as b/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/TestAvailableQualityLevelsMetric.as
new file mode 100644
index 0000000..41e8dfe
--- /dev/null
+++ b/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/TestAvailableQualityLevelsMetric.as
@@ -0,0 +1,155 @@
+/*****************************************************
+ *
+ * Copyright 2011 Adobe Systems Incorporated. All Rights Reserved.
+ *
+ *****************************************************
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ *
+ * The Initial Developer of the Original Code is Adobe Systems Incorporated.
+ * Portions created by Adobe Systems Incorporated are Copyright (C) 2011 Adobe Systems
+ * Incorporated. All Rights Reserved.
+ *
+ *****************************************************/
+package org.osmf.net.metrics
+{
+ import flash.net.NetConnection;
+ import flash.net.NetStream;
+
+ import flashx.textLayout.debug.assert;
+
+ import org.flexunit.asserts.assertEquals;
+ import org.flexunit.asserts.assertFalse;
+ import org.flexunit.asserts.assertTrue;
+ import org.osmf.events.QoSInfoEvent;
+ import org.osmf.net.qos.FragmentDetails;
+ import org.osmf.net.qos.QoSInfo;
+ import org.osmf.net.qos.QoSInfoHistory;
+ import org.osmf.net.qos.QualityLevel;
+
+ public class TestAvailableQualityLevelsMetric
+ {
+ [Before]
+ public function setUp():void
+ {
+ var conn:NetConnection = new NetConnection();
+ conn.connect(null);
+ netStream = new NetStream(conn);
+ qosInfoHistory = new QoSInfoHistory(netStream);
+ }
+
+ [After]
+ public function tearDown():void
+ {
+ }
+
+ [BeforeClass]
+ public static function setUpBeforeClass():void
+ {
+ }
+
+ [AfterClass]
+ public static function tearDownAfterClass():void
+ {
+ }
+
+ [Test]
+ public function testValueWhenQoSInfoHistoryIsEmpty():void
+ {
+ metric=new AvailableQualityLevelsMetric(qosInfoHistory);
+ assertEquals(MetricType.AVAILABLE_QUALITY_LEVELS, metric.type);
+
+ //check initial value
+ var metricValue:MetricValue;
+ metricValue = metric.value;
+ assertEquals(undefined, metricValue.value);
+ assertFalse(metricValue.valid);
+
+ }
+
+ [Test]
+ public function testValueWhenQoSInfoHistoryIsPopulated():void
+ {
+ metric=new AvailableQualityLevelsMetric(qosInfoHistory);
+ assertEquals(MetricType.AVAILABLE_QUALITY_LEVELS, metric.type);
+
+ var metricValue:MetricValue;
+ metricValue = metric.value;
+
+ //check initial value
+ assertEquals(undefined, metricValue.value);
+ assertFalse(metricValue.valid);
+
+ addQoSInfo(generateQoSInfo(1111, 150, 250, 350));
+
+ metricValue = metric.value;
+ assertTrue(metricValue.valid);
+
+ var v:Vector. = metricValue.value as Vector.;
+ assertEquals(3, v.length);
+
+ assertEquals(150, v[0].bitrate);
+ assertEquals(250, v[1].bitrate);
+ assertEquals(350, v[2].bitrate);
+
+ assertEquals("test150", v[0].streamName);
+ assertEquals("test250", v[1].streamName);
+ assertEquals("test350", v[2].streamName);
+
+ assertEquals(0, v[0].index);
+ assertEquals(1, v[1].index);
+ assertEquals(2, v[2].index);
+
+ //check the latest value
+ addQoSInfo(generateQoSInfo(2222, 151, 251, 351));
+
+ metricValue = metric.value;
+
+ v = metricValue.value as Vector.;
+ assertEquals(3, v.length);
+
+ assertEquals(151, v[0].bitrate);
+ assertEquals(251, v[1].bitrate);
+ assertEquals(351, v[2].bitrate);
+
+ assertEquals("test151", v[0].streamName);
+ assertEquals("test251", v[1].streamName);
+ assertEquals("test351", v[2].streamName);
+
+ assertEquals(0, v[0].index);
+ assertEquals(1, v[1].index);
+ assertEquals(2, v[2].index);
+ }
+
+
+ //helper different from qosinfo tests functions
+
+ private function generateQoSInfo(timestamp:Number, ... qualityLevels):QoSInfo
+ {
+ var v:Vector. = new Vector.();
+ for(var i:uint=0; i< qualityLevels.length; i++)
+ {
+ v[i] = new QualityLevel( i, qualityLevels[i], "test" + qualityLevels[i] );
+ }
+ return (new QoSInfo(timestamp, 5678, v, 0, 0, new FragmentDetails(14000, 4000, 568, 2)));
+ }
+
+ //helper identical to qosinfo tests functions
+ private function addQoSInfo(qos:QoSInfo):void
+ {
+ netStream.dispatchEvent(new QoSInfoEvent(QoSInfoEvent.QOS_UPDATE, false, false, qos));
+ }
+
+ private var metric:AvailableQualityLevelsMetric;
+ private var qosInfoHistory:QoSInfoHistory;
+ private var netStream:NetStream;
+ }
+}
\ No newline at end of file
diff --git a/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/TestBandwidthMetric.as b/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/TestBandwidthMetric.as
new file mode 100644
index 0000000..cc655d1
--- /dev/null
+++ b/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/TestBandwidthMetric.as
@@ -0,0 +1,212 @@
+/*****************************************************
+ *
+ * Copyright 2011 Adobe Systems Incorporated. All Rights Reserved.
+ *
+ *****************************************************
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ *
+ * The Initial Developer of the Original Code is Adobe Systems Incorporated.
+ * Portions created by Adobe Systems Incorporated are Copyright (C) 2011 Adobe Systems
+ * Incorporated. All Rights Reserved.
+ *
+ *****************************************************/
+package org.osmf.net.metrics
+{
+ import flash.net.NetConnection;
+ import flash.net.NetStream;
+
+ import flashx.textLayout.debug.assert;
+
+ import flexunit.framework.Assert;
+
+ import org.flexunit.asserts.assertEquals;
+ import org.flexunit.asserts.assertFalse;
+ import org.flexunit.asserts.assertNotNull;
+ import org.flexunit.asserts.assertTrue;
+ import org.osmf.events.QoSInfoEvent;
+ import org.osmf.net.qos.FragmentDetails;
+ import org.osmf.net.qos.QoSInfo;
+ import org.osmf.net.qos.QoSInfoHistory;
+ import org.osmf.net.qos.QualityLevel;
+
+ public class TestBandwidthMetric
+ {
+ [Before]
+ public function setUp():void
+ {
+ var conn:NetConnection = new NetConnection();
+ conn.connect(null);
+ netStream = new NetStream(conn);
+ qosInfoHistory = new QoSInfoHistory(netStream, 4);
+ }
+
+ [After]
+ public function tearDown():void
+ {
+ }
+
+ [BeforeClass]
+ public static function setUpBeforeClass():void
+ {
+ }
+
+ [AfterClass]
+ public static function tearDownAfterClass():void
+ {
+ }
+
+ [Test]
+ public function testBandwidthMetricWhenQoSInfoHistoryIsEmpty():void
+ {
+ metric=new BandwidthMetric(qosInfoHistory, generateWeights(0.5, 0.5) );
+ assertEquals(MetricType.BANDWIDTH, metric.type);
+
+ //check initial value
+ var metricValue:MetricValue;
+ metricValue = metric.value;
+ assertEquals(undefined, metricValue.value);
+ assertFalse(metricValue.valid);
+ }
+
+ [Test(expects="ArgumentError")]
+ public function testBandwidthMetricWhenQoSInfoHistoryIsNull():void
+ {
+ metric=new BandwidthMetric(null, generateWeights(0.5, 0.5) );
+ }
+
+ [Test]
+ public function testBandwidthMetricWhenQoSInfoHistoryIsFilledWithMoreValues():void
+ {
+ metric=new BandwidthMetric(qosInfoHistory, generateWeights(0.6, 0.4) );
+ assertEquals(MetricType.BANDWIDTH, metric.type);
+
+ addQoSInfo(generateQoSInfo(1111, 0, new FragmentDetails(1400000, 4010, 2001, 0)));
+ addQoSInfo(generateQoSInfo(2222, 0, new FragmentDetails(2400000, 4020, 4001, 0)));
+ addQoSInfo(generateQoSInfo(3333, 1, new FragmentDetails(3500000, 4040, 6001, 1)));
+
+
+ //check initial value
+ var metricValue:MetricValue;
+ metricValue = metric.value;
+ assertEquals((3500000 / 6001.0 * 0.6 + 2400000 / 4001.0 * 0.4 ) / (0.6 + 0.4), metricValue.value);
+ assertTrue(metricValue.valid);
+ }
+
+ [Test]
+ public function testBandwidthMetricWhenQoSInfoHistoryIsFilledWithLessValues():void
+ {
+ metric=new BandwidthMetric(qosInfoHistory, generateWeights(0.6, 0.4, 0.3) );
+ assertEquals(MetricType.BANDWIDTH, metric.type);
+
+ addQoSInfo(generateQoSInfo(1111, 0, new FragmentDetails(1400000, 4010, 2001, 0)));
+ addQoSInfo(generateQoSInfo(2222, 0, new FragmentDetails(2400000, 4020, 4001, 0)));
+
+
+ //check initial value
+ var metricValue:MetricValue;
+ metricValue = metric.value;
+ assertEquals( (2400000 / 4001.0 * 0.6 + 1400000 / 2001.0 * 0.4) / (0.6 + 0.4), metricValue.value);
+ assertTrue(metricValue.valid);
+ }
+
+ [Test]
+ public function testBandwidthMetricWithZeroWeight():void
+ {
+ metric=new BandwidthMetric(qosInfoHistory, generateWeights(0.0, 0.4) );
+ assertEquals(MetricType.BANDWIDTH, metric.type);
+
+ addQoSInfo(generateQoSInfo(1111, 0, new FragmentDetails(1400000, 4010, 2001, 0)));
+ addQoSInfo(generateQoSInfo(2222, 0, new FragmentDetails(2400000, 4020, 4001, 0)));
+ addQoSInfo(generateQoSInfo(3333, 1, new FragmentDetails(3500000, 4040, 6001, 1)));
+
+
+ //check initial value
+ var metricValue:MetricValue;
+ metricValue = metric.value;
+ assertEquals((3500000 / 6001.0 * 0.0 + 2400000 / 4001.0 * 0.4 ) / (0.0 + 0.4), metricValue.value);
+ assertTrue(metricValue.valid);
+ }
+
+
+ [Test(expects="ArgumentError")]
+ public function testBandwidthMetricWithAllZeroWeight():void
+ {
+ metric=new BandwidthMetric(qosInfoHistory, generateWeights(0.0, 0.0) );
+
+ }
+
+ [Test(expects="ArgumentError")]
+ public function testBandwidthMetricWithNegativeWeight():void
+ {
+ metric=new BandwidthMetric(qosInfoHistory, generateWeights(-1.0, 0.4) );
+ }
+
+ [Test(expects="ArgumentError")]
+ public function testBandwidthMetricWithNullWeight():void
+ {
+ metric=new BandwidthMetric(qosInfoHistory, null );
+ }
+
+ [Test]
+ public function testGet_weights():void
+ {
+ metric=new BandwidthMetric(qosInfoHistory, generateWeights(0.01, 0.4, 0.3) );
+ var v:Vector. = metric.weights;
+ assertNotNull(v);
+ assertEquals(3, v.length);
+ assertEquals(0.01, v[0]);
+ assertEquals(0.4, v[1]);
+ assertEquals(0.3, v[2]);
+ }
+
+ [Test]
+ public function testMetricGetType():void
+ {
+ metric=new BandwidthMetric(qosInfoHistory, generateWeights(1) );
+ assertEquals(MetricType.BANDWIDTH, metric.type);
+ }
+
+ //helper different from qosinfo tests functions
+
+ private function generateQoSInfo(timestamp:Number, currentBitrate:Number, fragmentDetails:FragmentDetails):QoSInfo
+ {
+ var v:Vector. = new Vector.();
+ for(var i:uint=0; i< 3; i++)
+ {
+ v[i] = new QualityLevel( i, 150+ 100*i, "test" + (150+ 100*i) );
+ }
+ return (new QoSInfo(timestamp, 5678, v, currentBitrate, currentBitrate, fragmentDetails ));
+ }
+
+ //helper identical to qosinfo tests functions
+ private function addQoSInfo(qos:QoSInfo):void
+ {
+ netStream.dispatchEvent(new QoSInfoEvent(QoSInfoEvent.QOS_UPDATE, false, false, qos));
+ }
+
+
+ private function generateWeights(... weights):Vector.
+ {
+ var v:Vector. = new Vector.();
+ for(var i:uint=0; i< weights.length; i++)
+ {
+ v[i] = weights[i] ;
+ }
+ return (v);
+ }
+
+ private var metric:BandwidthMetric;
+ private var qosInfoHistory:QoSInfoHistory;
+ private var netStream:NetStream;
+
+ }
+}
\ No newline at end of file
diff --git a/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/TestBufferFragmentsMetric.as b/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/TestBufferFragmentsMetric.as
new file mode 100644
index 0000000..ec375ad
--- /dev/null
+++ b/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/TestBufferFragmentsMetric.as
@@ -0,0 +1,225 @@
+/*****************************************************
+ *
+ * Copyright 2011 Adobe Systems Incorporated. All Rights Reserved.
+ *
+ *****************************************************
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ *
+ * The Initial Developer of the Original Code is Adobe Systems Incorporated.
+ * Portions created by Adobe Systems Incorporated are Copyright (C) 2011 Adobe Systems
+ * Incorporated. All Rights Reserved.
+ *
+ *****************************************************/
+
+package org.osmf.net.metrics
+{
+ import flash.net.NetConnection;
+ import flash.net.NetStream;
+
+ import flashx.textLayout.debug.assert;
+
+ import flexunit.framework.Assert;
+
+ import org.flexunit.asserts.assertEquals;
+ import org.flexunit.asserts.assertFalse;
+ import org.flexunit.asserts.assertTrue;
+ import org.osmf.events.QoSInfoEvent;
+ import org.osmf.net.qos.FragmentDetails;
+ import org.osmf.net.qos.QoSInfo;
+ import org.osmf.net.qos.QoSInfoHistory;
+ import org.osmf.net.qos.QualityLevel;
+
+ public class TestBufferFragmentsMetric
+ {
+ [Before]
+ public function setUp():void
+ {
+ var conn:NetConnection = new NetConnection();
+ conn.connect(null);
+ netStream = new NetStream(conn);
+ qosInfoHistory = new QoSInfoHistory(netStream);
+ }
+
+ [After]
+ public function tearDown():void
+ {
+ }
+
+ [BeforeClass]
+ public static function setUpBeforeClass():void
+ {
+ }
+
+ [AfterClass]
+ public static function tearDownAfterClass():void
+ {
+ }
+
+ [Test]
+ public function testBufferFragmentsMetricInit():void
+ {
+ metric = new BufferFragmentsMetric(qosInfoHistory);
+
+ assertEquals(MetricType.BUFFER_FRAGMENTS, metric.type);
+ var metricValue:MetricValue = metric.value;
+
+ assertEquals(undefined, metricValue.value);
+ assertFalse(metricValue.valid);
+ }
+
+ [Test]
+ public function testBufferFragmentsMetricGetValueBufferLessThanFragmentSum():void
+ {
+ metric = new BufferFragmentsMetric(qosInfoHistory);
+ assertEquals(MetricType.BUFFER_FRAGMENTS, metric.type);
+
+ var metricValue:MetricValue;
+
+ addQoSInfo(generateQoSInfo(1111, 8, 4, new FragmentDetails(300000, 4.1 , 2, 0, "streamname")));
+ addQoSInfo(generateQoSInfo(2222, 9, 4, new FragmentDetails(300000, 3.9 , 2, 1, "streamname")));
+ addQoSInfo(generateQoSInfo(3333, 9, 4, new FragmentDetails(300000, 4.2 , 2, 1, "streamname")));
+
+ metricValue = metric.value;
+ assertEquals(2, metricValue.value);
+ assertTrue(metricValue.valid);
+
+ }
+
+ [Test]
+ public function testBufferFragmentsMetricGetValueBufferLengthNegative():void
+ {
+ metric = new BufferFragmentsMetric(qosInfoHistory);
+ assertEquals(MetricType.BUFFER_FRAGMENTS, metric.type);
+
+ var metricValue:MetricValue;
+
+ addQoSInfo(generateQoSInfo(1111, 8, 4, new FragmentDetails(300000, 4.1 , 2, 0, "streamname")));
+ addQoSInfo(generateQoSInfo(2222, 9, 4, new FragmentDetails(300000, 3.9 , 2, 1, "streamname")));
+ addQoSInfo(generateQoSInfo(3333, -1, 4, new FragmentDetails(300000, 4.2 , 2, 1, "streamname")));
+
+ metricValue = metric.value;
+ assertEquals(undefined, metricValue.value);
+ assertFalse(metricValue.valid);
+
+ }
+
+ [Test]
+ public function testBufferFragmentsMetricGetValueBufferLengthNaN():void
+ {
+ metric = new BufferFragmentsMetric(qosInfoHistory);
+ assertEquals(MetricType.BUFFER_FRAGMENTS, metric.type);
+
+ var metricValue:MetricValue;
+
+ addQoSInfo(generateQoSInfo(1111, 8, 4, new FragmentDetails(300000, 4.1 , 2, 0, "streamname")));
+ addQoSInfo(generateQoSInfo(2222, 9, 4, new FragmentDetails(300000, 3.9 , 2, 1, "streamname")));
+ addQoSInfo(generateQoSInfo(3333, NaN, 4, new FragmentDetails(300000, 4.2 , 2, 1, "streamname")));
+
+ metricValue = metric.value;
+ assertEquals(undefined, metricValue.value);
+ assertFalse(metricValue.valid);
+ }
+
+
+ [Test]
+ public function testBufferFragmentsMetricGetValueBufferLengthZero():void
+ {
+ metric = new BufferFragmentsMetric(qosInfoHistory);
+ assertEquals(MetricType.BUFFER_FRAGMENTS, metric.type);
+
+ var metricValue:MetricValue;
+
+ addQoSInfo(generateQoSInfo(1111, 8, 4, new FragmentDetails(300000, 4.1 , 2, 0, "streamname")));
+ addQoSInfo(generateQoSInfo(2222, 9, 4, new FragmentDetails(300000, 3.9 , 2, 1, "streamname")));
+ addQoSInfo(generateQoSInfo(3333, 0, 4, new FragmentDetails(300000, 4.2 , 2, 1, "streamname")));
+
+ metricValue = metric.value;
+ assertEquals(0, metricValue.value);
+ assertTrue(metricValue.valid);
+ }
+
+ [Test]
+ public function testBufferFragmentsMetricGetValueBufferLessThanLastFragment():void
+ {
+ metric = new BufferFragmentsMetric(qosInfoHistory);
+ assertEquals(MetricType.BUFFER_FRAGMENTS, metric.type);
+
+ var metricValue:MetricValue;
+
+ addQoSInfo(generateQoSInfo(1111, 8, 4, new FragmentDetails(300000, 4.1 , 2, 0, "streamname")));
+ addQoSInfo(generateQoSInfo(2222, 9, 4, new FragmentDetails(300000, 3.9 , 2, 1, "streamname")));
+ addQoSInfo(generateQoSInfo(3333, 3, 4, new FragmentDetails(300000, 4.2 , 2, 1, "streamname")));
+
+ metricValue = metric.value;
+ assertEquals(0, metricValue.value);
+ assertTrue(metricValue.valid);
+ }
+
+ [Test]
+ public function testBufferFragmentsMetricGetValueBufferEqualToSumOfFragments():void
+ {
+ metric = new BufferFragmentsMetric(qosInfoHistory);
+ assertEquals(MetricType.BUFFER_FRAGMENTS, metric.type);
+
+ var metricValue:MetricValue;
+
+ addQoSInfo(generateQoSInfo(1111, 8, 4, new FragmentDetails(300000, 4.1 , 2, 0, "streamname")));
+ addQoSInfo(generateQoSInfo(2222, 9, 4, new FragmentDetails(300000, 3.9 , 2, 1, "streamname")));
+ addQoSInfo(generateQoSInfo(3333, 4.2+3.9, 4, new FragmentDetails(300000, 4.2 , 2, 1, "streamname")));
+
+ metricValue = metric.value;
+ assertEquals(2, metricValue.value);
+ assertTrue(metricValue.valid);
+ }
+
+
+ [Test]
+ public function testBufferFragmentsMetricGetValueBufferLongerThanHistory():void
+ {
+ metric = new BufferFragmentsMetric(qosInfoHistory);
+ assertEquals(MetricType.BUFFER_FRAGMENTS, metric.type);
+
+ var metricValue:MetricValue;
+
+ addQoSInfo(generateQoSInfo(1111, 8, 4, new FragmentDetails(300000, 4.1 , 2, 0, "streamname")));
+ addQoSInfo(generateQoSInfo(2222, 9, 4, new FragmentDetails(300000, 3.9 , 2, 1, "streamname")));
+ addQoSInfo(generateQoSInfo(3333, 30, 4, new FragmentDetails(300000, 4.2 , 2, 1, "streamname")));
+
+ metricValue = metric.value;
+ assertEquals(3, metricValue.value);
+ assertTrue(metricValue.valid);
+ }
+
+ //helper different from qosinfo tests functions
+
+ private function generateQoSInfo(timestamp:Number, bufferLength:Number, bufferTime:Number, lastFragmentDetails:FragmentDetails):QoSInfo
+ {
+ var v:Vector. = new Vector.();
+ for(var i:uint=0; i< 5; i++)
+ {
+ v[i] = new QualityLevel( i, 150+ 100*i, "test" + (150+ 100*i) );
+ }
+ return (new QoSInfo(timestamp, 5678+timestamp, v, 2, 2, lastFragmentDetails, 25, null, null, bufferLength, bufferTime));
+ }
+
+ //helper identical to qosinfo tests functions
+ private function addQoSInfo(qos:QoSInfo):void
+ {
+ netStream.dispatchEvent(new QoSInfoEvent(QoSInfoEvent.QOS_UPDATE, false, false, qos));
+ }
+
+ private var metric:BufferFragmentsMetric;
+ private var qosInfoHistory:QoSInfoHistory;
+ private var netStream:NetStream;
+
+ }
+}
\ No newline at end of file
diff --git a/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/TestBufferLengthMetric.as b/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/TestBufferLengthMetric.as
new file mode 100644
index 0000000..381bb26
--- /dev/null
+++ b/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/TestBufferLengthMetric.as
@@ -0,0 +1,132 @@
+/*****************************************************
+ *
+ * Copyright 2011 Adobe Systems Incorporated. All Rights Reserved.
+ *
+ *****************************************************
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ *
+ * The Initial Developer of the Original Code is Adobe Systems Incorporated.
+ * Portions created by Adobe Systems Incorporated are Copyright (C) 2011 Adobe Systems
+ * Incorporated. All Rights Reserved.
+ *
+ *****************************************************/
+
+package org.osmf.net.metrics
+{
+ import flash.net.NetConnection;
+ import flash.net.NetStream;
+
+ import flashx.textLayout.debug.assert;
+
+ import flexunit.framework.Assert;
+
+ import org.flexunit.asserts.assertEquals;
+ import org.flexunit.asserts.assertFalse;
+ import org.flexunit.asserts.assertTrue;
+ import org.osmf.events.QoSInfoEvent;
+ import org.osmf.net.qos.FragmentDetails;
+ import org.osmf.net.qos.QoSInfo;
+ import org.osmf.net.qos.QoSInfoHistory;
+ import org.osmf.net.qos.QualityLevel;
+
+ public class TestBufferLengthMetric
+ {
+ [Before]
+ public function setUp():void
+ {
+ var conn:NetConnection = new NetConnection();
+ conn.connect(null);
+ netStream = new NetStream(conn);
+ qosInfoHistory = new QoSInfoHistory(netStream);
+ }
+
+ [After]
+ public function tearDown():void
+ {
+ }
+
+ [BeforeClass]
+ public static function setUpBeforeClass():void
+ {
+ }
+
+ [AfterClass]
+ public static function tearDownAfterClass():void
+ {
+ }
+
+ [Test]
+ public function testBufferLengthMetricInit():void
+ {
+ metric = new BufferLengthMetric(qosInfoHistory);
+
+ assertEquals(MetricType.BUFFER_LENGTH, metric.type);
+ var metricValue:MetricValue = metric.value;
+
+ assertEquals(undefined, metricValue.value);
+ assertFalse(metricValue.valid);
+ }
+
+ [Test]
+ public function testBufferLengthMetricGetValue():void
+ {
+ metric = new BufferLengthMetric(qosInfoHistory);
+ assertEquals(MetricType.BUFFER_LENGTH, metric.type);
+
+ var metricValue:MetricValue;
+
+ addQoSInfo(generateQoSInfo(1111, 3, 4));
+ metricValue = metric.value;
+ assertEquals(3, metricValue.value);
+ assertTrue(metricValue.valid);
+
+ addQoSInfo(generateQoSInfo(2222, -1, 4));
+ metricValue = metric.value;
+ assertEquals(undefined, metricValue.value);
+ assertFalse(metricValue.valid);
+
+ addQoSInfo(generateQoSInfo(3333, NaN, 4));
+ metricValue = metric.value;
+ assertEquals(undefined, metricValue.value);
+ assertFalse(metricValue.valid);
+
+ addQoSInfo(generateQoSInfo(4444, 0, 4));
+ metricValue = metric.value;
+ assertEquals(0, metricValue.value);
+ assertTrue(metricValue.valid);
+
+ }
+
+ //helper different from qosinfo tests functions
+
+ private function generateQoSInfo(timestamp:Number, bufferLength:Number, bufferTime:Number):QoSInfo
+ {
+ var v:Vector. = new Vector.();
+ for(var i:uint=0; i< 5; i++)
+ {
+ v[i] = new QualityLevel( i, 150+ 100*i, "test" + (150+ 100*i) );
+ }
+ return (new QoSInfo(timestamp, 5678+timestamp, v, 2, 2, null, 25, null, null, bufferLength, bufferTime));
+ }
+
+ //helper identical to qosinfo tests functions
+ private function addQoSInfo(qos:QoSInfo):void
+ {
+ netStream.dispatchEvent(new QoSInfoEvent(QoSInfoEvent.QOS_UPDATE, false, false, qos));
+ }
+
+ private var metric:BufferLengthMetric;
+ private var qosInfoHistory:QoSInfoHistory;
+ private var netStream:NetStream;
+
+ }
+}
\ No newline at end of file
diff --git a/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/TestBufferOccupationRatioMetric.as b/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/TestBufferOccupationRatioMetric.as
new file mode 100644
index 0000000..1c05865
--- /dev/null
+++ b/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/TestBufferOccupationRatioMetric.as
@@ -0,0 +1,147 @@
+/*****************************************************
+ *
+ * Copyright 2011 Adobe Systems Incorporated. All Rights Reserved.
+ *
+ *****************************************************
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ *
+ * The Initial Developer of the Original Code is Adobe Systems Incorporated.
+ * Portions created by Adobe Systems Incorporated are Copyright (C) 2011 Adobe Systems
+ * Incorporated. All Rights Reserved.
+ *
+ *****************************************************/
+
+package org.osmf.net.metrics
+{
+ import flash.net.NetConnection;
+ import flash.net.NetStream;
+
+ import flashx.textLayout.debug.assert;
+
+ import flexunit.framework.Assert;
+
+ import org.flexunit.asserts.assertEquals;
+ import org.flexunit.asserts.assertFalse;
+ import org.flexunit.asserts.assertTrue;
+ import org.osmf.events.QoSInfoEvent;
+ import org.osmf.net.qos.FragmentDetails;
+ import org.osmf.net.qos.QoSInfo;
+ import org.osmf.net.qos.QoSInfoHistory;
+ import org.osmf.net.qos.QualityLevel;
+
+ public class TestBufferOccupationRatioMetric
+ {
+ [Before]
+ public function setUp():void
+ {
+ var conn:NetConnection = new NetConnection();
+ conn.connect(null);
+ netStream = new NetStream(conn);
+ qosInfoHistory = new QoSInfoHistory(netStream);
+ }
+
+ [After]
+ public function tearDown():void
+ {
+ }
+
+ [BeforeClass]
+ public static function setUpBeforeClass():void
+ {
+ }
+
+ [AfterClass]
+ public static function tearDownAfterClass():void
+ {
+ }
+
+ [Test]
+ public function testBufferOccupationRatioMetricInit():void
+ {
+ metric = new BufferOccupationRatioMetric(qosInfoHistory);
+
+ assertEquals(MetricType.BUFFER_OCCUPATION_RATIO, metric.type);
+ var metricValue:MetricValue = metric.value;
+
+ assertEquals(undefined, metricValue.value);
+ assertFalse(metricValue.valid);
+ }
+
+ [Test]
+ public function testBufferOccupationRatioMetricGetValue():void
+ {
+ metric = new BufferOccupationRatioMetric(qosInfoHistory);
+ assertEquals(MetricType.BUFFER_OCCUPATION_RATIO, metric.type);
+
+ var metricValue:MetricValue;
+
+ addQoSInfo(generateQoSInfo(1111, 3, 4));
+ metricValue = metric.value;
+ assertEquals(3/4, metricValue.value);
+ assertTrue(metricValue.valid);
+
+ addQoSInfo(generateQoSInfo(2222, -1, 4));
+ metricValue = metric.value;
+ assertEquals(undefined, metricValue.value);
+ assertFalse(metricValue.valid);
+
+ addQoSInfo(generateQoSInfo(3333, NaN, 4));
+ metricValue = metric.value;
+ assertEquals(undefined, metricValue.value);
+ assertFalse(metricValue.valid);
+
+ addQoSInfo(generateQoSInfo(4444, 0, 4));
+ metricValue = metric.value;
+ assertEquals(0, metricValue.value);
+ assertTrue(metricValue.valid);
+
+ addQoSInfo(generateQoSInfo(5555, 3, -1));
+ metricValue = metric.value;
+ assertEquals(undefined, metricValue.value);
+ assertFalse(metricValue.valid);
+
+ addQoSInfo(generateQoSInfo(6666, 3, NaN));
+ metricValue = metric.value;
+ assertEquals(undefined, metricValue.value);
+ assertFalse(metricValue.valid);
+
+ addQoSInfo(generateQoSInfo(7777, 3, 0));
+ metricValue = metric.value;
+ assertEquals(undefined, metricValue.value);
+ assertFalse(metricValue.valid);
+
+ }
+
+ //helper different from qosinfo tests functions
+
+ private function generateQoSInfo(timestamp:Number, bufferLength:Number, bufferTime:Number):QoSInfo
+ {
+ var v:Vector. = new Vector.();
+ for(var i:uint=0; i< 5; i++)
+ {
+ v[i] = new QualityLevel( i, 150+ 100*i, "test" + (150+ 100*i) );
+ }
+ return (new QoSInfo(timestamp, 5678+timestamp, v, 2, 2, null, 25, null, null, bufferLength, bufferTime));
+ }
+
+ //helper identical to qosinfo tests functions
+ private function addQoSInfo(qos:QoSInfo):void
+ {
+ netStream.dispatchEvent(new QoSInfoEvent(QoSInfoEvent.QOS_UPDATE, false, false, qos));
+ }
+
+ private var metric:BufferOccupationRatioMetric;
+ private var qosInfoHistory:QoSInfoHistory;
+ private var netStream:NetStream;
+
+ }
+}
\ No newline at end of file
diff --git a/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/TestCurrentStatusMetric.as b/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/TestCurrentStatusMetric.as
new file mode 100644
index 0000000..c60a0e9
--- /dev/null
+++ b/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/TestCurrentStatusMetric.as
@@ -0,0 +1,134 @@
+/*****************************************************
+ *
+ * Copyright 2011 Adobe Systems Incorporated. All Rights Reserved.
+ *
+ *****************************************************
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ *
+ * The Initial Developer of the Original Code is Adobe Systems Incorporated.
+ * Portions created by Adobe Systems Incorporated are Copyright (C) 2011 Adobe Systems
+ * Incorporated. All Rights Reserved.
+ *
+ *****************************************************/
+package org.osmf.net.metrics
+{
+ import flash.net.NetConnection;
+ import flash.net.NetStream;
+
+ import flashx.textLayout.debug.assert;
+
+ import flexunit.framework.Assert;
+
+ import org.flexunit.asserts.assertEquals;
+ import org.flexunit.asserts.assertFalse;
+ import org.flexunit.asserts.assertTrue;
+ import org.osmf.events.QoSInfoEvent;
+ import org.osmf.net.qos.FragmentDetails;
+ import org.osmf.net.qos.QoSInfo;
+ import org.osmf.net.qos.QoSInfoHistory;
+ import org.osmf.net.qos.QualityLevel;
+
+ public class TestCurrentStatusMetric
+ {
+ [Before]
+ public function setUp():void
+ {
+ var conn:NetConnection = new NetConnection();
+ conn.connect(null);
+ netStream = new NetStream(conn);
+ qosInfoHistory = new QoSInfoHistory(netStream);
+ }
+
+ [After]
+ public function tearDown():void
+ {
+ }
+
+ [BeforeClass]
+ public static function setUpBeforeClass():void
+ {
+ }
+
+ [AfterClass]
+ public static function tearDownAfterClass():void
+ {
+ }
+
+
+ [Test]
+ public function testCurrentStatusMetric():void
+ {
+ metric = new CurrentStatusMetric(qosInfoHistory);
+
+ assertEquals(MetricType.CURRENT_STATUS, metric.type);
+
+ var metricValue:MetricValue = metric.value;
+
+ assertEquals(undefined, metricValue.value);
+ assertFalse(metricValue.valid);
+ }
+
+
+ [Test]
+ public function testCurrentStatusMetricQoSPopulated():void
+ {
+ metric = new CurrentStatusMetric(qosInfoHistory);
+
+ var metricValue:MetricValue = metric.value;
+
+ assertEquals(undefined, metricValue.value);
+ assertFalse(metricValue.valid);
+
+ addQoSInfo(generateQoSInfo(1111, 4, 9));
+
+ metricValue = metric.value;
+ assertTrue(metricValue.valid);
+ assertTrue(metricValue.value is Vector.);
+ assertEquals(4, metricValue.value[0]);
+ assertEquals(9, metricValue.value[1]);
+
+
+ //test for more than one value in qosinfohistory
+ addQoSInfo(generateQoSInfo(2222, 5, 10));
+
+ metricValue = metric.value;
+
+ assertTrue(metricValue.valid);
+ assertTrue(metricValue.value is Vector.);
+ assertEquals(5, metricValue.value[0]);
+ assertEquals(10, metricValue.value[1]);
+ }
+
+ //helper different from qosinfo tests functions
+
+ private function generateQoSInfo(timestamp:Number, currentIndex:Number, actualIndex:Number):QoSInfo
+ {
+ var v:Vector. = new Vector.();
+ for(var i:uint = 0; i< 3; i++)
+ {
+ v[i] = new QualityLevel( i, 150+ 100*i, "test" + (150+ 100*i) );
+ }
+ return (new QoSInfo(timestamp, 5678+timestamp, v, currentIndex, actualIndex, null));
+ }
+
+ //helper identical to qosinfo tests functions
+ private function addQoSInfo(qos:QoSInfo):void
+ {
+ netStream.dispatchEvent(new QoSInfoEvent(QoSInfoEvent.QOS_UPDATE, false, false, qos));
+ }
+
+ private var metric:CurrentStatusMetric;
+ private var qosInfoHistory:QoSInfoHistory;
+ private var netStream:NetStream;
+
+ }
+}
\ No newline at end of file
diff --git a/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/TestDefaultMetricFactory.as b/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/TestDefaultMetricFactory.as
new file mode 100644
index 0000000..087f2f0
--- /dev/null
+++ b/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/TestDefaultMetricFactory.as
@@ -0,0 +1,114 @@
+/*****************************************************
+ *
+ * Copyright 2011 Adobe Systems Incorporated. All Rights Reserved.
+ *
+ *****************************************************
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ *
+ * The Initial Developer of the Original Code is Adobe Systems Incorporated.
+ * Portions created by Adobe Systems Incorporated are Copyright (C) 2011 Adobe Systems
+ * Incorporated. All Rights Reserved.
+ *
+ *****************************************************/
+package org.osmf.net.metrics
+{
+ import flash.net.NetConnection;
+ import flash.net.NetStream;
+
+ import org.flexunit.assertThat;
+ import org.flexunit.asserts.assertEquals;
+ import org.flexunit.asserts.assertNotNull;
+ import org.flexunit.asserts.assertStrictlyEquals;
+ import org.flexunit.asserts.assertTrue;
+ import org.osmf.net.ABRTestUtils;
+ import org.osmf.net.qos.QoSInfoHistory;
+
+ public class TestDefaultMetricFactory
+ {
+ [Before]
+ public function setUp():void
+ {
+ var conn:NetConnection = new NetConnection();
+ conn.connect(null);
+ var ns:NetStream = new NetStream(conn);
+ var qosInfoHistory:QoSInfoHistory = new QoSInfoHistory(ns);
+ factory = new DefaultMetricFactory(qosInfoHistory);
+ }
+
+ [After]
+ public function tearDown():void
+ {
+ factory = null;
+ }
+
+ [Test]
+ public function testBuildMetricsInit():void
+ {
+ assertEquals(12, factory.numItems);
+ assertEquals(12, factory.getItems().length);
+
+ assertTrue(factory.buildMetric(MetricType.ACTUAL_BITRATE, 10) is ActualBitrateMetric);
+
+ assertTrue(factory.buildMetric(MetricType.FRAGMENT_COUNT) is FragmentCountMetric);
+
+ assertTrue(factory.buildMetric(MetricType.AVAILABLE_QUALITY_LEVELS) is AvailableQualityLevelsMetric);
+
+ var weights:Vector. = new Vector.();
+ weights.push(0.8);
+ weights.push(0.2);
+ assertTrue(factory.buildMetric(MetricType.BANDWIDTH, weights) is BandwidthMetric);
+
+ assertTrue(factory.buildMetric(MetricType.FPS) is FPSMetric);
+
+ assertTrue(factory.buildMetric(MetricType.DROPPED_FPS) is DroppedFPSMetric);
+
+ assertTrue(factory.buildMetric(MetricType.CURRENT_STATUS) is CurrentStatusMetric);
+
+ assertTrue(factory.buildMetric(MetricType.BUFFER_LENGTH) is BufferLengthMetric);
+
+ assertTrue(factory.buildMetric(MetricType.BUFFER_OCCUPATION_RATIO) is BufferOccupationRatioMetric);
+
+ assertTrue(factory.buildMetric(MetricType.BUFFER_FRAGMENTS) is BufferFragmentsMetric);
+
+ assertTrue(factory.buildMetric(MetricType.EMPTY_BUFFER) is EmptyBufferMetric);
+
+ assertTrue(factory.buildMetric(MetricType.RECENT_SWITCH) is RecentSwitchMetric);
+ }
+
+ [Test]
+ public function testBuildActualBitrateMetric():void
+ {
+ var metric:ActualBitrateMetric = factory.buildMetric(MetricType.ACTUAL_BITRATE, 4) as ActualBitrateMetric;
+
+ assertNotNull(metric);
+ assertEquals(metric.maxFragments, 4);
+ }
+
+ [Test]
+ public function testBuildBandwidthMetric():void
+ {
+ var weights:Vector. = new Vector.();
+ weights.push(4);
+ weights.push(3);
+ weights.push(1);
+
+ var metric:BandwidthMetric = factory.buildMetric(MetricType.BANDWIDTH, weights) as BandwidthMetric;
+
+ assertNotNull(metric);
+ assertTrue(ABRTestUtils.equalNumberVectors(metric.weights, weights));
+ }
+
+ private var factory:MetricFactory;
+
+ private static const MAX_FRAGMENTS:Number = 10;
+ }
+}
diff --git a/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/TestDroppedFPSMetric.as b/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/TestDroppedFPSMetric.as
new file mode 100644
index 0000000..cfb0f26
--- /dev/null
+++ b/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/TestDroppedFPSMetric.as
@@ -0,0 +1,378 @@
+/*****************************************************
+ *
+ * Copyright 2011 Adobe Systems Incorporated. All Rights Reserved.
+ *
+ *****************************************************
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ *
+ * The Initial Developer of the Original Code is Adobe Systems Incorporated.
+ * Portions created by Adobe Systems Incorporated are Copyright (C) 2011 Adobe Systems
+ * Incorporated. All Rights Reserved.
+ *
+ *****************************************************/
+package org.osmf.net.metrics
+{
+ import flash.net.NetConnection;
+ import flash.net.NetStream;
+
+ import flashx.textLayout.debug.assert;
+
+ import org.flexunit.asserts.assertEquals;
+ import org.flexunit.asserts.assertFalse;
+ import org.flexunit.asserts.assertTrue;
+ import org.osmf.events.QoSInfoEvent;
+ import org.osmf.net.qos.FragmentDetails;
+ import org.osmf.net.qos.PlaybackDetails;
+ import org.osmf.net.qos.QoSInfo;
+ import org.osmf.net.qos.QoSInfoHistory;
+ import org.osmf.net.qos.QualityLevel;
+
+ public class TestDroppedFPSMetric
+ {
+ [Before]
+ public function setUp():void
+ {
+ var conn:NetConnection = new NetConnection();
+ conn.connect(null);
+ netStream = new NetStream(conn);
+ qosInfoHistory = new QoSInfoHistory(netStream);
+ }
+
+ [After]
+ public function tearDown():void
+ {
+ }
+
+ [BeforeClass]
+ public static function setUpBeforeClass():void
+ {
+ }
+
+ [AfterClass]
+ public static function tearDownAfterClass():void
+ {
+ }
+
+ [Test]
+ public function testValueWhenQoSInfoHistoryIsEmpty():void
+ {
+ metric=new DroppedFPSMetric(qosInfoHistory);
+ assertEquals(MetricType.DROPPED_FPS, metric.type);
+
+ //check initial value
+ var metricValue:MetricValue;
+ metricValue = metric.value;
+ assertEquals(undefined, metricValue.value);
+ assertFalse(metricValue.valid);
+ assertEquals(10, metric.desiredSampleLength);
+
+ }
+
+
+ [Test(expects="ArgumentError")]
+ public function testDesiredSampleLengthNegativeValue():void
+ {
+ metric=new DroppedFPSMetric(qosInfoHistory, -1);
+ }
+
+ [Test(expects="ArgumentError")]
+ public function testDesiredSampleLengthNaN():void
+ {
+ metric=new DroppedFPSMetric(qosInfoHistory, NaN);
+ }
+
+ [Test]
+ public function testDesiredSampleLengthDifferentValue():void
+ {
+ metric=new DroppedFPSMetric(qosInfoHistory, 6.78);
+ assertEquals(MetricType.DROPPED_FPS, metric.type);
+
+ //check initial value
+ var metricValue:MetricValue;
+ metricValue = metric.value;
+ assertEquals(undefined, metricValue.value);
+ assertFalse(metricValue.valid);
+ assertEquals(6.78, metric.desiredSampleLength);
+
+ }
+
+ [Test]
+ public function testValueWhenQoSInfoHistoryIsPopulated():void
+ {
+ metric=new DroppedFPSMetric(qosInfoHistory, 5);
+ assertEquals(MetricType.DROPPED_FPS, metric.type);
+ var timestamp:Number=1000;
+
+ var metricValue:MetricValue;
+ metricValue = metric.value;
+
+ //check initial value
+ assertEquals(undefined, metricValue.value);
+ assertFalse(metricValue.valid);
+
+ //check one value
+ addQoSInfo(generateQoSInfo(timestamp++, 0,
+ 2, 7,
+ 0, 0,
+ 0, 0,
+ 0, 0,
+ 0, 0));
+
+ metricValue = metric.value;
+ assertTrue(metricValue.valid);
+ assertEquals(7/2, metricValue.value);
+
+ //check bad data
+ addQoSInfo(generateQoSInfo(timestamp++, 4,
+ 2, 7,
+ 0, 0,
+ 0, 0,
+ 0, 0,
+ 0, 0));
+
+ metricValue = metric.value;
+ assertFalse(metricValue.valid);
+ assertEquals(undefined, metricValue.value);
+
+
+ //check value when other streams have been played (0 and 1)
+ addQoSInfo(generateQoSInfo(timestamp++, 1,
+ 2, 7,
+ 3, 4,
+ 5, 40,
+ 7, 45,
+ 9, 50));
+
+ metricValue = metric.value;
+ assertTrue(metricValue.valid);
+ assertEquals(4/3, metricValue.value);
+
+
+ //check that it sums 2 records, under the limit
+ addQoSInfo(generateQoSInfo(timestamp++, 1,
+ 2, 7,
+ 1, 5,
+ 5, 40,
+ 7, 45,
+ 9, 50));
+
+ metricValue = metric.value;
+ assertTrue(metricValue.valid);
+ assertEquals((4+5)/(3+1), metricValue.value);
+
+ //check that the limit stops the propagation
+ addQoSInfo(generateQoSInfo(timestamp++, 1,
+ 1, 7,
+ 2, 23,
+ 5, 40,
+ 7, 45,
+ 9, 50));
+
+ addQoSInfo(generateQoSInfo(timestamp++, 1,
+ 1, 7,
+ 3, 34,
+ 5, 40,
+ 7, 45,
+ 9, 50));
+
+
+ metricValue = metric.value;
+ assertTrue(metricValue.valid);
+ assertEquals((23+34)/(2+3), metricValue.value);
+
+ //check desiredSampleLength limit
+ addQoSInfo(generateQoSInfo(timestamp++, 1,
+ 2, 7,
+ 6, 13,
+ 5, 40,
+ 7, 45,
+ 9, 50));
+
+ metricValue = metric.value;
+ assertTrue(metricValue.valid);
+
+ assertEquals(13/6, metricValue.value);
+
+ //check undefined
+ addQoSInfo(generateQoSInfo(timestamp++, 1,
+ 2, 7,
+ 6, 13,
+ 5, 40,
+ 7, 45,
+ 9, 50));
+
+ metricValue = metric.value;
+ assertTrue(metricValue.valid);
+
+ assertEquals(13/6, metricValue.value);
+
+ }
+
+ [Test]
+ public function testValueForShortIntervals():void
+ {
+ metric=new DroppedFPSMetric(qosInfoHistory, 5);
+ assertEquals(MetricType.DROPPED_FPS, metric.type);
+ var timestamp:Number=2000;
+
+ var metricValue:MetricValue;
+ metricValue = metric.value;
+
+ //check initial value
+ assertEquals(undefined, metricValue.value);
+ assertFalse(metricValue.valid);
+
+ //check minimum MINIMUM_CONTINUOUS_PLAYBACK_DURATION = 1
+
+ addQoSInfo(generateQoSInfo(timestamp++, 0,
+ 0.99, 3,
+ 0, 0,
+ 0, 0,
+ 0, 0,
+ 0, 0));
+
+ metricValue = metric.value;
+ assertFalse(metricValue.valid);
+ assertEquals(undefined, metricValue.value);
+
+ addQoSInfo(generateQoSInfo(timestamp++, 0,
+ 4, 3,
+ 0, 0,
+ 0, 0,
+ 0, 0,
+ 0, 0));
+
+ metricValue = metric.value;
+ assertTrue(metricValue.valid);
+ assertEquals(3 / 4, metricValue.value);
+
+ //check minimum MINIMUM_TOTAL_PLAYBACK_DURATION = 2
+ addQoSInfo(generateQoSInfo(timestamp++, 4,
+ 2, 7,
+ 0, 0,
+ 0, 0,
+ 0, 0,
+ 1, 4));
+
+ metricValue = metric.value;
+ assertFalse(metricValue.valid);
+ assertEquals(undefined, metricValue.value);
+
+ addQoSInfo(generateQoSInfo(timestamp++, 4,
+ 2, 7,
+ 0, 0,
+ 0, 0,
+ 0, 0,
+ 1, 5));
+
+ metricValue = metric.value;
+ assertTrue(metricValue.valid);
+ assertEquals( (4 + 5) / 2, metricValue.value);
+
+ }
+
+ [Test]
+ public function testValueForNegativeDroppedFrameValue():void
+ {
+ metric=new DroppedFPSMetric(qosInfoHistory, 5);
+ assertEquals(MetricType.DROPPED_FPS, metric.type);
+ var timestamp:Number=2000;
+
+ var metricValue:MetricValue;
+ metricValue = metric.value;
+
+ //check initial value
+ assertEquals(undefined, metricValue.value);
+ assertFalse(metricValue.valid);
+
+ //check minimum MINIMUM_CONTINUOUS_PLAYBACK_DURATION = 1
+
+ addQoSInfo(generateQoSInfo(timestamp++, 0,
+ 8, -3,
+ 0, 0,
+ 0, 0,
+ 0, 0,
+ 0, 0));
+
+ metricValue = metric.value;
+ assertFalse(metricValue.valid);
+ assertEquals(undefined, metricValue.value);
+ }
+
+ [Test]
+ public function testValueForNegativeDurationValue():void
+ {
+ metric=new DroppedFPSMetric(qosInfoHistory, 5);
+ assertEquals(MetricType.DROPPED_FPS, metric.type);
+ var timestamp:Number=2000;
+
+ var metricValue:MetricValue;
+ metricValue = metric.value;
+
+ //check initial value
+ assertEquals(undefined, metricValue.value);
+ assertFalse(metricValue.valid);
+
+ //check minimum MINIMUM_CONTINUOUS_PLAYBACK_DURATION = 1
+
+ addQoSInfo(generateQoSInfo(timestamp++, 0,
+ 8, 3,
+ 0, 0,
+ 0, 0,
+ 0, 0,
+ 0, 0));
+
+ metricValue = metric.value;
+ assertTrue(metricValue.valid);
+ assertEquals(3 / 8, metricValue.value);
+
+ addQoSInfo(generateQoSInfo(timestamp++, 0,
+ -1, 4,
+ 0, 0,
+ 0, 0,
+ 0, 0,
+ 0, 0));
+
+ metricValue = metric.value;
+ assertFalse(metricValue.valid);
+ assertEquals(undefined, metricValue.value);
+
+ }
+
+ //helper different from qosinfo tests functions
+
+ private function generateQoSInfo(timestamp:Number, currentIndex:int, ... playbackArgs):QoSInfo
+ {
+ var v:Vector. = new Vector.();
+ var playbackDetails:Vector. = new Vector.;
+ var i:int;
+ for(i=0; i< playbackArgs.length; i+=2)
+ playbackDetails.push(new PlaybackDetails(i/2, playbackArgs[i], playbackArgs[i+1]));
+
+ for(i=0; i< 5; i++)
+ {
+ v[i] = new QualityLevel( i, 150+100*i , "test" + (150+100*i) );
+ }
+ return (new QoSInfo(timestamp, 5678, v, currentIndex, 0, new FragmentDetails(14000, 4000, 568, 2), 0, playbackDetails));
+ }
+
+ //helper identical to qosinfo tests functions
+ private function addQoSInfo(qos:QoSInfo):void
+ {
+ netStream.dispatchEvent(new QoSInfoEvent(QoSInfoEvent.QOS_UPDATE, false, false, qos));
+ }
+
+ private var metric:DroppedFPSMetric;
+ private var qosInfoHistory:QoSInfoHistory;
+ private var netStream:NetStream;
+ }
+}
\ No newline at end of file
diff --git a/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/TestEmptyBufferInterruptionMetric.as b/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/TestEmptyBufferInterruptionMetric.as
new file mode 100644
index 0000000..173aafa
--- /dev/null
+++ b/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/TestEmptyBufferInterruptionMetric.as
@@ -0,0 +1,131 @@
+/*****************************************************
+ *
+ * Copyright 2011 Adobe Systems Incorporated. All Rights Reserved.
+ *
+ *****************************************************
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ *
+ * The Initial Developer of the Original Code is Adobe Systems Incorporated.
+ * Portions created by Adobe Systems Incorporated are Copyright (C) 2011 Adobe Systems
+ * Incorporated. All Rights Reserved.
+ *
+ *****************************************************/
+package org.osmf.net.metrics
+{
+ import flash.net.NetConnection;
+ import flash.net.NetStream;
+
+ import flexunit.framework.Assert;
+
+ import org.flexunit.asserts.assertEquals;
+ import org.flexunit.asserts.assertFalse;
+ import org.flexunit.asserts.assertNotNull;
+ import org.flexunit.asserts.assertTrue;
+ import org.osmf.events.QoSInfoEvent;
+ import org.osmf.net.qos.QoSInfo;
+ import org.osmf.net.qos.QoSInfoHistory;
+ import org.osmf.net.qos.QualityLevel;
+
+ public class TestEmptyBufferInterruptionMetric
+ {
+ [Before]
+ public function setUp():void
+ {
+ var conn:NetConnection = new NetConnection();
+ conn.connect(null);
+ netStream = new NetStream(conn);
+ qosInfoHistory = new QoSInfoHistory(netStream, 4);
+ }
+
+ [After]
+ public function tearDown():void
+ {
+ netStream = null;
+ qosInfoHistory = null;
+ }
+
+ [BeforeClass]
+ public static function setUpBeforeClass():void
+ {
+ }
+
+ [AfterClass]
+ public static function tearDownAfterClass():void
+ {
+ }
+
+ [Test]
+ public function testEmptyBufferInterruptionMetricWhenQoSIsEmpty():void
+ {
+ metric=new EmptyBufferMetric(qosInfoHistory);
+ assertEquals(MetricType.EMPTY_BUFFER, metric.type);
+
+ //check initial value
+ var metricValue:MetricValue;
+ metricValue = metric.value;
+ assertEquals(undefined, metricValue.value);
+ assertFalse(metricValue.valid);
+ }
+
+
+ [Test]
+ public function testEmptyBufferInterruptionMetricForQoSPresent():void
+ {
+ metric=new EmptyBufferMetric(qosInfoHistory);
+ assertEquals(MetricType.EMPTY_BUFFER, metric.type);
+
+ addQoSInfo(generateQoSInfo(1111, false));
+ //check 1st value
+ var metricValue:MetricValue;
+ metricValue = metric.value;
+ assertFalse(metricValue.value);
+ assertTrue(metricValue.valid);
+
+ addQoSInfo(generateQoSInfo(2222, true));
+ //check 2nd value
+ metricValue = metric.value;
+ assertTrue(metricValue.value);
+ assertTrue(metricValue.valid);
+
+ addQoSInfo(generateQoSInfo(3333, false));
+ //check another value
+ metricValue = metric.value;
+ assertFalse(metricValue.value);
+ assertTrue(metricValue.valid);
+
+ }
+
+ //helper different from qosinfo tests functions
+
+ private function generateQoSInfo(timestamp:Number, bufferEmpty:Boolean):QoSInfo
+ {
+ var v:Vector. = new Vector.();
+ for(var i:uint=0; i< 3; i++)
+ {
+ v[i] = new QualityLevel( i, 150+ 100*i, "test" + (150+ 100*i) );
+ }
+ return (new QoSInfo(timestamp, 5678, v, 2, 2, null, NaN, null, null, NaN, NaN, bufferEmpty ));
+ }
+
+ //helper identical to qosinfo tests functions
+ private function addQoSInfo(qos:QoSInfo):void
+ {
+ netStream.dispatchEvent(new QoSInfoEvent(QoSInfoEvent.QOS_UPDATE, false, false, qos));
+ }
+
+
+ private var metric:EmptyBufferMetric;
+ private var qosInfoHistory:QoSInfoHistory;
+ private var netStream:NetStream;
+
+ }
+}
\ No newline at end of file
diff --git a/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/TestFPSMetric.as b/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/TestFPSMetric.as
new file mode 100644
index 0000000..79054d5
--- /dev/null
+++ b/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/TestFPSMetric.as
@@ -0,0 +1,133 @@
+/*****************************************************
+ *
+ * Copyright 2011 Adobe Systems Incorporated. All Rights Reserved.
+ *
+ *****************************************************
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ *
+ * The Initial Developer of the Original Code is Adobe Systems Incorporated.
+ * Portions created by Adobe Systems Incorporated are Copyright (C) 2011 Adobe Systems
+ * Incorporated. All Rights Reserved.
+ *
+ *****************************************************/
+package org.osmf.net.metrics
+{
+ import flash.net.NetConnection;
+ import flash.net.NetStream;
+
+ import flashx.textLayout.debug.assert;
+
+ import flexunit.framework.Assert;
+
+ import org.flexunit.asserts.assertEquals;
+ import org.flexunit.asserts.assertFalse;
+ import org.flexunit.asserts.assertNotNull;
+ import org.flexunit.asserts.assertTrue;
+ import org.osmf.events.QoSInfoEvent;
+ import org.osmf.net.qos.FragmentDetails;
+ import org.osmf.net.qos.QoSInfo;
+ import org.osmf.net.qos.QoSInfoHistory;
+ import org.osmf.net.qos.QualityLevel;
+
+ public class TestFPSMetric
+ {
+ [Before]
+ public function setUp():void
+ {
+ var conn:NetConnection = new NetConnection();
+ conn.connect(null);
+ netStream = new NetStream(conn);
+ qosInfoHistory = new QoSInfoHistory(netStream, 4);
+ }
+
+ [After]
+ public function tearDown():void
+ {
+ }
+
+ [BeforeClass]
+ public static function setUpBeforeClass():void
+ {
+ }
+
+ [AfterClass]
+ public static function tearDownAfterClass():void
+ {
+ }
+
+ [Test]
+ public function testMetricGetType():void
+ {
+ metric=new FPSMetric(qosInfoHistory);
+
+ //check first response when history is empty
+ var metricValue:MetricValue;
+ metricValue = metric.value;
+ assertEquals(MetricType.FPS, metric.type);
+ assertEquals(false, metricValue.valid);
+ assertEquals(undefined, metricValue.value);
+
+ //check response for NaN
+ addQoSInfo(generateQoSInfo(1111, NaN));
+ metricValue = metric.value;
+ assertEquals(MetricType.FPS, metric.type);
+ assertEquals(false, metricValue.valid);
+ assertEquals(undefined, metricValue.value);
+
+ //check response for 0
+ addQoSInfo(generateQoSInfo(2222, 0));
+ metricValue = metric.value;
+ assertEquals(MetricType.FPS, metric.type);
+ assertEquals(false, metricValue.valid);
+ assertEquals(undefined, metricValue.value);
+
+ //check response for valid value
+ addQoSInfo(generateQoSInfo(3333, 23.9));
+ metricValue = metric.value;
+ assertEquals(MetricType.FPS, metric.type);
+ assertEquals(true, metricValue.valid);
+ assertEquals(23.9, metricValue.value);
+
+ //check that it gets the latest
+ addQoSInfo(generateQoSInfo(4444, 25.1));
+ metricValue = metric.value;
+ assertEquals(MetricType.FPS, metric.type);
+ assertEquals(true, metricValue.valid);
+ assertEquals(25.1, metricValue.value);
+
+ }
+
+
+ //helper different from qosinfo tests functions
+
+ private function generateQoSInfo(timestamp:Number, fps:Number):QoSInfo
+ {
+ var v:Vector. = new Vector.();
+ for(var i:uint=0; i< 3; i++)
+ {
+ v[i] = new QualityLevel( i, 150+ 100*i, "test" + (150+ 100*i) );
+ }
+ return (new QoSInfo(timestamp, 5678, v,1, 2, new FragmentDetails(400000, 4, 3, 0, "test"), fps ));
+ }
+
+ //helper identical to qosinfo tests functions
+ private function addQoSInfo(qos:QoSInfo):void
+ {
+ netStream.dispatchEvent(new QoSInfoEvent(QoSInfoEvent.QOS_UPDATE, false, false, qos));
+ }
+
+
+ private var metric:FPSMetric;
+ private var qosInfoHistory:QoSInfoHistory;
+ private var netStream:NetStream;
+ }
+}
\ No newline at end of file
diff --git a/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/TestFragmentCountMetric.as b/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/TestFragmentCountMetric.as
new file mode 100644
index 0000000..9343f34
--- /dev/null
+++ b/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/TestFragmentCountMetric.as
@@ -0,0 +1,148 @@
+/*****************************************************
+ *
+ * Copyright 2011 Adobe Systems Incorporated. All Rights Reserved.
+ *
+ *****************************************************
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ *
+ * The Initial Developer of the Original Code is Adobe Systems Incorporated.
+ * Portions created by Adobe Systems Incorporated are Copyright (C) 2011 Adobe Systems
+ * Incorporated. All Rights Reserved.
+ *
+ *****************************************************/
+package org.osmf.net.metrics
+{
+ import flash.net.NetConnection;
+ import flash.net.NetStream;
+
+ import flashx.textLayout.debug.assert;
+
+ import flexunit.framework.Assert;
+
+ import org.flexunit.asserts.assertEquals;
+ import org.flexunit.asserts.assertFalse;
+ import org.flexunit.asserts.assertNotNull;
+ import org.flexunit.asserts.assertTrue;
+ import org.osmf.events.QoSInfoEvent;
+ import org.osmf.net.qos.FragmentDetails;
+ import org.osmf.net.qos.QoSInfo;
+ import org.osmf.net.qos.QoSInfoHistory;
+ import org.osmf.net.qos.QualityLevel;
+
+ public class TestFragmentCountMetric
+ {
+ [Before]
+ public function setUp():void
+ {
+ var conn:NetConnection = new NetConnection();
+ conn.connect(null);
+ netStream = new NetStream(conn);
+ qosInfoHistory = new QoSInfoHistory(netStream);
+ }
+
+ [After]
+ public function tearDown():void
+ {
+ }
+
+ [BeforeClass]
+ public static function setUpBeforeClass():void
+ {
+ }
+
+ [AfterClass]
+ public static function tearDownAfterClass():void
+ {
+ }
+
+ [Test]
+ public function testFragmentCountMetricEmptyQoSInfoHistory():void
+ {
+ metric=new FragmentCountMetric(qosInfoHistory);
+
+ //check initial value
+ var metricValue:MetricValue;
+ metricValue = metric.value;
+ assertEquals(undefined, metricValue.value);
+ assertFalse(metricValue.valid);
+ }
+
+ [Test]
+ public function testFragmentCountMetricPopulatedQoSInfoHistory():void
+ {
+ metric=new FragmentCountMetric(qosInfoHistory);
+
+ //check initial value
+ var metricValue:MetricValue;
+ metricValue = metric.value;
+ assertEquals(undefined, metricValue.value);
+ assertFalse(metricValue.valid);
+
+ addQoSInfo(generateQoSInfo(1111, 0, new FragmentDetails(1400000, 4010, 2001, 0)));
+ addQoSInfo(generateQoSInfo(2222, 0, new FragmentDetails(1400000, 4010, 2001, 0)));
+ addQoSInfo(generateQoSInfo(3333, 0, new FragmentDetails(1400000, 4010, 2001, 0)));
+ addQoSInfo(generateQoSInfo(4444, 0, new FragmentDetails(1400000, 4010, 2001, 0)));
+ addQoSInfo(generateQoSInfo(5555, 0, new FragmentDetails(1400000, 4010, 2001, 0)));
+
+ metricValue = metric.value;
+ assertEquals(5, metricValue.value);
+ assertTrue(metricValue.valid);
+
+ }
+
+
+ [Test(expects="ArgumentError")]
+ public function testFragmentCountMetricNullQoSInfoHistory():void
+ {
+ metric=new FragmentCountMetric(null);
+ }
+
+ [Test]
+ public function testMetricGetType():void
+ {
+ metric=new FragmentCountMetric(qosInfoHistory );
+ assertEquals(MetricType.FRAGMENT_COUNT, metric.type);
+ }
+
+ //helper different from qosinfo tests functions
+
+ private function generateQoSInfo(timestamp:Number, currentBitrate:Number, fragmentDetails:FragmentDetails):QoSInfo
+ {
+ var v:Vector. = new Vector.();
+ for(var i:uint=0; i< 3; i++)
+ {
+ v[i] = new QualityLevel( i, 150+ 100*i, "test" + (150+ 100*i) );
+ }
+ return (new QoSInfo(timestamp, 5678, v, currentBitrate, currentBitrate, fragmentDetails ));
+ }
+
+ //helper identical to qosinfo tests functions
+ private function addQoSInfo(qos:QoSInfo):void
+ {
+ netStream.dispatchEvent(new QoSInfoEvent(QoSInfoEvent.QOS_UPDATE, false, false, qos));
+ }
+
+ private function generateWeights(... weights):Vector.
+ {
+ var v:Vector. = new Vector.();
+ for(var i:uint=0; i< weights.length; i++)
+ {
+ v[i] = weights[i] ;
+ }
+ return (v);
+ }
+
+ private var metric:FragmentCountMetric;
+ private var qosInfoHistory:QoSInfoHistory;
+ private var netStream:NetStream;
+ }
+}
\ No newline at end of file
diff --git a/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/TestMetricBase.as b/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/TestMetricBase.as
new file mode 100644
index 0000000..93127d8
--- /dev/null
+++ b/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/TestMetricBase.as
@@ -0,0 +1,175 @@
+/*****************************************************
+ *
+ * Copyright 2011 Adobe Systems Incorporated. All Rights Reserved.
+ *
+ *****************************************************
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ *
+ * The Initial Developer of the Original Code is Adobe Systems Incorporated.
+ * Portions created by Adobe Systems Incorporated are Copyright (C) 2011 Adobe Systems
+ * Incorporated. All Rights Reserved.
+ *
+ *****************************************************/
+package org.osmf.net.metrics
+{
+ import flash.net.NetConnection;
+ import flash.net.NetStream;
+
+ import org.flexunit.asserts.assertEquals;
+ import org.flexunit.asserts.assertFalse;
+ import org.flexunit.asserts.assertStrictlyEquals;
+ import org.flexunit.asserts.assertTrue;
+ import org.osmf.events.QoSInfoEvent;
+ import org.osmf.net.qos.FragmentDetails;
+ import org.osmf.net.qos.QoSInfo;
+ import org.osmf.net.qos.QoSInfoHistory;
+ import org.osmf.net.qos.QualityLevel;
+
+ public class TestMetricBase
+ {
+ [Before]
+ public function setUp():void
+ {
+ var conn:NetConnection = new NetConnection();
+ conn.connect(null);
+ netStream = new NetStream(conn);
+ qosInfoHistory = new QoSInfoHistory(netStream);
+ }
+
+ [After]
+ public function tearDown():void
+ {
+ }
+
+ [BeforeClass]
+ public static function setUpBeforeClass():void
+ {
+ }
+
+ [AfterClass]
+ public static function tearDownAfterClass():void
+ {
+ }
+
+ [Test]
+ public function testValueWhenQoSInfoHistoryIsEmpty():void
+ {
+ metric = new MetricComplexMocker("test", qosInfoHistory);
+ assertEquals("test", metric.type);
+
+ //check initial value
+ var metricValue:MetricValue;
+ metricValue = metric.value;
+ assertEquals(undefined, metricValue.value);
+ assertFalse(metricValue.valid);
+
+ }
+
+ [Test(expects="ArgumentError")]
+ public function testMetricInitWithNullQoSInfoHistory():void
+ {
+ metric = new MetricComplexMocker("test", null);
+ }
+
+ [Test]
+ public function testValueWhenQoSInfoHistoryIsPopulated():void
+ {
+ metric=new MetricComplexMocker("test", qosInfoHistory);
+ assertEquals("test", metric.type);
+
+ var metricValue:MetricValue;
+ metricValue = metric.value;
+
+ //check initial value
+ assertEquals(undefined, metricValue.value);
+ assertFalse(metricValue.valid);
+
+ //add a new item in history, this will force refresh
+ addQoSInfo(generateQoSInfo(1111, 150, 250, 350));
+
+ metricValue = metric.value;
+ assertEquals(1,metricValue.value);
+ assertTrue(metricValue.valid);
+
+ //add a new item in history, this will force refresh
+ addQoSInfo(generateQoSInfo(2222, 151, 251, 351));
+
+ metricValue = metric.value;
+ assertEquals(2,metricValue.value);
+ assertTrue(metricValue.valid);
+
+
+ //get the cached value, this will not force refresh
+ metricValue = metric.value;
+ assertEquals(2,metricValue.value);
+ assertTrue(metricValue.valid);
+
+ }
+
+ [Test]
+ public function testValueWhenQoSInfoHistoryIsPopulatedAndFlushed():void
+ {
+ //create and populate the metric
+ metric=new MetricComplexMocker("test", qosInfoHistory);
+ assertEquals("test", metric.type);
+
+ addQoSInfo(generateQoSInfo(1111, 150, 250, 350));
+
+ var metricValue:MetricValue;
+ metricValue = metric.value;
+
+ //check initial value
+ assertEquals(1, metricValue.value);
+ assertTrue(metricValue.valid);
+
+ //add a new item in history, this will force refresh
+ addQoSInfo(generateQoSInfo(2222, 150, 250, 350));
+
+ metricValue = metric.value;
+ assertEquals(2, metricValue.value);
+ assertTrue(metricValue.valid);
+
+ //flush QosInfoHistory
+ qosInfoHistory.flush();
+
+ //check value, should default to not defined
+ metricValue = metric.value;
+ assertEquals(undefined, metricValue.value);
+ assertFalse(metricValue.valid);
+
+ }
+
+ //helper different from qosinfo tests functions
+
+ private function generateQoSInfo(timestamp:Number, ... qualityLevels):QoSInfo
+ {
+ var v:Vector. = new Vector.();
+ for(var i:uint=0; i< qualityLevels.length; i++)
+ {
+ v[i] = new QualityLevel( i, qualityLevels[i], "test" + qualityLevels[i] );
+ }
+ return (new QoSInfo(timestamp, 5678, v, 0, 0, new FragmentDetails(14000, 4000, 568, 2)));
+ }
+
+ //helper identical to qosinfo tests functions
+ private function addQoSInfo(qos:QoSInfo):void
+ {
+ netStream.dispatchEvent(new QoSInfoEvent(QoSInfoEvent.QOS_UPDATE, false, false, qos));
+ }
+
+ private var metric:MetricComplexMocker;
+ private var qosInfoHistory:QoSInfoHistory;
+ private var netStream:NetStream;
+
+
+ }
+}
\ No newline at end of file
diff --git a/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/TestMetricFactory.as b/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/TestMetricFactory.as
new file mode 100644
index 0000000..8cee0f7
--- /dev/null
+++ b/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/TestMetricFactory.as
@@ -0,0 +1,282 @@
+/*****************************************************
+ *
+ * Copyright 2011 Adobe Systems Incorporated. All Rights Reserved.
+ *
+ *****************************************************
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ *
+ * The Initial Developer of the Original Code is Adobe Systems Incorporated.
+ * Portions created by Adobe Systems Incorporated are Copyright (C) 2011 Adobe Systems
+ * Incorporated. All Rights Reserved.
+ *
+ *****************************************************/
+package org.osmf.net.metrics
+{
+ import flash.net.NetConnection;
+ import flash.net.NetStream;
+
+ import org.flexunit.asserts.assertEquals;
+ import org.flexunit.asserts.assertNotNull;
+ import org.flexunit.asserts.assertNull;
+ import org.flexunit.asserts.assertStrictlyEquals;
+ import org.flexunit.asserts.assertTrue;
+ import org.flexunit.internals.runners.statements.ExpectException;
+ import org.osmf.net.qos.QoSInfoHistory;
+ import org.osmf.net.qos.QoSInfoHistoryGenerator;
+
+ public class TestMetricFactory
+ {
+ [Before]
+ public function setUp():void
+ {
+ var conn:NetConnection = new NetConnection();
+ conn.connect(null);
+ var ns:NetStream = new NetStream(conn);
+ var qosInfoHistory:QoSInfoHistory = new QoSInfoHistory(ns);
+ factory = new MetricFactory(qosInfoHistory);
+ }
+
+ [After]
+ public function tearDown():void
+ {
+ factory = null;
+ }
+
+ [Test]
+ public function testAddItem():void
+ {
+
+ //check initial conditions
+ assertEquals(factory.numItems, 0);
+ assertNotNull(factory.getItems());
+ assertEquals(0,factory.getItems().length);
+
+ // create a MetricFactoryItem
+ var item:MetricFactoryItem = getMetricFactoryItem(METRIC_TYPE_1);
+
+ //checks the type of the item
+ assertEquals(METRIC_TYPE_1, item.type);
+
+ // add the item
+ factory.addItem(item);
+
+ // check that the item is the only one in the list
+ assertEquals(factory.numItems, 1);
+ assertEquals(factory.getItem(METRIC_TYPE_1), item);
+ }
+
+ [Test]
+ public function testRemoveItem():void
+ {
+ // create a MetricFactoryItem
+ var item:MetricFactoryItem = getMetricFactoryItem(METRIC_TYPE_1);
+
+ // add the item
+ factory.addItem(item);
+
+ // remove the item
+ factory.removeItem(item);
+
+ // check that the factory has no items
+ assertEquals(factory.numItems, 0);
+ assertNull(factory.getItem(METRIC_TYPE_1));
+ }
+
+ [Test]
+ public function testRemoveNonExistingItem():void
+ {
+ // create a MetricFactoryItem
+ var item:MetricFactoryItem = getMetricFactoryItem(METRIC_TYPE_1);
+
+ var item2:MetricFactoryItem = getMetricFactoryItem(METRIC_TYPE_3);
+
+ // add the item
+ factory.addItem(item);
+
+ // remove the item
+ factory.removeItem(item2);
+
+ // check that the factory still has 1 item
+ assertEquals(factory.numItems, 1);
+ }
+
+
+ [Test(expects="ArgumentError")]
+ public function testRemoveNullItem():void
+ {
+ // create a MetricFactoryItem
+ var item:MetricFactoryItem = getMetricFactoryItem(METRIC_TYPE_1);
+
+ // add the item
+ factory.addItem(item);
+
+ // remove the item
+ factory.removeItem(null);
+
+ }
+
+ [Test(expects="ArgumentError")]
+ public function testAddNullItem():void
+ {
+ // add the item
+ factory.addItem(null);
+ }
+
+ [Test]
+ public function testGetItemList():void
+ {
+ // create two items
+ var item1:MetricFactoryItem = getMetricFactoryItem(METRIC_TYPE_1);
+ var item2:MetricFactoryItem = getMetricFactoryItem(METRIC_TYPE_2);
+
+ // add them to the factory
+ factory.addItem(item1);
+ factory.addItem(item2);
+
+ // check that the list contains them both
+ var itemList:Vector. = factory.getItems();
+
+ assertEquals(itemList.length, 2);
+ var item1Found:Boolean = false;
+ var item2Found:Boolean = false;
+
+ for each (var item:MetricFactoryItem in itemList)
+ {
+ if (item == item1)
+ {
+ item1Found = true;
+ }
+ else if (item == item2)
+ {
+ item2Found = true;
+ }
+ }
+
+ assertTrue(item1Found && item2Found);
+ }
+
+ [Test]
+ public function testBuildMetricValid():void
+ {
+ // create two items
+ var item1:MetricFactoryItem = getMetricFactoryItem(METRIC_TYPE_1);
+ var item2:MetricFactoryItem = getMetricFactoryItem(METRIC_TYPE_2);
+
+ // add them to the factory
+ factory.addItem(item1);
+ factory.addItem(item2);
+
+ var metric:MetricMocker = factory.buildMetric(METRIC_TYPE_1, null) as MetricMocker;
+
+ assertEquals(metric.type, METRIC_TYPE_1);
+ }
+
+ [Test]
+ public function testBuildMetricAddSimilarMetricTwice():void
+ {
+ // create two items
+ var item1:MetricFactoryItem = getMetricFactoryItem(METRIC_TYPE_1);
+ var item2:MetricFactoryItem = getMetricFactoryItem(METRIC_TYPE_1);
+
+ // add them to the factory
+ factory.addItem(item1);
+ factory.addItem(item2);
+
+ var metric:MetricMocker = factory.buildMetric(METRIC_TYPE_1, null) as MetricMocker;
+
+ assertEquals(1,factory.numItems);
+ assertStrictlyEquals(item2,factory.getItem(METRIC_TYPE_1));
+
+ assertEquals(metric.type, METRIC_TYPE_1);
+ }
+
+ [Test]
+ public function testBuildMetricAddSameMetricTwice():void
+ {
+ // create two items
+ var item1:MetricFactoryItem = getMetricFactoryItem(METRIC_TYPE_1);
+
+ // add them to the factory
+ factory.addItem(item1);
+ factory.addItem(item1);
+
+ assertEquals(1,factory.numItems);
+ var metric:MetricMocker = factory.buildMetric(METRIC_TYPE_1, null) as MetricMocker;
+
+ assertEquals(metric.type, METRIC_TYPE_1);
+ }
+
+
+ [Test]
+ public function testGetItemByType():void
+ {
+ // create a MetricFactoryItem
+ var item:MetricFactoryItem = getMetricFactoryItem(METRIC_TYPE_1);
+
+ // add the item
+ factory.addItem(item);
+
+ // check that the item is the only one in the list
+ assertEquals(factory.numItems, 1);
+ assertEquals(factory.getItem(METRIC_TYPE_1), item);
+
+ //check 2 negative tests
+ assertNull(factory.getItem(METRIC_TYPE_3));
+ assertNull(factory.getItem(null));
+
+ }
+
+ [Test(expects="org.osmf.events.MetricError")]
+ public function testBuildMetricInvalid():void
+ {
+ // create two items
+ var item1:MetricFactoryItem = getMetricFactoryItem(METRIC_TYPE_1);
+ var item2:MetricFactoryItem = getMetricFactoryItem(METRIC_TYPE_2);
+
+ // add them to the factory
+ factory.addItem(item1);
+ factory.addItem(item2);
+
+ var metric:MetricMocker = factory.buildMetric(METRIC_TYPE_3, null) as MetricMocker;
+ }
+
+ [Test(expects="org.osmf.events.MetricError")]
+ public function testBuildMetricNullType():void
+ {
+
+ var metric:MetricMocker = factory.buildMetric(null, 4) as MetricMocker;
+ }
+ [Test(expects="org.osmf.events.MetricError")]
+ public function testBuildMetricEmptyType():void
+ {
+
+ var metric:MetricMocker = factory.buildMetric("", 4) as MetricMocker;
+ }
+
+ private function getMetricFactoryItem(type:String):MetricFactoryItem
+ {
+ return new MetricFactoryItem
+ ( type
+ , function(qosInfoHistory:QoSInfoHistory, ...args):MetricBase
+ {
+ return new MetricMocker(type, QoSInfoHistoryGenerator.generateSampleQoSInfoHistory());
+ }
+ );
+ }
+
+ private var factory:MetricFactory;
+
+ private static const METRIC_TYPE_1:String = "com.example.metrics.sample1";
+ private static const METRIC_TYPE_2:String = "com.example.metrics.sample2";
+ private static const METRIC_TYPE_3:String = "com.example.metrics.sample3";
+ }
+}
\ No newline at end of file
diff --git a/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/TestMetricFactoryItem.as b/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/TestMetricFactoryItem.as
new file mode 100644
index 0000000..3f163e4
--- /dev/null
+++ b/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/TestMetricFactoryItem.as
@@ -0,0 +1,93 @@
+/*****************************************************
+ *
+ * Copyright 2011 Adobe Systems Incorporated. All Rights Reserved.
+ *
+ *****************************************************
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ *
+ * The Initial Developer of the Original Code is Adobe Systems Incorporated.
+ * Portions created by Adobe Systems Incorporated are Copyright (C) 2011 Adobe Systems
+ * Incorporated. All Rights Reserved.
+ *
+ *****************************************************/
+package org.osmf.net.metrics
+{
+ import flexunit.framework.Assert;
+
+ import org.flexunit.asserts.assertEquals;
+ import org.flexunit.asserts.assertStrictlyEquals;
+ import org.flexunit.asserts.assertTrue;
+ import org.flexunit.internals.runners.statements.ExpectException;
+ import org.osmf.net.qos.QoSInfoHistory;
+ import org.osmf.net.qos.QoSInfoHistoryGenerator;
+
+ public class TestMetricFactoryItem
+ {
+ [Before]
+ public function setUp():void
+ {
+ }
+
+ [After]
+ public function tearDown():void
+ {
+ }
+
+ [BeforeClass]
+ public static function setUpBeforeClass():void
+ {
+ }
+
+ [AfterClass]
+ public static function tearDownAfterClass():void
+ {
+ }
+
+ [Test]
+ public function testMetricFactoryItemGet():void
+ {
+ var f:Function = function(qosInfoHistory:QoSInfoHistory, ...args):MetricBase
+ {
+ return new MetricMocker(METRIC_TYPE_1, QoSInfoHistoryGenerator.generateEmptyQoSInfoHistory());
+ };
+
+ metricFactoryItem = new MetricFactoryItem(METRIC_TYPE_1, f);
+
+ assertEquals(METRIC_TYPE_1, metricFactoryItem.type);
+ assertStrictlyEquals(f, metricFactoryItem.metricCreationFunction);
+
+ assertTrue(metricFactoryItem.metricCreationFunction(null) is MetricBase);
+ }
+
+
+ [Test(expects="ArgumentError")]
+ public function testMetricFactoryItemInitTypeNull():void
+ {
+ metricFactoryItem = new MetricFactoryItem(null,
+ function(qosInfoHistory:QoSInfoHistory, ...args):MetricBase
+ {
+ return new MetricMocker(METRIC_TYPE_1, qosInfoHistory);
+ });
+ }
+
+ [Test(expects="ArgumentError")]
+ public function testMetricFactoryItemInitFunctionNull():void
+ {
+ metricFactoryItem = new MetricFactoryItem(METRIC_TYPE_1,null);
+ }
+
+ private var metricFactoryItem:MetricFactoryItem;
+
+ private static const METRIC_TYPE_1:String = "com.example.metrics.sample1";
+
+ }
+}
\ No newline at end of file
diff --git a/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/TestMetricRepository.as b/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/TestMetricRepository.as
new file mode 100644
index 0000000..c522c7f
--- /dev/null
+++ b/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/TestMetricRepository.as
@@ -0,0 +1,258 @@
+/*****************************************************
+ *
+ * Copyright 2011 Adobe Systems Incorporated. All Rights Reserved.
+ *
+ *****************************************************
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ *
+ * The Initial Developer of the Original Code is Adobe Systems Incorporated.
+ * Portions created by Adobe Systems Incorporated are Copyright (C) 2011 Adobe Systems
+ * Incorporated. All Rights Reserved.
+ *
+ *****************************************************/
+package org.osmf.net.metrics
+{
+ import flash.utils.getTimer;
+
+ import org.flexunit.asserts.assertEquals;
+ import org.flexunit.asserts.assertNotNull;
+ import org.flexunit.asserts.assertStrictlyEquals;
+ import org.flexunit.asserts.assertTrue;
+ import org.osmf.events.TimeEvent;
+
+ public class TestMetricRepository
+ {
+ [Before]
+ public function setUp():void
+ {
+ metricRepository = new MetricRepository(new MetricFactoryMocker());
+
+ metric1Value = new MetricValue("metric1value", true);
+ metric2Value = new MetricValue("metric2value", true);
+ }
+
+ [After]
+ public function tearDown():void
+ {
+ metricRepository = null;
+ }
+
+ /**
+ * Tests that the getMetric function returns the desired metric (type and params)
+ */
+ [Test]
+ public function testGetMetric():void
+ {
+ var metric:MetricMocker = metricRepository.getMetric(METRIC_TYPE_1, metric1Value) as MetricMocker;
+
+ assertNotNull(metric);
+ assertEquals(metric.type, METRIC_TYPE_1);
+ assertEquals(metric.value, metric1Value);
+ }
+
+ /**
+ * Tests that the getMetric returns correct init error
+ */
+ [Test(expects="ArgumentError")]
+ public function testInitMetricRepository():void
+ {
+ metricRepository = new MetricRepository(null);
+ }
+
+ /**
+ * Tests that the same object is returned if we request the same metric type with the same params
+ * twice (no duplication of objects)
+ */
+ [Test]
+ public function testGetMetricNoDuplication():void
+ {
+ //create complex parameter
+ var v:Vector. = new Vector.();
+ v[0] = metric1Value;
+ v[1] = metric2Value;
+
+ var metric1:MetricMocker = metricRepository.getMetric(METRIC_TYPE_1, metric1Value, v) as MetricMocker;
+ var metric1bis:MetricMocker = metricRepository.getMetric(METRIC_TYPE_1, metric1Value, v) as MetricMocker;
+
+ assertNotNull(metric1);
+ assertNotNull(metric1bis);
+ assertStrictlyEquals(metric1, metric1bis);
+ }
+
+ /**
+ * Tests that the same object is returned if we request the same metric type with the same params
+ * twice (no duplication of objects)
+ */
+ [Test]
+ public function testGetMetricNoDuplicationDifferentObjects():void
+ {
+ //create complex parameter
+ var v:Vector. = new Vector.();
+ v.push(metric1Value);
+ v.push(metric2Value);
+ var u:Vector. = new Vector.();
+ u.push(metric1Value);
+ u.push(metric2Value);
+
+ var metric1:MetricMocker = metricRepository.getMetric(METRIC_TYPE_1, metric1Value, v) as MetricMocker;
+ var metric1bis:MetricMocker = metricRepository.getMetric(METRIC_TYPE_1, metric1Value, u) as MetricMocker;
+
+ assertNotNull(metric1);
+ assertNotNull(metric1bis);
+ assertStrictlyEquals(metric1, metric1bis);
+ }
+
+ /**
+ * Tests that two different objects are returned if we request 2 metrics with the same
+ * type, but with different params
+ */
+ [Test]
+ public function testGetMetricSameTypeDifferentParams():void
+ {
+ //create complex parameter
+ var v:Vector. = new Vector.();
+ v.push(metric1Value);
+ v.push(metric2Value);
+
+ var metric1:MetricMocker = metricRepository.getMetric(METRIC_TYPE_1, metric1Value, v) as MetricMocker;
+ var metric2:MetricMocker = metricRepository.getMetric(METRIC_TYPE_1, metric2Value, v) as MetricMocker;
+
+ assertNotNull(metric1);
+ assertNotNull(metric2);
+ assertTrue(metric1 != metric2);
+ }
+
+ /**
+ * Tests that two different objects are returned if we request 2 metrics with the same
+ * type, but with different params
+ */
+ [Test]
+ public function testGetMetricSameTypeDifferentParamsComplex():void
+ {
+ //create complex parameter
+ var v:Vector. = new Vector.();
+ v.push(metric1Value);
+ v.push(metric2Value);
+ var u:Vector. = new Vector.();
+ u.push(metric1Value);
+ u.push(metric1Value);
+
+ var a:Array = new Array();
+ a.push(u);
+ a.push(metric1Value);
+
+ var metric1:MetricMocker = metricRepository.getMetric(METRIC_TYPE_1, metric1Value, u) as MetricMocker;
+ var metric2:MetricMocker = metricRepository.getMetric(METRIC_TYPE_1, metric1Value, v) as MetricMocker;
+
+ assertNotNull(metric1);
+ assertNotNull(metric2);
+ assertTrue(metric1 != metric2);
+ }
+
+ /**
+ * Tests that two different objects are returned if we request 2 metrics with the same
+ * type, but with different params
+ */
+ [Test]
+ public function testGetMetricSameTypeDifferentParamsComplexArray():void
+ {
+ //create complex parameter
+ var u:Vector. = new Vector.();
+ u.push(metric1Value);
+ u.push(metric1Value);
+
+ var a:Array = new Array();
+
+ a.push(u);
+ a.push(metric1Value);
+
+
+ var metric1:MetricMocker = metricRepository.getMetric(METRIC_TYPE_1, metric1Value, u, a) as MetricMocker;
+
+ //modify array by changing the vector inside
+ u = new Vector.();
+ a = new Array();
+ u.push(metric1Value);
+ u.push(metric2Value);
+ a.push(u);
+ a.push(metric1Value);
+
+ var metric2:MetricMocker = metricRepository.getMetric(METRIC_TYPE_1, metric1Value, u, a) as MetricMocker;
+
+ assertNotNull(metric1);
+ assertNotNull(metric2);
+ assertTrue(metric1 != metric2);
+ }
+
+ /**
+ * Tests that two different objects are returned if we request 2 metrics with the same
+ * type, and with same params
+ */
+ [Test]
+ public function testGetMetricSameTypeSameParamsComplex():void
+ {
+ //create complex parameter
+ var v:Vector. = new Vector.();
+ v.push(metric1Value);
+ v.push(metric2Value);
+ var u:Vector. = new Vector.();
+ u.push(metric1Value);
+ u.push(metric2Value);
+
+ var metric1:MetricMocker = metricRepository.getMetric(METRIC_TYPE_1, metric1Value, u) as MetricMocker;
+ var metric2:MetricMocker = metricRepository.getMetric(METRIC_TYPE_1, metric1Value, v) as MetricMocker;
+
+ assertNotNull(metric1);
+ assertNotNull(metric2);
+ assertStrictlyEquals(metric1, metric2);
+ }
+
+ /**
+ * Tests that two different objects are returned if we request 2 metrics with the same
+ * type, and with null parameters
+ */
+ [Test]
+ public function testGetMetricSameTypeSameParamsNull():void
+ {
+ var metric1:MetricMocker = metricRepository.getMetric(METRIC_TYPE_1, null, null) as MetricMocker;
+ var metric2:MetricMocker = metricRepository.getMetric(METRIC_TYPE_1, null, null) as MetricMocker;
+
+ assertNotNull(metric1);
+ assertNotNull(metric2);
+ assertStrictlyEquals(metric1, metric2);
+ }
+
+ /**
+ * Tests that two different objects are returned if we request 2 metrics with the same
+ * type, and with different and null parameters
+ */
+ [Test]
+ public function testGetMetricSameTypeDifferentParamsNull():void
+ {
+ var metric1:MetricMocker = metricRepository.getMetric(METRIC_TYPE_1, null, 3) as MetricMocker;
+ var metric2:MetricMocker = metricRepository.getMetric(METRIC_TYPE_1, null, 4) as MetricMocker;
+
+ assertNotNull(metric1);
+ assertNotNull(metric2);
+ assertTrue(metric1 != metric2);
+ }
+
+ private var metricRepository:MetricRepository;
+
+ private static const METRIC_TYPE_1:String = "com.example.metrics.sample";
+ private static const MAX_RETRIEVING_TIME:int=1;
+ private static const MAX_CREATING_TIME:int=4;
+
+ private var metric1Value:MetricValue;
+ private var metric2Value:MetricValue;
+ }
+}
\ No newline at end of file
diff --git a/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/TestMetricValue.as b/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/TestMetricValue.as
new file mode 100644
index 0000000..95ec267
--- /dev/null
+++ b/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/TestMetricValue.as
@@ -0,0 +1,109 @@
+/*****************************************************
+ *
+ * Copyright 2011 Adobe Systems Incorporated. All Rights Reserved.
+ *
+ *****************************************************
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ *
+ * The Initial Developer of the Original Code is Adobe Systems Incorporated.
+ * Portions created by Adobe Systems Incorporated are Copyright (C) 2011 Adobe Systems
+ * Incorporated. All Rights Reserved.
+ *
+ *****************************************************/
+package org.osmf.net.metrics
+{
+ import flexunit.framework.Assert;
+
+ import org.flexunit.asserts.assertEquals;
+ import org.flexunit.asserts.assertFalse;
+ import org.flexunit.asserts.assertNull;
+ import org.flexunit.asserts.assertTrue;
+
+ public class TestMetricValue
+ {
+ [Before]
+ public function setUp():void
+ {
+ }
+
+ [After]
+ public function tearDown():void
+ {
+ }
+
+ [BeforeClass]
+ public static function setUpBeforeClass():void
+ {
+ }
+
+ [AfterClass]
+ public static function tearDownAfterClass():void
+ {
+ }
+
+ [Test]
+ public function testMetricValueNumber():void
+ {
+ metricValue = new MetricValue(101.3456);
+ assertEquals(101.3456, metricValue.value);
+ assertEquals(true, metricValue.valid);
+ }
+
+ [Test]
+ public function testMetricValueString():void
+ {
+ metricValue = new MetricValue("testvalue");
+ assertEquals("testvalue", metricValue.value);
+ assertEquals(true, metricValue.valid);
+ }
+
+ [Test]
+ public function testMetricValueNull():void
+ {
+ metricValue = new MetricValue(null);
+ assertNull(metricValue.value);
+ assertEquals(true, metricValue.valid);
+ }
+
+ [Test]
+ public function testMetricValueBool():void
+ {
+ metricValue = new MetricValue(true);
+ assertTrue(metricValue.value);
+ assertEquals(true, metricValue.valid);
+ }
+
+ [Test]
+ public function testMetricValueUndefined():void
+ {
+ metricValue = new MetricValue(undefined);
+ assertEquals(undefined, metricValue.value);
+ }
+
+ [Test]
+ public function testMetricValidityValid():void
+ {
+ metricValue = new MetricValue(10, true);
+ assertEquals(10,metricValue.value);
+ assertTrue(metricValue.valid);
+ }
+ [Test]
+ public function testMetricValidityInvalid():void
+ {
+ metricValue = new MetricValue(11, false);
+ assertEquals(11, metricValue.value);
+ assertFalse(metricValue.valid);
+ }
+
+ private var metricValue:MetricValue;
+ }
+}
\ No newline at end of file
diff --git a/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/TestRecentSwitchMetric.as b/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/TestRecentSwitchMetric.as
new file mode 100644
index 0000000..6f5a4f6
--- /dev/null
+++ b/lib/osmf/framework/OSMFTest/src/org/osmf/net/metrics/TestRecentSwitchMetric.as
@@ -0,0 +1,197 @@
+/*****************************************************
+ *
+ * Copyright 2011 Adobe Systems Incorporated. All Rights Reserved.
+ *
+ *****************************************************
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ *
+ * The Initial Developer of the Original Code is Adobe Systems Incorporated.
+ * Portions created by Adobe Systems Incorporated are Copyright (C) 2011 Adobe Systems
+ * Incorporated. All Rights Reserved.
+ *
+ *****************************************************/
+package org.osmf.net.metrics
+{
+ import flash.net.NetConnection;
+ import flash.net.NetStream;
+
+ import flexunit.framework.Assert;
+
+ import org.flexunit.asserts.assertEquals;
+ import org.flexunit.asserts.assertFalse;
+ import org.flexunit.asserts.assertTrue;
+ import org.osmf.events.QoSInfoEvent;
+ import org.osmf.net.qos.FragmentDetails;
+ import org.osmf.net.qos.QoSInfo;
+ import org.osmf.net.qos.QoSInfoHistory;
+ import org.osmf.net.qos.QualityLevel;
+
+ public class TestRecentSwitchMetric
+ {
+ [Before]
+ public function setUp():void
+ {
+ var conn:NetConnection = new NetConnection();
+ conn.connect(null);
+ netStream = new NetStream(conn);
+ qosInfoHistory = new QoSInfoHistory(netStream);
+ }
+
+ [After]
+ public function tearDown():void
+ {
+ netStream = null;
+ qosInfoHistory = null;
+ }
+
+ [BeforeClass]
+ public static function setUpBeforeClass():void
+ {
+ }
+
+ [AfterClass]
+ public static function tearDownAfterClass():void
+ {
+ }
+
+
+ [Test]
+ public function testRecentSwitchMetric():void
+ {
+ metric = new RecentSwitchMetric(qosInfoHistory);
+
+ assertEquals(MetricType.RECENT_SWITCH, metric.type);
+ var metricValue:MetricValue = metric.value;
+
+ assertEquals(undefined, metricValue.value);
+ assertFalse(metricValue.valid);
+
+ addQoSInfo(generateQoSInfo(1111, 0, new FragmentDetails(1400000, 4010, 2001, 0)));
+
+ metricValue = metric.value;
+ assertEquals(undefined, metricValue.value);
+ assertFalse(metricValue.valid);
+
+
+ addQoSInfo(generateQoSInfo(2222, 0, new FragmentDetails(2400000, 4020, 4001, 1)));
+
+ metricValue = metric.value;
+ assertEquals(1, metricValue.value);
+ assertTrue(metricValue.valid);
+
+ addQoSInfo(generateQoSInfo(3333, 1, new FragmentDetails(3500000, 4040, 6001, 0)));
+
+ metricValue = metric.value;
+ assertEquals(-1, metricValue.value);
+ assertTrue(metricValue.valid);
+
+
+ addQoSInfo(generateQoSInfo(4444, 4, new FragmentDetails(3500000, 4040, 6001, 4)));
+
+ metricValue = metric.value;
+ assertEquals(4, metricValue.value);
+ assertTrue(metricValue.valid);
+
+ addQoSInfo(generateQoSInfo(5555, 2, new FragmentDetails(3500000, 4040, 6001, 2)));
+
+ metricValue = metric.value;
+ assertEquals(-2, metricValue.value);
+ assertTrue(metricValue.valid);
+
+ addQoSInfo(generateQoSInfo(6666, 2, new FragmentDetails(3500000, 4040, 6001, 2)));
+
+ metricValue = metric.value;
+ assertEquals(0, metricValue.value);
+ assertTrue(metricValue.valid);
+
+ }
+
+
+ [Test]
+ public function testRecentSwitchMetricForNullFirstFragmentDetails():void
+ {
+ metric = new RecentSwitchMetric(qosInfoHistory);
+
+ assertEquals(MetricType.RECENT_SWITCH, metric.type);
+ var metricValue:MetricValue = metric.value;
+
+ assertEquals(undefined, metricValue.value);
+ assertFalse(metricValue.valid);
+
+ addQoSInfo(generateQoSInfo(1111, 0, null));
+
+ metricValue = metric.value;
+ assertEquals(undefined, metricValue.value);
+ assertFalse(metricValue.valid);
+
+
+ addQoSInfo(generateQoSInfo(2222, 0, new FragmentDetails(2400000, 4020, 4001, 1)));
+
+ metricValue = metric.value;
+ assertEquals(undefined, metricValue.value);
+ assertFalse(metricValue.valid);
+
+ }
+
+
+ [Test]
+ public function testRecentSwitchMetricForNullSecondFragmentDetails():void
+ {
+ metric = new RecentSwitchMetric(qosInfoHistory);
+
+ assertEquals(MetricType.RECENT_SWITCH, metric.type);
+ var metricValue:MetricValue = metric.value;
+
+ assertEquals(undefined, metricValue.value);
+ assertFalse(metricValue.valid);
+
+ addQoSInfo(generateQoSInfo(1111, 0, new FragmentDetails(2400000, 4020, 4001, 1)));
+
+ metricValue = metric.value;
+ assertEquals(undefined, metricValue.value);
+ assertFalse(metricValue.valid);
+
+
+ addQoSInfo(generateQoSInfo(2222, 1, null));
+
+ metricValue = metric.value;
+ assertEquals(undefined, metricValue.value);
+ assertFalse(metricValue.valid);
+
+ }
+
+ //helper different from qosinfo tests functions
+
+ private function generateQoSInfo(timestamp:Number, currentIndex:Number, fragmentDetails:FragmentDetails):QoSInfo
+ {
+ var v:Vector. = new Vector.();
+ for(var i:uint=0; i< 3; i++)
+ {
+ v[i] = new QualityLevel( i, 150+ 100*i, "test" + (150+ 100*i) );
+ }
+ return (new QoSInfo(timestamp, 5678+timestamp, v, currentIndex, currentIndex, fragmentDetails));
+ }
+
+ //helper identical to qosinfo tests functions
+ private function addQoSInfo(qos:QoSInfo):void
+ {
+ netStream.dispatchEvent(new QoSInfoEvent(QoSInfoEvent.QOS_UPDATE, false, false, qos));
+ }
+
+ private var metric:RecentSwitchMetric;
+ private var qosInfoHistory:QoSInfoHistory;
+ private var netStream:NetStream;
+
+
+
+ }
+}
\ No newline at end of file
diff --git a/lib/osmf/framework/OSMFTest/src/org/osmf/net/qos/QoSInfoHistoryGenerator.as b/lib/osmf/framework/OSMFTest/src/org/osmf/net/qos/QoSInfoHistoryGenerator.as
new file mode 100644
index 0000000..3ce36be
--- /dev/null
+++ b/lib/osmf/framework/OSMFTest/src/org/osmf/net/qos/QoSInfoHistoryGenerator.as
@@ -0,0 +1,56 @@
+/*****************************************************
+ *
+ * Copyright 2011 Adobe Systems Incorporated. All Rights Reserved.
+ *
+ *****************************************************
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ *
+ * The Initial Developer of the Original Code is Adobe Systems Incorporated.
+ * Portions created by Adobe Systems Incorporated are Copyright (C) 2011 Adobe Systems
+ * Incorporated. All Rights Reserved.
+ *
+ *****************************************************/
+package org.osmf.net.qos
+{
+ import flash.net.NetConnection;
+ import flash.net.NetStream;
+ import org.osmf.net.qos.QoSInfo;
+ import org.osmf.net.qos.QoSInfoHistory;
+
+ public class QoSInfoHistoryGenerator
+ {
+ public static function generateSampleQoSInfoHistory():QoSInfoHistory
+ {
+ var qosInfoHistory:QoSInfoHistory = generateEmptyQoSInfoHistory();
+
+ var qosInfo:QoSInfo = new QoSInfo(SAMPLE_MACHINE_TIME);
+
+ qosInfoHistory.addQoSInfo(qosInfo);
+
+ return qosInfoHistory;
+ }
+
+ public static function generateEmptyQoSInfoHistory():QoSInfoHistory
+ {
+ var conn:NetConnection = new NetConnection();
+ conn.connect(null);
+
+ var ns:NetStream = new NetStream(conn);
+
+ var qosInfoHistory:QoSInfoHistory = new QoSInfoHistory(ns);
+
+ return qosInfoHistory;
+ }
+
+ private static const SAMPLE_MACHINE_TIME:Number = 100;
+ }
+}
\ No newline at end of file
diff --git a/lib/osmf/framework/OSMFTest/src/org/osmf/net/qos/TestQoSInfoHistory.as b/lib/osmf/framework/OSMFTest/src/org/osmf/net/qos/TestQoSInfoHistory.as
new file mode 100644
index 0000000..39242e2
--- /dev/null
+++ b/lib/osmf/framework/OSMFTest/src/org/osmf/net/qos/TestQoSInfoHistory.as
@@ -0,0 +1,316 @@
+/*****************************************************
+ *
+ * Copyright 2011 Adobe Systems Incorporated. All Rights Reserved.
+ *
+ *****************************************************
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ *
+ * The Initial Developer of the Original Code is Adobe Systems Incorporated.
+ * Portions created by Adobe Systems Incorporated are Copyright (C) 2011 Adobe Systems
+ * Incorporated. All Rights Reserved.
+ *
+ *****************************************************/
+package org.osmf.net.qos
+{
+ import flash.net.NetConnection;
+ import flash.net.NetStream;
+ import flash.net.NetStreamInfo;
+
+ import mx.netmon.NetworkMonitor;
+
+ import org.flexunit.asserts.assertEquals;
+ import org.flexunit.asserts.assertFalse;
+ import org.flexunit.asserts.assertNotNull;
+ import org.flexunit.asserts.assertNull;
+ import org.flexunit.asserts.assertStrictlyEquals;
+ import org.flexunit.asserts.assertTrue;
+ import org.osmf.events.QoSInfoEvent;
+ import org.osmf.net.qos.FragmentDetails;
+ import org.osmf.net.qos.PlaybackDetails;
+ import org.osmf.net.qos.QoSInfo;
+ import org.osmf.net.qos.QoSInfoHistory;
+ import org.osmf.net.qos.QualityLevel;
+
+ public class TestQoSInfoHistory
+ {
+ [Before]
+ public function setUp():void
+ {
+ netConnection = new NetConnection();
+ netConnection.connect(null);
+ netStream = new NetStream(netConnection);
+ }
+
+ [After]
+ public function tearDown():void
+ {
+ }
+
+ [BeforeClass]
+ public static function setUpBeforeClass():void
+ {
+
+ }
+
+ [AfterClass]
+ public static function tearDownAfterClass():void
+ {
+ }
+
+ [Test]
+ public function testInitQoSInfoHistoryDefault():void
+ {
+ qosInfoHistory = new QoSInfoHistory(netStream);
+ assertEquals(10, qosInfoHistory.maxHistoryLength);
+ assertEquals(0, qosInfoHistory.length);
+ assertNull(qosInfoHistory.getLatestQoSInfo());
+
+ }
+
+ [Test(expects="ArgumentError")]
+ public function testInitQosInfoHistoryZeroMaxLength():void
+ {
+ qosInfoHistory = new QoSInfoHistory(netStream, 0);
+ }
+
+ [Test]
+ public function testQoSInfoHistoryWrap():void
+ {
+ qosInfoHistory = new QoSInfoHistory(netStream,3);
+
+
+ var qos:QoSInfo;
+
+ addQoSInfo(generateQoSInfo(1111));
+ assertEquals(1, qosInfoHistory.length);
+ addQoSInfo(generateQoSInfo(2222));
+ assertEquals(2, qosInfoHistory.length);
+ addQoSInfo(generateQoSInfo(3333));
+ assertEquals(3, qosInfoHistory.length);
+ addQoSInfo(generateQoSInfo(4444));
+ assertEquals(3, qosInfoHistory.length);
+
+ assertEquals(4444, qosInfoHistory.getHistory(3)[0].timestamp);
+ assertEquals(3333, qosInfoHistory.getHistory(3)[1].timestamp);
+ assertEquals(2222, qosInfoHistory.getHistory(3)[2].timestamp);
+
+ }
+
+ [Test]
+ public function testQoSInfoHistoryFlush():void
+ {
+ qosInfoHistory = new QoSInfoHistory(netStream,3);
+
+ //fill the QoSInfoHistory
+ var qos:QoSInfo;
+
+ addQoSInfo(generateQoSInfo(1111));
+ assertEquals(1, qosInfoHistory.length);
+
+ assertEquals(qosInfoHistory.getHistory()[0],qosInfoHistory.getLatestQoSInfo());
+
+ addQoSInfo(generateQoSInfo(2222));
+ assertEquals(2, qosInfoHistory.length);
+ addQoSInfo(generateQoSInfo(3333));
+ assertEquals(3, qosInfoHistory.length);
+ addQoSInfo(generateQoSInfo(4444));
+ assertEquals(3, qosInfoHistory.length);
+
+ assertEquals(4444, qosInfoHistory.getHistory(3)[0].timestamp);
+ assertEquals(3333, qosInfoHistory.getHistory(3)[1].timestamp);
+ assertEquals(2222, qosInfoHistory.getHistory(3)[2].timestamp);
+
+ //flush the QoSInfoHistory
+ qosInfoHistory.flush();
+
+ assertEquals(0,qosInfoHistory.length);
+ assertEquals(0,qosInfoHistory.getHistory(3).length);
+
+ }
+
+ [Test]
+ public function testQoSInfoHistorySlice():void
+ {
+ qosInfoHistory = new QoSInfoHistory(netStream,3);
+
+ var qos:QoSInfo;
+
+ addQoSInfo(generateQoSInfo(1111));
+ assertEquals(1, qosInfoHistory.length);
+ addQoSInfo(generateQoSInfo(2222));
+ assertEquals(2, qosInfoHistory.length);
+
+ //get slices
+ assertEquals(1, qosInfoHistory.getHistory(1).length);
+
+ assertEquals(2, qosInfoHistory.getHistory().length);
+
+ //next assert checks for slice limit
+ assertEquals(2, qosInfoHistory.getHistory(16777215+1).length);
+
+ //next assert checks for default responses
+ assertEquals(2, qosInfoHistory.getHistory(0).length);
+
+ //assert that the last pushed element is first always
+ assertEquals(2222, qosInfoHistory.getHistory(0)[0].timestamp);
+ assertEquals(2222, qosInfoHistory.getHistory()[0].timestamp);
+ assertEquals(2222, qosInfoHistory.getHistory(1)[0].timestamp);
+
+ //check for more elements than available in the history
+ assertEquals(2, qosInfoHistory.getHistory(4).length);
+ assertEquals(2222, qosInfoHistory.getHistory(4)[0].timestamp);
+ assertEquals(1111, qosInfoHistory.getHistory(4)[1].timestamp);
+ }
+
+
+ [Test]
+ public function testQoSInfoHistoryIncreaseLength():void
+ {
+ qosInfoHistory = new QoSInfoHistory(netStream,3);
+
+ var qos:QoSInfo;
+
+ addQoSInfo(generateQoSInfo(1111));
+ assertEquals(1, qosInfoHistory.length);
+ addQoSInfo(generateQoSInfo(2222));
+ assertEquals(2, qosInfoHistory.length);
+ addQoSInfo(generateQoSInfo(3333));
+ assertEquals(3, qosInfoHistory.length);
+
+ //action
+ qosInfoHistory.maxHistoryLength = 4;
+
+ assertEquals(4, qosInfoHistory.maxHistoryLength);
+ assertEquals(3, qosInfoHistory.length);
+
+
+ assertEquals(3, qosInfoHistory.getHistory().length);
+ assertEquals(3333, qosInfoHistory.getHistory()[0].timestamp);
+ assertEquals(2222, qosInfoHistory.getHistory()[1].timestamp);
+ assertEquals(1111, qosInfoHistory.getHistory()[2].timestamp);
+
+ }
+
+ [Test]
+ public function testQoSInfoHistoryDecreaseLength():void
+ {
+ qosInfoHistory = new QoSInfoHistory(netStream,3);
+
+ var qos:QoSInfo;
+
+ addQoSInfo(generateQoSInfo(1111));
+ assertEquals(1, qosInfoHistory.length);
+ addQoSInfo(generateQoSInfo(2222));
+ assertEquals(2, qosInfoHistory.length);
+ addQoSInfo(generateQoSInfo(3333));
+ assertEquals(3, qosInfoHistory.length);
+
+ //action
+ qosInfoHistory.maxHistoryLength = 2;
+
+ assertEquals(2, qosInfoHistory.maxHistoryLength);
+ assertEquals(2, qosInfoHistory.length);
+
+
+ assertEquals(2, qosInfoHistory.getHistory().length);
+ assertEquals(3333, qosInfoHistory.getHistory()[0].timestamp);
+ assertEquals(2222, qosInfoHistory.getHistory()[1].timestamp);
+ }
+
+
+
+ [Test]
+ public function testInitQoSInfoDefault():void
+ {
+ var qos:QoSInfo = new QoSInfo();
+ assertTrue(isNaN(qos.timestamp));
+ assertTrue(isNaN(qos.playheadTime));
+
+
+ assertNull(qos.availableQualityLevels);
+
+ assertEquals(-1, qos.currentIndex);
+ assertEquals(-1, qos.actualIndex);
+
+ assertNull(qos.lastDownloadedFragmentDetails);
+ assertTrue(isNaN(qos.maxFPS));
+ assertNull(qos.playbackDetailsRecord);
+ assertNull(qos.nsInfo);
+
+ assertTrue(isNaN(qos.bufferLength));
+ assertTrue(isNaN(qos.bufferTime));
+
+ assertFalse(qos.emptyBufferOccurred);
+ }
+
+ [Test]
+ public function testInitQoSInfoWithInformation():void
+ {
+ var qos:QoSInfo = generateQoSInfo(1234);
+
+ assertEquals(1234, qos.timestamp);
+ assertEquals(5678, qos.playheadTime);
+ assertEquals(0, qos.actualIndex);
+ assertNotNull(qos.availableQualityLevels);
+ assertEquals(2,qos.availableQualityLevels.length);
+ assertEquals("test1",qos.availableQualityLevels[0].streamName);
+ assertEquals(0,qos.availableQualityLevels[0].index);
+ assertEquals(611,qos.availableQualityLevels[0].bitrate);
+ assertEquals("test2",qos.availableQualityLevels[1].streamName);
+ assertEquals(1,qos.availableQualityLevels[1].index);
+ assertEquals(711,qos.availableQualityLevels[1].bitrate);
+ assertNotNull(qos.lastDownloadedFragmentDetails);
+ assertEquals(14000, qos.lastDownloadedFragmentDetails.size);
+ assertEquals(568, qos.lastDownloadedFragmentDetails.downloadDuration);
+ assertEquals(4000, qos.lastDownloadedFragmentDetails.playDuration);
+ assertEquals(2, qos.lastDownloadedFragmentDetails.index);
+ assertEquals(31.3, qos.maxFPS);
+ assertNotNull(qos.nsInfo);
+ assertTrue(qos.nsInfo is NetStreamInfo);
+ assertEquals(29.7, qos.nsInfo.currentBytesPerSecond);
+ assertNotNull(qos.playbackDetailsRecord);
+ assertTrue(qos.playbackDetailsRecord is Vector.);
+ assertEquals(2, qos.playbackDetailsRecord.length);
+ assertEquals(2.2, qos.playbackDetailsRecord[1].duration);
+ assertEquals(8.3, qos.bufferLength);
+ assertEquals(9.5, qos.bufferTime);
+ assertTrue(qos.emptyBufferOccurred);
+
+ }
+
+ private function addQoSInfo(qos:QoSInfo):void
+ {
+ netStream.dispatchEvent(new QoSInfoEvent(QoSInfoEvent.QOS_UPDATE, false, false, qos));
+ }
+
+ private function generateQoSInfo(timestamp:Number):QoSInfo
+ {
+ var q:Vector. = new Vector.();
+ q[0]= new QualityLevel(0,611,"test1");
+ q[1]= new QualityLevel(1,711,"test2");
+
+ var nsi:NetStreamInfo = new NetStreamInfo(29.7,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28);
+ var playbackDetails:Vector. = new Vector.();
+ playbackDetails.push(new PlaybackDetails(0,2.03,22));
+ playbackDetails.push(new PlaybackDetails(1,2.2,20));
+
+ return (new QoSInfo(timestamp, 5678, q, 0, 0, new FragmentDetails(14000, 4000, 568, 2), 31.3, playbackDetails, nsi, 8.3, 9.5, true));
+ }
+
+ private var qosInfoHistory:QoSInfoHistory;
+ private var netStream:NetStream;
+ private var netConnection:NetConnection;
+
+
+
+ }
+}
\ No newline at end of file
diff --git a/lib/osmf/framework/OSMFTest/src/org/osmf/net/rules/RuleMocker.as b/lib/osmf/framework/OSMFTest/src/org/osmf/net/rules/RuleMocker.as
new file mode 100644
index 0000000..f70cf8b
--- /dev/null
+++ b/lib/osmf/framework/OSMFTest/src/org/osmf/net/rules/RuleMocker.as
@@ -0,0 +1,70 @@
+/*****************************************************
+ *
+ * Copyright 2011 Adobe Systems Incorporated. All Rights Reserved.
+ *
+ *****************************************************
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ *
+ * The Initial Developer of the Original Code is Adobe Systems Incorporated.
+ * Portions created by Adobe Systems Incorporated are Copyright (C) 2011 Adobe Systems
+ * Incorporated. All Rights Reserved.
+ *
+ *****************************************************/
+/*****************************************************
+ *
+ * Copyright 2011 Adobe Systems Incorporated. All Rights Reserved.
+ *
+ *****************************************************
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ *
+ * The Initial Developer of the Original Code is Adobe Systems Incorporated.
+ * Portions created by Adobe Systems Incorporated are Copyright (C) 2011 Adobe Systems
+ * Incorporated. All Rights Reserved.
+ *
+ *****************************************************/
+package org.osmf.net.rules
+{
+ import org.osmf.net.metrics.MetricFactory;
+ import org.osmf.net.metrics.MetricRepository;
+ import org.osmf.net.qos.QoSInfoHistoryGenerator;
+
+ public class RuleMocker extends RuleBase
+ {
+ public function RuleMocker(returnValue:Recommendation)
+ {
+ super(new MetricRepository(new MetricFactory(QoSInfoHistoryGenerator.generateEmptyQoSInfoHistory())));
+ _returnValue = returnValue;
+ }
+
+ override public function getRecommendation():Recommendation
+ {
+ return _returnValue;
+ }
+
+ public function set returnValue(value:Recommendation):void
+ {
+ _returnValue = value;
+ }
+
+
+ private var _returnValue:Recommendation;
+ }
+}
\ No newline at end of file
diff --git a/lib/osmf/framework/OSMFTest/src/org/osmf/net/rules/TestAfterUpSwitchBufferBandwidthRule.as b/lib/osmf/framework/OSMFTest/src/org/osmf/net/rules/TestAfterUpSwitchBufferBandwidthRule.as
new file mode 100644
index 0000000..932cc1a
--- /dev/null
+++ b/lib/osmf/framework/OSMFTest/src/org/osmf/net/rules/TestAfterUpSwitchBufferBandwidthRule.as
@@ -0,0 +1,501 @@
+/*****************************************************
+ *
+ * Copyright 2012 Adobe Systems Incorporated. All Rights Reserved.
+ *
+ *****************************************************
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ *
+ * The Initial Developer of the Original Code is Adobe Systems Incorporated.
+ * Portions created by Adobe Systems Incorporated are Copyright (C) 2012 Adobe Systems
+ * Incorporated. All Rights Reserved.
+ *
+ *****************************************************/
+package org.osmf.net.rules
+{
+ import flash.net.NetConnection;
+ import flash.net.NetStream;
+
+ import org.flexunit.asserts.assertEquals;
+ import org.flexunit.asserts.assertTrue;
+ import org.osmf.media.DefaultMediaFactory;
+ import org.osmf.net.metrics.ActualBitrateMetric;
+ import org.osmf.net.metrics.ActualBitrateMetricMocker;
+ import org.osmf.net.metrics.AvailableQualityLevelsMetric;
+ import org.osmf.net.metrics.AvailableQualityLevelsMetricMocker;
+ import org.osmf.net.metrics.BandwidthMetric;
+ import org.osmf.net.metrics.BandwidthMetricMocker;
+ import org.osmf.net.metrics.BufferFragmentsMetric;
+ import org.osmf.net.metrics.BufferFragmentsMetricMocker;
+ import org.osmf.net.metrics.CurrentStatusMetric;
+ import org.osmf.net.metrics.CurrentStatusMetricMocker;
+ import org.osmf.net.metrics.DefaultMetricFactory;
+ import org.osmf.net.metrics.DefaultMetricFactoryMocker;
+ import org.osmf.net.metrics.FragmentCountMetric;
+ import org.osmf.net.metrics.FragmentCountMetricMocker;
+ import org.osmf.net.metrics.MetricFactory;
+ import org.osmf.net.metrics.MetricRepository;
+ import org.osmf.net.metrics.MetricType;
+ import org.osmf.net.metrics.RecentSwitchMetricMocker;
+ import org.osmf.net.qos.QoSInfo;
+ import org.osmf.net.qos.QoSInfoHistory;
+ import org.osmf.net.qos.QualityLevel;
+
+ public class TestAfterUpSwitchBufferBandwidthRule
+ {
+ [Before]
+ public function setUp():void
+ {
+
+ var conn:NetConnection = new NetConnection();
+ conn.connect(null);
+ netStream = new NetStream(conn);
+ qosInfoHistory = new QoSInfoHistory(netStream);
+ metricFactory = new DefaultMetricFactoryMocker(qosInfoHistory);
+ metricRepository = new MetricRepository(metricFactory);
+
+
+ bandwidthMetric = metricRepository.getMetric(MetricType.BANDWIDTH, generateWeights(1)) as BandwidthMetricMocker;
+
+ fragmentCountMetric = metricRepository.getMetric(MetricType.FRAGMENT_COUNT) as FragmentCountMetricMocker;
+ bufferFragmentsMetric = metricRepository.getMetric(MetricType.BUFFER_FRAGMENTS) as BufferFragmentsMetricMocker;
+
+ actualBitrateMetric = metricRepository.getMetric(MetricType.ACTUAL_BITRATE) as ActualBitrateMetricMocker;
+ bufferFragmentsMetric = metricRepository.getMetric(MetricType.BUFFER_FRAGMENTS) as BufferFragmentsMetricMocker;
+ availableQualityLevelsMetric = metricRepository.getMetric(MetricType.AVAILABLE_QUALITY_LEVELS) as AvailableQualityLevelsMetricMocker;
+ currentStatusMetric = metricRepository.getMetric(MetricType.CURRENT_STATUS) as CurrentStatusMetricMocker;
+ recentSwitchMetric = metricRepository.getMetric(MetricType.RECENT_SWITCH) as RecentSwitchMetricMocker;
+
+ }
+
+ [After]
+ public function tearDown():void
+ {
+ netStream = null;
+ qosInfoHistory = null;
+ metricFactory = null;
+ metricRepository = null;
+
+
+ bandwidthMetric = null;
+
+ fragmentCountMetric = null;
+ bufferFragmentsMetric = null;
+
+ actualBitrateMetric = null;
+ bufferFragmentsMetric = null;
+ availableQualityLevelsMetric = null;
+ currentStatusMetric = null;
+ recentSwitchMetric = null;
+ }
+
+ [BeforeClass]
+ public static function setUpBeforeClass():void
+ {
+ }
+
+ [AfterClass]
+ public static function tearDownAfterClass():void
+ {
+ }
+
+ [Test]
+ public function testAfterUpSwitchBandwidthBufferRuleInit():void
+ {
+ rule = new AfterUpSwitchBufferBandwidthRule(metricRepository, 4, 0.6);
+ assertEquals(0.6, rule.minBandwidthToBitrateRatio);
+ assertEquals(4, rule.bufferFragmentsThreshold);
+ assertEquals(1, rule.weights.length);
+ }
+
+ [Test]
+ public function testAfterUpSwitchBandwidthBufferRuleInitRatioZero():void
+ {
+ rule = new AfterUpSwitchBufferBandwidthRule(metricRepository, 4, 0);
+ assertEquals(0, rule.minBandwidthToBitrateRatio);
+ assertEquals(4, rule.bufferFragmentsThreshold);
+ assertEquals(1, rule.weights.length);
+ }
+
+ [Test(expects="ArgumentError")]
+ public function testAfterUpSwitchBandwidthBufferRuleInitRatioNaN():void
+ {
+ rule = new AfterUpSwitchBufferBandwidthRule(metricRepository, 4, NaN);
+ }
+
+ [Test(expects="ArgumentError")]
+ public function testAfterUpSwitchBandwidthBufferRuleInitRatioNegative():void
+ {
+ rule = new AfterUpSwitchBufferBandwidthRule(metricRepository, 4, -0.1);
+ }
+
+
+ [Test]
+ public function testAfterUpSwitchBandwidthBufferRule_Set_minBandwidthToBitrateRatio():void
+ {
+ rule = new AfterUpSwitchBufferBandwidthRule(metricRepository, 4, 0.6);
+ assertEquals(0.6, rule.minBandwidthToBitrateRatio);
+
+ rule.minBandwidthToBitrateRatio = 0.7;
+
+ assertEquals(0.7, rule.minBandwidthToBitrateRatio);
+ }
+
+ [Test]
+ public function testAfterUpSwitchBandwidthBufferRule_Set_minBandwidthToBitrateRatioZero():void
+ {
+ rule = new AfterUpSwitchBufferBandwidthRule(metricRepository, 4, 0.6);
+ assertEquals(0.6, rule.minBandwidthToBitrateRatio);
+
+ rule.minBandwidthToBitrateRatio = 0;
+
+ assertEquals(0, rule.minBandwidthToBitrateRatio);
+ }
+
+ [Test(expects="ArgumentError")]
+ public function testAfterUpSwitchBandwidthBufferRule_Set_minBandwidthToBitrateRatioNaN():void
+ {
+ rule = new AfterUpSwitchBufferBandwidthRule(metricRepository, 4, 0.6);
+ assertEquals(0.6, rule.minBandwidthToBitrateRatio);
+
+ rule.minBandwidthToBitrateRatio = NaN;
+ }
+
+ [Test(expects="ArgumentError")]
+ public function testAfterUpSwitchBandwidthBufferRule_Set_minBandwidthToBitrateRatioNegative():void
+ {
+ rule = new AfterUpSwitchBufferBandwidthRule(metricRepository, 4, 0.6);
+ assertEquals(0.6, rule.minBandwidthToBitrateRatio);
+
+ rule.minBandwidthToBitrateRatio = -0.1;
+ }
+
+
+ [Test]
+ public function testGetRecommendationInvalidRecentSwitchMetric():void
+ {
+ rule = new AfterUpSwitchBufferBandwidthRule(metricRepository, 4, 0.624);
+
+ recentSwitchMetric.internalValue = -2;
+ recentSwitchMetric.returnValid = false;
+
+ bandwidthMetric.internalValue = 8000.1;
+ bandwidthMetric.returnValid = true;
+
+ fragmentCountMetric.internalValue = 10;
+ fragmentCountMetric.returnValid = true;
+
+ actualBitrateMetric.internalValue = 501;
+ actualBitrateMetric.returnValid = true;
+
+ currentStatusMetric.internalValue = new Vector.();
+ currentStatusMetric.internalValue.push(2);
+ currentStatusMetric.internalValue.push(2);
+ currentStatusMetric.returnValid=true;
+
+ availableQualityLevelsMetric.internalValue = new Vector.();
+ for(var i:int=0; i< 5; i++)
+ {
+ availableQualityLevelsMetric.internalValue.push(
+ new QualityLevel( i, 100 * i + 150, "test" + (100 * i + 150) ));
+ }
+ availableQualityLevelsMetric.returnValid=true;
+
+ var recommendation:Recommendation = rule.getRecommendation();
+ assertEquals(RuleType.AFTER_UP_SWITCH_BUFFER_BANDWIDTH, recommendation.ruleType);
+ assertEquals(0, recommendation.bitrate);
+ assertEquals(0, recommendation.confidence);
+ }
+
+ [Test]
+ public function testGetRecommendationRecentSwitchMetricZero():void
+ {
+ rule = new AfterUpSwitchBufferBandwidthRule(metricRepository, 4, 0.624);
+
+ recentSwitchMetric.internalValue = 0;
+ recentSwitchMetric.returnValid = true;
+
+ bandwidthMetric.internalValue = 8000.1;
+ bandwidthMetric.returnValid = true;
+
+ fragmentCountMetric.internalValue = 10;
+ fragmentCountMetric.returnValid = true;
+
+ actualBitrateMetric.internalValue = 501;
+ actualBitrateMetric.returnValid = true;
+
+ currentStatusMetric.internalValue = new Vector.();
+ currentStatusMetric.internalValue.push(2);
+ currentStatusMetric.internalValue.push(2);
+ currentStatusMetric.returnValid=true;
+
+ availableQualityLevelsMetric.internalValue = new Vector.();
+ for(var i:int = 0; i < 5; i++)
+ {
+ availableQualityLevelsMetric.internalValue.push(
+ new QualityLevel( i, 100 * i + 150, "test" + (100 * i + 150) ));
+ }
+ availableQualityLevelsMetric.returnValid=true;
+
+ var recommendation:Recommendation = rule.getRecommendation();
+ assertEquals(RuleType.AFTER_UP_SWITCH_BUFFER_BANDWIDTH, recommendation.ruleType);
+ assertEquals(0, recommendation.bitrate);
+ assertEquals(0, recommendation.confidence);
+ }
+
+ [Test]
+ public function testGetRecommendationRecentSwitchMetricNegative():void
+ {
+ rule = new AfterUpSwitchBufferBandwidthRule(metricRepository, 4, 0.624);
+
+ recentSwitchMetric.internalValue = -2;
+ recentSwitchMetric.returnValid = true;
+
+ bandwidthMetric.internalValue = (800.1 - 0.1) * 1000 / 8 * 0.624;
+ bandwidthMetric.returnValid = true;
+
+ fragmentCountMetric.internalValue = 10;
+ fragmentCountMetric.returnValid = true;
+
+ actualBitrateMetric.internalValue = 800.1;
+ actualBitrateMetric.returnValid = true;
+
+ currentStatusMetric.internalValue = new Vector.();
+ currentStatusMetric.internalValue.push(2);
+ currentStatusMetric.internalValue.push(2);
+ currentStatusMetric.returnValid=true;
+
+ availableQualityLevelsMetric.internalValue = new Vector.();
+ for(var i:int=0; i< 5; i++)
+ {
+ availableQualityLevelsMetric.internalValue.push(
+ new QualityLevel( i, 100 * i + 150, "test" + (100 * i + 150) ));
+ }
+ availableQualityLevelsMetric.returnValid=true;
+
+ var recommendation:Recommendation = rule.getRecommendation();
+ assertEquals(RuleType.AFTER_UP_SWITCH_BUFFER_BANDWIDTH, recommendation.ruleType);
+ assertEquals(0, recommendation.bitrate);
+ assertEquals(0, recommendation.confidence);
+ }
+
+ [Test]
+ public function testGetRecommendationRecentSwitchMetricPositive_BandwidthInvalid():void
+ {
+ rule = new AfterUpSwitchBufferBandwidthRule(metricRepository, 4, 0.624);
+
+ recentSwitchMetric.internalValue = 2;
+ recentSwitchMetric.returnValid = true;
+
+ bandwidthMetric.internalValue = (800.1 - 0.1) * 1000 / 8 * 0.624;
+ bandwidthMetric.returnValid = false;
+
+ fragmentCountMetric.internalValue = 10;
+ fragmentCountMetric.returnValid = true;
+
+ actualBitrateMetric.internalValue = 800.1;
+ actualBitrateMetric.returnValid = true;
+
+ currentStatusMetric.internalValue = new Vector.();
+ currentStatusMetric.internalValue.push(2);
+ currentStatusMetric.internalValue.push(2);
+ currentStatusMetric.returnValid=true;
+
+ availableQualityLevelsMetric.internalValue = new Vector.();
+ for(var i:int = 0; i < 5; i++)
+ {
+ availableQualityLevelsMetric.internalValue.push(
+ new QualityLevel( i, 100 * i + 150, "test" + (100 * i + 150) ));
+ }
+ availableQualityLevelsMetric.returnValid=true;
+
+ var recommendation:Recommendation = rule.getRecommendation();
+ assertEquals(RuleType.AFTER_UP_SWITCH_BUFFER_BANDWIDTH, recommendation.ruleType);
+ assertEquals(0, recommendation.bitrate);
+ assertEquals(0, recommendation.confidence);
+ }
+
+ [Test]
+ public function testGetRecommendationRecentSwitchMetricPositive_ActualBitrateValid_LowBandwidth():void
+ {
+ rule = new AfterUpSwitchBufferBandwidthRule(metricRepository, 4, 0.624);
+
+ recentSwitchMetric.internalValue = 2;
+ recentSwitchMetric.returnValid = true;
+
+ bandwidthMetric.internalValue = (800.1 - 0.1) * 1000 / 8 * 0.624;
+ bandwidthMetric.returnValid = true;
+
+ fragmentCountMetric.internalValue = 10;
+ fragmentCountMetric.returnValid = true;
+
+ actualBitrateMetric.internalValue = 800.1;
+ actualBitrateMetric.returnValid = true;
+
+ currentStatusMetric.internalValue = new Vector.();
+ currentStatusMetric.internalValue.push(2);
+ currentStatusMetric.internalValue.push(2);
+ currentStatusMetric.returnValid=true;
+
+ availableQualityLevelsMetric.internalValue = new Vector.();
+ for(var i:int = 0; i < 5; i++)
+ {
+ availableQualityLevelsMetric.internalValue.push(
+ new QualityLevel( i, 100 * i + 150, "test" + (100 * i + 150) ));
+ }
+ availableQualityLevelsMetric.returnValid=true;
+
+ var recommendation:Recommendation = rule.getRecommendation();
+ assertEquals(RuleType.AFTER_UP_SWITCH_BUFFER_BANDWIDTH, recommendation.ruleType);
+ assertEquals((800.1 - 0.1) * 0.624, recommendation.bitrate);
+ assertEquals(1, recommendation.confidence);
+ }
+
+ [Test]
+ public function testGetRecommendationRecentSwitchMetricPositive_ActualBitrateValid_EqualBandwidth():void
+ {
+ rule = new AfterUpSwitchBufferBandwidthRule(metricRepository, 4, 0.624);
+
+ recentSwitchMetric.internalValue = 2;
+ recentSwitchMetric.returnValid = true;
+
+ bandwidthMetric.internalValue = (800.1 + 0.0) * 1000.0 / 8.0 * 0.624;
+ bandwidthMetric.returnValid = true;
+
+ fragmentCountMetric.internalValue = 10;
+ fragmentCountMetric.returnValid = true;
+
+ actualBitrateMetric.internalValue = 800.1;
+ actualBitrateMetric.returnValid = true;
+
+ currentStatusMetric.internalValue = new Vector.();
+ currentStatusMetric.internalValue.push(2);
+ currentStatusMetric.internalValue.push(2);
+ currentStatusMetric.returnValid=true;
+
+ availableQualityLevelsMetric.internalValue = new Vector.();
+ for( var i:int = 0; i < 5; i++)
+ {
+ availableQualityLevelsMetric.internalValue.push(
+ new QualityLevel( i, 100 * i + 150, "test" + (100 * i + 150) ));
+ }
+ availableQualityLevelsMetric.returnValid=true;
+
+ var recommendation:Recommendation = rule.getRecommendation();
+ assertEquals(RuleType.AFTER_UP_SWITCH_BUFFER_BANDWIDTH, recommendation.ruleType);
+ assertEquals((800.1 + 0.0) * 0.624, recommendation.bitrate);
+ assertEquals(0, recommendation.confidence);
+ }
+
+ [Test]
+ public function testGetRecommendationRecentSwitchMetricPositive_ActualBitrateValid_HighBandwidth():void
+ {
+ rule = new AfterUpSwitchBufferBandwidthRule(metricRepository, 4, 0.624);
+
+ recentSwitchMetric.internalValue = 2;
+ recentSwitchMetric.returnValid = true;
+
+ bandwidthMetric.internalValue = (800.1 + 0.1) * 1000.0 / 8.0 * 0.624;
+ bandwidthMetric.returnValid = true;
+
+ fragmentCountMetric.internalValue = 10;
+ fragmentCountMetric.returnValid = true;
+
+ actualBitrateMetric.internalValue = 800.1;
+ actualBitrateMetric.returnValid = true;
+
+ currentStatusMetric.internalValue = new Vector.();
+ currentStatusMetric.internalValue.push(2);
+ currentStatusMetric.internalValue.push(2);
+ currentStatusMetric.returnValid=true;
+
+ availableQualityLevelsMetric.internalValue = new Vector.();
+ for(var i:int = 0; i < 5; i++)
+ {
+ availableQualityLevelsMetric.internalValue.push(
+ new QualityLevel( i, 100 * i + 150, "test" + (100 * i + 150) ));
+ }
+ availableQualityLevelsMetric.returnValid=true;
+
+ var recommendation:Recommendation = rule.getRecommendation();
+ assertEquals(RuleType.AFTER_UP_SWITCH_BUFFER_BANDWIDTH, recommendation.ruleType);
+ assertEquals((800.1 + 0.1) * 1000.0 / 8.0 * 0.624 / 1000.0 * 8.0, recommendation.bitrate);
+ assertEquals(0, recommendation.confidence);
+ }
+
+ [Test]
+ public function testGetRecommendationRecentSwitchMetricPositive_ActualBitrateInvalid_CurrentStatusValid_AvailableQualityValid_LowBandwidth():void
+ {
+ rule = new AfterUpSwitchBufferBandwidthRule(metricRepository, 4, 0.624);
+
+ recentSwitchMetric.internalValue = 2;
+ recentSwitchMetric.returnValid = true;
+
+ bandwidthMetric.internalValue = (350.0 - 0.1) * 1000.0 / 8.0 * 0.624 ;
+ bandwidthMetric.returnValid = true;
+
+ fragmentCountMetric.internalValue = 10;
+ fragmentCountMetric.returnValid = true;
+
+ actualBitrateMetric.internalValue = 800.1;
+ actualBitrateMetric.returnValid = false;
+
+ currentStatusMetric.internalValue = new Vector.();
+ currentStatusMetric.internalValue.push(2);
+ currentStatusMetric.internalValue.push(2);
+ currentStatusMetric.returnValid=true;
+
+ availableQualityLevelsMetric.internalValue = new Vector.();
+ for(var i:int = 0; i < 5; i++)
+ {
+ availableQualityLevelsMetric.internalValue.push(
+ new QualityLevel( i, 100 * i + 150, "test" + (100 * i + 150) ));
+ }
+ availableQualityLevelsMetric.returnValid=true;
+
+ var recommendation:Recommendation = rule.getRecommendation();
+ assertEquals(RuleType.AFTER_UP_SWITCH_BUFFER_BANDWIDTH, recommendation.ruleType);
+ assertEquals((350.0 - 0.1) * 1000.0 / 8.0 * 0.624 / 1000.0 * 8.0, recommendation.bitrate);
+ assertEquals(1, recommendation.confidence);
+ }
+
+
+ private function generateWeights(... weights):Vector.
+ {
+ var v:Vector. = new Vector.();
+ for(var i:int=0; i< weights.length; i++)
+ {
+ v[i] = weights[i] ;
+ }
+ return (v);
+ }
+
+ private var rule:AfterUpSwitchBufferBandwidthRule;
+
+ //metrics for super
+ private var bandwidthMetric:BandwidthMetricMocker;
+ private var fragmentCountMetric:FragmentCountMetricMocker;
+ private var bufferFragmentsMetric:BufferFragmentsMetricMocker;
+
+ private var actualBitrateMetric:ActualBitrateMetricMocker;
+ private var currentStatusMetric:CurrentStatusMetricMocker;
+ private var availableQualityLevelsMetric:AvailableQualityLevelsMetricMocker;
+ private var recentSwitchMetric:RecentSwitchMetricMocker;
+
+
+
+ private var qosInfoHistory:QoSInfoHistory;
+ private var netStream:NetStream;
+ private var metricFactory:MetricFactory;
+ private var metricRepository:MetricRepository;
+
+ }
+}
\ No newline at end of file
diff --git a/lib/osmf/framework/OSMFTest/src/org/osmf/net/rules/TestBandwidthRule.as b/lib/osmf/framework/OSMFTest/src/org/osmf/net/rules/TestBandwidthRule.as
new file mode 100644
index 0000000..7c4613b
--- /dev/null
+++ b/lib/osmf/framework/OSMFTest/src/org/osmf/net/rules/TestBandwidthRule.as
@@ -0,0 +1,228 @@
+/*****************************************************
+ *
+ * Copyright 2011 Adobe Systems Incorporated. All Rights Reserved.
+ *
+ *****************************************************
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ *
+ * The Initial Developer of the Original Code is Adobe Systems Incorporated.
+ * Portions created by Adobe Systems Incorporated are Copyright (C) 2011 Adobe Systems
+ * Incorporated. All Rights Reserved.
+ *
+ *****************************************************/
+package org.osmf.net.rules
+{
+ import flash.net.NetConnection;
+ import flash.net.NetStream;
+
+ import org.flexunit.asserts.assertEquals;
+ import org.flexunit.asserts.assertTrue;
+ import org.osmf.events.QoSInfoEvent;
+ import org.osmf.media.DefaultMediaFactory;
+ import org.osmf.net.metrics.BandwidthMetric;
+ import org.osmf.net.metrics.BandwidthMetricMocker;
+ import org.osmf.net.metrics.DefaultMetricFactory;
+ import org.osmf.net.metrics.DefaultMetricFactoryMocker;
+ import org.osmf.net.metrics.FragmentCountMetric;
+ import org.osmf.net.metrics.FragmentCountMetricMocker;
+ import org.osmf.net.metrics.MetricFactory;
+ import org.osmf.net.metrics.MetricRepository;
+ import org.osmf.net.metrics.MetricType;
+ import org.osmf.net.qos.QoSInfo;
+ import org.osmf.net.qos.QoSInfoHistory;
+
+ public class TestBandwidthRule
+ {
+ [Before]
+ public function setUp():void
+ {
+ var conn:NetConnection = new NetConnection();
+ conn.connect(null);
+ netStream = new NetStream(conn);
+ qosInfoHistory = new QoSInfoHistory(netStream);
+ metricFactory = new DefaultMetricFactoryMocker(qosInfoHistory);
+ metricRepository = new MetricRepository(metricFactory);
+
+ bandwidthMetric = metricRepository.getMetric(MetricType.BANDWIDTH, generateWeights(0.7, 0.3) ) as BandwidthMetricMocker;
+ fragmentCountMetric = metricRepository.getMetric(MetricType.FRAGMENT_COUNT) as FragmentCountMetricMocker;
+
+ }
+
+ [After]
+ public function tearDown():void
+ {
+ fragmentCountMetric = null;
+ bandwidthMetric = null;
+ metricRepository = null;
+ metricFactory = null;
+ qosInfoHistory = null;
+ netStream = null;
+ }
+
+
+ [Test(expects="ArgumentError")]
+ public function testBandwidthRuleInitWithNoFragments():void
+ {
+
+ rule = new BandwidthRule(metricRepository, new []);
+ }
+
+ [Test(expects="ArgumentError")]
+ public function testBandwidthRuleInitWithNegativeWeight():void
+ {
+ rule = new BandwidthRule(metricRepository, new [1, -0.1, -0.01, -0.001]);
+ }
+
+
+ [Test(expects="ArgumentError")]
+ public function testBandwidthRuleInitWithNaNWeight():void
+ {
+ rule = new BandwidthRule(metricRepository, new [NaN, NaN, NaN, NaN]);
+ }
+
+ [Test(expects="ArgumentError")]
+ public function testBandwidthRuleInitWithZeroWeight():void
+ {
+ //create metric needed by specific rule
+ bandwidthMetric = metricRepository.getMetric(MetricType.BANDWIDTH, generateWeights(1,0.9, 0.9*0.9) ) as BandwidthMetricMocker;
+
+ rule = new BandwidthRule(metricRepository, new [0, 0, 0, 0]);
+
+ bandwidthMetric.internalValue=8000.1;
+ bandwidthMetric.returnValid=true;
+
+ fragmentCountMetric.internalValue=2;
+ fragmentCountMetric.returnValid=true;
+
+ var recommendation:Recommendation = rule.getRecommendation();
+ assertEquals(RuleType.BANDWIDTH, recommendation.ruleType);
+ assertEquals(8000.1 * 8 / 1000, recommendation.bitrate);
+ assertEquals(1, recommendation.confidence);
+ assertEquals(4, rule.weights.length);
+ }
+
+ [Test]
+ public function testBandwidthRuleInvalidMetric():void
+ {
+ //create metric needed by specific rule
+ bandwidthMetric = metricRepository.getMetric(MetricType.BANDWIDTH, generateWeights(1,0.9, 0.9*0.9) ) as BandwidthMetricMocker;
+
+ rule = new BandwidthRule(metricRepository, generateWeights(1, 0.9, 0.9*0.9));
+
+ //both rules return invalid
+
+ bandwidthMetric.internalValue=undefined;
+ bandwidthMetric.returnValid=false;
+
+ fragmentCountMetric.internalValue=undefined;
+ fragmentCountMetric.returnValid=false;
+
+ var recommendation:Recommendation = rule.getRecommendation();
+ assertEquals(0, recommendation.bitrate);
+ assertEquals(0, recommendation.confidence);
+
+ //check: bandwidth returns invalid
+
+ bandwidthMetric.internalValue=undefined;
+ bandwidthMetric.returnValid=false;
+
+ fragmentCountMetric.internalValue=1;
+ fragmentCountMetric.returnValid=true;
+
+ recommendation = rule.getRecommendation();
+ assertEquals(0, recommendation.bitrate);
+ assertEquals(0, recommendation.confidence);
+
+ //check: fragment count returns invalid
+
+ bandwidthMetric.internalValue=690;
+ bandwidthMetric.returnValid=true;
+
+ fragmentCountMetric.internalValue=undefined;
+ fragmentCountMetric.returnValid=false;
+
+ recommendation = rule.getRecommendation();
+ assertEquals(0, recommendation.bitrate);
+ assertEquals(0, recommendation.confidence);
+ }
+
+ [Test]
+ public function testBandwidthRuleValidMetric():void
+ {
+ // add sample qos info
+ netStream.dispatchEvent(new QoSInfoEvent(QoSInfoEvent.QOS_UPDATE, false,false , new QoSInfo()));
+
+ //create metric needed by specific rule
+ bandwidthMetric = metricRepository.getMetric(MetricType.BANDWIDTH, generateWeights(1, 0.9, 0.9*0.9) ) as BandwidthMetricMocker;
+
+ rule = new BandwidthRule(metricRepository, generateWeights(1, 0.9, 0.9*0.9));
+
+ //less fragments than needed
+
+ bandwidthMetric.internalValue=8000.1;
+ bandwidthMetric.returnValid=true;
+
+ fragmentCountMetric.internalValue=2;
+ fragmentCountMetric.returnValid=true;
+
+ var recommendation:Recommendation = rule.getRecommendation();
+ assertEquals(8000.1 * 8 / 1000, recommendation.bitrate);
+ assertEquals((1 + 0.9) / (1 + 0.9 + 0.9*0.9 ), recommendation.confidence);
+
+ //more fragments than needed
+
+ bandwidthMetric.internalValue=8000.1;
+ bandwidthMetric.returnValid=true;
+
+ fragmentCountMetric.internalValue=10;
+ fragmentCountMetric.returnValid=true;
+
+ recommendation = rule.getRecommendation();
+ assertEquals(8000.1 * 8 / 1000, recommendation.bitrate);
+ assertEquals(1, recommendation.confidence);
+
+ // fragments exactly as needed
+
+ bandwidthMetric.internalValue=8000.1;
+ bandwidthMetric.returnValid=true;
+
+ fragmentCountMetric.internalValue=3;
+ fragmentCountMetric.returnValid=true;
+
+ recommendation = rule.getRecommendation();
+ assertEquals(8000.1 * 8 / 1000, recommendation.bitrate);
+ assertEquals(1, recommendation.confidence);
+
+ }
+
+ private function generateWeights(... weights):Vector.
+ {
+ var v:Vector. = new Vector.();
+ for(var i:uint=0; i< weights.length; i++)
+ {
+ v[i] = weights[i] ;
+ }
+ return (v);
+ }
+
+ private var rule:BandwidthRule;
+
+ private var bandwidthMetric:BandwidthMetricMocker;
+ private var fragmentCountMetric:FragmentCountMetricMocker;
+
+ private var metric:FragmentCountMetric;
+ private var qosInfoHistory:QoSInfoHistory;
+ private var netStream:NetStream;
+ private var metricFactory:MetricFactory;
+ private var metricRepository:MetricRepository;
+ }
+}
\ No newline at end of file
diff --git a/lib/osmf/framework/OSMFTest/src/org/osmf/net/rules/TestBufferBandwidthRule.as b/lib/osmf/framework/OSMFTest/src/org/osmf/net/rules/TestBufferBandwidthRule.as
new file mode 100644
index 0000000..11a21b0
--- /dev/null
+++ b/lib/osmf/framework/OSMFTest/src/org/osmf/net/rules/TestBufferBandwidthRule.as
@@ -0,0 +1,523 @@
+/*****************************************************
+ *
+ * Copyright 2011 Adobe Systems Incorporated. All Rights Reserved.
+ *
+ *****************************************************
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ *
+ * The Initial Developer of the Original Code is Adobe Systems Incorporated.
+ * Portions created by Adobe Systems Incorporated are Copyright (C) 2011 Adobe Systems
+ * Incorporated. All Rights Reserved.
+ *
+ *****************************************************/
+package org.osmf.net.rules
+{
+ import flash.net.NetConnection;
+ import flash.net.NetStream;
+
+ import org.flexunit.asserts.assertEquals;
+ import org.flexunit.asserts.assertTrue;
+ import org.osmf.media.DefaultMediaFactory;
+ import org.osmf.net.metrics.ActualBitrateMetric;
+ import org.osmf.net.metrics.ActualBitrateMetricMocker;
+ import org.osmf.net.metrics.AvailableQualityLevelsMetric;
+ import org.osmf.net.metrics.AvailableQualityLevelsMetricMocker;
+ import org.osmf.net.metrics.BandwidthMetric;
+ import org.osmf.net.metrics.BandwidthMetricMocker;
+ import org.osmf.net.metrics.BufferFragmentsMetric;
+ import org.osmf.net.metrics.BufferFragmentsMetricMocker;
+ import org.osmf.net.metrics.CurrentStatusMetric;
+ import org.osmf.net.metrics.CurrentStatusMetricMocker;
+ import org.osmf.net.metrics.DefaultMetricFactory;
+ import org.osmf.net.metrics.DefaultMetricFactoryMocker;
+ import org.osmf.net.metrics.FragmentCountMetric;
+ import org.osmf.net.metrics.FragmentCountMetricMocker;
+ import org.osmf.net.metrics.MetricFactory;
+ import org.osmf.net.metrics.MetricRepository;
+ import org.osmf.net.metrics.MetricType;
+ import org.osmf.net.qos.QoSInfo;
+ import org.osmf.net.qos.QoSInfoHistory;
+ import org.osmf.net.qos.QualityLevel;
+
+ public class TestBufferBandwidthRule
+ {
+ [Before]
+ public function setUp():void
+ {
+ var conn:NetConnection = new NetConnection();
+ conn.connect(null);
+ netStream = new NetStream(conn);
+ qosInfoHistory = new QoSInfoHistory(netStream);
+ metricFactory = new DefaultMetricFactoryMocker(qosInfoHistory);
+ metricRepository = new MetricRepository(metricFactory);
+
+
+ bandwidthMetric = metricRepository.getMetric(MetricType.BANDWIDTH, generateWeights(1,0.9, 0.9*0.9) ) as BandwidthMetricMocker;
+
+ fragmentCountMetric = metricRepository.getMetric(MetricType.FRAGMENT_COUNT) as FragmentCountMetricMocker;
+ bufferFragmentsMetric = metricRepository.getMetric(MetricType.BUFFER_FRAGMENTS) as BufferFragmentsMetricMocker;
+
+ actualBitrateMetric = metricRepository.getMetric(MetricType.ACTUAL_BITRATE) as ActualBitrateMetricMocker;
+ bufferFragmentsMetric = metricRepository.getMetric(MetricType.BUFFER_FRAGMENTS) as BufferFragmentsMetricMocker;
+ availableQualityLevelsMetric = metricRepository.getMetric(MetricType.AVAILABLE_QUALITY_LEVELS) as AvailableQualityLevelsMetricMocker;
+ currentStatusMetric = metricRepository.getMetric(MetricType.CURRENT_STATUS) as CurrentStatusMetricMocker;
+ }
+
+ [After]
+ public function tearDown():void
+ {
+ fragmentCountMetric = null;
+ bandwidthMetric = null;
+ metricRepository = null;
+ metricFactory = null;
+ qosInfoHistory = null;
+ netStream = null;
+ }
+
+
+ [Test(expects="ArgumentError")]
+ public function testBandwidthBufferRuleInitWithNegativeBufferThreshold():void
+ {
+ rule = new BufferBandwidthRule(metricRepository, new [7, 3], -1 );
+ }
+
+ [Test(expects="ArgumentError")]
+ public function testBandwidthBufferRuleInitWithBufferThresholdNaN():void
+ {
+ rule = new BufferBandwidthRule(metricRepository, new [7, 3], NaN );
+ }
+
+ [Test]
+ public function testBandwidthBufferRuleInitWithBufferThresholdZero():void
+ {
+ rule = new BufferBandwidthRule(metricRepository, new [7, 3], 0 );
+ assertEquals(0, rule.bufferFragmentsThreshold);
+ }
+
+ [Test]
+ public function testBandwidthBufferRuleSetGetBufferFragmentsThreshold():void
+ {
+ rule = new BufferBandwidthRule(metricRepository, new [7, 3], 3 );
+ rule.bufferFragmentsThreshold = 4;
+ assertEquals(4, rule.bufferFragmentsThreshold);
+ }
+
+ [Test(expects="ArgumentError")]
+ public function testBandwidthBufferRuleSetGetBufferFragmentsThresholdNaN():void
+ {
+ rule = new BufferBandwidthRule(metricRepository, new [7, 3], 3 );
+ rule.bufferFragmentsThreshold=NaN;
+ }
+
+ [Test(expects="ArgumentError")]
+ public function testBandwidthBufferRuleSetGetBufferFragmentsThresholdNegative():void
+ {
+ rule = new BufferBandwidthRule(metricRepository, new [7, 3], 3 );
+ rule.bufferFragmentsThreshold=-1;
+ }
+
+ [Test]
+ public function testBandwidthBufferRuleSetGetBufferFragmentsThresholdZero():void
+ {
+ rule = new BufferBandwidthRule(metricRepository, new [7, 3], 3 );
+ rule.bufferFragmentsThreshold=0;
+ assertEquals(0, rule.bufferFragmentsThreshold);
+
+ }
+
+ [Test]
+ public function testBandwidthBufferRuleInvalidMetrics():void
+ {
+ var i:int;
+ //create metric needed by specific rule
+ bandwidthMetric = metricRepository.getMetric(MetricType.BANDWIDTH, generateWeights(1,0.9, 0.9*0.9) ) as BandwidthMetricMocker;
+
+ rule = new BufferBandwidthRule(metricRepository, generateWeights(1,0.9, 0.9*0.9), 3 );
+
+ //actualbitrate metric return invalid, currentstatus returns invalid
+ // to simulate a correct super call, make other metrics correct
+
+ bandwidthMetric.internalValue=8000.1;
+ bandwidthMetric.returnValid=true;
+
+ fragmentCountMetric.internalValue=10;
+ fragmentCountMetric.returnValid=true;
+
+ actualBitrateMetric.internalValue=501;
+ actualBitrateMetric.returnValid=false;
+
+ currentStatusMetric.internalValue=new Vector.();
+ currentStatusMetric.internalValue.push(2);
+ currentStatusMetric.internalValue.push(2);
+ currentStatusMetric.returnValid=false;
+
+ availableQualityLevelsMetric.internalValue = new Vector.();
+ for(i=0; i< 5; i++)
+ {
+ availableQualityLevelsMetric.internalValue.push(
+ new QualityLevel( i, 100 * i + 150, "test" + (100 * i + 150) ));
+ }
+ availableQualityLevelsMetric.returnValid=true;
+
+
+ var recommendation:Recommendation = rule.getRecommendation();
+ assertEquals(0, recommendation.bitrate);
+ assertEquals(0, recommendation.confidence);
+
+
+ //actualbitrate metric return invalid, available quality return invalid
+
+
+ bandwidthMetric.internalValue=8000.1;
+ bandwidthMetric.returnValid=true;
+
+ fragmentCountMetric.internalValue=10;
+ fragmentCountMetric.returnValid=true;
+
+ actualBitrateMetric.internalValue=501;
+ actualBitrateMetric.returnValid=false;
+
+ currentStatusMetric.internalValue=new Vector.();
+ currentStatusMetric.internalValue.push(2);
+ currentStatusMetric.internalValue.push(2);
+ currentStatusMetric.returnValid=true;
+
+ availableQualityLevelsMetric.internalValue = new Vector.();
+ for(i=0; i< 5; i++)
+ {
+ availableQualityLevelsMetric.internalValue.push(
+ new QualityLevel( i, 100 * i + 150, "test" + (100 * i + 150) ));
+ }
+ availableQualityLevelsMetric.returnValid=false;
+
+ recommendation = rule.getRecommendation();
+ assertEquals(0, recommendation.bitrate);
+ assertEquals(0, recommendation.confidence);
+ }
+
+ public function testBandwidthBufferRuleInvalidSuperMetrics():void
+ {
+ //create metric needed by specific rule
+ bandwidthMetric = metricRepository.getMetric(MetricType.BANDWIDTH, generateWeights(1,0.9, 0.9*0.9) ) as BandwidthMetricMocker;
+
+ rule = new BufferBandwidthRule(metricRepository, generateWeights(1,0.9, 0.9*0.9), 3 );
+
+ //actualbitrate metric return valid, currentstatus and available quality return valid
+ // to simulate a correct super call
+
+ bandwidthMetric.internalValue=8000.1;
+ bandwidthMetric.returnValid=false;
+
+ fragmentCountMetric.internalValue=10;
+ fragmentCountMetric.returnValid=false;
+
+ actualBitrateMetric.internalValue=501;
+ actualBitrateMetric.returnValid=true;
+
+ currentStatusMetric.internalValue=new Vector.();
+ currentStatusMetric.internalValue.push(2);
+ currentStatusMetric.internalValue.push(2);
+ currentStatusMetric.returnValid=true;
+
+ availableQualityLevelsMetric.internalValue = new Vector.();
+ for(var i:uint=0; i< 5; i++)
+ {
+ availableQualityLevelsMetric.internalValue.push(
+ new QualityLevel( i, 100 * i + 150, "test" + (100 * i + 150) ));
+ }
+ availableQualityLevelsMetric.returnValid=true;
+
+ var recommendation:Recommendation = rule.getRecommendation();
+ assertEquals(0, recommendation.bitrate);
+ assertEquals(0, recommendation.confidence);
+
+ }
+
+ [Test]
+ public function testBandwidthBufferRuleValidMetricActualLessThanRecommended():void
+ {
+ //create metric needed by specific rule
+ bandwidthMetric = metricRepository.getMetric(MetricType.BANDWIDTH, generateWeights(1,0.9, 0.9*0.9) ) as BandwidthMetricMocker;
+
+ rule = new BufferBandwidthRule(metricRepository, generateWeights(1,0.9, 0.9*0.9), 3 );
+
+ //actualbitrate metric return valid, currentstatus and available quality return valid
+ // to simulate a correct super call
+
+ bandwidthMetric.internalValue=800000.1;
+ bandwidthMetric.returnValid=true;
+
+ fragmentCountMetric.internalValue=10;
+ fragmentCountMetric.returnValid=true;
+
+ actualBitrateMetric.internalValue=501;
+ actualBitrateMetric.returnValid=true;
+
+ currentStatusMetric.internalValue=new Vector.();
+ currentStatusMetric.internalValue.push(2);
+ currentStatusMetric.internalValue.push(2);
+ currentStatusMetric.returnValid=true;
+
+ availableQualityLevelsMetric.internalValue = new Vector.();
+ for(var i:uint=0; i< 5; i++)
+ {
+ availableQualityLevelsMetric.internalValue.push(
+ new QualityLevel( i, 100 * i + 150, "test" + (100 * i + 150) ));
+ }
+ availableQualityLevelsMetric.returnValid=true;
+
+ var recommendation:Recommendation = rule.getRecommendation();
+ assertEquals(800000.1 * 8 / 1000, recommendation.bitrate);
+ assertEquals(1, recommendation.confidence);
+
+ }
+
+ [Test]
+ public function testBandwidthBufferRuleValidActualBitrateMetricRecommendedLessThanActualAndBufferHasFragments():void
+ {
+ //create metric needed by specific rule
+ bandwidthMetric = metricRepository.getMetric(MetricType.BANDWIDTH, generateWeights(1,0.9, 0.9*0.9) ) as BandwidthMetricMocker;
+
+ rule = new BufferBandwidthRule(metricRepository, generateWeights(1,0.9, 0.9*0.9), 3 );
+
+ //actualbitrate metric return valid, currentstatus and available quality return valid
+ // to simulate a correct super call
+
+ bandwidthMetric.internalValue=8000.1;
+ bandwidthMetric.returnValid=true;
+
+ fragmentCountMetric.internalValue=2;
+ fragmentCountMetric.returnValid=true;
+
+ actualBitrateMetric.internalValue=501;
+ actualBitrateMetric.returnValid=true;
+
+ currentStatusMetric.internalValue=new Vector.();
+ currentStatusMetric.internalValue.push(2);
+ currentStatusMetric.internalValue.push(2);
+ currentStatusMetric.returnValid=true;
+
+ availableQualityLevelsMetric.internalValue = new Vector.();
+ for(var i:uint=0; i< 5; i++)
+ {
+ availableQualityLevelsMetric.internalValue.push(
+ new QualityLevel( i, 100 * i + 150, "test" + (100 * i + 150) ));
+ }
+ availableQualityLevelsMetric.returnValid=true;
+
+ bufferFragmentsMetric.internalValue=3;
+ bufferFragmentsMetric.returnValid=true;
+
+ var recommendation:Recommendation = rule.getRecommendation();
+ assertEquals(8000.1 * 8 / 1000 , recommendation.bitrate);
+ assertEquals((1 + 0.9) / (1 + 0.9 + 0.9*0.9 ), recommendation.confidence);
+ }
+
+
+ [Test]
+ public function testBandwidthBufferRuleValidActualBitrateMetricRecommendedLessThanActualAndBufferHasMoreFragments():void
+ {
+ //create metric needed by specific rule
+ bandwidthMetric = metricRepository.getMetric(MetricType.BANDWIDTH, generateWeights(1,0.9, 0.9*0.9) ) as BandwidthMetricMocker;
+
+ rule = new BufferBandwidthRule(metricRepository, generateWeights(1,0.9, 0.9*0.9), 3 );
+
+ //actualbitrate metric return valid, currentstatus and available quality return valid
+ // to simulate a correct super call
+
+ bandwidthMetric.internalValue=8000.1;
+ bandwidthMetric.returnValid=true;
+
+ fragmentCountMetric.internalValue=2;
+ fragmentCountMetric.returnValid=true;
+
+ actualBitrateMetric.internalValue=501;
+ actualBitrateMetric.returnValid=true;
+
+ currentStatusMetric.internalValue=new Vector.();
+ currentStatusMetric.internalValue.push(2);
+ currentStatusMetric.internalValue.push(2);
+ currentStatusMetric.returnValid=true;
+
+ availableQualityLevelsMetric.internalValue = new Vector.();
+ for(var i:uint=0; i< 5; i++)
+ {
+ availableQualityLevelsMetric.internalValue.push(
+ new QualityLevel( i, 100 * i + 150, "test" + (100 * i + 150) ));
+ }
+ availableQualityLevelsMetric.returnValid=true;
+
+ bufferFragmentsMetric.internalValue=4;
+ bufferFragmentsMetric.returnValid=true;
+
+ var recommendation:Recommendation = rule.getRecommendation();
+ assertEquals(501, recommendation.bitrate);
+ assertEquals((1 + 0.9) / (1 + 0.9 + 0.9*0.9 ), recommendation.confidence);
+ }
+
+ [Test]
+ public function testBandwidthBufferRuleInvalidActualBitrateMetricRecommendedLessThanActualAndBufferHasFragments():void
+ {
+ //create metric needed by specific rule
+ bandwidthMetric = metricRepository.getMetric(MetricType.BANDWIDTH, generateWeights(1,0.9, 0.9*0.9) ) as BandwidthMetricMocker;
+
+ rule = new BufferBandwidthRule(metricRepository, generateWeights(1,0.9, 0.9*0.9), 3 );
+
+ //actualbitrate metric return valid, currentstatus and available quality return valid
+ // to simulate a correct super call
+
+ bandwidthMetric.internalValue=8000.1;
+ bandwidthMetric.returnValid=true;
+
+ fragmentCountMetric.internalValue=2;
+ fragmentCountMetric.returnValid=true;
+
+ actualBitrateMetric.internalValue=501;
+ actualBitrateMetric.returnValid=false;
+
+ currentStatusMetric.internalValue=new Vector.();
+ currentStatusMetric.internalValue.push(2);
+ currentStatusMetric.internalValue.push(3);
+ currentStatusMetric.returnValid=true;
+
+ availableQualityLevelsMetric.internalValue = new Vector.();
+ for(var i:uint=0; i< 5; i++)
+ {
+ availableQualityLevelsMetric.internalValue.push(
+ new QualityLevel( i, 100 * i + 150, "test" + (100 * i + 150) ));
+ }
+ availableQualityLevelsMetric.returnValid=true;
+
+ bufferFragmentsMetric.internalValue=3;
+ bufferFragmentsMetric.returnValid=true;
+
+ var recommendation:Recommendation = rule.getRecommendation();
+ assertEquals(8000.1/1000*8, recommendation.bitrate);
+ assertEquals((1 + 0.9) / (1 + 0.9 + 0.9*0.9 ), recommendation.confidence);
+ }
+
+ [Test]
+ public function testBandwidthBufferRuleValidMetricRecommendedLessThanActualAndBufferDoesNotHaveFragments():void
+ {
+
+ //create metric needed by specific rule
+ bandwidthMetric = metricRepository.getMetric(MetricType.BANDWIDTH, generateWeights(1,0.9, 0.9*0.9) ) as BandwidthMetricMocker;
+
+ rule = new BufferBandwidthRule(metricRepository, generateWeights(1,0.9, 0.9*0.9), 3 );
+
+ //actualbitrate metric return valid, currentstatus and available quality return valid
+ // to simulate a correct super call
+
+ bandwidthMetric.internalValue=8000.1;
+ bandwidthMetric.returnValid=true;
+
+ fragmentCountMetric.internalValue=2;
+ fragmentCountMetric.returnValid=true;
+
+ actualBitrateMetric.internalValue=501;
+ actualBitrateMetric.returnValid=true;
+
+ currentStatusMetric.internalValue=new Vector.();
+ currentStatusMetric.internalValue.push(2);
+ currentStatusMetric.internalValue.push(2);
+ currentStatusMetric.returnValid=true;
+
+ availableQualityLevelsMetric.internalValue = new Vector.();
+ for(var i:uint=0; i< 5; i++)
+ {
+ availableQualityLevelsMetric.internalValue.push(
+ new QualityLevel( i, 100 * i + 150, "test" + (100 * i + 150) ));
+ }
+ availableQualityLevelsMetric.returnValid=true;
+
+ bufferFragmentsMetric.internalValue=1;
+ bufferFragmentsMetric.returnValid=true;
+
+ var recommendation:Recommendation = rule.getRecommendation();
+ assertEquals(8000.1/1000*8, recommendation.bitrate);
+ assertEquals((1 + 0.9) / (1 + 0.9 + 0.9*0.9 ), recommendation.confidence);
+
+ }
+
+
+ [Test]
+ public function testBandwidthBufferRuleValidMetricRecommendedLessThanActualAndBufferFragmentMetricIsInvalid():void
+ {
+
+ //create metric needed by specific rule
+ bandwidthMetric = metricRepository.getMetric(MetricType.BANDWIDTH, generateWeights(1,0.9, 0.9*0.9) ) as BandwidthMetricMocker;
+
+ rule = new BufferBandwidthRule(metricRepository, generateWeights(1,0.9, 0.9*0.9), 3 );
+
+ //actualbitrate metric return valid, currentstatus and available quality return valid
+ // to simulate a correct super call
+
+ bandwidthMetric.internalValue=8000.1;
+ bandwidthMetric.returnValid=true;
+
+ fragmentCountMetric.internalValue=2;
+ fragmentCountMetric.returnValid=true;
+
+ actualBitrateMetric.internalValue=501;
+ actualBitrateMetric.returnValid=true;
+
+ currentStatusMetric.internalValue=new Vector.();
+ currentStatusMetric.internalValue.push(2);
+ currentStatusMetric.internalValue.push(2);
+ currentStatusMetric.returnValid=true;
+
+ availableQualityLevelsMetric.internalValue = new Vector.();
+ for(var i:uint=0; i< 5; i++)
+ {
+ availableQualityLevelsMetric.internalValue.push(
+ new QualityLevel( i, 100 * i + 150, "test" + (100 * i + 150) ));
+ }
+ availableQualityLevelsMetric.returnValid=true;
+
+ bufferFragmentsMetric.internalValue=1;
+ bufferFragmentsMetric.returnValid=false;
+
+ var recommendation:Recommendation = rule.getRecommendation();
+ assertEquals(8000.1 * 8 / 1000, recommendation.bitrate);
+ assertEquals((1 + 0.9) / (1 + 0.9 + 0.9*0.9 ), recommendation.confidence);
+
+ }
+
+ private function generateWeights(... weights):Vector.
+ {
+ var v:Vector. = new Vector.();
+ for(var i:uint=0; i< weights.length; i++)
+ {
+ v[i] = weights[i] ;
+ }
+ return (v);
+ }
+
+ private var rule:BufferBandwidthRule;
+
+ //metrics for super
+ private var bandwidthMetric:BandwidthMetricMocker;
+ private var fragmentCountMetric:FragmentCountMetricMocker;
+ private var bufferFragmentsMetric:BufferFragmentsMetricMocker;
+
+ private var actualBitrateMetric:ActualBitrateMetricMocker;
+ private var currentStatusMetric:CurrentStatusMetricMocker;
+ private var availableQualityLevelsMetric:AvailableQualityLevelsMetricMocker;
+
+
+
+ private var qosInfoHistory:QoSInfoHistory;
+ private var netStream:NetStream;
+ private var metricFactory:MetricFactory;
+ private var metricRepository:MetricRepository;
+ }
+}
\ No newline at end of file
diff --git a/lib/osmf/framework/OSMFTest/src/org/osmf/net/rules/TestDroppedFPSRule.as b/lib/osmf/framework/OSMFTest/src/org/osmf/net/rules/TestDroppedFPSRule.as
new file mode 100644
index 0000000..634f180
--- /dev/null
+++ b/lib/osmf/framework/OSMFTest/src/org/osmf/net/rules/TestDroppedFPSRule.as
@@ -0,0 +1,536 @@
+/*****************************************************
+ *
+ * Copyright 2011 Adobe Systems Incorporated. All Rights Reserved.
+ *
+ *****************************************************
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ *
+ * The Initial Developer of the Original Code is Adobe Systems Incorporated.
+ * Portions created by Adobe Systems Incorporated are Copyright (C) 2011 Adobe Systems
+ * Incorporated. All Rights Reserved.
+ *
+ *****************************************************/
+package org.osmf.net.rules
+{
+ import flash.net.NetConnection;
+ import flash.net.NetStream;
+
+ import org.flexunit.asserts.assertEquals;
+ import org.osmf.net.metrics.ActualBitrateMetricMocker;
+ import org.osmf.net.metrics.AvailableQualityLevelsMetric;
+ import org.osmf.net.metrics.AvailableQualityLevelsMetricMocker;
+ import org.osmf.net.metrics.CurrentStatusMetric;
+ import org.osmf.net.metrics.CurrentStatusMetricMocker;
+ import org.osmf.net.metrics.DefaultMetricFactoryMocker;
+ import org.osmf.net.metrics.DroppedFPSMetricMocker;
+ import org.osmf.net.metrics.FPSMetricMocker;
+ import org.osmf.net.metrics.MetricFactory;
+ import org.osmf.net.metrics.MetricRepository;
+ import org.osmf.net.metrics.MetricType;
+ import org.osmf.net.qos.QoSInfoHistory;
+ import org.osmf.net.qos.QualityLevel;
+
+ public class TestDroppedFPSRule
+ {
+ [Before]
+ public function setUp():void
+ {
+ var conn:NetConnection = new NetConnection();
+ conn.connect(null);
+ netStream = new NetStream(conn);
+ var qosInfoHistory:QoSInfoHistory = new QoSInfoHistory(netStream);
+ var metricFactory:DefaultMetricFactoryMocker = new DefaultMetricFactoryMocker(qosInfoHistory)
+ metricRepository = new MetricRepository(metricFactory);
+
+ droppedFPSMetric = metricRepository.getMetric(MetricType.DROPPED_FPS, DESIRED_SAMPLE_LENGTH) as DroppedFPSMetricMocker;
+ fpsMetric = metricRepository.getMetric(MetricType.FPS) as FPSMetricMocker;
+ availableQualityLevelsMetric = metricRepository.getMetric(MetricType.AVAILABLE_QUALITY_LEVELS) as AvailableQualityLevelsMetricMocker;
+
+ actualBitrateMetric = metricRepository.getMetric(MetricType.ACTUAL_BITRATE) as ActualBitrateMetricMocker;
+ currentStatusMetric = metricRepository.getMetric(MetricType.CURRENT_STATUS) as CurrentStatusMetricMocker;
+ }
+
+ [After]
+ public function tearDown():void
+ {
+ currentStatusMetric = null;
+ droppedFPSMetric = null;
+ metricRepository = null;
+ netStream = null;
+ }
+
+ [Test(expects="ArgumentError")]
+ public function testInitInvalidMaximumDroppedFPSRatioNaN():void
+ {
+ var dfpsRule:DroppedFPSRule = new DroppedFPSRule(metricRepository, 5, Number.NaN);
+ }
+
+ [Test(expects="ArgumentError")]
+ public function testInitInvalidMaximumDroppedFPSRatioLessThanZero():void
+ {
+ var dfpsRule:DroppedFPSRule = new DroppedFPSRule(metricRepository, 5, -0.1);
+ }
+
+ [Test(expects="ArgumentError")]
+ public function testInitInvalidMaximumDroppedFPSRatioOverOne():void
+ {
+ var dfpsRule:DroppedFPSRule = new DroppedFPSRule(metricRepository, 5, 1.1);
+ }
+
+ [Test(expects="ArgumentError")]
+ public function testInitInvalidDesiredSampleLengthNaN():void
+ {
+ var dfpsRule:DroppedFPSRule = new DroppedFPSRule(metricRepository, NaN, 0.1);
+ }
+
+ [Test(expects="ArgumentError")]
+ public function testInitInvalidDesiredSampleLengthLessThanZero():void
+ {
+ var dfpsRule:DroppedFPSRule = new DroppedFPSRule(metricRepository, -1, 0.1);
+ }
+
+ [Test(expects="ArgumentError")]
+ public function testInitInvalidInvalidDesiredSampleLengthZero():void
+ {
+ var dfpsRule:DroppedFPSRule = new DroppedFPSRule(metricRepository, 0, 1.1);
+ }
+
+ [Test]
+ public function testDroppedFPSRuleInit():void
+ {
+ var dfpsRule:DroppedFPSRule = new DroppedFPSRule(metricRepository, DESIRED_SAMPLE_LENGTH, 0.2);
+ assertEquals(DESIRED_SAMPLE_LENGTH, dfpsRule.desiredSampleLength);
+ assertEquals(0.2, dfpsRule.maximumDroppedFPSRatio);
+ }
+
+
+ [Test]
+ public function testDroppedFPSRuleGetRecommendationValidMetric():void
+ {
+ var dfpsRule:DroppedFPSRule = new DroppedFPSRule(metricRepository, DESIRED_SAMPLE_LENGTH, 0.2);
+
+ actualBitrateMetric.internalValue = 433.3;
+ actualBitrateMetric.returnValid = true;
+
+ currentStatusMetric.internalValue = new Vector.();
+ currentStatusMetric.internalValue.push(2);
+ currentStatusMetric.internalValue.push(2);
+ currentStatusMetric.returnValid = true;
+
+ availableQualityLevelsMetric.internalValue = new Vector.();
+ for(var i:uint=0; i< 5; i++)
+ {
+ availableQualityLevelsMetric.internalValue.push(
+ new QualityLevel( i, 100 * i + 150, "test" + (100 * i + 150) ));
+ }
+ availableQualityLevelsMetric.returnValid=true;
+
+ fpsMetric.internalValue = 29.7;
+ fpsMetric.returnValid = true;
+
+ droppedFPSMetric.internalValue = 29.7 * 0.2 - 0.01;
+ droppedFPSMetric.returnValid = true;
+
+ var recommendation:Recommendation = dfpsRule.getRecommendation();
+ assertEquals(RuleType.DROPPED_FPS, recommendation.ruleType);
+ assertEquals((29.7 * 0.2 - 0.01) / (29.7*0.2), recommendation.confidence);
+ assertEquals(433.3 * (1 - (29.7 * 0.2 - 0.01) / 29.7) , recommendation.bitrate); //actualBitrate * (1 - droppedFPS / fps);
+ }
+
+ [Test]
+ public function testDroppedFPSRuleGetRecommendationValidMetricLowFPS():void
+ {
+ var dfpsRule:DroppedFPSRule = new DroppedFPSRule(metricRepository, DESIRED_SAMPLE_LENGTH, 0.2);
+
+ actualBitrateMetric.internalValue = 433.3;
+ actualBitrateMetric.returnValid = true;
+
+ currentStatusMetric.internalValue = new Vector.();
+ currentStatusMetric.internalValue.push(2);
+ currentStatusMetric.internalValue.push(2);
+ currentStatusMetric.returnValid = true;
+
+
+ availableQualityLevelsMetric.internalValue = new Vector.();
+ for(var i:uint=0; i< 5; i++)
+ {
+ availableQualityLevelsMetric.internalValue.push(
+ new QualityLevel( i, 100 * i + 150, "test" + (100 * i + 150) ));
+ }
+ availableQualityLevelsMetric.returnValid=true;
+
+ fpsMetric.internalValue = 29.7;
+ fpsMetric.returnValid = true;
+
+ droppedFPSMetric.internalValue = 29.7 * 0.2 + 0.01;
+ droppedFPSMetric.returnValid = true;
+
+ var recommendation:Recommendation = dfpsRule.getRecommendation();
+ assertEquals(RuleType.DROPPED_FPS, recommendation.ruleType);
+ assertEquals(1, recommendation.confidence);
+ assertEquals(433.3 * (1 - (29.7 * 0.2 + 0.01) / 29.7) , recommendation.bitrate); //actualBitrate * (1 - droppedFPS / fps);
+ }
+
+ [Test]
+ public function testDroppedFPSRuleGetRecommendationValidMetricRatioZero():void
+ {
+ var dfpsRule:DroppedFPSRule = new DroppedFPSRule(metricRepository, DESIRED_SAMPLE_LENGTH, 0);
+
+ actualBitrateMetric.internalValue = 433.3;
+ actualBitrateMetric.returnValid = true;
+
+ currentStatusMetric.internalValue = new Vector.();
+ currentStatusMetric.internalValue.push(2);
+ currentStatusMetric.internalValue.push(2);
+ currentStatusMetric.returnValid = true;
+
+
+ availableQualityLevelsMetric.internalValue = new Vector.();
+ for(var i:uint=0; i< 5; i++)
+ {
+ availableQualityLevelsMetric.internalValue.push(
+ new QualityLevel( i, 100 * i + 150, "test" + (100 * i + 150) ));
+ }
+ availableQualityLevelsMetric.returnValid=true;
+
+ fpsMetric.internalValue = 29.7;
+ fpsMetric.returnValid = true;
+
+ droppedFPSMetric.internalValue = 0;
+ droppedFPSMetric.returnValid = true;
+
+ var recommendation:Recommendation = dfpsRule.getRecommendation();
+ assertEquals(RuleType.DROPPED_FPS, recommendation.ruleType);
+ assertEquals(0, recommendation.confidence);
+ assertEquals(0, recommendation.bitrate); //actualBitrate * (1 - droppedFPS / fps);
+ }
+
+ [Test]
+ public function testDroppedFPSRuleGetRecommendationValidMetricBorderFPS():void
+ {
+ var dfpsRule:DroppedFPSRule = new DroppedFPSRule(metricRepository, DESIRED_SAMPLE_LENGTH, 0.2);
+
+ actualBitrateMetric.internalValue = 433.3;
+ actualBitrateMetric.returnValid = true;
+
+ currentStatusMetric.internalValue = new Vector.();
+ currentStatusMetric.internalValue.push(2);
+ currentStatusMetric.internalValue.push(2);
+ currentStatusMetric.returnValid = true;
+
+ availableQualityLevelsMetric.internalValue = new Vector.();
+ for(var i:uint=0; i< 5; i++)
+ {
+ availableQualityLevelsMetric.internalValue.push(
+ new QualityLevel( i, 100 * i + 150, "test" + (100 * i + 150) ));
+ }
+ availableQualityLevelsMetric.returnValid=true;
+
+ fpsMetric.internalValue = 29.7;
+ fpsMetric.returnValid = true;
+
+ droppedFPSMetric.internalValue = 29.7 * 0.2 ;
+ droppedFPSMetric.returnValid = true;
+
+ var recommendation:Recommendation = dfpsRule.getRecommendation();
+ assertEquals(RuleType.DROPPED_FPS, recommendation.ruleType);
+ assertEquals(1, recommendation.confidence);
+ assertEquals(433.3 * (1 - (29.7 * 0.2) / 29.7) , recommendation.bitrate); //actualBitrate * (1 - droppedFPS / fps);
+
+ }
+
+
+ [Test]
+ public function testDroppedFPSRuleGetRecommendationCurrentIndexDifferentFromActualIndex():void
+ {
+ var dfpsRule:DroppedFPSRule = new DroppedFPSRule(metricRepository, DESIRED_SAMPLE_LENGTH, 0.2);
+
+ actualBitrateMetric.internalValue = 433.3;
+ actualBitrateMetric.returnValid = true;
+
+ currentStatusMetric.internalValue = new Vector.();
+ currentStatusMetric.internalValue.push(2);
+ currentStatusMetric.internalValue.push(1);
+ currentStatusMetric.returnValid = true;
+
+ availableQualityLevelsMetric.internalValue = new Vector.();
+ for(var i:uint=0; i< 5; i++)
+ {
+ availableQualityLevelsMetric.internalValue.push(
+ new QualityLevel( i, 100 * i + 150, "test" + (100 * i + 150) ));
+ }
+ availableQualityLevelsMetric.returnValid=true;
+
+ fpsMetric.internalValue = 29.7;
+ fpsMetric.returnValid = true;
+
+ droppedFPSMetric.internalValue = 29.7 * 0.2 ;
+ droppedFPSMetric.returnValid = true;
+
+ var recommendation:Recommendation = dfpsRule.getRecommendation();
+ assertEquals(RuleType.DROPPED_FPS, recommendation.ruleType);
+ assertEquals(0, recommendation.confidence);
+ assertEquals(0, recommendation.bitrate); //actualBitrate * (1 - droppedFPS / fps);
+
+ }
+
+ [Test]
+ public function testDroppedFPSRuleGetRecommendationInvalidActualBitrateMetric():void
+ {
+ //valid current status and available quality metrics
+ var dfpsRule:DroppedFPSRule = new DroppedFPSRule(metricRepository, DESIRED_SAMPLE_LENGTH, 0.2);
+
+ actualBitrateMetric.internalValue = 433.3;
+ actualBitrateMetric.returnValid = false;
+
+ currentStatusMetric.internalValue = new Vector.();
+ currentStatusMetric.internalValue.push(2);
+ currentStatusMetric.internalValue.push(2);
+ currentStatusMetric.returnValid = true;
+
+ availableQualityLevelsMetric.internalValue = new Vector.();
+ for(var i:uint=0; i< 5; i++)
+ {
+ availableQualityLevelsMetric.internalValue.push(
+ new QualityLevel( i, 100 * i + 150, "test" + (100 * i + 150) ));
+ }
+ availableQualityLevelsMetric.returnValid=true;
+
+ fpsMetric.internalValue = 29.7;
+ fpsMetric.returnValid = true;
+
+ droppedFPSMetric.internalValue = 29.7 * 0.2 + 0.01;
+ droppedFPSMetric.returnValid = true;
+
+ var recommendation:Recommendation = dfpsRule.getRecommendation();
+ assertEquals(RuleType.DROPPED_FPS, recommendation.ruleType);
+ assertEquals(1, recommendation.confidence);
+ assertEquals(350 * (1 - (29.7 * 0.2 + 0.01) / 29.7) , recommendation.bitrate);
+ }
+
+ [Test]
+ public function testDroppedFPSRuleGetRecommendationInvalidCurrentStatusMetric():void
+ {
+ var dfpsRule:DroppedFPSRule = new DroppedFPSRule(metricRepository, DESIRED_SAMPLE_LENGTH, 0.2);
+
+ actualBitrateMetric.internalValue = 433.3;
+ actualBitrateMetric.returnValid = true;
+
+ currentStatusMetric.internalValue = new Vector.();
+ currentStatusMetric.internalValue.push(2);
+ currentStatusMetric.internalValue.push(2);
+ currentStatusMetric.returnValid = false;
+
+ availableQualityLevelsMetric.internalValue = new Vector.();
+ for(var i:uint=0; i< 5; i++)
+ {
+ availableQualityLevelsMetric.internalValue.push(
+ new QualityLevel( i, 100 * i + 150, "test" + (100 * i + 150) ));
+ }
+ availableQualityLevelsMetric.returnValid=true;
+
+ fpsMetric.internalValue = 29.7;
+ fpsMetric.returnValid = true;
+
+ droppedFPSMetric.internalValue = 29.7 * 0.2 + 0.01;
+ droppedFPSMetric.returnValid = true;
+
+ var recommendation:Recommendation = dfpsRule.getRecommendation();
+ assertEquals(RuleType.DROPPED_FPS, recommendation.ruleType);
+ assertEquals(0, recommendation.confidence);
+ assertEquals(0, recommendation.bitrate);
+ }
+
+ [Test]
+ public function testDroppedFPSRuleGetRecommendationInvalidFPSMetric():void
+ {
+ var dfpsRule:DroppedFPSRule = new DroppedFPSRule(metricRepository, DESIRED_SAMPLE_LENGTH, 0.2);
+
+ actualBitrateMetric.internalValue = 433.3;
+ actualBitrateMetric.returnValid = true;
+
+ currentStatusMetric.internalValue = new Vector.();
+ currentStatusMetric.internalValue.push(2);
+ currentStatusMetric.internalValue.push(2);
+ currentStatusMetric.returnValid = true;
+
+ availableQualityLevelsMetric.internalValue = new Vector.();
+ for(var i:uint=0; i< 5; i++)
+ {
+ availableQualityLevelsMetric.internalValue.push(
+ new QualityLevel( i, 100 * i + 150, "test" + (100 * i + 150) ));
+ }
+ availableQualityLevelsMetric.returnValid=true;
+
+ fpsMetric.internalValue = 29.7;
+ fpsMetric.returnValid = false;
+
+ droppedFPSMetric.internalValue = 29.7 * 0.2 + 0.01;
+ droppedFPSMetric.returnValid = true;
+
+ var recommendation:Recommendation = dfpsRule.getRecommendation();
+ assertEquals(RuleType.DROPPED_FPS, recommendation.ruleType);
+ assertEquals(0, recommendation.confidence);
+ assertEquals(0 , recommendation.bitrate);
+ }
+
+ [Test]
+ public function testDroppedFPSRuleGetRecommendationInvalidDroppedFPSMetric():void
+ {
+ var dfpsRule:DroppedFPSRule = new DroppedFPSRule(metricRepository, DESIRED_SAMPLE_LENGTH, 0.2);
+
+ actualBitrateMetric.internalValue = 433.3;
+ actualBitrateMetric.returnValid = true;
+
+ currentStatusMetric.internalValue = new Vector.();
+ currentStatusMetric.internalValue.push(2);
+ currentStatusMetric.internalValue.push(2);
+ currentStatusMetric.returnValid = true;
+
+ availableQualityLevelsMetric.internalValue = new Vector.();
+ for(var i:uint=0; i< 5; i++)
+ {
+ availableQualityLevelsMetric.internalValue.push(
+ new QualityLevel( i, 100 * i + 150, "test" + (100 * i + 150) ));
+ }
+ availableQualityLevelsMetric.returnValid=true;
+
+ fpsMetric.internalValue = 29.7;
+ fpsMetric.returnValid = true;
+
+ droppedFPSMetric.internalValue = 29.7 * 0.2 + 0.01;
+ droppedFPSMetric.returnValid = false;
+
+ var recommendation:Recommendation = dfpsRule.getRecommendation();
+ assertEquals(RuleType.DROPPED_FPS, recommendation.ruleType);
+ assertEquals(0, recommendation.confidence);
+ assertEquals(0 , recommendation.bitrate);
+ }
+
+
+ //todo
+ [Test]
+ public function testDroppedFPSRuleGetRecommendationInvalidCurrentStatusMetricAndActualBitrate():void
+ {
+ var dfpsRule:DroppedFPSRule = new DroppedFPSRule(metricRepository, DESIRED_SAMPLE_LENGTH, 0.2);
+
+ actualBitrateMetric.internalValue = 433.3;
+ actualBitrateMetric.returnValid = false;
+
+ currentStatusMetric.internalValue = new Vector.();
+ currentStatusMetric.internalValue.push(2);
+ currentStatusMetric.internalValue.push(2);
+ currentStatusMetric.returnValid = false;
+
+ availableQualityLevelsMetric.internalValue = new Vector.();
+ for(var i:uint=0; i< 5; i++)
+ {
+ availableQualityLevelsMetric.internalValue.push(
+ new QualityLevel( i, 100 * i + 150, "test" + (100 * i + 150) ));
+ }
+ availableQualityLevelsMetric.returnValid=true;
+
+ fpsMetric.internalValue = 29.7;
+ fpsMetric.returnValid = true;
+
+ droppedFPSMetric.internalValue = 29.7 * 0.2 + 0.01;
+ droppedFPSMetric.returnValid = true;
+
+ var recommendation:Recommendation = dfpsRule.getRecommendation();
+ assertEquals(RuleType.DROPPED_FPS, recommendation.ruleType);
+ assertEquals(0, recommendation.confidence);
+ assertEquals(0, recommendation.bitrate);
+ }
+
+ //todo
+ [Test]
+ public function testDroppedFPSRuleGetRecommendationInvalidActualBitrateAndAvailableQualityLevelMetric():void
+ {
+ var dfpsRule:DroppedFPSRule = new DroppedFPSRule(metricRepository, DESIRED_SAMPLE_LENGTH, 0.2);
+
+ actualBitrateMetric.internalValue = 433.3;
+ actualBitrateMetric.returnValid = true;
+
+ currentStatusMetric.internalValue = new Vector.();
+ currentStatusMetric.internalValue.push(2);
+ currentStatusMetric.internalValue.push(2);
+ currentStatusMetric.returnValid = false;
+
+ availableQualityLevelsMetric.internalValue = new Vector.();
+ for(var i:uint=0; i< 5; i++)
+ {
+ availableQualityLevelsMetric.internalValue.push(
+ new QualityLevel( i, 100 * i + 150, "test" + (100 * i + 150) ));
+ }
+ availableQualityLevelsMetric.returnValid=false;
+
+ fpsMetric.internalValue = 29.7;
+ fpsMetric.returnValid = true;
+
+ droppedFPSMetric.internalValue = 29.7 * 0.2 + 0.01;
+ droppedFPSMetric.returnValid = true;
+
+ var recommendation:Recommendation = dfpsRule.getRecommendation();
+ assertEquals(RuleType.DROPPED_FPS, recommendation.ruleType);
+ assertEquals(0, recommendation.confidence);
+ assertEquals(0, recommendation.bitrate);
+ }
+
+
+
+ [Test]
+ public function testDroppedFPSRuleGetRecommendationMoreDroppedFramesThanMax():void
+ {
+ var dfpsRule:DroppedFPSRule = new DroppedFPSRule(metricRepository, DESIRED_SAMPLE_LENGTH, 0.2);
+
+ actualBitrateMetric.internalValue = 433.3;
+ actualBitrateMetric.returnValid = true;
+
+ currentStatusMetric.internalValue = new Vector.();
+ currentStatusMetric.internalValue.push(2);
+ currentStatusMetric.internalValue.push(2);
+ currentStatusMetric.returnValid = true;
+
+ availableQualityLevelsMetric.internalValue = new Vector.();
+ for(var i:uint=0; i< 5; i++)
+ {
+ availableQualityLevelsMetric.internalValue.push(
+ new QualityLevel( i, 100 * i + 150, "test" + (100 * i + 150) ));
+ }
+ availableQualityLevelsMetric.returnValid=true;
+
+ fpsMetric.internalValue = 29.7;
+ fpsMetric.returnValid = true;
+
+ droppedFPSMetric.internalValue = 29.71;
+ droppedFPSMetric.returnValid = true;
+
+ var recommendation:Recommendation = dfpsRule.getRecommendation();
+ assertEquals(RuleType.DROPPED_FPS, recommendation.ruleType);
+ assertEquals(1, recommendation.confidence);
+ assertEquals(0 , recommendation.bitrate); //actualBitrate * (1 - droppedFPS / fps);
+ }
+
+ private var droppedFPSMetric:DroppedFPSMetricMocker;
+ private var fpsMetric:FPSMetricMocker;
+ private var currentStatusMetric:CurrentStatusMetricMocker;
+ private var actualBitrateMetric:ActualBitrateMetricMocker;
+ private var availableQualityLevelsMetric:AvailableQualityLevelsMetricMocker;
+
+
+ private var netStream:NetStream;
+ private var metricRepository:MetricRepository;
+
+ private static const DESIRED_SAMPLE_LENGTH:Number = 5;
+ private static const DESIRED_RATIO:Number = 0.1;
+ }
+}
\ No newline at end of file
diff --git a/lib/osmf/framework/OSMFTest/src/org/osmf/net/rules/TestEmptyBufferRule.as b/lib/osmf/framework/OSMFTest/src/org/osmf/net/rules/TestEmptyBufferRule.as
new file mode 100644
index 0000000..622ec92
--- /dev/null
+++ b/lib/osmf/framework/OSMFTest/src/org/osmf/net/rules/TestEmptyBufferRule.as
@@ -0,0 +1,362 @@
+/*****************************************************
+ *
+ * Copyright 2011 Adobe Systems Incorporated. All Rights Reserved.
+ *
+ *****************************************************
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ *
+ * The Initial Developer of the Original Code is Adobe Systems Incorporated.
+ * Portions created by Adobe Systems Incorporated are Copyright (C) 2011 Adobe Systems
+ * Incorporated. All Rights Reserved.
+ *
+ *****************************************************/
+package org.osmf.net.rules
+{
+ import flash.net.NetConnection;
+ import flash.net.NetStream;
+
+ import org.flexunit.Assert;
+ import org.flexunit.asserts.assertEquals;
+ import org.flexunit.asserts.assertTrue;
+ import org.osmf.media.DefaultMediaFactory;
+ import org.osmf.net.metrics.ActualBitrateMetric;
+ import org.osmf.net.metrics.ActualBitrateMetricMocker;
+ import org.osmf.net.metrics.AvailableQualityLevelsMetric;
+ import org.osmf.net.metrics.AvailableQualityLevelsMetricMocker;
+ import org.osmf.net.metrics.BandwidthMetric;
+ import org.osmf.net.metrics.BandwidthMetricMocker;
+ import org.osmf.net.metrics.BufferFragmentsMetric;
+ import org.osmf.net.metrics.BufferFragmentsMetricMocker;
+ import org.osmf.net.metrics.CurrentStatusMetric;
+ import org.osmf.net.metrics.CurrentStatusMetricMocker;
+ import org.osmf.net.metrics.DefaultMetricFactory;
+ import org.osmf.net.metrics.DefaultMetricFactoryMocker;
+ import org.osmf.net.metrics.EmptyBufferMetricMocker;
+ import org.osmf.net.metrics.FragmentCountMetric;
+ import org.osmf.net.metrics.FragmentCountMetricMocker;
+ import org.osmf.net.metrics.MetricFactory;
+ import org.osmf.net.metrics.MetricRepository;
+ import org.osmf.net.metrics.MetricType;
+ import org.osmf.net.qos.QoSInfo;
+ import org.osmf.net.qos.QoSInfoHistory;
+ import org.osmf.net.qos.QualityLevel;
+
+ public class TestEmptyBufferRule
+ {
+ [Before]
+ public function setUp():void
+ {
+
+ var conn:NetConnection = new NetConnection();
+ conn.connect(null);
+ netStream = new NetStream(conn);
+ qosInfoHistory = new QoSInfoHistory(netStream);
+ metricFactory = new DefaultMetricFactoryMocker(qosInfoHistory);
+ metricRepository = new MetricRepository(metricFactory);
+
+
+ bandwidthMetric = metricRepository.getMetric(MetricType.BANDWIDTH, generateWeights(1,0.9, 0.9*0.9) ) as BandwidthMetricMocker;
+
+ fragmentCountMetric = metricRepository.getMetric(MetricType.FRAGMENT_COUNT) as FragmentCountMetricMocker;
+ bufferFragmentsMetric = metricRepository.getMetric(MetricType.BUFFER_FRAGMENTS) as BufferFragmentsMetricMocker;
+
+ actualBitrateMetric = metricRepository.getMetric(MetricType.ACTUAL_BITRATE) as ActualBitrateMetricMocker;
+ bufferFragmentsMetric = metricRepository.getMetric(MetricType.BUFFER_FRAGMENTS) as BufferFragmentsMetricMocker;
+ availableQualityLevelsMetric = metricRepository.getMetric(MetricType.AVAILABLE_QUALITY_LEVELS) as AvailableQualityLevelsMetricMocker;
+ currentStatusMetric = metricRepository.getMetric(MetricType.CURRENT_STATUS) as CurrentStatusMetricMocker;
+ emptyBufferInterruptionMetric = metricRepository.getMetric(MetricType.EMPTY_BUFFER) as EmptyBufferMetricMocker;
+
+ }
+
+ [After]
+ public function tearDown():void
+ {
+
+ bandwidthMetric = null;
+
+ fragmentCountMetric = null;
+ bufferFragmentsMetric = null;
+
+ actualBitrateMetric = null;
+ bufferFragmentsMetric = null;
+ availableQualityLevelsMetric = null;
+ currentStatusMetric = null;
+ emptyBufferInterruptionMetric = null;
+
+ metricRepository = null;
+ metricFactory = null;
+ qosInfoHistory = null;
+ netStream = null;
+
+ }
+
+ [BeforeClass]
+ public static function setUpBeforeClass():void
+ {
+ }
+
+ [AfterClass]
+ public static function tearDownAfterClass():void
+ {
+ }
+
+ [Test]
+ public function testEmptyBufferInterruptionRuleInit():void
+ {
+ rule = new EmptyBufferRule(metricRepository, 0.4);
+ assertEquals(0.4, rule.scaleDownFactor);
+ }
+
+ [Test(expects="ArgumentError")]
+ public function testEmptyBufferInterruptionRuleInitNaN():void
+ {
+ rule = new EmptyBufferRule(metricRepository, NaN);
+ }
+
+ [Test(expects="ArgumentError")]
+ public function testEmptyBufferInterruptionRuleInitGreaterThanOne():void
+ {
+ rule = new EmptyBufferRule(metricRepository, 1.01);
+ }
+
+ [Test(expects="ArgumentError")]
+ public function testEmptyBufferInterruptionRuleInitNegative():void
+ {
+ rule = new EmptyBufferRule(metricRepository, -0.1);
+ }
+
+ [Test]
+ public function testEmptyBufferInterruptionRuleInitOne():void
+ {
+ rule = new EmptyBufferRule(metricRepository, 1);
+ assertEquals(1, rule.scaleDownFactor);
+
+ }
+
+ [Test]
+ public function testEmptyBufferInterruptionRuleInitZero():void
+ {
+ rule = new EmptyBufferRule(metricRepository, 0);
+ assertEquals(0, rule.scaleDownFactor);
+
+ }
+
+ [Test]
+ public function testEmptyBufferInterruptionRuleSet_scaleDownFactor():void
+ {
+ rule = new EmptyBufferRule(metricRepository, 0.5);
+ rule.scaleDownFactor = 0.8;
+ assertEquals(0.8, rule.scaleDownFactor);
+ rule.scaleDownFactor = 0;
+ assertEquals(0, rule.scaleDownFactor);
+ rule.scaleDownFactor = 1;
+ assertEquals(1, rule.scaleDownFactor);
+ }
+
+ [Test(expects = "ArgumentError")]
+ public function testEmptyBufferInterruptionRuleSet_scaleDownFactorNaN():void
+ {
+ rule = new EmptyBufferRule(metricRepository, 0.5);
+ rule.scaleDownFactor = NaN;
+ }
+
+ [Test(expects = "ArgumentError")]
+ public function testEmptyBufferInterruptionRuleSet_scaleDownFactorNegative():void
+ {
+ rule = new EmptyBufferRule(metricRepository, 0.5);
+ rule.scaleDownFactor = -0.1;
+ }
+
+ [Test(expects = "ArgumentError")]
+ public function testEmptyBufferInterruptionRuleSet_scaleDownFactorGreaterThanOne():void
+ {
+ rule = new EmptyBufferRule(metricRepository, 0.5);
+ rule.scaleDownFactor = 1.1;
+ }
+
+
+
+ [Test]
+ public function testEmptyBufferInterruptionRule_GetRecommendation_InvalidEmptyBufferInterruptMetric():void
+ {
+ rule = new EmptyBufferRule(metricRepository, 0.5);
+
+ emptyBufferInterruptionMetric = metricRepository.getMetric(MetricType.EMPTY_BUFFER) as EmptyBufferMetricMocker;
+ emptyBufferInterruptionMetric.returnValid=false;
+ emptyBufferInterruptionMetric.internalValue=true;
+
+ var recommendation:Recommendation = rule.getRecommendation();
+ assertEquals(RuleType.EMPTY_BUFFER, recommendation.ruleType);
+ assertEquals(0, recommendation.bitrate);
+ assertEquals(0, recommendation.confidence);
+ }
+
+ [Test]
+ public function testEmptyBufferInterruptionRule_GetRecommendation_FalseEmptyBufferInterruptMetric():void
+ {
+ rule = new EmptyBufferRule(metricRepository, 0.5);
+
+ emptyBufferInterruptionMetric = metricRepository.getMetric(MetricType.EMPTY_BUFFER) as EmptyBufferMetricMocker;
+ emptyBufferInterruptionMetric.returnValid=true;
+ emptyBufferInterruptionMetric.internalValue=false;
+
+ var recommendation:Recommendation = rule.getRecommendation();
+ assertEquals(RuleType.EMPTY_BUFFER, recommendation.ruleType);
+ assertEquals(0, recommendation.bitrate);
+ assertEquals(0, recommendation.confidence);
+ }
+
+ [Test]
+ public function testEmptyBufferInterruptionRule_GetRecommendation_TrueEmptyBufferInterruptMetric_ValidActualBitrate():void
+ {
+ rule = new EmptyBufferRule(metricRepository, 0.5);
+
+ emptyBufferInterruptionMetric = metricRepository.getMetric(MetricType.EMPTY_BUFFER) as EmptyBufferMetricMocker;
+ emptyBufferInterruptionMetric.returnValid=true;
+ emptyBufferInterruptionMetric.internalValue=true;
+
+ actualBitrateMetric.returnValid=true;
+ actualBitrateMetric.internalValue=333;
+
+ var recommendation:Recommendation = rule.getRecommendation();
+ assertEquals(RuleType.EMPTY_BUFFER, recommendation.ruleType);
+ assertEquals(333*0.5, recommendation.bitrate);
+ assertEquals(1, recommendation.confidence);
+ }
+
+ [Test]
+ public function testEmptyBufferInterruptionRule_GetRecommendation_EmptyBuffer_InvalidActualBitrate_ValidCurrent_ValidAvailableQuality():void
+ {
+ rule = new EmptyBufferRule(metricRepository, 0.5);
+
+ emptyBufferInterruptionMetric = metricRepository.getMetric(MetricType.EMPTY_BUFFER) as EmptyBufferMetricMocker;
+ emptyBufferInterruptionMetric.returnValid=true;
+ emptyBufferInterruptionMetric.internalValue=true;
+
+ actualBitrateMetric.returnValid=false;
+ actualBitrateMetric.internalValue=333;
+
+ currentStatusMetric.internalValue=new Vector.();
+ currentStatusMetric.internalValue.push(3);
+ currentStatusMetric.internalValue.push(3);
+ currentStatusMetric.returnValid=true;
+
+ availableQualityLevelsMetric.internalValue = new Vector.();
+ var i:int;
+ for(i=0; i< 5; i++)
+ {
+ availableQualityLevelsMetric.internalValue.push(
+ new QualityLevel( i, 100 * i + 150, "test" + (100 * i + 150) ));
+ }
+ availableQualityLevelsMetric.returnValid=true;
+
+ var recommendation:Recommendation = rule.getRecommendation();
+ assertEquals(RuleType.EMPTY_BUFFER, recommendation.ruleType);
+ assertEquals(450*0.5, recommendation.bitrate);
+ assertEquals(1, recommendation.confidence);
+ }
+
+ [Test]
+ public function testEmptyBufferInterruptionRule_GetRecommendation_EmptyBuffer_InvalidActualBitrate_InvalidCurrent_ValidAvailableQuality():void
+ {
+ rule = new EmptyBufferRule(metricRepository, 0.5);
+
+ emptyBufferInterruptionMetric = metricRepository.getMetric(MetricType.EMPTY_BUFFER) as EmptyBufferMetricMocker;
+ emptyBufferInterruptionMetric.returnValid=true;
+ emptyBufferInterruptionMetric.internalValue=true;
+
+ actualBitrateMetric.returnValid=false;
+ actualBitrateMetric.internalValue=333;
+
+ currentStatusMetric.internalValue=new Vector.();
+ currentStatusMetric.internalValue.push(3);
+ currentStatusMetric.internalValue.push(3);
+ currentStatusMetric.returnValid=false;
+
+ availableQualityLevelsMetric.internalValue = new Vector.();
+ var i:int;
+ for(i=0; i< 5; i++)
+ {
+ availableQualityLevelsMetric.internalValue.push(
+ new QualityLevel( i, 100 * i + 150, "test" + (100 * i + 150) ));
+ }
+ availableQualityLevelsMetric.returnValid=true;
+
+ var recommendation:Recommendation = rule.getRecommendation();
+ assertEquals(RuleType.EMPTY_BUFFER, recommendation.ruleType);
+ assertEquals(0, recommendation.bitrate);
+ assertEquals(1, recommendation.confidence);
+ }
+
+ [Test]
+ public function testEmptyBufferInterruptionRule_GetRecommendation_EmptyBuffer_InvalidActualBitrate_ValidCurrent_InvalidAvailableQuality():void
+ {
+ rule = new EmptyBufferRule(metricRepository, 0.5);
+
+ emptyBufferInterruptionMetric = metricRepository.getMetric(MetricType.EMPTY_BUFFER) as EmptyBufferMetricMocker;
+ emptyBufferInterruptionMetric.returnValid=true;
+ emptyBufferInterruptionMetric.internalValue=true;
+
+ actualBitrateMetric.returnValid=false;
+ actualBitrateMetric.internalValue=333;
+
+ currentStatusMetric.internalValue=new Vector.();
+ currentStatusMetric.internalValue.push(3);
+ currentStatusMetric.internalValue.push(3);
+ currentStatusMetric.returnValid=true;
+
+ availableQualityLevelsMetric.internalValue = new Vector.();
+ var i:int;
+ for(i=0; i< 5; i++)
+ {
+ availableQualityLevelsMetric.internalValue.push(
+ new QualityLevel( i, 100 * i + 150, "test" + (100 * i + 150) ));
+ }
+ availableQualityLevelsMetric.returnValid=false;
+
+ var recommendation:Recommendation = rule.getRecommendation();
+ assertEquals(RuleType.EMPTY_BUFFER, recommendation.ruleType);
+ assertEquals(0, recommendation.bitrate);
+ assertEquals(1, recommendation.confidence);
+ }
+
+ private function generateWeights(... weights):Vector.
+ {
+ var v:Vector. = new Vector.();
+ for(var i:uint=0; i< weights.length; i++)
+ {
+ v[i] = weights[i] ;
+ }
+ return (v);
+ }
+
+ private var rule:EmptyBufferRule;
+
+ //metrics for super
+ private var bandwidthMetric:BandwidthMetricMocker;
+ private var fragmentCountMetric:FragmentCountMetricMocker;
+ private var bufferFragmentsMetric:BufferFragmentsMetricMocker;
+
+ private var actualBitrateMetric:ActualBitrateMetricMocker;
+ private var currentStatusMetric:CurrentStatusMetricMocker;
+ private var availableQualityLevelsMetric:AvailableQualityLevelsMetricMocker;
+ private var emptyBufferInterruptionMetric:EmptyBufferMetricMocker;
+
+
+
+
+ private var qosInfoHistory:QoSInfoHistory;
+ private var netStream:NetStream;
+ private var metricFactory:MetricFactory;
+ private var metricRepository:MetricRepository;
+ }
+}
\ No newline at end of file
diff --git a/lib/osmf/framework/OSMFTest/src/org/osmf/net/rules/TestRecommendation.as b/lib/osmf/framework/OSMFTest/src/org/osmf/net/rules/TestRecommendation.as
new file mode 100644
index 0000000..2dabaf6
--- /dev/null
+++ b/lib/osmf/framework/OSMFTest/src/org/osmf/net/rules/TestRecommendation.as
@@ -0,0 +1,128 @@
+/*****************************************************
+ *
+ * Copyright 2011 Adobe Systems Incorporated. All Rights Reserved.
+ *
+ *****************************************************
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ *
+ * The Initial Developer of the Original Code is Adobe Systems Incorporated.
+ * Portions created by Adobe Systems Incorporated are Copyright (C) 2011 Adobe Systems
+ * Incorporated. All Rights Reserved.
+ *
+ *****************************************************/
+package org.osmf.net.rules
+{
+ import flexunit.framework.Assert;
+
+ import org.flexunit.asserts.assertEquals;
+
+ public class TestRecommendation
+ {
+ [Before]
+ public function setUp():void
+ {
+ }
+
+ [After]
+ public function tearDown():void
+ {
+ }
+
+ [BeforeClass]
+ public static function setUpBeforeClass():void
+ {
+ }
+
+ [AfterClass]
+ public static function tearDownAfterClass():void
+ {
+ }
+
+ [Test]
+ public function testGet():void
+ {
+ recommendation = new Recommendation(RULE_TYPE, 467.8, 0.88);
+ assertEquals(RULE_TYPE, recommendation.ruleType);
+ assertEquals(467.8, recommendation.bitrate);
+ assertEquals(0.88, recommendation.confidence);
+ }
+
+
+ [Test]
+ public function testRecommendationInitValidConfidence():void
+ {
+ recommendation = new Recommendation(RULE_TYPE, 467.8, 0);
+ assertEquals(RULE_TYPE, recommendation.ruleType);
+ assertEquals(467.8, recommendation.bitrate);
+ assertEquals(0, recommendation.confidence);
+
+ recommendation = new Recommendation(RULE_TYPE, 467.8, 1);
+ assertEquals(467.8, recommendation.bitrate);
+ assertEquals(1, recommendation.confidence);
+
+ recommendation = new Recommendation(RULE_TYPE, 467.8, 0.2);
+ assertEquals(467.8, recommendation.bitrate);
+ assertEquals(0.2, recommendation.confidence);
+ }
+
+ [Test]
+ public function testRecommendationInitValidBitrate():void
+ {
+ recommendation = new Recommendation(RULE_TYPE, 0, 0.5);
+ assertEquals(0, recommendation.bitrate);
+ assertEquals(0.5, recommendation.confidence);
+
+ recommendation = new Recommendation(RULE_TYPE, 467, 0.5);
+ assertEquals(467, recommendation.bitrate);
+ assertEquals(0.5, recommendation.confidence);
+
+ recommendation = new Recommendation(RULE_TYPE, 467.8, 0.5);
+ assertEquals(467.8, recommendation.bitrate);
+ assertEquals(0.5, recommendation.confidence);
+ }
+
+ [Test(expects="ArgumentError")]
+ public function testRecommendationInvalidConfidenceNaN():void
+ {
+ recommendation = new Recommendation(RULE_TYPE, 400, Number.NaN);
+ }
+ [Test(expects="ArgumentError")]
+ public function testRecommendationInvalidConfidenceNegative():void
+ {
+ recommendation = new Recommendation(RULE_TYPE, 400, -0.1);
+ }
+ [Test(expects="ArgumentError")]
+ public function testRecommendationInvalidConfidenceOverOne():void
+ {
+ recommendation = new Recommendation(RULE_TYPE, 400, 1.1);
+ }
+
+ [Test(expects="ArgumentError")]
+ public function testRecommendationInvalidBitrateNegative():void
+ {
+ recommendation = new Recommendation(RULE_TYPE, -0.1, 0.5);
+ }
+ [Test(expects="ArgumentError")]
+ public function testRecommendationInvalidBitrateNaN():void
+ {
+ recommendation = new Recommendation(RULE_TYPE, Number.NaN, 0.5);
+ }
+ [Test(expects="ArgumentError")]
+ public function testRecommendationInvalidRuleType():void
+ {
+ recommendation = new Recommendation(null, 400, 0.5);
+ }
+
+ private var recommendation:Recommendation;
+ private static const RULE_TYPE:String = "sample_rule_type";
+ }
+}
\ No newline at end of file
diff --git a/lib/osmf/framework/OSMFTest/src/org/osmf/net/rules/TestRuleUtils.as b/lib/osmf/framework/OSMFTest/src/org/osmf/net/rules/TestRuleUtils.as
new file mode 100644
index 0000000..53c6109
--- /dev/null
+++ b/lib/osmf/framework/OSMFTest/src/org/osmf/net/rules/TestRuleUtils.as
@@ -0,0 +1,212 @@
+/*****************************************************
+ *
+ * Copyright 2011 Adobe Systems Incorporated. All Rights Reserved.
+ *
+ *****************************************************
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ *
+ * The Initial Developer of the Original Code is Adobe Systems Incorporated.
+ * Portions created by Adobe Systems Incorporated are Copyright (C) 2011 Adobe Systems
+ * Incorporated. All Rights Reserved.
+ *
+ *****************************************************/
+package org.osmf.net.rules
+{
+ import flash.net.NetConnection;
+ import flash.net.NetStream;
+
+ import org.flexunit.asserts.assertEquals;
+ import org.flexunit.asserts.assertTrue;
+ import org.osmf.media.DefaultMediaFactory;
+ import org.osmf.net.metrics.ActualBitrateMetric;
+ import org.osmf.net.metrics.ActualBitrateMetricMocker;
+ import org.osmf.net.metrics.AvailableQualityLevelsMetric;
+ import org.osmf.net.metrics.AvailableQualityLevelsMetricMocker;
+ import org.osmf.net.metrics.BandwidthMetric;
+ import org.osmf.net.metrics.BandwidthMetricMocker;
+ import org.osmf.net.metrics.BufferFragmentsMetric;
+ import org.osmf.net.metrics.BufferFragmentsMetricMocker;
+ import org.osmf.net.metrics.CurrentStatusMetric;
+ import org.osmf.net.metrics.CurrentStatusMetricMocker;
+ import org.osmf.net.metrics.DefaultMetricFactory;
+ import org.osmf.net.metrics.DefaultMetricFactoryMocker;
+ import org.osmf.net.metrics.FragmentCountMetric;
+ import org.osmf.net.metrics.FragmentCountMetricMocker;
+ import org.osmf.net.metrics.MetricFactory;
+ import org.osmf.net.metrics.MetricRepository;
+ import org.osmf.net.metrics.MetricType;
+ import org.osmf.net.qos.QoSInfo;
+ import org.osmf.net.qos.QoSInfoHistory;
+ import org.osmf.net.qos.QualityLevel;
+
+ public class TestRuleUtils
+ {
+ [Before]
+ public function setUp():void
+ {
+ var conn:NetConnection = new NetConnection();
+ conn.connect(null);
+ netStream = new NetStream(conn);
+ qosInfoHistory = new QoSInfoHistory(netStream);
+ metricFactory = new DefaultMetricFactoryMocker(qosInfoHistory);
+ metricRepository = new MetricRepository(metricFactory);
+
+
+ bandwidthMetric = metricRepository.getMetric(MetricType.BANDWIDTH, generateWeights(1,0.9, 0.9*0.9) ) as BandwidthMetricMocker;
+
+ fragmentCountMetric = metricRepository.getMetric(MetricType.FRAGMENT_COUNT) as FragmentCountMetricMocker;
+ bufferFragmentsMetric = metricRepository.getMetric(MetricType.BUFFER_FRAGMENTS) as BufferFragmentsMetricMocker;
+
+ actualBitrateMetric = metricRepository.getMetric(MetricType.ACTUAL_BITRATE) as ActualBitrateMetricMocker;
+ bufferFragmentsMetric = metricRepository.getMetric(MetricType.BUFFER_FRAGMENTS) as BufferFragmentsMetricMocker;
+ availableQualityLevelsMetric = metricRepository.getMetric(MetricType.AVAILABLE_QUALITY_LEVELS) as AvailableQualityLevelsMetricMocker;
+ currentStatusMetric = metricRepository.getMetric(MetricType.CURRENT_STATUS) as CurrentStatusMetricMocker;
+ }
+
+ [After]
+ public function tearDown():void
+ {
+ fragmentCountMetric = null;
+ bandwidthMetric = null;
+ metricRepository = null;
+ metricFactory = null;
+ qosInfoHistory = null;
+ netStream = null;
+ }
+
+
+ [Test]
+ public function testComputeActualBitrateWhenActualBitrateMetricIsValid():void
+ {
+
+ actualBitrateMetric.internalValue = 846;
+ actualBitrateMetric.returnValid = true;
+
+ currentStatusMetric.internalValue = new Vector.();
+ currentStatusMetric.internalValue.push(2);
+ currentStatusMetric.internalValue.push(2);
+ currentStatusMetric.returnValid = true;
+
+ availableQualityLevelsMetric.internalValue = new Vector.();
+ for(var i:uint=0; i< 5; i++)
+ {
+ availableQualityLevelsMetric.internalValue.push(
+ new QualityLevel( i, 100 * i + 150, "test" + (100 * i + 150) ));
+ }
+ availableQualityLevelsMetric.returnValid = true;
+
+ var bitrate:Number = RuleUtils.computeActualBitrate(actualBitrateMetric, availableQualityLevelsMetric, currentStatusMetric);
+ assertEquals(846, bitrate);
+ }
+
+
+ [Test]
+ public function testComputeActualBitrateWhenActualBitrateMetricIsInvalidAndCurrentStatusIsValidAndAvailableQualityLevelsMetricIsValid():void
+ {
+
+ actualBitrateMetric.internalValue = 846;
+ actualBitrateMetric.returnValid = false;
+
+ currentStatusMetric.internalValue = new Vector.();
+ currentStatusMetric.internalValue.push(2);
+ currentStatusMetric.internalValue.push(2);
+ currentStatusMetric.returnValid = true;
+
+ availableQualityLevelsMetric.internalValue = new Vector.();
+ for(var i:uint=0; i< 5; i++)
+ {
+ availableQualityLevelsMetric.internalValue.push(
+ new QualityLevel( i, 100 * i + 150, "test" + (100 * i + 150) ));
+ }
+ availableQualityLevelsMetric.returnValid = true;
+
+ var bitrate:Number = RuleUtils.computeActualBitrate(actualBitrateMetric, availableQualityLevelsMetric, currentStatusMetric);
+ assertEquals(350, bitrate);
+ }
+
+
+ [Test]
+ public function testComputeActualBitrateWhenActualBitrateMetricIsInvalidAndCurrentStatusIsInvalidAndAvailableQualityLevelsMetricIsValid():void
+ {
+
+ actualBitrateMetric.internalValue = 846;
+ actualBitrateMetric.returnValid = false;
+
+ currentStatusMetric.internalValue = new Vector.();
+ currentStatusMetric.internalValue.push(2);
+ currentStatusMetric.internalValue.push(2);
+ currentStatusMetric.returnValid = false;
+
+ availableQualityLevelsMetric.internalValue = new Vector.();
+ for(var i:uint=0; i< 5; i++)
+ {
+ availableQualityLevelsMetric.internalValue.push(
+ new QualityLevel( i, 100 * i + 150, "test" + (100 * i + 150) ));
+ }
+ availableQualityLevelsMetric.returnValid = true;
+
+ var bitrate:Number = RuleUtils.computeActualBitrate(actualBitrateMetric, availableQualityLevelsMetric, currentStatusMetric);
+ assertTrue(isNaN(bitrate));
+ }
+
+ [Test]
+ public function testComputeActualBitrateWhenActualBitrateMetricIsInvalidAndCurrentStatusIsValidAndAvailableQualityLevelsMetricIsInvalid():void
+ {
+
+ actualBitrateMetric.internalValue = 846;
+ actualBitrateMetric.returnValid = false;
+
+ currentStatusMetric.internalValue = new Vector.();
+ currentStatusMetric.internalValue.push(2);
+ currentStatusMetric.internalValue.push(2);
+ currentStatusMetric.returnValid = true;
+
+ availableQualityLevelsMetric.internalValue = new Vector.();
+ for(var i:uint=0; i< 5; i++)
+ {
+ availableQualityLevelsMetric.internalValue.push(
+ new QualityLevel( i, 100 * i + 150, "test" + (100 * i + 150) ));
+ }
+ availableQualityLevelsMetric.returnValid = false;
+
+ var bitrate:Number = RuleUtils.computeActualBitrate(actualBitrateMetric, availableQualityLevelsMetric, currentStatusMetric);
+ assertTrue(isNaN(bitrate));
+ }
+
+ private function generateWeights(... weights):Vector.