multiple subscribers freezes flash

Ask questions on the ActionScript API here

multiple subscribers freezes flash

Postby surbanczyk » Fri Oct 19, 2012 2:43 am

i want to add lets say 10 subscribers

Code: Select all
for (var i:int = 0; i < streams.length; i++)
         {
            for (var j:int = 0; j < 10; j++)
            {
               var stream:Stream = streams[i];
               if (stream.connection.connectionId != session.connection.connectionId)
               {
                  var subscriber:Subscriber = session.subscribe(stream);
                  var m:int = j % 2
                  subscriber.width = 80;
                  subscriber.height = 60;
                  
                  if (m != 1)
                  {
                     subscriber.x = 100 * Math.floor(j / 2)
                     subscriber.y = 0
                  }
                  else
                  {
                     subscriber.x = 100 * Math.floor(j / 2)
                     subscriber.y = 80
                  }
                  trace(subscriber.x)
                  
                  addChild(subscriber);
               }
            }
         }


why it freezes flash?
Was this post helpful? (0)
surbanczyk
 
Posts: 10
Joined: Thu Oct 18, 2012 2:22 am
Thumbs Up: 0

Re: multiple subscribers freezes flash

Postby mumm » Fri Oct 19, 2012 12:46 pm

Hi surbanczyk,

While we can in theory support more than 10 streams, in general, most people will start to run in to performance issues around that number.

How are you testing this? Is this happening consistently, exactly when you hit 10 streams?

Jon
Was this post helpful? (0)
mumm
 
Posts: 392
Joined: Wed May 18, 2011 12:10 am
Thumbs Up: 28

Re: multiple subscribers freezes flash

Postby surbanczyk » Tue Oct 23, 2012 2:56 am

Was this post helpful? (0)
surbanczyk
 
Posts: 10
Joined: Thu Oct 18, 2012 2:22 am
Thumbs Up: 0

Re: multiple subscribers freezes flash

Postby surbanczyk » Tue Oct 23, 2012 3:10 am

here is a code taken from Your sizing tutorial is converted from flex to flash:

