fix(iced-video): Fix the very high ram usage
feat(playback): add GstPlayFlags for playbin and playbin3
This commit is contained in:
82
gst/src/plugins/playback/playbin.rs
Normal file
82
gst/src/plugins/playback/playbin.rs
Normal file
@@ -0,0 +1,82 @@
|
||||
use crate::priv_prelude::*;
|
||||
|
||||
wrap_gst!(Playbin, gstreamer::Element);
|
||||
parent_child!(Element, Playbin);
|
||||
parent_child!(Pipeline, Playbin, downcast);
|
||||
parent_child!(Bin, Playbin, downcast);
|
||||
|
||||
impl Drop for Playbin {
|
||||
fn drop(&mut self) {
|
||||
self.set_state(gstreamer::State::Null).ok();
|
||||
}
|
||||
}
|
||||
|
||||
impl Playbin {
|
||||
pub fn new(name: impl AsRef<str>) -> Result<Self> {
|
||||
gstreamer::ElementFactory::make("playbin3")
|
||||
.name(name.as_ref())
|
||||
.build()
|
||||
.map(|element| Playbin { inner: element })
|
||||
.change_context(Error)
|
||||
}
|
||||
|
||||
pub fn with_uri(self, uri: impl AsRef<str>) -> Self {
|
||||
self.inner.set_property("uri", uri.as_ref());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_buffer_duration(self, duration: impl Into<Option<core::time::Duration>>) -> Self {
|
||||
let duration = match duration.into() {
|
||||
Some(dur) => dur.as_secs() as i64,
|
||||
None => -1,
|
||||
};
|
||||
self.inner.set_property("buffer-duration", duration);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_buffer_size(self, size: impl Into<Option<u32>>) -> Self {
|
||||
let size = match size.into() {
|
||||
Some(size) => size as i32,
|
||||
None => -1,
|
||||
};
|
||||
self.inner.set_property("buffer-size", size);
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the maximum size of the ring buffer in bytes.
|
||||
pub fn with_ring_buffer_max_size(self, size: u64) -> Self {
|
||||
self.inner.set_property("ring-buffer-max-size", size);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_video_sink(self, video_sink: &impl ChildOf<Element>) -> Self {
|
||||
self.inner
|
||||
.set_property("video-sink", &video_sink.upcast_ref().inner);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_text_sink(self, text_sink: &impl ChildOf<Element>) -> Self {
|
||||
self.inner
|
||||
.set_property("text-sink", &text_sink.upcast_ref().inner);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_audio_sink(self, audio_sink: &impl ChildOf<Element>) -> Self {
|
||||
self.inner
|
||||
.set_property("audio-sink", &audio_sink.upcast_ref().inner);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn set_volume(&self, volume: f64) {
|
||||
self.inner.set_property("volume", volume.clamp(1.0, 100.0))
|
||||
}
|
||||
|
||||
pub fn get_volume(&self) -> f64 {
|
||||
self.inner.property::<f64>("volume")
|
||||
}
|
||||
|
||||
pub fn with_flags(self, flags: playback::PlayFlags) -> Self {
|
||||
self.inner.set_property("flags", flags);
|
||||
self
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user