From 7b677bb017dd550bf7b298e459255cf76ea59ad8 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Sat, 15 Dec 2018 07:58:39 +0000 Subject: [PATCH] videoio(dc1394): use lazy initialization on demand backport eb1f3733eec947b9972fec612863999adb7c6777 into 2.4 --- modules/highgui/src/cap_dc1394_v2.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/modules/highgui/src/cap_dc1394_v2.cpp b/modules/highgui/src/cap_dc1394_v2.cpp index f4eb7a9deb..59af255af4 100644 --- a/modules/highgui/src/cap_dc1394_v2.cpp +++ b/modules/highgui/src/cap_dc1394_v2.cpp @@ -192,7 +192,11 @@ CvDC1394::~CvDC1394() dc = 0; } -static CvDC1394 dc1394; +static CvDC1394& getDC1394() +{ + static CvDC1394 dc1394; + return dc1394; +} class CvCaptureCAM_DC1394_v2_CPP : public CvCapture { @@ -451,7 +455,7 @@ bool CvCaptureCAM_DC1394_v2_CPP::startCapture() code = dc1394_capture_setup(dcCam, nDMABufs, DC1394_CAPTURE_FLAGS_DEFAULT); if (code >= 0) { - FD_SET(dc1394_capture_get_fileno(dcCam), &dc1394.camFds); + FD_SET(dc1394_capture_get_fileno(dcCam), &getDC1394().camFds); dc1394_video_set_transmission(dcCam, DC1394_ON); if (cameraId == VIDERE) { @@ -477,15 +481,15 @@ bool CvCaptureCAM_DC1394_v2_CPP::open(int index) close(); - if (!dc1394.dc) + if (!getDC1394().dc) goto _exit_; - err = dc1394_camera_enumerate(dc1394.dc, &cameraList); + err = dc1394_camera_enumerate(getDC1394().dc, &cameraList); if (err < 0 || !cameraList || (unsigned)index >= (unsigned)cameraList->num) goto _exit_; guid = cameraList->ids[index].guid; - dcCam = dc1394_camera_new(dc1394.dc, guid); + dcCam = dc1394_camera_new(getDC1394().dc, guid); if (!dcCam) goto _exit_; @@ -510,8 +514,8 @@ void CvCaptureCAM_DC1394_v2_CPP::close() // check for fileno valid before using int fileno=dc1394_capture_get_fileno(dcCam); - if (fileno>=0 && FD_ISSET(fileno, &dc1394.camFds)) - FD_CLR(fileno, &dc1394.camFds); + if (fileno>=0 && FD_ISSET(fileno, &getDC1394().camFds)) + FD_CLR(fileno, &getDC1394().camFds); dc1394_video_set_transmission(dcCam, DC1394_OFF); dc1394_capture_stop(dcCam); dc1394_camera_free(dcCam);