- added handling of call transfer failed event

- improved implementation of audio focus and abandon requests
- upstream re, rem, and baresip libs changes
This commit is contained in:
Juha Heinanen
2018-11-02 22:29:33 +02:00
parent ae0c9a983e
commit 9b98378f0c
3 changed files with 52 additions and 17 deletions

View File

@ -134,6 +134,9 @@ static void ua_event_handler(struct ua *ua, enum ua_event ev,
case UA_EVENT_CALL_TRANSFER: case UA_EVENT_CALL_TRANSFER:
re_snprintf(event_buf, sizeof event_buf, "call transfer,%s", prm); re_snprintf(event_buf, sizeof event_buf, "call transfer,%s", prm);
break; break;
case UA_EVENT_CALL_TRANSFER_FAILED:
re_snprintf(event_buf, sizeof event_buf, "transfer failed,%s", prm);
break;
case UA_EVENT_CALL_CLOSED: case UA_EVENT_CALL_CLOSED:
play = mem_deref(play); play = mem_deref(play);
if (call_scode(call)) { if (call_scode(call)) {
@ -155,7 +158,6 @@ static void ua_event_handler(struct ua *ua, enum ua_event ev,
re_snprintf(event_buf, sizeof event_buf, "%s", "exit"); re_snprintf(event_buf, sizeof event_buf, "%s", "exit");
break; break;
default: default:
re_snprintf(event_buf, sizeof event_buf, "%s", "unknown event");
return; return;
} }
event = event_buf; event = event_buf;

View File

@ -259,8 +259,6 @@ class BaresipService: Service() {
MainActivity.images[account_index] = R.drawable.dot_yellow MainActivity.images[account_index] = R.drawable.dot_yellow
updateStatusNotification() updateStatusNotification()
} }
"call ringing" -> {
}
"call incoming" -> { "call incoming" -> {
if (!Utils.isVisible()) { if (!Utils.isVisible()) {
val cnb = NotificationCompat.Builder(this, HIGH_CHANNEL_ID) val cnb = NotificationCompat.Builder(this, HIGH_CHANNEL_ID)

View File

@ -1,6 +1,7 @@
package com.tutpro.baresip package com.tutpro.baresip
import android.Manifest import android.Manifest
import android.annotation.TargetApi
import android.app.NotificationManager import android.app.NotificationManager
import android.content.* import android.content.*
import android.support.v4.app.ActivityCompat import android.support.v4.app.ActivityCompat
@ -13,11 +14,8 @@ import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import android.content.pm.PackageManager import android.content.pm.PackageManager
import android.graphics.Color import android.graphics.Color
import android.media.AudioManager import android.media.*
import android.media.AudioManager.STREAM_RING import android.os.Build
import android.media.AudioManager.STREAM_VOICE_CALL
import android.media.Ringtone
import android.media.RingtoneManager
import android.support.v4.content.LocalBroadcastManager import android.support.v4.content.LocalBroadcastManager
import android.support.v7.view.menu.ActionMenuItemView import android.support.v7.view.menu.ActionMenuItemView
import android.view.inputmethod.InputMethodManager import android.view.inputmethod.InputMethodManager
@ -405,7 +403,6 @@ class MainActivity : AppCompatActivity() {
uaAdapter.notifyDataSetChanged() uaAdapter.notifyDataSetChanged()
} }
"call ringing" -> { "call ringing" -> {
requestAudioFocus(STREAM_VOICE_CALL)
} }
"call incoming" -> { "call incoming" -> {
val callp = params[1] val callp = params[1]
@ -505,8 +502,8 @@ class MainActivity : AppCompatActivity() {
rtTimer = null rtTimer = null
if (rt.isPlaying) rt.stop() if (rt.isPlaying) rt.stop()
} }
am.mode = AudioManager . MODE_IN_COMMUNICATION am.mode = AudioManager.MODE_IN_COMMUNICATION
requestAudioFocus(STREAM_VOICE_CALL) requestAudioFocus( AudioManager.STREAM_VOICE_CALL)
am.isSpeakerphoneOn = false am.isSpeakerphoneOn = false
// am.setStreamVolume(AudioManager.STREAM_VOICE_CALL, // am.setStreamVolume(AudioManager.STREAM_VOICE_CALL,
// (am.getStreamMaxVolume(STREAM_VOICE_CALL) / 2) + 1, // (am.getStreamMaxVolume(STREAM_VOICE_CALL) / 2) + 1,
@ -596,6 +593,11 @@ class MainActivity : AppCompatActivity() {
} }
transferDialog.create().show() transferDialog.create().show()
} }
"transfer failed" -> {
val callp = params[1]
Log.d("Baresip", "AoR $aor hanging up call $callp with ${ev[1]}")
ua_hangup(ua.uap, callp, 0, "")
}
"call closed" -> { "call closed" -> {
val callp = params[1] val callp = params[1]
val call = Call.find(calls, callp) val call = Call.find(calls, callp)
@ -636,8 +638,7 @@ class MainActivity : AppCompatActivity() {
R.color.colorPrimary)) R.color.colorPrimary))
} }
if (audioFocused) { if (audioFocused) {
am.abandonAudioFocus(null) abandonAudioFocus()
audioFocused = false
} }
} }
"message" -> { "message" -> {
@ -1088,9 +1089,28 @@ class MainActivity : AppCompatActivity() {
} }
} }
private fun requestAudioFocus(stream: Int) { private fun requestAudioFocus(streamType: Int) {
if (!audioFocused) { val res: Int
val res = am.requestAudioFocus(null, stream, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE) if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) && (audioFocusRequest == null)) {
val playbackAttributes = AudioAttributes.Builder()
.setLegacyStreamType(streamType)
.build()
@TargetApi(26)
audioFocusRequest = AudioFocusRequest.Builder(AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE)
.setAudioAttributes(playbackAttributes)
.setAcceptsDelayedFocusGain(true)
.build()
@TargetApi(26)
res = am.requestAudioFocus(audioFocusRequest)
if (res == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
Log.d("Baresip", "Audio focus granted")
} else {
Log.d("Baresip", "Audio focus denied")
audioFocusRequest = null
}
} else {
res = am.requestAudioFocus(null, streamType,
AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE)
if (res == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) { if (res == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
Log.d("Baresip", "Audio focus granted") Log.d("Baresip", "Audio focus granted")
audioFocused = true audioFocused = true
@ -1101,9 +1121,23 @@ class MainActivity : AppCompatActivity() {
} }
} }
private fun abandonAudioFocus() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
if (audioFocusRequest != null) {
am.abandonAudioFocusRequest(audioFocusRequest)
audioFocusRequest = null
}
} else {
if (audioFocused) {
am.abandonAudioFocus(null)
audioFocused = false
}
}
}
private fun startRinging() { private fun startRinging() {
am.mode = AudioManager.MODE_RINGTONE am.mode = AudioManager.MODE_RINGTONE
requestAudioFocus(STREAM_RING) requestAudioFocus(AudioManager.STREAM_RING)
rt.play() rt.play()
rtTimer = Timer() rtTimer = Timer()
rtTimer!!.scheduleAtFixedRate(object : TimerTask() { rtTimer!!.scheduleAtFixedRate(object : TimerTask() {
@ -1145,6 +1179,7 @@ class MainActivity : AppCompatActivity() {
internal var calls = ArrayList<Call>() internal var calls = ArrayList<Call>()
internal var messages = ArrayList<Message>() internal var messages = ArrayList<Message>()
internal var audioFocused = false internal var audioFocused = false
internal var audioFocusRequest: AudioFocusRequest? = null
var filesPath = "" var filesPath = ""
var visible = true var visible = true
var makeCall = "" var makeCall = ""