Skip to content

NAT-547: Add cancellable Media3 SDR conversion adapter - #170

Merged
eugene-mux merged 10 commits into
feature/nat-534-hevc-standard-ingestfrom
em/nat-547-sdr-conversion
Oct 22, 2026
Merged

eugene-mux merged 10 commits into
feature/nat-534-hevc-standard-ingestfrom
em/nat-547-sdr-conversion

Conversation

@eugene-mux

@eugene-mux eugene-mux commented Oct 7, 2026 •

Copy link
Copy Markdown

Description

Add a cancellable Media3 adapter for whole-file SDR conversion. Generated files preserve the planned codec family and dimensions and must pass output validation before they can be selected for upload.

Changes

  • Use coroutines for dispatch and cancellation, with a cancellable continuation for Media3 callbacks.
  • Pin encoder profile, bitrate and keyframe settings, and reject automatic encoder or format fallback.
  • Preserve VFR timestamps and choose keyframe intervals from actual frame windows.
  • Select the first audio track, copy eligible AAC, and preserve mono/stereo channels and sample rate when encoding other audio.
  • Keep capability queries bounded and validate exported codec, profile, audio and timeline.
  • Clean SDK-owned partial files on failure or cancellation and suppress late callbacks.

Validation

  • 200 library tests pass in each debug/release variant on JDK 17.
  • SDK and sample release builds, lint-vital and whitespace checks pass.
  • Earlier external, manual emulator checks covered SDR exports, audio selection and cancellation; these historical runs are not reproducible from the repository.
  • Physical-device and Mux ingest acceptance remain pending.

Note

Medium Risk
New on-device transcode path touches MediaCodec/Media3 export, file lifecycle, and strict codec contracts; failures are gated by validation but bugs could reject valid inputs or leak partial files.

Overview
Adds a cancellable Media3 SDR conversion path for standard-input uploads: SdrConversionAdapter runs preflight, disk allocation, export, and shared output validation on coroutines, delivers a single terminal SdrConversionResult, and deletes or retains partial outputs via SdrGeneratedFile when cleanup fails.

Encoding is intentionally strict. SdrEncodingTargets derives H.264/HEVC bitrate, GOP, and audio plans (including VFR keyframe windows from real presentation timestamps) and rejects HDR, linear transfer, upscaling, and other unproven plans. SdrCapabilityPreflight bounds codec capability queries; Media3SdrExportEngine drives Transformer with no encoder fallback, pinned profiles via StrictSdrEncoderFactory, container-first audio via FirstAudioTrackSelector, and failures on muxer errors or Media3 transformation fallback.

Robolectric tests cover GOP math, adapter lifecycle/cancellation, and Media3 configuration edge cases (device/SOC encoder hints, query budgets).

Reviewed by Cursor Bugbot for commit fff4029. Bugbot is set up for automated code reviews on this repo. Configure here.

@eugene-mux
eugene-mux marked this pull request as ready for review October 7, 2026 22:44
@eugene-mux
eugene-mux requested a review from a team as a code owner October 7, 2026 22:44
@eugene-mux
eugene-mux requested a review from daytime-em October 7, 2026 22:44
@eugene-mux
eugene-mux added this pull request to stack #166 October 7, 2026 22:44

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

@eugene-mux
eugene-mux force-pushed the em/nat-547-sdr-conversion branch 2 times, most recently from b982df4 to 487a15c Compare October 16, 2026 18:09

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 487a15c. Configure here.

@eugene-mux
eugene-mux force-pushed the em/nat-547-sdr-conversion branch from 487a15c to 10889a3 Compare October 16, 2026 18:35
@eugene-mux
eugene-mux requested a review from daytime-em October 16, 2026 19:33
@eugene-mux

Copy link
Copy Markdown
Author

@daytime-em thanks for the review, I've added changes you requested.

@eugene-mux
eugene-mux force-pushed the em/nat-547-sdr-conversion branch from 1cc4386 to 54b04f9 Compare October 16, 2026 19:58
Base automatically changed from em/nat-546-output-validation to feature/nat-534-hevc-standard-ingest October 16, 2026 20:07
@eugene-mux
eugene-mux force-pushed the em/nat-547-sdr-conversion branch from 54b04f9 to fff4029 Compare October 16, 2026 20:07

@daytime-em daytime-em left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved, with one question

.setHdrMode(Composition.HDR_MODE_KEEP_HDR).build()
val exporter = Transformer.Builder(context)
.setLooper(looper)
.setPortraitEncodingEnabled(true)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a particular reason why you chose to enable this? Landscape with a rotation matrix might be better supported by on-device encoders and I don't think standard input is opinionated here.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, thanks. I’ll address this in a later PR in the stack.

@eugene-mux
eugene-mux merged commit 094af9b into feature/nat-534-hevc-standard-ingest Oct 22, 2026
2 checks passed
@github-actions github-actions Bot mentioned this pull request Nov 4, 2026
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.

2 participants