gstreamer_play/
play_message.rs
1use crate::{PlayMediaInfo, PlayMessageType, PlayState};
2
3#[derive(Clone, PartialEq, Debug)]
4#[non_exhaustive]
5#[doc(alias = "GstPlayMessage")]
6pub enum PlayMessage {
7 #[doc(alias = "GST_PLAY_MESSAGE_URI_LOADED")]
8 UriLoaded,
9 #[doc(alias = "GST_PLAY_MESSAGE_POSITION_UPDATED")]
10 PositionUpdated { position: Option<gst::ClockTime> },
11 #[doc(alias = "GST_PLAY_MESSAGE_DURATION_CHANGED")]
12 DurationChanged { duration: Option<gst::ClockTime> },
13 #[doc(alias = "GST_PLAY_MESSAGE_STATE_CHANGED")]
14 StateChanged { state: PlayState },
15 #[doc(alias = "GST_PLAY_MESSAGE_BUFFERING")]
16 Buffering { percent: u32 },
17 #[doc(alias = "GST_PLAY_MESSAGE_END_OF_STREAM")]
18 EndOfStream,
19 #[doc(alias = "GST_PLAY_MESSAGE_ERROR")]
20 Error {
21 error: glib::Error,
22 details: Option<gst::Structure>,
23 },
24 #[doc(alias = "GST_PLAY_MESSAGE_WARNING")]
25 Warning {
26 error: glib::Error,
27 details: Option<gst::Structure>,
28 },
29 #[doc(alias = "GST_PLAY_MESSAGE_VIDEO_DIMENSIONS_CHANGED")]
30 VideoDimensionsChanged { width: u32, height: u32 },
31 #[doc(alias = "GST_PLAY_MESSAGE_MEDIA_INFO_UPDATED")]
32 MediaInfoUpdated { info: PlayMediaInfo },
33 #[doc(alias = "GST_PLAY_MESSAGE_VOLUME_CHANGED")]
34 VolumeChanged { volume: f64 },
35 #[doc(alias = "GST_PLAY_MESSAGE_MUTE_CHANGED")]
36 MuteChanged { muted: bool },
37 #[doc(alias = "GST_PLAY_MESSAGE_SEEK_DONE")]
38 SeekDone,
39}
40
41impl PlayMessage {
42 #[doc(alias = "gst_play_message_parse_position_updated")]
43 #[doc(alias = "gst_play_message_parse_duration_updated")]
44 #[doc(alias = "gst_play_message_parse_state_changed")]
45 #[doc(alias = "gst_play_message_parse_buffering_percent")]
46 #[doc(alias = "gst_play_message_parse_error")]
47 #[doc(alias = "gst_play_message_parse_warning")]
48 #[doc(alias = "gst_play_message_parse_video_dimensions_changed")]
49 #[doc(alias = "gst_play_message_parse_media_info_updated")]
50 #[doc(alias = "gst_play_message_parse_muted_changed")]
51 #[doc(alias = "gst_play_message_parse_volume_changed")]
52 pub fn parse(msg: &gst::Message) -> Result<Self, glib::error::BoolError> {
53 skip_assert_initialized!();
54 if msg.type_() != gst::MessageType::Application {
55 return Err(glib::bool_error!("Invalid play message"));
56 }
57 match PlayMessageType::parse_type(msg) {
58 PlayMessageType::UriLoaded => Ok(Self::UriLoaded),
59 PlayMessageType::PositionUpdated => {
60 let position = PlayMessageType::parse_position_updated(msg);
61 Ok(Self::PositionUpdated { position })
62 }
63 #[allow(deprecated)]
64 PlayMessageType::DurationChanged => {
65 let duration = PlayMessageType::parse_duration_updated(msg);
66 Ok(Self::DurationChanged { duration })
67 }
68 PlayMessageType::StateChanged => {
69 let state = PlayMessageType::parse_state_changed(msg);
70 Ok(Self::StateChanged { state })
71 }
72 #[allow(deprecated)]
73 PlayMessageType::Buffering => {
74 let percent = PlayMessageType::parse_buffering_percent(msg);
75 Ok(Self::Buffering { percent })
76 }
77 PlayMessageType::EndOfStream => Ok(Self::EndOfStream),
78 PlayMessageType::Error => {
79 let (error, details) = PlayMessageType::parse_error(msg);
80 Ok(Self::Error { error, details })
81 }
82 PlayMessageType::Warning => {
83 let (error, details) = PlayMessageType::parse_warning(msg);
84 Ok(Self::Warning { error, details })
85 }
86 PlayMessageType::VideoDimensionsChanged => {
87 let (width, height) = PlayMessageType::parse_video_dimensions_changed(msg);
88 Ok(Self::VideoDimensionsChanged { width, height })
89 }
90 PlayMessageType::MediaInfoUpdated => {
91 let info = PlayMessageType::parse_media_info_updated(msg);
92 Ok(Self::MediaInfoUpdated { info })
93 }
94 PlayMessageType::VolumeChanged => {
95 let volume = PlayMessageType::parse_volume_changed(msg);
96 Ok(Self::VolumeChanged { volume })
97 }
98 PlayMessageType::MuteChanged => {
99 let muted = PlayMessageType::parse_muted_changed(msg);
100 Ok(Self::MuteChanged { muted })
101 }
102 PlayMessageType::SeekDone => Ok(Self::SeekDone),
103 _ => Err(glib::bool_error!("Invalid play message")),
104 }
105 }
106}