Address PR comments and fix compilation errors

This commit is contained in:
Bo Du 2018-04-04 14:40:45 -04:00 committed by Sebastian Dröge
parent 36d538c0a0
commit 3ecd67ee46
19 changed files with 637 additions and 443 deletions

View file

@ -55,9 +55,25 @@ status = "generate"
name = "add_payload" name = "add_payload"
ignore = true ignore = true
[[object.function]]
name = "get_payload"
ignore = true
[[object.function]]
name = "base64_encode"
ignore = true
[[object]] [[object]]
name = "GstSdp.MIKEYPayload" name = "GstSdp.MIKEYPayload"
status = "generate" status = "generate"
[[object.function]] [[object.function]]
name = "kemac_add_sub" name = "kemac_add_sub"
ignore = true ignore = true
[[object.function]]
name = "kemac_get_sub"
ignore = true
[[object.function]]
name = "key_data_set_interval"
ignore = true

View file

@ -85,12 +85,6 @@ impl MIKEYMessage {
} }
} }
pub fn base64_encode(&mut self) -> Option<String> {
unsafe {
from_glib_full(ffi::gst_mikey_message_base64_encode(self.to_glib_none_mut().0))
}
}
pub fn find_payload(&self, type_: MIKEYPayloadType, nth: u32) -> Option<MIKEYPayload> { pub fn find_payload(&self, type_: MIKEYPayloadType, nth: u32) -> Option<MIKEYPayload> {
unsafe { unsafe {
from_glib_none(ffi::gst_mikey_message_find_payload(self.to_glib_none().0, type_.to_glib(), nth)) from_glib_none(ffi::gst_mikey_message_find_payload(self.to_glib_none().0, type_.to_glib(), nth))
@ -113,12 +107,6 @@ 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))
}
}
//pub fn insert_cs_srtp(&mut self, idx: i32, map: /*Ignored*/&MIKEYMapSRTP) -> bool { //pub fn insert_cs_srtp(&mut self, idx: i32, map: /*Ignored*/&MIKEYMapSRTP) -> bool {
// unsafe { TODO: call ffi::gst_mikey_message_insert_cs_srtp() } // unsafe { TODO: call ffi::gst_mikey_message_insert_cs_srtp() }
//} //}

View file

@ -39,12 +39,6 @@ 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))
}
}
pub fn kemac_remove_sub(&mut self, idx: u32) -> bool { pub fn kemac_remove_sub(&mut self, idx: u32) -> bool {
unsafe { unsafe {
from_glib(ffi::gst_mikey_payload_kemac_remove_sub(self.to_glib_none_mut().0, idx)) from_glib(ffi::gst_mikey_payload_kemac_remove_sub(self.to_glib_none_mut().0, idx))
@ -57,14 +51,6 @@ impl MIKEYPayload {
} }
} }
pub fn key_data_set_interval(&mut self, vf_len: u8, vt_data: &[u8]) -> bool {
let vf_data = vf_data.len() as Vec<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))
}
}
pub fn key_data_set_key(&mut self, key_type: MIKEYKeyDataType, key_data: &[u8]) -> bool { pub fn key_data_set_key(&mut self, key_type: MIKEYKeyDataType, key_data: &[u8]) -> bool {
let key_len = key_data.len() as u16; let key_len = key_data.len() as u16;
unsafe { unsafe {

View file

@ -9,6 +9,7 @@
extern crate bitflags; extern crate bitflags;
extern crate libc; extern crate libc;
#[macro_use]
extern crate glib; extern crate glib;
extern crate glib_sys as glib_ffi; extern crate glib_sys as glib_ffi;
extern crate gobject_sys as gobject_ffi; extern crate gobject_sys as gobject_ffi;
@ -46,14 +47,11 @@ mod s_d_p_key;
mod s_d_p_origin; mod s_d_p_origin;
mod s_d_p_time; mod s_d_p_time;
mod s_d_p_zone; mod s_d_p_zone;
mod m_i_k_e_y_message; mod m_i_k_e_y_payload_s_p_param;
mod m_i_k_e_y_payload;
mod m_i_k_e_y_encrypt_info; mod m_i_k_e_y_encrypt_info;
mod m_i_k_e_y_decrypt_info; mod m_i_k_e_y_decrypt_info;
mod m_i_k_e_y_map_s_r_t_p; mod m_i_k_e_y_map_s_r_t_p;
pub use s_d_p_message::SDPMessage;
// Re-export all the traits in a prelude module, so that applications // Re-export all the traits in a prelude module, so that applications
// can always "use gst::prelude::*" without getting conflicts // can always "use gst::prelude::*" without getting conflicts
pub mod prelude { pub mod prelude {

View file

@ -6,18 +6,6 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use std::mem;
use std::ptr;
use ffi; use ffi;
use glib::translate::*;
use glib_ffi;
use libc::c_void;
pub struct MIKEYDecryptInfo(ffi::GstMIKEYDecryptInfo); pub struct MIKEYDecryptInfo(ffi::GstMIKEYDecryptInfo);
impl MIKEYDecryptInfo {
pub fn new() -> MIKEYDecryptInfo {
MIKEYDecryptInfo(ffi::GstMIKEYDecryptInfo(ptr::null_mut() as *mut c_void))
}
}

View file

@ -6,18 +6,6 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use std::mem;
use std::ptr;
use ffi; use ffi;
use glib::translate::*;
use glib_ffi;
use libc::c_void;
pub struct MIKEYEncryptInfo(ffi::GstMIKEYEncryptInfo); pub struct MIKEYEncryptInfo(ffi::GstMIKEYEncryptInfo);
impl MIKEYEncryptInfo {
pub fn new() -> MIKEYEncryptInfo {
MIKEYEncryptInfo(ffi::GstMIKEYEncryptInfo(ptr::null_mut() as *mut c_void))
}
}

View file

@ -6,13 +6,9 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use std::mem;
use std::ptr;
use ffi; use ffi;
use glib::translate::*;
use glib_ffi;
#[repr(C)]
pub struct MIKEYMapSRTP(ffi::GstMIKEYMapSRTP); pub struct MIKEYMapSRTP(ffi::GstMIKEYMapSRTP);
impl MIKEYMapSRTP { impl MIKEYMapSRTP {

View file

@ -25,22 +25,22 @@ 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_map_s_r_t_p::MIKEYMapSRTP;
impl MIKEYMessage { impl MIKEYMessage {
pub fn new_from_bytes(bytes: glib::Bytes, info: MIKEYDecryptInfo) -> Result<MIKEYMessage, Error> { pub fn new_from_bytes<'a, P: Into<Option<&'a MIKEYDecryptInfo>>>(bytes: &glib::Bytes, info: P) -> Result<MIKEYMessage, Error> {
unsafe { unsafe {
let mut error = ptr::null_mut(); let mut error = ptr::null_mut();
let ret = ffi::gst_mikey_message_new_from_bytes(bytes.to_glib_full(), 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(bytes);
mem::forget(info); 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(data: &[u8], info: MIKEYDecryptInfo) -> Result<MIKEYMessage, Error> { pub fn new_from_data<'a, P: Into<Option<&'a MIKEYDecryptInfo>>>(data: &[u8], info: P) -> Result<MIKEYMessage, Error> {
unsafe { unsafe {
let mut error = ptr::null_mut(); 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); 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)) }
} }
} }
@ -50,9 +50,9 @@ impl MIKEYMessage {
} }
} }
pub fn get_cs_srtp(&self, idx: u32) -> Option<MIKEYMapSRTP> { pub fn get_cs_srtp(&self, idx: u32) -> Option<&MIKEYMapSRTP> {
unsafe { unsafe {
from_glib_none(ffi::gst_mikey_message_get_cs_srtp(self.to_glib_none().0, idx)) &*(from_glib_none(ffi::gst_mikey_message_get_cs_srtp(self.to_glib_none().0, idx)) as *mut MIKEYMapSRTP)
} }
} }
@ -64,9 +64,15 @@ 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)
}
}
pub fn add_payload(&mut self, payload: MIKEYPayload) -> bool { pub fn add_payload(&mut self, payload: MIKEYPayload) -> bool {
unsafe { unsafe {
let ret = from_glib(ffi::gst_mikey_message_add_payload(self.to_glib_none_mut().0, payload.to_glib_full())) let ret = from_glib(ffi::gst_mikey_message_add_payload(self.to_glib_none_mut().0, payload.to_glib_full()));
mem::forget(payload); mem::forget(payload);
ret ret
} }
@ -95,4 +101,10 @@ impl MIKEYMessage {
ret ret
} }
} }
pub fn base64_encode(&self) -> Option<String> {
unsafe {
from_glib_full(ffi::gst_mikey_message_base64_encode(self.to_glib_none_mut().0))
}
}
} }

View file

@ -15,6 +15,7 @@ use glib_ffi;
use gobject_ffi; use gobject_ffi;
use auto::MIKEYPayload; use auto::MIKEYPayload;
use m_i_k_e_y_map_s_r_t_p::MIKEYPayloadSPParam;
impl MIKEYPayload { impl MIKEYPayload {
@ -25,11 +26,30 @@ impl MIKEYPayload {
mem::forget(newpay); mem::forget(newpay);
} }
//pub fn sp_get_param(&self, idx: u32) -> /*Ignored*/Option<MIKEYPayloadSPParam> { pub fn kemac_get_sub(&self, idx: u32) -> Option<MIKEYPayload> {
// unsafe { TODO: call ffi::gst_mikey_payload_sp_get_param() } unsafe {
//} &*(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)
}
}
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))
}
}
pub fn key_data_set_interval(&mut self, vf_data: &[u8], vt_data: &[u8]) -> bool {
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))
}
}
//pub fn t_set(&mut self, type_: MIKEYTSType, ts_value: &[u8]) -> bool {
// unsafe { TODO: call ffi::gst_mikey_payload_t_set() }
//}
} }

View file

@ -0,0 +1,30 @@
// Copyright (C) 2018 Sebastian Dröge <sebastian@centricular.com>
//
// 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 std::slice;
use ffi;
#[repr(C)]
pub struct MIKEYPayloadSPParam(ffi::GstMIKEYPayloadSPParam);
impl MIKEYPayloadSPParam {
pub fn type_(&self) -> u8 {
self.0.type_
}
pub fn len(&self) -> u8 {
self.0.len
}
pub fn val(&self) -> &[u8] {
unsafe {
slice::from_raw_parts(self.0.val as *const u8, self.0.len as usize)
}
}
}

View file

@ -10,35 +10,43 @@ use std::mem;
use std::ffi::CStr; use std::ffi::CStr;
use ffi; use ffi;
use glib::translate::*;
use auto::SDPResult; use auto::SDPResult;
pub struct SDPAttribute(ffi::GstSDPAttribute); #[repr(C)]
pub struct SDPAttribute(pub ffi::GstSDPAttribute);
impl SDPAttribute { impl SDPAttribute {
pub fn new(key: &str, value: &str) -> Result<Self, SDPResult> { pub fn new(key: &str, value: &str) -> Result<Self, ()> {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
unsafe { unsafe {
let mut attr = mem::uninitialized(); 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 { match result {
SDPResult::Ok => Ok(SDPAttribute(attr)), SDPResult::Ok => Ok(SDPAttribute(attr)),
_ => Err(result), _ => Err(()),
} }
} }
} }
pub fn key(&self) -> &str { pub fn key(&self) -> &str {
CStr::from_ptr(self.0.key).to_str().unwrap() unsafe {
CStr::from_ptr(self.0.key).to_str().unwrap()
}
} }
pub fn value(&self) -> &str { pub fn value(&self) -> &str {
CStr::from_ptr(self.0.value).to_str().unwrap() unsafe {
CStr::from_ptr(self.0.value).to_str().unwrap()
}
} }
} }
impl Drop for SDPAttribute { impl Drop for SDPAttribute {
fn drop(&mut self) { fn drop(&mut self) {
ffi::gst_sdp_attribute_clear(self.to_glib_none_mut().0); unsafe {
ffi::gst_sdp_attribute_clear(&mut self.0);
}
} }
} }

View file

