mirror of
https://github.com/bleackstorm/SteamFrame-FPV-Control-Center.git
synced 2026-12-03 07:31:57 +01:00
Merge pull request #18 from bleackstorm/feat/radxa-dhcp-python-and-raw-nal
Feat/radxa dhcp python and raw nal
This commit is contained in:
6 files changed
+137
-19
No files matched your search
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
<uses-permission android:name="android.permission.INTERNET" />
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||||
|
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
|
|||||||
@@ -1,6 +1,11 @@
|
|||||||
package com.steamframe.fpv
|
package com.steamframe.fpv
|
||||||
|
|
||||||
|
import android.net.ConnectivityManager
|
||||||
|
import android.net.Network
|
||||||
|
import android.net.NetworkCapabilities
|
||||||
|
import android.net.NetworkRequest
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.util.Log
|
||||||
import android.view.Surface
|
import android.view.Surface
|
||||||
import android.view.WindowManager
|
import android.view.WindowManager
|
||||||
import androidx.activity.ComponentActivity
|
import androidx.activity.ComponentActivity
|
||||||
@@ -20,6 +25,8 @@ import java.util.Locale
|
|||||||
|
|
||||||
class MainActivity : ComponentActivity() {
|
class MainActivity : ComponentActivity() {
|
||||||
private lateinit var decoder: LowLatencyVideoDecoder
|
private lateinit var decoder: LowLatencyVideoDecoder
|
||||||
|
private lateinit var connectivityManager: ConnectivityManager
|
||||||
|
private var ethCallback: ConnectivityManager.NetworkCallback? = null
|
||||||
private var nativeHandle: Long = 0L
|
private var nativeHandle: Long = 0L
|
||||||
private var currentSurface: Surface? = null
|
private var currentSurface: Surface? = null
|
||||||
|
|
||||||
@@ -65,6 +72,8 @@ class MainActivity : ComponentActivity() {
|
|||||||
hideSystemBars()
|
hideSystemBars()
|
||||||
|
|
||||||
decoder = LowLatencyVideoDecoder(applicationContext)
|
decoder = LowLatencyVideoDecoder(applicationContext)
|
||||||
|
connectivityManager = getSystemService(ConnectivityManager::class.java)
|
||||||
|
bindEthernetNetwork()
|
||||||
restartNativeEngine()
|
restartNativeEngine()
|
||||||
|
|
||||||
setContent {
|
setContent {
|
||||||
@@ -175,7 +184,47 @@ class MainActivity : ComponentActivity() {
|
|||||||
}.start()
|
}.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun bindEthernetNetwork() {
|
||||||
|
try {
|
||||||
|
// Sur Android 12+, une interface Ethernet USB sans Internet n'est pas routée par défaut :
|
||||||
|
// on force le processus sur TRANSPORT_ETHERNET pour que les sockets UDP Rust joignent 192.168.1.1 même Wi-Fi allumé.
|
||||||
|
val req = NetworkRequest.Builder()
|
||||||
|
.addTransportType(NetworkCapabilities.TRANSPORT_ETHERNET)
|
||||||
|
.removeCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
|
||||||
|
.build()
|
||||||
|
val cb = object : ConnectivityManager.NetworkCallback() {
|
||||||
|
override fun onAvailable(network: Network) {
|
||||||
|
val ok = connectivityManager.bindProcessToNetwork(network)
|
||||||
|
Log.i("SteamFrameFPV", "Ethernet USB lié au processus (bindProcessToNetwork=$ok)")
|
||||||
|
runOnUiThread {
|
||||||
|
pingStatus = if (ok) "ETH USB OK" else "ETH bind fail"
|
||||||
|
restartNativeEngine()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onLost(network: Network) {
|
||||||
|
connectivityManager.bindProcessToNetwork(null)
|
||||||
|
Log.i("SteamFrameFPV", "Ethernet USB déconnecté")
|
||||||
|
runOnUiThread {
|
||||||
|
pingStatus = "ETH déconnecté"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ethCallback = cb
|
||||||
|
connectivityManager.requestNetwork(req, cb)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.w("SteamFrameFPV", "Impossible de lier TRANSPORT_ETHERNET : ${e.message}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
|
ethCallback?.let {
|
||||||
|
try {
|
||||||
|
connectivityManager.unregisterNetworkCallback(it)
|
||||||
|
} catch (_: Exception) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
connectivityManager.bindProcessToNetwork(null)
|
||||||
stopNativeEngine()
|
stopNativeEngine()
|
||||||
decoder.release()
|
decoder.release()
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
|
|||||||
Executable
+53
@@ -0,0 +1,53 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# Configure un gadget USB Ethernet CDC-ECM pur (0525:a4a1, sans port série ACM)
|
||||||
|
# avec une MAC administrée globalement (00:1a:11:f0:00:02) afin que le noyau
|
||||||
|
# Samsung / Android nomme l'interface `eth0` (reconnue nativement par One UI)
|
||||||
|
# tout en restant 100 % compatible Linux / SteamOS (Steam Frame).
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
GADGET_DIR="/sys/kernel/config/usb_gadget/steamframe_ecm"
|
||||||
|
UDC_NAME="$(ls /sys/class/udc | head -n 1 || true)"
|
||||||
|
|
||||||
|
setup_configfs_ecm() {
|
||||||
|
[ -n "${UDC_NAME}" ] || return 1
|
||||||
|
modprobe usb_f_ecm || return 1
|
||||||
|
mountpoint -q /sys/kernel/config || mount -t configfs none /sys/kernel/config
|
||||||
|
|
||||||
|
if [ -d "${GADGET_DIR}" ] && [ -s "${GADGET_DIR}/UDC" ]; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
mkdir -p "${GADGET_DIR}"
|
||||||
|
cd "${GADGET_DIR}"
|
||||||
|
echo 0x0525 > idVendor
|
||||||
|
echo 0xa4a1 > idProduct
|
||||||
|
echo 0x0100 > bcdDevice
|
||||||
|
echo 0x0200 > bcdUSB
|
||||||
|
echo 0x00 > bDeviceClass
|
||||||
|
echo 0x00 > bDeviceSubClass
|
||||||
|
echo 0x00 > bDeviceProtocol
|
||||||
|
|
||||||
|
mkdir -p strings/0x409
|
||||||
|
echo "SF-RADXA-001" > strings/0x409/serialnumber
|
||||||
|
echo "SteamFrame FPV" > strings/0x409/manufacturer
|
||||||
|
echo "Radxa VRX USB Ethernet" > strings/0x409/product
|
||||||
|
|
||||||
|
mkdir -p configs/c.1/strings/0x409
|
||||||
|
echo "CDC-ECM Ethernet" > configs/c.1/strings/0x409/configuration
|
||||||
|
echo 250 > configs/c.1/MaxPower
|
||||||
|
|
||||||
|
mkdir -p functions/ecm.usb0
|
||||||
|
# Bit 1 du 1er octet = 0 (MAC globale) : indispensable pour que cdc_ether sur Android nomme l'interface eth0
|
||||||
|
echo "00:1a:11:f0:00:02" > functions/ecm.usb0/host_addr
|
||||||
|
echo "00:1a:11:f0:00:01" > functions/ecm.usb0/dev_addr
|
||||||
|
|
||||||
|
ln -sf functions/ecm.usb0 configs/c.1/ecm.usb0
|
||||||
|
echo "${UDC_NAME}" > UDC
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
if ! setup_configfs_ecm; then
|
||||||
|
echo "[usb0-gadget] Fallback vers g_cdc" >&2
|
||||||
|
modprobe g_cdc || true
|
||||||
|
fi
|
||||||
+10
-1
@@ -800,8 +800,17 @@ pub fn compose_osd_and_publish(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// En mode Bureau (sans OpenXR), pousser chaque nouvelle trame immédiatement (<= 4 ms)
|
||||||
|
// pour éliminer le bridage artificiel à 30 Hz (33 ms). En VR OpenXR, garder 33 ms pour
|
||||||
|
// ne pas voler de bande passante GPU au casque.
|
||||||
|
let preview_min_interval = if render_cpu_osd {
|
||||||
|
Duration::from_millis(4)
|
||||||
|
} else {
|
||||||
|
Duration::from_millis(33)
|
||||||
|
};
|
||||||
let push_preview = ctx.control.is_preview_active()
|
let push_preview = ctx.control.is_preview_active()
|
||||||
&& last_preview_push.is_none_or(|t| t.elapsed() >= Duration::from_millis(33));
|
&& (has_new_raw_frame || !has_video_stream)
|
||||||
|
&& last_preview_push.is_none_or(|t| t.elapsed() >= preview_min_interval);
|
||||||
|
|
||||||
if push_preview || fps_timer.elapsed() >= Duration::from_secs(1) || frame_received_at.is_some() {
|
if push_preview || fps_timer.elapsed() >= Duration::from_secs(1) || frame_received_at.is_some() {
|
||||||
if push_preview || fps_timer.elapsed() >= Duration::from_secs(1) {
|
if push_preview || fps_timer.elapsed() >= Duration::from_secs(1) {
|
||||||
|
|||||||
+1
-1
@@ -1114,7 +1114,7 @@ pub fn run_gpui_app(cfg: AppConfig, log_buffer: Arc<Mutex<LogBuffer>>) -> Result
|
|||||||
window
|
window
|
||||||
.spawn(cx, async move |cx| {
|
.spawn(cx, async move |cx| {
|
||||||
loop {
|
loop {
|
||||||
Timer::after(Duration::from_millis(16)).await;
|
Timer::after(Duration::from_millis(8)).await;
|
||||||
let should_continue = cx
|
let should_continue = cx
|
||||||
.update(|window, cx| {
|
.update(|window, cx| {
|
||||||
if let Some(view) = weak_view.upgrade() {
|
if let Some(view) = weak_view.upgrade() {
|
||||||
|
|||||||
+23
-17
@@ -98,12 +98,16 @@ pub struct FrameMailbox {
|
|||||||
ready_meta: Option<TakenFrameMeta>,
|
ready_meta: Option<TakenFrameMeta>,
|
||||||
spare_buf: Vec<u8>,
|
spare_buf: Vec<u8>,
|
||||||
dmabuf_ready: Option<DmaBufFrame>,
|
dmabuf_ready: Option<DmaBufFrame>,
|
||||||
|
/// Horodatage de la dernière trame publiée (conservé même après consommation par l'UI/VR
|
||||||
|
/// pour éviter les faux positifs "Signal vidéo perdu" entre deux trames).
|
||||||
|
last_received_at: Option<Instant>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FrameMailbox {
|
impl FrameMailbox {
|
||||||
/// Publie un buffer rempli hors verrou en l'échangeant en O(1) contre `spare_buf`.
|
/// Publie un buffer rempli hors verrou en l'échangeant en O(1) contre `spare_buf`.
|
||||||
fn publish(&mut self, incoming: &mut Vec<u8>, meta: TakenFrameMeta) {
|
fn publish(&mut self, incoming: &mut Vec<u8>, meta: TakenFrameMeta) {
|
||||||
std::mem::swap(&mut self.ready_buf, incoming);
|
std::mem::swap(&mut self.ready_buf, incoming);
|
||||||
|
self.last_received_at = Some(meta.received_at);
|
||||||
self.ready_meta = Some(meta);
|
self.ready_meta = Some(meta);
|
||||||
self.dmabuf_ready = None;
|
self.dmabuf_ready = None;
|
||||||
// Maintenir `incoming` prêt avec le tampon précédent réutilisable
|
// Maintenir `incoming` prêt avec le tampon précédent réutilisable
|
||||||
@@ -114,6 +118,7 @@ impl FrameMailbox {
|
|||||||
|
|
||||||
/// Publie une trame DMA-BUF zéro-copie (sans aucune copie pixel côté CPU).
|
/// Publie une trame DMA-BUF zéro-copie (sans aucune copie pixel côté CPU).
|
||||||
fn publish_dmabuf(&mut self, dmabuf: DmaBufFrame) {
|
fn publish_dmabuf(&mut self, dmabuf: DmaBufFrame) {
|
||||||
|
self.last_received_at = Some(dmabuf.received_at);
|
||||||
self.dmabuf_ready = Some(dmabuf);
|
self.dmabuf_ready = Some(dmabuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,10 +128,10 @@ impl FrameMailbox {
|
|||||||
last_frame_id: u64,
|
last_frame_id: u64,
|
||||||
max_age: Duration,
|
max_age: Duration,
|
||||||
) -> (bool, Option<DmaBufFrame>) {
|
) -> (bool, Option<DmaBufFrame>) {
|
||||||
|
let is_live = self.is_live(max_age);
|
||||||
let Some(ref d) = self.dmabuf_ready else {
|
let Some(ref d) = self.dmabuf_ready else {
|
||||||
return (false, None);
|
return (is_live, None);
|
||||||
};
|
};
|
||||||
let is_live = d.received_at.elapsed() < max_age;
|
|
||||||
if !is_live || d.frame_id == last_frame_id {
|
if !is_live || d.frame_id == last_frame_id {
|
||||||
return (is_live, None);
|
return (is_live, None);
|
||||||
}
|
}
|
||||||
@@ -141,10 +146,10 @@ impl FrameMailbox {
|
|||||||
last_frame_id: u64,
|
last_frame_id: u64,
|
||||||
max_age: Duration,
|
max_age: Duration,
|
||||||
) -> (bool, Option<TakenFrameMeta>) {
|
) -> (bool, Option<TakenFrameMeta>) {
|
||||||
|
let is_live = self.is_live(max_age);
|
||||||
let Some(meta) = self.ready_meta else {
|
let Some(meta) = self.ready_meta else {
|
||||||
return (false, None);
|
return (is_live, None);
|
||||||
};
|
};
|
||||||
let is_live = meta.received_at.elapsed() < max_age;
|
|
||||||
if !is_live || meta.frame_id == last_frame_id {
|
if !is_live || meta.frame_id == last_frame_id {
|
||||||
return (is_live, None);
|
return (is_live, None);
|
||||||
}
|
}
|
||||||
@@ -154,12 +159,8 @@ impl FrameMailbox {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_live(&self, max_age: Duration) -> bool {
|
pub fn is_live(&self, max_age: Duration) -> bool {
|
||||||
self.ready_meta
|
self.last_received_at
|
||||||
.is_some_and(|m| m.received_at.elapsed() < max_age)
|
.is_some_and(|t| t.elapsed() < max_age)
|
||||||
|| self
|
|
||||||
.dmabuf_ready
|
|
||||||
.as_ref()
|
|
||||||
.is_some_and(|d| d.received_at.elapsed() < max_age)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -459,14 +460,14 @@ fn select_best_decoder(is_h264: bool, allow_hw: bool) -> (&'static str, &'static
|
|||||||
let candidates: &[(&str, &str)] = if is_h264 {
|
let candidates: &[(&str, &str)] = if is_h264 {
|
||||||
&[
|
&[
|
||||||
("v4l2h264dec", "v4l2h264dec"),
|
("v4l2h264dec", "v4l2h264dec"),
|
||||||
("vah264dec", "vah264dec"),
|
("vah264dec", "vah264dec compliance=flexible"),
|
||||||
("vaapih264dec", "vaapih264dec"),
|
("vaapih264dec", "vaapih264dec low-latency=true"),
|
||||||
]
|
]
|
||||||
} else {
|
} else {
|
||||||
&[
|
&[
|
||||||
("v4l2h265dec", "v4l2h265dec"),
|
("v4l2h265dec", "v4l2h265dec"),
|
||||||
("vah265dec", "vah265dec"),
|
("vah265dec", "vah265dec"),
|
||||||
("vaapih265dec", "vaapih265dec"),
|
("vaapih265dec", "vaapih265dec low-latency=true"),
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
for &(factory_name, elem_desc) in candidates {
|
for &(factory_name, elem_desc) in candidates {
|
||||||
@@ -478,12 +479,12 @@ fn select_best_decoder(is_h264: bool, allow_hw: bool) -> (&'static str, &'static
|
|||||||
if is_h264 {
|
if is_h264 {
|
||||||
(
|
(
|
||||||
"avdec_h264",
|
"avdec_h264",
|
||||||
"avdec_h264 max-threads=2 discard-corrupted-frames=true",
|
"avdec_h264 max-threads=2 thread-type=slice output-corrupt=true",
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
(
|
(
|
||||||
"avdec_h265",
|
"avdec_h265",
|
||||||
"avdec_h265 max-threads=2 discard-corrupted-frames=true",
|
"avdec_h265 max-threads=2 thread-type=slice output-corrupt=true",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -509,9 +510,9 @@ fn pipeline_description_with_decoder(p: &PipelineParams, decoder_desc: &str) ->
|
|||||||
"h265parse name=nal_parser"
|
"h265parse name=nal_parser"
|
||||||
};
|
};
|
||||||
let stream_caps = if is_h264 {
|
let stream_caps = if is_h264 {
|
||||||
"video/x-h264,stream-format=byte-stream"
|
"video/x-h264,stream-format=byte-stream,alignment=au"
|
||||||
} else {
|
} else {
|
||||||
"video/x-h265,stream-format=byte-stream"
|
"video/x-h265,stream-format=byte-stream,alignment=au"
|
||||||
};
|
};
|
||||||
let codec_name = if is_h264 { "H264" } else { "H265" };
|
let codec_name = if is_h264 { "H264" } else { "H265" };
|
||||||
let depay = if is_h264 { "rtph264depay" } else { "rtph265depay" };
|
let depay = if is_h264 { "rtph264depay" } else { "rtph265depay" };
|
||||||
@@ -1205,6 +1206,11 @@ mod tests {
|
|||||||
assert_eq!(taken.unwrap().frame_id, 1);
|
assert_eq!(taken.unwrap().frame_id, 1);
|
||||||
assert_eq!(consumer.len(), 64);
|
assert_eq!(consumer.len(), 64);
|
||||||
assert_eq!(consumer[0], 42);
|
assert_eq!(consumer[0], 42);
|
||||||
|
// Après consommation, le flux doit rester "live" tant que max_age n'est pas dépassé
|
||||||
|
assert!(mb.is_live(Duration::from_secs(1)));
|
||||||
|
let (live2, taken2) = mb.take_if_newer(&mut consumer, 1, Duration::from_secs(1));
|
||||||
|
assert!(live2);
|
||||||
|
assert!(taken2.is_none());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
Reference in new issue
Block a user