mirror of
https://github.com/VallierDev/uu-remote-linux.git
synced 2026-11-16 16:50:41 +01:00
One video track carries H.264 or H.265 (RFC 7798 payloader); the host announces its encoders with CONTROL Message 18 CodecNegotiation and picks H.265 when the viewer negotiated it (the official Mac viewer offers H265 first; CaptureSettingRequest field 13 only reports the current codec). hevc_nvenc / libx265 / hevc_vaapi with fallback to software HEVC, then H.264; UU_VIDEO_CODEC=h264 forces H.264. True color 4:4:4 applies to H.265. Verified with the official Mac viewer on NVENC. Co-Authored-By: Claude Opus 5.5 <[email protected]>
88 lines
3.8 KiB
Rust
88 lines
3.8 KiB
Rust
//! Wire payloads reconstructed from the official libstreamer ARM64 serializers.
|
|
//! See analysis/protocol-fix-20261013/datachannel for address-bound evidence.
|
|
//! These payloads do not claim server acceptance or invent missing handshake steps.
|
|
|
|
use serde_json::{json, Value};
|
|
|
|
pub const ICE_FINISHED_EVENT: &str = "ice_finished_log";
|
|
pub const FORWARD_SETTING_EVENT: &str = "forward_setting";
|
|
pub const VIDEO_CODEC_H264: i32 = 1;
|
|
pub const CODEC_IMPL_NVENC: i32 = 0;
|
|
|
|
/// Official serializer emits exactly two string fields (0x107190).
|
|
/// The event is telemetry emitted for official pc::State 6; it is not an ACK.
|
|
pub fn ice_finished(ice_id: &str, app_control_id: &str) -> Value {
|
|
json!({"ice_id": ice_id, "app_control_id": app_control_id})
|
|
}
|
|
|
|
/// Supply the stable id of a display that this host can actually capture.
|
|
/// Official Mac display construction uses type 0 and HDR disabled value 0.
|
|
/// `codec_impl` is caller-selected: the observed names are 0 NVENC, 1 AMD AMF,
|
|
/// 2 Intel QSV, 3 VideoToolbox, 4 MediaCodec; values >=5 log as SoftWare.
|
|
/// Using 5 as software is an inference and must be runtime-validated by caller.
|
|
pub fn h264_device_capability(
|
|
client_id: &str,
|
|
ice_id: &str,
|
|
display_id: i32,
|
|
fps: i32,
|
|
codec_impl: i32,
|
|
) -> Value {
|
|
device_capability(client_id, ice_id, display_id, fps, codec_impl, false)
|
|
}
|
|
|
|
pub fn device_capability(client_id: &str, ice_id: &str, display_id: i32, fps: i32, codec_impl: i32, hevc: bool) -> Value {
|
|
let mut codecs = vec![json!({"video_codec": VIDEO_CODEC_H264, "chroma_sampling": 1,
|
|
"codec_impl": codec_impl, "bit_depth": 8})];
|
|
// Official VideoCodecCapability::SerializeJson uses the same fields for CodecType H265=2.
|
|
if hevc { codecs.push(json!({"video_codec": 2, "chroma_sampling": 1, "codec_impl": codec_impl, "bit_depth": 8})); }
|
|
json!({
|
|
"client_id": client_id,
|
|
"type": "device_capability",
|
|
"data": {
|
|
"display_info": [{"id": display_id, "fps": fps, "type": 0, "hdr": 0}],
|
|
"video_codec_capability": codecs,
|
|
"ice_id": ice_id
|
|
}
|
|
})
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn hevc_capability_uses_official_codec_enum_and_420_only() {
|
|
let payload = device_capability("client-example", "ice-example", 0, 60, 5, true);
|
|
assert_eq!(payload["data"]["video_codec_capability"], json!([
|
|
{"video_codec":1,"chroma_sampling":1,"codec_impl":5,"bit_depth":8},
|
|
{"video_codec":2,"chroma_sampling":1,"codec_impl":5,"bit_depth":8}]));
|
|
assert_eq!(device_capability("c", "i", 0, 60, 5, false)["data"]["video_codec_capability"].as_array().unwrap().len(), 1);
|
|
}
|
|
|
|
#[test]
|
|
fn ice_finished_keeps_string_identifiers_and_exact_fields() {
|
|
let payload = ice_finished("ice-example", "control-example");
|
|
assert_eq!(payload.as_object().unwrap().len(), 2);
|
|
assert!(payload["ice_id"].is_string());
|
|
assert_eq!(payload["app_control_id"], "control-example");
|
|
assert_eq!(ICE_FINISHED_EVENT, "ice_finished_log");
|
|
}
|
|
|
|
#[test]
|
|
fn device_capability_uses_object_data_and_string_ice_id() {
|
|
let payload = h264_device_capability("client-example", "ice-example", 11, 60, 0);
|
|
assert_eq!(payload["type"], "device_capability");
|
|
assert!(payload["data"].is_object());
|
|
assert_eq!(payload["data"]["ice_id"], "ice-example");
|
|
let display = &payload["data"]["display_info"][0];
|
|
assert_eq!(display.as_object().unwrap().len(), 4);
|
|
assert_eq!(display["id"], 11);
|
|
assert_eq!(display["fps"], 60);
|
|
let codec = &payload["data"]["video_codec_capability"][0];
|
|
assert_eq!(codec.as_object().unwrap().len(), 4);
|
|
assert_eq!(codec["video_codec"], 1);
|
|
assert_eq!(codec["codec_impl"], 0);
|
|
assert_eq!(codec["bit_depth"], 8);
|
|
}
|
|
}
|