释放VLCJ MediaPlayer时JVM崩溃

时间:2017-04-09 22:38:17

标签: java jna vlcj

我在OS X 10.11.6上使用Java 8u121,我试图使用VLCJ 3.10.1(使用VLC 2.2.4)转码音频文件(从MP3到OGG Vorbis) 。转码似乎工作正常,但我在发布MediaPlayer时收到错误。

Bellow是我的最小测试代码,基于VLCJ回购中的RipAudioTest

public class VlcjTestMain {

    public static void main(String[] args) throws InterruptedException {
        Path sourceFile = // source file here
        Path targetFile = // target file here

        new NativeDiscovery().discover();
        MediaPlayerFactory factory = new MediaPlayerFactory();
        MediaPlayer player = factory.newHeadlessMediaPlayer();

        CountDownLatch latch = new CountDownLatch(1);
        player.addMediaPlayerEventListener(new MediaPlayerEventAdapter() {
            @Override
            public void finished(MediaPlayer mediaPlayer) {
                latch.countDown();
            }

            @Override
            public void error(MediaPlayer mediaPlayer) {
                System.out.println("Rip failed");
                latch.countDown();
            }
        });

        String transcodeOpts =
                ":sout=#transcode{acodec=vorb,vcodec=dummy}:std{dst=" + targetFile.toAbsolutePath().toString() + ",mux=ogg,access=file}";
        player.playMedia(
                sourceFile.toAbsolutePath().toString(),
                transcodeOpts);

        latch.await();
        System.out.println("Finished!");

        player.release();
        System.out.println("Player released");

        factory.release();
        System.out.println("Factory released");
    }
}

转码成功完成,但在player.release()上,JVM崩溃并出现SIGSEGV错误:

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x00000001224e8649, pid=13561, tid=0x000000000000c253
#
# JRE version: Java(TM) SE Runtime Environment (8.0_121-b13) (build 1.8.0_121-b13)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.121-b13 mixed mode bsd-amd64 compressed oops)
# Problematic frame:
# C  [libvlc.dylib+0x6649]  libvlc_event_send+0x19
#
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#

崩溃日志的其余部分can be seen here

有谁知道可能导致这种情况的原因?

1 个答案:

答案 0 :(得分:0)

我想我能够回答我的问题,感谢caprica的评论。

tl; dr:finished事件发生后,VLC仍会触发另外两个事件:mediaChangednewMedia。如果在释放播放器后发生这种情况,它就会崩溃。

现在,这是我的实验细节......

我在Windows 10上尝试过相同的代码。它有时会有效,但大多数情况下会在java.lang.Error: Invalid memory access上引发错误player.release()

然后我尝试在Thread.sleep(1000)之前添加player.release()语句,我无法重现崩溃。

所以我使用了一个记录大多数事件的事件监听器,并在Thread.sleep(1000)之前保留了player.release()语句。我注意到在finished之后收到了两个事件:第一个mediaChanged,然后是newMedia。这是日志的结尾:

mediaStateChanged
finished
Finished!
mediaChanged
newMedia
[00000000209f45b0] mux_ogg mux: Close [this line logged by VLCJ, not by me]
Player released
Factory released

最后,我还尝试删除sleep语句,但在第二个player.release()事件(而不是第一个newMedia事件)之后调用finished,我也无法&# 39;重现崩溃。

相关问题