29 lines
1.6 KiB
Kotlin
29 lines
1.6 KiB
Kotlin
package com.gorios.lanvoice.audio
|
|
|
|
import com.gorios.lanvoice.net.DownlinkFrame
|
|
|
|
enum class AecAvailability { AVAILABLE, UNAVAILABLE, UNKNOWN }
|
|
// No audio devices in callback propagation tests.
|
|
class AudioCapture {
|
|
companion object { var lastFrame: ((ByteArray) -> Unit)? = null; var lastError: ((Exception) -> Unit)? = null; var starts = 0
|
|
var confirmStopsAutomatically = true; var lastStopped: ((Boolean)->Unit)? = null }
|
|
fun aecAvailability() = AecAvailability.UNKNOWN
|
|
fun start(onFrame: (ByteArray) -> Unit, onError: (Exception) -> Unit, onDiagnostic: (String) -> Unit = {}) { starts++; lastFrame = onFrame; lastError = onError; onDiagnostic("AudioRecord initialization ok") }
|
|
fun stopAndConfirm(confirmed: (Boolean) -> Unit) { lastStopped = confirmed; if(confirmStopsAutomatically) confirmed(true) }
|
|
fun stop() {}
|
|
fun release() {}
|
|
}
|
|
class AudioPlayback(onDrained: (Long, Long) -> Unit, onError: (Long, Exception) -> Unit, onProgress: (Long, Long, String) -> Unit = { _, _, _ -> }, onActivity: (PlaybackActivity) -> Unit = {}) {
|
|
companion object { var interrupts = 0; var enqueued = 0; var lastDrained: ((Long, Long) -> Unit)? = null
|
|
var lastActivity: ((PlaybackActivity) -> Unit)? = null
|
|
var activityFence: ((Long,Long)->Boolean)? = null }
|
|
init { lastDrained = onDrained; lastActivity = onActivity }
|
|
fun beginTurn(turn: Long) {}
|
|
fun endTurn(turn: Long) {}
|
|
fun enqueue(frame: DownlinkFrame): Boolean { enqueued++; return true }
|
|
fun isCurrent(turn: Long, epoch: Long) = activityFence?.invoke(turn,epoch) ?: true
|
|
fun isCurrent(epoch: Long) = true
|
|
fun interrupt() { interrupts++ }
|
|
fun release() {}
|
|
}
|