@ -10,26 +10,30 @@ use std::mem;
use std::ffi::CStr; use std::ffi::CStr;
use ffi; use ffi;
use glib::translate::*;
use auto::SDPResult; use auto::SDPResult;
pub struct SDPBandwidth(ffi::GstSDPBandwidth); #[repr(C)]
pub struct SDPBandwidth(pub ffi::GstSDPBandwidth);
impl SDPBandwidth { impl SDPBandwidth {
pub fn new(bwtype: &str, bandwidth: u32) -> Result<Self, SDPResult> { pub fn new(bwtype: &str, bandwidth: u32) -> Result<Self, ()> {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
unsafe { unsafe {
let mut bw = mem::uninitialized(); 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 { match result {
SDPResult::Ok => Ok(SDPBandwidth(bw)), SDPResult::Ok => Ok(SDPBandwidth(bw)),
_ => Err(result), _ => Err(()),
} }
} }
} }
pub fn bwtype(&self) -> &str { pub fn bwtype(&self) -> &str {
CStr::from_ptr(self.0.bwtype).to_str().unwrap() unsafe {
CStr::from_ptr(self.0.bwtype).to_str().unwrap()
}
} }
pub fn value(&self) -> u32 { pub fn value(&self) -> u32 {
@ -39,6 +43,8 @@ impl SDPBandwidth {
impl Drop for SDPBandwidth { impl Drop for SDPBandwidth {
fn drop(&mut self) { fn drop(&mut self) {
ffi::gst_sdp_bandwidth_clear(self.to_glib_none_mut().0); unsafe {
ffi::gst_sdp_bandwidth_clear(&mut self.0);
}
} }
} }

View file

@ -10,17 +10,18 @@ use std::mem;
use std::ffi::CStr; use std::ffi::CStr;
use ffi; use ffi;
use glib::translate::*;
use auto::SDPResult; use auto::SDPResult;
#[repr(C)]
pub struct SDPConnection(ffi::GstSDPConnection); pub struct SDPConnection(pub ffi::GstSDPConnection);
impl SDPConnection { impl SDPConnection {
pub fn new(nettype: &str, addrtype: &str, address: &str, ttl: u32, addr_number: u32) -> Result<Self, SDPResult> { pub fn new(nettype: &str, addrtype: &str, address: &str, ttl: u32, addr_number: u32) -> Result<Self, ()> {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
unsafe { unsafe {
let mut conn = mem::uninitialized(); let mut conn = mem::zeroed();
let result = from_glib(ffi::gst_sdp_connection_set( let result = from_glib(ffi::gst_sdp_connection_set(
&mut conn, &mut conn,
nettype.to_glib_none().0, nettype.to_glib_none().0,
@ -31,21 +32,27 @@ impl SDPConnection {
)); ));
match result { match result {
SDPResult::Ok => Ok(SDPConnection(conn)), SDPResult::Ok => Ok(SDPConnection(conn)),
_ => Err(result), _ => Err(()),
} }
} }
} }
pub fn nettype(&self) -> &str { pub fn nettype(&self) -> &str {
CStr::from_ptr(self.0.nettype).to_str().unwrap() unsafe {
CStr::from_ptr(self.0.nettype).to_str().unwrap()
}
} }
pub fn addrtype(&self) -> &str { pub fn addrtype(&self) -> &str {
CStr::from_ptr(self.0.addrtype).to_str().unwrap() unsafe {
CStr::from_ptr(self.0.addrtype).to_str().unwrap()
}
} }
pub fn address(&self) -> &str { pub fn address(&self) -> &str {
CStr::from_ptr(self.0.address).to_str().unwrap() unsafe {
CStr::from_ptr(self.0.address).to_str().unwrap()
}
} }
pub fn ttl(&self) -> u32 { pub fn ttl(&self) -> u32 {
@ -59,6 +66,8 @@ impl SDPConnection {
impl Drop for SDPConnection { impl Drop for SDPConnection {
fn drop(&mut self) { fn drop(&mut self) {
ffi::gst_sdp_connection_clear(self.to_glib_none_mut().0); unsafe {
ffi::gst_sdp_connection_clear(&mut self.0);
}
} }
} }

View file

@ -13,11 +13,15 @@ use ffi;
pub struct SDPKey(ffi::GstSDPKey); pub struct SDPKey(ffi::GstSDPKey);
impl SDPKey { impl SDPKey {
pub fn type(&self) -> &str { pub fn type_(&self) -> &str {
CStr::from_ptr(self.0.type_).to_str().unwrap() unsafe {
CStr::from_ptr(self.0.type_).to_str().unwrap()
}
} }
pub fn data(&self) -> &str { pub fn data(&self) -> &str {
CStr::from_ptr(self.0.data).to_str().unwrap() unsafe {
CStr::from_ptr(self.0.data).to_str().unwrap()
}
} }
} }

View file

@ -8,14 +8,17 @@
use std::mem; use std::mem;
use std::ptr; use std::ptr;
use std::ffi::CStr;
use ffi; use ffi;
use glib::translate::*; use glib::translate::*;
use glib_ffi; use glib_ffi;
use gst; use gst;
use auto::SDPResult; use auto::{
use m_i_k_e_y_message::MIKEYMessage; SDPResult,
MIKEYMessage,
};
use s_d_p_attribute::SDPAttribute; use s_d_p_attribute::SDPAttribute;
use s_d_p_bandwidth::SDPBandwidth; use s_d_p_bandwidth::SDPBandwidth;
use s_d_p_connection::SDPConnection; use s_d_p_connection::SDPConnection;
@ -25,55 +28,66 @@ glib_wrapper! {
pub struct SDPMedia(Boxed<ffi::GstSDPMedia>); pub struct SDPMedia(Boxed<ffi::GstSDPMedia>);
match fn { match fn {
copy => |ptr| ffi::gst_sdp_media_copy(mut_override(ptr)), copy => |ptr| {
free => |ptr| ffi::gst_sdp_media_free(ptr), let mut copy = ptr::null_mut();
ffi::gst_sdp_media_copy(ptr as *const ffi::GstSDPMedia, &mut copy);
copy
},
free => |ptr| {
ffi::gst_sdp_media_free(ptr);
},
} }
} }
impl SDPMedia { impl SDPMedia {
pub fn add_attribute<'a, P: Into<Option<&'a str>>>(&mut self, key: &str, value: P) -> Result<_, ()> { pub fn new() -> (SDPResult, SDPMedia) {
assert_initialized_main_thread!();
unsafe {
let mut media = ptr::null_mut();
let ret = from_glib(ffi::gst_sdp_media_new(&mut media));
(ret, from_glib_full(media))
}
}
pub fn add_attribute<'a, P: Into<Option<&'a str>>>(&mut self, key: &str, value: P) -> Result<(), ()> {
let value = value.into(); let value = value.into();
let value = value.to_glib_none(); let value = value.to_glib_none();
let result = unsafe { 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 { match result {
SDPResult::ok => Some(_), SDPResult::Ok => Ok(()),
_ => Err(()), _ => Err(()),
}
} }
} }
pub fn add_bandwidth(&mut self, bwtype: &str, bandwidth: u32) -> Result<_, ()> { pub fn add_bandwidth(&mut self, bwtype: &str, bandwidth: u32) -> Result<(), ()> {
let result = unsafe { 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 { match result {
SDPResult::ok => Some(_), SDPResult::Ok => Ok(()),
_ => Err(()), _ => Err(()),
}
} }
} }
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 { 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 { match result {
SDPResult::ok => Some(_), SDPResult::Ok => Ok(()),
_ => Err(()), _ => Err(()),
}
} }
} }
pub fn add_format(&mut self, format: &str) -> Result<_, ()> { pub fn add_format(&mut self, format: &str) -> Result<(), ()> {
let result = unsafe { 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 { match result {
SDPResult::ok => Some(_), SDPResult::Ok => Ok(()),
_ => Err(()), _ => Err(()),
}
} }
} }
@ -89,14 +103,13 @@ impl SDPMedia {
} }
} }
pub fn attributes_to_caps(&self, caps: &gst::Caps) -> Result<_, ()> { pub fn attributes_to_caps(&self, caps: &gst::Caps) -> Result<(), ()> {
let result = unsafe { 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 { match result {
SDPResult::ok => Some(_), SDPResult::Ok => Ok(()),
_ => Err(()), _ => Err(()),
}
} }
} }
@ -118,27 +131,55 @@ impl SDPMedia {
} }
} }
pub fn get_attribute(&self, idx: u32) -> Option<SDPAttribute> { pub fn get_attribute(&self, idx: u32) -> Option<&SDPAttribute> {
unsafe { unsafe {
from_glib_none(ffi::gst_sdp_media_get_attribute(self.to_glib_none().0, idx) ) let ptr = ffi::gst_sdp_media_get_attribute(self.to_glib_none().0, idx);
if ptr.is_null() {
None
} else {
Some(&*(ptr as *mut SDPAttribute))
}
} }
} }
pub fn get_attribute_val(&self, key: &str) -> Option<String> { pub fn get_attribute_val(&self, key: &str) -> Option<&str> {
unsafe { unsafe {
from_glib_none(ffi::gst_sdp_media_get_attribute_val(self.to_glib_none().0, key.to_glib_none().0)) let ptr = ffi::gst_sdp_media_get_attribute_val(self.to_glib_none().0, key.to_glib_none().0);
if ptr.is_null() {
None
} else {
let result = CStr::from_ptr(ptr).to_str();
match result {
Ok(attr) => Some(attr),
Err(_) => None,
}
}
} }
} }
pub fn get_attribute_val_n(&self, key: &str, nth: u32) -> Option<String> { pub fn get_attribute_val_n(&self, key: &str, nth: u32) -> Option<&str> {
unsafe { unsafe {
from_glib_none(ffi::gst_sdp_media_get_attribute_val_n(self.to_glib_none().0, key.to_glib_none().0, nth)) let ptr = ffi::gst_sdp_media_get_attribute_val_n(self.to_glib_none().0, key.to_glib_none().0, nth);
if ptr.is_null() {
None
} else {
let result = CStr::from_ptr(ptr).to_str();
match result {
Ok(attr) => Some(attr),
Err(_) => None,
}
}
} }
} }
pub fn get_bandwidth(&self, idx: u32) -> Option<SDPBandwidth> { pub fn get_bandwidth(&self, idx: u32) -> Option<&SDPBandwidth> {
unsafe { unsafe {
from_glib_none(ffi::gst_sdp_media_get_bandwidth(self.to_glib_none().0, idx)) let ptr = ffi::gst_sdp_media_get_bandwidth(self.to_glib_none().0, idx);
if ptr.is_null() {
None
} else {
Some(&*(ptr as *mut SDPBandwidth))
}
} }
} }
@ -148,33 +189,70 @@ impl SDPMedia {
} }
} }
pub fn get_connection(&self, idx: u32) -> Option<SDPConnection> { pub fn get_connection(&self, idx: u32) -> Option<&SDPConnection> {
unsafe { unsafe {
from_glib_none(ffi::gst_sdp_media_get_connection(self.to_glib_none().0, idx)) let ptr = ffi::gst_sdp_media_get_connection(self.to_glib_none().0, idx);
if ptr.is_null() {
None
} else {
Some(&*(ptr as *mut SDPConnection))
}
} }
} }
pub fn get_format(&self, idx: u32) -> Option<String> { pub fn get_format(&self, idx: u32) -> Option<&str> {
unsafe { unsafe {
from_glib_none(ffi::gst_sdp_media_get_format(self.to_glib_none().0, idx)) let ptr = ffi::gst_sdp_media_get_format(self.to_glib_none().0, idx);
if ptr.is_null() {
None
} else {
let result = CStr::from_ptr(ptr).to_str();
match result {
Ok(attr) => Some(attr),
Err(_) => None,
}
}
} }
} }
pub fn get_information(&self) -> Option<String> { pub fn get_information(&self) -> Option<&str> {
unsafe { unsafe {
from_glib_none(ffi::gst_sdp_media_get_information(self.to_glib_none().0)) let ptr = ffi::gst_sdp_media_get_information(self.to_glib_none().0);
if ptr.is_null() {
None
} else {
let result = CStr::from_ptr(ptr).to_str();
match result {
Ok(attr) => Some(attr),
Err(_) => None,
}
}
} }
} }
pub fn get_key(&self) -> Option<SDPKey> { pub fn get_key(&self) -> Option<&SDPKey> {
unsafe { unsafe {
from_glib_none(ffi::gst_sdp_media_get_key(self.to_glib_none().0)) let ptr = ffi::gst_sdp_media_get_key(self.to_glib_none().0);
if ptr.is_null() {
None
} else {
Some(&*(ptr as *mut SDPKey))
}
} }
} }
pub fn get_media(&self) -> Option<String> { pub fn get_media(&self) -> Option<&str> {
unsafe { unsafe {
from_glib_none(ffi::gst_sdp_media_get_media(self.to_glib_none().0)) let ptr = ffi::gst_sdp_media_get_media(self.to_glib_none().0);
if ptr.is_null() {
None
} else {
let result = CStr::from_ptr(ptr).to_str();
match result {
Ok(attr) => Some(attr),
Err(_) => None,
}
}
} }
} }
@ -190,259 +268,218 @@ impl SDPMedia {
} }
} }
pub fn get_proto(&self) -> Option<String> { pub fn get_proto(&self) -> Option<&str> {
unsafe { unsafe {
from_glib_none(ffi::gst_sdp_media_get_proto(self.to_glib_none().0)) let ptr = ffi::gst_sdp_media_get_proto(self.to_glib_none().0);
} if ptr.is_null() {
} None
} else {
pub fn init(&mut self) -> Result<_, ()> { let result = CStr::from_ptr(ptr).to_str();
let result = unsafe { match result {
from_glib(ffi::gst_sdp_media_init(self.to_glib_none_mut().0)) Ok(attr) => Some(attr),
}; Err(_) => None,
match result { }
SDPResult::ok => Some(_),
_ => Err(()),
} }
} }
} }
pub fn insert_attribute(&mut self, idx: i32, attr: &mut SDPAttribute) -> Result<_, ()> { pub fn insert_attribute(&mut self, idx: i32, mut attr: SDPAttribute) -> Result<(), ()> {
let result = unsafe { let result = unsafe {
from_glib(ffi::gst_sdp_media_insert_attribute(self.to_glib_none_mut().0, idx, attr.to_glib_none_mut().0)) from_glib(ffi::gst_sdp_media_insert_attribute(self.to_glib_none_mut().0, idx, &mut attr.0))
}; };
mem::forget(attr);
match result { match result {
SDPResult::ok => Some(_), SDPResult::Ok => Ok(()),
_ => Err(()), _ => Err(()),
}
} }
} }
pub fn insert_bandwidth(&mut self, idx: i32, bw: &mut SDPBandwidth) -> Result<_, ()> { pub fn insert_bandwidth(&mut self, idx: i32, mut bw: SDPBandwidth) -> Result<(), ()> {
let result = unsafe { let result = unsafe {
from_glib(ffi::gst_sdp_media_insert_bandwidth(self.to_glib_none_mut().0, idx, self.to_glib_none_mut().0)) from_glib(ffi::gst_sdp_media_insert_bandwidth(self.to_glib_none_mut().0, idx, &mut bw.0))
}; };
mem::forget(bw);
match result { match result {
SDPResult::ok => Some(_), SDPResult::Ok => Ok(()),
_ => Err(()), _ => Err(()),
}
} }
} }
pub fn insert_connection(&mut self, idx: i32, conn: &mut SDPConnection) -> Result<_, ()> { pub fn insert_connection(&mut self, idx: i32, mut conn: SDPConnection) -> Result<(), ()> {
let result = unsafe { let result = unsafe {
from_glib(ffi::gst_sdp_media_insert_connection(self.to_glib_none_mut().0, idx, conn.to_glib_none_mut().0)) from_glib(ffi::gst_sdp_media_insert_connection(self.to_glib_none_mut().0, idx, &mut conn.0))
}; };
mem::forget(conn);
match result { match result {
SDPResult::ok => Some(_), SDPResult::Ok => Ok(()),
_ => Err(()), _ => Err(()),
}
} }
} }
pub fn insert_format(&mut self, idx: i32, format: &str) -> Result<_, ()> { pub fn insert_format(&mut self, idx: i32, format: &str) -> Result<(), ()> {
let result = unsafe { let result = unsafe {
from_glib(ffi::gst_sdp_media_insert_format(self.to_glib_none_mut().0, idx, format.to_glib_none().0)) from_glib(ffi::gst_sdp_media_insert_format(self.to_glib_none_mut().0, idx, format.to_glib_none().0))
}; };
match result { match result {
SDPResult::ok => Some(_), SDPResult::Ok => Ok(()),
_ => Err(()), _ => Err(()),
}
} }
} }
#[cfg(any(feature = "v1_8_1", feature = "dox"))] #[cfg(any(feature = "v1_8_1", feature = "dox"))]
pub fn parse_keymgmt(&self) -> Result<MIKEYMessage, SDPResult> { pub fn parse_keymgmt(&self) -> Result<MIKEYMessage, ()> {
unsafe { unsafe {
let mut mikey = ptr::null_mut(); let mut mikey = ptr::null_mut();
let result = from_glib(ffi::gst_sdp_media_parse_keymgmt(self.to_glib_none().0, &mut mikey)); let result = from_glib(ffi::gst_sdp_media_parse_keymgmt(self.to_glib_none().0, &mut mikey));
match result { match result {
SDPResult::ok => Some(from_glib_full(mikey)), SDPResult::Ok => Ok(from_glib_full(mikey)),
_ => Err(result), _ => Err(()),
} }
} }
} }
pub fn remove_attribute(&mut self, idx: u32) -> Result<_, ()> { pub fn remove_attribute(&mut self, idx: u32) -> Result<(), ()> {
let result = unsafe { let result = unsafe {
from_glib(ffi::gst_sdp_media_remove_attribute(self.to_glib_none_mut().0, idx)) from_glib(ffi::gst_sdp_media_remove_attribute(self.to_glib_none_mut().0, idx))
}; };
match result { match result {
SDPResult::ok => Some(_), SDPResult::Ok => Ok(()),
_ => Err(()), _ => Err(()),
}
} }
} }
pub fn remove_bandwidth(&mut self, idx: u32) -> Result<_, ()> { pub fn remove_bandwidth(&mut self, idx: u32) -> Result<(), ()> {
let result = unsafe { let result = unsafe {
from_glib(ffi::gst_sdp_media_remove_bandwidth(self.to_glib_none_mut().0, idx)) from_glib(ffi::gst_sdp_media_remove_bandwidth(self.to_glib_none_mut().0, idx))
}; };
match result { match result {
SDPResult::ok => Some(_), SDPResult::Ok => Ok(()),
_ => Err(()), _ => Err(()),
}
} }
} }
pub fn remove_connection(&mut self, idx: u32) -> Result<_, ()> { pub fn remove_connection(&mut self, idx: u32) -> Result<(), ()> {
let result = unsafe { let result = unsafe {
from_glib(ffi::gst_sdp_media_remove_connection(self.to_glib_none_mut().0, idx)) from_glib(ffi::gst_sdp_media_remove_connection(self.to_glib_none_mut().0, idx))
}; };
match result { match result {
SDPResult::ok => Some(_), SDPResult::Ok => Ok(()),
_ => Err(()), _ => Err(()),
}
} }
} }
pub fn remove_format(&mut self, idx: u32) -> Result<_, ()> { pub fn remove_format(&mut self, idx: u32) -> Result<(), ()> {
let result = unsafe { let result = unsafe {
from_glib(ffi::gst_sdp_media_remove_format(self.to_glib_none_mut().0, idx)) from_glib(ffi::gst_sdp_media_remove_format(self.to_glib_none_mut().0, idx))
}; };
match result { match result {
SDPResult::ok => Some(_), SDPResult::Ok => Ok(()),
_ => Err(()), _ => Err(()),
}
} }
} }
pub fn replace_attribute(&mut self, idx: u32, attr: &mut SDPAttribute) -> Result<_, ()> { pub fn replace_attribute(&mut self, idx: u32, mut attr: SDPAttribute) -> Result<(), ()> {
let result = unsafe { let result = unsafe {
from_glib(ffi::gst_sdp_media_replace_attribute(self.to_glib_none_mut().0, idx, attr.to_glib_none_mut().0)) from_glib(ffi::gst_sdp_media_replace_attribute(self.to_glib_none_mut().0, idx, &mut attr.0))
}; };
mem::forget(attr);
match result { match result {
SDPResult::ok => Some(_), SDPResult::Ok => Ok(()),
_ => Err(()), _ => Err(()),
}
} }
} }
pub fn replace_bandwidth(&mut self, idx: u32, bw: &mut SDPBandwidth) -> Result<_, ()> { pub fn replace_bandwidth(&mut self, idx: u32, mut bw: SDPBandwidth) -> Result<(), ()> {
let result = unsafe { let result = unsafe {
from_glib(ffi::gst_sdp_media_replace_bandwidth(self.to_glib_none_mut().0, idx, bw.to_glib_none_mut().0)) from_glib(ffi::gst_sdp_media_replace_bandwidth(self.to_glib_none_mut().0, idx, &mut bw.0))
}; };
mem::forget(bw);
match result { match result {
SDPResult::ok => Some(_), SDPResult::Ok => Ok(()),
_ => Err(()), _ => Err(()),
}
} }
} }
pub fn replace_connection(&mut self, idx: u32, conn: &mut SDPConnection) -> Result<_, ()> { pub fn replace_connection(&mut self, idx: u32, mut conn: SDPConnection) -> Result<(), ()> {
let result = unsafe { let result = unsafe {
from_glib(ffi::gst_sdp_media_replace_connection(self.to_glib_none_mut().0, idx, conn.to_glib_none_mut().0)) from_glib(ffi::gst_sdp_media_replace_connection(self.to_glib_none_mut().0, idx, &mut conn.0))
}; };
mem::forget(conn);
match result { match result {
SDPResult::ok => Some(_), SDPResult::Ok => Ok(()),
_ => Err(()), _ => Err(()),
}
} }
} }
pub fn replace_format(&mut self, idx: u32, format: &str) -> Result<_, ()> { pub fn replace_format(&mut self, idx: u32, format: &str) -> Result<(), ()> {
let result = unsafe { let result = unsafe {
from_glib(ffi::gst_sdp_media_replace_format(self.to_glib_none_mut().0, idx, format.to_glib_none().0)) from_glib(ffi::gst_sdp_media_replace_format(self.to_glib_none_mut().0, idx, format.to_glib_none().0))
}; };
match result { match result {
SDPResult::ok => Some(_), SDPResult::Ok => Ok(()),
_ => Err(()), _ => Err(()),
}
} }
} }
pub fn set_information(&mut self, information: &str) -> Result<_, ()> { pub fn set_information(&mut self, information: &str) -> Result<(), ()> {
let result = unsafe { let result = unsafe {
from_glib(ffi::gst_sdp_media_set_information(self.to_glib_none_mut().0, information.to_glib_none().0)) from_glib(ffi::gst_sdp_media_set_information(self.to_glib_none_mut().0, information.to_glib_none().0))
}; };
match result { match result {
SDPResult::ok => Some(_), SDPResult::Ok => Ok(()),
_ => Err(()), _ => Err(()),
}
} }
} }
pub fn set_key(&mut self, type_: &str, data: &str) -> Result<_, ()> { pub fn set_key(&mut self, type_: &str, data: &str) -> Result<(), ()> {
let result = unsafe { let result = unsafe {
from_glib(ffi::gst_sdp_media_set_key(self.to_glib_none_mut().0, type_.to_glib_none().0, data.to_glib_none().0)) from_glib(ffi::gst_sdp_media_set_key(self.to_glib_none_mut().0, type_.to_glib_none().0, data.to_glib_none().0))
}; };
match result { match result {
SDPResult::ok => Some(_), SDPResult::Ok => Ok(()),
_ => Err(()), _ => Err(()),
}
} }
} }
pub fn set_media(&mut self, med: &str) -> Result<_, ()> { pub fn set_media(&mut self, med: &str) -> Result<(), ()> {
let result = unsafe { let result = unsafe {
from_glib(ffi::gst_sdp_media_set_media(self.to_glib_none_mut().0, med.to_glib_none().0)) from_glib(ffi::gst_sdp_media_set_media(self.to_glib_none_mut().0, med.to_glib_none().0))
}; };
match result { match result {
SDPResult::ok => Some(_), SDPResult::Ok => Ok(()),
_ => Err(()), _ => Err(()),
}
} }
} }
pub fn set_port_info(&mut self, port: u32, num_ports: u32) -> Result<_, ()> { pub fn set_port_info(&mut self, port: u32, num_ports: u32) -> Result<(), ()> {
let result = unsafe { let result = unsafe {
from_glib(ffi::gst_sdp_media_set_port_info(self.to_glib_none_mut().0, port, num_ports)) from_glib(ffi::gst_sdp_media_set_port_info(self.to_glib_none_mut().0, port, num_ports))
}; };
match result { match result {
SDPResult::ok => Some(_), SDPResult::Ok => Ok(()),
_ => Err(()), _ => Err(()),
}
} }
} }
pub fn set_proto(&mut self, proto: &str) -> Result<_, ()> { pub fn set_proto(&mut self, proto: &str) -> Result<(), ()> {
let result = unsafe { let result = unsafe {
from_glib(ffi::gst_sdp_media_set_proto(self.to_glib_none_mut().0, proto.to_glib_none().0)) from_glib(ffi::gst_sdp_media_set_proto(self.to_glib_none_mut().0, proto.to_glib_none().0))
}; };
match result { match result {
SDPResult::ok => Some(_), SDPResult::Ok => Ok(()),
_ => Err(()), _ => Err(()),
}
} }
} }
pub fn uninit(&mut self) -> Result<_, ()> { pub fn set_media_from_caps(caps: &gst::Caps, media: &mut SDPMedia) -> Result<(), ()> {
let result = unsafe {
from_glib(ffi::gst_sdp_media_uninit(self.to_glib_none_mut().0))
};
match result {
SDPResult::ok => Some(_),
_ => Err(()),
}
}
}
pub fn new() -> (SDPResult, SDPMedia) {
assert_initialized_main_thread!();
unsafe {
let mut media = ptr::null_mut();
let ret = from_glib(ffi::gst_sdp_media_new(&mut media));
(ret, from_glib_full(media))
}
}
pub fn set_media_from_caps(caps: &gst::Caps, media: &mut SDPMedia) -> Result<_, ()> {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
let result = unsafe { let result = unsafe {
from_glib(ffi::gst_sdp_media_set_media_from_caps(caps.to_glib_none().0, media.to_glib_none_mut().0)) from_glib(ffi::gst_sdp_media_set_media_from_caps(caps.to_glib_none().0, media.to_glib_none_mut().0))
}; };
mem::forget(media);
match result { match result {
SDPResult::ok => Some(_), SDPResult::Ok => Ok(()),
_ => Err(()), _ => Err(()),
}
} }
} }
} }
impl Default for SDPMedia {
fn default() -> Self {
Self::new()
}
}
unsafe impl Send for SDPMedia {}

View file

@ -6,12 +6,21 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use ffi; use std::mem;
use glib; use std::ptr;
use glib_ffi; use std::ffi::CStr;
use auto::SDPResult; use ffi;
use m_i_k_e_y_message::MikeyMessage; use gst;
use glib_ffi;
use gobject_ffi;
use glib::translate::*;
use gst::MiniObject;
use auto::{
SDPResult,
MIKEYMessage,
};
use s_d_p_media::SDPMedia; use s_d_p_media::SDPMedia;
use s_d_p_attribute::SDPAttribute; use s_d_p_attribute::SDPAttribute;
use s_d_p_bandwidth::SDPBandwidth; use s_d_p_bandwidth::SDPBandwidth;
@ -35,87 +44,70 @@ impl SDPMessage {
pub fn new() -> SDPMessage { pub fn new() -> SDPMessage {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
unsafe { unsafe {
let msg = glib_ffi::g_malloc(mem::size_of::<ffi::GstSDPMessage>()); let mut msg = mem::zeroed();
ffi::gst_sdp_message_new(msg); ffi::gst_sdp_message_new(&mut msg);
from_glib_full(msg) from_glib_full(msg)
} }
} }
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 result = unsafe { let result = unsafe {
from_glib(ffi::gst_sdp_message_add_attribute(self.to_glib_none_mut().0, key.to_glib_none().0, value.into().to_glib_none().0)) from_glib(ffi::gst_sdp_message_add_attribute(self.to_glib_none_mut().0, key.to_glib_none().0, value.into().to_glib_none().0))
}; };
match result { match result {
SDPResult::ok => Some(_), SDPResult::Ok => Ok(()),
_ => Err(()), _ => Err(()),
}
} }
} }
pub fn add_bandwidth(&mut self, bwtype: &str, bandwidth: u32) -> Result<_, ()> { pub fn add_email(&mut self, email: &str) -> Result<(), ()> {
let result = unsafe {
from_glib(ffi::gst_sdp_message_add_bandwidth(self.to_glib_none_mut().0, bwtype.to_glib_none().0, bandwidth))
};
match result {
SDPResult::ok => Some(_),
_ => Err(()),
}
}
}
pub fn add_email(&mut self, email: &str) -> Result<_, ()> {
let result = unsafe { let result = unsafe {
from_glib(ffi::gst_sdp_message_add_email(self.to_glib_none_mut().0, email.to_glib_none().0)) from_glib(ffi::gst_sdp_message_add_email(self.to_glib_none_mut().0, email.to_glib_none().0))
}; };
match result { match result {
SDPResult::ok => Some(_), SDPResult::Ok => Ok(()),
_ => Err(()), _ => Err(()),
}
} }
} }
pub fn add_media(&mut self, media: SDPMedia) -> Result<_, ()> { pub fn add_media(&mut self, media: SDPMedia) -> Result<(), ()> {
let result = unsafe { let result = unsafe {
from_glib(ffi::gst_sdp_message_add_media(self.to_glib_none_mut().0, media.to_glib_full())) from_glib(ffi::gst_sdp_message_add_media(self.to_glib_none_mut().0, media.to_glib_full() as *mut ffi::GstSDPMedia))
}; };
mem::forget(media); mem::forget(media);
match result { match result {
SDPResult::ok => Some(_), SDPResult::Ok => Ok(()),
_ => Err(()), _ => Err(()),
}
} }
} }
pub fn add_phone(&mut self, phone: &str) -> Result<_, ()> { pub fn add_phone(&mut self, phone: &str) -> Result<(), ()> {
let result = unsafe { let result = unsafe {
from_glib(ffi::gst_sdp_message_add_phone(self.to_glib_none_mut().0, phone.to_glib_none().0)) from_glib(ffi::gst_sdp_message_add_phone(self.to_glib_none_mut().0, phone.to_glib_none().0))
}; };
match result { match result {
SDPResult::ok => Some(_), SDPResult::Ok => Ok(()),
_ => Err(()), _ => Err(()),
}
} }
} }
pub fn add_time(&mut self, start: &str, stop: &str, repeat: &[&str]) -> Result<_, ()> { pub fn add_time(&mut self, start: &str, stop: &str, repeat: &[&str]) -> Result<(), ()> {
let result = unsafe { let result = unsafe {
from_glib(ffi::gst_sdp_message_add_time(self.to_glib_none_mut().0, start.to_glib_none().0, stop.to_glib_none().0, repeat.to_glib_none().0)) from_glib(ffi::gst_sdp_message_add_time(self.to_glib_none_mut().0, start.to_glib_none().0, stop.to_glib_none().0, repeat.to_glib_none().0))
}; };
match result { match result {
SDPResult::ok => Some(_), SDPResult::Ok => Ok(()),
_ => Err(()), _ => Err(()),
}
} }
} }
pub fn add_zone(&mut self, adj_time: &str, typed_time: &str) -> Result<_, ()> { pub fn add_zone(&mut self, adj_time: &str, typed_time: &str) -> Result<(), ()> {
let result = unsafe { let result = unsafe {
from_glib(ffi::gst_sdp_message_add_zone(self.to_glib_none_mut().0, adj_time.to_glib_none().0, typed_time.to_glib_none().0)) from_glib(ffi::gst_sdp_message_add_zone(self.to_glib_none_mut().0, adj_time.to_glib_none().0, typed_time.to_glib_none().0))
}; };
match result { match result {
SDPResult::ok => Some(_), SDPResult::Ok => Ok(()),
_ => Err(()), _ => Err(()),
}
} }
} }
@ -131,14 +123,13 @@ impl SDPMessage {
} }
} }
pub fn attributes_to_caps(&self, caps: &mut gst::CapsRef) -> Result<_, ()> { pub fn attributes_to_caps(&self, caps: &mut gst::CapsRef) -> Result<(), ()> {
let result = unsafe { let result = unsafe {
from_glib(ffi::gst_sdp_message_attributes_to_caps(self.to_glib_none().0, caps.to_glib_none_mut().0)) from_glib(ffi::gst_sdp_message_attributes_to_caps(self.to_glib_none().0, caps.as_mut_ptr()))
}; };
match result { match result {
SDPResult::ok => Some(_), SDPResult::Ok => Ok(()),
_ => Err(()), _ => Err(()),
}
} }
} }
@ -148,14 +139,13 @@ impl SDPMessage {
} }
} }
pub fn dump(&self) -> Result<_, ()> { pub fn dump(&self) -> Result<(), ()> {
let result = unsafe { let result = unsafe {
from_glib(ffi::gst_sdp_message_dump(self.to_glib_none().0)) from_glib(ffi::gst_sdp_message_dump(self.to_glib_none().0))
}; };
match result { match result {
SDPResult::ok => Some(_), SDPResult::Ok => Ok(()),
_ => Err(()), _ => Err(()),
}
} }
} }
@ -165,169 +155,275 @@ impl SDPMessage {
} }
} }
pub fn get_attribute(&self, idx: u32) -> Option<SDPAttribute> { pub fn get_attribute(&self, idx: u32) -> Option<&SDPAttribute> {
unsafe { unsafe {
from_glib_none(ffi::gst_sdp_message_get_attribute(self.to_glib_none().0, idx)) let ptr = ffi::gst_sdp_message_get_attribute(self.to_glib_none().0, idx);
if ptr.is_null() {
None
} else {
Some(&*(ptr as *mut SDPAttribute))
}
} }
} }
pub fn get_attribute_val(&self, key: &str) -> Option<String> { pub fn get_attribute_val(&self, key: &str) -> Option<&str> {
unsafe { unsafe {
from_glib_none(ffi::gst_sdp_message_get_attribute_val(self.to_glib_none().0, key.to_glib_none().0)) let ptr = ffi::gst_sdp_message_get_attribute_val(self.to_glib_none().0, key.to_glib_none().0);
if ptr.is_null() {
None
} else {
let result = CStr::from_ptr(ptr).to_str();
match result {
Ok(attr) => Some(attr),
Err(_) => None,
}
}
} }
} }
pub fn get_attribute_val_n(&self, key: &str, nth: u32) -> Option<String> { pub fn get_attribute_val_n(&self, key: &str, nth: u32) -> Option<&str> {
unsafe { unsafe {
from_glib_none(ffi::gst_sdp_message_get_attribute_val_n(self.to_glib_none().0, key.to_glib_none().0, nth)) let ptr = ffi::gst_sdp_message_get_attribute_val_n(self.to_glib_none().0, key.to_glib_none().0, nth);
if ptr.is_null() {
None
} else {
let result = CStr::from_ptr(ptr).to_str();
match result {
Ok(attr) => Some(attr),
Err(_) => None,
}
}
} }
} }
pub fn get_bandwidth(&self, idx: u32) -> Option<SDPBandwidth> { pub fn get_bandwidth(&self, idx: u32) -> Option<&SDPBandwidth> {
unsafe { unsafe {
from_glib_none(ffi::gst_sdp_message_get_bandwidth()) let ptr = ffi::gst_sdp_message_get_bandwidth(self.to_glib_none().0, idx);
if ptr.is_null() {
None
} else {
Some(&*(ptr as *mut SDPBandwidth))
}
} }
} }
pub fn get_connection(&self) -> Option<SDPConnection> { pub fn get_connection(&self) -> Option<&SDPConnection> {
unsafe { unsafe {
from_glib_none(ffi::gst_sdp_message_get_connection()) let ptr = ffi::gst_sdp_message_get_connection(self.to_glib_none().0);
if ptr.is_null() {
None
} else {
Some(&*(ptr as *mut SDPConnection))
}
} }
} }
pub fn get_email(&self, idx: u32) -> Option<String> { pub fn get_email(&self, idx: u32) -> Option<&str> {
unsafe { unsafe {
from_glib_none(ffi::gst_sdp_message_get_email(self.to_glib_none().0, idx)) let ptr = ffi::gst_sdp_message_get_email(self.to_glib_none().0, idx);
if ptr.is_null() {
None
} else {
let result = CStr::from_ptr(ptr).to_str();
match result {
Ok(attr) => Some(attr),
Err(_) => None,
}
}
} }
} }
pub fn get_information(&self) -> Option<String> { pub fn get_information(&self) -> Option<&str> {
unsafe { unsafe {
from_glib_none(ffi::gst_sdp_message_get_information(self.to_glib_none().0)) let ptr = ffi::gst_sdp_message_get_information(self.to_glib_none().0);
if ptr.is_null() {
None
} else {
let result = CStr::from_ptr(ptr).to_str();
match result {
Ok(attr) => Some(attr),
Err(_) => None,
}
}
} }
} }
pub fn get_key(&self) -> Option<SDPKey> { pub fn get_key(&self) -> Option<&SDPKey> {
unsafe { unsafe {
from_glib_none(ffi::gst_sdp_message_get_key()) let ptr = ffi::gst_sdp_message_get_key(self.to_glib_none().0);
if ptr.is_null() {
None
} else {
Some(&*(ptr as *mut SDPKey))
}
} }
} }
pub fn get_media(&self, idx: u32) -> Option<SDPMedia> { pub fn get_media(&self, idx: u32) -> Option<&SDPMedia> {
unsafe { unsafe {
from_glib_none(ffi::gst_sdp_message_get_media(self.to_glib_none().0, idx)) let ptr = ffi::gst_sdp_message_get_media(self.to_glib_none().0, idx);
if ptr.is_null() {
None
} else {
Some(&*(ptr as *mut SDPMedia))
}
} }
} }
pub fn get_origin(&self) -> Option<SDPOrigin> { pub fn get_origin(&self) -> Option<&SDPOrigin> {
unsafe { unsafe {
from_glib_none(ffi::gst_sdp_message_get_origin()) let ptr = ffi::gst_sdp_message_get_origin(self.to_glib_none().0);
if ptr.is_null() {
None
} else {
Some(&*(ptr as *mut SDPOrigin))
}
} }
} }
pub fn get_phone(&self, idx: u32) -> Option<String> { pub fn get_phone(&self, idx: u32) -> Option<&str> {
unsafe { unsafe {
from_glib_none(ffi::gst_sdp_message_get_phone(self.to_glib_none().0, idx)) let ptr = ffi::gst_sdp_message_get_phone(self.to_glib_none().0, idx);
if ptr.is_null() {
None
} else {
let result = CStr::from_ptr(ptr).to_str();
match result {
Ok(attr) => Some(attr),
Err(_) => None,
}
}
} }
} }
pub fn get_session_name(&self) -> Option<String> { pub fn get_session_name(&self) -> Option<&str> {
unsafe { unsafe {
from_glib_none(ffi::gst_sdp_message_get_session_name(self.to_glib_none().0)) let ptr = ffi::gst_sdp_message_get_session_name(self.to_glib_none().0);
if ptr.is_null() {
None
} else {
let result = CStr::from_ptr(ptr).to_str();
match result {
Ok(attr) => Some(attr),
Err(_) => None,
}
}
} }
} }
pub fn get_time(&self, idx: u32) -> Option<SDPTime> { pub fn get_time(&self, idx: u32) -> Option<&SDPTime> {
unsafe { unsafe {
from_glib_none(ffi::gst_sdp_message_get_time()) let ptr = ffi::gst_sdp_message_get_time(self.to_glib_none().0, idx);
if ptr.is_null() {
None
} else {
Some(&*(ptr as *mut SDPTime))
}
} }
} }
pub fn get_uri(&self) -> Option<String> { pub fn get_uri(&self) -> Option<&str> {
unsafe { unsafe {
from_glib_none(ffi::gst_sdp_message_get_uri(self.to_glib_none().0)) let ptr = ffi::gst_sdp_message_get_uri(self.to_glib_none().0);
if ptr.is_null() {
None
} else {
let result = CStr::from_ptr(ptr).to_str();
match result {
Ok(attr) => Some(attr),
Err(_) => None,
}
}
} }
} }
pub fn get_version(&self) -> Option<String> { pub fn get_version(&self) -> Option<&str> {
unsafe { unsafe {
from_glib_none(ffi::gst_sdp_message_get_version(self.to_glib_none().0)) let ptr = ffi::gst_sdp_message_get_version(self.to_glib_none().0);
if ptr.is_null() {
None
} else {
let result = CStr::from_ptr(ptr).to_str();
match result {
Ok(attr) => Some(attr),
Err(_) => None,
}
}
} }
} }
pub fn get_zone(&self, idx: u32) -> Option<SDPZone> { pub fn get_zone(&self, idx: u32) -> Option<&SDPZone> {
unsafe { unsafe {
from_glib_none(ffi::gst_sdp_message_get_zone()) let ptr = ffi::gst_sdp_message_get_zone(self.to_glib_none().0, idx);
if ptr.is_null() {
None
} else {
Some(&*(ptr as *mut SDPZone))
}
} }
} }
pub fn insert_attribute(&mut self, idx: i32, attr: SDPAttribute) -> Result<_, ()> { pub fn insert_attribute(&mut self, idx: i32, mut attr: SDPAttribute) -> Result<(), ()> {
let result = unsafe { let result = unsafe {
from_glib(ffi::gst_sdp_message_insert_attribute(self.to_glib_none_mut().0, idx, attr.to_glib_full())) from_glib(ffi::gst_sdp_message_insert_attribute(self.to_glib_none_mut().0, idx, &mut attr.0))
}; };
mem::forget(attr); mem::forget(attr);
match result { match result {
SDPResult::ok => Some(_), SDPResult::Ok => Ok(()),
_ => Err(()), _ => Err(()),
}
} }
} }
pub fn insert_bandwidth(&mut self, idx: i32, bw: SDPBandwidth) -> Result<_, ()> { pub fn insert_bandwidth(&mut self, idx: i32, mut bw: SDPBandwidth) -> Result<(), ()> {
let result = unsafe { let result = unsafe {
from_glib(ffi::gst_sdp_message_insert_bandwidth(self.to_glib_none_mut().0, idx, bw.to_glib_full())) from_glib(ffi::gst_sdp_message_insert_bandwidth(self.to_glib_none_mut().0, idx, &mut bw.0))
}; };
mem::forget(bw); mem::forget(bw);
match result { match result {
SDPResult::ok => Some(_), SDPResult::Ok => Ok(()),
_ => Err(()), _ => Err(()),
}
} }
} }
pub fn insert_email(&mut self, idx: i32, email: &str) -> Result<_, ()> { pub fn insert_email(&mut self, idx: i32, email: &str) -> Result<(), ()> {
let result = unsafe { let result = unsafe {
from_glib(ffi::gst_sdp_message_insert_email(self.to_glib_none_mut().0, idx, email.to_glib_none().0)) from_glib(ffi::gst_sdp_message_insert_email(self.to_glib_none_mut().0, idx, email.to_glib_none().0))
}; };
match result { match result {
SDPResult::ok => Some(_), SDPResult::Ok => Ok(()),
_ => Err(()), _ => Err(()),
}
} }
} }
pub fn insert_phone(&mut self, idx: i32, phone: &str) -> Result<_, ()> { pub fn insert_phone(&mut self, idx: i32, phone: &str) -> Result<(), ()> {
let result = unsafe { let result = unsafe {
from_glib(ffi::gst_sdp_message_insert_phone(self.to_glib_none_mut().0, idx, phone.to_glib_none().0)) from_glib(ffi::gst_sdp_message_insert_phone(self.to_glib_none_mut().0, idx, phone.to_glib_none().0))
}; };
match result { match result {
SDPResult::ok => Some(_), SDPResult::Ok => Ok(()),
_ => Err(()), _ => Err(()),
}
} }
} }
pub fn insert_time(&mut self, idx: i32, time: SDPTime) -> Result<_, ()> { pub fn insert_time(&mut self, idx: i32, mut time: SDPTime) -> Result<(), ()> {
let result = unsafe { let result = unsafe {
from_glib(ffi::gst_sdp_message_insert_time(self.to_glib_none_mut().0, idx, time.to_glib_full())) from_glib(ffi::gst_sdp_message_insert_time(self.to_glib_none_mut().0, idx, &mut time.0))
}; };
mem::forget(time); mem::forget(time);
match result { match result {
SDPResult::ok => Some(_), SDPResult::Ok => Ok(()),
_ => Err(()), _ => Err(()),
}
} }
} }
pub fn insert_zone(&mut self, idx: i32, zone: SDPZone) -> Result<_, ()> { pub fn insert_zone(&mut self, idx: i32, mut zone: SDPZone) -> Result<(), ()> {
let result = unsafe { let result = unsafe {
from_glib(ffi::gst_sdp_message_insert_zone(self.to_glib_none_mut().0, idx, zone.to_glib_full())) from_glib(ffi::gst_sdp_message_insert_zone(self.to_glib_none_mut().0, idx, &mut zone.0))
}; };
mem:forget(zone); mem::forget(zone);
match result { match result {
SDPResult::ok => Some(_), SDPResult::Ok => Ok(()),
_ => Err(()), _ => Err(()),
}
} }
} }
@ -338,15 +434,14 @@ impl SDPMessage {
} }
#[cfg(any(feature = "v1_8_1", feature = "dox"))] #[cfg(any(feature = "v1_8_1", feature = "dox"))]
pub fn parse_keymgmt(&self, mikey: MIKEYMessage) -> Result<_, ()> { pub fn parse_keymgmt(&self, mikey: MIKEYMessage) -> Result<(), ()> {
let result = unsafe { let result = unsafe {
from_glib(ffi::gst_sdp_message_parse_keymgmt(self.to_glib_none().0, &mut mikey)) from_glib(ffi::gst_sdp_message_parse_keymgmt(self.to_glib_none().0, &mut mikey))
}; };
mem::forget(mikey); mem::forget(mikey);
match result { match result {
SDPResult::ok => Some(_), SDPResult::Ok => Ok(()),
_ => Err(()), _ => Err(()),
}
} }
} }
@ -356,216 +451,197 @@ impl SDPMessage {
} }
} }
pub fn remove_attribute(&mut self, idx: u32) -> Result<_, ()> { pub fn remove_attribute(&mut self, idx: u32) -> Result<(), ()> {
let result = unsafe { let result = unsafe {
from_glib(ffi::gst_sdp_message_remove_attribute(self.to_glib_none_mut().0, idx)) from_glib(ffi::gst_sdp_message_remove_attribute(self.to_glib_none_mut().0, idx))
}; };
match result { match result {
SDPResult::ok => Some(_), SDPResult::Ok => Ok(()),
_ => Err(()), _ => Err(()),
}
} }
} }
pub fn remove_bandwidth(&mut self, idx: u32) -> Result<_, ()> { pub fn remove_bandwidth(&mut self, idx: u32) -> Result<(), ()> {
let result = unsafe { let result = unsafe {
from_glib(ffi::gst_sdp_message_remove_bandwidth(self.to_glib_none_mut().0, idx)) from_glib(ffi::gst_sdp_message_remove_bandwidth(self.to_glib_none_mut().0, idx))
}; };
match result { match result {
SDPResult::ok => Some(_), SDPResult::Ok => Ok(()),
_ => Err(()), _ => Err(()),
}
} }
} }
pub fn remove_email(&mut self, idx: u32) -> Result<_, ()> { pub fn remove_email(&mut self, idx: u32) -> Result<(), ()> {
let result = unsafe { let result = unsafe {
from_glib(ffi::gst_sdp_message_remove_email(self.to_glib_none_mut().0, idx)) from_glib(ffi::gst_sdp_message_remove_email(self.to_glib_none_mut().0, idx))
}; };
match result { match result {
SDPResult::ok => Some(_), SDPResult::Ok => Ok(()),
_ => Err(()), _ => Err(()),
}
} }
} }
pub fn remove_phone(&mut self, idx: u32) -> Result<_, ()> { pub fn remove_phone(&mut self, idx: u32) -> Result<(), ()> {
let result = unsafe { let result = unsafe {
from_glib(ffi::gst_sdp_message_remove_phone(self.to_glib_none_mut().0, idx)) from_glib(ffi::gst_sdp_message_remove_phone(self.to_glib_none_mut().0, idx))
}; };
match result { match result {
SDPResult::ok => Some(_), SDPResult::Ok => Ok(()),
_ => Err(()), _ => Err(()),
}
} }
} }
pub fn remove_time(&mut self, idx: u32) -> Result<_, ()> { pub fn remove_time(&mut self, idx: u32) -> Result<(), ()> {
let result = unsafe { let result = unsafe {
from_glib(ffi::gst_sdp_message_remove_time(self.to_glib_none_mut().0, idx)) from_glib(ffi::gst_sdp_message_remove_time(self.to_glib_none_mut().0, idx))
}; };
match result { match result {
SDPResult::ok => Some(_), SDPResult::Ok => Ok(()),
_ => Err(()), _ => Err(()),
}
} }
} }
pub fn remove_zone(&mut self, idx: u32) -> Result<_, ()> { pub fn remove_zone(&mut self, idx: u32) -> Result<(), ()> {
let result = unsafe { let result = unsafe {
from_glib(ffi::gst_sdp_message_remove_zone(self.to_glib_none_mut().0, idx)) from_glib(ffi::gst_sdp_message_remove_zone(self.to_glib_none_mut().0, idx))
}; };
match result { match result {
SDPResult::ok => Some(_), SDPResult::Ok => Ok(()),
_ => Err(()), _ => Err(()),
}
} }
} }
pub fn replace_attribute(&mut self, idx: u32, attr: SDPAttribute) -> Result<_, ()> { pub fn replace_attribute(&mut self, idx: u32, mut attr: SDPAttribute) -> Result<(), ()> {
let result = unsafe { let result = unsafe {
from_glib(ffi::gst_sdp_message_replace_attribute(self.to_glib_none_mut().0, idx, attr.to_glib_full())) from_glib(ffi::gst_sdp_message_replace_attribute(self.to_glib_none_mut().0, idx, &mut attr.0))
}; };
mem::forget(attr); mem::forget(attr);
match result { match result {
SDPResult::ok => Some(_), SDPResult::Ok => Ok(()),
_ => Err(()), _ => Err(()),
}
} }
} }
pub fn replace_bandwidth(&mut self, idx: u32, bw: SDPBandwidth) -> Result<_, ()> { pub fn replace_bandwidth(&mut self, idx: u32, mut bw: SDPBandwidth) -> Result<(), ()> {
let result = unsafe { let result = unsafe {
from_glib(ffi::gst_sdp_message_replace_bandwidth(self.to_glib_none_mut().0, idx, bw.to_glib_full())) from_glib(ffi::gst_sdp_message_replace_bandwidth(self.to_glib_none_mut().0, idx, &mut bw.0))
}; };
mem::forget(bw); mem::forget(bw);
match result { match result {
SDPResult::ok => Some(_), SDPResult::Ok => Ok(()),
_ => Err(()), _ => Err(()),
}
} }
} }
pub fn replace_email(&mut self, idx: u32, email: &str) -> Result<_, ()> { pub fn replace_email(&mut self, idx: u32, email: &str) -> Result<(), ()> {
let result = unsafe { let result = unsafe {
from_glib(ffi::gst_sdp_message_replace_email(self.to_glib_none_mut().0, idx, email.to_glib_none().0)) from_glib(ffi::gst_sdp_message_replace_email(self.to_glib_none_mut().0, idx, email.to_glib_none().0))
}; };
match result { match result {
SDPResult::ok => Some(_), SDPResult::Ok => Ok(()),
_ => Err(()), _ => Err(()),
}
} }
} }
pub fn replace_phone(&mut self, idx: u32, phone: &str) -> Result<_, ()> { pub fn replace_phone(&mut self, idx: u32, phone: &str) -> Result<(), ()> {
let result = unsafe { let result = unsafe {
from_glib(ffi::gst_sdp_message_replace_phone(self.to_glib_none_mut().0, idx, phone.to_glib_none().0)) from_glib(ffi::gst_sdp_message_replace_phone(self.to_glib_none_mut().0, idx, phone.to_glib_none().0))
}; };
match result { match result {
SDPResult::ok => Some(_), SDPResult::Ok => Ok(()),
_ => Err(()), _ => Err(()),
}
} }
} }
pub fn replace_time(&mut self, idx: u32, time: SDPTime) -> Result<_, ()> { pub fn replace_time(&mut self, idx: u32, mut time: SDPTime) -> Result<(), ()> {
let result = unsafe { let result = unsafe {
from_glib(ffi::gst_sdp_message_replace_time(self.to_glib_none_mut().0, idx, time.to_glib_full())) from_glib(ffi::gst_sdp_message_replace_time(self.to_glib_none_mut().0, idx, &mut time.0))
}; };
mem::forget(time); mem::forget(time);
match result { match result {
SDPResult::ok => Some(_), SDPResult::Ok => Ok(()),
_ => Err(()), _ => Err(()),
}
} }
} }
pub fn replace_zone(&mut self, idx: u32, zone: SDPZone) -> Result<_, ()> { pub fn replace_zone(&mut self, idx: u32, mut zone: SDPZone) -> Result<(), ()> {
let result = unsafe { let result = unsafe {
from_glib(ffi::gst_sdp_message_replace_zone(self.to_glib_none_mut().0, idx, zone.to_glib_full())) from_glib(ffi::gst_sdp_message_replace_zone(self.to_glib_none_mut().0, idx, &mut zone.0))
}; };
mem::forget(zone); mem::forget(zone);
match result { match result {
SDPResult::ok => Some(_), SDPResult::Ok => Ok(()),
_ => Err(()), _ => Err(()),
}
} }
} }
pub fn set_connection(&mut self, nettype: &str, addrtype: &str, address: &str, ttl: u32, addr_number: u32) -> Result<_, ()> { pub fn set_connection(&mut self, nettype: &str, addrtype: &str, address: &str, ttl: u32, addr_number: u32) -> Result<(), ()> {
let result = unsafe { let result = unsafe {
from_glib(ffi::gst_sdp_message_set_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_message_set_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 { match result {
SDPResult::ok => Some(_), SDPResult::Ok => Ok(()),
_ => Err(()), _ => Err(()),
}
} }
} }
pub fn set_information(&mut self, information: &str) -> Result<_, ()> { pub fn set_information(&mut self, information: &str) -> Result<(), ()> {
let result = unsafe { let result = unsafe {
from_glib(ffi::gst_sdp_message_set_information(self.to_glib_none_mut().0, information.to_glib_none().0)) from_glib(ffi::gst_sdp_message_set_information(self.to_glib_none_mut().0, information.to_glib_none().0))
}; };
match result { match result {
SDPResult::ok => Some(_), SDPResult::Ok => Ok(()),
_ => Err(()), _ => Err(()),
}
} }
} }
pub fn set_key(&mut self, type_: &str, data: &str) -> Result<_, ()> { pub fn set_key(&mut self, type_: &str, data: &str) -> Result<(), ()> {
let result = unsafe { let result = unsafe {
from_glib(ffi::gst_sdp_message_set_key(self.to_glib_none_mut().0, type_.to_glib_none().0, data.to_glib_none().0)) from_glib(ffi::gst_sdp_message_set_key(self.to_glib_none_mut().0, type_.to_glib_none().0, data.to_glib_none().0))
}; };
match result { match result {
SDPResult::ok => Some(_), SDPResult::Ok => Ok(()),
_ => Err(()), _ => Err(()),
}
} }
} }
pub fn set_origin(&mut self, username: &str, sess_id: &str, sess_version: &str, nettype: &str, addrtype: &str, addr: &str) -> Result<_, ()> { pub fn set_origin(&mut self, username: &str, sess_id: &str, sess_version: &str, nettype: &str, addrtype: &str, addr: &str) -> Result<(), ()> {
let result = unsafe { let result = unsafe {
from_glib(ffi::gst_sdp_message_set_origin(self.to_glib_none_mut().0, username.to_glib_none().0, sess_id.to_glib_none().0, sess_version.to_glib_none().0, nettype.to_glib_none().0, addrtype.to_glib_none().0, addr.to_glib_none().0)) from_glib(ffi::gst_sdp_message_set_origin(self.to_glib_none_mut().0, username.to_glib_none().0, sess_id.to_glib_none().0, sess_version.to_glib_none().0, nettype.to_glib_none().0, addrtype.to_glib_none().0, addr.to_glib_none().0))
}; };
match result { match result {
SDPResult::ok => Some(_), SDPResult::Ok => Ok(()),
_ => Err(()), _ => Err(()),
}
} }
} }
pub fn set_session_name(&mut self, session_name: &str) -> Result<_, ()> { pub fn set_session_name(&mut self, session_name: &str) -> Result<(), ()> {
let result = unsafe { let result = unsafe {
from_glib(ffi::gst_sdp_message_set_session_name(self.to_glib_none_mut().0, session_name.to_glib_none().0)) from_glib(ffi::gst_sdp_message_set_session_name(self.to_glib_none_mut().0, session_name.to_glib_none().0))
}; };
match result { match result {
SDPResult::ok => Some(_), SDPResult::Ok => Ok(()),
_ => Err(()), _ => Err(()),
}
} }
} }
pub fn set_uri(&mut self, uri: &str) -> Result<_, ()> { pub fn set_uri(&mut self, uri: &str) -> Result<(), ()> {
let result = unsafe { let result = unsafe {
from_glib(ffi::gst_sdp_message_set_uri(self.to_glib_none_mut().0, uri.to_glib_none().0)) from_glib(ffi::gst_sdp_message_set_uri(self.to_glib_none_mut().0, uri.to_glib_none().0))
}; };
match result { match result {
SDPResult::ok => Some(_), SDPResult::Ok => Ok(()),
_ => Err(()), _ => Err(()),
}
} }
} }
pub fn set_version(&mut self, version: &str) -> Result<_, ()> { pub fn set_version(&mut self, version: &str) -> Result<(), ()> {
let result = unsafe { let result = unsafe {
from_glib(ffi::gst_sdp_message_set_version(self.to_glib_none_mut().0, version.to_glib_none().0)) from_glib(ffi::gst_sdp_message_set_version(self.to_glib_none_mut().0, version.to_glib_none().0))
}; };
match result { match result {
SDPResult::ok => Some(_), SDPResult::Ok => Ok(()),
_ => Err(()), _ => Err(()),
}
} }
} }
@ -588,27 +664,27 @@ impl SDPMessage {
} }
} }
pub fn parse_buffer(data: &[u8]) -> Result<Self, SDPResult> { pub fn parse_buffer(data: &[u8]) -> Result<Self, ()> {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
unsafe { unsafe {
let size = data.len() as u32; let size = data.len() as u32;
let mut msg = glib_ffi::g_malloc(mem::size_of::<ffi::GstSDPMessage>()); let msg = glib_ffi::g_malloc0(mem::size_of::<ffi::GstSDPMessage>()) as *mut ffi::GstSDPMessage;
let result = from_glib(ffi::gst_sdp_message_parse_buffer(data.to_glib_none().0, size, &mut msg)); let result = from_glib(ffi::gst_sdp_message_parse_buffer(data.to_glib_none().0, size, msg));
match result { match result {
SDPResult::ok => Some(from_glib_full(msg)), SDPResult::Ok => Ok(from_glib_full(msg)),
_ => Err(result), _ => Err(()),
} }
} }
} }
pub fn parse_uri(uri: &str, msg: &mut SDPMessage) -> Result<Self, SDPResult> { pub fn parse_uri(uri: &str) -> Result<Self, ()> {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
unsafe { unsafe {
let mut msg = glib_ffi::g_malloc(mem::size_of::<ffi::GstSDPMessage>()); let msg = glib_ffi::g_malloc0(mem::size_of::<ffi::GstSDPMessage>()) as *mut ffi::GstSDPMessage;
let result = from_glib(ffi::gst_sdp_message_parse_uri(uri.to_glib_none().0, &mut msg)); let result = from_glib(ffi::gst_sdp_message_parse_uri(uri.to_glib_none().0, msg));
match result { match result {
SDPResult::ok => Some(from_glib_full(msg)), SDPResult::Ok => Ok(from_glib_full(msg)),
_ => Err(result), _ => Err(()),
} }
} }
} }

View file

@ -10,30 +10,43 @@ use std::ffi::CStr;
use ffi; use ffi;
pub struct SDPOrigin(ffi::GstSDPOrigin); #[repr(C)]
pub struct SDPOrigin(pub ffi::GstSDPOrigin);
impl SDPOrigin { impl SDPOrigin {
pub fn username(&self) -> &str { pub fn username(&self) -> &str {
CStr::from_ptr(self.0.username).to_str().unwrap() unsafe {
CStr::from_ptr(self.0.username).to_str().unwrap()
}
} }
pub fn sess_id(&self) -> &str { pub fn sess_id(&self) -> &str {
CStr::from_ptr(self.0.sess_id).to_str().unwrap() unsafe {
CStr::from_ptr(self.0.sess_id).to_str().unwrap()
}
} }
pub fn sess_version(&self) -> &str { pub fn sess_version(&self) -> &str {
CStr::from_ptr(self.0.sess_version).to_str().unwrap() unsafe {
CStr::from_ptr(self.0.sess_version).to_str().unwrap()
}
} }
pub fn nettype(&self) -> &str { pub fn nettype(&self) -> &str {
CStr::from_ptr(self.0.nettype).to_str().unwrap() unsafe {
CStr::from_ptr(self.0.nettype).to_str().unwrap()
}
} }
pub fn addrtype(&self) -> &str { pub fn addrtype(&self) -> &str {
CStr::from_ptr(self.0.addrtype).to_str().unwrap() unsafe {
CStr::from_ptr(self.0.addrtype).to_str().unwrap()
}
} }
pub fn addr(&self) -> &str { pub fn addr(&self) -> &str {
CStr::from_ptr(self.0.addr).to_str().unwrap() unsafe {
CStr::from_ptr(self.0.addr).to_str().unwrap()
}
} }
} }

