Huge CPU usage since iOS 16.1 on PiP using CMSampleBuffer.

Hi.

In Picture in Picture, a large number of work queue threads are created and CPU usage increases considerably.

This happens when startPictureInPicture() is executed on a class created with AVSampleBufferController(contentSource:.init(...)). It does not matter how many times AVSampleBufferDisplayLayer() isenque()`, it is reproduced when the Picture in Picture screen appears.

Checking the work queue thread, it looks like it is run by AVTimer of AVKIt, but I can't figure out how to control this.

Does anyone know anything about it?
This seems to occur on iOS 16.1 or later.

See: https://github.com/uakihir0/UIPiPView/issues/17

Replies

From you post image we can see that the cpu time usage is conern with play timer, so I wondering that maybe CMTimeRange(start: .negativeInfinity, duration: .positiveInfinity) is the problem, so I change this line to CMTimeRange(start: .zero, duration: .positiveInfinity). guess what, the cpu usage is drop to 0! so func pictureInPictureControllerTimeRangeForPlayback(_ pictureInPictureController: AVPictureInPictureController) -> CMTimeRange { CMTimeRange(start: .negativeInfinity, duration: .positiveInfinity) }

is the problem. don't return negativeInfinity, just zero.

This issue has been resolved. Thank you very much. https://github.com/uakihir0/UIPiPView/issues/17#issuecomment-1424135424