Code: Select all
package
{
   import com.tokbox.TB;
   import com.tokbox.events.DevicePanelEvent;
   import com.tokbox.events.ExceptionEvent;
   import com.tokbox.events.PublisherEvent;
   import com.tokbox.events.SessionConnectEvent;
   import com.tokbox.events.SessionDisconnectEvent;
   import com.tokbox.events.StreamEvent;
   import com.tokbox.model.DeviceManager;
   import com.tokbox.model.DevicePanel;
   import com.tokbox.model.Publisher;
   import com.tokbox.model.PublisherProperties;
   import com.tokbox.model.Session;
   import com.tokbox.model.Stream;
   import com.tokbox.model.Subscriber;
   import com.tokbox.model.SubscriberProperties;
   import flash.display.Sprite;
   
   import flash.display.LoaderInfo;
   
   import mx.collections.ArrayCollection;
   import mx.controls.Alert;
   import mx.core.UIComponent;
   
   public class Sizing extends Sprite
   {
      private static const API_KEY:String = "xxx"; // Replace with your API key.
      private var SESSION_ID:String = "xxx"; // Replace with your own session ID. See http://www.tokbox.com/opentok/api/tools/generator
      private var TOKEN:String = "xxx"; // Replace with a generated token. See http://www.tokbox.com/opentok/api/tools/generator
      
      private static const PUBLISHER_WIDTH:Number = 220;
      private static const PUBLISHER_HEIGHT:Number = 165;
      private static const subscriber_width:Array = new Array(120, 160, 220);
      private static const subscriber_height:Array = new Array(90, 120, 165);
      
      private static const CONNECTING:String = "Connecting...";
      private static const CONNECTED:String = "Connected. You can start publishing.";
      private static const PUBLISHING:String = "Publishing.";
      private static const UNPUBLISHING:String = "Unpublishing.";
      
      private var _session:Session;
      private var _publisher:Publisher;
      private var _devicePanel:DevicePanel;
      
      private var _callStatus:String = CONNECTING;
      
      private var _publishing:Boolean = false;
      
      public function Sizing()
      {
         init()
      }
      
      public function init():void
      {
         /*TOKEN = LoaderInfo(this.root.loaderInfo).parameters.token;*/
         TOKEN = unescape(TOKEN);
         _session = TB.initSession(SESSION_ID);
         
         // Add event listeners to the session
         _session.addEventListener(SessionConnectEvent.CONNECTED, sessionConnectedHandler);
         _session.addEventListener(StreamEvent.CREATED, streamCreatedHandler);
         _session.addEventListener(StreamEvent.DESTROYED, streamDestroyedHandler);
         
         /*
            If testing the app from the desktop, be sure to check the Flash Player Global Security setting
            to allow the page from communicating with SWF content loaded from the web. For more information,
            see http://www.tokbox.com/opentok/build/tutorials/helloworld.html#localTest
          */
         _session.connect(API_KEY, TOKEN);
      
         // Un-comment either of the following to set automatic logging and exception handling.
         // See the exceptionHandler() method below.
         // TB.setLogLevel(TB.DEBUG);
         // TB.addEventListener("exception", exceptionHandler);
      }
      
//--------------------------------------
//  OPENTOK EVENT HANDLERS
//--------------------------------------
      
      private function sessionConnectedHandler(event:SessionConnectEvent):void
      {
         // Now possible to start streaming
         _callStatus = CONNECTED;
         startPublishing();
      }
      
      private function streamCreatedHandler(event:StreamEvent):void
      {
         // When we get a streamCreated event for the stream we publish,
         // build the grid of subscribers at the appropriate sizes.
         for (var i:int = 0; i < event.streams.length; i++)
         {
            if (event.streams[i].connection.connectionId == event.target.connection.connectionId)
            {
               // Our publisher just started streaming
               // Create sized grid of subscribers
               
               for (var j:int = 0; j < 3; j++)
               {
                  //var gridRow:GridRow = videoGrid.getElementAt(j + 1) as GridRow;
                  //gridRow.height = subscriber_height[j];
                  
                  for (var k:int = 0; k < 3; k++)
                  {
                     
                     var subscriberProps:SubscriberProperties = new SubscriberProperties();
                     subscriberProps.subscribeToAudio = false;
                     var session:Session = event.target as Session;
                     var subscriber:Subscriber = session.subscribe(event.streams[i], subscriberProps);
                     subscriber.width = subscriber_width[k];
                     subscriber.height = subscriber_height[j];
                     subscriber.x = subscriber_width[k] * j;
                     subscriber.y = subscriber_height[j] * k;
                     trace("S")
                     addChild(subscriber);
                     
                  }
               }
               
               // Update status and controls
               _callStatus = PUBLISHING;
               _publishing = true;
            }
         }
      }
      
      private function streamDestroyedHandler(event:StreamEvent):void
      {
         for (var i:int = 0; i < event.streams.length; i++)
         {
            var session:Session = event.target as Session;
            if (event.streams[i].connection.connectionId == session.connection.connectionId)
            {
               // Our publisher just stopped streaming
               // Update status and controls
               _callStatus = CONNECTED;
               _publishing = false;
            }
         }
      }
      
      /*
       *   If you un-comment the call to TB.addEventListener(), above, OpenTok
       *   calls the exceptionHandler() method when exception events occur.
       *   You can modify this method to further process exception events.
       *   If you un-comment the call to TB.setLogLevel(), above, OpenTok
       *   automatically displays exception event messages.
       */
      private function exceptionHandler(event:ExceptionEvent):void
      {
         Alert.show("Exception: " + event.code + "::" + event.message);
      }
      
//--------------------------------------
//  LINK CLICK HANDLERS
//--------------------------------------
      
      /*private function publishButtonClickHandler():void
         {
         if (_publishing)
         {
         stopPublishing();
         }
         else
         {
         startPublishing();
         }
       }*/
      
//--------------------------------------
//  PRIVATE METHODS
//--------------------------------------
      
// Called when user wants to start participating in the call
      private function startPublishing():void
      {
         // Starts publishing user local camera and mic
         // as a stream into the session
         
         var publisherProps:PublisherProperties = new PublisherProperties();
         publisherProps.publishAudio = false;
         _publisher = TB.initPublisher(API_KEY, publisherProps);
         _session.publish(_publisher);
         _publisher.width = PUBLISHER_WIDTH;
         _publisher.height = PUBLISHER_HEIGHT;
         _publisher.x = 500
         addChild(_publisher);
         //_publisher.addEventListener(PublisherEvent.SETTINGS_BUTTON_CLICK, settingsButtonClickHandler, false, 0, true);
         
         _callStatus = PUBLISHING;
         //publishButton.enabled = false;
      }
      
// Called when user wants to stop participating in the call
      private function stopPublishing():void
      {
         if (_publishing)
         {
            // Stop the stream
            _session.unpublish(_publisher);
            _publisher = null;
         }
         
         _callStatus = UNPUBLISHING;
         _publishing = false;
      }
   }
}



