Adding type of stream to RequestAudioFocus

This commit is contained in:
Erwan Croze 2016-08-31 16:27:39 +02:00
parent 2171962b78
commit 8036675e28
3 changed files with 19 additions and 21 deletions

View file

@ -66,6 +66,7 @@ import org.linphone.core.PublishState;
import org.linphone.core.SubscriptionState; import org.linphone.core.SubscriptionState;
import org.linphone.core.TunnelConfig; import org.linphone.core.TunnelConfig;
import org.linphone.mediastream.Log; import org.linphone.mediastream.Log;
import org.linphone.mediastream.MediastreamerAndroidContext;
import org.linphone.mediastream.Version; import org.linphone.mediastream.Version;
import org.linphone.mediastream.video.capture.hwconf.AndroidCameraConfiguration; import org.linphone.mediastream.video.capture.hwconf.AndroidCameraConfiguration;
import org.linphone.mediastream.video.capture.hwconf.AndroidCameraConfiguration.AndroidCamera; import org.linphone.mediastream.video.capture.hwconf.AndroidCameraConfiguration.AndroidCamera;
@ -139,6 +140,7 @@ public class LinphoneManager implements LinphoneCoreListener, LinphoneChatMessag
private static List<LinphoneChatMessage> mPendingChatFileMessage; private static List<LinphoneChatMessage> mPendingChatFileMessage;
private static LinphoneChatMessage mUploadPendingFileMessage; private static LinphoneChatMessage mUploadPendingFileMessage;
public String wizardLoginViewDomain = null; public String wizardLoginViewDomain = null;
private static List<LinphoneChatMessage.LinphoneChatMessageListener> simpleListeners = new ArrayList<LinphoneChatMessage.LinphoneChatMessageListener>(); private static List<LinphoneChatMessage.LinphoneChatMessageListener> simpleListeners = new ArrayList<LinphoneChatMessage.LinphoneChatMessageListener>();
@ -1069,6 +1071,7 @@ public class LinphoneManager implements LinphoneCoreListener, LinphoneChatMessag
else if (state == State.IncomingReceived || (state == State.CallIncomingEarlyMedia && mR.getBoolean(R.bool.allow_ringing_while_early_media))) { else if (state == State.IncomingReceived || (state == State.CallIncomingEarlyMedia && mR.getBoolean(R.bool.allow_ringing_while_early_media))) {
// Brighten screen for at least 10 seconds // Brighten screen for at least 10 seconds
if (mLc.getCallsNb() == 1) { if (mLc.getCallsNb() == 1) {
requestAudioFocus(STREAM_RING);
BluetoothManager.getInstance().disableBluetoothSCO(); // Just in case BluetoothManager.getInstance().disableBluetoothSCO(); // Just in case
ringingCall = call; ringingCall = call;
@ -1082,8 +1085,8 @@ public class LinphoneManager implements LinphoneCoreListener, LinphoneChatMessag
if (state == State.Connected) { if (state == State.Connected) {
if (mLc.getCallsNb() == 1) { if (mLc.getCallsNb() == 1) {
requestAudioFocus(); mAudioManager.abandonAudioFocus(null);
setAudioManagerInCallMode(); requestAudioFocus(STREAM_VOICE_CALL);
} }
if (Hacks.needSoftvolume()) { if (Hacks.needSoftvolume()) {
@ -1096,15 +1099,14 @@ public class LinphoneManager implements LinphoneCoreListener, LinphoneChatMessag
setAudioManagerInCallMode(); setAudioManagerInCallMode();
} }
if (state == State.CallReleased || state == State.Error) { if (state == State.CallEnd || state == State.Error) {
if (mLc.getCallsNb() == 0) { if (mLc.getCallsNb() == 0) {
Context activity = getContext();
if (mAudioFocused){ if (mAudioFocused){
int res = mAudioManager.abandonAudioFocus(null); int res = mAudioManager.abandonAudioFocus(null);
Log.d("Audio focus released a bit later: " + (res == AudioManager.AUDIOFOCUS_REQUEST_GRANTED ? "Granted" : "Denied")); Log.d("Audio focus released a bit later: " + (res == AudioManager.AUDIOFOCUS_REQUEST_GRANTED ? "Granted" : "Denied"));
mAudioFocused = false; mAudioFocused = false;
} }
Context activity = getContext();
if (activity != null) { if (activity != null) {
TelephonyManager tm = (TelephonyManager) activity.getSystemService(Context.TELEPHONY_SERVICE); TelephonyManager tm = (TelephonyManager) activity.getSystemService(Context.TELEPHONY_SERVICE);
if (tm.getCallState() == TelephonyManager.CALL_STATE_IDLE) { if (tm.getCallState() == TelephonyManager.CALL_STATE_IDLE) {
@ -1116,17 +1118,6 @@ public class LinphoneManager implements LinphoneCoreListener, LinphoneChatMessag
} }
} }
} }
if (state == State.CallEnd) {
if (mLc.getCallsNb() == 0) {
if (mIncallWakeLock != null && mIncallWakeLock.isHeld()) {
mIncallWakeLock.release();
Log.i("Last call ended: releasing incall (CPU only) wake lock");
} else {
Log.i("Last call ended: no incall (CPU only) wake lock were held");
}
}
}
if (state == State.CallUpdatedByRemote) { if (state == State.CallUpdatedByRemote) {
// If the correspondent proposes video while audio call // If the correspondent proposes video while audio call
boolean remoteVideo = call.getRemoteParams().getVideoEnabled(); boolean remoteVideo = call.getRemoteParams().getVideoEnabled();
@ -1140,6 +1131,10 @@ public class LinphoneManager implements LinphoneCoreListener, LinphoneChatMessag
} }
} }
} }
if (state == State.OutgoingInit) {
setAudioManagerInCallMode();
requestAudioFocus(STREAM_VOICE_CALL);
}
if (state == State.StreamsRunning) { if (state == State.StreamsRunning) {
if (BluetoothManager.getInstance().isBluetoothHeadsetAvailable()) { if (BluetoothManager.getInstance().isBluetoothHeadsetAvailable()) {
@ -1175,6 +1170,7 @@ public class LinphoneManager implements LinphoneCoreListener, LinphoneChatMessag
routeAudioToSpeaker(); routeAudioToSpeaker();
setAudioManagerInCallMode(); setAudioManagerInCallMode();
Log.i("Set audio mode on 'Voice Communication'"); Log.i("Set audio mode on 'Voice Communication'");
requestAudioFocus(STREAM_VOICE_CALL);
int oldVolume = mAudioManager.getStreamVolume(STREAM_VOICE_CALL); int oldVolume = mAudioManager.getStreamVolume(STREAM_VOICE_CALL);
int maxVolume = mAudioManager.getStreamMaxVolume(STREAM_VOICE_CALL); int maxVolume = mAudioManager.getStreamMaxVolume(STREAM_VOICE_CALL);
mAudioManager.setStreamVolume(STREAM_VOICE_CALL, maxVolume, 0); mAudioManager.setStreamVolume(STREAM_VOICE_CALL, maxVolume, 0);
@ -1186,6 +1182,7 @@ public class LinphoneManager implements LinphoneCoreListener, LinphoneChatMessag
routeAudioToSpeaker(); routeAudioToSpeaker();
setAudioManagerInCallMode(); setAudioManagerInCallMode();
Log.i("Set audio mode on 'Voice Communication'"); Log.i("Set audio mode on 'Voice Communication'");
requestAudioFocus(STREAM_VOICE_CALL);
int oldVolume = mAudioManager.getStreamVolume(STREAM_VOICE_CALL); int oldVolume = mAudioManager.getStreamVolume(STREAM_VOICE_CALL);
int maxVolume = mAudioManager.getStreamMaxVolume(STREAM_VOICE_CALL); int maxVolume = mAudioManager.getStreamMaxVolume(STREAM_VOICE_CALL);
int sampleRate = 44100; int sampleRate = 44100;
@ -1222,9 +1219,9 @@ public class LinphoneManager implements LinphoneCoreListener, LinphoneChatMessag
private boolean isRinging; private boolean isRinging;
private void requestAudioFocus(){ private void requestAudioFocus(int stream){
if (!mAudioFocused){ if (!mAudioFocused){
int res = mAudioManager.requestAudioFocus(null, AudioManager.STREAM_VOICE_CALL, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT ); int res = mAudioManager.requestAudioFocus(null, stream, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT );
Log.d("Audio focus requested: " + (res == AudioManager.AUDIOFOCUS_REQUEST_GRANTED ? "Granted" : "Denied")); Log.d("Audio focus requested: " + (res == AudioManager.AUDIOFOCUS_REQUEST_GRANTED ? "Granted" : "Denied"));
if (res == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) mAudioFocused=true; if (res == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) mAudioFocused=true;
} }
@ -1259,7 +1256,7 @@ public class LinphoneManager implements LinphoneCoreListener, LinphoneChatMessag
mVibrator.vibrate(patern, 1); mVibrator.vibrate(patern, 1);
} }
if (mRingerPlayer == null) { if (mRingerPlayer == null) {
requestAudioFocus(); requestAudioFocus(STREAM_RING);
mRingerPlayer = new MediaPlayer(); mRingerPlayer = new MediaPlayer();
mRingerPlayer.setAudioStreamType(STREAM_RING); mRingerPlayer.setAudioStreamType(STREAM_RING);
@ -1528,6 +1525,7 @@ public class LinphoneManager implements LinphoneCoreListener, LinphoneChatMessag
public void ecCalibrationStatus(LinphoneCore lc, EcCalibratorStatus status, public void ecCalibrationStatus(LinphoneCore lc, EcCalibratorStatus status,
int delay_ms, Object data) { int delay_ms, Object data) {
((AudioManager)getContext().getSystemService(Context.AUDIO_SERVICE)).setMode(AudioManager.MODE_NORMAL); ((AudioManager)getContext().getSystemService(Context.AUDIO_SERVICE)).setMode(AudioManager.MODE_NORMAL);
mAudioManager.abandonAudioFocus(null);
Log.i("Set audio mode on 'Normal'"); Log.i("Set audio mode on 'Normal'");
} }

@ -1 +1 @@
Subproject commit 01df9f93533bb1526a673ae7c557ae2508747a49 Subproject commit 6bc186fb256f7a1ff0755d42773e55f91ca4a9b3

@ -1 +1 @@
Subproject commit 7744dc572470de6caf11b7e4ce7e79ba0c5efd55 Subproject commit 3fe5d85ee4dbed91920f3a43f129d28b3dece138