Skip to content

bug: libobs: buffered 2x deinterlacing flags a recycled frame and skips fields after it falls behind #2009

Closed

Description

@rdoupe

Bug

The buffered 2x deinterlace walk in ready_deinterlace_frames() (libobs/obs-source-deinterlace.c.h) sets the "pair" flag on the wrong frame. It skips fields when a buffered source falls behind.

The bug is in the loop's async_frames.num <= 2 exit:

if (prev_frame) {
	da_erase(source->async_frames, 0);
	remove_async_frame(source, prev_frame);   /* prev_frame goes back to the cache */
}

if (source->async_frames.num <= 2) {
	...
	if (prev_frame) {
		prev_frame->prev_frame = true;          /* ...and is then flagged */

There are two effects:

  • The new front frame is shown alone, not paired. The flag never reaches it.
  • The cached frame keeps the flag. remove_async_frame() returns the frame to async_cache, and copy_frame_data() doesn't reset prev_frame. The next incoming frame that reuses that cache entry is queued already flagged. When it is picked with another frame behind it, deinterlace_get_closest_frames() takes it as the first of a pair and shows the next frame instead. That frame shows one frame early, and the due frame's fields are skipped.

This reproduces in real libobs while working on #1965: buffered Yadif 2x after a 150 ms pause shows fields 0 1 2 5 5 5 …, both before and after #1995. It is memory-safe, because cached frames stay allocated. Upstream has the same code.

Plan

  1. RED: a real-libobs case in test_deinterlace_2x_field_order (or a sibling) that pauses a buffered source and then checks that the fields after the pause come in order. Add a focused case for the cache-reuse path if it can be reached through the API.
  2. GREEN: flag the frame that is actually paired, i.e. the new front, or don't flag at all on that exit. Also clear prev_frame when a frame is reused from the cache. Then check the buffered cadences of obs-source: Port the 2x deinterlace frame pacing #1954's caller model and libobs: Show both fields of the first 2x deinterlaced frame #1995's sequences, so only the broken cases change.

Activity

  1. rdoupe commented on Oct 23, 2026

    @rdoupe
    CollaboratorAuthor

    Claiming: #2009.

  2. added
    claimed
    on Oct 23, 2026
  3. rdoupe commented on Oct 24, 2026

    @rdoupe
    CollaboratorAuthor

    Correction to the description above: the pause case doesn't reproduce. A buffered source's clock only advances while frames are queued, so a pause never makes three frames due at once. The real trigger is a buffered source that falls behind, with three or more frames arriving at once after a tick. #2048 has the reproduction (8 new cases that fail on master) and the fix. The pause cases are kept as guards.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    claimed

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions