Page 1 of 1

Possible fix for incorrect fps and zoom values

Posted: Wed Feb 25, 2009 4:21 pm
by genanr
I was having a problem with incorrect fps and zoom values in live and montage views. I found that the following change seems to fix the problem.

Line 94 in web/ajax/stream.php reads something like:

$data = unpack("ltype/imonitor/dfps/istate ....

I changed it to:

$data = unpack("ltype/imonitor/C/C/C/C/dfps/istate ...

And now the fps and zoom numbers seem fine.

It's best to change the one in web/ajax under the zm directory and run make install again, rather the just changing the one that the web server is using because next time you install it will overwrite the one in the web server directory.

Hope this helps,

Andy

Posted: Thu Feb 26, 2009 9:09 am
by zoneminder
Thanks for posting this. The FOS etc appear to work in most cases so I am trying to figure out what might be different for you. Are you on a 64 bit system by any chance?

Posted: Thu Feb 26, 2009 5:33 pm
by genanr
Yes, I am on a 64-bit system.

I do think the problem is related to 64-bit and possibly the version of gcc/g++ that is being used.

Andy

Posted: Thu Feb 26, 2009 6:53 pm
by ris2t
genanr wrote: I do think the problem is related to 64-bit and possibly the version of gcc/g++ that is being used.
I'm also experiencing problems with the fps and zoom values. Here are my system values for comparision. Yet to try the fix.

Linux 2.6.27-12-generic #1 SMP x86_64 GNU/Linux
gcc.real (Ubuntu 4.3.2-1ubuntu12) 4.3.2

Posted: Thu Feb 26, 2009 8:42 pm
by genanr
Here is my info:

Linux 2.6.28.7 #1 SMP x86_64 GNU/Linux

Debian 5.0
gcc 4.3.3-3

Andy

Posted: Fri Feb 27, 2009 1:37 pm
by dbj
Thank you for that fix, that was driving me nuts how it would shift the images off the window when the fps went to a crazy number. I am on a 64bit system and that fix did work for me.

CentOS release 5.2 (Final)
2.6.18-92.el5
gcc-4.1.2-42.el5

Posted: Sun Mar 01, 2009 9:05 pm
by zoneminder
This is a little bit odd though. As the field is defined as an 'int' on both the sending and receiving side it appears to be mismatched. Do you know on your system(s) if a g++ int is 64 or 32 bits long?

Posted: Mon Mar 02, 2009 12:21 am
by genanr
Right, and int is in fact 4 bytes on my 64 bit system. I believe the real problem is is how g++ deals with structures, here is a little test program I wrote to figure out what really is going on.

#include <stdio>

#define FIELD_OFFSET(strptr,field) ((char*)&((strptr)->field)-(char*)strptr)

main()
{

struct {
int id;
double fps;
int state;
int buffer_level;
bool delayed;
bool paused;
int rate;
double delay;
int zoom;
bool enabled;
bool forced;
} __attribute__((packed)) status_data_packed;

struct {
int id;
double fps;
int state;
int buffer_level;
bool delayed;
bool paused;
int rate;
double delay;
int zoom;
bool enabled;
bool forced;
} status_data;

printf("sizeof(int) : %d sizeof(bool) : %d\n",sizeof(int),sizeof(bool));
printf("sizeof(status_data_packed) : %d\n",sizeof(status_data_packed));
printf("sizeof(status_data) : %d\n",sizeof(status_data));

printf("offset(fps) with __attribute__((packed)) %d\n" ,FIELD_OFFSET(&status_data_packed,fps));
printf("offset(fps) : %d\n",FIELD_OFFSET(&status_data,fps));
}

My results:

sizeof(int) : 4 sizeof(bool) : 1
sizeof(status_data_packed) : 40
sizeof(status_data) : 48
offset(fps) with __attribute__((packed)) : 4
offset(fps) : 8

This cause of the problem makes sense to me.

I'll try the packed attribute on Monday in ZoneMinder.

Andy

Posted: Mon Mar 02, 2009 11:19 am
by zoneminder
Ah, ok, thanks for that. It may well be a packing issue and by default it is aligning on 8 byte boundaries rather than 4. That makes some sense.

I am a little wary about using g++ attributes as they aren't standard so I will see if there is a more generic way round this.

Posted: Mon Mar 02, 2009 4:30 pm
by genanr
Using the packed attribute fixed the fps problem, but I had to take out the two /C after the paused field that were already in the SVN code to get zoom right.

This is my current line:

unpack( "ltype/imonitor/dfps/istate/ilevel/Cdelayed/Cpaused/irate/ddelay/izoom/Cenabled/Cforced")


Is this problem specific to gcc compilers?


Andy

Posted: Tue Mar 03, 2009 9:22 pm
by zoneminder
I don't know if it is specific to GNU compilers , probably not. It is an issue getting the php and c++ elements looking for things in the same place. I will post a proper solution in the next couple of days though I don't have a 64 bit system here. I will try and set up a 64 bit VM to play with.

Posted: Wed Mar 04, 2009 4:27 am
by cordel
I have a 64bit VM here ready to go. I'll PM you the info.

Posted: Sun Mar 08, 2009 11:49 am
by zoneminder
No worries. It's taken me the best part of a week to set up with one thing and another but I now have a better VM environment that I can use and have put up a Centos 5.2 64 bit VM and have got a ZM build on there so I will get cracking on this one now.

Posted: Sun Mar 08, 2009 8:55 pm
by zoneminder
Should be fixed in svn now.

Re: Possible fix for incorrect fps and zoom values

Posted: Sat Aug 29, 2009 7:16 pm
by bossi
genanr wrote:I was having a problem with incorrect fps and zoom values in live and montage views. I found that the following change seems to fix the problem.

Line 94 in web/ajax/stream.php reads something like:

$data = unpack("ltype/imonitor/dfps/istate ....

I changed it to:

$data = unpack("ltype/imonitor/C/C/C/C/dfps/istate ...

And now the fps and zoom numbers seem fine.

It's best to change the one in web/ajax under the zm directory and run make install again, rather the just changing the one that the web server is using because next time you install it will overwrite the one in the web server directory.

Hope this helps,

Andy
Yap! works perferct now! Tanks Man.