Improve audio hack for Galaxy S.

This commit is contained in:
Ghislain MARY 2012-12-07 14:25:11 +01:00
parent 062eda75e7
commit a20b80bfc2
4 changed files with 18 additions and 90 deletions

View file

@ -31,7 +31,6 @@ import org.linphone.core.LinphoneCoreException;
import org.linphone.core.LinphoneCoreFactory; import org.linphone.core.LinphoneCoreFactory;
import org.linphone.core.Log; import org.linphone.core.Log;
import org.linphone.mediastream.video.capture.hwconf.AndroidCameraConfiguration; import org.linphone.mediastream.video.capture.hwconf.AndroidCameraConfiguration;
import org.linphone.mediastream.video.capture.hwconf.Hacks;
import org.linphone.ui.AvatarWithShadow; import org.linphone.ui.AvatarWithShadow;
import org.linphone.ui.Numpad; import org.linphone.ui.Numpad;
@ -951,17 +950,10 @@ public class InCallActivity extends FragmentActivity implements
if (isVideoEnabledInCall != isVideoEnabled) { if (isVideoEnabledInCall != isVideoEnabled) {
isVideoEnabled = isVideoEnabledInCall; isVideoEnabled = isVideoEnabledInCall;
switchVideo(isVideoEnabled); switchVideo(isVideoEnabled);
} else {
//Hack to fix Galaxy S issue
if (Hacks.needGalaxySAudioHack()) {
if (isSpeakerEnabled) {
LinphoneManager.getInstance().routeAudioToSpeaker();
} else {
LinphoneManager.getInstance().routeAudioToReceiver();
} }
// The following should not be needed except some devices need it (e.g. Galaxy S).
LinphoneManager.getLc().enableSpeaker(isSpeakerEnabled); LinphoneManager.getLc().enableSpeaker(isSpeakerEnabled);
}
}
isMicMuted = LinphoneManager.getLc().isMicMuted(); isMicMuted = LinphoneManager.getLc().isMicMuted();
enableAndRefreshInCallActions(); enableAndRefreshInCallActions();

View file

