Compare commits

...
57 Commits
Author SHA1 Message Date
spoopyghosty0 8167cb86c6 Merge the shared hardware video decoder (PR #128, adapted: per game, off switch, VP9 fixes)
# Conflicts:
#	agent/frameport_agent.py
2026-10-10 02:25:41 -04:00
spoopyghosty0 44bc689348 Shared video decoder (codec revision 8): hidden VP9 frames no longer end the EOS drain early
Iris returns an empty capture buffer (bytesused 0, no LAST flag, time 0) for every VP9 frame that isn't shown
(alt-ref frames split from superframes). FFmpeg's V4L2 wrapper takes any empty capture buffer during a drain
for the end of the stream, so the first hidden frame decoded after EOS ended it and the pictures still in the
driver were lost (two-pass VP9 4K: 573/600 and 617/640, always the last frames); outside a drain the empty
buffers were returned as pictures, which the component then guessed away by counting hidden frames.
build.py now patches v4l2_context.c to requeue empty capture buffers without LAST/ERROR; the drain ends at the
LAST buffer, or after a skipped empty buffer at one silent second, so it can't block. The component's
hidden-frame counting is removed. Dev Frame (Batman's container): two-pass VP9 4K 600/600 and 640/640 in
hardware with the same Y hashes as OMX.google.vp9.decoder (seek phase too), VP9 without hidden frames,
H.264 4K and HEVC 4K 600/600, VP9 surface output 600/600. Two builds (different dirs and NDK copies) give the
same libstagefrighthw.so 141de01f.
2026-10-10 02:22:48 -04:00
spoopyghosty0 007db344d7 Shared video decoder: remove a game's old per-game codec folder once its launcher is converted, also when the recipe (not deployment.json) asks for hardware decoding (seen with Batman on the dev Frame) 2026-10-10 01:01:33 -04:00
spoopyghosty0 3fb2621030 Shared video decoder: per game (frame.hw_video_decode) with a global off switch; 8K retry at start and VP9 fixes from the hw-video-decode branch
- Opt-in per game: only launchers of games whose recipe has frame.hw_video_decode (install stage, no APK change;
  suggested from analysis media_codec, ANALYSIS_VERSION 8) get the codec line (deployment.json hw_video_decode,
  finalize + upgrade_launchers). Games that had agent 70's per-game codec (Batman) keep it; their old
  <base>/frameport-codec folders are removed afterwards. Batman: catalog + migration batman_video_patches
  (frame.hw_video_decode + the hidden adapter setting surface_native, no more package check); 4XVR catalog.
- Off switch: Settings -> Installing "Hardware video decoding" (library video.hw_decode, default on) -> agent
  video_codec_switch (video-codec/disabled, checked by the launcher line and the wrapper); FRAMEPORT_NO_HW_VIDEO=1
  for one game.
- Connection: the codec is checked once per connection, also after a failed install; a Frame keeps the same or a
  newer revision built elsewhere (logged) instead of flip-flopping between PCs.
- Wrapper: the merged media_codecs.xml goes to $XDG_RUNTIME_DIR/frameport-video, never into the version directory.
- Decoder: refused (busy) Iris sessions retry until 20 s after the plugin loaded (SteamVR's link holds a session
  ~12 s at game start), else 2 s, before the software fallback; VP9 capped at 4096x2304 (XML + component, larger
  decodes in software); hidden VP9 frames' pictures dropped. Manifest revision 7.
- build.py builds from paths with spaces and from freshly extracted FFmpeg sources. Artifacts rebuilt here, identical
  from two trees (ext4 and the NTFS repo path, two NDK copies); PR #128's own sources rebuild to its binary.
- AGENT_VERSION 71 (matches the connection's gate); triage hw-video-decoder-busy, PLAYBOOK row, docs.
2026-10-10 00:58:24 -04:00
spoopyghosty0 39ca9a5f0d Catalog: Audica works (shared working config)
Closes #126
2026-10-10 00:28:39 -04:00
spoopyghosty0 e64e8a95e0 Uninstall dialog: option to also delete the game's saves and everything it stored on the Frame (mods, downloads); they survived every uninstall before (GitHub #130) 2026-10-10 00:28:37 -04:00
spoopyghosty0 69e888c7fe Install on this PC works on Windows again: the agent (loaded for its VDF code) imported the POSIX-only fcntl at the top (ModuleNotFoundError for every PC VR install; GitHub #131) 2026-10-10 00:28:36 -04:00
spoopyghosty0 ce809c432d Merge PR #128: shared hardware video decoding (Lucas-Mathieu) 2026-10-10 00:23:42 -04:00
Lucas-Mathieu 26cee1551e Deploy shared hardware video decoding for compatible Lepton apps 2026-10-10 03:36:56 +02:00
spoopyghosty0 f812ea8716 Codec wrapper (PR #96): find the host's podman when Lepton calls it with the Android guest's PATH (its boot-wait, app-pid and logcat-mirror podman exec calls failed, so launch.log lost logcat and the container could be stopped early) 2026-10-09 17:54:44 -04:00
spoopyghosty0 3dc0a95379 Catalog: Doom3Quest uses frame.gl_multiview_fbo (HUD/PDA shown, no frame-rate drop: Xandrix1987's headset test, GitHub #77) 2026-10-09 16:30:33 -04:00
spoopyghosty0 f8244f582d Catalog: cubism works (shared working config)
Closes #121
2026-10-09 16:29:36 -04:00
spoopyghosty0 69fbdfdc4a SUPERHOT VR (Quest): create its cloud save folder at install, so the launcher gives it group write permission before the very first start (the game creates and checks it in the same millisecond; GitHub #120); triage text says to start again 2026-10-09 16:29:34 -04:00
spoopyghosty0 ef3272a31b Catalog: Vader Immortal III's campaign intro starts black by design (owner) 2026-10-09 15:04:18 -04:00
spoopyghosty0 b0f3ef2698 Catalog: Vader Immortal Episodes II and III work (owner's headset test) with Episode I's Unreal fixes (quest precompile, key map, thumb touch, pose_time_fix), all found in their code by the heuristics 2026-10-09 14:37:11 -04:00
spoopyghosty0 1711e7f7d9 Docs: session triage (PLAYBOOK rows for the session findings, CLAUDE.md note incl. the pac_hints survey) 2026-10-09 14:22:22 -04:00
spoopyghosty0 ff6cdf3b6a Triage real play sessions: the connection refresh fetches a finished session's log (agent v70) and triages it (launch-test signatures + new space-warp-used question and gpu-hang, find_rp_state for unreal-msrtt-crash, slow-frames from FrameBridge pacing, focus-dips), stored as last_session; game page "Last session" callout; value suggestions (adapter.key=value); FrameBridge-only fixes applied live via set_settings; CLI frameport session [--apply] 2026-10-09 14:22:20 -04:00
spoopyghosty0 28517a1999 Agent v70: session_log (the newest play session's launch.log sliced to 4 MB + its crash logcat + kernel GPU hang lines), last_play in list_installed, launch tests mark their session in plays.log 2026-10-09 14:22:17 -04:00
spoopyghosty0 af9c207ddf FrameBridge: always log the runtime's focus losses and returns with their length (focus: lost / back after N ms), before focus_hold hides a dip; for session triage 2026-10-09 14:03:23 -04:00
spoopyghosty0 88045bcf4e Merge remote-tracking branch 'origin/main' into merge/pr96 2026-10-09 13:43:24 -04:00
spoopyghosty0 5147710fad Merge Batman cutscene playback (hardware HEVC decoding, stereo composition) by Lucas-Mathieu (GitHub #96)
Adapter rebuilt here; the codec plugin rebuilt here with native/hevc/build.py (NDK r27c, Lepton SoftOMX fingerprint 456e912c) is byte-identical to the contributed one (c1c2a73e). Agent version 70 -> 69 (main was at 68).
2026-10-09 13:43:22 -04:00
spoopyghosty0 9c45cff09a Heuristics: suggest pose_time_fix for Unreal 4 games with Vader Immortal's Oculus input (the unreal_thumb_touch code match). Catalog: Phantom, Robo Recall and Time Stall get frame.unreal_thumb_touch + pose_time_fix (their code matches Vader's; not yet checked in these games), Star Wars: Tales gets frame.unreal_thumb_touch instead of proximity_emul (as Vader) 2026-10-09 13:43:07 -04:00
Lucas-Mathieu b4848c0424 Harden codec deployment and isolate native video hooks 2026-10-09 19:24:51 +02:00
spoopyghosty0 3a46b78361 Catalog: Clockwork (Quest), Beat Saber, Eleven: Table Tennis VR and Pistol Whip (PC VR, run directly without Revive) from shared working configs
Closes #116, closes #117, closes #118, closes #119
2026-10-09 13:21:50 -04:00
spoopyghosty0 75bbc6eb5f Heuristics: suggest scene_emul for every game that declares Meta's USE_SCENE permission, not only mixed-reality-only ones (VR HOT's room setup retried forever: LoadSceneModel failed / no XR_FB_spatial_entity_query; with scene_emul the room setup returned without errors). Catalog recipes still win (6 verified games declare USE_SCENE and run without it) 2026-10-09 13:06:44 -04:00
Lucas-Mathieu da638aea99 Merge remote-tracking branch 'origin/main' into fix/batman-cutscene-playback
# Conflicts:
#	agent/frameport_agent.py
#	artifacts/SHA256SUMS
#	artifacts/arm64-v8a/libopenxr_loader_generic.so
#	artifacts/armeabi-v7a/libopenxr_loader_generic.so
#	native/adapter/frame_adapter.c
2026-10-09 18:29:12 +02:00
spoopyghosty0 7c37b479db Agent v68: launch tests count their window from Lepton's 'Waiting for app' (up to 240 s more for boot + install). The first start after an APK change installs the app first; a 45 s window from the launcher stopped the container mid-install and left a broken installed APK ('base.apk is not zip') that never started again (VR HOT) 2026-10-09 11:58:54 -04:00
spoopyghosty0 fa473c5ada frame.unreal_thumb_touch: UE4 OculusInput's ThumbUp from the capacitive touches instead of near-touch, which the Frame never reports (thumbs always pointed up). Three instructions in SendControllerEvents (masks 0x2/0x8 -> 0x0f00/0x000f, NearTouches load -> Touches), matched exactly; suggested where the code matches (analysis unreal_thumb_touch, ANALYSIS_VERSION 7): Vader Immortal Ep. I, Robo Recall, Phantom: Covert Ops, Time Stall, Star Wars: Tales. Vader's recipe uses it instead of proximity_emul (the binding didn't animate the thumbs). Found by Klownicle, GitHub #49 2026-10-09 11:35:36 -04:00
spoopyghosty0 1e6ce04e4f pose_time_fix: never move a recent predicted display time; monotonic times only told apart when the clocks are more than 4 display periods apart and the time is clearly nearer the monotonic now (GitHub #49: on a Frame with XrTime only ~68 ms ahead of CLOCK_MONOTONIC, a request at the frame's display time after a hitch was taken for a monotonic time and moved +67.7 ms). Found by Klownicle, GitHub #49 2026-10-09 11:35:35 -04:00
spoopyghosty0 5cd5b119e7 Lint: extraneous parentheses (ruff UP034) 2026-10-09 11:33:00 -04:00
spoopyghosty0 186138cc3c Game page: a patch the build left out because the OVRPort runtime already has the fix (build.superseded, e.g. haptic_fix with runtime 3.4.3-aa54c3f) no longer counts as a settings change: 'Update on Frame' stayed after every update (owner's VR HOT, Klownicle's Vader, GitHub #49) 2026-10-09 11:32:40 -04:00
spoopyghosty0 98c7ca980a Triage: Lepton's own short lines survive the game-process filter. With the package known, game_lines dropped every line of 3 words or fewer, so Lepton's 'Boot complete!' vanished and the transient 'is not a running context' failed launch tests in the GUI although the games ran (owner's runs: Come Closer, AntiZeroGames CH, SKYBOX; Klownicle's Vader, GitHub #49). Only logcat lines are filtered by pid now 2026-10-09 11:29:12 -04:00
spoopyghosty0 b2470b962a Catalog: Max Mustard is listed by its name, not its package name Matilda (GitHub #110) 2026-10-09 11:10:09 -04:00
spoopyghosty0 2a705bc6d1 frame.gl_multiview_fbo: single-view twins for multiview programs drawn into flat framebuffers (GitHub #77)
Mesa enforces OVR_multiview's rule that a draw's program declares as many views as the draw framebuffer has and drops the draw silently; Doom3Quest compiles every vertex shader with layout(num_views=2) and draws its HUD/PDA into 2D-texture FBOs, which stay black on the Frame.

native/glmv (libfpglmv.so, same length as libGLESv3.so): the engine library's dlopen string is rewritten to it and it becomes the first DT_NEEDED. It records stage sources at link time and, when a multiview program draws into a framebuffer without views, draws with a lazily built single-view twin (num_views layout blanked, gl_ViewID_OVR -> 0u; attribute locations, block bindings and uniform values copied), then rebinds the original. Opt-in and experimental (analysis gl_multiview_libs, ANALYSIS_VERSION 6), setting gl_mv_debug, triage gl-multiview-twin-failed.

Host tests: the rewriter on Doom3Quest's 19 shaders (GPL-3.0 fixtures) and glmv.c against a stand-in GL that applies Mesa's rule. Untested on the device.
2026-10-09 10:54:40 -04:00
spoopyghosty0 5d44831757 Agent v67: keep launch.log filling when Lepton's logcat mirror dies ('logcat: Unexpected EOF!' right after the game starts, about 1 launch in 50: Vader Immortal on Lepton 3.0.5, Under Cover on 2.8.14). launch.sh starts _logcat_keeper, which then reads the container's logcat itself (podman exec ... logcat -T 2000, up to 5 restarts) so the dashboard auto-hide and launch tests see the game; upgrade_launchers adds it to existing launchers 2026-10-09 10:14:57 -04:00
spoopyghosty0 456880501b PC VR: a catalog recipe verified with another build (different VR APIs) keeps the build's own launch arguments; Electron launchers rank below the game; agent v67 collects Unity's Player.log / output_log.txt / crash error.log for launch tests and diagnostics; triage unity-vr-init and unity-crash (GitHub #105) 2026-10-09 10:10:33 -04:00
spoopyghosty0 63f7ae12e1 Catalog: Vader Immortal: Episode I works (owner's headset test of the GitHub #49 fixes by Klownicle) 2026-10-09 10:06:44 -04:00
spoopyghosty0 fa69ffefd2 Vader Immortal: loading card, controls, lightspeed shaders, thumbs (GitHub #49)
Klownicle's five fixes for Vader Immortal: Episode I, reimplemented as FramePort patches (found by Klownicle,
GitHub #49; their prebuilt APK is not used):

- frame.unreal_quest_precompile: UVRUtils::GetQuestShaderPrecompilePercent returned 0.0 on its non-Quest branch, so
  the menu waited forever on the loading card; that branch now returns 1.0. Located by symbol, every instruction
  around it checked (bl IsRunningOnSantaCruz; tbz w0,#0; fmov s0,wzr; ldp; ret); other builds stay untouched.
- frame.unreal_quest_keymap: the RPOC key selector (shared by AddAxisMapping and AddActionMapping, so both mapping
  kinds were affected) picked the empty Gear VR key set for an Oculus HMD; the tbz to it becomes a nop. Located as
  the common callee of both functions, pattern-checked.
- frame.zink_shader_fix + native/zinkfix (libVkLayer_fp_shaderfix.so): a Vulkan layer under Zink for GLES games
  that applies zink_shader_fix entries (vk_shader_fix format) to the SPIR-V Zink generates; it adds itself to
  GraphicsEnv's debug layer list from a constructor (the engine library loads it first). zink_shader_dump=1
  captures modules. Vader's recipe carries the two lightspeed-shader fixes (12 OpStores each).
- adapter proximity_emul (FrameBridge): OVRPlugin's thumb/index proximity actions get bindings to the capacitive
  touch inputs when the runtime lacks XR_FB_touch_controller_proximity (OVRPort offers the extension anyway):
  generic replacement for the libUE4 ThumbUp patch.
- Vader's recipe: pose_time_fix + proximity_emul, status unknown (to test in the headset), min_app 0.12.1.

Analysis records unreal_quest_gates (ANALYSIS_VERSION 4). Star Wars: Tales from the Galaxy's Edge (same studio)
has neither gate (different engine build) and gets a catalog entry with pose_time_fix + proximity_emul.

Headless on the dev Frame (Lepton 3.0.5): the layer loads into Zink's instances, the proximity bindings are
accepted, and the game passes the loading card to the "guardian smaller than recommended, press any button" screen.
2026-10-09 09:20:15 -04:00
spoopyghosty0 f78bc82cc4 frame.vivox_audio_route: Vivox voice chat without Android 12 audio routing (GitHub #101)
Newer Vivox builds (Green Hell VR) call AudioManager communication-device methods (API 31) from com.vivox.sdk.AudioChangeListener without a version check; Lepton is Android 11 -> NoSuchMethodError. The methods that call them now return at once (in-place dex edit, Dex.return_early). Detected by analysis vivox_api31 (ANALYSIS_VERSION 4), triage vivox-api31. Verified headless: Green Hell starts, Vivox initialises, ~65-70 fps.
2026-10-09 09:09:24 -04:00
spoopyghosty0 dfacf6a206 FrameBridge: serve cube swapchains the runtime refuses (GitHub #107)
Budget Cuts Ultimate asks for a 2048x2048 cube swapchain (faces=6); the Frame's runtime has no cube layers and refuses it (-2), OVRPlugin carries on with no images and crashes in ovrp_EndFrame4 (memset). cube_standin (default on, GLES) serves it as a GL cube map in the game's context and drops its layers. Triage cube-swapchain-refused (supersedes unity-render-crash/native-crash). Verified headless: the game runs on at ~70 fps.
2026-10-09 09:09:23 -04:00
spoopyghosty0 b2f14c1e2e Catalog: SUPERHOT VR (Rift) keeps the build's own launch arguments (GitHub #105: the older Oculus + SteamVR build needs -vrmode OpenVR; the catalog recipe from the OpenXR build dropped it) 2026-10-09 08:49:53 -04:00
spoopyghosty0 03d7a311bf Catalog: Batman: Arkham Shadow gets sync_guard to test (GitHub #102: quit to Steam's waiting screen after the Frame runtime crashed in xrSyncActions, the input race Myst had) 2026-10-09 08:32:50 -04:00
spoopyghosty0 cd5119278b Catalog: The Light Brigade (works with issues)
Closes #114
2026-10-09 07:56:14 -04:00
spoopyghosty0 6ab3608a44 Catalog: Gravity Lab (works)
Closes #113
2026-10-09 07:56:06 -04:00
spoopyghosty0 c0539af368 Catalog: Does it Stack? (works with issues)
Closes #112
2026-10-09 07:56:02 -04:00
spoopyghosty0 c6363140f4 Catalog: Walkabout Mini Golf (works)
Closes #111
2026-10-09 07:55:58 -04:00
spoopyghosty0 187105b729 Catalog: Matilda (works)
Closes #110
2026-10-09 07:55:55 -04:00
spoopyghosty0 b983c0f11f Catalog: The Tale of Onogoro (works)
Closes #108
2026-10-09 07:55:52 -04:00
spoopyghosty0 c7cee33889 Catalog: Please Don't Touch Anything (works)
Closes #106
2026-10-09 07:55:49 -04:00
spoopyghosty0 d9d73b8aec Triage: Lepton 3.0.5's transient 'is not a running context' (printed while its container is still starting, then 'Boot complete!') no longer fails a launch test (container-not-started unless Boot complete!; VR4 ran at 72 fps on the dev Frame but was marked failed) 2026-10-09 07:55:24 -04:00
spoopyghosty0 48455b9b72 pose_time_fix: robust clock offset (the largest of the last ~2 s of xrWaitFrame samples; hitches made single samples dip by up to 2.5 s and pushed fixed times up to 2 s into the future), far-past requests located at the frame's display time, nothing moved before 8 samples. Headless survey of 54 games: no other game asks for head/views on the monotonic clock; UE4 OVRPlugin 1.89 games and The Room VR ask for XrTime ~0 every frame and work today, so the setting stays suggested for Unity built-in Oculus games only. BattleSisters on the Frame: every moved request now at 0.0 ms from the display time 2026-10-09 01:35:15 -04:00
spoopyghosty0 af798c0bf3 Catalog: BattleSisters entry parses again (my previous edit put colons into a plain YAML text block); written with catalog.to_yaml 2026-10-08 22:55:47 -04:00
spoopyghosty0 ed714c9d65 Catalog: BattleSisters plays with hands following the controllers (adapter pose_time_fix, owner's headset test) 2026-10-08 22:51:26 -04:00
spoopyghosty0 832b401630 Pose time fix (adapter pose_time_fix, pose_debug): OVRPlugin locates its "now" poses at the monotonic clock
BattleSisters' hands lagged behind the controllers (also with ovrp_hold_physics on or off). pose_debug=1 (new,
FrameBridge: per 5 s and per located space, the requested time minus the predicted display time) showed on the dev
Frame (SteamOS 0.4.5): XrTime runs 2.56 s ahead of CLOCK_MONOTONIC, the hand spaces were located at -2564 ms (the
monotonic "now" passed on as an XrTime: OVRPort's dispatcher converts XR_KHR_convert_timespec_time 1:1 and
FrameBridge's emulation is never asked) and the head at XrTime 0.1 s (~1450 xrLocateViews/xrLocateSpace per 5 s).

pose_time_fix (default off; suggested for Unity built-in OVRPlugin games): in xrLocateSpace(s)/xrLocateViews a time
nearer the monotonic clock than XrTime's "now" is moved by the offset measured at xrWaitFrame, one more than 0.5 s
before the display time goes to "now". Headless with it on: every far-past request moved, located times -9.8..0 ms
from the display time. Host unit test for the time rules; PLAYBOOK row.
2026-10-08 22:41:34 -04:00
Lucas-Mathieu 8814b1ce56 Merge remote-tracking branch 'origin/main' into fix/batman-cutscene-playback
# Conflicts:
#	src/frameport/pipeline.py
2026-10-08 17:49:12 +02:00
Lucas-Mathieu e9eedb2241 Merge remote-tracking branch 'origin/main' into fix/batman-cutscene-playback
# Conflicts:
#	artifacts/SHA256SUMS
2026-10-08 01:57:46 +02:00
Lucas-Mathieu d3a35c307a Fix Batman native cutscene decoding and stereo composition 2026-10-08 01:57:29 +02:00
236 changed files with 35803 additions and 152 deletions

No files matched your search

+61 -1
View File
@@ -91,7 +91,11 @@ Read `docs/PLAYBOOK.md` (symptom → fix) before debugging a game, and `docs/FRA
doesn't do). `VD.bat` is Virtual Desktop's launcher: ignore it except as an exe-location hint. Library migration
`rift_run_direct` resets existing recipes.
Auto launch-test is skipped on PC installs (it would start the game on the user's desktop). Launch tests collect the Unreal
game log + crash summaries from the Proton prefix; triage `unreal-crash`. Lies Beneath via Proton without Revive
game log + crash summaries from the Proton prefix; triage `unreal-crash`. Agent v67 adds Unity's logs (LocalLow/<Company>/<Product>/Player(-prev).log via `<Name>_Data/app.info`,
`output_log.txt`, Temp/…/Crashes/*/error.log; `unity_logs`) to launch tests and diagnostics; triage `unity-vr-init` /
`unity-crash`. A catalog recipe verified with another build (catalog `xr` ≠ the build's) keeps the build's own
`pcvr.launch_args` (`engine._other_build`; GitHub #105: SUPERHOT VR's Oculus+OpenVR build needs `-vrmode OpenVR`,
the catalog's is the OpenXR build); Electron launchers next to a game rank −30 (`rift.is_electron`). Lies Beneath via Proton without Revive
crashed (UE 4.23 "Unhandled exception").
- Rift scanning: `sources/rift_dump.scan` = the scanned folder's subfolders are games (one per folder; a folder is a
game if all candidate exes sit under one child), recursing into collections; `analysis/rift.py` walks once,
@@ -614,6 +618,7 @@ FrameBridge `snapshot=N` (`snapshot_gl.c`, GLES): every N s the left-eye image t
own context and saved as `files/fb_snap_0-7.ppm` (quarter size) — headless launches show a black headset view, this
shows what the game draws. Vader: Lucasfilm logo (an OBB mp4: video works), then its loading card (portrait + segmented
bar) that never advances; the async loader thread sleeps and OBB reads stop (~168 MB of a 2.7 GB pak).
**Lepton's logcat mirror dies (agent v67, 2026-10-09):** occasionally launch.log ends with `logcat: Unexpected EOF!` right after the game starts (about 1 launch in 50, Lepton 2.8.14 and 3.0.5): no dashboard auto-hide, no launch-test result. launch.sh's `_logcat_keeper` then reads `podman exec lepton-steamlaunch-<appid> logcat` itself into launch.log (up to 5 restarts while the game runs).
**Double launch (agent v57, 2026-10-06):** a second Play while Lepton still boots (~10 s with nothing to see) made
the second Lepton stop the first one's container ("Waiting for steamlaunch-<appid> (PID …) to exit", exit 137
"(starting)", "Clearing baked app data due to early exit") and both died (Vader, BattleSisters). launch.sh now takes
@@ -641,6 +646,61 @@ head-pose deadline ends VR mode without a worn headset (not a game bug).
**Language packs (merged from PR #20, 2026-10-04):** overport's `libovrplatformloader.so` is a dispatcher that `dlopen`s Meta's own loader (`libovrplatformloader_meta.so` / `_meta_q1.so`, also `libpxrplatformloader.so`) and keeps its own message queue; `ovr_LanguagePack_GetCurrent/SetCurrent` are 8-byte `return 0` stubs in it, `ovr_AssetFile_GetList` forwards to Meta's loader. `frame.langpacks` (opt-in, `native/langpack`) serves `<tag>.lang` files from the game's data; `elf.hide_exports` marks the loader's exports STB_LOCAL (bionic and glibc only match GLOBAL/WEAK; verified for glibc, bionic's `is_symbol_global_and_defined` is from memory). `libfp_langpack.so` is built here (`python native/build.py --only langpack`) and committed. Owner-verified 2026-10-04: Deadpool VR with only `en.lang` and the patch on plays English dialogue and runs normally (headless launch tests show 2-6 fps while it loads: not a regression sign). A dispatcher answer that arrives after we answered the timed-out GetList is dropped (one answer per request); games already in a library get `lang_packs` filled after an app update (`library._refresh_data_fields`). The library logs to logcat under the tag `fp_langpack` (dirs looked in, packs found, every language-pack call), so it shows up in the game's `launch.log`; an `ovr_AssetFile_GetList` the dispatcher leaves unanswered for 1.5 s is answered with our packs alone. Deadpool VR (Unreal) accepts a pack only when its `Metadata` equals the game's own version string (`ULanguagePacksSubsystem` compares it with `%s.%s.%s.%s.%s` built from the build info, e.g. `1.0.40.356975.Quest` = versionName; found by disassembling `libUE4.so`): the patch writes the APK's versionName into the library (`@FPMETA@` slot, `with_metadata`), `FRAMEPORT_LANGPACK_META` overrides it. Deadpool VR (2026-10-04, headset): German became selectable with that Metadata, but dialogue stayed silent (even English once reported as a pack) while the path was spelled `/sdcard/Android/obb/<pkg>/x.lang`; with the `/storage/emulated/0/Android/obb/<pkg>/x.lang` spelling (Unreal's own, now listed first in `scan_dirs`) German dialogue plays. `FRAMEPORT_LANGPACK_SKIP=<tags>` or a file `fp_langpack_skip` in the obb folder leaves packs out of the list (experiments).
**Cube swapchains (GitHub #107, 2026-10-09):** the Frame's runtime refuses `faceCount=6` swapchains (-2,
XR_ERROR_RUNTIME_FAILURE); OVRPlugin ignores that ("CreateSwapchain for eye 0: 0x0, 0 stages") and crashes in
ovrp_EndFrame4 (memset). FrameBridge `cube_standin` (default on, `native/adapter/cube_standin.c`) serves a refused cube
swapchain as one GL cube-map texture in the app's context (GLES only) and drops its layers. Verified headless with
Budget Cuts Ultimate (2048² sRGB, 12 mips; runs on at ~70 fps); what the cube layer showed is simply missing.
**Hardware video decoding (PR #96, PR #128 by Lucas-Mathieu, adapted 2026-10-10, agent v71):** `native/hevc` = one
OMX plugin `OMX.frameport.{avc,hevc,vp9}.decoder` (FFmpeg v4l2m2m on Iris /dev/video-dec0, FFmpeg software decoders as
fallback inside the component, Vulkan copy for big native surfaces). The connection installs it once per Frame
(`ensure_video_codec` → agent `video_codec_status`/`install_video_codec`: `~/.local/share/frameport/video-codec/versions/
<manifest sha>` + `current` symlink). A Frame keeps the same or a newer `revision` (no flip-flop between PCs) → **bump
`revision` in native/hevc/build.py with every artifact change**; a failed install isn't retried during the connection.
Per game: only launchers of games whose recipe has `frame.hw_video_decode` (install stage, no APK change; suggested
from analysis `media_codec`, ANALYSIS_VERSION 8; deployment.json `hw_video_decode`) get the codec line → the Podman
wrapper (native/hevc/podman.py) mounts the plugin into that container (merged media_codecs.xml in
$XDG_RUNTIME_DIR/frameport-video). Off for every game: Settings → Installing (library `video.hw_decode` → agent
`video_codec_switch` = video-codec/disabled); one game: `FRAMEPORT_NO_HW_VIDEO=1 %command%`. `upgrade_launchers`
converts agent ≤70 launchers (Batman's `<base>/frameport-codec` → keeps the line, folder then removed). Batman: catalog
+ migration `batman_video_patches` (`frame.hw_video_decode` + hidden adapter setting `surface_native`). Iris: 8K
refused (ENOMEM) while any other decoder session is open; SteamVR's vrlinkrunthread holds one ~12 s at game start →
refused opens retry until 20 s after the plugin loaded (else 2 s), then software; VP9 7680x3840 never returned a
picture → VP9 ≤4096x2304; hidden VP9 frames come back as empty capture buffers (bytesused 0, no LAST):
FFmpeg's wrapper ended the EOS drain at the first one (two-pass VP9 lost its last ~25 frames) → build.py requeues
them (codec revision 8; drain ends at LAST, or 1 s after a skipped empty buffer; dev Frame 2026-10-10: 600/600 =
OMX.google.vp9 Y hashes). Rebuilds are deterministic (ext4 + NTFS path
with spaces, two NDK copies → same; rev 8 141de01f…; PR #128's own sources → its 27a2d749…). Not yet run on the device.
**Vivox API 31 (GitHub #101, 2026-10-09):** newer Vivox builds (Green Hell VR) call Android 12 AudioManager
communication-device methods from `com.vivox.sdk.AudioChangeListener` with no SDK check → NoSuchMethodError on Lepton's
Android 11. `frame.vivox_audio_route` (analysis `vivox_api31`, ANALYSIS_VERSION 4) makes every such method return at
once (`Dex.return_early`: return-void / `const/4 v0,0; return v0`; nopping the invoke would leave a move-result the
verifier rejects). Older Vivox (Eleven Table Tennis, BattleSisters) lacks that code and isn't matched. Verified
headless: Vivox initialises, 150 s at ~65-70 fps.
**Multiview programs on flat framebuffers (GitHub #77, Doom3Quest, 2026-10-09, prototype):** Mesa enforces OVR_multiview's
"program num_views == draw framebuffer views" rule (`draw_validate.c`, the draw is dropped silently); Qualcomm doesn't.
Doom3Quest compiles every VS with `layout(num_views=2) in;` and draws its HUD/PDA into 2D-texture FBOs → black. Opt-in
`frame.gl_multiview_fbo` (analysis `gl_multiview_libs`, ANALYSIS_VERSION 6; own-engine GLES only): `native/glmv` =
`libfpglmv.so` (12 chars = "libGLESv3.so": libdoom3.so's one `.rodata` dlopen string is rewritten in place, its qgl*
table comes from dlsym on that handle; also first DT_NEEDED for its direct gl*/egl* imports). Such draws use a lazily
built single-view twin (view 0, uniforms copied per draw); eglMakeCurrent resets the per-thread cache. Host-tested only
(rewriter on all 19 Doom3Quest shaders + glmv.c against a stand-in GL, `tests/test_gl_multiview_fbo.py`); the host's
Mesa 23.2 llvmpipe has no OVR_multiview. Headset-verified by Xandrix1987 (2026-10-09: HUD/PDA shown, no fps drop) -> in the Doom3Quest catalog recipe.
**Session triage (agent v70, 2026-10-09):** launch tests never reach FOCUSED, so real play sessions are triaged
too. list_installed gives each game `last_play` {start, end, test} from `<anchor>/plays.log` (launch tests write a
`test <unix>` line first → test sessions are only marked); `session_log` returns the newest session's launch.log
(`<base>/session.log`, ≤4 MB: head + tail + FrameBridge/crash lines between) + that session's logcat-crash.log +
`journalctl -k` GPU lines ("kernel: …"). The GUI's connection refresh (`app._check_sessions` → `pipeline.sessions_due`,
background thread; sessions >7 days old are skipped) runs `pipeline.triage_session` = `validate/session.analyze`
(triage.yaml signatures incl. `space-warp-used` (info, `question:`, never auto-applied), `gpu-hang` (`report: true`)
+ computed `slow-frames` (pacing windows vs the nearest refresh rate) and `focus-dips` (FrameBridge always logs
`focus: lost` / `focus: back after N ms`, session_fixes.c)) → library `last_session` / `last_session_checked` → game
page "Last session" callout (Try this fix / Rebuild with this fix / Yes-No question / Report / Dismiss). Suggestions may
be values (`adapter.scale=0.85`, `triage.split_suggestion`); adapter-only fixes are pushed live (`apply_suggestions_live`
→ agent set_settings, like the Game settings dialog). CLI `frameport session <pkg> [--apply]`. PC VR (Proton) launchers
log no session end, so they aren't triaged yet. pac_hints stays triage-only: a survey of all 68 dump APKs found unpaired
PAC hints in 21 libraries of 18 games (OpenSSL's 38/40 in most UE4 libUE4.so and libEOSSDK.so, UE5 libUnreal.so ~400
vs +2-3, libass, libopencv, …), most of them games that work, so default-on would rewrite many working builds.
**Unresolved (as of 2026-09-28):** Arcsmith (right-eye distortion) and Time Stall (both eyes) — swap, tracking, Valve
layers, depth, pacing ruled out. Sniper Elite VR (DEVICE LOST), Espire 1 (Mesa GL upload crash), HITMAN 3 (freedreno
crash): use PC versions.
+2
View File
@@ -11,6 +11,8 @@ FramePort is GPL-3.0-only (see `LICENSE`). It includes or downloads the followin
| Android NDK runtime (statically linked libc++) | native Android libraries | Apache-2.0 with LLVM exception, plus legacy notices (`native/vrapi-bridge/licenses/ANDROID-NDK.txt`) |
| Flet and Flutter (desktop app runtime) | release bundles | Apache-2.0 / BSD-3-Clause |
| flet-dropzone / desktop_drop (drag-and-drop) | release bundles | Apache-2.0 / MIT |
| FFmpeg 7.1.1 hardware HEVC wrapper (LGPL configuration, without GPL/nonfree components) | `artifacts/hevc/libstagefrighthw.so`; source/rebuild instructions in `native/hevc/build.py` and `native/hevc/README.md` | LGPL-2.1-or-later (`artifacts/hevc/COPYING.FFmpeg`); unmodified source: https://ffmpeg.org/releases/ffmpeg-7.1.1.tar.xz |
| AOSP Android 11 native media/utility headers | `native/hevc/platform/` | Apache-2.0; copyright/license notices retained in the headers |
| Python packages (paramiko, zeroconf, psutil, pyelftools, capstone, UnityPy, PyYAML, requests, typer, pyaxmlparser, Pillow, cryptography, …) | release bundles | their own licenses (see each package's metadata) |
FramePort's own native code (the FrameBridge adapter, GL/Vulkan/OpenXR shims, the Windows helpers) is GPL-3.0-only.
+492 -12
View File
@@ -23,7 +23,6 @@ PC VR (Oculus Rift) games packed for the Frame (id "rift.<slug>"), run by Proton
<dest>/<id>/compatdata/ Proton prefix = saves (kept across reinstalls), launch.log
"""
import base64
import fcntl
import glob
import hashlib
import json
@@ -34,16 +33,38 @@ import shutil
import struct
import subprocess
import sys
import tempfile
import time
import zipfile
import zlib
from types import SimpleNamespace
AGENT_VERSION = 64
try:
import fcntl
except ImportError: # Windows: pc_revive loads this file for its VDF code only (GitHub #131)
fcntl = None
AGENT_VERSION = 71
HOME = os.path.expanduser("~")
STEAM = os.path.join(HOME, ".local/share/Steam")
ANCHORS = os.path.join(HOME, "Applications/quest-frame")
LEPTON_APPID = "3029110" # fallback when no appmanifest names Lepton
PKG_RE = re.compile(r"^[A-Za-z][A-Za-z0-9_]*(\.[A-Za-z0-9_]+)+$")
VIDEO_CODEC_DIR = os.path.join(HOME, ".local/share/frameport/video-codec")
VIDEO_CODEC_FILES = ("libstagefrighthw.so", "media_codecs_frameport.xml", "podman.py", "COPYING.FFmpeg")
# Hardware video decoding (patch frame.hw_video_decode, per game): only launchers of games whose recipe has it put the
# shared codec's Podman wrapper first on Lepton's PATH (it adds the codec plugin to that game's container). Off for
# every game: FramePort's setting (VIDEO_CODEC_DIR/disabled); one game: FRAMEPORT_NO_HW_VIDEO=1 in its launch options.
VIDEO_CODEC_LINE = ('codec_dir="$HOME/.local/share/frameport/video-codec"\n'
'[[ "${FRAMEPORT_NO_HW_VIDEO:-0}" != 0 || -e "$codec_dir/disabled" || '
'! -x "$codec_dir/current/bin/podman" ]] || export PATH="$codec_dir/current/bin:$PATH"')
HW_VIDEO_PATCH = "frame.hw_video_decode"
# earlier codec lines: agent <= 70 (per-game codec extracted from the APK, line in every launcher) and PR #128's
# shared line (in every Lepton launcher)
OLD_CODEC_LINES = ('[[ ! -x "$app_dir/frameport-codec/bin/podman" ]] || '
'export PATH="$app_dir/frameport-codec/bin:$PATH"',
'codec_bin="$HOME/.local/share/frameport/video-codec/current/bin"\n'
'[[ ! -x "$codec_bin/podman" ]] || export PATH="$codec_bin:$PATH"')
class AgentError(Exception):
@@ -681,6 +702,12 @@ def ensure_host_fixes():
upgraded = []
if upgraded:
changed.append(f"launchers: exit watchdog, dashboard, play log ({len(upgraded)})")
try:
old = remove_old_codec_dirs()
except Exception: # noqa: BLE001
old = []
if old:
changed.append(f"per-game video codec folders removed ({len(old)})")
try:
entries = refresh_desktop_entries()
except Exception: # noqa: BLE001
@@ -1450,6 +1477,7 @@ def cmd_list_installed(args):
apk = os.path.join(dep["base"], "lepton-app/game.apk")
dep["apk_present"] = os.path.exists(apk)
dep["apk_size"] = os.path.getsize(apk) if dep["apk_present"] else 0
dep["last_play"] = last_play(dep["anchor"]) # agent v70: the PC triages a finished play session's log
games.append(dep)
return {"games": games}
@@ -1927,6 +1955,42 @@ def play_sessions():
return [tuple(s) for s in sessions]
TEST_MARK_WINDOW = 60 # s: a "test <unix>" line in plays.log marks a session starting this soon after as a launch test
def last_play(anchor):
"""The newest play session in <anchor>/plays.log: {start, end (None while it runs, and for Proton launchers, which
exec the game), test (started by a launch test, not by the player)}, or None."""
text = _tail(os.path.join(anchor, PLAYS_LOG), 8192)
if not text:
return None
start = end = None
tests = []
for line in text.splitlines():
parts = line.split()
if len(parts) < 2 or not parts[1].isdigit():
continue
t = int(parts[1])
if parts[0] == "start":
start, end = t, None
elif parts[0] == "end" and start is not None and t >= start:
end = t
elif parts[0] == "test":
tests.append(t)
if start is None:
return None
return {"start": start, "end": end, "test": any(0 <= start - t <= TEST_MARK_WINDOW for t in tests)}
def mark_launch_test(anchor):
"""A launch test runs the game's launcher, which logs a play session: mark it so the PC doesn't triage it as one."""
try:
with open(os.path.join(anchor, PLAYS_LOG), "a") as f:
f.write(f"test {int(time.time())}\n")
except OSError:
pass
def session_game(t, sessions):
"""Package whose play session contains time t (the latest start wins), else None."""
hit = None
@@ -2151,6 +2215,7 @@ export XDG_RUNTIME_DIR="/run/user/$(id -u)"
export DBUS_SESSION_BUS_ADDRESS="unix:path=$XDG_RUNTIME_DIR/bus"
export IS_PARENT=true
{extra_env}
{video_codec}
child=''
stop() {{
trap - EXIT INT TERM
@@ -2166,6 +2231,7 @@ trap 'exit 143' TERM
setsid {lepton_q} start >"$app_dir/launch.log" 2>&1 &
child=$!
{dashboard}
{logcat}
wait "$child"
""")
@@ -2193,10 +2259,22 @@ SINGLE_LINE = ('exec 9>"$app_dir/.launch.lock"; flock -n 9 || '
'exit 0; }')
# Lepton mirrors the game's logcat into launch.log, and that reader sometimes dies right after the game starts
# ("logcat: Unexpected EOF!", seen with Vader Immortal on Lepton 3.0.5 and Under Cover on 2.8.14). The game runs on,
# but launch.log stays empty: no dashboard auto-hide, no launch-test result. _logcat_keeper then reads the
# container's logcat itself and appends it to launch.log.
LOGCAT_LINE = ('python3 {agent_q} _logcat_keeper "$app_dir/launch.log" "$SteamAppId" $$ '
'>"$app_dir/logcat-keeper.log" 2>&1 9>&- &')
def dashboard_line():
return DASHBOARD_LINE.format(agent_q=shlex.quote(os.path.abspath(__file__)))
def logcat_line():
return LOGCAT_LINE.format(agent_q=shlex.quote(os.path.abspath(__file__)))
def plays_lines(anchor):
"""launch.sh lines that log play sessions to <anchor>/plays.log (screenshots are matched to games by time: the
Frame files every headset screenshot under SteamVR). Never fail the launcher."""
@@ -2215,12 +2293,18 @@ def upgrade_launchers():
except OSError:
continue
new = text
# the codec line follows the game's deployment (only Lepton launchers have this variable; Proton/Linux
# launchers are never touched). Running launchers keep reading their old file.
if "export LEPTON_ENV_FRAMEBRIDGE_CONFIG=" in new:
new = set_codec_line(new, wants_hw_video(os.path.dirname(path)))
if "a Linux app. Generated by FramePort" in new and "FRAMEPORT_DESKTOP" not in new:
new = upgrade_linux_launcher(new)
if OLD_WATCHDOG in new and "parent=$PPID" not in new:
new = new.replace(OLD_WATCHDOG, WATCHDOG, 1)
if "_dashboard_worker" not in new and 'child=$!\nwait "$child"' in new:
new = new.replace('child=$!\nwait "$child"', 'child=$!\n' + dashboard_line() + '\nwait "$child"', 1)
if "_logcat_keeper" not in new and "_dashboard_worker" in new and '\nwait "$child"' in new:
new = new.replace('\nwait "$child"', '\n' + logcat_line() + '\nwait "$child"', 1)
guard = '[[ -d "$app_dir/lepton-app" ]] ||'
if ".launch.lock" not in new and guard in new:
i = new.index("\n", new.index(guard)) + 1
@@ -2246,6 +2330,94 @@ def upgrade_launchers():
return changed
def wants_hw_video(anchor):
"""Whether this game's launcher gets the shared codec (frame.hw_video_decode): deployment.json's choice (written
at finalize), else its recipe's patches. A game that had agent <= 70's per-game codec (extracted from its APK:
Batman) keeps it; that choice is saved, since ensure_host_fixes then removes the old codec folder."""
path = os.path.join(anchor, "deployment.json")
try:
with open(path) as f:
dep = json.load(f)
except (OSError, ValueError):
return False
if not isinstance(dep, dict):
return False
if "hw_video_decode" in dep:
return bool(dep["hw_video_decode"])
recipe = dep.get("recipe") if isinstance(dep.get("recipe"), dict) else {}
if HW_VIDEO_PATCH in (recipe.get("patches") or []):
return True
base = dep.get("base")
if isinstance(base, str) and os.path.exists(os.path.join(base, "frameport-codec/bin/podman")):
dep["hw_video_decode"] = True
with open(path + ".tmp", "w") as f:
json.dump(dep, f, indent=2)
os.replace(path + ".tmp", path)
return True
return False
def set_codec_line(text, want):
"""A Lepton launcher with the current codec line where it belongs (want) or none; earlier lines are dropped."""
at = -1
for line in (VIDEO_CODEC_LINE, *OLD_CODEC_LINES):
i = text.find(line + "\n")
while i >= 0:
text = text[:i] + text[i + len(line) + 1:]
at = i if at < 0 else min(at, i) # the earliest one's place (text before it is unchanged)
i = text.find(line + "\n")
if want:
if at < 0:
for anchor in ("\nchild=''\n", "\nsetsid "):
if anchor in text:
at = text.index(anchor) + 1
break
if at >= 0:
text = text[:at] + VIDEO_CODEC_LINE + "\n" + text[at:]
return text
def remove_old_codec_dirs():
"""Agent <= 70 extracted a per-game codec into <base>/frameport-codec; the shared codec replaced it. Removed
once the game's launcher no longer uses it (upgrade_launchers converted it; the choice is in deployment.json or
the recipe's patches)."""
removed = []
for dep_path in glob.glob(os.path.join(ANCHORS, "*/deployment.json")):
try:
with open(dep_path) as f:
dep = json.load(f)
base = dep.get("base")
except (OSError, ValueError, AttributeError):
continue
old = os.path.join(base, "frameport-codec") if isinstance(base, str) else ""
if not old or not os.path.isdir(old) or os.path.islink(old):
continue
try:
with open(os.path.join(os.path.dirname(dep_path), "launch.sh")) as f:
launcher = f.read()
except OSError:
launcher = ""
if "frameport-codec" in launcher:
continue # its launcher hasn't been converted yet
shutil.rmtree(old, ignore_errors=True)
removed.append(dep.get("package") or os.path.basename(os.path.dirname(dep_path)))
return removed
def cmd_video_codec_switch(args):
"""FramePort's setting "Hardware video decoding" for every game on this Frame: off writes VIDEO_CODEC_DIR/disabled,
which launchers and the wrapper check at every start (no launcher rewrite, running games keep what they have)."""
flag = os.path.join(VIDEO_CODEC_DIR, "disabled")
if args.get("enabled", True):
if os.path.exists(flag):
os.remove(flag)
else:
os.makedirs(VIDEO_CODEC_DIR, exist_ok=True)
with open(flag, "w") as f:
f.write("switched off in FramePort\n")
return cmd_video_codec_status({})
def upgrade_linux_launcher(text):
"""A Linux app's launcher from before agent v63, made fit for Desktop Mode's menu entry (GitHub #84): no Steam
parent watchdog and no display taken from Steam when FRAMEPORT_DESKTOP is set."""
@@ -2258,12 +2430,14 @@ def upgrade_linux_launcher(text):
return text
def write_launcher(anchor, base, pkg, title, appid, lepton, env):
def write_launcher(anchor, base, pkg, title, appid, lepton, env, hw_video=False):
extra = "".join(f"export {k}={shlex.quote(str(v))}\n" for k, v in (env or {}).items()
if re.fullmatch(r"[A-Z_][A-Z0-9_]*", k))
text = LAUNCH_SH.format(title=title.replace("\n", " "), pkg=pkg, base_q=shlex.quote(base), appid=appid,
lepton_q=shlex.quote(lepton), extra_env=extra, watchdog=WATCHDOG,
dashboard=dashboard_line(), single=SINGLE_LINE, plays_start=plays_lines(anchor)[0],
dashboard=dashboard_line(), logcat=logcat_line(), single=SINGLE_LINE,
video_codec=VIDEO_CODEC_LINE if hw_video else "",
plays_start=plays_lines(anchor)[0],
plays_end=plays_lines(anchor)[1])
path = os.path.join(anchor, "launch.sh")
with open(path + ".tmp", "w") as f:
@@ -2276,6 +2450,114 @@ def data_files_dir(base, pkg):
return os.path.join(base, "lepton-data/external/Android/data", pkg, "files")
def cmd_video_codec_status(args):
"""The shared codec installed on this Frame ({digest, revision}, {} if none or damaged) and whether FramePort's
setting switched it off for every game ("disabled")."""
status = video_codec_installed()
status["disabled"] = os.path.exists(os.path.join(VIDEO_CODEC_DIR, "disabled"))
return status
def video_codec_installed():
path = os.path.join(VIDEO_CODEC_DIR, "current", "manifest.json")
try:
with open(path, "rb") as f:
raw = f.read()
manifest = json.loads(raw)
with open(os.path.join(os.path.dirname(path), "deployment.json")) as f:
config = json.load(f)
if not isinstance(config, dict) or config.get("scope") != "shared" or \
config.get("runtime_sha256") != manifest["runtime_sha256"]:
return {}
for name in VIDEO_CODEC_FILES:
local = "bin/podman" if name == "podman.py" else name
if sha256_file(os.path.join(os.path.dirname(path), local)) != manifest["files"][name]:
return {}
return {"digest": hashlib.sha256(raw).hexdigest(), "revision": manifest.get("revision", 1)}
except (OSError, ValueError, KeyError, TypeError):
return {}
def prune_video_codec_versions(versions, keep):
"""Each revision is ~15 MB. Keep the active one and the one it replaced (a launch that resolved the old
'current' just before the switch still mounts its files); running containers hold their mounts anyway."""
for name in os.listdir(versions):
if name in keep or not re.fullmatch(r"[0-9a-f]{64}(\.previous-[0-9]+)?|\.install-.*", name):
continue
path = os.path.join(versions, name)
if os.path.isdir(path) and not os.path.islink(path):
shutil.rmtree(path, ignore_errors=True)
def cmd_install_video_codec(args):
"""Verify a shared payload, then publish its complete version in one step."""
encoded = args["bundle"]
if not isinstance(encoded, str) or len(encoded) > 32 * 1024 * 1024:
raise AgentError("oversized video codec bundle")
import io
raw = base64.b64decode(encoded, validate=True)
data = {}
with zipfile.ZipFile(io.BytesIO(raw)) as archive:
if set(archive.namelist()) != {"manifest.json", *VIDEO_CODEC_FILES} or len(archive.infolist()) != 5:
raise AgentError("unexpected video codec bundle files")
for name in ("manifest.json", *VIDEO_CODEC_FILES):
if archive.getinfo(name).file_size > 16 * 1024 * 1024:
raise AgentError(f"oversized video codec asset: {name}")
data[name] = archive.read(name)
manifest = json.loads(data["manifest.json"])
if not isinstance(manifest, dict) or not isinstance(manifest.get("files"), dict) or \
not isinstance(manifest.get("revision", 1), int) or manifest.get("revision", 1) < 1:
raise AgentError("invalid video codec manifest")
digest = hashlib.sha256(data["manifest.json"]).hexdigest()
if digest != args["digest"]:
raise AgentError("video codec manifest checksum mismatch")
for name in VIDEO_CODEC_FILES:
if hashlib.sha256(data[name]).hexdigest() != manifest["files"][name]:
raise AgentError(f"video codec asset checksum mismatch: {name}")
# A second PC with older FramePort must not downgrade the shared codec.
os.makedirs(VIDEO_CODEC_DIR, exist_ok=True)
with open(os.path.join(VIDEO_CODEC_DIR, "install.lock"), "a") as lock:
fcntl.flock(lock, fcntl.LOCK_EX)
current = video_codec_installed()
if current.get("digest") not in (None, digest) and current.get("revision", 0) >= manifest.get("revision", 1):
# another PC's FramePort installed this revision (or a newer one) built differently: keep it, two
# PCs mustn't replace each other's codec at every connection
return dict(current, kept=True)
versions = os.path.join(VIDEO_CODEC_DIR, "versions")
os.makedirs(versions, exist_ok=True)
version = os.path.join(versions, digest)
previous = os.path.basename(os.path.realpath(os.path.join(VIDEO_CODEC_DIR, "current")))
if current.get("digest") != digest:
stage = tempfile.mkdtemp(prefix=".install-", dir=versions)
try:
os.mkdir(os.path.join(stage, "bin"))
# Config first, executable last, then expose the entire version.
config = {"scope": "shared", "runtime_sha256": manifest["runtime_sha256"]}
with open(os.path.join(stage, "deployment.json"), "w") as f:
json.dump(config, f)
for name in ("manifest.json", *[n for n in VIDEO_CODEC_FILES if n != "podman.py"], "podman.py"):
target = os.path.join(stage, "bin/podman" if name == "podman.py" else name)
with open(target, "wb") as f:
f.write(data[name])
os.chmod(target, 0o755 if name == "podman.py" else 0o644)
if os.path.lexists(version):
# Preserve an interrupted/corrupt prior version for diagnosis.
os.rename(version, version + f".previous-{time.time_ns()}")
os.rename(stage, version)
link = os.path.join(VIDEO_CODEC_DIR, f".current-{os.getpid()}")
if os.path.lexists(link):
os.unlink(link)
os.symlink(os.path.join("versions", digest), link)
os.replace(link, os.path.join(VIDEO_CODEC_DIR, "current"))
finally:
if os.path.isdir(stage):
shutil.rmtree(stage)
prune_video_codec_versions(versions, {digest, previous})
upgraded = upgrade_launchers()
return {"digest": digest, "revision": manifest.get("revision", 1), "launchers": upgraded}
def set_flatscreen(app_dir, on):
"""Lepton shows an app as a flat (2D) window only when its app folder holds this marker
(liblepton/app_metadata.sh); otherwise the app runs headless and only OpenXR output reaches the headset."""
@@ -2356,7 +2638,9 @@ def cmd_finalize(args):
with open(target, "w") as f:
f.write(content)
models = install_controller_models(files_dir, str(settings.get("controller_models", 0)) not in ("0", "0.0"))
write_launcher(anchor, base, pkg, title, appid, lepton, args.get("env"))
recipe = args.get("recipe") if isinstance(args.get("recipe"), dict) else {}
hw_video = HW_VIDEO_PATCH in (recipe.get("patches") or []) # the shared codec (install_video_codec)
write_launcher(anchor, base, pkg, title, appid, lepton, args.get("env"), hw_video)
art_in = os.path.join(base, "incoming-artwork")
if os.path.isdir(art_in):
shutil.rmtree(os.path.join(anchor, "artwork"), ignore_errors=True)
@@ -2364,7 +2648,7 @@ def cmd_finalize(args):
dep = {"package": pkg, "appid": int(appid), "base": base, "title": title, "tags": args.get("tags") or [],
"apk": args.get("apk_name", "game.apk"),
"sha256": args.get("apk_sha256"), "recipe": args.get("recipe"), "installed_by": "frameport",
"agent_version": AGENT_VERSION, "time": time.time()}
"hw_video_decode": hw_video, "agent_version": AGENT_VERSION, "time": time.time()}
with open(os.path.join(anchor, "deployment.json"), "w") as f:
json.dump(dep, f, indent=2)
return {"ok": True, "base": base, "appid": appid, "moved_data_files": moved, "controller_models": models}
@@ -3623,7 +3907,7 @@ def cmd_uninstall(args):
raise AgentError("the game is running")
keep_data = args.get("keep_data", True)
names = ("game", "revive", "xrlayer", "shadercache", "incoming", "incoming-artwork") if pcvr else \
("app", "incoming", "incoming-artwork", "launch.log") if linux else \
("app", "incoming", "incoming-artwork", "launch.log", "session.log") if linux else \
("lepton-app", "lepton-shaders", "incoming", "previous-game.apk")
for name in names:
p = os.path.join(base, name)
@@ -3649,7 +3933,7 @@ def cmd_uninstall(args):
if not keep_data or base != anchor:
remove_tree(anchor)
else: # saves live next to the launcher (Quest games): keep them, drop what marks the game as installed
for name in ("deployment.json", "launch.sh", "artwork", "launch.log", "launch-test.log"):
for name in ("deployment.json", "launch.sh", "artwork", "launch.log", "launch-test.log", "session.log"):
p = os.path.join(anchor, name)
remove_tree(p)
return {"removed": True, "kept_saves": keep_data, "shortcut_removed": removed_sc}
@@ -3987,10 +4271,56 @@ PCVR_LOGS = ("compatdata/pfx/drive_c/users/steamuser/AppData/Local/Revive/Revive
LOCAL_APPDATA = "compatdata/pfx/drive_c/users/steamuser/AppData/Local"
LOCAL_LOW = "compatdata/pfx/drive_c/users/steamuser/AppData/LocalLow"
def _head_tail(path, head=300, tail=1500):
lines = open(path, errors="replace").read().splitlines()
if len(lines) > head + tail:
lines = lines[:head] + [f"[... {len(lines) - head - tail} lines left out ...]"] + lines[-tail:]
return "\n".join(lines)
def unity_logs(base, since=0.0):
"""Unity's own logs of a PC VR game: LocalLow/<Company>/<Product>/Player.log + Player-prev.log (Unity 2018.3+;
company and product from <game>/<Name>_Data/app.info, else every Player log in LocalLow), the older
<Name>_Data/output_log.txt and the crash handler's Temp/<Company>/<Product>/Crashes/*/error.log. Unity logs VR
start-up (which SDK, init errors) at the top, so the head is kept as well as the tail."""
game = os.path.join(base, "game")
low = os.path.join(base, LOCAL_LOW)
temp = os.path.join(base, LOCAL_APPDATA, "Temp")
names = []
for info in glob.glob(os.path.join(glob.escape(game), "*_Data", "app.info")):
try:
lines = [ln.strip() for ln in open(info, errors="replace").read().splitlines()]
except OSError:
continue
if len(lines) >= 2 and lines[0] and lines[1] and "/" not in lines[0] + lines[1] and \
".." not in (lines[0], lines[1]):
names.append((lines[0], lines[1]))
dirs = [os.path.join(low, c, p) for c, p in names if os.path.isdir(os.path.join(low, c, p))]
logs = []
for d in dirs or glob.glob(os.path.join(glob.escape(low), "*", "*")):
logs += [os.path.join(d, n) for n in ("Player.log", "Player-prev.log")]
logs += glob.glob(os.path.join(glob.escape(game), "*_Data", "output_log.txt"))
crash_dirs = [os.path.join(temp, c, p) for c, p in names] or glob.glob(os.path.join(glob.escape(temp), "*", "*"))
crashes = [x for d in crash_dirs for x in glob.glob(os.path.join(glob.escape(d), "Crashes", "*", "error.log"))]
out = []
for log in [x for x in logs if os.path.isfile(x)]:
if os.path.getmtime(log) < since: # left over from an earlier run
continue
out.append(f"===== unity log {os.path.relpath(log, base)}\n" + _head_tail(log))
for err in sorted(crashes, key=os.path.getmtime, reverse=True)[:2]:
if os.path.getmtime(err) >= since:
out.append(f"===== unity crash {os.path.relpath(err, base)}\n" + _head_tail(err, 100, 400))
return out
def game_logs(base, since=0.0):
"""The game's own logs from the Proton prefix, newest first: Unreal Saved/Logs/*.log (tail) and crash summaries
(Saved/Crashes/*/CrashContext.runtime-xml → error message + call stack), Revive's logs."""
out = []
(Saved/Crashes/*/CrashContext.runtime-xml → error message + call stack), Unity's Player.log / crash error.log
(agent v67), Revive's logs."""
out = unity_logs(base, since)
local = os.path.join(base, LOCAL_APPDATA)
for log in sorted(glob.glob(os.path.join(local, "*", "Saved", "Logs", "*.log")), key=os.path.getmtime,
reverse=True)[:1]:
@@ -4015,6 +4345,9 @@ def game_logs(base, since=0.0):
return out
LAUNCH_INSTALL_GRACE = 240 # s a launch test waits at most for Lepton's boot + app install before its own window
def cmd_launch_test(args):
"""Start the game headless (as Steam would), wait, classify, stop. Without the headset worn the OpenXR session
never reaches FOCUSED, so this proves startup, not visuals."""
@@ -4036,20 +4369,31 @@ def cmd_launch_test(args):
keys = key_usage()
unit = f"frameport-test-{appid}"
run(["systemctl", "--user", "reset-failed", unit])
mark_launch_test(anchor)
p = run(["systemd-run", "--user", "--collect", "--quiet", f"--unit={unit}", os.path.join(anchor, "launch.sh")])
if p.returncode:
raise AgentError("could not start the launcher: " + p.stderr[-300:])
start = time.time()
state = "RUNNING"
while time.time() - start < seconds:
app_start = None # when Lepton started the app ("Waiting for app"): the test window counts from there
while True:
time.sleep(3)
now = time.time()
text = open(log, errors="replace").read() if os.path.exists(log) else ""
if "Exited!" in text:
state = "EXITED"
break
if "Early-exit" in text or not_started(text, time.time() - start):
if "Early-exit" in text or not_started(text, now - start):
state = "NEVER_STARTED"
break
if app_start is None and "Waiting for app" in text:
app_start = now
# the first start after an APK change boots Lepton and installs the app first (a minute or more): stopping the
# container then left a half-installed APK ("base.apk is not zip") that never started again (VR HOT)
if app_start is not None and now - app_start >= seconds:
break
if now - start >= seconds + LAUNCH_INSTALL_GRACE:
break
elapsed = round(time.time() - start)
if state == "EXITED": # Lepton dumps the container's logcat buffers (crash backtraces) after "Exited!"
until = time.time() + 15
@@ -4075,6 +4419,7 @@ def launch_test_linux(dep, anchor, log, seconds):
raise AgentError("the app is already running")
unit = f"frameport-test-{appid}"
run(["systemctl", "--user", "reset-failed", unit])
mark_launch_test(anchor)
start = time.time()
p = run(["systemd-run", "--user", "--quiet", f"--unit={unit}", "--property=RemainAfterExit=no",
os.path.join(anchor, "launch.sh")])
@@ -4108,6 +4453,7 @@ def launch_test_pcvr(dep, anchor, log, seconds):
raise AgentError("the game is already running")
unit = f"frameport-test-{appid}"
run(["systemctl", "--user", "reset-failed", unit])
mark_launch_test(anchor)
p = run(["systemd-run", "--user", "--quiet", f"--unit={unit}", "--property=RemainAfterExit=no",
os.path.join(anchor, "launch.sh")])
if p.returncode:
@@ -4146,6 +4492,92 @@ def launch_test_pcvr(dep, anchor, log, seconds):
"kind": "pcvr", "game_process": bool(game_seen)}
SESSION_LOG_MAX = 4 << 20 # bytes of a play session's log the PC triages
SESSION_READ_MAX = 64 << 20 # a longer launch.log is read from its end
SESSION_KEEP = re.compile(r"FrameBridge|focus|pacing|Fatal signal|FATAL|CRASH|#\d\d pc |Abort message|DEVICE.LOST|"
r"AndroidRuntime|vrclient|Start proc|lepton", re.I)
KERNEL_GPU = re.compile(r"hangcheck|gpu fault|adreno|kgsl|msm_drm.*(hang|recover)", re.I)
def slice_session_log(text, max_bytes=SESSION_LOG_MAX):
"""A long play session's log cut to max_bytes: its start (a quarter) and its end (half) whole, from the middle
only FrameBridge's, focus, pacing and crash lines (oldest first, while they fit). Returns (text, cut)."""
if len(text) <= max_bytes:
return text, False
head = text[:max_bytes // 4]
head = head[:head.rfind("\n") + 1]
tail = text[-(max_bytes // 2):]
tail = tail[tail.find("\n") + 1:]
middle = text[len(head):len(text) - len(tail)]
budget, kept = max_bytes - len(head) - len(tail) - 200, []
for line in middle.splitlines():
if SESSION_KEEP.search(line):
budget -= len(line) + 1
if budget < 0:
break
kept.append(line)
note = f"[FramePort: {len(middle)} bytes in the middle of this session cut, {len(kept)} lines kept]\n"
return head + note + "".join(ln + "\n" for ln in kept) + tail, True
def session_kernel_lines(start, end):
"""Kernel GPU lines (hangs, faults, recoveries) logged during a play session."""
until = (end or time.time()) + 120
try:
text = run(["journalctl", "-k", "--since", f"@{int(start)}", "--until", f"@{int(until)}", "-q", "--no-pager",
"-o", "short-unix"]).stdout
except OSError:
return ""
lines = [ln for ln in text.splitlines() if KERNEL_GPU.search(ln)]
return "".join(f"kernel: {ln}\n" for ln in lines[-200:])
def cmd_session_log(args):
"""The log of the game's newest play session (agent v70), for triage on the PC: {session: {start, end, test},
log: path of the session's log (launch.log sliced to 4 MB; PC VR: + Revive's and the game's own logs), log_size,
cut, crash: that session's crash logcat (tombstones), kernel: GPU hang/fault lines from the kernel log}.
session is None when the game was never played."""
pkg = check_pkg(args["package"])
dep = deployment(pkg)
if not dep:
raise AgentError(f"{pkg} is not installed")
anchor, base = os.path.join(ANCHORS, pkg), dep["base"]
session = last_play(anchor)
out = {"session": session, "log": None, "log_size": 0, "cut": False, "crash": "", "kernel": "",
"kind": dep.get("kind", "quest")}
if not session:
return out
start, end = session["start"], session["end"]
parts = []
log = os.path.join(base, "launch.log")
if os.path.exists(log) and os.path.getmtime(log) >= start - 5: # else no log of this session is left
size = os.path.getsize(log)
with open(log, "rb") as f:
if size > SESSION_READ_MAX:
f.seek(size - SESSION_READ_MAX)
parts.append(f.read().decode("utf-8", "replace"))
if dep.get("kind") == "pcvr":
for rel in PCVR_LOGS:
path = os.path.join(base, rel)
if os.path.exists(path) and os.path.getmtime(path) >= start - 5:
parts.append(f"===== {rel}\n" + (_tail(path, 400000) or ""))
parts += game_logs(base, since=start - 5)
text, cut = slice_session_log("\n".join(parts), int(args.get("max_bytes", SESSION_LOG_MAX)))
path = os.path.join(base, "session.log")
with open(path, "w") as f:
f.write(text)
out.update(log=path, log_size=os.path.getsize(path), cut=cut)
crash = os.path.join(STEAM, "logs", "lepton-logcats", f"steamlaunch-{dep['appid']}", "logcat-crash.log")
try:
mtime = os.path.getmtime(crash)
if start - 1 <= mtime <= (end or time.time()) + 120:
out["crash"] = _tail(crash, 256 * 1024) or ""
except OSError:
pass
out["kernel"] = session_kernel_lines(start, end)
return out
def steam_library_report():
"""Why a game installed by FramePort may be missing from Steam or fail with "Game configuration unavailable"
(GitHub #21/#30): where Steam really lives, Steam's client version/beta, each account's shortcuts.vdf (when it
@@ -4647,6 +5079,51 @@ def user_opened_dashboard(log, pos):
return False, pos
LOGCAT_EOF = "logcat: Unexpected EOF"
def logcat_keeper(log, appid, parent, poll=2.0, restarts=5, popen=None):
"""Keep launch.log filling when Lepton's logcat mirror dies while the game runs (LOGCAT_LINE): once the log shows
LOGCAT_EOF after "Waiting for app", read the container's logcat ourselves (from its last 2000 lines, so the start
of the game isn't lost) and append it; restart it if it ends while the game still runs (at most `restarts` times).
Ends with the launcher."""
popen = popen or subprocess.Popen
container = f"lepton-steamlaunch-{appid}"
def alive():
try:
os.kill(int(parent), 0)
return True
except (OSError, ValueError):
return False
proc, started = None, 0
while alive():
if proc is None or proc.poll() is not None:
try:
with open(log, errors="replace") as f:
text = f.read()
except OSError:
text = ""
i = text.find("Waiting for app")
if i >= 0 and LOGCAT_EOF in text[i:] and started < restarts:
started += 1
with open(log, "a") as f:
f.write(f"FramePort: Lepton's logcat ended; reading {container}'s logcat again ({started})\n")
out = open(log, "ab")
try:
proc = popen(["podman", "exec", container, "logcat", "-v", "threadtime", "-T", "2000"],
stdout=out, stderr=subprocess.STDOUT, stdin=subprocess.DEVNULL)
except OSError as exc:
print(f"logcat_keeper: {exc}", flush=True)
proc = None
finally:
out.close()
time.sleep(poll)
if proc is not None and proc.poll() is None:
proc.terminate()
def dashboard_worker(log, parent, wait_start=240, window=120, poll=0.5, ui_log=None, max_hides=10):
"""Close SteamVR's dashboard (Steam's "Resume game" frame menu) that opens when the game submits its first VR
frame: watch from FrameBridge's first "new layer:" line (the first submitted frame; Steam showed the menu ~0.3 s
@@ -5503,6 +5980,9 @@ def main():
if len(sys.argv) >= 3 and sys.argv[1] == "_xr_probe":
xr_probe(sys.argv[2])
return 0
if len(sys.argv) >= 5 and sys.argv[1] == "_logcat_keeper":
logcat_keeper(sys.argv[2], sys.argv[3], sys.argv[4])
return 0
if len(sys.argv) >= 4 and sys.argv[1] == "_dashboard_worker":
dashboard_worker(sys.argv[2], sys.argv[3])
return 0
+9 -2
View File
@@ -1,15 +1,22 @@
5becb96ee86fbda0ce98c0e0fd064f8ba092314aceaa400e3dcc785705dc3c23 ./arm64-v8a/libVkLayer_fp_shaderfix.so
e7554c6343ee2989b0a273ee6230e65c25bfe6499eefd00de19f5f0fee58754f ./arm64-v8a/libfp_langpack.so
321da502e0f8f46f0880aad39fe6b84bdef88f925164568814cf704a1b31a577 ./arm64-v8a/libfp_ovrp.so
40defdaddcda53bd2649eb48076fae1622bfc2bfc88e9e03c94fc8b45af2a4f2 ./arm64-v8a/libfp_ovrtrace.so
7522a7cfb236e48d3442d418c4820cd37760a9627c6bdef80fb0df82df5fd826 ./arm64-v8a/libfp_vk.so
383054f8b3b41dde76d062c71856cd3163655e50009c08454bc1793f393ead65 ./arm64-v8a/libfpg.so
5432674a59d02f411cd853a5dc57e3fa547d1ac518f25bf433fc54c43677177a ./arm64-v8a/libfpglmv.so
8a8f6b1da8952cb3933a5b53558424a5fc56043b2527a16bb6dd62a00d2de01a ./arm64-v8a/libframe_xrshim.so
fc559dbe0b87eecc3641256837293260cefb7c2ce7b21d808d10edd2a2dba9fc ./arm64-v8a/libglshim.so
cc5b493cadefe76ad13fd096d3f8494a140ba593e0e1692db12d284bc548c1cf ./arm64-v8a/libopenxr_loader_generic.so
1655921f4c91f2f336edf0aac66d8df1b2b649a272aafe365c1f2fa7867129de ./arm64-v8a/libopenxr_loader_generic.so
1feaeafad467c4cafdf2b018a4d84b0bee200c3f711697b4ce97e66a3ba256ca ./arm64-v8a/libovrplatformcompat.so
aa4dc0020c77e12d41ef6ce80b23ad90c9cb7e882338eddf2261efe8645cf38d ./arm64-v8a/libvrapi.so
c10412dd76a65a1d587b7ed226367d1a6f2bec238c733c97ee67eb8870c868e8 ./armeabi-v7a/libopenxr_loader_generic.so
7943c6825e1c2841e54627f96acbd0754a3c06bb608c47f7aa15007aec2191a5 ./armeabi-v7a/libopenxr_loader_generic.so
1871eae093432d277da4bc751bf5f3269dfcf11f9168260b0c3caadb0dedb19d ./dex/oculusos-stubs.dex
b634ab5640e258563c536e658cad87080553df6f34f62269a21d554844e58bfe ./hevc/COPYING.FFmpeg
141de01f0d40b97d4f9a720db5ab8ea442f6aa35db5272048899292884994a1c ./hevc/libstagefrighthw.so
4516971bbb2b635e19b14d2d37b9353962876f7de02043e7457327052c1fcbc0 ./hevc/manifest.json
46c3dcad2c43cc30bea3b3680b362ed84a99c15d60714bbbbb422c80ecf90405 ./hevc/media_codecs_frameport.xml
529ea35d5d82474afe9e09ad1216d269317f56dd24a05fb100fced52b7b4dbca ./hevc/podman.py.txt
1aa733117cf57ccff7cf23f0425dbfd73b0332a3ef1c905ceeca0ccd0449c4e0 ./linux-arm64/XR_APILAYER_FRAMEPORT_timefix.json
28c2430a02bbd8902c5bfb9562c6fd0e318654f9e05c095bfeb94b0450ab1b07 ./linux-arm64/libxr_frameport_timefix.so
b10b3a5c10c3339fc63fd9f6cb4d01ea29be11a863d0ebad1389ea69fd471940 ./linux-arm64-bin/fp_venc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+502
View File
@@ -0,0 +1,502 @@
GNU LESSER GENERAL PUBLIC LICENSE
Version 2.1, February 1999
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
[This is the first released version of the Lesser GPL. It also counts
as the successor of the GNU Library Public License, version 2, hence
the version number 2.1.]
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
Licenses are intended to guarantee your freedom to share and change
free software--to make sure the software is free for all its users.
This license, the Lesser General Public License, applies to some
specially designated software packages--typically libraries--of the
Free Software Foundation and other authors who decide to use it. You
can use it too, but we suggest you first think carefully about whether
this license or the ordinary General Public License is the better
strategy to use in any particular case, based on the explanations below.
When we speak of free software, we are referring to freedom of use,
not price. Our General Public Licenses are designed to make sure that
you have the freedom to distribute copies of free software (and charge
for this service if you wish); that you receive source code or can get
it if you want it; that you can change the software and use pieces of
it in new free programs; and that you are informed that you can do
these things.
To protect your rights, we need to make restrictions that forbid
distributors to deny you these rights or to ask you to surrender these
rights. These restrictions translate to certain responsibilities for
you if you distribute copies of the library or if you modify it.
For example, if you distribute copies of the library, whether gratis
or for a fee, you must give the recipients all the rights that we gave
you. You must make sure that they, too, receive or can get the source
code. If you link other code with the library, you must provide
complete object files to the recipients, so that they can relink them
with the library after making changes to the library and recompiling
it. And you must show them these terms so they know their rights.
We protect your rights with a two-step method: (1) we copyright the
library, and (2) we offer you this license, which gives you legal
permission to copy, distribute and/or modify the library.
To protect each distributor, we want to make it very clear that
there is no warranty for the free library. Also, if the library is
modified by someone else and passed on, the recipients should know
that what they have is not the original version, so that the original
author's reputation will not be affected by problems that might be
introduced by others.
Finally, software patents pose a constant threat to the existence of
any free program. We wish to make sure that a company cannot
effectively restrict the users of a free program by obtaining a
restrictive license from a patent holder. Therefore, we insist that
any patent license obtained for a version of the library must be
consistent with the full freedom of use specified in this license.
Most GNU software, including some libraries, is covered by the
ordinary GNU General Public License. This license, the GNU Lesser
General Public License, applies to certain designated libraries, and
is quite different from the ordinary General Public License. We use
this license for certain libraries in order to permit linking those
libraries into non-free programs.
When a program is linked with a library, whether statically or using
a shared library, the combination of the two is legally speaking a
combined work, a derivative of the original library. The ordinary
General Public License therefore permits such linking only if the
entire combination fits its criteria of freedom. The Lesser General
Public License permits more lax criteria for linking other code with
the library.
We call this license the "Lesser" General Public License because it
does Less to protect the user's freedom than the ordinary General
Public License. It also provides other free software developers Less
of an advantage over competing non-free programs. These disadvantages
are the reason we use the ordinary General Public License for many
libraries. However, the Lesser license provides advantages in certain
special circumstances.
For example, on rare occasions, there may be a special need to
encourage the widest possible use of a certain library, so that it becomes
a de-facto standard. To achieve this, non-free programs must be
allowed to use the library. A more frequent case is that a free
library does the same job as widely used non-free libraries. In this
case, there is little to gain by limiting the free library to free
software only, so we use the Lesser General Public License.
In other cases, permission to use a particular library in non-free
programs enables a greater number of people to use a large body of
free software. For example, permission to use the GNU C Library in
non-free programs enables many more people to use the whole GNU
operating system, as well as its variant, the GNU/Linux operating
system.
Although the Lesser General Public License is Less protective of the
users' freedom, it does ensure that the user of a program that is
linked with the Library has the freedom and the wherewithal to run
that program using a modified version of the Library.
The precise terms and conditions for copying, distribution and
modification follow. Pay close attention to the difference between a
"work based on the library" and a "work that uses the library". The
former contains code derived from the library, whereas the latter must
be combined with the library in order to run.
GNU LESSER GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License Agreement applies to any software library or other
program which contains a notice placed by the copyright holder or
other authorized party saying it may be distributed under the terms of
this Lesser General Public License (also called "this License").
Each licensee is addressed as "you".
A "library" means a collection of software functions and/or data
prepared so as to be conveniently linked with application programs
(which use some of those functions and data) to form executables.
The "Library", below, refers to any such software library or work
which has been distributed under these terms. A "work based on the
Library" means either the Library or any derivative work under
copyright law: that is to say, a work containing the Library or a
portion of it, either verbatim or with modifications and/or translated
straightforwardly into another language. (Hereinafter, translation is
included without limitation in the term "modification".)
"Source code" for a work means the preferred form of the work for
making modifications to it. For a library, complete source code means
all the source code for all modules it contains, plus any associated
interface definition files, plus the scripts used to control compilation
and installation of the library.
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running a program using the Library is not restricted, and output from
such a program is covered only if its contents constitute a work based
on the Library (independent of the use of the Library in a tool for
writing it). Whether that is true depends on what the Library does
and what the program that uses the Library does.
1. You may copy and distribute verbatim copies of the Library's
complete source code as you receive it, in any medium, provided that
you conspicuously and appropriately publish on each copy an
appropriate copyright notice and disclaimer of warranty; keep intact
all the notices that refer to this License and to the absence of any
warranty; and distribute a copy of this License along with the
Library.
You may charge a fee for the physical act of transferring a copy,
and you may at your option offer warranty protection in exchange for a
fee.
2. You may modify your copy or copies of the Library or any portion
of it, thus forming a work based on the Library, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) The modified work must itself be a software library.
b) You must cause the files modified to carry prominent notices
stating that you changed the files and the date of any change.
c) You must cause the whole of the work to be licensed at no
charge to all third parties under the terms of this License.
d) If a facility in the modified Library refers to a function or a
table of data to be supplied by an application program that uses
the facility, other than as an argument passed when the facility
is invoked, then you must make a good faith effort to ensure that,
in the event an application does not supply such function or
table, the facility still operates, and performs whatever part of
its purpose remains meaningful.
(For example, a function in a library to compute square roots has
a purpose that is entirely well-defined independent of the
application. Therefore, Subsection 2d requires that any
application-supplied function or table used by this function must
be optional: if the application does not supply it, the square
root function must still compute square roots.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Library,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Library, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote
it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Library.
In addition, mere aggregation of another work not based on the Library
with the Library (or with a work based on the Library) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may opt to apply the terms of the ordinary GNU General Public
License instead of this License to a given copy of the Library. To do
this, you must alter all the notices that refer to this License, so
that they refer to the ordinary GNU General Public License, version 2,
instead of to this License. (If a newer version than version 2 of the
ordinary GNU General Public License has appeared, then you can specify
that version instead if you wish.) Do not make any other change in
these notices.
Once this change is made in a given copy, it is irreversible for
that copy, so the ordinary GNU General Public License applies to all
subsequent copies and derivative works made from that copy.
This option is useful when you wish to copy part of the code of
the Library into a program that is not a library.
4. You may copy and distribute the Library (or a portion or
derivative of it, under Section 2) in object code or executable form
under the terms of Sections 1 and 2 above provided that you accompany
it with the complete corresponding machine-readable source code, which
must be distributed under the terms of Sections 1 and 2 above on a
medium customarily used for software interchange.
If distribution of object code is made by offering access to copy
from a designated place, then offering equivalent access to copy the
source code from the same place satisfies the requirement to
distribute the source code, even though third parties are not
compelled to copy the source along with the object code.
5. A program that contains no derivative of any portion of the
Library, but is designed to work with the Library by being compiled or
linked with it, is called a "work that uses the Library". Such a
work, in isolation, is not a derivative work of the Library, and
therefore falls outside the scope of this License.
However, linking a "work that uses the Library" with the Library
creates an executable that is a derivative of the Library (because it
contains portions of the Library), rather than a "work that uses the
library". The executable is therefore covered by this License.
Section 6 states terms for distribution of such executables.
When a "work that uses the Library" uses material from a header file
that is part of the Library, the object code for the work may be a
derivative work of the Library even though the source code is not.
Whether this is true is especially significant if the work can be
linked without the Library, or if the work is itself a library. The
threshold for this to be true is not precisely defined by law.
If such an object file uses only numerical parameters, data
structure layouts and accessors, and small macros and small inline
functions (ten lines or less in length), then the use of the object
file is unrestricted, regardless of whether it is legally a derivative
work. (Executables containing this object code plus portions of the
Library will still fall under Section 6.)
Otherwise, if the work is a derivative of the Library, you may
distribute the object code for the work under the terms of Section 6.
Any executables containing that work also fall under Section 6,
whether or not they are linked directly with the Library itself.
6. As an exception to the Sections above, you may also combine or
link a "work that uses the Library" with the Library to produce a
work containing portions of the Library, and distribute that work
under terms of your choice, provided that the terms permit
modification of the work for the customer's own use and reverse
engineering for debugging such modifications.
You must give prominent notice with each copy of the work that the
Library is used in it and that the Library and its use are covered by
this License. You must supply a copy of this License. If the work
during execution displays copyright notices, you must include the
copyright notice for the Library among them, as well as a reference
directing the user to the copy of this License. Also, you must do one
of these things:
a) Accompany the work with the complete corresponding
machine-readable source code for the Library including whatever
changes were used in the work (which must be distributed under
Sections 1 and 2 above); and, if the work is an executable linked
with the Library, with the complete machine-readable "work that
uses the Library", as object code and/or source code, so that the
user can modify the Library and then relink to produce a modified
executable containing the modified Library. (It is understood
that the user who changes the contents of definitions files in the
Library will not necessarily be able to recompile the application
to use the modified definitions.)
b) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (1) uses at run time a
copy of the library already present on the user's computer system,
rather than copying library functions into the executable, and (2)
will operate properly with a modified version of the library, if
the user installs one, as long as the modified version is
interface-compatible with the version that the work was made with.
c) Accompany the work with a written offer, valid for at
least three years, to give the same user the materials
specified in Subsection 6a, above, for a charge no more
than the cost of performing this distribution.
d) If distribution of the work is made by offering access to copy
from a designated place, offer equivalent access to copy the above
specified materials from the same place.
e) Verify that the user has already received a copy of these
materials or that you have already sent this user a copy.
For an executable, the required form of the "work that uses the
Library" must include any data and utility programs needed for
reproducing the executable from it. However, as a special exception,
the materials to be distributed need not include anything that is
normally distributed (in either source or binary form) with the major
components (compiler, kernel, and so on) of the operating system on
which the executable runs, unless that component itself accompanies
the executable.
It may happen that this requirement contradicts the license
restrictions of other proprietary libraries that do not normally
accompany the operating system. Such a contradiction means you cannot
use both them and the Library together in an executable that you
distribute.
7. You may place library facilities that are a work based on the
Library side-by-side in a single library together with other library
facilities not covered by this License, and distribute such a combined
library, provided that the separate distribution of the work based on
the Library and of the other library facilities is otherwise
permitted, and provided that you do these two things:
a) Accompany the combined library with a copy of the same work
based on the Library, uncombined with any other library
facilities. This must be distributed under the terms of the
Sections above.
b) Give prominent notice with the combined library of the fact
that part of it is a work based on the Library, and explaining
where to find the accompanying uncombined form of the same work.
8. You may not copy, modify, sublicense, link with, or distribute
the Library except as expressly provided under this License. Any
attempt otherwise to copy, modify, sublicense, link with, or
distribute the Library is void, and will automatically terminate your
rights under this License. However, parties who have received copies,
or rights, from you under this License will not have their licenses
terminated so long as such parties remain in full compliance.
9. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Library or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Library (or any work based on the
Library), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Library or works based on it.
10. Each time you redistribute the Library (or any work based on the
Library), the recipient automatically receives a license from the
original licensor to copy, distribute, link with or modify the Library
subject to these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties with
this License.
11. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Library at all. For example, if a patent
license would not permit royalty-free redistribution of the Library by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Library.
If any portion of this section is held invalid or unenforceable under any
particular circumstance, the balance of the section is intended to apply,
and the section as a whole is intended to apply in other circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
12. If the distribution and/or use of the Library is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Library under this License may add
an explicit geographical distribution limitation excluding those countries,
so that distribution is permitted only in or among countries not thus
excluded. In such case, this License incorporates the limitation as if
written in the body of this License.
13. The Free Software Foundation may publish revised and/or new
versions of the Lesser General Public License from time to time.
Such new versions will be similar in spirit to the present version,
but may differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the Library
specifies a version number of this License which applies to it and
"any later version", you have the option of following the terms and
conditions either of that version or of any later version published by
the Free Software Foundation. If the Library does not specify a
license version number, you may choose any version ever published by
the Free Software Foundation.
14. If you wish to incorporate parts of the Library into other free
programs whose distribution conditions are incompatible with these,
write to the author to ask for permission. For software which is
copyrighted by the Free Software Foundation, write to the Free
Software Foundation; we sometimes make exceptions for this. Our
decision will be guided by the two goals of preserving the free status
of all derivatives of our free software and of promoting the sharing
and reuse of software generally.
NO WARRANTY
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Libraries
If you develop a new library, and you want it to be of the greatest
possible use to the public, we recommend making it free software that
everyone can redistribute and change. You can do so by permitting
redistribution under these terms (or, alternatively, under the terms of the
ordinary General Public License).
To apply these terms, attach the following notices to the library. It is
safest to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least the
"copyright" line and a pointer to where the full notice is found.
<one line to give the library's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Also add information on how to contact you by electronic and paper mail.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the library, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the
library `Frob' (a library for tweaking knobs) written by James Random Hacker.
<signature of Ty Coon>, 1 April 1990
Ty Coon, President of Vice
That's all there is to it!
Binary file not shown.
+19
View File
@@ -0,0 +1,19 @@
{
"revision": 8,
"runtime_sha256": "456e912c75cd389abcf6a63bc80e2a53bdc334371d00b200c93680388ae955e2",
"files": {
"libstagefrighthw.so": "141de01f0d40b97d4f9a720db5ab8ea442f6aa35db5272048899292884994a1c",
"podman.py": "529ea35d5d82474afe9e09ad1216d269317f56dd24a05fb100fced52b7b4dbca",
"media_codecs_frameport.xml": "46c3dcad2c43cc30bea3b3680b362ed84a99c15d60714bbbbb422c80ecf90405",
"COPYING.FFmpeg": "b634ab5640e258563c536e658cad87080553df6f34f62269a21d554844e58bfe"
},
"codecs": [
"video/hevc",
"video/avc",
"video/x-vnd.on2.vp9"
],
"build": {
"ndk_revision": "27.2.12479018",
"ffmpeg_source_sha256": "733984395e0dbbe5c046abda2dc49a5544e7e0e1e2366bba849222ae9e3a03b1"
}
}
+32
View File
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<MediaCodecs>
<Decoders>
<MediaCodec name="OMX.frameport.hevc.decoder" type="video/hevc" rank="64">
<Limit name="size" min="128x128" max="8192x8192" />
<Limit name="alignment" value="2x2" />
<Limit name="block-size" value="16x16" />
<Limit name="block-count" range="1-138240" />
<Limit name="blocks-per-second" range="1-7864320" />
<Limit name="bitrate" range="1-245000000" />
<Limit name="concurrent-instances" max="1" />
</MediaCodec>
<MediaCodec name="OMX.frameport.avc.decoder" type="video/avc" rank="64">
<Limit name="size" min="128x128" max="8192x8192" />
<Limit name="alignment" value="2x2" />
<Limit name="block-size" value="16x16" />
<Limit name="block-count" range="1-138240" />
<Limit name="blocks-per-second" range="1-7864320" />
<Limit name="bitrate" range="1-245000000" />
<Limit name="concurrent-instances" max="1" />
</MediaCodec>
<MediaCodec name="OMX.frameport.vp9.decoder" type="video/x-vnd.on2.vp9" rank="64">
<Limit name="size" min="128x128" max="4096x2304" />
<Limit name="alignment" value="2x2" />
<Limit name="block-size" value="16x16" />
<Limit name="block-count" range="1-36864" />
<Limit name="blocks-per-second" range="1-2211840" />
<Limit name="bitrate" range="1-245000000" />
<Limit name="concurrent-instances" max="1" />
</MediaCodec>
</Decoders>
</MediaCodecs>
+146
View File
@@ -0,0 +1,146 @@
#!/usr/bin/python3
"""Add shared codecs to Lepton containers without editing their shared rootfs."""
import hashlib
import json
import os
import re
import shutil
import sys
from pathlib import Path
from xml.etree import ElementTree as ET
def mounts(directory, config, args):
if not args or args[0] != "run":
return []
name = None
for i, arg in enumerate(args):
if arg == "--name" and i + 1 < len(args):
name = args[i + 1]
elif arg.startswith("--name="):
name = arg.partition("=")[2]
if config.get("scope") == "shared":
# The common launcher supplies these values. Do not intercept arbitrary
# Podman containers or depend on a game's package/modified APK.
appid = os.environ.get("SteamAppId", "")
if not re.fullmatch(r"[0-9]+", appid) or name != f"lepton-steamlaunch-{appid}":
return []
app = Path(os.environ.get("STEAM_COMPAT_INSTALL_PATH", ""))
if app.name != "lepton-app" or not app.is_dir():
return []
root_arg = None
for i, arg in enumerate(args):
if arg == "--rootfs" and i + 1 < len(args):
root_arg = args[i + 1]
elif arg.startswith("--rootfs="):
root_arg = arg.partition("=")[2]
if not root_arg or not root_arg.endswith(":O"):
return []
root = Path(root_arg[:-2]).resolve()
else: # old per-game deployments remain compatible during migration
if name != f"lepton-steamlaunch-{config['appid']}":
return []
root = Path(config["lepton"]).resolve().parent / "images" / "rootfs"
expected_root = str(root) + ":O"
if not any(arg in (expected_root, "--rootfs=" + expected_root) for arg in args):
return []
device = Path("/dev/video-dec0")
runtime = root / "vendor/lib64/libstagefright_softomx.so"
upstream_plugin = (root / "vendor/lib64/libstagefrighthw.so").exists()
for i, arg in enumerate(args):
if arg == "--mount" and i + 1 < len(args):
fields = dict(item.split("=", 1) for item in args[i + 1].split(",") if "=" in item)
target = fields.get("destination", fields.get("target"))
if target == "/vendor/lib64/libstagefrighthw.so":
upstream_plugin = True
if target == "/vendor/lib64/libstagefright_softomx.so" and fields.get("source"):
runtime = Path(fields["source"])
if upstream_plugin:
print("FramePort video: using the runtime's hardware codec plugin", file=sys.stderr)
return []
if not device.exists() or hashlib.sha256(runtime.read_bytes()).hexdigest() != config["runtime_sha256"]:
print("FramePort video: device or runtime ABI differs; retaining the stock codecs", file=sys.stderr)
return []
xml = ET.parse(root / "vendor/etc/media_codecs.xml")
if not any(node.get("href") == "media_codecs_frameport.xml" for node in xml.getroot().findall("Include")):
ET.SubElement(xml.getroot(), "Include", href="media_codecs_frameport.xml")
# Immutable plugin versions can serve simultaneous app launches and
# different Lepton installations. Never share a temporary XML filename.
# The version directory stays as the agent verified it: the merged list goes to the user's runtime dir.
root_key = hashlib.sha256(str(root).encode()).hexdigest()[:16]
merged = merged_dir() / f"media_codecs.{root_key}.xml"
temporary = merged.with_suffix(f".{os.getpid()}.tmp")
xml.write(temporary, encoding="utf-8", xml_declaration=True)
temporary.replace(merged)
# Lepton supplies its own /dev tmpfs. A Podman --device node disappears
# beneath it; a bind mount matches Lepton's existing GPU/sound device setup.
result = ["--mount", f"type=bind,source={device},destination=/dev/video-dec0,rw"]
for path, target in (
(directory / "libstagefrighthw.so", "/vendor/lib64/libstagefrighthw.so"),
(merged, "/vendor/etc/media_codecs.xml"),
(directory / "media_codecs_frameport.xml", "/vendor/etc/media_codecs_frameport.xml"),
):
if not path.is_file():
raise FileNotFoundError(f"missing video codec mount: {path}")
result += ["--mount", f"type=bind,source={path},destination={target},ro"]
print("FramePort video: loading the Iris hardware codec plugin for this container", file=sys.stderr)
return result
def merged_dir():
runtime = os.environ.get("XDG_RUNTIME_DIR", "")
base = Path(runtime) if runtime and Path(runtime).is_dir() else Path.home() / ".cache"
path = base / "frameport-video"
path.mkdir(mode=0o700, parents=True, exist_ok=True)
return path
def switched_off(directory):
"""FRAMEPORT_NO_HW_VIDEO=1 (e.g. in a game's Steam launch options) or the Frame-wide switch (FramePort's
setting; the agent writes video-codec/disabled) leave every container with Android's stock codecs."""
if os.environ.get("FRAMEPORT_NO_HW_VIDEO", "") not in ("", "0"):
return True
return directory.parent.name == "versions" and (directory.parent.parent / "disabled").exists()
def real_podman(directory):
"""Find Podman independently of deployment.json, without recursing into this wrapper."""
own_bin = (directory / "bin").resolve()
own_script = Path(__file__).resolve()
# Lepton runs its `podman exec` calls (boot wait, app pid, logcat mirror) with the Android guest's PATH
# (/product/bin:/system/bin:...), which has no host Podman: the system folders come after PATH. Failing there
# broke Lepton's logcat mirror and app-pid checks, and the container was stopped early.
entries = os.environ.get("PATH", os.defpath).split(os.pathsep) + ["/usr/local/bin", "/usr/bin", "/bin"]
for entry in entries:
folder = Path(entry or os.curdir).resolve()
if folder == own_bin:
continue
found = shutil.which("podman", path=str(folder))
if found:
executable = Path(found).resolve()
if executable.parent != own_bin and executable != own_script:
return str(executable)
raise RuntimeError("no real Podman executable found outside the codec wrapper directory")
def main():
directory = Path(__file__).resolve().parent.parent
args = sys.argv[1:]
fallback = real_podman(directory)
if switched_off(directory):
os.execv(fallback, [fallback, *args])
try:
config = json.loads((directory / "deployment.json").read_text())
podman = Path(config.get("podman", fallback)).resolve()
if podman.parent == (directory / "bin").resolve() or podman == Path(__file__).resolve():
raise ValueError("configured Podman points to the codec wrapper")
extra = mounts(directory, config, args)
launch_args = [args[0], *extra, *args[1:]] if extra else args
os.execv(str(podman), [str(podman), *launch_args])
except Exception as exc: # a codec/configuration failure must never prevent the stock container from starting
print(f"FramePort video: retaining stock codecs: {exc}", file=sys.stderr)
os.execv(fallback, [fallback, *args])
if __name__ == "__main__":
main()
@@ -6,10 +6,14 @@ notes: 'Native OpenXR GLES video player. 360 theatres/videos (equirect2 layers,
at 72 fps (the runtime asks for 4536 px per eye). Confirmed in the headset by the owner (2026-10-01). Its "Internal
Storage" list is /sdcard/4XPlayer: send videos with the game page''s "Add videos".'
details: 'Settings: equirect_emul (GLES worker draws 360 layers into a projection layer), stable_local, focus_hold,
scale 0.75; frame.swapchain_limit for its 7680x3840 theatre swapchains.'
scale 0.75; frame.swapchain_limit for its 7680x3840 theatre swapchains. Its hardware decoding mode (Java MediaCodec,
Vr4pMediaPlayer; its own FFmpeg is the software path) gets the Frame''s video hardware with frame.hw_video_decode
(added 2026-10-09, not yet checked in the headset).'
tested_version: 2.0.22
engine: Other
xr: OpenXR
frame:
- frame.hw_video_decode
adapter:
equirect_emul: 1
stable_local: 1
@@ -17,4 +21,6 @@ adapter:
scale: 0.75
verified:
date: '2026-10-01'
updated: '2026-10-10'
min_app: 0.12.1
source_hint: 4XVR Video Player
@@ -0,0 +1,24 @@
package: com.CyberneticWalrus.DoesitStackMeta
title: Does it Stack?
status: issues
notes: Mixed reality mode does not work (works on Demeo), everything else seems to be OK
tested_version: 1.02 (3683)
engine: Unity
xr: OpenXR
frame:
- frame.unity_text_input
- frame.oculusos
device:
- device.text_input_window
adapter:
haptic_fix: 1
refresh_rate: 90.0
verified:
date: '2026-10-09'
known_good_sha256: e9fce6ac812f1bb317a7a6959be89c5ff54e87f56af9ad4c42dff5fecad4efe8
app: 0.12.0
overport_cli: 1.2.5
frame_build: '20261006.6173745'
agent: 59
issue: 112
source_hint: Does It Stack
+20
View File
@@ -0,0 +1,20 @@
package: com.ForwardXP.nuke
title: Please Don't Touch Anything
status: works
notes: Seems functional
tested_version: '2.2'
engine: Unity
xr: OpenXR
frame:
- frame.unity_text_input
device:
- device.text_input_window
verified:
date: '2026-10-08'
known_good_sha256: 17460c8691b9ff82f6c7ca5597afd0aacf1a94aa30ebb6a6108802991b60f51b
app: 0.12.0
overport_cli: 1.2.5
frame_build: '20261006.6173745'
agent: 59
issue: 106
source_hint: apks
@@ -0,0 +1,21 @@
package: com.FunktronicLabs.TheLightBrigade
title: The Light Brigade
status: issues
notes: Judder in weapons
tested_version: '746'
engine: Unity
xr: OpenXR
frame:
- frame.unity_text_input
device:
- device.text_input_window
adapter:
haptic_fix: 1
verified:
date: '2026-10-09'
app: 0.12.0
overport_cli: 1.2.5
frame_build: '20261007.6125817'
agent: 59
issue: 114
source_hint: The Light Brigade
@@ -1,20 +1,36 @@
package: com.ILMxLAB.VaderImmortal.ep1
title: 'Vader Immortal: Episode I'
status: issues
notes: Starts in VR and plays the intro, then stays on the loading card (Vader's portrait with a progress bar).
details: Unreal Engine 4 (GLES). After the Lucasfilm intro the game shows its loading card and never loads the next
scene; it keeps rendering at 72 fps and ignores input. Ruled out so far - Meta platform requests (all answered),
video playback (the intro is a video and plays), the no-ForceQuit build, frame and swapchain handling. The Frame's
SteamVR runtime also leaks about 20 MB of memory a second while the game runs, which slows it down after a few
minutes. Next steps - find what the loading code waits for in the game's engine library (no symbols) and report
the runtime leak to Valve. GitHub issue 49.
status: works
notes: 'Plays (owner''s headset test): loading card, grip/trigger, hands and the lightspeed sequence fixed. Thumbs
follow the touches with frame.unreal_thumb_touch (Klownicle''s engine fix).'
details: Unreal Engine 4 (GLES). Found and verified in gameplay on a Frame by Klownicle (GitHub issue 49); FramePort
reimplements them as patches that match the game's code exactly and change nothing when it differs. The engine's
Quest checks (IsRunningOnSantaCruz) answer "not a Quest" on the Frame - the menu waited for a Quest-only shader
precompile that never starts (frame.unreal_quest_precompile makes the non-Quest branch report 100 %), and the
game's key map picked the empty Gear VR controls (frame.unreal_quest_keymap keeps the Quest set). Two lightspeed
shaders, as the Frame's GL driver (Zink) compiles them, read loop counters and accumulators before setting them
and hang the GPU; a Vulkan layer under Zink inserts the stores that zero them (frame.zink_shader_fix, zink_shader_fix;
the captured modules are from Lepton 2.8.14 and stop matching if a Frame update changes the driver's output -
the layer logs that). OVRPlugin asks for poses at its own clock (pose_time_fix). Unreal's Oculus input animates the
thumbs from near-touch, which the Frame never reports (frame.unreal_thumb_touch reads the touches instead; binding
the proximity to the touch inputs in FrameBridge didn't reach the game). The Frame's SteamVR runtime
leaks about 20 MB a second while the game runs (reported to Valve).
tested_version: 1.1.1+667256.cl.387770
engine: Unreal
xr: VrApi
alt_overport:
- patch_remove_unreal_force_quit
frame:
- frame.unreal_quest_precompile
- frame.unreal_quest_keymap
- frame.unreal_thumb_touch
- frame.zink_shader_fix
adapter:
pose_time_fix: 1
zink_shader_fix: 12016:b2919629761ad268e0b21c72ac8520f81b76e72c3adc26897f97eae9a3e70a66:3092:0x0003003e,166,82,0x0003003e,177,82,0x0003003e,183,82,0x0003003e,189,82,0x0003003e,256,82,0x0003003e,266,82,0x0003003e,272,82,0x0003003e,278,82,0x0003003e,318,82,0x0003003e,328,82,0x0003003e,334,82,0x0003003e,340,82;11436:6f18be49f2aaa2452f962eb16f7af744c5c22a7b25f37ce681e0d6399e35a869:2932:0x0003003e,164,80,0x0003003e,175,80,0x0003003e,181,80,0x0003003e,187,80,0x0003003e,254,80,0x0003003e,264,80,0x0003003e,270,80,0x0003003e,276,80,0x0003003e,316,80,0x0003003e,326,80,0x0003003e,332,80,0x0003003e,338,80
verified:
date: '2026-10-06'
date: '2026-10-09'
issue: 49
updated: '2026-10-06'
updated: '2026-10-09'
min_app: 0.12.1
source_hint: Vader Immortal- Episode I
@@ -0,0 +1,24 @@
package: com.ILMxLAB.VaderImmortal.ep2
title: 'Vader Immortal: Episode II'
status: works
notes: Plays (owner's headset test, 2026-10-09) with Episode I's fixes, which FramePort finds in this episode's
code too.
details: 'Unreal Engine 4 (GLES), the same engine build as Episode I: the Quest-only shader precompile and key map
(frame.unreal_quest_precompile, frame.unreal_quest_keymap), thumbs from the capacitive touches (frame.unreal_thumb_touch)
and poses at OVRPlugin''s clock (pose_time_fix). Episode I''s lightspeed shader fix doesn''t apply. The campaign
intro once stayed black with its dialogue playing; it rendered on the next run.'
tested_version: 2.0.3+667261.cl.387778
engine: Unreal
xr: VrApi
alt_overport:
- patch_remove_unreal_force_quit
frame:
- frame.unreal_quest_precompile
- frame.unreal_quest_keymap
- frame.unreal_thumb_touch
adapter:
pose_time_fix: 1
verified:
date: '2026-10-09'
min_app: 0.12.1
source_hint: Vader Immortal- Episode II
@@ -0,0 +1,24 @@
package: com.ILMxLAB.VaderImmortal.ep3
title: 'Vader Immortal: Episode III'
status: works
notes: Plays (owner's headset test, 2026-10-09) with Episode I's fixes, which FramePort finds in this episode's
code too.
details: 'Unreal Engine 4 (GLES), the same engine build as Episode I: the Quest-only shader precompile and key map
(frame.unreal_quest_precompile, frame.unreal_quest_keymap), thumbs from the capacitive touches (frame.unreal_thumb_touch)
and poses at OVRPlugin''s clock (pose_time_fix). Episode I''s lightspeed shader fix doesn''t apply. The campaign
intro starts on a black screen with only dialogue: that is the game, not a bug.'
tested_version: 3.0.3+667263.cl.387932
engine: Unreal
xr: VrApi
alt_overport:
- patch_remove_unreal_force_quit
frame:
- frame.unreal_quest_precompile
- frame.unreal_quest_keymap
- frame.unreal_thumb_touch
adapter:
pose_time_fix: 1
verified:
date: '2026-10-09'
min_app: 0.12.1
source_hint: Vader Immortal- Episode III
@@ -0,0 +1,24 @@
package: com.MightyCoconut.WalkaboutMiniGolf
title: Walkabout Mini Golf
status: works
tested_version: '6.7'
engine: Unity
xr: OpenXR
frame:
- frame.unity_text_input
- frame.oculusos
device:
- device.text_input_window
adapter:
controller_models: 1
haptic_fix: 1
scale: 1.5
verified:
date: '2026-10-08'
known_good_sha256: cf3b5cbe131af8a2baaa3f5c665b1c7001c8b299473abfcf98d90e3c02b08a2f
app: 0.12.0
overport_cli: 1.2.5
frame_build: '20261007.6125817'
agent: 59
issue: 111
source_hint: Walkabout Mini Golf
+12 -9
View File
@@ -1,12 +1,14 @@
package: com.PixelToys.BattleSisters
title: BattleSisters
status: works
notes: Starts in VR; controller buttons and vibration work.
details: Unity 2019.4 with Unity's built-in Oculus support. frame.unity_oculus_check starts VR (Meta's system-app check),
adds the frame wait its legacy loop never makes (without it the GPU hung, black screen) and lets Unity's Oculus
input accept Lepton's device model (it only reported controllers on a device named "Oculus ...", so buttons were
dead). haptic_fix stops the first controller vibration from freezing the Frame (OVRPort's loader read its duration
in nanoseconds as seconds and the game ran out of memory).
notes: Plays; controller buttons and vibration work, hands follow the controllers (pose_time_fix).
details: Unity 2019.4 with Unity's built-in Oculus support. frame.unity_oculus_check starts VR (Meta's system-app
check), adds the frame wait its legacy loop never makes (without it the GPU hung, black screen) and lets Unity's
Oculus input accept Lepton's device model (it only reported controllers on a device named "Oculus ...", so buttons
were dead). haptic_fix stops the first controller vibration from freezing the Frame (OVRPort's loader read its
duration in nanoseconds as seconds and the game ran out of memory). With pose_time_fix the hands follow the controllers
- OVRPlugin asked for hand poses at Android's monotonic "now", which on SteamOS 0.4.5 is 2.56 s behind the runtime's
XrTime, so the hands lagged far behind.
tested_version: 1.2.4
engine: Unity
xr: VrApi
@@ -18,9 +20,10 @@ frame:
- frame.unity_gl_shim
adapter:
haptic_fix: 1
pose_time_fix: 1
verified:
date: '2026-10-06'
date: '2026-10-08'
issue: 48
updated: '2026-10-06'
min_app: 0.11.1
updated: '2026-10-08'
min_app: 0.12.1
source_hint: Battle Sister
+22
View File
@@ -0,0 +1,22 @@
package: com.ToastVR.Matilda
title: Max Mustard
status: works
tested_version: 1.1.0
engine: Unity
xr: OpenXR
frame:
- frame.unity_text_input
device:
- device.text_input_window
adapter:
haptic_fix: 1
verified:
date: '2026-10-08'
known_good_sha256: 9a67459fa36c3b9ac0d035e6c43b1809b39772699333e8cfd7d2a4d7f17926a7
app: 0.12.0
overport_cli: 1.2.5
frame_build: '20261007.6125817'
agent: 59
issue: 110
updated: '2026-10-09'
source_hint: com.ToastVR.Matilda
+12 -5
View File
@@ -1,16 +1,23 @@
package: com.YourCompany.RoboRecall
title: Robo Recall
tested_version: '1.0'
source_hint: 'Robo Recall- Unplugged'
engine: Unreal
xr: VrApi
status: works
notes: Needed the LAUNCHER category fix.
details: Source APK is a community 'patch+savefix+90Hz' build.
details: Source APK is a community 'patch+savefix+90Hz' build. Shares Vader Immortal's Unreal 4 Oculus input (GitHub
49) - thumbs follow the touches (frame.unreal_thumb_touch) and controller poses are located at the right time
(pose_time_fix); added 2026-10-09 from Vader's headset results, not yet checked in this game.
tested_version: '1.0'
engine: Unreal
xr: VrApi
alt_overport:
- patch_remove_unreal_force_quit
frame:
- frame.unreal_thumb_touch
adapter:
pose_time_fix: 1
verified:
date: '2026-09-28'
overport_cli: 1.2.3
overport_runtime: 3.4.3-23204ea
known_good_sha256: 4ce6e3563da131e288645f4b62a634ac98043e55bc42b7c0ad5f461207d5f53c
updated: '2026-10-09'
source_hint: Robo Recall- Unplugged
+23
View File
@@ -0,0 +1,23 @@
package: com.asg.clockworkdev
title: Clockwork
status: works
tested_version: '1.29'
engine: Unity
xr: OpenXR
frame:
- frame.unity_text_input
- frame.unity_runtime_msaa_off
- frame.unity_gl_shim
device:
- device.text_input_window
adapter:
haptic_fix: 1
verified:
date: '2026-10-09'
known_good_sha256: 99a14eed320ba267153963c2d87d4e11e943b9920d48dfd5352c681de28ba95e
app: 0.12.1.dev203
overport_cli: 1.2.5
frame_build: '20261007.6125817'
agent: 67
issue: 116
source_hint: com.asg.clockworkdev
+15 -5
View File
@@ -1,16 +1,26 @@
package: com.camouflaj.manta
title: 'Batman: Arkham Shadow'
tested_version: 1.4.1-350961
source_hint: 'Batman- Arkham Shadow'
engine: Unity
xr: OpenXR
status: works
notes: Large data set (~27 GiB) incl. all language packs.
details: Uses Meta XR Audio (Wwise), handled by patch_meta_xr_audio. Includes all language packs (~28 GB).
details: 'Uses Meta XR Audio (Wwise), handled by patch_meta_xr_audio. Cutscenes are 8K HEVC panoramas: frame.hw_video_decode
decodes them on the Frame''s hardware, adapter.surface_native shows them in stereo (PRs #96, #128). Includes all
language packs (~28 GB). sync_guard (to test, GitHub #102) - a reporter''s game quit to Steam''s waiting screen
after the Frame runtime crashed in xrSyncActions (CVRInputLatest::UpdateActionState), the input race Myst had.'
tested_version: 1.4.1-350961
engine: Unity
xr: OpenXR
overport_extra:
- patch_disable_space_warp
frame:
- frame.hw_video_decode
adapter:
sync_guard: 1
surface_native: 1
verified:
date: '2026-09-28'
overport_cli: 1.2.3
overport_runtime: 3.4.3-23204ea
known_good_sha256: 796d1cab08f614d72c50d9702974c719c0908f5de91183cfe02d1fd5eb09551a
updated: '2026-10-10'
min_app: 0.12.1
source_hint: Batman- Arkham Shadow
+10 -1
View File
@@ -1,14 +1,23 @@
package: com.drbeef.doom3quest
title: Doom3Quest
status: issues
notes: PDA shows black screen.
notes: 'HUD and PDA show with frame.gl_multiview_fbo (Xandrix1987''s headset test, GitHub 77, no frame-rate drop
with the PDA open). Open: the player sometimes switches between walking and running.'
details: Doom3Quest compiles every vertex shader for two views (OVR_multiview) and draws its HUD/PDA into single-view
framebuffers. Mesa (the Frame's GL) rejects that combination as the spec requires and drops the draw, so they
stayed black; frame.gl_multiview_fbo draws those passes with a single-view copy of the shader. Xandrix1987's framebuffer.cpp
fix went upstream as a PR to Team-Beef-Studios/Doom3Quest.
tested_version: 1.4.8
engine: Other
xr: OpenXR
frame:
- frame.gl_multiview_fbo
verified:
date: '2026-10-06'
known_good_sha256: 3c733f5cd08b6fa5d9e2775b1c1aee36b5943518b5d8451ba87e3c59a702afdf
app: 0.12.0
overport_cli: 1.2.3
issue: 77
updated: '2026-10-09'
min_app: 0.12.1
source_hint: doom3quest148
+11 -5
View File
@@ -1,18 +1,24 @@
package: com.forcefieldxr.timestall
title: Time Stall
tested_version: '1.0'
source_hint: Time Stall
engine: Unreal
xr: VrApi
status: issues
notes: Both eyes distort during movement (unresolved).
details: Legacy VrApi via OVRPlugin.
details: Legacy VrApi via OVRPlugin. Shares Vader Immortal's Unreal 4 Oculus input (GitHub 49) - thumbs follow the
touches (frame.unreal_thumb_touch) and controller poses are located at the right time (pose_time_fix); added 2026-10-09
from Vader's headset results, not yet checked in this game.
tested_version: '1.0'
engine: Unreal
xr: VrApi
alt_overport:
- patch_remove_unreal_force_quit
frame:
- frame.unreal_thumb_touch
- frame.nodebug
adapter:
pose_time_fix: 1
verified:
date: '2026-09-28'
overport_cli: 1.2.3
overport_runtime: 3.4.3-23204ea
known_good_sha256: 50c4d05b663b2f1851f5a7d650a89fd34587d65fafba13cc58671c96f7016db6
updated: '2026-10-09'
source_hint: Time Stall
+24
View File
@@ -0,0 +1,24 @@
package: com.harmonixmusic.kata
title: Audica
status: works
tested_version: 1.0.3.4
engine: Unity
xr: VrApi
frame:
- frame.unity_no_msaa
- frame.unity_oculus_check
- frame.unity_text_input
- frame.unity_runtime_msaa_off
- frame.unity_gl_shim
device:
- device.text_input_window
adapter:
haptic_fix: 1
verified:
date: '2026-10-09'
known_good_sha256: bc2c00fe049fd97643a296e622e3a90e08f0bd796ee454b0278525e9d72f8139
app: 0.12.0
overport_cli: 1.2.5
frame_build: '20261007.6125817'
agent: 59
issue: 126
+27
View File
@@ -0,0 +1,27 @@
package: com.ilmxlab.tales
title: 'Star Wars: Tales from the Galaxy''s Edge'
status: unknown
notes: Not working yet - after the intro logos and a loading animation the picture goes black (GitHub issue 61).
Gets the controller fixes found for Vader Immortal (same studio) to test.
details: Unreal Engine 4 (GLES) by ILMxLAB, like Vader Immortal, but a different engine build - it has none of Vader's
Quest-only branches (no GetQuestShaderPrecompilePercent or RPOC key map; it precompiles shaders through Unreal's
own pipeline cache), so frame.unreal_quest_precompile/_keymap don't apply. Its seasons and Wwise banks are Meta
platform asset files (frame.asset_files). Vader's OVRPlugin findings apply to it as well - poses asked for at
OVRPlugin's own clock (pose_time_fix) and thumbs from near-touch, which the Frame never reports (frame.unreal_thumb_touch).
Ruled out for the black picture so far (see the diagnostics in issue 61) - asset-file paks, Valve's foveation,
GL errors; the game's own eye image reads back black.
tested_version: 1.1.9+734762.cl.439699
engine: Unreal
xr: VrApi
alt_overport:
- patch_remove_unreal_force_quit
frame:
- frame.asset_files
- frame.unreal_thumb_touch
adapter:
pose_time_fix: 1
verified:
issue: 61
updated: '2026-10-09'
min_app: 0.12.1
source_hint: Star Wars- Tales from the Galaxys Edge
@@ -0,0 +1,24 @@
package: com.markschramm.gravitylab
title: Gravity Lab
status: works
notes: Works great, along with passthrough mode
tested_version: '1.221'
engine: Unity
xr: OpenXR
frame:
- frame.unity_text_input
- frame.unity_runtime_msaa_off
- frame.unity_gl_shim
device:
- device.text_input_window
adapter:
haptic_fix: 1
verified:
date: '2026-10-09'
known_good_sha256: 82c95ee7487a130b6e37b967dd97c8362bf4d7e873fcff823f2c7877a62ff99f
app: 0.12.0
overport_cli: 1.2.5
frame_build: '20261007.6125817'
agent: 59
issue: 113
source_hint: Gravity Lab
+12 -5
View File
@@ -1,18 +1,25 @@
package: com.nDreams.PhantomQuest
title: 'Phantom: Covert Ops'
tested_version: '1.2'
source_hint: 'Phantom- Covert Ops'
engine: Unreal
xr: VrApi
status: issues
notes: DLC/store button crashes (no Meta store). Installs the no-ForceQuit build.
details: The regular build quits itself on the Frame (System.exit after a failed platform check), so the no-ForceQuit
build is installed.
build is installed. Shares Vader Immortal's Unreal 4 Oculus input (GitHub 49) - thumbs follow the touches (frame.unreal_thumb_touch)
and controller poses are located at the right time (pose_time_fix); added 2026-10-09 from Vader's headset results,
not yet checked in this game.
tested_version: '1.2'
engine: Unreal
xr: VrApi
alt_overport:
- patch_remove_unreal_force_quit
use_alt: true
frame:
- frame.unreal_thumb_touch
adapter:
pose_time_fix: 1
verified:
date: '2026-09-28'
overport_cli: 1.2.3
overport_runtime: 3.4.3-23204ea
known_good_sha256: bb02b20a23fbe5e7a580ecde15a3cd015a4183421a51aab4a4dbcddbe7a09d1d
updated: '2026-10-09'
source_hint: Phantom- Covert Ops
+22
View File
@@ -0,0 +1,22 @@
package: com.tvb.cubism
title: cubism
status: works
tested_version: 1.8.0
engine: Unity
xr: OpenXR
frame:
- frame.unity_text_input
device:
- device.text_input_window
adapter:
haptic_fix: 1
scale: 2.0
verified:
date: '2026-10-09'
known_good_sha256: e4e000392e53111a991c1c78653c9241b8007f81dcdb126a4f4b2003033f5a6e
app: 0.12.0
overport_cli: 1.2.5
frame_build: '20261007.6125817'
agent: 59
issue: 121
source_hint: com.tvb.cubism
+21
View File
@@ -0,0 +1,21 @@
package: jp.co.amata.nvr
title: The Tale of Onogoro
status: works
tested_version: 1.1.0248
engine: Unity
xr: OpenXR
frame:
- frame.unity_text_input
device:
- device.text_input_window
adapter:
haptic_fix: 1
verified:
date: '2026-10-08'
known_good_sha256: d6258a22a0a6e4588bbec36170f126bffc44ed64784f99e37cf4b03ad212fb79
app: 0.12.0
overport_cli: 1.2.5
frame_build: '20261006.6173745'
agent: 59
issue: 108
source_hint: The Tale of Onogoro
+23
View File
@@ -0,0 +1,23 @@
package: rift.beat_saber
title: Beat Saber
status: works
notes: 'Supports SteamVR/OpenXR itself: runs directly, without Revive.'
engine: Unity
xr: OpenXR
kind: rift
quest_package: com.beatgames.beatsaber.lj369vr
pcvr:
- pcvr.xr_timefix
- pcvr.steamvr_tuning
pcvr_remove:
- pcvr.revive
as_is: true
verified:
date: '2026-10-09'
known_good_sha256: dc80bd1f8e46e7b7cdc4fbf51a84e68f2918d7481581bee9c21f65e269c6bf8b
app: 0.12.1.dev232
overport_cli: 1.2.5
frame_build: '20261007.6125817'
agent: 67
issue: 117
source_hint: Beat Saber
@@ -0,0 +1,23 @@
package: rift.eleven_table_tennis_vr
title: 'Eleven: Table Tennis VR'
status: works
notes: 'Supports SteamVR/OpenXR itself: runs directly, without Revive (arguments -vrmode OpenVR).'
engine: Unity
xr: LibOVR+OpenVR
kind: rift
pcvr:
- pcvr.launch_args
- pcvr.xr_timefix
- pcvr.steamvr_tuning
pcvr_remove:
- pcvr.revive
as_is: true
verified:
date: '2026-10-09'
known_good_sha256: 2cdfe3b096aef0bf76726156699381f7847ca4d17e7222359521982778470705
app: 0.12.1.dev232
overport_cli: 1.2.5
frame_build: '20261007.6125817'
agent: 67
issue: 118
source_hint: Eleven Table Tennis VR
+22
View File
@@ -0,0 +1,22 @@
package: rift.pistol_whip
title: Pistol Whip
status: works
notes: 'Supports SteamVR/OpenXR itself: runs directly, without Revive.'
engine: Unity
xr: OpenVR
kind: rift
pcvr:
- pcvr.xr_timefix
- pcvr.steamvr_tuning
pcvr_remove:
- pcvr.revive
as_is: true
verified:
date: '2026-10-09'
known_good_sha256: a01eaf73b292eb8ad21e316f1f99ad258d41b2cfed8436858a8caf2f5c0a4d28
app: 0.12.1.dev232
overport_cli: 1.2.5
frame_build: '20261007.6125817'
agent: 67
issue: 119
source_hint: Pistol Whip
+4 -1
View File
@@ -1,11 +1,13 @@
package: rift.superhot_vr
title: SUPERHOT VR
status: works
notes: 'Supports SteamVR/OpenXR itself: runs directly, without Revive.'
notes: 'Supports SteamVR/OpenXR itself: runs directly, without Revive. Older builds with both Oculus and SteamVR support
(SUPERHOTVR.exe) start with -vrmode OpenVR.'
engine: Unity
xr: OpenXR
kind: rift
pcvr:
- pcvr.launch_args
- pcvr.xr_timefix
- pcvr.steamvr_tuning
pcvr_remove:
@@ -17,4 +19,5 @@ verified:
app: 0.6.3
overport_cli: 1.2.5
issue: 28
updated: '2026-10-09'
source_hint: SUPERHOT VR
@@ -3,9 +3,11 @@ title: SUPERHOT VR
status: works
notes: Quest version. Needs FramePort's launcher from agent 41 (reinstall once) so the game can write its saves.
details: Unity 2018.4 with built-in Oculus support (GLES). Its eye swapchains (GL_RGBA8, then a 16-bit format) are
created as sRGB by the adapter's swapchain_fix. The game creates its cloud save folder with mode 1700 and quits at
start when it can't write there ("Something failed to initialize. Quitting!"); the launcher now gives every folder
in the game's storage owner and group write permission.
created as sRGB by the adapter's swapchain_fix. The game creates its cloud save folder with mode 1700 and quits
at start when it can't write there ("Something failed to initialize. Quitting!"); the launcher now gives every
folder in the game's storage owner and group write permission. On the very first start it creates that folder
and checks it in the same moment (GitHub 120), so the recipe creates the folder at install (device_files) and
the launcher fixes it before the game starts.
tested_version: '1.161'
engine: Unity
xr: VrApi
@@ -16,7 +18,9 @@ frame:
- frame.unity_runtime_msaa_off
device:
- device.text_input_window
device_files:
cloud/data/.frameport: ''
verified:
date: '2026-10-04'
updated: '2026-10-04'
updated: '2026-10-09'
source_hint: SUPERHOT VR
+84 -4
View File
@@ -1,6 +1,9 @@
# Log signature -> diagnosis -> suggested fix. Matched against the game's launch.log (Lepton logcat mirror).
# `pattern` is a Python regex (case-sensitive). `suggest` lists patch ids (+ optional params) the UI offers as
# "apply and rebuild". `severity`: fatal (the game can't run) | error | warning | info.
# "apply and rebuild"; an entry `adapter.<key>=<value>` sets that value (else 1). `severity`: fatal (the game can't
# run) | error | warning | info. `question`: a symptom only the player sees (play sessions, GUI "Last session"): its
# fix is offered as that question, never applied on its own. `report: true` = the useful next step is a problem report
# with diagnostics. Launch tests and real play sessions (agent session_log, `frameport session`) are both matched.
# Sources: every failure we hit porting 34 games to the Steam Frame (see docs/PLAYBOOK.md).
signatures:
- id: no-launcher
@@ -34,7 +37,7 @@ signatures:
diagnosis: Unity's render thread crashed inside the Frame's GL driver (Mesa/Zink); the picture freezes or stays grey. Known triggers - an OVROverlay copy (try "Unity - skip OVROverlay layers", e.g. The Room VR), MSAA switched on at runtime, a GPU hang (zink DEVICE LOST).
suggest: [frame.unity_no_overlay_copy, frame.unity_runtime_msaa_off]
- id: unreal-msrtt-crash
pattern: 'fault addr 0x10000 in tid \d+ \((RHIThread|RenderThread)'
pattern: 'fault addr 0x10000 in tid \d+ \((RHIThread|RenderThread)|libgallium_dri\.so \(find_rp_state'
severity: fatal
diagnosis: The game's render thread jumped to address 0x10000 inside the Frame's GL driver (Mesa/Zink) a few seconds after start. Zink looks up a render-pass cache slot past its end when a game renders through multisampled render-to-texture (Unreal's mobile MSAA, e.g. Star Wars Pinball VR). Load the GL shim, which hides that extension.
suggest: [frame.unreal_gl_shim, frame.unity_gl_shim]
@@ -43,6 +46,13 @@ signatures:
severity: fatal
diagnosis: The game crashed on a return-address check (autiasp) its code never signed. The Quest's CPU ignores these checks, the Steam Frame's enforces them; some OpenSSL assembly in game engines has such unpaired checks (e.g. Star Wars Pinball VR on its first network connection, thread HttpManager).
suggest: [frame.pac_hints]
- id: cube-swapchain-refused
pattern: 'xrCreateSwapchain \d+x\d+ .*faces=6 .*result=-\d+'
unless: 'cube_standin: runtime refused'
severity: fatal
diagnosis: The game asked for a cube-map swapchain (e.g. an OVROverlay skybox or loading cube), which the Frame's runtime doesn't have. OVRPlugin goes on without images and crashes in ovrp_EndFrame4 (Unity's render thread SIGSEGV in memset, e.g. Budget Cuts Ultimate). FrameBridge from FramePort 0.12 serves such swapchains itself and drops their cube layers (cube_standin, GLES games) - rebuild and reinstall the game.
suggest: [frame.adapter]
supersedes: [unity-render-crash, native-crash]
- id: swapchain-rect-invalid
pattern: 'xrEndFrame failed -25\b'
severity: fatal
@@ -75,11 +85,45 @@ signatures:
severity: error
diagnosis: The Frame rejected the swapchain format (GLES games must use sRGB formats, no MSAA).
suggest: [adapter.swapchain_fix]
- id: zink-shader-fix-mismatch
pattern: 'shader fix layer: a \d+-byte module differs from fix'
severity: warning
diagnosis: The game's OpenGL ES shader fix (zink_shader_fix) no longer matches the shader the Frame's GL driver (Zink)
builds - a Frame or Lepton update changed the driver's output - so the shader it fixes (e.g. Vader Immortal's
lightspeed jump) may hang the GPU again. Capture the new modules with zink_shader_dump=1 (files/fp_spirv/ in the
game's storage) and update the fix.
suggest: [adapter.zink_shader_dump]
- id: zink-shader-layer-inactive
pattern: 'shader fix layer: NOT active'
severity: warning
diagnosis: FramePort's shader-fix Vulkan layer couldn't add itself to the game's Vulkan layers (Android's
GraphicsEnv functions it uses were not found or behaved differently, e.g. after a Lepton update), so the game's
OpenGL ES shader fixes (zink_shader_fix) don't apply.
suggest: []
- id: zink-device-lost
pattern: 'zink.*DEVICE[_ ]LOST|VK_ERROR_DEVICE_LOST'
severity: fatal
diagnosis: The GPU hung (Zink/Mesa). For GLES Unity games MSAA render-to-texture is the usual cause.
diagnosis: The GPU hung (Zink/Mesa). For GLES Unity games MSAA render-to-texture is the usual cause; at one effect
only, a shader reading undefined loop counters (e.g. Vader Immortal's lightspeed jump - frame.zink_shader_fix).
suggest: [frame.unity_no_msaa, frame.unity_runtime_msaa_off]
- id: gpu-hang
pattern: 'kernel: .*(?i:hangcheck|gpu fault|msm_drm.*(hang|recover)|kgsl.*(hang|fault)|adreno.*(hang|fault))'
severity: fatal
diagnosis: The Frame's GPU hung while the game ran (the kernel reset it; the game froze or closed). Usually one
shader or effect the Frame's driver can't handle (e.g. Vader Immortal's lightspeed jump). FramePort can't fix
that on its own; capture the game's shaders (OpenGL ES games) and send a problem report with diagnostics, so a
shader fix can be added for this game.
suggest: [adapter.zink_shader_dump]
report: true
- id: space-warp-used
pattern: 'xrCreateSwapchain \d+x\d+ format=(97|129) '
unless: 'per-game: hide_space_warp=1'
severity: info
diagnosis: The game uses Meta's space warp (it renders half of its frames plus motion vectors, and the runtime makes
up the rest). On the Frame that can make textures flicker, jump or smear while you move (e.g. Into The Radius 2,
Metro Awakening). Turning it off makes the game render every frame itself.
question: Did textures flicker, jump or smear while you moved?
suggest: [adapter.hide_space_warp]
- id: unity-runtime-msaa
pattern: 'recommended MSAA level is [248]\. Switching to the recommended level'
severity: info
@@ -133,6 +177,13 @@ signatures:
severity: error
diagnosis: Shaders written for Quest drivers fail on Mesa (GLSL strictness).
suggest: [frame.gl_shim]
- id: gl-multiview-twin-failed
pattern: 'GLMV\s*: twin of program \d+(: stage| failed)'
severity: warning
diagnosis: The multiview interposer (frame.gl_multiview_fbo) couldn't build a single-view copy of one of the
game's shader programs (the line has the compiler's message); draws of that program into flat panels (HUD,
menus) still stay black. Please report it with the log; turning the patch off changes nothing else.
suggest: []
- id: vrapi-unsupported-layer
pattern: 'OVRPortVrApi.*Unsupported VrApi layer type (\d+)'
severity: error
@@ -251,6 +302,12 @@ signatures:
diagnosis: Stress Level Zero's graphics plugin (libSLZQuestNative.so) hooks Unity's Vulkan start-up and calls an invalid function there on the Frame (e.g. BONELAB 1.2974); the game crashes or hangs before its first frame.
suggest: [frame.slz_vulkan_hooks]
supersedes: [java-crash, native-crash]
- id: vivox-api31
pattern: 'NoSuchMethodError: No virtual method \w*CommunicationDevice\w*\(.*Landroid/media/AudioManager'
severity: fatal
diagnosis: The game's Vivox voice-chat SDK calls Android 12 audio-routing methods (AudioManager communication devices) without checking the Android version; Lepton runs Android 11, so the app crashes (e.g. Green Hell VR). The patch makes Vivox's audio-route check return early (voice chat keeps the default route).
suggest: [frame.vivox_audio_route]
supersedes: [java-crash]
- id: native-crash
pattern: 'Fatal signal (\d+) \(SIG[A-Z]+\)'
severity: fatal
@@ -275,6 +332,7 @@ signatures:
suggest: []
- id: container-not-started
pattern: "is not a running context|OCI runtime error"
unless: 'Boot complete!' # Lepton 3.x prints the error while its container is still starting, then boots fine
severity: fatal
diagnosis: The Lepton container failed to start (see the error above it in launch.log).
suggest: []
@@ -358,6 +416,19 @@ signatures:
severity: fatal
diagnosis: The game crashed (Unreal's crash reporter started). See the game log and crash summary in the log. Common causes are that no VR runtime reached the game (Revive off) or a GPU or driver problem under Proton.
suggest: [pcvr.revive, pcvr.proton_log, pcvr.no_crash_reporter]
- id: unity-vr-init
kind: pcvr
pattern: '(?i)OpenVR failed initialization|VRInitError_(?!None\b)\w+|Initialization of device \w+ failed|Failed to (load|initialize|start) (VR|XR|OpenVR|Oculus)\b'
severity: error
diagnosis: The game's Unity log shows that a VR device failed to start. Unity games built for both the Oculus and the SteamVR (OpenVR) runtime choose one with an argument; without it they may try Oculus, which the Frame doesn't have, and run without VR or quit. Start the game with -vrmode OpenVR (Game arguments).
suggest: [pcvr.launch_args]
- id: unity-crash
kind: pcvr
pattern: 'Crash!!!|caused an Access Violation|caused an Unhandled Exception'
severity: fatal
diagnosis: The game crashed (Unity's crash handler wrote a report; the Unity log in the launch log shows the stack). Common causes are that no VR runtime reached the game or a GPU or driver problem under Proton.
suggest: [pcvr.proton_log]
supersedes: [wine-crash]
- id: wine-crash
kind: pcvr
pattern: 'Unhandled exception: page fault|wine: Unhandled|Backtrace:'
@@ -370,7 +441,8 @@ signatures:
severity: error
diagnosis: The game can't write to a folder it created in its storage (e.g. SUPERHOT's cloud/data, mode 1700, which
makes it quit at start). FramePort's launcher (agent 41 or newer) gives such folders owner and group write
permission before and during every launch; update the game on the Frame (reinstall) to get the new launcher.
permission before and during every launch (agent 41 or newer; else reinstall the game). A folder the game creates
and checks in the same moment on its very first start can't be repaired in time, so start the game again.
suggest: []
- id: surface-swapchain-emulated
pattern: 'surface_emul: emulated Android surface swapchain'
@@ -384,6 +456,14 @@ signatures:
diagnosis: FrameBridge couldn't emulate an Android video panel (XR_KHR_android_surface_swapchain); the panel stays
empty, and a game waiting for its intro video may stay black (e.g. I Am Monkey's intro).
suggest: []
- id: hw-video-decoder-busy
pattern: 'Iris \S+ unavailable; keeping Android|Iris \S+ initialization failed \(-1[26]\); using software'
severity: info
diagnosis: FramePort's hardware video decoder (frame.hw_video_decode) couldn't open a session, because other
decoder sessions held the hardware (Steam's own hardware video decoding, SteamVR's link while a game starts);
the video was decoded in software instead, which is slow for 4K/8K. Turn off hardware video decoding in Steam's
settings, restart Steam, then start the game again.
suggest: []
milestones: # progress markers, in order; the furthest one reached is reported
- {id: pcvr-launch, kind: pcvr, pattern: 'FramePort: launching|Launched injector with', label: Launcher started}
- {id: pcvr-oculus-hmd, kind: pcvr, pattern: 'FramePort oculushmd: OculusHMDConnected event ready', label: Oculus headset event provided}
+2
View File
@@ -38,6 +38,8 @@ games/<pkg>/package/ stand-in for the game files (no content):
games/<pkg>/target/ from the Frame (or the PC): launch.sh, settings.conf, deployment.json, launch.log,
launch-test.log (PC VR), lepton-steamlaunch-<appid>.log, logcat-{main,crash,system,...}.log,
ReviveInjector.txt / steam-<appid>.log / game-log-N.txt (PC VR), files.json (+ missing)
(game-log-N.txt: Unreal Saved/Logs + crash summaries, Unity Player.log / Player-prev.log /
output_log.txt + crash error.log from the Proton prefix, agent v67)
```
Each log keeps at most its last 4 MB (2 MB per file from the Frame).
+7
View File
@@ -76,6 +76,13 @@
`device.foveation`: `fixed` = `FDM_DEBUG=disable_offsets`, `off` = `VK_INSTANCE_LAYERS=""`. Lepton passes `FDM`,
`FDM_DEBUG`, `FOVE_LEVEL` and `FDM_SWAPCHAIN_SIZE` through to the container (liblepton/mounting.sh PASSTHROUGH_VARS);
the layers are chosen on the host, so setting them inside the game does nothing.
- How Lepton loads them: `liblepton/vulkan_layers.sh` mounts the chosen layers (only those in the OS image's
`/usr/share/guestos/android/vendor/vulkan_layers`) into the app's lib dir and writes their names to Android's
`settings global gpu_debug_layers` for `gpu_debug_app` = the game; Android's loader reads that list from GraphicsEnv
at each vkCreateInstance and searches the app's lib dir (`/data/app/…/lib/arm64`). A layer bundled in the APK is
found there too; FramePort's shader-fix layer (`frame.zink_shader_fix`) adds its own name to GraphicsEnv's list from
inside the process (`android::GraphicsEnv::setDebugLayers`, exported by the guest's libgraphicsenv.so, Lepton 3.0.5).
That is the only way to reach the Vulkan side of OpenGL ES games (Zink creates the instance inside Mesa).
- GL ES: Zink (Mesa GL on Vulkan). Strict GLSL (see PLAYBOOK) and occasional `DEVICE LOST` with MSAA render-to-texture.
## Proton / Windows games (surveyed 2026-09-29; running a Rift game under it not yet verified)
+8 -1
View File
@@ -30,6 +30,7 @@ Generated from [catalog/games](../catalog/games) by `scripts/compat_list.py`.
| Espire 2 | Quest | ✅ Works | |
| Genotype | Quest | ✅ Works | |
| GORN2 | Quest | ✅ Works | |
| Gravity Lab | Quest | ✅ Works | |
| H.U.N.T | Quest | ✅ Works | |
| I Am Cat | Quest | ✅ Works | |
| I Am Monkey | Quest | ✅ Works | |
@@ -43,6 +44,7 @@ Generated from [catalog/games](../catalog/games) by `scripts/compat_list.py`.
| Lucky's Tale | Quest | ✅ Works | |
| Marvel's Deadpool VR | Quest | ✅ Works | |
| Marvel's Iron Man VR | Quest | ✅ Works | |
| Max Mustard | Quest | ✅ Works | |
| Medieval Dynasty New Settlement | Quest | ✅ Works | |
| Metro Awakening | Quest | ✅ Works | |
| Mobile Suit Gundam: Silver Phantom | Quest | ✅ Works | |
@@ -52,6 +54,7 @@ Generated from [catalog/games](../catalog/games) by `scripts/compat_list.py`.
| palazzo_santacruz | Quest | ✅ Works | |
| Path of the Warrior | Quest | ✅ Works | |
| Pistol Whip | Quest | ✅ Works | |
| Please Don't Touch Anything | Quest | ✅ Works | |
| PowerWash Simulator VR | Quest | ✅ Works | |
| QuestCraft | Quest | ✅ Works | |
| Retronika | Quest | ✅ Works | |
@@ -71,23 +74,27 @@ Generated from [catalog/games](../catalog/games) by `scripts/compat_list.py`.
| The Boys VR | Quest | ✅ Works | |
| The Climb 2 | Quest | ✅ Works | |
| The Room VR | Quest | ✅ Works | |
| The Tale of Onogoro | Quest | ✅ Works | |
| Time Crisis VR (Experimental) | Quest | ✅ Works | |
| Toy Master | Quest | ✅ Works | |
| Under Cover | Quest | ✅ Works | |
| Vader Immortal: Episode I | Quest | ✅ Works | |
| VR HOT Quest | Quest | ✅ Works | |
| VR4 | Quest | ✅ Works | |
| Walkabout Mini Golf | Quest | ✅ Works | |
| Wallace & Gromit in The Grand Getaway | Quest | ✅ Works | |
| Waltz of the Wizard: Extended Edition | Quest | ✅ Works | |
| Wander | Quest | ✅ Works | |
| Arcsmith | Quest | ⚠️ Works with issues | Right eye distorts during movement (unresolved; swap, tracking, Valve layers, depth and pacing ruled out). |
| Assassin's Creed Nexus | Quest | ⚠️ Works with issues | Some launch warning text is still upside down; the rest of the UI is fixed by flip emulation. |
| Does it Stack? | Quest | ⚠️ Works with issues | Mixed reality mode does not work (works on Demeo), everything else seems to be OK |
| Doom3Quest | Quest | ⚠️ Works with issues | PDA shows black screen. |
| Myst | Quest | ⚠️ Works with issues | Minor graphical glitches on some objects. |
| Phantom: Covert Ops | Quest | ⚠️ Works with issues | DLC/store button crashes (no Meta store). |
| Pinball FX VR | Quest | ⚠️ Works with issues | Plays; mixed reality mode not working yet. |
| Silhouette | Quest | ⚠️ Works with issues | Hand-tracking game; the Frame synthesizes hands from controllers, so it is janky. |
| The Light Brigade | Quest | ⚠️ Works with issues | Judder in weapons |
| Time Stall | Quest | ⚠️ Works with issues | Both eyes distort during movement (unresolved). |
| Vader Immortal: Episode I | Quest | ⚠️ Works with issues | Starts in VR and plays the intro, then stays on the loading card (Vader's portrait with a progress bar). |
| WiiCompiled VR | Quest | ⚠️ Works with issues | To add a game: in FramePort's Files tab, upload your .wcgame file to this game's storage, folder Android/data/org.wiicompiled.quest/files/WiiCompiledOpenXRVR… |
| BlazeRush | Quest | ❌ Doesn't run | Starts and reaches the menu room, but the room shows no controllers and ignores all input (it all reaches the game); no fix yet. |
| Espire 1: VR Operative (Quest Edition) | Quest | ❌ Doesn't run | Mesa GL driver crash during texture upload. |
+17
View File
@@ -46,6 +46,7 @@ version is `catalog/triage.yaml` (used by `frameport test` / the Job screen); ke
| PC VR game: `Failed to initialize Oculus API (-3001)` / `Unable to load LibOVRRT DLL` | Revive's LoadLibrary hook doesn't work under Proton arm64 (ARM64EC kernelbase); the game's LibOVR shim finds no runtime DLL | Symlink `LibOVRRT64_1.dll` → Revive's DLL in the prefix's system32 (manual so far) → then -3021 (runtime signature check; open) |
| Uploads to the Frame are slow (~15 MB/s) | PC and Frame both on Wi-Fi through the home router | Connect the PC to the Frame's own hotspot (or a USB cable): FramePort uses the direct link automatically (~80-100 MB/s); job log line "Transfer link" |
| PC VR game exits right away: `Unhandled Exception: 0xc06d007e` (after `FOnlineSubsystemOculus::InitWithWindowsPlatform`) | Delay-loaded `LibOVRPlatform64_1.dll` (Oculus Platform SDK, installed with the Oculus app) is missing | None on the Frame (entitlement check; FramePort doesn't replace it). PC mode with the Oculus app |
| Unity PC VR game (Oculus + SteamVR build: `OVRPlugin.dll` and `openvr_api.dll` in `<Name>_Data/Plugins`) opens a window and quits after ~20 s; no VR Vulkan instance after the game's DXVK device in launch.log; Unity log (`unity log … Player.log`, agent v67): `OpenVR failed initialization` / `Initialization of device … failed` | Unity's built-in VR tries its SDKs in list order (Oculus first) unless `-vrmode` picks one; a catalog recipe verified with another build of the game (e.g. SUPERHOT VR's OpenXR build, GitHub #105) used to drop the build's own arguments | `pcvr.launch_args` = `-vrmode OpenVR` (detected for such builds; kept when the catalog's `xr` differs from the build's). A game's Electron launcher next to it (SHVR.exe) is ranked below the game |
| Unreal PC VR game opens the crash reporter instead of closing | UE starts CrashReportClient.exe on a crash | `pcvr.no_crash_reporter` (default for Unreal Rift games): `-nocrashreports` + CrashReportClient.exe renamed `.disabled` in the Frame copy |
| A backup's game was added without its data (library `data_dir` null, `data_bytes` 0) although the folder has .obb files | The OBBs sit in a layout the scan didn't know: `<game>/obb/<package>/`, `Android/obb/<package>/`, or SideQuest-style `<game>/apk/x.apk` + `<game>/obb/<package>/` | `sources/quest_dump.find_data_dir` finds a `<package>` folder with .obb files ≤3 levels below the APK's folder or ≤2 below its parent (skipping neighbouring folders with APKs: other games); an `apk`/`apks` folder counts as part of its game folder. Add the folder again (Analyze again doesn't look for data) |
| Game hangs at start / never loads although its .obb files are right there: next to the APK, in an `obb` folder beside an `apk` folder inside a `<package>` folder, or a SideQuest backup (`<timestamp>_<versionCode>.apk`) (GitHub #85, #91) | No folder named after the package, so the folder-layout checks found nothing and no OBB was uploaded | `quest_dump.find_data` then looks for the files by name, `(main\|patch).<versionCode>.<package>.obb` (any case), in the APK's folder, its parent and up to 3 levels below each (folders with their own APKs are other games); prefers the folder and files of the APK's own versionCode, else the newest older, else any version. When that folder also holds other things (the APK itself, other games' OBBs), the library entry gets `data_files` and only those files are uploaded, counted and deleted with the game. Add the folder again |
@@ -78,29 +79,44 @@ version is `catalog/triage.yaml` (used by `frameport test` / the Job screen); ke
| Video player / app finds no local videos; MediaProvider "Requested path /home/steamos/... doesn't appear under ..." | Lepton's /sdcard is a symlink to a host path, so Android's media index rejects every file | upload in the Files tab (Videos = /sdcard/Movies) and browse folders in the app |
| Batman: Arkham Shadow closes during smoke-bomb effects; later input-tree corruption | Meta XR Audio Wwise deletes queued metadata still referenced by the current audio frame, then writes through the stale pointer | FrameBridge automatically retires metadata after current-frame references disappear, for the verified AArch64 SDK build only; see [AUDIO_METADATA.md](AUDIO_METADATA.md) |
| Game stays on a loading or "Waiting" box although it reached FOCUSED; log `FrameBridge: xrEndFrame failed -25` then no more `pacing:` lines (e.g. PowerWash Simulator on some Frames, GitHub #39) | The eye image rect ends a few pixels past its swapchain (Unity rounds the swapchain width, the runtime's recommended size differs per Frame); SteamVR rejects every frame with XR_ERROR_SWAPCHAIN_RECT_INVALID | FrameBridge clamps every projection/quad image rect to its swapchain (`rect_clamp`, default on since 0.11.0; log `rect_clamp: view N image rect clamped`): rebuild + reinstall the game |
| Unity game (OVRPlugin, GLES) crashes ~10 s in: `FrameBridge: xrCreateSwapchain … faces=6 … result=-2`, OVRPlugin `CreateSwapchain for eye 0: 0x0, 0 stages`, then render-thread SIGSEGV in memset ← libOVRPlugin ← `ovrp_EndFrame4` (libgallium/ANR follow; e.g. Budget Cuts Ultimate, GitHub #107); triage `cube-swapchain-refused` | The game shows a cube-map layer (OVROverlay cubemap); the Frame's runtime has no cube layers and refuses cube swapchains (XR_ERROR_RUNTIME_FAILURE); OVRPlugin doesn't check and writes into the image list it never got | FrameBridge `cube_standin` (default on): a refused cube swapchain is served as a GL cube map in the game's context and its layers are dropped (log `cube_standin: runtime refused …`): rebuild + reinstall. GLES only; a Vulkan game keeps the error |
| Game (Unity, GLES) freezes, `zink: DEVICE LOST` | multisampled render-to-texture hangs the GPU | `frame.unity_no_msaa`; if it persists: unfixable → PC version |
| Unreal GLES game crashes ~3 s after start: `Fatal signal 11 … fault addr 0x10000 in tid … (RHIThread)`, `#01 … libgallium_dri.so` (GitHub #83 Star Wars Pinball VR, triage `unreal-msrtt-crash`) | Unreal's mobile MSAA renders through multisampled render-to-texture; Zink's `find_rp_state` then indexes `rendering_state_cache[6]` one past its end (sample count ≥ 32) and calls a junk hash function (0x10000). Mesa bug (no bounds check) | `frame.unreal_gl_shim` (GL shim with `gl_hide_msrtt`, multiview kept for Unreal: Unreal 4.25 only enables multiview with GL_OVR_multiview, GL_OVR_multiview2 **and** GL_OVR_multiview_multisampled_render_to_texture, so the shim keeps the last one visible for Unreal and maps glFramebufferTextureMultisampleMultiviewOVR to the single-sampled glFramebufferTextureMultiviewOVR; log `multiview multisampled render-to-texture (N samples) drawn single-sampled`) |
| Crash with `SIGILL (ILL_ILLOPN)` and `*pc=0xd50323bf` (autiasp), e.g. on Unreal's HttpManager thread (GitHub #83 Star Wars Pinball VR, triage `pac-unpaired`) | The engine's OpenSSL ARMv8 assembly has autiasp without a matching paciasp (libUE4.so: 38 paciasp, 40 autiasp; Poly1305 NEON). Quest CPUs treat PAC hints as NOPs, the Frame's CPU checks them | `frame.pac_hints`: in a library with unpaired counts every paciasp/autiasp becomes a NOP (in place) |
| launch.log ends with `logcat: Unexpected EOF!` right after `Waiting for app …`; the game runs, but Steam's "Resume game" menu isn't closed and the launch test shows nothing (Vader Immortal on Lepton 3.0.5, Under Cover on 2.8.14; about 1 launch in 50) | Lepton's logcat mirror died | Agent v67 `_logcat_keeper` (started by launch.sh, added to older launchers by `upgrade_launchers`) reads the container's logcat itself (`podman exec lepton-steamlaunch-<appid> logcat -v threadtime -T 2000`) and appends it to launch.log; log `<base>/logcat-keeper.log` |
| A game no longer starts after a reinstall that was launch-tested right away: logcat `Zip: EOCD not found, …/base.apk is not zip` / `Failed to parse …base.apk`, no `Start proc` for the game (VR HOT, 2026-10-09) | The launch test's 45 s ran from the launcher, but the first start after an APK change spends ~1–2 min booting Lepton and installing the app: stopping the container mid-install left a broken installed copy | Agent v68: the test window counts from Lepton's `Waiting for app` (at most 240 s extra for boot + install). Repair a broken one: `touch <base>/lepton-app/game.apk` (Lepton re-installs it on the next start) |
| Unreal game (OVRPlugin) never starts VR: launch.log has `OVRPlugin: JNI_OnLoad` but never `CompositorOpenXR::PreInitialize`, no OpenXR session, then a crash a few seconds in (e.g. Star Wars Pinball VR, UE 4.25: null pointer in `FSceneRenderer::GetMultiViewSceneColor`, GitHub #83) | Unreal's Oculus module looks up every `ovrp_*` function of the OVRPlugin it was built against (`InitializeOculusPluginWrapper`, all ANDed); OVRPort's OpenXR OVRPlugin lacks a few old ones (UE 4.25 / OVRPlugin 1.44: `ovrp_GetPTWNear`), so the wrapper fails and OculusHMD is never pre-initialised | `frame.unreal_ovrp_entrypoints` (suggested when analysis `unreal_ovrp_lookups` name functions the shipped OVRPlugin lacks): generated `libfp_ovrpstubs.so` (DT_NEEDED of libOVRPlugin.so; dlsym on the plugin's handle searches its dependencies) with a stand-in per missing name returning ovrpFailure (-1000); build note lists the names |
| Only the Android home screen shows; the log has Unity's VR device as `None` (e.g. Accounting+, Unity 2017) | Unity 2017–2018 built-in Oculus support starts VR only when `com.oculus.systemactivities` is installed; Lepton has no Meta system apps, so Unity falls back to non-VR | `frame.unity_oculus_check`: that package name in libunity.so → `android`, plus `native/ovrpshim` (libfp_ovrp.so): Unity 2017's legacy frame loop (`ovrp_Update2`/`ovrp_BeginFrame`) never calls `ovrp_WaitToBeginFrame`, so without the shim no `xrWaitFrame` happens, `CompositorOpenXR::Update … outside of frame bounds` floods the log and the dashboard freezes. With it: log `ovrp frame loop shim: waited for frame N`, ~71 fps. Accounting+ then stops at "press any button" although its OVRInput gets clean input (`INPUT_PROBE` in the patch logs connected controllers/buttons/input focus per call) — unresolved |
| Black flat window, then a GPU hang: kernel `hangcheck detected gpu lockup` (offending task the game), `zink: DEVICE LOST`, Unity render-thread crash; `outside of frame bounds` thousands of times a second (e.g. BattleSisters, Unity 2019.4) | Unity 2019 on its built-in VR (no `libOculusXRPlugin.so`) uses the same legacy frame loop as Unity 2017: no `xrWaitFrame`, the render thread floods the GPU | `frame.unity_oculus_check` adds the ovrpshim frame wait for these too (revision 2) |
| Unity built-in VR game (with `frame.unity_oculus_check`) freezes at a scene switch: the log stops after `Boot: Activating Scene: …`, the process stays alive, every thread sleeps (e.g. Sniper Elite VR, Unity 2019.4) | The shim's `xrWaitFrame` blocks until the previously waited frame is begun; Unity skipped beginning it at the scene switch and its render thread then waited for the main thread (gdb: UnityMain in vrclient `CSxrSession::StartNextFrame` ← `ovrp_WaitToBeginFrame` ← `fpov_Update2`). OVRPlugin also only begins the frame index it waited for | `frame.unity_oculus_check` revision 5: libunity.so's `ovrp_BeginFrame`/`ovrp_EndFrame` go through the shim, which waits ≤ 50 ms for the last waited frame to begin, else skips the wait (log `the last waited frame wasn't begun`), and gives a begin/end of another index the waited one |
| Unity built-in VR game: the hands/weapons trail the controllers by centimetres when moving (headset fine, 72 fps), e.g. Sniper Elite VR | Unity's physics-step `ovrp_Update2` (prediction 0) makes OVRPlugin locate the nodes at the monotonic clock's "now", the XrTime base on a Quest but 0.05–0.9 s behind the Frame's XrTime; the runtime extrapolates backwards and the render-step reads after it get those poses too. A larger prediction is capped by OVRPlugin (~0.07 s) | `frame.unity_oculus_check` revision 5 holds the physics-step update back: both steps read the render update's display-time poses |
| OVRPlugin game: the hands lag behind the controllers (also with `ovrp_hold_physics` on or off; rendering fine), e.g. BattleSisters | OVRPlugin passes its monotonic-clock "now" on as the OpenXR time (OVRPort's dispatcher converts XR_KHR_convert_timespec_time 1:1: the Frame's runtime lacks it, and FrameBridge's emulation is never asked), but the Frame's XrTime runs ahead of CLOCK_MONOTONIC (2.56 s on SteamOS 0.4.5): with `pose_debug=1` the hand spaces show `time - predicted display time -2564 ms`; BattleSisters also asks for its head at XrTime 0.1 s every frame | `adapter.pose_time_fix` (FrameBridge, suggested for Unity built-in OVRPlugin games): a located time nearer the monotonic clock than XrTime's "now" is moved by the clock offset measured at xrWaitFrame, one more than 0.5 s before the display time goes to "now" (log `pose_time_fix: …`; `pose_debug=1` counts both per 5 s). Once a build has this FrameBridge it is toggled in settings.conf (no rebuild) The offset is the largest of the last ~2 s of xrWaitFrame samples (hitches made single samples dip by up to 2.5 s and pushed fixed times into the future); far-past requests get the frame's display time. Headless survey of 54 games (2026-10-09): no head/view request on the monotonic clock in any other game; UE4 OVRPlugin 1.89 games (Robo Recall, Vader, Phantom, Time Stall) and The Room VR ask for head/views at XrTime ≈ 0 every frame, which works today; hands only show in the headset. Suggested for Unity built-in Oculus games only. A time equal (±1 ms) to one of the last 6 predicted display times is never moved, and monotonic times are only told apart when the clocks are more than 4 display periods apart and the time is clearly nearer the monotonic "now" (GitHub #49: on a Frame with XrTime only ~68 ms ahead, a display-time request after a hitch was moved +67.7 ms) |
| Unreal game stuck on a loading image after the intro, frames keep coming (72 fps), no crash (e.g. Vader Immortal) | suspect: a Meta Platform SDK request no message ever answers | diagnostics: `frame.ovr_trace` (opt-in) logs every `ovr_*` call, the answers `ovr_PopMessage` returns and every 10 s the unanswered requests (`fp_ovrtrace` in launch.log). Never fake an entitlement answer |
| Own-engine game crashes in `libVkLayer_fossilize.so` (Fossilize's recording thread, e.g. Roblox) | same as Deadpool VR: uninitialised pointers in what Fossilize records | `frame.vk_sanitize` now also covers own-engine libraries that load `libvulkan.so` by name |
| Crash right after the game gets focus, in `vrclient.so … UpdateActionStateInternal` / `sxr_xrSyncActions` (e.g. Myst) | a race in the Frame runtime's input code on the first sync after focus (not every launch) | adapter `sync_guard` (input syncs one at a time with event polling, paused 250 ms after FOCUSED) |
| View jumps sideways / game pauses or freezes for a moment every few seconds (e.g. Blade & Sorcery, BattleGlide) | the Frame drops focus for ~0.5 s (FOCUSED→VISIBLE→SYNCHRONIZED); games pause or re-align the player (`OnVRPresence … Teleport`) | adapter `focus_hold` |
| SDL / LÖVE app crashes at start: `NullPointerException … ClipboardManager.addPrimaryClipChangedListener` in `SDLClipboardHandler.<init>` (e.g. Dramatic Shape) | Lepton's Android has no clipboard service (`service check clipboard`: not found) | `frame.sdl_clipboard` (that call → nops in classes.dex, in place, `apk/dex.py`); reproduced and verified with LÖVE for Android 11.5 |
| Game crashes at start: `java.lang.NoSuchMethodError: No virtual method getAvailableCommunicationDevices()… in class Landroid/media/AudioManager` at `com.vivox.sdk.AudioChangeListener.checkAudioRouteAndApplyChanges` (e.g. Green Hell VR, GitHub #101); triage `vivox-api31` | Newer Vivox (voice chat) builds call Android 12 audio-routing methods without a version check; Lepton is Android 11. Older Vivox builds (Eleven Table Tennis, BattleSisters) don't have that code | `frame.vivox_audio_route` (suggested by analysis `vivox_api31`): every AudioChangeListener method that calls one of them returns at once (`Dex.return_early`: return-void / `const/4 v0, 0; return v0`, in place); voice chat keeps the default audio route |
| Controllers do nothing (e.g. stuck on a setup screen); log: `xrSuggestInteractionProfileBindings … XR_ERROR_PATH_UNSUPPORTED` | the game only suggests bindings for Meta's newer profiles (Touch Plus / Touch Pro); the Frame's Android runtime knows `oculus/touch_controller`, not those | adapter `profile_remap` (default on): the bindings are suggested again for Touch (log: `controller profile … -> oculus/touch_controller`) |
| Some buttons do nothing or the wrong thing (e.g. a Quest game's X/Y on the Frame's left controller) | the game binds only Quest Touch and SteamVR maps Touch onto the Frame controllers with its own remap (Touch left X/Y land on the d-pad, right X and Y repeat B), or the runtime rejected a profile or an input call | turn on adapter `input_diag` (diagnostics, off by default; `frameport settings <pkg> input_diag=1`) and look for `input_diag:` lines: `bindings: <profile> accepted` or `unsupported: interaction profile <profile> -> <result>` with the rejected paths, `bindings: /user/hand/<hand> uses <profile>`, `unsupported: function <name>`, `unsupported: xrCreateAction -> <result> (<action>)` |
| Unity game hangs or the whole Frame restarts (e.g. in a menu); log: `The current MSAA level is 0, but the recommended MSAA level is 4. Switching to the recommended level.` (e.g. Lucky's Tale) | Meta's OVRManager (`useRecommendedMSAALevel`) turns 4x MSAA on at runtime, past QualitySettings; multisampled render-to-texture on GLES/Zink hangs the GPU | `frame.unity_runtime_msaa_off` (Cpp2IL: `OVRDisplay.get_recommendedMSAALevel` → 0) |
| Unity game: one eye shows only effects or grey, the other is fine (e.g. I Am Cat, Oculus XR Plugin on GLES) | the game's single-pass multiview rendering goes wrong for array slice 1 (the adapter submits both slices correctly) | `frame.unity_multipass` (Cpp2IL: `OculusSettings.GetStereoRenderingMode` → MultiPass); `swap_eyes=1` tells whether the game or the adapter is at fault |
| Setup/intro loops every launch (Espire 2) | save folders created without write permission | launcher repairs permissions every 2 s (built in) |
| VrApi bridge: never enters VR | Frame reaches FOCUSED later than Quest; tracking only when worn | bridge waits 30 s; test in the headset |
| Unreal game (ILMxLAB, e.g. Vader Immortal) plays its intro, then stays on its loading card (portrait + progress bar) at 72 fps and ignores input (GitHub #49) | the menu waits for `UVRUtils::GetQuestShaderPrecompilePercent()` to reach 100 %; the precompile only starts when `IsRunningOnSantaCruz()` (a Quest), the other branch returns 0.0 | `frame.unreal_quest_precompile` (non-Quest branch returns 1.0; found by Klownicle); suggested when the engine exports that function (analysis `unreal_quest_gates`) |
| Video in a game or player stutters, falls behind or drops to a few fps (4K/8K, e.g. a video player's 360° video, Batman's cutscenes); `OMX.google.*` / `c2.android.*` decoders in the log | Lepton's Android has only software decoders | `frame.hw_video_decode` (suggested when the APK uses MediaCodec/ExoPlayer/VLC; no APK change, reinstall): `OMX.frameport.{avc,hevc,vp9}.decoder` on the Frame's Iris hardware (H.264 High, HEVC Main, VP9 profile 0 up to 4096x2304; 8-bit; up to 8192 px), mounted into this game's container only (log `Iris hardware video/… decoder active`; launch.log `FramePort video: loading the Iris hardware codec plugin`). `Iris … unavailable` / `initialization failed (-12)` (triage `hw-video-decoder-busy`): another decoder holds the hardware, usually Steam's own hardware video decoding: turn it off in Steam, restart Steam. Video broken with it: Settings → Installing → Hardware video decoding off (all games) or `FRAMEPORT_NO_HW_VIDEO=1 %command%` (one game) |
## Picture problems (headset on)
| Symptom | Cause | Fix |
|---|---|---|
| Found after playing: the game page's "Last session" (or `frameport session <pkg>`) lists a finding (agent v70 `session_log`: the newest `plays.log` session's launch.log, ≤4 MB, + its crash logcat + kernel GPU lines) | launch tests never reach FOCUSED or gameplay; the same `catalog/triage.yaml` signatures (sync_guard, pac_hints, unreal_gl_shim, vk_spec_fixes, …) now also run on real sessions, plus the frame-rate and focus-dip findings below | "Try this fix" (FrameBridge settings: written on the Frame at once via `set_settings`, used from the next start) / "Rebuild with this fix" (APK patches); launch-test sessions (`test <unix>` in plays.log) are skipped |
| Textures flicker, jump or smear while moving in an OVRPlugin game that renders space-warp swapchains (`xrCreateSwapchain 376x376 format=97` / `format=129`; triage `space-warp-used`, info + question) | Application SpaceWarp: half the frames plus motion vectors; the Frame's reprojection of them misbehaves (Into The Radius 2, Metro Awakening) | adapter `hide_space_warp=1`; offered as "Did textures flicker…?" after a play session, never applied on its own |
| The game froze or closed and the kernel log has `hangcheck` / GPU fault / `msm_drm … recover` lines during the session (triage `gpu-hang`, play sessions only) | a shader or effect hangs the Frame's GPU (e.g. Vader Immortal's lightspeed jump) | capture the shaders (`adapter.zink_shader_dump=1`, GLES) and send a problem report; the maintainer adds a `zink_shader_fix` / `vk_shader_fix` catalog entry. `zink-device-lost` keeps its MSAA suggestions |
| The game keeps pausing or recentring for a moment while worn (session finding `focus-dips`: ≥3 `focus: back after N ms` lines longer than the game's focus_hold_ms, up to 5 s) | the Frame's wear sensor flickers "HMD off"; FrameBridge logs every runtime focus loss/return (always, before focus_hold) | `adapter.focus_hold_ms=<longest dip + 250 ms, in 500 ms steps, ≤5000>` (or `adapter.focus_hold=1` when off) |
| Judder or smearing on head turns; FrameBridge pacing below the display rate (session finding `slow-frames`: >30 % of the 5 s windows under 90 % of the nearest refresh rate ≥ the session's 90th-percentile fps, after the first two windows, ≥1 min) | the game renders below the refresh rate; the runtime reprojects | `adapter.scale=<current × 0.85>` first, then `frame.unity_runtime_msaa_off` (Unity) / `adapter.hide_space_warp` (Unreal 5 + OVRPlugin) |
| Unreal game (ILMxLAB, e.g. Vader Immortal): controllers track but grip/trigger do nothing, grabbing never works (Unreal's own input values move, the game's stay 0) | `URPOCKeyMapManagerComponent` picks the Quest or the Gear VR key set by `IsRunningOnSantaCruz()`; on the Frame it takes Gear VR, empty in a Quest build | `frame.unreal_quest_keymap` (the Oculus case keeps the Quest set, for action and axis mappings; found by Klownicle, GitHub #49) |
| The hands' thumbs never move when you touch the thumbstick or buttons (Unreal `ThumbUp` stays 1, e.g. Vader Immortal) | OVRPlugin reports thumb proximity from XR_FB_touch_controller_proximity, which the Frame's runtime lacks; OVRPort's loader offers it anyway and the proximity actions never get a binding | adapter `proximity_emul=1` (thumb proximity from the touch inputs: thumbstick, face buttons, thumb rest; 2 = also the index finger from trigger touch); log `proximity_emul: finger proximity bound to touch`. **For UE4 Oculus games this didn't animate the thumbs** (Vader, GitHub #49): use `frame.unreal_thumb_touch` (found by Klownicle): `OculusInput::FOculusInput::SendControllerEvents` computes ThumbUp from NearTouches (masks 0x2/0x8); the patch makes it read Touches (the slot 4 bytes before) with masks 0x0f00 (X/Y/stick/thumb rest) / 0x000f (A/B/stick/thumb rest), keeping the inversion; three instructions, matched exactly (build note `OculusInput ThumbUp: from the capacitive touches`). Matches Vader Immortal Ep. I, Robo Recall, Phantom: Covert Ops, Time Stall, Star Wars: Tales from the Galaxy's Edge; newer UE4 builds (e.g. Asgard's Wrath 2, RE4, In Death) compile it differently (shared mask registers) and aren't matched |
| OpenGL ES game: the GPU hangs at one effect (freeze/exit, compositor watchdog, e.g. Vader Immortal's lightspeed jump) | a shader (as Zink compiles it) reads loop counters/accumulators before setting them | capture the SPIR-V (adapter `zink_shader_dump=1` writes every module to `files/fp_spirv/`, or a GPU capture), then a `zink_shader_fix` entry (same format as `vk_shader_fix`) + `frame.zink_shader_fix` (Vulkan layer under Zink, activated through GraphicsEnv's debug layer list); log `shader fix layer: fixed shader module N`; triage `zink-shader-fix-mismatch` when a Frame update changed the driver's output |
| 2D Android app: Steam says it's running but nothing shows | Lepton runs apps headless unless the app folder has `lepton-show-flatscreen` | FramePort adds it for apps without VR (agent v28+); reinstall apps installed before |
| A phone/tablet app shows nothing in the headset, or a VR app opens as a flat window | FramePort's VR/2D guess (`vr_kind`) is wrong for this app | patch `device.display_mode` → **Flat window** or **VR** (Customize → "Show as VR or as a flat window"), then Update on Frame |
| "Install with FrameDrop" button opens FrameDrop (or nothing) instead of FramePort | another program owns `framedrop://`, or the switch is off, or macOS (Flet can't receive links there) | Settings → Install links → **Use FramePort for these links**; else Add games → Install from a link… (paste the button's address) |
@@ -108,6 +124,7 @@ version is `catalog/triage.yaml` (used by `frameport test` / the Job screen); ke
| Black screen, audio works, GLES engine with direct VrApi | Mesa rejects Quest-style GLSL | `frame.gl_shim` (logs `GLShim: SHADER COMPILE FAILED` + source lines) |
| Black screen, audio works, log `Unsupported VrApi layer type N` | bridge drops frames containing that layer | extend the bridge (cylinder=3 is converted to a quad already) |
| Only some draws visible (e.g. controllers) + `glGetError 0x502` | multiview shaders used on single-view FBOs | GL shim `gl_hide_multiview=1` (default) |
| Own GLES engine (OpenXR, not VrApi): eye view fine, but HUD / menu / PDA panels black (e.g. Doom3Quest, GitHub #77; no error in the log) | every shader declares `layout(num_views=2) in;`, also the ones drawn into the engine's single-layer offscreen framebuffers (2D textures/renderbuffers); OVR_multiview makes such draws INVALID_OPERATION and Mesa drops them (`draw_validate.c`), Quest's driver doesn't | `frame.gl_multiview_fbo` (opt-in, experimental: `libfpglmv.so` interposes GLES and draws those cases with a single-view twin of the program; logs `GLMV: twin built: program N -> M`, per-5-s `single-view draws` counters; `gl_mv_debug=1` adds glGetError checks; triage `gl-multiview-twin-failed`). Alternative: the game's own fix (two-layer multiview pool, Xandrix's patch in #77) |
| Upside-down image in a GL bridge game | GL images start at the bottom row | fixed in the bridge (swap angleUp/Down for GL chains) |
| UI panels upside down (AC Nexus) | XrCompositionLayerImageLayoutFB VERTICAL_FLIP unsupported | adapter `flip_emul=1` (default); rotating quads makes them vanish |
| Passthrough black (BAM) | XR_FB_passthrough missing | adapter `passthrough_emul=1` (default) + `patch_force_passthrough` for MR-only games |
+140
View File
@@ -0,0 +1,140 @@
# Batman cutscene playback on Steam Frame
Batman: Arkham Shadow (`com.camouflaj.manta`) submits its prerecorded cutscenes
through Android video surfaces and stereoscopic 180-degree OpenXR equirectangular
layers. Lepton/SteamVR's missing surface/layer support leaves those layers black,
while the separately played audio continues. Uploading software-decoded panorama
pixels also does not provide practical playback of the original 8192x4096 HEVC
assets.
## Scope and installation
FrameBridge enables the native-video path through the recipe-only adapter
setting `surface_native` (Batman's catalog recipe; a one-time library migration,
`batman_video_patches`, adds it and `frame.hw_video_decode` to existing Batman
recipes). Hardware decoding is deployed independently into FramePort's shared,
versioned codec store, without embedding decoder assets; games that have
`frame.hw_video_decode` in their recipe get the launcher line that places the
shared wrapper on the launcher's child PATH. Matching containers
receive read-only plugin/XML mounts and the Iris decoder device. Shared Lepton
files and original MP4/OBB assets are
never replaced, transcoded, resized, or rewritten.
The native projection, view recording and Vulkan-enable hooks are gated by
`surface_native`. With it off, Vulkan function lookup and directly exported
entry points pass through to the original loader; default `surface_emul`
alone does not enable the new Vulkan projection path. The fixture
`tests/fixtures/src/surface_hooks_test.c` checks function identity with the
setting off/on and direct-export forwarding with it off. Compile it with
`FRAMEPORT_FAKE_RUNTIME` as `libopenxr_loader_original.so`, then without that
define as the client; run each setting in a separate process next to the
production adapter and fake loader.
The wrapper verifies the tested Android 11 SoftOMX ABI. An existing runtime
hardware plugin takes precedence; incompatible runtimes keep their stock codecs.
Hardware decoder capacity is probed before the private component is advertised.
If the driver's session limit is exhausted, Android can fall back to software
decoding; that preserves functionality but not full-resolution performance.
FramePort does not change Steam's global hardware-decoding settings.
Other games don't get `surface_native`. The decoder is separate from that
setting, and runs in Lepton's arm64 media service. Rebuilding an older APK
removes the previously bundled codec files; launcher migration replaces
Batman's old per-game wrapper with the shared one. MP4 presence alone is not
evidence of compatible surface/overlay semantics.
The recipe change marks Batman's installed build "Update on Frame"; the shared
adapter revision is unchanged, so other games stay installed as they are.
## Decode and render path
`native/hevc/frameport_hevc.cpp` exposes `OMX.frameport.hevc.decoder` through the
tested SoftOMX ABI, using FFmpeg's LGPL Iris V4L2 hardware decoder wrapper.
Native surface clients receive full-resolution YUV hardware buffers with fences.
Compatible large native surfaces use fenced Vulkan transfers between imported
decoder and Android DMA buffers, retaining the decoded frame until GPU completion.
Other surfaces retain parallel NV12 row copies without CPU color conversion.
Input timestamps, EOS, dynamic dimensions, seek and flush
are preserved.
An AImageReader retains the decoder's actual image. The surface worker samples
that original YUV buffer and fuses conversion with visible-view projection on
the GPU. Vulkan imports the finished shared view with explicit foreign ownership
transfers. There is no full-panorama RGB intermediate or CPU picture readback.
The default native output is 2560x2560 per eye with a 12% tangent-space guard;
an explicit `equirect_res` takes precedence.
Every finished view carries the camera that actually generated its pixels.
Submitted game projection views are preferred over another tracking query.
The worker coalesces video/view arrivals and reuses held pixels only while the
visible frustum remains covered. Color/source changes redraw content without
unnecessarily changing the covered panorama-local sampling camera. Infinite
panoramas retain their layer rotation and have no translational parallax.
## Stable composition
A separately submitted projected video layer can alternate with the main game
projection as opaque coverage changes during head movement. That presentation
path exhibited snap-back/doubled video in headset tests even when rendering
and submitted camera metadata agreed.
The native path instead snapshots the game's successfully waited stereo color
image **before forwarding its release**, restoring its color-attachment layout
after the copy. Acquisition indices are tracked in FIFO order. The application
image is never sampled or modified after its OpenXR release, and release is not
deferred. Snapshot generations must match the last successful release.
The final GPU pass reprojects the cached video into the current game camera,
blends it with the scene in linear light, and draws directly into a runtime sRGB
attachment. One primary projection contains both scene and video, including
fades and uncovered hemisphere edges. Later subtitles/menu layers keep their
order. Once this output is ready, movie updates copy only to its private cache,
avoiding the additional standalone-output copy.
Batman attaches color-scale/bias and image-layout structures even when their
transforms are identity. The compositor applies RGB/alpha scale and bias using
OpenXR's straight-color transform and restored premultiplication, and respects
vertical orientation. Unknown scene/view chains, unsupported layout flags, and
intervening layers keep the ordinary fallback; settings are not silently lost.
The push constants fit Vulkan's guaranteed 128-byte minimum.
Each output image has separate commands, descriptors and fences. Positive wait
timeouts retain acquisition for retry. Missing snapshots retain the previous
combined output with the exact camera that produced it; old pixels are never
relabelled with a newer pose. Teardown retires snapshot writers and compositor
readers. Depth/motion-vector images from another render are not attached.
## Building and validation
Rebuild FrameBridge with Android NDK r27c:
```sh
python native/build.py --only adapter --ndk /path/to/android-ndk-r27c
```
The hardware plugin builder and its pinned source/runtime requirements are in
`native/hevc/README.md`. Shader sources and their generated SPIR-V are included.
Compile them for Vulkan 1.0 and validate with `spirv-val` when changing them.
The host tests cover package-scoped settings/assets/freshness, existing-wrapper
updates, codec extraction checksums, runtime/container isolation, and preservation
of original video assets. Android fixtures in `tests/fixtures/src/` exercise the
production Vulkan shaders, hardware worker, camera/coverage helpers and YUV copies.
The original-8K worker test requires a lawfully supplied cutscene file and the
private codec in an isolated Android container; no game assets are distributed.
Validation on Steam Frame included stereo/fade/transparent/uncovered pixels,
asymmetric vertical orientation, color/alpha transforms, unsupported-chain
fallback, timeout retry, held camera metadata, reader teardown, hardware playback,
pause/resume and seek. One isolated run presented 594/600 and 118/120 distinct
scheduled original pictures, none early; 120 moving-head composition frames
averaged 1.16 ms for submission plus GPU completion. These are isolated fixture
results, not a guarantee of full-game frame rate.
The final build was also tested in Batman in-headset: cutscenes displayed and
head-movement snap-back was reported resolved. Logs confirmed the combined path,
full-resolution hardware decoding, over 12,500 scene frames with only two startup
holds, and no subsequent old promotion messages or composition setup failures.
Some frame-rate dips and existing Unity render-pass warnings remain. The patch
does not claim universal game compatibility, exact Quest 3 pixel equivalence,
or perfect frame timing.
+3 -1
View File
@@ -11,11 +11,13 @@ embeds debug paths (`-g`) and the dex depends on the d8 version, so those differ
| Dir | Artifact | What / why |
|---|---|---|
| `adapter/` | `{arm64-v8a,armeabi-v7a}/libopenxr_loader_generic.so` | **FrameBridge**: replaces overport's generic loader (which is renamed `libopenxr_loader_original.so`) and fixes Steam Frame runtime gaps. Hooks xrCreateInstance, swapchains, xrEndFrame, spaces, xrPollEvent, … everything else is forwarded by `gen_forwarders.py`-generated tail calls. `scene_emu.c` = Meta scene/spatial-entity emulation; `flip_vk.c` = Vulkan blit for VERTICAL_FLIP quads. `session_fixes.c` = per-game session fixes, all off by default and hooked only when on (`layer_debug` diagnostics, `stable_local`, `focus_hold`, aim correction `aim_pitch/aim_yaw/aim_forward`, `refresh_rate`); `input_diag.c` = controller-input diagnostics (setting `input_diag`, off by default and hooked only when on; logs suggested interaction profiles and the runtime's answers, each hand's current profile, functions the runtime lacks and failing input/haptics/perf calls, each line once; tested on the host by `tests/test_input_diag.py`); `layer_emul_gl.c` = `equirect_emul` (GLES sessions only): 360° equirect/equirect2 layers become one adapter projection layer, drawn by a worker thread with its own EGL context shared with the app's: each 360° image is converted to a cube map only when it changes, and the view is redrawn only after a 4° head turn (GL/EGL resolved with dlopen, so Vulkan games never load them); `layer_math.h` = their pose/face math, tested on the host by `tests/test_layer_emul.py`. `render_model.c` = XR_FB_render_model emulation (setting `controller_models`, off by default): serves `files/framebridge/controller_{left,right}.glb`, which the agent converts on the Frame from SteamVR's own Frame controller render models (never shipped by FramePort); tested on the host by `tests/test_render_model.py`. Settings: `libframe_settings.so` in the APK + `settings.conf`/`framebridge.conf` on the Frame. |
| `adapter/` | `{arm64-v8a,armeabi-v7a}/libopenxr_loader_generic.so` | **FrameBridge**: replaces overport's generic loader (which is renamed `libopenxr_loader_original.so`) and fixes Steam Frame runtime gaps. Hooks xrCreateInstance, swapchains, xrEndFrame, spaces, xrPollEvent, … everything else is forwarded by `gen_forwarders.py`-generated tail calls. `scene_emu.c` = Meta scene/spatial-entity emulation; `flip_vk.c` = Vulkan blit for VERTICAL_FLIP quads. `session_fixes.c` = per-game session fixes, all off by default and hooked only when on (`layer_debug` diagnostics, `stable_local`, `focus_hold`, aim correction `aim_pitch/aim_yaw/aim_forward`, `refresh_rate`, `proximity_emul` = finger proximity (XR_FB_touch_controller_proximity, which the Frame lacks) from the capacitive touch inputs: OVRPlugin's `hand_thumb_proximity`/`hand_trigger_proximity` actions get extra Touch bindings); `input_diag.c` = controller-input diagnostics (setting `input_diag`, off by default and hooked only when on; logs suggested interaction profiles and the runtime's answers, each hand's current profile, functions the runtime lacks and failing input/haptics/perf calls, each line once; tested on the host by `tests/test_input_diag.py`); `layer_emul_gl.c` = `equirect_emul` (GLES sessions only): 360° equirect/equirect2 layers become one adapter projection layer, drawn by a worker thread with its own EGL context shared with the app's: each 360° image is converted to a cube map only when it changes, and the view is redrawn only after a 4° head turn (GL/EGL resolved with dlopen, so Vulkan games never load them); `layer_math.h` = their pose/face math, tested on the host by `tests/test_layer_emul.py`. `render_model.c` = XR_FB_render_model emulation (setting `controller_models`, off by default): serves `files/framebridge/controller_{left,right}.glb`, which the agent converts on the Frame from SteamVR's own Frame controller render models (never shipped by FramePort); tested on the host by `tests/test_render_model.py`. Settings: `libframe_settings.so` in the APK + `settings.conf`/`framebridge.conf` on the Frame. |
| `vrapi-bridge/` | `arm64-v8a/libvrapi.so` | VrApi → OpenXR bridge from [Android-XR-Bridge/OVRPort](https://github.com/Android-XR-Bridge/OVRPort) `native/vrapi` at 5e7df52 (GPL-3.0, `LICENSE.upstream`; unchanged upstream as of OVRPort v1.2.5, which ships the unpatched code as its opt-in `patch_vrapi_openxr` in experimental CLI builds), with our changes in `upstream-patches/`: GLES sessions + GL texture swapchains, cylinder→quad layers, GL vertical flip, UNORM↔sRGB format twins, 30 s VR-mode deadline, VALID-only recenter, loading-icon layers skipped, `vrapi_PollEvent`/`RecenterPose`/`SetDisplayRefreshRate`/`GetSystemPropertyFloatArray` (BlazeRush imports them, GitHub #57), diagnostics behind `-DOVP_GL_DIAG`. `upstream-patches/` reproduces these sources from the fork's `native/vrapi` (checked 2026-10-06 against its latest commit); upstream PRs Android-XR-Bridge/OVRPort#3-#8, tracked in GitHub #75. |
| `platformcompat/` | `arm64-v8a/libovrplatformcompat.so` | Real `ovrMessageType_ToString` (same fork, `native/platform`). |
| `langpack/` | `arm64-v8a/libfp_langpack.so` | Language packs for the Meta Platform SDK (patch `frame.langpacks`, opt-in). overport's platform loader is a dispatcher in front of Meta's own loader and answers `ovr_LanguagePack_GetCurrent/SetCurrent` with `return 0` (no reply ever). This library becomes the loader's first DT_NEEDED; the loader's own exports of the 31 functions it defines are made STB_LOCAL in `.dynsym` (`elf.hide_exports`, nothing moves), so symbol lookups reach the library first. It serves `<tag>.lang` files found in the game's OBB / app files (`$FRAMEPORT_LANGPACK_DIRS` overrides the search path) through `ovr_LanguagePack_*`, `ovr_AssetFile_GetList` (the loader's list + the packs) and `ovr_AssetFile_StatusById`; its own message queue is merged into `ovr_PopMessage`, and every handle that is not ours (an address-range check) goes to the loader's original function, whose address is read at run time from the loader's in-memory `.dynsym`. With patch `frame.asset_files` (marker byte `@FPASSETS@`, or env `FRAMEPORT_ASSET_FILES=1`) it also lists the data's `*.pak` content files as installed `default` asset files and answers `ovr_AssetFile_DownloadById` for them at once (a completed `DownloadUpdate`, then the result with the path). Host-tested against a stand-in loader (`tests/test_langpack.py`, plain `cc`, no NDK); the bionic/headset side is unverified. |
| `glshim/` | `arm64-v8a/libglshim.so` | Mesa GLSL compatibility for GLAD engines (hooks eglGetProcAddress): comments out `#pragma` before `#extension`, enables `GL_EXT_shader_implicit_conversions`, hides GL_OVR_multiview (`gl_hide_multiview`, default 1) and logs failed shaders. `-DGLSHIM_TRACE` adds per-FBO draw/error tracing. |
| `glmv/` | `arm64-v8a/libfpglmv.so` | Single-view draws of OVR_multiview programs (patch `frame.gl_multiview_fbo`, opt-in, GitHub #77). Mesa enforces OVR_multiview's rule that a draw's program declares as many views as the draw framebuffer has; engines that compile every shader with `num_views=2` and also draw into ordinary 2D framebuffers (Doom3Quest's HUD/PDA pool) lose those draws. The engine library gets it as first DT_NEEDED (direct `gl*` imports) and its `dlopen("libGLESv3.so")` string is rewritten to `libfpglmv.so` (same length; its `qgl*` dlsym table); linked `--no-as-needed` to libGLESv3 so dlsym on its handle finds everything it doesn't wrap. It records stage sources at glLinkProgram, caches the draw framebuffer's color-attachment view count per bind, and when a multiview program draws into a 0-view framebuffer it binds a lazily built twin (`glmv_rewrite.h`: num_views layout blanked, `gl_ViewID_OVR` -> `(0u)`; attribute locations + uniform block bindings copied, default-block uniforms copied before every such draw with a shadow to skip unchanged ones), draws, rebinds the original. Logcat tag `GLMV`; `gl_mv_debug=1`. The rewriter is host-tested on Doom3Quest's 19 shaders (`tests/test_gl_multiview_fbo.py`); untested on the device. |
| `zinkfix/` | `arm64-v8a/libVkLayer_fp_shaderfix.so` | Shader-fix Vulkan layer `VK_LAYER_FP_shader_fix` for OpenGL ES games (patch `frame.zink_shader_fix`): sits between Zink (Mesa's GL on Vulkan) and the driver and inserts the words of `zink_shader_fix` (same format as the Vulkan shim's `vk_shader_fix`: size + SHA-256 match) into SPIR-V modules; `zink_shader_dump=1` writes every distinct module to `files/fp_spirv/`. The engine library loads it first (DT_NEEDED); its constructor puts the layer in front of Android's GraphicsEnv debug layer list (private Android 11 `getDebugLayers`/`setDebugLayers`, found through libvulkan.so's dependencies) before EGL starts, so the loader picks it up from the app's lib dir. Exports only the enumeration functions and `VK_LAYER_FP_shader_fixGet*ProcAddr` (never plain `vk*` entry points). Vader Immortal's lightspeed shaders (Klownicle, GitHub #49). |
| `xrlayer/` | `linux-arm64/libxr_frameport_timefix.so` + `XR_APILAYER_FRAMEPORT_timefix.json` | OpenXR API layer for Windows PC VR games under Proton on the Frame (glibc aarch64, built freestanding with the NDK's clang), on by default (patch `pcvr.xr_timefix`). Retries `xrCreateInstance` as an OpenXR 1.0 app when the runtime rejects 1.1 (the Frame's SteamVR runtime does, and Proton 11's VR helper asks for 1.1). Also emulates `xrConvertTimespecTimeToTimeKHR`/`xrConvertTimeToTimespecTimeKHR` if the runtime refuses them (the Frame's Android runtime does; its Linux runtime, used by Proton, supports them as of 2026-09-29 — so this part is only a fallback; Proton's wineopenxr needs them for `XR_KHR_win32_convert_performance_counter_time`, which Revive requires) with the adapter's xrWaitFrame-calibrated offset, and drops the extension from xrCreateInstance if the runtime rejects it. Enabled per game by the Proton launch.sh (`XR_API_LAYER_PATH`, `XR_ENABLE_API_LAYERS`). `tests/test_xrlayer.py` builds it for x86_64 and drives it via ctypes. |
| `oculushmd/` | `win-x64/fp_oculushmd.exe` | PC VR counterpart of overport's `patch_oculus_unreal` (patch `pcvr.oculus_unreal`, default for Unreal Rift games on the Frame). Unreal's OculusHMD and LibOVR's `ovr_Detect` only start when the Windows named event `OculusHMDConnected` exists and is signalled (the Oculus service creates it). `fp_oculushmd.exe <command line>` creates it (manual reset, signalled), runs the command (Revive's injector) in a job object and keeps the event until every process in the job — the game and its children — has exited (fallback without job support: 3 minutes); returns the command's exit code and logs `FramePort oculushmd: …` to stderr (launch.log). Freestanding Windows x64 console exe (no CRT, no Windows SDK): the NDK's clang + `lld-link /Brepro` with a kernel32 import library generated by `llvm-dlltool`, so it's byte-reproducible. Tested on Windows from WSL with a build whose event name is `-DEVENT_NAME=L"…"` (the Oculus service owns the real event on a PC with the Oculus app). |
| `xrshim/` | `arm64-v8a/libframe_xrshim.so` | FrameBridge extension shim, only in builds with `controller_models=1`. overport's dispatcher (`libopenxr_loader.so`) answers `xrGetInstanceProcAddr` from a fixed table and refuses everything else (`overportOXR: Unknown proc addr: xrLoadRenderModelFB`), so the adapter never sees XR_FB_render_model lookups. Meta's OVRPlugin gets the function with `dlopen("libopenxr_loader.so")` + `dlsym`, so FramePort rewrites that `.rodata` string in `libOVRPlugin.so` (same length, in place) to `libframe_xrshim.so`. The shim returns the adapter's emulated functions (`framebridge_extension_proc`) and forwards every other name to overport. A DT_NEEDED interposer does not work here (dlsym on a handle searches that library first); tried and dropped. |
+130
View File
@@ -0,0 +1,130 @@
// SPDX-License-Identifier: GPL-3.0-only
// Included by frame_adapter.c (after layer_emul_gl.c, whose GL entry points it shares). cube_standin (default on):
// the Frame's runtime has no cube layers (XR_KHR_composition_layer_cube) and refuses cube swapchains (faceCount 6)
// with XR_ERROR_RUNTIME_FAILURE. OVRPlugin doesn't check: it goes on with "CreateSwapchain for eye 0: 0x0, 0 stages"
// and writes past its empty image list in the next ovrp_EndFrame4 (Unity's render thread SIGSEGV in memset, e.g.
// Budget Cuts Ultimate's cube-map overlay, GitHub #107). Only when the runtime refused one, a cube swapchain is served
// by the adapter instead: one GL cube-map texture (the format, size and mip levels asked for) in the app's current
// GLES context, acquire/wait/release succeed at once. The app renders or copies into it as usual; layers that use it
// are dropped in xrEndFrame (the runtime couldn't show them anyway). Vulkan sessions (no current EGL context) keep
// the runtime's error.
#define STANDIN_MAX 8
static struct { XrSwapchain handle; GLuint tex; } standins[STANDIN_MAX];
static pthread_mutex_t standin_lock = PTHREAD_MUTEX_INITIALIZER;
static int standin_find(XrSwapchain handle) {
if (!handle) return -1;
int slot = -1;
pthread_mutex_lock(&standin_lock);
for (int i = 0; i < STANDIN_MAX && slot < 0; ++i)
if (standins[i].handle == handle) slot = i;
pthread_mutex_unlock(&standin_lock);
return slot;
}
static int is_standin(XrSwapchain handle) { return cube_standin && standin_find(handle) >= 0; }
// After the runtime refused a swapchain: serve a cube stand-in if it was a cube swapchain in a GLES context.
static XrResult standin_after_failure(const XrSwapchainCreateInfo *info, XrSwapchain *out, XrResult result) {
if (XR_SUCCEEDED(result) || !cube_standin || !info || !out || info->faceCount != 6) return result;
if (info->width != info->height || !info->width || info->arraySize > 1) return result;
if (!p_eglCreateContext && !emul_load_gl()) { LOG("cube_standin: no GLES, the runtime's error stays"); return result; }
if (p_eglGetCurrentContext() == EGL_NO_CONTEXT) {
LOG("cube_standin: no current GLES context (Vulkan?), the runtime's error stays");
return result;
}
int slot = -1;
pthread_mutex_lock(&standin_lock);
for (int i = 0; i < STANDIN_MAX && slot < 0; ++i)
if (!standins[i].handle) slot = i;
if (slot >= 0) standins[slot].handle = (XrSwapchain)1; // reserved
pthread_mutex_unlock(&standin_lock);
if (slot < 0) { LOG("cube_standin: too many cube swapchains, the runtime's error stays"); return result; }
GLsizei levels = info->mipCount > 1 ? (GLsizei)info->mipCount : 1;
for (int i = 0; i < 8 && p_glGetError() != GL_NO_ERROR; ++i) {}
GLint previous = 0;
p_glGetIntegerv(GL_TEXTURE_BINDING_CUBE_MAP, &previous);
GLuint tex = 0;
p_glGenTextures(1, &tex);
p_glBindTexture(GL_TEXTURE_CUBE_MAP, tex);
p_glTexStorage2D(GL_TEXTURE_CUBE_MAP, levels, (GLenum)info->format, (GLsizei)info->width, (GLsizei)info->height);
GLenum err = p_glGetError();
p_glBindTexture(GL_TEXTURE_CUBE_MAP, (GLuint)previous); // the app's binding, untouched
if (err != GL_NO_ERROR) {
p_glDeleteTextures(1, &tex);
pthread_mutex_lock(&standin_lock);
standins[slot].handle = XR_NULL_HANDLE;
pthread_mutex_unlock(&standin_lock);
LOG("cube_standin: couldn't make a %ux%u cube map (GL 0x%x), the runtime's error stays", info->width,
info->height, err);
return result;
}
XrSwapchain handle = FAKE_HANDLE(XrSwapchain);
pthread_mutex_lock(&standin_lock);
standins[slot].handle = handle;
standins[slot].tex = tex;
pthread_mutex_unlock(&standin_lock);
*out = handle;
LOG("cube_standin: runtime refused a %ux%u cube swapchain (result=%d): served by FrameBridge (GL cube map %u, "
"%d levels); its cube layers are dropped", info->width, info->height, result, tex, (int)levels);
return XR_SUCCESS;
}
static XrResult standin_enumerate(XrSwapchain handle, uint32_t capacity, uint32_t *count, XrSwapchainImageBaseHeader *images) {
if (!count) return XR_ERROR_VALIDATION_FAILURE;
*count = 1;
if (!capacity) return XR_SUCCESS;
if (!images) return XR_ERROR_VALIDATION_FAILURE;
if (images->type != XR_TYPE_SWAPCHAIN_IMAGE_OPENGL_ES_KHR) return XR_ERROR_VALIDATION_FAILURE;
int slot = standin_find(handle);
((emul_gles_image *)images)[0].image = slot >= 0 ? standins[slot].tex : 0;
return XR_SUCCESS;
}
static void standin_destroy(XrSwapchain handle) {
pthread_mutex_lock(&standin_lock);
for (int i = 0; i < STANDIN_MAX; ++i)
if (standins[i].handle == handle) {
if (p_eglGetCurrentContext && p_eglGetCurrentContext() != EGL_NO_CONTEXT) p_glDeleteTextures(1, &standins[i].tex);
standins[i].handle = XR_NULL_HANDLE;
standins[i].tex = 0;
}
pthread_mutex_unlock(&standin_lock);
}
// A layer that shows a stand-in: never passed to the runtime (whatever layer_fix says).
static int layer_uses_standin(const XrCompositionLayerBaseHeader *layer) {
if (!cube_standin || !layer) return 0;
switch (layer->type) {
case XR_TYPE_COMPOSITION_LAYER_CUBE_KHR:
return is_standin(((const XrCompositionLayerCubeKHR *)layer)->swapchain);
case XR_TYPE_COMPOSITION_LAYER_QUAD:
return is_standin(((const XrCompositionLayerQuad *)layer)->subImage.swapchain);
case XR_TYPE_COMPOSITION_LAYER_CYLINDER_KHR:
return is_standin(((const XrCompositionLayerCylinderKHR *)layer)->subImage.swapchain);
case XR_TYPE_COMPOSITION_LAYER_EQUIRECT_KHR:
return is_standin(((const XrCompositionLayerEquirectKHR *)layer)->subImage.swapchain);
case XR_TYPE_COMPOSITION_LAYER_EQUIRECT2_KHR:
return is_standin(((const XrCompositionLayerEquirect2KHR *)layer)->subImage.swapchain);
case XR_TYPE_COMPOSITION_LAYER_PROJECTION: {
const XrCompositionLayerProjection *p = (const XrCompositionLayerProjection *)layer;
for (uint32_t v = 0; v < p->viewCount; ++v)
if (is_standin(p->views[v].subImage.swapchain)) return 1;
return 0;
}
default:
return 0;
}
}
// XR_FB_swapchain_update_state on a stand-in: nothing to update (only hooked when the runtime has the function).
static PFN_xrUpdateSwapchainFB real_update_swapchain;
static PFN_xrGetSwapchainStateFB real_get_swapchain_state;
static XRAPI_ATTR XrResult XRAPI_CALL standin_update_swapchain(XrSwapchain swapchain, const XrSwapchainStateBaseHeaderFB *state) {
if (is_standin(swapchain)) return XR_SUCCESS;
return real_update_swapchain ? real_update_swapchain(swapchain, state) : XR_ERROR_FUNCTION_UNSUPPORTED;
}
static XRAPI_ATTR XrResult XRAPI_CALL standin_get_swapchain_state(XrSwapchain swapchain, XrSwapchainStateBaseHeaderFB *state) {
if (is_standin(swapchain)) return XR_ERROR_VALIDATION_FAILURE; // no state to report (apps treat it as "unsupported")
return real_get_swapchain_state ? real_get_swapchain_state(swapchain, state) : XR_ERROR_FUNCTION_UNSUPPORTED;
}
+1
View File
@@ -40,6 +40,7 @@ static XRAPI_ATTR XrResult XRAPI_CALL eye_hook_xrReleaseSwapchainImage(XrSwapcha
const XrSwapchainImageReleaseInfo *info) {
PFN_xrReleaseSwapchainImage fn = (PFN_xrReleaseSwapchainImage)lookup(active_instance, "xrReleaseSwapchainImage");
if (!fn) return XR_ERROR_FUNCTION_UNSUPPORTED;
if (is_standin(swapchain)) return XR_SUCCESS;
if (release_wait_active()) eye_wait_for_gpu();
XrResult result = fn(swapchain, info);
if (eye_debug) {
+5 -1
View File
@@ -47,6 +47,7 @@ typedef struct {
VkImage images[MAX_IMAGES];
uint32_t image_count;
uint32_t last_acquired;
uint32_t acquired[MAX_IMAGES], acquired_count, waited_count;
XrSwapchain shadow;
XrRect2Di shadow_rect;
VkImage shadow_images[MAX_IMAGES];
@@ -105,7 +106,10 @@ static void flip_on_enumerate_images(XrSwapchain handle, uint32_t count, const X
static void flip_on_acquire(XrSwapchain handle, uint32_t index) {
pthread_mutex_lock(&flip_lock);
tracked_swapchain *t = find_tracked(handle, 0);
if (t) t->last_acquired = index;
if (t) {
t->last_acquired = index;
if(t->acquired_count<MAX_IMAGES)t->acquired[t->acquired_count++]=index;
}
pthread_mutex_unlock(&flip_lock);
}
+272 -8
View File
@@ -15,6 +15,7 @@
// * drops requested instance extensions the runtime lacks (e.g. XR_FB_passthrough);
// * retries rejected swapchains with 1 sample / a supported format (swapchain_fix, overport #71);
// * drops composition layers that reference swapchains that failed to create (layer_fix);
// * serves cube swapchains the runtime refuses as GL cube maps and drops their layers (cube_standin, cube_standin.c);
// * optionally requests mutable-format swapchain images (mutable_fix, off by default);
// * optionally swaps left/right images of stereo projection layers (swap_eyes, off by default);
// * emulates XR_FB_passthrough with XR_ENVIRONMENT_BLEND_MODE_ALPHA_BLEND when the runtime lacks it
@@ -37,6 +38,7 @@
// /sdcard/Android/data/<package>/files/framebridge.conf
// $FRAMEBRIDGE_CONFIG
#define _GNU_SOURCE
#define VK_USE_PLATFORM_ANDROID_KHR
#define XR_EXTENSION_PROTOTYPES
#include <openxr/openxr.h>
#include <android/log.h>
@@ -73,6 +75,7 @@ static void fb_log(const char *fmt, ...) {
}
#define LOG(...) fb_log(__VA_ARGS__)
#include "audio_metadata.h"
#include "surface_views.h"
static void *loader;
static PFN_xrGetInstanceProcAddr next_gipa;
@@ -80,8 +83,10 @@ static pthread_once_t init_once = PTHREAD_ONCE_INIT;
static XrInstance active_instance = XR_NULL_HANDLE;
static void *android_vm; // JavaVM from XrInstanceCreateInfoAndroidKHR (surface_swapchain.c)
static int surface_emul = 1; // setting: emulate Android surface swapchains
static int surface_native; // internal: GPU shared video buffers (panoramic video clients)
static int eye_debug; // setting: per-eye diagnostics + file log (eye_debug.c)
static int release_wait; // setting: wait for the app's GPU work before releasing images (2 = after 60 s: A/B)
static void surf_scene_destroy(XrSwapchain handle);
static void surf_on_destroy(XrSwapchain handle);
static float scale = 1.0f;
@@ -103,8 +108,11 @@ static int frame_open;
static int sc_acquires, sc_waits, sc_releases, sc_wait_fails; // per pacing period (layer_debug) // drop XrCompositionLayerColorScaleBiasKHR (the runtime's color pass)
static int controller_fix = 1;
static int swapchain_fix = 1;
static int cube_standin = 1; // cube swapchains the runtime refuses: served by the adapter (cube_standin.c)
static int rect_clamp = 1;
static int pose_consistency = 0; // repeat xrLocateViews queries for one display time get the same poses (GitHub #8) // clamp submitted image rects to their swapchain (SteamVR rejects a 1 px overrun)
static int pose_time_fix; // poses asked for at CLOCK_MONOTONIC "now" or far in the past: at XrTime "now" (pose_time.c)
static int pose_debug; // diagnostics: requested pose times vs the predicted display time (pose_time.c)
static int layer_fix = 1;
static int mutable_fix = 0;
static int swap_eyes = 0;
@@ -127,6 +135,8 @@ static int controller_models; // serve Frame controller models via XR_FB_render
// Per-game settings, all off by default (session_fixes.c, layer_emul_gl.c).
static int sync_guard; // xrSyncActions one at a time with xrPollEvent, paused briefly after focus returns
static int profile_remap = 1; // Meta's newer controller profiles (rejected by the Frame) -> oculus/touch_controller
static int proximity_emul; // finger proximity from capacitive touch: 1 thumb, 2 thumb + index (session_fixes.c)
static int runtime_has_proximity; // the runtime has XR_FB_touch_controller_proximity itself
static int layer_debug; // diagnostics: layers, swapchains, session states, spaces, aim/grip, refresh rates
static int input_diag; // diagnostics: controller profiles, bindings, missing functions, failing input calls
static int stable_local; // keep every LOCAL space the app creates on the session-start origin
@@ -137,7 +147,7 @@ static float aim_pitch, aim_yaw, aim_forward; // aim pose correction (degrees,
static float refresh_rate; // requested display refresh rate (Hz), 0 = the app's choice
static int equirect_emul; // show 360 layers as cube faces (GLES)
static int equirect_face = 1536; // max cube map face size (px)
static int equirect_res = 1536; // projection image size per eye (px)
static int equirect_res = 1536, equirect_res_set; // projection image size per eye (px)
static int equirect_flip; // source orientation fix: 1 upside down, 2 mirrored, 4 turned 180 degrees
static float equirect_fps = 60; // max redraws per second per 360 layer (0 = no limit)
static int equirect_stereo; // 0 auto (mono if the layer limit can't hold both eyes), 1 stereo, 2 mono
@@ -158,8 +168,11 @@ static void read_settings(const char *path) {
if (sscanf(line, "snapshot=%f", &value) == 1) snapshot = value > 0 ? (int)value : 0;
if (sscanf(line, "controller_fix=%f", &value) == 1) controller_fix = value != 0;
if (sscanf(line, "swapchain_fix=%f", &value) == 1) swapchain_fix = value != 0;
if (sscanf(line, "cube_standin=%f", &value) == 1) cube_standin = value != 0;
if (sscanf(line, "rect_clamp=%f", &value) == 1) rect_clamp = value != 0;
if (sscanf(line, "pose_consistency=%f", &value) == 1) pose_consistency = value != 0;
if (sscanf(line, "pose_debug=%f", &value) == 1) pose_debug = value != 0;
if (sscanf(line, "pose_time_fix=%f", &value) == 1) pose_time_fix = value != 0;
if (sscanf(line, "layer_fix=%f", &value) == 1) layer_fix = value != 0;
if (sscanf(line, "mutable_fix=%f", &value) == 1) mutable_fix = value != 0;
if (sscanf(line, "swap_eyes=%f", &value) == 1) swap_eyes = value != 0;
@@ -177,9 +190,11 @@ static void read_settings(const char *path) {
if (sscanf(line, "layer_debug=%f", &value) == 1) layer_debug = value != 0;
if (sscanf(line, "input_diag=%f", &value) == 1) input_diag = value != 0;
if (sscanf(line, "surface_emul=%f", &value) == 1) surface_emul = value != 0;
if (sscanf(line, "surface_native=%f", &value) == 1) surface_native = value != 0;
if (sscanf(line, "eye_debug=%f", &value) == 1) eye_debug = value != 0;
if (sscanf(line, "release_wait=%f", &value) == 1) release_wait = (int)value;
if (sscanf(line, "profile_remap=%f", &value) == 1) profile_remap = value != 0;
if (sscanf(line, "proximity_emul=%f", &value) == 1 && value >= 0 && value <= 2) proximity_emul = (int)value;
if (sscanf(line, "sync_guard=%f", &value) == 1) sync_guard = value != 0;
if (sscanf(line, "stable_local=%f", &value) == 1) stable_local = value != 0;
if (sscanf(line, "focus_hold=%f", &value) == 1) focus_hold = value != 0;
@@ -191,7 +206,7 @@ static void read_settings(const char *path) {
if (sscanf(line, "refresh_rate=%f", &value) == 1 && (value == 0 || (value >= 60 && value <= 144))) refresh_rate = value;
if (sscanf(line, "equirect_emul=%f", &value) == 1) equirect_emul = value != 0;
if (sscanf(line, "equirect_face=%f", &value) == 1 && value >= 256 && value <= 2730) equirect_face = (int)value;
if (sscanf(line, "equirect_res=%f", &value) == 1 && value >= 512 && value <= 4096) equirect_res = (int)value;
if (sscanf(line, "equirect_res=%f", &value) == 1 && value >= 512 && value <= 4096) {equirect_res = (int)value;equirect_res_set=1;}
if (sscanf(line, "equirect_flip=%f", &value) == 1 && value >= 0 && value <= 7) equirect_flip = (int)value;
if (sscanf(line, "equirect_fps=%f", &value) == 1 && value >= 0 && value <= 144) equirect_fps = value;
if (sscanf(line, "equirect_stereo=%f", &value) == 1 && value >= 0 && value <= 2) equirect_stereo = (int)value;
@@ -240,6 +255,8 @@ static void initialize(void) {
log_file = fopen(path, "a");
}
if (input_diag) LOG("per-game: input_diag=1 (controller-input diagnostics)");
if (proximity_emul) LOG("per-game: proximity_emul=%d (finger proximity from capacitive touch: %s)", proximity_emul,
proximity_emul > 1 ? "thumb + index" : "thumb");
if (hide_space_warp) LOG("per-game: hide_space_warp=1 (XR_FB_space_warp hidden, space warp info removed)");
if (strip_color_bias) LOG("per-game: strip_color_bias=%d (layer color scale/bias removed)", strip_color_bias);
if (frame_balance) LOG("per-game: frame_balance=1 (an open frame is ended before the next one begins)");
@@ -359,6 +376,7 @@ XRAPI_ATTR XrResult XRAPI_CALL xrCreateInstance(const XrInstanceCreateInfo *info
}
for (uint32_t j = 0; available && j < available_count; ++j)
if (!strcmp(available[j].extensionName, "XR_FB_composition_layer_image_layout")) runtime_has_image_layout = 1;
else if (!strcmp(available[j].extensionName, "XR_FB_touch_controller_proximity")) runtime_has_proximity = 1;
// Layer types are only valid if their extension ends up enabled; some apps submit them regardless.
int has_equirect = 0, has_equirect2 = 0, has_cylinder = 0, has_cube = 0;
for (uint32_t i = 0; i < kept; ++i) {
@@ -499,6 +517,10 @@ static int emul_is_virtual(XrSwapchain handle);
static void emul_virtual_destroy(XrSwapchain handle);
static XrResult emul_virtual_enumerate(XrSwapchain handle, uint32_t capacity, uint32_t *count, XrSwapchainImageBaseHeader *images);
static void emul_on_acquire(XrSwapchain handle, uint32_t index);
static XrResult standin_after_failure(const XrSwapchainCreateInfo *info, XrSwapchain *out, XrResult result);
static int is_standin(XrSwapchain handle);
static void standin_destroy(XrSwapchain handle);
static XrResult standin_enumerate(XrSwapchain handle, uint32_t capacity, uint32_t *count, XrSwapchainImageBaseHeader *images);
static int known_swapchain(XrSwapchain handle) {
int found = 0;
@@ -521,6 +543,11 @@ XRAPI_ATTR XrResult XRAPI_CALL xrCreateSwapchain(XrSession session, const XrSwap
fixed.next = p;
}
if (mutable_fix) fixed.usageFlags |= XR_SWAPCHAIN_USAGE_MUTABLE_FORMAT_BIT;
// Internal native-video composition snapshots the owned stereo scene before
// release. Other games and UI/depth/MSAA swapchains keep their original usage.
if(surface_native && fixed.arraySize==2 && fixed.sampleCount==1 &&
(fixed.usageFlags&XR_SWAPCHAIN_USAGE_COLOR_ATTACHMENT_BIT))
fixed.usageFlags |= XR_SWAPCHAIN_USAGE_TRANSFER_SRC_BIT;
if (equirect_emul && swapchain && emul_virtual_create(session, &fixed, swapchain)) {
remember_swapchain(*swapchain);
emul_on_create_swapchain(*swapchain, &fixed);
@@ -539,7 +566,7 @@ XRAPI_ATTR XrResult XRAPI_CALL xrCreateSwapchain(XrSession session, const XrSwap
snap_on_create(*swapchain, &fixed);
return result;
}
if (!swapchain_fix) return result;
if (!swapchain_fix) return standin_after_failure(&fixed, swapchain, result);
// Frame's runtime rejects some GLES formats (GL_RGBA8) and MSAA swapchains (overport #71).
if (fixed.sampleCount > 1) {
@@ -562,7 +589,7 @@ XRAPI_ATTR XrResult XRAPI_CALL xrCreateSwapchain(XrSession session, const XrSwap
emul_on_create_swapchain(*swapchain, &fixed);
snap_on_create(*swapchain, &fixed);
}
return result;
return standin_after_failure(&fixed, swapchain, result);
}
XRAPI_ATTR XrResult XRAPI_CALL xrDestroySwapchain(XrSwapchain swapchain) {
@@ -572,6 +599,8 @@ XRAPI_ATTR XrResult XRAPI_CALL xrDestroySwapchain(XrSwapchain swapchain) {
static int logged;
if (logged++ < 200) LOG("layer_debug: xrDestroySwapchain %p", (void *)swapchain);
}
if (is_standin(swapchain)) { standin_destroy(swapchain); return XR_SUCCESS; }
surf_scene_destroy(swapchain);
forget_swapchain(swapchain);
surf_on_destroy(swapchain);
flip_on_destroy(swapchain);
@@ -753,6 +782,7 @@ XRAPI_ATTR XrResult XRAPI_CALL xrGetSystemProperties(XrInstance instance, XrSyst
}
#include "flip_vk.c"
#include "pose_time.c"
// XR_KHR_convert_timespec_time for runtimes that lack it (Frame): XrTime is derived from the monotonic clock
// using the offset measured at the last xrWaitFrame. The runtime's own implementation is preferred.
@@ -762,10 +792,14 @@ static PFN_xrConvertTimeToTimespecTimeKHR runtime_time_to_timespec;
static XRAPI_ATTR XrResult XRAPI_CALL emu_timespec_to_time(XrInstance instance, const struct timespec *ts, XrTime *time) {
if (runtime_timespec_to_time) {
XrResult r = runtime_timespec_to_time(instance, ts, time);
if (r != XR_ERROR_FUNCTION_UNSUPPORTED) return r;
if (r != XR_ERROR_FUNCTION_UNSUPPORTED) {
if (XR_SUCCEEDED(r) && time) pose_time_note("xrConvertTimespecTimeToTimeKHR (runtime)", 0, 0, *time);
return r;
}
}
if (!ts || !time) return XR_ERROR_VALIDATION_FAILURE;
*time = (XrTime)((int64_t)ts->tv_sec * 1000000000ll + ts->tv_nsec + (xr_time_calibrated ? xr_time_offset : 0));
pose_time_note("xrConvertTimespecTimeToTimeKHR", 0, 0, *time);
return XR_SUCCESS;
}
static XRAPI_ATTR XrResult XRAPI_CALL emu_time_to_timespec(XrInstance instance, XrTime time, struct timespec *ts) {
@@ -781,6 +815,8 @@ static XRAPI_ATTR XrResult XRAPI_CALL emu_time_to_timespec(XrInstance instance,
}
XRAPI_ATTR XrResult XRAPI_CALL xrLocateSpace(XrSpace space, XrSpace baseSpace, XrTime time, XrSpaceLocation *location) {
time = pose_time_fixed(time);
pose_time_note("xrLocateSpace", (uint64_t)(uintptr_t)space, (uint64_t)(uintptr_t)baseSpace, time);
if (emulate_scene && location) {
XrPosef pose; XrSpaceLocationFlags flags;
if (locate_fake(space, baseSpace, time, &pose, &flags)) {
@@ -796,6 +832,14 @@ XRAPI_ATTR XrResult XRAPI_CALL xrLocateSpace(XrSpace space, XrSpace baseSpace, X
static XrResult locate_spaces_common(const char *name, XrSession session, const XrSpacesLocateInfo *info,
XrSpaceLocations *locations) {
int any_fake = 0;
XrSpacesLocateInfo moved;
if (info && pose_time_fix) {
moved = *info;
moved.time = pose_time_fixed(info->time);
info = &moved;
}
if (info) pose_time_note(name, info->spaceCount ? (uint64_t)(uintptr_t)info->spaces[0] : 0,
(uint64_t)(uintptr_t)info->baseSpace, info->time);
if (emulate_scene && info && locations) {
any_fake = fake_space_index(info->baseSpace) >= 0;
for (uint32_t i = 0; i < info->spaceCount && !any_fake; ++i) any_fake = fake_space_index(info->spaces[i]) >= 0;
@@ -829,8 +873,108 @@ XRAPI_ATTR XrResult XRAPI_CALL xrDestroySpace(XrSpace space) {
#include "input_diag.c"
#include "session_fixes.c"
#include "layer_emul_gl.c"
#include "cube_standin.c"
#include "snapshot_gl.c"
#include "surface_swapchain.c"
// GPU video buffers need explicit external-memory support on the app's device.
// Preserve the runtime's extension list and both Vulkan-enable entry points.
XRAPI_ATTR XrResult XRAPI_CALL xrCreateVulkanInstanceKHR(XrInstance instance,const XrVulkanInstanceCreateInfoKHR *info,
VkInstance *created,VkResult *vulkanResult) {
PFN_xrCreateVulkanInstanceKHR fn=(PFN_xrCreateVulkanInstanceKHR)lookup(instance,"xrCreateVulkanInstanceKHR");
if(!fn)return XR_ERROR_FUNCTION_UNSUPPORTED;
if(!surface_native)return fn(instance,info,created,vulkanResult);
XrResult result=fn(instance,info,created,vulkanResult);
if(XR_SUCCEEDED(result) && created && vulkanResult && *vulkanResult==VK_SUCCESS)vk.instance=*created;
return result;
}
static const char *surf_device_exts[] = {"VK_ANDROID_external_memory_android_hardware_buffer",
"VK_KHR_external_memory", "VK_KHR_get_memory_requirements2", "VK_KHR_dedicated_allocation",
"VK_EXT_queue_family_foreign", "VK_KHR_sampler_ycbcr_conversion", "VK_KHR_bind_memory2", "VK_KHR_maintenance1"};
static int surf_extension_present(const char *text,const char *name) {
size_t length=strlen(name);
for(const char *p=text;(p=strstr(p,name));p++)
if((p==text || p[-1]==' ') && (p[length]==' ' || p[length]=='\0'))return 1;
return 0;
}
static int surf_device_supported(PFN_vkGetInstanceProcAddr gipa, VkInstance instance, VkPhysicalDevice physical) {
if (!surface_native || !gipa) return 0;
if(!physical){
// Unity can ask for extension strings before it creates its instance.
// Query a temporary instance instead of depending on that call order.
PFN_vkCreateInstance create=(PFN_vkCreateInstance)gipa(VK_NULL_HANDLE,"vkCreateInstance");
VkApplicationInfo app={VK_STRUCTURE_TYPE_APPLICATION_INFO,NULL,"FrameBridge video capabilities",0,NULL,0,VK_API_VERSION_1_1};
VkInstanceCreateInfo ci={VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,NULL,0,&app};
VkInstance probe=VK_NULL_HANDLE;if(!create || create(&ci,NULL,&probe)!=VK_SUCCESS)return 0;
PFN_vkEnumeratePhysicalDevices devices=(PFN_vkEnumeratePhysicalDevices)gipa(probe,"vkEnumeratePhysicalDevices");
PFN_vkDestroyInstance destroy=(PFN_vkDestroyInstance)gipa(probe,"vkDestroyInstance");
uint32_t count=0;VkPhysicalDevice gpu=VK_NULL_HANDLE;
int ok=devices && devices(probe,&count,NULL)==VK_SUCCESS && count==1 &&
devices(probe,&count,&gpu)==VK_SUCCESS && surf_device_supported(gipa,probe,gpu);
if(destroy)destroy(probe,NULL);return ok;
}
PFN_vkEnumerateDeviceExtensionProperties enumerate=(PFN_vkEnumerateDeviceExtensionProperties)
gipa(instance,"vkEnumerateDeviceExtensionProperties");
uint32_t count=0;
if(!enumerate || enumerate(physical,NULL,&count,NULL)!=VK_SUCCESS || count>2048)return 0;
VkExtensionProperties *exts=calloc(count,sizeof(*exts));
if(!exts)return 0;
int ok=enumerate(physical,NULL,&count,exts)==VK_SUCCESS;
for(unsigned j=0;j<sizeof(surf_device_exts)/sizeof(*surf_device_exts);j++){
int found=0;for(uint32_t i=0;i<count;i++)found|=!strcmp(exts[i].extensionName,surf_device_exts[j]);
ok &= found;
}
free(exts);return ok;
}
XRAPI_ATTR XrResult XRAPI_CALL xrGetVulkanGraphicsDeviceKHR(XrInstance instance,XrSystemId system,
VkInstance vulkanInstance,VkPhysicalDevice *physical) {
PFN_xrGetVulkanGraphicsDeviceKHR fn=(PFN_xrGetVulkanGraphicsDeviceKHR)lookup(instance,"xrGetVulkanGraphicsDeviceKHR");
if(!surface_native)return fn?fn(instance,system,vulkanInstance,physical):XR_ERROR_FUNCTION_UNSUPPORTED;
XrResult result=fn?fn(instance,system,vulkanInstance,physical):XR_ERROR_FUNCTION_UNSUPPORTED;
if(XR_SUCCEEDED(result) && physical){vk.instance=vulkanInstance;vk.physical=*physical;}
return result;
}
XRAPI_ATTR XrResult XRAPI_CALL xrGetVulkanDeviceExtensionsKHR(XrInstance instance,XrSystemId system,
uint32_t capacity,uint32_t *count,char *buffer) {
PFN_xrGetVulkanDeviceExtensionsKHR fn=(PFN_xrGetVulkanDeviceExtensionsKHR)lookup(instance,"xrGetVulkanDeviceExtensionsKHR");
if(!fn)return XR_ERROR_FUNCTION_UNSUPPORTED;
if(!surface_native)return fn(instance,system,capacity,count,buffer);
void *lib=dlopen("libvulkan.so",RTLD_NOW|RTLD_LOCAL);
PFN_vkGetInstanceProcAddr gipa=lib?(PFN_vkGetInstanceProcAddr)dlsym(lib,"vkGetInstanceProcAddr"):NULL;
if(!surf_device_supported(gipa,vk.instance,vk.physical))return fn(instance,system,capacity,count,buffer);
uint32_t original=0;XrResult result=fn(instance,system,0,&original,NULL);
if(XR_FAILED(result) || !count || original>65536)return result;
char *text=calloc(original+1024,1);if(!text)return XR_ERROR_OUT_OF_MEMORY;
result=fn(instance,system,original,&original,text);
if(XR_SUCCEEDED(result)){
for(unsigned i=0;i<sizeof(surf_device_exts)/sizeof(*surf_device_exts);i++){
if(!surf_extension_present(text,surf_device_exts[i])){if(*text)strcat(text," ");strcat(text,surf_device_exts[i]);}
}
*count=(uint32_t)strlen(text)+1;
if(capacity && (capacity<*count || !buffer))result=XR_ERROR_SIZE_INSUFFICIENT;
else if(capacity)memcpy(buffer,text,*count);
}
free(text);return result;
}
XRAPI_ATTR XrResult XRAPI_CALL xrCreateVulkanDeviceKHR(XrInstance instance,const XrVulkanDeviceCreateInfoKHR *info,
VkDevice *device,VkResult *vulkanResult) {
PFN_xrCreateVulkanDeviceKHR fn=(PFN_xrCreateVulkanDeviceKHR)lookup(instance,"xrCreateVulkanDeviceKHR");
if(!fn)return XR_ERROR_FUNCTION_UNSUPPORTED;
if(!surface_native)return fn(instance,info,device,vulkanResult);
if(!info || !info->vulkanCreateInfo || !surf_device_supported(info->pfnGetInstanceProcAddr,
vk.instance,info->vulkanPhysicalDevice))return fn(instance,info,device,vulkanResult);
VkDeviceCreateInfo ci=*info->vulkanCreateInfo;
const char **names=calloc(ci.enabledExtensionCount+8,sizeof(*names));
if(!names)return XR_ERROR_OUT_OF_MEMORY;
for(uint32_t i=0;i<ci.enabledExtensionCount;i++)names[i]=ci.ppEnabledExtensionNames[i];
for(unsigned j=0;j<8;j++){
int found=0;for(uint32_t i=0;i<ci.enabledExtensionCount;i++)found|=!strcmp(names[i],surf_device_exts[j]);
if(!found)names[ci.enabledExtensionCount++]=surf_device_exts[j];
}
ci.ppEnabledExtensionNames=names;
XrVulkanDeviceCreateInfoKHR fixed=*info;fixed.vulkanCreateInfo=&ci;
XrResult result=fn(instance,&fixed,device,vulkanResult);free(names);return result;
}
#include "eye_debug.c"
// OpenXR requires xrGet*GraphicsRequirementsKHR before xrCreateSession; Meta's runtime doesn't enforce it, the Frame's
@@ -938,6 +1082,7 @@ XRAPI_ATTR XrResult XRAPI_CALL xrEnumerateSwapchainImages(XrSwapchain swapchain,
XrSwapchainImageBaseHeader *images) {
PFN_xrEnumerateSwapchainImages fn = (PFN_xrEnumerateSwapchainImages)lookup(active_instance, "xrEnumerateSwapchainImages");
if (!fn) return XR_ERROR_FUNCTION_UNSUPPORTED;
if (is_standin(swapchain)) return standin_enumerate(swapchain, capacity, count, images);
XrResult result = equirect_emul && emul_is_virtual(swapchain) ? emul_virtual_enumerate(swapchain, capacity, count, images)
: fn(swapchain, capacity, count, images);
if (XR_SUCCEEDED(result) && images && capacity && count) {
@@ -952,6 +1097,7 @@ XRAPI_ATTR XrResult XRAPI_CALL xrEnumerateSwapchainImages(XrSwapchain swapchain,
XRAPI_ATTR XrResult XRAPI_CALL xrWaitSwapchainImage(XrSwapchain swapchain, const XrSwapchainImageWaitInfo *info) {
PFN_xrWaitSwapchainImage fn = (PFN_xrWaitSwapchainImage)lookup(active_instance, "xrWaitSwapchainImage");
if (!fn) return XR_ERROR_FUNCTION_UNSUPPORTED;
if (is_standin(swapchain)) return XR_SUCCESS;
XrResult result = fn(swapchain, info);
__atomic_add_fetch(&sc_waits, 1, __ATOMIC_RELAXED);
if (result != XR_SUCCESS) __atomic_add_fetch(&sc_wait_fails, 1, __ATOMIC_RELAXED);
@@ -961,6 +1107,7 @@ XRAPI_ATTR XrResult XRAPI_CALL xrWaitSwapchainImage(XrSwapchain swapchain, const
XRAPI_ATTR XrResult XRAPI_CALL xrReleaseSwapchainImage(XrSwapchain swapchain, const XrSwapchainImageReleaseInfo *info) {
PFN_xrReleaseSwapchainImage fn = (PFN_xrReleaseSwapchainImage)lookup(active_instance, "xrReleaseSwapchainImage");
if (!fn) return XR_ERROR_FUNCTION_UNSUPPORTED;
if (is_standin(swapchain)) return XR_SUCCESS;
__atomic_add_fetch(&sc_releases, 1, __ATOMIC_RELAXED);
return fn(swapchain, info);
}
@@ -969,6 +1116,11 @@ XRAPI_ATTR XrResult XRAPI_CALL xrAcquireSwapchainImage(XrSwapchain swapchain, co
uint32_t *index) {
PFN_xrAcquireSwapchainImage fn = (PFN_xrAcquireSwapchainImage)lookup(active_instance, "xrAcquireSwapchainImage");
if (!fn) return XR_ERROR_FUNCTION_UNSUPPORTED;
if (is_standin(swapchain)) { // adapter-served cube stand-in: one image
if (!index) return XR_ERROR_VALIDATION_FAILURE;
*index = 0;
return XR_SUCCESS;
}
if (equirect_emul && emul_is_virtual(swapchain)) { // adapter-served write-once picture: one image
if (!index) return XR_ERROR_VALIDATION_FAILURE;
*index = 0;
@@ -985,6 +1137,37 @@ XRAPI_ATTR XrResult XRAPI_CALL xrAcquireSwapchainImage(XrSwapchain swapchain, co
return result;
}
// Copy scene content only while the oldest acquired image is successfully waited
// and still application-owned. Release itself is forwarded immediately.
static XRAPI_ATTR XrResult XRAPI_CALL surf_composite_release(XrSwapchain handle,const XrSwapchainImageReleaseInfo *info) {
pthread_mutex_lock(&flip_lock);
tracked_swapchain *t=find_tracked(handle,0);
if(t && t->acquired_count && t->waited_count)surf_scene_capture(t,t->acquired[0]);
pthread_mutex_unlock(&flip_lock);
XrResult result=equirect_emul?hook_xrReleaseSwapchainImage(handle,info):
((PFN_xrReleaseSwapchainImage)lookup(active_instance,"xrReleaseSwapchainImage"))(handle,info);
if(XR_SUCCEEDED(result)) {
surf_scene_release_commit(handle);
pthread_mutex_lock(&flip_lock);t=find_tracked(handle,0);
if(t && t->acquired_count) {
memmove(t->acquired,t->acquired+1,(--t->acquired_count)*sizeof(t->acquired[0]));
if(t->waited_count)t->waited_count--;
}
pthread_mutex_unlock(&flip_lock);
}
return result;
}
static XRAPI_ATTR XrResult XRAPI_CALL surf_composite_wait(XrSwapchain handle,const XrSwapchainImageWaitInfo *info) {
XrResult result=equirect_emul?hook_xrWaitSwapchainImage(handle,info):
((PFN_xrWaitSwapchainImage)lookup(active_instance,"xrWaitSwapchainImage"))(handle,info);
if(result==XR_SUCCESS) {
pthread_mutex_lock(&flip_lock);tracked_swapchain *t=find_tracked(handle,0);
if(t && t->waited_count<t->acquired_count)t->waited_count++;
pthread_mutex_unlock(&flip_lock);
}
return result;
}
// ---------------------------------------------------------------- tracking diagnostics
static XrSpace view_space_handle = XR_NULL_HANDLE;
@@ -1005,7 +1188,9 @@ XRAPI_ATTR XrResult XRAPI_CALL xrPollEvent(XrInstance instance, XrEventDataBuffe
if (got) return XR_SUCCESS;
}
if (sync_guard) pthread_mutex_lock(&sync_lock);
XrResult result = focus_hold && event ? focus_hold_poll(fn, instance, event) : fn(instance, event);
focus_log_next = fn; // the runtime's own focus changes are logged, before focus_hold hides any
XrResult result = focus_hold && event ? focus_hold_poll(focus_log_poll, instance, event)
: focus_log_poll(instance, event);
if (sync_guard) {
if (result == XR_SUCCESS && event && session_state_of(event) == XR_SESSION_STATE_FOCUSED)
sync_resume_at = monotonic_ns() + SYNC_GUARD_PAUSE_NS;
@@ -1079,6 +1264,10 @@ XRAPI_ATTR XrResult XRAPI_CALL xrWaitFrame(XrSession session, const XrFrameWaitI
// predictedDisplayTime is about one display period ahead of "now".
xr_time_offset = (int64_t)(state->predictedDisplayTime - state->predictedDisplayPeriod) - mono;
xr_time_calibrated = 1;
last_display_period = state->predictedDisplayPeriod;
pose_time_sample(xr_time_offset);
pose_time_display(state->predictedDisplayTime);
pose_time_note_offset((long long)(state->predictedDisplayTime - mono));
if (layer_debug) debug_aim_vs_grip(state->predictedDisplayTime);
}
return result;
@@ -1143,10 +1332,19 @@ XRAPI_ATTR XrResult XRAPI_CALL xrLocateViews(XrSession session, const XrViewLoca
uint32_t capacity, uint32_t *count, XrView *views) {
PFN_xrLocateViews fn = (PFN_xrLocateViews)lookup(active_instance, "xrLocateViews");
if (!fn) return XR_ERROR_FUNCTION_UNSUPPORTED;
XrViewLocateInfo moved;
if (info && pose_time_fix) {
moved = *info;
moved.displayTime = pose_time_fixed(info->displayTime);
info = &moved;
}
if (info) pose_time_note("xrLocateViews", (uint64_t)(uintptr_t)info->space, 0, info->displayTime);
int cacheable = pose_consistency && info && state && count && views && capacity > 0;
if (cacheable && pose_cache_lookup(session, info, state, capacity, count, views)) return XR_SUCCESS;
XrResult result = fn(session, info, state, capacity, count, views);
if (cacheable && result == XR_SUCCESS) pose_cache_store(session, info, state, *count, views);
if(surface_native && surface_emul && XR_SUCCEEDED(result) && count)
surf_views_record(session,info,state,*count<capacity?*count:capacity,views);
if (equirect_emul && XR_SUCCEEDED(result) && info && count && views && state &&
(state->viewStateFlags & XR_VIEW_STATE_ORIENTATION_VALID_BIT))
emul_on_locate_views(info->space, info->displayTime, *count < capacity ? *count : capacity, views);
@@ -1223,6 +1421,7 @@ XRAPI_ATTR XrResult XRAPI_CALL xrEndFrame(XrSession session, const XrFrameEndInf
frame_open = 0;
__atomic_add_fetch(&frame_ends, 1, __ATOMIC_RELAXED);
snap_end_frame(info);
if(surface_native)++sc_serial;
if (eye_debug) eye_debug_end_frame(session, info);
{ // frame pacing statistics every ~5 s: fps and submitted-vs-predicted display time
static struct timespec start;
@@ -1257,6 +1456,7 @@ XRAPI_ATTR XrResult XRAPI_CALL xrEndFrame(XrSession session, const XrFrameEndInf
__atomic_exchange_n(&input_sync_ok, 0, __ATOMIC_RELAXED), input_last_sync_result,
__atomic_exchange_n(&input_bool_reads, 0, __ATOMIC_RELAXED),
__atomic_exchange_n(&input_bool_true, 0, __ATOMIC_RELAXED));
pose_time_report();
frames = 0; drift_sum = drift_max = 0;
}
}
@@ -1300,9 +1500,38 @@ XRAPI_ATTR XrResult XRAPI_CALL xrEndFrame(XrSession session, const XrFrameEndInf
XrCompositionLayerProjectionView views[64][2];
XrCompositionLayerQuad quads[64];
uint32_t count = 0, dropped = 0, swapped = 0, passthrough = 0;
const XrCompositionLayerBaseHeader *surface_projections[SURF_MAX];
int surface_projection_count = 0;
for (uint32_t i = 0; i < info->layerCount; ++i) {
const XrCompositionLayerBaseHeader *layer = info->layers[i];
if (!layer) { ++dropped; continue; }
if (emul_is_equirect(layer)) {
const XrCompositionLayerBaseHeader *replacement = surface_native ? surf_projection_frame(session, info, layer) : NULL;
if (replacement) {
int already = 0;
for (int k = 0; k < surface_projection_count; ++k) already |= surface_projections[k] == replacement;
if (!already && surface_projection_count < SURF_MAX) {
surface_projections[surface_projection_count++] = replacement;
// An opaque native hemisphere covering the guarded stereo
// view hides every earlier layer. Cull only that hidden
// prefix: video becomes the primary projection, while
// later subtitles/menus keep their original order. Fades
// and uncovered views use the ordinary layered path.
const XrCompositionLayerBaseHeader *combined=NULL;
if(surface_native && count==1 && kept[0]->type==XR_TYPE_COMPOSITION_LAYER_PROJECTION && surf_composite_candidate(info,layer))
combined=surf_composite_frame(session,info,(const void*)kept[0],replacement);
if(combined) {kept[0]=combined;++swapped;}
else if (surf_projection_occludes(replacement)) {
dropped += count;
count = 0;
passthrough = 0;
}
if(!combined)kept[count++] = replacement;
}
++swapped;
continue;
}
}
if (emulate_passthrough && layer->type == XR_TYPE_COMPOSITION_LAYER_PASSTHROUGH_FB) {
++passthrough; // replaced by the runtime's camera environment below
continue;
@@ -1348,6 +1577,12 @@ XRAPI_ATTR XrResult XRAPI_CALL xrEndFrame(XrSession session, const XrFrameEndInf
++dropped; // an emulated video surface without a frame yet
continue;
}
if (layer_uses_standin(layer)) { // a cube layer whose swapchain the runtime refused (cube_standin.c)
static int logged;
if (logged++ < 3) LOG("cube_standin: dropped a layer (type=%d) that shows a stand-in swapchain", layer->type);
++dropped;
continue;
}
if (!layer || (layer_fix && !layer_usable(layer))) { ++dropped; continue; }
if (layer->type == XR_TYPE_COMPOSITION_LAYER_QUAD) {
const XrCompositionLayerQuad *flipped = flip_quad(session, (const XrCompositionLayerQuad *)layer, &quads[count]);
@@ -1678,6 +1913,14 @@ XRAPI_ATTR XrResult XRAPI_CALL xrEnumerateApiLayerProperties(uint32_t capacity,
// For native/xrshim: emulated functions that overport's dispatcher doesn't know (it never asks us for them).
__attribute__((visibility("default"))) PFN_xrVoidFunction framebridge_extension_proc(const char *name) {
pthread_once(&init_once, initialize);
if(surface_native && name){
#define NATIVE_PROC(fn) if(!strcmp(name,#fn))return (PFN_xrVoidFunction)fn;
NATIVE_PROC(xrGetVulkanGraphicsDeviceKHR)
NATIVE_PROC(xrGetVulkanDeviceExtensionsKHR)
NATIVE_PROC(xrCreateVulkanDeviceKHR)
NATIVE_PROC(xrCreateVulkanInstanceKHR)
#undef NATIVE_PROC
}
return name ? render_model_emulation(name) : NULL;
}
@@ -1727,6 +1970,14 @@ XRAPI_ATTR XrResult XRAPI_CALL xrGetInstanceProcAddr(XrInstance instance, const
HOOK(xrEnumerateInstanceExtensionProperties)
// Per-game hooks: only installed when their setting is on, so other games run through exactly the same calls.
#define HOOK_AS(fn, impl) if (!strcmp(name, #fn)) { *function = (PFN_xrVoidFunction)impl; return XR_SUCCESS; }
if (surface_native) {
HOOK(xrGetVulkanGraphicsDeviceKHR)
HOOK(xrGetVulkanDeviceExtensionsKHR)
HOOK(xrCreateVulkanDeviceKHR)
HOOK(xrCreateVulkanInstanceKHR)
HOOK_AS(xrReleaseSwapchainImage, surf_composite_release)
HOOK_AS(xrWaitSwapchainImage, surf_composite_wait)
}
if (equirect_emul) {
HOOK_AS(xrReleaseSwapchainImage, hook_xrReleaseSwapchainImage)
HOOK_AS(xrWaitSwapchainImage, hook_xrWaitSwapchainImage)
@@ -1738,14 +1989,27 @@ XRAPI_ATTR XrResult XRAPI_CALL xrGetInstanceProcAddr(XrInstance instance, const
}
if (surface_emul) HOOK_AS(xrCreateSwapchainAndroidSurfaceKHR, hook_xrCreateSwapchainAndroidSurfaceKHR)
if (eye_debug || release_wait) HOOK_AS(xrReleaseSwapchainImage, eye_hook_xrReleaseSwapchainImage)
if (layer_debug) { // counters only; every other wait/release hook above takes precedence
if (layer_debug || cube_standin) { // counters + cube stand-ins; every other wait/release hook above takes precedence
HOOK(xrWaitSwapchainImage)
HOOK(xrReleaseSwapchainImage)
}
if (cube_standin && (!strcmp(name, "xrUpdateSwapchainFB") || !strcmp(name, "xrGetSwapchainStateFB"))) {
XrResult result = next_gipa(instance, name, function); // only wrapped where the runtime has it
if (XR_FAILED(result) || !*function) return result;
if (!strcmp(name, "xrUpdateSwapchainFB")) {
real_update_swapchain = (PFN_xrUpdateSwapchainFB)*function;
*function = (PFN_xrVoidFunction)standin_update_swapchain;
} else {
real_get_swapchain_state = (PFN_xrGetSwapchainStateFB)*function;
*function = (PFN_xrVoidFunction)standin_get_swapchain_state;
}
return result;
}
if (sync_guard || layer_debug || input_diag) HOOK_AS(xrSyncActions, hook_xrSyncActions)
if (layer_debug) HOOK_AS(xrGetActionStateBoolean, hook_xrGetActionStateBoolean)
if (layer_debug || aim_correction_on() || profile_remap || input_diag)
if (layer_debug || aim_correction_on() || profile_remap || input_diag || proximity_emul)
HOOK_AS(xrSuggestInteractionProfileBindings, hook_xrSuggestInteractionProfileBindings)
if (proximity_emul) HOOK_AS(xrCreateAction, hook_xrCreateAction)
if (layer_debug || aim_correction_on()) {
HOOK_AS(xrCreateActionSpace, hook_xrCreateActionSpace)
}
+3 -1
View File
@@ -42,7 +42,7 @@ typedef struct { XrStructureType type; void *next; uint32_t image; } emul_gles_i
X(eglChooseConfig) X(eglCreatePbufferSurface) X(eglDestroySurface) X(eglGetCurrentContext) X(eglGetError) \
X(eglQueryString)
#define EMUL_GL_FUNCS(X) X(glFenceSync) X(glDeleteSync) X(glWaitSync) X(glClientWaitSync) X(glFlush) \
X(glGenFramebuffers) X(glBindFramebuffer) X(glFramebufferTexture2D) X(glCheckFramebufferStatus) X(glViewport) \
X(glGenFramebuffers) X(glDeleteFramebuffers) X(glBindFramebuffer) X(glFramebufferTexture2D) X(glCheckFramebufferStatus) X(glViewport) \
X(glUseProgram) X(glCreateShader) X(glShaderSource) X(glCompileShader) X(glGetShaderiv) X(glGetShaderInfoLog) \
X(glDeleteShader) X(glCreateProgram) X(glAttachShader) X(glLinkProgram) X(glGetProgramiv) X(glGetProgramInfoLog) \
X(glGetUniformLocation) X(glUniform1i) X(glUniform1f) X(glUniform3f) X(glUniform4f) X(glUniformMatrix3fv) \
@@ -304,6 +304,7 @@ static void emul_on_destroy_swapchain(XrSwapchain handle) {
static XRAPI_ATTR XrResult XRAPI_CALL hook_xrReleaseSwapchainImage(XrSwapchain swapchain, const XrSwapchainImageReleaseInfo *info) {
PFN_xrReleaseSwapchainImage fn = (PFN_xrReleaseSwapchainImage)lookup(active_instance, "xrReleaseSwapchainImage");
if (!fn) return XR_ERROR_FUNCTION_UNSUPPORTED;
if (is_standin(swapchain)) return XR_SUCCESS;
pthread_mutex_lock(&emul_lock);
emul_source *s = emul_active() ? emul_find_source(swapchain, 0) : NULL;
int index = s && s->acquired_count ? (int)s->acquired[0] : -1;
@@ -335,6 +336,7 @@ static XRAPI_ATTR XrResult XRAPI_CALL hook_xrReleaseSwapchainImage(XrSwapchain s
static XRAPI_ATTR XrResult XRAPI_CALL hook_xrWaitSwapchainImage(XrSwapchain swapchain, const XrSwapchainImageWaitInfo *info) {
PFN_xrWaitSwapchainImage fn = (PFN_xrWaitSwapchainImage)lookup(active_instance, "xrWaitSwapchainImage");
if (!fn) return XR_ERROR_FUNCTION_UNSUPPORTED;
if (is_standin(swapchain)) return XR_SUCCESS;
XrResult result = emul_is_virtual(swapchain) ? XR_SUCCESS : fn(swapchain, info);
pthread_mutex_lock(&emul_lock);
emul_source *s = emul_active() ? emul_find_source(swapchain, 0) : NULL;
+174
View File
@@ -0,0 +1,174 @@
// Included by frame_adapter.c: the times games locate poses at (pose_time_fix, pose_debug).
//
// pose_debug (diagnostics): every ~5 s, per located space (xrLocateSpace/xrLocateSpaces) and for xrLocateViews, the
// number of calls and the min/max of (requested time - the last xrWaitFrame's predictedDisplayTime); for
// xrConvertTimespecTimeToTimeKHR the same for its answers, plus the spread of the XrTime-vs-CLOCK_MONOTONIC offset
// measured at xrWaitFrame.
static XrDuration last_display_period;
#define PT_SLOTS 12
typedef struct {
const char *kind;
uint64_t space, base;
int count;
long long min, max; // ns relative to the last predicted display time
} pt_stat;
static pt_stat pt_stats[PT_SLOTS];
static int pt_overflow;
static long long pt_offset_min, pt_offset_max;
static int pt_offset_count;
static pthread_mutex_t pt_lock = PTHREAD_MUTEX_INITIALIZER;
static void pose_time_note(const char *kind, uint64_t space, uint64_t base, XrTime time) {
if (!pose_debug || !last_predicted_time) return;
long long d = (long long)(time - last_predicted_time);
pthread_mutex_lock(&pt_lock);
int i = 0;
while (i < PT_SLOTS && pt_stats[i].count &&
!(pt_stats[i].kind == kind && pt_stats[i].space == space && pt_stats[i].base == base))
++i;
if (i == PT_SLOTS) {
++pt_overflow;
} else {
pt_stat *s = &pt_stats[i];
if (!s->count) s->kind = kind, s->space = space, s->base = base, s->min = s->max = d;
if (d < s->min) s->min = d;
if (d > s->max) s->max = d;
++s->count;
}
pthread_mutex_unlock(&pt_lock);
}
// The offset sampled at xrWaitFrame dips (by up to 2.5 s) whenever xrWaitFrame returns late after a hitch, which put
// corrected times up to 2 s in the future (headless survey, 2026-10-09). The steady value is the largest recent sample:
// pose_time_fix uses the maximum of the last PT_RING samples (~2 s at 72 Hz; the offset drifts only ~0.14 s per hour).
#define PT_RING 144
static int64_t pt_ring[PT_RING];
static int pt_ring_n, pt_ring_i;
static void pose_time_sample(int64_t offset) { // XrTime "now" minus CLOCK_MONOTONIC, from xrWaitFrame
pthread_mutex_lock(&pt_lock);
pt_ring[pt_ring_i] = offset;
pt_ring_i = (pt_ring_i + 1) % PT_RING;
if (pt_ring_n < PT_RING) ++pt_ring_n;
pthread_mutex_unlock(&pt_lock);
}
// The last few predicted display times (xrWaitFrame): a pose asked for at one of them is the game rendering a frame
// and is never moved. On a Frame whose XrTime runs only ~70 ms ahead of the monotonic clock (GitHub #49), such a
// request could look nearer the monotonic "now" than XrTime's and was moved 68 ms into the future.
#define PT_DISPLAY_RING 6
#define PT_DISPLAY_MATCH 1000000ll // 1 ms
static XrTime pt_display[PT_DISPLAY_RING];
static int pt_display_i;
static void pose_time_display(XrTime predicted) { // from xrWaitFrame
pthread_mutex_lock(&pt_lock);
pt_display[pt_display_i] = predicted;
pt_display_i = (pt_display_i + 1) % PT_DISPLAY_RING;
pthread_mutex_unlock(&pt_lock);
}
static int pose_time_is_display(XrTime time) {
int found = 0;
pthread_mutex_lock(&pt_lock);
for (int i = 0; i < PT_DISPLAY_RING && !found; i++) {
long long d = (long long)(time - pt_display[i]);
found = pt_display[i] && d <= PT_DISPLAY_MATCH && d >= -PT_DISPLAY_MATCH;
}
pthread_mutex_unlock(&pt_lock);
return found;
}
static int64_t pose_time_offset(void) {
pthread_mutex_lock(&pt_lock);
int64_t best = pt_ring_n ? pt_ring[0] : 0;
for (int i = 1; i < pt_ring_n; i++)
if (pt_ring[i] > best) best = pt_ring[i];
pthread_mutex_unlock(&pt_lock);
return best;
}
static void pose_time_note_offset(long long offset) {
if (!pose_debug) return;
pthread_mutex_lock(&pt_lock);
if (!pt_offset_count || offset < pt_offset_min) pt_offset_min = offset;
if (!pt_offset_count || offset > pt_offset_max) pt_offset_max = offset;
++pt_offset_count;
pthread_mutex_unlock(&pt_lock);
}
// pose_time_fix: Meta's OVRPlugin takes "now" from CLOCK_MONOTONIC and passes it on as an XrTime unchanged (no
// conversion reaches FrameBridge: OVRPort's dispatcher answers XR_KHR_convert_timespec_time itself, 1:1, since the
// Frame's runtime lacks it). On a Quest XrTime is the monotonic clock; on the Frame it runs ahead (2.56 s measured on
// SteamOS 0.4.5, 0.05-0.9 s seen on older builds), so every "now" pose (Unity's physics step, OVRInput's controller
// poses) was located that far in the past and the hands trailed the controllers (BattleSisters, Sniper Elite VR).
// A located time nearer the monotonic clock than XrTime's "now" is taken as a monotonic timestamp and moved to the
// same moment in XrTime (offset measured at xrWaitFrame); a time more than PT_PAST_LIMIT before the predicted display
// time that isn't one (BattleSisters asks for its head at XrTime 0.1 s; Robo Recall, Phantom, Vader, Time Stall and
// The Room VR at ~0 every frame) is located at the predicted display time, the time the game renders with.
// A monotonic timestamp is only told apart when the clocks are more than PT_MONO_PERIODS display periods apart, and the
// time must be clearly nearer the monotonic "now" (at most a third of its distance to XrTime's "now"); a time equal to
// a recent predicted display time is never moved (GitHub #49: XrTime only ~68 ms ahead, display-time requests moved).
#define PT_PAST_LIMIT 500000000ll // 0.5 s: no runtime keeps a longer pose history; real past queries are far shorter
#define PT_MIN_OFFSET 5000000ll // XrTime and the monotonic clock this close: nothing to tell apart or to fix
#define PT_MONO_PERIODS 4
#define PT_DEFAULT_PERIOD 13888889ll // 72 Hz, before xrWaitFrame reported a period
static int pt_fixed_mono, pt_fixed_past;
static long long pt_fixed_min;
static XrTime pose_time_fixed(XrTime time) {
if (!pose_time_fix || !last_predicted_time || pt_ring_n < 8) return time; // a few frames of offset samples first
int64_t offset = pose_time_offset(); // XrTime "now" minus the monotonic clock (robust, see above)
if (offset < PT_MIN_OFFSET && offset > -PT_MIN_OFFSET) return time;
if (pose_time_is_display(time)) return time; // the frame (or a recent one) the game renders
long long period = last_display_period > 0 ? (long long)last_display_period : PT_DEFAULT_PERIOD;
long long abs_offset = offset < 0 ? -offset : offset;
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
long long mono = (long long)ts.tv_sec * 1000000000ll + ts.tv_nsec;
long long d_mono = (long long)time - mono, d_xr = (long long)time - (mono + offset);
long long abs_mono = d_mono < 0 ? -d_mono : d_mono, abs_xr = d_xr < 0 ? -d_xr : d_xr;
XrTime fixed;
int kind;
if (abs_offset > PT_MONO_PERIODS * period && abs_mono < PT_PAST_LIMIT && 3 * abs_mono < abs_xr) {
fixed = (XrTime)(time + offset), kind = 0; // a monotonic timestamp
} else if ((long long)(time - last_predicted_time) < -PT_PAST_LIMIT) {
fixed = last_predicted_time, kind = 1; // far in the past: the frame's display time
} else {
return time;
}
if (pose_debug) {
long long d = (long long)(time - last_predicted_time);
pthread_mutex_lock(&pt_lock);
if (!(pt_fixed_mono + pt_fixed_past) || d < pt_fixed_min) pt_fixed_min = d;
++*(kind ? &pt_fixed_past : &pt_fixed_mono);
pthread_mutex_unlock(&pt_lock);
}
static int logged[2];
if (logged[kind]++ < 3)
LOG("pose_time_fix: pose asked for at %.1f ms from the predicted display time (%s) located at %.1f ms",
(long long)(time - last_predicted_time) / 1e6, kind ? "far in the past" : "a monotonic-clock time",
(long long)(fixed - last_predicted_time) / 1e6);
return fixed;
}
// called from the pacing statistics in xrEndFrame
static void pose_time_report(void) {
if (!pose_debug) return;
pthread_mutex_lock(&pt_lock);
LOG("pose_debug: period %.2f ms; XrTime - monotonic at xrWaitFrame (%d): %.2f..%.2f ms", last_display_period / 1e6,
pt_offset_count, pt_offset_min / 1e6, pt_offset_max / 1e6);
for (int i = 0; i < PT_SLOTS && pt_stats[i].count; ++i)
LOG("pose_debug: %s space=0x%llx base=0x%llx: %d calls, time - predicted display time %.2f..%.2f ms",
pt_stats[i].kind, (unsigned long long)pt_stats[i].space, (unsigned long long)pt_stats[i].base,
pt_stats[i].count, pt_stats[i].min / 1e6, pt_stats[i].max / 1e6);
if (pt_overflow) LOG("pose_debug: %d calls not counted (more than %d spaces)", pt_overflow, PT_SLOTS);
if (pt_fixed_mono + pt_fixed_past)
LOG("pose_debug: pose_time_fix moved %d monotonic-clock times and %d far-past times (earliest asked %.2f ms)",
pt_fixed_mono, pt_fixed_past, pt_fixed_min / 1e6);
memset(pt_stats, 0, sizeof(pt_stats));
pt_overflow = pt_offset_count = pt_fixed_mono = pt_fixed_past = 0;
pthread_mutex_unlock(&pt_lock);
}
+124 -5
View File
@@ -163,6 +163,39 @@ static void focus_hold_note(int state) {
else if (state >= 0 && state != XR_SESSION_STATE_FOCUSED) is_focused = 0;
}
// ---------------------------------------------------------------- focus log (always on: rare events, cheap)
// Every time the runtime takes focus away and gives it back, as the runtime reports it (before focus_hold hides a dip
// from the app): FramePort's session triage counts these dips after a play session and suggests a longer
// focus_hold_ms when they keep reaching the game.
static PFN_xrPollEvent focus_log_next;
static int focus_log_focused;
static int64_t focus_log_lost_at;
static int focus_log_lost_state;
static XRAPI_ATTR XrResult XRAPI_CALL focus_log_poll(XrInstance instance, XrEventDataBuffer *event) {
XrResult r = focus_log_next(instance, event);
if (r != XR_SUCCESS || !event) return r;
int state = session_state_of(event);
if (state < 0) return r;
if (state == XR_SESSION_STATE_FOCUSED) {
if (focus_log_lost_at)
LOG("focus: back after %.0f ms (lost to state %d)", (monotonic_ns() - focus_log_lost_at) / 1e6,
focus_log_lost_state);
focus_log_focused = 1;
focus_log_lost_at = 0;
} else if (focus_log_focused && (state == XR_SESSION_STATE_VISIBLE || state == XR_SESSION_STATE_SYNCHRONIZED)) {
focus_log_focused = 0;
focus_log_lost_at = monotonic_ns();
focus_log_lost_state = state;
LOG("focus: lost (state %d)", state);
} else if (state != XR_SESSION_STATE_VISIBLE && state != XR_SESSION_STATE_SYNCHRONIZED) {
focus_log_focused = 0; // stopping, loss pending, exiting: the session ends, not a dip
if (focus_log_lost_at) LOG("focus: session ending (state %d)", state);
focus_log_lost_at = 0;
}
return r;
}
static XrResult focus_hold_poll(PFN_xrPollEvent fn, XrInstance instance, XrEventDataBuffer *event) {
for (;;) {
if (held.delivering) { // hand held events to the app, oldest first
@@ -285,6 +318,90 @@ static int touch_has(const char *path) {
return 0;
}
// ---------------------------------------------------------------- finger proximity from touch (proximity_emul)
// Meta's OVRPlugin reports a thumb or index finger resting near the controller through XR_FB_touch_controller_proximity
// (.../thumb_fb/proximity_fb, .../trigger/proximity_fb). The Frame's runtime doesn't have it; OVRPort's loader offers
// it to the game anyway, and the proximity actions never get a working binding: "near" stays false, so games that
// animate the hands from it show a thumb that never moves (Unreal's ThumbUp axis is "no thumb proximity", e.g. Vader
// Immortal; found by Klownicle, GitHub #49). With proximity_emul those actions are bound to the capacitive touch inputs
// instead (OpenXR combines several bindings of one boolean action with OR): thumb = thumbstick, face buttons or thumb
// rest touched; index (proximity_emul=2) = trigger touched. Only when the runtime lacks the extension itself.
static XrAction thumb_proximity_action, trigger_proximity_action;
static XRAPI_ATTR XrResult XRAPI_CALL hook_xrCreateAction(XrActionSet set, const XrActionCreateInfo *info,
XrAction *action) {
PFN_xrCreateAction fn = (PFN_xrCreateAction)lookup(active_instance, "xrCreateAction");
if (!fn) return XR_ERROR_FUNCTION_UNSUPPORTED;
XrResult r = fn(set, info, action);
if (XR_SUCCEEDED(r) && info && action) { // OVRPlugin's action names
if (!strcmp(info->actionName, "hand_thumb_proximity")) thumb_proximity_action = *action;
else if (!strcmp(info->actionName, "hand_trigger_proximity")) trigger_proximity_action = *action;
else return r;
LOG("proximity_emul: game action %s found", info->actionName);
}
return r;
}
static const char *const THUMB_TOUCH_LEFT[] = {"x/touch", "y/touch", "thumbstick/touch", "thumbrest/touch"};
static const char *const THUMB_TOUCH_RIGHT[] = {"a/touch", "b/touch", "thumbstick/touch", "thumbrest/touch"};
static int add_binding(XrInstance instance, PFN_xrStringToPath to_path, XrActionSuggestedBinding *b, uint32_t *n,
XrAction action, const char *hand, const char *input) {
char path[XR_MAX_PATH_LENGTH];
snprintf(path, sizeof(path), "/user/hand/%s/input/%s", hand, input);
XrPath p;
if (XR_FAILED(to_path(instance, path, &p))) return 0;
for (uint32_t i = 0; i < *n; ++i)
if (b[i].action == action && b[i].binding == p) return 0;
b[*n].action = action;
b[(*n)++].binding = p;
return 1;
}
// Suggests Touch bindings with finger proximity bound to the touch inputs (proximity_emul), falling back to the
// bindings as given when the runtime refuses them.
static XrResult suggest_touch(XrInstance instance, PFN_xrSuggestInteractionProfileBindings fn,
PFN_xrPathToString to_string, const XrInteractionProfileSuggestedBinding *suggested) {
PFN_xrStringToPath to_path = (PFN_xrStringToPath)lookup(instance, "xrStringToPath");
if (!proximity_emul || runtime_has_proximity || !to_path || !to_string) return fn(instance, suggested);
XrAction thumb = thumb_proximity_action, index = proximity_emul > 1 ? trigger_proximity_action : XR_NULL_HANDLE;
uint32_t n = suggested->countSuggestedBindings, kept = 0, dropped = 0, added = 0;
XrActionSuggestedBinding *b = calloc(n + 2 * 5, sizeof(*b));
if (!b) return fn(instance, suggested);
for (uint32_t i = 0; i < n; ++i) {
char path[XR_MAX_PATH_LENGTH];
uint32_t size = 0;
const XrActionSuggestedBinding *s = &suggested->suggestedBindings[i];
if (XR_SUCCEEDED(to_string(instance, s->binding, sizeof(path), &size, path)) && strstr(path, "/proximity_")) {
// the game's own proximity binding, which the runtime doesn't know: its action is bound to touch below
if (strstr(path, "/thumb")) { if (!thumb) thumb = s->action; }
else if (proximity_emul > 1 && !index) index = s->action;
++dropped;
continue;
}
b[kept++] = *s;
}
for (int hand = 0; hand < 2; ++hand) {
const char *name = hand ? "right" : "left";
const char *const *thumb_inputs = hand ? THUMB_TOUCH_RIGHT : THUMB_TOUCH_LEFT;
for (int c = 0; thumb && c < 4; ++c) added += add_binding(instance, to_path, b, &kept, thumb, name, thumb_inputs[c]);
if (index) added += add_binding(instance, to_path, b, &kept, index, name, "trigger/touch");
}
XrResult r;
if (!added && !dropped) r = fn(instance, suggested);
else {
XrInteractionProfileSuggestedBinding copy = *suggested;
copy.countSuggestedBindings = kept;
copy.suggestedBindings = b;
r = fn(instance, &copy);
LOG("proximity_emul: finger proximity bound to touch (%u binding(s) added, %u proximity path(s) replaced): %d",
added, dropped, r);
if (XR_FAILED(r)) r = fn(instance, suggested);
}
free(b);
return r;
}
static XrResult remap_to_touch(XrInstance instance, PFN_xrSuggestInteractionProfileBindings fn,
PFN_xrPathToString to_string, const XrInteractionProfileSuggestedBinding *suggested,
const char *profile) {
@@ -305,7 +422,7 @@ static XrResult remap_to_touch(XrInstance instance, PFN_xrSuggestInteractionProf
copy.interactionProfile = touch;
copy.countSuggestedBindings = kept;
copy.suggestedBindings = b;
XrResult r = kept ? fn(instance, &copy) : XR_ERROR_PATH_UNSUPPORTED;
XrResult r = kept ? suggest_touch(instance, fn, to_string, &copy) : XR_ERROR_PATH_UNSUPPORTED;
free(b);
LOG("controller profile %s -> oculus/touch_controller (%u bindings, %u dropped): %d", profile + 22, kept,
n - kept, r);
@@ -325,12 +442,14 @@ static XRAPI_ATTR XrResult XRAPI_CALL hook_xrSuggestInteractionProfileBindings(X
if (XR_SUCCEEDED(to_string(instance, suggested->suggestedBindings[i].binding, sizeof(path), &size, path)))
note_pose_binding(suggested->suggestedBindings[i].action, path);
}
XrResult r = fn(instance, suggested);
input_diag_suggested(instance, suggested, r, to_string); // the runtime's answer to the game's own suggestion
if (!profile_remap || !suggested || !to_string) return r;
char profile[XR_MAX_PATH_LENGTH] = {0};
uint32_t size = 0;
if (XR_FAILED(to_string(instance, suggested->interactionProfile, sizeof(profile), &size, profile))) return r;
int known = suggested && to_string &&
XR_SUCCEEDED(to_string(instance, suggested->interactionProfile, sizeof(profile), &size, profile));
XrResult r = known && !strcmp(profile, TOUCH_PROFILE) ? suggest_touch(instance, fn, to_string, suggested)
: fn(instance, suggested);
input_diag_suggested(instance, suggested, r, to_string); // the runtime's answer to the game's own suggestion
if (!profile_remap || !known) return r;
if (!strcmp(profile, TOUCH_PROFILE)) {
if (XR_SUCCEEDED(r)) app_suggested_touch = 1; // the app's own Touch bindings win over a remap
return r;
+383
View File
@@ -0,0 +1,383 @@
// SPDX-License-Identifier: GPL-3.0-only
// Included after surface_projection.c. Snapshots scene images BEFORE release,
// then composes decoded video + scene into one primary projection on the GPU.
#include "surface_composite.h"
#include "surface_composite_spv.h"
#define SC_SCENES 4
typedef struct {
XrSwapchain handle;
VkImage image;
VkImageView view;
VkDeviceMemory memory;
VkCommandBuffer commands[MAX_IMAGES];
VkFence fences[MAX_IMAGES];
int pending[MAX_IMAGES], ready;
uint64_t serial,captured_release,releases;
uint32_t width,height,layers;
} surf_scene_snapshot;
static surf_scene_snapshot sc_scenes[SC_SCENES];
static uint64_t sc_serial;
static int64_t sc_capture_until;
// Unity attaches both structures even when their transforms are identity.
// Apply supported transforms in our shader; reject other chains rather than
// silently discarding semantics when flattening the original scene.
static int sc_scene_supported(const XrCompositionLayerProjection *scene) {
int reason=0;
if(!scene || scene->viewCount!=2 || !scene->views)return 0;
int count=0;
for(const XrBaseInStructure *n=scene->next;n;n=n->next) {
if(++count>16){reason=-1;break;}
if(n->type==XR_TYPE_COMPOSITION_LAYER_COLOR_SCALE_BIAS_KHR)continue;
if(n->type==XR_TYPE_COMPOSITION_LAYER_IMAGE_LAYOUT_FB) {
const XrCompositionLayerImageLayoutFB *layout=(const void*)n;
if(!(layout->flags&~XR_COMPOSITION_LAYER_IMAGE_LAYOUT_VERTICAL_FLIP_BIT_FB))continue;
}
reason=n->type;break;
}
for(int e=0;e<2 && !reason;e++)if(scene->views[e].next)
reason=((const XrBaseInStructure*)scene->views[e].next)->type;
static int previous;
if(reason && reason!=previous)LOG("surface_composite: unsupported scene extension %d; retaining ordinary composition",reason);
previous=reason;return !reason;
}
typedef struct {
XrSwapchain output;
VkImage images[MAX_IMAGES];
VkImageView views[MAX_IMAGES];
VkFramebuffer framebuffers[MAX_IMAGES];
VkRenderPass render_pass;
VkSampler sampler;
VkDescriptorPool pool;
VkDescriptorSetLayout set_layout;
VkDescriptorSet sets[MAX_IMAGES][2];
VkPipelineLayout layout;
VkPipeline pipeline;
VkCommandBuffer commands[MAX_IMAGES];
VkFence fences[MAX_IMAGES];
int pending[MAX_IMAGES], ready, acquired, failed;
uint32_t count,index;
XrTime time;
XrCompositionLayerProjection layer;
XrCompositionLayerProjectionView eyes[2];
int64_t log_time;
uint64_t frames,holds;
} surf_composite;
static surf_composite sc_outputs[SURF_MAX];
static void sc_barrier(VkCommandBuffer cmd,VkImage image,uint32_t layers,VkImageLayout from,VkImageLayout to,
VkAccessFlags src,VkAccessFlags dst) {
VkImageMemoryBarrier b={VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,NULL,src,dst,from,to,
VK_QUEUE_FAMILY_IGNORED,VK_QUEUE_FAMILY_IGNORED,image,{VK_IMAGE_ASPECT_COLOR_BIT,0,1,0,layers}};
vk.CmdPipelineBarrier(cmd,VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
0,0,NULL,0,NULL,1,&b);
}
static int sc_command(VkCommandBuffer *cmd,VkFence *fence) {
VkCommandBufferAllocateInfo ai={VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,NULL,vk.pool,VK_COMMAND_BUFFER_LEVEL_PRIMARY,1};
VkFenceCreateInfo fi={VK_STRUCTURE_TYPE_FENCE_CREATE_INFO};
if(vk.AllocateCommandBuffers(vk.device,&ai,cmd)!=VK_SUCCESS)return 0;
if(vk.CreateFence(vk.device,&fi,NULL,fence)==VK_SUCCESS)return 1;
PFN_vkFreeCommandBuffers free_cmd=(PFN_vkFreeCommandBuffers)vk.GetDeviceProcAddr(vk.device,"vkFreeCommandBuffers");
free_cmd(vk.device,vk.pool,1,cmd);*cmd=VK_NULL_HANDLE;return 0;
}
static int sc_reuse(VkFence fence,int *pending) {
if(!*pending)return 1;
if(svk.GetFenceStatus(vk.device,fence)!=VK_SUCCESS)return 0;
if(vk.ResetFences(vk.device,1,&fence)!=VK_SUCCESS)return 0;
*pending=0;return 1;
}
static void sc_retire(VkCommandBuffer *commands,VkFence *fences,int *pending,uint32_t count) {
PFN_vkDestroyFence destroy=(PFN_vkDestroyFence)vk.GetDeviceProcAddr(vk.device,"vkDestroyFence");
PFN_vkFreeCommandBuffers free_cmd=(PFN_vkFreeCommandBuffers)vk.GetDeviceProcAddr(vk.device,"vkFreeCommandBuffers");
for(uint32_t i=0;i<count;i++) {
if(pending[i])vk.WaitForFences(vk.device,1,&fences[i],VK_TRUE,UINT64_MAX);
if(fences[i])destroy(vk.device,fences[i],NULL);
if(commands[i])free_cmd(vk.device,vk.pool,1,&commands[i]);
}
}
static void surf_scene_destroy(XrSwapchain handle) {
if(!handle || spvk.ready<=0)return;
// A compositor command can still be sampling this mirror after its
// snapshot copy completes. Retire those readers before destroying a view.
for(int k=0;k<SURF_MAX;k++)for(uint32_t j=0;j<sc_outputs[k].count;j++)
if(sc_outputs[k].pending[j])vk.WaitForFences(vk.device,1,&sc_outputs[k].fences[j],VK_TRUE,UINT64_MAX);
for(int i=0;i<SC_SCENES;i++)if(sc_scenes[i].handle==handle) {
surf_scene_snapshot *s=&sc_scenes[i];
sc_retire(s->commands,s->fences,s->pending,MAX_IMAGES);
if(s->view)spvk.DestroyImageView(vk.device,s->view,NULL);
if(s->image)spvk.DestroyImage(vk.device,s->image,NULL);
if(s->memory)spvk.FreeMemory(vk.device,s->memory,NULL);
memset(s,0,sizeof(*s));
}
}
static void surf_composite_destroy(surf_projection *p) {
surf_composite *c=&sc_outputs[p-surf_projections];
sc_retire(c->commands,c->fences,c->pending,c->count);
if(c->pipeline)spvk.DestroyPipeline(vk.device,c->pipeline,NULL);
if(c->layout)spvk.DestroyPipelineLayout(vk.device,c->layout,NULL);
if(c->pool)spvk.DestroyDescriptorPool(vk.device,c->pool,NULL);
if(c->set_layout)spvk.DestroyDescriptorSetLayout(vk.device,c->set_layout,NULL);
if(c->sampler)spvk.DestroySampler(vk.device,c->sampler,NULL);
for(uint32_t i=0;i<c->count;i++) {
if(c->framebuffers[i])spvk.DestroyFramebuffer(vk.device,c->framebuffers[i],NULL);
if(c->views[i])spvk.DestroyImageView(vk.device,c->views[i],NULL);
}
if(c->render_pass)spvk.DestroyRenderPass(vk.device,c->render_pass,NULL);
if(c->output) {
PFN_xrDestroySwapchain fn=(PFN_xrDestroySwapchain)lookup(active_instance,"xrDestroySwapchain");
if(c->acquired) {
PFN_xrWaitSwapchainImage wait=(PFN_xrWaitSwapchainImage)lookup(active_instance,"xrWaitSwapchainImage");
PFN_xrReleaseSwapchainImage release=(PFN_xrReleaseSwapchainImage)lookup(active_instance,"xrReleaseSwapchainImage");
XrSwapchainImageWaitInfo wi={XR_TYPE_SWAPCHAIN_IMAGE_WAIT_INFO,NULL,XR_INFINITE_DURATION};
XrSwapchainImageReleaseInfo ri={XR_TYPE_SWAPCHAIN_IMAGE_RELEASE_INFO};
if(wait(c->output,&wi)==XR_SUCCESS)release(c->output,&ri);
}
if(fn)fn(c->output);
}
memset(c,0,sizeof(*c));
}
// Called while the application still owns this successfully waited image.
// Queue ordering includes the application's rendering and this snapshot copy;
// no CPU readback, post-release access, or deferred OpenXR release is needed.
static void surf_scene_capture(tracked_swapchain *t,uint32_t index) {
if(!surface_native || monotonic_ns()>sc_capture_until || !t || index>=t->image_count ||
spvk.ready<=0 || t->info.sampleCount!=1 || t->info.arraySize!=2 ||
!(t->info.usageFlags&XR_SWAPCHAIN_USAGE_TRANSFER_SRC_BIT) ||
!(t->info.usageFlags&XR_SWAPCHAIN_USAGE_COLOR_ATTACHMENT_BIT))return;
surf_scene_snapshot *s=NULL;
for(int i=0;i<SC_SCENES;i++)if(sc_scenes[i].handle==t->handle){s=&sc_scenes[i];break;}
if(!s)for(int i=0;i<SC_SCENES;i++)if(!sc_scenes[i].handle){s=&sc_scenes[i];s->handle=t->handle;break;}
if(!s)return;
if(!s->view) {
s->width=t->info.width;s->height=t->info.height;s->layers=t->info.arraySize;
if(!surf_private_image(s->width,s->height,s->layers,(VkFormat)t->info.format,
VK_IMAGE_USAGE_TRANSFER_DST_BIT|VK_IMAGE_USAGE_SAMPLED_BIT,&s->image,&s->memory,&s->view)) {
surf_scene_destroy(t->handle);return;
}
}
if(!s->commands[index] && !sc_command(&s->commands[index],&s->fences[index]))return;
if(!sc_reuse(s->fences[index],&s->pending[index]))return;
VkCommandBuffer cmd=s->commands[index];
VkCommandBufferBeginInfo begin={VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,NULL,VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT};
if(vk.ResetCommandBuffer(cmd,0)!=VK_SUCCESS || vk.BeginCommandBuffer(cmd,&begin)!=VK_SUCCESS)return;
sc_barrier(cmd,t->images[index],s->layers,VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,VK_ACCESS_TRANSFER_READ_BIT);
sc_barrier(cmd,s->image,s->layers,s->ready?VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL:VK_IMAGE_LAYOUT_UNDEFINED,
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,s->ready?VK_ACCESS_SHADER_READ_BIT:0,VK_ACCESS_TRANSFER_WRITE_BIT);
VkImageCopy copy={{VK_IMAGE_ASPECT_COLOR_BIT,0,0,s->layers},{0,0,0},
{VK_IMAGE_ASPECT_COLOR_BIT,0,0,s->layers},{0,0,0},{s->width,s->height,1}};
spvk.CmdCopyImage(cmd,t->images[index],VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,s->image,VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,1,&copy);
sc_barrier(cmd,s->image,s->layers,VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
VK_ACCESS_TRANSFER_WRITE_BIT,VK_ACCESS_SHADER_READ_BIT);
sc_barrier(cmd,t->images[index],s->layers,VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
VK_ACCESS_TRANSFER_READ_BIT,VK_ACCESS_COLOR_ATTACHMENT_READ_BIT|VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT);
if(vk.EndCommandBuffer(cmd)!=VK_SUCCESS)return;
VkSubmitInfo submit={VK_STRUCTURE_TYPE_SUBMIT_INFO,NULL,0,NULL,NULL,1,&cmd};
if(vk.QueueSubmit(vk.queue,1,&submit,s->fences[index])!=VK_SUCCESS)return;
s->pending[index]=1;s->ready=1;s->serial=sc_serial+1;s->captured_release=s->releases+1;
}
static int sc_setup(XrSession session,surf_projection *p,surf_composite *c) {
if(c->pipeline)return 1;
if(c->failed)return 0;
PFN_xrCreateSwapchain create=(PFN_xrCreateSwapchain)lookup(active_instance,"xrCreateSwapchain");
PFN_xrEnumerateSwapchainImages enumerate=(PFN_xrEnumerateSwapchainImages)lookup(active_instance,"xrEnumerateSwapchainImages");
XrSwapchainCreateInfo ci={XR_TYPE_SWAPCHAIN_CREATE_INFO,NULL,0,
XR_SWAPCHAIN_USAGE_TRANSFER_DST_BIT|XR_SWAPCHAIN_USAGE_COLOR_ATTACHMENT_BIT,
VK_FORMAT_R8G8B8A8_SRGB,1,2*p->size,p->size,1,1,1};
if(!create || !enumerate || XR_FAILED(create(session,&ci,&c->output)))goto fail;
XrSwapchainImageVulkanKHR images[MAX_IMAGES];
for(int i=0;i<MAX_IMAGES;i++)images[i]=(XrSwapchainImageVulkanKHR){XR_TYPE_SWAPCHAIN_IMAGE_VULKAN_KHR};
if(XR_FAILED(enumerate(c->output,MAX_IMAGES,&c->count,(void*)images)) || !c->count || c->count>MAX_IMAGES) {
c->count=0;goto fail;
}
for(uint32_t i=0;i<c->count;i++) {
c->images[i]=images[i].image;
if(!sc_command(&c->commands[i],&c->fences[i]))goto fail;
}
VkAttachmentDescription attachment={0,VK_FORMAT_R8G8B8A8_SRGB,VK_SAMPLE_COUNT_1_BIT,
VK_ATTACHMENT_LOAD_OP_DONT_CARE,VK_ATTACHMENT_STORE_OP_STORE,VK_ATTACHMENT_LOAD_OP_DONT_CARE,
VK_ATTACHMENT_STORE_OP_DONT_CARE,VK_IMAGE_LAYOUT_UNDEFINED,VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
VkAttachmentReference reference={0,VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
VkSubpassDescription subpass={0,VK_PIPELINE_BIND_POINT_GRAPHICS,0,NULL,1,&reference};
VkSubpassDependency dependency={VK_SUBPASS_EXTERNAL,0,VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT|VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
VK_ACCESS_MEMORY_WRITE_BIT|VK_ACCESS_MEMORY_READ_BIT,VK_ACCESS_SHADER_READ_BIT|VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT};
VkRenderPassCreateInfo rpi={VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,NULL,0,1,&attachment,1,&subpass,1,&dependency};
if(spvk.CreateRenderPass(vk.device,&rpi,NULL,&c->render_pass)!=VK_SUCCESS)goto fail;
for(uint32_t i=0;i<c->count;i++) {
VkImageViewCreateInfo vi={VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,NULL,0,c->images[i],VK_IMAGE_VIEW_TYPE_2D,
VK_FORMAT_R8G8B8A8_SRGB,{0,0,0,0},{VK_IMAGE_ASPECT_COLOR_BIT,0,1,0,1}};
if(spvk.CreateImageView(vk.device,&vi,NULL,&c->views[i])!=VK_SUCCESS)goto fail;
VkFramebufferCreateInfo fi={VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO,NULL,0,c->render_pass,1,&c->views[i],2*p->size,p->size,1};
if(spvk.CreateFramebuffer(vk.device,&fi,NULL,&c->framebuffers[i])!=VK_SUCCESS)goto fail;
}
VkSamplerCreateInfo si={VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO,NULL,0,VK_FILTER_LINEAR,VK_FILTER_LINEAR,
VK_SAMPLER_MIPMAP_MODE_NEAREST,VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE};
if(spvk.CreateSampler(vk.device,&si,NULL,&c->sampler)!=VK_SUCCESS)goto fail;
VkDescriptorSetLayoutBinding bindings[2]={{0,VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,1,VK_SHADER_STAGE_FRAGMENT_BIT},
{1,VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,1,VK_SHADER_STAGE_FRAGMENT_BIT}};
VkDescriptorSetLayoutCreateInfo li={VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,NULL,0,2,bindings};
if(spvk.CreateDescriptorSetLayout(vk.device,&li,NULL,&c->set_layout)!=VK_SUCCESS)goto fail;
VkDescriptorPoolSize sizes[1]={{VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,4*c->count}};
VkDescriptorPoolCreateInfo pi={VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,NULL,0,2*c->count,1,sizes};
if(spvk.CreateDescriptorPool(vk.device,&pi,NULL,&c->pool)!=VK_SUCCESS)goto fail;
for(uint32_t i=0;i<c->count;i++)for(int e=0;e<2;e++) {
VkDescriptorSetAllocateInfo ai={VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO,NULL,c->pool,1,&c->set_layout};
if(spvk.AllocateDescriptorSets(vk.device,&ai,&c->sets[i][e])!=VK_SUCCESS)goto fail;
}
VkPushConstantRange range={VK_SHADER_STAGE_FRAGMENT_BIT,0,sizeof(surf_composite_params)};
VkPipelineLayoutCreateInfo pli={VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,NULL,0,1,&c->set_layout,1,&range};
if(spvk.CreatePipelineLayout(vk.device,&pli,NULL,&c->layout)!=VK_SUCCESS)goto fail;
VkShaderModule modules[2]={0};
VkShaderModuleCreateInfo mi={VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO,NULL,0,sizeof(surface_composite_vert_spv),surface_composite_vert_spv};
if(spvk.CreateShaderModule(vk.device,&mi,NULL,&modules[0])!=VK_SUCCESS)goto fail;
mi.codeSize=sizeof(surface_composite_frag_spv);mi.pCode=surface_composite_frag_spv;
if(spvk.CreateShaderModule(vk.device,&mi,NULL,&modules[1])!=VK_SUCCESS) {
spvk.DestroyShaderModule(vk.device,modules[0],NULL);goto fail;
}
VkPipelineShaderStageCreateInfo stages[2]={
{VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,NULL,0,VK_SHADER_STAGE_VERTEX_BIT,modules[0],"main"},
{VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,NULL,0,VK_SHADER_STAGE_FRAGMENT_BIT,modules[1],"main"}};
VkPipelineVertexInputStateCreateInfo vertices={VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO};
VkPipelineInputAssemblyStateCreateInfo assembly={VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,NULL,0,VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST};
VkPipelineViewportStateCreateInfo viewport={VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO,NULL,0,1,NULL,1,NULL};
VkPipelineRasterizationStateCreateInfo raster={VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO,NULL,0,VK_FALSE,VK_FALSE,
VK_POLYGON_MODE_FILL,VK_CULL_MODE_NONE,VK_FRONT_FACE_COUNTER_CLOCKWISE,VK_FALSE,0,0,0,1};
VkPipelineMultisampleStateCreateInfo samples={VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO,NULL,0,VK_SAMPLE_COUNT_1_BIT};
VkPipelineColorBlendAttachmentState blend={.colorWriteMask=VK_COLOR_COMPONENT_R_BIT|VK_COLOR_COMPONENT_G_BIT|VK_COLOR_COMPONENT_B_BIT|VK_COLOR_COMPONENT_A_BIT};
VkPipelineColorBlendStateCreateInfo blends={VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO,NULL,0,VK_FALSE,VK_LOGIC_OP_COPY,1,&blend};
VkDynamicState dynamic_states[2]={VK_DYNAMIC_STATE_VIEWPORT,VK_DYNAMIC_STATE_SCISSOR};
VkPipelineDynamicStateCreateInfo dynamic={VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO,NULL,0,2,dynamic_states};
VkGraphicsPipelineCreateInfo pci={VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,NULL,0,2,stages,&vertices,&assembly,NULL,&viewport,
&raster,&samples,NULL,&blends,&dynamic,c->layout,c->render_pass,0,VK_NULL_HANDLE,-1};
VkResult result=spvk.CreateGraphicsPipelines(vk.device,VK_NULL_HANDLE,1,&pci,NULL,&c->pipeline);
for(int k=0;k<2;k++)spvk.DestroyShaderModule(vk.device,modules[k],NULL);
if(result!=VK_SUCCESS)goto fail;
LOG("surface_composite: one primary stereo scene, %ux%u per eye",p->size,p->size);return 1;
fail:
surf_composite_destroy(p);c->failed=1;
LOG("surface_composite: setup failed; retaining ordinary composition");return 0;
}
static const XrCompositionLayerBaseHeader *surf_composite_frame(XrSession session,const XrFrameEndInfo *info,
const XrCompositionLayerProjection *scene,const XrCompositionLayerBaseHeader *video) {
surf_projection *p=NULL;
for(int i=0;i<SURF_MAX;i++)if(video==(const void*)&surf_projections[i].layer && surfs[i].native_project) {
p=&surf_projections[i];break;
}
if(!p || !p->cache_ready || !sc_scene_supported(scene))return NULL;
if(p->presented_job.params[0][7]!=0 || p->presented_job.params[1][7]!=0)return NULL;
sc_capture_until=monotonic_ns()+500000000ll;
surf_composite *c=&sc_outputs[p-surf_projections];
surf_scene_snapshot *sources[2]={0};
for(int e=0;e<2;e++)for(int i=0;i<SC_SCENES;i++)if(sc_scenes[i].handle==scene->views[e].subImage.swapchain) {
sources[e]=&sc_scenes[i];break;
}
if(p->cached_job.space!=surfs[p-surf_projections].video_job.space)return NULL;
if(!sources[0] || !sources[1] || sources[0]->captured_release!=sources[0]->releases || sources[1]->captured_release!=sources[1]->releases)goto held;
for(int e=0;e<2;e++)if(scene->views[e].next || scene->views[e].subImage.imageArrayIndex>=sources[e]->layers)goto held;
if(!sc_setup(session,p,c))return NULL;
PFN_xrAcquireSwapchainImage acquire=(PFN_xrAcquireSwapchainImage)lookup(active_instance,"xrAcquireSwapchainImage");
PFN_xrWaitSwapchainImage wait=(PFN_xrWaitSwapchainImage)lookup(active_instance,"xrWaitSwapchainImage");
PFN_xrReleaseSwapchainImage release=(PFN_xrReleaseSwapchainImage)lookup(active_instance,"xrReleaseSwapchainImage");
XrSwapchainImageAcquireInfo ai={XR_TYPE_SWAPCHAIN_IMAGE_ACQUIRE_INFO};
XrSwapchainImageWaitInfo wi={XR_TYPE_SWAPCHAIN_IMAGE_WAIT_INFO,NULL,0};
XrSwapchainImageReleaseInfo ri={XR_TYPE_SWAPCHAIN_IMAGE_RELEASE_INFO};
if(!c->acquired) {
if(XR_FAILED(acquire(c->output,&ai,&c->index)))goto held;
c->acquired=1;
}
if(wait(c->output,&wi)!=XR_SUCCESS)goto held;
if(c->index>=c->count) {release(c->output,&ri);c->acquired=0;goto held;}
uint32_t index=c->index;
if(!sc_reuse(c->fences[index],&c->pending[index]))goto held;
surf_swapchain *s=&surfs[p-surf_projections];
pthread_mutex_lock(&surf_lock);surf_video_job current=s->video_job;pthread_mutex_unlock(&surf_lock);
VkCommandBuffer cmd=c->commands[index];
VkCommandBufferBeginInfo begin={VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,NULL,VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT};
if(vk.ResetCommandBuffer(cmd,0)!=VK_SUCCESS || vk.BeginCommandBuffer(cmd,&begin)!=VK_SUCCESS)goto held;
VkRenderPassBeginInfo rbi={VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,NULL,c->render_pass,c->framebuffers[index],
{{0,0},{2*p->size,p->size}},0,NULL};
spvk.CmdBeginRenderPass(cmd,&rbi,VK_SUBPASS_CONTENTS_INLINE);
spvk.CmdBindPipeline(cmd,VK_PIPELINE_BIND_POINT_GRAPHICS,c->pipeline);
for(int e=0;e<2;e++) {
VkDescriptorImageInfo di[2]={{c->sampler,p->video_cache_view,VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL},
{c->sampler,sources[e]->view,VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL}};
VkWriteDescriptorSet writes[2];
for(int k=0;k<2;k++)writes[k]=(VkWriteDescriptorSet){VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,NULL,c->sets[index][e],k,0,1,
VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,&di[k]};
spvk.UpdateDescriptorSets(vk.device,2,writes,0,NULL);
spvk.CmdBindDescriptorSets(cmd,VK_PIPELINE_BIND_POINT_GRAPHICS,c->layout,0,1,&c->sets[index][e],0,NULL);
surf_composite_params params=surf_composite_parameters(&p->cached_job,&current,e,
scene->views[e].subImage.imageRect,sources[e]->width,sources[e]->height,scene->views[e].subImage.imageArrayIndex);
params.scene_options[0]=(scene->layerFlags&XR_COMPOSITION_LAYER_BLEND_TEXTURE_SOURCE_ALPHA_BIT)!=0;
params.scene_options[1]=(scene->layerFlags&XR_COMPOSITION_LAYER_UNPREMULTIPLIED_ALPHA_BIT)!=0;
for(const XrBaseInStructure *n=scene->next;n;n=n->next) {
if(n->type==XR_TYPE_COMPOSITION_LAYER_COLOR_SCALE_BIAS_KHR) {
const XrCompositionLayerColorScaleBiasKHR *color=(const void*)n;
memcpy(params.scene_scale,&color->colorScale,16);memcpy(params.scene_bias,&color->colorBias,16);
}
if(n->type==XR_TYPE_COMPOSITION_LAYER_IMAGE_LAYOUT_FB)
params.scene_options[2]=(((const XrCompositionLayerImageLayoutFB*)n)->flags&XR_COMPOSITION_LAYER_IMAGE_LAYOUT_VERTICAL_FLIP_BIT_FB)!=0;
}
VkViewport viewport={(float)(e*p->size),0,(float)p->size,(float)p->size,0,1};
VkRect2D scissor={{e*(int32_t)p->size,0},{p->size,p->size}};
spvk.CmdSetViewport(cmd,0,1,&viewport);spvk.CmdSetScissor(cmd,0,1,&scissor);
spvk.CmdPushConstants(cmd,c->layout,VK_SHADER_STAGE_FRAGMENT_BIT,0,sizeof(params),&params);
spvk.CmdDraw(cmd,3,1,0,0);
}
spvk.CmdEndRenderPass(cmd);
if(vk.EndCommandBuffer(cmd)!=VK_SUCCESS)goto held;
VkSubmitInfo submit={VK_STRUCTURE_TYPE_SUBMIT_INFO,NULL,0,NULL,NULL,1,&cmd};
if(vk.QueueSubmit(vk.queue,1,&submit,c->fences[index])!=VK_SUCCESS)goto held;
c->pending[index]=1;
if(XR_FAILED(release(c->output,&ri)))goto held;
c->acquired=0;
for(int e=0;e<2;e++) {
c->eyes[e]=scene->views[e];c->eyes[e].next=NULL;
c->eyes[e].subImage=(XrSwapchainSubImage){c->output,{{e*(int32_t)p->size,0},{(int32_t)p->size,(int32_t)p->size}},0};
}
c->layer=*scene;c->layer.layerFlags &= ~XR_COMPOSITION_LAYER_UNPREMULTIPLIED_ALPHA_BIT;c->layer.next=NULL;c->layer.views=c->eyes;c->ready=1;c->time=info->displayTime;c->frames++;
if(monotonic_ns()-c->log_time>5000000000ll) {
LOG("surface_composite: %llu new scene frames, %llu held; no scene/overlay promotion",(unsigned long long)c->frames,(unsigned long long)c->holds);
c->log_time=monotonic_ns();
}
return (const void*)&c->layer;
held:
c->holds++;
return c->ready && c->layer.space==scene->space?(const void*)&c->layer:NULL;
}
static int surf_composite_candidate(const XrFrameEndInfo *info,const XrCompositionLayerBaseHeader *video) {
if(!info || !info->layerCount || !info->layers[0] || info->layers[0]->type!=XR_TYPE_COMPOSITION_LAYER_PROJECTION ||
!emul_is_equirect(video))return 0;
const XrCompositionLayerProjection *scene=(const void*)info->layers[0];
if(!sc_scene_supported(scene))return 0;
emul_common target=emul_common_of(video);
for(uint32_t i=1;i<info->layerCount;i++) {
const XrCompositionLayerBaseHeader *layer=info->layers[i];
if(layer==video)return 1;
if(!layer)continue;
if(!emul_is_equirect(layer))return 0;
emul_common other=emul_common_of(layer);
if(other.sub.swapchain!=target.sub.swapchain || other.space!=target.space)return 0;
}
return 0;
}
static void surf_scene_release_commit(XrSwapchain handle) {
for(int i=0;i<SC_SCENES;i++)if(sc_scenes[i].handle==handle){sc_scenes[i].releases++;break;}
}
static int surf_composite_cached_only(const XrFrameEndInfo *info,surf_projection *p,
const surf_video_job *rendered,const surf_video_job *current) {
surf_composite *c=&sc_outputs[p-surf_projections];
const XrCompositionLayerProjection *scene=(const void*)info->layers[0];
return c->ready && !p->acquired && c->layer.space==scene->space && rendered->space==current->space &&
rendered->params[0][7]==0 && rendered->params[1][7]==0 && !c->failed;
}
static int surf_composite_active(surf_projection *p) {return sc_outputs[p-surf_projections].ready;}
+39
View File
@@ -0,0 +1,39 @@
#version 450
// Reproject the decoded video into the game camera, then compose in linear light.
// Every output pixel belongs to one primary projection, including fades/edges.
layout(location=0) in vec2 uv;
layout(location=0) out vec4 outputColor;
layout(binding=0) uniform sampler2D videoImage;
layout(binding=1) uniform sampler2DArray sceneImage;
layout(push_constant) uniform Params {
vec4 rotation; vec4 outputTans; vec4 videoTans;
vec4 sceneRect; vec4 options; vec4 sceneOptions; vec4 sceneScale; vec4 sceneBias;
} p;
vec3 rotate(vec4 q,vec3 v){return v+2.0*cross(q.xyz,cross(q.xyz,v)+q.w*v);}
void main(){
vec2 scenePixel=0.5/vec2(textureSize(sceneImage,0).xy);
vec2 sceneCoord=vec2(uv.x,p.sceneOptions.z>0 ? 1-uv.y : uv.y);
vec2 sceneUV=clamp(p.sceneRect.xy+sceneCoord*p.sceneRect.zw,p.sceneRect.xy+scenePixel,p.sceneRect.xy+p.sceneRect.zw-scenePixel);
vec4 scene=textureLod(sceneImage,vec3(sceneUV,p.options.y),0);
// Projection rows follow Vulkan/OpenXR's top-to-bottom convention.
vec3 ray=rotate(p.rotation,vec3(mix(p.outputTans.x,p.outputTans.y,uv.x),mix(p.outputTans.w,p.outputTans.z,uv.y),-1));
vec2 vuv=(ray.xy/-ray.z-p.videoTans.xz)/(p.videoTans.yw-p.videoTans.xz); vuv.y=1-vuv.y;
vec4 video=vec4(0);
if(ray.z<0 && all(greaterThanEqual(vuv,vec2(0))) && all(lessThanEqual(vuv,vec2(1))))
{
vec2 videoPixel=0.5/vec2(textureSize(videoImage,0));
vec4 videoRect=vec4(p.options.x*.5,0,.5,1);
vec2 videoUV=clamp(videoRect.xy+vuv*videoRect.zw,videoRect.xy+videoPixel,videoRect.xy+videoRect.zw-videoPixel);
video=textureLod(videoImage,videoUV,0);
}
float alpha=p.options.z>0 ? video.a : 1;
vec3 rgb=p.options.w>0 ? video.rgb*alpha : video.rgb;
float sceneAlpha=p.sceneOptions.x>0 ? scene.a : 1;
vec3 sceneRGB=p.sceneOptions.y>0 ? scene.rgb*sceneAlpha : scene.rgb;
// OpenXR colour transforms act on straight colour, then restore premultiplication.
vec4 sceneStraight=vec4(sceneAlpha>0 ? sceneRGB/sceneAlpha : vec3(0),sceneAlpha);
sceneStraight=sceneStraight*max(p.sceneScale,vec4(0))+p.sceneBias;
sceneAlpha=sceneStraight.a;sceneRGB=sceneStraight.rgb*sceneAlpha;
vec4 result=vec4(rgb+sceneRGB*(1-alpha),alpha+sceneAlpha*(1-alpha));
outputColor=result;
}
+29
View File
@@ -0,0 +1,29 @@
// SPDX-License-Identifier: GPL-3.0-only
// Parameters for composing a cached movie view into the game's scene camera.
#ifndef FRAMEBRIDGE_SURFACE_COMPOSITE_H
#define FRAMEBRIDGE_SURFACE_COMPOSITE_H
#include "surface_video.h"
typedef struct {
float rotation[4], output_tans[4], video_tans[4];
float scene_rect[4], options[4], scene_options[4], scene_scale[4], scene_bias[4];
} surf_composite_params;
static surf_composite_params surf_composite_parameters(const surf_video_job *rendered,
const surf_video_job *current,int eye,XrRect2Di rect,uint32_t width,uint32_t height,uint32_t array_index) {
surf_composite_params p={0};
// The current view must already be transformed into the panorama space.
XrPosef source=surf_video_pose(rendered,current,eye);
XrQuaternionf relative=lm_qmul(lm_qconj(source.orientation),current->views[eye].pose.orientation);
memcpy(p.rotation,&relative,sizeof(relative));
for(int i=0;i<4;i++) {
p.output_tans[i]=current->params[eye][8+i]/SURF_VIDEO_GUARD;
p.video_tans[i]=rendered->params[eye][8+i];
}
p.scene_rect[0]=rect.offset.x/(float)width;p.scene_rect[1]=rect.offset.y/(float)height;
p.scene_rect[2]=rect.extent.width/(float)width;p.scene_rect[3]=rect.extent.height/(float)height;
for(int i=0;i<4;i++)p.scene_scale[i]=1;
p.options[0]=(float)eye;p.options[1]=(float)array_index;
p.options[2]=(rendered->flags&XR_COMPOSITION_LAYER_BLEND_TEXTURE_SOURCE_ALPHA_BIT)!=0;
p.options[3]=(rendered->flags&XR_COMPOSITION_LAYER_UNPREMULTIPLIED_ALPHA_BIT)!=0;
return p;
}
#endif
+3
View File
@@ -0,0 +1,3 @@
#version 450
layout(location=0) out vec2 uv;
void main(){vec2 p=vec2((gl_VertexIndex<<1)&2,gl_VertexIndex&2);uv=p;gl_Position=vec4(p*2-1,0,1);}
+300
View File
@@ -0,0 +1,300 @@
// SPDX-License-Identifier: GPL-3.0-only
// Generated by glslc; Vulkan 1.0.
static const uint32_t surface_composite_vert_spv[]={
0x07230203,0x00010000,0x000d000a,0x0000002e,0x00000000,0x00020011,0x00000001,0x0006000b,
0x00000001,0x4c534c47,0x6474732e,0x3035342e,0x00000000,0x0003000e,0x00000000,0x00000001,
0x0008000f,0x00000000,0x00000004,0x6e69616d,0x00000000,0x0000000c,0x00000018,0x00000020,
0x00030003,0x00000002,0x000001c2,0x000a0004,0x475f4c47,0x4c474f4f,0x70635f45,0x74735f70,
0x5f656c79,0x656e696c,0x7269645f,0x69746365,0x00006576,0x00080004,0x475f4c47,0x4c474f4f,
0x6e695f45,0x64756c63,0x69645f65,0x74636572,0x00657669,0x00040005,0x00000004,0x6e69616d,
0x00000000,0x00030005,0x00000009,0x00000070,0x00060005,0x0000000c,0x565f6c67,0x65747265,
0x646e4978,0x00007865,0x00030005,0x00000018,0x00007675,0x00060005,0x0000001e,0x505f6c67,
0x65567265,0x78657472,0x00000000,0x00060006,0x0000001e,0x00000000,0x505f6c67,0x7469736f,
0x006e6f69,0x00070006,0x0000001e,0x00000001,0x505f6c67,0x746e696f,0x657a6953,0x00000000,
0x00070006,0x0000001e,0x00000002,0x435f6c67,0x4470696c,0x61747369,0x0065636e,0x00070006,
0x0000001e,0x00000003,0x435f6c67,0x446c6c75,0x61747369,0x0065636e,0x00030005,0x00000020,
0x00000000,0x00040047,0x0000000c,0x0000000b,0x0000002a,0x00040047,0x00000018,0x0000001e,
0x00000000,0x00050048,0x0000001e,0x00000000,0x0000000b,0x00000000,0x00050048,0x0000001e,
0x00000001,0x0000000b,0x00000001,0x00050048,0x0000001e,0x00000002,0x0000000b,0x00000003,
0x00050048,0x0000001e,0x00000003,0x0000000b,0x00000004,0x00030047,0x0000001e,0x00000002,
0x00020013,0x00000002,0x00030021,0x00000003,0x00000002,0x00030016,0x00000006,0x00000020,
0x00040017,0x00000007,0x00000006,0x00000002,0x00040020,0x00000008,0x00000007,0x00000007,
0x00040015,0x0000000a,0x00000020,0x00000001,0x00040020,0x0000000b,0x00000001,0x0000000a,
0x0004003b,0x0000000b,0x0000000c,0x00000001,0x0004002b,0x0000000a,0x0000000e,0x00000001,
0x0004002b,0x0000000a,0x00000010,0x00000002,0x00040020,0x00000017,0x00000003,0x00000007,
0x0004003b,0x00000017,0x00000018,0x00000003,0x00040017,0x0000001a,0x00000006,0x00000004,
0x00040015,0x0000001b,0x00000020,0x00000000,0x0004002b,0x0000001b,0x0000001c,0x00000001,
0x0004001c,0x0000001d,0x00000006,0x0000001c,0x0006001e,0x0000001e,0x0000001a,0x00000006,
0x0000001d,0x0000001d,0x00040020,0x0000001f,0x00000003,0x0000001e,0x0004003b,0x0000001f,
0x00000020,0x00000003,0x0004002b,0x0000000a,0x00000021,0x00000000,0x0004002b,0x00000006,
0x00000023,0x40000000,0x0004002b,0x00000006,0x00000025,0x3f800000,0x0004002b,0x00000006,
0x00000028,0x00000000,0x00040020,0x0000002c,0x00000003,0x0000001a,0x00050036,0x00000002,
0x00000004,0x00000000,0x00000003,0x000200f8,0x00000005,0x0004003b,0x00000008,0x00000009,
0x00000007,0x0004003d,0x0000000a,0x0000000d,0x0000000c,0x000500c4,0x0000000a,0x0000000f,
0x0000000d,0x0000000e,0x000500c7,0x0000000a,0x00000011,0x0000000f,0x00000010,0x0004006f,
0x00000006,0x00000012,0x00000011,0x0004003d,0x0000000a,0x00000013,0x0000000c,0x000500c7,
0x0000000a,0x00000014,0x00000013,0x00000010,0x0004006f,0x00000006,0x00000015,0x00000014,
0x00050050,0x00000007,0x00000016,0x00000012,0x00000015,0x0003003e,0x00000009,0x00000016,
0x0004003d,0x00000007,0x00000019,0x00000009,0x0003003e,0x00000018,0x00000019,0x0004003d,
0x00000007,0x00000022,0x00000009,0x0005008e,0x00000007,0x00000024,0x00000022,0x00000023,
0x00050050,0x00000007,0x00000026,0x00000025,0x00000025,0x00050083,0x00000007,0x00000027,
0x00000024,0x00000026,0x00050051,0x00000006,0x00000029,0x00000027,0x00000000,0x00050051,
0x00000006,0x0000002a,0x00000027,0x00000001,0x00070050,0x0000001a,0x0000002b,0x00000029,
0x0000002a,0x00000028,0x00000025,0x00050041,0x0000002c,0x0000002d,0x00000020,0x00000021,
0x0003003e,0x0000002d,0x0000002b,0x000100fd,0x00010038,
};
static const uint32_t surface_composite_frag_spv[]={
0x07230203,0x00010000,0x000d000a,0x00000153,0x00000000,0x00020011,0x00000001,0x00020011,
0x00000032,0x0006000b,0x00000001,0x4c534c47,0x6474732e,0x3035342e,0x00000000,0x0003000e,
0x00000000,0x00000001,0x0007000f,0x00000004,0x00000004,0x6e69616d,0x00000000,0x0000003a,
0x00000151,0x00030010,0x00000004,0x00000007,0x00030003,0x00000002,0x000001c2,0x000a0004,
0x475f4c47,0x4c474f4f,0x70635f45,0x74735f70,0x5f656c79,0x656e696c,0x7269645f,0x69746365,
0x00006576,0x00080004,0x475f4c47,0x4c474f4f,0x6e695f45,0x64756c63,0x69645f65,0x74636572,
0x00657669,0x00040005,0x00000004,0x6e69616d,0x00000000,0x00060005,0x0000000e,0x61746f72,
0x76286574,0x763b3466,0x003b3366,0x00030005,0x0000000c,0x00000071,0x00030005,0x0000000d,
0x00000076,0x00050005,0x00000027,0x6e656373,0x78695065,0x00006c65,0x00050005,0x0000002c,
0x6e656373,0x616d4965,0x00006567,0x00050005,0x00000038,0x6e656373,0x6f6f4365,0x00006472,
0x00030005,0x0000003a,0x00007675,0x00040005,0x0000003f,0x61726150,0x0000736d,0x00060006,
0x0000003f,0x00000000,0x61746f72,0x6e6f6974,0x00000000,0x00060006,0x0000003f,0x00000001,
0x7074756f,0x61547475,0x0000736e,0x00060006,0x0000003f,0x00000002,0x65646976,0x6e61546f,
0x00000073,0x00060006,0x0000003f,0x00000003,0x6e656373,0x63655265,0x00000074,0x00050006,
0x0000003f,0x00000004,0x6974706f,0x00736e6f,0x00070006,0x0000003f,0x00000005,0x6e656373,
0x74704f65,0x736e6f69,0x00000000,0x00060006,0x0000003f,0x00000006,0x6e656373,0x61635365,
0x0000656c,0x00060006,0x0000003f,0x00000007,0x6e656373,0x61694265,0x00000073,0x00030005,
0x00000041,0x00000070,0x00040005,0x00000057,0x6e656373,0x00565565,0x00040005,0x00000072,
0x6e656373,0x00000065,0x00030005,0x0000007c,0x00796172,0x00040005,0x0000008e,0x61726170,
0x0000006d,0x00040005,0x00000091,0x61726170,0x0000006d,0x00030005,0x00000093,0x00767576,
0x00040005,0x000000ac,0x65646976,0x0000006f,0x00050005,0x000000c2,0x65646976,0x7869506f,
0x00006c65,0x00050005,0x000000c6,0x65646976,0x616d496f,0x00006567,0x00050005,0x000000cd,
0x65646976,0x6365526f,0x00000074,0x00040005,0x000000d2,0x65646976,0x0056556f,0x00040005,
0x000000e9,0x68706c61,0x00000061,0x00030005,0x000000f4,0x00626772,0x00050005,0x00000103,
0x6e656373,0x706c4165,0x00006168,0x00050005,0x0000010e,0x6e656373,0x42475265,0x00000000,
0x00060005,0x0000011d,0x6e656373,0x72745365,0x68676961,0x00000074,0x00040005,0x0000013f,
0x75736572,0x0000746c,0x00050005,0x00000151,0x7074756f,0x6f437475,0x00726f6c,0x00040047,
0x0000002c,0x00000022,0x00000000,0x00040047,0x0000002c,0x00000021,0x00000001,0x00040047,
0x0000003a,0x0000001e,0x00000000,0x00050048,0x0000003f,0x00000000,0x00000023,0x00000000,
0x00050048,0x0000003f,0x00000001,0x00000023,0x00000010,0x00050048,0x0000003f,0x00000002,
0x00000023,0x00000020,0x00050048,0x0000003f,0x00000003,0x00000023,0x00000030,0x00050048,
0x0000003f,0x00000004,0x00000023,0x00000040,0x00050048,0x0000003f,0x00000005,0x00000023,
0x00000050,0x00050048,0x0000003f,0x00000006,0x00000023,0x00000060,0x00050048,0x0000003f,
0x00000007,0x00000023,0x00000070,0x00030047,0x0000003f,0x00000002,0x00040047,0x000000c6,
0x00000022,0x00000000,0x00040047,0x000000c6,0x00000021,0x00000000,0x00040047,0x00000151,
0x0000001e,0x00000000,0x00020013,0x00000002,0x00030021,0x00000003,0x00000002,0x00030016,
0x00000006,0x00000020,0x00040017,0x00000007,0x00000006,0x00000004,0x00040020,0x00000008,
0x00000007,0x00000007,0x00040017,0x00000009,0x00000006,0x00000003,0x00040020,0x0000000a,
0x00000007,0x00000009,0x00050021,0x0000000b,0x00000009,0x00000008,0x0000000a,0x0004002b,
0x00000006,0x00000011,0x40000000,0x00040015,0x00000018,0x00000020,0x00000000,0x0004002b,
0x00000018,0x00000019,0x00000003,0x00040020,0x0000001a,0x00000007,0x00000006,0x00040017,
0x00000025,0x00000006,0x00000002,0x00040020,0x00000026,0x00000007,0x00000025,0x0004002b,
0x00000006,0x00000028,0x3f000000,0x00090019,0x00000029,0x00000006,0x00000001,0x00000000,
0x00000001,0x00000000,0x00000001,0x00000000,0x0003001b,0x0000002a,0x00000029,0x00040020,
0x0000002b,0x00000000,0x0000002a,0x0004003b,0x0000002b,0x0000002c,0x00000000,0x00040015,
0x0000002e,0x00000020,0x00000001,0x0004002b,0x0000002e,0x0000002f,0x00000000,0x00040017,
0x00000031,0x0000002e,0x00000003,0x00040017,0x00000033,0x0000002e,0x00000002,0x00040020,
0x00000039,0x00000001,0x00000025,0x0004003b,0x00000039,0x0000003a,0x00000001,0x0004002b,
0x00000018,0x0000003b,0x00000000,0x00040020,0x0000003c,0x00000001,0x00000006,0x000a001e,
0x0000003f,0x00000007,0x00000007,0x00000007,0x00000007,0x00000007,0x00000007,0x00000007,
0x00000007,0x00040020,0x00000040,0x00000009,0x0000003f,0x0004003b,0x00000040,0x00000041,
0x00000009,0x0004002b,0x0000002e,0x00000042,0x00000005,0x0004002b,0x00000018,0x00000043,
0x00000002,0x00040020,0x00000044,0x00000009,0x00000006,0x0004002b,0x00000006,0x00000047,
0x00000000,0x00020014,0x00000048,0x0004002b,0x00000006,0x0000004d,0x3f800000,0x0004002b,
0x00000018,0x0000004e,0x00000001,0x0004002b,0x0000002e,0x00000058,0x00000003,0x00040020,
0x00000059,0x00000009,0x00000007,0x0004002b,0x0000002e,0x00000075,0x00000004,0x0004002b,
0x0000002e,0x0000007d,0x00000001,0x0004002b,0x00000006,0x0000008c,0xbf800000,0x0004002b,
0x0000002e,0x0000009b,0x00000002,0x0007002c,0x00000007,0x000000ad,0x00000047,0x00000047,
0x00000047,0x00000047,0x0005002c,0x00000025,0x000000b4,0x00000047,0x00000047,0x00040017,
0x000000b5,0x00000048,0x00000002,0x0005002c,0x00000025,0x000000bc,0x0000004d,0x0000004d,
0x00090019,0x000000c3,0x00000006,0x00000001,0x00000000,0x00000000,0x00000000,0x00000001,
0x00000000,0x0003001b,0x000000c4,0x000000c3,0x00040020,0x000000c5,0x00000000,0x000000c4,
0x0004003b,0x000000c5,0x000000c6,0x00000000,0x0006002c,0x00000009,0x00000128,0x00000047,
0x00000047,0x00000047,0x0004002b,0x0000002e,0x00000130,0x00000006,0x0004002b,0x0000002e,
0x00000135,0x00000007,0x00040020,0x00000150,0x00000003,0x00000007,0x0004003b,0x00000150,
0x00000151,0x00000003,0x00050036,0x00000002,0x00000004,0x00000000,0x00000003,0x000200f8,
0x00000005,0x0004003b,0x00000026,0x00000027,0x00000007,0x0004003b,0x00000026,0x00000038,
0x00000007,0x0004003b,0x0000001a,0x0000004a,0x00000007,0x0004003b,0x00000026,0x00000057,
0x00000007,0x0004003b,0x00000008,0x00000072,0x00000007,0x0004003b,0x0000000a,0x0000007c,
0x00000007,0x0004003b,0x00000008,0x0000008e,0x00000007,0x0004003b,0x0000000a,0x00000091,
0x00000007,0x0004003b,0x00000026,0x00000093,0x00000007,0x0004003b,0x00000008,0x000000ac,
0x00000007,0x0004003b,0x00000026,0x000000c2,0x00000007,0x0004003b,0x00000008,0x000000cd,
0x00000007,0x0004003b,0x00000026,0x000000d2,0x00000007,0x0004003b,0x0000001a,0x000000e9,
0x00000007,0x0004003b,0x0000001a,0x000000ed,0x00000007,0x0004003b,0x0000000a,0x000000f4,
0x00000007,0x0004003b,0x0000000a,0x000000f8,0x00000007,0x0004003b,0x0000001a,0x00000103,
0x00000007,0x0004003b,0x0000001a,0x00000107,0x00000007,0x0004003b,0x0000000a,0x0000010e,
0x00000007,0x0004003b,0x0000000a,0x00000112,0x00000007,0x0004003b,0x00000008,0x0000011d,
0x00000007,0x0004003b,0x0000000a,0x00000120,0x00000007,0x0004003b,0x00000008,0x0000013f,
0x00000007,0x0004003d,0x0000002a,0x0000002d,0x0000002c,0x00040064,0x00000029,0x00000030,
0x0000002d,0x00050067,0x00000031,0x00000032,0x00000030,0x0000002f,0x0007004f,0x00000033,
0x00000034,0x00000032,0x00000032,0x00000000,0x00000001,0x0004006f,0x00000025,0x00000035,
0x00000034,0x00050050,0x00000025,0x00000036,0x00000028,0x00000028,0x00050088,0x00000025,
0x00000037,0x00000036,0x00000035,0x0003003e,0x00000027,0x00000037,0x00050041,0x0000003c,
0x0000003d,0x0000003a,0x0000003b,0x0004003d,0x00000006,0x0000003e,0x0000003d,0x00060041,
0x00000044,0x00000045,0x00000041,0x00000042,0x00000043,0x0004003d,0x00000006,0x00000046,
0x00000045,0x000500ba,0x00000048,0x00000049,0x00000046,0x00000047,0x000300f7,0x0000004c,
0x00000000,0x000400fa,0x00000049,0x0000004b,0x00000052,0x000200f8,0x0000004b,0x00050041,
0x0000003c,0x0000004f,0x0000003a,0x0000004e,0x0004003d,0x00000006,0x00000050,0x0000004f,
0x00050083,0x00000006,0x00000051,0x0000004d,0x00000050,0x0003003e,0x0000004a,0x00000051,
0x000200f9,0x0000004c,0x000200f8,0x00000052,0x00050041,0x0000003c,0x00000053,0x0000003a,
0x0000004e,0x0004003d,0x00000006,0x00000054,0x00000053,0x0003003e,0x0000004a,0x00000054,
0x000200f9,0x0000004c,0x000200f8,0x0000004c,0x0004003d,0x00000006,0x00000055,0x0000004a,
0x00050050,0x00000025,0x00000056,0x0000003e,0x00000055,0x0003003e,0x00000038,0x00000056,
0x00050041,0x00000059,0x0000005a,0x00000041,0x00000058,0x0004003d,0x00000007,0x0000005b,
0x0000005a,0x0007004f,0x00000025,0x0000005c,0x0000005b,0x0000005b,0x00000000,0x00000001,
0x0004003d,0x00000025,0x0000005d,0x00000038,0x00050041,0x00000059,0x0000005e,0x00000041,
0x00000058,0x0004003d,0x00000007,0x0000005f,0x0000005e,0x0007004f,0x00000025,0x00000060,
0x0000005f,0x0000005f,0x00000002,0x00000003,0x00050085,0x00000025,0x00000061,0x0000005d,
0x00000060,0x00050081,0x00000025,0x00000062,0x0000005c,0x00000061,0x00050041,0x00000059,
0x00000063,0x00000041,0x00000058,0x0004003d,0x00000007,0x00000064,0x00000063,0x0007004f,
0x00000025,0x00000065,0x00000064,0x00000064,0x00000000,0x00000001,0x0004003d,0x00000025,
0x00000066,0x00000027,0x00050081,0x00000025,0x00000067,0x00000065,0x00000066,0x00050041,
0x00000059,0x00000068,0x00000041,0x00000058,0x0004003d,0x00000007,0x00000069,0x00000068,
0x0007004f,0x00000025,0x0000006a,0x00000069,0x00000069,0x00000000,0x00000001,0x00050041,
0x00000059,0x0000006b,0x00000041,0x00000058,0x0004003d,0x00000007,0x0000006c,0x0000006b,
0x0007004f,0x00000025,0x0000006d,0x0000006c,0x0000006c,0x00000002,0x00000003,0x00050081,
0x00000025,0x0000006e,0x0000006a,0x0000006d,0x0004003d,0x00000025,0x0000006f,0x00000027,
0x00050083,0x00000025,0x00000070,0x0000006e,0x0000006f,0x0008000c,0x00000025,0x00000071,
0x00000001,0x0000002b,0x00000062,0x00000067,0x00000070,0x0003003e,0x00000057,0x00000071,
0x0004003d,0x0000002a,0x00000073,0x0000002c,0x0004003d,0x00000025,0x00000074,0x00000057,
0x00060041,0x00000044,0x00000076,0x00000041,0x00000075,0x0000004e,0x0004003d,0x00000006,
0x00000077,0x00000076,0x00050051,0x00000006,0x00000078,0x00000074,0x00000000,0x00050051,
0x00000006,0x00000079,0x00000074,0x00000001,0x00060050,0x00000009,0x0000007a,0x00000078,
0x00000079,0x00000077,0x00070058,0x00000007,0x0000007b,0x00000073,0x0000007a,0x00000002,
0x00000047,0x0003003e,0x00000072,0x0000007b,0x00060041,0x00000044,0x0000007e,0x00000041,
0x0000007d,0x0000003b,0x0004003d,0x00000006,0x0000007f,0x0000007e,0x00060041,0x00000044,
0x00000080,0x00000041,0x0000007d,0x0000004e,0x0004003d,0x00000006,0x00000081,0x00000080,
0x00050041,0x0000003c,0x00000082,0x0000003a,0x0000003b,0x0004003d,0x00000006,0x00000083,
0x00000082,0x0008000c,0x00000006,0x00000084,0x00000001,0x0000002e,0x0000007f,0x00000081,
0x00000083,0x00060041,0x00000044,0x00000085,0x00000041,0x0000007d,0x00000019,0x0004003d,
0x00000006,0x00000086,0x00000085,0x00060041,0x00000044,0x00000087,0x00000041,0x0000007d,
0x00000043,0x0004003d,0x00000006,0x00000088,0x00000087,0x00050041,0x0000003c,0x00000089,
0x0000003a,0x0000004e,0x0004003d,0x00000006,0x0000008a,0x00000089,0x0008000c,0x00000006,
0x0000008b,0x00000001,0x0000002e,0x00000086,0x00000088,0x0000008a,0x00060050,0x00000009,
0x0000008d,0x00000084,0x0000008b,0x0000008c,0x00050041,0x00000059,0x0000008f,0x00000041,
0x0000002f,0x0004003d,0x00000007,0x00000090,0x0000008f,0x0003003e,0x0000008e,0x00000090,
0x0003003e,0x00000091,0x0000008d,0x00060039,0x00000009,0x00000092,0x0000000e,0x0000008e,
0x00000091,0x0003003e,0x0000007c,0x00000092,0x0004003d,0x00000009,0x00000094,0x0000007c,
0x0007004f,0x00000025,0x00000095,0x00000094,0x00000094,0x00000000,0x00000001,0x00050041,
0x0000001a,0x00000096,0x0000007c,0x00000043,0x0004003d,0x00000006,0x00000097,0x00000096,
0x0004007f,0x00000006,0x00000098,0x00000097,0x00050050,0x00000025,0x00000099,0x00000098,
0x00000098,0x00050088,0x00000025,0x0000009a,0x00000095,0x00000099,0x00050041,0x00000059,
0x0000009c,0x00000041,0x0000009b,0x0004003d,0x00000007,0x0000009d,0x0000009c,0x0007004f,
0x00000025,0x0000009e,0x0000009d,0x0000009d,0x00000000,0x00000002,0x00050083,0x00000025,
0x0000009f,0x0000009a,0x0000009e,0x00050041,0x00000059,0x000000a0,0x00000041,0x0000009b,
0x0004003d,0x00000007,0x000000a1,0x000000a0,0x0007004f,0x00000025,0x000000a2,0x000000a1,
0x000000a1,0x00000001,0x00000003,0x00050041,0x00000059,0x000000a3,0x00000041,0x0000009b,
0x0004003d,0x00000007,0x000000a4,0x000000a3,0x0007004f,0x00000025,0x000000a5,0x000000a4,
0x000000a4,0x00000000,0x00000002,0x00050083,0x00000025,0x000000a6,0x000000a2,0x000000a5,
0x00050088,0x00000025,0x000000a7,0x0000009f,0x000000a6,0x0003003e,0x00000093,0x000000a7,
0x00050041,0x0000001a,0x000000a8,0x00000093,0x0000004e,0x0004003d,0x00000006,0x000000a9,
0x000000a8,0x00050083,0x00000006,0x000000aa,0x0000004d,0x000000a9,0x00050041,0x0000001a,
0x000000ab,0x00000093,0x0000004e,0x0003003e,0x000000ab,0x000000aa,0x0003003e,0x000000ac,
0x000000ad,0x00050041,0x0000001a,0x000000ae,0x0000007c,0x00000043,0x0004003d,0x00000006,
0x000000af,0x000000ae,0x000500b8,0x00000048,0x000000b0,0x000000af,0x00000047,0x000300f7,
0x000000b2,0x00000000,0x000400fa,0x000000b0,0x000000b1,0x000000b2,0x000200f8,0x000000b1,
0x0004003d,0x00000025,0x000000b3,0x00000093,0x000500be,0x000000b5,0x000000b6,0x000000b3,
0x000000b4,0x0004009b,0x00000048,0x000000b7,0x000000b6,0x000200f9,0x000000b2,0x000200f8,
0x000000b2,0x000700f5,0x00000048,0x000000b8,0x000000b0,0x0000004c,0x000000b7,0x000000b1,
0x000300f7,0x000000ba,0x00000000,0x000400fa,0x000000b8,0x000000b9,0x000000ba,0x000200f8,
0x000000b9,0x0004003d,0x00000025,0x000000bb,0x00000093,0x000500bc,0x000000b5,0x000000bd,
0x000000bb,0x000000bc,0x0004009b,0x00000048,0x000000be,0x000000bd,0x000200f9,0x000000ba,
0x000200f8,0x000000ba,0x000700f5,0x00000048,0x000000bf,0x000000b8,0x000000b2,0x000000be,
0x000000b9,0x000300f7,0x000000c1,0x00000000,0x000400fa,0x000000bf,0x000000c0,0x000000c1,
0x000200f8,0x000000c0,0x0004003d,0x000000c4,0x000000c7,0x000000c6,0x00040064,0x000000c3,
0x000000c8,0x000000c7,0x00050067,0x00000033,0x000000c9,0x000000c8,0x0000002f,0x0004006f,
0x00000025,0x000000ca,0x000000c9,0x00050050,0x00000025,0x000000cb,0x00000028,0x00000028,
0x00050088,0x00000025,0x000000cc,0x000000cb,0x000000ca,0x0003003e,0x000000c2,0x000000cc,
0x00060041,0x00000044,0x000000ce,0x00000041,0x00000075,0x0000003b,0x0004003d,0x00000006,
0x000000cf,0x000000ce,0x00050085,0x00000006,0x000000d0,0x000000cf,0x00000028,0x00070050,
0x00000007,0x000000d1,0x000000d0,0x00000047,0x00000028,0x0000004d,0x0003003e,0x000000cd,
0x000000d1,0x0004003d,0x00000007,0x000000d3,0x000000cd,0x0007004f,0x00000025,0x000000d4,
0x000000d3,0x000000d3,0x00000000,0x00000001,0x0004003d,0x00000025,0x000000d5,0x00000093,
0x0004003d,0x00000007,0x000000d6,0x000000cd,0x0007004f,0x00000025,0x000000d7,0x000000d6,
0x000000d6,0x00000002,0x00000003,0x00050085,0x00000025,0x000000d8,0x000000d5,0x000000d7,
0x00050081,0x00000025,0x000000d9,0x000000d4,0x000000d8,0x0004003d,0x00000007,0x000000da,
0x000000cd,0x0007004f,0x00000025,0x000000db,0x000000da,0x000000da,0x00000000,0x00000001,
0x0004003d,0x00000025,0x000000dc,0x000000c2,0x00050081,0x00000025,0x000000dd,0x000000db,
0x000000dc,0x0004003d,0x00000007,0x000000de,0x000000cd,0x0007004f,0x00000025,0x000000df,
0x000000de,0x000000de,0x00000000,0x00000001,0x0004003d,0x00000007,0x000000e0,0x000000cd,
0x0007004f,0x00000025,0x000000e1,0x000000e0,0x000000e0,0x00000002,0x00000003,0x00050081,
0x00000025,0x000000e2,0x000000df,0x000000e1,0x0004003d,0x00000025,0x000000e3,0x000000c2,
0x00050083,0x00000025,0x000000e4,0x000000e2,0x000000e3,0x0008000c,0x00000025,0x000000e5,
0x00000001,0x0000002b,0x000000d9,0x000000dd,0x000000e4,0x0003003e,0x000000d2,0x000000e5,
0x0004003d,0x000000c4,0x000000e6,0x000000c6,0x0004003d,0x00000025,0x000000e7,0x000000d2,
0x00070058,0x00000007,0x000000e8,0x000000e6,0x000000e7,0x00000002,0x00000047,0x0003003e,
0x000000ac,0x000000e8,0x000200f9,0x000000c1,0x000200f8,0x000000c1,0x00060041,0x00000044,
0x000000ea,0x00000041,0x00000075,0x00000043,0x0004003d,0x00000006,0x000000eb,0x000000ea,
0x000500ba,0x00000048,0x000000ec,0x000000eb,0x00000047,0x000300f7,0x000000ef,0x00000000,
0x000400fa,0x000000ec,0x000000ee,0x000000f2,0x000200f8,0x000000ee,0x00050041,0x0000001a,
0x000000f0,0x000000ac,0x00000019,0x0004003d,0x00000006,0x000000f1,0x000000f0,0x0003003e,
0x000000ed,0x000000f1,0x000200f9,0x000000ef,0x000200f8,0x000000f2,0x0003003e,0x000000ed,
0x0000004d,0x000200f9,0x000000ef,0x000200f8,0x000000ef,0x0004003d,0x00000006,0x000000f3,
0x000000ed,0x0003003e,0x000000e9,0x000000f3,0x00060041,0x00000044,0x000000f5,0x00000041,
0x00000075,0x00000019,0x0004003d,0x00000006,0x000000f6,0x000000f5,0x000500ba,0x00000048,
0x000000f7,0x000000f6,0x00000047,0x000300f7,0x000000fa,0x00000000,0x000400fa,0x000000f7,
0x000000f9,0x000000ff,0x000200f8,0x000000f9,0x0004003d,0x00000007,0x000000fb,0x000000ac,
0x0008004f,0x00000009,0x000000fc,0x000000fb,0x000000fb,0x00000000,0x00000001,0x00000002,
0x0004003d,0x00000006,0x000000fd,0x000000e9,0x0005008e,0x00000009,0x000000fe,0x000000fc,
0x000000fd,0x0003003e,0x000000f8,0x000000fe,0x000200f9,0x000000fa,0x000200f8,0x000000ff,
0x0004003d,0x00000007,0x00000100,0x000000ac,0x0008004f,0x00000009,0x00000101,0x00000100,
0x00000100,0x00000000,0x00000001,0x00000002,0x0003003e,0x000000f8,0x00000101,0x000200f9,
0x000000fa,0x000200f8,0x000000fa,0x0004003d,0x00000009,0x00000102,0x000000f8,0x0003003e,
0x000000f4,0x00000102,0x00060041,0x00000044,0x00000104,0x00000041,0x00000042,0x0000003b,
0x0004003d,0x00000006,0x00000105,0x00000104,0x000500ba,0x00000048,0x00000106,0x00000105,
0x00000047,0x000300f7,0x00000109,0x00000000,0x000400fa,0x00000106,0x00000108,0x0000010c,
0x000200f8,0x00000108,0x00050041,0x0000001a,0x0000010a,0x00000072,0x00000019,0x0004003d,
0x00000006,0x0000010b,0x0000010a,0x0003003e,0x00000107,0x0000010b,0x000200f9,0x00000109,
0x000200f8,0x0000010c,0x0003003e,0x00000107,0x0000004d,0x000200f9,0x00000109,0x000200f8,
0x00000109,0x0004003d,0x00000006,0x0000010d,0x00000107,0x0003003e,0x00000103,0x0000010d,
0x00060041,0x00000044,0x0000010f,0x00000041,0x00000042,0x0000004e,0x0004003d,0x00000006,
0x00000110,0x0000010f,0x000500ba,0x00000048,0x00000111,0x00000110,0x00000047,0x000300f7,
0x00000114,0x00000000,0x000400fa,0x00000111,0x00000113,0x00000119,0x000200f8,0x00000113,
0x0004003d,0x00000007,0x00000115,0x00000072,0x0008004f,0x00000009,0x00000116,0x00000115,
0x00000115,0x00000000,0x00000001,0x00000002,0x0004003d,0x00000006,0x00000117,0x00000103,
0x0005008e,0x00000009,0x00000118,0x00000116,0x00000117,0x0003003e,0x00000112,0x00000118,
0x000200f9,0x00000114,0x000200f8,0x00000119,0x0004003d,0x00000007,0x0000011a,0x00000072,
0x0008004f,0x00000009,0x0000011b,0x0000011a,0x0000011a,0x00000000,0x00000001,0x00000002,
0x0003003e,0x00000112,0x0000011b,0x000200f9,0x00000114,0x000200f8,0x00000114,0x0004003d,
0x00000009,0x0000011c,0x00000112,0x0003003e,0x0000010e,0x0000011c,0x0004003d,0x00000006,
0x0000011e,0x00000103,0x000500ba,0x00000048,0x0000011f,0x0000011e,0x00000047,0x000300f7,
0x00000122,0x00000000,0x000400fa,0x0000011f,0x00000121,0x00000127,0x000200f8,0x00000121,
0x0004003d,0x00000009,0x00000123,0x0000010e,0x0004003d,0x00000006,0x00000124,0x00000103,
0x00060050,0x00000009,0x00000125,0x00000124,0x00000124,0x00000124,0x00050088,0x00000009,
0x00000126,0x00000123,0x00000125,0x0003003e,0x00000120,0x00000126,0x000200f9,0x00000122,
0x000200f8,0x00000127,0x0003003e,0x00000120,0x00000128,0x000200f9,0x00000122,0x000200f8,
0x00000122,0x0004003d,0x00000009,0x00000129,0x00000120,0x0004003d,0x00000006,0x0000012a,
0x00000103,0x00050051,0x00000006,0x0000012b,0x00000129,0x00000000,0x00050051,0x00000006,
0x0000012c,0x00000129,0x00000001,0x00050051,0x00000006,0x0000012d,0x00000129,0x00000002,
0x00070050,0x00000007,0x0000012e,0x0000012b,0x0000012c,0x0000012d,0x0000012a,0x0003003e,
0x0000011d,0x0000012e,0x0004003d,0x00000007,0x0000012f,0x0000011d,0x00050041,0x00000059,
0x00000131,0x00000041,0x00000130,0x0004003d,0x00000007,0x00000132,0x00000131,0x0007000c,
0x00000007,0x00000133,0x00000001,0x00000028,0x00000132,0x000000ad,0x00050085,0x00000007,
0x00000134,0x0000012f,0x00000133,0x00050041,0x00000059,0x00000136,0x00000041,0x00000135,
0x0004003d,0x00000007,0x00000137,0x00000136,0x00050081,0x00000007,0x00000138,0x00000134,
0x00000137,0x0003003e,0x0000011d,0x00000138,0x00050041,0x0000001a,0x00000139,0x0000011d,
0x00000019,0x0004003d,0x00000006,0x0000013a,0x00000139,0x0003003e,0x00000103,0x0000013a,
0x0004003d,0x00000007,0x0000013b,0x0000011d,0x0008004f,0x00000009,0x0000013c,0x0000013b,
0x0000013b,0x00000000,0x00000001,0x00000002,0x0004003d,0x00000006,0x0000013d,0x00000103,
0x0005008e,0x00000009,0x0000013e,0x0000013c,0x0000013d,0x0003003e,0x0000010e,0x0000013e,
0x0004003d,0x00000009,0x00000140,0x000000f4,0x0004003d,0x00000009,0x00000141,0x0000010e,
0x0004003d,0x00000006,0x00000142,0x000000e9,0x00050083,0x00000006,0x00000143,0x0000004d,
0x00000142,0x0005008e,0x00000009,0x00000144,0x00000141,0x00000143,0x00050081,0x00000009,
0x00000145,0x00000140,0x00000144,0x0004003d,0x00000006,0x00000146,0x000000e9,0x0004003d,
0x00000006,0x00000147,0x00000103,0x0004003d,0x00000006,0x00000148,0x000000e9,0x00050083,
0x00000006,0x00000149,0x0000004d,0x00000148,0x00050085,0x00000006,0x0000014a,0x00000147,
0x00000149,0x00050081,0x00000006,0x0000014b,0x00000146,0x0000014a,0x00050051,0x00000006,
0x0000014c,0x00000145,0x00000000,0x00050051,0x00000006,0x0000014d,0x00000145,0x00000001,
0x00050051,0x00000006,0x0000014e,0x00000145,0x00000002,0x00070050,0x00000007,0x0000014f,
0x0000014c,0x0000014d,0x0000014e,0x0000014b,0x0003003e,0x0000013f,0x0000014f,0x0004003d,
0x00000007,0x00000152,0x0000013f,0x0003003e,0x00000151,0x00000152,0x000100fd,0x00010038,
0x00050036,0x00000009,0x0000000e,0x00000000,0x0000000b,0x00030037,0x00000008,0x0000000c,
0x00030037,0x0000000a,0x0000000d,0x000200f8,0x0000000f,0x0004003d,0x00000009,0x00000010,
0x0000000d,0x0004003d,0x00000007,0x00000012,0x0000000c,0x0008004f,0x00000009,0x00000013,
0x00000012,0x00000012,0x00000000,0x00000001,0x00000002,0x0004003d,0x00000007,0x00000014,
0x0000000c,0x0008004f,0x00000009,0x00000015,0x00000014,0x00000014,0x00000000,0x00000001,
0x00000002,0x0004003d,0x00000009,0x00000016,0x0000000d,0x0007000c,0x00000009,0x00000017,
0x00000001,0x00000044,0x00000015,0x00000016,0x00050041,0x0000001a,0x0000001b,0x0000000c,
0x00000019,0x0004003d,0x00000006,0x0000001c,0x0000001b,0x0004003d,0x00000009,0x0000001d,
0x0000000d,0x0005008e,0x00000009,0x0000001e,0x0000001d,0x0000001c,0x00050081,0x00000009,
0x0000001f,0x00000017,0x0000001e,0x0007000c,0x00000009,0x00000020,0x00000001,0x00000044,
0x00000013,0x0000001f,0x0005008e,0x00000009,0x00000021,0x00000020,0x00000011,0x00050081,
0x00000009,0x00000022,0x00000010,0x00000021,0x000200fe,0x00000022,0x00010038,
};
+331
View File
@@ -0,0 +1,331 @@
// SPDX-License-Identifier: GPL-3.0-only
// Decoder -> AImageReader -> fused GLES YUV conversion/projection -> shared RGBA
// eye views -> Vulkan copy to the runtime. The original decoded image is not
// downscaled or converted into a full-size intermediate. No picture readback or
// CPU colour conversion; no YCbCr feature forced onto the application's device.
// Published buffers are retained until the Vulkan fence completes. The full
// panorama import path remains available to the independent reference fixture.
static struct {
media_status_t (*reader_new)(int32_t,int32_t,int32_t,uint64_t,int32_t,AImageReader**);
media_status_t (*reader_window)(AImageReader*,ANativeWindow**);
media_status_t (*reader_latest)(AImageReader*,AImage**);
media_status_t (*reader_next)(AImageReader*,AImage**);
media_status_t (*image_time)(const AImage*,int64_t*);
void (*reader_delete)(AImageReader*);
media_status_t (*image_buffer)(const AImage*,AHardwareBuffer**);
void (*image_delete)(AImage*);
int (*allocate)(const AHardwareBuffer_Desc*,AHardwareBuffer**);
void (*describe)(const AHardwareBuffer*,AHardwareBuffer_Desc*);
void (*release)(AHardwareBuffer*);
jobject (*to_surface)(JNIEnv*,ANativeWindow*);
PFNEGLGETNATIVECLIENTBUFFERANDROIDPROC client;
PFNEGLCREATEIMAGEKHRPROC create;
PFNEGLDESTROYIMAGEKHRPROC destroy;
PFNGLEGLIMAGETARGETTEXTURE2DOESPROC bind;
void (*finish)(void);
PFN_vkGetAndroidHardwareBufferPropertiesANDROID properties;
PFN_vkCreateImage create_image;
PFN_vkDestroyImage destroy_image;
PFN_vkAllocateMemory allocate_memory;
PFN_vkFreeMemory free_memory;
PFN_vkBindImageMemory bind_memory;
PFN_vkCreateImageView create_view;
PFN_vkDestroyImageView destroy_view;
} sn;
static int surf_native_load(void) {
if(!vk.GetDeviceProcAddr)return 0;
sn.properties=(PFN_vkGetAndroidHardwareBufferPropertiesANDROID)vk.GetDeviceProcAddr(vk.device,
"vkGetAndroidHardwareBufferPropertiesANDROID");
if(!sn.properties){LOG("surface_native: external-memory device extension unavailable");return 0;}
void *media=dlopen("libmediandk.so",RTLD_NOW|RTLD_LOCAL);
void *window=dlopen("libnativewindow.so",RTLD_NOW|RTLD_LOCAL);
void *gles=dlopen("libGLESv3.so",RTLD_NOW|RTLD_LOCAL);
if(!media || !window || !gles){LOG("surface_native: missing platform library: %s",dlerror());return 0;}
#define SN_SYM(field,lib,name) *(void**)&sn.field=dlsym(lib,name);if(!sn.field){LOG("surface_native: missing %s",name);return 0;}
SN_SYM(reader_new,media,"AImageReader_newWithUsage")
SN_SYM(reader_window,media,"AImageReader_getWindow")
SN_SYM(reader_latest,media,"AImageReader_acquireLatestImage")
SN_SYM(reader_next,media,"AImageReader_acquireNextImage")
SN_SYM(image_time,media,"AImage_getTimestamp")
SN_SYM(reader_delete,media,"AImageReader_delete")
SN_SYM(image_buffer,media,"AImage_getHardwareBuffer") SN_SYM(image_delete,media,"AImage_delete")
SN_SYM(allocate,window,"AHardwareBuffer_allocate") SN_SYM(describe,window,"AHardwareBuffer_describe")
SN_SYM(release,window,"AHardwareBuffer_release")
#ifndef SURF_NATIVE_ALLOCATOR_TEST
// A native GPU fixture has no Java VM; only the application needs this bridge.
void *android=dlopen("libandroid.so",RTLD_NOW|RTLD_LOCAL);
if(!android)return 0;
SN_SYM(to_surface,android,"ANativeWindow_toSurface")
#endif
SN_SYM(finish,gles,"glFinish")
#undef SN_SYM
#define SN_VK(field,name) sn.field=(PFN_vk##name)vk.GetDeviceProcAddr(vk.device,"vk" #name);if(!sn.field)return 0;
SN_VK(create_image,CreateImage) SN_VK(destroy_image,DestroyImage) SN_VK(allocate_memory,AllocateMemory)
SN_VK(free_memory,FreeMemory) SN_VK(bind_memory,BindImageMemory)
SN_VK(create_view,CreateImageView) SN_VK(destroy_view,DestroyImageView)
#undef SN_VK
void *egl=dlopen("libEGL.so",RTLD_NOW|RTLD_LOCAL);
__eglMustCastToProperFunctionPointerType (*get)(const char*)=egl?
(__eglMustCastToProperFunctionPointerType (*)(const char*))dlsym(egl,"eglGetProcAddress"):NULL;
if(!get)return 0;
sn.client=(PFNEGLGETNATIVECLIENTBUFFERANDROIDPROC)get("eglGetNativeClientBufferANDROID");
sn.create=(PFNEGLCREATEIMAGEKHRPROC)get("eglCreateImageKHR");
sn.destroy=(PFNEGLDESTROYIMAGEKHRPROC)get("eglDestroyImageKHR");
sn.bind=(PFNGLEGLIMAGETARGETTEXTURE2DOESPROC)get("glEGLImageTargetTexture2DOES");
return sn.client && sn.create && sn.destroy && sn.bind;
}
static void surf_native_slot_destroy(surf_native_slot *slot) {
if(slot->view)sn.destroy_view(vk.device,slot->view,NULL);
if(slot->image)sn.destroy_image(vk.device,slot->image,NULL);
if(slot->memory)sn.free_memory(vk.device,slot->memory,NULL);
if(slot->buffer)sn.release(slot->buffer);
slot->view=VK_NULL_HANDLE;slot->image=VK_NULL_HANDLE;slot->memory=VK_NULL_HANDLE;slot->buffer=NULL;
}
static int surf_native_allocate(surf_native_slot *slot,EGLDisplay display,uint32_t width,uint32_t height) {
AHardwareBuffer_Desc desc={.width=width,.height=height,.layers=1,
.format=AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM,
.usage=AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE|AHARDWAREBUFFER_USAGE_GPU_COLOR_OUTPUT};
if(sn.allocate(&desc,&slot->buffer))return 0;
VkAndroidHardwareBufferFormatPropertiesANDROID format={VK_STRUCTURE_TYPE_ANDROID_HARDWARE_BUFFER_FORMAT_PROPERTIES_ANDROID};
VkAndroidHardwareBufferPropertiesANDROID props={VK_STRUCTURE_TYPE_ANDROID_HARDWARE_BUFFER_PROPERTIES_ANDROID,&format};
if(sn.properties(vk.device,slot->buffer,&props)!=VK_SUCCESS || format.format!=VK_FORMAT_R8G8B8A8_UNORM)goto fail;
VkExternalMemoryImageCreateInfo external={VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_IMAGE_CREATE_INFO,NULL,
VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID};
VkImageCreateInfo image={VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,&external,0,VK_IMAGE_TYPE_2D,format.format,
{width,height,1},1,1,VK_SAMPLE_COUNT_1_BIT,VK_IMAGE_TILING_OPTIMAL,
VK_IMAGE_USAGE_SAMPLED_BIT|VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT|VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
VK_SHARING_MODE_EXCLUSIVE,0,NULL,VK_IMAGE_LAYOUT_UNDEFINED};
if(sn.create_image(vk.device,&image,NULL,&slot->image)!=VK_SUCCESS)goto fail;
uint32_t type=0;while(type<32 && !(props.memoryTypeBits&(1u<<type)))type++;
if(type==32)goto fail;
VkImportAndroidHardwareBufferInfoANDROID imported={VK_STRUCTURE_TYPE_IMPORT_ANDROID_HARDWARE_BUFFER_INFO_ANDROID,NULL,slot->buffer};
VkMemoryDedicatedAllocateInfo dedicated={VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO,&imported,slot->image,VK_NULL_HANDLE};
VkMemoryAllocateInfo alloc={VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,&dedicated,props.allocationSize,type};
if(sn.allocate_memory(vk.device,&alloc,NULL,&slot->memory)!=VK_SUCCESS ||
sn.bind_memory(vk.device,slot->image,slot->memory,0)!=VK_SUCCESS)goto fail;
VkImageViewCreateInfo view={VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,NULL,0,slot->image,VK_IMAGE_VIEW_TYPE_2D,
format.format,{0,0,0,0},{VK_IMAGE_ASPECT_COLOR_BIT,0,1,0,1}};
if(sn.create_view(vk.device,&view,NULL,&slot->view)!=VK_SUCCESS)goto fail;
slot->egl_image=sn.create(display,EGL_NO_CONTEXT,EGL_NATIVE_BUFFER_ANDROID,sn.client(slot->buffer),NULL);
if(slot->egl_image==EGL_NO_IMAGE_KHR)goto fail;
p_glGenTextures(1,&slot->texture);p_glBindTexture(GL_TEXTURE_2D,slot->texture);
sn.bind(GL_TEXTURE_2D,slot->egl_image);
slot->width=width;slot->height=height;
return p_glGetError()==GL_NO_ERROR;
fail:
surf_native_slot_destroy(slot);return 0;
}
// Runs on the surface worker's EGL context. The pose snapshot is published
// together with the completed image, so the compositor can timewarp correctly.
static void surf_video_draw(GLuint program,const GLint uniforms[8],GLuint external,
const surf_video_job *job) {
p_glUseProgram(program);p_glActiveTexture(GL_TEXTURE0);p_glBindTexture(GL_TEXTURE_EXTERNAL_OES,external);
for(int eye=0;eye<2;eye++){
p_glViewport((GLint)(eye*job->size),0,(GLsizei)job->size,(GLsizei)job->size);
for(int i=0;i<8;i++){
const float *v=job->params[eye]+4*i;
p_glUniform4f(uniforms[i],v[0],v[1],v[2],v[3]);
}
p_glDrawArrays(GL_TRIANGLES,0,3);
}
}
#if !defined(SURF_NATIVE_ALLOCATOR_TEST) || defined(SURF_NATIVE_WORKER_TEST)
static void surf_native_worker(surf_swapchain *s,JNIEnv *env,EGLDisplay display) {
AImageReader *reader=NULL;ANativeWindow *window=NULL;
GLuint program=0,external=0,fbo=0,vao=0;
enum {PENDING_IMAGES=4,ACQUIRED_IMAGES=5};
AImage *held=NULL,*pending[PENDING_IMAGES]={0};int64_t pending_time[PENDING_IMAGES]={0};int pending_count=0;
EGLImageKHR input=EGL_NO_IMAGE_KHR;
AHardwareBuffer_Desc desc={0};uint64_t last_job=0;GLint uniforms[8]={0};
int64_t source_time=0;
surf_video_job rendered_job={0};int video_dirty=0;
#ifdef SURF_NATIVE_WORKER_TEST
// A native fixture supplies the real reader/codec without a Java VM.
(void)env;reader=surf_worker_test_reader;
#else
if(sn.reader_new((int32_t)s->width,(int32_t)s->height,AIMAGE_FORMAT_PRIVATE,
AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE,s->native_project?ACQUIRED_IMAGES:3,&reader)!=AMEDIA_OK ||
sn.reader_window(reader,&window)!=AMEDIA_OK)goto fail;
jobject local=sn.to_surface(env,window);
if(!local || (*env)->ExceptionCheck(env)){(*env)->ExceptionClear(env);goto fail;}
s->surface=(*env)->NewGlobalRef(env,local);(*env)->DeleteLocalRef(env,local);
if(!s->surface)goto fail;
#endif
const char *fragment="#version 300 es\n#extension GL_OES_EGL_image_external_essl3 : require\n"
"precision highp float;uniform samplerExternalOES tex;in vec2 uv;out vec4 color;"
"void main(){color=texture(tex,uv);}";
GLuint vertex=emul_compile(GL_VERTEX_SHADER,"",surf_vs),pixel=emul_compile(GL_FRAGMENT_SHADER,"",
s->native_project?surf_video_fragment:fragment);
if(!vertex || !pixel)goto fail;
program=p_glCreateProgram();p_glAttachShader(program,vertex);p_glAttachShader(program,pixel);p_glLinkProgram(program);
GLint ok=0;p_glGetProgramiv(program,GL_LINK_STATUS,&ok);if(!ok)goto fail;
if(s->native_project)for(int i=0;i<8;i++)uniforms[i]=p_glGetUniformLocation(program,surf_video_uniforms[i]);
p_glGenTextures(1,&external);p_glBindTexture(GL_TEXTURE_EXTERNAL_OES,external);
s_glTexParameteri(GL_TEXTURE_EXTERNAL_OES,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
s_glTexParameteri(GL_TEXTURE_EXTERNAL_OES,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
s_glTexParameteri(GL_TEXTURE_EXTERNAL_OES,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE);
s_glTexParameteri(GL_TEXTURE_EXTERNAL_OES,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE);
p_glGenFramebuffers(1,&fbo);p_glGenVertexArrays(1,&vao);
pthread_mutex_lock(&surf_lock);s->ready=1;pthread_cond_broadcast(&surf_cond);pthread_mutex_unlock(&surf_lock);
LOG("surface_native: shared GPU video surface ready (%s)",s->native_project?"fused visible-view conversion":"full panorama");
int64_t start=0,frames=0,views=0,draw_ns=0,reused=0,held_views=0,anchored_views=0,recentred_views=0;
while(!s->stop){
int index=-1;
surf_video_job job;
pthread_mutex_lock(&surf_lock);
if(s->video_job.seq==last_job && !s->stop){
struct timespec until;clock_gettime(CLOCK_REALTIME,&until);until.tv_nsec+=1000000;
if(until.tv_nsec>=1000000000){until.tv_sec++;until.tv_nsec-=1000000000;}
pthread_cond_timedwait(&surf_cond,&surf_lock,&until);
}
job=s->video_job;
for(int i=0;i<SURF_NATIVE_SLOTS;i++)if(s->native_slots[i].state==0){index=i;s->native_slots[i].state=1;break;}
pthread_mutex_unlock(&surf_lock);
if(index<0){struct timespec pause={0,250000};nanosleep(&pause,NULL);continue;}
surf_native_slot *slot=&s->native_slots[index];
AImage *image=NULL;
if(s->native_project){
// Acquire future pictures promptly: leaving them in a droppable
// producer queue loses pictures before their presentation time.
// Keep at most four future pictures plus the currently sampled one.
int64_t now=monotonic_ns(),target=surf_video_target(now,job.time);
while(pending_count && !surf_video_future(pending_time[0],now,target)){
if(image)sn.image_delete(image);
image=pending[0];pending_count--;
memmove(pending,pending+1,pending_count*sizeof(*pending));
memmove(pending_time,pending_time+1,pending_count*sizeof(*pending_time));
}
while(pending_count<PENDING_IMAGES && pending_count+(held!=NULL)+(image!=NULL)<ACQUIRED_IMAGES){
AImage *next=NULL;if(sn.reader_next(reader,&next)!=AMEDIA_OK)break;
int64_t timestamp=0;sn.image_time(next,&timestamp);
if(surf_video_future(timestamp,now,target)){
pending[pending_count]=next;pending_time[pending_count++]=timestamp;
}else{
if(image)sn.image_delete(image);image=next;
}
}
}else sn.reader_latest(reader,&image);
int new_image=image!=NULL;
if(new_image){
// Keep the decoder image acquired while GLES might sample it again
// for head movement. Releasing it sooner lets the decoder overwrite it.
if(input!=EGL_NO_IMAGE_KHR)sn.destroy(display,input);
if(held)sn.image_delete(held);
held=image;input=EGL_NO_IMAGE_KHR;
sn.image_time(held,&source_time);
AHardwareBuffer *buffer=NULL;
int valid=sn.image_buffer(held,&buffer)==AMEDIA_OK;
if(valid)sn.describe(buffer,&desc);
if(!valid || !desc.width || !desc.height || desc.width>8192 || desc.height>8192)goto fail;
input=sn.create(display,EGL_NO_CONTEXT,EGL_NATIVE_BUFFER_ANDROID,sn.client(buffer),NULL);
if(input==EGL_NO_IMAGE_KHR)goto fail;
p_glActiveTexture(GL_TEXTURE0);p_glBindTexture(GL_TEXTURE_EXTERNAL_OES,external);sn.bind(GL_TEXTURE_EXTERNAL_OES,input);
frames++;video_dirty=1;
}
// Importing/acquiring a decoder buffer can take time. Pick the newest
// request immediately before drawing instead of keeping the earlier pose.
pthread_mutex_lock(&surf_lock);job=s->video_job;pthread_mutex_unlock(&surf_lock);
// Coalesce video arrivals into the next application view request. Drawing
// on both clocks would do up to video-fps + headset-fps work per second.
if(!held || (s->native_project?(!job.size || job.seq==last_job):!new_image)){
pthread_mutex_lock(&surf_lock);slot->state=0;pthread_mutex_unlock(&surf_lock);continue;
}
if(s->native_project && !video_dirty && surf_video_covers(&rendered_job,&job)){
last_job=job.seq;reused++;
pthread_mutex_lock(&surf_lock);slot->state=0;pthread_mutex_unlock(&surf_lock);continue;
}
uint32_t width=s->native_project?2*job.size:desc.width,height=s->native_project?job.size:desc.height;
if(!slot->buffer || slot->width!=width || slot->height!=height){
if(slot->texture)p_glDeleteTextures(1,&slot->texture);
if(slot->egl_image)sn.destroy(display,slot->egl_image);
slot->texture=0;slot->egl_image=EGL_NO_IMAGE_KHR;surf_native_slot_destroy(slot);
if(!surf_native_allocate(slot,display,width,height))goto fail;
LOG("surface_native: %ux%u decoded input -> %ux%u shared view",desc.width,desc.height,width,height);
}
p_glBindFramebuffer(GL_FRAMEBUFFER,fbo);
p_glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D,slot->texture,0);
if(p_glCheckFramebufferStatus(GL_FRAMEBUFFER)!=GL_FRAMEBUFFER_COMPLETE)goto fail;
p_glUseProgram(program);p_glUniform1i(p_glGetUniformLocation(program,"tex"),0);p_glBindVertexArray(vao);
int64_t draw_start=monotonic_ns();
surf_video_job draw=job;
if(s->native_project){
if(surf_video_anchor(&rendered_job,&job,&draw))anchored_views++;
else recentred_views++;
surf_video_draw(program,uniforms,external,&draw);
}
else {p_glViewport(0,0,(GLsizei)width,(GLsizei)height);p_glDrawArrays(GL_TRIANGLES,0,3);}
sn.finish(); // external writes completed before the Vulkan ownership acquire
if(!video_dirty)held_views++;
draw_ns+=monotonic_ns()-draw_start;views++;last_job=job.seq;rendered_job=draw;video_dirty=0;
GLenum error=p_glGetError();
if(error)goto fail;
pthread_mutex_lock(&surf_lock);
for(int i=0;i<SURF_NATIVE_SLOTS;i++)if(s->native_slots[i].state==2)s->native_slots[i].state=0;
slot->video=draw;slot->projected=s->native_project;slot->source_width=desc.width;slot->source_height=desc.height;
slot->source_time=source_time;
slot->seq=++s->seq;slot->state=2;s->frames++;
pthread_mutex_unlock(&surf_lock);
int64_t now=monotonic_ns();if(!start)start=now;
if(now-start>5000000000ll){LOG("surface_native: %.1f video frames/s, %.1f views/s, visible-view GPU wait %.2f ms, no picture readback",
frames*1e9/(now-start),views*1e9/(now-start),views?draw_ns/1e6/views:0);
if(s->native_project)LOG("surface_native: held-picture redraws=%lld, compositor reuse=%lld, panorama radius=%.3f",
(long long)held_views,(long long)reused,job.params[0][7]);
if(s->native_project)LOG("surface_native: fixed sampling grid=%lld views, recentered=%lld views",
(long long)anchored_views,(long long)recentred_views);
frames=views=draw_ns=reused=held_views=anchored_views=recentred_views=0;start=now;}
}
goto done;
fail:
surf_fail(s,"shared GPU video initialization/delivery failed");
done:
sn.finish();
if(input!=EGL_NO_IMAGE_KHR)sn.destroy(display,input);
if(held)sn.image_delete(held);
for(int i=0;i<pending_count;i++)sn.image_delete(pending[i]);
for(int i=0;i<SURF_NATIVE_SLOTS;i++){
surf_native_slot *slot=&s->native_slots[i];
if(slot->texture)p_glDeleteTextures(1,&slot->texture);
if(slot->egl_image)sn.destroy(display,slot->egl_image);
slot->texture=0;slot->egl_image=EGL_NO_IMAGE_KHR;
}
if(external)p_glDeleteTextures(1,&external);if(fbo)p_glDeleteFramebuffers(1,&fbo);
if(reader)sn.reader_delete(reader);
}
#endif
static void surf_native_complete(surf_swapchain *s) {
pthread_mutex_lock(&surf_lock);
if(s->native_pending>=0)s->native_slots[s->native_pending].state=0;
s->native_pending=-1;pthread_mutex_unlock(&surf_lock);
}
static void surf_native_ownership(VkCommandBuffer command,surf_native_slot *slot,int acquire) {
VkAccessFlags access=slot->projected?VK_ACCESS_TRANSFER_READ_BIT:VK_ACCESS_SHADER_READ_BIT;
VkImageLayout layout=slot->projected?VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL:VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
VkImageMemoryBarrier barrier={VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,NULL,
acquire?0:access,acquire?access:0,
acquire?VK_IMAGE_LAYOUT_GENERAL:layout,
acquire?layout:VK_IMAGE_LAYOUT_GENERAL,
acquire?VK_QUEUE_FAMILY_FOREIGN_EXT:vk.family,acquire?vk.family:VK_QUEUE_FAMILY_FOREIGN_EXT,
slot->image,{VK_IMAGE_ASPECT_COLOR_BIT,0,1,0,1}};
vk.CmdPipelineBarrier(command,VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
0,0,NULL,0,NULL,1,&barrier);
}
static void surf_native_retire(surf_swapchain *s) {
if(!s->native_mode || s->native_current<0)return;
// Teardown is the only blocking handoff. The worker is stopped before a
// swapchain is destroyed, so it cannot rewrite an image being retired.
VkCommandBufferBeginInfo begin={VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,NULL,
VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT,NULL};
vk.ResetCommandBuffer(s->cmd,0);vk.BeginCommandBuffer(s->cmd,&begin);
surf_native_ownership(s->cmd,&s->native_slots[s->native_current],0);
vk.EndCommandBuffer(s->cmd);
VkSubmitInfo submit={VK_STRUCTURE_TYPE_SUBMIT_INFO,NULL,0,NULL,NULL,1,&s->cmd,0,NULL};
if(vk.QueueSubmit(vk.queue,1,&submit,s->fence)==VK_SUCCESS){
vk.WaitForFences(vk.device,1,&s->fence,VK_TRUE,UINT64_MAX);vk.ResetFences(vk.device,1,&s->fence);
}
pthread_mutex_lock(&surf_lock);s->native_slots[s->native_current].state=0;
s->native_current=-1;pthread_mutex_unlock(&surf_lock);
}
static void surf_native_destroy(surf_swapchain *s) {
if(!s->native_mode)return;
for(int i=0;i<SURF_NATIVE_SLOTS;i++)surf_native_slot_destroy(&s->native_slots[i]);
}
+511
View File
@@ -0,0 +1,511 @@
// SPDX-License-Identifier: GPL-3.0-only
// Vulkan presentation for equirectangular Android video surfaces. The decoder's
// native GPU path projects directly from YUV on the surface worker, then copies
// the finished stereo view into a runtime swapchain. CPU-delivered/reference
// panoramas use a compute shader. No unsupported equirect layer reaches runtime.
#include "surface_projection_spv.h"
typedef struct {
XrSwapchain output;
VkImage images[MAX_IMAGES], source, rendered, video_cache;
VkImageView rendered_view, source_view, video_cache_view;
VkDeviceMemory memory, rendered_memory, video_cache_memory;
VkSampler sampler;
VkDescriptorPool descriptors;
VkDescriptorSetLayout set_layout;
VkDescriptorSet set;
VkPipelineLayout layout;
VkPipeline pipeline;
uint32_t count, size, width, height, acquired_index;
int acquired;
XrTime presented_time;
XrTime tracking_log_time;
uint64_t source_seq;
int source_ready, ready, view_source, occludes, cache_ready;
XrCompositionLayerProjection layer;
XrCompositionLayerProjectionView eyes[2];
surf_video_job presented_job, cached_job;
} surf_projection;
static surf_projection surf_projections[SURF_MAX];
static struct {
#define SP_FN(name) PFN_vk##name name;
SP_FN(CreateImage) SP_FN(DestroyImage) SP_FN(GetImageMemoryRequirements) SP_FN(BindImageMemory)
SP_FN(CreateImageView) SP_FN(DestroyImageView) SP_FN(CreateSampler) SP_FN(DestroySampler)
SP_FN(CreateDescriptorSetLayout) SP_FN(DestroyDescriptorSetLayout) SP_FN(CreateDescriptorPool)
SP_FN(DestroyDescriptorPool) SP_FN(AllocateDescriptorSets) SP_FN(UpdateDescriptorSets)
SP_FN(CreatePipelineLayout) SP_FN(DestroyPipelineLayout) SP_FN(CreateShaderModule) SP_FN(DestroyShaderModule)
SP_FN(CreateRenderPass) SP_FN(DestroyRenderPass) SP_FN(CreateFramebuffer) SP_FN(DestroyFramebuffer)
SP_FN(CreateGraphicsPipelines) SP_FN(CmdBeginRenderPass) SP_FN(CmdEndRenderPass)
SP_FN(CmdSetViewport) SP_FN(CmdSetScissor) SP_FN(CmdDraw)
SP_FN(CreateComputePipelines) SP_FN(DestroyPipeline) SP_FN(CmdBindPipeline) SP_FN(CmdBindDescriptorSets)
SP_FN(CmdPushConstants) SP_FN(CmdDispatch) SP_FN(CmdCopyImage) SP_FN(FreeMemory)
#undef SP_FN
int ready;
} spvk;
static int surf_projection_functions(void) {
if(spvk.ready)return spvk.ready>0;
spvk.ready=-1;
#define SP_LOAD(name) spvk.name=(PFN_vk##name)vk.GetDeviceProcAddr(vk.device,"vk" #name); if(!spvk.name)return 0;
SP_LOAD(CreateImage) SP_LOAD(DestroyImage) SP_LOAD(GetImageMemoryRequirements) SP_LOAD(BindImageMemory)
SP_LOAD(CreateImageView) SP_LOAD(DestroyImageView) SP_LOAD(CreateSampler) SP_LOAD(DestroySampler)
SP_LOAD(CreateDescriptorSetLayout) SP_LOAD(DestroyDescriptorSetLayout) SP_LOAD(CreateDescriptorPool)
SP_LOAD(DestroyDescriptorPool) SP_LOAD(AllocateDescriptorSets) SP_LOAD(UpdateDescriptorSets)
SP_LOAD(CreatePipelineLayout) SP_LOAD(DestroyPipelineLayout) SP_LOAD(CreateShaderModule) SP_LOAD(DestroyShaderModule)
SP_LOAD(CreateRenderPass) SP_LOAD(DestroyRenderPass) SP_LOAD(CreateFramebuffer) SP_LOAD(DestroyFramebuffer)
SP_LOAD(CreateGraphicsPipelines) SP_LOAD(CmdBeginRenderPass) SP_LOAD(CmdEndRenderPass)
SP_LOAD(CmdSetViewport) SP_LOAD(CmdSetScissor) SP_LOAD(CmdDraw)
SP_LOAD(CreateComputePipelines) SP_LOAD(DestroyPipeline) SP_LOAD(CmdBindPipeline) SP_LOAD(CmdBindDescriptorSets)
SP_LOAD(CmdPushConstants) SP_LOAD(CmdDispatch) SP_LOAD(CmdCopyImage) SP_LOAD(FreeMemory)
#undef SP_LOAD
spvk.ready=1;return 1;
}
// All images belong to the session device; failures leave cleanup-safe handles.
static int surf_private_image(uint32_t width,uint32_t height,uint32_t layers,VkFormat format,
VkImageUsageFlags usage,VkImage *image,VkDeviceMemory *memory,VkImageView *view) {
VkImageCreateInfo ci={VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,NULL,0,VK_IMAGE_TYPE_2D,format,
{width,height,1},1,layers,VK_SAMPLE_COUNT_1_BIT,VK_IMAGE_TILING_OPTIMAL,usage,VK_SHARING_MODE_EXCLUSIVE};
if(spvk.CreateImage(vk.device,&ci,NULL,image)!=VK_SUCCESS)return 0;
VkMemoryRequirements req;spvk.GetImageMemoryRequirements(vk.device,*image,&req);
VkPhysicalDeviceMemoryProperties props;svk.GetPhysicalDeviceMemoryProperties(vk.physical,&props);
uint32_t type=UINT32_MAX;
for(uint32_t i=0;i<props.memoryTypeCount;i++)if((req.memoryTypeBits&(1u<<i)) &&
(props.memoryTypes[i].propertyFlags&VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT)){type=i;break;}
if(type==UINT32_MAX)return 0;
VkMemoryAllocateInfo alloc={VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,NULL,req.size,type};
if(svk.AllocateMemory(vk.device,&alloc,NULL,memory)!=VK_SUCCESS ||
spvk.BindImageMemory(vk.device,*image,*memory,0)!=VK_SUCCESS)return 0;
VkImageViewCreateInfo vi={VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,NULL,0,*image,
layers>1?VK_IMAGE_VIEW_TYPE_2D_ARRAY:VK_IMAGE_VIEW_TYPE_2D,format,{0,0,0,0},
{VK_IMAGE_ASPECT_COLOR_BIT,0,1,0,layers}};
return spvk.CreateImageView(vk.device,&vi,NULL,view)==VK_SUCCESS;
}
static void surf_composite_destroy(surf_projection *p);
static int surf_composite_active(surf_projection *p);
static int surf_composite_candidate(const XrFrameEndInfo *info,const XrCompositionLayerBaseHeader *video);
static int surf_composite_cached_only(const XrFrameEndInfo *info,surf_projection *p,const surf_video_job *rendered,const surf_video_job *current);
static void surf_projection_destroy(surf_swapchain *s) {
surf_projection *p=&surf_projections[s-surfs];
if(!spvk.ready || spvk.ready<0)return;
if(s->in_flight) {
vk.WaitForFences(vk.device,1,&s->fence,VK_TRUE,UINT64_MAX);
vk.ResetFences(vk.device,1,&s->fence);s->in_flight=0;
}
surf_native_complete(s);
surf_native_retire(s);
surf_composite_destroy(p);
if(p->video_cache_view)spvk.DestroyImageView(vk.device,p->video_cache_view,NULL);
if(p->video_cache)spvk.DestroyImage(vk.device,p->video_cache,NULL);
if(p->video_cache_memory)spvk.FreeMemory(vk.device,p->video_cache_memory,NULL);
if(p->rendered_view)spvk.DestroyImageView(vk.device,p->rendered_view,NULL);
if(p->rendered)spvk.DestroyImage(vk.device,p->rendered,NULL);
if(p->rendered_memory)spvk.FreeMemory(vk.device,p->rendered_memory,NULL);
if(p->pipeline)spvk.DestroyPipeline(vk.device,p->pipeline,NULL);
if(p->layout)spvk.DestroyPipelineLayout(vk.device,p->layout,NULL);
if(p->descriptors)spvk.DestroyDescriptorPool(vk.device,p->descriptors,NULL);
if(p->set_layout)spvk.DestroyDescriptorSetLayout(vk.device,p->set_layout,NULL);
if(p->sampler)spvk.DestroySampler(vk.device,p->sampler,NULL);
if(p->source_view)spvk.DestroyImageView(vk.device,p->source_view,NULL);
if(p->source)spvk.DestroyImage(vk.device,p->source,NULL);
if(p->memory)spvk.FreeMemory(vk.device,p->memory,NULL);
if(p->output) {
PFN_xrDestroySwapchain destroy=(PFN_xrDestroySwapchain)lookup(active_instance,"xrDestroySwapchain");
if(destroy)destroy(p->output);
}
memset(p,0,sizeof(*p));
}
static int surf_projection_setup(XrSession session,surf_swapchain *s,surf_projection *p,uint32_t width,uint32_t height) {
if(p->pipeline || (s->native_project && p->output))return 1;
if(!surf_vk_ready() || !surf_staging(s) || !surf_projection_functions())return 0;
const char *stage="runtime swapchain";
p->size=equirect_res>=512 && equirect_res<=4096?(uint32_t)equirect_res:1536;
if(s->native_mode && !equirect_res_set)p->size=2560;
p->width=width;p->height=height;
XrSwapchainCreateInfo ci={XR_TYPE_SWAPCHAIN_CREATE_INFO,NULL,0,
XR_SWAPCHAIN_USAGE_TRANSFER_DST_BIT|XR_SWAPCHAIN_USAGE_COLOR_ATTACHMENT_BIT|XR_SWAPCHAIN_USAGE_SAMPLED_BIT,
VK_FORMAT_R8G8B8A8_SRGB,1,2*p->size,p->size,1,1,1};
PFN_xrCreateSwapchain create=(PFN_xrCreateSwapchain)lookup(active_instance,"xrCreateSwapchain");
PFN_xrEnumerateSwapchainImages enumerate=(PFN_xrEnumerateSwapchainImages)lookup(active_instance,"xrEnumerateSwapchainImages");
if(!create || !enumerate)goto fail;
XrResult xr_result=create(session,&ci,&p->output);
if(XR_FAILED(xr_result)) {
static int create_failures;
if(create_failures++<5)LOG("surface_projection: swapchain creation result=%d",xr_result);
goto fail;
}
stage="runtime image enumeration";
XrSwapchainImageVulkanKHR images[MAX_IMAGES];
for(int i=0;i<MAX_IMAGES;i++)images[i]=(XrSwapchainImageVulkanKHR){XR_TYPE_SWAPCHAIN_IMAGE_VULKAN_KHR,NULL,VK_NULL_HANDLE};
uint32_t image_count=0;
if(XR_FAILED(enumerate(p->output,MAX_IMAGES,&image_count,(XrSwapchainImageBaseHeader*)images)) ||
!image_count || image_count>MAX_IMAGES)goto fail;
p->count=image_count;
for(uint32_t i=0;i<p->count;i++)p->images[i]=images[i].image;
if(s->native_project){
stage="video composition cache";
if(!surf_private_image(2*p->size,p->size,1,VK_FORMAT_R8G8B8A8_SRGB,
VK_IMAGE_USAGE_TRANSFER_DST_BIT|VK_IMAGE_USAGE_SAMPLED_BIT,
&p->video_cache,&p->video_cache_memory,&p->video_cache_view))goto fail;
LOG("surface_projection: fused GPU video view ready (%ux%u per eye)",p->size,p->size);
return 1;
}
stage="source image";
VkImageCreateInfo image={VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,NULL,0,VK_IMAGE_TYPE_2D,VK_FORMAT_R8G8B8A8_UNORM,
{width,height,1},1,1,VK_SAMPLE_COUNT_1_BIT,VK_IMAGE_TILING_OPTIMAL,
VK_IMAGE_USAGE_TRANSFER_DST_BIT|VK_IMAGE_USAGE_SAMPLED_BIT,VK_SHARING_MODE_EXCLUSIVE,0,NULL,VK_IMAGE_LAYOUT_UNDEFINED};
VkMemoryRequirements req;
VkPhysicalDeviceMemoryProperties props;svk.GetPhysicalDeviceMemoryProperties(vk.physical,&props);
uint32_t type=UINT32_MAX;
VkMemoryAllocateInfo memory;
VkImageViewCreateInfo view={VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,NULL,0,p->source,VK_IMAGE_VIEW_TYPE_2D,
VK_FORMAT_R8G8B8A8_UNORM,{0,0,0,0},{VK_IMAGE_ASPECT_COLOR_BIT,0,1,0,1}};
if(!s->native_mode){
if(spvk.CreateImage(vk.device,&image,NULL,&p->source)!=VK_SUCCESS)goto fail;
spvk.GetImageMemoryRequirements(vk.device,p->source,&req);
for(uint32_t i=0;i<props.memoryTypeCount;i++)if((req.memoryTypeBits&(1u<<i)) &&
(props.memoryTypes[i].propertyFlags&VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT)){type=i;break;}
if(type==UINT32_MAX)goto fail;
memory=(VkMemoryAllocateInfo){VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,NULL,req.size,type};
if(svk.AllocateMemory(vk.device,&memory,NULL,&p->memory)!=VK_SUCCESS ||
spvk.BindImageMemory(vk.device,p->source,p->memory,0)!=VK_SUCCESS)goto fail;
view.image=p->source;
if(spvk.CreateImageView(vk.device,&view,NULL,&p->source_view)!=VK_SUCCESS)goto fail;
}
// The runtime supports sRGB swapchains, which cannot be storage images.
// Compute into a private UNORM image and copy its encoded pixels unchanged.
stage="private storage image";
image.extent=(VkExtent3D){2*p->size,p->size,1};
image.usage=VK_IMAGE_USAGE_STORAGE_BIT|VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
if(spvk.CreateImage(vk.device,&image,NULL,&p->rendered)!=VK_SUCCESS)goto fail;
spvk.GetImageMemoryRequirements(vk.device,p->rendered,&req);
type=UINT32_MAX;
for(uint32_t i=0;i<props.memoryTypeCount;i++)if((req.memoryTypeBits&(1u<<i)) &&
(props.memoryTypes[i].propertyFlags&VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT)){type=i;break;}
if(type==UINT32_MAX)goto fail;
memory=(VkMemoryAllocateInfo){VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,NULL,req.size,type};
if(svk.AllocateMemory(vk.device,&memory,NULL,&p->rendered_memory)!=VK_SUCCESS ||
spvk.BindImageMemory(vk.device,p->rendered,p->rendered_memory,0)!=VK_SUCCESS)goto fail;
view.image=p->rendered;
if(spvk.CreateImageView(vk.device,&view,NULL,&p->rendered_view)!=VK_SUCCESS)goto fail;
stage="sampler and descriptors";
VkSamplerCreateInfo sampler={VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO,NULL,0,VK_FILTER_LINEAR,VK_FILTER_LINEAR,
VK_SAMPLER_MIPMAP_MODE_NEAREST,VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,0,VK_FALSE,1,VK_FALSE,VK_COMPARE_OP_ALWAYS,0,0,VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK,VK_FALSE};
if(spvk.CreateSampler(vk.device,&sampler,NULL,&p->sampler)!=VK_SUCCESS)goto fail;
VkDescriptorSetLayoutBinding bindings[2]={{0,VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,1,VK_SHADER_STAGE_COMPUTE_BIT,NULL},
{1,VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,1,VK_SHADER_STAGE_COMPUTE_BIT,NULL}};
VkDescriptorSetLayoutCreateInfo set={VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,NULL,0,2,bindings};
if(spvk.CreateDescriptorSetLayout(vk.device,&set,NULL,&p->set_layout)!=VK_SUCCESS)goto fail;
VkDescriptorPoolSize sizes[2]={{VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,1},{VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,1}};
VkDescriptorPoolCreateInfo pool={VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,NULL,0,1,2,sizes};
if(spvk.CreateDescriptorPool(vk.device,&pool,NULL,&p->descriptors)!=VK_SUCCESS)goto fail;
VkDescriptorSetAllocateInfo alloc={VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO,NULL,p->descriptors,1,&p->set_layout};
if(spvk.AllocateDescriptorSets(vk.device,&alloc,&p->set)!=VK_SUCCESS)goto fail;
stage="compute pipeline";
VkPushConstantRange range={VK_SHADER_STAGE_COMPUTE_BIT,0,128};
VkPipelineLayoutCreateInfo layout={VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,NULL,0,1,&p->set_layout,1,&range};
if(spvk.CreatePipelineLayout(vk.device,&layout,NULL,&p->layout)!=VK_SUCCESS)goto fail;
VkShaderModule module;
VkShaderModuleCreateInfo shader={VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO,NULL,0,sizeof(surface_projection_spv),surface_projection_spv};
if(spvk.CreateShaderModule(vk.device,&shader,NULL,&module)!=VK_SUCCESS)goto fail;
VkComputePipelineCreateInfo pipeline={VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,NULL,0,
{VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,NULL,0,VK_SHADER_STAGE_COMPUTE_BIT,module,"main",NULL},p->layout,VK_NULL_HANDLE,0};
VkResult result=spvk.CreateComputePipelines(vk.device,VK_NULL_HANDLE,1,&pipeline,NULL,&p->pipeline);
spvk.DestroyShaderModule(vk.device,module,NULL);
if(result!=VK_SUCCESS)goto fail;
LOG("surface_projection: Vulkan stereo panorama renderer ready (%ux%u per eye)",p->size,p->size);return 1;
fail:;
static int failures;
if(failures++<5)LOG("surface_projection: setup failed at %s; retaining original layer behavior",stage);
surf_projection_destroy(s);return 0;
}
// Build both eyes at once. The worker carries this exact pose/space snapshot
// with its finished image rather than labelling an old image with a newer pose.
static int surf_video_request(XrSession session,const XrFrameEndInfo *info,
const XrCompositionLayerBaseHeader *layer,surf_swapchain *s,surf_projection *p) {
emul_common common=emul_common_of(layer);
pthread_mutex_lock(&surf_lock);
int same=s->video_job.seq && s->video_job.time==info->displayTime && s->video_job.space==common.space;
pthread_mutex_unlock(&surf_lock);
if(same)return 1;
surf_video_job job={.time=info->displayTime,.space=common.space,.flags=layer->layerFlags,.size=p->size};
job.views[0].type=job.views[1].type=XR_TYPE_VIEW;
int source=surf_views_select(session,info,common.space,
(PFN_xrLocateSpace)lookup(active_instance,"xrLocateSpace"),job.views);
if(!source){
PFN_xrLocateViews locate=(PFN_xrLocateViews)lookup(active_instance,"xrLocateViews");
XrViewLocateInfo li={XR_TYPE_VIEW_LOCATE_INFO,NULL,XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO,info->displayTime,common.space};
XrViewState state={XR_TYPE_VIEW_STATE};uint32_t count=0;
if(!locate || XR_FAILED(locate(session,&li,&state,2,&count,job.views)) || count!=2 ||
!(state.viewStateFlags&XR_VIEW_STATE_ORIENTATION_VALID_BIT))return 0;
source=3;
}
if(p->view_source!=source){
LOG("surface_projection: views from %s",source==1?"submitted projection":source==2?"application locate":"runtime locate");
p->view_source=source;
}
for(int eye=0;eye<2;eye++){
const XrCompositionLayerBaseHeader *selected=layer;
for(uint32_t i=0;i<info->layerCount;i++)if(emul_is_equirect(info->layers[i])){
emul_common c=emul_common_of(info->layers[i]);
if(c.sub.swapchain==s->handle && c.space==common.space && (c.eye==XR_EYE_VISIBILITY_BOTH ||
c.eye==(eye?XR_EYE_VISIBILITY_RIGHT:XR_EYE_VISIBILITY_LEFT))){selected=info->layers[i];break;}
}
emul_common c=emul_common_of(selected);XrView *view=&job.views[eye];
job.panorama[eye]=c.pose;
view->fov=surf_video_guard_fov(view->fov);
XrQuaternionf rotation=lm_qmul(lm_qconj(c.pose.orientation),view->pose.orientation);
XrVector3f origin=lm_rotate(lm_qconj(c.pose.orientation),(XrVector3f){view->pose.position.x-c.pose.position.x,
view->pose.position.y-c.pose.position.y,view->pose.position.z-c.pose.position.z});
float params[32]={rotation.x,rotation.y,rotation.z,rotation.w,origin.x,origin.y,origin.z,0,
tanf(view->fov.angleLeft),tanf(view->fov.angleRight),tanf(view->fov.angleDown),tanf(view->fov.angleUp),
c.sub.imageRect.offset.x/(float)s->width,c.sub.imageRect.offset.y/(float)s->height,
c.sub.imageRect.extent.width/(float)s->width,c.sub.imageRect.extent.height/(float)s->height,
0,0,0,(float)eye,1,1,0,0,1,1,1,1,0,0,0,0};
if(selected->type==XR_TYPE_COMPOSITION_LAYER_EQUIRECT2_KHR){
const XrCompositionLayerEquirect2KHR *e=(const void*)selected;
params[7]=e->radius;params[16]=e->centralHorizontalAngle;params[17]=e->upperVerticalAngle;params[18]=e->lowerVerticalAngle;
}else{
const XrCompositionLayerEquirectKHR *e=(const void*)selected;
params[7]=e->radius;params[20]=e->scale.x;params[21]=e->scale.y;params[22]=e->bias.x;params[23]=e->bias.y;
}
for(const XrBaseInStructure *n=selected->next;n;n=n->next)if(n->type==XR_TYPE_COMPOSITION_LAYER_COLOR_SCALE_BIAS_KHR){
const XrCompositionLayerColorScaleBiasKHR *color=(const void*)n;
memcpy(params+24,&color->colorScale,16);memcpy(params+28,&color->colorBias,16);
}
memcpy(job.params[eye],params,sizeof(params));
}
pthread_mutex_lock(&surf_lock);job.seq=s->video_job.seq+1;s->video_job=job;
pthread_cond_broadcast(&surf_cond);pthread_mutex_unlock(&surf_lock);
return 1;
}
static const XrCompositionLayerBaseHeader *surf_video_layer(surf_projection *p,const surf_video_job *current) {
if(!p->ready)return NULL;
int occludes=surf_video_occludes(&p->presented_job,current);
if(occludes!=p->occludes && !surf_composite_active(p))LOG("surface_projection: opaque primary=%d (fades and uncovered views retain lower layers)",occludes);
p->occludes=occludes;
for(int eye=0;eye<2;eye++)p->eyes[eye].pose=occludes?
surf_video_primary_pose(&p->presented_job,current,eye):surf_video_pose(&p->presented_job,current,eye);
if(current->time-p->tracking_log_time>=5000000000ll){
XrQuaternionf correction=lm_qmul(lm_qconj(p->eyes[0].pose.orientation),current->views[0].pose.orientation);
XrQuaternionf layer_delta=lm_qmul(lm_qconj(p->presented_job.panorama[0].orientation),current->panorama[0].orientation);
LOG("surface_projection: render age=%.2f ms, head correction=%.2f deg, layer rotation=%.2f deg, space=%p",
(current->time-p->presented_job.time)/1e6,lm_angle(correction)*180/LM_PI,lm_angle(layer_delta)*180/LM_PI,
(void*)(uintptr_t)current->space);
p->tracking_log_time=current->time;
}
return (const void*)&p->layer;
}
static int surf_projection_occludes(const XrCompositionLayerBaseHeader *layer) {
for(int i=0;i<SURF_MAX;i++)if(layer==(const void*)&surf_projections[i].layer)
return surfs[i].native_project && surf_projections[i].ready && surf_projections[i].occludes;
return 0;
}
static const XrCompositionLayerBaseHeader *surf_video_present(XrSession session,const XrFrameEndInfo *info,
const XrCompositionLayerBaseHeader *layer,surf_swapchain *s,surf_projection *p) {
if(!surf_projection_setup(session,s,p,s->width,s->height) || !surf_video_request(session,info,layer,s,p))return NULL;
pthread_mutex_lock(&surf_lock);surf_video_job current=s->video_job;pthread_mutex_unlock(&surf_lock);
// Request tracking updates even when our previous copy is still queued.
if(s->in_flight){
if(svk.GetFenceStatus(vk.device,s->fence)!=VK_SUCCESS)return surf_video_layer(p,&current);
vk.ResetFences(vk.device,1,&s->fence);s->in_flight=0;surf_native_complete(s);
}
// A worker can publish between the two eye calls; present the pair only once.
if(p->ready && p->presented_time==info->displayTime)return surf_video_layer(p,&current);
int slot=-1;
pthread_mutex_lock(&surf_lock);
for(int i=0;i<SURF_NATIVE_SLOTS;i++)if(s->native_slots[i].state==2){slot=i;s->native_slots[i].state=3;break;}
pthread_mutex_unlock(&surf_lock);
if(slot<0)return surf_video_layer(p,&current);
surf_native_slot *native=&s->native_slots[slot];
if(!native->projected || native->width!=2*p->size || native->height!=p->size)goto unused;
PFN_xrAcquireSwapchainImage acquire=(PFN_xrAcquireSwapchainImage)lookup(active_instance,"xrAcquireSwapchainImage");
PFN_xrWaitSwapchainImage wait=(PFN_xrWaitSwapchainImage)lookup(active_instance,"xrWaitSwapchainImage");
PFN_xrReleaseSwapchainImage release=(PFN_xrReleaseSwapchainImage)lookup(active_instance,"xrReleaseSwapchainImage");
int compose=surf_composite_candidate(info,layer);
int cached_only=compose && surf_composite_cached_only(info,p,&native->video,&current);
XrSwapchainImageAcquireInfo ai={XR_TYPE_SWAPCHAIN_IMAGE_ACQUIRE_INFO};
XrSwapchainImageWaitInfo wi={XR_TYPE_SWAPCHAIN_IMAGE_WAIT_INFO,NULL,0};
XrSwapchainImageReleaseInfo ri={XR_TYPE_SWAPCHAIN_IMAGE_RELEASE_INFO};uint32_t index;
if(!acquire || !wait || !release)goto unused;
if(!cached_only && !p->acquired){
if(XR_FAILED(acquire(p->output,&ai,&p->acquired_index)))goto unused;
p->acquired=1;
}
index=p->acquired_index;
XrResult waited=cached_only?XR_SUCCESS:wait(p->output,&wi);
// Timeout is a positive XrResult, but the image is not yet writable. Keep
// it acquired and retry next frame rather than blocking the render thread.
if(waited!=XR_SUCCESS)goto unused;
if(!cached_only && index>=p->count){release(p->output,&ri);p->acquired=0;goto unused;}
VkCommandBufferBeginInfo begin={VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,NULL,VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT};
vk.ResetCommandBuffer(s->cmd,0);vk.BeginCommandBuffer(s->cmd,&begin);
surf_native_ownership(s->cmd,native,1);
if(!cached_only)surf_barrier(s->cmd,p->images[index],VK_IMAGE_LAYOUT_UNDEFINED,VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,0,VK_ACCESS_TRANSFER_WRITE_BIT);
VkImageCopy copy={{VK_IMAGE_ASPECT_COLOR_BIT,0,0,1},{0,0,0},{VK_IMAGE_ASPECT_COLOR_BIT,0,0,1},{0,0,0},{2*p->size,p->size,1}};
if(!cached_only)spvk.CmdCopyImage(s->cmd,native->image,VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,p->images[index],VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,1,&copy);
if(compose){
surf_barrier(s->cmd,p->video_cache,p->cache_ready?VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL:VK_IMAGE_LAYOUT_UNDEFINED,
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,p->cache_ready?VK_ACCESS_SHADER_READ_BIT:0,VK_ACCESS_TRANSFER_WRITE_BIT);
spvk.CmdCopyImage(s->cmd,native->image,VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,p->video_cache,VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,1,&copy);
surf_barrier(s->cmd,p->video_cache,VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
VK_ACCESS_TRANSFER_WRITE_BIT,VK_ACCESS_SHADER_READ_BIT);
}
surf_native_ownership(s->cmd,native,0);
if(!cached_only)surf_barrier(s->cmd,p->images[index],VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
VK_ACCESS_TRANSFER_WRITE_BIT,VK_ACCESS_COLOR_ATTACHMENT_READ_BIT|VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT);
vk.EndCommandBuffer(s->cmd);
VkSubmitInfo submit={VK_STRUCTURE_TYPE_SUBMIT_INFO,NULL,0,NULL,NULL,1,&s->cmd};
int ok=vk.QueueSubmit(vk.queue,1,&submit,s->fence)==VK_SUCCESS;
if(!cached_only){release(p->output,&ri);p->acquired=0;}if(!ok)goto unused;
s->native_pending=slot;s->in_flight=1;s->uploads++;if(compose){p->cache_ready=1;p->cached_job=native->video;}
p->width=native->source_width;p->height=native->source_height;p->source_seq=native->seq;p->source_ready=1;
for(int eye=0;eye<2;eye++)p->eyes[eye]=(XrCompositionLayerProjectionView){XR_TYPE_COMPOSITION_LAYER_PROJECTION_VIEW,NULL,
native->video.views[eye].pose,native->video.views[eye].fov,
{p->output,{{eye*(int32_t)p->size,0},{(int32_t)p->size,(int32_t)p->size}},0}};
p->layer=(XrCompositionLayerProjection){XR_TYPE_COMPOSITION_LAYER_PROJECTION,NULL,native->video.flags,native->video.space,2,p->eyes};
p->presented_job=native->video;
p->ready=1;p->presented_time=info->displayTime;return surf_video_layer(p,&current);
unused:
pthread_mutex_lock(&surf_lock);native->state=native->seq==s->seq?2:0;pthread_mutex_unlock(&surf_lock);
return surf_video_layer(p,&current);
}
static const XrCompositionLayerBaseHeader *surf_projection_frame(XrSession session,const XrFrameEndInfo *info,
const XrCompositionLayerBaseHeader *layer) {
if(!surf_vulkan || !emul_is_equirect(layer))return NULL;
emul_common common=emul_common_of(layer);
surf_swapchain *s=surf_find(common.sub.swapchain);
if(!s)return NULL;
surf_projection *p=&surf_projections[s-surfs];
if(s->native_project)return surf_video_present(session,info,layer,s,p);
if(s->in_flight) {
if(svk.GetFenceStatus(vk.device,s->fence)!=VK_SUCCESS)return p->ready?(const XrCompositionLayerBaseHeader*)&p->layer:NULL;
vk.ResetFences(vk.device,1,&s->fence);s->in_flight=0;
surf_native_complete(s);
}
int native_index=-1;
if(s->native_mode){
pthread_mutex_lock(&surf_lock);
for(int i=0;i<SURF_NATIVE_SLOTS;i++)if(s->native_slots[i].state==2){native_index=i;s->native_slots[i].state=3;break;}
pthread_mutex_unlock(&surf_lock);
if(native_index<0 && !p->source_ready)return NULL;
}
surf_native_slot *native=native_index>=0?&s->native_slots[native_index]:NULL;
uint32_t source_width=native?native->width:(s->native_mode?p->width:s->width);
uint32_t source_height=native?native->height:(s->native_mode?p->height:s->height);
if(p->pipeline && (p->width!=source_width || p->height!=source_height)){
if(s->native_mode){p->width=source_width;p->height=source_height;}
else surf_projection_destroy(s);
}
if(!surf_projection_setup(session,s,p,source_width,source_height)){
if(native){pthread_mutex_lock(&surf_lock);native->state=native->seq==s->seq?2:0;pthread_mutex_unlock(&surf_lock);}return NULL;
}
XrView views[2]={{XR_TYPE_VIEW,NULL},{XR_TYPE_VIEW,NULL}};
XrViewState state={XR_TYPE_VIEW_STATE,NULL,0};uint32_t count=0;
XrViewLocateInfo locate={XR_TYPE_VIEW_LOCATE_INFO,NULL,XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO,info->displayTime,common.space};
PFN_xrLocateViews locate_views=(PFN_xrLocateViews)lookup(active_instance,"xrLocateViews");
int view_source=surf_views_select(session,info,common.space,
(PFN_xrLocateSpace)lookup(active_instance,"xrLocateSpace"),views);
if(!view_source){
if(!locate_views || XR_FAILED(locate_views(session,&locate,&state,2,&count,views)) || count!=2 ||
!(state.viewStateFlags&XR_VIEW_STATE_ORIENTATION_VALID_BIT))goto unused;
view_source=3;
}
if(p->view_source!=view_source){
LOG("surface_projection: views from %s, space=%p, frame time=%lld",view_source==1?"submitted projection":
view_source==2?"application locate":"runtime locate",(void*)(uintptr_t)common.space,(long long)info->displayTime);
p->view_source=view_source;
}
pthread_mutex_lock(&surf_lock);uint64_t seq=s->native_mode?(native?native->seq:p->source_seq):s->seq;
if(!s->native_mode && seq!=p->source_seq)memcpy(s->staging_map,s->pixels,(size_t)s->width*s->height*4);
pthread_mutex_unlock(&surf_lock);
if(!seq)goto unused;
PFN_xrAcquireSwapchainImage acquire=(PFN_xrAcquireSwapchainImage)lookup(active_instance,"xrAcquireSwapchainImage");
PFN_xrWaitSwapchainImage wait=(PFN_xrWaitSwapchainImage)lookup(active_instance,"xrWaitSwapchainImage");
PFN_xrReleaseSwapchainImage release=(PFN_xrReleaseSwapchainImage)lookup(active_instance,"xrReleaseSwapchainImage");
XrSwapchainImageAcquireInfo ai={XR_TYPE_SWAPCHAIN_IMAGE_ACQUIRE_INFO,NULL};
XrSwapchainImageWaitInfo wi={XR_TYPE_SWAPCHAIN_IMAGE_WAIT_INFO,NULL,100000000};
XrSwapchainImageReleaseInfo ri={XR_TYPE_SWAPCHAIN_IMAGE_RELEASE_INFO,NULL};uint32_t index;
if(!acquire || !wait || !release || XR_FAILED(acquire(p->output,&ai,&index)))goto unused;
if(index>=p->count || XR_FAILED(wait(p->output,&wi))) {release(p->output,&ri);goto unused;}
int previous_native=s->native_current;
surf_native_slot *sample=native?native:(s->native_mode && previous_native>=0?&s->native_slots[previous_native]:NULL);
VkDescriptorImageInfo descriptors[2]={{VK_NULL_HANDLE,p->rendered_view,VK_IMAGE_LAYOUT_GENERAL},
{p->sampler,sample?sample->view:p->source_view,VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL}};
VkWriteDescriptorSet writes[2];
for(int i=0;i<2;i++)writes[i]=(VkWriteDescriptorSet){VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,NULL,p->set,(uint32_t)i,0,1,
i?VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,&descriptors[i],NULL,NULL};
spvk.UpdateDescriptorSets(vk.device,2,writes,0,NULL);
VkCommandBufferBeginInfo begin={VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,NULL,VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT,NULL};
vk.ResetCommandBuffer(s->cmd,0);vk.BeginCommandBuffer(s->cmd,&begin);
if(native){
if(previous_native>=0)surf_native_ownership(s->cmd,&s->native_slots[previous_native],0);
surf_native_ownership(s->cmd,native,1);
}else if(!s->native_mode && seq!=p->source_seq) {
surf_barrier(s->cmd,p->source,p->source_ready?VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL:VK_IMAGE_LAYOUT_UNDEFINED,
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,p->source_ready?VK_ACCESS_SHADER_READ_BIT:0,VK_ACCESS_TRANSFER_WRITE_BIT);
VkBufferImageCopy copy={0,0,0,{VK_IMAGE_ASPECT_COLOR_BIT,0,0,1},{0,0,0},{s->width,s->height,1}};
svk.CmdCopyBufferToImage(s->cmd,s->staging,p->source,VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,1,&copy);
surf_barrier(s->cmd,p->source,VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
VK_ACCESS_TRANSFER_WRITE_BIT,VK_ACCESS_SHADER_READ_BIT);
}
surf_barrier(s->cmd,p->rendered,VK_IMAGE_LAYOUT_UNDEFINED,VK_IMAGE_LAYOUT_GENERAL,0,VK_ACCESS_SHADER_WRITE_BIT);
spvk.CmdBindPipeline(s->cmd,VK_PIPELINE_BIND_POINT_COMPUTE,p->pipeline);
spvk.CmdBindDescriptorSets(s->cmd,VK_PIPELINE_BIND_POINT_COMPUTE,p->layout,0,1,&p->set,0,NULL);
for(int eye=0;eye<2;eye++) {
const XrCompositionLayerBaseHeader *selected=NULL;
for(uint32_t i=0;i<info->layerCount;i++)if(emul_is_equirect(info->layers[i])) {
emul_common c=emul_common_of(info->layers[i]);
if(c.sub.swapchain==s->handle && c.space==common.space && (c.eye==XR_EYE_VISIBILITY_BOTH ||
c.eye==(eye?XR_EYE_VISIBILITY_RIGHT:XR_EYE_VISIBILITY_LEFT))){selected=info->layers[i];break;}
}
if(!selected)selected=layer;
emul_common c=emul_common_of(selected);
XrQuaternionf rotation=lm_qmul(lm_qconj(c.pose.orientation),views[eye].pose.orientation);
XrVector3f origin=lm_rotate(lm_qconj(c.pose.orientation),(XrVector3f){views[eye].pose.position.x-c.pose.position.x,
views[eye].pose.position.y-c.pose.position.y,views[eye].pose.position.z-c.pose.position.z});
float params[32]={rotation.x,rotation.y,rotation.z,rotation.w,origin.x,origin.y,origin.z,0,
tanf(views[eye].fov.angleLeft),tanf(views[eye].fov.angleRight),tanf(views[eye].fov.angleDown),tanf(views[eye].fov.angleUp),
c.sub.imageRect.offset.x/(float)s->width,c.sub.imageRect.offset.y/(float)s->height,
c.sub.imageRect.extent.width/(float)s->width,c.sub.imageRect.extent.height/(float)s->height,
0,0,0,(float)eye,1,1,0,0,1,1,1,1,0,0,0,0};
if(selected->type==XR_TYPE_COMPOSITION_LAYER_EQUIRECT2_KHR) {
const XrCompositionLayerEquirect2KHR *e=(const void*)selected;
params[7]=e->radius;params[16]=e->centralHorizontalAngle;params[17]=e->upperVerticalAngle;params[18]=e->lowerVerticalAngle;
} else {
const XrCompositionLayerEquirectKHR *e=(const void*)selected;
params[7]=e->radius;params[20]=e->scale.x;params[21]=e->scale.y;params[22]=e->bias.x;params[23]=e->bias.y;
}
for(const XrBaseInStructure *n=selected->next;n;n=n->next)if(n->type==XR_TYPE_COMPOSITION_LAYER_COLOR_SCALE_BIAS_KHR) {
const XrCompositionLayerColorScaleBiasKHR *color=(const void*)n;
memcpy(params+24,&color->colorScale,16);memcpy(params+28,&color->colorBias,16);
}
spvk.CmdPushConstants(s->cmd,p->layout,VK_SHADER_STAGE_COMPUTE_BIT,0,sizeof(params),params);
spvk.CmdDispatch(s->cmd,(p->size+15)/16,(p->size+15)/16,1);
p->eyes[eye]=(XrCompositionLayerProjectionView){XR_TYPE_COMPOSITION_LAYER_PROJECTION_VIEW,NULL,
views[eye].pose,views[eye].fov,{p->output,{{eye*(int32_t)p->size,0},{(int32_t)p->size,(int32_t)p->size}},0}};
}
surf_barrier(s->cmd,p->rendered,VK_IMAGE_LAYOUT_GENERAL,VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
VK_ACCESS_SHADER_WRITE_BIT,VK_ACCESS_TRANSFER_READ_BIT);
surf_barrier(s->cmd,p->images[index],VK_IMAGE_LAYOUT_UNDEFINED,VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
0,VK_ACCESS_TRANSFER_WRITE_BIT);
VkImageCopy rendered_copy={{VK_IMAGE_ASPECT_COLOR_BIT,0,0,1},{0,0,0},
{VK_IMAGE_ASPECT_COLOR_BIT,0,0,1},{0,0,0},{2*p->size,p->size,1}};
spvk.CmdCopyImage(s->cmd,p->rendered,VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
p->images[index],VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,1,&rendered_copy);
surf_barrier(s->cmd,p->images[index],VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
VK_ACCESS_TRANSFER_WRITE_BIT,VK_ACCESS_COLOR_ATTACHMENT_READ_BIT|VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT);
vk.EndCommandBuffer(s->cmd);
VkSubmitInfo submit={VK_STRUCTURE_TYPE_SUBMIT_INFO,NULL,0,NULL,NULL,1,&s->cmd,0,NULL};
int ok=vk.QueueSubmit(vk.queue,1,&submit,s->fence)==VK_SUCCESS;
release(p->output,&ri);
if(!ok)goto unused;
if(native){s->native_pending=previous_native;s->native_current=native_index;}
s->in_flight=1;p->source_ready=1;p->source_seq=seq;s->uploads++;
p->layer=(XrCompositionLayerProjection){XR_TYPE_COMPOSITION_LAYER_PROJECTION,NULL,layer->layerFlags,common.space,2,p->eyes};
p->ready=1;
return (const XrCompositionLayerBaseHeader*)&p->layer;
unused:
if(native){pthread_mutex_lock(&surf_lock);native->state=native->seq==s->seq?2:0;pthread_mutex_unlock(&surf_lock);}
return NULL;
}
#include "surface_composite.c"
+38
View File
@@ -0,0 +1,38 @@
#version 450
layout(local_size_x=16,local_size_y=16) in;
layout(binding=0,rgba8) uniform writeonly image2D outputImage;
layout(binding=1) uniform sampler2D panorama;
layout(push_constant) uniform Params {
vec4 rotation;
vec4 originRadius;
vec4 tans;
vec4 rect;
vec4 anglesEye;
vec4 scaleBias;
vec4 colorScale;
vec4 colorBias;
} p;
vec3 rotate(vec4 q,vec3 v) {return v+2.0*cross(q.xyz,cross(q.xyz,v)+q.w*v);}
void main() {
ivec2 size=imageSize(outputImage),pixel=ivec2(gl_GlobalInvocationID.xy);
int eye=int(p.anglesEye.w),width=size.x/2;
if(pixel.x>=width || pixel.y>=size.y)return;
vec2 uv=(vec2(pixel)+0.5)/vec2(width,size.y);
vec3 d=normalize(rotate(p.rotation,vec3(mix(p.tans.x,p.tans.y,uv.x),mix(p.tans.w,p.tans.z,uv.y),-1.0)));
if(p.originRadius.w>0.0) {
vec3 o=p.originRadius.xyz;
float b=dot(o,d),disc=b*b+p.originRadius.w*p.originRadius.w-dot(o,o);
if(disc<0.0){imageStore(outputImage,pixel+ivec2(eye*width,0),vec4(0));return;}
float distance=-b+sqrt(disc);
if(distance<=0.0){imageStore(outputImage,pixel+ivec2(eye*width,0),vec4(0));return;}
d=normalize(o+distance*d);
}
float lon=atan(d.x,-d.z),lat=asin(clamp(d.y,-1.0,1.0));
vec2 eq;
if(p.anglesEye.x>0.0) eq=vec2(lon/p.anglesEye.x+0.5,(lat-p.anglesEye.z)/(p.anglesEye.y-p.anglesEye.z));
else eq=vec2(lon/6.28318530718+0.5,lat/3.14159265359+0.5)*p.scaleBias.xy+p.scaleBias.zw;
vec4 color=vec4(0);
if(all(greaterThanEqual(eq,vec2(0))) && all(lessThanEqual(eq,vec2(1))))
color=clamp(textureLod(panorama,p.rect.xy+vec2(eq.x,1.0-eq.y)*p.rect.zw,0.0)*p.colorScale+p.colorBias,0.0,1.0);
imageStore(outputImage,pixel+ivec2(eye*width,0),color);
}
+224
View File
@@ -0,0 +1,224 @@
// SPDX-License-Identifier: GPL-3.0-only
// Generated from surface_projection.comp with glslangValidator -V --target-env vulkan1.0.
#pragma once
static const uint32_t surface_projection_spv[]={
0x7230203,0x10000,0x8000b,0x132,0x0,0x20011,0x1,0x20011,
0x32,0x6000b,0x1,0x4c534c47,0x6474732e,0x3035342e,0x0,0x3000e,
0x0,0x1,0x6000f,0x5,0x4,0x6e69616d,0x0,0x31,
0x60010,0x4,0x11,0x10,0x10,0x1,0x30003,0x2,
0x1c2,0x40005,0x4,0x6e69616d,0x0,0x60005,0xe,0x61746f72,
0x76286574,0x763b3466,0x3b3366,0x30005,0xc,0x71,0x30005,0xd,
0x76,0x40005,0x28,0x657a6973,0x0,0x50005,0x2b,0x7074756f,
0x6d497475,0x656761,0x40005,0x2e,0x65786970,0x6c,0x80005,0x31,
0x475f6c67,0x61626f6c,0x766e496c,0x7461636f,0x496e6f69,0x44,0x30005,0x37,
0x657965,0x40005,0x38,0x61726150,0x736d,0x60006,0x38,0x0,
0x61746f72,0x6e6f6974,0x0,0x70006,0x38,0x1,0x6769726f,0x61526e69,
0x73756964,0x0,0x50006,0x38,0x2,0x736e6174,0x0,0x50006,
0x38,0x3,0x74636572,0x0,0x60006,0x38,0x4,0x6c676e61,
0x79457365,0x65,0x60006,0x38,0x5,0x6c616373,0x61694265,0x73,
0x60006,0x38,0x6,0x6f6c6f63,0x61635372,0x656c,0x60006,0x38,
0x7,0x6f6c6f63,0x61694272,0x73,0x30005,0x3a,0x70,0x40005,
0x40,0x74646977,0x68,0x30005,0x5a,0x7675,0x30005,0x67,
0x64,0x40005,0x7a,0x61726170,0x6d,0x40005,0x7e,0x61726170,
0x6d,0x30005,0x88,0x6f,0x30005,0x8c,0x62,0x40005,
0x90,0x63736964,0x0,0x50005,0xab,0x74736964,0x65636e61,0x0,
0x30005,0xc3,0x6e6f6c,0x30005,0xca,0x74616c,0x30005,0xd5,
0x7165,0x40005,0xf9,0x6f6c6f63,0x72,0x50005,0x10b,0x6f6e6170,
0x616d6172,0x0,0x40047,0x2b,0x22,0x0,0x40047,0x2b,
0x21,0x0,0x30047,0x2b,0x19,0x40047,0x31,0xb,
0x1c,0x50048,0x38,0x0,0x23,0x0,0x50048,0x38,
0x1,0x23,0x10,0x50048,0x38,0x2,0x23,0x20,
0x50048,0x38,0x3,0x23,0x30,0x50048,0x38,0x4,
0x23,0x40,0x50048,0x38,0x5,0x23,0x50,0x50048,
0x38,0x6,0x23,0x60,0x50048,0x38,0x7,0x23,
0x70,0x30047,0x38,0x2,0x40047,0x10b,0x22,0x0,
0x40047,0x10b,0x21,0x1,0x40047,0x131,0xb,0x19,
0x20013,0x2,0x30021,0x3,0x2,0x30016,0x6,0x20,
0x40017,0x7,0x6,0x4,0x40020,0x8,0x7,0x7,
0x40017,0x9,0x6,0x3,0x40020,0xa,0x7,0x9,
0x50021,0xb,0x9,0x8,0xa,0x4002b,0x6,0x11,
0x40000000,0x40015,0x18,0x20,0x0,0x4002b,0x18,0x19,
0x3,0x40020,0x1a,0x7,0x6,0x40015,0x25,0x20,
0x1,0x40017,0x26,0x25,0x2,0x40020,0x27,0x7,
0x26,0x90019,0x29,0x6,0x1,0x0,0x0,0x0,
0x2,0x4,0x40020,0x2a,0x0,0x29,0x4003b,0x2a,
0x2b,0x0,0x40017,0x2f,0x18,0x3,0x40020,0x30,
0x1,0x2f,0x4003b,0x30,0x31,0x1,0x40017,0x32,
0x18,0x2,0x40020,0x36,0x7,0x25,0xa001e,0x38,
0x7,0x7,0x7,0x7,0x7,0x7,0x7,0x7,
0x40020,0x39,0x9,0x38,0x4003b,0x39,0x3a,0x9,
0x4002b,0x25,0x3b,0x4,0x40020,0x3c,0x9,0x6,
0x4002b,0x18,0x41,0x0,0x4002b,0x25,0x44,0x2,
0x20014,0x46,0x4002b,0x18,0x4e,0x1,0x40017,0x58,
0x6,0x2,0x40020,0x59,0x7,0x58,0x4002b,0x6,
0x5d,0x3f000000,0x4002b,0x25,0x68,0x0,0x4002b,0x18,
0x72,0x2,0x4002b,0x6,0x78,0xbf800000,0x40020,0x7b,
0x9,0x7,0x4002b,0x25,0x81,0x1,0x4002b,0x6,
0x84,0x0,0x7002c,0x7,0xa9,0x84,0x84,0x84,
0x84,0x4002b,0x6,0xcd,0x3f800000,0x4002b,0x6,0xe8,
0x40c90fdb,0x4002b,0x6,0xec,0x40490fdb,0x4002b,0x25,0xf0,
0x5,0x5002c,0x58,0xfb,0x84,0x84,0x40017,0xfc,
0x46,0x2,0x5002c,0x58,0x102,0xcd,0xcd,0x90019,
0x108,0x6,0x1,0x0,0x0,0x0,0x1,0x0,
0x3001b,0x109,0x108,0x40020,0x10a,0x0,0x109,0x4003b,
0x10a,0x10b,0x0,0x4002b,0x25,0x10d,0x3,0x4002b,
0x25,0x11d,0x6,0x4002b,0x25,0x121,0x7,0x4002b,
0x18,0x130,0x10,0x6002c,0x2f,0x131,0x130,0x130,
0x4e,0x50036,0x2,0x4,0x0,0x3,0x200f8,0x5,
0x4003b,0x27,0x28,0x7,0x4003b,0x27,0x2e,0x7,
0x4003b,0x36,0x37,0x7,0x4003b,0x36,0x40,0x7,
0x4003b,0x59,0x5a,0x7,0x4003b,0xa,0x67,0x7,
0x4003b,0x8,0x7a,0x7,0x4003b,0xa,0x7e,0x7,
0x4003b,0xa,0x88,0x7,0x4003b,0x1a,0x8c,0x7,
0x4003b,0x1a,0x90,0x7,0x4003b,0x1a,0xab,0x7,
0x4003b,0x1a,0xc3,0x7,0x4003b,0x1a,0xca,0x7,
0x4003b,0x59,0xd5,0x7,0x4003b,0x8,0xf9,0x7,
0x4003d,0x29,0x2c,0x2b,0x40068,0x26,0x2d,0x2c,
0x3003e,0x28,0x2d,0x4003d,0x2f,0x33,0x31,0x7004f,
0x32,0x34,0x33,0x33,0x0,0x1,0x4007c,0x26,
0x35,0x34,0x3003e,0x2e,0x35,0x60041,0x3c,0x3d,
0x3a,0x3b,0x19,0x4003d,0x6,0x3e,0x3d,0x4006e,
0x25,0x3f,0x3e,0x3003e,0x37,0x3f,0x50041,0x36,
0x42,0x28,0x41,0x4003d,0x25,0x43,0x42,0x50087,
0x25,0x45,0x43,0x44,0x3003e,0x40,0x45,0x50041,
0x36,0x47,0x2e,0x41,0x4003d,0x25,0x48,0x47,
0x4003d,0x25,0x49,0x40,0x500af,0x46,0x4a,0x48,
0x49,0x400a8,0x46,0x4b,0x4a,0x300f7,0x4d,0x0,
0x400fa,0x4b,0x4c,0x4d,0x200f8,0x4c,0x50041,0x36,
0x4f,0x2e,0x4e,0x4003d,0x25,0x50,0x4f,0x50041,
0x36,0x51,0x28,0x4e,0x4003d,0x25,0x52,0x51,
0x500af,0x46,0x53,0x50,0x52,0x200f9,0x4d,0x200f8,
0x4d,0x700f5,0x46,0x54,0x4a,0x5,0x53,0x4c,
0x300f7,0x56,0x0,0x400fa,0x54,0x55,0x56,0x200f8,
0x55,0x100fd,0x200f8,0x56,0x4003d,0x26,0x5b,0x2e,
0x4006f,0x58,0x5c,0x5b,0x50050,0x58,0x5e,0x5d,
0x5d,0x50081,0x58,0x5f,0x5c,0x5e,0x4003d,0x25,
0x60,0x40,0x4006f,0x6,0x61,0x60,0x50041,0x36,
0x62,0x28,0x4e,0x4003d,0x25,0x63,0x62,0x4006f,
0x6,0x64,0x63,0x50050,0x58,0x65,0x61,0x64,
0x50088,0x58,0x66,0x5f,0x65,0x3003e,0x5a,0x66,
0x60041,0x3c,0x69,0x3a,0x44,0x41,0x4003d,0x6,
0x6a,0x69,0x60041,0x3c,0x6b,0x3a,0x44,0x4e,
0x4003d,0x6,0x6c,0x6b,0x50041,0x1a,0x6d,0x5a,
0x41,0x4003d,0x6,0x6e,0x6d,0x8000c,0x6,0x6f,
0x1,0x2e,0x6a,0x6c,0x6e,0x60041,0x3c,0x70,
0x3a,0x44,0x19,0x4003d,0x6,0x71,0x70,0x60041,
0x3c,0x73,0x3a,0x44,0x72,0x4003d,0x6,0x74,
0x73,0x50041,0x1a,0x75,0x5a,0x4e,0x4003d,0x6,
0x76,0x75,0x8000c,0x6,0x77,0x1,0x2e,0x71,
0x74,0x76,0x60050,0x9,0x79,0x6f,0x77,0x78,
0x50041,0x7b,0x7c,0x3a,0x68,0x4003d,0x7,0x7d,
0x7c,0x3003e,0x7a,0x7d,0x3003e,0x7e,0x79,0x60039,
0x9,0x7f,0xe,0x7a,0x7e,0x6000c,0x9,0x80,
0x1,0x45,0x7f,0x3003e,0x67,0x80,0x60041,0x3c,
0x82,0x3a,0x81,0x19,0x4003d,0x6,0x83,0x82,
0x500ba,0x46,0x85,0x83,0x84,0x300f7,0x87,0x0,
0x400fa,0x85,0x86,0x87,0x200f8,0x86,0x50041,0x7b,
0x89,0x3a,0x81,0x4003d,0x7,0x8a,0x89,0x8004f,
0x9,0x8b,0x8a,0x8a,0x0,0x1,0x2,0x3003e,
0x88,0x8b,0x4003d,0x9,0x8d,0x88,0x4003d,0x9,
0x8e,0x67,0x50094,0x6,0x8f,0x8d,0x8e,0x3003e,
0x8c,0x8f,0x4003d,0x6,0x91,0x8c,0x4003d,0x6,
0x92,0x8c,0x50085,0x6,0x93,0x91,0x92,0x60041,
0x3c,0x94,0x3a,0x81,0x19,0x4003d,0x6,0x95,
0x94,0x60041,0x3c,0x96,0x3a,0x81,0x19,0x4003d,
0x6,0x97,0x96,0x50085,0x6,0x98,0x95,0x97,
0x50081,0x6,0x99,0x93,0x98,0x4003d,0x9,0x9a,
0x88,0x4003d,0x9,0x9b,0x88,0x50094,0x6,0x9c,
0x9a,0x9b,0x50083,0x6,0x9d,0x99,0x9c,0x3003e,
0x90,0x9d,0x4003d,0x6,0x9e,0x90,0x500b8,0x46,
0x9f,0x9e,0x84,0x300f7,0xa1,0x0,0x400fa,0x9f,
0xa0,0xa1,0x200f8,0xa0,0x4003d,0x29,0xa2,0x2b,
0x4003d,0x26,0xa3,0x2e,0x4003d,0x25,0xa4,0x37,
0x4003d,0x25,0xa5,0x40,0x50084,0x25,0xa6,0xa4,
0xa5,0x50050,0x26,0xa7,0xa6,0x68,0x50080,0x26,
0xa8,0xa3,0xa7,0x40063,0xa2,0xa8,0xa9,0x100fd,
0x200f8,0xa1,0x4003d,0x6,0xac,0x8c,0x4007f,0x6,
0xad,0xac,0x4003d,0x6,0xae,0x90,0x6000c,0x6,
0xaf,0x1,0x1f,0xae,0x50081,0x6,0xb0,0xad,
0xaf,0x3003e,0xab,0xb0,0x4003d,0x6,0xb1,0xab,
0x500bc,0x46,0xb2,0xb1,0x84,0x300f7,0xb4,0x0,
0x400fa,0xb2,0xb3,0xb4,0x200f8,0xb3,0x4003d,0x29,
0xb5,0x2b,0x4003d,0x26,0xb6,0x2e,0x4003d,0x25,
0xb7,0x37,0x4003d,0x25,0xb8,0x40,0x50084,0x25,
0xb9,0xb7,0xb8,0x50050,0x26,0xba,0xb9,0x68,
0x50080,0x26,0xbb,0xb6,0xba,0x40063,0xb5,0xbb,
0xa9,0x100fd,0x200f8,0xb4,0x4003d,0x9,0xbd,0x88,
0x4003d,0x6,0xbe,0xab,0x4003d,0x9,0xbf,0x67,
0x5008e,0x9,0xc0,0xbf,0xbe,0x50081,0x9,0xc1,
0xbd,0xc0,0x6000c,0x9,0xc2,0x1,0x45,0xc1,
0x3003e,0x67,0xc2,0x200f9,0x87,0x200f8,0x87,0x50041,
0x1a,0xc4,0x67,0x41,0x4003d,0x6,0xc5,0xc4,
0x50041,0x1a,0xc6,0x67,0x72,0x4003d,0x6,0xc7,
0xc6,0x4007f,0x6,0xc8,0xc7,0x7000c,0x6,0xc9,
0x1,0x19,0xc5,0xc8,0x3003e,0xc3,0xc9,0x50041,
0x1a,0xcb,0x67,0x4e,0x4003d,0x6,0xcc,0xcb,
0x8000c,0x6,0xce,0x1,0x2b,0xcc,0x78,0xcd,
0x6000c,0x6,0xcf,0x1,0x10,0xce,0x3003e,0xca,
0xcf,0x60041,0x3c,0xd0,0x3a,0x3b,0x41,0x4003d,
0x6,0xd1,0xd0,0x500ba,0x46,0xd2,0xd1,0x84,
0x300f7,0xd4,0x0,0x400fa,0xd2,0xd3,0xe6,0x200f8,
0xd3,0x4003d,0x6,0xd6,0xc3,0x60041,0x3c,0xd7,
0x3a,0x3b,0x41,0x4003d,0x6,0xd8,0xd7,0x50088,
0x6,0xd9,0xd6,0xd8,0x50081,0x6,0xda,0xd9,
0x5d,0x4003d,0x6,0xdb,0xca,0x60041,0x3c,0xdc,
0x3a,0x3b,0x72,0x4003d,0x6,0xdd,0xdc,0x50083,
0x6,0xde,0xdb,0xdd,0x60041,0x3c,0xdf,0x3a,
0x3b,0x4e,0x4003d,0x6,0xe0,0xdf,0x60041,0x3c,
0xe1,0x3a,0x3b,0x72,0x4003d,0x6,0xe2,0xe1,
0x50083,0x6,0xe3,0xe0,0xe2,0x50088,0x6,0xe4,
0xde,0xe3,0x50050,0x58,0xe5,0xda,0xe4,0x3003e,
0xd5,0xe5,0x200f9,0xd4,0x200f8,0xe6,0x4003d,0x6,
0xe7,0xc3,0x50088,0x6,0xe9,0xe7,0xe8,0x50081,
0x6,0xea,0xe9,0x5d,0x4003d,0x6,0xeb,0xca,
0x50088,0x6,0xed,0xeb,0xec,0x50081,0x6,0xee,
0xed,0x5d,0x50050,0x58,0xef,0xea,0xee,0x50041,
0x7b,0xf1,0x3a,0xf0,0x4003d,0x7,0xf2,0xf1,
0x7004f,0x58,0xf3,0xf2,0xf2,0x0,0x1,0x50085,
0x58,0xf4,0xef,0xf3,0x50041,0x7b,0xf5,0x3a,
0xf0,0x4003d,0x7,0xf6,0xf5,0x7004f,0x58,0xf7,
0xf6,0xf6,0x2,0x3,0x50081,0x58,0xf8,0xf4,
0xf7,0x3003e,0xd5,0xf8,0x200f9,0xd4,0x200f8,0xd4,
0x3003e,0xf9,0xa9,0x4003d,0x58,0xfa,0xd5,0x500be,
0xfc,0xfd,0xfa,0xfb,0x4009b,0x46,0xfe,0xfd,
0x300f7,0x100,0x0,0x400fa,0xfe,0xff,0x100,0x200f8,
0xff,0x4003d,0x58,0x101,0xd5,0x500bc,0xfc,0x103,
0x101,0x102,0x4009b,0x46,0x104,0x103,0x200f9,0x100,
0x200f8,0x100,0x700f5,0x46,0x105,0xfe,0xd4,0x104,
0xff,0x300f7,0x107,0x0,0x400fa,0x105,0x106,0x107,
0x200f8,0x106,0x4003d,0x109,0x10c,0x10b,0x50041,0x7b,
0x10e,0x3a,0x10d,0x4003d,0x7,0x10f,0x10e,0x7004f,
0x58,0x110,0x10f,0x10f,0x0,0x1,0x50041,0x1a,
0x111,0xd5,0x41,0x4003d,0x6,0x112,0x111,0x50041,
0x1a,0x113,0xd5,0x4e,0x4003d,0x6,0x114,0x113,
0x50083,0x6,0x115,0xcd,0x114,0x50050,0x58,0x116,
0x112,0x115,0x50041,0x7b,0x117,0x3a,0x10d,0x4003d,
0x7,0x118,0x117,0x7004f,0x58,0x119,0x118,0x118,
0x2,0x3,0x50085,0x58,0x11a,0x116,0x119,0x50081,
0x58,0x11b,0x110,0x11a,0x70058,0x7,0x11c,0x10c,
0x11b,0x2,0x84,0x50041,0x7b,0x11e,0x3a,0x11d,
0x4003d,0x7,0x11f,0x11e,0x50085,0x7,0x120,0x11c,
0x11f,0x50041,0x7b,0x122,0x3a,0x121,0x4003d,0x7,
0x123,0x122,0x50081,0x7,0x124,0x120,0x123,0x70050,
0x7,0x125,0x84,0x84,0x84,0x84,0x70050,0x7,
0x126,0xcd,0xcd,0xcd,0xcd,0x8000c,0x7,0x127,
0x1,0x2b,0x124,0x125,0x126,0x3003e,0xf9,0x127,
0x200f9,0x107,0x200f8,0x107,0x4003d,0x29,0x128,0x2b,
0x4003d,0x26,0x129,0x2e,0x4003d,0x25,0x12a,0x37,
0x4003d,0x25,0x12b,0x40,0x50084,0x25,0x12c,0x12a,
0x12b,0x50050,0x26,0x12d,0x12c,0x68,0x50080,0x26,
0x12e,0x129,0x12d,0x4003d,0x7,0x12f,0xf9,0x40063,
0x128,0x12e,0x12f,0x100fd,0x10038,0x50036,0x9,0xe,
0x0,0xb,0x30037,0x8,0xc,0x30037,0xa,0xd,
0x200f8,0xf,0x4003d,0x9,0x10,0xd,0x4003d,0x7,
0x12,0xc,0x8004f,0x9,0x13,0x12,0x12,0x0,
0x1,0x2,0x4003d,0x7,0x14,0xc,0x8004f,0x9,
0x15,0x14,0x14,0x0,0x1,0x2,0x4003d,0x9,
0x16,0xd,0x7000c,0x9,0x17,0x1,0x44,0x15,
0x16,0x50041,0x1a,0x1b,0xc,0x19,0x4003d,0x6,
0x1c,0x1b,0x4003d,0x9,0x1d,0xd,0x5008e,0x9,
0x1e,0x1d,0x1c,0x50081,0x9,0x1f,0x17,0x1e,
0x7000c,0x9,0x20,0x1,0x44,0x13,0x1f,0x5008e,
0x9,0x21,0x20,0x11,0x50081,0x9,0x22,0x10,
0x21,0x200fe,0x22,0x10038
};
+54 -2
View File
@@ -13,6 +13,29 @@
// copy on the session's queue; GLES: glTexSubImage2D in the app's context), then is submitted as usual.
// * Any failure: the call returns the runtime's own result (as before), so nothing gets worse.
#include <jni.h>
#include <android/hardware_buffer.h>
#include <android/native_window_jni.h>
#include <media/NdkImageReader.h>
#include <EGL/eglext.h>
#include <GLES2/gl2ext.h>
#include "surface_video.h"
#define SURF_NATIVE_SLOTS 4
typedef struct {
AHardwareBuffer *buffer;
VkImage image;
VkImageView view;
VkDeviceMemory memory;
EGLImageKHR egl_image;
GLuint texture;
uint32_t width,height;
int state; // 0 reusable, 1 worker writing, 2 published, 3 current/pending Vulkan sampler
uint64_t seq;
uint32_t source_width,source_height;
int64_t source_time;
surf_video_job video;
int projected;
} surf_native_slot;
#define SURF_MAX 8
@@ -49,6 +72,9 @@ typedef struct {
VkCommandBuffer cmd;
VkFence fence;
int in_flight; // a copy was submitted and its fence not yet seen signalled
int native_mode, native_pending, native_current, native_project;
surf_video_job video_job;
surf_native_slot native_slots[SURF_NATIVE_SLOTS];
} surf_swapchain;
static pthread_mutex_t surf_lock = PTHREAD_MUTEX_INITIALIZER;
@@ -68,7 +94,7 @@ static const char *surf_vs = "#version 300 es\nout vec2 uv;\nvoid main() {\n"
" uv = p; gl_Position = vec4(p * 2.0 - 1.0, 0.0, 1.0);\n}\n";
// window row 0 (glReadPixels' first row) must hold the image's top: sample t = 1 - y (SurfaceTexture t=0 is the bottom)
static const char *surf_fs = "#version 300 es\n#extension GL_OES_EGL_image_external_essl3 : require\n"
"precision mediump float;\nuniform samplerExternalOES tex;\nuniform mat4 st;\nin vec2 uv;\nout vec4 color;\n"
"precision highp float;\nuniform samplerExternalOES tex;\nuniform mat4 st;\nin vec2 uv;\nout vec4 color;\n"
"void main() { color = texture(tex, (st * vec4(uv.x, 1.0 - uv.y, 0.0, 1.0)).xy); }\n";
typedef void (*PFN_glReadPixels_)(GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, void *);
@@ -129,6 +155,8 @@ static void surf_fail(surf_swapchain *s, const char *why) {
pthread_mutex_unlock(&surf_lock);
}
#include "surface_native.c"
static void *surf_worker(void *arg) {
surf_swapchain *s = arg;
JNIEnv *env = NULL;
@@ -149,6 +177,7 @@ static void *surf_worker(void *arg) {
surf_fail(s, "EGL context failed");
goto out;
}
if(s->native_mode){surf_native_worker(s,env,dpy);goto out;}
// the SurfaceTexture's external texture, and the RGBA target the frames are drawn into
p_glGenTextures(1, &ext_tex);
p_glBindTexture(0x8D65 /* GL_TEXTURE_EXTERNAL_OES */, ext_tex);
@@ -202,10 +231,15 @@ static void *surf_worker(void *arg) {
size_t bytes = (size_t)s->width * s->height * 4;
uint8_t *buf = malloc(bytes);
int64_t last_ts = -1, window_frames = 0, window_start = 0;
int64_t latch_ns = 0, read_ns = 0, copy_ns = 0, latch_calls = 0;
while (!s->stop && buf) {
struct timespec pause = {0, 8000000}; // ~120 checks a second: well above video frame rates
nanosleep(&pause, NULL);
if (s_ast_update(ast) != 0) continue;
int64_t tick = monotonic_ns();
int latch_result = s_ast_update(ast);
latch_ns += monotonic_ns() - tick;
latch_calls++;
if (latch_result != 0) continue;
int64_t ts = s_ast_timestamp(ast);
if (ts == last_ts) continue; // no new frame latched
last_ts = ts;
@@ -221,11 +255,15 @@ static void *surf_worker(void *arg) {
p_glBindVertexArray(vao);
p_glDrawArrays(GL_TRIANGLES, 0, 3);
s_glPixelStorei(GL_PACK_ALIGNMENT, 1);
tick = monotonic_ns();
s_glReadPixels(0, 0, (GLsizei)s->width, (GLsizei)s->height, GL_RGBA, GL_UNSIGNED_BYTE, buf);
read_ns += monotonic_ns() - tick;
GLenum err = p_glGetError();
tick = monotonic_ns();
pthread_mutex_lock(&surf_lock);
if (!err && s->pixels) { memcpy(s->pixels, buf, bytes); s->seq++; s->frames++; }
pthread_mutex_unlock(&surf_lock);
copy_ns += monotonic_ns() - tick;
if (err) { static int warned; if (warned++ < 5) LOG("surface_emul: GL error 0x%x drawing a frame", err); }
int64_t now = monotonic_ns();
if (!window_start) {
@@ -235,7 +273,11 @@ static void *surf_worker(void *arg) {
if (++window_frames && now - window_start > 5000000000ll) {
LOG("surface_emul: %.1f video frames/s, %d uploaded, %d upload failures", window_frames * 1e9 / (now - window_start),
s->uploads, s->upload_failures);
LOG("surface_emul: timing latch %.2f ms/call (%lld calls), readback %.2f ms/frame, publish %.2f ms/frame, timestamp %lld",
latch_calls ? latch_ns / (1e6 * latch_calls) : 0.0, (long long)latch_calls,
read_ns / (1e6 * window_frames), copy_ns / (1e6 * window_frames), (long long)ts);
window_frames = 0;
latch_ns = read_ns = copy_ns = latch_calls = 0;
window_start = now;
}
}
@@ -442,6 +484,10 @@ static XRAPI_ATTR XrResult XRAPI_CALL hook_xrCreateSwapchainAndroidSurfaceKHR(Xr
s->handle = handle;
s->width = info->width;
s->height = info->height;
s->native_pending=-1;
s->native_current=-1;
s->native_mode=surface_native && surf_vulkan && surf_native_load();
s->native_project=s->native_mode;
s->pixels = calloc((size_t)s->width * s->height, 4);
uint32_t n = 0;
if (surf_vulkan) {
@@ -470,6 +516,7 @@ static XRAPI_ATTR XrResult XRAPI_CALL hook_xrCreateSwapchainAndroidSurfaceKHR(Xr
if (!setup_ok) {
LOG("surface_emul: setup failed (images %u, pixels %d): the panel stays empty", s->image_count, s->pixels != NULL);
if (s->thread) { s->stop = 1; pthread_join(s->thread, NULL); }
surf_native_destroy(s);
if (destroy) destroy(handle);
free(s->pixels);
pthread_mutex_lock(&surf_lock); s->used = 0; pthread_mutex_unlock(&surf_lock);
@@ -485,13 +532,16 @@ static XRAPI_ATTR XrResult XRAPI_CALL hook_xrCreateSwapchainAndroidSurfaceKHR(Xr
}
// xrDestroySwapchain: an emulated swapchain's worker and surface go with it
static void surf_projection_destroy(surf_swapchain *s);
static void surf_on_destroy(XrSwapchain handle) {
pthread_mutex_lock(&surf_lock);
surf_swapchain *s = surf_find(handle);
pthread_mutex_unlock(&surf_lock);
if (!s) return;
s->stop = 1;
surf_projection_destroy(s);
if (s->thread) pthread_join(s->thread, NULL);
surf_native_destroy(s);
if (surf_vm && s->surface) {
JNIEnv *env = NULL;
int attached = 0;
@@ -508,3 +558,5 @@ static void surf_on_destroy(XrSwapchain handle) {
pthread_mutex_unlock(&surf_lock);
LOG("surface_emul: destroyed %p", (void *)(uintptr_t)handle);
}
#include "surface_projection.c"
+165
View File
@@ -0,0 +1,165 @@
// SPDX-License-Identifier: GPL-3.0-only
// Immutable geometry/pose snapshot carried with a GPU-produced video view.
#ifndef FRAMEBRIDGE_SURFACE_VIDEO_H
#define FRAMEBRIDGE_SURFACE_VIDEO_H
#include <math.h>
#include <string.h>
#include "layer_math.h"
#define SURF_VIDEO_GUARD 1.12f
// MediaCodec's timed surface releases carry CLOCK_MONOTONIC presentation times.
// Untimed releases carry media PTS instead; those must not be treated as a clock.
static int64_t surf_video_target(int64_t now,XrTime display_time) {
return display_time>now-100000000ll && display_time<now+100000000ll?display_time:now;
}
static int surf_video_future(int64_t timestamp,int64_t now,int64_t target) {
return timestamp>now-60000000000ll && timestamp<now+60000000000ll && timestamp>target;
}
// A wider frustum gives runtime timewarp real pixels beyond the visible view.
// Keep the expanded FOV on the submitted image, not just on the shader rays.
static XrFovf surf_video_guard_fov(XrFovf fov) {
return (XrFovf){atanf(tanf(fov.angleLeft)*SURF_VIDEO_GUARD),
atanf(tanf(fov.angleRight)*SURF_VIDEO_GUARD),
atanf(tanf(fov.angleUp)*SURF_VIDEO_GUARD),
atanf(tanf(fov.angleDown)*SURF_VIDEO_GUARD)};
}
typedef struct {
uint64_t seq;
XrTime time;
XrSpace space;
XrCompositionLayerFlags flags;
uint32_t size;
XrView views[2];
XrPosef panorama[2];
float params[2][32];
} surf_video_job;
// Reorient a projected infinite panorama with its layer, retaining the actual
// camera rotation used to render it. Centre it on today's eye position because
// an infinite panorama has no translational parallax. This needs no pixel copy.
static XrPosef surf_video_pose(const surf_video_job *rendered,const surf_video_job *current,int eye) {
XrPosef pose=rendered->views[eye].pose;
if(rendered->space!=current->space || rendered->params[eye][7]!=0 || current->params[eye][7]!=0)return pose;
if(memcmp(&rendered->panorama[eye].orientation,&current->panorama[eye].orientation,sizeof(XrQuaternionf))){
XrQuaternionf delta=lm_qmul(current->panorama[eye].orientation,lm_qconj(rendered->panorama[eye].orientation));
pose.orientation=lm_qmul(delta,pose.orientation);
}
pose.position=current->views[eye].pose.position;
return pose;
}
// Reuse a held picture only while the next visible frustum fits inside it.
// The compositor still timewarps at headset cadence using the actual old pose.
// Changed source frames, layer geometry or colour bypass this reuse policy.
static int surf_video_frustum_covers(const surf_video_job *old,const surf_video_job *next,float margin) {
if(!old->seq || old->size!=next->size || old->space!=next->space)return 0;
for(int eye=0;eye<2;eye++){
const float *a=old->params[eye],*b=next->params[eye];
XrQuaternionf relative=lm_qmul(lm_qconj((XrQuaternionf){a[0],a[1],a[2],a[3]}),
(XrQuaternionf){b[0],b[1],b[2],b[3]});
for(int y=0;y<2;y++)for(int x=0;x<2;x++){
XrVector3f ray=lm_rotate(relative,(XrVector3f){b[8+x]/SURF_VIDEO_GUARD,b[10+y]/SURF_VIDEO_GUARD,-1});
if(ray.z>=-0.00001f)return 0;
float u=ray.x/-ray.z,v=ray.y/-ray.z;
if(u<a[8]*margin || u>a[9]*margin || v<a[10]*margin || v>a[11]*margin)return 0;
}
}
return 1;
}
static int surf_video_covers_margin(const surf_video_job *old,const surf_video_job *next,float margin) {
if(old->flags!=next->flags)return 0;
for(int eye=0;eye<2;eye++){
const float *a=old->params[eye],*b=next->params[eye];
if(a[7]>0 && memcmp(&old->panorama[eye],&next->panorama[eye],sizeof(XrPosef)))return 0;
if(a[7]!=b[7] || memcmp(a+12,b+12,20*sizeof(float)) ||
(a[7]>0 && memcmp(a+4,b+4,3*sizeof(float))))return 0;
}
return surf_video_frustum_covers(old,next,margin);
}
static int surf_video_covers(const surf_video_job *old,const surf_video_job *next) {
// Request a new sampling camera before the visible view reaches the outer
// guard. The worker/copy handoff needs reserve while that update is in flight.
return surf_video_covers_margin(old,next,.94f);
}
// Opaque decoded YUV can occlude earlier layers only when every pixel of the
// rendered, guarded stereo frustum lies in its 180-degree hemisphere. Keep
// ordinary composition during fades, outside coverage, and for other shapes.
static int surf_video_occludes(const surf_video_job *rendered,const surf_video_job *current) {
// Occlusion uses actual image coverage, not the worker's earlier redraw
// threshold. Otherwise each asynchronous camera update switches primary
// layers briefly even though the completed image still covers both eyes.
if(rendered->flags!=current->flags || !surf_video_frustum_covers(rendered,current,1.0f))return 0;
for(int eye=0;eye<2;eye++){
const float *p=rendered->params[eye];
const float *q=current->params[eye];
// RGB/source changes require fresh pixels, not a different composition
// path. Require both the submitted picture and requested fade opaque.
if(q[7]!=0 || !isfinite(q[27]+q[31]) || q[27]+q[31]<1.0f)return 0;
if(p[7]!=0 || fabsf(p[16]-LM_PI)>.00001f ||
fabsf(p[17]-LM_PI*.5f)>.00001f || fabsf(p[18]+LM_PI*.5f)>.00001f ||
!isfinite(p[27]+p[31]) || p[27]+p[31]<1.0f ||
p[12]<0 || p[13]<0 || p[14]<=0 || p[15]<=0 ||
p[12]+p[14]>1.0f || p[13]+p[15]>1.0f)return 0;
XrQuaternionf rotation={p[0],p[1],p[2],p[3]};
for(int y=0;y<2;y++)for(int x=0;x<2;x++){
XrVector3f ray=lm_rotate(rotation,(XrVector3f){p[8+x],p[10+y],-1});
if(!isfinite(ray.z) || ray.z>=-.01f)return 0;
}
}
return 1;
}
// A primary projection must describe one rigid stereo camera. Retarget the
// infinite panorama's centre to the current head position, but rotate the eye
// offsets with the actual camera orientation carried by its rendered pixels.
static XrPosef surf_video_primary_pose(const surf_video_job *rendered,const surf_video_job *current,int eye) {
XrPosef pose=surf_video_pose(rendered,current,eye);
XrVector3f centre={
(current->views[0].pose.position.x+current->views[1].pose.position.x)*.5f,
(current->views[0].pose.position.y+current->views[1].pose.position.y)*.5f,
(current->views[0].pose.position.z+current->views[1].pose.position.z)*.5f};
XrVector3f offset={current->views[eye].pose.position.x-centre.x,
current->views[eye].pose.position.y-centre.y,current->views[eye].pose.position.z-centre.z};
offset=lm_rotate(lm_qmul(pose.orientation,lm_qconj(current->views[eye].pose.orientation)),offset);
pose.position=(XrVector3f){centre.x+offset.x,centre.y+offset.y,centre.z+offset.z};
return pose;
}
// A fresh movie picture does not require a fresh camera direction. While the
// visible view fits, keep its panorama-local sampling grid stable across movie
// frames. This avoids encoding tracking motion into the video textures at the
// decoder's cadence. Tracking remains the compositor's responsibility. Carry
// the real anchored camera/FOV with the pixels; never relabel them as a new view.
// Re-anchor at the newest requested view when either eye leaves the guard band
// or the reference space changes. Source/colour updates keep this camera but
// are still rendered with the current mapping/colour. Finite spheres unchanged.
static int surf_video_anchor(const surf_video_job *old,const surf_video_job *current,surf_video_job *draw) {
*draw=*current;
if(old->params[0][7]!=0 || old->params[1][7]!=0 || current->params[0][7]!=0 || current->params[1][7]!=0 ||
!surf_video_frustum_covers(old,current,.94f))return 0;
for(int eye=0;eye<2;eye++){
draw->views[eye]=old->views[eye];
const float *p=old->params[eye];
// Reconstruct from the fixed sampling quaternion, not a succession of
// layer deltas, so long cutscenes cannot accumulate pose-rounding drift.
draw->views[eye].pose.orientation=lm_qmul(current->panorama[eye].orientation,(XrQuaternionf){p[0],p[1],p[2],p[3]});
draw->views[eye].pose.position=current->views[eye].pose.position;
memcpy(draw->params[eye],old->params[eye],12*sizeof(float));
}
return 1;
}
// Same ray/sphere mapping as the Vulkan reference shader, sampled directly
// from the decoder's external YUV texture. No full-size RGB intermediate.
static const char *surf_video_fragment=
"#version 300 es\n#extension GL_OES_EGL_image_external_essl3 : require\n"
"precision highp float;uniform samplerExternalOES tex;in vec2 uv;out vec4 color;"
"uniform vec4 rotation,originRadius,tans,rect,anglesEye,scaleBias,colorScale,colorBias;"
"vec3 rotate(vec4 q,vec3 v){return v+2.0*cross(q.xyz,cross(q.xyz,v)+q.w*v);}"
"void main(){vec3 d=normalize(rotate(rotation,vec3(mix(tans.x,tans.y,uv.x),mix(tans.w,tans.z,uv.y),-1.0)));"
"if(originRadius.w>0.0){vec3 o=originRadius.xyz;float b=dot(o,d),disc=b*b+originRadius.w*originRadius.w-dot(o,o);"
"if(disc<0.0){color=vec4(0);return;}float distance=-b+sqrt(disc);"
"if(distance<=0.0){color=vec4(0);return;}d=normalize(o+distance*d);}"
"float lon=atan(d.x,-d.z),lat=asin(clamp(d.y,-1.0,1.0));vec2 eq;"
"if(anglesEye.x>0.0)eq=vec2(lon/anglesEye.x+0.5,(lat-anglesEye.z)/(anglesEye.y-anglesEye.z));"
"else eq=vec2(lon/6.28318530718+0.5,lat/3.14159265359+0.5)*scaleBias.xy+scaleBias.zw;"
"color=vec4(0);if(all(greaterThanEqual(eq,vec2(0)))&&all(lessThanEqual(eq,vec2(1))))"
"color=clamp(texture(tex,rect.xy+vec2(eq.x,1.0-eq.y)*rect.zw)*colorScale+colorBias,0.0,1.0);}"
;
static const char *surf_video_uniforms[8]={"rotation","originRadius","tans","rect",
"anglesEye","scaleBias","colorScale","colorBias"};
#endif
+61
View File
@@ -0,0 +1,61 @@
// SPDX-License-Identifier: GPL-3.0-only
// Use the views belonging to the submitted frame before sampling tracking again.
// Cached application views are eligible only for the exact session/display time.
#ifndef FRAMEBRIDGE_SURFACE_VIEWS_H
#define FRAMEBRIDGE_SURFACE_VIEWS_H
#include <pthread.h>
#include "layer_math.h"
static pthread_mutex_t surf_views_lock=PTHREAD_MUTEX_INITIALIZER;
static struct {
XrSession session;
XrSpace space;
XrTime time;
XrView views[2];
} surf_view_cache[4];
static void surf_views_record(XrSession session,const XrViewLocateInfo *info,const XrViewState *state,
uint32_t count,const XrView *views) {
if(!info || !state || !views || count!=2 || !info->displayTime ||
!(state->viewStateFlags&XR_VIEW_STATE_ORIENTATION_VALID_BIT))return;
pthread_mutex_lock(&surf_views_lock);
int slot=0;
for(int i=0;i<4;i++){
if(surf_view_cache[i].session==session && surf_view_cache[i].space==info->space){slot=i;break;}
if(surf_view_cache[i].time<surf_view_cache[slot].time)slot=i;
}
surf_view_cache[slot].session=session;surf_view_cache[slot].space=info->space;
surf_view_cache[slot].time=info->displayTime;
surf_view_cache[slot].views[0]=views[0];surf_view_cache[slot].views[1]=views[1];
pthread_mutex_unlock(&surf_views_lock);
}
// 1 = submitted projection views, 2 = exact application locate, 0 = not available.
static int surf_views_select(XrSession session,const XrFrameEndInfo *frame,XrSpace space,
PFN_xrLocateSpace locate,XrView views[2]) {
if(!frame)return 0;
for(uint32_t i=0;i<frame->layerCount;i++){
const XrCompositionLayerBaseHeader *layer=frame->layers[i];
if(!layer || layer->type!=XR_TYPE_COMPOSITION_LAYER_PROJECTION)continue;
const XrCompositionLayerProjection *projection=(const void*)layer;
if(projection->viewCount!=2 || !projection->views)continue;
XrPosef transform={{0,0,0,1},{0,0,0}};
if(projection->space!=space){
XrSpaceLocation location={XR_TYPE_SPACE_LOCATION,NULL,0,{{0,0,0,1},{0,0,0}}};
XrSpaceLocationFlags valid=XR_SPACE_LOCATION_ORIENTATION_VALID_BIT|XR_SPACE_LOCATION_POSITION_VALID_BIT;
if(!locate || XR_FAILED(locate(projection->space,space,frame->displayTime,&location)) ||
(location.locationFlags&valid)!=valid)continue;
transform=location.pose;
}
for(int eye=0;eye<2;eye++){
views[eye].pose=lm_pose_mul(transform,projection->views[eye].pose);
views[eye].fov=projection->views[eye].fov;
}
return 1;
}
int found=0;
pthread_mutex_lock(&surf_views_lock);
for(int i=0;i<4;i++)if(surf_view_cache[i].session==session && surf_view_cache[i].space==space &&
surf_view_cache[i].time==frame->displayTime){
views[0]=surf_view_cache[i].views[0];views[1]=surf_view_cache[i].views[1];found=2;break;
}
pthread_mutex_unlock(&surf_views_lock);return found;
}
#endif
+25 -5
View File
@@ -5,12 +5,12 @@ Everything is fetched on demand into native/.cache (git-ignored):
- Android NDK r27c (27.2.12479018) from Google's repository (checksummed via repository2-3.xml)
- OpenXR headers at the commits each component was written against (KhronosGroup/OpenXR-SDK)
- Temurin JDK 21 (javac) and Android build-tools (d8) for the Java stub classes
Then builds: FrameBridge adapter (arm64 + arm32), VrApi bridge, platform compat, language packs, GL shim, oculusos stub dex, the
Then builds: FrameBridge adapter (arm64 + arm32), VrApi bridge, platform compat, language packs, GL shim, multiview twin interposer (glmv), oculusos stub dex, the
timefix OpenXR layer for Proton games (linux-arm64, glibc; the NDK's clang builds it freestanding), the
OculusHMDConnected helper for Rift games under Proton (win-x64 PE; the NDK's clang + lld-link, no Windows SDK), the
live view's hardware H.264 encoder fp_venc (linux-arm64-bin, static freestanding executable), and rewrites artifacts/SHA256SUMS. Run `frameport parity` afterwards to see which games change.
python native/build.py [--only adapter,bridge,compat,langpack,glshim,eglfmt,ovrtrace,dex,xrlayer,oculushmd,xrshim,vkshim,ovrpshim,vrsettings,venc] [--ndk PATH]
python native/build.py [--only adapter,bridge,compat,langpack,glshim,eglfmt,glmv,ovrtrace,dex,xrlayer,oculushmd,xrshim,vkshim,zinkfix,ovrpshim,vrsettings,venc] [--ndk PATH]
"""
from __future__ import annotations
@@ -275,6 +275,17 @@ def build_eglfmt(tc: Path):
"-Wl,--no-as-needed", "-lEGL", "-Wl,--as-needed", "-ldl", "-llog", "-o", ART / "arm64-v8a/libfpg.so"], cwd=src)
def build_glmv(tc: Path):
"""Single-view draws of OVR_multiview programs (see glmv/glmv.c, frame.gl_multiview_fbo). Named libfpglmv.so: as
long as "libGLESv3.so", whose dlopen string in the engine is rewritten in place. Linked to libGLESv3 so a dlsym on
its handle still finds every GL function it doesn't wrap."""
src = HERE / "glmv"
run([exe(tc, "aarch64-linux-android29-clang"), "-shared", "-fPIC", "-O2", "-Wall", "-Wextra", "-Werror",
"-fvisibility=hidden", f"-ffile-prefix-map={src}=native/glmv", "-Wl,-soname,libfpglmv.so",
"-Wl,-z,max-page-size=16384", "glmv.c", "-Wl,--no-as-needed", "-lGLESv3", "-Wl,--as-needed", "-lEGL", "-ldl",
"-llog", "-o", ART / "arm64-v8a/libfpglmv.so"], cwd=src)
def build_ovrtrace(tc: Path):
"""Meta Platform SDK tracer (see ovrtrace/ovrtrace.c): diagnostics, the game's engine library loads it first."""
src = HERE / "ovrtrace"
@@ -300,6 +311,14 @@ def build_vkshim(tc: Path):
cwd=src)
def build_zinkfix(tc: Path):
"""Shader-fix Vulkan layer for OpenGL ES games (see zinkfix/zinkfix.c): between Zink and the driver."""
src = HERE / "zinkfix"
run([exe(tc, "aarch64-linux-android29-clang"), "-shared", "-fPIC", "-O2", "-Wall", "-Wextra", "-Werror",
"-fvisibility=hidden", "-Wl,-soname,libVkLayer_fp_shaderfix.so", "-Wl,-z,max-page-size=16384", "zinkfix.c",
"-ldl", "-llog", "-o", ART / "arm64-v8a/libVkLayer_fp_shaderfix.so"], cwd=src)
def build_ovrpshim(tc: Path):
"""OVRPlugin frame-loop shim (see ovrpshim/ovrpshim.c) for Unity 2017-2018 built-in Oculus support."""
src = HERE / "ovrpshim"
@@ -352,7 +371,7 @@ def write_sums():
def main():
ap = argparse.ArgumentParser()
ap.add_argument("--only", default="adapter,bridge,compat,langpack,glshim,eglfmt,ovrtrace,dex,xrlayer,oculushmd,xrshim,vkshim,ovrpshim,vrsettings,venc")
ap.add_argument("--only", default="adapter,bridge,compat,langpack,glshim,eglfmt,glmv,ovrtrace,dex,xrlayer,oculushmd,xrshim,vkshim,zinkfix,ovrpshim,vrsettings,venc")
ap.add_argument("--ndk")
args = ap.parse_args()
parts = set(args.only.split(","))
@@ -361,11 +380,12 @@ def main():
tc = clang_dir(ndk(args.ndk)) if parts - {"dex"} else None
steps = {"adapter": lambda: build_adapter(tc), "bridge": lambda: build_bridge(tc), "compat": lambda: build_compat(tc),
"langpack": lambda: build_langpack(tc),
"glshim": lambda: build_glshim(tc), "eglfmt": lambda: build_eglfmt(tc), "ovrtrace": lambda: build_ovrtrace(tc), "xrshim": lambda: build_xrshim(tc), "dex": build_dex, "xrlayer": lambda: build_xrlayer(tc),
"glshim": lambda: build_glshim(tc), "eglfmt": lambda: build_eglfmt(tc), "glmv": lambda: build_glmv(tc), "ovrtrace": lambda: build_ovrtrace(tc), "xrshim": lambda: build_xrshim(tc), "dex": build_dex, "xrlayer": lambda: build_xrlayer(tc),
"oculushmd": lambda: build_oculushmd(tc), "vkshim": lambda: build_vkshim(tc),
"zinkfix": lambda: build_zinkfix(tc),
"ovrpshim": lambda: build_ovrpshim(tc),
"vrsettings": lambda: build_vrsettings(tc), "venc": lambda: build_venc(tc)}
for name in ("adapter", "bridge", "compat", "langpack", "glshim", "eglfmt", "ovrtrace", "xrshim", "vkshim", "ovrpshim", "dex", "xrlayer", "oculushmd", "vrsettings", "venc"):
for name in ("adapter", "bridge", "compat", "langpack", "glshim", "eglfmt", "glmv", "ovrtrace", "xrshim", "vkshim", "zinkfix", "ovrpshim", "dex", "xrlayer", "oculushmd", "vrsettings", "venc"):
if name in parts:
log(f"build {name}")
steps[name]()
+704
View File
@@ -0,0 +1,704 @@
// SPDX-License-Identifier: GPL-3.0-only
// libfpglmv.so: single-view draws of OVR_multiview programs (frame.gl_multiview_fbo, GitHub #77).
//
// OVR_multiview says a draw is INVALID_OPERATION when the number of views of the draw framebuffer differs from the
// num_views the program's vertex shader declares. Qualcomm's Quest driver tolerates it; Mesa (the Frame's GL, Zink)
// enforces it (src/mesa/main/draw_validate.c) and drops the draw silently. Engines that compile every shader with
// `layout(num_views=2) in;` and also draw into ordinary 2D framebuffers (Doom3Quest's HUD/PDA pool: glTexImage2D
// textures + renderbuffers) then get black panels.
//
// This library sits between such an engine and libGLESv3: the patch puts it first in the engine library's DT_NEEDED
// (direct gl* imports bind here) and points the engine's dlopen("libGLESv3.so") at it (same-length name, so its
// qgl* table from dlsym binds here too); every function it doesn't define resolves to libGLESv3 through its own
// dependency (linked --no-as-needed). When a multiview program draws into a framebuffer whose color attachment has no
// views (2D texture, texture layer, renderbuffer, FBO 0), the draw uses a lazily built single-view twin of the program
// (glmv_rewrite.h: num_views layout removed, gl_ViewID_OVR -> 0u), with the original's attribute locations, uniform
// block bindings and default-block uniform values (copied before every such draw), then the original is bound again.
//
// Logcat tag GLMV. Setting gl_mv_debug=1 (libframe_settings.so / framebridge.conf / FRAMEBRIDGE_CONFIG, as the GL
// shim): glGetError after every twin draw, and per-5-s counters.
#define _GNU_SOURCE
#include <EGL/egl.h>
#include <GLES3/gl32.h>
#include <android/log.h>
#include <dlfcn.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "glmv_rewrite.h"
#define TAG "GLMV"
#define LOG(...) __android_log_print(ANDROID_LOG_INFO, TAG, __VA_ARGS__)
#define EXPORT __attribute__((visibility("default")))
#ifndef GLMV_GLES_LIB // (the host test points these at a stand-in GL library)
#define GLMV_GLES_LIB "libGLESv3.so"
#define GLMV_EGL_LIB "libEGL.so"
#endif
#ifndef GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_NUM_VIEWS_OVR
#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_NUM_VIEWS_OVR 0x9630
#endif
// ---------------------------------------------------------------- real functions (only ever from libGLESv3's handle)
#define REAL_LIST(X) \
X(void, UseProgram, (GLuint)) \
X(void, LinkProgram, (GLuint)) \
X(void, DeleteProgram, (GLuint)) \
X(void, BindFramebuffer, (GLenum, GLuint)) \
X(void, DeleteFramebuffers, (GLsizei, const GLuint *)) \
X(void, FramebufferTexture2D, (GLenum, GLenum, GLenum, GLuint, GLint)) \
X(void, FramebufferRenderbuffer, (GLenum, GLenum, GLenum, GLuint)) \
X(void, FramebufferTextureLayer, (GLenum, GLenum, GLuint, GLint, GLint)) \
X(void, FramebufferTexture, (GLenum, GLenum, GLuint, GLint)) \
X(void, DrawBuffers, (GLsizei, const GLenum *)) \
X(void, DrawArrays, (GLenum, GLint, GLsizei)) \
X(void, DrawElements, (GLenum, GLsizei, GLenum, const void *)) \
X(void, DrawArraysInstanced, (GLenum, GLint, GLsizei, GLsizei)) \
X(void, DrawElementsInstanced, (GLenum, GLsizei, GLenum, const void *, GLsizei)) \
X(void, DrawRangeElements, (GLenum, GLuint, GLuint, GLsizei, GLenum, const void *)) \
X(void, DrawArraysIndirect, (GLenum, const void *)) \
X(void, DrawElementsIndirect, (GLenum, GLenum, const void *)) \
X(void, DrawElementsBaseVertex, (GLenum, GLsizei, GLenum, const void *, GLint)) \
X(void, DrawRangeElementsBaseVertex, (GLenum, GLuint, GLuint, GLsizei, GLenum, const void *, GLint)) \
X(void, DrawElementsInstancedBaseVertex, (GLenum, GLsizei, GLenum, const void *, GLsizei, GLint)) \
X(GLenum, GetError, (void)) \
X(void, GetIntegerv, (GLenum, GLint *)) \
X(void, GetFramebufferAttachmentParameteriv, (GLenum, GLenum, GLenum, GLint *)) \
X(void, GetProgramiv, (GLuint, GLenum, GLint *)) \
X(void, GetProgramInfoLog, (GLuint, GLsizei, GLsizei *, GLchar *)) \
X(void, GetShaderiv, (GLuint, GLenum, GLint *)) \
X(void, GetShaderInfoLog, (GLuint, GLsizei, GLsizei *, GLchar *)) \
X(void, GetShaderSource, (GLuint, GLsizei, GLsizei *, GLchar *)) \
X(void, GetAttachedShaders, (GLuint, GLsizei, GLsizei *, GLuint *)) \
X(GLuint, CreateShader, (GLenum)) \
X(void, ShaderSource, (GLuint, GLsizei, const GLchar *const *, const GLint *)) \
X(void, CompileShader, (GLuint)) \
X(void, DeleteShader, (GLuint)) \
X(GLuint, CreateProgram, (void)) \
X(void, AttachShader, (GLuint, GLuint)) \
X(void, BindAttribLocation, (GLuint, GLuint, const GLchar *)) \
X(void, GetActiveAttrib, (GLuint, GLuint, GLsizei, GLsizei *, GLint *, GLenum *, GLchar *)) \
X(GLint, GetAttribLocation, (GLuint, const GLchar *)) \
X(void, GetActiveUniform, (GLuint, GLuint, GLsizei, GLsizei *, GLint *, GLenum *, GLchar *)) \
X(void, GetActiveUniformsiv, (GLuint, GLsizei, const GLuint *, GLenum, GLint *)) \
X(GLint, GetUniformLocation, (GLuint, const GLchar *)) \
X(void, GetUniformfv, (GLuint, GLint, GLfloat *)) \
X(void, GetUniformiv, (GLuint, GLint, GLint *)) \
X(void, GetUniformuiv, (GLuint, GLint, GLuint *)) \
X(void, GetActiveUniformBlockName, (GLuint, GLuint, GLsizei, GLsizei *, GLchar *)) \
X(void, GetActiveUniformBlockiv, (GLuint, GLuint, GLenum, GLint *)) \
X(GLuint, GetUniformBlockIndex, (GLuint, const GLchar *)) \
X(void, UniformBlockBinding, (GLuint, GLuint, GLuint)) \
X(void, Uniform1fv, (GLint, GLsizei, const GLfloat *)) \
X(void, Uniform2fv, (GLint, GLsizei, const GLfloat *)) \
X(void, Uniform3fv, (GLint, GLsizei, const GLfloat *)) \
X(void, Uniform4fv, (GLint, GLsizei, const GLfloat *)) \
X(void, Uniform1iv, (GLint, GLsizei, const GLint *)) \
X(void, Uniform2iv, (GLint, GLsizei, const GLint *)) \
X(void, Uniform3iv, (GLint, GLsizei, const GLint *)) \
X(void, Uniform4iv, (GLint, GLsizei, const GLint *)) \
X(void, Uniform1uiv, (GLint, GLsizei, const GLuint *)) \
X(void, Uniform2uiv, (GLint, GLsizei, const GLuint *)) \
X(void, Uniform3uiv, (GLint, GLsizei, const GLuint *)) \
X(void, Uniform4uiv, (GLint, GLsizei, const GLuint *)) \
X(void, UniformMatrix2fv, (GLint, GLsizei, GLboolean, const GLfloat *)) \
X(void, UniformMatrix3fv, (GLint, GLsizei, GLboolean, const GLfloat *)) \
X(void, UniformMatrix4fv, (GLint, GLsizei, GLboolean, const GLfloat *)) \
X(void, UniformMatrix2x3fv, (GLint, GLsizei, GLboolean, const GLfloat *)) \
X(void, UniformMatrix3x2fv, (GLint, GLsizei, GLboolean, const GLfloat *)) \
X(void, UniformMatrix2x4fv, (GLint, GLsizei, GLboolean, const GLfloat *)) \
X(void, UniformMatrix4x2fv, (GLint, GLsizei, GLboolean, const GLfloat *)) \
X(void, UniformMatrix3x4fv, (GLint, GLsizei, GLboolean, const GLfloat *)) \
X(void, UniformMatrix4x3fv, (GLint, GLsizei, GLboolean, const GLfloat *))
#define DECL(ret, name, args) static ret(*r_##name) args;
REAL_LIST(DECL)
#undef DECL
typedef void (*PFN_FTMV)(GLenum, GLenum, GLuint, GLint, GLint, GLsizei);
typedef void (*PFN_FTMSMV)(GLenum, GLenum, GLuint, GLint, GLsizei, GLint, GLsizei);
static PFN_FTMV r_ftmv;
static PFN_FTMSMV r_ftmsmv;
static __eglMustCastToProperFunctionPointerType (*r_eglGetProcAddress)(const char *);
static EGLBoolean (*r_eglMakeCurrent)(EGLDisplay, EGLSurface, EGLSurface, EGLContext);
static pthread_once_t once = PTHREAD_ONCE_INIT;
static int debug;
static void read_conf_file(const char *path) {
FILE *f = fopen(path, "r");
if (!f) return;
char line[256];
while (fgets(line, sizeof(line), f))
if (!strncmp(line, "gl_mv_debug=", 12)) debug = atoi(line + 12);
fclose(f);
}
// The GL shim's settings sources, later ones winning: libframe_settings.so next to this library, the game's
// framebridge.conf, then FRAMEBRIDGE_CONFIG (Lepton's per-game settings.conf).
static void read_conf(void) {
Dl_info info;
char path[600];
if (dladdr((void *)read_conf, &info) && info.dli_fname) {
const char *slash = strrchr(info.dli_fname, '/');
if (slash && slash - info.dli_fname < 500) {
snprintf(path, sizeof(path), "%.*s/libframe_settings.so", (int)(slash - info.dli_fname), info.dli_fname);
read_conf_file(path);
}
}
char pkg[256] = {0};
FILE *f = fopen("/proc/self/cmdline", "r");
if (f) {
size_t n = fread(pkg, 1, sizeof(pkg) - 1, f);
fclose(f);
pkg[n] = 0;
}
char *colon = strchr(pkg, ':');
if (colon) *colon = 0;
if (*pkg && !strchr(pkg, '/')) {
snprintf(path, sizeof(path), "/sdcard/Android/data/%s/files/framebridge.conf", pkg);
read_conf_file(path);
}
const char *env = getenv("FRAMEBRIDGE_CONFIG");
if (env && *env) read_conf_file(env);
}
static void init(void) {
read_conf();
void *gles = dlopen(GLMV_GLES_LIB, RTLD_NOW | RTLD_LOCAL);
void *egl = dlopen(GLMV_EGL_LIB, RTLD_NOW | RTLD_LOCAL);
r_eglGetProcAddress = egl ? dlsym(egl, "eglGetProcAddress") : NULL;
r_eglMakeCurrent = egl ? dlsym(egl, "eglMakeCurrent") : NULL;
int missing = 0;
#define LOAD(ret, name, args) \
r_##name = gles ? (ret(*) args)dlsym(gles, "gl" #name) : NULL; \
if (!r_##name && r_eglGetProcAddress) r_##name = (ret(*) args)r_eglGetProcAddress("gl" #name); \
missing += !r_##name;
REAL_LIST(LOAD)
#undef LOAD
if (r_eglGetProcAddress) {
r_ftmv = (PFN_FTMV)r_eglGetProcAddress("glFramebufferTextureMultiviewOVR");
r_ftmsmv = (PFN_FTMSMV)r_eglGetProcAddress("glFramebufferTextureMultisampleMultiviewOVR");
}
LOG("library active: single-view draws of multiview programs (gl_mv_debug=%d, %d GL functions missing)", debug,
missing);
}
#define INIT() pthread_once(&once, init)
// ---------------------------------------------------------------- programs
struct uni {
GLenum type;
GLint orig, var; // locations in the original and the twin
GLuint shadow[16]; // last value given to the twin
int valid;
};
struct block {
GLuint orig_index, var_index;
GLint binding; // last binding given to the twin
};
struct prog {
GLuint id;
int multiview; // the vertex shader declares num_views
int nshaders;
GLenum types[6];
char *sources[6]; // stage sources at link time (only kept for multiview programs)
GLuint twin; // single-view twin, 0 = not built yet
int twin_failed;
struct uni *unis;
int nunis;
struct block *blocks;
int nblocks;
};
static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
static struct prog **progs; // indexed by program name (GL names are small integers)
static GLuint nprogs;
static struct prog *find_prog(GLuint id, int create) {
struct prog *p = NULL;
pthread_mutex_lock(&lock);
if (id < nprogs) p = progs[id];
if (!p && create && id < (1u << 24)) {
if (id >= nprogs) {
GLuint n = nprogs ? nprogs : 256;
while (n <= id) n *= 2;
struct prog **grown = realloc(progs, n * sizeof(*grown));
if (grown) {
memset(grown + nprogs, 0, (n - nprogs) * sizeof(*grown));
progs = grown;
nprogs = n;
}
}
if (id < nprogs && (p = calloc(1, sizeof(*p)))) {
p->id = id;
progs[id] = p;
}
}
pthread_mutex_unlock(&lock);
return p;
}
static void drop_twin(struct prog *p) {
if (p->twin && r_DeleteProgram) r_DeleteProgram(p->twin);
p->twin = 0;
p->twin_failed = 0;
free(p->unis);
p->unis = NULL;
p->nunis = 0;
free(p->blocks);
p->blocks = NULL;
p->nblocks = 0;
}
static void drop_sources(struct prog *p) {
for (int i = 0; i < p->nshaders; ++i) free(p->sources[i]);
p->nshaders = 0;
p->multiview = 0;
}
static char *shader_source(GLuint sh) {
GLint len = 0;
r_GetShaderiv(sh, GL_SHADER_SOURCE_LENGTH, &len);
if (len <= 0) return NULL;
char *src = malloc((size_t)len + 1);
if (!src) return NULL;
GLsizei got = 0;
r_GetShaderSource(sh, len, &got, src);
src[got > 0 && got <= len ? got : 0] = 0;
return src;
}
// Before the real link: note whether the program is multiview and keep its stage sources for a later twin.
static void note_program(GLuint id) {
struct prog *p = find_prog(id, 1);
if (!p) return;
drop_twin(p);
drop_sources(p);
GLuint shaders[6];
GLsizei n = 0;
r_GetAttachedShaders(id, 6, &n, shaders);
for (GLsizei i = 0; i < n && i < 6; ++i) {
GLint type = 0;
r_GetShaderiv(shaders[i], GL_SHADER_TYPE, &type);
char *src = shader_source(shaders[i]);
if (!src) continue;
if (type == GL_VERTEX_SHADER && glmv_has_num_views(src)) p->multiview = 1;
p->types[p->nshaders] = (GLenum)type;
p->sources[p->nshaders++] = src;
}
if (!p->multiview) drop_sources(p);
}
// ---------------------------------------------------------------- the single-view twin
static int components(GLenum type, int *kind) { // kind: 0 float, 1 int/bool/sampler, 2 uint, 3 matrix
switch (type) {
case GL_FLOAT: *kind = 0; return 1;
case GL_FLOAT_VEC2: *kind = 0; return 2;
case GL_FLOAT_VEC3: *kind = 0; return 3;
case GL_FLOAT_VEC4: *kind = 0; return 4;
case GL_INT: case GL_BOOL: *kind = 1; return 1;
case GL_INT_VEC2: case GL_BOOL_VEC2: *kind = 1; return 2;
case GL_INT_VEC3: case GL_BOOL_VEC3: *kind = 1; return 3;
case GL_INT_VEC4: case GL_BOOL_VEC4: *kind = 1; return 4;
case GL_UNSIGNED_INT: *kind = 2; return 1;
case GL_UNSIGNED_INT_VEC2: *kind = 2; return 2;
case GL_UNSIGNED_INT_VEC3: *kind = 2; return 3;
case GL_UNSIGNED_INT_VEC4: *kind = 2; return 4;
case GL_FLOAT_MAT2: *kind = 3; return 4;
case GL_FLOAT_MAT3: *kind = 3; return 9;
case GL_FLOAT_MAT4: *kind = 3; return 16;
case GL_FLOAT_MAT2x3: case GL_FLOAT_MAT3x2: *kind = 3; return 6;
case GL_FLOAT_MAT2x4: case GL_FLOAT_MAT4x2: *kind = 3; return 8;
case GL_FLOAT_MAT3x4: case GL_FLOAT_MAT4x3: *kind = 3; return 12;
default: *kind = 1; return 1; // samplers and images: one int (the unit)
}
}
static GLuint compile(GLenum type, const char *src, GLuint prog_id) {
GLuint sh = r_CreateShader(type);
if (!sh) return 0;
r_ShaderSource(sh, 1, &src, NULL);
r_CompileShader(sh);
GLint ok = 0;
r_GetShaderiv(sh, GL_COMPILE_STATUS, &ok);
if (!ok) {
char log[600] = {0};
r_GetShaderInfoLog(sh, sizeof(log) - 1, NULL, log);
LOG("twin of program %u: stage 0x%x failed to compile: %s", prog_id, type, log);
r_DeleteShader(sh);
return 0;
}
return sh;
}
static void copy_attrib_locations(GLuint orig, GLuint twin) {
GLint n = 0;
r_GetProgramiv(orig, GL_ACTIVE_ATTRIBUTES, &n);
for (GLint i = 0; i < n; ++i) {
char name[256];
GLsizei len = 0;
GLint size = 0;
GLenum type = 0;
r_GetActiveAttrib(orig, (GLuint)i, sizeof(name), &len, &size, &type, name);
if (len <= 0 || !strncmp(name, "gl_", 3)) continue;
GLint loc = r_GetAttribLocation(orig, name);
if (loc >= 0) r_BindAttribLocation(twin, (GLuint)loc, name);
}
}
static void map_uniforms(struct prog *p) {
GLint n = 0;
r_GetProgramiv(p->twin, GL_ACTIVE_UNIFORMS, &n);
int cap = 0;
for (GLint i = 0; i < n; ++i) {
char name[256];
GLsizei len = 0;
GLint size = 0;
GLenum type = 0;
GLuint index = (GLuint)i;
GLint block = -1;
r_GetActiveUniform(p->twin, index, sizeof(name) - 16, &len, &size, &type, name);
r_GetActiveUniformsiv(p->twin, 1, &index, GL_UNIFORM_BLOCK_INDEX, &block);
if (len <= 0 || block != -1 || !strncmp(name, "gl_", 3)) continue; // block members live in buffers
char *bracket = len > 3 && !strcmp(name + len - 3, "[0]") ? name + len - 3 : NULL;
if (bracket) *bracket = 0;
for (GLint e = 0; e < (size > 0 ? size : 1); ++e) {
char elem[300];
if (bracket) snprintf(elem, sizeof(elem), "%s[%d]", name, e);
else snprintf(elem, sizeof(elem), "%s", name);
GLint lo = r_GetUniformLocation(p->id, elem), lt = r_GetUniformLocation(p->twin, elem);
if (lo < 0 || lt < 0) continue;
if (p->nunis == cap) {
cap = cap ? cap * 2 : 16;
struct uni *grown = realloc(p->unis, (size_t)cap * sizeof(*grown));
if (!grown) return;
p->unis = grown;
}
p->unis[p->nunis++] = (struct uni){.type = type, .orig = lo, .var = lt};
}
}
GLint nb = 0;
r_GetProgramiv(p->twin, GL_ACTIVE_UNIFORM_BLOCKS, &nb);
p->blocks = nb > 0 ? calloc((size_t)nb, sizeof(*p->blocks)) : NULL;
for (GLint i = 0; p->blocks && i < nb; ++i) {
char name[256];
GLsizei len = 0;
r_GetActiveUniformBlockName(p->twin, (GLuint)i, sizeof(name), &len, name);
GLuint oi = len > 0 ? r_GetUniformBlockIndex(p->id, name) : GL_INVALID_INDEX;
if (oi == GL_INVALID_INDEX) continue;
p->blocks[p->nblocks++] = (struct block){.orig_index = oi, .var_index = (GLuint)i, .binding = -1};
}
}
static int build_twin(struct prog *p) {
GLuint twin = r_CreateProgram(), shaders[6];
int ns = 0, layouts = 0, ids = 0;
for (int i = 0; twin && i < p->nshaders; ++i) {
int l = 0, v = 0;
char *src = glmv_rewrite(p->sources[i], &l, &v);
GLuint sh = src ? compile(p->types[i], src, p->id) : 0;
free(src);
if (!sh) { ns = -1; break; }
layouts += l;
ids += v;
r_AttachShader(twin, sh);
shaders[ns++] = sh;
}
if (twin && ns > 0) {
copy_attrib_locations(p->id, twin);
r_LinkProgram(twin);
}
for (int i = 0; i < ns; ++i) r_DeleteShader(shaders[i]); // flagged only; freed with the program
GLint ok = 0;
if (twin && ns > 0) r_GetProgramiv(twin, GL_LINK_STATUS, &ok);
if (!ok) {
char log[600] = {0};
if (twin && ns > 0) r_GetProgramInfoLog(twin, sizeof(log) - 1, NULL, log);
LOG("twin of program %u failed (%s): drawing it unchanged", p->id, ns > 0 ? log : "compile");
if (twin) r_DeleteProgram(twin);
p->twin_failed = 1;
return 0;
}
p->twin = twin;
map_uniforms(p);
LOG("twin built: program %u -> %u (%d uniforms, %d blocks, %d num_views layouts and %d gl_ViewID_OVR replaced)",
p->id, twin, p->nunis, p->nblocks, layouts, ids);
return 1;
}
static unsigned long uniform_sets; // twin uniforms changed (statistics)
static void sync_uniforms(struct prog *p) {
for (int i = 0; i < p->nunis; ++i) {
struct uni *u = &p->unis[i];
int kind, n = components(u->type, &kind);
GLuint v[16] = {0};
if (kind == 0 || kind == 3) r_GetUniformfv(p->id, u->orig, (GLfloat *)v);
else if (kind == 2) r_GetUniformuiv(p->id, u->orig, v);
else r_GetUniformiv(p->id, u->orig, (GLint *)v);
if (u->valid && !memcmp(v, u->shadow, (size_t)n * sizeof(GLuint))) continue;
memcpy(u->shadow, v, sizeof(v));
u->valid = 1;
++uniform_sets;
const GLfloat *f = (const GLfloat *)v;
const GLint *iv = (const GLint *)v;
switch (u->type) {
case GL_FLOAT: r_Uniform1fv(u->var, 1, f); break;
case GL_FLOAT_VEC2: r_Uniform2fv(u->var, 1, f); break;
case GL_FLOAT_VEC3: r_Uniform3fv(u->var, 1, f); break;
case GL_FLOAT_VEC4: r_Uniform4fv(u->var, 1, f); break;
case GL_UNSIGNED_INT: r_Uniform1uiv(u->var, 1, v); break;
case GL_UNSIGNED_INT_VEC2: r_Uniform2uiv(u->var, 1, v); break;
case GL_UNSIGNED_INT_VEC3: r_Uniform3uiv(u->var, 1, v); break;
case GL_UNSIGNED_INT_VEC4: r_Uniform4uiv(u->var, 1, v); break;
case GL_FLOAT_MAT2: r_UniformMatrix2fv(u->var, 1, GL_FALSE, f); break;
case GL_FLOAT_MAT3: r_UniformMatrix3fv(u->var, 1, GL_FALSE, f); break;
case GL_FLOAT_MAT4: r_UniformMatrix4fv(u->var, 1, GL_FALSE, f); break;
case GL_FLOAT_MAT2x3: r_UniformMatrix2x3fv(u->var, 1, GL_FALSE, f); break;
case GL_FLOAT_MAT3x2: r_UniformMatrix3x2fv(u->var, 1, GL_FALSE, f); break;
case GL_FLOAT_MAT2x4: r_UniformMatrix2x4fv(u->var, 1, GL_FALSE, f); break;
case GL_FLOAT_MAT4x2: r_UniformMatrix4x2fv(u->var, 1, GL_FALSE, f); break;
case GL_FLOAT_MAT3x4: r_UniformMatrix3x4fv(u->var, 1, GL_FALSE, f); break;
case GL_FLOAT_MAT4x3: r_UniformMatrix4x3fv(u->var, 1, GL_FALSE, f); break;
case GL_INT_VEC2: case GL_BOOL_VEC2: r_Uniform2iv(u->var, 1, iv); break;
case GL_INT_VEC3: case GL_BOOL_VEC3: r_Uniform3iv(u->var, 1, iv); break;
case GL_INT_VEC4: case GL_BOOL_VEC4: r_Uniform4iv(u->var, 1, iv); break;
default: r_Uniform1iv(u->var, 1, iv); break; // int, bool, samplers
}
}
for (int i = 0; i < p->nblocks; ++i) {
struct block *b = &p->blocks[i];
GLint binding = 0;
r_GetActiveUniformBlockiv(p->id, b->orig_index, GL_UNIFORM_BLOCK_BINDING, &binding);
if (binding != b->binding) {
r_UniformBlockBinding(p->twin, b->var_index, (GLuint)binding);
b->binding = binding;
}
}
}
// ---------------------------------------------------------------- per-thread state (a GL context is per thread)
#define FB_UNKNOWN (-1)
#define FB_NO_COLOR (-2)
static __thread struct prog *cur_prog;
static __thread int fb_views = FB_UNKNOWN; // views of the draw framebuffer's first color attachment (cached)
static int draw_fb_views(void) {
if (fb_views != FB_UNKNOWN) return fb_views;
GLint fb = 0;
r_GetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &fb);
if (!fb) return fb_views = 0; // the window surface
GLint type = GL_NONE;
r_GetFramebufferAttachmentParameteriv(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &type);
if (type == GL_NONE) return fb_views = FB_NO_COLOR; // depth-only: Mesa doesn't compare views
if (type != GL_TEXTURE) return fb_views = 0; // renderbuffer
GLint views = 0;
r_GetFramebufferAttachmentParameteriv(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_NUM_VIEWS_OVR, &views);
return fb_views = views;
}
// ---------------------------------------------------------------- statistics (per 5 s)
static unsigned long twin_draws, mv_draws;
static struct timespec last_stats;
static void stats(void) {
struct timespec now;
clock_gettime(CLOCK_MONOTONIC, &now);
if (!last_stats.tv_sec) last_stats = now;
if (now.tv_sec - last_stats.tv_sec < 5) return;
last_stats = now;
if (twin_draws || debug)
LOG("5s: %lu single-view draws of multiview programs, %lu multiview draws, %lu twin uniform updates",
twin_draws, mv_draws, uniform_sets);
twin_draws = mv_draws = uniform_sets = 0;
}
// Before a draw: bind the twin when the program is multiview and the framebuffer has no views. 1 = twin bound.
static int begin_draw(void) {
struct prog *p = cur_prog;
if (!p || !p->multiview || p->twin_failed) return 0;
int views = draw_fb_views();
if (views != 0) {
++mv_draws;
if (debug) stats();
return 0;
}
if (!p->twin && !build_twin(p)) return 0;
r_UseProgram(p->twin);
sync_uniforms(p);
if (debug) r_GetError(); // (debug only: this consumes an earlier error the game hasn't read)
return 1;
}
static void end_draw(const char *what) {
struct prog *p = cur_prog;
if (debug) {
static int logs;
GLenum err = r_GetError();
if (err && logs < 20) {
++logs;
LOG("%s with the twin of program %u: GL error 0x%x", what, p ? p->id : 0, err);
}
}
r_UseProgram(p ? p->id : 0);
++twin_draws;
stats();
}
// ---------------------------------------------------------------- exported GL functions
EXPORT void glUseProgram(GLuint program) {
INIT();
r_UseProgram(program);
cur_prog = program ? find_prog(program, 0) : NULL;
}
EXPORT void glLinkProgram(GLuint program) {
INIT();
note_program(program);
r_LinkProgram(program);
}
EXPORT void glDeleteProgram(GLuint program) {
INIT();
struct prog *p = program ? find_prog(program, 0) : NULL;
if (p) { // the record stays (pointers to it may be cached); a new program with this name relinks it
drop_twin(p);
drop_sources(p);
}
r_DeleteProgram(program);
}
EXPORT void glBindFramebuffer(GLenum target, GLuint framebuffer) {
INIT();
r_BindFramebuffer(target, framebuffer);
if (target != GL_READ_FRAMEBUFFER) fb_views = FB_UNKNOWN;
}
EXPORT void glDeleteFramebuffers(GLsizei n, const GLuint *framebuffers) {
INIT();
r_DeleteFramebuffers(n, framebuffers);
fb_views = FB_UNKNOWN;
}
EXPORT void glFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level) {
INIT();
r_FramebufferTexture2D(target, attachment, textarget, texture, level);
fb_views = FB_UNKNOWN;
}
EXPORT void glFramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum rbtarget, GLuint renderbuffer) {
INIT();
r_FramebufferRenderbuffer(target, attachment, rbtarget, renderbuffer);
fb_views = FB_UNKNOWN;
}
EXPORT void glFramebufferTextureLayer(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer) {
INIT();
r_FramebufferTextureLayer(target, attachment, texture, level, layer);
fb_views = FB_UNKNOWN;
}
EXPORT void glFramebufferTexture(GLenum target, GLenum attachment, GLuint texture, GLint level) {
INIT();
if (r_FramebufferTexture) r_FramebufferTexture(target, attachment, texture, level);
fb_views = FB_UNKNOWN;
}
EXPORT void glDrawBuffers(GLsizei n, const GLenum *bufs) {
INIT();
r_DrawBuffers(n, bufs);
fb_views = FB_UNKNOWN;
}
static void w_ftmv(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint base, GLsizei views) {
r_ftmv(target, attachment, texture, level, base, views);
fb_views = FB_UNKNOWN;
}
static void w_ftmsmv(GLenum target, GLenum attachment, GLuint texture, GLint level, GLsizei samples, GLint base,
GLsizei views) {
r_ftmsmv(target, attachment, texture, level, samples, base, views);
fb_views = FB_UNKNOWN;
}
#define DRAW(name, call) \
INIT(); \
if (!r_##name) return; \
if (begin_draw()) { \
r_##name call; \
end_draw("gl" #name); \
} else { \
r_##name call; \
}
EXPORT void glDrawArrays(GLenum mode, GLint first, GLsizei count) { DRAW(DrawArrays, (mode, first, count)) }
EXPORT void glDrawElements(GLenum mode, GLsizei count, GLenum type, const void *indices) {
DRAW(DrawElements, (mode, count, type, indices))
}
EXPORT void glDrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instances) {
DRAW(DrawArraysInstanced, (mode, first, count, instances))
}
EXPORT void glDrawElementsInstanced(GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei instances) {
DRAW(DrawElementsInstanced, (mode, count, type, indices, instances))
}
EXPORT void glDrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type,
const void *indices) {
DRAW(DrawRangeElements, (mode, start, end, count, type, indices))
}
EXPORT void glDrawArraysIndirect(GLenum mode, const void *indirect) { DRAW(DrawArraysIndirect, (mode, indirect)) }
EXPORT void glDrawElementsIndirect(GLenum mode, GLenum type, const void *indirect) {
DRAW(DrawElementsIndirect, (mode, type, indirect))
}
EXPORT void glDrawElementsBaseVertex(GLenum mode, GLsizei count, GLenum type, const void *indices, GLint base) {
DRAW(DrawElementsBaseVertex, (mode, count, type, indices, base))
}
EXPORT void glDrawRangeElementsBaseVertex(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type,
const void *indices, GLint base) {
DRAW(DrawRangeElementsBaseVertex, (mode, start, end, count, type, indices, base))
}
EXPORT void glDrawElementsInstancedBaseVertex(GLenum mode, GLsizei count, GLenum type, const void *indices,
GLsizei instances, GLint base) {
DRAW(DrawElementsInstancedBaseVertex, (mode, count, type, indices, instances, base))
}
// A context made current on this thread (engines with a render thread move theirs between threads, e.g. Doom3Quest's
// GLimp_ActivateContext): what this thread knew about the bound program and framebuffer may be another context's.
EXPORT EGLBoolean eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx) {
INIT();
if (!r_eglMakeCurrent) return EGL_FALSE;
EGLBoolean ok = r_eglMakeCurrent(dpy, draw, read, ctx);
fb_views = FB_UNKNOWN;
cur_prog = NULL;
if (ok && ctx != EGL_NO_CONTEXT && r_GetIntegerv) {
GLint program = 0;
r_GetIntegerv(GL_CURRENT_PROGRAM, &program);
cur_prog = program > 0 ? find_prog((GLuint)program, 0) : NULL;
}
return ok;
}
// Engines fetch the OVR multiview functions (and SDL-style loaders every function) through eglGetProcAddress.
EXPORT __eglMustCastToProperFunctionPointerType eglGetProcAddress(const char *name) {
INIT();
__eglMustCastToProperFunctionPointerType fn = r_eglGetProcAddress ? r_eglGetProcAddress(name) : NULL;
if (!fn || !name) return fn;
if (!strcmp(name, "glFramebufferTextureMultiviewOVR")) {
if (!r_ftmv) r_ftmv = (PFN_FTMV)fn;
return (__eglMustCastToProperFunctionPointerType)w_ftmv;
}
if (!strcmp(name, "glFramebufferTextureMultisampleMultiviewOVR")) {
if (!r_ftmsmv) r_ftmsmv = (PFN_FTMSMV)fn;
return (__eglMustCastToProperFunctionPointerType)w_ftmsmv;
}
#define OWN(sym) if (!strcmp(name, #sym)) return (__eglMustCastToProperFunctionPointerType)sym;
OWN(glUseProgram) OWN(glLinkProgram) OWN(glDeleteProgram) OWN(glBindFramebuffer) OWN(glDeleteFramebuffers)
OWN(glFramebufferTexture2D) OWN(glFramebufferRenderbuffer) OWN(glFramebufferTextureLayer)
OWN(glFramebufferTexture) OWN(glDrawBuffers) OWN(glDrawArrays) OWN(glDrawElements) OWN(glDrawArraysInstanced)
OWN(glDrawElementsInstanced) OWN(glDrawRangeElements) OWN(glDrawArraysIndirect) OWN(glDrawElementsIndirect)
OWN(glDrawElementsBaseVertex) OWN(glDrawRangeElementsBaseVertex) OWN(glDrawElementsInstancedBaseVertex)
OWN(eglMakeCurrent)
#undef OWN
return fn;
}
+87
View File
@@ -0,0 +1,87 @@
// SPDX-License-Identifier: GPL-3.0-only
// GLSL source rewrite for libfpglmv.so (see glmv.c): turns an OVR_multiview shader into its single-view twin.
// - every `layout(... num_views ...) in;` statement is blanked out (the program then declares no views, which is
// what Mesa requires for a draw into a framebuffer whose attachments aren't multiview)
// - every gl_ViewID_OVR token becomes (0u): view 0 (the left eye's matrices in Doom3Quest)
// #extension lines stay (the driver supports OVR_multiview; enabling it without a num_views layout is harmless).
// Columns and line numbers are kept (blanks pad the replacements), so compile logs point at the same places.
// Plain C, no GL: the host unit test (tests/fixtures/src/glmv_rewrite_test.c) compiles it too.
#pragma once
#include <stdlib.h>
#include <string.h>
static int glmv_ident_char(char c) {
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_';
}
// `word` at p as a whole token (not part of a longer identifier)
static int glmv_token_at(const char *start, const char *p, const char *word) {
size_t n = strlen(word);
if (strncmp(p, word, n) != 0) return 0;
if (p > start && glmv_ident_char(p[-1])) return 0;
return !glmv_ident_char(p[n]);
}
static const char *glmv_skip_ws(const char *p) {
while (*p == ' ' || *p == '\t' || *p == '\n' || *p == '\r' || *p == '\f' || *p == '\v') ++p;
return p;
}
// If a `layout(...num_views...) in;` statement starts at p, returns a pointer to its ';', else NULL.
static const char *glmv_num_views_stmt(const char *start, const char *p) {
if (!glmv_token_at(start, p, "layout")) return NULL;
const char *q = glmv_skip_ws(p + 6);
if (*q != '(') return NULL;
const char *open = q;
int depth = 0;
for (; *q; ++q) {
if (*q == '(') ++depth;
else if (*q == ')' && --depth == 0) break;
}
if (!*q) return NULL;
const char *close = q;
int has_views = 0;
for (const char *r = open + 1; r < close; ++r)
if (glmv_token_at(start, r, "num_views")) { has_views = 1; break; }
if (!has_views) return NULL;
q = glmv_skip_ws(close + 1);
if (!glmv_token_at(start, q, "in")) return NULL;
q = glmv_skip_ws(q + 2);
return *q == ';' ? q : NULL;
}
// 1 if the source declares multiview views (a vertex shader of an OVR_multiview program)
static int glmv_has_num_views(const char *src) {
for (const char *p = src; (p = strstr(p, "layout")); p += 6)
if (glmv_num_views_stmt(src, p)) return 1;
return 0;
}
// The single-view twin of `src` (malloc'd, same length), or NULL when out of memory. Counts go to *layouts / *ids.
static char *glmv_rewrite(const char *src, int *layouts, int *ids) {
static const char id_tok[] = "gl_ViewID_OVR"; // 13 characters
static const char zero[] = "(0u)";
size_t n = strlen(src);
char *out = (char *)malloc(n + 1);
if (!out) return NULL;
memcpy(out, src, n + 1);
int nl = 0, ni = 0;
for (char *p = out; (p = strstr(p, "layout"));) {
const char *semi = glmv_num_views_stmt(out, p);
if (!semi) { p += 6; continue; }
for (char *b = p; b <= semi; ++b)
if (*b != '\n' && *b != '\r') *b = ' ';
++nl;
p = (char *)semi + 1;
}
for (char *p = out; (p = strstr(p, id_tok));) {
if (!glmv_token_at(out, p, id_tok)) { p += sizeof(id_tok) - 1; continue; }
memcpy(p, zero, sizeof(zero) - 1);
memset(p + sizeof(zero) - 1, ' ', sizeof(id_tok) - sizeof(zero));
++ni;
p += sizeof(id_tok) - 1;
}
if (layouts) *layouts = nl;
if (ids) *ids = ni;
return out;
}
+211
View File
@@ -0,0 +1,211 @@
# Shared hardware video decoding for Lepton
`frameport_hevc.cpp` implements Android OMX decoders for HEVC Main, H.264
(Constrained) Baseline/Main/(Constrained) High and VP9 Profile 0 using Iris
stateful V4L2 through FFmpeg. Android reports constrained H.264 streams under
separate profile values, so they are listed as stock decoders list them.
These are 8-bit 4:2:0 decoders. Format-aware clients keep Android's existing
codecs for Main10/HDR and protected content; clients selecting by MIME alone
must still respect the component's advertised profiles. Other codec types
retain Android's existing codecs. Applications that explicitly select their
own software decoder bypass this integration. Byte-buffer clients receive full-size
planar frames. Native surface clients receive YUV in Android hardware buffers,
with acquire/release fences. For large hardware-decoded NV12 surfaces (at least
4096×2048 pixels), compatible linear NV12 buffers are imported into Vulkan
and copied on the GPU without CPU pixel access or colour conversion. The decoded
AVFrame remains held until the transfer fence completes, preventing its Iris
capture buffer from being requeued. Explicit FOREIGN queue-family transfers
return both buffers to their Android/decoder owners before delivery. Imports are
cached within a bounded pool and cleared before decoder reconfiguration or flush.
Unsupported layouts, unavailable Vulkan capabilities and import failures retain
the parallel CPU copy; a submitted transfer that fails to complete reports an
OMX error instead of exposing incomplete pixels. This removes the CPU frame copy
on compatible surfaces but still performs one GPU copy; it is not direct decoding
into Android's consumer buffers. Small surfaces use disjoint parallel CPU row bands.
The same persistent worker pool handles native YUV copies, byte-buffer planar
copies and legacy RGBA conversion (helpers start at panorama sizes); all workers finish before the buffer is unlocked or the decoded
frame is released. Legacy software surfaces
retain parallel NEON RGBA conversion. Input timestamps, dynamic dimensions, EOS and
seek/flush are preserved.
This uses the tested Lepton Android 11 SoftOMX ABI. On connection, FramePort
deploys the plugin, codec XML and Podman wrapper once into the agent's shared
`~/.local/share/frameport/video-codec/versions/<manifest-sha256>` store.
Payload checksums are verified before an atomic `current` symlink exposes the
complete version. Older clients cannot downgrade a newer codec revision.
A Frame keeps an installed codec of the same or a newer manifest `revision`
(two PCs with different builds of one revision don't replace each other's), so
`build.py` bumps the revision with every change. A failed install is not
retried during the same connection.
Superseded versions are pruned, keeping the active version and the one it
replaced (a launch that resolved the previous `current` can still mount it).
Games opt in through their recipe: the patch `frame.hw_video_decode` (no APK
change; suggested when the APK decodes video through MediaCodec, ExoPlayer or
VLC) makes the agent give that game's launcher the line that puts the shared
wrapper first on Lepton's PATH (`deployment.json` `hw_video_decode`;
`upgrade_launchers` adds or removes it on existing launchers). Only that game's
matching `podman run` gains a read-only plugin/XML mount and `/dev/video-dec0`.
All other Podman operations pass through. FramePort's setting "Hardware video
decoding" turns it off for every game (`video-codec/disabled`, checked by the
launcher line and the wrapper at every start); `FRAMEPORT_NO_HW_VIDEO=1` in a
game's Steam launch options turns it off for that game. Shared Lepton, drivers and original MP4 assets are unchanged.
Unknown runtime ABIs retain the stock codecs and log why. A future native
Lepton hardware plugin takes precedence.
The wrapper resolves a fallback Podman from PATH outside its own directory
before reading deployment configuration. Lepton's Android-only `env -i PATH`
attach commands use host default paths if their PATH contains no host Podman.
Missing/malformed configuration,
recursive executable paths, mount-preparation errors and failed exec calls
retain the original arguments and launch stock Podman. The agent publishes
`deployment.json` and codec payloads before exposing the complete version.
The merged runtime XML is written to `$XDG_RUNTIME_DIR/frameport-video/`
(never into the verified version directory), named per runtime path, with
process-local temporary filenames, so concurrent app launches do not overwrite
each other's staging.
No package check or MP4 scan selects decoding: the recipe does. Older embedded
codec assets are removed when an APK is rebuilt, and agent 70's per-game
`<base>/frameport-codec` folders are removed once the launcher is converted (a
game that had one, Batman, keeps hardware decoding). The
codec has no OpenXR calls, camera poses or composition changes. Batman's
`surface_native` renderer remains package-scoped and separate. Other apps keep
their existing rendering path; hardware decoding alone does not eliminate
surface upload/conversion or GPU rendering bottlenecks.
The plugin enumerates coded formats and probes each at 1920x1080, not Batman's
8K geometry. Unavailable components are omitted so Android retains its stock
decoders. Actual-session admission can still fail (including Iris's concurrent
session-accounting issue: while any other decoder session is open, 8K is
refused with ENOMEM). SteamVR's link (`vrlinkrunthread`) holds a session for
about 12 s around every game start, when the plugin loads too (measured on the
dev Frame, 2026-10-09), so a refused session is retried every 250 ms until 20 s
after the plugin loaded (later: for 2 s); initialization then falls back to
FFmpeg software decoding inside the already-selected component. VP9 is limited
to 4096x2304 (codec list and component; larger VP9 decodes in software): at
7680x3840 Iris accepted the session but never returned a picture. For every
VP9 frame that isn't shown (alt-ref/hidden frames split from superframes) Iris
returns an empty capture buffer (bytesused 0, no LAST flag, time 0). FFmpeg's
wrapper returned those as pictures and, during the EOS drain, took the first one
for the end of the stream, losing the pictures still in the driver (two-pass
VP9 at 4K: 573 of 600 frames, measured 2026-10-10). `build.py` makes the wrapper
requeue empty non-LAST buffers instead; the drain ends at the LAST buffer, or
after a skipped empty buffer at one silent second, so a driver that ends a drain
with an empty unflagged buffer cannot block. This preserves the client's
buffer/surface contract without requiring the app to retry another codec.
During hardware playback, bounded references to two GOPs of compressed packets
permit software recovery after a driver-reported damaged picture. Replay drops
already-presented timestamps, retaining ordered output and EOS. The cache is
capped at 64 MiB/512 packets; if no usable keyframe remains, ordinary OMX error
handling applies. After recovery, later seeks flush the software decoder for
that component until reset. This is a fallback, not a repair to the Iris driver. VP9 seek tests
on this Frame exercised it. Capture buffers use FFmpeg's general-purpose budget
of 20 at ordinary sizes, which avoids the stall observed with the earlier
four-buffer H.264 configuration. At panorama sizes the budget follows the
standards' reference-picture bound plus four (10 at 8K HEVC/H.264, 13 for VP9),
instead of holding about 1 GB of 8K capture memory. Only hardware-reported
damage triggers recovery; software decoders conceal damage themselves and their
pictures are output, as Android's stock decoders do.
A seek after the stream has fully drained (replay or loop after EOS) restarts
the open hardware session in place with `V4L2_DEC_CMD_START`, keeping its
buffers; this works for all three codecs. The component checks the restart
result through a read-only FFmpeg option. A failed restart closes that session
and continues in software, rather than waiting indefinitely for hardware
output. A seek during playback reopens the
hardware session: on the tested Iris kernel, stopping and restarting a running
session's queues failed the driver's session admission ("current session not
supported", -12) and left buffers unreturned (videobuf2 kernel warnings), so it
is not used. On the same kernel, reopening VP9 after a seek produced a damaged
capture picture and a kernel fault in `lookup_swap_cgroup_id` during unmap, so
VP9 switches to software on a seek during playback rather than reopening that
hardware session; H.264 and HEVC retain hardware decoding after seeking.
This compatibility guard is independent of app/package identity.
Android CODECCONFIG parameter sets are prepended to the first H.264/HEVC
hardware access unit because FFmpeg's V4L2 wrapper does not submit extradata
to the driver. Parameter sets sent again mid-stream without a flush (streaming
apps, restarted encoders) replace the stored configuration and are submitted
in-band before the next access unit, rather than failing the session. Complete-frame parsers identify keyframes for bounded recovery,
including ACodec clients that omit the OMX input SYNCFRAME flag.
On the tested headset, disabling **hardware video decoding in Steam's interface**
and restarting Steam removed that conflicting session. This setting does not
disable the game's Iris decoder. It is a SteamOS-driver workaround, not a kernel
fix; FramePort does not silently change the global Steam setting.
Signalled bitstream colour (primaries, transfer, matrix, range) is reported to
ACodec as Android's stock decoders do, so the surface dataspace can follow it;
container values take precedence. Legacy RGBA conversion uses the resulting
matrix, BT.709 for unsignalled HD (Android's convention), and full-range BT.601
or BT.709 where signalled. A full-range BT.709 table matches the pinned Arm64
libyuv ABI. Both hardware NV12 and software planar conversions produce RGBA
channel order; native YUV output retains its original planes and dataspace.
Batman's native surface renderer and stereo composition are documented in
[Surface video playback](../../docs/SURFACE_VIDEO.md). The original decoded
panorama is retained; projected eye views are generated on the GPU.
Build on Linux/WSL with Android NDK r27c and the tested Lepton rootfs:
```
python native/hevc/build.py --ndk /path/to/android-ndk-r27c --lepton-root /path/to/Lepton/images/rootfs
```
Paths with spaces work: the builder links the repo, the NDK and the rootfs into
a space-free temp dir and compiles through those link paths (FFmpeg's configure
splits `--extra-cflags` on whitespace); with `-no-canonical-prefixes` clang keeps
the link path too, so the prefix maps give the same bytes wherever the real
folders are. Each build starts from freshly extracted FFmpeg sources.
The build requires Linux x86-64, Python 3.12+, Make, Perl, and a working host C
compiler with libc development headers (FFmpeg builds host tools). The NDK
revision is checked against `27.2.12479018`. Previous FFmpeg objects and install
output are discarded. Both FFmpeg and the plugin use that NDK's compiler and
linker. A private copy of its libc++ headers uses Android's platform `__1`
namespace; `-nostdinc++` prevents mixing these with the NDK's `__ndk1` headers.
The build uses libc++'s verbose-abort customization hook to avoid a newer NDK
abort symbol absent from Android 11's platform runtime. It does not edit the NDK
or ship a second libc++.
Compiler file-prefix maps cover source, NDK and runtime paths. FFmpeg's
generated configuration string is normalized separately because it embeds
literal configure arguments. The manifest records the NDK revision and source
checksum. Two clean builds in different directories produced the same codec
binary SHA256; `.comment` identifies NDK Clang/LLD 18.0.3 throughout. The rebuilt
plugin also passed 600 original 8K frames, a flush/seek, 120 replayed frames and
clean shutdown in an isolated headset container.
AOSP headers in `platform/` come from `android-11.0.0_r48` and retain their
original license notices. `fetch_headers.py` records the upstream paths.
The builder downloads the pinned FFmpeg 7.1.1 archive from
https://ffmpeg.org/releases/ffmpeg-7.1.1.tar.xz and verifies SHA256
`733984395e0dbbe5c046abda2dc49a5544e7e0e1e2366bba849222ae9e3a03b1`.
`build.py` applies explicit wrapper changes: VP9 V4L2 uses the same
`vp9_superframe_split` input filter as the software decoder, empty non-LAST
capture buffers (hidden VP9 frames) are requeued rather than output or taken
for the end of a drain, and the V4L2
decoder gains a flush callback that restarts a drained decoder in place
(`V4L2_DEC_CMD_START` with both queues still streaming). Its read-only
`frameport_flush_error` option reports failed or premature restarts to the
component, because `avcodec_flush_buffers` itself has no return value.
Without it a restart after EOS could only close and reopen the hardware
session. `v4l2_export.c.inc` adds a capture-buffer export interface inside FFmpeg,
so the component does not access FFmpeg's private buffer structures. The caller
must retain the AVFrame until GPU work completes. Its LGPL build
configuration and those source changes are recorded in the builder. The license
is included in the shared version directory as `COPYING.FFmpeg`.
`omx_decode_probe.cpp` and `media_codec_probe.cpp` exercise decoder selection,
original-size output, timestamps, flush/seek, EOS and teardown on the headset.
The OMX probe's `restartfail` mode uses the fault shim in
`tests/fixtures/src/video_codec_faults.c` to reject a drained-session restart;
`software_rgba` exercises software fallback and legacy surface conversion
together. `color_probe.cpp` compares both platform NEON conversion paths with
the full-range BT.709 equations, including channel order and extreme values.
The OMX probe's `native` mode hashes original-size Android YUV buffers and checks
GPU submissions and replayed pixels. `native_cpu` disables Vulkan initialization;
`native_importfail` rejects memory imports. Both verify fallback preserves the
same surface contract and pixels without GPU submissions.
The native surface fixtures cover buffer ownership, GPU projection and
composition. See the surface documentation for validation and limitations.
+262
View File
@@ -0,0 +1,262 @@
#!/usr/bin/env python3
"""Build the Android media-service plugin on Linux with NDK r27c and a Lepton rootfs.
The runtime's private SoftOMX ABI is deliberately pinned. This plugin is mounted
only when the tested library fingerprint matches; it never replaces system files.
"""
import argparse
import hashlib
import json
import os
import shutil
import subprocess
import tarfile
import tempfile
import urllib.request
from pathlib import Path
HERE = Path(__file__).resolve().parent
ARTIFACTS = HERE.parents[1] / "artifacts/hevc"
FFMPEG_SHA = "733984395e0dbbe5c046abda2dc49a5544e7e0e1e2366bba849222ae9e3a03b1"
RUNTIME_SHA = "456e912c75cd389abcf6a63bc80e2a53bdc334371d00b200c93680388ae955e2"
NDK_REVISION = "27.2.12479018"
FLUSH_SOURCE = r"""static void v4l2_flush(AVCodecContext *avctx)
{
V4L2m2mPriv *priv = avctx->priv_data;
V4L2m2mContext *s = priv->context;
struct v4l2_decoder_cmd cmd = { .cmd = V4L2_DEC_CMD_START };
av_packet_unref(&s->buf_pkt);
priv->frameport_flush_error = 0;
/* Only a drained decoder restarts in place: it has returned every picture
* and is stopped until V4L2_DEC_CMD_START (both queues keep streaming).
* Restarting a running decoder's queues failed Iris session admission and
* left its buffers unreturned (kernel warnings): callers reopen instead. */
if (!s->draining || !s->capture.done) {
priv->frameport_flush_error = AVERROR(EINVAL);
av_log(avctx, AV_LOG_WARNING, "flush before the drain completed; reopen the decoder\n");
return;
}
if (ioctl(s->fd, VIDIOC_DECODER_CMD, &cmd) < 0) {
priv->frameport_flush_error = AVERROR(errno);
av_log(avctx, AV_LOG_ERROR, "V4L2_DEC_CMD_START after drain: %s\n", av_err2str(priv->frameport_flush_error));
return;
}
s->draining = 0;
s->output.done = s->capture.done = 0;
}
"""
# Iris returns an empty capture buffer (bytesused 0, no LAST flag) for every
# VP9 frame that isn't shown (alt-ref/hidden frames split from superframes).
# FFmpeg's wrapper took any empty buffer during a drain for the end of the
# stream, so the pictures still in the driver after EOS were lost (two-pass VP9:
# 573 of 600), and outside a drain it returned them as pictures without content.
# Requeue them instead; the drain still ends at the LAST buffer (or EPIPE), and
# after a skipped empty buffer a silent second ends it too, so a driver that
# ends a drain with an empty buffer and no LAST flag cannot block the caller.
EMPTY_DECLARE = " .fd = ctx_to_m2mctx(ctx)->fd,\n };\n int i, ret;\n"
EMPTY_POLL = """ for (;;) {
ret = poll(&pfd, 1, timeout);
if (ret > 0)
break;
if (errno == EINTR)
continue;
return NULL;
}
"""
EMPTY_DRAIN = """ if (ctx_to_m2mctx(ctx)->draining && !V4L2_TYPE_IS_OUTPUT(ctx->type)) {
int bytesused"""
EMPTY_SKIP = """ if (!V4L2_TYPE_IS_OUTPUT(ctx->type) && ctx->buffers && buf.index < ctx->num_buffers &&
!(V4L2_TYPE_IS_MULTIPLANAR(buf.type) ? buf.m.planes[0].bytesused : buf.bytesused) &&
!(buf.flags & (V4L2_BUF_FLAG_LAST | V4L2_BUF_FLAG_ERROR))) {
/* an empty picture that doesn't end the stream (Iris: a hidden VP9 frame) */
if (ff_v4l2_buffer_enqueue(&ctx->buffers[buf.index]) < 0) {
ctx->done = 1;
return NULL;
}
skipped_empty = 1;
goto start;
}
"""
def skip_empty_pictures(context_text: str) -> str:
"""libavcodec/v4l2_context.c with empty non-LAST capture buffers requeued (see EMPTY_SKIP)."""
if any(context_text.count(text) != 1 for text in (EMPTY_DECLARE, EMPTY_POLL, EMPTY_DRAIN)):
raise RuntimeError("unexpected FFmpeg V4L2 context source")
return (context_text
.replace(EMPTY_DECLARE, EMPTY_DECLARE.replace("int i, ret;", "int i, ret, skipped_empty = 0;"))
.replace(EMPTY_POLL, EMPTY_POLL.replace(
" ret = poll(&pfd, 1, timeout);\n if (ret > 0)\n break;\n",
" ret = poll(&pfd, 1, skipped_empty && ctx_to_m2mctx(ctx)->draining &&\n"
" (timeout < 0 || timeout > 1000) ? 1000 : timeout);\n"
" if (ret > 0)\n break;\n"
" if (!ret && skipped_empty && ctx_to_m2mctx(ctx)->draining) {\n"
" ctx->done = 1;\n return NULL;\n }\n"))
.replace(EMPTY_DRAIN, EMPTY_SKIP + EMPTY_DRAIN))
def run(args, cwd=None, env=None):
# PWD keeps the shell's (and FFmpeg configure's) idea of the directory on the space-free link path
env = dict(env or os.environ, **({"PWD": str(cwd)} if cwd else {}))
subprocess.run([str(a) for a in args], check=True, cwd=cwd, env=env)
def space_free(links: Path, name: str, target: Path) -> Path:
"""FFmpeg's configure splits --extra-cflags on whitespace, so a repo/NDK/rootfs path with spaces breaks the
build. Build through unresolved symlinks in a space-free temp dir; the prefix maps name these link paths, so the
output is the same bytes wherever the real folders are."""
link = links / name
link.symlink_to(target, target_is_directory=True)
return link
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--ndk", type=Path, required=True)
parser.add_argument("--lepton-root", type=Path, required=True)
args = parser.parse_args()
ndk_root = args.ndk.resolve()
if not any(line.strip() == f"Pkg.Revision = {NDK_REVISION}"
for line in (ndk_root / "source.properties").read_text().splitlines()):
parser.error(f"use Android NDK r27c ({NDK_REVISION})")
ndk = ndk_root / "toolchains/llvm/prebuilt/linux-x86_64"
if not (ndk / "bin/clang++").exists():
parser.error("use the Linux NDK r27c (Windows: run this builder inside WSL)")
runtime = args.lepton_root.resolve()
with tempfile.TemporaryDirectory(prefix="fp-hevc-") as tmp:
links = Path(tmp)
if any(c.isspace() for c in str(links)):
parser.error(f"temp dir {links} has spaces: set TMPDIR to a folder without spaces")
build(parser, space_free(links, "repo", HERE.parents[1]), space_free(links, "ndk", ndk_root),
space_free(links, "rootfs", runtime))
def build(parser, repo: Path, ndk_root: Path, runtime: Path):
here = repo / HERE.relative_to(HERE.parents[1])
artifacts = repo / ARTIFACTS.relative_to(HERE.parents[1])
ndk = ndk_root / "toolchains/llvm/prebuilt/linux-x86_64"
if hashlib.sha256((runtime / "vendor/lib64/libstagefright_softomx.so").read_bytes()).hexdigest() != RUNTIME_SHA:
parser.error("unverified SoftOMX ABI; validate and update the fingerprint before rebuilding")
cache = here.parent / ".cache/hevc"
cache.mkdir(parents=True, exist_ok=True)
archive = cache / "ffmpeg-7.1.1.tar.xz"
if not archive.exists():
urllib.request.urlretrieve("https://ffmpeg.org/releases/ffmpeg-7.1.1.tar.xz", archive)
if hashlib.sha256(archive.read_bytes()).hexdigest() != FFMPEG_SHA:
raise RuntimeError("FFmpeg source checksum mismatch")
source = cache / "ffmpeg-7.1.1"
install = cache / "ffmpeg-install"
# Discard previous objects/configuration so a host compiler or changed
# configure flags cannot silently survive a rebuild (a distclean keyed on
# config.mak never ran: FFmpeg 7 keeps it in ffbuild/), and start from
# unpatched sources (the edits below are applied once).
for old in (source, install):
if old.exists():
shutil.rmtree(old)
with tarfile.open(archive) as tar:
tar.extractall(cache, filter="data")
# Unlike FFmpeg's software VP9 decoder, its V4L2 wrapper does not split
# packed VP9 superframes. Iris requires the same individual-frame input.
decoder_source = source / "libavcodec/v4l2_m2m_dec.c"
decoder_text = decoder_source.read_text()
original_vp9 = 'M2MDEC(vp9, "VP9", AV_CODEC_ID_VP9, NULL);'
if decoder_text.count(original_vp9) != 1:
raise RuntimeError("unexpected FFmpeg VP9 wrapper source")
decoder_text = decoder_text.replace(original_vp9, 'M2MDEC(vp9, "VP9", AV_CODEC_ID_VP9, "vp9_superframe_split");')
# The wrapper has no flush callback, so restarting after EOS (replay, loop)
# could only close and reopen the hardware session. Add the stateful
# decoder's restart after a completed drain (V4L2_DEC_CMD_START).
close_fn = "static av_cold int v4l2_decode_close(AVCodecContext *avctx)\n"
close_cb = " .close = v4l2_decode_close, \\\n"
if decoder_text.count(close_fn) != 1 or decoder_text.count(close_cb) != 1:
raise RuntimeError("unexpected FFmpeg V4L2 decoder source")
decoder_text = decoder_text.replace(close_fn, FLUSH_SOURCE + "\n" + close_fn).replace(
close_cb, close_cb + " .flush = v4l2_flush, \\\n")
decoder_source.write_text(decoder_text)
# avcodec_flush_buffers has no return value. Expose restart status through
# an AVOption rather than having the OMX component inspect private structs.
private_header = source / "libavcodec/v4l2_m2m.h"
private_text = private_header.read_text()
field = " int num_capture_buffers;\n} V4L2m2mPriv;"
option_end = " { NULL},\n};"
if private_text.count(field) != 1 or decoder_text.count(option_end) != 1:
raise RuntimeError("unexpected FFmpeg V4L2 private options source")
private_header.write_text(private_text.replace(field, " int num_capture_buffers;\n"
" int frameport_flush_error;\n} V4L2m2mPriv;"))
decoder_source.write_text(decoder_text.replace(option_end,
' { "frameport_flush_error", "Last drained-session restart error",\n'
' OFFSET(frameport_flush_error), AV_OPT_TYPE_INT, {.i64 = 0}, INT_MIN, 0,\n'
' FLAGS | AV_OPT_FLAG_READONLY },\n' + option_end))
context_source = source / "libavcodec/v4l2_context.c"
context_source.write_text(skip_empty_pictures(context_source.read_text()))
buffers_source = source / "libavcodec/v4l2_buffers.c"
buffers_source.write_text(buffers_source.read_text() + (here / "v4l2_export.c.inc").read_text())
env = dict(os.environ, PATH=str(ndk / "bin") + os.pathsep + os.environ["PATH"])
prefix_maps = [f"-ffile-prefix-map={repo}=.", f"-ffile-prefix-map={ndk_root}=android-ndk-r27c",
f"-ffile-prefix-map={runtime}=lepton-rootfs",
# clang otherwise resolves its own path (through the link) and embeds its real include dir
"-no-canonical-prefixes"]
run([
source / "configure", f"--prefix={install}", "--target-os=android", "--arch=aarch64",
"--enable-cross-compile", "--cc=aarch64-linux-android30-clang", "--cxx=aarch64-linux-android30-clang++",
"--ld=aarch64-linux-android30-clang", "--ar=llvm-ar", "--nm=llvm-nm", "--ranlib=llvm-ranlib",
"--extra-cflags=" + " ".join(prefix_maps),
"--extra-cxxflags=" + " ".join(prefix_maps),
"--disable-everything", "--disable-autodetect", "--enable-v4l2-m2m", "--disable-programs",
"--disable-doc", "--enable-pic", "--enable-static", "--disable-shared",
"--enable-decoder=hevc_v4l2m2m,h264_v4l2m2m,vp9_v4l2m2m,hevc,h264,vp9",
"--enable-parser=hevc,h264,vp9", "--enable-bsf=hevc_mp4toannexb,h264_mp4toannexb,vp9_superframe_split",
"--enable-demuxer=mov,matroska", "--enable-protocol=file", "--enable-avcodec", "--enable-avformat",
"--enable-avutil", "--disable-avdevice", "--disable-avfilter", "--disable-swscale",
"--disable-swresample", "--disable-postproc",
], cwd=source, env=env)
# FFmpeg embeds its configure command as a runtime diagnostic string.
# Prefix-map flags cannot rewrite string literals, so normalize that
# generated string too, retaining the options without host paths.
config = source / "config.h"
text = config.read_text()
for path, replacement in ((ndk_root, "android-ndk-r27c"), (runtime, "lepton-rootfs"), (repo, ".")):
text = text.replace(str(path), replacement)
config.write_text(text)
run(["make", f"-j{os.cpu_count() or 4}"], cwd=source, env=env)
run(["make", "install"], cwd=source, env=env)
# Use the platform libc++ namespace. Do not change the NDK's own headers or
# distribute another libc++, which would create a conflicting private ABI.
cpp = cache / "cpp"
shutil.copytree(ndk / "sysroot/usr/include/c++/v1", cpp, dirs_exist_ok=True)
site = cpp / "__config_site"
site.write_text(site.read_text().replace("_LIBCPP_ABI_NAMESPACE __ndk1", "_LIBCPP_ABI_NAMESPACE __1"))
artifacts.mkdir(parents=True, exist_ok=True)
run([
ndk / "bin/aarch64-linux-android30-clang++", "-std=gnu++17", "-O3", "-fPIC", "-shared",
*prefix_maps,
"-fno-rtti", "-fno-exceptions", "-nostdlib++", "-nostdinc++", "-Wall", "-Wextra", "-Werror",
"-D_LIBCPP_VERBOSE_ABORT(...)=__builtin_abort()",
"-Wno-unused-private-field", "-isystem", cpp, "-I", here / "platform",
"-I", here / "platform/media/openmax", "-I", install / "include", here / "frameport_hevc.cpp",
"-L", install / "lib", "-lavcodec", "-lavutil", "-L", runtime / "vendor/lib64",
"-L", runtime / "system/lib64", "-lstagefright_softomx", "-lstagefright_foundation", "-lutils",
"-llog", "-lnativewindow", "-lyuv", "-lvulkan", "-l:libc++.so", "-lm", "-ldl", "-Wl,--no-undefined",
"-Wl,-z,max-page-size=16384",
"-Wl,-soname,libstagefrighthw.so", "-o", artifacts / "libstagefrighthw.so",
], env=env)
for name in ("podman.py", "media_codecs_frameport.xml"):
shutil.copyfile(here / name, artifacts / (name + ".txt" if name == "podman.py" else name))
shutil.copyfile(source / "COPYING.LGPLv2.1", artifacts / "COPYING.FFmpeg")
files = {}
for name in ("libstagefrighthw.so", "podman.py", "media_codecs_frameport.xml", "COPYING.FFmpeg"):
path = artifacts / (name + ".txt" if name == "podman.py" else name)
files[name] = hashlib.sha256(path.read_bytes()).hexdigest()
# bump the revision with every change: a Frame keeps an installed codec of the same or a newer revision
manifest = {"revision": 8, "runtime_sha256": RUNTIME_SHA, "files": files,
"codecs": ["video/hevc", "video/avc", "video/x-vnd.on2.vp9"],
"build": {"ndk_revision": NDK_REVISION, "ffmpeg_source_sha256": FFMPEG_SHA}}
(artifacts / "manifest.json").write_text(json.dumps(manifest, indent=2) + "\n")
if __name__ == "__main__":
main()
+36
View File
@@ -0,0 +1,36 @@
// SPDX-License-Identifier: GPL-3.0-only
// Compare the actual platform NEON row functions with the full-range BT.709
// equations, including shadows/highlights and RGBA channel order in both paths.
#include "yuv_color.h"
#include <cassert>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <initializer_list>
extern "C" {
void NV21ToARGBRow_Any_NEON(const uint8_t*,const uint8_t*,uint8_t*,const YuvConstants*,int);
void I422ToARGBRow_Any_NEON(const uint8_t*,const uint8_t*,const uint8_t*,uint8_t*,const YuvConstants*,int);
}
static int clipped(double v) {int n=(int)std::lround(v);return n<0?0:n>255?255:n;}
int main() {
unsigned checked=0;
for(unsigned width : {2u,8u,18u})
for(int y : {0,8,16,64,128,235,247,255})
for(int u : {16,64,128,192,240})
for(int v : {16,64,128,192,240}) {
uint8_t yy[32],uu[16],vv[16],uv[32],nv[128],planar[128];
memset(yy,y,sizeof yy);memset(uu,u,sizeof uu);memset(vv,v,sizeof vv);
for(unsigned i=0;i<width/2;i++){uv[2*i]=u;uv[2*i+1]=v;}
NV21ToARGBRow_Any_NEON(yy,uv,nv,&frameport_full709_rgba,width);
I422ToARGBRow_Any_NEON(yy,vv,uu,planar,&frameport_full709_rgba,width);
int expected[]={clipped(y+1.5748*(v-128)),clipped(y-0.187324*(u-128)-0.468124*(v-128)),
clipped(y+1.8556*(u-128)),255};
for(unsigned x=0;x<width;x++)for(unsigned c=0;c<4;c++) {
assert(nv[4*x+c]==planar[4*x+c]);
assert(std::abs((int)nv[4*x+c]-expected[c])<=2);
if(u==128 && v==128 && c<3)assert(nv[4*x+c]==y);
}
checked++;
}
printf("PASS: %u full-range BT.709 colour/width combinations, planar and NV12 RGBA\n",checked);
}
+139
View File
@@ -0,0 +1,139 @@
// SPDX-License-Identifier: GPL-3.0-only
// Import linear decoder/Android DMA buffers. Ownership returns to the foreign
// producer/consumer before the completed fence permits either buffer to move.
#pragma once
#include <vulkan/vulkan.h>
#include <unistd.h>
#include <sys/stat.h>
#include <cstdio>
#include <cstring>
#include <vector>
class FramePortDmaCopy {
VkInstance instance=VK_NULL_HANDLE;
VkPhysicalDevice physical=VK_NULL_HANDLE;
VkDevice device=VK_NULL_HANDLE;
VkQueue queue=VK_NULL_HANDLE;
VkCommandPool pool=VK_NULL_HANDLE;
VkCommandBuffer command=VK_NULL_HANDLE;
VkFence completed=VK_NULL_HANDLE;
uint32_t family=0;
PFN_vkGetMemoryFdPropertiesKHR properties=nullptr;
struct Buffer {VkBuffer buffer=VK_NULL_HANDLE;VkDeviceMemory memory=VK_NULL_HANDLE;};
struct Entry {dev_t device;ino_t inode;VkBufferUsageFlags usage;Buffer imported;};
std::vector<Entry> cache;
bool attempted=false,ready=false,unsafe=false;
template<class T>static T info(VkStructureType type){T value={};value.sType=type;return value;}
bool check(VkResult r,const char *where){if(r!=VK_SUCCESS)ALOGW("GPU video %s: %d",where,r);return r==VK_SUCCESS;}
bool import(int fd,VkBufferUsageFlags usage,Buffer &out) {
struct stat st={};if(fstat(fd,&st)||st.st_size<=0)return false;
auto query=info<VkPhysicalDeviceExternalBufferInfo>(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_BUFFER_INFO);
query.usage=usage;query.handleType=VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT;
auto caps=info<VkExternalBufferProperties>(VK_STRUCTURE_TYPE_EXTERNAL_BUFFER_PROPERTIES);
vkGetPhysicalDeviceExternalBufferProperties(physical,&query,&caps);
if(!(caps.externalMemoryProperties.externalMemoryFeatures&VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT))return false;
auto external=info<VkExternalMemoryBufferCreateInfo>(VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_BUFFER_CREATE_INFO);
external.handleTypes=query.handleType;
auto create=info<VkBufferCreateInfo>(VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO);create.pNext=&external;
create.size=st.st_size;create.usage=usage;create.sharingMode=VK_SHARING_MODE_EXCLUSIVE;
if(!check(vkCreateBuffer(device,&create,nullptr,&out.buffer),"create buffer"))return false;
VkMemoryRequirements needs;vkGetBufferMemoryRequirements(device,out.buffer,&needs);
auto fdprops=info<VkMemoryFdPropertiesKHR>(VK_STRUCTURE_TYPE_MEMORY_FD_PROPERTIES_KHR);
if(!check(properties(device,query.handleType,fd,&fdprops),"fd properties"))return false;
uint32_t bits=needs.memoryTypeBits&fdprops.memoryTypeBits;
if(!bits || needs.size>(VkDeviceSize)st.st_size){ALOGW("GPU import layout mismatch: size %llu/%lld bits %#x",
(unsigned long long)needs.size,(long long)st.st_size,bits);return false;}
auto imported=info<VkImportMemoryFdInfoKHR>(VK_STRUCTURE_TYPE_IMPORT_MEMORY_FD_INFO_KHR);
imported.handleType=query.handleType;imported.fd=dup(fd);if(imported.fd<0)return false;
auto dedicated=info<VkMemoryDedicatedAllocateInfo>(VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO);
dedicated.buffer=out.buffer;
if(caps.externalMemoryProperties.externalMemoryFeatures&VK_EXTERNAL_MEMORY_FEATURE_DEDICATED_ONLY_BIT)imported.pNext=&dedicated;
auto allocate=info<VkMemoryAllocateInfo>(VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO);allocate.pNext=&imported;
allocate.allocationSize=st.st_size;allocate.memoryTypeIndex=__builtin_ctz(bits);
if(!check(vkAllocateMemory(device,&allocate,nullptr,&out.memory),"import memory")){close(imported.fd);return false;}
return check(vkBindBufferMemory(device,out.buffer,out.memory,0),"bind buffer");
}
void release(Buffer &b){if(b.buffer)vkDestroyBuffer(device,b.buffer,nullptr);if(b.memory)vkFreeMemory(device,b.memory,nullptr);b={};}
bool cached(int fd,VkBufferUsageFlags usage,Buffer &out){
struct stat st={};if(fstat(fd,&st))return false;
for(auto &e:cache)if(e.device==st.st_dev&&e.inode==st.st_ino&&e.usage==usage){out=e.imported;return true;}
Buffer b;bool ok=import(fd,usage,b);if(!ok){release(b);return false;}
cache.push_back({st.st_dev,st.st_ino,usage,b});out=b;return true;
}
public:
void clearBuffers(){if(device){vkDeviceWaitIdle(device);for(auto &e:cache)release(e.imported);cache.clear();}}
bool available(){if(!attempted){attempted=true;ready=init();}return ready;}
bool failedAfterSubmit()const{return unsafe;}
bool init(){
auto app=info<VkApplicationInfo>(VK_STRUCTURE_TYPE_APPLICATION_INFO);app.apiVersion=VK_API_VERSION_1_1;
auto create=info<VkInstanceCreateInfo>(VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO);create.pApplicationInfo=&app;
if(!check(vkCreateInstance(&create,nullptr,&instance),"create instance"))return false;
uint32_t n=0;vkEnumeratePhysicalDevices(instance,&n,nullptr);if(!n)return false;
std::vector<VkPhysicalDevice> devices(n);vkEnumeratePhysicalDevices(instance,&n,devices.data());physical=devices[0];
VkPhysicalDeviceProperties p;vkGetPhysicalDeviceProperties(physical,&p);
if(p.apiVersion<VK_API_VERSION_1_1)return false;
vkEnumerateDeviceExtensionProperties(physical,nullptr,&n,nullptr);std::vector<VkExtensionProperties> extensions(n);
vkEnumerateDeviceExtensionProperties(physical,nullptr,&n,extensions.data());
const char *required[]={VK_KHR_EXTERNAL_MEMORY_FD_EXTENSION_NAME,VK_EXT_EXTERNAL_MEMORY_DMA_BUF_EXTENSION_NAME,VK_EXT_QUEUE_FAMILY_FOREIGN_EXTENSION_NAME};
for(auto wanted:required){bool found=false;for(auto &e:extensions)if(!strcmp(e.extensionName,wanted))found=true;
if(!found)return false;}
vkGetPhysicalDeviceQueueFamilyProperties(physical,&n,nullptr);std::vector<VkQueueFamilyProperties> families(n);
vkGetPhysicalDeviceQueueFamilyProperties(physical,&n,families.data());
family=n;for(uint32_t i=0;i<n;i++)if(families[i].queueFlags&VK_QUEUE_TRANSFER_BIT){family=i;break;}
if(family==n)return false;
float priority=1;auto q=info<VkDeviceQueueCreateInfo>(VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO);
q.queueFamilyIndex=family;q.queueCount=1;q.pQueuePriorities=&priority;
auto d=info<VkDeviceCreateInfo>(VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO);d.queueCreateInfoCount=1;d.pQueueCreateInfos=&q;
d.enabledExtensionCount=3;d.ppEnabledExtensionNames=required;
if(!check(vkCreateDevice(physical,&d,nullptr,&device),"create device"))return false;
vkGetDeviceQueue(device,family,0,&queue);
properties=(PFN_vkGetMemoryFdPropertiesKHR)vkGetDeviceProcAddr(device,"vkGetMemoryFdPropertiesKHR");if(!properties)return false;
auto cp=info<VkCommandPoolCreateInfo>(VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO);cp.queueFamilyIndex=family;
cp.flags=VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
if(!check(vkCreateCommandPool(device,&cp,nullptr,&pool),"create pool"))return false;
auto a=info<VkCommandBufferAllocateInfo>(VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO);
a.commandPool=pool;a.level=VK_COMMAND_BUFFER_LEVEL_PRIMARY;a.commandBufferCount=1;
auto f=info<VkFenceCreateInfo>(VK_STRUCTURE_TYPE_FENCE_CREATE_INFO);
return check(vkAllocateCommandBuffers(device,&a,&command),"allocate command buffer")&&
check(vkCreateFence(device,&f,nullptr,&completed),"create fence");
}
bool copy(int source,int dest,const VkBufferCopy *regions,unsigned count){
unsafe=false;
struct stat s={},d={};
if(!count||fstat(source,&s)||fstat(dest,&d))return false;
for(unsigned i=0;i<count;i++)if(!regions[i].size||(regions[i].size&3)||
(regions[i].srcOffset&3)||(regions[i].dstOffset&3)||regions[i].srcOffset>(VkDeviceSize)s.st_size||
regions[i].dstOffset>(VkDeviceSize)d.st_size||regions[i].size>(VkDeviceSize)s.st_size-regions[i].srcOffset||
regions[i].size>(VkDeviceSize)d.st_size-regions[i].dstOffset)return false;
// Make room for the pair before resolving either handle. Evicting
// while importing the destination could destroy the source handle.
if(cache.size()>30)clearBuffers();
Buffer buffers[2];bool ok=cached(source,VK_BUFFER_USAGE_TRANSFER_SRC_BIT,buffers[0])&&
cached(dest,VK_BUFFER_USAGE_TRANSFER_DST_BIT,buffers[1]);
VkCommandBuffer cmd=command;VkFence fence=completed;
if(ok)ok=check(vkResetCommandBuffer(cmd,0),"reset command buffer")&&check(vkResetFences(device,1,&fence),"reset fence");
if(ok){
auto b=info<VkCommandBufferBeginInfo>(VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO);b.flags=VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
ok=check(vkBeginCommandBuffer(cmd,&b),"begin command buffer");
VkBufferMemoryBarrier barriers[2]={};
for(unsigned i=0;i<2;i++){
barriers[i].sType=VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;barriers[i].dstAccessMask=i?VK_ACCESS_TRANSFER_WRITE_BIT:VK_ACCESS_TRANSFER_READ_BIT;
barriers[i].srcQueueFamilyIndex=VK_QUEUE_FAMILY_FOREIGN_EXT;barriers[i].dstQueueFamilyIndex=family;
barriers[i].buffer=buffers[i].buffer;barriers[i].size=VK_WHOLE_SIZE;
}
vkCmdPipelineBarrier(cmd,VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,VK_PIPELINE_STAGE_TRANSFER_BIT,0,0,nullptr,2,barriers,0,nullptr);
vkCmdCopyBuffer(cmd,buffers[0].buffer,buffers[1].buffer,count,regions);
for(auto &barrier:barriers){barrier.srcAccessMask=barrier.dstAccessMask;barrier.dstAccessMask=0;
barrier.srcQueueFamilyIndex=family;barrier.dstQueueFamilyIndex=VK_QUEUE_FAMILY_FOREIGN_EXT;}
vkCmdPipelineBarrier(cmd,VK_PIPELINE_STAGE_TRANSFER_BIT,VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT,0,0,nullptr,2,barriers,0,nullptr);
ok=ok&&check(vkEndCommandBuffer(cmd),"end command buffer");
}
if(ok){auto s=info<VkSubmitInfo>(VK_STRUCTURE_TYPE_SUBMIT_INFO);s.commandBufferCount=1;s.pCommandBuffers=&cmd;
ok=check(vkQueueSubmit(queue,1,&s,fence),"submit");
if(ok){ok=check(vkWaitForFences(device,1,&fence,VK_TRUE,10000000000ull),"wait fence");unsafe=!ok;}}
if(!ok&&device)vkDeviceWaitIdle(device);
return ok;
}
~FramePortDmaCopy(){if(device){vkDeviceWaitIdle(device);for(auto &e:cache)release(e.imported);
if(completed)vkDestroyFence(device,completed,nullptr);if(pool)vkDestroyCommandPool(device,pool,nullptr);
vkDestroyDevice(device,nullptr);}if(instance)vkDestroyInstance(instance,nullptr);}
};
+70
View File
@@ -0,0 +1,70 @@
from pathlib import Path
import base64,re,urllib.request,urllib.error,json,concurrent.futures
root=Path(__file__).parent/'platform'
root.mkdir(exist_ok=True)
tag='android-11.0.0_r48'
trees=[
('frameworks/av','media/libstagefright/omx/include'),
('frameworks/av','media/libstagefright/foundation/include'),
('frameworks/av','media/libstagefright/include'),
('frameworks/av','media/libmedia/include'),
('frameworks/native','headers'),
('frameworks/native','headers/media_plugin'),
('frameworks/native','headers/media_plugin/include'),
('frameworks/native','libs/nativebase/include'),
('frameworks/native','libs/nativewindow/include'),
('frameworks/native','libs/ui/include'),
('frameworks/native','libs/binder/include'),
('system/core','libutils/include'),
('system/core','libcutils/include'),
('system/core','libsystem/include'),
('system/core','base/include'),
('system/core','libbacktrace/include'),
('system/logging','liblog/include'),
('system/core','liblog/include'),
('hardware/libhardware','include'),
('system/core','libsystem/include'),
('system/media','audio/include'),
]
seen=set()
def fetch(name,parent=None):
if name in seen:return
seen.add(name)
dest=root/name
if dest.exists(): data=dest.read_bytes()
else:
choices=list(trees)
preferred={'utils/':'libutils','cutils/':'libcutils','android-base/':'base/',
'log/':'liblog','system/':'libsystem','hardware/':'libhardware'}
for prefix,prefer in preferred.items():
if name.startswith(prefix):choices.sort(key=lambda item:prefer not in '/'.join(item))
if parent:choices=[parent]+choices
data=None
for repo,path in choices:
url=f'https://android.googlesource.com/platform/{repo}/+/refs/tags/{tag}/{path}/{name}?format=TEXT'
for attempt in range(3):
try:
data=base64.b64decode(urllib.request.urlopen(url,timeout=15).read());break
except urllib.error.HTTPError as exc:
if exc.code==404:break
except urllib.error.URLError:pass
if data is not None:break
if data is None:
print('Unresolved platform include:',name,flush=True);return
dest.parent.mkdir(parents=True,exist_ok=True);dest.write_bytes(data)
print('Fetched',name,flush=True)
# Only follow Android-specific and same-directory quote headers; C/C++
# standard and Linux headers are supplied by the checked NDK sysroot.
for delim,inc in re.findall(rb'#\s*include\s*([<"])([^>"\n]+)',data):
inc=inc.decode()
if inc.startswith(('utils/','cutils/','media/','system/','hardware/','android-base/','log/','ui/','nativebase/','binder/','backtrace/','android/')):
fetch(inc)
elif delim==b'"' and '/' not in inc:
fetch(str(Path(name).parent/inc).replace('\\','/'))
for n in ['media/stagefright/omx/SoftVideoDecoderOMXComponent.h',
'media/stagefright/foundation/AMessage.h','media/hardware/OMXPluginBase.h',
'utils/String8.h','utils/Log.h']:
fetch(n)
print('Platform header closure:',len(list(root.rglob('*.h'))),flush=True)
+759
View File
@@ -0,0 +1,759 @@
// SPDX-License-Identifier: GPL-3.0-only
// Android OMX integration for Iris stateful V4L2 video decoding. No OpenXR
// layer/pose manipulation, asset rewriting or package-specific behaviour.
#define LOG_TAG "FramePortVideo"
#include <media/stagefright/omx/SoftVideoDecoderOMXComponent.h>
#include <media/hardware/OMXPluginBase.h>
#include <media/openmax/OMX_IndexExt.h>
#include <media/hardware/HardwareAPI.h>
#include <media/stagefright/foundation/ColorUtils.h>
#include <android/hardware_buffer.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/videodev2.h>
#include <utils/String8.h>
#include <arm_neon.h>
#include <cstring>
#include <cerrno>
#include <pthread.h>
#include <time.h>
#include <poll.h>
#include "yuv_copy.h"
#include "yuv_color.h"
extern "C" {
#include <libavcodec/avcodec.h>
#include <libavutil/opt.h>
extern const YuvConstants kYvuH709Constants, kYvuI601Constants;
extern const YuvConstants kYvuJPEGConstants;
void NV21ToARGBRow_Any_NEON(const uint8_t*,const uint8_t*,uint8_t*,const YuvConstants*,int);
void I422ToARGBRow_Any_NEON(const uint8_t*,const uint8_t*,const uint8_t*,uint8_t*,const YuvConstants*,int);
AHardwareBuffer *ANativeWindowBuffer_getHardwareBuffer(ANativeWindowBuffer*);
const native_handle_t *AHardwareBuffer_getNativeHandle(const AHardwareBuffer*);
int frameport_v4l2_export_frame(const AVFrame*);
}
#include "dma_copy.h"
namespace android {
static const CodecProfileLevel hevc_profiles[]={{OMX_VIDEO_HEVCProfileMain,OMX_VIDEO_HEVCMainTierLevel62}};
// Android reports constrained AVC streams under their own profile values;
// stock decoders list them so format-aware clients can match them.
static const CodecProfileLevel avc_profiles[]={
{(OMX_U32)OMX_VIDEO_AVCProfileConstrainedBaseline,OMX_VIDEO_AVCLevel62},
{OMX_VIDEO_AVCProfileBaseline,OMX_VIDEO_AVCLevel62},
{(OMX_U32)OMX_VIDEO_AVCProfileConstrainedHigh,OMX_VIDEO_AVCLevel62},
{OMX_VIDEO_AVCProfileMain,OMX_VIDEO_AVCLevel62},
{OMX_VIDEO_AVCProfileHigh,OMX_VIDEO_AVCLevel62}};
static const CodecProfileLevel vp9_profiles[]={{OMX_VIDEO_VP9Profile0,OMX_VIDEO_VP9Level62}};
struct DecoderKind {
const char *name,*role,*mime,*hardware,*software;
OMX_VIDEO_CODINGTYPE coding;
uint32_t fourcc;
const CodecProfileLevel *profiles;
unsigned profile_count;
// What Iris returns pictures for on the Frame: VP9 at 7680x3840 opened but
// never returned one (2026-10-09), so larger VP9 decodes in software.
unsigned max_width,max_height;
};
static const DecoderKind kinds[]={
{"OMX.frameport.hevc.decoder","video_decoder.hevc","video/hevc","hevc_v4l2m2m","hevc",
OMX_VIDEO_CodingHEVC,V4L2_PIX_FMT_HEVC,hevc_profiles,1,8192,8192},
{"OMX.frameport.avc.decoder","video_decoder.avc","video/avc","h264_v4l2m2m","h264",
OMX_VIDEO_CodingAVC,V4L2_PIX_FMT_H264,avc_profiles,5,8192,8192},
{"OMX.frameport.vp9.decoder","video_decoder.vp9","video/x-vnd.on2.vp9","vp9_v4l2m2m","vp9",
OMX_VIDEO_CodingVP9,V4L2_PIX_FMT_VP9,vp9_profiles,1,4096,2304}};
static constexpr unsigned kind_count=sizeof(kinds)/sizeof(kinds[0]);
// When the media service loaded the plugin (= the container's start).
static int64_t plugin_loaded_ns=0;
class ColorWorkers {
struct Worker {ColorWorkers *owner;unsigned band,seen;pthread_t thread;};
Worker workers[3];unsigned count=0,generation=0,complete=0;
bool started=false,stopping=false;
pthread_mutex_t mutex=PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t work=PTHREAD_COND_INITIALIZER,done=PTHREAD_COND_INITIALIZER;
AVFrame *frame=nullptr;uint8_t *output=nullptr;size_t stride=0;
const YuvConstants *matrix=nullptr;
FramePortYuvPlane planes[3]={};bool native_yuv=false;
void rows(unsigned band) {
unsigned bands=count+1;
if(frame->format==AV_PIX_FMT_YUV420P || frame->format==AV_PIX_FMT_YUVJ420P){
unsigned begin=(frame->height/2)*band/bands,end=(frame->height/2)*(band+1)/bands;
if(native_yuv){
for(unsigned plane=0;plane<3;plane++){
unsigned first=plane?begin:2*begin,last=plane?end:2*end,width=plane?frame->width/2:frame->width;
for(unsigned row=first;row<last;row++){
const uint8_t *src=frame->data[plane]+row*frame->linesize[plane];
uint8_t *dst=planes[plane].data+row*planes[plane].row_stride;
if(planes[plane].pixel_stride==1)memcpy(dst,src,width);
else for(unsigned x=0;x<width;x++)dst[x*planes[plane].pixel_stride]=src[x];
}
}
}else for(unsigned row=2*begin;row<2*end;row++)
I422ToARGBRow_Any_NEON(frame->data[0]+row*frame->linesize[0],
frame->data[2]+(row/2)*frame->linesize[2],frame->data[1]+(row/2)*frame->linesize[1],
output+row*stride*4,matrix,frame->width);
return;
}
if(native_yuv){
frameport_yuv_copy_band(frame->data[0],frame->data[1],frame->width,frame->height,
frame->linesize[0],frame->linesize[1],planes,band,bands);return;
}
int begin=frame->height*band/bands,end=frame->height*(band+1)/bands;
for(int row=begin;row<end;row++)
NV21ToARGBRow_Any_NEON(frame->data[0]+row*frame->linesize[0],
frame->data[1]+(row/2)*frame->linesize[1],output+row*stride*4,matrix,frame->width);
}
static void *thread(void *arg) {
auto &worker=*static_cast<Worker*>(arg);auto &pool=*worker.owner;unsigned seen=worker.seen;
pthread_mutex_lock(&pool.mutex);
for(;;) {
while(!pool.stopping && seen==pool.generation)pthread_cond_wait(&pool.work,&pool.mutex);
if(pool.stopping)break;
seen=pool.generation;pthread_mutex_unlock(&pool.mutex);
pool.rows(worker.band);
pthread_mutex_lock(&pool.mutex);
if(++pool.complete==pool.count)pthread_cond_signal(&pool.done);
}
pthread_mutex_unlock(&pool.mutex);return nullptr;
}
public:
void convert(AVFrame *source,uint8_t *destination,size_t pitch,const YuvConstants *constants,
const AHardwareBuffer_Planes *native=nullptr) {
// Start helpers when a large picture first appears, including after
// an adaptive stream begins at a lower resolution.
if(!started && source->width*source->height>=4096*2048) {
started=true;
for(unsigned i=0;i<3;i++) {
// Only this thread advances the generation, so a helper
// created now waits for the next picture, never a stale one.
workers[i]={this,i+1,generation,{}};
if(pthread_create(&workers[i].thread,nullptr,thread,&workers[i]))break;
count++;
}
}
pthread_mutex_lock(&mutex);
frame=source;output=destination;stride=pitch;matrix=constants;complete=0;generation++;
native_yuv=native!=nullptr;
if(native)for(unsigned i=0;i<3;i++)planes[i]={static_cast<uint8_t*>(native->planes[i].data),
native->planes[i].rowStride,native->planes[i].pixelStride};
pthread_cond_broadcast(&work);pthread_mutex_unlock(&mutex);
rows(0);
pthread_mutex_lock(&mutex);
while(complete<count)pthread_cond_wait(&done,&mutex);
pthread_mutex_unlock(&mutex);
}
~ColorWorkers() {
pthread_mutex_lock(&mutex);stopping=true;pthread_cond_broadcast(&work);pthread_mutex_unlock(&mutex);
for(unsigned i=0;i<count;i++)pthread_join(workers[i].thread,nullptr);
pthread_cond_destroy(&work);pthread_cond_destroy(&done);pthread_mutex_destroy(&mutex);
}
};
class FramePortVideo final : public SoftVideoDecoderOMXComponent {
const DecoderKind &kind;
ColorWorkers color;
FramePortDmaCopy gpu;
bool gpu_allowed=true;
AVCodecContext *codec=nullptr;
AVCodecParserContext *parser=nullptr;
AVFrame *frame=av_frame_alloc();
uint8_t *config=nullptr;
size_t config_size=0;
bool failed=false,held=false,drained=false,replace_config=false,surface=false;
bool native_enabled=false,metadata=false;
bool hardware_active=false,prefer_software=false,eos_submitted=false,replay_eos=false;
bool prepend_config=false;
Vector<AVPacket*> history;
size_t history_bytes=0;
ssize_t replay_next=-1;
int64_t last_output_pts=AV_NOPTS_VALUE,discard_until=AV_NOPTS_VALUE;
static constexpr OMX_INDEXTYPE native_index=(OMX_INDEXTYPE)0x7f010001;
static constexpr OMX_INDEXTYPE metadata_index=(OMX_INDEXTYPE)0x7f010002;
static constexpr OMX_INDEXTYPE usage_index=(OMX_INDEXTYPE)0x7f010003;
int64_t eos_pts=0;
static int64_t clockNs() {timespec ts;clock_gettime(CLOCK_MONOTONIC,&ts);return ts.tv_sec*1000000000ll+ts.tv_nsec;}
int64_t stats_start=0, stats_lock=0, stats_convert=0, stats_unlock=0;
unsigned stats_frames=0,stats_gpu=0;
bool gpuCopy(AHardwareBuffer *hardware,const AHardwareBuffer_Planes &planes) {
if(planes.planes[1].pixelStride!=2 || planes.planes[2].pixelStride!=2 ||
planes.planes[1].rowStride!=planes.planes[2].rowStride ||
(uintptr_t)planes.planes[2].data!=(uintptr_t)planes.planes[1].data+1 ||
(uintptr_t)planes.planes[1].data<(uintptr_t)planes.planes[0].data)return false;
const auto *handle=AHardwareBuffer_getNativeHandle(hardware);
// CrOS gralloc includes duplicate plane fds and a metadata fd. The
// first fd holds the linear pixels; copy() bounds-checks both planes.
if(!handle || handle->numFds<1)return false;
int source=frameport_v4l2_export_frame(frame);if(source<0)return false;
uint64_t src_uv=(uintptr_t)frame->data[1]-(uintptr_t)frame->data[0];
uint64_t dst_uv=(uintptr_t)planes.planes[1].data-(uintptr_t)planes.planes[0].data;
std::vector<VkBufferCopy> regions;
auto append=[&](VkDeviceSize src,VkDeviceSize dst,VkDeviceSize bytes){
if(!regions.empty() && regions.back().srcOffset+regions.back().size==src &&
regions.back().dstOffset+regions.back().size==dst)regions.back().size+=bytes;
else regions.push_back({src,dst,bytes});
};
for(int row=0;row<frame->height;row++)
append((uint64_t)row*frame->linesize[0],(uint64_t)row*planes.planes[0].rowStride,frame->width);
for(int row=0;row<frame->height/2;row++)
append(src_uv+(uint64_t)row*frame->linesize[1],dst_uv+(uint64_t)row*planes.planes[1].rowStride,frame->width);
bool result=gpu.copy(source,handle->data[0],regions.data(),regions.size());close(source);return result;
}
void clearHistory() {
for(size_t i=0;i<history.size();i++){AVPacket *packet=history[i];av_packet_free(&packet);}
history.clear();history_bytes=0;replay_next=-1;
}
void rememberInput(const AVPacket *packet) {
if(!hardware_active)return;
if(packet->flags&AV_PKT_FLAG_KEY){
// Keep the preceding GOP too: the new keyframe can be submitted
// before older reordered pictures have finished coming out.
ssize_t previous=-1;
for(size_t i=0;i<history.size();i++)if(history[i]->flags&AV_PKT_FLAG_KEY)previous=i;
if(previous>0){
for(ssize_t i=0;i<previous;i++){
AVPacket *old=history[i];history_bytes-=old->size;av_packet_free(&old);
}
history.removeItemsAt(0,previous);
}
}
// References to compressed input, not copies of decoded panoramas.
// Bound memory for unusually long GOPs or malformed streams.
if(history_bytes+(size_t)packet->size>64*1024*1024 || history.size()>=512)clearHistory();
if(history.empty() && !(packet->flags&AV_PKT_FLAG_KEY))return;
AVPacket *copy=av_packet_clone(packet);
if(!copy)return;
if(history.add(copy)<0){av_packet_free(&copy);return;}
history_bytes+=copy->size;
}
bool annexB() const {
// H.264/HEVC parameter sets with start codes can go in-band. VP9's
// configuration is container metadata, never bitstream data.
return kind.coding!=OMX_VIDEO_CodingVP9 && config_size>=4 && !config[0] && !config[1] &&
(config[2]==1 || (!config[2] && config[3]==1));
}
void fail(int result,const char *operation) {
char message[128];av_strerror(result,message,sizeof(message));
ALOGE("%s failed: %s",operation,message);
failed=true;notify(OMX_EventError,OMX_ErrorHardware,0,nullptr);
}
static unsigned captureBuffers(const DecoderKind &kind,uint64_t pixels) {
// FFmpeg's general-purpose capture budget (20) suits ordinary sizes.
// Reference pictures shrink as pictures grow (HEVC level 6.x DPB
// limits; H.264 level 6.2 allows fewer), so 20 panorama-sized buffers
// would hold about 1 GB at 8K. VP9 can keep 8 references at any size.
// Unknown sizes keep the full budget.
const uint64_t max_luma=35651584;
unsigned references=pixels<=max_luma/4?16:pixels<=max_luma/2?12:pixels<=max_luma*3/4?8:6;
if(kind.coding==OMX_VIDEO_CodingVP9 && references<9)references=9;
// Room for the picture being decoded, one held for output and queueing.
return references+4<20?references+4:20;
}
int openCodec(const char *name,bool hardware) {
const AVCodec *implementation=avcodec_find_decoder_by_name(name);
if(!implementation || !frame)return AVERROR(ENOMEM);
codec=avcodec_alloc_context3(implementation);
if(!codec)return AVERROR(ENOMEM);
const auto &input=editPortInfo(kInputPortIndex)->mDef.format.video;
codec->width=codec->coded_width=input.nFrameWidth;
codec->height=codec->coded_height=input.nFrameHeight;
codec->pkt_timebase=AVRational{1,1000000};
codec->pix_fmt=AV_PIX_FMT_NV12;
if(config_size) {
codec->extradata=(uint8_t*)av_mallocz(config_size+AV_INPUT_BUFFER_PADDING_SIZE);
if(!codec->extradata)return AVERROR(ENOMEM);
memcpy(codec->extradata,config,config_size);codec->extradata_size=(int)config_size;
}
AVDictionary *options=nullptr;
if(hardware){
av_dict_set(&options,"num_output_buffers","2",0);
// Leave room for reference/reordered pictures: a four-buffer
// budget stalled a valid H.264 stream on Iris.
av_dict_set_int(&options,"num_capture_buffers",
captureBuffers(kind,(uint64_t)input.nFrameWidth*input.nFrameHeight),0);
}else{codec->thread_count=4;codec->thread_type=FF_THREAD_FRAME|FF_THREAD_SLICE;}
int result=avcodec_open2(codec,implementation,&options);av_dict_free(&options);
return result;
}
bool openDecoder() {
if(codec)return true;
const auto &size=editPortInfo(kInputPortIndex)->mDef.format.video;
int result=AVERROR(ENODEV);
if(size.nFrameWidth>kind.max_width || size.nFrameHeight>kind.max_height)
ALOGW("%s %ux%u is above what Iris decodes (%ux%u); using software decoding",kind.mime,
(unsigned)size.nFrameWidth,(unsigned)size.nFrameHeight,kind.max_width,kind.max_height);
else if(!prefer_software)for(int64_t start=clockNs(),attempt=0;;attempt++) {
result=openCodec(kind.hardware,true);
if(result>=0 || (result!=AVERROR(ENOMEM) && result!=AVERROR(EBUSY)))break;
// The driver refuses a session that doesn't fit next to the open
// ones (8K while any other is open). SteamVR's link holds one for
// about 12 s around every game start, when the plugin loads too:
// wait for it then (an 8K panorama in software is a slideshow),
// otherwise 2 s, before continuing in software.
int64_t now=clockNs();
if(now-start>=2000000000ll && now-plugin_loaded_ns>=20000000000ll)break;
if(!attempt)ALOGW("Iris %s busy (%ux%u); waiting for capacity",kind.mime,(unsigned)size.nFrameWidth,
(unsigned)size.nFrameHeight);
gpu.clearBuffers();avcodec_free_context(&codec);usleep(250000);
}
hardware_active=result>=0;
if(result<0){
// Availability can change after enumeration (another app/Steam
// opens Iris). Native MediaCodec clients do not all retry a stock
// component, so retain playback within this selected component.
if(prefer_software)ALOGI("%s: continuing in software for this session",kind.mime);
else ALOGW("Iris %s initialization failed (%d); using software decoding",kind.mime,result);
gpu.clearBuffers();avcodec_free_context(&codec);
result=openCodec(kind.software,false);
if(result<0){gpu.clearBuffers();avcodec_free_context(&codec);fail(result,"software fallback initialization");return false;}
}else ALOGI("Iris hardware %s decoder active: %dx%d",kind.mime,codec->coded_width,codec->coded_height);
prepend_config=hardware_active && annexB();
parser=av_parser_init(codec->codec_id);
if(parser)parser->flags|=PARSER_FLAG_COMPLETE_FRAMES;
return true;
}
bool recoverHardware(const char *operation) {
if(!hardware_active || history.empty() || !(history[0]->flags&AV_PKT_FLAG_KEY)){
fail(AVERROR_INVALIDDATA,operation);return false;
}
ALOGW("Iris %s failed during %s; replaying %zu compressed packets in software, last pts=%lld",kind.mime,operation,history.size(),(long long)last_output_pts);
av_frame_unref(frame);held=false;av_parser_close(parser);parser=nullptr;gpu.clearBuffers();avcodec_free_context(&codec);
hardware_active=false;prefer_software=true;
int result=openCodec(kind.software,false);
if(result<0){fail(result,"software recovery initialization");return false;}
replay_next=0;replay_eos=eos_submitted;eos_submitted=false;discard_until=last_output_pts;
return true;
}
void consumeInput(BufferInfo *info) {
OMX_BUFFERHEADERTYPE *header=info->mHeader;
getPortQueue(kInputPortIndex).erase(getPortQueue(kInputPortIndex).begin());
header->nOffset=0;header->nFilledLen=0;info->mOwnedByUs=false;
notifyEmptyBufferDone(header);
}
void reportBitstreamColor() {
// Like Android's stock decoders, pass signalled colour information
// to ACodec, which uses it for the surface dataspace. Container
// values still take precedence (getColorAspectPreference).
if(frame->color_primaries==AVCOL_PRI_UNSPECIFIED && frame->color_trc==AVCOL_TRC_UNSPECIFIED &&
frame->colorspace==AVCOL_SPC_UNSPECIFIED && frame->color_range==AVCOL_RANGE_UNSPECIFIED)return;
// FFmpeg's colour enums use the ISO/IEC 23091-2 code points.
ColorAspects aspects;
ColorUtils::convertIsoColorAspectsToCodecAspects(frame->color_primaries,frame->color_trc,
frame->colorspace,frame->color_range==AVCOL_RANGE_JPEG,aspects);
if(colorAspectsDiffer(aspects,mBitstreamColorAspects)){
ALOGI("%s bitstream colour: primaries %d, transfer %d, matrix %d, range %d",kind.mime,
frame->color_primaries,frame->color_trc,frame->colorspace,frame->color_range);
mBitstreamColorAspects=aspects;handleColorAspectsChange();
}
}
const YuvConstants *rgbaMatrix() {
ColorAspects aspects;
{Mutex::Autolock lock(mColorAspectsLock);aspects=mFinalColorAspects;}
// Unsignalled HD video is conventionally BT.709, as Android assumes.
bool bt709=aspects.mMatrixCoeffs==ColorAspects::MatrixBT709_5 ||
(aspects.mMatrixCoeffs==ColorAspects::MatrixUnspecified && (frame->width>=1280 || frame->height>=720));
if(aspects.mRange==ColorAspects::RangeFull)return bt709?&frameport_full709_rgba:&kYvuJPEGConstants;
return bt709?&kYvuH709Constants:&kYvuI601Constants;
}
bool outputFrame() {
// Hardware errors are recovered in software. Software decoders
// conceal damage themselves; output their picture as stock decoders do.
if(frame->decode_error_flags && hardware_active)return recoverHardware("decoded picture");
reportBitstreamColor();
bool reset=false;
handlePortSettingsChange(&reset,frame->width,frame->height,
native_enabled?(OMX_COLOR_FORMATTYPE)AHARDWAREBUFFER_FORMAT_Y8Cb8Cr8_420:
surface?OMX_COLOR_Format32BitRGBA8888:OMX_COLOR_FormatYUV420Planar);
rgbaPort();
if(reset)return false;
auto &queue=getPortQueue(kOutputPortIndex);
if(queue.empty())return false;
BufferInfo *info=*queue.begin();OMX_BUFFERHEADERTYPE *header=info->mHeader;
size_t stride=outputBufferWidth(),height=outputBufferHeight();
size_t bytes=native_enabled?sizeof(VideoNativeMetadata):surface?stride*height*4:stride*height*3/2;
bool planar=frame->format==AV_PIX_FMT_YUV420P || frame->format==AV_PIX_FMT_YUVJ420P;
if(bytes>header->nAllocLen || (frame->format!=AV_PIX_FMT_NV12 && !planar) ||
frame->width<1 || frame->height<1 || (frame->width&1) || (frame->height&1) ||
(size_t)frame->width>stride || (size_t)frame->height>height) {
fail(AVERROR(EINVAL),"output buffer format");return false;
}
// Native surfaces keep YUV planes for GPU colour conversion. Legacy
// software surfaces use parallel NEON RGBA conversion, bypassing
// Lepton's slow scalar RGB565 renderer.
if(surface || native_enabled) {
int64_t before=clockNs(),locked=before,converted=before;
const YuvConstants *matrix=native_enabled?nullptr:rgbaMatrix();
uint8_t *destination=header->pBuffer;
AHardwareBuffer *hardware=nullptr;VideoNativeMetadata *native=nullptr;
AHardwareBuffer_Planes planes={};
bool used_gpu=false;
if(native_enabled) {
native=reinterpret_cast<VideoNativeMetadata*>(header->pBuffer);
if(!metadata || native->eType!=kMetadataBufferTypeANWBuffer || !native->pBuffer) {
fail(AVERROR(EINVAL),"native output metadata");return false;
}
hardware=ANativeWindowBuffer_getHardwareBuffer(native->pBuffer);
if(!hardware){fail(AVERROR(EINVAL),"native hardware buffer");return false;}
AHardwareBuffer_Desc desc={};AHardwareBuffer_describe(hardware,&desc);
if(desc.format!=AHARDWAREBUFFER_FORMAT_Y8Cb8Cr8_420 || desc.width<(unsigned)frame->width ||
desc.height<(unsigned)frame->height) {
fail(AVERROR(EINVAL),"native output geometry");return false;
}
int result=AHardwareBuffer_lockPlanes(hardware,AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN,
native->nFenceFd,nullptr,&planes);
if(native->nFenceFd>=0)close(native->nFenceFd);
native->nFenceFd=-1;
if(result){fail(AVERROR(EIO),"native output lock");return false;}
if(planes.planeCount!=3 || planes.planes[0].pixelStride!=1 ||
planes.planes[0].rowStride<(unsigned)frame->width ||
!planes.planes[0].data || !planes.planes[1].data || !planes.planes[2].data ||
!planes.planes[1].pixelStride || !planes.planes[2].pixelStride ||
planes.planes[1].rowStride<(frame->width/2-1)*planes.planes[1].pixelStride+1 ||
planes.planes[2].rowStride<(frame->width/2-1)*planes.planes[2].pixelStride+1) {
AHardwareBuffer_unlock(hardware,&native->nFenceFd);
fail(AVERROR(EINVAL),"native YUV planes");return false;
}
locked=clockNs();
if(gpu_allowed && hardware_active && !planar && !(frame->width&3) &&
(uint64_t)frame->width*frame->height>=4096*2048 && gpu.available()) {
if(AHardwareBuffer_unlock(hardware,&native->nFenceFd)){
fail(AVERROR(EIO),"native layout unlock");return false;
}
if(native->nFenceFd>=0){
pollfd fence={native->nFenceFd,POLLIN,0};int waited;
do{waited=poll(&fence,1,10000);}while(waited<0 && errno==EINTR);
close(native->nFenceFd);native->nFenceFd=-1;
if(waited<=0 || !(fence.revents&POLLIN)){fail(AVERROR(EIO),"native layout fence");return false;}
}
used_gpu=gpuCopy(hardware,planes);
if(!used_gpu){
gpu_allowed=false;
if(gpu.failedAfterSubmit()){fail(AVERROR(EIO),"GPU video transfer");return false;}
if(AHardwareBuffer_lockPlanes(hardware,AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN,-1,nullptr,&planes)){
fail(AVERROR(EIO),"native CPU fallback lock");return false;
}
ALOGW("GPU video buffer sharing unavailable; retaining CPU copy");
}
}
}
if(!native_enabled)locked=clockNs();
if(native_enabled && !used_gpu)color.convert(frame,nullptr,0,nullptr,&planes);
else if(!native_enabled)color.convert(frame,destination,stride,matrix);
converted=clockNs();
if(hardware && !used_gpu && AHardwareBuffer_unlock(hardware,&native->nFenceFd)) {
fail(AVERROR(EIO),"native output unlock");return false;
}
int64_t after=clockNs();
stats_lock+=locked-before;stats_convert+=converted-locked;stats_unlock+=after-converted;
if(!stats_start)stats_start=before;
stats_frames++;
if(used_gpu)stats_gpu++;
if(after-stats_start>=5000000000ll) {
ALOGI("output %.1f fps, native=%d, gpu=%u/%u, lock %.2f ms, copy/convert %.2f ms, unlock %.2f ms, pts=%lld",
stats_frames*1e9/(after-stats_start),native_enabled,stats_gpu,stats_frames,
stats_lock/(1e6*stats_frames),stats_convert/(1e6*stats_frames),stats_unlock/(1e6*stats_frames),
(long long)frame->pts);
stats_start=after;stats_frames=stats_gpu=0;stats_lock=stats_convert=stats_unlock=0;
}
} else {
// Byte buffers hold planar YUV; the same worker bands copy the
// planes (in parallel for panorama sizes).
uint8_t *y=header->pBuffer,*u=y+stride*height,*v=u+stride*height/4;
AHardwareBuffer_Planes planes={};planes.planeCount=3;
planes.planes[0]={y,1,(uint32_t)stride};
planes.planes[1]={u,1,(uint32_t)(stride/2)};
planes.planes[2]={v,1,(uint32_t)(stride/2)};
color.convert(frame,nullptr,0,nullptr,&planes);
}
header->nOffset=0;header->nFilledLen=(OMX_U32)bytes;
header->nTimeStamp=frame->pts==AV_NOPTS_VALUE?frame->best_effort_timestamp:frame->pts;
last_output_pts=header->nTimeStamp;
header->nFlags=OMX_BUFFERFLAG_ENDOFFRAME;
queue.erase(queue.begin());info->mOwnedByUs=false;notifyFillBufferDone(header);
av_frame_unref(frame);held=false;return true;
}
protected:
void rgbaPort() {
if(native_enabled) {
auto &def=editPortInfo(kOutputPortIndex)->mDef;
def.format.video.eColorFormat=(OMX_COLOR_FORMATTYPE)AHARDWAREBUFFER_FORMAT_Y8Cb8Cr8_420;
def.nBufferSize=sizeof(VideoNativeMetadata);return;
}
if(mOutputFormat!=OMX_COLOR_Format32BitRGBA8888)return;
auto &def=editPortInfo(kOutputPortIndex)->mDef;
def.format.video.eColorFormat=OMX_COLOR_Format32BitRGBA8888;
def.nBufferSize=outputBufferWidth()*outputBufferHeight()*4;
}
OMX_ERRORTYPE internalGetParameter(OMX_INDEXTYPE index, OMX_PTR params) override {
if(index==(OMX_INDEXTYPE)OMX_IndexParamVideoAndroidRequiresSwRenderer) {
auto *value=static_cast<OMX_PARAM_U32TYPE*>(params);
if(!value || value->nSize<sizeof(*value) || value->nPortIndex!=kOutputPortIndex)
return OMX_ErrorBadParameter;
// Decoding happens on Iris; Android's Surface renderer consumes
// our ordinary planar buffers rather than vendor ANW metadata.
surface=!native_enabled;value->nU32=native_enabled?0:1;return OMX_ErrorNone;
}
if(index==usage_index) {
auto *value=static_cast<GetAndroidNativeBufferUsageParams*>(params);
if(!value || value->nSize<sizeof(*value) || value->nPortIndex!=kOutputPortIndex)return OMX_ErrorBadParameter;
value->nUsage=AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN|AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE;
return OMX_ErrorNone;
}
if(index==OMX_IndexParamPortDefinition)rgbaPort();
OMX_ERRORTYPE result=SoftVideoDecoderOMXComponent::internalGetParameter(index,params);
if(result==OMX_ErrorNone && index==OMX_IndexParamVideoPortFormat) {
auto *value=static_cast<OMX_VIDEO_PARAM_PORTFORMATTYPE*>(params);
if(value->nPortIndex==kOutputPortIndex)value->eColorFormat=native_enabled?
(OMX_COLOR_FORMATTYPE)AHARDWAREBUFFER_FORMAT_Y8Cb8Cr8_420:mOutputFormat;
}
return result;
}
OMX_ERRORTYPE getExtensionIndex(const char *name,OMX_INDEXTYPE *index) override {
if(!strcmp(name,"OMX.google.android.index.enableAndroidNativeBuffers"))*index=native_index;
else if(!strcmp(name,"OMX.google.android.index.storeANWBufferInMetadata"))*index=metadata_index;
else if(!strcmp(name,"OMX.google.android.index.getAndroidNativeBufferUsage"))*index=usage_index;
else return SoftVideoDecoderOMXComponent::getExtensionIndex(name,index);
return OMX_ErrorNone;
}
OMX_ERRORTYPE internalSetParameter(OMX_INDEXTYPE index,OMX_PTR params) override {
if(index==native_index || index==metadata_index) {
auto *value=static_cast<EnableAndroidNativeBuffersParams*>(params);
if(!value || value->nSize<sizeof(*value) || value->nPortIndex!=kOutputPortIndex)return OMX_ErrorBadParameter;
if(index==native_index)native_enabled=value->enable;
else metadata=value->enable;
rgbaPort();return OMX_ErrorNone;
}
if(index==OMX_IndexParamVideoPortFormat && native_enabled) {
auto *value=static_cast<OMX_VIDEO_PARAM_PORTFORMATTYPE*>(params);
if(value && value->nSize>=sizeof(*value) && value->nPortIndex==kOutputPortIndex) {
auto copy=*value;copy.eColorFormat=OMX_COLOR_FormatYUV420Planar;
return SoftVideoDecoderOMXComponent::internalSetParameter(index,&copy);
}
}
OMX_ERRORTYPE result=SoftVideoDecoderOMXComponent::internalSetParameter(index,params);
rgbaPort();return result;
}
int getColorAspectPreference() override {return kPreferContainer;}
void onQueueFilled(OMX_U32) override {
if(failed || mOutputPortSettingsChange!=NONE || drained)return;
auto &inputs=getPortQueue(kInputPortIndex);auto &outputs=getPortQueue(kOutputPortIndex);
while(!outputs.empty()) {
if(held){if(!outputFrame())return;continue;}
if(codec) {
int result=avcodec_receive_frame(codec,frame);
if(result==0){
int64_t pts=frame->pts==AV_NOPTS_VALUE?frame->best_effort_timestamp:frame->pts;
if(discard_until!=AV_NOPTS_VALUE && pts!=AV_NOPTS_VALUE && pts<=discard_until){av_frame_unref(frame);continue;}
discard_until=AV_NOPTS_VALUE;held=true;continue;
}
if(result==AVERROR_EOF) {
BufferInfo *info=*outputs.begin();auto *header=info->mHeader;
header->nOffset=0;header->nFilledLen=0;header->nTimeStamp=eos_pts;
header->nFlags=OMX_BUFFERFLAG_EOS;outputs.erase(outputs.begin());
info->mOwnedByUs=false;notifyFillBufferDone(header);drained=true;return;
}
if(result!=AVERROR(EAGAIN)){
if(hardware_active && recoverHardware("frame retrieval"))continue;
if(!failed)fail(result,"frame retrieval");return;
}
}
if(replay_next>=0){
if((size_t)replay_next<history.size()){
int result=avcodec_send_packet(codec,history[replay_next]);
if(result<0){fail(result,"software recovery packet");return;}
replay_next++;continue;
}
clearHistory();
if(replay_eos){
int result=avcodec_send_packet(codec,nullptr);
if(result<0){fail(result,"software recovery drain");return;}
replay_eos=false;eos_submitted=true;continue;
}
}
if(inputs.empty())return;
BufferInfo *info=*inputs.begin();auto *header=info->mHeader;
if(header->nOffset>header->nAllocLen || header->nFilledLen>header->nAllocLen-header->nOffset) {
fail(AVERROR(EINVAL),"input buffer bounds");return;
}
if(header->nFlags&OMX_BUFFERFLAG_CODECCONFIG) {
if(replace_config){av_freep(&config);config_size=0;replace_config=false;}
if(config_size+header->nFilledLen>1024*1024) {
fail(AVERROR(EINVAL),"oversized codec configuration");return;
}
if(header->nFilledLen) {
void *grown=av_realloc(config,config_size+header->nFilledLen);
if(!grown){fail(AVERROR(ENOMEM),"codec configuration storage");return;}
config=(uint8_t*)grown;
memcpy(config+config_size,header->pBuffer+header->nOffset,header->nFilledLen);
config_size+=header->nFilledLen;
}
// Streaming apps and restarted encoders can send parameter
// sets again mid-stream. Stock decoders accept them; submit
// them in-band before the next access unit.
if(codec)prepend_config=annexB();
consumeInput(info);continue;
}
if(!openDecoder())return;
if(header->nFilledLen) {
AVPacket *packet=av_packet_alloc();
if(!packet){fail(AVERROR(ENOMEM),"input packet");return;}
// Android delivers parameter sets in separate CODECCONFIG
// buffers. V4L2 expects Annex B parameter sets in its input
// stream; FFmpeg's V4L2 wrapper does not submit extradata.
size_t prefix=prepend_config?config_size:0;
int result=av_new_packet(packet,(int)(prefix+header->nFilledLen));
if(result>=0) {
if(prefix)memcpy(packet->data,config,prefix);
memcpy(packet->data+prefix,header->pBuffer+header->nOffset,header->nFilledLen);
packet->pts=packet->dts=header->nTimeStamp;
if(header->nFlags&OMX_BUFFERFLAG_SYNCFRAME)packet->flags|=AV_PKT_FLAG_KEY;
// ACodec does not preserve MediaCodec's KEY_FRAME flag
// on decoder input. Parse complete access units so driver
// recovery also works for ordinary Android clients.
if(parser){
uint8_t *parsed=nullptr;int parsed_size=0;
av_parser_parse2(parser,codec,&parsed,&parsed_size,packet->data,packet->size,
packet->pts,packet->dts,AV_NOPTS_VALUE);
if(parser->key_frame==1)packet->flags|=AV_PKT_FLAG_KEY;
}
result=avcodec_send_packet(codec,packet);
if(result>=0){prepend_config=false;rememberInput(packet);}
}
av_packet_free(&packet);
if(result==AVERROR(EAGAIN))return;
if(result<0){
if(hardware_active && recoverHardware("packet submission"))continue;
if(!failed)fail(result,"packet submission");return;
}
header->nFilledLen=0;
}
if(header->nFlags&OMX_BUFFERFLAG_EOS) {
eos_pts=header->nTimeStamp;
int result=avcodec_send_packet(codec,nullptr);
if(result==AVERROR(EAGAIN))return;
if(result<0){fail(result,"stream drain");return;}
eos_submitted=true;
}
replace_config=true; // a later configuration replaces this one
consumeInput(info);
}
}
void onPortFlushCompleted(OMX_U32 port) override {
if(port==kInputPortIndex) {
gpu.clearBuffers();
// Release the held picture first (its V4L2 buffer returns to the driver).
av_frame_unref(frame);av_parser_close(parser);parser=nullptr;clearHistory();
// Software decoders flush in place. A hardware session restarts in
// place only after a completed drain (replay/loop after EOS):
// restarting a running Iris session's queues failed its admission
// check and left buffers unreturned, so other seeks reopen it.
bool usable=codec && !failed && (!hardware_active || drained);
eos_submitted=false;replay_eos=false;
last_output_pts=discard_until=AV_NOPTS_VALUE;
held=false;drained=false;failed=false;replace_config=true;
if(usable) {
// Keeps the buffers and the Iris session (no reallocation).
avcodec_flush_buffers(codec);
int64_t restart_error=0;
if(hardware_active && (av_opt_get_int(codec->priv_data,"frameport_flush_error",0,&restart_error)<0 ||
restart_error<0)) {
ALOGW("Iris %s replay restart failed (%lld); continuing in software",kind.mime,(long long)restart_error);
gpu.clearBuffers();avcodec_free_context(&codec);hardware_active=false;prefer_software=true;
} else {
parser=av_parser_init(codec->codec_id);
if(parser)parser->flags|=PARSER_FLAG_COMPLETE_FRAMES;
prepend_config=annexB();
}
} else {
if(hardware_active && kind.coding==OMX_VIDEO_CodingVP9){
// Reopening Iris VP9 sessions after a seek damaged pictures and
// faulted the kernel on this Frame: continue in software.
prefer_software=true;
ALOGW("VP9 seek: continuing in software rather than reopening Iris");
}
gpu.clearBuffers();avcodec_free_context(&codec);hardware_active=false;
}
}
}
void onReset() override {
gpu_allowed=true;
av_frame_unref(frame);av_parser_close(parser);parser=nullptr;gpu.clearBuffers();avcodec_free_context(&codec);av_freep(&config);config_size=0;clearHistory();
hardware_active=false;prefer_software=false;eos_submitted=false;replay_eos=false;
last_output_pts=discard_until=AV_NOPTS_VALUE;
held=false;drained=false;failed=false;replace_config=false;
SoftVideoDecoderOMXComponent::onReset();
surface=false;native_enabled=false;metadata=false;mOutputFormat=OMX_COLOR_FormatYUV420Planar;
updatePortDefinitions(true,false);
}
~FramePortVideo() override {av_frame_free(&frame);av_parser_close(parser);gpu.clearBuffers();avcodec_free_context(&codec);av_freep(&config);clearHistory();}
public:
FramePortVideo(const DecoderKind &type,const OMX_CALLBACKTYPE *callbacks,OMX_PTR appData,OMX_COMPONENTTYPE **component)
:SoftVideoDecoderOMXComponent(type.name,type.role,type.coding,
type.profiles,type.profile_count,320,240,callbacks,appData,component),kind(type) {
initPorts(8,2*1024*1024,4,type.mime,1);
}
};
class FramePortOMXPlugin final : public OMXPluginBase {
bool available[kind_count]={};
static bool probeCapacity(const DecoderKind &kind) {
// Check each coded format separately, at ordinary video geometry.
// A rejected 8K session must not hide hardware from a 1080p app.
int fd=open("/dev/video-dec0",O_RDWR|O_NONBLOCK);
if(fd<0)return false;
bool supported=false;
for(unsigned i=0;;i++){
v4l2_fmtdesc desc={};desc.index=i;desc.type=V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
if(ioctl(fd,VIDIOC_ENUM_FMT,&desc)<0)break;
if(desc.pixelformat==kind.fourcc)supported=true;
}
if(!supported){close(fd);return false;}
v4l2_format format={};format.type=V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
format.fmt.pix_mp.width=1920;format.fmt.pix_mp.height=1080;
format.fmt.pix_mp.pixelformat=kind.fourcc;format.fmt.pix_mp.num_planes=1;
bool ok=ioctl(fd,VIDIOC_S_FMT,&format)==0 && format.fmt.pix_mp.pixelformat==kind.fourcc;
format.type=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;format.fmt.pix_mp.pixelformat=V4L2_PIX_FMT_NV12;
if(ok)ok=ioctl(fd,VIDIOC_S_FMT,&format)==0 && format.fmt.pix_mp.pixelformat==V4L2_PIX_FMT_NV12;
v4l2_requestbuffers buffers={};buffers.count=2;
buffers.type=V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;buffers.memory=V4L2_MEMORY_MMAP;
if(ok)ok=ioctl(fd,VIDIOC_REQBUFS,&buffers)==0;
close(fd);return ok;
}
public:
FramePortOMXPlugin() {
timespec now;clock_gettime(CLOCK_MONOTONIC,&now);plugin_loaded_ns=now.tv_sec*1000000000ll+now.tv_nsec;
for(unsigned i=0;i<kind_count;i++){
available[i]=probeCapacity(kinds[i]);
if(!available[i])ALOGW("Iris %s unavailable; keeping Android's stock decoder",kinds[i].mime);
}
}
OMX_ERRORTYPE makeComponentInstance(const char *name,const OMX_CALLBACKTYPE *callbacks,
OMX_PTR appData,OMX_COMPONENTTYPE **component) override {
for(unsigned i=0;i<kind_count;i++)if(available[i] && !strcmp(name,kinds[i].name)){
auto *decoder=new FramePortVideo(kinds[i],callbacks,appData,component);
decoder->incStrong(this);return decoder->initCheck();
}
return OMX_ErrorInvalidComponentName;
}
OMX_ERRORTYPE destroyComponentInstance(OMX_COMPONENTTYPE *component) override {
auto *decoder=static_cast<SoftOMXComponent*>(component->pComponentPrivate);
decoder->prepareForDestruction();decoder->decStrong(this);return OMX_ErrorNone;
}
OMX_ERRORTYPE enumerateComponents(OMX_STRING name,size_t size,OMX_U32 index) override {
for(unsigned i=0;i<kind_count;i++)if(available[i]){
if(index){--index;continue;}
if(size<=strlen(kinds[i].name))return OMX_ErrorBadParameter;
strcpy(name,kinds[i].name);return OMX_ErrorNone;
}
return OMX_ErrorNoMore;
}
OMX_ERRORTYPE getRolesOfComponent(const char *name,Vector<String8> *roles) override {
for(unsigned i=0;i<kind_count;i++)if(available[i] && !strcmp(name,kinds[i].name)){
roles->clear();roles->push(String8(kinds[i].role));return OMX_ErrorNone;
}
return OMX_ErrorInvalidComponentName;
}
};
}
android::OMXPluginBase *createOMXPlugin(){return new android::FramePortOMXPlugin;}
// Android loaders support both historical factory ABI spellings.
extern "C" android::OMXPluginBase *createFramePortOMXPlugin() __asm__("createOMXPlugin");
extern "C" android::OMXPluginBase *createFramePortOMXPlugin(){return createOMXPlugin();}
extern "C" void destroyOMXPlugin(android::OMXPluginBase *plugin){delete plugin;}
+78
View File
@@ -0,0 +1,78 @@
#include <media/NdkMediaCodec.h>
#include <media/NdkMediaExtractor.h>
#include <media/NdkImageReader.h>
#include <android/native_window.h>
#include <android/hardware_buffer.h>
#include <cstdio>
#include <cassert>
#include <cstring>
#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>
#include <time.h>
static double now(){timespec t;clock_gettime(CLOCK_MONOTONIC,&t);return t.tv_sec+t.tv_nsec*1e-9;}
int main(int argc,char **argv){
bool fallback=argc>2 && !strcmp(argv[2],"fallback");
assert(argc>=2);int fd=open(argv[1],O_RDONLY);assert(fd>=0);struct stat st;assert(!fstat(fd,&st));
auto *extractor=AMediaExtractor_new();assert(AMediaExtractor_setDataSourceFd(extractor,fd,0,st.st_size)==AMEDIA_OK);
AMediaFormat *format=nullptr;int width=0,height=0;const char *video_mime=nullptr;
for(size_t i=0;i<AMediaExtractor_getTrackCount(extractor);i++){
auto *candidate=AMediaExtractor_getTrackFormat(extractor,i);const char *mime=nullptr;
if(AMediaFormat_getString(candidate,AMEDIAFORMAT_KEY_MIME,&mime)&&
(!strcmp(mime,"video/hevc") || !strcmp(mime,"video/avc") || !strcmp(mime,"video/x-vnd.on2.vp9"))){
format=candidate;video_mime=mime;assert(AMediaExtractor_selectTrack(extractor,i)==AMEDIA_OK);break;
}AMediaFormat_delete(candidate);
}assert(format);
assert(AMediaFormat_getInt32(format,AMEDIAFORMAT_KEY_WIDTH,&width));assert(AMediaFormat_getInt32(format,AMEDIAFORMAT_KEY_HEIGHT,&height));
const char *expected=!strcmp(video_mime,"video/hevc")?"OMX.frameport.hevc.decoder":
!strcmp(video_mime,"video/avc")?"OMX.frameport.avc.decoder":"OMX.frameport.vp9.decoder";
const char *stock=!strcmp(video_mime,"video/hevc")?"OMX.google.hevc.decoder":
!strcmp(video_mime,"video/avc")?"OMX.google.h264.decoder":"OMX.google.vp9.decoder";
auto *codec=AMediaCodec_createDecoderByType(video_mime);assert(codec);char *name=nullptr;
assert(AMediaCodec_getName(codec,&name)==AMEDIA_OK);printf("Selected codec: %s\n",name);fflush(stdout);
if(argc>2 && !strcmp(argv[2],"query")){
assert(!strcmp(name,expected) || !strcmp(name,stock));
AMediaCodec_releaseName(codec,name);AMediaCodec_delete(codec);
AMediaFormat_delete(format);AMediaExtractor_delete(extractor);close(fd);
puts("PASS default HEVC selection");return 0;
}
assert(!strcmp(name,fallback?stock:expected));AMediaCodec_releaseName(codec,name);
AImageReader *reader=nullptr;ANativeWindow *window=nullptr;
if(argc>2){assert(AImageReader_newWithUsage(width,height,AIMAGE_FORMAT_PRIVATE,AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE,3,&reader)==AMEDIA_OK);assert(AImageReader_getWindow(reader,&window)==AMEDIA_OK);AMediaFormat_setInt32(format,"allow-frame-drop",0);}
printf("Input format: %s\n",AMediaFormat_toString(format));
const char *keys[]={"csd-0","csd-1"};for(const char *key:keys){void *p=nullptr;size_t n=0;if(AMediaFormat_getBuffer(format,key,&p,&n)){auto *b=(unsigned char*)p;printf("%s: %zu bytes %02x %02x %02x %02x\n",key,n,b[0],b[1],b[2],b[3]);}}
assert(AMediaCodec_configure(codec,format,window,nullptr,0)==AMEDIA_OK);assert(AMediaCodec_start(codec)==AMEDIA_OK);
for(unsigned phase=0;phase<2;phase++){
unsigned goal=fallback?(phase?2:6):(phase?120:600),sent=0,received=0,images=0;bool input_eos=false,output_eos=false;double start=now();
while(!output_eos && now()-start<45){
if(!input_eos){ssize_t id=AMediaCodec_dequeueInputBuffer(codec,1000);if(id>=0){
size_t capacity=0;auto *data=AMediaCodec_getInputBuffer(codec,id,&capacity);assert(data);
if(sent==goal){assert(AMediaCodec_queueInputBuffer(codec,id,0,0,sent*1000000/60,AMEDIACODEC_BUFFER_FLAG_END_OF_STREAM)==AMEDIA_OK);input_eos=true;}
else {ssize_t size=AMediaExtractor_readSampleData(extractor,data,capacity);assert(size>0);int64_t pts=AMediaExtractor_getSampleTime(extractor);
if(sent<2)printf("Input packet: %zd bytes %02x %02x %02x %02x\n",size,data[0],data[1],data[2],data[3]);
assert(AMediaCodec_queueInputBuffer(codec,id,0,size,pts,AMediaExtractor_getSampleFlags(extractor)&1?AMEDIACODEC_BUFFER_FLAG_KEY_FRAME:0)==AMEDIA_OK);
assert(AMediaExtractor_advance(extractor));sent++;
}
}}
AMediaCodecBufferInfo info={};ssize_t id=AMediaCodec_dequeueOutputBuffer(codec,&info,1000);
if(id>=0){if(received<2 || (info.flags&AMEDIACODEC_BUFFER_FLAG_END_OF_STREAM))printf("Buffer id=%zd size=%d flags=%u pts=%lld\n",id,info.size,info.flags,(long long)info.presentationTimeUs);if(info.size)received++;output_eos=info.flags&AMEDIACODEC_BUFFER_FLAG_END_OF_STREAM;
assert(AMediaCodec_releaseOutputBuffer(codec,id,window!=nullptr)==AMEDIA_OK);
// Surface delivery is asynchronous. Drain each rendered picture before
// submitting another, so this unpaced fixture does not test frame dropping.
if(reader && info.size){double deadline=now()+1;unsigned before=images;
do{AImage *image=nullptr;if(AImageReader_acquireNextImage(reader,&image)==AMEDIA_OK){
int32_t w=0,h=0;assert(AImage_getWidth(image,&w)==AMEDIA_OK && AImage_getHeight(image,&h)==AMEDIA_OK);
assert(w==width && h==height);images++;AImage_delete(image);
}else usleep(100);}while(images==before && now()<deadline);
assert(images>before);
}
}else if(id==AMEDIACODEC_INFO_OUTPUT_FORMAT_CHANGED){auto *out=AMediaCodec_getOutputFormat(codec);printf("Output: %s\n",AMediaFormat_toString(out));AMediaFormat_delete(out);fflush(stdout);}
if(reader){AImage *image=nullptr;while(AImageReader_acquireNextImage(reader,&image)==AMEDIA_OK){images++;AImage_delete(image);}}
}
printf("Phase %u: %u decoded frames, %u surface images, %.3f seconds\n",phase,received,images,now()-start);fflush(stdout);
assert(output_eos && received==goal);if(reader)assert(images>=goal-2);
if(!phase){assert(AMediaCodec_flush(codec)==AMEDIA_OK);assert(AMediaExtractor_seekTo(extractor,0,AMEDIAEXTRACTOR_SEEK_PREVIOUS_SYNC)==AMEDIA_OK);}
}
assert(AMediaCodec_stop(codec)==AMEDIA_OK);AMediaCodec_delete(codec);if(reader)AImageReader_delete(reader);
AMediaFormat_delete(format);AMediaExtractor_delete(extractor);close(fd);puts(fallback?"PASS stock fallback playback and seeking":"PASS MediaCodec default selection, full-resolution playback and seeking");
}
+32
View File
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<MediaCodecs>
<Decoders>
<MediaCodec name="OMX.frameport.hevc.decoder" type="video/hevc" rank="64">
<Limit name="size" min="128x128" max="8192x8192" />
<Limit name="alignment" value="2x2" />
<Limit name="block-size" value="16x16" />
<Limit name="block-count" range="1-138240" />
<Limit name="blocks-per-second" range="1-7864320" />
<Limit name="bitrate" range="1-245000000" />
<Limit name="concurrent-instances" max="1" />
</MediaCodec>
<MediaCodec name="OMX.frameport.avc.decoder" type="video/avc" rank="64">
<Limit name="size" min="128x128" max="8192x8192" />
<Limit name="alignment" value="2x2" />
<Limit name="block-size" value="16x16" />
<Limit name="block-count" range="1-138240" />
<Limit name="blocks-per-second" range="1-7864320" />
<Limit name="bitrate" range="1-245000000" />
<Limit name="concurrent-instances" max="1" />
</MediaCodec>
<MediaCodec name="OMX.frameport.vp9.decoder" type="video/x-vnd.on2.vp9" rank="64">
<Limit name="size" min="128x128" max="4096x2304" />
<Limit name="alignment" value="2x2" />
<Limit name="block-size" value="16x16" />
<Limit name="block-count" range="1-36864" />
<Limit name="blocks-per-second" range="1-2211840" />
<Limit name="bitrate" range="1-245000000" />
<Limit name="concurrent-instances" max="1" />
</MediaCodec>
</Decoders>
</MediaCodecs>
+297
View File
@@ -0,0 +1,297 @@
// Exercises the actual Android OMX component, including port renegotiation,
// output conversion, timestamps and normal state/buffer lifetimes.
#include <media/hardware/OMXPluginBase.h>
#include <media/hardware/HardwareAPI.h>
#include <media/stagefright/foundation/ColorUtils.h>
#include <media/openmax/OMX_Component.h>
#include <media/openmax/OMX_IndexExt.h>
#include <utils/String8.h>
#include <pthread.h>
#include <dlfcn.h>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <cstdlib>
#include <unistd.h>
#include <android/hardware_buffer.h>
#include <cutils/native_handle.h>
#include <sys/stat.h>
extern "C" const native_handle_t *AHardwareBuffer_getNativeHandle(const AHardwareBuffer*);
namespace android { ANativeWindowBuffer *AHardwareBuffer_to_ANativeWindowBuffer(AHardwareBuffer*); }
extern "C" {
#include <libavformat/avformat.h>
#include <libavcodec/bsf.h>
#include <libavutil/time.h>
}
struct Test {
pthread_mutex_t lock=PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t changed=PTHREAD_COND_INITIALIZER;
OMX_COMPONENTTYPE *component=nullptr;
OMX_BUFFERHEADERTYPE *input_free[64],*output_free[64];
unsigned in_count=0,out_count=0,frames=0;
bool resize=false,eos=false,error=false;
unsigned state=OMX_StateLoaded,port_event=0;
OMX_COMMANDTYPE port_command=OMX_CommandStateSet;
int64_t last_pts=-1;
uint64_t first_hash=0;
uint64_t pictures[120]={};
bool replay=false;
bool native=false;
unsigned width=0,height=0;
AHardwareBuffer *hardware[16]={};
};
static OMX_ERRORTYPE event(OMX_HANDLETYPE,OMX_PTR data,OMX_EVENTTYPE type,OMX_U32 a,OMX_U32 b,OMX_PTR) {
auto &t=*(Test*)data;pthread_mutex_lock(&t.lock);
if(type==OMX_EventError){fprintf(stderr,"OMX error: %x %x\n",a,b);t.error=true;}
// As ACodec: only definition changes reallocate; crop/colour are updates.
if(type==OMX_EventPortSettingsChanged && a==1 && (b==0 || b==OMX_IndexParamPortDefinition))t.resize=true;
if(type==OMX_EventCmdComplete) {
if(a==OMX_CommandStateSet)t.state=b;
else {t.port_event=b==OMX_ALL?2:b+1;t.port_command=(OMX_COMMANDTYPE)a;}
}
pthread_cond_broadcast(&t.changed);pthread_mutex_unlock(&t.lock);return OMX_ErrorNone;
}
static OMX_ERRORTYPE empty(OMX_HANDLETYPE,OMX_PTR data,OMX_BUFFERHEADERTYPE *header) {
auto &t=*(Test*)data;pthread_mutex_lock(&t.lock);assert(t.in_count<64);
t.input_free[t.in_count++]=header;pthread_cond_broadcast(&t.changed);pthread_mutex_unlock(&t.lock);return OMX_ErrorNone;
}
static OMX_ERRORTYPE fill(OMX_HANDLETYPE,OMX_PTR data,OMX_BUFFERHEADERTYPE *header) {
auto &t=*(Test*)data;pthread_mutex_lock(&t.lock);assert(t.out_count<64);
if(header->nFilledLen) {
AHardwareBuffer_Planes planes={};AHardwareBuffer *hardware=nullptr;
if(t.native){
auto *meta=reinterpret_cast<android::VideoNativeMetadata*>(header->pBuffer);
for(auto *b:t.hardware)if(b && android::AHardwareBuffer_to_ANativeWindowBuffer(b)==meta->pBuffer)hardware=b;
assert(hardware);
assert(AHardwareBuffer_lockPlanes(hardware,AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN,meta->nFenceFd,nullptr,&planes)==0);
if(meta->nFenceFd>=0)close(meta->nFenceFd);meta->nFenceFd=-1;
}
auto byte=[&](unsigned i)->uint8_t{
if(!t.native)return header->pBuffer[i];
unsigned y=t.width*t.height,plane=i<y?0:i<y+y/4?1:2;
unsigned index=plane?i-y-(plane==2?y/4:0):i,width=plane?t.width/2:t.width;
return ((uint8_t*)planes.planes[plane].data)[(index/width)*planes.planes[plane].rowStride+
(index%width)*planes.planes[plane].pixelStride];
};
if(t.frames<120){
uint64_t hash=1469598103934665603ull;
unsigned pixel_bytes=t.native?t.width*t.height*3/2:header->nFilledLen;
unsigned step=pixel_bytes/1024;if(!step)step=1;
for(unsigned i=0;i<pixel_bytes;i+=step){hash^=byte(i);hash*=1099511628211ull;}
if(t.replay && t.pictures[t.frames]!=hash){
fprintf(stderr,"Picture %u changed after seek/recovery\n",t.frames);t.error=true;
}
t.pictures[t.frames]=hash;
}
if(!t.frames){
uint64_t hash=1469598103934665603ull;
unsigned pixel_bytes=t.native?t.width*t.height*3/2:header->nFilledLen;
for(unsigned i=0;i<pixel_bytes;i++){hash^=byte(i);hash*=1099511628211ull;}
printf("First-picture hash: %016llx\n",(unsigned long long)hash);fflush(stdout);
if(t.first_hash && t.first_hash!=hash){fprintf(stderr,"Seek did not reproduce the first picture\n");t.error=true;}
t.first_hash=hash;
}
if(header->nTimeStamp<t.last_pts){fprintf(stderr,"PTS went backwards\n");t.error=true;}
t.last_pts=header->nTimeStamp;t.frames++;
if(hardware)assert(AHardwareBuffer_unlock(hardware,nullptr)==0);
}
if(header->nFlags&OMX_BUFFERFLAG_EOS)t.eos=true;
t.output_free[t.out_count++]=header;
pthread_cond_broadcast(&t.changed);pthread_mutex_unlock(&t.lock);return OMX_ErrorNone;
}
template<class T>static T parameter(unsigned port) {T p={};p.nSize=sizeof(p);p.nVersion.s.nVersionMajor=1;p.nPortIndex=port;return p;}
static void wait_state(Test &t,unsigned state) {
pthread_mutex_lock(&t.lock);while(!t.error && t.state!=state)pthread_cond_wait(&t.changed,&t.lock);
assert(!t.error);pthread_mutex_unlock(&t.lock);
}
static void wait_port(Test &t,OMX_COMMANDTYPE command) {
pthread_mutex_lock(&t.lock);while(!t.error && !(t.port_event==2 && t.port_command==command))pthread_cond_wait(&t.changed,&t.lock);
assert(!t.error);t.port_event=0;pthread_mutex_unlock(&t.lock);
}
static void allocate(Test &t,unsigned port,OMX_BUFFERHEADERTYPE **headers,unsigned &count) {
auto def=parameter<OMX_PARAM_PORTDEFINITIONTYPE>(port);
assert(t.component->GetParameter(t.component,OMX_IndexParamPortDefinition,&def)==OMX_ErrorNone);
count=def.nBufferCountActual;assert(count<=16);
printf("Allocate port %u: %ux%u, %u buffers x %u bytes\n",port,def.format.video.nFrameWidth,def.format.video.nFrameHeight,count,def.nBufferSize);fflush(stdout);
for(unsigned i=0;i<count;i++)assert(t.component->AllocateBuffer(t.component,&headers[i],port,nullptr,def.nBufferSize)==OMX_ErrorNone);
if(port==1 && t.native){
t.width=def.format.video.nFrameWidth;t.height=def.format.video.nFrameHeight;
for(unsigned i=0;i<count;i++){
AHardwareBuffer_Desc d={};d.width=t.width;d.height=t.height;d.layers=1;d.format=AHARDWAREBUFFER_FORMAT_Y8Cb8Cr8_420;
d.usage=AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN|AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN|AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE;
assert(AHardwareBuffer_allocate(&d,&t.hardware[i])==0);
if(!i){auto *handle=AHardwareBuffer_getNativeHandle(t.hardware[i]);
printf("Native buffer handles: %d\n",handle->numFds);
for(int fd=0;fd<handle->numFds;fd++){struct stat st={};assert(fstat(handle->data[fd],&st)==0);
printf(" fd %d: device=%llu inode=%llu bytes=%lld\n",fd,(unsigned long long)st.st_dev,
(unsigned long long)st.st_ino,(long long)st.st_size);}fflush(stdout);}
auto *meta=reinterpret_cast<android::VideoNativeMetadata*>(headers[i]->pBuffer);
meta->eType=android::kMetadataBufferTypeANWBuffer;meta->pBuffer=android::AHardwareBuffer_to_ANativeWindowBuffer(t.hardware[i]);
meta->nFenceFd=-1;
}
}
}
static void queue_output(Test &t) {
for(;;) {
pthread_mutex_lock(&t.lock);
if(!t.out_count || t.resize || t.eos){pthread_mutex_unlock(&t.lock);return;}
auto *header=t.output_free[--t.out_count];pthread_mutex_unlock(&t.lock);
header->nFilledLen=0;header->nFlags=0;
assert(t.component->FillThisBuffer(t.component,header)==OMX_ErrorNone);
}
}
int main(int argc,char **argv) {
alarm(60);
assert(argc==2 || argc==3);const char *path=getenv("FRAMEPORT_PROBE_CODEC");
void *lib=dlopen(path?path:"/probe/libstagefrighthw.so",RTLD_NOW);
if(!lib){fprintf(stderr,"%s\n",dlerror());return 1;}
auto factory=(android::OMXPluginBase*(*)())dlsym(lib,"createOMXPlugin");assert(factory);
auto *plugin=factory();Test t;OMX_CALLBACKTYPE callbacks={event,empty,fill};
t.native=argc==3 && (!strcmp(argv[2],"native") || !strcmp(argv[2],"native_cpu") || !strcmp(argv[2],"native_importfail"));
if(t.native && !strcmp(argv[2],"native_cpu")){
auto deny=(void(*)())dlsym(RTLD_DEFAULT,"frameport_probe_deny_gpu");assert(deny);deny();
}
if(t.native && !strcmp(argv[2],"native_importfail")){
auto deny=(void(*)())dlsym(RTLD_DEFAULT,"frameport_probe_deny_gpu_import");assert(deny);deny();
}
if(argc==3 && (!strcmp(argv[2],"software") || !strcmp(argv[2],"software_rgba"))){
auto deny=(void(*)())dlsym(RTLD_DEFAULT,"frameport_probe_deny_device");assert(deny);deny();
}
if(argc==3 && !strcmp(argv[2],"recover")){
auto corrupt=(void(*)())dlsym(RTLD_DEFAULT,"frameport_probe_corrupt_picture");assert(corrupt);corrupt();
}
if(argc==3 && !strcmp(argv[2],"restartfail")){
auto deny=(void(*)())dlsym(RTLD_DEFAULT,"frameport_probe_deny_restart");assert(deny);deny();
}
AVFormatContext *format=nullptr;assert(avformat_open_input(&format,argv[1],nullptr,nullptr)>=0);
unsigned video=0;while(video<format->nb_streams && format->streams[video]->codecpar->codec_type!=AVMEDIA_TYPE_VIDEO)video++;
assert(video<format->nb_streams);auto *stream=format->streams[video];
const char *name=nullptr,*filter=nullptr;
switch(stream->codecpar->codec_id){
case AV_CODEC_ID_HEVC:name="OMX.frameport.hevc.decoder";filter="hevc_mp4toannexb";break;
case AV_CODEC_ID_H264:name="OMX.frameport.avc.decoder";filter="h264_mp4toannexb";break;
case AV_CODEC_ID_VP9:name="OMX.frameport.vp9.decoder";break;
default:assert(false);
}
printf("Testing %s\n",name);fflush(stdout);
assert(plugin->makeComponentInstance(name,&callbacks,&t,&t.component)==OMX_ErrorNone);
if(t.native)for(const char *name:{"OMX.google.android.index.enableAndroidNativeBuffers","OMX.google.android.index.storeANWBufferInMetadata"}){
OMX_INDEXTYPE index;assert(t.component->GetExtensionIndex(t.component,(char*)name,&index)==OMX_ErrorNone);
auto mode=parameter<android::EnableAndroidNativeBuffersParams>(1);mode.enable=OMX_TRUE;
assert(t.component->SetParameter(t.component,index,&mode)==OMX_ErrorNone);
}
// ACodec supplies the container's colour metadata before decoding. Use the
// same contract so full-range fixtures exercise the intended conversion.
auto *par=stream->codecpar;
if(par->color_primaries!=AVCOL_PRI_UNSPECIFIED || par->color_trc!=AVCOL_TRC_UNSPECIFIED ||
par->color_space!=AVCOL_SPC_UNSPECIFIED || par->color_range!=AVCOL_RANGE_UNSPECIFIED) {
OMX_INDEXTYPE index;
char extension[]="OMX.google.android.index.describeColorAspects";
assert(t.component->GetExtensionIndex(t.component,extension,&index)==OMX_ErrorNone);
auto aspects=parameter<android::DescribeColorAspectsParams>(1);
android::ColorUtils::convertIsoColorAspectsToCodecAspects(par->color_primaries,par->color_trc,
par->color_space,par->color_range==AVCOL_RANGE_JPEG,aspects.sAspects);
assert(t.component->SetConfig(t.component,index,&aspects)==OMX_ErrorNone);
}
if(argc==3 && (!strcmp(argv[2],"rgba") || !strcmp(argv[2],"software_rgba"))) {
auto mode=parameter<OMX_PARAM_U32TYPE>(1);
assert(t.component->GetParameter(t.component,(OMX_INDEXTYPE)OMX_IndexParamVideoAndroidRequiresSwRenderer,&mode)==OMX_ErrorNone);
assert(mode.nU32==1);
}
AVBSFContext *bsf=nullptr;
if(filter){assert(av_bsf_alloc(av_bsf_get_by_name(filter),&bsf)>=0);
assert(avcodec_parameters_copy(bsf->par_in,stream->codecpar)>=0);bsf->time_base_in=stream->time_base;assert(av_bsf_init(bsf)>=0);}
auto input_def=parameter<OMX_PARAM_PORTDEFINITIONTYPE>(0);
assert(t.component->GetParameter(t.component,OMX_IndexParamPortDefinition,&input_def)==OMX_ErrorNone);
input_def.format.video.nFrameWidth=stream->codecpar->width;input_def.format.video.nFrameHeight=stream->codecpar->height;
assert(t.component->SetParameter(t.component,OMX_IndexParamPortDefinition,&input_def)==OMX_ErrorNone);
OMX_BUFFERHEADERTYPE *inputs[16],*outputs[16];unsigned input_count,output_count;
assert(t.component->SendCommand(t.component,OMX_CommandStateSet,OMX_StateIdle,nullptr)==OMX_ErrorNone);
allocate(t,0,inputs,input_count);allocate(t,1,outputs,output_count);wait_state(t,OMX_StateIdle);
for(unsigned i=0;i<input_count;i++)t.input_free[t.in_count++]=inputs[i];
for(unsigned i=0;i<output_count;i++)t.output_free[t.out_count++]=outputs[i];
assert(t.component->SendCommand(t.component,OMX_CommandStateSet,OMX_StateExecuting,nullptr)==OMX_ErrorNone);wait_state(t,OMX_StateExecuting);
AVPacket *packet=av_packet_alloc();
// midseek: seek mid-playback (no EOS first), as players usually do.
bool midseek=argc==3 && !strcmp(argv[2],"midseek");
for(unsigned phase=0;phase<2;phase++) {
bool sent_config=false,sent_eos=false,resent_config=false;unsigned submitted=0;
unsigned goal=phase?120:midseek?300:600;
int64_t start=av_gettime_relative();
for(;;) {
queue_output(t);
pthread_mutex_lock(&t.lock);
while(!t.error && !t.resize && !t.eos && (sent_eos || !t.in_count) && !t.out_count)pthread_cond_wait(&t.changed,&t.lock);
assert(!t.error);
bool resized=t.resize;t.resize=false;bool finished=t.eos;
pthread_mutex_unlock(&t.lock);
if(finished)break;
if(midseek && !phase && submitted>=goal) {
pthread_mutex_lock(&t.lock);bool enough=t.frames>=200;pthread_mutex_unlock(&t.lock);
if(enough)break;
usleep(1000);
}
if(resized) {
assert(t.component->SendCommand(t.component,OMX_CommandPortDisable,1,nullptr)==OMX_ErrorNone);
pthread_mutex_lock(&t.lock);while(t.out_count<output_count && !t.error)pthread_cond_wait(&t.changed,&t.lock);assert(!t.error);t.out_count=0;pthread_mutex_unlock(&t.lock);
for(unsigned i=0;i<output_count;i++)assert(t.component->FreeBuffer(t.component,1,outputs[i])==OMX_ErrorNone);
if(t.native)for(auto &b:t.hardware)if(b){AHardwareBuffer_release(b);b=nullptr;}
wait_port(t,OMX_CommandPortDisable);
assert(t.component->SendCommand(t.component,OMX_CommandPortEnable,1,nullptr)==OMX_ErrorNone);
allocate(t,1,outputs,output_count);wait_port(t,OMX_CommandPortEnable);
pthread_mutex_lock(&t.lock);for(unsigned i=0;i<output_count;i++)t.output_free[t.out_count++]=outputs[i];pthread_mutex_unlock(&t.lock);
continue;
}
if(sent_eos || (midseek && !phase && submitted>=goal))continue;
pthread_mutex_lock(&t.lock);
auto *header=t.in_count?t.input_free[--t.in_count]:nullptr;pthread_mutex_unlock(&t.lock);
if(!header)continue;
header->nOffset=0;header->nFilledLen=0;header->nTimeStamp=0;header->nFlags=0;
// midconfig: parameter sets sent again mid-stream without a flush.
bool midconfig=argc==3 && !strcmp(argv[2],"midconfig") && !phase && submitted==300 && !resent_config;
if(!sent_config || midconfig) {
const auto *params=bsf?bsf->par_out:stream->codecpar;
if(midconfig){resent_config=true;puts("Resending codec configuration mid-stream.");fflush(stdout);}
assert((unsigned)params->extradata_size<=header->nAllocLen);
if(params->extradata_size)memcpy(header->pBuffer,params->extradata,params->extradata_size);
header->nFilledLen=params->extradata_size;header->nFlags=OMX_BUFFERFLAG_CODECCONFIG;sent_config=true;
} else if(submitted>=goal) {
header->nFlags=OMX_BUFFERFLAG_EOS;header->nTimeStamp=goal*1000000/60;sent_eos=true;
} else {
int result;
do{result=av_read_frame(format,packet);assert(result>=0);if(packet->stream_index!=(int)video)av_packet_unref(packet);}while(packet->stream_index!=(int)video);
if(bsf){assert(av_bsf_send_packet(bsf,packet)>=0);assert(av_bsf_receive_packet(bsf,packet)>=0);}
av_packet_rescale_ts(packet,stream->time_base,AVRational{1,1000000});
assert((unsigned)packet->size<=header->nAllocLen);memcpy(header->pBuffer,packet->data,packet->size);header->nFilledLen=packet->size;
header->nTimeStamp=packet->pts;header->nFlags=OMX_BUFFERFLAG_ENDOFFRAME;
// Recovery runs model ACodec decoder input, which omits SYNCFRAME.
if((packet->flags&AV_PKT_FLAG_KEY) && !(argc==3 && !strcmp(argv[2],"recover")))
header->nFlags|=OMX_BUFFERFLAG_SYNCFRAME;
if(submitted<2){printf("Input phase %u: pts=%lld key=%d bytes=%d\n",phase,(long long)packet->pts,
!!(packet->flags&AV_PKT_FLAG_KEY),packet->size);fflush(stdout);}
av_packet_unref(packet);submitted++;
}
assert(t.component->EmptyThisBuffer(t.component,header)==OMX_ErrorNone);
}
double seconds=(av_gettime_relative()-start)/1000000.0;
printf("OMX decode + full-size delivery: %u frames in %.3fs = %.1ffps\n",t.frames,seconds,t.frames/seconds);fflush(stdout);
assert(midseek && !phase?t.frames>=200:t.frames==goal);
if(!phase) {
assert(t.component->SendCommand(t.component,OMX_CommandFlush,OMX_ALL,nullptr)==OMX_ErrorNone);
wait_port(t,OMX_CommandFlush);
assert(av_seek_frame(format,video,0,AVSEEK_FLAG_BACKWARD)>=0);if(bsf)av_bsf_flush(bsf);
pthread_mutex_lock(&t.lock);t.eos=false;t.frames=0;t.last_pts=-1;t.replay=true;pthread_mutex_unlock(&t.lock);
puts("Replaying after a complete OMX flush and seek to the beginning.");
}
}
assert(t.component->SendCommand(t.component,OMX_CommandStateSet,OMX_StateIdle,nullptr)==OMX_ErrorNone);wait_state(t,OMX_StateIdle);
assert(t.component->SendCommand(t.component,OMX_CommandStateSet,OMX_StateLoaded,nullptr)==OMX_ErrorNone);
for(unsigned i=0;i<input_count;i++)assert(t.component->FreeBuffer(t.component,0,inputs[i])==OMX_ErrorNone);
for(unsigned i=0;i<output_count;i++)assert(t.component->FreeBuffer(t.component,1,outputs[i])==OMX_ErrorNone);
if(t.native)for(auto &b:t.hardware)if(b){AHardwareBuffer_release(b);b=nullptr;}
wait_state(t,OMX_StateLoaded);assert(plugin->destroyComponentInstance(t.component)==OMX_ErrorNone);
delete plugin;dlclose(lib);av_packet_free(&packet);av_bsf_free(&bsf);avformat_close_input(&format);
if(t.native){auto count=(unsigned(*)())dlsym(RTLD_DEFAULT,"frameport_probe_gpu_submissions");assert(count);
printf("GPU submissions: %u\n",count());assert(!strcmp(argv[2],"native")?count()>0:count()==0);}
puts("PASS: OMX decode, ordered timestamps, EOS, seek and shutdown.");
}
+350
View File
@@ -0,0 +1,350 @@
/*
* Copyright (C) 2009 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
/**
* @addtogroup Logging
* @{
*/
/**
* \file
*
* Support routines to send messages to the Android log buffer,
* which can later be accessed through the `logcat` utility.
*
* Each log message must have
* - a priority
* - a log tag
* - some text
*
* The tag normally corresponds to the component that emits the log message,
* and should be reasonably small.
*
* Log message text may be truncated to less than an implementation-specific
* limit (1023 bytes).
*
* Note that a newline character ("\n") will be appended automatically to your
* log message, if not already there. It is not possible to send several
* messages and have them appear on a single line in logcat.
*
* Please use logging in moderation:
*
* - Sending log messages eats CPU and slow down your application and the
* system.
*
* - The circular log buffer is pretty small, so sending many messages
* will hide other important log messages.
*
* - In release builds, only send log messages to account for exceptional
* conditions.
*/
#include <stdarg.h>
#include <stddef.h>
#include <stdint.h>
#include <sys/cdefs.h>
#if !defined(__BIONIC__) && !defined(__INTRODUCED_IN)
#define __INTRODUCED_IN(x)
#endif
#ifdef __cplusplus
extern "C" {
#endif
/**
* Android log priority values, in increasing order of priority.
*/
typedef enum android_LogPriority {
/** For internal use only. */
ANDROID_LOG_UNKNOWN = 0,
/** The default priority, for internal use only. */
ANDROID_LOG_DEFAULT, /* only for SetMinPriority() */
/** Verbose logging. Should typically be disabled for a release apk. */
ANDROID_LOG_VERBOSE,
/** Debug logging. Should typically be disabled for a release apk. */
ANDROID_LOG_DEBUG,
/** Informational logging. Should typically be disabled for a release apk. */
ANDROID_LOG_INFO,
/** Warning logging. For use with recoverable failures. */
ANDROID_LOG_WARN,
/** Error logging. For use with unrecoverable failures. */
ANDROID_LOG_ERROR,
/** Fatal logging. For use when aborting. */
ANDROID_LOG_FATAL,
/** For internal use only. */
ANDROID_LOG_SILENT, /* only for SetMinPriority(); must be last */
} android_LogPriority;
/**
* Writes the constant string `text` to the log, with priority `prio` and tag
* `tag`.
*/
int __android_log_write(int prio, const char* tag, const char* text);
/**
* Writes a formatted string to the log, with priority `prio` and tag `tag`.
* The details of formatting are the same as for
* [printf(3)](http://man7.org/linux/man-pages/man3/printf.3.html).
*/
int __android_log_print(int prio, const char* tag, const char* fmt, ...)
__attribute__((__format__(printf, 3, 4)));
/**
* Equivalent to `__android_log_print`, but taking a `va_list`.
* (If `__android_log_print` is like `printf`, this is like `vprintf`.)
*/
int __android_log_vprint(int prio, const char* tag, const char* fmt, va_list ap)
__attribute__((__format__(printf, 3, 0)));
/**
* Writes an assertion failure to the log (as `ANDROID_LOG_FATAL`) and to
* stderr, before calling
* [abort(3)](http://man7.org/linux/man-pages/man3/abort.3.html).
*
* If `fmt` is non-null, `cond` is unused. If `fmt` is null, the string
* `Assertion failed: %s` is used with `cond` as the string argument.
* If both `fmt` and `cond` are null, a default string is provided.
*
* Most callers should use
* [assert(3)](http://man7.org/linux/man-pages/man3/assert.3.html) from
* `&lt;assert.h&gt;` instead, or the `__assert` and `__assert2` functions
* provided by bionic if more control is needed. They support automatically
* including the source filename and line number more conveniently than this
* function.
*/
void __android_log_assert(const char* cond, const char* tag, const char* fmt, ...)
__attribute__((__noreturn__)) __attribute__((__format__(printf, 3, 4)));
/**
* Identifies a specific log buffer for __android_log_buf_write()
* and __android_log_buf_print().
*/
typedef enum log_id {
LOG_ID_MIN = 0,
/** The main log buffer. This is the only log buffer available to apps. */
LOG_ID_MAIN = 0,
/** The radio log buffer. */
LOG_ID_RADIO = 1,
/** The event log buffer. */
LOG_ID_EVENTS = 2,
/** The system log buffer. */
LOG_ID_SYSTEM = 3,
/** The crash log buffer. */
LOG_ID_CRASH = 4,
/** The statistics log buffer. */
LOG_ID_STATS = 5,
/** The security log buffer. */
LOG_ID_SECURITY = 6,
/** The kernel log buffer. */
LOG_ID_KERNEL = 7,
LOG_ID_MAX,
/** Let the logging function choose the best log target. */
LOG_ID_DEFAULT = 0x7FFFFFFF
} log_id_t;
/**
* Writes the constant string `text` to the log buffer `id`,
* with priority `prio` and tag `tag`.
*
* Apps should use __android_log_write() instead.
*/
int __android_log_buf_write(int bufID, int prio, const char* tag, const char* text);
/**
* Writes a formatted string to log buffer `id`,
* with priority `prio` and tag `tag`.
* The details of formatting are the same as for
* [printf(3)](http://man7.org/linux/man-pages/man3/printf.3.html).
*
* Apps should use __android_log_print() instead.
*/
int __android_log_buf_print(int bufID, int prio, const char* tag, const char* fmt, ...)
__attribute__((__format__(printf, 4, 5)));
/**
* Logger data struct used for writing log messages to liblog via __android_log_write_logger_data()
* and sending log messages to user defined loggers specified in __android_log_set_logger().
*/
struct __android_log_message {
size_t
struct_size; /** Must be set to sizeof(__android_log_message) and is used for versioning. */
int32_t buffer_id; /** {@link log_id_t} values. */
int32_t priority; /** {@link android_LogPriority} values. */
const char* tag; /** The tag for the log message. */
const char* file; /** Optional file name, may be set to nullptr. */
uint32_t line; /** Optional line number, ignore if file is nullptr. */
const char* message; /** The log message itself. */
};
/**
* Prototype for the 'logger' function that is called for every log message.
*/
typedef void (*__android_logger_function)(const struct __android_log_message* log_message);
/**
* Prototype for the 'abort' function that is called when liblog will abort due to
* __android_log_assert() failures.
*/
typedef void (*__android_aborter_function)(const char* abort_message);
#if !defined(__ANDROID__) || __ANDROID_API__ >= 30
/**
* Writes the log message specified by log_message. log_message includes additional file name and
* line number information that a logger may use. log_message is versioned for backwards
* compatibility.
* This assumes that loggability has already been checked through __android_log_is_loggable().
* Higher level logging libraries, such as libbase, first check loggability, then format their
* buffers, then pass the message to liblog via this function, and therefore we do not want to
* duplicate the loggability check here.
*
* @param log_message the log message itself, see {@link __android_log_message}.
*
* Available since API level 30.
*/
void __android_log_write_log_message(struct __android_log_message* log_message) __INTRODUCED_IN(30);
/**
* Sets a user defined logger function. All log messages sent to liblog will be set to the
* function pointer specified by logger for processing. It is not expected that log messages are
* already terminated with a new line. This function should add new lines if required for line
* separation.
*
* @param logger the new function that will handle log messages.
*
* Available since API level 30.
*/
void __android_log_set_logger(__android_logger_function logger) __INTRODUCED_IN(30);
/**
* Writes the log message to logd. This is an __android_logger_function and can be provided to
* __android_log_set_logger(). It is the default logger when running liblog on a device.
*
* @param log_message the log message to write, see {@link __android_log_message}.
*
* Available since API level 30.
*/
void __android_log_logd_logger(const struct __android_log_message* log_message) __INTRODUCED_IN(30);
/**
* Writes the log message to stderr. This is an __android_logger_function and can be provided to
* __android_log_set_logger(). It is the default logger when running liblog on host.
*
* @param log_message the log message to write, see {@link __android_log_message}.
*
* Available since API level 30.
*/
void __android_log_stderr_logger(const struct __android_log_message* log_message)
__INTRODUCED_IN(30);
/**
* Sets a user defined aborter function that is called for __android_log_assert() failures. This
* user defined aborter function is highly recommended to abort and be noreturn, but is not strictly
* required to.
*
* @param aborter the new aborter function, see {@link __android_aborter_function}.
*
* Available since API level 30.
*/
void __android_log_set_aborter(__android_aborter_function aborter) __INTRODUCED_IN(30);
/**
* Calls the stored aborter function. This allows for other logging libraries to use the same
* aborter function by calling this function in liblog.
*
* @param abort_message an additional message supplied when aborting, for example this is used to
* call android_set_abort_message() in __android_log_default_aborter().
*
* Available since API level 30.
*/
void __android_log_call_aborter(const char* abort_message) __INTRODUCED_IN(30);
/**
* Sets android_set_abort_message() on device then aborts(). This is the default aborter.
*
* @param abort_message an additional message supplied when aborting. This functions calls
* android_set_abort_message() with its contents.
*
* Available since API level 30.
*/
void __android_log_default_aborter(const char* abort_message) __attribute__((noreturn))
__INTRODUCED_IN(30);
/**
* Use the per-tag properties "log.tag.<tagname>" along with the minimum priority from
* __android_log_set_minimum_priority() to determine if a log message with a given prio and tag will
* be printed. A non-zero result indicates yes, zero indicates false.
*
* If both a priority for a tag and a minimum priority are set by
* __android_log_set_minimum_priority(), then the lowest of the two values are to determine the
* minimum priority needed to log. If only one is set, then that value is used to determine the
* minimum priority needed. If none are set, then default_priority is used.
*
* @param prio the priority to test, takes {@link android_LogPriority} values.
* @param tag the tag to test.
* @param len the length of the tag.
* @param default_prio the default priority to use if no properties or minimum priority are set.
* @return an integer where 1 indicates that the message is loggable and 0 indicates that it is not.
*
* Available since API level 30.
*/
int __android_log_is_loggable(int prio, const char* tag, int default_prio) __INTRODUCED_IN(30);
int __android_log_is_loggable_len(int prio, const char* tag, size_t len, int default_prio)
__INTRODUCED_IN(30);
/**
* Sets the minimum priority that will be logged for this process.
*
* @param priority the new minimum priority to set, takes @{link android_LogPriority} values.
* @return the previous set minimum priority as @{link android_LogPriority} values, or
* ANDROID_LOG_DEFAULT if none was set.
*
* Available since API level 30.
*/
int32_t __android_log_set_minimum_priority(int32_t priority) __INTRODUCED_IN(30);
/**
* Gets the minimum priority that will be logged for this process. If none has been set by a
* previous __android_log_set_minimum_priority() call, this returns ANDROID_LOG_DEFAULT.
*
* @return the current minimum priority as @{link android_LogPriority} values, or
* ANDROID_LOG_DEFAULT if none is set.
*
* Available since API level 30.
*/
int32_t __android_log_get_minimum_priority(void) __INTRODUCED_IN(30);
/**
* Sets the default tag if no tag is provided when writing a log message. Defaults to
* getprogname(). This truncates tag to the maximum log message size, though appropriate tags
* should be much smaller.
*
* @param tag the new log tag.
*
* Available since API level 30.
*/
void __android_log_set_default_tag(const char* tag) __INTRODUCED_IN(30);
#endif
#ifdef __cplusplus
}
#endif
/** @} */
+106
View File
@@ -0,0 +1,106 @@
/*
* Copyright (C) 2009 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef NATIVE_HANDLE_H_
#define NATIVE_HANDLE_H_
#include <stdalign.h>
#ifdef __cplusplus
extern "C" {
#endif
#define NATIVE_HANDLE_MAX_FDS 1024
#define NATIVE_HANDLE_MAX_INTS 1024
/* Declare a char array for use with native_handle_init */
#define NATIVE_HANDLE_DECLARE_STORAGE(name, maxFds, maxInts) \
alignas(native_handle_t) char (name)[ \
sizeof(native_handle_t) + sizeof(int) * ((maxFds) + (maxInts))]
typedef struct native_handle
{
int version; /* sizeof(native_handle_t) */
int numFds; /* number of file-descriptors at &data[0] */
int numInts; /* number of ints at &data[numFds] */
#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wzero-length-array"
#endif
int data[0]; /* numFds + numInts ints */
#if defined(__clang__)
#pragma clang diagnostic pop
#endif
} native_handle_t;
typedef const native_handle_t* buffer_handle_t;
/*
* native_handle_close
*
* closes the file descriptors contained in this native_handle_t
*
* return 0 on success, or a negative error code on failure
*
*/
int native_handle_close(const native_handle_t* h);
/*
* native_handle_init
*
* Initializes a native_handle_t from storage. storage must be declared with
* NATIVE_HANDLE_DECLARE_STORAGE. numFds and numInts must not respectively
* exceed maxFds and maxInts used to declare the storage.
*/
native_handle_t* native_handle_init(char* storage, int numFds, int numInts);
/*
* native_handle_create
*
* creates a native_handle_t and initializes it. must be destroyed with
* native_handle_delete(). Note that numFds must be <= NATIVE_HANDLE_MAX_FDS,
* numInts must be <= NATIVE_HANDLE_MAX_INTS, and both must be >= 0.
*
*/
native_handle_t* native_handle_create(int numFds, int numInts);
/*
* native_handle_clone
*
* creates a native_handle_t and initializes it from another native_handle_t.
* Must be destroyed with native_handle_delete().
*
*/
native_handle_t* native_handle_clone(const native_handle_t* handle);
/*
* native_handle_delete
*
* frees a native_handle_t allocated with native_handle_create().
* This ONLY frees the memory allocated for the native_handle_t, but doesn't
* close the file descriptors; which can be achieved with native_handle_close().
*
* return 0 on success, or a negative error code on failure
*
*/
int native_handle_delete(native_handle_t* h);
#ifdef __cplusplus
}
#endif
#endif /* NATIVE_HANDLE_H_ */
+156
View File
@@ -0,0 +1,156 @@
/*
* Copyright (C) 2005-2014 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
/* Too many in the ecosystem assume these are included */
#if !defined(_WIN32)
#include <pthread.h>
#endif
#include <stdint.h> /* uint16_t, int32_t */
#include <stdio.h>
#include <time.h>
#include <unistd.h>
#include <android/log.h>
#include <log/log_id.h>
#include <log/log_main.h>
#include <log/log_radio.h>
#include <log/log_read.h>
#include <log/log_safetynet.h>
#include <log/log_system.h>
#include <log/log_time.h>
#ifdef __cplusplus
extern "C" {
#endif
/*
* LOG_TAG is the local tag used for the following simplified
* logging macros. You can change this preprocessor definition
* before using the other macros to change the tag.
*/
#ifndef LOG_TAG
#define LOG_TAG NULL
#endif
/*
* Normally we strip the effects of ALOGV (VERBOSE messages),
* LOG_FATAL and LOG_FATAL_IF (FATAL assert messages) from the
* release builds be defining NDEBUG. You can modify this (for
* example with "#define LOG_NDEBUG 0" at the top of your source
* file) to change that behavior.
*/
#ifndef LOG_NDEBUG
#ifdef NDEBUG
#define LOG_NDEBUG 1
#else
#define LOG_NDEBUG 0
#endif
#endif
/*
* Event logging.
*/
/*
* The following should not be used directly.
*/
int __android_log_bwrite(int32_t tag, const void* payload, size_t len);
int __android_log_btwrite(int32_t tag, char type, const void* payload,
size_t len);
int __android_log_bswrite(int32_t tag, const char* payload);
int __android_log_stats_bwrite(int32_t tag, const void* payload, size_t len);
#define android_bWriteLog(tag, payload, len) \
__android_log_bwrite(tag, payload, len)
#define android_btWriteLog(tag, type, payload, len) \
__android_log_btwrite(tag, type, payload, len)
/*
* Event log entry types.
*/
#ifndef __AndroidEventLogType_defined
#define __AndroidEventLogType_defined
typedef enum {
/* Special markers for android_log_list_element type */
EVENT_TYPE_LIST_STOP = '\n', /* declare end of list */
EVENT_TYPE_UNKNOWN = '?', /* protocol error */
/* must match with declaration in java/android/android/util/EventLog.java */
EVENT_TYPE_INT = 0, /* int32_t */
EVENT_TYPE_LONG = 1, /* int64_t */
EVENT_TYPE_STRING = 2,
EVENT_TYPE_LIST = 3,
EVENT_TYPE_FLOAT = 4,
} AndroidEventLogType;
#endif
#define sizeof_AndroidEventLogType sizeof(typeof_AndroidEventLogType)
#define typeof_AndroidEventLogType unsigned char
#ifndef LOG_EVENT_INT
#define LOG_EVENT_INT(_tag, _value) \
{ \
int intBuf = _value; \
(void)android_btWriteLog(_tag, EVENT_TYPE_INT, &intBuf, sizeof(intBuf)); \
}
#endif
#ifndef LOG_EVENT_LONG
#define LOG_EVENT_LONG(_tag, _value) \
{ \
long long longBuf = _value; \
(void)android_btWriteLog(_tag, EVENT_TYPE_LONG, &longBuf, sizeof(longBuf)); \
}
#endif
#ifndef LOG_EVENT_FLOAT
#define LOG_EVENT_FLOAT(_tag, _value) \
{ \
float floatBuf = _value; \
(void)android_btWriteLog(_tag, EVENT_TYPE_FLOAT, &floatBuf, \
sizeof(floatBuf)); \
}
#endif
#ifndef LOG_EVENT_STRING
#define LOG_EVENT_STRING(_tag, _value) \
(void)__android_log_bswrite(_tag, _value);
#endif
#ifdef __linux__
clockid_t android_log_clockid(void);
#endif /* __linux__ */
/* --------------------------------------------------------------------- */
/*
* Release any logger resources (a new log write will immediately re-acquire)
*
* This is specifically meant to be used by Zygote to close open file descriptors after fork()
* and before specialization. O_CLOEXEC is used on file descriptors, so they will be closed upon
* exec() in normal use cases.
*
* Note that this is not safe to call from a multi-threaded program.
*/
void __android_log_close(void);
#ifdef __cplusplus
}
#endif
+41
View File
@@ -0,0 +1,41 @@
/*
* Copyright (C) 2005-2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <android/log.h>
#ifdef __cplusplus
extern "C" {
#endif
/*
* Send a simple string to the log.
*/
int __android_log_buf_write(int bufID, int prio, const char* tag,
const char* text);
int __android_log_buf_print(int bufID, int prio, const char* tag, const char* fmt, ...)
__attribute__((__format__(printf, 4, 5)));
/*
* log_id_t helpers
*/
log_id_t android_name_to_log_id(const char* logName);
const char* android_log_id_to_name(log_id_t log_id);
#ifdef __cplusplus
}
#endif
+380
View File
@@ -0,0 +1,380 @@
/*
* Copyright (C) 2005-2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <stdbool.h>
#include <sys/cdefs.h>
#include <sys/types.h>
#include <android/log.h>
__BEGIN_DECLS
/*
* Normally we strip the effects of ALOGV (VERBOSE messages),
* LOG_FATAL and LOG_FATAL_IF (FATAL assert messages) from the
* release builds be defining NDEBUG. You can modify this (for
* example with "#define LOG_NDEBUG 0" at the top of your source
* file) to change that behavior.
*/
#ifndef LOG_NDEBUG
#ifdef NDEBUG
#define LOG_NDEBUG 1
#else
#define LOG_NDEBUG 0
#endif
#endif
/* --------------------------------------------------------------------- */
/*
* This file uses ", ## __VA_ARGS__" zero-argument token pasting to
* work around issues with debug-only syntax errors in assertions
* that are missing format strings. See commit
* 19299904343daf191267564fe32e6cd5c165cd42
*/
#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments"
#endif
/*
* Use __VA_ARGS__ if running a static analyzer,
* to avoid warnings of unused variables in __VA_ARGS__.
* Use constexpr function in C++ mode, so these macros can be used
* in other constexpr functions without warning.
*/
#ifdef __clang_analyzer__
#ifdef __cplusplus
extern "C++" {
template <typename... Ts>
constexpr int __fake_use_va_args(Ts...) {
return 0;
}
}
#else
extern int __fake_use_va_args(int, ...);
#endif /* __cplusplus */
#define __FAKE_USE_VA_ARGS(...) ((void)__fake_use_va_args(0, ##__VA_ARGS__))
#else
#define __FAKE_USE_VA_ARGS(...) ((void)(0))
#endif /* __clang_analyzer__ */
#ifndef __predict_false
#define __predict_false(exp) __builtin_expect((exp) != 0, 0)
#endif
#define android_writeLog(prio, tag, text) __android_log_write(prio, tag, text)
#define android_printLog(prio, tag, ...) \
__android_log_print(prio, tag, __VA_ARGS__)
#define android_vprintLog(prio, cond, tag, ...) \
__android_log_vprint(prio, tag, __VA_ARGS__)
/*
* Log macro that allows you to specify a number for the priority.
*/
#ifndef LOG_PRI
#define LOG_PRI(priority, tag, ...) android_printLog(priority, tag, __VA_ARGS__)
#endif
/*
* Log macro that allows you to pass in a varargs ("args" is a va_list).
*/
#ifndef LOG_PRI_VA
#define LOG_PRI_VA(priority, tag, fmt, args) \
android_vprintLog(priority, NULL, tag, fmt, args)
#endif
/* --------------------------------------------------------------------- */
/* XXX Macros to work around syntax errors in places where format string
* arg is not passed to ALOG_ASSERT, LOG_ALWAYS_FATAL or LOG_ALWAYS_FATAL_IF
* (happens only in debug builds).
*/
/* Returns 2nd arg. Used to substitute default value if caller's vararg list
* is empty.
*/
#define __android_second(dummy, second, ...) second
/* If passed multiple args, returns ',' followed by all but 1st arg, otherwise
* returns nothing.
*/
#define __android_rest(first, ...) , ##__VA_ARGS__
#define android_printAssert(cond, tag, ...) \
__android_log_assert(cond, tag, \
__android_second(0, ##__VA_ARGS__, NULL) \
__android_rest(__VA_ARGS__))
/*
* Log a fatal error. If the given condition fails, this stops program
* execution like a normal assertion, but also generating the given message.
* It is NOT stripped from release builds. Note that the condition test
* is -inverted- from the normal assert() semantics.
*/
#ifndef LOG_ALWAYS_FATAL_IF
#define LOG_ALWAYS_FATAL_IF(cond, ...) \
((__predict_false(cond)) ? (__FAKE_USE_VA_ARGS(__VA_ARGS__), \
((void)android_printAssert(#cond, LOG_TAG, ##__VA_ARGS__))) \
: ((void)0))
#endif
#ifndef LOG_ALWAYS_FATAL
#define LOG_ALWAYS_FATAL(...) \
(((void)android_printAssert(NULL, LOG_TAG, ##__VA_ARGS__)))
#endif
/*
* Versions of LOG_ALWAYS_FATAL_IF and LOG_ALWAYS_FATAL that
* are stripped out of release builds.
*/
#if LOG_NDEBUG
#ifndef LOG_FATAL_IF
#define LOG_FATAL_IF(cond, ...) __FAKE_USE_VA_ARGS(__VA_ARGS__)
#endif
#ifndef LOG_FATAL
#define LOG_FATAL(...) __FAKE_USE_VA_ARGS(__VA_ARGS__)
#endif
#else
#ifndef LOG_FATAL_IF
#define LOG_FATAL_IF(cond, ...) LOG_ALWAYS_FATAL_IF(cond, ##__VA_ARGS__)
#endif
#ifndef LOG_FATAL
#define LOG_FATAL(...) LOG_ALWAYS_FATAL(__VA_ARGS__)
#endif
#endif
/*
* Assertion that generates a log message when the assertion fails.
* Stripped out of release builds. Uses the current LOG_TAG.
*/
#ifndef ALOG_ASSERT
#define ALOG_ASSERT(cond, ...) LOG_FATAL_IF(!(cond), ##__VA_ARGS__)
#endif
/* --------------------------------------------------------------------- */
/*
* C/C++ logging functions. See the logging documentation for API details.
*
* We'd like these to be available from C code (in case we import some from
* somewhere), so this has a C interface.
*
* The output will be correct when the log file is shared between multiple
* threads and/or multiple processes so long as the operating system
* supports O_APPEND. These calls have mutex-protected data structures
* and so are NOT reentrant. Do not use LOG in a signal handler.
*/
/* --------------------------------------------------------------------- */
/*
* Simplified macro to send a verbose log message using the current LOG_TAG.
*/
#ifndef ALOGV
#define __ALOGV(...) ((void)ALOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
#if LOG_NDEBUG
#define ALOGV(...) \
do { \
__FAKE_USE_VA_ARGS(__VA_ARGS__); \
if (false) { \
__ALOGV(__VA_ARGS__); \
} \
} while (false)
#else
#define ALOGV(...) __ALOGV(__VA_ARGS__)
#endif
#endif
#ifndef ALOGV_IF
#if LOG_NDEBUG
#define ALOGV_IF(cond, ...) __FAKE_USE_VA_ARGS(__VA_ARGS__)
#else
#define ALOGV_IF(cond, ...) \
((__predict_false(cond)) \
? (__FAKE_USE_VA_ARGS(__VA_ARGS__), (void)ALOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \
: ((void)0))
#endif
#endif
/*
* Simplified macro to send a debug log message using the current LOG_TAG.
*/
#ifndef ALOGD
#define ALOGD(...) ((void)ALOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__))
#endif
#ifndef ALOGD_IF
#define ALOGD_IF(cond, ...) \
((__predict_false(cond)) \
? (__FAKE_USE_VA_ARGS(__VA_ARGS__), (void)ALOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \
: ((void)0))
#endif
/*
* Simplified macro to send an info log message using the current LOG_TAG.
*/
#ifndef ALOGI
#define ALOGI(...) ((void)ALOG(LOG_INFO, LOG_TAG, __VA_ARGS__))
#endif
#ifndef ALOGI_IF
#define ALOGI_IF(cond, ...) \
((__predict_false(cond)) \
? (__FAKE_USE_VA_ARGS(__VA_ARGS__), (void)ALOG(LOG_INFO, LOG_TAG, __VA_ARGS__)) \
: ((void)0))
#endif
/*
* Simplified macro to send a warning log message using the current LOG_TAG.
*/
#ifndef ALOGW
#define ALOGW(...) ((void)ALOG(LOG_WARN, LOG_TAG, __VA_ARGS__))
#endif
#ifndef ALOGW_IF
#define ALOGW_IF(cond, ...) \
((__predict_false(cond)) \
? (__FAKE_USE_VA_ARGS(__VA_ARGS__), (void)ALOG(LOG_WARN, LOG_TAG, __VA_ARGS__)) \
: ((void)0))
#endif
/*
* Simplified macro to send an error log message using the current LOG_TAG.
*/
#ifndef ALOGE
#define ALOGE(...) ((void)ALOG(LOG_ERROR, LOG_TAG, __VA_ARGS__))
#endif
#ifndef ALOGE_IF
#define ALOGE_IF(cond, ...) \
((__predict_false(cond)) \
? (__FAKE_USE_VA_ARGS(__VA_ARGS__), (void)ALOG(LOG_ERROR, LOG_TAG, __VA_ARGS__)) \
: ((void)0))
#endif
/* --------------------------------------------------------------------- */
/*
* Conditional based on whether the current LOG_TAG is enabled at
* verbose priority.
*/
#ifndef IF_ALOGV
#if LOG_NDEBUG
#define IF_ALOGV() if (false)
#else
#define IF_ALOGV() IF_ALOG(LOG_VERBOSE, LOG_TAG)
#endif
#endif
/*
* Conditional based on whether the current LOG_TAG is enabled at
* debug priority.
*/
#ifndef IF_ALOGD
#define IF_ALOGD() IF_ALOG(LOG_DEBUG, LOG_TAG)
#endif
/*
* Conditional based on whether the current LOG_TAG is enabled at
* info priority.
*/
#ifndef IF_ALOGI
#define IF_ALOGI() IF_ALOG(LOG_INFO, LOG_TAG)
#endif
/*
* Conditional based on whether the current LOG_TAG is enabled at
* warn priority.
*/
#ifndef IF_ALOGW
#define IF_ALOGW() IF_ALOG(LOG_WARN, LOG_TAG)
#endif
/*
* Conditional based on whether the current LOG_TAG is enabled at
* error priority.
*/
#ifndef IF_ALOGE
#define IF_ALOGE() IF_ALOG(LOG_ERROR, LOG_TAG)
#endif
/* --------------------------------------------------------------------- */
/*
* Basic log message macro.
*
* Example:
* ALOG(LOG_WARN, NULL, "Failed with error %d", errno);
*
* The second argument may be NULL or "" to indicate the "global" tag.
*/
#ifndef ALOG
#define ALOG(priority, tag, ...) LOG_PRI(ANDROID_##priority, tag, __VA_ARGS__)
#endif
/*
* Conditional given a desired logging priority and tag.
*/
#ifndef IF_ALOG
#define IF_ALOG(priority, tag) if (android_testLog(ANDROID_##priority, tag))
#endif
/* --------------------------------------------------------------------- */
/*
* IF_ALOG uses android_testLog, but IF_ALOG can be overridden.
* android_testLog will remain constant in its purpose as a wrapper
* for Android logging filter policy, and can be subject to
* change. It can be reused by the developers that override
* IF_ALOG as a convenient means to reimplement their policy
* over Android.
*/
/*
* Use the per-tag properties "log.tag.<tagname>" to generate a runtime
* result of non-zero to expose a log. prio is ANDROID_LOG_VERBOSE to
* ANDROID_LOG_FATAL. default_prio if no property. Undefined behavior if
* any other value.
*/
int __android_log_is_loggable(int prio, const char* tag, int default_prio);
int __android_log_is_loggable_len(int prio, const char* tag, size_t len, int default_prio);
#if LOG_NDEBUG /* Production */
#define android_testLog(prio, tag) \
(__android_log_is_loggable_len(prio, tag, ((tag) && *(tag)) ? strlen(tag) : 0, \
ANDROID_LOG_DEBUG) != 0)
#else
#define android_testLog(prio, tag) \
(__android_log_is_loggable_len(prio, tag, ((tag) && *(tag)) ? strlen(tag) : 0, \
ANDROID_LOG_VERBOSE) != 0)
#endif
#if defined(__clang__)
#pragma clang diagnostic pop
#endif
__END_DECLS
+141
View File
@@ -0,0 +1,141 @@
/*
* Copyright (C) 2005-2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <android/log.h>
#include <log/log_id.h>
/*
* Normally we strip the effects of ALOGV (VERBOSE messages),
* LOG_FATAL and LOG_FATAL_IF (FATAL assert messages) from the
* release builds be defining NDEBUG. You can modify this (for
* example with "#define LOG_NDEBUG 0" at the top of your source
* file) to change that behavior.
*/
#ifndef LOG_NDEBUG
#ifdef NDEBUG
#define LOG_NDEBUG 1
#else
#define LOG_NDEBUG 0
#endif
#endif
/* --------------------------------------------------------------------- */
#ifndef __predict_false
#define __predict_false(exp) __builtin_expect((exp) != 0, 0)
#endif
/*
* Simplified macro to send a verbose radio log message using current LOG_TAG.
*/
#ifndef RLOGV
#define __RLOGV(...) \
((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_VERBOSE, LOG_TAG, \
__VA_ARGS__))
#if LOG_NDEBUG
#define RLOGV(...) \
do { \
if (0) { \
__RLOGV(__VA_ARGS__); \
} \
} while (0)
#else
#define RLOGV(...) __RLOGV(__VA_ARGS__)
#endif
#endif
#ifndef RLOGV_IF
#if LOG_NDEBUG
#define RLOGV_IF(cond, ...) ((void)0)
#else
#define RLOGV_IF(cond, ...) \
((__predict_false(cond)) \
? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_VERBOSE, \
LOG_TAG, __VA_ARGS__)) \
: (void)0)
#endif
#endif
/*
* Simplified macro to send a debug radio log message using current LOG_TAG.
*/
#ifndef RLOGD
#define RLOGD(...) \
((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_DEBUG, LOG_TAG, \
__VA_ARGS__))
#endif
#ifndef RLOGD_IF
#define RLOGD_IF(cond, ...) \
((__predict_false(cond)) \
? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_DEBUG, \
LOG_TAG, __VA_ARGS__)) \
: (void)0)
#endif
/*
* Simplified macro to send an info radio log message using current LOG_TAG.
*/
#ifndef RLOGI
#define RLOGI(...) \
((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_INFO, LOG_TAG, \
__VA_ARGS__))
#endif
#ifndef RLOGI_IF
#define RLOGI_IF(cond, ...) \
((__predict_false(cond)) \
? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_INFO, \
LOG_TAG, __VA_ARGS__)) \
: (void)0)
#endif
/*
* Simplified macro to send a warning radio log message using current LOG_TAG.
*/
#ifndef RLOGW
#define RLOGW(...) \
((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_WARN, LOG_TAG, \
__VA_ARGS__))
#endif
#ifndef RLOGW_IF
#define RLOGW_IF(cond, ...) \
((__predict_false(cond)) \
? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_WARN, \
LOG_TAG, __VA_ARGS__)) \
: (void)0)
#endif
/*
* Simplified macro to send an error radio log message using current LOG_TAG.
*/
#ifndef RLOGE
#define RLOGE(...) \
((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_ERROR, LOG_TAG, \
__VA_ARGS__))
#endif
#ifndef RLOGE_IF
#define RLOGE_IF(cond, ...) \
((__predict_false(cond)) \
? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_ERROR, \
LOG_TAG, __VA_ARGS__)) \
: (void)0)
#endif
+172
View File
@@ -0,0 +1,172 @@
/*
* Copyright (C) 2005-2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <sys/types.h>
/* deal with possible sys/cdefs.h conflict with fcntl.h */
#ifdef __unused
#define __unused_defined __unused
#undef __unused
#endif
#include <fcntl.h> /* Pick up O_* macros */
/* restore definitions from above */
#ifdef __unused_defined
#define __unused __attribute__((__unused__))
#endif
#include <stdint.h>
#include <log/log_id.h>
#include <log/log_time.h>
#ifdef __cplusplus
extern "C" {
#endif
/*
* Native log reading interface section. See logcat for sample code.
*
* The preferred API is an exec of logcat. Likely uses of this interface
* are if native code suffers from exec or filtration being too costly,
* access to raw information, or parsing is an issue.
*/
struct logger_entry {
uint16_t len; /* length of the payload */
uint16_t hdr_size; /* sizeof(struct logger_entry) */
int32_t pid; /* generating process's pid */
uint32_t tid; /* generating process's tid */
uint32_t sec; /* seconds since Epoch */
uint32_t nsec; /* nanoseconds */
uint32_t lid; /* log id of the payload, bottom 4 bits currently */
uint32_t uid; /* generating process's uid */
};
/*
* The maximum size of the log entry payload that can be
* written to the logger. An attempt to write more than
* this amount will result in a truncated log entry.
*/
#define LOGGER_ENTRY_MAX_PAYLOAD 4068
/*
* The maximum size of a log entry which can be read.
* An attempt to read less than this amount may result
* in read() returning EINVAL.
*/
#define LOGGER_ENTRY_MAX_LEN (5 * 1024)
struct log_msg {
union {
unsigned char buf[LOGGER_ENTRY_MAX_LEN + 1];
struct logger_entry entry;
} __attribute__((aligned(4)));
#ifdef __cplusplus
/* Matching log_time operators */
bool operator==(const log_msg& T) const {
return (entry.sec == T.entry.sec) && (entry.nsec == T.entry.nsec);
}
bool operator!=(const log_msg& T) const {
return !(*this == T);
}
bool operator<(const log_msg& T) const {
return (entry.sec < T.entry.sec) ||
((entry.sec == T.entry.sec) && (entry.nsec < T.entry.nsec));
}
bool operator>=(const log_msg& T) const {
return !(*this < T);
}
bool operator>(const log_msg& T) const {
return (entry.sec > T.entry.sec) ||
((entry.sec == T.entry.sec) && (entry.nsec > T.entry.nsec));
}
bool operator<=(const log_msg& T) const {
return !(*this > T);
}
uint64_t nsec() const {
return static_cast<uint64_t>(entry.sec) * NS_PER_SEC + entry.nsec;
}
/* packet methods */
log_id_t id() {
return static_cast<log_id_t>(entry.lid);
}
char* msg() {
unsigned short hdr_size = entry.hdr_size;
if (hdr_size >= sizeof(struct log_msg) - sizeof(entry)) {
return nullptr;
}
return reinterpret_cast<char*>(buf) + hdr_size;
}
unsigned int len() { return entry.hdr_size + entry.len; }
#endif
};
struct logger;
log_id_t android_logger_get_id(struct logger* logger);
int android_logger_clear(struct logger* logger);
long android_logger_get_log_size(struct logger* logger);
int android_logger_set_log_size(struct logger* logger, unsigned long size);
long android_logger_get_log_readable_size(struct logger* logger);
int android_logger_get_log_version(struct logger* logger);
struct logger_list;
ssize_t android_logger_get_statistics(struct logger_list* logger_list,
char* buf, size_t len);
ssize_t android_logger_get_prune_list(struct logger_list* logger_list,
char* buf, size_t len);
int android_logger_set_prune_list(struct logger_list* logger_list, const char* buf, size_t len);
#define ANDROID_LOG_RDONLY O_RDONLY
#define ANDROID_LOG_WRONLY O_WRONLY
#define ANDROID_LOG_RDWR O_RDWR
#define ANDROID_LOG_ACCMODE O_ACCMODE
#ifndef O_NONBLOCK
#define ANDROID_LOG_NONBLOCK 0x00000800
#else
#define ANDROID_LOG_NONBLOCK O_NONBLOCK
#endif
#define ANDROID_LOG_WRAP 0x40000000 /* Block until buffer about to wrap */
#define ANDROID_LOG_WRAP_DEFAULT_TIMEOUT 7200 /* 2 hour default */
#define ANDROID_LOG_PSTORE 0x80000000
struct logger_list* android_logger_list_alloc(int mode, unsigned int tail,
pid_t pid);
struct logger_list* android_logger_list_alloc_time(int mode, log_time start,
pid_t pid);
void android_logger_list_free(struct logger_list* logger_list);
/* In the purest sense, the following two are orthogonal interfaces */
int android_logger_list_read(struct logger_list* logger_list,
struct log_msg* log_msg);
/* Multiple log_id_t opens */
struct logger* android_logger_open(struct logger_list* logger_list, log_id_t id);
#define android_logger_close android_logger_free
/* Single log_id_t open */
struct logger_list* android_logger_list_open(log_id_t id, int mode,
unsigned int tail, pid_t pid);
#define android_logger_list_close android_logger_list_free
#ifdef __cplusplus
}
#endif
+29
View File
@@ -0,0 +1,29 @@
/*
**
** Copyright 2017, The Android Open Source Project
**
** This file is dual licensed. It may be redistributed and/or modified
** under the terms of the Apache 2.0 License OR version 2 of the GNU
** General Public License.
*/
#pragma once
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
#define android_errorWriteLog(tag, subTag) \
__android_log_error_write(tag, subTag, -1, NULL, 0)
#define android_errorWriteWithInfoLog(tag, subTag, uid, data, dataLen) \
__android_log_error_write(tag, subTag, uid, data, dataLen)
int __android_log_error_write(int tag, const char* subTag, int32_t uid,
const char* data, uint32_t dataLen);
#ifdef __cplusplus
}
#endif
+139
View File
@@ -0,0 +1,139 @@
/*
* Copyright (C) 2005-2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <android/log.h>
#include <log/log_id.h>
/*
* Normally we strip the effects of ALOGV (VERBOSE messages),
* LOG_FATAL and LOG_FATAL_IF (FATAL assert messages) from the
* release builds be defining NDEBUG. You can modify this (for
* example with "#define LOG_NDEBUG 0" at the top of your source
* file) to change that behavior.
*/
#ifndef LOG_NDEBUG
#ifdef NDEBUG
#define LOG_NDEBUG 1
#else
#define LOG_NDEBUG 0
#endif
#endif
#ifndef __predict_false
#define __predict_false(exp) __builtin_expect((exp) != 0, 0)
#endif
/*
* Simplified macro to send a verbose system log message using current LOG_TAG.
*/
#ifndef SLOGV
#define __SLOGV(...) \
((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_VERBOSE, LOG_TAG, \
__VA_ARGS__))
#if LOG_NDEBUG
#define SLOGV(...) \
do { \
if (0) { \
__SLOGV(__VA_ARGS__); \
} \
} while (0)
#else
#define SLOGV(...) __SLOGV(__VA_ARGS__)
#endif
#endif
#ifndef SLOGV_IF
#if LOG_NDEBUG
#define SLOGV_IF(cond, ...) ((void)0)
#else
#define SLOGV_IF(cond, ...) \
((__predict_false(cond)) \
? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_VERBOSE, \
LOG_TAG, __VA_ARGS__)) \
: (void)0)
#endif
#endif
/*
* Simplified macro to send a debug system log message using current LOG_TAG.
*/
#ifndef SLOGD
#define SLOGD(...) \
((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_DEBUG, LOG_TAG, \
__VA_ARGS__))
#endif
#ifndef SLOGD_IF
#define SLOGD_IF(cond, ...) \
((__predict_false(cond)) \
? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_DEBUG, \
LOG_TAG, __VA_ARGS__)) \
: (void)0)
#endif
/*
* Simplified macro to send an info system log message using current LOG_TAG.
*/
#ifndef SLOGI
#define SLOGI(...) \
((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_INFO, LOG_TAG, \
__VA_ARGS__))
#endif
#ifndef SLOGI_IF
#define SLOGI_IF(cond, ...) \
((__predict_false(cond)) \
? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_INFO, \
LOG_TAG, __VA_ARGS__)) \
: (void)0)
#endif
/*
* Simplified macro to send a warning system log message using current LOG_TAG.
*/
#ifndef SLOGW
#define SLOGW(...) \
((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_WARN, LOG_TAG, \
__VA_ARGS__))
#endif
#ifndef SLOGW_IF
#define SLOGW_IF(cond, ...) \
((__predict_false(cond)) \
? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_WARN, \
LOG_TAG, __VA_ARGS__)) \
: (void)0)
#endif
/*
* Simplified macro to send an error system log message using current LOG_TAG.
*/
#ifndef SLOGE
#define SLOGE(...) \
((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_ERROR, LOG_TAG, \
__VA_ARGS__))
#endif
#ifndef SLOGE_IF
#define SLOGE_IF(cond, ...) \
((__predict_false(cond)) \
? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_ERROR, \
LOG_TAG, __VA_ARGS__)) \
: (void)0)
#endif
+163
View File
@@ -0,0 +1,163 @@
/*
* Copyright (C) 2005-2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <stdint.h>
#include <time.h>
/* struct log_time is a wire-format variant of struct timespec */
#define NS_PER_SEC 1000000000ULL
#define US_PER_SEC 1000000ULL
#define MS_PER_SEC 1000ULL
#define LOG_TIME_SEC(t) ((t)->tv_sec)
/* next power of two after NS_PER_SEC */
#define LOG_TIME_NSEC(t) ((t)->tv_nsec & (UINT32_MAX >> 2))
#ifdef __cplusplus
extern "C" {
struct log_time {
public:
uint32_t tv_sec = 0; /* good to Feb 5 2106 */
uint32_t tv_nsec = 0;
static const uint32_t tv_sec_max = 0xFFFFFFFFUL;
static const uint32_t tv_nsec_max = 999999999UL;
static const timespec EPOCH;
log_time() {}
explicit log_time(const timespec& T)
: tv_sec(static_cast<uint32_t>(T.tv_sec)), tv_nsec(static_cast<uint32_t>(T.tv_nsec)) {}
explicit log_time(uint32_t sec, uint32_t nsec = 0)
: tv_sec(sec), tv_nsec(nsec) {
}
#ifdef __linux__
explicit log_time(clockid_t id) {
timespec T;
clock_gettime(id, &T);
tv_sec = static_cast<uint32_t>(T.tv_sec);
tv_nsec = static_cast<uint32_t>(T.tv_nsec);
}
#endif
explicit log_time(const char* T) {
const uint8_t* c = reinterpret_cast<const uint8_t*>(T);
tv_sec = c[0] | (static_cast<uint32_t>(c[1]) << 8) |
(static_cast<uint32_t>(c[2]) << 16) |
(static_cast<uint32_t>(c[3]) << 24);
tv_nsec = c[4] | (static_cast<uint32_t>(c[5]) << 8) |
(static_cast<uint32_t>(c[6]) << 16) |
(static_cast<uint32_t>(c[7]) << 24);
}
/* timespec */
bool operator==(const timespec& T) const {
return (tv_sec == static_cast<uint32_t>(T.tv_sec)) &&
(tv_nsec == static_cast<uint32_t>(T.tv_nsec));
}
bool operator!=(const timespec& T) const {
return !(*this == T);
}
bool operator<(const timespec& T) const {
return (tv_sec < static_cast<uint32_t>(T.tv_sec)) ||
((tv_sec == static_cast<uint32_t>(T.tv_sec)) &&
(tv_nsec < static_cast<uint32_t>(T.tv_nsec)));
}
bool operator>=(const timespec& T) const {
return !(*this < T);
}
bool operator>(const timespec& T) const {
return (tv_sec > static_cast<uint32_t>(T.tv_sec)) ||
((tv_sec == static_cast<uint32_t>(T.tv_sec)) &&
(tv_nsec > static_cast<uint32_t>(T.tv_nsec)));
}
bool operator<=(const timespec& T) const {
return !(*this > T);
}
log_time operator-=(const timespec& T);
log_time operator-(const timespec& T) const {
log_time local(*this);
return local -= T;
}
log_time operator+=(const timespec& T);
log_time operator+(const timespec& T) const {
log_time local(*this);
return local += T;
}
/* log_time */
bool operator==(const log_time& T) const {
return (tv_sec == T.tv_sec) && (tv_nsec == T.tv_nsec);
}
bool operator!=(const log_time& T) const {
return !(*this == T);
}
bool operator<(const log_time& T) const {
return (tv_sec < T.tv_sec) ||
((tv_sec == T.tv_sec) && (tv_nsec < T.tv_nsec));
}
bool operator>=(const log_time& T) const {
return !(*this < T);
}
bool operator>(const log_time& T) const {
return (tv_sec > T.tv_sec) ||
((tv_sec == T.tv_sec) && (tv_nsec > T.tv_nsec));
}
bool operator<=(const log_time& T) const {
return !(*this > T);
}
log_time operator-=(const log_time& T);
log_time operator-(const log_time& T) const {
log_time local(*this);
return local -= T;
}
log_time operator+=(const log_time& T);
log_time operator+(const log_time& T) const {
log_time local(*this);
return local += T;
}
uint64_t nsec() const {
return static_cast<uint64_t>(tv_sec) * NS_PER_SEC + tv_nsec;
}
uint64_t usec() const {
return static_cast<uint64_t>(tv_sec) * US_PER_SEC +
tv_nsec / (NS_PER_SEC / US_PER_SEC);
}
uint64_t msec() const {
return static_cast<uint64_t>(tv_sec) * MS_PER_SEC +
tv_nsec / (NS_PER_SEC / MS_PER_SEC);
}
static const char default_format[];
/* Add %#q for the fraction of a second to the standard library functions */
char* strptime(const char* s, const char* format = default_format);
} __attribute__((__packed__));
}
#else /* __cplusplus */
typedef struct log_time {
uint32_t tv_sec;
uint32_t tv_nsec;
} __attribute__((__packed__)) log_time;
#endif /* __cplusplus */
@@ -0,0 +1,561 @@
/*
* Copyright (C) 2009 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef HARDWARE_API_H_
#define HARDWARE_API_H_
#include <media/hardware/OMXPluginBase.h>
#include <media/hardware/MetadataBufferType.h>
#include <cutils/native_handle.h>
#include <utils/RefBase.h>
#include "VideoAPI.h"
#include <OMX_Component.h>
struct ANativeWindowBuffer;
namespace android {
// This structure is used to enable Android native buffer use for either
// graphic buffers or secure buffers.
//
// TO CONTROL ANDROID GRAPHIC BUFFER USAGE:
//
// A pointer to this struct is passed to the OMX_SetParameter when the extension
// index for the 'OMX.google.android.index.enableAndroidNativeBuffers' extension
// is given.
//
// When Android native buffer use is disabled for a port (the default state),
// the OMX node should operate as normal, and expect UseBuffer calls to set its
// buffers. This is the mode that will be used when CPU access to the buffer is
// required.
//
// When Android native buffer use has been enabled for a given port, the video
// color format for the port is to be interpreted as an Android pixel format
// rather than an OMX color format. Enabling Android native buffers may also
// change how the component receives the native buffers. If store-metadata-mode
// is enabled on the port, the component will receive the buffers as specified
// in the section below. Otherwise, unless the node supports the
// 'OMX.google.android.index.useAndroidNativeBuffer2' extension, it should
// expect to receive UseAndroidNativeBuffer calls (via OMX_SetParameter) rather
// than UseBuffer calls for that port.
//
// TO CONTROL ANDROID SECURE BUFFER USAGE:
//
// A pointer to this struct is passed to the OMX_SetParameter when the extension
// index for the 'OMX.google.android.index.allocateNativeHandle' extension
// is given.
//
// When native handle use is disabled for a port (the default state),
// the OMX node should operate as normal, and expect AllocateBuffer calls to
// return buffer pointers. This is the mode that will be used for non-secure
// buffers if component requires allocate buffers instead of use buffers.
//
// When native handle use has been enabled for a given port, the component
// shall allocate native_buffer_t objects containing that can be passed between
// processes using binder. This is the mode that will be used for secure buffers.
// When an OMX component allocates native handle for buffers, it must close and
// delete that handle when it frees those buffers. Even though pBuffer will point
// to a native handle, nFilledLength, nAllocLength and nOffset will correspond
// to the data inside the opaque buffer.
struct EnableAndroidNativeBuffersParams {
OMX_U32 nSize;
OMX_VERSIONTYPE nVersion;
OMX_U32 nPortIndex;
OMX_BOOL enable;
};
typedef struct EnableAndroidNativeBuffersParams AllocateNativeHandleParams;
// A pointer to this struct is passed to OMX_SetParameter() when the extension index
// "OMX.google.android.index.storeMetaDataInBuffers" or
// "OMX.google.android.index.storeANWBufferInMetadata" is given.
//
// When meta data is stored in the video buffers passed between OMX clients
// and OMX components, interpretation of the buffer data is up to the
// buffer receiver, and the data may or may not be the actual video data, but
// some information helpful for the receiver to locate the actual data.
// The buffer receiver thus needs to know how to interpret what is stored
// in these buffers, with mechanisms pre-determined externally. How to
// interpret the meta data is outside of the scope of this parameter.
//
// Currently, this is used to pass meta data from video source (camera component, for instance) to
// video encoder to avoid memcpying of input video frame data, as well as to pass dynamic output
// buffer to video decoder. To do this, bStoreMetaData is set to OMX_TRUE.
//
// If bStoreMetaData is set to false, real YUV frame data will be stored in input buffers, and
// the output buffers contain either real YUV frame data, or are themselves native handles as
// directed by enable/use-android-native-buffer parameter settings.
// In addition, if no OMX_SetParameter() call is made on a port with the corresponding extension
// index, the component should not assume that the client is not using metadata mode for the port.
//
// If the component supports this using the "OMX.google.android.index.storeANWBufferInMetadata"
// extension and bStoreMetaData is set to OMX_TRUE, data is passed using the VideoNativeMetadata
// layout as defined below. Each buffer will be accompanied by a fence. The fence must signal
// before the buffer can be used (e.g. read from or written into). When returning such buffer to
// the client, component must provide a new fence that must signal before the returned buffer can
// be used (e.g. read from or written into). The component owns the incoming fenceFd, and must close
// it when fence has signaled. The client will own and close the returned fence file descriptor.
//
// If the component supports this using the "OMX.google.android.index.storeMetaDataInBuffers"
// extension and bStoreMetaData is set to OMX_TRUE, data is passed using VideoGrallocMetadata
// (the layout of which is the VideoGrallocMetadata defined below). Camera input can be also passed
// as "CameraSource", the layout of which is vendor dependent.
//
// Metadata buffers are registered with the component using UseBuffer calls, or can be allocated
// by the component for encoder-metadata-output buffers.
struct StoreMetaDataInBuffersParams {
OMX_U32 nSize;
OMX_VERSIONTYPE nVersion;
OMX_U32 nPortIndex;
OMX_BOOL bStoreMetaData;
};
// Meta data buffer layout used to transport output frames to the decoder for
// dynamic buffer handling.
struct VideoGrallocMetadata {
MetadataBufferType eType; // must be kMetadataBufferTypeGrallocSource
#ifdef OMX_ANDROID_COMPILE_AS_32BIT_ON_64BIT_PLATFORMS
OMX_PTR pHandle;
#else
buffer_handle_t pHandle;
#endif
};
// Legacy name for VideoGrallocMetadata struct.
struct VideoDecoderOutputMetaData : public VideoGrallocMetadata {};
struct VideoNativeMetadata {
MetadataBufferType eType; // must be kMetadataBufferTypeANWBuffer
#ifdef OMX_ANDROID_COMPILE_AS_32BIT_ON_64BIT_PLATFORMS
OMX_PTR pBuffer;
#else
struct ANativeWindowBuffer* pBuffer;
#endif
int nFenceFd; // -1 if unused
};
// Meta data buffer layout for passing a native_handle to codec
struct VideoNativeHandleMetadata {
MetadataBufferType eType; // must be kMetadataBufferTypeNativeHandleSource
#ifdef OMX_ANDROID_COMPILE_AS_32BIT_ON_64BIT_PLATFORMS
OMX_PTR pHandle;
#else
native_handle_t *pHandle;
#endif
};
// A pointer to this struct is passed to OMX_SetParameter() when the extension
// index "OMX.google.android.index.prepareForAdaptivePlayback" is given.
//
// This method is used to signal a video decoder, that the user has requested
// seamless resolution change support (if bEnable is set to OMX_TRUE).
// nMaxFrameWidth and nMaxFrameHeight are the dimensions of the largest
// anticipated frames in the video. If bEnable is OMX_FALSE, no resolution
// change is expected, and the nMaxFrameWidth/Height fields are unused.
//
// If the decoder supports dynamic output buffers, it may ignore this
// request. Otherwise, it shall request resources in such a way so that it
// avoids full port-reconfiguration (due to output port-definition change)
// during resolution changes.
//
// DO NOT USE THIS STRUCTURE AS IT WILL BE REMOVED. INSTEAD, IMPLEMENT
// METADATA SUPPORT FOR VIDEO DECODERS.
struct PrepareForAdaptivePlaybackParams {
OMX_U32 nSize;
OMX_VERSIONTYPE nVersion;
OMX_U32 nPortIndex;
OMX_BOOL bEnable;
OMX_U32 nMaxFrameWidth;
OMX_U32 nMaxFrameHeight;
};
// A pointer to this struct is passed to OMX_SetParameter when the extension
// index for the 'OMX.google.android.index.useAndroidNativeBuffer' extension is
// given. This call will only be performed if a prior call was made with the
// 'OMX.google.android.index.enableAndroidNativeBuffers' extension index,
// enabling use of Android native buffers.
struct UseAndroidNativeBufferParams {
OMX_U32 nSize;
OMX_VERSIONTYPE nVersion;
OMX_U32 nPortIndex;
OMX_PTR pAppPrivate;
OMX_BUFFERHEADERTYPE **bufferHeader;
const sp<ANativeWindowBuffer>& nativeBuffer;
};
// A pointer to this struct is passed to OMX_GetParameter when the extension
// index for the 'OMX.google.android.index.getAndroidNativeBufferUsage'
// extension is given. The usage bits returned from this query will be used to
// allocate the Gralloc buffers that get passed to the useAndroidNativeBuffer
// command.
struct GetAndroidNativeBufferUsageParams {
OMX_U32 nSize; // IN
OMX_VERSIONTYPE nVersion; // IN
OMX_U32 nPortIndex; // IN
OMX_U32 nUsage; // OUT
};
// An enum OMX_COLOR_FormatAndroidOpaque to indicate an opaque colorformat
// is declared in media/stagefright/openmax/OMX_IVCommon.h
// This will inform the encoder that the actual
// colorformat will be relayed by the GRalloc Buffers.
// OMX_COLOR_FormatAndroidOpaque = 0x7F000001,
// A pointer to this struct is passed to OMX_SetParameter when the extension
// index for the 'OMX.google.android.index.prependSPSPPSToIDRFrames' extension
// is given.
// A successful result indicates that future IDR frames will be prefixed by
// SPS/PPS.
struct PrependSPSPPSToIDRFramesParams {
OMX_U32 nSize;
OMX_VERSIONTYPE nVersion;
OMX_BOOL bEnable;
};
// A pointer to this struct is passed to OMX_GetParameter when the extension
// index for the 'OMX.google.android.index.describeColorFormat'
// extension is given. This method can be called from any component state
// other than invalid. The color-format, frame width/height, and stride/
// slice-height parameters are ones that are associated with a raw video
// port (input or output), but the stride/slice height parameters may be
// incorrect. bUsingNativeBuffers is OMX_TRUE if native android buffers will
// be used (while specifying this color format).
//
// The component shall fill out the MediaImage structure that
// corresponds to the described raw video format, and the potentially corrected
// stride and slice-height info.
//
// The behavior is slightly different if bUsingNativeBuffers is OMX_TRUE,
// though most implementations can ignore this difference. When using native buffers,
// the component may change the configured color format to an optimized format.
// Additionally, when allocating these buffers for flexible usecase, the framework
// will set the SW_READ/WRITE_OFTEN usage flags. In this case (if bUsingNativeBuffers
// is OMX_TRUE), the component shall fill out the MediaImage information for the
// scenario when these SW-readable/writable buffers are locked using gralloc_lock.
// Note, that these buffers may also be locked using gralloc_lock_ycbcr, which must
// be supported for vendor-specific formats.
//
// For non-YUV packed planar/semiplanar image formats, or if bUsingNativeBuffers
// is OMX_TRUE and the component does not support this color format with native
// buffers, the component shall set mNumPlanes to 0, and mType to MEDIA_IMAGE_TYPE_UNKNOWN.
// @deprecated: use DescribeColorFormat2Params
struct DescribeColorFormat2Params;
struct DescribeColorFormatParams {
OMX_U32 nSize;
OMX_VERSIONTYPE nVersion;
// input: parameters from OMX_VIDEO_PORTDEFINITIONTYPE
OMX_COLOR_FORMATTYPE eColorFormat;
OMX_U32 nFrameWidth;
OMX_U32 nFrameHeight;
OMX_U32 nStride;
OMX_U32 nSliceHeight;
OMX_BOOL bUsingNativeBuffers;
// output: fill out the MediaImage fields
MediaImage sMediaImage;
explicit DescribeColorFormatParams(const DescribeColorFormat2Params&); // for internal use only
};
// A pointer to this struct is passed to OMX_GetParameter when the extension
// index for the 'OMX.google.android.index.describeColorFormat2'
// extension is given. This is operationally the same as DescribeColorFormatParams
// but can be used for HDR and RGBA/YUVA formats.
struct DescribeColorFormat2Params {
OMX_U32 nSize;
OMX_VERSIONTYPE nVersion;
// input: parameters from OMX_VIDEO_PORTDEFINITIONTYPE
OMX_COLOR_FORMATTYPE eColorFormat;
OMX_U32 nFrameWidth;
OMX_U32 nFrameHeight;
OMX_U32 nStride;
OMX_U32 nSliceHeight;
OMX_BOOL bUsingNativeBuffers;
// output: fill out the MediaImage2 fields
MediaImage2 sMediaImage;
void initFromV1(const DescribeColorFormatParams&); // for internal use only
};
// A pointer to this struct is passed to OMX_SetParameter or OMX_GetParameter
// when the extension index for the
// 'OMX.google.android.index.configureVideoTunnelMode' extension is given.
// If the extension is supported then tunneled playback mode should be supported
// by the codec. If bTunneled is set to OMX_TRUE then the video decoder should
// operate in "tunneled" mode and output its decoded frames directly to the
// sink. In this case nAudioHwSync is the HW SYNC ID of the audio HAL Output
// stream to sync the video with. If bTunneled is set to OMX_FALSE, "tunneled"
// mode should be disabled and nAudioHwSync should be ignored.
// OMX_GetParameter is used to query tunneling configuration. bTunneled should
// return whether decoder is operating in tunneled mode, and if it is,
// pSidebandWindow should contain the codec allocated sideband window handle.
struct ConfigureVideoTunnelModeParams {
OMX_U32 nSize; // IN
OMX_VERSIONTYPE nVersion; // IN
OMX_U32 nPortIndex; // IN
OMX_BOOL bTunneled; // IN/OUT
OMX_U32 nAudioHwSync; // IN
OMX_PTR pSidebandWindow; // OUT
};
// Color space description (aspects) parameters.
// This is passed via OMX_SetConfig or OMX_GetConfig to video encoders and decoders when the
// 'OMX.google.android.index.describeColorAspects' extension is given. Component SHALL behave
// as described below if it supports this extension.
//
// bDataSpaceChanged and bRequestingDataSpace is assumed to be OMX_FALSE unless noted otherwise.
//
// VIDEO ENCODERS: the framework uses OMX_SetConfig to specify color aspects of the coded video.
// This may happen:
// a) before the component transitions to idle state
// b) before the input frame is sent via OMX_EmptyThisBuffer in executing state
// c) during execution, just before an input frame with a different color aspect information
// is sent.
//
// The framework also uses OMX_GetConfig to
// d) verify the color aspects that will be written to the stream
// e) (optional) verify the color aspects that should be reported to the container for a
// given dataspace/pixelformat received
//
// 1. Encoders SHOULD maintain an internal color aspect state, initialized to Unspecified values.
// This represents the values that will be written into the bitstream.
// 2. Upon OMX_SetConfig, they SHOULD update their internal state to the aspects received
// (including Unspecified values). For specific aspect values that are not supported by the
// codec standard, encoders SHOULD substitute Unspecified values; or they MAY use a suitable
// alternative (e.g. to suggest the use of BT.709 EOTF instead of SMPTE 240M.)
// 3. OMX_GetConfig SHALL return the internal state (values that will be written).
// 4. OMX_SetConfig SHALL always succeed before receiving the first frame. It MAY fail afterwards,
// but only if the configured values would change AND the component does not support updating the
// color information to those values mid-stream. If component supports updating a portion of
// the color information, those values should be updated in the internal state, and OMX_SetConfig
// SHALL succeed. Otherwise, the internal state SHALL remain intact and OMX_SetConfig SHALL fail
// with OMX_ErrorUnsupportedSettings.
// 5. When the framework receives an input frame with an unexpected dataspace, it will query
// encoders for the color aspects that should be reported to the container using OMX_GetConfig
// with bDataSpaceChanged set to OMX_TRUE, and nPixelFormat/nDataSpace containing the new
// format/dataspace values. This allows vendors to use extended dataspace during capture and
// composition (e.g. screenrecord) - while performing color-space conversion inside the encoder -
// and encode and report a different color-space information in the bitstream/container.
// sColorAspects contains the requested color aspects by the client for reference, which may
// include aspects not supported by the encoding. This is used together with guidance for
// dataspace selection; see 6. below.
//
// VIDEO DECODERS: the framework uses OMX_SetConfig to specify the default color aspects to use
// for the video.
// This may happen:
// a) before the component transitions to idle state
// b) during execution, when the resolution or the default color aspects change.
//
// The framework also uses OMX_GetConfig to
// c) get the final color aspects reported by the coded bitstream after taking the default values
// into account.
//
// 1. Decoders should maintain two color aspect states - the default state as reported by the
// framework, and the coded state as reported by the bitstream - as each state can change
// independently from the other.
// 2. Upon OMX_SetConfig, it SHALL update its default state regardless of whether such aspects
// could be supplied by the component bitstream. (E.g. it should blindly support all enumeration
// values, even unknown ones, and the Other value). This SHALL always succeed.
// 3. Upon OMX_GetConfig, the component SHALL return the final color aspects by replacing
// Unspecified coded values with the default values. This SHALL always succeed.
// 4. Whenever the component processes color aspect information in the bitstream even with an
// Unspecified value, it SHOULD update its internal coded state with that information just before
// the frame with the new information would be outputted, and the component SHALL signal an
// OMX_EventPortSettingsChanged event with data2 set to the extension index.
// NOTE: Component SHOULD NOT signal a separate event purely for color aspect change, if it occurs
// together with a port definition (e.g. size) or crop change.
// 5. If the aspects a component encounters in the bitstream cannot be represented with enumeration
// values as defined below, the component SHALL set those aspects to Other. Restricted values in
// the bitstream SHALL be treated as defined by the relevant bitstream specifications/standards,
// or as Unspecified, if not defined.
//
// BOTH DECODERS AND ENCODERS: the framework uses OMX_GetConfig during idle and executing state to
// f) (optional) get guidance for the dataspace to set for given color aspects, by setting
// bRequestingDataSpace to OMX_TRUE. The component SHALL return OMX_ErrorUnsupportedSettings
// IF it does not support this request.
//
// 6. This is an information request that can happen at any time, independent of the normal
// configuration process. This allows vendors to use extended dataspace during capture, playback
// and composition - while performing color-space conversion inside the component. Component
// SHALL set the desired dataspace into nDataSpace. Otherwise, it SHALL return
// OMX_ErrorUnsupportedSettings to let the framework choose a nearby standard dataspace.
//
// 6.a. For encoders, this query happens before the first frame is received using surface encoding.
// This allows the encoder to use a specific dataspace for the color aspects (e.g. because the
// device supports additional dataspaces, or because it wants to perform color-space extension
// to facilitate a more optimal rendering/capture pipeline.).
//
// 6.b. For decoders, this query happens before the first frame, and every time the color aspects
// change, while using surface buffers. This allows the decoder to use a specific dataspace for
// the color aspects (e.g. because the device supports additional dataspaces, or because it wants
// to perform color-space extension by inline color-space conversion to facilitate a more optimal
// rendering pipeline.).
//
// Note: the size of sAspects may increase in the future by additional fields.
// Implementations SHOULD NOT require a certain size.
struct DescribeColorAspectsParams {
OMX_U32 nSize; // IN
OMX_VERSIONTYPE nVersion; // IN
OMX_U32 nPortIndex; // IN
OMX_BOOL bRequestingDataSpace; // IN
OMX_BOOL bDataSpaceChanged; // IN
OMX_U32 nPixelFormat; // IN
OMX_U32 nDataSpace; // OUT
ColorAspects sAspects; // IN/OUT
};
// HDR color description parameters.
// This is passed via OMX_SetConfig or OMX_GetConfig to video encoders and decoders when the
// 'OMX.google.android.index.describeHDRStaticInfo' extension is given and an HDR stream
// is detected. Component SHALL behave as described below if it supports this extension.
//
// Currently, only Static Metadata Descriptor Type 1 support is required.
//
// VIDEO ENCODERS: the framework uses OMX_SetConfig to specify the HDR static information of the
// coded video.
// This may happen:
// a) before the component transitions to idle state
// b) before the input frame is sent via OMX_EmptyThisBuffer in executing state
// c) during execution, just before an input frame with a different HDR static
// information is sent.
//
// The framework also uses OMX_GetConfig to
// d) verify the HDR static information that will be written to the stream.
//
// 1. Encoders SHOULD maintain an internal HDR static info data, initialized to Unspecified values.
// This represents the values that will be written into the bitstream.
// 2. Upon OMX_SetConfig, they SHOULD update their internal state to the info received
// (including Unspecified values). For specific parameters that are not supported by the
// codec standard, encoders SHOULD substitute Unspecified values. NOTE: no other substitution
// is allowed.
// 3. OMX_GetConfig SHALL return the internal state (values that will be written).
// 4. OMX_SetConfig SHALL always succeed before receiving the first frame if the encoder is
// configured into an HDR compatible profile. It MAY fail with OMX_ErrorUnsupportedSettings error
// code if it is not configured into such a profile, OR if the configured values would change
// AND the component does not support updating the HDR static information mid-stream. If the
// component supports updating a portion of the information, those values should be updated in
// the internal state, and OMX_SetConfig SHALL succeed. Otherwise, the internal state SHALL
// remain intact.
//
// VIDEO DECODERS: the framework uses OMX_SetConfig to specify the default HDR static information
// to use for the video.
// a) This only happens if the client supplies this information, in which case it occurs before
// the component transitions to idle state.
// b) This may also happen subsequently if the default HDR static information changes.
//
// The framework also uses OMX_GetConfig to
// c) get the final HDR static information reported by the coded bitstream after taking the
// default values into account.
//
// 1. Decoders should maintain two HDR static information structures - the default values as
// reported by the framework, and the coded values as reported by the bitstream - as each
// structure can change independently from the other.
// 2. Upon OMX_SetConfig, it SHALL update its default structure regardless of whether such static
// parameters could be supplied by the component bitstream. (E.g. it should blindly support all
// parameter values, even seemingly illegal ones). This SHALL always succeed.
// Note: The descriptor ID used in sInfo may change in subsequent calls. (although for now only
// Type 1 support is required.)
// 3. Upon OMX_GetConfig, the component SHALL return the final HDR static information by replacing
// Unspecified coded values with the default values. This SHALL always succeed. This may be
// provided using any supported descriptor ID (currently only Type 1) with the goal of expressing
// the most of the available static information.
// 4. Whenever the component processes HDR static information in the bitstream even ones with
// Unspecified parameters, it SHOULD update its internal coded structure with that information
// just before the frame with the new information would be outputted, and the component SHALL
// signal an OMX_EventPortSettingsChanged event with data2 set to the extension index.
// NOTE: Component SHOULD NOT signal a separate event purely for HDR static info change, if it
// occurs together with a port definition (e.g. size), color aspect or crop change.
// 5. If certain parameters of the HDR static information encountered in the bitstream cannot be
// represented using sInfo, the component SHALL use the closest representation.
//
// Note: the size of sInfo may increase in the future by supporting additional descriptor types.
// Implementations SHOULD NOT require a certain size.
struct DescribeHDRStaticInfoParams {
OMX_U32 nSize; // IN
OMX_VERSIONTYPE nVersion; // IN
OMX_U32 nPortIndex; // IN
HDRStaticInfo sInfo; // IN/OUT
};
// HDR10+ metadata configuration.
//
// nParamSize: size of the storage starting at nValue (must be at least 1 and at most
// MAX_HDR10PLUSINFO_SIZE). This field must not be modified by the component.
// nParamSizeUsed: size of the actual HDR10+ metadata starting at nValue. For OMX_SetConfig,
// it must not be modified by the component. For OMX_GetConfig, the component
// should put the actual size of the retrieved config in this field (and in
// case where nParamSize is smaller than nParamSizeUsed, the component should
// still update nParamSizeUsed without actually copying the metadata to nValue).
// nValue: storage of the HDR10+ metadata conforming to the user_data_registered_itu_t_t35()
// syntax of SEI message for ST 2094-40.
//
// This is passed via OMX_SetConfig or OMX_GetConfig to video encoders and decoders when the
// 'OMX.google.android.index.describeHDR10PlusInfo' extension is given. In general, this config
// is associated with a particular frame. A typical sequence of usage is as follows:
//
// a) OMX_SetConfig associates the config with the next input buffer sent in OMX_EmptyThisBuffer
// (input A);
// b) The component sends OMX_EventConfigUpdate to notify the client that there is a config
// update on the output port that is associated with the next output buffer that's about to
// be sent via FillBufferDone callback (output A);
// c) The client, upon receiving the OMX_EventConfigUpdate, calls OMX_GetConfig to retrieve
// the config and associates it with output A.
//
// All config updates will be retrieved in the order reported, and the client is required to
// call OMX_GetConfig for each OMX_EventConfigUpdate for this config. Note that the order of
// OMX_EventConfigUpdate relative to FillBufferDone callback determines which output frame
// the config should be associated with, the actual OMX_GetConfig for the config could happen
// before or after the component calls the FillBufferDone callback.
//
// Depending on the video codec type (in particular, whether the codec uses in-band or out-of-
// band HDR10+ metadata), the component shall behave as detailed below:
//
// VIDEO DECODERS:
// 1) If the codec utilizes out-of-band HDR10+ metadata, the decoder must support the sequence
// a) ~ c) outlined above;
// 2) If the codec utilizes in-band HDR10+ metadata, OMX_SetConfig for this config should be
// ignored (as the metadata is embedded in the input buffer), while the notification and
// retrieval of the config on the output as outlined in b) & c) must be supported.
//
// VIDEO ENCODERS:
// 1) If the codec utilizes out-of-band HDR10+ metadata, the decoder must support the sequence
// a) ~ c) outlined above;
// 2) If the codec utilizes in-band HDR10+ metadata, OMX_SetConfig for this config outlined in
// a) must be supported. The notification as outlined in b) must not be sent, and the
// retrieval of the config via OMX_GetConfig should be ignored (as the metadata is embedded
// in the output buffer).
#define MAX_HDR10PLUSINFO_SIZE 1024
struct DescribeHDR10PlusInfoParams {
OMX_U32 nSize; // IN
OMX_VERSIONTYPE nVersion; // IN
OMX_U32 nPortIndex; // IN
OMX_U32 nParamSize; // IN
OMX_U32 nParamSizeUsed; // IN/OUT
OMX_U8 nValue[1]; // IN/OUT
};
} // namespace android
extern android::OMXPluginBase *createOMXPlugin();
#endif // HARDWARE_API_H_
@@ -0,0 +1,149 @@
/*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef METADATA_BUFFER_TYPE_H
#define METADATA_BUFFER_TYPE_H
#ifdef __cplusplus
extern "C" {
namespace android {
#endif
/*
* MetadataBufferType defines the type of the metadata buffers that
* can be passed to video encoder component for encoding, via Stagefright
* media recording framework. To see how to work with the metadata buffers
* in media recording framework, please consult HardwareAPI.h
*
* The creator of metadata buffers and video encoder share common knowledge
* on what is actually being stored in these metadata buffers, and
* how the information can be used by the video encoder component
* to locate the actual pixel data as the source input for video
* encoder, plus whatever other information that is necessary. Stagefright
* media recording framework does not need to know anything specific about the
* metadata buffers, except for receving each individual metadata buffer
* as the source input, making a copy of the metadata buffer, and passing the
* copy via OpenMAX API to the video encoder component.
*
* The creator of the metadata buffers must ensure that the first
* 4 bytes in every metadata buffer indicates its buffer type,
* and the rest of the metadata buffer contains the
* actual metadata information. When a video encoder component receives
* a metadata buffer, it uses the first 4 bytes in that buffer to find
* out the type of the metadata buffer, and takes action appropriate
* to that type of metadata buffers (for instance, locate the actual
* pixel data input and then encoding the input data to produce a
* compressed output buffer).
*
* The following shows the layout of a metadata buffer,
* where buffer type is a 4-byte field of MetadataBufferType,
* and the payload is the metadata information.
*
* --------------------------------------------------------------
* | buffer type | payload |
* --------------------------------------------------------------
*
*/
typedef enum {
/*
* kMetadataBufferTypeCameraSource is used to indicate that
* the source of the metadata buffer is the camera component.
*/
kMetadataBufferTypeCameraSource = 0,
/*
* kMetadataBufferTypeGrallocSource is used to indicate that
* the payload of the metadata buffers can be interpreted as
* a buffer_handle_t.
* So in this case,the metadata that the encoder receives
* will have a byte stream that consists of two parts:
* 1. First, there is an integer indicating that it is a GRAlloc
* source (kMetadataBufferTypeGrallocSource)
* 2. This is followed by the buffer_handle_t that is a handle to the
* GRalloc buffer. The encoder needs to interpret this GRalloc handle
* and encode the frames.
* --------------------------------------------------------------
* | kMetadataBufferTypeGrallocSource | buffer_handle_t buffer |
* --------------------------------------------------------------
*
* See the VideoGrallocMetadata structure.
*/
kMetadataBufferTypeGrallocSource = 1,
/*
* kMetadataBufferTypeGraphicBuffer is used to indicate that
* the payload of the metadata buffers can be interpreted as
* an ANativeWindowBuffer, and that a fence is provided.
*
* In this case, the metadata will have a byte stream that consists of three parts:
* 1. First, there is an integer indicating that the metadata
* contains an ANativeWindowBuffer (kMetadataBufferTypeANWBuffer)
* 2. This is followed by the pointer to the ANativeWindowBuffer.
* Codec must not free this buffer as it does not actually own this buffer.
* 3. Finally, there is an integer containing a fence file descriptor.
* The codec must wait on the fence before encoding or decoding into this
* buffer. When the buffer is returned, codec must replace this file descriptor
* with a new fence, that will be waited on before the buffer is replaced
* (encoder) or read (decoder).
* ---------------------------------
* | kMetadataBufferTypeANWBuffer |
* ---------------------------------
* | ANativeWindowBuffer *buffer |
* ---------------------------------
* | int fenceFd |
* ---------------------------------
*
* See the VideoNativeMetadata structure.
*/
kMetadataBufferTypeANWBuffer = 2,
/*
* kMetadataBufferTypeNativeHandleSource is used to indicate that
* the payload of the metadata buffers can be interpreted as
* a native_handle_t.
*
* In this case, the metadata that the encoder receives
* will have a byte stream that consists of two parts:
* 1. First, there is an integer indicating that the metadata contains a
* native handle (kMetadataBufferTypeNativeHandleSource).
* 2. This is followed by a pointer to native_handle_t. The encoder needs
* to interpret this native handle and encode the frame. The encoder must
* not free this native handle as it does not actually own this native
* handle. The handle will be freed after the encoder releases the buffer
* back to camera.
* ----------------------------------------------------------------
* | kMetadataBufferTypeNativeHandleSource | native_handle_t* nh |
* ----------------------------------------------------------------
*
* See the VideoNativeHandleMetadata structure.
*/
kMetadataBufferTypeNativeHandleSource = 3,
/* This value is used by framework, but is never used inside a metadata buffer */
kMetadataBufferTypeInvalid = -1,
// Add more here...
} MetadataBufferType;
#ifdef __cplusplus
} // namespace android
}
#endif
#endif // METADATA_BUFFER_TYPE_H
@@ -0,0 +1,59 @@
/*
* Copyright (C) 2009 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OMX_PLUGIN_BASE_H_
#define OMX_PLUGIN_BASE_H_
#include <sys/types.h>
#include <OMX_Component.h>
#include <utils/String8.h>
#include <utils/Vector.h>
namespace android {
struct OMXPluginBase {
OMXPluginBase() {}
virtual ~OMXPluginBase() {}
virtual OMX_ERRORTYPE makeComponentInstance(
const char *name,
const OMX_CALLBACKTYPE *callbacks,
OMX_PTR appData,
OMX_COMPONENTTYPE **component) = 0;
virtual OMX_ERRORTYPE destroyComponentInstance(
OMX_COMPONENTTYPE *component) = 0;
virtual OMX_ERRORTYPE enumerateComponents(
OMX_STRING name,
size_t size,
OMX_U32 index) = 0;
virtual OMX_ERRORTYPE getRolesOfComponent(
const char *name,
Vector<String8> *roles) = 0;
private:
OMXPluginBase(const OMXPluginBase &);
OMXPluginBase &operator=(const OMXPluginBase &);
};
} // namespace android
#endif // OMX_PLUGIN_BASE_H_
@@ -0,0 +1,344 @@
/*
* Copyright (C) 2016 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef VIDEO_API_H_
#define VIDEO_API_H_
namespace android {
/**
* Structure describing a media image (frame)
* Currently only supporting YUV
* @deprecated. Use MediaImage2 instead
*/
struct MediaImage {
enum Type {
MEDIA_IMAGE_TYPE_UNKNOWN = 0,
MEDIA_IMAGE_TYPE_YUV,
};
enum PlaneIndex {
Y = 0,
U,
V,
MAX_NUM_PLANES
};
Type mType;
uint32_t mNumPlanes; // number of planes
uint32_t mWidth; // width of largest plane (unpadded, as in nFrameWidth)
uint32_t mHeight; // height of largest plane (unpadded, as in nFrameHeight)
uint32_t mBitDepth; // useable bit depth
struct PlaneInfo {
uint32_t mOffset; // offset of first pixel of the plane in bytes
// from buffer offset
uint32_t mColInc; // column increment in bytes
uint32_t mRowInc; // row increment in bytes
uint32_t mHorizSubsampling; // subsampling compared to the largest plane
uint32_t mVertSubsampling; // subsampling compared to the largest plane
};
PlaneInfo mPlane[MAX_NUM_PLANES];
};
/**
* Structure describing a media image (frame)
*/
struct __attribute__ ((__packed__)) MediaImage2 {
enum Type : uint32_t {
MEDIA_IMAGE_TYPE_UNKNOWN = 0,
MEDIA_IMAGE_TYPE_YUV,
MEDIA_IMAGE_TYPE_YUVA,
MEDIA_IMAGE_TYPE_RGB,
MEDIA_IMAGE_TYPE_RGBA,
MEDIA_IMAGE_TYPE_Y,
};
enum PlaneIndex : uint32_t {
Y = 0,
U = 1,
V = 2,
R = 0,
G = 1,
B = 2,
A = 3,
MAX_NUM_PLANES = 4,
};
Type mType;
uint32_t mNumPlanes; // number of planes
uint32_t mWidth; // width of largest plane (unpadded, as in nFrameWidth)
uint32_t mHeight; // height of largest plane (unpadded, as in nFrameHeight)
uint32_t mBitDepth; // useable bit depth (always MSB)
uint32_t mBitDepthAllocated; // bits per component (must be 8 or 16)
struct __attribute__ ((__packed__)) PlaneInfo {
uint32_t mOffset; // offset of first pixel of the plane in bytes
// from buffer offset
int32_t mColInc; // column increment in bytes
int32_t mRowInc; // row increment in bytes
uint32_t mHorizSubsampling; // subsampling compared to the largest plane
uint32_t mVertSubsampling; // subsampling compared to the largest plane
};
PlaneInfo mPlane[MAX_NUM_PLANES];
void initFromV1(const MediaImage&); // for internal use only
};
static_assert(sizeof(MediaImage2::PlaneInfo) == 20, "wrong struct size");
static_assert(sizeof(MediaImage2) == 104, "wrong struct size");
/**
* Aspects of color.
*/
// NOTE: this structure is expected to grow in the future if new color aspects are
// added to codec bitstreams. OMX component should not require a specific nSize
// though could verify that nSize is at least the size of the structure at the
// time of implementation. All new fields will be added at the end of the structure
// ensuring backward compatibility.
struct __attribute__ ((__packed__, aligned(alignof(uint32_t)))) ColorAspects {
// this is in sync with the range values in graphics.h
enum Range : uint32_t {
RangeUnspecified,
RangeFull,
RangeLimited,
RangeOther = 0xff,
};
enum Primaries : uint32_t {
PrimariesUnspecified,
PrimariesBT709_5, // Rec.ITU-R BT.709-5 or equivalent
PrimariesBT470_6M, // Rec.ITU-R BT.470-6 System M or equivalent
PrimariesBT601_6_625, // Rec.ITU-R BT.601-6 625 or equivalent
PrimariesBT601_6_525, // Rec.ITU-R BT.601-6 525 or equivalent
PrimariesGenericFilm, // Generic Film
PrimariesBT2020, // Rec.ITU-R BT.2020 or equivalent
PrimariesOther = 0xff,
};
// this partially in sync with the transfer values in graphics.h prior to the transfers
// unlikely to be required by Android section
enum Transfer : uint32_t {
TransferUnspecified,
TransferLinear, // Linear transfer characteristics
TransferSRGB, // sRGB or equivalent
TransferSMPTE170M, // SMPTE 170M or equivalent (e.g. BT.601/709/2020)
TransferGamma22, // Assumed display gamma 2.2
TransferGamma28, // Assumed display gamma 2.8
TransferST2084, // SMPTE ST 2084 for 10/12/14/16 bit systems
TransferHLG, // ARIB STD-B67 hybrid-log-gamma
// transfers unlikely to be required by Android
TransferSMPTE240M = 0x40, // SMPTE 240M
TransferXvYCC, // IEC 61966-2-4
TransferBT1361, // Rec.ITU-R BT.1361 extended gamut
TransferST428, // SMPTE ST 428-1
TransferOther = 0xff,
};
enum MatrixCoeffs : uint32_t {
MatrixUnspecified,
MatrixBT709_5, // Rec.ITU-R BT.709-5 or equivalent
MatrixBT470_6M, // KR=0.30, KB=0.11 or equivalent
MatrixBT601_6, // Rec.ITU-R BT.601-6 625 or equivalent
MatrixSMPTE240M, // SMPTE 240M or equivalent
MatrixBT2020, // Rec.ITU-R BT.2020 non-constant luminance
MatrixBT2020Constant, // Rec.ITU-R BT.2020 constant luminance
MatrixOther = 0xff,
};
// this is in sync with the standard values in graphics.h
enum Standard : uint32_t {
StandardUnspecified,
StandardBT709, // PrimariesBT709_5 and MatrixBT709_5
StandardBT601_625, // PrimariesBT601_6_625 and MatrixBT601_6
StandardBT601_625_Unadjusted, // PrimariesBT601_6_625 and KR=0.222, KB=0.071
StandardBT601_525, // PrimariesBT601_6_525 and MatrixBT601_6
StandardBT601_525_Unadjusted, // PrimariesBT601_6_525 and MatrixSMPTE240M
StandardBT2020, // PrimariesBT2020 and MatrixBT2020
StandardBT2020Constant, // PrimariesBT2020 and MatrixBT2020Constant
StandardBT470M, // PrimariesBT470_6M and MatrixBT470_6M
StandardFilm, // PrimariesGenericFilm and KR=0.253, KB=0.068
StandardOther = 0xff,
};
Range mRange; // IN/OUT
Primaries mPrimaries; // IN/OUT
Transfer mTransfer; // IN/OUT
MatrixCoeffs mMatrixCoeffs; // IN/OUT
};
static_assert(sizeof(ColorAspects) == 16, "wrong struct size");
/**
* HDR Metadata.
*/
// HDR Static Metadata Descriptor as defined by CTA-861-3.
struct __attribute__ ((__packed__)) HDRStaticInfo {
// Static_Metadata_Descriptor_ID
enum ID : uint8_t {
kType1 = 0, // Static Metadata Type 1
} mID;
struct __attribute__ ((__packed__)) Primaries1 {
// values are in units of 0.00002
uint16_t x;
uint16_t y;
};
// Static Metadata Descriptor Type 1
struct __attribute__ ((__packed__)) Type1 {
Primaries1 mR; // display primary 0
Primaries1 mG; // display primary 1
Primaries1 mB; // display primary 2
Primaries1 mW; // white point
uint16_t mMaxDisplayLuminance; // in cd/m^2
uint16_t mMinDisplayLuminance; // in 0.0001 cd/m^2
uint16_t mMaxContentLightLevel; // in cd/m^2
uint16_t mMaxFrameAverageLightLevel; // in cd/m^2
};
union {
Type1 sType1;
};
};
static_assert(sizeof(HDRStaticInfo::Primaries1) == 4, "wrong struct size");
static_assert(sizeof(HDRStaticInfo::Type1) == 24, "wrong struct size");
static_assert(sizeof(HDRStaticInfo) == 25, "wrong struct size");
#ifdef STRINGIFY_ENUMS
inline static const char *asString(MediaImage::Type i, const char *def = "??") {
switch (i) {
case MediaImage::MEDIA_IMAGE_TYPE_UNKNOWN: return "Unknown";
case MediaImage::MEDIA_IMAGE_TYPE_YUV: return "YUV";
default: return def;
}
}
inline static const char *asString(MediaImage::PlaneIndex i, const char *def = "??") {
switch (i) {
case MediaImage::Y: return "Y";
case MediaImage::U: return "U";
case MediaImage::V: return "V";
default: return def;
}
}
inline static const char *asString(MediaImage2::Type i, const char *def = "??") {
switch (i) {
case MediaImage2::MEDIA_IMAGE_TYPE_UNKNOWN: return "Unknown";
case MediaImage2::MEDIA_IMAGE_TYPE_YUV: return "YUV";
case MediaImage2::MEDIA_IMAGE_TYPE_YUVA: return "YUVA";
case MediaImage2::MEDIA_IMAGE_TYPE_RGB: return "RGB";
case MediaImage2::MEDIA_IMAGE_TYPE_RGBA: return "RGBA";
case MediaImage2::MEDIA_IMAGE_TYPE_Y: return "Y";
default: return def;
}
}
inline static char asChar2(
MediaImage2::PlaneIndex i, MediaImage2::Type j, char def = '?') {
const char *planes = asString(j, NULL);
// handle unknown values
if (j == MediaImage2::MEDIA_IMAGE_TYPE_UNKNOWN || planes == NULL || i >= strlen(planes)) {
return def;
}
return planes[i];
}
inline static const char *asString(ColorAspects::Range i, const char *def = "??") {
switch (i) {
case ColorAspects::RangeUnspecified: return "Unspecified";
case ColorAspects::RangeFull: return "Full";
case ColorAspects::RangeLimited: return "Limited";
case ColorAspects::RangeOther: return "Other";
default: return def;
}
}
inline static const char *asString(ColorAspects::Primaries i, const char *def = "??") {
switch (i) {
case ColorAspects::PrimariesUnspecified: return "Unspecified";
case ColorAspects::PrimariesBT709_5: return "BT709_5";
case ColorAspects::PrimariesBT470_6M: return "BT470_6M";
case ColorAspects::PrimariesBT601_6_625: return "BT601_6_625";
case ColorAspects::PrimariesBT601_6_525: return "BT601_6_525";
case ColorAspects::PrimariesGenericFilm: return "GenericFilm";
case ColorAspects::PrimariesBT2020: return "BT2020";
case ColorAspects::PrimariesOther: return "Other";
default: return def;
}
}
inline static const char *asString(ColorAspects::Transfer i, const char *def = "??") {
switch (i) {
case ColorAspects::TransferUnspecified: return "Unspecified";
case ColorAspects::TransferLinear: return "Linear";
case ColorAspects::TransferSRGB: return "SRGB";
case ColorAspects::TransferSMPTE170M: return "SMPTE170M";
case ColorAspects::TransferGamma22: return "Gamma22";
case ColorAspects::TransferGamma28: return "Gamma28";
case ColorAspects::TransferST2084: return "ST2084";
case ColorAspects::TransferHLG: return "HLG";
case ColorAspects::TransferSMPTE240M: return "SMPTE240M";
case ColorAspects::TransferXvYCC: return "XvYCC";
case ColorAspects::TransferBT1361: return "BT1361";
case ColorAspects::TransferST428: return "ST428";
case ColorAspects::TransferOther: return "Other";
default: return def;
}
}
inline static const char *asString(ColorAspects::MatrixCoeffs i, const char *def = "??") {
switch (i) {
case ColorAspects::MatrixUnspecified: return "Unspecified";
case ColorAspects::MatrixBT709_5: return "BT709_5";
case ColorAspects::MatrixBT470_6M: return "BT470_6M";
case ColorAspects::MatrixBT601_6: return "BT601_6";
case ColorAspects::MatrixSMPTE240M: return "SMPTE240M";
case ColorAspects::MatrixBT2020: return "BT2020";
case ColorAspects::MatrixBT2020Constant: return "BT2020Constant";
case ColorAspects::MatrixOther: return "Other";
default: return def;
}
}
inline static const char *asString(ColorAspects::Standard i, const char *def = "??") {
switch (i) {
case ColorAspects::StandardUnspecified: return "Unspecified";
case ColorAspects::StandardBT709: return "BT709";
case ColorAspects::StandardBT601_625: return "BT601_625";
case ColorAspects::StandardBT601_625_Unadjusted: return "BT601_625_Unadjusted";
case ColorAspects::StandardBT601_525: return "BT601_525";
case ColorAspects::StandardBT601_525_Unadjusted: return "BT601_525_Unadjusted";
case ColorAspects::StandardBT2020: return "BT2020";
case ColorAspects::StandardBT2020Constant: return "BT2020Constant";
case ColorAspects::StandardBT470M: return "BT470M";
case ColorAspects::StandardFilm: return "Film";
case ColorAspects::StandardOther: return "Other";
default: return def;
}
}
#endif
} // namespace android
#endif // VIDEO_API_H_
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,144 @@
/*
* Copyright (c) 2010 The Khronos Group Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject
* to the following conditions:
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
/** OMX_AudioExt.h - OpenMax IL version 1.1.2
* The OMX_AudioExt header file contains extensions to the
* definitions used by both the application and the component to
* access video items.
*/
#ifndef OMX_AudioExt_h
#define OMX_AudioExt_h
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/* Each OMX header shall include all required header files to allow the
* header to compile without errors. The includes below are required
* for this header file to compile successfully
*/
#include <OMX_Core.h>
#define OMX_AUDIO_AACToolAndroidSSBR (OMX_AUDIO_AACToolVendor << 0) /**< SSBR: MPEG-4 Single-rate (downsampled) Spectral Band Replication tool allowed or active */
#define OMX_AUDIO_AACToolAndroidDSBR (OMX_AUDIO_AACToolVendor << 1) /**< DSBR: MPEG-4 Dual-rate Spectral Band Replication tool allowed or active */
typedef enum OMX_AUDIO_CODINGEXTTYPE {
OMX_AUDIO_CodingAndroidUnused = OMX_AUDIO_CodingKhronosExtensions + 0x00100000,
OMX_AUDIO_CodingAndroidAC3, /**< AC3 encoded data */
OMX_AUDIO_CodingAndroidOPUS, /**< OPUS encoded data */
OMX_AUDIO_CodingAndroidEAC3, /**< EAC3 encoded data */
OMX_AUDIO_CodingAndroidAC4, /**< AC4 encoded data */
} OMX_AUDIO_CODINGEXTTYPE;
typedef struct OMX_AUDIO_PARAM_ANDROID_AC3TYPE {
OMX_U32 nSize; /**< size of the structure in bytes */
OMX_VERSIONTYPE nVersion; /**< OMX specification version information */
OMX_U32 nPortIndex; /**< port that this structure applies to */
OMX_U32 nChannels; /**< Number of channels */
OMX_U32 nSampleRate; /**< Sampling rate of the source data. Use 0 for
variable or unknown sampling rate. */
} OMX_AUDIO_PARAM_ANDROID_AC3TYPE;
typedef struct OMX_AUDIO_PARAM_ANDROID_EAC3TYPE {
OMX_U32 nSize; /**< size of the structure in bytes */
OMX_VERSIONTYPE nVersion; /**< OMX specification version information */
OMX_U32 nPortIndex; /**< port that this structure applies to */
OMX_U32 nChannels; /**< Number of channels */
OMX_U32 nSampleRate; /**< Sampling rate of the source data. Use 0 for
variable or unknown sampling rate. */
} OMX_AUDIO_PARAM_ANDROID_EAC3TYPE;
typedef struct OMX_AUDIO_PARAM_ANDROID_AC4TYPE {
OMX_U32 nSize; /**< size of the structure in bytes */
OMX_VERSIONTYPE nVersion; /**< OMX specification version information */
OMX_U32 nPortIndex; /**< port that this structure applies to */
OMX_U32 nChannels; /**< Number of channels */
OMX_U32 nSampleRate; /**< Sampling rate of the source data. Use 0 for
variable or unknown sampling rate. */
} OMX_AUDIO_PARAM_ANDROID_AC4TYPE;
typedef struct OMX_AUDIO_PARAM_ANDROID_OPUSTYPE {
OMX_U32 nSize; /**< size of the structure in bytes */
OMX_VERSIONTYPE nVersion; /**< OMX specification version information */
OMX_U32 nPortIndex; /**< port that this structure applies to */
OMX_U32 nChannels; /**< Number of channels */
OMX_U32 nBitRate; /**< Bit rate of the encoded data data. Use 0 for variable
rate or unknown bit rates. Encoding is set to the
bitrate closest to specified value (in bps) */
OMX_U32 nSampleRate; /**< Sampling rate of the source data. Use 0 for
variable or unknown sampling rate. */
OMX_U32 nAudioBandWidth; /**< Audio band width (in Hz) to which an encoder should
limit the audio signal. Use 0 to let encoder decide */
} OMX_AUDIO_PARAM_ANDROID_OPUSTYPE;
/** deprecated. use OMX_AUDIO_PARAM_ANDROID_AACDRCPRESENTATIONTYPE */
typedef struct OMX_AUDIO_PARAM_ANDROID_AACPRESENTATIONTYPE {
OMX_U32 nSize; /**< size of the structure in bytes */
OMX_VERSIONTYPE nVersion; /**< OMX specification version information */
OMX_S32 nMaxOutputChannels; /**< Maximum channel count to be output, -1 if unspecified, 0 if downmixing disabled */
OMX_S32 nDrcCut; /**< The DRC attenuation factor, between 0 and 127, -1 if unspecified */
OMX_S32 nDrcBoost; /**< The DRC amplification factor, between 0 and 127, -1 if unspecified */
OMX_S32 nHeavyCompression; /**< 0 for light compression, 1 for heavy compression, -1 if unspecified */
OMX_S32 nTargetReferenceLevel; /**< Target reference level, between 0 and 127, -1 if unspecified */
OMX_S32 nEncodedTargetLevel; /**< Target reference level assumed at the encoder, between 0 and 127, -1 if unspecified */
OMX_S32 nPCMLimiterEnable; /**< Signal level limiting, 0 for disable, 1 for enable, -1 if unspecified */
} OMX_AUDIO_PARAM_ANDROID_AACPRESENTATIONTYPE;
typedef struct OMX_AUDIO_PARAM_ANDROID_AACDRCPRESENTATIONTYPE {
OMX_U32 nSize; /**< size of the structure in bytes */
OMX_VERSIONTYPE nVersion; /**< OMX specification version information */
OMX_S32 nMaxOutputChannels; /**< Maximum channel count to be output, -1 if unspecified, 0 if downmixing disabled */
OMX_S32 nDrcCut; /**< The DRC attenuation factor, between 0 and 127, -1 if unspecified */
OMX_S32 nDrcBoost; /**< The DRC amplification factor, between 0 and 127, -1 if unspecified */
OMX_S32 nHeavyCompression; /**< 0 for light compression, 1 for heavy compression, -1 if unspecified */
OMX_S32 nTargetReferenceLevel; /**< Target reference level, between 0 and 127, -1 if unspecified */
OMX_S32 nEncodedTargetLevel; /**< Target reference level assumed at the encoder, between 0 and 127, -1 if unspecified */
OMX_S32 nPCMLimiterEnable; /**< Signal level limiting, 0 for disable, 1 for enable, -1 if unspecified */
OMX_S32 nDrcEffectType; /**< MPEG-D DRC effect type, between -1 and 6, -2 if unspecified */
OMX_S32 nDrcOutputLoudness; /**< MPEG-D DRC Output Loudness, between -1 and 231, -2 if unspecified */
OMX_S32 nDrcAlbumMode; /**< MPEG-D DRC Album Mode, between 0 and 1, -1 if unspecified */
} OMX_AUDIO_PARAM_ANDROID_AACDRCPRESENTATIONTYPE;
typedef struct OMX_AUDIO_PARAM_ANDROID_PROFILETYPE {
OMX_U32 nSize;
OMX_VERSIONTYPE nVersion;
OMX_U32 nPortIndex;
OMX_U32 eProfile; /**< type is OMX_AUDIO_AACPROFILETYPE or OMX_AUDIO_WMAPROFILETYPE
depending on context */
OMX_U32 nProfileIndex; /**< Used to query for individual profile support information */
} OMX_AUDIO_PARAM_ANDROID_PROFILETYPE;
typedef struct OMX_AUDIO_CONFIG_ANDROID_AUDIOPRESENTATION {
OMX_U32 nSize; /**< size of the structure in bytes */
OMX_VERSIONTYPE nVersion; /**< OMX specification version information */
OMX_S32 nPresentationId; /**< presentation id */
OMX_S32 nProgramId; /**< program id */
} OMX_AUDIO_CONFIG_ANDROID_AUDIOPRESENTATION;
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* OMX_AudioExt_h */
/* File EOF */
@@ -0,0 +1,596 @@
/* ------------------------------------------------------------------
* Copyright (C) 1998-2009 PacketVideo
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied.
* See the License for the specific language governing permissions
* and limitations under the License.
* -------------------------------------------------------------------
*/
/*
* Copyright (c) 2008 The Khronos Group Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject
* to the following conditions:
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
/** OMX_Component.h - OpenMax IL version 1.1.2
* The OMX_Component header file contains the definitions used to define
* the public interface of a component. This header file is intended to
* be used by both the application and the component.
*/
#ifndef OMX_Component_h
#define OMX_Component_h
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/* Each OMX header must include all required header files to allow the
* header to compile without errors. The includes below are required
* for this header file to compile successfully
*/
#include <OMX_Audio.h>
#include <OMX_Video.h>
#include <OMX_Image.h>
#include <OMX_Other.h>
/** @ingroup comp */
typedef enum OMX_PORTDOMAINTYPE {
OMX_PortDomainAudio,
OMX_PortDomainVideo,
OMX_PortDomainImage,
OMX_PortDomainOther,
OMX_PortDomainKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */
OMX_PortDomainVendorStartUnused = 0x7F000000, /**< Reserved region for introducing Vendor Extensions */
OMX_PortDomainMax = 0x7ffffff
} OMX_PORTDOMAINTYPE;
/** @ingroup comp */
typedef struct OMX_PARAM_PORTDEFINITIONTYPE {
OMX_U32 nSize; /**< Size of the structure in bytes */
OMX_VERSIONTYPE nVersion; /**< OMX specification version information */
OMX_U32 nPortIndex; /**< Port number the structure applies to */
OMX_DIRTYPE eDir; /**< Direction (input or output) of this port */
OMX_U32 nBufferCountActual; /**< The actual number of buffers allocated on this port */
OMX_U32 nBufferCountMin; /**< The minimum number of buffers this port requires */
OMX_U32 nBufferSize; /**< Size, in bytes, for buffers to be used for this channel */
OMX_BOOL bEnabled; /**< Ports default to enabled and are enabled/disabled by
OMX_CommandPortEnable/OMX_CommandPortDisable.
When disabled a port is unpopulated. A disabled port
is not populated with buffers on a transition to IDLE. */
OMX_BOOL bPopulated; /**< Port is populated with all of its buffers as indicated by
nBufferCountActual. A disabled port is always unpopulated.
An enabled port is populated on a transition to OMX_StateIdle
and unpopulated on a transition to loaded. */
OMX_PORTDOMAINTYPE eDomain; /**< Domain of the port. Determines the contents of metadata below. */
union {
OMX_AUDIO_PORTDEFINITIONTYPE audio;
OMX_VIDEO_PORTDEFINITIONTYPE video;
OMX_IMAGE_PORTDEFINITIONTYPE image;
OMX_OTHER_PORTDEFINITIONTYPE other;
} format;
OMX_BOOL bBuffersContiguous;
OMX_U32 nBufferAlignment;
} OMX_PARAM_PORTDEFINITIONTYPE;
/** @ingroup comp */
typedef struct OMX_PARAM_U32TYPE {
OMX_U32 nSize; /**< Size of this structure, in Bytes */
OMX_VERSIONTYPE nVersion; /**< OMX specification version information */
OMX_U32 nPortIndex; /**< port that this structure applies to */
OMX_U32 nU32; /**< U32 value */
} OMX_PARAM_U32TYPE;
/** @ingroup rpm */
typedef enum OMX_SUSPENSIONPOLICYTYPE {
OMX_SuspensionDisabled, /**< No suspension; v1.0 behavior */
OMX_SuspensionEnabled, /**< Suspension allowed */
OMX_SuspensionPolicyKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */
OMX_SuspensionPolicyStartUnused = 0x7F000000, /**< Reserved region for introducing Vendor Extensions */
OMX_SuspensionPolicyMax = 0x7fffffff
} OMX_SUSPENSIONPOLICYTYPE;
/** @ingroup rpm */
typedef struct OMX_PARAM_SUSPENSIONPOLICYTYPE {
OMX_U32 nSize;
OMX_VERSIONTYPE nVersion;
OMX_SUSPENSIONPOLICYTYPE ePolicy;
} OMX_PARAM_SUSPENSIONPOLICYTYPE;
/** @ingroup rpm */
typedef enum OMX_SUSPENSIONTYPE {
OMX_NotSuspended, /**< component is not suspended */
OMX_Suspended, /**< component is suspended */
OMX_SuspensionKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */
OMX_SuspensionVendorStartUnused = 0x7F000000, /**< Reserved region for introducing Vendor Extensions */
OMX_SuspendMax = 0x7FFFFFFF
} OMX_SUSPENSIONTYPE;
/** @ingroup rpm */
typedef struct OMX_PARAM_SUSPENSIONTYPE {
OMX_U32 nSize;
OMX_VERSIONTYPE nVersion;
OMX_SUSPENSIONTYPE eType;
} OMX_PARAM_SUSPENSIONTYPE ;
typedef struct OMX_CONFIG_BOOLEANTYPE {
OMX_U32 nSize;
OMX_VERSIONTYPE nVersion;
OMX_BOOL bEnabled;
} OMX_CONFIG_BOOLEANTYPE;
/* Parameter specifying the content uri to use. */
/** @ingroup cp */
typedef struct OMX_PARAM_CONTENTURITYPE
{
OMX_U32 nSize; /**< size of the structure in bytes, including
actual URI name */
OMX_VERSIONTYPE nVersion; /**< OMX specification version information */
OMX_U8 contentURI[1]; /**< The URI name */
} OMX_PARAM_CONTENTURITYPE;
/* Parameter specifying the pipe to use. */
/** @ingroup cp */
typedef struct OMX_PARAM_CONTENTPIPETYPE
{
OMX_U32 nSize; /**< size of the structure in bytes */
OMX_VERSIONTYPE nVersion; /**< OMX specification version information */
OMX_HANDLETYPE hPipe; /**< The pipe handle*/
} OMX_PARAM_CONTENTPIPETYPE;
/** @ingroup rpm */
typedef struct OMX_RESOURCECONCEALMENTTYPE {
OMX_U32 nSize; /**< size of the structure in bytes */
OMX_VERSIONTYPE nVersion; /**< OMX specification version information */
OMX_BOOL bResourceConcealmentForbidden; /**< disallow the use of resource concealment
methods (like degrading algorithm quality to
lower resource consumption or functional bypass)
on a component as a resolution to resource conflicts. */
} OMX_RESOURCECONCEALMENTTYPE;
/** @ingroup metadata */
typedef enum OMX_METADATACHARSETTYPE {
OMX_MetadataCharsetUnknown = 0,
OMX_MetadataCharsetASCII,
OMX_MetadataCharsetBinary,
OMX_MetadataCharsetCodePage1252,
OMX_MetadataCharsetUTF8,
OMX_MetadataCharsetJavaConformantUTF8,
OMX_MetadataCharsetUTF7,
OMX_MetadataCharsetImapUTF7,
OMX_MetadataCharsetUTF16LE,
OMX_MetadataCharsetUTF16BE,
OMX_MetadataCharsetGB12345,
OMX_MetadataCharsetHZGB2312,
OMX_MetadataCharsetGB2312,
OMX_MetadataCharsetGB18030,
OMX_MetadataCharsetGBK,
OMX_MetadataCharsetBig5,
OMX_MetadataCharsetISO88591,
OMX_MetadataCharsetISO88592,
OMX_MetadataCharsetISO88593,
OMX_MetadataCharsetISO88594,
OMX_MetadataCharsetISO88595,
OMX_MetadataCharsetISO88596,
OMX_MetadataCharsetISO88597,
OMX_MetadataCharsetISO88598,
OMX_MetadataCharsetISO88599,
OMX_MetadataCharsetISO885910,
OMX_MetadataCharsetISO885913,
OMX_MetadataCharsetISO885914,
OMX_MetadataCharsetISO885915,
OMX_MetadataCharsetShiftJIS,
OMX_MetadataCharsetISO2022JP,
OMX_MetadataCharsetISO2022JP1,
OMX_MetadataCharsetISOEUCJP,
OMX_MetadataCharsetSMS7Bit,
OMX_MetadataCharsetKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */
OMX_MetadataCharsetVendorStartUnused = 0x7F000000, /**< Reserved region for introducing Vendor Extensions */
OMX_MetadataCharsetTypeMax= 0x7FFFFFFF
} OMX_METADATACHARSETTYPE;
/** @ingroup metadata */
typedef enum OMX_METADATASCOPETYPE
{
OMX_MetadataScopeAllLevels,
OMX_MetadataScopeTopLevel,
OMX_MetadataScopePortLevel,
OMX_MetadataScopeNodeLevel,
OMX_MetadataScopeKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */
OMX_MetadataScopeVendorStartUnused = 0x7F000000, /**< Reserved region for introducing Vendor Extensions */
OMX_MetadataScopeTypeMax = 0x7fffffff
} OMX_METADATASCOPETYPE;
/** @ingroup metadata */
typedef enum OMX_METADATASEARCHMODETYPE
{
OMX_MetadataSearchValueSizeByIndex,
OMX_MetadataSearchItemByIndex,
OMX_MetadataSearchNextItemByKey,
OMX_MetadataSearchKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */
OMX_MetadataSearchVendorStartUnused = 0x7F000000, /**< Reserved region for introducing Vendor Extensions */
OMX_MetadataSearchTypeMax = 0x7fffffff
} OMX_METADATASEARCHMODETYPE;
/** @ingroup metadata */
typedef struct OMX_CONFIG_METADATAITEMCOUNTTYPE
{
OMX_U32 nSize;
OMX_VERSIONTYPE nVersion;
OMX_METADATASCOPETYPE eScopeMode;
OMX_U32 nScopeSpecifier;
OMX_U32 nMetadataItemCount;
} OMX_CONFIG_METADATAITEMCOUNTTYPE;
/** @ingroup metadata */
typedef struct OMX_CONFIG_METADATAITEMTYPE
{
OMX_U32 nSize;
OMX_VERSIONTYPE nVersion;
OMX_METADATASCOPETYPE eScopeMode;
OMX_U32 nScopeSpecifier;
OMX_U32 nMetadataItemIndex;
OMX_METADATASEARCHMODETYPE eSearchMode;
OMX_METADATACHARSETTYPE eKeyCharset;
OMX_U8 nKeySizeUsed;
OMX_U8 nKey[128];
OMX_METADATACHARSETTYPE eValueCharset;
OMX_STRING sLanguageCountry;
OMX_U32 nValueMaxSize;
OMX_U32 nValueSizeUsed;
OMX_U8 nValue[1];
} OMX_CONFIG_METADATAITEMTYPE;
/* @ingroup metadata */
typedef struct OMX_CONFIG_CONTAINERNODECOUNTTYPE
{
OMX_U32 nSize;
OMX_VERSIONTYPE nVersion;
OMX_BOOL bAllKeys;
OMX_U32 nParentNodeID;
OMX_U32 nNumNodes;
} OMX_CONFIG_CONTAINERNODECOUNTTYPE;
/** @ingroup metadata */
typedef struct OMX_CONFIG_CONTAINERNODEIDTYPE
{
OMX_U32 nSize;
OMX_VERSIONTYPE nVersion;
OMX_BOOL bAllKeys;
OMX_U32 nParentNodeID;
OMX_U32 nNodeIndex;
OMX_U32 nNodeID;
OMX_STRING cNodeName;
OMX_BOOL bIsLeafType;
} OMX_CONFIG_CONTAINERNODEIDTYPE;
/** @ingroup metadata */
typedef struct OMX_PARAM_METADATAFILTERTYPE
{
OMX_U32 nSize;
OMX_VERSIONTYPE nVersion;
OMX_BOOL bAllKeys; /* if true then this structure refers to all keys and
* the three key fields below are ignored */
OMX_METADATACHARSETTYPE eKeyCharset;
OMX_U32 nKeySizeUsed;
OMX_U8 nKey [128];
OMX_U32 nLanguageCountrySizeUsed;
OMX_U8 nLanguageCountry[128];
OMX_BOOL bEnabled; /* if true then key is part of filter (e.g.
* retained for query later). If false then
* key is not part of filter */
} OMX_PARAM_METADATAFILTERTYPE;
/** The OMX_HANDLETYPE structure defines the component handle. The component
* handle is used to access all of the component's public methods and also
* contains pointers to the component's private data area. The component
* handle is initialized by the OMX core (with help from the component)
* during the process of loading the component. After the component is
* successfully loaded, the application can safely access any of the
* component's public functions (although some may return an error because
* the state is inappropriate for the access).
*
* @ingroup comp
*/
typedef struct OMX_COMPONENTTYPE
{
/** The size of this structure, in bytes. It is the responsibility
of the allocator of this structure to fill in this value. Since
this structure is allocated by the GetHandle function, this
function will fill in this value. */
OMX_U32 nSize;
/** nVersion is the version of the OMX specification that the structure
is built against. It is the responsibility of the creator of this
structure to initialize this value and every user of this structure
should verify that it knows how to use the exact version of
this structure found herein. */
OMX_VERSIONTYPE nVersion;
/** pComponentPrivate is a pointer to the component private data area.
This member is allocated and initialized by the component when the
component is first loaded. The application should not access this
data area. */
OMX_PTR pComponentPrivate;
/** pApplicationPrivate is a pointer that is a parameter to the
OMX_GetHandle method, and contains an application private value
provided by the IL client. This application private data is
returned to the IL Client by OMX in all callbacks */
OMX_PTR pApplicationPrivate;
/** refer to OMX_GetComponentVersion in OMX_core.h or the OMX IL
specification for details on the GetComponentVersion method.
*/
OMX_ERRORTYPE (*GetComponentVersion)(
OMX_IN OMX_HANDLETYPE hComponent,
OMX_OUT OMX_STRING pComponentName,
OMX_OUT OMX_VERSIONTYPE* pComponentVersion,
OMX_OUT OMX_VERSIONTYPE* pSpecVersion,
OMX_OUT OMX_UUIDTYPE* pComponentUUID);
/** refer to OMX_SendCommand in OMX_core.h or the OMX IL
specification for details on the SendCommand method.
*/
OMX_ERRORTYPE (*SendCommand)(
OMX_IN OMX_HANDLETYPE hComponent,
OMX_IN OMX_COMMANDTYPE Cmd,
OMX_IN OMX_U32 nParam1,
OMX_IN OMX_PTR pCmdData);
/** refer to OMX_GetParameter in OMX_core.h or the OMX IL
specification for details on the GetParameter method.
*/
OMX_ERRORTYPE (*GetParameter)(
OMX_IN OMX_HANDLETYPE hComponent,
OMX_IN OMX_INDEXTYPE nParamIndex,
OMX_INOUT OMX_PTR pComponentParameterStructure);
/** refer to OMX_SetParameter in OMX_core.h or the OMX IL
specification for details on the SetParameter method.
*/
OMX_ERRORTYPE (*SetParameter)(
OMX_IN OMX_HANDLETYPE hComponent,
OMX_IN OMX_INDEXTYPE nIndex,
OMX_IN OMX_PTR pComponentParameterStructure);
/** refer to OMX_GetConfig in OMX_core.h or the OMX IL
specification for details on the GetConfig method.
*/
OMX_ERRORTYPE (*GetConfig)(
OMX_IN OMX_HANDLETYPE hComponent,
OMX_IN OMX_INDEXTYPE nIndex,
OMX_INOUT OMX_PTR pComponentConfigStructure);
/** refer to OMX_SetConfig in OMX_core.h or the OMX IL
specification for details on the SetConfig method.
*/
OMX_ERRORTYPE (*SetConfig)(
OMX_IN OMX_HANDLETYPE hComponent,
OMX_IN OMX_INDEXTYPE nIndex,
OMX_IN OMX_PTR pComponentConfigStructure);
/** refer to OMX_GetExtensionIndex in OMX_core.h or the OMX IL
specification for details on the GetExtensionIndex method.
*/
OMX_ERRORTYPE (*GetExtensionIndex)(
OMX_IN OMX_HANDLETYPE hComponent,
OMX_IN OMX_STRING cParameterName,
OMX_OUT OMX_INDEXTYPE* pIndexType);
/** refer to OMX_GetState in OMX_core.h or the OMX IL
specification for details on the GetState method.
*/
OMX_ERRORTYPE (*GetState)(
OMX_IN OMX_HANDLETYPE hComponent,
OMX_OUT OMX_STATETYPE* pState);
/** The ComponentTunnelRequest method will interact with another OMX
component to determine if tunneling is possible and to setup the
tunneling. The return codes for this method can be used to
determine if tunneling is not possible, or if tunneling is not
supported.
Base profile components (i.e. non-interop) do not support this
method and should return OMX_ErrorNotImplemented
The interop profile component MUST support tunneling to another
interop profile component with a compatible port parameters.
A component may also support proprietary communication.
If proprietary communication is supported the negotiation of
proprietary communication is done outside of OMX in a vendor
specific way. It is only required that the proper result be
returned and the details of how the setup is done is left
to the component implementation.
When this method is invoked when nPort in an output port, the
component will:
1. Populate the pTunnelSetup structure with the output port's
requirements and constraints for the tunnel.
When this method is invoked when nPort in an input port, the
component will:
1. Query the necessary parameters from the output port to
determine if the ports are compatible for tunneling
2. If the ports are compatible, the component should store
the tunnel step provided by the output port
3. Determine which port (either input or output) is the buffer
supplier, and call OMX_SetParameter on the output port to
indicate this selection.
The component will return from this call within 5 msec.
@param [in] hComp
Handle of the component to be accessed. This is the component
handle returned by the call to the OMX_GetHandle method.
@param [in] nPort
nPort is used to select the port on the component to be used
for tunneling.
@param [in] hTunneledComp
Handle of the component to tunnel with. This is the component
handle returned by the call to the OMX_GetHandle method. When
this parameter is 0x0 the component should setup the port for
communication with the application / IL Client.
@param [in] nPortOutput
nPortOutput is used indicate the port the component should
tunnel with.
@param [in] pTunnelSetup
Pointer to the tunnel setup structure. When nPort is an output port
the component should populate the fields of this structure. When
When nPort is an input port the component should review the setup
provided by the component with the output port.
@return OMX_ERRORTYPE
If the command successfully executes, the return code will be
OMX_ErrorNone. Otherwise the appropriate OMX error will be returned.
@ingroup tun
*/
OMX_ERRORTYPE (*ComponentTunnelRequest)(
OMX_IN OMX_HANDLETYPE hComp,
OMX_IN OMX_U32 nPort,
OMX_IN OMX_HANDLETYPE hTunneledComp,
OMX_IN OMX_U32 nTunneledPort,
OMX_INOUT OMX_TUNNELSETUPTYPE* pTunnelSetup);
/** refer to OMX_UseBuffer in OMX_core.h or the OMX IL
specification for details on the UseBuffer method.
@ingroup buf
*/
OMX_ERRORTYPE (*UseBuffer)(
OMX_IN OMX_HANDLETYPE hComponent,
OMX_INOUT OMX_BUFFERHEADERTYPE** ppBufferHdr,
OMX_IN OMX_U32 nPortIndex,
OMX_IN OMX_PTR pAppPrivate,
OMX_IN OMX_U32 nSizeBytes,
OMX_IN OMX_U8* pBuffer);
/** refer to OMX_AllocateBuffer in OMX_core.h or the OMX IL
specification for details on the AllocateBuffer method.
@ingroup buf
*/
OMX_ERRORTYPE (*AllocateBuffer)(
OMX_IN OMX_HANDLETYPE hComponent,
OMX_INOUT OMX_BUFFERHEADERTYPE** ppBuffer,
OMX_IN OMX_U32 nPortIndex,
OMX_IN OMX_PTR pAppPrivate,
OMX_IN OMX_U32 nSizeBytes);
/** refer to OMX_FreeBuffer in OMX_core.h or the OMX IL
specification for details on the FreeBuffer method.
@ingroup buf
*/
OMX_ERRORTYPE (*FreeBuffer)(
OMX_IN OMX_HANDLETYPE hComponent,
OMX_IN OMX_U32 nPortIndex,
OMX_IN OMX_BUFFERHEADERTYPE* pBuffer);
/** refer to OMX_EmptyThisBuffer in OMX_core.h or the OMX IL
specification for details on the EmptyThisBuffer method.
@ingroup buf
*/
OMX_ERRORTYPE (*EmptyThisBuffer)(
OMX_IN OMX_HANDLETYPE hComponent,
OMX_IN OMX_BUFFERHEADERTYPE* pBuffer);
/** refer to OMX_FillThisBuffer in OMX_core.h or the OMX IL
specification for details on the FillThisBuffer method.
@ingroup buf
*/
OMX_ERRORTYPE (*FillThisBuffer)(
OMX_IN OMX_HANDLETYPE hComponent,
OMX_IN OMX_BUFFERHEADERTYPE* pBuffer);
/** The SetCallbacks method is used by the core to specify the callback
structure from the application to the component. This is a blocking
call. The component will return from this call within 5 msec.
@param [in] hComponent
Handle of the component to be accessed. This is the component
handle returned by the call to the GetHandle function.
@param [in] pCallbacks
pointer to an OMX_CALLBACKTYPE structure used to provide the
callback information to the component
@param [in] pAppData
pointer to an application defined value. It is anticipated that
the application will pass a pointer to a data structure or a "this
pointer" in this area to allow the callback (in the application)
to determine the context of the call
@return OMX_ERRORTYPE
If the command successfully executes, the return code will be
OMX_ErrorNone. Otherwise the appropriate OMX error will be returned.
*/
OMX_ERRORTYPE (*SetCallbacks)(
OMX_IN OMX_HANDLETYPE hComponent,
OMX_IN OMX_CALLBACKTYPE* pCallbacks,
OMX_IN OMX_PTR pAppData);
/** ComponentDeInit method is used to deinitialize the component
providing a means to free any resources allocated at component
initialization. NOTE: After this call the component handle is
not valid for further use.
@param [in] hComponent
Handle of the component to be accessed. This is the component
handle returned by the call to the GetHandle function.
@return OMX_ERRORTYPE
If the command successfully executes, the return code will be
OMX_ErrorNone. Otherwise the appropriate OMX error will be returned.
*/
OMX_ERRORTYPE (*ComponentDeInit)(
OMX_IN OMX_HANDLETYPE hComponent);
/** @ingroup buf */
OMX_ERRORTYPE (*UseEGLImage)(
OMX_IN OMX_HANDLETYPE hComponent,
OMX_INOUT OMX_BUFFERHEADERTYPE** ppBufferHdr,
OMX_IN OMX_U32 nPortIndex,
OMX_IN OMX_PTR pAppPrivate,
OMX_IN void* eglImage);
OMX_ERRORTYPE (*ComponentRoleEnum)(
OMX_IN OMX_HANDLETYPE hComponent,
OMX_OUT OMX_U8 *cRole,
OMX_IN OMX_U32 nIndex);
} OMX_COMPONENTTYPE;
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
/* File EOF */
@@ -0,0 +1,212 @@
/* ------------------------------------------------------------------
* Copyright (C) 1998-2009 PacketVideo
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied.
* See the License for the specific language governing permissions
* and limitations under the License.
* -------------------------------------------------------------------
*/
/*
* Copyright (c) 2008 The Khronos Group Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject
* to the following conditions:
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
/** OMX_ContentPipe.h - OpenMax IL version 1.1.2
* The OMX_ContentPipe header file contains the definitions used to define
* the public interface for content piples. This header file is intended to
* be used by the component.
*/
#ifndef OMX_CONTENTPIPE_H
#define OMX_CONTENTPIPE_H
#ifndef KD_EACCES
/* OpenKODE error codes. CPResult values may be zero (indicating success
or one of the following values) */
#define KD_EACCES (1)
#define KD_EADDRINUSE (2)
#define KD_EAGAIN (5)
#define KD_EBADF (7)
#define KD_EBUSY (8)
#define KD_ECONNREFUSED (9)
#define KD_ECONNRESET (10)
#define KD_EDEADLK (11)
#define KD_EDESTADDRREQ (12)
#define KD_ERANGE (35)
#define KD_EEXIST (13)
#define KD_EFBIG (14)
#define KD_EHOSTUNREACH (15)
#define KD_EINVAL (17)
#define KD_EIO (18)
#define KD_EISCONN (20)
#define KD_EISDIR (21)
#define KD_EMFILE (22)
#define KD_ENAMETOOLONG (23)
#define KD_ENOENT (24)
#define KD_ENOMEM (25)
#define KD_ENOSPC (26)
#define KD_ENOSYS (27)
#define KD_ENOTCONN (28)
#define KD_EPERM (33)
#define KD_ETIMEDOUT (36)
#define KD_EILSEQ (19)
#endif
/** Map types from OMX standard types only here so interface is as generic as possible. */
typedef OMX_U32 CPresult;
typedef char * CPstring;
typedef void * CPhandle;
typedef OMX_U32 CPuint;
typedef OMX_S32 CPint;
typedef char CPbyte;
typedef OMX_BOOL CPbool;
/** enumeration of origin types used in the CP_PIPETYPE's Seek function
* @ingroup cp
*/
typedef enum CP_ORIGINTYPE {
CP_OriginBegin,
CP_OriginCur,
CP_OriginEnd,
CP_OriginKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */
CP_OriginVendorStartUnused = 0x7F000000, /**< Reserved region for introducing Vendor Extensions */
CP_OriginMax = 0X7FFFFFFF
} CP_ORIGINTYPE;
/** enumeration of contact access types used in the CP_PIPETYPE's Open function
* @ingroup cp
*/
typedef enum CP_ACCESSTYPE {
CP_AccessRead,
CP_AccessWrite,
CP_AccessReadWrite,
CP_AccessKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */
CP_AccessVendorStartUnused = 0x7F000000, /**< Reserved region for introducing Vendor Extensions */
CP_AccessMax = 0X7FFFFFFF
} CP_ACCESSTYPE;
/** enumeration of results returned by the CP_PIPETYPE's CheckAvailableBytes function
* @ingroup cp
*/
typedef enum CP_CHECKBYTESRESULTTYPE
{
CP_CheckBytesOk, /**< There are at least the request number
of bytes available */
CP_CheckBytesNotReady, /**< The pipe is still retrieving bytes
and presently lacks sufficient bytes.
Client will be called when they are
sufficient bytes are available. */
CP_CheckBytesInsufficientBytes, /**< The pipe has retrieved all bytes
but those available are less than those
requested */
CP_CheckBytesAtEndOfStream, /**< The pipe has reached the end of stream
and no more bytes are available. */
CP_CheckBytesOutOfBuffers, /**< All read/write buffers are currently in use. */
CP_CheckBytesKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */
CP_CheckBytesVendorStartUnused = 0x7F000000, /**< Reserved region for introducing Vendor Extensions */
CP_CheckBytesMax = 0X7FFFFFFF
} CP_CHECKBYTESRESULTTYPE;
/** enumeration of content pipe events sent to the client callback.
* @ingroup cp
*/
typedef enum CP_EVENTTYPE{
CP_BytesAvailable, /** bytes requested in a CheckAvailableBytes call are now available*/
CP_Overflow, /** enumeration of content pipe events sent to the client callback*/
CP_PipeDisconnected, /** enumeration of content pipe events sent to the client callback*/
CP_EventKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */
CP_EventVendorStartUnused = 0x7F000000, /**< Reserved region for introducing Vendor Extensions */
CP_EventMax = 0X7FFFFFFF
} CP_EVENTTYPE;
/** content pipe definition
* @ingroup cp
*/
typedef struct CP_PIPETYPE
{
/** Open a content stream for reading or writing. */
CPresult (*Open)( CPhandle* hContent, CPstring szURI, CP_ACCESSTYPE eAccess );
/** Close a content stream. */
CPresult (*Close)( CPhandle hContent );
/** Create a content source and open it for writing. */
CPresult (*Create)( CPhandle *hContent, CPstring szURI );
/** Check the that specified number of bytes are available for reading or writing (depending on access type).*/
CPresult (*CheckAvailableBytes)( CPhandle hContent, CPuint nBytesRequested, CP_CHECKBYTESRESULTTYPE *eResult );
/** Seek to certain position in the content relative to the specified origin. */
CPresult (*SetPosition)( CPhandle hContent, CPint nOffset, CP_ORIGINTYPE eOrigin);
/** Retrieve the current position relative to the start of the content. */
CPresult (*GetPosition)( CPhandle hContent, CPuint *pPosition);
/** Retrieve data of the specified size from the content stream (advance content pointer by size of data).
Note: pipe client provides pointer. This function is appropriate for small high frequency reads. */
CPresult (*Read)( CPhandle hContent, CPbyte *pData, CPuint nSize);
/** Retrieve a buffer allocated by the pipe that contains the requested number of bytes.
Buffer contains the next block of bytes, as specified by nSize, of the content. nSize also
returns the size of the block actually read. Content pointer advances the by the returned size.
Note: pipe provides pointer. This function is appropriate for large reads. The client must call
ReleaseReadBuffer when done with buffer.
In some cases the requested block may not reside in contiguous memory within the
pipe implementation. For instance if the pipe leverages a circular buffer then the requested
block may straddle the boundary of the circular buffer. By default a pipe implementation
performs a copy in this case to provide the block to the pipe client in one contiguous buffer.
If, however, the client sets bForbidCopy, then the pipe returns only those bytes preceding the memory
boundary. Here the client may retrieve the data in segments over successive calls. */
CPresult (*ReadBuffer)( CPhandle hContent, CPbyte **ppBuffer, CPuint *nSize, CPbool bForbidCopy);
/** Release a buffer obtained by ReadBuffer back to the pipe. */
CPresult (*ReleaseReadBuffer)(CPhandle hContent, CPbyte *pBuffer);
/** Write data of the specified size to the content (advance content pointer by size of data).
Note: pipe client provides pointer. This function is appropriate for small high frequency writes. */
CPresult (*Write)( CPhandle hContent, CPbyte *data, CPuint nSize);
/** Retrieve a buffer allocated by the pipe used to write data to the content.
Client will fill buffer with output data. Note: pipe provides pointer. This function is appropriate
for large writes. The client must call WriteBuffer when done it has filled the buffer with data.*/
CPresult (*GetWriteBuffer)( CPhandle hContent, CPbyte **ppBuffer, CPuint nSize);
/** Deliver a buffer obtained via GetWriteBuffer to the pipe. Pipe will write the
the contents of the buffer to content and advance content pointer by the size of the buffer */
CPresult (*WriteBuffer)( CPhandle hContent, CPbyte *pBuffer, CPuint nFilledSize);
/** Register a per-handle client callback with the content pipe. */
CPresult (*RegisterCallback)( CPhandle hContent, CPresult (*ClientCallback)(CP_EVENTTYPE eEvent, CPuint iParam));
} CP_PIPETYPE;
#endif
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,966 @@
/* ------------------------------------------------------------------
* Copyright (C) 1998-2009 PacketVideo
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied.
* See the License for the specific language governing permissions
* and limitations under the License.
* -------------------------------------------------------------------
*/
/**
* Copyright (c) 2008 The Khronos Group Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject
* to the following conditions:
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
/**
* @file OMX_IVCommon.h - OpenMax IL version 1.1.2
* The structures needed by Video and Image components to exchange
* parameters and configuration data with the components.
*/
#ifndef OMX_IVCommon_h
#define OMX_IVCommon_h
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/**
* Each OMX header must include all required header files to allow the header
* to compile without errors. The includes below are required for this header
* file to compile successfully
*/
#include <OMX_Core.h>
/** @defgroup iv OpenMAX IL Imaging and Video Domain
* Common structures for OpenMAX IL Imaging and Video domains
* @{
*/
/**
* Enumeration defining possible uncompressed image/video formats.
*
* ENUMS:
* Unused : Placeholder value when format is N/A
* Monochrome : black and white
* 8bitRGB332 : Red 7:5, Green 4:2, Blue 1:0
* 12bitRGB444 : Red 11:8, Green 7:4, Blue 3:0
* 16bitARGB4444 : Alpha 15:12, Red 11:8, Green 7:4, Blue 3:0
* 16bitARGB1555 : Alpha 15, Red 14:10, Green 9:5, Blue 4:0
* 16bitRGB565 : Red 15:11, Green 10:5, Blue 4:0
* 16bitBGR565 : Blue 15:11, Green 10:5, Red 4:0
* 18bitRGB666 : Red 17:12, Green 11:6, Blue 5:0
* 18bitARGB1665 : Alpha 17, Red 16:11, Green 10:5, Blue 4:0
* 19bitARGB1666 : Alpha 18, Red 17:12, Green 11:6, Blue 5:0
* 24bitRGB888 : Red 24:16, Green 15:8, Blue 7:0
* 24bitBGR888 : Blue 24:16, Green 15:8, Red 7:0
* 24bitARGB1887 : Alpha 23, Red 22:15, Green 14:7, Blue 6:0
* 25bitARGB1888 : Alpha 24, Red 23:16, Green 15:8, Blue 7:0
* 32bitBGRA8888 : Blue 31:24, Green 23:16, Red 15:8, Alpha 7:0
* 32bitARGB8888 : Alpha 31:24, Red 23:16, Green 15:8, Blue 7:0
* YUV411Planar : U,Y are subsampled by a factor of 4 horizontally
* YUV411PackedPlanar : packed per payload in planar slices
* YUV420Planar : Three arrays Y,U,V.
* YUV420PackedPlanar : packed per payload in planar slices
* YUV420SemiPlanar : Two arrays, one is all Y, the other is U and V
* YUV422Planar : Three arrays Y,U,V.
* YUV422PackedPlanar : packed per payload in planar slices
* YUV422SemiPlanar : Two arrays, one is all Y, the other is U and V
* YCbYCr : Organized as 16bit YUYV (i.e. YCbYCr)
* YCrYCb : Organized as 16bit YVYU (i.e. YCrYCb)
* CbYCrY : Organized as 16bit UYVY (i.e. CbYCrY)
* CrYCbY : Organized as 16bit VYUY (i.e. CrYCbY)
* YUV444Interleaved : Each pixel contains equal parts YUV
* RawBayer8bit : SMIA camera output format
* RawBayer10bit : SMIA camera output format
* RawBayer8bitcompressed : SMIA camera output format
*/
typedef enum OMX_COLOR_FORMATTYPE {
OMX_COLOR_FormatUnused,
OMX_COLOR_FormatMonochrome,
OMX_COLOR_Format8bitRGB332,
OMX_COLOR_Format12bitRGB444,
OMX_COLOR_Format16bitARGB4444,
OMX_COLOR_Format16bitARGB1555,
OMX_COLOR_Format16bitRGB565,
OMX_COLOR_Format16bitBGR565,
OMX_COLOR_Format18bitRGB666,
OMX_COLOR_Format18bitARGB1665,
OMX_COLOR_Format19bitARGB1666,
OMX_COLOR_Format24bitRGB888,
OMX_COLOR_Format24bitBGR888,
OMX_COLOR_Format24bitARGB1887,
OMX_COLOR_Format25bitARGB1888,
OMX_COLOR_Format32bitBGRA8888,
OMX_COLOR_Format32bitARGB8888,
OMX_COLOR_FormatYUV411Planar,
OMX_COLOR_FormatYUV411PackedPlanar,
OMX_COLOR_FormatYUV420Planar,
OMX_COLOR_FormatYUV420PackedPlanar,
OMX_COLOR_FormatYUV420SemiPlanar,
OMX_COLOR_FormatYUV422Planar,
OMX_COLOR_FormatYUV422PackedPlanar,
OMX_COLOR_FormatYUV422SemiPlanar,
OMX_COLOR_FormatYCbYCr,
OMX_COLOR_FormatYCrYCb,
OMX_COLOR_FormatCbYCrY,
OMX_COLOR_FormatCrYCbY,
OMX_COLOR_FormatYUV444Interleaved,
OMX_COLOR_FormatRawBayer8bit,
OMX_COLOR_FormatRawBayer10bit,
OMX_COLOR_FormatRawBayer8bitcompressed,
OMX_COLOR_FormatL2,
OMX_COLOR_FormatL4,
OMX_COLOR_FormatL8,
OMX_COLOR_FormatL16,
OMX_COLOR_FormatL24,
OMX_COLOR_FormatL32,
OMX_COLOR_FormatYUV420PackedSemiPlanar,
OMX_COLOR_FormatYUV422PackedSemiPlanar,
OMX_COLOR_Format18BitBGR666,
OMX_COLOR_Format24BitARGB6666,
OMX_COLOR_Format24BitABGR6666,
OMX_COLOR_FormatKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */
OMX_COLOR_FormatVendorStartUnused = 0x7F000000, /**< Reserved region for introducing Vendor Extensions */
/**<Reserved android opaque colorformat. Tells the encoder that
* the actual colorformat will be relayed by the
* Gralloc Buffers.
* FIXME: In the process of reserving some enum values for
* Android-specific OMX IL colorformats. Change this enum to
* an acceptable range once that is done.
* */
OMX_COLOR_FormatAndroidOpaque = 0x7F000789,
OMX_COLOR_Format32BitRGBA8888 = 0x7F00A000,
/** Flexible 8-bit YUV format. Codec should report this format
* as being supported if it supports any YUV420 packed planar
* or semiplanar formats. When port is set to use this format,
* codec can substitute any YUV420 packed planar or semiplanar
* format for it. */
OMX_COLOR_FormatYUV420Flexible = 0x7F420888,
// 10-bit or 12-bit YUV format, LSB-justified (0's on higher bits)
OMX_COLOR_FormatYUV420Planar16 = 0x7F42016B,
// Packed 10-bit YUV444 representation that includes 2 bits of alpha. Each pixel is
// 32-bit. Bits 0-9 contain the U sample, bits 10-19 contain the Y sample,
// bits 20-29 contain the V sample, and bits 30-31 contain the alpha value.
OMX_COLOR_FormatYUV444Y410 = 0x7F444AAA,
OMX_TI_COLOR_FormatYUV420PackedSemiPlanar = 0x7F000100,
OMX_QCOM_COLOR_FormatYVU420SemiPlanar = 0x7FA30C00,
OMX_QCOM_COLOR_FormatYUV420PackedSemiPlanar64x32Tile2m8ka = 0x7FA30C03,
OMX_SEC_COLOR_FormatNV12Tiled = 0x7FC00002,
OMX_QCOM_COLOR_FormatYUV420PackedSemiPlanar32m = 0x7FA30C04,
OMX_COLOR_FormatMax = 0x7FFFFFFF
} OMX_COLOR_FORMATTYPE;
/**
* Defines the matrix for conversion from RGB to YUV or vice versa.
* iColorMatrix should be initialized with the fixed point values
* used in converting between formats.
*/
typedef struct OMX_CONFIG_COLORCONVERSIONTYPE {
OMX_U32 nSize; /**< Size of the structure in bytes */
OMX_VERSIONTYPE nVersion; /**< OMX specification version info */
OMX_U32 nPortIndex; /**< Port that this struct applies to */
OMX_S32 xColorMatrix[3][3]; /**< Stored in signed Q16 format */
OMX_S32 xColorOffset[4]; /**< Stored in signed Q16 format */
}OMX_CONFIG_COLORCONVERSIONTYPE;
/**
* Structure defining percent to scale each frame dimension. For example:
* To make the width 50% larger, use fWidth = 1.5 and to make the width
* 1/2 the original size, use fWidth = 0.5
*/
typedef struct OMX_CONFIG_SCALEFACTORTYPE {
OMX_U32 nSize; /**< Size of the structure in bytes */
OMX_VERSIONTYPE nVersion; /**< OMX specification version info */
OMX_U32 nPortIndex; /**< Port that this struct applies to */
OMX_S32 xWidth; /**< Fixed point value stored as Q16 */
OMX_S32 xHeight; /**< Fixed point value stored as Q16 */
}OMX_CONFIG_SCALEFACTORTYPE;
/**
* Enumeration of possible image filter types
*/
typedef enum OMX_IMAGEFILTERTYPE {
OMX_ImageFilterNone,
OMX_ImageFilterNoise,
OMX_ImageFilterEmboss,
OMX_ImageFilterNegative,
OMX_ImageFilterSketch,
OMX_ImageFilterOilPaint,
OMX_ImageFilterHatch,
OMX_ImageFilterGpen,
OMX_ImageFilterAntialias,
OMX_ImageFilterDeRing,
OMX_ImageFilterSolarize,
OMX_ImageFilterKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */
OMX_ImageFilterVendorStartUnused = 0x7F000000, /**< Reserved region for introducing Vendor Extensions */
OMX_ImageFilterMax = 0x7FFFFFFF
} OMX_IMAGEFILTERTYPE;
/**
* Image filter configuration
*
* STRUCT MEMBERS:
* nSize : Size of the structure in bytes
* nVersion : OMX specification version information
* nPortIndex : Port that this structure applies to
* eImageFilter : Image filter type enumeration
*/
typedef struct OMX_CONFIG_IMAGEFILTERTYPE {
OMX_U32 nSize;
OMX_VERSIONTYPE nVersion;
OMX_U32 nPortIndex;
OMX_IMAGEFILTERTYPE eImageFilter;
} OMX_CONFIG_IMAGEFILTERTYPE;
/**
* Customized U and V for color enhancement
*
* STRUCT MEMBERS:
* nSize : Size of the structure in bytes
* nVersion : OMX specification version information
* nPortIndex : Port that this structure applies to
* bColorEnhancement : Enable/disable color enhancement
* nCustomizedU : Practical values: 16-240, range: 0-255, value set for
* U component
* nCustomizedV : Practical values: 16-240, range: 0-255, value set for
* V component
*/
typedef struct OMX_CONFIG_COLORENHANCEMENTTYPE {
OMX_U32 nSize;
OMX_VERSIONTYPE nVersion;
OMX_U32 nPortIndex;
OMX_BOOL bColorEnhancement;
OMX_U8 nCustomizedU;
OMX_U8 nCustomizedV;
} OMX_CONFIG_COLORENHANCEMENTTYPE;
/**
* Define color key and color key mask
*
* STRUCT MEMBERS:
* nSize : Size of the structure in bytes
* nVersion : OMX specification version information
* nPortIndex : Port that this structure applies to
* nARGBColor : 32bit Alpha, Red, Green, Blue Color
* nARGBMask : 32bit Mask for Alpha, Red, Green, Blue channels
*/
typedef struct OMX_CONFIG_COLORKEYTYPE {
OMX_U32 nSize;
OMX_VERSIONTYPE nVersion;
OMX_U32 nPortIndex;
OMX_U32 nARGBColor;
OMX_U32 nARGBMask;
} OMX_CONFIG_COLORKEYTYPE;
/**
* List of color blend types for pre/post processing
*
* ENUMS:
* None : No color blending present
* AlphaConstant : Function is (alpha_constant * src) +
* (1 - alpha_constant) * dst)
* AlphaPerPixel : Function is (alpha * src) + (1 - alpha) * dst)
* Alternate : Function is alternating pixels from src and dst
* And : Function is (src & dst)
* Or : Function is (src | dst)
* Invert : Function is ~src
*/
typedef enum OMX_COLORBLENDTYPE {
OMX_ColorBlendNone,
OMX_ColorBlendAlphaConstant,
OMX_ColorBlendAlphaPerPixel,
OMX_ColorBlendAlternate,
OMX_ColorBlendAnd,
OMX_ColorBlendOr,
OMX_ColorBlendInvert,
OMX_ColorBlendKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */
OMX_ColorBlendVendorStartUnused = 0x7F000000, /**< Reserved region for introducing Vendor Extensions */
OMX_ColorBlendMax = 0x7FFFFFFF
} OMX_COLORBLENDTYPE;
/**
* Color blend configuration
*
* STRUCT MEMBERS:
* nSize : Size of the structure in bytes
* nVersion : OMX specification version information
* nPortIndex : Port that this structure applies to
* nRGBAlphaConstant : Constant global alpha values when global alpha is used
* eColorBlend : Color blend type enumeration
*/
typedef struct OMX_CONFIG_COLORBLENDTYPE {
OMX_U32 nSize;
OMX_VERSIONTYPE nVersion;
OMX_U32 nPortIndex;
OMX_U32 nRGBAlphaConstant;
OMX_COLORBLENDTYPE eColorBlend;
} OMX_CONFIG_COLORBLENDTYPE;
/**
* Hold frame dimension
*
* STRUCT MEMBERS:
* nSize : Size of the structure in bytes
* nVersion : OMX specification version information
* nPortIndex : Port that this structure applies to
* nWidth : Frame width in pixels
* nHeight : Frame height in pixels
*/
typedef struct OMX_FRAMESIZETYPE {
OMX_U32 nSize;
OMX_VERSIONTYPE nVersion;
OMX_U32 nPortIndex;
OMX_U32 nWidth;
OMX_U32 nHeight;
} OMX_FRAMESIZETYPE;
/**
* Rotation configuration
*
* STRUCT MEMBERS:
* nSize : Size of the structure in bytes
* nVersion : OMX specification version information
* nPortIndex : Port that this structure applies to
* nRotation : +/- integer rotation value
*/
typedef struct OMX_CONFIG_ROTATIONTYPE {
OMX_U32 nSize;
OMX_VERSIONTYPE nVersion;
OMX_U32 nPortIndex;
OMX_S32 nRotation;
} OMX_CONFIG_ROTATIONTYPE;
/**
* Possible mirroring directions for pre/post processing
*
* ENUMS:
* None : No mirroring
* Vertical : Vertical mirroring, flip on X axis
* Horizontal : Horizontal mirroring, flip on Y axis
* Both : Both vertical and horizontal mirroring
*/
typedef enum OMX_MIRRORTYPE {
OMX_MirrorNone = 0,
OMX_MirrorVertical,
OMX_MirrorHorizontal,
OMX_MirrorBoth,
OMX_MirrorKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */
OMX_MirrorVendorStartUnused = 0x7F000000, /**< Reserved region for introducing Vendor Extensions */
OMX_MirrorMax = 0x7FFFFFFF
} OMX_MIRRORTYPE;
/**
* Mirroring configuration
*
* STRUCT MEMBERS:
* nSize : Size of the structure in bytes
* nVersion : OMX specification version information
* nPortIndex : Port that this structure applies to
* eMirror : Mirror type enumeration
*/
typedef struct OMX_CONFIG_MIRRORTYPE {
OMX_U32 nSize;
OMX_VERSIONTYPE nVersion;
OMX_U32 nPortIndex;
OMX_MIRRORTYPE eMirror;
} OMX_CONFIG_MIRRORTYPE;
/**
* Position information only
*
* STRUCT MEMBERS:
* nSize : Size of the structure in bytes
* nVersion : OMX specification version information
* nPortIndex : Port that this structure applies to
* nX : X coordinate for the point
* nY : Y coordinate for the point
*/
typedef struct OMX_CONFIG_POINTTYPE {
OMX_U32 nSize;
OMX_VERSIONTYPE nVersion;
OMX_U32 nPortIndex;
OMX_S32 nX;
OMX_S32 nY;
} OMX_CONFIG_POINTTYPE;
/**
* Frame size plus position
*
* STRUCT MEMBERS:
* nSize : Size of the structure in bytes
* nVersion : OMX specification version information
* nPortIndex : Port that this structure applies to
* nLeft : X Coordinate of the top left corner of the rectangle
* nTop : Y Coordinate of the top left corner of the rectangle
* nWidth : Width of the rectangle
* nHeight : Height of the rectangle
*/
typedef struct OMX_CONFIG_RECTTYPE {
OMX_U32 nSize;
OMX_VERSIONTYPE nVersion;
OMX_U32 nPortIndex;
OMX_S32 nLeft;
OMX_S32 nTop;
OMX_U32 nWidth;
OMX_U32 nHeight;
} OMX_CONFIG_RECTTYPE;
/**
* Deblocking state; it is required to be set up before starting the codec
*
* STRUCT MEMBERS:
* nSize : Size of the structure in bytes
* nVersion : OMX specification version information
* nPortIndex : Port that this structure applies to
* bDeblocking : Enable/disable deblocking mode
*/
typedef struct OMX_PARAM_DEBLOCKINGTYPE {
OMX_U32 nSize;
OMX_VERSIONTYPE nVersion;
OMX_U32 nPortIndex;
OMX_BOOL bDeblocking;
} OMX_PARAM_DEBLOCKINGTYPE;
/**
* Stabilization state
*
* STRUCT MEMBERS:
* nSize : Size of the structure in bytes
* nVersion : OMX specification version information
* nPortIndex : Port that this structure applies to
* bStab : Enable/disable frame stabilization state
*/
typedef struct OMX_CONFIG_FRAMESTABTYPE {
OMX_U32 nSize;
OMX_VERSIONTYPE nVersion;
OMX_U32 nPortIndex;
OMX_BOOL bStab;
} OMX_CONFIG_FRAMESTABTYPE;
/**
* White Balance control type
*
* STRUCT MEMBERS:
* SunLight : Referenced in JSR-234
* Flash : Optimal for device's integrated flash
*/
typedef enum OMX_WHITEBALCONTROLTYPE {
OMX_WhiteBalControlOff = 0,
OMX_WhiteBalControlAuto,
OMX_WhiteBalControlSunLight,
OMX_WhiteBalControlCloudy,
OMX_WhiteBalControlShade,
OMX_WhiteBalControlTungsten,
OMX_WhiteBalControlFluorescent,
OMX_WhiteBalControlIncandescent,
OMX_WhiteBalControlFlash,
OMX_WhiteBalControlHorizon,
OMX_WhiteBalControlKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */
OMX_WhiteBalControlVendorStartUnused = 0x7F000000, /**< Reserved region for introducing Vendor Extensions */
OMX_WhiteBalControlMax = 0x7FFFFFFF
} OMX_WHITEBALCONTROLTYPE;
/**
* White Balance control configuration
*
* STRUCT MEMBERS:
* nSize : Size of the structure in bytes
* nVersion : OMX specification version information
* nPortIndex : Port that this structure applies to
* eWhiteBalControl : White balance enumeration
*/
typedef struct OMX_CONFIG_WHITEBALCONTROLTYPE {
OMX_U32 nSize;
OMX_VERSIONTYPE nVersion;
OMX_U32 nPortIndex;
OMX_WHITEBALCONTROLTYPE eWhiteBalControl;
} OMX_CONFIG_WHITEBALCONTROLTYPE;
/**
* Exposure control type
*/
typedef enum OMX_EXPOSURECONTROLTYPE {
OMX_ExposureControlOff = 0,
OMX_ExposureControlAuto,
OMX_ExposureControlNight,
OMX_ExposureControlBackLight,
OMX_ExposureControlSpotLight,
OMX_ExposureControlSports,
OMX_ExposureControlSnow,
OMX_ExposureControlBeach,
OMX_ExposureControlLargeAperture,
OMX_ExposureControlSmallApperture,
OMX_ExposureControlKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */
OMX_ExposureControlVendorStartUnused = 0x7F000000, /**< Reserved region for introducing Vendor Extensions */
OMX_ExposureControlMax = 0x7FFFFFFF
} OMX_EXPOSURECONTROLTYPE;
/**
* White Balance control configuration
*
* STRUCT MEMBERS:
* nSize : Size of the structure in bytes
* nVersion : OMX specification version information
* nPortIndex : Port that this structure applies to
* eExposureControl : Exposure control enumeration
*/
typedef struct OMX_CONFIG_EXPOSURECONTROLTYPE {
OMX_U32 nSize;
OMX_VERSIONTYPE nVersion;
OMX_U32 nPortIndex;
OMX_EXPOSURECONTROLTYPE eExposureControl;
} OMX_CONFIG_EXPOSURECONTROLTYPE;
/**
* Defines sensor supported mode.
*
* STRUCT MEMBERS:
* nSize : Size of the structure in bytes
* nVersion : OMX specification version information
* nPortIndex : Port that this structure applies to
* nFrameRate : Single shot mode is indicated by a 0
* bOneShot : Enable for single shot, disable for streaming
* sFrameSize : Framesize
*/
typedef struct OMX_PARAM_SENSORMODETYPE {
OMX_U32 nSize;
OMX_VERSIONTYPE nVersion;
OMX_U32 nPortIndex;
OMX_U32 nFrameRate;
OMX_BOOL bOneShot;
OMX_FRAMESIZETYPE sFrameSize;
} OMX_PARAM_SENSORMODETYPE;
/**
* Defines contrast level
*
* STRUCT MEMBERS:
* nSize : Size of the structure in bytes
* nVersion : OMX specification version information
* nPortIndex : Port that this structure applies to
* nContrast : Values allowed for contrast -100 to 100, zero means no change
*/
typedef struct OMX_CONFIG_CONTRASTTYPE {
OMX_U32 nSize;
OMX_VERSIONTYPE nVersion;
OMX_U32 nPortIndex;
OMX_S32 nContrast;
} OMX_CONFIG_CONTRASTTYPE;
/**
* Defines brightness level
*
* STRUCT MEMBERS:
* nSize : Size of the structure in bytes
* nVersion : OMX specification version information
* nPortIndex : Port that this structure applies to
* nBrightness : 0-100%
*/
typedef struct OMX_CONFIG_BRIGHTNESSTYPE {
OMX_U32 nSize;
OMX_VERSIONTYPE nVersion;
OMX_U32 nPortIndex;
OMX_U32 nBrightness;
} OMX_CONFIG_BRIGHTNESSTYPE;
/**
* Defines backlight level configuration for a video sink, e.g. LCD panel
*
* STRUCT MEMBERS:
* nSize : Size of the structure in bytes
* nVersion : OMX specification version information
* nPortIndex : Port that this structure applies to
* nBacklight : Values allowed for backlight 0-100%
* nTimeout : Number of milliseconds before backlight automatically turns
* off. A value of 0x0 disables backight timeout
*/
typedef struct OMX_CONFIG_BACKLIGHTTYPE {
OMX_U32 nSize;
OMX_VERSIONTYPE nVersion;
OMX_U32 nPortIndex;
OMX_U32 nBacklight;
OMX_U32 nTimeout;
} OMX_CONFIG_BACKLIGHTTYPE;
/**
* Defines setting for Gamma
*
* STRUCT MEMBERS:
* nSize : Size of the structure in bytes
* nVersion : OMX specification version information
* nPortIndex : Port that this structure applies to
* nGamma : Values allowed for gamma -100 to 100, zero means no change
*/
typedef struct OMX_CONFIG_GAMMATYPE {
OMX_U32 nSize;
OMX_VERSIONTYPE nVersion;
OMX_U32 nPortIndex;
OMX_S32 nGamma;
} OMX_CONFIG_GAMMATYPE;
/**
* Define for setting saturation
*
* STRUCT MEMBERS:
* nSize : Size of the structure in bytes
* nVersion : OMX specification version information
* nPortIndex : Port that this structure applies to
* nSaturation : Values allowed for saturation -100 to 100, zero means
* no change
*/
typedef struct OMX_CONFIG_SATURATIONTYPE {
OMX_U32 nSize;
OMX_VERSIONTYPE nVersion;
OMX_U32 nPortIndex;
OMX_S32 nSaturation;
} OMX_CONFIG_SATURATIONTYPE;
/**
* Define for setting Lightness
*
* STRUCT MEMBERS:
* nSize : Size of the structure in bytes
* nVersion : OMX specification version information
* nPortIndex : Port that this structure applies to
* nLightness : Values allowed for lightness -100 to 100, zero means no
* change
*/
typedef struct OMX_CONFIG_LIGHTNESSTYPE {
OMX_U32 nSize;
OMX_VERSIONTYPE nVersion;
OMX_U32 nPortIndex;
OMX_S32 nLightness;
} OMX_CONFIG_LIGHTNESSTYPE;
/**
* Plane blend configuration
*
* STRUCT MEMBERS:
* nSize : Size of the structure in bytes
* nVersion : OMX specification version information
* nPortIndex : Index of input port associated with the plane.
* nDepth : Depth of the plane in relation to the screen. Higher
* numbered depths are "behind" lower number depths.
* This number defaults to the Port Index number.
* nAlpha : Transparency blending component for the entire plane.
* See blending modes for more detail.
*/
typedef struct OMX_CONFIG_PLANEBLENDTYPE {
OMX_U32 nSize;
OMX_VERSIONTYPE nVersion;
OMX_U32 nPortIndex;
OMX_U32 nDepth;
OMX_U32 nAlpha;
} OMX_CONFIG_PLANEBLENDTYPE;
/**
* Define interlace type
*
* STRUCT MEMBERS:
* nSize : Size of the structure in bytes
* nVersion : OMX specification version information
* nPortIndex : Port that this structure applies to
* bEnable : Enable control variable for this functionality
* (see below)
* nInterleavePortIndex : Index of input or output port associated with
* the interleaved plane.
* pPlanarPortIndexes[4] : Index of input or output planar ports.
*/
typedef struct OMX_PARAM_INTERLEAVETYPE {
OMX_U32 nSize;
OMX_VERSIONTYPE nVersion;
OMX_U32 nPortIndex;
OMX_BOOL bEnable;
OMX_U32 nInterleavePortIndex;
} OMX_PARAM_INTERLEAVETYPE;
/**
* Defines the picture effect used for an input picture
*/
typedef enum OMX_TRANSITIONEFFECTTYPE {
OMX_EffectNone,
OMX_EffectFadeFromBlack,
OMX_EffectFadeToBlack,
OMX_EffectUnspecifiedThroughConstantColor,
OMX_EffectDissolve,
OMX_EffectWipe,
OMX_EffectUnspecifiedMixOfTwoScenes,
OMX_EffectKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */
OMX_EffectVendorStartUnused = 0x7F000000, /**< Reserved region for introducing Vendor Extensions */
OMX_EffectMax = 0x7FFFFFFF
} OMX_TRANSITIONEFFECTTYPE;
/**
* Structure used to configure current transition effect
*
* STRUCT MEMBERS:
* nSize : Size of the structure in bytes
* nVersion : OMX specification version information
* nPortIndex : Port that this structure applies to
* eEffect : Effect to enable
*/
typedef struct OMX_CONFIG_TRANSITIONEFFECTTYPE {
OMX_U32 nSize;
OMX_VERSIONTYPE nVersion;
OMX_U32 nPortIndex;
OMX_TRANSITIONEFFECTTYPE eEffect;
} OMX_CONFIG_TRANSITIONEFFECTTYPE;
/**
* Defines possible data unit types for encoded video data. The data unit
* types are used both for encoded video input for playback as well as
* encoded video output from recording.
*/
typedef enum OMX_DATAUNITTYPE {
OMX_DataUnitCodedPicture,
OMX_DataUnitVideoSegment,
OMX_DataUnitSeveralSegments,
OMX_DataUnitArbitraryStreamSection,
OMX_DataUnitKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */
OMX_DataUnitVendorStartUnused = 0x7F000000, /**< Reserved region for introducing Vendor Extensions */
OMX_DataUnitMax = 0x7FFFFFFF
} OMX_DATAUNITTYPE;
/**
* Defines possible encapsulation types for coded video data unit. The
* encapsulation information is used both for encoded video input for
* playback as well as encoded video output from recording.
*/
typedef enum OMX_DATAUNITENCAPSULATIONTYPE {
OMX_DataEncapsulationElementaryStream,
OMX_DataEncapsulationGenericPayload,
OMX_DataEncapsulationRtpPayload,
OMX_DataEncapsulationKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */
OMX_DataEncapsulationVendorStartUnused = 0x7F000000, /**< Reserved region for introducing Vendor Extensions */
OMX_DataEncapsulationMax = 0x7FFFFFFF
} OMX_DATAUNITENCAPSULATIONTYPE;
/**
* Structure used to configure the type of being decoded/encoded
*/
typedef struct OMX_PARAM_DATAUNITTYPE {
OMX_U32 nSize; /**< Size of the structure in bytes */
OMX_VERSIONTYPE nVersion; /**< OMX specification version information */
OMX_U32 nPortIndex; /**< Port that this structure applies to */
OMX_DATAUNITTYPE eUnitType;
OMX_DATAUNITENCAPSULATIONTYPE eEncapsulationType;
} OMX_PARAM_DATAUNITTYPE;
/**
* Defines dither types
*/
typedef enum OMX_DITHERTYPE {
OMX_DitherNone,
OMX_DitherOrdered,
OMX_DitherErrorDiffusion,
OMX_DitherOther,
OMX_DitherKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */
OMX_DitherVendorStartUnused = 0x7F000000, /**< Reserved region for introducing Vendor Extensions */
OMX_DitherMax = 0x7FFFFFFF
} OMX_DITHERTYPE;
/**
* Structure used to configure current type of dithering
*/
typedef struct OMX_CONFIG_DITHERTYPE {
OMX_U32 nSize; /**< Size of the structure in bytes */
OMX_VERSIONTYPE nVersion; /**< OMX specification version information */
OMX_U32 nPortIndex; /**< Port that this structure applies to */
OMX_DITHERTYPE eDither; /**< Type of dithering to use */
} OMX_CONFIG_DITHERTYPE;
typedef struct OMX_CONFIG_CAPTUREMODETYPE {
OMX_U32 nSize;
OMX_VERSIONTYPE nVersion;
OMX_U32 nPortIndex; /**< Port that this structure applies to */
OMX_BOOL bContinuous; /**< If true then ignore frame rate and emit capture
* data as fast as possible (otherwise obey port's frame rate). */
OMX_BOOL bFrameLimited; /**< If true then terminate capture after the port emits the
* specified number of frames (otherwise the port does not
* terminate the capture until instructed to do so by the client).
* Even if set, the client may manually terminate the capture prior
* to reaching the limit. */
OMX_U32 nFrameLimit; /**< Limit on number of frames emitted during a capture (only
* valid if bFrameLimited is set). */
} OMX_CONFIG_CAPTUREMODETYPE;
typedef enum OMX_METERINGTYPE {
OMX_MeteringModeAverage, /**< Center-weighted average metering. */
OMX_MeteringModeSpot, /**< Spot (partial) metering. */
OMX_MeteringModeMatrix, /**< Matrix or evaluative metering. */
OMX_MeteringKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */
OMX_MeteringVendorStartUnused = 0x7F000000, /**< Reserved region for introducing Vendor Extensions */
OMX_EVModeMax = 0x7fffffff
} OMX_METERINGTYPE;
typedef struct OMX_CONFIG_EXPOSUREVALUETYPE {
OMX_U32 nSize;
OMX_VERSIONTYPE nVersion;
OMX_U32 nPortIndex;
OMX_METERINGTYPE eMetering;
OMX_S32 xEVCompensation; /**< Fixed point value stored as Q16 */
OMX_U32 nApertureFNumber; /**< e.g. nApertureFNumber = 2 implies "f/2" - Q16 format */
OMX_BOOL bAutoAperture; /**< Whether aperture number is defined automatically */
OMX_U32 nShutterSpeedMsec; /**< Shutterspeed in milliseconds */
OMX_BOOL bAutoShutterSpeed; /**< Whether shutter speed is defined automatically */
OMX_U32 nSensitivity; /**< e.g. nSensitivity = 100 implies "ISO 100" */
OMX_BOOL bAutoSensitivity; /**< Whether sensitivity is defined automatically */
} OMX_CONFIG_EXPOSUREVALUETYPE;
/**
* Focus region configuration
*
* STRUCT MEMBERS:
* nSize : Size of the structure in bytes
* nVersion : OMX specification version information
* nPortIndex : Port that this structure applies to
* bCenter : Use center region as focus region of interest
* bLeft : Use left region as focus region of interest
* bRight : Use right region as focus region of interest
* bTop : Use top region as focus region of interest
* bBottom : Use bottom region as focus region of interest
* bTopLeft : Use top left region as focus region of interest
* bTopRight : Use top right region as focus region of interest
* bBottomLeft : Use bottom left region as focus region of interest
* bBottomRight : Use bottom right region as focus region of interest
*/
typedef struct OMX_CONFIG_FOCUSREGIONTYPE {
OMX_U32 nSize;
OMX_VERSIONTYPE nVersion;
OMX_U32 nPortIndex;
OMX_BOOL bCenter;
OMX_BOOL bLeft;
OMX_BOOL bRight;
OMX_BOOL bTop;
OMX_BOOL bBottom;
OMX_BOOL bTopLeft;
OMX_BOOL bTopRight;
OMX_BOOL bBottomLeft;
OMX_BOOL bBottomRight;
} OMX_CONFIG_FOCUSREGIONTYPE;
/**
* Focus Status type
*/
typedef enum OMX_FOCUSSTATUSTYPE {
OMX_FocusStatusOff = 0,
OMX_FocusStatusRequest,
OMX_FocusStatusReached,
OMX_FocusStatusUnableToReach,
OMX_FocusStatusLost,
OMX_FocusStatusKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */
OMX_FocusStatusVendorStartUnused = 0x7F000000, /**< Reserved region for introducing Vendor Extensions */
OMX_FocusStatusMax = 0x7FFFFFFF
} OMX_FOCUSSTATUSTYPE;
/**
* Focus status configuration
*
* STRUCT MEMBERS:
* nSize : Size of the structure in bytes
* nVersion : OMX specification version information
* nPortIndex : Port that this structure applies to
* eFocusStatus : Specifies the focus status
* bCenterStatus : Use center region as focus region of interest
* bLeftStatus : Use left region as focus region of interest
* bRightStatus : Use right region as focus region of interest
* bTopStatus : Use top region as focus region of interest
* bBottomStatus : Use bottom region as focus region of interest
* bTopLeftStatus : Use top left region as focus region of interest
* bTopRightStatus : Use top right region as focus region of interest
* bBottomLeftStatus : Use bottom left region as focus region of interest
* bBottomRightStatus : Use bottom right region as focus region of interest
*/
typedef struct OMX_PARAM_FOCUSSTATUSTYPE {
OMX_U32 nSize;
OMX_VERSIONTYPE nVersion;
OMX_U32 nPortIndex;
OMX_FOCUSSTATUSTYPE eFocusStatus;
OMX_BOOL bCenterStatus;
OMX_BOOL bLeftStatus;
OMX_BOOL bRightStatus;
OMX_BOOL bTopStatus;
OMX_BOOL bBottomStatus;
OMX_BOOL bTopLeftStatus;
OMX_BOOL bTopRightStatus;
OMX_BOOL bBottomLeftStatus;
OMX_BOOL bBottomRightStatus;
} OMX_PARAM_FOCUSSTATUSTYPE;
/** @} */
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
/* File EOF */
@@ -0,0 +1,345 @@
/* ------------------------------------------------------------------
* Copyright (C) 1998-2009 PacketVideo
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied.
* See the License for the specific language governing permissions
* and limitations under the License.
* -------------------------------------------------------------------
*/
/**
* Copyright (c) 2008 The Khronos Group Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject
* to the following conditions:
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/**
* @file OMX_Image.h - OpenMax IL version 1.1.2
* The structures needed by Image components to exchange parameters and
* configuration data with the components.
*/
#ifndef OMX_Image_h
#define OMX_Image_h
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/**
* Each OMX header must include all required header files to allow the
* header to compile without errors. The includes below are required
* for this header file to compile successfully
*/
#include <OMX_IVCommon.h>
/** @defgroup imaging OpenMAX IL Imaging Domain
* @ingroup iv
* Structures for OpenMAX IL Imaging domain
* @{
*/
/**
* Enumeration used to define the possible image compression coding.
*/
typedef enum OMX_IMAGE_CODINGTYPE {
OMX_IMAGE_CodingUnused, /**< Value when format is N/A */
OMX_IMAGE_CodingAutoDetect, /**< Auto detection of image format */
OMX_IMAGE_CodingJPEG, /**< JPEG/JFIF image format */
OMX_IMAGE_CodingJPEG2K, /**< JPEG 2000 image format */
OMX_IMAGE_CodingEXIF, /**< EXIF image format */
OMX_IMAGE_CodingTIFF, /**< TIFF image format */
OMX_IMAGE_CodingGIF, /**< Graphics image format */
OMX_IMAGE_CodingPNG, /**< PNG image format */
OMX_IMAGE_CodingLZW, /**< LZW image format */
OMX_IMAGE_CodingBMP, /**< Windows Bitmap format */
OMX_IMAGE_CodingKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */
OMX_IMAGE_CodingVendorStartUnused = 0x7F000000, /**< Reserved region for introducing Vendor Extensions */
OMX_IMAGE_CodingMax = 0x7FFFFFFF
} OMX_IMAGE_CODINGTYPE;
/**
* Data structure used to define an image path. The number of image paths
* for input and output will vary by type of the image component.
*
* Input (aka Source) : Zero Inputs, one Output,
* Splitter : One Input, 2 or more Outputs,
* Processing Element : One Input, one output,
* Mixer : 2 or more inputs, one output,
* Output (aka Sink) : One Input, zero outputs.
*
* The PortDefinition structure is used to define all of the parameters
* necessary for the compliant component to setup an input or an output
* image path. If additional vendor specific data is required, it should
* be transmitted to the component using the CustomCommand function.
* Compliant components will prepopulate this structure with optimal
* values during the OMX_GetParameter() command.
*
* STRUCT MEMBERS:
* cMIMEType : MIME type of data for the port
* pNativeRender : Platform specific reference for a display if a
* sync, otherwise this field is 0
* nFrameWidth : Width of frame to be used on port if
* uncompressed format is used. Use 0 for
* unknown, don't care or variable
* nFrameHeight : Height of frame to be used on port if
* uncompressed format is used. Use 0 for
* unknown, don't care or variable
* nStride : Number of bytes per span of an image (i.e.
* indicates the number of bytes to get from
* span N to span N+1, where negative stride
* indicates the image is bottom up
* nSliceHeight : Height used when encoding in slices
* bFlagErrorConcealment : Turns on error concealment if it is supported by
* the OMX component
* eCompressionFormat : Compression format used in this instance of
* the component. When OMX_IMAGE_CodingUnused is
* specified, eColorFormat is valid
* eColorFormat : Decompressed format used by this component
* pNativeWindow : Platform specific reference for a window object if a
* display sink , otherwise this field is 0x0.
*/
typedef struct OMX_IMAGE_PORTDEFINITIONTYPE {
OMX_STRING cMIMEType;
OMX_NATIVE_DEVICETYPE pNativeRender;
OMX_U32 nFrameWidth;
OMX_U32 nFrameHeight;
OMX_S32 nStride;
OMX_U32 nSliceHeight;
OMX_BOOL bFlagErrorConcealment;
OMX_IMAGE_CODINGTYPE eCompressionFormat;
OMX_COLOR_FORMATTYPE eColorFormat;
OMX_NATIVE_WINDOWTYPE pNativeWindow;
} OMX_IMAGE_PORTDEFINITIONTYPE;
/**
* Port format parameter. This structure is used to enumerate the various
* data input/output format supported by the port.
*
* STRUCT MEMBERS:
* nSize : Size of the structure in bytes
* nVersion : OMX specification version information
* nPortIndex : Indicates which port to set
* nIndex : Indicates the enumeration index for the format from
* 0x0 to N-1
* eCompressionFormat : Compression format used in this instance of the
* component. When OMX_IMAGE_CodingUnused is specified,
* eColorFormat is valid
* eColorFormat : Decompressed format used by this component
*/
typedef struct OMX_IMAGE_PARAM_PORTFORMATTYPE {
OMX_U32 nSize;
OMX_VERSIONTYPE nVersion;
OMX_U32 nPortIndex;
OMX_U32 nIndex;
OMX_IMAGE_CODINGTYPE eCompressionFormat;
OMX_COLOR_FORMATTYPE eColorFormat;
} OMX_IMAGE_PARAM_PORTFORMATTYPE;
/**
* Flash control type
*
* ENUMS
* Torch : Flash forced constantly on
*/
typedef enum OMX_IMAGE_FLASHCONTROLTYPE {
OMX_IMAGE_FlashControlOn = 0,
OMX_IMAGE_FlashControlOff,
OMX_IMAGE_FlashControlAuto,
OMX_IMAGE_FlashControlRedEyeReduction,
OMX_IMAGE_FlashControlFillin,
OMX_IMAGE_FlashControlTorch,
OMX_IMAGE_FlashControlKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */
OMX_IMAGE_FlashControlVendorStartUnused = 0x7F000000, /**< Reserved region for introducing Vendor Extensions */
OMX_IMAGE_FlashControlMax = 0x7FFFFFFF
} OMX_IMAGE_FLASHCONTROLTYPE;
/**
* Flash control configuration
*
* STRUCT MEMBERS:
* nSize : Size of the structure in bytes
* nVersion : OMX specification version information
* nPortIndex : Port that this structure applies to
* eFlashControl : Flash control type
*/
typedef struct OMX_IMAGE_PARAM_FLASHCONTROLTYPE {
OMX_U32 nSize;
OMX_VERSIONTYPE nVersion;
OMX_U32 nPortIndex;
OMX_IMAGE_FLASHCONTROLTYPE eFlashControl;
} OMX_IMAGE_PARAM_FLASHCONTROLTYPE;
/**
* Focus control type
*/
typedef enum OMX_IMAGE_FOCUSCONTROLTYPE {
OMX_IMAGE_FocusControlOn = 0,
OMX_IMAGE_FocusControlOff,
OMX_IMAGE_FocusControlAuto,
OMX_IMAGE_FocusControlAutoLock,
OMX_IMAGE_FocusControlKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */
OMX_IMAGE_FocusControlVendorStartUnused = 0x7F000000, /**< Reserved region for introducing Vendor Extensions */
OMX_IMAGE_FocusControlMax = 0x7FFFFFFF
} OMX_IMAGE_FOCUSCONTROLTYPE;
/**
* Focus control configuration
*
* STRUCT MEMBERS:
* nSize : Size of the structure in bytes
* nVersion : OMX specification version information
* nPortIndex : Port that this structure applies to
* eFocusControl : Focus control
* nFocusSteps : Focus can take on values from 0 mm to infinity.
* Interest is only in number of steps over this range.
* nFocusStepIndex : Current focus step index
*/
typedef struct OMX_IMAGE_CONFIG_FOCUSCONTROLTYPE {
OMX_U32 nSize;
OMX_VERSIONTYPE nVersion;
OMX_U32 nPortIndex;
OMX_IMAGE_FOCUSCONTROLTYPE eFocusControl;
OMX_U32 nFocusSteps;
OMX_U32 nFocusStepIndex;
} OMX_IMAGE_CONFIG_FOCUSCONTROLTYPE;
/**
* Q Factor for JPEG compression, which controls the tradeoff between image
* quality and size. Q Factor provides a more simple means of controlling
* JPEG compression quality, without directly programming Quantization
* tables for chroma and luma
*
* STRUCT MEMBERS:
* nSize : Size of the structure in bytes
* nVersion : OMX specification version information
* nPortIndex : Port that this structure applies to
* nQFactor : JPEG Q factor value in the range of 1-100. A factor of 1
* produces the smallest, worst quality images, and a factor
* of 100 produces the largest, best quality images. A
* typical default is 75 for small good quality images
*/
typedef struct OMX_IMAGE_PARAM_QFACTORTYPE {
OMX_U32 nSize;
OMX_VERSIONTYPE nVersion;
OMX_U32 nPortIndex;
OMX_U32 nQFactor;
} OMX_IMAGE_PARAM_QFACTORTYPE;
/**
* Quantization table type
*/
typedef enum OMX_IMAGE_QUANTIZATIONTABLETYPE {
OMX_IMAGE_QuantizationTableLuma = 0,
OMX_IMAGE_QuantizationTableChroma,
OMX_IMAGE_QuantizationTableChromaCb,
OMX_IMAGE_QuantizationTableChromaCr,
OMX_IMAGE_QuantizationTableKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */
OMX_IMAGE_QuantizationTableVendorStartUnused = 0x7F000000, /**< Reserved region for introducing Vendor Extensions */
OMX_IMAGE_QuantizationTableMax = 0x7FFFFFFF
} OMX_IMAGE_QUANTIZATIONTABLETYPE;
/**
* JPEG quantization tables are used to determine DCT compression for
* YUV data, as an alternative to specifying Q factor, providing exact
* control of compression
*
* STRUCT MEMBERS:
* nSize : Size of the structure in bytes
* nVersion : OMX specification version information
* nPortIndex : Port that this structure applies to
* eQuantizationTable : Quantization table type
* nQuantizationMatrix[64] : JPEG quantization table of coefficients stored
* in increasing columns then by rows of data (i.e.
* row 1, ... row 8). Quantization values are in
* the range 0-255 and stored in linear order
* (i.e. the component will zig-zag the
* quantization table data if required internally)
*/
typedef struct OMX_IMAGE_PARAM_QUANTIZATIONTABLETYPE {
OMX_U32 nSize;
OMX_VERSIONTYPE nVersion;
OMX_U32 nPortIndex;
OMX_IMAGE_QUANTIZATIONTABLETYPE eQuantizationTable;
OMX_U8 nQuantizationMatrix[64];
} OMX_IMAGE_PARAM_QUANTIZATIONTABLETYPE;
/**
* Huffman table type, the same Huffman table is applied for chroma and
* luma component
*/
typedef enum OMX_IMAGE_HUFFMANTABLETYPE {
OMX_IMAGE_HuffmanTableAC = 0,
OMX_IMAGE_HuffmanTableDC,
OMX_IMAGE_HuffmanTableACLuma,
OMX_IMAGE_HuffmanTableACChroma,
OMX_IMAGE_HuffmanTableDCLuma,
OMX_IMAGE_HuffmanTableDCChroma,
OMX_IMAGE_HuffmanTableKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */
OMX_IMAGE_HuffmanTableVendorStartUnused = 0x7F000000, /**< Reserved region for introducing Vendor Extensions */
OMX_IMAGE_HuffmanTableMax = 0x7FFFFFFF
} OMX_IMAGE_HUFFMANTABLETYPE;
/**
* JPEG Huffman table
*
* STRUCT MEMBERS:
* nSize : Size of the structure in bytes
* nVersion : OMX specification version information
* nPortIndex : Port that this structure applies to
* eHuffmanTable : Huffman table type
* nNumberOfHuffmanCodeOfLength[16] : 0-16, number of Huffman codes of each
* possible length
* nHuffmanTable[256] : 0-255, the size used for AC and DC
* HuffmanTable are 16 and 162
*/
typedef struct OMX_IMAGE_PARAM_HUFFMANTTABLETYPE {
OMX_U32 nSize;
OMX_VERSIONTYPE nVersion;
OMX_U32 nPortIndex;
OMX_IMAGE_HUFFMANTABLETYPE eHuffmanTable;
OMX_U8 nNumberOfHuffmanCodeOfLength[16];
OMX_U8 nHuffmanTable[256];
}OMX_IMAGE_PARAM_HUFFMANTTABLETYPE;
/** @} */
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
/* File EOF */
@@ -0,0 +1,280 @@
/* ------------------------------------------------------------------
* Copyright (C) 1998-2009 PacketVideo
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied.
* See the License for the specific language governing permissions
* and limitations under the License.
* -------------------------------------------------------------------
*/
/*
* Copyright (c) 2008 The Khronos Group Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject
* to the following conditions:
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
/** @file OMX_Index.h - OpenMax IL version 1.1.2
* The OMX_Index header file contains the definitions for both applications
* and components .
*/
#ifndef OMX_Index_h
#define OMX_Index_h
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/* Each OMX header must include all required header files to allow the
* header to compile without errors. The includes below are required
* for this header file to compile successfully
*/
#include <OMX_Types.h>
/** The OMX_INDEXTYPE enumeration is used to select a structure when either
* getting or setting parameters and/or configuration data. Each entry in
* this enumeration maps to an OMX specified structure. When the
* OMX_GetParameter, OMX_SetParameter, OMX_GetConfig or OMX_SetConfig methods
* are used, the second parameter will always be an entry from this enumeration
* and the third entry will be the structure shown in the comments for the entry.
* For example, if the application is initializing a cropping function, the
* OMX_SetConfig command would have OMX_IndexConfigCommonInputCrop as the second parameter
* and would send a pointer to an initialized OMX_RECTTYPE structure as the
* third parameter.
*
* The enumeration entries named with the OMX_Config prefix are sent using
* the OMX_SetConfig command and the enumeration entries named with the
* OMX_PARAM_ prefix are sent using the OMX_SetParameter command.
*/
typedef enum OMX_INDEXTYPE {
OMX_IndexComponentStartUnused = 0x01000000,
OMX_IndexParamPriorityMgmt, /**< reference: OMX_PRIORITYMGMTTYPE */
OMX_IndexParamAudioInit, /**< reference: OMX_PORT_PARAM_TYPE */
OMX_IndexParamImageInit, /**< reference: OMX_PORT_PARAM_TYPE */
OMX_IndexParamVideoInit, /**< reference: OMX_PORT_PARAM_TYPE */
OMX_IndexParamOtherInit, /**< reference: OMX_PORT_PARAM_TYPE */
OMX_IndexParamNumAvailableStreams, /**< reference: OMX_PARAM_U32TYPE */
OMX_IndexParamActiveStream, /**< reference: OMX_PARAM_U32TYPE */
OMX_IndexParamSuspensionPolicy, /**< reference: OMX_PARAM_SUSPENSIONPOLICYTYPE */
OMX_IndexParamComponentSuspended, /**< reference: OMX_PARAM_SUSPENSIONTYPE */
OMX_IndexConfigCapturing, /**< reference: OMX_CONFIG_BOOLEANTYPE */
OMX_IndexConfigCaptureMode, /**< reference: OMX_CONFIG_CAPTUREMODETYPE */
OMX_IndexAutoPauseAfterCapture, /**< reference: OMX_CONFIG_BOOLEANTYPE */
OMX_IndexParamContentURI, /**< reference: OMX_PARAM_CONTENTURITYPE */
OMX_IndexParamCustomContentPipe, /**< reference: OMX_PARAM_CONTENTPIPETYPE */
OMX_IndexParamDisableResourceConcealment, /**< reference: OMX_RESOURCECONCEALMENTTYPE */
OMX_IndexConfigMetadataItemCount, /**< reference: OMX_CONFIG_METADATAITEMCOUNTTYPE */
OMX_IndexConfigContainerNodeCount, /**< reference: OMX_CONFIG_CONTAINERNODECOUNTTYPE */
OMX_IndexConfigMetadataItem, /**< reference: OMX_CONFIG_METADATAITEMTYPE */
OMX_IndexConfigCounterNodeID, /**< reference: OMX_CONFIG_CONTAINERNODEIDTYPE */
OMX_IndexParamMetadataFilterType, /**< reference: OMX_PARAM_METADATAFILTERTYPE */
OMX_IndexParamMetadataKeyFilter, /**< reference: OMX_PARAM_METADATAFILTERTYPE */
OMX_IndexConfigPriorityMgmt, /**< reference: OMX_PRIORITYMGMTTYPE */
OMX_IndexParamStandardComponentRole, /**< reference: OMX_PARAM_COMPONENTROLETYPE */
OMX_IndexComponentEndUnused,
OMX_IndexPortStartUnused = 0x02000000,
OMX_IndexParamPortDefinition, /**< reference: OMX_PARAM_PORTDEFINITIONTYPE */
OMX_IndexParamCompBufferSupplier, /**< reference: OMX_PARAM_BUFFERSUPPLIERTYPE */
OMX_IndexPortEndUnused,
OMX_IndexReservedStartUnused = 0x03000000,
/* Audio parameters and configurations */
OMX_IndexAudioStartUnused = 0x04000000,
OMX_IndexParamAudioPortFormat, /**< reference: OMX_AUDIO_PARAM_PORTFORMATTYPE */
OMX_IndexParamAudioPcm, /**< reference: OMX_AUDIO_PARAM_PCMMODETYPE */
OMX_IndexParamAudioAac, /**< reference: OMX_AUDIO_PARAM_AACPROFILETYPE */
OMX_IndexParamAudioRa, /**< reference: OMX_AUDIO_PARAM_RATYPE */
OMX_IndexParamAudioMp3, /**< reference: OMX_AUDIO_PARAM_MP3TYPE */
OMX_IndexParamAudioAdpcm, /**< reference: OMX_AUDIO_PARAM_ADPCMTYPE */
OMX_IndexParamAudioG723, /**< reference: OMX_AUDIO_PARAM_G723TYPE */
OMX_IndexParamAudioG729, /**< reference: OMX_AUDIO_PARAM_G729TYPE */
OMX_IndexParamAudioAmr, /**< reference: OMX_AUDIO_PARAM_AMRTYPE */
OMX_IndexParamAudioWma, /**< reference: OMX_AUDIO_PARAM_WMATYPE */
OMX_IndexParamAudioSbc, /**< reference: OMX_AUDIO_PARAM_SBCTYPE */
OMX_IndexParamAudioMidi, /**< reference: OMX_AUDIO_PARAM_MIDITYPE */
OMX_IndexParamAudioGsm_FR, /**< reference: OMX_AUDIO_PARAM_GSMFRTYPE */
OMX_IndexParamAudioMidiLoadUserSound, /**< reference: OMX_AUDIO_PARAM_MIDILOADUSERSOUNDTYPE */
OMX_IndexParamAudioG726, /**< reference: OMX_AUDIO_PARAM_G726TYPE */
OMX_IndexParamAudioGsm_EFR, /**< reference: OMX_AUDIO_PARAM_GSMEFRTYPE */
OMX_IndexParamAudioGsm_HR, /**< reference: OMX_AUDIO_PARAM_GSMHRTYPE */
OMX_IndexParamAudioPdc_FR, /**< reference: OMX_AUDIO_PARAM_PDCFRTYPE */
OMX_IndexParamAudioPdc_EFR, /**< reference: OMX_AUDIO_PARAM_PDCEFRTYPE */
OMX_IndexParamAudioPdc_HR, /**< reference: OMX_AUDIO_PARAM_PDCHRTYPE */
OMX_IndexParamAudioTdma_FR, /**< reference: OMX_AUDIO_PARAM_TDMAFRTYPE */
OMX_IndexParamAudioTdma_EFR, /**< reference: OMX_AUDIO_PARAM_TDMAEFRTYPE */
OMX_IndexParamAudioQcelp8, /**< reference: OMX_AUDIO_PARAM_QCELP8TYPE */
OMX_IndexParamAudioQcelp13, /**< reference: OMX_AUDIO_PARAM_QCELP13TYPE */
OMX_IndexParamAudioEvrc, /**< reference: OMX_AUDIO_PARAM_EVRCTYPE */
OMX_IndexParamAudioSmv, /**< reference: OMX_AUDIO_PARAM_SMVTYPE */
OMX_IndexParamAudioVorbis, /**< reference: OMX_AUDIO_PARAM_VORBISTYPE */
OMX_IndexParamAudioFlac, /**< reference: OMX_AUDIO_PARAM_FLACTYPE */
OMX_IndexAudioEndUnused,
OMX_IndexConfigAudioMidiImmediateEvent, /**< reference: OMX_AUDIO_CONFIG_MIDIIMMEDIATEEVENTTYPE */
OMX_IndexConfigAudioMidiControl, /**< reference: OMX_AUDIO_CONFIG_MIDICONTROLTYPE */
OMX_IndexConfigAudioMidiSoundBankProgram, /**< reference: OMX_AUDIO_CONFIG_MIDISOUNDBANKPROGRAMTYPE */
OMX_IndexConfigAudioMidiStatus, /**< reference: OMX_AUDIO_CONFIG_MIDISTATUSTYPE */
OMX_IndexConfigAudioMidiMetaEvent, /**< reference: OMX_AUDIO_CONFIG_MIDIMETAEVENTTYPE */
OMX_IndexConfigAudioMidiMetaEventData, /**< reference: OMX_AUDIO_CONFIG_MIDIMETAEVENTDATATYPE */
OMX_IndexConfigAudioVolume, /**< reference: OMX_AUDIO_CONFIG_VOLUMETYPE */
OMX_IndexConfigAudioBalance, /**< reference: OMX_AUDIO_CONFIG_BALANCETYPE */
OMX_IndexConfigAudioChannelMute, /**< reference: OMX_AUDIO_CONFIG_CHANNELMUTETYPE */
OMX_IndexConfigAudioMute, /**< reference: OMX_AUDIO_CONFIG_MUTETYPE */
OMX_IndexConfigAudioLoudness, /**< reference: OMX_AUDIO_CONFIG_LOUDNESSTYPE */
OMX_IndexConfigAudioEchoCancelation, /**< reference: OMX_AUDIO_CONFIG_ECHOCANCELATIONTYPE */
OMX_IndexConfigAudioNoiseReduction, /**< reference: OMX_AUDIO_CONFIG_NOISEREDUCTIONTYPE */
OMX_IndexConfigAudioBass, /**< reference: OMX_AUDIO_CONFIG_BASSTYPE */
OMX_IndexConfigAudioTreble, /**< reference: OMX_AUDIO_CONFIG_TREBLETYPE */
OMX_IndexConfigAudioStereoWidening, /**< reference: OMX_AUDIO_CONFIG_STEREOWIDENINGTYPE */
OMX_IndexConfigAudioChorus, /**< reference: OMX_AUDIO_CONFIG_CHORUSTYPE */
OMX_IndexConfigAudioEqualizer, /**< reference: OMX_AUDIO_CONFIG_EQUALIZERTYPE */
OMX_IndexConfigAudioReverberation, /**< reference: OMX_AUDIO_CONFIG_REVERBERATIONTYPE */
OMX_IndexConfigAudioChannelVolume, /**< reference: OMX_AUDIO_CONFIG_CHANNELVOLUMETYPE */
/* Image specific parameters and configurations */
OMX_IndexImageStartUnused = 0x05000000,
OMX_IndexParamImagePortFormat, /**< reference: OMX_IMAGE_PARAM_PORTFORMATTYPE */
OMX_IndexParamFlashControl, /**< reference: OMX_IMAGE_PARAM_FLASHCONTROLTYPE */
OMX_IndexConfigFocusControl, /**< reference: OMX_IMAGE_CONFIG_FOCUSCONTROLTYPE */
OMX_IndexParamQFactor, /**< reference: OMX_IMAGE_PARAM_QFACTORTYPE */
OMX_IndexParamQuantizationTable, /**< reference: OMX_IMAGE_PARAM_QUANTIZATIONTABLETYPE */
OMX_IndexParamHuffmanTable, /**< reference: OMX_IMAGE_PARAM_HUFFMANTTABLETYPE */
OMX_IndexConfigFlashControl, /**< reference: OMX_IMAGE_PARAM_FLASHCONTROLTYPE */
/* Video specific parameters and configurations */
OMX_IndexVideoStartUnused = 0x06000000,
OMX_IndexParamVideoPortFormat, /**< reference: OMX_VIDEO_PARAM_PORTFORMATTYPE */
OMX_IndexParamVideoQuantization, /**< reference: OMX_VIDEO_PARAM_QUANTIZATIONTYPE */
OMX_IndexParamVideoFastUpdate, /**< reference: OMX_VIDEO_PARAM_VIDEOFASTUPDATETYPE */
OMX_IndexParamVideoBitrate, /**< reference: OMX_VIDEO_PARAM_BITRATETYPE */
OMX_IndexParamVideoMotionVector, /**< reference: OMX_VIDEO_PARAM_MOTIONVECTORTYPE */
OMX_IndexParamVideoIntraRefresh, /**< reference: OMX_VIDEO_PARAM_INTRAREFRESHTYPE */
OMX_IndexParamVideoErrorCorrection, /**< reference: OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE */
OMX_IndexParamVideoVBSMC, /**< reference: OMX_VIDEO_PARAM_VBSMCTYPE */
OMX_IndexParamVideoMpeg2, /**< reference: OMX_VIDEO_PARAM_MPEG2TYPE */
OMX_IndexParamVideoMpeg4, /**< reference: OMX_VIDEO_PARAM_MPEG4TYPE */
OMX_IndexParamVideoWmv, /**< reference: OMX_VIDEO_PARAM_WMVTYPE */
OMX_IndexParamVideoRv, /**< reference: OMX_VIDEO_PARAM_RVTYPE */
OMX_IndexParamVideoAvc, /**< reference: OMX_VIDEO_PARAM_AVCTYPE */
OMX_IndexParamVideoH263, /**< reference: OMX_VIDEO_PARAM_H263TYPE */
OMX_IndexParamVideoProfileLevelQuerySupported, /**< reference: OMX_VIDEO_PARAM_PROFILELEVELTYPE */
OMX_IndexParamVideoProfileLevelCurrent, /**< reference: OMX_VIDEO_PARAM_PROFILELEVELTYPE */
OMX_IndexConfigVideoBitrate, /**< reference: OMX_VIDEO_CONFIG_BITRATETYPE */
OMX_IndexConfigVideoFramerate, /**< reference: OMX_CONFIG_FRAMERATETYPE */
OMX_IndexConfigVideoIntraVOPRefresh, /**< reference: OMX_CONFIG_INTRAREFRESHVOPTYPE */
OMX_IndexConfigVideoIntraMBRefresh, /**< reference: OMX_CONFIG_MACROBLOCKERRORMAPTYPE */
OMX_IndexConfigVideoMBErrorReporting, /**< reference: OMX_CONFIG_MBERRORREPORTINGTYPE */
OMX_IndexParamVideoMacroblocksPerFrame, /**< reference: OMX_PARAM_MACROBLOCKSTYPE */
OMX_IndexConfigVideoMacroBlockErrorMap, /**< reference: OMX_CONFIG_MACROBLOCKERRORMAPTYPE */
OMX_IndexParamVideoSliceFMO, /**< reference: OMX_VIDEO_PARAM_AVCSLICEFMO */
OMX_IndexConfigVideoAVCIntraPeriod, /**< reference: OMX_VIDEO_CONFIG_AVCINTRAPERIOD */
OMX_IndexConfigVideoNalSize, /**< reference: OMX_VIDEO_CONFIG_NALSIZE */
OMX_IndexVideoEndUnused,
/* Image & Video common Configurations */
OMX_IndexCommonStartUnused = 0x07000000,
OMX_IndexParamCommonDeblocking, /**< reference: OMX_PARAM_DEBLOCKINGTYPE */
OMX_IndexParamCommonSensorMode, /**< reference: OMX_PARAM_SENSORMODETYPE */
OMX_IndexParamCommonInterleave, /**< reference: OMX_PARAM_INTERLEAVETYPE */
OMX_IndexConfigCommonColorFormatConversion, /**< reference: OMX_CONFIG_COLORCONVERSIONTYPE */
OMX_IndexConfigCommonScale, /**< reference: OMX_CONFIG_SCALEFACTORTYPE */
OMX_IndexConfigCommonImageFilter, /**< reference: OMX_CONFIG_IMAGEFILTERTYPE */
OMX_IndexConfigCommonColorEnhancement, /**< reference: OMX_CONFIG_COLORENHANCEMENTTYPE */
OMX_IndexConfigCommonColorKey, /**< reference: OMX_CONFIG_COLORKEYTYPE */
OMX_IndexConfigCommonColorBlend, /**< reference: OMX_CONFIG_COLORBLENDTYPE */
OMX_IndexConfigCommonFrameStabilisation,/**< reference: OMX_CONFIG_FRAMESTABTYPE */
OMX_IndexConfigCommonRotate, /**< reference: OMX_CONFIG_ROTATIONTYPE */
OMX_IndexConfigCommonMirror, /**< reference: OMX_CONFIG_MIRRORTYPE */
OMX_IndexConfigCommonOutputPosition, /**< reference: OMX_CONFIG_POINTTYPE */
OMX_IndexConfigCommonInputCrop, /**< reference: OMX_CONFIG_RECTTYPE */
OMX_IndexConfigCommonOutputCrop, /**< reference: OMX_CONFIG_RECTTYPE */
OMX_IndexConfigCommonDigitalZoom, /**< reference: OMX_CONFIG_SCALEFACTORTYPE */
OMX_IndexConfigCommonOpticalZoom, /**< reference: OMX_CONFIG_SCALEFACTORTYPE*/
OMX_IndexConfigCommonWhiteBalance, /**< reference: OMX_CONFIG_WHITEBALCONTROLTYPE */
OMX_IndexConfigCommonExposure, /**< reference: OMX_CONFIG_EXPOSURECONTROLTYPE */
OMX_IndexConfigCommonContrast, /**< reference: OMX_CONFIG_CONTRASTTYPE */
OMX_IndexConfigCommonBrightness, /**< reference: OMX_CONFIG_BRIGHTNESSTYPE */
OMX_IndexConfigCommonBacklight, /**< reference: OMX_CONFIG_BACKLIGHTTYPE */
OMX_IndexConfigCommonGamma, /**< reference: OMX_CONFIG_GAMMATYPE */
OMX_IndexConfigCommonSaturation, /**< reference: OMX_CONFIG_SATURATIONTYPE */
OMX_IndexConfigCommonLightness, /**< reference: OMX_CONFIG_LIGHTNESSTYPE */
OMX_IndexConfigCommonExclusionRect, /**< reference: OMX_CONFIG_RECTTYPE */
OMX_IndexConfigCommonDithering, /**< reference: OMX_CONFIG_DITHERTYPE */
OMX_IndexConfigCommonPlaneBlend, /**< reference: OMX_CONFIG_PLANEBLENDTYPE */
OMX_IndexConfigCommonExposureValue, /**< reference: OMX_CONFIG_EXPOSUREVALUETYPE */
OMX_IndexConfigCommonOutputSize, /**< reference: OMX_FRAMESIZETYPE */
OMX_IndexParamCommonExtraQuantData, /**< reference: OMX_OTHER_EXTRADATATYPE */
OMX_IndexConfigCommonFocusRegion, /**< reference: OMX_CONFIG_FOCUSREGIONTYPE */
OMX_IndexConfigCommonFocusStatus, /**< reference: OMX_PARAM_FOCUSSTATUSTYPE */
OMX_IndexConfigCommonTransitionEffect, /**< reference: OMX_CONFIG_TRANSITIONEFFECTTYPE */
OMX_IndexCommonEndUnused,
/* Reserved Configuration range */
OMX_IndexOtherStartUnused = 0x08000000,
OMX_IndexParamOtherPortFormat, /**< reference: OMX_OTHER_PARAM_PORTFORMATTYPE */
OMX_IndexConfigOtherPower, /**< reference: OMX_OTHER_CONFIG_POWERTYPE */
OMX_IndexConfigOtherStats, /**< reference: OMX_OTHER_CONFIG_STATSTYPE */
/* Reserved Time range */
OMX_IndexTimeStartUnused = 0x09000000,
OMX_IndexConfigTimeScale, /**< reference: OMX_TIME_CONFIG_SCALETYPE */
OMX_IndexConfigTimeClockState, /**< reference: OMX_TIME_CONFIG_CLOCKSTATETYPE */
OMX_IndexConfigTimeActiveRefClock, /**< reference: OMX_TIME_CONFIG_ACTIVEREFCLOCKTYPE */
OMX_IndexConfigTimeCurrentMediaTime, /**< reference: OMX_TIME_CONFIG_TIMESTAMPTYPE (read only) */
OMX_IndexConfigTimeCurrentWallTime, /**< reference: OMX_TIME_CONFIG_TIMESTAMPTYPE (read only) */
OMX_IndexConfigTimeCurrentAudioReference, /**< reference: OMX_TIME_CONFIG_TIMESTAMPTYPE (write only) */
OMX_IndexConfigTimeCurrentVideoReference, /**< reference: OMX_TIME_CONFIG_TIMESTAMPTYPE (write only) */
OMX_IndexConfigTimeMediaTimeRequest, /**< reference: OMX_TIME_CONFIG_MEDIATIMEREQUESTTYPE (write only) */
OMX_IndexConfigTimeClientStartTime, /**<reference: OMX_TIME_CONFIG_TIMESTAMPTYPE (write only) */
OMX_IndexConfigTimePosition, /**< reference: OMX_TIME_CONFIG_TIMESTAMPTYPE */
OMX_IndexConfigTimeSeekMode, /**< reference: OMX_TIME_CONFIG_SEEKMODETYPE */
OMX_IndexKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */
/* Vendor specific area */
OMX_IndexVendorStartUnused = 0x7F000000,
/* Vendor specific structures should be in the range of 0x7F000000
to 0x7FFFFFFE. This range is not broken out by vendor, so
private indexes are not guaranteed unique and therefore should
only be sent to the appropriate component. */
OMX_IndexMax = 0x7FFFFFFF
} OMX_INDEXTYPE;
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
/* File EOF */
Loaded 100 of 236 files, more files were not shown because too many files have changed in this diff. Show more