iOS Examples
GitHub Examples
You can find our iOS examples on GitHub:
Override Playout Delay
Example Code for overriding the playout delay via a PhenixMediaStream object
1import PhenixSdk23class SomeClass {4 private var currentRendererPlayoutDelayOverride: PhenixDisposable?5 private var currentRenderer: PhenixRenderer?67 private func setPlayoutDelayOverrideFor10Seconds() {8 // Previously obtained9 let mediaStream: PhenixMediaStream = ...1011 self.currentRenderer = mediaStream.createRenderer()1213 // Override playout delay to 900ms for 10 seconds14 let playoutDelay: TimeInterval = 0.91516 self.currentRendererPlayoutDelayOverride = self.currentRenderer?.overridePlayoutDelay(playoutDelay)1718 DispatchQueue.main.asyncAfter(deadline: .now() + 10) {19 // Dropping the disposable will undo the playout delay override20 self.currentRendererPlayoutDelayOverride = nil21 }22 }23}
Example Code for limiting video bandwidth with a PhenixExpressSubscriber object
1import PhenixSdk23class SomeClass {4 private var currentRendererPlayoutDelayOverride: PhenixDisposable?5 private var currentRenderer: PhenixRenderer?67 private func setPlayoutDelayOverrideFor10Seconds() {8 // Previously obtained9 let subscriber: PhenixExpressSubscriber = ...1011 self.currentRenderer = subscriber.createRenderer()1213 // Override playout delay to 900ms for 10 seconds14 let playoutDelay: TimeInterval = 0.91516 self.currentRendererPlayoutDelayOverride = self.currentRenderer?.overridePlayoutDelay(playoutDelay)1718 DispatchQueue.main.asyncAfter(deadline: .now() + 10) {19 // Dropping the disposable will undo the playout delay override20 self.currentRendererPlayoutDelayOverride = nil21 }22 }23}
The playout delay represents the amount of time by which audio and video are delayed when content is rendered by a subscriber; i.e. it works as a buffer. The delay adds to the overall end-to-end latency experienced by the user (on top of capture, encoding, and network latencies). It is necessary to handle network-related fluctuations (such as jitter or data loss). By default, the playout delay for real-time streams is set to 230ms. The following API allows app developers to override this default value.
In order to access the API, a reference to a PhenixRenderer
is needed.
It can be obtained either by creating it from PhenixMediaStream
or PhenixExpressSubscriber
,
or via several of the Express APIs, which can return renderers
(joinChannel,
subscribeToMemberStream,
subscribe).
The returned disposable allows control over how long the override should stay in effect; it therefore needs to be held onto via a strong reference. If overridePlayoutDelay
is called multiple times before any of the previous disposables are released, then only the most recent override will remain in effect until its disposable is released. Releasing any of the disposables from earlier overridePlayoutDelay
calls will have no effect.
Notes:
- The override represents an absolute value, not a delta.
- If an override increases the playout delay, it will result in content being paused. Example: changing a delay of 1 second to 5 seconds will cause the content to be paused for roughly 4 seconds.
- If an override decreases the playout delay, it will cause a jump where some of the content will be skipped.
- Very large override values will increase the amount of memory consumed. It is generally recommended to stay below 10 seconds.
Parameters
Name | Type | Description |
---|---|---|
desiredPlayoutDelay (required) | TimeInterval | Desired playout delay |
Returns
Type | Description |
---|---|
PhenixDisposable | Ensures override is kept in effect for as long as a strong reference is held |