bit rate analyzing problem - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

bit rate analyzing problem

rahavrrahavr Posts: 2Member
hello to everyone.

im doing a project in c++ that is aim is to analyze the bit rate that recived from video applications (like vlc , media player ,etc...).
i have a big problem with it but first i will present the code.
in order to do that i build a generator of packets that will send me simulated packets to the ip i enter as arguments. the generator look like that :[red] (the given argument is :
udp_serverwin32Debugstreamer.exe 127.0.0.1 1234 300
the arcv[0] is the path for the exe file , the [1] is the ip , the
[2] is the port and the [3] is the requested bit rate in KB/sec)[/red]

[code]
#define PACKET_SIZE 1 //KByte
int main(int argc, char *argv[])
{
if (argc < 4)
{
printf("streamer
");
return 1;
}
int port = atoi(argv[2]);
int rate = atoi(argv[3]); // KByte/sec
double RequestSendTime;
char buff[(PACKET_SIZE*1000)]; //KByte
memset(buff,'R',(PACKET_SIZE*1000)); //KByte

try
{
UDPSocket sock;
printf("openning client on %s:%d
",argv[1],port);
RequestSendTime=PACKET_SIZE/double(rate);
while(1)
{
[green] sock.sendTo(buff,sizeof(buff),argv[1],port); [/green]
Sleep ((DWORD(RequestSendTime*1000))); //Sleep gets msec
printf("generate one packet every %2.5f sec
",RequestSendTime);
}
}
catch (SocketException &e)
{
cerr << e.what() << endl;
exit(1);
}
return 1;
}
[/code]

the green sendTo function uses the sendto function and look like that :
[code]
void UDPSocket::sendTo(const void *buffer, int bufferLen,
const string &foreignAddress, unsigned short foreignPort)
throw(SocketException) {
sockaddr_in destAddr;
int test;
fillAddr(foreignAddress, foreignPort, destAddr);

// Write out the whole buffer as a single message.
test=sendto(sockDesc,(raw_type *)buffer,bufferLen,0,(sockaddr *) &destAddr, sizeof(destAddr));
if (test != bufferLen) {
throw SocketException("Send failed (sendto())", true);
}
}
[/code]

so far for the sending side. now, to the reciever side.
the reciever side the gets the ip that he should get from the packets (called SourceAddress), also im using there a mechanisim that calls profiler that measure the time for the recieving operation . the idea is that i sum the packets that get from the source and the time that it takes to get it, every one sec i print the bit rate which is calculate by the sum of the packets divide by the time. and it looks like that :

[code]
void Analyze::BitRate()
{
double TheTime;
int len;
profile.start();

while(1)
{ // Run forever
// Block until receive message from a client

[green]len = sock.recvFrom(buff,sizeof(buff),
SourceAddress,SourcePort); // Byte [/green]

profile.finish();
TheTime=(double)profile.get_duration_time(); //sec
total_size +=len; // in Bytes

/* print statistics */
if (TheTime >= SLEEP_PRINT)
{
//divide the size for KB(time is in sec)
printf("recive bit rate is: %4.1f KByte/sec
",
((total_size) )/(TheTime*1000));

total_size = 0;
profile.clear();
}
profile.start();
}
}
[/code]

the recvFrom function in green uses the recvfrom function and look like that :

[code]
int UDPSocket::recvFrom(void *buffer, int bufferLen, string &sourceAddress,
unsigned short &sourcePort) throw(SocketException) {

sockaddr_in clntAddr;
socklen_t addrLen = sizeof(clntAddr);
int rtn;
if ((rtn = recvfrom(sockDesc, (raw_type *) buffer, bufferLen, 0,
(sockaddr *) &clntAddr, (socklen_t *) &addrLen)) < 0) {
throw SocketException("Send failed (sendto())", true);
}
sourceAddress = inet_ntoa(clntAddr.sin_addr);
sourcePort = ntohs(clntAddr.sin_port);

return rtn;
}
[/code]

the profiler code:

[code]
//class CProfiler implement time measuring functionality
class CProfiler{
clock_t m_start; // measuring start clock
clock_t m_finish;// measuring end clock
double m_duration;// accumulated clocks measured
public:

CProfiler(){ m_duration = 0;}
void start(){ m_start = clock();}
void finish(){m_duration += (clock() - m_start);}
double get_duration(){return m_duration;}
double get_duration_time(){
return ((double)m_duration) / CLOCKS_PER_SEC;}
void print_duration(){
printf(" duration: %2.1f seconds
",get_duration_time());
}
void clear(){ m_duration = 0;}
};// end class CProfiler

[/code]

[b]now i will get to my problem:[/b]
[size=4]i'm not getting the bit rate that i requested in the generator!!![/size]

i checked everyting. i maked sure that the units are currects(they are), that there isnt packet lost (there isnt - i entered serial numbers to the packets that was send and i got all the numbers in the reciever ) and lots more checking.
what i get is only part of the bit rate according to the following table:
[code]
received rate requested rate
OK 0-80
79 80-83
85/6 84-90
92/3 91-100
102/103 101-110/111
113/114 112-125
128 126-142
146/7 143-166
170/1 197-200
204/205 201-250
255/256 251-333
341 334-500
511 501-1000
3500-4300 1001-3000

[/code]

if someone can help me understarnd why is there a difference i will be very very very happy.
also if someone wants me to send him the code for trying this i will be more than happy to do so.
send me email to [email protected]

thank u all.

Comments

  • rahavrrahavr Posts: 2Member
    [size=5] Please Help Me... [/size]



    : hello to everyone.
    :
    : im doing a project in c++ that is aim is to analyze the bit rate that recived from video applications (like vlc , media player ,etc...).
    : i have a big problem with it but first i will present the code.
    : in order to do that i build a generator of packets that will send me simulated packets to the ip i enter as arguments. the generator look like that :[red] (the given argument is :
    : udp_serverwin32Debugstreamer.exe 127.0.0.1 1234 300
    : the arcv[0] is the path for the exe file , the [1] is the ip , the
    : [2] is the port and the [3] is the requested bit rate in KB/sec)[/red]
    :
    : [code]
    : #define PACKET_SIZE 1 //KByte
    : int main(int argc, char *argv[])
    : {
    : if (argc < 4)
    : {
    : printf("streamer
    ");
    : return 1;
    : }
    : int port = atoi(argv[2]);
    : int rate = atoi(argv[3]); // KByte/sec
    : double RequestSendTime;
    : char buff[(PACKET_SIZE*1000)]; //KByte
    : memset(buff,'R',(PACKET_SIZE*1000)); //KByte
    :
    : try
    : {
    : UDPSocket sock;
    : printf("openning client on %s:%d
    ",argv[1],port);
    : RequestSendTime=PACKET_SIZE/double(rate);
    : while(1)
    : {
    : [green] sock.sendTo(buff,sizeof(buff),argv[1],port); [/green]
    : Sleep ((DWORD(RequestSendTime*1000))); //Sleep gets msec
    : printf("generate one packet every %2.5f sec
    ",RequestSendTime);
    : }
    : }
    : catch (SocketException &e)
    : {
    : cerr << e.what() << endl;
    : exit(1);
    : }
    : return 1;
    : }
    : [/code]
    :
    : the green sendTo function uses the sendto function and look like that :
    : [code]
    : void UDPSocket::sendTo(const void *buffer, int bufferLen,
    : const string &foreignAddress, unsigned short foreignPort)
    : throw(SocketException) {
    : sockaddr_in destAddr;
    : int test;
    : fillAddr(foreignAddress, foreignPort, destAddr);
    :
    : // Write out the whole buffer as a single message.
    : test=sendto(sockDesc,(raw_type *)buffer,bufferLen,0,(sockaddr *) &destAddr, sizeof(destAddr));
    : if (test != bufferLen) {
    : throw SocketException("Send failed (sendto())", true);
    : }
    : }
    : [/code]
    :
    : so far for the sending side. now, to the reciever side.
    : the reciever side the gets the ip that he should get from the packets (called SourceAddress), also im using there a mechanisim that calls profiler that measure the time for the recieving operation . the idea is that i sum the packets that get from the source and the time that it takes to get it, every one sec i print the bit rate which is calculate by the sum of the packets divide by the time. and it looks like that :
    :
    : [code]
    : void Analyze::BitRate()
    : {
    : double TheTime;
    : int len;
    : profile.start();
    :
    : while(1)
    : { // Run forever
    : // Block until receive message from a client
    :
    : [green]len = sock.recvFrom(buff,sizeof(buff),
    : SourceAddress,SourcePort); // Byte [/green]
    :
    : profile.finish();
    : TheTime=(double)profile.get_duration_time(); //sec
    : total_size +=len; // in Bytes
    :
    : /* print statistics */
    : if (TheTime >= SLEEP_PRINT)
    : {
    : //divide the size for KB(time is in sec)
    : printf("recive bit rate is: %4.1f KByte/sec
    ",
    : ((total_size) )/(TheTime*1000));
    :
    : total_size = 0;
    : profile.clear();
    : }
    : profile.start();
    : }
    : }
    : [/code]
    :
    : the recvFrom function in green uses the recvfrom function and look like that :
    :
    : [code]
    : int UDPSocket::recvFrom(void *buffer, int bufferLen, string &sourceAddress,
    : unsigned short &sourcePort) throw(SocketException) {
    :
    : sockaddr_in clntAddr;
    : socklen_t addrLen = sizeof(clntAddr);
    : int rtn;
    : if ((rtn = recvfrom(sockDesc, (raw_type *) buffer, bufferLen, 0,
    : (sockaddr *) &clntAddr, (socklen_t *) &addrLen)) < 0) {
    : throw SocketException("Send failed (sendto())", true);
    : }
    : sourceAddress = inet_ntoa(clntAddr.sin_addr);
    : sourcePort = ntohs(clntAddr.sin_port);
    :
    : return rtn;
    : }
    : [/code]
    :
    : the profiler code:
    :
    : [code]
    : //class CProfiler implement time measuring functionality
    : class CProfiler{
    : clock_t m_start; // measuring start clock
    : clock_t m_finish;// measuring end clock
    : double m_duration;// accumulated clocks measured
    : public:
    :
    : CProfiler(){ m_duration = 0;}
    : void start(){ m_start = clock();}
    : void finish(){m_duration += (clock() - m_start);}
    : double get_duration(){return m_duration;}
    : double get_duration_time(){
    : return ((double)m_duration) / CLOCKS_PER_SEC;}
    : void print_duration(){
    : printf(" duration: %2.1f seconds
    ",get_duration_time());
    : }
    : void clear(){ m_duration = 0;}
    : };// end class CProfiler
    :
    : [/code]
    :
    : [b]now i will get to my problem:[/b]
    : [size=4]i'm not getting the bit rate that i requested in the generator!!![/size]
    :
    : i checked everyting. i maked sure that the units are currects(they are), that there isnt packet lost (there isnt - i entered serial numbers to the packets that was send and i got all the numbers in the reciever ) and lots more checking.
    : what i get is only part of the bit rate according to the following table:
    : [code]
    : received rate requested rate
    : OK 0-80
    : 79 80-83
    : 85/6 84-90
    : 92/3 91-100
    : 102/103 101-110/111
    : 113/114 112-125
    : 128 126-142
    : 146/7 143-166
    : 170/1 197-200
    : 204/205 201-250
    : 255/256 251-333
    : 341 334-500
    : 511 501-1000
    : 3500-4300 1001-3000
    :
    : [/code]
    :
    : if someone can help me understarnd why is there a difference i will be very very very happy.
    : also if someone wants me to send him the code for trying this i will be more than happy to do so.
    : send me email to [email protected]
    :
    : thank u all.
    :
    :

Sign In or Register to comment.