From 052101a6adae597c77870c3cf4dca99d1302a8db Mon Sep 17 00:00:00 2001 From: Gustavo Emanuel Farias Rosa Date: Wed, 22 Jun 2022 18:23:52 -0300 Subject: [PATCH] Add screen share rotation support #16 --- .../Classes/ScreenBroadcasterService.swift | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/ios-broadcast-upload-extension/Classes/ScreenBroadcasterService.swift b/ios-broadcast-upload-extension/Classes/ScreenBroadcasterService.swift index da3bb46..7e346cb 100644 --- a/ios-broadcast-upload-extension/Classes/ScreenBroadcasterService.swift +++ b/ios-broadcast-upload-extension/Classes/ScreenBroadcasterService.swift @@ -6,6 +6,7 @@ import os import bigbluebutton_mobile_sdk_common import WebRTC +import UIKit open class ScreenBroadcasterService { // Logger (these messages are displayed in the console application) @@ -24,6 +25,8 @@ open class ScreenBroadcasterService { "stun:stun3.l.google.com:19302", "stun:stun4.l.google.com:19302"]) webRTCClient.delegate = self + + } public func createOffer() async -> String? { @@ -60,6 +63,23 @@ open class ScreenBroadcasterService { if(!isConnected) { self.logger.info("Ignoring pushVideoFrame - not connected") } else { + var rotationFrame: RTCVideoRotation = ._0 + var orientation = CGImagePropertyOrientation.up + if #available(iOS 11.0, *) { + if let orientationAttachment = CMGetAttachment(sampleBuffer, key: RPVideoSampleOrientationKey as CFString, attachmentModeOut: nil) as? NSNumber { + orientation = CGImagePropertyOrientation(rawValue: orientationAttachment.uint32Value) ?? .up + } + } + + switch orientation.rawValue { + case UInt32(6): + rotationFrame = ._270 + case UInt32(8): + rotationFrame = ._90 + default: + rotationFrame = ._0 + } + self.logger.info("pushing video") let imageBuffer:CVImageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer)! let timeStampNs: Int64 = Int64(CMTimeGetSeconds(CMSampleBufferGetPresentationTimeStamp(sampleBuffer)) * 1000000000) @@ -69,7 +89,7 @@ open class ScreenBroadcasterService { webRTCClient.setRatio(originalWidth: rtcPixlBuffer.width, originalHeight: rtcPixlBuffer.height) } - let rtcVideoFrame = RTCVideoFrame(buffer: rtcPixlBuffer, rotation: ._0, timeStampNs: timeStampNs) + let rtcVideoFrame = RTCVideoFrame(buffer: rtcPixlBuffer, rotation: rotationFrame, timeStampNs: timeStampNs) self.webRTCClient.push(videoFrame: rtcVideoFrame) self.logger.info("video pushed") }