gstreamer_mse/
media_source_range.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use std::fmt;
4
5use crate::ffi;
6
7glib::wrapper! {
8    /// A structure describing a simplified version of the TimeRanges concept in the
9    /// HTML specification, only representing a single `start` and `end` time.
10    ///
11    /// [Specification](https://html.spec.whatwg.org/multipage/media.html`timeranges`)
12    #[doc(alias = "GstMediaSourceRange")]
13    pub struct MediaSourceRange(BoxedInline<ffi::GstMediaSourceRange>);
14
15    match fn {}
16}
17
18impl MediaSourceRange {
19    pub fn new(start: gst::ClockTime, end: gst::ClockTime) -> Self {
20        skip_assert_initialized!();
21
22        let inner = ffi::GstMediaSourceRange {
23            start: start.nseconds(),
24            end: end.nseconds(),
25        };
26
27        Self { inner }
28    }
29
30    pub fn start(&self) -> gst::ClockTime {
31        gst::ClockTime::from_nseconds(self.inner.start)
32    }
33
34    pub fn set_start(&mut self, start: gst::ClockTime) {
35        self.inner.start = start.nseconds();
36    }
37
38    pub fn end(&self) -> gst::ClockTime {
39        gst::ClockTime::from_nseconds(self.inner.end)
40    }
41
42    pub fn set_end(&mut self, end: gst::ClockTime) {
43        self.inner.end = end.nseconds();
44    }
45}
46
47unsafe impl Send for MediaSourceRange {}
48unsafe impl Sync for MediaSourceRange {}
49
50impl PartialEq for MediaSourceRange {
51    fn eq(&self, other: &Self) -> bool {
52        self.inner.start == other.inner.start && self.inner.end == other.inner.end
53    }
54}
55
56impl Eq for MediaSourceRange {}
57
58impl fmt::Debug for MediaSourceRange {
59    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
60        f.debug_struct("MediaSourceRange")
61            .field("start", &self.start())
62            .field("end", &self.end())
63            .finish()
64    }
65}