Skip to content

Fix JavaScript video codec discovery and round trip#5415

Merged
shai-almog merged 5 commits into
masterfrom
fix-javascript-videoio-codec-discovery
Jul 19, 2026
Merged

Fix JavaScript video codec discovery and round trip#5415
shai-almog merged 5 commits into
masterfrom
fix-javascript-videoio-codec-discovery

Conversation

@shai-almog

@shai-almog shai-almog commented Jul 19, 2026

Copy link
Copy Markdown
Collaborator

What changed

  • Probe real WebCodecs encoder output before advertising H.264, VP8, VP9, AAC, or Opus; cache successful capability probes for the page lifetime.
  • Carry the asynchronous capability checks through the ParparVM worker/host bridge.
  • Select a container-compatible video/audio pair in VideoIORoundTripTest instead of selecting video and audio independently.
  • Reject incompatible JavaScript writer requests explicitly (for example, Opus in MP4) instead of silently substituting a different codec.
  • Preserve the failing encoder stage in diagnostics so video, audio, muxer, and flush failures are distinguishable.

Root cause

Linux Chromium supports VP8/VP9 plus Opus but not the AAC configuration used by the HTML5 writer. The test preferred H.264 for MP4, then independently selected the available Opus encoder. The JavaScript writer ignored that requested Opus codec and silently attempted AAC because the container was MP4. Chromium correctly rejected AAC, and the test reported an encode-unavailable skip.

The test now prefers complete compatible pairs (H.264/AAC for MP4, then VP8/Opus or VP9/Opus for WebM) and falls back to video-only only when no compatible audio encoder exists. The writer now rejects mismatched container/codec requests rather than changing codecs behind the caller's back.

Validation

@github-actions

github-actions Bot commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

✅ ByteCodeTranslator Quality Report

Test & Coverage

  • Tests: 405 total, 0 failed, 14 skipped

Benchmark Results

  • Execution Time: 20398 ms

  • Hotspots (Top 20 sampled methods):

    • 25.75% java.util.ArrayList.indexOf (479 samples)
    • 9.95% com.codename1.tools.translator.BytecodeMethod.addToConstantPool (185 samples)
    • 3.28% java.lang.StringBuilder.append (61 samples)
    • 2.85% com.codename1.tools.translator.ByteCodeClass.hasDeclaredMethod (53 samples)
    • 2.58% org.objectweb.asm.tree.analysis.Analyzer.analyze (48 samples)
    • 2.20% org.objectweb.asm.tree.analysis.Analyzer.findSubroutine (41 samples)
    • 2.10% com.codename1.tools.translator.Parser.cn1EnsureSubclassIndex (39 samples)
    • 2.04% java.util.HashMap.hash (38 samples)
    • 1.61% com.codename1.tools.translator.Parser.generateClassAndMethodIndexHeader (30 samples)
    • 1.40% java.lang.System.identityHashCode (26 samples)
    • 1.40% com.codename1.tools.translator.bytecodes.Invoke.resolveDirectTarget (26 samples)
    • 1.13% com.codename1.tools.translator.MethodDependencyGraph.getCallers (21 samples)
    • 1.13% com.codename1.tools.translator.BytecodeMethod.optimize (21 samples)
    • 0.97% com.codename1.tools.translator.Parser.resolveDupForms (18 samples)
    • 0.97% org.objectweb.asm.ClassReader.readCode (18 samples)
    • 0.91% java.lang.String.equals (17 samples)
    • 0.91% sun.nio.fs.UnixNativeDispatcher.open0 (17 samples)
    • 0.86% java.util.TreeMap.getEntry (16 samples)
    • 0.86% com.codename1.tools.translator.Parser.classIndex (16 samples)
    • 0.86% java.util.HashMap.putVal (16 samples)
  • ⚠️ Coverage report not generated.

Static Analysis

  • ✅ SpotBugs: no findings (report was not generated by the build).
  • ⚠️ PMD report not generated.
  • ⚠️ Checkstyle report not generated.

Generated automatically by the PR CI workflow.

@github-actions

github-actions Bot commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

✅ Continuous Quality Report

Test & Coverage

