gstreamer-java / gst1-java-core

Java bindings for GStreamer 1.x
GNU Lesser General Public License v3.0
188 stars 72 forks source link

Exception in thread "main" java.lang.Error: Invalid memory access #265

Closed AmitAkuka closed 1 year ago

AmitAkuka commented 1 year ago

Hi, I've been running lately into this issue (on version 1.22.2 and latest version 1.22.3). The full exception output: Exception in thread "main" java.lang.Error: Invalid memory access at com.sun.jna.Native.invokePointer(Native Method) at com.sun.jna.Function.invokePointer(Function.java:497) at com.sun.jna.Function.invoke(Function.java:441) at com.sun.jna.Function.invoke(Function.java:361) at com.sun.jna.Library$Handler.invoke(Library.java:270) at jdk.proxy1/jdk.proxy1.$Proxy3.gst_parse_launch(Unknown Source) at org.freedesktop.gstreamer.Gst.parseLaunch(Gst.java:225) at org.freedesktop.gstreamer.Gst.parseLaunch(Gst.java:256) at com.cisco.jtapi.collabEdgeIvr.collabEdgeIvr.main(collabEdgeIvr.java:253)

Line 253: pipeline = (Pipeline) Gst.parseLaunch(pipeGreetingsDesc); Looks like something is happening to the Gst object pointer which turns out to be a null for some reason.

neilcsmith-net commented 1 year ago

Can you replicate with the BasicPipeline example at https://github.com/gstreamer-java/gst1-java-examples/tree/master/BasicPipeline ?

What's the relation with com.cisco.jtapi.collabEdgeIvr?

Unfortunately we don't have CI testing on 1.22 at the moment. It could be that updates are required in the bindings. If this is for a commercial project, please contact me as covered in the readme.

AmitAkuka commented 1 year ago

Can you replicate with the BasicPipeline example at https://github.com/gstreamer-java/gst1-java-examples/tree/master/BasicPipeline ?

What's the relation with com.cisco.jtapi.collabEdgeIvr?

Unfortunately we don't have CI testing on 1.22 at the moment. It could be that updates are required in the bindings. If this is for a commercial project, please contact me as covered in the readme.

Hi Neil, Further to our conversation, here is the code I'm using after I removed the additional dependencies that might be an issue. Thank you for the support.

`package com.cisco.jtapi.collabEdgeIvr;

import java.time.format.DateTimeFormatter; import java.time.LocalDateTime; import java.time.DayOfWeek; import java.time.LocalTime;

import org.freedesktop.gstreamer.Gst; import org.freedesktop.gstreamer.GstObject; import org.freedesktop.gstreamer.Pipeline; import org.freedesktop.gstreamer.State; import org.freedesktop.gstreamer.Bus; import org.freedesktop.gstreamer.Element;

import java.util.List;

public class test { public static Pipeline pipeline; public static Bus bus;

static String greetingsPath;
static String closedPath;
static String pipeGreetingsDesc;
static String pipeClosedDesc;
static String destHost = "192.168.1.50";
static Integer destPort = 16895;
static Boolean isDoneResetParams;

private static DateTimeFormatter dtf = DateTimeFormatter.ofPattern("HH:mm:ss.SS");

private static void log(String msg) {
    System.out.println(dtf.format(LocalDateTime.now()) + " " + msg);
}

public static void main(String[] args) throws

InterruptedException {

    // Initialize the gstreamer-java framework Gst object
    Utils.configurePaths();
    Gst.init();

    while (true) {
        System.out.println("Running");
        isDoneResetParams = false;

        pipeGreetingsDesc = String.format(
                "filesrc location=" + greetingsPath
                        + " ! wavparse ! mulawenc ! rtppcmupay max-ptime=30000000 ! udpsink host=%s port=%s",
                destHost, destPort);

        pipeClosedDesc = String.format(
                "filesrc location=" + closedPath
                        + " ! wavparse ! mulawenc ! rtppcmupay max-ptime=30000000 ! udpsink host=%s port=%s",
                destHost, destPort);

        pipeline = (Pipeline) Gst.parseLaunch(pipeGreetingsDesc);
        bus = (Bus) pipeline.getBus();

        System.out.println(pipeline);
        System.out.println(bus);

        bus.connect(new Bus.EOS() {
            public void endOfStream(GstObject source) {
                Gst.quit();
            }
        });

        pipeline.play();
        System.out.println("PLAYING GREETING");

        Gst.main();
        System.out.println("GREETING ENDED");

        Boolean isOpen = false;
        if (!isOpen) {
            System.out.println("Closed");

            // Cleaning resources.
            List<Element> elements = pipeline.getElements();
            for (Element element : elements) {
                element.dispose();
            }
            pipeline.setState(State.NULL);
            bus.clearSyncHandler();
            Gst.invokeLater(() -> {
                pipeline.dispose();
            });

            pipeline = (Pipeline) Gst.parseLaunch(pipeClosedDesc);
            bus = (Bus) pipeline.getBus();

            System.out.println(pipeline);
            System.out.println(bus);

            bus.connect(new Bus.EOS() {
                public void endOfStream(GstObject source) {
                    Gst.quit();
                }
            });

            pipeline.play();
            System.out.println("PLAYING CLOSING");

            Gst.main();
            System.out.println("CLOSING ENDED");

            while (!isDoneResetParams) {
                log("waiting for isDoneResetParams: " + isDoneResetParams);
                Thread.sleep(1000);
            }
        }
    }
}

public static void resetParams() {
    try {
        System.out.println("Restarting params");

        try {
            if (pipeline.getState().toString().equals("PLAYING")) {
                System.out.print("pipeline is playing, disposing...");
                Gst.quit();
                List<Element> elements = pipeline.getElements();
                for (Element element : elements) {
                    element.dispose();
                }

                pipeline.setState(State.NULL);
                bus.clearSyncHandler();
                Gst.invokeLater(() -> {
                    pipeline.dispose();
                });
            }
        } catch (Exception e) {
            System.out.print("Failed to clean pipeline " + e);
        }

        System.out.println("Done cleaning");

        isDoneResetParams = true;
    } catch (Exception e) {
        System.out.println(e);
    }
}

} `