Skip to main content

servo_media_gstreamer_render/
lib.rs

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