Stopping and starting a capture

50 views
Skip to first unread message

JR

unread,
Mar 15, 2012, 2:36:24 PM3/15/12
to v4l4j
I have used the sample code as a starting point to successfully
capture video from my webcam and now I am trying to stop the capture
and restart it again but I get a java.lang.NullPointerException:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at au.edu.jcu.v4l4j.PushSource.startCapture(Unknown Source)
at au.edu.jcu.v4l4j.AbstractGrabber.startCapture(Unknown Source)
at v4l4jTest.SimpleViewer.startCapture(SimpleViewer.java:127)
at v4l4jTest.SimpleViewer.actionPerformed(SimpleViewer.java:316)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:
2012)
at javax.swing.AbstractButton
$Handler.actionPerformed(AbstractButton.java:2335)
at
javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:
404)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:
259)
at
javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:
252)
at java.awt.Component.processMouseEvent(Component.java:6268)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
at java.awt.Component.processEvent(Component.java:6033)
at java.awt.Container.processEvent(Container.java:2045)
at java.awt.Component.dispatchEventImpl(Component.java:4629)
at java.awt.Container.dispatchEventImpl(Container.java:2103)
at java.awt.Component.dispatchEvent(Component.java:4455)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:
4633)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:
4297)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4227)
at java.awt.Container.dispatchEventImpl(Container.java:2089)
at java.awt.Window.dispatchEventImpl(Window.java:2517)
at java.awt.Component.dispatchEvent(Component.java:4455)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:649)
at java.awt.EventQueue.access$000(EventQueue.java:96)
at java.awt.EventQueue$1.run(EventQueue.java:608)
at java.awt.EventQueue$1.run(EventQueue.java:606)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext
$1.doIntersectionPrivilege(AccessControlContext.java:105)
at java.security.AccessControlContext
$1.doIntersectionPrivilege(AccessControlContext.java:116)
at java.awt.EventQueue$2.run(EventQueue.java:622)
at java.awt.EventQueue$2.run(EventQueue.java:620)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext
$1.doIntersectionPrivilege(AccessControlContext.java:105)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:619)
at
java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:
275)
at
java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:
200)
at
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:
190)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:
185)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:
177)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:138)

I can successfully stop the capture, but starting it with
frameGrabber.startCapture() causes the above error. Any ideas on what
may be the problem? (I am using libvideo version 0.8-10)

Gilles Gigan

unread,
Mar 15, 2012, 5:44:51 PM3/15/12
to v4...@googlegroups.com
Hi,
Thanks for reporting this issue, I think it is a bug in v4l4j.
You can do two things:
- if you have v4l4j's source code, remove line 103 in
src/au/edu/jcu/v4l4j/PushSource.java, rebuild, reinstall and the issue
should be gone
- otherwise, try move the call to FrameGrabber.setCaptureCallback()
just before FrameGrabber.startCapture() so setCaptureCallback() is
called every time startCapture() is called.

Let me know if this helps.
Gilles

> --
> You received this message because you are subscribed to the Google Groups "v4l4j" group.
> To post to this group, send email to v4...@googlegroups.com.
> To unsubscribe from this group, send email to v4l4j+un...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/v4l4j?hl=en.
>

JR

unread,
Mar 15, 2012, 11:14:35 PM3/15/12
to v4l4j
Thanks for the prompt reply.

I have downloaded v4l4j, removed line 103 from PushSource.java and
compiled, but when testing it out with test-gui I get the following:

test-gui:
[java] Cant load v4l4j JNI library
[java] Exception in thread "AWT-EventQueue-0"
java.lang.UnsatisfiedLinkError: /usr/lib/jni/libv4l4j.so: /usr/lib/jni/
libv4l4j.so: undefined symbol: libvideo_palettes
[java] at java.lang.ClassLoader$NativeLibrary.load(Native
Method)
[java] at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:
1807)
[java] at java.lang.ClassLoader.loadLibrary(ClassLoader.java:
1732)
[java] at java.lang.Runtime.loadLibrary0(Runtime.java:823)
[java] at java.lang.System.loadLibrary(System.java:1028)
[java] at au.edu.jcu.v4l4j.VideoDevice.<clinit>(Unknown Source)
[java] at au.edu.jcu.v4l4j.examples.videoViewer.DeviceChooser
$DeviceInfoPane.<init>(Unknown Source)
[java] at
au.edu.jcu.v4l4j.examples.videoViewer.DeviceChooser.actionPerformed(Unknown
Source)
[java] at
au.edu.jcu.v4l4j.examples.videoViewer.DeviceChooser.<init>(Unknown
Source)
[java] at au.edu.jcu.v4l4j.examples.videoViewer.DeviceChooser
$1.run(Unknown Source)
[java] at
java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
[java] at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:
641)
[java] at java.awt.EventQueue.access$000(EventQueue.java:84)
[java] at java.awt.EventQueue$1.run(EventQueue.java:602)
[java] at java.awt.EventQueue$1.run(EventQueue.java:600)
[java] at java.security.AccessController.doPrivileged(Native
Method)
[java] at java.security.AccessControlContext
$1.doIntersectionPrivilege(AccessControlContext.java:87)
[java] at java.awt.EventQueue.dispatchEvent(EventQueue.java:611)
[java] at
java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:
269)
[java] at
java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:
184)
[java] at
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:
174)
[java] at
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
[java] at
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
[java] at
java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

