Run manual code through rustfmt

This commit is contained in:
Sebastian Dröge 2017-07-11 00:33:24 +03:00
parent abe4248a96
commit 4c5aa49fa2
10 changed files with 460 additions and 173 deletions

View file

@ -75,7 +75,10 @@ fn main() {
}
});
assert_ne!(pipeline.set_state(gst::State::Playing), gst::StateChangeReturn::Failure);
assert_ne!(
pipeline.set_state(gst::State::Playing),
gst::StateChangeReturn::Failure
);
let bus = pipeline.get_bus().unwrap();
@ -88,17 +91,29 @@ fn main() {
match msg.view() {
MessageView::Eos => break,
MessageView::Error(err) => {
println!("Error from {}: {} ({:?})", msg.get_src().get_path_string(),
err.get_error(), err.get_debug());
println!(
"Error from {}: {} ({:?})",
msg.get_src().get_path_string(),
err.get_error(),
err.get_debug()
);
break;
},
}
MessageView::StateChanged(s) => {
println!("State changed from {}: {:?} -> {:?} ({:?})", msg.get_src().get_path_string(),
s.get_old(), s.get_current(), s.get_pending());
},
println!(
"State changed from {}: {:?} -> {:?} ({:?})",
msg.get_src().get_path_string(),
s.get_old(),
s.get_current(),
s.get_pending()
);
}
_ => (),
}
}
assert_ne!(pipeline.set_state(gst::State::Null), gst::StateChangeReturn::Failure);
assert_ne!(
pipeline.set_state(gst::State::Null),
gst::StateChangeReturn::Failure
);
}

View file

@ -21,10 +21,14 @@ fn main() {
match msg.view() {
MessageView::Eos => break,
MessageView::Error(err) => {
println!("Error from {}: {} ({:?})", msg.get_src().get_path_string(),
err.get_error(), err.get_debug());
println!(
"Error from {}: {} ({:?})",
msg.get_src().get_path_string(),
err.get_error(),
err.get_debug()
);
break;
},
}
_ => (),
}
}

View file

@ -19,16 +19,18 @@ fn main() {
assert_ne!(ret, gst::StateChangeReturn::Failure);
bus.add_signal_watch();
bus.connect_message(|_, msg| {
match msg.view() {
bus.connect_message(|_, msg| match msg.view() {
MessageView::Eos => gtk::main_quit(),
MessageView::Error(err) => {
println!("Error from {}: {} ({:?})", msg.get_src().get_path_string(),
err.get_error(), err.get_debug());
println!(
"Error from {}: {} ({:?})",
msg.get_src().get_path_string(),
err.get_error(),
err.get_debug()
);
gtk::main_quit();
},
_ => (),
}
_ => (),
});
gtk::main();

View file

@ -24,7 +24,8 @@ impl<O: IsA<Bin>> BinExtManual for O {
fn add_many<E: IsA<Element>>(&self, elements: &[&E]) -> Result<(), glib::BoolError> {
for e in elements {
unsafe {
let ret: bool = from_glib(ffi::gst_bin_add(self.to_glib_none().0, e.to_glib_none().0));
let ret: bool =
from_glib(ffi::gst_bin_add(self.to_glib_none().0, e.to_glib_none().0));
if !ret {
return Err(glib::BoolError("Failed to add elements"));
}
@ -37,7 +38,10 @@ impl<O: IsA<Bin>> BinExtManual for O {
fn remove_many<E: IsA<Element>>(&self, elements: &[&E]) -> Result<(), glib::BoolError> {
for e in elements {
unsafe {
let ret: bool = from_glib(ffi::gst_bin_remove(self.to_glib_none().0, e.to_glib_none().0));
let ret: bool = from_glib(ffi::gst_bin_remove(
self.to_glib_none().0,
e.to_glib_none().0,
));
if !ret {
return Err(glib::BoolError("Failed to add elements"));
}

View file

@ -65,15 +65,17 @@ impl CapsRef {
pub fn set_simple(&mut self, values: &[(&str, &glib::Value)]) {
for &(name, ref value) in values {
unsafe {
ffi::gst_caps_set_value(self.as_mut_ptr(), name.to_glib_none().0, value.to_glib_none().0);
ffi::gst_caps_set_value(
self.as_mut_ptr(),
name.to_glib_none().0,
value.to_glib_none().0,
);
}
}
}
pub fn to_string(&self) -> String {
unsafe {
from_glib_full(ffi::gst_caps_to_string(self.as_ptr()))
}
unsafe { from_glib_full(ffi::gst_caps_to_string(self.as_ptr())) }
}
pub fn get_structure(&self, idx: u32) -> Option<&StructureRef> {
@ -103,9 +105,7 @@ impl CapsRef {
}
pub fn append_structure(&mut self, structure: Structure) {
unsafe {
ffi::gst_caps_append_structure(self.as_mut_ptr(), structure.into_ptr())
}
unsafe { ffi::gst_caps_append_structure(self.as_mut_ptr(), structure.into_ptr()) }
}
pub fn get_size(&self) -> u32 {
@ -125,9 +125,7 @@ impl CapsRef {
impl glib::types::StaticType for GstRc<CapsRef> {
fn static_type() -> glib::types::Type {
unsafe {
from_glib(ffi::gst_caps_get_type())
}
unsafe { from_glib(ffi::gst_caps_get_type()) }
}
}

View file

@ -18,7 +18,10 @@ impl Element {
pub fn link_many<E: IsA<Element>>(elements: &[&E]) -> Result<(), glib::BoolError> {
for (e1, e2) in elements.iter().zip(elements.iter().skip(1)) {
unsafe {
let ret: bool = from_glib(ffi::gst_element_link(e1.to_glib_none().0, e2.to_glib_none().0));
let ret: bool = from_glib(ffi::gst_element_link(
e1.to_glib_none().0,
e2.to_glib_none().0,
));
if !ret {
return Err(glib::BoolError("Failed to link elements"));
}

View file

@ -36,17 +36,7 @@ macro_rules! skip_assert_initialized {
)
}
pub use glib::{
Cast,
Continue,
Error,
IsA,
StaticType,
ToValue,
Type,
TypedValue,
Value,
};
pub use glib::{Cast, Continue, Error, IsA, StaticType, ToValue, Type, TypedValue, Value};
mod auto;
pub use auto::*;
@ -72,7 +62,11 @@ use std::ptr;
pub fn init() -> Result<(), glib::Error> {
unsafe {
let mut error = ptr::null_mut();
if from_glib(ffi::gst_init_check(ptr::null_mut(), ptr::null_mut(), &mut error)) {
if from_glib(ffi::gst_init_check(
ptr::null_mut(),
ptr::null_mut(),
&mut error,
)) {
Ok(())
} else {
Err(from_glib_full(error))

View file

@ -31,15 +31,11 @@ unsafe impl MiniObject for MessageRef {
impl MessageRef {
pub fn get_src(&self) -> Object {
unsafe {
from_glib_none((*self.as_ptr()).src)
}
unsafe { from_glib_none((*self.as_ptr()).src) }
}
pub fn get_seqnum(&self) -> u32 {
unsafe {
ffi::gst_message_get_seqnum(self.as_mut_ptr())
}
unsafe { ffi::gst_message_get_seqnum(self.as_mut_ptr()) }
}
pub fn get_structure(&self) -> &StructureRef {
@ -132,9 +128,7 @@ impl MessageRef {
impl glib::types::StaticType for GstRc<MessageRef> {
fn static_type() -> glib::types::Type {
unsafe {
from_glib(ffi::gst_message_get_type())
}
unsafe { from_glib(ffi::gst_message_get_type()) }
}
}
@ -316,7 +310,13 @@ impl<'a> Buffering<'a> {
let mut avg_out = mem::uninitialized();
let mut buffering_left = mem::uninitialized();
ffi::gst_message_parse_buffering_stats(self.0.as_mut_ptr(), &mut mode, &mut avg_in, &mut avg_out, &mut buffering_left);
ffi::gst_message_parse_buffering_stats(
self.0.as_mut_ptr(),
&mut mode,
&mut avg_in,
&mut avg_out,
&mut buffering_left,
);
(from_glib(mode), avg_in, avg_out, buffering_left)
}
@ -329,7 +329,12 @@ impl<'a> StateChanged<'a> {
unsafe {
let mut state = mem::uninitialized();
ffi::gst_message_parse_state_changed(self.0.as_mut_ptr(), &mut state, ptr::null_mut(), ptr::null_mut());
ffi::gst_message_parse_state_changed(
self.0.as_mut_ptr(),
&mut state,
ptr::null_mut(),
ptr::null_mut(),
);
from_glib(state)
}
@ -339,7 +344,12 @@ impl<'a> StateChanged<'a> {
unsafe {
let mut state = mem::uninitialized();
ffi::gst_message_parse_state_changed(self.0.as_mut_ptr(), ptr::null_mut(), &mut state, ptr::null_mut());
ffi::gst_message_parse_state_changed(
self.0.as_mut_ptr(),
ptr::null_mut(),
&mut state,
ptr::null_mut(),
);
from_glib(state)
}
@ -349,7 +359,12 @@ impl<'a> StateChanged<'a> {
unsafe {
let mut state = mem::uninitialized();
ffi::gst_message_parse_state_changed(self.0.as_mut_ptr(), ptr::null_mut(), ptr::null_mut(), &mut state);
ffi::gst_message_parse_state_changed(
self.0.as_mut_ptr(),
ptr::null_mut(),
ptr::null_mut(),
&mut state,
);
from_glib(state)
}
@ -368,9 +383,26 @@ impl<'a> StepDone<'a> {
let mut duration = mem::uninitialized();
let mut eos = mem::uninitialized();
ffi::gst_message_parse_step_done(self.0.as_mut_ptr(), &mut format, &mut amount, &mut rate, &mut flush, &mut intermediate, &mut duration, &mut eos);
ffi::gst_message_parse_step_done(
self.0.as_mut_ptr(),
&mut format,
&mut amount,
&mut rate,
&mut flush,
&mut intermediate,
&mut duration,
&mut eos,
);
(from_glib(format), amount, rate, from_glib(flush), from_glib(intermediate), duration, from_glib(eos))
(
from_glib(format),
amount,
rate,
from_glib(flush),
from_glib(intermediate),
duration,
from_glib(eos),
)
}
}
}
@ -433,7 +465,12 @@ impl<'a> StructureChange<'a> {
let mut owner = ptr::null_mut();
let mut busy = mem::uninitialized();
ffi::gst_message_parse_structure_change(self.0.as_mut_ptr(), &mut type_, &mut owner, &mut busy);
ffi::gst_message_parse_structure_change(
self.0.as_mut_ptr(),
&mut type_,
&mut owner,
&mut busy,
);
(from_glib(type_), from_glib_none(owner), from_glib(busy))
}
@ -527,9 +564,24 @@ impl<'a> StepStart<'a> {
let mut flush = mem::uninitialized();
let mut intermediate = mem::uninitialized();
ffi::gst_message_parse_step_start(self.0.as_mut_ptr(), &mut active, &mut format, &mut amount, &mut rate, &mut flush, &mut intermediate);
ffi::gst_message_parse_step_start(
self.0.as_mut_ptr(),
&mut active,
&mut format,
&mut amount,
&mut rate,
&mut flush,
&mut intermediate,
);
(from_glib(active), from_glib(format), amount, rate, from_glib(flush), from_glib(intermediate))
(
from_glib(active),
from_glib(format),
amount,
rate,
from_glib(flush),
from_glib(intermediate),
)
}
}
}
@ -544,9 +596,22 @@ impl<'a> Qos<'a> {
let mut timestamp = mem::uninitialized();
let mut duration = mem::uninitialized();
ffi::gst_message_parse_qos(self.0.as_mut_ptr(), &mut live, &mut running_time, &mut stream_time, &mut timestamp, &mut duration);
ffi::gst_message_parse_qos(
self.0.as_mut_ptr(),
&mut live,
&mut running_time,
&mut stream_time,
&mut timestamp,
&mut duration,
);
(from_glib(live), running_time, stream_time, timestamp, duration)
(
from_glib(live),
running_time,
stream_time,
timestamp,
duration,
)
}
}
@ -556,7 +621,12 @@ impl<'a> Qos<'a> {
let mut proportion = mem::uninitialized();
let mut quality = mem::uninitialized();
ffi::gst_message_parse_qos_values(self.0.as_mut_ptr(), &mut jitter, &mut proportion, &mut quality);
ffi::gst_message_parse_qos_values(
self.0.as_mut_ptr(),
&mut jitter,
&mut proportion,
&mut quality,
);
(jitter, proportion, quality)
}
@ -568,7 +638,12 @@ impl<'a> Qos<'a> {
let mut processed = mem::uninitialized();
let mut dropped = mem::uninitialized();
ffi::gst_message_parse_qos_stats(self.0.as_mut_ptr(), &mut format, &mut processed, &mut dropped);
ffi::gst_message_parse_qos_stats(
self.0.as_mut_ptr(),
&mut format,
&mut processed,
&mut dropped,
);
(from_glib(format), processed, dropped)
}
@ -626,7 +701,10 @@ impl<'a> StreamStart<'a> {
unsafe {
let mut group_id = mem::uninitialized();
if from_glib(ffi::gst_message_parse_group_id(self.0.as_mut_ptr(), &mut group_id)) {
if from_glib(ffi::gst_message_parse_group_id(
self.0.as_mut_ptr(),
&mut group_id,
)) {
Some(group_id)
} else {
None
@ -641,7 +719,11 @@ impl<'a> NeedContext<'a> {
unsafe {
let mut context_type = ptr::null();
if from_glib(ffi::gst_message_parse_context_type(self.0.as_mut_ptr(), &mut context_type)) && !context_type.is_null() {
if from_glib(ffi::gst_message_parse_context_type(
self.0.as_mut_ptr(),
&mut context_type,
)) && !context_type.is_null()
{
Some(CStr::from_ptr(context_type).to_str().unwrap())
} else {
None
@ -690,9 +772,18 @@ impl<'a> PropertyNotify<'a> {
let mut property_name = ptr::null();
let mut value = ptr::null();
ffi::gst_message_parse_property_notify(self.0.as_mut_ptr(), &mut object, &mut property_name, &mut value);
ffi::gst_message_parse_property_notify(
self.0.as_mut_ptr(),
&mut object,
&mut property_name,
&mut value,
);
(from_glib_none(object), CStr::from_ptr(property_name).to_str().unwrap(), from_glib_none(value))
(
from_glib_none(object),
CStr::from_ptr(property_name).to_str().unwrap(),
from_glib_none(value),
)
}
}
}
@ -728,7 +819,14 @@ impl<'a> StreamsSelected<'a> {
unsafe {
let n = ffi::gst_message_streams_selected_get_size(self.0.as_mut_ptr());
(0..n).map(|i| from_glib_full(ffi::gst_message_streams_selected_get_stream(self.0.as_mut_ptr(), i))).collect()
(0..n)
.map(|i| {
from_glib_full(ffi::gst_message_streams_selected_get_stream(
self.0.as_mut_ptr(),
i,
))
})
.collect()
}
}
}
@ -741,13 +839,21 @@ impl<'a> StreamsSelected<'a> {
unsafe {
let n = ffi::gst_message_get_num_redirect_entries(self.0.as_mut_ptr());
(0..n).map(|i| {
(0..n)
.map(|i| {
let mut location = ptr::null();
ffi::gst_message_parse_redirect_entry(self.0.as_mut_ptr(), i, &mut location, ptr::null_mut(), ptr::null_mut());
ffi::gst_message_parse_redirect_entry(
self.0.as_mut_ptr(),
i,
&mut location,
ptr::null_mut(),
ptr::null_mut(),
);
CStr::from_ptr(location).to_str().unwrap()
}).collect()
})
.collect()
}
}
}
@ -839,11 +945,20 @@ impl<'a> ErrorBuilder<'a> {
Some(details) => details.into_ptr(),
};
ffi::gst_message_new_error_with_details(src, mut_override(s.error.to_glib_none().0), s.debug.to_glib_none().0, details)
ffi::gst_message_new_error_with_details(
src,
mut_override(s.error.to_glib_none().0),
s.debug.to_glib_none().0,
details,
)
}
#[cfg(not(feature = "v1_10"))]
{
ffi::gst_message_new_error(src, mut_override(s.error.to_glib_none().0), s.debug.to_glib_none().0)
ffi::gst_message_new_error(
src,
mut_override(s.error.to_glib_none().0),
s.debug.to_glib_none().0,
)
}
});
}
@ -889,11 +1004,20 @@ impl<'a> WarningBuilder<'a> {
Some(details) => details.into_ptr(),
};
ffi::gst_message_new_warning_with_details(src, mut_override(s.error.to_glib_none().0), s.debug.to_glib_none().0, details)
ffi::gst_message_new_warning_with_details(
src,
mut_override(s.error.to_glib_none().0),
s.debug.to_glib_none().0,
details,
)
}
#[cfg(not(feature = "v1_10"))]
{
ffi::gst_message_new_warning(src, mut_override(s.error.to_glib_none().0), s.debug.to_glib_none().0)
ffi::gst_message_new_warning(
src,
mut_override(s.error.to_glib_none().0),
s.debug.to_glib_none().0,
)
}
});
}
@ -939,11 +1063,20 @@ impl<'a> InfoBuilder<'a> {
Some(details) => details.into_ptr(),
};
ffi::gst_message_new_info_with_details(src, mut_override(s.error.to_glib_none().0), s.debug.to_glib_none().0, details)
ffi::gst_message_new_info_with_details(
src,
mut_override(s.error.to_glib_none().0),
s.debug.to_glib_none().0,
details,
)
}
#[cfg(not(feature = "v1_10"))]
{
ffi::gst_message_new_info(src, mut_override(s.error.to_glib_none().0), s.debug.to_glib_none().0)
ffi::gst_message_new_info(
src,
mut_override(s.error.to_glib_none().0),
s.debug.to_glib_none().0,
)
}
});
}
@ -955,7 +1088,7 @@ pub struct TagBuilder<'a> {
// TODO tags
}
impl<'a> TagBuilder<'a> {
pub fn new(tags: /*Tags*/ ()) -> Self {
pub fn new(tags: ()) -> Self {
Self {
src: None,
seqnum: None,
@ -963,7 +1096,13 @@ impl<'a> TagBuilder<'a> {
}
}
message_builder_generic_impl!(|_, src| ffi::gst_message_new_tag(src, /*s.tags.to_glib_full().0*/ ptr::null_mut()));
message_builder_generic_impl!(|_, src| {
ffi::gst_message_new_tag(
src,
/*s.tags.to_glib_full().0*/
ptr::null_mut(),
)
});
}
pub struct BufferingBuilder<'a> {
@ -982,7 +1121,13 @@ impl<'a> BufferingBuilder<'a> {
}
}
pub fn stats(self, mode: ::BufferingMode, avg_in: i32, avg_out: i32, buffering_left: i64) -> Self {
pub fn stats(
self,
mode: ::BufferingMode,
avg_in: i32,
avg_out: i32,
buffering_left: i64,
) -> Self {
Self {
stats: Some((mode, avg_in, avg_out, buffering_left)),
..self
@ -993,7 +1138,13 @@ impl<'a> BufferingBuilder<'a> {
let msg = ffi::gst_message_new_buffering(src, s.percent);
if let Some((mode, avg_in, avg_out, buffering_left)) = s.stats {
ffi::gst_message_set_buffering_stats(msg, mode.to_glib(), avg_in, avg_out, buffering_left);
ffi::gst_message_set_buffering_stats(
msg,
mode.to_glib(),
avg_in,
avg_out,
buffering_left,
);
}
msg
@ -1018,7 +1169,14 @@ impl<'a> StateChangedBuilder<'a> {
}
}
message_builder_generic_impl!(|s: &mut Self, src| ffi::gst_message_new_state_changed(src, s.old.to_glib(), s.new.to_glib(), s.pending.to_glib()));
message_builder_generic_impl!(|s: &mut Self, src| {
ffi::gst_message_new_state_changed(
src,
s.old.to_glib(),
s.new.to_glib(),
s.pending.to_glib(),
)
});
}
pub struct StateDirtyBuilder<'a> {
@ -1048,7 +1206,15 @@ pub struct StepDoneBuilder<'a> {
eos: bool,
}
impl<'a> StepDoneBuilder<'a> {
pub fn new(format: ::Format, amount: u64, rate: f64, flush: bool, intermediate: bool, duration: u64, eos: bool) -> Self {
pub fn new(
format: ::Format,
amount: u64,
rate: f64,
flush: bool,
intermediate: bool,
duration: u64,
eos: bool,
) -> Self {
Self {
src: None,
seqnum: None,
@ -1062,7 +1228,18 @@ impl<'a> StepDoneBuilder<'a> {
}
}
message_builder_generic_impl!(|s: &mut Self, src| ffi::gst_message_new_step_done(src, s.format.to_glib(), s.amount, s.rate, s.flush.to_glib(), s.intermediate.to_glib(), s.duration, s.eos.to_glib()));
message_builder_generic_impl!(|s: &mut Self, src| {
ffi::gst_message_new_step_done(
src,
s.format.to_glib(),
s.amount,
s.rate,
s.flush.to_glib(),
s.intermediate.to_glib(),
s.duration,
s.eos.to_glib(),
)
});
}
pub struct ClockProvideBuilder<'a> {
@ -1081,7 +1258,9 @@ impl<'a> ClockProvideBuilder<'a> {
}
}
message_builder_generic_impl!(|s: &mut Self, src| ffi::gst_message_new_clock_provide(src, s.clock.to_glib_none().0, s.ready.to_glib()));
message_builder_generic_impl!(|s: &mut Self, src| {
ffi::gst_message_new_clock_provide(src, s.clock.to_glib_none().0, s.ready.to_glib())
});
}
pub struct ClockLostBuilder<'a> {
@ -1098,7 +1277,9 @@ impl<'a> ClockLostBuilder<'a> {
}
}
message_builder_generic_impl!(|s: &mut Self, src| ffi::gst_message_new_clock_lost(src, s.clock.to_glib_none().0));
message_builder_generic_impl!(|s: &mut Self, src| {
ffi::gst_message_new_clock_lost(src, s.clock.to_glib_none().0)
});
}
pub struct NewClockBuilder<'a> {
@ -1115,7 +1296,9 @@ impl<'a> NewClockBuilder<'a> {
}
}
message_builder_generic_impl!(|s: &mut Self, src| ffi::gst_message_new_new_clock(src, s.clock.to_glib_none().0));
message_builder_generic_impl!(|s: &mut Self, src| {
ffi::gst_message_new_new_clock(src, s.clock.to_glib_none().0)
});
}
pub struct StructureChangeBuilder<'a> {
@ -1136,7 +1319,14 @@ impl<'a> StructureChangeBuilder<'a> {
}
}
message_builder_generic_impl!(|s: &mut Self, src| ffi::gst_message_new_structure_change(src, s.type_.to_glib(), s.owner.to_glib_none().0, s.busy.to_glib()));
message_builder_generic_impl!(|s: &mut Self, src| {
ffi::gst_message_new_structure_change(
src,
s.type_.to_glib(),
s.owner.to_glib_none().0,
s.busy.to_glib(),
)
});
}
pub struct StreamStatusBuilder<'a> {
@ -1165,7 +1355,8 @@ impl<'a> StreamStatusBuilder<'a> {
}
message_builder_generic_impl!(|s: &mut Self, src| {
let msg = ffi::gst_message_new_stream_status(src, s.type_.to_glib(), s.owner.to_glib_none().0);
let msg =
ffi::gst_message_new_stream_status(src, s.type_.to_glib(), s.owner.to_glib_none().0);
if let Some(status_object) = s.status_object {
ffi::gst_message_set_stream_status_object(msg, status_object.to_glib_none().0);
}
@ -1187,7 +1378,9 @@ impl<'a> ApplicationBuilder<'a> {
}
}
message_builder_generic_impl!(|s: &mut Self, src| ffi::gst_message_new_application(src, s.structure.take().unwrap().into_ptr()));
message_builder_generic_impl!(|s: &mut Self, src| {
ffi::gst_message_new_application(src, s.structure.take().unwrap().into_ptr())
});
}
pub struct ElementBuilder<'a> {
@ -1204,7 +1397,9 @@ impl<'a> ElementBuilder<'a> {
}
}
message_builder_generic_impl!(|s: &mut Self, src| ffi::gst_message_new_element(src, s.structure.take().unwrap().into_ptr()));
message_builder_generic_impl!(|s: &mut Self, src| {
ffi::gst_message_new_element(src, s.structure.take().unwrap().into_ptr())
});
}
pub struct SegmentStartBuilder<'a> {
@ -1223,7 +1418,9 @@ impl<'a> SegmentStartBuilder<'a> {
}
}
message_builder_generic_impl!(|s: &mut Self, src| ffi::gst_message_new_segment_start(src, s.format.to_glib(), s.position));
message_builder_generic_impl!(|s: &mut Self, src| {
ffi::gst_message_new_segment_start(src, s.format.to_glib(), s.position)
});
}
pub struct SegmentDoneBuilder<'a> {
@ -1242,7 +1439,9 @@ impl<'a> SegmentDoneBuilder<'a> {
}
}
message_builder_generic_impl!(|s: &mut Self, src| ffi::gst_message_new_segment_done(src, s.format.to_glib(), s.position));
message_builder_generic_impl!(|s: &mut Self, src| {
ffi::gst_message_new_segment_done(src, s.format.to_glib(), s.position)
});
}
pub struct DurationChangedBuilder<'a> {
@ -1304,7 +1503,9 @@ impl<'a> AsyncDoneBuilder<'a> {
}
}
message_builder_generic_impl!(|s: &mut Self, src| ffi::gst_message_new_async_done(src, s.running_time));
message_builder_generic_impl!(|s: &mut Self, src| {
ffi::gst_message_new_async_done(src, s.running_time)
});
}
pub struct RequestStateBuilder<'a> {
@ -1321,7 +1522,9 @@ impl<'a> RequestStateBuilder<'a> {
}
}
message_builder_generic_impl!(|s: &mut Self, src| ffi::gst_message_new_request_state(src, s.state.to_glib()));
message_builder_generic_impl!(|s: &mut Self, src| {
ffi::gst_message_new_request_state(src, s.state.to_glib())
});
}
pub struct StepStartBuilder<'a> {
@ -1335,7 +1538,14 @@ pub struct StepStartBuilder<'a> {
intermediate: bool,
}
impl<'a> StepStartBuilder<'a> {
pub fn new(active: bool, format: ::Format, amount: u64, rate: f64, flush: bool, intermediate: bool) -> Self {
pub fn new(
active: bool,
format: ::Format,
amount: u64,
rate: f64,
flush: bool,
intermediate: bool,
) -> Self {
Self {
src: None,
seqnum: None,
@ -1348,7 +1558,17 @@ impl<'a> StepStartBuilder<'a> {
}
}
message_builder_generic_impl!(|s: &mut Self, src| ffi::gst_message_new_step_start(src, s.active.to_glib(), s.format.to_glib(), s.amount, s.rate, s.flush.to_glib(), s.intermediate.to_glib()));
message_builder_generic_impl!(|s: &mut Self, src| {
ffi::gst_message_new_step_start(
src,
s.active.to_glib(),
s.format.to_glib(),
s.amount,
s.rate,
s.flush.to_glib(),
s.intermediate.to_glib(),
)
});
}
pub struct QosBuilder<'a> {
@ -1363,7 +1583,13 @@ pub struct QosBuilder<'a> {
stats: Option<(::Format, u64, u64)>,
}
impl<'a> QosBuilder<'a> {
pub fn new(live: bool, running_time: u64, stream_time: u64, timestamp: u64, duration: u64) -> Self {
pub fn new(
live: bool,
running_time: u64,
stream_time: u64,
timestamp: u64,
duration: u64,
) -> Self {
Self {
src: None,
seqnum: None,
@ -1392,7 +1618,14 @@ impl<'a> QosBuilder<'a> {
}
message_builder_generic_impl!(|s: &mut Self, src| {
let msg = ffi::gst_message_new_qos(src, s.live.to_glib(), s.running_time, s.stream_time, s.timestamp, s.duration);
let msg = ffi::gst_message_new_qos(
src,
s.live.to_glib(),
s.running_time,
s.stream_time,
s.timestamp,
s.duration,
);
if let Some((jitter, proportion, quality)) = s.values {
ffi::gst_message_set_qos_values(msg, jitter, proportion, quality);
}
@ -1435,7 +1668,14 @@ impl<'a> ProgressBuilder<'a> {
}
}
message_builder_generic_impl!(|s: &mut Self, src| ffi::gst_message_new_progress(src, s.type_.to_glib(), s.code.to_glib_none().0, s.text.to_glib_none().0));
message_builder_generic_impl!(|s: &mut Self, src| {
ffi::gst_message_new_progress(
src,
s.type_.to_glib(),
s.code.to_glib_none().0,
s.text.to_glib_none().0,
)
});
}
// TODO Toc
@ -1455,7 +1695,13 @@ impl<'a> TocBuilder<'a> {
}
}
message_builder_generic_impl!(|s: &mut Self, src| ffi::gst_message_new_toc(src, ptr::null_mut() /*s.structure.to_glib_full()*/, s.updated.to_glib()));
message_builder_generic_impl!(|s: &mut Self, src| {
ffi::gst_message_new_toc(
src,
ptr::null_mut(), /*s.structure.to_glib_full()*/
s.updated.to_glib(),
)
});
}
pub struct ResetTimeBuilder<'a> {
@ -1472,7 +1718,9 @@ impl<'a> ResetTimeBuilder<'a> {
}
}
message_builder_generic_impl!(|s: &mut Self, src| ffi::gst_message_new_reset_time(src, s.running_time));
message_builder_generic_impl!(|s: &mut Self, src| {
ffi::gst_message_new_reset_time(src, s.running_time)
});
}
pub struct StreamStartBuilder<'a> {
@ -1519,7 +1767,9 @@ impl<'a> NeedContextBuilder<'a> {
}
}
message_builder_generic_impl!(|s: &mut Self, src| ffi::gst_message_new_need_context(src, s.context_type.to_glib_none().0));
message_builder_generic_impl!(|s: &mut Self, src| {
ffi::gst_message_new_need_context(src, s.context_type.to_glib_none().0)
});
}
// TODO Context
@ -1537,7 +1787,9 @@ impl<'a> HaveContextBuilder<'a> {
}
}
message_builder_generic_impl!(|s: &mut Self, src| ffi::gst_message_new_have_context(src, ptr::null_mut() /*s.context.to_glib_full().0*/));
message_builder_generic_impl!(|s: &mut Self, src| {
ffi::gst_message_new_have_context(src, ptr::null_mut() /*s.context.to_glib_full().0*/)
});
}
pub struct DeviceAddedBuilder<'a> {
@ -1554,7 +1806,9 @@ impl<'a> DeviceAddedBuilder<'a> {
}
}
message_builder_generic_impl!(|s: &mut Self, src| ffi::gst_message_new_device_added(src, s.device.to_glib_none().0));
message_builder_generic_impl!(|s: &mut Self, src| {
ffi::gst_message_new_device_added(src, s.device.to_glib_none().0)
});
}
pub struct DeviceRemovedBuilder<'a> {
@ -1571,7 +1825,9 @@ impl<'a> DeviceRemovedBuilder<'a> {
}
}
message_builder_generic_impl!(|s: &mut Self, src| ffi::gst_message_new_device_removed(src, s.device.to_glib_none().0));
message_builder_generic_impl!(|s: &mut Self, src| {
ffi::gst_message_new_device_removed(src, s.device.to_glib_none().0)
});
}
pub struct PropertyNotifyBuilder<'a> {
@ -1591,7 +1847,13 @@ impl<'a> PropertyNotifyBuilder<'a> {
}
}
message_builder_generic_impl!(|s: &mut Self, src| ffi::gst_message_new_property_notify(src, s.property_name.to_glib_none().0, mut_override(s.value.to_glib_none().0)));
message_builder_generic_impl!(|s: &mut Self, src| {
ffi::gst_message_new_property_notify(
src,
s.property_name.to_glib_none().0,
mut_override(s.value.to_glib_none().0),
)
});
}
pub struct StreamCollectionBuilder<'a> {
@ -1610,7 +1872,9 @@ impl<'a> StreamCollectionBuilder<'a> {
}
}
message_builder_generic_impl!(|s: &mut Self, src| ffi::gst_message_new_stream_collection(src, s.collection.to_glib_none().0));
message_builder_generic_impl!(|s: &mut Self, src| {
ffi::gst_message_new_stream_collection(src, s.collection.to_glib_none().0)
});
}
pub struct StreamsSelectedBuilder<'a> {
@ -1680,13 +1944,22 @@ impl<'a> RedirectBuilder<'a> {
}
message_builder_generic_impl!(|s: &mut Self, src| {
let msg = ffi::gst_message_new_redirect(src, s.location.to_glib_none().0, ptr::null_mut(), ptr::null_mut());
let msg = ffi::gst_message_new_redirect(
src,
s.location.to_glib_none().0,
ptr::null_mut(),
ptr::null_mut(),
);
if let Some(entries) = s.entries {
for &(location, tag_list, entry_struct) in entries {
ffi::gst_message_add_redirect_entry(msg, location.to_glib_none().0, ptr::null_mut(), ptr::null_mut());
ffi::gst_message_add_redirect_entry(
msg,
location.to_glib_none().0,
ptr::null_mut(),
ptr::null_mut(),
);
}
}
msg
});
}

