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