-
-
Notifications
You must be signed in to change notification settings - Fork 620
Moving from 1.7.0 APIs to 1.8.x
shogo4405 edited this page May 2, 2024
·
10 revisions
stream.attachAudio(AVCaptureDevice.default(for: .audio), automaticallyConfiguresApplicationAudioSession: true) { error in
// print(error)
}
stream.configuration { session in
session.automaticallyConfiguresApplicationAudioSession = true
}
stream.attachAudio(AVCaptureDevice.default(for: .audio), track: 0) { unit, error in
}
stream.attachCamera(AVCaptureDevice.default(.builtInWideAngleCamera, for: .video, position: .back), channel: 0) { _, error in
if let error {
logger.warn(error)
}
}
stream.attachCamera(AVCaptureDevice.default(.builtInWideAngleCamera, for: .video, position: .back), track: 0) { _, error in
if let error {
logger.warn(error)
}
}
Removed.
/// The interface an IOStream uses to inform its delegate.
public protocol IOStreamDelegate: AnyObject {
/// Tells the receiver to an audio packet incoming.
func stream(_ stream: IOStream, didOutput audio: AVAudioBuffer, when: AVAudioTime)
/// Tells the receiver to a video incoming.
func stream(_ stream: IOStream, didOutput video: CMSampleBuffer)
}
setream.delegate = delegate.
/// A delegate protocol your app implements to receive capture stream output events.
public protocol IOStreamObserver: AnyObject {
/// Tells the receiver to an audio packet incoming.
func stream(_ stream: IOStream, didOutput audio: AVAudioBuffer, when: AVAudioTime)
/// Tells the receiver to a video incoming.
func stream(_ stream: IOStream, didOutput video: CMSampleBuffer)
}
class MyStreamObserver: IOStreamObserver {
}
val observer = MyStreamObserver()
stream.addObserver(observer)
stream.audioSettings = AudioCodecSettings(
bitRate: Int = 64 * 1000,
sampleRate: Float64 = 0,
channels: UInt32 = 0,
downmix: Bool = false,
channelMap: [Int]? = nil
)
Settings for audio mixing processes such as sample rate conversion have been transferred to audioMixerSettings.
stream.audioMixerSettings = .init(sampleRate: 0, channels: 0)
stream.audioMixerSettings.tracks[0] = [
0: .init(
isMuted: Bool = false,
downmix: Bool = true,
channelMap: [Int]? = nil
)
]
stream.audioSettings.bitRate = 64 * 1000
// Start recording.
stream.isRecording
stream.startRecording(self, settings: settings)
// Stop recording.
stream.stopRecording()
Internally, I am now handling data with more than 3 channels. If you encounter audio issues with IOStreamRecorder, it is recommended to set it back to a maximum of 2 channels when saving locally.
let channels = max(stream.audioInputFormats[0]?.channels ?? 1, 2)
stream.audioMixerSettings = .init(sampleRate: 0, channels: channels)
// Start recordings
recorder = IOStreamRecorder()
recorder.delegate = self
// Subscribes stream sample data.
stream.addObserver(recorder)
recorder.startRunning()
// Stop recording.
recorder.stopRunning()
// stream.removeObserver(recorder)
1.7.x | 1.8.0 |
---|---|
IOStreamDrawable | IOStreamView |
NetBitRateStrategyConvertible | IOStreamBitRateStrategyConvertible |
NetBitRateStats | IOStreamBitRateStats |
NetBitRateStrateg | IOStreamBitRateStrategy |
VideoAdaptiveNetBitRateStrategy | IOStreamVideoAdaptiveBitRateStrategy |
IORecorder | IOStreamRecorder |
IORecorderDelegate | IOStreamRecorderDelegate |
MultiCamCaptureSettings | IOVideoMixerSettings |
HaishinKit.swift | 🇬🇧 HaishinKit.kt | 🇯🇵 Zenn