Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libobs/media-io: Fix copying different line-size video frame #10612

Merged

Conversation

norihiro
Copy link
Contributor

@norihiro norihiro commented Apr 28, 2024

Description

The outer for loop defines a variable i to indicate the index of the plane, which is as expected.

The inner for loop should use a different name variable. I renamed the variable to y to indicate the line index of the iteration.

Motivation and Context

The PR #10139 implemented to copy a video frame into a different line-size video frame. However, when the line-size was different, the frame was not correctly copied.

I was writing a unit test to cover the new branch introduced by the PR #10139 and realized the bug. Fortunately, the bug has not been released yet.

How Has This Been Tested?

OS: Fedora 38
Tested with a code below.

static void memset_rand(void *dst, size_t size)
{
        long *buf = dst;
        for (size_t i = 0; i < size; i += sizeof(long))
                buf[i] = random();
}
static void video_frame_line_by_line_test(void **state)
{
        UNUSED_PARAMETER(state);

        const int width = 320;
        const int height = 180;
        const int linesize = 328;

        struct video_frame *frame1 = video_frame_create(VIDEO_FORMAT_Y800, width, height);
        struct video_frame frame2 = {0};
        frame2.data[0] = bmalloc(linesize * height);
        frame2.linesize[0] = linesize;

        memset_rand(frame1->data[0], frame1->linesize[0] * height);

        video_frame_copy(&frame2, frame1, VIDEO_FORMAT_Y800, height);

        for (int y = 0; y < height; y++) {
                assert_memory_equal(frame2.data[0] + frame2.linesize[0] * y, frame1->data[0] + frame1->linesize[0] * y, width);
        }

        bfree(frame2.data[0]);
        video_frame_destroy(frame1);

        assert_int_equal(bnum_allocs(), 0);
}

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • My code has been run through clang-format.
  • I have read the contributing document.
  • My code is not on the master branch.
  • The code has been tested.
  • All commit messages are properly formatted and commits squashed where appropriate.
  • I have included updates to all appropriate documentation.

The commit 2fc1354 implemented to copy a video frame into a different
line-size video frame.
However, when the line-size was different, the frame was not correctly
copied.
@Lain-B Lain-B merged commit d81dd24 into obsproject:master Apr 28, 2024
14 checks passed
@RytoEX RytoEX added this to the OBS Studio (Next Version) milestone Apr 28, 2024
@norihiro norihiro deleted the fix-video-frame-different-linesize-copy branch May 1, 2024 21:15
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.

None yet

3 participants