google / ExoPlayer

This project is deprecated and stale. The latest ExoPlayer code is available in https://github.com/androidx/media
https://developer.android.com/media/media3/exoplayer
Apache License 2.0
21.7k stars 6.02k forks source link

Problem with too many threads when looping #11336

Closed LQ753799168 closed 10 months ago

LQ753799168 commented 10 months ago

When I play a video on android, if I don't set Loop, then create ExoPlayer: Loader: ProgressiveMediaPeriod thread there would be only one, but if I check the Loop, Will appear many ExoPlayer: Loader: ProgressiveMediaPeriod threads, sometimes as many as 19, could you tell me how to avoid the excessive number of threads created, the number of the number of threads created which parameters related。

Unity version: 2019.4.30f1 AVPro Video version:2.8.5

https://github.com/google/ExoPlayer/assets/35380099/c68c7e8e-f202-4fd6-910b-e6ba88db9f4a

https://github.com/google/ExoPlayer/assets/35380099/23387d2b-114f-4120-8b0d-5532e0ccd8ad

Video 1 will create 5 threads。 Video 2 will create 19 threads

Verification method:

adb shell "ps|grep com.DefaultCompany.AVProDemo"
adb shell cat /proc/pid/status
adb shell ps -t pid

For example

C:\Users\Lenovo>adb shell ps -t 23483
USER      PID   PPID  VSIZE  RSS   WCHAN              PC  NAME
u0_a377   23483 529   1817704 173276          0 0000000000 S com.DefaultCompany.AVProDemo
u0_a377   23488 23483 1817704 173276          0 0000000000 S Jit thread pool
u0_a377   23490 23483 1817704 173276          0 0000000000 S Signal Catcher
u0_a377   23491 23483 1817704 173276          0 0000000000 S ReferenceQueueD
u0_a377   23492 23483 1817704 173276          0 0000000000 S FinalizerDaemon
u0_a377   23493 23483 1817704 173276          0 0000000000 S FinalizerWatchd
u0_a377   23494 23483 1817704 173276          0 0000000000 S HeapTaskDaemon
u0_a377   23495 23483 1817704 173276          0 0000000000 S Binder:23483_1
u0_a377   23497 23483 1817704 173276          0 0000000000 S Binder:23483_2
u0_a377   23505 23483 1817704 173276          0 0000000000 S Profile Saver
u0_a377   23511 23483 1817704 173276          0 0000000000 S UnityMain
u0_a377   23513 23483 1817704 173276          0 0000000000 S pool-1-thread-1
u0_a377   23516 23483 1817704 173276          0 0000000000 S Thread-16
u0_a377   23530 23483 1817704 173276          0 0000000000 S Job.Worker 0
u0_a377   23531 23483 1817704 173276          0 0000000000 S Job.Worker 1
u0_a377   23532 23483 1817704 173276          0 0000000000 S Job.Worker 2
u0_a377   23533 23483 1817704 173276          0 0000000000 S Job.Worker 3
u0_a377   23534 23483 1817704 173276          0 0000000000 S Background Job.
u0_a377   23535 23483 1817704 173276          0 0000000000 S Background Job.
u0_a377   23536 23483 1817704 173276          0 0000000000 S Background Job.
u0_a377   23537 23483 1817704 173276          0 0000000000 S Background Job.
u0_a377   23538 23483 1817704 173276          0 0000000000 S Background Job.
u0_a377   23539 23483 1817704 173276          0 0000000000 S Background Job.
u0_a377   23540 23483 1817704 173276          0 0000000000 S Background Job.
u0_a377   23541 23483 1817704 173276          0 0000000000 S Background Job.
u0_a377   23542 23483 1817704 173276          0 0000000000 S Background Job.
u0_a377   23543 23483 1817704 173276          0 0000000000 S Background Job.
u0_a377   23544 23483 1817704 173276          0 0000000000 S Background Job.
u0_a377   23545 23483 1817704 173276          0 0000000000 S Background Job.
u0_a377   23546 23483 1817704 173276          0 0000000000 S Background Job.
u0_a377   23547 23483 1817704 173276          0 0000000000 S Background Job.
u0_a377   23548 23483 1817704 173276          0 0000000000 S Background Job.
u0_a377   23549 23483 1817704 173276          0 0000000000 S Background Job.
u0_a377   23551 23483 1817704 173276          0 0000000000 S BatchDeleteObje
u0_a377   23552 23483 1817704 173276          0 0000000000 S Loading.AsyncRe
u0_a377   23554 23483 1817704 173276          0 0000000000 S mali-mem-purge
u0_a377   23555 23483 1817704 173276          0 0000000000 S mali-event-hnd
u0_a377   23556 23483 1817704 173276          0 0000000000 S mali-utility-wo
u0_a377   23557 23483 1817704 173276          0 0000000000 S mali-utility-wo
u0_a377   23558 23483 1817704 173276          0 0000000000 S mali-utility-wo
u0_a377   23559 23483 1817704 173272          0 0000000000 S mali-utility-wo
u0_a377   23560 23483 1817704 173272          0 0000000000 S mali-utility-wo
u0_a377   23561 23483 1817712 173272          0 0000000000 S mali-utility-wo
u0_a377   23562 23483 1817712 173272          0 0000000000 S mali-utility-wo
u0_a377   23563 23483 1817704 173272          0 0000000000 S mali-utility-wo
u0_a377   23564 23483 1817704 173272          0 0000000000 S mali-renderer
u0_a377   23565 23483 1817704 173272          0 0000000000 S mali-hist-dump
u0_a377   23566 23483 1817704 173272          0 0000000000 R Thread-1430
u0_a377   23567 23483 1817704 173272          0 0000000000 S FMODAudioDevice
u0_a377   23568 23483 1817704 173272          0 0000000000 S FMOD stream thr
u0_a377   23569 23483 1817704 173272          0 0000000000 S AudioTrack
u0_a377   23573 23483 1817704 173272          0 0000000000 S Loading.Preload
u0_a377   23618 23483 1817704 173272          0 0000000000 S UnityChoreograp
u0_a377   23619 23483 1817704 173272          0 0000000000 S ExoPlayer:Frame
u0_a377   23620 23483 1817704 173272          0 0000000000 S ExoPlayer:Playb
u0_a377   23621 23483 1817704 173272          0 0000000000 S ConnectivityThr
u0_a377   23624 23483 1817704 173272          0 0000000000 S Okio Watchdog
u0_a377   23625 23483 1817704 173272          0 0000000000 S Thread-6
u0_a377   23626 23483 1817704 173272          0 0000000000 S Thread-5
u0_a377   23627 23483 1817704 173272          0 0000000000 S MediaCodec_loop
u0_a377   23628 23483 1817704 173272          0 0000000000 S JNISurfaceTextu
u0_a377   23633 23483 1817704 173272          0 0000000000 S MediaCodec_loop
u0_a377   23634 23483 1817704 173272          0 0000000000 S gle.aac.decoder
u0_a377   23635 23483 1817704 173272          0 0000000000 S OMXCallbackDisp
u0_a377   23636 23483 1817704 173272          0 0000000000 S AudioTrack
u0_a377   23637 23483 1817704 173272          0 0000000000 S OkHttp Connecti
u0_a377   23641 23483 1817704 173272          0 0000000000 S ExoPlayer:Loade
u0_a377   23642 23483 1817704 173272          0 0000000000 S ExoPlayer:Loade
u0_a377   23643 23483 1817704 173272          0 0000000000 S ExoPlayer:Loade
u0_a377   23644 23483 1817704 173272          0 0000000000 S ExoPlayer:Loade
u0_a377   23645 23483 1817704 173272          0 0000000000 S ExoPlayer:Loade
u0_a377   23646 23483 1817704 173272          0 0000000000 S ExoPlayer:Loade
u0_a377   23672 23483 1817704 173272          0 0000000000 S ExoPlayer:Loade
u0_a377   23721 23483 1817704 173272          0 0000000000 S Binder:23483_3
u0_a377   23726 23483 1817704 173272          0 0000000000 S ExoPlayer:Loade
u0_a377   23740 23483 1817704 173272          0 0000000000 S ExoPlayer:Loade
LQ753799168 commented 10 months ago

