forked from react-native-webrtc/react-native-webrtc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
32348af
commit ba5e404
Showing
4 changed files
with
270 additions
and
74 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
android/src/main/java/com/oney/WebRTCModule/AudioSamplesInterceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.oney.WebRTCModule; | ||
|
||
import android.annotation.SuppressLint; | ||
|
||
import org.webrtc.audio.JavaAudioDeviceModule.SamplesReadyCallback; | ||
import org.webrtc.audio.JavaAudioDeviceModule.AudioSamples; | ||
|
||
import java.util.HashMap; | ||
|
||
// Note: This is a happy path implementation and heavily based off of Flutters webrtc implementation | ||
// https://github.com/flutter-webrtc/flutter-webrtc/blob/main/android/src/main/java/com/cloudwebrtc/webrtc/record/AudioSamplesInterceptor.java | ||
|
||
/** JavaAudioDeviceModule allows attaching samples callback only on building | ||
* We don't want to instantiate VideoFileRenderer and codecs at this step | ||
* It's simple dummy class, it does nothing until samples are necessary */ | ||
@SuppressWarnings("WeakerAccess") | ||
public class AudioSamplesInterceptor implements SamplesReadyCallback { | ||
|
||
@SuppressLint("UseSparseArrays") | ||
protected final HashMap<String, SamplesReadyCallback> callbacks = new HashMap<>(); | ||
|
||
@Override | ||
public void onWebRtcAudioRecordSamplesReady(AudioSamples audioSamples) { | ||
for (SamplesReadyCallback callback : callbacks.values()) { | ||
callback.onWebRtcAudioRecordSamplesReady(audioSamples); | ||
} | ||
} | ||
|
||
public void attachCallback(String id, SamplesReadyCallback callback) throws Exception { | ||
callbacks.put(id, callback); | ||
} | ||
|
||
public void detachCallback(String id) { | ||
callbacks.remove(id); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.