mirror of
https://github.com/bleackstorm/SteamFrame-FPV-Control-Center.git
synced 2026-12-03 07:31:57 +01:00
perf(android): prefer Qualcomm c2.qti.*.low_latency decoder, picture-order output, and immediate VSync render
This commit is contained in:
1 parent
4fdffe3393
commit
19cdf982c4
1 file changed
+38
-6
@@ -3,6 +3,8 @@ package com.steamframe.fpv
|
|||||||
import android.content.ContentValues
|
import android.content.ContentValues
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.media.MediaCodec
|
import android.media.MediaCodec
|
||||||
|
import android.media.MediaCodecInfo
|
||||||
|
import android.media.MediaCodecList
|
||||||
import android.media.MediaFormat
|
import android.media.MediaFormat
|
||||||
import android.media.MediaMuxer
|
import android.media.MediaMuxer
|
||||||
import android.os.Environment
|
import android.os.Environment
|
||||||
@@ -67,15 +69,45 @@ class LowLatencyVideoDecoder(private val context: Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun createBestLowLatencyDecoder(mime: String): MediaCodec {
|
||||||
|
val list = MediaCodecList(MediaCodecList.REGULAR_CODECS).codecInfos
|
||||||
|
var featureMatch: String? = null
|
||||||
|
for (info in list) {
|
||||||
|
if (info.isEncoder) continue
|
||||||
|
if (!info.supportedTypes.any { it.equals(mime, ignoreCase = true) }) continue
|
||||||
|
val nameLower = info.name.lowercase(Locale.US)
|
||||||
|
if (nameLower.contains("low_latency")) {
|
||||||
|
Log.i(TAG, "Sélection décodeur matériel dédié low_latency : ${info.name}")
|
||||||
|
return MediaCodec.createByCodecName(info.name)
|
||||||
|
}
|
||||||
|
if (featureMatch == null && !nameLower.startsWith("c2.android.") && !nameLower.startsWith("omx.google.")) {
|
||||||
|
val caps = try {
|
||||||
|
info.getCapabilitiesForType(mime)
|
||||||
|
} catch (_: Exception) {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
if (caps?.isFeatureSupported(MediaCodecInfo.CodecCapabilities.FEATURE_LowLatency) == true) {
|
||||||
|
featureMatch = info.name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (featureMatch != null) {
|
||||||
|
Log.i(TAG, "Sélection décodeur matériel FEATURE_LowLatency : $featureMatch")
|
||||||
|
return MediaCodec.createByCodecName(featureMatch)
|
||||||
|
}
|
||||||
|
return MediaCodec.createDecoderByType(mime)
|
||||||
|
}
|
||||||
|
|
||||||
private fun initCodecLocked(targetSurface: Surface) {
|
private fun initCodecLocked(targetSurface: Surface) {
|
||||||
try {
|
try {
|
||||||
val mc = MediaCodec.createDecoderByType(mimeType)
|
val mc = createBestLowLatencyDecoder(mimeType)
|
||||||
val format = MediaFormat.createVideoFormat(mimeType, 1920, 1080).apply {
|
val format = MediaFormat.createVideoFormat(mimeType, 1280, 720).apply {
|
||||||
setInteger(MediaFormat.KEY_LOW_LATENCY, 1)
|
setInteger(MediaFormat.KEY_LOW_LATENCY, 1)
|
||||||
setInteger(MediaFormat.KEY_PRIORITY, 0) // Temps réel
|
setInteger(MediaFormat.KEY_PRIORITY, 0) // Temps réel
|
||||||
setInteger(MediaFormat.KEY_OPERATING_RATE, Short.MAX_VALUE.toInt())
|
setInteger(MediaFormat.KEY_OPERATING_RATE, Short.MAX_VALUE.toInt())
|
||||||
// Clé matérielle Qualcomm (Snapdragon 8 Gen 1 / Tab S8 Ultra) pour zéro frame buffering
|
// 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-low-latency.enable", 1)
|
||||||
|
setInteger("vendor.qti-ext-dec-picture-order.enable", 1)
|
||||||
}
|
}
|
||||||
mc.configure(format, targetSurface, null, 0)
|
mc.configure(format, targetSurface, null, 0)
|
||||||
mc.start()
|
mc.start()
|
||||||
@@ -93,7 +125,7 @@ class LowLatencyVideoDecoder(private val context: Context) {
|
|||||||
priority = Thread.MAX_PRIORITY
|
priority = Thread.MAX_PRIORITY
|
||||||
start()
|
start()
|
||||||
}
|
}
|
||||||
Log.i(TAG, "MediaCodec démarré ($mimeType, Low-Latency Snapdragon actif)")
|
Log.i(TAG, "MediaCodec démarré (${mc.name}, $mimeType, Low-Latency + Picture-Order actif)")
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.e(TAG, "Échec initialisation MediaCodec ($mimeType): ${e.message}")
|
Log.e(TAG, "Échec initialisation MediaCodec ($mimeType): ${e.message}")
|
||||||
releaseCodecLocked()
|
releaseCodecLocked()
|
||||||
@@ -159,8 +191,8 @@ class LowLatencyVideoDecoder(private val context: Context) {
|
|||||||
try {
|
try {
|
||||||
val outIdx = mc.dequeueOutputBuffer(info, 10_000)
|
val outIdx = mc.dequeueOutputBuffer(info, 10_000)
|
||||||
if (outIdx >= 0) {
|
if (outIdx >= 0) {
|
||||||
// render = true -> affichage immédiat sur SurfaceView sans attente de PTS (latence minimale)
|
// Présentation immédiate sur le tout prochain VSync 120 Hz (zéro attente PTS)
|
||||||
mc.releaseOutputBuffer(outIdx, true)
|
mc.releaseOutputBuffer(outIdx, System.nanoTime())
|
||||||
}
|
}
|
||||||
} catch (_: IllegalStateException) {
|
} catch (_: IllegalStateException) {
|
||||||
break
|
break
|
||||||
|
|||||||
Reference in new issue
Block a user