forked from AgoraIO-Extensions/react-native-agora-rawdata
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AgoraRawdata.swift
91 lines (75 loc) · 2.85 KB
/
AgoraRawdata.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
//
// AgoraRawdata.swift
// AgoraRawdata
//
// Created by LXH on 2020/11/11.
// Copyright © 2020 Facebook. All rights reserved.
//
import Foundation
@objc(AgoraRawdata)
class AgoraRawdata: NSObject, RCTBridgeModule, AgoraAudioFrameDelegate, AgoraVideoFrameDelegate {
static let REACT_CLASS = "AgoraRawdata"
private var audioObserver: AgoraAudioFrameObserver?
private var videoObserver: AgoraVideoFrameObserver?
static func moduleName() -> String! {
return AgoraRawdata.REACT_CLASS
}
static func requiresMainQueueSetup() -> Bool {
return true
}
var methodQueue: DispatchQueue! = DispatchQueue.main
@objc func registerAudioFrameObserver(_ engineHandle: NSNumber, _ resolve: RCTPromiseResolveBlock?, _: RCTPromiseRejectBlock?) {
if audioObserver == nil {
audioObserver = AgoraAudioFrameObserver(engineHandle: engineHandle.uintValue)
}
audioObserver?.delegate = self
audioObserver?.register()
resolve?(0)
}
@objc func unregisterAudioFrameObserver(_ resolve: RCTPromiseResolveBlock?, _: RCTPromiseRejectBlock?) {
if audioObserver != nil {
audioObserver?.delegate = nil
audioObserver?.unregisterAudioFrameObserver()
audioObserver = nil
}
resolve?(0)
}
@objc func registerVideoFrameObserver(_ engineHandle: NSNumber, _ resolve: RCTPromiseResolveBlock?, _: RCTPromiseRejectBlock?) {
if videoObserver == nil {
videoObserver = AgoraVideoFrameObserver(engineHandle: engineHandle.uintValue)
}
videoObserver?.delegate = self
videoObserver?.register()
resolve?(0)
}
@objc func unregisterVideoFrameObserver(_ resolve: RCTPromiseResolveBlock?, _: RCTPromiseRejectBlock?) {
if videoObserver != nil {
videoObserver?.delegate = nil
videoObserver?.unregisterVideoFrameObserver()
videoObserver = nil
}
resolve?(0)
}
func onRecord(_: AgoraAudioFrame) -> Bool {
return true
}
func onPlaybackAudioFrame(_: AgoraAudioFrame) -> Bool {
return true
}
func onMixedAudioFrame(_: AgoraAudioFrame) -> Bool {
return true
}
func onPlaybackAudioFrame(beforeMixing _: AgoraAudioFrame, uid _: UInt) -> Bool {
return true
}
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, 255, Int(videoFrame.uStride * videoFrame.height) / 2)
memset(videoFrame.vBuffer, 255, Int(videoFrame.vStride * videoFrame.height) / 2)
return true
}
}