MediaPlayer: Seek for integrated fMP4 file#952
Conversation
|
Confirming this one's known — we hit the same on device (Quest, Mux Light version of what we've seen so far: the segment jump itself works (the VOD seek index rebuilds the fetch queue at the target), but the delivery pace clock doesn't re-anchor on an HLS seek the way a byte-source seek does — so after the jump, playback runs against a stale pacing anchor and stalls. It's on our list; still digging, no fix pinned down yet. |
|
Follow-up: the HLS-TS VOD seek issue mentioned on this PR (forward stall / backward flood after seeking) is now fixed in #956 — the segment-source reposition re-anchors the delivery pace clock at the flushed boundary. |
…fig / crop-rect hardening) (#956) ## Summary A batch of mediaplayer native fixes on top of #953, one commit per concern. The headline is the HLS-TS VOD seek fix; the rest are Android AAC-config and crop-rect hardening that came up alongside it. **HLS-TS VOD seek re-anchor (the main fix).** On the HLS-TS VOD path, seeking the on-demand slider misbehaved: a forward seek froze for roughly the jump distance before resuming, and a backward seek fast-forwarded unpaced through the intervening segments back to the pre-seek position instead of honouring the seek. Root cause is the delivery pace clock: it has to re-anchor at the flushed boundary on a seek, and while that re-anchor existed it lost a race — a stale pre-seek access unit could win it and pin the pace anchor to the old timestamp. The fix routes the HLS seek through the same flush-and-re-anchor handshake the MP4 byte-source path already uses: `basis_hls_read` raises a `BASIS_READ_REPOSITION` sentinel at the flushed boundary (gated on the seek generation), `basis_ts_run` drops the ring and PES accumulators and takes the seek to re-anchor on the demux thread, the seek publishes its sequence before arming the producer, and the whole handshake is serialised through the ring lock. A seek that races end-of-stream on a VOD no longer hangs. **Android AAC-config hardening (follow-up to #953).** Only publish a fully-parsed AudioSpecificConfig rather than announcing a partial one, bound the esds descriptor walk against its declared lengths, and fix the AAC-LC core trim while synchronising the Android video dimensions. **Android crop-rect hardening (follow-up to #953).** Read and apply the display-crop rect as a unit with endpoint validation, and close a data race on the crop rect between the decode and present paths. **Binaries.** Win x64 and Android arm64 native plugins rebuilt (RIST-enabled) to carry all of the above. Docs: README refreshed, and TESTING.md gained an HLS-TS VOD seek row (seek both directions on the Mux master, confirm playback resumes paced at 1x from the target rather than freezing forward or flooding backward). Verified on Windows (Unity editor, D3D11) and Android (Quest Pro) — full test matrix under Notes. ## Required checks All boxes below must be ticked before this PR can merge. If a check is genuinely N/A, tick it anyway and explain under **Notes**. <!-- required-checks-start --> <!-- Tick the boxes in place — do not edit the line text. The pr-checklist workflow parses this block; per-PR context goes under Notes. --> - [x] **Tested** — I built and ran this locally. The change works in the editor and (where relevant) in a built player. - [x] **Transform access is combined and limited** — In hot paths, transform reads/writes go through `TransformAccessArray` or are otherwise batched. I have not added per-frame `transform.position` / `transform.rotation` / `transform.localPosition` calls inside loops. Whenever I need both position and rotation, I use the combined APIs — `SetPositionAndRotation` / `SetLocalPositionAndRotation` for writes, `GetPositionAndRotation` / `GetLocalPositionAndRotation` for reads — instead of two separate property accesses; the combined call does one local-to-world matrix traversal instead of two. - [x] **Addressables used for asset/memory loading** — Any new asset loads go through Addressables. No new `Resources.Load`, no direct asset references that pull large content into memory on scene load. - [x] **No new `GetComponent` / `AddComponent` where avoidable** — Where unavoidable, the result is cached on a field, and any `GetComponent<T>` is replaced with `TryGetComponent<T>(out var x)` — bare `GetComponent` will be denied. `TryGetComponent` is the modern API (Unity 2019.2+) and skips the Editor-only GC allocation `GetComponent` causes when a component is missing: Unity wraps the `null` return in a managed "fake null" object so its overloaded `==` operator can still detect destroyed C++ objects, and constructing that wrapper allocates; `TryGetComponent` returns a `bool` plus `out` parameter and never builds the wrapper. None of these calls run inside `Update`, `LateUpdate`, `FixedUpdate`, jobs, or other per-frame code paths. - [x] **Per-frame work is scheduled through `BasisEventDriver`** — Any new per-frame work hooks into `BasisEventDriver` rather than adding standalone `Update` / `LateUpdate` / `FixedUpdate` callbacks on a MonoBehaviour. - [x] **Anything added to `BasisEventDriver` is bulletproof, or guarded by `try`/`catch`** — `BasisEventDriver` runs the single per-frame tick that drives the whole framework (network apply, local player sim, blendshapes, JigglePhysics, nameplates, and more) as one sequential chain. An unhandled exception anywhere in that chain aborts the rest of the tick, so every step after the throwing one is silently skipped for that frame. New work added to the driver must either be guaranteed not to throw, or be wrapped in a `try`/`catch` that contains the failure and surfaces it through `BasisDebug` — logged once / rate-limited, never every frame (see the existing `HVRBasisBuiltInAddresses.Simulate()` guard for the pattern). Expect this to be scrutinized closely in review. - [x] **Considered jobification** — I asked whether this work can be moved to a Unity Job (Burst-compiled where possible). If it can, it is. If it cannot, the reason is in **Notes**. - [x] **No needless `{ get; set; }` properties or access lockdowns** — Public fields are fine; Basis is meant to be read and modified freely, so don't wall things off `private`/`internal` without a real reason. Don't wrap a field in `{ get; set; }` when the accessors do nothing — property accessors have a real performance cost vs direct field access, and the lead maintainer prefers plain fields (or a method / setter-only property when only the setter needs logic) over a noop-getter pair. For `.Instance` singletons, callers reassigning `Type.Instance` is allowed; if that would break your code, log a warning or throw — don't block the assignment. Locking down access is not your call. - [x] **Camera access goes through `BasisLocalCameraDriver`** — Code that needs the local camera (transform, projection, rig data, etc.) pulls it from `BasisLocalCameraDriver` rather than looking one up itself. Don't roll a separate camera discovery path. - [x] **Logging uses `BasisDebug`** — All new logging calls go through `BasisDebug.Log` / `BasisDebug.LogWarning` / `BasisDebug.LogError` (with an appropriate `LogTag`) instead of `UnityEngine.Debug.Log` / `Debug.LogWarning` / `Debug.LogError`. `BasisDebug` routes through Basis's tagged, color-coded logger and respects the project-wide `LoggingDisabled` toggle so logging can be killed at runtime; bare `Debug.Log` calls bypass that and will be denied. - [x] **No scene-wide discovery for dependencies** — New code is architected so it does not need `FindObjectOfType` / `FindObjectsOfType` / `GameObject.Find` / `FindGameObjectsWithTag` to locate what it depends on. References are wired in — registered through an existing manager/driver, injected at init, or passed in by the caller — rather than discovered by scanning the scene at runtime. If a scene scan is genuinely unavoidable, justify it under **Notes**. - [x] **No allocations in hot paths** — Per-frame code (Update / LateUpdate / FixedUpdate, simulation loops, jobs, anything called once per frame or more) does not allocate. No `new` on reference types, no LINQ, no `string` concatenation/interpolation, no boxing, no `foreach` over interface-typed collections. Allocate once at init and reuse the buffer. - [x] **No debugging in hot paths** — No log calls of any kind on per-frame paths, including `BasisDebug`. Hot-path logging floods the console and incurs cost on every frame regardless of whether the message is filtered out downstream. If a hot-path log is needed while iterating, gate it behind `#if UNITY_EDITOR` and remove (or leave gated) before merge. - [x] **Hot-path collection access is optimized** — Cache `.Count` (lists) / `.Length` (arrays) into a local `int` before the loop instead of re-reading the property each iteration. Prefer `T[]` (with a separate length int when the array is over-sized) over `List<T>` where the data is hot — Unity's mono BCL doesn't expose `CollectionsMarshal.AsSpan(List<T>)`, so a list can't be fed into `Span<T>` / unsafe paths cleanly. Where the perf justifies it, drop into `Span<T>` / `ref` locals / `Unsafe.As` / `unsafe` pointer code to skip bounds checks and copies, and call out the invariants you're relying on under **Notes** so reviewers can sanity-check them. <!-- required-checks-end --> ## Testing details Tick the platforms you actually tested on. Leave the rest unticked — these are informational and do not block merge. - [x] Windows - [ ] Linux - [x] Android - [ ] iOS - [ ] macOS Input / control mode coverage: - [x] Tested in VR (note headset under **Notes**) - [x] Tested in desktop / non-VR mode - [ ] Tested with phone controls (mobile touch input) - [ ] N/A — change does not touch player/XR/input code Where applicable, confirm these flows still work after your changes: - [ ] Hot-switching (desktop ↔ VR mode swap at runtime) - [ ] Avatar swapping - [ ] Server swapping (joining / leaving / changing servers) - [x] N/A — change does not touch any of the above ## Notes - **Tested — Windows (Unity editor, D3D11) + Android (Quest Pro):** both green across HLS-TS VOD seek both directions (the fix — no forward stall / backward flood), integrated-fMP4 seek (regression check for #952 — unaffected), progressive + trailing-moov MP4 seek, AAC 5.1 in a progressive MP4 on Android (discrete, not silence), the Android coded-height crop (clean edge on device), RTSP UDP/TCP negotiation, HTTP-TS + HLS live, LPCM 7.1, HE-AAC 5.1, WAV, CEA-608 captions, both RIST modes, and the SSRF / localhost / `file://` security gates. - **Native-only change.** C sources under `com.basis.mediaplayer/Native~` plus the prebuilt Win x64 / Android arm64 binaries, and README/TESTING docs. No C#, Unity gameplay, scene, transform, camera, per-frame, or input code, so the Unity/C#-specific required checks are ticked N/A on that basis. - **Base.** Sits on #953 (merge-base), a few commits behind `developer`; no mediaplayer source has changed on `developer` since #953, so it rebases clean and the committed Win x64 / Android arm64 binaries are current.
|
Closing the loop: this is fixed in #956 (merged). One correction to my note above: a re-anchor did fire on HLS seeks, it just lost a race to access units already in flight from before the seek, so the pace anchor could re-base on stale timestamps. #956 moves the flush and re-anchor onto the demux thread at the flushed boundary, the same way the byte-source seek already worked, and both seek directions now behave on the Mux fixture (Windows editor and Quest). |
Summary
This pull request enables video seeking on videos from certain websites that stream Integrated fMP4 files.
Required checks
All boxes below must be ticked before this PR can merge. If a check is genuinely N/A, tick it anyway and explain under Notes.
TransformAccessArrayor are otherwise batched. I have not added per-frametransform.position/transform.rotation/transform.localPositioncalls inside loops. Whenever I need both position and rotation, I use the combined APIs —SetPositionAndRotation/SetLocalPositionAndRotationfor writes,GetPositionAndRotation/GetLocalPositionAndRotationfor reads — instead of two separate property accesses; the combined call does one local-to-world matrix traversal instead of two.Resources.Load, no direct asset references that pull large content into memory on scene load.GetComponent/AddComponentwhere avoidable — Where unavoidable, the result is cached on a field, and anyGetComponent<T>is replaced withTryGetComponent<T>(out var x)— bareGetComponentwill be denied.TryGetComponentis the modern API (Unity 2019.2+) and skips the Editor-only GC allocationGetComponentcauses when a component is missing: Unity wraps thenullreturn in a managed "fake null" object so its overloaded==operator can still detect destroyed C++ objects, and constructing that wrapper allocates;TryGetComponentreturns aboolplusoutparameter and never builds the wrapper. None of these calls run insideUpdate,LateUpdate,FixedUpdate, jobs, or other per-frame code paths.BasisEventDriver— Any new per-frame work hooks intoBasisEventDriverrather than adding standaloneUpdate/LateUpdate/FixedUpdatecallbacks on a MonoBehaviour.BasisEventDriveris bulletproof, or guarded bytry/catch—BasisEventDriverruns the single per-frame tick that drives the whole framework (network apply, local player sim, blendshapes, JigglePhysics, nameplates, and more) as one sequential chain. An unhandled exception anywhere in that chain aborts the rest of the tick, so every step after the throwing one is silently skipped for that frame. New work added to the driver must either be guaranteed not to throw, or be wrapped in atry/catchthat contains the failure and surfaces it throughBasisDebug— logged once / rate-limited, never every frame (see the existingHVRBasisBuiltInAddresses.Simulate()guard for the pattern). Expect this to be scrutinized closely in review.{ get; set; }properties or access lockdowns — Public fields are fine; Basis is meant to be read and modified freely, so don't wall things offprivate/internalwithout a real reason. Don't wrap a field in{ get; set; }when the accessors do nothing — property accessors have a real performance cost vs direct field access, and the lead maintainer prefers plain fields (or a method / setter-only property when only the setter needs logic) over a noop-getter pair. For.Instancesingletons, callers reassigningType.Instanceis allowed; if that would break your code, log a warning or throw — don't block the assignment. Locking down access is not your call.BasisLocalCameraDriver— Code that needs the local camera (transform, projection, rig data, etc.) pulls it fromBasisLocalCameraDriverrather than looking one up itself. Don't roll a separate camera discovery path.BasisDebug— All new logging calls go throughBasisDebug.Log/BasisDebug.LogWarning/BasisDebug.LogError(with an appropriateLogTag) instead ofUnityEngine.Debug.Log/Debug.LogWarning/Debug.LogError.BasisDebugroutes through Basis's tagged, color-coded logger and respects the project-wideLoggingDisabledtoggle so logging can be killed at runtime; bareDebug.Logcalls bypass that and will be denied.FindObjectOfType/FindObjectsOfType/GameObject.Find/FindGameObjectsWithTagto locate what it depends on. References are wired in — registered through an existing manager/driver, injected at init, or passed in by the caller — rather than discovered by scanning the scene at runtime. If a scene scan is genuinely unavoidable, justify it under Notes.newon reference types, no LINQ, nostringconcatenation/interpolation, no boxing, noforeachover interface-typed collections. Allocate once at init and reuse the buffer.BasisDebug. Hot-path logging floods the console and incurs cost on every frame regardless of whether the message is filtered out downstream. If a hot-path log is needed while iterating, gate it behind#if UNITY_EDITORand remove (or leave gated) before merge..Count(lists) /.Length(arrays) into a localintbefore the loop instead of re-reading the property each iteration. PreferT[](with a separate length int when the array is over-sized) overList<T>where the data is hot — Unity's mono BCL doesn't exposeCollectionsMarshal.AsSpan(List<T>), so a list can't be fed intoSpan<T>/ unsafe paths cleanly. Where the perf justifies it, drop intoSpan<T>/reflocals /Unsafe.As/unsafepointer code to skip bounds checks and copies, and call out the invariants you're relying on under Notes so reviewers can sanity-check them.Testing details
Tick the platforms you actually tested on. Leave the rest unticked — these are informational and do not block merge.
Input / control mode coverage:
Where applicable, confirm these flows still work after your changes:
Notes
Validation
Testing was conducted in the editor on Windows 11.
Integrated fMP4 VOD file: https://zipline.space.superneko.net/raw/bbb_sunflower_1080p_30fps_normal_idfmp4.mp4
The test file was encoded using the following options:
Integrated fMP4 VOD: Pausing and then resuming playback causes a small jump of approximately one second. This matches the behavior of progressive MP4 playback, so there is no regression. Player on Android also works.
HLS VOD: The video is reported as seekable, but playback becomes stuck after actually seeking. This matches the original behavior, so there is no regression, although it is probably a bug.
RIST: Validated successfully.
Split-stream playback: Tested with a video podcast resolved by
dlp-native. For some reason, the audio briefly cuts out approximately one second after audio/video synchronization completes. After this interruption, playback continues without further issues.Limitations
Native libraries
Base native libraries are built with this patch, based on 59b6e04 librist enabled.