From 2becc79dfb88a7d9aab8496fc5d401cb31f67d87 Mon Sep 17 00:00:00 2001 From: Daniel Pendse Date: Tue, 30 May 2023 12:36:08 +0200 Subject: [PATCH] rtsp-server: Add RTSPContext uri getter Add uri getter from RTSPContext Fix #469 Part-of: --- examples/src/bin/rtsp-server-subclass.rs | 6 ++++++ gstreamer-rtsp-server/src/rtsp_context.rs | 24 +++++++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/examples/src/bin/rtsp-server-subclass.rs b/examples/src/bin/rtsp-server-subclass.rs index 170149603..46d542574 100644 --- a/examples/src/bin/rtsp-server-subclass.rs +++ b/examples/src/bin/rtsp-server-subclass.rs @@ -303,6 +303,12 @@ mod client { self.parent_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:?}"); + } } } diff --git a/gstreamer-rtsp-server/src/rtsp_context.rs b/gstreamer-rtsp-server/src/rtsp_context.rs index cda3e3c2c..3be5b399d 100644 --- a/gstreamer-rtsp-server/src/rtsp_context.rs +++ b/gstreamer-rtsp-server/src/rtsp_context.rs @@ -1,11 +1,16 @@ // 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 gst_rtsp::RTSPUrl; #[derive(Debug, PartialEq, Eq)] #[doc(alias = "GstRTSPContext")] +#[repr(transparent)] pub struct RTSPContext(ptr::NonNull); 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)]