TheWidlarzGroup / react-native-video

A <Video /> component for react-native
https://docs.thewidlarzgroup.com/react-native-video/
MIT License
7.2k stars 2.9k forks source link

ExoPlayer has memory leakage problem #2767

Open RickoNoNo3 opened 2 years ago

RickoNoNo3 commented 2 years ago

Bug

Finally, the application went crashed with a number of out of memory exceptions, after many or several times (depending on the device performance) of mount/unmount/hot-reload operations. This only happens on ExoPlayer, not so on Android Media Player.

Here is a cut of my Android Logcat:

2022-07-14 22:13:31.287 24490-24490/? W/unknown:ReactNative: Calling JS function after bridge has been destroyed: RCTEventEmitter.receiveEvent([3297,"onVideoProgress",{"seekableDuration":3,"playableDuration":3,"currentTime":1.954}])
2022-07-14 22:13:31.288 24490-24490/? W/unknown:ReactNative: Calling JS function after bridge has been destroyed: RCTEventEmitter.receiveEvent([4897,"onVideoEnd",null])
2022-07-14 22:13:33.027 24490-24490/? W/unknown:WrappingUtils: Don't know how to round that drawable: com.facebook.react.views.image.ReactImageDownloadListener$EmptyDrawable@56846f1
2022-07-14 22:13:33.028 24490-24490/? W/unknown:ReactNative: Calling JS function after bridge has been destroyed: RCTEventEmitter.receiveEvent([3297,"onVideoProgress",{"seekableDuration":3,"playableDuration":3,"currentTime":4.777}])
2022-07-14 22:13:33.028 24490-24490/? W/unknown:ReactNative: Calling JS function after bridge has been destroyed: RCTEventEmitter.receiveEvent([89,"onVideoProgress",{"seekableDuration":3,"playableDuration":3,"currentTime":4.134}])
2022-07-14 22:13:33.028 24490-24490/? W/unknown:ReactNative: Calling JS function after bridge has been destroyed: RCTEventEmitter.receiveEvent([89,"onVideoProgress",{"seekableDuration":3,"playableDuration":3,"currentTime":3.032}])
2022-07-14 22:13:33.028 24490-24490/? W/unknown:ReactNative: Calling JS function after bridge has been destroyed: RCTEventEmitter.receiveEvent([3297,"onVideoProgress",{"seekableDuration":3,"playableDuration":3,"currentTime":3.91}])
2022-07-14 22:13:33.028 24490-24490/? W/unknown:ReactNative: Calling JS function after bridge has been destroyed: RCTEventEmitter.receiveEvent([3297,"onVideoProgress",{"seekableDuration":3,"playableDuration":3,"currentTime":5.186}])
2022-07-14 22:13:33.028 24490-24490/? W/unknown:ReactNative: Calling JS function after bridge has been destroyed: RCTEventEmitter.receiveEvent([4897,"onVideoProgress",{"seekableDuration":2.96,"playableDuration":2.96,"currentTime":2.971}])
2022-07-14 22:13:33.028 24490-24490/? W/unknown:ReactNative: Calling JS function after bridge has been destroyed: RCTEventEmitter.receiveEvent([4897,"onVideoProgress",{"seekableDuration":2.96,"playableDuration":2.96,"currentTime":2.971}])
2022-07-14 22:13:33.028 24490-24490/? W/unknown:ReactNative: Calling JS function after bridge has been destroyed: RCTEventEmitter.receiveEvent([3297,"onVideoProgress",{"seekableDuration":3,"playableDuration":3,"currentTime":6.188}])
2022-07-14 22:13:33.624 24490-28550/? E/mypackage: [MemLeak.JavaTrack]: failed to write oom info: Operation not permitted
2022-07-14 22:13:33.624 24490-28550/? W/mypackage: Throwing OutOfMemoryError "Failed to allocate a 65548 byte allocation with 42144 free bytes and 41KB until OOM, target footprint 402653184, growth limit 402653184" (VmSize 50160224 kB)
2022-07-14 22:13:34.800 24490-24490/? W/unknown:ReactNative: Calling JS function after bridge has been destroyed: RCTEventEmitter.receiveEvent([89,"onVideoProgress",{"seekableDuration":3,"playableDuration":3,"currentTime":4.01}])
2022-07-14 22:13:35.039 24490-24490/? W/unknown:ReactNative: Calling JS function after bridge has been destroyed: RCTEventEmitter.receiveEvent([89,"onVideoProgress",{"seekableDuration":3,"playableDuration":3,"currentTime":4.211}])
2022-07-14 22:13:35.301 24490-28550/? E/mypackage: [MemLeak.JavaTrack]: failed to write oom info: Operation not permitted
2022-07-14 22:13:35.301 24490-28550/? W/mypackage: Throwing OutOfMemoryError "Failed to allocate a 65548 byte allocation with 3816 free bytes and 3816B until OOM, target footprint 402653184, growth limit 402653184" (VmSize 50142736 kB)
2022-07-14 22:13:35.488 24490-28529/? E/mypackage: [MemLeak.JavaTrack]: failed to write oom info: Operation not permitted
2022-07-14 22:13:35.488 24490-28529/? W/mypackage: Throwing OutOfMemoryError "Failed to allocate a 65548 byte allocation with 14888 free bytes and 14KB until OOM, target footprint 402653184, growth limit 402653184" (VmSize 50142736 kB)
2022-07-14 22:13:35.829 24490-24490/? W/unknown:ReactNative: Calling JS function after bridge has been destroyed: RCTEventEmitter.receiveEvent([4897,"onVideoProgress",{"seekableDuration":2.96,"playableDuration":2.96,"currentTime":2.971}])
2022-07-14 22:13:35.830 24490-24490/? W/unknown:ReactNative: Calling JS function after bridge has been destroyed: RCTEventEmitter.receiveEvent([89,"onVideoProgress",{"seekableDuration":3,"playableDuration":3,"currentTime":7.798}])
2022-07-14 22:13:36.422 24490-28561/? E/mypackage: [MemLeak.JavaTrack]: failed to write oom info: Operation not permitted
2022-07-14 22:13:36.423 24490-28561/? W/mypackage: Throwing OutOfMemoryError "Failed to allocate a 65548 byte allocation with 13472 free bytes and 13KB until OOM, target footprint 402653184, growth limit 402653184" (VmSize 50142736 kB)
2022-07-14 22:13:36.969 24490-28548/? E/mypackage: [MemLeak.JavaTrack]: failed to write oom info: Operation not permitted
2022-07-14 22:13:36.969 24490-28548/? W/mypackage: Throwing OutOfMemoryError "Failed to allocate a 65548 byte allocation with 14256 free bytes and 13KB until OOM, target footprint 402653184, growth limit 402653184" (VmSize 50055296 kB)
2022-07-14 22:13:37.294 24490-28545/? E/mypackage: [MemLeak.JavaTrack]: failed to write oom info: Operation not permitted
2022-07-14 22:13:37.294 24490-28545/? W/mypackage: Throwing OutOfMemoryError "Failed to allocate a 65548 byte allocation with 14496 free bytes and 14KB until OOM, target footprint 402653184, growth limit 402653184" (VmSize 50055296 kB)
2022-07-14 22:13:37.651 24490-28529/? E/mypackage: [MemLeak.JavaTrack]: failed to write oom info: Operation not permitted
2022-07-14 22:13:37.651 24490-28529/? W/mypackage: Throwing OutOfMemoryError "Failed to allocate a 65552 byte allocation with 15952 free bytes and 15KB until OOM, target footprint 402653184, growth limit 402653184" (VmSize 50055296 kB)
2022-07-14 22:13:38.289 24490-28560/? E/mypackage: [MemLeak.JavaTrack]: failed to write oom info: Operation not permitted
2022-07-14 22:13:38.290 24490-28560/? W/mypackage: Throwing OutOfMemoryError "Failed to allocate a 65548 byte allocation with 5184 free bytes and 5184B until OOM, target footprint 402653184, growth limit 402653184" (VmSize 50037808 kB)
2022-07-14 22:13:38.475 24490-28529/? E/LoadTask: OutOfMemory error loading stream
    java.lang.OutOfMemoryError: Failed to allocate a 65552 byte allocation with 15952 free bytes and 15KB until OOM, target footprint 402653184, growth limit 402653184
        at com.google.android.exoplayer2.upstream.DefaultAllocator.allocate(DefaultAllocator.java:102)
        at com.google.android.exoplayer2.source.SampleQueue.preAppend(SampleQueue.java:624)
        at com.google.android.exoplayer2.source.SampleQueue.sampleData(SampleQueue.java:544)
        at com.google.android.exoplayer2.extractor.mp4.Mp4Extractor.readSample(Mp4Extractor.java:533)
        at com.google.android.exoplayer2.extractor.mp4.Mp4Extractor.read(Mp4Extractor.java:187)
        at com.google.android.exoplayer2.source.ExtractorMediaPeriod$ExtractingLoadable.load(ExtractorMediaPeriod.java:898)
        at com.google.android.exoplayer2.upstream.Loader$LoadTask.run(Loader.java:381)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:929)
2022-07-14 22:13:38.478 24490-24490/? W/unknown:ReactNative: Calling JS function after bridge has been destroyed: RCTEventEmitter.receiveEvent([3297,"onVideoProgress",{"seekableDuration":3,"playableDuration":3,"currentTime":2.506}])
2022-07-14 22:13:38.480 24490-24490/? W/unknown:ReactNative: Calling JS function after bridge has been destroyed: RCTEventEmitter.receiveEvent([3297,"onVideoProgress",{"seekableDuration":3,"playableDuration":3,"currentTime":5.936}])
2022-07-14 22:13:38.480 24490-24490/? W/unknown:ReactNative: Calling JS function after bridge has been destroyed: RCTEventEmitter.receiveEvent([89,"onVideoProgress",{"seekableDuration":3,"playableDuration":3,"currentTime":10.574}])
2022-07-14 22:13:38.480 24490-24490/? W/unknown:ReactNative: Calling JS function after bridge has been destroyed: RCTEventEmitter.receiveEvent([89,"onVideoProgress",{"seekableDuration":3,"playableDuration":3,"currentTime":9.702}])
2022-07-14 22:13:38.480 24490-24490/? W/unknown:ReactNative: Calling JS function after bridge has been destroyed: RCTEventEmitter.receiveEvent([3297,"onVideoProgress",{"seekableDuration":3,"playableDuration":3,"currentTime":6.611}])
2022-07-14 22:13:38.481 24490-24490/? W/unknown:ReactNative: Calling JS function after bridge has been destroyed: RCTEventEmitter.receiveEvent([3297,"onVideoProgress",{"seekableDuration":3,"playableDuration":3,"currentTime":5.186}])
2022-07-14 22:13:38.481 24490-24490/? W/unknown:ReactNative: Calling JS function after bridge has been destroyed: RCTEventEmitter.receiveEvent([4897,"onVideoProgress",{"seekableDuration":2.96,"playableDuration":2.96,"currentTime":9.535}])
2022-07-14 22:13:38.481 24490-24490/? W/unknown:ReactNative: Calling JS function after bridge has been destroyed: RCTEventEmitter.receiveEvent([4897,"onVideoProgress",{"seekableDuration":2.96,"playableDuration":2.96,"currentTime":9.535}])
2022-07-14 22:13:38.481 24490-24490/? W/unknown:ReactNative: Calling JS function after bridge has been destroyed: RCTEventEmitter.receiveEvent([3297,"onVideoProgress",{"seekableDuration":3,"playableDuration":3,"currentTime":7.961}])
2022-07-14 22:13:38.481 24490-24490/? W/unknown:ReactNative: Calling JS function after bridge has been destroyed: RCTEventEmitter.receiveEvent([89,"onVideoEnd",null])
2022-07-14 22:13:38.481 24490-24490/? W/unknown:ReactNative: Calling JS function after bridge has been destroyed: RCTEventEmitter.receiveEvent([3297,"onVideoEnd",null])
2022-07-14 22:13:38.497 24490-24490/? W/unknown:ReactNative: Calling JS function after bridge has been destroyed: RCTEventEmitter.receiveEvent([89,"onVideoProgress",{"seekableDuration":3,"playableDuration":3,"currentTime":7.934}])
2022-07-14 22:13:38.497 24490-24490/? W/unknown:ReactNative: Calling JS function after bridge has been destroyed: RCTEventEmitter.receiveEvent([89,"onVideoProgress",{"seekableDuration":3,"playableDuration":3,"currentTime":6.409}])
2022-07-14 22:13:38.497 24490-24490/? W/unknown:ReactNative: Calling JS function after bridge has been destroyed: RCTEventEmitter.receiveEvent([4897,"onVideoProgress",{"seekableDuration":2.96,"playableDuration":2.96,"currentTime":9.535}])
2022-07-14 22:13:38.497 24490-24490/? W/unknown:ReactNative: Calling JS function after bridge has been destroyed: RCTEventEmitter.receiveEvent([89,"onVideoProgress",{"seekableDuration":3,"playableDuration":3,"currentTime":7.798}])
2022-07-14 22:13:38.497 24490-24490/? W/unknown:ReactNative: Calling JS function after bridge has been destroyed: RCTEventEmitter.receiveEvent([4897,"onVideoEnd",null])
2022-07-14 22:13:39.205 24490-28532/? E/mypackage: [MemLeak.JavaTrack]: failed to write oom info: Operation not permitted
2022-07-14 22:13:39.205 24490-28532/? W/mypackage: Throwing OutOfMemoryError "Failed to allocate a 65548 byte allocation with 28200 free bytes and 27KB until OOM, target footprint 402653184, growth limit 402653184" (VmSize 50055296 kB)
2022-07-14 22:13:39.695 24490-24490/? W/unknown:ReactNative: Calling JS function after bridge has been destroyed: RCTEventEmitter.receiveEvent([89,"onVideoEnd",null])
2022-07-14 22:13:40.407 24490-28550/? E/mypackage: [MemLeak.JavaTrack]: failed to write oom info: Operation not permitted
2022-07-14 22:13:40.407 24490-28550/? W/mypackage: Throwing OutOfMemoryError "Failed to allocate a 65552 byte allocation with 20984 free bytes and 20KB until OOM, target footprint 402653184, growth limit 402653184" (VmSize 50037820 kB)
2022-07-14 22:13:40.407 24490-28550/? E/LoadTask: OutOfMemory error loading stream
    java.lang.OutOfMemoryError: Failed to allocate a 65552 byte allocation with 20984 free bytes and 20KB until OOM, target footprint 402653184, growth limit 402653184
        at com.google.android.exoplayer2.upstream.DefaultAllocator.allocate(DefaultAllocator.java:102)
        at com.google.android.exoplayer2.source.SampleQueue.preAppend(SampleQueue.java:624)
        at com.google.android.exoplayer2.source.SampleQueue.sampleData(SampleQueue.java:544)
        at com.google.android.exoplayer2.extractor.mp4.Mp4Extractor.readSample(Mp4Extractor.java:533)
        at com.google.android.exoplayer2.extractor.mp4.Mp4Extractor.read(Mp4Extractor.java:187)
        at com.google.android.exoplayer2.source.ExtractorMediaPeriod$ExtractingLoadable.load(ExtractorMediaPeriod.java:898)
        at com.google.android.exoplayer2.upstream.Loader$LoadTask.run(Loader.java:381)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:929)
2022-07-14 22:13:41.107 24490-28573/? E/mypackage: [MemLeak.JavaTrack]: failed to write oom info: Operation not permitted
2022-07-14 22:13:41.107 24490-28573/? W/mypackage: Throwing OutOfMemoryError "Failed to allocate a 65548 byte allocation with 5160 free bytes and 5160B until OOM, target footprint 402653184, growth limit 402653184" (VmSize 49915488 kB)
2022-07-14 22:13:41.143 24490-24490/? W/unknown:ReactNative: Calling JS function after bridge has been destroyed: RCTEventEmitter.receiveEvent([3297,"onVideoProgress",{"seekableDuration":3,"playableDuration":3,"currentTime":6.703}])
2022-07-14 22:13:41.380 24490-28548/? E/mypackage: [MemLeak.JavaTrack]: failed to write oom info: Operation not permitted
2022-07-14 22:13:41.380 24490-28548/? W/mypackage: Throwing OutOfMemoryError "Failed to allocate a 65548 byte allocation with 4792 free bytes and 4792B until OOM, target footprint 402653184, growth limit 402653184" (VmSize 49898000 kB)
2022-07-14 22:13:42.506 24490-28565/? E/mypackage: [MemLeak.JavaTrack]: failed to write oom info: Operation not permitted
2022-07-14 22:13:42.506 24490-28565/? W/mypackage: Throwing OutOfMemoryError "Failed to allocate a 65548 byte allocation with 864 free bytes and 864B until OOM, target footprint 402653184, growth limit 402653184" (VmSize 49898000 kB)
2022-07-14 22:13:42.644 24490-28560/? E/mypackage: [MemLeak.JavaTrack]: failed to write oom info: Operation not permitted
2022-07-14 22:13:42.644 24490-28560/? W/mypackage: Throwing OutOfMemoryError "Failed to allocate a 65548 byte allocation with 864 free bytes and 864B until OOM, target footprint 402653184, growth limit 402653184" (VmSize 49898000 kB)
2022-07-14 22:13:43.128 24490-28564/? E/mypackage: [MemLeak.JavaTrack]: failed to write oom info: Operation not permitted
2022-07-14 22:13:43.128 24490-28564/? W/mypackage: Throwing OutOfMemoryError "Failed to allocate a 65548 byte allocation with 240 free bytes and 240B until OOM, target footprint 402653184, growth limit 402653184" (VmSize 49898000 kB)
2022-07-14 22:13:43.262 24490-28648/? E/mypackage: [MemLeak.JavaTrack]: failed to write oom info: Operation not permitted
2022-07-14 22:13:43.263 24490-28648/? W/mypackage: Throwing OutOfMemoryError "Failed to allocate a 4016 byte allocation with 8 free bytes and 8B until OOM, target footprint 402653184, growth limit 402653184" (VmSize 49898000 kB)
2022-07-14 22:13:44.489 24490-28532/? E/mypackage: [MemLeak.JavaTrack]: failed to write oom info: Operation not permitted
2022-07-14 22:13:44.489 24490-28532/? W/mypackage: Throwing OutOfMemoryError "Failed to allocate a 65552 byte allocation with 40 free bytes and 40B until OOM, target footprint 402653184, growth limit 402653184" (VmSize 49880524 kB)
2022-07-14 22:13:44.925 24490-28536/? E/mypackage: [MemLeak.JavaTrack]: failed to write oom info: Operation not permitted
2022-07-14 22:13:44.926 24490-28536/? W/mypackage: Throwing OutOfMemoryError "Failed to allocate a 65548 byte allocation with 232 free bytes and 232B until OOM, target footprint 402653184, growth limit 402653184" (VmSize 49880524 kB)
2022-07-14 22:13:45.062 24490-24544/? E/mypackage: [MemLeak.JavaTrack]: failed to write oom info: Operation not permitted
2022-07-14 22:13:45.062 24490-24544/? W/mypackage: Throwing OutOfMemoryError "Failed to allocate a 56 byte allocation with 16 free bytes and 16B until OOM, target footprint 402653184, growth limit 402653184" (VmSize 49880524 kB)
2022-07-14 22:13:45.604 24490-28540/? E/mypackage: [MemLeak.JavaTrack]: failed to write oom info: Operation not permitted
2022-07-14 22:13:45.604 24490-28540/? W/mypackage: Throwing OutOfMemoryError "Failed to allocate a 65548 byte allocation with 16 free bytes and 16B until OOM, target footprint 402653184, growth limit 402653184" (VmSize 49880524 kB)
2022-07-14 22:13:46.175 24490-28652/? E/mypackage: [MemLeak.JavaTrack]: failed to write oom info: Operation not permitted
2022-07-14 22:13:46.175 24490-28652/? W/mypackage: Throwing OutOfMemoryError "Failed to allocate a 40 byte allocation with 16 free bytes and 16B until OOM, target footprint 402653184, growth limit 402653184" (VmSize 49880524 kB)
2022-07-14 22:13:46.392 24490-24758/? E/mypackage: [MemLeak.JavaTrack]: failed to write oom info: Operation not permitted
2022-07-14 22:13:46.392 24490-24758/? W/mypackage: Throwing OutOfMemoryError "Failed to allocate a 48 byte allocation with 16 free bytes and 16B until OOM, target footprint 402653184, growth limit 402653184" (VmSize 49880524 kB)
2022-07-14 22:13:46.794 24490-28573/? E/mypackage: [MemLeak.JavaTrack]: failed to write oom info: Operation not permitted
2022-07-14 22:13:46.794 24490-28573/? W/mypackage: Throwing OutOfMemoryError "Failed to allocate a 65552 byte allocation with 16 free bytes and 16B until OOM, target footprint 402653184, growth limit 402653184" (VmSize 49880524 kB)
2022-07-14 22:13:47.650 24490-28442/? E/mypackage: [MemLeak.JavaTrack]: failed to write oom info: Operation not permitted
2022-07-14 22:13:47.651 24490-28442/? W/mypackage: Throwing OutOfMemoryError "Failed to allocate a 152 byte allocation with 16 free bytes and 16B until OOM, target footprint 402653184, growth limit 402653184" (VmSize 49880524 kB)
2022-07-14 22:13:47.987 24490-24751/? E/mypackage: [MemLeak.JavaTrack]: failed to write oom info: Operation not permitted
2022-07-14 22:13:47.987 24490-24751/? W/mypackage: Throwing OutOfMemoryError "Failed to allocate a 64 byte allocation with 16 free bytes and 16B until OOM, target footprint 402653184, growth limit 402653184" (VmSize 49880524 kB)
2022-07-14 22:13:48.804 24490-28557/? E/mypackage: [MemLeak.JavaTrack]: failed to write oom info: Operation not permitted
2022-07-14 22:13:48.804 24490-28557/? W/mypackage: Throwing OutOfMemoryError "Failed to allocate a 65548 byte allocation with 0 free bytes and 0B until OOM, target footprint 402653184, growth limit 402653184" (VmSize 49880524 kB)
2022-07-14 22:13:49.100 24490-28538/? E/mypackage: [MemLeak.JavaTrack]: failed to write oom info: Operation not permitted
2022-07-14 22:13:49.100 24490-28538/? W/mypackage: Throwing OutOfMemoryError "Failed to allocate a 32 byte allocation with 0 free bytes and 0B until OOM, target footprint 402653184, growth limit 402653184" (VmSize 49880524 kB)
2022-07-14 22:13:49.685 24490-24490/? E/mypackage: [MemLeak.JavaTrack]: failed to write oom info: Operation not permitted
2022-07-14 22:13:49.685 24490-24490/? W/mypackage: Throwing OutOfMemoryError "Failed to allocate a 760 byte allocation with 400 free bytes and 400B until OOM, target footprint 402653184, growth limit 402653184" (VmSize 49845548 kB)
2022-07-14 22:13:49.825 24490-28548/? E/mypackage: [MemLeak.JavaTrack]: failed to write oom info: Operation not permitted
2022-07-14 22:13:49.825 24490-28548/? W/mypackage: Throwing OutOfMemoryError "Failed to allocate a 65552 byte allocation with 1824 free bytes and 1824B until OOM, target footprint 402653184, growth limit 402653184" (VmSize 49845548 kB)

