|
|
|
|
@ -13,7 +13,8 @@ import java.util.concurrent.atomic.AtomicLong
|
|
|
|
|
|
|
|
|
|
enum class StreamPhase { STARTING, LIVE, STOPPING, ENDED, FAILED } |
|
|
|
|
data class StreamState(val id: Long, val group: Long, val phase: StreamPhase, val error: Int? = null, |
|
|
|
|
val config: StreamCaptureConfig? = null, val pendingConfig: StreamCaptureConfig? = null, val notice: Int? = null, val preview: StreamPreview = StreamPreview()) { |
|
|
|
|
val config: StreamCaptureConfig? = null, val pendingConfig: StreamCaptureConfig? = null, val notice: Int? = null, |
|
|
|
|
val preview: StreamPreview = StreamPreview(), val audioAvailable: Boolean = false, val audioEnabled: Boolean = false) { |
|
|
|
|
val ongoing get() = phase == StreamPhase.STARTING || phase == StreamPhase.LIVE || phase == StreamPhase.STOPPING |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -43,7 +44,8 @@ object StreamController {
|
|
|
|
|
LogManager.addLog("WARN", "stream", "start rejected: core/call/voice busy group=$group") |
|
|
|
|
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, audioAvailable = audio, audioEnabled = audio) |
|
|
|
|
mutableTx.value = null |
|
|
|
|
try { |
|
|
|
|
ContextCompat.startForegroundService(ChatApplication.instance, Intent(ChatApplication.instance, StreamService::class.java) |
|
|
|
|
@ -66,6 +68,17 @@ object StreamController {
|
|
|
|
|
owner.change(config) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun setAudioEnabled(enabled: Boolean) { |
|
|
|
|
check(Looper.myLooper() == Looper.getMainLooper()) |
|
|
|
|
val st = mutable.value ?: return |
|
|
|
|
if (st.phase != StreamPhase.LIVE || !st.audioAvailable || service == null) { |
|
|
|
|
LogManager.addLog("WARN", "stream", "audio control unavailable id=${st.id} phase=${st.phase}"); return |
|
|
|
|
} |
|
|
|
|
if (st.audioEnabled == enabled) return |
|
|
|
|
if (service!!.setAudioEnabled(enabled)) mutable.value = st.copy(audioEnabled = enabled) |
|
|
|
|
else failed(st.id, "audio control failed enabled=$enabled") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun captureReady(id: Long, config: StreamCaptureConfig, restored: Boolean) { |
|
|
|
|
main.post { |
|
|
|
|
val st = mutable.value ?: return@post |
|
|
|
|
|