Re: AVFoundation and the main thread
Re: AVFoundation and the main thread
- Subject: Re: AVFoundation and the main thread
- From: Kyle Sluder <email@hidden>
- Date: Tue, 20 Dec 2016 10:58:54 -0600
On Tue, Dec 20, 2016, at 08:59 AM, Andreas Falkenhahn wrote:
> So everybody knows that all things relating to UIKit have to be done
> on the main thread.
>
> But what about AVFoundation functions which bear some resemblance to
> UIKit APIs? Do these have to be called on the main thread too or can
> they also be called from a worker thread?
>
> For example, when adding an AVPlayerLayer to a view using addSubview()
> I have to do this on the main thread of course.
>
> But what about changing the frame size of an AVPlayerLayer using
> setFrame()? AVPlayerLayer inherits from CALayer which is part of the
> QuartzCore framework, not UIKit. But of course CALayer methods like
> setFrame() bear a strong resemblance to their UIKit counterparts so
> I'm wondering whether it is really allowed to call setFrame() from
> a worker thread?
Since AVPlayerLayer is a layer, not a view, it cannot be added with
addSubview. It can either be added as a sublayer to your view’s layer,
or it can be wrapped in a view and *that view* added as a subview.
The distinction is important in many ways, but in this case the answer
is the same for both: don’t do this from a background thread.
(Caveat: it is technically possible to do CALayer-level work on a
background thread, but you have to manage many aspects of the
CATransaction yourself. It’s not easy to do correctly, and it gets
_very_ complex when manipulating a layer tree from multiple threads
simultaneously. And as soon as one of these layers belongs to a view,
you must only touch it from the main thread.)
--Kyle Sluder
>
> Also, what about AVPlayerLayer methods like removeFromSuperlayer()?
> Is this main thread only as well?
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden