help wantedquestion
Repository metrics
- Stars
- (6,985 stars)
- PR merge metrics
- (No merged PRs in 30d)
Description
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)
- org.bytedeco.javacpp.Pointer.trimMemory() @bci=0 (Interpreted frame)
- org.bytedeco.javacpp.Pointer.deallocator(org.bytedeco.javacpp.Pointer$Deallocator) @bci=214, line=640 (Interpreted frame)
- org.bytedeco.javacpp.Pointer.init(long, long, long, long) @bci=47, line=127 (Compiled frame)
- org.bytedeco.ffmpeg.avformat.AVIOInterruptCB$Callback_Pointer.allocate() @bci=0 (Compiled frame)
- org.bytedeco.ffmpeg.avformat.AVIOInterruptCB$Callback_Pointer.() @bci=5, line=49 (Compiled frame)
- com.pd.service.mt.audio.service.frameworkImpl.PgFFmpegFrameGrabber$1.(com.pd.service.mt.audio.service.frameworkImpl.PgFFmpegFrameGrabber) @bci=6, line=119 (Compiled frame)
- com.pd.service.mt.audio.service.frameworkImpl.PgFFmpegFrameGrabber.(java.lang.String) @bci=29, line=119 (Compiled frame)
- com.pd.service.mt.audio.service.common.CustomFFmpegFrameGrabber.(java.lang.String, java.lang.Integer) @bci=20, line=35 (Compiled frame)
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.