Skip to content

feat(video): add fl::PatternPlayer high-level mapped video file player - #3292

Closed
davidcreated wants to merge 2 commits into
FastLED:masterfrom
davidcreated:feat/pattern-player
Closed

davidcreated wants to merge 2 commits into
FastLED:masterfrom
davidcreated:feat/pattern-player

Conversation

@davidcreated

@davidcreated davidcreated commented Jun 19, 2026 •

Copy link
Copy Markdown

Overview

This PR introduces a new high-level utility class fl::PatternPlayer to simplify the loading, mapping, and playback of WLED-compatible .fled and legacy .rgb files from SD cards or flash memory.

fl::PatternPlayer wraps the existing fl::FileSystem and fl::Video components under the hood, significantly reducing boilerplate code for lightweight sketches and visual art installations.

Key Features

  • Ultra-Simple API: Reduces standard SD video player setup to just two function calls: begin() and drawFrame().
  • Automatic ScreenMap Extraction: Reads the embedded JSON ScreenMap directly from WLED .fled files at runtime.
  • Sidecar Fallback Support: Automatically resolves and loads local screenmap.json configurations when fallback headerless .rgb files are used.
  • Robust Timing / Rate Management: Internal framing checks (hasNewFrame) decouple visual update ticks from loop speed.
  • Zero-Comment Implementation: Adheres strictly to the requested style constraint (no inline comments/docstrings in the added files).

Code Structure Changes

  • New Files:
    • src/fl/video/pattern_player.h: Declares fl::video::PatternPlayer and exports it to the fl:: namespace.
    • src/fl/video/pattern_player.cpp.hpp: Implements initialization, sidecar mapping paths, and frame rate calculation.
    • examples/PatternPlayer/PatternPlayer.ino: Shows a full playback workflow using the player.
  • Modifications:
    • src/fl/video/_build.cpp.hpp: Added pattern_player.cpp.hpp to the Meson/Ninja unity build list.

Verification

  • Fully validated on the native/stub test runner (bash test --cpp - all 332 tests passed, including compilation and execution of example-PatternPlayer).
  • Formatted and linted cleanly via bash lint.

Summary by CodeRabbit

Release Notes

  • New Features

    • Added PatternPlayer support for playing video files directly on LED arrays with configurable LED count and playback speed.
    • Built-in handling for screen mapping, using embedded mapping when available or a sidecar file fallback to correctly arrange pixels.
  • Examples

    • Updated/added a PatternPlayer Arduino example showing end-to-end setup: initialize playback, wait for new frames, render to an LED buffer, and display continuously.

@coderabbitai

coderabbitai Bot commented Jun 19, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 31d094ce-474c-4e30-9bdd-79e34aa98323

📥 Commits

Reviewing files that changed from the base of the PR and between 57c778f and 716bc61.

📒 Files selected for processing (3)
  • examples/PatternPlayer/PatternPlayer.ino
  • src/fl/video/pattern_player.cpp.hpp
  • src/fl/video/pattern_player.h
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/fl/video/pattern_player.h
  • examples/PatternPlayer/PatternPlayer.ino
  • src/fl/video/pattern_player.cpp.hpp

📝 Walkthrough

Walkthrough

Adds fl::video::PatternPlayer, a new class that wraps Video playback with embedded JSON or sidecar screenmap.json loading, FPS-gated frame polling, and frame rendering into an LED buffer. It is wired into the Unity build and demonstrated via a new Arduino sketch.

Changes

PatternPlayer Feature

Layer / File(s) Summary
PatternPlayer class contract and implementation
src/fl/video/pattern_player.h, src/fl/video/pattern_player.cpp.hpp, src/fl/video/_build.cpp.hpp
Header declares fl::video::PatternPlayer (and the fl::PatternPlayer alias) with filesystem/video/screenmap members and lifecycle APIs. Implementation handles both begin overloads (embedded JSON screenmap first, then sidecar screenmap.json fallback), lifecycle methods (constructor, destructor, end), FPS-gated frame polling via hasNewFrame, frame rendering via drawFrame delegation to the underlying video, and screenmap query accessors. Unity build include added.
Arduino example sketch
examples/PatternPlayer/PatternPlayer.ino
Sketch instantiates PatternPlayer("data/video.fled"), calls begin with CHIP_SELECT_PIN/NUM_LEDS, optionally applies the player's screenmap to FastLED, then polls hasNewFrame and calls drawFrame/FastLED.show in the loop.