Platform

Android Exoplayer

Environment info

React native info output:

System:
    OS: Windows 10 10.0.19043
    CPU: (8) x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
    Memory: 5.93 GB / 23.88 GB
  Binaries:
    Node: 16.14.2 - C:\nodejs\node.EXE
    Yarn: 1.22.18 - C:\nodejs\yarn.CMD
    npm: 8.5.0 - C:\nodejs\npm.CMD
    Watchman: Not Found
  SDKs:
    Android SDK:
      API Levels: 28, 29, 30, 31
      Build Tools: 28.0.3, 29.0.2, 29.0.3, 30.0.0, 30.0.2
      System Images: android-28 | Google Play Intel x86 Atom, android-29 | Google APIs Intel x86 Atom
      Android NDK: Not Found
    Windows SDK: Not Found
  IDEs:
    Android Studio: Not Found
    Visual Studio: 16.11.31911.196 (Visual Studio Community 2019)
  Languages:
    Java: javac 13 - C:\Program Files\Java\jdk-13\bin\javac.EXE
  npmPackages:
    @react-native-community/cli: Not Found
    react: 17.0.2 => 17.0.2
    react-native: 0.68.2 => 0.68.2
    react-native-windows: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

Library version: 4.4.5 ~ 5.2.0 ~ 6.0.0-alpha0 all have this problem

Steps To Reproduce

  1. Create a React Native project and install react-native-video
  2. Create a Video component in App, style it as absolute and stretch(or fixed), make it autoplay and silent and playInBackground and repeat and all of the possible way to make it like a background of App View and not bother any other players or applications outside. Prepare several videos with length 1~5s. (see the demo below)
  3. Create a state field in the App, and setInterval to update it regularly. This step is to let the Video component auto refresh many times.
  4. Run the application in an Android device. hold on and wait... until it crashes. ...

demo:

import React from 'react';
import {Dimensions, View} from 'react-native';
import Video from 'react-native-video';

const videos = [require('./video1.mp4'), require('./video2.mp4')];
//// for production release
// const videos = [{uri:'raw/video1'}, {uri:'raw/video2'}]

export default function App() {
  const [src, setSrc] = React.useState(0);
  const [width, setWidth] = React.useState(Dimensions.get('window').width);
  const [height, setHeight] = React.useState(Dimensions.get('window').height);
  React.useEffect(() => {
    setTimeout(() => {
      setSrc((src + 1) % videos.length);
    }, 4000);
  }, [src]);

  return (
    <View
      style={{flex: 1}}
      onLayout={({nativeEvent}) => {
        setWidth(nativeEvent.layout.width);
        setHeight(nativeEvent.layout.height);
      }}>
      <Video
        source={videos[src]}
        style={[
          {
            position: 'absolute',
            top: 0,
            left: 0,
            zIndex: 1,
            width: width,
            height: height,
          },
        ]}
        resizeMode="cover"
        repeat
        allowsExternalPlayback={false}
        ignoreSilentSwitch="obey"
        mixWithOthers="mix"
        muted
        volume={0}
        selectedAudioTrack={{type: 'disabled'}}
        selectedTextTrack={{type: 'disabled'}}
        playWhenInactive
        playInBackground
        disableFocus
      />
    </View>
  );
}

Expected behaviour

  1. Not crash!

Suppose

the reactContext in the module has been catched in unsafe ways. When the context hot changed, the module could not run correctly, but it still had some kind of references to the old reactContext and some others, that makes memory leakages and errors.

RickoNoNo3 commented 2 years ago

Actually, I've tried from 4.4.5 to 6.0.0-alpha0, the problem alway exists.

hmShuvo314 commented 2 years ago

Hi, could you please tell me how you integrated the exoplayer in the first place? I am also using react-native-video and it is working but the loading is very slow for me. I think it is using the media player instead of the exoplayer in my case. Would like to k now how you implemented it. Thanks

RickoNoNo3 commented 2 years ago

@hmShuvo314 The versions before v6.0 (such as v5.x), are documented for this, see the document. You can integrate this library correctly only by following the chapter Android installation. The two integrating options in android/settings.gradle only need to complete one, and be sure to put it at the end of the file, do not put anything below. v6.x has removed the Android Media Player, it can only and automatically use Exoplayer.

c-moyer commented 2 years ago

I've been having the exact same issue for quite some time. If you alternate rendering a Video and another element such as an Image infinitely, the memory eventually runs out. I've seen it crash in as little as 45 minutes with a 1 second delay between each render. This is a problem for us since our app is for digital signage so we require the ability to render multiple media types in a list.

RickoNoNo3 commented 2 years ago

@c-moyer It seems that I'm not in an isolated case.

Our project uses the video component as an animated background, and it switches between several video sources frequently, that causes trouble. We are using Android Media Player implementation now.

c-moyer commented 2 years ago

@RickoNoNo3 I haven't had a chance to review the memory profiler yet with my latest change, but commenting out the following code from react-native.config.js seems to have improved performance.

// module.exports = {
//     dependencies: {
//         'react-native-video': {
//             platforms: {
//                 android: {
//                     sourceDir: '../node_modules/react-native-video/android-exoplayer',
//                 },
//             },
//         },
//     },
// };

I've had the app running now for about 36 hours alternating between two videos and an image with 1 second between each render. With exoplayer, this crashes within 45 minutes. I did notice the UI froze for a couple of minutes about 24 hours in which was odd, but the app didn't crash like it usually does and I didn't receive any bugsnag notifications either. I'll try to do some more digging later this week but it seems like there's some sort of teardown that's missing which is needed specifically for Exoplayer.

c-moyer commented 2 years ago

After running the app for about an hour using Exoplayer, I began getting out of memory errors. Here's a sample of my logcat:

2022-09-14 22:57:51.884 426-23477/? I/MtkOmxVdecExV4L2: [0xa7118a00] -FlushOutputPort -> mNumPendingOutput(0)
2022-09-14 22:57:51.899 426-492/? I/MtkOmxVdecExV4L2: [0xa7118a00] MtkOmxVdec::FreeBuffer all output buffers have been freed!!! signal mOutPortFreeDoneSem(1)
2022-09-14 22:57:57.368 25405-23338/com.digitalsignageplayer W/alsignageplaye: Throwing OutOfMemoryError "Failed to allocate a 65548 byte allocation with 17856 free bytes and 17KB until OOM, max allowed footprint 201326592, growth limit 201326592"
2022-09-14 22:57:57.861 23514-23542/? D/BlackbirdPluginHandler: kso device attributes: {"type":"DeviceAttributes","acceptLanguage":"en-US","apkVersion":"7.5.848.0","appVersion":"dynamic","cor":"US","deviceLocalTime":"America/Chicago","devicePartnerId":"NO_PARTNER_ID","deviceType":"AFTKA","directedId":"amzn1.account.AE3CHNEV5V52ASM2JEW3HVU22DRA","dsn":"G071R207132437JN","idfa":"03fb9eb9-3c8c-405a-976a-22eff9055cfe","launcherVersion":"639002610","optOut":false,"osVersion":"0024126400644","pconState":"0","pconViewingRestrictions":"-1","pfm":"ATVPDKIKX0DER","sha1UDID":"5f4806ce160a07799670accb9b000287302961d3","sisId":"A_riPLQ0gUegsXM-PsbbnD8","userAgent":"Dalvik/2.1.0 (Linux; U; Android 9; AFTKA Build/PS7292.2984N)"}
2022-09-14 22:57:57.988 23514-23542/? D/BlackbirdPluginHandler: kso device attributes: {"type":"DeviceAttributes","acceptLanguage":"en-US","apkVersion":"7.5.848.0","appVersion":"dynamic","cor":"US","deviceLocalTime":"America/Chicago","devicePartnerId":"NO_PARTNER_ID","deviceType":"AFTKA","directedId":"amzn1.account.AE3CHNEV5V52ASM2JEW3HVU22DRA","dsn":"G071R207132437JN","idfa":"03fb9eb9-3c8c-405a-976a-22eff9055cfe","launcherVersion":"639002610","optOut":false,"osVersion":"0024126400644","pconState":"0","pconViewingRestrictions":"-1","pfm":"ATVPDKIKX0DER","sha1UDID":"5f4806ce160a07799670accb9b000287302961d3","sisId":"A_riPLQ0gUegsXM-PsbbnD8","userAgent":"Dalvik/2.1.0 (Linux; U; Android 9; AFTKA Build/PS7292.2984N)"}
2022-09-14 22:58:01.855 25405-23338/com.digitalsignageplayer W/alsignageplaye: Throwing OutOfMemoryError "Failed to allocate a 65552 byte allocation with 13784 free bytes and 13KB until OOM, max allowed footprint 201326592, growth limit 201326592"
2022-09-14 22:58:03.672 25405-23338/com.digitalsignageplayer E/LoadTask: OutOfMemory error loading stream
      java.lang.OutOfMemoryError: Failed to allocate a 65552 byte allocation with 13784 free bytes and 13KB until OOM, max allowed footprint 201326592, growth limit 201326592
        at com.google.android.exoplayer2.upstream.DefaultAllocator.allocate(DefaultAllocator.java:102)
        at com.google.android.exoplayer2.source.SampleDataQueue.preAppend(SampleDataQueue.java:392)
        at com.google.android.exoplayer2.source.SampleDataQueue.sampleData(SampleDataQueue.java:181)
        at com.google.android.exoplayer2.source.SampleQueue.sampleData(SampleQueue.java:471)
        at com.google.android.exoplayer2.extractor.mp4.Mp4Extractor.readSample(Mp4Extractor.java:552)
        at com.google.android.exoplayer2.extractor.mp4.Mp4Extractor.read(Mp4Extractor.java:192)
        at com.google.android.exoplayer2.source.ProgressiveMediaPeriod$ExtractingLoadable.load(ProgressiveMediaPeriod.java:982)
        at com.google.android.exoplayer2.upstream.Loader$LoadTask.run(Loader.java:391)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:764)
