Commit Graph
26 Commits
Author SHA1 Message Date
TheM14 ad9419fa7d Resume native PCM draining after input EOF
process_pcm saved the EOF frame and enabled draining, then returned
without emitting output or marking filter progress. Reading the input
pin does not schedule another process call, so the queued PCM was left
stranded with the output request still pending. On Android this stalled
the 10-second WAV at 00:06 and the full FLAC at 04:38 / 05:05.

Mark filter progress after storing EOF so the next process call runs the
existing gradual drain and forwards EOF after the remaining audio.
Keep the input-duration limit, renderer flush and decoder routing intact.

Verified with native Windows builds: the WAV outputs 480000 samples and
the FLAC outputs 14647040 samples at 48 kHz, both reaching EOF. The FLAC
baseline stalls at 278.528 seconds. E-AC-3 JOC output is bit-identical,
and ad-joc-pcm=no still selects the default decoder. Android baseline
failures were reproduced; the patched APK has not been built or tested.
2026-11-14 03:36:51 +08:00
TheM14 23a94a60fa Remove the PCM queue gate and drain EOF gradually
The queue gate stopped feeding PCM once the decoded-ahead count exceeded
PCM_MAX_QUEUE_SAMPLES.  On Android that happened at samples_out=97856
(about 2.04 s); process_pcm then returned without reading another packet,
so playback ended after the buffered two seconds.

Remove the gate and its constant.  At EOF, do not call joc_stream_flush()
while a large PCM backlog is still queued.  Instead push one frame of
silence at a time, compare joc_stream_status().samples_in with the actual
input duration, and only flush after the queued PCM has been rendered.
emit() still truncates output at pcm_input_samples, so the drain silence
never reaches the listener.  This restores full-length playback and avoids
rendering the whole EOF backlog in one operation.
2026-11-14 03:06:11 +08:00
TheM14 587ff24e86 Fix native PCM startup stall at the queue gate
The PCM queue cap was applied before the first output sample.  For any
input longer than about two seconds the gate could trigger while
samples_out was still zero, emit() had nothing to return, and process_pcm
returned without marking filter progress.  The decoder thread then stopped
and audio never became ready; short clips and E-AC-3 JOC were unaffected.

Only apply the cap after the first output sample, and mark progress when
the gate cannot emit.  This keeps the EOF flush bounded without blocking
startup.
2026-11-14 02:53:36 +08:00
TheM14 e5954169b2 Sign Android APKs with a fixed repository keystore
The Android workflow generated a new throwaway keystore on every run, so
every APK had a different signature and Android refused to install it over
the previous build.

Load the release keystore from ANDROID_KEYSTORE_BASE64, validate it with
keytool, and sign assembleRelease with the PKCS12 store type plus
ANDROID_KEYSTORE_PASSWORD, ANDROID_KEY_ALIAS and ANDROID_KEY_PASSWORD.
Fail the build when any secret is missing instead of falling back to a
random key, and remove the temporary keystore afterwards.

Document the one-time keystore and secret setup, and ignore *.jks and
*.keystore so private keys cannot be committed.

The first fixed-signature APK needs one uninstall because the installed APK
was signed by the old throwaway key; later builds install as updates.
2026-11-13 18:21:41 +08:00
TheM14 11b353e9b1 Bound native PCM lookahead and clear EOF state on seek
The PCM path decoded and pushed samples into joc_core without any
backpressure.  The kernel's rendered-output queue is bounded, but its
input queue is not, so a large part of the track could pile up and
joc_stream_flush() at EOF rendered all of it in one call, causing the
stall near the end of playback.

Keep at most 96000 samples (2 seconds at 48 kHz) between the samples
pushed into the renderer and the samples already handed to mpv.  When
that limit is reached, drain output and wait instead of decoding another
packet.  The flush at EOF then only has a short queue to process.

Also clear eof_pending/eof_frame and the PCM decoder's in-flight
frame/packet in ad_joc_reset().  Near the end of a track the demuxer may
already have delivered EOF; seeking back left the stale EOF state in
place, and the next process call wrote EOF immediately, closing the
track.

E-AC-3 JOC and the ad-joc-pcm=no path are unchanged.
2026-11-13 17:49:38 +08:00
TheM14 7bab2c0c3c Route ad-joc-pcm inputs to ad_joc
The generated f_decoder_wrapper patch only switched to ad_joc when the
codec was E-AC-3. ad-joc-pcm=yes was read by the decoder but never had any
effect, because PCM/FLAC/TrueHD inputs still went to the default lavc
decoder.

