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 ci/test_ported_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"obs-source-draw-plan.c.h.o",
"obs-source-frame-copy.c.h.o",
"obs-source-load.c.h.o",
"obs-source-media-admission.c.h.o",
"obs-source-ptm-gate.c.h.o",
"obs-source-render-route.c.h.o",
"obs-source-size.c.h.o",
Expand Down
10 changes: 10 additions & 0 deletions libobs/build/libobs-ported-source-media-admission.pch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* Precompiled header (BUILD.md) for the libobs unity group
* libobs.ported-source-media-admission. obs-source-media-admission.c needs
* only its declarations (obs-source-media-admission.h, with stdbool.h,
* stddef.h and stdint.h, and the libobs values it mirrors), not the core, so
* the C oracle and the C test can compile it on its own. The implementation
* file includes this header and nothing else. */

#pragma once

#include "libobs/obs-source-media-admission.h"
1 change: 1 addition & 0 deletions libobs/build/libobs.pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@
#include "obs-source-conversion-plan.h"
#include "obs-source-draw-plan.h"
#include "obs-source-frame-copy.h"
#include "obs-source-media-admission.h"
#include "obs-source-ptm-gate.h"
#include "obs-source-render-route.h"
#include "obs-source-size.h"
Expand Down
5 changes: 5 additions & 0 deletions libobs/build/libobs.ported-source-media-admission+.h.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* Unity group (BUILD.md): ported obs-source-media-admission.c. */

#include "libobs/build/libobs-ported-source-media-admission.pch.h"

#include "libobs/obs-source-media-admission.c.h"
2 changes: 2 additions & 0 deletions libobs/build/source-sets.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"obs-source-draw-technique.h",
"obs-source-frame-copy.h",
"obs-source-load.h",
"obs-source-media-admission.h",
"obs-source-ptm-gate.h",
"obs-source-render-route.h",
"obs-source-size.h",
Expand Down Expand Up @@ -199,6 +200,7 @@
"build/libobs.ported-source-draw-plan+.h.c",
"build/libobs.ported-source-frame-copy+.h.c",
"build/libobs.ported-source-load+.h.c",
"build/libobs.ported-source-media-admission+.h.c",
"build/libobs.ported-source-profiler+.h.c",
"build/libobs.ported-source-ptm-gate+.h.c",
"build/libobs.ported-source-render-route+.h.c",
Expand Down
10 changes: 10 additions & 0 deletions libobs/cmake/rust-exports.map
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,16 @@
obs_source_frame_copy_full_range;
obs_source_frame_copy_full_range2;
obs_source_frame_copy_preload_changed;
/* obs-source-media-admission.c. obs-source.c calls them inside libobs.
* Not EXPORT. */
obs_source_media_admit;
obs_source_media_admit_flags;
obs_source_media_admit_callback;
obs_source_media_time_fallback;
obs_source_media_state_fallback;
obs_source_media_dispatch;
obs_source_media_signal_reads_pause;
obs_source_media_signal;
/* obs-source-ptm-gate.c. obs-source.c calls them inside libobs. Not
* EXPORT. */
obs_source_ptm_gate_stop_time;
Expand Down
12 changes: 12 additions & 0 deletions libobs/cmake/rust-hidden.txt
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,18 @@ obs_source_frame_copy_cache_clean
obs_source_frame_copy_full_range
obs_source_frame_copy_full_range2
obs_source_frame_copy_preload_changed
# obs-source-media-admission.c: the obs_source_media_*() functions and
# process_media_actions() in obs-source.c call them inside libobs. Declared in
# obs-source-media-admission.h without EXPORT, so the shims stay hidden the
# same way.
obs_source_media_admit
obs_source_media_admit_flags
obs_source_media_admit_callback
obs_source_media_time_fallback
obs_source_media_state_fallback
obs_source_media_dispatch
obs_source_media_signal_reads_pause
obs_source_media_signal
# obs-source-ptm-gate.c: source_muted() and get_source_volume() in
# obs-source.c call them inside libobs. Declared in obs-source-ptm-gate.h
# without EXPORT, so the shims stay hidden the same way.
Expand Down
10 changes: 10 additions & 0 deletions libobs/cmake/rust-unexports-macos.txt
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,16 @@ _obs_source_frame_copy_cache_clean
_obs_source_frame_copy_full_range
_obs_source_frame_copy_full_range2
_obs_source_frame_copy_preload_changed
# obs-source-media-admission.c: obs-source.c calls them inside libobs. Not
# EXPORT.
_obs_source_media_admit
_obs_source_media_admit_flags
_obs_source_media_admit_callback
_obs_source_media_time_fallback
_obs_source_media_state_fallback
_obs_source_media_dispatch
_obs_source_media_signal_reads_pause
_obs_source_media_signal
# obs-source-ptm-gate.c: obs-source.c calls them inside libobs. Not EXPORT.
_obs_source_ptm_gate_stop_time
_obs_source_ptm_gate_held
Expand Down
129 changes: 129 additions & 0 deletions libobs/obs-source-media-admission.c.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/******************************************************************************
Copyright (C) 2023 by Lain Bailey <lain@obsproject.com>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/

#include "libobs/build/libobs-ported-source-media-admission.pch.h"

/* The media action admission decisions of obs-source.c, moved from the
* obs_source_media_*() functions (the controllable and callback checks and
* the getters' fallbacks) and process_media_actions() (the callback and
* signal of each queued action): the decisions, on plain values.
* obs-source.c keeps data_valid(), every field read, the action queue and
* its mutex, the callbacks and the signals, and acts on what comes back.
* Declared in obs-source-media-admission.h without EXPORT. In hybrid libobs
* the Rust port (rust/obs-source, media_admission) replaces this file. */

enum obs_source_media_admit obs_source_media_admit(bool valid)
{
if (!valid)
return OBS_SOURCE_MEDIA_ADMIT_REJECT;

return OBS_SOURCE_MEDIA_ADMIT_READ_FLAGS;
}

enum obs_source_media_admit obs_source_media_admit_flags(enum obs_source_media_call call, uint32_t output_flags)
{
if ((output_flags & OBS_SOURCE_MEDIA_CONTROLLABLE) == 0)
return OBS_SOURCE_MEDIA_ADMIT_REJECT;

switch (call) {
case OBS_SOURCE_MEDIA_CALL_STARTED:
case OBS_SOURCE_MEDIA_CALL_ENDED:
return OBS_SOURCE_MEDIA_ADMIT_ACCEPT;
case OBS_SOURCE_MEDIA_CALL_PLAY_PAUSE:
case OBS_SOURCE_MEDIA_CALL_RESTART:
case OBS_SOURCE_MEDIA_CALL_STOP:
case OBS_SOURCE_MEDIA_CALL_NEXT:
case OBS_SOURCE_MEDIA_CALL_PREVIOUS:
case OBS_SOURCE_MEDIA_CALL_GET_DURATION:
case OBS_SOURCE_MEDIA_CALL_GET_TIME:
case OBS_SOURCE_MEDIA_CALL_SET_TIME:
case OBS_SOURCE_MEDIA_CALL_GET_STATE:
break;
}

return OBS_SOURCE_MEDIA_ADMIT_READ_CALLBACK;
}

enum obs_source_media_admit obs_source_media_admit_callback(bool has_callback)
{
if (!has_callback)
return OBS_SOURCE_MEDIA_ADMIT_REJECT;

return OBS_SOURCE_MEDIA_ADMIT_ACCEPT;
}

int64_t obs_source_media_time_fallback(void)
{
return 0;
}

int obs_source_media_state_fallback(void)
{
return OBS_SOURCE_MEDIA_STATE_NONE;
}

