libobs,docs: Add protocol enumeration functions

This commit is contained in:
tytan652 2022-09-05 14:58:27 +02:00
parent 813b3b2763
commit 56411eda8e
4 changed files with 61 additions and 0 deletions

View file

@ -709,6 +709,24 @@ General Output Functions
---------------------
.. function:: bool obs_enum_output_protocols(size_t idx, char **protocol)
Enumerates all registered protocol.
---------------------
.. function:: void obs_enum_output_types_with_protocol(const char *protocol, void *data, bool (*enum_cb)(void *data, const char *id))
Enumerates through a callback all available output types for the given protocol.
:param protocol: Protocol of the outputs to enumerate
:param data: Data passed to the callback
:param enum_cb: Callback used when a matching output is found, the id
of the output is passed to the callback
:return: When all outputs are enumerated or if the callback return *false*
---------------------
Functions used by outputs
-------------------------

View file

@ -2723,3 +2723,31 @@ const char *obs_output_get_protocols(const obs_output_t *output)
? output->info.protocols
: NULL;
}
void obs_enum_output_types_with_protocol(const char *protocol, void *data,
bool (*enum_cb)(void *data,
const char *id))
{
if (!obs_is_output_protocol_registered(protocol))
return;
size_t protocol_len = strlen(protocol);
for (size_t i = 0; i < obs->output_types.num; i++) {
if (!(obs->output_types.array[i].flags & OBS_OUTPUT_SERVICE))
continue;
const char *substr = obs->output_types.array[i].protocols;
while (substr && substr[0] != '\0') {
const char *next = strchr(substr, ';');
size_t len = next ? (size_t)(next - substr)
: strlen(substr);
if (protocol_len == len &&
strncmp(substr, protocol, len) == 0) {
if (!enum_cb(data,
obs->output_types.array[i].id))
return;
}
substr = next ? next + 1 : NULL;
}
}
}

View file

@ -3466,3 +3466,12 @@ bool obs_is_output_protocol_registered(const char *protocol)
return false;
}
bool obs_enum_output_protocols(size_t idx, char **protocol)
{
if (idx >= obs->data.protocols.num)
return false;
*protocol = obs->data.protocols.array[idx];
return true;
}

View file

@ -2215,6 +2215,12 @@ EXPORT const char *obs_output_get_protocols(const obs_output_t *output);
EXPORT bool obs_is_output_protocol_registered(const char *protocol);
EXPORT bool obs_enum_output_protocols(size_t idx, char **protocol);
EXPORT void obs_enum_output_types_with_protocol(
const char *protocol, void *data,
bool (*enum_cb)(void *data, const char *id));
/* ------------------------------------------------------------------------- */
/* Functions used by outputs */