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.Log;
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.Numpad;
@ -935,7 +934,7 @@ public class InCallActivity extends FragmentActivity implements
}
@Override
public void onCallStateChanged(final LinphoneCall call, State state, String message) {
public void onCallStateChanged(final LinphoneCall call, State state, String message) {
if (LinphoneManager.getLc().getCallsNb() == 0) {
finish();
return;
@ -951,18 +950,11 @@ public class InCallActivity extends FragmentActivity implements
if (isVideoEnabledInCall != isVideoEnabled) {
isVideoEnabled = isVideoEnabledInCall;
switchVideo(isVideoEnabled);
} else {
//Hack to fix Galaxy S issue
if (Hacks.needGalaxySAudioHack()) {
if (isSpeakerEnabled) {
LinphoneManager.getInstance().routeAudioToSpeaker();
} else {
LinphoneManager.getInstance().routeAudioToReceiver();
}
LinphoneManager.getLc().enableSpeaker(isSpeakerEnabled);
}
}
// The following should not be needed except some devices need it (e.g. Galaxy S).
LinphoneManager.getLc().enableSpeaker(isSpeakerEnabled);
isMicMuted = LinphoneManager.getLc().isMicMuted();
enableAndRefreshInCallActions();

View file

@ -144,6 +144,10 @@ public class IncomingCallActivity extends Activity implements LinphoneOnCallStat
if (call == mCall && State.CallEnd == state) {
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() {

View file

@ -18,11 +18,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package org.linphone;
import static android.media.AudioManager.MODE_IN_CALL;
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_VOICE_CALL;
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 native void hackSpeakerState(boolean speakerOn);
private static void sRouteAudioToSpeakerHelperHelper(boolean 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);
}
private void routeAudioToSpeakerHelper(boolean speakerOn) {
mLc.enableSpeaker(speakerOn);
for (LinphoneOnAudioChangedListener listener : getSimpleListeners(LinphoneOnAudioChangedListener.class)) {
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() {
routeAudioToSpeakerHelper(true);
}
@ -274,7 +229,7 @@ public final class LinphoneManager implements LinphoneCoreListener {
throw new RuntimeException("Linphone Manager is already initialized");
instance = new LinphoneManager(c, listener);
instance.startLibLinphone();
instance.startLibLinphone(c);
TelephonyManager tm = (TelephonyManager) c.getSystemService(Context.TELEPHONY_SERVICE);
boolean gsmIdle = tm.getCallState() == TelephonyManager.CALL_STATE_IDLE;
setGsmIdle(gsmIdle);
@ -299,16 +254,6 @@ public final class LinphoneManager implements LinphoneCoreListener {
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) {
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 {
copyAssetsFromPackage();
//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(
this, mLinphoneConfigFile, mLinphoneInitialConfigFile, null);
mLc.setContext(c);
mLc.enableIpv6(getPrefBoolean(R.string.pref_ipv6_key, false));
mLc.setZrtpSecretsCache(basePath+"/zrtp_secrets");
@ -1149,11 +1095,9 @@ public final class LinphoneManager implements LinphoneCoreListener {
if (disableRinging ) {
return;
}
if (Hacks.needGalaxySAudioHack()) {
mAudioManager.setMode(MODE_RINGTONE);
}
mLc.startRinging();
try {
if ((mAudioManager.getRingerMode() == AudioManager.RINGER_MODE_VIBRATE || mAudioManager.getRingerMode() == AudioManager.RINGER_MODE_NORMAL) && mVibrator !=null) {
long[] patern = {0,1000,1000};
@ -1224,12 +1168,6 @@ public final class LinphoneManager implements LinphoneCoreListener {
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
public void initializePayloads() {
Log.i("Initializing supported payloads");
@ -1279,9 +1217,6 @@ public final class LinphoneManager implements LinphoneCoreListener {
}
public boolean acceptCallIfIncomingPending() throws LinphoneCoreException {
if (Hacks.needGalaxySAudioHack() || sLPref.useGalaxySHack())
setAudioModeIncallForGalaxyS();
if (mLc.isInComingInvitePending()) {
mLc.acceptCall(mLc.getCurrentCall());
return true;
@ -1290,9 +1225,6 @@ public final class LinphoneManager implements LinphoneCoreListener {
}
public boolean acceptCallWithParams(LinphoneCall call, LinphoneCallParams params) {
if (Hacks.needGalaxySAudioHack() || sLPref.useGalaxySHack())
setAudioModeIncallForGalaxyS();
try {
mLc.acceptCallWithParams(call, params);
return true;

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