0 Replies Latest reply on Dec 1, 2011 6:28 PM by markussieb123

    Detecting the optimal upload bandwidth of cam video stream (Dynamic Bandwidth Detection Approach)


      Hello folks,


      i am discovering the wide world of adobe technologies and i am impressed how seamless all is working.


      Anyway i have a tricky problem, at least it seems tricky to me. Here we go: i build up a client (camera+audio conferencing) streaming its camera right to my server (red5). Every client can see the camera streams of each connected particpant. So far so good all is working as expected, we can call this a conferencing solution. Now i would like to improve that by implementing some kind of automatic bandwidth detection in order to adjust the video resolution depending on the current bandwidth "situation" of every participant. Some might have stronger upload bandwidth, some might have a bad or even too low upload bandwidth to even up-stream their video. My client should be able to handle them individually. Those clients who have a good upload bandwidth should be able to up-stream their video in the most high resolution as possible regarding their bandwidth. For those clients having a bad upload connection i assume to reduce their video resolution automatically. The aim behind this automatic bandwidth detection should be to give the most priority to the audio streaming by taking care to not overhelming the bandwidth with heavy camera usage.


      I know there is upload speed tests (onBWCheck, etc), but i assume this test is annoying for the participants as well as they are not reflecting dynamic changes.


      So lets say i start with a default camera resolution of 640 x 480 px for every client. What i need to know is in general two informtion in order to judge about the current bandwidth is enough for the currently up-streamed camera video:


      1) the actual bandwidth used for the up-streaming camera video (based on specific resolution, quality and fps) which is of course dynamicly changing

      2) the max. needed bandwidth which is necessary to perfectly up-stream the camera video regarding the specific resolution, quality and fps of the camera settings


      So here is my current solutions:


      1) the actual bandwidth: every second the currentBytesPerSecond() method of the NetStreamInfo object is of my uploading stream is called to get the currently used bandwidth speed (http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/NetStreamInfo .html#currentBytesPerSecond). The documentation says about the currentBytesPerSecond() method: Specifies the rate at which the NetStream buffer is filled in bytes per second. I understood from that phrase that literally this is the amount of bytes filled into the network depending on the current network situation. I tested this by using bandwidth limitation and in fact the currentBytesPerSecond() returns the dynamicly changed amount of bytes sent through the network. So thats pretty OK.


      2) the max. needed bandwidth: here i struggle. I have three principal ideas to know how much bytes/second are max. needed to up-stream the camera video to the server in a proper way:


      * either by experience, which means i manually make several tests to know the max. bytes/second needed for every possible specific resolution, quality, fps (i discovered that different cameras can even produce different results with the same camera settings!)

      * calculate the needed bytes/second (actually i use the H246 codec)

      * or finally the most crazy but maybe most proper solution: beside the up-stream to the server the client streams additionally to the same client application over the localhost network. I find this last attempt the most interesting because it gives very practicaly accurate result how much bytes must be send because almost the bandwidth of the network through the internet isnt used either. The client sends a stream to himself over the internal network IP (localhost, To achieve this i tried to let the NetConnection being connected to localhost and null and publish the video. But the stream didnt worked. Here is my code:



                private function init():void {
                      nc = new NetConnection();
                      nc.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
                      ns = new NetStream(nc);
                      ns.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
                      ns.client = {};
                      var camera:Camera = Camera.getCamera();
                      if (camera) {
                      } else {
                          Alert.show("You don't seem to have a camera.");
                      mainTimer.addEventListener (TimerEvent.TIMER, onMainTimerTickHandler);
                  private function onMainTimerTickHandler (evt:TimerEvent): void
                      info.text += Number(ns.info.currentBytesPerSecond / 1000).toFixed(2) + " kBytes (OUT)\n";
                  private function netStatusHandler(event:NetStatusEvent):void {
                      info.text += event.info.code+"\n";


      The result is a connection success, but the stream didnt send any data due to the fact that ns.info.currentBytesPerSecond returns 0. Also strange is that the NetSteam or NetConnection didn't return any error.


      So folks here i struggle and i ask does anyone out there have any hints or ideas how to solve this tricky one?


      Thanks in advance,