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