servo_media_gstreamer_render/
lib.rs

1//! `Render` is a trait to be used by GStreamer's backend player
2//!
3//! The purpose of this trait is to provide different accelerated
4//! video renders.
5//!
6//! By default, the player will use a rendering mechanism based on
7//! mapping the raw video into CPU memory, but it might be other
8//! rendering mechanism. The main target for this trait are
9//! OpenGL-based render mechanisms.
10//!
11//! Each platform (Unix, MacOS, Windows) might offer an implementation
12//! of this trait, so the player could setup a proper GStreamer
13//! pipeline, and handle the produced buffers.
14//!
15
16pub trait Render {
17    /// Returns `True` if the render implementation uses any version
18    /// or flavor of OpenGL
19    fn is_gl(&self) -> bool;
20
21    /// Returns the Player's `Frame` to be consumed by the API user.
22    ///
23    /// The implementation of this method will map the `sample`'s
24    /// buffer to the rendering appropriate structure. In the case of
25    /// OpenGL-based renders, the `Frame`, instead of the raw data,
26    /// will transfer the texture ID.
27    ///
28    /// # Arguments
29    ///
30    /// * `sample` -  the GStreamer sample with the buffer to map
31    fn build_frame(&self, sample: gst::Sample) -> Result<sm_player::video::VideoFrame, ()>;
32
33    /// Sets the proper *video-sink* to GStreamer's `pipeline`, this
34    /// video sink is simply a decorator of the passed `appsink`.
35    ///
36    /// # Arguments
37    ///
38    /// * `appsink` - the appsink GStreamer element to decorate
39    /// * `pipeline` - the GStreamer pipeline to set the video sink
40    fn build_video_sink(
41        &self,
42        appsink: &gst::Element,
43        pipeline: &gst::Element,
44    ) -> Result<(), sm_player::PlayerError>;
45}