rtsp-server: Add RTSPContext uri getter

Add uri getter from RTSPContext

Fix #469

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1271>
This commit is contained in:
Daniel Pendse 2023-05-30 12:36:08 +02:00
parent 5f8aaed96b
commit 2becc79dfb
2 changed files with 28 additions and 2 deletions

View file

@ -303,6 +303,12 @@ mod client {
self.parent_closed(); self.parent_closed();
println!("Client {client:?} closed"); println!("Client {client:?} closed");
} }
fn describe_request(&self, ctx: &gst_rtsp_server::RTSPContext) {
self.parent_describe_request(ctx);
let request_uri = ctx.uri().unwrap().request_uri();
println!("Describe request for uri: {request_uri:?}");
}
} }
} }

View file

@ -1,11 +1,16 @@
// Take a look at the license at the top of the repository in the LICENSE file. // Take a look at the license at the top of the repository in the LICENSE file.
use std::{marker::PhantomData, ptr}; use std::{
marker::PhantomData,
ptr::{self, addr_of},
};
use glib::translate::*; use glib::translate::*;
use gst_rtsp::RTSPUrl;
#[derive(Debug, PartialEq, Eq)] #[derive(Debug, PartialEq, Eq)]
#[doc(alias = "GstRTSPContext")] #[doc(alias = "GstRTSPContext")]
#[repr(transparent)]
pub struct RTSPContext(ptr::NonNull<ffi::GstRTSPContext>); pub struct RTSPContext(ptr::NonNull<ffi::GstRTSPContext>);
impl RTSPContext { impl RTSPContext {
@ -22,7 +27,22 @@ impl RTSPContext {
} }
} }
// TODO: Add various getters for all the contained fields as needed #[inline]
pub fn uri(&self) -> Option<&RTSPUrl> {
unsafe {
let ptr = self.0.as_ptr();
if (*ptr).uri.is_null() {
None
} else {
let uri = RTSPUrl::from_glib_ptr_borrow(
addr_of!((*ptr).uri) as *const *const gst_rtsp::ffi::GstRTSPUrl
);
Some(uri)
}
}
}
// TODO: Add additional getters for all the contained fields as needed
} }
#[doc(hidden)] #[doc(hidden)]