Hi,
We're writing code to decode a real-time network RTSP video stream (using ffmpeg + ************) on iOS, we've experienced issues that *seems* to be related to our work-queue loop getting throttled/paused/whatever during the parsing+decoding process. Under load (and noticably more on weaker devices) we experience "gaps" - times that the thread seems to be paused so the video stream jumps - we've boiled the code down to the basics of just parsing the rtsp stream and decoding h264 frames and still get "gaps" (packet loss is minimal from what we've checked with rvictl and wireshark)
I've stumbled upon Technical Note TN2169 - High Precision Timers in iOS / OS X which explains how to set the pthread to real-time scheduling but want to make sure it actually works on iOS (on the comments of this article from 2011 someone stated that Apple disabled real-time scheduling of pthreads on iOS) and if it's the correct solution to the issue.
Running the code with real-time pthread gives the impression that there are less gaps (we're printing the times of the gaps while streaming) but we're working on this for so long that it might be a lie.
Thanks,
Nimrod
If you’re doing a real time task that the real-time thread policy (
THREAD_TIME_CONSTRAINT_POLICY) is a reasonable option.
IMPORTANT This policy is very deliberately structured to force you to state, in advance, how much CPU you need. If you can’t come up with reasonable values for the
period,
computation and
constraint values, you probably need to reconsider whether you should be using this policy.
(we're printing the times of the gaps while streaming)
I hope you’re not printing from the real-time thread itself. That would represent a massive priority inversion. I recommend that you gather statistics in your real-time thread, record them in memory, and then print them from a normal-priority thread.
If you see anything unexpected you can investigate using the System Trace instrument. That’ll show you how long your thread is on the CPU and, when it get kicked off, why.
Share and Enjoy
—
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
let myEmail = "eskimo" + "1" + "@apple.com"