bytedeco / javacv

Java interface to OpenCV, FFmpeg, and more
Other
7.59k stars 1.59k forks source link

org.bytedeco.javacpp.Pointer.trimMemory() coredump #1421

Open lixiangflyin opened 4 years ago

lixiangflyin commented 4 years ago

I pull many rtmp streams by muti threads.(use startunsafe) And use Callback_Pointer to stop block stream. But catch one problem.

Info from coredump file as below:

Thread 561: (state = IN_NATIVE)

PgFFmpegFrameGrabber add code:

private static int FRAME_READ_TIMEOUT = 60;
// 增加callbacjk 监听
private final AtomicLong lastFrameTime = new AtomicLong(System.currentTimeMillis());
private Consumer<Long> blockCallback = null;
public void subscribeBlockCallBack(Consumer<Long> callback) {
    this.blockCallback = callback;
}
private final org.bytedeco.ffmpeg.avformat.AVIOInterruptCB.Callback_Pointer cp = new org.bytedeco.ffmpeg.avformat.AVIOInterruptCB.Callback_Pointer() {
    @Override
    public int call(Pointer pointer) {
        // 0:continue, 1:exit
        if (lastFrameTime.get() + FRAME_READ_TIMEOUT * 1000 < System.currentTimeMillis()) {
            log.info("frame read timeout {}s. time:{} url:{}", FRAME_READ_TIMEOUT, System.currentTimeMillis(), filename);
            blockCallback.accept(System.currentTimeMillis());
            return 1;
        }
        return 0;
    }
}

startUnsafe method add some code: lastFrameTime.set(System.currentTimeMillis()); oc = avformat_alloc_context(); org.bytedeco.ffmpeg.avformat.AVIOInterruptCB cb = new org.bytedeco.ffmpeg.avformat.AVIOInterruptCB(); cb.callback(cp); oc.interrupt_callback(cb);

want to help.

saudet commented 4 years ago

It's probably just caused by memory corruption. Make sure that your callback function doesn't get garbage collected, for example, by keeping a reference in a field.

lixiangflyin commented 4 years ago

Callback_Pointer ,I need to free memory?

My callback function only contain one log, nothing else.

saudet commented 4 years ago

No, you need to make sure it doesn't get freed.

lixiangflyin commented 4 years ago

some detail info, please. thanks.

saudet commented 4 years ago

Try to set the "org.bytedeco.javacpp.nopointergc" system property to "true" and see what that gives.

lixiangflyin commented 4 years ago

coredump error log, where program run error?

Calling System.gc() and Pointer.trimMemory() in org.bytedeco.ffmpeg.avcodec.AVPacket[address=0xdfc4a0,position=0,limit=1,capacity=1,deallocator=org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0xdfc4a0,deallocatorAddress=0x7f32572166a0]] Collecting org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x0,deallocatorAddress=0x0] Collecting org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x0,deallocatorAddress=0x0] Collecting org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x0,deallocatorAddress=0x0] Collecting org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x0,deallocatorAddress=0x0] Collecting org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x0,deallocatorAddress=0x0] Collecting org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x0,deallocatorAddress=0x0] Collecting org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x0,deallocatorAddress=0x0] Collecting org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x0,deallocatorAddress=0x0] Collecting org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x0,deallocatorAddress=0x0] Collecting org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x0,deallocatorAddress=0x0] Collecting org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x0,deallocatorAddress=0x0] Collecting org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x0,deallocatorAddress=0x0] Collecting org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x0,deallocatorAddress=0x0] Collecting org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x0,deallocatorAddress=0x0] Collecting org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x0,deallocatorAddress=0x0] Collecting org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x0,deallocatorAddress=0x0] Collecting org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x0,deallocatorAddress=0x0] Collecting org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x0,deallocatorAddress=0x0] Collecting org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x0,deallocatorAddress=0x0] Collecting org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x0,deallocatorAddress=0x0] Collecting org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x0,deallocatorAddress=0x0] Collecting org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x0,deallocatorAddress=0x0] Collecting org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x0,deallocatorAddress=0x0] Collecting org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x0,deallocatorAddress=0x0] Collecting org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x0,deallocatorAddress=0x0] Collecting org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x0,deallocatorAddress=0x0] Collecting org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x0,deallocatorAddress=0x0] Collecting org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x0,deallocatorAddress=0x0] Collecting org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x0,deallocatorAddress=0x0] Collecting org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x0,deallocatorAddress=0x0] Calling System.gc() and Pointer.trimMemory() in org.bytedeco.ffmpeg.avcodec.AVPacket[address=0xdfc4a0,position=0,limit=1,capacity=1,deallocator=org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0xdfc4a0,deallocatorAddress=0x7f32572166a0]] Collecting org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x0,deallocatorAddress=0x0] Collecting org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x0,deallocatorAddress=0x0] Collecting org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x0,deallocatorAddress=0x0] Collecting org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x0,deallocatorAddress=0x0] Collecting org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x0,deallocatorAddress=0x0] Collecting org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x0,deallocatorAddress=0x0] Input #0, flv, from 'rtmp://172.22.0.27:8102/xxxxx': Duration: 00:00:00.00 , start: 15.334000 , bitrate: N/A Stream #0:0 : Data: none Stream #0:1 : Audio: aac (LC), 44100 Hz, mono, fltp

