@@ -14,7 +14,6 @@ use rustsynth_sys as ffi;
1414use std:: {
1515 ffi:: { CStr , CString } ,
1616 marker:: PhantomData ,
17- mem,
1817 ptr:: NonNull ,
1918} ;
2019
@@ -36,7 +35,7 @@ bitflags! {
3635}
3736
3837/// A reference to a VapourSynth core.
39- #[ derive( Debug , Clone , Copy ) ]
38+ #[ derive( Debug , Clone , PartialEq , Eq ) ]
4039pub struct CoreRef < ' core > {
4140 handle : NonNull < ffi:: VSCore > ,
4241 _owner : PhantomData < & ' core ( ) > ,
@@ -48,11 +47,6 @@ unsafe impl<'core> Sync for CoreRef<'core> {}
4847impl < ' core > CoreRef < ' core > {
4948 /// Creates and returns a new core.
5049 ///
51- /// Note that there's currently no safe way of freeing the returned core, and the lifetime is
52- /// unbounded, because it can live for an arbitrary long time. You may use the (unsafe)
53- /// `rustsynth_sys::VSAPI::freeCore()` after ensuring that all frame requests have completed
54- /// and all objects belonging to the core have been released.
55- ///
5650 /// # Example
5751 ///
5852 /// ```
@@ -111,14 +105,34 @@ impl<'core> CoreRef<'core> {
111105 ///
112106 /// [None] if no plugin is found
113107 pub fn plugin_by_namespace ( & self , namespace : & str ) -> Option < Plugin < ' core > > {
114- unsafe { API :: get_cached ( ) } . plugin_by_namespace ( namespace, self )
108+ let namespace = CString :: new ( namespace) . unwrap ( ) ;
109+ unsafe { API :: get_cached ( ) } . plugin_by_namespace ( namespace. as_ptr ( ) , self )
115110 }
116111
117112 /// Returns an instance of [Some]<[Plugin]> if there exists a plugin loaded associated with the id
118113 ///
119114 /// [None] if no plugin is found
120115 pub fn plugin_by_id ( & self , id : & str ) -> Option < Plugin < ' _ > > {
121- unsafe { API :: get_cached ( ) } . plugin_by_id ( id, self )
116+ let id = CString :: new ( id) . unwrap ( ) ;
117+ unsafe { API :: get_cached ( ) } . plugin_by_id ( id. as_ptr ( ) , self )
118+ }
119+
120+ pub fn std ( & self ) -> Option < Plugin < ' _ > > {
121+ unsafe {
122+ API :: get_cached ( ) . plugin_by_id ( ffi:: VSH_STD_PLUGIN_ID . as_ptr ( ) as * const i8 , self )
123+ }
124+ }
125+
126+ pub fn resize ( & self ) -> Option < Plugin < ' _ > > {
127+ unsafe {
128+ API :: get_cached ( ) . plugin_by_id ( ffi:: VSH_RESIZE_PLUGIN_ID . as_ptr ( ) as * const i8 , self )
129+ }
130+ }
131+
132+ pub fn text ( & self ) -> Option < Plugin < ' _ > > {
133+ unsafe {
134+ API :: get_cached ( ) . plugin_by_id ( ffi:: VSH_TEXT_PLUGIN_ID . as_ptr ( ) as * const i8 , self )
135+ }
122136 }
123137
124138 /// Returns a iterator over the loaded plugins
@@ -194,9 +208,9 @@ impl<'core> CoreRef<'core> {
194208 }
195209
196210 /// Create a video filter using the Filter trait
197- pub fn create_video_filter < F > ( & self , filter : F ) -> Result < OwnedMap < ' _ > , String >
211+ pub fn create_video_filter < F > ( & self , filter : & F ) -> Result < OwnedMap < ' _ > , String >
198212 where
199- F : Filter + Send + Sync + ' static ,
213+ F : Filter < ' core > ,
200214 {
201215 let out = OwnedMap :: new ( ) ;
202216 // Get video info from the filter
@@ -233,9 +247,9 @@ impl<'core> CoreRef<'core> {
233247 }
234248
235249 /// Create a video filter using the Filter trait (returns node directly)
236- pub fn create_video_filter2 < F > ( & self , filter : F ) -> Result < crate :: node:: Node , String >
250+ pub fn create_video_filter2 < F > ( & self , filter : & F ) -> Result < crate :: node:: Node < ' core > , String >
237251 where
238- F : Filter + Send + Sync + ' static ,
252+ F : Filter < ' core > ,
239253 {
240254 // Get video info from the filter
241255 let video_info = filter. get_video_info ( ) ?;
@@ -274,9 +288,9 @@ impl<'core> CoreRef<'core> {
274288 }
275289
276290 /// Create a audio filter using the Filter trait
277- pub fn create_audio_filter < F > ( & self , filter : F ) -> Result < OwnedMap < ' _ > , String >
291+ pub fn create_audio_filter < F > ( & self , filter : & F ) -> Result < OwnedMap < ' _ > , String >
278292 where
279- F : Filter + Send + Sync + ' static ,
293+ F : Filter < ' core > ,
280294 {
281295 let out = OwnedMap :: new ( ) ;
282296 // Get audio info from the filter
@@ -313,9 +327,9 @@ impl<'core> CoreRef<'core> {
313327 }
314328
315329 /// Create an audio filter using the Filter trait (returns node directly)
316- pub fn create_audio_filter2 < F > ( & self , filter : F ) -> Result < crate :: node:: Node , String >
330+ pub fn create_audio_filter2 < F > ( & self , filter : & F ) -> Result < crate :: node:: Node < ' core > , String >
317331 where
318- F : Filter + Send + Sync + ' static ,
332+ F : Filter < ' core > ,
319333 {
320334 // Get audio info from the filter
321335 let audio_info = filter. get_audio_info ( ) ?;
@@ -355,7 +369,7 @@ impl<'core> CoreRef<'core> {
355369}
356370
357371// Callback functions for Filter trait integration
358- unsafe extern "C" fn filter_get_frame < F > (
372+ unsafe extern "C" fn filter_get_frame < ' core , F > (
359373 n : i32 ,
360374 activation_reason : i32 ,
361375 instance_data : * mut std:: ffi:: c_void ,
@@ -365,7 +379,7 @@ unsafe extern "C" fn filter_get_frame<F>(
365379 _vs_api : * const ffi:: VSAPI ,
366380) -> * const ffi:: VSFrame
367381where
368- F : Filter + Send + Sync + ' static ,
382+ F : Filter < ' core > ,
369383{
370384 if instance_data. is_null ( ) || frame_ctx. is_null ( ) || core. is_null ( ) {
371385 return std:: ptr:: null ( ) ;
@@ -398,10 +412,7 @@ where
398412 } ;
399413
400414 match filter. process_frame ( n, & frame_data_array, & frame_context, core_ref) {
401- Ok ( frame) => {
402- let frame = mem:: ManuallyDrop :: new ( frame) ;
403- frame. as_ptr ( )
404- }
415+ Ok ( frame) => frame. as_ptr ( ) ,
405416 Err ( error) => {
406417 frame_context. set_filter_error ( & error) ;
407418 std:: ptr:: null ( )
@@ -428,12 +439,12 @@ where
428439 }
429440}
430441
431- unsafe extern "C" fn filter_free < F > (
442+ unsafe extern "C" fn filter_free < ' core , F > (
432443 instance_data : * mut std:: ffi:: c_void ,
433444 _core : * mut ffi:: VSCore ,
434445 _vs_api : * const ffi:: VSAPI ,
435446) where
436- F : Filter + Send + Sync + ' static ,
447+ F : Filter < ' core > ,
437448{
438449 if !instance_data. is_null ( ) {
439450 let filter = Box :: from_raw ( instance_data as * mut F ) ;
0 commit comments