Creating and destroying AVFoundation classes in background queues?

I am trying to eliminate some Main Thread performance hits that occur when I allocate AVPlayer, AVPlayerItem and AVURLAsset in the main thread. Has anyone had experience moving or highlighting these objects in a background thread? In the same way, can the current AVPlayer ID be set in the background?

+6
source share
2 answers

The following will certainly hurt scroll performance

  • Create AVPlayer, drop 10 frames per second
  • Adding a player to AVPlayerLayer, drop by 15 frames per second
  • Start playback, drop 15/25 frames per second
  • Pause playback, drop 15 frames per second
  • Disable AVPlayer, drop by 20+ frames per second

I tried to isolate AVPlayer from the background thread, however AVFoundation will go back to the main one and do the selection / initialization from main. Same thing with play / pause.

I have some success when releasing AVPlayer / AVPlayerItem in the background thread. Basically you need to clear the last AVPlayer link from the background thread.

+2
source

Generally speaking, if the documentation for classes is not documented to be thread safe, you should not use an object of this class for multiple threads.

Moreover, although the advantage is to do less on the main thread, allocating AVPlayer , AVPlayerItem and AVURLAsset will never be a practical bottleneck that you need to worry about. Instead, you should run the tools and find real performance issues, and focus on them instead.

-1
source

Source: https://habr.com/ru/post/952323/


All Articles