Example on how to use BASS_StreamCreateFileUser

Hello is there any example or do someone know how to use bass stream create file user properly? there are a lot of things like creating a function pointer and I've never done this.

What do you want to use the function to do? There's a bass-rs crate that provides a safe wrapper over bass-sys, but it only supports creating a stream from a file or an in-memory buffer.

I need it because the bass opus plugin requires that the stream be
loaded to the end so that it can work properly and this is done via
the bass stream create file user

2022-06-15 14:33 GMT+02:00, LegionMammal978 via The Rust Programming
Language Forum notifications@rust-lang.discoursemail.com:

here on this link is finished bass create file user example but i
would like someone to help me to avoid statics or do some improvements

use std::ffi::c_void;
use std::path::PathBuf;
static mut VECTEST: Vec<u8> = Vec::new();
fn main() {
    let mut paths: Vec<PathBuf> = Vec::new();
    bass_sys::set_library_name("bass.dll".to_string()).unwrap();
    let path: PathBuf = [r"lib"].iter().collect();
    paths.push(path);
    bass_sys::set_library_search_paths(paths).unwrap();
    let data = std::fs::read("jloop8.ogg").unwrap();
    unsafe {
        VECTEST = data.to_vec();
    }
    bass_sys::BASS_Init(-1, 44100, 0, std::ptr::null_mut(),
std::ptr::null_mut());
    let mut ptr = bass_sys::BassFileProcs::new(
        filecloseproc_callback as *mut _,
        filelenproc_callback as *mut _,
        readproc_callback as *mut _,
        std::ptr::null_mut(),
    );
    let svina = bass_sys::BASS_StreamCreateFileUser(2, 0, &mut ptr,
std::ptr::null_mut());
    bass_sys::BASS_StreamPutFileData(svina, unsafe {
VECTEST.as_ptr().cast() }, unsafe {
        VECTEST.len() as u32
    });
    std::fs::write("errors.txt",
bass_sys::BASS_ErrorGetCode().to_string()).unwrap();
    bass_sys::BASS_ChannelPlay(svina, 0);
    std::io::stdin().read_line(&mut String::new()).unwrap();
    extern "C" fn filelenproc_callback(_param1: *mut c_void) -> u64 {
        unsafe { VECTEST.len() as u64 }
    }
    extern "C" fn filecloseproc_callback(_param1: *mut c_void) {}
    extern "C" fn readproc_callback(param1: *mut c_void, param2: u32,
_param3: *mut c_void) -> u32 {
        unsafe {
            std::ptr::copy(VECTEST.as_ptr() as *const c_void, param1,
param2 as usize);
            VECTEST = VECTEST[param2 as usize..].to_vec();
        }
        param2
    }
    //koniec callbacku
}

(Playground)