ffmpeg_rs/codec/
traits.rs

1use super::{decoder, encoder};
2use codec::{Audio, Id, Video};
3use Codec;
4
5pub trait Decoder {
6    fn decoder(self) -> Option<Codec>;
7}
8
9impl<'a> Decoder for &'a str {
10    fn decoder(self) -> Option<Codec> {
11        decoder::find_by_name(self)
12    }
13}
14
15impl Decoder for Id {
16    fn decoder(self) -> Option<Codec> {
17        decoder::find(self)
18    }
19}
20
21impl Decoder for Codec {
22    fn decoder(self) -> Option<Codec> {
23        if self.is_decoder() {
24            Some(self)
25        } else {
26            None
27        }
28    }
29}
30
31impl Decoder for Option<Codec> {
32    fn decoder(self) -> Option<Codec> {
33        self.and_then(|c| c.decoder())
34    }
35}
36
37impl Decoder for Audio {
38    fn decoder(self) -> Option<Codec> {
39        if self.is_decoder() {
40            Some(*self)
41        } else {
42            None
43        }
44    }
45}
46
47impl Decoder for Video {
48    fn decoder(self) -> Option<Codec> {
49        if self.is_decoder() {
50            Some(*self)
51        } else {
52            None
53        }
54    }
55}
56
57pub trait Encoder {
58    fn encoder(self) -> Option<Codec>;
59}
60
61impl<'a> Encoder for &'a str {
62    fn encoder(self) -> Option<Codec> {
63        encoder::find_by_name(self)
64    }
65}
66
67impl Encoder for Id {
68    fn encoder(self) -> Option<Codec> {
69        encoder::find(self)
70    }
71}
72
73impl Encoder for Codec {
74    fn encoder(self) -> Option<Codec> {
75        if self.is_encoder() {
76            Some(self)
77        } else {
78            None
79        }
80    }
81}
82
83impl Encoder for Option<Codec> {
84    fn encoder(self) -> Option<Codec> {
85        self.and_then(|c| c.encoder())
86    }
87}
88
89impl Encoder for Audio {
90    fn encoder(self) -> Option<Codec> {
91        if self.is_encoder() {
92            Some(*self)
93        } else {
94            None
95        }
96    }
97}
98
99impl Encoder for Video {
100    fn encoder(self) -> Option<Codec> {
101        if self.is_encoder() {
102            Some(*self)
103        } else {
104            None
105        }
106    }
107}