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
// Take a look at the license at the top of the repository in the LICENSE file.

use glib::translate::*;

use crate::{ffi, Play};

impl Play {
    /// Get a copy of the current configuration of the play. This configuration
    /// can either be modified and used for the [`set_config()`][Self::set_config()] call
    /// or it must be freed after usage.
    ///
    /// # Returns
    ///
    /// a copy of the current configuration of `self`. Use
    /// `gst_structure_free()` after usage or [`set_config()`][Self::set_config()].
    #[doc(alias = "get_config")]
    #[doc(alias = "gst_play_get_config")]
    pub fn config(&self) -> crate::PlayConfig {
        unsafe { from_glib_full(ffi::gst_play_get_config(self.to_glib_none().0)) }
    }

    /// Set the configuration of the play. If the play is already configured, and
    /// the configuration hasn't changed, this function will return [`true`]. If the
    /// play is not in the GST_PLAY_STATE_STOPPED, this method will return [`false`]
    /// and active configuration will remain.
    ///
    /// `config` is a [`gst::Structure`][crate::gst::Structure] that contains the configuration parameters for
    /// the play.
    ///
    /// This function takes ownership of `config`.
    /// ## `config`
    /// a [`gst::Structure`][crate::gst::Structure]
    ///
    /// # Returns
    ///
    /// [`true`] when the configuration could be set.
    #[doc(alias = "gst_play_set_config")]
    pub fn set_config(&self, config: crate::PlayConfig) -> Result<(), glib::error::BoolError> {
        unsafe {
            glib::result_from_gboolean!(
                ffi::gst_play_set_config(self.to_glib_none().0, config.into_glib_ptr()),
                "Failed to set config",
            )
        }
    }

    /// Get a snapshot of the currently selected video stream, if any. The format can be
    /// selected with `format` and optional configuration is possible with `config`.
    /// Currently supported settings are:
    /// - width, height of type G_TYPE_INT
    /// - pixel-aspect-ratio of type GST_TYPE_FRACTION
    ///  Except for GST_PLAY_THUMBNAIL_RAW_NATIVE format, if no config is set, pixel-aspect-ratio would be 1/1
    /// ## `format`
    /// output format of the video snapshot
    /// ## `config`
    /// Additional configuration
    ///
    /// # Returns
    ///
    /// Current video snapshot sample or [`None`] on failure
    #[doc(alias = "gst_play_get_video_snapshot")]
    #[doc(alias = "get_video_snapshot")]
    pub fn video_snapshot(
        &self,
        format: crate::PlaySnapshotFormat,
        config: Option<&gst::StructureRef>,
    ) -> Option<gst::Sample> {
        unsafe {
            from_glib_full(ffi::gst_play_get_video_snapshot(
                self.to_glib_none().0,
                format.into_glib(),
                mut_override(config.map(|c| c.as_ptr()).unwrap_or(std::ptr::null())),
            ))
        }
    }
}

impl Default for Play {
    fn default() -> Self {
        Self::new(None::<crate::PlayVideoRenderer>)
    }
}