phaneron_plugin/
traits.rs1pub use crate::{
2 audio::{AudioChannelLayout, AudioFormat},
3 colour::*,
4 graph::{AudioInputId, AudioOutputId, VideoInputId, VideoOutputId},
5 video::{InterlaceMode, VideoFormat},
6 AudioFrameWithId, VideoFrameWithId,
7};
8use abi_stable::{
9 sabi_trait,
10 std_types::{RHashMap, ROption, RResult, RSlice, RStr, RString, RVec},
11 StableAbi,
12};
13
14#[sabi_trait]
15pub trait PhaneronPlugin: Send + Sync {
16 fn get_available_node_types(&self) -> RVec<PluginNodeDescription>;
17 fn create_node(
18 &self,
19 description: CreateNodeDescription,
20 ) -> RResult<crate::types::NodeHandle, RString>;
21 fn destroy_node(&self, node_id: RString) -> RResult<(), RString>;
22}
23
24#[repr(C)]
26#[derive(StableAbi)]
27pub struct PluginNodeDescription {
28 pub id: RString,
30 pub name: RString,
32}
33
34#[repr(C)]
36#[derive(StableAbi)]
37pub struct CreateNodeDescription {
38 pub node_id: RString,
40 pub node_type: RString,
42}
43
44#[sabi_trait]
47pub trait NodeHandle: Send + Sync {
48 fn initialize(
49 &self,
50 context: crate::types::NodeContext,
51 configuration: ROption<RString>,
52 ) -> crate::types::Node;
53}
54
55#[sabi_trait]
57pub trait Node: Send + Sync {
58 fn apply_state(&self, state: RString) -> bool;
60 fn process_frame(
62 &self,
63 frame_context: crate::types::ProcessFrameContext,
64 video_frames: RHashMap<VideoInputId, VideoFrameWithId>,
65 audio_frames: RHashMap<AudioInputId, AudioFrameWithId>,
66 black_frame: VideoFrameWithId,
67 silence_frame: AudioFrameWithId,
68 );
69}
70
71#[sabi_trait]
73pub trait NodeContext: Send + Sync {
74 fn add_audio_input(&self) -> AudioInputId;
76 fn add_video_input(&self) -> VideoInputId;
78 fn add_audio_output(&self) -> crate::types::AudioOutput;
80 fn add_video_output(&self) -> crate::types::VideoOutput;
82 fn create_to_rgba(
84 &self,
85 video_format: &VideoFormat,
86 colour_space: &ColourSpec,
87 width: usize,
88 height: usize,
89 ) -> crate::types::ToRGBA;
90 fn create_from_rgba(
92 &self,
93 video_format: &VideoFormat,
94 colour_space: &ColourSpec,
95 width: usize,
96 height: usize,
97 interlace: InterlaceMode,
98 ) -> crate::types::FromRGBA;
99 fn create_to_audio_f32(
101 &self,
102 audio_format: AudioFormat,
103 channel_layout: AudioChannelLayout,
104 ) -> crate::types::ToAudioF32;
105 fn create_from_audio_f32(
107 &self,
108 audio_format: AudioFormat,
109 channel_layout: AudioChannelLayout,
110 ) -> crate::types::FromAudioF32;
111 fn create_process_shader(
115 &self,
116 kernel: RStr<'_>,
117 program_name: RStr<'_>,
118 ) -> crate::types::ProcessShader;
119}
120
121#[sabi_trait]
126pub trait ProcessFrameContext {
127 fn submit(&self) -> RResult<crate::types::FrameContext, RString>;
129}
130
131#[sabi_trait]
133pub trait FrameContext {}
134
135#[sabi_trait]
138pub trait ProcessShader: Send + Sync {
139 fn run(
140 &self,
141 params: crate::ShaderParams,
142 global_work_size: &[usize; 2],
143 ) -> RVec<crate::types::VideoFrame>;
144}
145
146#[sabi_trait]
148pub trait VideoFrame: Send + Sync {
149 fn buffer_index(&self) -> usize;
150 fn width(&self) -> usize;
151 fn height(&self) -> usize;
152}
153
154#[sabi_trait]
156pub trait AudioFrame: Send + Sync {
157 fn buffers(&self) -> &RVec<RVec<f32>>;
158}
159
160#[sabi_trait]
163pub trait VideoOutput: Send + Sync {
164 fn push_frame(&self, context: &crate::types::FrameContext, frame: crate::types::VideoFrame);
165}
166
167#[sabi_trait]
170pub trait AudioOutput: Send + Sync {
171 fn push_frame(&self, context: &crate::types::FrameContext, frame: crate::types::AudioFrame);
172}
173
174#[sabi_trait]
176pub trait ToRGBA: Send + Sync {
177 fn get_num_bytes(&self) -> RVec<usize>;
179 fn get_num_bytes_rgba(&self) -> usize;
181 fn get_total_bytes(&self) -> usize;
183 fn load_frame(&self, inputs: &RSlice<RSlice<u8>>) -> crate::types::LoadedVideoFrame;
190 fn process_frame(&self, sources: crate::types::LoadedVideoFrame) -> crate::types::VideoFrame;
192}
193
194#[sabi_trait]
196pub trait LoadedVideoFrame {}
197
198#[sabi_trait]
200pub trait FromRGBA: Send + Sync {
201 fn get_num_bytes(&self) -> RVec<usize>;
203 fn get_num_bytes_rgba(&self) -> usize;
205 fn get_total_bytes(&self) -> usize;
207 fn process_frame(
209 &self,
210 context: &crate::types::ProcessFrameContext,
211 frame: crate::types::VideoFrame,
212 ) -> crate::types::ConsumedVideoFrame;
213 fn copy_frame(
215 &self,
216 context: &crate::types::FrameContext, frame: crate::types::ConsumedVideoFrame,
218 ) -> RVec<RVec<u8>>;
219}
220
221#[sabi_trait]
224pub trait ConsumedVideoFrame {}
225
226#[sabi_trait]
228pub trait ToAudioF32: Send + Sync {
229 fn load_frame(&self, input: &RSlice<u8>) -> crate::types::LoadedAudioFrame;
231 fn process_frame(&self, source: crate::types::LoadedAudioFrame) -> crate::types::AudioFrame;
233}
234
235#[sabi_trait]
237pub trait LoadedAudioFrame {}
238
239#[sabi_trait]
241pub trait FromAudioF32: Send + Sync {
242 fn process_frame(
244 &self,
245 context: &crate::types::ProcessFrameContext,
246 frame: crate::types::AudioFrame,
247 ) -> crate::types::ConsumedAudioFrame;
248 fn copy_frame(
250 &self,
251 context: &crate::types::FrameContext,
252 frame: crate::types::ConsumedAudioFrame,
253 ) -> RVec<u8>;
254}
255
256#[sabi_trait]
258pub trait ConsumedAudioFrame {}