Read ad_joc_params through mp_get_config_group(ad_joc_conf) and include
audio/decode/ad_joc.h in f_decoder_wrapper.c. Accessing p->opts for this
was wrong: p->opts is dec_wrapper_opts, not the global MPOpts, and the
build failed with "struct dec_wrapper_opts has no member named
ad_joc_params".

With this change, ad-joc-pcm=yes routes non-E-AC-3 codecs into ad_joc;
with no or the option absent, PCM is released to the default decoder.
E-AC-3 JOC is unchanged.

Rebuild mpv after this change; existing binaries still contain the old
eac3-only routing.
2026-11-13 15:55:59 +08:00
TheM14 9f698ad694 Route ad-joc-pcm inputs to ad_joc
The generated f_decoder_wrapper patch only switched to ad_joc when the
codec was E-AC-3.  ad-joc-pcm=yes was read by the decoder but never had
any effect, because PCM/FLAC/TrueHD inputs were still handed to the
default lavc decoder.

Extend the wrapper condition to select ad_joc for non-E-AC-3 codecs when
ad_joc_params->pcm is enabled.  With ad-joc-pcm=no (or the option absent)
those inputs continue through the default decoder.  The E-AC-3 JOC path
is unchanged.

Include audio/decode/ad_joc.h in f_decoder_wrapper.c so the generated
code can access ad_joc_params->pcm; options.h only forward-declares the
struct.  Rebuild mpv after this change; existing binaries still contain
the old eac3-only routing.
2026-11-13 15:31:31 +08:00
TheM14 66359ff089 Add native ad-joc-pcm takeover with libswresample
- Add ad-joc-pcm (default no). With it disabled, non-E-AC-3 audio is handed
  directly to ad_lavc and the native component does not take PCM over.
- With ad-joc-pcm=yes, decode registered PCM/compressed codecs with
  libavcodec, convert to 48 kHz interleaved float32 through libswresample,
  and feed joc_core's JOC_STREAM_IN_PCM_LAYOUT path.
- Register common codecs (FLAC, MP3, AAC, AC3, TrueHD, DTS, ALAC, Vorbis,
  Opus, WavPack, APE, TTA, MPC and PCM variants) so ad=joc can select the
  native path for them.
- Keep the existing E-AC-3 JOC path unchanged; ad-joc-pcm only affects
  non-E-AC-3 inputs.
- Document the option in fork/mpv.conf.example and fork/README.md.
2026-11-13 14:23:35 +08:00
TheM14 87b850fd2f Sync the native ad_joc stream header to the 1.3.3 kernel
The native decoder is compiled against fork/files/audio/decode/joc_stream.h,
but the workflow builds joc_core from the current JustOneCacophony main
branch. Version 1.3.3 appended pcm_layout to joc_stream_config; the stale
1.3.1 header made struct_size disagree with the core, so joc_stream_create()
failed and every E-AC-3 JOC file stopped initializing.

Sync the header with include/joc_stream.h, including
JOC_STREAM_IN_PCM_LAYOUT and the pcm_layout field, so the native decoder
matches the 1.3.3 core ABI.

This only restores the existing JOC path; ad-joc-pcm is not implemented yet.
2026-11-13 13:50:54 +08:00
TheM14 5fab3feac5 Update the kernel version to 1.3.1
Both copies of joc_version.h follow the main repository: third_party/joc/
include for the cplugin and fork/files/audio/decode for the ad_joc patch now
carry JOC_VERSION_STRING 1.3.1.  joc_core.h and joc_stream.h are unchanged, so
the public ABI stays at 6 and neither integration needs a code change.  The
kernel behaviour behind the version (a mid-stream frame without JOC metadata
holds the previous matrices instead of switching to the core planes) reaches
the builds through the main branch they compile against.

tools/verify_kernel.ps1 reports all three headers byte-identical to the 1.3.1
checkout.
2026-11-10 15:40:14 +08:00
TheM14 27aa8881f4 Update the kernel headers to 1.3.0
Both copies of the three public headers follow the main repository:
third_party/joc/include for the cplugin and fork/files/audio/decode for the
ad_joc patch now carry joc_core.h, joc_stream.h and joc_version.h from
JustOneCacophonyCXX abce846 (version 1.3.0).  The fix behind them turns an
ID14 payload that ends inside joc_data into a frame status (7) instead of a
stream error, so the renderer holds the previous matrices and playback
continues; joc_stream_status_info gains an appended truncated_joc_frames
field while JOC_ABI_VERSION stays at 6, so neither integration needs a code
change.