I noticed another discussion on this but there didn't seem to be a
resolution.

ldd /usr/lib/jni/libv4l4j.so gives the following:
linux-gate.so.1 => (0x00c50000)
libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0x00a65000)
/lib/ld-linux.so.2 (0x0051f000)

Thanks for your help,
Jeff


On Mar 15, 5:44 pm, Gilles Gigan <gilles.gi...@gmail.com> wrote:
> Hi,
> Thanks for reporting this issue, I think it is a bug in v4l4j.
> You can do two things:
> - if you have v4l4j's source code, remove line 103 in
> src/au/edu/jcu/v4l4j/PushSource.java, rebuild, reinstall and the issue
> should be gone
> - otherwise, try move the call to FrameGrabber.setCaptureCallback()
> just before FrameGrabber.startCapture() so setCaptureCallback() is
> called every time startCapture() is called.
>
> Let me know if this helps.
> Gilles
>
> > You received this message because you are subscribed to the Google Groups "v4l4j" group.> To post to this group, send email tov...@googlegroups.com.> To unsubscribe from this group, send email tov4l4j+u...@googlegroups.com.

Gilles Gigan

unread,
Mar 15, 2012, 11:22:01 PM3/15/12
to v4...@googlegroups.com
Ok, that's weird. What platform & OS are you on ?
In the v4l4j source dir, can you do:
sudo ant uninstall
and clean all
sudo ant install

and then try the simple viewer app again.

Gilles

> To post to this group, send email to v4...@googlegroups.com.
> To unsubscribe from this group, send email to v4l4j+un...@googlegroups.com.

JR

unread,
Mar 15, 2012, 11:59:57 PM3/15/12
to v4l4j
I am running Ubuntu 11.10 (Kernel 3.0.0-12-generic) on an 386 platform
(Intel Core 2 Duo).

Still the same result after uninstalling, rebuilding and installing.

It is weird though because if I install the deb package, the program
works fine (except for the stop/startCapture part)

Jeff

On Mar 15, 11:22 pm, Gilles Gigan <gilles.gi...@gmail.com> wrote:
> Ok, that's weird. What platform & OS are you on ?
> In the v4l4j source dir, can you do:
> sudo ant uninstall
> and clean all
> sudo ant install
>
> and then try the simple viewer app again.
>
> Gilles
>
> >> > -->> > You received this message because you are subscribed to the Google Groups "v4l4j" group.> To post to this group, send emailt...@googlegroups.com.> To unsubscribe from this group, send emailtov4l4j...@googlegroups.com.

Gilles Gigan

unread,
Mar 16, 2012, 12:05:45 AM3/16/12
to v4...@googlegroups.com
One more thing for you to try:

can you change line 55 in src/Makefile from
$(LD) $(LDFLAGS) $(OBJ) -o $(LIB)
to
$(LD) $(OBJ) $(LDFLAGS) -o $(LIB)

(essentially swap $(OBJ) and $(LDFLAGS) and make sure you preserve the
tab at the start of the line)

then
sudo ant uninstall
ant clean all
sudo ant install

and test again
Gilles

> To post to this group, send email to v4...@googlegroups.com.
> To unsubscribe from this group, send email to v4l4j+un...@googlegroups.com.

JR

unread,
Mar 16, 2012, 12:34:26 AM3/16/12
to v4l4j
Ok, that worked! However, when I restart a capture I get a different
error:

Exception in thread "AWT-EventQueue-0"
java.lang.IllegalThreadStateException
at java.lang.Thread.start(Thread.java:655)
at au.edu.jcu.v4l4j.PushSource.startCapture(Unknown Source)
at au.edu.jcu.v4l4j.AbstractGrabber.startCapture(Unknown Source)
at v4l4jTest.SimpleViewer.startCapture(SimpleViewer.java:132)
at v4l4jTest.SimpleViewer.actionPerformed(SimpleViewer.java:361)
But if I place the frameGrabber.setCaptureCallback(this); line before
I start the capture, it works great!

So thanks again for your help...this is a great project!

Jeff

