[icecast-dev] net/sock.c question
Mihai RUSU
dizzy at roedu.net
Wed Feb 11 08:21:04 PST 2004
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi
I have started to add bandwidth <limit> option to icecast. My ideea is to
compute the current bandwidth by estimation on each sock_write*() call.
Something like this:
1. initially we set kbps = 0, kbps_time = now and kbps_bytes = 0
2. after some time, a sock_write*() function is called which in turn calls
sock_kbps_update(nobytes); sock_kbps_update fetches current timestamp,
adds nobytes to kbps_bytes then:
2.1 if the time difference between now and kbps_time is smaller than
ESTIMATION_INTERVAL (which I think a value of 5 seconds should do) then we
go back to 2
2.2 if the time difference is greater or equal to ESTIMATION_INTERVAL then
we recompute the current kbps by this formula,
kbps = (int)(((double)kbps_bytes / (now - kbps_time)) * 8 / 1000)
then we store kbps_time = now and reset kbps_bytes = 0 . then go back to 2
I think this is a good solution because all socket writes are done with
sock_write*() so we catch them all this way. Problem is that I think I
need a mutex on this values (kbps, kbps_time, kbps_bytes) and it seems
sock.c didnt use any yet. Whould it be a problem to use one ? (and include
thread/thread.h ?)
Any other sugestions welcomed. Thanks!
- --
Mihai RUSU Email: dizzy at roedu.net
GPG : http://dizzy.roedu.net/dizzy-gpg.txt WWW: http://dizzy.roedu.net
"Linux is obsolete" -- AST
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)
iD8DBQFAKlZxPZzOzrZY/1QRAjIlAJ0aEUnnZMO1zqupGSYFZxkF7QdDBACcDWLp
FZyelTkdoGpp2GBfUyBGBPY=
=440c
-----END PGP SIGNATURE-----
--- >8 ----
List archives: http://www.xiph.org/archives/
icecast project homepage: http://www.icecast.org/
To unsubscribe from this list, send a message to 'icecast-dev-request at xiph.org'
containing only the word 'unsubscribe' in the body. No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.
More information about the Icecast-dev
mailing list