This project demonstrates how to use the Agora RTC SDK for iOS with a custom video source to publish video streams from both the internal iPad cameras, and an external USB camera into the same channel. It also shows how to use the multi-channel connection feature to manage multiple video sources.
- Custom Video Source: Uses
AVCaptureMultiCamSessionandAVCaptureDeviceInputto capture raw frames from cameras. - Multi-Camera Support: Publishes both the built-in iPad front camera, back camera, and an external USB camera at the same time.
- Multi-Channel Connection: Demonstrates joining multiple connections with Agora SDK and publishing custom video tracks.
| File/Folder | Description |
|---|---|
Views/ContentView.swift |
The main view to display all the 3 local video streams |
Views/LocalUIViewRepresent.swift |
SwiftUI/UIView bridge for rendering local video frames using AVSampleBufferDisplayLayer. |
Models/MultiCameraSourcePushDelegate.swift |
Protocol and delegator for multi-camera video capture and delegation. |
Models/AgoraMultiChannelDelegate.swift |
Protocol and delegator for handling multiple Agora channel callbacks. |
ViewModels/AgoraViewModel.swift |
Main view model. Manages Agora engine, channel connections, and custom video track publishing. |
Podfile |
CocoaPods dependencies configuration. |
- Xcode 15.0 or later
- iOS 14.0 or later
- Physical iPad device (multi-camera capture is not supported in Simulator)
- External USB camera (via Lightning/USB-C adapter)
- Agora RTC iOS SDK 4.6.0 (installed via CocoaPods)
-
Clone the repository:
git clone https://github.com/Bac1314/AgoraCustomSourceMultiCam_iOS.git cd AgoraCustomSourceMultiCam -
Install dependencies:
pod install
-
Open the workspace:
open AgoraCustomSourceMultiCam.xcworkspace
-
Add your Agora App ID, channel, and token in AgoraViewModel.swift:
var agoraAppID = "" @Published var agoraChannel = "channel_bac" // RTC Tokens (tokens not needed if project didn't enable certificate) var frontCameraUidToken : String = "" var backCameraUidToken : String = "" var externalCameraUidToken : String = ""
- Connect an external USB camera to your iPad.
- Run the project on a physical iPad device.
- Enter a channel name and join.
- The app will publish streams from:
- **iPad internal cameras
- **iPad external cameras
- **USB external camera
- Use [https://webdemo-na.agora.io/basicLive/index.html][Agora Web demo] to join the same channel as an audience, you should be able to see the streams
Both streams will be visible to remote participants in the same channel.
- ** Multi-camera capture may increase CPU/GPU load and network bandwidth usage.
- ** USB cameras must support UVC (USB Video Class).
- ** Only real devices are supported. iOS Simulator cannot access cameras.
[https://docs.agora.io/en/interactive-live-streaming/get-started/get-started-sdk?platform=ios][Agora iOS SDK Documentation] [https://developer.apple.com/av-foundation][AVFoundation Programming Guide]
This project is provided for educational/demo purposes under the MIT License. See LICENSE.txt for more information.