# Dynamic Bandwidth Detection (BWCheck)

**URL:** <https://community.wowza.com/t/dynamic-bandwidth-detection-bwcheck/73>\
**Category:** Wowza Streaming Engine\
**Created:** [March 15, 2007, 6:40am UTC](https://community.wowza.com/t/dynamic-bandwidth-detection-bwcheck/73 "2007-03-15T06:40:15Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![Roger\_Littin](https://avatars.discourse-cdn.com/v4/letter/r/d26b3c/32.png) [@Roger\_Littin](https://community.wowza.com/u/Roger_Littin)\
**Post date:** [June 10, 2007, 9:31pm UTC](https://community.wowza.com/t/dynamic-bandwidth-detection-bwcheck/73/21 "2007-06-10T21:31:41Z")

</div>

This example has moved here:

[https://www.wowza.com/docs/how-to-check-bandwidth-from-client-to-server-to-test-uplink-to-be-used-by-a-live-stream-encoder-moduleclientbwcheck](https://www.wowza.com/docs/how-to-check-bandwidth-from-client-to-server-to-test-uplink-to-be-used-by-a-live-stream-encoder-moduleclientbwcheck)

---

<div class="post-metadata">

**Author:** ![Roger\_Littin](https://avatars.discourse-cdn.com/v4/letter/r/d26b3c/32.png) [@Roger\_Littin](https://community.wowza.com/u/Roger_Littin)\
**Post date:** [September 17, 2008, 9:31pm UTC](https://community.wowza.com/t/dynamic-bandwidth-detection-bwcheck/73/22 "2008-09-17T21:31:22Z")

</div>

[http://www.fluidmd.com/wowza/bwcheck.zip](http://www.fluidmd.com/wowza/bwcheck.zip)

I will update the link in the other post.

Roger.

---

<div class="post-metadata">

**Author:** ![Roger\_Littin](https://avatars.discourse-cdn.com/v4/letter/r/d26b3c/32.png) [@Roger\_Littin](https://community.wowza.com/u/Roger_Littin)\
**Post date:** [October 3, 2008, 7:22pm UTC](https://community.wowza.com/t/dynamic-bandwidth-detection-bwcheck/73/23 "2008-10-03T19:22:54Z")

</div>

I’m working on a new checker that will allow you to do this while a stream is running.

I will post the code here when it is ready.

Roger.

---

<div class="post-metadata">

**Author:** ![Roger\_Littin](https://avatars.discourse-cdn.com/v4/letter/r/d26b3c/32.png) [@Roger\_Littin](https://community.wowza.com/u/Roger_Littin)\
**Post date:** [December 14, 2009, 3:13pm UTC](https://community.wowza.com/t/dynamic-bandwidth-detection-bwcheck/73/24 "2009-12-14T15:13:51Z")

</div>

Hi Romano,

As is says on page 1 of this thread, The original bw checker was a port of a similar bit of code originally done for FMS2. They did the same thing with the latency.

Since coding the original, I have tried to make some improvements but the latency thing has always bugged be as well 🙂

The problem is that while wowza is multi threaded, the player only runs in a single thread so all call etc join an event queue and get handled in a fifo fashion.

If the player is running standalone then the queue gets polled every 1 ms and the latency is accurate but if it is running in a browser, this is increased to 15 - 16 ms. This is to do with the active-x or plugin.

The latency reported will be affected by this delay and could be up to 15ms too long. If you run the bw checker locally then the latency should be around 0 - 1ms but it is reported up to 15ms.

This bit of actionscript demonstrates this. First run it in a standalone player and then in the browser. You will need a debug player with flashlog.txt enabled to be able to see the traces.

```auto
var time:Date;
var timer:Number = 0;
var lastTime:Number = 0;
function counter() {
	time = new Date();
	trace(String(time.getTime() - lastTime));
	lastTime = time.getTime();
}
timer = setInterval(counter, 1);

```

The problem is I haven’t found a way to distinguish the difference between the real latency and the delay in the event queue.

Around line 153 in the code, is the first call to the client. This is an empty packet which basically just wakes up the client. I found in testing that the first call always took a long time.

In FirstResult.onResult, the first real packet is sent to the client. This one measures the round trip latency and is what is used to make the latency calculations.

Next, it sends random packets until bwCheckMaxLoops or bwCheckMaxTime is exceeded.

The actual latency figure is used to subtract the calculated latency from the total time so that a more accurate time value can be obtained. That is why it is multiplied by the number of loops.

In order to get accurate figures, you probably need to increase the packet size and reduce the loop count.

Possibly a more accurate way to calculate the latency would be to do it from the client side as the event queue delay is known and could be subtracted from the actual latency value. The reason I haven’t done this is it would require a custom call on the client.

---

<div class="post-metadata">

**Author:** ![Roger\_Littin](https://avatars.discourse-cdn.com/v4/letter/r/d26b3c/32.png) [@Roger\_Littin](https://community.wowza.com/u/Roger_Littin)\
**Post date:** [December 14, 2009, 4:48pm UTC](https://community.wowza.com/t/dynamic-bandwidth-detection-bwcheck/73/25 "2009-12-14T16:48:38Z")

</div>

I am not sure if you are, but it is not wise to run the bw checker while the server is sending an actual stream to the client. The reason for this is the the bwchecker packets will end up getting queued on the wire along with the video packets and the results will be wildly inaccurate. If you are targeting flash player 10 then there are features built into the player to detect the bandwidth of the running stream.

---

<div class="post-metadata">

**Author:** ![Roger\_Littin](https://avatars.discourse-cdn.com/v4/letter/r/d26b3c/32.png) [@Roger\_Littin](https://community.wowza.com/u/Roger_Littin)\
**Post date:** [December 16, 2009, 7:26pm UTC](https://community.wowza.com/t/dynamic-bandwidth-detection-bwcheck/73/26 "2009-12-16T19:26:13Z")

</div>

Hi Romano,

Have you checked your results using the checker that comes with Wowza? After my last post, I did some other checks and the results I get are normal both in the browser and standalone.

I think it is possible that Adobe have changed the later browser plugins as they now seem to give similar results to the standalone player even though the above test still shows a 15ms polling cycle.

Roger.

---

<div class="post-metadata">

**Author:** ![Alexey\_Aylarov](https://avatars.discourse-cdn.com/v4/letter/a/82dd89/32.png) [@Alexey\_Aylarov](https://community.wowza.com/u/Alexey_Aylarov)\
**Post date:** [April 11, 2007, 12:57pm UTC](https://community.wowza.com/t/dynamic-bandwidth-detection-bwcheck/73/27 "2007-04-11T12:57:05Z")

</div>

I need to measure upload bandwidth to server for setting cam.quality

---

<div class="post-metadata">

**Author:** ![Balint\_Pelhos](https://avatars.discourse-cdn.com/v4/letter/b/c4cdca/32.png) [@Balint\_Pelhos](https://community.wowza.com/u/Balint_Pelhos)\
**Post date:** [March 12, 2008, 4:14pm UTC](https://community.wowza.com/t/dynamic-bandwidth-detection-bwcheck/73/28 "2008-03-12T16:14:34Z")

</div>

Is there any method to calculate the actual bandwidth after the stream has started?

Are there any onStreamFlush event (on the server side) that could be extended?

(I know, that I could use the code of BW checker, but it generates an extra traffic with the measurement which is unnecessary if I have a live/working stream.)

---

<div class="post-metadata">

**Author:** ![Balint\_Pelhos](https://avatars.discourse-cdn.com/v4/letter/b/c4cdca/32.png) [@Balint\_Pelhos](https://community.wowza.com/u/Balint_Pelhos)\
**Post date:** [March 14, 2008, 5:00pm UTC](https://community.wowza.com/t/dynamic-bandwidth-detection-bwcheck/73/29 "2008-03-14T17:00:42Z")

</div>

Not really.

What is the event/method that I should extend with these calculations?

How could I measure time (to get bytes per sec)?

I have read the IMediaStream and IOPerformanceCounter section in Server API Guide but have no idea.

---

<div class="post-metadata">

**Author:** ![Balint\_Pelhos](https://avatars.discourse-cdn.com/v4/letter/b/c4cdca/32.png) [@Balint\_Pelhos](https://community.wowza.com/u/Balint_Pelhos)\
**Post date:** [June 6, 2008, 11:25am UTC](https://community.wowza.com/t/dynamic-bandwidth-detection-bwcheck/73/30 "2008-06-06T11:25:56Z")

</div>

> Take a look at the IOPerformanceCounter interface that is attached the IMediaStream interface.
> 
> …
> 
> Through the IOPerformanceCounter you can monitor the bits that travel in and out of the publishing stream. So if you monitor this over time you can calculate the rate.
> 
> Charlie

Thanks for the tip, now I can query the actual MessageBytes counters of the publishing stream and I’m able to calculate the actual traffic rate of the publisher.

Actually I want to track of lost traffic, but the getMessagesLossBytes counter gives me always 0. (I reproduced an upload limited situation.)

My server side code is:

```auto
public void getStreamStats(IClient client, RequestFunction function, AMFDataList params)
	{
		String streamName = params.getString(PARAM1);
		List streamList = null;
		AMFDataObj streamStatObj = new AMFDataObj();
		IApplicationInstance appInstance = client.getAppInstance();
		MediaStreamMap streams = appInstance.getStreams();
		IMediaStream stream = streams.getStream(streamName);
		IOPerformanceCounter streamStats = stream.getMediaIOPerformance();
		streamStatObj.put("droppedBytes", new AMFDataItem(streamStats.getMessagesLossBytes()));
		streamStatObj.put("outBytes", new AMFDataItem(streamStats.getMessagesInBytes()));
	
		getLogger().debug("getStreamStats for "+streamName+", BytesIn:"+streamStats.getMessagesInBytes()+", BytesOut:"+streamStats.getMessagesOutBytes()+", BytesLoss:"+streamStats.getMessagesLossBytes());
		
		sendResult(client, params, streamStatObj);
	}

```

My goal is to alert the live publishing client/user if the upload bandwidth limit is exceeded.

---

<div class="post-metadata">

**Author:** ![Balint\_Pelhos](https://avatars.discourse-cdn.com/v4/letter/b/c4cdca/32.png) [@Balint\_Pelhos](https://community.wowza.com/u/Balint_Pelhos)\
**Post date:** [June 6, 2008, 2:26pm UTC](https://community.wowza.com/t/dynamic-bandwidth-detection-bwcheck/73/31 "2008-06-06T14:26:17Z")

</div>

> since the throttling is happening on the client side
> 
> Charlie

So then, anybody has Actionscript code to detect if frame dropes happen by publishing?

---

<div class="post-metadata">

**Author:** ![babbage\_charles](https://avatars.discourse-cdn.com/v4/letter/b/b782af/32.png) [@babbage\_charles](https://community.wowza.com/u/babbage_charles)\
**Post date:** [December 25, 2007, 11:50am UTC](https://community.wowza.com/t/dynamic-bandwidth-detection-bwcheck/73/32 "2007-12-25T11:50:50Z")

</div>

hi ,

i am new to Wowza media server…

here live video is coming from client side(flash player using action scripts)

now i want write java code on server side to take that video from client…

please send java code to server side…

and also provide how to compile that one and execute it…

please sir…

thank u.

---

<div class="post-metadata">

**Author:** ![Richard\_Lanham](https://avatars.discourse-cdn.com/v4/letter/r/c68b51/32.png) [@Richard\_Lanham](https://community.wowza.com/u/Richard_Lanham)\
**Post date:** [February 27, 2008, 3:36pm UTC](https://community.wowza.com/t/dynamic-bandwidth-detection-bwcheck/73/33 "2008-02-27T15:36:14Z")

</div>

That trace is coming from netStatusHandler, not onBWCheck:

```auto
function netStatusHandler (e:NetStatusEvent):void{
	trace("Level: "+e.info.level+" Code: "+e.info.code);
	if (e.info.code == "NetConnection.Connect.Success") {
		trace("--- connected to: " + nc.uri);	//this.uri
	}
}

```

“NetConnection.Connect.Success” means it is working.

---

<div class="post-metadata">

**Author:** ![Richard\_Lanham](https://avatars.discourse-cdn.com/v4/letter/r/c68b51/32.png) [@Richard\_Lanham](https://community.wowza.com/u/Richard_Lanham)\
**Post date:** [February 27, 2008, 3:40pm UTC](https://community.wowza.com/t/dynamic-bandwidth-detection-bwcheck/73/34 "2008-02-27T15:40:07Z")

</div>

… also, to get onBWCheck to fire, do this:

```auto
var client:Object = new Object();
client.onBWCheck = onBWCheck;
nc.client = client;

```

---

<div class="post-metadata">

**Author:** ![Richard\_Lanham](https://avatars.discourse-cdn.com/v4/letter/r/c68b51/32.png) [@Richard\_Lanham](https://community.wowza.com/u/Richard_Lanham)\
**Post date:** [January 29, 2009, 10:22am UTC](https://community.wowza.com/t/dynamic-bandwidth-detection-bwcheck/73/35 "2009-01-29T10:22:41Z")

</div>

That’s what I get too, it’s normal. You can make a new connection every time a new video plays, which is what JW Player does.

Richard

---

<div class="post-metadata">

**Author:** ![Richard\_Lanham](https://avatars.discourse-cdn.com/v4/letter/r/c68b51/32.png) [@Richard\_Lanham](https://community.wowza.com/u/Richard_Lanham)\
**Post date:** [January 29, 2009, 11:48am UTC](https://community.wowza.com/t/dynamic-bandwidth-detection-bwcheck/73/36 "2009-01-29T11:48:17Z")

</div>

This bandwidth detection, the one in the first post of this thread, measures bandwidth from server to client. There is another version later in this thread that detects bandwidth from client to server. I’m not sure but maybe that one is more consistent.

But I think the reason that bandwidth is calculated server to client is because that is Wowza’s point of view.

Richard

---

<div class="post-metadata">

**Author:** ![Richard\_Lanham](https://avatars.discourse-cdn.com/v4/letter/r/c68b51/32.png) [@Richard\_Lanham](https://community.wowza.com/u/Richard_Lanham)\
**Post date:** [February 3, 2009, 8:13pm UTC](https://community.wowza.com/t/dynamic-bandwidth-detection-bwcheck/73/37 "2009-02-03T20:13:06Z")

</div>

Have you traced the value of detected\_bw? Does bandwidthVer have default of “\_750”?

Is this up somewhere?

If you’re tester has debug player you can use this method to get trace output from their instance of your player:

[http://blog.flexexamples.com/2007/08/26/debugging-flex-applications-with-mmcfg-and-flashlogtxt/](http://blog.flexexamples.com/2007/08/26/debugging-flex-applications-with-mmcfg-and-flashlogtxt/)

Richard (another one)

richard.lanham@gmail.com

---

<div class="post-metadata">

**Author:** ![Richard\_Lanham](https://avatars.discourse-cdn.com/v4/letter/r/c68b51/32.png) [@Richard\_Lanham](https://community.wowza.com/u/Richard_Lanham)\
**Post date:** [February 4, 2009, 2:08pm UTC](https://community.wowza.com/t/dynamic-bandwidth-detection-bwcheck/73/38 "2009-02-04T14:08:02Z")

</div>

It would be set somewhere above the snip you posted.

But what I was getting at really was whether detect\_bw might be null and therefore not meet any of those tests, and so the default value of bandwidthVer is used.

In other words, are you sure the bandwidth checking process has really happened?

Richard

---

<div class="post-metadata">

**Author:** ![Richard\_Lanham](https://avatars.discourse-cdn.com/v4/letter/r/c68b51/32.png) [@Richard\_Lanham](https://community.wowza.com/u/Richard_Lanham)\
**Post date:** [February 4, 2009, 2:30pm UTC](https://community.wowza.com/t/dynamic-bandwidth-detection-bwcheck/73/39 "2009-02-04T14:30:10Z")

</div>

Okay, it’s the example. mostly at least. So you are looking for the trace output of the line below specifically “kbitDown”:

```auto
trace("onBWDone: kbitDown:"+kbitDown+" deltaDown:"+deltaDown+" deltaTime:"+deltaTime+" latency:"+latency);

```

Do you see this trace, and what is it if you do?

There is a server-side to this too, you have to have the right section in the Application.xml at [wowza-install-dir]/conf/video/Application.xml

Also, remember to take out the FLVPlayback Module that is in the original Application.xml. You don’t need that when using the bw check module.

Richard

---

<div class="post-metadata">

**Author:** ![Richard\_Lanham](https://avatars.discourse-cdn.com/v4/letter/r/c68b51/32.png) [@Richard\_Lanham](https://community.wowza.com/u/Richard_Lanham)\
**Post date:** [February 4, 2009, 5:01pm UTC](https://community.wowza.com/t/dynamic-bandwidth-detection-bwcheck/73/40 "2009-02-04T17:01:44Z")

</div>

That looks perfect. Is it solved?

Richard

[Previous page](https://community.wowza.com/t/dynamic-bandwidth-detection-bwcheck/73.md?page=1)

[Next page](https://community.wowza.com/t/dynamic-bandwidth-detection-bwcheck/73.md?page=3)
