Page 2 of 7

Posted: Fri Feb 04, 2011 9:54 am
by zoneminder
linuxsense wrote:This went pretty smooth for me but I am having an issue I cant sort. I upgraded my db from 1.24.2 but when viewing an event I get the following error when clicking the 'video' link to generate a video:

Code: Select all

[Thu Feb 03 14:25:33 2011] [error] [client 192.168.1.2] SQL-ERROR(15AE0F): Unknown column 'undefined' in 'where clause', referer: http://192.168.1.6/zm/index.php?view=event&eid=749583&filter[terms][0][attr]=DateTime&filter[terms][0][op]=%3E%3D&filter[terms][0][val]=-1+hour&filter[terms][1][cnj]=and&filter[terms][1][attr]=MonitorId&filter[terms][1][op]=%3D&filter[terms][1][val]=3&sort_field=StartTime&sort_asc=1&page=1
Anyone have any idea on the fix?
You should have a line just above the one you have included which gives the actual SQL statement that was being executed (it will be tagged with 15AE0F also). It would be helpful to see that as well if possible.

Posted: Fri Feb 04, 2011 9:55 am
by zoneminder
PacoLM wrote:
I have tried to install manually the perl module but:
I am unable to check at the moment but is the module not available as a Ubuntu package?

Posted: Fri Feb 04, 2011 11:31 am
by insippo
apt-cache search perl-module
libcgi-pm-perl - Simple Common Gateway Interface Class
libfile-path-perl - Perl module for creating or removing directory trees
libfile-temp-perl - Perl module to create a temporary file safely
libnet-smtpauth-perl - Perl module that provides SMTP authentication (Net::SMTP_auth)
libthread-queue-perl - Perl module for thread-safe queues
openser-perl-modules - Perl extensions and database driver for OpenSER
perl-base - minimal Perl system
perl-modules - Core Perl modules

Posted: Fri Feb 04, 2011 5:56 pm
by linuxsense
zoneminder wrote:
linuxsense wrote:This went pretty smooth for me but I am having an issue I cant sort. I upgraded my db from 1.24.2 but when viewing an event I get the following error when clicking the 'video' link to generate a video:

Code: Select all

[Thu Feb 03 14:25:33 2011] [error] [client 192.168.1.2] SQL-ERROR(15AE0F): Unknown column 'undefined' in 'where clause', referer: http://192.168.1.6/zm/index.php?view=event&eid=749583&filter[terms][0][attr]=DateTime&filter[terms][0][op]=%3E%3D&filter[terms][0][val]=-1+hour&filter[terms][1][cnj]=and&filter[terms][1][attr]=MonitorId&filter[terms][1][op]=%3D&filter[terms][1][val]=3&sort_field=StartTime&sort_asc=1&page=1
Anyone have any idea on the fix?
You should have a line just above the one you have included which gives the actual SQL statement that was being executed (it will be tagged with 15AE0F also). It would be helpful to see that as well if possible.
Here it is:

Code: Select all

[Thu Feb 03 14:25:33 2011] [error] [client 192.168.1.2] SQL-ERROR(15AE0F): select E.*,M.Name as MonitorName,M.Width,M.Height,M.DefaultRate,M.DefaultScale from Events as E inner join Monitors as M on E.MonitorId = M.Id where E.Id = undefined, referer: http://192.168.1.6/zm/index.php?view=event&eid=749583&filter[terms][0][attr]=DateTime&filter[terms][0][op]=%3E%3D&filter[terms][0][val]=-1+hour&filter[terms][1][cnj]=and&filter[terms][1][attr]=MonitorId&filter[terms][1][op]=%3D&filter[terms][1][val]=3&sort_field=StartTime&sort_asc=1&page=1
Thanks much for looking into this.

Some fixes

Posted: Fri Feb 04, 2011 7:40 pm
by mastertheknife
Hi,

I have collected some fixes of mine that i would like to make it into 1.24.3.
I'm not sure what would be the best way to upload them. I simply uploaded my git log together with the diffs, in order to explain what each change fixes:
http://pastebin.com/JWUMpQ1e

Also, i am working on fixing additional bugs at the moment and i hope you will add them into 1.24.3 as well.

mastertheknife.

Posted: Sat Feb 05, 2011 10:22 am
by insippo
either way it could, the events-cam1-zone4 such events would be written in column events

column events
event-1234-cam1-zone3

Posted: Sat Feb 05, 2011 1:51 pm
by mastertheknife
Hi,

Some more fixes that i would like to make it into 1.24.3:
http://pastebin.com/2GPRrQX0

Thank you,
mastertheknife :D

Posted: Sat Feb 05, 2011 6:54 pm
by insippo
insippo wrote:either way it could, the events-cam1-zone4 such events would be written in column events


Sample
column events
event-1234-cam1-zone3

Posted: Sun Feb 06, 2011 2:40 pm
by zoneminder
insippo wrote:
insippo wrote:either way it could, the events-cam1-zone4 such events would be written in column events


Sample
column events
event-1234-cam1-zone3
I'm not sure I really understand what you are discussing here.

Posted: Sun Feb 06, 2011 2:41 pm
by zoneminder
mastertheknife wrote:Hi,

Some more fixes that i would like to make it into 1.24.3:
http://pastebin.com/2GPRrQX0

Thank you,
mastertheknife :D
Thanks. I will go through these and the previous set you provided.

Re: Some fixes

Posted: Sun Feb 06, 2011 4:26 pm
by zoneminder
mastertheknife wrote:Hi,

I have collected some fixes of mine that i would like to make it into 1.24.3.
I'm not sure what would be the best way to upload them. I simply uploaded my git log together with the diffs, in order to explain what each change fixes:
http://pastebin.com/JWUMpQ1e

Also, i am working on fixing additional bugs at the moment and i hope you will add them into 1.24.3 as well.

mastertheknife.
I have been going through these and most are spot on. I am considering what to do about the final one, the streamScale one, as just deleting the line seems to a bit of a blunt object. The only other ones I have some doubts about are the first two which are to do with freeing of ffmpeg structures.

Your first fix says

Code: Select all

#
diff --git a/src/zm_ffmpeg_camera.cpp b/src/zm_ffmpeg_camera.cpp
#index 5015269..9323f15 100644
#--- a/src/zm_ffmpeg_camera.cpp
#+++ b/src/zm_ffmpeg_camera.cpp
#@@ -43,13 +43,13 @@ FfmpegCamera::FfmpegCamera( int p_id, const std::string &p_path, int p_width, in
# 
# FfmpegCamera::~FfmpegCamera()
# {
#-    av_free( mFrame );
#-    av_free( mRawFrame );
#+    av_freep( mFrame );
#+    av_freep( mRawFrame );
#     
#     avcodec_close( mCodecContext );
#-    av_free( mCodecContext );
#+    mCodecContext = NULL;
#     av_close_input_file( mFormatContext );
#-    av_free( mFormatContext );
#+    mFormatContext = NULL;
# 
#        if ( capture )
#        {
In other words you are replacing some av_free calls with av_freep, presumably in order to also zero the pointer. However as far as I can tell, av_freep should be passed a pointer to a pointer, in other words the address of the pointer. If you just pass the pointer in then bad things will probably happen.

Also I think you are suggesting that avcodec_close and av_close_input_file both free their respective passed in contexts. Looking at the code for ffmpeg I don't see any evidence of that.

I may have misunderstood your intentions with these changes so maybe you can elaborate.

Thanks.

Posted: Sun Feb 06, 2011 5:35 pm
by jnmacd
linuxsense and developers,

This seems to happen only when using Chrome. Hope this helps to track down the problem.
linuxsense wrote:
zoneminder wrote:
linuxsense wrote:This went pretty smooth for me but I am having an issue I cant sort. I upgraded my db from 1.24.2 but when viewing an event I get the following error when clicking the 'video' link to generate a video:

Code: Select all

[Thu Feb 03 14:25:33 2011] [error] [client 192.168.1.2] SQL-ERROR(15AE0F): Unknown column 'undefined' in 'where clause', referer: http://192.168.1.6/zm/index.php?view=event&eid=749583&filter[terms][0][attr]=DateTime&filter[terms][0][op]=%3E%3D&filter[terms][0][val]=-1+hour&filter[terms][1][cnj]=and&filter[terms][1][attr]=MonitorId&filter[terms][1][op]=%3D&filter[terms][1][val]=3&sort_field=StartTime&sort_asc=1&page=1
Anyone have any idea on the fix?
You should have a line just above the one you have included which gives the actual SQL statement that was being executed (it will be tagged with 15AE0F also). It would be helpful to see that as well if possible.
Here it is:

Code: Select all

[Thu Feb 03 14:25:33 2011] [error] [client 192.168.1.2] SQL-ERROR(15AE0F): select E.*,M.Name as MonitorName,M.Width,M.Height,M.DefaultRate,M.DefaultScale from Events as E inner join Monitors as M on E.MonitorId = M.Id where E.Id = undefined, referer: http://192.168.1.6/zm/index.php?view=event&eid=749583&filter[terms][0][attr]=DateTime&filter[terms][0][op]=%3E%3D&filter[terms][0][val]=-1+hour&filter[terms][1][cnj]=and&filter[terms][1][attr]=MonitorId&filter[terms][1][op]=%3D&filter[terms][1][val]=3&sort_field=StartTime&sort_asc=1&page=1
Thanks much for looking into this.

