Commit 36d538c0 authored by Bo Du's avatar Bo Du Committed by Sebastian Dröge

Add SDPMessage definition and other manual SDP definitions.

parent 92016945
// 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;
}
// 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))
}
}
// 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))
}
}
// 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
}
}
// 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
}
}
}
// 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() }
//}
}
// 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);
}
}
// 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);
}
}
// 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);
}
}
// 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()
}
}
This diff is collapsed.
This diff is collapsed.
// 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()
}
}
// 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);
}
}
// 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);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment