gstreamer 0.13.0

Rust bindings for GStreamer
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
// Copyright (C) 2017 Sebastian Dröge <sebastian@centricular.com>
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use std::cmp;
use std::error::Error;
use std::fmt;
use ClockReturn;
use FlowReturn;
use PadLinkReturn;
use StateChangeReturn;

use glib::translate::ToGlib;

impl StateChangeReturn {
    pub fn into_result(self) -> Result<StateChangeSuccess, StateChangeError> {
        match self {
            StateChangeReturn::Success => Ok(StateChangeSuccess::Success),
            StateChangeReturn::Async => Ok(StateChangeSuccess::Async),
            StateChangeReturn::NoPreroll => Ok(StateChangeSuccess::NoPreroll),
            StateChangeReturn::Failure => Err(StateChangeError),
            _ => Err(StateChangeError),
        }
    }

    pub fn from_error(_: StateChangeError) -> Self {
        StateChangeReturn::Failure
    }

    pub fn from_ok(v: StateChangeSuccess) -> Self {
        match v {
            StateChangeSuccess::Success => StateChangeReturn::Success,
            StateChangeSuccess::Async => StateChangeReturn::Async,
            StateChangeSuccess::NoPreroll => StateChangeReturn::NoPreroll,
        }
    }
}

#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
pub enum StateChangeSuccess {
    Success,
    Async,
    NoPreroll,
}

impl From<StateChangeSuccess> for StateChangeReturn {
    fn from(value: StateChangeSuccess) -> Self {
        StateChangeReturn::from_ok(value)
    }
}

#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
#[must_use]
pub struct StateChangeError;

impl fmt::Display for StateChangeError {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "State-change error")
    }
}

impl From<StateChangeError> for StateChangeReturn {
    fn from(value: StateChangeError) -> Self {
        StateChangeReturn::from_error(value)
    }
}

impl Error for StateChangeError {
    fn description(&self) -> &str {
        "Element failed to change its state"
    }
}

impl From<Result<StateChangeSuccess, StateChangeError>> for StateChangeReturn {
    fn from(res: Result<StateChangeSuccess, StateChangeError>) -> Self {
        match res {
            Ok(success) => StateChangeReturn::from_ok(success),
            Err(error) => StateChangeReturn::from_error(error),
        }
    }
}

impl FlowReturn {
    pub fn into_result(self) -> Result<FlowSuccess, FlowError> {
        match self {
            FlowReturn::CustomSuccess2 => Ok(FlowSuccess::CustomSuccess2),
            FlowReturn::CustomSuccess1 => Ok(FlowSuccess::CustomSuccess1),
            FlowReturn::CustomSuccess => Ok(FlowSuccess::CustomSuccess),
            FlowReturn::Ok => Ok(FlowSuccess::Ok),
            FlowReturn::NotLinked => Err(FlowError::NotLinked),
            FlowReturn::Flushing => Err(FlowError::Flushing),
            FlowReturn::Eos => Err(FlowError::Eos),
            FlowReturn::NotNegotiated => Err(FlowError::NotNegotiated),
            FlowReturn::Error => Err(FlowError::Error),
            FlowReturn::NotSupported => Err(FlowError::NotSupported),
            FlowReturn::CustomError => Err(FlowError::CustomError),
            FlowReturn::CustomError1 => Err(FlowError::CustomError1),
            FlowReturn::CustomError2 => Err(FlowError::CustomError2),
            _ => Err(FlowError::Error),
        }
    }

    pub fn into_result_value<T, F: FnOnce() -> T>(self, func: F) -> Result<T, FlowError> {
        match self.into_result() {
            Ok(_) => Ok(func()),
            Err(err) => Err(err),
        }
    }

    pub fn from_error(v: FlowError) -> Self {
        match v {
            FlowError::NotLinked => FlowReturn::NotLinked,
            FlowError::Flushing => FlowReturn::Flushing,
            FlowError::Eos => FlowReturn::Eos,
            FlowError::NotNegotiated => FlowReturn::NotNegotiated,
            FlowError::Error => FlowReturn::Error,
            FlowError::NotSupported => FlowReturn::NotSupported,
            FlowError::CustomError => FlowReturn::CustomError,
            FlowError::CustomError1 => FlowReturn::CustomError1,
            FlowError::CustomError2 => FlowReturn::CustomError2,
        }
    }

    pub fn from_ok(v: FlowSuccess) -> Self {
        match v {
            FlowSuccess::CustomSuccess2 => FlowReturn::CustomSuccess2,
            FlowSuccess::CustomSuccess1 => FlowReturn::CustomSuccess1,
            FlowSuccess::CustomSuccess => FlowReturn::CustomSuccess,
            FlowSuccess::Ok => FlowReturn::Ok,
        }
    }
}

#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
pub enum FlowSuccess {
    CustomSuccess2,
    CustomSuccess1,
    CustomSuccess,
    Ok,
}

impl From<FlowSuccess> for FlowReturn {
    fn from(value: FlowSuccess) -> Self {
        FlowReturn::from_ok(value)
    }
}

#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
#[must_use]
pub enum FlowError {
    NotLinked,
    Flushing,
    Eos,
    NotNegotiated,
    Error,
    NotSupported,
    CustomError,
    CustomError1,
    CustomError2,
}

impl fmt::Display for FlowError {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "Flow error: {}", self.description())
    }
}

impl From<FlowError> for FlowReturn {
    fn from(value: FlowError) -> Self {
        FlowReturn::from_error(value)
    }
}

impl Error for FlowError {
    fn description(&self) -> &str {
        match *self {
            FlowError::NotLinked => "Pad is not linked",
            FlowError::Flushing => "Pad is flushing",
            FlowError::Eos => "Pad is EOS",
            FlowError::NotNegotiated => "Pad is not negotiated",
            FlowError::Error => {
                "Some (fatal) error occurred. Element generating this error should post an error message with more details"
            }
            FlowError::NotSupported => "This operation is not supported",
            FlowError::CustomError => {
                "Elements can use values starting from this (and lower) to define custom error codes"
            }
            FlowError::CustomError1 => "Pre-defined custom error code",
            FlowError::CustomError2 => "Pre-defined custom error code",
        }
    }
}

impl From<Result<FlowSuccess, FlowError>> for FlowReturn {
    fn from(res: Result<FlowSuccess, FlowError>) -> Self {
        match res {
            Ok(success) => FlowReturn::from_ok(success),
            Err(error) => FlowReturn::from_error(error),
        }
    }
}

impl PadLinkReturn {
    pub fn into_result(self) -> Result<PadLinkSuccess, PadLinkError> {
        match self {
            PadLinkReturn::Ok => Ok(PadLinkSuccess),
            PadLinkReturn::WrongHierarchy => Err(PadLinkError::WrongHierarchy),
            PadLinkReturn::WasLinked => Err(PadLinkError::WasLinked),
            PadLinkReturn::WrongDirection => Err(PadLinkError::WrongDirection),
            PadLinkReturn::Noformat => Err(PadLinkError::Noformat),
            PadLinkReturn::Nosched => Err(PadLinkError::Nosched),
            PadLinkReturn::Refused => Err(PadLinkError::Refused),
            _ => Err(PadLinkError::Refused),
        }
    }

    pub fn from_error(v: PadLinkError) -> Self {
        match v {
            PadLinkError::WrongHierarchy => PadLinkReturn::WrongHierarchy,
            PadLinkError::WasLinked => PadLinkReturn::WasLinked,
            PadLinkError::WrongDirection => PadLinkReturn::WrongDirection,
            PadLinkError::Noformat => PadLinkReturn::Noformat,
            PadLinkError::Nosched => PadLinkReturn::Nosched,
            PadLinkError::Refused => PadLinkReturn::Refused,
        }
    }

    pub fn from_ok(_: PadLinkSuccess) -> Self {
        PadLinkReturn::Ok
    }
}

#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
pub struct PadLinkSuccess;

impl From<PadLinkSuccess> for PadLinkReturn {
    fn from(value: PadLinkSuccess) -> Self {
        PadLinkReturn::from_ok(value)
    }
}

#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
#[must_use]
pub enum PadLinkError {
    WrongHierarchy,
    WasLinked,
    WrongDirection,
    Noformat,
    Nosched,
    Refused,
}

impl fmt::Display for PadLinkError {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "Pad failed to link: {}", self.description())
    }
}

impl From<PadLinkError> for PadLinkReturn {
    fn from(value: PadLinkError) -> Self {
        PadLinkReturn::from_error(value)
    }
}

