forked from livekit/react-native-webrtc
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathAudioDeviceModuleObserver.m
More file actions
184 lines (148 loc) · 7.08 KB
/
AudioDeviceModuleObserver.m
File metadata and controls
184 lines (148 loc) · 7.08 KB
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#import "AudioDeviceModuleObserver.h"
#import <React/RCTLog.h>
NS_ASSUME_NONNULL_BEGIN
@interface AudioDeviceModuleObserver ()
@property(weak, nonatomic) WebRTCModule *module;
@end
@implementation AudioDeviceModuleObserver
- (instancetype)initWithWebRTCModule:(WebRTCModule *)module {
self = [super init];
if (self) {
self.module = module;
RCTLog(@"[AudioDeviceModuleObserver] Initialized observer: %@ for module: %@", self, module);
}
return self;
}
#pragma mark - RTCAudioDeviceModuleDelegate
- (void)audioDeviceModule:(RTCAudioDeviceModule *)audioDeviceModule
didReceiveSpeechActivityEvent:(RTCSpeechActivityEvent)speechActivityEvent {
NSString *eventType = speechActivityEvent == RTCSpeechActivityEventStarted ? @"started" : @"ended";
if (self.module.bridge != nil) {
[self.module sendEventWithName:kEventAudioDeviceModuleSpeechActivity
body:@{
@"event" : eventType,
}];
}
RCTLog(@"[AudioDeviceModuleObserver] Speech activity event: %@", eventType);
}
- (NSInteger)audioDeviceModule:(RTCAudioDeviceModule *)audioDeviceModule didCreateEngine:(AVAudioEngine *)engine {
RCTLog(@"[AudioDeviceModuleObserver] Engine created");
if (self.module.bridge != nil) {
[self.module sendEventWithName:kEventAudioDeviceModuleEngineCreated body:@{}];
}
return 0; // Success
}
- (NSInteger)audioDeviceModule:(RTCAudioDeviceModule *)audioDeviceModule
willEnableEngine:(AVAudioEngine *)engine
isPlayoutEnabled:(BOOL)isPlayoutEnabled
isRecordingEnabled:(BOOL)isRecordingEnabled {
RCTLog(@"[AudioDeviceModuleObserver] Engine will enable - playout: %d, recording: %d",
isPlayoutEnabled,
isRecordingEnabled);
if (self.module.bridge != nil) {
[self.module sendEventWithName:kEventAudioDeviceModuleEngineWillEnable
body:@{
@"isPlayoutEnabled" : @(isPlayoutEnabled),
@"isRecordingEnabled" : @(isRecordingEnabled),
}];
}
return 0; // Success
}
- (NSInteger)audioDeviceModule:(RTCAudioDeviceModule *)audioDeviceModule
willStartEngine:(AVAudioEngine *)engine
isPlayoutEnabled:(BOOL)isPlayoutEnabled
isRecordingEnabled:(BOOL)isRecordingEnabled {
RCTLog(@"[AudioDeviceModuleObserver] Engine will start - playout: %d, recording: %d",
isPlayoutEnabled,
isRecordingEnabled);
if (self.module.bridge != nil) {
[self.module sendEventWithName:kEventAudioDeviceModuleEngineWillStart
body:@{
@"isPlayoutEnabled" : @(isPlayoutEnabled),
@"isRecordingEnabled" : @(isRecordingEnabled),
}];
}
return 0; // Success
}
- (NSInteger)audioDeviceModule:(RTCAudioDeviceModule *)audioDeviceModule
didStopEngine:(AVAudioEngine *)engine
isPlayoutEnabled:(BOOL)isPlayoutEnabled
isRecordingEnabled:(BOOL)isRecordingEnabled {
RCTLog(@"[AudioDeviceModuleObserver] Engine did stop - playout: %d, recording: %d",
isPlayoutEnabled,
isRecordingEnabled);
if (self.module.bridge != nil) {
[self.module sendEventWithName:kEventAudioDeviceModuleEngineDidStop
body:@{
@"isPlayoutEnabled" : @(isPlayoutEnabled),
@"isRecordingEnabled" : @(isRecordingEnabled),
}];
}
return 0; // Success
}
- (NSInteger)audioDeviceModule:(RTCAudioDeviceModule *)audioDeviceModule
didDisableEngine:(AVAudioEngine *)engine
isPlayoutEnabled:(BOOL)isPlayoutEnabled
isRecordingEnabled:(BOOL)isRecordingEnabled {
RCTLog(@"[AudioDeviceModuleObserver] Engine did disable - playout: %d, recording: %d",
isPlayoutEnabled,
isRecordingEnabled);
if (self.module.bridge != nil) {
[self.module sendEventWithName:kEventAudioDeviceModuleEngineDidDisable
body:@{
@"isPlayoutEnabled" : @(isPlayoutEnabled),
@"isRecordingEnabled" : @(isRecordingEnabled),
}];
}
return 0; // Success
}
- (NSInteger)audioDeviceModule:(RTCAudioDeviceModule *)audioDeviceModule willReleaseEngine:(AVAudioEngine *)engine {
RCTLog(@"[AudioDeviceModuleObserver] Engine will release");
if (self.module.bridge != nil) {
[self.module sendEventWithName:kEventAudioDeviceModuleEngineWillRelease body:@{}];
}
return 0; // Success
}
- (NSInteger)audioDeviceModule:(RTCAudioDeviceModule *)audioDeviceModule
engine:(AVAudioEngine *)engine
configureInputFromSource:(nullable AVAudioNode *)source
toDestination:(AVAudioNode *)destination
withFormat:(AVAudioFormat *)format
context:(NSDictionary *)context {
RCTLog(@"[AudioDeviceModuleObserver] Configure input - format: %@", format);
return 0;
}
- (NSInteger)audioDeviceModule:(RTCAudioDeviceModule *)audioDeviceModule
engine:(AVAudioEngine *)engine
configureOutputFromSource:(AVAudioNode *)source
toDestination:(nullable AVAudioNode *)destination
withFormat:(AVAudioFormat *)format
context:(NSDictionary *)context {
RCTLog(@"[AudioDeviceModuleObserver] Configure output - format: %@", format);
return 0;
}
- (void)audioDeviceModuleDidUpdateDevices:(RTCAudioDeviceModule *)audioDeviceModule {
if (self.module.bridge != nil) {
[self.module sendEventWithName:kEventAudioDeviceModuleDevicesUpdated body:@{}];
}
RCTLog(@"[AudioDeviceModuleObserver] Devices updated");
}
- (void)audioDeviceModule:(RTCAudioDeviceModule *)audioDeviceModule
didUpdateAudioProcessingState:(RTCAudioProcessingState)state {
if (self.module.bridge != nil) {
[self.module sendEventWithName:kEventAudioDeviceModuleAudioProcessingStateUpdated
body:@{
@"voiceProcessingEnabled" : @(state.voiceProcessingEnabled),
@"voiceProcessingBypassed" : @(state.voiceProcessingBypassed),
@"voiceProcessingAGCEnabled" : @(state.voiceProcessingAGCEnabled),
@"stereoPlayoutEnabled" : @(state.stereoPlayoutEnabled),
}];
}
RCTLog(@"[AudioDeviceModuleObserver] Audio processing state updated - VP enabled: %d, VP bypassed: %d, AGC enabled: %d, stereo: %d",
state.voiceProcessingEnabled,
state.voiceProcessingBypassed,
state.voiceProcessingAGCEnabled,
state.stereoPlayoutEnabled);
}
@end
NS_ASSUME_NONNULL_END