|
|
|
@ -24,6 +24,12 @@ object StreamController { |
|
|
|
private val main = Handler(Looper.getMainLooper()) |
|
|
|
private val main = Handler(Looper.getMainLooper()) |
|
|
|
private val mutable = MutableStateFlow<StreamState?>(null) |
|
|
|
private val mutable = MutableStateFlow<StreamState?>(null) |
|
|
|
val state: StateFlow<StreamState?> = mutable |
|
|
|
val state: StateFlow<StreamState?> = mutable |
|
|
|
|
|
|
|
private val mutableTx = MutableStateFlow<StreamTxStats?>(null) |
|
|
|
|
|
|
|
val txStats: StateFlow<StreamTxStats?> = mutableTx |
|
|
|
|
|
|
|
fun updateTx(id: Long, data: LongArray) { |
|
|
|
|
|
|
|
check(Looper.myLooper() == Looper.getMainLooper()) |
|
|
|
|
|
|
|
if (mutable.value?.id == id && mutable.value?.ongoing == true) mutableTx.value = StreamTxStats.fromNative(id, data) |
|
|
|
|
|
|
|
} |
|
|
|
@Volatile var capturing = false |
|
|
|
@Volatile var capturing = false |
|
|
|
private set |
|
|
|
private set |
|
|
|
private var service: StreamService? = null |
|
|
|
private var service: StreamService? = null |
|
|
|
@ -38,6 +44,7 @@ object StreamController { |
|
|
|
mutable.value = StreamState(id, group, StreamPhase.FAILED, R.string.stream_resources_busy); return |
|
|
|
mutable.value = StreamState(id, group, StreamPhase.FAILED, R.string.stream_resources_busy); return |
|
|
|
} |
|
|
|
} |
|
|
|
capturing = true; mutable.value = StreamState(id, group, StreamPhase.STARTING, pendingConfig = config) |
|
|
|
capturing = true; mutable.value = StreamState(id, group, StreamPhase.STARTING, pendingConfig = config) |
|
|
|
|
|
|
|
mutableTx.value = null |
|
|
|
try { |
|
|
|
try { |
|
|
|
ContextCompat.startForegroundService(ChatApplication.instance, Intent(ChatApplication.instance, StreamService::class.java) |
|
|
|
ContextCompat.startForegroundService(ChatApplication.instance, Intent(ChatApplication.instance, StreamService::class.java) |
|
|
|
.putExtra("id", id).putExtra("group", group).putExtra("audio", audio)) |
|
|
|
.putExtra("id", id).putExtra("group", group).putExtra("audio", audio)) |
|
|
|
@ -99,6 +106,7 @@ object StreamController { |
|
|
|
val st = mutable.value ?: return |
|
|
|
val st = mutable.value ?: return |
|
|
|
if (st.id != id || !st.ongoing) return |
|
|
|
if (st.id != id || !st.ongoing) return |
|
|
|
capturing = false |
|
|
|
capturing = false |
|
|
|
|
|
|
|
mutableTx.value = null |
|
|
|
mutable.value = st.copy(phase = if (st.error != null) StreamPhase.FAILED else StreamPhase.ENDED, pendingConfig = null) |
|
|
|
mutable.value = st.copy(phase = if (st.error != null) StreamPhase.FAILED else StreamPhase.ENDED, pendingConfig = null) |
|
|
|
LogManager.addLog("INFO", "stream", "publisher released id=$id") |
|
|
|
LogManager.addLog("INFO", "stream", "publisher released id=$id") |
|
|
|
} |
|
|
|
} |
|
|
|
|