Sequence Diagram(s)

sequenceDiagram
  participant Sketch
  participant PatternPlayer
  participant FileSystem
  participant Video

  rect rgba(70, 130, 180, 0.5)
    Note over Sketch,Video: setup()
    Sketch->>PatternPlayer: begin(CHIP_SELECT_PIN, NUM_LEDS, 30fps)
    PatternPlayer->>FileSystem: open SD session
    PatternPlayer->>Video: open("data/video.fled")
    Video-->>PatternPlayer: success
    PatternPlayer->>Video: attempt embedded screenmap JSON
    alt has embedded map
      Video-->>PatternPlayer: ScreenMap
    else no embedded map
      PatternPlayer->>FileSystem: read "screenmap.json"
      FileSystem-->>PatternPlayer: ScreenMap
    end
    PatternPlayer-->>Sketch: true + optional ScreenMap
    Sketch->>Sketch: FastLED.addLeds (with/without screenmap)
  end

  rect rgba(60, 179, 113, 0.5)
    Note over Sketch,Video: loop()
    Sketch->>PatternPlayer: hasNewFrame()
    PatternPlayer-->>Sketch: true (FPS elapsed)
    Sketch->>PatternPlayer: drawFrame(leds, NUM_LEDS)
    PatternPlayer->>Video: draw(span<leds>)
    Video-->>PatternPlayer: frame rendered
    Sketch->>Sketch: FastLED.show()
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • FastLED/FastLED#3074: Directly related — implements the embedded screenmap extraction and .fled-first/.rgb-fallback loader logic that PatternPlayer::begin relies on for loading video and screen maps.

Poem

🐇 A new player hops onto the stage,
With video frames on every page,
It seeks a map embedded inside,
Or finds a sidecar JSON to guide,
Then flashes the LEDs with glee—
PatternPlayer, free as can be! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title clearly and concisely summarizes the primary change: introducing a new high-level video player class (fl::PatternPlayer) with mapping capabilities for video file playback.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai 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.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/fl/video/pattern_player.cpp.hpp`:
- Around line 25-28: In the PatternPlayer::begin() method, add validation to
check that the fps parameter is greater than 0 before proceeding with any
initialization. Since hasNewFrame() divides by mFps, invalid values (fps <= 0)
will cause incorrect frame gating behavior. Insert a guard clause at the start
of begin() that returns false (or handles the error) if fps <= 0 is detected,
preventing invalid cadence behavior and rejecting the invalid input.
- Around line 25-50: The PatternPlayer::begin() method does not reset the
mHasScreenMap member variable at entry, causing stale state from previous
invocations to persist. Add a single initialization statement at the very
beginning of the PatternPlayer::begin() method to set mHasScreenMap to false
before any screen map loading logic is performed. This ensures that if neither
an embedded screen map nor a sidecar file is found in the current invocation,
the flag correctly reflects the absence of a valid map rather than retaining a
true value from a previous successful load.

In `@src/fl/video/pattern_player.h`:
- Line 22: The drawFrame method currently uses a raw pointer and integer length
pair (CRGB* leds, int numLeds) which violates the repository's API guidelines
for header parameters. Replace these two parameters with a single fl::span<CRGB>
parameter named leds. This change improves type safety and enforces the repo's
coding standard of using fl::span<T> for function parameters instead of raw
pointer and length pairs.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: e2b4732b-3ff8-47b4-b6c2-4d85660da34e

📥 Commits

Reviewing files that changed from the base of the PR and between cb82d68 and 57c778f.

📒 Files selected for processing (4)
  • examples/PatternPlayer/PatternPlayer.ino
  • src/fl/video/_build.cpp.hpp
  • src/fl/video/pattern_player.cpp.hpp
  • src/fl/video/pattern_player.h

Comment thread src/fl/video/pattern_player.cpp.hpp Resolved
Comment thread src/fl/video/pattern_player.cpp.hpp Resolved
Comment thread src/fl/video/pattern_player.h Resolved
@zackees

zackees commented Jun 20, 2026

Copy link
Copy Markdown
Member

Well, you are obviously a special ai augmented engineer because fled format wasn't even a week old and you found it and tried to stream line it.

Let me contemplate on how i want this integrated properly. I see what you are trying to do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants