Add SDPMessage definition and other manual SDP definitions.

This commit is contained in:
Bo Du 2018-03-29 14:43:25 -04:00 committed by Sebastian Dröge
parent 92016945fc
commit 36d538c0a0
15 changed files with 1617 additions and 2 deletions

View file

@ -1,4 +1,4 @@
// Copyright (C) 2017 Sebastian Dröge <sebastian@centricular.com>
// 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
@ -16,6 +16,14 @@ extern crate gstreamer as gst;
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 {
panic!("GStreamer has not been initialized. Call `gst::init` first.");
}
)
}
macro_rules! skip_assert_initialized {
() => {};
}
@ -29,6 +37,23 @@ 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 s_d_p_attribute;
mod s_d_p_bandwidth;
mod s_d_p_connection;
mod s_d_p_key;
mod s_d_p_origin;
mod s_d_p_time;
mod s_d_p_zone;
mod m_i_k_e_y_message;
mod m_i_k_e_y_payload;
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;
pub use s_d_p_message::SDPMessage;
// Re-export all the traits in a prelude module, so that applications
// can always "use gst::prelude::*" without getting conflicts
pub mod prelude {
@ -36,4 +61,6 @@ pub mod prelude {
pub use gst::prelude::*;
pub use auto::traits::*;
pub use s_d_p_message::SDPMessage;
}

View file

@ -0,0 +1,23 @@
// 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::mem;
use std::ptr;
use ffi;
use glib::translate::*;
use glib_ffi;
use libc::c_void;
pub struct MIKEYDecryptInfo(ffi::GstMIKEYDecryptInfo);
impl MIKEYDecryptInfo {
pub fn new() -> MIKEYDecryptInfo {
MIKEYDecryptInfo(ffi::GstMIKEYDecryptInfo(ptr::null_mut() as *mut c_void))
}
}

View file

@ -0,0 +1,23 @@
// 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::mem;
use std::ptr;
use ffi;
use glib::translate::*;
use glib_ffi;
use libc::c_void;
pub struct MIKEYEncryptInfo(ffi::GstMIKEYEncryptInfo);
impl MIKEYEncryptInfo {
pub fn new() -> MIKEYEncryptInfo {
MIKEYEncryptInfo(ffi::GstMIKEYEncryptInfo(ptr::null_mut() as *mut c_void))
}
}

View file

@ -0,0 +1,38 @@
// 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::mem;
use std::ptr;
use ffi;
use glib::translate::*;
use glib_ffi;
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,
})
}
pub fn policy(&self) -> u8 {
self.0.policy
}
pub fn ssrc(&self) -> u32 {
self.0.ssrc
}
pub fn roc(&self) -> u32 {
self.0.roc
}
}

View file

@ -0,0 +1,98 @@
// 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::mem;
use std::ptr;
use ffi;
use glib::translate::*;
use glib_ffi;
use gobject_ffi;
use gst;
use auto::{
MIKEYMessage,
MIKEYTSType,
};
use m_i_k_e_y_payload::MIKEYPayload;
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;
impl MIKEYMessage {
pub fn new_from_bytes(bytes: glib::Bytes, info: MIKEYDecryptInfo) -> Result<MIKEYMessage, Error> {
unsafe {
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);
mem::forget(bytes);
mem::forget(info);
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> {
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);
mem::forget(info);
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))
}
}
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))
}
}
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()));
mem::forget(map);
ret
}
}
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()));
mem::forget(payload);
ret
}
}
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()));
mem::forget(map);
ret
}
}
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()));
mem::forget(payload);
ret
}
}
}

View file

@ -0,0 +1,35 @@
// 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::mem;
use std::ptr;
use ffi;
use glib::translate::*;
use glib_ffi;
use gobject_ffi;
use auto::MIKEYPayload;
impl MIKEYPayload {
pub fn kemac_add_sub(&mut self, newpay: MIKEYPayload) -> bool {
unsafe {
from_glib(ffi::gst_mikey_payload_kemac_add_sub(self.to_glib_none_mut().0, newpay.to_glib_full()))
}
mem::forget(newpay);
}
//pub fn sp_get_param(&self, idx: u32) -> /*Ignored*/Option<MIKEYPayloadSPParam> {
// unsafe { TODO: call ffi::gst_mikey_payload_sp_get_param() }
//}
//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,44 @@
// 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::mem;
use std::ffi::CStr;
use ffi;
use auto::SDPResult;
pub struct SDPAttribute(ffi::GstSDPAttribute);
impl SDPAttribute {
pub fn new(key: &str, value: &str) -> Result<Self, SDPResult> {
assert_initialized_main_thread!();
unsafe {
let mut attr = mem::uninitialized();
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(result),
}
}
}
pub fn key(&self) -> &str {
CStr::from_ptr(self.0.key).to_str().unwrap()
}
pub fn value(&self) -> &str {
CStr::from_ptr(self.0.value).to_str().unwrap()
}
}
impl Drop for SDPAttribute {
fn drop(&mut self) {
ffi::gst_sdp_attribute_clear(self.to_glib_none_mut().0);
}
}

View file

@ -0,0 +1,44 @@
// 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::mem;
use std::ffi::CStr;
use ffi;
use auto::SDPResult;
pub struct SDPBandwidth(ffi::GstSDPBandwidth);
impl SDPBandwidth {
pub fn new(bwtype: &str, bandwidth: u32) -> Result<Self, SDPResult> {
assert_initialized_main_thread!();
unsafe {
let mut bw = mem::uninitialized();
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(result),
}
}
}
pub fn bwtype(&self) -> &str {
CStr::from_ptr(self.0.bwtype).to_str().unwrap()
}
pub fn value(&self) -> u32 {
self.0.bandwidth as u32
}
}
impl Drop for SDPBandwidth {
fn drop(&mut self) {
ffi::gst_sdp_bandwidth_clear(self.to_glib_none_mut().0);
}
}

View file

@ -0,0 +1,64 @@
// 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::mem;
use std::ffi::CStr;
use ffi;
use auto::SDPResult;
pub struct SDPConnection(ffi::GstSDPConnection);
impl SDPConnection {
pub fn new(nettype: &str, addrtype: &str, address: &str, ttl: u32, addr_number: u32) -> Result<Self, SDPResult> {
assert_initialized_main_thread!();
unsafe {
let mut conn = mem::uninitialized();
let result = from_glib(ffi::gst_sdp_connection_set(
&mut conn,
nettype.to_glib_none().0,
addrtype.to_glib_none().0,
address.to_glib_none().0,
ttl,
addr_number,
));
match result {
SDPResult::Ok => Ok(SDPConnection(conn)),
_ => Err(result),
}
}
}
pub fn nettype(&self) -> &str {
CStr::from_ptr(self.0.nettype).to_str().unwrap()
}
pub fn addrtype(&self) -> &str {
CStr::from_ptr(self.0.addrtype).to_str().unwrap()
}
pub fn address(&self) -> &str {
CStr::from_ptr(self.0.address).to_str().unwrap()
}
pub fn ttl(&self) -> u32 {
self.0.ttl as u32
}
pub fn addr_number(&self) -> u32 {
self.0.addr_number as u32
}
}
impl Drop for SDPConnection {
fn drop(&mut self) {
ffi::gst_sdp_connection_clear(self.to_glib_none_mut().0);
}
}

View file

@ -0,0 +1,23 @@
// 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::ffi::CStr;
use ffi;
pub struct SDPKey(ffi::GstSDPKey);
impl SDPKey {
pub fn type(&self) -> &str {
CStr::from_ptr(self.0.type_).to_str().unwrap()
}
pub fn data(&self) -> &str {
CStr::from_ptr(self.0.data).to_str().unwrap()
}
}

View file

