From 42a9b03efec10a57d1dd92b400f3725d16231afa Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Wed, 25 Nov 2026 10:18:38 -0800 Subject: [PATCH 1/2] test(libobs): characterize obs_source_frame_copy (Refs #5720) Co-Authored-By: Claude Opus 5.5 --- .../test_source_frame_copy_characterization.c | 262 ++++++++++++++++++ 1 file changed, 262 insertions(+) create mode 100644 test/cmocka/test_source_frame_copy_characterization.c diff --git a/test/cmocka/test_source_frame_copy_characterization.c b/test/cmocka/test_source_frame_copy_characterization.c new file mode 100644 index 0000000000..ab122b136e --- /dev/null +++ b/test/cmocka/test_source_frame_copy_characterization.c @@ -0,0 +1,262 @@ +/* Characterize the public obs_source_frame_copy against the actual library + * before its extraction and Rust replacement (#5720). Frames are caller-owned + * buffers: no OBS core, video device, or graphics context is needed. */ +#include +#include +#include +#include +#include +#include +#include +#include "obs.h" + +#define SRC_FILL 0x11 +#define DST_FILL 0xa5 + +struct plane_spec { + uint32_t src_linesize; + uint32_t dst_linesize; + uint32_t rows; /* buffer rows to allocate for both frames */ +}; + +struct frames { + struct obs_source_frame src; + struct obs_source_frame dst; + size_t sizes[MAX_AV_PLANES][2]; +}; + +/* Source plane bytes are a per-plane pattern; destination bytes are DST_FILL, + * so untouched destination bytes stay recognizable. */ +static void frames_init(struct frames *f, enum video_format src_format, uint32_t src_height, + enum video_format dst_format, uint32_t dst_height, const struct plane_spec *planes, + size_t count) +{ + memset(f, 0, sizeof(*f)); + memset(&f->dst, 0x5a, sizeof(f->dst)); + f->dst.full_range = true; + f->dst.flip = false; + f->dst.prev_frame = false; + f->dst.format = dst_format; + f->dst.width = 77; + f->dst.height = dst_height; + f->dst.refs = 3; + for (size_t i = 0; i < MAX_AV_PLANES; i++) { + f->dst.data[i] = NULL; + f->dst.linesize[i] = 0; + } + + f->src.format = src_format; + f->src.width = 99; + f->src.height = src_height; + f->src.timestamp = 0x0102030405060708ULL; + f->src.full_range = false; + f->src.max_luminance = 1000; + f->src.flip = true; + f->src.flags = OBS_SOURCE_FRAME_LINEAR_ALPHA; + f->src.trc = VIDEO_TRC_PQ; + f->src.refs = 9; + for (size_t i = 0; i < 16; i++) + f->src.color_matrix[i] = (float)i + 0.5f; + for (size_t i = 0; i < 3; i++) { + f->src.color_range_min[i] = 0.0625f * (float)(i + 1); + f->src.color_range_max[i] = 0.9f + 0.01f * (float)i; + f->dst.color_range_min[i] = -1.0f; + f->dst.color_range_max[i] = -2.0f; + } + + for (size_t i = 0; i < count; i++) { + size_t src_size = (size_t)planes[i].src_linesize * planes[i].rows; + size_t dst_size = (size_t)planes[i].dst_linesize * planes[i].rows; + f->sizes[i][0] = src_size; + f->sizes[i][1] = dst_size; + f->src.linesize[i] = planes[i].src_linesize; + f->dst.linesize[i] = planes[i].dst_linesize; + f->src.data[i] = malloc(src_size ? src_size : 1); + f->dst.data[i] = malloc(dst_size ? dst_size : 1); + assert_non_null(f->src.data[i]); + assert_non_null(f->dst.data[i]); + for (size_t b = 0; b < src_size; b++) + f->src.data[i][b] = (uint8_t)(SRC_FILL * (i + 1) + b); + memset(f->dst.data[i], DST_FILL, dst_size); + } +} + +static void frames_free(struct frames *f) +{ + for (size_t i = 0; i < MAX_AV_PLANES; i++) { + free(f->src.data[i]); + free(f->dst.data[i]); + } +} + +/* The destination after a copy: the metadata of the source, its own size, + * format, strides, plane pointers, refs and prev_frame. Color range follows + * the copied full_range flag. */ +static void expect_metadata(const struct obs_source_frame *before, const struct obs_source_frame *src, + const struct obs_source_frame *after) +{ + struct obs_source_frame expected; + memcpy(&expected, before, sizeof(expected)); + expected.flip = src->flip; + expected.flags = src->flags; + expected.trc = src->trc; + expected.full_range = src->full_range; + expected.max_luminance = src->max_luminance; + expected.timestamp = src->timestamp; + memcpy(expected.color_matrix, src->color_matrix, sizeof(expected.color_matrix)); + if (!src->full_range) { + memcpy(expected.color_range_min, src->color_range_min, sizeof(expected.color_range_min)); + memcpy(expected.color_range_max, src->color_range_max, sizeof(expected.color_range_max)); + } + assert_memory_equal(after, &expected, sizeof(expected)); +} + +/* Checks one destination plane: `rows` rows of `bytes` copied at each stride, + * everything else still DST_FILL. */ +static void expect_plane(const struct frames *f, size_t plane, uint32_t rows, size_t bytes) +{ + const uint32_t src_stride = f->src.linesize[plane]; + const uint32_t dst_stride = f->dst.linesize[plane]; + const size_t dst_size = f->sizes[plane][1]; + const uint8_t *dst = f->dst.data[plane]; + const uint8_t *src = f->src.data[plane]; + for (size_t b = 0; b < dst_size; b++) { + size_t row = b / dst_stride; + size_t col = b % dst_stride; + if (row < rows && col < bytes) + assert_int_equal(dst[b], src[row * src_stride + col]); + else + assert_int_equal(dst[b], DST_FILL); + } +} + +static void expect_plane_untouched(const struct frames *f, size_t plane) +{ + for (size_t b = 0; b < f->sizes[plane][1]; b++) + assert_int_equal(f->dst.data[plane][b], DST_FILL); +} + +static void copy_and_check_metadata(struct frames *f) +{ + struct obs_source_frame before; + struct obs_source_frame src_before; + memcpy(&before, &f->dst, sizeof(before)); + memcpy(&src_before, &f->src, sizeof(src_before)); + obs_source_frame_copy(&f->dst, &f->src); + expect_metadata(&before, &f->src, &f->dst); + assert_memory_equal(&f->src, &src_before, sizeof(src_before)); +} + +/* Packed RGBA with equal strides: one whole-plane copy of linesize * height; + * limited range copies the color range. */ +static void packed_equal_strides_copy_whole_plane(void **state) +{ + (void)state; + struct frames f; + const struct plane_spec planes[] = {{16, 16, 6}}; + frames_init(&f, VIDEO_FORMAT_RGBA, 6, VIDEO_FORMAT_RGBA, 4, planes, 1); + copy_and_check_metadata(&f); + /* Rows come from the destination height, not the source's. */ + expect_plane(&f, 0, 4, 16); + frames_free(&f); +} + +/* Full range: the destination color range is left as it was. */ +static void full_range_keeps_destination_color_range(void **state) +{ + (void)state; + struct frames f; + const struct plane_spec planes[] = {{8, 8, 3}}; + frames_init(&f, VIDEO_FORMAT_BGRA, 3, VIDEO_FORMAT_BGRA, 3, planes, 1); + f.src.full_range = true; + copy_and_check_metadata(&f); + assert_true(f.dst.full_range); + for (size_t i = 0; i < 3; i++) { + assert_true(f.dst.color_range_min[i] == -1.0f); + assert_true(f.dst.color_range_max[i] == -2.0f); + } + expect_plane(&f, 0, 3, 8); + frames_free(&f); +} + +/* Planar I420 with padded strides in both directions: row copies of the + * smaller line size, chroma rows rounded up from an odd height, padding + * untouched. */ +static void planar_padded_strides_copy_rows(void **state) +{ + (void)state; + struct frames f; + const struct plane_spec planes[] = {{12, 16, 5}, {6, 4, 3}, {8, 8, 3}}; + frames_init(&f, VIDEO_FORMAT_I420, 5, VIDEO_FORMAT_I420, 5, planes, 3); + copy_and_check_metadata(&f); + expect_plane(&f, 0, 5, 12); + expect_plane(&f, 1, 3, 4); + expect_plane(&f, 2, 3, 8); + frames_free(&f); +} + +/* The plan follows the source format: an NV12 source copies two planes even + * when the destination says RGBA, and later destination planes stay as they + * were. */ +static void source_format_selects_planes(void **state) +{ + (void)state; + struct frames f; + const struct plane_spec planes[] = {{8, 8, 4}, {8, 10, 2}, {4, 4, 4}}; + frames_init(&f, VIDEO_FORMAT_NV12, 4, VIDEO_FORMAT_RGBA, 4, planes, 3); + copy_and_check_metadata(&f); + expect_plane(&f, 0, 4, 8); + expect_plane(&f, 1, 2, 8); + expect_plane_untouched(&f, 2); + frames_free(&f); +} + +/* Four full-height planes for YUVA and I40A's alpha plane at full height. */ +static void alpha_planes(void **state) +{ + (void)state; + struct frames f; + const struct plane_spec yuva[] = {{4, 4, 3}, {4, 4, 3}, {4, 6, 3}, {4, 4, 3}}; + frames_init(&f, VIDEO_FORMAT_YUVA, 3, VIDEO_FORMAT_YUVA, 3, yuva, 4); + copy_and_check_metadata(&f); + expect_plane(&f, 0, 3, 4); + expect_plane(&f, 1, 3, 4); + expect_plane(&f, 2, 3, 4); + expect_plane(&f, 3, 3, 4); + frames_free(&f); + + const struct plane_spec i40a[] = {{4, 4, 3}, {2, 2, 2}, {2, 2, 2}, {4, 4, 3}}; + frames_init(&f, VIDEO_FORMAT_I40A, 3, VIDEO_FORMAT_I40A, 3, i40a, 4); + copy_and_check_metadata(&f); + expect_plane(&f, 0, 3, 4); + expect_plane(&f, 1, 2, 2); + expect_plane(&f, 2, 2, 2); + expect_plane(&f, 3, 3, 4); + frames_free(&f); +} + +/* P216 has no copy plan: metadata is copied, no plane bytes are. */ +static void unimplemented_format_copies_metadata_only(void **state) +{ + (void)state; + struct frames f; + const struct plane_spec planes[] = {{8, 8, 2}, {8, 8, 2}}; + frames_init(&f, VIDEO_FORMAT_P216, 2, VIDEO_FORMAT_P216, 2, planes, 2); + copy_and_check_metadata(&f); + expect_plane_untouched(&f, 0); + expect_plane_untouched(&f, 1); + frames_free(&f); +} + +int main(void) +{ + const struct CMUnitTest tests[] = { + cmocka_unit_test(packed_equal_strides_copy_whole_plane), + cmocka_unit_test(full_range_keeps_destination_color_range), + cmocka_unit_test(planar_padded_strides_copy_rows), + cmocka_unit_test(source_format_selects_planes), + cmocka_unit_test(alpha_planes), + cmocka_unit_test(unimplemented_format_copies_metadata_only), + }; + return cmocka_run_group_tests(tests, NULL, NULL); +} From 2524ef9d2548c5a22ee090c2a43997b4636eb0aa Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Wed, 25 Nov 2026 10:18:38 -0800 Subject: [PATCH 2/2] test(libobs): register source frame copy characterization (Refs #5720) Co-Authored-By: Claude Opus 5.5 Client-Checks: {"checks":{"base":"152c528e41cbfc33e0a17189d18f7ca81191937b","coverage":"all-tracked-applicable-files","diff":["test/cmocka/build/test-graph.json","test/cmocka/test_source_frame_copy_characterization.c"],"head":"0886c9e098b3d2f1ce59a500d6d8d890d463a5d6","tools":{"orchestrator-python":"3.13.15 (main, Aug 14 2026, 15:34:59) [Clang 22.1.3 ]","schema-dependencies":"3.13.15 (main, Aug 14 2026, 15:34:59) [Clang 22.1.3 ]\n{'jsonschema': '4.26.0', 'json_source_map': '1.0.5'}","uv":"uv 0.13.5 (x86_64-unknown-linux-gnu)","xmllint":"xmllint: using libxml version 21503\n compiled with: Threads Tree Output Push Reader Patterns Writer SAXv1 DTDValid HTML C14N Catalog XPath XPointer XInclude Iconv ISO8859X Regexps Automata RelaxNG Schemas Modules Debug"},"tracked-digest":"b1ea9548afc9eb9966cdc59e079f83c2d5f0f3cd027fd3ca18a5c52e2d889951","tree":"ab0a7d6f69bd22f0ffdf65f44877d2f5160e7251"}} Ci-Attestation: {"at":1795687273,"gate":"data/all/compatibility","host":"linux-x86_64","key":"","lane":"client-checks","parents":["1609f4f7c53bd907624ce5c6c498aa09936843eb"],"secs":152,"stamp":"909b7e84a7345bcc866cb14eac55f7a7","tree":"ab0a7d6f69bd22f0ffdf65f44877d2f5160e7251","v":1,"via":"run"} Ci-Attestation: {"at":1795687273,"gate":"data/all/flatpak-manifest","host":"linux-x86_64","key":"","lane":"client-checks","parents":["1609f4f7c53bd907624ce5c6c498aa09936843eb"],"secs":152,"stamp":"8e24d21c0cb61e315e3bc52d69209df5","tree":"ab0a7d6f69bd22f0ffdf65f44877d2f5160e7251","v":1,"via":"run"} Ci-Attestation: {"at":1795687273,"gate":"data/all/qt-xml","host":"linux-x86_64","key":"","lane":"client-checks","parents":["1609f4f7c53bd907624ce5c6c498aa09936843eb"],"secs":152,"stamp":"24f791c2ddc38e27945bb31bd2b9e108","tree":"ab0a7d6f69bd22f0ffdf65f44877d2f5160e7251","v":1,"via":"run"} Ci-Attestation: {"at":1795687273,"gate":"data/all/services-schema","host":"linux-x86_64","key":"","lane":"client-checks","parents":["1609f4f7c53bd907624ce5c6c498aa09936843eb"],"secs":152,"stamp":"c4f7e5f61f37f8915dc57d0aeb2c6084","tree":"ab0a7d6f69bd22f0ffdf65f44877d2f5160e7251","v":1,"via":"run"} Ci-Attestation: {"at":1796410121,"gate":"general/all/client-lint","host":"linux-x86_64","key":"4751a827bfe6a7813ddce8970770e625484f6f82dd0994e6c33d2484583aecce","lane":"client-lint","parents":["42a9b03efec10a57d1dd92b400f3725d16231afa"],"secs":62,"stamp":"e780be8ac5ce63f5091739037476f376","tree":"bde0f8439a2ab9d8d8e9782ff0bf501768f921f9","v":1,"via":"run"} Ci-Attestation: {"at":1795687273,"gate":"python/all/self-test","host":"linux-x86_64","key":"","lane":"client-checks","parents":["1609f4f7c53bd907624ce5c6c498aa09936843eb"],"secs":152,"stamp":"c02761040f15c21c0c335f5112bf150d","tree":"ab0a7d6f69bd22f0ffdf65f44877d2f5160e7251","v":1,"via":"run"} Ci-Attestation: {"at":1796410123,"gate":"rust/aarch64-apple-darwin/client-clippy","host":"linux-x86_64","key":"4751a827bfe6a7813ddce8970770e625484f6f82dd0994e6c33d2484583aecce","lane":"client-lint","parents":["42a9b03efec10a57d1dd92b400f3725d16231afa"],"secs":62,"stamp":"ce4ca940691a3c44ea38a9e0ef2d2ab9","tree":"bde0f8439a2ab9d8d8e9782ff0bf501768f921f9","v":1,"via":"run"} Ci-Attestation: {"at":1796410123,"gate":"rust/aarch64-apple-darwin/client-dylint","host":"linux-x86_64","key":"4751a827bfe6a7813ddce8970770e625484f6f82dd0994e6c33d2484583aecce","lane":"client-lint","parents":["42a9b03efec10a57d1dd92b400f3725d16231afa"],"secs":62,"stamp":"41ca8583d95978b7a576184a1459b25f","tree":"bde0f8439a2ab9d8d8e9782ff0bf501768f921f9","v":1,"via":"run"} Ci-Attestation: {"at":1796410122,"gate":"rust/aarch64-pc-windows-msvc/client-clippy","host":"linux-x86_64","key":"4751a827bfe6a7813ddce8970770e625484f6f82dd0994e6c33d2484583aecce","lane":"client-lint","parents":["42a9b03efec10a57d1dd92b400f3725d16231afa"],"secs":62,"stamp":"4830c71773b6e208ada21b36848ffc81","tree":"bde0f8439a2ab9d8d8e9782ff0bf501768f921f9","v":1,"via":"run"} Ci-Attestation: {"at":1796410122,"gate":"rust/aarch64-pc-windows-msvc/client-dylint","host":"linux-x86_64","key":"4751a827bfe6a7813ddce8970770e625484f6f82dd0994e6c33d2484583aecce","lane":"client-lint","parents":["42a9b03efec10a57d1dd92b400f3725d16231afa"],"secs":62,"stamp":"62efce4dd602e9ec7af0b52b8865ac58","tree":"bde0f8439a2ab9d8d8e9782ff0bf501768f921f9","v":1,"via":"run"} Ci-Attestation: {"at":1796410122,"gate":"rust/aarch64-unknown-linux-gnu/client-clippy","host":"linux-x86_64","key":"4751a827bfe6a7813ddce8970770e625484f6f82dd0994e6c33d2484583aecce","lane":"client-lint","parents":["42a9b03efec10a57d1dd92b400f3725d16231afa"],"secs":62,"stamp":"f540f6276834fff7b08abeaac237275a","tree":"bde0f8439a2ab9d8d8e9782ff0bf501768f921f9","v":1,"via":"run"} Ci-Attestation: {"at":1796410122,"gate":"rust/aarch64-unknown-linux-gnu/client-dylint","host":"linux-x86_64","key":"4751a827bfe6a7813ddce8970770e625484f6f82dd0994e6c33d2484583aecce","lane":"client-lint","parents":["42a9b03efec10a57d1dd92b400f3725d16231afa"],"secs":62,"stamp":"f1c58600e52e810d6d49b48b30988fde","tree":"bde0f8439a2ab9d8d8e9782ff0bf501768f921f9","v":1,"via":"run"} Ci-Attestation: {"at":1796410122,"gate":"rust/x86_64-apple-darwin/client-clippy","host":"linux-x86_64","key":"4751a827bfe6a7813ddce8970770e625484f6f82dd0994e6c33d2484583aecce","lane":"client-lint","parents":["42a9b03efec10a57d1dd92b400f3725d16231afa"],"secs":62,"stamp":"2537a4d46421e48e752cf0151b5fb726","tree":"bde0f8439a2ab9d8d8e9782ff0bf501768f921f9","v":1,"via":"run"} Ci-Attestation: {"at":1796410123,"gate":"rust/x86_64-apple-darwin/client-dylint","host":"linux-x86_64","key":"4751a827bfe6a7813ddce8970770e625484f6f82dd0994e6c33d2484583aecce","lane":"client-lint","parents":["42a9b03efec10a57d1dd92b400f3725d16231afa"],"secs":62,"stamp":"dcbef512804dec07cf4a369386af340c","tree":"bde0f8439a2ab9d8d8e9782ff0bf501768f921f9","v":1,"via":"run"} Ci-Attestation: {"at":1796410122,"gate":"rust/x86_64-pc-windows-msvc/client-clippy","host":"linux-x86_64","key":"4751a827bfe6a7813ddce8970770e625484f6f82dd0994e6c33d2484583aecce","lane":"client-lint","parents":["42a9b03efec10a57d1dd92b400f3725d16231afa"],"secs":62,"stamp":"5fddbeb6282b42a784307d6515f1ec3b","tree":"bde0f8439a2ab9d8d8e9782ff0bf501768f921f9","v":1,"via":"run"} Ci-Attestation: {"at":1796410122,"gate":"rust/x86_64-pc-windows-msvc/client-dylint","host":"linux-x86_64","key":"4751a827bfe6a7813ddce8970770e625484f6f82dd0994e6c33d2484583aecce","lane":"client-lint","parents":["42a9b03efec10a57d1dd92b400f3725d16231afa"],"secs":62,"stamp":"82dcaa5e1cadf71077a67b2909d45d84","tree":"bde0f8439a2ab9d8d8e9782ff0bf501768f921f9","v":1,"via":"run"} Ci-Attestation: {"at":1796410122,"gate":"rust/x86_64-unknown-linux-gnu/client-clippy","host":"linux-x86_64","key":"4751a827bfe6a7813ddce8970770e625484f6f82dd0994e6c33d2484583aecce","lane":"client-lint","parents":["42a9b03efec10a57d1dd92b400f3725d16231afa"],"secs":62,"stamp":"b3b183667c658c70b41cfd22855e7e7c","tree":"bde0f8439a2ab9d8d8e9782ff0bf501768f921f9","v":1,"via":"run"} Ci-Attestation: {"at":1796410122,"gate":"rust/x86_64-unknown-linux-gnu/client-dylint","host":"linux-x86_64","key":"4751a827bfe6a7813ddce8970770e625484f6f82dd0994e6c33d2484583aecce","lane":"client-lint","parents":["42a9b03efec10a57d1dd92b400f3725d16231afa"],"secs":62,"stamp":"23fa32d123a0fddb45f6010f7ff29ecf","tree":"bde0f8439a2ab9d8d8e9782ff0bf501768f921f9","v":1,"via":"run"} Ci-Attestation: {"at":1795687853,"gate":"rust/x86_64-unknown-linux-gnu/client-test","host":"linux-x86_64","key":"86c43e67ed5ceb1466f1b3f1b0a1627b16915a5af19a13d86d4c54188c5dc321","lane":"client-test-x86_64-unknown-linux-gnu","parents":["1609f4f7c53bd907624ce5c6c498aa09936843eb"],"secs":579,"stamp":"60e0cd2859bc8d9779e7996f613cadfb","tree":"ab0a7d6f69bd22f0ffdf65f44877d2f5160e7251","v":1,"via":"run"} --- ...st_source_frame_copy_characterization.json | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 test/cmocka/build/test-graph.d/test_source_frame_copy_characterization.json diff --git a/test/cmocka/build/test-graph.d/test_source_frame_copy_characterization.json b/test/cmocka/build/test-graph.d/test_source_frame_copy_characterization.json new file mode 100644 index 0000000000..c9899e7007 --- /dev/null +++ b/test/cmocka/build/test-graph.d/test_source_frame_copy_characterization.json @@ -0,0 +1,30 @@ +{ + "schema": 1, + "targets": { + "test_source_frame_copy_characterization": { + "sources": [ + "test/cmocka/test_source_frame_copy_characterization.c" + ], + "libraries": [ + "OBS::libobs", + "SIMDe::SIMDe", + "OBS::caption", + "Uthash::Uthash", + "OBS::native-test-cmocka", + { + "name": "OBS::w32-pthreads", + "requires": "OS_WINDOWS" + } + ] + } + }, + "tests": { + "test_source_frame_copy_characterization": { + "target": "test_source_frame_copy_characterization", + "command": [ + "${target}" + ], + "timeout_seconds": 30 + } + } +}