the code above works it displays me 9 subscribers

when I change the size of the subscriber window from:
Code: Select all
private static const subscriber_width:Array = new Array(120, 160, 220);
   private static const subscriber_height:Array = new Array(90, 120, 165);


to

Code: Select all
private static const subscriber_width:Array = new Array(120, 120, 120);
   private static const subscriber_height:Array = new Array(90, 90, 90);




so the overall code look s like this:

Code: Select all
package
{
   import com.tokbox.TB;
   import com.tokbox.events.DevicePanelEvent;
   import com.tokbox.events.ExceptionEvent;
   import com.tokbox.events.PublisherEvent;
   import com.tokbox.events.SessionConnectEvent;
   import com.tokbox.events.SessionDisconnectEvent;
   import com.tokbox.events.StreamEvent;
   import com.tokbox.model.DeviceManager;
   import com.tokbox.model.DevicePanel;
   import com.tokbox.model.Publisher;
   import com.tokbox.model.PublisherProperties;
   import com.tokbox.model.Session;
   import com.tokbox.model.Stream;
   import com.tokbox.model.Subscriber;
   import com.tokbox.model.SubscriberProperties;
   import flash.display.Sprite;
   
   import flash.display.LoaderInfo;
   
   import mx.collections.ArrayCollection;
   import mx.controls.Alert;
   import mx.core.UIComponent;
   
   public class Sizing extends Sprite
   {
      private static const API_KEY:String = "xxx"; // Replace with your API key.
      private var SESSION_ID:String = "xxx"; // Replace with your own session ID. See http://www.tokbox.com/opentok/api/tools/generator
      private var TOKEN:String = "xxx"; // Replace with a generated token. See http://www.tokbox.com/opentok/api/tools/generator
      
      private static const PUBLISHER_WIDTH:Number = 220;
      private static const PUBLISHER_HEIGHT:Number = 165;
      private static const subscriber_width:Array = new Array(120, 120, 120);
      private static const subscriber_height:Array = new Array(90, 90, 90);
      
      private static const CONNECTING:String = "Connecting...";
      private static const CONNECTED:String = "Connected. You can start publishing.";
      private static const PUBLISHING:String = "Publishing.";
      private static const UNPUBLISHING:String = "Unpublishing.";
      
      private var _session:Session;
      private var _publisher:Publisher;
      private var _devicePanel:DevicePanel;
      
      private var _callStatus:String = CONNECTING;
      
      private var _publishing:Boolean = false;
      
      public function Sizing()
      {
         init()
      }
      
      public function init():void
      {
         /*TOKEN = LoaderInfo(this.root.loaderInfo).parameters.token;*/
         TOKEN = unescape(TOKEN);
         _session = TB.initSession(SESSION_ID);
         
         // Add event listeners to the session
         _session.addEventListener(SessionConnectEvent.CONNECTED, sessionConnectedHandler);
         _session.addEventListener(StreamEvent.CREATED, streamCreatedHandler);
         _session.addEventListener(StreamEvent.DESTROYED, streamDestroyedHandler);
         
         /*
            If testing the app from the desktop, be sure to check the Flash Player Global Security setting
            to allow the page from communicating with SWF content loaded from the web. For more information,
            see http://www.tokbox.com/opentok/build/tutorials/helloworld.html#localTest
          */
         _session.connect(API_KEY, TOKEN);
      
         // Un-comment either of the following to set automatic logging and exception handling.
         // See the exceptionHandler() method below.
         // TB.setLogLevel(TB.DEBUG);
         // TB.addEventListener("exception", exceptionHandler);
      }
      
//--------------------------------------
//  OPENTOK EVENT HANDLERS
//--------------------------------------
      
      private function sessionConnectedHandler(event:SessionConnectEvent):void
      {
         // Now possible to start streaming
         _callStatus = CONNECTED;
         startPublishing();
      }
      
      private function streamCreatedHandler(event:StreamEvent):void
      {
         // When we get a streamCreated event for the stream we publish,
         // build the grid of subscribers at the appropriate sizes.
         for (var i:int = 0; i < event.streams.length; i++)
         {
            if (event.streams[i].connection.connectionId == event.target.connection.connectionId)
            {
               // Our publisher just started streaming
               // Create sized grid of subscribers
               
               for (var j:int = 0; j < 3; j++)
               {
                  //var gridRow:GridRow = videoGrid.getElementAt(j + 1) as GridRow;
                  //gridRow.height = subscriber_height[j];
                  
                  for (var k:int = 0; k < 3; k++)
                  {
                     
                     var subscriberProps:SubscriberProperties = new SubscriberProperties();
                     subscriberProps.subscribeToAudio = false;
                     var session:Session = event.target as Session;
                     var subscriber:Subscriber = session.subscribe(event.streams[i], subscriberProps);
                     subscriber.width = subscriber_width[k];
                     subscriber.height = subscriber_height[j];
                     subscriber.x = subscriber_width[k] * j;
                     subscriber.y = subscriber_height[j] * k;
                     trace("S")
                     addChild(subscriber);
                     
                  }
               }
               
               // Update status and controls
               _callStatus = PUBLISHING;
               _publishing = true;
            }
         }
      }
      
      private function streamDestroyedHandler(event:StreamEvent):void
      {
         for (var i:int = 0; i < event.streams.length; i++)
         {
            var session:Session = event.target as Session;
            if (event.streams[i].connection.connectionId == session.connection.connectionId)
            {
               // Our publisher just stopped streaming
               // Update status and controls
               _callStatus = CONNECTED;
               _publishing = false;
            }
         }
      }
      
      /*
       *   If you un-comment the call to TB.addEventListener(), above, OpenTok
       *   calls the exceptionHandler() method when exception events occur.
       *   You can modify this method to further process exception events.
       *   If you un-comment the call to TB.setLogLevel(), above, OpenTok
       *   automatically displays exception event messages.
       */
      private function exceptionHandler(event:ExceptionEvent):void
      {
         Alert.show("Exception: " + event.code + "::" + event.message);
      }
      
//--------------------------------------
//  LINK CLICK HANDLERS
//--------------------------------------
      
      /*private function publishButtonClickHandler():void
         {
         if (_publishing)
         {
         stopPublishing();
         }
         else
         {
         startPublishing();
         }
       }*/
      
//--------------------------------------
//  PRIVATE METHODS
//--------------------------------------
      
// Called when user wants to start participating in the call
      private function startPublishing():void
      {
         // Starts publishing user local camera and mic
         // as a stream into the session
         
         var publisherProps:PublisherProperties = new PublisherProperties();
         publisherProps.publishAudio = false;
         _publisher = TB.initPublisher(API_KEY, publisherProps);
         _session.publish(_publisher);
         _publisher.width = PUBLISHER_WIDTH;
         _publisher.height = PUBLISHER_HEIGHT;
         _publisher.x = 500
         addChild(_publisher);
         //_publisher.addEventListener(PublisherEvent.SETTINGS_BUTTON_CLICK, settingsButtonClickHandler, false, 0, true);
         
         _callStatus = PUBLISHING;
         //publishButton.enabled = false;
      }
      
// Called when user wants to stop participating in the call
      private function stopPublishing():void
      {
         if (_publishing)
         {
            // Stop the stream
            _session.unpublish(_publisher);
            _publisher = null;
         }
         
         _callStatus = UNPUBLISHING;
         _publishing = false;
      }
   }
}