View file

@ -12,7 +12,8 @@ use std::marker::PhantomData;
use ffi;
use glib;
use glib::translate::{from_glib, Stash, StashMut, ToGlibPtr, ToGlibPtrMut, FromGlibPtrNone, FromGlibPtrFull, FromGlibPtrBorrow};
use glib::translate::{from_glib, Stash, StashMut, ToGlibPtr, ToGlibPtrMut, FromGlibPtrNone,
FromGlibPtrFull, FromGlibPtrBorrow};
#[derive(Hash, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub struct GstRc<T: MiniObject> {
@ -60,11 +61,9 @@ impl<T: MiniObject> GstRc<T> {
return &mut *self.obj;
}
self.obj = T::from_mut_ptr(
ffi::gst_mini_object_make_writable(
self.as_mut_ptr() as *mut ffi::GstMiniObject
) as *mut T::GstType
);
self.obj = T::from_mut_ptr(ffi::gst_mini_object_make_writable(
self.as_mut_ptr() as *mut ffi::GstMiniObject,
) as *mut T::GstType);
assert!(self.is_writable());
&mut *self.obj
@ -81,17 +80,17 @@ impl<T: MiniObject> GstRc<T> {
pub fn copy(&self) -> Self {
unsafe {
GstRc::from_glib_full(
ffi::gst_mini_object_copy(
self.as_ptr() as *const ffi::GstMiniObject
) as *const T::GstType
)
GstRc::from_glib_full(ffi::gst_mini_object_copy(
self.as_ptr() as *const ffi::GstMiniObject,
) as *const T::GstType)
}
}
pub fn is_writable(&self) -> bool {
unsafe {
from_glib(ffi::gst_mini_object_is_writable(self.as_ptr() as *const ffi::GstMiniObject))
from_glib(ffi::gst_mini_object_is_writable(
self.as_ptr() as *const ffi::GstMiniObject,
))
}
}
@ -255,4 +254,3 @@ impl<T: MiniObject + 'static> FromGlibPtrBorrow<*mut T::GstType> for GstRc<T> {
Self::from_glib_borrow(ptr)
}
}

