Possible fix for incorrect fps and zoom values

Forum for questions and support relating to the 1.24.x releases only.
Locked
genanr
Posts: 9
Joined: Tue Apr 08, 2008 9:49 pm

Possible fix for incorrect fps and zoom values

Post 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
User avatar
zoneminder
Site Admin
Posts: 5215
Joined: Wed Jul 09, 2003 2:07 pm
Location: Bristol, UK
Contact:

Post 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?
Phil
genanr
Posts: 9
Joined: Tue Apr 08, 2008 9:49 pm

Post 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
ris2t
Posts: 43
Joined: Thu Jan 22, 2009 8:44 am

Post 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
genanr
Posts: 9
Joined: Tue Apr 08, 2008 9:49 pm

Post 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
dbj
Posts: 1
Joined: Fri Feb 27, 2009 1:33 pm

Post 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
User avatar
zoneminder
Site Admin
Posts: 5215
Joined: Wed Jul 09, 2003 2:07 pm
Location: Bristol, UK
Contact:

Post 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?
Phil
genanr
Posts: 9
Joined: Tue Apr 08, 2008 9:49 pm

Post 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
User avatar
zoneminder
Site Admin
Posts: 5215
Joined: Wed Jul 09, 2003 2:07 pm
Location: Bristol, UK
Contact:

Post 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.
Phil
genanr
Posts: 9
Joined: Tue Apr 08, 2008 9:49 pm

Post 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
User avatar
zoneminder
Site Admin
Posts: 5215
Joined: Wed Jul 09, 2003 2:07 pm
Location: Bristol, UK
Contact:

Post 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.
Phil
User avatar
cordel
Posts: 5210
Joined: Fri Mar 05, 2004 4:47 pm
Location: /USA/Washington/Seattle

Post by cordel »

I have a 64bit VM here ready to go. I'll PM you the info.
User avatar
zoneminder
Site Admin
Posts: 5215
Joined: Wed Jul 09, 2003 2:07 pm
Location: Bristol, UK
Contact:

Post 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.
Phil
User avatar
zoneminder
Site Admin
Posts: 5215
Joined: Wed Jul 09, 2003 2:07 pm
Location: Bristol, UK
Contact:

Post by zoneminder »

Should be fixed in svn now.
Phil
bossi
Posts: 1
Joined: Sat Aug 29, 2009 5:11 pm
Location: Curitiba, Parana, Brasil
Contact:

Re: Possible fix for incorrect fps and zoom values

Post 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.
Locked