Skip to content

Commit

Permalink
update WebRTC stack m117
Browse files Browse the repository at this point in the history
  • Loading branch information
burak-58 committed Oct 30, 2023
1 parent 4142ca1 commit a99fd7e
Show file tree
Hide file tree
Showing 45 changed files with 739 additions and 2,493 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,7 @@ public void init(String url, String streamId, String mode, String token, Intent

public boolean checkPermissions(PermissionCallback permissionCallback) {
boolean isForPublish = streamMode.equals(MODE_PUBLISH) ||
streamMode.equals(MODE_JOIN) ||
streamMode.equals(MODE_TRACK_BASED_CONFERENCE);

return webRTCListener.checkAndRequestPermisssions(isForPublish, permissionCallback);
Expand Down Expand Up @@ -1283,14 +1284,23 @@ else if (streamMode.equals(IWebRTCClient.MODE_PLAY)) {
}
else if (streamMode.equals(IWebRTCClient.MODE_JOIN)) {
init(this.url, streamId, this.streamMode, token, this.intent);
wsHandler.joinToPeer(streamId, token);
join(streamId);
}
else if (streamMode.equals(IWebRTCClient.MODE_MULTI_TRACK_PLAY)) {
init(this.url, streamId, this.streamMode, token, this.intent);
wsHandler.getTrackList(streamId, token);
}
}

private void join(String streamId) {
Log.e(TAG, "Join: "+streamId);
PeerInfo peerInfo = new PeerInfo(streamId, MODE_JOIN);
peers.put(streamId, peerInfo);

init(this.url, streamId, this.streamMode, this.token, this.intent);
wsHandler.joinToPeer(streamId, token);
}

public void publish(String streamId, String token, boolean videoCallEnabled, boolean audioCallEnabled, String subscriberId, String subscriberCode, String streamName, String mainTrackId) {
Log.e(TAG, "Publish: "+streamId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,9 @@
/**
* Android hardware video decoder.
*/
@SuppressWarnings("deprecation")
// Cannot support API 16 without using deprecated methods.
// TODO(sakal): Rename to MediaCodecVideoDecoder once the deprecated implementation is removed.
class AndroidVideoDecoder implements VideoDecoder, VideoSink {
private static final String TAG = "AndroidVideoDecoder";

// TODO(magjed): Use MediaFormat.KEY_* constants when part of the public API.
private static final String MEDIA_FORMAT_KEY_STRIDE = "stride";
private static final String MEDIA_FORMAT_KEY_SLICE_HEIGHT = "slice-height";
private static final String MEDIA_FORMAT_KEY_CROP_LEFT = "crop-left";
private static final String MEDIA_FORMAT_KEY_CROP_RIGHT = "crop-right";
private static final String MEDIA_FORMAT_KEY_CROP_TOP = "crop-top";
private static final String MEDIA_FORMAT_KEY_CROP_BOTTOM = "crop-bottom";

// MediaCodec.release() occasionally hangs. Release stops waiting and reports failure after
// this timeout.
private static final int MEDIA_CODEC_RELEASE_TIMEOUT_MS = 5000;
Expand Down Expand Up @@ -162,7 +151,7 @@ private VideoCodecStatus initDecodeInternal(int width, int height) {
decoderThreadChecker.checkIsOnValidThread();
Logging.d(TAG,
"initDecodeInternal name: " + codecName + " type: " + codecType + " width: " + width
+ " height: " + height);
+ " height: " + height + " color format: " + colorFormat);
if (outputThread != null) {
Logging.e(TAG, "initDecodeInternal called while the codec is already running");
return VideoCodecStatus.FALLBACK_SOFTWARE;
Expand Down Expand Up @@ -568,17 +557,17 @@ private VideoFrame.Buffer copyI420Buffer(

private void reformat(MediaFormat format) {
outputThreadChecker.checkIsOnValidThread();
Logging.d(TAG, "Decoder format changed: " + format.toString());
Logging.d(TAG, "Decoder format changed: " + format);
final int newWidth;
final int newHeight;
if (format.containsKey(MEDIA_FORMAT_KEY_CROP_LEFT)
&& format.containsKey(MEDIA_FORMAT_KEY_CROP_RIGHT)
&& format.containsKey(MEDIA_FORMAT_KEY_CROP_BOTTOM)
&& format.containsKey(MEDIA_FORMAT_KEY_CROP_TOP)) {
newWidth = 1 + format.getInteger(MEDIA_FORMAT_KEY_CROP_RIGHT)
- format.getInteger(MEDIA_FORMAT_KEY_CROP_LEFT);
newHeight = 1 + format.getInteger(MEDIA_FORMAT_KEY_CROP_BOTTOM)
- format.getInteger(MEDIA_FORMAT_KEY_CROP_TOP);
if (format.containsKey(MediaFormat.KEY_CROP_LEFT)
&& format.containsKey(MediaFormat.KEY_CROP_RIGHT)
&& format.containsKey(MediaFormat.KEY_CROP_BOTTOM)
&& format.containsKey(MediaFormat.KEY_CROP_TOP)) {
newWidth = 1 + format.getInteger(MediaFormat.KEY_CROP_RIGHT)
- format.getInteger(MediaFormat.KEY_CROP_LEFT);
newHeight = 1 + format.getInteger(MediaFormat.KEY_CROP_BOTTOM)
- format.getInteger(MediaFormat.KEY_CROP_TOP);
} else {
newWidth = format.getInteger(MediaFormat.KEY_WIDTH);
newHeight = format.getInteger(MediaFormat.KEY_HEIGHT);
Expand Down Expand Up @@ -615,11 +604,11 @@ private void reformat(MediaFormat format) {

// Save stride and sliceHeight under the dimension lock.
synchronized (dimensionLock) {
if (format.containsKey(MEDIA_FORMAT_KEY_STRIDE)) {
stride = format.getInteger(MEDIA_FORMAT_KEY_STRIDE);
if (format.containsKey(MediaFormat.KEY_STRIDE)) {
stride = format.getInteger(MediaFormat.KEY_STRIDE);
}
if (format.containsKey(MEDIA_FORMAT_KEY_SLICE_HEIGHT)) {
sliceHeight = format.getInteger(MEDIA_FORMAT_KEY_SLICE_HEIGHT);
if (format.containsKey(MediaFormat.KEY_SLICE_HEIGHT)) {
sliceHeight = format.getInteger(MediaFormat.KEY_SLICE_HEIGHT);
}
Logging.d(TAG, "Frame stride and slice height: " + stride + " x " + sliceHeight);
stride = Math.max(width, stride);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
import android.content.Context;
import android.graphics.Rect;
import android.graphics.SurfaceTexture;
import android.hardware.camera2.CameraAccessException;
import android.hardware.camera2.CameraCharacteristics;
import android.hardware.camera2.CameraManager;
import android.hardware.camera2.CameraMetadata;
import android.hardware.camera2.params.StreamConfigurationMap;
import android.os.Build;
import android.os.SystemClock;
import android.util.AndroidException;
import android.util.Range;
import androidx.annotation.Nullable;
import java.util.ArrayList;
Expand Down Expand Up @@ -50,10 +50,7 @@ public Camera2Enumerator(Context context) {
public String[] getDeviceNames() {
try {
return cameraManager.getCameraIdList();
// On Android OS pre 4.4.2, a class will not load because of VerifyError if it contains a
// catch statement with an Exception from a newer API, even if the code is never executed.
// https://code.google.com/p/android/issues/detail?id=209129
} catch (/* CameraAccessException */ AndroidException e) {
} catch (CameraAccessException e) {
Logging.e(TAG, "Camera access exception", e);
return new String[] {};
}
Expand Down Expand Up @@ -92,10 +89,7 @@ public CameraVideoCapturer createCapturer(
private @Nullable CameraCharacteristics getCameraCharacteristics(String deviceName) {
try {
return cameraManager.getCameraCharacteristics(deviceName);
// On Android OS pre 4.4.2, a class will not load because of VerifyError if it contains a
// catch statement with an Exception from a newer API, even if the code is never executed.
// https://code.google.com/p/android/issues/detail?id=209129
} catch (/* CameraAccessException */ AndroidException e) {
} catch (CameraAccessException | RuntimeException e) {
Logging.e(TAG, "Camera access exception", e);
return null;
}
Expand All @@ -115,10 +109,7 @@ public static boolean isSupported(Context context) {
return false;
}
}
// On Android OS pre 4.4.2, a class will not load because of VerifyError if it contains a
// catch statement with an Exception from a newer API, even if the code is never executed.
// https://code.google.com/p/android/issues/detail?id=209129
} catch (/* CameraAccessException */ AndroidException | RuntimeException e) {
} catch (CameraAccessException | RuntimeException e) {
Logging.e(TAG, "Failed to check if camera2 is supported", e);
return false;
}
Expand Down
50 changes: 50 additions & 0 deletions webrtc-android-framework/src/main/java/org/webrtc/EglBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,38 @@ public interface Context {
long getNativeEglContext();
}

/**
* Wraps the objects needed to interact with EGL that are independent of a particular EGLSurface.
* In practice this means EGLContext, EGLDisplay and EGLConfig objects. Separating them out in a
* standalone object allows for multiple EglBase instances to use the same underlying EGLContext,
* while still operating on their own EGLSurface.
*/
public interface EglConnection extends RefCounted {
/** Analogous to corresponding EglBase#create below. */
public static EglConnection create(@Nullable Context sharedContext, int[] configAttributes) {
if (sharedContext == null) {
return EglConnection.createEgl14(configAttributes);
} else if (sharedContext instanceof EglBase14.Context) {
return new EglBase14Impl.EglConnection(
((EglBase14.Context) sharedContext).getRawContext(), configAttributes);
} else if (sharedContext instanceof EglBase10.Context) {
return new EglBase10Impl.EglConnection(
((EglBase10.Context) sharedContext).getRawContext(), configAttributes);
}
throw new IllegalArgumentException("Unrecognized Context");
}

/** Analogous to corresponding EglBase#createEgl10 below. */
public static EglConnection createEgl10(int[] configAttributes) {
return new EglBase10Impl.EglConnection(/* sharedContext= */ null, configAttributes);
}

/** Analogous to corresponding EglBase#createEgl14 below. */
public static EglConnection createEgl14(int[] configAttributes) {
return new EglBase14Impl.EglConnection(/* sharedContext= */ null, configAttributes);
}
}

// According to the documentation, EGL can be used from multiple threads at the same time if each
// thread has its own EGLContext, but in practice it deadlocks on some devices when doing this.
// Therefore, synchronize on this global lock before calling dangerous EGL functions that might
Expand Down Expand Up @@ -145,6 +177,24 @@ static int getOpenGlesVersionFromConfig(int[] configAttributes) {
return 1;
}

/**
* Creates a new EglBase with a shared EglConnection. EglBase instances sharing the same
* EglConnection should be used on the same thread to avoid the underlying EGLContext being made
* current on multiple threads. It is up to the client of EglBase to ensure that instances with a
* shared EglConnection are current on that thread before each use since other EglBase instances
* may have used the same EGLContext since the last interaction.
*/
public static EglBase create(EglConnection eglConnection) {
if (eglConnection == null) {
return create();
} else if (eglConnection instanceof EglBase14Impl.EglConnection) {
return new EglBase14Impl((EglBase14Impl.EglConnection) eglConnection);
} else if (eglConnection instanceof EglBase10Impl.EglConnection) {
return new EglBase10Impl((EglBase10Impl.EglConnection) eglConnection);
}
throw new IllegalArgumentException("Unrecognized EglConnection");
}

/**
* Create a new context with the specified config attributes, sharing data with `sharedContext`.
* If `sharedContext` is null, a root EGL 1.4 context is created.
Expand Down
13 changes: 13 additions & 0 deletions webrtc-android-framework/src/main/java/org/webrtc/EglBase10.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,24 @@

package org.webrtc;

import javax.microedition.khronos.egl.EGL10;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.egl.EGLContext;
import javax.microedition.khronos.egl.EGLDisplay;

/** EGL 1.0 implementation of EglBase. */
public interface EglBase10 extends EglBase {
interface Context extends EglBase.Context {
EGLContext getRawContext();
}

interface EglConnection extends EglBase.EglConnection {
EGL10 getEgl();

EGLContext getContext();

EGLDisplay getDisplay();

EGLConfig getConfig();
}
}
Loading

0 comments on commit a99fd7e

Please sign in to comment.