@ -0,0 +1,448 @@
// 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::mem;
use std::ptr;
use ffi;
use glib::translate::*;
use glib_ffi;
use gst;
use auto::SDPResult;
use m_i_k_e_y_message::MIKEYMessage;
use s_d_p_attribute::SDPAttribute;
use s_d_p_bandwidth::SDPBandwidth;
use s_d_p_connection::SDPConnection;
use s_d_p_key::SDPKey;
glib_wrapper! {
pub struct SDPMedia(Boxed<ffi::GstSDPMedia>);
match fn {
copy => |ptr| ffi::gst_sdp_media_copy(mut_override(ptr)),
free => |ptr| ffi::gst_sdp_media_free(ptr),
}
}
impl SDPMedia {
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))
};
match result {
SDPResult::ok => Some(_),
_ => Err(()),
}
}
}
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))
};
match result {
SDPResult::ok => Some(_),
_ => Err(()),
}
}
}
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))
};
match result {
SDPResult::ok => Some(_),
_ => Err(()),
}
}
}
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))
};
match result {
SDPResult::ok => Some(_),
_ => Err(()),
}
}
}
pub fn as_text(&self) -> Option<String> {
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)
}
}
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))
};
match result {
SDPResult::ok => Some(_),
_ => Err(()),
}
}
}
pub fn bandwidths_len(&self) -> u32 {
unsafe {
ffi::gst_sdp_media_bandwidths_len(self.to_glib_none().0)
}
}
pub fn connections_len(&self) -> u32 {
unsafe {
ffi::gst_sdp_media_connections_len(self.to_glib_none().0)
}
}
pub fn formats_len(&self) -> u32 {
unsafe {
ffi::gst_sdp_media_formats_len(self.to_glib_none().0)
}
}
pub fn get_attribute(&self, idx: u32) -> Option<SDPAttribute> {
unsafe {
from_glib_none(ffi::gst_sdp_media_get_attribute(self.to_glib_none().0, idx) )
}
}
pub fn get_attribute_val(&self, key: &str) -> Option<String> {
unsafe {
from_glib_none(ffi::gst_sdp_media_get_attribute_val(self.to_glib_none().0, key.to_glib_none().0))
}
}
pub fn get_attribute_val_n(&self, key: &str, nth: u32) -> Option<String> {
unsafe {
from_glib_none(ffi::gst_sdp_media_get_attribute_val_n(self.to_glib_none().0, key.to_glib_none().0, nth))
}
}
pub fn get_bandwidth(&self, idx: u32) -> Option<SDPBandwidth> {
unsafe {
from_glib_none(ffi::gst_sdp_media_get_bandwidth(self.to_glib_none().0, idx))
}
}
pub fn get_caps_from_media(&self, pt: i32) -> Option<gst::Caps> {
unsafe {
from_glib_full(ffi::gst_sdp_media_get_caps_from_media(self.to_glib_none().0, pt))
}
}
pub fn get_connection(&self, idx: u32) -> Option<SDPConnection> {
unsafe {
from_glib_none(ffi::gst_sdp_media_get_connection(self.to_glib_none().0, idx))
}
}
pub fn get_format(&self, idx: u32) -> Option<String> {
unsafe {
from_glib_none(ffi::gst_sdp_media_get_format(self.to_glib_none().0, idx))
}
}
pub fn get_information(&self) -> Option<String> {
unsafe {
from_glib_none(ffi::gst_sdp_media_get_information(self.to_glib_none().0))
}
}
pub fn get_key(&self) -> Option<SDPKey> {
unsafe {
from_glib_none(ffi::gst_sdp_media_get_key(self.to_glib_none().0))
}
}
pub fn get_media(&self) -> Option<String> {
unsafe {
from_glib_none(ffi::gst_sdp_media_get_media(self.to_glib_none().0))
}
}
pub fn get_num_ports(&self) -> u32 {
unsafe {
ffi::gst_sdp_media_get_num_ports(self.to_glib_none().0)
}
}
pub fn get_port(&self) -> u32 {
unsafe {
ffi::gst_sdp_media_get_port(self.to_glib_none().0)
}
}
pub fn get_proto(&self) -> Option<String> {
unsafe {
from_glib_none(ffi::gst_sdp_media_get_proto(self.to_glib_none().0))
}
}
pub fn init(&mut self) -> Result<_, ()> {
let result = unsafe {
from_glib(ffi::gst_sdp_media_init(self.to_glib_none_mut().0))
};
match result {
SDPResult::ok => Some(_),
_ => Err(()),
}
}
}
pub fn insert_attribute(&mut self, idx: i32, attr: &mut SDPAttribute) -> Result<_, ()> {
let result = unsafe {
from_glib(ffi::gst_sdp_media_insert_attribute(self.to_glib_none_mut().0, idx, attr.to_glib_none_mut().0))
};
match result {
SDPResult::ok => Some(_),
_ => Err(()),
}
}
}
pub fn insert_bandwidth(&mut self, idx: i32, bw: &mut SDPBandwidth) -> Result<_, ()> {
let result = unsafe {
from_glib(ffi::gst_sdp_media_insert_bandwidth(self.to_glib_none_mut().0, idx, self.to_glib_none_mut().0))
};
match result {
SDPResult::ok => Some(_),
_ => Err(()),
}
}
}
pub fn insert_connection(&mut self, idx: i32, conn: &mut SDPConnection) -> Result<_, ()> {
let result = unsafe {
from_glib(ffi::gst_sdp_media_insert_connection(self.to_glib_none_mut().0, idx, conn.to_glib_none_mut().0))
};
match result {
SDPResult::ok => Some(_),
_ => Err(()),
}
}
}
pub fn insert_format(&mut self, idx: i32, format: &str) -> Result<_, ()> {
let result = unsafe {
from_glib(ffi::gst_sdp_media_insert_format(self.to_glib_none_mut().0, idx, format.to_glib_none().0))
};
match result {
SDPResult::ok => Some(_),
_ => Err(()),
}
}
}
#[cfg(any(feature = "v1_8_1", feature = "dox"))]
pub fn parse_keymgmt(&self) -> Result<MIKEYMessage, SDPResult> {
unsafe {
let mut mikey = ptr::null_mut();
let result = from_glib(ffi::gst_sdp_media_parse_keymgmt(self.to_glib_none().0, &mut mikey));
match result {
SDPResult::ok => Some(from_glib_full(mikey)),
_ => Err(result),
}
}
}
pub fn remove_attribute(&mut self, idx: u32) -> Result<_, ()> {
let result = unsafe {
from_glib(ffi::gst_sdp_media_remove_attribute(self.to_glib_none_mut().0, idx))
};
match result {
SDPResult::ok => Some(_),
_ => Err(()),
}
}
}
pub fn remove_bandwidth(&mut self, idx: u32) -> Result<_, ()> {
let result = unsafe {
from_glib(ffi::gst_sdp_media_remove_bandwidth(self.to_glib_none_mut().0, idx))
};
match result {
SDPResult::ok => Some(_),
_ => Err(()),
}
}
}
pub fn remove_connection(&mut self, idx: u32) -> Result<_, ()> {
let result = unsafe {
from_glib(ffi::gst_sdp_media_remove_connection(self.to_glib_none_mut().0, idx))
};
match result {
SDPResult::ok => Some(_),
_ => Err(()),
}
}
}
pub fn remove_format(&mut self, idx: u32) -> Result<_, ()> {
let result = unsafe {
from_glib(ffi::gst_sdp_media_remove_format(self.to_glib_none_mut().0, idx))
};
match result {
SDPResult::ok => Some(_),
_ => Err(()),
}
}
}
pub fn replace_attribute(&mut self, idx: u32, attr: &mut SDPAttribute) -> Result<_, ()> {
let result = unsafe {
from_glib(ffi::gst_sdp_media_replace_attribute(self.to_glib_none_mut().0, idx, attr.to_glib_none_mut().0))
};
match result {
SDPResult::ok => Some(_),
_ => Err(()),
}
}
}
pub fn replace_bandwidth(&mut self, idx: u32, bw: &mut SDPBandwidth) -> Result<_, ()> {
let result = unsafe {
from_glib(ffi::gst_sdp_media_replace_bandwidth(self.to_glib_none_mut().0, idx, bw.to_glib_none_mut().0))
};
match result {
SDPResult::ok => Some(_),
_ => Err(()),
}
}
}
pub fn replace_connection(&mut self, idx: u32, conn: &mut SDPConnection) -> Result<_, ()> {
let result = unsafe {
from_glib(ffi::gst_sdp_media_replace_connection(self.to_glib_none_mut().0, idx, conn.to_glib_none_mut().0))
};
match result {
SDPResult::ok => Some(_),
_ => Err(()),
}
}
}
pub fn replace_format(&mut self, idx: u32, format: &str) -> Result<_, ()> {
let result = unsafe {
from_glib(ffi::gst_sdp_media_replace_format(self.to_glib_none_mut().0, idx, format.to_glib_none().0))
};
match result {
SDPResult::ok => Some(_),
_ => Err(()),
}
}
}
pub fn set_information(&mut self, information: &str) -> Result<_, ()> {
let result = unsafe {
from_glib(ffi::gst_sdp_media_set_information(self.to_glib_none_mut().0, information.to_glib_none().0))
};
match result {
SDPResult::ok => Some(_),
_ => Err(()),
}
}
}
pub fn set_key(&mut self, type_: &str, data: &str) -> Result<_, ()> {
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))
};
match result {
SDPResult::ok => Some(_),
_ => Err(()),
}
}
}
pub fn set_media(&mut self, med: &str) -> Result<_, ()> {
let result = unsafe {
from_glib(ffi::gst_sdp_media_set_media(self.to_glib_none_mut().0, med.to_glib_none().0))
};
match result {
SDPResult::ok => Some(_),
_ => Err(()),
}
}
}
pub fn set_port_info(&mut self, port: u32, num_ports: u32) -> Result<_, ()> {
let result = unsafe {
from_glib(ffi::gst_sdp_media_set_port_info(self.to_glib_none_mut().0, port, num_ports))
};
match result {
SDPResult::ok => Some(_),
_ => Err(()),
}
}
}
pub fn set_proto(&mut self, proto: &str) -> Result<_, ()> {
let result = unsafe {
from_glib(ffi::gst_sdp_media_set_proto(self.to_glib_none_mut().0, proto.to_glib_none().0))
};
match result {
SDPResult::ok => Some(_),
_ => Err(()),
}
}
}
pub fn uninit(&mut self) -> 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!();
let result = unsafe {
from_glib(ffi::gst_sdp_media_set_media_from_caps(caps.to_glib_none().0, media.to_glib_none_mut().0))
};
match result {
SDPResult::ok => Some(_),
_ => Err(()),
}
}
}
}
impl Default for SDPMedia {
fn default() -> Self {
Self::new()
}
}
unsafe impl Send for SDPMedia {}

