Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating and destroying AVFoundation classes on background queues?

I am trying to eliminate some Main Thread performance hits that occur when I allocate AVPlayer, AVPlayerItem and AVURLAsset on the main thread. Has anyone had experience with moving allocation/releasing of these objects to a background thread? Similarly, can an AVPlayer's currentItem be set on a background queue?

like image 292
Alan Cannistraro Avatar asked Aug 23 '13 01:08

Alan Cannistraro


1 Answers

The following will definitely hurt scrolling performance

  • Creating AVPlayer, 10 fps drop
  • Adding player to AVPlayerLayer, 15 fps drop
  • Start play, 15/25 fps drop
  • Pause play, 15 fps drop
  • Deallocate AVPlayer, 20+ fps drop

I tried with allocate AVPlayer from a background thread, however, AVFoundation will switch back to main and perform the allocation/initialization from main. Same with play/pause.

I have some success with deallocating AVPlayer/AVPlayerItem on a background thread. Basically you need to clear out last reference to AVPlayer from your background thread.

like image 103
Feng Yun Avatar answered Nov 12 '22 07:11

Feng Yun