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 Aug 12, 2022
1 parent 6cd5f1f commit 5e39e04
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 @@ -115,6 +115,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 @@ -245,6 +246,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 isPTTActive = false;
private PulseAnimation pulseAnimation;
Expand Down Expand Up @@ -420,7 +424,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 @@ -858,7 +864,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 @@ -1760,7 +1765,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 5e39e04

Please sign in to comment.