You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openmeetings.apache.org by so...@apache.org on 2014/09/21 20:49:44 UTC

svn commit: r1626616 - in /openmeetings/trunk/singlewebapp/openmeetings-flash/src/main/flex: main.mxml org/apache/openmeetings/OmVideo.as

Author: solomax
Date: Sun Sep 21 18:49:43 2014
New Revision: 1626616

URL: http://svn.apache.org/r1626616
Log:
[OPENMEETINGS-1003] recording test seems to work

Modified:
    openmeetings/trunk/singlewebapp/openmeetings-flash/src/main/flex/main.mxml
    openmeetings/trunk/singlewebapp/openmeetings-flash/src/main/flex/org/apache/openmeetings/OmVideo.as

Modified: openmeetings/trunk/singlewebapp/openmeetings-flash/src/main/flex/main.mxml
URL: http://svn.apache.org/viewvc/openmeetings/trunk/singlewebapp/openmeetings-flash/src/main/flex/main.mxml?rev=1626616&r1=1626615&r2=1626616&view=diff
==============================================================================
--- openmeetings/trunk/singlewebapp/openmeetings-flash/src/main/flex/main.mxml (original)
+++ openmeetings/trunk/singlewebapp/openmeetings-flash/src/main/flex/main.mxml Sun Sep 21 18:49:43 2014
@@ -29,7 +29,6 @@
 	<fx:Script><![CDATA[
 		import mx.collections.ArrayCollection;
 		import mx.core.FlexGlobals;
-
 		import org.apache.openmeetings.OmVideo;
 
 		private static const MODE_N:String = "n";
@@ -51,6 +50,12 @@
 		private var echoSuppression:Boolean = true;
 		private var microphoneRateBest:int = 22;//5, 8, 11, 22, and 44
 		private var video:OmVideo;
+		private var recName:String;
+		private var codec:String = OmVideo.CODEC_H264;
+		private var protocol:String;
+		private var host:String;
+		private var port:String;
+		private var app:String;
 		[Bindable]
 		private var interview:Boolean = false;
 		[Bindable]
@@ -101,6 +106,10 @@
 			for (var i:int = 0; i < lbls.length; ++i) {
 				labels[lbls[i].id] = lbls[i].value;
 			}
+			protocol = tla.parameters['protocol'];
+			host = tla.parameters['host'];
+			port = tla.parameters['port'];
+			app = tla.parameters['app'];
 		}
 
 		private function selectListItem(combo:ComboBox, selected:int):void {
@@ -148,23 +157,23 @@
 		}
 
 		private function appInit():void {
-			video = new OmVideo(videoDisplay);
+			video = new OmVideo(videoDisplay, codec, protocol + "://" + host + ":" + port + "/" + app);
 			var modItems:ArrayCollection = new ArrayCollection();
 			if (camAvail() && micAvail()) {
 				modItems.addItem({label: getLabel(448), data: MODE_AV});
 			}
-			if (micAvail()) {
-				var micros:Array = Microphone.names;
-				var foundedMic:int = fillDeviceList(micros, mics, "mic");
-				selectListItem(mics, foundedMic);
-				modItems.addItem({label: getLabel(449), data: MODE_A});
-			}
 			if (camAvail()) {
 				var cameras:Array = Camera.names;
 				var foundedCam:int = fillDeviceList(cameras, cams, "cam");
 				selectListItem(cams, foundedCam);
 				modItems.addItem({label: getLabel(450), data: MODE_V});
 			}
+			if (micAvail()) {
+				var micros:Array = Microphone.names;
+				var foundedMic:int = fillDeviceList(micros, mics, "mic");
+				selectListItem(mics, foundedMic);
+				modItems.addItem({label: getLabel(449), data: MODE_A});
+			}
 			modItems.addItem({label: getLabel(451), data: MODE_N});
 			modes.dataProvider = modItems;
 
@@ -229,6 +238,8 @@
 			noAv.visible = textVisible;
 			startTest.visible = !textVisible;
 			videoGroup.visible = !textVisible;
+			videoScroller.visible = camVisible;
+			playGroup.visible = !textVisible;
 			resGroup.visible = interview ? false : camVisible;
 			attachCamera();
 		}
@@ -271,14 +282,15 @@
 
 		private function getCam():Camera {
 			debug("Entering getCam ...");
-			if (!videoDisplay.visible) {
+			if (!videoScroller.visible) {
 				return null;
 			}
 			var _camera:Camera = Camera.getCamera(cams.selectedItem.data);
 			if (_camera != null && !_camera.muted) {
+				//FIXME need to be unified
 				if (interview) {
 					//we need a fixed frame rate for the videos to merge them later on
-					_camera.setMode(video.width, video.height, 24, true);
+					_camera.setMode(video.width, video.height, 24);
 					debug("IS INTERVIEW ");
 					_camera.setQuality(0, 98);
 				} else {
@@ -291,7 +303,6 @@
 			return _camera;
 		}
 
-		//FIXME impossible to create test recording with mic only !!!!
 		private function attachCamera():void {
 			if (!camAvail()) {
 				return;
@@ -299,7 +310,6 @@
 			debug("Camera selected:: " + cams.selectedItem.data);
 			var cam:Camera = getCam();
 			debug("Camera selected:: " + cam);
-			//mic = getMic();
 			if (cam != null) {
 				if (cam.muted) {
 					debug("Camera Muted");
@@ -314,10 +324,28 @@
 						}
 					});
 				} else {
-					//cam = null;
 					_attachCamera(cam);
 				}
-			}
+			} else {
+				var mic:Microphone = getMic();
+				if (mic != null) {
+					if (mic.muted) {
+						var nc:NetConnection = new NetConnection();
+						nc.connect(null);
+						var ns:NetStream = new NetStream(nc);
+						ns.attachAudio(mic);
+						mic.addEventListener(StatusEvent.STATUS, function (event:StatusEvent):void {
+							debug("micStatusHandler! " + event);
+							mic.removeEventListener(StatusEvent.STATUS, arguments.callee);
+							ns.close();
+							nc.close();
+							if (mic.muted) {
+								debug("Unable to connect to active microphone.");
+							}
+						});
+					}
+				}
+ 			}
 		}
 
 		private function _attachCamera(cam:Camera):void {
@@ -366,7 +394,52 @@
 		private function startConf(e:Event):void {
 			store();
 		}
-		]]></fx:Script>
+
+		private function playTestRecording():void {
+			video.play(recName);
+		}
+
+		private function startTestRecording():void {
+			if (!noAv.visible) {
+				startTest.enabled = false;
+				play.enabled = false;
+				var counter:int = 5;
+				timerText.visible = true;
+				timerText.text = "5 sec";
+				var recTimer:Timer = new Timer(1000, counter);
+				var t:Date = new Date();
+				recName = "TEST_SETUP_" + t.getTime();
+				var mic:Microphone = getMic();
+				video.record(recName, getCam(), mic, function ():void {
+					mic.addEventListener(ActivityEvent.ACTIVITY, micActivityHandler);
+					//mic.onA
+					var micTimer:Timer = new Timer(100, 0);
+					micTimer.addEventListener(TimerEvent.TIMER, function (event:TimerEvent):void {
+						fill.width =  mic.activityLevel * RIGHT_WIDTH / 100;
+						trace("activity: " + mic.activityLevel);
+					});
+					recTimer.addEventListener(TimerEvent.TIMER, function (event:TimerEvent):void {
+						timerText.text = --counter + " sec";
+						if (counter == 0) {
+							timerText.visible = false;
+							startTest.enabled = true;
+							play.enabled = true;
+							playTestRecording();
+							micTimer.stop();
+							mic.removeEventListener(ActivityEvent.ACTIVITY, micActivityHandler);
+						}
+					});
+					recTimer.start();
+					micTimer.start();
+				});
+			}
+		}
+
+		function micActivityHandler(event:ActivityEvent):void{
+			//Do nothing, it just need to be there.
+		}
+	]]>
+	</fx:Script>
 
 	<s:Group id="mainSetupGroup" width="{APP_WIDTH}">
 		<s:layout>
