Skip to content

rust: Port the frame timing of the graphics loop (tick time and frame statistics) in obs-video.c to obs-core #2754

Closed

Description

@vpacher

Unit

Port the frame timing decisions of the graphics thread loop in libobs/obs-video.c.h to rust/obs-core, as a new module video_frame_timing, next to video_pacing (#2738, the frame time step of video_sleep() in the same loop), video_output_step (#2165) and video_copy_plan (#2118). obs_graphics_thread_loop() runs once per frame. These decisions move:

  • The tick time of tick_sources(). Input: the current frame time, the last tick time and the frame interval. Output:
    • the last tick time to use (on the first frame, when it is 0, the current frame time minus one interval);
    • the delta and the seconds that every tick callback and every source's video_tick gets ((float)((double)delta / 1e9));
    • the new last tick time (the current frame time).
  • The frame statistics at the end of obs_graphics_thread_loop(). Input: the three sums of struct obs_graphics_context (frame_time_total_ns, fps_total_ns, fps_total_frames), this frame's render time, the new frame time after video_sleep() and the last tick time. Output:
    • the new sums;
    • whether the window of at least one second is complete, and then the fps (double) and the average frame time (uint64_t) for obs_video_stats_set_timing(), and the reset sums.

These stay in C:

  • os_gettime_ns() (C passes the times), the profiler calls, gs_*;
  • the tick callbacks with draw_callbacks_mutex, the source list with sources_mutex, the references and obs_source_video_tick();
  • obs_video_stats_set_timing() and the stats mutex;
  • output_frames(), render_displays(), execute_graphics_tasks(), video_sleep().

Plan (one PR, separate commits)

  1. A behaviour-neutral move of the two decisions into libobs/obs-video-frame-timing.c.h, as hidden functions on plain values.
  2. Characterization in test_video_frame_timing_steps. It covers:
    • the first frame (last tick time 0) and normal frames;
    • a clock that goes backwards or jumps (the uint64_t delta wraps; the seconds of a huge delta as float);
    • common intervals (25, 29.97, 30, 60 fps) and the float/double rounding of the seconds;
    • the statistics window: just under one second, exactly one second, a late frame that ends the window with a large step, the fps and average frame time values, and the reset;
    • large sums near the uint64_t and uint32_t limits (characterized, not endorsed).
  3. RED, then GREEN: the safe Rust core plus shims, in a libobs.ported-video-frame-timing group. Exported symbols are unchanged.
  4. Tier 3 parity against the original C: exhaustive over the edges, plus proptests over full-range times, intervals and sums. Also a deliberate-break check and port_comparison numbers (it runs once per frame).

These real-libobs tests must stay green on every lane:

  • test_source_video_tick_steps
  • test_source_profiler
  • test_media_restart_stale_frame
  • test_transition_recursive_destination
  • test_slideshow_empty, test_slideshow_manual_end
  • test_video_pacing_steps, test_video_output_step_steps, test_video_copy_plan_steps

Production check: batched with the other per-frame ports in one before/after run on the obs-rust production box (Linux, NDI output, 25 fps).

Refs #2738 #2165 #2118

Activity

  1. vpacher commented on Oct 28, 2026

    @vpacher
    MemberAuthor

    Claiming: #2754

    Plan as in the issue: one PR with the behaviour-neutral move, the characterization (test_video_frame_timing_steps), RED/GREEN (obs-core::video_frame_timing, group libobs.ported-video-frame-timing) and Tier 3 parity. Before pushing: memory and time of the new tests, Windows on a local VM, and a local-gate stamp so PR CI can skip the Linux jobs.

  2. added
    ready
    on Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

ready

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions