8000 Updating WebRTC lib #1 · flutter-webrtc/flutter-webrtc@9a78b81 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9a78b81

Browse files
committed
Updating WebRTC lib #1
It builds 🎉 Loopback sample working. Poorly
1 parent 396d9d9 commit 9a78b81

File tree

9 files changed

+125
-128
lines changed

9 files changed

+125
-128
lines changed

android/build.gradle

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ buildscript {
88
}
99

1010
dependencies {
11-
classpath 'com.android.tools.build:gradle:3.0.1'
11+
classpath 'com.android.tools.build:gradle:3.2.1'
1212
}
1313
}
1414

@@ -22,23 +22,24 @@ rootProject.allprojects {
2222
apply plugin: 'com.android.library'
2323

2424
android {
25-
compileSdkVersion 23
25+
compileSdkVersion 28
2626

2727
defaultConfig {
2828
minSdkVersion 21
2929
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
30-
ndk {
31-
abiFilters "armeabi-v7a", "x86"
32-
}
3330
}
31+
3432
lintOptions {
3533
disable 'InvalidPackage'
3634
}
35+
36+
compileOptions {
37+
sourceCompatibility JavaVersion.VERSION_1_8
38+
targetCompatibility JavaVersion.VERSION_1_8
39+
}
3740
}
3841

3942
dependencies {
40-
implementation fileTree(dir: 'libs', include: ['*.jar'])
41-
implementation "com.android.support:appcompat-v7:23.0.1"
42-
implementation "com.android.support:support-v4:23.0.1"
43+
api 'org.webrtc:google-webrtc:1.0.25331'
4344
implementation "com.android.support:support-annotations:22.0.0"
4445
}
-15.6 MB
Binary file not shown.

android/libs/libwebrtc.jar

-730 KB
Binary file not shown.

android/src/main/java/com/cloudwebrtc/webrtc/FlutterRTCVideoRenderer.java

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
import org.webrtc.EglBase;
1313
import org.webrtc.MediaStream;
1414
import org.webrtc.RendererCommon.RendererEvents;
15-
import org.webrtc.VideoRenderer;
15+
import org.webrtc.SurfaceViewRenderer;
1616
import org.webrtc.VideoTrack;
1717

1818
import io.flutter.plugin.common.EventChannel;
1919

20-
public class FlutterRTCVideoRenderer implements EventChannel.StreamHandler {
20+
public class FlutterRTCVideoRenderer implements EventChannel.StreamHandler {
2121

2222
private static final String TAG = FlutterWebRTCPlugin.TAG;
2323
private final SurfaceTexture texture;
@@ -90,12 +90,6 @@ public void onFrameResolutionChanged(
9090

9191
private SurfaceTextureRenderer surfaceTextureRenderer;
9292

93-
/**
94-
* The {@code VideoRenderer}, if any, which renders {@link #videoTrack} on
95-
* this {@code View}.
96-
*/
97-
private VideoRenderer videoRenderer;
98-
9993
/**
10094
* The {@code VideoTrack}, if any, rendered by this {@code FlutterRTCVideoRenderer}.
10195
*/
@@ -106,6 +100,8 @@ public void onFrameResolutionChanged(
106100

107101
public FlutterRTCVideoRenderer(SurfaceTexture texture, Context context) {
108102
this.surfaceTextureRenderer = new SurfaceTextureRenderer(context, texture);
103+
SurfaceViewRenderer svr = new SurfaceViewRenderer(context);
104+
109105
this.texture = texture;
110106
this.context = context;
111107
this.eventSink = null;
@@ -134,11 +130,7 @@ public void onCancel(Object o) {
134130
* resources (if rendering is in progress).
135131
*/
136132
private void removeRendererFromVideoTrack() {
137-
if (videoRenderer != null) {
138-
videoTrack.removeRenderer(videoRenderer);
139-
videoRenderer.dispose();
140-
videoRenderer = null;
141-
}
133+
videoTrack.removeSink(surfaceTextureRenderer);
142134
}
143135

144136
/**
@@ -181,8 +173,8 @@ private void setVideoTrack(VideoTrack videoTrack) {
181173

182174
if (videoTrack != null) {
183175
tryAddRendererToVideoTrack();
184-
}else{
185-
176+
} else {
177+
Log.w(TAG, "VideoTrack is null");
186178
}
187179
}
188180
}
@@ -192,8 +184,7 @@ private void setVideoTrack(VideoTrack videoTrack) {
192184
* all preconditions for the start of rendering are met.
193185
*/
194186
private void tryAddRendererToVideoTrack() {
195-
if (videoRenderer == null
196-
&& videoTrack != null) {
187+
if (videoTrack != null) {
197188
EglBase.Context sharedContext = EglUtils.getRootEglBaseContext();
198189

199190
if (sharedContext == null) {
@@ -207,8 +198,8 @@ private void tryAddRendererToVideoTrack() {
207198
surfaceTextureRenderer = new SurfaceTextureRenderer(context, texture);
208199
surfaceTextureRenderer.init(sharedContext, rendererEvents);
209200

210-
videoRenderer = new VideoRenderer(surfaceTextureRenderer);
211-
videoTrack.addRenderer(videoRenderer);
201+
videoTrack.addSink(surfaceTextureRenderer);
212202
}
213203
}
204+
214205
}

android/src/main/java/com/cloudwebrtc/webrtc/FlutterWebRTCPlugin.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import android.content.Context;
55
import android.hardware.Camera;
66
import android.graphics.SurfaceTexture;
7+
import android.os.Process;
78
import android.util.Log;
89
import android.util.LongSparseArray;
910

@@ -26,6 +27,8 @@
2627
import org.webrtc.SdpObserver;
2728
import org.webrtc.SessionDescription;
2829
import org.webrtc.VideoTrack;
30+
import org.webrtc.audio.AudioDeviceModule;
31+
import org.webrtc.audio.JavaAudioDeviceModule;
2932

3033
import io.flutter.plugin.common.EventChannel;
3134
import io.flutter.plugin.common.MethodChannel;
@@ -91,15 +94,21 @@ private FlutterWebRTCPlugin(Registrar registrar, MethodChannel channel) {
9194
PeerConnectionFactory.initialize(
9295
PeerConnectionFactory.InitializationOptions.builder(registrar.context())
9396
.setEnableInternalTracer(false)
94-
.setEnableVideoHwAcceleration(true)
9597
.createInitializationOptions());
9698

97-
mFactory = new PeerConnectionFactory(null);
99+
final AudioDeviceModule audioDeviceModule = JavaAudioDeviceModule.builder(registrar.context())
100+
.setUseHardwareAcousticEchoCanceler(true)
101+
.setUseHardwareNoiseSuppressor(true)
102+
.createAudioDeviceModule();
103+
98104
// Initialize EGL contexts required for HW acceleration.
99-
EglBase.Context eglContext = EglUtils.getRootEglBaseContext();
100-
if (eglContext != null) {
101-
mFactory.setVideoHwAccelerationOptions(eglContext, eglContext);
102-
}
105+
EglUtils.getRootEglBaseContext();
106+
107+
mFactory = PeerConnectionFactory.builder()
108+
.setOptions(new PeerConnectionFactory.Options())
109+
.setAudioDeviceModule(audioDeviceModule)
110+
.createPeerConnectionFactory();
111+
103112
getUserMediaImpl = new GetUserMediaImpl(this, registrar.context());
104113
}
105114

@@ -1042,4 +1051,5 @@ public void dataChannelClose(String peerConnectionId, int dataChannelId) {
10421051
pco.dataChannelClose(dataChannelId);
10431052
}
10441053
}
1054+
10451055
}

android/src/main/java/com/cloudwebrtc/webrtc/GetUserMediaImpl.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.cloudwebrtc.webrtc.utils.Callback;
2121
import com.cloudwebrtc.webrtc.utils.ConstraintsArray;
2222
import com.cloudwebrtc.webrtc.utils.ConstraintsMap;
23+
import com.cloudwebrtc.webrtc.utils.EglUtils;
2324
import com.cloudwebrtc.webrtc.utils.ObjectType;
2425
import com.cloudwebrtc.webrtc.utils.PermissionUtils;
2526

@@ -365,7 +366,7 @@ public void onStop() {
365366
if (videoCapturer != null) {
366367

367368
PeerConnectionFactory pcFactory = plugin.mFactory;
368-
VideoSource videoSource = pcFactory.createVideoSource(videoCapturer);
369+
VideoSource videoSource = pcFactory.createVideoSource(true);
369370

370371
// Fall back to defaults if keys are missing.
371372
int width
@@ -426,7 +427,7 @@ public void onStop() {
426427
}
427428
}
428429

429-
String streamId = mediaStream.label();
430+
String streamId = mediaStream.getId();
430431

431432
Log.d(TAG, "MediaStream id: " + streamId);
432433
plugin.localStreams.put(streamId, mediaStream);
@@ -580,7 +581,7 @@ private void getUserMedia(
580581
}
581582
}
582583

583-
String streamId = mediaStream.label();
584+
String streamId = mediaStream.getId();
584585

585586
Log.d(TAG, "MediaStream id: " + streamId);
586587
plugin.localStreams.put(streamId, mediaStream);
@@ -636,7 +637,10 @@ private VideoTrack getUserVideo(ConstraintsMap constraints) {
636637
}
637638

638639
PeerConnectionFactory pcFactory = plugin.mFactory;
639-
VideoSource videoSource = pcFactory.createVideoSource(videoCapturer);
640+
VideoSource videoSource = pcFactory.createVideoSource(false);
641+
String threadName = Thread.currentThread().getName();
642+
SurfaceTextureHelper surfaceTextureHelper = SurfaceTextureHelper.create(threadName, EglUtils.getRootEglBaseContext());
643+
videoCapturer.initialize(surfaceTextureHelper, context, videoSource.getCapturerObserver());
640644

641645
// Fall back to defaults if keys are missing.
642646
int width

0 commit comments

Comments
 (0)
0