@@ -392,7 +465,7 @@
 					</s:VGroup>
 					<s:Group width="100%">
 						<s:layout><s:HorizontalLayout horizontalAlign="right"/></s:layout>
-						<s:Button id="startTest" label="{getLabel(775)}"/>
+						<s:Button id="startTest" label="{getLabel(775)}" click="startTestRecording()"/><!--FIXME should be disabled until stream is attached-->
 					</s:Group>
 				</s:VGroup>
 				<mx:Text text="{getLabel(452)}" id="noAv" visible="false"/>
@@ -403,6 +476,8 @@
 						<mx:UIComponent id="videoDisplay" width="0" height="0" />
 					</s:Group>
 				</s:Scroller>
+				<s:Label id="timerText" height="20" width="45" x="{videoGroup.width - 60}" y="5" paddingLeft="5" paddingTop="5"
+				         visible="false" backgroundColor="0xf5f5f5" fontWeight="bold"><s:text></s:text></s:Label>
 				<s:VGroup id="playGroup">
 					<s:Group>
 						<s:Graphic x="0" z="1">
@@ -416,7 +491,7 @@
 					</s:Group>
 					<s:Group width="100%">
 						<s:layout><s:HorizontalLayout horizontalAlign="right"/></s:layout>
-						<s:Button id="play" label="{getLabel(764)}" enabled="false"/>
+						<s:Button id="play" label="{getLabel(764)}" enabled="false" click="playTestRecording()"/>
 					</s:Group>
 				</s:VGroup>
 			</s:Group>

