1 | // Take a look at the license at the top of the repository in the LICENSE file. |
2 | |
3 | use std::{borrow::Borrow, ffi::CStr, fmt, mem, num::NonZeroU32, ops::Deref, ops::DerefMut, ptr}; |
4 | |
5 | use glib::{ |
6 | translate::*, |
7 | value::{SendValue, ValueType}, |
8 | }; |
9 | |
10 | use crate::{ |
11 | ffi, |
12 | format::{CompatibleFormattedValue, FormattedValue}, |
13 | prelude::*, |
14 | structure::*, |
15 | GenericFormattedValue, GroupId, MessageType, Object, Seqnum, TagList, |
16 | }; |
17 | |
18 | mini_object_wrapper!(Message, MessageRef, ffi::GstMessage, || { |
19 | ffi::gst_message_get_type() |
20 | }); |
21 | |
22 | impl MessageRef { |
23 | #[doc (alias = "get_src" )] |
24 | #[inline ] |
25 | pub fn src(&self) -> Option<&Object> { |
26 | unsafe { |
27 | if (*self.as_ptr()).src.is_null() { |
28 | None |
29 | } else { |
30 | Some(&*(&(*self.as_ptr()).src as *const *mut ffi::GstObject as *const Object)) |
31 | } |
32 | } |
33 | } |
34 | |
35 | #[doc (alias = "get_seqnum" )] |
36 | #[doc (alias = "gst_message_get_seqnum" )] |
37 | pub fn seqnum(&self) -> Seqnum { |
38 | unsafe { |
39 | let seqnum = ffi::gst_message_get_seqnum(self.as_mut_ptr()); |
40 | |
41 | if seqnum == 0 { |
42 | // seqnum for this message is invalid. This can happen with buggy elements |
43 | // overriding the seqnum with GST_SEQNUM_INVALID instead of the expected seqnum. |
44 | // As a workaround, let's generate an unused valid seqnum. |
45 | let next = Seqnum::next(); |
46 | |
47 | crate::warning!( |
48 | crate::CAT_RUST, |
49 | "get_seqnum detected invalid seqnum, returning next {:?}" , |
50 | next |
51 | ); |
52 | |
53 | return next; |
54 | } |
55 | |
56 | Seqnum(NonZeroU32::new_unchecked(seqnum)) |
57 | } |
58 | } |
59 | |
60 | #[doc (alias = "gst_message_set_seqnum" )] |
61 | pub fn set_seqnum(&self, seqnum: Seqnum) { |
62 | unsafe { |
63 | ffi::gst_message_set_seqnum(self.as_mut_ptr(), seqnum.0.get()); |
64 | } |
65 | } |
66 | |
67 | #[doc (alias = "get_structure" )] |
68 | #[doc (alias = "gst_message_get_structure" )] |
69 | #[inline ] |
70 | pub fn structure(&self) -> Option<&StructureRef> { |
71 | unsafe { |
72 | let structure = ffi::gst_message_get_structure(self.as_mut_ptr()); |
73 | if structure.is_null() { |
74 | None |
75 | } else { |
76 | Some(StructureRef::from_glib_borrow(structure)) |
77 | } |
78 | } |
79 | } |
80 | |
81 | #[doc (alias = "gst_message_writable_structure" )] |
82 | #[inline ] |
83 | pub fn structure_mut(&mut self) -> &mut StructureRef { |
84 | unsafe { |
85 | StructureRef::from_glib_borrow_mut(ffi::gst_message_writable_structure( |
86 | self.as_mut_ptr(), |
87 | )) |
88 | } |
89 | } |
90 | |
91 | #[cfg (feature = "v1_26" )] |
92 | #[cfg_attr (docsrs, doc(cfg(feature = "v1_26" )))] |
93 | #[doc (alias = "gst_message_writable_details" )] |
94 | #[inline ] |
95 | pub fn details(&self) -> Option<&StructureRef> { |
96 | unsafe { |
97 | let structure = ffi::gst_message_writable_details(self.as_mut_ptr()); |
98 | if structure.is_null() { |
99 | None |
100 | } else { |
101 | Some(StructureRef::from_glib_borrow(structure)) |
102 | } |
103 | } |
104 | } |
105 | |
106 | #[cfg (feature = "v1_26" )] |
107 | #[cfg_attr (docsrs, doc(cfg(feature = "v1_26" )))] |
108 | #[doc (alias = "gst_message_writable_details" )] |
109 | #[inline ] |
110 | pub fn details_mut(&mut self) -> &mut StructureRef { |
111 | unsafe { |
112 | StructureRef::from_glib_borrow_mut(ffi::gst_message_writable_details(self.as_mut_ptr())) |
113 | } |
114 | } |
115 | |
116 | #[cfg (feature = "v1_26" )] |
117 | #[cfg_attr (docsrs, doc(cfg(feature = "v1_26" )))] |
118 | #[doc (alias = "gst_message_set_details" )] |
119 | #[inline ] |
120 | pub fn set_details(&mut self, structure: Structure) { |
121 | unsafe { |
122 | ffi::gst_message_set_details(self.as_mut_ptr(), structure.into_glib_ptr()); |
123 | } |
124 | } |
125 | |
126 | #[doc (alias = "gst_message_has_name" )] |
127 | #[inline ] |
128 | pub fn has_name(&self, name: &str) -> bool { |
129 | self.structure().is_some_and(|s| s.has_name(name)) |
130 | } |
131 | |
132 | pub fn view(&self) -> MessageView { |
133 | unsafe { |
134 | let type_ = (*self.as_ptr()).type_; |
135 | |
136 | match type_ { |
137 | ffi::GST_MESSAGE_EOS => Eos::view(self), |
138 | ffi::GST_MESSAGE_ERROR => Error::view(self), |
139 | ffi::GST_MESSAGE_WARNING => Warning::view(self), |
140 | ffi::GST_MESSAGE_INFO => Info::view(self), |
141 | ffi::GST_MESSAGE_TAG => Tag::view(self), |
142 | ffi::GST_MESSAGE_BUFFERING => Buffering::view(self), |
143 | ffi::GST_MESSAGE_STATE_CHANGED => StateChanged::view(self), |
144 | ffi::GST_MESSAGE_STATE_DIRTY => StateDirty::view(self), |
145 | ffi::GST_MESSAGE_STEP_DONE => StepDone::view(self), |
146 | ffi::GST_MESSAGE_CLOCK_PROVIDE => ClockProvide::view(self), |
147 | ffi::GST_MESSAGE_CLOCK_LOST => ClockLost::view(self), |
148 | ffi::GST_MESSAGE_NEW_CLOCK => NewClock::view(self), |
149 | ffi::GST_MESSAGE_STRUCTURE_CHANGE => StructureChange::view(self), |
150 | ffi::GST_MESSAGE_STREAM_STATUS => StreamStatus::view(self), |
151 | ffi::GST_MESSAGE_APPLICATION => Application::view(self), |
152 | ffi::GST_MESSAGE_ELEMENT => Element::view(self), |
153 | ffi::GST_MESSAGE_SEGMENT_START => SegmentStart::view(self), |
154 | ffi::GST_MESSAGE_SEGMENT_DONE => SegmentDone::view(self), |
155 | ffi::GST_MESSAGE_DURATION_CHANGED => DurationChanged::view(self), |
156 | ffi::GST_MESSAGE_LATENCY => Latency::view(self), |
157 | ffi::GST_MESSAGE_ASYNC_START => AsyncStart::view(self), |
158 | ffi::GST_MESSAGE_ASYNC_DONE => AsyncDone::view(self), |
159 | ffi::GST_MESSAGE_REQUEST_STATE => RequestState::view(self), |
160 | ffi::GST_MESSAGE_STEP_START => StepStart::view(self), |
161 | ffi::GST_MESSAGE_QOS => Qos::view(self), |
162 | ffi::GST_MESSAGE_PROGRESS => Progress::view(self), |
163 | ffi::GST_MESSAGE_TOC => Toc::view(self), |
164 | ffi::GST_MESSAGE_RESET_TIME => ResetTime::view(self), |
165 | ffi::GST_MESSAGE_STREAM_START => StreamStart::view(self), |
166 | ffi::GST_MESSAGE_NEED_CONTEXT => NeedContext::view(self), |
167 | ffi::GST_MESSAGE_HAVE_CONTEXT => HaveContext::view(self), |
168 | ffi::GST_MESSAGE_DEVICE_ADDED => DeviceAdded::view(self), |
169 | ffi::GST_MESSAGE_DEVICE_REMOVED => DeviceRemoved::view(self), |
170 | ffi::GST_MESSAGE_REDIRECT => Redirect::view(self), |
171 | ffi::GST_MESSAGE_PROPERTY_NOTIFY => PropertyNotify::view(self), |
172 | ffi::GST_MESSAGE_STREAM_COLLECTION => StreamCollection::view(self), |
173 | ffi::GST_MESSAGE_STREAMS_SELECTED => StreamsSelected::view(self), |
174 | #[cfg (feature = "v1_16" )] |
175 | ffi::GST_MESSAGE_DEVICE_CHANGED => DeviceChanged::view(self), |
176 | #[cfg (feature = "v1_18" )] |
177 | ffi::GST_MESSAGE_INSTANT_RATE_REQUEST => InstantRateRequest::view(self), |
178 | _ => MessageView::Other, |
179 | } |
180 | } |
181 | } |
182 | |
183 | pub fn view_mut(&mut self) -> MessageViewMut { |
184 | unsafe { |
185 | let type_ = (*self.as_ptr()).type_; |
186 | |
187 | match type_ { |
188 | ffi::GST_MESSAGE_EOS => Eos::view_mut(self), |
189 | ffi::GST_MESSAGE_ERROR => Error::view_mut(self), |
190 | ffi::GST_MESSAGE_WARNING => Warning::view_mut(self), |
191 | ffi::GST_MESSAGE_INFO => Info::view_mut(self), |
192 | ffi::GST_MESSAGE_TAG => Tag::view_mut(self), |
193 | ffi::GST_MESSAGE_BUFFERING => Buffering::view_mut(self), |
194 | ffi::GST_MESSAGE_STATE_CHANGED => StateChanged::view_mut(self), |
195 | ffi::GST_MESSAGE_STATE_DIRTY => StateDirty::view_mut(self), |
196 | ffi::GST_MESSAGE_STEP_DONE => StepDone::view_mut(self), |
197 | ffi::GST_MESSAGE_CLOCK_PROVIDE => ClockProvide::view_mut(self), |
198 | ffi::GST_MESSAGE_CLOCK_LOST => ClockLost::view_mut(self), |
199 | ffi::GST_MESSAGE_NEW_CLOCK => NewClock::view_mut(self), |
200 | ffi::GST_MESSAGE_STRUCTURE_CHANGE => StructureChange::view_mut(self), |
201 | ffi::GST_MESSAGE_STREAM_STATUS => StreamStatus::view_mut(self), |
202 | ffi::GST_MESSAGE_APPLICATION => Application::view_mut(self), |
203 | ffi::GST_MESSAGE_ELEMENT => Element::view_mut(self), |
204 | ffi::GST_MESSAGE_SEGMENT_START => SegmentStart::view_mut(self), |
205 | ffi::GST_MESSAGE_SEGMENT_DONE => SegmentDone::view_mut(self), |
206 | ffi::GST_MESSAGE_DURATION_CHANGED => DurationChanged::view_mut(self), |
207 | ffi::GST_MESSAGE_LATENCY => Latency::view_mut(self), |
208 | ffi::GST_MESSAGE_ASYNC_START => AsyncStart::view_mut(self), |
209 | ffi::GST_MESSAGE_ASYNC_DONE => AsyncDone::view_mut(self), |
210 | ffi::GST_MESSAGE_REQUEST_STATE => RequestState::view_mut(self), |
211 | ffi::GST_MESSAGE_STEP_START => StepStart::view_mut(self), |
212 | ffi::GST_MESSAGE_QOS => Qos::view_mut(self), |
213 | ffi::GST_MESSAGE_PROGRESS => Progress::view_mut(self), |
214 | ffi::GST_MESSAGE_TOC => Toc::view_mut(self), |
215 | ffi::GST_MESSAGE_RESET_TIME => ResetTime::view_mut(self), |
216 | ffi::GST_MESSAGE_STREAM_START => StreamStart::view_mut(self), |
217 | ffi::GST_MESSAGE_NEED_CONTEXT => NeedContext::view_mut(self), |
218 | ffi::GST_MESSAGE_HAVE_CONTEXT => HaveContext::view_mut(self), |
219 | ffi::GST_MESSAGE_DEVICE_ADDED => DeviceAdded::view_mut(self), |
220 | ffi::GST_MESSAGE_DEVICE_REMOVED => DeviceRemoved::view_mut(self), |
221 | ffi::GST_MESSAGE_REDIRECT => Redirect::view_mut(self), |
222 | ffi::GST_MESSAGE_PROPERTY_NOTIFY => PropertyNotify::view_mut(self), |
223 | ffi::GST_MESSAGE_STREAM_COLLECTION => StreamCollection::view_mut(self), |
224 | ffi::GST_MESSAGE_STREAMS_SELECTED => StreamsSelected::view_mut(self), |
225 | #[cfg (feature = "v1_16" )] |
226 | ffi::GST_MESSAGE_DEVICE_CHANGED => DeviceChanged::view_mut(self), |
227 | #[cfg (feature = "v1_18" )] |
228 | ffi::GST_MESSAGE_INSTANT_RATE_REQUEST => InstantRateRequest::view_mut(self), |
229 | _ => MessageViewMut::Other, |
230 | } |
231 | } |
232 | } |
233 | |
234 | #[doc (alias = "get_type" )] |
235 | #[inline ] |
236 | pub fn type_(&self) -> MessageType { |
237 | unsafe { from_glib((*self.as_ptr()).type_) } |
238 | } |
239 | } |
240 | |
241 | impl fmt::Debug for Message { |
242 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
243 | MessageRef::fmt(self, f) |
244 | } |
245 | } |
246 | |
247 | impl fmt::Debug for MessageRef { |
248 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
249 | // Don't retrieve `seqnum` using `MessageRef::get_seqnum` |
250 | // because it would generate a new seqnum if a buggy `Element` |
251 | // emitted a `Message` with an invalid `seqnum`. |
252 | // We want to help the user find out there is something wrong here, |
253 | // so they can investigate the origin. |
254 | let seqnum = unsafe { ffi::gst_message_get_seqnum(self.as_mut_ptr()) }; |
255 | let seqnum = if seqnum != 0 { |
256 | &seqnum as &dyn fmt::Debug |
257 | } else { |
258 | &"INVALID (0)" as &dyn fmt::Debug |
259 | }; |
260 | |
261 | f.debug_struct("Message" ) |
262 | .field("ptr" , &self.as_ptr()) |
263 | .field("type" , &unsafe { |
264 | let type_ = ffi::gst_message_type_get_name((*self.as_ptr()).type_); |
265 | CStr::from_ptr(type_).to_str().unwrap() |
266 | }) |
267 | .field("seqnum" , seqnum) |
268 | .field( |
269 | "src" , |
270 | &self |
271 | .src() |
272 | .map(|s| s.name()) |
273 | .as_ref() |
274 | .map(glib::GString::as_str), |
275 | ) |
276 | .field("structure" , &self.structure()) |
277 | .finish() |
278 | } |
279 | } |
280 | |
281 | #[derive (Debug)] |
282 | #[non_exhaustive ] |
283 | pub enum MessageView<'a> { |
284 | Eos(&'a Eos), |
285 | Error(&'a Error), |
286 | Warning(&'a Warning), |
287 | Info(&'a Info), |
288 | Tag(&'a Tag), |
289 | Buffering(&'a Buffering), |
290 | StateChanged(&'a StateChanged), |
291 | StateDirty(&'a StateDirty), |
292 | StepDone(&'a StepDone), |
293 | ClockProvide(&'a ClockProvide), |
294 | ClockLost(&'a ClockLost), |
295 | NewClock(&'a NewClock), |
296 | StructureChange(&'a StructureChange), |
297 | StreamStatus(&'a StreamStatus), |
298 | Application(&'a Application), |
299 | Element(&'a Element), |
300 | SegmentStart(&'a SegmentStart), |
301 | SegmentDone(&'a SegmentDone), |
302 | DurationChanged(&'a DurationChanged), |
303 | Latency(&'a Latency), |
304 | AsyncStart(&'a AsyncStart), |
305 | AsyncDone(&'a AsyncDone), |
306 | RequestState(&'a RequestState), |
307 | StepStart(&'a StepStart), |
308 | Qos(&'a Qos), |
309 | Progress(&'a Progress), |
310 | Toc(&'a Toc), |
311 | ResetTime(&'a ResetTime), |
312 | StreamStart(&'a StreamStart), |
313 | NeedContext(&'a NeedContext), |
314 | HaveContext(&'a HaveContext), |
315 | DeviceAdded(&'a DeviceAdded), |
316 | DeviceRemoved(&'a DeviceRemoved), |
317 | PropertyNotify(&'a PropertyNotify), |
318 | StreamCollection(&'a StreamCollection), |
319 | StreamsSelected(&'a StreamsSelected), |
320 | Redirect(&'a Redirect), |
321 | #[cfg (feature = "v1_16" )] |
322 | #[cfg_attr (docsrs, doc(cfg(feature = "v1_16" )))] |
323 | DeviceChanged(&'a DeviceChanged), |
324 | #[cfg (feature = "v1_18" )] |
325 | #[cfg_attr (docsrs, doc(cfg(feature = "v1_18" )))] |
326 | InstantRateRequest(&'a InstantRateRequest), |
327 | Other, |
328 | } |
329 | |
330 | #[derive (Debug)] |
331 | #[non_exhaustive ] |
332 | pub enum MessageViewMut<'a> { |
333 | Eos(&'a mut Eos), |
334 | Error(&'a mut Error), |
335 | Warning(&'a mut Warning), |
336 | Info(&'a mut Info), |
337 | Tag(&'a mut Tag), |
338 | Buffering(&'a mut Buffering), |
339 | StateChanged(&'a mut StateChanged), |
340 | StateDirty(&'a mut StateDirty), |
341 | StepDone(&'a mut StepDone), |
342 | ClockProvide(&'a mut ClockProvide), |
343 | ClockLost(&'a mut ClockLost), |
344 | NewClock(&'a mut NewClock), |
345 | StructureChange(&'a mut StructureChange), |
346 | StreamStatus(&'a mut StreamStatus), |
347 | Application(&'a mut Application), |
348 | Element(&'a mut Element), |
349 | SegmentStart(&'a mut SegmentStart), |
350 | SegmentDone(&'a mut SegmentDone), |
351 | DurationChanged(&'a mut DurationChanged), |
352 | Latency(&'a mut Latency), |
353 | AsyncStart(&'a mut AsyncStart), |
354 | AsyncDone(&'a mut AsyncDone), |
355 | RequestState(&'a mut RequestState), |
356 | StepStart(&'a mut StepStart), |
357 | Qos(&'a mut Qos), |
358 | Progress(&'a mut Progress), |
359 | Toc(&'a mut Toc), |
360 | ResetTime(&'a mut ResetTime), |
361 | StreamStart(&'a mut StreamStart), |
362 | NeedContext(&'a mut NeedContext), |
363 | HaveContext(&'a mut HaveContext), |
364 | DeviceAdded(&'a mut DeviceAdded), |
365 | DeviceRemoved(&'a mut DeviceRemoved), |
366 | PropertyNotify(&'a mut PropertyNotify), |
367 | StreamCollection(&'a mut StreamCollection), |
368 | StreamsSelected(&'a mut StreamsSelected), |
369 | Redirect(&'a mut Redirect), |
370 | #[cfg (feature = "v1_16" )] |
371 | #[cfg_attr (docsrs, doc(cfg(feature = "v1_16" )))] |
372 | DeviceChanged(&'a mut DeviceChanged), |
373 | #[cfg (feature = "v1_18" )] |
374 | #[cfg_attr (docsrs, doc(cfg(feature = "v1_18" )))] |
375 | InstantRateRequest(&'a mut InstantRateRequest), |
376 | Other, |
377 | } |
378 | |
379 | macro_rules! declare_concrete_message( |
380 | ($name:ident, $param:ident) => { |
381 | #[repr(transparent)] |
382 | pub struct $name<$param = MessageRef>($param); |
383 | |
384 | impl $name { |
385 | #[inline] |
386 | pub fn message(&self) -> &MessageRef { |
387 | unsafe { &*(self as *const Self as *const MessageRef) } |
388 | } |
389 | |
390 | #[inline] |
391 | pub fn message_mut(&mut self) -> &mut MessageRef { |
392 | unsafe { &mut *(self as *mut Self as *mut MessageRef) } |
393 | } |
394 | |
395 | #[inline] |
396 | unsafe fn view(message: &MessageRef) -> MessageView<'_> { |
397 | let message = &*(message as *const MessageRef as *const Self); |
398 | MessageView::$name(message) |
399 | } |
400 | |
401 | #[inline] |
402 | unsafe fn view_mut(message: &mut MessageRef) -> MessageViewMut<'_> { |
403 | let message = &mut *(message as *mut MessageRef as *mut Self); |
404 | MessageViewMut::$name(message) |
405 | } |
406 | } |
407 | |
408 | impl Deref for $name { |
409 | type Target = MessageRef; |
410 | |
411 | #[inline] |
412 | fn deref(&self) -> &Self::Target { |
413 | unsafe { |
414 | &*(self as *const Self as *const Self::Target) |
415 | } |
416 | } |
417 | } |
418 | |
419 | impl DerefMut for $name { |
420 | #[inline] |
421 | fn deref_mut(&mut self) -> &mut Self::Target { |
422 | self.message_mut() |
423 | } |
424 | } |
425 | |
426 | impl ToOwned for $name { |
427 | type Owned = $name<Message>; |
428 | |
429 | #[inline] |
430 | fn to_owned(&self) -> Self::Owned { |
431 | $name::<Message>(self.copy()) |
432 | } |
433 | } |
434 | |
435 | impl $name<Message> { |
436 | #[inline] |
437 | pub fn get_mut(&mut self) -> Option<&mut $name> { |
438 | self.0.get_mut().map(|message| unsafe { |
439 | &mut *(message as *mut MessageRef as *mut $name) |
440 | }) |
441 | } |
442 | } |
443 | |
444 | impl Deref for $name<Message> { |
445 | type Target = $name; |
446 | |
447 | #[inline] |
448 | fn deref(&self) -> &Self::Target { |
449 | unsafe { &*(self.0.as_ptr() as *const Self::Target) } |
450 | } |
451 | } |
452 | |
453 | impl DerefMut for $name<Message> { |
454 | #[inline] |
455 | fn deref_mut(&mut self) -> &mut Self::Target { |
456 | debug_assert!(self.0.is_writable()); |
457 | unsafe { &mut *(self.0.as_mut_ptr() as *mut Self::Target) } |
458 | } |
459 | } |
460 | |
461 | impl Borrow<$name> for $name<Message> { |
462 | #[inline] |
463 | fn borrow(&self) -> &$name { |
464 | &*self |
465 | } |
466 | } |
467 | |
468 | impl From<$name<Message>> for Message { |
469 | #[inline] |
470 | fn from(concrete: $name<Message>) -> Self { |
471 | skip_assert_initialized!(); |
472 | concrete.0 |
473 | } |
474 | } |
475 | } |
476 | ); |
477 | |
478 | declare_concrete_message!(Eos, T); |
479 | impl Eos { |
480 | #[doc (alias = "gst_message_new_eos" )] |
481 | #[allow (clippy::new_ret_no_self)] |
482 | pub fn new() -> Message { |
483 | skip_assert_initialized!(); |
484 | Self::builder().build() |
485 | } |
486 | |
487 | pub fn builder<'a>() -> EosBuilder<'a> { |
488 | assert_initialized_main_thread!(); |
489 | EosBuilder::new() |
490 | } |
491 | } |
492 | |
493 | impl std::fmt::Debug for Eos { |
494 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
495 | f&mut DebugStruct<'_, '_>.debug_struct("Eos" ) |
496 | .field("structure" , &self.message().structure()) |
497 | .field(name:"source" , &self.src().map(|obj: &Object| (obj, obj.name()))) |
498 | .finish() |
499 | } |
500 | } |
501 | |
502 | impl std::fmt::Debug for Eos<Message> { |
503 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
504 | Eos::<MessageRef>::fmt(self, f) |
505 | } |
506 | } |
507 | |
508 | declare_concrete_message!(Error, T); |
509 | impl Error { |
510 | #[doc (alias = "gst_message_new_error" )] |
511 | #[allow (clippy::new_ret_no_self)] |
512 | pub fn new<T: MessageErrorDomain>(error: T, message: &str) -> Message { |
513 | skip_assert_initialized!(); |
514 | Self::builder(error, message).build() |
515 | } |
516 | |
517 | pub fn builder<T: MessageErrorDomain>(error: T, message: &str) -> ErrorBuilder { |
518 | assert_initialized_main_thread!(); |
519 | ErrorBuilder::new(glib::Error::new(error, message)) |
520 | } |
521 | |
522 | pub fn builder_from_error<'a>(error: glib::Error) -> ErrorBuilder<'a> { |
523 | assert_initialized_main_thread!(); |
524 | |
525 | assert!([ |
526 | crate::CoreError::domain(), |
527 | crate::ResourceError::domain(), |
528 | crate::StreamError::domain(), |
529 | crate::LibraryError::domain(), |
530 | ] |
531 | .contains(&error.domain())); |
532 | ErrorBuilder::new(error) |
533 | } |
534 | |
535 | #[doc (alias = "get_error" )] |
536 | #[doc (alias = "gst_message_parse_error" )] |
537 | pub fn error(&self) -> glib::Error { |
538 | unsafe { |
539 | let mut error = ptr::null_mut(); |
540 | |
541 | ffi::gst_message_parse_error(self.as_mut_ptr(), &mut error, ptr::null_mut()); |
542 | |
543 | from_glib_full(error) |
544 | } |
545 | } |
546 | |
547 | #[doc (alias = "get_debug" )] |
548 | #[doc (alias = "gst_message_parse_error" )] |
549 | pub fn debug(&self) -> Option<glib::GString> { |
550 | unsafe { |
551 | let mut debug = ptr::null_mut(); |
552 | |
553 | ffi::gst_message_parse_error(self.as_mut_ptr(), ptr::null_mut(), &mut debug); |
554 | |
555 | from_glib_full(debug) |
556 | } |
557 | } |
558 | |
559 | #[doc (alias = "get_details" )] |
560 | #[doc (alias = "gst_message_parse_error_details" )] |
561 | pub fn details(&self) -> Option<&StructureRef> { |
562 | unsafe { |
563 | let mut details = ptr::null(); |
564 | |
565 | ffi::gst_message_parse_error_details(self.as_mut_ptr(), &mut details); |
566 | |
567 | if details.is_null() { |
568 | None |
569 | } else { |
570 | Some(StructureRef::from_glib_borrow(details)) |
571 | } |
572 | } |
573 | } |
574 | |
575 | #[cfg (feature = "v1_26" )] |
576 | #[cfg_attr (docsrs, doc(cfg(feature = "v1_26" )))] |
577 | #[doc (alias = "gst_message_parse_error_writable_details" )] |
578 | pub fn writable_details(&mut self) -> &mut StructureRef { |
579 | unsafe { |
580 | let mut details = ptr::null_mut(); |
581 | |
582 | ffi::gst_message_parse_error_writable_details(self.as_mut_ptr(), &mut details); |
583 | |
584 | StructureRef::from_glib_borrow_mut(details) |
585 | } |
586 | } |
587 | } |
588 | |
589 | impl std::fmt::Display for Error { |
590 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
591 | write!(f, " {}" , self.error()) |
592 | } |
593 | } |
594 | |
595 | impl std::fmt::Debug for Error { |
596 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
597 | f&mut DebugStruct<'_, '_>.debug_struct("Error" ) |
598 | .field("structure" , &self.message().structure()) |
599 | .field("source" , &self.src().map(|obj| (obj, obj.name()))) |
600 | .field("error" , &self.error()) |
601 | .field("debug" , &self.debug()) |
602 | .field(name:"details" , &self.details()) |
603 | .finish() |
604 | } |
605 | } |
606 | |
607 | impl std::fmt::Debug for Error<Message> { |
608 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
609 | Error::<MessageRef>::fmt(self, f) |
610 | } |
611 | } |
612 | |
613 | declare_concrete_message!(Warning, T); |
614 | impl Warning { |
615 | #[doc (alias = "gst_message_new_warning" )] |
616 | #[allow (clippy::new_ret_no_self)] |
617 | pub fn new<T: MessageErrorDomain>(error: T, message: &str) -> Message { |
618 | skip_assert_initialized!(); |
619 | Self::builder(error, message).build() |
620 | } |
621 | |
622 | pub fn builder<T: MessageErrorDomain>(error: T, message: &str) -> WarningBuilder { |
623 | assert_initialized_main_thread!(); |
624 | WarningBuilder::new(glib::Error::new(error, message)) |
625 | } |
626 | |
627 | pub fn builder_from_error<'a>(error: glib::Error) -> WarningBuilder<'a> { |
628 | assert_initialized_main_thread!(); |
629 | |
630 | assert!([ |
631 | crate::CoreError::domain(), |
632 | crate::ResourceError::domain(), |
633 | crate::StreamError::domain(), |
634 | crate::LibraryError::domain(), |
635 | ] |
636 | .contains(&error.domain())); |
637 | WarningBuilder::new(error) |
638 | } |
639 | |
640 | #[doc (alias = "get_error" )] |
641 | #[doc (alias = "gst_message_parse_warning" )] |
642 | pub fn error(&self) -> glib::Error { |
643 | unsafe { |
644 | let mut error = ptr::null_mut(); |
645 | |
646 | ffi::gst_message_parse_warning(self.as_mut_ptr(), &mut error, ptr::null_mut()); |
647 | |
648 | from_glib_full(error) |
649 | } |
650 | } |
651 | |
652 | #[doc (alias = "get_debug" )] |
653 | #[doc (alias = "gst_message_parse_warning" )] |
654 | pub fn debug(&self) -> Option<glib::GString> { |
655 | unsafe { |
656 | let mut debug = ptr::null_mut(); |
657 | |
658 | ffi::gst_message_parse_warning(self.as_mut_ptr(), ptr::null_mut(), &mut debug); |
659 | |
660 | from_glib_full(debug) |
661 | } |
662 | } |
663 | |
664 | #[doc (alias = "get_details" )] |
665 | #[doc (alias = "gst_message_parse_warning_details" )] |
666 | pub fn details(&self) -> Option<&StructureRef> { |
667 | unsafe { |
668 | let mut details = ptr::null(); |
669 | |
670 | ffi::gst_message_parse_warning_details(self.as_mut_ptr(), &mut details); |
671 | |
672 | if details.is_null() { |
673 | None |
674 | } else { |
675 | Some(StructureRef::from_glib_borrow(details)) |
676 | } |
677 | } |
678 | } |
679 | |
680 | #[cfg (feature = "v1_26" )] |
681 | #[cfg_attr (docsrs, doc(cfg(feature = "v1_26" )))] |
682 | #[doc (alias = "gst_message_parse_warning_writable_details" )] |
683 | pub fn writable_details(&mut self) -> &mut StructureRef { |
684 | unsafe { |
685 | let mut details = ptr::null_mut(); |
686 | |
687 | ffi::gst_message_parse_warning_writable_details(self.as_mut_ptr(), &mut details); |
688 | |
689 | StructureRef::from_glib_borrow_mut(details) |
690 | } |
691 | } |
692 | } |
693 | |
694 | impl std::fmt::Display for Warning { |
695 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
696 | write!(f, " {}" , self.error()) |
697 | } |
698 | } |
699 | |
700 | impl std::fmt::Debug for Warning { |
701 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
702 | f&mut DebugStruct<'_, '_>.debug_struct("Warning" ) |
703 | .field("structure" , &self.message().structure()) |
704 | .field("source" , &self.src().map(|obj| (obj, obj.name()))) |
705 | .field("error" , &self.error()) |
706 | .field("debug" , &self.debug()) |
707 | .field(name:"details" , &self.details()) |
708 | .finish() |
709 | } |
710 | } |
711 | |
712 | impl std::fmt::Debug for Warning<Message> { |
713 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
714 | Warning::<MessageRef>::fmt(self, f) |
715 | } |
716 | } |
717 | |
718 | declare_concrete_message!(Info, T); |
719 | impl Info { |
720 | #[doc (alias = "gst_message_new_info" )] |
721 | #[allow (clippy::new_ret_no_self)] |
722 | pub fn new<T: MessageErrorDomain>(error: T, message: &str) -> Message { |
723 | skip_assert_initialized!(); |
724 | Self::builder(error, message).build() |
725 | } |
726 | |
727 | pub fn builder<T: MessageErrorDomain>(error: T, message: &str) -> InfoBuilder { |
728 | assert_initialized_main_thread!(); |
729 | InfoBuilder::new(glib::Error::new(error, message)) |
730 | } |
731 | |
732 | pub fn builder_from_error<'a>(error: glib::Error) -> InfoBuilder<'a> { |
733 | assert_initialized_main_thread!(); |
734 | |
735 | assert!([ |
736 | crate::CoreError::domain(), |
737 | crate::ResourceError::domain(), |
738 | crate::StreamError::domain(), |
739 | crate::LibraryError::domain(), |
740 | ] |
741 | .contains(&error.domain())); |
742 | InfoBuilder::new(error) |
743 | } |
744 | |
745 | #[doc (alias = "get_error" )] |
746 | #[doc (alias = "gst_message_parse_info" )] |
747 | pub fn error(&self) -> glib::Error { |
748 | unsafe { |
749 | let mut error = ptr::null_mut(); |
750 | |
751 | ffi::gst_message_parse_info(self.as_mut_ptr(), &mut error, ptr::null_mut()); |
752 | |
753 | from_glib_full(error) |
754 | } |
755 | } |
756 | |
757 | #[doc (alias = "get_debug" )] |
758 | #[doc (alias = "gst_message_parse_info" )] |
759 | pub fn debug(&self) -> Option<glib::GString> { |
760 | unsafe { |
761 | let mut debug = ptr::null_mut(); |
762 | |
763 | ffi::gst_message_parse_info(self.as_mut_ptr(), ptr::null_mut(), &mut debug); |
764 | |
765 | from_glib_full(debug) |
766 | } |
767 | } |
768 | |
769 | #[doc (alias = "get_details" )] |
770 | #[doc (alias = "gst_message_parse_info_details" )] |
771 | pub fn details(&self) -> Option<&StructureRef> { |
772 | unsafe { |
773 | let mut details = ptr::null(); |
774 | |
775 | ffi::gst_message_parse_info_details(self.as_mut_ptr(), &mut details); |
776 | |
777 | if details.is_null() { |
778 | None |
779 | } else { |
780 | Some(StructureRef::from_glib_borrow(details)) |
781 | } |
782 | } |
783 | } |
784 | |
785 | #[cfg (feature = "v1_26" )] |
786 | #[cfg_attr (docsrs, doc(cfg(feature = "v1_26" )))] |
787 | #[doc (alias = "gst_message_parse_info_writable_details" )] |
788 | pub fn writable_details(&mut self) -> &mut StructureRef { |
789 | unsafe { |
790 | let mut details = ptr::null_mut(); |
791 | |
792 | ffi::gst_message_parse_info_writable_details(self.as_mut_ptr(), &mut details); |
793 | |
794 | StructureRef::from_glib_borrow_mut(details) |
795 | } |
796 | } |
797 | } |
798 | |
799 | impl std::fmt::Display for Info { |
800 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
801 | write!(f, " {}" , self.error()) |
802 | } |
803 | } |
804 | |
805 | impl std::fmt::Debug for Info { |
806 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
807 | f&mut DebugStruct<'_, '_>.debug_struct("Info" ) |
808 | .field("structure" , &self.message().structure()) |
809 | .field("source" , &self.src().map(|obj| (obj, obj.name()))) |
810 | .field("error" , &self.error()) |
811 | .field("debug" , &self.debug()) |
812 | .field(name:"details" , &self.details()) |
813 | .finish() |
814 | } |
815 | } |
816 | |
817 | impl std::fmt::Debug for Info<Message> { |
818 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
819 | Info::<MessageRef>::fmt(self, f) |
820 | } |
821 | } |
822 | |
823 | declare_concrete_message!(Tag, T); |
824 | impl Tag { |
825 | #[doc (alias = "gst_message_new_tag" )] |
826 | #[allow (clippy::new_ret_no_self)] |
827 | pub fn new(tags: &TagList) -> Message { |
828 | skip_assert_initialized!(); |
829 | Self::builder(tags).build() |
830 | } |
831 | |
832 | pub fn builder(tags: &TagList) -> TagBuilder { |
833 | assert_initialized_main_thread!(); |
834 | TagBuilder::new(tags) |
835 | } |
836 | |
837 | #[doc (alias = "get_tags" )] |
838 | #[doc (alias = "gst_message_parse_tag" )] |
839 | pub fn tags(&self) -> TagList { |
840 | unsafe { |
841 | let mut tags: *mut GstTagList = ptr::null_mut(); |
842 | ffi::gst_message_parse_tag(self.as_mut_ptr(), &mut tags); |
843 | from_glib_full(ptr:tags) |
844 | } |
845 | } |
846 | } |
847 | |
848 | impl std::fmt::Debug for Tag { |
849 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
850 | f&mut DebugStruct<'_, '_>.debug_struct("Tag" ) |
851 | .field("structure" , &self.message().structure()) |
852 | .field("source" , &self.src().map(|obj| (obj, obj.name()))) |
853 | .field(name:"tags" , &self.tags()) |
854 | .finish() |
855 | } |
856 | } |
857 | |
858 | impl std::fmt::Debug for Tag<Message> { |
859 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
860 | Tag::<MessageRef>::fmt(self, f) |
861 | } |
862 | } |
863 | |
864 | declare_concrete_message!(Buffering, T); |
865 | impl Buffering { |
866 | #[doc (alias = "gst_message_new_buffering" )] |
867 | #[allow (clippy::new_ret_no_self)] |
868 | pub fn new(percent: i32) -> Message { |
869 | skip_assert_initialized!(); |
870 | Self::builder(percent).build() |
871 | } |
872 | |
873 | pub fn builder<'a>(percent: i32) -> BufferingBuilder<'a> { |
874 | assert_initialized_main_thread!(); |
875 | BufferingBuilder::new(percent) |
876 | } |
877 | |
878 | #[doc (alias = "get_percent" )] |
879 | #[doc (alias = "gst_message_parse_buffering" )] |
880 | pub fn percent(&self) -> i32 { |
881 | unsafe { |
882 | let mut p = mem::MaybeUninit::uninit(); |
883 | ffi::gst_message_parse_buffering(self.as_mut_ptr(), p.as_mut_ptr()); |
884 | p.assume_init() |
885 | } |
886 | } |
887 | |
888 | #[doc (alias = "get_buffering_stats" )] |
889 | #[doc (alias = "gst_message_parse_buffering_stats" )] |
890 | pub fn buffering_stats(&self) -> (crate::BufferingMode, i32, i32, i64) { |
891 | unsafe { |
892 | let mut mode = mem::MaybeUninit::uninit(); |
893 | let mut avg_in = mem::MaybeUninit::uninit(); |
894 | let mut avg_out = mem::MaybeUninit::uninit(); |
895 | let mut buffering_left = mem::MaybeUninit::uninit(); |
896 | |
897 | ffi::gst_message_parse_buffering_stats( |
898 | self.as_mut_ptr(), |
899 | mode.as_mut_ptr(), |
900 | avg_in.as_mut_ptr(), |
901 | avg_out.as_mut_ptr(), |
902 | buffering_left.as_mut_ptr(), |
903 | ); |
904 | |
905 | ( |
906 | from_glib(mode.assume_init()), |
907 | avg_in.assume_init(), |
908 | avg_out.assume_init(), |
909 | buffering_left.assume_init(), |
910 | ) |
911 | } |
912 | } |
913 | } |
914 | |
915 | impl std::fmt::Debug for Buffering { |
916 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
917 | f&mut DebugStruct<'_, '_>.debug_struct("Buffering" ) |
918 | .field("structure" , &self.message().structure()) |
919 | .field("source" , &self.src().map(|obj| (obj, obj.name()))) |
920 | .field("percent" , &self.percent()) |
921 | .field(name:"buffering-stats" , &self.buffering_stats()) |
922 | .finish() |
923 | } |
924 | } |
925 | |
926 | impl std::fmt::Debug for Buffering<Message> { |
927 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
928 | Buffering::<MessageRef>::fmt(self, f) |
929 | } |
930 | } |
931 | |
932 | declare_concrete_message!(StateChanged, T); |
933 | impl StateChanged { |
934 | #[doc (alias = "gst_message_new_state_changed" )] |
935 | #[allow (clippy::new_ret_no_self)] |
936 | pub fn new(old: crate::State, new: crate::State, pending: crate::State) -> Message { |
937 | skip_assert_initialized!(); |
938 | Self::builder(old, new, pending).build() |
939 | } |
940 | |
941 | pub fn builder<'a>( |
942 | old: crate::State, |
943 | new: crate::State, |
944 | pending: crate::State, |
945 | ) -> StateChangedBuilder<'a> { |
946 | assert_initialized_main_thread!(); |
947 | StateChangedBuilder::new(old, new, pending) |
948 | } |
949 | |
950 | #[doc (alias = "get_old" )] |
951 | #[doc (alias = "gst_message_parse_state_changed" )] |
952 | pub fn old(&self) -> crate::State { |
953 | unsafe { |
954 | let mut state = mem::MaybeUninit::uninit(); |
955 | |
956 | ffi::gst_message_parse_state_changed( |
957 | self.as_mut_ptr(), |
958 | state.as_mut_ptr(), |
959 | ptr::null_mut(), |
960 | ptr::null_mut(), |
961 | ); |
962 | |
963 | from_glib(state.assume_init()) |
964 | } |
965 | } |
966 | |
967 | #[doc (alias = "get_current" )] |
968 | #[doc (alias = "gst_message_parse_state_changed" )] |
969 | pub fn current(&self) -> crate::State { |
970 | unsafe { |
971 | let mut state = mem::MaybeUninit::uninit(); |
972 | |
973 | ffi::gst_message_parse_state_changed( |
974 | self.as_mut_ptr(), |
975 | ptr::null_mut(), |
976 | state.as_mut_ptr(), |
977 | ptr::null_mut(), |
978 | ); |
979 | |
980 | from_glib(state.assume_init()) |
981 | } |
982 | } |
983 | |
984 | #[doc (alias = "get_pending" )] |
985 | #[doc (alias = "gst_message_parse_state_changed" )] |
986 | pub fn pending(&self) -> crate::State { |
987 | unsafe { |
988 | let mut state = mem::MaybeUninit::uninit(); |
989 | |
990 | ffi::gst_message_parse_state_changed( |
991 | self.as_mut_ptr(), |
992 | ptr::null_mut(), |
993 | ptr::null_mut(), |
994 | state.as_mut_ptr(), |
995 | ); |
996 | |
997 | from_glib(state.assume_init()) |
998 | } |
999 | } |
1000 | } |
1001 | |
1002 | impl std::fmt::Debug for StateChanged { |
1003 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
1004 | f&mut DebugStruct<'_, '_>.debug_struct("StateChanged" ) |
1005 | .field("structure" , &self.message().structure()) |
1006 | .field("source" , &self.src().map(|obj| (obj, obj.name()))) |
1007 | .field("old" , &self.old()) |
1008 | .field("current" , &self.current()) |
1009 | .field(name:"pending" , &self.pending()) |
1010 | .finish() |
1011 | } |
1012 | } |
1013 | |
1014 | impl std::fmt::Debug for StateChanged<Message> { |
1015 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
1016 | StateChanged::<MessageRef>::fmt(self, f) |
1017 | } |
1018 | } |
1019 | |
1020 | declare_concrete_message!(StateDirty, T); |
1021 | impl StateDirty { |
1022 | #[doc (alias = "gst_message_new_state_dirty" )] |
1023 | #[allow (clippy::new_ret_no_self)] |
1024 | pub fn new() -> Message { |
1025 | skip_assert_initialized!(); |
1026 | Self::builder().build() |
1027 | } |
1028 | |
1029 | pub fn builder<'a>() -> StateDirtyBuilder<'a> { |
1030 | assert_initialized_main_thread!(); |
1031 | StateDirtyBuilder::new() |
1032 | } |
1033 | } |
1034 | |
1035 | impl std::fmt::Debug for StateDirty { |
1036 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
1037 | f&mut DebugStruct<'_, '_>.debug_struct("StateDirty" ) |
1038 | .field("structure" , &self.message().structure()) |
1039 | .field(name:"source" , &self.src().map(|obj: &Object| (obj, obj.name()))) |
1040 | .finish() |
1041 | } |
1042 | } |
1043 | |
1044 | impl std::fmt::Debug for StateDirty<Message> { |
1045 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
1046 | StateDirty::<MessageRef>::fmt(self, f) |
1047 | } |
1048 | } |
1049 | |
1050 | declare_concrete_message!(StepDone, T); |
1051 | impl StepDone { |
1052 | #[doc (alias = "gst_message_new_step_done" )] |
1053 | #[allow (clippy::new_ret_no_self)] |
1054 | pub fn new( |
1055 | amount: impl FormattedValue, |
1056 | rate: f64, |
1057 | flush: bool, |
1058 | intermediate: bool, |
1059 | duration: impl Into<Option<crate::ClockTime>>, |
1060 | eos: bool, |
1061 | ) -> Message { |
1062 | skip_assert_initialized!(); |
1063 | Self::builder(amount, rate, flush, intermediate, duration, eos).build() |
1064 | } |
1065 | |
1066 | pub fn builder<'a>( |
1067 | amount: impl FormattedValue, |
1068 | rate: f64, |
1069 | flush: bool, |
1070 | intermediate: bool, |
1071 | duration: impl Into<Option<crate::ClockTime>>, |
1072 | eos: bool, |
1073 | ) -> StepDoneBuilder<'a> { |
1074 | assert_initialized_main_thread!(); |
1075 | StepDoneBuilder::new( |
1076 | amount.into(), |
1077 | rate, |
1078 | flush, |
1079 | intermediate, |
1080 | duration.into(), |
1081 | eos, |
1082 | ) |
1083 | } |
1084 | |
1085 | #[doc (alias = "gst_message_parse_step_done" )] |
1086 | pub fn get( |
1087 | &self, |
1088 | ) -> ( |
1089 | GenericFormattedValue, |
1090 | f64, |
1091 | bool, |
1092 | bool, |
1093 | Option<crate::ClockTime>, |
1094 | bool, |
1095 | ) { |
1096 | unsafe { |
1097 | let mut format = mem::MaybeUninit::uninit(); |
1098 | let mut amount = mem::MaybeUninit::uninit(); |
1099 | let mut rate = mem::MaybeUninit::uninit(); |
1100 | let mut flush = mem::MaybeUninit::uninit(); |
1101 | let mut intermediate = mem::MaybeUninit::uninit(); |
1102 | let mut duration = mem::MaybeUninit::uninit(); |
1103 | let mut eos = mem::MaybeUninit::uninit(); |
1104 | |
1105 | ffi::gst_message_parse_step_done( |
1106 | self.as_mut_ptr(), |
1107 | format.as_mut_ptr(), |
1108 | amount.as_mut_ptr(), |
1109 | rate.as_mut_ptr(), |
1110 | flush.as_mut_ptr(), |
1111 | intermediate.as_mut_ptr(), |
1112 | duration.as_mut_ptr(), |
1113 | eos.as_mut_ptr(), |
1114 | ); |
1115 | |
1116 | ( |
1117 | GenericFormattedValue::new( |
1118 | from_glib(format.assume_init()), |
1119 | amount.assume_init() as i64, |
1120 | ), |
1121 | rate.assume_init(), |
1122 | from_glib(flush.assume_init()), |
1123 | from_glib(intermediate.assume_init()), |
1124 | from_glib(duration.assume_init()), |
1125 | from_glib(eos.assume_init()), |
1126 | ) |
1127 | } |
1128 | } |
1129 | } |
1130 | |
1131 | impl std::fmt::Debug for StepDone { |
1132 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
1133 | let (format: GenericFormattedValue, rate: f64, flush: bool, intermediate: bool, duration: Option, eos: bool) = self.get(); |
1134 | f&mut DebugStruct<'_, '_>.debug_struct("StepDone" ) |
1135 | .field("structure" , &self.message().structure()) |
1136 | .field("source" , &self.src().map(|obj| (obj, obj.name()))) |
1137 | .field("format" , &format) |
1138 | .field("rate" , &rate) |
1139 | .field("flush" , &flush) |
1140 | .field("intermediate" , &intermediate) |
1141 | .field("duration" , &duration) |
1142 | .field(name:"eos" , &eos) |
1143 | .finish() |
1144 | } |
1145 | } |
1146 | |
1147 | impl std::fmt::Debug for StepDone<Message> { |
1148 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
1149 | StepDone::<MessageRef>::fmt(self, f) |
1150 | } |
1151 | } |
1152 | |
1153 | declare_concrete_message!(ClockProvide, T); |
1154 | impl ClockProvide { |
1155 | #[doc (alias = "gst_message_new_clock_provide" )] |
1156 | #[allow (clippy::new_ret_no_self)] |
1157 | pub fn new(clock: &crate::Clock, ready: bool) -> Message { |
1158 | skip_assert_initialized!(); |
1159 | Self::builder(clock, ready).build() |
1160 | } |
1161 | |
1162 | pub fn builder(clock: &crate::Clock, ready: bool) -> ClockProvideBuilder { |
1163 | assert_initialized_main_thread!(); |
1164 | ClockProvideBuilder::new(clock, ready) |
1165 | } |
1166 | |
1167 | #[doc (alias = "get_clock" )] |
1168 | #[doc (alias = "gst_message_parse_clock_provide" )] |
1169 | pub fn clock(&self) -> Option<crate::Clock> { |
1170 | let mut clock = ptr::null_mut(); |
1171 | |
1172 | unsafe { |
1173 | ffi::gst_message_parse_clock_provide(self.as_mut_ptr(), &mut clock, ptr::null_mut()); |
1174 | |
1175 | from_glib_none(clock) |
1176 | } |
1177 | } |
1178 | |
1179 | #[doc (alias = "get_ready" )] |
1180 | #[doc (alias = "gst_message_parse_clock_provide" )] |
1181 | pub fn is_ready(&self) -> bool { |
1182 | unsafe { |
1183 | let mut ready = mem::MaybeUninit::uninit(); |
1184 | |
1185 | ffi::gst_message_parse_clock_provide( |
1186 | self.as_mut_ptr(), |
1187 | ptr::null_mut(), |
1188 | ready.as_mut_ptr(), |
1189 | ); |
1190 | |
1191 | from_glib(ready.assume_init()) |
1192 | } |
1193 | } |
1194 | } |
1195 | |
1196 | impl std::fmt::Debug for ClockProvide { |
1197 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
1198 | f&mut DebugStruct<'_, '_>.debug_struct("ClockProvide" ) |
1199 | .field("structure" , &self.message().structure()) |
1200 | .field("source" , &self.src().map(|obj| (obj, obj.name()))) |
1201 | .field("clock" , &self.clock()) |
1202 | .field(name:"is-ready" , &self.is_ready()) |
1203 | .finish() |
1204 | } |
1205 | } |
1206 | |
1207 | impl std::fmt::Debug for ClockProvide<Message> { |
1208 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
1209 | ClockProvide::<MessageRef>::fmt(self, f) |
1210 | } |
1211 | } |
1212 | |
1213 | declare_concrete_message!(ClockLost, T); |
1214 | impl ClockLost { |
1215 | #[doc (alias = "gst_message_new_clock_lost" )] |
1216 | #[allow (clippy::new_ret_no_self)] |
1217 | pub fn new(clock: &crate::Clock) -> Message { |
1218 | skip_assert_initialized!(); |
1219 | Self::builder(clock).build() |
1220 | } |
1221 | |
1222 | pub fn builder(clock: &crate::Clock) -> ClockLostBuilder { |
1223 | assert_initialized_main_thread!(); |
1224 | ClockLostBuilder::new(clock) |
1225 | } |
1226 | |
1227 | #[doc (alias = "get_clock" )] |
1228 | #[doc (alias = "gst_message_parse_clock_lost" )] |
1229 | pub fn clock(&self) -> Option<crate::Clock> { |
1230 | let mut clock = ptr::null_mut(); |
1231 | |
1232 | unsafe { |
1233 | ffi::gst_message_parse_clock_lost(self.as_mut_ptr(), &mut clock); |
1234 | |
1235 | from_glib_none(clock) |
1236 | } |
1237 | } |
1238 | } |
1239 | |
1240 | impl std::fmt::Debug for ClockLost { |
1241 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
1242 | f&mut DebugStruct<'_, '_>.debug_struct("ClockLost" ) |
1243 | .field("structure" , &self.message().structure()) |
1244 | .field("source" , &self.src().map(|obj| (obj, obj.name()))) |
1245 | .field(name:"clock" , &self.clock()) |
1246 | .finish() |
1247 | } |
1248 | } |
1249 | |
1250 | impl std::fmt::Debug for ClockLost<Message> { |
1251 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
1252 | ClockLost::<MessageRef>::fmt(self, f) |
1253 | } |
1254 | } |
1255 | |
1256 | declare_concrete_message!(NewClock, T); |
1257 | impl NewClock { |
1258 | #[doc (alias = "gst_message_new_new_clock" )] |
1259 | #[allow (clippy::new_ret_no_self)] |
1260 | pub fn new(clock: &crate::Clock) -> Message { |
1261 | skip_assert_initialized!(); |
1262 | Self::builder(clock).build() |
1263 | } |
1264 | |
1265 | pub fn builder(clock: &crate::Clock) -> NewClockBuilder { |
1266 | assert_initialized_main_thread!(); |
1267 | NewClockBuilder::new(clock) |
1268 | } |
1269 | |
1270 | #[doc (alias = "get_clock" )] |
1271 | #[doc (alias = "gst_message_parse_new_clock" )] |
1272 | pub fn clock(&self) -> Option<crate::Clock> { |
1273 | let mut clock = ptr::null_mut(); |
1274 | |
1275 | unsafe { |
1276 | ffi::gst_message_parse_new_clock(self.as_mut_ptr(), &mut clock); |
1277 | |
1278 | from_glib_none(clock) |
1279 | } |
1280 | } |
1281 | } |
1282 | |
1283 | impl std::fmt::Debug for NewClock { |
1284 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
1285 | f&mut DebugStruct<'_, '_>.debug_struct("NewClock" ) |
1286 | .field("structure" , &self.message().structure()) |
1287 | .field("source" , &self.src().map(|obj| (obj, obj.name()))) |
1288 | .field(name:"clock" , &self.clock()) |
1289 | .finish() |
1290 | } |
1291 | } |
1292 | |
1293 | impl std::fmt::Debug for NewClock<Message> { |
1294 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
1295 | NewClock::<MessageRef>::fmt(self, f) |
1296 | } |
1297 | } |
1298 | |
1299 | declare_concrete_message!(StructureChange, T); |
1300 | impl StructureChange { |
1301 | #[doc (alias = "gst_message_new_structure_change" )] |
1302 | #[allow (clippy::new_ret_no_self)] |
1303 | pub fn new(type_: crate::StructureChangeType, owner: &crate::Element, busy: bool) -> Message { |
1304 | skip_assert_initialized!(); |
1305 | Self::builder(type_, owner, busy).build() |
1306 | } |
1307 | |
1308 | pub fn builder( |
1309 | type_: crate::StructureChangeType, |
1310 | owner: &crate::Element, |
1311 | busy: bool, |
1312 | ) -> StructureChangeBuilder { |
1313 | assert_initialized_main_thread!(); |
1314 | StructureChangeBuilder::new(type_, owner, busy) |
1315 | } |
1316 | |
1317 | #[doc (alias = "gst_message_parse_structure_change" )] |
1318 | pub fn get(&self) -> (crate::StructureChangeType, crate::Element, bool) { |
1319 | unsafe { |
1320 | let mut type_ = mem::MaybeUninit::uninit(); |
1321 | let mut owner = ptr::null_mut(); |
1322 | let mut busy = mem::MaybeUninit::uninit(); |
1323 | |
1324 | ffi::gst_message_parse_structure_change( |
1325 | self.as_mut_ptr(), |
1326 | type_.as_mut_ptr(), |
1327 | &mut owner, |
1328 | busy.as_mut_ptr(), |
1329 | ); |
1330 | |
1331 | ( |
1332 | from_glib(type_.assume_init()), |
1333 | from_glib_none(owner), |
1334 | from_glib(busy.assume_init()), |
1335 | ) |
1336 | } |
1337 | } |
1338 | } |
1339 | |
1340 | impl std::fmt::Debug for StructureChange { |
1341 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
1342 | let (type_: StructureChangeType, owner: Element, busy: bool) = self.get(); |
1343 | |
1344 | f&mut DebugStruct<'_, '_>.debug_struct("StructureChange" ) |
1345 | .field("structure" , &self.message().structure()) |
1346 | .field("source" , &self.src().map(|obj| (obj, obj.name()))) |
1347 | .field("type" , &type_) |
1348 | .field("owner" , &owner) |
1349 | .field(name:"busy" , &busy) |
1350 | .finish() |
1351 | } |
1352 | } |
1353 | |
1354 | impl std::fmt::Debug for StructureChange<Message> { |
1355 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
1356 | StructureChange::<MessageRef>::fmt(self, f) |
1357 | } |
1358 | } |
1359 | |
1360 | declare_concrete_message!(StreamStatus, T); |
1361 | impl StreamStatus { |
1362 | #[doc (alias = "gst_message_new_stream_status" )] |
1363 | #[allow (clippy::new_ret_no_self)] |
1364 | pub fn new(type_: crate::StreamStatusType, owner: &crate::Element) -> Message { |
1365 | skip_assert_initialized!(); |
1366 | Self::builder(type_, owner).build() |
1367 | } |
1368 | |
1369 | pub fn builder(type_: crate::StreamStatusType, owner: &crate::Element) -> StreamStatusBuilder { |
1370 | assert_initialized_main_thread!(); |
1371 | StreamStatusBuilder::new(type_, owner) |
1372 | } |
1373 | |
1374 | #[doc (alias = "gst_message_parse_stream_status" )] |
1375 | pub fn get(&self) -> (crate::StreamStatusType, crate::Element) { |
1376 | unsafe { |
1377 | let mut type_ = mem::MaybeUninit::uninit(); |
1378 | let mut owner = ptr::null_mut(); |
1379 | |
1380 | ffi::gst_message_parse_stream_status(self.as_mut_ptr(), type_.as_mut_ptr(), &mut owner); |
1381 | |
1382 | (from_glib(type_.assume_init()), from_glib_none(owner)) |
1383 | } |
1384 | } |
1385 | |
1386 | #[doc (alias = "get_stream_status_object" )] |
1387 | #[doc (alias = "gst_message_get_stream_status_object" )] |
1388 | pub fn stream_status_object(&self) -> Option<glib::Value> { |
1389 | unsafe { |
1390 | let value = ffi::gst_message_get_stream_status_object(self.as_mut_ptr()); |
1391 | |
1392 | from_glib_none(value) |
1393 | } |
1394 | } |
1395 | } |
1396 | |
1397 | impl std::fmt::Debug for StreamStatus { |
1398 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
1399 | f&mut DebugStruct<'_, '_>.debug_struct("StreamStatus" ) |
1400 | .field("structure" , &self.message().structure()) |
1401 | .field("source" , &self.src().map(|obj| (obj, obj.name()))) |
1402 | .field(name:"status" , &self.stream_status_object()) |
1403 | .finish() |
1404 | } |
1405 | } |
1406 | |
1407 | impl std::fmt::Debug for StreamStatus<Message> { |
1408 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
1409 | StreamStatus::<MessageRef>::fmt(self, f) |
1410 | } |
1411 | } |
1412 | |
1413 | declare_concrete_message!(Application, T); |
1414 | impl Application { |
1415 | #[doc (alias = "gst_message_new_application" )] |
1416 | #[allow (clippy::new_ret_no_self)] |
1417 | pub fn new(structure: crate::Structure) -> Message { |
1418 | skip_assert_initialized!(); |
1419 | Self::builder(structure).build() |
1420 | } |
1421 | |
1422 | pub fn builder<'a>(structure: crate::Structure) -> ApplicationBuilder<'a> { |
1423 | assert_initialized_main_thread!(); |
1424 | ApplicationBuilder::new(structure) |
1425 | } |
1426 | } |
1427 | |
1428 | impl std::fmt::Debug for Application { |
1429 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
1430 | f&mut DebugStruct<'_, '_>.debug_struct("Application" ) |
1431 | .field("structure" , &self.message().structure()) |
1432 | .field(name:"source" , &self.src().map(|obj: &Object| (obj, obj.name()))) |
1433 | .finish() |
1434 | } |
1435 | } |
1436 | |
1437 | impl std::fmt::Debug for Application<Message> { |
1438 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
1439 | Application::<MessageRef>::fmt(self, f) |
1440 | } |
1441 | } |
1442 | |
1443 | declare_concrete_message!(Element, T); |
1444 | impl Element { |
1445 | #[doc (alias = "gst_message_new_element" )] |
1446 | #[allow (clippy::new_ret_no_self)] |
1447 | pub fn new(structure: crate::Structure) -> Message { |
1448 | skip_assert_initialized!(); |
1449 | Self::builder(structure).build() |
1450 | } |
1451 | |
1452 | pub fn builder<'a>(structure: crate::Structure) -> ElementBuilder<'a> { |
1453 | assert_initialized_main_thread!(); |
1454 | ElementBuilder::new(structure) |
1455 | } |
1456 | } |
1457 | |
1458 | impl std::fmt::Debug for Element { |
1459 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
1460 | f&mut DebugStruct<'_, '_>.debug_struct("Element" ) |
1461 | .field("structure" , &self.message().structure()) |
1462 | .field(name:"source" , &self.src().map(|obj: &Object| (obj, obj.name()))) |
1463 | .finish() |
1464 | } |
1465 | } |
1466 | |
1467 | impl std::fmt::Debug for Element<Message> { |
1468 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
1469 | Element::<MessageRef>::fmt(self, f) |
1470 | } |
1471 | } |
1472 | |
1473 | declare_concrete_message!(SegmentStart, T); |
1474 | impl SegmentStart { |
1475 | #[doc (alias = "gst_message_new_segment_start" )] |
1476 | #[allow (clippy::new_ret_no_self)] |
1477 | pub fn new(position: impl FormattedValue) -> Message { |
1478 | skip_assert_initialized!(); |
1479 | Self::builder(position).build() |
1480 | } |
1481 | |
1482 | pub fn builder<'a>(position: impl FormattedValue) -> SegmentStartBuilder<'a> { |
1483 | assert_initialized_main_thread!(); |
1484 | SegmentStartBuilder::new(position.into()) |
1485 | } |
1486 | |
1487 | #[doc (alias = "gst_message_parse_segment_start" )] |
1488 | pub fn get(&self) -> GenericFormattedValue { |
1489 | unsafe { |
1490 | let mut format = mem::MaybeUninit::uninit(); |
1491 | let mut position = mem::MaybeUninit::uninit(); |
1492 | |
1493 | ffi::gst_message_parse_segment_start( |
1494 | self.as_mut_ptr(), |
1495 | format.as_mut_ptr(), |
1496 | position.as_mut_ptr(), |
1497 | ); |
1498 | |
1499 | GenericFormattedValue::new(from_glib(format.assume_init()), position.assume_init()) |
1500 | } |
1501 | } |
1502 | } |
1503 | |
1504 | impl std::fmt::Debug for SegmentStart { |
1505 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
1506 | f&mut DebugStruct<'_, '_>.debug_struct("SegmentStart" ) |
1507 | .field("structure" , &self.message().structure()) |
1508 | .field("source" , &self.src().map(|obj| (obj, obj.name()))) |
1509 | .field(name:"segment" , &self.get()) |
1510 | .finish() |
1511 | } |
1512 | } |
1513 | |
1514 | impl std::fmt::Debug for SegmentStart<Message> { |
1515 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
1516 | SegmentStart::<MessageRef>::fmt(self, f) |
1517 | } |
1518 | } |
1519 | |
1520 | declare_concrete_message!(SegmentDone, T); |
1521 | impl SegmentDone { |
1522 | #[doc (alias = "gst_message_new_segment_done" )] |
1523 | #[allow (clippy::new_ret_no_self)] |
1524 | pub fn new(position: impl FormattedValue) -> Message { |
1525 | skip_assert_initialized!(); |
1526 | Self::builder(position).build() |
1527 | } |
1528 | |
1529 | pub fn builder<'a>(position: impl FormattedValue) -> SegmentDoneBuilder<'a> { |
1530 | assert_initialized_main_thread!(); |
1531 | SegmentDoneBuilder::new(position.into()) |
1532 | } |
1533 | |
1534 | #[doc (alias = "gst_message_parse_segment_done" )] |
1535 | pub fn get(&self) -> GenericFormattedValue { |
1536 | unsafe { |
1537 | let mut format = mem::MaybeUninit::uninit(); |
1538 | let mut position = mem::MaybeUninit::uninit(); |
1539 | |
1540 | ffi::gst_message_parse_segment_done( |
1541 | self.as_mut_ptr(), |
1542 | format.as_mut_ptr(), |
1543 | position.as_mut_ptr(), |
1544 | ); |
1545 | |
1546 | GenericFormattedValue::new(from_glib(format.assume_init()), position.assume_init()) |
1547 | } |
1548 | } |
1549 | } |
1550 | |
1551 | impl std::fmt::Debug for SegmentDone { |
1552 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
1553 | f&mut DebugStruct<'_, '_>.debug_struct("SegmentDone" ) |
1554 | .field("structure" , &self.message().structure()) |
1555 | .field("source" , &self.src().map(|obj| (obj, obj.name()))) |
1556 | .field(name:"segment" , &self.get()) |
1557 | .finish() |
1558 | } |
1559 | } |
1560 | |
1561 | impl std::fmt::Debug for SegmentDone<Message> { |
1562 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
1563 | SegmentDone::<MessageRef>::fmt(self, f) |
1564 | } |
1565 | } |
1566 | |
1567 | declare_concrete_message!(DurationChanged, T); |
1568 | impl DurationChanged { |
1569 | #[doc (alias = "gst_message_new_duration_changed" )] |
1570 | #[allow (clippy::new_ret_no_self)] |
1571 | pub fn new() -> Message { |
1572 | skip_assert_initialized!(); |
1573 | Self::builder().build() |
1574 | } |
1575 | |
1576 | pub fn builder<'a>() -> DurationChangedBuilder<'a> { |
1577 | assert_initialized_main_thread!(); |
1578 | DurationChangedBuilder::new() |
1579 | } |
1580 | } |
1581 | |
1582 | impl std::fmt::Debug for DurationChanged { |
1583 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
1584 | f&mut DebugStruct<'_, '_>.debug_struct("DurationChanged" ) |
1585 | .field("structure" , &self.message().structure()) |
1586 | .field(name:"source" , &self.src().map(|obj: &Object| (obj, obj.name()))) |
1587 | .finish() |
1588 | } |
1589 | } |
1590 | |
1591 | impl std::fmt::Debug for DurationChanged<Message> { |
1592 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
1593 | DurationChanged::<MessageRef>::fmt(self, f) |
1594 | } |
1595 | } |
1596 | |
1597 | declare_concrete_message!(Latency, T); |
1598 | impl Latency { |
1599 | #[doc (alias = "gst_message_new_latency" )] |
1600 | #[allow (clippy::new_ret_no_self)] |
1601 | pub fn new() -> Message { |
1602 | skip_assert_initialized!(); |
1603 | Self::builder().build() |
1604 | } |
1605 | |
1606 | pub fn builder<'a>() -> LatencyBuilder<'a> { |
1607 | assert_initialized_main_thread!(); |
1608 | LatencyBuilder::new() |
1609 | } |
1610 | } |
1611 | |
1612 | impl std::fmt::Debug for Latency { |
1613 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
1614 | f&mut DebugStruct<'_, '_>.debug_struct("Latency" ) |
1615 | .field("structure" , &self.message().structure()) |
1616 | .field(name:"source" , &self.src().map(|obj: &Object| (obj, obj.name()))) |
1617 | .finish() |
1618 | } |
1619 | } |
1620 | |
1621 | impl std::fmt::Debug for Latency<Message> { |
1622 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
1623 | Latency::<MessageRef>::fmt(self, f) |
1624 | } |
1625 | } |
1626 | |
1627 | declare_concrete_message!(AsyncStart, T); |
1628 | impl AsyncStart { |
1629 | #[doc (alias = "gst_message_new_async_start" )] |
1630 | #[allow (clippy::new_ret_no_self)] |
1631 | pub fn new() -> Message { |
1632 | skip_assert_initialized!(); |
1633 | Self::builder().build() |
1634 | } |
1635 | |
1636 | pub fn builder<'a>() -> AsyncStartBuilder<'a> { |
1637 | assert_initialized_main_thread!(); |
1638 | AsyncStartBuilder::new() |
1639 | } |
1640 | } |
1641 | |
1642 | impl std::fmt::Debug for AsyncStart { |
1643 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
1644 | f&mut DebugStruct<'_, '_>.debug_struct("AsyncStart" ) |
1645 | .field("structure" , &self.message().structure()) |
1646 | .field(name:"source" , &self.src().map(|obj: &Object| (obj, obj.name()))) |
1647 | .finish() |
1648 | } |
1649 | } |
1650 | |
1651 | impl std::fmt::Debug for AsyncStart<Message> { |
1652 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
1653 | AsyncStart::<MessageRef>::fmt(self, f) |
1654 | } |
1655 | } |
1656 | |
1657 | declare_concrete_message!(AsyncDone, T); |
1658 | impl AsyncDone { |
1659 | #[doc (alias = "gst_message_new_async_done" )] |
1660 | #[allow (clippy::new_ret_no_self)] |
1661 | pub fn new(running_time: impl Into<Option<crate::ClockTime>>) -> Message { |
1662 | skip_assert_initialized!(); |
1663 | Self::builder().running_time(running_time).build() |
1664 | } |
1665 | |
1666 | pub fn builder<'a>() -> AsyncDoneBuilder<'a> { |
1667 | assert_initialized_main_thread!(); |
1668 | AsyncDoneBuilder::new() |
1669 | } |
1670 | |
1671 | #[doc (alias = "get_running_time" )] |
1672 | #[doc (alias = "gst_message_parse_async_done" )] |
1673 | pub fn running_time(&self) -> Option<crate::ClockTime> { |
1674 | unsafe { |
1675 | let mut running_time = mem::MaybeUninit::uninit(); |
1676 | |
1677 | ffi::gst_message_parse_async_done(self.as_mut_ptr(), running_time.as_mut_ptr()); |
1678 | |
1679 | from_glib(running_time.assume_init()) |
1680 | } |
1681 | } |
1682 | } |
1683 | |
1684 | impl std::fmt::Debug for AsyncDone { |
1685 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
1686 | f&mut DebugStruct<'_, '_>.debug_struct("AsyncDone" ) |
1687 | .field("structure" , &self.message().structure()) |
1688 | .field("source" , &self.src().map(|obj| (obj, obj.name()))) |
1689 | .field(name:"running-time" , &self.running_time()) |
1690 | .finish() |
1691 | } |
1692 | } |
1693 | |
1694 | impl std::fmt::Debug for AsyncDone<Message> { |
1695 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
1696 | AsyncDone::<MessageRef>::fmt(self, f) |
1697 | } |
1698 | } |
1699 | |
1700 | declare_concrete_message!(RequestState, T); |
1701 | impl RequestState { |
1702 | #[doc (alias = "gst_message_new_request_state" )] |
1703 | #[allow (clippy::new_ret_no_self)] |
1704 | pub fn new(state: crate::State) -> Message { |
1705 | skip_assert_initialized!(); |
1706 | Self::builder(state).build() |
1707 | } |
1708 | |
1709 | pub fn builder<'a>(state: crate::State) -> RequestStateBuilder<'a> { |
1710 | assert_initialized_main_thread!(); |
1711 | RequestStateBuilder::new(state) |
1712 | } |
1713 | |
1714 | #[doc (alias = "get_requested_state" )] |
1715 | #[doc (alias = "gst_message_parse_request_state" )] |
1716 | pub fn requested_state(&self) -> crate::State { |
1717 | unsafe { |
1718 | let mut state = mem::MaybeUninit::uninit(); |
1719 | |
1720 | ffi::gst_message_parse_request_state(self.as_mut_ptr(), state.as_mut_ptr()); |
1721 | |
1722 | from_glib(state.assume_init()) |
1723 | } |
1724 | } |
1725 | } |
1726 | |
1727 | impl std::fmt::Debug for RequestState { |
1728 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
1729 | f&mut DebugStruct<'_, '_>.debug_struct("RequestState" ) |
1730 | .field("structure" , &self.message().structure()) |
1731 | .field("source" , &self.src().map(|obj| (obj, obj.name()))) |
1732 | .field(name:"requested-state" , &self.requested_state()) |
1733 | .finish() |
1734 | } |
1735 | } |
1736 | |
1737 | impl std::fmt::Debug for RequestState<Message> { |
1738 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
1739 | RequestState::<MessageRef>::fmt(self, f) |
1740 | } |
1741 | } |
1742 | |
1743 | declare_concrete_message!(StepStart, T); |
1744 | impl StepStart { |
1745 | #[doc (alias = "gst_message_new_step_start" )] |
1746 | #[allow (clippy::new_ret_no_self)] |
1747 | pub fn new( |
1748 | active: bool, |
1749 | amount: impl FormattedValue, |
1750 | rate: f64, |
1751 | flush: bool, |
1752 | intermediate: bool, |
1753 | ) -> Message { |
1754 | skip_assert_initialized!(); |
1755 | Self::builder(active, amount, rate, flush, intermediate).build() |
1756 | } |
1757 | |
1758 | pub fn builder<'a>( |
1759 | active: bool, |
1760 | amount: impl FormattedValue, |
1761 | rate: f64, |
1762 | flush: bool, |
1763 | intermediate: bool, |
1764 | ) -> StepStartBuilder<'a> { |
1765 | assert_initialized_main_thread!(); |
1766 | StepStartBuilder::new(active, amount.into(), rate, flush, intermediate) |
1767 | } |
1768 | |
1769 | #[doc (alias = "gst_message_parse_step_start" )] |
1770 | pub fn get(&self) -> (bool, GenericFormattedValue, f64, bool, bool) { |
1771 | unsafe { |
1772 | let mut active = mem::MaybeUninit::uninit(); |
1773 | let mut format = mem::MaybeUninit::uninit(); |
1774 | let mut amount = mem::MaybeUninit::uninit(); |
1775 | let mut rate = mem::MaybeUninit::uninit(); |
1776 | let mut flush = mem::MaybeUninit::uninit(); |
1777 | let mut intermediate = mem::MaybeUninit::uninit(); |
1778 | |
1779 | ffi::gst_message_parse_step_start( |
1780 | self.as_mut_ptr(), |
1781 | active.as_mut_ptr(), |
1782 | format.as_mut_ptr(), |
1783 | amount.as_mut_ptr(), |
1784 | rate.as_mut_ptr(), |
1785 | flush.as_mut_ptr(), |
1786 | intermediate.as_mut_ptr(), |
1787 | ); |
1788 | |
1789 | ( |
1790 | from_glib(active.assume_init()), |
1791 | GenericFormattedValue::new( |
1792 | from_glib(format.assume_init()), |
1793 | amount.assume_init() as i64, |
1794 | ), |
1795 | rate.assume_init(), |
1796 | from_glib(flush.assume_init()), |
1797 | from_glib(intermediate.assume_init()), |
1798 | ) |
1799 | } |
1800 | } |
1801 | } |
1802 | |
1803 | impl std::fmt::Debug for StepStart { |
1804 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
1805 | let (active: bool, amount: GenericFormattedValue, rate: f64, flush: bool, intermediate: bool) = self.get(); |
1806 | f&mut DebugStruct<'_, '_>.debug_struct("StepStart" ) |
1807 | .field("structure" , &self.message().structure()) |
1808 | .field("source" , &self.src().map(|obj| (obj, obj.name()))) |
1809 | .field("active" , &active) |
1810 | .field("amount" , &amount) |
1811 | .field("rate" , &rate) |
1812 | .field("flush" , &flush) |
1813 | .field(name:"intermediate" , &intermediate) |
1814 | .finish() |
1815 | } |
1816 | } |
1817 | |
1818 | impl std::fmt::Debug for StepStart<Message> { |
1819 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
1820 | StepStart::<MessageRef>::fmt(self, f) |
1821 | } |
1822 | } |
1823 | |
1824 | declare_concrete_message!(Qos, T); |
1825 | impl Qos { |
1826 | #[doc (alias = "gst_message_new_qos" )] |
1827 | #[allow (clippy::new_ret_no_self)] |
1828 | pub fn new( |
1829 | live: bool, |
1830 | running_time: impl Into<Option<crate::ClockTime>>, |
1831 | stream_time: impl Into<Option<crate::ClockTime>>, |
1832 | timestamp: impl Into<Option<crate::ClockTime>>, |
1833 | duration: impl Into<Option<crate::ClockTime>>, |
1834 | ) -> Message { |
1835 | skip_assert_initialized!(); |
1836 | Self::builder(live) |
1837 | .running_time(running_time) |
1838 | .stream_time(stream_time) |
1839 | .timestamp(timestamp) |
1840 | .duration(duration) |
1841 | .build() |
1842 | } |
1843 | |
1844 | pub fn builder<'a>(live: bool) -> QosBuilder<'a> { |
1845 | assert_initialized_main_thread!(); |
1846 | QosBuilder::new(live) |
1847 | } |
1848 | |
1849 | #[doc (alias = "gst_message_parse_qos" )] |
1850 | pub fn get( |
1851 | &self, |
1852 | ) -> ( |
1853 | bool, |
1854 | Option<crate::ClockTime>, |
1855 | Option<crate::ClockTime>, |
1856 | Option<crate::ClockTime>, |
1857 | Option<crate::ClockTime>, |
1858 | ) { |
1859 | unsafe { |
1860 | let mut live = mem::MaybeUninit::uninit(); |
1861 | let mut running_time = mem::MaybeUninit::uninit(); |
1862 | let mut stream_time = mem::MaybeUninit::uninit(); |
1863 | let mut timestamp = mem::MaybeUninit::uninit(); |
1864 | let mut duration = mem::MaybeUninit::uninit(); |
1865 | |
1866 | ffi::gst_message_parse_qos( |
1867 | self.as_mut_ptr(), |
1868 | live.as_mut_ptr(), |
1869 | running_time.as_mut_ptr(), |
1870 | stream_time.as_mut_ptr(), |
1871 | timestamp.as_mut_ptr(), |
1872 | duration.as_mut_ptr(), |
1873 | ); |
1874 | |
1875 | ( |
1876 | from_glib(live.assume_init()), |
1877 | from_glib(running_time.assume_init()), |
1878 | from_glib(stream_time.assume_init()), |
1879 | from_glib(timestamp.assume_init()), |
1880 | from_glib(duration.assume_init()), |
1881 | ) |
1882 | } |
1883 | } |
1884 | |
1885 | #[doc (alias = "get_values" )] |
1886 | #[doc (alias = "gst_message_parse_qos_values" )] |
1887 | pub fn values(&self) -> (i64, f64, i32) { |
1888 | unsafe { |
1889 | let mut jitter = mem::MaybeUninit::uninit(); |
1890 | let mut proportion = mem::MaybeUninit::uninit(); |
1891 | let mut quality = mem::MaybeUninit::uninit(); |
1892 | |
1893 | ffi::gst_message_parse_qos_values( |
1894 | self.as_mut_ptr(), |
1895 | jitter.as_mut_ptr(), |
1896 | proportion.as_mut_ptr(), |
1897 | quality.as_mut_ptr(), |
1898 | ); |
1899 | |
1900 | ( |
1901 | jitter.assume_init(), |
1902 | proportion.assume_init(), |
1903 | quality.assume_init(), |
1904 | ) |
1905 | } |
1906 | } |
1907 | |
1908 | #[doc (alias = "get_stats" )] |
1909 | #[doc (alias = "gst_message_parse_qos_stats" )] |
1910 | pub fn stats(&self) -> (GenericFormattedValue, GenericFormattedValue) { |
1911 | unsafe { |
1912 | let mut format = mem::MaybeUninit::uninit(); |
1913 | let mut processed = mem::MaybeUninit::uninit(); |
1914 | let mut dropped = mem::MaybeUninit::uninit(); |
1915 | |
1916 | ffi::gst_message_parse_qos_stats( |
1917 | self.as_mut_ptr(), |
1918 | format.as_mut_ptr(), |
1919 | processed.as_mut_ptr(), |
1920 | dropped.as_mut_ptr(), |
1921 | ); |
1922 | |
1923 | ( |
1924 | GenericFormattedValue::new( |
1925 | from_glib(format.assume_init()), |
1926 | processed.assume_init() as i64, |
1927 | ), |
1928 | GenericFormattedValue::new( |
1929 | from_glib(format.assume_init()), |
1930 | dropped.assume_init() as i64, |
1931 | ), |
1932 | ) |
1933 | } |
1934 | } |
1935 | } |
1936 | |
1937 | impl std::fmt::Debug for Qos { |
1938 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
1939 | let (live: bool, running_time: Option, stream_time: Option, timestamp: Option, duration: Option) = self.get(); |
1940 | let (jitter: i64, proportion: f64, quality: i32) = self.values(); |
1941 | let (processed: GenericFormattedValue, dropped: GenericFormattedValue) = self.stats(); |
1942 | |
1943 | f&mut DebugStruct<'_, '_>.debug_struct("Qos" ) |
1944 | .field("structure" , &self.message().structure()) |
1945 | .field("source" , &self.src().map(|obj| (obj, obj.name()))) |
1946 | .field("live" , &live) |
1947 | .field("running-time" , &running_time) |
1948 | .field("stream-time" , &stream_time) |
1949 | .field("timestamp" , ×tamp) |
1950 | .field("duration" , &duration) |
1951 | .field("jitter" , &jitter) |
1952 | .field("proportion" , &proportion) |
1953 | .field("quality" , &quality) |
1954 | .field("processed" , &processed) |
1955 | .field(name:"dropped" , &dropped) |
1956 | .finish() |
1957 | } |
1958 | } |
1959 | |
1960 | impl std::fmt::Debug for Qos<Message> { |
1961 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
1962 | Qos::<MessageRef>::fmt(self, f) |
1963 | } |
1964 | } |
1965 | |
1966 | declare_concrete_message!(Progress, T); |
1967 | impl Progress { |
1968 | #[doc (alias = "gst_message_new_progress" )] |
1969 | #[allow (clippy::new_ret_no_self)] |
1970 | pub fn new(type_: crate::ProgressType, code: &str, text: &str) -> Message { |
1971 | skip_assert_initialized!(); |
1972 | Self::builder(type_, code, text).build() |
1973 | } |
1974 | |
1975 | pub fn builder<'a>( |
1976 | type_: crate::ProgressType, |
1977 | code: &'a str, |
1978 | text: &'a str, |
1979 | ) -> ProgressBuilder<'a> { |
1980 | assert_initialized_main_thread!(); |
1981 | ProgressBuilder::new(type_, code, text) |
1982 | } |
1983 | |
1984 | #[doc (alias = "gst_message_parse_progress" )] |
1985 | pub fn get(&self) -> (crate::ProgressType, &str, &str) { |
1986 | unsafe { |
1987 | let mut type_ = mem::MaybeUninit::uninit(); |
1988 | let mut code = ptr::null_mut(); |
1989 | let mut text = ptr::null_mut(); |
1990 | |
1991 | ffi::gst_message_parse_progress( |
1992 | self.as_mut_ptr(), |
1993 | type_.as_mut_ptr(), |
1994 | &mut code, |
1995 | &mut text, |
1996 | ); |
1997 | |
1998 | let code = CStr::from_ptr(code).to_str().unwrap(); |
1999 | let text = CStr::from_ptr(text).to_str().unwrap(); |
2000 | |
2001 | (from_glib(type_.assume_init()), code, text) |
2002 | } |
2003 | } |
2004 | } |
2005 | |
2006 | impl std::fmt::Debug for Progress { |
2007 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
2008 | let (type_: ProgressType, code: &str, text: &str) = self.get(); |
2009 | f&mut DebugStruct<'_, '_>.debug_struct("Progress" ) |
2010 | .field("structure" , &self.message().structure()) |
2011 | .field("source" , &self.src().map(|obj| (obj, obj.name()))) |
2012 | .field("type" , &type_) |
2013 | .field("code" , &code) |
2014 | .field(name:"text" , &text) |
2015 | .finish() |
2016 | } |
2017 | } |
2018 | |
2019 | impl std::fmt::Debug for Progress<Message> { |
2020 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
2021 | Progress::<MessageRef>::fmt(self, f) |
2022 | } |
2023 | } |
2024 | |
2025 | declare_concrete_message!(Toc, T); |
2026 | impl Toc { |
2027 | // FIXME could use false for updated as default |
2028 | // Even better: use an enum for updated so that it is more explicit than true / false |
2029 | #[doc (alias = "gst_message_new_toc" )] |
2030 | #[allow (clippy::new_ret_no_self)] |
2031 | pub fn new(toc: &crate::Toc, updated: bool) -> Message { |
2032 | skip_assert_initialized!(); |
2033 | Self::builder(toc, updated).build() |
2034 | } |
2035 | |
2036 | pub fn builder(toc: &crate::Toc, updated: bool) -> TocBuilder { |
2037 | assert_initialized_main_thread!(); |
2038 | TocBuilder::new(toc, updated) |
2039 | } |
2040 | |
2041 | #[doc (alias = "get_toc" )] |
2042 | #[doc (alias = "gst_message_parse_toc" )] |
2043 | pub fn toc(&self) -> (crate::Toc, bool) { |
2044 | unsafe { |
2045 | let mut toc = ptr::null_mut(); |
2046 | let mut updated = mem::MaybeUninit::uninit(); |
2047 | ffi::gst_message_parse_toc(self.as_mut_ptr(), &mut toc, updated.as_mut_ptr()); |
2048 | (from_glib_full(toc), from_glib(updated.assume_init())) |
2049 | } |
2050 | } |
2051 | } |
2052 | |
2053 | impl std::fmt::Debug for Toc { |
2054 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
2055 | f&mut DebugStruct<'_, '_>.debug_struct("Toc" ) |
2056 | .field("structure" , &self.message().structure()) |
2057 | .field("source" , &self.src().map(|obj| (obj, obj.name()))) |
2058 | .field(name:"toc" , &self.toc()) |
2059 | .finish() |
2060 | } |
2061 | } |
2062 | |
2063 | impl std::fmt::Debug for Toc<Message> { |
2064 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
2065 | Toc::<MessageRef>::fmt(self, f) |
2066 | } |
2067 | } |
2068 | |
2069 | declare_concrete_message!(ResetTime, T); |
2070 | impl ResetTime { |
2071 | #[doc (alias = "gst_message_new_reset_time" )] |
2072 | #[allow (clippy::new_ret_no_self)] |
2073 | pub fn new(running_time: crate::ClockTime) -> Message { |
2074 | skip_assert_initialized!(); |
2075 | Self::builder(running_time).build() |
2076 | } |
2077 | |
2078 | pub fn builder<'a>(running_time: crate::ClockTime) -> ResetTimeBuilder<'a> { |
2079 | assert_initialized_main_thread!(); |
2080 | ResetTimeBuilder::new(running_time) |
2081 | } |
2082 | |
2083 | #[doc (alias = "get_running_time" )] |
2084 | #[doc (alias = "gst_message_parse_reset_time" )] |
2085 | pub fn running_time(&self) -> crate::ClockTime { |
2086 | unsafe { |
2087 | let mut running_time = mem::MaybeUninit::uninit(); |
2088 | |
2089 | ffi::gst_message_parse_reset_time(self.as_mut_ptr(), running_time.as_mut_ptr()); |
2090 | |
2091 | try_from_glib(running_time.assume_init()).expect("undefined running_time" ) |
2092 | } |
2093 | } |
2094 | } |
2095 | |
2096 | impl std::fmt::Debug for ResetTime { |
2097 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
2098 | f&mut DebugStruct<'_, '_>.debug_struct("ResetTime" ) |
2099 | .field("structure" , &self.message().structure()) |
2100 | .field("source" , &self.src().map(|obj| (obj, obj.name()))) |
2101 | .field(name:"running-time" , &self.running_time()) |
2102 | .finish() |
2103 | } |
2104 | } |
2105 | |
2106 | impl std::fmt::Debug for ResetTime<Message> { |
2107 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
2108 | ResetTime::<MessageRef>::fmt(self, f) |
2109 | } |
2110 | } |
2111 | |
2112 | declare_concrete_message!(StreamStart, T); |
2113 | impl StreamStart { |
2114 | #[doc (alias = "gst_message_new_stream_start" )] |
2115 | #[allow (clippy::new_ret_no_self)] |
2116 | pub fn new() -> Message { |
2117 | skip_assert_initialized!(); |
2118 | Self::builder().build() |
2119 | } |
2120 | |
2121 | pub fn builder<'a>() -> StreamStartBuilder<'a> { |
2122 | assert_initialized_main_thread!(); |
2123 | StreamStartBuilder::new() |
2124 | } |
2125 | |
2126 | #[doc (alias = "get_group_id" )] |
2127 | #[doc (alias = "gst_message_parse_group_id" )] |
2128 | pub fn group_id(&self) -> Option<GroupId> { |
2129 | unsafe { |
2130 | let mut group_id = mem::MaybeUninit::uninit(); |
2131 | |
2132 | if from_glib(ffi::gst_message_parse_group_id( |
2133 | self.as_mut_ptr(), |
2134 | group_id.as_mut_ptr(), |
2135 | )) { |
2136 | let group_id = group_id.assume_init(); |
2137 | if group_id == 0 { |
2138 | None |
2139 | } else { |
2140 | Some(GroupId(NonZeroU32::new_unchecked(group_id))) |
2141 | } |
2142 | } else { |
2143 | None |
2144 | } |
2145 | } |
2146 | } |
2147 | |
2148 | #[doc (alias = "gst_message_set_group_id" )] |
2149 | pub fn set_group_id(&mut self, group_id: GroupId) { |
2150 | unsafe { |
2151 | ffi::gst_message_set_group_id(self.as_mut_ptr(), group_id.0.get()); |
2152 | } |
2153 | } |
2154 | } |
2155 | |
2156 | impl std::fmt::Debug for StreamStart { |
2157 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
2158 | f&mut DebugStruct<'_, '_>.debug_struct("StreamStart" ) |
2159 | .field("structure" , &self.message().structure()) |
2160 | .field("source" , &self.src().map(|obj| (obj, obj.name()))) |
2161 | .field(name:"group-id" , &self.group_id()) |
2162 | .finish() |
2163 | } |
2164 | } |
2165 | |
2166 | impl std::fmt::Debug for StreamStart<Message> { |
2167 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
2168 | StreamStart::<MessageRef>::fmt(self, f) |
2169 | } |
2170 | } |
2171 | |
2172 | declare_concrete_message!(NeedContext, T); |
2173 | impl NeedContext { |
2174 | #[doc (alias = "gst_message_new_need_context" )] |
2175 | #[allow (clippy::new_ret_no_self)] |
2176 | pub fn new(context_type: &str) -> Message { |
2177 | skip_assert_initialized!(); |
2178 | Self::builder(context_type).build() |
2179 | } |
2180 | |
2181 | pub fn builder(context_type: &str) -> NeedContextBuilder { |
2182 | assert_initialized_main_thread!(); |
2183 | NeedContextBuilder::new(context_type) |
2184 | } |
2185 | |
2186 | #[doc (alias = "get_context_type" )] |
2187 | #[doc (alias = "gst_message_parse_context_type" )] |
2188 | pub fn context_type(&self) -> &str { |
2189 | unsafe { |
2190 | let mut context_type = ptr::null(); |
2191 | |
2192 | ffi::gst_message_parse_context_type(self.as_mut_ptr(), &mut context_type); |
2193 | |
2194 | CStr::from_ptr(context_type).to_str().unwrap() |
2195 | } |
2196 | } |
2197 | } |
2198 | |
2199 | impl std::fmt::Debug for NeedContext { |
2200 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
2201 | f&mut DebugStruct<'_, '_>.debug_struct("NeedContext" ) |
2202 | .field("structure" , &self.message().structure()) |
2203 | .field("source" , &self.src().map(|obj| (obj, obj.name()))) |
2204 | .field(name:"context-type" , &self.context_type()) |
2205 | .finish() |
2206 | } |
2207 | } |
2208 | |
2209 | impl std::fmt::Debug for NeedContext<Message> { |
2210 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
2211 | NeedContext::<MessageRef>::fmt(self, f) |
2212 | } |
2213 | } |
2214 | |
2215 | declare_concrete_message!(HaveContext, T); |
2216 | impl HaveContext { |
2217 | #[doc (alias = "gst_message_new_have_context" )] |
2218 | #[allow (clippy::new_ret_no_self)] |
2219 | pub fn new(context: crate::Context) -> Message { |
2220 | skip_assert_initialized!(); |
2221 | Self::builder(context).build() |
2222 | } |
2223 | |
2224 | pub fn builder<'a>(context: crate::Context) -> HaveContextBuilder<'a> { |
2225 | assert_initialized_main_thread!(); |
2226 | HaveContextBuilder::new(context) |
2227 | } |
2228 | |
2229 | #[doc (alias = "get_context" )] |
2230 | #[doc (alias = "gst_message_parse_have_context" )] |
2231 | pub fn context(&self) -> crate::Context { |
2232 | unsafe { |
2233 | let mut context: *mut GstContext = ptr::null_mut(); |
2234 | ffi::gst_message_parse_have_context(self.as_mut_ptr(), &mut context); |
2235 | from_glib_full(ptr:context) |
2236 | } |
2237 | } |
2238 | } |
2239 | |
2240 | impl std::fmt::Debug for HaveContext { |
2241 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
2242 | f&mut DebugStruct<'_, '_>.debug_struct("HaveContext" ) |
2243 | .field("structure" , &self.message().structure()) |
2244 | .field("source" , &self.src().map(|obj| (obj, obj.name()))) |
2245 | .field(name:"context" , &self.context()) |
2246 | .finish() |
2247 | } |
2248 | } |
2249 | |
2250 | impl std::fmt::Debug for HaveContext<Message> { |
2251 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
2252 | HaveContext::<MessageRef>::fmt(self, f) |
2253 | } |
2254 | } |
2255 | |
2256 | declare_concrete_message!(DeviceAdded, T); |
2257 | impl DeviceAdded { |
2258 | #[doc (alias = "gst_message_new_device_added" )] |
2259 | #[allow (clippy::new_ret_no_self)] |
2260 | pub fn new(device: &crate::Device) -> Message { |
2261 | skip_assert_initialized!(); |
2262 | Self::builder(device).build() |
2263 | } |
2264 | |
2265 | pub fn builder(device: &crate::Device) -> DeviceAddedBuilder { |
2266 | assert_initialized_main_thread!(); |
2267 | DeviceAddedBuilder::new(device) |
2268 | } |
2269 | |
2270 | #[doc (alias = "get_device" )] |
2271 | #[doc (alias = "gst_message_parse_device_added" )] |
2272 | pub fn device(&self) -> crate::Device { |
2273 | unsafe { |
2274 | let mut device = ptr::null_mut(); |
2275 | |
2276 | ffi::gst_message_parse_device_added(self.as_mut_ptr(), &mut device); |
2277 | |
2278 | from_glib_full(device) |
2279 | } |
2280 | } |
2281 | } |
2282 | |
2283 | impl std::fmt::Debug for DeviceAdded { |
2284 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
2285 | f&mut DebugStruct<'_, '_>.debug_struct("DeviceAdded" ) |
2286 | .field("structure" , &self.message().structure()) |
2287 | .field("source" , &self.src().map(|obj| (obj, obj.name()))) |
2288 | .field(name:"device" , &self.device()) |
2289 | .finish() |
2290 | } |
2291 | } |
2292 | |
2293 | impl std::fmt::Debug for DeviceAdded<Message> { |
2294 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
2295 | DeviceAdded::<MessageRef>::fmt(self, f) |
2296 | } |
2297 | } |
2298 | |
2299 | declare_concrete_message!(DeviceRemoved, T); |
2300 | impl DeviceRemoved { |
2301 | #[doc (alias = "gst_message_new_device_removed" )] |
2302 | #[allow (clippy::new_ret_no_self)] |
2303 | pub fn new(device: &crate::Device) -> Message { |
2304 | skip_assert_initialized!(); |
2305 | Self::builder(device).build() |
2306 | } |
2307 | |
2308 | pub fn builder(device: &crate::Device) -> DeviceRemovedBuilder { |
2309 | assert_initialized_main_thread!(); |
2310 | DeviceRemovedBuilder::new(device) |
2311 | } |
2312 | |
2313 | #[doc (alias = "get_device" )] |
2314 | #[doc (alias = "gst_message_parse_device_removed" )] |
2315 | pub fn device(&self) -> crate::Device { |
2316 | unsafe { |
2317 | let mut device = ptr::null_mut(); |
2318 | |
2319 | ffi::gst_message_parse_device_removed(self.as_mut_ptr(), &mut device); |
2320 | |
2321 | from_glib_full(device) |
2322 | } |
2323 | } |
2324 | } |
2325 | |
2326 | impl std::fmt::Debug for DeviceRemoved { |
2327 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
2328 | f&mut DebugStruct<'_, '_>.debug_struct("DeviceRemoved" ) |
2329 | .field("structure" , &self.message().structure()) |
2330 | .field("source" , &self.src().map(|obj| (obj, obj.name()))) |
2331 | .field(name:"device" , &self.device()) |
2332 | .finish() |
2333 | } |
2334 | } |
2335 | |
2336 | impl std::fmt::Debug for DeviceRemoved<Message> { |
2337 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
2338 | DeviceRemoved::<MessageRef>::fmt(self, f) |
2339 | } |
2340 | } |
2341 | |
2342 | declare_concrete_message!(PropertyNotify, T); |
2343 | impl PropertyNotify { |
2344 | #[doc (alias = "gst_message_new_property_notify" )] |
2345 | #[allow (clippy::new_ret_no_self)] |
2346 | pub fn new(object: &impl IsA<crate::Object>, property_name: &str) -> Message { |
2347 | skip_assert_initialized!(); |
2348 | Self::builder(object, property_name).build() |
2349 | } |
2350 | |
2351 | pub fn builder<'a>( |
2352 | object: &'a impl IsA<crate::Object>, |
2353 | property_name: &'a str, |
2354 | ) -> PropertyNotifyBuilder<'a> { |
2355 | assert_initialized_main_thread!(); |
2356 | PropertyNotifyBuilder::new(property_name).src(object) |
2357 | } |
2358 | |
2359 | #[doc (alias = "gst_message_parse_property_notify" )] |
2360 | pub fn get(&self) -> (Object, &str, Option<&glib::Value>) { |
2361 | unsafe { |
2362 | let mut object = ptr::null_mut(); |
2363 | let mut property_name = ptr::null(); |
2364 | let mut value = ptr::null(); |
2365 | |
2366 | ffi::gst_message_parse_property_notify( |
2367 | self.as_mut_ptr(), |
2368 | &mut object, |
2369 | &mut property_name, |
2370 | &mut value, |
2371 | ); |
2372 | |
2373 | ( |
2374 | from_glib_none(object), |
2375 | CStr::from_ptr(property_name).to_str().unwrap(), |
2376 | if value.is_null() { |
2377 | None |
2378 | } else { |
2379 | Some(&*(value as *const glib::Value)) |
2380 | }, |
2381 | ) |
2382 | } |
2383 | } |
2384 | } |
2385 | |
2386 | impl std::fmt::Debug for PropertyNotify { |
2387 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
2388 | let (object: Object, property_name: &str, value: Option<&Value>) = self.get(); |
2389 | f&mut DebugStruct<'_, '_>.debug_struct("PropertyNotify" ) |
2390 | .field("structure" , &self.message().structure()) |
2391 | .field("source" , &self.src().map(|obj| (obj, obj.name()))) |
2392 | .field("object" , &object) |
2393 | .field("property-name" , &property_name) |
2394 | .field(name:"value" , &value) |
2395 | .finish() |
2396 | } |
2397 | } |
2398 | |
2399 | impl std::fmt::Debug for PropertyNotify<Message> { |
2400 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
2401 | PropertyNotify::<MessageRef>::fmt(self, f) |
2402 | } |
2403 | } |
2404 | |
2405 | declare_concrete_message!(StreamCollection, T); |
2406 | impl StreamCollection { |
2407 | #[doc (alias = "gst_message_new_stream_collection" )] |
2408 | #[allow (clippy::new_ret_no_self)] |
2409 | pub fn new(collection: &crate::StreamCollection) -> Message { |
2410 | skip_assert_initialized!(); |
2411 | Self::builder(collection).build() |
2412 | } |
2413 | |
2414 | pub fn builder(collection: &crate::StreamCollection) -> StreamCollectionBuilder { |
2415 | assert_initialized_main_thread!(); |
2416 | StreamCollectionBuilder::new(collection) |
2417 | } |
2418 | |
2419 | #[doc (alias = "get_stream_collection" )] |
2420 | #[doc (alias = "gst_message_parse_stream_collection" )] |
2421 | pub fn stream_collection(&self) -> crate::StreamCollection { |
2422 | unsafe { |
2423 | let mut collection = ptr::null_mut(); |
2424 | |
2425 | ffi::gst_message_parse_stream_collection(self.as_mut_ptr(), &mut collection); |
2426 | |
2427 | from_glib_full(collection) |
2428 | } |
2429 | } |
2430 | } |
2431 | |
2432 | impl std::fmt::Debug for StreamCollection { |
2433 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
2434 | f&mut DebugStruct<'_, '_>.debug_struct("StreamCollection" ) |
2435 | .field("structure" , &self.message().structure()) |
2436 | .field("source" , &self.src().map(|obj| (obj, obj.name()))) |
2437 | .field(name:"stream-collection" , &self.stream_collection()) |
2438 | .finish() |
2439 | } |
2440 | } |
2441 | |
2442 | impl std::fmt::Debug for StreamCollection<Message> { |
2443 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
2444 | StreamCollection::<MessageRef>::fmt(self, f) |
2445 | } |
2446 | } |
2447 | |
2448 | declare_concrete_message!(StreamsSelected, T); |
2449 | impl StreamsSelected { |
2450 | #[doc (alias = "gst_message_new_streams_selected" )] |
2451 | #[allow (clippy::new_ret_no_self)] |
2452 | pub fn new(collection: &crate::StreamCollection) -> Message { |
2453 | skip_assert_initialized!(); |
2454 | Self::builder(collection).build() |
2455 | } |
2456 | |
2457 | pub fn builder(collection: &crate::StreamCollection) -> StreamsSelectedBuilder { |
2458 | assert_initialized_main_thread!(); |
2459 | StreamsSelectedBuilder::new(collection) |
2460 | } |
2461 | |
2462 | #[doc (alias = "get_stream_collection" )] |
2463 | #[doc (alias = "gst_message_parse_streams_selected" )] |
2464 | pub fn stream_collection(&self) -> crate::StreamCollection { |
2465 | unsafe { |
2466 | let mut collection = ptr::null_mut(); |
2467 | |
2468 | ffi::gst_message_parse_streams_selected(self.as_mut_ptr(), &mut collection); |
2469 | |
2470 | from_glib_full(collection) |
2471 | } |
2472 | } |
2473 | |
2474 | #[doc (alias = "get_streams" )] |
2475 | #[doc (alias = "gst_message_streams_selected_get_size" )] |
2476 | #[doc (alias = "gst_message_streams_selected_get_stream" )] |
2477 | pub fn streams(&self) -> Vec<crate::Stream> { |
2478 | unsafe { |
2479 | let n = ffi::gst_message_streams_selected_get_size(self.as_mut_ptr()); |
2480 | |
2481 | (0..n) |
2482 | .map(|i| { |
2483 | from_glib_full(ffi::gst_message_streams_selected_get_stream( |
2484 | self.as_mut_ptr(), |
2485 | i, |
2486 | )) |
2487 | }) |
2488 | .collect() |
2489 | } |
2490 | } |
2491 | } |
2492 | |
2493 | impl std::fmt::Debug for StreamsSelected { |
2494 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
2495 | f&mut DebugStruct<'_, '_>.debug_struct("StreamsSelected" ) |
2496 | .field("structure" , &self.message().structure()) |
2497 | .field("source" , &self.src().map(|obj| (obj, obj.name()))) |
2498 | .field("stream-collection" , &self.stream_collection()) |
2499 | .field(name:"streams" , &self.streams()) |
2500 | .finish() |
2501 | } |
2502 | } |
2503 | |
2504 | impl std::fmt::Debug for StreamsSelected<Message> { |
2505 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
2506 | StreamsSelected::<MessageRef>::fmt(self, f) |
2507 | } |
2508 | } |
2509 | |
2510 | declare_concrete_message!(Redirect, T); |
2511 | impl Redirect { |
2512 | #[doc (alias = "gst_message_new_redirect" )] |
2513 | #[allow (clippy::new_ret_no_self)] |
2514 | pub fn new(location: &str) -> Message { |
2515 | skip_assert_initialized!(); |
2516 | Self::builder(location).build() |
2517 | } |
2518 | |
2519 | pub fn builder(location: &str) -> RedirectBuilder { |
2520 | assert_initialized_main_thread!(); |
2521 | RedirectBuilder::new(location) |
2522 | } |
2523 | |
2524 | #[doc (alias = "get_entries" )] |
2525 | #[doc (alias = "gst_message_get_num_redirect_entries" )] |
2526 | #[doc (alias = "gst_message_parse_redirect_entry" )] |
2527 | pub fn entries(&self) -> Vec<(&str, Option<TagList>, Option<&StructureRef>)> { |
2528 | unsafe { |
2529 | let n = ffi::gst_message_get_num_redirect_entries(self.as_mut_ptr()); |
2530 | |
2531 | (0..n) |
2532 | .map(|i| { |
2533 | let mut location = ptr::null(); |
2534 | let mut tags = ptr::null_mut(); |
2535 | let mut structure = ptr::null(); |
2536 | |
2537 | ffi::gst_message_parse_redirect_entry( |
2538 | self.as_mut_ptr(), |
2539 | i, |
2540 | &mut location, |
2541 | &mut tags, |
2542 | &mut structure, |
2543 | ); |
2544 | |
2545 | let structure = if structure.is_null() { |
2546 | None |
2547 | } else { |
2548 | Some(StructureRef::from_glib_borrow(structure)) |
2549 | }; |
2550 | |
2551 | ( |
2552 | CStr::from_ptr(location).to_str().unwrap(), |
2553 | from_glib_none(tags), |
2554 | structure, |
2555 | ) |
2556 | }) |
2557 | .collect() |
2558 | } |
2559 | } |
2560 | } |
2561 | |
2562 | impl std::fmt::Debug for Redirect { |
2563 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
2564 | f&mut DebugStruct<'_, '_>.debug_struct("Redirect" ) |
2565 | .field("structure" , &self.message().structure()) |
2566 | .field("source" , &self.src().map(|obj| (obj, obj.name()))) |
2567 | .field(name:"entries" , &self.entries()) |
2568 | .finish() |
2569 | } |
2570 | } |
2571 | |
2572 | impl std::fmt::Debug for Redirect<Message> { |
2573 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
2574 | Redirect::<MessageRef>::fmt(self, f) |
2575 | } |
2576 | } |
2577 | |
2578 | #[cfg (feature = "v1_16" )] |
2579 | #[cfg_attr (docsrs, doc(cfg(feature = "v1_16" )))] |
2580 | declare_concrete_message!(DeviceChanged, T); |
2581 | #[cfg (feature = "v1_16" )] |
2582 | #[cfg_attr (docsrs, doc(cfg(feature = "v1_16" )))] |
2583 | impl DeviceChanged { |
2584 | #[doc (alias = "gst_message_new_device_changed" )] |
2585 | #[allow (clippy::new_ret_no_self)] |
2586 | pub fn new(device: &crate::Device, changed_device: &crate::Device) -> Message { |
2587 | skip_assert_initialized!(); |
2588 | Self::builder(device, changed_device).build() |
2589 | } |
2590 | |
2591 | pub fn builder<'a>( |
2592 | device: &'a crate::Device, |
2593 | changed_device: &'a crate::Device, |
2594 | ) -> DeviceChangedBuilder<'a> { |
2595 | assert_initialized_main_thread!(); |
2596 | DeviceChangedBuilder::new(device, changed_device) |
2597 | } |
2598 | |
2599 | #[doc (alias = "get_device_changed" )] |
2600 | #[doc (alias = "gst_message_parse_device_changed" )] |
2601 | pub fn device_changed(&self) -> (crate::Device, crate::Device) { |
2602 | unsafe { |
2603 | let mut device = ptr::null_mut(); |
2604 | let mut changed_device = ptr::null_mut(); |
2605 | |
2606 | ffi::gst_message_parse_device_changed( |
2607 | self.as_mut_ptr(), |
2608 | &mut device, |
2609 | &mut changed_device, |
2610 | ); |
2611 | |
2612 | (from_glib_full(device), from_glib_full(changed_device)) |
2613 | } |
2614 | } |
2615 | } |
2616 | |
2617 | #[cfg (feature = "v1_16" )] |
2618 | impl std::fmt::Debug for DeviceChanged { |
2619 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
2620 | f.debug_struct("DeviceChanged" ) |
2621 | .field("structure" , &self.message().structure()) |
2622 | .field("source" , &self.src().map(|obj| (obj, obj.name()))) |
2623 | .field("device-changed" , &self.device_changed()) |
2624 | .finish() |
2625 | } |
2626 | } |
2627 | |
2628 | #[cfg (feature = "v1_16" )] |
2629 | impl std::fmt::Debug for DeviceChanged<Message> { |
2630 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
2631 | DeviceChanged::<MessageRef>::fmt(self, f) |
2632 | } |
2633 | } |
2634 | |
2635 | #[cfg (feature = "v1_18" )] |
2636 | #[cfg_attr (docsrs, doc(cfg(feature = "v1_18" )))] |
2637 | declare_concrete_message!(InstantRateRequest, T); |
2638 | #[cfg (feature = "v1_18" )] |
2639 | #[cfg_attr (docsrs, doc(cfg(feature = "v1_18" )))] |
2640 | impl InstantRateRequest { |
2641 | #[doc (alias = "gst_message_new_instant_rate_request" )] |
2642 | #[allow (clippy::new_ret_no_self)] |
2643 | pub fn new(rate_multiplier: f64) -> Message { |
2644 | skip_assert_initialized!(); |
2645 | Self::builder(rate_multiplier).build() |
2646 | } |
2647 | |
2648 | pub fn builder<'a>(rate_multiplier: f64) -> InstantRateRequestBuilder<'a> { |
2649 | assert_initialized_main_thread!(); |
2650 | InstantRateRequestBuilder::new(rate_multiplier) |
2651 | } |
2652 | |
2653 | #[doc (alias = "parse_instant_rate_request" )] |
2654 | #[doc (alias = "gst_message_parse_instant_rate_request" )] |
2655 | pub fn rate_multiplier(&self) -> f64 { |
2656 | unsafe { |
2657 | let mut rate_multiplier = mem::MaybeUninit::uninit(); |
2658 | |
2659 | ffi::gst_message_parse_instant_rate_request( |
2660 | self.as_mut_ptr(), |
2661 | rate_multiplier.as_mut_ptr(), |
2662 | ); |
2663 | |
2664 | rate_multiplier.assume_init() |
2665 | } |
2666 | } |
2667 | } |
2668 | |
2669 | #[cfg (feature = "v1_18" )] |
2670 | impl std::fmt::Debug for InstantRateRequest { |
2671 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
2672 | f.debug_struct("InstantRateRequest" ) |
2673 | .field("structure" , &self.message().structure()) |
2674 | .field("source" , &self.src().map(|obj| (obj, obj.name()))) |
2675 | .field("rate-multiplier" , &self.rate_multiplier()) |
2676 | .finish() |
2677 | } |
2678 | } |
2679 | |
2680 | #[cfg (feature = "v1_18" )] |
2681 | impl std::fmt::Debug for InstantRateRequest<Message> { |
2682 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
2683 | InstantRateRequest::<MessageRef>::fmt(self, f) |
2684 | } |
2685 | } |
2686 | |
2687 | struct MessageBuilder<'a> { |
2688 | src: Option<Object>, |
2689 | seqnum: Option<Seqnum>, |
2690 | #[cfg (feature = "v1_26" )] |
2691 | details: Option<Structure>, |
2692 | other_fields: Vec<(&'a str, glib::SendValue)>, |
2693 | } |
2694 | |
2695 | impl<'a> MessageBuilder<'a> { |
2696 | fn new() -> Self { |
2697 | Self { |
2698 | src: None, |
2699 | seqnum: None, |
2700 | #[cfg (feature = "v1_26" )] |
2701 | details: None, |
2702 | other_fields: Vec::new(), |
2703 | } |
2704 | } |
2705 | |
2706 | pub fn src<O: IsA<Object> + Cast + Clone>(self, src: &O) -> Self { |
2707 | Self { |
2708 | src: Some(src.clone().upcast::<Object>()), |
2709 | ..self |
2710 | } |
2711 | } |
2712 | |
2713 | fn seqnum(self, seqnum: Seqnum) -> Self { |
2714 | Self { |
2715 | seqnum: Some(seqnum), |
2716 | ..self |
2717 | } |
2718 | } |
2719 | |
2720 | #[cfg (feature = "v1_26" )] |
2721 | fn details(self, details: Structure) -> Self { |
2722 | Self { |
2723 | details: Some(details), |
2724 | ..self |
2725 | } |
2726 | } |
2727 | |
2728 | fn other_field(self, name: &'a str, value: impl ToSendValue) -> Self { |
2729 | let mut other_fields = self.other_fields; |
2730 | other_fields.push((name, value.to_send_value())); |
2731 | |
2732 | Self { |
2733 | other_fields, |
2734 | ..self |
2735 | } |
2736 | } |
2737 | |
2738 | fn other_fields(self, other_fields: &[(&'a str, &'a (dyn ToSendValue + Sync))]) -> Self { |
2739 | let mut s = self; |
2740 | |
2741 | for (name, value) in other_fields { |
2742 | s = s.other_field(name, value.to_send_value()); |
2743 | } |
2744 | |
2745 | s |
2746 | } |
2747 | } |
2748 | |
2749 | macro_rules! message_builder_generic_impl { |
2750 | ($new_fn:expr) => { |
2751 | #[allow(clippy::needless_update)] |
2752 | pub fn src<O: IsA<Object> + Cast + Clone>(self, src: &O) -> Self { |
2753 | Self { |
2754 | builder: self.builder.src(src), |
2755 | ..self |
2756 | } |
2757 | } |
2758 | |
2759 | #[allow(clippy::needless_update)] |
2760 | pub fn src_if<O: IsA<Object> + Cast + Clone>(self, src: &O, predicate: bool) -> Self { |
2761 | if predicate { |
2762 | self.src(src) |
2763 | } else { |
2764 | self |
2765 | } |
2766 | } |
2767 | |
2768 | #[allow(clippy::needless_update)] |
2769 | pub fn src_if_some<O: IsA<Object> + Cast + Clone>(self, src: Option<&O>) -> Self { |
2770 | if let Some(src) = src { |
2771 | self.src(src) |
2772 | } else { |
2773 | self |
2774 | } |
2775 | } |
2776 | |
2777 | #[doc(alias = "gst_message_set_seqnum" )] |
2778 | #[allow(clippy::needless_update)] |
2779 | pub fn seqnum(self, seqnum: Seqnum) -> Self { |
2780 | Self { |
2781 | builder: self.builder.seqnum(seqnum), |
2782 | ..self |
2783 | } |
2784 | } |
2785 | |
2786 | #[doc(alias = "gst_message_set_seqnum" )] |
2787 | #[allow(clippy::needless_update)] |
2788 | pub fn seqnum_if(self, seqnum: Seqnum, predicate: bool) -> Self { |
2789 | if predicate { |
2790 | self.seqnum(seqnum) |
2791 | } else { |
2792 | self |
2793 | } |
2794 | } |
2795 | |
2796 | #[doc(alias = "gst_message_set_seqnum" )] |
2797 | #[allow(clippy::needless_update)] |
2798 | pub fn seqnum_if_some(self, seqnum: Option<Seqnum>) -> Self { |
2799 | if let Some(seqnum) = seqnum { |
2800 | self.seqnum(seqnum) |
2801 | } else { |
2802 | self |
2803 | } |
2804 | } |
2805 | |
2806 | #[cfg(feature = "v1_26" )] |
2807 | #[cfg_attr(docsrs, doc(cfg(feature = "v1_26" )))] |
2808 | #[doc(alias = "gst_message_set_details" )] |
2809 | #[allow(clippy::needless_update)] |
2810 | pub fn details(self, details: Structure) -> Self { |
2811 | Self { |
2812 | builder: self.builder.details(details), |
2813 | ..self |
2814 | } |
2815 | } |
2816 | |
2817 | #[cfg(feature = "v1_26" )] |
2818 | #[cfg_attr(docsrs, doc(cfg(feature = "v1_26" )))] |
2819 | #[doc(alias = "gst_message_set_details" )] |
2820 | #[allow(clippy::needless_update)] |
2821 | pub fn details_if(self, details: Structure, predicate: bool) -> Self { |
2822 | if predicate { |
2823 | self.details(details) |
2824 | } else { |
2825 | self |
2826 | } |
2827 | } |
2828 | |
2829 | #[cfg(feature = "v1_26" )] |
2830 | #[cfg_attr(docsrs, doc(cfg(feature = "v1_26" )))] |
2831 | #[doc(alias = "gst_message_set_details" )] |
2832 | #[allow(clippy::needless_update)] |
2833 | pub fn details_if_some(self, details: Option<Structure>) -> Self { |
2834 | if let Some(details) = details { |
2835 | self.details(details) |
2836 | } else { |
2837 | self |
2838 | } |
2839 | } |
2840 | |
2841 | // rustdoc-stripper-ignore-next |
2842 | /// Sets field `name` to the given value `value`. |
2843 | /// |
2844 | /// Overrides any default or previously defined value for `name`. |
2845 | #[allow(clippy::needless_update)] |
2846 | pub fn other_field(self, name: &'a str, value: impl ToSendValue) -> Self { |
2847 | Self { |
2848 | builder: self.builder.other_field(name, value), |
2849 | ..self |
2850 | } |
2851 | } |
2852 | |
2853 | impl_builder_gvalue_extra_setters!(other_field); |
2854 | |
2855 | #[deprecated = "use build.other_field() instead" ] |
2856 | #[allow(clippy::needless_update)] |
2857 | pub fn other_fields( |
2858 | self, |
2859 | other_fields: &[(&'a str, &'a (dyn ToSendValue + Sync))], |
2860 | ) -> Self { |
2861 | Self { |
2862 | builder: self.builder.other_fields(other_fields), |
2863 | ..self |
2864 | } |
2865 | } |
2866 | |
2867 | #[must_use = "Building the message without using it has no effect" ] |
2868 | #[allow(clippy::redundant_closure_call)] |
2869 | pub fn build(mut self) -> Message { |
2870 | unsafe { |
2871 | let src = self.builder.src.to_glib_none().0; |
2872 | let msg = $new_fn(&mut self, src); |
2873 | if let Some(seqnum) = self.builder.seqnum { |
2874 | ffi::gst_message_set_seqnum(msg, seqnum.0.get()); |
2875 | } |
2876 | |
2877 | #[cfg(feature = "v1_26" )] |
2878 | if let Some(details) = self.builder.details { |
2879 | ffi::gst_message_set_details(msg, details.into_glib_ptr()); |
2880 | } |
2881 | |
2882 | if !self.builder.other_fields.is_empty() { |
2883 | let structure = ffi::gst_message_writable_structure(msg); |
2884 | |
2885 | if !structure.is_null() { |
2886 | let structure = StructureRef::from_glib_borrow_mut(structure as *mut _); |
2887 | |
2888 | for (k, v) in self.builder.other_fields { |
2889 | structure.set_value(k, v); |
2890 | } |
2891 | } |
2892 | } |
2893 | |
2894 | from_glib_full(msg) |
2895 | } |
2896 | } |
2897 | }; |
2898 | } |
2899 | |
2900 | #[must_use = "The builder must be built to be used" ] |
2901 | pub struct EosBuilder<'a> { |
2902 | builder: MessageBuilder<'a>, |
2903 | } |
2904 | |
2905 | impl<'a> EosBuilder<'a> { |
2906 | fn new() -> Self { |
2907 | skip_assert_initialized!(); |
2908 | Self { |
2909 | builder: MessageBuilder::new(), |
2910 | } |
2911 | } |
2912 | |
2913 | message_builder_generic_impl!(|_, src| ffi::gst_message_new_eos(src)); |
2914 | } |
2915 | |
2916 | pub trait MessageErrorDomain: glib::error::ErrorDomain {} |
2917 | |
2918 | impl MessageErrorDomain for crate::CoreError {} |
2919 | impl MessageErrorDomain for crate::ResourceError {} |
2920 | impl MessageErrorDomain for crate::StreamError {} |
2921 | impl MessageErrorDomain for crate::LibraryError {} |
2922 | |
2923 | #[must_use = "The builder must be built to be used" ] |
2924 | pub struct ErrorBuilder<'a> { |
2925 | builder: MessageBuilder<'a>, |
2926 | error: glib::Error, |
2927 | debug: Option<&'a str>, |
2928 | #[allow (unused)] |
2929 | details: Option<Structure>, |
2930 | } |
2931 | |
2932 | impl<'a> ErrorBuilder<'a> { |
2933 | fn new(error: glib::Error) -> Self { |
2934 | skip_assert_initialized!(); |
2935 | Self { |
2936 | builder: MessageBuilder::new(), |
2937 | error, |
2938 | debug: None, |
2939 | details: None, |
2940 | } |
2941 | } |
2942 | |
2943 | pub fn debug(self, debug: &'a str) -> Self { |
2944 | Self { |
2945 | debug: Some(debug), |
2946 | ..self |
2947 | } |
2948 | } |
2949 | |
2950 | pub fn debug_if(self, debug: &'a str, predicate: bool) -> Self { |
2951 | if predicate { |
2952 | self.debug(debug) |
2953 | } else { |
2954 | self |
2955 | } |
2956 | } |
2957 | |
2958 | pub fn debug_if_some(self, debug: Option<&'a str>) -> Self { |
2959 | if let Some(debug) = debug { |
2960 | self.debug(debug) |
2961 | } else { |
2962 | self |
2963 | } |
2964 | } |
2965 | |
2966 | #[cfg (not(feature = "v1_26" ))] |
2967 | pub fn details(self, details: Structure) -> Self { |
2968 | Self { |
2969 | details: Some(details), |
2970 | ..self |
2971 | } |
2972 | } |
2973 | |
2974 | #[cfg (not(feature = "v1_26" ))] |
2975 | pub fn details_if(self, details: Structure, predicate: bool) -> Self { |
2976 | if predicate { |
2977 | self.details(details) |
2978 | } else { |
2979 | self |
2980 | } |
2981 | } |
2982 | |
2983 | #[cfg (not(feature = "v1_26" ))] |
2984 | pub fn details_if_some(self, details: Option<Structure>) -> Self { |
2985 | if let Some(details) = details { |
2986 | self.details(details) |
2987 | } else { |
2988 | self |
2989 | } |
2990 | } |
2991 | |
2992 | message_builder_generic_impl!(|s: &mut Self, src| { |
2993 | let details = match s.details.take() { |
2994 | None => ptr::null_mut(), |
2995 | Some(details) => details.into_glib_ptr(), |
2996 | }; |
2997 | |
2998 | ffi::gst_message_new_error_with_details( |
2999 | src, |
3000 | mut_override(s.error.to_glib_none().0), |
3001 | s.debug.to_glib_none().0, |
3002 | details, |
3003 | ) |
3004 | }); |
3005 | } |
3006 | |
3007 | #[must_use = "The builder must be built to be used" ] |
3008 | pub struct WarningBuilder<'a> { |
3009 | builder: MessageBuilder<'a>, |
3010 | error: glib::Error, |
3011 | debug: Option<&'a str>, |
3012 | #[allow (unused)] |
3013 | details: Option<Structure>, |
3014 | } |
3015 | |
3016 | impl<'a> WarningBuilder<'a> { |
3017 | fn new(error: glib::Error) -> Self { |
3018 | skip_assert_initialized!(); |
3019 | Self { |
3020 | builder: MessageBuilder::new(), |
3021 | error, |
3022 | debug: None, |
3023 | details: None, |
3024 | } |
3025 | } |
3026 | |
3027 | pub fn debug(self, debug: &'a str) -> Self { |
3028 | Self { |
3029 | debug: Some(debug), |
3030 | ..self |
3031 | } |
3032 | } |
3033 | |
3034 | pub fn debug_if(self, debug: &'a str, predicate: bool) -> Self { |
3035 | if predicate { |
3036 | self.debug(debug) |
3037 | } else { |
3038 | self |
3039 | } |
3040 | } |
3041 | |
3042 | pub fn debug_if_some(self, debug: Option<&'a str>) -> Self { |
3043 | if let Some(debug) = debug { |
3044 | self.debug(debug) |
3045 | } else { |
3046 | self |
3047 | } |
3048 | } |
3049 | |
3050 | #[cfg (not(feature = "v1_26" ))] |
3051 | pub fn details(self, details: Structure) -> Self { |
3052 | Self { |
3053 | details: Some(details), |
3054 | ..self |
3055 | } |
3056 | } |
3057 | |
3058 | #[cfg (not(feature = "v1_26" ))] |
3059 | pub fn details_if(self, details: Structure, predicate: bool) -> Self { |
3060 | if predicate { |
3061 | self.details(details) |
3062 | } else { |
3063 | self |
3064 | } |
3065 | } |
3066 | |
3067 | #[cfg (not(feature = "v1_26" ))] |
3068 | pub fn details_if_some(self, details: Option<Structure>) -> Self { |
3069 | if let Some(details) = details { |
3070 | self.details(details) |
3071 | } else { |
3072 | self |
3073 | } |
3074 | } |
3075 | |
3076 | message_builder_generic_impl!(|s: &mut Self, src| { |
3077 | let details = match s.details.take() { |
3078 | None => ptr::null_mut(), |
3079 | Some(details) => details.into_glib_ptr(), |
3080 | }; |
3081 | |
3082 | ffi::gst_message_new_warning_with_details( |
3083 | src, |
3084 | mut_override(s.error.to_glib_none().0), |
3085 | s.debug.to_glib_none().0, |
3086 | details, |
3087 | ) |
3088 | }); |
3089 | } |
3090 | |
3091 | #[must_use = "The builder must be built to be used" ] |
3092 | pub struct InfoBuilder<'a> { |
3093 | builder: MessageBuilder<'a>, |
3094 | error: glib::Error, |
3095 | debug: Option<&'a str>, |
3096 | #[allow (unused)] |
3097 | details: Option<Structure>, |
3098 | } |
3099 | |
3100 | impl<'a> InfoBuilder<'a> { |
3101 | fn new(error: glib::Error) -> Self { |
3102 | skip_assert_initialized!(); |
3103 | Self { |
3104 | builder: MessageBuilder::new(), |
3105 | error, |
3106 | debug: None, |
3107 | details: None, |
3108 | } |
3109 | } |
3110 | |
3111 | pub fn debug(self, debug: &'a str) -> Self { |
3112 | Self { |
3113 | debug: Some(debug), |
3114 | ..self |
3115 | } |
3116 | } |
3117 | |
3118 | pub fn debug_if(self, debug: &'a str, predicate: bool) -> Self { |
3119 | if predicate { |
3120 | self.debug(debug) |
3121 | } else { |
3122 | self |
3123 | } |
3124 | } |
3125 | |
3126 | pub fn debug_if_some(self, debug: Option<&'a str>) -> Self { |
3127 | if let Some(debug) = debug { |
3128 | self.debug(debug) |
3129 | } else { |
3130 | self |
3131 | } |
3132 | } |
3133 | |
3134 | #[cfg (not(feature = "v1_26" ))] |
3135 | pub fn details(self, details: Structure) -> Self { |
3136 | Self { |
3137 | details: Some(details), |
3138 | ..self |
3139 | } |
3140 | } |
3141 | |
3142 | #[cfg (not(feature = "v1_26" ))] |
3143 | pub fn details_if(self, details: Structure, predicate: bool) -> Self { |
3144 | if predicate { |
3145 | self.details(details) |
3146 | } else { |
3147 | self |
3148 | } |
3149 | } |
3150 | |
3151 | #[cfg (not(feature = "v1_26" ))] |
3152 | pub fn details_if_some(self, details: Option<Structure>) -> Self { |
3153 | if let Some(details) = details { |
3154 | self.details(details) |
3155 | } else { |
3156 | self |
3157 | } |
3158 | } |
3159 | |
3160 | message_builder_generic_impl!(|s: &mut Self, src| { |
3161 | let details = match s.details.take() { |
3162 | None => ptr::null_mut(), |
3163 | Some(details) => details.into_glib_ptr(), |
3164 | }; |
3165 | |
3166 | ffi::gst_message_new_info_with_details( |
3167 | src, |
3168 | mut_override(s.error.to_glib_none().0), |
3169 | s.debug.to_glib_none().0, |
3170 | details, |
3171 | ) |
3172 | }); |
3173 | } |
3174 | |
3175 | #[must_use = "The builder must be built to be used" ] |
3176 | pub struct TagBuilder<'a> { |
3177 | builder: MessageBuilder<'a>, |
3178 | tags: &'a TagList, |
3179 | } |
3180 | |
3181 | impl<'a> TagBuilder<'a> { |
3182 | fn new(tags: &'a TagList) -> Self { |
3183 | skip_assert_initialized!(); |
3184 | Self { |
3185 | builder: MessageBuilder::new(), |
3186 | tags, |
3187 | } |
3188 | } |
3189 | |
3190 | message_builder_generic_impl!(|s: &Self, src| ffi::gst_message_new_tag( |
3191 | src, |
3192 | s.tags.to_glib_full() |
3193 | )); |
3194 | } |
3195 | |
3196 | #[must_use = "The builder must be built to be used" ] |
3197 | pub struct BufferingBuilder<'a> { |
3198 | builder: MessageBuilder<'a>, |
3199 | percent: i32, |
3200 | stats: Option<(crate::BufferingMode, i32, i32, i64)>, |
3201 | } |
3202 | |
3203 | impl<'a> BufferingBuilder<'a> { |
3204 | fn new(percent: i32) -> Self { |
3205 | skip_assert_initialized!(); |
3206 | Self { |
3207 | builder: MessageBuilder::new(), |
3208 | percent, |
3209 | stats: None, |
3210 | } |
3211 | } |
3212 | |
3213 | pub fn stats( |
3214 | self, |
3215 | mode: crate::BufferingMode, |
3216 | avg_in: i32, |
3217 | avg_out: i32, |
3218 | buffering_left: i64, |
3219 | ) -> Self { |
3220 | skip_assert_initialized!(); |
3221 | Self { |
3222 | stats: Some((mode, avg_in, avg_out, buffering_left)), |
3223 | ..self |
3224 | } |
3225 | } |
3226 | |
3227 | message_builder_generic_impl!(|s: &mut Self, src| { |
3228 | let msg = ffi::gst_message_new_buffering(src, s.percent); |
3229 | |
3230 | if let Some((mode, avg_in, avg_out, buffering_left)) = s.stats { |
3231 | ffi::gst_message_set_buffering_stats( |
3232 | msg, |
3233 | mode.into_glib(), |
3234 | avg_in, |
3235 | avg_out, |
3236 | buffering_left, |
3237 | ); |
3238 | } |
3239 | |
3240 | msg |
3241 | }); |
3242 | } |
3243 | |
3244 | #[must_use = "The builder must be built to be used" ] |
3245 | pub struct StateChangedBuilder<'a> { |
3246 | builder: MessageBuilder<'a>, |
3247 | old: crate::State, |
3248 | new: crate::State, |
3249 | pending: crate::State, |
3250 | } |
3251 | |
3252 | impl<'a> StateChangedBuilder<'a> { |
3253 | fn new(old: crate::State, new: crate::State, pending: crate::State) -> Self { |
3254 | skip_assert_initialized!(); |
3255 | Self { |
3256 | builder: MessageBuilder::new(), |
3257 | old, |
3258 | new, |
3259 | pending, |
3260 | } |
3261 | } |
3262 | |
3263 | message_builder_generic_impl!(|s: &mut Self, src| ffi::gst_message_new_state_changed( |
3264 | src, |
3265 | s.old.into_glib(), |
3266 | s.new.into_glib(), |
3267 | s.pending.into_glib(), |
3268 | )); |
3269 | } |
3270 | |
3271 | #[must_use = "The builder must be built to be used" ] |
3272 | pub struct StateDirtyBuilder<'a> { |
3273 | builder: MessageBuilder<'a>, |
3274 | } |
3275 | |
3276 | impl<'a> StateDirtyBuilder<'a> { |
3277 | fn new() -> Self { |
3278 | skip_assert_initialized!(); |
3279 | Self { |
3280 | builder: MessageBuilder::new(), |
3281 | } |
3282 | } |
3283 | |
3284 | message_builder_generic_impl!(|_, src| ffi::gst_message_new_state_dirty(src)); |
3285 | } |
3286 | |
3287 | #[must_use = "The builder must be built to be used" ] |
3288 | pub struct StepDoneBuilder<'a> { |
3289 | builder: MessageBuilder<'a>, |
3290 | amount: GenericFormattedValue, |
3291 | rate: f64, |
3292 | flush: bool, |
3293 | intermediate: bool, |
3294 | duration: Option<crate::ClockTime>, |
3295 | eos: bool, |
3296 | } |
3297 | |
3298 | impl<'a> StepDoneBuilder<'a> { |
3299 | fn new( |
3300 | amount: GenericFormattedValue, |
3301 | rate: f64, |
3302 | flush: bool, |
3303 | intermediate: bool, |
3304 | duration: Option<crate::ClockTime>, |
3305 | eos: bool, |
3306 | ) -> Self { |
3307 | skip_assert_initialized!(); |
3308 | assert_eq!(amount.format(), duration.format()); |
3309 | Self { |
3310 | builder: MessageBuilder::new(), |
3311 | amount, |
3312 | rate, |
3313 | flush, |
3314 | intermediate, |
3315 | duration, |
3316 | eos, |
3317 | } |
3318 | } |
3319 | |
3320 | message_builder_generic_impl!(|s: &mut Self, src| ffi::gst_message_new_step_done( |
3321 | src, |
3322 | s.amount.format().into_glib(), |
3323 | s.amount.value() as u64, |
3324 | s.rate, |
3325 | s.flush.into_glib(), |
3326 | s.intermediate.into_glib(), |
3327 | s.duration.into_raw_value() as u64, |
3328 | s.eos.into_glib(), |
3329 | )); |
3330 | } |
3331 | |
3332 | #[must_use = "The builder must be built to be used" ] |
3333 | pub struct ClockProvideBuilder<'a> { |
3334 | builder: MessageBuilder<'a>, |
3335 | clock: &'a crate::Clock, |
3336 | ready: bool, |
3337 | } |
3338 | |
3339 | impl<'a> ClockProvideBuilder<'a> { |
3340 | fn new(clock: &'a crate::Clock, ready: bool) -> Self { |
3341 | skip_assert_initialized!(); |
3342 | Self { |
3343 | builder: MessageBuilder::new(), |
3344 | clock, |
3345 | ready, |
3346 | } |
3347 | } |
3348 | |
3349 | message_builder_generic_impl!(|s: &mut Self, src| ffi::gst_message_new_clock_provide( |
3350 | src, |
3351 | s.clock.to_glib_none().0, |
3352 | s.ready.into_glib() |
3353 | )); |
3354 | } |
3355 | |
3356 | #[must_use = "The builder must be built to be used" ] |
3357 | pub struct ClockLostBuilder<'a> { |
3358 | builder: MessageBuilder<'a>, |
3359 | clock: &'a crate::Clock, |
3360 | } |
3361 | |
3362 | impl<'a> ClockLostBuilder<'a> { |
3363 | fn new(clock: &'a crate::Clock) -> Self { |
3364 | skip_assert_initialized!(); |
3365 | Self { |
3366 | builder: MessageBuilder::new(), |
3367 | clock, |
3368 | } |
3369 | } |
3370 | |
3371 | message_builder_generic_impl!(|s: &mut Self, src| ffi::gst_message_new_clock_lost( |
3372 | src, |
3373 | s.clock.to_glib_none().0 |
3374 | )); |
3375 | } |
3376 | |
3377 | #[must_use = "The builder must be built to be used" ] |
3378 | pub struct NewClockBuilder<'a> { |
3379 | builder: MessageBuilder<'a>, |
3380 | clock: &'a crate::Clock, |
3381 | } |
3382 | |
3383 | impl<'a> NewClockBuilder<'a> { |
3384 | fn new(clock: &'a crate::Clock) -> Self { |
3385 | skip_assert_initialized!(); |
3386 | Self { |
3387 | builder: MessageBuilder::new(), |
3388 | clock, |
3389 | } |
3390 | } |
3391 | |
3392 | message_builder_generic_impl!(|s: &mut Self, src| ffi::gst_message_new_new_clock( |
3393 | src, |
3394 | s.clock.to_glib_none().0 |
3395 | )); |
3396 | } |
3397 | |
3398 | #[must_use = "The builder must be built to be used" ] |
3399 | pub struct StructureChangeBuilder<'a> { |
3400 | builder: MessageBuilder<'a>, |
3401 | type_: crate::StructureChangeType, |
3402 | owner: &'a crate::Element, |
3403 | busy: bool, |
3404 | } |
3405 | |
3406 | impl<'a> StructureChangeBuilder<'a> { |
3407 | fn new(type_: crate::StructureChangeType, owner: &'a crate::Element, busy: bool) -> Self { |
3408 | skip_assert_initialized!(); |
3409 | Self { |
3410 | builder: MessageBuilder::new(), |
3411 | type_, |
3412 | owner, |
3413 | busy, |
3414 | } |
3415 | } |
3416 | |
3417 | message_builder_generic_impl!(|s: &mut Self, src| ffi::gst_message_new_structure_change( |
3418 | src, |
3419 | s.type_.into_glib(), |
3420 | s.owner.to_glib_none().0, |
3421 | s.busy.into_glib(), |
3422 | )); |
3423 | } |
3424 | |
3425 | #[must_use = "The builder must be built to be used" ] |
3426 | pub struct StreamStatusBuilder<'a> { |
3427 | builder: MessageBuilder<'a>, |
3428 | type_: crate::StreamStatusType, |
3429 | owner: &'a crate::Element, |
3430 | status_object: Option<glib::SendValue>, |
3431 | } |
3432 | |
3433 | impl<'a> StreamStatusBuilder<'a> { |
3434 | fn new(type_: crate::StreamStatusType, owner: &'a crate::Element) -> Self { |
3435 | skip_assert_initialized!(); |
3436 | Self { |
3437 | builder: MessageBuilder::new(), |
3438 | type_, |
3439 | owner, |
3440 | status_object: None, |
3441 | } |
3442 | } |
3443 | |
3444 | pub fn status_object(self, status_object: impl ToSendValue) -> Self { |
3445 | Self { |
3446 | status_object: Some(status_object.to_send_value()), |
3447 | ..self |
3448 | } |
3449 | } |
3450 | |
3451 | pub fn status_object_if(self, status_object: impl ToSendValue, predicate: bool) -> Self { |
3452 | if predicate { |
3453 | self.status_object(status_object) |
3454 | } else { |
3455 | self |
3456 | } |
3457 | } |
3458 | |
3459 | pub fn status_object_if_some(self, status_object: Option<impl ToSendValue>) -> Self { |
3460 | if let Some(status_object) = status_object { |
3461 | self.status_object(status_object) |
3462 | } else { |
3463 | self |
3464 | } |
3465 | } |
3466 | |
3467 | message_builder_generic_impl!(|s: &mut Self, src| { |
3468 | let msg = |
3469 | ffi::gst_message_new_stream_status(src, s.type_.into_glib(), s.owner.to_glib_none().0); |
3470 | if let Some(ref status_object) = s.status_object { |
3471 | ffi::gst_message_set_stream_status_object(msg, status_object.to_glib_none().0); |
3472 | } |
3473 | msg |
3474 | }); |
3475 | } |
3476 | |
3477 | #[must_use = "The builder must be built to be used" ] |
3478 | pub struct ApplicationBuilder<'a> { |
3479 | builder: MessageBuilder<'a>, |
3480 | structure: Option<crate::Structure>, |
3481 | } |
3482 | |
3483 | impl<'a> ApplicationBuilder<'a> { |
3484 | fn new(structure: crate::Structure) -> Self { |
3485 | skip_assert_initialized!(); |
3486 | Self { |
3487 | builder: MessageBuilder::new(), |
3488 | structure: Some(structure), |
3489 | } |
3490 | } |
3491 | |
3492 | message_builder_generic_impl!(|s: &mut Self, src| ffi::gst_message_new_application( |
3493 | src, |
3494 | s.structure.take().unwrap().into_glib_ptr() |
3495 | )); |
3496 | } |
3497 | |
3498 | #[must_use = "The builder must be built to be used" ] |
3499 | pub struct ElementBuilder<'a> { |
3500 | builder: MessageBuilder<'a>, |
3501 | structure: Option<crate::Structure>, |
3502 | } |
3503 | |
3504 | impl<'a> ElementBuilder<'a> { |
3505 | fn new(structure: crate::Structure) -> Self { |
3506 | skip_assert_initialized!(); |
3507 | Self { |
3508 | builder: MessageBuilder::new(), |
3509 | structure: Some(structure), |
3510 | } |
3511 | } |
3512 | |
3513 | message_builder_generic_impl!(|s: &mut Self, src| ffi::gst_message_new_element( |
3514 | src, |
3515 | s.structure.take().unwrap().into_glib_ptr() |
3516 | )); |
3517 | } |
3518 | |
3519 | #[must_use = "The builder must be built to be used" ] |
3520 | pub struct SegmentStartBuilder<'a> { |
3521 | builder: MessageBuilder<'a>, |
3522 | position: GenericFormattedValue, |
3523 | } |
3524 | |
3525 | impl<'a> SegmentStartBuilder<'a> { |
3526 | fn new(position: GenericFormattedValue) -> Self { |
3527 | skip_assert_initialized!(); |
3528 | Self { |
3529 | builder: MessageBuilder::new(), |
3530 | position, |
3531 | } |
3532 | } |
3533 | |
3534 | message_builder_generic_impl!(|s: &mut Self, src| ffi::gst_message_new_segment_start( |
3535 | src, |
3536 | s.position.format().into_glib(), |
3537 | s.position.value(), |
3538 | )); |
3539 | } |
3540 | |
3541 | #[must_use = "The builder must be built to be used" ] |
3542 | pub struct SegmentDoneBuilder<'a> { |
3543 | builder: MessageBuilder<'a>, |
3544 | position: GenericFormattedValue, |
3545 | } |
3546 | |
3547 | impl<'a> SegmentDoneBuilder<'a> { |
3548 | fn new(position: GenericFormattedValue) -> Self { |
3549 | skip_assert_initialized!(); |
3550 | Self { |
3551 | builder: MessageBuilder::new(), |
3552 | position, |
3553 | } |
3554 | } |
3555 | |
3556 | message_builder_generic_impl!(|s: &mut Self, src| ffi::gst_message_new_segment_done( |
3557 | src, |
3558 | s.position.format().into_glib(), |
3559 | s.position.value(), |
3560 | )); |
3561 | } |
3562 | |
3563 | #[must_use = "The builder must be built to be used" ] |
3564 | pub struct DurationChangedBuilder<'a> { |
3565 | builder: MessageBuilder<'a>, |
3566 | } |
3567 | |
3568 | impl<'a> DurationChangedBuilder<'a> { |
3569 | fn new() -> Self { |
3570 | skip_assert_initialized!(); |
3571 | Self { |
3572 | builder: MessageBuilder::new(), |
3573 | } |
3574 | } |
3575 | |
3576 | message_builder_generic_impl!(|_, src| ffi::gst_message_new_duration_changed(src)); |
3577 | } |
3578 | |
3579 | #[must_use = "The builder must be built to be used" ] |
3580 | pub struct LatencyBuilder<'a> { |
3581 | builder: MessageBuilder<'a>, |
3582 | } |
3583 | |
3584 | impl<'a> LatencyBuilder<'a> { |
3585 | fn new() -> Self { |
3586 | skip_assert_initialized!(); |
3587 | Self { |
3588 | builder: MessageBuilder::new(), |
3589 | } |
3590 | } |
3591 | |
3592 | message_builder_generic_impl!(|_, src| ffi::gst_message_new_latency(src)); |
3593 | } |
3594 | |
3595 | #[must_use = "The builder must be built to be used" ] |
3596 | pub struct AsyncStartBuilder<'a> { |
3597 | builder: MessageBuilder<'a>, |
3598 | } |
3599 | |
3600 | impl<'a> AsyncStartBuilder<'a> { |
3601 | fn new() -> Self { |
3602 | skip_assert_initialized!(); |
3603 | Self { |
3604 | builder: MessageBuilder::new(), |
3605 | } |
3606 | } |
3607 | |
3608 | message_builder_generic_impl!(|_, src| ffi::gst_message_new_async_start(src)); |
3609 | } |
3610 | |
3611 | #[must_use = "The builder must be built to be used" ] |
3612 | pub struct AsyncDoneBuilder<'a> { |
3613 | builder: MessageBuilder<'a>, |
3614 | running_time: Option<crate::ClockTime>, |
3615 | } |
3616 | |
3617 | impl<'a> AsyncDoneBuilder<'a> { |
3618 | fn new() -> Self { |
3619 | skip_assert_initialized!(); |
3620 | Self { |
3621 | builder: MessageBuilder::new(), |
3622 | running_time: None, |
3623 | } |
3624 | } |
3625 | |
3626 | pub fn running_time(mut self, running_time: impl Into<Option<crate::ClockTime>>) -> Self { |
3627 | self.running_time = running_time.into(); |
3628 | self |
3629 | } |
3630 | |
3631 | pub fn running_time_if(self, running_time: crate::ClockTime, predicate: bool) -> Self { |
3632 | if predicate { |
3633 | self.running_time(running_time) |
3634 | } else { |
3635 | self |
3636 | } |
3637 | } |
3638 | |
3639 | pub fn running_time_if_some(self, running_time: Option<crate::ClockTime>) -> Self { |
3640 | if let Some(running_time) = running_time { |
3641 | self.running_time(running_time) |
3642 | } else { |
3643 | self |
3644 | } |
3645 | } |
3646 | |
3647 | message_builder_generic_impl!(|s: &mut Self, src| ffi::gst_message_new_async_done( |
3648 | src, |
3649 | s.running_time.into_glib() |
3650 | )); |
3651 | } |
3652 | |
3653 | #[must_use = "The builder must be built to be used" ] |
3654 | pub struct RequestStateBuilder<'a> { |
3655 | builder: MessageBuilder<'a>, |
3656 | state: crate::State, |
3657 | } |
3658 | |
3659 | impl<'a> RequestStateBuilder<'a> { |
3660 | fn new(state: crate::State) -> Self { |
3661 | skip_assert_initialized!(); |
3662 | Self { |
3663 | builder: MessageBuilder::new(), |
3664 | state, |
3665 | } |
3666 | } |
3667 | |
3668 | message_builder_generic_impl!(|s: &mut Self, src| ffi::gst_message_new_request_state( |
3669 | src, |
3670 | s.state.into_glib() |
3671 | )); |
3672 | } |
3673 | |
3674 | #[must_use = "The builder must be built to be used" ] |
3675 | pub struct StepStartBuilder<'a> { |
3676 | builder: MessageBuilder<'a>, |
3677 | active: bool, |
3678 | amount: GenericFormattedValue, |
3679 | rate: f64, |
3680 | flush: bool, |
3681 | intermediate: bool, |
3682 | } |
3683 | |
3684 | impl<'a> StepStartBuilder<'a> { |
3685 | fn new( |
3686 | active: bool, |
3687 | amount: GenericFormattedValue, |
3688 | rate: f64, |
3689 | flush: bool, |
3690 | intermediate: bool, |
3691 | ) -> Self { |
3692 | skip_assert_initialized!(); |
3693 | Self { |
3694 | builder: MessageBuilder::new(), |
3695 | active, |
3696 | amount, |
3697 | rate, |
3698 | flush, |
3699 | intermediate, |
3700 | } |
3701 | } |
3702 | |
3703 | message_builder_generic_impl!(|s: &mut Self, src| ffi::gst_message_new_step_start( |
3704 | src, |
3705 | s.active.into_glib(), |
3706 | s.amount.format().into_glib(), |
3707 | s.amount.value() as u64, |
3708 | s.rate, |
3709 | s.flush.into_glib(), |
3710 | s.intermediate.into_glib(), |
3711 | )); |
3712 | } |
3713 | |
3714 | #[must_use = "The builder must be built to be used" ] |
3715 | pub struct QosBuilder<'a> { |
3716 | builder: MessageBuilder<'a>, |
3717 | live: bool, |
3718 | running_time: Option<crate::ClockTime>, |
3719 | stream_time: Option<crate::ClockTime>, |
3720 | timestamp: Option<crate::ClockTime>, |
3721 | duration: Option<crate::ClockTime>, |
3722 | values: Option<(i64, f64, i32)>, |
3723 | stats: Option<(GenericFormattedValue, GenericFormattedValue)>, |
3724 | } |
3725 | |
3726 | impl<'a> QosBuilder<'a> { |
3727 | fn new(live: bool) -> Self { |
3728 | skip_assert_initialized!(); |
3729 | Self { |
3730 | builder: MessageBuilder::new(), |
3731 | live, |
3732 | running_time: None, |
3733 | stream_time: None, |
3734 | timestamp: None, |
3735 | duration: None, |
3736 | values: None, |
3737 | stats: None, |
3738 | } |
3739 | } |
3740 | |
3741 | pub fn running_time(mut self, running_time: impl Into<Option<crate::ClockTime>>) -> Self { |
3742 | self.running_time = running_time.into(); |
3743 | self |
3744 | } |
3745 | |
3746 | pub fn running_time_if(self, running_time: crate::ClockTime, predicate: bool) -> Self { |
3747 | if predicate { |
3748 | self.running_time(running_time) |
3749 | } else { |
3750 | self |
3751 | } |
3752 | } |
3753 | |
3754 | pub fn running_time_if_some(self, running_time: Option<crate::ClockTime>) -> Self { |
3755 | if let Some(running_time) = running_time { |
3756 | self.running_time(running_time) |
3757 | } else { |
3758 | self |
3759 | } |
3760 | } |
3761 | |
3762 | pub fn stream_time(mut self, stream_time: impl Into<Option<crate::ClockTime>>) -> Self { |
3763 | self.stream_time = stream_time.into(); |
3764 | self |
3765 | } |
3766 | |
3767 | pub fn stream_time_if(self, stream_time: crate::ClockTime, predicate: bool) -> Self { |
3768 | if predicate { |
3769 | self.stream_time(stream_time) |
3770 | } else { |
3771 | self |
3772 | } |
3773 | } |
3774 | |
3775 | pub fn stream_time_if_some(self, stream_time: Option<crate::ClockTime>) -> Self { |
3776 | if let Some(stream_time) = stream_time { |
3777 | self.stream_time(stream_time) |
3778 | } else { |
3779 | self |
3780 | } |
3781 | } |
3782 | |
3783 | pub fn timestamp(mut self, timestamp: impl Into<Option<crate::ClockTime>>) -> Self { |
3784 | self.timestamp = timestamp.into(); |
3785 | self |
3786 | } |
3787 | |
3788 | pub fn timestamp_if(self, timestamp: crate::ClockTime, predicate: bool) -> Self { |
3789 | if predicate { |
3790 | self.timestamp(timestamp) |
3791 | } else { |
3792 | self |
3793 | } |
3794 | } |
3795 | |
3796 | pub fn timestamp_if_some(self, timestamp: Option<crate::ClockTime>) -> Self { |
3797 | if let Some(timestamp) = timestamp { |
3798 | self.timestamp(timestamp) |
3799 | } else { |
3800 | self |
3801 | } |
3802 | } |
3803 | |
3804 | pub fn duration(mut self, duration: impl Into<Option<crate::ClockTime>>) -> Self { |
3805 | self.duration = duration.into(); |
3806 | self |
3807 | } |
3808 | |
3809 | pub fn duration_if(self, duration: crate::ClockTime, predicate: bool) -> Self { |
3810 | if predicate { |
3811 | self.duration(duration) |
3812 | } else { |
3813 | self |
3814 | } |
3815 | } |
3816 | |
3817 | pub fn duration_if_some(self, duration: Option<crate::ClockTime>) -> Self { |
3818 | if let Some(duration) = duration { |
3819 | self.duration(duration) |
3820 | } else { |
3821 | self |
3822 | } |
3823 | } |
3824 | |
3825 | pub fn values(self, jitter: i64, proportion: f64, quality: i32) -> Self { |
3826 | Self { |
3827 | values: Some((jitter, proportion, quality)), |
3828 | ..self |
3829 | } |
3830 | } |
3831 | |
3832 | pub fn stats<V: FormattedValue>( |
3833 | self, |
3834 | processed: V, |
3835 | dropped: impl CompatibleFormattedValue<V>, |
3836 | ) -> Self { |
3837 | let dropped = dropped.try_into_checked(processed).unwrap(); |
3838 | Self { |
3839 | stats: Some((processed.into(), dropped.into())), |
3840 | ..self |
3841 | } |
3842 | } |
3843 | |
3844 | message_builder_generic_impl!(|s: &mut Self, src| { |
3845 | let msg = ffi::gst_message_new_qos( |
3846 | src, |
3847 | s.live.into_glib(), |
3848 | s.running_time.into_glib(), |
3849 | s.stream_time.into_glib(), |
3850 | s.timestamp.into_glib(), |
3851 | s.duration.into_glib(), |
3852 | ); |
3853 | if let Some((jitter, proportion, quality)) = s.values { |
3854 | ffi::gst_message_set_qos_values(msg, jitter, proportion, quality); |
3855 | } |
3856 | if let Some((processed, dropped)) = s.stats { |
3857 | ffi::gst_message_set_qos_stats( |
3858 | msg, |
3859 | processed.format().into_glib(), |
3860 | processed.value() as u64, |
3861 | dropped.value() as u64, |
3862 | ); |
3863 | } |
3864 | msg |
3865 | }); |
3866 | } |
3867 | |
3868 | #[must_use = "The builder must be built to be used" ] |
3869 | pub struct ProgressBuilder<'a> { |
3870 | builder: MessageBuilder<'a>, |
3871 | type_: crate::ProgressType, |
3872 | code: &'a str, |
3873 | text: &'a str, |
3874 | } |
3875 | |
3876 | impl<'a> ProgressBuilder<'a> { |
3877 | fn new(type_: crate::ProgressType, code: &'a str, text: &'a str) -> Self { |
3878 | skip_assert_initialized!(); |
3879 | Self { |
3880 | builder: MessageBuilder::new(), |
3881 | type_, |
3882 | code, |
3883 | text, |
3884 | } |
3885 | } |
3886 | |
3887 | message_builder_generic_impl!(|s: &mut Self, src| ffi::gst_message_new_progress( |
3888 | src, |
3889 | s.type_.into_glib(), |
3890 | s.code.to_glib_none().0, |
3891 | s.text.to_glib_none().0, |
3892 | )); |
3893 | } |
3894 | |
3895 | #[must_use = "The builder must be built to be used" ] |
3896 | pub struct TocBuilder<'a> { |
3897 | builder: MessageBuilder<'a>, |
3898 | toc: &'a crate::Toc, |
3899 | updated: bool, |
3900 | } |
3901 | |
3902 | impl<'a> TocBuilder<'a> { |
3903 | fn new(toc: &'a crate::Toc, updated: bool) -> Self { |
3904 | skip_assert_initialized!(); |
3905 | Self { |
3906 | builder: MessageBuilder::new(), |
3907 | toc, |
3908 | updated, |
3909 | } |
3910 | } |
3911 | |
3912 | message_builder_generic_impl!(|s: &Self, src| ffi::gst_message_new_toc( |
3913 | src, |
3914 | s.toc.to_glib_none().0, |
3915 | s.updated.into_glib() |
3916 | )); |
3917 | } |
3918 | |
3919 | #[must_use = "The builder must be built to be used" ] |
3920 | pub struct ResetTimeBuilder<'a> { |
3921 | builder: MessageBuilder<'a>, |
3922 | running_time: crate::ClockTime, |
3923 | } |
3924 | |
3925 | impl<'a> ResetTimeBuilder<'a> { |
3926 | fn new(running_time: crate::ClockTime) -> Self { |
3927 | skip_assert_initialized!(); |
3928 | Self { |
3929 | builder: MessageBuilder::new(), |
3930 | running_time, |
3931 | } |
3932 | } |
3933 | |
3934 | message_builder_generic_impl!(|s: &mut Self, src| ffi::gst_message_new_reset_time( |
3935 | src, |
3936 | s.running_time.into_glib() |
3937 | )); |
3938 | } |
3939 | |
3940 | #[must_use = "The builder must be built to be used" ] |
3941 | pub struct StreamStartBuilder<'a> { |
3942 | builder: MessageBuilder<'a>, |
3943 | group_id: Option<GroupId>, |
3944 | } |
3945 | |
3946 | impl<'a> StreamStartBuilder<'a> { |
3947 | fn new() -> Self { |
3948 | skip_assert_initialized!(); |
3949 | Self { |
3950 | builder: MessageBuilder::new(), |
3951 | group_id: None, |
3952 | } |
3953 | } |
3954 | |
3955 | pub fn group_id(self, group_id: GroupId) -> Self { |
3956 | Self { |
3957 | group_id: Some(group_id), |
3958 | ..self |
3959 | } |
3960 | } |
3961 | |
3962 | pub fn group_id_if(self, group_id: GroupId, predicate: bool) -> Self { |
3963 | if predicate { |
3964 | self.group_id(group_id) |
3965 | } else { |
3966 | self |
3967 | } |
3968 | } |
3969 | |
3970 | pub fn group_id_if_some(self, group_id: Option<GroupId>) -> Self { |
3971 | if let Some(group_id) = group_id { |
3972 | self.group_id(group_id) |
3973 | } else { |
3974 | self |
3975 | } |
3976 | } |
3977 | |
3978 | message_builder_generic_impl!(|s: &mut Self, src| { |
3979 | let msg = ffi::gst_message_new_stream_start(src); |
3980 | if let Some(group_id) = s.group_id { |
3981 | ffi::gst_message_set_group_id(msg, group_id.0.get()); |
3982 | } |
3983 | msg |
3984 | }); |
3985 | } |
3986 | |
3987 | #[must_use = "The builder must be built to be used" ] |
3988 | pub struct NeedContextBuilder<'a> { |
3989 | builder: MessageBuilder<'a>, |
3990 | context_type: &'a str, |
3991 | } |
3992 | |
3993 | impl<'a> NeedContextBuilder<'a> { |
3994 | fn new(context_type: &'a str) -> Self { |
3995 | skip_assert_initialized!(); |
3996 | Self { |
3997 | builder: MessageBuilder::new(), |
3998 | context_type, |
3999 | } |
4000 | } |
4001 | |
4002 | message_builder_generic_impl!(|s: &mut Self, src| ffi::gst_message_new_need_context( |
4003 | src, |
4004 | s.context_type.to_glib_none().0 |
4005 | )); |
4006 | } |
4007 | |
4008 | #[must_use = "The builder must be built to be used" ] |
4009 | pub struct HaveContextBuilder<'a> { |
4010 | builder: MessageBuilder<'a>, |
4011 | context: Option<crate::Context>, |
4012 | } |
4013 | |
4014 | impl<'a> HaveContextBuilder<'a> { |
4015 | fn new(context: crate::Context) -> Self { |
4016 | skip_assert_initialized!(); |
4017 | Self { |
4018 | builder: MessageBuilder::new(), |
4019 | context: Some(context), |
4020 | } |
4021 | } |
4022 | |
4023 | message_builder_generic_impl!(|s: &mut Self, src| { |
4024 | let context = s.context.take().unwrap(); |
4025 | ffi::gst_message_new_have_context(src, context.into_glib_ptr()) |
4026 | }); |
4027 | } |
4028 | |
4029 | #[must_use = "The builder must be built to be used" ] |
4030 | pub struct DeviceAddedBuilder<'a> { |
4031 | builder: MessageBuilder<'a>, |
4032 | device: &'a crate::Device, |
4033 | } |
4034 | |
4035 | impl<'a> DeviceAddedBuilder<'a> { |
4036 | fn new(device: &'a crate::Device) -> Self { |
4037 | skip_assert_initialized!(); |
4038 | Self { |
4039 | builder: MessageBuilder::new(), |
4040 | device, |
4041 | } |
4042 | } |
4043 | |
4044 | message_builder_generic_impl!(|s: &mut Self, src| ffi::gst_message_new_device_added( |
4045 | src, |
4046 | s.device.to_glib_none().0 |
4047 | )); |
4048 | } |
4049 | |
4050 | #[must_use = "The builder must be built to be used" ] |
4051 | pub struct DeviceRemovedBuilder<'a> { |
4052 | builder: MessageBuilder<'a>, |
4053 | device: &'a crate::Device, |
4054 | } |
4055 | |
4056 | impl<'a> DeviceRemovedBuilder<'a> { |
4057 | fn new(device: &'a crate::Device) -> Self { |
4058 | skip_assert_initialized!(); |
4059 | Self { |
4060 | builder: MessageBuilder::new(), |
4061 | device, |
4062 | } |
4063 | } |
4064 | |
4065 | message_builder_generic_impl!(|s: &mut Self, src| ffi::gst_message_new_device_removed( |
4066 | src, |
4067 | s.device.to_glib_none().0 |
4068 | )); |
4069 | } |
4070 | |
4071 | #[must_use = "The builder must be built to be used" ] |
4072 | pub struct PropertyNotifyBuilder<'a> { |
4073 | builder: MessageBuilder<'a>, |
4074 | property_name: &'a str, |
4075 | value: Option<glib::SendValue>, |
4076 | } |
4077 | |
4078 | impl<'a> PropertyNotifyBuilder<'a> { |
4079 | fn new(property_name: &'a str) -> Self { |
4080 | skip_assert_initialized!(); |
4081 | Self { |
4082 | builder: MessageBuilder::new(), |
4083 | property_name, |
4084 | value: None, |
4085 | } |
4086 | } |
4087 | |
4088 | pub fn value(self, value: impl ToSendValue) -> Self { |
4089 | Self { |
4090 | value: Some(value.to_send_value()), |
4091 | ..self |
4092 | } |
4093 | } |
4094 | |
4095 | pub fn value_if(self, value: impl ToSendValue, predicate: bool) -> Self { |
4096 | if predicate { |
4097 | self.value(value) |
4098 | } else { |
4099 | self |
4100 | } |
4101 | } |
4102 | |
4103 | pub fn value_if_some(self, value: Option<impl ToSendValue>) -> Self { |
4104 | if let Some(value) = value { |
4105 | self.value(value) |
4106 | } else { |
4107 | self |
4108 | } |
4109 | } |
4110 | |
4111 | pub fn value_from_iter<V: ValueType + ToSendValue + FromIterator<SendValue>>( |
4112 | self, |
4113 | name: &'a str, |
4114 | iter: impl IntoIterator<Item = impl ToSendValue>, |
4115 | ) -> Self { |
4116 | let iter = iter.into_iter().map(|item| item.to_send_value()); |
4117 | self.other_field(name, V::from_iter(iter)) |
4118 | } |
4119 | |
4120 | pub fn value_field_if_not_empty<V: ValueType + ToSendValue + FromIterator<SendValue>>( |
4121 | self, |
4122 | name: &'a str, |
4123 | iter: impl IntoIterator<Item = impl ToSendValue>, |
4124 | ) -> Self { |
4125 | let mut iter = iter.into_iter().peekable(); |
4126 | if iter.peek().is_some() { |
4127 | let iter = iter.map(|item| item.to_send_value()); |
4128 | self.other_field(name, V::from_iter(iter)) |
4129 | } else { |
4130 | self |
4131 | } |
4132 | } |
4133 | |
4134 | message_builder_generic_impl!(|s: &mut Self, src| { |
4135 | let v = s.value.take(); |
4136 | ffi::gst_message_new_property_notify( |
4137 | src, |
4138 | s.property_name.to_glib_none().0, |
4139 | v.as_ref().map(|v| v.as_ptr()).unwrap_or(ptr::null_mut()), |
4140 | ) |
4141 | }); |
4142 | } |
4143 | |
4144 | #[must_use = "The builder must be built to be used" ] |
4145 | pub struct StreamCollectionBuilder<'a> { |
4146 | builder: MessageBuilder<'a>, |
4147 | collection: &'a crate::StreamCollection, |
4148 | } |
4149 | |
4150 | impl<'a> StreamCollectionBuilder<'a> { |
4151 | fn new(collection: &'a crate::StreamCollection) -> Self { |
4152 | skip_assert_initialized!(); |
4153 | Self { |
4154 | builder: MessageBuilder::new(), |
4155 | collection, |
4156 | } |
4157 | } |
4158 | |
4159 | message_builder_generic_impl!(|s: &mut Self, src| { |
4160 | ffi::gst_message_new_stream_collection(src, s.collection.to_glib_none().0) |
4161 | }); |
4162 | } |
4163 | |
4164 | #[must_use = "The builder must be built to be used" ] |
4165 | pub struct StreamsSelectedBuilder<'a> { |
4166 | builder: MessageBuilder<'a>, |
4167 | collection: &'a crate::StreamCollection, |
4168 | streams: Option<Vec<crate::Stream>>, |
4169 | } |
4170 | |
4171 | impl<'a> StreamsSelectedBuilder<'a> { |
4172 | fn new(collection: &'a crate::StreamCollection) -> Self { |
4173 | skip_assert_initialized!(); |
4174 | Self { |
4175 | builder: MessageBuilder::new(), |
4176 | collection, |
4177 | streams: None, |
4178 | } |
4179 | } |
4180 | |
4181 | pub fn streams( |
4182 | self, |
4183 | streams: impl IntoIterator<Item = impl std::borrow::Borrow<crate::Stream>>, |
4184 | ) -> Self { |
4185 | Self { |
4186 | streams: Some( |
4187 | streams |
4188 | .into_iter() |
4189 | .map(|s| s.borrow().clone()) |
4190 | .collect::<Vec<_>>(), |
4191 | ), |
4192 | ..self |
4193 | } |
4194 | } |
4195 | |
4196 | pub fn streams_if( |
4197 | self, |
4198 | streams: impl IntoIterator<Item = impl std::borrow::Borrow<crate::Stream>>, |
4199 | predicate: bool, |
4200 | ) -> Self { |
4201 | if predicate { |
4202 | self.streams(streams) |
4203 | } else { |
4204 | self |
4205 | } |
4206 | } |
4207 | |
4208 | pub fn streams_if_some( |
4209 | self, |
4210 | streams: Option<impl IntoIterator<Item = impl std::borrow::Borrow<crate::Stream>>>, |
4211 | ) -> Self { |
4212 | if let Some(streams) = streams { |
4213 | self.streams(streams) |
4214 | } else { |
4215 | self |
4216 | } |
4217 | } |
4218 | |
4219 | pub fn streams_if_not_empty( |
4220 | self, |
4221 | streams: impl IntoIterator<Item = impl std::borrow::Borrow<crate::Stream>>, |
4222 | ) -> Self { |
4223 | let mut streams = streams.into_iter().peekable(); |
4224 | if streams.peek().is_some() { |
4225 | self.streams(streams) |
4226 | } else { |
4227 | self |
4228 | } |
4229 | } |
4230 | |
4231 | message_builder_generic_impl!(|s: &mut Self, src| { |
4232 | let msg = ffi::gst_message_new_streams_selected(src, s.collection.to_glib_none().0); |
4233 | if let Some(ref streams) = s.streams { |
4234 | for stream in streams { |
4235 | ffi::gst_message_streams_selected_add(msg, stream.to_glib_none().0); |
4236 | } |
4237 | } |
4238 | msg |
4239 | }); |
4240 | } |
4241 | |
4242 | #[must_use = "The builder must be built to be used" ] |
4243 | pub struct RedirectBuilder<'a> { |
4244 | builder: MessageBuilder<'a>, |
4245 | location: &'a str, |
4246 | tag_list: Option<&'a TagList>, |
4247 | entry_struct: Option<Structure>, |
4248 | #[allow (clippy::type_complexity)] |
4249 | entries: Option<&'a [(&'a str, Option<&'a TagList>, Option<&'a Structure>)]>, |
4250 | } |
4251 | |
4252 | impl<'a> RedirectBuilder<'a> { |
4253 | fn new(location: &'a str) -> Self { |
4254 | skip_assert_initialized!(); |
4255 | Self { |
4256 | builder: MessageBuilder::new(), |
4257 | location, |
4258 | tag_list: None, |
4259 | entry_struct: None, |
4260 | entries: None, |
4261 | } |
4262 | } |
4263 | |
4264 | pub fn tag_list(self, tag_list: &'a TagList) -> Self { |
4265 | Self { |
4266 | tag_list: Some(tag_list), |
4267 | ..self |
4268 | } |
4269 | } |
4270 | |
4271 | pub fn tag_list_if(self, tag_list: &'a TagList, predicate: bool) -> Self { |
4272 | if predicate { |
4273 | self.tag_list(tag_list) |
4274 | } else { |
4275 | self |
4276 | } |
4277 | } |
4278 | |
4279 | pub fn tag_list_if_some(self, tag_list: Option<&'a TagList>) -> Self { |
4280 | if let Some(tag_list) = tag_list { |
4281 | self.tag_list(tag_list) |
4282 | } else { |
4283 | self |
4284 | } |
4285 | } |
4286 | |
4287 | pub fn entry_struct(self, entry_struct: Structure) -> Self { |
4288 | Self { |
4289 | entry_struct: Some(entry_struct), |
4290 | ..self |
4291 | } |
4292 | } |
4293 | |
4294 | pub fn entry_struct_if(self, entry_struct: Structure, predicate: bool) -> Self { |
4295 | if predicate { |
4296 | self.entry_struct(entry_struct) |
4297 | } else { |
4298 | self |
4299 | } |
4300 | } |
4301 | |
4302 | pub fn entry_struct_if_some(self, entry_struct: Option<Structure>) -> Self { |
4303 | if let Some(entry_struct) = entry_struct { |
4304 | self.entry_struct(entry_struct) |
4305 | } else { |
4306 | self |
4307 | } |
4308 | } |
4309 | |
4310 | pub fn entries( |
4311 | self, |
4312 | entries: &'a [(&'a str, Option<&'a TagList>, Option<&'a Structure>)], |
4313 | ) -> Self { |
4314 | skip_assert_initialized!(); |
4315 | Self { |
4316 | entries: Some(entries), |
4317 | ..self |
4318 | } |
4319 | } |
4320 | |
4321 | #[allow (clippy::type_complexity)] |
4322 | pub fn entries_if( |
4323 | self, |
4324 | entries: &'a [(&'a str, Option<&'a TagList>, Option<&'a Structure>)], |
4325 | predicate: bool, |
4326 | ) -> Self { |
4327 | if predicate { |
4328 | self.entries(entries) |
4329 | } else { |
4330 | self |
4331 | } |
4332 | } |
4333 | |
4334 | #[allow (clippy::type_complexity)] |
4335 | pub fn entries_if_some( |
4336 | self, |
4337 | entries: Option<&'a [(&'a str, Option<&'a TagList>, Option<&'a Structure>)]>, |
4338 | ) -> Self { |
4339 | if let Some(entries) = entries { |
4340 | self.entries(entries) |
4341 | } else { |
4342 | self |
4343 | } |
4344 | } |
4345 | |
4346 | message_builder_generic_impl!(|s: &mut Self, src| { |
4347 | let entry_struct = s.entry_struct.take(); |
4348 | let entry_struct_ptr = if let Some(entry_struct) = entry_struct { |
4349 | entry_struct.into_glib_ptr() |
4350 | } else { |
4351 | ptr::null_mut() |
4352 | }; |
4353 | |
4354 | let msg = ffi::gst_message_new_redirect( |
4355 | src, |
4356 | s.location.to_glib_none().0, |
4357 | s.tag_list.to_glib_full(), |
4358 | entry_struct_ptr, |
4359 | ); |
4360 | if let Some(entries) = s.entries { |
4361 | for &(location, tag_list, entry_struct) in entries { |
4362 | let entry_struct = entry_struct.cloned(); |
4363 | let entry_struct_ptr = if let Some(entry_struct) = entry_struct { |
4364 | entry_struct.into_glib_ptr() |
4365 | } else { |
4366 | ptr::null_mut() |
4367 | }; |
4368 | ffi::gst_message_add_redirect_entry( |
4369 | msg, |
4370 | location.to_glib_none().0, |
4371 | tag_list.to_glib_full(), |
4372 | entry_struct_ptr, |
4373 | ); |
4374 | } |
4375 | } |
4376 | msg |
4377 | }); |
4378 | } |
4379 | |
4380 | #[cfg (feature = "v1_16" )] |
4381 | #[cfg_attr (docsrs, doc(cfg(feature = "v1_16" )))] |
4382 | #[must_use = "The builder must be built to be used" ] |
4383 | pub struct DeviceChangedBuilder<'a> { |
4384 | builder: MessageBuilder<'a>, |
4385 | device: &'a crate::Device, |
4386 | changed_device: &'a crate::Device, |
4387 | } |
4388 | |
4389 | #[cfg (feature = "v1_16" )] |
4390 | #[cfg_attr (docsrs, doc(cfg(feature = "v1_16" )))] |
4391 | impl<'a> DeviceChangedBuilder<'a> { |
4392 | fn new(device: &'a crate::Device, changed_device: &'a crate::Device) -> Self { |
4393 | skip_assert_initialized!(); |
4394 | Self { |
4395 | builder: MessageBuilder::new(), |
4396 | device, |
4397 | changed_device, |
4398 | } |
4399 | } |
4400 | |
4401 | message_builder_generic_impl!(|s: &mut Self, src| ffi::gst_message_new_device_changed( |
4402 | src, |
4403 | s.device.to_glib_none().0, |
4404 | s.changed_device.to_glib_none().0, |
4405 | )); |
4406 | } |
4407 | |
4408 | #[cfg (feature = "v1_18" )] |
4409 | #[cfg_attr (docsrs, doc(cfg(feature = "v1_18" )))] |
4410 | #[must_use = "The builder must be built to be used" ] |
4411 | pub struct InstantRateRequestBuilder<'a> { |
4412 | builder: MessageBuilder<'a>, |
4413 | rate_multiplier: f64, |
4414 | } |
4415 | |
4416 | #[cfg (feature = "v1_18" )] |
4417 | #[cfg_attr (docsrs, doc(cfg(feature = "v1_18" )))] |
4418 | impl<'a> InstantRateRequestBuilder<'a> { |
4419 | fn new(rate_multiplier: f64) -> Self { |
4420 | skip_assert_initialized!(); |
4421 | Self { |
4422 | builder: MessageBuilder::new(), |
4423 | rate_multiplier, |
4424 | } |
4425 | } |
4426 | |
4427 | message_builder_generic_impl!( |
4428 | |s: &mut Self, src| ffi::gst_message_new_instant_rate_request(src, s.rate_multiplier,) |
4429 | ); |
4430 | } |
4431 | |
4432 | #[cfg (test)] |
4433 | mod tests { |
4434 | use super::*; |
4435 | |
4436 | #[test ] |
4437 | fn test_simple() { |
4438 | crate::init().unwrap(); |
4439 | |
4440 | // Message without arguments |
4441 | let seqnum = Seqnum::next(); |
4442 | let eos_msg = Eos::builder().seqnum(seqnum).build(); |
4443 | match eos_msg.view() { |
4444 | MessageView::Eos(eos_msg) => { |
4445 | assert_eq!(eos_msg.seqnum(), seqnum); |
4446 | assert!(eos_msg.structure().is_none()); |
4447 | } |
4448 | _ => panic!("eos_msg.view() is not a MessageView::Eos(_)" ), |
4449 | } |
4450 | |
4451 | // Message with arguments |
4452 | let buffering_msg = Buffering::new(42); |
4453 | match buffering_msg.view() { |
4454 | MessageView::Buffering(buffering_msg) => { |
4455 | assert_eq!(buffering_msg.percent(), 42); |
4456 | } |
4457 | _ => panic!("buffering_msg.view() is not a MessageView::Buffering(_)" ), |
4458 | } |
4459 | } |
4460 | |
4461 | #[test ] |
4462 | #[allow (deprecated)] |
4463 | fn test_other_fields() { |
4464 | crate::init().unwrap(); |
4465 | |
4466 | let seqnum = Seqnum::next(); |
4467 | let eos_msg = Eos::builder() |
4468 | .other_fields(&[("extra-field" , &true)]) |
4469 | .seqnum(seqnum) |
4470 | .build(); |
4471 | match eos_msg.view() { |
4472 | MessageView::Eos(eos_msg) => { |
4473 | assert_eq!(eos_msg.seqnum(), seqnum); |
4474 | if let Some(other_fields) = eos_msg.structure() { |
4475 | assert!(other_fields.has_field("extra-field" )); |
4476 | } |
4477 | } |
4478 | _ => panic!("eos_msg.view() is not a MessageView::Eos(_)" ), |
4479 | } |
4480 | |
4481 | let buffering_msg = Buffering::builder(42) |
4482 | .other_field("extra-field" , true) |
4483 | .build(); |
4484 | match buffering_msg.view() { |
4485 | MessageView::Buffering(buffering_msg) => { |
4486 | assert_eq!(buffering_msg.percent(), 42); |
4487 | if let Some(other_fields) = buffering_msg.structure() { |
4488 | assert!(other_fields.has_field("extra-field" )); |
4489 | } |
4490 | } |
4491 | _ => panic!("buffering_msg.view() is not a MessageView::Buffering(_)" ), |
4492 | } |
4493 | } |
4494 | |
4495 | #[test ] |
4496 | fn test_get_seqnum_valid() { |
4497 | crate::init().unwrap(); |
4498 | |
4499 | let msg = StreamStart::new(); |
4500 | let seqnum = Seqnum( |
4501 | NonZeroU32::new(unsafe { ffi::gst_message_get_seqnum(msg.as_mut_ptr()) }).unwrap(), |
4502 | ); |
4503 | |
4504 | match msg.view() { |
4505 | MessageView::StreamStart(stream_start) => assert_eq!(seqnum, stream_start.seqnum()), |
4506 | _ => panic!(), |
4507 | } |
4508 | } |
4509 | |
4510 | #[test ] |
4511 | fn test_get_seqnum_invalid() { |
4512 | crate::init().unwrap(); |
4513 | |
4514 | let msg = StreamStart::new(); |
4515 | let seqnum_init = msg.seqnum(); |
4516 | |
4517 | // Invalid the seqnum |
4518 | unsafe { |
4519 | (*msg.as_mut_ptr()).seqnum = ffi::GST_SEQNUM_INVALID as u32; |
4520 | assert_eq!(0, (*msg.as_ptr()).seqnum); |
4521 | }; |
4522 | |
4523 | match msg.view() { |
4524 | MessageView::StreamStart(stream_start) => { |
4525 | // get_seqnum is expected to return a new Seqnum, |
4526 | // further in the sequence than the last known seqnum. |
4527 | assert!(seqnum_init < stream_start.seqnum()); |
4528 | } |
4529 | _ => panic!(), |
4530 | } |
4531 | } |
4532 | } |
4533 | |