Skip to content

Use frame rate reported by CasparCG if nothing else is configured#420

Open
rjmunro wants to merge 3 commits into
mainfrom
rjmunro/use-detected-frame-rate
Open

Use frame rate reported by CasparCG if nothing else is configured#420
rjmunro wants to merge 3 commits into
mainfrom
rjmunro/use-detected-frame-rate

Conversation

@rjmunro
Copy link
Copy Markdown
Contributor

@rjmunro rjmunro commented Jan 22, 2026

About the Contributor

Type of Contribution

This is a Bug fix / Feature

Current Behavior

The framerate is read from CasparCG with the INFO command, but it is ignored. It uses a user configured value or a default of 25. This breaks timing in e.g. 50i modes, meaning that you jump to a point twice as far in a video than you should. It probably breaks 30 and 60fps to, but I we didn't test that.

New Behavior

Use the value from the INFO command if config is unset. Only default to 25 if that doesn't work.

Testing Instructions

@Saftret Can you review this?

While working in a 50i setup, leave the configured value in settings -> studio -> playout devices -> CasparCG -> frame rate blank. Then jump to a place in a clip (how?). It should take you to the right place. The previous version would take you to a point double what you requested.

Other Information

This was discussed and coded at the SuperFlyTV dev meet on 2026/01/22.

Status

  • PR is ready to be reviewed.
  • The functionality has been tested by the author.
  • Relevant unit tests has been added / updated.
  • Relevant documentation (code comments, system documentation) has been added / updated.

Use detected frame rate as default if not configured

Problem

The CasparCG integration was ignoring the frame rate reported by CasparCG's INFO command and instead relying on a user-configured value or defaulting to 25 fps. This caused incorrect timing behavior—notably, in 50i setups, jumps landed at twice the requested position, and the issue potentially affects 30/60 fps configurations as well.

Solution

Modified the CasparCG integration to prioritize the frame rate detected from CasparCG's INFO command when the user has not explicitly configured a frame rate. The fallback hierarchy is now:

  1. User-configured frame rate (if set)
  2. Frame rate detected from CasparCG INFO response
  3. Default to 25 fps (only if detection is unavailable or invalid)

Technical Changes

  • Refactored channel initialization and resync logic to return a structured object { doResync: boolean, channelInfo: InfoEntry[] } instead of a plain boolean, enabling more flexible channel metadata handling
  • Deferred per-channel INFO population from the virgin connection phase, constructing channel info asynchronously via a promise chain
  • Reworked the resync decision flow: when any channel contains layers, returns doResync: false; otherwise doResync: true
  • Updated error handling to return structured resync signals with empty channel info
  • Enhanced the post-connection handler to apply resync state and populate _currentState from the retrieved channel info
  • Modified FPS resolution logic: uses configured initOptions.fps if available, else falls back to detected FPS from _currentState for the channel, or defaults to 25
  • Ensured channel metadata (FPS, video mode) is properly reconstructed after clearing all channels

Testing

Testing instructions provided: In a 50i setup, leave the CasparCG frame rate configuration blank and verify that jumps to clip positions land at the correct location (previously landed at double the requested position).

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jan 22, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

  • 🔍 Trigger a full review

Walkthrough

The CasparCG integration refactors connection initialization and resync handling to return a structured object containing resync flags and channel information instead of boolean values, enabling dynamic channel set support and deferred state population during connection and recovery operations.

Changes

Cohort / File(s) Summary
CasparCG Resync & State Initialization
packages/timeline-state-resolver/src/integrations/casparCG/index.ts
Replaced boolean return values with structured { doResync: boolean, channelInfo: InfoEntry[] } object; reworked channel initialization to dynamically iterate over channelInfo; deferred per-channel INFO accumulation via channelPromises; generalized FPS and metadata reconstruction on resync with fallback to configured or derived FPS values; updated clearAllChannels to rebuild channel state from response data

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A channel springs to life anew,
No fixed loops—just dynamic, true!
Resync signals flow with grace,
State deferred finds its place,
FPS whispers, channels dance! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately reflects the main objective of the pull request: enabling CasparCG's detected frame rate to be used as a default when no frame rate is configured.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

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


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.

Comment thread packages/timeline-state-resolver-types/src/templateString.ts Fixed
@jstarpl jstarpl changed the base branch from main to release53 January 22, 2026 14:50
@rjmunro rjmunro force-pushed the rjmunro/use-detected-frame-rate branch 2 times, most recently from 9c2af07 to 6af085d Compare January 22, 2026 15:11
@rjmunro
Copy link
Copy Markdown
Contributor Author

rjmunro commented Jan 22, 2026

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jan 22, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@rjmunro rjmunro marked this pull request as ready for review January 26, 2026 12:20
@rjmunro rjmunro requested a review from a team as a code owner January 26, 2026 12:20
Comment thread packages/timeline-state-resolver/src/integrations/casparCG/index.ts Outdated
Rather than directly defaulting to 25.
Previously, channel info was populated during the virgin check loop but
then immediately cleared if a resync was needed (which includes first
connect). This meant _currentState.channels was empty during normal
operation.

Changes:
- Move channel info population to after the resync decision
- Pass channelInfo through the promise chain alongside doResync
- Fix bug where channels[i] was checked but channels[obj.channel] was set
- Simplify loop to iterate over channelInfo array directly

This ensures channel metadata (fps, videoMode) is always available.
Only clear _currentState.channels when doing a resync (firstConnect || doResync).
When updating channel info (videoMode/fps), preserve existing layers that are
built up by shared-control feature instead of always clearing them.

Addresses PR feedback from @Julusian
@rjmunro rjmunro force-pushed the rjmunro/use-detected-frame-rate branch from 6af085d to cffbaa7 Compare January 28, 2026 11:25
@nytamin nytamin changed the base branch from release53 to main February 9, 2026 11:38
@rjmunro
Copy link
Copy Markdown
Contributor Author

rjmunro commented Feb 16, 2026

Awaiting retesting by @Saftret. It's possibly not detecting anything and just defaulting to 25fps.

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.

3 participants