|
@@ -6,8 +6,34 @@
|
|
|
//
|
|
|
|
|
|
public class PublishManager: IPublishManager {
|
|
|
+ public static var hasInstalled = false
|
|
|
+
|
|
|
+ private let libPublisher: SmartPublisherSDK
|
|
|
+ private let videoStreamingQulity: DNVideoStreamingQuality = .init(1) // 固定为480P
|
|
|
private var _profile: PublishProfile = .empty()
|
|
|
+ private var eventHandler: PublishEventHandler?
|
|
|
private var _isPublishing: Bool = false
|
|
|
+ private var ret: Int = 0
|
|
|
+ private var renderView: UIView?
|
|
|
+ private var isVideoMute: Bool = false
|
|
|
+
|
|
|
+ init() {
|
|
|
+ libPublisher = SmartPublisherSDK()
|
|
|
+ initPublisher()
|
|
|
+ }
|
|
|
+
|
|
|
+ public static func install() {
|
|
|
+ if hasInstalled {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ let ret = SmartPublisherSDK.smartPublisherSetSDKClientKey(DaniuConfig.CLIENT_ID, in_key: DaniuConfig.SECRET_KEY, reserve1: 0, reserve2: nil)
|
|
|
+ if ret == 0 {
|
|
|
+ hasInstalled = true
|
|
|
+ print("SmartPublisherSDK install success.")
|
|
|
+ } else {
|
|
|
+ print("SmartPublisherSDK install fail.")
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
public var isPublishing: Bool {
|
|
|
return _isPublishing
|
|
@@ -19,15 +45,106 @@ public class PublishManager: IPublishManager {
|
|
|
|
|
|
public func setProfile(_ value: PublishProfile) {
|
|
|
_profile = value
|
|
|
+ ret = libPublisher.smartPublisherSetFPS(value.frameRate)
|
|
|
+
|
|
|
+ print("SmartPublisherSetFPS -> fps=\(value.frameRate) ret=\(ret)")
|
|
|
+ }
|
|
|
+
|
|
|
+ public func setView(_ view: UIView) {
|
|
|
+ renderView = view
|
|
|
+ ret = libPublisher.smartPublisherSetVideoPreview(view)
|
|
|
+
|
|
|
+ print("SmartPublisherSetVideoPreview ret=\(ret)")
|
|
|
+ }
|
|
|
+
|
|
|
+ public func start() {
|
|
|
+ if isPublishing {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ ret = libPublisher.smartPublisherStartCapture(videoStreamingQulity)
|
|
|
+ ret = libPublisher.smartPublisherStartPublisher(_profile.url)
|
|
|
+
|
|
|
+ print("SmartPublisherStartPublisher ret=\(ret)")
|
|
|
+
|
|
|
+ _isPublishing = true
|
|
|
}
|
|
|
|
|
|
- public func start() {}
|
|
|
+ public func stop() {
|
|
|
+ if !isPublishing {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ ret = libPublisher.smartPublisherStopPublisher()
|
|
|
+ ret = libPublisher.smartPublisherStopCaputure()
|
|
|
+
|
|
|
+ print("SmartPublisherStopPublisher ret=\(ret)")
|
|
|
+
|
|
|
+ _isPublishing = false
|
|
|
+ }
|
|
|
|
|
|
- public func stop() {}
|
|
|
+ public func muteVideo(_ isMute: Bool) {
|
|
|
+ if !isPublishing {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if isMute {
|
|
|
+ if !isVideoMute {
|
|
|
+ ret = libPublisher.smartPublisherStopCaputure()
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if isVideoMute {
|
|
|
+ ret = libPublisher.smartPublisherStartCapture(videoStreamingQulity)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ print("SmartPublisherSetMute -> isMute=\(isMute) ret=\(ret)")
|
|
|
+ }
|
|
|
|
|
|
- public func muteVideo(_ isMute: Bool) {}
|
|
|
+ public func muteAudio(_ isMute: Bool) {
|
|
|
+ if !isPublishing {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ ret = libPublisher.smartPublisherSetMute(isMute)
|
|
|
+ print("SmartPublisherSetMute -> isMute=\(isMute) ret=\(ret)")
|
|
|
+ }
|
|
|
|
|
|
- public func muteAudio(_ isMute: Bool) {}
|
|
|
+ public func setVolume(_ volume: Int) {
|
|
|
+ if !isPublishing {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ print("SmartPublishSetInputAudioVolume -> volume=\(volume) [Unsupport!]")
|
|
|
+ }
|
|
|
|
|
|
- public func setVolume(_ volume: Int) {}
|
|
|
+ private func initPublisher() {
|
|
|
+ ret = libPublisher.smartPublisherInit(1, video_opt: 1)
|
|
|
+ eventHandler = PublishEventHandler()
|
|
|
+ libPublisher.delegate = eventHandler
|
|
|
+
|
|
|
+ let orientation = _profile.isLandscape ? 2 : 1
|
|
|
+ ret = libPublisher.smartPublisherSetPublishOrientation(orientation)
|
|
|
+
|
|
|
+ ret = libPublisher.smartPublisherSetVideoEncoderType(1, isHwEncoder: true) // H.264 硬编码
|
|
|
+ if ret == 0 {
|
|
|
+ print("Great, it support h.264 hardware encoder!")
|
|
|
+ }
|
|
|
+ ret = libPublisher.smartPublisherSetAudioEncoderType(1, isHwEncoder: true) // ACC 硬编码
|
|
|
+ if ret == 0 {
|
|
|
+ print("Great, it support acc hardware encoder!")
|
|
|
+ }
|
|
|
+
|
|
|
+ ret = libPublisher.smartPublisherSetMirror(true) // 开启镜像
|
|
|
+ }
|
|
|
+
|
|
|
+ deinit {
|
|
|
+ doDispose()
|
|
|
+ }
|
|
|
+
|
|
|
+ private func doDispose() {
|
|
|
+ stop()
|
|
|
+
|
|
|
+ libPublisher.smartPublisherSetVideoPreview(nil)
|
|
|
+ renderView = nil
|
|
|
+ libPublisher.smartPublisherUnInit()
|
|
|
+ }
|
|
|
}
|