Skip to content

Commit

Permalink
fix: CSD-56669
Browse files Browse the repository at this point in the history
  • Loading branch information
LichKing-2234 committed Jun 7, 2023
1 parent 956a2f9 commit 03d9168
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 79 deletions.
54 changes: 30 additions & 24 deletions android/src/main/java/io/agora/rtc/base/RtcSurfaceView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class RtcSurfaceView(
context: Context
) : FrameLayout(context) {
private var surface: SurfaceView
private var canvas: VideoCanvas
private var canvas: VideoCanvas? = null
private var isMediaOverlay = false
private var onTop = false
private var channel: WeakReference<RtcChannel>? = null
Expand All @@ -23,7 +23,6 @@ class RtcSurfaceView(
} catch (e: UnsatisfiedLinkError) {
throw RuntimeException("Please init RtcEngine first!")
}
canvas = VideoCanvas(surface)
addView(surface)
}

Expand Down Expand Up @@ -51,18 +50,21 @@ class RtcSurfaceView(

fun setData(engine: RtcEngine, channel: RtcChannel?, uid: Number) {
this.channel = if (channel != null) WeakReference(channel) else null
canvas.channelId = this.channel?.get()?.channelId()
canvas.uid = uid.toNativeUInt()
canvas = canvas ?: VideoCanvas(surface)
canvas?.channelId = this.channel?.get()?.channelId()
canvas?.uid = uid.toNativeUInt()
setupVideoCanvas(engine)
}

fun resetVideoCanvas(engine: RtcEngine) {
val canvas =
VideoCanvas(null, canvas.renderMode, canvas.channelId, canvas.uid, canvas.mirrorMode)
if (canvas.uid == 0) {
engine.setupLocalVideo(canvas)
} else {
engine.setupRemoteVideo(canvas)
canvas?.let {
val canvas =
VideoCanvas(null, it.renderMode, it.channelId, it.uid, it.mirrorMode)
if (canvas.uid == 0) {
engine.setupLocalVideo(canvas)
} else {
engine.setupRemoteVideo(canvas)
}
}
}

Expand All @@ -73,33 +75,37 @@ class RtcSurfaceView(
surface.setZOrderOnTop(onTop)
addView(surface)
surface.layout(0, 0, width, height)
canvas.view = surface
if (canvas.uid == 0) {
engine.setupLocalVideo(canvas)
} else {
engine.setupRemoteVideo(canvas)
canvas?.let { canvas ->
canvas.view = surface
if (canvas.uid == 0) {
engine.setupLocalVideo(canvas)
} else {
engine.setupRemoteVideo(canvas)
}
}
}

fun setRenderMode(engine: RtcEngine, @Annotations.AgoraVideoRenderMode renderMode: Int) {
canvas.renderMode = renderMode
canvas?.renderMode = renderMode
setupRenderMode(engine)
}

fun setMirrorMode(engine: RtcEngine, @Annotations.AgoraVideoMirrorMode mirrorMode: Int) {
canvas.mirrorMode = mirrorMode
canvas?.mirrorMode = mirrorMode
setupRenderMode(engine)
}

private fun setupRenderMode(engine: RtcEngine) {
if (canvas.uid == 0) {
engine.setLocalRenderMode(canvas.renderMode, canvas.mirrorMode)
} else {
channel?.get()?.let {
it.setRemoteRenderMode(canvas.uid, canvas.renderMode, canvas.mirrorMode)
return@setupRenderMode
canvas?.let { canvas ->
if (canvas.uid == 0) {
engine.setLocalRenderMode(canvas.renderMode, canvas.mirrorMode)
} else {
channel?.get()?.let {
it.setRemoteRenderMode(canvas.uid, canvas.renderMode, canvas.mirrorMode)
return@setupRenderMode
}
engine.setRemoteRenderMode(canvas.uid, canvas.renderMode, canvas.mirrorMode)
}
engine.setRemoteRenderMode(canvas.uid, canvas.renderMode, canvas.mirrorMode)
}
}

Expand Down
54 changes: 30 additions & 24 deletions android/src/main/java/io/agora/rtc/base/RtcTextureView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class RtcTextureView(
context: Context
) : FrameLayout(context) {
private var texture: TextureView
private var canvas: VideoCanvas
private var canvas: VideoCanvas? = null
private var channel: WeakReference<RtcChannel>? = null

init {
Expand All @@ -21,24 +21,26 @@ class RtcTextureView(
} catch (e: UnsatisfiedLinkError) {
throw RuntimeException("Please init RtcEngine first!")
}
canvas = VideoCanvas(texture)
addView(texture)
}

fun setData(engine: RtcEngine, channel: RtcChannel?, uid: Number) {
this.channel = if (channel != null) WeakReference(channel) else null
canvas.channelId = this.channel?.get()?.channelId()
canvas.uid = uid.toNativeUInt()
canvas = canvas ?: VideoCanvas(texture)
canvas?.channelId = this.channel?.get()?.channelId()
canvas?.uid = uid.toNativeUInt()
setupVideoCanvas(engine)
}

fun resetVideoCanvas(engine: RtcEngine) {
val canvas =
VideoCanvas(null, canvas.renderMode, canvas.channelId, canvas.uid, canvas.mirrorMode)
if (canvas.uid == 0) {
engine.setupLocalVideo(canvas)
} else {
engine.setupRemoteVideo(canvas)
canvas?.let {
val canvas =
VideoCanvas(null, it.renderMode, it.channelId, it.uid, it.mirrorMode)
if (canvas.uid == 0) {
engine.setupLocalVideo(canvas)
} else {
engine.setupRemoteVideo(canvas)
}
}
}

Expand All @@ -47,33 +49,37 @@ class RtcTextureView(
texture = RtcEngine.CreateTextureView(context.applicationContext)
addView(texture)
texture.layout(0, 0, width, height)
canvas.view = texture
if (canvas.uid == 0) {
engine.setupLocalVideo(canvas)
} else {
engine.setupRemoteVideo(canvas)
canvas?.let { canvas ->
canvas.view = texture
if (canvas.uid == 0) {
engine.setupLocalVideo(canvas)
} else {
engine.setupRemoteVideo(canvas)
}
}
}

fun setRenderMode(engine: RtcEngine, @Annotations.AgoraVideoRenderMode renderMode: Int) {
canvas.renderMode = renderMode
canvas?.renderMode = renderMode
setupRenderMode(engine)
}

fun setMirrorMode(engine: RtcEngine, @Annotations.AgoraVideoMirrorMode mirrorMode: Int) {
canvas.mirrorMode = mirrorMode
canvas?.mirrorMode = mirrorMode
setupRenderMode(engine)
}

private fun setupRenderMode(engine: RtcEngine) {
if (canvas.uid == 0) {
engine.setLocalRenderMode(canvas.renderMode, canvas.mirrorMode)
} else {
channel?.get()?.let {
it.setRemoteRenderMode(canvas.uid, canvas.renderMode, canvas.mirrorMode)
return@setupRenderMode
canvas?.let { canvas ->
if (canvas.uid == 0) {
engine.setLocalRenderMode(canvas.renderMode, canvas.mirrorMode)
} else {
channel?.get()?.let {
it.setRemoteRenderMode(canvas.uid, canvas.renderMode, canvas.mirrorMode)
return@setupRenderMode
}
engine.setRemoteRenderMode(canvas.uid, canvas.renderMode, canvas.mirrorMode)
}
engine.setRemoteRenderMode(canvas.uid, canvas.renderMode, canvas.mirrorMode)
}
}

Expand Down
4 changes: 2 additions & 2 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ PODS:
- React-jsinspector (0.68.2)
- React-logger (0.68.2):
- glog
- react-native-agora (3.7.1):
- react-native-agora (3.7.2-rc.1):
- AgoraRtcEngine_Special_iOS (= 3.7.2.4)
- React-Core
- react-native-safe-area-context (3.4.1):
Expand Down Expand Up @@ -939,7 +939,7 @@ SPEC CHECKSUMS:
React-jsiexecutor: b7b553412f2ec768fe6c8f27cd6bafdb9d8719e6
React-jsinspector: c5989c77cb89ae6a69561095a61cce56a44ae8e8
React-logger: a0833912d93b36b791b7a521672d8ee89107aff1
react-native-agora: a1446a62fd8f0fd652f9b774a0394099c40db241
react-native-agora: bffc8d8b2251e5636fb9a7984b2b9c2c92e799f2
react-native-safe-area-context: 9e40fb181dac02619414ba1294d6c2a807056ab9
react-native-slider: cecabb58ecffad671d2ad3ccc58c7f4d2d029e95
React-perflogger: a18b4f0bd933b8b24ecf9f3c54f9bf65180f3fe6
Expand Down
66 changes: 37 additions & 29 deletions ios/RCTAgora/Base/RtcSurfaceView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ import UIKit

class RtcSurfaceView: UIView {
private var surface: UIView
private var canvas: AgoraRtcVideoCanvas
private var canvas: AgoraRtcVideoCanvas?
private weak var channel: AgoraRtcChannel?

override init(frame: CGRect) {
surface = UIView(frame: CGRect(origin: CGPoint(x: 0, y: 0), size: frame.size))
canvas = AgoraRtcVideoCanvas()
canvas.view = surface
super.init(frame: frame)
addSubview(surface)
addObserver(self, forKeyPath: observerForKeyPath(), options: .new, context: nil)
Expand All @@ -26,29 +24,35 @@ class RtcSurfaceView: UIView {
}

deinit {
canvas.view = nil
canvas = nil
removeObserver(self, forKeyPath: observerForKeyPath(), context: nil)
}

func setData(_ engine: AgoraRtcEngineKit, _ channel: AgoraRtcChannel?, _ uid: UInt) {
self.channel = channel
canvas.channelId = channel?.getId()
canvas.uid = uid
if canvas == nil {
canvas = AgoraRtcVideoCanvas()
canvas!.view = surface
}
canvas!.channelId = channel?.getId()
canvas!.uid = uid
setupVideoCanvas(engine)
}

func resetVideoCanvas(_ engine: AgoraRtcEngineKit) {
let canvas = AgoraRtcVideoCanvas()
canvas.view = nil
canvas.renderMode = self.canvas.renderMode
canvas.channelId = self.canvas.channelId
canvas.uid = self.canvas.uid
canvas.mirrorMode = self.canvas.mirrorMode
if let it = self.canvas {
let canvas = AgoraRtcVideoCanvas()
canvas.view = nil
canvas.renderMode = it.renderMode
canvas.channelId = it.channelId
canvas.uid = it.uid
canvas.mirrorMode = it.mirrorMode

if canvas.uid == 0 {
engine.setupLocalVideo(canvas)
} else {
engine.setupRemoteVideo(canvas)
if canvas.uid == 0 {
engine.setupLocalVideo(canvas)
} else {
engine.setupRemoteVideo(canvas)
}
}
}

Expand All @@ -58,32 +62,36 @@ class RtcSurfaceView: UIView {
}
surface = UIView(frame: CGRect(origin: CGPoint(x: 0, y: 0), size: bounds.size))
addSubview(surface)
canvas.view = surface
if canvas.uid == 0 {
engine.setupLocalVideo(canvas)
} else {
engine.setupRemoteVideo(canvas)
if let canvas = self.canvas {
canvas.view = surface
if canvas.uid == 0 {
engine.setupLocalVideo(canvas)
} else {
engine.setupRemoteVideo(canvas)
}
}
}

func setRenderMode(_ engine: AgoraRtcEngineKit, _ renderMode: UInt) {
canvas.renderMode = AgoraVideoRenderMode(rawValue: renderMode)!
canvas?.renderMode = AgoraVideoRenderMode(rawValue: renderMode)!
setupRenderMode(engine)
}

func setMirrorMode(_ engine: AgoraRtcEngineKit, _ mirrorMode: UInt) {
canvas.mirrorMode = AgoraVideoMirrorMode(rawValue: mirrorMode)!
canvas?.mirrorMode = AgoraVideoMirrorMode(rawValue: mirrorMode)!
setupRenderMode(engine)
}

private func setupRenderMode(_ engine: AgoraRtcEngineKit) {
if canvas.uid == 0 {
engine.setLocalRenderMode(canvas.renderMode, mirrorMode: canvas.mirrorMode)
} else {
if let channel = channel {
channel.setRemoteRenderMode(canvas.uid, renderMode: canvas.renderMode, mirrorMode: canvas.mirrorMode)
if let canvas = self.canvas {
if canvas.uid == 0 {
engine.setLocalRenderMode(canvas.renderMode, mirrorMode: canvas.mirrorMode)
} else {
engine.setRemoteRenderMode(canvas.uid, renderMode: canvas.renderMode, mirrorMode: canvas.mirrorMode)
if let channel = channel {
channel.setRemoteRenderMode(canvas.uid, renderMode: canvas.renderMode, mirrorMode: canvas.mirrorMode)
} else {
engine.setRemoteRenderMode(canvas.uid, renderMode: canvas.renderMode, mirrorMode: canvas.mirrorMode)
}
}
}
}
Expand Down

0 comments on commit 03d9168

Please sign in to comment.