1use ffi::*;
2use {DictionaryRef, Rational};
3
4use 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 #[allow(clippy::unnecessary_cast)]
30 unsafe {
31 (*self.as_ptr()).id as i64
32 }
33 }
34
35 pub fn time_base(&self) -> Rational {
36 unsafe { Rational::from((*self.as_ptr()).time_base) }
37 }
38
39 pub fn start(&self) -> i64 {
40 unsafe { (*self.as_ptr()).start }
41 }
42
43 pub fn end(&self) -> i64 {
44 unsafe { (*self.as_ptr()).end }
45 }
46
47 pub fn metadata(&self) -> DictionaryRef {
48 unsafe { DictionaryRef::wrap((*self.as_ptr()).metadata) }
49 }
50}
51
52impl<'a> PartialEq for Chapter<'a> {
53 fn eq(&self, other: &Self) -> bool {
54 unsafe { self.as_ptr() == other.as_ptr() }
55 }
56}
57