gstreamer_play/play.rs
1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use glib::translate::*;
4
5use crate::{ffi, Play};
6
7impl Play {
8 /// Get a copy of the current configuration of the play. This configuration
9 /// can either be modified and used for the [`set_config()`][Self::set_config()] call
10 /// or it must be freed after usage.
11 ///
12 /// # Returns
13 ///
14 /// a copy of the current configuration of `self`. Use
15 /// `gst_structure_free()` after usage or [`set_config()`][Self::set_config()].
16 #[doc(alias = "get_config")]
17 #[doc(alias = "gst_play_get_config")]
18 pub fn config(&self) -> crate::PlayConfig {
19 unsafe { from_glib_full(ffi::gst_play_get_config(self.to_glib_none().0)) }
20 }
21
22 /// Set the configuration of the play. If the play is already configured, and
23 /// the configuration hasn't changed, this function will return [`true`]. If the
24 /// play is not in the GST_PLAY_STATE_STOPPED, this method will return [`false`]
25 /// and active configuration will remain.
26 ///
27 /// `config` is a [`gst::Structure`][crate::gst::Structure] that contains the configuration parameters for
28 /// the play.
29 ///
30 /// This function takes ownership of `config`.
31 /// ## `config`
32 /// a [`gst::Structure`][crate::gst::Structure]
33 ///
34 /// # Returns
35 ///
36 /// [`true`] when the configuration could be set.
37 #[doc(alias = "gst_play_set_config")]
38 pub fn set_config(&self, config: crate::PlayConfig) -> Result<(), glib::error::BoolError> {
39 unsafe {
40 glib::result_from_gboolean!(
41 ffi::gst_play_set_config(self.to_glib_none().0, config.into_glib_ptr()),
42 "Failed to set config",
43 )
44 }
45 }
46
47 /// Get a snapshot of the currently selected video stream, if any. The format can be
48 /// selected with `format` and optional configuration is possible with `config`.
49 /// Currently supported settings are:
50 /// - width, height of type G_TYPE_INT
51 /// - pixel-aspect-ratio of type GST_TYPE_FRACTION
52 /// Except for GST_PLAY_THUMBNAIL_RAW_NATIVE format, if no config is set, pixel-aspect-ratio would be 1/1
53 /// ## `format`
54 /// output format of the video snapshot
55 /// ## `config`
56 /// Additional configuration
57 ///
58 /// # Returns
59 ///
60 /// Current video snapshot sample or [`None`] on failure
61 #[doc(alias = "gst_play_get_video_snapshot")]
62 #[doc(alias = "get_video_snapshot")]
63 pub fn video_snapshot(
64 &self,
65 format: crate::PlaySnapshotFormat,
66 config: Option<&gst::StructureRef>,
67 ) -> Option<gst::Sample> {
68 unsafe {
69 from_glib_full(ffi::gst_play_get_video_snapshot(
70 self.to_glib_none().0,
71 format.into_glib(),
72 mut_override(config.map(|c| c.as_ptr()).unwrap_or(std::ptr::null())),
73 ))
74 }
75 }
76}
77
78impl Default for Play {
79 fn default() -> Self {
80 Self::new(None::<crate::PlayVideoRenderer>)
81 }
82}