libobs: Implement transition sources
Transition sources are implemented by registering a source type as OBS_SOURCE_TYPE_TRANSITION. They're automatically marked as video composite sources, and video_render/audio_render callbacks must be set when registering the source. get_width and get_height callbacks are unused for these types of sources, as transitions automatically handle width/height behind the scenes with the transition settings. In the video_render callback, the helper function obs_transition_video_render is used to assist in automatically processing and rendering the audio. A render callback is passed to the function, which in turn passes to/from textures that are automatically rendered in the back-end. Similarly, in the audio_render callback, the helper function obs_transition_audio_render is used to assist in automatically processing and rendering the audio. Two mix callbacks are used to handle how the source/destination sources are mixed together. To ensure the best possible quality, audio processing is per-sample. Transitions can be set to automatically resize, or they can be set to have a fixed size. Sources within transitions can be made to scale to the transition size (with or without aspect ratio), or to not scale unless they're bigger than the transition. They can have a specific alignment within the transition, or they just default to top-left. These features are implemented for the purpose of extending transitions to also act as "switch" sources later, where you can switch to/from two different sources using the transition animation. Planned (but not yet implemented and lower priority) features: - "Switch" transitions which allow the ability to switch back and forth between two sources with a transitioning animation without discarding the references - Easing options to allow the option to transition with a bezier or custom curve - Manual transitioning to allow the front-end/user to manually control the transition offset
This commit is contained in:
74
libobs/obs.h
74
libobs/obs.h
@@ -976,6 +976,80 @@ EXPORT uint64_t obs_source_get_audio_timestamp(const obs_source_t *source);
|
||||
EXPORT void obs_source_get_audio_mix(const obs_source_t *source,
|
||||
struct obs_source_audio_mix *audio);
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* Transition-specific functions */
|
||||
enum obs_transition_target {
|
||||
OBS_TRANSITION_SOURCE_A,
|
||||
OBS_TRANSITION_SOURCE_B
|
||||
};
|
||||
|
||||
EXPORT obs_source_t *obs_transition_get_source(obs_source_t *transition,
|
||||
enum obs_transition_target target);
|
||||
EXPORT void obs_transition_clear(obs_source_t *transition);
|
||||
|
||||
EXPORT obs_source_t *obs_transition_get_active_source(obs_source_t *transition);
|
||||
|
||||
enum obs_transition_mode {
|
||||
OBS_TRANSITION_MODE_AUTO,
|
||||
};
|
||||
|
||||
EXPORT bool obs_transition_start(obs_source_t *transition,
|
||||
enum obs_transition_mode mode, uint32_t duration_ms,
|
||||
obs_source_t *dest);
|
||||
|
||||
EXPORT void obs_transition_set(obs_source_t *transition, obs_source_t *source);
|
||||
|
||||
enum obs_transition_scale_type {
|
||||
OBS_TRANSITION_SCALE_MAX_ONLY,
|
||||
OBS_TRANSITION_SCALE_ASPECT,
|
||||
OBS_TRANSITION_SCALE_STRETCH,
|
||||
};
|
||||
|
||||
EXPORT void obs_transition_set_scale_type(obs_source_t *transition,
|
||||
enum obs_transition_scale_type type);
|
||||
EXPORT enum obs_transition_scale_type obs_transition_get_scale_type(
|
||||
const obs_source_t *transition);
|
||||
|
||||
EXPORT void obs_transition_set_alignment(obs_source_t *transition,
|
||||
uint32_t alignment);
|
||||
EXPORT uint32_t obs_transition_get_alignment(const obs_source_t *transition);
|
||||
|
||||
EXPORT void obs_transition_set_size(obs_source_t *transition,
|
||||
uint32_t cx, uint32_t cy);
|
||||
EXPORT void obs_transition_get_size(const obs_source_t *transition,
|
||||
uint32_t *cx, uint32_t *cy);
|
||||
|
||||
/* function used by transitions */
|
||||
|
||||
/**
|
||||
* Enables fixed transitions (videos or specific types of transitions that
|
||||
* are of fixed duration and linearly interpolated
|
||||
*/
|
||||
EXPORT void obs_transition_enable_fixed(obs_source_t *transition, bool enable,
|
||||
uint32_t duration_ms);
|
||||
EXPORT bool obs_transition_fixed(obs_source_t *transition);
|
||||
|
||||
typedef void (*obs_transition_video_render_callback_t)(void *data,
|
||||
gs_texture_t *a, gs_texture_t *b, float t,
|
||||
uint32_t cx, uint32_t cy);
|
||||
typedef float (*obs_transition_audio_mix_callback_t)(void *data, float t);
|
||||
|
||||
EXPORT void obs_transition_video_render(obs_source_t *transition,
|
||||
obs_transition_video_render_callback_t callback);
|
||||
|
||||
EXPORT bool obs_transition_audio_render(obs_source_t *transition,
|
||||
uint64_t *ts_out, struct obs_source_audio_mix *audio,
|
||||
uint32_t mixers, size_t channels, size_t sample_rate,
|
||||
obs_transition_audio_mix_callback_t mix_a_callback,
|
||||
obs_transition_audio_mix_callback_t mix_b_callback);
|
||||
|
||||
/* swaps transition sources and textures as an optimization and to reduce
|
||||
* memory usage when switching between transitions */
|
||||
EXPORT void obs_transition_swap_begin(obs_source_t *tr_dest,
|
||||
obs_source_t *tr_source);
|
||||
EXPORT void obs_transition_swap_end(obs_source_t *tr_dest,
|
||||
obs_source_t *tr_source);
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* Scenes */
|
||||
|
Reference in New Issue
Block a user