it hands flash and tells me that the script is working for more then 15s.
http://screencast.com/t/e6PHeQKVtz

what does LayoutMenager.validateDisplayList do ?

I guess is that it checks if the subscriber displayObject is placed somewhere, and it gets some false value and tries to position it somewhere else so it causes an infinite loop.

Why the script behaves so different if subscribers have all the exact same size?
Any idea?
Was this post helpful? (0)
surbanczyk
 
Posts: 10
Joined: Thu Oct 18, 2012 2:22 am
Thumbs Up: 0

Re: multiple subscribers freezes flash

Postby jtsai » Thu Oct 25, 2012 2:30 pm

I have logged a bug with our AS3 developers as I was also able to reproduce the freezing.

John
Was this post helpful? (0)
Very helpful resource: Devs Checklist
Examples with OpenTok: Examples
User avatar
jtsai
 
Posts: 1954
Joined: Wed Sep 14, 2011 3:00 pm
Thumbs Up: 156

Re: multiple subscribers freezes flash

Postby surbanczyk » Thu Oct 25, 2012 11:12 pm

thx
Was this post helpful? (0)
surbanczyk
 
Posts: 10
Joined: Thu Oct 18, 2012 2:22 am
Thumbs Up: 0

Re: multiple subscribers freezes flash

