Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discovery Service Reset #93

Closed
MisterWil opened this issue May 6, 2013 · 5 comments
Closed

Discovery Service Reset #93

MisterWil opened this issue May 6, 2013 · 5 comments
Assignees
Labels
Milestone

Comments

@MisterWil
Copy link

Following up on my previous issue #92, it would appear the next problem I'm having is registering an IPCamDevice with the IPCamDeviceRegistry after having already called Webcam.getWebcams(). What appears to be happening is the WebcamDiscoveryService is caching the webcam's, so subsequent calls to WebcamDiscoveryService.getWebcams() is returning the old list of Webcams.

Does this imply that we should not be able to register new webcams after having used a Webcam, or is it an oversight in that there is no way to perform a reset on WebcamDiscoveryService.getWebcams()?

I created a workaround for this by creating a reset method in WebcamDiscoveryService:

public void reset() {
    webcams = null;
}

Calling it in this instance, which is called after Webcam.getWebcams() has already been called at least once and a webcam has been started and stopped:

if (!IpCamDeviceRegistry.isRegistered(cameraName)) {
    ipCam = new IpCamDevice(cameraName, new URL(cameraURL), cameraMode);
    ipCam.setAuth(new IpCamAuth(cameraUsername, cameraPassword));

    IpCamDeviceRegistry.register(ipCam);
    Webcam.getDiscoveryService().reset();

    for (Webcam webcam : Webcam.getWebcams()) {
        System.out.println("Found Webcam: " + webcam.getName());
        if (webcam.getName() == cameraName) {
            webcams.put(cameraName, webcam);
        }
    }
}
@sarxos
Copy link
Owner

sarxos commented May 6, 2013

Hi,

Thank you for the report.

This is a bug, I will fix it.

@sarxos
Copy link
Owner

sarxos commented May 6, 2013

Ok, the issue you've reported is now fixed. Therefore, this code:

static {
    Webcam.setDriver(new IpCamDriver());
}

public static void main(String[] args) throws MalformedURLException {

    IpCamDeviceRegistry.register("test 01", "http://p.de/c=1", IpCamMode.PULL);

    System.out.println("-------");
    for (Webcam w : Webcam.getWebcams()) {
        System.out.println(w);
    }

    IpCamDeviceRegistry.register("test 02", "http://p.de/c=1", IpCamMode.PULL);
    IpCamDeviceRegistry.register("test 03", "http://p.de/c=1", IpCamMode.PULL);
    IpCamDeviceRegistry.register("test 04", "http://p.de/c=1", IpCamMode.PULL);
    IpCamDevice d = IpCamDeviceRegistry.register("test 05", "http://p.de/c=1", IpCamMode.PULL);

    System.out.println("-------");
    for (Webcam w : Webcam.getWebcams()) {
        System.out.println(w);
    }

    IpCamDeviceRegistry.unregister(d); // remove "test 05"

    System.out.println("-------");
    for (Webcam w : Webcam.getWebcams()) {
        System.out.println(w);
    }
}

Will result in all webcams to be printed in appropriate manner:

20:56:40.769 [main] INFO  com.github.sarxos.webcam.Webcam - IpCamDriver capture driver will be used
-------
Webcam test 01
-------
Webcam test 01
Webcam test 02
Webcam test 03
Webcam test 04
Webcam test 05
20:56:40.801 [main] INFO  com.github.sarxos.webcam.Webcam - Disposing webcam test 05
20:56:40.801 [main] DEBUG com.github.sarxos.webcam.Webcam - Webcam disposed test 05
-------
Webcam test 01
Webcam test 02
Webcam test 03
Webcam test 04

@sarxos
Copy link
Owner

sarxos commented May 6, 2013

@wschrader,

Do you need new Webcam Capture release, or is it enough for you to work with source code?

@MisterWil
Copy link
Author

Nah, I don't need a new release. I just grabbed the updated files and it works great. Thanks!

@sarxos
Copy link
Owner

sarxos commented May 6, 2013

Great :) Thank you one more time! Take care!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants