Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/video/gif
diff options
context:
space:
mode:
authorSebastian Dröge <sebastian@centricular.com>2020-11-15 16:50:12 +0300
committerSebastian Dröge <sebastian@centricular.com>2020-11-15 19:50:31 +0300
commit717477fd36f00c5f1b8dbb64ec4dadc602d5fc22 (patch)
tree7387cf91d55c71afa125a6891579045fa6de5197 /video/gif
parentb021a8bf100bbd7bbb35c28a7fc9fff78afad28f (diff)
video: Update for subclassing API changes
Diffstat (limited to 'video/gif')
-rw-r--r--video/gif/src/gifenc/imp.rs (renamed from video/gif/src/gifenc.rs)38
-rw-r--r--video/gif/src/gifenc/mod.rs29
-rw-r--r--video/gif/src/lib.rs1
3 files changed, 43 insertions, 25 deletions
diff --git a/video/gif/src/gifenc.rs b/video/gif/src/gifenc/imp.rs
index 7d0ec9919..3d0c56e3b 100644
--- a/video/gif/src/gifenc.rs
+++ b/video/gif/src/gifenc/imp.rs
@@ -12,7 +12,6 @@ use glib::subclass::prelude::*;
use gst::subclass::prelude::*;
use gst_video::prelude::*;
use gst_video::subclass::prelude::*;
-use gstreamer_video as gst_video;
use once_cell::sync::Lazy;
use std::{
io,
@@ -29,6 +28,7 @@ const DEFAULT_REPEAT: i32 = 0;
struct CacheBuffer {
buffer: AtomicRefCell<Vec<u8>>,
}
+
impl CacheBuffer {
pub fn new() -> Self {
Self {
@@ -47,6 +47,7 @@ impl CacheBuffer {
std::mem::replace(&mut *buffer, Vec::new())
}
}
+
/// Writer for a CacheBuffer instance. This class is passed to the gif::Encoder.
/// Everything written to the CacheBufferWriter is stored in the underlying CacheBuffer.
struct CacheBufferWriter {
@@ -98,6 +99,7 @@ struct State {
last_actual_pts: gst::ClockTime,
context: Option<gif::Encoder<CacheBufferWriter>>,
}
+
impl State {
pub fn new(video_info: gst_video::VideoInfo) -> Self {
Self {
@@ -130,7 +132,7 @@ impl State {
}
}
-struct GifEnc {
+pub struct GifEnc {
state: AtomicRefCell<Option<State>>,
settings: Mutex<Settings>,
}
@@ -141,6 +143,7 @@ static CAT: Lazy<gst::DebugCategory> = Lazy::new(|| {
impl ObjectSubclass for GifEnc {
const NAME: &'static str = "GifEnc";
+ type Type = super::GifEnc;
type ParentType = gst_video::VideoEncoder;
type Instance = gst::subclass::ElementInstanceStruct<Self>;
type Class = subclass::simple::ClassStruct<Self>;
@@ -154,7 +157,7 @@ impl ObjectSubclass for GifEnc {
}
}
- fn class_init(klass: &mut subclass::simple::ClassStruct<Self>) {
+ fn class_init(klass: &mut Self::Class) {
klass.set_metadata(
"GIF encoder",
"Encoder/Video",
@@ -211,7 +214,7 @@ impl ObjectSubclass for GifEnc {
}
impl ObjectImpl for GifEnc {
- fn set_property(&self, _obj: &glib::Object, id: usize, value: &glib::Value) {
+ fn set_property(&self, _obj: &Self::Type, id: usize, value: &glib::Value) {
let prop = &PROPERTIES[id];
match *prop {
@@ -223,7 +226,7 @@ impl ObjectImpl for GifEnc {
}
}
- fn get_property(&self, _obj: &glib::Object, id: usize) -> Result<glib::Value, ()> {
+ fn get_property(&self, _obj: &Self::Type, id: usize) -> Result<glib::Value, ()> {
let prop = &PROPERTIES[id];
match *prop {
@@ -239,14 +242,14 @@ impl ObjectImpl for GifEnc {
impl ElementImpl for GifEnc {}
impl VideoEncoderImpl for GifEnc {
- fn stop(&self, _element: &gst_video::VideoEncoder) -> Result<(), gst::ErrorMessage> {
+ fn stop(&self, _element: &Self::Type) -> Result<(), gst::ErrorMessage> {
*self.state.borrow_mut() = None;
Ok(())
}
fn set_format(
&self,
- element: &gst_video::VideoEncoder,
+ element: &Self::Type,
state: &gst_video::VideoCodecState<'static, gst_video::video_codec_state::Readable>,
) -> Result<(), gst::LoggableError> {
self.flush_encoder(element)
@@ -272,16 +275,13 @@ impl VideoEncoderImpl for GifEnc {
self.parent_set_format(element, state)
}
- fn finish(
- &self,
- element: &gst_video::VideoEncoder,
- ) -> Result<gst::FlowSuccess, gst::FlowError> {
+ fn finish(&self, element: &Self::Type) -> Result<gst::FlowSuccess, gst::FlowError> {
self.flush_encoder(element)
}
fn handle_frame(
&self,
- element: &gst_video::VideoEncoder,
+ element: &Self::Type,
mut frame: gst_video::VideoCodecFrame,
) -> Result<gst::FlowSuccess, gst::FlowError> {
let mut state_guard = self.state.borrow_mut();
@@ -388,10 +388,7 @@ impl VideoEncoderImpl for GifEnc {
}
impl GifEnc {
- fn flush_encoder(
- &self,
- element: &gst_video::VideoEncoder,
- ) -> Result<gst::FlowSuccess, gst::FlowError> {
+ fn flush_encoder(&self, element: &super::GifEnc) -> Result<gst::FlowSuccess, gst::FlowError> {
gst_debug!(CAT, obj: element, "Flushing");
let trailer_buffer = self.state.borrow_mut().as_mut().map(|state| {
@@ -440,12 +437,3 @@ fn get_tightly_packed_framebuffer(frame: &gst_video::VideoFrameRef<&gst::BufferR
raw_frame
}
-
-pub fn register(plugin: &gst::Plugin) -> Result<(), glib::BoolError> {
- gst::Element::register(
- Some(plugin),
- "gifenc",
- gst::Rank::Primary,
- GifEnc::get_type(),
- )
-}
diff --git a/video/gif/src/gifenc/mod.rs b/video/gif/src/gifenc/mod.rs
new file mode 100644
index 000000000..40543d41d
--- /dev/null
+++ b/video/gif/src/gifenc/mod.rs
@@ -0,0 +1,29 @@
+// Copyright (C) 2020 Markus Ebner <info@ebner-markus.de>
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+use glib::prelude::*;
+
+mod imp;
+
+glib_wrapper! {
+ pub struct GifEnc(ObjectSubclass<imp::GifEnc>) @extends gst_video::VideoEncoder, gst::Element, gst::Object;
+}
+
+// GStreamer elements need to be thread-safe. For the private implementation this is automatically
+// enforced but for the public wrapper type we need to specify this manually.
+unsafe impl Send for GifEnc {}
+unsafe impl Sync for GifEnc {}
+
+pub fn register(plugin: &gst::Plugin) -> Result<(), glib::BoolError> {
+ gst::Element::register(
+ Some(plugin),
+ "gifenc",
+ gst::Rank::Primary,
+ GifEnc::static_type(),
+ )
+}
diff --git a/video/gif/src/lib.rs b/video/gif/src/lib.rs
index 64cb03308..7b14fbd0c 100644
--- a/video/gif/src/lib.rs
+++ b/video/gif/src/lib.rs
@@ -10,6 +10,7 @@
extern crate glib;
#[macro_use]
extern crate gstreamer as gst;
+extern crate gstreamer_video as gst_video;
mod gifenc;