On Mar 16, 12:05 am, Gilles Gigan <gilles.gi...@gmail.com> wrote:
> One more thing for you to try:
>
> can you change line 55 in src/Makefile from
>         $(LD) $(LDFLAGS) $(OBJ) -o $(LIB)
> to
>         $(LD) $(OBJ) $(LDFLAGS) -o $(LIB)
>
> (essentially swap $(OBJ) and $(LDFLAGS) and make sure you preserve the
> tab at the start of the line)
>
> then
> sudo ant uninstall
> ant clean all
> sudo ant install
>
> and test again
> Gilles
>
> >> >> > -->> > You received this message because you are subscribed to the Google Groups "v4l4j" group.> To post to this group, sendemai...@googlegroups.com.> To unsubscribe from this group, sendemailtov4l...@googlegroups.com.
> >> >> > For more options, visit this group athttp://groups.google.com/group/v4l4j?hl=en.
>
> >> > -->> > You received this message because you are subscribed to the Google Groups "v4l4j" group.> To post to this group, send emailt...@googlegroups.com.> To unsubscribe from this group, send emailtov4l4j...@googlegroups.com.
> >> > For more options, visit this group athttp://groups.google.com/group/v4l4j?hl=en.
>
> > --
> > You received this message because you are subscribed to the Google Groups "v4l4j" group.> To post to this group, send email tov...@googlegroups.com.> To unsubscribe from this group, send email tov4l4j+u...@googlegroups.com.
> > For more options, visit this group at
>
> ...
>
> read more »

Gilles Gigan

unread,
Mar 16, 2012, 12:39:19 AM3/16/12
to v4...@googlegroups.com
No worries Jeff ! I ll put in the fixes when I have some time this
week end so they will be in the next release.
Did you make any modifications to the SimpleViewer class ? If so, can
you send it to me, so I can try and see why it happens ?
Thanks for your help.
Cheers,
Gilles

> To post to this group, send email to v4...@googlegroups.com.
> To unsubscribe from this group, send email to v4l4j+un...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/v4l4j?hl=en.
>

Gilles Gigan

unread,
Mar 17, 2012, 5:03:40 AM3/17/12
to v4...@googlegroups.com
Hi Jeff,
thanks for sending your code.
Looking through it, I noticed you are not using VideoFrame's correctly:
In the nextFrame() callback, you obtain BufferedImage's from
VideoFrame's and place them in an ArrayList for later use, and call
VideoFrame.recycle(). You shouldnt be doing this. Calling recycle()
tells v4l4j that the VideoFrame and any other objects obtained through
the VideoFrame (in your case, that's the BufferedImage) will not be
used anymore. However, in your code, you store a reference to a
BufferedImage that will be used AFTER you called recycle(), and that
spells trouble. I suggest you store VideoFrame's in your frameImages
ArrayList. Make sure there is another thread (that would be your timer
thread) which pulls the VideoFrames from frameImages in a timely
manner (timely is very important here) , deals with them (in your
case, that's displaying the resized frames) and only then, call
recycle().
I hope that makes sens to you, otherwise, let me know and I ll give
that explanation another shot.
Cheers,
Gilles

On 16 March 2012 16:10, Jeff Radulovich <jeff.ra...@gmail.com> wrote:
> Hi Gilles,
>
> Here is the modified SimpleViewer class I was using.  I was messing around
> with an ImageScaler class, so you will need it to compile (I have attached
> it as well).
>
> Sorry for the sloppy code, but I am still experimenting with your code.
>
> Jeff

JR

unread,
Mar 17, 2012, 6:21:19 PM3/17/12
to v4l4j
Hi Gilles,

Thanks for pointing out what I should have read myself about how the
recycle() method works.

However, even if I don't do anything with the VideoFrame (or its
associated objects), stopping and starting the capture seems to still
cause the same problem.

And, as before, placing the line frameGragger.setCaptureCallback()
before restarting the capture seems to solve the problem.

Jeff

On Mar 17, 5:03 am, Gilles Gigan <gilles.gi...@gmail.com> wrote:
> Hi Jeff,
> thanks for sending your code.
> Looking through it, I noticed you are not using VideoFrame's correctly:
> In the nextFrame() callback, you obtain BufferedImage's from
> VideoFrame's and place them in an ArrayList for later use, and call
> VideoFrame.recycle(). You shouldnt be doing this. Calling recycle()
> tells v4l4j that the VideoFrame and any other objects obtained through
> the VideoFrame (in your case, that's the BufferedImage) will not be
> used anymore. However, in your code, you store a reference to a
> BufferedImage that will be used AFTER you called recycle(), and that
> spells trouble. I suggest you store VideoFrame's in your frameImages
> ArrayList. Make sure there is another thread (that would be your timer
> thread) which pulls the VideoFrames from frameImages in a timely
> manner (timely is very important here) , deals with them (in your
> case, that's displaying the resized frames) and only then, call
> recycle().
> I hope that makes sens to you, otherwise, let me know and I ll give
> that explanation another shot.
> Cheers,
> Gilles
>

Gilles Gigan

unread,
Mar 17, 2012, 8:29:28 PM3/17/12
to v4...@googlegroups.com
Hi Jeff,
Sorry I should have been more clear:
- the recycle() usage is an issue with your code.
- Having to call setCaptureCallback() before startCapture() is a bug
in v4l4j, and unrelated to how you used recycle().

Cheers,
GIlles

Reply all
Reply to author
Forward
0 new messages