forked from mirrors/gstreamer-rs
sdp: Add proper Debug/Clone impls for various SDP types
And fix nullability of others.
This commit is contained in:
parent
7673be5baa
commit
74bbff55ad
7 changed files with 139 additions and 46 deletions
|
@ -7,26 +7,22 @@
|
|||
// except according to those terms.
|
||||
|
||||
use std::ffi::CStr;
|
||||
use std::fmt;
|
||||
use std::mem;
|
||||
|
||||
use ffi;
|
||||
use glib::translate::*;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug)]
|
||||
pub struct SDPAttribute(pub(crate) ffi::GstSDPAttribute);
|
||||
|
||||
impl SDPAttribute {
|
||||
pub fn new(key: &str, value: &str) -> Result<Self, ()> {
|
||||
pub fn new(key: &str, value: Option<&str>) -> Self {
|
||||
assert_initialized_main_thread!();
|
||||
unsafe {
|
||||
let mut attr = mem::zeroed();
|
||||
let result =
|
||||
ffi::gst_sdp_attribute_set(&mut attr, key.to_glib_none().0, value.to_glib_none().0);
|
||||
match result {
|
||||
ffi::GST_SDP_OK => Ok(SDPAttribute(attr)),
|
||||
_ => Err(()),
|
||||
}
|
||||
ffi::gst_sdp_attribute_set(&mut attr, key.to_glib_none().0, value.to_glib_none().0);
|
||||
SDPAttribute(attr)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -34,8 +30,22 @@ impl SDPAttribute {
|
|||
unsafe { CStr::from_ptr(self.0.key).to_str().unwrap() }
|
||||
}
|
||||
|
||||
pub fn value(&self) -> &str {
|
||||
unsafe { CStr::from_ptr(self.0.value).to_str().unwrap() }
|
||||
pub fn value(&self) -> Option<&str> {
|
||||
unsafe {
|
||||
let ptr = self.0.value;
|
||||
|
||||
if ptr.is_null() {
|
||||
None
|
||||
} else {
|
||||
Some(CStr::from_ptr(ptr).to_str().unwrap())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Clone for SDPAttribute {
|
||||
fn clone(&self) -> Self {
|
||||
SDPAttribute::new(self.key(), self.value())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -46,3 +56,12 @@ impl Drop for SDPAttribute {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for SDPAttribute {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
f.debug_struct("SDPAttribute")
|
||||
.field("key", &self.key())
|
||||
.field("value", &self.value())
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,25 +7,22 @@
|
|||
// except according to those terms.
|
||||
|
||||
use std::ffi::CStr;
|
||||
use std::fmt;
|
||||
use std::mem;
|
||||
|
||||
use ffi;
|
||||
use glib::translate::*;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug)]
|
||||
pub struct SDPBandwidth(pub(crate) ffi::GstSDPBandwidth);
|
||||
|
||||
impl SDPBandwidth {
|
||||
pub fn new(bwtype: &str, bandwidth: u32) -> Result<Self, ()> {
|
||||
pub fn new(bwtype: &str, bandwidth: u32) -> Self {
|
||||
assert_initialized_main_thread!();
|
||||
unsafe {
|
||||
let mut bw = mem::zeroed();
|
||||
let result = ffi::gst_sdp_bandwidth_set(&mut bw, bwtype.to_glib_none().0, bandwidth);
|
||||
match result {
|
||||
ffi::GST_SDP_OK => Ok(SDPBandwidth(bw)),
|
||||
_ => Err(()),
|
||||
}
|
||||
ffi::gst_sdp_bandwidth_set(&mut bw, bwtype.to_glib_none().0, bandwidth);
|
||||
SDPBandwidth(bw)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -38,6 +35,12 @@ impl SDPBandwidth {
|
|||
}
|
||||
}
|
||||
|
||||
impl Clone for SDPBandwidth {
|
||||
fn clone(&self) -> Self {
|
||||
SDPBandwidth::new(self.bwtype(), self.value())
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for SDPBandwidth {
|
||||
fn drop(&mut self) {
|
||||
unsafe {
|
||||
|
@ -45,3 +48,12 @@ impl Drop for SDPBandwidth {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for SDPBandwidth {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
f.debug_struct("SDPBandwidth")
|
||||
.field("bwtype", &self.bwtype())
|
||||
.field("value", &self.value())
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,27 +7,21 @@
|
|||
// except according to those terms.
|
||||
|
||||
use std::ffi::CStr;
|
||||
use std::fmt;
|
||||
use std::mem;
|
||||
|
||||
use ffi;
|
||||
use glib::translate::*;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug)]
|
||||
pub struct SDPConnection(pub(crate) ffi::GstSDPConnection);
|
||||
|
||||
impl SDPConnection {
|
||||
pub fn new(
|
||||
nettype: &str,
|
||||
addrtype: &str,
|
||||
address: &str,
|
||||
ttl: u32,
|
||||
addr_number: u32,
|
||||
) -> Result<Self, ()> {
|
||||
pub fn new(nettype: &str, addrtype: &str, address: &str, ttl: u32, addr_number: u32) -> Self {
|
||||
assert_initialized_main_thread!();
|
||||
unsafe {
|
||||
let mut conn = mem::zeroed();
|
||||
let result = ffi::gst_sdp_connection_set(
|
||||
ffi::gst_sdp_connection_set(
|
||||
&mut conn,
|
||||
nettype.to_glib_none().0,
|
||||
addrtype.to_glib_none().0,
|
||||
|
@ -35,10 +29,7 @@ impl SDPConnection {
|
|||
ttl,
|
||||
addr_number,
|
||||
);
|
||||
match result {
|
||||
ffi::GST_SDP_OK => Ok(SDPConnection(conn)),
|
||||
_ => Err(()),
|
||||
}
|
||||
SDPConnection(conn)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -63,6 +54,18 @@ impl SDPConnection {
|
|||
}
|
||||
}
|
||||
|
||||
impl Clone for SDPConnection {
|
||||
fn clone(&self) -> Self {
|
||||
SDPConnection::new(
|
||||
self.nettype(),
|
||||
self.addrtype(),
|
||||
self.address(),
|
||||
self.ttl(),
|
||||
self.addr_number(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for SDPConnection {
|
||||
fn drop(&mut self) {
|
||||
unsafe {
|
||||
|
@ -70,3 +73,15 @@ impl Drop for SDPConnection {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for SDPConnection {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
f.debug_struct("SDPConnection")
|
||||
.field("nettype", &self.nettype())
|
||||
.field("addrtype", &self.addrtype())
|
||||
.field("address", &self.address())
|
||||
.field("ttl", &self.ttl())
|
||||
.field("addr_number", &self.addr_number())
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,11 +7,11 @@
|
|||
// except according to those terms.
|
||||
|
||||
use std::ffi::CStr;
|
||||
use std::fmt;
|
||||
|
||||
use ffi;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug)]
|
||||
pub struct SDPKey(ffi::GstSDPKey);
|
||||
|
||||
impl SDPKey {
|
||||
|
@ -23,3 +23,12 @@ impl SDPKey {
|
|||
unsafe { CStr::from_ptr(self.0.data).to_str().unwrap() }
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for SDPKey {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
f.debug_struct("SDPKey")
|
||||
.field("type", &self.type_())
|
||||
.field("data", &self.data())
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,11 +7,11 @@
|
|||
// except according to those terms.
|
||||
|
||||
use std::ffi::CStr;
|
||||
use std::fmt;
|
||||
|
||||
use ffi;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug)]
|
||||
pub struct SDPOrigin(pub(crate) ffi::GstSDPOrigin);
|
||||
|
||||
impl SDPOrigin {
|
||||
|
@ -39,3 +39,16 @@ impl SDPOrigin {
|
|||
unsafe { CStr::from_ptr(self.0.addr).to_str().unwrap() }
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for SDPOrigin {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
f.debug_struct("SDPOrigin")
|
||||
.field("username", &self.username())
|
||||
.field("sess_id", &self.sess_id())
|
||||
.field("sess_version", &self.sess_version())
|
||||
.field("nettype", &self.nettype())
|
||||
.field("addrtype", &self.addrtype())
|
||||
.field("addr", &self.addr())
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
// except according to those terms.
|
||||
|
||||
use std::ffi::CStr;
|
||||
use std::fmt;
|
||||
use std::mem;
|
||||
use std::os::raw::c_char;
|
||||
|
||||
|
@ -14,24 +15,20 @@ use ffi;
|
|||
use glib::translate::*;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug)]
|
||||
pub struct SDPTime(pub(crate) ffi::GstSDPTime);
|
||||
|
||||
impl SDPTime {
|
||||
pub fn new(start: &str, stop: &str, repeat: &[&str]) -> Result<Self, ()> {
|
||||
pub fn new(start: &str, stop: &str, repeat: &[&str]) -> Self {
|
||||
assert_initialized_main_thread!();
|
||||
unsafe {
|
||||
let mut time = mem::zeroed();
|
||||
let result = ffi::gst_sdp_time_set(
|
||||
ffi::gst_sdp_time_set(
|
||||
&mut time,
|
||||
start.to_glib_none().0,
|
||||
stop.to_glib_none().0,
|
||||
repeat.to_glib_none().0,
|
||||
);
|
||||
match result {
|
||||
ffi::GST_SDP_OK => Ok(SDPTime(time)),
|
||||
_ => Err(()),
|
||||
}
|
||||
SDPTime(time)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -57,6 +54,12 @@ impl SDPTime {
|
|||
}
|
||||
}
|
||||
|
||||
impl Clone for SDPTime {
|
||||
fn clone(&self) -> Self {
|
||||
SDPTime::new(self.start(), self.stop(), self.repeat().as_slice())
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for SDPTime {
|
||||
fn drop(&mut self) {
|
||||
unsafe {
|
||||
|
@ -64,3 +67,13 @@ impl Drop for SDPTime {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for SDPTime {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
f.debug_struct("SDPTime")
|
||||
.field("start", &self.start())
|
||||
.field("stop", &self.stop())
|
||||
.field("repeat", &self.repeat())
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,29 +7,26 @@
|
|||
// except according to those terms.
|
||||
|
||||
use std::ffi::CStr;
|
||||
use std::fmt;
|
||||
use std::mem;
|
||||
|
||||
use ffi;
|
||||
use glib::translate::*;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug)]
|
||||
pub struct SDPZone(pub(crate) ffi::GstSDPZone);
|
||||
|
||||
impl SDPZone {
|
||||
pub fn new(time: &str, typed_time: &str) -> Result<Self, ()> {
|
||||
pub fn new(time: &str, typed_time: &str) -> Self {
|
||||
assert_initialized_main_thread!();
|
||||
unsafe {
|
||||
let mut zone = mem::zeroed();
|
||||
let result = ffi::gst_sdp_zone_set(
|
||||
ffi::gst_sdp_zone_set(
|
||||
&mut zone,
|
||||
time.to_glib_none().0,
|
||||
typed_time.to_glib_none().0,
|
||||
);
|
||||
match result {
|
||||
ffi::GST_SDP_OK => Ok(SDPZone(zone)),
|
||||
_ => Err(()),
|
||||
}
|
||||
SDPZone(zone)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -42,6 +39,12 @@ impl SDPZone {
|
|||
}
|
||||
}
|
||||
|
||||
impl Clone for SDPZone {
|
||||
fn clone(&self) -> Self {
|
||||
SDPZone::new(self.time(), self.typed_time())
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for SDPZone {
|
||||
fn drop(&mut self) {
|
||||
unsafe {
|
||||
|
@ -49,3 +52,12 @@ impl Drop for SDPZone {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for SDPZone {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
f.debug_struct("SDPZone")
|
||||
.field("time", &self.time())
|
||||
.field("typed_time", &self.typed_time())
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue