Does "Webcam capture API" work with AdoptOpenJDK 11?

2

I am writing a simple webcam recorder using Webcam Capture API, Xuggler and Java's Sound API. I've been using JDK 1.8 for this project and almost completed it. I am able to record video with audio using those libraries. But when I switch to AdoptOpenJDK 11 (jdk-11.0.4.11-openj9) and run the app, it crashes, showing following message on console.

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Unhandled exception
Type=Segmentation error vmState=0x00040000
Windows_ExceptionCode=c0000005 J9Generic_Signal=00000004 ExceptionAddress=00007FFB4F155BC3 ContextFlags=0010005f
Handler1=00007FFB4F14CAD0 Handler2=00007FFB52F2EFE0 InaccessibleReadAddress=0000000000000010
RDI=00000000002A8500 RSI=0000000000000000 RAX=000000DC1DCFE8E8 RBX=0000021E65DA0DA8
RCX=00000000002A8500 RDX=0000021E64542528 R8=0000000000000000 R9=00007FFB4F233DF0
R10=000000000000001B R11=00007FFB4F233DF0 R12=0000021E64542528 R13=0000021E64542560
R14=0000021E64542528 R15=0000021E6449C160
RIP=00007FFB4F155BC3 RSP=000000DC1DCFE870 RBP=0000000000000000 GS=002B
FS=0053 ES=002B DS=002B
XMM0 0000000000000000 (f: 0.000000, d: 0.000000e+00)
XMM1 000000000000000a (f: 10.000000, d: 4.940656e-323)
XMM2 000000003f800000 (f: 1065353216.000000, d: 5.263544e-315)
XMM3 3c7cb44f431440ef (f: 1125400832.000000, d: 2.489704e-17)
XMM4 402d1cb7c6000000 (f: 3321888768.000000, d: 1.455609e+01)
XMM5 3f1a8114c70a41cc (f: 3339338240.000000, d: 1.011056e-04)
XMM6 0000000000000000 (f: 0.000000, d: 0.000000e+00)
XMM7 0000000000000000 (f: 0.000000, d: 0.000000e+00)
XMM8 0000000000000000 (f: 0.000000, d: 0.000000e+00)
XMM9 0000000000000000 (f: 0.000000, d: 0.000000e+00)
XMM10 0000000000000000 (f: 0.000000, d: 0.000000e+00)
XMM11 0000000000000000 (f: 0.000000, d: 0.000000e+00)
XMM12 0000000000000000 (f: 0.000000, d: 0.000000e+00)
XMM13 0000000000000000 (f: 0.000000, d: 0.000000e+00)
XMM14 0000000000000000 (f: 0.000000, d: 0.000000e+00)
XMM15 0000000000000000 (f: 0.000000, d: 0.000000e+00)
Module=C:\Program Files\AdoptOpenJDK\jdk-11.0.4.11-openj9\bin\compressedrefs\j9vm29.dll
Module_base_address=00007FFB4F0D0000 Offset_in_DLL=0000000000085bc3
Target=2_90_20190717_282 (Windows 10 10.0 build 10240)
CPU=amd64 (4 logical CPUs) (0x3f8903000 RAM)
----------- Stack Backtrace -----------
(0x00007FFB4F155BC3 [j9vm29+0x85bc3])
Java_org_bridj_JNI_bindJavaMethodsToCFunctions+0x255 (0x00007FFB4C0A68E5 [bridj+0x68e5])
J9_GetInterface+0x99ef3 (0x00007FFB4F1F3BD3 [j9vm29+0x123bd3])
J9_GetInterface+0x99948 (0x00007FFB4F1F3628 [j9vm29+0x123628])
(0x00007FFB4F0E52D0 [j9vm29+0x152d0])
---------------------------------------
JVMDUMP039I Processing dump event "gpf", detail "" at 2020/04/30 03:06:43 - please wait.
JVMDUMP032I JVM requested System dump using 'E:\workspace_cam\webcam-examples\core.20200430.030643.6148.0001.dmp' in response to an event
JVMDUMP010I System dump written to E:\workspace_cam\webcam-examples\core.20200430.030643.6148.0001.dmp
JVMDUMP032I JVM requested Java dump using 'E:\workspace_cam\webcam-examples\javacore.20200430.030643.6148.0002.txt' in response to an event
JVMDUMP010I Java dump written to E:\workspace_cam\webcam-examples\javacore.20200430.030643.6148.0002.txt
JVMDUMP032I JVM requested Snap dump using 'E:\workspace_cam\webcam-examples\Snap.20200430.030643.6148.0003.trc' in response to an event
JVMDUMP010I Snap dump written to E:\workspace_cam\webcam-examples\Snap.20200430.030643.6148.0003.trc
JVMDUMP007I JVM Requesting JIT dump using 'E:\workspace_cam\webcam-examples\jitdump.20200430.030643.6148.0004.dmp'
JVMDUMP010I JIT dump written to E:\workspace_cam\webcam-examples\jitdump.20200430.030643.6148.0004.dmp
JVMDUMP013I Processed dump event "gpf", detail "".

It seems bridj library causes the error. I've tried to find the fix but couldn't. Below is a sample program which produces the same issue (runs fine with jdk1.8 but crashes with openjdk11).

package com.lauren.webcam_examples;

import com.github.sarxos.webcam.Webcam;
import com.github.sarxos.webcam.WebcamResolution;
import com.xuggle.mediatool.IMediaWriter;
import com.xuggle.mediatool.ToolFactory;
import com.xuggle.xuggler.ICodec;
import com.xuggle.xuggler.IPixelFormat;
import com.xuggle.xuggler.IVideoPicture;
import com.xuggle.xuggler.video.ConverterFactory;
import com.xuggle.xuggler.video.IConverter;
import java.awt.Dimension;
import java.awt.image.BufferedImage;
import java.io.File;

public class VideoWriter {

    public static void main(String[] args) throws InterruptedException {
        VideoWriter videoWriter = new VideoWriter();
        videoWriter.startVideoRecording();
    }

    private void startVideoRecording() throws InterruptedException {
        File saveFile = new File("E:\\fdt-camera-app\\Video\\saved.ts");

        //Initialize media writer
        IMediaWriter writer = ToolFactory.makeWriter(saveFile.getAbsolutePath());
        //Set video recording size
        Dimension size = WebcamResolution.VGA.getSize();

        writer.addVideoStream(0, 0, ICodec.ID.CODEC_ID_H264, size.width, size.height);

        long start = System.currentTimeMillis();
        Webcam webcam = openWebcam(size);

        for (int i = 0; i < 300; i++) {
            BufferedImage image = ConverterFactory.convertToType(webcam.getImage(), BufferedImage.TYPE_3BYTE_BGR);
            IConverter converter = ConverterFactory.createConverter(image, IPixelFormat.Type.YUV420P);

            IVideoPicture frame = converter.toPicture(image, (System.currentTimeMillis() - start) * 1000);
            frame.setKeyFrame(i == 0);
            frame.setQuality(100);

            writer.encodeVideo(0, frame);

            Thread.sleep(20);
        }

        writer.close();
        System.out.println("Video recorded to the file: " + saveFile.getAbsolutePath());
    }

    private Webcam openWebcam(Dimension size) {
        Webcam webcam = Webcam.getDefault();
        webcam.setViewSize(size);
        webcam.open();
        return webcam;
    }
}

Can someone help me to solve this and explain briefly why this kind of error occurs?

Edit: The crash happens only with OpenJ9 VM. In HotSpot, it just runs fine.

java
javafx
segmentation-fault
webcam-capture
asked on Stack Overflow Apr 30, 2020 by Mani kandan • edited May 3, 2020 by Mani kandan

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0