Added setting to choose which camera to use + improved reload devices to not use legacy capture filter code directly
This commit is contained in:
parent
d753ca238b
commit
a0c3fe58cb
7 changed files with 86 additions and 31 deletions
|
@ -539,11 +539,37 @@ public class LinphoneManager implements SensorEventListener {
|
|||
PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK,
|
||||
mContext.getPackageName() + ";manager_proximity_sensor");
|
||||
|
||||
resetCameraFromPreferences();
|
||||
|
||||
mAccountCreator = mCore.createAccountCreator(LinphonePreferences.instance().getXmlrpcUrl());
|
||||
mAccountCreator.setListener(mAccountCreatorListener);
|
||||
mCallGsmON = false;
|
||||
}
|
||||
|
||||
public void resetCameraFromPreferences() {
|
||||
Core core = getCore();
|
||||
if (core == null) return;
|
||||
|
||||
boolean useFrontCam = LinphonePreferences.instance().useFrontCam();
|
||||
String firstDevice = null;
|
||||
for (String camera : core.getVideoDevicesList()) {
|
||||
if (firstDevice == null) {
|
||||
firstDevice = camera;
|
||||
}
|
||||
|
||||
if (useFrontCam) {
|
||||
if (camera.contains("Front")) {
|
||||
Log.i("[Manager] Found front facing camera: " + camera);
|
||||
core.setVideoDevice(camera);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Log.i("[Manager] Using first camera available: " + firstDevice);
|
||||
core.setVideoDevice(firstDevice);
|
||||
}
|
||||
|
||||
/* Account linking */
|
||||
|
||||
public void isAccountWithAlias() {
|
||||
|
|
|
@ -30,7 +30,7 @@ import org.linphone.LinphoneManager;
|
|||
import org.linphone.R;
|
||||
import org.linphone.core.Core;
|
||||
import org.linphone.core.CoreListenerStub;
|
||||
import org.linphone.mediastream.video.capture.hwconf.AndroidCameraConfiguration;
|
||||
import org.linphone.core.tools.Log;
|
||||
|
||||
public class QrCodeConfigurationAssistantActivity extends AssistantActivity {
|
||||
private TextureView mQrcodeView;
|
||||
|
@ -105,19 +105,20 @@ public class QrCodeConfigurationAssistantActivity extends AssistantActivity {
|
|||
Core core = LinphoneManager.getCore();
|
||||
if (core == null) return;
|
||||
|
||||
int camId = 0;
|
||||
AndroidCameraConfiguration.AndroidCamera[] cameras =
|
||||
AndroidCameraConfiguration.retrieveCameras();
|
||||
for (AndroidCameraConfiguration.AndroidCamera androidCamera : cameras) {
|
||||
if (!androidCamera.frontFacing) camId = androidCamera.id;
|
||||
}
|
||||
String[] devices = core.getVideoDevicesList();
|
||||
String newDevice = devices[camId];
|
||||
String firstDevice = null;
|
||||
for (String camera : core.getVideoDevicesList()) {
|
||||
if (firstDevice == null) {
|
||||
firstDevice = camera;
|
||||
}
|
||||
|
||||
String currentDevice = core.getVideoDevice();
|
||||
if (currentDevice != null && currentDevice.equals(newDevice)) {
|
||||
return;
|
||||
if (camera.contains("Back")) {
|
||||
Log.i("[QR Code] Found back facing camera: " + camera);
|
||||
core.setVideoDevice(camera);
|
||||
return;
|
||||
}
|
||||
}
|
||||
core.setVideoDevice(newDevice);
|
||||
|
||||
Log.i("[QR Code] Using first camera available: " + firstDevice);
|
||||
core.setVideoDevice(firstDevice);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -329,6 +329,14 @@ public class LinphonePreferences {
|
|||
getConfig().setBool("app", "front_camera_default", frontcam);
|
||||
}
|
||||
|
||||
public String getCameraDevice() {
|
||||
return getLc().getVideoDevice();
|
||||
}
|
||||
|
||||
public void setCameraDevice(String device) {
|
||||
getLc().setVideoDevice(device);
|
||||
}
|
||||
|
||||
public boolean isVideoEnabled() {
|
||||
if (getLc() == null) return false;
|
||||
return getLc().videoSupported() && getLc().videoEnabled();
|
||||
|
|
|
@ -52,6 +52,7 @@ public class VideoSettingsFragment extends SettingsFragment {
|
|||
private TextSetting mBandwidth;
|
||||
private LinearLayout mVideoCodecs;
|
||||
private TextView mVideoCodecsHeader;
|
||||
private ListSetting mCameraDevices;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
|
@ -82,6 +83,9 @@ public class VideoSettingsFragment extends SettingsFragment {
|
|||
|
||||
mAutoAccept = mRootView.findViewById(R.id.pref_video_automatically_accept_video);
|
||||
|
||||
mCameraDevices = mRootView.findViewById(R.id.pref_video_camera_device);
|
||||
initCameraDevicesList();
|
||||
|
||||
mOverlay = mRootView.findViewById(R.id.pref_overlay);
|
||||
|
||||
mPreset = mRootView.findViewById(R.id.pref_video_preset);
|
||||
|
@ -148,6 +152,14 @@ public class VideoSettingsFragment extends SettingsFragment {
|
|||
}
|
||||
});
|
||||
|
||||
mCameraDevices.setListener(
|
||||
new SettingListenerBase() {
|
||||
@Override
|
||||
public void onListValueChanged(int position, String newLabel, String newValue) {
|
||||
mPrefs.setCameraDevice(newValue);
|
||||
}
|
||||
});
|
||||
|
||||
mOverlay.setListener(
|
||||
new SettingListenerBase() {
|
||||
@Override
|
||||
|
@ -213,6 +225,8 @@ public class VideoSettingsFragment extends SettingsFragment {
|
|||
|
||||
mAutoAccept.setChecked(mPrefs.shouldAutomaticallyAcceptVideoRequests());
|
||||
|
||||
mCameraDevices.setValue(mPrefs.getCameraDevice());
|
||||
|
||||
mOverlay.setChecked(mPrefs.isOverlayEnabled());
|
||||
if (Version.sdkAboveOrEqual(Version.API26_O_80)
|
||||
&& getResources().getBoolean(R.bool.allow_pip_while_video_call)) {
|
||||
|
@ -306,4 +320,19 @@ public class VideoSettingsFragment extends SettingsFragment {
|
|||
mVideoCodecs.setVisibility(show ? View.VISIBLE : View.GONE);
|
||||
mVideoCodecsHeader.setVisibility(show ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
|
||||
private void initCameraDevicesList() {
|
||||
List<String> entries = new ArrayList<>();
|
||||
List<String> values = new ArrayList<>();
|
||||
|
||||
Core core = LinphoneManager.getCore();
|
||||
if (core != null) {
|
||||
for (String camera : core.getVideoDevicesList()) {
|
||||
entries.add(camera);
|
||||
values.add(camera);
|
||||
}
|
||||
}
|
||||
|
||||
mCameraDevices.setItems(entries, values);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,7 +53,6 @@ import org.linphone.core.Factory;
|
|||
import org.linphone.core.LogCollectionState;
|
||||
import org.linphone.core.ProxyConfig;
|
||||
import org.linphone.core.tools.Log;
|
||||
import org.linphone.mediastream.video.capture.hwconf.AndroidCameraConfiguration;
|
||||
import org.linphone.settings.LinphonePreferences;
|
||||
|
||||
/** Helpers. */
|
||||
|
@ -227,25 +226,10 @@ public final class LinphoneUtils {
|
|||
Core core = LinphoneManager.getCore();
|
||||
if (core == null) return;
|
||||
|
||||
Log.i("[Utils] Reloading camera");
|
||||
Log.i("[Utils] Reloading camera devices");
|
||||
core.reloadVideoDevices();
|
||||
|
||||
boolean useFrontCam = LinphonePreferences.instance().useFrontCam();
|
||||
int camId = 0;
|
||||
AndroidCameraConfiguration.AndroidCamera[] cameras =
|
||||
AndroidCameraConfiguration.retrieveCameras();
|
||||
for (AndroidCameraConfiguration.AndroidCamera androidCamera : cameras) {
|
||||
if (androidCamera.frontFacing == useFrontCam) {
|
||||
camId = androidCamera.id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
String[] devices = core.getVideoDevicesList();
|
||||
if (camId >= devices.length) {
|
||||
camId = 0;
|
||||
}
|
||||
String newDevice = devices[camId];
|
||||
core.setVideoDevice(newDevice);
|
||||
LinphoneManager.getInstance().resetCameraFromPreferences();
|
||||
}
|
||||
|
||||
public static String getDisplayableUsernameFromAddress(String sipAddress) {
|
||||
|
|
|
@ -37,6 +37,12 @@
|
|||
linphone:subtitle="@string/pref_video_automatically_accept_video"
|
||||
linphone:title="@string/pref_video_automatically_accept_video_title" />
|
||||
|
||||
<org.linphone.settings.widget.ListSetting
|
||||
android:id="@+id/pref_video_camera_device"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
linphone:title="@string/pref_video_camera_device" />
|
||||
|
||||
<org.linphone.settings.widget.SwitchSetting
|
||||
android:id="@+id/pref_overlay"
|
||||
android:layout_width="match_parent"
|
||||
|
|
|
@ -421,6 +421,7 @@
|
|||
|
||||
<!-- Video settings -->
|
||||
<string name="pref_video_title">Video</string>
|
||||
<string name="pref_video_camera_device">Camera</string>
|
||||
<string name="pref_overlay">Video overlay</string>
|
||||
<string name="pref_overlay_summary">Display call video in overlay when outside the application</string>
|
||||
<string name="pref_video_use_front_camera_title">Use front camera</string>
|
||||
|
|
Loading…
Reference in a new issue