Remove syncOrientation property.
This commit is contained in:
parent
dc0e02a76c
commit
0a48c6ac2c
|
@ -49,12 +49,14 @@ final class LiveViewController: UIViewController {
|
|||
super.viewDidLoad()
|
||||
|
||||
rtmpStream = RTMPStream(connection: rtmpConnection)
|
||||
rtmpStream.syncOrientation = true
|
||||
if let orientation = DeviceUtil.videoOrientation(by: UIApplication.shared.statusBarOrientation) {
|
||||
rtmpStream.orientation = orientation
|
||||
}
|
||||
rtmpStream.captureSettings = [
|
||||
.sessionPreset: AVCaptureSession.Preset.hd1280x720,
|
||||
.continuousAutofocus: true,
|
||||
.continuousExposure: true,
|
||||
.preferredVideoStabilizationMode: AVCaptureVideoStabilizationMode.auto
|
||||
// .preferredVideoStabilizationMode: AVCaptureVideoStabilizationMode.auto
|
||||
]
|
||||
rtmpStream.videoSettings = [
|
||||
.width: 720,
|
||||
|
@ -67,6 +69,8 @@ final class LiveViewController: UIViewController {
|
|||
|
||||
videoBitrateSlider?.value = Float(RTMPStream.defaultVideoBitrate) / 1024
|
||||
audioBitrateSlider?.value = Float(RTMPStream.defaultAudioBitrate) / 1024
|
||||
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(on(_:)), name: UIDevice.orientationDidChangeNotification, object: nil)
|
||||
}
|
||||
|
||||
override func viewWillAppear(_ animated: Bool) {
|
||||
|
@ -184,7 +188,7 @@ final class LiveViewController: UIViewController {
|
|||
}
|
||||
}
|
||||
|
||||
@IBAction func onFPSValueChanged(_ segment: UISegmentedControl) {
|
||||
@IBAction private func onFPSValueChanged(_ segment: UISegmentedControl) {
|
||||
switch segment.selectedSegmentIndex {
|
||||
case 0:
|
||||
rtmpStream.captureSettings[.fps] = 15.0
|
||||
|
@ -197,7 +201,7 @@ final class LiveViewController: UIViewController {
|
|||
}
|
||||
}
|
||||
|
||||
@IBAction func onEffectValueChanged(_ segment: UISegmentedControl) {
|
||||
@IBAction private func onEffectValueChanged(_ segment: UISegmentedControl) {
|
||||
if let currentEffect: VideoEffect = currentEffect {
|
||||
_ = rtmpStream.unregisterVideoEffect(currentEffect)
|
||||
}
|
||||
|
@ -213,6 +217,14 @@ final class LiveViewController: UIViewController {
|
|||
}
|
||||
}
|
||||
|
||||
@objc
|
||||
private func on(_ notification: Notification) {
|
||||
guard let orientation = DeviceUtil.videoOrientation(by: UIApplication.shared.statusBarOrientation) else {
|
||||
return
|
||||
}
|
||||
rtmpStream.orientation = orientation
|
||||
}
|
||||
|
||||
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey: Any]?, context: UnsafeMutableRawPointer?) {
|
||||
if Thread.isMainThread {
|
||||
currentFPSLabel?.text = "\(rtmpStream.currentFPS)"
|
||||
|
|
|
@ -22,4 +22,19 @@ extension DeviceUtil {
|
|||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
public static func videoOrientation(by orientation: UIInterfaceOrientation) -> AVCaptureVideoOrientation? {
|
||||
switch orientation {
|
||||
case .portrait:
|
||||
return .portrait
|
||||
case .portraitUpsideDown:
|
||||
return .portraitUpsideDown
|
||||
case .landscapeLeft:
|
||||
return .landscapeLeft
|
||||
case .landscapeRight:
|
||||
return .landscapeRight
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -290,13 +290,6 @@ final class VideoIOComponent: IOComponent {
|
|||
super.init(mixer: mixer)
|
||||
encoder.lockQueue = lockQueue
|
||||
decoder.delegate = self
|
||||
#if os(iOS)
|
||||
if let orientation: AVCaptureVideoOrientation = DeviceUtil.videoOrientation(by: UIDevice.current.orientation) {
|
||||
self.orientation = orientation
|
||||
} else if let defaultOrientation = RTMPStream.defaultOrientation {
|
||||
self.orientation = defaultOrientation
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#if os(iOS) || os(macOS)
|
||||
|
|
|
@ -23,7 +23,6 @@ open class NetStream: NSObject {
|
|||
|
||||
deinit {
|
||||
metadata.removeAll()
|
||||
NotificationCenter.default.removeObserver(self)
|
||||
}
|
||||
|
||||
open var metadata: [String: Any?] = [:]
|
||||
|
@ -54,21 +53,6 @@ open class NetStream: NSObject {
|
|||
}
|
||||
#endif
|
||||
|
||||
#if os(iOS)
|
||||
open var syncOrientation: Bool = false {
|
||||
didSet {
|
||||
guard syncOrientation != oldValue else {
|
||||
return
|
||||
}
|
||||
if syncOrientation {
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(on), name: UIDevice.orientationDidChangeNotification, object: nil)
|
||||
} else {
|
||||
NotificationCenter.default.removeObserver(self, name: UIDevice.orientationDidChangeNotification, object: nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
open var audioSettings: Setting<AudioConverter, AudioConverter.Option> {
|
||||
get {
|
||||
return mixer.audioIO.encoder.settings
|
||||
|
@ -183,15 +167,6 @@ open class NetStream: NSObject {
|
|||
}
|
||||
}
|
||||
|
||||
#if os(iOS)
|
||||
@objc
|
||||
private func on(uiDeviceOrientationDidChange: Notification) {
|
||||
if let orientation: AVCaptureVideoOrientation = DeviceUtil.videoOrientation(by: uiDeviceOrientationDidChange) {
|
||||
self.orientation = orientation
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
func ensureLockQueue(callback: () -> Void) {
|
||||
if DispatchQueue.getSpecific(key: NetStream.queueKey) == NetStream.queueValue {
|
||||
callback()
|
||||
|
|
|
@ -217,9 +217,6 @@ open class RTMPStream: NetStream {
|
|||
static let defaultID: UInt32 = 0
|
||||
public static let defaultAudioBitrate: UInt32 = AudioConverter.defaultBitrate
|
||||
public static let defaultVideoBitrate: UInt32 = H264Encoder.defaultBitrate
|
||||
#if !os(tvOS)
|
||||
public static var defaultOrientation: AVCaptureVideoOrientation?
|
||||
#endif
|
||||
|
||||
open weak var delegate: RTMPStreamDelegate?
|
||||
open internal(set) var info = RTMPStreamInfo()
|
||||
|
|
|
@ -43,10 +43,7 @@ extension AVCaptureDevice {
|
|||
}
|
||||
}
|
||||
|
||||
public final class DeviceUtil {
|
||||
private init() {
|
||||
}
|
||||
|
||||
public struct DeviceUtil {
|
||||
public static func device(withPosition: AVCaptureDevice.Position) -> AVCaptureDevice? {
|
||||
return AVCaptureDevice.devices().first {
|
||||
$0.hasMediaType(.video) && $0.position == withPosition
|
||||
|
|
Loading…
Reference in New Issue