eduramiba / webcam-capture-driver-native

Native driver for Webcam Capture API
25 stars 8 forks source link

Webcam close and open #4

Closed pacioc193 closed 1 year ago

pacioc193 commented 2 years ago

After having close and open a webcam is not possible to open anymore!

This is the code : ` Webcam.setDriver(new CaptureManagerDriver()); Webcam webcam = Webcam.getWebcams().get(4);

    long t1, t2;

    for (int i = 0; i < 5; i++) {

        try {
            System.out.format("Opening...\n");

            t1 = System.currentTimeMillis();
            webcam.open();
            t2 = System.currentTimeMillis();

            System.out.format("Opening time: %d ms\n", t2 - t1);
            System.out.format("Fetch image...\n");

            t1 = System.currentTimeMillis();
            if (webcam.getImage() == null) {
                System.err.println("Damn! Image is null!");
            }
            t2 = System.currentTimeMillis();

            System.out.format("Fetch image time: %d ms\n", t2 - t1);
            System.out.format("Closing...\n");

            t1 = System.currentTimeMillis();
            webcam.close();
            t2 = System.currentTimeMillis();

            System.out.format("Closing time: %d ms\n", t2 - t1);
            System.out.format("Wait 5 seconds...\n", t2 - t1);

            Thread.sleep(5000);
        } catch (InterruptedException ex) {
            java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
    }

    System.out.format("Done...\n");

` image

Without the loading of the driver

image

pacioc193 commented 2 years ago

It is stuck and can't open anymore the USB webcam...

pacioc193 commented 2 years ago

Debugging the software seems that after having close the webcam, open command will call automatically the original driver and not the loaded one.

I will try to continue to investigate...

pacioc193 commented 2 years ago

Closing procedure called from the driver is not closing the device and then could not be open anymore because seems still always open.

eduramiba commented 1 year ago

Duplicate of https://github.com/sarxos/webcam-capture/issues/859