1 | use std::ptr; |
2 | |
3 | use super::Context; |
4 | use ffi::*; |
5 | use {Error, Frame}; |
6 | |
7 | pub struct Source<'a> { |
8 | ctx: &'a mut Context<'a>, |
9 | } |
10 | |
11 | impl<'a> Source<'a> { |
12 | pub unsafe fn wrap<'b>(ctx: &'b mut Context<'b>) -> Source<'b> { |
13 | Source { ctx } |
14 | } |
15 | } |
16 | |
17 | impl<'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 | } |
44 | |