Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions libobs/build/libobs.core-output+.h.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "libobs/obs-encoder-settings-fields.c.h"
#include "libobs/obs-encoder-state-queries-fields.c.h"
#include "libobs/obs-encoder-type-info-fields.c.h"
#include "libobs/obs-encoder-video-tex-active.c.h"
#include "libobs/obs-encoder.c.h"
#include "libobs/obs-output-active-fields.c.h"
#include "libobs/obs-output-can-pause-fields.c.h"
Expand Down
17 changes: 17 additions & 0 deletions libobs/obs-encoder-video-tex-active.c.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include "libobs/build/libobs.pch.h"

bool obs_encoder_video_tex_active(const obs_encoder_t *encoder, enum video_format format)
{
/* No mix owns the video of an encoder with no video set, or of one
* whose canvas mix is gone (#2267): no texture input then. */
const struct obs_core_video_mix *mix = get_mix_for_video(encoder->media);
if (!mix)
return false;

if (format == VIDEO_FORMAT_NV12)
return mix->using_nv12_tex;
if (format == VIDEO_FORMAT_P010)
return mix->using_p010_tex;

return false;
}
16 changes: 0 additions & 16 deletions libobs/obs-encoder.c.h
Original file line number Diff line number Diff line change
Expand Up @@ -1645,22 +1645,6 @@ void obs_encoder_enum_roi(obs_encoder_t *encoder, void (*enum_proc)(void *, stru
pthread_mutex_unlock(&encoder->roi_mutex);
}

bool obs_encoder_video_tex_active(const obs_encoder_t *encoder, enum video_format format)
{
/* No mix owns the video of an encoder with no video set, or of one
* whose canvas mix is gone (#2267): no texture input then. */
const struct obs_core_video_mix *mix = get_mix_for_video(encoder->media);
if (!mix)
return false;

if (format == VIDEO_FORMAT_NV12)
return mix->using_nv12_tex;
if (format == VIDEO_FORMAT_P010)
return mix->using_p010_tex;

return false;
}

/* File-local macros: keep them out of the next source of a unity build. */
#undef get_weak

Expand Down
25 changes: 25 additions & 0 deletions test/cmocka/build/test-graph.json
Original file line number Diff line number Diff line change
Expand Up @@ -4037,6 +4037,25 @@
"libobs/data"
]
},
"test_encoder_video_tex_active": {
"sources": [
"test/cmocka/test_encoder_video_tex_active.c",
"libobs/obs-encoder-video-tex-active.c.h"
],
"definitions": [
"get_mix_for_video=tex_active_recording_mix_lookup"
],
"libraries": [
"OBS::libobs",
"OBS::caption",
"Uthash::Uthash",
"OBS::native-test-cmocka",
{
"name": "OBS::w32-pthreads",
"requires": "OS_WINDOWS"
}
]
},
"test_encoding_lag_rescale": {
"sources": [
"test/cmocka/test_encoding_lag_rescale.c"
Expand Down Expand Up @@ -22954,6 +22973,12 @@
"working_directory": "${runtime}",
"timeout_seconds": 120
},
"test_encoder_video_tex_active": {
"target": "test_encoder_video_tex_active",
"command": [
"${target}"
]
},
"test_encoding_lag_rescale": {
"target": "test_encoding_lag_rescale",
"command": [
Expand Down
113 changes: 113 additions & 0 deletions test/cmocka/test_encoder_video_tex_active.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/* C-source characterization of obs_encoder_video_tex_active (#5212).
* Compile the current production body with a recording mix lookup and real
* private layouts. This does not characterize GPU support or replace the
* unchanged shared-library checks in test_encoder_tex_active_null.c. A later
* Rust swap must relink this fixture through real private field adapters. */
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include <string.h>
#include "obs-internal.h"

static struct obs_encoder encoder;
static struct obs_core_video_mix mix;
static unsigned char video_token;
static video_t *expected_media;
static struct obs_core_video_mix *lookup_result;
static unsigned lookup_calls;
static bool nv12_after_lookup, p010_after_lookup;

struct obs_core_video_mix *get_mix_for_video(video_t *video)
{
assert_ptr_equal(video, expected_media);
lookup_calls++;
/* The query must read flags after the lookup returns its selected mix. */
mix.using_nv12_tex = nv12_after_lookup;
mix.using_p010_tex = p010_after_lookup;
return lookup_result;
}

static void check_query(enum video_format format, bool expected)
{
unsigned char encoder_before[sizeof(encoder)], mix_before[sizeof(mix)];
mix.using_nv12_tex = nv12_after_lookup;
mix.using_p010_tex = p010_after_lookup;
memcpy(encoder_before, &encoder, sizeof(encoder));
memcpy(mix_before, &mix, sizeof(mix));
lookup_calls = 0;
assert_int_equal(obs_encoder_video_tex_active(&encoder, format), expected);
assert_int_equal(lookup_calls, 1);
assert_memory_equal(&encoder, encoder_before, sizeof(encoder));
assert_memory_equal(&mix, mix_before, sizeof(mix));
}

static int setup(void **state)
{
(void)state;
memset(&encoder, 0, sizeof(encoder));
memset(&mix, 0, sizeof(mix));
expected_media = (video_t *)&video_token;
encoder.media = expected_media;
lookup_result = &mix;
nv12_after_lookup = p010_after_lookup = false;
lookup_calls = 0;
return 0;
}

static void missing_mix(void **state)
{
(void)state;
lookup_result = NULL;
nv12_after_lookup = p010_after_lookup = true;
check_query(VIDEO_FORMAT_NV12, false);
check_query(VIDEO_FORMAT_P010, false);
check_query(VIDEO_FORMAT_RGBA, false);
/* A live encoder with no video still performs the exact NULL lookup. */
encoder.media = expected_media = NULL;
check_query(VIDEO_FORMAT_NV12, false);
check_query(VIDEO_FORMAT_P010, false);
check_query(VIDEO_FORMAT_NONE, false);
}

static void format_and_flag_matrix(void **state)
{
(void)state;
for (unsigned flags = 0; flags < 4; flags++) {
nv12_after_lookup = (flags & 1) != 0;
p010_after_lookup = (flags & 2) != 0;
/* The real enum is contiguous, NONE through R10L; no host defaults. */
for (enum video_format format = VIDEO_FORMAT_NONE; format <= VIDEO_FORMAT_R10L; format++) {
bool expected = (format == VIDEO_FORMAT_NV12 && nv12_after_lookup) ||
(format == VIDEO_FORMAT_P010 && p010_after_lookup);
check_query(format, expected);
}
}
}

static void reads_selected_mix_after_lookup(void **state)
{
(void)state;
for (unsigned flags = 0; flags < 4; flags++) {
nv12_after_lookup = (flags & 1) != 0;
p010_after_lookup = (flags & 2) != 0;
mix.using_nv12_tex = !nv12_after_lookup;
mix.using_p010_tex = !p010_after_lookup;
lookup_calls = 0;
assert_int_equal(obs_encoder_video_tex_active(&encoder, VIDEO_FORMAT_NV12), nv12_after_lookup);
assert_int_equal(lookup_calls, 1);
mix.using_nv12_tex = !nv12_after_lookup;
mix.using_p010_tex = !p010_after_lookup;
lookup_calls = 0;
assert_int_equal(obs_encoder_video_tex_active(&encoder, VIDEO_FORMAT_P010), p010_after_lookup);
assert_int_equal(lookup_calls, 1);
}
}

int main(void)
{
const struct CMUnitTest tests[] = {cmocka_unit_test_setup(missing_mix, setup),
cmocka_unit_test_setup(format_and_flag_matrix, setup),
cmocka_unit_test_setup(reads_selected_mix_after_lookup, setup)};
return cmocka_run_group_tests(tests, NULL, NULL);
}
1 change: 1 addition & 0 deletions test/cmocka/tests.d/test_encoder_video_tex_active.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Registered in the canonical native test graph (test/cmocka/build/test-graph.json).
Loading