ffmpeg_next/filter/context/
sink.rs1use super::Context;
2use crate::ffi::*;
3use crate::{Error, Frame, Rational};
4use libc::c_int;
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 av_frame_unref(frame.as_mut_ptr());
20 match av_buffersink_get_frame(self.ctx.as_mut_ptr(), frame.as_mut_ptr()) {
21 n if n >= 0 => Ok(()),
22 e => Err(Error::from(e)),
23 }
24 }
25 }
26
27 pub fn samples(&mut self, frame: &mut Frame, samples: usize) -> Result<(), Error> {
28 unsafe {
29 av_frame_unref(frame.as_mut_ptr());
30 match av_buffersink_get_samples(
31 self.ctx.as_mut_ptr(),
32 frame.as_mut_ptr(),
33 samples as c_int,
34 ) {
35 n if n >= 0 => Ok(()),
36 e => Err(Error::from(e)),
37 }
38 }
39 }
40
41 pub fn set_frame_size(&mut self, value: u32) {
42 unsafe {
43 av_buffersink_set_frame_size(self.ctx.as_mut_ptr(), value);
44 }
45 }
46
47 pub fn time_base(&self) -> Rational {
48 unsafe { av_buffersink_get_time_base(self.ctx.as_ptr()) }.into()
49 }
50}