2022-09-14 22:58:07.705 426-492/? E/OMXNodeInstance: setParameter(0xa7118344:MTK.DECODER.AVC, OMX.google.android.index.allocateNativeHandle(0x7f20040e): Output:1 en=0) ERROR: BadParameter(0x80001005)
2022-09-14 22:58:07.705 426-29796/? I/MtkOmxVdecExV4L2: [0xa7118340] --- GetOutputPortDefinition --- (176 144 176 160 5 46096 0x7f000001), pPortDef (176 144 176 160 5 46096 0x7f000001)
2022-09-14 22:58:07.707 426-29796/? I/MtkOmxVdecExV4L2: [0xa7118340] --- GetOutputPortDefinition --- (3840 2160 3840 2176 5 12533776 0x7f000001), pPortDef (3840 2160 3840 2176 5 12533776 0x7f000001)
2022-09-14 22:58:07.824 426-29796/? I/MtkOmxVdecExV4L2: [0xa7118340] --- GetOutputPortDefinition --- (3840 2160 3840 2176 5 12533776 0x7f000001), pPortDef (3840 2160 3840 2176 5 12533776 0x7f000001)
2022-09-14 22:58:07.824 426-29796/? I/MtkOmxVdecExV4L2: [0xa7118340] --- GetOutputPortDefinition --- (3840 2160 3840 2176 5 12533776 0x7f000001), pPortDef (3840 2160 3840 2176 5 12533776 0x7f000001)
2022-09-14 22:58:08.107 426-29796/? I/MtkOmxVdecExV4L2: [0xa7118340] --- GetOutputPortDefinition --- (3840 2160 3840 2176 5 12533776 0x7f000003), pPortDef (3840 2160 3840 2176 5 12533776 0x10f)
2022-09-14 22:58:08.114 426-24163/? I/MtkOmxVdecExV4L2: [0xa7118340] [getReconfigOutputPortSetting] u4CheckBufferCount: 13, u4ChagnedDPBSize: 5, mMinUndequeuedBufs: 4, FRAMEWORK_OVERHEAD: 3, MAX_COLORCONVERT_OUTPUTBUFFER_COUNT:1
2022-09-14 22:58:08.116 426-29796/? I/MtkOmxVdecExV4L2: [0xa7118340] --- GetOutputPortDefinition --- (3840 2160 3840 2184 13 12583040 0x7f000003), pPortDef (3840 2160 3840 2184 13 12583040 0x10f)
2022-09-14 22:58:08.117 426-24162/? I/MtkOmxVdecExV4L2: [0xa7118340] --- FTBQ: mNumPendingOutput 1; mFillThisBufQ.size() 1,  CCDst: 0, CCSrc: 0
2022-09-14 22:58:08.117 426-24162/? I/MtkOmxVdecExV4L2: [0xa7118340] -FlushOutputPort -> mNumPendingOutput(0)
2022-09-14 22:58:08.117 426-29796/? I/MtkOmxVdecExV4L2: [0xa7118340] MtkOmxVdec::FreeBuffer all output buffers have been freed!!! signal mOutPortFreeDoneSem(1)
2022-09-14 22:58:08.120 426-24162/? I/MtkOmxVdecExV4L2: [0xa7118340] [getReconfigOutputPortSetting] u4CheckBufferCount: 13, u4ChagnedDPBSize: 5, mMinUndequeuedBufs: 4, FRAMEWORK_OVERHEAD: 3, MAX_COLORCONVERT_OUTPUTBUFFER_COUNT:1
2022-09-14 22:58:08.121 426-492/? I/MtkOmxVdecExV4L2: [0xa7118340] --- GetOutputPortDefinition --- (3840 2160 3840 2184 13 12583040 0x7f000003), pPortDef (3840 2160 3840 2184 13 12583040 0x10f)
2022-09-14 22:58:08.121 426-26744/? I/MtkOmxVdecExV4L2: [0xa7118340] --- GetOutputPortDefinition --- (3840 2160 3840 2184 13 12583040 0x7f000003), pPortDef (3840 2160 3840 2184 13 12583040 0x10f)
2022-09-14 22:58:09.926 426-28806/? I/MtkOmxVdecExV4L2: [0xa7118340] --- GetOutputPortDefinition --- (3840 2160 3840 2184 13 12583040 0x10f), pPortDef (3840 2160 3840 2184 13 12583040 0x10f)
2022-09-14 22:58:09.982 455-484/? I/VCodecDrv: phHandle->fgOutputEarly 0
2022-09-14 22:58:09.983 426-24162/? I/MtkOmxVdecExV4L2: [0xa7118340] --- FTBQ: mNumPendingOutput 2; mFillThisBufQ.size() 0,  CCDst: 0, CCSrc: 0
2022-09-14 22:58:09.983 455-484/? I/VCodecDrv: phHandle->fgOutputEarly 0
2022-09-14 22:58:09.989 426-24162/? I/MtkOmxVdecExV4L2: [0xa7118340] -FlushOutputPort -> mNumPendingOutput(0)
2022-09-14 22:58:10.299 455-484/? I/VCodecDrv: phHandle->fgOutputEarly 0
2022-09-14 22:58:10.300 426-24162/? I/MtkOmxVdecExV4L2: [0xa7118340] --- FTBQ: mNumPendingOutput 9; mFillThisBufQ.size() 7,  CCDst: 0, CCSrc: 0
2022-09-14 22:58:10.300 455-484/? I/VCodecDrv: phHandle->fgOutputEarly 0
2022-09-14 22:58:10.301 426-24162/? I/MtkOmxVdecExV4L2: [0xa7118340] -FlushOutputPort -> mNumPendingOutput(0)
2022-09-14 22:58:10.334 426-28806/? I/MtkOmxVdecExV4L2: [0xa7118340] MtkOmxVdec::FreeBuffer all output buffers have been freed!!! signal mOutPortFreeDoneSem(1)
2022-09-14 22:58:18.193 24380-24429/? D/BlackbirdPluginHandler: kso device attributes: {"type":"DeviceAttributes","acceptLanguage":"en-US","apkVersion":"7.5.848.0","appVersion":"dynamic","cor":"US","deviceLocalTime":"America/Chicago","devicePartnerId":"NO_PARTNER_ID","deviceType":"AFTKA","directedId":"amzn1.account.AE3CHNEV5V52ASM2JEW3HVU22DRA","dsn":"G071R207132437JN","idfa":"03fb9eb9-3c8c-405a-976a-22eff9055cfe","launcherVersion":"639002610","optOut":false,"osVersion":"0024126400644","pconState":"0","pconViewingRestrictions":"-1","pfm":"ATVPDKIKX0DER","sha1UDID":"5f4806ce160a07799670accb9b000287302961d3","sisId":"A_riPLQ0gUegsXM-PsbbnD8","userAgent":"Dalvik/2.1.0 (Linux; U; Android 9; AFTKA Build/PS7292.2984N)"}
2022-09-14 22:58:18.201 24380-24429/? D/BlackbirdPluginHandler: kso device attributes: {"type":"DeviceAttributes","acceptLanguage":"en-US","apkVersion":"7.5.848.0","appVersion":"dynamic","cor":"US","deviceLocalTime":"America/Chicago","devicePartnerId":"NO_PARTNER_ID","deviceType":"AFTKA","directedId":"amzn1.account.AE3CHNEV5V52ASM2JEW3HVU22DRA","dsn":"G071R207132437JN","idfa":"03fb9eb9-3c8c-405a-976a-22eff9055cfe","launcherVersion":"639002610","optOut":false,"osVersion":"0024126400644","pconState":"0","pconViewingRestrictions":"-1","pfm":"ATVPDKIKX0DER","sha1UDID":"5f4806ce160a07799670accb9b000287302961d3","sisId":"A_riPLQ0gUegsXM-PsbbnD8","userAgent":"Dalvik/2.1.0 (Linux; U; Android 9; AFTKA Build/PS7292.2984N)"}
2022-09-14 22:58:19.964 25405-24374/com.digitalsignageplayer W/alsignageplaye: Throwing OutOfMemoryError "Failed to allocate a 65548 byte allocation with 53152 free bytes and 51KB until OOM, max allowed footprint 201326592, growth limit 201326592"
2022-09-14 22:58:23.995 25405-24374/com.digitalsignageplayer W/alsignageplaye: Throwing OutOfMemoryError "Failed to allocate a 65552 byte allocation with 53392 free bytes and 52KB until OOM, max allowed footprint 201326592, growth limit 201326592"
2022-09-14 22:58:24.067 25405-24374/com.digitalsignageplayer E/LoadTask: OutOfMemory error loading stream
      java.lang.OutOfMemoryError: Failed to allocate a 65552 byte allocation with 53392 free bytes and 52KB until OOM, max allowed footprint 201326592, growth limit 201326592
        at com.google.android.exoplayer2.upstream.DefaultAllocator.allocate(DefaultAllocator.java:102)
        at com.google.android.exoplayer2.source.SampleDataQueue.preAppend(SampleDataQueue.java:392)
        at com.google.android.exoplayer2.source.SampleDataQueue.sampleData(SampleDataQueue.java:181)
        at com.google.android.exoplayer2.source.SampleQueue.sampleData(SampleQueue.java:471)
        at com.google.android.exoplayer2.extractor.mp4.Mp4Extractor.readSample(Mp4Extractor.java:552)
        at com.google.android.exoplayer2.extractor.mp4.Mp4Extractor.read(Mp4Extractor.java:192)
        at com.google.android.exoplayer2.source.ProgressiveMediaPeriod$ExtractingLoadable.load(ProgressiveMediaPeriod.java:982)
        at com.google.android.exoplayer2.upstream.Loader$LoadTask.run(Loader.java:391)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:764)
