Page 1 of 1

Signal loss detection bug

Posted: Sat Feb 05, 2011 11:05 am
by mastertheknife
There is a bug somewhere inside CheckSignal() and i'm not sure whats the problem. I'm using ZM from SVN (1.24.3 preview?)

If i disconnect the BNC connector of my camera, i get lots of 1-5 seconds events and in the system log i see this:

Code: Select all

Feb  5 12:48:06 p1400 zma_m1[5781]: WAR [Signal: Reacquired]
Feb  5 12:48:06 p1400 zma_m1[5781]: INF [Camera1: 310 - Gone into alarm state]
Feb  5 12:48:06 p1400 zma_m1[5781]: INF [Camera1: 310 - Opening new event 12518, alarm start]
Feb  5 12:48:07 p1400 zma_m1[5781]: INF [Camera1: 311 - Gone into alert state]
Feb  5 12:48:07 p1400 zma_m1[5781]: WAR [Signal: Lost]
Feb  5 12:48:07 p1400 zma_m1[5781]: INF [Camera1: 315 - Closing event 12518, signal loss]
Feb  5 12:48:07 p1400 zma_m1[5781]: WAR [Signal: Reacquired]
Feb  5 12:48:07 p1400 zma_m1[5781]: INF [Camera1: 316 - Gone into alarm state]
Feb  5 12:48:07 p1400 zma_m1[5781]: INF [Camera1: 316 - Opening new event 12519, alarm start]
Feb  5 12:48:08 p1400 zma_m1[5781]: INF [Camera1: 317 - Gone into alert state]
Feb  5 12:48:09 p1400 zma_m1[5781]: WAR [Signal: Lost]
Feb  5 12:48:09 p1400 zma_m1[5781]: INF [Camera1: 325 - Closing event 12519, signal loss]
Feb  5 12:48:10 p1400 zma_m1[5781]: WAR [Signal: Reacquired]
Feb  5 12:48:10 p1400 zma_m1[5781]: INF [Camera1: 327 - Gone into alarm state]
Feb  5 12:48:10 p1400 zma_m1[5781]: INF [Camera1: 327 - Opening new event 12520, alarm start]
Feb  5 12:48:10 p1400 zma_m1[5781]: INF [Camera1: 328 - Gone into alert state]
Feb  5 12:48:12 p1400 zma_m1[5781]: WAR [Signal: Lost]
Feb  5 12:48:12 p1400 zma_m1[5781]: INF [Camera1: 340 - Closing event 12520, signal loss]
Feb  5 12:48:12 p1400 zma_m1[5781]: WAR [Signal: Reacquired]
Feb  5 12:48:12 p1400 zma_m1[5781]: INF [Camera1: 341 - Gone into alarm state]
Feb  5 12:48:13 p1400 zma_m1[5781]: INF [Camera1: 341 - Opening new event 12521, alarm start]
Feb  5 12:48:13 p1400 zma_m1[5781]: INF [Camera1: 342 - Gone into alert state]
Feb  5 12:48:18 p1400 zma_m1[5781]: INF [Camera1: 367 - Left alarm state (12521) - 51(1) images]
Feb  5 12:48:18 p1400 zma_m1[5781]: INF [Camera1: 367 - Closing event 12521, alarm end]
Feb  5 12:48:18 p1400 zma_m1[5781]: INF [Camera1: 368 - Opening new event 12522, section start]
To troubleshoot, i've added some debugging code, including at the return value of CheckSignal() and it seems that the CheckSignal() function is not working properly on my setup (Single camera connected to a pico2000 card and signal check color is #0000c0)

With the camera disconnected (ZM stream shows blue screen):

Code: Select all

