Recording enc and dec files may not be created during the same second

This commit is contained in:
Juha Heinanen
2023-03-15 10:08:47 +02:00
parent bc3c7cf75c
commit 17d5fb5d07
8 changed files with 25 additions and 22 deletions

View File

@ -579,8 +579,12 @@ class BaresipService: Service() {
if (ev[0] == "sndfile dump") {
Log.d(TAG, "Got sndfile dump ${ev[1]}")
if (Call.inCall())
Call.calls()[0].dumpfile = ev[1]
if (Call.inCall()) {
if (ev[1].endsWith("enc.wav"))
Call.calls()[0].dumpfiles[0] = ev[1]
else
Call.calls()[0].dumpfiles[1] = ev[1]
}
return
}
@ -885,8 +889,8 @@ class BaresipService: Service() {
val history = CallHistory(aor, call.peerUri, call.dir)
history.startTime = call.startTime
history.stopTime = GregorianCalendar()
if (call.startTime != null && call.dumpfile != "")
history.recording = call.dumpfile.substringBeforeLast("-")
if (call.startTime != null && call.dumpfiles[0] != "")
history.recording = call.dumpfiles
CallHistory.add(history)
CallHistory.save()
ua.account.missedCalls = ua.account.missedCalls || missed

View File

@ -15,7 +15,7 @@ class Call(val callp: Long, val ua: UserAgent, val peerUri: String, val dir: Str
var zid = ""
var startTime: GregorianCalendar? = null // Set when call is established
var referTo = ""
var dumpfile = ""
var dumpfiles = arrayOf("", "")
fun add() {
BaresipService.calls.add(0, this)

View File

@ -74,7 +74,7 @@ class CallDetailsAdapter(private val ctx: Context, private val rows: ArrayList<C
val duration = (stopTime.time.time - startTime.time.time) / 1000
viewHolder.durationView.text = DateUtils.formatElapsedTime(duration)
val recording = rows[position].recording
if (recording != "") {
if (recording[0] != "") {
viewHolder.durationView.typeface = Typeface.DEFAULT_BOLD
viewHolder.durationView.setOnClickListener {
Utils.playRecording(ctx, recording)

View File

@ -7,8 +7,8 @@ import java.util.GregorianCalendar
class CallHistory(val aor: String, val peerUri: String, val direction: String) : Serializable {
var startTime: GregorianCalendar? = null // Set to time when call is established (if ever)
var stopTime = GregorianCalendar() // Set to time when call is closed
var recording = ""
var stopTime = GregorianCalendar() // Set to time when call is closed
var recording = arrayOf("", "") // Encoder and decoder recording files
companion object {
@ -20,7 +20,7 @@ class CallHistory(val aor: String, val peerUri: String, val direction: String) :
if (aorHistorySize(history.aor) > CALL_HISTORY_SIZE) {
for (h in BaresipService.callHistory)
if (h.aor == history.aor) {
if (h.recording != "")
if (h.recording[0] != "")
deleteRecording(h.recording)
BaresipService.callHistory.remove(h)
break
@ -32,7 +32,7 @@ class CallHistory(val aor: String, val peerUri: String, val direction: String) :
for (i in BaresipService.callHistory.indices.reversed()) {
val h = BaresipService.callHistory[i]
if (h.aor == aor) {
if (h.recording != "")
if (h.recording[0] != "")
deleteRecording(h.recording)
BaresipService.callHistory.removeAt(i)
}
@ -81,16 +81,16 @@ class CallHistory(val aor: String, val peerUri: String, val direction: String) :
}
}
fun deleteRecording(recording: String) {
Utils.deleteFile(File("$recording-enc.wav"))
Utils.deleteFile(File("$recording-dec.wav"))
fun deleteRecording(recording: Array<String>) {
Utils.deleteFile(File(recording[0]))
Utils.deleteFile(File(recording[1]))
}
@Suppress("UNUSED")
fun print() {
for (h in BaresipService.callHistory)
Log.d(TAG, "[${h.aor}, ${h.peerUri}, ${h.direction}, ${h.startTime}," +
"${h.stopTime}, ${h.recording}]")
"${h.stopTime}, ${h.recording}")
}
}

View File

@ -48,7 +48,7 @@ class CallListAdapter(private val ctx: Context, private val account: Account,
viewHolder.directionsView.removeAllViews()
var count = 1
for (d in callRow.details) {
if (d.recording != "")
if (d.recording[0] != "")
viewHolder.timeView.typeface = Typeface.DEFAULT_BOLD
if (count > 3) {
viewHolder.etcView.text = "..."

View File

@ -6,12 +6,12 @@ import kotlin.collections.ArrayList
class CallRow(val aor: String, val peerUri: String, val direction: Int,
startTime: GregorianCalendar?,
val stopTime: GregorianCalendar,
val recording: String)
val recording: Array<String>)
{
class Details(val direction: Int, val startTime: GregorianCalendar?,
val stopTime: GregorianCalendar, val recording: String)
val stopTime: GregorianCalendar, val recording: Array<String>)
val details = ArrayList<Details>()

View File

@ -13,7 +13,6 @@ import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AppCompatActivity
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.tutpro.baresip.databinding.ActivityCallsBinding
import java.io.File
class CallsActivity : AppCompatActivity() {
@ -277,7 +276,7 @@ class CallsActivity : AppCompatActivity() {
private fun removeUaHistoryAt(i: Int) {
for (details in uaHistory[i].details) {
if (details.recording != "")
if (details.recording[0] != "")
CallHistory.deleteRecording(details.recording)
BaresipService.callHistory.removeAll {
it.startTime == details.startTime && it.stopTime == details.stopTime

View File

@ -995,7 +995,7 @@ object Utils {
}
}
fun playRecording(ctx: Context, recording: String) {
fun playRecording(ctx: Context, recording: Array<String>) {
Log.d(TAG, "Playing recording $recording")
val decPlayer = MediaPlayer()
decPlayer.apply {
@ -1025,7 +1025,7 @@ object Utils {
it.release()
}
try {
val file = "$recording-enc.wav"
val file = recording[0]
val encFile = File(file).copyTo(File(BaresipService.filesPath + "/tmp/encode.wav"), true)
val encUri = encFile.toUri()
setDataSource(ctx, encUri)
@ -1045,7 +1045,7 @@ object Utils {
it.release()
}
try {
val file = "$recording-dec.wav"
val file = recording[1]
val decFile = File(file).copyTo(File(BaresipService.filesPath + "/tmp/decode.wav"), true)
val decUri = decFile.toUri()
setDataSource(ctx, decUri)