impl Error for PadLinkError {
    fn description(&self) -> &str {
        match *self {
            PadLinkError::WrongHierarchy => "Pads have no common grandparent",
            PadLinkError::WasLinked => "Pad was already linked",
            PadLinkError::WrongDirection => "Pads have wrong direction",
            PadLinkError::Noformat => "Pads do not have common format",
            PadLinkError::Nosched => "Pads cannot cooperate in scheduling",
            PadLinkError::Refused => "Refused for some other reason",
        }
    }
}

impl From<Result<PadLinkSuccess, PadLinkError>> for PadLinkReturn {
    fn from(res: Result<PadLinkSuccess, PadLinkError>) -> Self {
        match res {
            Ok(success) => PadLinkReturn::from_ok(success),
            Err(error) => PadLinkReturn::from_error(error),
        }
    }
}

impl ClockReturn {
    pub fn into_result(self) -> Result<ClockSuccess, ClockError> {
        match self {
            ClockReturn::Ok => Ok(ClockSuccess::Ok),
            ClockReturn::Done => Ok(ClockSuccess::Done),
            ClockReturn::Early => Err(ClockError::Early),
            ClockReturn::Unscheduled => Err(ClockError::Unscheduled),
            ClockReturn::Busy => Err(ClockError::Busy),
            ClockReturn::Badtime => Err(ClockError::Badtime),
            ClockReturn::Error => Err(ClockError::Error),
            ClockReturn::Unsupported => Err(ClockError::Unsupported),
            _ => Err(ClockError::Error),
        }
    }

    pub fn from_error(v: ClockError) -> Self {
        match v {
            ClockError::Early => ClockReturn::Early,
            ClockError::Unscheduled => ClockReturn::Unscheduled,
            ClockError::Busy => ClockReturn::Busy,
            ClockError::Badtime => ClockReturn::Badtime,
            ClockError::Error => ClockReturn::Error,
            ClockError::Unsupported => ClockReturn::Unsupported,
        }
    }

    pub fn from_ok(v: ClockSuccess) -> Self {
        match v {
            ClockSuccess::Ok => ClockReturn::Ok,
            ClockSuccess::Done => ClockReturn::Done,
        }
    }
}

#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
pub enum ClockSuccess {
    Ok,
    Done,
}

impl From<ClockSuccess> for ClockReturn {
    fn from(value: ClockSuccess) -> Self {
        ClockReturn::from_ok(value)
    }
}

#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
#[must_use]
pub enum ClockError {
    Early,
    Unscheduled,
    Busy,
    Badtime,
    Error,
    Unsupported,
}

impl fmt::Display for ClockError {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "Clock error: {}", self.description())
    }
}

impl From<ClockError> for ClockReturn {
    fn from(value: ClockError) -> Self {
        ClockReturn::from_error(value)
    }
}

impl Error for ClockError {
    fn description(&self) -> &str {
        match *self {
            ClockError::Early => "The operation was scheduled too late",
            ClockError::Unscheduled => "The clockID was unscheduled",
            ClockError::Busy => "The ClockID is busy",
            ClockError::Badtime => "A bad time was provided to a function",
            ClockError::Error => "An error occurred",
            ClockError::Unsupported => "Operation is not supported",
        }
    }
}

impl From<Result<ClockSuccess, ClockError>> for ClockReturn {
    fn from(res: Result<ClockSuccess, ClockError>) -> Self {
        match res {
            Ok(success) => ClockReturn::from_ok(success),
            Err(error) => ClockReturn::from_error(error),
        }
    }
}

impl PartialOrd for ::TypeFindProbability {
    fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> {
        self.to_glib().partial_cmp(&other.to_glib())
    }
}

impl Ord for ::TypeFindProbability {
    fn cmp(&self, other: &Self) -> cmp::Ordering {
        self.to_glib().cmp(&other.to_glib())
    }
}

impl PartialOrd for ::Rank {
    fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> {
        self.to_glib().partial_cmp(&other.to_glib())
    }
}

impl Ord for ::Rank {
    fn cmp(&self, other: &Self) -> cmp::Ordering {
        self.to_glib().cmp(&other.to_glib())
    }
}

#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
#[must_use]
pub enum TagError {
    TypeMismatch,
}

impl fmt::Display for TagError {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "Tag error: {}", self.description())
    }
}

impl Error for TagError {
    fn description(&self) -> &str {
        match *self {
            TagError::TypeMismatch => "The value type doesn't match with the specified Tag",
        }
    }
}