Static Analysis

  • SpotBugs [Report archive]
    • ByteCodeTranslator: 0 findings (no issues)
    • android: 0 findings (no issues)
    • codenameone-maven-plugin: 0 findings (no issues)
    • core-unittests: 0 findings (no issues)
    • ios: 0 findings (no issues)
  • PMD: 0 findings (no issues) [Report archive]
  • Checkstyle: 0 findings (no issues) [Report archive]

Generated automatically by the PR CI workflow.

@github-actions

Copy link
Copy Markdown
Contributor

Cloudflare Preview

@shai-almog

shai-almog commented Jul 19, 2026

Copy link
Copy Markdown
Collaborator Author

Compared 146 screenshots: 146 matched.
Native Windows port (x64 / Intel-AMD): full hellocodenameone screenshot suite rendered offscreen with Direct2D/DirectWrite, plus the real benchmarks (base64 native/CN1/SIMD, image createMask/applyMask/modifyAlpha/PNG/JPEG, SSE2 SIMD kernels). Compared against the in-repo baseline in scripts/windows/screenshots.

Benchmark Results

Detailed Performance Metrics

Metric Duration
SIMD kernel backend SSE2 (x64) / NEON (arm64) native kernels
SIMD int-add (64K x300) java 90ms / native 7ms = 12.8x speedup
SIMD float-mul (64K x300) java 86ms / native 4ms = 21.5x speedup
SIMD kernel correctness PASS (native result == scalar reference)

@shai-almog

shai-almog commented Jul 19, 2026

Copy link
Copy Markdown
Collaborator Author

Compared 146 screenshots: 146 matched.
Native Windows port, REAL shipping pipeline: the hellocodenameone screenshot suite rendered by a binary CROSS-COMPILED on Linux (clang-cl + xwin, WebView2 linked) and RUN on a Windows x64 runner. Compared against the in-repo baseline in scripts/windows/screenshots.

Benchmark Results

Detailed Performance Metrics

Metric Duration
SIMD kernel backend SSE2 (x64) / NEON (arm64) native kernels
SIMD int-add (64K x300) java 63ms / native 4ms = 15.7x speedup
SIMD float-mul (64K x300) java 62ms / native 4ms = 15.5x speedup
SIMD kernel correctness PASS (native result == scalar reference)

@shai-almog

shai-almog commented Jul 19, 2026

Copy link
Copy Markdown
Collaborator Author

Compared 147 screenshots: 147 matched.
Native Linux port (x64), GTK3/Cairo/Pango, ParparVM bytecode-to-C (no JVM): the hellocodenameone screenshot suite rendered by a native ELF built + run on the GitHub x64 runner. Baseline: scripts/linux/screenshots.

@shai-almog

shai-almog commented Jul 19, 2026

Copy link
Copy Markdown
Collaborator Author

Compared 147 screenshots: 147 matched.
Native Linux port (arm64), GTK3/Cairo/Pango, ParparVM bytecode-to-C (no JVM): the hellocodenameone screenshot suite rendered by a native ELF built + run on the GitHub arm64 runner. Baseline: scripts/linux/screenshots-arm.

@shai-almog

shai-almog commented Jul 19, 2026

Copy link
Copy Markdown
Collaborator Author

Compared 181 screenshots: 181 matched.
✅ JavaScript-port screenshot tests passed.

@shai-almog

shai-almog commented Jul 19, 2026

Copy link
Copy Markdown
Collaborator Author

Compared 146 screenshots: 146 matched.
Native Windows port (arm64 / Apple Silicon - Arm): full hellocodenameone screenshot suite rendered offscreen with Direct2D/DirectWrite, plus the real benchmarks (base64 native/CN1/SIMD, image createMask/applyMask/modifyAlpha/PNG/JPEG, NEON SIMD kernels). Compared against the in-repo baseline in scripts/windows/screenshots.

Benchmark Results

Detailed Performance Metrics

Metric Duration
SIMD kernel backend SSE2 (x64) / NEON (arm64) native kernels
SIMD int-add (64K x300) java 55ms / native 3ms = 18.3x speedup
SIMD float-mul (64K x300) java 56ms / native 3ms = 18.6x speedup
SIMD kernel correctness PASS (native result == scalar reference)

@shai-almog

shai-almog commented Jul 19, 2026

Copy link
Copy Markdown
Collaborator Author

Compared 217 screenshots: 217 matched.
✅ Native Apple Watch (watchOS, Core Graphics) screenshot tests passed.

@shai-almog

shai-almog commented Jul 19, 2026

Copy link
Copy Markdown
Collaborator Author

Compared 143 screenshots: 143 matched.
✅ Native iOS screenshot tests passed.

Benchmark Results

  • VM Translation Time: 0 seconds
  • Compilation Time: 500 seconds

Build and Run Timing

Metric Duration
Simulator Boot 73000 ms
Simulator Boot (Run) 1000 ms
App Install 15000 ms
App Launch 6000 ms
Test Execution 953000 ms

Detailed Performance Metrics

Metric Duration
SIMD kernel backend SSE2 (x64) / NEON (arm64) native kernels
SIMD int-add (64K x300) java 258ms / native 4ms = 64.5x speedup
SIMD float-mul (64K x300) java 78ms / native 3ms = 26.0x speedup
SIMD kernel correctness PASS (native result == scalar reference)
Base64 payload size 8192 bytes
Base64 benchmark iterations 6000
Base64 SIMD byte path active (NEON-accelerated)
Base64 CN1 encode 170.000 ms
Base64 CN1 decode 124.000 ms
Base64 native encode 570.000 ms
Base64 encode ratio (CN1/native) 0.298x (70.2% faster)
Base64 native decode 356.000 ms
Base64 decode ratio (CN1/native) 0.348x (65.2% faster)
Base64 SIMD encode 55.000 ms
Base64 encode ratio (SIMD/CN1) 0.324x (67.6% faster)
Base64 SIMD decode 52.000 ms
Base64 decode ratio (SIMD/CN1) 0.419x (58.1% faster)
Base64 encode ratio (SIMD/native) 0.096x (90.4% faster)
Base64 decode ratio (SIMD/native) 0.146x (85.4% faster)
Image encode benchmark iterations 100
Image createMask (SIMD off) 9.000 ms
Image createMask (SIMD on) 5.000 ms
Image createMask ratio (SIMD on/off) 0.556x (44.4% faster)
Image applyMask (SIMD off) 75.000 ms
Image applyMask (SIMD on) 48.000 ms
Image applyMask ratio (SIMD on/off) 0.640x (36.0% faster)
Image modifyAlpha (SIMD off) 61.000 ms
Image modifyAlpha (SIMD on) 83.000 ms
Image modifyAlpha ratio (SIMD on/off) 1.361x (36.1% slower)
Image modifyAlpha removeColor (SIMD off) 46.000 ms
Image modifyAlpha removeColor (SIMD on) 46.000 ms
Image modifyAlpha removeColor ratio (SIMD on/off) 1.000x (0.0% slower)

@shai-almog

shai-almog commented Jul 19, 2026

Copy link
Copy Markdown
Collaborator Author

Compared 149 screenshots: 149 matched.
✅ Native iOS Metal screenshot tests passed.

Benchmark Results

  • VM Translation Time: 0 seconds
  • Compilation Time: 309 seconds

Build and Run Timing

Metric Duration
Simulator Boot 57000 ms
Simulator Boot (Run) 0 ms
App Install 10000 ms
App Launch 8000 ms
Test Execution 647000 ms

Detailed Performance Metrics

Metric Duration
SIMD kernel backend SSE2 (x64) / NEON (arm64) native kernels
SIMD int-add (64K x300) java 54ms / native 3ms = 18.0x speedup
SIMD float-mul (64K x300) java 57ms / native 3ms = 19.0x speedup
SIMD kernel correctness PASS (native result == scalar reference)
Base64 payload size 8192 bytes
Base64 benchmark iterations 6000
Base64 SIMD byte path active (NEON-accelerated)
Base64 CN1 encode 172.000 ms
Base64 CN1 decode 120.000 ms
Base64 native encode 284.000 ms
Base64 encode ratio (CN1/native) 0.606x (39.4% faster)
Base64 native decode 205.000 ms
Base64 decode ratio (CN1/native) 0.585x (41.5% faster)
Base64 SIMD encode 52.000 ms
Base64 encode ratio (SIMD/CN1) 0.302x (69.8% faster)
Base64 SIMD decode 46.000 ms
Base64 decode ratio (SIMD/CN1) 0.383x (61.7% faster)
Base64 encode ratio (SIMD/native) 0.183x (81.7% faster)
Base64 decode ratio (SIMD/native) 0.224x (77.6% faster)
Image encode benchmark iterations 100
Image createMask (SIMD off) 7.000 ms
Image createMask (SIMD on) 1.000 ms
Image createMask ratio (SIMD on/off) 0.143x (85.7% faster)
Image applyMask (SIMD off) 42.000 ms
Image applyMask (SIMD on) 51.000 ms
Image applyMask ratio (SIMD on/off) 1.214x (21.4% slower)
Image modifyAlpha (SIMD off) 35.000 ms
Image modifyAlpha (SIMD on) 35.000 ms
Image modifyAlpha ratio (SIMD on/off) 1.000x (0.0% slower)
Image modifyAlpha removeColor (SIMD off) 36.000 ms
Image modifyAlpha removeColor (SIMD on) 32.000 ms
Image modifyAlpha removeColor ratio (SIMD on/off) 0.889x (11.1% faster)

@shai-almog

shai-almog commented Jul 19, 2026

Copy link
Copy Markdown
Collaborator Author

Compared 148 screenshots: 148 matched.
✅ Native Mac screenshot tests passed.

Benchmark Results

  • VM Translation Time: 0 seconds
  • Compilation Time: 197 seconds

Detailed Performance Metrics

Metric Duration
SIMD kernel backend SSE2 (x64) / NEON (arm64) native kernels
SIMD int-add (64K x300) java 57ms / native 4ms = 14.2x speedup
SIMD float-mul (64K x300) java 58ms / native 3ms = 19.3x speedup
SIMD kernel correctness PASS (native result == scalar reference)
Base64 payload size 8192 bytes
Base64 benchmark iterations 6000
Base64 SIMD byte path active (NEON-accelerated)
Base64 CN1 encode 170.000 ms
Base64 CN1 decode 123.000 ms
Base64 native encode 686.000 ms
Base64 encode ratio (CN1/native) 0.248x (75.2% faster)
Base64 native decode 343.000 ms
Base64 decode ratio (CN1/native) 0.359x (64.1% faster)
Base64 SIMD encode 47.000 ms
Base64 encode ratio (SIMD/CN1) 0.276x (72.4% faster)
Base64 SIMD decode 44.000 ms
Base64 decode ratio (SIMD/CN1) 0.358x (64.2% faster)
Base64 encode ratio (SIMD/native) 0.069x (93.1% faster)
Base64 decode ratio (SIMD/native) 0.128x (87.2% faster)
Image encode benchmark iterations 100
Image createMask (SIMD off) 12.000 ms
Image createMask (SIMD on) 4.000 ms
Image createMask ratio (SIMD on/off) 0.333x (66.7% faster)
Image applyMask (SIMD off) 85.000 ms
Image applyMask (SIMD on) 71.000 ms
Image applyMask ratio (SIMD on/off) 0.835x (16.5% faster)
Image modifyAlpha (SIMD off) 41.000 ms
Image modifyAlpha (SIMD on) 35.000 ms
Image modifyAlpha ratio (SIMD on/off) 0.854x (14.6% faster)
Image modifyAlpha removeColor (SIMD off) 36.000 ms
Image modifyAlpha removeColor (SIMD on) 34.000 ms
Image modifyAlpha removeColor ratio (SIMD on/off) 0.944x (5.6% faster)

@shai-almog

shai-almog commented Jul 19, 2026

Copy link
Copy Markdown
Collaborator Author

Compared 144 screenshots: 144 matched.
✅ Native Apple TV (tvOS, Metal) screenshot tests passed.

@shai-almog

shai-almog commented Jul 19, 2026

Copy link
Copy Markdown
Collaborator Author

Compared 151 screenshots: 151 matched.

