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

OpenIMAJGrabber fatal error on Beaglebone Black Ubuntu armhf and Java 1.8.0 #152

Open
AtomicCactus opened this issue Oct 13, 2013 · 15 comments

Comments

@AtomicCactus
Copy link

Trying to get Webcam Capture working on the Beaglebone Black running Ubuntu Precise 12.04.2 LTS Hard Float Minimal Image.

Webcam Capture version:

        <dependency>
            <groupId>com.github.sarxos</groupId>
            <artifactId>webcam-capture</artifactId>
            <version>0.3.9</version>
        </dependency>

BridJ Jar replaced with this version (was having issues with the one included in 0.3.9):

bridj-0.6.3-20130316.190111-13-linux-only

Java version:

java version "1.8.0-ea"
Java(TM) SE Runtime Environment (build 1.8.0-ea-b109)
Java HotSpot(TM) Client VM (build 25.0-b51, mixed mode)

I'm able to get the list of webcams:

Java HotSpot(TM) Client VM warning: You have loaded library /tmp/BridJExtractedLibraries2631550482475098768/libbridj.so which might have disabled stack guard. The VM will try to fix the stack guard now.
It's highly recommended that you fix the library with 'execstack -c <libfile>', or link it with '-z noexecstack'.
Oct 13, 2013 3:10:47 AM org.bridj.BridJ log
INFO: Not enough args for null OpenIMAJGrabber.startSession(int, int, double)

Webcams list: [Webcam UVC Camera (046d:0819) /dev/video0]

However, trying to grab an image from a webcam results in:

# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0xab324762, pid=1235, tid=2872710256
#
# JRE version: Java(TM) SE Runtime Environment (8.0-b109) (build 1.8.0-ea-b109)
# Java VM: Java HotSpot(TM) Client VM (25.0-b51 mixed mode linux-arm )
# Problematic frame:
# C  [OpenIMAJGrabber.so+0x1762]  Device::getIdentifier()+0x9
#
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# An error report file with more information is saved as:
# /home/ubuntu/tracker/hs_err_pid1235.log
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.sun.com/bugreport/crash.jsp
#
Aborted

I have compiled my own OpenIMAJGrabber.so from source on the Beaglebone.

*** PLEASE NOTE *** that this setup works perfectly fine with the following Java version
(everything else left the same):

ubuntu@ubuntu-armhf:~$ java -version
java version "1.7.0_25"
OpenJDK Runtime Environment (IcedTea 2.3.10) (7u25-2.3.10-1ubuntu0.12.04.2)
OpenJDK Zero VM (build 22.0-b10, mixed mode)

I'm trying to get it to work with Java 1.8.0-ea because it has the hard float optimization, where 1.7.0_25 uses soft floats. This is for a computer vision project.

I'll attach the hs_err_pid file and verbose logs in a moment

@AtomicCactus
Copy link
Author

Here's what I see output to the console:
http://www.atomic-cactus.com/armhf/console.txt

Here's the hs_err_pid file:
http://www.atomic-cactus.com/armhf/hs_err_pid693.log

Some more details:

  • Camera is powered with a powered USB hub.
  • Camera works when using OpenJDK Java 1.7.*, but that's the soft float version which has serious performance drawbacks on this platform
  • When you see "bridj-0.6.2" it's actually using version "bridj-0.6.3-20130316.190111-13-linux-only"
  • OpenIMAJGrabber.so compiled directly on the device from source

@sarxos
Copy link
Owner

sarxos commented Oct 14, 2013

Hi,

Thank you one more time for the report and very detailed description.

Could you please remove the copy of /usr/lib/OpenIMAJGrabber.so (and other extracted copies if you have somewhere else) and try using this dependency instead of 0.3.9:

<dependency>
  <groupId>com.github.sarxos</groupId>
  <artifactId>webcam-capture</artifactId>
  <version>0.3.10-RC5</version>
</dependency>

But you will have to add this repository into your POM:

<repository>
    <id>SarXos Repository</id>
    <url>http://www.sarxos.pl/repo/maven2</url>
</repository>

The newest version should work fine without OpenIMAJGrabber.so extracted. Just add the JAR into your classpath and everything should be working fine. My first suspicion goes to the weak synchronization issue I fixed in 0.3.10, but this is just and thought about why this problem could appear. I also fixed issue causing native libs to not being extracted, but had no chance to test it on RasPi.

@sarxos
Copy link
Owner

sarxos commented Oct 14, 2013

Hi, please hold on. I found that I didn't include the fix I mentioned above in the 0.3.10-RC5. Will release 0.3.10-RC6 and let you know ASAP.

I'm sorry for making you confused.

@sarxos
Copy link
Owner

sarxos commented Oct 14, 2013

Ok, the newest Webcam Capture API, that is 0.3.10-RC6, contains the fix for *.so files extraction from JAR and some synchronization tweeks. Can you please try it instead of 0.3.9?

Repository:

<repository>
    <id>SarXos Repository</id>
    <url>http://www.sarxos.pl/repo/maven2</url>
</repository>

Dependency:

<dependency>
    <groupId>com.github.sarxos</groupId>
    <artifactId>webcam-capture</artifactId>
    <version>0.3.10-RC6</version>
</dependency>

If you do not want to use Maven, you can also download ZIP assembly:

If this won't help we will have to investigate this issue much deeper.

@AtomicCactus
Copy link
Author

@sarxos, thanks for a quick response!
My laptop died yesterday evening, right after I sent you the info. I'll need to get it repaired (doing that today). Should have it ready by tomorrow, probably. That's when I'll try it. Sorry about the delay

@AtomicCactus
Copy link
Author

Sorry about the delay. Had to get my motherboard replaced, took forever!
I've ran the 0.3.10-RC6 version successfully on my Mac, though the framerate seems to be limited to around 15 fps (before it was shooting into the hundreds). On the BeagleBoard I'm getting a new error:

root@ubuntu-armhf:/home/ubuntu# java -jar tracker/tracker.jar
Exception in thread "main" com.github.sarxos.webcam.WebcamException: java.util.concurrent.ExecutionException: com.github.sarxos.webcam.WebcamException: Cannot execute task
    at com.github.sarxos.webcam.WebcamDiscoveryService.getWebcams(WebcamDiscoveryService.java:123)
    at com.github.sarxos.webcam.Webcam.getWebcams(Webcam.java:706)
    at com.github.sarxos.webcam.Webcam.getWebcams(Webcam.java:679)
    at com.github.sarxos.webcam.Webcam.getWebcams(Webcam.java:659)
    at com.atomic.cactus.Main.main(Main.java:37)
Caused by: java.util.concurrent.ExecutionException: com.github.sarxos.webcam.WebcamException: Cannot execute task
    at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:252)
    at java.util.concurrent.FutureTask.get(FutureTask.java:111)
    at com.github.sarxos.webcam.WebcamDiscoveryService.getWebcams(WebcamDiscoveryService.java:115)
    ... 4 more
Caused by: com.github.sarxos.webcam.WebcamException: Cannot execute task
    at com.github.sarxos.webcam.WebcamProcessor$AtomicProcessor.process(WebcamProcessor.java:57)
    at com.github.sarxos.webcam.WebcamProcessor.process(WebcamProcessor.java:122)
    at com.github.sarxos.webcam.WebcamTask.process(WebcamTask.java:38)
    at com.github.sarxos.webcam.ds.buildin.WebcamDefaultDriver$WebcamNewGrabberTask.newGrabber(WebcamDefaultDriver.java:46)
    at com.github.sarxos.webcam.ds.buildin.WebcamDefaultDriver.getDevices(WebcamDefaultDriver.java:118)
    at com.github.sarxos.webcam.WebcamDiscoveryService$WebcamsDiscovery.call(WebcamDiscoveryService.java:36)
    at com.github.sarxos.webcam.WebcamDiscoveryService$WebcamsDiscovery.call(WebcamDiscoveryService.java:26)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
    at java.util.concurrent.FutureTask.run(FutureTask.java:166)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:724)
Caused by: java.lang.NoClassDefFoundError: org/bridj/cpp/CPPObject
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:788)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:447)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at com.github.sarxos.webcam.ds.buildin.WebcamDefaultDriver$WebcamNewGrabberTask.handle(WebcamDefaultDriver.java:56)
    at com.github.sarxos.webcam.WebcamProcessor$AtomicProcessor.run(WebcamProcessor.java:66)
    ... 3 more
Caused by: java.lang.ClassNotFoundException: org.bridj.cpp.CPPObject
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 17 more

This is both on the 1.8.0 and 1.7.0 Java. I removed the OpenIMAJGrabber.so like you asked.

@AtomicCactus
Copy link
Author

Ok, I can't seem to run it on my Mac from the command line either. This is probably a missing JAR issue. I'm using Maven, though, and I copied all the libs. Hmm.. Let me see if I can figure this out.

update:
Runs in the IDE, but not from the command line. Makes no sense.. Maven builds the project just fine. Must be a JAR packaging problem, but this wasn't happening before..

@AtomicCactus
Copy link
Author

Ok, had to add a few random dependencies to the POM, but it seems to at least run from the command line now. Looks like the issue is still there:

root@ubuntu-armhf:/home/ubuntu# jdk1.8.0/bin/java -jar tracker/tracker-0.1.0.jar
[main] INFO com.github.sarxos.webcam.Webcam - WebcamDefaultDriver capture driver will be used
Java HotSpot(TM) Client VM warning: You have loaded library /tmp/BridJExtractedLibraries480302159542860357/libbridj.so which might have disabled stack guard. The VM will try to fix the stack guard now.
It's highly recommended that you fix the library with 'execstack -c <libfile>', or link it with '-z noexecstack'.
Webcams:[Webcam UVC Camera (046d:0819) /dev/video0]
[atomic-processor-1] INFO com.github.sarxos.webcam.ds.cgt.WebcamOpenTask - Opening webcam UVC Camera (046d:0819) /dev/video0
#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0xab81e762, pid=1286, tid=2875188336
#
# JRE version: Java(TM) SE Runtime Environment (8.0-b109) (build 1.8.0-ea-b109)
# Java VM: Java HotSpot(TM) Client VM (25.0-b51 mixed mode linux-arm )
# Problematic frame:
# C  [OpenIMAJGrabber.so+0x1762]  Device::getIdentifier()+0x9
#
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# An error report file with more information is saved as:
# /home/ubuntu/hs_err_pid1286.log
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.sun.com/bugreport/crash.jsp
#
Aborted

More info is coming in a second

@AtomicCactus
Copy link
Author

Here's the output from

jdk1.8.0/bin/java -Dbridj.veryVerbose=true -Dbridj.debug=true -Dwebcam.debug=true -jar tracker/tracker-0.1.0.jar

Console output: http://www.atomic-cactus.com/armhf/10272013/console.txt
hr_err_pid* file: http://www.atomic-cactus.com/armhf/10272013/hs_err_pid1346.log

PS: as before, this works with OpenJDK 1.7.0 (the soft-float version)

@sarxos
Copy link
Owner

sarxos commented Oct 28, 2013

Hi,

Thank you for more details. Indeed, the first issue you've went into was caused by missing BridJ JAR. It can be found in ZIP package:

webcam-capture-0.3.10-RC6-dist.zip

I will take a closer look on the hs_err_pid you included.

I can try to reproduce this issue on my RasPi, but I would have to know from where I can download Ubuntu image you have installed on you HW.

I almost know what is happening here but I have to verify this with guys from OpenIMAJ. Stack trace:

Stack: [0xab57f000,0xab5cf000],  sp=0xab5cd784,  free space=313k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
C  [OpenIMAJGrabber.so+0x1a64]  Device::getIdentifier()+0x14

[error occurred during error reporting (printing native stack), id 0xb]

Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
j  com.github.sarxos.webcam.ds.buildin.natives.OpenIMAJGrabber.startSession(IIDLorg/bridj/Pointer;)Z+0
j  com.github.sarxos.webcam.ds.buildin.WebcamDefaultDevice.open()V+158
j  com.github.sarxos.webcam.ds.cgt.WebcamOpenTask.handle()V+55
j  com.github.sarxos.webcam.WebcamProcessor$AtomicProcessor.run()V+14
j  java.util.concurrent.ThreadPoolExecutor.runWorker(Ljava/util/concurrent/ThreadPoolExecutor$Worker;)V+95
j  java.util.concurrent.ThreadPoolExecutor$Worker.run()V+5
j  java.lang.Thread.run()V+11
v  ~StubRoutines::call_stub

We can see that OpenIMAJGrabber.startSession(int, int, double, Pointer) [src] is failing when calling native Device::getIdentifier() [src].

 boolean started = grabber.startSession(size.width, size.height, 50, Pointer.pointerTo(device));

It calls native:

bool OpenIMAJGrabber::startSession(int width, int height, double rate, Device * device) {
  if (device == NULL) {
    DeviceList * list = getVideoDevices();
    if (list->getNumDevices() > 0) {
      device = list->getDevice(0);
    }
    delete list;
  }

  if (device == NULL) {
    return false;
  }

  data = new VideoGrabber();
  strcpy(VG->dev_name, device->getIdentifier());

  VG->requested_width = width;
  VG->requested_height = height;
  VG->requested_rate = rate;
  VG->timeout = 5000;

  if (open_device(VG) < 0) return false;
  if (init_device(VG) < 0) return false;
  if (start_capturing(VG) < 0) return false;
  return true;
} 

And fails on:

strcpy(VG->dev_name, device->getIdentifier());

But when you check the last method, it seems to be really trivial:

const char* Device::getIdentifier() {
  return identifier;
} 

Therefore I guess that something is wrong with the identifier field - maybe NULL or too long string, which causes strcpy(char*, char*) to fail. I'm not experienced in C++ and need to verify this. I'm pretty loaded till the end of this week, but after the next weekend, I should give you short code sample to run on your Ubuntu to verify what is wrong with the identifier here.

@AtomicCactus
Copy link
Author

It does seem like an OpenIMAJGrabber problem. I have both a Raspberry Pi and a BeagleBone Black which I tried to run this on. On the Pi I could not get the uvcvideo driver to work, so I gave up. Plus, that device is a bit slow for my needs. So I am currently using a BeagleBone Black. Not sure if this helps. Here's the Ubuntu distro I have installed:
http://www.armhf.com/index.php/boards/beaglebone-black/#precise
The webcam code runs on the soft-float version of the JDK, but the framerate is around 2 fps t 320x240 using a Logitec C210 webcam. Trying to get that number up to at least 10 fps, which is the reason I want to switch to the hard-float JDK. I think a lot of the framerate is lost in the raw image conversion. Maybe I'll try a different (non OpenIMAJ) driver.

I haven't looked, but is there an interface one can implement to create a new driver? Maybe I could create a v4l4j driver: https://code.google.com/p/v4l4j/

@spicelove
Copy link

May I ask u one question. May you tell me how to set size frame show camera??(Jpanel show came not jframe)
-->private final static Dimension dimension = new Dimension(320,240) in code with size jframe
i wanna frame show came small or bigger so what i'm do?

Another Pc when show camera use your lib frame show camera bigger or smaller . I want to fix frame show camera plzz tell me where Can i fix it in your project
https://github.com/sarxos/webcam-capture/tree/master/webcam-capture-examples/webcam-capture-live-streaming

plzz email for support : spicelove8x@hotmail.com thanks.


EDIT: Moved to #154

@sarxos
Copy link
Owner

sarxos commented Oct 29, 2013

Hi @spicelove,

I moved your question to #154, please check it for the answer you are looking for :)

I encourage users to create separate issues for the different problems so communication is clear, resolution fast and original issues not affected.

@sarxos
Copy link
Owner

sarxos commented Oct 29, 2013

Hi @AtomicCactus,

I had this post almost written, but my stupid WinXP terminated itself with blue screen and now I have to start it over again.

Ok, if you want to create new capture driver, it's enough to implement two interfaces - WebcamDriver and WebcamDevice, but why to bother and creating new driver for v4l4j if there is existing one webcam-capture-driver-v4l4j. Currently it supports 64-bit Linux only, but with a little bit of development magic it should easily run on any arch. I've customized v4l4j a little bit and added one class to make this magic easier to cast. My fork can be found here:

https://github.com/sarxos/v4l4j-wc

And the only class added to the overall solution is:

https://github.com/sarxos/v4l4j-wc/blob/master/src/main/java/au/edu/jcu/v4l4j/V4L4J.java

It must be modified to support architectures other than 64-bit. Especially, native libraries have to be compiled for these archs. Take a look on the code - it's trivial, what would have to be added here is a detection feature which will check runtime against 64-, 32-, armel or armhf architecture, and load specific *.so object. This is how I would see it:

try {
  if (!isLinux()) {
    throw new RuntimeException("Ooops, only Linux is supported!");
  } else {
    if (is64()) {
      NativeUtils.loadLibraryFromJar("/META-INF/native/linux64", new String[] { "video", "v4l4j" });
    } else if (is32()) {
      NativeUtils.loadLibraryFromJar("/META-INF/native/linux32", new String[] { "video", "v4l4j" });
    } else if (isArmel()) {
      NativeUtils.loadLibraryFromJar("/META-INF/native/linuxarmel", new String[] { "video", "v4l4j" });
    } else if (isArmhf()) {
      NativeUtils.loadLibraryFromJar("/META-INF/native/linuxarmhf", new String[] { "video", "v4l4j" });
    }
  }
} catch (IOException e) {
  e.printStackTrace();
}

After native *.so are ready and above code modified, it's enough to change POM in webcam-capture-driver-v4l4j to use newer version and mvn clean install.

Please let me know if you would like to follow this path to use v4l4j under the hood of Webcam Capture on your BeagleBone. I will then try to compile it first on my RasPi.

@rogierslag
Copy link

I encounter the same issue currently on Arch Linux but cannot seem to figure out how to fix this..

sarxos added a commit that referenced this issue Feb 26, 2015
refs #286
refs #315
refs #244
refs #219
refs #194
refs #192
refs #189
refs #184
refs #176
refs #153
refs #152
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants