Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#8607 closed defect (fixed)

JNI global ref table overflow after av_mediacodec init many times

Reported by: PaulYao Owned by:
Priority: normal Component: avcodec
Version: git-master Keywords: mediacodec
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

Hi
I got this error on Android 4.4.2

Error Log:

E/dalvikvm( 1366): JNI ERROR (app bug): global reference table overflow (max=51200)
W/dalvikvm( 1366): JNI global reference table (0x8cd81008) dump:
W/dalvikvm( 1366):   Last 10 entries (of 51200):
W/dalvikvm( 1366):     51199: 0x433b2880 android.content.res.AssetFileDescriptor
W/dalvikvm( 1366):     51198: 0x416a8f68 java.lang.Class<android.content.res.AssetManager>
W/dalvikvm( 1366):     51197: 0x41938d48 android.content.res.AssetManager
W/dalvikvm( 1366):     51196: 0x4193bef0 java.lang.Class<com.unity3d.player.UnityPlayer>
W/dalvikvm( 1366):     51195: 0x4193aca0 com.unity3d.player.UnityPlayerActivity
W/dalvikvm( 1366):     51194: 0x4193a9a0 java.lang.Class<com.unity3d.player.UnityPlayerActivity>
W/dalvikvm( 1366):     51193: 0x42a365e8 android.media.MediaFormat
W/dalvikvm( 1366):     51192: 0x42a265a0 android.media.MediaCodec
W/dalvikvm( 1366):     51191: 0x4177cdb0 java.lang.Class<android.media.MediaCodec>
W/dalvikvm( 1366):     51190: 0x419b4998 java.lang.Class<android.media.MediaCodec$BufferInfo>
W/dalvikvm( 1366):   Summary:
W/dalvikvm( 1366):       423 of java.lang.Class (254 unique instances)
W/dalvikvm( 1366):         1 of java.lang.Object
W/dalvikvm( 1366):        17 of java.lang.String (17 unique instances)
W/dalvikvm( 1366):       151 of java.lang.ref.WeakReference (151 unique instances)
W/dalvikvm( 1366):         1 of android.content.res.AssetFileDescriptor
W/dalvikvm( 1366):         1 of android.content.res.AssetManager
W/dalvikvm( 1366):         2 of android.view.Surface (1 unique instances)
W/dalvikvm( 1366):         2 of android.os.Handler (2 unique instances)
W/dalvikvm( 1366):         1 of android.util.DisplayMetrics
W/dalvikvm( 1366):         1 of android.view.Display
W/dalvikvm( 1366):         1 of android.os.Bundle
W/dalvikvm( 1366):         1 of android.view.Choreographer
W/dalvikvm( 1366):         1 of android.app.ActivityThread$ApplicationThread
W/dalvikvm( 1366):         3 of android.app.LoadedApk$ReceiverDispatcher$InnerReceiver (3 unique instances)
W/dalvikvm( 1366):         1 of android.app.SharedPreferencesImpl
W/dalvikvm( 1366):         1 of android.hardware.input.InputManager$InputDevicesChangedListener
W/dalvikvm( 1366):         1 of android.app.SharedPreferencesImpl$EditorImpl
W/dalvikvm( 1366):         1 of android.hardware.input.InputManager
W/dalvikvm( 1366):         1 of android.os.HandlerThread
W/dalvikvm( 1366):         1 of android.location.LocationManager
W/dalvikvm( 1366):         1 of android.hardware.display.DisplayManagerGlobal$DisplayManagerCallback
W/dalvikvm( 1366):         2 of android.hardware.display.DisplayManager (1 unique instances)
W/dalvikvm( 1366):         1 of android.opengl.EGLSurface
W/dalvikvm( 1366):         1 of android.opengl.EGLContext
W/dalvikvm( 1366):         1 of android.opengl.EGLDisplay
W/dalvikvm( 1366):         1 of android.media.MediaCodec
W/dalvikvm( 1366):         1 of android.media.AudioManager
W/dalvikvm( 1366):         2 of android.view.Choreographer$FrameDisplayEventReceiver (2 unique instances)
W/dalvikvm( 1366):         1 of android.view.SurfaceView$MyWindow
W/dalvikvm( 1366):         1 of android.view.ViewRootImpl$W
W/dalvikvm( 1366):         1 of android.view.accessibility.AccessibilityManager$1
W/dalvikvm( 1366):         1 of android.view.inputmethod.InputMethodManager$1
W/dalvikvm( 1366):         1 of android.view.inputmethod.InputMethodManager$ControlledInputConnectionWrapper
W/dalvikvm( 1366):         3 of com.unity3d.player.UnityPlayerActivity (1 unique instances)
W/dalvikvm( 1366):         1 of com.unity3d.player.UnityPlayer
W/dalvikvm( 1366):         1 of com.unity3d.player.Camera2Wrapper
W/dalvikvm( 1366):         1 of $Proxy0
W/dalvikvm( 1366):         1 of $Proxy1
W/dalvikvm( 1366):         1 of $Proxy2
W/dalvikvm( 1366):         2 of $Proxy3 (2 unique instances)
W/dalvikvm( 1366):         1 of $Proxy4
W/dalvikvm( 1366):         1 of android.media.MediaFormat
W/dalvikvm( 1366):         1 of $Proxy5
W/dalvikvm( 1366):         1 of org.fmod.FMODAudioDevice
W/dalvikvm( 1366):         1 of $Proxy6
W/dalvikvm( 1366):         1 of android.media.MediaRouter
W/dalvikvm( 1366):         1 of android.media.MediaRouter$Static$1
W/dalvikvm( 1366):         1 of android.media.MediaRouter$Static$Client
W/dalvikvm( 1366):         1 of $Proxy7
W/dalvikvm( 1366):     50554 of java.nio.ByteBuffer[] (4 elements) (50554 unique instances)
E/dalvikvm( 1366): Failed adding to JNI global ref table (51200 entries)

You can see 50554 of java nio bytebuffer in jni global ref table
and i found av_mediacodec create a inputbuffer by ff_AMediaCodec_getInputBuffer at mediacodec_wrapper.c

This inputbuffer didn't DeleteGlobalRef when MediaCodec deleted

Change History (7)

comment:1 by Carl Eugen Hoyos, 4 years ago

Keywords: android added; JNI removed

How can we reproduce this issue?

comment:2 by mateo, 4 years ago

This patch should fix your issue, I don't have an Android device < 5.0 to test it though:
https://ffmpeg.org/pipermail/ffmpeg-devel/2020-April/260163.html

in reply to:  2 comment:3 by PaulYao, 4 years ago

Replying to mateo:

This patch should fix your issue, I don't have an Android device < 5.0 to test it though:
https://ffmpeg.org/pipermail/ffmpeg-devel/2020-April/260163.html

I will test again and report testing result on monday

thanks

comment:4 by PaulYao, 4 years ago

Hi
I have been initializing repeatedly for three days, the problem was not reappeared
and i also tested it on Android 5.1,everything works fine!

Thanks

Last edited 4 years ago by PaulYao (previous) (diff)

comment:5 by mateo, 4 years ago

Thanks, I will apply the patch on master in a few days.

comment:6 by mateo, 4 years ago

Resolution: fixed
Status: newclosed

Patch has been applied on master.

comment:7 by Carl Eugen Hoyos, 4 years ago

Component: undeterminedavcodec
Keywords: mediacodec added; android removed
Version: unspecifiedgit-master
Note: See TracTickets for help on using tickets.