2022-09-14 22:58:24.913 426-28806/? E/OMXNodeInstance: setParameter(0xa7118544:MTK.DECODER.AVC, OMX.google.android.index.allocateNativeHandle(0x7f20040e): Output:1 en=0) ERROR: BadParameter(0x80001005)
2022-09-14 22:58:24.913 426-28806/? I/MtkOmxVdecExV4L2: [0xa7118540] --- GetOutputPortDefinition --- (176 144 176 160 5 46096 0x7f000001), pPortDef (176 144 176 160 5 46096 0x7f000001)
2022-09-14 22:58:24.915 426-28806/? I/MtkOmxVdecExV4L2: [0xa7118540] --- GetOutputPortDefinition --- (3840 2160 3840 2176 5 12533776 0x7f000001), pPortDef (3840 2160 3840 2176 5 12533776 0x7f000001)
2022-09-14 22:58:25.019 426-492/? I/MtkOmxVdecExV4L2: [0xa7118540] --- GetOutputPortDefinition --- (3840 2160 3840 2176 5 12533776 0x7f000001), pPortDef (3840 2160 3840 2176 5 12533776 0x7f000001)
2022-09-14 22:58:25.020 426-492/? I/MtkOmxVdecExV4L2: [0xa7118540] --- GetOutputPortDefinition --- (3840 2160 3840 2176 5 12533776 0x7f000001), pPortDef (3840 2160 3840 2176 5 12533776 0x7f000001)
2022-09-14 22:58:25.237 426-24827/? I/MtkOmxVdecExV4L2: [0xa7118540] [getReconfigOutputPortSetting] u4CheckBufferCount: 13, u4ChagnedDPBSize: 5, mMinUndequeuedBufs: 4, FRAMEWORK_OVERHEAD: 3, MAX_COLORCONVERT_OUTPUTBUFFER_COUNT:1
2022-09-14 22:58:25.239 426-492/? I/MtkOmxVdecExV4L2: [0xa7118540] --- GetOutputPortDefinition --- (3840 2160 3840 2184 13 12583040 0x7f000003), pPortDef (3840 2160 3840 2184 13 12583040 0x10f)
2022-09-14 22:58:25.240 426-492/? I/MtkOmxVdecExV4L2: [0xa7118540] --- GetOutputPortDefinition --- (3840 2160 3840 2184 13 12583040 0x7f000003), pPortDef (3840 2160 3840 2184 13 12583040 0x10f)
2022-09-14 22:58:25.241 426-24826/? I/MtkOmxVdecExV4L2: [0xa7118540] --- FTBQ: mNumPendingOutput 1; mFillThisBufQ.size() 1,  CCDst: 0, CCSrc: 0
2022-09-14 22:58:25.241 426-24826/? I/MtkOmxVdecExV4L2: [0xa7118540] -FlushOutputPort -> mNumPendingOutput(0)
2022-09-14 22:58:25.242 426-26744/? I/MtkOmxVdecExV4L2: [0xa7118540] MtkOmxVdec::FreeBuffer all output buffers have been freed!!! signal mOutPortFreeDoneSem(1)
2022-09-14 22:58:25.242 426-24826/? I/MtkOmxVdecExV4L2: [0xa7118540] [getReconfigOutputPortSetting] u4CheckBufferCount: 13, u4ChagnedDPBSize: 5, mMinUndequeuedBufs: 4, FRAMEWORK_OVERHEAD: 3, MAX_COLORCONVERT_OUTPUTBUFFER_COUNT:1
2022-09-14 22:58:25.243 426-26744/? I/MtkOmxVdecExV4L2: [0xa7118540] --- GetOutputPortDefinition --- (3840 2160 3840 2184 13 12583040 0x7f000003), pPortDef (3840 2160 3840 2184 13 12583040 0x10f)
2022-09-14 22:58:25.243 426-26744/? I/MtkOmxVdecExV4L2: [0xa7118540] --- GetOutputPortDefinition --- (3840 2160 3840 2184 13 12583040 0x7f000003), pPortDef (3840 2160 3840 2184 13 12583040 0x10f)
2022-09-14 22:58:25.303 426-26744/? I/MtkOmxVdecExV4L2: [0xa7118540] --- GetOutputPortDefinition --- (3840 2160 3840 2184 13 12583040 0x10f), pPortDef (3840 2160 3840 2184 13 12583040 0x10f)
2022-09-14 22:58:25.321 25405-24373/com.digitalsignageplayer E/ExoPlayerImplInternal: Source error
      com.google.android.exoplayer2.upstream.Loader$UnexpectedLoaderException: Unexpected OutOfMemoryError: Failed to allocate a 65552 byte allocation with 53392 free bytes and 52KB until OOM, max allowed footprint 201326592, growth limit 201326592
        at com.google.android.exoplayer2.upstream.Loader$LoadTask.run(Loader.java:421)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:764)
     Caused by: java.lang.OutOfMemoryError: Failed to allocate a 65552 byte allocation with 53392 free bytes and 52KB until OOM, max allowed footprint 201326592, growth limit 201326592
        at com.google.android.exoplayer2.upstream.DefaultAllocator.allocate(DefaultAllocator.java:102)
        at com.google.android.exoplayer2.source.SampleDataQueue.preAppend(SampleDataQueue.java:392)
        at com.google.android.exoplayer2.source.SampleDataQueue.sampleData(SampleDataQueue.java:181)
        at com.google.android.exoplayer2.source.SampleQueue.sampleData(SampleQueue.java:471)
        at com.google.android.exoplayer2.extractor.mp4.Mp4Extractor.readSample(Mp4Extractor.java:552)
        at com.google.android.exoplayer2.extractor.mp4.Mp4Extractor.read(Mp4Extractor.java:192)
        at com.google.android.exoplayer2.source.ProgressiveMediaPeriod$ExtractingLoadable.load(ProgressiveMediaPeriod.java:982)
        at com.google.android.exoplayer2.upstream.Loader$LoadTask.run(Loader.java:391)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) 
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 
        at java.lang.Thread.run(Thread.java:764) 
2022-09-14 22:58:25.322 455-484/? I/VCodecDrv: phHandle->fgOutputEarly 0
2022-09-14 22:58:25.323 426-24826/? I/MtkOmxVdecExV4L2: [0xa7118540] --- FTBQ: mNumPendingOutput 2; mFillThisBufQ.size() 0,  CCDst: 0, CCSrc: 0
2022-09-14 22:58:25.323 455-484/? I/VCodecDrv: phHandle->fgOutputEarly 0
2022-09-14 22:58:25.325 426-24826/? I/MtkOmxVdecExV4L2: [0xa7118540] -FlushOutputPort -> mNumPendingOutput(0)
2022-09-14 22:58:25.688 455-484/? I/VCodecDrv: phHandle->fgOutputEarly 0
2022-09-14 22:58:25.689 426-24826/? I/MtkOmxVdecExV4L2: [0xa7118540] --- FTBQ: mNumPendingOutput 9; mFillThisBufQ.size() 8,  CCDst: 0, CCSrc: 0
2022-09-14 22:58:25.689 455-484/? I/VCodecDrv: phHandle->fgOutputEarly 0
2022-09-14 22:58:25.691 426-24826/? I/MtkOmxVdecExV4L2: [0xa7118540] -FlushOutputPort -> mNumPendingOutput(0)
2022-09-14 22:58:25.707 426-29796/? I/MtkOmxVdecExV4L2: [0xa7118540] MtkOmxVdec::FreeBuffer all output buffers have been freed!!! signal mOutPortFreeDoneSem(1)
2022-09-14 22:58:28.814 426-29796/? E/OMXNodeInstance: setParameter(0xa7118d44:MTK.DECODER.AVC, OMX.google.android.index.allocateNativeHandle(0x7f20040e): Output:1 en=0) ERROR: BadParameter(0x80001005)
2022-09-14 22:58:28.815 426-29796/? I/MtkOmxVdecExV4L2: [0xa7118d40] --- GetOutputPortDefinition --- (176 144 176 160 5 46096 0x7f000001), pPortDef (176 144 176 160 5 46096 0x7f000001)
2022-09-14 22:58:28.818 426-29796/? I/MtkOmxVdecExV4L2: [0xa7118d40] --- GetOutputPortDefinition --- (3840 2160 3840 2176 5 12533776 0x7f000001), pPortDef (3840 2160 3840 2176 5 12533776 0x7f000001)
2022-09-14 22:58:28.879 426-29796/? I/MtkOmxVdecExV4L2: [0xa7118d40] --- GetOutputPortDefinition --- (3840 2160 3840 2176 5 12533776 0x7f000001), pPortDef (3840 2160 3840 2176 5 12533776 0x7f000001)
2022-09-14 22:58:28.879 426-29796/? I/MtkOmxVdecExV4L2: [0xa7118d40] --- GetOutputPortDefinition --- (3840 2160 3840 2176 5 12533776 0x7f000001), pPortDef (3840 2160 3840 2176 5 12533776 0x7f000001)
2022-09-14 22:58:29.065 426-28806/? I/MtkOmxVdecExV4L2: [0xa7118d40] --- GetOutputPortDefinition --- (3840 2160 3840 2176 5 12533776 0x7f000001), pPortDef (3840 2160 3840 2176 5 12533776 0x7f000001)
2022-09-14 22:58:29.066 426-24937/? I/MtkOmxVdecExV4L2: [0xa7118d40] [getReconfigOutputPortSetting] u4CheckBufferCount: 13, u4ChagnedDPBSize: 5, mMinUndequeuedBufs: 4, FRAMEWORK_OVERHEAD: 3, MAX_COLORCONVERT_OUTPUTBUFFER_COUNT:1
2022-09-14 22:58:29.069 455-484/? I/VCodecDrv: phHandle->fgOutputEarly 0
2022-09-14 22:58:29.070 426-24936/? I/MtkOmxVdecExV4L2: [0xa7118d40] --- FTBQ: mNumPendingOutput 1; mFillThisBufQ.size() 1,  CCDst: 0, CCSrc: 0
2022-09-14 22:58:29.070 426-24936/? I/MtkOmxVdecExV4L2: [0xa7118d40] -FlushOutputPort -> mNumPendingOutput(0)
2022-09-14 22:58:29.075 426-28806/? I/MtkOmxVdecExV4L2: [0xa7118d40] --- GetOutputPortDefinition --- (3840 2160 3840 2184 13 12583040 0x7f000003), pPortDef (3840 2160 3840 2184 13 12583040 0x10f)
2022-09-14 22:58:29.076 426-28806/? I/MtkOmxVdecExV4L2: [0xa7118d40] --- GetOutputPortDefinition --- (3840 2160 3840 2184 13 12583040 0x7f000003), pPortDef (3840 2160 3840 2184 13 12583040 0x10f)
2022-09-14 22:58:29.077 426-24936/? I/MtkOmxVdecExV4L2: [0xa7118d40] --- FTBQ: mNumPendingOutput 0; mFillThisBufQ.size() 0,  CCDst: 0, CCSrc: 0
2022-09-14 22:58:29.077 426-24936/? I/MtkOmxVdecExV4L2: [0xa7118d40] -FlushOutputPort -> mNumPendingOutput(0)
2022-09-14 22:58:29.077 426-28806/? I/MtkOmxVdecExV4L2: [0xa7118d40] MtkOmxVdec::FreeBuffer all output buffers have been freed!!! signal mOutPortFreeDoneSem(1)
2022-09-14 22:58:29.079 426-24936/? I/MtkOmxVdecExV4L2: [0xa7118d40] [getReconfigOutputPortSetting] u4CheckBufferCount: 13, u4ChagnedDPBSize: 5, mMinUndequeuedBufs: 4, FRAMEWORK_OVERHEAD: 3, MAX_COLORCONVERT_OUTPUTBUFFER_COUNT:1
2022-09-14 22:58:29.092 426-492/? I/MtkOmxVdecExV4L2: [0xa7118d40] --- GetOutputPortDefinition --- (3840 2160 3840 2184 13 12583040 0x7f000003), pPortDef (3840 2160 3840 2184 13 12583040 0x10f)
2022-09-14 22:58:29.092 426-28806/? I/MtkOmxVdecExV4L2: [0xa7118d40] --- GetOutputPortDefinition --- (3840 2160 3840 2184 13 12583040 0x7f000003), pPortDef (3840 2160 3840 2184 13 12583040 0x10f)
2022-09-14 22:58:29.095 455-484/? I/VCodecDrv: phHandle->fgOutputEarly 0
2022-09-14 22:58:29.097 426-24936/? I/MtkOmxVdecExV4L2: [0xa7118d40] --- FTBQ: mNumPendingOutput 0; mFillThisBufQ.size() 0,  CCDst: 0, CCSrc: 0

The final memory error as my app crashed:

2022-09-14 23:01:38.166 25405-25264/com.digitalsignageplayer E/AndroidRuntime: FATAL EXCEPTION: Loader:ProgressiveMediaPeriod
    Process: com.digitalsignageplayer, PID: 25405
    java.lang.OutOfMemoryError: OutOfMemoryError thrown while trying to throw OutOfMemoryError; no stack trace available
2022-09-14 23:02:17.829 25405-25469/com.digitalsignageplayer W/alsignageplaye: Throwing OutOfMemoryError "Failed to allocate a 120 byte allocation with 80 free bytes and 80B until OOM, max allowed footprint 201326592, growth limit 201326592"
2022-09-14 23:02:21.407 25405-25417/com.digitalsignageplayer W/alsignageplaye: Throwing OutOfMemoryError "Failed to allocate a 56 byte allocation with 8 free bytes and 8B until OOM, max allowed footprint 201326592, growth limit 201326592"
2022-09-14 23:02:24.540 25405-25264/com.digitalsignageplayer W/alsignageplaye: Throwing OutOfMemoryError "Failed to allocate a 32 byte allocation with 8 free bytes and 8B until OOM, max allowed footprint 201326592, growth limit 201326592"
2022-09-14 23:02:31.327 25405-25405/com.digitalsignageplayer W/alsignageplaye: Throwing OutOfMemoryError "Failed to allocate a 16 byte allocation with 8 free bytes and 8B until OOM, max allowed footprint 201326592, growth limit 201326592"
2022-09-14 23:02:32.654 25405-25469/com.digitalsignageplayer W/alsignageplaye: Throwing OutOfMemoryError "Failed to allocate a 152 byte allocation with 8 free bytes and 8B until OOM, max allowed footprint 201326592, growth limit 201326592" (recursive case)
2022-09-14 23:02:35.385 25405-25417/com.digitalsignageplayer E/AndroidRuntime: FATAL EXCEPTION: FinalizerWatchdogDaemon
    Process: com.digitalsignageplayer, PID: 25405
    java.lang.OutOfMemoryError: Failed to allocate a 56 byte allocation with 8 free bytes and 8B until OOM, max allowed footprint 201326592, growth limit 201326592
        at dalvik.system.VMStack.getThreadStackTrace(Native Method)
        at java.lang.Thread.getStackTrace(Thread.java:1538)
        at java.lang.Thread.getAllStackTraces(Thread.java:1588)
        at com.bugsnag.android.ThreadState.<init>(ThreadState.kt:33)
        at com.bugsnag.android.ThreadState.<init>(ThreadState.kt:16)
        at com.bugsnag.android.ThreadState.<init>(ThreadState.kt:23)
        at com.bugsnag.android.EventInternal.<init>(EventInternal.kt:46)
        at com.bugsnag.android.Event.<init>(Event.java:35)
        at com.bugsnag.android.Client.notifyUnhandledException(Client.java:698)
        at com.bugsnag.android.ExceptionHandler.uncaughtException(ExceptionHandler.java:65)
        at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:1068)
        at java.lang.Thread.dispatchUncaughtException(Thread.java:1955)
        at java.lang.Daemons$FinalizerWatchdogDaemon.finalizerTimedOut(Daemons.java:436)
        at java.lang.Daemons$FinalizerWatchdogDaemon.runInternal(Daemons.java:283)
        at java.lang.Daemons$Daemon.run(Daemons.java:103)
        at java.lang.Thread.run(Thread.java:764)
2022-09-14 23:02:36.383 25405-25405/com.digitalsignageplayer A/alsignageplaye: java_vm_ext.cc:542] JNI DETECTED ERROR IN APPLICATION: JNI IsInstanceOf called with pending exception java.lang.OutOfMemoryError: Failed to allocate a 16 byte allocation with 8 free bytes and 8B until OOM, max allowed footprint 201326592, growth limit 201326592

And my profiler:

image image

image

I did receive one error around the same time as the memory errors occurred that seemed a bit weird to me. I'm not sure if this is related but for documentation purposes here it is:

2022-09-14 22:56:39.349 514-514/? W/Binder: Outgoing transactions from this process must be FLAG_ONEWAY
java.lang.Throwable
at android.os.BinderProxy.transact(Binder.java:1116)
at com.amazon.connectivitymanager.IControllerManager$Stub$Proxy.registerEventCallback(IControllerManager.java:439)
at com.amazon.connectivitymanager.ConnectivityManager.registerConnectivityEventCallback(ConnectivityManager.java:671)
at com.amazon.service.AmazonAutoPairService$2.onRemoteServiceConnected(AmazonAutoPairService.java:209)
at com.amazon.connectivitymanager.ConnectivityManager$1.onServiceConnected(ConnectivityManager.java:518)
at android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:1748)
at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:1780)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:211)
at com.android.server.SystemServer.run(SystemServer.java:471)
at com.android.server.SystemServer.main(SystemServer.java:307)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:838)

Sample of my code: Each half-second, a component re-renders causing this code to evaluate. For the purposes of my test above, I rendered an image and then a video in an endless loop until the app crashed. It took about an hour. Under normal use, we see this error after a couple of days:

if (asset.content_type.includes('image/')) {
   return <Image testID='imageAsset' resizeMode={'stretch'} source={{uri:`file://...` }} style={styles.image} />
}

if (asset.content_type.includes('video/')) {
   return <Video repeat={false} resizeMode="cover" style={styles.video} fullScreen={true} source={{uri: `file:....` }} />
}
freeboub commented 2 years ago

@c-moyer thank you for the report! Just to be clear:

c-moyer commented 2 years ago

@freeboub

"react-native": "0.64.2",
"react-native-video": "version": "5.1.1",

I have only tried a 4k (25fps) mp4 that's saved locally to the file system. I'll upgrade tonight or tomorrow and see if I can still reproduce the error. I noticed @RickoNoNo3 said the issue appeared on 6 alpha but I'll attempt to reproduce.

c-moyer commented 2 years ago

Still working to update my app to React Native version 0.68.2, but just wanted to update that I'm getting constant memory errors on react-native-video 5.2.1 on react native 0.65.0. My initial test video won't even successfully loop once at this point.

2022-09-15 23:47:20.921 5073-6110/com.digitalsignageplayer E/LoadTask: OutOfMemory error loading stream
      java.lang.OutOfMemoryError: OutOfMemoryError thrown while trying to throw OutOfMemoryError; no stack trace available
2022-09-15 23:47:20.948 5073-5084/com.digitalsignageplayer E/System: java.lang.OutOfMemoryError: Failed to allocate a 24 byte allocation with 0 free bytes and 3GB until OOM, max allowed footprint 201328480, growth limit 201326592
        at com.android.internal.os.BinderInternal$GcWatcher.finalize(BinderInternal.java:62)
        at java.lang.Daemons$FinalizerDaemon.doFinalize(Daemons.java:250)
        at java.lang.Daemons$FinalizerDaemon.runInternal(Daemons.java:237)
        at java.lang.Daemons$Daemon.run(Daemons.java:103)
        at java.lang.Thread.run(Thread.java:764)
2022-09-15 23:47:20.955 5073-6086/com.digitalsignageplayer E/AndroidRuntime: FATAL EXCEPTION: ExoPlayer:Playback
    Process: com.digitalsignageplayer, PID: 5073
    java.lang.OutOfMemoryError: Failed to allocate a 32 byte allocation with 0 free bytes and 3GB until OOM, max allowed footprint 201328480, growth limit 201326592
        at android.media.MediaCodec$BufferInfo.dup(MediaCodec.java:1545)
        at android.media.MediaCodec.dequeueOutputBuffer(MediaCodec.java:2705)
        at com.google.android.exoplayer2.mediacodec.SynchronousMediaCodecAdapter.dequeueOutputBufferIndex(SynchronousMediaCodecAdapter.java:82)
        at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.drainOutputBuffer(MediaCodecRenderer.java:1779)
        at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.render(MediaCodecRenderer.java:824)
        at com.google.android.exoplayer2.ExoPlayerImplInternal.doSomeWork(ExoPlayerImplInternal.java:948)
        at com.google.android.exoplayer2.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:478)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:211)
        at android.os.HandlerThread.run(HandlerThread.java:65)
