Zurück   Flashforum > Flash und Server > Flash Media Server

Antwort
 
LinkBack Themen-Optionen Ansicht
Alt 25-05-2007, 10:07   #1 (permalink)
Neuer User
 
Registriert seit: Aug 2006
Beiträge: 15
Question bwcheck to red5

Hallo,

kann man dieses bwcheck howto vom devnet
http://www.adobe.com/devnet/flashcom...bandwidth.html
zum Red5 portieren?

Oder gibt es da vielleicht schon etwas Serverseitiges für Red5?


Danke im vorraus
bertengel ist offline   Mit Zitat antworten
Alt 30-05-2007, 09:25   #2 (permalink)
Neuer User
 
Registriert seit: Aug 2006
Beiträge: 15
Lightbulb

ich habe mal das snippet von d.rossi benutzt um erstmal serverseitig vorranzukommen:

hier mal der code:

Application:
Code:
package demo;

import org.red5.server.adapter.ApplicationAdapter;
import org.red5.server.api.IConnection;

public class Application extends ApplicationAdapter 
{
   public boolean appConnect(IConnection conn, Object[] params) 
   {
    	BandwidthDetection detect = new BandwidthDetection();
        detect.checkBandwidth(conn);
       
        return true;
    }  
}
Interface

Code:
package demo;

import org.red5.server.api.IConnection;

public interface IBandwidthDetection {
       
   public void checkBandwidth(IConnection p_client);
       
   public void calculateClientBw(IConnection p_client);
}
Bandwidth Class

Code:
package demo;

import org.red5.server.api.IConnection;
import org.red5.server.api.Red5;
import org.red5.server.api.service.IPendingServiceCall;
import org.red5.server.api.service.IPendingServiceCallback;
import org.red5.server.api.service.IServiceCapableConnection;
import org.red5.server.api.stream.IStreamCapableConnection;

import org.apache.log4j.Logger;

import java.util.*;

import java.util.Map;
import java.util.HashMap;

public class BandwidthDetection implements IPendingServiceCallback, IBandwidthDetection {
   
   IConnection client = null;
   double latency = 0;
   double cumLatency = 1;
   int count = 0;
   int sent = 0;
   double kbitDown = 0;
   double deltaDown = 0;
   double deltaTime = 0;
   
   List<Long> pakSent = new ArrayList<Long>();
   List<Long> pakRecv = new ArrayList<Long>();
   
   private Map<String, Long> beginningValues;
   private double[] payload = new double[1200];
   private double[] payload_1 = new double[12000];
   private double[] payload_2 = new double[12000];
   
   private static final Logger log = Logger.getLogger(BandwidthDetection.class.getName());
   
   public BandwidthDetection()
   {
       
   }
   
   public void checkBandwidth(IConnection p_client)
   {
       this.calculateClientBw(p_client);
   }
   
   
   
   public void calculateClientBw(IConnection p_client)
   {
       for (int i=0; i<1200; i++){
           payload[i] = Math.random();
       }
       
       p_client.setAttribute("payload", payload);
       
       for (int i=0; i<12000; i++){
           payload_1[i] = Math.random();
       }
       
       p_client.setAttribute("payload_1", payload_1);
       
       for (int i=0; i<12000; i++){
           payload_2[i] = Math.random();
       }
       
       p_client.setAttribute("payload_2", payload_2);
       
       final IStreamCapableConnection beginningStats = this.getStats();
       final Long start = new Long(System.nanoTime()/1000000); //new Long(System.currentTimeMillis());
       
       this.client = p_client;
       beginningValues = new HashMap<String, Long>();
       beginningValues.put("b_down", beginningStats.getWrittenBytes());
       beginningValues.put("b_up", beginningStats.getReadBytes());
       beginningValues.put("time", start);
       
       this.pakSent.add(start);
       this.sent++;
       this.callBWCheck("");
   }
   