View file

@ -15,7 +15,8 @@ use std::borrow::{Borrow, ToOwned, BorrowMut};
use std::marker::PhantomData;
use glib;
use glib::translate::{from_glib, from_glib_full, from_glib_none, Stash, StashMut, ToGlibPtr, ToGlibPtrMut, FromGlibPtrNone, FromGlibPtrBorrow, FromGlibPtrFull};
use glib::translate::{from_glib, from_glib_full, from_glib_none, Stash, StashMut, ToGlibPtr,
ToGlibPtrMut, FromGlibPtrNone, FromGlibPtrBorrow, FromGlibPtrFull};
use glib::value::{Value, ToValue, FromValueOptional};
use ffi;
use glib_ffi;
@ -148,9 +149,7 @@ impl ToOwned for StructureRef {
impl glib::types::StaticType for Structure {
fn static_type() -> glib::types::Type {
unsafe {
from_glib(ffi::gst_structure_get_type())
}
unsafe { from_glib(ffi::gst_structure_get_type()) }
}
}
@ -162,9 +161,7 @@ impl<'a> ToGlibPtr<'a, *const ffi::GstStructure> for Structure {
}
fn to_glib_full(&self) -> *const ffi::GstStructure {
unsafe {
ffi::gst_structure_copy(&(*self.0).0)
}
unsafe { ffi::gst_structure_copy(&(*self.0).0) }
}
}
@ -176,9 +173,7 @@ impl<'a> ToGlibPtr<'a, *mut ffi::GstStructure> for Structure {
}
fn to_glib_full(&self) -> *mut ffi::GstStructure {
unsafe {
ffi::gst_structure_copy(&(*self.0).0)
}
unsafe { ffi::gst_structure_copy(&(*self.0).0) }
}
}
@ -210,19 +205,13 @@ impl FromGlibPtrNone<*mut ffi::GstStructure> for Structure {
impl FromGlibPtrFull<*const ffi::GstStructure> for Structure {
unsafe fn from_glib_full(ptr: *const ffi::GstStructure) -> Self {
Structure(
ptr as *mut StructureRef,
PhantomData,
)
Structure(ptr as *mut StructureRef, PhantomData)
}
}
impl FromGlibPtrFull<*mut ffi::GstStructure> for Structure {
unsafe fn from_glib_full(ptr: *mut ffi::GstStructure) -> Self {
Structure(
ptr as *mut StructureRef,
PhantomData,
)
Structure(ptr as *mut StructureRef, PhantomData)
}
}
@ -243,9 +232,7 @@ impl StructureRef {
}
pub fn to_string(&self) -> String {
unsafe {
from_glib_full(ffi::gst_structure_to_string(&self.0))
}
unsafe { from_glib_full(ffi::gst_structure_to_string(&self.0)) }
}
pub fn get<'a, T: FromValueOptional<'a>>(&'a self, name: &str) -> Option<T> {
@ -271,20 +258,29 @@ impl StructureRef {
pub fn set_value(&mut self, name: &str, mut value: Value) {
unsafe {
ffi::gst_structure_take_value(&mut self.0, name.to_glib_none().0, value.to_glib_none_mut().0);
ffi::gst_structure_take_value(
&mut self.0,
name.to_glib_none().0,
value.to_glib_none_mut().0,
);
mem::forget(value);
}
}
pub fn get_name(&self) -> &str {
unsafe {
CStr::from_ptr(ffi::gst_structure_get_name(&self.0)).to_str().unwrap()
CStr::from_ptr(ffi::gst_structure_get_name(&self.0))
.to_str()
.unwrap()
}
}
pub fn has_field(&self, field: &str) -> bool {
unsafe {
from_glib(ffi::gst_structure_has_field(&self.0, field.to_glib_none().0))
from_glib(ffi::gst_structure_has_field(
&self.0,
field.to_glib_none().0,
))
}
}