2022-09-15 23:47:21.545 5073-5073/com.digitalsignageplayer A/alsignageplaye: java_vm_ext.cc:542] JNI DETECTED ERROR IN APPLICATION: JNI IsInstanceOf called with pending exception java.lang.OutOfMemoryError: Failed to allocate a 40 byte allocation with 0 free bytes and 3GB until OOM, max allowed footprint 201328480, growth limit 201326592
freeboub commented 2 years ago

I can confirm that the issue is also reproduced on basic sample (easy to reproduce with live channel), but I am not able to highlight the root cause for now.

freeboub commented 2 years ago

@c-moyer My reproduction on sample seems to be linked (at least) to react-native version. I think I have this issue: https://github.com/facebook/react-native/issues/26407

I will try to update react-native version of sample. In the time, we are also upgrading our production app to 0.68 this week.

We can investigate the issue together you you want a fast fix :) let me know !

freeboub commented 2 years ago

I rebuild a sample on react native 0.70 (new architecture enabled) with a very basic video player. (Notice I worked on my company fork) and I don't reproduce the issue. This is definitely the memory leak of react-native in my point of view. The leak can be reproduced with a simple setState called in loop.

@c-moyer Can you update after react native upgrade please ?

c-moyer commented 2 years ago

@freeboub Thanks for the update. I was trying to upgrade from 0.67 to 0.68 but ran into issues with the new architecture with our app. I'll try and look through that again tonight and see if I can get things to work. Thanks for looking into this, I'll do all I can to help as well!

c-moyer commented 2 years ago

newArchEnabled=false

@freeboub I created a fresh React Native app (no expo btw) on version 0.70.1 and installed react-native-video@6.0.0-alpha.3 and I'm still getting out of memory errors except I'm getting the errors almost immediately. The video I am attempting to play stutters terribly and then after it loops, the app crashes with a memory error:

2022-09-20 21:07:38.640 17399-17399/com.digitalsignageplayer W/RenderThread: type=1400 audit(0.0:139007): avc: denied { open } for path="/dev/__properties__/u:object_r:vendor_default_prop:s0" dev="tmpfs" ino=1585 scontext=u:r:untrusted_app:s0:c203,c256,c512,c768 tcontext=u:object_r:vendor_default_prop:s0 tclass=file permissive=0
2022-09-20 21:07:38.672 17399-17573/com.digitalsignageplayer I/alsignageplaye: Waiting for a blocking GC Alloc
2022-09-20 21:07:38.676 17399-17545/com.digitalsignageplayer I/alsignageplaye: Waiting for a blocking GC Alloc
2022-09-20 21:07:38.686 17399-17481/com.digitalsignageplayer I/alsignageplaye: Waiting for a blocking GC Alloc
2022-09-20 21:07:38.723 17399-17410/com.digitalsignageplayer I/alsignageplaye: Clamp target GC heap from 197MB to 192MB
2022-09-20 21:07:38.723 17399-17573/com.digitalsignageplayer I/alsignageplaye: WaitForGcToComplete blocked Alloc on HeapTrim for 51.114ms
2022-09-20 21:07:38.723 17399-17573/com.digitalsignageplayer I/alsignageplaye: Starting a blocking GC Alloc
2022-09-20 21:07:38.724 17399-17545/com.digitalsignageplayer I/alsignageplaye: WaitForGcToComplete blocked Alloc on HeapTrim for 47.734ms
2022-09-20 21:07:38.724 17399-17545/com.digitalsignageplayer I/alsignageplaye: Starting a blocking GC Alloc
2022-09-20 21:07:38.724 17399-17481/com.digitalsignageplayer I/alsignageplaye: WaitForGcToComplete blocked Alloc on HeapTrim for 38.063ms
2022-09-20 21:07:38.724 17399-17481/com.digitalsignageplayer I/alsignageplaye: Starting a blocking GC Alloc
2022-09-20 21:07:38.724 17399-17573/com.digitalsignageplayer E/AndroidRuntime: FATAL EXCEPTION: ExoPlayer:Loader:ProgressiveMediaPeriod
    Process: com.digitalsignageplayer, PID: 17399
    java.lang.OutOfMemoryError: OutOfMemoryError thrown while trying to throw OutOfMemoryError; no stack trace available
2022-09-20 21:07:38.725 17399-17573/com.digitalsignageplayer I/alsignageplaye: Starting a blocking GC Alloc
2022-09-20 21:07:38.728 17399-17573/com.digitalsignageplayer I/alsignageplaye: Starting a blocking GC Alloc
2022-09-20 21:07:38.729 17399-17545/com.digitalsignageplayer I/alsignageplaye: Waiting for a blocking GC Alloc
2022-09-20 21:07:38.735 17399-17481/com.digitalsignageplayer I/alsignageplaye: Waiting for a blocking GC Alloc
2022-09-20 21:07:38.782 17399-17573/com.digitalsignageplayer I/alsignageplaye: Clamp target GC heap from 197MB to 192MB

I am testing this on a physical Amazon 4k Max Firestick.

From an emulator, I haven't yet received an out of memory error, but I am getting a ton of W/ExoPlayer Warning: Free memory reached 0, forcing garbage collection in the logcat. The video is still stuttering terribly on the emulator too.

newArchEnabled=true

Working to enable the new architecture but am currently getting the error RCTVideo is not Fabric compatible yet when rendering the Video component.

image
freeboub commented 2 years ago

Hello @c-moyer, let's keep newArch feature in dedicated ticket (I have no plan to enable it in a near future, but we will need to do it for sure! )

For the memory leak, I found yesterday that there is an option enabled to prioritize time for size which can lead to a but amount of memory reserved: see https://github.com/react-native-video/react-native-video/blob/2349fad25f402d75812d449e4630172851590dc6/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java#L591

Can you try to dis ale it manually, please ? I did it yesterday in my fork, but I am not 100% sure it fixes the issue... Let me know !

c-moyer commented 2 years ago

@freeboub So changing the parameter to false didn't fix the memory issue, but it did result in a different overall error. I still noticed warnings in my logcat of forced garbage collection because memory limits had been exceeded, but here is the error which actually crashed the app. I was able to replicate this three times in a row.

image
2022-09-23 01:43:30.727 27155-19737/com.digitalsignageplayer A/libc: Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x8 in tid 19737 (CodecLooper), pid 27155 (alsignageplayer)
2022-09-23 01:43:31.213 27155-19714/com.digitalsignageplayer I/alsignageplaye: Explicit concurrent copying GC freed 6576(768KB) AllocSpace objects, 130(8MB) LOS objects, 3% free, 155MB/161MB, paused 144us total 2.349s
2022-09-23 01:43:31.210 27155-27155/com.digitalsignageplayer W/MediaCodec_loop: type=1400 audit(0.0:565980): avc: denied { read } for name="u:object_r:media_prop:s0" dev="tmpfs" ino=1403 scontext=u:r:untrusted_app:s0:c203,c256,c512,c768 tcontext=u:object_r:media_prop:s0 tclass=file permissive=0
2022-09-23 01:43:31.215 27155-19718/com.digitalsignageplayer I/MediaCodecLogger: [ASAP] HW.video.avc Got First Frame Render 194786969(4261)
2022-09-23 01:43:31.216 27155-19718/com.digitalsignageplayer I/MediaCodecLogger: App sets Timestamps for render in SurfaceFlinger
2022-09-23 01:43:31.216 27155-19719/com.digitalsignageplayer E/BufferQueueProducer: [SurfaceTexture-0-27155-5038] queueBuffer: BufferQueue has been abandoned
2022-09-23 01:43:31.216 27155-19719/com.digitalsignageplayer E/Surface: queueBuffer: error queuing buffer to SurfaceTexture, -19
2022-09-23 01:43:31.216 27155-19719/com.digitalsignageplayer E/FrameEvents: updateAcquireFence: Did not find frame.
2022-09-23 01:43:31.216 27155-19719/com.digitalsignageplayer E/ACodec: queueBuffer failed in onOutputBufferDrained: -19
2022-09-23 01:43:31.216 27155-19719/com.digitalsignageplayer E/ACodec: signalError(omxError 0x80001001, internalError -19)
2022-09-23 01:43:31.217 27155-19718/com.digitalsignageplayer E/MediaCodec: Codec reported err 0xffffffed, actionCode 0, while in state 6
2022-09-23 01:43:31.217 27155-19718/com.digitalsignageplayer I/MediaCodecLogger: 27155.HW.video.avc.DecoderErrorFatal = 1
2022-09-23 01:43:31.217 27155-19718/com.digitalsignageplayer I/MediaCodecLogger: 27155.HW.video.avc.ASAP-P2Ms = 4
2022-09-23 01:43:31.217 27155-19718/com.digitalsignageplayer I/MediaCodecLogger: 27155.HW.video.avc.ASAP-P3Ms = 15
2022-09-23 01:43:31.217 27155-19718/com.digitalsignageplayer I/MediaCodecLogger: 27155.HW.video.avc.FirstFrameReadyMs = 246
2022-09-23 01:43:31.218 27155-19718/com.digitalsignageplayer E/libc: Access denied finding property "media.metrics.enabled"
2022-09-23 01:43:31.220 27155-19718/com.digitalsignageplayer D/SurfaceUtils: disconnecting from surface 0xbba4e008, reason disconnectFromSurface
2022-09-23 01:43:31.221 27155-19714/com.digitalsignageplayer E/MediaCodecVideoRenderer: Video codec error
      java.lang.IllegalStateException
        at android.media.MediaCodec.native_dequeueInputBuffer(Native Method)
        at android.media.MediaCodec.dequeueInputBuffer(MediaCodec.java:2635)
        at com.google.android.exoplayer2.mediacodec.SynchronousMediaCodecAdapter.dequeueInputBufferIndex(SynchronousMediaCodecAdapter.java:99)
        at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.feedInputBuffer(MediaCodecRenderer.java:1190)
        at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.render(MediaCodecRenderer.java:794)
        at com.google.android.exoplayer2.ExoPlayerImplInternal.doSomeWork(ExoPlayerImplInternal.java:989)
        at com.google.android.exoplayer2.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:490)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:211)
        at android.os.HandlerThread.run(HandlerThread.java:65)
