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

Add WebcamDiscoveryListener #17

Closed
sarxos opened this issue Jan 9, 2013 · 11 comments
Closed

Add WebcamDiscoveryListener #17

sarxos opened this issue Jan 9, 2013 · 11 comments
Assignees
Milestone

Comments

@sarxos
Copy link
Owner

sarxos commented Jan 9, 2013

Created on behalf of @hepin1989, related to #12.

This would be something like that:

Webcam.addWebcamDiscoveryListener(new WebcamDiscoveryListener({
  public void webcamFound(WebcamDiscoveryEvent e) {
    System.out.println("Webcam found: " + e.getWebcam().getName());
  }
});
WebcamDiscoveryListener[] listeners = Webcam.getWebcamDiscoveryListeners();
Webcam.removeWebcamDiscoveryListener(listeners[0]);
@ghost ghost assigned sarxos Jan 9, 2013
@He-Pin
Copy link

He-Pin commented Jan 9, 2013

yes~~!that more good and nice!

@sarxos
Copy link
Owner Author

sarxos commented Jan 10, 2013

More complex webcam discovery service has been added along with webcam discovery listener.

Example code:

public class Test implements WebcamDiscoveryListener {

    public Test() throws Throwable {
        for (Webcam webcam : Webcam.getWebcams()) {
            System.out.println("Found webcam: " + webcam.getName());
        }
        Webcam.addDiscoveryListener(this);
        Thread.sleep(120000);
    }

    public static void main(String[] args) throws Throwable {
        new Test();
    }

    @Override
    public void webcamFound(WebcamDiscoveryEvent event) {
        System.out.println("Webcam has been connected: " + event.getWebcam().getName());
    }

    @Override
    public void webcamGone(WebcamDiscoveryEvent event) {
        System.out.println("Webcam has been disconnected: " + event.getWebcam().getName());
    }
}

Now perform such test:

  1. Connect your camera to the USB,
  2. Wait for a while,
  3. Disconnect your USB camera.

The console output will be:

Found webcam: HP HD Webcam [Fixed] /dev/video0
Webcam has been connected: USB camera /dev/video1
Webcam has been disconnected: USB camera /dev/video1

For now only default webcam driver supports discovery capabilities but I will implement it in JMF and other drivers later.

If one would like to add discovery support to own driver, it's enough for to implement WebcamDiscoverySupport.

This feature can be used always when developer would like to present user some list of all available webcams and would like to keep this list up-to-date whenever user take a look on it. This can be done by reloading (or cleaning) list instance after webcamFound(..) or webcamGone(..) methods are fired.

Please also note that in case when discovery listener is added at the very beggining of the program execution, it will also be notified when Webcam.getWebcams(..) method is being invoked for the first time.

@sarxos
Copy link
Owner Author

sarxos commented Jan 10, 2013

In some cases, when camera is being connected for the first time, discovery can take some more time due to OS busy with drivers initialization.

@He-Pin
Copy link

He-Pin commented Jan 11, 2013

@sarxos sorry for my busy ,and when will you provide an new release ?and how can i build an jar from your source code?

@sarxos
Copy link
Owner Author

sarxos commented Jan 11, 2013

I'm planning new release at the end of February, since I wanted to prepare some more examples of new features plus unit tests, but I can do it faster if you need it in Maven Central.

To build assemblies (ZIP distributions) from source code:

$ git clone git://github.com/sarxos/webcam-capture.git
$ cd webcam-capture
$ mvn clean package -P assembly // this will create ZIP

Or this one to build JARs only, without assembling ZIPs:

$ mvn clean install

Regards

@He-Pin
Copy link

He-Pin commented Jan 15, 2013

@sarxos thanks,after my current busy work done,i want to write some example for this.and can this project support android too by add some armeabi so?even that is not that needed.

@sarxos
Copy link
Owner Author

sarxos commented Jan 15, 2013

For additional architecture support one would have to write your own armebi OpenIMAJGrabber, which compiled will be stored in armebi folder, all Android SDK + NDK-style .so embedding go there.

If you are asking if this is possible, then answer is yes, but I'm not familiar with Android, so will not be able handle this task. Furthermore, such Android-based armebi lib should be supported within OpenIMAJ project, since webcam-capture use their native libraries to capture.

@sarxos
Copy link
Owner Author

sarxos commented Jan 16, 2013

@hepin1989 Just FYI. Yesterday I released 0.3.7 since there was few bugs in 0.3.6 peoples were still encountering. It was initially planned at February, but to make webcam-capture more usable I decided to release it now. Thank you for your support and great ideas :)

@He-Pin
Copy link

He-Pin commented Jan 16, 2013

@sarxos anyway thanks,on android ,we could use the current android api to grab the image,and now,i want to porting the barchart udt to android and maybe i need an codec witch can encode and decode the image to an video stream and then transport the the pc ,it's an heavy task,our complany has nothing ,and our boss want that very ~~~very~~much,and i found that is an heavy task for we don't hava an unicore codec binding.

and one more thing ,could i write my own native code to use some other native library and then build them to an .so ,and then i can interactive with it with the birdj?

the barchart-udt need to change some native implement for the android porting cause the android's java class' implement is not the same with the oracle java's implement even them has the same name.i just found the mediacodec of android come up with the api level 16.but i think the api style is not that good and the MediaCodec Api is incomplete.

maybe i need to learn openMax or ffmpeg's codec part...

i buy a book about maven today and will going to learn it,i think it's grate!

this project is greate ,realy~, i will keep learning .thanks

@sarxos
Copy link
Owner Author

sarxos commented Jan 16, 2013

Thank you :)

In terms of BridJ custom code, yes, you can create your won native code, compile to *.so, *.dll or *.dylib (it depends for which system you want it to compile) and later use it from your Java code.

If you want to go this way, then please take a closer look at JNAerator project - it generates Java binding for your native C/C++ headers. The way of how this has been done in OpenIMAJ is pretty straightforward, so it can be a good point to start learning the BridJ basics. Take a look on the BridJ Java bindings generated (with JNAreator) here for native code available here (search for OpenIMAJGrabber.h in sub folders).

In terms of Maven book. Please take a look on this (Maven: The Definitive Guide). You can download it for free. There is also very good online reference prepared by Sonatype (Maven: The Complete Reference) and set of online examples also by Sonatype (Maven By Example).

From my point of view Maven is the best choice for companies to build project and manage dependencies. There are tons of examples, thousands of users and millions of artifacts available. In the past I've used Ant, but now I know it was just a waste of my time.

@He-Pin
Copy link

He-Pin commented Jan 17, 2013

Thanks a lot,I know how to implement the java selector and nio via epoll now,and past i just copy the udt.h to the JNAerator but there is an three-dimensional array in the net.h ,and theJNaerator cant know how to handle that,so i thinks the usage of this way maybe wrong,and i need to build my own native code with the udt library and them compile them to *.so.

i first notice this in your source code,thank you provide such an nice project open source.

for the maven ,I will starting to learning it ,cause in our Chengdu term .no one familiar with it,thanks a lot.

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

No branches or pull requests

2 participants