Perform async rendering in the main thread on Mac & iOS #3166
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently, worker thread will dispatch the rendering task synchronously to the main thread (while holding vid conf mutex lock), i.e.:
So if the main thread is trying to acquire vid conf mutex lock, such as by calling
pjsua_call_hangup()
or callingpjsua_vid_conf_*()
APIs, a deadlock can occur.The proposed solution in this PR is to perform the rendering asynchronously. A few notes:
dispatch_sync()
is replaced byperformSelectorOnMainThread()
. According to the doc,performSelectorOnMainThread()
queues the message on the run loop of the main thread and then later dequeues the message and invokes the desired method (And multiple calls to this method from the same thread cause the corresponding selectors to be queued and performed in the same same order in which the calls were made.). While fordispatch_sync()
, the doc states that as a performance optimization, the function can execute blocks on the current thread whenever possible. So here we use the method queuing property ofperformSelectorOnMainThread()
to make sure that the async rendering has completed when stopping the renderer.