scuffle_ffmpeg/enums/
av_seek.rs

1use nutype_enum::{bitwise_enum, nutype_enum};
2
3use crate::ffi::*;
4
5nutype_enum! {
6    /// Seek flags used in FFmpeg's `av_seek_frame` function.
7    ///
8    /// These flags modify how seeking is performed in media files.
9    ///
10    /// See the official FFmpeg documentation:
11    /// <https://ffmpeg.org/doxygen/trunk/group__lavf__decoding.html#gaa59bdaec0590cc36300753c5cf6c9d49>
12    pub enum AVSeekFlag(i32) {
13        /// Seek to the closest keyframe before the specified timestamp.
14        /// - **Used for**: Ensuring accurate decoding by seeking to a valid keyframe.
15        /// - **Binary representation**: `0b0000000000000001`
16        /// - **Equivalent to**: `AVSEEK_FLAG_BACKWARD`
17        Backward = AVSEEK_FLAG_BACKWARD as i32,
18
19        /// Seek by byte position instead of timestamp.
20        /// - **Used for**: Formats where byte offsets are more reliable than timestamps.
21        /// - **Binary representation**: `0b0000000000000010`
22        /// - **Equivalent to**: `AVSEEK_FLAG_BYTE`
23        Byte = AVSEEK_FLAG_BYTE as i32,
24
25        /// Seek to any frame, not just keyframes.
26        /// - **Used for**: Allowing finer seeking granularity at the cost of possible decoding artifacts.
27        /// - **Binary representation**: `0b0000000000000100`
28        /// - **Equivalent to**: `AVSEEK_FLAG_ANY`
29        Any = AVSEEK_FLAG_ANY as i32,
30
31        /// Seek based on frame numbers rather than timestamps.
32        /// - **Used for**: Direct frame-based seeking in formats that support it.
33        /// - **Binary representation**: `0b0000000000001000`
34        /// - **Equivalent to**: `AVSEEK_FLAG_FRAME`
35        Frame = AVSEEK_FLAG_FRAME as i32,
36    }
37}
38
39bitwise_enum!(AVSeekFlag);
40
41impl PartialEq<i32> for AVSeekFlag {
42    fn eq(&self, other: &i32) -> bool {
43        self.0 == *other
44    }
45}
46
47impl From<u32> for AVSeekFlag {
48    fn from(value: u32) -> Self {
49        AVSeekFlag(value as i32)
50    }
51}
52
53impl From<AVSeekFlag> for u32 {
54    fn from(value: AVSeekFlag) -> Self {
55        value.0 as u32
56    }
57}
58
59nutype_enum! {
60    /// Seek flags used in FFmpeg's `av_seek_frame` function.
61    ///
62    /// These flags modify how seeking is performed in media files.
63    ///
64    /// See the official FFmpeg documentation:
65    /// <https://ffmpeg.org/doxygen/trunk/group__lavf__decoding.html#gaa59bdaec0590cc36300753c5cf6c9d49>
66    pub enum AVSeekWhence(i32) {
67        /// Seek from the beginning of the file.
68        /// - **Used for**: Seeking from the start of the file.
69        /// - **Binary representation**: `0b0000000000000001`
70        /// - **Equivalent to**: `SEEK_SET`
71        Start = SEEK_SET as i32,
72
73        /// Seek from the current position.
74        /// - **Used for**: Seeking from the current position.
75        /// - **Binary representation**: `0b0000000000000010`
76        /// - **Equivalent to**: `SEEK_CUR`
77        Current = SEEK_CUR as i32,
78
79        /// Seek from the end of the file.
80        /// - **Used for**: Seeking from the end of the file.
81        /// - **Binary representation**: `0b0000000000000100`
82        /// - **Equivalent to**: `SEEK_END`
83        End = SEEK_END as i32,
84
85        /// Return the file size instead of performing a seek.
86        /// - **Used for**: Querying the total file size.
87        /// - **Binary representation**: `0b00000000000000010000000000000000`
88        /// - **Equivalent to**: `AVSEEK_SIZE`
89        Size = AVSEEK_SIZE as i32,
90
91        /// Force seeking, even if the demuxer does not indicate it supports it.
92        /// - **Used for**: Forcing a seek operation when the demuxer might otherwise refuse.
93        /// - **Binary representation**: `0b00000000000000100000000000000000`
94        /// - **Equivalent to**: `AVSEEK_FORCE`
95        Force = AVSEEK_FORCE as i32,
96    }
97}
98
99bitwise_enum!(AVSeekWhence);
100
101impl PartialEq<i32> for AVSeekWhence {
102    fn eq(&self, other: &i32) -> bool {
103        self.0 == *other
104    }
105}
106
107impl From<u32> for AVSeekWhence {
108    fn from(value: u32) -> Self {
109        AVSeekWhence(value as i32)
110    }
111}
112
113impl From<AVSeekWhence> for u32 {
114    fn from(value: AVSeekWhence) -> Self {
115        value.0 as u32
116    }
117}