ffmpeg_the_third/codec/
threading.rs

1use crate::ffi::*;
2use libc::c_int;
3#[cfg(feature = "serialize")]
4use serde::{Deserialize, Serialize};
5
6#[derive(Eq, PartialEq, Clone, Copy, Debug)]
7pub struct Config {
8    pub kind: Type,
9    pub count: usize,
10    #[cfg(not(feature = "ffmpeg_6_0"))]
11    pub safe: bool,
12}
13
14impl Config {
15    pub fn kind(value: Type) -> Self {
16        Config {
17            kind: value,
18            ..Default::default()
19        }
20    }
21
22    pub fn count(value: usize) -> Self {
23        Config {
24            count: value,
25            ..Default::default()
26        }
27    }
28
29    #[cfg(not(feature = "ffmpeg_6_0"))]
30    pub fn safe(value: bool) -> Self {
31        Config {
32            safe: value,
33            ..Default::default()
34        }
35    }
36}
37
38impl Default for Config {
39    fn default() -> Self {
40        Config {
41            kind: Type::None,
42            count: 0,
43            #[cfg(not(feature = "ffmpeg_6_0"))]
44            safe: false,
45        }
46    }
47}
48
49#[derive(Eq, PartialEq, Clone, Copy, Debug)]
50#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
51pub enum Type {
52    None,
53    Frame,
54    Slice,
55}
56
57impl From<c_int> for Type {
58    fn from(value: c_int) -> Type {
59        match value {
60            FF_THREAD_FRAME => Type::Frame,
61            FF_THREAD_SLICE => Type::Slice,
62
63            _ => Type::None,
64        }
65    }
66}
67
68impl From<Type> for c_int {
69    fn from(value: Type) -> c_int {
70        match value {
71            Type::None => 0,
72            Type::Frame => FF_THREAD_FRAME,
73            Type::Slice => FF_THREAD_SLICE,
74        }
75    }
76}