tools/verify_kernel.ps1 reports all three headers byte-identical to the
checkout.  tools/build.ps1 -JocCoreSource compiles joc_mpv.dll against the
synced headers and builds joc_core.dll from the fixed source; with that core
next to the portable mpv build, --ad=joc plays the reported M4A to the end
instead of stopping at 2:12.672.
2026-11-10 00:18:07 +08:00
TheM14 0d8ccbf5cd Update the kernel header to ABI 6
Both copies of joc_core.h follow the main repository: third_party/joc/include
for the cplugin and fork/files/audio/decode for the ad_joc patch now carry
JOC_ABI_VERSION 6, frame parameters and EMDF payload info at v2, the
JOC_FRAME_STATUS_* values and the calling convention chosen per platform.
joc_stream.h and joc_version.h are unchanged, so neither integration needs a
code change.

The plugin compares the loaded core's abi_version() with JOC_ABI_VERSION at
load time, so the vendored header has to match the new joc_core.dll.

Rebuilt against commit 3f0d5e87fe41b90d9350528d2dca2ca82a637a3f with
-DJOC_CORE_SOURCE: joc_mpv.dll and joc_core.dll build, the plugin compiles
against ABI 6, and the built joc_core.dll reports abi 6 / version 1.2.0.
2026-11-08 16:13:09 +08:00
TheM14 2a60931875 Update the kernel headers to 1.2.0
Both copies of joc_version.h follow the main repository: third_party/joc/
include for the cplugin and fork/files/audio/decode for the ad_joc patch
now carry JOC_VERSION_STRING 1.2.0. joc_core.h and joc_stream.h are
unchanged, so the public ABI stays at 5 and neither integration needs a
code change.

Rebuilt joc_core.dll from the 1.2.0 kernel with tools/build.ps1;
tools/verify_kernel.ps1 reports all three headers byte-identical, and
joc_cli.exe --version reports 1.2.0 (joc_core ABI 5). The warp and trim
behaviour arrives through the unchanged joc_stream surface.
2026-11-03 01:35:28 +08:00
TheM14 f555235f2b Remove the cache lines the decoder was left with
The previous change dropped the SOFA input but left two lines of the old disk
cache block inside create(): the stream config was still assigned
hrtf_cache_policy, which the kernel no longer has, and the brace that closed the
block ended the binaural branch early. Both compilers stopped there, so the
Windows and the Android build agreed on the error.

The frame-length message in feed() is a size_t and uses %zu now, which the same
build reported as a warning.
2026-11-01 20:04:34 +08:00
TheM14 a2471ce502 Compile the fork decoder against the kernel that takes one HRTF input
ad_joc.c still asked the stream config for hrtf_sofa_path, hrtf_cache_dir and
hrtf_cache_policy, which the kernel no longer has; the same file is compiled by
the Windows and the Android build, so both stopped there.

The decoder now recognises only the Rosella model -- a JSON file containing a
personalized_hrtf object -- and passes its path to personalized_headphone_path.
The SOFA magic sniffing, the .jochrtf extension branch, the default cache
directory and the disk-cache retry path are gone, the default lookup is
HRTF/binaural.personalized_headphone, and the format warning for the frame length
uses %zu. The README, the fork docs and the example configs name the model file
instead of binaural.sofa.
2026-11-01 19:59:08 +08:00
TheM14 19b4a49407 Drop the HRTF source and cache options
The kernel renders the Rosella .personalized_headphone model or an already
compiled .jochrtf field, and only the first is a user-facing input: the SOFA
reader and its compile cache left the library. joc-hrtf-source, joc-hrtf-cache
and joc-hrtf-cache-dir go with them, and the default file is now
binaural.personalized_headphone only.

The plugin sets personalized_headphone_path directly, and the disk-cache retry
path disappears with the cache itself. The headers in third_party/joc/include
and fork/files/audio/decode follow the new kernel, so the config structs no
longer carry hrtf_sofa_path, hrtf_cache_policy, hrtf_cache_dir or hrtf_radius_m,
and the rosella filterbank no longer needs its SOFA exception.

