Commit 3ecd67ee authored by Bo Du's avatar Bo Du Committed by Sebastian Dröge

Address PR comments and fix compilation errors

parent 36d538c0
......@@ -55,9 +55,25 @@ status = "generate"
name = "add_payload"
ignore = true
[[object.function]]
name = "get_payload"
ignore = true
[[object.function]]
name = "base64_encode"
ignore = true
[[object]]
name = "GstSdp.MIKEYPayload"
status = "generate"
[[object.function]]
name = "kemac_add_sub"
ignore = true
[[object.function]]
name = "kemac_get_sub"
ignore = true
[[object.function]]
name = "key_data_set_interval"
ignore = true
......@@ -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> {
unsafe {
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 {
// unsafe { TODO: call ffi::gst_mikey_message_insert_cs_srtp() }
//}
......
......@@ -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 {
unsafe {
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 {
let key_len = key_data.len() as u16;
unsafe {
......
......@@ -9,6 +9,7 @@
extern crate bitflags;
extern crate libc;
#[macro_use]
extern crate glib;
extern crate glib_sys as glib_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_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_payload_s_p_param;
mod m_i_k_e_y_encrypt_info;
mod m_i_k_e_y_decrypt_info;
mod m_i_k_e_y_map_s_r_t_p;
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 {
......
......@@ -6,18 +6,6 @@
// 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))
}
}
......@@ -6,18 +6,6 @@
// 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))
}
}
......@@ -6,13 +6,9 @@
// 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;
#[repr(C)]
pub struct MIKEYMapSRTP(ffi::GstMIKEYMapSRTP);
impl MIKEYMapSRTP {
......
......@@ -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;
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 {
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(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 {
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) }
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 {
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 {
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);
ret
}
......@@ -95,4 +101,10 @@ impl MIKEYMessage {
ret
}
}
pub fn base64_encode(&self) -> Option<String> {
unsafe {
from_glib_full(ffi::gst_mikey_message_base64_encode(self.to_glib_none_mut().0))
}
}
}
......@@ -15,6 +15,7 @@ use glib_ffi;
use gobject_ffi;
use auto::MIKEYPayload;
use m_i_k_e_y_map_s_r_t_p::MIKEYPayloadSPParam;
impl MIKEYPayload {
......@@ -25,11 +26,30 @@ impl MIKEYPayload {
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 kemac_get_sub(&self, idx: u32) -> Option<MIKEYPayload> {
unsafe {
&*(from_glib_none(ffi::gst_mikey_payload_kemac_get_sub(self.to_glib_none().0, idx)) as *mut MIKEYPayload)
}
}
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() }
//}
}
// 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)
}
}
}
......@@ -10,35 +10,43 @@ use std::mem;
use std::ffi::CStr;
use ffi;
use glib::translate::*;
use auto::SDPResult;
pub struct SDPAttribute(ffi::GstSDPAttribute);
#[repr(C)]
pub struct SDPAttribute(pub ffi::GstSDPAttribute);
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!();
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));
match result {
SDPResult::Ok => Ok(SDPAttribute(attr)),
_ => Err(result),
_ => Err(()),
}
}
}
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 {
CStr::from_ptr(self.0.value).to_str().unwrap()
unsafe {
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);
unsafe {
ffi::gst_sdp_attribute_clear(&mut self.0);
}
}
}
......@@ -10,26 +10,30 @@ use std::mem;
use std::ffi::CStr;
use ffi;
use glib::translate::*;
use auto::SDPResult;
pub struct SDPBandwidth(ffi::GstSDPBandwidth);
#[repr(C)]
pub struct SDPBandwidth(pub ffi::GstSDPBandwidth);
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!();
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));
match result {
SDPResult::Ok => Ok(SDPBandwidth(bw)),
_ => Err(result),
_ => Err(()),
}
}
}
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 {
......@@ -39,6 +43,8 @@ impl SDPBandwidth {
impl Drop for SDPBandwidth {
fn drop(&mut self) {
ffi::gst_sdp_bandwidth_clear(self.to_glib_none_mut().0);
unsafe {
ffi::gst_sdp_bandwidth_clear(&mut self.0);
}
}
}
......@@ -10,17 +10,18 @@ use std::mem;
use std::ffi::CStr;
use ffi;
use glib::translate::*;
use auto::SDPResult;
pub struct SDPConnection(ffi::GstSDPConnection);
#[repr(C)]
pub struct SDPConnection(pub ffi::GstSDPConnection);
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!();
unsafe {
let mut conn = mem::uninitialized();
let mut conn = mem::zeroed();
let result = from_glib(ffi::gst_sdp_connection_set(
&mut conn,
nettype.to_glib_none().0,
......@@ -31,21 +32,27 @@ impl SDPConnection {
));
match result {
SDPResult::Ok => Ok(SDPConnection(conn)),
_ => Err(result),
_ => Err(()),
}
}
}
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 {
CStr::from_ptr(self.0.addrtype).to_str().unwrap()
unsafe {
CStr::from_ptr(self.0.addrtype).to_str().unwrap()
}
}
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 {
......@@ -59,6 +66,8 @@ impl SDPConnection {
impl Drop for SDPConnection {
fn drop(&mut self) {
ffi::gst_sdp_connection_clear(self.to_glib_none_mut().0);
unsafe {
ffi::gst_sdp_connection_clear(&mut self.0);
}
}
}
......@@ -13,11 +13,15 @@ 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 type_(&self) -> &str {
unsafe {
CStr::from_ptr(self.0.type_).to_str().unwrap()
}
}
pub fn data(&self) -> &str {
CStr::from_ptr(self.0.data).to_str().unwrap()
unsafe {
CStr::from_ptr(self.0.data).to_str().unwrap()
}
}
}
This diff is collapsed.
This diff is collapsed.
......@@ -10,30 +10,43 @@ use std::ffi::CStr;
use ffi;
pub struct SDPOrigin(ffi::GstSDPOrigin);
#[repr(C)]
pub struct SDPOrigin(pub ffi::GstSDPOrigin);
impl SDPOrigin {
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 {
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 {
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 {
CStr::from_ptr(self.0.nettype).to_str().unwrap()
unsafe {
CStr::from_ptr(self.0.nettype).to_str().unwrap()
}
}
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 {
CStr::from_ptr(self.0.addr).to_str().unwrap()
unsafe {
CStr::from_ptr(self.0.addr).to_str().unwrap()
}
}
}
......@@ -7,20 +7,23 @@
// except according to those terms.
use std::mem;
use std::ffi:CStr;
use std::os::raw::c_char;
use std::ffi::CStr;
use ffi;
use glib::translate::*;
use auto::SDPResult;
pub struct SDPTime(ffi::GstSDPTime);
#[repr(C)]
pub struct SDPTime(pub ffi::GstSDPTime);
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!();
unsafe {
let mut time = mem::uninitialized();
let result =from_glib(ffi::gst_sdp_time_set(
let mut time = mem::zeroed();
let result = from_glib(ffi::gst_sdp_time_set(
&mut time,
start.to_glib_none().0,
stop.to_glib_none().0,
......@@ -28,32 +31,40 @@ impl SDPTime {
));
match result {
SDPResult::Ok => Ok(SDPTime(time)),
_ => Err(result),
_ => Err(()),
}
}
}
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 {
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> {
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());
unsafe {
let arr = (*self.0.repeat).data as *const *const c_char;
let len = (*self.0.repeat).len as usize;
let mut vec = Vec::with_capacity(len);
for i in 0..len {
vec.push(CStr::from_ptr(*arr.offset(i as isize)).to_str().unwrap());
}
vec
}
vec
}
}
impl Drop for SDPTime {
fn drop(&mut self) {
ffi::gst_sdp_time_clear(self.to_glib_none_mut().0);
unsafe {
ffi::gst_sdp_time_clear(&mut self.0);
}
}
}
......@@ -7,38 +7,46 @@
// except according to those terms.
use std::mem;
use std::ffi:CStr;
use auto::SDPResult;
use std::ffi::CStr;
use ffi;
use glib::translate::*;
pub struct SDPZone(ffi::GstSDPZone);
use auto::SDPResult;
#[repr(C)]
pub struct SDPZone(pub ffi::GstSDPZone);
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!();
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));
match result {
SDPResult::Ok => Ok(SDPZone(zone)),
_ => Err(result),
_ => Err(()),
}
}
}
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 {
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 {
fn drop(&mut self) {
ffi::gst_sdp_zone_clear(self.to_glib_none_mut().0);
unsafe {
ffi::gst_sdp_zone_clear(&mut self.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