Posted: Sun Feb 06, 2011 7:01 pm
by zoneminder
Thanks. I think I have tracked this down to the fact that Chrome does not like variables named 'event' as I guess it clashes with actual javascript events. I think I have fixed this and will check it in later this evening if it proves not to have broken anything else.

I have been doing quite a bit of testing with Chrome today and it's not the best in the field streamwise. It appears to have a bug with multipart jpeg streams in that it will display the stream but nothing else on the page so I have had to make it fallback to updated stills for the live streams.

Posted: Sun Feb 06, 2011 8:46 pm
by mastertheknife
Hi Phil,
Thank you for adding the fixes and for your response :D
zoneminder wrote: I have been going through these and most are spot on. I am considering what to do about the final one, the streamScale one, as just deleting the line seems to a bit of a blunt object. The only other ones I have some doubts about are the first two which are to do with freeing of ffmpeg structures.

In other words you are replacing some av_free calls with av_freep, presumably in order to also zero the pointer. However as far as I can tell, av_freep should be passed a pointer to a pointer, in other words the address of the pointer. If you just pass the pointer in then bad things will probably happen.

Also I think you are suggesting that avcodec_close and av_close_input_file both free their respective passed in contexts. Looking at the code for ffmpeg I don't see any evidence of that.

I may have misunderstood your intentions with these changes so maybe you can elaborate.

Thanks.
Regarding the scale line, I simply noticed that you removed it from the live stream, but kept it for events and it seems more trouble than its worth and kills the stream on firefox 3.6 so i simply removed it.

Regarding ffmpeg:
1) Yes, i know that av_freep takes a pointer, and when reading your reply i didn't know whats wrong until i looked at my patch again and noticed i changed the function name but forgot to add a "&" to the pointers. :oops:
2) You are right, avcodec_close() doesn't free the structure, but you know what, avcodec_open() doesn't allocate it either! :shock:
On the call to avcodec_open(), it overwrote another codec context.
av_open_input_file does allocate a format context and av_close_input_file frees it.

Here is a hopefully corrected patch for the first file, after some reading about the FFMPEG API. I don't have any suitable cameras (just analog) so i'm unable to test it unfortunately.

Code: Select all

--- a/src/zm_ffmpeg_camera.cpp
+++ b/src/zm_ffmpeg_camera.cpp
@@ -43,18 +43,27 @@ FfmpegCamera::FfmpegCamera( int p_id, const std::string &p_path, int p_width, in
 
 FfmpegCamera::~FfmpegCamera()
 {
-    av_free( mFrame );
-    av_free( mRawFrame );
-    
-    avcodec_close( mCodecContext );
-    av_free( mCodecContext );
-    av_close_input_file( mFormatContext );
-    av_free( mFormatContext );
+    av_freep( &mFrame );
+    av_freep( &mRawFrame );
 
-	if ( capture )
-	{
-		Terminate();
-	}
+    /* Only free these (in the reverse order) if PrimeCapture() was called, otherwise they are all NULL */
+    if( mConvertContext ) {
+        sws_freeContext( mConvertContext );
+        mConvertContext = NULL;
+    }
+    if( mCodecContext ) {
+       avcodec_close( mCodecContext );
+       av_freep( &mCodecContext );
+    }
+    if( mFormatContext ) {
+        av_close_input_file( mFormatContext );
+        mFormatContext = NULL;
+    }
+
+    if ( capture )
+    {
+        Terminate();
+    }
 }
 
 void FfmpegCamera::Initialise()
@@ -105,6 +114,11 @@ int FfmpegCamera::PrimeCapture()
     // Try and get the codec from the codec context
     if ( (mCodec = avcodec_find_decoder( mCodecContext->codec_id )) == NULL )
         Fatal( "Can't find codec for video stream from %s", mPath.c_str() );
+    
+    // Allocate memory for the new codec context that avcodec_open() will write to.
+    if( (mCodecContext = avcodec_alloc_context()) == NULL) {
+        Fatal( "Codec context allocation failed." );
+    }
 
     // Open the codec
     if ( avcodec_open( mCodecContext, mCodec ) < 0 )

edit: fixed a typo.

mastertheknife

Posted: Mon Feb 07, 2011 7:12 pm
by mastertheknife
Hi Phil,

On another note, i think i've located another problem in the same file, although its harmless because mBuffer doesn't seem to be used for anything.

mCodecContext->height and mCodecContext->width in PrimeCapture() on a new codec context initialized by avcodec_open() and at this point doesn't contain properties such as height and width. This can cause avpicture_get_size to spit an error or a random value and mBuffer will reserve a memory buffer of the wrong size and later might cause memory corruption\segmentation fault. Correct height and width will be set automatically later by avcodec_decode_video2() causing the scaling process to work as expected.

mastertheknife :D