1 | use std::ops::{Deref, DerefMut}; |
2 | |
3 | use ffi::*; |
4 | use libc::c_int; |
5 | |
6 | use super::Opened; |
7 | use codec::Context; |
8 | use {packet, Error}; |
9 | |
10 | pub struct Subtitle(pub Opened); |
11 | |
12 | impl 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 | |
34 | impl Deref for Subtitle { |
35 | type Target = Opened; |
36 | |
37 | fn deref(&self) -> &<Self as Deref>::Target { |
38 | &self.0 |
39 | } |
40 | } |
41 | |
42 | impl DerefMut for Subtitle { |
43 | fn deref_mut(&mut self) -> &mut <Self as Deref>::Target { |
44 | &mut self.0 |
45 | } |
46 | } |
47 | |
48 | impl AsRef<Context> for Subtitle { |
49 | fn as_ref(&self) -> &Context { |
50 | self |
51 | } |
52 | } |
53 | |
54 | impl AsMut<Context> for Subtitle { |
55 | fn as_mut(&mut self) -> &mut Context { |
56 | &mut self.0 |
57 | } |
58 | } |
59 | |