Simplify & fix i/o video params

This commit is contained in:
Sylvain Berfini 2012-09-21 14:53:46 +02:00
parent 7343d5810d
commit 3cbbd36f2a
7 changed files with 97 additions and 21 deletions

View file

@ -98,11 +98,11 @@
<string name="pref_video_settings_title">Paramètres vidéo</string> <string name="pref_video_settings_title">Paramètres vidéo</string>
<string name="pref_video_automatically_share_my_video_title">Partager ma vidéo</string> <string name="pref_video_automatically_share_my_video_title">Partager ma vidéo</string>
<string name="pref_video_automatically_accept_video_title">Accepter vidéo entrante</string> <string name="pref_video_automatically_accept_video_title">Accepter appels vidéo</string>
<string name="pref_video_automatically_share_my_video">Envoyer ma vidéo automatiquement</string> <string name="pref_video_automatically_share_my_video">Envoyer ma vidéo automatiquement</string>
<string name="pref_video_automatically_accept_video">Accepter automatiquement la vidéo</string> <string name="pref_video_automatically_accept_video">Toujours accepter les demandes d\'appels vidéo</string>
<string name="pref_video_initiate_call_with_video_title">Initier les appels en vidéo</string> <string name="pref_video_initiate_call_with_video_title">Initier les appels en vidéo</string>
<string name="pref_video_initiate_call_with_video"></string> <string name="pref_video_initiate_call_with_video">Toujours envoyer des demandes d\'appels vidéo</string>
<string name="pref_video_enable_title">Activer la vidéo</string> <string name="pref_video_enable_title">Activer la vidéo</string>
<string name="pref_animation_enable_title">Activer les animations</string> <string name="pref_animation_enable_title">Activer les animations</string>
<string name="pref_escape_plus">Remplacer + par 00</string> <string name="pref_escape_plus">Remplacer + par 00</string>

View file

@ -130,11 +130,11 @@
<string name="menu_videocall_terminate_call_title">Terminate call</string> <string name="menu_videocall_terminate_call_title">Terminate call</string>
<string name="pref_video_settings_title">Video settings</string> <string name="pref_video_settings_title">Video settings</string>
<string name="pref_video_automatically_share_my_video_title">Share my camera</string> <string name="pref_video_automatically_share_my_video_title">Share my camera</string>
<string name="pref_video_automatically_accept_video_title">Accept incoming camera</string> <string name="pref_video_automatically_accept_video_title">Accept incoming video requests</string>
<string name="pref_video_automatically_share_my_video">Automatically send my camera</string> <string name="pref_video_automatically_share_my_video">Automatically send my camera</string>
<string name="pref_video_automatically_accept_video">Automatically accept correspondent\'s camera</string> <string name="pref_video_automatically_accept_video">Always accept video requests</string>
<string name="pref_video_initiate_call_with_video_title">Initiate video calls</string> <string name="pref_video_initiate_call_with_video_title">Initiate video calls</string>
<string name="pref_video_initiate_call_with_video"></string> <string name="pref_video_initiate_call_with_video">Always send video requests</string>
<string name="pref_video_enable_title">Enable Video</string> <string name="pref_video_enable_title">Enable Video</string>
<string name="pref_animation_enable_title">Enable Animations</string> <string name="pref_animation_enable_title">Enable Animations</string>
<string name="pref_escape_plus">Replace + by 00</string> <string name="pref_escape_plus">Replace + by 00</string>

View file

@ -153,7 +153,8 @@
android:key="@string/pref_video_use_front_camera_key" android:key="@string/pref_video_use_front_camera_key"
android:defaultValue="true" android:defaultValue="true"
android:title="@string/pref_video_use_front_camera_title" android:title="@string/pref_video_use_front_camera_title"
android:dependency="@string/pref_video_enable_key"/> android:dependency="@string/pref_video_enable_key"
android:layout="@layout/hidden"/>
<CheckBoxPreference <CheckBoxPreference
android:key="@string/pref_video_initiate_call_with_video_key" android:key="@string/pref_video_initiate_call_with_video_key"
@ -167,7 +168,8 @@
android:title="@string/pref_video_automatically_share_my_video_title" android:title="@string/pref_video_automatically_share_my_video_title"
android:defaultValue="true" android:defaultValue="true"
android:summary="@string/pref_video_automatically_share_my_video" android:summary="@string/pref_video_automatically_share_my_video"
android:dependency="@string/pref_video_enable_key"/> android:dependency="@string/pref_video_enable_key"
android:layout="@layout/hidden"/>
<CheckBoxPreference <CheckBoxPreference
android:key="@string/pref_video_automatically_accept_video_key" android:key="@string/pref_video_automatically_accept_video_key"

View file

@ -148,7 +148,12 @@ public class DialerFragment extends Fragment {
public void resetLayout(boolean callTransfer) { public void resetLayout(boolean callTransfer) {
isCallTransferOngoing = callTransfer; isCallTransferOngoing = callTransfer;
if (LinphoneManager.getLc() != null && LinphoneManager.getLc().getCallsNb() > 0) { LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
if (lc == null) {
return;
}
if (lc.getCallsNb() > 0) {
if (isCallTransferOngoing) { if (isCallTransferOngoing) {
mCall.setImageResource(R.drawable.transfer_call); mCall.setImageResource(R.drawable.transfer_call);
mCall.setExternalClickListener(transferListener); mCall.setExternalClickListener(transferListener);

View file

@ -26,6 +26,7 @@ import org.linphone.core.LinphoneCall;
import org.linphone.core.LinphoneCall.State; import org.linphone.core.LinphoneCall.State;
import org.linphone.core.LinphoneCallParams; import org.linphone.core.LinphoneCallParams;
import org.linphone.core.LinphoneCore; import org.linphone.core.LinphoneCore;
import org.linphone.core.LinphoneCoreException;
import org.linphone.mediastream.video.capture.hwconf.AndroidCameraConfiguration; import org.linphone.mediastream.video.capture.hwconf.AndroidCameraConfiguration;
import org.linphone.ui.Numpad; import org.linphone.ui.Numpad;
@ -34,6 +35,7 @@ import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.os.Bundle; import android.os.Bundle;
import android.os.CountDownTimer;
import android.os.Handler; import android.os.Handler;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
@ -60,6 +62,7 @@ public class InCallActivity extends FragmentActivity implements
LinphoneOnCallEncryptionChangedListener, LinphoneOnCallEncryptionChangedListener,
OnClickListener { OnClickListener {
private final static int SECONDS_BEFORE_HIDING_CONTROLS = 3000; private final static int SECONDS_BEFORE_HIDING_CONTROLS = 3000;
private static InCallActivity instance; private static InCallActivity instance;
private Handler mHandler = new Handler(); private Handler mHandler = new Handler();
@ -75,6 +78,7 @@ public class InCallActivity extends FragmentActivity implements
private Numpad numpad; private Numpad numpad;
private int cameraNumber; private int cameraNumber;
private Animation slideOutLeftToRight, slideInRightToLeft, slideInBottomToTop, slideInTopToBottom, slideOutBottomToTop, slideOutTopToBottom; private Animation slideOutLeftToRight, slideInRightToLeft, slideInBottomToTop, slideInTopToBottom, slideOutBottomToTop, slideOutTopToBottom;
private CountDownTimer timer;
public static InCallActivity instance() { public static InCallActivity instance() {
return instance; return instance;
@ -322,15 +326,14 @@ public class InCallActivity extends FragmentActivity implements
if (!displayVideo) { if (!displayVideo) {
LinphoneCallParams params = call.getCurrentParamsCopy(); LinphoneCallParams params = call.getCurrentParamsCopy();
params.setVideoEnabled(false); params.setVideoEnabled(false);
LinphoneManager.getLc().updateCall(call, params); LinphoneManager.getLc().updateCall(call, params);
replaceFragmentVideoByAudio(); replaceFragmentVideoByAudio();
video.setBackgroundResource(R.drawable.video_on); video.setBackgroundResource(R.drawable.video_on);
setCallControlsVisibleAndRemoveCallbacks(); setCallControlsVisibleAndRemoveCallbacks();
} else { } else {
LinphoneManager.getInstance().addVideo(); LinphoneManager.getInstance().addVideo();
isSpeakerEnabled = true; isSpeakerEnabled = true;
LinphoneManager.getInstance().routeAudioToSpeaker(); LinphoneManager.getInstance().routeAudioToSpeaker();
speaker.setBackgroundResource(R.drawable.speaker_on); speaker.setBackgroundResource(R.drawable.speaker_on);
@ -808,6 +811,39 @@ public class InCallActivity extends FragmentActivity implements
setResult(Activity.RESULT_FIRST_USER, intent); setResult(Activity.RESULT_FIRST_USER, intent);
finish(); finish();
} }
private void acceptCallUpdate(boolean accept) {
if (timer != null) {
timer.cancel();
}
LinphoneCall call = LinphoneManager.getLc().getCurrentCall();
if (call == null) {
return;
}
LinphoneCallParams params = call.getCurrentParamsCopy();
if (accept) {
params.setVideoEnabled(true);
LinphoneManager.getLc().enableVideo(true, true);
}
try {
LinphoneManager.getLc().acceptCallUpdate(call, params);
} catch (LinphoneCoreException e) {
e.printStackTrace();
}
if (accept) {
isSpeakerEnabled = true;
LinphoneManager.getInstance().routeAudioToSpeaker();
speaker.setBackgroundResource(R.drawable.speaker_on);
replaceFragmentAudioByVideo();
video.setBackgroundResource(R.drawable.video_off);
displayVideoCallControlsIfHidden();
}
}
@Override @Override
public void onCallStateChanged(final LinphoneCall call, State state, String message) { public void onCallStateChanged(final LinphoneCall call, State state, String message) {
@ -816,7 +852,7 @@ public class InCallActivity extends FragmentActivity implements
return; return;
} }
if (state == State.StreamsRunning) { if (state == State.StreamsRunning) {
boolean isVideoEnabledInCall = call.getCurrentParamsCopy().getVideoEnabled(); boolean isVideoEnabledInCall = call.getCurrentParamsCopy().getVideoEnabled();
if (isVideoEnabledInCall != isVideoEnabled) { if (isVideoEnabledInCall != isVideoEnabled) {
isVideoEnabled = isVideoEnabledInCall; isVideoEnabled = isVideoEnabledInCall;
@ -846,6 +882,35 @@ public class InCallActivity extends FragmentActivity implements
}); });
} }
if (state == State.CallUpdatedByRemote) {
// If the correspondent proposes video while audio call
boolean remoteVideo = call.getRemoteParams().getVideoEnabled();
boolean localVideo = call.getCurrentParamsCopy().getVideoEnabled();
boolean autoAcceptCameraPolicy = LinphoneManager.getInstance().isAutoAcceptCamera();
if (remoteVideo && !localVideo && !autoAcceptCameraPolicy && !LinphoneManager.getLc().isInConference()) {
mHandler.post(new Runnable() {
public void run() {
//TODO: ask the user it's choice
// We let 30 secs for the user to decide
timer = new CountDownTimer(30000, 1000) {
public void onTick(long millisUntilFinished) { }
public void onFinish() {
acceptCallUpdate(false);
}
}.start();
}
});
} else if (remoteVideo && !LinphoneManager.getLc().isInConference() && autoAcceptCameraPolicy) {
mHandler.post(new Runnable() {
@Override
public void run() {
acceptCallUpdate(true);
}
});
}
}
transfer.setEnabled(LinphoneManager.getLc().getCurrentCall() != null); transfer.setEnabled(LinphoneManager.getLc().getCurrentCall() != null);
} }

View file

@ -24,6 +24,7 @@ import org.linphone.LinphoneSimpleListener.LinphoneOnCallStateChangedListener;
import org.linphone.core.LinphoneAddress; import org.linphone.core.LinphoneAddress;
import org.linphone.core.LinphoneCall; import org.linphone.core.LinphoneCall;
import org.linphone.core.LinphoneCall.State; import org.linphone.core.LinphoneCall.State;
import org.linphone.core.LinphoneCallParams;
import org.linphone.core.Log; import org.linphone.core.Log;
import org.linphone.ui.AvatarWithShadow; import org.linphone.ui.AvatarWithShadow;
import org.linphone.ui.LinphoneSliders; import org.linphone.ui.LinphoneSliders;
@ -128,7 +129,12 @@ public class IncomingCallActivity extends Activity implements LinphoneOnCallStat
LinphoneManager.getLc().terminateCall(mCall); LinphoneManager.getLc().terminateCall(mCall);
} }
private void answer() { private void answer() {
if (!LinphoneManager.getInstance().acceptCall(mCall)) { LinphoneCallParams params = mCall.getCurrentParamsCopy();
if (mCall.getRemoteParams().getVideoEnabled() && LinphoneManager.getInstance().isAutoAcceptCamera()) {
params.setVideoEnabled(true);
}
if (!LinphoneManager.getInstance().acceptCallWithParams(mCall, params)) {
// the above method takes care of Samsung Galaxy S // the above method takes care of Samsung Galaxy S
Toast.makeText(this, R.string.couldnt_accept_call, Toast.LENGTH_LONG).show(); Toast.makeText(this, R.string.couldnt_accept_call, Toast.LENGTH_LONG).show();
} else { } else {
@ -136,7 +142,7 @@ public class IncomingCallActivity extends Activity implements LinphoneOnCallStat
return; return;
} }
if (mCall.getCurrentParamsCopy().getVideoEnabled()) { if (mCall.getRemoteParams().getVideoEnabled() && LinphoneManager.getInstance().isAutoAcceptCamera()) {
LinphoneActivity.instance().startVideoActivity(mCall); LinphoneActivity.instance().startVideoActivity(mCall);
} }
else { else {

View file

@ -54,6 +54,7 @@ import org.linphone.core.LinphoneAddress;
import org.linphone.core.LinphoneAuthInfo; import org.linphone.core.LinphoneAuthInfo;
import org.linphone.core.LinphoneCall; import org.linphone.core.LinphoneCall;
import org.linphone.core.LinphoneCall.State; import org.linphone.core.LinphoneCall.State;
import org.linphone.core.LinphoneCallParams;
import org.linphone.core.LinphoneChatMessage; import org.linphone.core.LinphoneChatMessage;
import org.linphone.core.LinphoneChatRoom; import org.linphone.core.LinphoneChatRoom;
import org.linphone.core.LinphoneCore; import org.linphone.core.LinphoneCore;
@ -482,7 +483,6 @@ public final class LinphoneManager implements LinphoneCoreListener {
mLc.setRing(null); mLc.setRing(null);
mLc.setRootCA(mLinphoneRootCaFile); mLc.setRootCA(mLinphoneRootCaFile);
mLc.setPlayFile(mPauseSoundFile); mLc.setPlayFile(mPauseSoundFile);
mLc.setVideoPolicy(isAutoInitiateVideoCalls(), isAutoAcceptCamera());
int availableCores = Runtime.getRuntime().availableProcessors(); int availableCores = Runtime.getRuntime().availableProcessors();
Log.w("MediaStreamer : " + availableCores + " cores detected and configured"); Log.w("MediaStreamer : " + availableCores + " cores detected and configured");
@ -655,6 +655,8 @@ public final class LinphoneManager implements LinphoneCoreListener {
setSignalingTransportsFromConfiguration(initialTransports); setSignalingTransportsFromConfiguration(initialTransports);
initMediaEncryption(); initMediaEncryption();
mLc.setVideoPolicy(isAutoInitiateVideoCalls(), isAutoAcceptCamera());
try { try {
// Configure audio codecs // Configure audio codecs
@ -1109,10 +1111,6 @@ public final class LinphoneManager implements LinphoneCoreListener {
return getPrefBoolean(R.string.pref_video_enable_key, false); return getPrefBoolean(R.string.pref_video_enable_key, false);
} }
public boolean shareMyCamera() {
return isVideoEnabled() && getPrefBoolean(R.string.pref_video_automatically_share_my_video_key, false);
}
public boolean isAutoAcceptCamera() { public boolean isAutoAcceptCamera() {
return isVideoEnabled() && getPrefBoolean(R.string.pref_video_automatically_accept_video_key, false); return isVideoEnabled() && getPrefBoolean(R.string.pref_video_automatically_accept_video_key, false);
} }
@ -1184,12 +1182,12 @@ public final class LinphoneManager implements LinphoneCoreListener {
return false; return false;
} }
public boolean acceptCall(LinphoneCall call) { public boolean acceptCallWithParams(LinphoneCall call, LinphoneCallParams params) {
if (Hacks.needGalaxySAudioHack() || sLPref.useGalaxySHack()) if (Hacks.needGalaxySAudioHack() || sLPref.useGalaxySHack())
setAudioModeIncallForGalaxyS(); setAudioModeIncallForGalaxyS();
try { try {
mLc.acceptCall(call); mLc.acceptCallWithParams(call, params);
return true; return true;
} catch (LinphoneCoreException e) { } catch (LinphoneCoreException e) {
Log.i(e, "Accept call failed"); Log.i(e, "Accept call failed");