Skip to content

CMAF support #8

Open
jpbusta10 wants to merge 19 commits intomainfrom
full-cmaf-import
Open

CMAF support #8
jpbusta10 wants to merge 19 commits intomainfrom
full-cmaf-import

Conversation

@jpbusta10
Copy link

@jpbusta10 jpbusta10 commented Jan 7, 2026

Add passthrough mode for CMAF/HLS import and MSE playback support

This PR adds comprehensive CMAF/fMP4 support with passthrough mode for ingestion and Media Source Extensions (MSE) for efficient browser playback.

Changes

Rust/CLI Side

  • Added --passthrough flag to hang publish hls command
  • Updated just pub-hls command to support passthrough mode via optional parameter
  • Passthrough mode transports complete CMAF fragments (moof+mdat) without decomposition, improving efficiency for certain use cases

TypeScript/Browser Side

  • New MSE-based playback: Implemented SourceMSE class for both audio and video tracks
  • Automatic routing: When container type is fmp4, playback automatically uses MSE instead of WebCodecs
  • Fragment handling: Properly handles CMAF fragments with init segment (moov) detection and GOP grouping
  • Queue management: Implements fragment queuing with size limits to prevent memory issues in live streaming
  • Fallback support: Gracefully falls back to WebCodecs if MSE initialization fails

Technical Details

Passthrough Mode:
The passthrough flag enables transport of complete CMAF fragments without re-encoding or decomposing them. This is particularly useful when you want to preserve the original CMAF structure.

MSE Implementation:

  • Uses browser's native MediaSource API for CMAF/fMP4 playback
  • Handles init segments (moov atoms) separately from media fragments
  • Groups fragments by MOQ group before appending to SourceBuffer
  • Implements proper buffering and playback state management
  • Exposes audio/video elements for direct control (volume, mute, etc.)

Usage

Publish HLS with passthrough mode

just pub-hls bbb passthrough

Publish HLS without passthrough (default)

just pub-hls bbb

The browser will automatically use MSE for playback when the container is fmp4, providing more efficient decoding and lower latency compared to WebCodecs for CMAF content.

@gemini-code-assist
Copy link

Summary of Changes

Hello @jpbusta10, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly expands the project's documentation by introducing a new VitePress-based site, offering comprehensive guides and examples for both Rust and TypeScript libraries. A major focus has been placed on enhancing CMAF/fMP4 support across the hang libraries, enabling a 'passthrough' mode for direct fragment transport, which is vital for web-based playback using Media Source Extensions. Additionally, improvements include dynamic TLS certificate reloading for server components, streamlined HLS ingest, and general dependency and build system updates to support the new documentation infrastructure.

Highlights

  • New Documentation Site: A comprehensive documentation site has been introduced using VitePress, including detailed guides on architecture, deployment, Rust and TypeScript libraries, and code examples. This significantly improves the project's user-facing resources.
  • Enhanced CMAF/fMP4 Support: The js/hang and rs/hang libraries now feature improved handling of CMAF/fMP4 fragments, including a new 'passthrough' mode. This mode allows for direct transport of complete fragments, crucial for Media Source Extensions (MSE) compatibility in web browsers, and ensures init segments are sent with keyframes for live stream joining.
  • Dynamic TLS Certificate Reloading: The moq-native and moq-relay components now support dynamic reloading of TLS certificates via a SIGUSR1 signal on Unix systems, enhancing operational flexibility and security without requiring a server restart.
  • Dependency and Build System Updates: The Cargo.lock file has been updated to remove the strum dependency and adjust tokio features. New deno.lock and bun.lock files were added to support the new doc workspace, streamlining the build and dependency management for the documentation site.
  • Improved HLS Ingest Workflow: The justfile and rs/hang-cli have been updated to provide more robust HLS ingest capabilities, including better handling of playlist synchronization and segment processing, especially during initial stream setup.
  • Codecs and Container Configuration: The hang library now includes a Container enum in its catalog, allowing explicit specification of frame encoding formats (e.g., Legacy, Raw, Fmp4). This provides greater control over media stream packaging and compatibility.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request primarily focuses on a major overhaul of the project's documentation, migrating it to VitePress. This involved adding new configuration files (.editorconfig, biome.jsonc, deno.lock, doc/.gitignore, doc/.vitepress/config.ts, doc/.vitepress/theme/custom.css, doc/.vitepress/theme/index.js, doc/bun.lock, doc/package.json, doc/public/icon.svg, doc/public/logo.svg, doc/worker.js, doc/wrangler.jsonc) and creating numerous new documentation pages covering architecture, authentication, deployment, core concepts, Rust and TypeScript libraries, examples, and Web Components. The documentation also saw updates to internal links to reflect the new structure. Concurrently, the project's media handling logic was enhanced to support CMAF/fMP4 fragments via Media Source Extensions (MSE) in the @moq/hang TypeScript library, introducing new MSE-specific audio and video sources, MIME type utilities, and passthrough mode for HLS ingestion in the Rust hang library. This involved changes to js/hang/src/container/codec.ts, js/hang/src/frame.ts, js/hang/src/util/mime.ts, js/hang/src/watch/audio/emitter.ts, js/hang/src/watch/audio/source-mse.ts, js/hang/src/watch/audio/source.ts, js/hang/src/watch/video/source-mse.ts, js/hang/src/watch/video/source.ts, rs/hang-cli/src/publish.rs, rs/hang/src/catalog/audio/mod.rs, rs/hang/src/catalog/container.rs, rs/hang/src/catalog/mod.rs, rs/hang/src/catalog/root.rs, rs/hang/src/catalog/video/mod.rs, rs/hang/src/error.rs, rs/hang/src/import/aac.rs, rs/hang/src/import/avc3.rs, rs/hang/src/import/decoder.rs, rs/hang/src/import/fmp4.rs, rs/hang/src/import/hls.rs, rs/hang/src/model/track.rs. Additionally, the strum dependency was removed from Cargo.lock and rs/hang/Cargo.toml, and server-side TLS certificate handling was improved in rs/hang-cli/src/server.rs, rs/moq-native/src/server.rs, rs/moq-relay/src/main.rs, rs/moq-relay/src/web.rs. Review comments highlighted several broken or outdated links in the new documentation, a TODO to remove ignoreDeadLinks: true in VitePress config, and suggested a more robust check for buffered media ranges in the MSE implementation.

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