hylarana_common/
codec.rs

1use std::{
2    io::{Error, ErrorKind},
3    str::FromStr,
4};
5
6use serde::{Deserialize, Serialize};
7
8/// Video decoder type.
9#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)]
10pub enum VideoDecoderType {
11    /// [Open H264](https://www.openh264.org/)
12    ///
13    /// OpenH264 is a codec library which supports H.264 encoding and decoding.
14    H264,
15    /// [D3D11VA](https://learn.microsoft.com/en-us/windows/win32/medfound/direct3d-11-video-apis)
16    ///
17    /// Accelerated video decoding using Direct3D 11 Video APIs.
18    D3D11,
19    /// [H264 QSV](https://en.wikipedia.org/wiki/Intel_Quick_Sync_Video)
20    ///
21    /// Intel Quick Sync Video is Intel's brand for its dedicated video encoding
22    /// and decoding hardware core.
23    Qsv,
24    /// [Video Toolbox](https://developer.apple.com/documentation/videotoolbox)
25    ///
26    /// VideoToolbox is a low-level framework that provides direct access to
27    /// hardware encoders and decoders.
28    VideoToolBox,
29}
30
31impl ToString for VideoDecoderType {
32    fn to_string(&self) -> String {
33        match self {
34            Self::H264 => "h264",
35            Self::D3D11 => "d3d11va",
36            Self::Qsv => "h264_qsv",
37            Self::VideoToolBox => "h264_videotoolbox",
38        }
39        .to_string()
40    }
41}
42
43impl FromStr for VideoDecoderType {
44    type Err = Error;
45
46    fn from_str(value: &str) -> Result<Self, Self::Err> {
47        Ok(match value {
48            "h264" => Self::H264,
49            "d3d11va" => Self::D3D11,
50            "h264_qsv" => Self::Qsv,
51            "h264_videotoolbox" => Self::VideoToolBox,
52            _ => return Err(Error::new(ErrorKind::InvalidInput, value)),
53        })
54    }
55}
56
57/// Video encoder type.
58#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)]
59pub enum VideoEncoderType {
60    /// [X264](https://www.videolan.org/developers/x264.html)
61    ///
62    /// x264 is a free software library and application for encoding video
63    /// streams into the H.264/MPEG-4 AVC compression format, and is released
64    /// under the terms of the GNU GPL.
65    X264,
66    /// [H264 QSV](https://en.wikipedia.org/wiki/Intel_Quick_Sync_Video)
67    ///
68    /// Intel Quick Sync Video is Intel's brand for its dedicated video encoding
69    /// and decoding hardware core.
70    Qsv,
71    /// [Video Toolbox](https://developer.apple.com/documentation/videotoolbox)
72    ///
73    /// VideoToolbox is a low-level framework that provides direct access to
74    /// hardware encoders and decoders.
75    VideoToolBox,
76}
77
78impl ToString for VideoEncoderType {
79    fn to_string(&self) -> String {
80        match self {
81            Self::X264 => "libx264",
82            Self::Qsv => "h264_qsv",
83            Self::VideoToolBox => "h264_videotoolbox",
84        }
85        .to_string()
86    }
87}
88
89impl FromStr for VideoEncoderType {
90    type Err = Error;
91
92    fn from_str(value: &str) -> Result<Self, Self::Err> {
93        Ok(match value {
94            "libx264" => Self::X264,
95            "h264_qsv" => Self::Qsv,
96            "h264_videotoolbox" => Self::VideoToolBox,
97            _ => return Err(Error::new(ErrorKind::InvalidInput, value)),
98        })
99    }
100}