Skip to content

Commit

Permalink
HACKS: Maximize FOV
Browse files Browse the repository at this point in the history
1) Use 4:3 video aspect ratio to prevent cropping to 16:9
2) Disable EIS
3) Zoom out
  • Loading branch information
ASerbinski committed Oct 28, 2022
1 parent 037e0b3 commit 86a0d5d
Show file tree
Hide file tree
Showing 4 changed files with 452 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
import org.webrtc.DefaultVideoDecoderFactory;
import org.webrtc.DefaultVideoEncoderFactory;
import org.webrtc.EglBase;
import org.webrtc.ExtCamera2Enumerator;
import org.webrtc.IceCandidate;
import org.webrtc.Logging;
import org.webrtc.MediaConstraints;
Expand Down Expand Up @@ -257,6 +258,9 @@ public class CallActivity extends CallBaseActivity {
private Handler callInfosHandler = new Handler();
private Handler cameraSwitchHandler = new Handler();

private boolean disableEIS = true;
private boolean zoomOut = true;

// push to talk
private boolean isPushToTalkActive = false;
private PulseAnimation pulseAnimation;
Expand Down Expand Up @@ -454,7 +458,9 @@ private void createCameraEnumerator() {
Log.w(TAG, "Camera2Enumerator threw an error", t);
}

if (camera2EnumeratorIsSupported) {
if (camera2EnumeratorIsSupported & (disableEIS || zoomOut)) {
cameraEnumerator = new ExtCamera2Enumerator(this, disableEIS, zoomOut);
} else if (camera2EnumeratorIsSupported) {
cameraEnumerator = new Camera2Enumerator(this);
} else {
cameraEnumerator = new Camera1Enumerator(MagicWebRTCUtils.shouldEnableVideoHardwareAcceleration());
Expand Down Expand Up @@ -894,7 +900,6 @@ private VideoCapturer createCameraCapturer(CameraEnumerator enumerator) {
}
}


// Front facing camera not found, try something else
Logging.d(TAG, "Looking for other cameras.");
for (String deviceName : deviceNames) {
Expand Down Expand Up @@ -1827,7 +1832,7 @@ public void onComplete() {

private void startVideoCapture() {
if (videoCapturer != null) {
videoCapturer.startCapture(1280, 720, 30);
videoCapturer.startCapture(1280, 960, 30);
}
}

Expand Down
42 changes: 42 additions & 0 deletions app/src/main/java/org/webrtc/ExtCamera2Capturer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package org.webrtc;

import android.content.Context;
import android.hardware.camera2.CameraManager;

import org.jetbrains.annotations.Nullable;

public class ExtCamera2Capturer extends Camera2Capturer {

@Nullable private final CameraManager cameraManager;
private final boolean disableEIS, zoomOut;

public ExtCamera2Capturer(Context context, String cameraName, CameraEventsHandler eventsHandler,
boolean disableEIS, boolean zoomOut) {
super(context, cameraName, eventsHandler);
cameraManager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE);
this.disableEIS = disableEIS;
this.zoomOut = zoomOut;
}

@Override
protected void createCameraSession(CameraSession.CreateSessionCallback createSessionCallback,
CameraSession.Events events, Context applicationContext,
SurfaceTextureHelper surfaceTextureHelper, String cameraName, int width, int height,
int framerate) {

CameraSession.CreateSessionCallback myCallback = new CameraSession.CreateSessionCallback() {
@Override
public void onDone(CameraSession cameraSession) {
createSessionCallback.onDone(cameraSession);
}

@Override
public void onFailure(CameraSession.FailureType failureType, String s) {
createSessionCallback.onFailure(failureType, s);
}
};

ExtCamera2Session.create(myCallback, events, applicationContext, cameraManager,
surfaceTextureHelper, cameraName, width, height, framerate, disableEIS, zoomOut);
}
}
27 changes: 27 additions & 0 deletions app/src/main/java/org/webrtc/ExtCamera2Enumerator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.webrtc;

import android.content.Context;
import android.hardware.camera2.CameraManager;

import org.jetbrains.annotations.Nullable;

public class ExtCamera2Enumerator extends Camera2Enumerator {

final Context context;
@Nullable final CameraManager cameraManager;
private final boolean disableEIS, zoomOut;

public ExtCamera2Enumerator(Context context, boolean disableEIS, boolean zoomOut) {
super(context);
this.context = context;
this.disableEIS = disableEIS;
this.zoomOut = zoomOut;
this.cameraManager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE);
}

@Override
public CameraVideoCapturer createCapturer(String deviceName,
CameraVideoCapturer.CameraEventsHandler eventsHandler) {
return new ExtCamera2Capturer(context, deviceName, eventsHandler, disableEIS, zoomOut);
}
}
Loading

0 comments on commit 86a0d5d

Please sign in to comment.