enum obs_source_media_dispatch obs_source_media_dispatch(int type)
{
switch (type) {
case OBS_SOURCE_MEDIA_ACTION_NONE:
return OBS_SOURCE_MEDIA_DISPATCH_RETURN;
case OBS_SOURCE_MEDIA_ACTION_PLAY_PAUSE:
return OBS_SOURCE_MEDIA_DISPATCH_PLAY_PAUSE;
case OBS_SOURCE_MEDIA_ACTION_RESTART:
return OBS_SOURCE_MEDIA_DISPATCH_RESTART;
case OBS_SOURCE_MEDIA_ACTION_STOP:
return OBS_SOURCE_MEDIA_DISPATCH_STOP;
case OBS_SOURCE_MEDIA_ACTION_NEXT:
return OBS_SOURCE_MEDIA_DISPATCH_NEXT;
case OBS_SOURCE_MEDIA_ACTION_PREVIOUS:
return OBS_SOURCE_MEDIA_DISPATCH_PREVIOUS;
case OBS_SOURCE_MEDIA_ACTION_SET_TIME:
return OBS_SOURCE_MEDIA_DISPATCH_SET_TIME;
default:
return OBS_SOURCE_MEDIA_DISPATCH_SKIP;
}
}

bool obs_source_media_signal_reads_pause(enum obs_source_media_dispatch dispatch)
{
return dispatch == OBS_SOURCE_MEDIA_DISPATCH_PLAY_PAUSE;
}

const char *obs_source_media_signal(enum obs_source_media_dispatch dispatch, bool pause)
{
switch (dispatch) {
case OBS_SOURCE_MEDIA_DISPATCH_PLAY_PAUSE:
if (pause)
return "media_pause";
else
return "media_play";
case OBS_SOURCE_MEDIA_DISPATCH_RESTART:
return "media_restart";
case OBS_SOURCE_MEDIA_DISPATCH_STOP:
return "media_stopped";
case OBS_SOURCE_MEDIA_DISPATCH_NEXT:
return "media_next";
case OBS_SOURCE_MEDIA_DISPATCH_PREVIOUS:
return "media_previous";
case OBS_SOURCE_MEDIA_DISPATCH_RETURN:
case OBS_SOURCE_MEDIA_DISPATCH_SET_TIME:
case OBS_SOURCE_MEDIA_DISPATCH_SKIP:
break;
}

return NULL;
}
142 changes: 142 additions & 0 deletions libobs/obs-source-media-admission.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
/******************************************************************************
Copyright (C) 2023 by Lain Bailey <lain@obsproject.com>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/

#pragma once

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>

/* The media action admission decisions of obs-source.c, on plain values
* (obs-source-media-admission.c):
* - the obs_source_media_*() functions: whether a call is accepted, in the
* old order. A source that is not valid (data_valid(), or
* obs_source_valid() for _started() and _ended()) is rejected, then one
* without OBS_SOURCE_CONTROLLABLE_MEDIA, then, for every call but
* _started() and _ended(), one without the call's callback. A READ_ step
* asks obs-source.c for the next value, so a field is read only where it
* was read before;
* - the getters' fallbacks: 0 for the duration and the time,
* OBS_MEDIA_STATE_NONE for the state;
* - process_media_actions(): what each queued action does, the callback it
* calls and the signal it emits after it.
*
* obs-source.c keeps data_valid() and obs_source_valid() (they log), every
* field read, the action queue and its mutex, the callbacks, the signals
* and the source refs. None of these functions takes a lock, calls into
* libobs or keeps state.
*
* Hidden in libobs: not EXPORT. */

/* obs-source.c checks that these are OBS_SOURCE_CONTROLLABLE_MEDIA,
* OBS_MEDIA_STATE_NONE and enum media_action_type (obs-internal.h). */
#define OBS_SOURCE_MEDIA_CONTROLLABLE (1u << 13)
#define OBS_SOURCE_MEDIA_STATE_NONE 0
#define OBS_SOURCE_MEDIA_ACTION_NONE 0
#define OBS_SOURCE_MEDIA_ACTION_PLAY_PAUSE 1
#define OBS_SOURCE_MEDIA_ACTION_RESTART 2
#define OBS_SOURCE_MEDIA_ACTION_STOP 3
#define OBS_SOURCE_MEDIA_ACTION_NEXT 4
#define OBS_SOURCE_MEDIA_ACTION_PREVIOUS 5
#define OBS_SOURCE_MEDIA_ACTION_SET_TIME 6

/* The public obs_source_media_*() function being admitted. */
enum obs_source_media_call {
OBS_SOURCE_MEDIA_CALL_PLAY_PAUSE,
OBS_SOURCE_MEDIA_CALL_RESTART,
OBS_SOURCE_MEDIA_CALL_STOP,
OBS_SOURCE_MEDIA_CALL_NEXT,
OBS_SOURCE_MEDIA_CALL_PREVIOUS,
OBS_SOURCE_MEDIA_CALL_GET_DURATION,
OBS_SOURCE_MEDIA_CALL_GET_TIME,
OBS_SOURCE_MEDIA_CALL_SET_TIME,
OBS_SOURCE_MEDIA_CALL_GET_STATE,
OBS_SOURCE_MEDIA_CALL_STARTED,
OBS_SOURCE_MEDIA_CALL_ENDED,
};

/* An admission answer, or the value to read before it is known. */
enum obs_source_media_admit {
/* return (a getter returns its fallback) */
OBS_SOURCE_MEDIA_ADMIT_REJECT,
/* queue the action, call the getter or emit the signal */
OBS_SOURCE_MEDIA_ADMIT_ACCEPT,
/* read source->info.output_flags */
OBS_SOURCE_MEDIA_ADMIT_READ_FLAGS,
/* read the call's callback in source->info (!= NULL) */
OBS_SOURCE_MEDIA_ADMIT_READ_CALLBACK,
};

/* What process_media_actions() does with an action it took off the
* queue. */
enum obs_source_media_dispatch {
/* MEDIA_ACTION_NONE, the queue was empty: return */
OBS_SOURCE_MEDIA_DISPATCH_RETURN,
/* media_play_pause(data, action.pause) */
OBS_SOURCE_MEDIA_DISPATCH_PLAY_PAUSE,
/* media_restart(data) */
OBS_SOURCE_MEDIA_DISPATCH_RESTART,
/* media_stop(data) */
OBS_SOURCE_MEDIA_DISPATCH_STOP,
/* media_next(data) */
OBS_SOURCE_MEDIA_DISPATCH_NEXT,
/* media_previous(data) */
OBS_SOURCE_MEDIA_DISPATCH_PREVIOUS,
/* media_set_time(data, action.ms) */
OBS_SOURCE_MEDIA_DISPATCH_SET_TIME,
/* a type outside the enum: nothing, take the next action */
OBS_SOURCE_MEDIA_DISPATCH_SKIP,
};

/* --- the obs_source_media_*() functions -------------------------------- */

/* The first step: READ_FLAGS for a valid source, else REJECT. */
enum obs_source_media_admit obs_source_media_admit(bool valid);

/* The step after reading the output flags: REJECT without
* OBS_SOURCE_CONTROLLABLE_MEDIA, ACCEPT for _started() and _ended(), else
* READ_CALLBACK (a call outside the enum included). */
enum obs_source_media_admit obs_source_media_admit_flags(enum obs_source_media_call call, uint32_t output_flags);

/* The step after reading the callback: ACCEPT when it is set, else
* REJECT. */
enum obs_source_media_admit obs_source_media_admit_callback(bool has_callback);

/* What obs_source_media_get_duration() and _get_time() return when the
* call is rejected: 0. */
int64_t obs_source_media_time_fallback(void);

/* What obs_source_media_get_state() returns when the call is rejected:
* OBS_MEDIA_STATE_NONE, as int (obs-source.c checks the enum's size). */
int obs_source_media_state_fallback(void);

/* --- process_media_actions() -------------------------------------------- */

/* The dispatch of a queued action's type (enum media_action_type, as
* int): RETURN for MEDIA_ACTION_NONE, the matching callback for the
* others, SKIP for a value outside the enum. */
enum obs_source_media_dispatch obs_source_media_dispatch(int type);

/* Whether the signal reads action.pause: only for PLAY_PAUSE (the union
* holds the time for SET_TIME). */
bool obs_source_media_signal_reads_pause(enum obs_source_media_dispatch dispatch);

/* The signal emitted after the callback: "media_pause" or "media_play"
* (by pause), "media_restart", "media_stopped", "media_next",
* "media_previous"; NULL for SET_TIME, RETURN, SKIP and a value outside
* the enum. pause is false when not read. */
const char *obs_source_media_signal(enum obs_source_media_dispatch dispatch, bool pause);
Loading
Loading