Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
shogo4405 committed Mar 14, 2023
1 parent 3c7b5b7 commit 4c11ed7
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions Examples/iOS/LiveViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ final class LiveViewController: UIViewController {
private var currentEffect: VideoEffect?
private var currentPosition: AVCaptureDevice.Position = .back
private var retryCount: Int = 0
private var videoBitRate = VideoCodecSettings.default.bitRate

override func viewDidLoad() {
super.viewDidLoad()
Expand All @@ -40,6 +41,7 @@ final class LiveViewController: UIViewController {
if let orientation = DeviceUtil.videoOrientation(by: UIApplication.shared.statusBarOrientation) {
rtmpStream.videoOrientation = orientation
}
rtmpStream.delegate = self
rtmpStream.videoSettings.videoSize = .init(width: 720, height: 1280)
rtmpStream.mixer.recorder.delegate = self
videoBitrateSlider?.value = Float(VideoCodecSettings.default.bitRate) / 1000
Expand Down Expand Up @@ -296,3 +298,39 @@ extension LiveViewController: IORecorderDelegate {
})
}
}

extension LiveViewController: RTMPStreamDelegate {
// MARK: RTMPStreamDelegate
func rtmpStream(_ stream: RTMPStream, publishInsufficientBWOccured connection: RTMPConnection) {
// Adaptive bitrate streaming exsample. Please feedback me your good algorithm. :D
videoBitRate -= 32 * 1000
stream.videoSettings.bitRate = max(videoBitRate, 64 * 1000)
}

func rtmpStream(_ stream: RTMPStream, publishSufficientBWOccured connection: RTMPConnection) {
videoBitRate += 32 * 1000
stream.videoSettings.bitRate = min(videoBitRate, VideoCodecSettings.default.bitRate)
}

func rtmpStream(_ stream: RTMPStream, didOutput audio: AVAudioBuffer, presentationTimeStamp: CMTime) {
}

func rtmpStream(_ stream: RTMPStream, didOutput video: CMSampleBuffer) {
}

func rtmpStream(_ stream: RTMPStream, updatedStats connection: RTMPConnection) {
}

func rtmpStream(_ stream: RTMPStream, sessionWasInterrupted session: AVCaptureSession, reason: AVCaptureSession.InterruptionReason) {
}

func rtmpStream(_ stream: RTMPStream, sessionInterruptionEnded session: AVCaptureSession, reason: AVCaptureSession.InterruptionReason) {
}

func rtmpStream(_ stream: RTMPStream, videoCodecErrorOccurred error: VideoCodec.Error) {
}

func rtmpStreamDidClear(_ stream: RTMPStream) {
videoBitRate = VideoCodecSettings.default.bitRate
}
}

0 comments on commit 4c11ed7

Please sign in to comment.