File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ NS_ASSUME_NONNULL_BEGIN
1616
1717+ (CVPixelBufferRef)i420ToPixelBuffer : (void *)srcY srcU : (void *)srcU srcV : (void *)srcV width : (int )width height : (int )height ;
1818
19- + (NSImage *)pixelBufferToImage : (CVPixelBufferRef)pixelBuffer ;
19+ + (NSImage *)pixelBufferToImage : (CVPixelBufferRef)pixelBuffer withRotationDegrees : (CGFloat) angleInDegrees ;
2020
2121+ (NSData *)dataFromPixelBuffer : (CVPixelBufferRef)pixelBuffer ;
2222
Original file line number Diff line number Diff line change @@ -140,18 +140,18 @@ + (NSImage *)i420ToImage:(void *)srcY srcU:(void *)srcU srcV:(void *)srcV width:
140140 return finalImage;
141141}
142142
143- + (NSImage *)pixelBufferToImage : (CVPixelBufferRef)pixelBuffer {
144- size_t width = CVPixelBufferGetHeight (pixelBuffer);
145- size_t height = CVPixelBufferGetWidth (pixelBuffer);
146-
143+ + (NSImage *)pixelBufferToImage : (CVPixelBufferRef)pixelBuffer withRotationDegrees : (CGFloat)angleInDegrees {
147144 CIImage *coreImage = [CIImage imageWithCVPixelBuffer: pixelBuffer];
145+ CGFloat angleInRadians = -angleInDegrees * (M_PI / 180 );
146+
147+ CGAffineTransform rotationTransform = CGAffineTransformMakeRotation (angleInRadians);
148+ CIImage *rotatedImage = [coreImage imageByApplyingTransform: rotationTransform];
149+
148150 CIContext *temporaryContext = [CIContext contextWithOptions: nil ];
149- CGImageRef videoImage = [temporaryContext createCGImage: coreImage
150- fromRect: CGRectMake (0 , 0 , height, width)];
151+ CGImageRef videoImage = [temporaryContext createCGImage: rotatedImage fromRect: [rotatedImage extent ]];
151152
152- NSImage *finalImage = [[NSImage alloc ] initWithCGImage: videoImage size: CGSizeMake (width, height) ];
153+ NSImage *finalImage = [[NSImage alloc ] initWithCGImage: videoImage size: NSZeroSize ];
153154
154- // CVPixelBufferRelease(pixelBuffer);
155155 CGImageRelease (videoImage);
156156 return finalImage;
157157}
Original file line number Diff line number Diff line change 3838 <autoresizingMask key =" autoresizingMask" widthSizable =" YES" flexibleMinY =" YES" />
3939 </view >
4040 <switch horizontalHuggingPriority =" 750" verticalHuggingPriority =" 750" baseWritingDirection =" leftToRight" alignment =" left" state =" on" translatesAutoresizingMaskIntoConstraints =" NO" id =" Lwi-x7-gXz" >
41- <rect key =" frame" x =" 236" y =" 325 " width =" 42" height =" 26" />
41+ <rect key =" frame" x =" 236" y =" 323 " width =" 42" height =" 26" />
4242 <connections >
4343 <action selector =" onClickMultipathSwitch:" target =" zLf-Ex-oud" id =" Vt2-3l-vzb" />
4444 </connections >
132132 <outlet property =" Container" destination =" fby-v7-FIJ" id =" juc-7s-DOF" />
133133 <outlet property =" channelField" destination =" EJd-Bd-Goe" id =" 0A4-WA-Fi1" />
134134 <outlet property =" joinChannelButton" destination =" CS3-Kj-Lpq" id =" hPB-xL-Tpw" />
135+ <outlet property =" multipathSwitch" destination =" Lwi-x7-gXz" id =" 9kP-Wc-zh7" />
135136 <outlet property =" selectModePicker" destination =" 6i1-vk-Tbe" id =" IFb-zT-hrH" />
136137 <outlet property =" selectRolePicker" destination =" 5UX-4c-O42" id =" Prj-iq-HRi" />
137138 </connections >
Original file line number Diff line number Diff line change @@ -35,6 +35,9 @@ class MultipathMain: BaseViewController {
3535 return nil
3636 }
3737 }
38+
39+ @IBOutlet weak var multipathSwitch : NSSwitch !
40+
3841 func initSelectRolePicker( ) {
3942 selectRolePicker. label. stringValue = " Role " . localized
4043 selectRolePicker. picker. addItems ( withTitles: roles. map { $0. description ( ) } )
@@ -179,7 +182,7 @@ class MultipathMain: BaseViewController {
179182 channelMediaOption. publishCameraTrack = role == . broadcaster
180183 channelMediaOption. publishMicrophoneTrack = role == . broadcaster
181184 channelMediaOption. clientRoleType = role
182- channelMediaOption. enableMultipath = true
185+ channelMediaOption. enableMultipath = ( multipathSwitch . state == . on )
183186 channelMediaOption. uplinkMultipathMode = ( selectModePicker. picker. indexOfSelectedItem == 0 ) ? . dynamic : . duplicate
184187 channelMediaOption. downlinkMultipathMode = ( selectModePicker. picker. indexOfSelectedItem == 0 ) ? . dynamic : . duplicate
185188 channelMediaOption. autoSubscribeVideo = true
@@ -230,7 +233,7 @@ class MultipathMain: BaseViewController {
230233 let isOn = ( sender. state == . on)
231234 channelMediaOption. enableMultipath = isOn
232235 let ret = agoraKit. updateChannel ( with: channelMediaOption)
233- if isOn {
236+ if ! isOn {
234237 videos [ 0 ] . statsInfo? . updateMultipathStats ( nil )
235238 }
236239 LogUtils . log ( message: " updateChannel Multipath ret: \( ret) isOn: \( isOn) " , level: . info)
Original file line number Diff line number Diff line change @@ -120,8 +120,8 @@ extension RawVideoData: AgoraVideoFrameDelegate {
120120 func onRenderVideoFrame( _ videoFrame: AgoraOutputVideoFrame , uid: UInt , channelId: String ) -> Bool {
121121 if isSnapShoting, let pixelBuffer = videoFrame. pixelBuffer {
122122 isSnapShoting = false
123- let image = MediaUtils . pixelBuffer ( toImage: pixelBuffer)
124-
123+ let image = MediaUtils . pixelBuffer ( toImage: pixelBuffer, withRotationDegrees : CGFloat ( videoFrame . rotation ) )
124+
125125 DispatchQueue . main. async {
126126 self . imageView. image = image
127127 }
You can’t perform that action at this time.
0 commit comments