View file

@ -1,11 +1,617 @@
// 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 ffi;
use glib;
use glib_ffi;
use auto::SDPResult;
use m_i_k_e_y_message::MikeyMessage;
use s_d_p_media::SDPMedia;
use s_d_p_attribute::SDPAttribute;
use s_d_p_bandwidth::SDPBandwidth;
use s_d_p_connection::SDPConnection;
use s_d_p_key::SDPKey;
use s_d_p_origin::SDPOrigin;
use s_d_p_time::SDPTime;
use s_d_p_zone::SDPZone;
glib_wrapper! {
pub struct SDPMessage(Boxed<ffi::GstSDPMessage>);
match fn {
copy => |ptr| gobject_ffi::g_boxed_copy(ffi::gst_sdp_message_get_type(), ptr as *mut _) as *mut ffi::GstSDPMessage,
free => |ptr| gobject_ffi::g_boxed_free(ffi::gst_sdp_message_get_type(), ptr as *mut _),
get_type => || ffi::gst_sdp_message_get_type(),
}
}
impl SDPMessage {
pub fn new() -> SDPMessage {
assert_initialized_main_thread!();
unsafe {
let msg = glib_ffi::g_malloc(mem::size_of::<ffi::GstSDPMessage>());
let _ = ffi::gst_sdp_message_new(msg);
ffi::gst_sdp_message_new(msg);
from_glib_full(msg)
}
}
pub fn add_attribute<'a, P: Into<Option<&'a str>>>(&mut self, key: &str, value: P) -> Result<_, ()> {
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))
};
match result {
SDPResult::ok => Some(_),
_ => Err(()),
}
}
}
pub fn add_bandwidth(&mut self, bwtype: &str, bandwidth: u32) -> 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 {
from_glib(ffi::gst_sdp_message_add_email(self.to_glib_none_mut().0, email.to_glib_none().0))
};
match result {
SDPResult::ok => Some(_),
_ => Err(()),
}
}
}
pub fn add_media(&mut self, media: SDPMedia) -> Result<_, ()> {
let result = unsafe {
from_glib(ffi::gst_sdp_message_add_media(self.to_glib_none_mut().0, media.to_glib_full()))
};
mem::forget(media);
match result {
SDPResult::ok => Some(_),
_ => Err(()),
}
}
}
pub fn add_phone(&mut self, phone: &str) -> Result<_, ()> {
let result = unsafe {
from_glib(ffi::gst_sdp_message_add_phone(self.to_glib_none_mut().0, phone.to_glib_none().0))
};
match result {
SDPResult::ok => Some(_),
_ => Err(()),
}
}
}
pub fn add_time(&mut self, start: &str, stop: &str, repeat: &[&str]) -> Result<_, ()> {
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))
};
match result {
SDPResult::ok => Some(_),
_ => Err(()),
}
}
}
pub fn add_zone(&mut self, adj_time: &str, typed_time: &str) -> Result<_, ()> {
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))
};
match result {
SDPResult::ok => Some(_),
_ => Err(()),
}
}
}
pub fn as_text(&self) -> Option<String> {
unsafe {
from_glib_full(ffi::gst_sdp_message_as_text(self.to_glib_none().0))
}
}
pub fn attributes_len(&self) -> u32 {
unsafe {
ffi::gst_sdp_message_attributes_len(self.to_glib_none().0)
}
}
pub fn attributes_to_caps(&self, caps: &mut gst::CapsRef) -> Result<_, ()> {
let result = unsafe {
from_glib(ffi::gst_sdp_message_attributes_to_caps(self.to_glib_none().0, caps.to_glib_none_mut().0))
};
match result {
SDPResult::ok => Some(_),
_ => Err(()),
}
}
}
pub fn bandwidths_len(&self) -> u32 {
unsafe {
ffi::gst_sdp_message_bandwidths_len(self.to_glib_none().0)
}
}
pub fn dump(&self) -> Result<_, ()> {
let result = unsafe {
from_glib(ffi::gst_sdp_message_dump(self.to_glib_none().0))
};
match result {
SDPResult::ok => Some(_),
_ => Err(()),
}
}
}
pub fn emails_len(&self) -> u32 {
unsafe {
ffi::gst_sdp_message_emails_len(self.to_glib_none().0)
}
}
pub fn get_attribute(&self, idx: u32) -> Option<SDPAttribute> {
unsafe {
from_glib_none(ffi::gst_sdp_message_get_attribute(self.to_glib_none().0, idx))
}
}
pub fn get_attribute_val(&self, key: &str) -> Option<String> {
unsafe {
from_glib_none(ffi::gst_sdp_message_get_attribute_val(self.to_glib_none().0, key.to_glib_none().0))
}
}
pub fn get_attribute_val_n(&self, key: &str, nth: u32) -> Option<String> {
unsafe {
from_glib_none(ffi::gst_sdp_message_get_attribute_val_n(self.to_glib_none().0, key.to_glib_none().0, nth))
}
}
pub fn get_bandwidth(&self, idx: u32) -> Option<SDPBandwidth> {
unsafe {
from_glib_none(ffi::gst_sdp_message_get_bandwidth())
}
}
pub fn get_connection(&self) -> Option<SDPConnection> {
unsafe {
from_glib_none(ffi::gst_sdp_message_get_connection())
}
}
pub fn get_email(&self, idx: u32) -> Option<String> {
unsafe {
from_glib_none(ffi::gst_sdp_message_get_email(self.to_glib_none().0, idx))
}
}
pub fn get_information(&self) -> Option<String> {
unsafe {
from_glib_none(ffi::gst_sdp_message_get_information(self.to_glib_none().0))
}
}
pub fn get_key(&self) -> Option<SDPKey> {
unsafe {
from_glib_none(ffi::gst_sdp_message_get_key())
}
}
pub fn get_media(&self, idx: u32) -> Option<SDPMedia> {
unsafe {
from_glib_none(ffi::gst_sdp_message_get_media(self.to_glib_none().0, idx))
}
}
pub fn get_origin(&self) -> Option<SDPOrigin> {
unsafe {
from_glib_none(ffi::gst_sdp_message_get_origin())
}
}
pub fn get_phone(&self, idx: u32) -> Option<String> {
unsafe {
from_glib_none(ffi::gst_sdp_message_get_phone(self.to_glib_none().0, idx))
}
}
pub fn get_session_name(&self) -> Option<String> {
unsafe {
from_glib_none(ffi::gst_sdp_message_get_session_name(self.to_glib_none().0))
}
}
pub fn get_time(&self, idx: u32) -> Option<SDPTime> {
unsafe {
from_glib_none(ffi::gst_sdp_message_get_time())
}
}
pub fn get_uri(&self) -> Option<String> {
unsafe {
from_glib_none(ffi::gst_sdp_message_get_uri(self.to_glib_none().0))
}
}
pub fn get_version(&self) -> Option<String> {
unsafe {
from_glib_none(ffi::gst_sdp_message_get_version(self.to_glib_none().0))
}
}
pub fn get_zone(&self, idx: u32) -> Option<SDPZone> {
unsafe {
from_glib_none(ffi::gst_sdp_message_get_zone())
}
}
pub fn insert_attribute(&mut self, idx: i32, attr: SDPAttribute) -> Result<_, ()> {
let result = unsafe {
from_glib(ffi::gst_sdp_message_insert_attribute(self.to_glib_none_mut().0, idx, attr.to_glib_full()))
};
mem::forget(attr);
match result {
SDPResult::ok => Some(_),
_ => Err(()),
}
}
}
pub fn insert_bandwidth(&mut self, idx: i32, bw: SDPBandwidth) -> Result<_, ()> {
let result = unsafe {
from_glib(ffi::gst_sdp_message_insert_bandwidth(self.to_glib_none_mut().0, idx, bw.to_glib_full()))
};
mem::forget(bw);
match result {
SDPResult::ok => Some(_),
_ => Err(()),
}
}
}
pub fn insert_email(&mut self, idx: i32, email: &str) -> Result<_, ()> {
let result = unsafe {
from_glib(ffi::gst_sdp_message_insert_email(self.to_glib_none_mut().0, idx, email.to_glib_none().0))
};
match result {
SDPResult::ok => Some(_),
_ => Err(()),
}
}
}
pub fn insert_phone(&mut self, idx: i32, phone: &str) -> Result<_, ()> {
let result = unsafe {
from_glib(ffi::gst_sdp_message_insert_phone(self.to_glib_none_mut().0, idx, phone.to_glib_none().0))
};
match result {
SDPResult::ok => Some(_),
_ => Err(()),
}
}
}
pub fn insert_time(&mut self, idx: i32, time: SDPTime) -> Result<_, ()> {
let result = unsafe {
from_glib(ffi::gst_sdp_message_insert_time(self.to_glib_none_mut().0, idx, time.to_glib_full()))
};
mem::forget(time);
match result {
SDPResult::ok => Some(_),
_ => Err(()),
}
}
}
pub fn insert_zone(&mut self, idx: i32, zone: SDPZone) -> Result<_, ()> {
let result = unsafe {
from_glib(ffi::gst_sdp_message_insert_zone(self.to_glib_none_mut().0, idx, zone.to_glib_full()))
};
mem:forget(zone);
match result {
SDPResult::ok => Some(_),
_ => Err(()),
}
}
}
pub fn medias_len(&self) -> u32 {
unsafe {
ffi::gst_sdp_message_medias_len(self.to_glib_none().0)
}
}
#[cfg(any(feature = "v1_8_1", feature = "dox"))]
pub fn parse_keymgmt(&self, mikey: MIKEYMessage) -> Result<_, ()> {
let result = unsafe {
from_glib(ffi::gst_sdp_message_parse_keymgmt(self.to_glib_none().0, &mut mikey))
};
mem::forget(mikey);
match result {
SDPResult::ok => Some(_),
_ => Err(()),
}
}
}
pub fn phones_len(&self) -> u32 {
unsafe {
ffi::gst_sdp_message_phones_len(self.to_glib_none().0)
}
}
pub fn remove_attribute(&mut self, idx: u32) -> Result<_, ()> {
let result = unsafe {
from_glib(ffi::gst_sdp_message_remove_attribute(self.to_glib_none_mut().0, idx))
};
match result {
SDPResult::ok => Some(_),
_ => Err(()),
}
}
}
pub fn remove_bandwidth(&mut self, idx: u32) -> Result<_, ()> {
let result = unsafe {
from_glib(ffi::gst_sdp_message_remove_bandwidth(self.to_glib_none_mut().0, idx))
};
match result {
SDPResult::ok => Some(_),
_ => Err(()),
}
}
}
pub fn remove_email(&mut self, idx: u32) -> Result<_, ()> {
let result = unsafe {
from_glib(ffi::gst_sdp_message_remove_email(self.to_glib_none_mut().0, idx))
};
match result {
SDPResult::ok => Some(_),
_ => Err(()),
}
}
}
pub fn remove_phone(&mut self, idx: u32) -> Result<_, ()> {
let result = unsafe {
from_glib(ffi::gst_sdp_message_remove_phone(self.to_glib_none_mut().0, idx))
};
match result {
SDPResult::ok => Some(_),
_ => Err(()),
}
}
}
pub fn remove_time(&mut self, idx: u32) -> Result<_, ()> {
let result = unsafe {
from_glib(ffi::gst_sdp_message_remove_time(self.to_glib_none_mut().0, idx))
};
match result {
SDPResult::ok => Some(_),
_ => Err(()),
}
}
}
pub fn remove_zone(&mut self, idx: u32) -> Result<_, ()> {
let result = unsafe {
from_glib(ffi::gst_sdp_message_remove_zone(self.to_glib_none_mut().0, idx))
};
match result {
SDPResult::ok => Some(_),
_ => Err(()),
}
}
}
pub fn replace_attribute(&mut self, idx: u32, attr: SDPAttribute) -> Result<_, ()> {
let result = unsafe {
from_glib(ffi::gst_sdp_message_replace_attribute(self.to_glib_none_mut().0, idx, attr.to_glib_full()))
};
mem::forget(attr);
match result {
SDPResult::ok => Some(_),
_ => Err(()),
}
}
}
pub fn replace_bandwidth(&mut self, idx: u32, bw: SDPBandwidth) -> Result<_, ()> {
let result = unsafe {
from_glib(ffi::gst_sdp_message_replace_bandwidth(self.to_glib_none_mut().0, idx, bw.to_glib_full()))
};
mem::forget(bw);
match result {
SDPResult::ok => Some(_),
_ => Err(()),
}
}
}
pub fn replace_email(&mut self, idx: u32, email: &str) -> Result<_, ()> {
let result = unsafe {
from_glib(ffi::gst_sdp_message_replace_email(self.to_glib_none_mut().0, idx, email.to_glib_none().0))
};
match result {
SDPResult::ok => Some(_),
_ => Err(()),
}
}
}
pub fn replace_phone(&mut self, idx: u32, phone: &str) -> Result<_, ()> {
let result = unsafe {
from_glib(ffi::gst_sdp_message_replace_phone(self.to_glib_none_mut().0, idx, phone.to_glib_none().0))
};
match result {
SDPResult::ok => Some(_),
_ => Err(()),
}
}
}
pub fn replace_time(&mut self, idx: u32, time: SDPTime) -> Result<_, ()> {
let result = unsafe {
from_glib(ffi::gst_sdp_message_replace_time(self.to_glib_none_mut().0, idx, time.to_glib_full()))
};
mem::forget(time);
match result {
SDPResult::ok => Some(_),
_ => Err(()),
}
}
}
pub fn replace_zone(&mut self, idx: u32, zone: SDPZone) -> Result<_, ()> {
let result = unsafe {
from_glib(ffi::gst_sdp_message_replace_zone(self.to_glib_none_mut().0, idx, zone.to_glib_full()))
};
mem::forget(zone);
match result {
SDPResult::ok => Some(_),
_ => Err(()),
}
}
}
pub fn set_connection(&mut self, nettype: &str, addrtype: &str, address: &str, ttl: u32, addr_number: u32) -> Result<_, ()> {
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))
};
match result {
SDPResult::ok => Some(_),
_ => Err(()),
}
}
}
pub fn set_information(&mut self, information: &str) -> Result<_, ()> {
let result = unsafe {
from_glib(ffi::gst_sdp_message_set_information(self.to_glib_none_mut().0, information.to_glib_none().0))
};
match result {
SDPResult::ok => Some(_),
_ => Err(()),
}
}
}
pub fn set_key(&mut self, type_: &str, data: &str) -> Result<_, ()> {
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))
};
match result {
SDPResult::ok => Some(_),
_ => Err(()),
}
}
}
pub fn set_origin(&mut self, username: &str, sess_id: &str, sess_version: &str, nettype: &str, addrtype: &str, addr: &str) -> Result<_, ()> {
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))
};
match result {
SDPResult::ok => Some(_),
_ => Err(()),
}
}
}
pub fn set_session_name(&mut self, session_name: &str) -> Result<_, ()> {
let result = unsafe {
from_glib(ffi::gst_sdp_message_set_session_name(self.to_glib_none_mut().0, session_name.to_glib_none().0))
};
match result {
SDPResult::ok => Some(_),
_ => Err(()),
}
}
}
pub fn set_uri(&mut self, uri: &str) -> Result<_, ()> {
let result = unsafe {
from_glib(ffi::gst_sdp_message_set_uri(self.to_glib_none_mut().0, uri.to_glib_none().0))
};
match result {
SDPResult::ok => Some(_),
_ => Err(()),
}
}
}
pub fn set_version(&mut self, version: &str) -> Result<_, ()> {
let result = unsafe {
from_glib(ffi::gst_sdp_message_set_version(self.to_glib_none_mut().0, version.to_glib_none().0))
};
match result {
SDPResult::ok => Some(_),
_ => Err(()),
}
}
}
pub fn times_len(&self) -> u32 {
unsafe {
ffi::gst_sdp_message_times_len(self.to_glib_none().0)
}
}
pub fn zones_len(&self) -> u32 {
unsafe {
ffi::gst_sdp_message_zones_len(self.to_glib_none().0)
}
}
pub fn as_uri(scheme: &str, msg: &SDPMessage) -> Option<String> {
assert_initialized_main_thread!();
unsafe {
from_glib_full(ffi::gst_sdp_message_as_uri(scheme.to_glib_none().0, msg.to_glib_none().0))
}
}
pub fn parse_buffer(data: &[u8]) -> Result<Self, SDPResult> {
assert_initialized_main_thread!();
unsafe {
let size = data.len() as u32;
let mut msg = glib_ffi::g_malloc(mem::size_of::<ffi::GstSDPMessage>());
let result = from_glib(ffi::gst_sdp_message_parse_buffer(data.to_glib_none().0, size, &mut msg));
match result {
SDPResult::ok => Some(from_glib_full(msg)),
_ => Err(result),
}
}
}
pub fn parse_uri(uri: &str, msg: &mut SDPMessage) -> Result<Self, SDPResult> {
assert_initialized_main_thread!();
unsafe {
let mut msg = glib_ffi::g_malloc(mem::size_of::<ffi::GstSDPMessage>());
let result = from_glib(ffi::gst_sdp_message_parse_uri(uri.to_glib_none().0, &mut msg));
match result {
SDPResult::ok => Some(from_glib_full(msg)),
_ => Err(result),
}
}
}
}
unsafe impl Send for SDPMessage {}

