mirror of
https://github.com/bleackstorm/SteamFrame-FPV-Control-Center.git
synced 2026-12-03 07:31:57 +01:00
fix(android,telemetry,radxa): synchronize JNI handle lifecycle, add MediaCodec fallback, ignore MAVLink rssi=0, and deploy CDC-ECM gadget in setup script
This commit is contained in:
1 parent
a6ba4e5140
commit
cefbad47e9
4 files changed
+105
-31
No files matched your search
@@ -98,19 +98,43 @@ class LowLatencyVideoDecoder(private val context: Context) {
|
||||
return MediaCodec.createDecoderByType(mime)
|
||||
}
|
||||
|
||||
private fun initCodecLocked(targetSurface: Surface) {
|
||||
try {
|
||||
val mc = createBestLowLatencyDecoder(mimeType)
|
||||
val format = MediaFormat.createVideoFormat(mimeType, 1280, 720).apply {
|
||||
setInteger(MediaFormat.KEY_LOW_LATENCY, 1)
|
||||
setInteger(MediaFormat.KEY_PRIORITY, 0) // Temps réel
|
||||
setInteger(MediaFormat.KEY_OPERATING_RATE, Short.MAX_VALUE.toInt())
|
||||
private fun configureDecoder(targetSurface: Surface, useVendorLowLatency: Boolean): MediaCodec {
|
||||
val mc = if (useVendorLowLatency) {
|
||||
createBestLowLatencyDecoder(mimeType)
|
||||
} else {
|
||||
MediaCodec.createDecoderByType(mimeType)
|
||||
}
|
||||
val format = MediaFormat.createVideoFormat(mimeType, 1280, 720).apply {
|
||||
setInteger(MediaFormat.KEY_LOW_LATENCY, 1)
|
||||
setInteger(MediaFormat.KEY_PRIORITY, 0) // Temps réel
|
||||
setInteger(MediaFormat.KEY_OPERATING_RATE, Short.MAX_VALUE.toInt())
|
||||
if (useVendorLowLatency) {
|
||||
// Clés matérielles Qualcomm (Snapdragon 8 Gen 1 / Tab S8 Ultra) : zéro buffering + sortie en ordre de décodage
|
||||
setInteger("vendor.qti-ext-dec-low-latency.enable", 1)
|
||||
setInteger("vendor.qti-ext-dec-picture-order.enable", 1)
|
||||
}
|
||||
}
|
||||
try {
|
||||
mc.configure(format, targetSurface, null, 0)
|
||||
mc.start()
|
||||
return mc
|
||||
} catch (e: Exception) {
|
||||
try {
|
||||
mc.release()
|
||||
} catch (_: Exception) {
|
||||
}
|
||||
throw e
|
||||
}
|
||||
}
|
||||
|
||||
private fun initCodecLocked(targetSurface: Surface) {
|
||||
try {
|
||||
val mc = try {
|
||||
configureDecoder(targetSurface, useVendorLowLatency = true)
|
||||
} catch (e: Exception) {
|
||||
Log.w(TAG, "Config vendor low-latency rejetée (${e.message}), repli MediaCodec standard")
|
||||
configureDecoder(targetSurface, useVendorLowLatency = false)
|
||||
}
|
||||
codec = mc
|
||||
codecConfigured = true
|
||||
awaitingKeyframe = true
|
||||
|
||||
@@ -27,7 +27,10 @@ class MainActivity : ComponentActivity() {
|
||||
private lateinit var decoder: LowLatencyVideoDecoder
|
||||
private lateinit var connectivityManager: ConnectivityManager
|
||||
private var ethCallback: ConnectivityManager.NetworkCallback? = null
|
||||
private val nativeLock = Any()
|
||||
private var nativeHandle: Long = 0L
|
||||
@Volatile
|
||||
private var isDestroyedFlag: Boolean = false
|
||||
private var currentSurface: Surface? = null
|
||||
|
||||
private var snapshot by mutableStateOf(FpvSnapshot())
|
||||
@@ -78,12 +81,14 @@ class MainActivity : ComponentActivity() {
|
||||
|
||||
setContent {
|
||||
LaunchedEffect(Unit) {
|
||||
while (true) {
|
||||
val h = nativeHandle
|
||||
if (h != 0L) {
|
||||
val json = withContext(Dispatchers.IO) {
|
||||
NativeFpvEngine.nativePollSnapshotJson(h)
|
||||
while (!isDestroyedFlag) {
|
||||
val json = withContext(Dispatchers.IO) {
|
||||
synchronized(nativeLock) {
|
||||
val h = nativeHandle
|
||||
if (h != 0L) NativeFpvEngine.nativePollSnapshotJson(h) else null
|
||||
}
|
||||
}
|
||||
if (json != null) {
|
||||
val snap = FpvSnapshot.fromJson(json)
|
||||
snapshot = snap
|
||||
if (dvrRecording && snap.telemetry.srtLine.isNotBlank()) {
|
||||
@@ -133,19 +138,28 @@ class MainActivity : ComponentActivity() {
|
||||
}
|
||||
|
||||
private fun restartNativeEngine() {
|
||||
stopNativeEngine()
|
||||
nativeHandle = NativeFpvEngine.nativeStart(
|
||||
callback = nativeCallback,
|
||||
videoPort = videoPort,
|
||||
codec = codecName,
|
||||
transport = transportName,
|
||||
g29Port = g29Port,
|
||||
telemetryPort = telemetryPort,
|
||||
)
|
||||
syncNativeFlags()
|
||||
synchronized(nativeLock) {
|
||||
if (isDestroyedFlag) return
|
||||
stopNativeEngineLocked()
|
||||
nativeHandle = NativeFpvEngine.nativeStart(
|
||||
callback = nativeCallback,
|
||||
videoPort = videoPort,
|
||||
codec = codecName,
|
||||
transport = transportName,
|
||||
g29Port = g29Port,
|
||||
telemetryPort = telemetryPort,
|
||||
)
|
||||
syncNativeFlagsLocked()
|
||||
}
|
||||
}
|
||||
|
||||
private fun stopNativeEngine() {
|
||||
synchronized(nativeLock) {
|
||||
stopNativeEngineLocked()
|
||||
}
|
||||
}
|
||||
|
||||
private fun stopNativeEngineLocked() {
|
||||
val h = nativeHandle
|
||||
nativeHandle = 0L
|
||||
if (h != 0L) {
|
||||
@@ -154,6 +168,12 @@ class MainActivity : ComponentActivity() {
|
||||
}
|
||||
|
||||
private fun syncNativeFlags() {
|
||||
synchronized(nativeLock) {
|
||||
syncNativeFlagsLocked()
|
||||
}
|
||||
}
|
||||
|
||||
private fun syncNativeFlagsLocked() {
|
||||
val h = nativeHandle
|
||||
if (h != 0L) {
|
||||
NativeFpvEngine.nativeSyncUiFlags(h, dvrRecording, osdEnabled)
|
||||
@@ -194,9 +214,11 @@ class MainActivity : ComponentActivity() {
|
||||
.build()
|
||||
val cb = object : ConnectivityManager.NetworkCallback() {
|
||||
override fun onAvailable(network: Network) {
|
||||
if (isDestroyedFlag) return
|
||||
val ok = connectivityManager.bindProcessToNetwork(network)
|
||||
Log.i("SteamFrameFPV", "Ethernet USB lié au processus (bindProcessToNetwork=$ok)")
|
||||
runOnUiThread {
|
||||
if (isDestroyedFlag) return@runOnUiThread
|
||||
pingStatus = if (ok) "ETH USB OK" else "ETH bind fail"
|
||||
restartNativeEngine()
|
||||
}
|
||||
@@ -206,6 +228,7 @@ class MainActivity : ComponentActivity() {
|
||||
connectivityManager.bindProcessToNetwork(null)
|
||||
Log.i("SteamFrameFPV", "Ethernet USB déconnecté")
|
||||
runOnUiThread {
|
||||
if (isDestroyedFlag) return@runOnUiThread
|
||||
pingStatus = "ETH déconnecté"
|
||||
}
|
||||
}
|
||||
@@ -218,6 +241,7 @@ class MainActivity : ComponentActivity() {
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
isDestroyedFlag = true
|
||||
ethCallback?.let {
|
||||
try {
|
||||
connectivityManager.unregisterNetworkCallback(it)
|
||||
|
||||
Reference in new issue
Block a user