ffmpeg_next/filter/context/
source.rs

1use std::ptr;
2
3use super::Context;
4use ffi::*;
5use {Error, Frame};
6
7pub struct Source<'a> {
8    ctx: &'a mut Context,
9}
10
11impl<'a> Source<'a> {
12    pub unsafe fn wrap(ctx: &'a mut Context) -> Self {
13        Self { ctx }
14    }
15}
16
17impl<'a> Source<'a> {
18    pub fn failed_requests(&self) -> usize {
19        unsafe { av_buffersrc_get_nb_failed_requests(self.ctx.as_ptr() as *mut _) as usize }
20    }
21
22    pub fn add(&mut self, frame: &Frame) -> Result<(), Error> {
23        unsafe {
24            match av_buffersrc_add_frame(self.ctx.as_mut_ptr(), frame.as_ptr() as *mut _) {
25                0 => Ok(()),
26                e => Err(Error::from(e)),
27            }
28        }
29    }
30
31    pub fn flush(&mut self) -> Result<(), Error> {
32        unsafe { self.add(&Frame::wrap(ptr::null_mut())) }
33    }
34
35    pub fn close(&mut self, pts: i64) -> Result<(), Error> {
36        unsafe {
37            match av_buffersrc_close(self.ctx.as_mut_ptr(), pts, 0) {
38                0 => Ok(()),
39                e => Err(Error::from(e)),
40            }
41        }
42    }
43}