Skip to content

Commit

Permalink
fix: Android miss unregister
Browse files Browse the repository at this point in the history
  • Loading branch information
LichKing-2234 committed Nov 20, 2020
1 parent efd3ef9 commit 7fcaf4f
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,48 +11,76 @@ import io.agora.rtc.rawdata.base.VideoFrame
import java.util.*

class AgoraRawdataModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) {
private var audioObserver: IAudioFrameObserver? = null
private var videoObserver: IVideoFrameObserver? = null

override fun getName(): String {
return "AgoraRawdata"
}

@ReactMethod
fun registerAudioFrameObserver(engineHandle: Double, promise: Promise) {
object : IAudioFrameObserver(engineHandle.toLong()) {
override fun onRecordAudioFrame(audioFrame: AudioFrame): Boolean {
return true
}
if (audioObserver == null) {
audioObserver = object : IAudioFrameObserver(engineHandle.toLong()) {
override fun onRecordAudioFrame(audioFrame: AudioFrame): Boolean {
return true
}

override fun onPlaybackAudioFrame(audioFrame: AudioFrame): Boolean {
return true
}
override fun onPlaybackAudioFrame(audioFrame: AudioFrame): Boolean {
return true
}

override fun onMixedAudioFrame(audioFrame: AudioFrame): Boolean {
return true
}
override fun onMixedAudioFrame(audioFrame: AudioFrame): Boolean {
return true
}

override fun onPlaybackAudioFrameBeforeMixing(uid: Int, audioFrame: AudioFrame): Boolean {
return true
override fun onPlaybackAudioFrameBeforeMixing(uid: Int, audioFrame: AudioFrame): Boolean {
return true
}
}
}.registerAudioFrameObserver()
promise.resolve(0)
}
audioObserver?.registerAudioFrameObserver()
promise.resolve(null)
}

@ReactMethod
fun unregisterAudioFrameObserver(promise: Promise) {
audioObserver?.let {
it.unregisterAudioFrameObserver()
audioObserver = null
}
promise.resolve(null)
}

@ReactMethod
fun registerVideoFrameObserver(engineHandle: Double, promise: Promise) {
object : IVideoFrameObserver(engineHandle.toLong()) {
override fun onCaptureVideoFrame(videoFrame: VideoFrame): Boolean {
Arrays.fill(videoFrame.getuBuffer(), 0)
Arrays.fill(videoFrame.getvBuffer(), 0)
return true
}
if (videoObserver == null) {
videoObserver = object : IVideoFrameObserver(engineHandle.toLong()) {
override fun onCaptureVideoFrame(videoFrame: VideoFrame): Boolean {
Arrays.fill(videoFrame.getuBuffer(), 0)
Arrays.fill(videoFrame.getvBuffer(), 0)
return true
}

override fun onRenderVideoFrame(uid: Int, videoFrame: VideoFrame): Boolean {
Arrays.fill(videoFrame.getuBuffer(), -128)
Arrays.fill(videoFrame.getvBuffer(), -128)
return true
override fun onRenderVideoFrame(uid: Int, videoFrame: VideoFrame): Boolean {
// unsigned char value 255
Arrays.fill(videoFrame.getuBuffer(), -1)
Arrays.fill(videoFrame.getvBuffer(), -1)
return true
}
}
}.registerVideoFrameObserver()
promise.resolve(0)
}
videoObserver?.registerVideoFrameObserver()
promise.resolve(null)
}

@ReactMethod
fun unregisterVideoFrameObserver(promise: Promise) {
videoObserver?.let {
it.unregisterVideoFrameObserver()
videoObserver = null
}
promise.resolve(null)
}

companion object {
Expand Down
8 changes: 5 additions & 3 deletions ios/React/AgoraRawdata.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,15 @@ class AgoraRawdata: NSObject, RCTBridgeModule, AgoraAudioFrameDelegate, AgoraVid
return true
}

func onCapture(_: AgoraVideoFrame) -> Bool {
func onCapture(_ videoFrame: AgoraVideoFrame) -> Bool {
memset(videoFrame.uBuffer, 0, Int(videoFrame.uStride * videoFrame.height) / 2)
memset(videoFrame.vBuffer, 0, Int(videoFrame.vStride * videoFrame.height) / 2)
return true
}

func onRenderVideoFrame(_ videoFrame: AgoraVideoFrame, uid _: UInt) -> Bool {
memset(videoFrame.uBuffer, 0, Int(videoFrame.uStride * videoFrame.height) / 2)
memset(videoFrame.vBuffer, 0, Int(videoFrame.vStride * videoFrame.height) / 2)
memset(videoFrame.uBuffer, 255, Int(videoFrame.uStride * videoFrame.height) / 2)
memset(videoFrame.vBuffer, 255, Int(videoFrame.vStride * videoFrame.height) / 2)
return true
}
}

0 comments on commit 7fcaf4f

Please sign in to comment.