Calling System.gc() and Pointer.trimMemory() in org.bytedeco.ffmpeg.avcodec.AVPacket[address=0xdfc4a0,position=0,limit=1,capacity=1,deallocator=org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0xdfc4a0,deallocatorAddress=0x7f32572166a0]] Calling System.gc() and Pointer.trimMemory() in org.bytedeco.ffmpeg.avcodec.AVPacket[address=0xdfc4a0,position=0,limit=1,capacity=1,deallocator=org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0xdfc4a0,deallocatorAddress=0x7f32572166a0]] Calling System.gc() and Pointer.trimMemory() in org.bytedeco.ffmpeg.avcodec.AVPacket[address=0xdfc4a0,position=0,limit=1,capacity=1,deallocator=org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0xdfc4a0,deallocatorAddress=0x7f32572166a0]] Calling System.gc() and Pointer.trimMemory() in org.bytedeco.ffmpeg.avcodec.AVPacket[address=0xdfc4a0,position=0,limit=1,capacity=1,deallocator=org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0xdfc4a0,deallocatorAddress=0x7f32572166a0]] Calling System.gc() and Pointer.trimMemory() in org.bytedeco.ffmpeg.avcodec.AVPacket[address=0xdfc4a0,position=0,limit=1,capacity=1,deallocator=org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0xdfc4a0,deallocatorAddress=0x7f32572166a0]] Calling System.gc() and Pointer.trimMemory() in org.bytedeco.ffmpeg.avcodec.AVPacket[address=0xdfc4a0,position=0,limit=1,capacity=1,deallocator=org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0xdfc4a0,deallocatorAddress=0x7f32572166a0]] Calling System.gc() and Pointer.trimMemory() in org.bytedeco.ffmpeg.avcodec.AVPacket[address=0xdfc4a0,position=0,limit=1,capacity=1,deallocator=org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0xdfc4a0,deallocatorAddress=0x7f32572166a0]] Calling System.gc() and Pointer.trimMemory() in org.bytedeco.ffmpeg.avcodec.AVPacket[address=0xdfc4a0,position=0,limit=1,capacity=1,deallocator=org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0xdfc4a0,deallocatorAddress=0x7f32572166a0]] Deallocating org.bytedeco.ffmpeg.avcodec.AVPacket[address=0xdfc4a0,position=0,limit=1,capacity=1,deallocator=org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0xdfc4a0,deallocatorAddress=0x7f32572166a0]] Calling System.gc() and Pointer.trimMemory() in org.bytedeco.ffmpeg.avcodec.AVPacket[address=0x7f325c5fce60,position=0,limit=1,capacity=1,deallocator=org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x7f325c5fce60,deallocatorAddress=0x7f32572166a0]] Closing org.bytedeco.javacpp.PointerScope@6a38dcfb Releasing org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0xdfe6e0,deallocatorAddress=0x7f32572166a0] Releasing org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0xdff4a0,deallocatorAddress=0x7f32572166a0] Releasing org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0xdc72a0,deallocatorAddress=0x7f325676e8a0] Releasing org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0xdc26a0,deallocatorAddress=0x7f3256770a00] Calling System.gc() and Pointer.trimMemory() in org.bytedeco.ffmpeg.avcodec.AVPacket[address=0x7f325c5fce60,position=0,limit=1,capacity=1,deallocator=org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x7f325c5fce60,deallocatorAddress=0x7f32572166a0]] Collecting org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x0,deallocatorAddress=0x0] Collecting org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x0,deallocatorAddress=0x0] Calling System.gc() and Pointer.trimMemory() in org.bytedeco.ffmpeg.avcodec.AVPacket[address=0x7f325c5fce60,position=0,limit=1,capacity=1,deallocator=org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x7f325c5fce60,deallocatorAddress=0x7f32572166a0]] Collecting org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x0,deallocatorAddress=0x0] Collecting org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x0,deallocatorAddress=0x0] Calling System.gc() and Pointer.trimMemory() in org.bytedeco.ffmpeg.avcodec.AVPacket[address=0x7f325c5fce60,position=0,limit=1,capacity=1,deallocator=org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x7f325c5fce60,deallocatorAddress=0x7f32572166a0]] Calling System.gc() and Pointer.trimMemory() in org.bytedeco.ffmpeg.avcodec.AVPacket[address=0x7f325c5fce60,position=0,limit=1,capacity=1,deallocator=org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x7f325c5fce60,deallocatorAddress=0x7f32572166a0]] Calling System.gc() and Pointer.trimMemory() in org.bytedeco.ffmpeg.avcodec.AVPacket[address=0x7f325c5fce60,position=0,limit=1,capacity=1,deallocator=org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x7f325c5fce60,deallocatorAddress=0x7f32572166a0]] Calling System.gc() and Pointer.trimMemory() in org.bytedeco.ffmpeg.avcodec.AVPacket[address=0x7f325c5fce60,position=0,limit=1,capacity=1,deallocator=org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x7f325c5fce60,deallocatorAddress=0x7f32572166a0]] Calling System.gc() and Pointer.trimMemory() in org.bytedeco.ffmpeg.avcodec.AVPacket[address=0x7f325c5fce60,position=0,limit=1,capacity=1,deallocator=org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x7f325c5fce60,deallocatorAddress=0x7f32572166a0]] Calling System.gc() and Pointer.trimMemory() in org.bytedeco.ffmpeg.avcodec.AVPacket[address=0x7f325c5fce60,position=0,limit=1,capacity=1,deallocator=org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x7f325c5fce60,deallocatorAddress=0x7f32572166a0]] Calling System.gc() and Pointer.trimMemory() in org.bytedeco.ffmpeg.avcodec.AVPacket[address=0x7f325c5fce60,position=0,limit=1,capacity=1,deallocator=org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x7f325c5fce60,deallocatorAddress=0x7f32572166a0]] Deallocating org.bytedeco.ffmpeg.avcodec.AVPacket[address=0x7f325c5fce60,position=0,limit=1,capacity=1,deallocator=org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x7f325c5fce60,deallocatorAddress=0x7f32572166a0]] Closing org.bytedeco.javacpp.PointerScope@4924d750 Releasing org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x7f325c5face0,deallocatorAddress=0x7f32572166a0] Releasing org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x7f325c349260,deallocatorAddress=0x7f32572166a0] Releasing org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x7f325c2ba4a0,deallocatorAddress=0x7f325676e8a0] Releasing org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x7f325c2bab20,deallocatorAddress=0x7f3256770a00] Opening org.bytedeco.javacpp.PointerScope@7459bf2a Calling System.gc() and Pointer.trimMemory() in com.mt.service.goods.audio.service.frameworkImpl.CustomFFmpegFrameGrabber$1[address=0xe00d60,position=0,limit=1,capacity=1,deallocator=org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0xe00d60,deallocatorAddress=0x7f3256770a00]] Collecting org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x0,deallocatorAddress=0x0] Collecting org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x0,deallocatorAddress=0x0] Calling System.gc() and Pointer.trimMemory() in com.mt.service.goods.audio.service.frameworkImpl.CustomFFmpegFrameGrabber$1[address=0xe00d60,position=0,limit=1,capacity=1,deallocator=org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0xe00d60,deallocatorAddress=0x7f3256770a00]] Collecting org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x0,deallocatorAddress=0x0] Collecting org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x0,deallocatorAddress=0x0] Calling System.gc() and Pointer.trimMemory() in com.mt.service.goods.audio.service.frameworkImpl.CustomFFmpegFrameGrabber$1[address=0xe00d60,position=0,limit=1,capacity=1,deallocator=org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0xe00d60,deallocatorAddress=0x7f3256770a00]] Calling System.gc() and Pointer.trimMemory() in com.mt.service.goods.audio.service.frameworkImpl.CustomFFmpegFrameGrabber$1[address=0xe00d60,position=0,limit=1,capacity=1,deallocator=org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0xe00d60,deallocatorAddress=0x7f3256770a00]] Calling System.gc() and Pointer.trimMemory() in com.mt.service.goods.audio.service.frameworkImpl.CustomFFmpegFrameGrabber$1[address=0xe00d60,position=0,limit=1,capacity=1,deallocator=org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0xe00d60,deallocatorAddress=0x7f3256770a00]] Calling System.gc() and Pointer.trimMemory() in com.mt.service.goods.audio.service.frameworkImpl.CustomFFmpegFrameGrabber$1[address=0xe00d60,position=0,limit=1,capacity=1,deallocator=org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0xe00d60,deallocatorAddress=0x7f3256770a00]] Calling System.gc() and Pointer.trimMemory() in com.mt.service.goods.audio.service.frameworkImpl.CustomFFmpegFrameGrabber$1[address=0xe00d60,position=0,limit=1,capacity=1,deallocator=org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0xe00d60,deallocatorAddress=0x7f3256770a00]] Calling System.gc() and Pointer.trimMemory() in com.mt.service.goods.audio.service.frameworkImpl.CustomFFmpegFrameGrabber$1[address=0xe00d60,position=0,limit=1,capacity=1,deallocator=org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0xe00d60,deallocatorAddress=0x7f3256770a00]] Calling System.gc() and Pointer.trimMemory() in com.mt.service.goods.audio.service.frameworkImpl.CustomFFmpegFrameGrabber$1[address=0xe00d60,position=0,limit=1,capacity=1,deallocator=org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0xe00d60,deallocatorAddress=0x7f3256770a00]] Calling System.gc() and Pointer.trimMemory() in com.mt.service.goods.audio.service.frameworkImpl.CustomFFmpegFrameGrabber$1[address=0xe00d60,position=0,limit=1,capacity=1,deallocator=org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0xe00d60,deallocatorAddress=0x7f3256770a00]] Deallocating com.mt.service.goods.audio.service.frameworkImpl.CustomFFmpegFrameGrabber$1[address=0xe00d60,position=0,limit=1,capacity=1,deallocator=org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0xe00d60,deallocatorAddress=0x7f3256770a00]] Closing org.bytedeco.javacpp.PointerScope@7459bf2a Opening org.bytedeco.javacpp.PointerScope@728dad57 Calling System.gc() and Pointer.trimMemory() in com.mt.service.goods.audio.service.frameworkImpl.CustomFFmpegFrameGrabber$1[address=0x7f9d182bac20,position=0,limit=1,capacity=1,deallocator=org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x7f9d182bac20,deallocatorAddress=0x7f9ca7b58a00]]

A fatal error has been detected by the Java Runtime Environment: SIGBUS (0x7) at pc=0x00007f3301e9945b, pid=1, tid=0x00007f3251e5c700 JRE version: Java(TM) SE Runtime Environment (8.0_191-b12) (build 1.8.0_191-b12) Java VM: Java HotSpot(TM) 64-Bit Server VM (25.191-b12 mixed mode linux-amd64 compressed oops) Problematic frame: C [libc.so.6+0x7e45b]# [ timer expired, abort... ] [thread 139855668598528 also had an error]

saudet commented 4 years ago

You did not set "org.bytedeco.javacpp.nopointergc" to "true". Please set that system property and try again.