02/05/11 12:48:05.545237 zmc_dvideo0[5773].DB1-zm_monitor.cpp/2579 [TRACE1: Signal is 1]
02/05/11 12:48:05.746170 zmc_dvideo0[5773].DB1-zm_monitor.cpp/2579 [TRACE1: Signal is 1]
02/05/11 12:48:05.946965 zmc_dvideo0[5773].DB1-zm_monitor.cpp/2579 [TRACE1: Signal is 1]
02/05/11 12:48:06.147773 zmc_dvideo0[5773].DB1-zm_monitor.cpp/2579 [TRACE1: Signal is 1]
02/05/11 12:48:06.348579 zmc_dvideo0[5773].DB1-zm_monitor.cpp/2579 [TRACE1: Signal is 0]
02/05/11 12:48:06.549482 zmc_dvideo0[5773].DB1-zm_monitor.cpp/2579 [TRACE1: Signal is 1]
02/05/11 12:48:06.750280 zmc_dvideo0[5773].DB1-zm_monitor.cpp/2579 [TRACE1: Signal is 1]
02/05/11 12:48:06.951019 zmc_dvideo0[5773].DB1-zm_monitor.cpp/2579 [TRACE1: Signal is 1]
02/05/11 12:48:07.151833 zmc_dvideo0[5773].DB1-zm_monitor.cpp/2579 [TRACE1: Signal is 1]
02/05/11 12:48:07.352810 zmc_dvideo0[5773].DB1-zm_monitor.cpp/2579 [TRACE1: Signal is 1]
02/05/11 12:48:07.553610 zmc_dvideo0[5773].DB1-zm_monitor.cpp/2579 [TRACE1: Signal is 0]
02/05/11 12:48:07.754365 zmc_dvideo0[5773].DB1-zm_monitor.cpp/2579 [TRACE1: Signal is 1]
02/05/11 12:48:07.955186 zmc_dvideo0[5773].DB1-zm_monitor.cpp/2579 [TRACE1: Signal is 0]
02/05/11 12:48:08.155989 zmc_dvideo0[5773].DB1-zm_monitor.cpp/2579 [TRACE1: Signal is 1]
02/05/11 12:48:08.356872 zmc_dvideo0[5773].DB1-zm_monitor.cpp/2579 [TRACE1: Signal is 1]
02/05/11 12:48:08.557695 zmc_dvideo0[5773].DB1-zm_monitor.cpp/2579 [TRACE1: Signal is 1]
02/05/11 12:48:08.758484 zmc_dvideo0[5773].DB1-zm_monitor.cpp/2579 [TRACE1: Signal is 1]
02/05/11 12:48:08.959330 zmc_dvideo0[5773].DB1-zm_monitor.cpp/2579 [TRACE1: Signal is 1]
02/05/11 12:48:09.160029 zmc_dvideo0[5773].DB1-zm_monitor.cpp/2579 [TRACE1: Signal is 1]
02/05/11 12:48:09.360836 zmc_dvideo0[5773].DB1-zm_monitor.cpp/2579 [TRACE1: Signal is 1]
02/05/11 12:48:09.561642 zmc_dvideo0[5773].DB1-zm_monitor.cpp/2579 [TRACE1: Signal is 0]
02/05/11 12:48:09.762539 zmc_dvideo0[5773].DB1-zm_monitor.cpp/2579 [TRACE1: Signal is 0]
02/05/11 12:48:09.963277 zmc_dvideo0[5773].DB1-zm_monitor.cpp/2579 [TRACE1: Signal is 0]
02/05/11 12:48:10.164039 zmc_dvideo0[5773].DB1-zm_monitor.cpp/2579 [TRACE1: Signal is 1]
02/05/11 12:48:10.364843 zmc_dvideo0[5773].DB1-zm_monitor.cpp/2579 [TRACE1: Signal is 1]
02/05/11 12:48:10.565708 zmc_dvideo0[5773].DB1-zm_monitor.cpp/2579 [TRACE1: Signal is 1]
02/05/11 12:48:10.766523 zmc_dvideo0[5773].DB1-zm_monitor.cpp/2579 [TRACE1: Signal is 1]
mastertheknife.

Posted: Sat Feb 05, 2011 1:43 pm
by mastertheknife
After debugging for hours i realized the problem is that despite the recent patch to fix signal checking inside the timestamp label, it still happens sometimes, causing the color to mismatch and ZM to think a signal is detected.

I wrote a patch that fixes it once and for all and verified it on my machine to be working.

Code: Select all

--- a/src/zm_monitor.cpp
+++ b/src/zm_monitor.cpp
@@ -1022,9 +1022,9 @@ bool Monitor::CheckSignal( const Image *image )
                 index = (int)(((long long)rand()*(long long)(pixels-1))/RAND_MAX);
                 if ( !config.timestamp_on_capture || !label_format[0] )
                     break;
+
                 // Avoid sampling the rows with timestamp in
-                int y = index / (width * colours);
-                if ( y < label_coord.Y() || y <= label_coord.Y()+Image::LINE_HEIGHT )
+                if ( index < (label_coord.Y()*width) || index >= (label_coord.Y()+Image::LINE_HEIGHT)*width )
                     break;
             }
             const unsigned char *ptr = buffer+(index*colours);
mastertheknife.

How to apply patch

Posted: Mon Mar 07, 2011 8:03 am
by chiun66
Hi.

I have the same problem. I am not a programmer and not so very good at compiling source even though I have compiled zoneminder (at last).

Please tell me how to apply this patch

Thanks.