By the way, the devices with this problem are Huawei Android 7.0,level 24, Android 8.0.0,level 26, Android 8.1.0,level 27

This will cause a crash

Caused by:
java.lang.OutOfMemoryError:pthread_create (1040KB stack) failed: Out of memory
java.lang.Thread.nativeCreate(Native Method)
java.lang.Thread.start(Thread.java:753)
java.util.concurrent.ThreadPoolExecutor.addWorker(ThreadPoolExecutor.java:970)
java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1377)
java.util.concurrent.Executors$DelegatedExecutorService.execute(Executors.java:620)
com.google.android.exoplr2avp.upstream.Loader$LoadTask.execute(Loader.java:510)
com.google.android.exoplr2avp.upstream.Loader$LoadTask.start(Loader.java:363)
com.google.android.exoplr2avp.upstream.Loader.startLoading(Loader.java:257)
com.google.android.exoplr2avp.source.ProgressiveMediaPeriod.startLoading(ProgressiveMediaPeriod.java:818)
com.google.android.exoplr2avp.source.ProgressiveMediaPeriod.prepare(ProgressiveMediaPeriod.java:234)
com.google.android.exoplr2avp.source.MaskingMediaPeriod.prepare(MaskingMediaPeriod.java:145)
com.google.android.exoplr2avp.ExoPlayerImplInternal.maybeUpdateLoadingPeriod(ExoPlayerImplInternal.java:1988)
com.google.android.exoplr2avp.ExoPlayerImplInternal.updatePeriods(ExoPlayerImplInternal.java:1968)
com.google.android.exoplr2avp.ExoPlayerImplInternal.doSomeWork(ExoPlayerImplInternal.java:955)
com.google.android.exoplr2avp.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:490)
android.os.Handler.dispatchMessage(Handler.java:105)
android.os.Looper.loop(Looper.java:166)
android.os.HandlerThread.run(HandlerThread.java:65)
rohitjoins commented 10 months ago

The com.google.android.exoplayer2 project is now deprecated. We are not accepting any new issues in this project. Please file your issue in the androidx.media3 GitHub project instead: https://github.com/androidx/media/issues