ffmpeg_the_third/format/chapter/
chapter.rs

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