processing / processing-video

GStreamer-based video library for Processing
276 stars 130 forks source link

Video Library Release 3 (version 2.0-beta1) - WARNING: no real random source present #104

Closed cacheflowe closed 5 years ago

cacheflowe commented 5 years ago

I've been using version 2.0-beta1 of the video library on some long-running projects and it's been working great - it especially helped me play 4k video at a good frame rate, where the last official video library release can't play 4k video very well, even on a fast new machine.

There's one issue that keeps popping up for me on multiple Windows 10 machines (I'm not sure if it happens on other platforms, but I think it also happened on my Mac). Videos often won't load, and my app will hang. If I wait long enough, I'll get the following error in the console:

WARNING: no real random source present

This seems to be a gstreamer error that I can't quite figure out as it's deep under the hood and intermittent. It seems to not matter what the video codec/encoding is. It also seems to stay stuck, and I can't relaunch my app with a video playing successfully until this error shows up in the console. After this error message appears, I can usually launch my app w/video playing again. So it seems like some rogue process is hanging and prevents future videos from working until it finally dies.

I'm happy to help test this if anyone else has encountered it and has an idea of how to investigate.

neilcsmith-net commented 5 years ago

Which version of GStreamer are you using? Also maybe try gst1-java-core 0.9.4 and JNA 5.2, although it's more likely to be a problem in the native library.

cacheflowe commented 5 years ago

I'm using everything the the 2.0 beta1 release, except for gst-java-core and now the newer jna. It seems to have helped a tiny bit, though without fail, my app doesn't fully exit when I quit. There's still the hanging process issue. I'm using Eclipse and can see the app doesn't fully terminate until I hit the red stop button. It now gives me the WARNING: no real random source present error when I quit my app sometimes, which didn't seem to happen at that specific time before. So, the results aren't much different yet. I'll look at using the older gstreamer binaries, if that's even possible. Thanks @neilcsmith-net !

neilcsmith-net commented 5 years ago

@cacheflowe older GStreamer binaries?! If anything, you should be looking to test with the latest stable upstream release (eg. 1.14.4 as below). I'm not sure how easy it is to override the library loading procedure in the Video library to just use an installed GStreamer though, and you may have some fun setting up PATH too. You could always test in PraxisLIVE, which uses its own support for integrating gst1-java-core with Processing, and works with a system installed GStreamer. It might at least help narrow down what's causing this.

https://gstreamer.freedesktop.org/ https://gstreamer.freedesktop.org/data/pkg/windows/1.14.4/gstreamer-1.0-x86_64-1.14.4.msi

cacheflowe commented 5 years ago

@neilcsmith-net Thanks so much for the direction here. When I mentioned an older version, I wasn't sure if this video library pre-release (1.0.2) would have any better combination of new Java and updated gstreamer natives. Upon inspection, it looks like the natives are exactly the same as the 2.0 beta1 version though, so that didn't help.

I grabbed new DLLs from the latest gstreamer for Windows and just dropped those into my project (overwriting old natives), which I didn't think would work. It did, though I couldn't solve a bunch of Failed to load plugin errors. But, videos played normally and it no longer hangs and disallows new videos to play. Now I get the WARNING: no real random source present every time I play a video, which seems to be better behavior than before, when it was very intermittent. I still have a hung process that doesn't let my app terminate, but at least my videos play every time, which is cool 😬 It seems that this no real random source present error is the sign of a process dying that lets me start a video. So, a slight improvement for now 🤷‍♂️

neilcsmith-net commented 5 years ago

@cacheflowe I pointed to the latest GStreamer as 1.14.4 for a reason - odd numbered releases are unstable! :wink: If you can either try PraxisLIVE or the examples for gst1-java-core (such as PlayBinVideoPlayer [1]) with a system installed GStreamer it might help narrow down if the issue is caused by the way the Video library is loading GStreamer natives. If you're using the examples rather than PraxisLIVE you'll have to either set up GStreamer in your PATH manually (as the first item!), or add JNA Platform and replicate the code at [2].

[1] https://github.com/gstreamer-java/gst1-java-examples/blob/master/src/main/java/org/freedesktop/gstreamer/examples/PlayBinVideoPlayer.java [2] https://github.com/praxis-live/praxis/blob/master/praxis.video.gstreamer/src/org/praxislive/video/gstreamer/components/GStreamerLibrary.java#L50

codeanticode commented 5 years ago

The debug level is set to 1, so no warnings should be printed in the console:

https://github.com/processing/processing-video/blob/master/src/processing/video/Video.java#L197

One can set a different debug level by calling Video.DEBUG_LEVEL = x (the different debug levels are described in this table) before creating any video object.

cacheflowe commented 4 years ago

I'm still seeing this error (WARNING: no real random source present!) very often with the latest video beta release (Release 6 (version 2.0-beta4)). I'm testing with larger videos (4k and larger), and I'm getting a lot of crashing. Many of the crashes have this error message, but some do not.

I'm currently using the bundled gstreamer library on Windows 10. I've also tried the latest system installation of Gstreamer to no avail (v 1.16.2). This is the message I get as the library initializes when I'm using the default 2.0-beta4 release:

Processing video library using GStreamer 1.16.0

Some funky behavior that coincides with the crashes:

This is the most common error I'm seeing when my app crashes (though I see this sometime when a video loops but doesn't cause a crash):

com.sun.jna.Native$1 uncaughtException
WARNING: JNA: Callback org.freedesktop.gstreamer.elements.AppSink$2@4cde62a0 threw the following exception
java.lang.IllegalStateException: Native object has been disposed
    at org.freedesktop.gstreamer.glib.NativeObject.getRawPointer(NativeObject.java:125)
    at org.freedesktop.gstreamer.glib.Natives.getRawPointer(Natives.java:175)
    at org.freedesktop.gstreamer.lowlevel.GTypeMapper$2.toNative(GTypeMapper.java:73)
    at com.sun.jna.Function.convertArgument(Function.java:521)
    at com.sun.jna.Function.invoke(Function.java:345)
    at com.sun.jna.Library$Handler.invoke(Library.java:265)
    at com.sun.proxy.$Proxy21.gst_buffer_unmap(Unknown Source)
    at org.freedesktop.gstreamer.Buffer.unmap(Buffer.java:115)
    at processing.video.Movie$NewSampleListener.newSample(Unknown Source)
    at org.freedesktop.gstreamer.elements.AppSink$2.callback(AppSink.java:232)
    at sun.reflect.GeneratedMethodAccessor5.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.sun.jna.CallbackReference$DefaultCallbackProxy.invokeCallback(CallbackReference.java:520)
    at com.sun.jna.CallbackReference$DefaultCallbackProxy.callback(CallbackReference.java:551)

This often comes with a native library error .log file, that looks like this:

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x000000002a69fdf4, pid=1812, tid=0x0000000000004140
#
# JRE version: Java(TM) SE Runtime Environment (8.0_231-b11) (build 1.8.0_231-b11)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.231-b11 mixed mode windows-amd64 compressed oops)
# Problematic frame:
# C  0x000000002a69fdf4
#
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
#
# 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.
#

And I get a lot of these messages while the video is starting to play for the first time, but I've seen this type of error in the old Video library too, with some videos:

java.lang.NullPointerException
    at processing.opengl.Texture.copyBufferFromSource(Texture.java:827)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at processing.video.Movie$NewSampleListener.newSample(Unknown Source)
    at org.freedesktop.gstreamer.elements.AppSink$2.callback(AppSink.java:232)
    at sun.reflect.GeneratedMethodAccessor5.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.sun.jna.CallbackReference$DefaultCallbackProxy.invokeCallback(CallbackReference.java:520)
    at com.sun.jna.CallbackReference$DefaultCallbackProxy.callback(CallbackReference.java:551)

Sorry for the scattered info - the behavior is unpredictable.

Also, FWIW, I enabled level 4 logging (INFO), and when a looping video gets stuck, I see a ton of logs that point to gstreamer being confused, but I can't make much sense of them. Let me know if those would be helpful to see.

cacheflowe commented 4 years ago

After a lot more testing, it seems that videos larger than 1080p are far more likely to crash the Movie object. I was testing with 8k videos and incrementally smaller down to 1920, and as the videos shrunk, the less likely they were to throw errors. Hopefully this is helpful info.

neilcsmith-net commented 4 years ago

@cacheflowe the "no real random source present" message has no bearing on this. I'd suggest a new issue.

There are two problems I can see in the code without testing it -

  1. https://github.com/processing/processing-video/blob/r6-v2.0-beta4/src/processing/video/Movie.java#L795 This line returns without unmapping the buffer or disposing of the sample. This will lead to memory leaks, and possibly invalid refcounts.

  2. https://github.com/processing/processing/blob/master/core/src/processing/opengl/Texture.java#L815 This method needs to be given something that wraps Sample and Buffer, and calls buffer.unmap() and sample.dispose() when the Texture is done, and the Sample must not be disposed in the AppSink callback. I'm also dubious about any need for the queue - could swap and dispose a single reference here?

Depending on what you need for your project, maybe check out PraxisLIVE for working with Processing OpenGL and GStreamer.

Niek-Okido commented 4 years ago

maybe someone get the same issue than it could be your environment variables : you need to change for example GSTREAMER_ROOT_X86_64 to GSTREAMER_1_0_ROOT_X86_64 otherwise he thinks it's using the 0.10 version

hems commented 3 years ago

GSTREAMER_ROOT_X86_64

I'm trying to figure this issue, i'm wondering if that's the caseon Windows 10?

verybigelephants commented 3 years ago

GSTREAMER_1_0_ROOT_X86_64

there's no such variable/valu in the environment variables

i am still getting this error, both with the new procesing4 and the latest processing3 :( happens when i close the sketch or sometimes randomly when running the sketch with an occasional null pointer exception. the larger the video the more frequent the errors. 1200x800 is allright but 1920 gets the errors all the time on my machine