Skip to main content

ffmpeg_next/filter/context/
sink.rs

1use super::Context;
2use ffi::*;
3use libc::c_int;
4use {Error, Frame, Rational};
5
6pub struct Sink<'a> {
7    ctx: &'a mut Context,
8}
9
10impl<'a> Sink<'a> {
11    pub unsafe fn wrap(ctx: &'a mut Context) -> Self {
12        Self { ctx }
13    }
14}
15
16impl<'a> Sink<'a> {
17    pub fn frame(&mut self, frame: &mut Frame) -> Result<(), Error> {
18        unsafe {
19            match av_buffersink_get_frame(self.ctx.as_mut_ptr(), frame.as_mut_ptr()) {
20                n if n >= 0 => Ok(()),
21                e => Err(Error::from(e)),
22            }
23        }
24    }
25
26    pub fn samples(&mut self, frame: &mut Frame, samples: usize) -> Result<(), Error> {
27        unsafe {
28            match av_buffersink_get_samples(
29                self.ctx.as_mut_ptr(),
30                frame.as_mut_ptr(),
31                samples as c_int,
32            ) {
33                n if n >= 0 => Ok(()),
34                e => Err(Error::from(e)),
35            }
36        }
37    }
38
39    pub fn set_frame_size(&mut self, value: u32) {
40        unsafe {
41            av_buffersink_set_frame_size(self.ctx.as_mut_ptr(), value);
42        }
43    }
44
45    pub fn time_base(&self) -> Rational {
46        unsafe { av_buffersink_get_time_base(self.ctx.as_ptr()) }.into()
47    }
48}