larksuite / rsmpeg

A Rust crate that exposes FFmpeg's power as much as possible.
https://docs.rs/rsmpeg/latest/rsmpeg/
MIT License
678 stars 41 forks source link

mutable `data_mut` and `linesize_mut` #82

Closed lattice0 closed 2 years ago

lattice0 commented 2 years ago

at https://github.com/larksuite/rsmpeg/blob/master/src/avutil/frame.rs#L76, these two

    pub fn data_mut(&mut self) -> &mut [*mut u8; 8] {
        unsafe { &mut self.deref_mut().data }
    }

    pub fn linesize_mut(&mut self) -> &mut [libc::c_int; 8] {
        unsafe { &mut self.deref_mut().linesize }
    }

are mutable. Can I do versions for &self? Also, why it returns &mut [*mut u8; 8] and not &mut [&mut[u8]]? I have to rely on usafe outside of the library to do std::slice::from_raw_parts (is it even safe?)

ldm0 commented 2 years ago

Size of AVFrame.data[0] is not well-defined by FFmpeg. Due to this limitation, there is no way to exposed the data safely(as slice).

ldm0 commented 2 years ago

Can I do versions for &self?

&AVFrame derefs to &ffi::AVFrame, which means you can immutably access all fields of &ffi::AVFrame, including the data and line_size by frame.data and frame.line_size.

Ref: https://docs.rs/rsmpeg/0.8.0/rsmpeg/ffi/struct.AVFrame.html#structfield.data Example: https://github.com/larksuite/rsmpeg/blob/6ed7c7e71bbe92771d219e5f198d45988266e2ed/tests/tutorial01.rs#L26

ldm0 commented 2 years ago

Feel free to reopen this issue if it doesn't work. :-)