The example config and the option tables in both READMEs drop the removed keys.
Builds against the kernel with tools/build.ps1 -JocCoreSource.
2026-11-01 19:38:41 +08:00
TheM14 5ddbd6154b Build the JNI bridge for the Android app
The app's MPVLib loads libplayer.so before libmpv, and mpv-android builds
that bridge with ndk-build over app/src/main/jni, installing it and the
prebuilt ffmpeg/mpv objects into app/src/main/libs/<abi>. The workflow
only built the mpv target and then ran Gradle, so the APK shipped
without libplayer.so and every playback died with UnsatisfiedLinkError.

Run ndk-build the way buildscripts/scripts/mpv-android.sh does, and write
ndk.properties, which the Gradle build needs to find the NDK for symbol
stripping (the previous APK carried 134 MB of unstripped libraries).
2026-10-31 03:52:57 +08:00
TheM14 8673a3b762 Package the ffmpeg shared libraries the Android build links against
The Android libmpv.so has DT_NEEDED entries for libavcodec, libavfilter,
libavformat, libavutil, libswresample, libswscale and libavdevice, but
the app only carried libmpv.so, libjoc_core.so and libc++_shared.so, so
the linker rejected libmpv at dlopen time and the player crashed on
every file.

Copy every shared object from the cross-build prefix into the app's
libs/<abi> directory, and into the standalone library artifact too,
instead of naming the three files.
2026-10-31 03:33:27 +08:00
TheM14 c45808135d Package the Android build as an installable APK
The arm64 job stopped at the three shared libraries, so the only way to
use them was to build a player around them. Let the libraries go into
mpv-android's jniLibs and let Gradle assemble and sign the app instead.

- copy libmpv.so, libjoc_core.so and libc++_shared.so into
  app/src/main/jniLibs/arm64-v8a
- locate the SDK under buildscripts/sdk, accept its licences, and link
  the unpacked NDK where AGP looks for it
- run assembleRelease with a throwaway injected signing key, so the APK
  installs without repository secrets
- verify the signature when apksigner is available and upload the APK as
  mpv-joc-android-arm64-v8a-apk, keeping the bare libraries as before
- cache the Gradle home between runs
- document the artifact and how to pass the ad_joc options

Checked locally: the workflow parses and every shell block passes
bash -n; the Gradle build itself needs a CI run.
2026-10-31 02:47:40 +08:00
TheM14 ecf14d8c32 Sync the Rosella filterbank choice into the plugin and the fork
The kernel can now render the Rosella path through either bank; expose
that choice in both front ends with the same values and the same
default.

- plugin: joc-rosella-filterbank = 1|2 (public|captured); unset means
  the kernel default (the public bank), and it applies only to
  joc-hrtf-source=rosella, logging a warning otherwise
- fork: --ad-joc-rosella-filterbank, the same values and default; it
  sits in the ad_joc option group, so it is read only when ad_joc
  decodes a Rosella model
- log the bank actually selected (public|captured) on both paths
- add a bank-2 case to tools/verify_parity.ps1
- document the key in both READMEs and the example config

Checked: the plugin builds, the option parser covers the numeric and
named spellings plus invalid values, and for both banks the plugin's
PCM is bit-identical to joc_cli with --rosella-filterbank 1|2.
2026-10-31 02:29:23 +08:00
TheM14 a9cbffa1cf Synchronize the kernel headers with the upstream repository
The kernel replaced the reserved words with rosella_filterbank and
bumped the task config version to 4; joc_task_config and
joc_stream_config keep their sizes, so the ABI stays compatible.

- Update third_party/joc/include/joc_core.h and joc_stream.h
- Update the copies ad_joc compiles against in
  fork/files/audio/decode/

tools/verify_kernel.ps1 reports the public headers byte-identical to
the upstream checkout.
2026-10-31 02:29:01 +08:00
TheM14 c22fa692f8 Synchronize the kernel version headers with the upstream repository 2026-10-30 04:21:17 +08:00
TheM14 78f2c4b4bd Serve the renderer's channel order without touching the player's layout 2026-10-29 01:09:55 +08:00
TheM14 95c4626abd Build the Windows fork in UCRT64, where LuaJIT is still published 2026-10-28 00:31:28 +08:00
TheM14 7d013fef46 Support the two 4.0 layouts in the plugin and the fork 2026-10-27 23:52:43 +08:00
TheM14 126e2cd233 Init mpv-joc 2026-10-18 21:31:38 +08:00