Skip to content

Commit

Permalink
feat: add clone to params
Browse files Browse the repository at this point in the history
  • Loading branch information
thewh1teagle committed Jul 9, 2024
1 parent f1030ef commit a5f516a
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/whisper_params.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::whisper_grammar::WhisperGrammarElement;
use std::ffi::{c_char, c_float, c_int, CString};
use std::marker::PhantomData;
use std::sync::Arc;
use whisper_rs_sys::whisper_token;

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -31,14 +32,15 @@ pub struct SegmentCallbackData {

type SegmentCallbackFn = Box<dyn FnMut(SegmentCallbackData)>;

#[derive(Clone)]
pub struct FullParams<'a, 'b> {
pub(crate) fp: whisper_rs_sys::whisper_full_params,
phantom_lang: PhantomData<&'a str>,
phantom_tokens: PhantomData<&'b [c_int]>,
grammar: Option<Vec<whisper_rs_sys::whisper_grammar_element>>,
progess_callback_safe: Option<Box<dyn FnMut(i32)>>,
abort_callback_safe: Option<Box<dyn FnMut() -> bool>>,
segment_calllback_safe: Option<SegmentCallbackFn>,
progess_callback_safe: Option<Arc<Box<dyn FnMut(i32)>>>,
abort_callback_safe: Option<Arc<Box<dyn FnMut() -> bool>>>,
segment_calllback_safe: Option<Arc<SegmentCallbackFn>>,
}

impl<'a, 'b> FullParams<'a, 'b> {
Expand Down Expand Up @@ -588,7 +590,7 @@ impl<'a, 'b> FullParams<'a, 'b> {
self.fp.progress_callback = Some(trampoline::<F>);
self.fp.progress_callback_user_data = &mut closure as *mut F as *mut c_void;
// store the closure internally to make sure that the pointer above remains valid
self.progess_callback_safe = Some(Box::new(closure));
self.progess_callback_safe = Some(Arc::new(Box::new(closure)));
}
None => {
self.fp.progress_callback = None;
Expand Down

0 comments on commit a5f516a

Please sign in to comment.