2022-09-23 01:43:31.222 27155-19714/com.digitalsignageplayer E/ExoPlayerImplInternal: Playback error
      com.google.android.exoplayer2.ExoPlaybackException: MediaCodecVideoRenderer error, index=0, format=Format(1, null, null, video/avc, avc1.640033, -1, null, [3840, 2160, 25.0], [-1, -1]), format_supported=YES
        at com.google.android.exoplayer2.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:566)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:211)
        at android.os.HandlerThread.run(HandlerThread.java:65)
     Caused by: com.google.android.exoplayer2.video.MediaCodecVideoDecoderException: Decoder failed: OMX.MTK.VIDEO.DECODER.AVC
        at com.google.android.exoplayer2.video.MediaCodecVideoRenderer.createDecoderException(MediaCodecVideoRenderer.java:1590)
        at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.render(MediaCodecRenderer.java:813)
        at com.google.android.exoplayer2.ExoPlayerImplInternal.doSomeWork(ExoPlayerImplInternal.java:989)
        at com.google.android.exoplayer2.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:490)
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:211) 
        at android.os.HandlerThread.run(HandlerThread.java:65) 
     Caused by: java.lang.IllegalStateException
        at android.media.MediaCodec.native_dequeueInputBuffer(Native Method)
        at android.media.MediaCodec.dequeueInputBuffer(MediaCodec.java:2635)
        at com.google.android.exoplayer2.mediacodec.SynchronousMediaCodecAdapter.dequeueInputBufferIndex(SynchronousMediaCodecAdapter.java:99)
        at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.feedInputBuffer(MediaCodecRenderer.java:1190)
        at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.render(MediaCodecRenderer.java:794)
        at com.google.android.exoplayer2.ExoPlayerImplInternal.doSomeWork(ExoPlayerImplInternal.java:989) 
        at com.google.android.exoplayer2.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:490) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:211) 
        at android.os.HandlerThread.run(HandlerThread.java:65) 
2022-09-23 01:43:31.225 27155-19714/com.digitalsignageplayer E/ExoPlayerImplInternal: Disable failed.
      java.lang.IllegalStateException
        at android.media.MediaCodec.native_flush(Native Method)
        at android.media.MediaCodec.flush(MediaCodec.java:2131)
        at com.google.android.exoplayer2.mediacodec.SynchronousMediaCodecAdapter.flush(SynchronousMediaCodecAdapter.java:166)
        at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.flushCodec(MediaCodecRenderer.java:877)
        at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.flushOrReleaseCodec(MediaCodecRenderer.java:870)
        at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.onDisabled(MediaCodecRenderer.java:710)
        at com.google.android.exoplayer2.video.MediaCodecVideoRenderer.onDisabled(MediaCodecVideoRenderer.java:561)
        at com.google.android.exoplayer2.BaseRenderer.disable(BaseRenderer.java:186)
        at com.google.android.exoplayer2.ExoPlayerImplInternal.disableRenderer(ExoPlayerImplInternal.java:1651)
        at com.google.android.exoplayer2.ExoPlayerImplInternal.resetInternal(ExoPlayerImplInternal.java:1392)
        at com.google.android.exoplayer2.ExoPlayerImplInternal.stopInternal(ExoPlayerImplInternal.java:1355)
        at com.google.android.exoplayer2.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:582)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:211)
        at android.os.HandlerThread.run(HandlerThread.java:65)
BestLeader commented 2 years ago

I am also running into this issue (on 6.0.0-alpha3) on Android, but only (or only noticeable) when the video file is local (gallery or camera, I didn't try bundled video in app package). It's pretty bad as loading any local video over a few minutes long will immediately trigger the out of memory exception. It will also trigger if few short videos were loaded consecutively. Loading videos from a remote url doesn't seem to trigger it.

BestLeader commented 2 years ago

Upon further digging, my issue seems to be related to this: https://github.com/google/ExoPlayer/issues/7480 Disabling the "repeat" seems to solve the problem for me.

TensionCoding commented 2 years ago

I have been struggling with this memory issue too. I realized that my memory problem was partly related to React Navigation. I had too many screens with the Video component in the navigation stack. Once I started replacing screens instead of navigating, things got manageable. However, is there a better technique for un-mounting/disabling the Video component without having to modify the Navigation Stack?

BestLeader commented 2 years ago

@TensionCoding

I had a similar issue but for iOS, which isn’t related to ExoPlayer, and solved it this way.

You can use a custom view to wrap your video component, and use import { useIsFocused } from '@react-navigation/native'; To conditionally render the Video component only when the screen is focused, otherwise rendering an Image component instead. You can also pass in a flag to pre-load the Video if needed.

You can use Memo on other parts of the screen to further improve performance if needed.

c-moyer commented 2 years ago

@freeboub Have you had a chance to look at this anymore?

oferRounds commented 1 year ago

seeing it also

valn1 commented 1 year ago

i'm having this issue in my project as well, the app crashes after i record a video, when the app shows a preview of it

only crashes with resolutions above FHD tho

valn1 commented 1 year ago

image here is my logcat output

valn1 commented 1 year ago

i used adb logcat -D *:E

valn1 commented 1 year ago

tested on samsung s20+ and s21

c-moyer commented 1 year ago

I created a fresh React Native app and installed 6.0.0-alpha.3. I'm noticing a difference in the memory leak compared with my initial profiler that I posted above. In the initial profiler, the memory leakage was appearing under "other" but now it's appearing under "native". I've spent countless hours trying to figure this out and would appreciate any help since this is vital to our app. image

c-moyer commented 1 year ago

These rendered nodes seems to be hanging around. image A few minutes later: image

nikonhub commented 1 year ago

Hello,

Have you tried bufferConfig ? Default max buffer length is 50 sec which is a lot.

I got my app crash with just 3 or 4 very short looping videos. After limiting the buffer to something shorter than video length the memory stabilized.

Source : https://stackoverflow.com/a/64900778/10859647

valn1 commented 1 year ago

i got it fixed by adding

android:largeHeap="true"
android:hardwareAccelerated="true"

to my manifest, it does not mean the issue is fixed tho, only means the app won't crash as often

but give it a try @RickoNoNo3

freeboub commented 1 year ago

Not sure on how to handle this issue as it seems linked to props (loop) and video type. On my side I don't see any leak with video... Not sure on how to proceed. To be reproduced with sample exoplayer to ensure this is not an exoplayer issue ...

c-moyer commented 1 year ago

@freeboub Can you provide the code you're testing with that doesn't have the memory leak?

MicaelCosta commented 1 year ago

until there is a resolution on this, this solution(https://github.com/react-native-video/react-native-video/issues/2984) solved my case:

react-native: 0.72.3 react-native-video: 6.0.0-alpha.6 Android: 13 Videos <= 1min

<Video ref={playerRef} source={{ uri: file.path }} resizeMode="contain" controls bufferConfig={{ minBufferMs: 2500, maxBufferMs: 3000, // default is 50 segundos, 3 seconds bufferForPlaybackMs: 2500, bufferForPlaybackAfterRebufferMs: 2500, }} />

alexhernandez commented 11 months ago

Might be related to my work around here: https://github.com/react-native-video/react-native-video/issues/2984#issuecomment-1853228133

I have a FlatList w/ Videos and I was able to workaround this Memory issue by disabling repeat on Android:

<Video
        ref={vidRef}
        // RNV SOURCE IS HLS | .m3u8
        source={uri}
        ...

        // RNV ANDROID ISSUE - `hideShutterView` ONLY WORKS W/ TEXTURE VIEWS NOT SURFACE VIEWS :/
        useTextureView
        hideShutterView

        // RNV VIDEO LOOP (REPEAT) CAUSES MEMORY CRASH
        repeat={Platform.OS === 'android' ? false : true}
      />
WriteCodeEveryday commented 10 months ago

Having issues with this as well on 5.2.1 and 6.0.0-beta.3 BufferConfig and repeat didn't make a difference.

dnetcrawler commented 9 months ago

Hi Team,

We have this issue as well:

[ExoPlayer:Playback] Free memory reached 0, forcing garbage collection
Background concurrent mark compact GC freed 30863(9548KB) AllocSpace objects, 28(17MB) LOS objects, 39% free, 36MB/60MB, paused 1.693ms,7.307ms total 270.995ms
WaitForGcToComplete blocked Explicit on Background for 183.764ms
Explicit concurrent mark compact GC freed 3274(696KB) AllocSpace objects, 1(152KB) LOS objects, 40% free, 35MB/59MB, paused 2.520ms,7.236ms total 251.234ms
bufferpool2 0xb400006c2e7dde28 : 5(40960 size) total buffers - 4(32768 size) used buffers - 1433/1438 (recycle/alloc) - 5/1435 (fetch/transfer)

Made these changes with no improvement at all:

BufferConfig and repeat

android:largeHeap="true"
android:hardwareAccelerated="true"
dnetcrawler commented 8 months ago

This has been opened for a while and we don't see any developments. Any updates?

freeboub commented 8 months ago

@dnetcrawler I tried to investigate and it seems to be an issue in exoplayer (I cannot find anymore the issue I found). If you reproduce it, I would advise you to try on a sample exoplayer to tripple check...

Dav2015 commented 8 months ago

After doing seek operation on the Video player, the video starts to lag or flick. I think is related to memory leaks.

ali-sao commented 6 months ago

The issue persists, use HLS live stream to reproduce it immediately.

eldadts commented 4 months ago

I can confirm the issue still persists on 6.3.0

lklima commented 3 months ago

For me the repeat prop was causing the memory leak, fixed by repeating the video using ref

import Video, { VideoRef } from 'react-native-video';    

 <Video
          ref={videoRef}
          source={require('~/assets/videos/intro.mp4')}
          resizeMode="cover"
          repeat={false}
          onEnd={() => videoRef.current?.seek(0)}
        />
Ahsanch11 commented 2 months ago

For me the repeat prop was causing the memory leak, fixed by repeating the video using ref

import Video, { VideoRef } from 'react-native-video';    

 <Video
          ref={videoRef}
          source={require('~/assets/videos/intro.mp4')}
          resizeMode="cover"
          repeat={false}
          onEnd={() => videoRef.current?.seek(0)}
        />

thanks tried this resolved my issue its due to repeating the video.

davinun99 commented 2 months ago

Whats the final solution to this? Can we do something? Can we contribute in some way? I have the same memory leakage and I must render multiple HD videos at the same time.

freeboub commented 2 months ago

@davinun99 I my mind all issues comes from exoplayer, not react native video itself. There is one leak issue in exoplayer, when you repeat small videos (with repeat=true) a workround is available in the thread. Some 4K video leaks. not 100% sure f the root cause. Keep in mind that video decoders of the device can also leak :/