Commit 873ddf0d authored by Sebastian Dröge's avatar Sebastian Dröge 🍵

Run gstreamer-sdp and gstreamer-webrtc through rustfmt

parent 2de1f6f7
......@@ -18,11 +18,11 @@ extern crate gstreamer_sdp_sys as ffi;
extern crate gstreamer_sys as gst_ffi;
macro_rules! assert_initialized_main_thread {
() => (
if unsafe {::gst_ffi::gst_is_initialized()} != ::glib_ffi::GTRUE {
() => {
if unsafe { ::gst_ffi::gst_is_initialized() } != ::glib_ffi::GTRUE {
panic!("GStreamer has not been initialized. Call `gst::init` first.");
}
)
};
}
macro_rules! skip_assert_initialized {
......@@ -38,19 +38,19 @@ pub use glib::{Cast, Continue, Error, IsA, StaticType, ToValue, Type, TypedValue
mod auto;
pub use auto::*;
mod s_d_p_message;
mod s_d_p_media;
mod m_i_k_e_y_decrypt_info;
mod m_i_k_e_y_encrypt_info;
mod m_i_k_e_y_map_s_r_t_p;
mod m_i_k_e_y_payload_s_p_param;
mod s_d_p_attribute;
mod s_d_p_bandwidth;
mod s_d_p_connection;
mod s_d_p_key;
mod s_d_p_media;
mod s_d_p_message;
mod s_d_p_origin;
mod s_d_p_time;
mod s_d_p_zone;
mod m_i_k_e_y_payload_s_p_param;
mod m_i_k_e_y_encrypt_info;
mod m_i_k_e_y_decrypt_info;
mod m_i_k_e_y_map_s_r_t_p;
// Re-export all the traits in a prelude module, so that applications
// can always "use gst::prelude::*" without getting conflicts
......
......@@ -13,10 +13,10 @@ pub struct MIKEYMapSRTP(ffi::GstMIKEYMapSRTP);
impl MIKEYMapSRTP {
pub fn new(policy: u8, ssrc: u32, roc: u32) -> MIKEYMapSRTP {
MIKEYMapSRTP(ffi::GstMIKEYMapSRTP{
policy: policy,
ssrc: ssrc,
roc: roc,
MIKEYMapSRTP(ffi::GstMIKEYMapSRTP {
policy: policy,
ssrc: ssrc,
roc: roc,
})
}
......
......@@ -15,50 +15,81 @@ use glib_ffi;
use gobject_ffi;
use gst;
use auto::{
MIKEYMessage,
MIKEYTSType,
};
use m_i_k_e_y_payload::MIKEYPayload;
use auto::{MIKEYMessage, MIKEYTSType};
use m_i_k_e_y_decrypt_info::MIKEYDecryptInfo;
use m_i_k_e_y_encrypt_info::MIKEYEncryptInfo;
use m_i_k_e_y_map_s_r_t_p::MIKEYMapSRTP;
use m_i_k_e_y_payload::MIKEYPayload;
impl MIKEYMessage {
pub fn new_from_bytes<'a, P: Into<Option<&'a MIKEYDecryptInfo>>>(bytes: &glib::Bytes, info: P) -> Result<MIKEYMessage, Error> {
pub fn new_from_bytes<'a, P: Into<Option<&'a MIKEYDecryptInfo>>>(
bytes: &glib::Bytes,
info: P,
) -> Result<MIKEYMessage, Error> {
unsafe {
let mut error = ptr::null_mut();
let ret = ffi::gst_mikey_message_new_from_bytes(bytes.to_glib_none(), info.to_glib_full(), &mut error);
let ret = ffi::gst_mikey_message_new_from_bytes(
bytes.to_glib_none(),
info.to_glib_full(),
&mut error,
);
mem::forget(bytes);
mem::forget(info);
if error.is_null() { Ok(from_glib_full(ret)) } else { Err(from_glib_full(error)) }
if error.is_null() {
Ok(from_glib_full(ret))
} else {
Err(from_glib_full(error))
}
}
}
pub fn new_from_data<'a, P: Into<Option<&'a MIKEYDecryptInfo>>>(data: &[u8], info: P) -> Result<MIKEYMessage, Error> {
pub fn new_from_data<'a, P: Into<Option<&'a MIKEYDecryptInfo>>>(
data: &[u8],
info: P,
) -> Result<MIKEYMessage, Error> {
unsafe {
let mut error = ptr::null_mut();
let ret = ffi::gst_mikey_message_new_from_data(data.to_glib_none().0, data.len(), info.to_glib_full(), &mut err);
let ret = ffi::gst_mikey_message_new_from_data(
data.to_glib_none().0,
data.len(),
info.to_glib_full(),
&mut err,
);
mem::forget(info);
if error.is_null() { Ok(from_glib_full(ret)) } else { Err(from_glib_full(error)) }
if error.is_null() {
Ok(from_glib_full(ret))
} else {
Err(from_glib_full(error))
}
}
}
pub fn add_t(&mut self, type_: MIKEYTSType, ts_value: &[u8]) -> bool {
unsafe {
from_glib(ffi::gst_mikey_message_add_t(self.to_glib_none_mut().0, type_.to_glib(), ts_value.to_glib_none().0))
from_glib(ffi::gst_mikey_message_add_t(
self.to_glib_none_mut().0,
type_.to_glib(),
ts_value.to_glib_none().0,
))
}
}
pub fn get_cs_srtp(&self, idx: u32) -> Option<&MIKEYMapSRTP> {
unsafe {
&*(from_glib_none(ffi::gst_mikey_message_get_cs_srtp(self.to_glib_none().0, idx)) as *mut MIKEYMapSRTP)
&*(from_glib_none(ffi::gst_mikey_message_get_cs_srtp(
self.to_glib_none().0,
idx,
)) as *mut MIKEYMapSRTP)
}
}
pub fn insert_cs_srtp(&mut self, idx: i32, map: MIKEYMapSRTP) -> bool {
unsafe {
let ret = from_glib(ffi::gst_mikey_message_insert_cs_srtp(self.to_glib_none_mut().0, idx, map.to_glib_full()));
let ret = from_glib(ffi::gst_mikey_message_insert_cs_srtp(
self.to_glib_none_mut().0,
idx,
map.to_glib_full(),
));
mem::forget(map);
ret
}
......@@ -66,21 +97,31 @@ impl MIKEYMessage {
pub fn get_payload(&self, idx: u32) -> Option<&MIKEYPayload> {
unsafe {
&*(from_glib_none(ffi::gst_mikey_message_get_payload(self.to_glib_none().0, idx)) as *mut MIKEYPayload)
&*(from_glib_none(ffi::gst_mikey_message_get_payload(
self.to_glib_none().0,
idx,
)) as *mut MIKEYPayload)
}
}
pub fn add_payload(&mut self, payload: MIKEYPayload) -> bool {
unsafe {
let ret = from_glib(ffi::gst_mikey_message_add_payload(self.to_glib_none_mut().0, payload.to_glib_full()));
pub fn add_payload(&mut self, payload: MIKEYPayload) -> bool {
unsafe {
let ret = from_glib(ffi::gst_mikey_message_add_payload(
self.to_glib_none_mut().0,
payload.to_glib_full(),
));
mem::forget(payload);
ret
}
}
}
pub fn insert_payload(&mut self, idx: u32, payload: MIKEYPayload) -> bool {
unsafe {
let ret = from_glib(ffi::gst_mikey_message_insert_payload(self.to_glib_none_mut().0, idx, payload.to_glib_full()));
let ret = from_glib(ffi::gst_mikey_message_insert_payload(
self.to_glib_none_mut().0,
idx,
payload.to_glib_full(),
));
mem::forget(payload);
ret
}
......@@ -88,7 +129,11 @@ impl MIKEYMessage {
pub fn replace_cs_srtp(&mut self, idx: i32, map: MIKEYMapSRTP) -> bool {
unsafe {
let ret = from_glib(ffi::gst_mikey_message_replace_cs_srtp(self.to_glib_none_mut().0, idx, map.to_glib_full()));
let ret = from_glib(ffi::gst_mikey_message_replace_cs_srtp(
self.to_glib_none_mut().0,
idx,
map.to_glib_full(),
));
mem::forget(map);
ret
}
......@@ -96,7 +141,11 @@ impl MIKEYMessage {
pub fn replace_payload(&mut self, idx: u32, payload: MIKEYPayload) -> bool {
unsafe {
let ret = from_glib(ffi::gst_mikey_message_replace_payload(self.to_glib_none_mut().0, idx, payload.to_glib_full()));
let ret = from_glib(ffi::gst_mikey_message_replace_payload(
self.to_glib_none_mut().0,
idx,
payload.to_glib_full(),
));
mem::forget(payload);
ret
}
......@@ -104,7 +153,9 @@ impl MIKEYMessage {
pub fn base64_encode(&self) -> Option<String> {
unsafe {
from_glib_full(ffi::gst_mikey_message_base64_encode(self.to_glib_none_mut().0))
from_glib_full(ffi::gst_mikey_message_base64_encode(
self.to_glib_none_mut().0,
))
}
}
}
......@@ -18,10 +18,12 @@ use auto::MIKEYPayload;
use m_i_k_e_y_map_s_r_t_p::MIKEYPayloadSPParam;
impl MIKEYPayload {
pub fn kemac_add_sub(&mut self, newpay: MIKEYPayload) -> bool {
unsafe {
let ret = from_glib(ffi::gst_mikey_payload_kemac_add_sub(self.to_glib_none_mut().0, newpay.to_glib_full()));
let ret = from_glib(ffi::gst_mikey_payload_kemac_add_sub(
self.to_glib_none_mut().0,
newpay.to_glib_full(),
));
mem::forget(newpay);
ret
}
......@@ -29,19 +31,29 @@ impl MIKEYPayload {
pub fn kemac_get_sub(&self, idx: u32) -> Option<&MIKEYPayload> {
unsafe {
&*(from_glib_none(ffi::gst_mikey_payload_kemac_get_sub(self.to_glib_none().0, idx)) as *mut MIKEYPayload)
&*(from_glib_none(ffi::gst_mikey_payload_kemac_get_sub(
self.to_glib_none().0,
idx,
)) as *mut MIKEYPayload)
}
}
pub fn sp_get_param(&self, idx: u32) -> Option<&MIKEYPayloadSPParam> {
unsafe {
&*(from_glib_none(ffi::gst_mikey_payload_sp_get_param(self.to_glib_none().0, idx)) as *mut MIKEYPayloadSPParam)
&*(from_glib_none(ffi::gst_mikey_payload_sp_get_param(
self.to_glib_none().0,
idx,
)) as *mut MIKEYPayloadSPParam)
}
}
pub fn t_set(&mut self, type_: MIKEYTSType, ts_value: &[u8]) -> bool {
unsafe {
from_glib(ffi::gst_mikey_payload_t_set(self.to_glib_none_mut().0, type_.to_glib(), ts_value.to_glib_none().0))
from_glib(ffi::gst_mikey_payload_t_set(
self.to_glib_none_mut().0,
type_.to_glib(),
ts_value.to_glib_none().0,
))
}
}
......@@ -49,8 +61,13 @@ impl MIKEYPayload {
let vf_len = vf_data.len() as u8;
let vt_len = vt_data.len() as u8;
unsafe {
from_glib(ffi::gst_mikey_payload_key_data_set_interval(self.to_glib_none_mut().0, vf_len, vf_data.to_glib_none().0, vt_len, vt_data.to_glib_none().0))
from_glib(ffi::gst_mikey_payload_key_data_set_interval(
self.to_glib_none_mut().0,
vf_len,
vf_data.to_glib_none().0,
vt_len,
vt_data.to_glib_none().0,
))
}
}
}
......@@ -23,8 +23,6 @@ impl MIKEYPayloadSPParam {
}
pub fn val(&self) -> &[u8] {
unsafe {
slice::from_raw_parts(self.0.val as *const u8, self.0.len as usize)
}
unsafe { slice::from_raw_parts(self.0.val as *const u8, self.0.len as usize) }
}
}
......@@ -6,8 +6,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use std::mem;
use std::ffi::CStr;
use std::mem;
use ffi;
use glib::translate::*;
......@@ -22,7 +22,11 @@ impl SDPAttribute {
assert_initialized_main_thread!();
unsafe {
let mut attr = mem::zeroed();
let result = from_glib(ffi::gst_sdp_attribute_set(&mut attr, key.to_glib_none().0, value.to_glib_none().0));
let result = from_glib(ffi::gst_sdp_attribute_set(
&mut attr,
key.to_glib_none().0,
value.to_glib_none().0,
));
match result {
SDPResult::Ok => Ok(SDPAttribute(attr)),
_ => Err(()),
......@@ -31,15 +35,11 @@ impl SDPAttribute {
}
pub fn key(&self) -> &str {
unsafe {
CStr::from_ptr(self.0.key).to_str().unwrap()
}
unsafe { CStr::from_ptr(self.0.key).to_str().unwrap() }
}
pub fn value(&self) -> &str {
unsafe {
CStr::from_ptr(self.0.value).to_str().unwrap()
}
unsafe { CStr::from_ptr(self.0.value).to_str().unwrap() }
}
}
......
......@@ -6,8 +6,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use std::mem;
use std::ffi::CStr;
use std::mem;
use ffi;
use glib::translate::*;
......@@ -22,7 +22,11 @@ impl SDPBandwidth {
assert_initialized_main_thread!();
unsafe {
let mut bw = mem::zeroed();
let result = from_glib(ffi::gst_sdp_bandwidth_set(&mut bw, bwtype.to_glib_none().0, bandwidth));
let result = from_glib(ffi::gst_sdp_bandwidth_set(
&mut bw,
bwtype.to_glib_none().0,
bandwidth,
));
match result {
SDPResult::Ok => Ok(SDPBandwidth(bw)),
_ => Err(()),
......@@ -31,9 +35,7 @@ impl SDPBandwidth {
}
pub fn bwtype(&self) -> &str {
unsafe {
CStr::from_ptr(self.0.bwtype).to_str().unwrap()
}
unsafe { CStr::from_ptr(self.0.bwtype).to_str().unwrap() }
}
pub fn value(&self) -> u32 {
......
......@@ -6,8 +6,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use std::mem;
use std::ffi::CStr;
use std::mem;
use ffi;
use glib::translate::*;
......@@ -18,10 +18,16 @@ use auto::SDPResult;
pub struct SDPConnection(pub(crate) ffi::GstSDPConnection);
impl SDPConnection {
pub fn new(nettype: &str, addrtype: &str, address: &str, ttl: u32, addr_number: u32) -> Result<Self, ()> {
assert_initialized_main_thread!();
pub fn new(
nettype: &str,
addrtype: &str,
address: &str,
ttl: u32,
addr_number: u32,
) -> Result<Self, ()> {
assert_initialized_main_thread!();
unsafe {
let mut conn = mem::zeroed();
let mut conn = mem::zeroed();
let result = from_glib(ffi::gst_sdp_connection_set(
&mut conn,
nettype.to_glib_none().0,
......@@ -30,38 +36,32 @@ impl SDPConnection {
ttl,
addr_number,
));
match result {
SDPResult::Ok => Ok(SDPConnection(conn)),
_ => Err(()),
}
match result {
SDPResult::Ok => Ok(SDPConnection(conn)),
_ => Err(()),
}
}
}
pub fn nettype(&self) -> &str {
unsafe {
CStr::from_ptr(self.0.nettype).to_str().unwrap()
}
}
pub fn nettype(&self) -> &str {
unsafe { CStr::from_ptr(self.0.nettype).to_str().unwrap() }
}
pub fn addrtype(&self) -> &str {
unsafe {
CStr::from_ptr(self.0.addrtype).to_str().unwrap()
}
}
pub fn addrtype(&self) -> &str {
unsafe { CStr::from_ptr(self.0.addrtype).to_str().unwrap() }
}
pub fn address(&self) -> &str {
unsafe {
CStr::from_ptr(self.0.address).to_str().unwrap()
}
}
pub fn address(&self) -> &str {
unsafe { CStr::from_ptr(self.0.address).to_str().unwrap() }
}
pub fn ttl(&self) -> u32 {
self.0.ttl as u32
}
pub fn ttl(&self) -> u32 {
self.0.ttl as u32
}
pub fn addr_number(&self) -> u32 {
self.0.addr_number as u32
}
pub fn addr_number(&self) -> u32 {
self.0.addr_number as u32
}
}
impl Drop for SDPConnection {
......
......@@ -13,15 +13,11 @@ use ffi;
pub struct SDPKey(ffi::GstSDPKey);
impl SDPKey {
pub fn type_(&self) -> &str {
unsafe {
CStr::from_ptr(self.0.type_).to_str().unwrap()
}
}
pub fn type_(&self) -> &str {
unsafe { CStr::from_ptr(self.0.type_).to_str().unwrap() }
}
pub fn data(&self) -> &str {
unsafe {
CStr::from_ptr(self.0.data).to_str().unwrap()
}
}
pub fn data(&self) -> &str {
unsafe { CStr::from_ptr(self.0.data).to_str().unwrap() }
}
}
......@@ -6,19 +6,16 @@
// // option. This file may not be copied, modified, or distributed
// // except according to those terms.
use std::ffi::CStr;
use std::mem;
use std::ptr;
use std::ffi::CStr;
use ffi;
use glib::translate::*;
use glib_ffi;
use gst;
use auto::{
SDPResult,
MIKEYMessage,
};
use auto::{MIKEYMessage, SDPResult};
use s_d_p_attribute::SDPAttribute;
use s_d_p_bandwidth::SDPBandwidth;
use s_d_p_connection::SDPConnection;
......@@ -52,11 +49,19 @@ impl SDPMedia {
}
}
pub fn add_attribute<'a, P: Into<Option<&'a str>>>(&mut self, key: &str, value: P) -> Result<(), ()> {
pub fn add_attribute<'a, P: Into<Option<&'a str>>>(
&mut self,
key: &str,
value: P,
) -> Result<(), ()> {
let value = value.into();
let value = value.to_glib_none();
let result = unsafe {
from_glib(ffi::gst_sdp_media_add_attribute(self.to_glib_none_mut().0, key.to_glib_none().0, value.0))
from_glib(ffi::gst_sdp_media_add_attribute(
self.to_glib_none_mut().0,
key.to_glib_none().0,
value.0,
))
};
match result {
SDPResult::Ok => Ok(()),
......@@ -66,7 +71,11 @@ impl SDPMedia {
pub fn add_bandwidth(&mut self, bwtype: &str, bandwidth: u32) -> Result<(), ()> {
let result = unsafe {
from_glib(ffi::gst_sdp_media_add_bandwidth(self.to_glib_none_mut().0, bwtype.to_glib_none().0, bandwidth))
from_glib(ffi::gst_sdp_media_add_bandwidth(
self.to_glib_none_mut().0,
bwtype.to_glib_none().0,
bandwidth,
))
};
match result {
SDPResult::Ok => Ok(()),
......@@ -74,9 +83,23 @@ impl SDPMedia {
}
}
pub fn add_connection(&mut self, nettype: &str, addrtype: &str, address: &str, ttl: u32, addr_number: u32) -> Result<(), ()> {
pub fn add_connection(
&mut self,
nettype: &str,
addrtype: &str,
address: &str,
ttl: u32,
addr_number: u32,
) -> Result<(), ()> {
let result = unsafe {
from_glib(ffi::gst_sdp_media_add_connection(self.to_glib_none_mut().0, nettype.to_glib_none().0, addrtype.to_glib_none().0, address.to_glib_none().0, ttl, addr_number))
from_glib(ffi::gst_sdp_media_add_connection(
self.to_glib_none_mut().0,
nettype.to_glib_none().0,
addrtype.to_glib_none().0,
address.to_glib_none().0,
ttl,
addr_number,
))
};
match result {
SDPResult::Ok => Ok(()),
......@@ -86,7 +109,10 @@ impl SDPMedia {
pub fn add_format(&mut self, format: &str) -> Result<(), ()> {
let result = unsafe {
from_glib(ffi::gst_sdp_media_add_format(self.to_glib_none_mut().0, format.to_glib_none().0))
from_glib(ffi::gst_sdp_media_add_format(
self.to_glib_none_mut().0,
format.to_glib_none().0,
))
};
match result {
SDPResult::Ok => Ok(()),
......@@ -95,20 +121,19 @@ impl SDPMedia {
}
pub fn as_text(&self) -> Option<String> {
unsafe {
from_glib_full(ffi::gst_sdp_media_as_text(self.to_glib_none().0))
}
unsafe { from_glib_full(ffi::gst_sdp_media_as_text(self.to_glib_none().0)) }
}
pub fn attributes_len(&self) -> u32 {
unsafe {
ffi::gst_sdp_media_attributes_len(self.to_glib_none().0)
}
unsafe { ffi::gst_sdp_media_attributes_len(self.to_glib_none().0) }
}
pub fn attributes_to_caps(&self, caps: &gst::Caps) -> Result<(), ()> {
let result = unsafe {
from_glib(ffi::gst_sdp_media_attributes_to_caps(self.to_glib_none().0, caps.to_glib_none().0))
from_glib(ffi::gst_sdp_media_attributes_to_caps(
self.to_glib_none().0,
caps.to_glib_none().0,
))
};
match result {