From a68976a08f0d1bc9f5c36017f019022fd1e5d31e Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Thu, 19 Nov 2026 14:44:40 -0800 Subject: [PATCH 1/2] test: characterize output last-error query before extraction (Refs #5294) --- test/cmocka/build/test-graph.json | 22 ++ test/cmocka/test_output_get_last_error.c | 227 ++++++++++++++++++ .../tests.d/test_output_get_last_error.cmake | 1 + 3 files changed, 250 insertions(+) create mode 100644 test/cmocka/test_output_get_last_error.c create mode 100644 test/cmocka/tests.d/test_output_get_last_error.cmake diff --git a/test/cmocka/build/test-graph.json b/test/cmocka/build/test-graph.json index 22b80a4eff..7027d02b9c 100644 --- a/test/cmocka/build/test-graph.json +++ b/test/cmocka/build/test-graph.json @@ -10286,6 +10286,21 @@ } ] }, + "test_output_get_last_error": { + "sources": [ + "test/cmocka/test_output_get_last_error.c" + ], + "libraries": [ + "OBS::libobs", + "OBS::caption", + "Uthash::Uthash", + "OBS::native-test-cmocka", + { + "name": "OBS::w32-pthreads", + "requires": "OS_WINDOWS" + } + ] + }, "test_output_handler_getters": { "sources": [ "test/cmocka/test_output_handler_getters.c" @@ -25644,6 +25659,13 @@ "${target}" ] }, + "test_output_get_last_error": { + "target": "test_output_get_last_error", + "command": [ + "${target}" + ], + "timeout_seconds": 30 + }, "test_output_handler_getters": { "target": "test_output_handler_getters", "command": [ diff --git a/test/cmocka/test_output_get_last_error.c b/test/cmocka/test_output_get_last_error.c new file mode 100644 index 0000000000..42d624792d --- /dev/null +++ b/test/cmocka/test_output_get_last_error.c @@ -0,0 +1,227 @@ +/* Characterize the original C source and the loaded public API (#5294). + * The future Rust swap can define OUTPUT_LAST_ERROR_EXTERNAL to run these + * unchanged assertions solely against its public symbol. No fake objects. */ +#include +#include +#include +#include +#include +#include +#include "obs-internal.h" + +#ifndef OUTPUT_LAST_ERROR_EXTERNAL +#ifndef OUTPUT_LAST_ERROR_SOURCE +#define OUTPUT_LAST_ERROR_SOURCE "libobs/obs-output-get-last-error.c.h" +#endif +#define obs_output_get_last_error output_last_error_original_c +#include OUTPUT_LAST_ERROR_SOURCE +#undef obs_output_get_last_error +#endif + +static obs_output_t *output; +static obs_encoder_t *video[MAX_OUTPUT_VIDEO_ENCODERS]; +static obs_encoder_t *audio[MAX_OUTPUT_AUDIO_ENCODERS]; +static unsigned log_count; +static int log_level; +static char log_message[128]; + +#if defined(__GNUC__) || defined(__clang__) +static void capture_log(int level, const char *format, va_list args, void *param) __attribute__((format(printf, 2, 0))); +#endif +static void capture_log(int level, const char *format, va_list args, void *param) +{ + (void)param; + log_count++; + log_level = level; + vsnprintf(log_message, sizeof(log_message), format, args); +} + +static const char *type_name(void *data) +{ + (void)data; + return "last-error characterization"; +} + +static void *output_create(obs_data_t *settings, obs_output_t *owner) +{ + (void)settings; + return owner; +} + +static void output_destroy(void *data) +{ + (void)data; +} + +static bool output_start(void *data) +{ + (void)data; + return false; +} + +static void output_stop(void *data, uint64_t ts) +{ + (void)data; + (void)ts; +} + +static void output_packet(void *data, struct encoder_packet *packet) +{ + (void)data; + (void)packet; +} + +static int setup(void **state) +{ + (void)state; + assert_true(obs_startup("en-US", NULL, NULL)); + struct obs_output_info info = { + .id = "last_error_output", + .flags = OBS_OUTPUT_AV | OBS_OUTPUT_ENCODED | OBS_OUTPUT_MULTI_TRACK | OBS_OUTPUT_MULTI_TRACK_VIDEO, + .get_name = type_name, + .create = output_create, + .destroy = output_destroy, + .start = output_start, + .stop = output_stop, + .encoded_packet = output_packet, + }; + obs_register_output(&info); + output = obs_output_create(info.id, "last-error output", NULL, NULL); + assert_non_null(output); + /* Unregistered IDs still create real, inactive C encoder objects. There + * is no encoding, media setup or plugin callback in this query test. */ + for (size_t i = 0; i < MAX_OUTPUT_VIDEO_ENCODERS; i++) { + video[i] = obs_video_encoder_create("last_error_video", "video", NULL, NULL); + assert_non_null(video[i]); + } + for (size_t i = 0; i < MAX_OUTPUT_AUDIO_ENCODERS; i++) { + audio[i] = obs_audio_encoder_create("last_error_audio", "audio", NULL, i, NULL); + assert_non_null(audio[i]); + } + return 0; +} + +static int teardown(void **state) +{ + (void)state; + obs_output_release(output); + for (size_t i = 0; i < MAX_OUTPUT_VIDEO_ENCODERS; i++) + obs_encoder_release(video[i]); + for (size_t i = 0; i < MAX_OUTPUT_AUDIO_ENCODERS; i++) + obs_encoder_release(audio[i]); + obs_shutdown(); + return 0; +} + +static void check_query(obs_output_t *owner, const char *expected) +{ + log_handler_t old_handler; + void *old_param; + base_get_log_handler(&old_handler, &old_param); + base_set_log_handler(capture_log, NULL); + log_count = 0; + long allocations = bnum_allocs(); + const char *actual = obs_output_get_last_error(owner); + unsigned count = log_count; + int actual_level = log_level; + char actual_message[sizeof(log_message)]; + memcpy(actual_message, log_message, sizeof(actual_message)); +#ifndef OUTPUT_LAST_ERROR_EXTERNAL + const char *original = output_last_error_original_c(owner); +#endif + base_set_log_handler(old_handler, old_param); + assert_ptr_equal(actual, expected); +#ifndef OUTPUT_LAST_ERROR_EXTERNAL + assert_ptr_equal(original, expected); + assert_int_equal(log_count, 2 * count); +#endif + assert_int_equal(bnum_allocs(), allocations); + assert_int_equal(count, owner ? 0 : 1); + if (!owner) { + assert_int_equal(actual_level, LOG_DEBUG); + assert_string_equal(actual_message, "obs_output_get_last_error: Null 'output' parameter"); + assert_int_equal(log_level, LOG_DEBUG); + assert_string_equal(log_message, "obs_output_get_last_error: Null 'output' parameter"); + } else if (expected) { + assert_string_equal(actual, expected); + } +} + +static void null_diagnostic(void **state) +{ + (void)state; + check_query(NULL, NULL); +} + +static void fallback_order_and_borrowing(void **state) +{ + (void)state; + check_query(output, NULL); + /* Attach every slot through the real ownership APIs. NULL errors on + * present encoders must be skipped just like empty encoder slots. */ + for (size_t i = 0; i < MAX_OUTPUT_VIDEO_ENCODERS; i++) { + obs_output_set_video_encoder2(output, video[i], i); + assert_ptr_equal(output->video_encoders[i], video[i]); + } + for (size_t i = 0; i < MAX_OUTPUT_AUDIO_ENCODERS; i++) { + obs_output_set_audio_encoder(output, audio[i], i); + assert_ptr_equal(output->audio_encoders[i], audio[i]); + } + check_query(output, NULL); + /* Equal bytes in independent allocations expose copying and returning + * the wrong encoder even when a string-only assertion would pass. */ + for (size_t i = 0; i < MAX_OUTPUT_AUDIO_ENCODERS; i++) + obs_encoder_set_last_error(audio[i], "same error"); + for (size_t i = 0; i < MAX_OUTPUT_VIDEO_ENCODERS; i++) + obs_encoder_set_last_error(video[i], "same error"); + obs_output_set_last_error(output, "same error"); + check_query(output, output->last_error_message); + /* Characterized, not endorsed: empty strings are errors, not fallback. */ + obs_output_set_last_error(output, ""); + check_query(output, output->last_error_message); + obs_output_set_last_error(output, NULL); + for (size_t i = 0; i < MAX_OUTPUT_VIDEO_ENCODERS; i++) { + check_query(output, video[i]->last_error_message); + obs_encoder_set_last_error(video[i], ""); + check_query(output, video[i]->last_error_message); + obs_encoder_set_last_error(video[i], NULL); + check_query(output, i + 1 < MAX_OUTPUT_VIDEO_ENCODERS ? video[i + 1]->last_error_message + : audio[0]->last_error_message); + obs_output_set_video_encoder2(output, NULL, i); + } + for (size_t i = 0; i < MAX_OUTPUT_AUDIO_ENCODERS; i++) { + check_query(output, audio[i]->last_error_message); + obs_encoder_set_last_error(audio[i], ""); + check_query(output, audio[i]->last_error_message); + obs_encoder_set_last_error(audio[i], NULL); + check_query(output, i + 1 < MAX_OUTPUT_AUDIO_ENCODERS ? audio[i + 1]->last_error_message : NULL); + obs_output_set_audio_encoder(output, NULL, i); + } + check_query(output, NULL); + /* Last-slot errors with holes before them, including non-UTF-8 bytes. */ + const char bytes[] = {(char)0xff, (char)0x80, 'x', 0}; + obs_encoder_t *last_video = video[MAX_OUTPUT_VIDEO_ENCODERS - 1]; + obs_encoder_t *last_audio = audio[MAX_OUTPUT_AUDIO_ENCODERS - 1]; + obs_output_set_video_encoder2(output, last_video, MAX_OUTPUT_VIDEO_ENCODERS - 1); + obs_output_set_audio_encoder(output, last_audio, MAX_OUTPUT_AUDIO_ENCODERS - 1); + obs_encoder_set_last_error(last_video, bytes); + obs_encoder_set_last_error(last_audio, bytes); + /* A borrowed query must not acquire the encoder error mutexes. Holding + * both on this thread makes an added lock fail the CTest timeout. */ + assert_int_equal(pthread_mutex_lock(&last_video->last_error_mutex), 0); + assert_int_equal(pthread_mutex_lock(&last_audio->last_error_mutex), 0); + check_query(output, last_video->last_error_message); + assert_int_equal(pthread_mutex_unlock(&last_audio->last_error_mutex), 0); + assert_int_equal(pthread_mutex_unlock(&last_video->last_error_mutex), 0); + obs_output_set_video_encoder2(output, NULL, MAX_OUTPUT_VIDEO_ENCODERS - 1); + check_query(output, last_audio->last_error_message); + obs_output_set_audio_encoder(output, NULL, MAX_OUTPUT_AUDIO_ENCODERS - 1); + check_query(output, NULL); +} + +int main(void) +{ + const struct CMUnitTest tests[] = {cmocka_unit_test(null_diagnostic), + cmocka_unit_test(fallback_order_and_borrowing)}; + return cmocka_run_group_tests(tests, setup, teardown); +} diff --git a/test/cmocka/tests.d/test_output_get_last_error.cmake b/test/cmocka/tests.d/test_output_get_last_error.cmake new file mode 100644 index 0000000000..d85a840326 --- /dev/null +++ b/test/cmocka/tests.d/test_output_get_last_error.cmake @@ -0,0 +1 @@ +# Registered in the canonical native test graph (test/cmocka/build/test-graph.json). From b127671fc370d33fb15d38df4fdee82d88c5347d Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Thu, 19 Nov 2026 14:54:25 -0800 Subject: [PATCH 2/2] libobs: extract output last-error query without behavior changes (Refs #5294) Ci-Attestation: {"at":1795131212,"gate":"data/all/compatibility","host":"linux-x86_64","key":"","lane":"client-checks","parents":["a68976a08f0d1bc9f5c36017f019022fd1e5d31e"],"secs":517,"stamp":"ed5a2daf8617493831edb67dcc9bd4a8","tree":"ed5df9640d9921f2b783ec04c2aea36706b13735","v":1,"via":"run"} Ci-Attestation: {"at":1795131212,"gate":"data/all/flatpak-manifest","host":"linux-x86_64","key":"","lane":"client-checks","parents":["a68976a08f0d1bc9f5c36017f019022fd1e5d31e"],"secs":517,"stamp":"ce80d8548e67071a26ce308f8d1e0f31","tree":"ed5df9640d9921f2b783ec04c2aea36706b13735","v":1,"via":"run"} Ci-Attestation: {"at":1795131212,"gate":"data/all/qt-xml","host":"linux-x86_64","key":"","lane":"client-checks","parents":["a68976a08f0d1bc9f5c36017f019022fd1e5d31e"],"secs":517,"stamp":"eb047c7d661e22e628a4bcdbedca778b","tree":"ed5df9640d9921f2b783ec04c2aea36706b13735","v":1,"via":"run"} Ci-Attestation: {"at":1795131212,"gate":"data/all/services-schema","host":"linux-x86_64","key":"","lane":"client-checks","parents":["a68976a08f0d1bc9f5c36017f019022fd1e5d31e"],"secs":517,"stamp":"fd5cb682db5c311bf7e35f1a99e8f880","tree":"ed5df9640d9921f2b783ec04c2aea36706b13735","v":1,"via":"run"} Ci-Attestation: {"at":1795130681,"gate":"general/all/client-lint","host":"linux-x86_64","key":"9269d688027752940c66c131def31dc4d45e4786ec276e89e2ca882ce8f6da43","lane":"client-lint","parents":["a68976a08f0d1bc9f5c36017f019022fd1e5d31e"],"secs":130,"stamp":"a1e7fc00ee54b572fa95ef99ddc12ce8","tree":"ed5df9640d9921f2b783ec04c2aea36706b13735","v":1,"via":"run"} Ci-Attestation: {"at":1795131212,"gate":"python/all/self-test","host":"linux-x86_64","key":"","lane":"client-checks","parents":["a68976a08f0d1bc9f5c36017f019022fd1e5d31e"],"secs":517,"stamp":"7dce04ea0f8ddcefc2a3ccd56a04f232","tree":"ed5df9640d9921f2b783ec04c2aea36706b13735","v":1,"via":"run"} Ci-Attestation: {"at":1795130684,"gate":"rust/aarch64-apple-darwin/client-clippy","host":"linux-x86_64","key":"9269d688027752940c66c131def31dc4d45e4786ec276e89e2ca882ce8f6da43","lane":"client-lint","parents":["a68976a08f0d1bc9f5c36017f019022fd1e5d31e"],"secs":130,"stamp":"90757cf9d22b004eca57923d55265468","tree":"ed5df9640d9921f2b783ec04c2aea36706b13735","v":1,"via":"run"} Ci-Attestation: {"at":1795130684,"gate":"rust/aarch64-apple-darwin/client-dylint","host":"linux-x86_64","key":"9269d688027752940c66c131def31dc4d45e4786ec276e89e2ca882ce8f6da43","lane":"client-lint","parents":["a68976a08f0d1bc9f5c36017f019022fd1e5d31e"],"secs":130,"stamp":"165f5c7e513b5bd6f6a85347a856f92d","tree":"ed5df9640d9921f2b783ec04c2aea36706b13735","v":1,"via":"run"} Ci-Attestation: {"at":1795130683,"gate":"rust/aarch64-pc-windows-msvc/client-clippy","host":"linux-x86_64","key":"9269d688027752940c66c131def31dc4d45e4786ec276e89e2ca882ce8f6da43","lane":"client-lint","parents":["a68976a08f0d1bc9f5c36017f019022fd1e5d31e"],"secs":130,"stamp":"87a0274f058bca7749a1bf5c076d3d1b","tree":"ed5df9640d9921f2b783ec04c2aea36706b13735","v":1,"via":"run"} Ci-Attestation: {"at":1795130683,"gate":"rust/aarch64-pc-windows-msvc/client-dylint","host":"linux-x86_64","key":"9269d688027752940c66c131def31dc4d45e4786ec276e89e2ca882ce8f6da43","lane":"client-lint","parents":["a68976a08f0d1bc9f5c36017f019022fd1e5d31e"],"secs":130,"stamp":"5df6301fd93b2c95f08c79ca0b4e4c4d","tree":"ed5df9640d9921f2b783ec04c2aea36706b13735","v":1,"via":"run"} Ci-Attestation: {"at":1795130682,"gate":"rust/aarch64-unknown-linux-gnu/client-clippy","host":"linux-x86_64","key":"9269d688027752940c66c131def31dc4d45e4786ec276e89e2ca882ce8f6da43","lane":"client-lint","parents":["a68976a08f0d1bc9f5c36017f019022fd1e5d31e"],"secs":130,"stamp":"e14705980c40fab198c9130194595e0f","tree":"ed5df9640d9921f2b783ec04c2aea36706b13735","v":1,"via":"run"} Ci-Attestation: {"at":1795130682,"gate":"rust/aarch64-unknown-linux-gnu/client-dylint","host":"linux-x86_64","key":"9269d688027752940c66c131def31dc4d45e4786ec276e89e2ca882ce8f6da43","lane":"client-lint","parents":["a68976a08f0d1bc9f5c36017f019022fd1e5d31e"],"secs":130,"stamp":"943bf5b3b44e4b482cd40349215191bb","tree":"ed5df9640d9921f2b783ec04c2aea36706b13735","v":1,"via":"run"} Ci-Attestation: {"at":1795130684,"gate":"rust/x86_64-apple-darwin/client-clippy","host":"linux-x86_64","key":"9269d688027752940c66c131def31dc4d45e4786ec276e89e2ca882ce8f6da43","lane":"client-lint","parents":["a68976a08f0d1bc9f5c36017f019022fd1e5d31e"],"secs":130,"stamp":"b9cedd06d533a60dc55ba72d894991f1","tree":"ed5df9640d9921f2b783ec04c2aea36706b13735","v":1,"via":"run"} Ci-Attestation: {"at":1795130684,"gate":"rust/x86_64-apple-darwin/client-dylint","host":"linux-x86_64","key":"9269d688027752940c66c131def31dc4d45e4786ec276e89e2ca882ce8f6da43","lane":"client-lint","parents":["a68976a08f0d1bc9f5c36017f019022fd1e5d31e"],"secs":130,"stamp":"a1d4b1d116a7f7ac85f009b8994148a5","tree":"ed5df9640d9921f2b783ec04c2aea36706b13735","v":1,"via":"run"} Ci-Attestation: {"at":1795130683,"gate":"rust/x86_64-pc-windows-msvc/client-clippy","host":"linux-x86_64","key":"9269d688027752940c66c131def31dc4d45e4786ec276e89e2ca882ce8f6da43","lane":"client-lint","parents":["a68976a08f0d1bc9f5c36017f019022fd1e5d31e"],"secs":130,"stamp":"47f091849d4670418e1b44ec00bc4a92","tree":"ed5df9640d9921f2b783ec04c2aea36706b13735","v":1,"via":"run"} Ci-Attestation: {"at":1795130683,"gate":"rust/x86_64-pc-windows-msvc/client-dylint","host":"linux-x86_64","key":"9269d688027752940c66c131def31dc4d45e4786ec276e89e2ca882ce8f6da43","lane":"client-lint","parents":["a68976a08f0d1bc9f5c36017f019022fd1e5d31e"],"secs":130,"stamp":"2298794a6ef45d83a4cd44a60f73ab59","tree":"ed5df9640d9921f2b783ec04c2aea36706b13735","v":1,"via":"run"} Ci-Attestation: {"at":1795130681,"gate":"rust/x86_64-unknown-linux-gnu/client-clippy","host":"linux-x86_64","key":"9269d688027752940c66c131def31dc4d45e4786ec276e89e2ca882ce8f6da43","lane":"client-lint","parents":["a68976a08f0d1bc9f5c36017f019022fd1e5d31e"],"secs":130,"stamp":"2b20b95d554462b5e766e582a904678a","tree":"ed5df9640d9921f2b783ec04c2aea36706b13735","v":1,"via":"run"} Ci-Attestation: {"at":1795130682,"gate":"rust/x86_64-unknown-linux-gnu/client-dylint","host":"linux-x86_64","key":"9269d688027752940c66c131def31dc4d45e4786ec276e89e2ca882ce8f6da43","lane":"client-lint","parents":["a68976a08f0d1bc9f5c36017f019022fd1e5d31e"],"secs":130,"stamp":"8e9a613bd2f1c216365f1fbc6d89a462","tree":"ed5df9640d9921f2b783ec04c2aea36706b13735","v":1,"via":"run"} Ci-Attestation: {"at":1795132885,"gate":"rust/x86_64-unknown-linux-gnu/client-test","host":"linux-x86_64","key":"88c67cc76a86078d8fe7e07a05faaf2dfaa1c9bbeb0cdebf87c802686385b0c5","lane":"client-test-x86_64-unknown-linux-gnu","parents":["a68976a08f0d1bc9f5c36017f019022fd1e5d31e"],"secs":1657,"stamp":"1acf7a005c76e1e400159f2cd7321a97","tree":"ed5df9640d9921f2b783ec04c2aea36706b13735","v":1,"via":"run"} Client-Checks: {"checks":{"base":"9d8624941fa5ca0d9458492af07dddc9103347d4","coverage":"all-tracked-applicable-files","diff":["ci/local_gate.py","ci/test_hotkey_register_extraction.py","ci/test_local_gate.py","libobs/build/libobs.core+.h.c","libobs/build/libobs.core-output+.h.c","libobs/obs-hotkey-combination-background-id.c.h","libobs/obs-hotkey.c.h","libobs/obs-output-get-last-error.c.h","libobs/obs-output.c.h","rust/obs-build/tests/native/registration/headless_characterizations_expected.json","rust/obs-build/tests/native/registration/portal_output_expected.json","rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_hotkey_background_enum.json","rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_hotkey_background_press.json","rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_hotkey_background_trigger.json","rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_hotkey_binding_press_steps.json","rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_hotkey_getters_characterization.json","rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_hotkey_load.json","rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_hotkey_pair_steps.json","rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_hotkey_press_steps.json","rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_hotkey_unregister_entry.json","rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_portal_shortcuts.json","rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_wayland_hotkeys.json","test/cmocka/build/test-graph.json","test/cmocka/test_hotkey_combination_background_id.c","test/cmocka/test_output_get_last_error.c","test/cmocka/tests.d/test_hotkey_combination_background_id.cmake","test/cmocka/tests.d/test_output_get_last_error.cmake"],"head":"c2b1469d9739243ccc56bf374d9a5f6e169b9001","tools":{"orchestrator-python":"3.14.7 (main, Aug 14 2026, 15:35:28) [Clang 22.1.3 ]","schema-dependencies":"3.14.7 (main, Aug 14 2026, 15:35:28) [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 21504\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":"01b3df18e18d17cb2c008dcb7203be71451e8858f048c57fc804063a7e1aeb94","tree":"ed5df9640d9921f2b783ec04c2aea36706b13735"}} --- libobs/build/libobs.core-output+.h.c | 1 + libobs/obs-output-get-last-error.c.h | 27 ++++++++++++++++ libobs/obs-output.c.h | 26 --------------- test/cmocka/test_output_get_last_error.c | 41 ++++++++++++++++++++++-- 4 files changed, 66 insertions(+), 29 deletions(-) create mode 100644 libobs/obs-output-get-last-error.c.h diff --git a/libobs/build/libobs.core-output+.h.c b/libobs/build/libobs.core-output+.h.c index fdd98c5197..48aabb5dc5 100644 --- a/libobs/build/libobs.core-output+.h.c +++ b/libobs/build/libobs.core-output+.h.c @@ -49,6 +49,7 @@ #include "libobs/obs-output-enum-types-with-protocol.c.h" #include "libobs/obs-output-flags-fields.c.h" #include "libobs/obs-output-frames-dropped-fields.c.h" +#include "libobs/obs-output-get-last-error.c.h" #include "libobs/obs-output-handler-getters-fields.c.h" #include "libobs/obs-output-identity-fields.c.h" #include "libobs/obs-output-interleave-name-fields.c.h" diff --git a/libobs/obs-output-get-last-error.c.h b/libobs/obs-output-get-last-error.c.h new file mode 100644 index 0000000000..058364d2e2 --- /dev/null +++ b/libobs/obs-output-get-last-error.c.h @@ -0,0 +1,27 @@ +#include "libobs/build/libobs.pch.h" + +const char *obs_output_get_last_error(obs_output_t *output) +{ + if (!obs_output_valid(output, "obs_output_get_last_error")) + return NULL; + + if (output->last_error_message) { + return output->last_error_message; + } else { + for (size_t i = 0; i < MAX_OUTPUT_VIDEO_ENCODERS; i++) { + obs_encoder_t *vencoder = output->video_encoders[i]; + if (vencoder && vencoder->last_error_message) { + return vencoder->last_error_message; + } + } + + for (size_t i = 0; i < MAX_OUTPUT_AUDIO_ENCODERS; i++) { + obs_encoder_t *aencoder = output->audio_encoders[i]; + if (aencoder && aencoder->last_error_message) { + return aencoder->last_error_message; + } + } + } + + return NULL; +} diff --git a/libobs/obs-output.c.h b/libobs/obs-output.c.h index 33d84eff5f..c70bed081a 100644 --- a/libobs/obs-output.c.h +++ b/libobs/obs-output.c.h @@ -2262,32 +2262,6 @@ void obs_output_output_caption_text2(obs_output_t *output, const char *text, dou } } -const char *obs_output_get_last_error(obs_output_t *output) -{ - if (!obs_output_valid(output, "obs_output_get_last_error")) - return NULL; - - if (output->last_error_message) { - return output->last_error_message; - } else { - for (size_t i = 0; i < MAX_OUTPUT_VIDEO_ENCODERS; i++) { - obs_encoder_t *vencoder = output->video_encoders[i]; - if (vencoder && vencoder->last_error_message) { - return vencoder->last_error_message; - } - } - - for (size_t i = 0; i < MAX_OUTPUT_AUDIO_ENCODERS; i++) { - obs_encoder_t *aencoder = output->audio_encoders[i]; - if (aencoder && aencoder->last_error_message) { - return aencoder->last_error_message; - } - } - } - - return NULL; -} - /* File-local macros: keep them out of the next source of a unity build. */ #undef get_weak diff --git a/test/cmocka/test_output_get_last_error.c b/test/cmocka/test_output_get_last_error.c index 42d624792d..c4734349d2 100644 --- a/test/cmocka/test_output_get_last_error.c +++ b/test/cmocka/test_output_get_last_error.c @@ -71,6 +71,27 @@ static void output_packet(void *data, struct encoder_packet *packet) (void)packet; } +static void *encoder_create(obs_data_t *settings, obs_encoder_t *owner) +{ + (void)settings; + return owner; +} + +static bool encoder_encode(void *data, struct encoder_frame *frame, struct encoder_packet *packet, bool *received) +{ + (void)data; + (void)frame; + (void)packet; + *received = false; + return true; +} + +static size_t encoder_frame_size(void *data) +{ + (void)data; + return 1024; +} + static int setup(void **state) { (void)state; @@ -88,8 +109,22 @@ static int setup(void **state) obs_register_output(&info); output = obs_output_create(info.id, "last-error output", NULL, NULL); assert_non_null(output); - /* Unregistered IDs still create real, inactive C encoder objects. There - * is no encoding, media setup or plugin callback in this query test. */ + struct obs_encoder_info encoder_info = { + .id = "last_error_video", + .type = OBS_ENCODER_VIDEO, + .codec = "h264", + .get_name = type_name, + .create = encoder_create, + .destroy = output_destroy, + .encode = encoder_encode, + }; + obs_register_encoder(&encoder_info); + encoder_info.id = "last_error_audio"; + encoder_info.type = OBS_ENCODER_AUDIO; + encoder_info.codec = "aac"; + encoder_info.get_frame_size = encoder_frame_size; + obs_register_encoder(&encoder_info); + /* Real, inactive objects: no encoding or media setup is needed. */ for (size_t i = 0; i < MAX_OUTPUT_VIDEO_ENCODERS; i++) { video[i] = obs_video_encoder_create("last_error_video", "video", NULL, NULL); assert_non_null(video[i]); @@ -186,7 +221,7 @@ static void fallback_order_and_borrowing(void **state) check_query(output, video[i]->last_error_message); obs_encoder_set_last_error(video[i], NULL); check_query(output, i + 1 < MAX_OUTPUT_VIDEO_ENCODERS ? video[i + 1]->last_error_message - : audio[0]->last_error_message); + : audio[0]->last_error_message); obs_output_set_video_encoder2(output, NULL, i); } for (size_t i = 0; i < MAX_OUTPUT_AUDIO_ENCODERS; i++) {