1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
use super::context::{CreatableSourceContext, GlobalContext, VideoRenderContext};
use crate::properties::Properties;
use super::{audio::AudioDataContext, media::MediaState};
use super::{video::VideoDataContext};
use super::{EnumActiveContext, EnumAllContext, SourceType, SourceContext};
use crate::data::DataObj;
use crate::string::ObsString;

pub trait Sourceable: Sized {
    fn get_id() -> ObsString;
    fn get_type() -> SourceType;
    fn create(create: &mut CreatableSourceContext<Self>, source: SourceContext) -> Self;
}

macro_rules! simple_trait {
    ($($f:ident => $t:ident $(-> $ret:ty)?)*) => ($(
        pub trait $t: Sized {
            fn $f(&mut self) $(-> $ret)?;
        }
    )*)
}

pub trait GetNameSource {
    fn get_name() -> ObsString;
}

simple_trait!(
    get_width => GetWidthSource -> u32
    get_height => GetHeightSource -> u32
    activate => ActivateSource
    deactivate => DeactivateSource
);

pub trait UpdateSource: Sized {
    fn update(&mut self, settings: &mut DataObj, context: &mut GlobalContext);
}

pub trait VideoRenderSource: Sized {
    fn video_render(
        &mut self,
        context: &mut GlobalContext,
        render: &mut VideoRenderContext,
    );
}

pub trait AudioRenderSource: Sized {
    fn audio_render(&mut self, context: &mut GlobalContext);
}

pub trait GetPropertiesSource: Sized {
    fn get_properties(&mut self) -> Properties;
}

pub trait VideoTickSource: Sized {
    fn video_tick(&mut self, seconds: f32);
}

pub trait EnumActiveSource: Sized {
    fn enum_active_sources(&mut self, context: &EnumActiveContext);
}

pub trait EnumAllSource: Sized {
    fn enum_all_sources(&mut self, context: &EnumAllContext);
}

simple_trait!(
    transition_start => TransitionStartSource
    transition_stop => TransitionStopSource
);

pub trait FilterAudioSource: Sized {
    fn filter_audio(&mut self, audio: &mut AudioDataContext);
}

pub trait FilterVideoSource: Sized {
    fn filter_video(&mut self, audio: &mut VideoDataContext);
}

pub trait MediaPlayPauseSource: Sized {
    fn play_pause(&mut self, pause: bool);
}

pub trait MediaGetStateSource: Sized {
    fn get_state(&mut self) -> MediaState;
}

pub trait MediaSetTimeSource: Sized {
    fn set_time(&mut self, milliseconds: i64);
}

pub trait GetDefaultsSource {
    fn get_defaults(settings: &mut DataObj);
}

simple_trait!(
    restart => MediaRestartSource
    stop => MediaStopSource
    next => MediaNextSource
    previous => MediaPreviousSource
    get_duration => MediaGetDurationSource -> i64
    get_time => MediaGetTimeSource -> i64
);