Skip to main content

gst_client/
gstd_types.rs

1//! [`GStreamer Daemon HTTP`][1] API structures.
2//!
3//! [1]: https://developer.ridgerun.com/wiki/index.php/GStreamer_Daemon_-_HTTP_API
4#![allow(unreachable_pub, missing_docs)]
5
6use derive_more::{Display, Error};
7use serde::{Deserialize, Serialize};
8use serde_repr::{Deserialize_repr, Serialize_repr};
9
10/// Response returned by [`GStreamer Daemon`][1] API.
11///
12/// [1]: https://developer.ridgerun.com/wiki/index.php/GStreamer_Daemon
13#[derive(Clone, Debug, Deserialize, Serialize)]
14#[serde(untagged)]
15pub enum ApiResponse {
16    Success(SuccessResponse),
17    Error(ErrorResponse),
18}
19
20/// Successful response by [`GStreamer Daemon`][1] API.
21///
22/// [1]: https://developer.ridgerun.com/wiki/index.php/GStreamer_Daemon
23#[derive(Clone, Debug, Deserialize, Serialize)]
24pub struct SuccessResponse {
25    pub code: ResponseCode,
26    /// Description of command response.
27    /// Same as [`SuccessResponse::code`] but with text
28    pub description: String,
29    /// The actual response data from the server
30    pub response: ResponseT,
31}
32
33/// Unsuccessful response by [`GStreamer Daemon`][1] API.
34///
35/// [1]: https://developer.ridgerun.com/wiki/index.php/GStreamer_Daemon
36#[derive(Clone, Debug, Deserialize, Serialize)]
37pub struct ErrorResponse {
38    pub code: ResponseCode,
39    pub description: String,
40    pub response: Option<()>,
41}
42
43/// Response Codes for [`SuccessResponse`] of [`GStD`]
44///
45/// [`GStD`]: https://developer.ridgerun.com/wiki/index.php/GStreamer_Daemon
46#[derive(Serialize_repr, Deserialize_repr, PartialEq, Eq, Debug, Clone, Copy, Error, Display)]
47#[repr(u8)]
48pub enum ResponseCode {
49    ///Everything went OK
50    Success = 0,
51    /// A mandatory argument was passed NULL
52    NullArgument = 1,
53    /// A bad pipeline description was provided
54    BadDescription = 2,
55    /// The name trying to be used already exists
56    ExistingName = 3,
57    /// Missing initialization
58    MissingInitialization = 4,
59    /// The requested pipeline was not found
60    NoPipeline = 5,
61    /// The requested resource was not found
62    NoResource = 6,
63    /// Cannot create a resource in the given property
64    NoCreate = 7,
65    /// The resource to create already exists
66    ExistingResource = 8,
67    /// Cannot update the given property
68    NoUpdate = 9,
69    /// Unknown command
70    BadCommand = 10,
71    /// Cannot read the given resource
72    NoRead = 11,
73    ///Cannot connect
74    NoConnection = 12,
75    /// The given value is incorrect
76    BadValue = 13,
77    /// Failed to change state of a pipeline
78    StateError = 14,
79    /// Failed to start IPC
80    IpcError = 15,
81    /// Unknown event
82    EventError = 16,
83    /// Incomplete arguments in user input
84    MissingArgument = 17,
85    /// Missing name of the pipeline
86    MissingName = 18,
87}
88
89#[derive(Clone, Debug, Deserialize, Serialize)]
90#[serde(untagged)]
91pub enum ResponseT {
92    Bus(Option<Bus>),
93    PropertiesWithNodes(PropertiesWithNodes),
94    Properties(Properties),
95    Property(Property),
96}
97
98#[derive(Clone, Debug, Deserialize, Serialize)]
99pub struct Param {
100    pub description: String,
101    pub r#type: String,
102    pub access: String,
103}
104
105/// Possible result in [`SuccessResponse::response`] after
106/// `GET /pipelines` API request
107#[derive(Clone, Debug, Deserialize, Serialize)]
108pub struct PropertiesWithNodes {
109    pub properties: Vec<Property>,
110    pub nodes: Vec<Node>,
111}
112
113/// Possible result in [`SuccessResponse::response`] after
114/// `GET /pipelines/{{pipeline_name}}/graph` API request
115#[derive(Clone, Debug, Deserialize, Serialize)]
116pub struct Properties {
117    pub properties: Vec<Property>,
118}
119
120#[derive(Clone, Debug, Deserialize, Serialize)]
121pub struct Node {
122    /// The name of [`GStreamer element`]
123    ///
124    /// [`GStreamer element`]: https://gstreamer.freedesktop.org/documentation/
125    /// application-development/basics/elements.html
126    pub name: String,
127}
128
129/// Possible result in [`SuccessResponse::response`] after
130/// `GET /pipelines/{pipeline_name}/graph` API request
131#[derive(Clone, Debug, Deserialize, Serialize)]
132pub struct Property {
133    pub name: String,
134    pub value: PropertyValue,
135    pub param: Param,
136}
137
138#[derive(Clone, Debug, Deserialize, Serialize)]
139#[serde(untagged)]
140pub enum PropertyValue {
141    String(String),
142    Integer(i32),
143    Bool(bool),
144}
145
146/// Possible result in [`SuccessResponse::response`] after
147/// `GET /pipelines/{name}/bus/message` API request
148#[derive(Clone, Debug, Deserialize, Serialize)]
149pub struct Bus {
150    pub r#type: String,
151    pub source: String,
152    pub timestamp: String,
153    pub seqnum: i64,
154    pub message: String,
155    pub debug: String,
156}