Postby surbanczyk » Tue Oct 30, 2012 3:45 am

I some further research on this problem and it is not multiple subscribers that freezes flash but more then one publisher, I was able to get 16 streams from one publisher but when there is more than one publisher flash freezes.

So this It is a publisher Object related problem.
Was this post helpful? (0)
surbanczyk
 
Posts: 10
Joined: Thu Oct 18, 2012 2:22 am
Thumbs Up: 0

Re: multiple subscribers freezes flash

Postby surbanczyk » Tue Oct 30, 2012 4:04 am

new info

I did some tests:
-I was able to send 3 streams on 3 different workstations but the app didn't generate any subscriber video, and it worked.
-I was able to receive a subscriber object video only when one stream was published from 3 connected clients and it worked,
- when ever I try to add a subscriber Object to stage while a publisher Object is streaming data the flash freezes

In general I'm not able to simultaneously publish and watch other streams on one app, so I'm not able to build a conference app.
Was this post helpful? (0)
surbanczyk
 
Posts: 10
Joined: Thu Oct 18, 2012 2:22 am
Thumbs Up: 0

Re: multiple subscribers freezes flash

Postby surbanczyk » Tue Mar 05, 2013 7:56 am

this bug was fixed
Was this post helpful? (0)
surbanczyk
 
Posts: 10
Joined: Thu Oct 18, 2012 2:22 am
Thumbs Up: 0


Return to ActionScript



Who is online

Users browsing this forum: Google [Bot] and 1 guest

cron