Modified: openmeetings/trunk/singlewebapp/openmeetings-flash/src/main/flex/org/apache/openmeetings/OmVideo.as
URL: http://svn.apache.org/viewvc/openmeetings/trunk/singlewebapp/openmeetings-flash/src/main/flex/org/apache/openmeetings/OmVideo.as?rev=1626616&r1=1626615&r2=1626616&view=diff
==============================================================================
--- openmeetings/trunk/singlewebapp/openmeetings-flash/src/main/flex/org/apache/openmeetings/OmVideo.as (original)
+++ openmeetings/trunk/singlewebapp/openmeetings-flash/src/main/flex/org/apache/openmeetings/OmVideo.as Sun Sep 21 18:49:43 2014
@@ -2,25 +2,39 @@
  * Created by solomax on 9/17/2014.
  */
 package org.apache.openmeetings {
+import flash.events.AsyncErrorEvent;
+import flash.events.NetStatusEvent;
 import flash.media.Camera;
+import flash.media.H264Level;
+import flash.media.H264Profile;
+import flash.media.H264VideoStreamSettings;
 import flash.media.Microphone;
 import flash.media.Video;
+import flash.media.VideoStreamSettings;
+import flash.net.NetConnection;
 import flash.net.NetStream;
 import mx.core.UIComponent;
 
 public class OmVideo {
+	public static const CODEC_H264:String = "h264";
 	public static const PLAY:String = "play";
 	public static const BROADCAST:String = "broadcast";
 	public static const RECORD:String = "record";
+	public static const LIVE:String = "live";
 	private var vid:Video;
 	private var ui:UIComponent;
+	private var nc:NetConnection;
 	private var ns:NetStream;
 	public var width:int;
 	public var height:int;
 	private var mode:String;
+	private var codec:String;
+	private var url:String;
 
-	public function OmVideo(ui:UIComponent) {
+	public function OmVideo(ui:UIComponent, codec:String, url:String) {
 		this.ui = ui;
+		this.codec = codec;
+		this.url = url;
 	}
 
 	private function getVideo():Video {
@@ -55,6 +69,140 @@ public class OmVideo {
 		vid = null;
 	}
 
+	private function createStream():void {
+		ns = new NetStream(nc);
+		//see: http://livedocs.adobe.com/flash/9.0_de/ActionScriptLangRefV3/flash/net/NetStream.html
+		//according to the docs the construct to catch event has to be implemented like this.
+		//var t = this;
+		var clientObject:Object = new Object();
+		clientObject.onMetaData = function(metadata:Object):void {
+			//t.onMetaData(metadata);
+			trace("onMetaData: ", metadata);
+		};
+		clientObject.onPlayStatus = function(metadata:Object):void {
+			//t.onPlayStatus(metadata);
+			trace("onPlayStatus: ", metadata);
+		};
+		clientObject.onCuePoint = function(metadata:Object):void {
+			//t.onCuePoint(metadata);
+			trace("onCuePoint: ", metadata);
+		};
+		clientObject.ioError = function(error:Object):void {
+			//t.ioError(error);
+			trace("ioError: ", error);
+		};
+		clientObject.netStatus = function(status:Object):void {
+			//t.netStatus(status);
+			trace("netStatus: ", status);
+		};
+		clientObject.asyncError = function(error:Object):void {
+			//t.asyncError(error);
+			trace("asyncError: ", error);
+		};
+		ns.client = clientObject;
+		//this is a workaround, attaching the event to the client object does not work
+		ns.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus2);
+	}
+
+	private function onNetStatus2(evt:Object):void {
+		trace("netStream_onNetStatus: ", evt.info.code, evt.target);
+		//this.onNetStatus.sendEvent(evt.info);
+	}
+
+	private function _publish(mode:String, name:String, cam:Camera, mic:Microphone, f:Function):void {
+		if (ns != null){
+			reset();
+		}
+		this.mode = mode;
+		createStream();
+
+		if (cam != null) {
+			ns.attachCamera(cam);
+			//invokes Method in baseVideoView which shows the cam
+			attachCamera(cam);
+
+			var videoStreamSettings:VideoStreamSettings = null;
+			trace("codec = " + codec);
+			if (codec === CODEC_H264) {
+				var vss:H264VideoStreamSettings = new H264VideoStreamSettings();
+				vss.setProfileLevel(H264Profile.BASELINE, H264Level.LEVEL_5_1);
+				videoStreamSettings = vss;
+			} else {
+				videoStreamSettings = new VideoStreamSettings();
+			}
+			videoStreamSettings.setQuality(cam.bandwidth, cam.quality);
+			videoStreamSettings.setKeyFrameInterval(cam.keyFrameInterval);
+			trace("::keyFrameInterval " + cam.keyFrameInterval);
+			videoStreamSettings.setMode(cam.width, cam.height, cam.fps);
+			ns.videoStreamSettings = videoStreamSettings;
+		}
+		if (mic != null) {
+			ns.attachAudio(mic);
+			//FIXME !!! no mute !!! muteMicro(this.micMuted);
+		}
+
+		ns.publish(name, (mode == BROADCAST) ? LIVE : mode);
+		if (f != null) {
+			f.call();
+		}
+	}
+
+	private function publish(mode:String, name:String, cam:Camera, mic:Microphone, f:Function):void {
+		if (nc == null || !nc.connected) {
+			trace("NetConnection is not connected");
+			nc = new NetConnection();
+			nc.addEventListener(NetStatusEvent.NET_STATUS, function onConnectionStatus(e:NetStatusEvent):void {
+				trace("ConnectionStatus: " + e.info.code);
+				if (e.info.code == "NetConnection.Connect.Success") {
+					_publish(mode, name, cam, mic, f);
+				} else {
+					//TODO
+				}
+			});
+			nc.addEventListener(AsyncErrorEvent.ASYNC_ERROR, function (event:AsyncErrorEvent):void {
+				trace("login Async error" + event);
+			});
+			nc.client = {
+				onMetaData: function (infoObject:Object):void {
+					for (var propName:String in infoObject) {
+						trace(propName + " = " + infoObject[propName]);
+					}
+				}
+				, onBWDone: function(...rest):void {
+					trace("onBWDone");
+				}
+				, onBWCheck: function(...rest):Number {
+					trace("onBWCheck");
+					return 0;
+				}
+				, setId: function (id:Number):void {
+					trace("id: " + id); //TODO save connection id
+				}
+			};
+			nc.connect(url);
+		} else {
+			_publish(mode, name, cam, mic, f);
+		}
+	}
+
+	public function record(name:String, cam:Camera, mic:Microphone, f:Function):void {
+		publish(RECORD, name, cam, mic, f);
+	}
+
+	public function play(name:String):void {
+		if (ns != null){
+			reset();
+		}
+		mode = PLAY;
+		createStream();
+		//invokes Method in baseVideoView which shows the stream
+		getVideo().attachNetStream(ns);
+		//FIXME: Commented out, cause this leads to Buffer-Full/Buffer-Empty Events
+		//after re-syncing the stream
+		//this.setBuffer(0.1);
+		ns.play(name);
+	}
+
 	public function reset():void {
 		var vid:Video = getVideo();
 		if (ns != null) {