View file

@ -0,0 +1,39 @@
// 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::ffi::CStr;
use ffi;
pub struct SDPOrigin(ffi::GstSDPOrigin);
impl SDPOrigin {
pub fn username(&self) -> &str {
CStr::from_ptr(self.0.username).to_str().unwrap()
}
pub fn sess_id(&self) -> &str {
CStr::from_ptr(self.0.sess_id).to_str().unwrap()
}
pub fn sess_version(&self) -> &str {
CStr::from_ptr(self.0.sess_version).to_str().unwrap()
}
pub fn nettype(&self) -> &str {
CStr::from_ptr(self.0.nettype).to_str().unwrap()
}
pub fn addrtype(&self) -> &str {
CStr::from_ptr(self.0.addrtype).to_str().unwrap()
}
pub fn addr(&self) -> &str {
CStr::from_ptr(self.0.addr).to_str().unwrap()
}
}

View file

@ -0,0 +1,59 @@
// 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::mem;
use std::ffi:CStr;
use ffi;
use auto::SDPResult;
pub struct SDPTime(ffi::GstSDPTime);
impl SDPTime {
pub fn new(start: &str, stop: &str, repeat: &[&str]) -> Result<Self, SDPResult> {
assert_initialized_main_thread!();
unsafe {
let mut time = mem::uninitialized();
let result =from_glib(ffi::gst_sdp_time_set(
&mut time,
start.to_glib_none().0,
stop.to_glib_none().0,
repeat.to_glib_none().0,
));
match result {
SDPResult::Ok => Ok(SDPTime(time)),
_ => Err(result),
}
}
}
pub fn start(&self) -> &str {
CStr::from_ptr(self.0.start).to_str().unwrap()
}
pub fn stop(&self) -> &str {
CStr::from_ptr(self.0.stop).to_str().unwrap()
}
pub fn repeat(&self) -> Vec<&str> {
let arr = (*self.0.repeat).data as *const *const c_char;
let len = (*self.0.repeat).len as usize;
let vec = Vec::with_capacity(len);
for i in 0..len {
vec.push(CStr::from_ptr(arr.offset(i)).to_str().unwrap());
}
vec
}
}
impl Drop for SDPTime {
fn drop(&mut self) {
ffi::gst_sdp_time_clear(self.to_glib_none_mut().0);
}
}

View file

@ -0,0 +1,44 @@
// 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::mem;
use std::ffi:CStr;
use auto::SDPResult;
use ffi;
pub struct SDPZone(ffi::GstSDPZone);
impl SDPZone {
pub fn new(time: &str, typed_time: &str) -> Result<Self, SDPResult> {
assert_initialized_main_thread!();
unsafe {
let mut zone = mem::uninitialized();
let result = from_glib(ffi::gst_sdp_zone_set(&mut zone, time.to_glib_none().0, typed_time.to_glib_none().0));
match result {
SDPResult::Ok => Ok(SDPZone(zone)),
_ => Err(result),
}
}
}
pub fn time(&self) -> &str {
CStr::from_ptr(self.0.time).to_str().unwrap()
}
pub fn typed_time(&self) -> &str {
CStr::from_ptr(self.0.typed_time).to_str().unwrap()
}
}
impl Drop for SDPZone {
fn drop(&mut self) {
ffi::gst_sdp_zone_clear(self.to_glib_none_mut().0);
}
}