View file

@ -7,20 +7,23 @@
// except according to those terms. // except according to those terms.
use std::mem; use std::mem;
use std::ffi:CStr; use std::os::raw::c_char;
use std::ffi::CStr;
use ffi; use ffi;
use glib::translate::*;
use auto::SDPResult; use auto::SDPResult;
pub struct SDPTime(ffi::GstSDPTime); #[repr(C)]
pub struct SDPTime(pub ffi::GstSDPTime);
impl SDPTime { impl SDPTime {
pub fn new(start: &str, stop: &str, repeat: &[&str]) -> Result<Self, SDPResult> { pub fn new(start: &str, stop: &str, repeat: &[&str]) -> Result<Self, ()> {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
unsafe { unsafe {
let mut time = mem::uninitialized(); let mut time = mem::zeroed();
let result =from_glib(ffi::gst_sdp_time_set( let result = from_glib(ffi::gst_sdp_time_set(
&mut time, &mut time,
start.to_glib_none().0, start.to_glib_none().0,
stop.to_glib_none().0, stop.to_glib_none().0,
@ -28,32 +31,40 @@ impl SDPTime {
)); ));
match result { match result {
SDPResult::Ok => Ok(SDPTime(time)), SDPResult::Ok => Ok(SDPTime(time)),
_ => Err(result), _ => Err(()),
} }
} }
} }
pub fn start(&self) -> &str { pub fn start(&self) -> &str {
CStr::from_ptr(self.0.start).to_str().unwrap() unsafe {
CStr::from_ptr(self.0.start).to_str().unwrap()
}
} }
pub fn stop(&self) -> &str { pub fn stop(&self) -> &str {
CStr::from_ptr(self.0.stop).to_str().unwrap() unsafe {
CStr::from_ptr(self.0.stop).to_str().unwrap()
}
} }
pub fn repeat(&self) -> Vec<&str> { pub fn repeat(&self) -> Vec<&str> {
let arr = (*self.0.repeat).data as *const *const c_char; unsafe {
let len = (*self.0.repeat).len as usize; let arr = (*self.0.repeat).data as *const *const c_char;
let vec = Vec::with_capacity(len); let len = (*self.0.repeat).len as usize;
for i in 0..len { let mut vec = Vec::with_capacity(len);
vec.push(CStr::from_ptr(arr.offset(i)).to_str().unwrap()); for i in 0..len {
vec.push(CStr::from_ptr(*arr.offset(i as isize)).to_str().unwrap());
}
vec
} }
vec
} }
} }
impl Drop for SDPTime { impl Drop for SDPTime {
fn drop(&mut self) { fn drop(&mut self) {
ffi::gst_sdp_time_clear(self.to_glib_none_mut().0); unsafe {
ffi::gst_sdp_time_clear(&mut self.0);
}
} }
} }

View file

@ -7,38 +7,46 @@
// except according to those terms. // except according to those terms.
use std::mem; use std::mem;
use std::ffi:CStr; use std::ffi::CStr;
use ffi;
use glib::translate::*;
use auto::SDPResult; use auto::SDPResult;
use ffi; #[repr(C)]
pub struct SDPZone(pub ffi::GstSDPZone);
pub struct SDPZone(ffi::GstSDPZone);
impl SDPZone { impl SDPZone {
pub fn new(time: &str, typed_time: &str) -> Result<Self, SDPResult> { pub fn new(time: &str, typed_time: &str) -> Result<Self, ()> {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
unsafe { unsafe {
let mut zone = mem::uninitialized(); let mut zone = mem::zeroed();
let result = from_glib(ffi::gst_sdp_zone_set(&mut zone, time.to_glib_none().0, typed_time.to_glib_none().0)); let result = from_glib(ffi::gst_sdp_zone_set(&mut zone, time.to_glib_none().0, typed_time.to_glib_none().0));
match result { match result {
SDPResult::Ok => Ok(SDPZone(zone)), SDPResult::Ok => Ok(SDPZone(zone)),
_ => Err(result), _ => Err(()),
} }
} }
} }
pub fn time(&self) -> &str { pub fn time(&self) -> &str {
CStr::from_ptr(self.0.time).to_str().unwrap() unsafe {
CStr::from_ptr(self.0.time).to_str().unwrap()
}
} }
pub fn typed_time(&self) -> &str { pub fn typed_time(&self) -> &str {
CStr::from_ptr(self.0.typed_time).to_str().unwrap() unsafe {
CStr::from_ptr(self.0.typed_time).to_str().unwrap()
}
} }
} }
impl Drop for SDPZone { impl Drop for SDPZone {
fn drop(&mut self) { fn drop(&mut self) {
ffi::gst_sdp_zone_clear(self.to_glib_none_mut().0); unsafe {
ffi::gst_sdp_zone_clear(&mut self.0);
}
} }
} }