@ -144,6 +144,10 @@ public class IncomingCallActivity extends Activity implements LinphoneOnCallStat
if (call == mCall && State.CallEnd == state) { if (call == mCall && State.CallEnd == state) {
finish(); finish();
} }
if (state == State.StreamsRunning) {
// The following should not be needed except some devices need it (e.g. Galaxy S).
LinphoneManager.getLc().enableSpeaker(LinphoneManager.getLc().isSpeakerEnabled());
}
} }
private void decline() { private void decline() {

View file

@ -18,11 +18,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/ */
package org.linphone; package org.linphone;
import static android.media.AudioManager.MODE_IN_CALL;
import static android.media.AudioManager.MODE_NORMAL; import static android.media.AudioManager.MODE_NORMAL;
import static android.media.AudioManager.MODE_RINGTONE;
import static android.media.AudioManager.ROUTE_EARPIECE;
import static android.media.AudioManager.ROUTE_SPEAKER;
import static android.media.AudioManager.STREAM_RING; import static android.media.AudioManager.STREAM_RING;
import static android.media.AudioManager.STREAM_VOICE_CALL; import static android.media.AudioManager.STREAM_VOICE_CALL;
import static org.linphone.R.string.pref_codec_amr_key; import static org.linphone.R.string.pref_codec_amr_key;
@ -199,53 +195,12 @@ public final class LinphoneManager implements LinphoneCoreListener {
private BroadcastReceiver mKeepAliveReceiver = new KeepAliveReceiver(); private BroadcastReceiver mKeepAliveReceiver = new KeepAliveReceiver();
private native void hackSpeakerState(boolean speakerOn); private void routeAudioToSpeakerHelper(boolean speakerOn) {
private static void sRouteAudioToSpeakerHelperHelper(boolean speakerOn) { mLc.enableSpeaker(speakerOn);
getInstance().routeAudioToSpeakerHelperHelper(speakerOn);
}
@SuppressWarnings("deprecation")
private void routeAudioToSpeakerHelperHelper(boolean speakerOn) {
boolean different = isSpeakerOn() ^ speakerOn;
if (!different && !Hacks.needGalaxySAudioHack()) {
Log.d("Skipping change audio route by the same route ",
speakerOn ? "speaker" : "earpiece");
return;
}
if (Hacks.needGalaxySAudioHack() || sLPref.useGalaxySHack())
setAudioModeIncallForGalaxyS();
if (sLPref.useSpecificAudioModeHack() != -1)
mAudioManager.setMode(sLPref.useSpecificAudioModeHack());
if (Hacks.needRoutingAPI() || sLPref.useAudioRoutingAPIHack()) {
mAudioManager.setRouting(
MODE_NORMAL,
speakerOn? ROUTE_SPEAKER : ROUTE_EARPIECE,
AudioManager.ROUTE_ALL);
} else {
mAudioManager.setSpeakerphoneOn(speakerOn);
}
for (LinphoneOnAudioChangedListener listener : getSimpleListeners(LinphoneOnAudioChangedListener.class)) { for (LinphoneOnAudioChangedListener listener : getSimpleListeners(LinphoneOnAudioChangedListener.class)) {
listener.onAudioStateChanged(speakerOn ? AudioState.SPEAKER : AudioState.EARPIECE); listener.onAudioStateChanged(speakerOn ? AudioState.SPEAKER : AudioState.EARPIECE);
} }
} }
public synchronized void routeAudioToSpeakerHelper(boolean speakerOn) {
final LinphoneCall call = mLc.getCurrentCall();
if (call != null && call.getState() == State.StreamsRunning && Hacks.needPausingCallForSpeakers()) {
Log.d("Hack to have speaker=",speakerOn," while on call");
hackSpeakerState(speakerOn);
} else {
routeAudioToSpeakerHelperHelper(speakerOn);
}
}
/**
*
* @param isUserRequest true if the setting is permanent, otherwise it can be lost
* eg: video activity imply speaker on, which is not a request from the user.
* when the activity stops, the sound is routed to the previously user requested route.
*/
public void routeAudioToSpeaker() { public void routeAudioToSpeaker() {
routeAudioToSpeakerHelper(true); routeAudioToSpeakerHelper(true);
} }
@ -274,7 +229,7 @@ public final class LinphoneManager implements LinphoneCoreListener {
throw new RuntimeException("Linphone Manager is already initialized"); throw new RuntimeException("Linphone Manager is already initialized");
instance = new LinphoneManager(c, listener); instance = new LinphoneManager(c, listener);
instance.startLibLinphone(); instance.startLibLinphone(c);
TelephonyManager tm = (TelephonyManager) c.getSystemService(Context.TELEPHONY_SERVICE); TelephonyManager tm = (TelephonyManager) c.getSystemService(Context.TELEPHONY_SERVICE);
boolean gsmIdle = tm.getCallState() == TelephonyManager.CALL_STATE_IDLE; boolean gsmIdle = tm.getCallState() == TelephonyManager.CALL_STATE_IDLE;
setGsmIdle(gsmIdle); setGsmIdle(gsmIdle);
@ -299,16 +254,6 @@ public final class LinphoneManager implements LinphoneCoreListener {
return getInstance().mLc; return getInstance().mLc;
} }
@SuppressWarnings("deprecation")
public boolean isSpeakerOn() {
if (Hacks.needRoutingAPI() || sLPref.useAudioRoutingAPIHack()) {
return mAudioManager.getRouting(MODE_NORMAL) == ROUTE_SPEAKER;
} else {
return mAudioManager.isSpeakerphoneOn();
}
}
public void newOutgoingCall(AddressType address) { public void newOutgoingCall(AddressType address) {
String to = address.getText().toString(); String to = address.getText().toString();
@ -457,7 +402,7 @@ public final class LinphoneManager implements LinphoneCoreListener {
} }
} }
private synchronized void startLibLinphone() { private synchronized void startLibLinphone(Context c) {
try { try {
copyAssetsFromPackage(); copyAssetsFromPackage();
//traces alway start with traces enable to not missed first initialization //traces alway start with traces enable to not missed first initialization
@ -466,6 +411,7 @@ public final class LinphoneManager implements LinphoneCoreListener {
mLc = LinphoneCoreFactory.instance().createLinphoneCore( mLc = LinphoneCoreFactory.instance().createLinphoneCore(
this, mLinphoneConfigFile, mLinphoneInitialConfigFile, null); this, mLinphoneConfigFile, mLinphoneInitialConfigFile, null);
mLc.setContext(c);
mLc.enableIpv6(getPrefBoolean(R.string.pref_ipv6_key, false)); mLc.enableIpv6(getPrefBoolean(R.string.pref_ipv6_key, false));
mLc.setZrtpSecretsCache(basePath+"/zrtp_secrets"); mLc.setZrtpSecretsCache(basePath+"/zrtp_secrets");
@ -1150,9 +1096,7 @@ public final class LinphoneManager implements LinphoneCoreListener {
return; return;
} }
if (Hacks.needGalaxySAudioHack()) { mLc.startRinging();
mAudioManager.setMode(MODE_RINGTONE);
}
try { try {
if ((mAudioManager.getRingerMode() == AudioManager.RINGER_MODE_VIBRATE || mAudioManager.getRingerMode() == AudioManager.RINGER_MODE_NORMAL) && mVibrator !=null) { if ((mAudioManager.getRingerMode() == AudioManager.RINGER_MODE_VIBRATE || mAudioManager.getRingerMode() == AudioManager.RINGER_MODE_NORMAL) && mVibrator !=null) {
@ -1224,12 +1168,6 @@ public final class LinphoneManager implements LinphoneCoreListener {
return isVideoEnabled() && getPrefBoolean(R.string.pref_video_initiate_call_with_video_key, false); return isVideoEnabled() && getPrefBoolean(R.string.pref_video_initiate_call_with_video_key, false);
} }
public void setAudioModeIncallForGalaxyS() {
mAudioManager.setMode(MODE_IN_CALL);
/* The microphone gain is way too high on the Galaxy S so correct it here. */
LinphoneManager.getLc().setMicrophoneGain(-9.0f);
}
// Called on first launch only // Called on first launch only
public void initializePayloads() { public void initializePayloads() {
Log.i("Initializing supported payloads"); Log.i("Initializing supported payloads");
@ -1279,9 +1217,6 @@ public final class LinphoneManager implements LinphoneCoreListener {
} }
public boolean acceptCallIfIncomingPending() throws LinphoneCoreException { public boolean acceptCallIfIncomingPending() throws LinphoneCoreException {
if (Hacks.needGalaxySAudioHack() || sLPref.useGalaxySHack())
setAudioModeIncallForGalaxyS();
if (mLc.isInComingInvitePending()) { if (mLc.isInComingInvitePending()) {
mLc.acceptCall(mLc.getCurrentCall()); mLc.acceptCall(mLc.getCurrentCall());
return true; return true;
@ -1290,9 +1225,6 @@ public final class LinphoneManager implements LinphoneCoreListener {
} }
public boolean acceptCallWithParams(LinphoneCall call, LinphoneCallParams params) { public boolean acceptCallWithParams(LinphoneCall call, LinphoneCallParams params) {
if (Hacks.needGalaxySAudioHack() || sLPref.useGalaxySHack())
setAudioModeIncallForGalaxyS();
try { try {
mLc.acceptCallWithParams(call, params); mLc.acceptCallWithParams(call, params);
return true; return true;

@ -1 +1 @@
Subproject commit ba478b89e88f5b60f6f3ee5bfe9c636cd8648f3e Subproject commit 4821958ecddd49fb8170e7b6ccc7c17d454f06e2