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