Native Android coverage

  • 📊 Line coverage: 11.44% (12044/105236 lines covered) [HTML preview] (artifact android-coverage-report, jacocoAndroidReport/html/index.html)
    • Other counters: instruction 10.25% (59657/582251), branch 5.31% (2825/53225), complexity 5.06% (2820/55772), method 7.55% (2166/28678), class 11.96% (489/4088)
    • Lowest covered classes
      • kotlin.collections.kotlin.collections.ArraysKt___ArraysKt – 0.00% (0/6327 lines covered)
      • kotlin.collections.unsigned.kotlin.collections.unsigned.UArraysKt___UArraysKt – 0.00% (0/2384 lines covered)
      • org.jacoco.agent.rt.internal_b6258fc.asm.org.jacoco.agent.rt.internal_b6258fc.asm.ClassReader – 0.00% (0/1519 lines covered)
      • kotlin.collections.kotlin.collections.CollectionsKt___CollectionsKt – 0.00% (0/1148 lines covered)
      • org.jacoco.agent.rt.internal_b6258fc.asm.org.jacoco.agent.rt.internal_b6258fc.asm.MethodWriter – 0.00% (0/923 lines covered)
      • kotlin.sequences.kotlin.sequences.SequencesKt___SequencesKt – 0.00% (0/730 lines covered)
      • com.google.common.cache.com.google.common.cache.LocalCache$Segment – 0.00% (0/726 lines covered)
      • kotlin.text.kotlin.text.StringsKt___StringsKt – 0.00% (0/623 lines covered)
      • org.jacoco.agent.rt.internal_b6258fc.asm.org.jacoco.agent.rt.internal_b6258fc.asm.Frame – 0.00% (0/564 lines covered)
      • kotlin.collections.kotlin.collections.ArraysKt___ArraysJvmKt – 0.00% (0/495 lines covered)

✅ Native Android screenshot tests passed.

Native Android coverage

  • 📊 Line coverage: 11.44% (12044/105236 lines covered) [HTML preview] (artifact android-coverage-report, jacocoAndroidReport/html/index.html)
    • Other counters: instruction 10.25% (59657/582251), branch 5.31% (2825/53225), complexity 5.06% (2820/55772), method 7.55% (2166/28678), class 11.96% (489/4088)
    • Lowest covered classes
      • kotlin.collections.kotlin.collections.ArraysKt___ArraysKt – 0.00% (0/6327 lines covered)
      • kotlin.collections.unsigned.kotlin.collections.unsigned.UArraysKt___UArraysKt – 0.00% (0/2384 lines covered)
      • org.jacoco.agent.rt.internal_b6258fc.asm.org.jacoco.agent.rt.internal_b6258fc.asm.ClassReader – 0.00% (0/1519 lines covered)
      • kotlin.collections.kotlin.collections.CollectionsKt___CollectionsKt – 0.00% (0/1148 lines covered)
      • org.jacoco.agent.rt.internal_b6258fc.asm.org.jacoco.agent.rt.internal_b6258fc.asm.MethodWriter – 0.00% (0/923 lines covered)
      • kotlin.sequences.kotlin.sequences.SequencesKt___SequencesKt – 0.00% (0/730 lines covered)
      • com.google.common.cache.com.google.common.cache.LocalCache$Segment – 0.00% (0/726 lines covered)
      • kotlin.text.kotlin.text.StringsKt___StringsKt – 0.00% (0/623 lines covered)
      • org.jacoco.agent.rt.internal_b6258fc.asm.org.jacoco.agent.rt.internal_b6258fc.asm.Frame – 0.00% (0/564 lines covered)
      • kotlin.collections.kotlin.collections.ArraysKt___ArraysJvmKt – 0.00% (0/495 lines covered)

Benchmark Results

Detailed Performance Metrics

Metric Duration
SIMD kernel backend scalar fallback (no native SIMD)
SIMD int-add (64K x300) java 139ms / native 57ms = 2.4x speedup
SIMD float-mul (64K x300) java 90ms / native 44ms = 2.0x speedup
SIMD kernel correctness PASS (native result == scalar reference)
Base64 payload size 8192 bytes
Base64 benchmark iterations 6000
Base64 SIMD byte path gated to scalar (CPU autovectorizes scalar; explicit SIMD not beneficial here)
Base64 CN1 encode 60.000 ms
Base64 CN1 decode 68.000 ms
Base64 native encode 280.000 ms
Base64 encode ratio (CN1/native) 0.214x (78.6% faster)
Base64 native decode 249.000 ms
Base64 decode ratio (CN1/native) 0.273x (72.7% faster)
Image encode benchmark status skipped (SIMD unsupported)

@shai-almog shai-almog changed the title Probe JavaScript video encoder capabilities Fix JavaScript video codec discovery and round trip Jul 19, 2026
@shai-almog
shai-almog merged commit 2bec305 into master Jul 19, 2026
51 checks passed
@shai-almog
shai-almog deleted the fix-javascript-videoio-codec-discovery branch July 19, 2026 14:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant