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