playa_ffmpeg/format/chapter/
chapter.rs

1use crate::{DictionaryRef, Rational, ffi::*};
2
3use crate::format::context::common::Context;
4
5// WARNING: index refers to the offset in the chapters array (starting from 0)
6// it is not necessarly equal to the id (which may start at 1)
7pub struct Chapter<'a> {
8    context: &'a Context,
9    index: usize,
10}
11
12impl<'a> Chapter<'a> {
13    pub unsafe fn wrap(context: &Context, index: usize) -> Chapter<'_> {
14        Chapter { context, index }
15    }
16
17    pub unsafe fn as_ptr(&self) -> *const AVChapter {
18        unsafe { *(*self.context.as_ptr()).chapters.add(self.index) }
19    }
20}
21
22impl<'a> Chapter<'a> {
23    pub fn index(&self) -> usize {
24        self.index
25    }
26
27    pub fn id(&self) -> i64 {
28        #[allow(clippy::unnecessary_cast)]
29        unsafe {
30            (*self.as_ptr()).id as i64
31        }
32    }
33
34    pub fn time_base(&self) -> Rational {
35        unsafe { Rational::from((*self.as_ptr()).time_base) }
36    }
37
38    pub fn start(&self) -> i64 {
39        unsafe { (*self.as_ptr()).start }
40    }
41
42    pub fn end(&self) -> i64 {
43        unsafe { (*self.as_ptr()).end }
44    }
45
46    pub fn metadata(&self) -> DictionaryRef<'_> {
47        unsafe { DictionaryRef::wrap((*self.as_ptr()).metadata) }
48    }
49}
50
51impl<'a> PartialEq for Chapter<'a> {
52    fn eq(&self, other: &Self) -> bool {
53        unsafe { self.as_ptr() == other.as_ptr() }
54    }
55}