   /**
    * Handle callback from service call. 
    */
   public void resultReceived(IPendingServiceCall call) { 
       Long now = new Long(System.nanoTime()/1000000); //new Long(System.currentTimeMillis());
       this.pakRecv.add(now);
       Long timePassed = (now - this.beginningValues.get("time"));
       this.count++;
       
       if (count == 1) {
           latency = Math.min(timePassed, 800);
           latency = Math.max(latency, 10);
           
           log.info("count: "+count+ " sent: "+sent+" timePassed: "+timePassed+" latency: "+latency);
           
           // We now have a latency figure so can start sending test data.
           // Second call.  1st packet sent
           pakSent.add(now);
           sent++;
           
           this.callBWCheck(this.client.getAttribute("payload"));
       }
       // To run a very quick test, uncomment the following if statement and comment out the next 3 if statements.
       /*
       else if (count == 2 && (timePassed < 2000)) {
           pakSent.add(now);
           sent++;
           cumLatency++;
           this.callBWCheck(this.client.getAttribute("payload"));
       }
      */
       // The following will progressivly increase the size of the packets been sent until 1 second has elapsed.
       else if ((count > 1 && count < 3) && (timePassed < 1000)) {
           pakSent.add(now);
           sent++;
           cumLatency++;
           this.callBWCheck(this.client.getAttribute("payload"));
       } else if ((count >=3 && count < 6) && (timePassed < 1000)) {
           pakSent.add(now);
           sent++;
           cumLatency++;
           this.callBWCheck(this.client.getAttribute("payload_1"));
       } else if (count >= 6 && (timePassed < 1000)) {
           pakSent.add(now);
           sent++;
           cumLatency++;
           this.callBWCheck(this.client.getAttribute("payload_2"));
       }
       // Time elapsed now do the calcs
       else if (sent == count) {
           // see if we need to normalize latency
           if (latency >= 100) {
               // make sure satelite and modem is detected properly
               if (pakRecv.get(1) - pakRecv.get(0) > 1000) {
                   latency = 100; 
               }
           }
   
           this.client.removeAttribute("payload");
           this.client.removeAttribute("payload_1");
           this.client.removeAttribute("payload_2");
           
           final IStreamCapableConnection endStats = this.getStats();           
           deltaDown = (endStats.getWrittenBytes() - beginningValues.get("b_down")) * 8 / 1000; // bytes to kbits
           deltaTime = ((now - beginningValues.get("time")) - (latency * cumLatency)) / 1000; // total dl time - latency for each packet sent in secs
           if (deltaTime <= 0) {
               deltaTime = (now - beginningValues.get("time")) / 1000;
           }
           kbitDown = Math.round(deltaDown / deltaTime); // kbits / sec
           
           log.info("onBWDone: kbitDown = " + kbitDown + ", deltaDown= " + deltaDown + ", deltaTime = " + deltaTime + ", latency = " + this.latency);
        
                   
           this.callBWDone(this.kbitDown, this.deltaDown, this.deltaTime, this.latency);                                 
       }
   }
  
   private void callBWCheck(Object params)
   {
       IConnection conn = Red5.getConnectionLocal();
       
       if (conn instanceof IServiceCapableConnection) {
           ((IServiceCapableConnection) conn).invoke("onBWCheck", new Object[]{params}, this);
       }
   }
   
   private void callBWDone(double kbitDown, double deltaDown, double deltaTime, double latency)
   {
       IConnection conn = Red5.getConnectionLocal();
               
       if (conn instanceof IServiceCapableConnection) {
           ((IServiceCapableConnection) conn).invoke("onBWDone", new Object[]{kbitDown,  deltaDown, deltaTime, latency});
       }
   }
   
   private IStreamCapableConnection getStats()
   {
       IConnection conn = Red5.getConnectionLocal();
       if (conn instanceof IStreamCapableConnection) {
           return (IStreamCapableConnection) conn;
       }
       return null;
   }
  
   
}
in der Clientanwendung (Flash8) frage ich nun diesen kbitDown Wert ab. Aber dieser ändert sich erheblich wenn ich dieses SWF öfter aufrufe.

Wo könnte es buggy sein?

Probiert mal und schreibt bitte ob die Werte sinnvoll sind:

http://213.239.215.73/demo.html

Geändert von bertengel (30-05-2007 um 09:28 Uhr)
bertengel ist offline   Mit Zitat antworten
Antwort

Lesezeichen

Themen-Optionen
Ansicht

Forumregeln
Es ist Ihnen nicht erlaubt, neue Themen zu verfassen.
Es ist Ihnen nicht erlaubt, auf Beiträge zu antworten.
Es ist Ihnen nicht erlaubt, Anhänge hochzuladen.
Es ist Ihnen nicht erlaubt, Ihre Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks sind an
Pingbacks sind an
Refbacks sind an



Alle Zeitangaben in WEZ +1. Es ist jetzt 01:59 Uhr.

Domains, Webhosting & Vserver von Host Europe
Unterstützt das Flashforum!
Adobe User Group


Copyright ©1999 – 2012 Marc Thiele