hylarana_common/
lib.rs

1pub mod atomic;
2pub mod codec;
3pub mod frame;
4pub mod logger;
5pub mod strings;
6
7#[cfg(target_os = "windows")]
8pub mod win32;
9
10#[cfg(target_os = "macos")]
11pub mod macos;
12
13use std::net::SocketAddr;
14
15use frame::VideoFormat;
16use serde::{Deserialize, Serialize};
17
18#[derive(Debug, Default, Clone, Copy, Deserialize, Serialize)]
19pub struct Size {
20    #[serde(rename = "w")]
21    pub width: u32,
22    #[serde(rename = "h")]
23    pub height: u32,
24}
25
26/// Transport layer strategies.
27#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
28#[serde(tag = "t", content = "v")]
29pub enum TransportStrategy {
30    /// In straight-through mode, the sender creates an SRT server and the
31    /// receiver connects directly to the sender via the SRT protocol.
32    ///
33    /// For the sender, the network address is the address to which the SRT
34    /// server binds and listens.
35    ///
36    /// ```text
37    /// example: 0.0.0.0:8080
38    /// ```
39    ///
40    /// For the receiving end, the network address is the address of the SRT
41    /// server on the sending end.
42    ///
43    /// ```text
44    /// example: 192.168.1.100:8080
45    /// ```
46    #[serde(rename = "d")]
47    Direct(SocketAddr),
48    /// Forwarding mode, where the sender and receiver pass data through a relay
49    /// server.
50    ///
51    /// The network address is the address of the transit server.
52    #[serde(rename = "r")]
53    Relay(SocketAddr),
54    /// UDP multicast mode, where the sender sends multicast packets into the
55    /// current network and the receiver processes the multicast packets.
56    ///
57    /// The sender and receiver use the same address, which is a combination of
58    /// multicast address + port.
59    ///
60    /// ```text
61    /// example: 239.0.0.1:8080
62    /// ```
63    #[serde(rename = "m")]
64    Multicast(SocketAddr),
65}
66
67/// Transport configuration.
68#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
69pub struct TransportOptions {
70    #[serde(rename = "s")]
71    pub strategy: TransportStrategy,
72    /// see: [Maximum_transmission_unit](https://en.wikipedia.org/wiki/Maximum_transmission_unit)
73    #[serde(rename = "m")]
74    pub mtu: usize,
75}
76
77#[derive(Debug, Clone, Copy, Deserialize, Serialize)]
78pub struct MediaVideoStreamDescription {
79    #[serde(rename = "f")]
80    pub format: VideoFormat,
81    #[serde(rename = "s")]
82    pub size: Size,
83    pub fps: u8,
84    #[serde(rename = "br")]
85    pub bit_rate: u64,
86}
87
88#[derive(Debug, Clone, Copy, Deserialize, Serialize)]
89pub struct MediaAudioStreamDescription {
90    #[serde(rename = "sr")]
91    pub sample_rate: u64,
92    #[serde(rename = "cs")]
93    pub channels: u8,
94    #[serde(rename = "br")]
95    pub bit_rate: u64,
96}
97
98#[derive(Debug, Clone, Deserialize, Serialize)]
99pub struct MediaStreamDescription {
100    #[serde(rename = "i")]
101    pub id: String,
102    #[serde(rename = "t")]
103    pub transport: TransportOptions,
104    #[serde(rename = "v")]
105    pub video: Option<MediaVideoStreamDescription>,
106    #[serde(rename = "a")]
107    pub audio: Option<MediaAudioStreamDescription>,
108}