Allow only one camera on at a time.
authorDebian User <debian@snoopy.(none)>
Thu, 17 Oct 2013 02:04:07 +0000 (10:04 +0800)
committerDebian User <debian@snoopy.(none)>
Thu, 17 Oct 2013 02:04:07 +0000 (10:04 +0800)
This fixes a crash if both cameras are activated at once.

server/image.c

index a24d091..1d35264 100644 (file)
@@ -4,7 +4,8 @@
 #include <string.h>
 #include <stdio.h>
 
-CvCapture *captures[2] = {0};
+CvCapture *capture;
+int captureID = -1;
 
 void Image_Handler(FCGIContext * context, char * params)
 {
@@ -24,10 +25,12 @@ void Image_Handler(FCGIContext * context, char * params)
                return;
        }
 
-       CvCapture *capture = captures[num];
-       if (capture == NULL) {
+       if (captureID != num) {
+               if (captureID >= 0) {
+                       cvReleaseCapture(&capture);
+               }
                capture = cvCreateCameraCapture(num);
-               captures[num] = capture;
+               captureID = num;
        }
 
        cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH, width);

UCC git Repository :: git.ucc.asn.au