|
| 1 | +<PlatformWrapper platform="ios, macos"> |
| 2 | + |
| 3 | +Before joining a channel, set up multi-resolution video streaming by calling the `setSimulcastConfig` method and configuring the `simulcastConfig` parameters. |
| 4 | + |
| 5 | +```objc |
| 6 | +- (int)setSimulcastConfig:(AgoraSimulcastConfig* _Nonnull)simulcastConfig NS_SWIFT_NAME(setSimulcastConfig(_:)); |
| 7 | +``` |
| 8 | +
|
| 9 | +The following snippet shows how `SimulcastConfig` and related classes are defined in the SDK: |
| 10 | +
|
| 11 | +```objc |
| 12 | +__attribute__((visibility("default"))) @interface AgoraSimulcastConfig: NSObject |
| 13 | +// The configuration of each simulcast video stream. |
| 14 | +@property (copy, nonatomic, readonly) NSArray<AgoraStreamLayerConfig*>* _Nonnull configs; |
| 15 | +// Whether to allow the SDK to dynamically disable simulcast streams when the sender's |
| 16 | +// device performance or uplink network conditions are poor. |
| 17 | +@property (assign, nonatomic) BOOL publishFallbackEnable; |
| 18 | +@end |
| 19 | +
|
| 20 | +// The video properties for a simulcast stream. |
| 21 | +__attribute__((visibility("default"))) @interface AgoraStreamLayerConfig: NSObject |
| 22 | +// The resolution of the video stream. |
| 23 | +@property (assign, nonatomic) CGSize dimensions; |
| 24 | +// The frame rate of the video stream. |
| 25 | +@property (assign, nonatomic) int framerate; |
| 26 | +// Whether this stream layer is enabled. |
| 27 | +@property (assign, nonatomic) BOOL enable; |
| 28 | +@end |
| 29 | +
|
| 30 | +// The index of simulcast stream layers. |
| 31 | +typedef NS_ENUM(NSInteger, AgoraStreamLayerIndex) { |
| 32 | + AgoraStreamLayer1 = 0, |
| 33 | + AgoraStreamLayer2 = 1, |
| 34 | + AgoraStreamLayer3 = 2, |
| 35 | + AgoraStreamLayer4 = 3, |
| 36 | + AgoraStreamLayer5 = 4, |
| 37 | + AgoraStreamLayer6 = 5, |
| 38 | + AgoraStreamLow = 6, |
| 39 | + AgoraStreamLayerCountMax = 7, |
| 40 | +}; |
| 41 | +``` |
| 42 | + |
| 43 | +### Configure parameters |
| 44 | + |
| 45 | +When configuring extended streams, follow these rules: |
| 46 | + |
| 47 | +- Configure the resolution and frame rate of each stream before joining a channel. After joining, you cannot change resolution or frame rate; you can only enable or disable streams using `AgoraStreamLayerConfig.enable`. |
| 48 | + |
| 49 | +- Set the resolution and frame rate of each configuration lower than the source stream, defined in `AgoraVideoEncoderConfiguration`. |
| 50 | + |
| 51 | +- Decrease the resolution and frame rate with each additional layer. For example, `AgoraStreamLayerIndex.layer2` must have a lower resolution and frame rate than `AgoraStreamLayerIndex.layer1`, and so on. |
| 52 | + |
| 53 | +- Enable up to three configurations at the same time, including the small stream. |
| 54 | + |
| 55 | +### Sample code |
| 56 | + |
| 57 | +Set the resolution and frame rate of configurations based on your use case and bandwidth. <Vg k="COMPANY" /> recommends configuring only the layers you need and setting `AgoraStreamLayerConfig.enable = false` for others. The following sample shows how to configure a multi-resolution video stream: |
| 58 | + |
| 59 | +```swift |
| 60 | +private func setupSimulcast() { |
| 61 | + let layer1_index = AgoraStreamLayerIndex.layer1.rawValue |
| 62 | + let layer2_index = AgoraStreamLayerIndex.layer2.rawValue |
| 63 | + let layer3_index = AgoraStreamLayerIndex.layer3.rawValue |
| 64 | + let layer4_index = AgoraStreamLayerIndex.layer4.rawValue |
| 65 | + |
| 66 | + // Configure layer 1 (high resolution) |
| 67 | + simulcastConfig.configs[layer1_index].dimensions.width = 1280 |
| 68 | + simulcastConfig.configs[layer1_index].dimensions.height = 720 |
| 69 | + simulcastConfig.configs[layer1_index].framerate = 30 |
| 70 | + simulcastConfig.configs[layer1_index].enable = true |
| 71 | + |
| 72 | + // Configure layer 2 (medium resolution) |
| 73 | + simulcastConfig.configs[layer2_index].dimensions.width = 960 |
| 74 | + simulcastConfig.configs[layer2_index].dimensions.height = 540 |
| 75 | + simulcastConfig.configs[layer2_index].framerate = 15 |
| 76 | + simulcastConfig.configs[layer2_index].enable = true |
| 77 | + |
| 78 | + // Configure layer 3 (optional, disabled by default) |
| 79 | + simulcastConfig.configs[layer3_index].dimensions.width = 640 |
| 80 | + simulcastConfig.configs[layer3_index].dimensions.height = 360 |
| 81 | + simulcastConfig.configs[layer3_index].framerate = 15 |
| 82 | + simulcastConfig.configs[layer3_index].enable = false |
| 83 | + |
| 84 | + // Configure layer 4 (low resolution) |
| 85 | + simulcastConfig.configs[layer4_index].dimensions.width = 480 |
| 86 | + simulcastConfig.configs[layer4_index].dimensions.height = 270 |
| 87 | + simulcastConfig.configs[layer4_index].framerate = 15 |
| 88 | + simulcastConfig.configs[layer4_index].enable = true |
| 89 | + |
| 90 | + // Apply simulcast configuration |
| 91 | + let ret = agoraKit.setSimulcastConfig(simulcastConfig) |
| 92 | + LogUtils.log(message: "setSimulcastConfig: \(ret) ", level: .info) |
| 93 | +} |
| 94 | +``` |
| 95 | + |
| 96 | +### Subscribe to a stream |
| 97 | + |
| 98 | +A remote user subscribes to the desired video quality level by setting the `streamType` parameter in `setRemoteVideoStreamType`. |
| 99 | + |
| 100 | +```swift |
| 101 | +let ret = agoraKit.setRemoteVideoStream(uid, type: .layer1) |
| 102 | +LogUtils.log(message: "set remote layer, ret: \(ret) ", level: .info) |
| 103 | +``` |
| 104 | + |
| 105 | +To update the subscribed video quality level during real-time interaction, you can call `setRemoteVideoStreamType` multiple times. |
| 106 | + |
| 107 | +</PlatformWrapper> |
0 commit comments