2020-12-15 10:53:31 +00:00
|
|
|
// Take a look at the license at the top of the repository in the LICENSE file.
|
2018-03-29 18:43:25 +00:00
|
|
|
|
2023-01-03 18:58:25 +00:00
|
|
|
use std::{
|
|
|
|
borrow::{Borrow, BorrowMut, ToOwned},
|
|
|
|
ffi::CStr,
|
|
|
|
fmt, mem, ops, ptr,
|
|
|
|
};
|
2018-03-29 18:43:25 +00:00
|
|
|
|
|
|
|
use glib::translate::*;
|
2020-06-29 21:12:46 +00:00
|
|
|
|
2023-01-03 18:58:25 +00:00
|
|
|
use crate::{
|
2024-06-02 08:48:53 +00:00
|
|
|
ffi, sdp_attribute::SDPAttribute, sdp_bandwidth::SDPBandwidth, sdp_connection::SDPConnection,
|
2023-01-03 18:58:25 +00:00
|
|
|
sdp_key::SDPKey,
|
|
|
|
};
|
2018-03-29 18:43:25 +00:00
|
|
|
|
2020-12-17 22:38:06 +00:00
|
|
|
glib::wrapper! {
|
2019-02-27 16:04:12 +00:00
|
|
|
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash)]
|
2021-06-01 13:15:59 +00:00
|
|
|
#[doc(alias = "GstSDPMedia")]
|
2020-11-22 10:38:16 +00:00
|
|
|
pub struct SDPMedia(Boxed<ffi::GstSDPMedia>);
|
2018-03-29 18:43:25 +00:00
|
|
|
|
|
|
|
match fn {
|
2018-04-04 18:40:45 +00:00
|
|
|
copy => |ptr| {
|
|
|
|
let mut copy = ptr::null_mut();
|
2022-12-25 10:47:02 +00:00
|
|
|
let res = ffi::gst_sdp_media_copy(ptr, &mut copy);
|
|
|
|
debug_assert_eq!(res, ffi::GST_SDP_OK);
|
2018-04-04 18:40:45 +00:00
|
|
|
copy
|
|
|
|
},
|
|
|
|
free => |ptr| {
|
2022-12-25 10:47:02 +00:00
|
|
|
let res = ffi::gst_sdp_media_free(ptr);
|
|
|
|
debug_assert_eq!(res, ffi::GST_SDP_OK);
|
2018-04-04 18:40:45 +00:00
|
|
|
},
|
2018-03-29 18:43:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl SDPMedia {
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_sdp_media_new")]
|
2019-02-28 18:30:09 +00:00
|
|
|
pub fn new() -> Self {
|
2018-04-04 18:40:45 +00:00
|
|
|
assert_initialized_main_thread!();
|
|
|
|
unsafe {
|
|
|
|
let mut media = ptr::null_mut();
|
2020-11-22 10:38:16 +00:00
|
|
|
ffi::gst_sdp_media_new(&mut media);
|
2019-02-28 18:30:09 +00:00
|
|
|
from_glib_full(media)
|
2018-04-04 18:40:45 +00:00
|
|
|
}
|
|
|
|
}
|
2019-02-27 16:04:12 +00:00
|
|
|
}
|
|
|
|
|
2019-03-19 07:59:34 +00:00
|
|
|
impl Default for SDPMedia {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self::new()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-27 16:04:12 +00:00
|
|
|
unsafe impl Send for SDPMedia {}
|
|
|
|
unsafe impl Sync for SDPMedia {}
|
|
|
|
|
|
|
|
impl ops::Deref for SDPMedia {
|
|
|
|
type Target = SDPMediaRef;
|
|
|
|
|
|
|
|
fn deref(&self) -> &SDPMediaRef {
|
2023-01-17 07:59:02 +00:00
|
|
|
unsafe { &*(self.as_ptr() as *const SDPMediaRef) }
|
2019-02-27 16:04:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ops::DerefMut for SDPMedia {
|
|
|
|
fn deref_mut(&mut self) -> &mut SDPMediaRef {
|
|
|
|
unsafe { &mut *(self.to_glib_none_mut().0 as *mut SDPMediaRef) }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl fmt::Debug for SDPMedia {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
2022-06-30 12:22:30 +00:00
|
|
|
<SDPMediaRef as fmt::Debug>::fmt(self, f)
|
2019-02-27 16:04:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl fmt::Display for SDPMedia {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
2022-06-30 12:22:30 +00:00
|
|
|
<SDPMediaRef as fmt::Display>::fmt(self, f)
|
2019-02-27 16:04:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-24 17:06:59 +00:00
|
|
|
#[repr(transparent)]
|
2021-06-01 13:15:59 +00:00
|
|
|
#[doc(alias = "GstSDPMedia")]
|
2020-11-22 10:38:16 +00:00
|
|
|
pub struct SDPMediaRef(ffi::GstSDPMedia);
|
2018-04-04 18:40:45 +00:00
|
|
|
|
2019-02-27 16:04:12 +00:00
|
|
|
impl fmt::Debug for SDPMediaRef {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
2019-02-27 16:29:32 +00:00
|
|
|
use std::cell::RefCell;
|
|
|
|
|
|
|
|
struct DebugIter<I>(RefCell<I>);
|
|
|
|
impl<I: Iterator> fmt::Debug for DebugIter<I>
|
|
|
|
where
|
|
|
|
I::Item: fmt::Debug,
|
|
|
|
{
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
f.debug_list().entries(&mut *self.0.borrow_mut()).finish()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
f.debug_struct("SDPMedia")
|
|
|
|
.field("formats", &DebugIter(RefCell::new(self.formats())))
|
|
|
|
.field("connections", &DebugIter(RefCell::new(self.connections())))
|
|
|
|
.field("bandwidths", &DebugIter(RefCell::new(self.bandwidths())))
|
|
|
|
.field("attributes", &DebugIter(RefCell::new(self.attributes())))
|
2021-04-11 19:39:50 +00:00
|
|
|
.field("information", &self.information())
|
|
|
|
.field("key", &self.key())
|
|
|
|
.field("media", &self.media())
|
|
|
|
.field("port", &self.port())
|
|
|
|
.field("num-ports", &self.num_ports())
|
|
|
|
.field("proto", &self.proto())
|
2019-02-27 16:04:12 +00:00
|
|
|
.finish()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl fmt::Display for SDPMediaRef {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
match self.as_text() {
|
2019-12-17 08:20:47 +00:00
|
|
|
Ok(text) => f.write_str(text.as_str()),
|
|
|
|
Err(_) => Err(fmt::Error),
|
2019-02-27 16:04:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe impl Send for SDPMediaRef {}
|
|
|
|
unsafe impl Sync for SDPMediaRef {}
|
|
|
|
|
|
|
|
impl SDPMediaRef {
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_sdp_media_add_attribute")]
|
2019-05-23 18:19:24 +00:00
|
|
|
pub fn add_attribute(&mut self, key: &str, value: Option<&str>) {
|
2018-03-29 18:43:25 +00:00
|
|
|
let value = value.to_glib_none();
|
2020-11-22 10:38:16 +00:00
|
|
|
unsafe { ffi::gst_sdp_media_add_attribute(&mut self.0, key.to_glib_none().0, value.0) };
|
2018-03-29 18:43:25 +00:00
|
|
|
}
|
|
|
|
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_sdp_media_add_bandwidth")]
|
2019-02-28 18:34:31 +00:00
|
|
|
pub fn add_bandwidth(&mut self, bwtype: &str, bandwidth: u32) {
|
|
|
|
unsafe {
|
2020-11-22 10:38:16 +00:00
|
|
|
ffi::gst_sdp_media_add_bandwidth(&mut self.0, bwtype.to_glib_none().0, bandwidth)
|
2018-03-29 18:43:25 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_sdp_media_add_connection")]
|
2018-04-05 17:41:31 +00:00
|
|
|
pub fn add_connection(
|
|
|
|
&mut self,
|
|
|
|
nettype: &str,
|
|
|
|
addrtype: &str,
|
|
|
|
address: &str,
|
|
|
|
ttl: u32,
|
|
|
|
addr_number: u32,
|
2019-02-28 18:34:31 +00:00
|
|
|
) {
|
|
|
|
unsafe {
|
2020-11-22 10:38:16 +00:00
|
|
|
ffi::gst_sdp_media_add_connection(
|
2019-02-27 16:04:12 +00:00
|
|
|
&mut self.0,
|
2018-04-05 17:41:31 +00:00
|
|
|
nettype.to_glib_none().0,
|
|
|
|
addrtype.to_glib_none().0,
|
|
|
|
address.to_glib_none().0,
|
|
|
|
ttl,
|
|
|
|
addr_number,
|
2018-04-05 18:05:49 +00:00
|
|
|
)
|
2018-03-29 18:43:25 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_sdp_media_add_format")]
|
2019-02-28 18:34:31 +00:00
|
|
|
pub fn add_format(&mut self, format: &str) {
|
2020-11-22 10:38:16 +00:00
|
|
|
unsafe { ffi::gst_sdp_media_add_format(&mut self.0, format.to_glib_none().0) };
|
2018-03-29 18:43:25 +00:00
|
|
|
}
|
|
|
|
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_sdp_media_as_text")]
|
2019-12-17 08:20:47 +00:00
|
|
|
pub fn as_text(&self) -> Result<String, glib::error::BoolError> {
|
|
|
|
unsafe {
|
2020-11-22 10:38:16 +00:00
|
|
|
match from_glib_full(ffi::gst_sdp_media_as_text(&self.0)) {
|
2019-12-17 08:20:47 +00:00
|
|
|
Some(s) => Ok(s),
|
2020-12-17 22:38:06 +00:00
|
|
|
None => Err(glib::bool_error!(
|
2019-12-17 08:20:47 +00:00
|
|
|
"Failed to convert the contents of media to a text string"
|
|
|
|
)),
|
|
|
|
}
|
|
|
|
}
|
2018-03-29 18:43:25 +00:00
|
|
|
}
|
|
|
|
|
2019-02-27 16:10:31 +00:00
|
|
|
pub fn attributes(&self) -> AttributesIter {
|
|
|
|
AttributesIter::new(self)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn formats(&self) -> FormatsIter {
|
|
|
|
FormatsIter::new(self)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn bandwidths(&self) -> BandwidthsIter {
|
|
|
|
BandwidthsIter::new(self)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn connections(&self) -> ConnectionsIter {
|
|
|
|
ConnectionsIter::new(self)
|
|
|
|
}
|
|
|
|
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_sdp_media_attributes_len")]
|
2018-03-29 18:43:25 +00:00
|
|
|
pub fn attributes_len(&self) -> u32 {
|
2020-11-22 10:38:16 +00:00
|
|
|
unsafe { ffi::gst_sdp_media_attributes_len(&self.0) }
|
2018-03-29 18:43:25 +00:00
|
|
|
}
|
|
|
|
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_sdp_media_attributes_to_caps")]
|
2020-12-29 14:55:45 +00:00
|
|
|
pub fn attributes_to_caps(&self, caps: &mut gst::CapsRef) -> Result<(), glib::BoolError> {
|
2020-11-22 10:38:16 +00:00
|
|
|
let result = unsafe { ffi::gst_sdp_media_attributes_to_caps(&self.0, caps.as_mut_ptr()) };
|
2018-03-29 18:43:25 +00:00
|
|
|
match result {
|
2020-11-22 10:38:16 +00:00
|
|
|
ffi::GST_SDP_OK => Ok(()),
|
2020-12-29 14:55:45 +00:00
|
|
|
_ => Err(glib::bool_error!("Failed to store attributes in caps")),
|
2018-03-29 18:43:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_sdp_media_bandwidths_len")]
|
2018-03-29 18:43:25 +00:00
|
|
|
pub fn bandwidths_len(&self) -> u32 {
|
2020-11-22 10:38:16 +00:00
|
|
|
unsafe { ffi::gst_sdp_media_bandwidths_len(&self.0) }
|
2018-03-29 18:43:25 +00:00
|
|
|
}
|
|
|
|
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_sdp_media_connections_len")]
|
2018-03-29 18:43:25 +00:00
|
|
|
pub fn connections_len(&self) -> u32 {
|
2020-11-22 10:38:16 +00:00
|
|
|
unsafe { ffi::gst_sdp_media_connections_len(&self.0) }
|
2018-03-29 18:43:25 +00:00
|
|
|
}
|
|
|
|
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_sdp_media_formats_len")]
|
2018-03-29 18:43:25 +00:00
|
|
|
pub fn formats_len(&self) -> u32 {
|
2020-11-22 10:38:16 +00:00
|
|
|
unsafe { ffi::gst_sdp_media_formats_len(&self.0) }
|
2018-03-29 18:43:25 +00:00
|
|
|
}
|
|
|
|
|
2021-05-02 09:41:18 +00:00
|
|
|
#[doc(alias = "get_attribute")]
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_sdp_media_get_attribute")]
|
2021-04-20 10:23:24 +00:00
|
|
|
pub fn attribute(&self, idx: u32) -> Option<&SDPAttribute> {
|
2019-02-27 16:14:46 +00:00
|
|
|
if idx >= self.attributes_len() {
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
|
2018-03-29 18:43:25 +00:00
|
|
|
unsafe {
|
2020-11-22 10:38:16 +00:00
|
|
|
let ptr = ffi::gst_sdp_media_get_attribute(&self.0, idx);
|
2018-04-04 18:40:45 +00:00
|
|
|
if ptr.is_null() {
|
|
|
|
None
|
|
|
|
} else {
|
|
|
|
Some(&*(ptr as *mut SDPAttribute))
|
|
|
|
}
|
2018-03-29 18:43:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-02 09:41:18 +00:00
|
|
|
#[doc(alias = "get_attribute_val")]
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_sdp_media_get_attribute_val")]
|
2021-04-20 10:23:24 +00:00
|
|
|
pub fn attribute_val(&self, key: &str) -> Option<&str> {
|
2018-03-29 18:43:25 +00:00
|
|
|
unsafe {
|
2020-11-22 10:38:16 +00:00
|
|
|
let ptr = ffi::gst_sdp_media_get_attribute_val(&self.0, key.to_glib_none().0);
|
2018-04-04 18:40:45 +00:00
|
|
|
if ptr.is_null() {
|
|
|
|
None
|
|
|
|
} else {
|
2021-01-07 21:49:11 +00:00
|
|
|
CStr::from_ptr(ptr).to_str().ok()
|
2018-04-04 18:40:45 +00:00
|
|
|
}
|
2018-03-29 18:43:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-02 09:41:18 +00:00
|
|
|
#[doc(alias = "get_attribute_val_n")]
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_sdp_media_get_attribute_val_n")]
|
2021-04-20 10:23:24 +00:00
|
|
|
pub fn attribute_val_n(&self, key: &str, nth: u32) -> Option<&str> {
|
2018-03-29 18:43:25 +00:00
|
|
|
unsafe {
|
2020-11-22 10:38:16 +00:00
|
|
|
let ptr = ffi::gst_sdp_media_get_attribute_val_n(&self.0, key.to_glib_none().0, nth);
|
2018-04-04 18:40:45 +00:00
|
|
|
if ptr.is_null() {
|
|
|
|
None
|
|
|
|
} else {
|
2021-01-07 21:49:11 +00:00
|
|
|
CStr::from_ptr(ptr).to_str().ok()
|
2018-04-04 18:40:45 +00:00
|
|
|
}
|
2018-03-29 18:43:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-02 09:41:18 +00:00
|
|
|
#[doc(alias = "get_bandwidth")]
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_sdp_media_get_bandwidth")]
|
2021-04-20 10:23:24 +00:00
|
|
|
pub fn bandwidth(&self, idx: u32) -> Option<&SDPBandwidth> {
|
2019-02-27 16:14:46 +00:00
|
|
|
if idx >= self.bandwidths_len() {
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
|
2018-03-29 18:43:25 +00:00
|
|
|
unsafe {
|
2020-11-22 10:38:16 +00:00
|
|
|
let ptr = ffi::gst_sdp_media_get_bandwidth(&self.0, idx);
|
2018-04-04 18:40:45 +00:00
|
|
|
if ptr.is_null() {
|
|
|
|
None
|
|
|
|
} else {
|
|
|
|
Some(&*(ptr as *mut SDPBandwidth))
|
|
|
|
}
|
2018-03-29 18:43:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-02 09:41:18 +00:00
|
|
|
#[doc(alias = "get_caps_from_media")]
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_sdp_media_get_caps_from_media")]
|
2021-04-20 10:23:24 +00:00
|
|
|
pub fn caps_from_media(&self, pt: i32) -> Option<gst::Caps> {
|
2020-11-22 10:38:16 +00:00
|
|
|
unsafe { from_glib_full(ffi::gst_sdp_media_get_caps_from_media(&self.0, pt)) }
|
2018-03-29 18:43:25 +00:00
|
|
|
}
|
|
|
|
|
2021-05-02 09:41:18 +00:00
|
|
|
#[doc(alias = "get_connection")]
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_sdp_media_get_connection")]
|
2021-04-20 10:23:24 +00:00
|
|
|
pub fn connection(&self, idx: u32) -> Option<&SDPConnection> {
|
2019-02-27 16:14:46 +00:00
|
|
|
if idx >= self.connections_len() {
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
|
2018-03-29 18:43:25 +00:00
|
|
|
unsafe {
|
2020-11-22 10:38:16 +00:00
|
|
|
let ptr = ffi::gst_sdp_media_get_connection(&self.0, idx);
|
2018-04-04 18:40:45 +00:00
|
|
|
if ptr.is_null() {
|
|
|
|
None
|
|
|
|
} else {
|
|
|
|
Some(&*(ptr as *mut SDPConnection))
|
|
|
|
}
|
2018-03-29 18:43:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-02 09:41:18 +00:00
|
|
|
#[doc(alias = "get_format")]
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_sdp_media_get_format")]
|
2021-04-20 10:23:24 +00:00
|
|
|
pub fn format(&self, idx: u32) -> Option<&str> {
|
2019-02-27 16:14:46 +00:00
|
|
|
if idx >= self.formats_len() {
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
|
2018-03-29 18:43:25 +00:00
|
|
|
unsafe {
|
2020-11-22 10:38:16 +00:00
|
|
|
let ptr = ffi::gst_sdp_media_get_format(&self.0, idx);
|
2018-04-04 18:40:45 +00:00
|
|
|
if ptr.is_null() {
|
|
|
|
None
|
|
|
|
} else {
|
2021-01-07 21:49:11 +00:00
|
|
|
CStr::from_ptr(ptr).to_str().ok()
|
2018-04-04 18:40:45 +00:00
|
|
|
}
|
2018-03-29 18:43:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-02 09:41:18 +00:00
|
|
|
#[doc(alias = "get_information")]
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_sdp_media_get_information")]
|
2021-04-11 19:39:50 +00:00
|
|
|
pub fn information(&self) -> Option<&str> {
|
2018-03-29 18:43:25 +00:00
|
|
|
unsafe {
|
2020-11-22 10:38:16 +00:00
|
|
|
let ptr = ffi::gst_sdp_media_get_information(&self.0);
|
2018-04-04 18:40:45 +00:00
|
|
|
if ptr.is_null() {
|
|
|
|
None
|
|
|
|
} else {
|
2021-01-07 21:49:11 +00:00
|
|
|
CStr::from_ptr(ptr).to_str().ok()
|
2018-04-04 18:40:45 +00:00
|
|
|
}
|
2018-03-29 18:43:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-02 09:41:18 +00:00
|
|
|
#[doc(alias = "get_key")]
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_sdp_media_get_key")]
|
2021-04-11 19:39:50 +00:00
|
|
|
pub fn key(&self) -> Option<&SDPKey> {
|
2018-03-29 18:43:25 +00:00
|
|
|
unsafe {
|
2020-11-22 10:38:16 +00:00
|
|
|
let ptr = ffi::gst_sdp_media_get_key(&self.0);
|
2018-04-04 18:40:45 +00:00
|
|
|
if ptr.is_null() {
|
|
|
|
None
|
|
|
|
} else {
|
|
|
|
Some(&*(ptr as *mut SDPKey))
|
|
|
|
}
|
2018-03-29 18:43:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-02 09:41:18 +00:00
|
|
|
#[doc(alias = "get_media")]
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_sdp_media_get_media")]
|
2021-04-11 19:39:50 +00:00
|
|
|
pub fn media(&self) -> Option<&str> {
|
2018-03-29 18:43:25 +00:00
|
|
|
unsafe {
|
2020-11-22 10:38:16 +00:00
|
|
|
let ptr = ffi::gst_sdp_media_get_media(&self.0);
|
2018-04-04 18:40:45 +00:00
|
|
|
if ptr.is_null() {
|
|
|
|
None
|
|
|
|
} else {
|
2021-01-07 21:49:11 +00:00
|
|
|
CStr::from_ptr(ptr).to_str().ok()
|
2018-04-04 18:40:45 +00:00
|
|
|
}
|
2018-03-29 18:43:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-02 09:41:18 +00:00
|
|
|
#[doc(alias = "get_num_ports")]
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_sdp_media_get_num_ports")]
|
2021-04-11 19:39:50 +00:00
|
|
|
pub fn num_ports(&self) -> u32 {
|
2020-11-22 10:38:16 +00:00
|
|
|
unsafe { ffi::gst_sdp_media_get_num_ports(&self.0) }
|
2018-03-29 18:43:25 +00:00
|
|
|
}
|
|
|
|
|
2021-05-02 09:41:18 +00:00
|
|
|
#[doc(alias = "get_port")]
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_sdp_media_get_port")]
|
2021-04-11 19:39:50 +00:00
|
|
|
pub fn port(&self) -> u32 {
|
2020-11-22 10:38:16 +00:00
|
|
|
unsafe { ffi::gst_sdp_media_get_port(&self.0) }
|
2018-03-29 18:43:25 +00:00
|
|
|
}
|
|
|
|
|
2021-05-02 09:41:18 +00:00
|
|
|
#[doc(alias = "get_proto")]
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_sdp_media_get_proto")]
|
2021-04-11 19:39:50 +00:00
|
|
|
pub fn proto(&self) -> Option<&str> {
|
2018-03-29 18:43:25 +00:00
|
|
|
unsafe {
|
2020-11-22 10:38:16 +00:00
|
|
|
let ptr = ffi::gst_sdp_media_get_proto(&self.0);
|
2018-04-04 18:40:45 +00:00
|
|
|
if ptr.is_null() {
|
|
|
|
None
|
|
|
|
} else {
|
2021-01-07 21:49:11 +00:00
|
|
|
CStr::from_ptr(ptr).to_str().ok()
|
2018-03-29 18:43:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_sdp_media_insert_attribute")]
|
2020-12-29 14:55:45 +00:00
|
|
|
pub fn insert_attribute(
|
|
|
|
&mut self,
|
|
|
|
idx: Option<u32>,
|
|
|
|
attr: SDPAttribute,
|
|
|
|
) -> Result<(), glib::BoolError> {
|
2019-02-27 16:14:46 +00:00
|
|
|
if let Some(idx) = idx {
|
|
|
|
if idx >= self.attributes_len() {
|
2020-12-29 14:55:45 +00:00
|
|
|
return Err(glib::bool_error!("Failed to insert attribute"));
|
2019-02-27 16:14:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let idx = idx.map(|idx| idx as i32).unwrap_or(-1);
|
2020-04-09 12:59:14 +00:00
|
|
|
let mut attr = mem::ManuallyDrop::new(attr);
|
2020-11-22 10:38:16 +00:00
|
|
|
let result = unsafe { ffi::gst_sdp_media_insert_attribute(&mut self.0, idx, &mut attr.0) };
|
2018-03-29 18:43:25 +00:00
|
|
|
match result {
|
2020-11-22 10:38:16 +00:00
|
|
|
ffi::GST_SDP_OK => Ok(()),
|
2020-12-29 14:55:45 +00:00
|
|
|
_ => Err(glib::bool_error!("Failed to insert attribute")),
|
2018-03-29 18:43:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_sdp_media_insert_bandwidth")]
|
2020-12-29 14:55:45 +00:00
|
|
|
pub fn insert_bandwidth(
|
|
|
|
&mut self,
|
|
|
|
idx: Option<u32>,
|
|
|
|
bw: SDPBandwidth,
|
|
|
|
) -> Result<(), glib::BoolError> {
|
2019-02-27 16:14:46 +00:00
|
|
|
if let Some(idx) = idx {
|
|
|
|
if idx >= self.bandwidths_len() {
|
2020-12-29 14:55:45 +00:00
|
|
|
return Err(glib::bool_error!("Failed to insert bandwidth"));
|
2019-02-27 16:14:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let idx = idx.map(|idx| idx as i32).unwrap_or(-1);
|
2020-04-09 12:59:14 +00:00
|
|
|
let mut bw = mem::ManuallyDrop::new(bw);
|
2020-11-22 10:38:16 +00:00
|
|
|
let result = unsafe { ffi::gst_sdp_media_insert_bandwidth(&mut self.0, idx, &mut bw.0) };
|
2018-03-29 18:43:25 +00:00
|
|
|
match result {
|
2020-11-22 10:38:16 +00:00
|
|
|
ffi::GST_SDP_OK => Ok(()),
|
2020-12-29 14:55:45 +00:00
|
|
|
_ => Err(glib::bool_error!("Failed to insert attribute")),
|
2018-03-29 18:43:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_sdp_media_insert_connection")]
|
2020-12-29 14:55:45 +00:00
|
|
|
pub fn insert_connection(
|
|
|
|
&mut self,
|
|
|
|
idx: Option<u32>,
|
|
|
|
conn: SDPConnection,
|
|
|
|
) -> Result<(), glib::BoolError> {
|
2019-02-27 16:14:46 +00:00
|
|
|
if let Some(idx) = idx {
|
|
|
|
if idx >= self.connections_len() {
|
2020-12-29 14:55:45 +00:00
|
|
|
return Err(glib::bool_error!("Failed to insert connection"));
|
2019-02-27 16:14:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let idx = idx.map(|idx| idx as i32).unwrap_or(-1);
|
2020-04-09 12:59:14 +00:00
|
|
|
let mut conn = mem::ManuallyDrop::new(conn);
|
2020-11-22 10:38:16 +00:00
|
|
|
let result = unsafe { ffi::gst_sdp_media_insert_connection(&mut self.0, idx, &mut conn.0) };
|
2018-03-29 18:43:25 +00:00
|
|
|
match result {
|
2020-11-22 10:38:16 +00:00
|
|
|
ffi::GST_SDP_OK => Ok(()),
|
2020-12-29 14:55:45 +00:00
|
|
|
_ => Err(glib::bool_error!("Failed to insert connection")),
|
2018-03-29 18:43:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_sdp_media_insert_format")]
|
2020-12-29 14:55:45 +00:00
|
|
|
pub fn insert_format(&mut self, idx: Option<u32>, format: &str) -> Result<(), glib::BoolError> {
|
2019-02-27 16:14:46 +00:00
|
|
|
if let Some(idx) = idx {
|
|
|
|
if idx >= self.formats_len() {
|
2020-12-29 14:55:45 +00:00
|
|
|
return Err(glib::bool_error!("Failed to insert format"));
|
2019-02-27 16:14:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let idx = idx.map(|idx| idx as i32).unwrap_or(-1);
|
2020-11-22 10:38:16 +00:00
|
|
|
let result =
|
|
|
|
unsafe { ffi::gst_sdp_media_insert_format(&mut self.0, idx, format.to_glib_none().0) };
|
2018-03-29 18:43:25 +00:00
|
|
|
match result {
|
2020-11-22 10:38:16 +00:00
|
|
|
ffi::GST_SDP_OK => Ok(()),
|
2020-12-29 14:55:45 +00:00
|
|
|
_ => Err(glib::bool_error!("Failed to insert format")),
|
2018-03-29 18:43:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_sdp_media_remove_attribute")]
|
2020-12-29 14:55:45 +00:00
|
|
|
pub fn remove_attribute(&mut self, idx: u32) -> Result<(), glib::BoolError> {
|
2019-02-27 16:14:46 +00:00
|
|
|
if idx >= self.attributes_len() {
|
2020-12-29 14:55:45 +00:00
|
|
|
return Err(glib::bool_error!("Failed to remove attribute"));
|
2019-02-27 16:14:46 +00:00
|
|
|
}
|
|
|
|
|
2020-11-22 10:38:16 +00:00
|
|
|
let result = unsafe { ffi::gst_sdp_media_remove_attribute(&mut self.0, idx) };
|
2018-03-29 18:43:25 +00:00
|
|
|
match result {
|
2020-11-22 10:38:16 +00:00
|
|
|
ffi::GST_SDP_OK => Ok(()),
|
2020-12-29 14:55:45 +00:00
|
|
|
_ => Err(glib::bool_error!("Failed to remove attribute")),
|
2018-03-29 18:43:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_sdp_media_remove_bandwidth")]
|
2020-12-29 14:55:45 +00:00
|
|
|
pub fn remove_bandwidth(&mut self, idx: u32) -> Result<(), glib::BoolError> {
|
2019-02-27 16:14:46 +00:00
|
|
|
if idx >= self.bandwidths_len() {
|
2020-12-29 14:55:45 +00:00
|
|
|
return Err(glib::bool_error!("Failed to remove bandwidth"));
|
2019-02-27 16:14:46 +00:00
|
|
|
}
|
|
|
|
|
2020-11-22 10:38:16 +00:00
|
|
|
let result = unsafe { ffi::gst_sdp_media_remove_bandwidth(&mut self.0, idx) };
|
2018-03-29 18:43:25 +00:00
|
|
|
match result {
|
2020-11-22 10:38:16 +00:00
|
|
|
ffi::GST_SDP_OK => Ok(()),
|
2020-12-29 14:55:45 +00:00
|
|
|
_ => Err(glib::bool_error!("Failed to remove bandwidth")),
|
2018-03-29 18:43:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_sdp_media_remove_connection")]
|
2020-12-29 14:55:45 +00:00
|
|
|
pub fn remove_connection(&mut self, idx: u32) -> Result<(), glib::BoolError> {
|
2019-02-27 16:14:46 +00:00
|
|
|
if idx >= self.connections_len() {
|
2020-12-29 14:55:45 +00:00
|
|
|
return Err(glib::bool_error!("Failed to remove connection"));
|
2019-02-27 16:14:46 +00:00
|
|
|
}
|
|
|
|
|
2020-11-22 10:38:16 +00:00
|
|
|
let result = unsafe { ffi::gst_sdp_media_remove_connection(&mut self.0, idx) };
|
2018-03-29 18:43:25 +00:00
|
|
|
match result {
|
2020-11-22 10:38:16 +00:00
|
|
|
ffi::GST_SDP_OK => Ok(()),
|
2020-12-29 14:55:45 +00:00
|
|
|
_ => Err(glib::bool_error!("Failed to remove connection")),
|
2018-03-29 18:43:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_sdp_media_remove_format")]
|
2020-12-29 14:55:45 +00:00
|
|
|
pub fn remove_format(&mut self, idx: u32) -> Result<(), glib::BoolError> {
|
2019-02-27 16:14:46 +00:00
|
|
|
if idx >= self.formats_len() {
|
2020-12-29 14:55:45 +00:00
|
|
|
return Err(glib::bool_error!("Failed to remove format"));
|
2019-02-27 16:14:46 +00:00
|
|
|
}
|
|
|
|
|
2020-11-22 10:38:16 +00:00
|
|
|
let result = unsafe { ffi::gst_sdp_media_remove_format(&mut self.0, idx) };
|
2018-03-29 18:43:25 +00:00
|
|
|
match result {
|
2020-11-22 10:38:16 +00:00
|
|
|
ffi::GST_SDP_OK => Ok(()),
|
2020-12-29 14:55:45 +00:00
|
|
|
_ => Err(glib::bool_error!("Failed to remove format")),
|
2018-03-29 18:43:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_sdp_media_replace_attribute")]
|
2020-12-29 14:55:45 +00:00
|
|
|
pub fn replace_attribute(
|
|
|
|
&mut self,
|
|
|
|
idx: u32,
|
|
|
|
attr: SDPAttribute,
|
|
|
|
) -> Result<(), glib::BoolError> {
|
2019-02-27 16:14:46 +00:00
|
|
|
if idx >= self.attributes_len() {
|
2020-12-29 14:55:45 +00:00
|
|
|
return Err(glib::bool_error!("Failed to replace attribute"));
|
2019-02-27 16:14:46 +00:00
|
|
|
}
|
|
|
|
|
2020-04-09 12:59:14 +00:00
|
|
|
let mut attr = mem::ManuallyDrop::new(attr);
|
2020-11-22 10:38:16 +00:00
|
|
|
let result = unsafe { ffi::gst_sdp_media_replace_attribute(&mut self.0, idx, &mut attr.0) };
|
2018-03-29 18:43:25 +00:00
|
|
|
match result {
|
2020-11-22 10:38:16 +00:00
|
|
|
ffi::GST_SDP_OK => Ok(()),
|
2020-12-29 14:55:45 +00:00
|
|
|
_ => Err(glib::bool_error!("Failed to replace attribute")),
|
2018-03-29 18:43:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_sdp_media_replace_bandwidth")]
|
2020-12-29 14:55:45 +00:00
|
|
|
pub fn replace_bandwidth(&mut self, idx: u32, bw: SDPBandwidth) -> Result<(), glib::BoolError> {
|
2019-02-27 16:14:46 +00:00
|
|
|
if idx >= self.bandwidths_len() {
|
2020-12-29 14:55:45 +00:00
|
|
|
return Err(glib::bool_error!("Failed to replace bandwidth"));
|
2019-02-27 16:14:46 +00:00
|
|
|
}
|
|
|
|
|
2020-04-09 12:59:14 +00:00
|
|
|
let mut bw = mem::ManuallyDrop::new(bw);
|
2020-11-22 10:38:16 +00:00
|
|
|
let result = unsafe { ffi::gst_sdp_media_replace_bandwidth(&mut self.0, idx, &mut bw.0) };
|
2018-03-29 18:43:25 +00:00
|
|
|
match result {
|
2020-11-22 10:38:16 +00:00
|
|
|
ffi::GST_SDP_OK => Ok(()),
|
2020-12-29 14:55:45 +00:00
|
|
|
_ => Err(glib::bool_error!("Failed to replace bandwidth")),
|
2018-03-29 18:43:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_sdp_media_replace_connection")]
|
2020-12-29 14:55:45 +00:00
|
|
|
pub fn replace_connection(
|
|
|
|
&mut self,
|
|
|
|
idx: u32,
|
|
|
|
conn: SDPConnection,
|
|
|
|
) -> Result<(), glib::BoolError> {
|
2019-02-27 16:14:46 +00:00
|
|
|
if idx >= self.connections_len() {
|
2020-12-29 14:55:45 +00:00
|
|
|
return Err(glib::bool_error!("Failed to replace connection"));
|
2019-02-27 16:14:46 +00:00
|
|
|
}
|
|
|
|
|
2020-04-09 12:59:14 +00:00
|
|
|
let mut conn = mem::ManuallyDrop::new(conn);
|
2019-02-27 16:04:12 +00:00
|
|
|
let result =
|
2020-11-22 10:38:16 +00:00
|
|
|
unsafe { ffi::gst_sdp_media_replace_connection(&mut self.0, idx, &mut conn.0) };
|
2018-03-29 18:43:25 +00:00
|
|
|
match result {
|
2020-11-22 10:38:16 +00:00
|
|
|
ffi::GST_SDP_OK => Ok(()),
|
2020-12-29 14:55:45 +00:00
|
|
|
_ => Err(glib::bool_error!("Failed to replace connection")),
|
2018-03-29 18:43:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_sdp_media_replace_format")]
|
2020-12-29 14:55:45 +00:00
|
|
|
pub fn replace_format(&mut self, idx: u32, format: &str) -> Result<(), glib::BoolError> {
|
2019-02-27 16:14:46 +00:00
|
|
|
if idx >= self.formats_len() {
|
2020-12-29 14:55:45 +00:00
|
|
|
return Err(glib::bool_error!("Failed to replace format"));
|
2019-02-27 16:14:46 +00:00
|
|
|
}
|
|
|
|
|
2020-11-22 10:38:16 +00:00
|
|
|
let result =
|
|
|
|
unsafe { ffi::gst_sdp_media_replace_format(&mut self.0, idx, format.to_glib_none().0) };
|
2018-03-29 18:43:25 +00:00
|
|
|
match result {
|
2020-11-22 10:38:16 +00:00
|
|
|
ffi::GST_SDP_OK => Ok(()),
|
2020-12-29 14:55:45 +00:00
|
|
|
_ => Err(glib::bool_error!("Failed to replace format")),
|
2018-03-29 18:43:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_sdp_media_set_information")]
|
2019-02-28 18:34:31 +00:00
|
|
|
pub fn set_information(&mut self, information: &str) {
|
2020-11-22 10:38:16 +00:00
|
|
|
unsafe { ffi::gst_sdp_media_set_information(&mut self.0, information.to_glib_none().0) };
|
2018-03-29 18:43:25 +00:00
|
|
|
}
|
|
|
|
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_sdp_media_set_key")]
|
2019-02-28 18:34:31 +00:00
|
|
|
pub fn set_key(&mut self, type_: &str, data: &str) {
|
|
|
|
unsafe {
|
2020-11-22 10:38:16 +00:00
|
|
|
ffi::gst_sdp_media_set_key(&mut self.0, type_.to_glib_none().0, data.to_glib_none().0)
|
2018-03-29 18:43:25 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_sdp_media_set_media")]
|
2019-02-28 18:34:31 +00:00
|
|
|
pub fn set_media(&mut self, med: &str) {
|
2020-11-22 10:38:16 +00:00
|
|
|
unsafe { ffi::gst_sdp_media_set_media(&mut self.0, med.to_glib_none().0) };
|
2018-03-29 18:43:25 +00:00
|
|
|
}
|
|
|
|
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_sdp_media_set_port_info")]
|
2019-02-28 18:34:31 +00:00
|
|
|
pub fn set_port_info(&mut self, port: u32, num_ports: u32) {
|
2020-11-22 10:38:16 +00:00
|
|
|
unsafe { ffi::gst_sdp_media_set_port_info(&mut self.0, port, num_ports) };
|
2018-03-29 18:43:25 +00:00
|
|
|
}
|
|
|
|
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_sdp_media_set_proto")]
|
2019-02-28 18:34:31 +00:00
|
|
|
pub fn set_proto(&mut self, proto: &str) {
|
2020-11-22 10:38:16 +00:00
|
|
|
unsafe { ffi::gst_sdp_media_set_proto(&mut self.0, proto.to_glib_none().0) };
|
2018-03-29 18:43:25 +00:00
|
|
|
}
|
|
|
|
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_sdp_media_set_media_from_caps")]
|
2020-12-29 14:55:45 +00:00
|
|
|
pub fn set_media_from_caps(
|
2022-11-21 09:38:45 +00:00
|
|
|
caps: &gst::CapsRef,
|
2020-12-29 14:55:45 +00:00
|
|
|
media: &mut SDPMedia,
|
|
|
|
) -> Result<(), glib::BoolError> {
|
2022-12-25 10:47:02 +00:00
|
|
|
skip_assert_initialized!();
|
2018-03-29 18:43:25 +00:00
|
|
|
let result = unsafe {
|
2022-11-21 09:38:45 +00:00
|
|
|
ffi::gst_sdp_media_set_media_from_caps(caps.as_ptr(), media.to_glib_none_mut().0)
|
2018-03-29 18:43:25 +00:00
|
|
|
};
|
|
|
|
match result {
|
2020-11-22 10:38:16 +00:00
|
|
|
ffi::GST_SDP_OK => Ok(()),
|
2020-12-29 14:55:45 +00:00
|
|
|
_ => Err(glib::bool_error!("Failed to set media from caps")),
|
2018-03-29 18:43:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-02-27 16:10:31 +00:00
|
|
|
|
2019-02-28 09:26:15 +00:00
|
|
|
impl Borrow<SDPMediaRef> for SDPMedia {
|
|
|
|
fn borrow(&self) -> &SDPMediaRef {
|
2022-06-30 12:22:30 +00:00
|
|
|
self
|
2019-02-28 09:26:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl BorrowMut<SDPMediaRef> for SDPMedia {
|
|
|
|
fn borrow_mut(&mut self) -> &mut SDPMediaRef {
|
|
|
|
&mut *self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ToOwned for SDPMediaRef {
|
|
|
|
type Owned = SDPMedia;
|
|
|
|
|
|
|
|
fn to_owned(&self) -> SDPMedia {
|
|
|
|
unsafe {
|
|
|
|
let mut ptr = ptr::null_mut();
|
2020-11-22 10:38:16 +00:00
|
|
|
ffi::gst_sdp_media_copy(&self.0, &mut ptr);
|
2019-02-28 09:26:15 +00:00
|
|
|
from_glib_full(ptr)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-27 16:10:31 +00:00
|
|
|
macro_rules! define_iter(
|
|
|
|
($name:ident, $typ:ty, $get_item:expr, $get_len:expr) => {
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct $name<'a> {
|
|
|
|
media: &'a SDPMediaRef,
|
2022-05-20 13:58:46 +00:00
|
|
|
idx: usize,
|
|
|
|
len: usize,
|
2019-02-27 16:10:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> $name<'a> {
|
2023-08-22 07:00:35 +00:00
|
|
|
#[allow(clippy::redundant_closure_call)]
|
2019-02-27 16:10:31 +00:00
|
|
|
fn new(media: &'a SDPMediaRef) -> $name<'a> {
|
|
|
|
skip_assert_initialized!();
|
2021-04-20 13:12:36 +00:00
|
|
|
let len = $get_len(media);
|
2019-02-27 16:10:31 +00:00
|
|
|
|
|
|
|
$name {
|
|
|
|
media,
|
|
|
|
idx: 0,
|
2022-05-20 13:58:46 +00:00
|
|
|
len: len as usize,
|
2019-02-27 16:10:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-22 07:00:35 +00:00
|
|
|
#[allow(clippy::redundant_closure_call)]
|
2019-02-27 16:10:31 +00:00
|
|
|
impl<'a> Iterator for $name<'a> {
|
|
|
|
type Item = $typ;
|
|
|
|
|
|
|
|
fn next(&mut self) -> Option<Self::Item> {
|
|
|
|
if self.idx >= self.len {
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
|
2022-05-20 13:58:46 +00:00
|
|
|
let item = $get_item(self.media, self.idx as u32).unwrap();
|
2019-02-27 16:10:31 +00:00
|
|
|
self.idx += 1;
|
|
|
|
Some(item)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn size_hint(&self) -> (usize, Option<usize>) {
|
2022-05-20 13:58:46 +00:00
|
|
|
let remaining = self.len - self.idx;
|
2019-02-27 16:10:31 +00:00
|
|
|
|
|
|
|
(remaining, Some(remaining))
|
|
|
|
}
|
2022-05-20 13:58:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
fn count(self) -> usize {
|
|
|
|
self.len - self.idx
|
|
|
|
}
|
|
|
|
|
|
|
|
fn nth(&mut self, n: usize) -> Option<Self::Item> {
|
|
|
|
let (end, overflow) = self.idx.overflowing_add(n);
|
|
|
|
if end >= self.len || overflow {
|
|
|
|
self.idx = self.len;
|
|
|
|
None
|
|
|
|
} else {
|
|
|
|
self.idx = end + 1;
|
|
|
|
Some($get_item(self.media, end as u32).unwrap())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn last(self) -> Option<Self::Item> {
|
|
|
|
if self.idx == self.len {
|
|
|
|
None
|
|
|
|
} else {
|
|
|
|
Some($get_item(self.media, self.len as u32 - 1).unwrap())
|
|
|
|
}
|
|
|
|
}
|
2019-02-27 16:10:31 +00:00
|
|
|
}
|
|
|
|
|
2023-08-22 07:00:35 +00:00
|
|
|
#[allow(clippy::redundant_closure_call)]
|
2019-02-27 16:10:31 +00:00
|
|
|
impl<'a> DoubleEndedIterator for $name<'a> {
|
|
|
|
fn next_back(&mut self) -> Option<Self::Item> {
|
|
|
|
if self.idx == self.len {
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
|
|
|
|
self.len -= 1;
|
|
|
|
|
2022-05-20 13:58:46 +00:00
|
|
|
Some($get_item(self.media, self.len as u32).unwrap())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn nth_back(&mut self, n: usize) -> Option<Self::Item> {
|
|
|
|
let (end, overflow) = self.len.overflowing_sub(n);
|
|
|
|
if end <= self.idx || overflow {
|
|
|
|
self.idx = self.len;
|
|
|
|
None
|
|
|
|
} else {
|
|
|
|
self.len = end - 1;
|
|
|
|
Some($get_item(self.media, self.len as u32).unwrap())
|
|
|
|
}
|
2019-02-27 16:10:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> ExactSizeIterator for $name<'a> {}
|
2022-05-20 13:58:46 +00:00
|
|
|
|
|
|
|
impl<'a> std::iter::FusedIterator for $name<'a> {}
|
2019-02-27 16:10:31 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
define_iter!(
|
|
|
|
BandwidthsIter,
|
|
|
|
&'a SDPBandwidth,
|
2021-04-20 10:24:17 +00:00
|
|
|
|media: &'a SDPMediaRef, idx| media.bandwidth(idx),
|
2019-02-27 16:10:31 +00:00
|
|
|
|media: &SDPMediaRef| media.bandwidths_len()
|
|
|
|
);
|
|
|
|
define_iter!(
|
|
|
|
FormatsIter,
|
|
|
|
&'a str,
|
2021-04-20 10:24:17 +00:00
|
|
|
|media: &'a SDPMediaRef, idx| media.format(idx),
|
2019-02-27 16:10:31 +00:00
|
|
|
|media: &SDPMediaRef| media.formats_len()
|
|
|
|
);
|
|
|
|
define_iter!(
|
|
|
|
ConnectionsIter,
|
|
|
|
&'a SDPConnection,
|
2021-04-20 10:24:17 +00:00
|
|
|
|media: &'a SDPMediaRef, idx| media.connection(idx),
|
2019-02-27 16:10:31 +00:00
|
|
|
|media: &SDPMediaRef| media.connections_len()
|
|
|
|
);
|
|
|
|
define_iter!(
|
|
|
|
AttributesIter,
|
|
|
|
&'a SDPAttribute,
|
2021-04-20 10:24:17 +00:00
|
|
|
|media: &'a SDPMediaRef, idx| media.attribute(idx),
|
2019-02-27 16:10:31 +00:00
|
|
|
|media: &SDPMediaRef| media.attributes_len()
|
|
|
|
);
|
2019-11-20 21:57:46 +00:00
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
fn init() {
|
|
|
|
gst::init().unwrap();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn debug_impl() {
|
|
|
|
init();
|
|
|
|
|
|
|
|
let sdp = SDPMedia::new();
|
2023-01-25 08:09:45 +00:00
|
|
|
assert!(!format!("{sdp:?}").is_empty());
|
2019-11-20 21:57:46 +00:00
|
|
|
}
|
|
|
|
}
|