Skip to content

Commit b520e56

Browse files
authored
Merge pull request #253 from GetStream/elgbase
Add elgbase & thread & connections
2 parents 0ee592a + 5395685 commit b520e56

9 files changed

Lines changed: 868 additions & 288 deletions

File tree

stream-webrtc-android/api/stream-webrtc-android.api

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ public abstract interface class org/webrtc/EglBase {
315315
public static fun create ()Lorg/webrtc/EglBase;
316316
public static fun create (Lorg/webrtc/EglBase$Context;)Lorg/webrtc/EglBase;
317317
public static fun create (Lorg/webrtc/EglBase$Context;[I)Lorg/webrtc/EglBase;
318+
public static fun create (Lorg/webrtc/EglBase$EglConnection;)Lorg/webrtc/EglBase;
318319
public abstract fun createDummyPbufferSurface ()V
319320
public static fun createEgl10 (Ljavax/microedition/khronos/egl/EGLContext;[I)Lorg/webrtc/EglBase10;
320321
public static fun createEgl10 (Lorg/webrtc/EglBase10$Context;[I)Lorg/webrtc/EglBase10;
@@ -352,20 +353,39 @@ public abstract interface class org/webrtc/EglBase$Context {
352353
public abstract fun getNativeEglContext ()J
353354
}
354355

356+
public abstract interface class org/webrtc/EglBase$EglConnection : org/webrtc/RefCounted {
357+
public static fun create (Lorg/webrtc/EglBase$Context;[I)Lorg/webrtc/EglBase$EglConnection;
358+
public static fun createEgl10 ([I)Lorg/webrtc/EglBase$EglConnection;
359+
public static fun createEgl14 ([I)Lorg/webrtc/EglBase$EglConnection;
360+
}
361+
355362
public abstract interface class org/webrtc/EglBase10 : org/webrtc/EglBase {
356363
}
357364

358365
public abstract interface class org/webrtc/EglBase10$Context : org/webrtc/EglBase$Context {
359366
public abstract fun getRawContext ()Ljavax/microedition/khronos/egl/EGLContext;
360367
}
361368

369+
public abstract interface class org/webrtc/EglBase10$EglConnection : org/webrtc/EglBase$EglConnection {
370+
public abstract fun getConfig ()Ljavax/microedition/khronos/egl/EGLConfig;
371+
public abstract fun getContext ()Ljavax/microedition/khronos/egl/EGLContext;
372+
public abstract fun getDisplay ()Ljavax/microedition/khronos/egl/EGLDisplay;
373+
public abstract fun getEgl ()Ljavax/microedition/khronos/egl/EGL10;
374+
}
375+
362376
public abstract interface class org/webrtc/EglBase14 : org/webrtc/EglBase {
363377
}
364378

365379
public abstract interface class org/webrtc/EglBase14$Context : org/webrtc/EglBase$Context {
366380
public abstract fun getRawContext ()Landroid/opengl/EGLContext;
367381
}
368382

383+
public abstract interface class org/webrtc/EglBase14$EglConnection : org/webrtc/EglBase$EglConnection {
384+
public abstract fun getConfig ()Landroid/opengl/EGLConfig;
385+
public abstract fun getContext ()Landroid/opengl/EGLContext;
386+
public abstract fun getDisplay ()Landroid/opengl/EGLDisplay;
387+
}
388+
369389
public class org/webrtc/EglRenderer : org/webrtc/VideoSink {
370390
protected final field name Ljava/lang/String;
371391
public fun <init> (Ljava/lang/String;)V
@@ -380,6 +400,7 @@ public class org/webrtc/EglRenderer : org/webrtc/VideoSink {
380400
public fun disableFpsReduction ()V
381401
public fun init (Lorg/webrtc/EglBase$Context;[ILorg/webrtc/RendererCommon$GlDrawer;)V
382402
public fun init (Lorg/webrtc/EglBase$Context;[ILorg/webrtc/RendererCommon$GlDrawer;Z)V
403+
public fun init (Lorg/webrtc/EglThread;Lorg/webrtc/RendererCommon$GlDrawer;Z)V
383404
public fun onFrame (Lorg/webrtc/VideoFrame;)V
384405
public fun pauseVideo ()V
385406
public fun printStackTrace ()V
@@ -401,6 +422,27 @@ public abstract interface class org/webrtc/EglRenderer$FrameListener {
401422
public abstract fun onFrame (Landroid/graphics/Bitmap;)V
402423
}
403424

425+
public class org/webrtc/EglThread : org/webrtc/RenderSynchronizer$Listener {
426+
public fun addExceptionCallback (Ljava/lang/Runnable;)V
427+
public static fun create (Lorg/webrtc/EglThread$ReleaseMonitor;Lorg/webrtc/EglBase$Context;[I)Lorg/webrtc/EglThread;
428+
public static fun create (Lorg/webrtc/EglThread$ReleaseMonitor;Lorg/webrtc/EglBase$Context;[ILorg/webrtc/RenderSynchronizer;)Lorg/webrtc/EglThread;
429+
public fun createEglBaseWithSharedConnection ()Lorg/webrtc/EglBase;
430+
public fun getHandler ()Landroid/os/Handler;
431+
public fun onRenderWindowClose ()V
432+
public fun onRenderWindowOpen ()V
433+
public fun release ()V
434+
public fun removeExceptionCallback (Ljava/lang/Runnable;)V
435+
public fun scheduleRenderUpdate (Lorg/webrtc/EglThread$RenderUpdate;)V
436+
}
437+
438+
public abstract interface class org/webrtc/EglThread$ReleaseMonitor {
439+
public abstract fun onRelease (Lorg/webrtc/EglThread;)Z
440+
}
441+
442+
public abstract interface class org/webrtc/EglThread$RenderUpdate {
443+
public abstract fun update (Z)V
444+
}
445+
404446
public class org/webrtc/EncodedImage : org/webrtc/RefCounted {
405447
public final field buffer Ljava/nio/ByteBuffer;
406448
public final field captureTimeMs J
@@ -1338,6 +1380,18 @@ public abstract interface class org/webrtc/RefCounted {
13381380
public abstract fun retain ()V
13391381
}
13401382

1383+
public final class org/webrtc/RenderSynchronizer {
1384+
public fun <init> ()V
1385+
public fun <init> (F)V
1386+
public fun registerListener (Lorg/webrtc/RenderSynchronizer$Listener;)V
1387+
public fun removeListener (Lorg/webrtc/RenderSynchronizer$Listener;)V
1388+
}
1389+
1390+
public abstract interface class org/webrtc/RenderSynchronizer$Listener {
1391+
public abstract fun onRenderWindowClose ()V
1392+
public abstract fun onRenderWindowOpen ()V
1393+
}
1394+
13411395
public class org/webrtc/RendererCommon {
13421396
public fun <init> ()V
13431397
public static fun convertMatrixFromAndroidGraphicsMatrix (Landroid/graphics/Matrix;)[F

stream-webrtc-android/src/main/java/org/webrtc/EglBase.java

Lines changed: 61 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,3 @@
1-
/*
2-
* Copyright 2015 The WebRTC project authors. All Rights Reserved.
3-
*
4-
* Use of this source code is governed by a BSD-style license
5-
* that can be found in the LICENSE file in the root of the source
6-
* tree. An additional intellectual property rights grant can be found
7-
* in the file PATENTS. All contributing project authors may
8-
* be found in the AUTHORS file in the root of the source tree.
9-
*/
10-
111
package org.webrtc;
122

133
import android.graphics.SurfaceTexture;
@@ -34,6 +24,38 @@ public interface Context {
3424
long getNativeEglContext();
3525
}
3626

27+
/**
28+
* Wraps the objects needed to interact with EGL that are independent of a particular EGLSurface.
29+
* In practice this means EGLContext, EGLDisplay and EGLConfig objects. Separating them out in a
30+
* standalone object allows for multiple EglBase instances to use the same underlying EGLContext,
31+
* while still operating on their own EGLSurface.
32+
*/
33+
public interface EglConnection extends RefCounted {
34+
/** Analogous to corresponding EglBase#create below. */
35+
public static EglConnection create(@Nullable Context sharedContext, int[] configAttributes) {
36+
if (sharedContext == null) {
37+
return EglConnection.createEgl14(configAttributes);
38+
} else if (sharedContext instanceof EglBase14.Context) {
39+
return new EglBase14Impl.EglConnection(
40+
((EglBase14.Context) sharedContext).getRawContext(), configAttributes);
41+
} else if (sharedContext instanceof EglBase10.Context) {
42+
return new EglBase10Impl.EglConnection(
43+
((EglBase10.Context) sharedContext).getRawContext(), configAttributes);
44+
}
45+
throw new IllegalArgumentException("Unrecognized Context");
46+
}
47+
48+
/** Analogous to corresponding EglBase#createEgl10 below. */
49+
public static EglConnection createEgl10(int[] configAttributes) {
50+
return new EglBase10Impl.EglConnection(/* sharedContext= */ null, configAttributes);
51+
}
52+
53+
/** Analogous to corresponding EglBase#createEgl14 below. */
54+
public static EglConnection createEgl14(int[] configAttributes) {
55+
return new EglBase14Impl.EglConnection(/* sharedContext= */ null, configAttributes);
56+
}
57+
}
58+
3759
// According to the documentation, EGL can be used from multiple threads at the same time if each
3860
// thread has its own EGLContext, but in practice it deadlocks on some devices when doing this.
3961
// Therefore, synchronize on this global lock before calling dangerous EGL functions that might
@@ -118,15 +140,15 @@ public int[] createConfigAttributes() {
118140

119141
public static final int[] CONFIG_PLAIN = configBuilder().createConfigAttributes();
120142
public static final int[] CONFIG_RGBA =
121-
configBuilder().setHasAlphaChannel(true).createConfigAttributes();
143+
configBuilder().setHasAlphaChannel(true).createConfigAttributes();
122144
public static final int[] CONFIG_PIXEL_BUFFER =
123-
configBuilder().setSupportsPixelBuffer(true).createConfigAttributes();
145+
configBuilder().setSupportsPixelBuffer(true).createConfigAttributes();
124146
public static final int[] CONFIG_PIXEL_RGBA_BUFFER = configBuilder()
125-
.setHasAlphaChannel(true)
126-
.setSupportsPixelBuffer(true)
127-
.createConfigAttributes();
147+
.setHasAlphaChannel(true)
148+
.setSupportsPixelBuffer(true)
149+
.createConfigAttributes();
128150
public static final int[] CONFIG_RECORDABLE =
129-
configBuilder().setIsRecordable(true).createConfigAttributes();
151+
configBuilder().setIsRecordable(true).createConfigAttributes();
130152

131153
static int getOpenGlesVersionFromConfig(int[] configAttributes) {
132154
for (int i = 0; i < configAttributes.length - 1; ++i) {
@@ -145,6 +167,24 @@ static int getOpenGlesVersionFromConfig(int[] configAttributes) {
145167
return 1;
146168
}
147169

170+
/**
171+
* Creates a new EglBase with a shared EglConnection. EglBase instances sharing the same
172+
* EglConnection should be used on the same thread to avoid the underlying EGLContext being made
173+
* current on multiple threads. It is up to the client of EglBase to ensure that instances with a
174+
* shared EglConnection are current on that thread before each use since other EglBase instances
175+
* may have used the same EGLContext since the last interaction.
176+
*/
177+
public static EglBase create(EglConnection eglConnection) {
178+
if (eglConnection == null) {
179+
return create();
180+
} else if (eglConnection instanceof EglBase14Impl.EglConnection) {
181+
return new EglBase14Impl((EglBase14Impl.EglConnection) eglConnection);
182+
} else if (eglConnection instanceof EglBase10Impl.EglConnection) {
183+
return new EglBase10Impl((EglBase10Impl.EglConnection) eglConnection);
184+
}
185+
throw new IllegalArgumentException("Unrecognized EglConnection");
186+
}
187+
148188
/**
149189
* Create a new context with the specified config attributes, sharing data with `sharedContext`.
150190
* If `sharedContext` is null, a root EGL 1.4 context is created.
@@ -187,15 +227,15 @@ public static EglBase10 createEgl10(int[] configAttributes) {
187227
*/
188228
public static EglBase10 createEgl10(EglBase10.Context sharedContext, int[] configAttributes) {
189229
return new EglBase10Impl(
190-
sharedContext == null ? null : sharedContext.getRawContext(), configAttributes);
230+
sharedContext == null ? null : sharedContext.getRawContext(), configAttributes);
191231
}
192232

193233
/**
194234
* Explicitly create a root EGl 1.0 context with the specified config attributes
195235
* and shared context.
196236
*/
197237
public static EglBase10 createEgl10(
198-
javax.microedition.khronos.egl.EGLContext sharedContext, int[] configAttributes) {
238+
javax.microedition.khronos.egl.EGLContext sharedContext, int[] configAttributes) {
199239
return new EglBase10Impl(sharedContext, configAttributes);
200240
}
201241

@@ -210,15 +250,15 @@ public static EglBase14 createEgl14(int[] configAttributes) {
210250
*/
211251
public static EglBase14 createEgl14(EglBase14.Context sharedContext, int[] configAttributes) {
212252
return new EglBase14Impl(
213-
sharedContext == null ? null : sharedContext.getRawContext(), configAttributes);
253+
sharedContext == null ? null : sharedContext.getRawContext(), configAttributes);
214254
}
215255

216256
/**
217257
* Explicitly create a root EGl 1.4 context with the specified config attributes
218258
* and shared context.
219259
*/
220260
public static EglBase14 createEgl14(
221-
android.opengl.EGLContext sharedContext, int[] configAttributes) {
261+
android.opengl.EGLContext sharedContext, int[] configAttributes) {
222262
return new EglBase14Impl(sharedContext, configAttributes);
223263
}
224264

@@ -252,4 +292,4 @@ public static EglBase14 createEgl14(
252292
void swapBuffers();
253293

254294
void swapBuffers(long presentationTimeStampNs);
255-
}
295+
}

stream-webrtc-android/src/main/java/org/webrtc/EglBase10.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,24 @@
1010

1111
package org.webrtc;
1212

13+
import javax.microedition.khronos.egl.EGL10;
14+
import javax.microedition.khronos.egl.EGLConfig;
1315
import javax.microedition.khronos.egl.EGLContext;
16+
import javax.microedition.khronos.egl.EGLDisplay;
1417

1518
/** EGL 1.0 implementation of EglBase. */
1619
public interface EglBase10 extends EglBase {
1720
interface Context extends EglBase.Context {
1821
EGLContext getRawContext();
1922
}
20-
}
23+
24+
interface EglConnection extends EglBase.EglConnection {
25+
EGL10 getEgl();
26+
27+
EGLContext getContext();
28+
29+
EGLDisplay getDisplay();
30+
31+
EGLConfig getConfig();
32+
}
33+
}

0 commit comments

Comments
 (0)