ffmpeg_rs/codec/decoder/
subtitle.rs

1use std::ops::{Deref, DerefMut};
2
3use ffi::*;
4use libc::c_int;
5
6use super::Opened;
7use codec::Context;
8use {packet, Error};
9
10pub struct Subtitle(pub Opened);
11
12impl Subtitle {
13    pub fn decode<P: packet::Ref>(
14        &mut self,
15        packet: &P,
16        out: &mut ::Subtitle,
17    ) -> Result<bool, Error> {
18        unsafe {
19            let mut got: c_int = 0;
20
21            match avcodec_decode_subtitle2(
22                self.as_mut_ptr(),
23                out.as_mut_ptr(),
24                &mut got,
25                packet.as_ptr() as *mut _,
26            ) {
27                e if e < 0 => Err(Error::from(e)),
28                _ => Ok(got != 0),
29            }
30        }
31    }
32}
33
34impl Deref for Subtitle {
35    type Target = Opened;
36
37    fn deref(&self) -> &<Self as Deref>::Target {
38        &self.0
39    }
40}
41
42impl DerefMut for Subtitle {
43    fn deref_mut(&mut self) -> &mut <Self as Deref>::Target {
44        &mut self.0
45    }
46}
47
48impl AsRef<Context> for Subtitle {
49    fn as_ref(&self) -> &Context {
50        self
51    }
52}
53
54impl AsMut<Context> for Subtitle {
55    fn as_mut(&mut self) -> &mut Context {
56        &mut self.0
57    }
58}