Commit f3c8dfeb authored by Thiago Sousa Santos's avatar Thiago Sousa Santos Committed by Sebastian Dröge

EncodingProfile: remove setters and constructors, use builders

Provide builders for the EncodingProfile so that the created objects are
imutable and can have the Send and Sync traits
parent 861f052c
......@@ -149,6 +149,14 @@ status = "generate"
name = "is_equal"
ignore = true
# Ignore all setters, making it imutable. A builder will be provided.
[[object.function]]
name = "new"
ignore = true
[[object.function]]
pattern = "set_.*"
ignore = true
[[object.function]]
name = "copy"
[object.function.return]
......@@ -168,10 +176,14 @@ status = "generate"
name = "GstPbutils.EncodingContainerProfile"
status = "generate"
# Make it imutable, only able to be constructed for a builder
[[object.function]]
name = "new"
ignore = true
[[object.function]]
name = "add_profile"
[object.function.return]
bool_return_is_error = "Failed to add profile"
ignore = true
[[object]]
name = "GstPbutils.EncodingTarget"
......@@ -199,8 +211,23 @@ status = "generate"
name = "GstPbutils.EncodingAudioProfile"
status = "generate"
trait = false
# Ignore all setters, making it imutable. A builder will be provided.
[[object.function]]
name = "new"
ignore = true
[[object.function]]
pattern = "set_.*"
ignore = true
[[object]]
name = "GstPbutils.EncodingVideoProfile"
status = "generate"
trait = false
# Ignore all setters, making it imutable. A builder will be provided.
[[object.function]]
name = "new"
ignore = true
[[object.function]]
pattern = "set_.*"
ignore = true
......@@ -3,6 +3,7 @@ extern crate gstreamer as gst;
use gst::prelude::*;
extern crate gstreamer_pbutils as pbutils;
use pbutils::EncodingProfileBuilder;
extern crate glib;
......
// This file was generated by gir (https://github.com/gtk-rs/gir @ fe7a6ff+)
// from gir-files (https://github.com/gtk-rs/gir-files @ ???)
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT
use EncodingProfile;
......@@ -7,7 +7,6 @@ use ffi;
use glib::translate::*;
use glib_ffi;
use gobject_ffi;
use gst;
use std::mem;
use std::ptr;
......@@ -19,18 +18,7 @@ glib_wrapper! {
}
}
impl EncodingAudioProfile {
pub fn new<'a, 'b, P: Into<Option<&'a str>>, Q: Into<Option<&'b gst::Caps>>>(format: &gst::Caps, preset: P, restriction: Q, presence: u32) -> EncodingAudioProfile {
assert_initialized_main_thread!();
let preset = preset.into();
let preset = preset.to_glib_none();
let restriction = restriction.into();
let restriction = restriction.to_glib_none();
unsafe {
from_glib_full(ffi::gst_encoding_audio_profile_new(format.to_glib_none().0, preset.0, restriction.0, presence))
}
}
}
impl EncodingAudioProfile {}
unsafe impl Send for EncodingAudioProfile {}
unsafe impl Sync for EncodingAudioProfile {}
// This file was generated by gir (https://github.com/gtk-rs/gir @ fe7a6ff+)
// from gir-files (https://github.com/gtk-rs/gir-files @ ???)
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT
use EncodingProfile;
use ffi;
use glib;
use glib::object::IsA;
use glib::translate::*;
use glib_ffi;
use gobject_ffi;
use gst;
use std::mem;
use std::ptr;
......@@ -21,39 +19,16 @@ glib_wrapper! {
}
}
impl EncodingContainerProfile {
pub fn new<'a, 'b, 'c, P: Into<Option<&'a str>>, Q: Into<Option<&'b str>>, R: Into<Option<&'c str>>>(name: P, description: Q, format: &gst::Caps, preset: R) -> EncodingContainerProfile {
assert_initialized_main_thread!();
let name = name.into();
let name = name.to_glib_none();
let description = description.into();
let description = description.to_glib_none();
let preset = preset.into();
let preset = preset.to_glib_none();
unsafe {
from_glib_full(ffi::gst_encoding_container_profile_new(name.0, description.0, format.to_glib_none().0, preset.0))
}
}
}
unsafe impl Send for EncodingContainerProfile {}
unsafe impl Sync for EncodingContainerProfile {}
pub trait EncodingContainerProfileExt {
fn add_profile<P: IsA<EncodingProfile>>(&self, profile: &P) -> Result<(), glib::error::BoolError>;
fn contains_profile<P: IsA<EncodingProfile>>(&self, profile: &P) -> bool;
fn get_profiles(&self) -> Vec<EncodingProfile>;
}
impl<O: IsA<EncodingContainerProfile>> EncodingContainerProfileExt for O {
fn add_profile<P: IsA<EncodingProfile>>(&self, profile: &P) -> Result<(), glib::error::BoolError> {
unsafe {
glib::error::BoolError::from_glib(ffi::gst_encoding_container_profile_add_profile(self.to_glib_none().0, profile.to_glib_full()), "Failed to add profile")
}
}
fn contains_profile<P: IsA<EncodingProfile>>(&self, profile: &P) -> bool {
unsafe {
from_glib(ffi::gst_encoding_container_profile_contains_profile(self.to_glib_none().0, profile.to_glib_none().0))
......
// This file was generated by gir (https://github.com/gtk-rs/gir @ fe7a6ff+)
// from gir-files (https://github.com/gtk-rs/gir-files @ ???)
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT
use DiscovererInfo;
......@@ -78,24 +78,6 @@ pub trait EncodingProfileExt {
fn is_enabled(&self) -> bool;
fn set_allow_dynamic_output(&self, allow_dynamic_output: bool);
fn set_description<'a, P: Into<Option<&'a str>>>(&self, description: P);
fn set_enabled(&self, enabled: bool);
fn set_format(&self, format: &gst::Caps);
fn set_name<'a, P: Into<Option<&'a str>>>(&self, name: P);
fn set_presence(&self, presence: u32);
fn set_preset<'a, P: Into<Option<&'a str>>>(&self, preset: P);
fn set_preset_name<'a, P: Into<Option<&'a str>>>(&self, preset_name: P);
fn set_restriction<'a, P: Into<Option<&'a gst::Caps>>>(&self, restriction: P);
fn get_property_restriction_caps(&self) -> Option<gst::Caps>;
fn set_property_restriction_caps(&self, restriction_caps: Option<&gst::Caps>);
......@@ -182,70 +164,6 @@ impl<O: IsA<EncodingProfile> + IsA<glib::object::Object>> EncodingProfileExt for
}
}
fn set_allow_dynamic_output(&self, allow_dynamic_output: bool) {
unsafe {
ffi::gst_encoding_profile_set_allow_dynamic_output(self.to_glib_none().0, allow_dynamic_output.to_glib());
}
}
fn set_description<'a, P: Into<Option<&'a str>>>(&self, description: P) {
let description = description.into();
let description = description.to_glib_none();
unsafe {
ffi::gst_encoding_profile_set_description(self.to_glib_none().0, description.0);
}
}
fn set_enabled(&self, enabled: bool) {
unsafe {
ffi::gst_encoding_profile_set_enabled(self.to_glib_none().0, enabled.to_glib());
}
}
fn set_format(&self, format: &gst::Caps) {
unsafe {
ffi::gst_encoding_profile_set_format(self.to_glib_none().0, format.to_glib_none().0);
}
}
fn set_name<'a, P: Into<Option<&'a str>>>(&self, name: P) {
let name = name.into();
let name = name.to_glib_none();
unsafe {
ffi::gst_encoding_profile_set_name(self.to_glib_none().0, name.0);
}
}
fn set_presence(&self, presence: u32) {
unsafe {
ffi::gst_encoding_profile_set_presence(self.to_glib_none().0, presence);
}
}
fn set_preset<'a, P: Into<Option<&'a str>>>(&self, preset: P) {
let preset = preset.into();
let preset = preset.to_glib_none();
unsafe {
ffi::gst_encoding_profile_set_preset(self.to_glib_none().0, preset.0);
}
}
fn set_preset_name<'a, P: Into<Option<&'a str>>>(&self, preset_name: P) {
let preset_name = preset_name.into();
let preset_name = preset_name.to_glib_none();
unsafe {
ffi::gst_encoding_profile_set_preset_name(self.to_glib_none().0, preset_name.0);
}
}
fn set_restriction<'a, P: Into<Option<&'a gst::Caps>>>(&self, restriction: P) {
let restriction = restriction.into();
let restriction = restriction.to_glib_none();
unsafe {
ffi::gst_encoding_profile_set_restriction(self.to_glib_none().0, restriction.0);
}
}
fn get_property_restriction_caps(&self) -> Option<gst::Caps> {
unsafe {
let mut value = Value::from_type(<gst::Caps as StaticType>::static_type());
......@@ -271,7 +189,6 @@ impl<O: IsA<EncodingProfile> + IsA<glib::object::Object>> EncodingProfileExt for
unsafe extern "C" fn notify_restriction_caps_trampoline<P>(this: *mut ffi::GstEncodingProfile, _param_spec: glib_ffi::gpointer, f: glib_ffi::gpointer)
where P: IsA<EncodingProfile> {
callback_guard!();
let f: &&(Fn(&P) + Send + Sync + 'static) = transmute(f);
f(&EncodingProfile::from_glib_borrow(this).downcast_unchecked())
}
// This file was generated by gir (https://github.com/gtk-rs/gir @ fe7a6ff+)
// from gir-files (https://github.com/gtk-rs/gir-files @ ???)
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT
use EncodingProfile;
......
// This file was generated by gir (https://github.com/gtk-rs/gir @ fe7a6ff+)
// from gir-files (https://github.com/gtk-rs/gir-files @ ???)
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT
use EncodingProfile;
......@@ -7,7 +7,6 @@ use ffi;
use glib::translate::*;
use glib_ffi;
use gobject_ffi;
use gst;
use std::mem;
use std::ptr;
......@@ -20,17 +19,6 @@ glib_wrapper! {
}
impl EncodingVideoProfile {
pub fn new<'a, 'b, P: Into<Option<&'a str>>, Q: Into<Option<&'b gst::Caps>>>(format: &gst::Caps, preset: P, restriction: Q, presence: u32) -> EncodingVideoProfile {
assert_initialized_main_thread!();
let preset = preset.into();
let preset = preset.to_glib_none();
let restriction = restriction.into();
let restriction = restriction.to_glib_none();
unsafe {
from_glib_full(ffi::gst_encoding_video_profile_new(format.to_glib_none().0, preset.0, restriction.0, presence))
}
}
pub fn get_pass(&self) -> u32 {
unsafe {
ffi::gst_encoding_video_profile_get_pass(self.to_glib_none().0)
......@@ -42,18 +30,6 @@ impl EncodingVideoProfile {
from_glib(ffi::gst_encoding_video_profile_get_variableframerate(self.to_glib_none().0))
}
}
pub fn set_pass(&self, pass: u32) {
unsafe {
ffi::gst_encoding_video_profile_set_pass(self.to_glib_none().0, pass);
}
}
pub fn set_variableframerate(&self, variableframerate: bool) {
unsafe {
ffi::gst_encoding_video_profile_set_variableframerate(self.to_glib_none().0, variableframerate.to_glib());
}
}
}
unsafe impl Send for EncodingVideoProfile {}
......
use gst;
use std::error;
use std::fmt;
use auto::EncodingAudioProfile;
#[derive(Debug, Clone)]
pub struct EncodingAudioProfileBuilderError;
impl fmt::Display for EncodingAudioProfileBuilderError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "failed to build encoding audio profile")
}
}
impl error::Error for EncodingAudioProfileBuilderError {
fn description(&self) -> &str {
"invalid parameters to build encoding audio profile"
}
fn cause(&self) -> Option<&error::Error> {
None
}
}
pub struct EncodingAudioProfileBuilder<'a> {
format: Option<& 'a gst::Caps>,
preset: Option<& 'a str>,
restriction: Option<& 'a gst::Caps>,
presence: u32
}
impl<'a> EncodingAudioProfileBuilder<'a> {
pub fn new() -> Self {
EncodingAudioProfileBuilder {
format: None,
preset: None,
restriction: None,
presence: 0,
}
}
pub fn build(self) -> Result<EncodingAudioProfile, EncodingAudioProfileBuilderError> {
if self.format.is_none() {
return Err(EncodingAudioProfileBuilderError);
}
let profile = EncodingAudioProfile::new(
self.format.unwrap(), self.preset, self.restriction, self.presence);
Ok(profile)
}
pub fn format(self, format: & 'a gst::Caps) -> Self {
Self {
format: Some(format),
..self
}
}
pub fn restriction(self, restriction: & 'a gst::Caps) -> Self {
Self {
restriction: Some(restriction),
..self
}
}
pub fn preset(self, preset: & 'a str) -> Self {
Self {
preset: Some(preset),
..self
}
}
pub fn presence(self, presence: u32) -> Self {
Self {
presence: presence,
..self
}
}
}
use gst;
use std::error;
use std::fmt;
use auto::EncodingProfile;
use auto::EncodingContainerProfile;
use auto::EncodingContainerProfileExt;
use std::collections::LinkedList;
#[derive(Debug, Clone)]
pub struct EncodingContainerProfileBuilderError;
impl fmt::Display for EncodingContainerProfileBuilderError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "failed to build encoding video profile")
}
}
impl error::Error for EncodingContainerProfileBuilderError {
fn description(&self) -> &str {
"invalid parameters to build encoding container profile"
}
fn cause(&self) -> Option<&error::Error> {
None
}
}
pub struct EncodingContainerProfileBuilder<'a> {
name: Option<& 'a str>,
description: Option<& 'a str>,
format: Option<& 'a gst::Caps>,
preset: Option<& 'a str>,
profiles: LinkedList<& 'a EncodingProfile>
}
impl<'a> EncodingContainerProfileBuilder<'a> {
pub fn new() -> Self {
EncodingContainerProfileBuilder {
name: None,
description: None,
format: None,
preset: None,
profiles: LinkedList::new()
}
}
pub fn build(self) -> Result<EncodingContainerProfile, EncodingContainerProfileBuilderError> {
if self.format.is_none() {
return Err(EncodingContainerProfileBuilderError);
}
let container_profile = EncodingContainerProfile::new(
self.name, self.description, self.format.unwrap(), self.preset);
for profile in self.profiles {
container_profile.add_profile(profile).or_else(|_error| Err(EncodingContainerProfileBuilderError))?;
}
Ok(container_profile)
}
pub fn name(self, name: & 'a str) -> Self {
Self {
name: Some(name),
..self
}
}
pub fn description(self, description: & 'a str) -> Self {
Self {
description: Some(description),
..self
}
}
pub fn format(self, format: & 'a gst::Caps) -> Self {
Self {
format: Some(format),
..self
}
}
pub fn preset(self, preset: & 'a str) -> Self {
Self {
preset: Some(preset),
..self
}
}
pub fn add_profile(mut self, profile: & 'a EncodingProfile) -> Self {
self.profiles.push_back(profile);
self
}
}
This diff is collapsed.
use gst;
use std::error;
use std::fmt;
use auto::EncodingVideoProfile;
#[derive(Debug, Clone)]
pub struct EncodingVideoProfileBuilderError;
impl fmt::Display for EncodingVideoProfileBuilderError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "failed to build encoding video profile")
}
}
impl error::Error for EncodingVideoProfileBuilderError {
fn description(&self) -> &str {
"invalid parameters to build encoding video profile"
}
fn cause(&self) -> Option<&error::Error> {
None
}
}
pub struct EncodingVideoProfileBuilder<'a> {
format: Option<& 'a gst::Caps>,
preset: Option<& 'a str>,
restriction: Option<& 'a gst::Caps>,
presence: u32,
pass: u32,
variable_framerate: bool,
}
impl<'a> EncodingVideoProfileBuilder<'a> {
pub fn new() -> Self {
EncodingVideoProfileBuilder {
format: None,
preset: None,
restriction: None,
presence: 0,
pass: 0,
variable_framerate: false,
}
}
pub fn build(self) -> Result<EncodingVideoProfile, EncodingVideoProfileBuilderError> {
if self.format.is_none() {
return Err(EncodingVideoProfileBuilderError);
}
let profile = EncodingVideoProfile::new(
self.format.unwrap(), self.preset, self.restriction, self.presence);
profile.set_pass(self.pass);
profile.set_variableframerate(self.variable_framerate);
Ok(profile)
}
pub fn format(self, format: & 'a gst::Caps) -> Self {
Self {
format: Some(format),
..self
}
}
pub fn restriction(self, restriction: & 'a gst::Caps) -> Self {
Self {
restriction: Some(restriction),
..self
}
}
pub fn preset(self, preset: & 'a str) -> Self {
Self {
preset: Some(preset),
..self
}
}
pub fn presence(self, presence: u32) -> Self {
Self {
presence: presence,
..self
}
}
pub fn pass(self, pass: u32) -> Self {
Self {
pass: pass,
..self
}
}
pub fn variable_framerate(self, variable_framerate: bool) -> Self {
Self {
variable_framerate: variable_framerate,
..self
}
}
}
......@@ -55,14 +55,8 @@ pub mod discoverer_stream_info;
mod discoverer_video_info;
pub use discoverer_video_info::*;
mod encoding_container_profile;
pub use encoding_container_profile::*;
mod encoding_audio_profile;
pub use encoding_audio_profile::*;
mod encoding_video_profile;
pub use encoding_video_profile::*;
mod encoding_profile;
pub use encoding_profile::*;
// Re-export all the traits in a prelude module, so that applications
// can always "use gst::prelude::*" without getting conflicts
......@@ -74,9 +68,7 @@ pub mod prelude {
pub use discoverer_stream_info::*;
pub use discoverer_video_info::*;
pub use encoding_container_profile::*;
pub use encoding_video_profile::*;
pub use encoding_audio_profile::*;
pub use encoding_profile::*;
pub use auto::traits::*;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment