obs_wrapper/output/
traits.rs

1use obs_sys::{audio_data, encoder_packet, video_data};
2
3use crate::{prelude::DataObj, properties::Properties, string::ObsString};
4
5use super::{CreatableOutputContext, OutputContext};
6
7pub trait Outputable: Sized {
8    fn get_id() -> ObsString;
9    fn create(context: &mut CreatableOutputContext<'_, Self>, output: OutputContext) -> Self;
10
11    fn start(&mut self) -> bool {
12        true
13    }
14    fn stop(&mut self, _ts: u64) {}
15}
16
17pub trait GetNameOutput {
18    fn get_name() -> ObsString;
19}
20
21macro_rules! simple_trait {
22    ($($f:ident$(($($params:tt)*))? => $t:ident $(-> $ret:ty)?)*) => ($(
23        pub trait $t: Sized {
24            fn $f(&mut self $(, $($params)*)?) $(-> $ret)?;
25        }
26    )*)
27}
28
29pub trait RawVideoOutput: Sized {
30    fn raw_video(&mut self, frame: &mut video_data);
31}
32
33pub trait RawAudioOutput: Sized {
34    fn raw_audio(&mut self, frame: &mut audio_data);
35}
36
37pub trait RawAudio2Output: Sized {
38    fn raw_audio2(&mut self, idx: usize, frame: &mut audio_data);
39}
40
41pub trait EncodedPacketOutput: Sized {
42    fn encoded_packet(&mut self, packet: &mut encoder_packet);
43}
44
45pub trait UpdateOutput: Sized {
46    fn update(&mut self, settings: &mut DataObj);
47}
48
49pub trait GetDefaultsOutput {
50    fn get_defaults(settings: &mut DataObj);
51}
52
53pub trait GetPropertiesOutput: Sized {
54    fn get_properties(&mut self) -> Properties;
55}
56
57simple_trait! {
58    get_total_bytes => GetTotalBytesOutput -> u64
59    get_dropped_frames => GetDroppedFramesOutput-> i32
60    get_congestion => GetCongestionOutput -> f32
61    get_connect_time_ms => GetConnectTimeMsOutput -> i32
62}